app/testpmd: remove command to set FDIR flexible filter mask
[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                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
668                         "    Load a profile package on a port\n\n"
669
670                         "ddp del (port_id) (backup_profile_path)\n"
671                         "    Delete a profile package from a port\n\n"
672
673                         "ptype mapping get (port_id) (valid_only)\n"
674                         "    Get ptype mapping on a port\n\n"
675
676                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
677                         "    Replace target with the pkt_type in ptype mapping\n\n"
678
679                         "ptype mapping reset (port_id)\n"
680                         "    Reset ptype mapping on a port\n\n"
681
682                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
683                         "    Update a ptype mapping item on a port\n\n"
684
685                         "set port (port_id) ptype_mask (ptype_mask)\n"
686                         "    set packet types classification for a specific port\n\n"
687
688                         "set port (port_id) queue-region region_id (value) "
689                         "queue_start_index (value) queue_num (value)\n"
690                         "    Set a queue region on a port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "flowtype (value)\n"
694                         "    Set a flowtype region index on a port\n\n"
695
696                         "set port (port_id) queue-region UP (value) region_id (value)\n"
697                         "    Set the mapping of User Priority to "
698                         "queue region on a port\n\n"
699
700                         "set port (port_id) queue-region flush (on|off)\n"
701                         "    flush all queue region related configuration\n\n"
702
703                         "show port meter cap (port_id)\n"
704                         "    Show port meter capability information\n\n"
705
706                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
707                         "    meter profile add - srtcm rfc 2697\n\n"
708
709                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
710                         "    meter profile add - trtcm rfc 2698\n\n"
711
712                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
713                         "    meter profile add - trtcm rfc 4115\n\n"
714
715                         "del port meter profile (port_id) (profile_id)\n"
716                         "    meter profile delete\n\n"
717
718                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
719                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
720                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
721                         "(dscp_tbl_entry63)]\n"
722                         "    meter create\n\n"
723
724                         "enable port meter (port_id) (mtr_id)\n"
725                         "    meter enable\n\n"
726
727                         "disable port meter (port_id) (mtr_id)\n"
728                         "    meter disable\n\n"
729
730                         "del port meter (port_id) (mtr_id)\n"
731                         "    meter delete\n\n"
732
733                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
734                         "    meter update meter profile\n\n"
735
736                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
737                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
738                         "    update meter dscp table entries\n\n"
739
740                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
741                         "(action0) [(action1) (action2)]\n"
742                         "    meter update policer action\n\n"
743
744                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
745                         "    meter update stats\n\n"
746
747                         "show port (port_id) queue-region\n"
748                         "    show all queue region related configuration info\n\n"
749
750                         "set port (port_id) fec_mode auto|off|rs|baser\n"
751                         "    set fec mode for a specific port\n\n"
752
753                         , list_pkt_forwarding_modes()
754                 );
755         }
756
757         if (show_all || !strcmp(res->section, "ports")) {
758
759                 cmdline_printf(
760                         cl,
761                         "\n"
762                         "Port Operations:\n"
763                         "----------------\n\n"
764
765                         "port start (port_id|all)\n"
766                         "    Start all ports or port_id.\n\n"
767
768                         "port stop (port_id|all)\n"
769                         "    Stop all ports or port_id.\n\n"
770
771                         "port close (port_id|all)\n"
772                         "    Close all ports or port_id.\n\n"
773
774                         "port reset (port_id|all)\n"
775                         "    Reset all ports or port_id.\n\n"
776
777                         "port attach (ident)\n"
778                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
779
780                         "port detach (port_id)\n"
781                         "    Detach physical or virtual dev by port_id\n\n"
782
783                         "port config (port_id|all)"
784                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
785                         " duplex (half|full|auto)\n"
786                         "    Set speed and duplex for all ports or port_id\n\n"
787
788                         "port config (port_id|all) loopback (mode)\n"
789                         "    Set loopback mode for all ports or port_id\n\n"
790
791                         "port config all (rxq|txq|rxd|txd) (value)\n"
792                         "    Set number for rxq/txq/rxd/txd.\n\n"
793
794                         "port config all max-pkt-len (value)\n"
795                         "    Set the max packet length.\n\n"
796
797                         "port config all max-lro-pkt-size (value)\n"
798                         "    Set the max LRO aggregated packet size.\n\n"
799
800                         "port config all drop-en (on|off)\n"
801                         "    Enable or disable packet drop on all RX queues of all ports when no "
802                         "receive buffers available.\n\n"
803
804                         "port config all rss (all|default|ip|tcp|udp|sctp|"
805                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
806                         "level-outer|level-inner|<flowtype_id>)\n"
807                         "    Set the RSS mode.\n\n"
808
809                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
810                         "    Set the RSS redirection table.\n\n"
811
812                         "port config (port_id) dcb vt (on|off) (traffic_class)"
813                         " pfc (on|off)\n"
814                         "    Set the DCB mode.\n\n"
815
816                         "port config all burst (value)\n"
817                         "    Set the number of packets per burst.\n\n"
818
819                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
820                         " (value)\n"
821                         "    Set the ring prefetch/host/writeback threshold"
822                         " for tx/rx queue.\n\n"
823
824                         "port config all (txfreet|txrst|rxfreet) (value)\n"
825                         "    Set free threshold for rx/tx, or set"
826                         " tx rs bit threshold.\n\n"
827                         "port config mtu X value\n"
828                         "    Set the MTU of port X to a given value\n\n"
829
830                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
831                         "    Set a rx/tx queue's ring size configuration, the new"
832                         " value will take effect after command that (re-)start the port"
833                         " or command that setup the specific queue\n\n"
834
835                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
836                         "    Start/stop a rx/tx queue of port X. Only take effect"
837                         " when port X is started\n\n"
838
839                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
840                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
841                         " take effect when port X is stopped.\n\n"
842
843                         "port (port_id) (rxq|txq) (queue_id) setup\n"
844                         "    Setup a rx/tx queue of port X.\n\n"
845
846                         "port config (port_id|all) l2-tunnel E-tag ether-type"
847                         " (value)\n"
848                         "    Set the value of E-tag ether-type.\n\n"
849
850                         "port config (port_id|all) l2-tunnel E-tag"
851                         " (enable|disable)\n"
852                         "    Enable/disable the E-tag support.\n\n"
853
854                         "port config (port_id) pctype mapping reset\n"
855                         "    Reset flow type to pctype mapping on a port\n\n"
856
857                         "port config (port_id) pctype mapping update"
858                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
859                         "    Update a flow type to pctype mapping item on a port\n\n"
860
861                         "port config (port_id) pctype (pctype_id) hash_inset|"
862                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
863                         " (field_idx)\n"
864                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
865
866                         "port config (port_id) pctype (pctype_id) hash_inset|"
867                         "fdir_inset|fdir_flx_inset clear all"
868                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
869
870                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
871                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
872
873                         "port config <port_id> rx_offload vlan_strip|"
874                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
875                         "outer_ipv4_cksum|macsec_strip|header_split|"
876                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
877                         "buffer_split|timestamp|security|keep_crc on|off\n"
878                         "     Enable or disable a per port Rx offloading"
879                         " on all Rx queues of a port\n\n"
880
881                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
882                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
883                         "outer_ipv4_cksum|macsec_strip|header_split|"
884                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
885                         "buffer_split|timestamp|security|keep_crc on|off\n"
886                         "    Enable or disable a per queue Rx offloading"
887                         " only on a specific Rx queue\n\n"
888
889                         "port config (port_id) tx_offload vlan_insert|"
890                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
891                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
892                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
893                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
894                         "security on|off\n"
895                         "    Enable or disable a per port Tx offloading"
896                         " on all Tx queues of a port\n\n"
897
898                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
899                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
900                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
901                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
902                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
903                         " on|off\n"
904                         "    Enable or disable a per queue Tx offloading"
905                         " only on a specific Tx queue\n\n"
906
907                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
908                         "    Load an eBPF program as a callback"
909                         " for particular RX/TX queue\n\n"
910
911                         "bpf-unload rx|tx (port) (queue)\n"
912                         "    Unload previously loaded eBPF program"
913                         " for particular RX/TX queue\n\n"
914
915                         "port config (port_id) tx_metadata (value)\n"
916                         "    Set Tx metadata value per port. Testpmd will add this value"
917                         " to any Tx packet sent from this port\n\n"
918
919                         "port config (port_id) dynf (name) set|clear\n"
920                         "    Register a dynf and Set/clear this flag on Tx. "
921                         "Testpmd will set this value to any Tx packet "
922                         "sent from this port\n\n"
923                 );
924         }
925
926         if (show_all || !strcmp(res->section, "registers")) {
927
928                 cmdline_printf(
929                         cl,
930                         "\n"
931                         "Registers:\n"
932                         "----------\n\n"
933
934                         "read reg (port_id) (address)\n"
935                         "    Display value of a port register.\n\n"
936
937                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
938                         "    Display a port register bit field.\n\n"
939
940                         "read regbit (port_id) (address) (bit_x)\n"
941                         "    Display a single port register bit.\n\n"
942
943                         "write reg (port_id) (address) (value)\n"
944                         "    Set value of a port register.\n\n"
945
946                         "write regfield (port_id) (address) (bit_x) (bit_y)"
947                         " (value)\n"
948                         "    Set bit field of a port register.\n\n"
949
950                         "write regbit (port_id) (address) (bit_x) (value)\n"
951                         "    Set single bit value of a port register.\n\n"
952                 );
953         }
954         if (show_all || !strcmp(res->section, "filters")) {
955
956                 cmdline_printf(
957                         cl,
958                         "\n"
959                         "filters:\n"
960                         "--------\n\n"
961
962 #ifdef RTE_NET_I40E
963                         "flow_director_filter (port_id) mode raw (add|del|update)"
964                         " flow (flow_id) (drop|fwd) queue (queue_id)"
965                         " fd_id (fd_id_value) packet (packet file name)\n"
966                         "    Add/Del a raw type flow director filter.\n\n"
967 #endif
968
969                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
970                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
971                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
972                         "    Set flow director IP mask.\n\n"
973
974                         "flow_director_mask (port_id) mode MAC-VLAN"
975                         " vlan (vlan_value)\n"
976                         "    Set flow director MAC-VLAN mask.\n\n"
977
978                         "flow_director_mask (port_id) mode Tunnel"
979                         " vlan (vlan_value) mac (mac_value)"
980                         " tunnel-type (tunnel_type_value)"
981                         " tunnel-id (tunnel_id_value)\n"
982                         "    Set flow director Tunnel mask.\n\n"
983
984                         "flow_director_flex_payload (port_id)"
985                         " (raw|l2|l3|l4) (config)\n"
986                         "    Configure flex payload selection.\n\n"
987
988                         "flow validate {port_id}"
989                         " [group {group_id}] [priority {level}]"
990                         " [ingress] [egress]"
991                         " pattern {item} [/ {item} [...]] / end"
992                         " actions {action} [/ {action} [...]] / end\n"
993                         "    Check whether a flow rule can be created.\n\n"
994
995                         "flow create {port_id}"
996                         " [group {group_id}] [priority {level}]"
997                         " [ingress] [egress]"
998                         " pattern {item} [/ {item} [...]] / end"
999                         " actions {action} [/ {action} [...]] / end\n"
1000                         "    Create a flow rule.\n\n"
1001
1002                         "flow destroy {port_id} rule {rule_id} [...]\n"
1003                         "    Destroy specific flow rules.\n\n"
1004
1005                         "flow flush {port_id}\n"
1006                         "    Destroy all flow rules.\n\n"
1007
1008                         "flow query {port_id} {rule_id} {action}\n"
1009                         "    Query an existing flow rule.\n\n"
1010
1011                         "flow list {port_id} [group {group_id}] [...]\n"
1012                         "    List existing flow rules sorted by priority,"
1013                         " filtered by group identifiers.\n\n"
1014
1015                         "flow isolate {port_id} {boolean}\n"
1016                         "    Restrict ingress traffic to the defined"
1017                         " flow rules\n\n"
1018
1019                         "flow aged {port_id} [destroy]\n"
1020                         "    List and destroy aged flows"
1021                         " flow rules\n\n"
1022
1023                         "flow shared_action {port_id} create"
1024                         " [action_id {shared_action_id}]"
1025                         " [ingress] [egress]"
1026                         " action {action} / end\n"
1027                         "    Create shared action.\n\n"
1028
1029                         "flow shared_action {port_id} update"
1030                         " {shared_action_id} action {action} / end\n"
1031                         "    Update shared action.\n\n"
1032
1033                         "flow shared_action {port_id} destroy"
1034                         " action_id {shared_action_id} [...]\n"
1035                         "    Destroy specific shared actions.\n\n"
1036
1037                         "flow shared_action {port_id} query"
1038                         " {shared_action_id}\n"
1039                         "    Query an existing shared action.\n\n"
1040
1041                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1042                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1043                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the VXLAN encapsulation for flows.\n\n"
1045
1046                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1047                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1048                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1049                         " eth-dst (eth-dst)\n"
1050                         "       Configure the VXLAN encapsulation for flows.\n\n"
1051
1052                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1053                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1054                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1055                         " eth-dst (eth-dst)\n"
1056                         "       Configure the VXLAN encapsulation for flows.\n\n"
1057
1058                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1059                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1060                         " (eth-dst)\n"
1061                         "       Configure the NVGRE encapsulation for flows.\n\n"
1062
1063                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1064                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1065                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1066                         "       Configure the NVGRE encapsulation for flows.\n\n"
1067
1068                         "set raw_encap {flow items}\n"
1069                         "       Configure the encapsulation with raw data.\n\n"
1070
1071                         "set raw_decap {flow items}\n"
1072                         "       Configure the decapsulation with raw data.\n\n"
1073
1074                 );
1075         }
1076
1077         if (show_all || !strcmp(res->section, "traffic_management")) {
1078                 cmdline_printf(
1079                         cl,
1080                         "\n"
1081                         "Traffic Management:\n"
1082                         "--------------\n"
1083                         "show port tm cap (port_id)\n"
1084                         "       Display the port TM capability.\n\n"
1085
1086                         "show port tm level cap (port_id) (level_id)\n"
1087                         "       Display the port TM hierarchical level capability.\n\n"
1088
1089                         "show port tm node cap (port_id) (node_id)\n"
1090                         "       Display the port TM node capability.\n\n"
1091
1092                         "show port tm node type (port_id) (node_id)\n"
1093                         "       Display the port TM node type.\n\n"
1094
1095                         "show port tm node stats (port_id) (node_id) (clear)\n"
1096                         "       Display the port TM node stats.\n\n"
1097
1098                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1099                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1100                         " (packet_length_adjust) (packet_mode)\n"
1101                         "       Add port tm node private shaper profile.\n\n"
1102
1103                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1104                         "       Delete port tm node private shaper profile.\n\n"
1105
1106                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1107                         " (shaper_profile_id)\n"
1108                         "       Add/update port tm node shared shaper.\n\n"
1109
1110                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1111                         "       Delete port tm node shared shaper.\n\n"
1112
1113                         "set port tm node shaper profile (port_id) (node_id)"
1114                         " (shaper_profile_id)\n"
1115                         "       Set port tm node shaper profile.\n\n"
1116
1117                         "add port tm node wred profile (port_id) (wred_profile_id)"
1118                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1119                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1120                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1121                         "       Add port tm node wred profile.\n\n"
1122
1123                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1124                         "       Delete port tm node wred profile.\n\n"
1125
1126                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1127                         " (priority) (weight) (level_id) (shaper_profile_id)"
1128                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1129                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1130                         "       Add port tm nonleaf node.\n\n"
1131
1132                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1133                         " (priority) (weight) (level_id) (shaper_profile_id)"
1134                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1135                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1136                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1137
1138                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1139                         " (priority) (weight) (level_id) (shaper_profile_id)"
1140                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1141                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1142                         "       Add port tm leaf node.\n\n"
1143
1144                         "del port tm node (port_id) (node_id)\n"
1145                         "       Delete port tm node.\n\n"
1146
1147                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1148                         " (priority) (weight)\n"
1149                         "       Set port tm node parent.\n\n"
1150
1151                         "suspend port tm node (port_id) (node_id)"
1152                         "       Suspend tm node.\n\n"
1153
1154                         "resume port tm node (port_id) (node_id)"
1155                         "       Resume tm node.\n\n"
1156
1157                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1158                         "       Commit tm hierarchy.\n\n"
1159
1160                         "set port tm mark ip_ecn (port) (green) (yellow)"
1161                         " (red)\n"
1162                         "    Enables/Disables the traffic management marking"
1163                         " for IP ECN (Explicit Congestion Notification)"
1164                         " packets on a given port\n\n"
1165
1166                         "set port tm mark ip_dscp (port) (green) (yellow)"
1167                         " (red)\n"
1168                         "    Enables/Disables the traffic management marking"
1169                         " on the port for IP dscp packets\n\n"
1170
1171                         "set port tm mark vlan_dei (port) (green) (yellow)"
1172                         " (red)\n"
1173                         "    Enables/Disables the traffic management marking"
1174                         " on the port for VLAN packets with DEI enabled\n\n"
1175                 );
1176         }
1177
1178         if (show_all || !strcmp(res->section, "devices")) {
1179                 cmdline_printf(
1180                         cl,
1181                         "\n"
1182                         "Device Operations:\n"
1183                         "--------------\n"
1184                         "device detach (identifier)\n"
1185                         "       Detach device by identifier.\n\n"
1186                 );
1187         }
1188
1189 }
1190
1191 cmdline_parse_token_string_t cmd_help_long_help =
1192         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1193
1194 cmdline_parse_token_string_t cmd_help_long_section =
1195         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1196                         "all#control#display#config#"
1197                         "ports#registers#filters#traffic_management#devices");
1198
1199 cmdline_parse_inst_t cmd_help_long = {
1200         .f = cmd_help_long_parsed,
1201         .data = NULL,
1202         .help_str = "help all|control|display|config|ports|register|"
1203                 "filters|traffic_management|devices: "
1204                 "Show help",
1205         .tokens = {
1206                 (void *)&cmd_help_long_help,
1207                 (void *)&cmd_help_long_section,
1208                 NULL,
1209         },
1210 };
1211
1212
1213 /* *** start/stop/close all ports *** */
1214 struct cmd_operate_port_result {
1215         cmdline_fixed_string_t keyword;
1216         cmdline_fixed_string_t name;
1217         cmdline_fixed_string_t value;
1218 };
1219
1220 static void cmd_operate_port_parsed(void *parsed_result,
1221                                 __rte_unused struct cmdline *cl,
1222                                 __rte_unused void *data)
1223 {
1224         struct cmd_operate_port_result *res = parsed_result;
1225
1226         if (!strcmp(res->name, "start"))
1227                 start_port(RTE_PORT_ALL);
1228         else if (!strcmp(res->name, "stop"))
1229                 stop_port(RTE_PORT_ALL);
1230         else if (!strcmp(res->name, "close"))
1231                 close_port(RTE_PORT_ALL);
1232         else if (!strcmp(res->name, "reset"))
1233                 reset_port(RTE_PORT_ALL);
1234         else
1235                 printf("Unknown parameter\n");
1236 }
1237
1238 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1239         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1240                                                                 "port");
1241 cmdline_parse_token_string_t cmd_operate_port_all_port =
1242         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1243                                                 "start#stop#close#reset");
1244 cmdline_parse_token_string_t cmd_operate_port_all_all =
1245         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1246
1247 cmdline_parse_inst_t cmd_operate_port = {
1248         .f = cmd_operate_port_parsed,
1249         .data = NULL,
1250         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1251         .tokens = {
1252                 (void *)&cmd_operate_port_all_cmd,
1253                 (void *)&cmd_operate_port_all_port,
1254                 (void *)&cmd_operate_port_all_all,
1255                 NULL,
1256         },
1257 };
1258
1259 /* *** start/stop/close specific port *** */
1260 struct cmd_operate_specific_port_result {
1261         cmdline_fixed_string_t keyword;
1262         cmdline_fixed_string_t name;
1263         uint8_t value;
1264 };
1265
1266 static void cmd_operate_specific_port_parsed(void *parsed_result,
1267                         __rte_unused struct cmdline *cl,
1268                                 __rte_unused void *data)
1269 {
1270         struct cmd_operate_specific_port_result *res = parsed_result;
1271
1272         if (!strcmp(res->name, "start"))
1273                 start_port(res->value);
1274         else if (!strcmp(res->name, "stop"))
1275                 stop_port(res->value);
1276         else if (!strcmp(res->name, "close"))
1277                 close_port(res->value);
1278         else if (!strcmp(res->name, "reset"))
1279                 reset_port(res->value);
1280         else
1281                 printf("Unknown parameter\n");
1282 }
1283
1284 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1285         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1286                                                         keyword, "port");
1287 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1288         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1289                                                 name, "start#stop#close#reset");
1290 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1291         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1292                                                         value, UINT8);
1293
1294 cmdline_parse_inst_t cmd_operate_specific_port = {
1295         .f = cmd_operate_specific_port_parsed,
1296         .data = NULL,
1297         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1298         .tokens = {
1299                 (void *)&cmd_operate_specific_port_cmd,
1300                 (void *)&cmd_operate_specific_port_port,
1301                 (void *)&cmd_operate_specific_port_id,
1302                 NULL,
1303         },
1304 };
1305
1306 /* *** enable port setup (after attach) via iterator or event *** */
1307 struct cmd_set_port_setup_on_result {
1308         cmdline_fixed_string_t set;
1309         cmdline_fixed_string_t port;
1310         cmdline_fixed_string_t setup;
1311         cmdline_fixed_string_t on;
1312         cmdline_fixed_string_t mode;
1313 };
1314
1315 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1316                                 __rte_unused struct cmdline *cl,
1317                                 __rte_unused void *data)
1318 {
1319         struct cmd_set_port_setup_on_result *res = parsed_result;
1320
1321         if (strcmp(res->mode, "event") == 0)
1322                 setup_on_probe_event = true;
1323         else if (strcmp(res->mode, "iterator") == 0)
1324                 setup_on_probe_event = false;
1325         else
1326                 printf("Unknown mode\n");
1327 }
1328
1329 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1330         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1331                         set, "set");
1332 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1333         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1334                         port, "port");
1335 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1336         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1337                         setup, "setup");
1338 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1339         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1340                         on, "on");
1341 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1342         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1343                         mode, "iterator#event");
1344
1345 cmdline_parse_inst_t cmd_set_port_setup_on = {
1346         .f = cmd_set_port_setup_on_parsed,
1347         .data = NULL,
1348         .help_str = "set port setup on iterator|event",
1349         .tokens = {
1350                 (void *)&cmd_set_port_setup_on_set,
1351                 (void *)&cmd_set_port_setup_on_port,
1352                 (void *)&cmd_set_port_setup_on_setup,
1353                 (void *)&cmd_set_port_setup_on_on,
1354                 (void *)&cmd_set_port_setup_on_mode,
1355                 NULL,
1356         },
1357 };
1358
1359 /* *** attach a specified port *** */
1360 struct cmd_operate_attach_port_result {
1361         cmdline_fixed_string_t port;
1362         cmdline_fixed_string_t keyword;
1363         cmdline_multi_string_t identifier;
1364 };
1365
1366 static void cmd_operate_attach_port_parsed(void *parsed_result,
1367                                 __rte_unused struct cmdline *cl,
1368                                 __rte_unused void *data)
1369 {
1370         struct cmd_operate_attach_port_result *res = parsed_result;
1371
1372         if (!strcmp(res->keyword, "attach"))
1373                 attach_port(res->identifier);
1374         else
1375                 printf("Unknown parameter\n");
1376 }
1377
1378 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1379         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1380                         port, "port");
1381 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1382         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1383                         keyword, "attach");
1384 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1385         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1386                         identifier, TOKEN_STRING_MULTI);
1387
1388 cmdline_parse_inst_t cmd_operate_attach_port = {
1389         .f = cmd_operate_attach_port_parsed,
1390         .data = NULL,
1391         .help_str = "port attach <identifier>: "
1392                 "(identifier: pci address or virtual dev name)",
1393         .tokens = {
1394                 (void *)&cmd_operate_attach_port_port,
1395                 (void *)&cmd_operate_attach_port_keyword,
1396                 (void *)&cmd_operate_attach_port_identifier,
1397                 NULL,
1398         },
1399 };
1400
1401 /* *** detach a specified port *** */
1402 struct cmd_operate_detach_port_result {
1403         cmdline_fixed_string_t port;
1404         cmdline_fixed_string_t keyword;
1405         portid_t port_id;
1406 };
1407
1408 static void cmd_operate_detach_port_parsed(void *parsed_result,
1409                                 __rte_unused struct cmdline *cl,
1410                                 __rte_unused void *data)
1411 {
1412         struct cmd_operate_detach_port_result *res = parsed_result;
1413
1414         if (!strcmp(res->keyword, "detach")) {
1415                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1416                 detach_port_device(res->port_id);
1417         } else {
1418                 printf("Unknown parameter\n");
1419         }
1420 }
1421
1422 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1424                         port, "port");
1425 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1426         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1427                         keyword, "detach");
1428 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1429         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1430                         port_id, UINT16);
1431
1432 cmdline_parse_inst_t cmd_operate_detach_port = {
1433         .f = cmd_operate_detach_port_parsed,
1434         .data = NULL,
1435         .help_str = "port detach <port_id>",
1436         .tokens = {
1437                 (void *)&cmd_operate_detach_port_port,
1438                 (void *)&cmd_operate_detach_port_keyword,
1439                 (void *)&cmd_operate_detach_port_port_id,
1440                 NULL,
1441         },
1442 };
1443
1444 /* *** detach device by identifier *** */
1445 struct cmd_operate_detach_device_result {
1446         cmdline_fixed_string_t device;
1447         cmdline_fixed_string_t keyword;
1448         cmdline_fixed_string_t identifier;
1449 };
1450
1451 static void cmd_operate_detach_device_parsed(void *parsed_result,
1452                                 __rte_unused struct cmdline *cl,
1453                                 __rte_unused void *data)
1454 {
1455         struct cmd_operate_detach_device_result *res = parsed_result;
1456
1457         if (!strcmp(res->keyword, "detach"))
1458                 detach_devargs(res->identifier);
1459         else
1460                 printf("Unknown parameter\n");
1461 }
1462
1463 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1464         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1465                         device, "device");
1466 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1467         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1468                         keyword, "detach");
1469 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1470         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1471                         identifier, NULL);
1472
1473 cmdline_parse_inst_t cmd_operate_detach_device = {
1474         .f = cmd_operate_detach_device_parsed,
1475         .data = NULL,
1476         .help_str = "device detach <identifier>:"
1477                 "(identifier: pci address or virtual dev name)",
1478         .tokens = {
1479                 (void *)&cmd_operate_detach_device_device,
1480                 (void *)&cmd_operate_detach_device_keyword,
1481                 (void *)&cmd_operate_detach_device_identifier,
1482                 NULL,
1483         },
1484 };
1485 /* *** configure speed for all ports *** */
1486 struct cmd_config_speed_all {
1487         cmdline_fixed_string_t port;
1488         cmdline_fixed_string_t keyword;
1489         cmdline_fixed_string_t all;
1490         cmdline_fixed_string_t item1;
1491         cmdline_fixed_string_t item2;
1492         cmdline_fixed_string_t value1;
1493         cmdline_fixed_string_t value2;
1494 };
1495
1496 static int
1497 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1498 {
1499
1500         int duplex;
1501
1502         if (!strcmp(duplexstr, "half")) {
1503                 duplex = ETH_LINK_HALF_DUPLEX;
1504         } else if (!strcmp(duplexstr, "full")) {
1505                 duplex = ETH_LINK_FULL_DUPLEX;
1506         } else if (!strcmp(duplexstr, "auto")) {
1507                 duplex = ETH_LINK_FULL_DUPLEX;
1508         } else {
1509                 printf("Unknown duplex parameter\n");
1510                 return -1;
1511         }
1512
1513         if (!strcmp(speedstr, "10")) {
1514                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1515                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1516         } else if (!strcmp(speedstr, "100")) {
1517                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1518                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1519         } else {
1520                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1521                         printf("Invalid speed/duplex parameters\n");
1522                         return -1;
1523                 }
1524                 if (!strcmp(speedstr, "1000")) {
1525                         *speed = ETH_LINK_SPEED_1G;
1526                 } else if (!strcmp(speedstr, "10000")) {
1527                         *speed = ETH_LINK_SPEED_10G;
1528                 } else if (!strcmp(speedstr, "25000")) {
1529                         *speed = ETH_LINK_SPEED_25G;
1530                 } else if (!strcmp(speedstr, "40000")) {
1531                         *speed = ETH_LINK_SPEED_40G;
1532                 } else if (!strcmp(speedstr, "50000")) {
1533                         *speed = ETH_LINK_SPEED_50G;
1534                 } else if (!strcmp(speedstr, "100000")) {
1535                         *speed = ETH_LINK_SPEED_100G;
1536                 } else if (!strcmp(speedstr, "200000")) {
1537                         *speed = ETH_LINK_SPEED_200G;
1538                 } else if (!strcmp(speedstr, "auto")) {
1539                         *speed = ETH_LINK_SPEED_AUTONEG;
1540                 } else {
1541                         printf("Unknown speed parameter\n");
1542                         return -1;
1543                 }
1544         }
1545
1546         return 0;
1547 }
1548
1549 static void
1550 cmd_config_speed_all_parsed(void *parsed_result,
1551                         __rte_unused struct cmdline *cl,
1552                         __rte_unused void *data)
1553 {
1554         struct cmd_config_speed_all *res = parsed_result;
1555         uint32_t link_speed;
1556         portid_t pid;
1557
1558         if (!all_ports_stopped()) {
1559                 printf("Please stop all ports first\n");
1560                 return;
1561         }
1562
1563         if (parse_and_check_speed_duplex(res->value1, res->value2,
1564                         &link_speed) < 0)
1565                 return;
1566
1567         RTE_ETH_FOREACH_DEV(pid) {
1568                 ports[pid].dev_conf.link_speeds = link_speed;
1569         }
1570
1571         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1572 }
1573
1574 cmdline_parse_token_string_t cmd_config_speed_all_port =
1575         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1576 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1577         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1578                                                         "config");
1579 cmdline_parse_token_string_t cmd_config_speed_all_all =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1581 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1582         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1583 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1584         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1585                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1586 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1587         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1588 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1590                                                 "half#full#auto");
1591
1592 cmdline_parse_inst_t cmd_config_speed_all = {
1593         .f = cmd_config_speed_all_parsed,
1594         .data = NULL,
1595         .help_str = "port config all speed "
1596                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1597                                                         "half|full|auto",
1598         .tokens = {
1599                 (void *)&cmd_config_speed_all_port,
1600                 (void *)&cmd_config_speed_all_keyword,
1601                 (void *)&cmd_config_speed_all_all,
1602                 (void *)&cmd_config_speed_all_item1,
1603                 (void *)&cmd_config_speed_all_value1,
1604                 (void *)&cmd_config_speed_all_item2,
1605                 (void *)&cmd_config_speed_all_value2,
1606                 NULL,
1607         },
1608 };
1609
1610 /* *** configure speed for specific port *** */
1611 struct cmd_config_speed_specific {
1612         cmdline_fixed_string_t port;
1613         cmdline_fixed_string_t keyword;
1614         portid_t id;
1615         cmdline_fixed_string_t item1;
1616         cmdline_fixed_string_t item2;
1617         cmdline_fixed_string_t value1;
1618         cmdline_fixed_string_t value2;
1619 };
1620
1621 static void
1622 cmd_config_speed_specific_parsed(void *parsed_result,
1623                                 __rte_unused struct cmdline *cl,
1624                                 __rte_unused void *data)
1625 {
1626         struct cmd_config_speed_specific *res = parsed_result;
1627         uint32_t link_speed;
1628
1629         if (!all_ports_stopped()) {
1630                 printf("Please stop all ports first\n");
1631                 return;
1632         }
1633
1634         if (port_id_is_invalid(res->id, ENABLED_WARN))
1635                 return;
1636
1637         if (parse_and_check_speed_duplex(res->value1, res->value2,
1638                         &link_speed) < 0)
1639                 return;
1640
1641         ports[res->id].dev_conf.link_speeds = link_speed;
1642
1643         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1644 }
1645
1646
1647 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1649                                                                 "port");
1650 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1652                                                                 "config");
1653 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1654         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1655 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1657                                                                 "speed");
1658 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1660                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1661 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1663                                                                 "duplex");
1664 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1666                                                         "half#full#auto");
1667
1668 cmdline_parse_inst_t cmd_config_speed_specific = {
1669         .f = cmd_config_speed_specific_parsed,
1670         .data = NULL,
1671         .help_str = "port config <port_id> speed "
1672                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1673                                                         "half|full|auto",
1674         .tokens = {
1675                 (void *)&cmd_config_speed_specific_port,
1676                 (void *)&cmd_config_speed_specific_keyword,
1677                 (void *)&cmd_config_speed_specific_id,
1678                 (void *)&cmd_config_speed_specific_item1,
1679                 (void *)&cmd_config_speed_specific_value1,
1680                 (void *)&cmd_config_speed_specific_item2,
1681                 (void *)&cmd_config_speed_specific_value2,
1682                 NULL,
1683         },
1684 };
1685
1686 /* *** configure loopback for all ports *** */
1687 struct cmd_config_loopback_all {
1688         cmdline_fixed_string_t port;
1689         cmdline_fixed_string_t keyword;
1690         cmdline_fixed_string_t all;
1691         cmdline_fixed_string_t item;
1692         uint32_t mode;
1693 };
1694
1695 static void
1696 cmd_config_loopback_all_parsed(void *parsed_result,
1697                         __rte_unused struct cmdline *cl,
1698                         __rte_unused void *data)
1699 {
1700         struct cmd_config_loopback_all *res = parsed_result;
1701         portid_t pid;
1702
1703         if (!all_ports_stopped()) {
1704                 printf("Please stop all ports first\n");
1705                 return;
1706         }
1707
1708         RTE_ETH_FOREACH_DEV(pid) {
1709                 ports[pid].dev_conf.lpbk_mode = res->mode;
1710         }
1711
1712         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1713 }
1714
1715 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1717 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1719                                                         "config");
1720 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1722 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1724                                                         "loopback");
1725 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1726         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1727
1728 cmdline_parse_inst_t cmd_config_loopback_all = {
1729         .f = cmd_config_loopback_all_parsed,
1730         .data = NULL,
1731         .help_str = "port config all loopback <mode>",
1732         .tokens = {
1733                 (void *)&cmd_config_loopback_all_port,
1734                 (void *)&cmd_config_loopback_all_keyword,
1735                 (void *)&cmd_config_loopback_all_all,
1736                 (void *)&cmd_config_loopback_all_item,
1737                 (void *)&cmd_config_loopback_all_mode,
1738                 NULL,
1739         },
1740 };
1741
1742 /* *** configure loopback for specific port *** */
1743 struct cmd_config_loopback_specific {
1744         cmdline_fixed_string_t port;
1745         cmdline_fixed_string_t keyword;
1746         uint16_t port_id;
1747         cmdline_fixed_string_t item;
1748         uint32_t mode;
1749 };
1750
1751 static void
1752 cmd_config_loopback_specific_parsed(void *parsed_result,
1753                                 __rte_unused struct cmdline *cl,
1754                                 __rte_unused void *data)
1755 {
1756         struct cmd_config_loopback_specific *res = parsed_result;
1757
1758         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1759                 return;
1760
1761         if (!port_is_stopped(res->port_id)) {
1762                 printf("Please stop port %u first\n", res->port_id);
1763                 return;
1764         }
1765
1766         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1767
1768         cmd_reconfig_device_queue(res->port_id, 1, 1);
1769 }
1770
1771
1772 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1774                                                                 "port");
1775 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1777                                                                 "config");
1778 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1779         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1780                                                                 UINT16);
1781 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1783                                                                 "loopback");
1784 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1785         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1786                               UINT32);
1787
1788 cmdline_parse_inst_t cmd_config_loopback_specific = {
1789         .f = cmd_config_loopback_specific_parsed,
1790         .data = NULL,
1791         .help_str = "port config <port_id> loopback <mode>",
1792         .tokens = {
1793                 (void *)&cmd_config_loopback_specific_port,
1794                 (void *)&cmd_config_loopback_specific_keyword,
1795                 (void *)&cmd_config_loopback_specific_id,
1796                 (void *)&cmd_config_loopback_specific_item,
1797                 (void *)&cmd_config_loopback_specific_mode,
1798                 NULL,
1799         },
1800 };
1801
1802 /* *** configure txq/rxq, txd/rxd *** */
1803 struct cmd_config_rx_tx {
1804         cmdline_fixed_string_t port;
1805         cmdline_fixed_string_t keyword;
1806         cmdline_fixed_string_t all;
1807         cmdline_fixed_string_t name;
1808         uint16_t value;
1809 };
1810
1811 static void
1812 cmd_config_rx_tx_parsed(void *parsed_result,
1813                         __rte_unused struct cmdline *cl,
1814                         __rte_unused void *data)
1815 {
1816         struct cmd_config_rx_tx *res = parsed_result;
1817
1818         if (!all_ports_stopped()) {
1819                 printf("Please stop all ports first\n");
1820                 return;
1821         }
1822         if (!strcmp(res->name, "rxq")) {
1823                 if (!res->value && !nb_txq) {
1824                         printf("Warning: Either rx or tx queues should be non zero\n");
1825                         return;
1826                 }
1827                 if (check_nb_rxq(res->value) != 0)
1828                         return;
1829                 nb_rxq = res->value;
1830         }
1831         else if (!strcmp(res->name, "txq")) {
1832                 if (!res->value && !nb_rxq) {
1833                         printf("Warning: Either rx or tx queues should be non zero\n");
1834                         return;
1835                 }
1836                 if (check_nb_txq(res->value) != 0)
1837                         return;
1838                 nb_txq = res->value;
1839         }
1840         else if (!strcmp(res->name, "rxd")) {
1841                 if (check_nb_rxd(res->value) != 0)
1842                         return;
1843                 nb_rxd = res->value;
1844         } else if (!strcmp(res->name, "txd")) {
1845                 if (check_nb_txd(res->value) != 0)
1846                         return;
1847
1848                 nb_txd = res->value;
1849         } else {
1850                 printf("Unknown parameter\n");
1851                 return;
1852         }
1853
1854         fwd_config_setup();
1855
1856         init_port_config();
1857
1858         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1859 }
1860
1861 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1863 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1864         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1865 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1867 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1868         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1869                                                 "rxq#txq#rxd#txd");
1870 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1871         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1872
1873 cmdline_parse_inst_t cmd_config_rx_tx = {
1874         .f = cmd_config_rx_tx_parsed,
1875         .data = NULL,
1876         .help_str = "port config all rxq|txq|rxd|txd <value>",
1877         .tokens = {
1878                 (void *)&cmd_config_rx_tx_port,
1879                 (void *)&cmd_config_rx_tx_keyword,
1880                 (void *)&cmd_config_rx_tx_all,
1881                 (void *)&cmd_config_rx_tx_name,
1882                 (void *)&cmd_config_rx_tx_value,
1883                 NULL,
1884         },
1885 };
1886
1887 /* *** config max packet length *** */
1888 struct cmd_config_max_pkt_len_result {
1889         cmdline_fixed_string_t port;
1890         cmdline_fixed_string_t keyword;
1891         cmdline_fixed_string_t all;
1892         cmdline_fixed_string_t name;
1893         uint32_t value;
1894 };
1895
1896 static void
1897 cmd_config_max_pkt_len_parsed(void *parsed_result,
1898                                 __rte_unused struct cmdline *cl,
1899                                 __rte_unused void *data)
1900 {
1901         struct cmd_config_max_pkt_len_result *res = parsed_result;
1902         portid_t pid;
1903
1904         if (!all_ports_stopped()) {
1905                 printf("Please stop all ports first\n");
1906                 return;
1907         }
1908
1909         RTE_ETH_FOREACH_DEV(pid) {
1910                 struct rte_port *port = &ports[pid];
1911                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1912
1913                 if (!strcmp(res->name, "max-pkt-len")) {
1914                         if (res->value < RTE_ETHER_MIN_LEN) {
1915                                 printf("max-pkt-len can not be less than %d\n",
1916                                                 RTE_ETHER_MIN_LEN);
1917                                 return;
1918                         }
1919                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1920                                 return;
1921
1922                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1923                         if (res->value > RTE_ETHER_MAX_LEN)
1924                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1925                         else
1926                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1927                         port->dev_conf.rxmode.offloads = rx_offloads;
1928                 } else {
1929                         printf("Unknown parameter\n");
1930                         return;
1931                 }
1932         }
1933
1934         init_port_config();
1935
1936         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1937 }
1938
1939 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1941                                                                 "port");
1942 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1944                                                                 "config");
1945 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1946         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1947                                                                 "all");
1948 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1949         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1950                                                                 "max-pkt-len");
1951 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1952         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1953                                                                 UINT32);
1954
1955 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1956         .f = cmd_config_max_pkt_len_parsed,
1957         .data = NULL,
1958         .help_str = "port config all max-pkt-len <value>",
1959         .tokens = {
1960                 (void *)&cmd_config_max_pkt_len_port,
1961                 (void *)&cmd_config_max_pkt_len_keyword,
1962                 (void *)&cmd_config_max_pkt_len_all,
1963                 (void *)&cmd_config_max_pkt_len_name,
1964                 (void *)&cmd_config_max_pkt_len_value,
1965                 NULL,
1966         },
1967 };
1968
1969 /* *** config max LRO aggregated packet size *** */
1970 struct cmd_config_max_lro_pkt_size_result {
1971         cmdline_fixed_string_t port;
1972         cmdline_fixed_string_t keyword;
1973         cmdline_fixed_string_t all;
1974         cmdline_fixed_string_t name;
1975         uint32_t value;
1976 };
1977
1978 static void
1979 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1980                                 __rte_unused struct cmdline *cl,
1981                                 __rte_unused void *data)
1982 {
1983         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1984         portid_t pid;
1985
1986         if (!all_ports_stopped()) {
1987                 printf("Please stop all ports first\n");
1988                 return;
1989         }
1990
1991         RTE_ETH_FOREACH_DEV(pid) {
1992                 struct rte_port *port = &ports[pid];
1993
1994                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1995                         if (res->value ==
1996                                         port->dev_conf.rxmode.max_lro_pkt_size)
1997                                 return;
1998
1999                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2000                 } else {
2001                         printf("Unknown parameter\n");
2002                         return;
2003                 }
2004         }
2005
2006         init_port_config();
2007
2008         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2009 }
2010
2011 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2012         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2013                                  port, "port");
2014 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2016                                  keyword, "config");
2017 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2019                                  all, "all");
2020 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2022                                  name, "max-lro-pkt-size");
2023 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2024         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2025                               value, UINT32);
2026
2027 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2028         .f = cmd_config_max_lro_pkt_size_parsed,
2029         .data = NULL,
2030         .help_str = "port config all max-lro-pkt-size <value>",
2031         .tokens = {
2032                 (void *)&cmd_config_max_lro_pkt_size_port,
2033                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2034                 (void *)&cmd_config_max_lro_pkt_size_all,
2035                 (void *)&cmd_config_max_lro_pkt_size_name,
2036                 (void *)&cmd_config_max_lro_pkt_size_value,
2037                 NULL,
2038         },
2039 };
2040
2041 /* *** configure port MTU *** */
2042 struct cmd_config_mtu_result {
2043         cmdline_fixed_string_t port;
2044         cmdline_fixed_string_t keyword;
2045         cmdline_fixed_string_t mtu;
2046         portid_t port_id;
2047         uint16_t value;
2048 };
2049
2050 static void
2051 cmd_config_mtu_parsed(void *parsed_result,
2052                       __rte_unused struct cmdline *cl,
2053                       __rte_unused void *data)
2054 {
2055         struct cmd_config_mtu_result *res = parsed_result;
2056
2057         if (res->value < RTE_ETHER_MIN_LEN) {
2058                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2059                 return;
2060         }
2061         port_mtu_set(res->port_id, res->value);
2062 }
2063
2064 cmdline_parse_token_string_t cmd_config_mtu_port =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2066                                  "port");
2067 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2068         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2069                                  "config");
2070 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2072                                  "mtu");
2073 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2074         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2075 cmdline_parse_token_num_t cmd_config_mtu_value =
2076         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2077
2078 cmdline_parse_inst_t cmd_config_mtu = {
2079         .f = cmd_config_mtu_parsed,
2080         .data = NULL,
2081         .help_str = "port config mtu <port_id> <value>",
2082         .tokens = {
2083                 (void *)&cmd_config_mtu_port,
2084                 (void *)&cmd_config_mtu_keyword,
2085                 (void *)&cmd_config_mtu_mtu,
2086                 (void *)&cmd_config_mtu_port_id,
2087                 (void *)&cmd_config_mtu_value,
2088                 NULL,
2089         },
2090 };
2091
2092 /* *** configure rx mode *** */
2093 struct cmd_config_rx_mode_flag {
2094         cmdline_fixed_string_t port;
2095         cmdline_fixed_string_t keyword;
2096         cmdline_fixed_string_t all;
2097         cmdline_fixed_string_t name;
2098         cmdline_fixed_string_t value;
2099 };
2100
2101 static void
2102 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2103                                 __rte_unused struct cmdline *cl,
2104                                 __rte_unused void *data)
2105 {
2106         struct cmd_config_rx_mode_flag *res = parsed_result;
2107
2108         if (!all_ports_stopped()) {
2109                 printf("Please stop all ports first\n");
2110                 return;
2111         }
2112
2113         if (!strcmp(res->name, "drop-en")) {
2114                 if (!strcmp(res->value, "on"))
2115                         rx_drop_en = 1;
2116                 else if (!strcmp(res->value, "off"))
2117                         rx_drop_en = 0;
2118                 else {
2119                         printf("Unknown parameter\n");
2120                         return;
2121                 }
2122         } else {
2123                 printf("Unknown parameter\n");
2124                 return;
2125         }
2126
2127         init_port_config();
2128
2129         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2130 }
2131
2132 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2133         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2134 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2135         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2136                                                                 "config");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2139 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2141                                         "drop-en");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2144                                                         "on#off");
2145
2146 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2147         .f = cmd_config_rx_mode_flag_parsed,
2148         .data = NULL,
2149         .help_str = "port config all drop-en on|off",
2150         .tokens = {
2151                 (void *)&cmd_config_rx_mode_flag_port,
2152                 (void *)&cmd_config_rx_mode_flag_keyword,
2153                 (void *)&cmd_config_rx_mode_flag_all,
2154                 (void *)&cmd_config_rx_mode_flag_name,
2155                 (void *)&cmd_config_rx_mode_flag_value,
2156                 NULL,
2157         },
2158 };
2159
2160 /* *** configure rss *** */
2161 struct cmd_config_rss {
2162         cmdline_fixed_string_t port;
2163         cmdline_fixed_string_t keyword;
2164         cmdline_fixed_string_t all;
2165         cmdline_fixed_string_t name;
2166         cmdline_fixed_string_t value;
2167 };
2168
2169 static void
2170 cmd_config_rss_parsed(void *parsed_result,
2171                         __rte_unused struct cmdline *cl,
2172                         __rte_unused void *data)
2173 {
2174         struct cmd_config_rss *res = parsed_result;
2175         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2176         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2177         int use_default = 0;
2178         int all_updated = 1;
2179         int diag;
2180         uint16_t i;
2181         int ret;
2182
2183         if (!strcmp(res->value, "all"))
2184                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2185                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2186                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2187                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2188         else if (!strcmp(res->value, "eth"))
2189                 rss_conf.rss_hf = ETH_RSS_ETH;
2190         else if (!strcmp(res->value, "vlan"))
2191                 rss_conf.rss_hf = ETH_RSS_VLAN;
2192         else if (!strcmp(res->value, "ip"))
2193                 rss_conf.rss_hf = ETH_RSS_IP;
2194         else if (!strcmp(res->value, "udp"))
2195                 rss_conf.rss_hf = ETH_RSS_UDP;
2196         else if (!strcmp(res->value, "tcp"))
2197                 rss_conf.rss_hf = ETH_RSS_TCP;
2198         else if (!strcmp(res->value, "sctp"))
2199                 rss_conf.rss_hf = ETH_RSS_SCTP;
2200         else if (!strcmp(res->value, "ether"))
2201                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2202         else if (!strcmp(res->value, "port"))
2203                 rss_conf.rss_hf = ETH_RSS_PORT;
2204         else if (!strcmp(res->value, "vxlan"))
2205                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2206         else if (!strcmp(res->value, "geneve"))
2207                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2208         else if (!strcmp(res->value, "nvgre"))
2209                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2210         else if (!strcmp(res->value, "l3-pre32"))
2211                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2212         else if (!strcmp(res->value, "l3-pre40"))
2213                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2214         else if (!strcmp(res->value, "l3-pre48"))
2215                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2216         else if (!strcmp(res->value, "l3-pre56"))
2217                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2218         else if (!strcmp(res->value, "l3-pre64"))
2219                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2220         else if (!strcmp(res->value, "l3-pre96"))
2221                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2222         else if (!strcmp(res->value, "l3-src-only"))
2223                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2224         else if (!strcmp(res->value, "l3-dst-only"))
2225                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2226         else if (!strcmp(res->value, "l4-src-only"))
2227                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2228         else if (!strcmp(res->value, "l4-dst-only"))
2229                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2230         else if (!strcmp(res->value, "l2-src-only"))
2231                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2232         else if (!strcmp(res->value, "l2-dst-only"))
2233                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2234         else if (!strcmp(res->value, "l2tpv3"))
2235                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2236         else if (!strcmp(res->value, "esp"))
2237                 rss_conf.rss_hf = ETH_RSS_ESP;
2238         else if (!strcmp(res->value, "ah"))
2239                 rss_conf.rss_hf = ETH_RSS_AH;
2240         else if (!strcmp(res->value, "pfcp"))
2241                 rss_conf.rss_hf = ETH_RSS_PFCP;
2242         else if (!strcmp(res->value, "pppoe"))
2243                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2244         else if (!strcmp(res->value, "gtpu"))
2245                 rss_conf.rss_hf = ETH_RSS_GTPU;
2246         else if (!strcmp(res->value, "none"))
2247                 rss_conf.rss_hf = 0;
2248         else if (!strcmp(res->value, "level-default")) {
2249                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2250                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2251         } else if (!strcmp(res->value, "level-outer")) {
2252                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2253                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2254         } else if (!strcmp(res->value, "level-inner")) {
2255                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2256                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2257         } else if (!strcmp(res->value, "default"))
2258                 use_default = 1;
2259         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2260                                                 atoi(res->value) < 64)
2261                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2262         else {
2263                 printf("Unknown parameter\n");
2264                 return;
2265         }
2266         rss_conf.rss_key = NULL;
2267         /* Update global configuration for RSS types. */
2268         RTE_ETH_FOREACH_DEV(i) {
2269                 struct rte_eth_rss_conf local_rss_conf;
2270
2271                 ret = eth_dev_info_get_print_err(i, &dev_info);
2272                 if (ret != 0)
2273                         return;
2274
2275                 if (use_default)
2276                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2277
2278                 local_rss_conf = rss_conf;
2279                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2280                         dev_info.flow_type_rss_offloads;
2281                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2282                         printf("Port %u modified RSS hash function based on hardware support,"
2283                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2284                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2285                 }
2286                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2287                 if (diag < 0) {
2288                         all_updated = 0;
2289                         printf("Configuration of RSS hash at ethernet port %d "
2290                                 "failed with error (%d): %s.\n",
2291                                 i, -diag, strerror(-diag));
2292                 }
2293         }
2294         if (all_updated && !use_default) {
2295                 rss_hf = rss_conf.rss_hf;
2296                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2297         }
2298 }
2299
2300 cmdline_parse_token_string_t cmd_config_rss_port =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2302 cmdline_parse_token_string_t cmd_config_rss_keyword =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2304 cmdline_parse_token_string_t cmd_config_rss_all =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2306 cmdline_parse_token_string_t cmd_config_rss_name =
2307         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2308 cmdline_parse_token_string_t cmd_config_rss_value =
2309         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2310
2311 cmdline_parse_inst_t cmd_config_rss = {
2312         .f = cmd_config_rss_parsed,
2313         .data = NULL,
2314         .help_str = "port config all rss "
2315                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2316                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2317                 "level-outer|level-inner|<flowtype_id>",
2318         .tokens = {
2319                 (void *)&cmd_config_rss_port,
2320                 (void *)&cmd_config_rss_keyword,
2321                 (void *)&cmd_config_rss_all,
2322                 (void *)&cmd_config_rss_name,
2323                 (void *)&cmd_config_rss_value,
2324                 NULL,
2325         },
2326 };
2327
2328 /* *** configure rss hash key *** */
2329 struct cmd_config_rss_hash_key {
2330         cmdline_fixed_string_t port;
2331         cmdline_fixed_string_t config;
2332         portid_t port_id;
2333         cmdline_fixed_string_t rss_hash_key;
2334         cmdline_fixed_string_t rss_type;
2335         cmdline_fixed_string_t key;
2336 };
2337
2338 static uint8_t
2339 hexa_digit_to_value(char hexa_digit)
2340 {
2341         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2342                 return (uint8_t) (hexa_digit - '0');
2343         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2344                 return (uint8_t) ((hexa_digit - 'a') + 10);
2345         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2346                 return (uint8_t) ((hexa_digit - 'A') + 10);
2347         /* Invalid hexa digit */
2348         return 0xFF;
2349 }
2350
2351 static uint8_t
2352 parse_and_check_key_hexa_digit(char *key, int idx)
2353 {
2354         uint8_t hexa_v;
2355
2356         hexa_v = hexa_digit_to_value(key[idx]);
2357         if (hexa_v == 0xFF)
2358                 printf("invalid key: character %c at position %d is not a "
2359                        "valid hexa digit\n", key[idx], idx);
2360         return hexa_v;
2361 }
2362
2363 static void
2364 cmd_config_rss_hash_key_parsed(void *parsed_result,
2365                                __rte_unused struct cmdline *cl,
2366                                __rte_unused void *data)
2367 {
2368         struct cmd_config_rss_hash_key *res = parsed_result;
2369         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2370         uint8_t xdgt0;
2371         uint8_t xdgt1;
2372         int i;
2373         struct rte_eth_dev_info dev_info;
2374         uint8_t hash_key_size;
2375         uint32_t key_len;
2376         int ret;
2377
2378         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2379         if (ret != 0)
2380                 return;
2381
2382         if (dev_info.hash_key_size > 0 &&
2383                         dev_info.hash_key_size <= sizeof(hash_key))
2384                 hash_key_size = dev_info.hash_key_size;
2385         else {
2386                 printf("dev_info did not provide a valid hash key size\n");
2387                 return;
2388         }
2389         /* Check the length of the RSS hash key */
2390         key_len = strlen(res->key);
2391         if (key_len != (hash_key_size * 2)) {
2392                 printf("key length: %d invalid - key must be a string of %d"
2393                            " hexa-decimal numbers\n",
2394                            (int) key_len, hash_key_size * 2);
2395                 return;
2396         }
2397         /* Translate RSS hash key into binary representation */
2398         for (i = 0; i < hash_key_size; i++) {
2399                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2400                 if (xdgt0 == 0xFF)
2401                         return;
2402                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2403                 if (xdgt1 == 0xFF)
2404                         return;
2405                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2406         }
2407         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2408                         hash_key_size);
2409 }
2410
2411 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2413 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2414         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2415                                  "config");
2416 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2417         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2420                                  rss_hash_key, "rss-hash-key");
2421 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2422         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2423                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2424                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2425                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2426                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2427                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2428                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2429                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2430 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2432
2433 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2434         .f = cmd_config_rss_hash_key_parsed,
2435         .data = NULL,
2436         .help_str = "port config <port_id> rss-hash-key "
2437                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2438                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2439                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2440                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2441                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2442                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2443                 "<string of hex digits (variable length, NIC dependent)>",
2444         .tokens = {
2445                 (void *)&cmd_config_rss_hash_key_port,
2446                 (void *)&cmd_config_rss_hash_key_config,
2447                 (void *)&cmd_config_rss_hash_key_port_id,
2448                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2449                 (void *)&cmd_config_rss_hash_key_rss_type,
2450                 (void *)&cmd_config_rss_hash_key_value,
2451                 NULL,
2452         },
2453 };
2454
2455 /* *** configure port rxq/txq ring size *** */
2456 struct cmd_config_rxtx_ring_size {
2457         cmdline_fixed_string_t port;
2458         cmdline_fixed_string_t config;
2459         portid_t portid;
2460         cmdline_fixed_string_t rxtxq;
2461         uint16_t qid;
2462         cmdline_fixed_string_t rsize;
2463         uint16_t size;
2464 };
2465
2466 static void
2467 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2468                                  __rte_unused struct cmdline *cl,
2469                                  __rte_unused void *data)
2470 {
2471         struct cmd_config_rxtx_ring_size *res = parsed_result;
2472         struct rte_port *port;
2473         uint8_t isrx;
2474
2475         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2476                 return;
2477
2478         if (res->portid == (portid_t)RTE_PORT_ALL) {
2479                 printf("Invalid port id\n");
2480                 return;
2481         }
2482
2483         port = &ports[res->portid];
2484
2485         if (!strcmp(res->rxtxq, "rxq"))
2486                 isrx = 1;
2487         else if (!strcmp(res->rxtxq, "txq"))
2488                 isrx = 0;
2489         else {
2490                 printf("Unknown parameter\n");
2491                 return;
2492         }
2493
2494         if (isrx && rx_queue_id_is_invalid(res->qid))
2495                 return;
2496         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2497                 return;
2498
2499         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2500                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2501                        rx_free_thresh);
2502                 return;
2503         }
2504
2505         if (isrx)
2506                 port->nb_rx_desc[res->qid] = res->size;
2507         else
2508                 port->nb_tx_desc[res->qid] = res->size;
2509
2510         cmd_reconfig_device_queue(res->portid, 0, 1);
2511 }
2512
2513 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2514         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2515                                  port, "port");
2516 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2517         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2518                                  config, "config");
2519 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2520         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2521                                  portid, UINT16);
2522 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2523         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2524                                  rxtxq, "rxq#txq");
2525 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2526         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2527                               qid, UINT16);
2528 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2529         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2530                                  rsize, "ring_size");
2531 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2532         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2533                               size, UINT16);
2534
2535 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2536         .f = cmd_config_rxtx_ring_size_parsed,
2537         .data = NULL,
2538         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2539         .tokens = {
2540                 (void *)&cmd_config_rxtx_ring_size_port,
2541                 (void *)&cmd_config_rxtx_ring_size_config,
2542                 (void *)&cmd_config_rxtx_ring_size_portid,
2543                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2544                 (void *)&cmd_config_rxtx_ring_size_qid,
2545                 (void *)&cmd_config_rxtx_ring_size_rsize,
2546                 (void *)&cmd_config_rxtx_ring_size_size,
2547                 NULL,
2548         },
2549 };
2550
2551 /* *** configure port rxq/txq start/stop *** */
2552 struct cmd_config_rxtx_queue {
2553         cmdline_fixed_string_t port;
2554         portid_t portid;
2555         cmdline_fixed_string_t rxtxq;
2556         uint16_t qid;
2557         cmdline_fixed_string_t opname;
2558 };
2559
2560 static void
2561 cmd_config_rxtx_queue_parsed(void *parsed_result,
2562                         __rte_unused struct cmdline *cl,
2563                         __rte_unused void *data)
2564 {
2565         struct cmd_config_rxtx_queue *res = parsed_result;
2566         uint8_t isrx;
2567         uint8_t isstart;
2568         int ret = 0;
2569
2570         if (test_done == 0) {
2571                 printf("Please stop forwarding first\n");
2572                 return;
2573         }
2574
2575         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2576                 return;
2577
2578         if (port_is_started(res->portid) != 1) {
2579                 printf("Please start port %u first\n", res->portid);
2580                 return;
2581         }
2582
2583         if (!strcmp(res->rxtxq, "rxq"))
2584                 isrx = 1;
2585         else if (!strcmp(res->rxtxq, "txq"))
2586                 isrx = 0;
2587         else {
2588                 printf("Unknown parameter\n");
2589                 return;
2590         }
2591
2592         if (isrx && rx_queue_id_is_invalid(res->qid))
2593                 return;
2594         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2595                 return;
2596
2597         if (!strcmp(res->opname, "start"))
2598                 isstart = 1;
2599         else if (!strcmp(res->opname, "stop"))
2600                 isstart = 0;
2601         else {
2602                 printf("Unknown parameter\n");
2603                 return;
2604         }
2605
2606         if (isstart && isrx)
2607                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2608         else if (!isstart && isrx)
2609                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2610         else if (isstart && !isrx)
2611                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2612         else
2613                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2614
2615         if (ret == -ENOTSUP)
2616                 printf("Function not supported in PMD driver\n");
2617 }
2618
2619 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2621 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2622         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2623 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2625 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2626         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2627 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2628         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2629                                                 "start#stop");
2630
2631 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2632         .f = cmd_config_rxtx_queue_parsed,
2633         .data = NULL,
2634         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2635         .tokens = {
2636                 (void *)&cmd_config_rxtx_queue_port,
2637                 (void *)&cmd_config_rxtx_queue_portid,
2638                 (void *)&cmd_config_rxtx_queue_rxtxq,
2639                 (void *)&cmd_config_rxtx_queue_qid,
2640                 (void *)&cmd_config_rxtx_queue_opname,
2641                 NULL,
2642         },
2643 };
2644
2645 /* *** configure port rxq/txq deferred start on/off *** */
2646 struct cmd_config_deferred_start_rxtx_queue {
2647         cmdline_fixed_string_t port;
2648         portid_t port_id;
2649         cmdline_fixed_string_t rxtxq;
2650         uint16_t qid;
2651         cmdline_fixed_string_t opname;
2652         cmdline_fixed_string_t state;
2653 };
2654
2655 static void
2656 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2657                         __rte_unused struct cmdline *cl,
2658                         __rte_unused void *data)
2659 {
2660         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2661         struct rte_port *port;
2662         uint8_t isrx;
2663         uint8_t ison;
2664         uint8_t needreconfig = 0;
2665
2666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2667                 return;
2668
2669         if (port_is_started(res->port_id) != 0) {
2670                 printf("Please stop port %u first\n", res->port_id);
2671                 return;
2672         }
2673
2674         port = &ports[res->port_id];
2675
2676         isrx = !strcmp(res->rxtxq, "rxq");
2677
2678         if (isrx && rx_queue_id_is_invalid(res->qid))
2679                 return;
2680         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2681                 return;
2682
2683         ison = !strcmp(res->state, "on");
2684
2685         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2686                 port->rx_conf[res->qid].rx_deferred_start = ison;
2687                 needreconfig = 1;
2688         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2689                 port->tx_conf[res->qid].tx_deferred_start = ison;
2690                 needreconfig = 1;
2691         }
2692
2693         if (needreconfig)
2694                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2695 }
2696
2697 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2698         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2699                                                 port, "port");
2700 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2701         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2702                                                 port_id, UINT16);
2703 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2705                                                 rxtxq, "rxq#txq");
2706 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2708                                                 qid, UINT16);
2709 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2710         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2711                                                 opname, "deferred_start");
2712 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2713         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2714                                                 state, "on#off");
2715
2716 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2717         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2718         .data = NULL,
2719         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2720         .tokens = {
2721                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2722                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2723                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2724                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2725                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2726                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2727                 NULL,
2728         },
2729 };
2730
2731 /* *** configure port rxq/txq setup *** */
2732 struct cmd_setup_rxtx_queue {
2733         cmdline_fixed_string_t port;
2734         portid_t portid;
2735         cmdline_fixed_string_t rxtxq;
2736         uint16_t qid;
2737         cmdline_fixed_string_t setup;
2738 };
2739
2740 /* Common CLI fields for queue setup */
2741 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2742         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2743 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2744         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2745 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2746         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2747 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2749 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2750         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2751
2752 static void
2753 cmd_setup_rxtx_queue_parsed(
2754         void *parsed_result,
2755         __rte_unused struct cmdline *cl,
2756         __rte_unused void *data)
2757 {
2758         struct cmd_setup_rxtx_queue *res = parsed_result;
2759         struct rte_port *port;
2760         struct rte_mempool *mp;
2761         unsigned int socket_id;
2762         uint8_t isrx = 0;
2763         int ret;
2764
2765         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2766                 return;
2767
2768         if (res->portid == (portid_t)RTE_PORT_ALL) {
2769                 printf("Invalid port id\n");
2770                 return;
2771         }
2772
2773         if (!strcmp(res->rxtxq, "rxq"))
2774                 isrx = 1;
2775         else if (!strcmp(res->rxtxq, "txq"))
2776                 isrx = 0;
2777         else {
2778                 printf("Unknown parameter\n");
2779                 return;
2780         }
2781
2782         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2783                 printf("Invalid rx queue\n");
2784                 return;
2785         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2786                 printf("Invalid tx queue\n");
2787                 return;
2788         }
2789
2790         port = &ports[res->portid];
2791         if (isrx) {
2792                 socket_id = rxring_numa[res->portid];
2793                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2794                         socket_id = port->socket_id;
2795
2796                 mp = mbuf_pool_find(socket_id, 0);
2797                 if (mp == NULL) {
2798                         printf("Failed to setup RX queue: "
2799                                 "No mempool allocation"
2800                                 " on the socket %d\n",
2801                                 rxring_numa[res->portid]);
2802                         return;
2803                 }
2804                 ret = rx_queue_setup(res->portid,
2805                                      res->qid,
2806                                      port->nb_rx_desc[res->qid],
2807                                      socket_id,
2808                                      &port->rx_conf[res->qid],
2809                                      mp);
2810                 if (ret)
2811                         printf("Failed to setup RX queue\n");
2812         } else {
2813                 socket_id = txring_numa[res->portid];
2814                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2815                         socket_id = port->socket_id;
2816
2817                 ret = rte_eth_tx_queue_setup(res->portid,
2818                                              res->qid,
2819                                              port->nb_tx_desc[res->qid],
2820                                              socket_id,
2821                                              &port->tx_conf[res->qid]);
2822                 if (ret)
2823                         printf("Failed to setup TX queue\n");
2824         }
2825 }
2826
2827 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2828         .f = cmd_setup_rxtx_queue_parsed,
2829         .data = NULL,
2830         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2831         .tokens = {
2832                 (void *)&cmd_setup_rxtx_queue_port,
2833                 (void *)&cmd_setup_rxtx_queue_portid,
2834                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2835                 (void *)&cmd_setup_rxtx_queue_qid,
2836                 (void *)&cmd_setup_rxtx_queue_setup,
2837                 NULL,
2838         },
2839 };
2840
2841
2842 /* *** Configure RSS RETA *** */
2843 struct cmd_config_rss_reta {
2844         cmdline_fixed_string_t port;
2845         cmdline_fixed_string_t keyword;
2846         portid_t port_id;
2847         cmdline_fixed_string_t name;
2848         cmdline_fixed_string_t list_name;
2849         cmdline_fixed_string_t list_of_items;
2850 };
2851
2852 static int
2853 parse_reta_config(const char *str,
2854                   struct rte_eth_rss_reta_entry64 *reta_conf,
2855                   uint16_t nb_entries)
2856 {
2857         int i;
2858         unsigned size;
2859         uint16_t hash_index, idx, shift;
2860         uint16_t nb_queue;
2861         char s[256];
2862         const char *p, *p0 = str;
2863         char *end;
2864         enum fieldnames {
2865                 FLD_HASH_INDEX = 0,
2866                 FLD_QUEUE,
2867                 _NUM_FLD
2868         };
2869         unsigned long int_fld[_NUM_FLD];
2870         char *str_fld[_NUM_FLD];
2871
2872         while ((p = strchr(p0,'(')) != NULL) {
2873                 ++p;
2874                 if((p0 = strchr(p,')')) == NULL)
2875                         return -1;
2876
2877                 size = p0 - p;
2878                 if(size >= sizeof(s))
2879                         return -1;
2880
2881                 snprintf(s, sizeof(s), "%.*s", size, p);
2882                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2883                         return -1;
2884                 for (i = 0; i < _NUM_FLD; i++) {
2885                         errno = 0;
2886                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2887                         if (errno != 0 || end == str_fld[i] ||
2888                                         int_fld[i] > 65535)
2889                                 return -1;
2890                 }
2891
2892                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2893                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2894
2895                 if (hash_index >= nb_entries) {
2896                         printf("Invalid RETA hash index=%d\n", hash_index);
2897                         return -1;
2898                 }
2899
2900                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2901                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2902                 reta_conf[idx].mask |= (1ULL << shift);
2903                 reta_conf[idx].reta[shift] = nb_queue;
2904         }
2905
2906         return 0;
2907 }
2908
2909 static void
2910 cmd_set_rss_reta_parsed(void *parsed_result,
2911                         __rte_unused struct cmdline *cl,
2912                         __rte_unused void *data)
2913 {
2914         int ret;
2915         struct rte_eth_dev_info dev_info;
2916         struct rte_eth_rss_reta_entry64 reta_conf[8];
2917         struct cmd_config_rss_reta *res = parsed_result;
2918
2919         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2920         if (ret != 0)
2921                 return;
2922
2923         if (dev_info.reta_size == 0) {
2924                 printf("Redirection table size is 0 which is "
2925                                         "invalid for RSS\n");
2926                 return;
2927         } else
2928                 printf("The reta size of port %d is %u\n",
2929                         res->port_id, dev_info.reta_size);
2930         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2931                 printf("Currently do not support more than %u entries of "
2932                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2933                 return;
2934         }
2935
2936         memset(reta_conf, 0, sizeof(reta_conf));
2937         if (!strcmp(res->list_name, "reta")) {
2938                 if (parse_reta_config(res->list_of_items, reta_conf,
2939                                                 dev_info.reta_size)) {
2940                         printf("Invalid RSS Redirection Table "
2941                                         "config entered\n");
2942                         return;
2943                 }
2944                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2945                                 reta_conf, dev_info.reta_size);
2946                 if (ret != 0)
2947                         printf("Bad redirection table parameter, "
2948                                         "return code = %d \n", ret);
2949         }
2950 }
2951
2952 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2954 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2956 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2957         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2958 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2960 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2961         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2962 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2963         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2964                                  NULL);
2965 cmdline_parse_inst_t cmd_config_rss_reta = {
2966         .f = cmd_set_rss_reta_parsed,
2967         .data = NULL,
2968         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2969         .tokens = {
2970                 (void *)&cmd_config_rss_reta_port,
2971                 (void *)&cmd_config_rss_reta_keyword,
2972                 (void *)&cmd_config_rss_reta_port_id,
2973                 (void *)&cmd_config_rss_reta_name,
2974                 (void *)&cmd_config_rss_reta_list_name,
2975                 (void *)&cmd_config_rss_reta_list_of_items,
2976                 NULL,
2977         },
2978 };
2979
2980 /* *** SHOW PORT RETA INFO *** */
2981 struct cmd_showport_reta {
2982         cmdline_fixed_string_t show;
2983         cmdline_fixed_string_t port;
2984         portid_t port_id;
2985         cmdline_fixed_string_t rss;
2986         cmdline_fixed_string_t reta;
2987         uint16_t size;
2988         cmdline_fixed_string_t list_of_items;
2989 };
2990
2991 static int
2992 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2993                            uint16_t nb_entries,
2994                            char *str)
2995 {
2996         uint32_t size;
2997         const char *p, *p0 = str;
2998         char s[256];
2999         char *end;
3000         char *str_fld[8];
3001         uint16_t i;
3002         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3003                         RTE_RETA_GROUP_SIZE;
3004         int ret;
3005
3006         p = strchr(p0, '(');
3007         if (p == NULL)
3008                 return -1;
3009         p++;
3010         p0 = strchr(p, ')');
3011         if (p0 == NULL)
3012                 return -1;
3013         size = p0 - p;
3014         if (size >= sizeof(s)) {
3015                 printf("The string size exceeds the internal buffer size\n");
3016                 return -1;
3017         }
3018         snprintf(s, sizeof(s), "%.*s", size, p);
3019         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3020         if (ret <= 0 || ret != num) {
3021                 printf("The bits of masks do not match the number of "
3022                                         "reta entries: %u\n", num);
3023                 return -1;
3024         }
3025         for (i = 0; i < ret; i++)
3026                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3027
3028         return 0;
3029 }
3030
3031 static void
3032 cmd_showport_reta_parsed(void *parsed_result,
3033                          __rte_unused struct cmdline *cl,
3034                          __rte_unused void *data)
3035 {
3036         struct cmd_showport_reta *res = parsed_result;
3037         struct rte_eth_rss_reta_entry64 reta_conf[8];
3038         struct rte_eth_dev_info dev_info;
3039         uint16_t max_reta_size;
3040         int ret;
3041
3042         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3043         if (ret != 0)
3044                 return;
3045
3046         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3047         if (res->size == 0 || res->size > max_reta_size) {
3048                 printf("Invalid redirection table size: %u (1-%u)\n",
3049                         res->size, max_reta_size);
3050                 return;
3051         }
3052
3053         memset(reta_conf, 0, sizeof(reta_conf));
3054         if (showport_parse_reta_config(reta_conf, res->size,
3055                                 res->list_of_items) < 0) {
3056                 printf("Invalid string: %s for reta masks\n",
3057                                         res->list_of_items);
3058                 return;
3059         }
3060         port_rss_reta_info(res->port_id, reta_conf, res->size);
3061 }
3062
3063 cmdline_parse_token_string_t cmd_showport_reta_show =
3064         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3065 cmdline_parse_token_string_t cmd_showport_reta_port =
3066         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3067 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3068         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3069 cmdline_parse_token_string_t cmd_showport_reta_rss =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3071 cmdline_parse_token_string_t cmd_showport_reta_reta =
3072         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3073 cmdline_parse_token_num_t cmd_showport_reta_size =
3074         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3075 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3077                                         list_of_items, NULL);
3078
3079 cmdline_parse_inst_t cmd_showport_reta = {
3080         .f = cmd_showport_reta_parsed,
3081         .data = NULL,
3082         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3083         .tokens = {
3084                 (void *)&cmd_showport_reta_show,
3085                 (void *)&cmd_showport_reta_port,
3086                 (void *)&cmd_showport_reta_port_id,
3087                 (void *)&cmd_showport_reta_rss,
3088                 (void *)&cmd_showport_reta_reta,
3089                 (void *)&cmd_showport_reta_size,
3090                 (void *)&cmd_showport_reta_list_of_items,
3091                 NULL,
3092         },
3093 };
3094
3095 /* *** Show RSS hash configuration *** */
3096 struct cmd_showport_rss_hash {
3097         cmdline_fixed_string_t show;
3098         cmdline_fixed_string_t port;
3099         portid_t port_id;
3100         cmdline_fixed_string_t rss_hash;
3101         cmdline_fixed_string_t rss_type;
3102         cmdline_fixed_string_t key; /* optional argument */
3103 };
3104
3105 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3106                                 __rte_unused struct cmdline *cl,
3107                                 void *show_rss_key)
3108 {
3109         struct cmd_showport_rss_hash *res = parsed_result;
3110
3111         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3112 }
3113
3114 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3115         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3116 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3117         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3118 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3119         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3120 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3121         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3122                                  "rss-hash");
3123 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3124         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3125
3126 cmdline_parse_inst_t cmd_showport_rss_hash = {
3127         .f = cmd_showport_rss_hash_parsed,
3128         .data = NULL,
3129         .help_str = "show port <port_id> rss-hash",
3130         .tokens = {
3131                 (void *)&cmd_showport_rss_hash_show,
3132                 (void *)&cmd_showport_rss_hash_port,
3133                 (void *)&cmd_showport_rss_hash_port_id,
3134                 (void *)&cmd_showport_rss_hash_rss_hash,
3135                 NULL,
3136         },
3137 };
3138
3139 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3140         .f = cmd_showport_rss_hash_parsed,
3141         .data = (void *)1,
3142         .help_str = "show port <port_id> rss-hash key",
3143         .tokens = {
3144                 (void *)&cmd_showport_rss_hash_show,
3145                 (void *)&cmd_showport_rss_hash_port,
3146                 (void *)&cmd_showport_rss_hash_port_id,
3147                 (void *)&cmd_showport_rss_hash_rss_hash,
3148                 (void *)&cmd_showport_rss_hash_rss_key,
3149                 NULL,
3150         },
3151 };
3152
3153 /* *** Configure DCB *** */
3154 struct cmd_config_dcb {
3155         cmdline_fixed_string_t port;
3156         cmdline_fixed_string_t config;
3157         portid_t port_id;
3158         cmdline_fixed_string_t dcb;
3159         cmdline_fixed_string_t vt;
3160         cmdline_fixed_string_t vt_en;
3161         uint8_t num_tcs;
3162         cmdline_fixed_string_t pfc;
3163         cmdline_fixed_string_t pfc_en;
3164 };
3165
3166 static void
3167 cmd_config_dcb_parsed(void *parsed_result,
3168                         __rte_unused struct cmdline *cl,
3169                         __rte_unused void *data)
3170 {
3171         struct cmd_config_dcb *res = parsed_result;
3172         portid_t port_id = res->port_id;
3173         struct rte_port *port;
3174         uint8_t pfc_en;
3175         int ret;
3176
3177         port = &ports[port_id];
3178         /** Check if the port is not started **/
3179         if (port->port_status != RTE_PORT_STOPPED) {
3180                 printf("Please stop port %d first\n", port_id);
3181                 return;
3182         }
3183
3184         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3185                 printf("The invalid number of traffic class,"
3186                         " only 4 or 8 allowed.\n");
3187                 return;
3188         }
3189
3190         if (nb_fwd_lcores < res->num_tcs) {
3191                 printf("nb_cores shouldn't be less than number of TCs.\n");
3192                 return;
3193         }
3194         if (!strncmp(res->pfc_en, "on", 2))
3195                 pfc_en = 1;
3196         else
3197                 pfc_en = 0;
3198
3199         /* DCB in VT mode */
3200         if (!strncmp(res->vt_en, "on", 2))
3201                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3202                                 (enum rte_eth_nb_tcs)res->num_tcs,
3203                                 pfc_en);
3204         else
3205                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3206                                 (enum rte_eth_nb_tcs)res->num_tcs,
3207                                 pfc_en);
3208
3209
3210         if (ret != 0) {
3211                 printf("Cannot initialize network ports.\n");
3212                 return;
3213         }
3214
3215         cmd_reconfig_device_queue(port_id, 1, 1);
3216 }
3217
3218 cmdline_parse_token_string_t cmd_config_dcb_port =
3219         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3220 cmdline_parse_token_string_t cmd_config_dcb_config =
3221         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3222 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3223         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3224 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3225         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3226 cmdline_parse_token_string_t cmd_config_dcb_vt =
3227         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3228 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3229         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3230 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3231         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3232 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3233         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3234 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3235         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3236
3237 cmdline_parse_inst_t cmd_config_dcb = {
3238         .f = cmd_config_dcb_parsed,
3239         .data = NULL,
3240         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3241         .tokens = {
3242                 (void *)&cmd_config_dcb_port,
3243                 (void *)&cmd_config_dcb_config,
3244                 (void *)&cmd_config_dcb_port_id,
3245                 (void *)&cmd_config_dcb_dcb,
3246                 (void *)&cmd_config_dcb_vt,
3247                 (void *)&cmd_config_dcb_vt_en,
3248                 (void *)&cmd_config_dcb_num_tcs,
3249                 (void *)&cmd_config_dcb_pfc,
3250                 (void *)&cmd_config_dcb_pfc_en,
3251                 NULL,
3252         },
3253 };
3254
3255 /* *** configure number of packets per burst *** */
3256 struct cmd_config_burst {
3257         cmdline_fixed_string_t port;
3258         cmdline_fixed_string_t keyword;
3259         cmdline_fixed_string_t all;
3260         cmdline_fixed_string_t name;
3261         uint16_t value;
3262 };
3263
3264 static void
3265 cmd_config_burst_parsed(void *parsed_result,
3266                         __rte_unused struct cmdline *cl,
3267                         __rte_unused void *data)
3268 {
3269         struct cmd_config_burst *res = parsed_result;
3270         struct rte_eth_dev_info dev_info;
3271         uint16_t rec_nb_pkts;
3272         int ret;
3273
3274         if (!all_ports_stopped()) {
3275                 printf("Please stop all ports first\n");
3276                 return;
3277         }
3278
3279         if (!strcmp(res->name, "burst")) {
3280                 if (res->value == 0) {
3281                         /* If user gives a value of zero, query the PMD for
3282                          * its recommended Rx burst size. Testpmd uses a single
3283                          * size for all ports, so assume all ports are the same
3284                          * NIC model and use the values from Port 0.
3285                          */
3286                         ret = eth_dev_info_get_print_err(0, &dev_info);
3287                         if (ret != 0)
3288                                 return;
3289
3290                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3291
3292                         if (rec_nb_pkts == 0) {
3293                                 printf("PMD does not recommend a burst size.\n"
3294                                         "User provided value must be between"
3295                                         " 1 and %d\n", MAX_PKT_BURST);
3296                                 return;
3297                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3298                                 printf("PMD recommended burst size of %d"
3299                                         " exceeds maximum value of %d\n",
3300                                         rec_nb_pkts, MAX_PKT_BURST);
3301                                 return;
3302                         }
3303                         printf("Using PMD-provided burst value of %d\n",
3304                                 rec_nb_pkts);
3305                         nb_pkt_per_burst = rec_nb_pkts;
3306                 } else if (res->value > MAX_PKT_BURST) {
3307                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3308                         return;
3309                 } else
3310                         nb_pkt_per_burst = res->value;
3311         } else {
3312                 printf("Unknown parameter\n");
3313                 return;
3314         }
3315
3316         init_port_config();
3317
3318         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3319 }
3320
3321 cmdline_parse_token_string_t cmd_config_burst_port =
3322         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3323 cmdline_parse_token_string_t cmd_config_burst_keyword =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3325 cmdline_parse_token_string_t cmd_config_burst_all =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3327 cmdline_parse_token_string_t cmd_config_burst_name =
3328         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3329 cmdline_parse_token_num_t cmd_config_burst_value =
3330         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3331
3332 cmdline_parse_inst_t cmd_config_burst = {
3333         .f = cmd_config_burst_parsed,
3334         .data = NULL,
3335         .help_str = "port config all burst <value>",
3336         .tokens = {
3337                 (void *)&cmd_config_burst_port,
3338                 (void *)&cmd_config_burst_keyword,
3339                 (void *)&cmd_config_burst_all,
3340                 (void *)&cmd_config_burst_name,
3341                 (void *)&cmd_config_burst_value,
3342                 NULL,
3343         },
3344 };
3345
3346 /* *** configure rx/tx queues *** */
3347 struct cmd_config_thresh {
3348         cmdline_fixed_string_t port;
3349         cmdline_fixed_string_t keyword;
3350         cmdline_fixed_string_t all;
3351         cmdline_fixed_string_t name;
3352         uint8_t value;
3353 };
3354
3355 static void
3356 cmd_config_thresh_parsed(void *parsed_result,
3357                         __rte_unused struct cmdline *cl,
3358                         __rte_unused void *data)
3359 {
3360         struct cmd_config_thresh *res = parsed_result;
3361
3362         if (!all_ports_stopped()) {
3363                 printf("Please stop all ports first\n");
3364                 return;
3365         }
3366
3367         if (!strcmp(res->name, "txpt"))
3368                 tx_pthresh = res->value;
3369         else if(!strcmp(res->name, "txht"))
3370                 tx_hthresh = res->value;
3371         else if(!strcmp(res->name, "txwt"))
3372                 tx_wthresh = res->value;
3373         else if(!strcmp(res->name, "rxpt"))
3374                 rx_pthresh = res->value;
3375         else if(!strcmp(res->name, "rxht"))
3376                 rx_hthresh = res->value;
3377         else if(!strcmp(res->name, "rxwt"))
3378                 rx_wthresh = res->value;
3379         else {
3380                 printf("Unknown parameter\n");
3381                 return;
3382         }
3383
3384         init_port_config();
3385
3386         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3387 }
3388
3389 cmdline_parse_token_string_t cmd_config_thresh_port =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3391 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3393 cmdline_parse_token_string_t cmd_config_thresh_all =
3394         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3395 cmdline_parse_token_string_t cmd_config_thresh_name =
3396         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3397                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3398 cmdline_parse_token_num_t cmd_config_thresh_value =
3399         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3400
3401 cmdline_parse_inst_t cmd_config_thresh = {
3402         .f = cmd_config_thresh_parsed,
3403         .data = NULL,
3404         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3405         .tokens = {
3406                 (void *)&cmd_config_thresh_port,
3407                 (void *)&cmd_config_thresh_keyword,
3408                 (void *)&cmd_config_thresh_all,
3409                 (void *)&cmd_config_thresh_name,
3410                 (void *)&cmd_config_thresh_value,
3411                 NULL,
3412         },
3413 };
3414
3415 /* *** configure free/rs threshold *** */
3416 struct cmd_config_threshold {
3417         cmdline_fixed_string_t port;
3418         cmdline_fixed_string_t keyword;
3419         cmdline_fixed_string_t all;
3420         cmdline_fixed_string_t name;
3421         uint16_t value;
3422 };
3423
3424 static void
3425 cmd_config_threshold_parsed(void *parsed_result,
3426                         __rte_unused struct cmdline *cl,
3427                         __rte_unused void *data)
3428 {
3429         struct cmd_config_threshold *res = parsed_result;
3430
3431         if (!all_ports_stopped()) {
3432                 printf("Please stop all ports first\n");
3433                 return;
3434         }
3435
3436         if (!strcmp(res->name, "txfreet"))
3437                 tx_free_thresh = res->value;
3438         else if (!strcmp(res->name, "txrst"))
3439                 tx_rs_thresh = res->value;
3440         else if (!strcmp(res->name, "rxfreet"))
3441                 rx_free_thresh = res->value;
3442         else {
3443                 printf("Unknown parameter\n");
3444                 return;
3445         }
3446
3447         init_port_config();
3448
3449         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3450 }
3451
3452 cmdline_parse_token_string_t cmd_config_threshold_port =
3453         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3454 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3455         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3456                                                                 "config");
3457 cmdline_parse_token_string_t cmd_config_threshold_all =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3459 cmdline_parse_token_string_t cmd_config_threshold_name =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3461                                                 "txfreet#txrst#rxfreet");
3462 cmdline_parse_token_num_t cmd_config_threshold_value =
3463         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3464
3465 cmdline_parse_inst_t cmd_config_threshold = {
3466         .f = cmd_config_threshold_parsed,
3467         .data = NULL,
3468         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3469         .tokens = {
3470                 (void *)&cmd_config_threshold_port,
3471                 (void *)&cmd_config_threshold_keyword,
3472                 (void *)&cmd_config_threshold_all,
3473                 (void *)&cmd_config_threshold_name,
3474                 (void *)&cmd_config_threshold_value,
3475                 NULL,
3476         },
3477 };
3478
3479 /* *** stop *** */
3480 struct cmd_stop_result {
3481         cmdline_fixed_string_t stop;
3482 };
3483
3484 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3485                             __rte_unused struct cmdline *cl,
3486                             __rte_unused void *data)
3487 {
3488         stop_packet_forwarding();
3489 }
3490
3491 cmdline_parse_token_string_t cmd_stop_stop =
3492         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3493
3494 cmdline_parse_inst_t cmd_stop = {
3495         .f = cmd_stop_parsed,
3496         .data = NULL,
3497         .help_str = "stop: Stop packet forwarding",
3498         .tokens = {
3499                 (void *)&cmd_stop_stop,
3500                 NULL,
3501         },
3502 };
3503
3504 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3505
3506 unsigned int
3507 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3508                 unsigned int *parsed_items, int check_unique_values)
3509 {
3510         unsigned int nb_item;
3511         unsigned int value;
3512         unsigned int i;
3513         unsigned int j;
3514         int value_ok;
3515         char c;
3516
3517         /*
3518          * First parse all items in the list and store their value.
3519          */
3520         value = 0;
3521         nb_item = 0;
3522         value_ok = 0;
3523         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3524                 c = str[i];
3525                 if ((c >= '0') && (c <= '9')) {
3526                         value = (unsigned int) (value * 10 + (c - '0'));
3527                         value_ok = 1;
3528                         continue;
3529                 }
3530                 if (c != ',') {
3531                         printf("character %c is not a decimal digit\n", c);
3532                         return 0;
3533                 }
3534                 if (! value_ok) {
3535                         printf("No valid value before comma\n");
3536                         return 0;
3537                 }
3538                 if (nb_item < max_items) {
3539                         parsed_items[nb_item] = value;
3540                         value_ok = 0;
3541                         value = 0;
3542                 }
3543                 nb_item++;
3544         }
3545         if (nb_item >= max_items) {
3546                 printf("Number of %s = %u > %u (maximum items)\n",
3547                        item_name, nb_item + 1, max_items);
3548                 return 0;
3549         }
3550         parsed_items[nb_item++] = value;
3551         if (! check_unique_values)
3552                 return nb_item;
3553
3554         /*
3555          * Then, check that all values in the list are differents.
3556          * No optimization here...
3557          */
3558         for (i = 0; i < nb_item; i++) {
3559                 for (j = i + 1; j < nb_item; j++) {
3560                         if (parsed_items[j] == parsed_items[i]) {
3561                                 printf("duplicated %s %u at index %u and %u\n",
3562                                        item_name, parsed_items[i], i, j);
3563                                 return 0;
3564                         }
3565                 }
3566         }
3567         return nb_item;
3568 }
3569
3570 struct cmd_set_list_result {
3571         cmdline_fixed_string_t cmd_keyword;
3572         cmdline_fixed_string_t list_name;
3573         cmdline_fixed_string_t list_of_items;
3574 };
3575
3576 static void cmd_set_list_parsed(void *parsed_result,
3577                                 __rte_unused struct cmdline *cl,
3578                                 __rte_unused void *data)
3579 {
3580         struct cmd_set_list_result *res;
3581         union {
3582                 unsigned int lcorelist[RTE_MAX_LCORE];
3583                 unsigned int portlist[RTE_MAX_ETHPORTS];
3584         } parsed_items;
3585         unsigned int nb_item;
3586
3587         if (test_done == 0) {
3588                 printf("Please stop forwarding first\n");
3589                 return;
3590         }
3591
3592         res = parsed_result;
3593         if (!strcmp(res->list_name, "corelist")) {
3594                 nb_item = parse_item_list(res->list_of_items, "core",
3595                                           RTE_MAX_LCORE,
3596                                           parsed_items.lcorelist, 1);
3597                 if (nb_item > 0) {
3598                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3599                         fwd_config_setup();
3600                 }
3601                 return;
3602         }
3603         if (!strcmp(res->list_name, "portlist")) {
3604                 nb_item = parse_item_list(res->list_of_items, "port",
3605                                           RTE_MAX_ETHPORTS,
3606                                           parsed_items.portlist, 1);
3607                 if (nb_item > 0) {
3608                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3609                         fwd_config_setup();
3610                 }
3611         }
3612 }
3613
3614 cmdline_parse_token_string_t cmd_set_list_keyword =
3615         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3616                                  "set");
3617 cmdline_parse_token_string_t cmd_set_list_name =
3618         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3619                                  "corelist#portlist");
3620 cmdline_parse_token_string_t cmd_set_list_of_items =
3621         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3622                                  NULL);
3623
3624 cmdline_parse_inst_t cmd_set_fwd_list = {
3625         .f = cmd_set_list_parsed,
3626         .data = NULL,
3627         .help_str = "set corelist|portlist <list0[,list1]*>",
3628         .tokens = {
3629                 (void *)&cmd_set_list_keyword,
3630                 (void *)&cmd_set_list_name,
3631                 (void *)&cmd_set_list_of_items,
3632                 NULL,
3633         },
3634 };
3635
3636 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3637
3638 struct cmd_setmask_result {
3639         cmdline_fixed_string_t set;
3640         cmdline_fixed_string_t mask;
3641         uint64_t hexavalue;
3642 };
3643
3644 static void cmd_set_mask_parsed(void *parsed_result,
3645                                 __rte_unused struct cmdline *cl,
3646                                 __rte_unused void *data)
3647 {
3648         struct cmd_setmask_result *res = parsed_result;
3649
3650         if (test_done == 0) {
3651                 printf("Please stop forwarding first\n");
3652                 return;
3653         }
3654         if (!strcmp(res->mask, "coremask")) {
3655                 set_fwd_lcores_mask(res->hexavalue);
3656                 fwd_config_setup();
3657         } else if (!strcmp(res->mask, "portmask")) {
3658                 set_fwd_ports_mask(res->hexavalue);
3659                 fwd_config_setup();
3660         }
3661 }
3662
3663 cmdline_parse_token_string_t cmd_setmask_set =
3664         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3665 cmdline_parse_token_string_t cmd_setmask_mask =
3666         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3667                                  "coremask#portmask");
3668 cmdline_parse_token_num_t cmd_setmask_value =
3669         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3670
3671 cmdline_parse_inst_t cmd_set_fwd_mask = {
3672         .f = cmd_set_mask_parsed,
3673         .data = NULL,
3674         .help_str = "set coremask|portmask <hexadecimal value>",
3675         .tokens = {
3676                 (void *)&cmd_setmask_set,
3677                 (void *)&cmd_setmask_mask,
3678                 (void *)&cmd_setmask_value,
3679                 NULL,
3680         },
3681 };
3682
3683 /*
3684  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3685  */
3686 struct cmd_set_result {
3687         cmdline_fixed_string_t set;
3688         cmdline_fixed_string_t what;
3689         uint16_t value;
3690 };
3691
3692 static void cmd_set_parsed(void *parsed_result,
3693                            __rte_unused struct cmdline *cl,
3694                            __rte_unused void *data)
3695 {
3696         struct cmd_set_result *res = parsed_result;
3697         if (!strcmp(res->what, "nbport")) {
3698                 set_fwd_ports_number(res->value);
3699                 fwd_config_setup();
3700         } else if (!strcmp(res->what, "nbcore")) {
3701                 set_fwd_lcores_number(res->value);
3702                 fwd_config_setup();
3703         } else if (!strcmp(res->what, "burst"))
3704                 set_nb_pkt_per_burst(res->value);
3705         else if (!strcmp(res->what, "verbose"))
3706                 set_verbose_level(res->value);
3707 }
3708
3709 cmdline_parse_token_string_t cmd_set_set =
3710         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3711 cmdline_parse_token_string_t cmd_set_what =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3713                                  "nbport#nbcore#burst#verbose");
3714 cmdline_parse_token_num_t cmd_set_value =
3715         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3716
3717 cmdline_parse_inst_t cmd_set_numbers = {
3718         .f = cmd_set_parsed,
3719         .data = NULL,
3720         .help_str = "set nbport|nbcore|burst|verbose <value>",
3721         .tokens = {
3722                 (void *)&cmd_set_set,
3723                 (void *)&cmd_set_what,
3724                 (void *)&cmd_set_value,
3725                 NULL,
3726         },
3727 };
3728
3729 /* *** SET LOG LEVEL CONFIGURATION *** */
3730
3731 struct cmd_set_log_result {
3732         cmdline_fixed_string_t set;
3733         cmdline_fixed_string_t log;
3734         cmdline_fixed_string_t type;
3735         uint32_t level;
3736 };
3737
3738 static void
3739 cmd_set_log_parsed(void *parsed_result,
3740                    __rte_unused struct cmdline *cl,
3741                    __rte_unused void *data)
3742 {
3743         struct cmd_set_log_result *res;
3744         int ret;
3745
3746         res = parsed_result;
3747         if (!strcmp(res->type, "global"))
3748                 rte_log_set_global_level(res->level);
3749         else {
3750                 ret = rte_log_set_level_regexp(res->type, res->level);
3751                 if (ret < 0)
3752                         printf("Unable to set log level\n");
3753         }
3754 }
3755
3756 cmdline_parse_token_string_t cmd_set_log_set =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3758 cmdline_parse_token_string_t cmd_set_log_log =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3760 cmdline_parse_token_string_t cmd_set_log_type =
3761         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3762 cmdline_parse_token_num_t cmd_set_log_level =
3763         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3764
3765 cmdline_parse_inst_t cmd_set_log = {
3766         .f = cmd_set_log_parsed,
3767         .data = NULL,
3768         .help_str = "set log global|<type> <level>",
3769         .tokens = {
3770                 (void *)&cmd_set_log_set,
3771                 (void *)&cmd_set_log_log,
3772                 (void *)&cmd_set_log_type,
3773                 (void *)&cmd_set_log_level,
3774                 NULL,
3775         },
3776 };
3777
3778 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3779
3780 struct cmd_set_rxoffs_result {
3781         cmdline_fixed_string_t cmd_keyword;
3782         cmdline_fixed_string_t rxoffs;
3783         cmdline_fixed_string_t seg_offsets;
3784 };
3785
3786 static void
3787 cmd_set_rxoffs_parsed(void *parsed_result,
3788                       __rte_unused struct cmdline *cl,
3789                       __rte_unused void *data)
3790 {
3791         struct cmd_set_rxoffs_result *res;
3792         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3793         unsigned int nb_segs;
3794
3795         res = parsed_result;
3796         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3797                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3798         if (nb_segs > 0)
3799                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3800 }
3801
3802 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3803         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3804                                  cmd_keyword, "set");
3805 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3806         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3807                                  rxoffs, "rxoffs");
3808 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3809         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3810                                  seg_offsets, NULL);
3811
3812 cmdline_parse_inst_t cmd_set_rxoffs = {
3813         .f = cmd_set_rxoffs_parsed,
3814         .data = NULL,
3815         .help_str = "set rxoffs <len0[,len1]*>",
3816         .tokens = {
3817                 (void *)&cmd_set_rxoffs_keyword,
3818                 (void *)&cmd_set_rxoffs_name,
3819                 (void *)&cmd_set_rxoffs_offsets,
3820                 NULL,
3821         },
3822 };
3823
3824 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3825
3826 struct cmd_set_rxpkts_result {
3827         cmdline_fixed_string_t cmd_keyword;
3828         cmdline_fixed_string_t rxpkts;
3829         cmdline_fixed_string_t seg_lengths;
3830 };
3831
3832 static void
3833 cmd_set_rxpkts_parsed(void *parsed_result,
3834                       __rte_unused struct cmdline *cl,
3835                       __rte_unused void *data)
3836 {
3837         struct cmd_set_rxpkts_result *res;
3838         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3839         unsigned int nb_segs;
3840
3841         res = parsed_result;
3842         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3843                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3844         if (nb_segs > 0)
3845                 set_rx_pkt_segments(seg_lengths, nb_segs);
3846 }
3847
3848 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3849         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3850                                  cmd_keyword, "set");
3851 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3853                                  rxpkts, "rxpkts");
3854 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3855         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3856                                  seg_lengths, NULL);
3857
3858 cmdline_parse_inst_t cmd_set_rxpkts = {
3859         .f = cmd_set_rxpkts_parsed,
3860         .data = NULL,
3861         .help_str = "set rxpkts <len0[,len1]*>",
3862         .tokens = {
3863                 (void *)&cmd_set_rxpkts_keyword,
3864                 (void *)&cmd_set_rxpkts_name,
3865                 (void *)&cmd_set_rxpkts_lengths,
3866                 NULL,
3867         },
3868 };
3869
3870 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3871
3872 struct cmd_set_txpkts_result {
3873         cmdline_fixed_string_t cmd_keyword;
3874         cmdline_fixed_string_t txpkts;
3875         cmdline_fixed_string_t seg_lengths;
3876 };
3877
3878 static void
3879 cmd_set_txpkts_parsed(void *parsed_result,
3880                       __rte_unused struct cmdline *cl,
3881                       __rte_unused void *data)
3882 {
3883         struct cmd_set_txpkts_result *res;
3884         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3885         unsigned int nb_segs;
3886
3887         res = parsed_result;
3888         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3889                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3890         if (nb_segs > 0)
3891                 set_tx_pkt_segments(seg_lengths, nb_segs);
3892 }
3893
3894 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3895         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3896                                  cmd_keyword, "set");
3897 cmdline_parse_token_string_t cmd_set_txpkts_name =
3898         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3899                                  txpkts, "txpkts");
3900 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3902                                  seg_lengths, NULL);
3903
3904 cmdline_parse_inst_t cmd_set_txpkts = {
3905         .f = cmd_set_txpkts_parsed,
3906         .data = NULL,
3907         .help_str = "set txpkts <len0[,len1]*>",
3908         .tokens = {
3909                 (void *)&cmd_set_txpkts_keyword,
3910                 (void *)&cmd_set_txpkts_name,
3911                 (void *)&cmd_set_txpkts_lengths,
3912                 NULL,
3913         },
3914 };
3915
3916 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3917
3918 struct cmd_set_txsplit_result {
3919         cmdline_fixed_string_t cmd_keyword;
3920         cmdline_fixed_string_t txsplit;
3921         cmdline_fixed_string_t mode;
3922 };
3923
3924 static void
3925 cmd_set_txsplit_parsed(void *parsed_result,
3926                       __rte_unused struct cmdline *cl,
3927                       __rte_unused void *data)
3928 {
3929         struct cmd_set_txsplit_result *res;
3930
3931         res = parsed_result;
3932         set_tx_pkt_split(res->mode);
3933 }
3934
3935 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3936         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3937                                  cmd_keyword, "set");
3938 cmdline_parse_token_string_t cmd_set_txsplit_name =
3939         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3940                                  txsplit, "txsplit");
3941 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3942         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3943                                  mode, NULL);
3944
3945 cmdline_parse_inst_t cmd_set_txsplit = {
3946         .f = cmd_set_txsplit_parsed,
3947         .data = NULL,
3948         .help_str = "set txsplit on|off|rand",
3949         .tokens = {
3950                 (void *)&cmd_set_txsplit_keyword,
3951                 (void *)&cmd_set_txsplit_name,
3952                 (void *)&cmd_set_txsplit_mode,
3953                 NULL,
3954         },
3955 };
3956
3957 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3958
3959 struct cmd_set_txtimes_result {
3960         cmdline_fixed_string_t cmd_keyword;
3961         cmdline_fixed_string_t txtimes;
3962         cmdline_fixed_string_t tx_times;
3963 };
3964
3965 static void
3966 cmd_set_txtimes_parsed(void *parsed_result,
3967                        __rte_unused struct cmdline *cl,
3968                        __rte_unused void *data)
3969 {
3970         struct cmd_set_txtimes_result *res;
3971         unsigned int tx_times[2] = {0, 0};
3972         unsigned int n_times;
3973
3974         res = parsed_result;
3975         n_times = parse_item_list(res->tx_times, "tx times",
3976                                   2, tx_times, 0);
3977         if (n_times == 2)
3978                 set_tx_pkt_times(tx_times);
3979 }
3980
3981 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3982         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3983                                  cmd_keyword, "set");
3984 cmdline_parse_token_string_t cmd_set_txtimes_name =
3985         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3986                                  txtimes, "txtimes");
3987 cmdline_parse_token_string_t cmd_set_txtimes_value =
3988         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3989                                  tx_times, NULL);
3990
3991 cmdline_parse_inst_t cmd_set_txtimes = {
3992         .f = cmd_set_txtimes_parsed,
3993         .data = NULL,
3994         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3995         .tokens = {
3996                 (void *)&cmd_set_txtimes_keyword,
3997                 (void *)&cmd_set_txtimes_name,
3998                 (void *)&cmd_set_txtimes_value,
3999                 NULL,
4000         },
4001 };
4002
4003 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4004 struct cmd_rx_vlan_filter_all_result {
4005         cmdline_fixed_string_t rx_vlan;
4006         cmdline_fixed_string_t what;
4007         cmdline_fixed_string_t all;
4008         portid_t port_id;
4009 };
4010
4011 static void
4012 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4013                               __rte_unused struct cmdline *cl,
4014                               __rte_unused void *data)
4015 {
4016         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4017
4018         if (!strcmp(res->what, "add"))
4019                 rx_vlan_all_filter_set(res->port_id, 1);
4020         else
4021                 rx_vlan_all_filter_set(res->port_id, 0);
4022 }
4023
4024 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4025         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4026                                  rx_vlan, "rx_vlan");
4027 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4028         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4029                                  what, "add#rm");
4030 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4031         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4032                                  all, "all");
4033 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4034         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4035                               port_id, UINT16);
4036
4037 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4038         .f = cmd_rx_vlan_filter_all_parsed,
4039         .data = NULL,
4040         .help_str = "rx_vlan add|rm all <port_id>: "
4041                 "Add/Remove all identifiers to/from the set of VLAN "
4042                 "identifiers filtered by a port",
4043         .tokens = {
4044                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4045                 (void *)&cmd_rx_vlan_filter_all_what,
4046                 (void *)&cmd_rx_vlan_filter_all_all,
4047                 (void *)&cmd_rx_vlan_filter_all_portid,
4048                 NULL,
4049         },
4050 };
4051
4052 /* *** VLAN OFFLOAD SET ON A PORT *** */
4053 struct cmd_vlan_offload_result {
4054         cmdline_fixed_string_t vlan;
4055         cmdline_fixed_string_t set;
4056         cmdline_fixed_string_t vlan_type;
4057         cmdline_fixed_string_t what;
4058         cmdline_fixed_string_t on;
4059         cmdline_fixed_string_t port_id;
4060 };
4061
4062 static void
4063 cmd_vlan_offload_parsed(void *parsed_result,
4064                           __rte_unused struct cmdline *cl,
4065                           __rte_unused void *data)
4066 {
4067         int on;
4068         struct cmd_vlan_offload_result *res = parsed_result;
4069         char *str;
4070         int i, len = 0;
4071         portid_t port_id = 0;
4072         unsigned int tmp;
4073
4074         str = res->port_id;
4075         len = strnlen(str, STR_TOKEN_SIZE);
4076         i = 0;
4077         /* Get port_id first */
4078         while(i < len){
4079                 if(str[i] == ',')
4080                         break;
4081
4082                 i++;
4083         }
4084         str[i]='\0';
4085         tmp = strtoul(str, NULL, 0);
4086         /* If port_id greater that what portid_t can represent, return */
4087         if(tmp >= RTE_MAX_ETHPORTS)
4088                 return;
4089         port_id = (portid_t)tmp;
4090
4091         if (!strcmp(res->on, "on"))
4092                 on = 1;
4093         else
4094                 on = 0;
4095
4096         if (!strcmp(res->what, "strip"))
4097                 rx_vlan_strip_set(port_id,  on);
4098         else if(!strcmp(res->what, "stripq")){
4099                 uint16_t queue_id = 0;
4100
4101                 /* No queue_id, return */
4102                 if(i + 1 >= len) {
4103                         printf("must specify (port,queue_id)\n");
4104                         return;
4105                 }
4106                 tmp = strtoul(str + i + 1, NULL, 0);
4107                 /* If queue_id greater that what 16-bits can represent, return */
4108                 if(tmp > 0xffff)
4109                         return;
4110
4111                 queue_id = (uint16_t)tmp;
4112                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4113         }
4114         else if (!strcmp(res->what, "filter"))
4115                 rx_vlan_filter_set(port_id, on);
4116         else if (!strcmp(res->what, "qinq_strip"))
4117                 rx_vlan_qinq_strip_set(port_id, on);
4118         else
4119                 vlan_extend_set(port_id, on);
4120
4121         return;
4122 }
4123
4124 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4125         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4126                                  vlan, "vlan");
4127 cmdline_parse_token_string_t cmd_vlan_offload_set =
4128         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4129                                  set, "set");
4130 cmdline_parse_token_string_t cmd_vlan_offload_what =
4131         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4132                                 what, "strip#filter#qinq_strip#extend#stripq");
4133 cmdline_parse_token_string_t cmd_vlan_offload_on =
4134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4135                               on, "on#off");
4136 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4138                               port_id, NULL);
4139
4140 cmdline_parse_inst_t cmd_vlan_offload = {
4141         .f = cmd_vlan_offload_parsed,
4142         .data = NULL,
4143         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4144                 "<port_id[,queue_id]>: "
4145                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4146         .tokens = {
4147                 (void *)&cmd_vlan_offload_vlan,
4148                 (void *)&cmd_vlan_offload_set,
4149                 (void *)&cmd_vlan_offload_what,
4150                 (void *)&cmd_vlan_offload_on,
4151                 (void *)&cmd_vlan_offload_portid,
4152                 NULL,
4153         },
4154 };
4155
4156 /* *** VLAN TPID SET ON A PORT *** */
4157 struct cmd_vlan_tpid_result {
4158         cmdline_fixed_string_t vlan;
4159         cmdline_fixed_string_t set;
4160         cmdline_fixed_string_t vlan_type;
4161         cmdline_fixed_string_t what;
4162         uint16_t tp_id;
4163         portid_t port_id;
4164 };
4165
4166 static void
4167 cmd_vlan_tpid_parsed(void *parsed_result,
4168                           __rte_unused struct cmdline *cl,
4169                           __rte_unused void *data)
4170 {
4171         struct cmd_vlan_tpid_result *res = parsed_result;
4172         enum rte_vlan_type vlan_type;
4173
4174         if (!strcmp(res->vlan_type, "inner"))
4175                 vlan_type = ETH_VLAN_TYPE_INNER;
4176         else if (!strcmp(res->vlan_type, "outer"))
4177                 vlan_type = ETH_VLAN_TYPE_OUTER;
4178         else {
4179                 printf("Unknown vlan type\n");
4180                 return;
4181         }
4182         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4183 }
4184
4185 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4186         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4187                                  vlan, "vlan");
4188 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4189         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4190                                  set, "set");
4191 cmdline_parse_token_string_t cmd_vlan_type =
4192         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4193                                  vlan_type, "inner#outer");
4194 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4196                                  what, "tpid");
4197 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4198         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4199                               tp_id, UINT16);
4200 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4201         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4202                               port_id, UINT16);
4203
4204 cmdline_parse_inst_t cmd_vlan_tpid = {
4205         .f = cmd_vlan_tpid_parsed,
4206         .data = NULL,
4207         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4208                 "Set the VLAN Ether type",
4209         .tokens = {
4210                 (void *)&cmd_vlan_tpid_vlan,
4211                 (void *)&cmd_vlan_tpid_set,
4212                 (void *)&cmd_vlan_type,
4213                 (void *)&cmd_vlan_tpid_what,
4214                 (void *)&cmd_vlan_tpid_tpid,
4215                 (void *)&cmd_vlan_tpid_portid,
4216                 NULL,
4217         },
4218 };
4219
4220 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4221 struct cmd_rx_vlan_filter_result {
4222         cmdline_fixed_string_t rx_vlan;
4223         cmdline_fixed_string_t what;
4224         uint16_t vlan_id;
4225         portid_t port_id;
4226 };
4227
4228 static void
4229 cmd_rx_vlan_filter_parsed(void *parsed_result,
4230                           __rte_unused struct cmdline *cl,
4231                           __rte_unused void *data)
4232 {
4233         struct cmd_rx_vlan_filter_result *res = parsed_result;
4234
4235         if (!strcmp(res->what, "add"))
4236                 rx_vft_set(res->port_id, res->vlan_id, 1);
4237         else
4238                 rx_vft_set(res->port_id, res->vlan_id, 0);
4239 }
4240
4241 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4242         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4243                                  rx_vlan, "rx_vlan");
4244 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4245         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4246                                  what, "add#rm");
4247 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4248         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4249                               vlan_id, UINT16);
4250 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4251         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4252                               port_id, UINT16);
4253
4254 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4255         .f = cmd_rx_vlan_filter_parsed,
4256         .data = NULL,
4257         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4258                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4259                 "identifiers filtered by a port",
4260         .tokens = {
4261                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4262                 (void *)&cmd_rx_vlan_filter_what,
4263                 (void *)&cmd_rx_vlan_filter_vlanid,
4264                 (void *)&cmd_rx_vlan_filter_portid,
4265                 NULL,
4266         },
4267 };
4268
4269 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4270 struct cmd_tx_vlan_set_result {
4271         cmdline_fixed_string_t tx_vlan;
4272         cmdline_fixed_string_t set;
4273         portid_t port_id;
4274         uint16_t vlan_id;
4275 };
4276
4277 static void
4278 cmd_tx_vlan_set_parsed(void *parsed_result,
4279                        __rte_unused struct cmdline *cl,
4280                        __rte_unused void *data)
4281 {
4282         struct cmd_tx_vlan_set_result *res = parsed_result;
4283
4284         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4285                 return;
4286
4287         if (!port_is_stopped(res->port_id)) {
4288                 printf("Please stop port %d first\n", res->port_id);
4289                 return;
4290         }
4291
4292         tx_vlan_set(res->port_id, res->vlan_id);
4293
4294         cmd_reconfig_device_queue(res->port_id, 1, 1);
4295 }
4296
4297 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4298         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4299                                  tx_vlan, "tx_vlan");
4300 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4301         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4302                                  set, "set");
4303 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4304         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4305                               port_id, UINT16);
4306 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4308                               vlan_id, UINT16);
4309
4310 cmdline_parse_inst_t cmd_tx_vlan_set = {
4311         .f = cmd_tx_vlan_set_parsed,
4312         .data = NULL,
4313         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4314                 "Enable hardware insertion of a single VLAN header "
4315                 "with a given TAG Identifier in packets sent on a port",
4316         .tokens = {
4317                 (void *)&cmd_tx_vlan_set_tx_vlan,
4318                 (void *)&cmd_tx_vlan_set_set,
4319                 (void *)&cmd_tx_vlan_set_portid,
4320                 (void *)&cmd_tx_vlan_set_vlanid,
4321                 NULL,
4322         },
4323 };
4324
4325 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4326 struct cmd_tx_vlan_set_qinq_result {
4327         cmdline_fixed_string_t tx_vlan;
4328         cmdline_fixed_string_t set;
4329         portid_t port_id;
4330         uint16_t vlan_id;
4331         uint16_t vlan_id_outer;
4332 };
4333
4334 static void
4335 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4336                             __rte_unused struct cmdline *cl,
4337                             __rte_unused void *data)
4338 {
4339         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4340
4341         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4342                 return;
4343
4344         if (!port_is_stopped(res->port_id)) {
4345                 printf("Please stop port %d first\n", res->port_id);
4346                 return;
4347         }
4348
4349         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4350
4351         cmd_reconfig_device_queue(res->port_id, 1, 1);
4352 }
4353
4354 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4355         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4356                 tx_vlan, "tx_vlan");
4357 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4358         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4359                 set, "set");
4360 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4362                 port_id, UINT16);
4363 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4364         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4365                 vlan_id, UINT16);
4366 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4367         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4368                 vlan_id_outer, UINT16);
4369
4370 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4371         .f = cmd_tx_vlan_set_qinq_parsed,
4372         .data = NULL,
4373         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4374                 "Enable hardware insertion of double VLAN header "
4375                 "with given TAG Identifiers in packets sent on a port",
4376         .tokens = {
4377                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4378                 (void *)&cmd_tx_vlan_set_qinq_set,
4379                 (void *)&cmd_tx_vlan_set_qinq_portid,
4380                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4381                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4382                 NULL,
4383         },
4384 };
4385
4386 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4387 struct cmd_tx_vlan_set_pvid_result {
4388         cmdline_fixed_string_t tx_vlan;
4389         cmdline_fixed_string_t set;
4390         cmdline_fixed_string_t pvid;
4391         portid_t port_id;
4392         uint16_t vlan_id;
4393         cmdline_fixed_string_t mode;
4394 };
4395
4396 static void
4397 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4398                             __rte_unused struct cmdline *cl,
4399                             __rte_unused void *data)
4400 {
4401         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4402
4403         if (strcmp(res->mode, "on") == 0)
4404                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4405         else
4406                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4407 }
4408
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4411                                  tx_vlan, "tx_vlan");
4412 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4413         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4414                                  set, "set");
4415 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4416         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4417                                  pvid, "pvid");
4418 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4419         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4420                              port_id, UINT16);
4421 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4422         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4423                               vlan_id, UINT16);
4424 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4426                                  mode, "on#off");
4427
4428 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4429         .f = cmd_tx_vlan_set_pvid_parsed,
4430         .data = NULL,
4431         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4432         .tokens = {
4433                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4434                 (void *)&cmd_tx_vlan_set_pvid_set,
4435                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4436                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4437                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4438                 (void *)&cmd_tx_vlan_set_pvid_mode,
4439                 NULL,
4440         },
4441 };
4442
4443 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4444 struct cmd_tx_vlan_reset_result {
4445         cmdline_fixed_string_t tx_vlan;
4446         cmdline_fixed_string_t reset;
4447         portid_t port_id;
4448 };
4449
4450 static void
4451 cmd_tx_vlan_reset_parsed(void *parsed_result,
4452                          __rte_unused struct cmdline *cl,
4453                          __rte_unused void *data)
4454 {
4455         struct cmd_tx_vlan_reset_result *res = parsed_result;
4456
4457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4458                 return;
4459
4460         if (!port_is_stopped(res->port_id)) {
4461                 printf("Please stop port %d first\n", res->port_id);
4462                 return;
4463         }
4464
4465         tx_vlan_reset(res->port_id);
4466
4467         cmd_reconfig_device_queue(res->port_id, 1, 1);
4468 }
4469
4470 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4471         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4472                                  tx_vlan, "tx_vlan");
4473 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4474         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4475                                  reset, "reset");
4476 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4477         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4478                               port_id, UINT16);
4479
4480 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4481         .f = cmd_tx_vlan_reset_parsed,
4482         .data = NULL,
4483         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4484                 "VLAN header in packets sent on a port",
4485         .tokens = {
4486                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4487                 (void *)&cmd_tx_vlan_reset_reset,
4488                 (void *)&cmd_tx_vlan_reset_portid,
4489                 NULL,
4490         },
4491 };
4492
4493
4494 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4495 struct cmd_csum_result {
4496         cmdline_fixed_string_t csum;
4497         cmdline_fixed_string_t mode;
4498         cmdline_fixed_string_t proto;
4499         cmdline_fixed_string_t hwsw;
4500         portid_t port_id;
4501 };
4502
4503 static void
4504 csum_show(int port_id)
4505 {
4506         struct rte_eth_dev_info dev_info;
4507         uint64_t tx_offloads;
4508         int ret;
4509
4510         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4511         printf("Parse tunnel is %s\n",
4512                 (ports[port_id].parse_tunnel) ? "on" : "off");
4513         printf("IP checksum offload is %s\n",
4514                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4515         printf("UDP checksum offload is %s\n",
4516                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4517         printf("TCP checksum offload is %s\n",
4518                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4519         printf("SCTP checksum offload is %s\n",
4520                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4521         printf("Outer-Ip checksum offload is %s\n",
4522                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4523         printf("Outer-Udp checksum offload is %s\n",
4524                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4525
4526         /* display warnings if configuration is not supported by the NIC */
4527         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4528         if (ret != 0)
4529                 return;
4530
4531         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4532                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4533                 printf("Warning: hardware IP checksum enabled but not "
4534                         "supported by port %d\n", port_id);
4535         }
4536         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4537                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4538                 printf("Warning: hardware UDP checksum enabled but not "
4539                         "supported by port %d\n", port_id);
4540         }
4541         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4542                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4543                 printf("Warning: hardware TCP checksum enabled but not "
4544                         "supported by port %d\n", port_id);
4545         }
4546         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4547                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4548                 printf("Warning: hardware SCTP checksum enabled but not "
4549                         "supported by port %d\n", port_id);
4550         }
4551         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4552                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4553                 printf("Warning: hardware outer IP checksum enabled but not "
4554                         "supported by port %d\n", port_id);
4555         }
4556         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4557                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4558                         == 0) {
4559                 printf("Warning: hardware outer UDP checksum enabled but not "
4560                         "supported by port %d\n", port_id);
4561         }
4562 }
4563
4564 static void
4565 cmd_config_queue_tx_offloads(struct rte_port *port)
4566 {
4567         int k;
4568
4569         /* Apply queue tx offloads configuration */
4570         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4571                 port->tx_conf[k].offloads =
4572                         port->dev_conf.txmode.offloads;
4573 }
4574
4575 static void
4576 cmd_csum_parsed(void *parsed_result,
4577                        __rte_unused struct cmdline *cl,
4578                        __rte_unused void *data)
4579 {
4580         struct cmd_csum_result *res = parsed_result;
4581         int hw = 0;
4582         uint64_t csum_offloads = 0;
4583         struct rte_eth_dev_info dev_info;
4584         int ret;
4585
4586         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4587                 printf("invalid port %d\n", res->port_id);
4588                 return;
4589         }
4590         if (!port_is_stopped(res->port_id)) {
4591                 printf("Please stop port %d first\n", res->port_id);
4592                 return;
4593         }
4594
4595         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4596         if (ret != 0)
4597                 return;
4598
4599         if (!strcmp(res->mode, "set")) {
4600
4601                 if (!strcmp(res->hwsw, "hw"))
4602                         hw = 1;
4603
4604                 if (!strcmp(res->proto, "ip")) {
4605                         if (hw == 0 || (dev_info.tx_offload_capa &
4606                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4607                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4608                         } else {
4609                                 printf("IP checksum offload is not supported "
4610                                        "by port %u\n", res->port_id);
4611                         }
4612                 } else if (!strcmp(res->proto, "udp")) {
4613                         if (hw == 0 || (dev_info.tx_offload_capa &
4614                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4615                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4616                         } else {
4617                                 printf("UDP checksum offload is not supported "
4618                                        "by port %u\n", res->port_id);
4619                         }
4620                 } else if (!strcmp(res->proto, "tcp")) {
4621                         if (hw == 0 || (dev_info.tx_offload_capa &
4622                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4623                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4624                         } else {
4625                                 printf("TCP checksum offload is not supported "
4626                                        "by port %u\n", res->port_id);
4627                         }
4628                 } else if (!strcmp(res->proto, "sctp")) {
4629                         if (hw == 0 || (dev_info.tx_offload_capa &
4630                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4631                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4632                         } else {
4633                                 printf("SCTP checksum offload is not supported "
4634                                        "by port %u\n", res->port_id);
4635                         }
4636                 } else if (!strcmp(res->proto, "outer-ip")) {
4637                         if (hw == 0 || (dev_info.tx_offload_capa &
4638                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4639                                 csum_offloads |=
4640                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4641                         } else {
4642                                 printf("Outer IP checksum offload is not "
4643                                        "supported by port %u\n", res->port_id);
4644                         }
4645                 } else if (!strcmp(res->proto, "outer-udp")) {
4646                         if (hw == 0 || (dev_info.tx_offload_capa &
4647                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4648                                 csum_offloads |=
4649                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4650                         } else {
4651                                 printf("Outer UDP checksum offload is not "
4652                                        "supported by port %u\n", res->port_id);
4653                         }
4654                 }
4655
4656                 if (hw) {
4657                         ports[res->port_id].dev_conf.txmode.offloads |=
4658                                                         csum_offloads;
4659                 } else {
4660                         ports[res->port_id].dev_conf.txmode.offloads &=
4661                                                         (~csum_offloads);
4662                 }
4663                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4664         }
4665         csum_show(res->port_id);
4666
4667         cmd_reconfig_device_queue(res->port_id, 1, 1);
4668 }
4669
4670 cmdline_parse_token_string_t cmd_csum_csum =
4671         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4672                                 csum, "csum");
4673 cmdline_parse_token_string_t cmd_csum_mode =
4674         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4675                                 mode, "set");
4676 cmdline_parse_token_string_t cmd_csum_proto =
4677         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4678                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4679 cmdline_parse_token_string_t cmd_csum_hwsw =
4680         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4681                                 hwsw, "hw#sw");
4682 cmdline_parse_token_num_t cmd_csum_portid =
4683         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4684                                 port_id, UINT16);
4685
4686 cmdline_parse_inst_t cmd_csum_set = {
4687         .f = cmd_csum_parsed,
4688         .data = NULL,
4689         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4690                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4691                 "using csum forward engine",
4692         .tokens = {
4693                 (void *)&cmd_csum_csum,
4694                 (void *)&cmd_csum_mode,
4695                 (void *)&cmd_csum_proto,
4696                 (void *)&cmd_csum_hwsw,
4697                 (void *)&cmd_csum_portid,
4698                 NULL,
4699         },
4700 };
4701
4702 cmdline_parse_token_string_t cmd_csum_mode_show =
4703         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4704                                 mode, "show");
4705
4706 cmdline_parse_inst_t cmd_csum_show = {
4707         .f = cmd_csum_parsed,
4708         .data = NULL,
4709         .help_str = "csum show <port_id>: Show checksum offload configuration",
4710         .tokens = {
4711                 (void *)&cmd_csum_csum,
4712                 (void *)&cmd_csum_mode_show,
4713                 (void *)&cmd_csum_portid,
4714                 NULL,
4715         },
4716 };
4717
4718 /* Enable/disable tunnel parsing */
4719 struct cmd_csum_tunnel_result {
4720         cmdline_fixed_string_t csum;
4721         cmdline_fixed_string_t parse;
4722         cmdline_fixed_string_t onoff;
4723         portid_t port_id;
4724 };
4725
4726 static void
4727 cmd_csum_tunnel_parsed(void *parsed_result,
4728                        __rte_unused struct cmdline *cl,
4729                        __rte_unused void *data)
4730 {
4731         struct cmd_csum_tunnel_result *res = parsed_result;
4732
4733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4734                 return;
4735
4736         if (!strcmp(res->onoff, "on"))
4737                 ports[res->port_id].parse_tunnel = 1;
4738         else
4739                 ports[res->port_id].parse_tunnel = 0;
4740
4741         csum_show(res->port_id);
4742 }
4743
4744 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4745         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4746                                 csum, "csum");
4747 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4748         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4749                                 parse, "parse-tunnel");
4750 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4751         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4752                                 onoff, "on#off");
4753 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4754         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4755                                 port_id, UINT16);
4756
4757 cmdline_parse_inst_t cmd_csum_tunnel = {
4758         .f = cmd_csum_tunnel_parsed,
4759         .data = NULL,
4760         .help_str = "csum parse-tunnel on|off <port_id>: "
4761                 "Enable/Disable parsing of tunnels for csum engine",
4762         .tokens = {
4763                 (void *)&cmd_csum_tunnel_csum,
4764                 (void *)&cmd_csum_tunnel_parse,
4765                 (void *)&cmd_csum_tunnel_onoff,
4766                 (void *)&cmd_csum_tunnel_portid,
4767                 NULL,
4768         },
4769 };
4770
4771 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4772 struct cmd_tso_set_result {
4773         cmdline_fixed_string_t tso;
4774         cmdline_fixed_string_t mode;
4775         uint16_t tso_segsz;
4776         portid_t port_id;
4777 };
4778
4779 static void
4780 cmd_tso_set_parsed(void *parsed_result,
4781                        __rte_unused struct cmdline *cl,
4782                        __rte_unused void *data)
4783 {
4784         struct cmd_tso_set_result *res = parsed_result;
4785         struct rte_eth_dev_info dev_info;
4786         int ret;
4787
4788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4789                 return;
4790         if (!port_is_stopped(res->port_id)) {
4791                 printf("Please stop port %d first\n", res->port_id);
4792                 return;
4793         }
4794
4795         if (!strcmp(res->mode, "set"))
4796                 ports[res->port_id].tso_segsz = res->tso_segsz;
4797
4798         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4799         if (ret != 0)
4800                 return;
4801
4802         if ((ports[res->port_id].tso_segsz != 0) &&
4803                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4804                 printf("Error: TSO is not supported by port %d\n",
4805                        res->port_id);
4806                 return;
4807         }
4808
4809         if (ports[res->port_id].tso_segsz == 0) {
4810                 ports[res->port_id].dev_conf.txmode.offloads &=
4811                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4812                 printf("TSO for non-tunneled packets is disabled\n");
4813         } else {
4814                 ports[res->port_id].dev_conf.txmode.offloads |=
4815                                                 DEV_TX_OFFLOAD_TCP_TSO;
4816                 printf("TSO segment size for non-tunneled packets is %d\n",
4817                         ports[res->port_id].tso_segsz);
4818         }
4819         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4820
4821         /* display warnings if configuration is not supported by the NIC */
4822         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4823         if (ret != 0)
4824                 return;
4825
4826         if ((ports[res->port_id].tso_segsz != 0) &&
4827                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4828                 printf("Warning: TSO enabled but not "
4829                         "supported by port %d\n", res->port_id);
4830         }
4831
4832         cmd_reconfig_device_queue(res->port_id, 1, 1);
4833 }
4834
4835 cmdline_parse_token_string_t cmd_tso_set_tso =
4836         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4837                                 tso, "tso");
4838 cmdline_parse_token_string_t cmd_tso_set_mode =
4839         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4840                                 mode, "set");
4841 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4842         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4843                                 tso_segsz, UINT16);
4844 cmdline_parse_token_num_t cmd_tso_set_portid =
4845         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4846                                 port_id, UINT16);
4847
4848 cmdline_parse_inst_t cmd_tso_set = {
4849         .f = cmd_tso_set_parsed,
4850         .data = NULL,
4851         .help_str = "tso set <tso_segsz> <port_id>: "
4852                 "Set TSO segment size of non-tunneled packets for csum engine "
4853                 "(0 to disable)",
4854         .tokens = {
4855                 (void *)&cmd_tso_set_tso,
4856                 (void *)&cmd_tso_set_mode,
4857                 (void *)&cmd_tso_set_tso_segsz,
4858                 (void *)&cmd_tso_set_portid,
4859                 NULL,
4860         },
4861 };
4862
4863 cmdline_parse_token_string_t cmd_tso_show_mode =
4864         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4865                                 mode, "show");
4866
4867
4868 cmdline_parse_inst_t cmd_tso_show = {
4869         .f = cmd_tso_set_parsed,
4870         .data = NULL,
4871         .help_str = "tso show <port_id>: "
4872                 "Show TSO segment size of non-tunneled packets for csum engine",
4873         .tokens = {
4874                 (void *)&cmd_tso_set_tso,
4875                 (void *)&cmd_tso_show_mode,
4876                 (void *)&cmd_tso_set_portid,
4877                 NULL,
4878         },
4879 };
4880
4881 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4882 struct cmd_tunnel_tso_set_result {
4883         cmdline_fixed_string_t tso;
4884         cmdline_fixed_string_t mode;
4885         uint16_t tso_segsz;
4886         portid_t port_id;
4887 };
4888
4889 static struct rte_eth_dev_info
4890 check_tunnel_tso_nic_support(portid_t port_id)
4891 {
4892         struct rte_eth_dev_info dev_info;
4893
4894         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4895                 return dev_info;
4896
4897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4898                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4899                        "not enabled for port %d\n", port_id);
4900         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4901                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4902                        "not enabled for port %d\n", port_id);
4903         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4904                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4905                        "not enabled for port %d\n", port_id);
4906         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4907                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4908                        "not enabled for port %d\n", port_id);
4909         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4910                 printf("Warning: IP TUNNEL TSO not supported therefore "
4911                        "not enabled for port %d\n", port_id);
4912         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4913                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4914                        "not enabled for port %d\n", port_id);
4915         return dev_info;
4916 }
4917
4918 static void
4919 cmd_tunnel_tso_set_parsed(void *parsed_result,
4920                           __rte_unused struct cmdline *cl,
4921                           __rte_unused void *data)
4922 {
4923         struct cmd_tunnel_tso_set_result *res = parsed_result;
4924         struct rte_eth_dev_info dev_info;
4925
4926         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4927                 return;
4928         if (!port_is_stopped(res->port_id)) {
4929                 printf("Please stop port %d first\n", res->port_id);
4930                 return;
4931         }
4932
4933         if (!strcmp(res->mode, "set"))
4934                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4935
4936         dev_info = check_tunnel_tso_nic_support(res->port_id);
4937         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4938                 ports[res->port_id].dev_conf.txmode.offloads &=
4939                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4940                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4941                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4942                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4943                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4944                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4945                 printf("TSO for tunneled packets is disabled\n");
4946         } else {
4947                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4948                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4949                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4950                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4951                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4952                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4953
4954                 ports[res->port_id].dev_conf.txmode.offloads |=
4955                         (tso_offloads & dev_info.tx_offload_capa);
4956                 printf("TSO segment size for tunneled packets is %d\n",
4957                         ports[res->port_id].tunnel_tso_segsz);
4958
4959                 /* Below conditions are needed to make it work:
4960                  * (1) tunnel TSO is supported by the NIC;
4961                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4962                  * are recognized;
4963                  * (3) for tunneled pkts with outer L3 of IPv4,
4964                  * "csum set outer-ip" must be set to hw, because after tso,
4965                  * total_len of outer IP header is changed, and the checksum
4966                  * of outer IP header calculated by sw should be wrong; that
4967                  * is not necessary for IPv6 tunneled pkts because there's no
4968                  * checksum in IP header anymore.
4969                  */
4970
4971                 if (!ports[res->port_id].parse_tunnel)
4972                         printf("Warning: csum parse_tunnel must be set "
4973                                 "so that tunneled packets are recognized\n");
4974                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4975                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4976                         printf("Warning: csum set outer-ip must be set to hw "
4977                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4978         }
4979
4980         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4981         cmd_reconfig_device_queue(res->port_id, 1, 1);
4982 }
4983
4984 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4985         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4986                                 tso, "tunnel_tso");
4987 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4988         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4989                                 mode, "set");
4990 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4991         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4992                                 tso_segsz, UINT16);
4993 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4994         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4995                                 port_id, UINT16);
4996
4997 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4998         .f = cmd_tunnel_tso_set_parsed,
4999         .data = NULL,
5000         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5001                 "Set TSO segment size of tunneled packets for csum engine "
5002                 "(0 to disable)",
5003         .tokens = {
5004                 (void *)&cmd_tunnel_tso_set_tso,
5005                 (void *)&cmd_tunnel_tso_set_mode,
5006                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5007                 (void *)&cmd_tunnel_tso_set_portid,
5008                 NULL,
5009         },
5010 };
5011
5012 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5013         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5014                                 mode, "show");
5015
5016
5017 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5018         .f = cmd_tunnel_tso_set_parsed,
5019         .data = NULL,
5020         .help_str = "tunnel_tso show <port_id> "
5021                 "Show TSO segment size of tunneled packets for csum engine",
5022         .tokens = {
5023                 (void *)&cmd_tunnel_tso_set_tso,
5024                 (void *)&cmd_tunnel_tso_show_mode,
5025                 (void *)&cmd_tunnel_tso_set_portid,
5026                 NULL,
5027         },
5028 };
5029
5030 /* *** SET GRO FOR A PORT *** */
5031 struct cmd_gro_enable_result {
5032         cmdline_fixed_string_t cmd_set;
5033         cmdline_fixed_string_t cmd_port;
5034         cmdline_fixed_string_t cmd_keyword;
5035         cmdline_fixed_string_t cmd_onoff;
5036         portid_t cmd_pid;
5037 };
5038
5039 static void
5040 cmd_gro_enable_parsed(void *parsed_result,
5041                 __rte_unused struct cmdline *cl,
5042                 __rte_unused void *data)
5043 {
5044         struct cmd_gro_enable_result *res;
5045
5046         res = parsed_result;
5047         if (!strcmp(res->cmd_keyword, "gro"))
5048                 setup_gro(res->cmd_onoff, res->cmd_pid);
5049 }
5050
5051 cmdline_parse_token_string_t cmd_gro_enable_set =
5052         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5053                         cmd_set, "set");
5054 cmdline_parse_token_string_t cmd_gro_enable_port =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5056                         cmd_keyword, "port");
5057 cmdline_parse_token_num_t cmd_gro_enable_pid =
5058         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5059                         cmd_pid, UINT16);
5060 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5061         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5062                         cmd_keyword, "gro");
5063 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5064         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5065                         cmd_onoff, "on#off");
5066
5067 cmdline_parse_inst_t cmd_gro_enable = {
5068         .f = cmd_gro_enable_parsed,
5069         .data = NULL,
5070         .help_str = "set port <port_id> gro on|off",
5071         .tokens = {
5072                 (void *)&cmd_gro_enable_set,
5073                 (void *)&cmd_gro_enable_port,
5074                 (void *)&cmd_gro_enable_pid,
5075                 (void *)&cmd_gro_enable_keyword,
5076                 (void *)&cmd_gro_enable_onoff,
5077                 NULL,
5078         },
5079 };
5080
5081 /* *** DISPLAY GRO CONFIGURATION *** */
5082 struct cmd_gro_show_result {
5083         cmdline_fixed_string_t cmd_show;
5084         cmdline_fixed_string_t cmd_port;
5085         cmdline_fixed_string_t cmd_keyword;
5086         portid_t cmd_pid;
5087 };
5088
5089 static void
5090 cmd_gro_show_parsed(void *parsed_result,
5091                 __rte_unused struct cmdline *cl,
5092                 __rte_unused void *data)
5093 {
5094         struct cmd_gro_show_result *res;
5095
5096         res = parsed_result;
5097         if (!strcmp(res->cmd_keyword, "gro"))
5098                 show_gro(res->cmd_pid);
5099 }
5100
5101 cmdline_parse_token_string_t cmd_gro_show_show =
5102         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5103                         cmd_show, "show");
5104 cmdline_parse_token_string_t cmd_gro_show_port =
5105         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5106                         cmd_port, "port");
5107 cmdline_parse_token_num_t cmd_gro_show_pid =
5108         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5109                         cmd_pid, UINT16);
5110 cmdline_parse_token_string_t cmd_gro_show_keyword =
5111         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5112                         cmd_keyword, "gro");
5113
5114 cmdline_parse_inst_t cmd_gro_show = {
5115         .f = cmd_gro_show_parsed,
5116         .data = NULL,
5117         .help_str = "show port <port_id> gro",
5118         .tokens = {
5119                 (void *)&cmd_gro_show_show,
5120                 (void *)&cmd_gro_show_port,
5121                 (void *)&cmd_gro_show_pid,
5122                 (void *)&cmd_gro_show_keyword,
5123                 NULL,
5124         },
5125 };
5126
5127 /* *** SET FLUSH CYCLES FOR GRO *** */
5128 struct cmd_gro_flush_result {
5129         cmdline_fixed_string_t cmd_set;
5130         cmdline_fixed_string_t cmd_keyword;
5131         cmdline_fixed_string_t cmd_flush;
5132         uint8_t cmd_cycles;
5133 };
5134
5135 static void
5136 cmd_gro_flush_parsed(void *parsed_result,
5137                 __rte_unused struct cmdline *cl,
5138                 __rte_unused void *data)
5139 {
5140         struct cmd_gro_flush_result *res;
5141
5142         res = parsed_result;
5143         if ((!strcmp(res->cmd_keyword, "gro")) &&
5144                         (!strcmp(res->cmd_flush, "flush")))
5145                 setup_gro_flush_cycles(res->cmd_cycles);
5146 }
5147
5148 cmdline_parse_token_string_t cmd_gro_flush_set =
5149         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5150                         cmd_set, "set");
5151 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5152         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5153                         cmd_keyword, "gro");
5154 cmdline_parse_token_string_t cmd_gro_flush_flush =
5155         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5156                         cmd_flush, "flush");
5157 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5158         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5159                         cmd_cycles, UINT8);
5160
5161 cmdline_parse_inst_t cmd_gro_flush = {
5162         .f = cmd_gro_flush_parsed,
5163         .data = NULL,
5164         .help_str = "set gro flush <cycles>",
5165         .tokens = {
5166                 (void *)&cmd_gro_flush_set,
5167                 (void *)&cmd_gro_flush_keyword,
5168                 (void *)&cmd_gro_flush_flush,
5169                 (void *)&cmd_gro_flush_cycles,
5170                 NULL,
5171         },
5172 };
5173
5174 /* *** ENABLE/DISABLE GSO *** */
5175 struct cmd_gso_enable_result {
5176         cmdline_fixed_string_t cmd_set;
5177         cmdline_fixed_string_t cmd_port;
5178         cmdline_fixed_string_t cmd_keyword;
5179         cmdline_fixed_string_t cmd_mode;
5180         portid_t cmd_pid;
5181 };
5182
5183 static void
5184 cmd_gso_enable_parsed(void *parsed_result,
5185                 __rte_unused struct cmdline *cl,
5186                 __rte_unused void *data)
5187 {
5188         struct cmd_gso_enable_result *res;
5189
5190         res = parsed_result;
5191         if (!strcmp(res->cmd_keyword, "gso"))
5192                 setup_gso(res->cmd_mode, res->cmd_pid);
5193 }
5194
5195 cmdline_parse_token_string_t cmd_gso_enable_set =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5197                         cmd_set, "set");
5198 cmdline_parse_token_string_t cmd_gso_enable_port =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5200                         cmd_port, "port");
5201 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5202         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5203                         cmd_keyword, "gso");
5204 cmdline_parse_token_string_t cmd_gso_enable_mode =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5206                         cmd_mode, "on#off");
5207 cmdline_parse_token_num_t cmd_gso_enable_pid =
5208         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5209                         cmd_pid, UINT16);
5210
5211 cmdline_parse_inst_t cmd_gso_enable = {
5212         .f = cmd_gso_enable_parsed,
5213         .data = NULL,
5214         .help_str = "set port <port_id> gso on|off",
5215         .tokens = {
5216                 (void *)&cmd_gso_enable_set,
5217                 (void *)&cmd_gso_enable_port,
5218                 (void *)&cmd_gso_enable_pid,
5219                 (void *)&cmd_gso_enable_keyword,
5220                 (void *)&cmd_gso_enable_mode,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5226 struct cmd_gso_size_result {
5227         cmdline_fixed_string_t cmd_set;
5228         cmdline_fixed_string_t cmd_keyword;
5229         cmdline_fixed_string_t cmd_segsz;
5230         uint16_t cmd_size;
5231 };
5232
5233 static void
5234 cmd_gso_size_parsed(void *parsed_result,
5235                        __rte_unused struct cmdline *cl,
5236                        __rte_unused void *data)
5237 {
5238         struct cmd_gso_size_result *res = parsed_result;
5239
5240         if (test_done == 0) {
5241                 printf("Before setting GSO segsz, please first"
5242                                 " stop forwarding\n");
5243                 return;
5244         }
5245
5246         if (!strcmp(res->cmd_keyword, "gso") &&
5247                         !strcmp(res->cmd_segsz, "segsz")) {
5248                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5249                         printf("gso_size should be larger than %zu."
5250                                         " Please input a legal value\n",
5251                                         RTE_GSO_SEG_SIZE_MIN);
5252                 else
5253                         gso_max_segment_size = res->cmd_size;
5254         }
5255 }
5256
5257 cmdline_parse_token_string_t cmd_gso_size_set =
5258         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5259                                 cmd_set, "set");
5260 cmdline_parse_token_string_t cmd_gso_size_keyword =
5261         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5262                                 cmd_keyword, "gso");
5263 cmdline_parse_token_string_t cmd_gso_size_segsz =
5264         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5265                                 cmd_segsz, "segsz");
5266 cmdline_parse_token_num_t cmd_gso_size_size =
5267         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5268                                 cmd_size, UINT16);
5269
5270 cmdline_parse_inst_t cmd_gso_size = {
5271         .f = cmd_gso_size_parsed,
5272         .data = NULL,
5273         .help_str = "set gso segsz <length>",
5274         .tokens = {
5275                 (void *)&cmd_gso_size_set,
5276                 (void *)&cmd_gso_size_keyword,
5277                 (void *)&cmd_gso_size_segsz,
5278                 (void *)&cmd_gso_size_size,
5279                 NULL,
5280         },
5281 };
5282
5283 /* *** SHOW GSO CONFIGURATION *** */
5284 struct cmd_gso_show_result {
5285         cmdline_fixed_string_t cmd_show;
5286         cmdline_fixed_string_t cmd_port;
5287         cmdline_fixed_string_t cmd_keyword;
5288         portid_t cmd_pid;
5289 };
5290
5291 static void
5292 cmd_gso_show_parsed(void *parsed_result,
5293                        __rte_unused struct cmdline *cl,
5294                        __rte_unused void *data)
5295 {
5296         struct cmd_gso_show_result *res = parsed_result;
5297
5298         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5299                 printf("invalid port id %u\n", res->cmd_pid);
5300                 return;
5301         }
5302         if (!strcmp(res->cmd_keyword, "gso")) {
5303                 if (gso_ports[res->cmd_pid].enable) {
5304                         printf("Max GSO'd packet size: %uB\n"
5305                                         "Supported GSO types: TCP/IPv4, "
5306                                         "UDP/IPv4, VxLAN with inner "
5307                                         "TCP/IPv4 packet, GRE with inner "
5308                                         "TCP/IPv4 packet\n",
5309                                         gso_max_segment_size);
5310                 } else
5311                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5312         }
5313 }
5314
5315 cmdline_parse_token_string_t cmd_gso_show_show =
5316 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5317                 cmd_show, "show");
5318 cmdline_parse_token_string_t cmd_gso_show_port =
5319 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5320                 cmd_port, "port");
5321 cmdline_parse_token_string_t cmd_gso_show_keyword =
5322         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5323                                 cmd_keyword, "gso");
5324 cmdline_parse_token_num_t cmd_gso_show_pid =
5325         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5326                                 cmd_pid, UINT16);
5327
5328 cmdline_parse_inst_t cmd_gso_show = {
5329         .f = cmd_gso_show_parsed,
5330         .data = NULL,
5331         .help_str = "show port <port_id> gso",
5332         .tokens = {
5333                 (void *)&cmd_gso_show_show,
5334                 (void *)&cmd_gso_show_port,
5335                 (void *)&cmd_gso_show_pid,
5336                 (void *)&cmd_gso_show_keyword,
5337                 NULL,
5338         },
5339 };
5340
5341 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5342 struct cmd_set_flush_rx {
5343         cmdline_fixed_string_t set;
5344         cmdline_fixed_string_t flush_rx;
5345         cmdline_fixed_string_t mode;
5346 };
5347
5348 static void
5349 cmd_set_flush_rx_parsed(void *parsed_result,
5350                 __rte_unused struct cmdline *cl,
5351                 __rte_unused void *data)
5352 {
5353         struct cmd_set_flush_rx *res = parsed_result;
5354         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5355 }
5356
5357 cmdline_parse_token_string_t cmd_setflushrx_set =
5358         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5359                         set, "set");
5360 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5362                         flush_rx, "flush_rx");
5363 cmdline_parse_token_string_t cmd_setflushrx_mode =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5365                         mode, "on#off");
5366
5367
5368 cmdline_parse_inst_t cmd_set_flush_rx = {
5369         .f = cmd_set_flush_rx_parsed,
5370         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5371         .data = NULL,
5372         .tokens = {
5373                 (void *)&cmd_setflushrx_set,
5374                 (void *)&cmd_setflushrx_flush_rx,
5375                 (void *)&cmd_setflushrx_mode,
5376                 NULL,
5377         },
5378 };
5379
5380 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5381 struct cmd_set_link_check {
5382         cmdline_fixed_string_t set;
5383         cmdline_fixed_string_t link_check;
5384         cmdline_fixed_string_t mode;
5385 };
5386
5387 static void
5388 cmd_set_link_check_parsed(void *parsed_result,
5389                 __rte_unused struct cmdline *cl,
5390                 __rte_unused void *data)
5391 {
5392         struct cmd_set_link_check *res = parsed_result;
5393         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5394 }
5395
5396 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5398                         set, "set");
5399 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5401                         link_check, "link_check");
5402 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5403         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5404                         mode, "on#off");
5405
5406
5407 cmdline_parse_inst_t cmd_set_link_check = {
5408         .f = cmd_set_link_check_parsed,
5409         .help_str = "set link_check on|off: Enable/Disable link status check "
5410                     "when starting/stopping a port",
5411         .data = NULL,
5412         .tokens = {
5413                 (void *)&cmd_setlinkcheck_set,
5414                 (void *)&cmd_setlinkcheck_link_check,
5415                 (void *)&cmd_setlinkcheck_mode,
5416                 NULL,
5417         },
5418 };
5419
5420 /* *** SET NIC BYPASS MODE *** */
5421 struct cmd_set_bypass_mode_result {
5422         cmdline_fixed_string_t set;
5423         cmdline_fixed_string_t bypass;
5424         cmdline_fixed_string_t mode;
5425         cmdline_fixed_string_t value;
5426         portid_t port_id;
5427 };
5428
5429 static void
5430 cmd_set_bypass_mode_parsed(void *parsed_result,
5431                 __rte_unused struct cmdline *cl,
5432                 __rte_unused void *data)
5433 {
5434         struct cmd_set_bypass_mode_result *res = parsed_result;
5435         portid_t port_id = res->port_id;
5436         int32_t rc = -EINVAL;
5437
5438 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5439         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5440
5441         if (!strcmp(res->value, "bypass"))
5442                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5443         else if (!strcmp(res->value, "isolate"))
5444                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5445         else
5446                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5447
5448         /* Set the bypass mode for the relevant port. */
5449         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5450 #endif
5451         if (rc != 0)
5452                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5453 }
5454
5455 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5457                         set, "set");
5458 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5460                         bypass, "bypass");
5461 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5463                         mode, "mode");
5464 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5466                         value, "normal#bypass#isolate");
5467 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5468         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5469                                 port_id, UINT16);
5470
5471 cmdline_parse_inst_t cmd_set_bypass_mode = {
5472         .f = cmd_set_bypass_mode_parsed,
5473         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5474                     "Set the NIC bypass mode for port_id",
5475         .data = NULL,
5476         .tokens = {
5477                 (void *)&cmd_setbypass_mode_set,
5478                 (void *)&cmd_setbypass_mode_bypass,
5479                 (void *)&cmd_setbypass_mode_mode,
5480                 (void *)&cmd_setbypass_mode_value,
5481                 (void *)&cmd_setbypass_mode_port,
5482                 NULL,
5483         },
5484 };
5485
5486 /* *** SET NIC BYPASS EVENT *** */
5487 struct cmd_set_bypass_event_result {
5488         cmdline_fixed_string_t set;
5489         cmdline_fixed_string_t bypass;
5490         cmdline_fixed_string_t event;
5491         cmdline_fixed_string_t event_value;
5492         cmdline_fixed_string_t mode;
5493         cmdline_fixed_string_t mode_value;
5494         portid_t port_id;
5495 };
5496
5497 static void
5498 cmd_set_bypass_event_parsed(void *parsed_result,
5499                 __rte_unused struct cmdline *cl,
5500                 __rte_unused void *data)
5501 {
5502         int32_t rc = -EINVAL;
5503         struct cmd_set_bypass_event_result *res = parsed_result;
5504         portid_t port_id = res->port_id;
5505
5506 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5507         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5508         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5509
5510         if (!strcmp(res->event_value, "timeout"))
5511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5512         else if (!strcmp(res->event_value, "os_on"))
5513                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5514         else if (!strcmp(res->event_value, "os_off"))
5515                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5516         else if (!strcmp(res->event_value, "power_on"))
5517                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5518         else if (!strcmp(res->event_value, "power_off"))
5519                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5520         else
5521                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5522
5523         if (!strcmp(res->mode_value, "bypass"))
5524                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5525         else if (!strcmp(res->mode_value, "isolate"))
5526                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5527         else
5528                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5529
5530         /* Set the watchdog timeout. */
5531         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5532
5533                 rc = -EINVAL;
5534                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5535                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5536                                                            bypass_timeout);
5537                 }
5538                 if (rc != 0) {
5539                         printf("Failed to set timeout value %u "
5540                         "for port %d, errto code: %d.\n",
5541                         bypass_timeout, port_id, rc);
5542                 }
5543         }
5544
5545         /* Set the bypass event to transition to bypass mode. */
5546         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5547                                               bypass_mode);
5548 #endif
5549
5550         if (rc != 0)
5551                 printf("\t Failed to set bypass event for port = %d.\n",
5552                        port_id);
5553 }
5554
5555 cmdline_parse_token_string_t cmd_setbypass_event_set =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5557                         set, "set");
5558 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5560                         bypass, "bypass");
5561 cmdline_parse_token_string_t cmd_setbypass_event_event =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5563                         event, "event");
5564 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5566                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5567 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5569                         mode, "mode");
5570 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5572                         mode_value, "normal#bypass#isolate");
5573 cmdline_parse_token_num_t cmd_setbypass_event_port =
5574         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5575                                 port_id, UINT16);
5576
5577 cmdline_parse_inst_t cmd_set_bypass_event = {
5578         .f = cmd_set_bypass_event_parsed,
5579         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5580                 "power_off mode normal|bypass|isolate <port_id>: "
5581                 "Set the NIC bypass event mode for port_id",
5582         .data = NULL,
5583         .tokens = {
5584                 (void *)&cmd_setbypass_event_set,
5585                 (void *)&cmd_setbypass_event_bypass,
5586                 (void *)&cmd_setbypass_event_event,
5587                 (void *)&cmd_setbypass_event_event_value,
5588                 (void *)&cmd_setbypass_event_mode,
5589                 (void *)&cmd_setbypass_event_mode_value,
5590                 (void *)&cmd_setbypass_event_port,
5591                 NULL,
5592         },
5593 };
5594
5595
5596 /* *** SET NIC BYPASS TIMEOUT *** */
5597 struct cmd_set_bypass_timeout_result {
5598         cmdline_fixed_string_t set;
5599         cmdline_fixed_string_t bypass;
5600         cmdline_fixed_string_t timeout;
5601         cmdline_fixed_string_t value;
5602 };
5603
5604 static void
5605 cmd_set_bypass_timeout_parsed(void *parsed_result,
5606                 __rte_unused struct cmdline *cl,
5607                 __rte_unused void *data)
5608 {
5609         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5610
5611 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5612         if (!strcmp(res->value, "1.5"))
5613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5614         else if (!strcmp(res->value, "2"))
5615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5616         else if (!strcmp(res->value, "3"))
5617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5618         else if (!strcmp(res->value, "4"))
5619                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5620         else if (!strcmp(res->value, "8"))
5621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5622         else if (!strcmp(res->value, "16"))
5623                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5624         else if (!strcmp(res->value, "32"))
5625                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5626         else
5627                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5628 #endif
5629 }
5630
5631 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5633                         set, "set");
5634 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5636                         bypass, "bypass");
5637 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5639                         timeout, "timeout");
5640 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5642                         value, "0#1.5#2#3#4#8#16#32");
5643
5644 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5645         .f = cmd_set_bypass_timeout_parsed,
5646         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5647                 "Set the NIC bypass watchdog timeout in seconds",
5648         .data = NULL,
5649         .tokens = {
5650                 (void *)&cmd_setbypass_timeout_set,
5651                 (void *)&cmd_setbypass_timeout_bypass,
5652                 (void *)&cmd_setbypass_timeout_timeout,
5653                 (void *)&cmd_setbypass_timeout_value,
5654                 NULL,
5655         },
5656 };
5657
5658 /* *** SHOW NIC BYPASS MODE *** */
5659 struct cmd_show_bypass_config_result {
5660         cmdline_fixed_string_t show;
5661         cmdline_fixed_string_t bypass;
5662         cmdline_fixed_string_t config;
5663         portid_t port_id;
5664 };
5665
5666 static void
5667 cmd_show_bypass_config_parsed(void *parsed_result,
5668                 __rte_unused struct cmdline *cl,
5669                 __rte_unused void *data)
5670 {
5671         struct cmd_show_bypass_config_result *res = parsed_result;
5672         portid_t port_id = res->port_id;
5673         int rc = -EINVAL;
5674 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5675         uint32_t event_mode;
5676         uint32_t bypass_mode;
5677         uint32_t timeout = bypass_timeout;
5678         unsigned int i;
5679
5680         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5681                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5682         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5683                 {"UNKNOWN", "normal", "bypass", "isolate"};
5684         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5685                 "NONE",
5686                 "OS/board on",
5687                 "power supply on",
5688                 "OS/board off",
5689                 "power supply off",
5690                 "timeout"};
5691
5692         /* Display the bypass mode.*/
5693         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5694                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5695                 return;
5696         }
5697         else {
5698                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5699                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5700
5701                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5702         }
5703
5704         /* Display the bypass timeout.*/
5705         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5706                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5707
5708         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5709
5710         /* Display the bypass events and associated modes. */
5711         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5712
5713                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5714                         printf("\tFailed to get bypass mode for event = %s\n",
5715                                 events[i]);
5716                 } else {
5717                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5718                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5719
5720                         printf("\tbypass event: %-16s = %s\n", events[i],
5721                                 modes[event_mode]);
5722                 }
5723         }
5724 #endif
5725         if (rc != 0)
5726                 printf("\tFailed to get bypass configuration for port = %d\n",
5727                        port_id);
5728 }
5729
5730 cmdline_parse_token_string_t cmd_showbypass_config_show =
5731         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5732                         show, "show");
5733 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5734         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5735                         bypass, "bypass");
5736 cmdline_parse_token_string_t cmd_showbypass_config_config =
5737         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5738                         config, "config");
5739 cmdline_parse_token_num_t cmd_showbypass_config_port =
5740         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5741                                 port_id, UINT16);
5742
5743 cmdline_parse_inst_t cmd_show_bypass_config = {
5744         .f = cmd_show_bypass_config_parsed,
5745         .help_str = "show bypass config <port_id>: "
5746                     "Show the NIC bypass config for port_id",
5747         .data = NULL,
5748         .tokens = {
5749                 (void *)&cmd_showbypass_config_show,
5750                 (void *)&cmd_showbypass_config_bypass,
5751                 (void *)&cmd_showbypass_config_config,
5752                 (void *)&cmd_showbypass_config_port,
5753                 NULL,
5754         },
5755 };
5756
5757 #ifdef RTE_NET_BOND
5758 /* *** SET BONDING MODE *** */
5759 struct cmd_set_bonding_mode_result {
5760         cmdline_fixed_string_t set;
5761         cmdline_fixed_string_t bonding;
5762         cmdline_fixed_string_t mode;
5763         uint8_t value;
5764         portid_t port_id;
5765 };
5766
5767 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5768                 __rte_unused  struct cmdline *cl,
5769                 __rte_unused void *data)
5770 {
5771         struct cmd_set_bonding_mode_result *res = parsed_result;
5772         portid_t port_id = res->port_id;
5773
5774         /* Set the bonding mode for the relevant port. */
5775         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5776                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5777 }
5778
5779 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5780 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5781                 set, "set");
5782 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5783 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5784                 bonding, "bonding");
5785 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5786 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5787                 mode, "mode");
5788 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5789 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5790                 value, UINT8);
5791 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5792 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5793                 port_id, UINT16);
5794
5795 cmdline_parse_inst_t cmd_set_bonding_mode = {
5796                 .f = cmd_set_bonding_mode_parsed,
5797                 .help_str = "set bonding mode <mode_value> <port_id>: "
5798                         "Set the bonding mode for port_id",
5799                 .data = NULL,
5800                 .tokens = {
5801                                 (void *) &cmd_setbonding_mode_set,
5802                                 (void *) &cmd_setbonding_mode_bonding,
5803                                 (void *) &cmd_setbonding_mode_mode,
5804                                 (void *) &cmd_setbonding_mode_value,
5805                                 (void *) &cmd_setbonding_mode_port,
5806                                 NULL
5807                 }
5808 };
5809
5810 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5811 struct cmd_set_bonding_lacp_dedicated_queues_result {
5812         cmdline_fixed_string_t set;
5813         cmdline_fixed_string_t bonding;
5814         cmdline_fixed_string_t lacp;
5815         cmdline_fixed_string_t dedicated_queues;
5816         portid_t port_id;
5817         cmdline_fixed_string_t mode;
5818 };
5819
5820 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5821                 __rte_unused  struct cmdline *cl,
5822                 __rte_unused void *data)
5823 {
5824         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5825         portid_t port_id = res->port_id;
5826         struct rte_port *port;
5827
5828         port = &ports[port_id];
5829
5830         /** Check if the port is not started **/
5831         if (port->port_status != RTE_PORT_STOPPED) {
5832                 printf("Please stop port %d first\n", port_id);
5833                 return;
5834         }
5835
5836         if (!strcmp(res->mode, "enable")) {
5837                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5838                         printf("Dedicate queues for LACP control packets"
5839                                         " enabled\n");
5840                 else
5841                         printf("Enabling dedicate queues for LACP control "
5842                                         "packets on port %d failed\n", port_id);
5843         } else if (!strcmp(res->mode, "disable")) {
5844                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5845                         printf("Dedicated queues for LACP control packets "
5846                                         "disabled\n");
5847                 else
5848                         printf("Disabling dedicated queues for LACP control "
5849                                         "traffic on port %d failed\n", port_id);
5850         }
5851 }
5852
5853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5855                 set, "set");
5856 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5858                 bonding, "bonding");
5859 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5861                 lacp, "lacp");
5862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5864                 dedicated_queues, "dedicated_queues");
5865 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5866 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5867                 port_id, UINT16);
5868 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5869 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5870                 mode, "enable#disable");
5871
5872 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5873                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5874                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5875                         "enable|disable: "
5876                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5877                 .data = NULL,
5878                 .tokens = {
5879                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5880                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5881                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5882                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5883                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5884                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5885                         NULL
5886                 }
5887 };
5888
5889 /* *** SET BALANCE XMIT POLICY *** */
5890 struct cmd_set_bonding_balance_xmit_policy_result {
5891         cmdline_fixed_string_t set;
5892         cmdline_fixed_string_t bonding;
5893         cmdline_fixed_string_t balance_xmit_policy;
5894         portid_t port_id;
5895         cmdline_fixed_string_t policy;
5896 };
5897
5898 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5899                 __rte_unused  struct cmdline *cl,
5900                 __rte_unused void *data)
5901 {
5902         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5903         portid_t port_id = res->port_id;
5904         uint8_t policy;
5905
5906         if (!strcmp(res->policy, "l2")) {
5907                 policy = BALANCE_XMIT_POLICY_LAYER2;
5908         } else if (!strcmp(res->policy, "l23")) {
5909                 policy = BALANCE_XMIT_POLICY_LAYER23;
5910         } else if (!strcmp(res->policy, "l34")) {
5911                 policy = BALANCE_XMIT_POLICY_LAYER34;
5912         } else {
5913                 printf("\t Invalid xmit policy selection");
5914                 return;
5915         }
5916
5917         /* Set the bonding mode for the relevant port. */
5918         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5919                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5920                                 port_id);
5921         }
5922 }
5923
5924 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5926                 set, "set");
5927 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5929                 bonding, "bonding");
5930 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5932                 balance_xmit_policy, "balance_xmit_policy");
5933 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5934 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5935                 port_id, UINT16);
5936 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5938                 policy, "l2#l23#l34");
5939
5940 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5941                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5942                 .help_str = "set bonding balance_xmit_policy <port_id> "
5943                         "l2|l23|l34: "
5944                         "Set the bonding balance_xmit_policy for port_id",
5945                 .data = NULL,
5946                 .tokens = {
5947                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5948                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5949                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5950                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5951                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5952                                 NULL
5953                 }
5954 };
5955
5956 /* *** SHOW NIC BONDING CONFIGURATION *** */
5957 struct cmd_show_bonding_config_result {
5958         cmdline_fixed_string_t show;
5959         cmdline_fixed_string_t bonding;
5960         cmdline_fixed_string_t config;
5961         portid_t port_id;
5962 };
5963
5964 static void cmd_show_bonding_config_parsed(void *parsed_result,
5965                 __rte_unused  struct cmdline *cl,
5966                 __rte_unused void *data)
5967 {
5968         struct cmd_show_bonding_config_result *res = parsed_result;
5969         int bonding_mode, agg_mode;
5970         portid_t slaves[RTE_MAX_ETHPORTS];
5971         int num_slaves, num_active_slaves;
5972         int primary_id;
5973         int i;
5974         portid_t port_id = res->port_id;
5975
5976         /* Display the bonding mode.*/
5977         bonding_mode = rte_eth_bond_mode_get(port_id);
5978         if (bonding_mode < 0) {
5979                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5980                 return;
5981         } else
5982                 printf("\tBonding mode: %d\n", bonding_mode);
5983
5984         if (bonding_mode == BONDING_MODE_BALANCE) {
5985                 int balance_xmit_policy;
5986
5987                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5988                 if (balance_xmit_policy < 0) {
5989                         printf("\tFailed to get balance xmit policy for port = %d\n",
5990                                         port_id);
5991                         return;
5992                 } else {
5993                         printf("\tBalance Xmit Policy: ");
5994
5995                         switch (balance_xmit_policy) {
5996                         case BALANCE_XMIT_POLICY_LAYER2:
5997                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5998                                 break;
5999                         case BALANCE_XMIT_POLICY_LAYER23:
6000                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6001                                 break;
6002                         case BALANCE_XMIT_POLICY_LAYER34:
6003                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6004                                 break;
6005                         }
6006                         printf("\n");
6007                 }
6008         }
6009
6010         if (bonding_mode == BONDING_MODE_8023AD) {
6011                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6012                 printf("\tIEEE802.3AD Aggregator Mode: ");
6013                 switch (agg_mode) {
6014                 case AGG_BANDWIDTH:
6015                         printf("bandwidth");
6016                         break;
6017                 case AGG_STABLE:
6018                         printf("stable");
6019                         break;
6020                 case AGG_COUNT:
6021                         printf("count");
6022                         break;
6023                 }
6024                 printf("\n");
6025         }
6026
6027         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6028
6029         if (num_slaves < 0) {
6030                 printf("\tFailed to get slave list for port = %d\n", port_id);
6031                 return;
6032         }
6033         if (num_slaves > 0) {
6034                 printf("\tSlaves (%d): [", num_slaves);
6035                 for (i = 0; i < num_slaves - 1; i++)
6036                         printf("%d ", slaves[i]);
6037
6038                 printf("%d]\n", slaves[num_slaves - 1]);
6039         } else {
6040                 printf("\tSlaves: []\n");
6041
6042         }
6043
6044         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6045                         RTE_MAX_ETHPORTS);
6046
6047         if (num_active_slaves < 0) {
6048                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6049                 return;
6050         }
6051         if (num_active_slaves > 0) {
6052                 printf("\tActive Slaves (%d): [", num_active_slaves);
6053                 for (i = 0; i < num_active_slaves - 1; i++)
6054                         printf("%d ", slaves[i]);
6055
6056                 printf("%d]\n", slaves[num_active_slaves - 1]);
6057
6058         } else {
6059                 printf("\tActive Slaves: []\n");
6060
6061         }
6062
6063         primary_id = rte_eth_bond_primary_get(port_id);
6064         if (primary_id < 0) {
6065                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6066                 return;
6067         } else
6068                 printf("\tPrimary: [%d]\n", primary_id);
6069
6070 }
6071
6072 cmdline_parse_token_string_t cmd_showbonding_config_show =
6073 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6074                 show, "show");
6075 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6076 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6077                 bonding, "bonding");
6078 cmdline_parse_token_string_t cmd_showbonding_config_config =
6079 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6080                 config, "config");
6081 cmdline_parse_token_num_t cmd_showbonding_config_port =
6082 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6083                 port_id, UINT16);
6084
6085 cmdline_parse_inst_t cmd_show_bonding_config = {
6086                 .f = cmd_show_bonding_config_parsed,
6087                 .help_str = "show bonding config <port_id>: "
6088                         "Show the bonding config for port_id",
6089                 .data = NULL,
6090                 .tokens = {
6091                                 (void *)&cmd_showbonding_config_show,
6092                                 (void *)&cmd_showbonding_config_bonding,
6093                                 (void *)&cmd_showbonding_config_config,
6094                                 (void *)&cmd_showbonding_config_port,
6095                                 NULL
6096                 }
6097 };
6098
6099 /* *** SET BONDING PRIMARY *** */
6100 struct cmd_set_bonding_primary_result {
6101         cmdline_fixed_string_t set;
6102         cmdline_fixed_string_t bonding;
6103         cmdline_fixed_string_t primary;
6104         portid_t slave_id;
6105         portid_t port_id;
6106 };
6107
6108 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6109                 __rte_unused  struct cmdline *cl,
6110                 __rte_unused void *data)
6111 {
6112         struct cmd_set_bonding_primary_result *res = parsed_result;
6113         portid_t master_port_id = res->port_id;
6114         portid_t slave_port_id = res->slave_id;
6115
6116         /* Set the primary slave for a bonded device. */
6117         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6118                 printf("\t Failed to set primary slave for port = %d.\n",
6119                                 master_port_id);
6120                 return;
6121         }
6122         init_port_config();
6123 }
6124
6125 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6126 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6127                 set, "set");
6128 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6129 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6130                 bonding, "bonding");
6131 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6132 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6133                 primary, "primary");
6134 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6135 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6136                 slave_id, UINT16);
6137 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6138 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6139                 port_id, UINT16);
6140
6141 cmdline_parse_inst_t cmd_set_bonding_primary = {
6142                 .f = cmd_set_bonding_primary_parsed,
6143                 .help_str = "set bonding primary <slave_id> <port_id>: "
6144                         "Set the primary slave for port_id",
6145                 .data = NULL,
6146                 .tokens = {
6147                                 (void *)&cmd_setbonding_primary_set,
6148                                 (void *)&cmd_setbonding_primary_bonding,
6149                                 (void *)&cmd_setbonding_primary_primary,
6150                                 (void *)&cmd_setbonding_primary_slave,
6151                                 (void *)&cmd_setbonding_primary_port,
6152                                 NULL
6153                 }
6154 };
6155
6156 /* *** ADD SLAVE *** */
6157 struct cmd_add_bonding_slave_result {
6158         cmdline_fixed_string_t add;
6159         cmdline_fixed_string_t bonding;
6160         cmdline_fixed_string_t slave;
6161         portid_t slave_id;
6162         portid_t port_id;
6163 };
6164
6165 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6166                 __rte_unused  struct cmdline *cl,
6167                 __rte_unused void *data)
6168 {
6169         struct cmd_add_bonding_slave_result *res = parsed_result;
6170         portid_t master_port_id = res->port_id;
6171         portid_t slave_port_id = res->slave_id;
6172
6173         /* add the slave for a bonded device. */
6174         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6175                 printf("\t Failed to add slave %d to master port = %d.\n",
6176                                 slave_port_id, master_port_id);
6177                 return;
6178         }
6179         init_port_config();
6180         set_port_slave_flag(slave_port_id);
6181 }
6182
6183 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6184 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6185                 add, "add");
6186 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6187 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6188                 bonding, "bonding");
6189 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6190 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6191                 slave, "slave");
6192 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6193 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6194                 slave_id, UINT16);
6195 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6196 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6197                 port_id, UINT16);
6198
6199 cmdline_parse_inst_t cmd_add_bonding_slave = {
6200                 .f = cmd_add_bonding_slave_parsed,
6201                 .help_str = "add bonding slave <slave_id> <port_id>: "
6202                         "Add a slave device to a bonded device",
6203                 .data = NULL,
6204                 .tokens = {
6205                                 (void *)&cmd_addbonding_slave_add,
6206                                 (void *)&cmd_addbonding_slave_bonding,
6207                                 (void *)&cmd_addbonding_slave_slave,
6208                                 (void *)&cmd_addbonding_slave_slaveid,
6209                                 (void *)&cmd_addbonding_slave_port,
6210                                 NULL
6211                 }
6212 };
6213
6214 /* *** REMOVE SLAVE *** */
6215 struct cmd_remove_bonding_slave_result {
6216         cmdline_fixed_string_t remove;
6217         cmdline_fixed_string_t bonding;
6218         cmdline_fixed_string_t slave;
6219         portid_t slave_id;
6220         portid_t port_id;
6221 };
6222
6223 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6224                 __rte_unused  struct cmdline *cl,
6225                 __rte_unused void *data)
6226 {
6227         struct cmd_remove_bonding_slave_result *res = parsed_result;
6228         portid_t master_port_id = res->port_id;
6229         portid_t slave_port_id = res->slave_id;
6230
6231         /* remove the slave from a bonded device. */
6232         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6233                 printf("\t Failed to remove slave %d from master port = %d.\n",
6234                                 slave_port_id, master_port_id);
6235                 return;
6236         }
6237         init_port_config();
6238         clear_port_slave_flag(slave_port_id);
6239 }
6240
6241 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6243                                 remove, "remove");
6244 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6246                                 bonding, "bonding");
6247 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6248                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6249                                 slave, "slave");
6250 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6251                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6252                                 slave_id, UINT16);
6253 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6254                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6255                                 port_id, UINT16);
6256
6257 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6258                 .f = cmd_remove_bonding_slave_parsed,
6259                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6260                         "Remove a slave device from a bonded device",
6261                 .data = NULL,
6262                 .tokens = {
6263                                 (void *)&cmd_removebonding_slave_remove,
6264                                 (void *)&cmd_removebonding_slave_bonding,
6265                                 (void *)&cmd_removebonding_slave_slave,
6266                                 (void *)&cmd_removebonding_slave_slaveid,
6267                                 (void *)&cmd_removebonding_slave_port,
6268                                 NULL
6269                 }
6270 };
6271
6272 /* *** CREATE BONDED DEVICE *** */
6273 struct cmd_create_bonded_device_result {
6274         cmdline_fixed_string_t create;
6275         cmdline_fixed_string_t bonded;
6276         cmdline_fixed_string_t device;
6277         uint8_t mode;
6278         uint8_t socket;
6279 };
6280
6281 static int bond_dev_num = 0;
6282
6283 static void cmd_create_bonded_device_parsed(void *parsed_result,
6284                 __rte_unused  struct cmdline *cl,
6285                 __rte_unused void *data)
6286 {
6287         struct cmd_create_bonded_device_result *res = parsed_result;
6288         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6289         int port_id;
6290         int ret;
6291
6292         if (test_done == 0) {
6293                 printf("Please stop forwarding first\n");
6294                 return;
6295         }
6296
6297         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6298                         bond_dev_num++);
6299
6300         /* Create a new bonded device. */
6301         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6302         if (port_id < 0) {
6303                 printf("\t Failed to create bonded device.\n");
6304                 return;
6305         } else {
6306                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6307                                 port_id);
6308
6309                 /* Update number of ports */
6310                 nb_ports = rte_eth_dev_count_avail();
6311                 reconfig(port_id, res->socket);
6312                 ret = rte_eth_promiscuous_enable(port_id);
6313                 if (ret != 0)
6314                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6315                                 port_id, rte_strerror(-ret));
6316
6317                 ports[port_id].need_setup = 0;
6318                 ports[port_id].port_status = RTE_PORT_STOPPED;
6319         }
6320
6321 }
6322
6323 cmdline_parse_token_string_t cmd_createbonded_device_create =
6324                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6325                                 create, "create");
6326 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6327                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6328                                 bonded, "bonded");
6329 cmdline_parse_token_string_t cmd_createbonded_device_device =
6330                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6331                                 device, "device");
6332 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6333                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6334                                 mode, UINT8);
6335 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6336                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6337                                 socket, UINT8);
6338
6339 cmdline_parse_inst_t cmd_create_bonded_device = {
6340                 .f = cmd_create_bonded_device_parsed,
6341                 .help_str = "create bonded device <mode> <socket>: "
6342                         "Create a new bonded device with specific bonding mode and socket",
6343                 .data = NULL,
6344                 .tokens = {
6345                                 (void *)&cmd_createbonded_device_create,
6346                                 (void *)&cmd_createbonded_device_bonded,
6347                                 (void *)&cmd_createbonded_device_device,
6348                                 (void *)&cmd_createbonded_device_mode,
6349                                 (void *)&cmd_createbonded_device_socket,
6350                                 NULL
6351                 }
6352 };
6353
6354 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6355 struct cmd_set_bond_mac_addr_result {
6356         cmdline_fixed_string_t set;
6357         cmdline_fixed_string_t bonding;
6358         cmdline_fixed_string_t mac_addr;
6359         uint16_t port_num;
6360         struct rte_ether_addr address;
6361 };
6362
6363 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6364                 __rte_unused  struct cmdline *cl,
6365                 __rte_unused void *data)
6366 {
6367         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6368         int ret;
6369
6370         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6371                 return;
6372
6373         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6374
6375         /* check the return value and print it if is < 0 */
6376         if (ret < 0)
6377                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6378 }
6379
6380 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6381                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6382 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6383                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6384                                 "bonding");
6385 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6386                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6387                                 "mac_addr");
6388 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6389                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6390                                 port_num, UINT16);
6391 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6392                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6393
6394 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6395                 .f = cmd_set_bond_mac_addr_parsed,
6396                 .data = (void *) 0,
6397                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6398                 .tokens = {
6399                                 (void *)&cmd_set_bond_mac_addr_set,
6400                                 (void *)&cmd_set_bond_mac_addr_bonding,
6401                                 (void *)&cmd_set_bond_mac_addr_mac,
6402                                 (void *)&cmd_set_bond_mac_addr_portnum,
6403                                 (void *)&cmd_set_bond_mac_addr_addr,
6404                                 NULL
6405                 }
6406 };
6407
6408
6409 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6410 struct cmd_set_bond_mon_period_result {
6411         cmdline_fixed_string_t set;
6412         cmdline_fixed_string_t bonding;
6413         cmdline_fixed_string_t mon_period;
6414         uint16_t port_num;
6415         uint32_t period_ms;
6416 };
6417
6418 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6419                 __rte_unused  struct cmdline *cl,
6420                 __rte_unused void *data)
6421 {
6422         struct cmd_set_bond_mon_period_result *res = parsed_result;
6423         int ret;
6424
6425         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6426
6427         /* check the return value and print it if is < 0 */
6428         if (ret < 0)
6429                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6430 }
6431
6432 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6433                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6434                                 set, "set");
6435 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6436                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6437                                 bonding, "bonding");
6438 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6439                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6440                                 mon_period,     "mon_period");
6441 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6442                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6443                                 port_num, UINT16);
6444 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6445                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6446                                 period_ms, UINT32);
6447
6448 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6449                 .f = cmd_set_bond_mon_period_parsed,
6450                 .data = (void *) 0,
6451                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6452                 .tokens = {
6453                                 (void *)&cmd_set_bond_mon_period_set,
6454                                 (void *)&cmd_set_bond_mon_period_bonding,
6455                                 (void *)&cmd_set_bond_mon_period_mon_period,
6456                                 (void *)&cmd_set_bond_mon_period_portnum,
6457                                 (void *)&cmd_set_bond_mon_period_period_ms,
6458                                 NULL
6459                 }
6460 };
6461
6462
6463
6464 struct cmd_set_bonding_agg_mode_policy_result {
6465         cmdline_fixed_string_t set;
6466         cmdline_fixed_string_t bonding;
6467         cmdline_fixed_string_t agg_mode;
6468         uint16_t port_num;
6469         cmdline_fixed_string_t policy;
6470 };
6471
6472
6473 static void
6474 cmd_set_bonding_agg_mode(void *parsed_result,
6475                 __rte_unused struct cmdline *cl,
6476                 __rte_unused void *data)
6477 {
6478         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6479         uint8_t policy = AGG_BANDWIDTH;
6480
6481         if (!strcmp(res->policy, "bandwidth"))
6482                 policy = AGG_BANDWIDTH;
6483         else if (!strcmp(res->policy, "stable"))
6484                 policy = AGG_STABLE;
6485         else if (!strcmp(res->policy, "count"))
6486                 policy = AGG_COUNT;
6487
6488         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6489 }
6490
6491
6492 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6493         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6494                                 set, "set");
6495 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6497                                 bonding, "bonding");
6498
6499 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6501                                 agg_mode, "agg_mode");
6502
6503 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6504         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6505                                 port_num, UINT16);
6506
6507 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6508         TOKEN_STRING_INITIALIZER(
6509                         struct cmd_set_bonding_balance_xmit_policy_result,
6510                 policy, "stable#bandwidth#count");
6511
6512 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6513         .f = cmd_set_bonding_agg_mode,
6514         .data = (void *) 0,
6515         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6516         .tokens = {
6517                         (void *)&cmd_set_bonding_agg_mode_set,
6518                         (void *)&cmd_set_bonding_agg_mode_bonding,
6519                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6520                         (void *)&cmd_set_bonding_agg_mode_portnum,
6521                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6522                         NULL
6523                 }
6524 };
6525
6526
6527 #endif /* RTE_NET_BOND */
6528
6529 /* *** SET FORWARDING MODE *** */
6530 struct cmd_set_fwd_mode_result {
6531         cmdline_fixed_string_t set;
6532         cmdline_fixed_string_t fwd;
6533         cmdline_fixed_string_t mode;
6534 };
6535
6536 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6537                                     __rte_unused struct cmdline *cl,
6538                                     __rte_unused void *data)
6539 {
6540         struct cmd_set_fwd_mode_result *res = parsed_result;
6541
6542         retry_enabled = 0;
6543         set_pkt_forwarding_mode(res->mode);
6544 }
6545
6546 cmdline_parse_token_string_t cmd_setfwd_set =
6547         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6548 cmdline_parse_token_string_t cmd_setfwd_fwd =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6550 cmdline_parse_token_string_t cmd_setfwd_mode =
6551         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6552                 "" /* defined at init */);
6553
6554 cmdline_parse_inst_t cmd_set_fwd_mode = {
6555         .f = cmd_set_fwd_mode_parsed,
6556         .data = NULL,
6557         .help_str = NULL, /* defined at init */
6558         .tokens = {
6559                 (void *)&cmd_setfwd_set,
6560                 (void *)&cmd_setfwd_fwd,
6561                 (void *)&cmd_setfwd_mode,
6562                 NULL,
6563         },
6564 };
6565
6566 static void cmd_set_fwd_mode_init(void)
6567 {
6568         char *modes, *c;
6569         static char token[128];
6570         static char help[256];
6571         cmdline_parse_token_string_t *token_struct;
6572
6573         modes = list_pkt_forwarding_modes();
6574         snprintf(help, sizeof(help), "set fwd %s: "
6575                 "Set packet forwarding mode", modes);
6576         cmd_set_fwd_mode.help_str = help;
6577
6578         /* string token separator is # */
6579         for (c = token; *modes != '\0'; modes++)
6580                 if (*modes == '|')
6581                         *c++ = '#';
6582                 else
6583                         *c++ = *modes;
6584         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6585         token_struct->string_data.str = token;
6586 }
6587
6588 /* *** SET RETRY FORWARDING MODE *** */
6589 struct cmd_set_fwd_retry_mode_result {
6590         cmdline_fixed_string_t set;
6591         cmdline_fixed_string_t fwd;
6592         cmdline_fixed_string_t mode;
6593         cmdline_fixed_string_t retry;
6594 };
6595
6596 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6597                             __rte_unused struct cmdline *cl,
6598                             __rte_unused void *data)
6599 {
6600         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6601
6602         retry_enabled = 1;
6603         set_pkt_forwarding_mode(res->mode);
6604 }
6605
6606 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6608                         set, "set");
6609 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6610         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6611                         fwd, "fwd");
6612 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6613         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6614                         mode,
6615                 "" /* defined at init */);
6616 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6617         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6618                         retry, "retry");
6619
6620 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6621         .f = cmd_set_fwd_retry_mode_parsed,
6622         .data = NULL,
6623         .help_str = NULL, /* defined at init */
6624         .tokens = {
6625                 (void *)&cmd_setfwd_retry_set,
6626                 (void *)&cmd_setfwd_retry_fwd,
6627                 (void *)&cmd_setfwd_retry_mode,
6628                 (void *)&cmd_setfwd_retry_retry,
6629                 NULL,
6630         },
6631 };
6632
6633 static void cmd_set_fwd_retry_mode_init(void)
6634 {
6635         char *modes, *c;
6636         static char token[128];
6637         static char help[256];
6638         cmdline_parse_token_string_t *token_struct;
6639
6640         modes = list_pkt_forwarding_retry_modes();
6641         snprintf(help, sizeof(help), "set fwd %s retry: "
6642                 "Set packet forwarding mode with retry", modes);
6643         cmd_set_fwd_retry_mode.help_str = help;
6644
6645         /* string token separator is # */
6646         for (c = token; *modes != '\0'; modes++)
6647                 if (*modes == '|')
6648                         *c++ = '#';
6649                 else
6650                         *c++ = *modes;
6651         token_struct = (cmdline_parse_token_string_t *)
6652                 cmd_set_fwd_retry_mode.tokens[2];
6653         token_struct->string_data.str = token;
6654 }
6655
6656 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6657 struct cmd_set_burst_tx_retry_result {
6658         cmdline_fixed_string_t set;
6659         cmdline_fixed_string_t burst;
6660         cmdline_fixed_string_t tx;
6661         cmdline_fixed_string_t delay;
6662         uint32_t time;
6663         cmdline_fixed_string_t retry;
6664         uint32_t retry_num;
6665 };
6666
6667 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6668                                         __rte_unused struct cmdline *cl,
6669                                         __rte_unused void *data)
6670 {
6671         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6672
6673         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6674                 && !strcmp(res->tx, "tx")) {
6675                 if (!strcmp(res->delay, "delay"))
6676                         burst_tx_delay_time = res->time;
6677                 if (!strcmp(res->retry, "retry"))
6678                         burst_tx_retry_num = res->retry_num;
6679         }
6680
6681 }
6682
6683 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6685 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6686         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6687                                  "burst");
6688 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6689         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6690 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6692 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6693         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6694 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6695         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6696 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6697         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6698
6699 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6700         .f = cmd_set_burst_tx_retry_parsed,
6701         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6702         .tokens = {
6703                 (void *)&cmd_set_burst_tx_retry_set,
6704                 (void *)&cmd_set_burst_tx_retry_burst,
6705                 (void *)&cmd_set_burst_tx_retry_tx,
6706                 (void *)&cmd_set_burst_tx_retry_delay,
6707                 (void *)&cmd_set_burst_tx_retry_time,
6708                 (void *)&cmd_set_burst_tx_retry_retry,
6709                 (void *)&cmd_set_burst_tx_retry_retry_num,
6710                 NULL,
6711         },
6712 };
6713
6714 /* *** SET PROMISC MODE *** */
6715 struct cmd_set_promisc_mode_result {
6716         cmdline_fixed_string_t set;
6717         cmdline_fixed_string_t promisc;
6718         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6719         uint16_t port_num;               /* valid if "allports" argument == 0 */
6720         cmdline_fixed_string_t mode;
6721 };
6722
6723 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6724                                         __rte_unused struct cmdline *cl,
6725                                         void *allports)
6726 {
6727         struct cmd_set_promisc_mode_result *res = parsed_result;
6728         int enable;
6729         portid_t i;
6730
6731         if (!strcmp(res->mode, "on"))
6732                 enable = 1;
6733         else
6734                 enable = 0;
6735
6736         /* all ports */
6737         if (allports) {
6738                 RTE_ETH_FOREACH_DEV(i)
6739                         eth_set_promisc_mode(i, enable);
6740         } else {
6741                 eth_set_promisc_mode(res->port_num, enable);
6742         }
6743 }
6744
6745 cmdline_parse_token_string_t cmd_setpromisc_set =
6746         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6747 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6748         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6749                                  "promisc");
6750 cmdline_parse_token_string_t cmd_setpromisc_portall =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6752                                  "all");
6753 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6754         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6755                               UINT16);
6756 cmdline_parse_token_string_t cmd_setpromisc_mode =
6757         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6758                                  "on#off");
6759
6760 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6761         .f = cmd_set_promisc_mode_parsed,
6762         .data = (void *)1,
6763         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6764         .tokens = {
6765                 (void *)&cmd_setpromisc_set,
6766                 (void *)&cmd_setpromisc_promisc,
6767                 (void *)&cmd_setpromisc_portall,
6768                 (void *)&cmd_setpromisc_mode,
6769                 NULL,
6770         },
6771 };
6772
6773 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6774         .f = cmd_set_promisc_mode_parsed,
6775         .data = (void *)0,
6776         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6777         .tokens = {
6778                 (void *)&cmd_setpromisc_set,
6779                 (void *)&cmd_setpromisc_promisc,
6780                 (void *)&cmd_setpromisc_portnum,
6781                 (void *)&cmd_setpromisc_mode,
6782                 NULL,
6783         },
6784 };
6785
6786 /* *** SET ALLMULTI MODE *** */
6787 struct cmd_set_allmulti_mode_result {
6788         cmdline_fixed_string_t set;
6789         cmdline_fixed_string_t allmulti;
6790         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6791         uint16_t port_num;               /* valid if "allports" argument == 0 */
6792         cmdline_fixed_string_t mode;
6793 };
6794
6795 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6796                                         __rte_unused struct cmdline *cl,
6797                                         void *allports)
6798 {
6799         struct cmd_set_allmulti_mode_result *res = parsed_result;
6800         int enable;
6801         portid_t i;
6802
6803         if (!strcmp(res->mode, "on"))
6804                 enable = 1;
6805         else
6806                 enable = 0;
6807
6808         /* all ports */
6809         if (allports) {
6810                 RTE_ETH_FOREACH_DEV(i) {
6811                         eth_set_allmulticast_mode(i, enable);
6812                 }
6813         }
6814         else {
6815                 eth_set_allmulticast_mode(res->port_num, enable);
6816         }
6817 }
6818
6819 cmdline_parse_token_string_t cmd_setallmulti_set =
6820         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6821 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6822         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6823                                  "allmulti");
6824 cmdline_parse_token_string_t cmd_setallmulti_portall =
6825         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6826                                  "all");
6827 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6828         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6829                               UINT16);
6830 cmdline_parse_token_string_t cmd_setallmulti_mode =
6831         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6832                                  "on#off");
6833
6834 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6835         .f = cmd_set_allmulti_mode_parsed,
6836         .data = (void *)1,
6837         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6838         .tokens = {
6839                 (void *)&cmd_setallmulti_set,
6840                 (void *)&cmd_setallmulti_allmulti,
6841                 (void *)&cmd_setallmulti_portall,
6842                 (void *)&cmd_setallmulti_mode,
6843                 NULL,
6844         },
6845 };
6846
6847 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6848         .f = cmd_set_allmulti_mode_parsed,
6849         .data = (void *)0,
6850         .help_str = "set allmulti <port_id> on|off: "
6851                 "Set allmulti mode on port_id",
6852         .tokens = {
6853                 (void *)&cmd_setallmulti_set,
6854                 (void *)&cmd_setallmulti_allmulti,
6855                 (void *)&cmd_setallmulti_portnum,
6856                 (void *)&cmd_setallmulti_mode,
6857                 NULL,
6858         },
6859 };
6860
6861 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6862 struct cmd_link_flow_ctrl_set_result {
6863         cmdline_fixed_string_t set;
6864         cmdline_fixed_string_t flow_ctrl;
6865         cmdline_fixed_string_t rx;
6866         cmdline_fixed_string_t rx_lfc_mode;
6867         cmdline_fixed_string_t tx;
6868         cmdline_fixed_string_t tx_lfc_mode;
6869         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6870         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6871         cmdline_fixed_string_t autoneg_str;
6872         cmdline_fixed_string_t autoneg;
6873         cmdline_fixed_string_t hw_str;
6874         uint32_t high_water;
6875         cmdline_fixed_string_t lw_str;
6876         uint32_t low_water;
6877         cmdline_fixed_string_t pt_str;
6878         uint16_t pause_time;
6879         cmdline_fixed_string_t xon_str;
6880         uint16_t send_xon;
6881         portid_t port_id;
6882 };
6883
6884 cmdline_parse_token_string_t cmd_lfc_set_set =
6885         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6886                                 set, "set");
6887 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6888         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6889                                 flow_ctrl, "flow_ctrl");
6890 cmdline_parse_token_string_t cmd_lfc_set_rx =
6891         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6892                                 rx, "rx");
6893 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6894         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6895                                 rx_lfc_mode, "on#off");
6896 cmdline_parse_token_string_t cmd_lfc_set_tx =
6897         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6898                                 tx, "tx");
6899 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6900         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6901                                 tx_lfc_mode, "on#off");
6902 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6903         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6904                                 hw_str, "high_water");
6905 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6906         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6907                                 high_water, UINT32);
6908 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6909         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6910                                 lw_str, "low_water");
6911 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6912         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6913                                 low_water, UINT32);
6914 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6915         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6916                                 pt_str, "pause_time");
6917 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6918         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6919                                 pause_time, UINT16);
6920 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6921         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6922                                 xon_str, "send_xon");
6923 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6924         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6925                                 send_xon, UINT16);
6926 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6927         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6928                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6929 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6930         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6931                                 mac_ctrl_frame_fwd_mode, "on#off");
6932 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6933         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6934                                 autoneg_str, "autoneg");
6935 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6936         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6937                                 autoneg, "on#off");
6938 cmdline_parse_token_num_t cmd_lfc_set_portid =
6939         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6940                                 port_id, UINT16);
6941
6942 /* forward declaration */
6943 static void
6944 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6945                               void *data);
6946
6947 cmdline_parse_inst_t cmd_link_flow_control_set = {
6948         .f = cmd_link_flow_ctrl_set_parsed,
6949         .data = NULL,
6950         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6951                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6952                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6953         .tokens = {
6954                 (void *)&cmd_lfc_set_set,
6955                 (void *)&cmd_lfc_set_flow_ctrl,
6956                 (void *)&cmd_lfc_set_rx,
6957                 (void *)&cmd_lfc_set_rx_mode,
6958                 (void *)&cmd_lfc_set_tx,
6959                 (void *)&cmd_lfc_set_tx_mode,
6960                 (void *)&cmd_lfc_set_high_water,
6961                 (void *)&cmd_lfc_set_low_water,
6962                 (void *)&cmd_lfc_set_pause_time,
6963                 (void *)&cmd_lfc_set_send_xon,
6964                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6965                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6966                 (void *)&cmd_lfc_set_autoneg_str,
6967                 (void *)&cmd_lfc_set_autoneg,
6968                 (void *)&cmd_lfc_set_portid,
6969                 NULL,
6970         },
6971 };
6972
6973 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6974         .f = cmd_link_flow_ctrl_set_parsed,
6975         .data = (void *)&cmd_link_flow_control_set_rx,
6976         .help_str = "set flow_ctrl rx on|off <port_id>: "
6977                 "Change rx flow control parameter",
6978         .tokens = {
6979                 (void *)&cmd_lfc_set_set,
6980                 (void *)&cmd_lfc_set_flow_ctrl,
6981                 (void *)&cmd_lfc_set_rx,
6982                 (void *)&cmd_lfc_set_rx_mode,
6983                 (void *)&cmd_lfc_set_portid,
6984                 NULL,
6985         },
6986 };
6987
6988 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6989         .f = cmd_link_flow_ctrl_set_parsed,
6990         .data = (void *)&cmd_link_flow_control_set_tx,
6991         .help_str = "set flow_ctrl tx on|off <port_id>: "
6992                 "Change tx flow control parameter",
6993         .tokens = {
6994                 (void *)&cmd_lfc_set_set,
6995                 (void *)&cmd_lfc_set_flow_ctrl,
6996                 (void *)&cmd_lfc_set_tx,
6997                 (void *)&cmd_lfc_set_tx_mode,
6998                 (void *)&cmd_lfc_set_portid,
6999                 NULL,
7000         },
7001 };
7002
7003 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7004         .f = cmd_link_flow_ctrl_set_parsed,
7005         .data = (void *)&cmd_link_flow_control_set_hw,
7006         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7007                 "Change high water flow control parameter",
7008         .tokens = {
7009                 (void *)&cmd_lfc_set_set,
7010                 (void *)&cmd_lfc_set_flow_ctrl,
7011                 (void *)&cmd_lfc_set_high_water_str,
7012                 (void *)&cmd_lfc_set_high_water,
7013                 (void *)&cmd_lfc_set_portid,
7014                 NULL,
7015         },
7016 };
7017
7018 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7019         .f = cmd_link_flow_ctrl_set_parsed,
7020         .data = (void *)&cmd_link_flow_control_set_lw,
7021         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7022                 "Change low water flow control parameter",
7023         .tokens = {
7024                 (void *)&cmd_lfc_set_set,
7025                 (void *)&cmd_lfc_set_flow_ctrl,
7026                 (void *)&cmd_lfc_set_low_water_str,
7027                 (void *)&cmd_lfc_set_low_water,
7028                 (void *)&cmd_lfc_set_portid,
7029                 NULL,
7030         },
7031 };
7032
7033 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7034         .f = cmd_link_flow_ctrl_set_parsed,
7035         .data = (void *)&cmd_link_flow_control_set_pt,
7036         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7037                 "Change pause time flow control parameter",
7038         .tokens = {
7039                 (void *)&cmd_lfc_set_set,
7040                 (void *)&cmd_lfc_set_flow_ctrl,
7041                 (void *)&cmd_lfc_set_pause_time_str,
7042                 (void *)&cmd_lfc_set_pause_time,
7043                 (void *)&cmd_lfc_set_portid,
7044                 NULL,
7045         },
7046 };
7047
7048 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7049         .f = cmd_link_flow_ctrl_set_parsed,
7050         .data = (void *)&cmd_link_flow_control_set_xon,
7051         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7052                 "Change send_xon flow control parameter",
7053         .tokens = {
7054                 (void *)&cmd_lfc_set_set,
7055                 (void *)&cmd_lfc_set_flow_ctrl,
7056                 (void *)&cmd_lfc_set_send_xon_str,
7057                 (void *)&cmd_lfc_set_send_xon,
7058                 (void *)&cmd_lfc_set_portid,
7059                 NULL,
7060         },
7061 };
7062
7063 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7064         .f = cmd_link_flow_ctrl_set_parsed,
7065         .data = (void *)&cmd_link_flow_control_set_macfwd,
7066         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7067                 "Change mac ctrl fwd flow control parameter",
7068         .tokens = {
7069                 (void *)&cmd_lfc_set_set,
7070                 (void *)&cmd_lfc_set_flow_ctrl,
7071                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7072                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7073                 (void *)&cmd_lfc_set_portid,
7074                 NULL,
7075         },
7076 };
7077
7078 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7079         .f = cmd_link_flow_ctrl_set_parsed,
7080         .data = (void *)&cmd_link_flow_control_set_autoneg,
7081         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7082                 "Change autoneg flow control parameter",
7083         .tokens = {
7084                 (void *)&cmd_lfc_set_set,
7085                 (void *)&cmd_lfc_set_flow_ctrl,
7086                 (void *)&cmd_lfc_set_autoneg_str,
7087                 (void *)&cmd_lfc_set_autoneg,
7088                 (void *)&cmd_lfc_set_portid,
7089                 NULL,
7090         },
7091 };
7092
7093 static void
7094 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7095                               __rte_unused struct cmdline *cl,
7096                               void *data)
7097 {
7098         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7099         cmdline_parse_inst_t *cmd = data;
7100         struct rte_eth_fc_conf fc_conf;
7101         int rx_fc_en = 0;
7102         int tx_fc_en = 0;
7103         int ret;
7104
7105         /*
7106          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7107          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7108          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7109          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7110          */
7111         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7112                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7113         };
7114
7115         /* Partial command line, retrieve current configuration */
7116         if (cmd) {
7117                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7118                 if (ret != 0) {
7119                         printf("cannot get current flow ctrl parameters, return"
7120                                "code = %d\n", ret);
7121                         return;
7122                 }
7123
7124                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7125                     (fc_conf.mode == RTE_FC_FULL))
7126                         rx_fc_en = 1;
7127                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7128                     (fc_conf.mode == RTE_FC_FULL))
7129                         tx_fc_en = 1;
7130         }
7131
7132         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7133                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7134
7135         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7136                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7137
7138         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7139
7140         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7141                 fc_conf.high_water = res->high_water;
7142
7143         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7144                 fc_conf.low_water = res->low_water;
7145
7146         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7147                 fc_conf.pause_time = res->pause_time;
7148
7149         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7150                 fc_conf.send_xon = res->send_xon;
7151
7152         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7153                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7154                         fc_conf.mac_ctrl_frame_fwd = 1;
7155                 else
7156                         fc_conf.mac_ctrl_frame_fwd = 0;
7157         }
7158
7159         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7160                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7161
7162         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7163         if (ret != 0)
7164                 printf("bad flow contrl parameter, return code = %d \n", ret);
7165 }
7166
7167 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7168 struct cmd_priority_flow_ctrl_set_result {
7169         cmdline_fixed_string_t set;
7170         cmdline_fixed_string_t pfc_ctrl;
7171         cmdline_fixed_string_t rx;
7172         cmdline_fixed_string_t rx_pfc_mode;
7173         cmdline_fixed_string_t tx;
7174         cmdline_fixed_string_t tx_pfc_mode;
7175         uint32_t high_water;
7176         uint32_t low_water;
7177         uint16_t pause_time;
7178         uint8_t  priority;
7179         portid_t port_id;
7180 };
7181
7182 static void
7183 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7184                        __rte_unused struct cmdline *cl,
7185                        __rte_unused void *data)
7186 {
7187         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7188         struct rte_eth_pfc_conf pfc_conf;
7189         int rx_fc_enable, tx_fc_enable;
7190         int ret;
7191
7192         /*
7193          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7194          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7195          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7196          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7197          */
7198         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7199                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7200         };
7201
7202         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7203         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7204         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7205         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7206         pfc_conf.fc.high_water = res->high_water;
7207         pfc_conf.fc.low_water  = res->low_water;
7208         pfc_conf.fc.pause_time = res->pause_time;
7209         pfc_conf.priority      = res->priority;
7210
7211         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7212         if (ret != 0)
7213                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7214 }
7215
7216 cmdline_parse_token_string_t cmd_pfc_set_set =
7217         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7218                                 set, "set");
7219 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7220         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7221                                 pfc_ctrl, "pfc_ctrl");
7222 cmdline_parse_token_string_t cmd_pfc_set_rx =
7223         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7224                                 rx, "rx");
7225 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7226         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7227                                 rx_pfc_mode, "on#off");
7228 cmdline_parse_token_string_t cmd_pfc_set_tx =
7229         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7230                                 tx, "tx");
7231 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7232         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7233                                 tx_pfc_mode, "on#off");
7234 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7235         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7236                                 high_water, UINT32);
7237 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7238         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7239                                 low_water, UINT32);
7240 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7241         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7242                                 pause_time, UINT16);
7243 cmdline_parse_token_num_t cmd_pfc_set_priority =
7244         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7245                                 priority, UINT8);
7246 cmdline_parse_token_num_t cmd_pfc_set_portid =
7247         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7248                                 port_id, UINT16);
7249
7250 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7251         .f = cmd_priority_flow_ctrl_set_parsed,
7252         .data = NULL,
7253         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7254                 "<pause_time> <priority> <port_id>: "
7255                 "Configure the Ethernet priority flow control",
7256         .tokens = {
7257                 (void *)&cmd_pfc_set_set,
7258                 (void *)&cmd_pfc_set_flow_ctrl,
7259                 (void *)&cmd_pfc_set_rx,
7260                 (void *)&cmd_pfc_set_rx_mode,
7261                 (void *)&cmd_pfc_set_tx,
7262                 (void *)&cmd_pfc_set_tx_mode,
7263                 (void *)&cmd_pfc_set_high_water,
7264                 (void *)&cmd_pfc_set_low_water,
7265                 (void *)&cmd_pfc_set_pause_time,
7266                 (void *)&cmd_pfc_set_priority,
7267                 (void *)&cmd_pfc_set_portid,
7268                 NULL,
7269         },
7270 };
7271
7272 /* *** RESET CONFIGURATION *** */
7273 struct cmd_reset_result {
7274         cmdline_fixed_string_t reset;
7275         cmdline_fixed_string_t def;
7276 };
7277
7278 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7279                              struct cmdline *cl,
7280                              __rte_unused void *data)
7281 {
7282         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7283         set_def_fwd_config();
7284 }
7285
7286 cmdline_parse_token_string_t cmd_reset_set =
7287         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7288 cmdline_parse_token_string_t cmd_reset_def =
7289         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7290                                  "default");
7291
7292 cmdline_parse_inst_t cmd_reset = {
7293         .f = cmd_reset_parsed,
7294         .data = NULL,
7295         .help_str = "set default: Reset default forwarding configuration",
7296         .tokens = {
7297                 (void *)&cmd_reset_set,
7298                 (void *)&cmd_reset_def,
7299                 NULL,
7300         },
7301 };
7302
7303 /* *** START FORWARDING *** */
7304 struct cmd_start_result {
7305         cmdline_fixed_string_t start;
7306 };
7307
7308 cmdline_parse_token_string_t cmd_start_start =
7309         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7310
7311 static void cmd_start_parsed(__rte_unused void *parsed_result,
7312                              __rte_unused struct cmdline *cl,
7313                              __rte_unused void *data)
7314 {
7315         start_packet_forwarding(0);
7316 }
7317
7318 cmdline_parse_inst_t cmd_start = {
7319         .f = cmd_start_parsed,
7320         .data = NULL,
7321         .help_str = "start: Start packet forwarding",
7322         .tokens = {
7323                 (void *)&cmd_start_start,
7324                 NULL,
7325         },
7326 };
7327
7328 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7329 struct cmd_start_tx_first_result {
7330         cmdline_fixed_string_t start;
7331         cmdline_fixed_string_t tx_first;
7332 };
7333
7334 static void
7335 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7336                           __rte_unused struct cmdline *cl,
7337                           __rte_unused void *data)
7338 {
7339         start_packet_forwarding(1);
7340 }
7341
7342 cmdline_parse_token_string_t cmd_start_tx_first_start =
7343         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7344                                  "start");
7345 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7346         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7347                                  tx_first, "tx_first");
7348
7349 cmdline_parse_inst_t cmd_start_tx_first = {
7350         .f = cmd_start_tx_first_parsed,
7351         .data = NULL,
7352         .help_str = "start tx_first: Start packet forwarding, "
7353                 "after sending 1 burst of packets",
7354         .tokens = {
7355                 (void *)&cmd_start_tx_first_start,
7356                 (void *)&cmd_start_tx_first_tx_first,
7357                 NULL,
7358         },
7359 };
7360
7361 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7362 struct cmd_start_tx_first_n_result {
7363         cmdline_fixed_string_t start;
7364         cmdline_fixed_string_t tx_first;
7365         uint32_t tx_num;
7366 };
7367
7368 static void
7369 cmd_start_tx_first_n_parsed(void *parsed_result,
7370                           __rte_unused struct cmdline *cl,
7371                           __rte_unused void *data)
7372 {
7373         struct cmd_start_tx_first_n_result *res = parsed_result;
7374
7375         start_packet_forwarding(res->tx_num);
7376 }
7377
7378 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7379         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7380                         start, "start");
7381 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7382         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7383                         tx_first, "tx_first");
7384 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7385         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7386                         tx_num, UINT32);
7387
7388 cmdline_parse_inst_t cmd_start_tx_first_n = {
7389         .f = cmd_start_tx_first_n_parsed,
7390         .data = NULL,
7391         .help_str = "start tx_first <num>: "
7392                 "packet forwarding, after sending <num> bursts of packets",
7393         .tokens = {
7394                 (void *)&cmd_start_tx_first_n_start,
7395                 (void *)&cmd_start_tx_first_n_tx_first,
7396                 (void *)&cmd_start_tx_first_n_tx_num,
7397                 NULL,
7398         },
7399 };
7400
7401 /* *** SET LINK UP *** */
7402 struct cmd_set_link_up_result {
7403         cmdline_fixed_string_t set;
7404         cmdline_fixed_string_t link_up;
7405         cmdline_fixed_string_t port;
7406         portid_t port_id;
7407 };
7408
7409 cmdline_parse_token_string_t cmd_set_link_up_set =
7410         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7411 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7412         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7413                                 "link-up");
7414 cmdline_parse_token_string_t cmd_set_link_up_port =
7415         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7416 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7417         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7418
7419 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7420                              __rte_unused struct cmdline *cl,
7421                              __rte_unused void *data)
7422 {
7423         struct cmd_set_link_up_result *res = parsed_result;
7424         dev_set_link_up(res->port_id);
7425 }
7426
7427 cmdline_parse_inst_t cmd_set_link_up = {
7428         .f = cmd_set_link_up_parsed,
7429         .data = NULL,
7430         .help_str = "set link-up port <port id>",
7431         .tokens = {
7432                 (void *)&cmd_set_link_up_set,
7433                 (void *)&cmd_set_link_up_link_up,
7434                 (void *)&cmd_set_link_up_port,
7435                 (void *)&cmd_set_link_up_port_id,
7436                 NULL,
7437         },
7438 };
7439
7440 /* *** SET LINK DOWN *** */
7441 struct cmd_set_link_down_result {
7442         cmdline_fixed_string_t set;
7443         cmdline_fixed_string_t link_down;
7444         cmdline_fixed_string_t port;
7445         portid_t port_id;
7446 };
7447
7448 cmdline_parse_token_string_t cmd_set_link_down_set =
7449         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7450 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7452                                 "link-down");
7453 cmdline_parse_token_string_t cmd_set_link_down_port =
7454         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7455 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7456         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7457
7458 static void cmd_set_link_down_parsed(
7459                                 __rte_unused void *parsed_result,
7460                                 __rte_unused struct cmdline *cl,
7461                                 __rte_unused void *data)
7462 {
7463         struct cmd_set_link_down_result *res = parsed_result;
7464         dev_set_link_down(res->port_id);
7465 }
7466
7467 cmdline_parse_inst_t cmd_set_link_down = {
7468         .f = cmd_set_link_down_parsed,
7469         .data = NULL,
7470         .help_str = "set link-down port <port id>",
7471         .tokens = {
7472                 (void *)&cmd_set_link_down_set,
7473                 (void *)&cmd_set_link_down_link_down,
7474                 (void *)&cmd_set_link_down_port,
7475                 (void *)&cmd_set_link_down_port_id,
7476                 NULL,
7477         },
7478 };
7479
7480 /* *** SHOW CFG *** */
7481 struct cmd_showcfg_result {
7482         cmdline_fixed_string_t show;
7483         cmdline_fixed_string_t cfg;
7484         cmdline_fixed_string_t what;
7485 };
7486
7487 static void cmd_showcfg_parsed(void *parsed_result,
7488                                __rte_unused struct cmdline *cl,
7489                                __rte_unused void *data)
7490 {
7491         struct cmd_showcfg_result *res = parsed_result;
7492         if (!strcmp(res->what, "rxtx"))
7493                 rxtx_config_display();
7494         else if (!strcmp(res->what, "cores"))
7495                 fwd_lcores_config_display();
7496         else if (!strcmp(res->what, "fwd"))
7497                 pkt_fwd_config_display(&cur_fwd_config);
7498         else if (!strcmp(res->what, "rxoffs"))
7499                 show_rx_pkt_offsets();
7500         else if (!strcmp(res->what, "rxpkts"))
7501                 show_rx_pkt_segments();
7502         else if (!strcmp(res->what, "txpkts"))
7503                 show_tx_pkt_segments();
7504         else if (!strcmp(res->what, "txtimes"))
7505                 show_tx_pkt_times();
7506 }
7507
7508 cmdline_parse_token_string_t cmd_showcfg_show =
7509         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7510 cmdline_parse_token_string_t cmd_showcfg_port =
7511         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7512 cmdline_parse_token_string_t cmd_showcfg_what =
7513         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7514                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7515
7516 cmdline_parse_inst_t cmd_showcfg = {
7517         .f = cmd_showcfg_parsed,
7518         .data = NULL,
7519         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7520         .tokens = {
7521                 (void *)&cmd_showcfg_show,
7522                 (void *)&cmd_showcfg_port,
7523                 (void *)&cmd_showcfg_what,
7524                 NULL,
7525         },
7526 };
7527
7528 /* *** SHOW ALL PORT INFO *** */
7529 struct cmd_showportall_result {
7530         cmdline_fixed_string_t show;
7531         cmdline_fixed_string_t port;
7532         cmdline_fixed_string_t what;
7533         cmdline_fixed_string_t all;
7534 };
7535
7536 static void cmd_showportall_parsed(void *parsed_result,
7537                                 __rte_unused struct cmdline *cl,
7538                                 __rte_unused void *data)
7539 {
7540         portid_t i;
7541
7542         struct cmd_showportall_result *res = parsed_result;
7543         if (!strcmp(res->show, "clear")) {
7544                 if (!strcmp(res->what, "stats"))
7545                         RTE_ETH_FOREACH_DEV(i)
7546                                 nic_stats_clear(i);
7547                 else if (!strcmp(res->what, "xstats"))
7548                         RTE_ETH_FOREACH_DEV(i)
7549                                 nic_xstats_clear(i);
7550         } else if (!strcmp(res->what, "info"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         port_infos_display(i);
7553         else if (!strcmp(res->what, "summary")) {
7554                 port_summary_header_display();
7555                 RTE_ETH_FOREACH_DEV(i)
7556                         port_summary_display(i);
7557         }
7558         else if (!strcmp(res->what, "stats"))
7559                 RTE_ETH_FOREACH_DEV(i)
7560                         nic_stats_display(i);
7561         else if (!strcmp(res->what, "xstats"))
7562                 RTE_ETH_FOREACH_DEV(i)
7563                         nic_xstats_display(i);
7564 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7565         else if (!strcmp(res->what, "fdir"))
7566                 RTE_ETH_FOREACH_DEV(i)
7567                         fdir_get_infos(i);
7568 #endif
7569         else if (!strcmp(res->what, "stat_qmap"))
7570                 RTE_ETH_FOREACH_DEV(i)
7571                         nic_stats_mapping_display(i);
7572         else if (!strcmp(res->what, "dcb_tc"))
7573                 RTE_ETH_FOREACH_DEV(i)
7574                         port_dcb_info_display(i);
7575         else if (!strcmp(res->what, "cap"))
7576                 RTE_ETH_FOREACH_DEV(i)
7577                         port_offload_cap_display(i);
7578 }
7579
7580 cmdline_parse_token_string_t cmd_showportall_show =
7581         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7582                                  "show#clear");
7583 cmdline_parse_token_string_t cmd_showportall_port =
7584         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7585 cmdline_parse_token_string_t cmd_showportall_what =
7586         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7587                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7588 cmdline_parse_token_string_t cmd_showportall_all =
7589         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7590 cmdline_parse_inst_t cmd_showportall = {
7591         .f = cmd_showportall_parsed,
7592         .data = NULL,
7593         .help_str = "show|clear port "
7594                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7595         .tokens = {
7596                 (void *)&cmd_showportall_show,
7597                 (void *)&cmd_showportall_port,
7598                 (void *)&cmd_showportall_what,
7599                 (void *)&cmd_showportall_all,
7600                 NULL,
7601         },
7602 };
7603
7604 /* *** SHOW PORT INFO *** */
7605 struct cmd_showport_result {
7606         cmdline_fixed_string_t show;
7607         cmdline_fixed_string_t port;
7608         cmdline_fixed_string_t what;
7609         uint16_t portnum;
7610 };
7611
7612 static void cmd_showport_parsed(void *parsed_result,
7613                                 __rte_unused struct cmdline *cl,
7614                                 __rte_unused void *data)
7615 {
7616         struct cmd_showport_result *res = parsed_result;
7617         if (!strcmp(res->show, "clear")) {
7618                 if (!strcmp(res->what, "stats"))
7619                         nic_stats_clear(res->portnum);
7620                 else if (!strcmp(res->what, "xstats"))
7621                         nic_xstats_clear(res->portnum);
7622         } else if (!strcmp(res->what, "info"))
7623                 port_infos_display(res->portnum);
7624         else if (!strcmp(res->what, "summary")) {
7625                 port_summary_header_display();
7626                 port_summary_display(res->portnum);
7627         }
7628         else if (!strcmp(res->what, "stats"))
7629                 nic_stats_display(res->portnum);
7630         else if (!strcmp(res->what, "xstats"))
7631                 nic_xstats_display(res->portnum);
7632 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7633         else if (!strcmp(res->what, "fdir"))
7634                  fdir_get_infos(res->portnum);
7635 #endif
7636         else if (!strcmp(res->what, "stat_qmap"))
7637                 nic_stats_mapping_display(res->portnum);
7638         else if (!strcmp(res->what, "dcb_tc"))
7639                 port_dcb_info_display(res->portnum);
7640         else if (!strcmp(res->what, "cap"))
7641                 port_offload_cap_display(res->portnum);
7642 }
7643
7644 cmdline_parse_token_string_t cmd_showport_show =
7645         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7646                                  "show#clear");
7647 cmdline_parse_token_string_t cmd_showport_port =
7648         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7649 cmdline_parse_token_string_t cmd_showport_what =
7650         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7651                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7652 cmdline_parse_token_num_t cmd_showport_portnum =
7653         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7654
7655 cmdline_parse_inst_t cmd_showport = {
7656         .f = cmd_showport_parsed,
7657         .data = NULL,
7658         .help_str = "show|clear port "
7659                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7660                 "<port_id>",
7661         .tokens = {
7662                 (void *)&cmd_showport_show,
7663                 (void *)&cmd_showport_port,
7664                 (void *)&cmd_showport_what,
7665                 (void *)&cmd_showport_portnum,
7666                 NULL,
7667         },
7668 };
7669
7670 /* *** SHOW DEVICE INFO *** */
7671 struct cmd_showdevice_result {
7672         cmdline_fixed_string_t show;
7673         cmdline_fixed_string_t device;
7674         cmdline_fixed_string_t what;
7675         cmdline_fixed_string_t identifier;
7676 };
7677
7678 static void cmd_showdevice_parsed(void *parsed_result,
7679                                 __rte_unused struct cmdline *cl,
7680                                 __rte_unused void *data)
7681 {
7682         struct cmd_showdevice_result *res = parsed_result;
7683         if (!strcmp(res->what, "info")) {
7684                 if (!strcmp(res->identifier, "all"))
7685                         device_infos_display(NULL);
7686                 else
7687                         device_infos_display(res->identifier);
7688         }
7689 }
7690
7691 cmdline_parse_token_string_t cmd_showdevice_show =
7692         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7693                                  "show");
7694 cmdline_parse_token_string_t cmd_showdevice_device =
7695         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7696 cmdline_parse_token_string_t cmd_showdevice_what =
7697         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7698                                  "info");
7699 cmdline_parse_token_string_t cmd_showdevice_identifier =
7700         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7701                         identifier, NULL);
7702
7703 cmdline_parse_inst_t cmd_showdevice = {
7704         .f = cmd_showdevice_parsed,
7705         .data = NULL,
7706         .help_str = "show device info <identifier>|all",
7707         .tokens = {
7708                 (void *)&cmd_showdevice_show,
7709                 (void *)&cmd_showdevice_device,
7710                 (void *)&cmd_showdevice_what,
7711                 (void *)&cmd_showdevice_identifier,
7712                 NULL,
7713         },
7714 };
7715
7716 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7717 struct cmd_showeeprom_result {
7718         cmdline_fixed_string_t show;
7719         cmdline_fixed_string_t port;
7720         uint16_t portnum;
7721         cmdline_fixed_string_t type;
7722 };
7723
7724 static void cmd_showeeprom_parsed(void *parsed_result,
7725                 __rte_unused struct cmdline *cl,
7726                 __rte_unused void *data)
7727 {
7728         struct cmd_showeeprom_result *res = parsed_result;
7729
7730         if (!strcmp(res->type, "eeprom"))
7731                 port_eeprom_display(res->portnum);
7732         else if (!strcmp(res->type, "module_eeprom"))
7733                 port_module_eeprom_display(res->portnum);
7734         else
7735                 printf("Unknown argument\n");
7736 }
7737
7738 cmdline_parse_token_string_t cmd_showeeprom_show =
7739         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7740 cmdline_parse_token_string_t cmd_showeeprom_port =
7741         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7742 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7743         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7744 cmdline_parse_token_string_t cmd_showeeprom_type =
7745         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7746
7747 cmdline_parse_inst_t cmd_showeeprom = {
7748         .f = cmd_showeeprom_parsed,
7749         .data = NULL,
7750         .help_str = "show port <port_id> module_eeprom|eeprom",
7751         .tokens = {
7752                 (void *)&cmd_showeeprom_show,
7753                 (void *)&cmd_showeeprom_port,
7754                 (void *)&cmd_showeeprom_portnum,
7755                 (void *)&cmd_showeeprom_type,
7756                 NULL,
7757         },
7758 };
7759
7760 /* *** SHOW QUEUE INFO *** */
7761 struct cmd_showqueue_result {
7762         cmdline_fixed_string_t show;
7763         cmdline_fixed_string_t type;
7764         cmdline_fixed_string_t what;
7765         uint16_t portnum;
7766         uint16_t queuenum;
7767 };
7768
7769 static void
7770 cmd_showqueue_parsed(void *parsed_result,
7771         __rte_unused struct cmdline *cl,
7772         __rte_unused void *data)
7773 {
7774         struct cmd_showqueue_result *res = parsed_result;
7775
7776         if (!strcmp(res->type, "rxq"))
7777                 rx_queue_infos_display(res->portnum, res->queuenum);
7778         else if (!strcmp(res->type, "txq"))
7779                 tx_queue_infos_display(res->portnum, res->queuenum);
7780 }
7781
7782 cmdline_parse_token_string_t cmd_showqueue_show =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7784 cmdline_parse_token_string_t cmd_showqueue_type =
7785         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7786 cmdline_parse_token_string_t cmd_showqueue_what =
7787         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7788 cmdline_parse_token_num_t cmd_showqueue_portnum =
7789         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7790 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7791         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7792
7793 cmdline_parse_inst_t cmd_showqueue = {
7794         .f = cmd_showqueue_parsed,
7795         .data = NULL,
7796         .help_str = "show rxq|txq info <port_id> <queue_id>",
7797         .tokens = {
7798                 (void *)&cmd_showqueue_show,
7799                 (void *)&cmd_showqueue_type,
7800                 (void *)&cmd_showqueue_what,
7801                 (void *)&cmd_showqueue_portnum,
7802                 (void *)&cmd_showqueue_queuenum,
7803                 NULL,
7804         },
7805 };
7806
7807 /* show/clear fwd engine statistics */
7808 struct fwd_result {
7809         cmdline_fixed_string_t action;
7810         cmdline_fixed_string_t fwd;
7811         cmdline_fixed_string_t stats;
7812         cmdline_fixed_string_t all;
7813 };
7814
7815 cmdline_parse_token_string_t cmd_fwd_action =
7816         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7817 cmdline_parse_token_string_t cmd_fwd_fwd =
7818         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7819 cmdline_parse_token_string_t cmd_fwd_stats =
7820         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7821 cmdline_parse_token_string_t cmd_fwd_all =
7822         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7823
7824 static void
7825 cmd_showfwdall_parsed(void *parsed_result,
7826                       __rte_unused struct cmdline *cl,
7827                       __rte_unused void *data)
7828 {
7829         struct fwd_result *res = parsed_result;
7830
7831         if (!strcmp(res->action, "show"))
7832                 fwd_stats_display();
7833         else
7834                 fwd_stats_reset();
7835 }
7836
7837 static cmdline_parse_inst_t cmd_showfwdall = {
7838         .f = cmd_showfwdall_parsed,
7839         .data = NULL,
7840         .help_str = "show|clear fwd stats all",
7841         .tokens = {
7842                 (void *)&cmd_fwd_action,
7843                 (void *)&cmd_fwd_fwd,
7844                 (void *)&cmd_fwd_stats,
7845                 (void *)&cmd_fwd_all,
7846                 NULL,
7847         },
7848 };
7849
7850 /* *** READ PORT REGISTER *** */
7851 struct cmd_read_reg_result {
7852         cmdline_fixed_string_t read;
7853         cmdline_fixed_string_t reg;
7854         portid_t port_id;
7855         uint32_t reg_off;
7856 };
7857
7858 static void
7859 cmd_read_reg_parsed(void *parsed_result,
7860                     __rte_unused struct cmdline *cl,
7861                     __rte_unused void *data)
7862 {
7863         struct cmd_read_reg_result *res = parsed_result;
7864         port_reg_display(res->port_id, res->reg_off);
7865 }
7866
7867 cmdline_parse_token_string_t cmd_read_reg_read =
7868         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7869 cmdline_parse_token_string_t cmd_read_reg_reg =
7870         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7871 cmdline_parse_token_num_t cmd_read_reg_port_id =
7872         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7873 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7874         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7875
7876 cmdline_parse_inst_t cmd_read_reg = {
7877         .f = cmd_read_reg_parsed,
7878         .data = NULL,
7879         .help_str = "read reg <port_id> <reg_off>",
7880         .tokens = {
7881                 (void *)&cmd_read_reg_read,
7882                 (void *)&cmd_read_reg_reg,
7883                 (void *)&cmd_read_reg_port_id,
7884                 (void *)&cmd_read_reg_reg_off,
7885                 NULL,
7886         },
7887 };
7888
7889 /* *** READ PORT REGISTER BIT FIELD *** */
7890 struct cmd_read_reg_bit_field_result {
7891         cmdline_fixed_string_t read;
7892         cmdline_fixed_string_t regfield;
7893         portid_t port_id;
7894         uint32_t reg_off;
7895         uint8_t bit1_pos;
7896         uint8_t bit2_pos;
7897 };
7898
7899 static void
7900 cmd_read_reg_bit_field_parsed(void *parsed_result,
7901                               __rte_unused struct cmdline *cl,
7902                               __rte_unused void *data)
7903 {
7904         struct cmd_read_reg_bit_field_result *res = parsed_result;
7905         port_reg_bit_field_display(res->port_id, res->reg_off,
7906                                    res->bit1_pos, res->bit2_pos);
7907 }
7908
7909 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7910         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7911                                  "read");
7912 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7913         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7914                                  regfield, "regfield");
7915 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7916         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7917                               UINT16);
7918 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7919         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7920                               UINT32);
7921 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7922         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7923                               UINT8);
7924 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7925         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7926                               UINT8);
7927
7928 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7929         .f = cmd_read_reg_bit_field_parsed,
7930         .data = NULL,
7931         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7932         "Read register bit field between bit_x and bit_y included",
7933         .tokens = {
7934                 (void *)&cmd_read_reg_bit_field_read,
7935                 (void *)&cmd_read_reg_bit_field_regfield,
7936                 (void *)&cmd_read_reg_bit_field_port_id,
7937                 (void *)&cmd_read_reg_bit_field_reg_off,
7938                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7939                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7940                 NULL,
7941         },
7942 };
7943
7944 /* *** READ PORT REGISTER BIT *** */
7945 struct cmd_read_reg_bit_result {
7946         cmdline_fixed_string_t read;
7947         cmdline_fixed_string_t regbit;
7948         portid_t port_id;
7949         uint32_t reg_off;
7950         uint8_t bit_pos;
7951 };
7952
7953 static void
7954 cmd_read_reg_bit_parsed(void *parsed_result,
7955                         __rte_unused struct cmdline *cl,
7956                         __rte_unused void *data)
7957 {
7958         struct cmd_read_reg_bit_result *res = parsed_result;
7959         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7960 }
7961
7962 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7963         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7964 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7965         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7966                                  regbit, "regbit");
7967 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7968         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7969 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7970         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7971 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7972         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7973
7974 cmdline_parse_inst_t cmd_read_reg_bit = {
7975         .f = cmd_read_reg_bit_parsed,
7976         .data = NULL,
7977         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7978         .tokens = {
7979                 (void *)&cmd_read_reg_bit_read,
7980                 (void *)&cmd_read_reg_bit_regbit,
7981                 (void *)&cmd_read_reg_bit_port_id,
7982                 (void *)&cmd_read_reg_bit_reg_off,
7983                 (void *)&cmd_read_reg_bit_bit_pos,
7984                 NULL,
7985         },
7986 };
7987
7988 /* *** WRITE PORT REGISTER *** */
7989 struct cmd_write_reg_result {
7990         cmdline_fixed_string_t write;
7991         cmdline_fixed_string_t reg;
7992         portid_t port_id;
7993         uint32_t reg_off;
7994         uint32_t value;
7995 };
7996
7997 static void
7998 cmd_write_reg_parsed(void *parsed_result,
7999                      __rte_unused struct cmdline *cl,
8000                      __rte_unused void *data)
8001 {
8002         struct cmd_write_reg_result *res = parsed_result;
8003         port_reg_set(res->port_id, res->reg_off, res->value);
8004 }
8005
8006 cmdline_parse_token_string_t cmd_write_reg_write =
8007         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8008 cmdline_parse_token_string_t cmd_write_reg_reg =
8009         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8010 cmdline_parse_token_num_t cmd_write_reg_port_id =
8011         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8012 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8013         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8014 cmdline_parse_token_num_t cmd_write_reg_value =
8015         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8016
8017 cmdline_parse_inst_t cmd_write_reg = {
8018         .f = cmd_write_reg_parsed,
8019         .data = NULL,
8020         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8021         .tokens = {
8022                 (void *)&cmd_write_reg_write,
8023                 (void *)&cmd_write_reg_reg,
8024                 (void *)&cmd_write_reg_port_id,
8025                 (void *)&cmd_write_reg_reg_off,
8026                 (void *)&cmd_write_reg_value,
8027                 NULL,
8028         },
8029 };
8030
8031 /* *** WRITE PORT REGISTER BIT FIELD *** */
8032 struct cmd_write_reg_bit_field_result {
8033         cmdline_fixed_string_t write;
8034         cmdline_fixed_string_t regfield;
8035         portid_t port_id;
8036         uint32_t reg_off;
8037         uint8_t bit1_pos;
8038         uint8_t bit2_pos;
8039         uint32_t value;
8040 };
8041
8042 static void
8043 cmd_write_reg_bit_field_parsed(void *parsed_result,
8044                                __rte_unused struct cmdline *cl,
8045                                __rte_unused void *data)
8046 {
8047         struct cmd_write_reg_bit_field_result *res = parsed_result;
8048         port_reg_bit_field_set(res->port_id, res->reg_off,
8049                           res->bit1_pos, res->bit2_pos, res->value);
8050 }
8051
8052 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8053         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8054                                  "write");
8055 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8056         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8057                                  regfield, "regfield");
8058 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8059         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8060                               UINT16);
8061 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8062         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8063                               UINT32);
8064 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8065         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8066                               UINT8);
8067 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8068         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8069                               UINT8);
8070 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8071         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8072                               UINT32);
8073
8074 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8075         .f = cmd_write_reg_bit_field_parsed,
8076         .data = NULL,
8077         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8078                 "<reg_value>: "
8079                 "Set register bit field between bit_x and bit_y included",
8080         .tokens = {
8081                 (void *)&cmd_write_reg_bit_field_write,
8082                 (void *)&cmd_write_reg_bit_field_regfield,
8083                 (void *)&cmd_write_reg_bit_field_port_id,
8084                 (void *)&cmd_write_reg_bit_field_reg_off,
8085                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8086                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8087                 (void *)&cmd_write_reg_bit_field_value,
8088                 NULL,
8089         },
8090 };
8091
8092 /* *** WRITE PORT REGISTER BIT *** */
8093 struct cmd_write_reg_bit_result {
8094         cmdline_fixed_string_t write;
8095         cmdline_fixed_string_t regbit;
8096         portid_t port_id;
8097         uint32_t reg_off;
8098         uint8_t bit_pos;
8099         uint8_t value;
8100 };
8101
8102 static void
8103 cmd_write_reg_bit_parsed(void *parsed_result,
8104                          __rte_unused struct cmdline *cl,
8105                          __rte_unused void *data)
8106 {
8107         struct cmd_write_reg_bit_result *res = parsed_result;
8108         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8109 }
8110
8111 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8112         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8113                                  "write");
8114 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8115         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8116                                  regbit, "regbit");
8117 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8118         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8119 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8120         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8121 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8122         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8123 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8124         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8125
8126 cmdline_parse_inst_t cmd_write_reg_bit = {
8127         .f = cmd_write_reg_bit_parsed,
8128         .data = NULL,
8129         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8130                 "0 <= bit_x <= 31",
8131         .tokens = {
8132                 (void *)&cmd_write_reg_bit_write,
8133                 (void *)&cmd_write_reg_bit_regbit,
8134                 (void *)&cmd_write_reg_bit_port_id,
8135                 (void *)&cmd_write_reg_bit_reg_off,
8136                 (void *)&cmd_write_reg_bit_bit_pos,
8137                 (void *)&cmd_write_reg_bit_value,
8138                 NULL,
8139         },
8140 };
8141
8142 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8143 struct cmd_read_rxd_txd_result {
8144         cmdline_fixed_string_t read;
8145         cmdline_fixed_string_t rxd_txd;
8146         portid_t port_id;
8147         uint16_t queue_id;
8148         uint16_t desc_id;
8149 };
8150
8151 static void
8152 cmd_read_rxd_txd_parsed(void *parsed_result,
8153                         __rte_unused struct cmdline *cl,
8154                         __rte_unused void *data)
8155 {
8156         struct cmd_read_rxd_txd_result *res = parsed_result;
8157
8158         if (!strcmp(res->rxd_txd, "rxd"))
8159                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8160         else if (!strcmp(res->rxd_txd, "txd"))
8161                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8162 }
8163
8164 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8165         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8166 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8167         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8168                                  "rxd#txd");
8169 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8170         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8171 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8172         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8173 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8174         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8175
8176 cmdline_parse_inst_t cmd_read_rxd_txd = {
8177         .f = cmd_read_rxd_txd_parsed,
8178         .data = NULL,
8179         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8180         .tokens = {
8181                 (void *)&cmd_read_rxd_txd_read,
8182                 (void *)&cmd_read_rxd_txd_rxd_txd,
8183                 (void *)&cmd_read_rxd_txd_port_id,
8184                 (void *)&cmd_read_rxd_txd_queue_id,
8185                 (void *)&cmd_read_rxd_txd_desc_id,
8186                 NULL,
8187         },
8188 };
8189
8190 /* *** QUIT *** */
8191 struct cmd_quit_result {
8192         cmdline_fixed_string_t quit;
8193 };
8194
8195 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8196                             struct cmdline *cl,
8197                             __rte_unused void *data)
8198 {
8199         cmdline_quit(cl);
8200 }
8201
8202 cmdline_parse_token_string_t cmd_quit_quit =
8203         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8204
8205 cmdline_parse_inst_t cmd_quit = {
8206         .f = cmd_quit_parsed,
8207         .data = NULL,
8208         .help_str = "quit: Exit application",
8209         .tokens = {
8210                 (void *)&cmd_quit_quit,
8211                 NULL,
8212         },
8213 };
8214
8215 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8216 struct cmd_mac_addr_result {
8217         cmdline_fixed_string_t mac_addr_cmd;
8218         cmdline_fixed_string_t what;
8219         uint16_t port_num;
8220         struct rte_ether_addr address;
8221 };
8222
8223 static void cmd_mac_addr_parsed(void *parsed_result,
8224                 __rte_unused struct cmdline *cl,
8225                 __rte_unused void *data)
8226 {
8227         struct cmd_mac_addr_result *res = parsed_result;
8228         int ret;
8229
8230         if (strcmp(res->what, "add") == 0)
8231                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8232         else if (strcmp(res->what, "set") == 0)
8233                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8234                                                        &res->address);
8235         else
8236                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8237
8238         /* check the return value and print it if is < 0 */
8239         if(ret < 0)
8240                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8241
8242 }
8243
8244 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8245         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8246                                 "mac_addr");
8247 cmdline_parse_token_string_t cmd_mac_addr_what =
8248         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8249                                 "add#remove#set");
8250 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8251                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8252                                         UINT16);
8253 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8254                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8255
8256 cmdline_parse_inst_t cmd_mac_addr = {
8257         .f = cmd_mac_addr_parsed,
8258         .data = (void *)0,
8259         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8260                         "Add/Remove/Set MAC address on port_id",
8261         .tokens = {
8262                 (void *)&cmd_mac_addr_cmd,
8263                 (void *)&cmd_mac_addr_what,
8264                 (void *)&cmd_mac_addr_portnum,
8265                 (void *)&cmd_mac_addr_addr,
8266                 NULL,
8267         },
8268 };
8269
8270 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8271 struct cmd_eth_peer_result {
8272         cmdline_fixed_string_t set;
8273         cmdline_fixed_string_t eth_peer;
8274         portid_t port_id;
8275         cmdline_fixed_string_t peer_addr;
8276 };
8277
8278 static void cmd_set_eth_peer_parsed(void *parsed_result,
8279                         __rte_unused struct cmdline *cl,
8280                         __rte_unused void *data)
8281 {
8282                 struct cmd_eth_peer_result *res = parsed_result;
8283
8284                 if (test_done == 0) {
8285                         printf("Please stop forwarding first\n");
8286                         return;
8287                 }
8288                 if (!strcmp(res->eth_peer, "eth-peer")) {
8289                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8290                         fwd_config_setup();
8291                 }
8292 }
8293 cmdline_parse_token_string_t cmd_eth_peer_set =
8294         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8295 cmdline_parse_token_string_t cmd_eth_peer =
8296         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8297 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8298         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8299 cmdline_parse_token_string_t cmd_eth_peer_addr =
8300         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8301
8302 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8303         .f = cmd_set_eth_peer_parsed,
8304         .data = NULL,
8305         .help_str = "set eth-peer <port_id> <peer_mac>",
8306         .tokens = {
8307                 (void *)&cmd_eth_peer_set,
8308                 (void *)&cmd_eth_peer,
8309                 (void *)&cmd_eth_peer_port_id,
8310                 (void *)&cmd_eth_peer_addr,
8311                 NULL,
8312         },
8313 };
8314
8315 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8316 struct cmd_set_qmap_result {
8317         cmdline_fixed_string_t set;
8318         cmdline_fixed_string_t qmap;
8319         cmdline_fixed_string_t what;
8320         portid_t port_id;
8321         uint16_t queue_id;
8322         uint8_t map_value;
8323 };
8324
8325 static void
8326 cmd_set_qmap_parsed(void *parsed_result,
8327                        __rte_unused struct cmdline *cl,
8328                        __rte_unused void *data)
8329 {
8330         struct cmd_set_qmap_result *res = parsed_result;
8331         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8332
8333         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8334 }
8335
8336 cmdline_parse_token_string_t cmd_setqmap_set =
8337         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8338                                  set, "set");
8339 cmdline_parse_token_string_t cmd_setqmap_qmap =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8341                                  qmap, "stat_qmap");
8342 cmdline_parse_token_string_t cmd_setqmap_what =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8344                                  what, "tx#rx");
8345 cmdline_parse_token_num_t cmd_setqmap_portid =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8347                               port_id, UINT16);
8348 cmdline_parse_token_num_t cmd_setqmap_queueid =
8349         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8350                               queue_id, UINT16);
8351 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8352         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8353                               map_value, UINT8);
8354
8355 cmdline_parse_inst_t cmd_set_qmap = {
8356         .f = cmd_set_qmap_parsed,
8357         .data = NULL,
8358         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8359                 "Set statistics mapping value on tx|rx queue_id of port_id",
8360         .tokens = {
8361                 (void *)&cmd_setqmap_set,
8362                 (void *)&cmd_setqmap_qmap,
8363                 (void *)&cmd_setqmap_what,
8364                 (void *)&cmd_setqmap_portid,
8365                 (void *)&cmd_setqmap_queueid,
8366                 (void *)&cmd_setqmap_mapvalue,
8367                 NULL,
8368         },
8369 };
8370
8371 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8372 struct cmd_set_xstats_hide_zero_result {
8373         cmdline_fixed_string_t keyword;
8374         cmdline_fixed_string_t name;
8375         cmdline_fixed_string_t on_off;
8376 };
8377
8378 static void
8379 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8380                         __rte_unused struct cmdline *cl,
8381                         __rte_unused void *data)
8382 {
8383         struct cmd_set_xstats_hide_zero_result *res;
8384         uint16_t on_off = 0;
8385
8386         res = parsed_result;
8387         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8388         set_xstats_hide_zero(on_off);
8389 }
8390
8391 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8392         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8393                                  keyword, "set");
8394 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8395         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8396                                  name, "xstats-hide-zero");
8397 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8398         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8399                                  on_off, "on#off");
8400
8401 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8402         .f = cmd_set_xstats_hide_zero_parsed,
8403         .data = NULL,
8404         .help_str = "set xstats-hide-zero on|off",
8405         .tokens = {
8406                 (void *)&cmd_set_xstats_hide_zero_keyword,
8407                 (void *)&cmd_set_xstats_hide_zero_name,
8408                 (void *)&cmd_set_xstats_hide_zero_on_off,
8409                 NULL,
8410         },
8411 };
8412
8413 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8414 struct cmd_set_record_core_cycles_result {
8415         cmdline_fixed_string_t keyword;
8416         cmdline_fixed_string_t name;
8417         cmdline_fixed_string_t on_off;
8418 };
8419
8420 static void
8421 cmd_set_record_core_cycles_parsed(void *parsed_result,
8422                         __rte_unused struct cmdline *cl,
8423                         __rte_unused void *data)
8424 {
8425         struct cmd_set_record_core_cycles_result *res;
8426         uint16_t on_off = 0;
8427
8428         res = parsed_result;
8429         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8430         set_record_core_cycles(on_off);
8431 }
8432
8433 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8434         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8435                                  keyword, "set");
8436 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8437         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8438                                  name, "record-core-cycles");
8439 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8440         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8441                                  on_off, "on#off");
8442
8443 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8444         .f = cmd_set_record_core_cycles_parsed,
8445         .data = NULL,
8446         .help_str = "set record-core-cycles on|off",
8447         .tokens = {
8448                 (void *)&cmd_set_record_core_cycles_keyword,
8449                 (void *)&cmd_set_record_core_cycles_name,
8450                 (void *)&cmd_set_record_core_cycles_on_off,
8451                 NULL,
8452         },
8453 };
8454
8455 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8456 struct cmd_set_record_burst_stats_result {
8457         cmdline_fixed_string_t keyword;
8458         cmdline_fixed_string_t name;
8459         cmdline_fixed_string_t on_off;
8460 };
8461
8462 static void
8463 cmd_set_record_burst_stats_parsed(void *parsed_result,
8464                         __rte_unused struct cmdline *cl,
8465                         __rte_unused void *data)
8466 {
8467         struct cmd_set_record_burst_stats_result *res;
8468         uint16_t on_off = 0;
8469
8470         res = parsed_result;
8471         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8472         set_record_burst_stats(on_off);
8473 }
8474
8475 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8476         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8477                                  keyword, "set");
8478 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8480                                  name, "record-burst-stats");
8481 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8483                                  on_off, "on#off");
8484
8485 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8486         .f = cmd_set_record_burst_stats_parsed,
8487         .data = NULL,
8488         .help_str = "set record-burst-stats on|off",
8489         .tokens = {
8490                 (void *)&cmd_set_record_burst_stats_keyword,
8491                 (void *)&cmd_set_record_burst_stats_name,
8492                 (void *)&cmd_set_record_burst_stats_on_off,
8493                 NULL,
8494         },
8495 };
8496
8497 /* *** CONFIGURE UNICAST HASH TABLE *** */
8498 struct cmd_set_uc_hash_table {
8499         cmdline_fixed_string_t set;
8500         cmdline_fixed_string_t port;
8501         portid_t port_id;
8502         cmdline_fixed_string_t what;
8503         struct rte_ether_addr address;
8504         cmdline_fixed_string_t mode;
8505 };
8506
8507 static void
8508 cmd_set_uc_hash_parsed(void *parsed_result,
8509                        __rte_unused struct cmdline *cl,
8510                        __rte_unused void *data)
8511 {
8512         int ret=0;
8513         struct cmd_set_uc_hash_table *res = parsed_result;
8514
8515         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8516
8517         if (strcmp(res->what, "uta") == 0)
8518                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8519                                                 &res->address,(uint8_t)is_on);
8520         if (ret < 0)
8521                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8522
8523 }
8524
8525 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8527                                  set, "set");
8528 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8529         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8530                                  port, "port");
8531 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8532         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8533                               port_id, UINT16);
8534 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8535         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8536                                  what, "uta");
8537 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8538         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8539                                 address);
8540 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8541         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8542                                  mode, "on#off");
8543
8544 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8545         .f = cmd_set_uc_hash_parsed,
8546         .data = NULL,
8547         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8548         .tokens = {
8549                 (void *)&cmd_set_uc_hash_set,
8550                 (void *)&cmd_set_uc_hash_port,
8551                 (void *)&cmd_set_uc_hash_portid,
8552                 (void *)&cmd_set_uc_hash_what,
8553                 (void *)&cmd_set_uc_hash_mac,
8554                 (void *)&cmd_set_uc_hash_mode,
8555                 NULL,
8556         },
8557 };
8558
8559 struct cmd_set_uc_all_hash_table {
8560         cmdline_fixed_string_t set;
8561         cmdline_fixed_string_t port;
8562         portid_t port_id;
8563         cmdline_fixed_string_t what;
8564         cmdline_fixed_string_t value;
8565         cmdline_fixed_string_t mode;
8566 };
8567
8568 static void
8569 cmd_set_uc_all_hash_parsed(void *parsed_result,
8570                        __rte_unused struct cmdline *cl,
8571                        __rte_unused void *data)
8572 {
8573         int ret=0;
8574         struct cmd_set_uc_all_hash_table *res = parsed_result;
8575
8576         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8577
8578         if ((strcmp(res->what, "uta") == 0) &&
8579                 (strcmp(res->value, "all") == 0))
8580                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8581         if (ret < 0)
8582                 printf("bad unicast hash table parameter,"
8583                         "return code = %d \n", ret);
8584 }
8585
8586 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8587         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8588                                  set, "set");
8589 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8590         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8591                                  port, "port");
8592 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8593         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8594                               port_id, UINT16);
8595 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8596         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8597                                  what, "uta");
8598 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8599         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8600                                 value,"all");
8601 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8602         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8603                                  mode, "on#off");
8604
8605 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8606         .f = cmd_set_uc_all_hash_parsed,
8607         .data = NULL,
8608         .help_str = "set port <port_id> uta all on|off",
8609         .tokens = {
8610                 (void *)&cmd_set_uc_all_hash_set,
8611                 (void *)&cmd_set_uc_all_hash_port,
8612                 (void *)&cmd_set_uc_all_hash_portid,
8613                 (void *)&cmd_set_uc_all_hash_what,
8614                 (void *)&cmd_set_uc_all_hash_value,
8615                 (void *)&cmd_set_uc_all_hash_mode,
8616                 NULL,
8617         },
8618 };
8619
8620 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8621 struct cmd_set_vf_traffic {
8622         cmdline_fixed_string_t set;
8623         cmdline_fixed_string_t port;
8624         portid_t port_id;
8625         cmdline_fixed_string_t vf;
8626         uint8_t vf_id;
8627         cmdline_fixed_string_t what;
8628         cmdline_fixed_string_t mode;
8629 };
8630
8631 static void
8632 cmd_set_vf_traffic_parsed(void *parsed_result,
8633                        __rte_unused struct cmdline *cl,
8634                        __rte_unused void *data)
8635 {
8636         struct cmd_set_vf_traffic *res = parsed_result;
8637         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8638         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8639
8640         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8641 }
8642
8643 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8644         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8645                                  set, "set");
8646 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8647         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8648                                  port, "port");
8649 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8650         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8651                               port_id, UINT16);
8652 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8653         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8654                                  vf, "vf");
8655 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8656         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8657                               vf_id, UINT8);
8658 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8659         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8660                                  what, "tx#rx");
8661 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8662         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8663                                  mode, "on#off");
8664
8665 cmdline_parse_inst_t cmd_set_vf_traffic = {
8666         .f = cmd_set_vf_traffic_parsed,
8667         .data = NULL,
8668         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8669         .tokens = {
8670                 (void *)&cmd_setvf_traffic_set,
8671                 (void *)&cmd_setvf_traffic_port,
8672                 (void *)&cmd_setvf_traffic_portid,
8673                 (void *)&cmd_setvf_traffic_vf,
8674                 (void *)&cmd_setvf_traffic_vfid,
8675                 (void *)&cmd_setvf_traffic_what,
8676                 (void *)&cmd_setvf_traffic_mode,
8677                 NULL,
8678         },
8679 };
8680
8681 /* *** CONFIGURE VF RECEIVE MODE *** */
8682 struct cmd_set_vf_rxmode {
8683         cmdline_fixed_string_t set;
8684         cmdline_fixed_string_t port;
8685         portid_t port_id;
8686         cmdline_fixed_string_t vf;
8687         uint8_t vf_id;
8688         cmdline_fixed_string_t what;
8689         cmdline_fixed_string_t mode;
8690         cmdline_fixed_string_t on;
8691 };
8692
8693 static void
8694 cmd_set_vf_rxmode_parsed(void *parsed_result,
8695                        __rte_unused struct cmdline *cl,
8696                        __rte_unused void *data)
8697 {
8698         int ret = -ENOTSUP;
8699         uint16_t vf_rxmode = 0;
8700         struct cmd_set_vf_rxmode *res = parsed_result;
8701
8702         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8703         if (!strcmp(res->what,"rxmode")) {
8704                 if (!strcmp(res->mode, "AUPE"))
8705                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8706                 else if (!strcmp(res->mode, "ROPE"))
8707                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8708                 else if (!strcmp(res->mode, "BAM"))
8709                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8710                 else if (!strncmp(res->mode, "MPE",3))
8711                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8712         }
8713
8714         RTE_SET_USED(is_on);
8715
8716 #ifdef RTE_NET_IXGBE
8717         if (ret == -ENOTSUP)
8718                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8719                                                   vf_rxmode, (uint8_t)is_on);
8720 #endif
8721 #ifdef RTE_NET_BNXT
8722         if (ret == -ENOTSUP)
8723                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8724                                                  vf_rxmode, (uint8_t)is_on);
8725 #endif
8726         if (ret < 0)
8727                 printf("bad VF receive mode parameter, return code = %d \n",
8728                 ret);
8729 }
8730
8731 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8732         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8733                                  set, "set");
8734 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8735         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8736                                  port, "port");
8737 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8738         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8739                               port_id, UINT16);
8740 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8741         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8742                                  vf, "vf");
8743 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8744         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8745                               vf_id, UINT8);
8746 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8747         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8748                                  what, "rxmode");
8749 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8750         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8751                                  mode, "AUPE#ROPE#BAM#MPE");
8752 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8753         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8754                                  on, "on#off");
8755
8756 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8757         .f = cmd_set_vf_rxmode_parsed,
8758         .data = NULL,
8759         .help_str = "set port <port_id> vf <vf_id> rxmode "
8760                 "AUPE|ROPE|BAM|MPE on|off",
8761         .tokens = {
8762                 (void *)&cmd_set_vf_rxmode_set,
8763                 (void *)&cmd_set_vf_rxmode_port,
8764                 (void *)&cmd_set_vf_rxmode_portid,
8765                 (void *)&cmd_set_vf_rxmode_vf,
8766                 (void *)&cmd_set_vf_rxmode_vfid,
8767                 (void *)&cmd_set_vf_rxmode_what,
8768                 (void *)&cmd_set_vf_rxmode_mode,
8769                 (void *)&cmd_set_vf_rxmode_on,
8770                 NULL,
8771         },
8772 };
8773
8774 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8775 struct cmd_vf_mac_addr_result {
8776         cmdline_fixed_string_t mac_addr_cmd;
8777         cmdline_fixed_string_t what;
8778         cmdline_fixed_string_t port;
8779         uint16_t port_num;
8780         cmdline_fixed_string_t vf;
8781         uint8_t vf_num;
8782         struct rte_ether_addr address;
8783 };
8784
8785 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8786                 __rte_unused struct cmdline *cl,
8787                 __rte_unused void *data)
8788 {
8789         struct cmd_vf_mac_addr_result *res = parsed_result;
8790         int ret = -ENOTSUP;
8791
8792         if (strcmp(res->what, "add") != 0)
8793                 return;
8794
8795 #ifdef RTE_NET_I40E
8796         if (ret == -ENOTSUP)
8797                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8798                                                    &res->address);
8799 #endif
8800 #ifdef RTE_NET_BNXT
8801         if (ret == -ENOTSUP)
8802                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8803                                                 res->vf_num);
8804 #endif
8805
8806         if(ret < 0)
8807                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8808
8809 }
8810
8811 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8812         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8813                                 mac_addr_cmd,"mac_addr");
8814 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8815         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8816                                 what,"add");
8817 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8818         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8819                                 port,"port");
8820 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8821         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8822                                 port_num, UINT16);
8823 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8824         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8825                                 vf,"vf");
8826 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8827         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8828                                 vf_num, UINT8);
8829 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8830         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8831                                 address);
8832
8833 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8834         .f = cmd_vf_mac_addr_parsed,
8835         .data = (void *)0,
8836         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8837                 "Add MAC address filtering for a VF on port_id",
8838         .tokens = {
8839                 (void *)&cmd_vf_mac_addr_cmd,
8840                 (void *)&cmd_vf_mac_addr_what,
8841                 (void *)&cmd_vf_mac_addr_port,
8842                 (void *)&cmd_vf_mac_addr_portnum,
8843                 (void *)&cmd_vf_mac_addr_vf,
8844                 (void *)&cmd_vf_mac_addr_vfnum,
8845                 (void *)&cmd_vf_mac_addr_addr,
8846                 NULL,
8847         },
8848 };
8849
8850 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8851 struct cmd_vf_rx_vlan_filter {
8852         cmdline_fixed_string_t rx_vlan;
8853         cmdline_fixed_string_t what;
8854         uint16_t vlan_id;
8855         cmdline_fixed_string_t port;
8856         portid_t port_id;
8857         cmdline_fixed_string_t vf;
8858         uint64_t vf_mask;
8859 };
8860
8861 static void
8862 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8863                           __rte_unused struct cmdline *cl,
8864                           __rte_unused void *data)
8865 {
8866         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8867         int ret = -ENOTSUP;
8868
8869         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8870
8871 #ifdef RTE_NET_IXGBE
8872         if (ret == -ENOTSUP)
8873                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8874                                 res->vlan_id, res->vf_mask, is_add);
8875 #endif
8876 #ifdef RTE_NET_I40E
8877         if (ret == -ENOTSUP)
8878                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8879                                 res->vlan_id, res->vf_mask, is_add);
8880 #endif
8881 #ifdef RTE_NET_BNXT
8882         if (ret == -ENOTSUP)
8883                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8884                                 res->vlan_id, res->vf_mask, is_add);
8885 #endif
8886
8887         switch (ret) {
8888         case 0:
8889                 break;
8890         case -EINVAL:
8891                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8892                                 res->vlan_id, res->vf_mask);
8893                 break;
8894         case -ENODEV:
8895                 printf("invalid port_id %d\n", res->port_id);
8896                 break;
8897         case -ENOTSUP:
8898                 printf("function not implemented or supported\n");
8899                 break;
8900         default:
8901                 printf("programming error: (%s)\n", strerror(-ret));
8902         }
8903 }
8904
8905 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8906         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8907                                  rx_vlan, "rx_vlan");
8908 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8909         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8910                                  what, "add#rm");
8911 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8912         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8913                               vlan_id, UINT16);
8914 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8915         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8916                                  port, "port");
8917 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8918         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8919                               port_id, UINT16);
8920 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8921         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8922                                  vf, "vf");
8923 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8924         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8925                               vf_mask, UINT64);
8926
8927 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8928         .f = cmd_vf_rx_vlan_filter_parsed,
8929         .data = NULL,
8930         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8931                 "(vf_mask = hexadecimal VF mask)",
8932         .tokens = {
8933                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8934                 (void *)&cmd_vf_rx_vlan_filter_what,
8935                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8936                 (void *)&cmd_vf_rx_vlan_filter_port,
8937                 (void *)&cmd_vf_rx_vlan_filter_portid,
8938                 (void *)&cmd_vf_rx_vlan_filter_vf,
8939                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8940                 NULL,
8941         },
8942 };
8943
8944 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8945 struct cmd_queue_rate_limit_result {
8946         cmdline_fixed_string_t set;
8947         cmdline_fixed_string_t port;
8948         uint16_t port_num;
8949         cmdline_fixed_string_t queue;
8950         uint8_t queue_num;
8951         cmdline_fixed_string_t rate;
8952         uint16_t rate_num;
8953 };
8954
8955 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8956                 __rte_unused struct cmdline *cl,
8957                 __rte_unused void *data)
8958 {
8959         struct cmd_queue_rate_limit_result *res = parsed_result;
8960         int ret = 0;
8961
8962         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8963                 && (strcmp(res->queue, "queue") == 0)
8964                 && (strcmp(res->rate, "rate") == 0))
8965                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8966                                         res->rate_num);
8967         if (ret < 0)
8968                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8969
8970 }
8971
8972 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8973         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8974                                 set, "set");
8975 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8976         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8977                                 port, "port");
8978 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8979         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8980                                 port_num, UINT16);
8981 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8982         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8983                                 queue, "queue");
8984 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8985         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8986                                 queue_num, UINT8);
8987 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8988         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8989                                 rate, "rate");
8990 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8991         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8992                                 rate_num, UINT16);
8993
8994 cmdline_parse_inst_t cmd_queue_rate_limit = {
8995         .f = cmd_queue_rate_limit_parsed,
8996         .data = (void *)0,
8997         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8998                 "Set rate limit for a queue on port_id",
8999         .tokens = {
9000                 (void *)&cmd_queue_rate_limit_set,
9001                 (void *)&cmd_queue_rate_limit_port,
9002                 (void *)&cmd_queue_rate_limit_portnum,
9003                 (void *)&cmd_queue_rate_limit_queue,
9004                 (void *)&cmd_queue_rate_limit_queuenum,
9005                 (void *)&cmd_queue_rate_limit_rate,
9006                 (void *)&cmd_queue_rate_limit_ratenum,
9007                 NULL,
9008         },
9009 };
9010
9011 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9012 struct cmd_vf_rate_limit_result {
9013         cmdline_fixed_string_t set;
9014         cmdline_fixed_string_t port;
9015         uint16_t port_num;
9016         cmdline_fixed_string_t vf;
9017         uint8_t vf_num;
9018         cmdline_fixed_string_t rate;
9019         uint16_t rate_num;
9020         cmdline_fixed_string_t q_msk;
9021         uint64_t q_msk_val;
9022 };
9023
9024 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9025                 __rte_unused struct cmdline *cl,
9026                 __rte_unused void *data)
9027 {
9028         struct cmd_vf_rate_limit_result *res = parsed_result;
9029         int ret = 0;
9030
9031         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9032                 && (strcmp(res->vf, "vf") == 0)
9033                 && (strcmp(res->rate, "rate") == 0)
9034                 && (strcmp(res->q_msk, "queue_mask") == 0))
9035                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9036                                         res->rate_num, res->q_msk_val);
9037         if (ret < 0)
9038                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9039
9040 }
9041
9042 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9043         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9044                                 set, "set");
9045 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9046         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9047                                 port, "port");
9048 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9049         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9050                                 port_num, UINT16);
9051 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9052         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9053                                 vf, "vf");
9054 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9055         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9056                                 vf_num, UINT8);
9057 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9058         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9059                                 rate, "rate");
9060 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9061         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9062                                 rate_num, UINT16);
9063 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9064         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9065                                 q_msk, "queue_mask");
9066 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9067         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9068                                 q_msk_val, UINT64);
9069
9070 cmdline_parse_inst_t cmd_vf_rate_limit = {
9071         .f = cmd_vf_rate_limit_parsed,
9072         .data = (void *)0,
9073         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9074                 "queue_mask <queue_mask_value>: "
9075                 "Set rate limit for queues of VF on port_id",
9076         .tokens = {
9077                 (void *)&cmd_vf_rate_limit_set,
9078                 (void *)&cmd_vf_rate_limit_port,
9079                 (void *)&cmd_vf_rate_limit_portnum,
9080                 (void *)&cmd_vf_rate_limit_vf,
9081                 (void *)&cmd_vf_rate_limit_vfnum,
9082                 (void *)&cmd_vf_rate_limit_rate,
9083                 (void *)&cmd_vf_rate_limit_ratenum,
9084                 (void *)&cmd_vf_rate_limit_q_msk,
9085                 (void *)&cmd_vf_rate_limit_q_msk_val,
9086                 NULL,
9087         },
9088 };
9089
9090 /* *** CONFIGURE TUNNEL UDP PORT *** */
9091 struct cmd_tunnel_udp_config {
9092         cmdline_fixed_string_t cmd;
9093         cmdline_fixed_string_t what;
9094         uint16_t udp_port;
9095         portid_t port_id;
9096 };
9097
9098 static void
9099 cmd_tunnel_udp_config_parsed(void *parsed_result,
9100                           __rte_unused struct cmdline *cl,
9101                           __rte_unused void *data)
9102 {
9103         struct cmd_tunnel_udp_config *res = parsed_result;
9104         struct rte_eth_udp_tunnel tunnel_udp;
9105         int ret;
9106
9107         tunnel_udp.udp_port = res->udp_port;
9108
9109         if (!strcmp(res->cmd, "rx_vxlan_port"))
9110                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9111
9112         if (!strcmp(res->what, "add"))
9113                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9114                                                       &tunnel_udp);
9115         else
9116                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9117                                                          &tunnel_udp);
9118
9119         if (ret < 0)
9120                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9121 }
9122
9123 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9125                                 cmd, "rx_vxlan_port");
9126 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9128                                 what, "add#rm");
9129 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9131                                 udp_port, UINT16);
9132 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9134                                 port_id, UINT16);
9135
9136 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9137         .f = cmd_tunnel_udp_config_parsed,
9138         .data = (void *)0,
9139         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9140                 "Add/Remove a tunneling UDP port filter",
9141         .tokens = {
9142                 (void *)&cmd_tunnel_udp_config_cmd,
9143                 (void *)&cmd_tunnel_udp_config_what,
9144                 (void *)&cmd_tunnel_udp_config_udp_port,
9145                 (void *)&cmd_tunnel_udp_config_port_id,
9146                 NULL,
9147         },
9148 };
9149
9150 struct cmd_config_tunnel_udp_port {
9151         cmdline_fixed_string_t port;
9152         cmdline_fixed_string_t config;
9153         portid_t port_id;
9154         cmdline_fixed_string_t udp_tunnel_port;
9155         cmdline_fixed_string_t action;
9156         cmdline_fixed_string_t tunnel_type;
9157         uint16_t udp_port;
9158 };
9159
9160 static void
9161 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9162                                __rte_unused struct cmdline *cl,
9163                                __rte_unused void *data)
9164 {
9165         struct cmd_config_tunnel_udp_port *res = parsed_result;
9166         struct rte_eth_udp_tunnel tunnel_udp;
9167         int ret = 0;
9168
9169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9170                 return;
9171
9172         tunnel_udp.udp_port = res->udp_port;
9173
9174         if (!strcmp(res->tunnel_type, "vxlan")) {
9175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9176         } else if (!strcmp(res->tunnel_type, "geneve")) {
9177                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9178         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9179                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9180         } else {
9181                 printf("Invalid tunnel type\n");
9182                 return;
9183         }
9184
9185         if (!strcmp(res->action, "add"))
9186                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9187                                                       &tunnel_udp);
9188         else
9189                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9190                                                          &tunnel_udp);
9191
9192         if (ret < 0)
9193                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9194 }
9195
9196 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9197         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9198                                  "port");
9199 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9200         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9201                                  "config");
9202 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9203         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9204                               UINT16);
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9206         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9207                                  udp_tunnel_port,
9208                                  "udp_tunnel_port");
9209 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9210         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9211                                  "add#rm");
9212 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9213         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9214                                  "vxlan#geneve#vxlan-gpe");
9215 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9216         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9217                               UINT16);
9218
9219 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9220         .f = cmd_cfg_tunnel_udp_port_parsed,
9221         .data = NULL,
9222         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9223         .tokens = {
9224                 (void *)&cmd_config_tunnel_udp_port_port,
9225                 (void *)&cmd_config_tunnel_udp_port_config,
9226                 (void *)&cmd_config_tunnel_udp_port_port_id,
9227                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9228                 (void *)&cmd_config_tunnel_udp_port_action,
9229                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9230                 (void *)&cmd_config_tunnel_udp_port_value,
9231                 NULL,
9232         },
9233 };
9234
9235 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9236 struct cmd_set_mirror_mask_result {
9237         cmdline_fixed_string_t set;
9238         cmdline_fixed_string_t port;
9239         portid_t port_id;
9240         cmdline_fixed_string_t mirror;
9241         uint8_t rule_id;
9242         cmdline_fixed_string_t what;
9243         cmdline_fixed_string_t value;
9244         cmdline_fixed_string_t dstpool;
9245         uint8_t dstpool_id;
9246         cmdline_fixed_string_t on;
9247 };
9248
9249 cmdline_parse_token_string_t cmd_mirror_mask_set =
9250         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9251                                 set, "set");
9252 cmdline_parse_token_string_t cmd_mirror_mask_port =
9253         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9254                                 port, "port");
9255 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9256         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9257                                 port_id, UINT16);
9258 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9259         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9260                                 mirror, "mirror-rule");
9261 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9262         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9263                                 rule_id, UINT8);
9264 cmdline_parse_token_string_t cmd_mirror_mask_what =
9265         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9266                                 what, "pool-mirror-up#pool-mirror-down"
9267                                       "#vlan-mirror");
9268 cmdline_parse_token_string_t cmd_mirror_mask_value =
9269         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9270                                 value, NULL);
9271 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9272         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9273                                 dstpool, "dst-pool");
9274 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9275         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9276                                 dstpool_id, UINT8);
9277 cmdline_parse_token_string_t cmd_mirror_mask_on =
9278         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9279                                 on, "on#off");
9280
9281 static void
9282 cmd_set_mirror_mask_parsed(void *parsed_result,
9283                        __rte_unused struct cmdline *cl,
9284                        __rte_unused void *data)
9285 {
9286         int ret,nb_item,i;
9287         struct cmd_set_mirror_mask_result *res = parsed_result;
9288         struct rte_eth_mirror_conf mr_conf;
9289
9290         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9291
9292         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9293
9294         mr_conf.dst_pool = res->dstpool_id;
9295
9296         if (!strcmp(res->what, "pool-mirror-up")) {
9297                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9298                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9299         } else if (!strcmp(res->what, "pool-mirror-down")) {
9300                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9301                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9302         } else if (!strcmp(res->what, "vlan-mirror")) {
9303                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9304                 nb_item = parse_item_list(res->value, "vlan",
9305                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9306                 if (nb_item <= 0)
9307                         return;
9308
9309                 for (i = 0; i < nb_item; i++) {
9310                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9311                                 printf("Invalid vlan_id: must be < 4096\n");
9312                                 return;
9313                         }
9314
9315                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9316                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9317                 }
9318         }
9319
9320         if (!strcmp(res->on, "on"))
9321                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9322                                                 res->rule_id, 1);
9323         else
9324                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9325                                                 res->rule_id, 0);
9326         if (ret < 0)
9327                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9328 }
9329
9330 cmdline_parse_inst_t cmd_set_mirror_mask = {
9331                 .f = cmd_set_mirror_mask_parsed,
9332                 .data = NULL,
9333                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9334                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9335                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9336                 .tokens = {
9337                         (void *)&cmd_mirror_mask_set,
9338                         (void *)&cmd_mirror_mask_port,
9339                         (void *)&cmd_mirror_mask_portid,
9340                         (void *)&cmd_mirror_mask_mirror,
9341                         (void *)&cmd_mirror_mask_ruleid,
9342                         (void *)&cmd_mirror_mask_what,
9343                         (void *)&cmd_mirror_mask_value,
9344                         (void *)&cmd_mirror_mask_dstpool,
9345                         (void *)&cmd_mirror_mask_poolid,
9346                         (void *)&cmd_mirror_mask_on,
9347                         NULL,
9348                 },
9349 };
9350
9351 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9352 struct cmd_set_mirror_link_result {
9353         cmdline_fixed_string_t set;
9354         cmdline_fixed_string_t port;
9355         portid_t port_id;
9356         cmdline_fixed_string_t mirror;
9357         uint8_t rule_id;
9358         cmdline_fixed_string_t what;
9359         cmdline_fixed_string_t dstpool;
9360         uint8_t dstpool_id;
9361         cmdline_fixed_string_t on;
9362 };
9363
9364 cmdline_parse_token_string_t cmd_mirror_link_set =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9366                                  set, "set");
9367 cmdline_parse_token_string_t cmd_mirror_link_port =
9368         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9369                                 port, "port");
9370 cmdline_parse_token_num_t cmd_mirror_link_portid =
9371         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9372                                 port_id, UINT16);
9373 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9374         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9375                                 mirror, "mirror-rule");
9376 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9377         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9378                             rule_id, UINT8);
9379 cmdline_parse_token_string_t cmd_mirror_link_what =
9380         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9381                                 what, "uplink-mirror#downlink-mirror");
9382 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9383         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9384                                 dstpool, "dst-pool");
9385 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9386         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9387                                 dstpool_id, UINT8);
9388 cmdline_parse_token_string_t cmd_mirror_link_on =
9389         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9390                                 on, "on#off");
9391
9392 static void
9393 cmd_set_mirror_link_parsed(void *parsed_result,
9394                        __rte_unused struct cmdline *cl,
9395                        __rte_unused void *data)
9396 {
9397         int ret;
9398         struct cmd_set_mirror_link_result *res = parsed_result;
9399         struct rte_eth_mirror_conf mr_conf;
9400
9401         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9402         if (!strcmp(res->what, "uplink-mirror"))
9403                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9404         else
9405                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9406
9407         mr_conf.dst_pool = res->dstpool_id;
9408
9409         if (!strcmp(res->on, "on"))
9410                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9411                                                 res->rule_id, 1);
9412         else
9413                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9414                                                 res->rule_id, 0);
9415
9416         /* check the return value and print it if is < 0 */
9417         if (ret < 0)
9418                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9419
9420 }
9421
9422 cmdline_parse_inst_t cmd_set_mirror_link = {
9423                 .f = cmd_set_mirror_link_parsed,
9424                 .data = NULL,
9425                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9426                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9427                 .tokens = {
9428                         (void *)&cmd_mirror_link_set,
9429                         (void *)&cmd_mirror_link_port,
9430                         (void *)&cmd_mirror_link_portid,
9431                         (void *)&cmd_mirror_link_mirror,
9432                         (void *)&cmd_mirror_link_ruleid,
9433                         (void *)&cmd_mirror_link_what,
9434                         (void *)&cmd_mirror_link_dstpool,
9435                         (void *)&cmd_mirror_link_poolid,
9436                         (void *)&cmd_mirror_link_on,
9437                         NULL,
9438                 },
9439 };
9440
9441 /* *** RESET VM MIRROR RULE *** */
9442 struct cmd_rm_mirror_rule_result {
9443         cmdline_fixed_string_t reset;
9444         cmdline_fixed_string_t port;
9445         portid_t port_id;
9446         cmdline_fixed_string_t mirror;
9447         uint8_t rule_id;
9448 };
9449
9450 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9451         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9452                                  reset, "reset");
9453 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9454         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9455                                 port, "port");
9456 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9457         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9458                                 port_id, UINT16);
9459 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9460         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9461                                 mirror, "mirror-rule");
9462 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9463         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9464                                 rule_id, UINT8);
9465
9466 static void
9467 cmd_reset_mirror_rule_parsed(void *parsed_result,
9468                        __rte_unused struct cmdline *cl,
9469                        __rte_unused void *data)
9470 {
9471         int ret;
9472         struct cmd_set_mirror_link_result *res = parsed_result;
9473         /* check rule_id */
9474         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9475         if(ret < 0)
9476                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9477 }
9478
9479 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9480                 .f = cmd_reset_mirror_rule_parsed,
9481                 .data = NULL,
9482                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9483                 .tokens = {
9484                         (void *)&cmd_rm_mirror_rule_reset,
9485                         (void *)&cmd_rm_mirror_rule_port,
9486                         (void *)&cmd_rm_mirror_rule_portid,
9487                         (void *)&cmd_rm_mirror_rule_mirror,
9488                         (void *)&cmd_rm_mirror_rule_ruleid,
9489                         NULL,
9490                 },
9491 };
9492
9493 /* ******************************************************************************** */
9494
9495 struct cmd_dump_result {
9496         cmdline_fixed_string_t dump;
9497 };
9498
9499 static void
9500 dump_struct_sizes(void)
9501 {
9502 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9503         DUMP_SIZE(struct rte_mbuf);
9504         DUMP_SIZE(struct rte_mempool);
9505         DUMP_SIZE(struct rte_ring);
9506 #undef DUMP_SIZE
9507 }
9508
9509
9510 /* Dump the socket memory statistics on console */
9511 static void
9512 dump_socket_mem(FILE *f)
9513 {
9514         struct rte_malloc_socket_stats socket_stats;
9515         unsigned int i;
9516         size_t total = 0;
9517         size_t alloc = 0;
9518         size_t free = 0;
9519         unsigned int n_alloc = 0;
9520         unsigned int n_free = 0;
9521         static size_t last_allocs;
9522         static size_t last_total;
9523
9524
9525         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9526                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9527                     !socket_stats.heap_totalsz_bytes)
9528                         continue;
9529                 total += socket_stats.heap_totalsz_bytes;
9530                 alloc += socket_stats.heap_allocsz_bytes;
9531                 free += socket_stats.heap_freesz_bytes;
9532                 n_alloc += socket_stats.alloc_count;
9533                 n_free += socket_stats.free_count;
9534                 fprintf(f,
9535                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9536                         i,
9537                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9538                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9539                         (double)socket_stats.heap_allocsz_bytes * 100 /
9540                         (double)socket_stats.heap_totalsz_bytes,
9541                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9542                         socket_stats.alloc_count,
9543                         socket_stats.free_count);
9544         }
9545         fprintf(f,
9546                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9547                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9548                 (double)alloc * 100 / (double)total,
9549                 (double)free / (1024 * 1024),
9550                 n_alloc, n_free);
9551         if (last_allocs)
9552                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9553                         ((double)total - (double)last_total) / (1024 * 1024),
9554                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9555         last_allocs = alloc;
9556         last_total = total;
9557 }
9558
9559 static void cmd_dump_parsed(void *parsed_result,
9560                             __rte_unused struct cmdline *cl,
9561                             __rte_unused void *data)
9562 {
9563         struct cmd_dump_result *res = parsed_result;
9564
9565         if (!strcmp(res->dump, "dump_physmem"))
9566                 rte_dump_physmem_layout(stdout);
9567         else if (!strcmp(res->dump, "dump_socket_mem"))
9568                 dump_socket_mem(stdout);
9569         else if (!strcmp(res->dump, "dump_memzone"))
9570                 rte_memzone_dump(stdout);
9571         else if (!strcmp(res->dump, "dump_struct_sizes"))
9572                 dump_struct_sizes();
9573         else if (!strcmp(res->dump, "dump_ring"))
9574                 rte_ring_list_dump(stdout);
9575         else if (!strcmp(res->dump, "dump_mempool"))
9576                 rte_mempool_list_dump(stdout);
9577         else if (!strcmp(res->dump, "dump_devargs"))
9578                 rte_devargs_dump(stdout);
9579         else if (!strcmp(res->dump, "dump_log_types"))
9580                 rte_log_dump(stdout);
9581 }
9582
9583 cmdline_parse_token_string_t cmd_dump_dump =
9584         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9585                 "dump_physmem#"
9586                 "dump_memzone#"
9587                 "dump_socket_mem#"
9588                 "dump_struct_sizes#"
9589                 "dump_ring#"
9590                 "dump_mempool#"
9591                 "dump_devargs#"
9592                 "dump_log_types");
9593
9594 cmdline_parse_inst_t cmd_dump = {
9595         .f = cmd_dump_parsed,  /* function to call */
9596         .data = NULL,      /* 2nd arg of func */
9597         .help_str = "Dump status",
9598         .tokens = {        /* token list, NULL terminated */
9599                 (void *)&cmd_dump_dump,
9600                 NULL,
9601         },
9602 };
9603
9604 /* ******************************************************************************** */
9605
9606 struct cmd_dump_one_result {
9607         cmdline_fixed_string_t dump;
9608         cmdline_fixed_string_t name;
9609 };
9610
9611 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9612                                 __rte_unused void *data)
9613 {
9614         struct cmd_dump_one_result *res = parsed_result;
9615
9616         if (!strcmp(res->dump, "dump_ring")) {
9617                 struct rte_ring *r;
9618                 r = rte_ring_lookup(res->name);
9619                 if (r == NULL) {
9620                         cmdline_printf(cl, "Cannot find ring\n");
9621                         return;
9622                 }
9623                 rte_ring_dump(stdout, r);
9624         } else if (!strcmp(res->dump, "dump_mempool")) {
9625                 struct rte_mempool *mp;
9626                 mp = rte_mempool_lookup(res->name);
9627                 if (mp == NULL) {
9628                         cmdline_printf(cl, "Cannot find mempool\n");
9629                         return;
9630                 }
9631                 rte_mempool_dump(stdout, mp);
9632         }
9633 }
9634
9635 cmdline_parse_token_string_t cmd_dump_one_dump =
9636         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9637                                  "dump_ring#dump_mempool");
9638
9639 cmdline_parse_token_string_t cmd_dump_one_name =
9640         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9641
9642 cmdline_parse_inst_t cmd_dump_one = {
9643         .f = cmd_dump_one_parsed,  /* function to call */
9644         .data = NULL,      /* 2nd arg of func */
9645         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9646         .tokens = {        /* token list, NULL terminated */
9647                 (void *)&cmd_dump_one_dump,
9648                 (void *)&cmd_dump_one_name,
9649                 NULL,
9650         },
9651 };
9652
9653 /* *** queue region set *** */
9654 struct cmd_queue_region_result {
9655         cmdline_fixed_string_t set;
9656         cmdline_fixed_string_t port;
9657         portid_t port_id;
9658         cmdline_fixed_string_t cmd;
9659         cmdline_fixed_string_t region;
9660         uint8_t  region_id;
9661         cmdline_fixed_string_t queue_start_index;
9662         uint8_t  queue_id;
9663         cmdline_fixed_string_t queue_num;
9664         uint8_t  queue_num_value;
9665 };
9666
9667 static void
9668 cmd_queue_region_parsed(void *parsed_result,
9669                         __rte_unused struct cmdline *cl,
9670                         __rte_unused void *data)
9671 {
9672         struct cmd_queue_region_result *res = parsed_result;
9673         int ret = -ENOTSUP;
9674 #ifdef RTE_NET_I40E
9675         struct rte_pmd_i40e_queue_region_conf region_conf;
9676         enum rte_pmd_i40e_queue_region_op op_type;
9677 #endif
9678
9679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9680                 return;
9681
9682 #ifdef RTE_NET_I40E
9683         memset(&region_conf, 0, sizeof(region_conf));
9684         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9685         region_conf.region_id = res->region_id;
9686         region_conf.queue_num = res->queue_num_value;
9687         region_conf.queue_start_index = res->queue_id;
9688
9689         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9690                                 op_type, &region_conf);
9691 #endif
9692
9693         switch (ret) {
9694         case 0:
9695                 break;
9696         case -ENOTSUP:
9697                 printf("function not implemented or supported\n");
9698                 break;
9699         default:
9700                 printf("queue region config error: (%s)\n", strerror(-ret));
9701         }
9702 }
9703
9704 cmdline_parse_token_string_t cmd_queue_region_set =
9705 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9706                 set, "set");
9707 cmdline_parse_token_string_t cmd_queue_region_port =
9708         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9709 cmdline_parse_token_num_t cmd_queue_region_port_id =
9710         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9711                                 port_id, UINT16);
9712 cmdline_parse_token_string_t cmd_queue_region_cmd =
9713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9714                                  cmd, "queue-region");
9715 cmdline_parse_token_string_t cmd_queue_region_id =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                                 region, "region_id");
9718 cmdline_parse_token_num_t cmd_queue_region_index =
9719         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9720                                 region_id, UINT8);
9721 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9723                                 queue_start_index, "queue_start_index");
9724 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9725         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9726                                 queue_id, UINT8);
9727 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_num, "queue_num");
9730 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_num_value, UINT8);
9733
9734 cmdline_parse_inst_t cmd_queue_region = {
9735         .f = cmd_queue_region_parsed,
9736         .data = NULL,
9737         .help_str = "set port <port_id> queue-region region_id <value> "
9738                 "queue_start_index <value> queue_num <value>: Set a queue region",
9739         .tokens = {
9740                 (void *)&cmd_queue_region_set,
9741                 (void *)&cmd_queue_region_port,
9742                 (void *)&cmd_queue_region_port_id,
9743                 (void *)&cmd_queue_region_cmd,
9744                 (void *)&cmd_queue_region_id,
9745                 (void *)&cmd_queue_region_index,
9746                 (void *)&cmd_queue_region_queue_start_index,
9747                 (void *)&cmd_queue_region_queue_id,
9748                 (void *)&cmd_queue_region_queue_num,
9749                 (void *)&cmd_queue_region_queue_num_value,
9750                 NULL,
9751         },
9752 };
9753
9754 /* *** queue region and flowtype set *** */
9755 struct cmd_region_flowtype_result {
9756         cmdline_fixed_string_t set;
9757         cmdline_fixed_string_t port;
9758         portid_t port_id;
9759         cmdline_fixed_string_t cmd;
9760         cmdline_fixed_string_t region;
9761         uint8_t  region_id;
9762         cmdline_fixed_string_t flowtype;
9763         uint8_t  flowtype_id;
9764 };
9765
9766 static void
9767 cmd_region_flowtype_parsed(void *parsed_result,
9768                         __rte_unused struct cmdline *cl,
9769                         __rte_unused void *data)
9770 {
9771         struct cmd_region_flowtype_result *res = parsed_result;
9772         int ret = -ENOTSUP;
9773 #ifdef RTE_NET_I40E
9774         struct rte_pmd_i40e_queue_region_conf region_conf;
9775         enum rte_pmd_i40e_queue_region_op op_type;
9776 #endif
9777
9778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9779                 return;
9780
9781 #ifdef RTE_NET_I40E
9782         memset(&region_conf, 0, sizeof(region_conf));
9783
9784         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9785         region_conf.region_id = res->region_id;
9786         region_conf.hw_flowtype = res->flowtype_id;
9787
9788         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9789                         op_type, &region_conf);
9790 #endif
9791
9792         switch (ret) {
9793         case 0:
9794                 break;
9795         case -ENOTSUP:
9796                 printf("function not implemented or supported\n");
9797                 break;
9798         default:
9799                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9800         }
9801 }
9802
9803 cmdline_parse_token_string_t cmd_region_flowtype_set =
9804 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9805                                 set, "set");
9806 cmdline_parse_token_string_t cmd_region_flowtype_port =
9807         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9808                                 port, "port");
9809 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9810         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 port_id, UINT16);
9812 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 cmd, "queue-region");
9815 cmdline_parse_token_string_t cmd_region_flowtype_index =
9816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 region, "region_id");
9818 cmdline_parse_token_num_t cmd_region_flowtype_id =
9819         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 region_id, UINT8);
9821 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9822         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 flowtype, "flowtype");
9824 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9825         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 flowtype_id, UINT8);
9827 cmdline_parse_inst_t cmd_region_flowtype = {
9828         .f = cmd_region_flowtype_parsed,
9829         .data = NULL,
9830         .help_str = "set port <port_id> queue-region region_id <value> "
9831                 "flowtype <value>: Set a flowtype region index",
9832         .tokens = {
9833                 (void *)&cmd_region_flowtype_set,
9834                 (void *)&cmd_region_flowtype_port,
9835                 (void *)&cmd_region_flowtype_port_index,
9836                 (void *)&cmd_region_flowtype_cmd,
9837                 (void *)&cmd_region_flowtype_index,
9838                 (void *)&cmd_region_flowtype_id,
9839                 (void *)&cmd_region_flowtype_flow_index,
9840                 (void *)&cmd_region_flowtype_flow_id,
9841                 NULL,
9842         },
9843 };
9844
9845 /* *** User Priority (UP) to queue region (region_id) set *** */
9846 struct cmd_user_priority_region_result {
9847         cmdline_fixed_string_t set;
9848         cmdline_fixed_string_t port;
9849         portid_t port_id;
9850         cmdline_fixed_string_t cmd;
9851         cmdline_fixed_string_t user_priority;
9852         uint8_t  user_priority_id;
9853         cmdline_fixed_string_t region;
9854         uint8_t  region_id;
9855 };
9856
9857 static void
9858 cmd_user_priority_region_parsed(void *parsed_result,
9859                         __rte_unused struct cmdline *cl,
9860                         __rte_unused void *data)
9861 {
9862         struct cmd_user_priority_region_result *res = parsed_result;
9863         int ret = -ENOTSUP;
9864 #ifdef RTE_NET_I40E
9865         struct rte_pmd_i40e_queue_region_conf region_conf;
9866         enum rte_pmd_i40e_queue_region_op op_type;
9867 #endif
9868
9869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9870                 return;
9871
9872 #ifdef RTE_NET_I40E
9873         memset(&region_conf, 0, sizeof(region_conf));
9874         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9875         region_conf.user_priority = res->user_priority_id;
9876         region_conf.region_id = res->region_id;
9877
9878         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9879                                 op_type, &region_conf);
9880 #endif
9881
9882         switch (ret) {
9883         case 0:
9884                 break;
9885         case -ENOTSUP:
9886                 printf("function not implemented or supported\n");
9887                 break;
9888         default:
9889                 printf("user_priority region config error: (%s)\n",
9890                                 strerror(-ret));
9891         }
9892 }
9893
9894 cmdline_parse_token_string_t cmd_user_priority_region_set =
9895         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9896                                 set, "set");
9897 cmdline_parse_token_string_t cmd_user_priority_region_port =
9898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9899                                 port, "port");
9900 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9901         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 port_id, UINT16);
9903 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 cmd, "queue-region");
9906 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 user_priority, "UP");
9909 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9910         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 user_priority_id, UINT8);
9912 cmdline_parse_token_string_t cmd_user_priority_region_region =
9913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 region, "region_id");
9915 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9916         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 region_id, UINT8);
9918
9919 cmdline_parse_inst_t cmd_user_priority_region = {
9920         .f = cmd_user_priority_region_parsed,
9921         .data = NULL,
9922         .help_str = "set port <port_id> queue-region UP <value> "
9923                 "region_id <value>: Set the mapping of User Priority (UP) "
9924                 "to queue region (region_id) ",
9925         .tokens = {
9926                 (void *)&cmd_user_priority_region_set,
9927                 (void *)&cmd_user_priority_region_port,
9928                 (void *)&cmd_user_priority_region_port_index,
9929                 (void *)&cmd_user_priority_region_cmd,
9930                 (void *)&cmd_user_priority_region_UP,
9931                 (void *)&cmd_user_priority_region_UP_id,
9932                 (void *)&cmd_user_priority_region_region,
9933                 (void *)&cmd_user_priority_region_region_id,
9934                 NULL,
9935         },
9936 };
9937
9938 /* *** flush all queue region related configuration *** */
9939 struct cmd_flush_queue_region_result {
9940         cmdline_fixed_string_t set;
9941         cmdline_fixed_string_t port;
9942         portid_t port_id;
9943         cmdline_fixed_string_t cmd;
9944         cmdline_fixed_string_t flush;
9945         cmdline_fixed_string_t what;
9946 };
9947
9948 static void
9949 cmd_flush_queue_region_parsed(void *parsed_result,
9950                         __rte_unused struct cmdline *cl,
9951                         __rte_unused void *data)
9952 {
9953         struct cmd_flush_queue_region_result *res = parsed_result;
9954         int ret = -ENOTSUP;
9955 #ifdef RTE_NET_I40E
9956         struct rte_pmd_i40e_queue_region_conf region_conf;
9957         enum rte_pmd_i40e_queue_region_op op_type;
9958 #endif
9959
9960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9961                 return;
9962
9963 #ifdef RTE_NET_I40E
9964         memset(&region_conf, 0, sizeof(region_conf));
9965
9966         if (strcmp(res->what, "on") == 0)
9967                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9968         else
9969                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9970
9971         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9972                                 op_type, &region_conf);
9973 #endif
9974
9975         switch (ret) {
9976         case 0:
9977                 break;
9978         case -ENOTSUP:
9979                 printf("function not implemented or supported\n");
9980                 break;
9981         default:
9982                 printf("queue region config flush error: (%s)\n",
9983                                 strerror(-ret));
9984         }
9985 }
9986
9987 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9988         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9989                                 set, "set");
9990 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9992                                 port, "port");
9993 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9994         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 port_id, UINT16);
9996 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9997         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 cmd, "queue-region");
9999 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 flush, "flush");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 what, "on#off");
10005
10006 cmdline_parse_inst_t cmd_flush_queue_region = {
10007         .f = cmd_flush_queue_region_parsed,
10008         .data = NULL,
10009         .help_str = "set port <port_id> queue-region flush on|off"
10010                 ": flush all queue region related configuration",
10011         .tokens = {
10012                 (void *)&cmd_flush_queue_region_set,
10013                 (void *)&cmd_flush_queue_region_port,
10014                 (void *)&cmd_flush_queue_region_port_index,
10015                 (void *)&cmd_flush_queue_region_cmd,
10016                 (void *)&cmd_flush_queue_region_flush,
10017                 (void *)&cmd_flush_queue_region_what,
10018                 NULL,
10019         },
10020 };
10021
10022 /* *** get all queue region related configuration info *** */
10023 struct cmd_show_queue_region_info {
10024         cmdline_fixed_string_t show;
10025         cmdline_fixed_string_t port;
10026         portid_t port_id;
10027         cmdline_fixed_string_t cmd;
10028 };
10029
10030 static void
10031 cmd_show_queue_region_info_parsed(void *parsed_result,
10032                         __rte_unused struct cmdline *cl,
10033                         __rte_unused void *data)
10034 {
10035         struct cmd_show_queue_region_info *res = parsed_result;
10036         int ret = -ENOTSUP;
10037 #ifdef RTE_NET_I40E
10038         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10039         enum rte_pmd_i40e_queue_region_op op_type;
10040 #endif
10041
10042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10043                 return;
10044
10045 #ifdef RTE_NET_I40E
10046         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10047
10048         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10049
10050         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10051                                         op_type, &rte_pmd_regions);
10052
10053         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10054 #endif
10055
10056         switch (ret) {
10057         case 0:
10058                 break;
10059         case -ENOTSUP:
10060                 printf("function not implemented or supported\n");
10061                 break;
10062         default:
10063                 printf("queue region config info show error: (%s)\n",
10064                                 strerror(-ret));
10065         }
10066 }
10067
10068 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10069 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10070                                 show, "show");
10071 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10072         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10073                                 port, "port");
10074 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10075         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 port_id, UINT16);
10077 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10078         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 cmd, "queue-region");
10080
10081 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10082         .f = cmd_show_queue_region_info_parsed,
10083         .data = NULL,
10084         .help_str = "show port <port_id> queue-region"
10085                 ": show all queue region related configuration info",
10086         .tokens = {
10087                 (void *)&cmd_show_queue_region_info_get,
10088                 (void *)&cmd_show_queue_region_info_port,
10089                 (void *)&cmd_show_queue_region_info_port_index,
10090                 (void *)&cmd_show_queue_region_info_cmd,
10091                 NULL,
10092         },
10093 };
10094
10095 /* *** Filters Control *** */
10096
10097 static uint16_t
10098 str2flowtype(char *string)
10099 {
10100         uint8_t i = 0;
10101         static const struct {
10102                 char str[32];
10103                 uint16_t type;
10104         } flowtype_str[] = {
10105                 {"raw", RTE_ETH_FLOW_RAW},
10106                 {"ipv4", RTE_ETH_FLOW_IPV4},
10107                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10108                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10109                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10110                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10111                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10112                 {"ipv6", RTE_ETH_FLOW_IPV6},
10113                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10114                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10115                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10116                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10117                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10118                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10119         };
10120
10121         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10122                 if (!strcmp(flowtype_str[i].str, string))
10123                         return flowtype_str[i].type;
10124         }
10125
10126         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10127                 return (uint16_t)atoi(string);
10128
10129         return RTE_ETH_FLOW_UNKNOWN;
10130 }
10131
10132 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10133 do { \
10134         if ((ip_addr).family == AF_INET) \
10135                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10136         else { \
10137                 printf("invalid parameter.\n"); \
10138                 return; \
10139         } \
10140 } while (0)
10141
10142 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10143 do { \
10144         if ((ip_addr).family == AF_INET6) \
10145                 rte_memcpy(&(ip), \
10146                                  &((ip_addr).addr.ipv6), \
10147                                  sizeof(struct in6_addr)); \
10148         else { \
10149                 printf("invalid parameter.\n"); \
10150                 return; \
10151         } \
10152 } while (0)
10153
10154 #ifdef RTE_NET_I40E
10155
10156 /* *** deal with flow director filter *** */
10157 struct cmd_flow_director_result {
10158         cmdline_fixed_string_t flow_director_filter;
10159         portid_t port_id;
10160         cmdline_fixed_string_t mode;
10161         cmdline_fixed_string_t mode_value;
10162         cmdline_fixed_string_t ops;
10163         cmdline_fixed_string_t flow;
10164         cmdline_fixed_string_t flow_type;
10165         cmdline_fixed_string_t drop;
10166         cmdline_fixed_string_t queue;
10167         uint16_t  queue_id;
10168         cmdline_fixed_string_t fd_id;
10169         uint32_t  fd_id_value;
10170         cmdline_fixed_string_t packet;
10171         char filepath[];
10172 };
10173
10174 static void
10175 cmd_flow_director_filter_parsed(void *parsed_result,
10176                           __rte_unused struct cmdline *cl,
10177                           __rte_unused void *data)
10178 {
10179         struct cmd_flow_director_result *res = parsed_result;
10180         int ret = 0;
10181         struct rte_pmd_i40e_flow_type_mapping
10182                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10183         struct rte_pmd_i40e_pkt_template_conf conf;
10184         uint16_t flow_type = str2flowtype(res->flow_type);
10185         uint16_t i, port = res->port_id;
10186         uint8_t add;
10187
10188         memset(&conf, 0, sizeof(conf));
10189
10190         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10191                 printf("Invalid flow type specified.\n");
10192                 return;
10193         }
10194         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10195                                                  mapping);
10196         if (ret)
10197                 return;
10198         if (mapping[flow_type].pctype == 0ULL) {
10199                 printf("Invalid flow type specified.\n");
10200                 return;
10201         }
10202         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10203                 if (mapping[flow_type].pctype & (1ULL << i)) {
10204                         conf.input.pctype = i;
10205                         break;
10206                 }
10207         }
10208
10209         conf.input.packet = open_file(res->filepath,
10210                                 &conf.input.length);
10211         if (!conf.input.packet)
10212                 return;
10213         if (!strcmp(res->drop, "drop"))
10214                 conf.action.behavior =
10215                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10216         else
10217                 conf.action.behavior =
10218                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10219         conf.action.report_status =
10220                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10221         conf.action.rx_queue = res->queue_id;
10222         conf.soft_id = res->fd_id_value;
10223         add  = strcmp(res->ops, "del") ? 1 : 0;
10224         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10225                                                         &conf,
10226                                                         add);
10227         if (ret < 0)
10228                 printf("flow director config error: (%s)\n",
10229                        strerror(-ret));
10230         close_file(conf.input.packet);
10231 }
10232
10233 cmdline_parse_token_string_t cmd_flow_director_filter =
10234         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10235                                  flow_director_filter, "flow_director_filter");
10236 cmdline_parse_token_num_t cmd_flow_director_port_id =
10237         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10238                               port_id, UINT16);
10239 cmdline_parse_token_string_t cmd_flow_director_ops =
10240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10241                                  ops, "add#del#update");
10242 cmdline_parse_token_string_t cmd_flow_director_flow =
10243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10244                                  flow, "flow");
10245 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10247                 flow_type, NULL);
10248 cmdline_parse_token_string_t cmd_flow_director_drop =
10249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10250                                  drop, "drop#fwd");
10251 cmdline_parse_token_string_t cmd_flow_director_queue =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  queue, "queue");
10254 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10256                               queue_id, UINT16);
10257 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10259                                  fd_id, "fd_id");
10260 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10261         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10262                               fd_id_value, UINT32);
10263
10264 cmdline_parse_token_string_t cmd_flow_director_mode =
10265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10266                                  mode, "mode");
10267 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10269                                  mode_value, "raw");
10270 cmdline_parse_token_string_t cmd_flow_director_packet =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10272                                  packet, "packet");
10273 cmdline_parse_token_string_t cmd_flow_director_filepath =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10275                                  filepath, NULL);
10276
10277 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10278         .f = cmd_flow_director_filter_parsed,
10279         .data = NULL,
10280         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10281                 "director entry on NIC",
10282         .tokens = {
10283                 (void *)&cmd_flow_director_filter,
10284                 (void *)&cmd_flow_director_port_id,
10285                 (void *)&cmd_flow_director_mode,
10286                 (void *)&cmd_flow_director_mode_raw,
10287                 (void *)&cmd_flow_director_ops,
10288                 (void *)&cmd_flow_director_flow,
10289                 (void *)&cmd_flow_director_flow_type,
10290                 (void *)&cmd_flow_director_drop,
10291                 (void *)&cmd_flow_director_queue,
10292                 (void *)&cmd_flow_director_queue_id,
10293                 (void *)&cmd_flow_director_fd_id,
10294                 (void *)&cmd_flow_director_fd_id_value,
10295                 (void *)&cmd_flow_director_packet,
10296                 (void *)&cmd_flow_director_filepath,
10297                 NULL,
10298         },
10299 };
10300
10301 #endif /* RTE_NET_I40E */
10302
10303 /* *** deal with flow director mask *** */
10304 struct cmd_flow_director_mask_result {
10305         cmdline_fixed_string_t flow_director_mask;
10306         portid_t port_id;
10307         cmdline_fixed_string_t mode;
10308         cmdline_fixed_string_t mode_value;
10309         cmdline_fixed_string_t vlan;
10310         uint16_t vlan_mask;
10311         cmdline_fixed_string_t src_mask;
10312         cmdline_ipaddr_t ipv4_src;
10313         cmdline_ipaddr_t ipv6_src;
10314         uint16_t port_src;
10315         cmdline_fixed_string_t dst_mask;
10316         cmdline_ipaddr_t ipv4_dst;
10317         cmdline_ipaddr_t ipv6_dst;
10318         uint16_t port_dst;
10319         cmdline_fixed_string_t mac;
10320         uint8_t mac_addr_byte_mask;
10321         cmdline_fixed_string_t tunnel_id;
10322         uint32_t tunnel_id_mask;
10323         cmdline_fixed_string_t tunnel_type;
10324         uint8_t tunnel_type_mask;
10325 };
10326
10327 static void
10328 cmd_flow_director_mask_parsed(void *parsed_result,
10329                           __rte_unused struct cmdline *cl,
10330                           __rte_unused void *data)
10331 {
10332         struct cmd_flow_director_mask_result *res = parsed_result;
10333         struct rte_eth_fdir_masks *mask;
10334         struct rte_port *port;
10335
10336         port = &ports[res->port_id];
10337         /** Check if the port is not started **/
10338         if (port->port_status != RTE_PORT_STOPPED) {
10339                 printf("Please stop port %d first\n", res->port_id);
10340                 return;
10341         }
10342
10343         mask = &port->dev_conf.fdir_conf.mask;
10344
10345         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10346                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10347                         printf("Please set mode to MAC-VLAN.\n");
10348                         return;
10349                 }
10350
10351                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10352         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10353                 if (strcmp(res->mode_value, "Tunnel")) {
10354                         printf("Please set mode to Tunnel.\n");
10355                         return;
10356                 }
10357
10358                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10359                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10360                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10361                 mask->tunnel_type_mask = res->tunnel_type_mask;
10362         } else {
10363                 if (strcmp(res->mode_value, "IP")) {
10364                         printf("Please set mode to IP.\n");
10365                         return;
10366                 }
10367
10368                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10369                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10370                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10371                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10372                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10373                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10374                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10375         }
10376
10377         cmd_reconfig_device_queue(res->port_id, 1, 1);
10378 }
10379
10380 cmdline_parse_token_string_t cmd_flow_director_mask =
10381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10382                                  flow_director_mask, "flow_director_mask");
10383 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10384         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10385                               port_id, UINT16);
10386 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10387         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10388                                  vlan, "vlan");
10389 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10390         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10391                               vlan_mask, UINT16);
10392 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10394                                  src_mask, "src_mask");
10395 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10396         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10397                                  ipv4_src);
10398 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10399         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  ipv6_src);
10401 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10403                               port_src, UINT16);
10404 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10406                                  dst_mask, "dst_mask");
10407 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10408         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10409                                  ipv4_dst);
10410 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10411         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10412                                  ipv6_dst);
10413 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10414         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10415                               port_dst, UINT16);
10416
10417 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10418         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10419                                  mode, "mode");
10420 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  mode_value, "IP");
10423 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  mode_value, "MAC-VLAN");
10426 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10428                                  mode_value, "Tunnel");
10429 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10431                                  mac, "mac");
10432 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10434                               mac_addr_byte_mask, UINT8);
10435 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10437                                  tunnel_type, "tunnel-type");
10438 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10439         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10440                               tunnel_type_mask, UINT8);
10441 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10443                                  tunnel_id, "tunnel-id");
10444 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10446                               tunnel_id_mask, UINT32);
10447
10448 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10449         .f = cmd_flow_director_mask_parsed,
10450         .data = NULL,
10451         .help_str = "flow_director_mask ... : "
10452                 "Set IP mode flow director's mask on NIC",
10453         .tokens = {
10454                 (void *)&cmd_flow_director_mask,
10455                 (void *)&cmd_flow_director_mask_port_id,
10456                 (void *)&cmd_flow_director_mask_mode,
10457                 (void *)&cmd_flow_director_mask_mode_ip,
10458                 (void *)&cmd_flow_director_mask_vlan,
10459                 (void *)&cmd_flow_director_mask_vlan_value,
10460                 (void *)&cmd_flow_director_mask_src,
10461                 (void *)&cmd_flow_director_mask_ipv4_src,
10462                 (void *)&cmd_flow_director_mask_ipv6_src,
10463                 (void *)&cmd_flow_director_mask_port_src,
10464                 (void *)&cmd_flow_director_mask_dst,
10465                 (void *)&cmd_flow_director_mask_ipv4_dst,
10466                 (void *)&cmd_flow_director_mask_ipv6_dst,
10467                 (void *)&cmd_flow_director_mask_port_dst,
10468                 NULL,
10469         },
10470 };
10471
10472 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10473         .f = cmd_flow_director_mask_parsed,
10474         .data = NULL,
10475         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10476                 "flow director's mask on NIC",
10477         .tokens = {
10478                 (void *)&cmd_flow_director_mask,
10479                 (void *)&cmd_flow_director_mask_port_id,
10480                 (void *)&cmd_flow_director_mask_mode,
10481                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10482                 (void *)&cmd_flow_director_mask_vlan,
10483                 (void *)&cmd_flow_director_mask_vlan_value,
10484                 NULL,
10485         },
10486 };
10487
10488 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10489         .f = cmd_flow_director_mask_parsed,
10490         .data = NULL,
10491         .help_str = "flow_director_mask ... : Set tunnel mode "
10492                 "flow director's mask on NIC",
10493         .tokens = {
10494                 (void *)&cmd_flow_director_mask,
10495                 (void *)&cmd_flow_director_mask_port_id,
10496                 (void *)&cmd_flow_director_mask_mode,
10497                 (void *)&cmd_flow_director_mask_mode_tunnel,
10498                 (void *)&cmd_flow_director_mask_vlan,
10499                 (void *)&cmd_flow_director_mask_vlan_value,
10500                 (void *)&cmd_flow_director_mask_mac,
10501                 (void *)&cmd_flow_director_mask_mac_value,
10502                 (void *)&cmd_flow_director_mask_tunnel_type,
10503                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10504                 (void *)&cmd_flow_director_mask_tunnel_id,
10505                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10506                 NULL,
10507         },
10508 };
10509
10510 /* *** deal with flow director flexible payload configuration *** */
10511 struct cmd_flow_director_flexpayload_result {
10512         cmdline_fixed_string_t flow_director_flexpayload;
10513         portid_t port_id;
10514         cmdline_fixed_string_t payload_layer;
10515         cmdline_fixed_string_t payload_cfg;
10516 };
10517
10518 static inline int
10519 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10520 {
10521         char s[256];
10522         const char *p, *p0 = q_arg;
10523         char *end;
10524         unsigned long int_fld;
10525         char *str_fld[max_num];
10526         int i;
10527         unsigned size;
10528         int ret = -1;
10529
10530         p = strchr(p0, '(');
10531         if (p == NULL)
10532                 return -1;
10533         ++p;
10534         p0 = strchr(p, ')');
10535         if (p0 == NULL)
10536                 return -1;
10537
10538         size = p0 - p;
10539         if (size >= sizeof(s))
10540                 return -1;
10541
10542         snprintf(s, sizeof(s), "%.*s", size, p);
10543         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10544         if (ret < 0 || ret > max_num)
10545                 return -1;
10546         for (i = 0; i < ret; i++) {
10547                 errno = 0;
10548                 int_fld = strtoul(str_fld[i], &end, 0);
10549                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10550                         return -1;
10551                 offsets[i] = (uint16_t)int_fld;
10552         }
10553         return ret;
10554 }
10555
10556 static void
10557 cmd_flow_director_flxpld_parsed(void *parsed_result,
10558                           __rte_unused struct cmdline *cl,
10559                           __rte_unused void *data)
10560 {
10561         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10562         struct rte_eth_flex_payload_cfg flex_cfg;
10563         struct rte_port *port;
10564         int ret = 0;
10565
10566         port = &ports[res->port_id];
10567         /** Check if the port is not started **/
10568         if (port->port_status != RTE_PORT_STOPPED) {
10569                 printf("Please stop port %d first\n", res->port_id);
10570                 return;
10571         }
10572
10573         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10574
10575         if (!strcmp(res->payload_layer, "raw"))
10576                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10577         else if (!strcmp(res->payload_layer, "l2"))
10578                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10579         else if (!strcmp(res->payload_layer, "l3"))
10580                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10581         else if (!strcmp(res->payload_layer, "l4"))
10582                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10583
10584         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10585                             RTE_ETH_FDIR_MAX_FLEXLEN);
10586         if (ret < 0) {
10587                 printf("error: Cannot parse flex payload input.\n");
10588                 return;
10589         }
10590
10591         fdir_set_flex_payload(res->port_id, &flex_cfg);
10592         cmd_reconfig_device_queue(res->port_id, 1, 1);
10593 }
10594
10595 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10597                                  flow_director_flexpayload,
10598                                  "flow_director_flex_payload");
10599 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10600         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10601                               port_id, UINT16);
10602 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10604                                  payload_layer, "raw#l2#l3#l4");
10605 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10607                                  payload_cfg, NULL);
10608
10609 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10610         .f = cmd_flow_director_flxpld_parsed,
10611         .data = NULL,
10612         .help_str = "flow_director_flexpayload ... : "
10613                 "Set flow director's flex payload on NIC",
10614         .tokens = {
10615                 (void *)&cmd_flow_director_flexpayload,
10616                 (void *)&cmd_flow_director_flexpayload_port_id,
10617                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10618                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10619                 NULL,
10620         },
10621 };
10622
10623 /* Generic flow interface command. */
10624 extern cmdline_parse_inst_t cmd_flow;
10625
10626 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10627 struct cmd_mcast_addr_result {
10628         cmdline_fixed_string_t mcast_addr_cmd;
10629         cmdline_fixed_string_t what;
10630         uint16_t port_num;
10631         struct rte_ether_addr mc_addr;
10632 };
10633
10634 static void cmd_mcast_addr_parsed(void *parsed_result,
10635                 __rte_unused struct cmdline *cl,
10636                 __rte_unused void *data)
10637 {
10638         struct cmd_mcast_addr_result *res = parsed_result;
10639
10640         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10641                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10642                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10643                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10644                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10645                 return;
10646         }
10647         if (strcmp(res->what, "add") == 0)
10648                 mcast_addr_add(res->port_num, &res->mc_addr);
10649         else
10650                 mcast_addr_remove(res->port_num, &res->mc_addr);
10651 }
10652
10653 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10654         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10655                                  mcast_addr_cmd, "mcast_addr");
10656 cmdline_parse_token_string_t cmd_mcast_addr_what =
10657         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10658                                  "add#remove");
10659 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10660         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
10661 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10662         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10663
10664 cmdline_parse_inst_t cmd_mcast_addr = {
10665         .f = cmd_mcast_addr_parsed,
10666         .data = (void *)0,
10667         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10668                 "Add/Remove multicast MAC address on port_id",
10669         .tokens = {
10670                 (void *)&cmd_mcast_addr_cmd,
10671                 (void *)&cmd_mcast_addr_what,
10672                 (void *)&cmd_mcast_addr_portnum,
10673                 (void *)&cmd_mcast_addr_addr,
10674                 NULL,
10675         },
10676 };
10677
10678 /* l2 tunnel config
10679  * only support E-tag now.
10680  */
10681
10682 /* Ether type config */
10683 struct cmd_config_l2_tunnel_eth_type_result {
10684         cmdline_fixed_string_t port;
10685         cmdline_fixed_string_t config;
10686         cmdline_fixed_string_t all;
10687         portid_t id;
10688         cmdline_fixed_string_t l2_tunnel;
10689         cmdline_fixed_string_t l2_tunnel_type;
10690         cmdline_fixed_string_t eth_type;
10691         uint16_t eth_type_val;
10692 };
10693
10694 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10695         TOKEN_STRING_INITIALIZER
10696                 (struct cmd_config_l2_tunnel_eth_type_result,
10697                  port, "port");
10698 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10699         TOKEN_STRING_INITIALIZER
10700                 (struct cmd_config_l2_tunnel_eth_type_result,
10701                  config, "config");
10702 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10703         TOKEN_STRING_INITIALIZER
10704                 (struct cmd_config_l2_tunnel_eth_type_result,
10705                  all, "all");
10706 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10707         TOKEN_NUM_INITIALIZER
10708                 (struct cmd_config_l2_tunnel_eth_type_result,
10709                  id, UINT16);
10710 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10711         TOKEN_STRING_INITIALIZER
10712                 (struct cmd_config_l2_tunnel_eth_type_result,
10713                  l2_tunnel, "l2-tunnel");
10714 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10715         TOKEN_STRING_INITIALIZER
10716                 (struct cmd_config_l2_tunnel_eth_type_result,
10717                  l2_tunnel_type, "E-tag");
10718 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10719         TOKEN_STRING_INITIALIZER
10720                 (struct cmd_config_l2_tunnel_eth_type_result,
10721                  eth_type, "ether-type");
10722 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10723         TOKEN_NUM_INITIALIZER
10724                 (struct cmd_config_l2_tunnel_eth_type_result,
10725                  eth_type_val, UINT16);
10726
10727 static enum rte_eth_tunnel_type
10728 str2fdir_l2_tunnel_type(char *string)
10729 {
10730         uint32_t i = 0;
10731
10732         static const struct {
10733                 char str[32];
10734                 enum rte_eth_tunnel_type type;
10735         } l2_tunnel_type_str[] = {
10736                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10737         };
10738
10739         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10740                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10741                         return l2_tunnel_type_str[i].type;
10742         }
10743         return RTE_TUNNEL_TYPE_NONE;
10744 }
10745
10746 /* ether type config for all ports */
10747 static void
10748 cmd_config_l2_tunnel_eth_type_all_parsed
10749         (void *parsed_result,
10750          __rte_unused struct cmdline *cl,
10751          __rte_unused void *data)
10752 {
10753         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10754         struct rte_eth_l2_tunnel_conf entry;
10755         portid_t pid;
10756
10757         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10758         entry.ether_type = res->eth_type_val;
10759
10760         RTE_ETH_FOREACH_DEV(pid) {
10761                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10762         }
10763 }
10764
10765 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10766         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
10767         .data = NULL,
10768         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
10769         .tokens = {
10770                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10771                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10772                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
10773                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10774                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10775                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10776                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10777                 NULL,
10778         },
10779 };
10780
10781 /* ether type config for a specific port */
10782 static void
10783 cmd_config_l2_tunnel_eth_type_specific_parsed(
10784         void *parsed_result,
10785         __rte_unused struct cmdline *cl,
10786         __rte_unused void *data)
10787 {
10788         struct cmd_config_l2_tunnel_eth_type_result *res =
10789                  parsed_result;
10790         struct rte_eth_l2_tunnel_conf entry;
10791
10792         if (port_id_is_invalid(res->id, ENABLED_WARN))
10793                 return;
10794
10795         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10796         entry.ether_type = res->eth_type_val;
10797
10798         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10799 }
10800
10801 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10802         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10803         .data = NULL,
10804         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10805         .tokens = {
10806                 (void *)&cmd_config_l2_tunnel_eth_type_port,
10807                 (void *)&cmd_config_l2_tunnel_eth_type_config,
10808                 (void *)&cmd_config_l2_tunnel_eth_type_id,
10809                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10810                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10811                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10812                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10813                 NULL,
10814         },
10815 };
10816
10817 /* Enable/disable l2 tunnel */
10818 struct cmd_config_l2_tunnel_en_dis_result {
10819         cmdline_fixed_string_t port;
10820         cmdline_fixed_string_t config;
10821         cmdline_fixed_string_t all;
10822         portid_t id;
10823         cmdline_fixed_string_t l2_tunnel;
10824         cmdline_fixed_string_t l2_tunnel_type;
10825         cmdline_fixed_string_t en_dis;
10826 };
10827
10828 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10829         TOKEN_STRING_INITIALIZER
10830                 (struct cmd_config_l2_tunnel_en_dis_result,
10831                  port, "port");
10832 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10833         TOKEN_STRING_INITIALIZER
10834                 (struct cmd_config_l2_tunnel_en_dis_result,
10835                  config, "config");
10836 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10837         TOKEN_STRING_INITIALIZER
10838                 (struct cmd_config_l2_tunnel_en_dis_result,
10839                  all, "all");
10840 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10841         TOKEN_NUM_INITIALIZER
10842                 (struct cmd_config_l2_tunnel_en_dis_result,
10843                  id, UINT16);
10844 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10845         TOKEN_STRING_INITIALIZER
10846                 (struct cmd_config_l2_tunnel_en_dis_result,
10847                  l2_tunnel, "l2-tunnel");
10848 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10849         TOKEN_STRING_INITIALIZER
10850                 (struct cmd_config_l2_tunnel_en_dis_result,
10851                  l2_tunnel_type, "E-tag");
10852 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10853         TOKEN_STRING_INITIALIZER
10854                 (struct cmd_config_l2_tunnel_en_dis_result,
10855                  en_dis, "enable#disable");
10856
10857 /* enable/disable l2 tunnel for all ports */
10858 static void
10859 cmd_config_l2_tunnel_en_dis_all_parsed(
10860         void *parsed_result,
10861         __rte_unused struct cmdline *cl,
10862         __rte_unused void *data)
10863 {
10864         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10865         struct rte_eth_l2_tunnel_conf entry;
10866         portid_t pid;
10867         uint8_t en;
10868
10869         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10870
10871         if (!strcmp("enable", res->en_dis))
10872                 en = 1;
10873         else
10874                 en = 0;
10875
10876         RTE_ETH_FOREACH_DEV(pid) {
10877                 rte_eth_dev_l2_tunnel_offload_set(pid,
10878                                                   &entry,
10879                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10880                                                   en);
10881         }
10882 }
10883
10884 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10885         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10886         .data = NULL,
10887         .help_str = "port config all l2-tunnel E-tag enable|disable",
10888         .tokens = {
10889                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10890                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10891                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10892                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10893                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10894                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10895                 NULL,
10896         },
10897 };
10898
10899 /* enable/disable l2 tunnel for a port */
10900 static void
10901 cmd_config_l2_tunnel_en_dis_specific_parsed(
10902         void *parsed_result,
10903         __rte_unused struct cmdline *cl,
10904         __rte_unused void *data)
10905 {
10906         struct cmd_config_l2_tunnel_en_dis_result *res =
10907                 parsed_result;
10908         struct rte_eth_l2_tunnel_conf entry;
10909
10910         if (port_id_is_invalid(res->id, ENABLED_WARN))
10911                 return;
10912
10913         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10914
10915         if (!strcmp("enable", res->en_dis))
10916                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10917                                                   &entry,
10918                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10919                                                   1);
10920         else
10921                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10922                                                   &entry,
10923                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10924                                                   0);
10925 }
10926
10927 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10928         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10929         .data = NULL,
10930         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10931         .tokens = {
10932                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10933                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10934                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10935                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10936                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10937                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10938                 NULL,
10939         },
10940 };
10941
10942 /* E-tag configuration */
10943
10944 /* Common result structure for all E-tag configuration */
10945 struct cmd_config_e_tag_result {
10946         cmdline_fixed_string_t e_tag;
10947         cmdline_fixed_string_t set;
10948         cmdline_fixed_string_t insertion;
10949         cmdline_fixed_string_t stripping;
10950         cmdline_fixed_string_t forwarding;
10951         cmdline_fixed_string_t filter;
10952         cmdline_fixed_string_t add;
10953         cmdline_fixed_string_t del;
10954         cmdline_fixed_string_t on;
10955         cmdline_fixed_string_t off;
10956         cmdline_fixed_string_t on_off;
10957         cmdline_fixed_string_t port_tag_id;
10958         uint32_t port_tag_id_val;
10959         cmdline_fixed_string_t e_tag_id;
10960         uint16_t e_tag_id_val;
10961         cmdline_fixed_string_t dst_pool;
10962         uint8_t dst_pool_val;
10963         cmdline_fixed_string_t port;
10964         portid_t port_id;
10965         cmdline_fixed_string_t vf;
10966         uint8_t vf_id;
10967 };
10968
10969 /* Common CLI fields for all E-tag configuration */
10970 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10971         TOKEN_STRING_INITIALIZER
10972                 (struct cmd_config_e_tag_result,
10973                  e_tag, "E-tag");
10974 cmdline_parse_token_string_t cmd_config_e_tag_set =
10975         TOKEN_STRING_INITIALIZER
10976                 (struct cmd_config_e_tag_result,
10977                  set, "set");
10978 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10979         TOKEN_STRING_INITIALIZER
10980                 (struct cmd_config_e_tag_result,
10981                  insertion, "insertion");
10982 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10983         TOKEN_STRING_INITIALIZER
10984                 (struct cmd_config_e_tag_result,
10985                  stripping, "stripping");
10986 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10987         TOKEN_STRING_INITIALIZER
10988                 (struct cmd_config_e_tag_result,
10989                  forwarding, "forwarding");
10990 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10991         TOKEN_STRING_INITIALIZER
10992                 (struct cmd_config_e_tag_result,
10993                  filter, "filter");
10994 cmdline_parse_token_string_t cmd_config_e_tag_add =
10995         TOKEN_STRING_INITIALIZER
10996                 (struct cmd_config_e_tag_result,
10997                  add, "add");
10998 cmdline_parse_token_string_t cmd_config_e_tag_del =
10999         TOKEN_STRING_INITIALIZER
11000                 (struct cmd_config_e_tag_result,
11001                  del, "del");
11002 cmdline_parse_token_string_t cmd_config_e_tag_on =
11003         TOKEN_STRING_INITIALIZER
11004                 (struct cmd_config_e_tag_result,
11005                  on, "on");
11006 cmdline_parse_token_string_t cmd_config_e_tag_off =
11007         TOKEN_STRING_INITIALIZER
11008                 (struct cmd_config_e_tag_result,
11009                  off, "off");
11010 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11011         TOKEN_STRING_INITIALIZER
11012                 (struct cmd_config_e_tag_result,
11013                  on_off, "on#off");
11014 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11015         TOKEN_STRING_INITIALIZER
11016                 (struct cmd_config_e_tag_result,
11017                  port_tag_id, "port-tag-id");
11018 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11019         TOKEN_NUM_INITIALIZER
11020                 (struct cmd_config_e_tag_result,
11021                  port_tag_id_val, UINT32);
11022 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11023         TOKEN_STRING_INITIALIZER
11024                 (struct cmd_config_e_tag_result,
11025                  e_tag_id, "e-tag-id");
11026 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11027         TOKEN_NUM_INITIALIZER
11028                 (struct cmd_config_e_tag_result,
11029                  e_tag_id_val, UINT16);
11030 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11031         TOKEN_STRING_INITIALIZER
11032                 (struct cmd_config_e_tag_result,
11033                  dst_pool, "dst-pool");
11034 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11035         TOKEN_NUM_INITIALIZER
11036                 (struct cmd_config_e_tag_result,
11037                  dst_pool_val, UINT8);
11038 cmdline_parse_token_string_t cmd_config_e_tag_port =
11039         TOKEN_STRING_INITIALIZER
11040                 (struct cmd_config_e_tag_result,
11041                  port, "port");
11042 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11043         TOKEN_NUM_INITIALIZER
11044                 (struct cmd_config_e_tag_result,
11045                  port_id, UINT16);
11046 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11047         TOKEN_STRING_INITIALIZER
11048                 (struct cmd_config_e_tag_result,
11049                  vf, "vf");
11050 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11051         TOKEN_NUM_INITIALIZER
11052                 (struct cmd_config_e_tag_result,
11053                  vf_id, UINT8);
11054
11055 /* E-tag insertion configuration */
11056 static void
11057 cmd_config_e_tag_insertion_en_parsed(
11058         void *parsed_result,
11059         __rte_unused struct cmdline *cl,
11060         __rte_unused void *data)
11061 {
11062         struct cmd_config_e_tag_result *res =
11063                 parsed_result;
11064         struct rte_eth_l2_tunnel_conf entry;
11065
11066         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11067                 return;
11068
11069         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11070         entry.tunnel_id = res->port_tag_id_val;
11071         entry.vf_id = res->vf_id;
11072         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11073                                           &entry,
11074                                           ETH_L2_TUNNEL_INSERTION_MASK,
11075                                           1);
11076 }
11077
11078 static void
11079 cmd_config_e_tag_insertion_dis_parsed(
11080         void *parsed_result,
11081         __rte_unused struct cmdline *cl,
11082         __rte_unused void *data)
11083 {
11084         struct cmd_config_e_tag_result *res =
11085                 parsed_result;
11086         struct rte_eth_l2_tunnel_conf entry;
11087
11088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11089                 return;
11090
11091         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11092         entry.vf_id = res->vf_id;
11093
11094         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11095                                           &entry,
11096                                           ETH_L2_TUNNEL_INSERTION_MASK,
11097                                           0);
11098 }
11099
11100 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11101         .f = cmd_config_e_tag_insertion_en_parsed,
11102         .data = NULL,
11103         .help_str = "E-tag ... : E-tag insertion enable",
11104         .tokens = {
11105                 (void *)&cmd_config_e_tag_e_tag,
11106                 (void *)&cmd_config_e_tag_set,
11107                 (void *)&cmd_config_e_tag_insertion,
11108                 (void *)&cmd_config_e_tag_on,
11109                 (void *)&cmd_config_e_tag_port_tag_id,
11110                 (void *)&cmd_config_e_tag_port_tag_id_val,
11111                 (void *)&cmd_config_e_tag_port,
11112                 (void *)&cmd_config_e_tag_port_id,
11113                 (void *)&cmd_config_e_tag_vf,
11114                 (void *)&cmd_config_e_tag_vf_id,
11115                 NULL,
11116         },
11117 };
11118
11119 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11120         .f = cmd_config_e_tag_insertion_dis_parsed,
11121         .data = NULL,
11122         .help_str = "E-tag ... : E-tag insertion disable",
11123         .tokens = {
11124                 (void *)&cmd_config_e_tag_e_tag,
11125                 (void *)&cmd_config_e_tag_set,
11126                 (void *)&cmd_config_e_tag_insertion,
11127                 (void *)&cmd_config_e_tag_off,
11128                 (void *)&cmd_config_e_tag_port,
11129                 (void *)&cmd_config_e_tag_port_id,
11130                 (void *)&cmd_config_e_tag_vf,
11131                 (void *)&cmd_config_e_tag_vf_id,
11132                 NULL,
11133         },
11134 };
11135
11136 /* E-tag stripping configuration */
11137 static void
11138 cmd_config_e_tag_stripping_parsed(
11139         void *parsed_result,
11140         __rte_unused struct cmdline *cl,
11141         __rte_unused void *data)
11142 {
11143         struct cmd_config_e_tag_result *res =
11144                 parsed_result;
11145         struct rte_eth_l2_tunnel_conf entry;
11146
11147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11148                 return;
11149
11150         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11151
11152         if (!strcmp(res->on_off, "on"))
11153                 rte_eth_dev_l2_tunnel_offload_set
11154                         (res->port_id,
11155                          &entry,
11156                          ETH_L2_TUNNEL_STRIPPING_MASK,
11157                          1);
11158         else
11159                 rte_eth_dev_l2_tunnel_offload_set
11160                         (res->port_id,
11161                          &entry,
11162                          ETH_L2_TUNNEL_STRIPPING_MASK,
11163                          0);
11164 }
11165
11166 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11167         .f = cmd_config_e_tag_stripping_parsed,
11168         .data = NULL,
11169         .help_str = "E-tag ... : E-tag stripping enable/disable",
11170         .tokens = {
11171                 (void *)&cmd_config_e_tag_e_tag,
11172                 (void *)&cmd_config_e_tag_set,
11173                 (void *)&cmd_config_e_tag_stripping,
11174                 (void *)&cmd_config_e_tag_on_off,
11175                 (void *)&cmd_config_e_tag_port,
11176                 (void *)&cmd_config_e_tag_port_id,
11177                 NULL,
11178         },
11179 };
11180
11181 /* E-tag forwarding configuration */
11182 static void
11183 cmd_config_e_tag_forwarding_parsed(
11184         void *parsed_result,
11185         __rte_unused struct cmdline *cl,
11186         __rte_unused void *data)
11187 {
11188         struct cmd_config_e_tag_result *res = parsed_result;
11189         struct rte_eth_l2_tunnel_conf entry;
11190
11191         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11192                 return;
11193
11194         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11195
11196         if (!strcmp(res->on_off, "on"))
11197                 rte_eth_dev_l2_tunnel_offload_set
11198                         (res->port_id,
11199                          &entry,
11200                          ETH_L2_TUNNEL_FORWARDING_MASK,
11201                          1);
11202         else
11203                 rte_eth_dev_l2_tunnel_offload_set
11204                         (res->port_id,
11205                          &entry,
11206                          ETH_L2_TUNNEL_FORWARDING_MASK,
11207                          0);
11208 }
11209
11210 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11211         .f = cmd_config_e_tag_forwarding_parsed,
11212         .data = NULL,
11213         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11214         .tokens = {
11215                 (void *)&cmd_config_e_tag_e_tag,
11216                 (void *)&cmd_config_e_tag_set,
11217                 (void *)&cmd_config_e_tag_forwarding,
11218                 (void *)&cmd_config_e_tag_on_off,
11219                 (void *)&cmd_config_e_tag_port,
11220                 (void *)&cmd_config_e_tag_port_id,
11221                 NULL,
11222         },
11223 };
11224
11225 /* vf vlan anti spoof configuration */
11226
11227 /* Common result structure for vf vlan anti spoof */
11228 struct cmd_vf_vlan_anti_spoof_result {
11229         cmdline_fixed_string_t set;
11230         cmdline_fixed_string_t vf;
11231         cmdline_fixed_string_t vlan;
11232         cmdline_fixed_string_t antispoof;
11233         portid_t port_id;
11234         uint32_t vf_id;
11235         cmdline_fixed_string_t on_off;
11236 };
11237
11238 /* Common CLI fields for vf vlan anti spoof enable disable */
11239 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11240         TOKEN_STRING_INITIALIZER
11241                 (struct cmd_vf_vlan_anti_spoof_result,
11242                  set, "set");
11243 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11244         TOKEN_STRING_INITIALIZER
11245                 (struct cmd_vf_vlan_anti_spoof_result,
11246                  vf, "vf");
11247 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11248         TOKEN_STRING_INITIALIZER
11249                 (struct cmd_vf_vlan_anti_spoof_result,
11250                  vlan, "vlan");
11251 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11252         TOKEN_STRING_INITIALIZER
11253                 (struct cmd_vf_vlan_anti_spoof_result,
11254                  antispoof, "antispoof");
11255 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11256         TOKEN_NUM_INITIALIZER
11257                 (struct cmd_vf_vlan_anti_spoof_result,
11258                  port_id, UINT16);
11259 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11260         TOKEN_NUM_INITIALIZER
11261                 (struct cmd_vf_vlan_anti_spoof_result,
11262                  vf_id, UINT32);
11263 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11264         TOKEN_STRING_INITIALIZER
11265                 (struct cmd_vf_vlan_anti_spoof_result,
11266                  on_off, "on#off");
11267
11268 static void
11269 cmd_set_vf_vlan_anti_spoof_parsed(
11270         void *parsed_result,
11271         __rte_unused struct cmdline *cl,
11272         __rte_unused void *data)
11273 {
11274         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11275         int ret = -ENOTSUP;
11276
11277         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11278
11279         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11280                 return;
11281
11282 #ifdef RTE_NET_IXGBE
11283         if (ret == -ENOTSUP)
11284                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11285                                 res->vf_id, is_on);
11286 #endif
11287 #ifdef RTE_NET_I40E
11288         if (ret == -ENOTSUP)
11289                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11290                                 res->vf_id, is_on);
11291 #endif
11292 #ifdef RTE_NET_BNXT
11293         if (ret == -ENOTSUP)
11294                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11295                                 res->vf_id, is_on);
11296 #endif
11297
11298         switch (ret) {
11299         case 0:
11300                 break;
11301         case -EINVAL:
11302                 printf("invalid vf_id %d\n", res->vf_id);
11303                 break;
11304         case -ENODEV:
11305                 printf("invalid port_id %d\n", res->port_id);
11306                 break;
11307         case -ENOTSUP:
11308                 printf("function not implemented\n");
11309                 break;
11310         default:
11311                 printf("programming error: (%s)\n", strerror(-ret));
11312         }
11313 }
11314
11315 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11316         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11317         .data = NULL,
11318         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11319         .tokens = {
11320                 (void *)&cmd_vf_vlan_anti_spoof_set,
11321                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11322                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11323                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11324                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11325                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11326                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11327                 NULL,
11328         },
11329 };
11330
11331 /* vf mac anti spoof configuration */
11332
11333 /* Common result structure for vf mac anti spoof */
11334 struct cmd_vf_mac_anti_spoof_result {
11335         cmdline_fixed_string_t set;
11336         cmdline_fixed_string_t vf;
11337         cmdline_fixed_string_t mac;
11338         cmdline_fixed_string_t antispoof;
11339         portid_t port_id;
11340         uint32_t vf_id;
11341         cmdline_fixed_string_t on_off;
11342 };
11343
11344 /* Common CLI fields for vf mac anti spoof enable disable */
11345 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11346         TOKEN_STRING_INITIALIZER
11347                 (struct cmd_vf_mac_anti_spoof_result,
11348                  set, "set");
11349 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11350         TOKEN_STRING_INITIALIZER
11351                 (struct cmd_vf_mac_anti_spoof_result,
11352                  vf, "vf");
11353 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11354         TOKEN_STRING_INITIALIZER
11355                 (struct cmd_vf_mac_anti_spoof_result,
11356                  mac, "mac");
11357 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11358         TOKEN_STRING_INITIALIZER
11359                 (struct cmd_vf_mac_anti_spoof_result,
11360                  antispoof, "antispoof");
11361 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11362         TOKEN_NUM_INITIALIZER
11363                 (struct cmd_vf_mac_anti_spoof_result,
11364                  port_id, UINT16);
11365 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11366         TOKEN_NUM_INITIALIZER
11367                 (struct cmd_vf_mac_anti_spoof_result,
11368                  vf_id, UINT32);
11369 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11370         TOKEN_STRING_INITIALIZER
11371                 (struct cmd_vf_mac_anti_spoof_result,
11372                  on_off, "on#off");
11373
11374 static void
11375 cmd_set_vf_mac_anti_spoof_parsed(
11376         void *parsed_result,
11377         __rte_unused struct cmdline *cl,
11378         __rte_unused void *data)
11379 {
11380         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11381         int ret = -ENOTSUP;
11382
11383         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11384
11385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11386                 return;
11387
11388 #ifdef RTE_NET_IXGBE
11389         if (ret == -ENOTSUP)
11390                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11391                         res->vf_id, is_on);
11392 #endif
11393 #ifdef RTE_NET_I40E
11394         if (ret == -ENOTSUP)
11395                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11396                         res->vf_id, is_on);
11397 #endif
11398 #ifdef RTE_NET_BNXT
11399         if (ret == -ENOTSUP)
11400                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11401                         res->vf_id, is_on);
11402 #endif
11403
11404         switch (ret) {
11405         case 0:
11406                 break;
11407         case -EINVAL:
11408                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11409                 break;
11410         case -ENODEV:
11411                 printf("invalid port_id %d\n", res->port_id);
11412                 break;
11413         case -ENOTSUP:
11414                 printf("function not implemented\n");
11415                 break;
11416         default:
11417                 printf("programming error: (%s)\n", strerror(-ret));
11418         }
11419 }
11420
11421 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11422         .f = cmd_set_vf_mac_anti_spoof_parsed,
11423         .data = NULL,
11424         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11425         .tokens = {
11426                 (void *)&cmd_vf_mac_anti_spoof_set,
11427                 (void *)&cmd_vf_mac_anti_spoof_vf,
11428                 (void *)&cmd_vf_mac_anti_spoof_mac,
11429                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11430                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11431                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11432                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11433                 NULL,
11434         },
11435 };
11436
11437 /* vf vlan strip queue configuration */
11438
11439 /* Common result structure for vf mac anti spoof */
11440 struct cmd_vf_vlan_stripq_result {
11441         cmdline_fixed_string_t set;
11442         cmdline_fixed_string_t vf;
11443         cmdline_fixed_string_t vlan;
11444         cmdline_fixed_string_t stripq;
11445         portid_t port_id;
11446         uint16_t vf_id;
11447         cmdline_fixed_string_t on_off;
11448 };
11449
11450 /* Common CLI fields for vf vlan strip enable disable */
11451 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11452         TOKEN_STRING_INITIALIZER
11453                 (struct cmd_vf_vlan_stripq_result,
11454                  set, "set");
11455 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11456         TOKEN_STRING_INITIALIZER
11457                 (struct cmd_vf_vlan_stripq_result,
11458                  vf, "vf");
11459 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11460         TOKEN_STRING_INITIALIZER
11461                 (struct cmd_vf_vlan_stripq_result,
11462                  vlan, "vlan");
11463 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11464         TOKEN_STRING_INITIALIZER
11465                 (struct cmd_vf_vlan_stripq_result,
11466                  stripq, "stripq");
11467 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11468         TOKEN_NUM_INITIALIZER
11469                 (struct cmd_vf_vlan_stripq_result,
11470                  port_id, UINT16);
11471 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11472         TOKEN_NUM_INITIALIZER
11473                 (struct cmd_vf_vlan_stripq_result,
11474                  vf_id, UINT16);
11475 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11476         TOKEN_STRING_INITIALIZER
11477                 (struct cmd_vf_vlan_stripq_result,
11478                  on_off, "on#off");
11479
11480 static void
11481 cmd_set_vf_vlan_stripq_parsed(
11482         void *parsed_result,
11483         __rte_unused struct cmdline *cl,
11484         __rte_unused void *data)
11485 {
11486         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11487         int ret = -ENOTSUP;
11488
11489         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11490
11491         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11492                 return;
11493
11494 #ifdef RTE_NET_IXGBE
11495         if (ret == -ENOTSUP)
11496                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11497                         res->vf_id, is_on);
11498 #endif
11499 #ifdef RTE_NET_I40E
11500         if (ret == -ENOTSUP)
11501                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11502                         res->vf_id, is_on);
11503 #endif
11504 #ifdef RTE_NET_BNXT
11505         if (ret == -ENOTSUP)
11506                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11507                         res->vf_id, is_on);
11508 #endif
11509
11510         switch (ret) {
11511         case 0:
11512                 break;
11513         case -EINVAL:
11514                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11515                 break;
11516         case -ENODEV:
11517                 printf("invalid port_id %d\n", res->port_id);
11518                 break;
11519         case -ENOTSUP:
11520                 printf("function not implemented\n");
11521                 break;
11522         default:
11523                 printf("programming error: (%s)\n", strerror(-ret));
11524         }
11525 }
11526
11527 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11528         .f = cmd_set_vf_vlan_stripq_parsed,
11529         .data = NULL,
11530         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11531         .tokens = {
11532                 (void *)&cmd_vf_vlan_stripq_set,
11533                 (void *)&cmd_vf_vlan_stripq_vf,
11534                 (void *)&cmd_vf_vlan_stripq_vlan,
11535                 (void *)&cmd_vf_vlan_stripq_stripq,
11536                 (void *)&cmd_vf_vlan_stripq_port_id,
11537                 (void *)&cmd_vf_vlan_stripq_vf_id,
11538                 (void *)&cmd_vf_vlan_stripq_on_off,
11539                 NULL,
11540         },
11541 };
11542
11543 /* vf vlan insert configuration */
11544
11545 /* Common result structure for vf vlan insert */
11546 struct cmd_vf_vlan_insert_result {
11547         cmdline_fixed_string_t set;
11548         cmdline_fixed_string_t vf;
11549         cmdline_fixed_string_t vlan;
11550         cmdline_fixed_string_t insert;
11551         portid_t port_id;
11552         uint16_t vf_id;
11553         uint16_t vlan_id;
11554 };
11555
11556 /* Common CLI fields for vf vlan insert enable disable */
11557 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11558         TOKEN_STRING_INITIALIZER
11559                 (struct cmd_vf_vlan_insert_result,
11560                  set, "set");
11561 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11562         TOKEN_STRING_INITIALIZER
11563                 (struct cmd_vf_vlan_insert_result,
11564                  vf, "vf");
11565 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11566         TOKEN_STRING_INITIALIZER
11567                 (struct cmd_vf_vlan_insert_result,
11568                  vlan, "vlan");
11569 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11570         TOKEN_STRING_INITIALIZER
11571                 (struct cmd_vf_vlan_insert_result,
11572                  insert, "insert");
11573 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11574         TOKEN_NUM_INITIALIZER
11575                 (struct cmd_vf_vlan_insert_result,
11576                  port_id, UINT16);
11577 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11578         TOKEN_NUM_INITIALIZER
11579                 (struct cmd_vf_vlan_insert_result,
11580                  vf_id, UINT16);
11581 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11582         TOKEN_NUM_INITIALIZER
11583                 (struct cmd_vf_vlan_insert_result,
11584                  vlan_id, UINT16);
11585
11586 static void
11587 cmd_set_vf_vlan_insert_parsed(
11588         void *parsed_result,
11589         __rte_unused struct cmdline *cl,
11590         __rte_unused void *data)
11591 {
11592         struct cmd_vf_vlan_insert_result *res = parsed_result;
11593         int ret = -ENOTSUP;
11594
11595         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11596                 return;
11597
11598 #ifdef RTE_NET_IXGBE
11599         if (ret == -ENOTSUP)
11600                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11601                         res->vlan_id);
11602 #endif
11603 #ifdef RTE_NET_I40E
11604         if (ret == -ENOTSUP)
11605                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11606                         res->vlan_id);
11607 #endif
11608 #ifdef RTE_NET_BNXT
11609         if (ret == -ENOTSUP)
11610                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11611                         res->vlan_id);
11612 #endif
11613
11614         switch (ret) {
11615         case 0:
11616                 break;
11617         case -EINVAL:
11618                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11619                 break;
11620         case -ENODEV:
11621                 printf("invalid port_id %d\n", res->port_id);
11622                 break;
11623         case -ENOTSUP:
11624                 printf("function not implemented\n");
11625                 break;
11626         default:
11627                 printf("programming error: (%s)\n", strerror(-ret));
11628         }
11629 }
11630
11631 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11632         .f = cmd_set_vf_vlan_insert_parsed,
11633         .data = NULL,
11634         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11635         .tokens = {
11636                 (void *)&cmd_vf_vlan_insert_set,
11637                 (void *)&cmd_vf_vlan_insert_vf,
11638                 (void *)&cmd_vf_vlan_insert_vlan,
11639                 (void *)&cmd_vf_vlan_insert_insert,
11640                 (void *)&cmd_vf_vlan_insert_port_id,
11641                 (void *)&cmd_vf_vlan_insert_vf_id,
11642                 (void *)&cmd_vf_vlan_insert_vlan_id,
11643                 NULL,
11644         },
11645 };
11646
11647 /* tx loopback configuration */
11648
11649 /* Common result structure for tx loopback */
11650 struct cmd_tx_loopback_result {
11651         cmdline_fixed_string_t set;
11652         cmdline_fixed_string_t tx;
11653         cmdline_fixed_string_t loopback;
11654         portid_t port_id;
11655         cmdline_fixed_string_t on_off;
11656 };
11657
11658 /* Common CLI fields for tx loopback enable disable */
11659 cmdline_parse_token_string_t cmd_tx_loopback_set =
11660         TOKEN_STRING_INITIALIZER
11661                 (struct cmd_tx_loopback_result,
11662                  set, "set");
11663 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11664         TOKEN_STRING_INITIALIZER
11665                 (struct cmd_tx_loopback_result,
11666                  tx, "tx");
11667 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11668         TOKEN_STRING_INITIALIZER
11669                 (struct cmd_tx_loopback_result,
11670                  loopback, "loopback");
11671 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11672         TOKEN_NUM_INITIALIZER
11673                 (struct cmd_tx_loopback_result,
11674                  port_id, UINT16);
11675 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11676         TOKEN_STRING_INITIALIZER
11677                 (struct cmd_tx_loopback_result,
11678                  on_off, "on#off");
11679
11680 static void
11681 cmd_set_tx_loopback_parsed(
11682         void *parsed_result,
11683         __rte_unused struct cmdline *cl,
11684         __rte_unused void *data)
11685 {
11686         struct cmd_tx_loopback_result *res = parsed_result;
11687         int ret = -ENOTSUP;
11688
11689         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11690
11691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11692                 return;
11693
11694 #ifdef RTE_NET_IXGBE
11695         if (ret == -ENOTSUP)
11696                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11697 #endif
11698 #ifdef RTE_NET_I40E
11699         if (ret == -ENOTSUP)
11700                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11701 #endif
11702 #ifdef RTE_NET_BNXT
11703         if (ret == -ENOTSUP)
11704                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11705 #endif
11706 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11707         if (ret == -ENOTSUP)
11708                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11709 #endif
11710
11711         switch (ret) {
11712         case 0:
11713                 break;
11714         case -EINVAL:
11715                 printf("invalid is_on %d\n", is_on);
11716                 break;
11717         case -ENODEV:
11718                 printf("invalid port_id %d\n", res->port_id);
11719                 break;
11720         case -ENOTSUP:
11721                 printf("function not implemented\n");
11722                 break;
11723         default:
11724                 printf("programming error: (%s)\n", strerror(-ret));
11725         }
11726 }
11727
11728 cmdline_parse_inst_t cmd_set_tx_loopback = {
11729         .f = cmd_set_tx_loopback_parsed,
11730         .data = NULL,
11731         .help_str = "set tx loopback <port_id> on|off",
11732         .tokens = {
11733                 (void *)&cmd_tx_loopback_set,
11734                 (void *)&cmd_tx_loopback_tx,
11735                 (void *)&cmd_tx_loopback_loopback,
11736                 (void *)&cmd_tx_loopback_port_id,
11737                 (void *)&cmd_tx_loopback_on_off,
11738                 NULL,
11739         },
11740 };
11741
11742 /* all queues drop enable configuration */
11743
11744 /* Common result structure for all queues drop enable */
11745 struct cmd_all_queues_drop_en_result {
11746         cmdline_fixed_string_t set;
11747         cmdline_fixed_string_t all;
11748         cmdline_fixed_string_t queues;
11749         cmdline_fixed_string_t drop;
11750         portid_t port_id;
11751         cmdline_fixed_string_t on_off;
11752 };
11753
11754 /* Common CLI fields for tx loopback enable disable */
11755 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11756         TOKEN_STRING_INITIALIZER
11757                 (struct cmd_all_queues_drop_en_result,
11758                  set, "set");
11759 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11760         TOKEN_STRING_INITIALIZER
11761                 (struct cmd_all_queues_drop_en_result,
11762                  all, "all");
11763 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11764         TOKEN_STRING_INITIALIZER
11765                 (struct cmd_all_queues_drop_en_result,
11766                  queues, "queues");
11767 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11768         TOKEN_STRING_INITIALIZER
11769                 (struct cmd_all_queues_drop_en_result,
11770                  drop, "drop");
11771 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11772         TOKEN_NUM_INITIALIZER
11773                 (struct cmd_all_queues_drop_en_result,
11774                  port_id, UINT16);
11775 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11776         TOKEN_STRING_INITIALIZER
11777                 (struct cmd_all_queues_drop_en_result,
11778                  on_off, "on#off");
11779
11780 static void
11781 cmd_set_all_queues_drop_en_parsed(
11782         void *parsed_result,
11783         __rte_unused struct cmdline *cl,
11784         __rte_unused void *data)
11785 {
11786         struct cmd_all_queues_drop_en_result *res = parsed_result;
11787         int ret = -ENOTSUP;
11788         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11789
11790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11791                 return;
11792
11793 #ifdef RTE_NET_IXGBE
11794         if (ret == -ENOTSUP)
11795                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11796 #endif
11797 #ifdef RTE_NET_BNXT
11798         if (ret == -ENOTSUP)
11799                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11800 #endif
11801         switch (ret) {
11802         case 0:
11803                 break;
11804         case -EINVAL:
11805                 printf("invalid is_on %d\n", is_on);
11806                 break;
11807         case -ENODEV:
11808                 printf("invalid port_id %d\n", res->port_id);
11809                 break;
11810         case -ENOTSUP:
11811                 printf("function not implemented\n");
11812                 break;
11813         default:
11814                 printf("programming error: (%s)\n", strerror(-ret));
11815         }
11816 }
11817
11818 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11819         .f = cmd_set_all_queues_drop_en_parsed,
11820         .data = NULL,
11821         .help_str = "set all queues drop <port_id> on|off",
11822         .tokens = {
11823                 (void *)&cmd_all_queues_drop_en_set,
11824                 (void *)&cmd_all_queues_drop_en_all,
11825                 (void *)&cmd_all_queues_drop_en_queues,
11826                 (void *)&cmd_all_queues_drop_en_drop,
11827                 (void *)&cmd_all_queues_drop_en_port_id,
11828                 (void *)&cmd_all_queues_drop_en_on_off,
11829                 NULL,
11830         },
11831 };
11832
11833 /* vf split drop enable configuration */
11834
11835 /* Common result structure for vf split drop enable */
11836 struct cmd_vf_split_drop_en_result {
11837         cmdline_fixed_string_t set;
11838         cmdline_fixed_string_t vf;
11839         cmdline_fixed_string_t split;
11840         cmdline_fixed_string_t drop;
11841         portid_t port_id;
11842         uint16_t vf_id;
11843         cmdline_fixed_string_t on_off;
11844 };
11845
11846 /* Common CLI fields for vf split drop enable disable */
11847 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_vf_split_drop_en_result,
11850                  set, "set");
11851 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11852         TOKEN_STRING_INITIALIZER
11853                 (struct cmd_vf_split_drop_en_result,
11854                  vf, "vf");
11855 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11856         TOKEN_STRING_INITIALIZER
11857                 (struct cmd_vf_split_drop_en_result,
11858                  split, "split");
11859 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11860         TOKEN_STRING_INITIALIZER
11861                 (struct cmd_vf_split_drop_en_result,
11862                  drop, "drop");
11863 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11864         TOKEN_NUM_INITIALIZER
11865                 (struct cmd_vf_split_drop_en_result,
11866                  port_id, UINT16);
11867 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11868         TOKEN_NUM_INITIALIZER
11869                 (struct cmd_vf_split_drop_en_result,
11870                  vf_id, UINT16);
11871 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_vf_split_drop_en_result,
11874                  on_off, "on#off");
11875
11876 static void
11877 cmd_set_vf_split_drop_en_parsed(
11878         void *parsed_result,
11879         __rte_unused struct cmdline *cl,
11880         __rte_unused void *data)
11881 {
11882         struct cmd_vf_split_drop_en_result *res = parsed_result;
11883         int ret = -ENOTSUP;
11884         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11885
11886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11887                 return;
11888
11889 #ifdef RTE_NET_IXGBE
11890         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11891                         is_on);
11892 #endif
11893         switch (ret) {
11894         case 0:
11895                 break;
11896         case -EINVAL:
11897                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11898                 break;
11899         case -ENODEV:
11900                 printf("invalid port_id %d\n", res->port_id);
11901                 break;
11902         case -ENOTSUP:
11903                 printf("not supported on port %d\n", res->port_id);
11904                 break;
11905         default:
11906                 printf("programming error: (%s)\n", strerror(-ret));
11907         }
11908 }
11909
11910 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11911         .f = cmd_set_vf_split_drop_en_parsed,
11912         .data = NULL,
11913         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11914         .tokens = {
11915                 (void *)&cmd_vf_split_drop_en_set,
11916                 (void *)&cmd_vf_split_drop_en_vf,
11917                 (void *)&cmd_vf_split_drop_en_split,
11918                 (void *)&cmd_vf_split_drop_en_drop,
11919                 (void *)&cmd_vf_split_drop_en_port_id,
11920                 (void *)&cmd_vf_split_drop_en_vf_id,
11921                 (void *)&cmd_vf_split_drop_en_on_off,
11922                 NULL,
11923         },
11924 };
11925
11926 /* vf mac address configuration */
11927
11928 /* Common result structure for vf mac address */
11929 struct cmd_set_vf_mac_addr_result {
11930         cmdline_fixed_string_t set;
11931         cmdline_fixed_string_t vf;
11932         cmdline_fixed_string_t mac;
11933         cmdline_fixed_string_t addr;
11934         portid_t port_id;
11935         uint16_t vf_id;
11936         struct rte_ether_addr mac_addr;
11937
11938 };
11939
11940 /* Common CLI fields for vf split drop enable disable */
11941 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11942         TOKEN_STRING_INITIALIZER
11943                 (struct cmd_set_vf_mac_addr_result,
11944                  set, "set");
11945 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11946         TOKEN_STRING_INITIALIZER
11947                 (struct cmd_set_vf_mac_addr_result,
11948                  vf, "vf");
11949 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11950         TOKEN_STRING_INITIALIZER
11951                 (struct cmd_set_vf_mac_addr_result,
11952                  mac, "mac");
11953 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11954         TOKEN_STRING_INITIALIZER
11955                 (struct cmd_set_vf_mac_addr_result,
11956                  addr, "addr");
11957 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11958         TOKEN_NUM_INITIALIZER
11959                 (struct cmd_set_vf_mac_addr_result,
11960                  port_id, UINT16);
11961 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11962         TOKEN_NUM_INITIALIZER
11963                 (struct cmd_set_vf_mac_addr_result,
11964                  vf_id, UINT16);
11965 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11966         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11967                  mac_addr);
11968
11969 static void
11970 cmd_set_vf_mac_addr_parsed(
11971         void *parsed_result,
11972         __rte_unused struct cmdline *cl,
11973         __rte_unused void *data)
11974 {
11975         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11976         int ret = -ENOTSUP;
11977
11978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11979                 return;
11980
11981 #ifdef RTE_NET_IXGBE
11982         if (ret == -ENOTSUP)
11983                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11984                                 &res->mac_addr);
11985 #endif
11986 #ifdef RTE_NET_I40E
11987         if (ret == -ENOTSUP)
11988                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11989                                 &res->mac_addr);
11990 #endif
11991 #ifdef RTE_NET_BNXT
11992         if (ret == -ENOTSUP)
11993                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11994                                 &res->mac_addr);
11995 #endif
11996
11997         switch (ret) {
11998         case 0:
11999                 break;
12000         case -EINVAL:
12001                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12002                 break;
12003         case -ENODEV:
12004                 printf("invalid port_id %d\n", res->port_id);
12005                 break;
12006         case -ENOTSUP:
12007                 printf("function not implemented\n");
12008                 break;
12009         default:
12010                 printf("programming error: (%s)\n", strerror(-ret));
12011         }
12012 }
12013
12014 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12015         .f = cmd_set_vf_mac_addr_parsed,
12016         .data = NULL,
12017         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12018         .tokens = {
12019                 (void *)&cmd_set_vf_mac_addr_set,
12020                 (void *)&cmd_set_vf_mac_addr_vf,
12021                 (void *)&cmd_set_vf_mac_addr_mac,
12022                 (void *)&cmd_set_vf_mac_addr_addr,
12023                 (void *)&cmd_set_vf_mac_addr_port_id,
12024                 (void *)&cmd_set_vf_mac_addr_vf_id,
12025                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12026                 NULL,
12027         },
12028 };
12029
12030 /* MACsec configuration */
12031
12032 /* Common result structure for MACsec offload enable */
12033 struct cmd_macsec_offload_on_result {
12034         cmdline_fixed_string_t set;
12035         cmdline_fixed_string_t macsec;
12036         cmdline_fixed_string_t offload;
12037         portid_t port_id;
12038         cmdline_fixed_string_t on;
12039         cmdline_fixed_string_t encrypt;
12040         cmdline_fixed_string_t en_on_off;
12041         cmdline_fixed_string_t replay_protect;
12042         cmdline_fixed_string_t rp_on_off;
12043 };
12044
12045 /* Common CLI fields for MACsec offload disable */
12046 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12047         TOKEN_STRING_INITIALIZER
12048                 (struct cmd_macsec_offload_on_result,
12049                  set, "set");
12050 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12051         TOKEN_STRING_INITIALIZER
12052                 (struct cmd_macsec_offload_on_result,
12053                  macsec, "macsec");
12054 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12055         TOKEN_STRING_INITIALIZER
12056                 (struct cmd_macsec_offload_on_result,
12057                  offload, "offload");
12058 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12059         TOKEN_NUM_INITIALIZER
12060                 (struct cmd_macsec_offload_on_result,
12061                  port_id, UINT16);
12062 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12063         TOKEN_STRING_INITIALIZER
12064                 (struct cmd_macsec_offload_on_result,
12065                  on, "on");
12066 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12067         TOKEN_STRING_INITIALIZER
12068                 (struct cmd_macsec_offload_on_result,
12069                  encrypt, "encrypt");
12070 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12071         TOKEN_STRING_INITIALIZER
12072                 (struct cmd_macsec_offload_on_result,
12073                  en_on_off, "on#off");
12074 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12075         TOKEN_STRING_INITIALIZER
12076                 (struct cmd_macsec_offload_on_result,
12077                  replay_protect, "replay-protect");
12078 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12079         TOKEN_STRING_INITIALIZER
12080                 (struct cmd_macsec_offload_on_result,
12081                  rp_on_off, "on#off");
12082
12083 static void
12084 cmd_set_macsec_offload_on_parsed(
12085         void *parsed_result,
12086         __rte_unused struct cmdline *cl,
12087         __rte_unused void *data)
12088 {
12089         struct cmd_macsec_offload_on_result *res = parsed_result;
12090         int ret = -ENOTSUP;
12091         portid_t port_id = res->port_id;
12092         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12093         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12094         struct rte_eth_dev_info dev_info;
12095
12096         if (port_id_is_invalid(port_id, ENABLED_WARN))
12097                 return;
12098         if (!port_is_stopped(port_id)) {
12099                 printf("Please stop port %d first\n", port_id);
12100                 return;
12101         }
12102
12103         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12104         if (ret != 0)
12105                 return;
12106
12107         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
12108 #ifdef RTE_NET_IXGBE
12109                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12110 #endif
12111         }
12112         RTE_SET_USED(en);
12113         RTE_SET_USED(rp);
12114
12115         switch (ret) {
12116         case 0:
12117                 ports[port_id].dev_conf.txmode.offloads |=
12118                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
12119                 cmd_reconfig_device_queue(port_id, 1, 1);
12120                 break;
12121         case -ENODEV:
12122                 printf("invalid port_id %d\n", port_id);
12123                 break;
12124         case -ENOTSUP:
12125                 printf("not supported on port %d\n", port_id);
12126                 break;
12127         default:
12128                 printf("programming error: (%s)\n", strerror(-ret));
12129         }
12130 }
12131
12132 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12133         .f = cmd_set_macsec_offload_on_parsed,
12134         .data = NULL,
12135         .help_str = "set macsec offload <port_id> on "
12136                 "encrypt on|off replay-protect on|off",
12137         .tokens = {
12138                 (void *)&cmd_macsec_offload_on_set,
12139                 (void *)&cmd_macsec_offload_on_macsec,
12140                 (void *)&cmd_macsec_offload_on_offload,
12141                 (void *)&cmd_macsec_offload_on_port_id,
12142                 (void *)&cmd_macsec_offload_on_on,
12143                 (void *)&cmd_macsec_offload_on_encrypt,
12144                 (void *)&cmd_macsec_offload_on_en_on_off,
12145                 (void *)&cmd_macsec_offload_on_replay_protect,
12146                 (void *)&cmd_macsec_offload_on_rp_on_off,
12147                 NULL,
12148         },
12149 };
12150
12151 /* Common result structure for MACsec offload disable */
12152 struct cmd_macsec_offload_off_result {
12153         cmdline_fixed_string_t set;
12154         cmdline_fixed_string_t macsec;
12155         cmdline_fixed_string_t offload;
12156         portid_t port_id;
12157         cmdline_fixed_string_t off;
12158 };
12159
12160 /* Common CLI fields for MACsec offload disable */
12161 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12162         TOKEN_STRING_INITIALIZER
12163                 (struct cmd_macsec_offload_off_result,
12164                  set, "set");
12165 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12166         TOKEN_STRING_INITIALIZER
12167                 (struct cmd_macsec_offload_off_result,
12168                  macsec, "macsec");
12169 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_macsec_offload_off_result,
12172                  offload, "offload");
12173 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12174         TOKEN_NUM_INITIALIZER
12175                 (struct cmd_macsec_offload_off_result,
12176                  port_id, UINT16);
12177 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_macsec_offload_off_result,
12180                  off, "off");
12181
12182 static void
12183 cmd_set_macsec_offload_off_parsed(
12184         void *parsed_result,
12185         __rte_unused struct cmdline *cl,
12186         __rte_unused void *data)
12187 {
12188         struct cmd_macsec_offload_off_result *res = parsed_result;
12189         int ret = -ENOTSUP;
12190         struct rte_eth_dev_info dev_info;
12191         portid_t port_id = res->port_id;
12192
12193         if (port_id_is_invalid(port_id, ENABLED_WARN))
12194                 return;
12195         if (!port_is_stopped(port_id)) {
12196                 printf("Please stop port %d first\n", port_id);
12197                 return;
12198         }
12199
12200         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12201         if (ret != 0)
12202                 return;
12203
12204         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
12205 #ifdef RTE_NET_IXGBE
12206                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12207 #endif
12208         }
12209         switch (ret) {
12210         case 0:
12211                 ports[port_id].dev_conf.txmode.offloads &=
12212                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
12213                 cmd_reconfig_device_queue(port_id, 1, 1);
12214                 break;
12215         case -ENODEV:
12216                 printf("invalid port_id %d\n", port_id);
12217                 break;
12218         case -ENOTSUP:
12219                 printf("not supported on port %d\n", port_id);
12220                 break;
12221         default:
12222                 printf("programming error: (%s)\n", strerror(-ret));
12223         }
12224 }
12225
12226 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12227         .f = cmd_set_macsec_offload_off_parsed,
12228         .data = NULL,
12229         .help_str = "set macsec offload <port_id> off",
12230         .tokens = {
12231                 (void *)&cmd_macsec_offload_off_set,
12232                 (void *)&cmd_macsec_offload_off_macsec,
12233                 (void *)&cmd_macsec_offload_off_offload,
12234                 (void *)&cmd_macsec_offload_off_port_id,
12235                 (void *)&cmd_macsec_offload_off_off,
12236                 NULL,
12237         },
12238 };
12239
12240 /* Common result structure for MACsec secure connection configure */
12241 struct cmd_macsec_sc_result {
12242         cmdline_fixed_string_t set;
12243         cmdline_fixed_string_t macsec;
12244         cmdline_fixed_string_t sc;
12245         cmdline_fixed_string_t tx_rx;
12246         portid_t port_id;
12247         struct rte_ether_addr mac;
12248         uint16_t pi;
12249 };
12250
12251 /* Common CLI fields for MACsec secure connection configure */
12252 cmdline_parse_token_string_t cmd_macsec_sc_set =
12253         TOKEN_STRING_INITIALIZER
12254                 (struct cmd_macsec_sc_result,
12255                  set, "set");
12256 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12257         TOKEN_STRING_INITIALIZER
12258                 (struct cmd_macsec_sc_result,
12259                  macsec, "macsec");
12260 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12261         TOKEN_STRING_INITIALIZER
12262                 (struct cmd_macsec_sc_result,
12263                  sc, "sc");
12264 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12265         TOKEN_STRING_INITIALIZER
12266                 (struct cmd_macsec_sc_result,
12267                  tx_rx, "tx#rx");
12268 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12269         TOKEN_NUM_INITIALIZER
12270                 (struct cmd_macsec_sc_result,
12271                  port_id, UINT16);
12272 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12273         TOKEN_ETHERADDR_INITIALIZER
12274                 (struct cmd_macsec_sc_result,
12275                  mac);
12276 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12277         TOKEN_NUM_INITIALIZER
12278                 (struct cmd_macsec_sc_result,
12279                  pi, UINT16);
12280
12281 static void
12282 cmd_set_macsec_sc_parsed(
12283         void *parsed_result,
12284         __rte_unused struct cmdline *cl,
12285         __rte_unused void *data)
12286 {
12287         struct cmd_macsec_sc_result *res = parsed_result;
12288         int ret = -ENOTSUP;
12289         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12290
12291 #ifdef RTE_NET_IXGBE
12292         ret = is_tx ?
12293                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12294                                 res->mac.addr_bytes) :
12295                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12296                                 res->mac.addr_bytes, res->pi);
12297 #endif
12298         RTE_SET_USED(is_tx);
12299
12300         switch (ret) {
12301         case 0:
12302                 break;
12303         case -ENODEV:
12304                 printf("invalid port_id %d\n", res->port_id);
12305                 break;
12306         case -ENOTSUP:
12307                 printf("not supported on port %d\n", res->port_id);
12308                 break;
12309         default:
12310                 printf("programming error: (%s)\n", strerror(-ret));
12311         }
12312 }
12313
12314 cmdline_parse_inst_t cmd_set_macsec_sc = {
12315         .f = cmd_set_macsec_sc_parsed,
12316         .data = NULL,
12317         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12318         .tokens = {
12319                 (void *)&cmd_macsec_sc_set,
12320                 (void *)&cmd_macsec_sc_macsec,
12321                 (void *)&cmd_macsec_sc_sc,
12322                 (void *)&cmd_macsec_sc_tx_rx,
12323                 (void *)&cmd_macsec_sc_port_id,
12324                 (void *)&cmd_macsec_sc_mac,
12325                 (void *)&cmd_macsec_sc_pi,
12326                 NULL,
12327         },
12328 };
12329
12330 /* Common result structure for MACsec secure connection configure */
12331 struct cmd_macsec_sa_result {
12332         cmdline_fixed_string_t set;
12333         cmdline_fixed_string_t macsec;
12334         cmdline_fixed_string_t sa;
12335         cmdline_fixed_string_t tx_rx;
12336         portid_t port_id;
12337         uint8_t idx;
12338         uint8_t an;
12339         uint32_t pn;
12340         cmdline_fixed_string_t key;
12341 };
12342
12343 /* Common CLI fields for MACsec secure connection configure */
12344 cmdline_parse_token_string_t cmd_macsec_sa_set =
12345         TOKEN_STRING_INITIALIZER
12346                 (struct cmd_macsec_sa_result,
12347                  set, "set");
12348 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12349         TOKEN_STRING_INITIALIZER
12350                 (struct cmd_macsec_sa_result,
12351                  macsec, "macsec");
12352 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_macsec_sa_result,
12355                  sa, "sa");
12356 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12357         TOKEN_STRING_INITIALIZER
12358                 (struct cmd_macsec_sa_result,
12359                  tx_rx, "tx#rx");
12360 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12361         TOKEN_NUM_INITIALIZER
12362                 (struct cmd_macsec_sa_result,
12363                  port_id, UINT16);
12364 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12365         TOKEN_NUM_INITIALIZER
12366                 (struct cmd_macsec_sa_result,
12367                  idx, UINT8);
12368 cmdline_parse_token_num_t cmd_macsec_sa_an =
12369         TOKEN_NUM_INITIALIZER
12370                 (struct cmd_macsec_sa_result,
12371                  an, UINT8);
12372 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12373         TOKEN_NUM_INITIALIZER
12374                 (struct cmd_macsec_sa_result,
12375                  pn, UINT32);
12376 cmdline_parse_token_string_t cmd_macsec_sa_key =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_macsec_sa_result,
12379                  key, NULL);
12380
12381 static void
12382 cmd_set_macsec_sa_parsed(
12383         void *parsed_result,
12384         __rte_unused struct cmdline *cl,
12385         __rte_unused void *data)
12386 {
12387         struct cmd_macsec_sa_result *res = parsed_result;
12388         int ret = -ENOTSUP;
12389         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12390         uint8_t key[16] = { 0 };
12391         uint8_t xdgt0;
12392         uint8_t xdgt1;
12393         int key_len;
12394         int i;
12395
12396         key_len = strlen(res->key) / 2;
12397         if (key_len > 16)
12398                 key_len = 16;
12399
12400         for (i = 0; i < key_len; i++) {
12401                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12402                 if (xdgt0 == 0xFF)
12403                         return;
12404                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12405                 if (xdgt1 == 0xFF)
12406                         return;
12407                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12408         }
12409
12410 #ifdef RTE_NET_IXGBE
12411         ret = is_tx ?
12412                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12413                         res->idx, res->an, res->pn, key) :
12414                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12415                         res->idx, res->an, res->pn, key);
12416 #endif
12417         RTE_SET_USED(is_tx);
12418         RTE_SET_USED(key);
12419
12420         switch (ret) {
12421         case 0:
12422                 break;
12423         case -EINVAL:
12424                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12425                 break;
12426         case -ENODEV:
12427                 printf("invalid port_id %d\n", res->port_id);
12428                 break;
12429         case -ENOTSUP:
12430                 printf("not supported on port %d\n", res->port_id);
12431                 break;
12432         default:
12433                 printf("programming error: (%s)\n", strerror(-ret));
12434         }
12435 }
12436
12437 cmdline_parse_inst_t cmd_set_macsec_sa = {
12438         .f = cmd_set_macsec_sa_parsed,
12439         .data = NULL,
12440         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12441         .tokens = {
12442                 (void *)&cmd_macsec_sa_set,
12443                 (void *)&cmd_macsec_sa_macsec,
12444                 (void *)&cmd_macsec_sa_sa,
12445                 (void *)&cmd_macsec_sa_tx_rx,
12446                 (void *)&cmd_macsec_sa_port_id,
12447                 (void *)&cmd_macsec_sa_idx,
12448                 (void *)&cmd_macsec_sa_an,
12449                 (void *)&cmd_macsec_sa_pn,
12450                 (void *)&cmd_macsec_sa_key,
12451                 NULL,
12452         },
12453 };
12454
12455 /* VF unicast promiscuous mode configuration */
12456
12457 /* Common result structure for VF unicast promiscuous mode */
12458 struct cmd_vf_promisc_result {
12459         cmdline_fixed_string_t set;
12460         cmdline_fixed_string_t vf;
12461         cmdline_fixed_string_t promisc;
12462         portid_t port_id;
12463         uint32_t vf_id;
12464         cmdline_fixed_string_t on_off;
12465 };
12466
12467 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12468 cmdline_parse_token_string_t cmd_vf_promisc_set =
12469         TOKEN_STRING_INITIALIZER
12470                 (struct cmd_vf_promisc_result,
12471                  set, "set");
12472 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_vf_promisc_result,
12475                  vf, "vf");
12476 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_vf_promisc_result,
12479                  promisc, "promisc");
12480 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12481         TOKEN_NUM_INITIALIZER
12482                 (struct cmd_vf_promisc_result,
12483                  port_id, UINT16);
12484 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12485         TOKEN_NUM_INITIALIZER
12486                 (struct cmd_vf_promisc_result,
12487                  vf_id, UINT32);
12488 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_vf_promisc_result,
12491                  on_off, "on#off");
12492
12493 static void
12494 cmd_set_vf_promisc_parsed(
12495         void *parsed_result,
12496         __rte_unused struct cmdline *cl,
12497         __rte_unused void *data)
12498 {
12499         struct cmd_vf_promisc_result *res = parsed_result;
12500         int ret = -ENOTSUP;
12501
12502         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12503
12504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12505                 return;
12506
12507 #ifdef RTE_NET_I40E
12508         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12509                                                   res->vf_id, is_on);
12510 #endif
12511
12512         switch (ret) {
12513         case 0:
12514                 break;
12515         case -EINVAL:
12516                 printf("invalid vf_id %d\n", res->vf_id);
12517                 break;
12518         case -ENODEV:
12519                 printf("invalid port_id %d\n", res->port_id);
12520                 break;
12521         case -ENOTSUP:
12522                 printf("function not implemented\n");
12523                 break;
12524         default:
12525                 printf("programming error: (%s)\n", strerror(-ret));
12526         }
12527 }
12528
12529 cmdline_parse_inst_t cmd_set_vf_promisc = {
12530         .f = cmd_set_vf_promisc_parsed,
12531         .data = NULL,
12532         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12533                 "Set unicast promiscuous mode for a VF from the PF",
12534         .tokens = {
12535                 (void *)&cmd_vf_promisc_set,
12536                 (void *)&cmd_vf_promisc_vf,
12537                 (void *)&cmd_vf_promisc_promisc,
12538                 (void *)&cmd_vf_promisc_port_id,
12539                 (void *)&cmd_vf_promisc_vf_id,
12540                 (void *)&cmd_vf_promisc_on_off,
12541                 NULL,
12542         },
12543 };
12544
12545 /* VF multicast promiscuous mode configuration */
12546
12547 /* Common result structure for VF multicast promiscuous mode */
12548 struct cmd_vf_allmulti_result {
12549         cmdline_fixed_string_t set;
12550         cmdline_fixed_string_t vf;
12551         cmdline_fixed_string_t allmulti;
12552         portid_t port_id;
12553         uint32_t vf_id;
12554         cmdline_fixed_string_t on_off;
12555 };
12556
12557 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12558 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12559         TOKEN_STRING_INITIALIZER
12560                 (struct cmd_vf_allmulti_result,
12561                  set, "set");
12562 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12563         TOKEN_STRING_INITIALIZER
12564                 (struct cmd_vf_allmulti_result,
12565                  vf, "vf");
12566 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12567         TOKEN_STRING_INITIALIZER
12568                 (struct cmd_vf_allmulti_result,
12569                  allmulti, "allmulti");
12570 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12571         TOKEN_NUM_INITIALIZER
12572                 (struct cmd_vf_allmulti_result,
12573                  port_id, UINT16);
12574 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12575         TOKEN_NUM_INITIALIZER
12576                 (struct cmd_vf_allmulti_result,
12577                  vf_id, UINT32);
12578 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12579         TOKEN_STRING_INITIALIZER
12580                 (struct cmd_vf_allmulti_result,
12581                  on_off, "on#off");
12582
12583 static void
12584 cmd_set_vf_allmulti_parsed(
12585         void *parsed_result,
12586         __rte_unused struct cmdline *cl,
12587         __rte_unused void *data)
12588 {
12589         struct cmd_vf_allmulti_result *res = parsed_result;
12590         int ret = -ENOTSUP;
12591
12592         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12593
12594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12595                 return;
12596
12597 #ifdef RTE_NET_I40E
12598         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12599                                                     res->vf_id, is_on);
12600 #endif
12601
12602         switch (ret) {
12603         case 0:
12604                 break;
12605         case -EINVAL:
12606                 printf("invalid vf_id %d\n", res->vf_id);
12607                 break;
12608         case -ENODEV:
12609                 printf("invalid port_id %d\n", res->port_id);
12610                 break;
12611         case -ENOTSUP:
12612                 printf("function not implemented\n");
12613                 break;
12614         default:
12615                 printf("programming error: (%s)\n", strerror(-ret));
12616         }
12617 }
12618
12619 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12620         .f = cmd_set_vf_allmulti_parsed,
12621         .data = NULL,
12622         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12623                 "Set multicast promiscuous mode for a VF from the PF",
12624         .tokens = {
12625                 (void *)&cmd_vf_allmulti_set,
12626                 (void *)&cmd_vf_allmulti_vf,
12627                 (void *)&cmd_vf_allmulti_allmulti,
12628                 (void *)&cmd_vf_allmulti_port_id,
12629                 (void *)&cmd_vf_allmulti_vf_id,
12630                 (void *)&cmd_vf_allmulti_on_off,
12631                 NULL,
12632         },
12633 };
12634
12635 /* vf broadcast mode configuration */
12636
12637 /* Common result structure for vf broadcast */
12638 struct cmd_set_vf_broadcast_result {
12639         cmdline_fixed_string_t set;
12640         cmdline_fixed_string_t vf;
12641         cmdline_fixed_string_t broadcast;
12642         portid_t port_id;
12643         uint16_t vf_id;
12644         cmdline_fixed_string_t on_off;
12645 };
12646
12647 /* Common CLI fields for vf broadcast enable disable */
12648 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12649         TOKEN_STRING_INITIALIZER
12650                 (struct cmd_set_vf_broadcast_result,
12651                  set, "set");
12652 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12653         TOKEN_STRING_INITIALIZER
12654                 (struct cmd_set_vf_broadcast_result,
12655                  vf, "vf");
12656 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12657         TOKEN_STRING_INITIALIZER
12658                 (struct cmd_set_vf_broadcast_result,
12659                  broadcast, "broadcast");
12660 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12661         TOKEN_NUM_INITIALIZER
12662                 (struct cmd_set_vf_broadcast_result,
12663                  port_id, UINT16);
12664 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12665         TOKEN_NUM_INITIALIZER
12666                 (struct cmd_set_vf_broadcast_result,
12667                  vf_id, UINT16);
12668 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12669         TOKEN_STRING_INITIALIZER
12670                 (struct cmd_set_vf_broadcast_result,
12671                  on_off, "on#off");
12672
12673 static void
12674 cmd_set_vf_broadcast_parsed(
12675         void *parsed_result,
12676         __rte_unused struct cmdline *cl,
12677         __rte_unused void *data)
12678 {
12679         struct cmd_set_vf_broadcast_result *res = parsed_result;
12680         int ret = -ENOTSUP;
12681
12682         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12683
12684         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12685                 return;
12686
12687 #ifdef RTE_NET_I40E
12688         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12689                                             res->vf_id, is_on);
12690 #endif
12691
12692         switch (ret) {
12693         case 0:
12694                 break;
12695         case -EINVAL:
12696                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12697                 break;
12698         case -ENODEV:
12699                 printf("invalid port_id %d\n", res->port_id);
12700                 break;
12701         case -ENOTSUP:
12702                 printf("function not implemented\n");
12703                 break;
12704         default:
12705                 printf("programming error: (%s)\n", strerror(-ret));
12706         }
12707 }
12708
12709 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12710         .f = cmd_set_vf_broadcast_parsed,
12711         .data = NULL,
12712         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12713         .tokens = {
12714                 (void *)&cmd_set_vf_broadcast_set,
12715                 (void *)&cmd_set_vf_broadcast_vf,
12716                 (void *)&cmd_set_vf_broadcast_broadcast,
12717                 (void *)&cmd_set_vf_broadcast_port_id,
12718                 (void *)&cmd_set_vf_broadcast_vf_id,
12719                 (void *)&cmd_set_vf_broadcast_on_off,
12720                 NULL,
12721         },
12722 };
12723
12724 /* vf vlan tag configuration */
12725
12726 /* Common result structure for vf vlan tag */
12727 struct cmd_set_vf_vlan_tag_result {
12728         cmdline_fixed_string_t set;
12729         cmdline_fixed_string_t vf;
12730         cmdline_fixed_string_t vlan;
12731         cmdline_fixed_string_t tag;
12732         portid_t port_id;
12733         uint16_t vf_id;
12734         cmdline_fixed_string_t on_off;
12735 };
12736
12737 /* Common CLI fields for vf vlan tag enable disable */
12738 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12739         TOKEN_STRING_INITIALIZER
12740                 (struct cmd_set_vf_vlan_tag_result,
12741                  set, "set");
12742 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12743         TOKEN_STRING_INITIALIZER
12744                 (struct cmd_set_vf_vlan_tag_result,
12745                  vf, "vf");
12746 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12747         TOKEN_STRING_INITIALIZER
12748                 (struct cmd_set_vf_vlan_tag_result,
12749                  vlan, "vlan");
12750 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12751         TOKEN_STRING_INITIALIZER
12752                 (struct cmd_set_vf_vlan_tag_result,
12753                  tag, "tag");
12754 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12755         TOKEN_NUM_INITIALIZER
12756                 (struct cmd_set_vf_vlan_tag_result,
12757                  port_id, UINT16);
12758 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12759         TOKEN_NUM_INITIALIZER
12760                 (struct cmd_set_vf_vlan_tag_result,
12761                  vf_id, UINT16);
12762 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12763         TOKEN_STRING_INITIALIZER
12764                 (struct cmd_set_vf_vlan_tag_result,
12765                  on_off, "on#off");
12766
12767 static void
12768 cmd_set_vf_vlan_tag_parsed(
12769         void *parsed_result,
12770         __rte_unused struct cmdline *cl,
12771         __rte_unused void *data)
12772 {
12773         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12774         int ret = -ENOTSUP;
12775
12776         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12777
12778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12779                 return;
12780
12781 #ifdef RTE_NET_I40E
12782         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12783                                            res->vf_id, is_on);
12784 #endif
12785
12786         switch (ret) {
12787         case 0:
12788                 break;
12789         case -EINVAL:
12790                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12791                 break;
12792         case -ENODEV:
12793                 printf("invalid port_id %d\n", res->port_id);
12794                 break;
12795         case -ENOTSUP:
12796                 printf("function not implemented\n");
12797                 break;
12798         default:
12799                 printf("programming error: (%s)\n", strerror(-ret));
12800         }
12801 }
12802
12803 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12804         .f = cmd_set_vf_vlan_tag_parsed,
12805         .data = NULL,
12806         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12807         .tokens = {
12808                 (void *)&cmd_set_vf_vlan_tag_set,
12809                 (void *)&cmd_set_vf_vlan_tag_vf,
12810                 (void *)&cmd_set_vf_vlan_tag_vlan,
12811                 (void *)&cmd_set_vf_vlan_tag_tag,
12812                 (void *)&cmd_set_vf_vlan_tag_port_id,
12813                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12814                 (void *)&cmd_set_vf_vlan_tag_on_off,
12815                 NULL,
12816         },
12817 };
12818
12819 /* Common definition of VF and TC TX bandwidth configuration */
12820 struct cmd_vf_tc_bw_result {
12821         cmdline_fixed_string_t set;
12822         cmdline_fixed_string_t vf;
12823         cmdline_fixed_string_t tc;
12824         cmdline_fixed_string_t tx;
12825         cmdline_fixed_string_t min_bw;
12826         cmdline_fixed_string_t max_bw;
12827         cmdline_fixed_string_t strict_link_prio;
12828         portid_t port_id;
12829         uint16_t vf_id;
12830         uint8_t tc_no;
12831         uint32_t bw;
12832         cmdline_fixed_string_t bw_list;
12833         uint8_t tc_map;
12834 };
12835
12836 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12837         TOKEN_STRING_INITIALIZER
12838                 (struct cmd_vf_tc_bw_result,
12839                  set, "set");
12840 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12841         TOKEN_STRING_INITIALIZER
12842                 (struct cmd_vf_tc_bw_result,
12843                  vf, "vf");
12844 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12845         TOKEN_STRING_INITIALIZER
12846                 (struct cmd_vf_tc_bw_result,
12847                  tc, "tc");
12848 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12849         TOKEN_STRING_INITIALIZER
12850                 (struct cmd_vf_tc_bw_result,
12851                  tx, "tx");
12852 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12853         TOKEN_STRING_INITIALIZER
12854                 (struct cmd_vf_tc_bw_result,
12855                  strict_link_prio, "strict-link-priority");
12856 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12857         TOKEN_STRING_INITIALIZER
12858                 (struct cmd_vf_tc_bw_result,
12859                  min_bw, "min-bandwidth");
12860 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12861         TOKEN_STRING_INITIALIZER
12862                 (struct cmd_vf_tc_bw_result,
12863                  max_bw, "max-bandwidth");
12864 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12865         TOKEN_NUM_INITIALIZER
12866                 (struct cmd_vf_tc_bw_result,
12867                  port_id, UINT16);
12868 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12869         TOKEN_NUM_INITIALIZER
12870                 (struct cmd_vf_tc_bw_result,
12871                  vf_id, UINT16);
12872 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12873         TOKEN_NUM_INITIALIZER
12874                 (struct cmd_vf_tc_bw_result,
12875                  tc_no, UINT8);
12876 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12877         TOKEN_NUM_INITIALIZER
12878                 (struct cmd_vf_tc_bw_result,
12879                  bw, UINT32);
12880 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_vf_tc_bw_result,
12883                  bw_list, NULL);
12884 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12885         TOKEN_NUM_INITIALIZER
12886                 (struct cmd_vf_tc_bw_result,
12887                  tc_map, UINT8);
12888
12889 /* VF max bandwidth setting */
12890 static void
12891 cmd_vf_max_bw_parsed(
12892         void *parsed_result,
12893         __rte_unused struct cmdline *cl,
12894         __rte_unused void *data)
12895 {
12896         struct cmd_vf_tc_bw_result *res = parsed_result;
12897         int ret = -ENOTSUP;
12898
12899         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12900                 return;
12901
12902 #ifdef RTE_NET_I40E
12903         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12904                                          res->vf_id, res->bw);
12905 #endif
12906
12907         switch (ret) {
12908         case 0:
12909                 break;
12910         case -EINVAL:
12911                 printf("invalid vf_id %d or bandwidth %d\n",
12912                        res->vf_id, res->bw);
12913                 break;
12914         case -ENODEV:
12915                 printf("invalid port_id %d\n", res->port_id);
12916                 break;
12917         case -ENOTSUP:
12918                 printf("function not implemented\n");
12919                 break;
12920         default:
12921                 printf("programming error: (%s)\n", strerror(-ret));
12922         }
12923 }
12924
12925 cmdline_parse_inst_t cmd_vf_max_bw = {
12926         .f = cmd_vf_max_bw_parsed,
12927         .data = NULL,
12928         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12929         .tokens = {
12930                 (void *)&cmd_vf_tc_bw_set,
12931                 (void *)&cmd_vf_tc_bw_vf,
12932                 (void *)&cmd_vf_tc_bw_tx,
12933                 (void *)&cmd_vf_tc_bw_max_bw,
12934                 (void *)&cmd_vf_tc_bw_port_id,
12935                 (void *)&cmd_vf_tc_bw_vf_id,
12936                 (void *)&cmd_vf_tc_bw_bw,
12937                 NULL,
12938         },
12939 };
12940
12941 static int
12942 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12943                            uint8_t *tc_num,
12944                            char *str)
12945 {
12946         uint32_t size;
12947         const char *p, *p0 = str;
12948         char s[256];
12949         char *end;
12950         char *str_fld[16];
12951         uint16_t i;
12952         int ret;
12953
12954         p = strchr(p0, '(');
12955         if (p == NULL) {
12956                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12957                 return -1;
12958         }
12959         p++;
12960         p0 = strchr(p, ')');
12961         if (p0 == NULL) {
12962                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12963                 return -1;
12964         }
12965         size = p0 - p;
12966         if (size >= sizeof(s)) {
12967                 printf("The string size exceeds the internal buffer size\n");
12968                 return -1;
12969         }
12970         snprintf(s, sizeof(s), "%.*s", size, p);
12971         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12972         if (ret <= 0) {
12973                 printf("Failed to get the bandwidth list. ");
12974                 return -1;
12975         }
12976         *tc_num = ret;
12977         for (i = 0; i < ret; i++)
12978                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12979
12980         return 0;
12981 }
12982
12983 /* TC min bandwidth setting */
12984 static void
12985 cmd_vf_tc_min_bw_parsed(
12986         void *parsed_result,
12987         __rte_unused struct cmdline *cl,
12988         __rte_unused void *data)
12989 {
12990         struct cmd_vf_tc_bw_result *res = parsed_result;
12991         uint8_t tc_num;
12992         uint8_t bw[16];
12993         int ret = -ENOTSUP;
12994
12995         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12996                 return;
12997
12998         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12999         if (ret)
13000                 return;
13001
13002 #ifdef RTE_NET_I40E
13003         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13004                                               tc_num, bw);
13005 #endif
13006
13007         switch (ret) {
13008         case 0:
13009                 break;
13010         case -EINVAL:
13011                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13012                 break;
13013         case -ENODEV:
13014                 printf("invalid port_id %d\n", res->port_id);
13015                 break;
13016         case -ENOTSUP:
13017                 printf("function not implemented\n");
13018                 break;
13019         default:
13020                 printf("programming error: (%s)\n", strerror(-ret));
13021         }
13022 }
13023
13024 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13025         .f = cmd_vf_tc_min_bw_parsed,
13026         .data = NULL,
13027         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13028                     " <bw1, bw2, ...>",
13029         .tokens = {
13030                 (void *)&cmd_vf_tc_bw_set,
13031                 (void *)&cmd_vf_tc_bw_vf,
13032                 (void *)&cmd_vf_tc_bw_tc,
13033                 (void *)&cmd_vf_tc_bw_tx,
13034                 (void *)&cmd_vf_tc_bw_min_bw,
13035                 (void *)&cmd_vf_tc_bw_port_id,
13036                 (void *)&cmd_vf_tc_bw_vf_id,
13037                 (void *)&cmd_vf_tc_bw_bw_list,
13038                 NULL,
13039         },
13040 };
13041
13042 static void
13043 cmd_tc_min_bw_parsed(
13044         void *parsed_result,
13045         __rte_unused struct cmdline *cl,
13046         __rte_unused void *data)
13047 {
13048         struct cmd_vf_tc_bw_result *res = parsed_result;
13049         struct rte_port *port;
13050         uint8_t tc_num;
13051         uint8_t bw[16];
13052         int ret = -ENOTSUP;
13053
13054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13055                 return;
13056
13057         port = &ports[res->port_id];
13058         /** Check if the port is not started **/
13059         if (port->port_status != RTE_PORT_STOPPED) {
13060                 printf("Please stop port %d first\n", res->port_id);
13061                 return;
13062         }
13063
13064         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13065         if (ret)
13066                 return;
13067
13068 #ifdef RTE_NET_IXGBE
13069         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13070 #endif
13071
13072         switch (ret) {
13073         case 0:
13074                 break;
13075         case -EINVAL:
13076                 printf("invalid bandwidth\n");
13077                 break;
13078         case -ENODEV:
13079                 printf("invalid port_id %d\n", res->port_id);
13080                 break;
13081         case -ENOTSUP:
13082                 printf("function not implemented\n");
13083                 break;
13084         default:
13085                 printf("programming error: (%s)\n", strerror(-ret));
13086         }
13087 }
13088
13089 cmdline_parse_inst_t cmd_tc_min_bw = {
13090         .f = cmd_tc_min_bw_parsed,
13091         .data = NULL,
13092         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13093         .tokens = {
13094                 (void *)&cmd_vf_tc_bw_set,
13095                 (void *)&cmd_vf_tc_bw_tc,
13096                 (void *)&cmd_vf_tc_bw_tx,
13097                 (void *)&cmd_vf_tc_bw_min_bw,
13098                 (void *)&cmd_vf_tc_bw_port_id,
13099                 (void *)&cmd_vf_tc_bw_bw_list,
13100                 NULL,
13101         },
13102 };
13103
13104 /* TC max bandwidth setting */
13105 static void
13106 cmd_vf_tc_max_bw_parsed(
13107         void *parsed_result,
13108         __rte_unused struct cmdline *cl,
13109         __rte_unused void *data)
13110 {
13111         struct cmd_vf_tc_bw_result *res = parsed_result;
13112         int ret = -ENOTSUP;
13113
13114         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13115                 return;
13116
13117 #ifdef RTE_NET_I40E
13118         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13119                                             res->tc_no, res->bw);
13120 #endif
13121
13122         switch (ret) {
13123         case 0:
13124                 break;
13125         case -EINVAL:
13126                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13127                        res->vf_id, res->tc_no, res->bw);
13128                 break;
13129         case -ENODEV:
13130                 printf("invalid port_id %d\n", res->port_id);
13131                 break;
13132         case -ENOTSUP:
13133                 printf("function not implemented\n");
13134                 break;
13135         default:
13136                 printf("programming error: (%s)\n", strerror(-ret));
13137         }
13138 }
13139
13140 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13141         .f = cmd_vf_tc_max_bw_parsed,
13142         .data = NULL,
13143         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13144                     " <bandwidth>",
13145         .tokens = {
13146                 (void *)&cmd_vf_tc_bw_set,
13147                 (void *)&cmd_vf_tc_bw_vf,
13148                 (void *)&cmd_vf_tc_bw_tc,
13149                 (void *)&cmd_vf_tc_bw_tx,
13150                 (void *)&cmd_vf_tc_bw_max_bw,
13151                 (void *)&cmd_vf_tc_bw_port_id,
13152                 (void *)&cmd_vf_tc_bw_vf_id,
13153                 (void *)&cmd_vf_tc_bw_tc_no,
13154                 (void *)&cmd_vf_tc_bw_bw,
13155                 NULL,
13156         },
13157 };
13158
13159 /** Set VXLAN encapsulation details */
13160 struct cmd_set_vxlan_result {
13161         cmdline_fixed_string_t set;
13162         cmdline_fixed_string_t vxlan;
13163         cmdline_fixed_string_t pos_token;
13164         cmdline_fixed_string_t ip_version;
13165         uint32_t vlan_present:1;
13166         uint32_t vni;
13167         uint16_t udp_src;
13168         uint16_t udp_dst;
13169         cmdline_ipaddr_t ip_src;
13170         cmdline_ipaddr_t ip_dst;
13171         uint16_t tci;
13172         uint8_t tos;
13173         uint8_t ttl;
13174         struct rte_ether_addr eth_src;
13175         struct rte_ether_addr eth_dst;
13176 };
13177
13178 cmdline_parse_token_string_t cmd_set_vxlan_set =
13179         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13180 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13182 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13183         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13184                                  "vxlan-tos-ttl");
13185 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13187                                  "vxlan-with-vlan");
13188 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13189         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13190                                  "ip-version");
13191 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13192         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13193                                  "ipv4#ipv6");
13194 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13195         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13196                                  "vni");
13197 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13198         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
13199 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13200         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13201                                  "udp-src");
13202 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13203         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
13204 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13205         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13206                                  "udp-dst");
13207 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13208         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
13209 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13210         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13211                                  "ip-tos");
13212 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13213         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
13214 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13215         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13216                                  "ip-ttl");
13217 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13218         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
13219 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13220         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13221                                  "ip-src");
13222 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13223         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13224 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13225         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13226                                  "ip-dst");
13227 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13228         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13229 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13230         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13231                                  "vlan-tci");
13232 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13233         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
13234 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13235         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13236                                  "eth-src");
13237 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13238         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13239 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13240         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13241                                  "eth-dst");
13242 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13243         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13244
13245 static void cmd_set_vxlan_parsed(void *parsed_result,
13246         __rte_unused struct cmdline *cl,
13247         __rte_unused void *data)
13248 {
13249         struct cmd_set_vxlan_result *res = parsed_result;
13250         union {
13251                 uint32_t vxlan_id;
13252                 uint8_t vni[4];
13253         } id = {
13254                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13255         };
13256
13257         vxlan_encap_conf.select_tos_ttl = 0;
13258         if (strcmp(res->vxlan, "vxlan") == 0)
13259                 vxlan_encap_conf.select_vlan = 0;
13260         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13261                 vxlan_encap_conf.select_vlan = 1;
13262         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13263                 vxlan_encap_conf.select_vlan = 0;
13264                 vxlan_encap_conf.select_tos_ttl = 1;
13265         }
13266         if (strcmp(res->ip_version, "ipv4") == 0)
13267                 vxlan_encap_conf.select_ipv4 = 1;
13268         else if (strcmp(res->ip_version, "ipv6") == 0)
13269                 vxlan_encap_conf.select_ipv4 = 0;
13270         else
13271                 return;
13272         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13273         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13274         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13275         vxlan_encap_conf.ip_tos = res->tos;
13276         vxlan_encap_conf.ip_ttl = res->ttl;
13277         if (vxlan_encap_conf.select_ipv4) {
13278                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13279                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13280         } else {
13281                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13282                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13283         }
13284         if (vxlan_encap_conf.select_vlan)
13285                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13286         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13287                    RTE_ETHER_ADDR_LEN);
13288         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13289                    RTE_ETHER_ADDR_LEN);
13290 }
13291
13292 cmdline_parse_inst_t cmd_set_vxlan = {
13293         .f = cmd_set_vxlan_parsed,
13294         .data = NULL,
13295         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13296                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13297                 " eth-src <eth-src> eth-dst <eth-dst>",
13298         .tokens = {
13299                 (void *)&cmd_set_vxlan_set,
13300                 (void *)&cmd_set_vxlan_vxlan,
13301                 (void *)&cmd_set_vxlan_ip_version,
13302                 (void *)&cmd_set_vxlan_ip_version_value,
13303                 (void *)&cmd_set_vxlan_vni,
13304                 (void *)&cmd_set_vxlan_vni_value,
13305                 (void *)&cmd_set_vxlan_udp_src,
13306                 (void *)&cmd_set_vxlan_udp_src_value,
13307                 (void *)&cmd_set_vxlan_udp_dst,
13308                 (void *)&cmd_set_vxlan_udp_dst_value,
13309                 (void *)&cmd_set_vxlan_ip_src,
13310                 (void *)&cmd_set_vxlan_ip_src_value,
13311                 (void *)&cmd_set_vxlan_ip_dst,
13312                 (void *)&cmd_set_vxlan_ip_dst_value,
13313                 (void *)&cmd_set_vxlan_eth_src,
13314                 (void *)&cmd_set_vxlan_eth_src_value,
13315                 (void *)&cmd_set_vxlan_eth_dst,
13316                 (void *)&cmd_set_vxlan_eth_dst_value,
13317                 NULL,
13318         },
13319 };
13320
13321 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13322         .f = cmd_set_vxlan_parsed,
13323         .data = NULL,
13324         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13325                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13326                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13327                 " eth-dst <eth-dst>",
13328         .tokens = {
13329                 (void *)&cmd_set_vxlan_set,
13330                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13331                 (void *)&cmd_set_vxlan_ip_version,
13332                 (void *)&cmd_set_vxlan_ip_version_value,
13333                 (void *)&cmd_set_vxlan_vni,
13334                 (void *)&cmd_set_vxlan_vni_value,
13335                 (void *)&cmd_set_vxlan_udp_src,
13336                 (void *)&cmd_set_vxlan_udp_src_value,
13337                 (void *)&cmd_set_vxlan_udp_dst,
13338                 (void *)&cmd_set_vxlan_udp_dst_value,
13339                 (void *)&cmd_set_vxlan_ip_tos,
13340                 (void *)&cmd_set_vxlan_ip_tos_value,
13341                 (void *)&cmd_set_vxlan_ip_ttl,
13342                 (void *)&cmd_set_vxlan_ip_ttl_value,
13343                 (void *)&cmd_set_vxlan_ip_src,
13344                 (void *)&cmd_set_vxlan_ip_src_value,
13345                 (void *)&cmd_set_vxlan_ip_dst,
13346                 (void *)&cmd_set_vxlan_ip_dst_value,
13347                 (void *)&cmd_set_vxlan_eth_src,
13348                 (void *)&cmd_set_vxlan_eth_src_value,
13349                 (void *)&cmd_set_vxlan_eth_dst,
13350                 (void *)&cmd_set_vxlan_eth_dst_value,
13351                 NULL,
13352         },
13353 };
13354
13355 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13356         .f = cmd_set_vxlan_parsed,
13357         .data = NULL,
13358         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13359                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13360                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13361                 " <eth-dst>",
13362         .tokens = {
13363                 (void *)&cmd_set_vxlan_set,
13364                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13365                 (void *)&cmd_set_vxlan_ip_version,
13366                 (void *)&cmd_set_vxlan_ip_version_value,
13367                 (void *)&cmd_set_vxlan_vni,
13368                 (void *)&cmd_set_vxlan_vni_value,
13369                 (void *)&cmd_set_vxlan_udp_src,
13370                 (void *)&cmd_set_vxlan_udp_src_value,
13371                 (void *)&cmd_set_vxlan_udp_dst,
13372                 (void *)&cmd_set_vxlan_udp_dst_value,
13373                 (void *)&cmd_set_vxlan_ip_src,
13374                 (void *)&cmd_set_vxlan_ip_src_value,
13375                 (void *)&cmd_set_vxlan_ip_dst,
13376                 (void *)&cmd_set_vxlan_ip_dst_value,
13377                 (void *)&cmd_set_vxlan_vlan,
13378                 (void *)&cmd_set_vxlan_vlan_value,
13379                 (void *)&cmd_set_vxlan_eth_src,
13380                 (void *)&cmd_set_vxlan_eth_src_value,
13381                 (void *)&cmd_set_vxlan_eth_dst,
13382                 (void *)&cmd_set_vxlan_eth_dst_value,
13383                 NULL,
13384         },
13385 };
13386
13387 /** Set NVGRE encapsulation details */
13388 struct cmd_set_nvgre_result {
13389         cmdline_fixed_string_t set;
13390         cmdline_fixed_string_t nvgre;
13391         cmdline_fixed_string_t pos_token;
13392         cmdline_fixed_string_t ip_version;
13393         uint32_t tni;
13394         cmdline_ipaddr_t ip_src;
13395         cmdline_ipaddr_t ip_dst;
13396         uint16_t tci;
13397         struct rte_ether_addr eth_src;
13398         struct rte_ether_addr eth_dst;
13399 };
13400
13401 cmdline_parse_token_string_t cmd_set_nvgre_set =
13402         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13403 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13404         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13405 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13406         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13407                                  "nvgre-with-vlan");
13408 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13409         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13410                                  "ip-version");
13411 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13412         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13413                                  "ipv4#ipv6");
13414 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13415         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13416                                  "tni");
13417 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13418         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
13419 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13420         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13421                                  "ip-src");
13422 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13423         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13424 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13425         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13426                                  "ip-dst");
13427 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13428         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13429 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13430         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13431                                  "vlan-tci");
13432 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13433         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
13434 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13435         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13436                                  "eth-src");
13437 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13438         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13439 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13440         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13441                                  "eth-dst");
13442 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13443         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13444
13445 static void cmd_set_nvgre_parsed(void *parsed_result,
13446         __rte_unused struct cmdline *cl,
13447         __rte_unused void *data)
13448 {
13449         struct cmd_set_nvgre_result *res = parsed_result;
13450         union {
13451                 uint32_t nvgre_tni;
13452                 uint8_t tni[4];
13453         } id = {
13454                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13455         };
13456
13457         if (strcmp(res->nvgre, "nvgre") == 0)
13458                 nvgre_encap_conf.select_vlan = 0;
13459         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13460                 nvgre_encap_conf.select_vlan = 1;
13461         if (strcmp(res->ip_version, "ipv4") == 0)
13462                 nvgre_encap_conf.select_ipv4 = 1;
13463         else if (strcmp(res->ip_version, "ipv6") == 0)
13464                 nvgre_encap_conf.select_ipv4 = 0;
13465         else
13466                 return;
13467         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13468         if (nvgre_encap_conf.select_ipv4) {
13469                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13470                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13471         } else {
13472                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13473                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13474         }
13475         if (nvgre_encap_conf.select_vlan)
13476                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13477         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13478                    RTE_ETHER_ADDR_LEN);
13479         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13480                    RTE_ETHER_ADDR_LEN);
13481 }
13482
13483 cmdline_parse_inst_t cmd_set_nvgre = {
13484         .f = cmd_set_nvgre_parsed,
13485         .data = NULL,
13486         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13487                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13488                 " eth-dst <eth-dst>",
13489         .tokens = {
13490                 (void *)&cmd_set_nvgre_set,
13491                 (void *)&cmd_set_nvgre_nvgre,
13492                 (void *)&cmd_set_nvgre_ip_version,
13493                 (void *)&cmd_set_nvgre_ip_version_value,
13494                 (void *)&cmd_set_nvgre_tni,
13495                 (void *)&cmd_set_nvgre_tni_value,
13496                 (void *)&cmd_set_nvgre_ip_src,
13497                 (void *)&cmd_set_nvgre_ip_src_value,
13498                 (void *)&cmd_set_nvgre_ip_dst,
13499                 (void *)&cmd_set_nvgre_ip_dst_value,
13500                 (void *)&cmd_set_nvgre_eth_src,
13501                 (void *)&cmd_set_nvgre_eth_src_value,
13502                 (void *)&cmd_set_nvgre_eth_dst,
13503                 (void *)&cmd_set_nvgre_eth_dst_value,
13504                 NULL,
13505         },
13506 };
13507
13508 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13509         .f = cmd_set_nvgre_parsed,
13510         .data = NULL,
13511         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13512                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13513                 " eth-src <eth-src> eth-dst <eth-dst>",
13514         .tokens = {
13515                 (void *)&cmd_set_nvgre_set,
13516                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13517                 (void *)&cmd_set_nvgre_ip_version,
13518                 (void *)&cmd_set_nvgre_ip_version_value,
13519                 (void *)&cmd_set_nvgre_tni,
13520                 (void *)&cmd_set_nvgre_tni_value,
13521                 (void *)&cmd_set_nvgre_ip_src,
13522                 (void *)&cmd_set_nvgre_ip_src_value,
13523                 (void *)&cmd_set_nvgre_ip_dst,
13524                 (void *)&cmd_set_nvgre_ip_dst_value,
13525                 (void *)&cmd_set_nvgre_vlan,
13526                 (void *)&cmd_set_nvgre_vlan_value,
13527                 (void *)&cmd_set_nvgre_eth_src,
13528                 (void *)&cmd_set_nvgre_eth_src_value,
13529                 (void *)&cmd_set_nvgre_eth_dst,
13530                 (void *)&cmd_set_nvgre_eth_dst_value,
13531                 NULL,
13532         },
13533 };
13534
13535 /** Set L2 encapsulation details */
13536 struct cmd_set_l2_encap_result {
13537         cmdline_fixed_string_t set;
13538         cmdline_fixed_string_t l2_encap;
13539         cmdline_fixed_string_t pos_token;
13540         cmdline_fixed_string_t ip_version;
13541         uint32_t vlan_present:1;
13542         uint16_t tci;
13543         struct rte_ether_addr eth_src;
13544         struct rte_ether_addr eth_dst;
13545 };
13546
13547 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13548         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13549 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13550         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13551 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13552         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13553                                  "l2_encap-with-vlan");
13554 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13555         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13556                                  "ip-version");
13557 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13558         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13559                                  "ipv4#ipv6");
13560 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13561         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13562                                  "vlan-tci");
13563 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13564         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
13565 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13566         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13567                                  "eth-src");
13568 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13569         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13570 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13571         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13572                                  "eth-dst");
13573 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13574         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13575
13576 static void cmd_set_l2_encap_parsed(void *parsed_result,
13577         __rte_unused struct cmdline *cl,
13578         __rte_unused void *data)
13579 {
13580         struct cmd_set_l2_encap_result *res = parsed_result;
13581
13582         if (strcmp(res->l2_encap, "l2_encap") == 0)
13583                 l2_encap_conf.select_vlan = 0;
13584         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13585                 l2_encap_conf.select_vlan = 1;
13586         if (strcmp(res->ip_version, "ipv4") == 0)
13587                 l2_encap_conf.select_ipv4 = 1;
13588         else if (strcmp(res->ip_version, "ipv6") == 0)
13589                 l2_encap_conf.select_ipv4 = 0;
13590         else
13591                 return;
13592         if (l2_encap_conf.select_vlan)
13593                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13594         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13595                    RTE_ETHER_ADDR_LEN);
13596         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13597                    RTE_ETHER_ADDR_LEN);
13598 }
13599
13600 cmdline_parse_inst_t cmd_set_l2_encap = {
13601         .f = cmd_set_l2_encap_parsed,
13602         .data = NULL,
13603         .help_str = "set l2_encap ip-version ipv4|ipv6"
13604                 " eth-src <eth-src> eth-dst <eth-dst>",
13605         .tokens = {
13606                 (void *)&cmd_set_l2_encap_set,
13607                 (void *)&cmd_set_l2_encap_l2_encap,
13608                 (void *)&cmd_set_l2_encap_ip_version,
13609                 (void *)&cmd_set_l2_encap_ip_version_value,
13610                 (void *)&cmd_set_l2_encap_eth_src,
13611                 (void *)&cmd_set_l2_encap_eth_src_value,
13612                 (void *)&cmd_set_l2_encap_eth_dst,
13613                 (void *)&cmd_set_l2_encap_eth_dst_value,
13614                 NULL,
13615         },
13616 };
13617
13618 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13619         .f = cmd_set_l2_encap_parsed,
13620         .data = NULL,
13621         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13622                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13623         .tokens = {
13624                 (void *)&cmd_set_l2_encap_set,
13625                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13626                 (void *)&cmd_set_l2_encap_ip_version,
13627                 (void *)&cmd_set_l2_encap_ip_version_value,
13628                 (void *)&cmd_set_l2_encap_vlan,
13629                 (void *)&cmd_set_l2_encap_vlan_value,
13630                 (void *)&cmd_set_l2_encap_eth_src,
13631                 (void *)&cmd_set_l2_encap_eth_src_value,
13632                 (void *)&cmd_set_l2_encap_eth_dst,
13633                 (void *)&cmd_set_l2_encap_eth_dst_value,
13634                 NULL,
13635         },
13636 };
13637
13638 /** Set L2 decapsulation details */
13639 struct cmd_set_l2_decap_result {
13640         cmdline_fixed_string_t set;
13641         cmdline_fixed_string_t l2_decap;
13642         cmdline_fixed_string_t pos_token;
13643         uint32_t vlan_present:1;
13644 };
13645
13646 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13647         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13648 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13649         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13650                                  "l2_decap");
13651 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13652         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13653                                  "l2_decap-with-vlan");
13654
13655 static void cmd_set_l2_decap_parsed(void *parsed_result,
13656         __rte_unused struct cmdline *cl,
13657         __rte_unused void *data)
13658 {
13659         struct cmd_set_l2_decap_result *res = parsed_result;
13660
13661         if (strcmp(res->l2_decap, "l2_decap") == 0)
13662                 l2_decap_conf.select_vlan = 0;
13663         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13664                 l2_decap_conf.select_vlan = 1;
13665 }
13666
13667 cmdline_parse_inst_t cmd_set_l2_decap = {
13668         .f = cmd_set_l2_decap_parsed,
13669         .data = NULL,
13670         .help_str = "set l2_decap",
13671         .tokens = {
13672                 (void *)&cmd_set_l2_decap_set,
13673                 (void *)&cmd_set_l2_decap_l2_decap,
13674                 NULL,
13675         },
13676 };
13677
13678 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13679         .f = cmd_set_l2_decap_parsed,
13680         .data = NULL,
13681         .help_str = "set l2_decap-with-vlan",
13682         .tokens = {
13683                 (void *)&cmd_set_l2_decap_set,
13684                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13685                 NULL,
13686         },
13687 };
13688
13689 /** Set MPLSoGRE encapsulation details */
13690 struct cmd_set_mplsogre_encap_result {
13691         cmdline_fixed_string_t set;
13692         cmdline_fixed_string_t mplsogre;
13693         cmdline_fixed_string_t pos_token;
13694         cmdline_fixed_string_t ip_version;
13695         uint32_t vlan_present:1;
13696         uint32_t label;
13697         cmdline_ipaddr_t ip_src;
13698         cmdline_ipaddr_t ip_dst;
13699         uint16_t tci;
13700         struct rte_ether_addr eth_src;
13701         struct rte_ether_addr eth_dst;
13702 };
13703
13704 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13705         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13706                                  "set");
13707 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13708         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13709                                  "mplsogre_encap");
13710 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13711         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13712                                  mplsogre, "mplsogre_encap-with-vlan");
13713 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13714         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13715                                  pos_token, "ip-version");
13716 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13717         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13718                                  ip_version, "ipv4#ipv6");
13719 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13720         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13721                                  pos_token, "label");
13722 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13723         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13724                               UINT32);
13725 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13726         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13727                                  pos_token, "ip-src");
13728 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13729         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13730 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13731         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13732                                  pos_token, "ip-dst");
13733 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13734         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13735 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13736         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13737                                  pos_token, "vlan-tci");
13738 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13739         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13740                               UINT16);
13741 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13742         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13743                                  pos_token, "eth-src");
13744 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13745         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13746                                     eth_src);
13747 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13749                                  pos_token, "eth-dst");
13750 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13751         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13752                                     eth_dst);
13753
13754 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13755         __rte_unused struct cmdline *cl,
13756         __rte_unused void *data)
13757 {
13758         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13759         union {
13760                 uint32_t mplsogre_label;
13761                 uint8_t label[4];
13762         } id = {
13763                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13764         };
13765
13766         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13767                 mplsogre_encap_conf.select_vlan = 0;
13768         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13769                 mplsogre_encap_conf.select_vlan = 1;
13770         if (strcmp(res->ip_version, "ipv4") == 0)
13771                 mplsogre_encap_conf.select_ipv4 = 1;
13772         else if (strcmp(res->ip_version, "ipv6") == 0)
13773                 mplsogre_encap_conf.select_ipv4 = 0;
13774         else
13775                 return;
13776         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13777         if (mplsogre_encap_conf.select_ipv4) {
13778                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13779                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13780         } else {
13781                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13782                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13783         }
13784         if (mplsogre_encap_conf.select_vlan)
13785                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13786         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13787                    RTE_ETHER_ADDR_LEN);
13788         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13789                    RTE_ETHER_ADDR_LEN);
13790 }
13791
13792 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13793         .f = cmd_set_mplsogre_encap_parsed,
13794         .data = NULL,
13795         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13796                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13797                 " eth-dst <eth-dst>",
13798         .tokens = {
13799                 (void *)&cmd_set_mplsogre_encap_set,
13800                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13801                 (void *)&cmd_set_mplsogre_encap_ip_version,
13802                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13803                 (void *)&cmd_set_mplsogre_encap_label,
13804                 (void *)&cmd_set_mplsogre_encap_label_value,
13805                 (void *)&cmd_set_mplsogre_encap_ip_src,
13806                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13807                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13808                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13809                 (void *)&cmd_set_mplsogre_encap_eth_src,
13810                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13811                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13812                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13813                 NULL,
13814         },
13815 };
13816
13817 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13818         .f = cmd_set_mplsogre_encap_parsed,
13819         .data = NULL,
13820         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13821                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13822                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13823         .tokens = {
13824                 (void *)&cmd_set_mplsogre_encap_set,
13825                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13826                 (void *)&cmd_set_mplsogre_encap_ip_version,
13827                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13828                 (void *)&cmd_set_mplsogre_encap_label,
13829                 (void *)&cmd_set_mplsogre_encap_label_value,
13830                 (void *)&cmd_set_mplsogre_encap_ip_src,
13831                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13832                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13833                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13834                 (void *)&cmd_set_mplsogre_encap_vlan,
13835                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13836                 (void *)&cmd_set_mplsogre_encap_eth_src,
13837                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13838                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13839                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13840                 NULL,
13841         },
13842 };
13843
13844 /** Set MPLSoGRE decapsulation details */
13845 struct cmd_set_mplsogre_decap_result {
13846         cmdline_fixed_string_t set;
13847         cmdline_fixed_string_t mplsogre;
13848         cmdline_fixed_string_t pos_token;
13849         cmdline_fixed_string_t ip_version;
13850         uint32_t vlan_present:1;
13851 };
13852
13853 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13854         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13855                                  "set");
13856 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13857         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13858                                  "mplsogre_decap");
13859 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13860         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13861                                  mplsogre, "mplsogre_decap-with-vlan");
13862 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13863         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13864                                  pos_token, "ip-version");
13865 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13866         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13867                                  ip_version, "ipv4#ipv6");
13868
13869 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13870         __rte_unused struct cmdline *cl,
13871         __rte_unused void *data)
13872 {
13873         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13874
13875         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13876                 mplsogre_decap_conf.select_vlan = 0;
13877         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13878                 mplsogre_decap_conf.select_vlan = 1;
13879         if (strcmp(res->ip_version, "ipv4") == 0)
13880                 mplsogre_decap_conf.select_ipv4 = 1;
13881         else if (strcmp(res->ip_version, "ipv6") == 0)
13882                 mplsogre_decap_conf.select_ipv4 = 0;
13883 }
13884
13885 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13886         .f = cmd_set_mplsogre_decap_parsed,
13887         .data = NULL,
13888         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13889         .tokens = {
13890                 (void *)&cmd_set_mplsogre_decap_set,
13891                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13892                 (void *)&cmd_set_mplsogre_decap_ip_version,
13893                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13894                 NULL,
13895         },
13896 };
13897
13898 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13899         .f = cmd_set_mplsogre_decap_parsed,
13900         .data = NULL,
13901         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13902         .tokens = {
13903                 (void *)&cmd_set_mplsogre_decap_set,
13904                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13905                 (void *)&cmd_set_mplsogre_decap_ip_version,
13906                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13907                 NULL,
13908         },
13909 };
13910
13911 /** Set MPLSoUDP encapsulation details */
13912 struct cmd_set_mplsoudp_encap_result {
13913         cmdline_fixed_string_t set;
13914         cmdline_fixed_string_t mplsoudp;
13915         cmdline_fixed_string_t pos_token;
13916         cmdline_fixed_string_t ip_version;
13917         uint32_t vlan_present:1;
13918         uint32_t label;
13919         uint16_t udp_src;
13920         uint16_t udp_dst;
13921         cmdline_ipaddr_t ip_src;
13922         cmdline_ipaddr_t ip_dst;
13923         uint16_t tci;
13924         struct rte_ether_addr eth_src;
13925         struct rte_ether_addr eth_dst;
13926 };
13927
13928 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13929         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13930                                  "set");
13931 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13932         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13933                                  "mplsoudp_encap");
13934 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13935         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13936                                  mplsoudp, "mplsoudp_encap-with-vlan");
13937 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13938         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13939                                  pos_token, "ip-version");
13940 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13941         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13942                                  ip_version, "ipv4#ipv6");
13943 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13944         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13945                                  pos_token, "label");
13946 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13947         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13948                               UINT32);
13949 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13950         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13951                                  pos_token, "udp-src");
13952 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13953         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13954                               UINT16);
13955 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13956         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13957                                  pos_token, "udp-dst");
13958 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13959         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13960                               UINT16);
13961 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13962         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13963                                  pos_token, "ip-src");
13964 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13965         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13966 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13967         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13968                                  pos_token, "ip-dst");
13969 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13970         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13971 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13972         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13973                                  pos_token, "vlan-tci");
13974 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13975         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13976                               UINT16);
13977 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13979                                  pos_token, "eth-src");
13980 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13981         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13982                                     eth_src);
13983 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13985                                  pos_token, "eth-dst");
13986 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13987         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13988                                     eth_dst);
13989
13990 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13991         __rte_unused struct cmdline *cl,
13992         __rte_unused void *data)
13993 {
13994         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13995         union {
13996                 uint32_t mplsoudp_label;
13997                 uint8_t label[4];
13998         } id = {
13999                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
14000         };
14001
14002         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
14003                 mplsoudp_encap_conf.select_vlan = 0;
14004         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
14005                 mplsoudp_encap_conf.select_vlan = 1;
14006         if (strcmp(res->ip_version, "ipv4") == 0)
14007                 mplsoudp_encap_conf.select_ipv4 = 1;
14008         else if (strcmp(res->ip_version, "ipv6") == 0)
14009                 mplsoudp_encap_conf.select_ipv4 = 0;
14010         else
14011                 return;
14012         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
14013         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14014         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14015         if (mplsoudp_encap_conf.select_ipv4) {
14016                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
14017                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
14018         } else {
14019                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
14020                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
14021         }
14022         if (mplsoudp_encap_conf.select_vlan)
14023                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14024         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
14025                    RTE_ETHER_ADDR_LEN);
14026         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14027                    RTE_ETHER_ADDR_LEN);
14028 }
14029
14030 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
14031         .f = cmd_set_mplsoudp_encap_parsed,
14032         .data = NULL,
14033         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
14034                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
14035                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
14036         .tokens = {
14037                 (void *)&cmd_set_mplsoudp_encap_set,
14038                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
14039                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14040                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14041                 (void *)&cmd_set_mplsoudp_encap_label,
14042                 (void *)&cmd_set_mplsoudp_encap_label_value,
14043                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14044                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14045                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14046                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14047                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14048                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14049                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14050                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14051                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14052                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14053                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14054                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14055                 NULL,
14056         },
14057 };
14058
14059 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
14060         .f = cmd_set_mplsoudp_encap_parsed,
14061         .data = NULL,
14062         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
14063                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
14064                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14065                 " eth-src <eth-src> eth-dst <eth-dst>",
14066         .tokens = {
14067                 (void *)&cmd_set_mplsoudp_encap_set,
14068                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
14069                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14070                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14071                 (void *)&cmd_set_mplsoudp_encap_label,
14072                 (void *)&cmd_set_mplsoudp_encap_label_value,
14073                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14074                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14075                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14076                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14077                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14078                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14079                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14080                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14081                 (void *)&cmd_set_mplsoudp_encap_vlan,
14082                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14083                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14084                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14085                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14086                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14087                 NULL,
14088         },
14089 };
14090
14091 /** Set MPLSoUDP decapsulation details */
14092 struct cmd_set_mplsoudp_decap_result {
14093         cmdline_fixed_string_t set;
14094         cmdline_fixed_string_t mplsoudp;
14095         cmdline_fixed_string_t pos_token;
14096         cmdline_fixed_string_t ip_version;
14097         uint32_t vlan_present:1;
14098 };
14099
14100 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14101         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14102                                  "set");
14103 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14104         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14105                                  "mplsoudp_decap");
14106 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14107         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14108                                  mplsoudp, "mplsoudp_decap-with-vlan");
14109 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14110         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14111                                  pos_token, "ip-version");
14112 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14113         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14114                                  ip_version, "ipv4#ipv6");
14115
14116 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14117         __rte_unused struct cmdline *cl,
14118         __rte_unused void *data)
14119 {
14120         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14121
14122         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14123                 mplsoudp_decap_conf.select_vlan = 0;
14124         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14125                 mplsoudp_decap_conf.select_vlan = 1;
14126         if (strcmp(res->ip_version, "ipv4") == 0)
14127                 mplsoudp_decap_conf.select_ipv4 = 1;
14128         else if (strcmp(res->ip_version, "ipv6") == 0)
14129                 mplsoudp_decap_conf.select_ipv4 = 0;
14130 }
14131
14132 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14133         .f = cmd_set_mplsoudp_decap_parsed,
14134         .data = NULL,
14135         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14136         .tokens = {
14137                 (void *)&cmd_set_mplsoudp_decap_set,
14138                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14139                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14140                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14141                 NULL,
14142         },
14143 };
14144
14145 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14146         .f = cmd_set_mplsoudp_decap_parsed,
14147         .data = NULL,
14148         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14149         .tokens = {
14150                 (void *)&cmd_set_mplsoudp_decap_set,
14151                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14152                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14153                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14154                 NULL,
14155         },
14156 };
14157
14158 /* Strict link priority scheduling mode setting */
14159 static void
14160 cmd_strict_link_prio_parsed(
14161         void *parsed_result,
14162         __rte_unused struct cmdline *cl,
14163         __rte_unused void *data)
14164 {
14165         struct cmd_vf_tc_bw_result *res = parsed_result;
14166         int ret = -ENOTSUP;
14167
14168         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14169                 return;
14170
14171 #ifdef RTE_NET_I40E
14172         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14173 #endif
14174
14175         switch (ret) {
14176         case 0:
14177                 break;
14178         case -EINVAL:
14179                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14180                 break;
14181         case -ENODEV:
14182                 printf("invalid port_id %d\n", res->port_id);
14183                 break;
14184         case -ENOTSUP:
14185                 printf("function not implemented\n");
14186                 break;
14187         default:
14188                 printf("programming error: (%s)\n", strerror(-ret));
14189         }
14190 }
14191
14192 cmdline_parse_inst_t cmd_strict_link_prio = {
14193         .f = cmd_strict_link_prio_parsed,
14194         .data = NULL,
14195         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14196         .tokens = {
14197                 (void *)&cmd_vf_tc_bw_set,
14198                 (void *)&cmd_vf_tc_bw_tx,
14199                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14200                 (void *)&cmd_vf_tc_bw_port_id,
14201                 (void *)&cmd_vf_tc_bw_tc_map,
14202                 NULL,
14203         },
14204 };
14205
14206 /* Load dynamic device personalization*/
14207 struct cmd_ddp_add_result {
14208         cmdline_fixed_string_t ddp;
14209         cmdline_fixed_string_t add;
14210         portid_t port_id;
14211         char filepath[];
14212 };
14213
14214 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14215         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14216 cmdline_parse_token_string_t cmd_ddp_add_add =
14217         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14218 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14219         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14220 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14221         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14222
14223 static void
14224 cmd_ddp_add_parsed(
14225         void *parsed_result,
14226         __rte_unused struct cmdline *cl,
14227         __rte_unused void *data)
14228 {
14229         struct cmd_ddp_add_result *res = parsed_result;
14230         uint8_t *buff;
14231         uint32_t size;
14232         char *filepath;
14233         char *file_fld[2];
14234         int file_num;
14235         int ret = -ENOTSUP;
14236
14237         if (!all_ports_stopped()) {
14238                 printf("Please stop all ports first\n");
14239                 return;
14240         }
14241
14242         filepath = strdup(res->filepath);
14243         if (filepath == NULL) {
14244                 printf("Failed to allocate memory\n");
14245                 return;
14246         }
14247         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14248
14249         buff = open_file(file_fld[0], &size);
14250         if (!buff) {
14251                 free((void *)filepath);
14252                 return;
14253         }
14254
14255 #ifdef RTE_NET_I40E
14256         if (ret == -ENOTSUP)
14257                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14258                                                buff, size,
14259                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14260 #endif
14261
14262         if (ret == -EEXIST)
14263                 printf("Profile has already existed.\n");
14264         else if (ret < 0)
14265                 printf("Failed to load profile.\n");
14266         else if (file_num == 2)
14267                 save_file(file_fld[1], buff, size);
14268
14269         close_file(buff);
14270         free((void *)filepath);
14271 }
14272
14273 cmdline_parse_inst_t cmd_ddp_add = {
14274         .f = cmd_ddp_add_parsed,
14275         .data = NULL,
14276         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14277         .tokens = {
14278                 (void *)&cmd_ddp_add_ddp,
14279                 (void *)&cmd_ddp_add_add,
14280                 (void *)&cmd_ddp_add_port_id,
14281                 (void *)&cmd_ddp_add_filepath,
14282                 NULL,
14283         },
14284 };
14285
14286 /* Delete dynamic device personalization*/
14287 struct cmd_ddp_del_result {
14288         cmdline_fixed_string_t ddp;
14289         cmdline_fixed_string_t del;
14290         portid_t port_id;
14291         char filepath[];
14292 };
14293
14294 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14295         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14296 cmdline_parse_token_string_t cmd_ddp_del_del =
14297         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14298 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14299         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14300 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14301         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14302
14303 static void
14304 cmd_ddp_del_parsed(
14305         void *parsed_result,
14306         __rte_unused struct cmdline *cl,
14307         __rte_unused void *data)
14308 {
14309         struct cmd_ddp_del_result *res = parsed_result;
14310         uint8_t *buff;
14311         uint32_t size;
14312         int ret = -ENOTSUP;
14313
14314         if (!all_ports_stopped()) {
14315                 printf("Please stop all ports first\n");
14316                 return;
14317         }
14318
14319         buff = open_file(res->filepath, &size);
14320         if (!buff)
14321                 return;
14322
14323 #ifdef RTE_NET_I40E
14324         if (ret == -ENOTSUP)
14325                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14326                                                buff, size,
14327                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14328 #endif
14329
14330         if (ret == -EACCES)
14331                 printf("Profile does not exist.\n");
14332         else if (ret < 0)
14333                 printf("Failed to delete profile.\n");
14334
14335         close_file(buff);
14336 }
14337
14338 cmdline_parse_inst_t cmd_ddp_del = {
14339         .f = cmd_ddp_del_parsed,
14340         .data = NULL,
14341         .help_str = "ddp del <port_id> <backup_profile_path>",
14342         .tokens = {
14343                 (void *)&cmd_ddp_del_ddp,
14344                 (void *)&cmd_ddp_del_del,
14345                 (void *)&cmd_ddp_del_port_id,
14346                 (void *)&cmd_ddp_del_filepath,
14347                 NULL,
14348         },
14349 };
14350
14351 /* Get dynamic device personalization profile info */
14352 struct cmd_ddp_info_result {
14353         cmdline_fixed_string_t ddp;
14354         cmdline_fixed_string_t get;
14355         cmdline_fixed_string_t info;
14356         char filepath[];
14357 };
14358
14359 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14360         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14361 cmdline_parse_token_string_t cmd_ddp_info_get =
14362         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14363 cmdline_parse_token_string_t cmd_ddp_info_info =
14364         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14365 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14366         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14367
14368 static void
14369 cmd_ddp_info_parsed(
14370         void *parsed_result,
14371         __rte_unused struct cmdline *cl,
14372         __rte_unused void *data)
14373 {
14374         struct cmd_ddp_info_result *res = parsed_result;
14375         uint8_t *pkg;
14376         uint32_t pkg_size;
14377         int ret = -ENOTSUP;
14378 #ifdef RTE_NET_I40E
14379         uint32_t i, j, n;
14380         uint8_t *buff;
14381         uint32_t buff_size = 0;
14382         struct rte_pmd_i40e_profile_info info;
14383         uint32_t dev_num = 0;
14384         struct rte_pmd_i40e_ddp_device_id *devs;
14385         uint32_t proto_num = 0;
14386         struct rte_pmd_i40e_proto_info *proto = NULL;
14387         uint32_t pctype_num = 0;
14388         struct rte_pmd_i40e_ptype_info *pctype;
14389         uint32_t ptype_num = 0;
14390         struct rte_pmd_i40e_ptype_info *ptype;
14391         uint8_t proto_id;
14392
14393 #endif
14394
14395         pkg = open_file(res->filepath, &pkg_size);
14396         if (!pkg)
14397                 return;
14398
14399 #ifdef RTE_NET_I40E
14400         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14401                                 (uint8_t *)&info, sizeof(info),
14402                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14403         if (!ret) {
14404                 printf("Global Track id:       0x%x\n", info.track_id);
14405                 printf("Global Version:        %d.%d.%d.%d\n",
14406                         info.version.major,
14407                         info.version.minor,
14408                         info.version.update,
14409                         info.version.draft);
14410                 printf("Global Package name:   %s\n\n", info.name);
14411         }
14412
14413         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14414                                 (uint8_t *)&info, sizeof(info),
14415                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14416         if (!ret) {
14417                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14418                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14419                         info.version.major,
14420                         info.version.minor,
14421                         info.version.update,
14422                         info.version.draft);
14423                 printf("i40e Profile name:     %s\n\n", info.name);
14424         }
14425
14426         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14427                                 (uint8_t *)&buff_size, sizeof(buff_size),
14428                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14429         if (!ret && buff_size) {
14430                 buff = (uint8_t *)malloc(buff_size);
14431                 if (buff) {
14432                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14433                                                 buff, buff_size,
14434                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14435                         if (!ret)
14436                                 printf("Package Notes:\n%s\n\n", buff);
14437                         free(buff);
14438                 }
14439         }
14440
14441         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14442                                 (uint8_t *)&dev_num, sizeof(dev_num),
14443                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14444         if (!ret && dev_num) {
14445                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14446                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14447                 if (devs) {
14448                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14449                                                 (uint8_t *)devs, buff_size,
14450                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14451                         if (!ret) {
14452                                 printf("List of supported devices:\n");
14453                                 for (i = 0; i < dev_num; i++) {
14454                                         printf("  %04X:%04X %04X:%04X\n",
14455                                                 devs[i].vendor_dev_id >> 16,
14456                                                 devs[i].vendor_dev_id & 0xFFFF,
14457                                                 devs[i].sub_vendor_dev_id >> 16,
14458                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14459                                 }
14460                                 printf("\n");
14461                         }
14462                         free(devs);
14463                 }
14464         }
14465
14466         /* get information about protocols and packet types */
14467         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14468                 (uint8_t *)&proto_num, sizeof(proto_num),
14469                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14470         if (ret || !proto_num)
14471                 goto no_print_return;
14472
14473         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14474         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14475         if (!proto)
14476                 goto no_print_return;
14477
14478         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14479                                         buff_size,
14480                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14481         if (!ret) {
14482                 printf("List of used protocols:\n");
14483                 for (i = 0; i < proto_num; i++)
14484                         printf("  %2u: %s\n", proto[i].proto_id,
14485                                proto[i].name);
14486                 printf("\n");
14487         }
14488         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14489                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14490                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14491         if (ret || !pctype_num)
14492                 goto no_print_pctypes;
14493
14494         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14495         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14496         if (!pctype)
14497                 goto no_print_pctypes;
14498
14499         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14500                                         buff_size,
14501                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14502         if (ret) {
14503                 free(pctype);
14504                 goto no_print_pctypes;
14505         }
14506
14507         printf("List of defined packet classification types:\n");
14508         for (i = 0; i < pctype_num; i++) {
14509                 printf("  %2u:", pctype[i].ptype_id);
14510                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14511                         proto_id = pctype[i].protocols[j];
14512                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14513                                 for (n = 0; n < proto_num; n++) {
14514                                         if (proto[n].proto_id == proto_id) {
14515                                                 printf(" %s", proto[n].name);
14516                                                 break;
14517                                         }
14518                                 }
14519                         }
14520                 }
14521                 printf("\n");
14522         }
14523         printf("\n");
14524         free(pctype);
14525
14526 no_print_pctypes:
14527
14528         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14529                                         sizeof(ptype_num),
14530                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14531         if (ret || !ptype_num)
14532                 goto no_print_return;
14533
14534         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14535         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14536         if (!ptype)
14537                 goto no_print_return;
14538
14539         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14540                                         buff_size,
14541                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14542         if (ret) {
14543                 free(ptype);
14544                 goto no_print_return;
14545         }
14546         printf("List of defined packet types:\n");
14547         for (i = 0; i < ptype_num; i++) {
14548                 printf("  %2u:", ptype[i].ptype_id);
14549                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14550                         proto_id = ptype[i].protocols[j];
14551                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14552                                 for (n = 0; n < proto_num; n++) {
14553                                         if (proto[n].proto_id == proto_id) {
14554                                                 printf(" %s", proto[n].name);
14555                                                 break;
14556                                         }
14557                                 }
14558                         }
14559                 }
14560                 printf("\n");
14561         }
14562         free(ptype);
14563         printf("\n");
14564
14565         ret = 0;
14566 no_print_return:
14567         if (proto)
14568                 free(proto);
14569 #endif
14570         if (ret == -ENOTSUP)
14571                 printf("Function not supported in PMD driver\n");
14572         close_file(pkg);
14573 }
14574
14575 cmdline_parse_inst_t cmd_ddp_get_info = {
14576         .f = cmd_ddp_info_parsed,
14577         .data = NULL,
14578         .help_str = "ddp get info <profile_path>",
14579         .tokens = {
14580                 (void *)&cmd_ddp_info_ddp,
14581                 (void *)&cmd_ddp_info_get,
14582                 (void *)&cmd_ddp_info_info,
14583                 (void *)&cmd_ddp_info_filepath,
14584                 NULL,
14585         },
14586 };
14587
14588 /* Get dynamic device personalization profile info list*/
14589 #define PROFILE_INFO_SIZE 48
14590 #define MAX_PROFILE_NUM 16
14591
14592 struct cmd_ddp_get_list_result {
14593         cmdline_fixed_string_t ddp;
14594         cmdline_fixed_string_t get;
14595         cmdline_fixed_string_t list;
14596         portid_t port_id;
14597 };
14598
14599 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14600         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14601 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14602         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14603 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14604         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14605 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14606         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14607
14608 static void
14609 cmd_ddp_get_list_parsed(
14610         __rte_unused void *parsed_result,
14611         __rte_unused struct cmdline *cl,
14612         __rte_unused void *data)
14613 {
14614 #ifdef RTE_NET_I40E
14615         struct cmd_ddp_get_list_result *res = parsed_result;
14616         struct rte_pmd_i40e_profile_list *p_list;
14617         struct rte_pmd_i40e_profile_info *p_info;
14618         uint32_t p_num;
14619         uint32_t size;
14620         uint32_t i;
14621 #endif
14622         int ret = -ENOTSUP;
14623
14624 #ifdef RTE_NET_I40E
14625         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14626         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14627         if (!p_list) {
14628                 printf("%s: Failed to malloc buffer\n", __func__);
14629                 return;
14630         }
14631
14632         if (ret == -ENOTSUP)
14633                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14634                                                 (uint8_t *)p_list, size);
14635
14636         if (!ret) {
14637                 p_num = p_list->p_count;
14638                 printf("Profile number is: %d\n\n", p_num);
14639
14640                 for (i = 0; i < p_num; i++) {
14641                         p_info = &p_list->p_info[i];
14642                         printf("Profile %d:\n", i);
14643                         printf("Track id:     0x%x\n", p_info->track_id);
14644                         printf("Version:      %d.%d.%d.%d\n",
14645                                p_info->version.major,
14646                                p_info->version.minor,
14647                                p_info->version.update,
14648                                p_info->version.draft);
14649                         printf("Profile name: %s\n\n", p_info->name);
14650                 }
14651         }
14652
14653         free(p_list);
14654 #endif
14655
14656         if (ret < 0)
14657                 printf("Failed to get ddp list\n");
14658 }
14659
14660 cmdline_parse_inst_t cmd_ddp_get_list = {
14661         .f = cmd_ddp_get_list_parsed,
14662         .data = NULL,
14663         .help_str = "ddp get list <port_id>",
14664         .tokens = {
14665                 (void *)&cmd_ddp_get_list_ddp,
14666                 (void *)&cmd_ddp_get_list_get,
14667                 (void *)&cmd_ddp_get_list_list,
14668                 (void *)&cmd_ddp_get_list_port_id,
14669                 NULL,
14670         },
14671 };
14672
14673 /* Configure input set */
14674 struct cmd_cfg_input_set_result {
14675         cmdline_fixed_string_t port;
14676         cmdline_fixed_string_t cfg;
14677         portid_t port_id;
14678         cmdline_fixed_string_t pctype;
14679         uint8_t pctype_id;
14680         cmdline_fixed_string_t inset_type;
14681         cmdline_fixed_string_t opt;
14682         cmdline_fixed_string_t field;
14683         uint8_t field_idx;
14684 };
14685
14686 static void
14687 cmd_cfg_input_set_parsed(
14688         __rte_unused void *parsed_result,
14689         __rte_unused struct cmdline *cl,
14690         __rte_unused void *data)
14691 {
14692 #ifdef RTE_NET_I40E
14693         struct cmd_cfg_input_set_result *res = parsed_result;
14694         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14695         struct rte_pmd_i40e_inset inset;
14696 #endif
14697         int ret = -ENOTSUP;
14698
14699         if (!all_ports_stopped()) {
14700                 printf("Please stop all ports first\n");
14701                 return;
14702         }
14703
14704 #ifdef RTE_NET_I40E
14705         if (!strcmp(res->inset_type, "hash_inset"))
14706                 inset_type = INSET_HASH;
14707         else if (!strcmp(res->inset_type, "fdir_inset"))
14708                 inset_type = INSET_FDIR;
14709         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14710                 inset_type = INSET_FDIR_FLX;
14711         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14712                                      &inset, inset_type);
14713         if (ret) {
14714                 printf("Failed to get input set.\n");
14715                 return;
14716         }
14717
14718         if (!strcmp(res->opt, "get")) {
14719                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14720                                                    res->field_idx);
14721                 if (ret)
14722                         printf("Field index %d is enabled.\n", res->field_idx);
14723                 else
14724                         printf("Field index %d is disabled.\n", res->field_idx);
14725                 return;
14726         } else if (!strcmp(res->opt, "set"))
14727                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14728                                                    res->field_idx);
14729         else if (!strcmp(res->opt, "clear"))
14730                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14731                                                      res->field_idx);
14732         if (ret) {
14733                 printf("Failed to configure input set field.\n");
14734                 return;
14735         }
14736
14737         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14738                                      &inset, inset_type);
14739         if (ret) {
14740                 printf("Failed to set input set.\n");
14741                 return;
14742         }
14743 #endif
14744
14745         if (ret == -ENOTSUP)
14746                 printf("Function not supported\n");
14747 }
14748
14749 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14750         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14751                                  port, "port");
14752 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14753         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14754                                  cfg, "config");
14755 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14756         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14757                               port_id, UINT16);
14758 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14759         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14760                                  pctype, "pctype");
14761 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14762         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14763                               pctype_id, UINT8);
14764 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14765         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14766                                  inset_type,
14767                                  "hash_inset#fdir_inset#fdir_flx_inset");
14768 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14769         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14770                                  opt, "get#set#clear");
14771 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14772         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14773                                  field, "field");
14774 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14775         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14776                               field_idx, UINT8);
14777
14778 cmdline_parse_inst_t cmd_cfg_input_set = {
14779         .f = cmd_cfg_input_set_parsed,
14780         .data = NULL,
14781         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14782                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14783         .tokens = {
14784                 (void *)&cmd_cfg_input_set_port,
14785                 (void *)&cmd_cfg_input_set_cfg,
14786                 (void *)&cmd_cfg_input_set_port_id,
14787                 (void *)&cmd_cfg_input_set_pctype,
14788                 (void *)&cmd_cfg_input_set_pctype_id,
14789                 (void *)&cmd_cfg_input_set_inset_type,
14790                 (void *)&cmd_cfg_input_set_opt,
14791                 (void *)&cmd_cfg_input_set_field,
14792                 (void *)&cmd_cfg_input_set_field_idx,
14793                 NULL,
14794         },
14795 };
14796
14797 /* Clear input set */
14798 struct cmd_clear_input_set_result {
14799         cmdline_fixed_string_t port;
14800         cmdline_fixed_string_t cfg;
14801         portid_t port_id;
14802         cmdline_fixed_string_t pctype;
14803         uint8_t pctype_id;
14804         cmdline_fixed_string_t inset_type;
14805         cmdline_fixed_string_t clear;
14806         cmdline_fixed_string_t all;
14807 };
14808
14809 static void
14810 cmd_clear_input_set_parsed(
14811         __rte_unused void *parsed_result,
14812         __rte_unused struct cmdline *cl,
14813         __rte_unused void *data)
14814 {
14815 #ifdef RTE_NET_I40E
14816         struct cmd_clear_input_set_result *res = parsed_result;
14817         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14818         struct rte_pmd_i40e_inset inset;
14819 #endif
14820         int ret = -ENOTSUP;
14821
14822         if (!all_ports_stopped()) {
14823                 printf("Please stop all ports first\n");
14824                 return;
14825         }
14826
14827 #ifdef RTE_NET_I40E
14828         if (!strcmp(res->inset_type, "hash_inset"))
14829                 inset_type = INSET_HASH;
14830         else if (!strcmp(res->inset_type, "fdir_inset"))
14831                 inset_type = INSET_FDIR;
14832         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14833                 inset_type = INSET_FDIR_FLX;
14834
14835         memset(&inset, 0, sizeof(inset));
14836
14837         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14838                                      &inset, inset_type);
14839         if (ret) {
14840                 printf("Failed to clear input set.\n");
14841                 return;
14842         }
14843
14844 #endif
14845
14846         if (ret == -ENOTSUP)
14847                 printf("Function not supported\n");
14848 }
14849
14850 cmdline_parse_token_string_t cmd_clear_input_set_port =
14851         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14852                                  port, "port");
14853 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14854         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14855                                  cfg, "config");
14856 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14857         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14858                               port_id, UINT16);
14859 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14860         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14861                                  pctype, "pctype");
14862 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14863         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14864                               pctype_id, UINT8);
14865 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14866         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14867                                  inset_type,
14868                                  "hash_inset#fdir_inset#fdir_flx_inset");
14869 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14870         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14871                                  clear, "clear");
14872 cmdline_parse_token_string_t cmd_clear_input_set_all =
14873         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14874                                  all, "all");
14875
14876 cmdline_parse_inst_t cmd_clear_input_set = {
14877         .f = cmd_clear_input_set_parsed,
14878         .data = NULL,
14879         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14880                     "fdir_inset|fdir_flx_inset clear all",
14881         .tokens = {
14882                 (void *)&cmd_clear_input_set_port,
14883                 (void *)&cmd_clear_input_set_cfg,
14884                 (void *)&cmd_clear_input_set_port_id,
14885                 (void *)&cmd_clear_input_set_pctype,
14886                 (void *)&cmd_clear_input_set_pctype_id,
14887                 (void *)&cmd_clear_input_set_inset_type,
14888                 (void *)&cmd_clear_input_set_clear,
14889                 (void *)&cmd_clear_input_set_all,
14890                 NULL,
14891         },
14892 };
14893
14894 /* show vf stats */
14895
14896 /* Common result structure for show vf stats */
14897 struct cmd_show_vf_stats_result {
14898         cmdline_fixed_string_t show;
14899         cmdline_fixed_string_t vf;
14900         cmdline_fixed_string_t stats;
14901         portid_t port_id;
14902         uint16_t vf_id;
14903 };
14904
14905 /* Common CLI fields show vf stats*/
14906 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14907         TOKEN_STRING_INITIALIZER
14908                 (struct cmd_show_vf_stats_result,
14909                  show, "show");
14910 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14911         TOKEN_STRING_INITIALIZER
14912                 (struct cmd_show_vf_stats_result,
14913                  vf, "vf");
14914 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14915         TOKEN_STRING_INITIALIZER
14916                 (struct cmd_show_vf_stats_result,
14917                  stats, "stats");
14918 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14919         TOKEN_NUM_INITIALIZER
14920                 (struct cmd_show_vf_stats_result,
14921                  port_id, UINT16);
14922 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14923         TOKEN_NUM_INITIALIZER
14924                 (struct cmd_show_vf_stats_result,
14925                  vf_id, UINT16);
14926
14927 static void
14928 cmd_show_vf_stats_parsed(
14929         void *parsed_result,
14930         __rte_unused struct cmdline *cl,
14931         __rte_unused void *data)
14932 {
14933         struct cmd_show_vf_stats_result *res = parsed_result;
14934         struct rte_eth_stats stats;
14935         int ret = -ENOTSUP;
14936         static const char *nic_stats_border = "########################";
14937
14938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14939                 return;
14940
14941         memset(&stats, 0, sizeof(stats));
14942
14943 #ifdef RTE_NET_I40E
14944         if (ret == -ENOTSUP)
14945                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14946                                                 res->vf_id,
14947                                                 &stats);
14948 #endif
14949 #ifdef RTE_NET_BNXT
14950         if (ret == -ENOTSUP)
14951                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14952                                                 res->vf_id,
14953                                                 &stats);
14954 #endif
14955
14956         switch (ret) {
14957         case 0:
14958                 break;
14959         case -EINVAL:
14960                 printf("invalid vf_id %d\n", res->vf_id);
14961                 break;
14962         case -ENODEV:
14963                 printf("invalid port_id %d\n", res->port_id);
14964                 break;
14965         case -ENOTSUP:
14966                 printf("function not implemented\n");
14967                 break;
14968         default:
14969                 printf("programming error: (%s)\n", strerror(-ret));
14970         }
14971
14972         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14973                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14974
14975         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14976                "%-"PRIu64"\n",
14977                stats.ipackets, stats.imissed, stats.ibytes);
14978         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14979         printf("  RX-nombuf:  %-10"PRIu64"\n",
14980                stats.rx_nombuf);
14981         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14982                "%-"PRIu64"\n",
14983                stats.opackets, stats.oerrors, stats.obytes);
14984
14985         printf("  %s############################%s\n",
14986                                nic_stats_border, nic_stats_border);
14987 }
14988
14989 cmdline_parse_inst_t cmd_show_vf_stats = {
14990         .f = cmd_show_vf_stats_parsed,
14991         .data = NULL,
14992         .help_str = "show vf stats <port_id> <vf_id>",
14993         .tokens = {
14994                 (void *)&cmd_show_vf_stats_show,
14995                 (void *)&cmd_show_vf_stats_vf,
14996                 (void *)&cmd_show_vf_stats_stats,
14997                 (void *)&cmd_show_vf_stats_port_id,
14998                 (void *)&cmd_show_vf_stats_vf_id,
14999                 NULL,
15000         },
15001 };
15002
15003 /* clear vf stats */
15004
15005 /* Common result structure for clear vf stats */
15006 struct cmd_clear_vf_stats_result {
15007         cmdline_fixed_string_t clear;
15008         cmdline_fixed_string_t vf;
15009         cmdline_fixed_string_t stats;
15010         portid_t port_id;
15011         uint16_t vf_id;
15012 };
15013
15014 /* Common CLI fields clear vf stats*/
15015 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15016         TOKEN_STRING_INITIALIZER
15017                 (struct cmd_clear_vf_stats_result,
15018                  clear, "clear");
15019 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15020         TOKEN_STRING_INITIALIZER
15021                 (struct cmd_clear_vf_stats_result,
15022                  vf, "vf");
15023 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15024         TOKEN_STRING_INITIALIZER
15025                 (struct cmd_clear_vf_stats_result,
15026                  stats, "stats");
15027 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15028         TOKEN_NUM_INITIALIZER
15029                 (struct cmd_clear_vf_stats_result,
15030                  port_id, UINT16);
15031 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15032         TOKEN_NUM_INITIALIZER
15033                 (struct cmd_clear_vf_stats_result,
15034                  vf_id, UINT16);
15035
15036 static void
15037 cmd_clear_vf_stats_parsed(
15038         void *parsed_result,
15039         __rte_unused struct cmdline *cl,
15040         __rte_unused void *data)
15041 {
15042         struct cmd_clear_vf_stats_result *res = parsed_result;
15043         int ret = -ENOTSUP;
15044
15045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15046                 return;
15047
15048 #ifdef RTE_NET_I40E
15049         if (ret == -ENOTSUP)
15050                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15051                                                   res->vf_id);
15052 #endif
15053 #ifdef RTE_NET_BNXT
15054         if (ret == -ENOTSUP)
15055                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15056                                                   res->vf_id);
15057 #endif
15058
15059         switch (ret) {
15060         case 0:
15061                 break;
15062         case -EINVAL:
15063                 printf("invalid vf_id %d\n", res->vf_id);
15064                 break;
15065         case -ENODEV:
15066                 printf("invalid port_id %d\n", res->port_id);
15067                 break;
15068         case -ENOTSUP:
15069                 printf("function not implemented\n");
15070                 break;
15071         default:
15072                 printf("programming error: (%s)\n", strerror(-ret));
15073         }
15074 }
15075
15076 cmdline_parse_inst_t cmd_clear_vf_stats = {
15077         .f = cmd_clear_vf_stats_parsed,
15078         .data = NULL,
15079         .help_str = "clear vf stats <port_id> <vf_id>",
15080         .tokens = {
15081                 (void *)&cmd_clear_vf_stats_clear,
15082                 (void *)&cmd_clear_vf_stats_vf,
15083                 (void *)&cmd_clear_vf_stats_stats,
15084                 (void *)&cmd_clear_vf_stats_port_id,
15085                 (void *)&cmd_clear_vf_stats_vf_id,
15086                 NULL,
15087         },
15088 };
15089
15090 /* port config pctype mapping reset */
15091
15092 /* Common result structure for port config pctype mapping reset */
15093 struct cmd_pctype_mapping_reset_result {
15094         cmdline_fixed_string_t port;
15095         cmdline_fixed_string_t config;
15096         portid_t port_id;
15097         cmdline_fixed_string_t pctype;
15098         cmdline_fixed_string_t mapping;
15099         cmdline_fixed_string_t reset;
15100 };
15101
15102 /* Common CLI fields for port config pctype mapping reset*/
15103 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15104         TOKEN_STRING_INITIALIZER
15105                 (struct cmd_pctype_mapping_reset_result,
15106                  port, "port");
15107 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15108         TOKEN_STRING_INITIALIZER
15109                 (struct cmd_pctype_mapping_reset_result,
15110                  config, "config");
15111 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15112         TOKEN_NUM_INITIALIZER
15113                 (struct cmd_pctype_mapping_reset_result,
15114                  port_id, UINT16);
15115 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15116         TOKEN_STRING_INITIALIZER
15117                 (struct cmd_pctype_mapping_reset_result,
15118                  pctype, "pctype");
15119 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15120         TOKEN_STRING_INITIALIZER
15121                 (struct cmd_pctype_mapping_reset_result,
15122                  mapping, "mapping");
15123 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15124         TOKEN_STRING_INITIALIZER
15125                 (struct cmd_pctype_mapping_reset_result,
15126                  reset, "reset");
15127
15128 static void
15129 cmd_pctype_mapping_reset_parsed(
15130         void *parsed_result,
15131         __rte_unused struct cmdline *cl,
15132         __rte_unused void *data)
15133 {
15134         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15135         int ret = -ENOTSUP;
15136
15137         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15138                 return;
15139
15140 #ifdef RTE_NET_I40E
15141         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15142 #endif
15143
15144         switch (ret) {
15145         case 0:
15146                 break;
15147         case -ENODEV:
15148                 printf("invalid port_id %d\n", res->port_id);
15149                 break;
15150         case -ENOTSUP:
15151                 printf("function not implemented\n");
15152                 break;
15153         default:
15154                 printf("programming error: (%s)\n", strerror(-ret));
15155         }
15156 }
15157
15158 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15159         .f = cmd_pctype_mapping_reset_parsed,
15160         .data = NULL,
15161         .help_str = "port config <port_id> pctype mapping reset",
15162         .tokens = {
15163                 (void *)&cmd_pctype_mapping_reset_port,
15164                 (void *)&cmd_pctype_mapping_reset_config,
15165                 (void *)&cmd_pctype_mapping_reset_port_id,
15166                 (void *)&cmd_pctype_mapping_reset_pctype,
15167                 (void *)&cmd_pctype_mapping_reset_mapping,
15168                 (void *)&cmd_pctype_mapping_reset_reset,
15169                 NULL,
15170         },
15171 };
15172
15173 /* show port pctype mapping */
15174
15175 /* Common result structure for show port pctype mapping */
15176 struct cmd_pctype_mapping_get_result {
15177         cmdline_fixed_string_t show;
15178         cmdline_fixed_string_t port;
15179         portid_t port_id;
15180         cmdline_fixed_string_t pctype;
15181         cmdline_fixed_string_t mapping;
15182 };
15183
15184 /* Common CLI fields for pctype mapping get */
15185 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15186         TOKEN_STRING_INITIALIZER
15187                 (struct cmd_pctype_mapping_get_result,
15188                  show, "show");
15189 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15190         TOKEN_STRING_INITIALIZER
15191                 (struct cmd_pctype_mapping_get_result,
15192                  port, "port");
15193 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15194         TOKEN_NUM_INITIALIZER
15195                 (struct cmd_pctype_mapping_get_result,
15196                  port_id, UINT16);
15197 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15198         TOKEN_STRING_INITIALIZER
15199                 (struct cmd_pctype_mapping_get_result,
15200                  pctype, "pctype");
15201 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15202         TOKEN_STRING_INITIALIZER
15203                 (struct cmd_pctype_mapping_get_result,
15204                  mapping, "mapping");
15205
15206 static void
15207 cmd_pctype_mapping_get_parsed(
15208         void *parsed_result,
15209         __rte_unused struct cmdline *cl,
15210         __rte_unused void *data)
15211 {
15212         struct cmd_pctype_mapping_get_result *res = parsed_result;
15213         int ret = -ENOTSUP;
15214 #ifdef RTE_NET_I40E
15215         struct rte_pmd_i40e_flow_type_mapping
15216                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15217         int i, j, first_pctype;
15218 #endif
15219
15220         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15221                 return;
15222
15223 #ifdef RTE_NET_I40E
15224         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15225 #endif
15226
15227         switch (ret) {
15228         case 0:
15229                 break;
15230         case -ENODEV:
15231                 printf("invalid port_id %d\n", res->port_id);
15232                 return;
15233         case -ENOTSUP:
15234                 printf("function not implemented\n");
15235                 return;
15236         default:
15237                 printf("programming error: (%s)\n", strerror(-ret));
15238                 return;
15239         }
15240
15241 #ifdef RTE_NET_I40E
15242         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15243                 if (mapping[i].pctype != 0ULL) {
15244                         first_pctype = 1;
15245
15246                         printf("pctype: ");
15247                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15248                                 if (mapping[i].pctype & (1ULL << j)) {
15249                                         printf(first_pctype ?
15250                                                "%02d" : ",%02d", j);
15251                                         first_pctype = 0;
15252                                 }
15253                         }
15254                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15255                 }
15256         }
15257 #endif
15258 }
15259
15260 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15261         .f = cmd_pctype_mapping_get_parsed,
15262         .data = NULL,
15263         .help_str = "show port <port_id> pctype mapping",
15264         .tokens = {
15265                 (void *)&cmd_pctype_mapping_get_show,
15266                 (void *)&cmd_pctype_mapping_get_port,
15267                 (void *)&cmd_pctype_mapping_get_port_id,
15268                 (void *)&cmd_pctype_mapping_get_pctype,
15269                 (void *)&cmd_pctype_mapping_get_mapping,
15270                 NULL,
15271         },
15272 };
15273
15274 /* port config pctype mapping update */
15275
15276 /* Common result structure for port config pctype mapping update */
15277 struct cmd_pctype_mapping_update_result {
15278         cmdline_fixed_string_t port;
15279         cmdline_fixed_string_t config;
15280         portid_t port_id;
15281         cmdline_fixed_string_t pctype;
15282         cmdline_fixed_string_t mapping;
15283         cmdline_fixed_string_t update;
15284         cmdline_fixed_string_t pctype_list;
15285         uint16_t flow_type;
15286 };
15287
15288 /* Common CLI fields for pctype mapping update*/
15289 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15290         TOKEN_STRING_INITIALIZER
15291                 (struct cmd_pctype_mapping_update_result,
15292                  port, "port");
15293 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15294         TOKEN_STRING_INITIALIZER
15295                 (struct cmd_pctype_mapping_update_result,
15296                  config, "config");
15297 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15298         TOKEN_NUM_INITIALIZER
15299                 (struct cmd_pctype_mapping_update_result,
15300                  port_id, UINT16);
15301 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15302         TOKEN_STRING_INITIALIZER
15303                 (struct cmd_pctype_mapping_update_result,
15304                  pctype, "pctype");
15305 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15306         TOKEN_STRING_INITIALIZER
15307                 (struct cmd_pctype_mapping_update_result,
15308                  mapping, "mapping");
15309 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15310         TOKEN_STRING_INITIALIZER
15311                 (struct cmd_pctype_mapping_update_result,
15312                  update, "update");
15313 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15314         TOKEN_STRING_INITIALIZER
15315                 (struct cmd_pctype_mapping_update_result,
15316                  pctype_list, NULL);
15317 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15318         TOKEN_NUM_INITIALIZER
15319                 (struct cmd_pctype_mapping_update_result,
15320                  flow_type, UINT16);
15321
15322 static void
15323 cmd_pctype_mapping_update_parsed(
15324         void *parsed_result,
15325         __rte_unused struct cmdline *cl,
15326         __rte_unused void *data)
15327 {
15328         struct cmd_pctype_mapping_update_result *res = parsed_result;
15329         int ret = -ENOTSUP;
15330 #ifdef RTE_NET_I40E
15331         struct rte_pmd_i40e_flow_type_mapping mapping;
15332         unsigned int i;
15333         unsigned int nb_item;
15334         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15335 #endif
15336
15337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15338                 return;
15339
15340 #ifdef RTE_NET_I40E
15341         nb_item = parse_item_list(res->pctype_list, "pctypes",
15342                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15343         mapping.flow_type = res->flow_type;
15344         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15345                 mapping.pctype |= (1ULL << pctype_list[i]);
15346         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15347                                                 &mapping,
15348                                                 1,
15349                                                 0);
15350 #endif
15351
15352         switch (ret) {
15353         case 0:
15354                 break;
15355         case -EINVAL:
15356                 printf("invalid pctype or flow type\n");
15357                 break;
15358         case -ENODEV:
15359                 printf("invalid port_id %d\n", res->port_id);
15360                 break;
15361         case -ENOTSUP:
15362                 printf("function not implemented\n");
15363                 break;
15364         default:
15365                 printf("programming error: (%s)\n", strerror(-ret));
15366         }
15367 }
15368
15369 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15370         .f = cmd_pctype_mapping_update_parsed,
15371         .data = NULL,
15372         .help_str = "port config <port_id> pctype mapping update"
15373         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15374         .tokens = {
15375                 (void *)&cmd_pctype_mapping_update_port,
15376                 (void *)&cmd_pctype_mapping_update_config,
15377                 (void *)&cmd_pctype_mapping_update_port_id,
15378                 (void *)&cmd_pctype_mapping_update_pctype,
15379                 (void *)&cmd_pctype_mapping_update_mapping,
15380                 (void *)&cmd_pctype_mapping_update_update,
15381                 (void *)&cmd_pctype_mapping_update_pc_type,
15382                 (void *)&cmd_pctype_mapping_update_flow_type,
15383                 NULL,
15384         },
15385 };
15386
15387 /* ptype mapping get */
15388
15389 /* Common result structure for ptype mapping get */
15390 struct cmd_ptype_mapping_get_result {
15391         cmdline_fixed_string_t ptype;
15392         cmdline_fixed_string_t mapping;
15393         cmdline_fixed_string_t get;
15394         portid_t port_id;
15395         uint8_t valid_only;
15396 };
15397
15398 /* Common CLI fields for ptype mapping get */
15399 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15400         TOKEN_STRING_INITIALIZER
15401                 (struct cmd_ptype_mapping_get_result,
15402                  ptype, "ptype");
15403 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15404         TOKEN_STRING_INITIALIZER
15405                 (struct cmd_ptype_mapping_get_result,
15406                  mapping, "mapping");
15407 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15408         TOKEN_STRING_INITIALIZER
15409                 (struct cmd_ptype_mapping_get_result,
15410                  get, "get");
15411 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15412         TOKEN_NUM_INITIALIZER
15413                 (struct cmd_ptype_mapping_get_result,
15414                  port_id, UINT16);
15415 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15416         TOKEN_NUM_INITIALIZER
15417                 (struct cmd_ptype_mapping_get_result,
15418                  valid_only, UINT8);
15419
15420 static void
15421 cmd_ptype_mapping_get_parsed(
15422         void *parsed_result,
15423         __rte_unused struct cmdline *cl,
15424         __rte_unused void *data)
15425 {
15426         struct cmd_ptype_mapping_get_result *res = parsed_result;
15427         int ret = -ENOTSUP;
15428 #ifdef RTE_NET_I40E
15429         int max_ptype_num = 256;
15430         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15431         uint16_t count;
15432         int i;
15433 #endif
15434
15435         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15436                 return;
15437
15438 #ifdef RTE_NET_I40E
15439         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15440                                         mapping,
15441                                         max_ptype_num,
15442                                         &count,
15443                                         res->valid_only);
15444 #endif
15445
15446         switch (ret) {
15447         case 0:
15448                 break;
15449         case -ENODEV:
15450                 printf("invalid port_id %d\n", res->port_id);
15451                 break;
15452         case -ENOTSUP:
15453                 printf("function not implemented\n");
15454                 break;
15455         default:
15456                 printf("programming error: (%s)\n", strerror(-ret));
15457         }
15458
15459 #ifdef RTE_NET_I40E
15460         if (!ret) {
15461                 for (i = 0; i < count; i++)
15462                         printf("%3d\t0x%08x\n",
15463                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15464         }
15465 #endif
15466 }
15467
15468 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15469         .f = cmd_ptype_mapping_get_parsed,
15470         .data = NULL,
15471         .help_str = "ptype mapping get <port_id> <valid_only>",
15472         .tokens = {
15473                 (void *)&cmd_ptype_mapping_get_ptype,
15474                 (void *)&cmd_ptype_mapping_get_mapping,
15475                 (void *)&cmd_ptype_mapping_get_get,
15476                 (void *)&cmd_ptype_mapping_get_port_id,
15477                 (void *)&cmd_ptype_mapping_get_valid_only,
15478                 NULL,
15479         },
15480 };
15481
15482 /* ptype mapping replace */
15483
15484 /* Common result structure for ptype mapping replace */
15485 struct cmd_ptype_mapping_replace_result {
15486         cmdline_fixed_string_t ptype;
15487         cmdline_fixed_string_t mapping;
15488         cmdline_fixed_string_t replace;
15489         portid_t port_id;
15490         uint32_t target;
15491         uint8_t mask;
15492         uint32_t pkt_type;
15493 };
15494
15495 /* Common CLI fields for ptype mapping replace */
15496 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15497         TOKEN_STRING_INITIALIZER
15498                 (struct cmd_ptype_mapping_replace_result,
15499                  ptype, "ptype");
15500 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15501         TOKEN_STRING_INITIALIZER
15502                 (struct cmd_ptype_mapping_replace_result,
15503                  mapping, "mapping");
15504 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15505         TOKEN_STRING_INITIALIZER
15506                 (struct cmd_ptype_mapping_replace_result,
15507                  replace, "replace");
15508 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15509         TOKEN_NUM_INITIALIZER
15510                 (struct cmd_ptype_mapping_replace_result,
15511                  port_id, UINT16);
15512 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15513         TOKEN_NUM_INITIALIZER
15514                 (struct cmd_ptype_mapping_replace_result,
15515                  target, UINT32);
15516 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15517         TOKEN_NUM_INITIALIZER
15518                 (struct cmd_ptype_mapping_replace_result,
15519                  mask, UINT8);
15520 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15521         TOKEN_NUM_INITIALIZER
15522                 (struct cmd_ptype_mapping_replace_result,
15523                  pkt_type, UINT32);
15524
15525 static void
15526 cmd_ptype_mapping_replace_parsed(
15527         void *parsed_result,
15528         __rte_unused struct cmdline *cl,
15529         __rte_unused void *data)
15530 {
15531         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15532         int ret = -ENOTSUP;
15533
15534         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15535                 return;
15536
15537 #ifdef RTE_NET_I40E
15538         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15539                                         res->target,
15540                                         res->mask,
15541                                         res->pkt_type);
15542 #endif
15543
15544         switch (ret) {
15545         case 0:
15546                 break;
15547         case -EINVAL:
15548                 printf("invalid ptype 0x%8x or 0x%8x\n",
15549                                 res->target, res->pkt_type);
15550                 break;
15551         case -ENODEV:
15552                 printf("invalid port_id %d\n", res->port_id);
15553                 break;
15554         case -ENOTSUP:
15555                 printf("function not implemented\n");
15556                 break;
15557         default:
15558                 printf("programming error: (%s)\n", strerror(-ret));
15559         }
15560 }
15561
15562 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15563         .f = cmd_ptype_mapping_replace_parsed,
15564         .data = NULL,
15565         .help_str =
15566                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15567         .tokens = {
15568                 (void *)&cmd_ptype_mapping_replace_ptype,
15569                 (void *)&cmd_ptype_mapping_replace_mapping,
15570                 (void *)&cmd_ptype_mapping_replace_replace,
15571                 (void *)&cmd_ptype_mapping_replace_port_id,
15572                 (void *)&cmd_ptype_mapping_replace_target,
15573                 (void *)&cmd_ptype_mapping_replace_mask,
15574                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15575                 NULL,
15576         },
15577 };
15578
15579 /* ptype mapping reset */
15580
15581 /* Common result structure for ptype mapping reset */
15582 struct cmd_ptype_mapping_reset_result {
15583         cmdline_fixed_string_t ptype;
15584         cmdline_fixed_string_t mapping;
15585         cmdline_fixed_string_t reset;
15586         portid_t port_id;
15587 };
15588
15589 /* Common CLI fields for ptype mapping reset*/
15590 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15591         TOKEN_STRING_INITIALIZER
15592                 (struct cmd_ptype_mapping_reset_result,
15593                  ptype, "ptype");
15594 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15595         TOKEN_STRING_INITIALIZER
15596                 (struct cmd_ptype_mapping_reset_result,
15597                  mapping, "mapping");
15598 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15599         TOKEN_STRING_INITIALIZER
15600                 (struct cmd_ptype_mapping_reset_result,
15601                  reset, "reset");
15602 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15603         TOKEN_NUM_INITIALIZER
15604                 (struct cmd_ptype_mapping_reset_result,
15605                  port_id, UINT16);
15606
15607 static void
15608 cmd_ptype_mapping_reset_parsed(
15609         void *parsed_result,
15610         __rte_unused struct cmdline *cl,
15611         __rte_unused void *data)
15612 {
15613         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15614         int ret = -ENOTSUP;
15615
15616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15617                 return;
15618
15619 #ifdef RTE_NET_I40E
15620         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15621 #endif
15622
15623         switch (ret) {
15624         case 0:
15625                 break;
15626         case -ENODEV:
15627                 printf("invalid port_id %d\n", res->port_id);
15628                 break;
15629         case -ENOTSUP:
15630                 printf("function not implemented\n");
15631                 break;
15632         default:
15633                 printf("programming error: (%s)\n", strerror(-ret));
15634         }
15635 }
15636
15637 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15638         .f = cmd_ptype_mapping_reset_parsed,
15639         .data = NULL,
15640         .help_str = "ptype mapping reset <port_id>",
15641         .tokens = {
15642                 (void *)&cmd_ptype_mapping_reset_ptype,
15643                 (void *)&cmd_ptype_mapping_reset_mapping,
15644                 (void *)&cmd_ptype_mapping_reset_reset,
15645                 (void *)&cmd_ptype_mapping_reset_port_id,
15646                 NULL,
15647         },
15648 };
15649
15650 /* ptype mapping update */
15651
15652 /* Common result structure for ptype mapping update */
15653 struct cmd_ptype_mapping_update_result {
15654         cmdline_fixed_string_t ptype;
15655         cmdline_fixed_string_t mapping;
15656         cmdline_fixed_string_t reset;
15657         portid_t port_id;
15658         uint8_t hw_ptype;
15659         uint32_t sw_ptype;
15660 };
15661
15662 /* Common CLI fields for ptype mapping update*/
15663 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15664         TOKEN_STRING_INITIALIZER
15665                 (struct cmd_ptype_mapping_update_result,
15666                  ptype, "ptype");
15667 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15668         TOKEN_STRING_INITIALIZER
15669                 (struct cmd_ptype_mapping_update_result,
15670                  mapping, "mapping");
15671 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15672         TOKEN_STRING_INITIALIZER
15673                 (struct cmd_ptype_mapping_update_result,
15674                  reset, "update");
15675 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15676         TOKEN_NUM_INITIALIZER
15677                 (struct cmd_ptype_mapping_update_result,
15678                  port_id, UINT16);
15679 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15680         TOKEN_NUM_INITIALIZER
15681                 (struct cmd_ptype_mapping_update_result,
15682                  hw_ptype, UINT8);
15683 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15684         TOKEN_NUM_INITIALIZER
15685                 (struct cmd_ptype_mapping_update_result,
15686                  sw_ptype, UINT32);
15687
15688 static void
15689 cmd_ptype_mapping_update_parsed(
15690         void *parsed_result,
15691         __rte_unused struct cmdline *cl,
15692         __rte_unused void *data)
15693 {
15694         struct cmd_ptype_mapping_update_result *res = parsed_result;
15695         int ret = -ENOTSUP;
15696 #ifdef RTE_NET_I40E
15697         struct rte_pmd_i40e_ptype_mapping mapping;
15698 #endif
15699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15700                 return;
15701
15702 #ifdef RTE_NET_I40E
15703         mapping.hw_ptype = res->hw_ptype;
15704         mapping.sw_ptype = res->sw_ptype;
15705         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15706                                                 &mapping,
15707                                                 1,
15708                                                 0);
15709 #endif
15710
15711         switch (ret) {
15712         case 0:
15713                 break;
15714         case -EINVAL:
15715                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15716                 break;
15717         case -ENODEV:
15718                 printf("invalid port_id %d\n", res->port_id);
15719                 break;
15720         case -ENOTSUP:
15721                 printf("function not implemented\n");
15722                 break;
15723         default:
15724                 printf("programming error: (%s)\n", strerror(-ret));
15725         }
15726 }
15727
15728 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15729         .f = cmd_ptype_mapping_update_parsed,
15730         .data = NULL,
15731         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15732         .tokens = {
15733                 (void *)&cmd_ptype_mapping_update_ptype,
15734                 (void *)&cmd_ptype_mapping_update_mapping,
15735                 (void *)&cmd_ptype_mapping_update_update,
15736                 (void *)&cmd_ptype_mapping_update_port_id,
15737                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15738                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15739                 NULL,
15740         },
15741 };
15742
15743 /* Common result structure for file commands */
15744 struct cmd_cmdfile_result {
15745         cmdline_fixed_string_t load;
15746         cmdline_fixed_string_t filename;
15747 };
15748
15749 /* Common CLI fields for file commands */
15750 cmdline_parse_token_string_t cmd_load_cmdfile =
15751         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15752 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15753         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15754
15755 static void
15756 cmd_load_from_file_parsed(
15757         void *parsed_result,
15758         __rte_unused struct cmdline *cl,
15759         __rte_unused void *data)
15760 {
15761         struct cmd_cmdfile_result *res = parsed_result;
15762
15763         cmdline_read_from_file(res->filename);
15764 }
15765
15766 cmdline_parse_inst_t cmd_load_from_file = {
15767         .f = cmd_load_from_file_parsed,
15768         .data = NULL,
15769         .help_str = "load <filename>",
15770         .tokens = {
15771                 (void *)&cmd_load_cmdfile,
15772                 (void *)&cmd_load_cmdfile_filename,
15773                 NULL,
15774         },
15775 };
15776
15777 /* Get Rx offloads capabilities */
15778 struct cmd_rx_offload_get_capa_result {
15779         cmdline_fixed_string_t show;
15780         cmdline_fixed_string_t port;
15781         portid_t port_id;
15782         cmdline_fixed_string_t rx_offload;
15783         cmdline_fixed_string_t capabilities;
15784 };
15785
15786 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15787         TOKEN_STRING_INITIALIZER
15788                 (struct cmd_rx_offload_get_capa_result,
15789                  show, "show");
15790 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15791         TOKEN_STRING_INITIALIZER
15792                 (struct cmd_rx_offload_get_capa_result,
15793                  port, "port");
15794 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15795         TOKEN_NUM_INITIALIZER
15796                 (struct cmd_rx_offload_get_capa_result,
15797                  port_id, UINT16);
15798 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15799         TOKEN_STRING_INITIALIZER
15800                 (struct cmd_rx_offload_get_capa_result,
15801                  rx_offload, "rx_offload");
15802 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15803         TOKEN_STRING_INITIALIZER
15804                 (struct cmd_rx_offload_get_capa_result,
15805                  capabilities, "capabilities");
15806
15807 static void
15808 print_rx_offloads(uint64_t offloads)
15809 {
15810         uint64_t single_offload;
15811         int begin;
15812         int end;
15813         int bit;
15814
15815         if (offloads == 0)
15816                 return;
15817
15818         begin = __builtin_ctzll(offloads);
15819         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15820
15821         single_offload = 1ULL << begin;
15822         for (bit = begin; bit < end; bit++) {
15823                 if (offloads & single_offload)
15824                         printf(" %s",
15825                                rte_eth_dev_rx_offload_name(single_offload));
15826                 single_offload <<= 1;
15827         }
15828 }
15829
15830 static void
15831 cmd_rx_offload_get_capa_parsed(
15832         void *parsed_result,
15833         __rte_unused struct cmdline *cl,
15834         __rte_unused void *data)
15835 {
15836         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15837         struct rte_eth_dev_info dev_info;
15838         portid_t port_id = res->port_id;
15839         uint64_t queue_offloads;
15840         uint64_t port_offloads;
15841         int ret;
15842
15843         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15844         if (ret != 0)
15845                 return;
15846
15847         queue_offloads = dev_info.rx_queue_offload_capa;
15848         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15849
15850         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15851         printf("  Per Queue :");
15852         print_rx_offloads(queue_offloads);
15853
15854         printf("\n");
15855         printf("  Per Port  :");
15856         print_rx_offloads(port_offloads);
15857         printf("\n\n");
15858 }
15859
15860 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15861         .f = cmd_rx_offload_get_capa_parsed,
15862         .data = NULL,
15863         .help_str = "show port <port_id> rx_offload capabilities",
15864         .tokens = {
15865                 (void *)&cmd_rx_offload_get_capa_show,
15866                 (void *)&cmd_rx_offload_get_capa_port,
15867                 (void *)&cmd_rx_offload_get_capa_port_id,
15868                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15869                 (void *)&cmd_rx_offload_get_capa_capabilities,
15870                 NULL,
15871         }
15872 };
15873
15874 /* Get Rx offloads configuration */
15875 struct cmd_rx_offload_get_configuration_result {
15876         cmdline_fixed_string_t show;
15877         cmdline_fixed_string_t port;
15878         portid_t port_id;
15879         cmdline_fixed_string_t rx_offload;
15880         cmdline_fixed_string_t configuration;
15881 };
15882
15883 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15884         TOKEN_STRING_INITIALIZER
15885                 (struct cmd_rx_offload_get_configuration_result,
15886                  show, "show");
15887 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15888         TOKEN_STRING_INITIALIZER
15889                 (struct cmd_rx_offload_get_configuration_result,
15890                  port, "port");
15891 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15892         TOKEN_NUM_INITIALIZER
15893                 (struct cmd_rx_offload_get_configuration_result,
15894                  port_id, UINT16);
15895 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15896         TOKEN_STRING_INITIALIZER
15897                 (struct cmd_rx_offload_get_configuration_result,
15898                  rx_offload, "rx_offload");
15899 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15900         TOKEN_STRING_INITIALIZER
15901                 (struct cmd_rx_offload_get_configuration_result,
15902                  configuration, "configuration");
15903
15904 static void
15905 cmd_rx_offload_get_configuration_parsed(
15906         void *parsed_result,
15907         __rte_unused struct cmdline *cl,
15908         __rte_unused void *data)
15909 {
15910         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15911         struct rte_eth_dev_info dev_info;
15912         portid_t port_id = res->port_id;
15913         struct rte_port *port = &ports[port_id];
15914         uint64_t port_offloads;
15915         uint64_t queue_offloads;
15916         uint16_t nb_rx_queues;
15917         int q;
15918         int ret;
15919
15920         printf("Rx Offloading Configuration of port %d :\n", port_id);
15921
15922         port_offloads = port->dev_conf.rxmode.offloads;
15923         printf("  Port :");
15924         print_rx_offloads(port_offloads);
15925         printf("\n");
15926
15927         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15928         if (ret != 0)
15929                 return;
15930
15931         nb_rx_queues = dev_info.nb_rx_queues;
15932         for (q = 0; q < nb_rx_queues; q++) {
15933                 queue_offloads = port->rx_conf[q].offloads;
15934                 printf("  Queue[%2d] :", q);
15935                 print_rx_offloads(queue_offloads);
15936                 printf("\n");
15937         }
15938         printf("\n");
15939 }
15940
15941 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15942         .f = cmd_rx_offload_get_configuration_parsed,
15943         .data = NULL,
15944         .help_str = "show port <port_id> rx_offload configuration",
15945         .tokens = {
15946                 (void *)&cmd_rx_offload_get_configuration_show,
15947                 (void *)&cmd_rx_offload_get_configuration_port,
15948                 (void *)&cmd_rx_offload_get_configuration_port_id,
15949                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15950                 (void *)&cmd_rx_offload_get_configuration_configuration,
15951                 NULL,
15952         }
15953 };
15954
15955 /* Enable/Disable a per port offloading */
15956 struct cmd_config_per_port_rx_offload_result {
15957         cmdline_fixed_string_t port;
15958         cmdline_fixed_string_t config;
15959         portid_t port_id;
15960         cmdline_fixed_string_t rx_offload;
15961         cmdline_fixed_string_t offload;
15962         cmdline_fixed_string_t on_off;
15963 };
15964
15965 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15966         TOKEN_STRING_INITIALIZER
15967                 (struct cmd_config_per_port_rx_offload_result,
15968                  port, "port");
15969 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15970         TOKEN_STRING_INITIALIZER
15971                 (struct cmd_config_per_port_rx_offload_result,
15972                  config, "config");
15973 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15974         TOKEN_NUM_INITIALIZER
15975                 (struct cmd_config_per_port_rx_offload_result,
15976                  port_id, UINT16);
15977 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15978         TOKEN_STRING_INITIALIZER
15979                 (struct cmd_config_per_port_rx_offload_result,
15980                  rx_offload, "rx_offload");
15981 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15982         TOKEN_STRING_INITIALIZER
15983                 (struct cmd_config_per_port_rx_offload_result,
15984                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15985                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15986                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15987                            "scatter#buffer_split#timestamp#security#"
15988                            "keep_crc#rss_hash");
15989 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15990         TOKEN_STRING_INITIALIZER
15991                 (struct cmd_config_per_port_rx_offload_result,
15992                  on_off, "on#off");
15993
15994 static uint64_t
15995 search_rx_offload(const char *name)
15996 {
15997         uint64_t single_offload;
15998         const char *single_name;
15999         int found = 0;
16000         unsigned int bit;
16001
16002         single_offload = 1;
16003         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16004                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16005                 if (!strcasecmp(single_name, name)) {
16006                         found = 1;
16007                         break;
16008                 }
16009                 single_offload <<= 1;
16010         }
16011
16012         if (found)
16013                 return single_offload;
16014
16015         return 0;
16016 }
16017
16018 static void
16019 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16020                                 __rte_unused struct cmdline *cl,
16021                                 __rte_unused void *data)
16022 {
16023         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16024         portid_t port_id = res->port_id;
16025         struct rte_eth_dev_info dev_info;
16026         struct rte_port *port = &ports[port_id];
16027         uint64_t single_offload;
16028         uint16_t nb_rx_queues;
16029         int q;
16030         int ret;
16031
16032         if (port->port_status != RTE_PORT_STOPPED) {
16033                 printf("Error: Can't config offload when Port %d "
16034                        "is not stopped\n", port_id);
16035                 return;
16036         }
16037
16038         single_offload = search_rx_offload(res->offload);
16039         if (single_offload == 0) {
16040                 printf("Unknown offload name: %s\n", res->offload);
16041                 return;
16042         }
16043
16044         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16045         if (ret != 0)
16046                 return;
16047
16048         nb_rx_queues = dev_info.nb_rx_queues;
16049         if (!strcmp(res->on_off, "on")) {
16050                 port->dev_conf.rxmode.offloads |= single_offload;
16051                 for (q = 0; q < nb_rx_queues; q++)
16052                         port->rx_conf[q].offloads |= single_offload;
16053         } else {
16054                 port->dev_conf.rxmode.offloads &= ~single_offload;
16055                 for (q = 0; q < nb_rx_queues; q++)
16056                         port->rx_conf[q].offloads &= ~single_offload;
16057         }
16058
16059         cmd_reconfig_device_queue(port_id, 1, 1);
16060 }
16061
16062 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16063         .f = cmd_config_per_port_rx_offload_parsed,
16064         .data = NULL,
16065         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16066                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16067                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16068                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16069                     "keep_crc|rss_hash on|off",
16070         .tokens = {
16071                 (void *)&cmd_config_per_port_rx_offload_result_port,
16072                 (void *)&cmd_config_per_port_rx_offload_result_config,
16073                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16074                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16075                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16076                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16077                 NULL,
16078         }
16079 };
16080
16081 /* Enable/Disable a per queue offloading */
16082 struct cmd_config_per_queue_rx_offload_result {
16083         cmdline_fixed_string_t port;
16084         portid_t port_id;
16085         cmdline_fixed_string_t rxq;
16086         uint16_t queue_id;
16087         cmdline_fixed_string_t rx_offload;
16088         cmdline_fixed_string_t offload;
16089         cmdline_fixed_string_t on_off;
16090 };
16091
16092 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16093         TOKEN_STRING_INITIALIZER
16094                 (struct cmd_config_per_queue_rx_offload_result,
16095                  port, "port");
16096 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16097         TOKEN_NUM_INITIALIZER
16098                 (struct cmd_config_per_queue_rx_offload_result,
16099                  port_id, UINT16);
16100 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16101         TOKEN_STRING_INITIALIZER
16102                 (struct cmd_config_per_queue_rx_offload_result,
16103                  rxq, "rxq");
16104 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16105         TOKEN_NUM_INITIALIZER
16106                 (struct cmd_config_per_queue_rx_offload_result,
16107                  queue_id, UINT16);
16108 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16109         TOKEN_STRING_INITIALIZER
16110                 (struct cmd_config_per_queue_rx_offload_result,
16111                  rx_offload, "rx_offload");
16112 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16113         TOKEN_STRING_INITIALIZER
16114                 (struct cmd_config_per_queue_rx_offload_result,
16115                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16116                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16117                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16118                            "scatter#buffer_split#timestamp#security#keep_crc");
16119 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16120         TOKEN_STRING_INITIALIZER
16121                 (struct cmd_config_per_queue_rx_offload_result,
16122                  on_off, "on#off");
16123
16124 static void
16125 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16126                                 __rte_unused struct cmdline *cl,
16127                                 __rte_unused void *data)
16128 {
16129         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16130         struct rte_eth_dev_info dev_info;
16131         portid_t port_id = res->port_id;
16132         uint16_t queue_id = res->queue_id;
16133         struct rte_port *port = &ports[port_id];
16134         uint64_t single_offload;
16135         int ret;
16136
16137         if (port->port_status != RTE_PORT_STOPPED) {
16138                 printf("Error: Can't config offload when Port %d "
16139                        "is not stopped\n", port_id);
16140                 return;
16141         }
16142
16143         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16144         if (ret != 0)
16145                 return;
16146
16147         if (queue_id >= dev_info.nb_rx_queues) {
16148                 printf("Error: input queue_id should be 0 ... "
16149                        "%d\n", dev_info.nb_rx_queues - 1);
16150                 return;
16151         }
16152
16153         single_offload = search_rx_offload(res->offload);
16154         if (single_offload == 0) {
16155                 printf("Unknown offload name: %s\n", res->offload);
16156                 return;
16157         }
16158
16159         if (!strcmp(res->on_off, "on"))
16160                 port->rx_conf[queue_id].offloads |= single_offload;
16161         else
16162                 port->rx_conf[queue_id].offloads &= ~single_offload;
16163
16164         cmd_reconfig_device_queue(port_id, 1, 1);
16165 }
16166
16167 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16168         .f = cmd_config_per_queue_rx_offload_parsed,
16169         .data = NULL,
16170         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16171                     "vlan_strip|ipv4_cksum|"
16172                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16173                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16174                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16175                     "keep_crc on|off",
16176         .tokens = {
16177                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16178                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16179                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16180                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16181                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16182                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16183                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16184                 NULL,
16185         }
16186 };
16187
16188 /* Get Tx offloads capabilities */
16189 struct cmd_tx_offload_get_capa_result {
16190         cmdline_fixed_string_t show;
16191         cmdline_fixed_string_t port;
16192         portid_t port_id;
16193         cmdline_fixed_string_t tx_offload;
16194         cmdline_fixed_string_t capabilities;
16195 };
16196
16197 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16198         TOKEN_STRING_INITIALIZER
16199                 (struct cmd_tx_offload_get_capa_result,
16200                  show, "show");
16201 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16202         TOKEN_STRING_INITIALIZER
16203                 (struct cmd_tx_offload_get_capa_result,
16204                  port, "port");
16205 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16206         TOKEN_NUM_INITIALIZER
16207                 (struct cmd_tx_offload_get_capa_result,
16208                  port_id, UINT16);
16209 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16210         TOKEN_STRING_INITIALIZER
16211                 (struct cmd_tx_offload_get_capa_result,
16212                  tx_offload, "tx_offload");
16213 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16214         TOKEN_STRING_INITIALIZER
16215                 (struct cmd_tx_offload_get_capa_result,
16216                  capabilities, "capabilities");
16217
16218 static void
16219 print_tx_offloads(uint64_t offloads)
16220 {
16221         uint64_t single_offload;
16222         int begin;
16223         int end;
16224         int bit;
16225
16226         if (offloads == 0)
16227                 return;
16228
16229         begin = __builtin_ctzll(offloads);
16230         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16231
16232         single_offload = 1ULL << begin;
16233         for (bit = begin; bit < end; bit++) {
16234                 if (offloads & single_offload)
16235                         printf(" %s",
16236                                rte_eth_dev_tx_offload_name(single_offload));
16237                 single_offload <<= 1;
16238         }
16239 }
16240
16241 static void
16242 cmd_tx_offload_get_capa_parsed(
16243         void *parsed_result,
16244         __rte_unused struct cmdline *cl,
16245         __rte_unused void *data)
16246 {
16247         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16248         struct rte_eth_dev_info dev_info;
16249         portid_t port_id = res->port_id;
16250         uint64_t queue_offloads;
16251         uint64_t port_offloads;
16252         int ret;
16253
16254         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16255         if (ret != 0)
16256                 return;
16257
16258         queue_offloads = dev_info.tx_queue_offload_capa;
16259         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16260
16261         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16262         printf("  Per Queue :");
16263         print_tx_offloads(queue_offloads);
16264
16265         printf("\n");
16266         printf("  Per Port  :");
16267         print_tx_offloads(port_offloads);
16268         printf("\n\n");
16269 }
16270
16271 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16272         .f = cmd_tx_offload_get_capa_parsed,
16273         .data = NULL,
16274         .help_str = "show port <port_id> tx_offload capabilities",
16275         .tokens = {
16276                 (void *)&cmd_tx_offload_get_capa_show,
16277                 (void *)&cmd_tx_offload_get_capa_port,
16278                 (void *)&cmd_tx_offload_get_capa_port_id,
16279                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16280                 (void *)&cmd_tx_offload_get_capa_capabilities,
16281                 NULL,
16282         }
16283 };
16284
16285 /* Get Tx offloads configuration */
16286 struct cmd_tx_offload_get_configuration_result {
16287         cmdline_fixed_string_t show;
16288         cmdline_fixed_string_t port;
16289         portid_t port_id;
16290         cmdline_fixed_string_t tx_offload;
16291         cmdline_fixed_string_t configuration;
16292 };
16293
16294 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16295         TOKEN_STRING_INITIALIZER
16296                 (struct cmd_tx_offload_get_configuration_result,
16297                  show, "show");
16298 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16299         TOKEN_STRING_INITIALIZER
16300                 (struct cmd_tx_offload_get_configuration_result,
16301                  port, "port");
16302 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16303         TOKEN_NUM_INITIALIZER
16304                 (struct cmd_tx_offload_get_configuration_result,
16305                  port_id, UINT16);
16306 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16307         TOKEN_STRING_INITIALIZER
16308                 (struct cmd_tx_offload_get_configuration_result,
16309                  tx_offload, "tx_offload");
16310 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16311         TOKEN_STRING_INITIALIZER
16312                 (struct cmd_tx_offload_get_configuration_result,
16313                  configuration, "configuration");
16314
16315 static void
16316 cmd_tx_offload_get_configuration_parsed(
16317         void *parsed_result,
16318         __rte_unused struct cmdline *cl,
16319         __rte_unused void *data)
16320 {
16321         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16322         struct rte_eth_dev_info dev_info;
16323         portid_t port_id = res->port_id;
16324         struct rte_port *port = &ports[port_id];
16325         uint64_t port_offloads;
16326         uint64_t queue_offloads;
16327         uint16_t nb_tx_queues;
16328         int q;
16329         int ret;
16330
16331         printf("Tx Offloading Configuration of port %d :\n", port_id);
16332
16333         port_offloads = port->dev_conf.txmode.offloads;
16334         printf("  Port :");
16335         print_tx_offloads(port_offloads);
16336         printf("\n");
16337
16338         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16339         if (ret != 0)
16340                 return;
16341
16342         nb_tx_queues = dev_info.nb_tx_queues;
16343         for (q = 0; q < nb_tx_queues; q++) {
16344                 queue_offloads = port->tx_conf[q].offloads;
16345                 printf("  Queue[%2d] :", q);
16346                 print_tx_offloads(queue_offloads);
16347                 printf("\n");
16348         }
16349         printf("\n");
16350 }
16351
16352 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16353         .f = cmd_tx_offload_get_configuration_parsed,
16354         .data = NULL,
16355         .help_str = "show port <port_id> tx_offload configuration",
16356         .tokens = {
16357                 (void *)&cmd_tx_offload_get_configuration_show,
16358                 (void *)&cmd_tx_offload_get_configuration_port,
16359                 (void *)&cmd_tx_offload_get_configuration_port_id,
16360                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16361                 (void *)&cmd_tx_offload_get_configuration_configuration,
16362                 NULL,
16363         }
16364 };
16365
16366 /* Enable/Disable a per port offloading */
16367 struct cmd_config_per_port_tx_offload_result {
16368         cmdline_fixed_string_t port;
16369         cmdline_fixed_string_t config;
16370         portid_t port_id;
16371         cmdline_fixed_string_t tx_offload;
16372         cmdline_fixed_string_t offload;
16373         cmdline_fixed_string_t on_off;
16374 };
16375
16376 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16377         TOKEN_STRING_INITIALIZER
16378                 (struct cmd_config_per_port_tx_offload_result,
16379                  port, "port");
16380 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16381         TOKEN_STRING_INITIALIZER
16382                 (struct cmd_config_per_port_tx_offload_result,
16383                  config, "config");
16384 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16385         TOKEN_NUM_INITIALIZER
16386                 (struct cmd_config_per_port_tx_offload_result,
16387                  port_id, UINT16);
16388 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16389         TOKEN_STRING_INITIALIZER
16390                 (struct cmd_config_per_port_tx_offload_result,
16391                  tx_offload, "tx_offload");
16392 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16393         TOKEN_STRING_INITIALIZER
16394                 (struct cmd_config_per_port_tx_offload_result,
16395                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16396                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16397                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16398                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16399                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16400                           "send_on_timestamp");
16401 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16402         TOKEN_STRING_INITIALIZER
16403                 (struct cmd_config_per_port_tx_offload_result,
16404                  on_off, "on#off");
16405
16406 static uint64_t
16407 search_tx_offload(const char *name)
16408 {
16409         uint64_t single_offload;
16410         const char *single_name;
16411         int found = 0;
16412         unsigned int bit;
16413
16414         single_offload = 1;
16415         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16416                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16417                 if (single_name == NULL)
16418                         break;
16419                 if (!strcasecmp(single_name, name)) {
16420                         found = 1;
16421                         break;
16422                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16423                         break;
16424                 single_offload <<= 1;
16425         }
16426
16427         if (found)
16428                 return single_offload;
16429
16430         return 0;
16431 }
16432
16433 static void
16434 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16435                                 __rte_unused struct cmdline *cl,
16436                                 __rte_unused void *data)
16437 {
16438         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16439         portid_t port_id = res->port_id;
16440         struct rte_eth_dev_info dev_info;
16441         struct rte_port *port = &ports[port_id];
16442         uint64_t single_offload;
16443         uint16_t nb_tx_queues;
16444         int q;
16445         int ret;
16446
16447         if (port->port_status != RTE_PORT_STOPPED) {
16448                 printf("Error: Can't config offload when Port %d "
16449                        "is not stopped\n", port_id);
16450                 return;
16451         }
16452
16453         single_offload = search_tx_offload(res->offload);
16454         if (single_offload == 0) {
16455                 printf("Unknown offload name: %s\n", res->offload);
16456                 return;
16457         }
16458
16459         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16460         if (ret != 0)
16461                 return;
16462
16463         nb_tx_queues = dev_info.nb_tx_queues;
16464         if (!strcmp(res->on_off, "on")) {
16465                 port->dev_conf.txmode.offloads |= single_offload;
16466                 for (q = 0; q < nb_tx_queues; q++)
16467                         port->tx_conf[q].offloads |= single_offload;
16468         } else {
16469                 port->dev_conf.txmode.offloads &= ~single_offload;
16470                 for (q = 0; q < nb_tx_queues; q++)
16471                         port->tx_conf[q].offloads &= ~single_offload;
16472         }
16473
16474         cmd_reconfig_device_queue(port_id, 1, 1);
16475 }
16476
16477 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16478         .f = cmd_config_per_port_tx_offload_parsed,
16479         .data = NULL,
16480         .help_str = "port config <port_id> tx_offload "
16481                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16482                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16483                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16484                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16485                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16486                     "send_on_timestamp on|off",
16487         .tokens = {
16488                 (void *)&cmd_config_per_port_tx_offload_result_port,
16489                 (void *)&cmd_config_per_port_tx_offload_result_config,
16490                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16491                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16492                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16493                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16494                 NULL,
16495         }
16496 };
16497
16498 /* Enable/Disable a per queue offloading */
16499 struct cmd_config_per_queue_tx_offload_result {
16500         cmdline_fixed_string_t port;
16501         portid_t port_id;
16502         cmdline_fixed_string_t txq;
16503         uint16_t queue_id;
16504         cmdline_fixed_string_t tx_offload;
16505         cmdline_fixed_string_t offload;
16506         cmdline_fixed_string_t on_off;
16507 };
16508
16509 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_config_per_queue_tx_offload_result,
16512                  port, "port");
16513 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16514         TOKEN_NUM_INITIALIZER
16515                 (struct cmd_config_per_queue_tx_offload_result,
16516                  port_id, UINT16);
16517 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16518         TOKEN_STRING_INITIALIZER
16519                 (struct cmd_config_per_queue_tx_offload_result,
16520                  txq, "txq");
16521 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16522         TOKEN_NUM_INITIALIZER
16523                 (struct cmd_config_per_queue_tx_offload_result,
16524                  queue_id, UINT16);
16525 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16526         TOKEN_STRING_INITIALIZER
16527                 (struct cmd_config_per_queue_tx_offload_result,
16528                  tx_offload, "tx_offload");
16529 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16530         TOKEN_STRING_INITIALIZER
16531                 (struct cmd_config_per_queue_tx_offload_result,
16532                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16533                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16534                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16535                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16536                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16537 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16538         TOKEN_STRING_INITIALIZER
16539                 (struct cmd_config_per_queue_tx_offload_result,
16540                  on_off, "on#off");
16541
16542 static void
16543 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16544                                 __rte_unused struct cmdline *cl,
16545                                 __rte_unused void *data)
16546 {
16547         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16548         struct rte_eth_dev_info dev_info;
16549         portid_t port_id = res->port_id;
16550         uint16_t queue_id = res->queue_id;
16551         struct rte_port *port = &ports[port_id];
16552         uint64_t single_offload;
16553         int ret;
16554
16555         if (port->port_status != RTE_PORT_STOPPED) {
16556                 printf("Error: Can't config offload when Port %d "
16557                        "is not stopped\n", port_id);
16558                 return;
16559         }
16560
16561         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16562         if (ret != 0)
16563                 return;
16564
16565         if (queue_id >= dev_info.nb_tx_queues) {
16566                 printf("Error: input queue_id should be 0 ... "
16567                        "%d\n", dev_info.nb_tx_queues - 1);
16568                 return;
16569         }
16570
16571         single_offload = search_tx_offload(res->offload);
16572         if (single_offload == 0) {
16573                 printf("Unknown offload name: %s\n", res->offload);
16574                 return;
16575         }
16576
16577         if (!strcmp(res->on_off, "on"))
16578                 port->tx_conf[queue_id].offloads |= single_offload;
16579         else
16580                 port->tx_conf[queue_id].offloads &= ~single_offload;
16581
16582         cmd_reconfig_device_queue(port_id, 1, 1);
16583 }
16584
16585 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16586         .f = cmd_config_per_queue_tx_offload_parsed,
16587         .data = NULL,
16588         .help_str = "port <port_id> txq <queue_id> tx_offload "
16589                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16590                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16591                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16592                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16593                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16594                     "on|off",
16595         .tokens = {
16596                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16597                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16598                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16599                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16600                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16601                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16602                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16603                 NULL,
16604         }
16605 };
16606
16607 /* *** configure tx_metadata for specific port *** */
16608 struct cmd_config_tx_metadata_specific_result {
16609         cmdline_fixed_string_t port;
16610         cmdline_fixed_string_t keyword;
16611         uint16_t port_id;
16612         cmdline_fixed_string_t item;
16613         uint32_t value;
16614 };
16615
16616 static void
16617 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16618                                 __rte_unused struct cmdline *cl,
16619                                 __rte_unused void *data)
16620 {
16621         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16622
16623         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16624                 return;
16625         ports[res->port_id].tx_metadata = res->value;
16626         /* Add/remove callback to insert valid metadata in every Tx packet. */
16627         if (ports[res->port_id].tx_metadata)
16628                 add_tx_md_callback(res->port_id);
16629         else
16630                 remove_tx_md_callback(res->port_id);
16631         rte_flow_dynf_metadata_register();
16632 }
16633
16634 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16635         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16636                         port, "port");
16637 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16638         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16639                         keyword, "config");
16640 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16641         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16642                         port_id, UINT16);
16643 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16644         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16645                         item, "tx_metadata");
16646 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16647         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16648                         value, UINT32);
16649
16650 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16651         .f = cmd_config_tx_metadata_specific_parsed,
16652         .data = NULL,
16653         .help_str = "port config <port_id> tx_metadata <value>",
16654         .tokens = {
16655                 (void *)&cmd_config_tx_metadata_specific_port,
16656                 (void *)&cmd_config_tx_metadata_specific_keyword,
16657                 (void *)&cmd_config_tx_metadata_specific_id,
16658                 (void *)&cmd_config_tx_metadata_specific_item,
16659                 (void *)&cmd_config_tx_metadata_specific_value,
16660                 NULL,
16661         },
16662 };
16663
16664 /* *** set dynf *** */
16665 struct cmd_config_tx_dynf_specific_result {
16666         cmdline_fixed_string_t port;
16667         cmdline_fixed_string_t keyword;
16668         uint16_t port_id;
16669         cmdline_fixed_string_t item;
16670         cmdline_fixed_string_t name;
16671         cmdline_fixed_string_t value;
16672 };
16673
16674 static void
16675 cmd_config_dynf_specific_parsed(void *parsed_result,
16676                                 __rte_unused struct cmdline *cl,
16677                                 __rte_unused void *data)
16678 {
16679         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16680         struct rte_mbuf_dynflag desc_flag;
16681         int flag;
16682         uint64_t old_port_flags;
16683
16684         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16685                 return;
16686         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16687         if (flag <= 0) {
16688                 if (strlcpy(desc_flag.name, res->name,
16689                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16690                         printf("Flag name too long\n");
16691                         return;
16692                 }
16693                 desc_flag.flags = 0;
16694                 flag = rte_mbuf_dynflag_register(&desc_flag);
16695                 if (flag < 0) {
16696                         printf("Can't register flag\n");
16697                         return;
16698                 }
16699                 strcpy(dynf_names[flag], desc_flag.name);
16700         }
16701         old_port_flags = ports[res->port_id].mbuf_dynf;
16702         if (!strcmp(res->value, "set")) {
16703                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16704                 if (old_port_flags == 0)
16705                         add_tx_dynf_callback(res->port_id);
16706         } else {
16707                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16708                 if (ports[res->port_id].mbuf_dynf == 0)
16709                         remove_tx_dynf_callback(res->port_id);
16710         }
16711 }
16712
16713 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16714         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16715                         keyword, "port");
16716 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16717         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16718                         keyword, "config");
16719 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16720         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16721                         port_id, UINT16);
16722 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16723         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16724                         item, "dynf");
16725 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16726         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16727                         name, NULL);
16728 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16729         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16730                         value, "set#clear");
16731
16732 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16733         .f = cmd_config_dynf_specific_parsed,
16734         .data = NULL,
16735         .help_str = "port config <port id> dynf <name> set|clear",
16736         .tokens = {
16737                 (void *)&cmd_config_tx_dynf_specific_port,
16738                 (void *)&cmd_config_tx_dynf_specific_keyword,
16739                 (void *)&cmd_config_tx_dynf_specific_port_id,
16740                 (void *)&cmd_config_tx_dynf_specific_item,
16741                 (void *)&cmd_config_tx_dynf_specific_name,
16742                 (void *)&cmd_config_tx_dynf_specific_value,
16743                 NULL,
16744         },
16745 };
16746
16747 /* *** display tx_metadata per port configuration *** */
16748 struct cmd_show_tx_metadata_result {
16749         cmdline_fixed_string_t cmd_show;
16750         cmdline_fixed_string_t cmd_port;
16751         cmdline_fixed_string_t cmd_keyword;
16752         portid_t cmd_pid;
16753 };
16754
16755 static void
16756 cmd_show_tx_metadata_parsed(void *parsed_result,
16757                 __rte_unused struct cmdline *cl,
16758                 __rte_unused void *data)
16759 {
16760         struct cmd_show_tx_metadata_result *res = parsed_result;
16761
16762         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16763                 printf("invalid port id %u\n", res->cmd_pid);
16764                 return;
16765         }
16766         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16767                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16768                        ports[res->cmd_pid].tx_metadata);
16769         }
16770 }
16771
16772 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16773         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16774                         cmd_show, "show");
16775 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16776         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16777                         cmd_port, "port");
16778 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16779         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16780                         cmd_pid, UINT16);
16781 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16782         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16783                         cmd_keyword, "tx_metadata");
16784
16785 cmdline_parse_inst_t cmd_show_tx_metadata = {
16786         .f = cmd_show_tx_metadata_parsed,
16787         .data = NULL,
16788         .help_str = "show port <port_id> tx_metadata",
16789         .tokens = {
16790                 (void *)&cmd_show_tx_metadata_show,
16791                 (void *)&cmd_show_tx_metadata_port,
16792                 (void *)&cmd_show_tx_metadata_pid,
16793                 (void *)&cmd_show_tx_metadata_keyword,
16794                 NULL,
16795         },
16796 };
16797
16798 /* *** show fec capability per port configuration *** */
16799 struct cmd_show_fec_capability_result {
16800         cmdline_fixed_string_t cmd_show;
16801         cmdline_fixed_string_t cmd_port;
16802         cmdline_fixed_string_t cmd_fec;
16803         cmdline_fixed_string_t cmd_keyword;
16804         portid_t cmd_pid;
16805 };
16806
16807 static void
16808 cmd_show_fec_capability_parsed(void *parsed_result,
16809                 __rte_unused struct cmdline *cl,
16810                 __rte_unused void *data)
16811 {
16812 #define FEC_CAP_NUM 2
16813         struct cmd_show_fec_capability_result *res = parsed_result;
16814         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16815         unsigned int num = FEC_CAP_NUM;
16816         unsigned int ret_num;
16817         int ret;
16818
16819         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16820                 printf("Invalid port id %u\n", res->cmd_pid);
16821                 return;
16822         }
16823
16824         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16825         if (ret == -ENOTSUP) {
16826                 printf("Function not implemented\n");
16827                 return;
16828         } else if (ret < 0) {
16829                 printf("Get FEC capability failed\n");
16830                 return;
16831         }
16832
16833         ret_num = (unsigned int)ret;
16834         show_fec_capability(ret_num, speed_fec_capa);
16835 }
16836
16837 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16838         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16839                         cmd_show, "show");
16840 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16841         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16842                         cmd_port, "port");
16843 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16844         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16845                         cmd_pid, UINT16);
16846 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16847         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16848                         cmd_fec, "fec");
16849 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16850         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16851                         cmd_keyword, "capabilities");
16852
16853 cmdline_parse_inst_t cmd_show_capability = {
16854         .f = cmd_show_fec_capability_parsed,
16855         .data = NULL,
16856         .help_str = "show port <port_id> fec capabilities",
16857         .tokens = {
16858                 (void *)&cmd_show_fec_capability_show,
16859                 (void *)&cmd_show_fec_capability_port,
16860                 (void *)&cmd_show_fec_capability_pid,
16861                 (void *)&cmd_show_fec_capability_fec,
16862                 (void *)&cmd_show_fec_capability_keyword,
16863                 NULL,
16864         },
16865 };
16866
16867 /* *** show fec mode per port configuration *** */
16868 struct cmd_show_fec_metadata_result {
16869         cmdline_fixed_string_t cmd_show;
16870         cmdline_fixed_string_t cmd_port;
16871         cmdline_fixed_string_t cmd_keyword;
16872         portid_t cmd_pid;
16873 };
16874
16875 static void
16876 cmd_show_fec_mode_parsed(void *parsed_result,
16877                 __rte_unused struct cmdline *cl,
16878                 __rte_unused void *data)
16879 {
16880 #define FEC_NAME_SIZE 16
16881         struct cmd_show_fec_metadata_result *res = parsed_result;
16882         uint32_t mode;
16883         char buf[FEC_NAME_SIZE];
16884         int ret;
16885
16886         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16887                 printf("Invalid port id %u\n", res->cmd_pid);
16888                 return;
16889         }
16890         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16891         if (ret == -ENOTSUP) {
16892                 printf("Function not implemented\n");
16893                 return;
16894         } else if (ret < 0) {
16895                 printf("Get FEC mode failed\n");
16896                 return;
16897         }
16898
16899         switch (mode) {
16900         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16901                 strlcpy(buf, "off", sizeof(buf));
16902                 break;
16903         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16904                 strlcpy(buf, "auto", sizeof(buf));
16905                 break;
16906         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16907                 strlcpy(buf, "baser", sizeof(buf));
16908                 break;
16909         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16910                 strlcpy(buf, "rs", sizeof(buf));
16911                 break;
16912         default:
16913                 return;
16914         }
16915
16916         printf("%s\n", buf);
16917 }
16918
16919 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16920         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16921                         cmd_show, "show");
16922 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16923         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16924                         cmd_port, "port");
16925 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16926         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16927                         cmd_pid, UINT16);
16928 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16929         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16930                         cmd_keyword, "fec_mode");
16931
16932 cmdline_parse_inst_t cmd_show_fec_mode = {
16933         .f = cmd_show_fec_mode_parsed,
16934         .data = NULL,
16935         .help_str = "show port <port_id> fec_mode",
16936         .tokens = {
16937                 (void *)&cmd_show_fec_mode_show,
16938                 (void *)&cmd_show_fec_mode_port,
16939                 (void *)&cmd_show_fec_mode_pid,
16940                 (void *)&cmd_show_fec_mode_keyword,
16941                 NULL,
16942         },
16943 };
16944
16945 /* *** set fec mode per port configuration *** */
16946 struct cmd_set_port_fec_mode {
16947         cmdline_fixed_string_t set;
16948         cmdline_fixed_string_t port;
16949         portid_t port_id;
16950         cmdline_fixed_string_t fec_mode;
16951         cmdline_fixed_string_t fec_value;
16952 };
16953
16954 /* Common CLI fields for set fec mode */
16955 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16956         TOKEN_STRING_INITIALIZER
16957                 (struct cmd_set_port_fec_mode,
16958                  set, "set");
16959 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16960         TOKEN_STRING_INITIALIZER
16961                 (struct cmd_set_port_fec_mode,
16962                  port, "port");
16963 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16964         TOKEN_NUM_INITIALIZER
16965                 (struct cmd_set_port_fec_mode,
16966                  port_id, UINT16);
16967 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16968         TOKEN_STRING_INITIALIZER
16969                 (struct cmd_set_port_fec_mode,
16970                  fec_mode, "fec_mode");
16971 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16972         TOKEN_STRING_INITIALIZER
16973                 (struct cmd_set_port_fec_mode,
16974                  fec_value, NULL);
16975
16976 static void
16977 cmd_set_port_fec_mode_parsed(
16978         void *parsed_result,
16979         __rte_unused struct cmdline *cl,
16980         __rte_unused void *data)
16981 {
16982         struct cmd_set_port_fec_mode *res = parsed_result;
16983         uint16_t port_id = res->port_id;
16984         uint32_t mode;
16985         int ret;
16986
16987         ret = parse_fec_mode(res->fec_value, &mode);
16988         if (ret < 0) {
16989                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16990                         port_id);
16991                 return;
16992         }
16993
16994         ret = rte_eth_fec_set(port_id, mode);
16995         if (ret == -ENOTSUP) {
16996                 printf("Function not implemented\n");
16997                 return;
16998         } else if (ret < 0) {
16999                 printf("Set FEC mode failed\n");
17000                 return;
17001         }
17002 }
17003
17004 cmdline_parse_inst_t cmd_set_fec_mode = {
17005         .f = cmd_set_port_fec_mode_parsed,
17006         .data = NULL,
17007         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17008         .tokens = {
17009                 (void *)&cmd_set_port_fec_mode_set,
17010                 (void *)&cmd_set_port_fec_mode_port,
17011                 (void *)&cmd_set_port_fec_mode_port_id,
17012                 (void *)&cmd_set_port_fec_mode_str,
17013                 (void *)&cmd_set_port_fec_mode_value,
17014                 NULL,
17015         },
17016 };
17017
17018 /* show port supported ptypes */
17019
17020 /* Common result structure for show port ptypes */
17021 struct cmd_show_port_supported_ptypes_result {
17022         cmdline_fixed_string_t show;
17023         cmdline_fixed_string_t port;
17024         portid_t port_id;
17025         cmdline_fixed_string_t ptypes;
17026 };
17027
17028 /* Common CLI fields for show port ptypes */
17029 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17030         TOKEN_STRING_INITIALIZER
17031                 (struct cmd_show_port_supported_ptypes_result,
17032                  show, "show");
17033 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17034         TOKEN_STRING_INITIALIZER
17035                 (struct cmd_show_port_supported_ptypes_result,
17036                  port, "port");
17037 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17038         TOKEN_NUM_INITIALIZER
17039                 (struct cmd_show_port_supported_ptypes_result,
17040                  port_id, UINT16);
17041 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17042         TOKEN_STRING_INITIALIZER
17043                 (struct cmd_show_port_supported_ptypes_result,
17044                  ptypes, "ptypes");
17045
17046 static void
17047 cmd_show_port_supported_ptypes_parsed(
17048         void *parsed_result,
17049         __rte_unused struct cmdline *cl,
17050         __rte_unused void *data)
17051 {
17052 #define RSVD_PTYPE_MASK       0xf0000000
17053 #define MAX_PTYPES_PER_LAYER  16
17054 #define LTYPE_NAMESIZE        32
17055 #define PTYPE_NAMESIZE        256
17056         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17057         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17058         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17059         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17060         uint16_t port_id = res->port_id;
17061         int ret, i;
17062
17063         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17064         if (ret < 0)
17065                 return;
17066
17067         while (ptype_mask != RSVD_PTYPE_MASK) {
17068
17069                 switch (ptype_mask) {
17070                 case RTE_PTYPE_L2_MASK:
17071                         strlcpy(ltype, "L2", sizeof(ltype));
17072                         break;
17073                 case RTE_PTYPE_L3_MASK:
17074                         strlcpy(ltype, "L3", sizeof(ltype));
17075                         break;
17076                 case RTE_PTYPE_L4_MASK:
17077                         strlcpy(ltype, "L4", sizeof(ltype));
17078                         break;
17079                 case RTE_PTYPE_TUNNEL_MASK:
17080                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17081                         break;
17082                 case RTE_PTYPE_INNER_L2_MASK:
17083                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17084                         break;
17085                 case RTE_PTYPE_INNER_L3_MASK:
17086                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17087                         break;
17088                 case RTE_PTYPE_INNER_L4_MASK:
17089                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17090                         break;
17091                 default:
17092                         return;
17093                 }
17094
17095                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17096                                                        ptype_mask, ptypes,
17097                                                        MAX_PTYPES_PER_LAYER);
17098
17099                 if (ret > 0)
17100                         printf("Supported %s ptypes:\n", ltype);
17101                 else
17102                         printf("%s ptypes unsupported\n", ltype);
17103
17104                 for (i = 0; i < ret; ++i) {
17105                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17106                         printf("%s\n", buf);
17107                 }
17108
17109                 ptype_mask <<= 4;
17110         }
17111 }
17112
17113 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17114         .f = cmd_show_port_supported_ptypes_parsed,
17115         .data = NULL,
17116         .help_str = "show port <port_id> ptypes",
17117         .tokens = {
17118                 (void *)&cmd_show_port_supported_ptypes_show,
17119                 (void *)&cmd_show_port_supported_ptypes_port,
17120                 (void *)&cmd_show_port_supported_ptypes_port_id,
17121                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17122                 NULL,
17123         },
17124 };
17125
17126 /* *** display rx/tx descriptor status *** */
17127 struct cmd_show_rx_tx_desc_status_result {
17128         cmdline_fixed_string_t cmd_show;
17129         cmdline_fixed_string_t cmd_port;
17130         cmdline_fixed_string_t cmd_keyword;
17131         cmdline_fixed_string_t cmd_desc;
17132         cmdline_fixed_string_t cmd_status;
17133         portid_t cmd_pid;
17134         portid_t cmd_qid;
17135         portid_t cmd_did;
17136 };
17137
17138 static void
17139 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17140                 __rte_unused struct cmdline *cl,
17141                 __rte_unused void *data)
17142 {
17143         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17144         int rc;
17145
17146         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17147                 printf("invalid port id %u\n", res->cmd_pid);
17148                 return;
17149         }
17150
17151         if (!strcmp(res->cmd_keyword, "rxq")) {
17152                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17153                                              res->cmd_did);
17154                 if (rc < 0) {
17155                         printf("Invalid queueid = %d\n", res->cmd_qid);
17156                         return;
17157                 }
17158                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17159                         printf("Desc status = AVAILABLE\n");
17160                 else if (rc == RTE_ETH_RX_DESC_DONE)
17161                         printf("Desc status = DONE\n");
17162                 else
17163                         printf("Desc status = UNAVAILABLE\n");
17164         } else if (!strcmp(res->cmd_keyword, "txq")) {
17165                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17166                                              res->cmd_did);
17167                 if (rc < 0) {
17168                         printf("Invalid queueid = %d\n", res->cmd_qid);
17169                         return;
17170                 }
17171                 if (rc == RTE_ETH_TX_DESC_FULL)
17172                         printf("Desc status = FULL\n");
17173                 else if (rc == RTE_ETH_TX_DESC_DONE)
17174                         printf("Desc status = DONE\n");
17175                 else
17176                         printf("Desc status = UNAVAILABLE\n");
17177         }
17178 }
17179
17180 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17181         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17182                         cmd_show, "show");
17183 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17184         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17185                         cmd_port, "port");
17186 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17187         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17188                         cmd_pid, UINT16);
17189 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17190         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17191                         cmd_keyword, "rxq#txq");
17192 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17193         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17194                         cmd_qid, UINT16);
17195 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17196         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17197                         cmd_desc, "desc");
17198 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17199         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17200                         cmd_did, UINT16);
17201 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17202         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17203                         cmd_status, "status");
17204 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17205         .f = cmd_show_rx_tx_desc_status_parsed,
17206         .data = NULL,
17207         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17208                 "status",
17209         .tokens = {
17210                 (void *)&cmd_show_rx_tx_desc_status_show,
17211                 (void *)&cmd_show_rx_tx_desc_status_port,
17212                 (void *)&cmd_show_rx_tx_desc_status_pid,
17213                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17214                 (void *)&cmd_show_rx_tx_desc_status_qid,
17215                 (void *)&cmd_show_rx_tx_desc_status_desc,
17216                 (void *)&cmd_show_rx_tx_desc_status_did,
17217                 (void *)&cmd_show_rx_tx_desc_status_status,
17218                 NULL,
17219         },
17220 };
17221
17222 /* Common result structure for set port ptypes */
17223 struct cmd_set_port_ptypes_result {
17224         cmdline_fixed_string_t set;
17225         cmdline_fixed_string_t port;
17226         portid_t port_id;
17227         cmdline_fixed_string_t ptype_mask;
17228         uint32_t mask;
17229 };
17230
17231 /* Common CLI fields for set port ptypes */
17232 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17233         TOKEN_STRING_INITIALIZER
17234                 (struct cmd_set_port_ptypes_result,
17235                  set, "set");
17236 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17237         TOKEN_STRING_INITIALIZER
17238                 (struct cmd_set_port_ptypes_result,
17239                  port, "port");
17240 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17241         TOKEN_NUM_INITIALIZER
17242                 (struct cmd_set_port_ptypes_result,
17243                  port_id, UINT16);
17244 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17245         TOKEN_STRING_INITIALIZER
17246                 (struct cmd_set_port_ptypes_result,
17247                  ptype_mask, "ptype_mask");
17248 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17249         TOKEN_NUM_INITIALIZER
17250                 (struct cmd_set_port_ptypes_result,
17251                  mask, UINT32);
17252
17253 static void
17254 cmd_set_port_ptypes_parsed(
17255         void *parsed_result,
17256         __rte_unused struct cmdline *cl,
17257         __rte_unused void *data)
17258 {
17259         struct cmd_set_port_ptypes_result *res = parsed_result;
17260 #define PTYPE_NAMESIZE        256
17261         char ptype_name[PTYPE_NAMESIZE];
17262         uint16_t port_id = res->port_id;
17263         uint32_t ptype_mask = res->mask;
17264         int ret, i;
17265
17266         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17267                                                NULL, 0);
17268         if (ret <= 0) {
17269                 printf("Port %d doesn't support any ptypes.\n", port_id);
17270                 return;
17271         }
17272
17273         uint32_t ptypes[ret];
17274
17275         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17276         if (ret < 0) {
17277                 printf("Unable to set requested ptypes for Port %d\n", port_id);
17278                 return;
17279         }
17280
17281         printf("Successfully set following ptypes for Port %d\n", port_id);
17282         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17283                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17284                 printf("%s\n", ptype_name);
17285         }
17286
17287         clear_ptypes = false;
17288 }
17289
17290 cmdline_parse_inst_t cmd_set_port_ptypes = {
17291         .f = cmd_set_port_ptypes_parsed,
17292         .data = NULL,
17293         .help_str = "set port <port_id> ptype_mask <mask>",
17294         .tokens = {
17295                 (void *)&cmd_set_port_ptypes_set,
17296                 (void *)&cmd_set_port_ptypes_port,
17297                 (void *)&cmd_set_port_ptypes_port_id,
17298                 (void *)&cmd_set_port_ptypes_mask_str,
17299                 (void *)&cmd_set_port_ptypes_mask_u32,
17300                 NULL,
17301         },
17302 };
17303
17304 /* *** display mac addresses added to a port *** */
17305 struct cmd_showport_macs_result {
17306         cmdline_fixed_string_t cmd_show;
17307         cmdline_fixed_string_t cmd_port;
17308         cmdline_fixed_string_t cmd_keyword;
17309         portid_t cmd_pid;
17310 };
17311
17312 static void
17313 cmd_showport_macs_parsed(void *parsed_result,
17314                 __rte_unused struct cmdline *cl,
17315                 __rte_unused void *data)
17316 {
17317         struct cmd_showport_macs_result *res = parsed_result;
17318
17319         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17320                 return;
17321
17322         if (!strcmp(res->cmd_keyword, "macs"))
17323                 show_macs(res->cmd_pid);
17324         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17325                 show_mcast_macs(res->cmd_pid);
17326 }
17327
17328 cmdline_parse_token_string_t cmd_showport_macs_show =
17329         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17330                         cmd_show, "show");
17331 cmdline_parse_token_string_t cmd_showport_macs_port =
17332         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17333                         cmd_port, "port");
17334 cmdline_parse_token_num_t cmd_showport_macs_pid =
17335         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17336                         cmd_pid, UINT16);
17337 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17338         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17339                         cmd_keyword, "macs#mcast_macs");
17340
17341 cmdline_parse_inst_t cmd_showport_macs = {
17342         .f = cmd_showport_macs_parsed,
17343         .data = NULL,
17344         .help_str = "show port <port_id> macs|mcast_macs",
17345         .tokens = {
17346                 (void *)&cmd_showport_macs_show,
17347                 (void *)&cmd_showport_macs_port,
17348                 (void *)&cmd_showport_macs_pid,
17349                 (void *)&cmd_showport_macs_keyword,
17350                 NULL,
17351         },
17352 };
17353
17354 /* ******************************************************************************** */
17355
17356 /* list of instructions */
17357 cmdline_parse_ctx_t main_ctx[] = {
17358         (cmdline_parse_inst_t *)&cmd_help_brief,
17359         (cmdline_parse_inst_t *)&cmd_help_long,
17360         (cmdline_parse_inst_t *)&cmd_quit,
17361         (cmdline_parse_inst_t *)&cmd_load_from_file,
17362         (cmdline_parse_inst_t *)&cmd_showport,
17363         (cmdline_parse_inst_t *)&cmd_showqueue,
17364         (cmdline_parse_inst_t *)&cmd_showeeprom,
17365         (cmdline_parse_inst_t *)&cmd_showportall,
17366         (cmdline_parse_inst_t *)&cmd_showdevice,
17367         (cmdline_parse_inst_t *)&cmd_showcfg,
17368         (cmdline_parse_inst_t *)&cmd_showfwdall,
17369         (cmdline_parse_inst_t *)&cmd_start,
17370         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17371         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17372         (cmdline_parse_inst_t *)&cmd_set_link_up,
17373         (cmdline_parse_inst_t *)&cmd_set_link_down,
17374         (cmdline_parse_inst_t *)&cmd_reset,
17375         (cmdline_parse_inst_t *)&cmd_set_numbers,
17376         (cmdline_parse_inst_t *)&cmd_set_log,
17377         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17378         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17379         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17380         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17381         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17382         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17383         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17384         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17385         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17386         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17387         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17388         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17389         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17390         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17391         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17392         (cmdline_parse_inst_t *)&cmd_set_link_check,
17393         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17394         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17395         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17396         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17397 #ifdef RTE_NET_BOND
17398         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17399         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17400         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17401         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17402         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17403         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17404         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17405         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17406         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17407         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17408         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17409 #endif
17410         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17411         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17412         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17413         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17414         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17415         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17416         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17417         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17418         (cmdline_parse_inst_t *)&cmd_csum_set,
17419         (cmdline_parse_inst_t *)&cmd_csum_show,
17420         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17421         (cmdline_parse_inst_t *)&cmd_tso_set,
17422         (cmdline_parse_inst_t *)&cmd_tso_show,
17423         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17424         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17425         (cmdline_parse_inst_t *)&cmd_gro_enable,
17426         (cmdline_parse_inst_t *)&cmd_gro_flush,
17427         (cmdline_parse_inst_t *)&cmd_gro_show,
17428         (cmdline_parse_inst_t *)&cmd_gso_enable,
17429         (cmdline_parse_inst_t *)&cmd_gso_size,
17430         (cmdline_parse_inst_t *)&cmd_gso_show,
17431         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17432         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17433         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17434         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17435         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17436         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17437         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17438         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17439         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17440         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17441         (cmdline_parse_inst_t *)&cmd_config_dcb,
17442         (cmdline_parse_inst_t *)&cmd_read_reg,
17443         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17444         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17445         (cmdline_parse_inst_t *)&cmd_write_reg,
17446         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17447         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17448         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17449         (cmdline_parse_inst_t *)&cmd_stop,
17450         (cmdline_parse_inst_t *)&cmd_mac_addr,
17451         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17452         (cmdline_parse_inst_t *)&cmd_set_qmap,
17453         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17454         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17455         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17456         (cmdline_parse_inst_t *)&cmd_operate_port,
17457         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17458         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17459         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17460         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17461         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17462         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17463         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17464         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17465         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17466         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17467         (cmdline_parse_inst_t *)&cmd_config_mtu,
17468         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17469         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17470         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17471         (cmdline_parse_inst_t *)&cmd_config_rss,
17472         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17473         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17474         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17475         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17476         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17477         (cmdline_parse_inst_t *)&cmd_showport_reta,
17478         (cmdline_parse_inst_t *)&cmd_showport_macs,
17479         (cmdline_parse_inst_t *)&cmd_config_burst,
17480         (cmdline_parse_inst_t *)&cmd_config_thresh,
17481         (cmdline_parse_inst_t *)&cmd_config_threshold,
17482         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17483         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17484         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17485         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17486         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17487         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17488         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17489         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17490         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17491         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17492         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17493         (cmdline_parse_inst_t *)&cmd_dump,
17494         (cmdline_parse_inst_t *)&cmd_dump_one,
17495 #ifdef RTE_NET_I40E
17496         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17497 #endif
17498         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17499         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17500         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17501         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17502         (cmdline_parse_inst_t *)&cmd_flow,
17503         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17504         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17505         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17506         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17507         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17508         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17509         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17510         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17511         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17512         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17513         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17514         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17515         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17516         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17517         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17518         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17519         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17520         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17521         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17522         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17523         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17524         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17525         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17526         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17527         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17528         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17529         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17530         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17531         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17532         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17533         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17534         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17535         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17536         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17537         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17538         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17539         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17540         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17541         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17542         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17543         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17544         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17545         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17546         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17547         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17548         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17549         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17550         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17551         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17552         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17553         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17554         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17555         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17556         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17557         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17558         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17559         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17560         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17561         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17562         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17563         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17564         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17565         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17566         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17567         (cmdline_parse_inst_t *)&cmd_ddp_add,
17568         (cmdline_parse_inst_t *)&cmd_ddp_del,
17569         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17570         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17571         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17572         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17573         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17574         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17575         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17576         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17577         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17578         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17579         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17580         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17581
17582         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17583         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17584         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17585         (cmdline_parse_inst_t *)&cmd_queue_region,
17586         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17587         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17588         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17589         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17590         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17591         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17592         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17593         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17594         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17595         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17596         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17597         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17598         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17599         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17600         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17601         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17602         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17603         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17604         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17605         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17606         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17607         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17608         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17609         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17610         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17611         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17612         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17613         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17614         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17615         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17616         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17617         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17618         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17619         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17620         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17621         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17622 #ifdef RTE_LIB_BPF
17623         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17624         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17625 #endif
17626         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17627         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17628         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17629         (cmdline_parse_inst_t *)&cmd_set_raw,
17630         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17631         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17632         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17633         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17634         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17635         (cmdline_parse_inst_t *)&cmd_show_capability,
17636         NULL,
17637 };
17638
17639 /* read cmdline commands from file */
17640 void
17641 cmdline_read_from_file(const char *filename)
17642 {
17643         struct cmdline *cl;
17644
17645         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17646         if (cl == NULL) {
17647                 printf("Failed to create file based cmdline context: %s\n",
17648                        filename);
17649                 return;
17650         }
17651
17652         cmdline_interact(cl);
17653         cmdline_quit(cl);
17654
17655         cmdline_free(cl);
17656
17657         printf("Read CLI commands from %s\n", filename);
17658 }
17659
17660 /* prompt function, called from main on MAIN lcore */
17661 void
17662 prompt(void)
17663 {
17664         /* initialize non-constant commands */
17665         cmd_set_fwd_mode_init();
17666         cmd_set_fwd_retry_mode_init();
17667
17668         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17669         if (testpmd_cl == NULL)
17670                 return;
17671         cmdline_interact(testpmd_cl);
17672         cmdline_stdin_exit(testpmd_cl);
17673 }
17674
17675 void
17676 prompt_exit(void)
17677 {
17678         if (testpmd_cl != NULL)
17679                 cmdline_quit(testpmd_cl);
17680 }
17681
17682 static void
17683 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17684 {
17685         if (id == (portid_t)RTE_PORT_ALL) {
17686                 portid_t pid;
17687
17688                 RTE_ETH_FOREACH_DEV(pid) {
17689                         /* check if need_reconfig has been set to 1 */
17690                         if (ports[pid].need_reconfig == 0)
17691                                 ports[pid].need_reconfig = dev;
17692                         /* check if need_reconfig_queues has been set to 1 */
17693                         if (ports[pid].need_reconfig_queues == 0)
17694                                 ports[pid].need_reconfig_queues = queue;
17695                 }
17696         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17697                 /* check if need_reconfig has been set to 1 */
17698                 if (ports[id].need_reconfig == 0)
17699                         ports[id].need_reconfig = dev;
17700                 /* check if need_reconfig_queues has been set to 1 */
17701                 if (ports[id].need_reconfig_queues == 0)
17702                         ports[id].need_reconfig_queues = queue;
17703         }
17704 }