ethdev: remove API to config L2 tunnel EtherType
[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"
847                         " (enable|disable)\n"
848                         "    Enable/disable the E-tag support.\n\n"
849
850                         "port config (port_id) pctype mapping reset\n"
851                         "    Reset flow type to pctype mapping on a port\n\n"
852
853                         "port config (port_id) pctype mapping update"
854                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
855                         "    Update a flow type to pctype mapping item on a port\n\n"
856
857                         "port config (port_id) pctype (pctype_id) hash_inset|"
858                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
859                         " (field_idx)\n"
860                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
861
862                         "port config (port_id) pctype (pctype_id) hash_inset|"
863                         "fdir_inset|fdir_flx_inset clear all"
864                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
865
866                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
867                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
868
869                         "port config <port_id> rx_offload vlan_strip|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
871                         "outer_ipv4_cksum|macsec_strip|header_split|"
872                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
873                         "buffer_split|timestamp|security|keep_crc on|off\n"
874                         "     Enable or disable a per port Rx offloading"
875                         " on all Rx queues of a port\n\n"
876
877                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
878                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
879                         "outer_ipv4_cksum|macsec_strip|header_split|"
880                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
881                         "buffer_split|timestamp|security|keep_crc on|off\n"
882                         "    Enable or disable a per queue Rx offloading"
883                         " only on a specific Rx queue\n\n"
884
885                         "port config (port_id) tx_offload vlan_insert|"
886                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
889                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
890                         "security on|off\n"
891                         "    Enable or disable a per port Tx offloading"
892                         " on all Tx queues of a port\n\n"
893
894                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
895                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
896                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
897                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
898                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
899                         " on|off\n"
900                         "    Enable or disable a per queue Tx offloading"
901                         " only on a specific Tx queue\n\n"
902
903                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
904                         "    Load an eBPF program as a callback"
905                         " for particular RX/TX queue\n\n"
906
907                         "bpf-unload rx|tx (port) (queue)\n"
908                         "    Unload previously loaded eBPF program"
909                         " for particular RX/TX queue\n\n"
910
911                         "port config (port_id) tx_metadata (value)\n"
912                         "    Set Tx metadata value per port. Testpmd will add this value"
913                         " to any Tx packet sent from this port\n\n"
914
915                         "port config (port_id) dynf (name) set|clear\n"
916                         "    Register a dynf and Set/clear this flag on Tx. "
917                         "Testpmd will set this value to any Tx packet "
918                         "sent from this port\n\n"
919                 );
920         }
921
922         if (show_all || !strcmp(res->section, "registers")) {
923
924                 cmdline_printf(
925                         cl,
926                         "\n"
927                         "Registers:\n"
928                         "----------\n\n"
929
930                         "read reg (port_id) (address)\n"
931                         "    Display value of a port register.\n\n"
932
933                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
934                         "    Display a port register bit field.\n\n"
935
936                         "read regbit (port_id) (address) (bit_x)\n"
937                         "    Display a single port register bit.\n\n"
938
939                         "write reg (port_id) (address) (value)\n"
940                         "    Set value of a port register.\n\n"
941
942                         "write regfield (port_id) (address) (bit_x) (bit_y)"
943                         " (value)\n"
944                         "    Set bit field of a port register.\n\n"
945
946                         "write regbit (port_id) (address) (bit_x) (value)\n"
947                         "    Set single bit value of a port register.\n\n"
948                 );
949         }
950         if (show_all || !strcmp(res->section, "filters")) {
951
952                 cmdline_printf(
953                         cl,
954                         "\n"
955                         "filters:\n"
956                         "--------\n\n"
957
958 #ifdef RTE_NET_I40E
959                         "flow_director_filter (port_id) mode raw (add|del|update)"
960                         " flow (flow_id) (drop|fwd) queue (queue_id)"
961                         " fd_id (fd_id_value) packet (packet file name)\n"
962                         "    Add/Del a raw type flow director filter.\n\n"
963 #endif
964
965                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
966                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
967                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
968                         "    Set flow director IP mask.\n\n"
969
970                         "flow_director_mask (port_id) mode MAC-VLAN"
971                         " vlan (vlan_value)\n"
972                         "    Set flow director MAC-VLAN mask.\n\n"
973
974                         "flow_director_mask (port_id) mode Tunnel"
975                         " vlan (vlan_value) mac (mac_value)"
976                         " tunnel-type (tunnel_type_value)"
977                         " tunnel-id (tunnel_id_value)\n"
978                         "    Set flow director Tunnel mask.\n\n"
979
980                         "flow_director_flex_payload (port_id)"
981                         " (raw|l2|l3|l4) (config)\n"
982                         "    Configure flex payload selection.\n\n"
983
984                         "flow validate {port_id}"
985                         " [group {group_id}] [priority {level}]"
986                         " [ingress] [egress]"
987                         " pattern {item} [/ {item} [...]] / end"
988                         " actions {action} [/ {action} [...]] / end\n"
989                         "    Check whether a flow rule can be created.\n\n"
990
991                         "flow create {port_id}"
992                         " [group {group_id}] [priority {level}]"
993                         " [ingress] [egress]"
994                         " pattern {item} [/ {item} [...]] / end"
995                         " actions {action} [/ {action} [...]] / end\n"
996                         "    Create a flow rule.\n\n"
997
998                         "flow destroy {port_id} rule {rule_id} [...]\n"
999                         "    Destroy specific flow rules.\n\n"
1000
1001                         "flow flush {port_id}\n"
1002                         "    Destroy all flow rules.\n\n"
1003
1004                         "flow query {port_id} {rule_id} {action}\n"
1005                         "    Query an existing flow rule.\n\n"
1006
1007                         "flow list {port_id} [group {group_id}] [...]\n"
1008                         "    List existing flow rules sorted by priority,"
1009                         " filtered by group identifiers.\n\n"
1010
1011                         "flow isolate {port_id} {boolean}\n"
1012                         "    Restrict ingress traffic to the defined"
1013                         " flow rules\n\n"
1014
1015                         "flow aged {port_id} [destroy]\n"
1016                         "    List and destroy aged flows"
1017                         " flow rules\n\n"
1018
1019                         "flow shared_action {port_id} create"
1020                         " [action_id {shared_action_id}]"
1021                         " [ingress] [egress]"
1022                         " action {action} / end\n"
1023                         "    Create shared action.\n\n"
1024
1025                         "flow shared_action {port_id} update"
1026                         " {shared_action_id} action {action} / end\n"
1027                         "    Update shared action.\n\n"
1028
1029                         "flow shared_action {port_id} destroy"
1030                         " action_id {shared_action_id} [...]\n"
1031                         "    Destroy specific shared actions.\n\n"
1032
1033                         "flow shared_action {port_id} query"
1034                         " {shared_action_id}\n"
1035                         "    Query an existing shared action.\n\n"
1036
1037                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1038                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1039                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1040                         "       Configure the VXLAN encapsulation for flows.\n\n"
1041
1042                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1043                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1044                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1045                         " eth-dst (eth-dst)\n"
1046                         "       Configure the VXLAN encapsulation for flows.\n\n"
1047
1048                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1049                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1050                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1051                         " eth-dst (eth-dst)\n"
1052                         "       Configure the VXLAN encapsulation for flows.\n\n"
1053
1054                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1055                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1056                         " (eth-dst)\n"
1057                         "       Configure the NVGRE encapsulation for flows.\n\n"
1058
1059                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1060                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1061                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1062                         "       Configure the NVGRE encapsulation for flows.\n\n"
1063
1064                         "set raw_encap {flow items}\n"
1065                         "       Configure the encapsulation with raw data.\n\n"
1066
1067                         "set raw_decap {flow items}\n"
1068                         "       Configure the decapsulation with raw data.\n\n"
1069
1070                 );
1071         }
1072
1073         if (show_all || !strcmp(res->section, "traffic_management")) {
1074                 cmdline_printf(
1075                         cl,
1076                         "\n"
1077                         "Traffic Management:\n"
1078                         "--------------\n"
1079                         "show port tm cap (port_id)\n"
1080                         "       Display the port TM capability.\n\n"
1081
1082                         "show port tm level cap (port_id) (level_id)\n"
1083                         "       Display the port TM hierarchical level capability.\n\n"
1084
1085                         "show port tm node cap (port_id) (node_id)\n"
1086                         "       Display the port TM node capability.\n\n"
1087
1088                         "show port tm node type (port_id) (node_id)\n"
1089                         "       Display the port TM node type.\n\n"
1090
1091                         "show port tm node stats (port_id) (node_id) (clear)\n"
1092                         "       Display the port TM node stats.\n\n"
1093
1094                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1095                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1096                         " (packet_length_adjust) (packet_mode)\n"
1097                         "       Add port tm node private shaper profile.\n\n"
1098
1099                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1100                         "       Delete port tm node private shaper profile.\n\n"
1101
1102                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1103                         " (shaper_profile_id)\n"
1104                         "       Add/update port tm node shared shaper.\n\n"
1105
1106                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1107                         "       Delete port tm node shared shaper.\n\n"
1108
1109                         "set port tm node shaper profile (port_id) (node_id)"
1110                         " (shaper_profile_id)\n"
1111                         "       Set port tm node shaper profile.\n\n"
1112
1113                         "add port tm node wred profile (port_id) (wred_profile_id)"
1114                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1115                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1116                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1117                         "       Add port tm node wred profile.\n\n"
1118
1119                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1120                         "       Delete port tm node wred profile.\n\n"
1121
1122                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1123                         " (priority) (weight) (level_id) (shaper_profile_id)"
1124                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1125                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1126                         "       Add port tm nonleaf node.\n\n"
1127
1128                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1129                         " (priority) (weight) (level_id) (shaper_profile_id)"
1130                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1131                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1132                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1133
1134                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1135                         " (priority) (weight) (level_id) (shaper_profile_id)"
1136                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1137                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1138                         "       Add port tm leaf node.\n\n"
1139
1140                         "del port tm node (port_id) (node_id)\n"
1141                         "       Delete port tm node.\n\n"
1142
1143                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1144                         " (priority) (weight)\n"
1145                         "       Set port tm node parent.\n\n"
1146
1147                         "suspend port tm node (port_id) (node_id)"
1148                         "       Suspend tm node.\n\n"
1149
1150                         "resume port tm node (port_id) (node_id)"
1151                         "       Resume tm node.\n\n"
1152
1153                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1154                         "       Commit tm hierarchy.\n\n"
1155
1156                         "set port tm mark ip_ecn (port) (green) (yellow)"
1157                         " (red)\n"
1158                         "    Enables/Disables the traffic management marking"
1159                         " for IP ECN (Explicit Congestion Notification)"
1160                         " packets on a given port\n\n"
1161
1162                         "set port tm mark ip_dscp (port) (green) (yellow)"
1163                         " (red)\n"
1164                         "    Enables/Disables the traffic management marking"
1165                         " on the port for IP dscp packets\n\n"
1166
1167                         "set port tm mark vlan_dei (port) (green) (yellow)"
1168                         " (red)\n"
1169                         "    Enables/Disables the traffic management marking"
1170                         " on the port for VLAN packets with DEI enabled\n\n"
1171                 );
1172         }
1173
1174         if (show_all || !strcmp(res->section, "devices")) {
1175                 cmdline_printf(
1176                         cl,
1177                         "\n"
1178                         "Device Operations:\n"
1179                         "--------------\n"
1180                         "device detach (identifier)\n"
1181                         "       Detach device by identifier.\n\n"
1182                 );
1183         }
1184
1185 }
1186
1187 cmdline_parse_token_string_t cmd_help_long_help =
1188         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1189
1190 cmdline_parse_token_string_t cmd_help_long_section =
1191         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1192                         "all#control#display#config#"
1193                         "ports#registers#filters#traffic_management#devices");
1194
1195 cmdline_parse_inst_t cmd_help_long = {
1196         .f = cmd_help_long_parsed,
1197         .data = NULL,
1198         .help_str = "help all|control|display|config|ports|register|"
1199                 "filters|traffic_management|devices: "
1200                 "Show help",
1201         .tokens = {
1202                 (void *)&cmd_help_long_help,
1203                 (void *)&cmd_help_long_section,
1204                 NULL,
1205         },
1206 };
1207
1208
1209 /* *** start/stop/close all ports *** */
1210 struct cmd_operate_port_result {
1211         cmdline_fixed_string_t keyword;
1212         cmdline_fixed_string_t name;
1213         cmdline_fixed_string_t value;
1214 };
1215
1216 static void cmd_operate_port_parsed(void *parsed_result,
1217                                 __rte_unused struct cmdline *cl,
1218                                 __rte_unused void *data)
1219 {
1220         struct cmd_operate_port_result *res = parsed_result;
1221
1222         if (!strcmp(res->name, "start"))
1223                 start_port(RTE_PORT_ALL);
1224         else if (!strcmp(res->name, "stop"))
1225                 stop_port(RTE_PORT_ALL);
1226         else if (!strcmp(res->name, "close"))
1227                 close_port(RTE_PORT_ALL);
1228         else if (!strcmp(res->name, "reset"))
1229                 reset_port(RTE_PORT_ALL);
1230         else
1231                 printf("Unknown parameter\n");
1232 }
1233
1234 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1235         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1236                                                                 "port");
1237 cmdline_parse_token_string_t cmd_operate_port_all_port =
1238         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1239                                                 "start#stop#close#reset");
1240 cmdline_parse_token_string_t cmd_operate_port_all_all =
1241         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1242
1243 cmdline_parse_inst_t cmd_operate_port = {
1244         .f = cmd_operate_port_parsed,
1245         .data = NULL,
1246         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1247         .tokens = {
1248                 (void *)&cmd_operate_port_all_cmd,
1249                 (void *)&cmd_operate_port_all_port,
1250                 (void *)&cmd_operate_port_all_all,
1251                 NULL,
1252         },
1253 };
1254
1255 /* *** start/stop/close specific port *** */
1256 struct cmd_operate_specific_port_result {
1257         cmdline_fixed_string_t keyword;
1258         cmdline_fixed_string_t name;
1259         uint8_t value;
1260 };
1261
1262 static void cmd_operate_specific_port_parsed(void *parsed_result,
1263                         __rte_unused struct cmdline *cl,
1264                                 __rte_unused void *data)
1265 {
1266         struct cmd_operate_specific_port_result *res = parsed_result;
1267
1268         if (!strcmp(res->name, "start"))
1269                 start_port(res->value);
1270         else if (!strcmp(res->name, "stop"))
1271                 stop_port(res->value);
1272         else if (!strcmp(res->name, "close"))
1273                 close_port(res->value);
1274         else if (!strcmp(res->name, "reset"))
1275                 reset_port(res->value);
1276         else
1277                 printf("Unknown parameter\n");
1278 }
1279
1280 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1281         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1282                                                         keyword, "port");
1283 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1284         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1285                                                 name, "start#stop#close#reset");
1286 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1287         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1288                                                         value, UINT8);
1289
1290 cmdline_parse_inst_t cmd_operate_specific_port = {
1291         .f = cmd_operate_specific_port_parsed,
1292         .data = NULL,
1293         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1294         .tokens = {
1295                 (void *)&cmd_operate_specific_port_cmd,
1296                 (void *)&cmd_operate_specific_port_port,
1297                 (void *)&cmd_operate_specific_port_id,
1298                 NULL,
1299         },
1300 };
1301
1302 /* *** enable port setup (after attach) via iterator or event *** */
1303 struct cmd_set_port_setup_on_result {
1304         cmdline_fixed_string_t set;
1305         cmdline_fixed_string_t port;
1306         cmdline_fixed_string_t setup;
1307         cmdline_fixed_string_t on;
1308         cmdline_fixed_string_t mode;
1309 };
1310
1311 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1312                                 __rte_unused struct cmdline *cl,
1313                                 __rte_unused void *data)
1314 {
1315         struct cmd_set_port_setup_on_result *res = parsed_result;
1316
1317         if (strcmp(res->mode, "event") == 0)
1318                 setup_on_probe_event = true;
1319         else if (strcmp(res->mode, "iterator") == 0)
1320                 setup_on_probe_event = false;
1321         else
1322                 printf("Unknown mode\n");
1323 }
1324
1325 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1326         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1327                         set, "set");
1328 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1329         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1330                         port, "port");
1331 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1332         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1333                         setup, "setup");
1334 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1335         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1336                         on, "on");
1337 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1338         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1339                         mode, "iterator#event");
1340
1341 cmdline_parse_inst_t cmd_set_port_setup_on = {
1342         .f = cmd_set_port_setup_on_parsed,
1343         .data = NULL,
1344         .help_str = "set port setup on iterator|event",
1345         .tokens = {
1346                 (void *)&cmd_set_port_setup_on_set,
1347                 (void *)&cmd_set_port_setup_on_port,
1348                 (void *)&cmd_set_port_setup_on_setup,
1349                 (void *)&cmd_set_port_setup_on_on,
1350                 (void *)&cmd_set_port_setup_on_mode,
1351                 NULL,
1352         },
1353 };
1354
1355 /* *** attach a specified port *** */
1356 struct cmd_operate_attach_port_result {
1357         cmdline_fixed_string_t port;
1358         cmdline_fixed_string_t keyword;
1359         cmdline_multi_string_t identifier;
1360 };
1361
1362 static void cmd_operate_attach_port_parsed(void *parsed_result,
1363                                 __rte_unused struct cmdline *cl,
1364                                 __rte_unused void *data)
1365 {
1366         struct cmd_operate_attach_port_result *res = parsed_result;
1367
1368         if (!strcmp(res->keyword, "attach"))
1369                 attach_port(res->identifier);
1370         else
1371                 printf("Unknown parameter\n");
1372 }
1373
1374 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1375         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1376                         port, "port");
1377 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1378         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1379                         keyword, "attach");
1380 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1381         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1382                         identifier, TOKEN_STRING_MULTI);
1383
1384 cmdline_parse_inst_t cmd_operate_attach_port = {
1385         .f = cmd_operate_attach_port_parsed,
1386         .data = NULL,
1387         .help_str = "port attach <identifier>: "
1388                 "(identifier: pci address or virtual dev name)",
1389         .tokens = {
1390                 (void *)&cmd_operate_attach_port_port,
1391                 (void *)&cmd_operate_attach_port_keyword,
1392                 (void *)&cmd_operate_attach_port_identifier,
1393                 NULL,
1394         },
1395 };
1396
1397 /* *** detach a specified port *** */
1398 struct cmd_operate_detach_port_result {
1399         cmdline_fixed_string_t port;
1400         cmdline_fixed_string_t keyword;
1401         portid_t port_id;
1402 };
1403
1404 static void cmd_operate_detach_port_parsed(void *parsed_result,
1405                                 __rte_unused struct cmdline *cl,
1406                                 __rte_unused void *data)
1407 {
1408         struct cmd_operate_detach_port_result *res = parsed_result;
1409
1410         if (!strcmp(res->keyword, "detach")) {
1411                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1412                 detach_port_device(res->port_id);
1413         } else {
1414                 printf("Unknown parameter\n");
1415         }
1416 }
1417
1418 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1419         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1420                         port, "port");
1421 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1422         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1423                         keyword, "detach");
1424 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1425         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1426                         port_id, UINT16);
1427
1428 cmdline_parse_inst_t cmd_operate_detach_port = {
1429         .f = cmd_operate_detach_port_parsed,
1430         .data = NULL,
1431         .help_str = "port detach <port_id>",
1432         .tokens = {
1433                 (void *)&cmd_operate_detach_port_port,
1434                 (void *)&cmd_operate_detach_port_keyword,
1435                 (void *)&cmd_operate_detach_port_port_id,
1436                 NULL,
1437         },
1438 };
1439
1440 /* *** detach device by identifier *** */
1441 struct cmd_operate_detach_device_result {
1442         cmdline_fixed_string_t device;
1443         cmdline_fixed_string_t keyword;
1444         cmdline_fixed_string_t identifier;
1445 };
1446
1447 static void cmd_operate_detach_device_parsed(void *parsed_result,
1448                                 __rte_unused struct cmdline *cl,
1449                                 __rte_unused void *data)
1450 {
1451         struct cmd_operate_detach_device_result *res = parsed_result;
1452
1453         if (!strcmp(res->keyword, "detach"))
1454                 detach_devargs(res->identifier);
1455         else
1456                 printf("Unknown parameter\n");
1457 }
1458
1459 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1460         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1461                         device, "device");
1462 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1463         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1464                         keyword, "detach");
1465 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1466         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1467                         identifier, NULL);
1468
1469 cmdline_parse_inst_t cmd_operate_detach_device = {
1470         .f = cmd_operate_detach_device_parsed,
1471         .data = NULL,
1472         .help_str = "device detach <identifier>:"
1473                 "(identifier: pci address or virtual dev name)",
1474         .tokens = {
1475                 (void *)&cmd_operate_detach_device_device,
1476                 (void *)&cmd_operate_detach_device_keyword,
1477                 (void *)&cmd_operate_detach_device_identifier,
1478                 NULL,
1479         },
1480 };
1481 /* *** configure speed for all ports *** */
1482 struct cmd_config_speed_all {
1483         cmdline_fixed_string_t port;
1484         cmdline_fixed_string_t keyword;
1485         cmdline_fixed_string_t all;
1486         cmdline_fixed_string_t item1;
1487         cmdline_fixed_string_t item2;
1488         cmdline_fixed_string_t value1;
1489         cmdline_fixed_string_t value2;
1490 };
1491
1492 static int
1493 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1494 {
1495
1496         int duplex;
1497
1498         if (!strcmp(duplexstr, "half")) {
1499                 duplex = ETH_LINK_HALF_DUPLEX;
1500         } else if (!strcmp(duplexstr, "full")) {
1501                 duplex = ETH_LINK_FULL_DUPLEX;
1502         } else if (!strcmp(duplexstr, "auto")) {
1503                 duplex = ETH_LINK_FULL_DUPLEX;
1504         } else {
1505                 printf("Unknown duplex parameter\n");
1506                 return -1;
1507         }
1508
1509         if (!strcmp(speedstr, "10")) {
1510                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1511                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1512         } else if (!strcmp(speedstr, "100")) {
1513                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1514                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1515         } else {
1516                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1517                         printf("Invalid speed/duplex parameters\n");
1518                         return -1;
1519                 }
1520                 if (!strcmp(speedstr, "1000")) {
1521                         *speed = ETH_LINK_SPEED_1G;
1522                 } else if (!strcmp(speedstr, "10000")) {
1523                         *speed = ETH_LINK_SPEED_10G;
1524                 } else if (!strcmp(speedstr, "25000")) {
1525                         *speed = ETH_LINK_SPEED_25G;
1526                 } else if (!strcmp(speedstr, "40000")) {
1527                         *speed = ETH_LINK_SPEED_40G;
1528                 } else if (!strcmp(speedstr, "50000")) {
1529                         *speed = ETH_LINK_SPEED_50G;
1530                 } else if (!strcmp(speedstr, "100000")) {
1531                         *speed = ETH_LINK_SPEED_100G;
1532                 } else if (!strcmp(speedstr, "200000")) {
1533                         *speed = ETH_LINK_SPEED_200G;
1534                 } else if (!strcmp(speedstr, "auto")) {
1535                         *speed = ETH_LINK_SPEED_AUTONEG;
1536                 } else {
1537                         printf("Unknown speed parameter\n");
1538                         return -1;
1539                 }
1540         }
1541
1542         return 0;
1543 }
1544
1545 static void
1546 cmd_config_speed_all_parsed(void *parsed_result,
1547                         __rte_unused struct cmdline *cl,
1548                         __rte_unused void *data)
1549 {
1550         struct cmd_config_speed_all *res = parsed_result;
1551         uint32_t link_speed;
1552         portid_t pid;
1553
1554         if (!all_ports_stopped()) {
1555                 printf("Please stop all ports first\n");
1556                 return;
1557         }
1558
1559         if (parse_and_check_speed_duplex(res->value1, res->value2,
1560                         &link_speed) < 0)
1561                 return;
1562
1563         RTE_ETH_FOREACH_DEV(pid) {
1564                 ports[pid].dev_conf.link_speeds = link_speed;
1565         }
1566
1567         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1568 }
1569
1570 cmdline_parse_token_string_t cmd_config_speed_all_port =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1572 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1573         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1574                                                         "config");
1575 cmdline_parse_token_string_t cmd_config_speed_all_all =
1576         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1577 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1578         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1579 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1581                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1582 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1584 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1585         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1586                                                 "half#full#auto");
1587
1588 cmdline_parse_inst_t cmd_config_speed_all = {
1589         .f = cmd_config_speed_all_parsed,
1590         .data = NULL,
1591         .help_str = "port config all speed "
1592                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1593                                                         "half|full|auto",
1594         .tokens = {
1595                 (void *)&cmd_config_speed_all_port,
1596                 (void *)&cmd_config_speed_all_keyword,
1597                 (void *)&cmd_config_speed_all_all,
1598                 (void *)&cmd_config_speed_all_item1,
1599                 (void *)&cmd_config_speed_all_value1,
1600                 (void *)&cmd_config_speed_all_item2,
1601                 (void *)&cmd_config_speed_all_value2,
1602                 NULL,
1603         },
1604 };
1605
1606 /* *** configure speed for specific port *** */
1607 struct cmd_config_speed_specific {
1608         cmdline_fixed_string_t port;
1609         cmdline_fixed_string_t keyword;
1610         portid_t id;
1611         cmdline_fixed_string_t item1;
1612         cmdline_fixed_string_t item2;
1613         cmdline_fixed_string_t value1;
1614         cmdline_fixed_string_t value2;
1615 };
1616
1617 static void
1618 cmd_config_speed_specific_parsed(void *parsed_result,
1619                                 __rte_unused struct cmdline *cl,
1620                                 __rte_unused void *data)
1621 {
1622         struct cmd_config_speed_specific *res = parsed_result;
1623         uint32_t link_speed;
1624
1625         if (!all_ports_stopped()) {
1626                 printf("Please stop all ports first\n");
1627                 return;
1628         }
1629
1630         if (port_id_is_invalid(res->id, ENABLED_WARN))
1631                 return;
1632
1633         if (parse_and_check_speed_duplex(res->value1, res->value2,
1634                         &link_speed) < 0)
1635                 return;
1636
1637         ports[res->id].dev_conf.link_speeds = link_speed;
1638
1639         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1640 }
1641
1642
1643 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1645                                                                 "port");
1646 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1648                                                                 "config");
1649 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1650         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1651 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1653                                                                 "speed");
1654 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1656                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1657 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1659                                                                 "duplex");
1660 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1662                                                         "half#full#auto");
1663
1664 cmdline_parse_inst_t cmd_config_speed_specific = {
1665         .f = cmd_config_speed_specific_parsed,
1666         .data = NULL,
1667         .help_str = "port config <port_id> speed "
1668                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1669                                                         "half|full|auto",
1670         .tokens = {
1671                 (void *)&cmd_config_speed_specific_port,
1672                 (void *)&cmd_config_speed_specific_keyword,
1673                 (void *)&cmd_config_speed_specific_id,
1674                 (void *)&cmd_config_speed_specific_item1,
1675                 (void *)&cmd_config_speed_specific_value1,
1676                 (void *)&cmd_config_speed_specific_item2,
1677                 (void *)&cmd_config_speed_specific_value2,
1678                 NULL,
1679         },
1680 };
1681
1682 /* *** configure loopback for all ports *** */
1683 struct cmd_config_loopback_all {
1684         cmdline_fixed_string_t port;
1685         cmdline_fixed_string_t keyword;
1686         cmdline_fixed_string_t all;
1687         cmdline_fixed_string_t item;
1688         uint32_t mode;
1689 };
1690
1691 static void
1692 cmd_config_loopback_all_parsed(void *parsed_result,
1693                         __rte_unused struct cmdline *cl,
1694                         __rte_unused void *data)
1695 {
1696         struct cmd_config_loopback_all *res = parsed_result;
1697         portid_t pid;
1698
1699         if (!all_ports_stopped()) {
1700                 printf("Please stop all ports first\n");
1701                 return;
1702         }
1703
1704         RTE_ETH_FOREACH_DEV(pid) {
1705                 ports[pid].dev_conf.lpbk_mode = res->mode;
1706         }
1707
1708         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1709 }
1710
1711 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1713 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1715                                                         "config");
1716 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1718 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1720                                                         "loopback");
1721 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1722         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1723
1724 cmdline_parse_inst_t cmd_config_loopback_all = {
1725         .f = cmd_config_loopback_all_parsed,
1726         .data = NULL,
1727         .help_str = "port config all loopback <mode>",
1728         .tokens = {
1729                 (void *)&cmd_config_loopback_all_port,
1730                 (void *)&cmd_config_loopback_all_keyword,
1731                 (void *)&cmd_config_loopback_all_all,
1732                 (void *)&cmd_config_loopback_all_item,
1733                 (void *)&cmd_config_loopback_all_mode,
1734                 NULL,
1735         },
1736 };
1737
1738 /* *** configure loopback for specific port *** */
1739 struct cmd_config_loopback_specific {
1740         cmdline_fixed_string_t port;
1741         cmdline_fixed_string_t keyword;
1742         uint16_t port_id;
1743         cmdline_fixed_string_t item;
1744         uint32_t mode;
1745 };
1746
1747 static void
1748 cmd_config_loopback_specific_parsed(void *parsed_result,
1749                                 __rte_unused struct cmdline *cl,
1750                                 __rte_unused void *data)
1751 {
1752         struct cmd_config_loopback_specific *res = parsed_result;
1753
1754         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1755                 return;
1756
1757         if (!port_is_stopped(res->port_id)) {
1758                 printf("Please stop port %u first\n", res->port_id);
1759                 return;
1760         }
1761
1762         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1763
1764         cmd_reconfig_device_queue(res->port_id, 1, 1);
1765 }
1766
1767
1768 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1770                                                                 "port");
1771 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1773                                                                 "config");
1774 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1775         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1776                                                                 UINT16);
1777 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1778         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1779                                                                 "loopback");
1780 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1781         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1782                               UINT32);
1783
1784 cmdline_parse_inst_t cmd_config_loopback_specific = {
1785         .f = cmd_config_loopback_specific_parsed,
1786         .data = NULL,
1787         .help_str = "port config <port_id> loopback <mode>",
1788         .tokens = {
1789                 (void *)&cmd_config_loopback_specific_port,
1790                 (void *)&cmd_config_loopback_specific_keyword,
1791                 (void *)&cmd_config_loopback_specific_id,
1792                 (void *)&cmd_config_loopback_specific_item,
1793                 (void *)&cmd_config_loopback_specific_mode,
1794                 NULL,
1795         },
1796 };
1797
1798 /* *** configure txq/rxq, txd/rxd *** */
1799 struct cmd_config_rx_tx {
1800         cmdline_fixed_string_t port;
1801         cmdline_fixed_string_t keyword;
1802         cmdline_fixed_string_t all;
1803         cmdline_fixed_string_t name;
1804         uint16_t value;
1805 };
1806
1807 static void
1808 cmd_config_rx_tx_parsed(void *parsed_result,
1809                         __rte_unused struct cmdline *cl,
1810                         __rte_unused void *data)
1811 {
1812         struct cmd_config_rx_tx *res = parsed_result;
1813
1814         if (!all_ports_stopped()) {
1815                 printf("Please stop all ports first\n");
1816                 return;
1817         }
1818         if (!strcmp(res->name, "rxq")) {
1819                 if (!res->value && !nb_txq) {
1820                         printf("Warning: Either rx or tx queues should be non zero\n");
1821                         return;
1822                 }
1823                 if (check_nb_rxq(res->value) != 0)
1824                         return;
1825                 nb_rxq = res->value;
1826         }
1827         else if (!strcmp(res->name, "txq")) {
1828                 if (!res->value && !nb_rxq) {
1829                         printf("Warning: Either rx or tx queues should be non zero\n");
1830                         return;
1831                 }
1832                 if (check_nb_txq(res->value) != 0)
1833                         return;
1834                 nb_txq = res->value;
1835         }
1836         else if (!strcmp(res->name, "rxd")) {
1837                 if (check_nb_rxd(res->value) != 0)
1838                         return;
1839                 nb_rxd = res->value;
1840         } else if (!strcmp(res->name, "txd")) {
1841                 if (check_nb_txd(res->value) != 0)
1842                         return;
1843
1844                 nb_txd = res->value;
1845         } else {
1846                 printf("Unknown parameter\n");
1847                 return;
1848         }
1849
1850         fwd_config_setup();
1851
1852         init_port_config();
1853
1854         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1855 }
1856
1857 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1858         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1859 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1861 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1863 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1864         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1865                                                 "rxq#txq#rxd#txd");
1866 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1867         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1868
1869 cmdline_parse_inst_t cmd_config_rx_tx = {
1870         .f = cmd_config_rx_tx_parsed,
1871         .data = NULL,
1872         .help_str = "port config all rxq|txq|rxd|txd <value>",
1873         .tokens = {
1874                 (void *)&cmd_config_rx_tx_port,
1875                 (void *)&cmd_config_rx_tx_keyword,
1876                 (void *)&cmd_config_rx_tx_all,
1877                 (void *)&cmd_config_rx_tx_name,
1878                 (void *)&cmd_config_rx_tx_value,
1879                 NULL,
1880         },
1881 };
1882
1883 /* *** config max packet length *** */
1884 struct cmd_config_max_pkt_len_result {
1885         cmdline_fixed_string_t port;
1886         cmdline_fixed_string_t keyword;
1887         cmdline_fixed_string_t all;
1888         cmdline_fixed_string_t name;
1889         uint32_t value;
1890 };
1891
1892 static void
1893 cmd_config_max_pkt_len_parsed(void *parsed_result,
1894                                 __rte_unused struct cmdline *cl,
1895                                 __rte_unused void *data)
1896 {
1897         struct cmd_config_max_pkt_len_result *res = parsed_result;
1898         portid_t pid;
1899
1900         if (!all_ports_stopped()) {
1901                 printf("Please stop all ports first\n");
1902                 return;
1903         }
1904
1905         RTE_ETH_FOREACH_DEV(pid) {
1906                 struct rte_port *port = &ports[pid];
1907                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1908
1909                 if (!strcmp(res->name, "max-pkt-len")) {
1910                         if (res->value < RTE_ETHER_MIN_LEN) {
1911                                 printf("max-pkt-len can not be less than %d\n",
1912                                                 RTE_ETHER_MIN_LEN);
1913                                 return;
1914                         }
1915                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1916                                 return;
1917
1918                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1919                         if (res->value > RTE_ETHER_MAX_LEN)
1920                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1921                         else
1922                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1923                         port->dev_conf.rxmode.offloads = rx_offloads;
1924                 } else {
1925                         printf("Unknown parameter\n");
1926                         return;
1927                 }
1928         }
1929
1930         init_port_config();
1931
1932         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1933 }
1934
1935 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1937                                                                 "port");
1938 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1940                                                                 "config");
1941 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1943                                                                 "all");
1944 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1946                                                                 "max-pkt-len");
1947 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1948         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1949                                                                 UINT32);
1950
1951 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1952         .f = cmd_config_max_pkt_len_parsed,
1953         .data = NULL,
1954         .help_str = "port config all max-pkt-len <value>",
1955         .tokens = {
1956                 (void *)&cmd_config_max_pkt_len_port,
1957                 (void *)&cmd_config_max_pkt_len_keyword,
1958                 (void *)&cmd_config_max_pkt_len_all,
1959                 (void *)&cmd_config_max_pkt_len_name,
1960                 (void *)&cmd_config_max_pkt_len_value,
1961                 NULL,
1962         },
1963 };
1964
1965 /* *** config max LRO aggregated packet size *** */
1966 struct cmd_config_max_lro_pkt_size_result {
1967         cmdline_fixed_string_t port;
1968         cmdline_fixed_string_t keyword;
1969         cmdline_fixed_string_t all;
1970         cmdline_fixed_string_t name;
1971         uint32_t value;
1972 };
1973
1974 static void
1975 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1976                                 __rte_unused struct cmdline *cl,
1977                                 __rte_unused void *data)
1978 {
1979         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1980         portid_t pid;
1981
1982         if (!all_ports_stopped()) {
1983                 printf("Please stop all ports first\n");
1984                 return;
1985         }
1986
1987         RTE_ETH_FOREACH_DEV(pid) {
1988                 struct rte_port *port = &ports[pid];
1989
1990                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1991                         if (res->value ==
1992                                         port->dev_conf.rxmode.max_lro_pkt_size)
1993                                 return;
1994
1995                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1996                 } else {
1997                         printf("Unknown parameter\n");
1998                         return;
1999                 }
2000         }
2001
2002         init_port_config();
2003
2004         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2005 }
2006
2007 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2009                                  port, "port");
2010 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2012                                  keyword, "config");
2013 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2015                                  all, "all");
2016 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2018                                  name, "max-lro-pkt-size");
2019 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2020         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2021                               value, UINT32);
2022
2023 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2024         .f = cmd_config_max_lro_pkt_size_parsed,
2025         .data = NULL,
2026         .help_str = "port config all max-lro-pkt-size <value>",
2027         .tokens = {
2028                 (void *)&cmd_config_max_lro_pkt_size_port,
2029                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2030                 (void *)&cmd_config_max_lro_pkt_size_all,
2031                 (void *)&cmd_config_max_lro_pkt_size_name,
2032                 (void *)&cmd_config_max_lro_pkt_size_value,
2033                 NULL,
2034         },
2035 };
2036
2037 /* *** configure port MTU *** */
2038 struct cmd_config_mtu_result {
2039         cmdline_fixed_string_t port;
2040         cmdline_fixed_string_t keyword;
2041         cmdline_fixed_string_t mtu;
2042         portid_t port_id;
2043         uint16_t value;
2044 };
2045
2046 static void
2047 cmd_config_mtu_parsed(void *parsed_result,
2048                       __rte_unused struct cmdline *cl,
2049                       __rte_unused void *data)
2050 {
2051         struct cmd_config_mtu_result *res = parsed_result;
2052
2053         if (res->value < RTE_ETHER_MIN_LEN) {
2054                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2055                 return;
2056         }
2057         port_mtu_set(res->port_id, res->value);
2058 }
2059
2060 cmdline_parse_token_string_t cmd_config_mtu_port =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2062                                  "port");
2063 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2065                                  "config");
2066 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2068                                  "mtu");
2069 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2070         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2071 cmdline_parse_token_num_t cmd_config_mtu_value =
2072         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2073
2074 cmdline_parse_inst_t cmd_config_mtu = {
2075         .f = cmd_config_mtu_parsed,
2076         .data = NULL,
2077         .help_str = "port config mtu <port_id> <value>",
2078         .tokens = {
2079                 (void *)&cmd_config_mtu_port,
2080                 (void *)&cmd_config_mtu_keyword,
2081                 (void *)&cmd_config_mtu_mtu,
2082                 (void *)&cmd_config_mtu_port_id,
2083                 (void *)&cmd_config_mtu_value,
2084                 NULL,
2085         },
2086 };
2087
2088 /* *** configure rx mode *** */
2089 struct cmd_config_rx_mode_flag {
2090         cmdline_fixed_string_t port;
2091         cmdline_fixed_string_t keyword;
2092         cmdline_fixed_string_t all;
2093         cmdline_fixed_string_t name;
2094         cmdline_fixed_string_t value;
2095 };
2096
2097 static void
2098 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2099                                 __rte_unused struct cmdline *cl,
2100                                 __rte_unused void *data)
2101 {
2102         struct cmd_config_rx_mode_flag *res = parsed_result;
2103
2104         if (!all_ports_stopped()) {
2105                 printf("Please stop all ports first\n");
2106                 return;
2107         }
2108
2109         if (!strcmp(res->name, "drop-en")) {
2110                 if (!strcmp(res->value, "on"))
2111                         rx_drop_en = 1;
2112                 else if (!strcmp(res->value, "off"))
2113                         rx_drop_en = 0;
2114                 else {
2115                         printf("Unknown parameter\n");
2116                         return;
2117                 }
2118         } else {
2119                 printf("Unknown parameter\n");
2120                 return;
2121         }
2122
2123         init_port_config();
2124
2125         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2126 }
2127
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2129         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2130 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2131         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2132                                                                 "config");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2137                                         "drop-en");
2138 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2140                                                         "on#off");
2141
2142 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2143         .f = cmd_config_rx_mode_flag_parsed,
2144         .data = NULL,
2145         .help_str = "port config all drop-en on|off",
2146         .tokens = {
2147                 (void *)&cmd_config_rx_mode_flag_port,
2148                 (void *)&cmd_config_rx_mode_flag_keyword,
2149                 (void *)&cmd_config_rx_mode_flag_all,
2150                 (void *)&cmd_config_rx_mode_flag_name,
2151                 (void *)&cmd_config_rx_mode_flag_value,
2152                 NULL,
2153         },
2154 };
2155
2156 /* *** configure rss *** */
2157 struct cmd_config_rss {
2158         cmdline_fixed_string_t port;
2159         cmdline_fixed_string_t keyword;
2160         cmdline_fixed_string_t all;
2161         cmdline_fixed_string_t name;
2162         cmdline_fixed_string_t value;
2163 };
2164
2165 static void
2166 cmd_config_rss_parsed(void *parsed_result,
2167                         __rte_unused struct cmdline *cl,
2168                         __rte_unused void *data)
2169 {
2170         struct cmd_config_rss *res = parsed_result;
2171         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2172         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2173         int use_default = 0;
2174         int all_updated = 1;
2175         int diag;
2176         uint16_t i;
2177         int ret;
2178
2179         if (!strcmp(res->value, "all"))
2180                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2181                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2182                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2183                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2184         else if (!strcmp(res->value, "eth"))
2185                 rss_conf.rss_hf = ETH_RSS_ETH;
2186         else if (!strcmp(res->value, "vlan"))
2187                 rss_conf.rss_hf = ETH_RSS_VLAN;
2188         else if (!strcmp(res->value, "ip"))
2189                 rss_conf.rss_hf = ETH_RSS_IP;
2190         else if (!strcmp(res->value, "udp"))
2191                 rss_conf.rss_hf = ETH_RSS_UDP;
2192         else if (!strcmp(res->value, "tcp"))
2193                 rss_conf.rss_hf = ETH_RSS_TCP;
2194         else if (!strcmp(res->value, "sctp"))
2195                 rss_conf.rss_hf = ETH_RSS_SCTP;
2196         else if (!strcmp(res->value, "ether"))
2197                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2198         else if (!strcmp(res->value, "port"))
2199                 rss_conf.rss_hf = ETH_RSS_PORT;
2200         else if (!strcmp(res->value, "vxlan"))
2201                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2202         else if (!strcmp(res->value, "geneve"))
2203                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2204         else if (!strcmp(res->value, "nvgre"))
2205                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2206         else if (!strcmp(res->value, "l3-pre32"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2208         else if (!strcmp(res->value, "l3-pre40"))
2209                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2210         else if (!strcmp(res->value, "l3-pre48"))
2211                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2212         else if (!strcmp(res->value, "l3-pre56"))
2213                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2214         else if (!strcmp(res->value, "l3-pre64"))
2215                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2216         else if (!strcmp(res->value, "l3-pre96"))
2217                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2218         else if (!strcmp(res->value, "l3-src-only"))
2219                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2220         else if (!strcmp(res->value, "l3-dst-only"))
2221                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2222         else if (!strcmp(res->value, "l4-src-only"))
2223                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2224         else if (!strcmp(res->value, "l4-dst-only"))
2225                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2226         else if (!strcmp(res->value, "l2-src-only"))
2227                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2228         else if (!strcmp(res->value, "l2-dst-only"))
2229                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2230         else if (!strcmp(res->value, "l2tpv3"))
2231                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2232         else if (!strcmp(res->value, "esp"))
2233                 rss_conf.rss_hf = ETH_RSS_ESP;
2234         else if (!strcmp(res->value, "ah"))
2235                 rss_conf.rss_hf = ETH_RSS_AH;
2236         else if (!strcmp(res->value, "pfcp"))
2237                 rss_conf.rss_hf = ETH_RSS_PFCP;
2238         else if (!strcmp(res->value, "pppoe"))
2239                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2240         else if (!strcmp(res->value, "gtpu"))
2241                 rss_conf.rss_hf = ETH_RSS_GTPU;
2242         else if (!strcmp(res->value, "none"))
2243                 rss_conf.rss_hf = 0;
2244         else if (!strcmp(res->value, "level-default")) {
2245                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2246                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2247         } else if (!strcmp(res->value, "level-outer")) {
2248                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2249                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2250         } else if (!strcmp(res->value, "level-inner")) {
2251                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2252                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2253         } else if (!strcmp(res->value, "default"))
2254                 use_default = 1;
2255         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2256                                                 atoi(res->value) < 64)
2257                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2258         else {
2259                 printf("Unknown parameter\n");
2260                 return;
2261         }
2262         rss_conf.rss_key = NULL;
2263         /* Update global configuration for RSS types. */
2264         RTE_ETH_FOREACH_DEV(i) {
2265                 struct rte_eth_rss_conf local_rss_conf;
2266
2267                 ret = eth_dev_info_get_print_err(i, &dev_info);
2268                 if (ret != 0)
2269                         return;
2270
2271                 if (use_default)
2272                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2273
2274                 local_rss_conf = rss_conf;
2275                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2276                         dev_info.flow_type_rss_offloads;
2277                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2278                         printf("Port %u modified RSS hash function based on hardware support,"
2279                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2280                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2281                 }
2282                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2283                 if (diag < 0) {
2284                         all_updated = 0;
2285                         printf("Configuration of RSS hash at ethernet port %d "
2286                                 "failed with error (%d): %s.\n",
2287                                 i, -diag, strerror(-diag));
2288                 }
2289         }
2290         if (all_updated && !use_default) {
2291                 rss_hf = rss_conf.rss_hf;
2292                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2293         }
2294 }
2295
2296 cmdline_parse_token_string_t cmd_config_rss_port =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2298 cmdline_parse_token_string_t cmd_config_rss_keyword =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2300 cmdline_parse_token_string_t cmd_config_rss_all =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2302 cmdline_parse_token_string_t cmd_config_rss_name =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2304 cmdline_parse_token_string_t cmd_config_rss_value =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2306
2307 cmdline_parse_inst_t cmd_config_rss = {
2308         .f = cmd_config_rss_parsed,
2309         .data = NULL,
2310         .help_str = "port config all rss "
2311                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2312                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2313                 "level-outer|level-inner|<flowtype_id>",
2314         .tokens = {
2315                 (void *)&cmd_config_rss_port,
2316                 (void *)&cmd_config_rss_keyword,
2317                 (void *)&cmd_config_rss_all,
2318                 (void *)&cmd_config_rss_name,
2319                 (void *)&cmd_config_rss_value,
2320                 NULL,
2321         },
2322 };
2323
2324 /* *** configure rss hash key *** */
2325 struct cmd_config_rss_hash_key {
2326         cmdline_fixed_string_t port;
2327         cmdline_fixed_string_t config;
2328         portid_t port_id;
2329         cmdline_fixed_string_t rss_hash_key;
2330         cmdline_fixed_string_t rss_type;
2331         cmdline_fixed_string_t key;
2332 };
2333
2334 static uint8_t
2335 hexa_digit_to_value(char hexa_digit)
2336 {
2337         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2338                 return (uint8_t) (hexa_digit - '0');
2339         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2340                 return (uint8_t) ((hexa_digit - 'a') + 10);
2341         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2342                 return (uint8_t) ((hexa_digit - 'A') + 10);
2343         /* Invalid hexa digit */
2344         return 0xFF;
2345 }
2346
2347 static uint8_t
2348 parse_and_check_key_hexa_digit(char *key, int idx)
2349 {
2350         uint8_t hexa_v;
2351
2352         hexa_v = hexa_digit_to_value(key[idx]);
2353         if (hexa_v == 0xFF)
2354                 printf("invalid key: character %c at position %d is not a "
2355                        "valid hexa digit\n", key[idx], idx);
2356         return hexa_v;
2357 }
2358
2359 static void
2360 cmd_config_rss_hash_key_parsed(void *parsed_result,
2361                                __rte_unused struct cmdline *cl,
2362                                __rte_unused void *data)
2363 {
2364         struct cmd_config_rss_hash_key *res = parsed_result;
2365         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2366         uint8_t xdgt0;
2367         uint8_t xdgt1;
2368         int i;
2369         struct rte_eth_dev_info dev_info;
2370         uint8_t hash_key_size;
2371         uint32_t key_len;
2372         int ret;
2373
2374         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2375         if (ret != 0)
2376                 return;
2377
2378         if (dev_info.hash_key_size > 0 &&
2379                         dev_info.hash_key_size <= sizeof(hash_key))
2380                 hash_key_size = dev_info.hash_key_size;
2381         else {
2382                 printf("dev_info did not provide a valid hash key size\n");
2383                 return;
2384         }
2385         /* Check the length of the RSS hash key */
2386         key_len = strlen(res->key);
2387         if (key_len != (hash_key_size * 2)) {
2388                 printf("key length: %d invalid - key must be a string of %d"
2389                            " hexa-decimal numbers\n",
2390                            (int) key_len, hash_key_size * 2);
2391                 return;
2392         }
2393         /* Translate RSS hash key into binary representation */
2394         for (i = 0; i < hash_key_size; i++) {
2395                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2396                 if (xdgt0 == 0xFF)
2397                         return;
2398                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2399                 if (xdgt1 == 0xFF)
2400                         return;
2401                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2402         }
2403         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2404                         hash_key_size);
2405 }
2406
2407 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2408         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2409 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2411                                  "config");
2412 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2413         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2414 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2415         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2416                                  rss_hash_key, "rss-hash-key");
2417 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2418         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2419                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2420                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2421                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2422                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2423                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2424                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2425                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2426 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2427         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2428
2429 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2430         .f = cmd_config_rss_hash_key_parsed,
2431         .data = NULL,
2432         .help_str = "port config <port_id> rss-hash-key "
2433                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2434                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2435                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2436                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2437                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2438                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2439                 "<string of hex digits (variable length, NIC dependent)>",
2440         .tokens = {
2441                 (void *)&cmd_config_rss_hash_key_port,
2442                 (void *)&cmd_config_rss_hash_key_config,
2443                 (void *)&cmd_config_rss_hash_key_port_id,
2444                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2445                 (void *)&cmd_config_rss_hash_key_rss_type,
2446                 (void *)&cmd_config_rss_hash_key_value,
2447                 NULL,
2448         },
2449 };
2450
2451 /* *** configure port rxq/txq ring size *** */
2452 struct cmd_config_rxtx_ring_size {
2453         cmdline_fixed_string_t port;
2454         cmdline_fixed_string_t config;
2455         portid_t portid;
2456         cmdline_fixed_string_t rxtxq;
2457         uint16_t qid;
2458         cmdline_fixed_string_t rsize;
2459         uint16_t size;
2460 };
2461
2462 static void
2463 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2464                                  __rte_unused struct cmdline *cl,
2465                                  __rte_unused void *data)
2466 {
2467         struct cmd_config_rxtx_ring_size *res = parsed_result;
2468         struct rte_port *port;
2469         uint8_t isrx;
2470
2471         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2472                 return;
2473
2474         if (res->portid == (portid_t)RTE_PORT_ALL) {
2475                 printf("Invalid port id\n");
2476                 return;
2477         }
2478
2479         port = &ports[res->portid];
2480
2481         if (!strcmp(res->rxtxq, "rxq"))
2482                 isrx = 1;
2483         else if (!strcmp(res->rxtxq, "txq"))
2484                 isrx = 0;
2485         else {
2486                 printf("Unknown parameter\n");
2487                 return;
2488         }
2489
2490         if (isrx && rx_queue_id_is_invalid(res->qid))
2491                 return;
2492         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2493                 return;
2494
2495         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2496                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2497                        rx_free_thresh);
2498                 return;
2499         }
2500
2501         if (isrx)
2502                 port->nb_rx_desc[res->qid] = res->size;
2503         else
2504                 port->nb_tx_desc[res->qid] = res->size;
2505
2506         cmd_reconfig_device_queue(res->portid, 0, 1);
2507 }
2508
2509 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2510         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                                  port, "port");
2512 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2513         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2514                                  config, "config");
2515 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2516         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2517                                  portid, UINT16);
2518 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2519         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2520                                  rxtxq, "rxq#txq");
2521 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2522         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2523                               qid, UINT16);
2524 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2525         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2526                                  rsize, "ring_size");
2527 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2528         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2529                               size, UINT16);
2530
2531 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2532         .f = cmd_config_rxtx_ring_size_parsed,
2533         .data = NULL,
2534         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2535         .tokens = {
2536                 (void *)&cmd_config_rxtx_ring_size_port,
2537                 (void *)&cmd_config_rxtx_ring_size_config,
2538                 (void *)&cmd_config_rxtx_ring_size_portid,
2539                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2540                 (void *)&cmd_config_rxtx_ring_size_qid,
2541                 (void *)&cmd_config_rxtx_ring_size_rsize,
2542                 (void *)&cmd_config_rxtx_ring_size_size,
2543                 NULL,
2544         },
2545 };
2546
2547 /* *** configure port rxq/txq start/stop *** */
2548 struct cmd_config_rxtx_queue {
2549         cmdline_fixed_string_t port;
2550         portid_t portid;
2551         cmdline_fixed_string_t rxtxq;
2552         uint16_t qid;
2553         cmdline_fixed_string_t opname;
2554 };
2555
2556 static void
2557 cmd_config_rxtx_queue_parsed(void *parsed_result,
2558                         __rte_unused struct cmdline *cl,
2559                         __rte_unused void *data)
2560 {
2561         struct cmd_config_rxtx_queue *res = parsed_result;
2562         uint8_t isrx;
2563         uint8_t isstart;
2564         int ret = 0;
2565
2566         if (test_done == 0) {
2567                 printf("Please stop forwarding first\n");
2568                 return;
2569         }
2570
2571         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2572                 return;
2573
2574         if (port_is_started(res->portid) != 1) {
2575                 printf("Please start port %u first\n", res->portid);
2576                 return;
2577         }
2578
2579         if (!strcmp(res->rxtxq, "rxq"))
2580                 isrx = 1;
2581         else if (!strcmp(res->rxtxq, "txq"))
2582                 isrx = 0;
2583         else {
2584                 printf("Unknown parameter\n");
2585                 return;
2586         }
2587
2588         if (isrx && rx_queue_id_is_invalid(res->qid))
2589                 return;
2590         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2591                 return;
2592
2593         if (!strcmp(res->opname, "start"))
2594                 isstart = 1;
2595         else if (!strcmp(res->opname, "stop"))
2596                 isstart = 0;
2597         else {
2598                 printf("Unknown parameter\n");
2599                 return;
2600         }
2601
2602         if (isstart && isrx)
2603                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2604         else if (!isstart && isrx)
2605                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2606         else if (isstart && !isrx)
2607                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2608         else
2609                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2610
2611         if (ret == -ENOTSUP)
2612                 printf("Function not supported in PMD driver\n");
2613 }
2614
2615 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2616         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2617 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2618         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2619 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2621 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2622         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2623 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2625                                                 "start#stop");
2626
2627 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2628         .f = cmd_config_rxtx_queue_parsed,
2629         .data = NULL,
2630         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2631         .tokens = {
2632                 (void *)&cmd_config_rxtx_queue_port,
2633                 (void *)&cmd_config_rxtx_queue_portid,
2634                 (void *)&cmd_config_rxtx_queue_rxtxq,
2635                 (void *)&cmd_config_rxtx_queue_qid,
2636                 (void *)&cmd_config_rxtx_queue_opname,
2637                 NULL,
2638         },
2639 };
2640
2641 /* *** configure port rxq/txq deferred start on/off *** */
2642 struct cmd_config_deferred_start_rxtx_queue {
2643         cmdline_fixed_string_t port;
2644         portid_t port_id;
2645         cmdline_fixed_string_t rxtxq;
2646         uint16_t qid;
2647         cmdline_fixed_string_t opname;
2648         cmdline_fixed_string_t state;
2649 };
2650
2651 static void
2652 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2653                         __rte_unused struct cmdline *cl,
2654                         __rte_unused void *data)
2655 {
2656         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2657         struct rte_port *port;
2658         uint8_t isrx;
2659         uint8_t ison;
2660         uint8_t needreconfig = 0;
2661
2662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2663                 return;
2664
2665         if (port_is_started(res->port_id) != 0) {
2666                 printf("Please stop port %u first\n", res->port_id);
2667                 return;
2668         }
2669
2670         port = &ports[res->port_id];
2671
2672         isrx = !strcmp(res->rxtxq, "rxq");
2673
2674         if (isrx && rx_queue_id_is_invalid(res->qid))
2675                 return;
2676         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2677                 return;
2678
2679         ison = !strcmp(res->state, "on");
2680
2681         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2682                 port->rx_conf[res->qid].rx_deferred_start = ison;
2683                 needreconfig = 1;
2684         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2685                 port->tx_conf[res->qid].tx_deferred_start = ison;
2686                 needreconfig = 1;
2687         }
2688
2689         if (needreconfig)
2690                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2691 }
2692
2693 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2695                                                 port, "port");
2696 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2697         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2698                                                 port_id, UINT16);
2699 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2700         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2701                                                 rxtxq, "rxq#txq");
2702 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2703         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2704                                                 qid, UINT16);
2705 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2706         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2707                                                 opname, "deferred_start");
2708 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2709         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2710                                                 state, "on#off");
2711
2712 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2713         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2714         .data = NULL,
2715         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2716         .tokens = {
2717                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2718                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2719                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2720                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2721                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2722                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2723                 NULL,
2724         },
2725 };
2726
2727 /* *** configure port rxq/txq setup *** */
2728 struct cmd_setup_rxtx_queue {
2729         cmdline_fixed_string_t port;
2730         portid_t portid;
2731         cmdline_fixed_string_t rxtxq;
2732         uint16_t qid;
2733         cmdline_fixed_string_t setup;
2734 };
2735
2736 /* Common CLI fields for queue setup */
2737 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2738         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2739 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2740         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2741 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2742         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2743 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2744         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2745 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2746         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2747
2748 static void
2749 cmd_setup_rxtx_queue_parsed(
2750         void *parsed_result,
2751         __rte_unused struct cmdline *cl,
2752         __rte_unused void *data)
2753 {
2754         struct cmd_setup_rxtx_queue *res = parsed_result;
2755         struct rte_port *port;
2756         struct rte_mempool *mp;
2757         unsigned int socket_id;
2758         uint8_t isrx = 0;
2759         int ret;
2760
2761         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2762                 return;
2763
2764         if (res->portid == (portid_t)RTE_PORT_ALL) {
2765                 printf("Invalid port id\n");
2766                 return;
2767         }
2768
2769         if (!strcmp(res->rxtxq, "rxq"))
2770                 isrx = 1;
2771         else if (!strcmp(res->rxtxq, "txq"))
2772                 isrx = 0;
2773         else {
2774                 printf("Unknown parameter\n");
2775                 return;
2776         }
2777
2778         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2779                 printf("Invalid rx queue\n");
2780                 return;
2781         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2782                 printf("Invalid tx queue\n");
2783                 return;
2784         }
2785
2786         port = &ports[res->portid];
2787         if (isrx) {
2788                 socket_id = rxring_numa[res->portid];
2789                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2790                         socket_id = port->socket_id;
2791
2792                 mp = mbuf_pool_find(socket_id, 0);
2793                 if (mp == NULL) {
2794                         printf("Failed to setup RX queue: "
2795                                 "No mempool allocation"
2796                                 " on the socket %d\n",
2797                                 rxring_numa[res->portid]);
2798                         return;
2799                 }
2800                 ret = rx_queue_setup(res->portid,
2801                                      res->qid,
2802                                      port->nb_rx_desc[res->qid],
2803                                      socket_id,
2804                                      &port->rx_conf[res->qid],
2805                                      mp);
2806                 if (ret)
2807                         printf("Failed to setup RX queue\n");
2808         } else {
2809                 socket_id = txring_numa[res->portid];
2810                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2811                         socket_id = port->socket_id;
2812
2813                 ret = rte_eth_tx_queue_setup(res->portid,
2814                                              res->qid,
2815                                              port->nb_tx_desc[res->qid],
2816                                              socket_id,
2817                                              &port->tx_conf[res->qid]);
2818                 if (ret)
2819                         printf("Failed to setup TX queue\n");
2820         }
2821 }
2822
2823 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2824         .f = cmd_setup_rxtx_queue_parsed,
2825         .data = NULL,
2826         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2827         .tokens = {
2828                 (void *)&cmd_setup_rxtx_queue_port,
2829                 (void *)&cmd_setup_rxtx_queue_portid,
2830                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2831                 (void *)&cmd_setup_rxtx_queue_qid,
2832                 (void *)&cmd_setup_rxtx_queue_setup,
2833                 NULL,
2834         },
2835 };
2836
2837
2838 /* *** Configure RSS RETA *** */
2839 struct cmd_config_rss_reta {
2840         cmdline_fixed_string_t port;
2841         cmdline_fixed_string_t keyword;
2842         portid_t port_id;
2843         cmdline_fixed_string_t name;
2844         cmdline_fixed_string_t list_name;
2845         cmdline_fixed_string_t list_of_items;
2846 };
2847
2848 static int
2849 parse_reta_config(const char *str,
2850                   struct rte_eth_rss_reta_entry64 *reta_conf,
2851                   uint16_t nb_entries)
2852 {
2853         int i;
2854         unsigned size;
2855         uint16_t hash_index, idx, shift;
2856         uint16_t nb_queue;
2857         char s[256];
2858         const char *p, *p0 = str;
2859         char *end;
2860         enum fieldnames {
2861                 FLD_HASH_INDEX = 0,
2862                 FLD_QUEUE,
2863                 _NUM_FLD
2864         };
2865         unsigned long int_fld[_NUM_FLD];
2866         char *str_fld[_NUM_FLD];
2867
2868         while ((p = strchr(p0,'(')) != NULL) {
2869                 ++p;
2870                 if((p0 = strchr(p,')')) == NULL)
2871                         return -1;
2872
2873                 size = p0 - p;
2874                 if(size >= sizeof(s))
2875                         return -1;
2876
2877                 snprintf(s, sizeof(s), "%.*s", size, p);
2878                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2879                         return -1;
2880                 for (i = 0; i < _NUM_FLD; i++) {
2881                         errno = 0;
2882                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2883                         if (errno != 0 || end == str_fld[i] ||
2884                                         int_fld[i] > 65535)
2885                                 return -1;
2886                 }
2887
2888                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2889                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2890
2891                 if (hash_index >= nb_entries) {
2892                         printf("Invalid RETA hash index=%d\n", hash_index);
2893                         return -1;
2894                 }
2895
2896                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2897                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2898                 reta_conf[idx].mask |= (1ULL << shift);
2899                 reta_conf[idx].reta[shift] = nb_queue;
2900         }
2901
2902         return 0;
2903 }
2904
2905 static void
2906 cmd_set_rss_reta_parsed(void *parsed_result,
2907                         __rte_unused struct cmdline *cl,
2908                         __rte_unused void *data)
2909 {
2910         int ret;
2911         struct rte_eth_dev_info dev_info;
2912         struct rte_eth_rss_reta_entry64 reta_conf[8];
2913         struct cmd_config_rss_reta *res = parsed_result;
2914
2915         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2916         if (ret != 0)
2917                 return;
2918
2919         if (dev_info.reta_size == 0) {
2920                 printf("Redirection table size is 0 which is "
2921                                         "invalid for RSS\n");
2922                 return;
2923         } else
2924                 printf("The reta size of port %d is %u\n",
2925                         res->port_id, dev_info.reta_size);
2926         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2927                 printf("Currently do not support more than %u entries of "
2928                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2929                 return;
2930         }
2931
2932         memset(reta_conf, 0, sizeof(reta_conf));
2933         if (!strcmp(res->list_name, "reta")) {
2934                 if (parse_reta_config(res->list_of_items, reta_conf,
2935                                                 dev_info.reta_size)) {
2936                         printf("Invalid RSS Redirection Table "
2937                                         "config entered\n");
2938                         return;
2939                 }
2940                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2941                                 reta_conf, dev_info.reta_size);
2942                 if (ret != 0)
2943                         printf("Bad redirection table parameter, "
2944                                         "return code = %d \n", ret);
2945         }
2946 }
2947
2948 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2949         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2950 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2951         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2952 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2953         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2954 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2956 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2957         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2958 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2960                                  NULL);
2961 cmdline_parse_inst_t cmd_config_rss_reta = {
2962         .f = cmd_set_rss_reta_parsed,
2963         .data = NULL,
2964         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2965         .tokens = {
2966                 (void *)&cmd_config_rss_reta_port,
2967                 (void *)&cmd_config_rss_reta_keyword,
2968                 (void *)&cmd_config_rss_reta_port_id,
2969                 (void *)&cmd_config_rss_reta_name,
2970                 (void *)&cmd_config_rss_reta_list_name,
2971                 (void *)&cmd_config_rss_reta_list_of_items,
2972                 NULL,
2973         },
2974 };
2975
2976 /* *** SHOW PORT RETA INFO *** */
2977 struct cmd_showport_reta {
2978         cmdline_fixed_string_t show;
2979         cmdline_fixed_string_t port;
2980         portid_t port_id;
2981         cmdline_fixed_string_t rss;
2982         cmdline_fixed_string_t reta;
2983         uint16_t size;
2984         cmdline_fixed_string_t list_of_items;
2985 };
2986
2987 static int
2988 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2989                            uint16_t nb_entries,
2990                            char *str)
2991 {
2992         uint32_t size;
2993         const char *p, *p0 = str;
2994         char s[256];
2995         char *end;
2996         char *str_fld[8];
2997         uint16_t i;
2998         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2999                         RTE_RETA_GROUP_SIZE;
3000         int ret;
3001
3002         p = strchr(p0, '(');
3003         if (p == NULL)
3004                 return -1;
3005         p++;
3006         p0 = strchr(p, ')');
3007         if (p0 == NULL)
3008                 return -1;
3009         size = p0 - p;
3010         if (size >= sizeof(s)) {
3011                 printf("The string size exceeds the internal buffer size\n");
3012                 return -1;
3013         }
3014         snprintf(s, sizeof(s), "%.*s", size, p);
3015         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3016         if (ret <= 0 || ret != num) {
3017                 printf("The bits of masks do not match the number of "
3018                                         "reta entries: %u\n", num);
3019                 return -1;
3020         }
3021         for (i = 0; i < ret; i++)
3022                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3023
3024         return 0;
3025 }
3026
3027 static void
3028 cmd_showport_reta_parsed(void *parsed_result,
3029                          __rte_unused struct cmdline *cl,
3030                          __rte_unused void *data)
3031 {
3032         struct cmd_showport_reta *res = parsed_result;
3033         struct rte_eth_rss_reta_entry64 reta_conf[8];
3034         struct rte_eth_dev_info dev_info;
3035         uint16_t max_reta_size;
3036         int ret;
3037
3038         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3039         if (ret != 0)
3040                 return;
3041
3042         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3043         if (res->size == 0 || res->size > max_reta_size) {
3044                 printf("Invalid redirection table size: %u (1-%u)\n",
3045                         res->size, max_reta_size);
3046                 return;
3047         }
3048
3049         memset(reta_conf, 0, sizeof(reta_conf));
3050         if (showport_parse_reta_config(reta_conf, res->size,
3051                                 res->list_of_items) < 0) {
3052                 printf("Invalid string: %s for reta masks\n",
3053                                         res->list_of_items);
3054                 return;
3055         }
3056         port_rss_reta_info(res->port_id, reta_conf, res->size);
3057 }
3058
3059 cmdline_parse_token_string_t cmd_showport_reta_show =
3060         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3061 cmdline_parse_token_string_t cmd_showport_reta_port =
3062         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3063 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3064         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3065 cmdline_parse_token_string_t cmd_showport_reta_rss =
3066         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3067 cmdline_parse_token_string_t cmd_showport_reta_reta =
3068         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3069 cmdline_parse_token_num_t cmd_showport_reta_size =
3070         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3071 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3072         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3073                                         list_of_items, NULL);
3074
3075 cmdline_parse_inst_t cmd_showport_reta = {
3076         .f = cmd_showport_reta_parsed,
3077         .data = NULL,
3078         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3079         .tokens = {
3080                 (void *)&cmd_showport_reta_show,
3081                 (void *)&cmd_showport_reta_port,
3082                 (void *)&cmd_showport_reta_port_id,
3083                 (void *)&cmd_showport_reta_rss,
3084                 (void *)&cmd_showport_reta_reta,
3085                 (void *)&cmd_showport_reta_size,
3086                 (void *)&cmd_showport_reta_list_of_items,
3087                 NULL,
3088         },
3089 };
3090
3091 /* *** Show RSS hash configuration *** */
3092 struct cmd_showport_rss_hash {
3093         cmdline_fixed_string_t show;
3094         cmdline_fixed_string_t port;
3095         portid_t port_id;
3096         cmdline_fixed_string_t rss_hash;
3097         cmdline_fixed_string_t rss_type;
3098         cmdline_fixed_string_t key; /* optional argument */
3099 };
3100
3101 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3102                                 __rte_unused struct cmdline *cl,
3103                                 void *show_rss_key)
3104 {
3105         struct cmd_showport_rss_hash *res = parsed_result;
3106
3107         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3108 }
3109
3110 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3111         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3112 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3113         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3114 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3115         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3116 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3117         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3118                                  "rss-hash");
3119 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3120         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3121
3122 cmdline_parse_inst_t cmd_showport_rss_hash = {
3123         .f = cmd_showport_rss_hash_parsed,
3124         .data = NULL,
3125         .help_str = "show port <port_id> rss-hash",
3126         .tokens = {
3127                 (void *)&cmd_showport_rss_hash_show,
3128                 (void *)&cmd_showport_rss_hash_port,
3129                 (void *)&cmd_showport_rss_hash_port_id,
3130                 (void *)&cmd_showport_rss_hash_rss_hash,
3131                 NULL,
3132         },
3133 };
3134
3135 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3136         .f = cmd_showport_rss_hash_parsed,
3137         .data = (void *)1,
3138         .help_str = "show port <port_id> rss-hash key",
3139         .tokens = {
3140                 (void *)&cmd_showport_rss_hash_show,
3141                 (void *)&cmd_showport_rss_hash_port,
3142                 (void *)&cmd_showport_rss_hash_port_id,
3143                 (void *)&cmd_showport_rss_hash_rss_hash,
3144                 (void *)&cmd_showport_rss_hash_rss_key,
3145                 NULL,
3146         },
3147 };
3148
3149 /* *** Configure DCB *** */
3150 struct cmd_config_dcb {
3151         cmdline_fixed_string_t port;
3152         cmdline_fixed_string_t config;
3153         portid_t port_id;
3154         cmdline_fixed_string_t dcb;
3155         cmdline_fixed_string_t vt;
3156         cmdline_fixed_string_t vt_en;
3157         uint8_t num_tcs;
3158         cmdline_fixed_string_t pfc;
3159         cmdline_fixed_string_t pfc_en;
3160 };
3161
3162 static void
3163 cmd_config_dcb_parsed(void *parsed_result,
3164                         __rte_unused struct cmdline *cl,
3165                         __rte_unused void *data)
3166 {
3167         struct cmd_config_dcb *res = parsed_result;
3168         portid_t port_id = res->port_id;
3169         struct rte_port *port;
3170         uint8_t pfc_en;
3171         int ret;
3172
3173         port = &ports[port_id];
3174         /** Check if the port is not started **/
3175         if (port->port_status != RTE_PORT_STOPPED) {
3176                 printf("Please stop port %d first\n", port_id);
3177                 return;
3178         }
3179
3180         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3181                 printf("The invalid number of traffic class,"
3182                         " only 4 or 8 allowed.\n");
3183                 return;
3184         }
3185
3186         if (nb_fwd_lcores < res->num_tcs) {
3187                 printf("nb_cores shouldn't be less than number of TCs.\n");
3188                 return;
3189         }
3190         if (!strncmp(res->pfc_en, "on", 2))
3191                 pfc_en = 1;
3192         else
3193                 pfc_en = 0;
3194
3195         /* DCB in VT mode */
3196         if (!strncmp(res->vt_en, "on", 2))
3197                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3198                                 (enum rte_eth_nb_tcs)res->num_tcs,
3199                                 pfc_en);
3200         else
3201                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3202                                 (enum rte_eth_nb_tcs)res->num_tcs,
3203                                 pfc_en);
3204
3205
3206         if (ret != 0) {
3207                 printf("Cannot initialize network ports.\n");
3208                 return;
3209         }
3210
3211         cmd_reconfig_device_queue(port_id, 1, 1);
3212 }
3213
3214 cmdline_parse_token_string_t cmd_config_dcb_port =
3215         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3216 cmdline_parse_token_string_t cmd_config_dcb_config =
3217         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3218 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3219         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3220 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3221         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3222 cmdline_parse_token_string_t cmd_config_dcb_vt =
3223         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3224 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3225         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3226 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3227         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3228 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3229         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3230 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3231         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3232
3233 cmdline_parse_inst_t cmd_config_dcb = {
3234         .f = cmd_config_dcb_parsed,
3235         .data = NULL,
3236         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3237         .tokens = {
3238                 (void *)&cmd_config_dcb_port,
3239                 (void *)&cmd_config_dcb_config,
3240                 (void *)&cmd_config_dcb_port_id,
3241                 (void *)&cmd_config_dcb_dcb,
3242                 (void *)&cmd_config_dcb_vt,
3243                 (void *)&cmd_config_dcb_vt_en,
3244                 (void *)&cmd_config_dcb_num_tcs,
3245                 (void *)&cmd_config_dcb_pfc,
3246                 (void *)&cmd_config_dcb_pfc_en,
3247                 NULL,
3248         },
3249 };
3250
3251 /* *** configure number of packets per burst *** */
3252 struct cmd_config_burst {
3253         cmdline_fixed_string_t port;
3254         cmdline_fixed_string_t keyword;
3255         cmdline_fixed_string_t all;
3256         cmdline_fixed_string_t name;
3257         uint16_t value;
3258 };
3259
3260 static void
3261 cmd_config_burst_parsed(void *parsed_result,
3262                         __rte_unused struct cmdline *cl,
3263                         __rte_unused void *data)
3264 {
3265         struct cmd_config_burst *res = parsed_result;
3266         struct rte_eth_dev_info dev_info;
3267         uint16_t rec_nb_pkts;
3268         int ret;
3269
3270         if (!all_ports_stopped()) {
3271                 printf("Please stop all ports first\n");
3272                 return;
3273         }
3274
3275         if (!strcmp(res->name, "burst")) {
3276                 if (res->value == 0) {
3277                         /* If user gives a value of zero, query the PMD for
3278                          * its recommended Rx burst size. Testpmd uses a single
3279                          * size for all ports, so assume all ports are the same
3280                          * NIC model and use the values from Port 0.
3281                          */
3282                         ret = eth_dev_info_get_print_err(0, &dev_info);
3283                         if (ret != 0)
3284                                 return;
3285
3286                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3287
3288                         if (rec_nb_pkts == 0) {
3289                                 printf("PMD does not recommend a burst size.\n"
3290                                         "User provided value must be between"
3291                                         " 1 and %d\n", MAX_PKT_BURST);
3292                                 return;
3293                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3294                                 printf("PMD recommended burst size of %d"
3295                                         " exceeds maximum value of %d\n",
3296                                         rec_nb_pkts, MAX_PKT_BURST);
3297                                 return;
3298                         }
3299                         printf("Using PMD-provided burst value of %d\n",
3300                                 rec_nb_pkts);
3301                         nb_pkt_per_burst = rec_nb_pkts;
3302                 } else if (res->value > MAX_PKT_BURST) {
3303                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3304                         return;
3305                 } else
3306                         nb_pkt_per_burst = res->value;
3307         } else {
3308                 printf("Unknown parameter\n");
3309                 return;
3310         }
3311
3312         init_port_config();
3313
3314         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3315 }
3316
3317 cmdline_parse_token_string_t cmd_config_burst_port =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3319 cmdline_parse_token_string_t cmd_config_burst_keyword =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3321 cmdline_parse_token_string_t cmd_config_burst_all =
3322         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3323 cmdline_parse_token_string_t cmd_config_burst_name =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3325 cmdline_parse_token_num_t cmd_config_burst_value =
3326         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3327
3328 cmdline_parse_inst_t cmd_config_burst = {
3329         .f = cmd_config_burst_parsed,
3330         .data = NULL,
3331         .help_str = "port config all burst <value>",
3332         .tokens = {
3333                 (void *)&cmd_config_burst_port,
3334                 (void *)&cmd_config_burst_keyword,
3335                 (void *)&cmd_config_burst_all,
3336                 (void *)&cmd_config_burst_name,
3337                 (void *)&cmd_config_burst_value,
3338                 NULL,
3339         },
3340 };
3341
3342 /* *** configure rx/tx queues *** */
3343 struct cmd_config_thresh {
3344         cmdline_fixed_string_t port;
3345         cmdline_fixed_string_t keyword;
3346         cmdline_fixed_string_t all;
3347         cmdline_fixed_string_t name;
3348         uint8_t value;
3349 };
3350
3351 static void
3352 cmd_config_thresh_parsed(void *parsed_result,
3353                         __rte_unused struct cmdline *cl,
3354                         __rte_unused void *data)
3355 {
3356         struct cmd_config_thresh *res = parsed_result;
3357
3358         if (!all_ports_stopped()) {
3359                 printf("Please stop all ports first\n");
3360                 return;
3361         }
3362
3363         if (!strcmp(res->name, "txpt"))
3364                 tx_pthresh = res->value;
3365         else if(!strcmp(res->name, "txht"))
3366                 tx_hthresh = res->value;
3367         else if(!strcmp(res->name, "txwt"))
3368                 tx_wthresh = res->value;
3369         else if(!strcmp(res->name, "rxpt"))
3370                 rx_pthresh = res->value;
3371         else if(!strcmp(res->name, "rxht"))
3372                 rx_hthresh = res->value;
3373         else if(!strcmp(res->name, "rxwt"))
3374                 rx_wthresh = res->value;
3375         else {
3376                 printf("Unknown parameter\n");
3377                 return;
3378         }
3379
3380         init_port_config();
3381
3382         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3383 }
3384
3385 cmdline_parse_token_string_t cmd_config_thresh_port =
3386         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3387 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3388         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3389 cmdline_parse_token_string_t cmd_config_thresh_all =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3391 cmdline_parse_token_string_t cmd_config_thresh_name =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3393                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3394 cmdline_parse_token_num_t cmd_config_thresh_value =
3395         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3396
3397 cmdline_parse_inst_t cmd_config_thresh = {
3398         .f = cmd_config_thresh_parsed,
3399         .data = NULL,
3400         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3401         .tokens = {
3402                 (void *)&cmd_config_thresh_port,
3403                 (void *)&cmd_config_thresh_keyword,
3404                 (void *)&cmd_config_thresh_all,
3405                 (void *)&cmd_config_thresh_name,
3406                 (void *)&cmd_config_thresh_value,
3407                 NULL,
3408         },
3409 };
3410
3411 /* *** configure free/rs threshold *** */
3412 struct cmd_config_threshold {
3413         cmdline_fixed_string_t port;
3414         cmdline_fixed_string_t keyword;
3415         cmdline_fixed_string_t all;
3416         cmdline_fixed_string_t name;
3417         uint16_t value;
3418 };
3419
3420 static void
3421 cmd_config_threshold_parsed(void *parsed_result,
3422                         __rte_unused struct cmdline *cl,
3423                         __rte_unused void *data)
3424 {
3425         struct cmd_config_threshold *res = parsed_result;
3426
3427         if (!all_ports_stopped()) {
3428                 printf("Please stop all ports first\n");
3429                 return;
3430         }
3431
3432         if (!strcmp(res->name, "txfreet"))
3433                 tx_free_thresh = res->value;
3434         else if (!strcmp(res->name, "txrst"))
3435                 tx_rs_thresh = res->value;
3436         else if (!strcmp(res->name, "rxfreet"))
3437                 rx_free_thresh = res->value;
3438         else {
3439                 printf("Unknown parameter\n");
3440                 return;
3441         }
3442
3443         init_port_config();
3444
3445         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3446 }
3447
3448 cmdline_parse_token_string_t cmd_config_threshold_port =
3449         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3450 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3451         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3452                                                                 "config");
3453 cmdline_parse_token_string_t cmd_config_threshold_all =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3455 cmdline_parse_token_string_t cmd_config_threshold_name =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3457                                                 "txfreet#txrst#rxfreet");
3458 cmdline_parse_token_num_t cmd_config_threshold_value =
3459         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3460
3461 cmdline_parse_inst_t cmd_config_threshold = {
3462         .f = cmd_config_threshold_parsed,
3463         .data = NULL,
3464         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3465         .tokens = {
3466                 (void *)&cmd_config_threshold_port,
3467                 (void *)&cmd_config_threshold_keyword,
3468                 (void *)&cmd_config_threshold_all,
3469                 (void *)&cmd_config_threshold_name,
3470                 (void *)&cmd_config_threshold_value,
3471                 NULL,
3472         },
3473 };
3474
3475 /* *** stop *** */
3476 struct cmd_stop_result {
3477         cmdline_fixed_string_t stop;
3478 };
3479
3480 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3481                             __rte_unused struct cmdline *cl,
3482                             __rte_unused void *data)
3483 {
3484         stop_packet_forwarding();
3485 }
3486
3487 cmdline_parse_token_string_t cmd_stop_stop =
3488         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3489
3490 cmdline_parse_inst_t cmd_stop = {
3491         .f = cmd_stop_parsed,
3492         .data = NULL,
3493         .help_str = "stop: Stop packet forwarding",
3494         .tokens = {
3495                 (void *)&cmd_stop_stop,
3496                 NULL,
3497         },
3498 };
3499
3500 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3501
3502 unsigned int
3503 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3504                 unsigned int *parsed_items, int check_unique_values)
3505 {
3506         unsigned int nb_item;
3507         unsigned int value;
3508         unsigned int i;
3509         unsigned int j;
3510         int value_ok;
3511         char c;
3512
3513         /*
3514          * First parse all items in the list and store their value.
3515          */
3516         value = 0;
3517         nb_item = 0;
3518         value_ok = 0;
3519         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3520                 c = str[i];
3521                 if ((c >= '0') && (c <= '9')) {
3522                         value = (unsigned int) (value * 10 + (c - '0'));
3523                         value_ok = 1;
3524                         continue;
3525                 }
3526                 if (c != ',') {
3527                         printf("character %c is not a decimal digit\n", c);
3528                         return 0;
3529                 }
3530                 if (! value_ok) {
3531                         printf("No valid value before comma\n");
3532                         return 0;
3533                 }
3534                 if (nb_item < max_items) {
3535                         parsed_items[nb_item] = value;
3536                         value_ok = 0;
3537                         value = 0;
3538                 }
3539                 nb_item++;
3540         }
3541         if (nb_item >= max_items) {
3542                 printf("Number of %s = %u > %u (maximum items)\n",
3543                        item_name, nb_item + 1, max_items);
3544                 return 0;
3545         }
3546         parsed_items[nb_item++] = value;
3547         if (! check_unique_values)
3548                 return nb_item;
3549
3550         /*
3551          * Then, check that all values in the list are differents.
3552          * No optimization here...
3553          */
3554         for (i = 0; i < nb_item; i++) {
3555                 for (j = i + 1; j < nb_item; j++) {
3556                         if (parsed_items[j] == parsed_items[i]) {
3557                                 printf("duplicated %s %u at index %u and %u\n",
3558                                        item_name, parsed_items[i], i, j);
3559                                 return 0;
3560                         }
3561                 }
3562         }
3563         return nb_item;
3564 }
3565
3566 struct cmd_set_list_result {
3567         cmdline_fixed_string_t cmd_keyword;
3568         cmdline_fixed_string_t list_name;
3569         cmdline_fixed_string_t list_of_items;
3570 };
3571
3572 static void cmd_set_list_parsed(void *parsed_result,
3573                                 __rte_unused struct cmdline *cl,
3574                                 __rte_unused void *data)
3575 {
3576         struct cmd_set_list_result *res;
3577         union {
3578                 unsigned int lcorelist[RTE_MAX_LCORE];
3579                 unsigned int portlist[RTE_MAX_ETHPORTS];
3580         } parsed_items;
3581         unsigned int nb_item;
3582
3583         if (test_done == 0) {
3584                 printf("Please stop forwarding first\n");
3585                 return;
3586         }
3587
3588         res = parsed_result;
3589         if (!strcmp(res->list_name, "corelist")) {
3590                 nb_item = parse_item_list(res->list_of_items, "core",
3591                                           RTE_MAX_LCORE,
3592                                           parsed_items.lcorelist, 1);
3593                 if (nb_item > 0) {
3594                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3595                         fwd_config_setup();
3596                 }
3597                 return;
3598         }
3599         if (!strcmp(res->list_name, "portlist")) {
3600                 nb_item = parse_item_list(res->list_of_items, "port",
3601                                           RTE_MAX_ETHPORTS,
3602                                           parsed_items.portlist, 1);
3603                 if (nb_item > 0) {
3604                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3605                         fwd_config_setup();
3606                 }
3607         }
3608 }
3609
3610 cmdline_parse_token_string_t cmd_set_list_keyword =
3611         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3612                                  "set");
3613 cmdline_parse_token_string_t cmd_set_list_name =
3614         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3615                                  "corelist#portlist");
3616 cmdline_parse_token_string_t cmd_set_list_of_items =
3617         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3618                                  NULL);
3619
3620 cmdline_parse_inst_t cmd_set_fwd_list = {
3621         .f = cmd_set_list_parsed,
3622         .data = NULL,
3623         .help_str = "set corelist|portlist <list0[,list1]*>",
3624         .tokens = {
3625                 (void *)&cmd_set_list_keyword,
3626                 (void *)&cmd_set_list_name,
3627                 (void *)&cmd_set_list_of_items,
3628                 NULL,
3629         },
3630 };
3631
3632 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3633
3634 struct cmd_setmask_result {
3635         cmdline_fixed_string_t set;
3636         cmdline_fixed_string_t mask;
3637         uint64_t hexavalue;
3638 };
3639
3640 static void cmd_set_mask_parsed(void *parsed_result,
3641                                 __rte_unused struct cmdline *cl,
3642                                 __rte_unused void *data)
3643 {
3644         struct cmd_setmask_result *res = parsed_result;
3645
3646         if (test_done == 0) {
3647                 printf("Please stop forwarding first\n");
3648                 return;
3649         }
3650         if (!strcmp(res->mask, "coremask")) {
3651                 set_fwd_lcores_mask(res->hexavalue);
3652                 fwd_config_setup();
3653         } else if (!strcmp(res->mask, "portmask")) {
3654                 set_fwd_ports_mask(res->hexavalue);
3655                 fwd_config_setup();
3656         }
3657 }
3658
3659 cmdline_parse_token_string_t cmd_setmask_set =
3660         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3661 cmdline_parse_token_string_t cmd_setmask_mask =
3662         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3663                                  "coremask#portmask");
3664 cmdline_parse_token_num_t cmd_setmask_value =
3665         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3666
3667 cmdline_parse_inst_t cmd_set_fwd_mask = {
3668         .f = cmd_set_mask_parsed,
3669         .data = NULL,
3670         .help_str = "set coremask|portmask <hexadecimal value>",
3671         .tokens = {
3672                 (void *)&cmd_setmask_set,
3673                 (void *)&cmd_setmask_mask,
3674                 (void *)&cmd_setmask_value,
3675                 NULL,
3676         },
3677 };
3678
3679 /*
3680  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3681  */
3682 struct cmd_set_result {
3683         cmdline_fixed_string_t set;
3684         cmdline_fixed_string_t what;
3685         uint16_t value;
3686 };
3687
3688 static void cmd_set_parsed(void *parsed_result,
3689                            __rte_unused struct cmdline *cl,
3690                            __rte_unused void *data)
3691 {
3692         struct cmd_set_result *res = parsed_result;
3693         if (!strcmp(res->what, "nbport")) {
3694                 set_fwd_ports_number(res->value);
3695                 fwd_config_setup();
3696         } else if (!strcmp(res->what, "nbcore")) {
3697                 set_fwd_lcores_number(res->value);
3698                 fwd_config_setup();
3699         } else if (!strcmp(res->what, "burst"))
3700                 set_nb_pkt_per_burst(res->value);
3701         else if (!strcmp(res->what, "verbose"))
3702                 set_verbose_level(res->value);
3703 }
3704
3705 cmdline_parse_token_string_t cmd_set_set =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3707 cmdline_parse_token_string_t cmd_set_what =
3708         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3709                                  "nbport#nbcore#burst#verbose");
3710 cmdline_parse_token_num_t cmd_set_value =
3711         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3712
3713 cmdline_parse_inst_t cmd_set_numbers = {
3714         .f = cmd_set_parsed,
3715         .data = NULL,
3716         .help_str = "set nbport|nbcore|burst|verbose <value>",
3717         .tokens = {
3718                 (void *)&cmd_set_set,
3719                 (void *)&cmd_set_what,
3720                 (void *)&cmd_set_value,
3721                 NULL,
3722         },
3723 };
3724
3725 /* *** SET LOG LEVEL CONFIGURATION *** */
3726
3727 struct cmd_set_log_result {
3728         cmdline_fixed_string_t set;
3729         cmdline_fixed_string_t log;
3730         cmdline_fixed_string_t type;
3731         uint32_t level;
3732 };
3733
3734 static void
3735 cmd_set_log_parsed(void *parsed_result,
3736                    __rte_unused struct cmdline *cl,
3737                    __rte_unused void *data)
3738 {
3739         struct cmd_set_log_result *res;
3740         int ret;
3741
3742         res = parsed_result;
3743         if (!strcmp(res->type, "global"))
3744                 rte_log_set_global_level(res->level);
3745         else {
3746                 ret = rte_log_set_level_regexp(res->type, res->level);
3747                 if (ret < 0)
3748                         printf("Unable to set log level\n");
3749         }
3750 }
3751
3752 cmdline_parse_token_string_t cmd_set_log_set =
3753         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3754 cmdline_parse_token_string_t cmd_set_log_log =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3756 cmdline_parse_token_string_t cmd_set_log_type =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3758 cmdline_parse_token_num_t cmd_set_log_level =
3759         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3760
3761 cmdline_parse_inst_t cmd_set_log = {
3762         .f = cmd_set_log_parsed,
3763         .data = NULL,
3764         .help_str = "set log global|<type> <level>",
3765         .tokens = {
3766                 (void *)&cmd_set_log_set,
3767                 (void *)&cmd_set_log_log,
3768                 (void *)&cmd_set_log_type,
3769                 (void *)&cmd_set_log_level,
3770                 NULL,
3771         },
3772 };
3773
3774 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3775
3776 struct cmd_set_rxoffs_result {
3777         cmdline_fixed_string_t cmd_keyword;
3778         cmdline_fixed_string_t rxoffs;
3779         cmdline_fixed_string_t seg_offsets;
3780 };
3781
3782 static void
3783 cmd_set_rxoffs_parsed(void *parsed_result,
3784                       __rte_unused struct cmdline *cl,
3785                       __rte_unused void *data)
3786 {
3787         struct cmd_set_rxoffs_result *res;
3788         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3789         unsigned int nb_segs;
3790
3791         res = parsed_result;
3792         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3793                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3794         if (nb_segs > 0)
3795                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3796 }
3797
3798 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3799         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3800                                  cmd_keyword, "set");
3801 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3802         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3803                                  rxoffs, "rxoffs");
3804 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3805         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3806                                  seg_offsets, NULL);
3807
3808 cmdline_parse_inst_t cmd_set_rxoffs = {
3809         .f = cmd_set_rxoffs_parsed,
3810         .data = NULL,
3811         .help_str = "set rxoffs <len0[,len1]*>",
3812         .tokens = {
3813                 (void *)&cmd_set_rxoffs_keyword,
3814                 (void *)&cmd_set_rxoffs_name,
3815                 (void *)&cmd_set_rxoffs_offsets,
3816                 NULL,
3817         },
3818 };
3819
3820 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3821
3822 struct cmd_set_rxpkts_result {
3823         cmdline_fixed_string_t cmd_keyword;
3824         cmdline_fixed_string_t rxpkts;
3825         cmdline_fixed_string_t seg_lengths;
3826 };
3827
3828 static void
3829 cmd_set_rxpkts_parsed(void *parsed_result,
3830                       __rte_unused struct cmdline *cl,
3831                       __rte_unused void *data)
3832 {
3833         struct cmd_set_rxpkts_result *res;
3834         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3835         unsigned int nb_segs;
3836
3837         res = parsed_result;
3838         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3839                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3840         if (nb_segs > 0)
3841                 set_rx_pkt_segments(seg_lengths, nb_segs);
3842 }
3843
3844 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3845         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3846                                  cmd_keyword, "set");
3847 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3848         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3849                                  rxpkts, "rxpkts");
3850 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3851         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3852                                  seg_lengths, NULL);
3853
3854 cmdline_parse_inst_t cmd_set_rxpkts = {
3855         .f = cmd_set_rxpkts_parsed,
3856         .data = NULL,
3857         .help_str = "set rxpkts <len0[,len1]*>",
3858         .tokens = {
3859                 (void *)&cmd_set_rxpkts_keyword,
3860                 (void *)&cmd_set_rxpkts_name,
3861                 (void *)&cmd_set_rxpkts_lengths,
3862                 NULL,
3863         },
3864 };
3865
3866 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3867
3868 struct cmd_set_txpkts_result {
3869         cmdline_fixed_string_t cmd_keyword;
3870         cmdline_fixed_string_t txpkts;
3871         cmdline_fixed_string_t seg_lengths;
3872 };
3873
3874 static void
3875 cmd_set_txpkts_parsed(void *parsed_result,
3876                       __rte_unused struct cmdline *cl,
3877                       __rte_unused void *data)
3878 {
3879         struct cmd_set_txpkts_result *res;
3880         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3881         unsigned int nb_segs;
3882
3883         res = parsed_result;
3884         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3885                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3886         if (nb_segs > 0)
3887                 set_tx_pkt_segments(seg_lengths, nb_segs);
3888 }
3889
3890 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3892                                  cmd_keyword, "set");
3893 cmdline_parse_token_string_t cmd_set_txpkts_name =
3894         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3895                                  txpkts, "txpkts");
3896 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3897         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3898                                  seg_lengths, NULL);
3899
3900 cmdline_parse_inst_t cmd_set_txpkts = {
3901         .f = cmd_set_txpkts_parsed,
3902         .data = NULL,
3903         .help_str = "set txpkts <len0[,len1]*>",
3904         .tokens = {
3905                 (void *)&cmd_set_txpkts_keyword,
3906                 (void *)&cmd_set_txpkts_name,
3907                 (void *)&cmd_set_txpkts_lengths,
3908                 NULL,
3909         },
3910 };
3911
3912 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3913
3914 struct cmd_set_txsplit_result {
3915         cmdline_fixed_string_t cmd_keyword;
3916         cmdline_fixed_string_t txsplit;
3917         cmdline_fixed_string_t mode;
3918 };
3919
3920 static void
3921 cmd_set_txsplit_parsed(void *parsed_result,
3922                       __rte_unused struct cmdline *cl,
3923                       __rte_unused void *data)
3924 {
3925         struct cmd_set_txsplit_result *res;
3926
3927         res = parsed_result;
3928         set_tx_pkt_split(res->mode);
3929 }
3930
3931 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3932         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3933                                  cmd_keyword, "set");
3934 cmdline_parse_token_string_t cmd_set_txsplit_name =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3936                                  txsplit, "txsplit");
3937 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3938         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3939                                  mode, NULL);
3940
3941 cmdline_parse_inst_t cmd_set_txsplit = {
3942         .f = cmd_set_txsplit_parsed,
3943         .data = NULL,
3944         .help_str = "set txsplit on|off|rand",
3945         .tokens = {
3946                 (void *)&cmd_set_txsplit_keyword,
3947                 (void *)&cmd_set_txsplit_name,
3948                 (void *)&cmd_set_txsplit_mode,
3949                 NULL,
3950         },
3951 };
3952
3953 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3954
3955 struct cmd_set_txtimes_result {
3956         cmdline_fixed_string_t cmd_keyword;
3957         cmdline_fixed_string_t txtimes;
3958         cmdline_fixed_string_t tx_times;
3959 };
3960
3961 static void
3962 cmd_set_txtimes_parsed(void *parsed_result,
3963                        __rte_unused struct cmdline *cl,
3964                        __rte_unused void *data)
3965 {
3966         struct cmd_set_txtimes_result *res;
3967         unsigned int tx_times[2] = {0, 0};
3968         unsigned int n_times;
3969
3970         res = parsed_result;
3971         n_times = parse_item_list(res->tx_times, "tx times",
3972                                   2, tx_times, 0);
3973         if (n_times == 2)
3974                 set_tx_pkt_times(tx_times);
3975 }
3976
3977 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3978         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3979                                  cmd_keyword, "set");
3980 cmdline_parse_token_string_t cmd_set_txtimes_name =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3982                                  txtimes, "txtimes");
3983 cmdline_parse_token_string_t cmd_set_txtimes_value =
3984         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3985                                  tx_times, NULL);
3986
3987 cmdline_parse_inst_t cmd_set_txtimes = {
3988         .f = cmd_set_txtimes_parsed,
3989         .data = NULL,
3990         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3991         .tokens = {
3992                 (void *)&cmd_set_txtimes_keyword,
3993                 (void *)&cmd_set_txtimes_name,
3994                 (void *)&cmd_set_txtimes_value,
3995                 NULL,
3996         },
3997 };
3998
3999 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4000 struct cmd_rx_vlan_filter_all_result {
4001         cmdline_fixed_string_t rx_vlan;
4002         cmdline_fixed_string_t what;
4003         cmdline_fixed_string_t all;
4004         portid_t port_id;
4005 };
4006
4007 static void
4008 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4009                               __rte_unused struct cmdline *cl,
4010                               __rte_unused void *data)
4011 {
4012         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4013
4014         if (!strcmp(res->what, "add"))
4015                 rx_vlan_all_filter_set(res->port_id, 1);
4016         else
4017                 rx_vlan_all_filter_set(res->port_id, 0);
4018 }
4019
4020 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4021         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4022                                  rx_vlan, "rx_vlan");
4023 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4024         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4025                                  what, "add#rm");
4026 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4027         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4028                                  all, "all");
4029 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4030         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4031                               port_id, UINT16);
4032
4033 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4034         .f = cmd_rx_vlan_filter_all_parsed,
4035         .data = NULL,
4036         .help_str = "rx_vlan add|rm all <port_id>: "
4037                 "Add/Remove all identifiers to/from the set of VLAN "
4038                 "identifiers filtered by a port",
4039         .tokens = {
4040                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4041                 (void *)&cmd_rx_vlan_filter_all_what,
4042                 (void *)&cmd_rx_vlan_filter_all_all,
4043                 (void *)&cmd_rx_vlan_filter_all_portid,
4044                 NULL,
4045         },
4046 };
4047
4048 /* *** VLAN OFFLOAD SET ON A PORT *** */
4049 struct cmd_vlan_offload_result {
4050         cmdline_fixed_string_t vlan;
4051         cmdline_fixed_string_t set;
4052         cmdline_fixed_string_t vlan_type;
4053         cmdline_fixed_string_t what;
4054         cmdline_fixed_string_t on;
4055         cmdline_fixed_string_t port_id;
4056 };
4057
4058 static void
4059 cmd_vlan_offload_parsed(void *parsed_result,
4060                           __rte_unused struct cmdline *cl,
4061                           __rte_unused void *data)
4062 {
4063         int on;
4064         struct cmd_vlan_offload_result *res = parsed_result;
4065         char *str;
4066         int i, len = 0;
4067         portid_t port_id = 0;
4068         unsigned int tmp;
4069
4070         str = res->port_id;
4071         len = strnlen(str, STR_TOKEN_SIZE);
4072         i = 0;
4073         /* Get port_id first */
4074         while(i < len){
4075                 if(str[i] == ',')
4076                         break;
4077
4078                 i++;
4079         }
4080         str[i]='\0';
4081         tmp = strtoul(str, NULL, 0);
4082         /* If port_id greater that what portid_t can represent, return */
4083         if(tmp >= RTE_MAX_ETHPORTS)
4084                 return;
4085         port_id = (portid_t)tmp;
4086
4087         if (!strcmp(res->on, "on"))
4088                 on = 1;
4089         else
4090                 on = 0;
4091
4092         if (!strcmp(res->what, "strip"))
4093                 rx_vlan_strip_set(port_id,  on);
4094         else if(!strcmp(res->what, "stripq")){
4095                 uint16_t queue_id = 0;
4096
4097                 /* No queue_id, return */
4098                 if(i + 1 >= len) {
4099                         printf("must specify (port,queue_id)\n");
4100                         return;
4101                 }
4102                 tmp = strtoul(str + i + 1, NULL, 0);
4103                 /* If queue_id greater that what 16-bits can represent, return */
4104                 if(tmp > 0xffff)
4105                         return;
4106
4107                 queue_id = (uint16_t)tmp;
4108                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4109         }
4110         else if (!strcmp(res->what, "filter"))
4111                 rx_vlan_filter_set(port_id, on);
4112         else if (!strcmp(res->what, "qinq_strip"))
4113                 rx_vlan_qinq_strip_set(port_id, on);
4114         else
4115                 vlan_extend_set(port_id, on);
4116
4117         return;
4118 }
4119
4120 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4121         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4122                                  vlan, "vlan");
4123 cmdline_parse_token_string_t cmd_vlan_offload_set =
4124         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4125                                  set, "set");
4126 cmdline_parse_token_string_t cmd_vlan_offload_what =
4127         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4128                                 what, "strip#filter#qinq_strip#extend#stripq");
4129 cmdline_parse_token_string_t cmd_vlan_offload_on =
4130         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4131                               on, "on#off");
4132 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4133         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4134                               port_id, NULL);
4135
4136 cmdline_parse_inst_t cmd_vlan_offload = {
4137         .f = cmd_vlan_offload_parsed,
4138         .data = NULL,
4139         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4140                 "<port_id[,queue_id]>: "
4141                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4142         .tokens = {
4143                 (void *)&cmd_vlan_offload_vlan,
4144                 (void *)&cmd_vlan_offload_set,
4145                 (void *)&cmd_vlan_offload_what,
4146                 (void *)&cmd_vlan_offload_on,
4147                 (void *)&cmd_vlan_offload_portid,
4148                 NULL,
4149         },
4150 };
4151
4152 /* *** VLAN TPID SET ON A PORT *** */
4153 struct cmd_vlan_tpid_result {
4154         cmdline_fixed_string_t vlan;
4155         cmdline_fixed_string_t set;
4156         cmdline_fixed_string_t vlan_type;
4157         cmdline_fixed_string_t what;
4158         uint16_t tp_id;
4159         portid_t port_id;
4160 };
4161
4162 static void
4163 cmd_vlan_tpid_parsed(void *parsed_result,
4164                           __rte_unused struct cmdline *cl,
4165                           __rte_unused void *data)
4166 {
4167         struct cmd_vlan_tpid_result *res = parsed_result;
4168         enum rte_vlan_type vlan_type;
4169
4170         if (!strcmp(res->vlan_type, "inner"))
4171                 vlan_type = ETH_VLAN_TYPE_INNER;
4172         else if (!strcmp(res->vlan_type, "outer"))
4173                 vlan_type = ETH_VLAN_TYPE_OUTER;
4174         else {
4175                 printf("Unknown vlan type\n");
4176                 return;
4177         }
4178         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4179 }
4180
4181 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4182         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4183                                  vlan, "vlan");
4184 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4185         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4186                                  set, "set");
4187 cmdline_parse_token_string_t cmd_vlan_type =
4188         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4189                                  vlan_type, "inner#outer");
4190 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4191         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4192                                  what, "tpid");
4193 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4194         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4195                               tp_id, UINT16);
4196 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4197         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4198                               port_id, UINT16);
4199
4200 cmdline_parse_inst_t cmd_vlan_tpid = {
4201         .f = cmd_vlan_tpid_parsed,
4202         .data = NULL,
4203         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4204                 "Set the VLAN Ether type",
4205         .tokens = {
4206                 (void *)&cmd_vlan_tpid_vlan,
4207                 (void *)&cmd_vlan_tpid_set,
4208                 (void *)&cmd_vlan_type,
4209                 (void *)&cmd_vlan_tpid_what,
4210                 (void *)&cmd_vlan_tpid_tpid,
4211                 (void *)&cmd_vlan_tpid_portid,
4212                 NULL,
4213         },
4214 };
4215
4216 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4217 struct cmd_rx_vlan_filter_result {
4218         cmdline_fixed_string_t rx_vlan;
4219         cmdline_fixed_string_t what;
4220         uint16_t vlan_id;
4221         portid_t port_id;
4222 };
4223
4224 static void
4225 cmd_rx_vlan_filter_parsed(void *parsed_result,
4226                           __rte_unused struct cmdline *cl,
4227                           __rte_unused void *data)
4228 {
4229         struct cmd_rx_vlan_filter_result *res = parsed_result;
4230
4231         if (!strcmp(res->what, "add"))
4232                 rx_vft_set(res->port_id, res->vlan_id, 1);
4233         else
4234                 rx_vft_set(res->port_id, res->vlan_id, 0);
4235 }
4236
4237 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4238         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4239                                  rx_vlan, "rx_vlan");
4240 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4241         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4242                                  what, "add#rm");
4243 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4244         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4245                               vlan_id, UINT16);
4246 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4247         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4248                               port_id, UINT16);
4249
4250 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4251         .f = cmd_rx_vlan_filter_parsed,
4252         .data = NULL,
4253         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4254                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4255                 "identifiers filtered by a port",
4256         .tokens = {
4257                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4258                 (void *)&cmd_rx_vlan_filter_what,
4259                 (void *)&cmd_rx_vlan_filter_vlanid,
4260                 (void *)&cmd_rx_vlan_filter_portid,
4261                 NULL,
4262         },
4263 };
4264
4265 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4266 struct cmd_tx_vlan_set_result {
4267         cmdline_fixed_string_t tx_vlan;
4268         cmdline_fixed_string_t set;
4269         portid_t port_id;
4270         uint16_t vlan_id;
4271 };
4272
4273 static void
4274 cmd_tx_vlan_set_parsed(void *parsed_result,
4275                        __rte_unused struct cmdline *cl,
4276                        __rte_unused void *data)
4277 {
4278         struct cmd_tx_vlan_set_result *res = parsed_result;
4279
4280         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4281                 return;
4282
4283         if (!port_is_stopped(res->port_id)) {
4284                 printf("Please stop port %d first\n", res->port_id);
4285                 return;
4286         }
4287
4288         tx_vlan_set(res->port_id, res->vlan_id);
4289
4290         cmd_reconfig_device_queue(res->port_id, 1, 1);
4291 }
4292
4293 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4294         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4295                                  tx_vlan, "tx_vlan");
4296 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4297         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4298                                  set, "set");
4299 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4300         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4301                               port_id, UINT16);
4302 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4303         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4304                               vlan_id, UINT16);
4305
4306 cmdline_parse_inst_t cmd_tx_vlan_set = {
4307         .f = cmd_tx_vlan_set_parsed,
4308         .data = NULL,
4309         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4310                 "Enable hardware insertion of a single VLAN header "
4311                 "with a given TAG Identifier in packets sent on a port",
4312         .tokens = {
4313                 (void *)&cmd_tx_vlan_set_tx_vlan,
4314                 (void *)&cmd_tx_vlan_set_set,
4315                 (void *)&cmd_tx_vlan_set_portid,
4316                 (void *)&cmd_tx_vlan_set_vlanid,
4317                 NULL,
4318         },
4319 };
4320
4321 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4322 struct cmd_tx_vlan_set_qinq_result {
4323         cmdline_fixed_string_t tx_vlan;
4324         cmdline_fixed_string_t set;
4325         portid_t port_id;
4326         uint16_t vlan_id;
4327         uint16_t vlan_id_outer;
4328 };
4329
4330 static void
4331 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4332                             __rte_unused struct cmdline *cl,
4333                             __rte_unused void *data)
4334 {
4335         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4336
4337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4338                 return;
4339
4340         if (!port_is_stopped(res->port_id)) {
4341                 printf("Please stop port %d first\n", res->port_id);
4342                 return;
4343         }
4344
4345         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4346
4347         cmd_reconfig_device_queue(res->port_id, 1, 1);
4348 }
4349
4350 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4351         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4352                 tx_vlan, "tx_vlan");
4353 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4354         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4355                 set, "set");
4356 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4357         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4358                 port_id, UINT16);
4359 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4360         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4361                 vlan_id, UINT16);
4362 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4363         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4364                 vlan_id_outer, UINT16);
4365
4366 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4367         .f = cmd_tx_vlan_set_qinq_parsed,
4368         .data = NULL,
4369         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4370                 "Enable hardware insertion of double VLAN header "
4371                 "with given TAG Identifiers in packets sent on a port",
4372         .tokens = {
4373                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4374                 (void *)&cmd_tx_vlan_set_qinq_set,
4375                 (void *)&cmd_tx_vlan_set_qinq_portid,
4376                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4377                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4378                 NULL,
4379         },
4380 };
4381
4382 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4383 struct cmd_tx_vlan_set_pvid_result {
4384         cmdline_fixed_string_t tx_vlan;
4385         cmdline_fixed_string_t set;
4386         cmdline_fixed_string_t pvid;
4387         portid_t port_id;
4388         uint16_t vlan_id;
4389         cmdline_fixed_string_t mode;
4390 };
4391
4392 static void
4393 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4394                             __rte_unused struct cmdline *cl,
4395                             __rte_unused void *data)
4396 {
4397         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4398
4399         if (strcmp(res->mode, "on") == 0)
4400                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4401         else
4402                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4403 }
4404
4405 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4406         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4407                                  tx_vlan, "tx_vlan");
4408 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4409         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4410                                  set, "set");
4411 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4412         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4413                                  pvid, "pvid");
4414 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4415         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4416                              port_id, UINT16);
4417 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4418         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4419                               vlan_id, UINT16);
4420 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4421         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4422                                  mode, "on#off");
4423
4424 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4425         .f = cmd_tx_vlan_set_pvid_parsed,
4426         .data = NULL,
4427         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4428         .tokens = {
4429                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4430                 (void *)&cmd_tx_vlan_set_pvid_set,
4431                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4432                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4433                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4434                 (void *)&cmd_tx_vlan_set_pvid_mode,
4435                 NULL,
4436         },
4437 };
4438
4439 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4440 struct cmd_tx_vlan_reset_result {
4441         cmdline_fixed_string_t tx_vlan;
4442         cmdline_fixed_string_t reset;
4443         portid_t port_id;
4444 };
4445
4446 static void
4447 cmd_tx_vlan_reset_parsed(void *parsed_result,
4448                          __rte_unused struct cmdline *cl,
4449                          __rte_unused void *data)
4450 {
4451         struct cmd_tx_vlan_reset_result *res = parsed_result;
4452
4453         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4454                 return;
4455
4456         if (!port_is_stopped(res->port_id)) {
4457                 printf("Please stop port %d first\n", res->port_id);
4458                 return;
4459         }
4460
4461         tx_vlan_reset(res->port_id);
4462
4463         cmd_reconfig_device_queue(res->port_id, 1, 1);
4464 }
4465
4466 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4467         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4468                                  tx_vlan, "tx_vlan");
4469 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4470         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4471                                  reset, "reset");
4472 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4473         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4474                               port_id, UINT16);
4475
4476 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4477         .f = cmd_tx_vlan_reset_parsed,
4478         .data = NULL,
4479         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4480                 "VLAN header in packets sent on a port",
4481         .tokens = {
4482                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4483                 (void *)&cmd_tx_vlan_reset_reset,
4484                 (void *)&cmd_tx_vlan_reset_portid,
4485                 NULL,
4486         },
4487 };
4488
4489
4490 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4491 struct cmd_csum_result {
4492         cmdline_fixed_string_t csum;
4493         cmdline_fixed_string_t mode;
4494         cmdline_fixed_string_t proto;
4495         cmdline_fixed_string_t hwsw;
4496         portid_t port_id;
4497 };
4498
4499 static void
4500 csum_show(int port_id)
4501 {
4502         struct rte_eth_dev_info dev_info;
4503         uint64_t tx_offloads;
4504         int ret;
4505
4506         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4507         printf("Parse tunnel is %s\n",
4508                 (ports[port_id].parse_tunnel) ? "on" : "off");
4509         printf("IP checksum offload is %s\n",
4510                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4511         printf("UDP checksum offload is %s\n",
4512                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4513         printf("TCP checksum offload is %s\n",
4514                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4515         printf("SCTP checksum offload is %s\n",
4516                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4517         printf("Outer-Ip checksum offload is %s\n",
4518                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4519         printf("Outer-Udp checksum offload is %s\n",
4520                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4521
4522         /* display warnings if configuration is not supported by the NIC */
4523         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4524         if (ret != 0)
4525                 return;
4526
4527         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4528                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4529                 printf("Warning: hardware IP checksum enabled but not "
4530                         "supported by port %d\n", port_id);
4531         }
4532         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4533                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4534                 printf("Warning: hardware UDP checksum enabled but not "
4535                         "supported by port %d\n", port_id);
4536         }
4537         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4538                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4539                 printf("Warning: hardware TCP checksum enabled but not "
4540                         "supported by port %d\n", port_id);
4541         }
4542         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4543                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4544                 printf("Warning: hardware SCTP checksum enabled but not "
4545                         "supported by port %d\n", port_id);
4546         }
4547         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4548                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4549                 printf("Warning: hardware outer IP checksum enabled but not "
4550                         "supported by port %d\n", port_id);
4551         }
4552         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4553                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4554                         == 0) {
4555                 printf("Warning: hardware outer UDP checksum enabled but not "
4556                         "supported by port %d\n", port_id);
4557         }
4558 }
4559
4560 static void
4561 cmd_config_queue_tx_offloads(struct rte_port *port)
4562 {
4563         int k;
4564
4565         /* Apply queue tx offloads configuration */
4566         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4567                 port->tx_conf[k].offloads =
4568                         port->dev_conf.txmode.offloads;
4569 }
4570
4571 static void
4572 cmd_csum_parsed(void *parsed_result,
4573                        __rte_unused struct cmdline *cl,
4574                        __rte_unused void *data)
4575 {
4576         struct cmd_csum_result *res = parsed_result;
4577         int hw = 0;
4578         uint64_t csum_offloads = 0;
4579         struct rte_eth_dev_info dev_info;
4580         int ret;
4581
4582         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4583                 printf("invalid port %d\n", res->port_id);
4584                 return;
4585         }
4586         if (!port_is_stopped(res->port_id)) {
4587                 printf("Please stop port %d first\n", res->port_id);
4588                 return;
4589         }
4590
4591         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4592         if (ret != 0)
4593                 return;
4594
4595         if (!strcmp(res->mode, "set")) {
4596
4597                 if (!strcmp(res->hwsw, "hw"))
4598                         hw = 1;
4599
4600                 if (!strcmp(res->proto, "ip")) {
4601                         if (hw == 0 || (dev_info.tx_offload_capa &
4602                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4603                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4604                         } else {
4605                                 printf("IP checksum offload is not supported "
4606                                        "by port %u\n", res->port_id);
4607                         }
4608                 } else if (!strcmp(res->proto, "udp")) {
4609                         if (hw == 0 || (dev_info.tx_offload_capa &
4610                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4611                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4612                         } else {
4613                                 printf("UDP checksum offload is not supported "
4614                                        "by port %u\n", res->port_id);
4615                         }
4616                 } else if (!strcmp(res->proto, "tcp")) {
4617                         if (hw == 0 || (dev_info.tx_offload_capa &
4618                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4619                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4620                         } else {
4621                                 printf("TCP checksum offload is not supported "
4622                                        "by port %u\n", res->port_id);
4623                         }
4624                 } else if (!strcmp(res->proto, "sctp")) {
4625                         if (hw == 0 || (dev_info.tx_offload_capa &
4626                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4627                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4628                         } else {
4629                                 printf("SCTP checksum offload is not supported "
4630                                        "by port %u\n", res->port_id);
4631                         }
4632                 } else if (!strcmp(res->proto, "outer-ip")) {
4633                         if (hw == 0 || (dev_info.tx_offload_capa &
4634                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4635                                 csum_offloads |=
4636                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4637                         } else {
4638                                 printf("Outer IP checksum offload is not "
4639                                        "supported by port %u\n", res->port_id);
4640                         }
4641                 } else if (!strcmp(res->proto, "outer-udp")) {
4642                         if (hw == 0 || (dev_info.tx_offload_capa &
4643                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4644                                 csum_offloads |=
4645                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4646                         } else {
4647                                 printf("Outer UDP checksum offload is not "
4648                                        "supported by port %u\n", res->port_id);
4649                         }
4650                 }
4651
4652                 if (hw) {
4653                         ports[res->port_id].dev_conf.txmode.offloads |=
4654                                                         csum_offloads;
4655                 } else {
4656                         ports[res->port_id].dev_conf.txmode.offloads &=
4657                                                         (~csum_offloads);
4658                 }
4659                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4660         }
4661         csum_show(res->port_id);
4662
4663         cmd_reconfig_device_queue(res->port_id, 1, 1);
4664 }
4665
4666 cmdline_parse_token_string_t cmd_csum_csum =
4667         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4668                                 csum, "csum");
4669 cmdline_parse_token_string_t cmd_csum_mode =
4670         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4671                                 mode, "set");
4672 cmdline_parse_token_string_t cmd_csum_proto =
4673         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4674                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4675 cmdline_parse_token_string_t cmd_csum_hwsw =
4676         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4677                                 hwsw, "hw#sw");
4678 cmdline_parse_token_num_t cmd_csum_portid =
4679         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4680                                 port_id, UINT16);
4681
4682 cmdline_parse_inst_t cmd_csum_set = {
4683         .f = cmd_csum_parsed,
4684         .data = NULL,
4685         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4686                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4687                 "using csum forward engine",
4688         .tokens = {
4689                 (void *)&cmd_csum_csum,
4690                 (void *)&cmd_csum_mode,
4691                 (void *)&cmd_csum_proto,
4692                 (void *)&cmd_csum_hwsw,
4693                 (void *)&cmd_csum_portid,
4694                 NULL,
4695         },
4696 };
4697
4698 cmdline_parse_token_string_t cmd_csum_mode_show =
4699         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4700                                 mode, "show");
4701
4702 cmdline_parse_inst_t cmd_csum_show = {
4703         .f = cmd_csum_parsed,
4704         .data = NULL,
4705         .help_str = "csum show <port_id>: Show checksum offload configuration",
4706         .tokens = {
4707                 (void *)&cmd_csum_csum,
4708                 (void *)&cmd_csum_mode_show,
4709                 (void *)&cmd_csum_portid,
4710                 NULL,
4711         },
4712 };
4713
4714 /* Enable/disable tunnel parsing */
4715 struct cmd_csum_tunnel_result {
4716         cmdline_fixed_string_t csum;
4717         cmdline_fixed_string_t parse;
4718         cmdline_fixed_string_t onoff;
4719         portid_t port_id;
4720 };
4721
4722 static void
4723 cmd_csum_tunnel_parsed(void *parsed_result,
4724                        __rte_unused struct cmdline *cl,
4725                        __rte_unused void *data)
4726 {
4727         struct cmd_csum_tunnel_result *res = parsed_result;
4728
4729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4730                 return;
4731
4732         if (!strcmp(res->onoff, "on"))
4733                 ports[res->port_id].parse_tunnel = 1;
4734         else
4735                 ports[res->port_id].parse_tunnel = 0;
4736
4737         csum_show(res->port_id);
4738 }
4739
4740 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4741         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4742                                 csum, "csum");
4743 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4744         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4745                                 parse, "parse-tunnel");
4746 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4747         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4748                                 onoff, "on#off");
4749 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4750         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4751                                 port_id, UINT16);
4752
4753 cmdline_parse_inst_t cmd_csum_tunnel = {
4754         .f = cmd_csum_tunnel_parsed,
4755         .data = NULL,
4756         .help_str = "csum parse-tunnel on|off <port_id>: "
4757                 "Enable/Disable parsing of tunnels for csum engine",
4758         .tokens = {
4759                 (void *)&cmd_csum_tunnel_csum,
4760                 (void *)&cmd_csum_tunnel_parse,
4761                 (void *)&cmd_csum_tunnel_onoff,
4762                 (void *)&cmd_csum_tunnel_portid,
4763                 NULL,
4764         },
4765 };
4766
4767 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4768 struct cmd_tso_set_result {
4769         cmdline_fixed_string_t tso;
4770         cmdline_fixed_string_t mode;
4771         uint16_t tso_segsz;
4772         portid_t port_id;
4773 };
4774
4775 static void
4776 cmd_tso_set_parsed(void *parsed_result,
4777                        __rte_unused struct cmdline *cl,
4778                        __rte_unused void *data)
4779 {
4780         struct cmd_tso_set_result *res = parsed_result;
4781         struct rte_eth_dev_info dev_info;
4782         int ret;
4783
4784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4785                 return;
4786         if (!port_is_stopped(res->port_id)) {
4787                 printf("Please stop port %d first\n", res->port_id);
4788                 return;
4789         }
4790
4791         if (!strcmp(res->mode, "set"))
4792                 ports[res->port_id].tso_segsz = res->tso_segsz;
4793
4794         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4795         if (ret != 0)
4796                 return;
4797
4798         if ((ports[res->port_id].tso_segsz != 0) &&
4799                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4800                 printf("Error: TSO is not supported by port %d\n",
4801                        res->port_id);
4802                 return;
4803         }
4804
4805         if (ports[res->port_id].tso_segsz == 0) {
4806                 ports[res->port_id].dev_conf.txmode.offloads &=
4807                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4808                 printf("TSO for non-tunneled packets is disabled\n");
4809         } else {
4810                 ports[res->port_id].dev_conf.txmode.offloads |=
4811                                                 DEV_TX_OFFLOAD_TCP_TSO;
4812                 printf("TSO segment size for non-tunneled packets is %d\n",
4813                         ports[res->port_id].tso_segsz);
4814         }
4815         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4816
4817         /* display warnings if configuration is not supported by the NIC */
4818         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4819         if (ret != 0)
4820                 return;
4821
4822         if ((ports[res->port_id].tso_segsz != 0) &&
4823                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4824                 printf("Warning: TSO enabled but not "
4825                         "supported by port %d\n", res->port_id);
4826         }
4827
4828         cmd_reconfig_device_queue(res->port_id, 1, 1);
4829 }
4830
4831 cmdline_parse_token_string_t cmd_tso_set_tso =
4832         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4833                                 tso, "tso");
4834 cmdline_parse_token_string_t cmd_tso_set_mode =
4835         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4836                                 mode, "set");
4837 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4838         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4839                                 tso_segsz, UINT16);
4840 cmdline_parse_token_num_t cmd_tso_set_portid =
4841         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4842                                 port_id, UINT16);
4843
4844 cmdline_parse_inst_t cmd_tso_set = {
4845         .f = cmd_tso_set_parsed,
4846         .data = NULL,
4847         .help_str = "tso set <tso_segsz> <port_id>: "
4848                 "Set TSO segment size of non-tunneled packets for csum engine "
4849                 "(0 to disable)",
4850         .tokens = {
4851                 (void *)&cmd_tso_set_tso,
4852                 (void *)&cmd_tso_set_mode,
4853                 (void *)&cmd_tso_set_tso_segsz,
4854                 (void *)&cmd_tso_set_portid,
4855                 NULL,
4856         },
4857 };
4858
4859 cmdline_parse_token_string_t cmd_tso_show_mode =
4860         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4861                                 mode, "show");
4862
4863
4864 cmdline_parse_inst_t cmd_tso_show = {
4865         .f = cmd_tso_set_parsed,
4866         .data = NULL,
4867         .help_str = "tso show <port_id>: "
4868                 "Show TSO segment size of non-tunneled packets for csum engine",
4869         .tokens = {
4870                 (void *)&cmd_tso_set_tso,
4871                 (void *)&cmd_tso_show_mode,
4872                 (void *)&cmd_tso_set_portid,
4873                 NULL,
4874         },
4875 };
4876
4877 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4878 struct cmd_tunnel_tso_set_result {
4879         cmdline_fixed_string_t tso;
4880         cmdline_fixed_string_t mode;
4881         uint16_t tso_segsz;
4882         portid_t port_id;
4883 };
4884
4885 static struct rte_eth_dev_info
4886 check_tunnel_tso_nic_support(portid_t port_id)
4887 {
4888         struct rte_eth_dev_info dev_info;
4889
4890         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4891                 return dev_info;
4892
4893         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4894                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4895                        "not enabled for port %d\n", port_id);
4896         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4897                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4898                        "not enabled for port %d\n", port_id);
4899         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4900                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4901                        "not enabled for port %d\n", port_id);
4902         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4903                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4904                        "not enabled for port %d\n", port_id);
4905         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4906                 printf("Warning: IP TUNNEL TSO not supported therefore "
4907                        "not enabled for port %d\n", port_id);
4908         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4909                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4910                        "not enabled for port %d\n", port_id);
4911         return dev_info;
4912 }
4913
4914 static void
4915 cmd_tunnel_tso_set_parsed(void *parsed_result,
4916                           __rte_unused struct cmdline *cl,
4917                           __rte_unused void *data)
4918 {
4919         struct cmd_tunnel_tso_set_result *res = parsed_result;
4920         struct rte_eth_dev_info dev_info;
4921
4922         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4923                 return;
4924         if (!port_is_stopped(res->port_id)) {
4925                 printf("Please stop port %d first\n", res->port_id);
4926                 return;
4927         }
4928
4929         if (!strcmp(res->mode, "set"))
4930                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4931
4932         dev_info = check_tunnel_tso_nic_support(res->port_id);
4933         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4934                 ports[res->port_id].dev_conf.txmode.offloads &=
4935                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4936                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4937                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4938                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4939                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4940                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4941                 printf("TSO for tunneled packets is disabled\n");
4942         } else {
4943                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4944                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4945                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4946                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4947                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4948                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4949
4950                 ports[res->port_id].dev_conf.txmode.offloads |=
4951                         (tso_offloads & dev_info.tx_offload_capa);
4952                 printf("TSO segment size for tunneled packets is %d\n",
4953                         ports[res->port_id].tunnel_tso_segsz);
4954
4955                 /* Below conditions are needed to make it work:
4956                  * (1) tunnel TSO is supported by the NIC;
4957                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4958                  * are recognized;
4959                  * (3) for tunneled pkts with outer L3 of IPv4,
4960                  * "csum set outer-ip" must be set to hw, because after tso,
4961                  * total_len of outer IP header is changed, and the checksum
4962                  * of outer IP header calculated by sw should be wrong; that
4963                  * is not necessary for IPv6 tunneled pkts because there's no
4964                  * checksum in IP header anymore.
4965                  */
4966
4967                 if (!ports[res->port_id].parse_tunnel)
4968                         printf("Warning: csum parse_tunnel must be set "
4969                                 "so that tunneled packets are recognized\n");
4970                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4971                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4972                         printf("Warning: csum set outer-ip must be set to hw "
4973                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4974         }
4975
4976         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4977         cmd_reconfig_device_queue(res->port_id, 1, 1);
4978 }
4979
4980 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4981         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4982                                 tso, "tunnel_tso");
4983 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4984         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4985                                 mode, "set");
4986 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4987         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4988                                 tso_segsz, UINT16);
4989 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4990         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4991                                 port_id, UINT16);
4992
4993 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4994         .f = cmd_tunnel_tso_set_parsed,
4995         .data = NULL,
4996         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4997                 "Set TSO segment size of tunneled packets for csum engine "
4998                 "(0 to disable)",
4999         .tokens = {
5000                 (void *)&cmd_tunnel_tso_set_tso,
5001                 (void *)&cmd_tunnel_tso_set_mode,
5002                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5003                 (void *)&cmd_tunnel_tso_set_portid,
5004                 NULL,
5005         },
5006 };
5007
5008 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5009         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5010                                 mode, "show");
5011
5012
5013 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5014         .f = cmd_tunnel_tso_set_parsed,
5015         .data = NULL,
5016         .help_str = "tunnel_tso show <port_id> "
5017                 "Show TSO segment size of tunneled packets for csum engine",
5018         .tokens = {
5019                 (void *)&cmd_tunnel_tso_set_tso,
5020                 (void *)&cmd_tunnel_tso_show_mode,
5021                 (void *)&cmd_tunnel_tso_set_portid,
5022                 NULL,
5023         },
5024 };
5025
5026 /* *** SET GRO FOR A PORT *** */
5027 struct cmd_gro_enable_result {
5028         cmdline_fixed_string_t cmd_set;
5029         cmdline_fixed_string_t cmd_port;
5030         cmdline_fixed_string_t cmd_keyword;
5031         cmdline_fixed_string_t cmd_onoff;
5032         portid_t cmd_pid;
5033 };
5034
5035 static void
5036 cmd_gro_enable_parsed(void *parsed_result,
5037                 __rte_unused struct cmdline *cl,
5038                 __rte_unused void *data)
5039 {
5040         struct cmd_gro_enable_result *res;
5041
5042         res = parsed_result;
5043         if (!strcmp(res->cmd_keyword, "gro"))
5044                 setup_gro(res->cmd_onoff, res->cmd_pid);
5045 }
5046
5047 cmdline_parse_token_string_t cmd_gro_enable_set =
5048         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5049                         cmd_set, "set");
5050 cmdline_parse_token_string_t cmd_gro_enable_port =
5051         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5052                         cmd_keyword, "port");
5053 cmdline_parse_token_num_t cmd_gro_enable_pid =
5054         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5055                         cmd_pid, UINT16);
5056 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5057         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5058                         cmd_keyword, "gro");
5059 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5060         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5061                         cmd_onoff, "on#off");
5062
5063 cmdline_parse_inst_t cmd_gro_enable = {
5064         .f = cmd_gro_enable_parsed,
5065         .data = NULL,
5066         .help_str = "set port <port_id> gro on|off",
5067         .tokens = {
5068                 (void *)&cmd_gro_enable_set,
5069                 (void *)&cmd_gro_enable_port,
5070                 (void *)&cmd_gro_enable_pid,
5071                 (void *)&cmd_gro_enable_keyword,
5072                 (void *)&cmd_gro_enable_onoff,
5073                 NULL,
5074         },
5075 };
5076
5077 /* *** DISPLAY GRO CONFIGURATION *** */
5078 struct cmd_gro_show_result {
5079         cmdline_fixed_string_t cmd_show;
5080         cmdline_fixed_string_t cmd_port;
5081         cmdline_fixed_string_t cmd_keyword;
5082         portid_t cmd_pid;
5083 };
5084
5085 static void
5086 cmd_gro_show_parsed(void *parsed_result,
5087                 __rte_unused struct cmdline *cl,
5088                 __rte_unused void *data)
5089 {
5090         struct cmd_gro_show_result *res;
5091
5092         res = parsed_result;
5093         if (!strcmp(res->cmd_keyword, "gro"))
5094                 show_gro(res->cmd_pid);
5095 }
5096
5097 cmdline_parse_token_string_t cmd_gro_show_show =
5098         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5099                         cmd_show, "show");
5100 cmdline_parse_token_string_t cmd_gro_show_port =
5101         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5102                         cmd_port, "port");
5103 cmdline_parse_token_num_t cmd_gro_show_pid =
5104         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5105                         cmd_pid, UINT16);
5106 cmdline_parse_token_string_t cmd_gro_show_keyword =
5107         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5108                         cmd_keyword, "gro");
5109
5110 cmdline_parse_inst_t cmd_gro_show = {
5111         .f = cmd_gro_show_parsed,
5112         .data = NULL,
5113         .help_str = "show port <port_id> gro",
5114         .tokens = {
5115                 (void *)&cmd_gro_show_show,
5116                 (void *)&cmd_gro_show_port,
5117                 (void *)&cmd_gro_show_pid,
5118                 (void *)&cmd_gro_show_keyword,
5119                 NULL,
5120         },
5121 };
5122
5123 /* *** SET FLUSH CYCLES FOR GRO *** */
5124 struct cmd_gro_flush_result {
5125         cmdline_fixed_string_t cmd_set;
5126         cmdline_fixed_string_t cmd_keyword;
5127         cmdline_fixed_string_t cmd_flush;
5128         uint8_t cmd_cycles;
5129 };
5130
5131 static void
5132 cmd_gro_flush_parsed(void *parsed_result,
5133                 __rte_unused struct cmdline *cl,
5134                 __rte_unused void *data)
5135 {
5136         struct cmd_gro_flush_result *res;
5137
5138         res = parsed_result;
5139         if ((!strcmp(res->cmd_keyword, "gro")) &&
5140                         (!strcmp(res->cmd_flush, "flush")))
5141                 setup_gro_flush_cycles(res->cmd_cycles);
5142 }
5143
5144 cmdline_parse_token_string_t cmd_gro_flush_set =
5145         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5146                         cmd_set, "set");
5147 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5148         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5149                         cmd_keyword, "gro");
5150 cmdline_parse_token_string_t cmd_gro_flush_flush =
5151         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5152                         cmd_flush, "flush");
5153 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5154         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5155                         cmd_cycles, UINT8);
5156
5157 cmdline_parse_inst_t cmd_gro_flush = {
5158         .f = cmd_gro_flush_parsed,
5159         .data = NULL,
5160         .help_str = "set gro flush <cycles>",
5161         .tokens = {
5162                 (void *)&cmd_gro_flush_set,
5163                 (void *)&cmd_gro_flush_keyword,
5164                 (void *)&cmd_gro_flush_flush,
5165                 (void *)&cmd_gro_flush_cycles,
5166                 NULL,
5167         },
5168 };
5169
5170 /* *** ENABLE/DISABLE GSO *** */
5171 struct cmd_gso_enable_result {
5172         cmdline_fixed_string_t cmd_set;
5173         cmdline_fixed_string_t cmd_port;
5174         cmdline_fixed_string_t cmd_keyword;
5175         cmdline_fixed_string_t cmd_mode;
5176         portid_t cmd_pid;
5177 };
5178
5179 static void
5180 cmd_gso_enable_parsed(void *parsed_result,
5181                 __rte_unused struct cmdline *cl,
5182                 __rte_unused void *data)
5183 {
5184         struct cmd_gso_enable_result *res;
5185
5186         res = parsed_result;
5187         if (!strcmp(res->cmd_keyword, "gso"))
5188                 setup_gso(res->cmd_mode, res->cmd_pid);
5189 }
5190
5191 cmdline_parse_token_string_t cmd_gso_enable_set =
5192         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5193                         cmd_set, "set");
5194 cmdline_parse_token_string_t cmd_gso_enable_port =
5195         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5196                         cmd_port, "port");
5197 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5198         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5199                         cmd_keyword, "gso");
5200 cmdline_parse_token_string_t cmd_gso_enable_mode =
5201         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5202                         cmd_mode, "on#off");
5203 cmdline_parse_token_num_t cmd_gso_enable_pid =
5204         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5205                         cmd_pid, UINT16);
5206
5207 cmdline_parse_inst_t cmd_gso_enable = {
5208         .f = cmd_gso_enable_parsed,
5209         .data = NULL,
5210         .help_str = "set port <port_id> gso on|off",
5211         .tokens = {
5212                 (void *)&cmd_gso_enable_set,
5213                 (void *)&cmd_gso_enable_port,
5214                 (void *)&cmd_gso_enable_pid,
5215                 (void *)&cmd_gso_enable_keyword,
5216                 (void *)&cmd_gso_enable_mode,
5217                 NULL,
5218         },
5219 };
5220
5221 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5222 struct cmd_gso_size_result {
5223         cmdline_fixed_string_t cmd_set;
5224         cmdline_fixed_string_t cmd_keyword;
5225         cmdline_fixed_string_t cmd_segsz;
5226         uint16_t cmd_size;
5227 };
5228
5229 static void
5230 cmd_gso_size_parsed(void *parsed_result,
5231                        __rte_unused struct cmdline *cl,
5232                        __rte_unused void *data)
5233 {
5234         struct cmd_gso_size_result *res = parsed_result;
5235
5236         if (test_done == 0) {
5237                 printf("Before setting GSO segsz, please first"
5238                                 " stop forwarding\n");
5239                 return;
5240         }
5241
5242         if (!strcmp(res->cmd_keyword, "gso") &&
5243                         !strcmp(res->cmd_segsz, "segsz")) {
5244                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5245                         printf("gso_size should be larger than %zu."
5246                                         " Please input a legal value\n",
5247                                         RTE_GSO_SEG_SIZE_MIN);
5248                 else
5249                         gso_max_segment_size = res->cmd_size;
5250         }
5251 }
5252
5253 cmdline_parse_token_string_t cmd_gso_size_set =
5254         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5255                                 cmd_set, "set");
5256 cmdline_parse_token_string_t cmd_gso_size_keyword =
5257         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5258                                 cmd_keyword, "gso");
5259 cmdline_parse_token_string_t cmd_gso_size_segsz =
5260         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5261                                 cmd_segsz, "segsz");
5262 cmdline_parse_token_num_t cmd_gso_size_size =
5263         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5264                                 cmd_size, UINT16);
5265
5266 cmdline_parse_inst_t cmd_gso_size = {
5267         .f = cmd_gso_size_parsed,
5268         .data = NULL,
5269         .help_str = "set gso segsz <length>",
5270         .tokens = {
5271                 (void *)&cmd_gso_size_set,
5272                 (void *)&cmd_gso_size_keyword,
5273                 (void *)&cmd_gso_size_segsz,
5274                 (void *)&cmd_gso_size_size,
5275                 NULL,
5276         },
5277 };
5278
5279 /* *** SHOW GSO CONFIGURATION *** */
5280 struct cmd_gso_show_result {
5281         cmdline_fixed_string_t cmd_show;
5282         cmdline_fixed_string_t cmd_port;
5283         cmdline_fixed_string_t cmd_keyword;
5284         portid_t cmd_pid;
5285 };
5286
5287 static void
5288 cmd_gso_show_parsed(void *parsed_result,
5289                        __rte_unused struct cmdline *cl,
5290                        __rte_unused void *data)
5291 {
5292         struct cmd_gso_show_result *res = parsed_result;
5293
5294         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5295                 printf("invalid port id %u\n", res->cmd_pid);
5296                 return;
5297         }
5298         if (!strcmp(res->cmd_keyword, "gso")) {
5299                 if (gso_ports[res->cmd_pid].enable) {
5300                         printf("Max GSO'd packet size: %uB\n"
5301                                         "Supported GSO types: TCP/IPv4, "
5302                                         "UDP/IPv4, VxLAN with inner "
5303                                         "TCP/IPv4 packet, GRE with inner "
5304                                         "TCP/IPv4 packet\n",
5305                                         gso_max_segment_size);
5306                 } else
5307                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5308         }
5309 }
5310
5311 cmdline_parse_token_string_t cmd_gso_show_show =
5312 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5313                 cmd_show, "show");
5314 cmdline_parse_token_string_t cmd_gso_show_port =
5315 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5316                 cmd_port, "port");
5317 cmdline_parse_token_string_t cmd_gso_show_keyword =
5318         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5319                                 cmd_keyword, "gso");
5320 cmdline_parse_token_num_t cmd_gso_show_pid =
5321         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5322                                 cmd_pid, UINT16);
5323
5324 cmdline_parse_inst_t cmd_gso_show = {
5325         .f = cmd_gso_show_parsed,
5326         .data = NULL,
5327         .help_str = "show port <port_id> gso",
5328         .tokens = {
5329                 (void *)&cmd_gso_show_show,
5330                 (void *)&cmd_gso_show_port,
5331                 (void *)&cmd_gso_show_pid,
5332                 (void *)&cmd_gso_show_keyword,
5333                 NULL,
5334         },
5335 };
5336
5337 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5338 struct cmd_set_flush_rx {
5339         cmdline_fixed_string_t set;
5340         cmdline_fixed_string_t flush_rx;
5341         cmdline_fixed_string_t mode;
5342 };
5343
5344 static void
5345 cmd_set_flush_rx_parsed(void *parsed_result,
5346                 __rte_unused struct cmdline *cl,
5347                 __rte_unused void *data)
5348 {
5349         struct cmd_set_flush_rx *res = parsed_result;
5350         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5351 }
5352
5353 cmdline_parse_token_string_t cmd_setflushrx_set =
5354         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5355                         set, "set");
5356 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5357         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5358                         flush_rx, "flush_rx");
5359 cmdline_parse_token_string_t cmd_setflushrx_mode =
5360         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5361                         mode, "on#off");
5362
5363
5364 cmdline_parse_inst_t cmd_set_flush_rx = {
5365         .f = cmd_set_flush_rx_parsed,
5366         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5367         .data = NULL,
5368         .tokens = {
5369                 (void *)&cmd_setflushrx_set,
5370                 (void *)&cmd_setflushrx_flush_rx,
5371                 (void *)&cmd_setflushrx_mode,
5372                 NULL,
5373         },
5374 };
5375
5376 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5377 struct cmd_set_link_check {
5378         cmdline_fixed_string_t set;
5379         cmdline_fixed_string_t link_check;
5380         cmdline_fixed_string_t mode;
5381 };
5382
5383 static void
5384 cmd_set_link_check_parsed(void *parsed_result,
5385                 __rte_unused struct cmdline *cl,
5386                 __rte_unused void *data)
5387 {
5388         struct cmd_set_link_check *res = parsed_result;
5389         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5390 }
5391
5392 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5393         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5394                         set, "set");
5395 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5396         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5397                         link_check, "link_check");
5398 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5399         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5400                         mode, "on#off");
5401
5402
5403 cmdline_parse_inst_t cmd_set_link_check = {
5404         .f = cmd_set_link_check_parsed,
5405         .help_str = "set link_check on|off: Enable/Disable link status check "
5406                     "when starting/stopping a port",
5407         .data = NULL,
5408         .tokens = {
5409                 (void *)&cmd_setlinkcheck_set,
5410                 (void *)&cmd_setlinkcheck_link_check,
5411                 (void *)&cmd_setlinkcheck_mode,
5412                 NULL,
5413         },
5414 };
5415
5416 /* *** SET NIC BYPASS MODE *** */
5417 struct cmd_set_bypass_mode_result {
5418         cmdline_fixed_string_t set;
5419         cmdline_fixed_string_t bypass;
5420         cmdline_fixed_string_t mode;
5421         cmdline_fixed_string_t value;
5422         portid_t port_id;
5423 };
5424
5425 static void
5426 cmd_set_bypass_mode_parsed(void *parsed_result,
5427                 __rte_unused struct cmdline *cl,
5428                 __rte_unused void *data)
5429 {
5430         struct cmd_set_bypass_mode_result *res = parsed_result;
5431         portid_t port_id = res->port_id;
5432         int32_t rc = -EINVAL;
5433
5434 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5435         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5436
5437         if (!strcmp(res->value, "bypass"))
5438                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5439         else if (!strcmp(res->value, "isolate"))
5440                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5441         else
5442                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5443
5444         /* Set the bypass mode for the relevant port. */
5445         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5446 #endif
5447         if (rc != 0)
5448                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5449 }
5450
5451 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5452         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5453                         set, "set");
5454 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5455         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5456                         bypass, "bypass");
5457 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5458         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5459                         mode, "mode");
5460 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5461         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5462                         value, "normal#bypass#isolate");
5463 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5464         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5465                                 port_id, UINT16);
5466
5467 cmdline_parse_inst_t cmd_set_bypass_mode = {
5468         .f = cmd_set_bypass_mode_parsed,
5469         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5470                     "Set the NIC bypass mode for port_id",
5471         .data = NULL,
5472         .tokens = {
5473                 (void *)&cmd_setbypass_mode_set,
5474                 (void *)&cmd_setbypass_mode_bypass,
5475                 (void *)&cmd_setbypass_mode_mode,
5476                 (void *)&cmd_setbypass_mode_value,
5477                 (void *)&cmd_setbypass_mode_port,
5478                 NULL,
5479         },
5480 };
5481
5482 /* *** SET NIC BYPASS EVENT *** */
5483 struct cmd_set_bypass_event_result {
5484         cmdline_fixed_string_t set;
5485         cmdline_fixed_string_t bypass;
5486         cmdline_fixed_string_t event;
5487         cmdline_fixed_string_t event_value;
5488         cmdline_fixed_string_t mode;
5489         cmdline_fixed_string_t mode_value;
5490         portid_t port_id;
5491 };
5492
5493 static void
5494 cmd_set_bypass_event_parsed(void *parsed_result,
5495                 __rte_unused struct cmdline *cl,
5496                 __rte_unused void *data)
5497 {
5498         int32_t rc = -EINVAL;
5499         struct cmd_set_bypass_event_result *res = parsed_result;
5500         portid_t port_id = res->port_id;
5501
5502 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5503         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5504         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5505
5506         if (!strcmp(res->event_value, "timeout"))
5507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5508         else if (!strcmp(res->event_value, "os_on"))
5509                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5510         else if (!strcmp(res->event_value, "os_off"))
5511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5512         else if (!strcmp(res->event_value, "power_on"))
5513                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5514         else if (!strcmp(res->event_value, "power_off"))
5515                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5516         else
5517                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5518
5519         if (!strcmp(res->mode_value, "bypass"))
5520                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5521         else if (!strcmp(res->mode_value, "isolate"))
5522                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5523         else
5524                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5525
5526         /* Set the watchdog timeout. */
5527         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5528
5529                 rc = -EINVAL;
5530                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5531                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5532                                                            bypass_timeout);
5533                 }
5534                 if (rc != 0) {
5535                         printf("Failed to set timeout value %u "
5536                         "for port %d, errto code: %d.\n",
5537                         bypass_timeout, port_id, rc);
5538                 }
5539         }
5540
5541         /* Set the bypass event to transition to bypass mode. */
5542         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5543                                               bypass_mode);
5544 #endif
5545
5546         if (rc != 0)
5547                 printf("\t Failed to set bypass event for port = %d.\n",
5548                        port_id);
5549 }
5550
5551 cmdline_parse_token_string_t cmd_setbypass_event_set =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5553                         set, "set");
5554 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5556                         bypass, "bypass");
5557 cmdline_parse_token_string_t cmd_setbypass_event_event =
5558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5559                         event, "event");
5560 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5561         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5562                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5563 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5564         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5565                         mode, "mode");
5566 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5567         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5568                         mode_value, "normal#bypass#isolate");
5569 cmdline_parse_token_num_t cmd_setbypass_event_port =
5570         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5571                                 port_id, UINT16);
5572
5573 cmdline_parse_inst_t cmd_set_bypass_event = {
5574         .f = cmd_set_bypass_event_parsed,
5575         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5576                 "power_off mode normal|bypass|isolate <port_id>: "
5577                 "Set the NIC bypass event mode for port_id",
5578         .data = NULL,
5579         .tokens = {
5580                 (void *)&cmd_setbypass_event_set,
5581                 (void *)&cmd_setbypass_event_bypass,
5582                 (void *)&cmd_setbypass_event_event,
5583                 (void *)&cmd_setbypass_event_event_value,
5584                 (void *)&cmd_setbypass_event_mode,
5585                 (void *)&cmd_setbypass_event_mode_value,
5586                 (void *)&cmd_setbypass_event_port,
5587                 NULL,
5588         },
5589 };
5590
5591
5592 /* *** SET NIC BYPASS TIMEOUT *** */
5593 struct cmd_set_bypass_timeout_result {
5594         cmdline_fixed_string_t set;
5595         cmdline_fixed_string_t bypass;
5596         cmdline_fixed_string_t timeout;
5597         cmdline_fixed_string_t value;
5598 };
5599
5600 static void
5601 cmd_set_bypass_timeout_parsed(void *parsed_result,
5602                 __rte_unused struct cmdline *cl,
5603                 __rte_unused void *data)
5604 {
5605         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5606
5607 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5608         if (!strcmp(res->value, "1.5"))
5609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5610         else if (!strcmp(res->value, "2"))
5611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5612         else if (!strcmp(res->value, "3"))
5613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5614         else if (!strcmp(res->value, "4"))
5615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5616         else if (!strcmp(res->value, "8"))
5617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5618         else if (!strcmp(res->value, "16"))
5619                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5620         else if (!strcmp(res->value, "32"))
5621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5622         else
5623                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5624 #endif
5625 }
5626
5627 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5628         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5629                         set, "set");
5630 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5631         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5632                         bypass, "bypass");
5633 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5634         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5635                         timeout, "timeout");
5636 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5637         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5638                         value, "0#1.5#2#3#4#8#16#32");
5639
5640 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5641         .f = cmd_set_bypass_timeout_parsed,
5642         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5643                 "Set the NIC bypass watchdog timeout in seconds",
5644         .data = NULL,
5645         .tokens = {
5646                 (void *)&cmd_setbypass_timeout_set,
5647                 (void *)&cmd_setbypass_timeout_bypass,
5648                 (void *)&cmd_setbypass_timeout_timeout,
5649                 (void *)&cmd_setbypass_timeout_value,
5650                 NULL,
5651         },
5652 };
5653
5654 /* *** SHOW NIC BYPASS MODE *** */
5655 struct cmd_show_bypass_config_result {
5656         cmdline_fixed_string_t show;
5657         cmdline_fixed_string_t bypass;
5658         cmdline_fixed_string_t config;
5659         portid_t port_id;
5660 };
5661
5662 static void
5663 cmd_show_bypass_config_parsed(void *parsed_result,
5664                 __rte_unused struct cmdline *cl,
5665                 __rte_unused void *data)
5666 {
5667         struct cmd_show_bypass_config_result *res = parsed_result;
5668         portid_t port_id = res->port_id;
5669         int rc = -EINVAL;
5670 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5671         uint32_t event_mode;
5672         uint32_t bypass_mode;
5673         uint32_t timeout = bypass_timeout;
5674         unsigned int i;
5675
5676         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5677                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5678         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5679                 {"UNKNOWN", "normal", "bypass", "isolate"};
5680         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5681                 "NONE",
5682                 "OS/board on",
5683                 "power supply on",
5684                 "OS/board off",
5685                 "power supply off",
5686                 "timeout"};
5687
5688         /* Display the bypass mode.*/
5689         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5690                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5691                 return;
5692         }
5693         else {
5694                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5695                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5696
5697                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5698         }
5699
5700         /* Display the bypass timeout.*/
5701         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5702                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5703
5704         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5705
5706         /* Display the bypass events and associated modes. */
5707         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5708
5709                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5710                         printf("\tFailed to get bypass mode for event = %s\n",
5711                                 events[i]);
5712                 } else {
5713                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5714                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5715
5716                         printf("\tbypass event: %-16s = %s\n", events[i],
5717                                 modes[event_mode]);
5718                 }
5719         }
5720 #endif
5721         if (rc != 0)
5722                 printf("\tFailed to get bypass configuration for port = %d\n",
5723                        port_id);
5724 }
5725
5726 cmdline_parse_token_string_t cmd_showbypass_config_show =
5727         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5728                         show, "show");
5729 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5730         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5731                         bypass, "bypass");
5732 cmdline_parse_token_string_t cmd_showbypass_config_config =
5733         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5734                         config, "config");
5735 cmdline_parse_token_num_t cmd_showbypass_config_port =
5736         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5737                                 port_id, UINT16);
5738
5739 cmdline_parse_inst_t cmd_show_bypass_config = {
5740         .f = cmd_show_bypass_config_parsed,
5741         .help_str = "show bypass config <port_id>: "
5742                     "Show the NIC bypass config for port_id",
5743         .data = NULL,
5744         .tokens = {
5745                 (void *)&cmd_showbypass_config_show,
5746                 (void *)&cmd_showbypass_config_bypass,
5747                 (void *)&cmd_showbypass_config_config,
5748                 (void *)&cmd_showbypass_config_port,
5749                 NULL,
5750         },
5751 };
5752
5753 #ifdef RTE_NET_BOND
5754 /* *** SET BONDING MODE *** */
5755 struct cmd_set_bonding_mode_result {
5756         cmdline_fixed_string_t set;
5757         cmdline_fixed_string_t bonding;
5758         cmdline_fixed_string_t mode;
5759         uint8_t value;
5760         portid_t port_id;
5761 };
5762
5763 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5764                 __rte_unused  struct cmdline *cl,
5765                 __rte_unused void *data)
5766 {
5767         struct cmd_set_bonding_mode_result *res = parsed_result;
5768         portid_t port_id = res->port_id;
5769
5770         /* Set the bonding mode for the relevant port. */
5771         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5772                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5773 }
5774
5775 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5776 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5777                 set, "set");
5778 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5779 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5780                 bonding, "bonding");
5781 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5783                 mode, "mode");
5784 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5785 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5786                 value, UINT8);
5787 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5788 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5789                 port_id, UINT16);
5790
5791 cmdline_parse_inst_t cmd_set_bonding_mode = {
5792                 .f = cmd_set_bonding_mode_parsed,
5793                 .help_str = "set bonding mode <mode_value> <port_id>: "
5794                         "Set the bonding mode for port_id",
5795                 .data = NULL,
5796                 .tokens = {
5797                                 (void *) &cmd_setbonding_mode_set,
5798                                 (void *) &cmd_setbonding_mode_bonding,
5799                                 (void *) &cmd_setbonding_mode_mode,
5800                                 (void *) &cmd_setbonding_mode_value,
5801                                 (void *) &cmd_setbonding_mode_port,
5802                                 NULL
5803                 }
5804 };
5805
5806 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5807 struct cmd_set_bonding_lacp_dedicated_queues_result {
5808         cmdline_fixed_string_t set;
5809         cmdline_fixed_string_t bonding;
5810         cmdline_fixed_string_t lacp;
5811         cmdline_fixed_string_t dedicated_queues;
5812         portid_t port_id;
5813         cmdline_fixed_string_t mode;
5814 };
5815
5816 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5817                 __rte_unused  struct cmdline *cl,
5818                 __rte_unused void *data)
5819 {
5820         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5821         portid_t port_id = res->port_id;
5822         struct rte_port *port;
5823
5824         port = &ports[port_id];
5825
5826         /** Check if the port is not started **/
5827         if (port->port_status != RTE_PORT_STOPPED) {
5828                 printf("Please stop port %d first\n", port_id);
5829                 return;
5830         }
5831
5832         if (!strcmp(res->mode, "enable")) {
5833                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5834                         printf("Dedicate queues for LACP control packets"
5835                                         " enabled\n");
5836                 else
5837                         printf("Enabling dedicate queues for LACP control "
5838                                         "packets on port %d failed\n", port_id);
5839         } else if (!strcmp(res->mode, "disable")) {
5840                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5841                         printf("Dedicated queues for LACP control packets "
5842                                         "disabled\n");
5843                 else
5844                         printf("Disabling dedicated queues for LACP control "
5845                                         "traffic on port %d failed\n", port_id);
5846         }
5847 }
5848
5849 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5851                 set, "set");
5852 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5854                 bonding, "bonding");
5855 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5857                 lacp, "lacp");
5858 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5859 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5860                 dedicated_queues, "dedicated_queues");
5861 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5862 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5863                 port_id, UINT16);
5864 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5865 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5866                 mode, "enable#disable");
5867
5868 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5869                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5870                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5871                         "enable|disable: "
5872                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5873                 .data = NULL,
5874                 .tokens = {
5875                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5876                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5877                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5878                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5879                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5880                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5881                         NULL
5882                 }
5883 };
5884
5885 /* *** SET BALANCE XMIT POLICY *** */
5886 struct cmd_set_bonding_balance_xmit_policy_result {
5887         cmdline_fixed_string_t set;
5888         cmdline_fixed_string_t bonding;
5889         cmdline_fixed_string_t balance_xmit_policy;
5890         portid_t port_id;
5891         cmdline_fixed_string_t policy;
5892 };
5893
5894 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5895                 __rte_unused  struct cmdline *cl,
5896                 __rte_unused void *data)
5897 {
5898         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5899         portid_t port_id = res->port_id;
5900         uint8_t policy;
5901
5902         if (!strcmp(res->policy, "l2")) {
5903                 policy = BALANCE_XMIT_POLICY_LAYER2;
5904         } else if (!strcmp(res->policy, "l23")) {
5905                 policy = BALANCE_XMIT_POLICY_LAYER23;
5906         } else if (!strcmp(res->policy, "l34")) {
5907                 policy = BALANCE_XMIT_POLICY_LAYER34;
5908         } else {
5909                 printf("\t Invalid xmit policy selection");
5910                 return;
5911         }
5912
5913         /* Set the bonding mode for the relevant port. */
5914         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5915                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5916                                 port_id);
5917         }
5918 }
5919
5920 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5922                 set, "set");
5923 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5925                 bonding, "bonding");
5926 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5928                 balance_xmit_policy, "balance_xmit_policy");
5929 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5930 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5931                 port_id, UINT16);
5932 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5933 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5934                 policy, "l2#l23#l34");
5935
5936 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5937                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5938                 .help_str = "set bonding balance_xmit_policy <port_id> "
5939                         "l2|l23|l34: "
5940                         "Set the bonding balance_xmit_policy for port_id",
5941                 .data = NULL,
5942                 .tokens = {
5943                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5944                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5945                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5946                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5947                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5948                                 NULL
5949                 }
5950 };
5951
5952 /* *** SHOW NIC BONDING CONFIGURATION *** */
5953 struct cmd_show_bonding_config_result {
5954         cmdline_fixed_string_t show;
5955         cmdline_fixed_string_t bonding;
5956         cmdline_fixed_string_t config;
5957         portid_t port_id;
5958 };
5959
5960 static void cmd_show_bonding_config_parsed(void *parsed_result,
5961                 __rte_unused  struct cmdline *cl,
5962                 __rte_unused void *data)
5963 {
5964         struct cmd_show_bonding_config_result *res = parsed_result;
5965         int bonding_mode, agg_mode;
5966         portid_t slaves[RTE_MAX_ETHPORTS];
5967         int num_slaves, num_active_slaves;
5968         int primary_id;
5969         int i;
5970         portid_t port_id = res->port_id;
5971
5972         /* Display the bonding mode.*/
5973         bonding_mode = rte_eth_bond_mode_get(port_id);
5974         if (bonding_mode < 0) {
5975                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5976                 return;
5977         } else
5978                 printf("\tBonding mode: %d\n", bonding_mode);
5979
5980         if (bonding_mode == BONDING_MODE_BALANCE) {
5981                 int balance_xmit_policy;
5982
5983                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5984                 if (balance_xmit_policy < 0) {
5985                         printf("\tFailed to get balance xmit policy for port = %d\n",
5986                                         port_id);
5987                         return;
5988                 } else {
5989                         printf("\tBalance Xmit Policy: ");
5990
5991                         switch (balance_xmit_policy) {
5992                         case BALANCE_XMIT_POLICY_LAYER2:
5993                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5994                                 break;
5995                         case BALANCE_XMIT_POLICY_LAYER23:
5996                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5997                                 break;
5998                         case BALANCE_XMIT_POLICY_LAYER34:
5999                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6000                                 break;
6001                         }
6002                         printf("\n");
6003                 }
6004         }
6005
6006         if (bonding_mode == BONDING_MODE_8023AD) {
6007                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6008                 printf("\tIEEE802.3AD Aggregator Mode: ");
6009                 switch (agg_mode) {
6010                 case AGG_BANDWIDTH:
6011                         printf("bandwidth");
6012                         break;
6013                 case AGG_STABLE:
6014                         printf("stable");
6015                         break;
6016                 case AGG_COUNT:
6017                         printf("count");
6018                         break;
6019                 }
6020                 printf("\n");
6021         }
6022
6023         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6024
6025         if (num_slaves < 0) {
6026                 printf("\tFailed to get slave list for port = %d\n", port_id);
6027                 return;
6028         }
6029         if (num_slaves > 0) {
6030                 printf("\tSlaves (%d): [", num_slaves);
6031                 for (i = 0; i < num_slaves - 1; i++)
6032                         printf("%d ", slaves[i]);
6033
6034                 printf("%d]\n", slaves[num_slaves - 1]);
6035         } else {
6036                 printf("\tSlaves: []\n");
6037
6038         }
6039
6040         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6041                         RTE_MAX_ETHPORTS);
6042
6043         if (num_active_slaves < 0) {
6044                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6045                 return;
6046         }
6047         if (num_active_slaves > 0) {
6048                 printf("\tActive Slaves (%d): [", num_active_slaves);
6049                 for (i = 0; i < num_active_slaves - 1; i++)
6050                         printf("%d ", slaves[i]);
6051
6052                 printf("%d]\n", slaves[num_active_slaves - 1]);
6053
6054         } else {
6055                 printf("\tActive Slaves: []\n");
6056
6057         }
6058
6059         primary_id = rte_eth_bond_primary_get(port_id);
6060         if (primary_id < 0) {
6061                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6062                 return;
6063         } else
6064                 printf("\tPrimary: [%d]\n", primary_id);
6065
6066 }
6067
6068 cmdline_parse_token_string_t cmd_showbonding_config_show =
6069 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6070                 show, "show");
6071 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6072 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6073                 bonding, "bonding");
6074 cmdline_parse_token_string_t cmd_showbonding_config_config =
6075 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6076                 config, "config");
6077 cmdline_parse_token_num_t cmd_showbonding_config_port =
6078 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6079                 port_id, UINT16);
6080
6081 cmdline_parse_inst_t cmd_show_bonding_config = {
6082                 .f = cmd_show_bonding_config_parsed,
6083                 .help_str = "show bonding config <port_id>: "
6084                         "Show the bonding config for port_id",
6085                 .data = NULL,
6086                 .tokens = {
6087                                 (void *)&cmd_showbonding_config_show,
6088                                 (void *)&cmd_showbonding_config_bonding,
6089                                 (void *)&cmd_showbonding_config_config,
6090                                 (void *)&cmd_showbonding_config_port,
6091                                 NULL
6092                 }
6093 };
6094
6095 /* *** SET BONDING PRIMARY *** */
6096 struct cmd_set_bonding_primary_result {
6097         cmdline_fixed_string_t set;
6098         cmdline_fixed_string_t bonding;
6099         cmdline_fixed_string_t primary;
6100         portid_t slave_id;
6101         portid_t port_id;
6102 };
6103
6104 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6105                 __rte_unused  struct cmdline *cl,
6106                 __rte_unused void *data)
6107 {
6108         struct cmd_set_bonding_primary_result *res = parsed_result;
6109         portid_t master_port_id = res->port_id;
6110         portid_t slave_port_id = res->slave_id;
6111
6112         /* Set the primary slave for a bonded device. */
6113         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6114                 printf("\t Failed to set primary slave for port = %d.\n",
6115                                 master_port_id);
6116                 return;
6117         }
6118         init_port_config();
6119 }
6120
6121 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6123                 set, "set");
6124 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6125 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6126                 bonding, "bonding");
6127 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6128 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6129                 primary, "primary");
6130 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6131 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6132                 slave_id, UINT16);
6133 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6134 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6135                 port_id, UINT16);
6136
6137 cmdline_parse_inst_t cmd_set_bonding_primary = {
6138                 .f = cmd_set_bonding_primary_parsed,
6139                 .help_str = "set bonding primary <slave_id> <port_id>: "
6140                         "Set the primary slave for port_id",
6141                 .data = NULL,
6142                 .tokens = {
6143                                 (void *)&cmd_setbonding_primary_set,
6144                                 (void *)&cmd_setbonding_primary_bonding,
6145                                 (void *)&cmd_setbonding_primary_primary,
6146                                 (void *)&cmd_setbonding_primary_slave,
6147                                 (void *)&cmd_setbonding_primary_port,
6148                                 NULL
6149                 }
6150 };
6151
6152 /* *** ADD SLAVE *** */
6153 struct cmd_add_bonding_slave_result {
6154         cmdline_fixed_string_t add;
6155         cmdline_fixed_string_t bonding;
6156         cmdline_fixed_string_t slave;
6157         portid_t slave_id;
6158         portid_t port_id;
6159 };
6160
6161 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6162                 __rte_unused  struct cmdline *cl,
6163                 __rte_unused void *data)
6164 {
6165         struct cmd_add_bonding_slave_result *res = parsed_result;
6166         portid_t master_port_id = res->port_id;
6167         portid_t slave_port_id = res->slave_id;
6168
6169         /* add the slave for a bonded device. */
6170         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6171                 printf("\t Failed to add slave %d to master port = %d.\n",
6172                                 slave_port_id, master_port_id);
6173                 return;
6174         }
6175         init_port_config();
6176         set_port_slave_flag(slave_port_id);
6177 }
6178
6179 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6180 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6181                 add, "add");
6182 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6183 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6184                 bonding, "bonding");
6185 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6186 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6187                 slave, "slave");
6188 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6189 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6190                 slave_id, UINT16);
6191 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6192 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6193                 port_id, UINT16);
6194
6195 cmdline_parse_inst_t cmd_add_bonding_slave = {
6196                 .f = cmd_add_bonding_slave_parsed,
6197                 .help_str = "add bonding slave <slave_id> <port_id>: "
6198                         "Add a slave device to a bonded device",
6199                 .data = NULL,
6200                 .tokens = {
6201                                 (void *)&cmd_addbonding_slave_add,
6202                                 (void *)&cmd_addbonding_slave_bonding,
6203                                 (void *)&cmd_addbonding_slave_slave,
6204                                 (void *)&cmd_addbonding_slave_slaveid,
6205                                 (void *)&cmd_addbonding_slave_port,
6206                                 NULL
6207                 }
6208 };
6209
6210 /* *** REMOVE SLAVE *** */
6211 struct cmd_remove_bonding_slave_result {
6212         cmdline_fixed_string_t remove;
6213         cmdline_fixed_string_t bonding;
6214         cmdline_fixed_string_t slave;
6215         portid_t slave_id;
6216         portid_t port_id;
6217 };
6218
6219 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6220                 __rte_unused  struct cmdline *cl,
6221                 __rte_unused void *data)
6222 {
6223         struct cmd_remove_bonding_slave_result *res = parsed_result;
6224         portid_t master_port_id = res->port_id;
6225         portid_t slave_port_id = res->slave_id;
6226
6227         /* remove the slave from a bonded device. */
6228         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6229                 printf("\t Failed to remove slave %d from master port = %d.\n",
6230                                 slave_port_id, master_port_id);
6231                 return;
6232         }
6233         init_port_config();
6234         clear_port_slave_flag(slave_port_id);
6235 }
6236
6237 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6238                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6239                                 remove, "remove");
6240 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6241                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6242                                 bonding, "bonding");
6243 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6244                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6245                                 slave, "slave");
6246 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6247                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6248                                 slave_id, UINT16);
6249 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6250                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6251                                 port_id, UINT16);
6252
6253 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6254                 .f = cmd_remove_bonding_slave_parsed,
6255                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6256                         "Remove a slave device from a bonded device",
6257                 .data = NULL,
6258                 .tokens = {
6259                                 (void *)&cmd_removebonding_slave_remove,
6260                                 (void *)&cmd_removebonding_slave_bonding,
6261                                 (void *)&cmd_removebonding_slave_slave,
6262                                 (void *)&cmd_removebonding_slave_slaveid,
6263                                 (void *)&cmd_removebonding_slave_port,
6264                                 NULL
6265                 }
6266 };
6267
6268 /* *** CREATE BONDED DEVICE *** */
6269 struct cmd_create_bonded_device_result {
6270         cmdline_fixed_string_t create;
6271         cmdline_fixed_string_t bonded;
6272         cmdline_fixed_string_t device;
6273         uint8_t mode;
6274         uint8_t socket;
6275 };
6276
6277 static int bond_dev_num = 0;
6278
6279 static void cmd_create_bonded_device_parsed(void *parsed_result,
6280                 __rte_unused  struct cmdline *cl,
6281                 __rte_unused void *data)
6282 {
6283         struct cmd_create_bonded_device_result *res = parsed_result;
6284         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6285         int port_id;
6286         int ret;
6287
6288         if (test_done == 0) {
6289                 printf("Please stop forwarding first\n");
6290                 return;
6291         }
6292
6293         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6294                         bond_dev_num++);
6295
6296         /* Create a new bonded device. */
6297         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6298         if (port_id < 0) {
6299                 printf("\t Failed to create bonded device.\n");
6300                 return;
6301         } else {
6302                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6303                                 port_id);
6304
6305                 /* Update number of ports */
6306                 nb_ports = rte_eth_dev_count_avail();
6307                 reconfig(port_id, res->socket);
6308                 ret = rte_eth_promiscuous_enable(port_id);
6309                 if (ret != 0)
6310                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6311                                 port_id, rte_strerror(-ret));
6312
6313                 ports[port_id].need_setup = 0;
6314                 ports[port_id].port_status = RTE_PORT_STOPPED;
6315         }
6316
6317 }
6318
6319 cmdline_parse_token_string_t cmd_createbonded_device_create =
6320                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6321                                 create, "create");
6322 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6323                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6324                                 bonded, "bonded");
6325 cmdline_parse_token_string_t cmd_createbonded_device_device =
6326                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6327                                 device, "device");
6328 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6329                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6330                                 mode, UINT8);
6331 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6332                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6333                                 socket, UINT8);
6334
6335 cmdline_parse_inst_t cmd_create_bonded_device = {
6336                 .f = cmd_create_bonded_device_parsed,
6337                 .help_str = "create bonded device <mode> <socket>: "
6338                         "Create a new bonded device with specific bonding mode and socket",
6339                 .data = NULL,
6340                 .tokens = {
6341                                 (void *)&cmd_createbonded_device_create,
6342                                 (void *)&cmd_createbonded_device_bonded,
6343                                 (void *)&cmd_createbonded_device_device,
6344                                 (void *)&cmd_createbonded_device_mode,
6345                                 (void *)&cmd_createbonded_device_socket,
6346                                 NULL
6347                 }
6348 };
6349
6350 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6351 struct cmd_set_bond_mac_addr_result {
6352         cmdline_fixed_string_t set;
6353         cmdline_fixed_string_t bonding;
6354         cmdline_fixed_string_t mac_addr;
6355         uint16_t port_num;
6356         struct rte_ether_addr address;
6357 };
6358
6359 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6360                 __rte_unused  struct cmdline *cl,
6361                 __rte_unused void *data)
6362 {
6363         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6364         int ret;
6365
6366         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6367                 return;
6368
6369         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6370
6371         /* check the return value and print it if is < 0 */
6372         if (ret < 0)
6373                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6374 }
6375
6376 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6377                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6378 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6379                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6380                                 "bonding");
6381 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6382                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6383                                 "mac_addr");
6384 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6385                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6386                                 port_num, UINT16);
6387 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6388                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6389
6390 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6391                 .f = cmd_set_bond_mac_addr_parsed,
6392                 .data = (void *) 0,
6393                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6394                 .tokens = {
6395                                 (void *)&cmd_set_bond_mac_addr_set,
6396                                 (void *)&cmd_set_bond_mac_addr_bonding,
6397                                 (void *)&cmd_set_bond_mac_addr_mac,
6398                                 (void *)&cmd_set_bond_mac_addr_portnum,
6399                                 (void *)&cmd_set_bond_mac_addr_addr,
6400                                 NULL
6401                 }
6402 };
6403
6404
6405 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6406 struct cmd_set_bond_mon_period_result {
6407         cmdline_fixed_string_t set;
6408         cmdline_fixed_string_t bonding;
6409         cmdline_fixed_string_t mon_period;
6410         uint16_t port_num;
6411         uint32_t period_ms;
6412 };
6413
6414 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6415                 __rte_unused  struct cmdline *cl,
6416                 __rte_unused void *data)
6417 {
6418         struct cmd_set_bond_mon_period_result *res = parsed_result;
6419         int ret;
6420
6421         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6422
6423         /* check the return value and print it if is < 0 */
6424         if (ret < 0)
6425                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6426 }
6427
6428 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6429                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6430                                 set, "set");
6431 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6432                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6433                                 bonding, "bonding");
6434 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6435                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6436                                 mon_period,     "mon_period");
6437 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6438                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6439                                 port_num, UINT16);
6440 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6441                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6442                                 period_ms, UINT32);
6443
6444 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6445                 .f = cmd_set_bond_mon_period_parsed,
6446                 .data = (void *) 0,
6447                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6448                 .tokens = {
6449                                 (void *)&cmd_set_bond_mon_period_set,
6450                                 (void *)&cmd_set_bond_mon_period_bonding,
6451                                 (void *)&cmd_set_bond_mon_period_mon_period,
6452                                 (void *)&cmd_set_bond_mon_period_portnum,
6453                                 (void *)&cmd_set_bond_mon_period_period_ms,
6454                                 NULL
6455                 }
6456 };
6457
6458
6459
6460 struct cmd_set_bonding_agg_mode_policy_result {
6461         cmdline_fixed_string_t set;
6462         cmdline_fixed_string_t bonding;
6463         cmdline_fixed_string_t agg_mode;
6464         uint16_t port_num;
6465         cmdline_fixed_string_t policy;
6466 };
6467
6468
6469 static void
6470 cmd_set_bonding_agg_mode(void *parsed_result,
6471                 __rte_unused struct cmdline *cl,
6472                 __rte_unused void *data)
6473 {
6474         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6475         uint8_t policy = AGG_BANDWIDTH;
6476
6477         if (!strcmp(res->policy, "bandwidth"))
6478                 policy = AGG_BANDWIDTH;
6479         else if (!strcmp(res->policy, "stable"))
6480                 policy = AGG_STABLE;
6481         else if (!strcmp(res->policy, "count"))
6482                 policy = AGG_COUNT;
6483
6484         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6485 }
6486
6487
6488 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6489         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6490                                 set, "set");
6491 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6492         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6493                                 bonding, "bonding");
6494
6495 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6497                                 agg_mode, "agg_mode");
6498
6499 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6500         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6501                                 port_num, UINT16);
6502
6503 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6504         TOKEN_STRING_INITIALIZER(
6505                         struct cmd_set_bonding_balance_xmit_policy_result,
6506                 policy, "stable#bandwidth#count");
6507
6508 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6509         .f = cmd_set_bonding_agg_mode,
6510         .data = (void *) 0,
6511         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6512         .tokens = {
6513                         (void *)&cmd_set_bonding_agg_mode_set,
6514                         (void *)&cmd_set_bonding_agg_mode_bonding,
6515                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6516                         (void *)&cmd_set_bonding_agg_mode_portnum,
6517                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6518                         NULL
6519                 }
6520 };
6521
6522
6523 #endif /* RTE_NET_BOND */
6524
6525 /* *** SET FORWARDING MODE *** */
6526 struct cmd_set_fwd_mode_result {
6527         cmdline_fixed_string_t set;
6528         cmdline_fixed_string_t fwd;
6529         cmdline_fixed_string_t mode;
6530 };
6531
6532 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6533                                     __rte_unused struct cmdline *cl,
6534                                     __rte_unused void *data)
6535 {
6536         struct cmd_set_fwd_mode_result *res = parsed_result;
6537
6538         retry_enabled = 0;
6539         set_pkt_forwarding_mode(res->mode);
6540 }
6541
6542 cmdline_parse_token_string_t cmd_setfwd_set =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6544 cmdline_parse_token_string_t cmd_setfwd_fwd =
6545         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6546 cmdline_parse_token_string_t cmd_setfwd_mode =
6547         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6548                 "" /* defined at init */);
6549
6550 cmdline_parse_inst_t cmd_set_fwd_mode = {
6551         .f = cmd_set_fwd_mode_parsed,
6552         .data = NULL,
6553         .help_str = NULL, /* defined at init */
6554         .tokens = {
6555                 (void *)&cmd_setfwd_set,
6556                 (void *)&cmd_setfwd_fwd,
6557                 (void *)&cmd_setfwd_mode,
6558                 NULL,
6559         },
6560 };
6561
6562 static void cmd_set_fwd_mode_init(void)
6563 {
6564         char *modes, *c;
6565         static char token[128];
6566         static char help[256];
6567         cmdline_parse_token_string_t *token_struct;
6568
6569         modes = list_pkt_forwarding_modes();
6570         snprintf(help, sizeof(help), "set fwd %s: "
6571                 "Set packet forwarding mode", modes);
6572         cmd_set_fwd_mode.help_str = help;
6573
6574         /* string token separator is # */
6575         for (c = token; *modes != '\0'; modes++)
6576                 if (*modes == '|')
6577                         *c++ = '#';
6578                 else
6579                         *c++ = *modes;
6580         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6581         token_struct->string_data.str = token;
6582 }
6583
6584 /* *** SET RETRY FORWARDING MODE *** */
6585 struct cmd_set_fwd_retry_mode_result {
6586         cmdline_fixed_string_t set;
6587         cmdline_fixed_string_t fwd;
6588         cmdline_fixed_string_t mode;
6589         cmdline_fixed_string_t retry;
6590 };
6591
6592 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6593                             __rte_unused struct cmdline *cl,
6594                             __rte_unused void *data)
6595 {
6596         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6597
6598         retry_enabled = 1;
6599         set_pkt_forwarding_mode(res->mode);
6600 }
6601
6602 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6603         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6604                         set, "set");
6605 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6606         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6607                         fwd, "fwd");
6608 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6609         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6610                         mode,
6611                 "" /* defined at init */);
6612 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6613         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6614                         retry, "retry");
6615
6616 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6617         .f = cmd_set_fwd_retry_mode_parsed,
6618         .data = NULL,
6619         .help_str = NULL, /* defined at init */
6620         .tokens = {
6621                 (void *)&cmd_setfwd_retry_set,
6622                 (void *)&cmd_setfwd_retry_fwd,
6623                 (void *)&cmd_setfwd_retry_mode,
6624                 (void *)&cmd_setfwd_retry_retry,
6625                 NULL,
6626         },
6627 };
6628
6629 static void cmd_set_fwd_retry_mode_init(void)
6630 {
6631         char *modes, *c;
6632         static char token[128];
6633         static char help[256];
6634         cmdline_parse_token_string_t *token_struct;
6635
6636         modes = list_pkt_forwarding_retry_modes();
6637         snprintf(help, sizeof(help), "set fwd %s retry: "
6638                 "Set packet forwarding mode with retry", modes);
6639         cmd_set_fwd_retry_mode.help_str = help;
6640
6641         /* string token separator is # */
6642         for (c = token; *modes != '\0'; modes++)
6643                 if (*modes == '|')
6644                         *c++ = '#';
6645                 else
6646                         *c++ = *modes;
6647         token_struct = (cmdline_parse_token_string_t *)
6648                 cmd_set_fwd_retry_mode.tokens[2];
6649         token_struct->string_data.str = token;
6650 }
6651
6652 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6653 struct cmd_set_burst_tx_retry_result {
6654         cmdline_fixed_string_t set;
6655         cmdline_fixed_string_t burst;
6656         cmdline_fixed_string_t tx;
6657         cmdline_fixed_string_t delay;
6658         uint32_t time;
6659         cmdline_fixed_string_t retry;
6660         uint32_t retry_num;
6661 };
6662
6663 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6664                                         __rte_unused struct cmdline *cl,
6665                                         __rte_unused void *data)
6666 {
6667         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6668
6669         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6670                 && !strcmp(res->tx, "tx")) {
6671                 if (!strcmp(res->delay, "delay"))
6672                         burst_tx_delay_time = res->time;
6673                 if (!strcmp(res->retry, "retry"))
6674                         burst_tx_retry_num = res->retry_num;
6675         }
6676
6677 }
6678
6679 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6680         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6681 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6682         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6683                                  "burst");
6684 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6686 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6687         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6688 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6689         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6690 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6692 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6693         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6694
6695 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6696         .f = cmd_set_burst_tx_retry_parsed,
6697         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6698         .tokens = {
6699                 (void *)&cmd_set_burst_tx_retry_set,
6700                 (void *)&cmd_set_burst_tx_retry_burst,
6701                 (void *)&cmd_set_burst_tx_retry_tx,
6702                 (void *)&cmd_set_burst_tx_retry_delay,
6703                 (void *)&cmd_set_burst_tx_retry_time,
6704                 (void *)&cmd_set_burst_tx_retry_retry,
6705                 (void *)&cmd_set_burst_tx_retry_retry_num,
6706                 NULL,
6707         },
6708 };
6709
6710 /* *** SET PROMISC MODE *** */
6711 struct cmd_set_promisc_mode_result {
6712         cmdline_fixed_string_t set;
6713         cmdline_fixed_string_t promisc;
6714         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6715         uint16_t port_num;               /* valid if "allports" argument == 0 */
6716         cmdline_fixed_string_t mode;
6717 };
6718
6719 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6720                                         __rte_unused struct cmdline *cl,
6721                                         void *allports)
6722 {
6723         struct cmd_set_promisc_mode_result *res = parsed_result;
6724         int enable;
6725         portid_t i;
6726
6727         if (!strcmp(res->mode, "on"))
6728                 enable = 1;
6729         else
6730                 enable = 0;
6731
6732         /* all ports */
6733         if (allports) {
6734                 RTE_ETH_FOREACH_DEV(i)
6735                         eth_set_promisc_mode(i, enable);
6736         } else {
6737                 eth_set_promisc_mode(res->port_num, enable);
6738         }
6739 }
6740
6741 cmdline_parse_token_string_t cmd_setpromisc_set =
6742         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6743 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6745                                  "promisc");
6746 cmdline_parse_token_string_t cmd_setpromisc_portall =
6747         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6748                                  "all");
6749 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6750         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6751                               UINT16);
6752 cmdline_parse_token_string_t cmd_setpromisc_mode =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6754                                  "on#off");
6755
6756 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6757         .f = cmd_set_promisc_mode_parsed,
6758         .data = (void *)1,
6759         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6760         .tokens = {
6761                 (void *)&cmd_setpromisc_set,
6762                 (void *)&cmd_setpromisc_promisc,
6763                 (void *)&cmd_setpromisc_portall,
6764                 (void *)&cmd_setpromisc_mode,
6765                 NULL,
6766         },
6767 };
6768
6769 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6770         .f = cmd_set_promisc_mode_parsed,
6771         .data = (void *)0,
6772         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6773         .tokens = {
6774                 (void *)&cmd_setpromisc_set,
6775                 (void *)&cmd_setpromisc_promisc,
6776                 (void *)&cmd_setpromisc_portnum,
6777                 (void *)&cmd_setpromisc_mode,
6778                 NULL,
6779         },
6780 };
6781
6782 /* *** SET ALLMULTI MODE *** */
6783 struct cmd_set_allmulti_mode_result {
6784         cmdline_fixed_string_t set;
6785         cmdline_fixed_string_t allmulti;
6786         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6787         uint16_t port_num;               /* valid if "allports" argument == 0 */
6788         cmdline_fixed_string_t mode;
6789 };
6790
6791 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6792                                         __rte_unused struct cmdline *cl,
6793                                         void *allports)
6794 {
6795         struct cmd_set_allmulti_mode_result *res = parsed_result;
6796         int enable;
6797         portid_t i;
6798
6799         if (!strcmp(res->mode, "on"))
6800                 enable = 1;
6801         else
6802                 enable = 0;
6803
6804         /* all ports */
6805         if (allports) {
6806                 RTE_ETH_FOREACH_DEV(i) {
6807                         eth_set_allmulticast_mode(i, enable);
6808                 }
6809         }
6810         else {
6811                 eth_set_allmulticast_mode(res->port_num, enable);
6812         }
6813 }
6814
6815 cmdline_parse_token_string_t cmd_setallmulti_set =
6816         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6817 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6819                                  "allmulti");
6820 cmdline_parse_token_string_t cmd_setallmulti_portall =
6821         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6822                                  "all");
6823 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6824         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6825                               UINT16);
6826 cmdline_parse_token_string_t cmd_setallmulti_mode =
6827         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6828                                  "on#off");
6829
6830 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6831         .f = cmd_set_allmulti_mode_parsed,
6832         .data = (void *)1,
6833         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6834         .tokens = {
6835                 (void *)&cmd_setallmulti_set,
6836                 (void *)&cmd_setallmulti_allmulti,
6837                 (void *)&cmd_setallmulti_portall,
6838                 (void *)&cmd_setallmulti_mode,
6839                 NULL,
6840         },
6841 };
6842
6843 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6844         .f = cmd_set_allmulti_mode_parsed,
6845         .data = (void *)0,
6846         .help_str = "set allmulti <port_id> on|off: "
6847                 "Set allmulti mode on port_id",
6848         .tokens = {
6849                 (void *)&cmd_setallmulti_set,
6850                 (void *)&cmd_setallmulti_allmulti,
6851                 (void *)&cmd_setallmulti_portnum,
6852                 (void *)&cmd_setallmulti_mode,
6853                 NULL,
6854         },
6855 };
6856
6857 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6858 struct cmd_link_flow_ctrl_set_result {
6859         cmdline_fixed_string_t set;
6860         cmdline_fixed_string_t flow_ctrl;
6861         cmdline_fixed_string_t rx;
6862         cmdline_fixed_string_t rx_lfc_mode;
6863         cmdline_fixed_string_t tx;
6864         cmdline_fixed_string_t tx_lfc_mode;
6865         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6866         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6867         cmdline_fixed_string_t autoneg_str;
6868         cmdline_fixed_string_t autoneg;
6869         cmdline_fixed_string_t hw_str;
6870         uint32_t high_water;
6871         cmdline_fixed_string_t lw_str;
6872         uint32_t low_water;
6873         cmdline_fixed_string_t pt_str;
6874         uint16_t pause_time;
6875         cmdline_fixed_string_t xon_str;
6876         uint16_t send_xon;
6877         portid_t port_id;
6878 };
6879
6880 cmdline_parse_token_string_t cmd_lfc_set_set =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 set, "set");
6883 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 flow_ctrl, "flow_ctrl");
6886 cmdline_parse_token_string_t cmd_lfc_set_rx =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 rx, "rx");
6889 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 rx_lfc_mode, "on#off");
6892 cmdline_parse_token_string_t cmd_lfc_set_tx =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 tx, "tx");
6895 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 tx_lfc_mode, "on#off");
6898 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 hw_str, "high_water");
6901 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 high_water, UINT32);
6904 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 lw_str, "low_water");
6907 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 low_water, UINT32);
6910 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 pt_str, "pause_time");
6913 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6914         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 pause_time, UINT16);
6916 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 xon_str, "send_xon");
6919 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6920         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 send_xon, UINT16);
6922 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6925 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 mac_ctrl_frame_fwd_mode, "on#off");
6928 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6929         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 autoneg_str, "autoneg");
6931 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6933                                 autoneg, "on#off");
6934 cmdline_parse_token_num_t cmd_lfc_set_portid =
6935         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6936                                 port_id, UINT16);
6937
6938 /* forward declaration */
6939 static void
6940 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6941                               void *data);
6942
6943 cmdline_parse_inst_t cmd_link_flow_control_set = {
6944         .f = cmd_link_flow_ctrl_set_parsed,
6945         .data = NULL,
6946         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6947                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6948                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6949         .tokens = {
6950                 (void *)&cmd_lfc_set_set,
6951                 (void *)&cmd_lfc_set_flow_ctrl,
6952                 (void *)&cmd_lfc_set_rx,
6953                 (void *)&cmd_lfc_set_rx_mode,
6954                 (void *)&cmd_lfc_set_tx,
6955                 (void *)&cmd_lfc_set_tx_mode,
6956                 (void *)&cmd_lfc_set_high_water,
6957                 (void *)&cmd_lfc_set_low_water,
6958                 (void *)&cmd_lfc_set_pause_time,
6959                 (void *)&cmd_lfc_set_send_xon,
6960                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6961                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6962                 (void *)&cmd_lfc_set_autoneg_str,
6963                 (void *)&cmd_lfc_set_autoneg,
6964                 (void *)&cmd_lfc_set_portid,
6965                 NULL,
6966         },
6967 };
6968
6969 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6970         .f = cmd_link_flow_ctrl_set_parsed,
6971         .data = (void *)&cmd_link_flow_control_set_rx,
6972         .help_str = "set flow_ctrl rx on|off <port_id>: "
6973                 "Change rx flow control parameter",
6974         .tokens = {
6975                 (void *)&cmd_lfc_set_set,
6976                 (void *)&cmd_lfc_set_flow_ctrl,
6977                 (void *)&cmd_lfc_set_rx,
6978                 (void *)&cmd_lfc_set_rx_mode,
6979                 (void *)&cmd_lfc_set_portid,
6980                 NULL,
6981         },
6982 };
6983
6984 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6985         .f = cmd_link_flow_ctrl_set_parsed,
6986         .data = (void *)&cmd_link_flow_control_set_tx,
6987         .help_str = "set flow_ctrl tx on|off <port_id>: "
6988                 "Change tx flow control parameter",
6989         .tokens = {
6990                 (void *)&cmd_lfc_set_set,
6991                 (void *)&cmd_lfc_set_flow_ctrl,
6992                 (void *)&cmd_lfc_set_tx,
6993                 (void *)&cmd_lfc_set_tx_mode,
6994                 (void *)&cmd_lfc_set_portid,
6995                 NULL,
6996         },
6997 };
6998
6999 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7000         .f = cmd_link_flow_ctrl_set_parsed,
7001         .data = (void *)&cmd_link_flow_control_set_hw,
7002         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7003                 "Change high water flow control parameter",
7004         .tokens = {
7005                 (void *)&cmd_lfc_set_set,
7006                 (void *)&cmd_lfc_set_flow_ctrl,
7007                 (void *)&cmd_lfc_set_high_water_str,
7008                 (void *)&cmd_lfc_set_high_water,
7009                 (void *)&cmd_lfc_set_portid,
7010                 NULL,
7011         },
7012 };
7013
7014 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7015         .f = cmd_link_flow_ctrl_set_parsed,
7016         .data = (void *)&cmd_link_flow_control_set_lw,
7017         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7018                 "Change low water flow control parameter",
7019         .tokens = {
7020                 (void *)&cmd_lfc_set_set,
7021                 (void *)&cmd_lfc_set_flow_ctrl,
7022                 (void *)&cmd_lfc_set_low_water_str,
7023                 (void *)&cmd_lfc_set_low_water,
7024                 (void *)&cmd_lfc_set_portid,
7025                 NULL,
7026         },
7027 };
7028
7029 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7030         .f = cmd_link_flow_ctrl_set_parsed,
7031         .data = (void *)&cmd_link_flow_control_set_pt,
7032         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7033                 "Change pause time flow control parameter",
7034         .tokens = {
7035                 (void *)&cmd_lfc_set_set,
7036                 (void *)&cmd_lfc_set_flow_ctrl,
7037                 (void *)&cmd_lfc_set_pause_time_str,
7038                 (void *)&cmd_lfc_set_pause_time,
7039                 (void *)&cmd_lfc_set_portid,
7040                 NULL,
7041         },
7042 };
7043
7044 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7045         .f = cmd_link_flow_ctrl_set_parsed,
7046         .data = (void *)&cmd_link_flow_control_set_xon,
7047         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7048                 "Change send_xon flow control parameter",
7049         .tokens = {
7050                 (void *)&cmd_lfc_set_set,
7051                 (void *)&cmd_lfc_set_flow_ctrl,
7052                 (void *)&cmd_lfc_set_send_xon_str,
7053                 (void *)&cmd_lfc_set_send_xon,
7054                 (void *)&cmd_lfc_set_portid,
7055                 NULL,
7056         },
7057 };
7058
7059 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7060         .f = cmd_link_flow_ctrl_set_parsed,
7061         .data = (void *)&cmd_link_flow_control_set_macfwd,
7062         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7063                 "Change mac ctrl fwd flow control parameter",
7064         .tokens = {
7065                 (void *)&cmd_lfc_set_set,
7066                 (void *)&cmd_lfc_set_flow_ctrl,
7067                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7068                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7069                 (void *)&cmd_lfc_set_portid,
7070                 NULL,
7071         },
7072 };
7073
7074 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7075         .f = cmd_link_flow_ctrl_set_parsed,
7076         .data = (void *)&cmd_link_flow_control_set_autoneg,
7077         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7078                 "Change autoneg flow control parameter",
7079         .tokens = {
7080                 (void *)&cmd_lfc_set_set,
7081                 (void *)&cmd_lfc_set_flow_ctrl,
7082                 (void *)&cmd_lfc_set_autoneg_str,
7083                 (void *)&cmd_lfc_set_autoneg,
7084                 (void *)&cmd_lfc_set_portid,
7085                 NULL,
7086         },
7087 };
7088
7089 static void
7090 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7091                               __rte_unused struct cmdline *cl,
7092                               void *data)
7093 {
7094         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7095         cmdline_parse_inst_t *cmd = data;
7096         struct rte_eth_fc_conf fc_conf;
7097         int rx_fc_en = 0;
7098         int tx_fc_en = 0;
7099         int ret;
7100
7101         /*
7102          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7103          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7104          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7105          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7106          */
7107         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7108                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7109         };
7110
7111         /* Partial command line, retrieve current configuration */
7112         if (cmd) {
7113                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7114                 if (ret != 0) {
7115                         printf("cannot get current flow ctrl parameters, return"
7116                                "code = %d\n", ret);
7117                         return;
7118                 }
7119
7120                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7121                     (fc_conf.mode == RTE_FC_FULL))
7122                         rx_fc_en = 1;
7123                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7124                     (fc_conf.mode == RTE_FC_FULL))
7125                         tx_fc_en = 1;
7126         }
7127
7128         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7129                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7130
7131         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7132                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7133
7134         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7137                 fc_conf.high_water = res->high_water;
7138
7139         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7140                 fc_conf.low_water = res->low_water;
7141
7142         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7143                 fc_conf.pause_time = res->pause_time;
7144
7145         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7146                 fc_conf.send_xon = res->send_xon;
7147
7148         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7149                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7150                         fc_conf.mac_ctrl_frame_fwd = 1;
7151                 else
7152                         fc_conf.mac_ctrl_frame_fwd = 0;
7153         }
7154
7155         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7156                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7157
7158         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7159         if (ret != 0)
7160                 printf("bad flow contrl parameter, return code = %d \n", ret);
7161 }
7162
7163 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7164 struct cmd_priority_flow_ctrl_set_result {
7165         cmdline_fixed_string_t set;
7166         cmdline_fixed_string_t pfc_ctrl;
7167         cmdline_fixed_string_t rx;
7168         cmdline_fixed_string_t rx_pfc_mode;
7169         cmdline_fixed_string_t tx;
7170         cmdline_fixed_string_t tx_pfc_mode;
7171         uint32_t high_water;
7172         uint32_t low_water;
7173         uint16_t pause_time;
7174         uint8_t  priority;
7175         portid_t port_id;
7176 };
7177
7178 static void
7179 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7180                        __rte_unused struct cmdline *cl,
7181                        __rte_unused void *data)
7182 {
7183         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7184         struct rte_eth_pfc_conf pfc_conf;
7185         int rx_fc_enable, tx_fc_enable;
7186         int ret;
7187
7188         /*
7189          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7190          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7191          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7192          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7193          */
7194         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7195                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7196         };
7197
7198         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7199         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7200         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7201         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7202         pfc_conf.fc.high_water = res->high_water;
7203         pfc_conf.fc.low_water  = res->low_water;
7204         pfc_conf.fc.pause_time = res->pause_time;
7205         pfc_conf.priority      = res->priority;
7206
7207         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7208         if (ret != 0)
7209                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7210 }
7211
7212 cmdline_parse_token_string_t cmd_pfc_set_set =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 set, "set");
7215 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 pfc_ctrl, "pfc_ctrl");
7218 cmdline_parse_token_string_t cmd_pfc_set_rx =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 rx, "rx");
7221 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7222         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 rx_pfc_mode, "on#off");
7224 cmdline_parse_token_string_t cmd_pfc_set_tx =
7225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 tx, "tx");
7227 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 tx_pfc_mode, "on#off");
7230 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 high_water, UINT32);
7233 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7234         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 low_water, UINT32);
7236 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7237         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 pause_time, UINT16);
7239 cmdline_parse_token_num_t cmd_pfc_set_priority =
7240         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7241                                 priority, UINT8);
7242 cmdline_parse_token_num_t cmd_pfc_set_portid =
7243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7244                                 port_id, UINT16);
7245
7246 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7247         .f = cmd_priority_flow_ctrl_set_parsed,
7248         .data = NULL,
7249         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7250                 "<pause_time> <priority> <port_id>: "
7251                 "Configure the Ethernet priority flow control",
7252         .tokens = {
7253                 (void *)&cmd_pfc_set_set,
7254                 (void *)&cmd_pfc_set_flow_ctrl,
7255                 (void *)&cmd_pfc_set_rx,
7256                 (void *)&cmd_pfc_set_rx_mode,
7257                 (void *)&cmd_pfc_set_tx,
7258                 (void *)&cmd_pfc_set_tx_mode,
7259                 (void *)&cmd_pfc_set_high_water,
7260                 (void *)&cmd_pfc_set_low_water,
7261                 (void *)&cmd_pfc_set_pause_time,
7262                 (void *)&cmd_pfc_set_priority,
7263                 (void *)&cmd_pfc_set_portid,
7264                 NULL,
7265         },
7266 };
7267
7268 /* *** RESET CONFIGURATION *** */
7269 struct cmd_reset_result {
7270         cmdline_fixed_string_t reset;
7271         cmdline_fixed_string_t def;
7272 };
7273
7274 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7275                              struct cmdline *cl,
7276                              __rte_unused void *data)
7277 {
7278         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7279         set_def_fwd_config();
7280 }
7281
7282 cmdline_parse_token_string_t cmd_reset_set =
7283         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7284 cmdline_parse_token_string_t cmd_reset_def =
7285         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7286                                  "default");
7287
7288 cmdline_parse_inst_t cmd_reset = {
7289         .f = cmd_reset_parsed,
7290         .data = NULL,
7291         .help_str = "set default: Reset default forwarding configuration",
7292         .tokens = {
7293                 (void *)&cmd_reset_set,
7294                 (void *)&cmd_reset_def,
7295                 NULL,
7296         },
7297 };
7298
7299 /* *** START FORWARDING *** */
7300 struct cmd_start_result {
7301         cmdline_fixed_string_t start;
7302 };
7303
7304 cmdline_parse_token_string_t cmd_start_start =
7305         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7306
7307 static void cmd_start_parsed(__rte_unused void *parsed_result,
7308                              __rte_unused struct cmdline *cl,
7309                              __rte_unused void *data)
7310 {
7311         start_packet_forwarding(0);
7312 }
7313
7314 cmdline_parse_inst_t cmd_start = {
7315         .f = cmd_start_parsed,
7316         .data = NULL,
7317         .help_str = "start: Start packet forwarding",
7318         .tokens = {
7319                 (void *)&cmd_start_start,
7320                 NULL,
7321         },
7322 };
7323
7324 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7325 struct cmd_start_tx_first_result {
7326         cmdline_fixed_string_t start;
7327         cmdline_fixed_string_t tx_first;
7328 };
7329
7330 static void
7331 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7332                           __rte_unused struct cmdline *cl,
7333                           __rte_unused void *data)
7334 {
7335         start_packet_forwarding(1);
7336 }
7337
7338 cmdline_parse_token_string_t cmd_start_tx_first_start =
7339         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7340                                  "start");
7341 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7342         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7343                                  tx_first, "tx_first");
7344
7345 cmdline_parse_inst_t cmd_start_tx_first = {
7346         .f = cmd_start_tx_first_parsed,
7347         .data = NULL,
7348         .help_str = "start tx_first: Start packet forwarding, "
7349                 "after sending 1 burst of packets",
7350         .tokens = {
7351                 (void *)&cmd_start_tx_first_start,
7352                 (void *)&cmd_start_tx_first_tx_first,
7353                 NULL,
7354         },
7355 };
7356
7357 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7358 struct cmd_start_tx_first_n_result {
7359         cmdline_fixed_string_t start;
7360         cmdline_fixed_string_t tx_first;
7361         uint32_t tx_num;
7362 };
7363
7364 static void
7365 cmd_start_tx_first_n_parsed(void *parsed_result,
7366                           __rte_unused struct cmdline *cl,
7367                           __rte_unused void *data)
7368 {
7369         struct cmd_start_tx_first_n_result *res = parsed_result;
7370
7371         start_packet_forwarding(res->tx_num);
7372 }
7373
7374 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7375         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7376                         start, "start");
7377 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7378         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7379                         tx_first, "tx_first");
7380 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7381         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7382                         tx_num, UINT32);
7383
7384 cmdline_parse_inst_t cmd_start_tx_first_n = {
7385         .f = cmd_start_tx_first_n_parsed,
7386         .data = NULL,
7387         .help_str = "start tx_first <num>: "
7388                 "packet forwarding, after sending <num> bursts of packets",
7389         .tokens = {
7390                 (void *)&cmd_start_tx_first_n_start,
7391                 (void *)&cmd_start_tx_first_n_tx_first,
7392                 (void *)&cmd_start_tx_first_n_tx_num,
7393                 NULL,
7394         },
7395 };
7396
7397 /* *** SET LINK UP *** */
7398 struct cmd_set_link_up_result {
7399         cmdline_fixed_string_t set;
7400         cmdline_fixed_string_t link_up;
7401         cmdline_fixed_string_t port;
7402         portid_t port_id;
7403 };
7404
7405 cmdline_parse_token_string_t cmd_set_link_up_set =
7406         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7407 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7409                                 "link-up");
7410 cmdline_parse_token_string_t cmd_set_link_up_port =
7411         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7412 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7413         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7414
7415 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7416                              __rte_unused struct cmdline *cl,
7417                              __rte_unused void *data)
7418 {
7419         struct cmd_set_link_up_result *res = parsed_result;
7420         dev_set_link_up(res->port_id);
7421 }
7422
7423 cmdline_parse_inst_t cmd_set_link_up = {
7424         .f = cmd_set_link_up_parsed,
7425         .data = NULL,
7426         .help_str = "set link-up port <port id>",
7427         .tokens = {
7428                 (void *)&cmd_set_link_up_set,
7429                 (void *)&cmd_set_link_up_link_up,
7430                 (void *)&cmd_set_link_up_port,
7431                 (void *)&cmd_set_link_up_port_id,
7432                 NULL,
7433         },
7434 };
7435
7436 /* *** SET LINK DOWN *** */
7437 struct cmd_set_link_down_result {
7438         cmdline_fixed_string_t set;
7439         cmdline_fixed_string_t link_down;
7440         cmdline_fixed_string_t port;
7441         portid_t port_id;
7442 };
7443
7444 cmdline_parse_token_string_t cmd_set_link_down_set =
7445         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7446 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7447         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7448                                 "link-down");
7449 cmdline_parse_token_string_t cmd_set_link_down_port =
7450         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7451 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7452         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7453
7454 static void cmd_set_link_down_parsed(
7455                                 __rte_unused void *parsed_result,
7456                                 __rte_unused struct cmdline *cl,
7457                                 __rte_unused void *data)
7458 {
7459         struct cmd_set_link_down_result *res = parsed_result;
7460         dev_set_link_down(res->port_id);
7461 }
7462
7463 cmdline_parse_inst_t cmd_set_link_down = {
7464         .f = cmd_set_link_down_parsed,
7465         .data = NULL,
7466         .help_str = "set link-down port <port id>",
7467         .tokens = {
7468                 (void *)&cmd_set_link_down_set,
7469                 (void *)&cmd_set_link_down_link_down,
7470                 (void *)&cmd_set_link_down_port,
7471                 (void *)&cmd_set_link_down_port_id,
7472                 NULL,
7473         },
7474 };
7475
7476 /* *** SHOW CFG *** */
7477 struct cmd_showcfg_result {
7478         cmdline_fixed_string_t show;
7479         cmdline_fixed_string_t cfg;
7480         cmdline_fixed_string_t what;
7481 };
7482
7483 static void cmd_showcfg_parsed(void *parsed_result,
7484                                __rte_unused struct cmdline *cl,
7485                                __rte_unused void *data)
7486 {
7487         struct cmd_showcfg_result *res = parsed_result;
7488         if (!strcmp(res->what, "rxtx"))
7489                 rxtx_config_display();
7490         else if (!strcmp(res->what, "cores"))
7491                 fwd_lcores_config_display();
7492         else if (!strcmp(res->what, "fwd"))
7493                 pkt_fwd_config_display(&cur_fwd_config);
7494         else if (!strcmp(res->what, "rxoffs"))
7495                 show_rx_pkt_offsets();
7496         else if (!strcmp(res->what, "rxpkts"))
7497                 show_rx_pkt_segments();
7498         else if (!strcmp(res->what, "txpkts"))
7499                 show_tx_pkt_segments();
7500         else if (!strcmp(res->what, "txtimes"))
7501                 show_tx_pkt_times();
7502 }
7503
7504 cmdline_parse_token_string_t cmd_showcfg_show =
7505         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7506 cmdline_parse_token_string_t cmd_showcfg_port =
7507         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7508 cmdline_parse_token_string_t cmd_showcfg_what =
7509         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7510                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7511
7512 cmdline_parse_inst_t cmd_showcfg = {
7513         .f = cmd_showcfg_parsed,
7514         .data = NULL,
7515         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7516         .tokens = {
7517                 (void *)&cmd_showcfg_show,
7518                 (void *)&cmd_showcfg_port,
7519                 (void *)&cmd_showcfg_what,
7520                 NULL,
7521         },
7522 };
7523
7524 /* *** SHOW ALL PORT INFO *** */
7525 struct cmd_showportall_result {
7526         cmdline_fixed_string_t show;
7527         cmdline_fixed_string_t port;
7528         cmdline_fixed_string_t what;
7529         cmdline_fixed_string_t all;
7530 };
7531
7532 static void cmd_showportall_parsed(void *parsed_result,
7533                                 __rte_unused struct cmdline *cl,
7534                                 __rte_unused void *data)
7535 {
7536         portid_t i;
7537
7538         struct cmd_showportall_result *res = parsed_result;
7539         if (!strcmp(res->show, "clear")) {
7540                 if (!strcmp(res->what, "stats"))
7541                         RTE_ETH_FOREACH_DEV(i)
7542                                 nic_stats_clear(i);
7543                 else if (!strcmp(res->what, "xstats"))
7544                         RTE_ETH_FOREACH_DEV(i)
7545                                 nic_xstats_clear(i);
7546         } else if (!strcmp(res->what, "info"))
7547                 RTE_ETH_FOREACH_DEV(i)
7548                         port_infos_display(i);
7549         else if (!strcmp(res->what, "summary")) {
7550                 port_summary_header_display();
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         port_summary_display(i);
7553         }
7554         else if (!strcmp(res->what, "stats"))
7555                 RTE_ETH_FOREACH_DEV(i)
7556                         nic_stats_display(i);
7557         else if (!strcmp(res->what, "xstats"))
7558                 RTE_ETH_FOREACH_DEV(i)
7559                         nic_xstats_display(i);
7560 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7561         else if (!strcmp(res->what, "fdir"))
7562                 RTE_ETH_FOREACH_DEV(i)
7563                         fdir_get_infos(i);
7564 #endif
7565         else if (!strcmp(res->what, "stat_qmap"))
7566                 RTE_ETH_FOREACH_DEV(i)
7567                         nic_stats_mapping_display(i);
7568         else if (!strcmp(res->what, "dcb_tc"))
7569                 RTE_ETH_FOREACH_DEV(i)
7570                         port_dcb_info_display(i);
7571         else if (!strcmp(res->what, "cap"))
7572                 RTE_ETH_FOREACH_DEV(i)
7573                         port_offload_cap_display(i);
7574 }
7575
7576 cmdline_parse_token_string_t cmd_showportall_show =
7577         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7578                                  "show#clear");
7579 cmdline_parse_token_string_t cmd_showportall_port =
7580         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7581 cmdline_parse_token_string_t cmd_showportall_what =
7582         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7583                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7584 cmdline_parse_token_string_t cmd_showportall_all =
7585         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7586 cmdline_parse_inst_t cmd_showportall = {
7587         .f = cmd_showportall_parsed,
7588         .data = NULL,
7589         .help_str = "show|clear port "
7590                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7591         .tokens = {
7592                 (void *)&cmd_showportall_show,
7593                 (void *)&cmd_showportall_port,
7594                 (void *)&cmd_showportall_what,
7595                 (void *)&cmd_showportall_all,
7596                 NULL,
7597         },
7598 };
7599
7600 /* *** SHOW PORT INFO *** */
7601 struct cmd_showport_result {
7602         cmdline_fixed_string_t show;
7603         cmdline_fixed_string_t port;
7604         cmdline_fixed_string_t what;
7605         uint16_t portnum;
7606 };
7607
7608 static void cmd_showport_parsed(void *parsed_result,
7609                                 __rte_unused struct cmdline *cl,
7610                                 __rte_unused void *data)
7611 {
7612         struct cmd_showport_result *res = parsed_result;
7613         if (!strcmp(res->show, "clear")) {
7614                 if (!strcmp(res->what, "stats"))
7615                         nic_stats_clear(res->portnum);
7616                 else if (!strcmp(res->what, "xstats"))
7617                         nic_xstats_clear(res->portnum);
7618         } else if (!strcmp(res->what, "info"))
7619                 port_infos_display(res->portnum);
7620         else if (!strcmp(res->what, "summary")) {
7621                 port_summary_header_display();
7622                 port_summary_display(res->portnum);
7623         }
7624         else if (!strcmp(res->what, "stats"))
7625                 nic_stats_display(res->portnum);
7626         else if (!strcmp(res->what, "xstats"))
7627                 nic_xstats_display(res->portnum);
7628 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7629         else if (!strcmp(res->what, "fdir"))
7630                  fdir_get_infos(res->portnum);
7631 #endif
7632         else if (!strcmp(res->what, "stat_qmap"))
7633                 nic_stats_mapping_display(res->portnum);
7634         else if (!strcmp(res->what, "dcb_tc"))
7635                 port_dcb_info_display(res->portnum);
7636         else if (!strcmp(res->what, "cap"))
7637                 port_offload_cap_display(res->portnum);
7638 }
7639
7640 cmdline_parse_token_string_t cmd_showport_show =
7641         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7642                                  "show#clear");
7643 cmdline_parse_token_string_t cmd_showport_port =
7644         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7645 cmdline_parse_token_string_t cmd_showport_what =
7646         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7647                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7648 cmdline_parse_token_num_t cmd_showport_portnum =
7649         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7650
7651 cmdline_parse_inst_t cmd_showport = {
7652         .f = cmd_showport_parsed,
7653         .data = NULL,
7654         .help_str = "show|clear port "
7655                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7656                 "<port_id>",
7657         .tokens = {
7658                 (void *)&cmd_showport_show,
7659                 (void *)&cmd_showport_port,
7660                 (void *)&cmd_showport_what,
7661                 (void *)&cmd_showport_portnum,
7662                 NULL,
7663         },
7664 };
7665
7666 /* *** SHOW DEVICE INFO *** */
7667 struct cmd_showdevice_result {
7668         cmdline_fixed_string_t show;
7669         cmdline_fixed_string_t device;
7670         cmdline_fixed_string_t what;
7671         cmdline_fixed_string_t identifier;
7672 };
7673
7674 static void cmd_showdevice_parsed(void *parsed_result,
7675                                 __rte_unused struct cmdline *cl,
7676                                 __rte_unused void *data)
7677 {
7678         struct cmd_showdevice_result *res = parsed_result;
7679         if (!strcmp(res->what, "info")) {
7680                 if (!strcmp(res->identifier, "all"))
7681                         device_infos_display(NULL);
7682                 else
7683                         device_infos_display(res->identifier);
7684         }
7685 }
7686
7687 cmdline_parse_token_string_t cmd_showdevice_show =
7688         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7689                                  "show");
7690 cmdline_parse_token_string_t cmd_showdevice_device =
7691         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7692 cmdline_parse_token_string_t cmd_showdevice_what =
7693         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7694                                  "info");
7695 cmdline_parse_token_string_t cmd_showdevice_identifier =
7696         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7697                         identifier, NULL);
7698
7699 cmdline_parse_inst_t cmd_showdevice = {
7700         .f = cmd_showdevice_parsed,
7701         .data = NULL,
7702         .help_str = "show device info <identifier>|all",
7703         .tokens = {
7704                 (void *)&cmd_showdevice_show,
7705                 (void *)&cmd_showdevice_device,
7706                 (void *)&cmd_showdevice_what,
7707                 (void *)&cmd_showdevice_identifier,
7708                 NULL,
7709         },
7710 };
7711
7712 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7713 struct cmd_showeeprom_result {
7714         cmdline_fixed_string_t show;
7715         cmdline_fixed_string_t port;
7716         uint16_t portnum;
7717         cmdline_fixed_string_t type;
7718 };
7719
7720 static void cmd_showeeprom_parsed(void *parsed_result,
7721                 __rte_unused struct cmdline *cl,
7722                 __rte_unused void *data)
7723 {
7724         struct cmd_showeeprom_result *res = parsed_result;
7725
7726         if (!strcmp(res->type, "eeprom"))
7727                 port_eeprom_display(res->portnum);
7728         else if (!strcmp(res->type, "module_eeprom"))
7729                 port_module_eeprom_display(res->portnum);
7730         else
7731                 printf("Unknown argument\n");
7732 }
7733
7734 cmdline_parse_token_string_t cmd_showeeprom_show =
7735         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7736 cmdline_parse_token_string_t cmd_showeeprom_port =
7737         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7738 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7739         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7740 cmdline_parse_token_string_t cmd_showeeprom_type =
7741         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7742
7743 cmdline_parse_inst_t cmd_showeeprom = {
7744         .f = cmd_showeeprom_parsed,
7745         .data = NULL,
7746         .help_str = "show port <port_id> module_eeprom|eeprom",
7747         .tokens = {
7748                 (void *)&cmd_showeeprom_show,
7749                 (void *)&cmd_showeeprom_port,
7750                 (void *)&cmd_showeeprom_portnum,
7751                 (void *)&cmd_showeeprom_type,
7752                 NULL,
7753         },
7754 };
7755
7756 /* *** SHOW QUEUE INFO *** */
7757 struct cmd_showqueue_result {
7758         cmdline_fixed_string_t show;
7759         cmdline_fixed_string_t type;
7760         cmdline_fixed_string_t what;
7761         uint16_t portnum;
7762         uint16_t queuenum;
7763 };
7764
7765 static void
7766 cmd_showqueue_parsed(void *parsed_result,
7767         __rte_unused struct cmdline *cl,
7768         __rte_unused void *data)
7769 {
7770         struct cmd_showqueue_result *res = parsed_result;
7771
7772         if (!strcmp(res->type, "rxq"))
7773                 rx_queue_infos_display(res->portnum, res->queuenum);
7774         else if (!strcmp(res->type, "txq"))
7775                 tx_queue_infos_display(res->portnum, res->queuenum);
7776 }
7777
7778 cmdline_parse_token_string_t cmd_showqueue_show =
7779         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7780 cmdline_parse_token_string_t cmd_showqueue_type =
7781         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7782 cmdline_parse_token_string_t cmd_showqueue_what =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7784 cmdline_parse_token_num_t cmd_showqueue_portnum =
7785         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7786 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7787         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7788
7789 cmdline_parse_inst_t cmd_showqueue = {
7790         .f = cmd_showqueue_parsed,
7791         .data = NULL,
7792         .help_str = "show rxq|txq info <port_id> <queue_id>",
7793         .tokens = {
7794                 (void *)&cmd_showqueue_show,
7795                 (void *)&cmd_showqueue_type,
7796                 (void *)&cmd_showqueue_what,
7797                 (void *)&cmd_showqueue_portnum,
7798                 (void *)&cmd_showqueue_queuenum,
7799                 NULL,
7800         },
7801 };
7802
7803 /* show/clear fwd engine statistics */
7804 struct fwd_result {
7805         cmdline_fixed_string_t action;
7806         cmdline_fixed_string_t fwd;
7807         cmdline_fixed_string_t stats;
7808         cmdline_fixed_string_t all;
7809 };
7810
7811 cmdline_parse_token_string_t cmd_fwd_action =
7812         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7813 cmdline_parse_token_string_t cmd_fwd_fwd =
7814         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7815 cmdline_parse_token_string_t cmd_fwd_stats =
7816         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7817 cmdline_parse_token_string_t cmd_fwd_all =
7818         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7819
7820 static void
7821 cmd_showfwdall_parsed(void *parsed_result,
7822                       __rte_unused struct cmdline *cl,
7823                       __rte_unused void *data)
7824 {
7825         struct fwd_result *res = parsed_result;
7826
7827         if (!strcmp(res->action, "show"))
7828                 fwd_stats_display();
7829         else
7830                 fwd_stats_reset();
7831 }
7832
7833 static cmdline_parse_inst_t cmd_showfwdall = {
7834         .f = cmd_showfwdall_parsed,
7835         .data = NULL,
7836         .help_str = "show|clear fwd stats all",
7837         .tokens = {
7838                 (void *)&cmd_fwd_action,
7839                 (void *)&cmd_fwd_fwd,
7840                 (void *)&cmd_fwd_stats,
7841                 (void *)&cmd_fwd_all,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** READ PORT REGISTER *** */
7847 struct cmd_read_reg_result {
7848         cmdline_fixed_string_t read;
7849         cmdline_fixed_string_t reg;
7850         portid_t port_id;
7851         uint32_t reg_off;
7852 };
7853
7854 static void
7855 cmd_read_reg_parsed(void *parsed_result,
7856                     __rte_unused struct cmdline *cl,
7857                     __rte_unused void *data)
7858 {
7859         struct cmd_read_reg_result *res = parsed_result;
7860         port_reg_display(res->port_id, res->reg_off);
7861 }
7862
7863 cmdline_parse_token_string_t cmd_read_reg_read =
7864         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7865 cmdline_parse_token_string_t cmd_read_reg_reg =
7866         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7867 cmdline_parse_token_num_t cmd_read_reg_port_id =
7868         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7869 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7870         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7871
7872 cmdline_parse_inst_t cmd_read_reg = {
7873         .f = cmd_read_reg_parsed,
7874         .data = NULL,
7875         .help_str = "read reg <port_id> <reg_off>",
7876         .tokens = {
7877                 (void *)&cmd_read_reg_read,
7878                 (void *)&cmd_read_reg_reg,
7879                 (void *)&cmd_read_reg_port_id,
7880                 (void *)&cmd_read_reg_reg_off,
7881                 NULL,
7882         },
7883 };
7884
7885 /* *** READ PORT REGISTER BIT FIELD *** */
7886 struct cmd_read_reg_bit_field_result {
7887         cmdline_fixed_string_t read;
7888         cmdline_fixed_string_t regfield;
7889         portid_t port_id;
7890         uint32_t reg_off;
7891         uint8_t bit1_pos;
7892         uint8_t bit2_pos;
7893 };
7894
7895 static void
7896 cmd_read_reg_bit_field_parsed(void *parsed_result,
7897                               __rte_unused struct cmdline *cl,
7898                               __rte_unused void *data)
7899 {
7900         struct cmd_read_reg_bit_field_result *res = parsed_result;
7901         port_reg_bit_field_display(res->port_id, res->reg_off,
7902                                    res->bit1_pos, res->bit2_pos);
7903 }
7904
7905 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7906         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7907                                  "read");
7908 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7909         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7910                                  regfield, "regfield");
7911 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7912         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7913                               UINT16);
7914 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7915         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7916                               UINT32);
7917 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7918         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7919                               UINT8);
7920 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7921         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7922                               UINT8);
7923
7924 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7925         .f = cmd_read_reg_bit_field_parsed,
7926         .data = NULL,
7927         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7928         "Read register bit field between bit_x and bit_y included",
7929         .tokens = {
7930                 (void *)&cmd_read_reg_bit_field_read,
7931                 (void *)&cmd_read_reg_bit_field_regfield,
7932                 (void *)&cmd_read_reg_bit_field_port_id,
7933                 (void *)&cmd_read_reg_bit_field_reg_off,
7934                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7935                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7936                 NULL,
7937         },
7938 };
7939
7940 /* *** READ PORT REGISTER BIT *** */
7941 struct cmd_read_reg_bit_result {
7942         cmdline_fixed_string_t read;
7943         cmdline_fixed_string_t regbit;
7944         portid_t port_id;
7945         uint32_t reg_off;
7946         uint8_t bit_pos;
7947 };
7948
7949 static void
7950 cmd_read_reg_bit_parsed(void *parsed_result,
7951                         __rte_unused struct cmdline *cl,
7952                         __rte_unused void *data)
7953 {
7954         struct cmd_read_reg_bit_result *res = parsed_result;
7955         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7956 }
7957
7958 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7959         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7960 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7961         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7962                                  regbit, "regbit");
7963 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7964         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7965 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7966         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7967 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7968         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7969
7970 cmdline_parse_inst_t cmd_read_reg_bit = {
7971         .f = cmd_read_reg_bit_parsed,
7972         .data = NULL,
7973         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7974         .tokens = {
7975                 (void *)&cmd_read_reg_bit_read,
7976                 (void *)&cmd_read_reg_bit_regbit,
7977                 (void *)&cmd_read_reg_bit_port_id,
7978                 (void *)&cmd_read_reg_bit_reg_off,
7979                 (void *)&cmd_read_reg_bit_bit_pos,
7980                 NULL,
7981         },
7982 };
7983
7984 /* *** WRITE PORT REGISTER *** */
7985 struct cmd_write_reg_result {
7986         cmdline_fixed_string_t write;
7987         cmdline_fixed_string_t reg;
7988         portid_t port_id;
7989         uint32_t reg_off;
7990         uint32_t value;
7991 };
7992
7993 static void
7994 cmd_write_reg_parsed(void *parsed_result,
7995                      __rte_unused struct cmdline *cl,
7996                      __rte_unused void *data)
7997 {
7998         struct cmd_write_reg_result *res = parsed_result;
7999         port_reg_set(res->port_id, res->reg_off, res->value);
8000 }
8001
8002 cmdline_parse_token_string_t cmd_write_reg_write =
8003         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8004 cmdline_parse_token_string_t cmd_write_reg_reg =
8005         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8006 cmdline_parse_token_num_t cmd_write_reg_port_id =
8007         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8008 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8009         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8010 cmdline_parse_token_num_t cmd_write_reg_value =
8011         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8012
8013 cmdline_parse_inst_t cmd_write_reg = {
8014         .f = cmd_write_reg_parsed,
8015         .data = NULL,
8016         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8017         .tokens = {
8018                 (void *)&cmd_write_reg_write,
8019                 (void *)&cmd_write_reg_reg,
8020                 (void *)&cmd_write_reg_port_id,
8021                 (void *)&cmd_write_reg_reg_off,
8022                 (void *)&cmd_write_reg_value,
8023                 NULL,
8024         },
8025 };
8026
8027 /* *** WRITE PORT REGISTER BIT FIELD *** */
8028 struct cmd_write_reg_bit_field_result {
8029         cmdline_fixed_string_t write;
8030         cmdline_fixed_string_t regfield;
8031         portid_t port_id;
8032         uint32_t reg_off;
8033         uint8_t bit1_pos;
8034         uint8_t bit2_pos;
8035         uint32_t value;
8036 };
8037
8038 static void
8039 cmd_write_reg_bit_field_parsed(void *parsed_result,
8040                                __rte_unused struct cmdline *cl,
8041                                __rte_unused void *data)
8042 {
8043         struct cmd_write_reg_bit_field_result *res = parsed_result;
8044         port_reg_bit_field_set(res->port_id, res->reg_off,
8045                           res->bit1_pos, res->bit2_pos, res->value);
8046 }
8047
8048 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8049         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8050                                  "write");
8051 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8052         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8053                                  regfield, "regfield");
8054 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8056                               UINT16);
8057 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8059                               UINT32);
8060 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8062                               UINT8);
8063 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8064         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8065                               UINT8);
8066 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8067         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8068                               UINT32);
8069
8070 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8071         .f = cmd_write_reg_bit_field_parsed,
8072         .data = NULL,
8073         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8074                 "<reg_value>: "
8075                 "Set register bit field between bit_x and bit_y included",
8076         .tokens = {
8077                 (void *)&cmd_write_reg_bit_field_write,
8078                 (void *)&cmd_write_reg_bit_field_regfield,
8079                 (void *)&cmd_write_reg_bit_field_port_id,
8080                 (void *)&cmd_write_reg_bit_field_reg_off,
8081                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8082                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8083                 (void *)&cmd_write_reg_bit_field_value,
8084                 NULL,
8085         },
8086 };
8087
8088 /* *** WRITE PORT REGISTER BIT *** */
8089 struct cmd_write_reg_bit_result {
8090         cmdline_fixed_string_t write;
8091         cmdline_fixed_string_t regbit;
8092         portid_t port_id;
8093         uint32_t reg_off;
8094         uint8_t bit_pos;
8095         uint8_t value;
8096 };
8097
8098 static void
8099 cmd_write_reg_bit_parsed(void *parsed_result,
8100                          __rte_unused struct cmdline *cl,
8101                          __rte_unused void *data)
8102 {
8103         struct cmd_write_reg_bit_result *res = parsed_result;
8104         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8105 }
8106
8107 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8108         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8109                                  "write");
8110 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8111         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8112                                  regbit, "regbit");
8113 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8114         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8115 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8116         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8117 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8118         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8119 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8120         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8121
8122 cmdline_parse_inst_t cmd_write_reg_bit = {
8123         .f = cmd_write_reg_bit_parsed,
8124         .data = NULL,
8125         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8126                 "0 <= bit_x <= 31",
8127         .tokens = {
8128                 (void *)&cmd_write_reg_bit_write,
8129                 (void *)&cmd_write_reg_bit_regbit,
8130                 (void *)&cmd_write_reg_bit_port_id,
8131                 (void *)&cmd_write_reg_bit_reg_off,
8132                 (void *)&cmd_write_reg_bit_bit_pos,
8133                 (void *)&cmd_write_reg_bit_value,
8134                 NULL,
8135         },
8136 };
8137
8138 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8139 struct cmd_read_rxd_txd_result {
8140         cmdline_fixed_string_t read;
8141         cmdline_fixed_string_t rxd_txd;
8142         portid_t port_id;
8143         uint16_t queue_id;
8144         uint16_t desc_id;
8145 };
8146
8147 static void
8148 cmd_read_rxd_txd_parsed(void *parsed_result,
8149                         __rte_unused struct cmdline *cl,
8150                         __rte_unused void *data)
8151 {
8152         struct cmd_read_rxd_txd_result *res = parsed_result;
8153
8154         if (!strcmp(res->rxd_txd, "rxd"))
8155                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8156         else if (!strcmp(res->rxd_txd, "txd"))
8157                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8158 }
8159
8160 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8161         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8162 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8163         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8164                                  "rxd#txd");
8165 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8166         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8167 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8168         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8169 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8170         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8171
8172 cmdline_parse_inst_t cmd_read_rxd_txd = {
8173         .f = cmd_read_rxd_txd_parsed,
8174         .data = NULL,
8175         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8176         .tokens = {
8177                 (void *)&cmd_read_rxd_txd_read,
8178                 (void *)&cmd_read_rxd_txd_rxd_txd,
8179                 (void *)&cmd_read_rxd_txd_port_id,
8180                 (void *)&cmd_read_rxd_txd_queue_id,
8181                 (void *)&cmd_read_rxd_txd_desc_id,
8182                 NULL,
8183         },
8184 };
8185
8186 /* *** QUIT *** */
8187 struct cmd_quit_result {
8188         cmdline_fixed_string_t quit;
8189 };
8190
8191 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8192                             struct cmdline *cl,
8193                             __rte_unused void *data)
8194 {
8195         cmdline_quit(cl);
8196 }
8197
8198 cmdline_parse_token_string_t cmd_quit_quit =
8199         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8200
8201 cmdline_parse_inst_t cmd_quit = {
8202         .f = cmd_quit_parsed,
8203         .data = NULL,
8204         .help_str = "quit: Exit application",
8205         .tokens = {
8206                 (void *)&cmd_quit_quit,
8207                 NULL,
8208         },
8209 };
8210
8211 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8212 struct cmd_mac_addr_result {
8213         cmdline_fixed_string_t mac_addr_cmd;
8214         cmdline_fixed_string_t what;
8215         uint16_t port_num;
8216         struct rte_ether_addr address;
8217 };
8218
8219 static void cmd_mac_addr_parsed(void *parsed_result,
8220                 __rte_unused struct cmdline *cl,
8221                 __rte_unused void *data)
8222 {
8223         struct cmd_mac_addr_result *res = parsed_result;
8224         int ret;
8225
8226         if (strcmp(res->what, "add") == 0)
8227                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8228         else if (strcmp(res->what, "set") == 0)
8229                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8230                                                        &res->address);
8231         else
8232                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8233
8234         /* check the return value and print it if is < 0 */
8235         if(ret < 0)
8236                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8237
8238 }
8239
8240 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8241         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8242                                 "mac_addr");
8243 cmdline_parse_token_string_t cmd_mac_addr_what =
8244         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8245                                 "add#remove#set");
8246 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8247                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8248                                         UINT16);
8249 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8250                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8251
8252 cmdline_parse_inst_t cmd_mac_addr = {
8253         .f = cmd_mac_addr_parsed,
8254         .data = (void *)0,
8255         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8256                         "Add/Remove/Set MAC address on port_id",
8257         .tokens = {
8258                 (void *)&cmd_mac_addr_cmd,
8259                 (void *)&cmd_mac_addr_what,
8260                 (void *)&cmd_mac_addr_portnum,
8261                 (void *)&cmd_mac_addr_addr,
8262                 NULL,
8263         },
8264 };
8265
8266 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8267 struct cmd_eth_peer_result {
8268         cmdline_fixed_string_t set;
8269         cmdline_fixed_string_t eth_peer;
8270         portid_t port_id;
8271         cmdline_fixed_string_t peer_addr;
8272 };
8273
8274 static void cmd_set_eth_peer_parsed(void *parsed_result,
8275                         __rte_unused struct cmdline *cl,
8276                         __rte_unused void *data)
8277 {
8278                 struct cmd_eth_peer_result *res = parsed_result;
8279
8280                 if (test_done == 0) {
8281                         printf("Please stop forwarding first\n");
8282                         return;
8283                 }
8284                 if (!strcmp(res->eth_peer, "eth-peer")) {
8285                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8286                         fwd_config_setup();
8287                 }
8288 }
8289 cmdline_parse_token_string_t cmd_eth_peer_set =
8290         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8291 cmdline_parse_token_string_t cmd_eth_peer =
8292         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8293 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8294         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8295 cmdline_parse_token_string_t cmd_eth_peer_addr =
8296         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8297
8298 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8299         .f = cmd_set_eth_peer_parsed,
8300         .data = NULL,
8301         .help_str = "set eth-peer <port_id> <peer_mac>",
8302         .tokens = {
8303                 (void *)&cmd_eth_peer_set,
8304                 (void *)&cmd_eth_peer,
8305                 (void *)&cmd_eth_peer_port_id,
8306                 (void *)&cmd_eth_peer_addr,
8307                 NULL,
8308         },
8309 };
8310
8311 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8312 struct cmd_set_qmap_result {
8313         cmdline_fixed_string_t set;
8314         cmdline_fixed_string_t qmap;
8315         cmdline_fixed_string_t what;
8316         portid_t port_id;
8317         uint16_t queue_id;
8318         uint8_t map_value;
8319 };
8320
8321 static void
8322 cmd_set_qmap_parsed(void *parsed_result,
8323                        __rte_unused struct cmdline *cl,
8324                        __rte_unused void *data)
8325 {
8326         struct cmd_set_qmap_result *res = parsed_result;
8327         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8328
8329         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8330 }
8331
8332 cmdline_parse_token_string_t cmd_setqmap_set =
8333         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8334                                  set, "set");
8335 cmdline_parse_token_string_t cmd_setqmap_qmap =
8336         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8337                                  qmap, "stat_qmap");
8338 cmdline_parse_token_string_t cmd_setqmap_what =
8339         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8340                                  what, "tx#rx");
8341 cmdline_parse_token_num_t cmd_setqmap_portid =
8342         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8343                               port_id, UINT16);
8344 cmdline_parse_token_num_t cmd_setqmap_queueid =
8345         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8346                               queue_id, UINT16);
8347 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8348         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8349                               map_value, UINT8);
8350
8351 cmdline_parse_inst_t cmd_set_qmap = {
8352         .f = cmd_set_qmap_parsed,
8353         .data = NULL,
8354         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8355                 "Set statistics mapping value on tx|rx queue_id of port_id",
8356         .tokens = {
8357                 (void *)&cmd_setqmap_set,
8358                 (void *)&cmd_setqmap_qmap,
8359                 (void *)&cmd_setqmap_what,
8360                 (void *)&cmd_setqmap_portid,
8361                 (void *)&cmd_setqmap_queueid,
8362                 (void *)&cmd_setqmap_mapvalue,
8363                 NULL,
8364         },
8365 };
8366
8367 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8368 struct cmd_set_xstats_hide_zero_result {
8369         cmdline_fixed_string_t keyword;
8370         cmdline_fixed_string_t name;
8371         cmdline_fixed_string_t on_off;
8372 };
8373
8374 static void
8375 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8376                         __rte_unused struct cmdline *cl,
8377                         __rte_unused void *data)
8378 {
8379         struct cmd_set_xstats_hide_zero_result *res;
8380         uint16_t on_off = 0;
8381
8382         res = parsed_result;
8383         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8384         set_xstats_hide_zero(on_off);
8385 }
8386
8387 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8388         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8389                                  keyword, "set");
8390 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8391         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8392                                  name, "xstats-hide-zero");
8393 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8394         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8395                                  on_off, "on#off");
8396
8397 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8398         .f = cmd_set_xstats_hide_zero_parsed,
8399         .data = NULL,
8400         .help_str = "set xstats-hide-zero on|off",
8401         .tokens = {
8402                 (void *)&cmd_set_xstats_hide_zero_keyword,
8403                 (void *)&cmd_set_xstats_hide_zero_name,
8404                 (void *)&cmd_set_xstats_hide_zero_on_off,
8405                 NULL,
8406         },
8407 };
8408
8409 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8410 struct cmd_set_record_core_cycles_result {
8411         cmdline_fixed_string_t keyword;
8412         cmdline_fixed_string_t name;
8413         cmdline_fixed_string_t on_off;
8414 };
8415
8416 static void
8417 cmd_set_record_core_cycles_parsed(void *parsed_result,
8418                         __rte_unused struct cmdline *cl,
8419                         __rte_unused void *data)
8420 {
8421         struct cmd_set_record_core_cycles_result *res;
8422         uint16_t on_off = 0;
8423
8424         res = parsed_result;
8425         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8426         set_record_core_cycles(on_off);
8427 }
8428
8429 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8430         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8431                                  keyword, "set");
8432 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8433         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8434                                  name, "record-core-cycles");
8435 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8436         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8437                                  on_off, "on#off");
8438
8439 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8440         .f = cmd_set_record_core_cycles_parsed,
8441         .data = NULL,
8442         .help_str = "set record-core-cycles on|off",
8443         .tokens = {
8444                 (void *)&cmd_set_record_core_cycles_keyword,
8445                 (void *)&cmd_set_record_core_cycles_name,
8446                 (void *)&cmd_set_record_core_cycles_on_off,
8447                 NULL,
8448         },
8449 };
8450
8451 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8452 struct cmd_set_record_burst_stats_result {
8453         cmdline_fixed_string_t keyword;
8454         cmdline_fixed_string_t name;
8455         cmdline_fixed_string_t on_off;
8456 };
8457
8458 static void
8459 cmd_set_record_burst_stats_parsed(void *parsed_result,
8460                         __rte_unused struct cmdline *cl,
8461                         __rte_unused void *data)
8462 {
8463         struct cmd_set_record_burst_stats_result *res;
8464         uint16_t on_off = 0;
8465
8466         res = parsed_result;
8467         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8468         set_record_burst_stats(on_off);
8469 }
8470
8471 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8473                                  keyword, "set");
8474 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8475         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8476                                  name, "record-burst-stats");
8477 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8478         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8479                                  on_off, "on#off");
8480
8481 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8482         .f = cmd_set_record_burst_stats_parsed,
8483         .data = NULL,
8484         .help_str = "set record-burst-stats on|off",
8485         .tokens = {
8486                 (void *)&cmd_set_record_burst_stats_keyword,
8487                 (void *)&cmd_set_record_burst_stats_name,
8488                 (void *)&cmd_set_record_burst_stats_on_off,
8489                 NULL,
8490         },
8491 };
8492
8493 /* *** CONFIGURE UNICAST HASH TABLE *** */
8494 struct cmd_set_uc_hash_table {
8495         cmdline_fixed_string_t set;
8496         cmdline_fixed_string_t port;
8497         portid_t port_id;
8498         cmdline_fixed_string_t what;
8499         struct rte_ether_addr address;
8500         cmdline_fixed_string_t mode;
8501 };
8502
8503 static void
8504 cmd_set_uc_hash_parsed(void *parsed_result,
8505                        __rte_unused struct cmdline *cl,
8506                        __rte_unused void *data)
8507 {
8508         int ret=0;
8509         struct cmd_set_uc_hash_table *res = parsed_result;
8510
8511         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8512
8513         if (strcmp(res->what, "uta") == 0)
8514                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8515                                                 &res->address,(uint8_t)is_on);
8516         if (ret < 0)
8517                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8518
8519 }
8520
8521 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8522         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8523                                  set, "set");
8524 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8525         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8526                                  port, "port");
8527 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8528         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8529                               port_id, UINT16);
8530 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8531         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8532                                  what, "uta");
8533 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8534         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8535                                 address);
8536 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8537         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8538                                  mode, "on#off");
8539
8540 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8541         .f = cmd_set_uc_hash_parsed,
8542         .data = NULL,
8543         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8544         .tokens = {
8545                 (void *)&cmd_set_uc_hash_set,
8546                 (void *)&cmd_set_uc_hash_port,
8547                 (void *)&cmd_set_uc_hash_portid,
8548                 (void *)&cmd_set_uc_hash_what,
8549                 (void *)&cmd_set_uc_hash_mac,
8550                 (void *)&cmd_set_uc_hash_mode,
8551                 NULL,
8552         },
8553 };
8554
8555 struct cmd_set_uc_all_hash_table {
8556         cmdline_fixed_string_t set;
8557         cmdline_fixed_string_t port;
8558         portid_t port_id;
8559         cmdline_fixed_string_t what;
8560         cmdline_fixed_string_t value;
8561         cmdline_fixed_string_t mode;
8562 };
8563
8564 static void
8565 cmd_set_uc_all_hash_parsed(void *parsed_result,
8566                        __rte_unused struct cmdline *cl,
8567                        __rte_unused void *data)
8568 {
8569         int ret=0;
8570         struct cmd_set_uc_all_hash_table *res = parsed_result;
8571
8572         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8573
8574         if ((strcmp(res->what, "uta") == 0) &&
8575                 (strcmp(res->value, "all") == 0))
8576                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8577         if (ret < 0)
8578                 printf("bad unicast hash table parameter,"
8579                         "return code = %d \n", ret);
8580 }
8581
8582 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8583         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8584                                  set, "set");
8585 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8586         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8587                                  port, "port");
8588 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8589         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8590                               port_id, UINT16);
8591 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8592         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8593                                  what, "uta");
8594 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8595         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8596                                 value,"all");
8597 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8599                                  mode, "on#off");
8600
8601 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8602         .f = cmd_set_uc_all_hash_parsed,
8603         .data = NULL,
8604         .help_str = "set port <port_id> uta all on|off",
8605         .tokens = {
8606                 (void *)&cmd_set_uc_all_hash_set,
8607                 (void *)&cmd_set_uc_all_hash_port,
8608                 (void *)&cmd_set_uc_all_hash_portid,
8609                 (void *)&cmd_set_uc_all_hash_what,
8610                 (void *)&cmd_set_uc_all_hash_value,
8611                 (void *)&cmd_set_uc_all_hash_mode,
8612                 NULL,
8613         },
8614 };
8615
8616 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8617 struct cmd_set_vf_traffic {
8618         cmdline_fixed_string_t set;
8619         cmdline_fixed_string_t port;
8620         portid_t port_id;
8621         cmdline_fixed_string_t vf;
8622         uint8_t vf_id;
8623         cmdline_fixed_string_t what;
8624         cmdline_fixed_string_t mode;
8625 };
8626
8627 static void
8628 cmd_set_vf_traffic_parsed(void *parsed_result,
8629                        __rte_unused struct cmdline *cl,
8630                        __rte_unused void *data)
8631 {
8632         struct cmd_set_vf_traffic *res = parsed_result;
8633         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8634         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8635
8636         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8637 }
8638
8639 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8640         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8641                                  set, "set");
8642 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8643         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8644                                  port, "port");
8645 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8646         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8647                               port_id, UINT16);
8648 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8649         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8650                                  vf, "vf");
8651 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8652         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8653                               vf_id, UINT8);
8654 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8655         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8656                                  what, "tx#rx");
8657 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8658         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8659                                  mode, "on#off");
8660
8661 cmdline_parse_inst_t cmd_set_vf_traffic = {
8662         .f = cmd_set_vf_traffic_parsed,
8663         .data = NULL,
8664         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8665         .tokens = {
8666                 (void *)&cmd_setvf_traffic_set,
8667                 (void *)&cmd_setvf_traffic_port,
8668                 (void *)&cmd_setvf_traffic_portid,
8669                 (void *)&cmd_setvf_traffic_vf,
8670                 (void *)&cmd_setvf_traffic_vfid,
8671                 (void *)&cmd_setvf_traffic_what,
8672                 (void *)&cmd_setvf_traffic_mode,
8673                 NULL,
8674         },
8675 };
8676
8677 /* *** CONFIGURE VF RECEIVE MODE *** */
8678 struct cmd_set_vf_rxmode {
8679         cmdline_fixed_string_t set;
8680         cmdline_fixed_string_t port;
8681         portid_t port_id;
8682         cmdline_fixed_string_t vf;
8683         uint8_t vf_id;
8684         cmdline_fixed_string_t what;
8685         cmdline_fixed_string_t mode;
8686         cmdline_fixed_string_t on;
8687 };
8688
8689 static void
8690 cmd_set_vf_rxmode_parsed(void *parsed_result,
8691                        __rte_unused struct cmdline *cl,
8692                        __rte_unused void *data)
8693 {
8694         int ret = -ENOTSUP;
8695         uint16_t vf_rxmode = 0;
8696         struct cmd_set_vf_rxmode *res = parsed_result;
8697
8698         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8699         if (!strcmp(res->what,"rxmode")) {
8700                 if (!strcmp(res->mode, "AUPE"))
8701                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8702                 else if (!strcmp(res->mode, "ROPE"))
8703                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8704                 else if (!strcmp(res->mode, "BAM"))
8705                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8706                 else if (!strncmp(res->mode, "MPE",3))
8707                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8708         }
8709
8710         RTE_SET_USED(is_on);
8711
8712 #ifdef RTE_NET_IXGBE
8713         if (ret == -ENOTSUP)
8714                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8715                                                   vf_rxmode, (uint8_t)is_on);
8716 #endif
8717 #ifdef RTE_NET_BNXT
8718         if (ret == -ENOTSUP)
8719                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8720                                                  vf_rxmode, (uint8_t)is_on);
8721 #endif
8722         if (ret < 0)
8723                 printf("bad VF receive mode parameter, return code = %d \n",
8724                 ret);
8725 }
8726
8727 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8728         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8729                                  set, "set");
8730 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8731         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8732                                  port, "port");
8733 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8734         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8735                               port_id, UINT16);
8736 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8737         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8738                                  vf, "vf");
8739 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8740         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8741                               vf_id, UINT8);
8742 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8743         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8744                                  what, "rxmode");
8745 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8746         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8747                                  mode, "AUPE#ROPE#BAM#MPE");
8748 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8749         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8750                                  on, "on#off");
8751
8752 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8753         .f = cmd_set_vf_rxmode_parsed,
8754         .data = NULL,
8755         .help_str = "set port <port_id> vf <vf_id> rxmode "
8756                 "AUPE|ROPE|BAM|MPE on|off",
8757         .tokens = {
8758                 (void *)&cmd_set_vf_rxmode_set,
8759                 (void *)&cmd_set_vf_rxmode_port,
8760                 (void *)&cmd_set_vf_rxmode_portid,
8761                 (void *)&cmd_set_vf_rxmode_vf,
8762                 (void *)&cmd_set_vf_rxmode_vfid,
8763                 (void *)&cmd_set_vf_rxmode_what,
8764                 (void *)&cmd_set_vf_rxmode_mode,
8765                 (void *)&cmd_set_vf_rxmode_on,
8766                 NULL,
8767         },
8768 };
8769
8770 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8771 struct cmd_vf_mac_addr_result {
8772         cmdline_fixed_string_t mac_addr_cmd;
8773         cmdline_fixed_string_t what;
8774         cmdline_fixed_string_t port;
8775         uint16_t port_num;
8776         cmdline_fixed_string_t vf;
8777         uint8_t vf_num;
8778         struct rte_ether_addr address;
8779 };
8780
8781 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8782                 __rte_unused struct cmdline *cl,
8783                 __rte_unused void *data)
8784 {
8785         struct cmd_vf_mac_addr_result *res = parsed_result;
8786         int ret = -ENOTSUP;
8787
8788         if (strcmp(res->what, "add") != 0)
8789                 return;
8790
8791 #ifdef RTE_NET_I40E
8792         if (ret == -ENOTSUP)
8793                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8794                                                    &res->address);
8795 #endif
8796 #ifdef RTE_NET_BNXT
8797         if (ret == -ENOTSUP)
8798                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8799                                                 res->vf_num);
8800 #endif
8801
8802         if(ret < 0)
8803                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8804
8805 }
8806
8807 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8808         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8809                                 mac_addr_cmd,"mac_addr");
8810 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8811         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8812                                 what,"add");
8813 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8814         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8815                                 port,"port");
8816 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8817         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8818                                 port_num, UINT16);
8819 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8820         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8821                                 vf,"vf");
8822 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8823         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8824                                 vf_num, UINT8);
8825 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8826         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8827                                 address);
8828
8829 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8830         .f = cmd_vf_mac_addr_parsed,
8831         .data = (void *)0,
8832         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8833                 "Add MAC address filtering for a VF on port_id",
8834         .tokens = {
8835                 (void *)&cmd_vf_mac_addr_cmd,
8836                 (void *)&cmd_vf_mac_addr_what,
8837                 (void *)&cmd_vf_mac_addr_port,
8838                 (void *)&cmd_vf_mac_addr_portnum,
8839                 (void *)&cmd_vf_mac_addr_vf,
8840                 (void *)&cmd_vf_mac_addr_vfnum,
8841                 (void *)&cmd_vf_mac_addr_addr,
8842                 NULL,
8843         },
8844 };
8845
8846 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8847 struct cmd_vf_rx_vlan_filter {
8848         cmdline_fixed_string_t rx_vlan;
8849         cmdline_fixed_string_t what;
8850         uint16_t vlan_id;
8851         cmdline_fixed_string_t port;
8852         portid_t port_id;
8853         cmdline_fixed_string_t vf;
8854         uint64_t vf_mask;
8855 };
8856
8857 static void
8858 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8859                           __rte_unused struct cmdline *cl,
8860                           __rte_unused void *data)
8861 {
8862         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8863         int ret = -ENOTSUP;
8864
8865         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8866
8867 #ifdef RTE_NET_IXGBE
8868         if (ret == -ENOTSUP)
8869                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8870                                 res->vlan_id, res->vf_mask, is_add);
8871 #endif
8872 #ifdef RTE_NET_I40E
8873         if (ret == -ENOTSUP)
8874                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8875                                 res->vlan_id, res->vf_mask, is_add);
8876 #endif
8877 #ifdef RTE_NET_BNXT
8878         if (ret == -ENOTSUP)
8879                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8880                                 res->vlan_id, res->vf_mask, is_add);
8881 #endif
8882
8883         switch (ret) {
8884         case 0:
8885                 break;
8886         case -EINVAL:
8887                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8888                                 res->vlan_id, res->vf_mask);
8889                 break;
8890         case -ENODEV:
8891                 printf("invalid port_id %d\n", res->port_id);
8892                 break;
8893         case -ENOTSUP:
8894                 printf("function not implemented or supported\n");
8895                 break;
8896         default:
8897                 printf("programming error: (%s)\n", strerror(-ret));
8898         }
8899 }
8900
8901 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8902         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8903                                  rx_vlan, "rx_vlan");
8904 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8905         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8906                                  what, "add#rm");
8907 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8908         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8909                               vlan_id, UINT16);
8910 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8911         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8912                                  port, "port");
8913 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8914         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8915                               port_id, UINT16);
8916 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8917         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8918                                  vf, "vf");
8919 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8920         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8921                               vf_mask, UINT64);
8922
8923 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8924         .f = cmd_vf_rx_vlan_filter_parsed,
8925         .data = NULL,
8926         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8927                 "(vf_mask = hexadecimal VF mask)",
8928         .tokens = {
8929                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8930                 (void *)&cmd_vf_rx_vlan_filter_what,
8931                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8932                 (void *)&cmd_vf_rx_vlan_filter_port,
8933                 (void *)&cmd_vf_rx_vlan_filter_portid,
8934                 (void *)&cmd_vf_rx_vlan_filter_vf,
8935                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8936                 NULL,
8937         },
8938 };
8939
8940 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8941 struct cmd_queue_rate_limit_result {
8942         cmdline_fixed_string_t set;
8943         cmdline_fixed_string_t port;
8944         uint16_t port_num;
8945         cmdline_fixed_string_t queue;
8946         uint8_t queue_num;
8947         cmdline_fixed_string_t rate;
8948         uint16_t rate_num;
8949 };
8950
8951 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8952                 __rte_unused struct cmdline *cl,
8953                 __rte_unused void *data)
8954 {
8955         struct cmd_queue_rate_limit_result *res = parsed_result;
8956         int ret = 0;
8957
8958         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8959                 && (strcmp(res->queue, "queue") == 0)
8960                 && (strcmp(res->rate, "rate") == 0))
8961                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8962                                         res->rate_num);
8963         if (ret < 0)
8964                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8965
8966 }
8967
8968 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8969         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8970                                 set, "set");
8971 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8972         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8973                                 port, "port");
8974 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8975         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8976                                 port_num, UINT16);
8977 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8978         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8979                                 queue, "queue");
8980 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8981         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8982                                 queue_num, UINT8);
8983 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8984         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8985                                 rate, "rate");
8986 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8987         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8988                                 rate_num, UINT16);
8989
8990 cmdline_parse_inst_t cmd_queue_rate_limit = {
8991         .f = cmd_queue_rate_limit_parsed,
8992         .data = (void *)0,
8993         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8994                 "Set rate limit for a queue on port_id",
8995         .tokens = {
8996                 (void *)&cmd_queue_rate_limit_set,
8997                 (void *)&cmd_queue_rate_limit_port,
8998                 (void *)&cmd_queue_rate_limit_portnum,
8999                 (void *)&cmd_queue_rate_limit_queue,
9000                 (void *)&cmd_queue_rate_limit_queuenum,
9001                 (void *)&cmd_queue_rate_limit_rate,
9002                 (void *)&cmd_queue_rate_limit_ratenum,
9003                 NULL,
9004         },
9005 };
9006
9007 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9008 struct cmd_vf_rate_limit_result {
9009         cmdline_fixed_string_t set;
9010         cmdline_fixed_string_t port;
9011         uint16_t port_num;
9012         cmdline_fixed_string_t vf;
9013         uint8_t vf_num;
9014         cmdline_fixed_string_t rate;
9015         uint16_t rate_num;
9016         cmdline_fixed_string_t q_msk;
9017         uint64_t q_msk_val;
9018 };
9019
9020 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9021                 __rte_unused struct cmdline *cl,
9022                 __rte_unused void *data)
9023 {
9024         struct cmd_vf_rate_limit_result *res = parsed_result;
9025         int ret = 0;
9026
9027         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9028                 && (strcmp(res->vf, "vf") == 0)
9029                 && (strcmp(res->rate, "rate") == 0)
9030                 && (strcmp(res->q_msk, "queue_mask") == 0))
9031                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9032                                         res->rate_num, res->q_msk_val);
9033         if (ret < 0)
9034                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9035
9036 }
9037
9038 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9039         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9040                                 set, "set");
9041 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9042         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9043                                 port, "port");
9044 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9045         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9046                                 port_num, UINT16);
9047 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9048         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9049                                 vf, "vf");
9050 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9051         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9052                                 vf_num, UINT8);
9053 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9054         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9055                                 rate, "rate");
9056 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9057         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9058                                 rate_num, UINT16);
9059 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9060         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9061                                 q_msk, "queue_mask");
9062 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9063         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9064                                 q_msk_val, UINT64);
9065
9066 cmdline_parse_inst_t cmd_vf_rate_limit = {
9067         .f = cmd_vf_rate_limit_parsed,
9068         .data = (void *)0,
9069         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9070                 "queue_mask <queue_mask_value>: "
9071                 "Set rate limit for queues of VF on port_id",
9072         .tokens = {
9073                 (void *)&cmd_vf_rate_limit_set,
9074                 (void *)&cmd_vf_rate_limit_port,
9075                 (void *)&cmd_vf_rate_limit_portnum,
9076                 (void *)&cmd_vf_rate_limit_vf,
9077                 (void *)&cmd_vf_rate_limit_vfnum,
9078                 (void *)&cmd_vf_rate_limit_rate,
9079                 (void *)&cmd_vf_rate_limit_ratenum,
9080                 (void *)&cmd_vf_rate_limit_q_msk,
9081                 (void *)&cmd_vf_rate_limit_q_msk_val,
9082                 NULL,
9083         },
9084 };
9085
9086 /* *** CONFIGURE TUNNEL UDP PORT *** */
9087 struct cmd_tunnel_udp_config {
9088         cmdline_fixed_string_t cmd;
9089         cmdline_fixed_string_t what;
9090         uint16_t udp_port;
9091         portid_t port_id;
9092 };
9093
9094 static void
9095 cmd_tunnel_udp_config_parsed(void *parsed_result,
9096                           __rte_unused struct cmdline *cl,
9097                           __rte_unused void *data)
9098 {
9099         struct cmd_tunnel_udp_config *res = parsed_result;
9100         struct rte_eth_udp_tunnel tunnel_udp;
9101         int ret;
9102
9103         tunnel_udp.udp_port = res->udp_port;
9104
9105         if (!strcmp(res->cmd, "rx_vxlan_port"))
9106                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9107
9108         if (!strcmp(res->what, "add"))
9109                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9110                                                       &tunnel_udp);
9111         else
9112                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9113                                                          &tunnel_udp);
9114
9115         if (ret < 0)
9116                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9117 }
9118
9119 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9120         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9121                                 cmd, "rx_vxlan_port");
9122 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9123         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9124                                 what, "add#rm");
9125 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9126         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9127                                 udp_port, UINT16);
9128 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9129         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9130                                 port_id, UINT16);
9131
9132 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9133         .f = cmd_tunnel_udp_config_parsed,
9134         .data = (void *)0,
9135         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9136                 "Add/Remove a tunneling UDP port filter",
9137         .tokens = {
9138                 (void *)&cmd_tunnel_udp_config_cmd,
9139                 (void *)&cmd_tunnel_udp_config_what,
9140                 (void *)&cmd_tunnel_udp_config_udp_port,
9141                 (void *)&cmd_tunnel_udp_config_port_id,
9142                 NULL,
9143         },
9144 };
9145
9146 struct cmd_config_tunnel_udp_port {
9147         cmdline_fixed_string_t port;
9148         cmdline_fixed_string_t config;
9149         portid_t port_id;
9150         cmdline_fixed_string_t udp_tunnel_port;
9151         cmdline_fixed_string_t action;
9152         cmdline_fixed_string_t tunnel_type;
9153         uint16_t udp_port;
9154 };
9155
9156 static void
9157 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9158                                __rte_unused struct cmdline *cl,
9159                                __rte_unused void *data)
9160 {
9161         struct cmd_config_tunnel_udp_port *res = parsed_result;
9162         struct rte_eth_udp_tunnel tunnel_udp;
9163         int ret = 0;
9164
9165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9166                 return;
9167
9168         tunnel_udp.udp_port = res->udp_port;
9169
9170         if (!strcmp(res->tunnel_type, "vxlan")) {
9171                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9172         } else if (!strcmp(res->tunnel_type, "geneve")) {
9173                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9174         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9176         } else {
9177                 printf("Invalid tunnel type\n");
9178                 return;
9179         }
9180
9181         if (!strcmp(res->action, "add"))
9182                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9183                                                       &tunnel_udp);
9184         else
9185                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9186                                                          &tunnel_udp);
9187
9188         if (ret < 0)
9189                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9190 }
9191
9192 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9193         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9194                                  "port");
9195 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9196         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9197                                  "config");
9198 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9199         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9200                               UINT16);
9201 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9202         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9203                                  udp_tunnel_port,
9204                                  "udp_tunnel_port");
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9206         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9207                                  "add#rm");
9208 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9209         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9210                                  "vxlan#geneve#vxlan-gpe");
9211 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9212         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9213                               UINT16);
9214
9215 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9216         .f = cmd_cfg_tunnel_udp_port_parsed,
9217         .data = NULL,
9218         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9219         .tokens = {
9220                 (void *)&cmd_config_tunnel_udp_port_port,
9221                 (void *)&cmd_config_tunnel_udp_port_config,
9222                 (void *)&cmd_config_tunnel_udp_port_port_id,
9223                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9224                 (void *)&cmd_config_tunnel_udp_port_action,
9225                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9226                 (void *)&cmd_config_tunnel_udp_port_value,
9227                 NULL,
9228         },
9229 };
9230
9231 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9232 struct cmd_set_mirror_mask_result {
9233         cmdline_fixed_string_t set;
9234         cmdline_fixed_string_t port;
9235         portid_t port_id;
9236         cmdline_fixed_string_t mirror;
9237         uint8_t rule_id;
9238         cmdline_fixed_string_t what;
9239         cmdline_fixed_string_t value;
9240         cmdline_fixed_string_t dstpool;
9241         uint8_t dstpool_id;
9242         cmdline_fixed_string_t on;
9243 };
9244
9245 cmdline_parse_token_string_t cmd_mirror_mask_set =
9246         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9247                                 set, "set");
9248 cmdline_parse_token_string_t cmd_mirror_mask_port =
9249         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9250                                 port, "port");
9251 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9252         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9253                                 port_id, UINT16);
9254 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9255         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9256                                 mirror, "mirror-rule");
9257 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9258         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9259                                 rule_id, UINT8);
9260 cmdline_parse_token_string_t cmd_mirror_mask_what =
9261         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9262                                 what, "pool-mirror-up#pool-mirror-down"
9263                                       "#vlan-mirror");
9264 cmdline_parse_token_string_t cmd_mirror_mask_value =
9265         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9266                                 value, NULL);
9267 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9268         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9269                                 dstpool, "dst-pool");
9270 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9271         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9272                                 dstpool_id, UINT8);
9273 cmdline_parse_token_string_t cmd_mirror_mask_on =
9274         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9275                                 on, "on#off");
9276
9277 static void
9278 cmd_set_mirror_mask_parsed(void *parsed_result,
9279                        __rte_unused struct cmdline *cl,
9280                        __rte_unused void *data)
9281 {
9282         int ret,nb_item,i;
9283         struct cmd_set_mirror_mask_result *res = parsed_result;
9284         struct rte_eth_mirror_conf mr_conf;
9285
9286         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9287
9288         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9289
9290         mr_conf.dst_pool = res->dstpool_id;
9291
9292         if (!strcmp(res->what, "pool-mirror-up")) {
9293                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9294                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9295         } else if (!strcmp(res->what, "pool-mirror-down")) {
9296                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9297                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9298         } else if (!strcmp(res->what, "vlan-mirror")) {
9299                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9300                 nb_item = parse_item_list(res->value, "vlan",
9301                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9302                 if (nb_item <= 0)
9303                         return;
9304
9305                 for (i = 0; i < nb_item; i++) {
9306                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9307                                 printf("Invalid vlan_id: must be < 4096\n");
9308                                 return;
9309                         }
9310
9311                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9312                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9313                 }
9314         }
9315
9316         if (!strcmp(res->on, "on"))
9317                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9318                                                 res->rule_id, 1);
9319         else
9320                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9321                                                 res->rule_id, 0);
9322         if (ret < 0)
9323                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9324 }
9325
9326 cmdline_parse_inst_t cmd_set_mirror_mask = {
9327                 .f = cmd_set_mirror_mask_parsed,
9328                 .data = NULL,
9329                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9330                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9331                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9332                 .tokens = {
9333                         (void *)&cmd_mirror_mask_set,
9334                         (void *)&cmd_mirror_mask_port,
9335                         (void *)&cmd_mirror_mask_portid,
9336                         (void *)&cmd_mirror_mask_mirror,
9337                         (void *)&cmd_mirror_mask_ruleid,
9338                         (void *)&cmd_mirror_mask_what,
9339                         (void *)&cmd_mirror_mask_value,
9340                         (void *)&cmd_mirror_mask_dstpool,
9341                         (void *)&cmd_mirror_mask_poolid,
9342                         (void *)&cmd_mirror_mask_on,
9343                         NULL,
9344                 },
9345 };
9346
9347 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9348 struct cmd_set_mirror_link_result {
9349         cmdline_fixed_string_t set;
9350         cmdline_fixed_string_t port;
9351         portid_t port_id;
9352         cmdline_fixed_string_t mirror;
9353         uint8_t rule_id;
9354         cmdline_fixed_string_t what;
9355         cmdline_fixed_string_t dstpool;
9356         uint8_t dstpool_id;
9357         cmdline_fixed_string_t on;
9358 };
9359
9360 cmdline_parse_token_string_t cmd_mirror_link_set =
9361         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9362                                  set, "set");
9363 cmdline_parse_token_string_t cmd_mirror_link_port =
9364         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9365                                 port, "port");
9366 cmdline_parse_token_num_t cmd_mirror_link_portid =
9367         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9368                                 port_id, UINT16);
9369 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9370         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9371                                 mirror, "mirror-rule");
9372 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9373         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9374                             rule_id, UINT8);
9375 cmdline_parse_token_string_t cmd_mirror_link_what =
9376         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9377                                 what, "uplink-mirror#downlink-mirror");
9378 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9379         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9380                                 dstpool, "dst-pool");
9381 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9382         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9383                                 dstpool_id, UINT8);
9384 cmdline_parse_token_string_t cmd_mirror_link_on =
9385         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9386                                 on, "on#off");
9387
9388 static void
9389 cmd_set_mirror_link_parsed(void *parsed_result,
9390                        __rte_unused struct cmdline *cl,
9391                        __rte_unused void *data)
9392 {
9393         int ret;
9394         struct cmd_set_mirror_link_result *res = parsed_result;
9395         struct rte_eth_mirror_conf mr_conf;
9396
9397         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9398         if (!strcmp(res->what, "uplink-mirror"))
9399                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9400         else
9401                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9402
9403         mr_conf.dst_pool = res->dstpool_id;
9404
9405         if (!strcmp(res->on, "on"))
9406                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9407                                                 res->rule_id, 1);
9408         else
9409                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9410                                                 res->rule_id, 0);
9411
9412         /* check the return value and print it if is < 0 */
9413         if (ret < 0)
9414                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9415
9416 }
9417
9418 cmdline_parse_inst_t cmd_set_mirror_link = {
9419                 .f = cmd_set_mirror_link_parsed,
9420                 .data = NULL,
9421                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9422                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9423                 .tokens = {
9424                         (void *)&cmd_mirror_link_set,
9425                         (void *)&cmd_mirror_link_port,
9426                         (void *)&cmd_mirror_link_portid,
9427                         (void *)&cmd_mirror_link_mirror,
9428                         (void *)&cmd_mirror_link_ruleid,
9429                         (void *)&cmd_mirror_link_what,
9430                         (void *)&cmd_mirror_link_dstpool,
9431                         (void *)&cmd_mirror_link_poolid,
9432                         (void *)&cmd_mirror_link_on,
9433                         NULL,
9434                 },
9435 };
9436
9437 /* *** RESET VM MIRROR RULE *** */
9438 struct cmd_rm_mirror_rule_result {
9439         cmdline_fixed_string_t reset;
9440         cmdline_fixed_string_t port;
9441         portid_t port_id;
9442         cmdline_fixed_string_t mirror;
9443         uint8_t rule_id;
9444 };
9445
9446 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9447         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9448                                  reset, "reset");
9449 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9450         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9451                                 port, "port");
9452 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9453         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9454                                 port_id, UINT16);
9455 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9456         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9457                                 mirror, "mirror-rule");
9458 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9459         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9460                                 rule_id, UINT8);
9461
9462 static void
9463 cmd_reset_mirror_rule_parsed(void *parsed_result,
9464                        __rte_unused struct cmdline *cl,
9465                        __rte_unused void *data)
9466 {
9467         int ret;
9468         struct cmd_set_mirror_link_result *res = parsed_result;
9469         /* check rule_id */
9470         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9471         if(ret < 0)
9472                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9473 }
9474
9475 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9476                 .f = cmd_reset_mirror_rule_parsed,
9477                 .data = NULL,
9478                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9479                 .tokens = {
9480                         (void *)&cmd_rm_mirror_rule_reset,
9481                         (void *)&cmd_rm_mirror_rule_port,
9482                         (void *)&cmd_rm_mirror_rule_portid,
9483                         (void *)&cmd_rm_mirror_rule_mirror,
9484                         (void *)&cmd_rm_mirror_rule_ruleid,
9485                         NULL,
9486                 },
9487 };
9488
9489 /* ******************************************************************************** */
9490
9491 struct cmd_dump_result {
9492         cmdline_fixed_string_t dump;
9493 };
9494
9495 static void
9496 dump_struct_sizes(void)
9497 {
9498 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9499         DUMP_SIZE(struct rte_mbuf);
9500         DUMP_SIZE(struct rte_mempool);
9501         DUMP_SIZE(struct rte_ring);
9502 #undef DUMP_SIZE
9503 }
9504
9505
9506 /* Dump the socket memory statistics on console */
9507 static void
9508 dump_socket_mem(FILE *f)
9509 {
9510         struct rte_malloc_socket_stats socket_stats;
9511         unsigned int i;
9512         size_t total = 0;
9513         size_t alloc = 0;
9514         size_t free = 0;
9515         unsigned int n_alloc = 0;
9516         unsigned int n_free = 0;
9517         static size_t last_allocs;
9518         static size_t last_total;
9519
9520
9521         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9522                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9523                     !socket_stats.heap_totalsz_bytes)
9524                         continue;
9525                 total += socket_stats.heap_totalsz_bytes;
9526                 alloc += socket_stats.heap_allocsz_bytes;
9527                 free += socket_stats.heap_freesz_bytes;
9528                 n_alloc += socket_stats.alloc_count;
9529                 n_free += socket_stats.free_count;
9530                 fprintf(f,
9531                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9532                         i,
9533                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9534                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9535                         (double)socket_stats.heap_allocsz_bytes * 100 /
9536                         (double)socket_stats.heap_totalsz_bytes,
9537                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9538                         socket_stats.alloc_count,
9539                         socket_stats.free_count);
9540         }
9541         fprintf(f,
9542                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9543                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9544                 (double)alloc * 100 / (double)total,
9545                 (double)free / (1024 * 1024),
9546                 n_alloc, n_free);
9547         if (last_allocs)
9548                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9549                         ((double)total - (double)last_total) / (1024 * 1024),
9550                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9551         last_allocs = alloc;
9552         last_total = total;
9553 }
9554
9555 static void cmd_dump_parsed(void *parsed_result,
9556                             __rte_unused struct cmdline *cl,
9557                             __rte_unused void *data)
9558 {
9559         struct cmd_dump_result *res = parsed_result;
9560
9561         if (!strcmp(res->dump, "dump_physmem"))
9562                 rte_dump_physmem_layout(stdout);
9563         else if (!strcmp(res->dump, "dump_socket_mem"))
9564                 dump_socket_mem(stdout);
9565         else if (!strcmp(res->dump, "dump_memzone"))
9566                 rte_memzone_dump(stdout);
9567         else if (!strcmp(res->dump, "dump_struct_sizes"))
9568                 dump_struct_sizes();
9569         else if (!strcmp(res->dump, "dump_ring"))
9570                 rte_ring_list_dump(stdout);
9571         else if (!strcmp(res->dump, "dump_mempool"))
9572                 rte_mempool_list_dump(stdout);
9573         else if (!strcmp(res->dump, "dump_devargs"))
9574                 rte_devargs_dump(stdout);
9575         else if (!strcmp(res->dump, "dump_log_types"))
9576                 rte_log_dump(stdout);
9577 }
9578
9579 cmdline_parse_token_string_t cmd_dump_dump =
9580         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9581                 "dump_physmem#"
9582                 "dump_memzone#"
9583                 "dump_socket_mem#"
9584                 "dump_struct_sizes#"
9585                 "dump_ring#"
9586                 "dump_mempool#"
9587                 "dump_devargs#"
9588                 "dump_log_types");
9589
9590 cmdline_parse_inst_t cmd_dump = {
9591         .f = cmd_dump_parsed,  /* function to call */
9592         .data = NULL,      /* 2nd arg of func */
9593         .help_str = "Dump status",
9594         .tokens = {        /* token list, NULL terminated */
9595                 (void *)&cmd_dump_dump,
9596                 NULL,
9597         },
9598 };
9599
9600 /* ******************************************************************************** */
9601
9602 struct cmd_dump_one_result {
9603         cmdline_fixed_string_t dump;
9604         cmdline_fixed_string_t name;
9605 };
9606
9607 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9608                                 __rte_unused void *data)
9609 {
9610         struct cmd_dump_one_result *res = parsed_result;
9611
9612         if (!strcmp(res->dump, "dump_ring")) {
9613                 struct rte_ring *r;
9614                 r = rte_ring_lookup(res->name);
9615                 if (r == NULL) {
9616                         cmdline_printf(cl, "Cannot find ring\n");
9617                         return;
9618                 }
9619                 rte_ring_dump(stdout, r);
9620         } else if (!strcmp(res->dump, "dump_mempool")) {
9621                 struct rte_mempool *mp;
9622                 mp = rte_mempool_lookup(res->name);
9623                 if (mp == NULL) {
9624                         cmdline_printf(cl, "Cannot find mempool\n");
9625                         return;
9626                 }
9627                 rte_mempool_dump(stdout, mp);
9628         }
9629 }
9630
9631 cmdline_parse_token_string_t cmd_dump_one_dump =
9632         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9633                                  "dump_ring#dump_mempool");
9634
9635 cmdline_parse_token_string_t cmd_dump_one_name =
9636         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9637
9638 cmdline_parse_inst_t cmd_dump_one = {
9639         .f = cmd_dump_one_parsed,  /* function to call */
9640         .data = NULL,      /* 2nd arg of func */
9641         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9642         .tokens = {        /* token list, NULL terminated */
9643                 (void *)&cmd_dump_one_dump,
9644                 (void *)&cmd_dump_one_name,
9645                 NULL,
9646         },
9647 };
9648
9649 /* *** queue region set *** */
9650 struct cmd_queue_region_result {
9651         cmdline_fixed_string_t set;
9652         cmdline_fixed_string_t port;
9653         portid_t port_id;
9654         cmdline_fixed_string_t cmd;
9655         cmdline_fixed_string_t region;
9656         uint8_t  region_id;
9657         cmdline_fixed_string_t queue_start_index;
9658         uint8_t  queue_id;
9659         cmdline_fixed_string_t queue_num;
9660         uint8_t  queue_num_value;
9661 };
9662
9663 static void
9664 cmd_queue_region_parsed(void *parsed_result,
9665                         __rte_unused struct cmdline *cl,
9666                         __rte_unused void *data)
9667 {
9668         struct cmd_queue_region_result *res = parsed_result;
9669         int ret = -ENOTSUP;
9670 #ifdef RTE_NET_I40E
9671         struct rte_pmd_i40e_queue_region_conf region_conf;
9672         enum rte_pmd_i40e_queue_region_op op_type;
9673 #endif
9674
9675         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9676                 return;
9677
9678 #ifdef RTE_NET_I40E
9679         memset(&region_conf, 0, sizeof(region_conf));
9680         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9681         region_conf.region_id = res->region_id;
9682         region_conf.queue_num = res->queue_num_value;
9683         region_conf.queue_start_index = res->queue_id;
9684
9685         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9686                                 op_type, &region_conf);
9687 #endif
9688
9689         switch (ret) {
9690         case 0:
9691                 break;
9692         case -ENOTSUP:
9693                 printf("function not implemented or supported\n");
9694                 break;
9695         default:
9696                 printf("queue region config error: (%s)\n", strerror(-ret));
9697         }
9698 }
9699
9700 cmdline_parse_token_string_t cmd_queue_region_set =
9701 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9702                 set, "set");
9703 cmdline_parse_token_string_t cmd_queue_region_port =
9704         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9705 cmdline_parse_token_num_t cmd_queue_region_port_id =
9706         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9707                                 port_id, UINT16);
9708 cmdline_parse_token_string_t cmd_queue_region_cmd =
9709         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9710                                  cmd, "queue-region");
9711 cmdline_parse_token_string_t cmd_queue_region_id =
9712         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9713                                 region, "region_id");
9714 cmdline_parse_token_num_t cmd_queue_region_index =
9715         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9716                                 region_id, UINT8);
9717 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9718         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9719                                 queue_start_index, "queue_start_index");
9720 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9721         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9722                                 queue_id, UINT8);
9723 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9724         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9725                                 queue_num, "queue_num");
9726 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9727         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9728                                 queue_num_value, UINT8);
9729
9730 cmdline_parse_inst_t cmd_queue_region = {
9731         .f = cmd_queue_region_parsed,
9732         .data = NULL,
9733         .help_str = "set port <port_id> queue-region region_id <value> "
9734                 "queue_start_index <value> queue_num <value>: Set a queue region",
9735         .tokens = {
9736                 (void *)&cmd_queue_region_set,
9737                 (void *)&cmd_queue_region_port,
9738                 (void *)&cmd_queue_region_port_id,
9739                 (void *)&cmd_queue_region_cmd,
9740                 (void *)&cmd_queue_region_id,
9741                 (void *)&cmd_queue_region_index,
9742                 (void *)&cmd_queue_region_queue_start_index,
9743                 (void *)&cmd_queue_region_queue_id,
9744                 (void *)&cmd_queue_region_queue_num,
9745                 (void *)&cmd_queue_region_queue_num_value,
9746                 NULL,
9747         },
9748 };
9749
9750 /* *** queue region and flowtype set *** */
9751 struct cmd_region_flowtype_result {
9752         cmdline_fixed_string_t set;
9753         cmdline_fixed_string_t port;
9754         portid_t port_id;
9755         cmdline_fixed_string_t cmd;
9756         cmdline_fixed_string_t region;
9757         uint8_t  region_id;
9758         cmdline_fixed_string_t flowtype;
9759         uint8_t  flowtype_id;
9760 };
9761
9762 static void
9763 cmd_region_flowtype_parsed(void *parsed_result,
9764                         __rte_unused struct cmdline *cl,
9765                         __rte_unused void *data)
9766 {
9767         struct cmd_region_flowtype_result *res = parsed_result;
9768         int ret = -ENOTSUP;
9769 #ifdef RTE_NET_I40E
9770         struct rte_pmd_i40e_queue_region_conf region_conf;
9771         enum rte_pmd_i40e_queue_region_op op_type;
9772 #endif
9773
9774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9775                 return;
9776
9777 #ifdef RTE_NET_I40E
9778         memset(&region_conf, 0, sizeof(region_conf));
9779
9780         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9781         region_conf.region_id = res->region_id;
9782         region_conf.hw_flowtype = res->flowtype_id;
9783
9784         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9785                         op_type, &region_conf);
9786 #endif
9787
9788         switch (ret) {
9789         case 0:
9790                 break;
9791         case -ENOTSUP:
9792                 printf("function not implemented or supported\n");
9793                 break;
9794         default:
9795                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9796         }
9797 }
9798
9799 cmdline_parse_token_string_t cmd_region_flowtype_set =
9800 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9801                                 set, "set");
9802 cmdline_parse_token_string_t cmd_region_flowtype_port =
9803         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9804                                 port, "port");
9805 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9806         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9807                                 port_id, UINT16);
9808 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9809         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9810                                 cmd, "queue-region");
9811 cmdline_parse_token_string_t cmd_region_flowtype_index =
9812         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9813                                 region, "region_id");
9814 cmdline_parse_token_num_t cmd_region_flowtype_id =
9815         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9816                                 region_id, UINT8);
9817 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9818         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9819                                 flowtype, "flowtype");
9820 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9821         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9822                                 flowtype_id, UINT8);
9823 cmdline_parse_inst_t cmd_region_flowtype = {
9824         .f = cmd_region_flowtype_parsed,
9825         .data = NULL,
9826         .help_str = "set port <port_id> queue-region region_id <value> "
9827                 "flowtype <value>: Set a flowtype region index",
9828         .tokens = {
9829                 (void *)&cmd_region_flowtype_set,
9830                 (void *)&cmd_region_flowtype_port,
9831                 (void *)&cmd_region_flowtype_port_index,
9832                 (void *)&cmd_region_flowtype_cmd,
9833                 (void *)&cmd_region_flowtype_index,
9834                 (void *)&cmd_region_flowtype_id,
9835                 (void *)&cmd_region_flowtype_flow_index,
9836                 (void *)&cmd_region_flowtype_flow_id,
9837                 NULL,
9838         },
9839 };
9840
9841 /* *** User Priority (UP) to queue region (region_id) set *** */
9842 struct cmd_user_priority_region_result {
9843         cmdline_fixed_string_t set;
9844         cmdline_fixed_string_t port;
9845         portid_t port_id;
9846         cmdline_fixed_string_t cmd;
9847         cmdline_fixed_string_t user_priority;
9848         uint8_t  user_priority_id;
9849         cmdline_fixed_string_t region;
9850         uint8_t  region_id;
9851 };
9852
9853 static void
9854 cmd_user_priority_region_parsed(void *parsed_result,
9855                         __rte_unused struct cmdline *cl,
9856                         __rte_unused void *data)
9857 {
9858         struct cmd_user_priority_region_result *res = parsed_result;
9859         int ret = -ENOTSUP;
9860 #ifdef RTE_NET_I40E
9861         struct rte_pmd_i40e_queue_region_conf region_conf;
9862         enum rte_pmd_i40e_queue_region_op op_type;
9863 #endif
9864
9865         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9866                 return;
9867
9868 #ifdef RTE_NET_I40E
9869         memset(&region_conf, 0, sizeof(region_conf));
9870         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9871         region_conf.user_priority = res->user_priority_id;
9872         region_conf.region_id = res->region_id;
9873
9874         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9875                                 op_type, &region_conf);
9876 #endif
9877
9878         switch (ret) {
9879         case 0:
9880                 break;
9881         case -ENOTSUP:
9882                 printf("function not implemented or supported\n");
9883                 break;
9884         default:
9885                 printf("user_priority region config error: (%s)\n",
9886                                 strerror(-ret));
9887         }
9888 }
9889
9890 cmdline_parse_token_string_t cmd_user_priority_region_set =
9891         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9892                                 set, "set");
9893 cmdline_parse_token_string_t cmd_user_priority_region_port =
9894         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9895                                 port, "port");
9896 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9897         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9898                                 port_id, UINT16);
9899 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9900         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9901                                 cmd, "queue-region");
9902 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9903         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9904                                 user_priority, "UP");
9905 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9906         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9907                                 user_priority_id, UINT8);
9908 cmdline_parse_token_string_t cmd_user_priority_region_region =
9909         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9910                                 region, "region_id");
9911 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9912         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9913                                 region_id, UINT8);
9914
9915 cmdline_parse_inst_t cmd_user_priority_region = {
9916         .f = cmd_user_priority_region_parsed,
9917         .data = NULL,
9918         .help_str = "set port <port_id> queue-region UP <value> "
9919                 "region_id <value>: Set the mapping of User Priority (UP) "
9920                 "to queue region (region_id) ",
9921         .tokens = {
9922                 (void *)&cmd_user_priority_region_set,
9923                 (void *)&cmd_user_priority_region_port,
9924                 (void *)&cmd_user_priority_region_port_index,
9925                 (void *)&cmd_user_priority_region_cmd,
9926                 (void *)&cmd_user_priority_region_UP,
9927                 (void *)&cmd_user_priority_region_UP_id,
9928                 (void *)&cmd_user_priority_region_region,
9929                 (void *)&cmd_user_priority_region_region_id,
9930                 NULL,
9931         },
9932 };
9933
9934 /* *** flush all queue region related configuration *** */
9935 struct cmd_flush_queue_region_result {
9936         cmdline_fixed_string_t set;
9937         cmdline_fixed_string_t port;
9938         portid_t port_id;
9939         cmdline_fixed_string_t cmd;
9940         cmdline_fixed_string_t flush;
9941         cmdline_fixed_string_t what;
9942 };
9943
9944 static void
9945 cmd_flush_queue_region_parsed(void *parsed_result,
9946                         __rte_unused struct cmdline *cl,
9947                         __rte_unused void *data)
9948 {
9949         struct cmd_flush_queue_region_result *res = parsed_result;
9950         int ret = -ENOTSUP;
9951 #ifdef RTE_NET_I40E
9952         struct rte_pmd_i40e_queue_region_conf region_conf;
9953         enum rte_pmd_i40e_queue_region_op op_type;
9954 #endif
9955
9956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9957                 return;
9958
9959 #ifdef RTE_NET_I40E
9960         memset(&region_conf, 0, sizeof(region_conf));
9961
9962         if (strcmp(res->what, "on") == 0)
9963                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9964         else
9965                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9966
9967         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9968                                 op_type, &region_conf);
9969 #endif
9970
9971         switch (ret) {
9972         case 0:
9973                 break;
9974         case -ENOTSUP:
9975                 printf("function not implemented or supported\n");
9976                 break;
9977         default:
9978                 printf("queue region config flush error: (%s)\n",
9979                                 strerror(-ret));
9980         }
9981 }
9982
9983 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9984         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9985                                 set, "set");
9986 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9987         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9988                                 port, "port");
9989 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9990         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9991                                 port_id, UINT16);
9992 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9993         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9994                                 cmd, "queue-region");
9995 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9996         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9997                                 flush, "flush");
9998 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9999         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10000                                 what, "on#off");
10001
10002 cmdline_parse_inst_t cmd_flush_queue_region = {
10003         .f = cmd_flush_queue_region_parsed,
10004         .data = NULL,
10005         .help_str = "set port <port_id> queue-region flush on|off"
10006                 ": flush all queue region related configuration",
10007         .tokens = {
10008                 (void *)&cmd_flush_queue_region_set,
10009                 (void *)&cmd_flush_queue_region_port,
10010                 (void *)&cmd_flush_queue_region_port_index,
10011                 (void *)&cmd_flush_queue_region_cmd,
10012                 (void *)&cmd_flush_queue_region_flush,
10013                 (void *)&cmd_flush_queue_region_what,
10014                 NULL,
10015         },
10016 };
10017
10018 /* *** get all queue region related configuration info *** */
10019 struct cmd_show_queue_region_info {
10020         cmdline_fixed_string_t show;
10021         cmdline_fixed_string_t port;
10022         portid_t port_id;
10023         cmdline_fixed_string_t cmd;
10024 };
10025
10026 static void
10027 cmd_show_queue_region_info_parsed(void *parsed_result,
10028                         __rte_unused struct cmdline *cl,
10029                         __rte_unused void *data)
10030 {
10031         struct cmd_show_queue_region_info *res = parsed_result;
10032         int ret = -ENOTSUP;
10033 #ifdef RTE_NET_I40E
10034         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10035         enum rte_pmd_i40e_queue_region_op op_type;
10036 #endif
10037
10038         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10039                 return;
10040
10041 #ifdef RTE_NET_I40E
10042         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10043
10044         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10045
10046         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10047                                         op_type, &rte_pmd_regions);
10048
10049         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10050 #endif
10051
10052         switch (ret) {
10053         case 0:
10054                 break;
10055         case -ENOTSUP:
10056                 printf("function not implemented or supported\n");
10057                 break;
10058         default:
10059                 printf("queue region config info show error: (%s)\n",
10060                                 strerror(-ret));
10061         }
10062 }
10063
10064 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10065 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10066                                 show, "show");
10067 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10068         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10069                                 port, "port");
10070 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10071         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10072                                 port_id, UINT16);
10073 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10074         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10075                                 cmd, "queue-region");
10076
10077 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10078         .f = cmd_show_queue_region_info_parsed,
10079         .data = NULL,
10080         .help_str = "show port <port_id> queue-region"
10081                 ": show all queue region related configuration info",
10082         .tokens = {
10083                 (void *)&cmd_show_queue_region_info_get,
10084                 (void *)&cmd_show_queue_region_info_port,
10085                 (void *)&cmd_show_queue_region_info_port_index,
10086                 (void *)&cmd_show_queue_region_info_cmd,
10087                 NULL,
10088         },
10089 };
10090
10091 /* *** Filters Control *** */
10092
10093 static uint16_t
10094 str2flowtype(char *string)
10095 {
10096         uint8_t i = 0;
10097         static const struct {
10098                 char str[32];
10099                 uint16_t type;
10100         } flowtype_str[] = {
10101                 {"raw", RTE_ETH_FLOW_RAW},
10102                 {"ipv4", RTE_ETH_FLOW_IPV4},
10103                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10104                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10105                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10106                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10107                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10108                 {"ipv6", RTE_ETH_FLOW_IPV6},
10109                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10110                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10111                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10112                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10113                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10114                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10115         };
10116
10117         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10118                 if (!strcmp(flowtype_str[i].str, string))
10119                         return flowtype_str[i].type;
10120         }
10121
10122         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10123                 return (uint16_t)atoi(string);
10124
10125         return RTE_ETH_FLOW_UNKNOWN;
10126 }
10127
10128 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10129 do { \
10130         if ((ip_addr).family == AF_INET) \
10131                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10132         else { \
10133                 printf("invalid parameter.\n"); \
10134                 return; \
10135         } \
10136 } while (0)
10137
10138 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10139 do { \
10140         if ((ip_addr).family == AF_INET6) \
10141                 rte_memcpy(&(ip), \
10142                                  &((ip_addr).addr.ipv6), \
10143                                  sizeof(struct in6_addr)); \
10144         else { \
10145                 printf("invalid parameter.\n"); \
10146                 return; \
10147         } \
10148 } while (0)
10149
10150 #ifdef RTE_NET_I40E
10151
10152 /* *** deal with flow director filter *** */
10153 struct cmd_flow_director_result {
10154         cmdline_fixed_string_t flow_director_filter;
10155         portid_t port_id;
10156         cmdline_fixed_string_t mode;
10157         cmdline_fixed_string_t mode_value;
10158         cmdline_fixed_string_t ops;
10159         cmdline_fixed_string_t flow;
10160         cmdline_fixed_string_t flow_type;
10161         cmdline_fixed_string_t drop;
10162         cmdline_fixed_string_t queue;
10163         uint16_t  queue_id;
10164         cmdline_fixed_string_t fd_id;
10165         uint32_t  fd_id_value;
10166         cmdline_fixed_string_t packet;
10167         char filepath[];
10168 };
10169
10170 static void
10171 cmd_flow_director_filter_parsed(void *parsed_result,
10172                           __rte_unused struct cmdline *cl,
10173                           __rte_unused void *data)
10174 {
10175         struct cmd_flow_director_result *res = parsed_result;
10176         int ret = 0;
10177         struct rte_pmd_i40e_flow_type_mapping
10178                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10179         struct rte_pmd_i40e_pkt_template_conf conf;
10180         uint16_t flow_type = str2flowtype(res->flow_type);
10181         uint16_t i, port = res->port_id;
10182         uint8_t add;
10183
10184         memset(&conf, 0, sizeof(conf));
10185
10186         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10187                 printf("Invalid flow type specified.\n");
10188                 return;
10189         }
10190         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10191                                                  mapping);
10192         if (ret)
10193                 return;
10194         if (mapping[flow_type].pctype == 0ULL) {
10195                 printf("Invalid flow type specified.\n");
10196                 return;
10197         }
10198         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10199                 if (mapping[flow_type].pctype & (1ULL << i)) {
10200                         conf.input.pctype = i;
10201                         break;
10202                 }
10203         }
10204
10205         conf.input.packet = open_file(res->filepath,
10206                                 &conf.input.length);
10207         if (!conf.input.packet)
10208                 return;
10209         if (!strcmp(res->drop, "drop"))
10210                 conf.action.behavior =
10211                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10212         else
10213                 conf.action.behavior =
10214                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10215         conf.action.report_status =
10216                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10217         conf.action.rx_queue = res->queue_id;
10218         conf.soft_id = res->fd_id_value;
10219         add  = strcmp(res->ops, "del") ? 1 : 0;
10220         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10221                                                         &conf,
10222                                                         add);
10223         if (ret < 0)
10224                 printf("flow director config error: (%s)\n",
10225                        strerror(-ret));
10226         close_file(conf.input.packet);
10227 }
10228
10229 cmdline_parse_token_string_t cmd_flow_director_filter =
10230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10231                                  flow_director_filter, "flow_director_filter");
10232 cmdline_parse_token_num_t cmd_flow_director_port_id =
10233         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10234                               port_id, UINT16);
10235 cmdline_parse_token_string_t cmd_flow_director_ops =
10236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10237                                  ops, "add#del#update");
10238 cmdline_parse_token_string_t cmd_flow_director_flow =
10239         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10240                                  flow, "flow");
10241 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10243                 flow_type, NULL);
10244 cmdline_parse_token_string_t cmd_flow_director_drop =
10245         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10246                                  drop, "drop#fwd");
10247 cmdline_parse_token_string_t cmd_flow_director_queue =
10248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10249                                  queue, "queue");
10250 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10251         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10252                               queue_id, UINT16);
10253 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10255                                  fd_id, "fd_id");
10256 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10258                               fd_id_value, UINT32);
10259
10260 cmdline_parse_token_string_t cmd_flow_director_mode =
10261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10262                                  mode, "mode");
10263 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10265                                  mode_value, "raw");
10266 cmdline_parse_token_string_t cmd_flow_director_packet =
10267         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10268                                  packet, "packet");
10269 cmdline_parse_token_string_t cmd_flow_director_filepath =
10270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10271                                  filepath, NULL);
10272
10273 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10274         .f = cmd_flow_director_filter_parsed,
10275         .data = NULL,
10276         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10277                 "director entry on NIC",
10278         .tokens = {
10279                 (void *)&cmd_flow_director_filter,
10280                 (void *)&cmd_flow_director_port_id,
10281                 (void *)&cmd_flow_director_mode,
10282                 (void *)&cmd_flow_director_mode_raw,
10283                 (void *)&cmd_flow_director_ops,
10284                 (void *)&cmd_flow_director_flow,
10285                 (void *)&cmd_flow_director_flow_type,
10286                 (void *)&cmd_flow_director_drop,
10287                 (void *)&cmd_flow_director_queue,
10288                 (void *)&cmd_flow_director_queue_id,
10289                 (void *)&cmd_flow_director_fd_id,
10290                 (void *)&cmd_flow_director_fd_id_value,
10291                 (void *)&cmd_flow_director_packet,
10292                 (void *)&cmd_flow_director_filepath,
10293                 NULL,
10294         },
10295 };
10296
10297 #endif /* RTE_NET_I40E */
10298
10299 /* *** deal with flow director mask *** */
10300 struct cmd_flow_director_mask_result {
10301         cmdline_fixed_string_t flow_director_mask;
10302         portid_t port_id;
10303         cmdline_fixed_string_t mode;
10304         cmdline_fixed_string_t mode_value;
10305         cmdline_fixed_string_t vlan;
10306         uint16_t vlan_mask;
10307         cmdline_fixed_string_t src_mask;
10308         cmdline_ipaddr_t ipv4_src;
10309         cmdline_ipaddr_t ipv6_src;
10310         uint16_t port_src;
10311         cmdline_fixed_string_t dst_mask;
10312         cmdline_ipaddr_t ipv4_dst;
10313         cmdline_ipaddr_t ipv6_dst;
10314         uint16_t port_dst;
10315         cmdline_fixed_string_t mac;
10316         uint8_t mac_addr_byte_mask;
10317         cmdline_fixed_string_t tunnel_id;
10318         uint32_t tunnel_id_mask;
10319         cmdline_fixed_string_t tunnel_type;
10320         uint8_t tunnel_type_mask;
10321 };
10322
10323 static void
10324 cmd_flow_director_mask_parsed(void *parsed_result,
10325                           __rte_unused struct cmdline *cl,
10326                           __rte_unused void *data)
10327 {
10328         struct cmd_flow_director_mask_result *res = parsed_result;
10329         struct rte_eth_fdir_masks *mask;
10330         struct rte_port *port;
10331
10332         port = &ports[res->port_id];
10333         /** Check if the port is not started **/
10334         if (port->port_status != RTE_PORT_STOPPED) {
10335                 printf("Please stop port %d first\n", res->port_id);
10336                 return;
10337         }
10338
10339         mask = &port->dev_conf.fdir_conf.mask;
10340
10341         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10342                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10343                         printf("Please set mode to MAC-VLAN.\n");
10344                         return;
10345                 }
10346
10347                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10348         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10349                 if (strcmp(res->mode_value, "Tunnel")) {
10350                         printf("Please set mode to Tunnel.\n");
10351                         return;
10352                 }
10353
10354                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10355                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10356                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10357                 mask->tunnel_type_mask = res->tunnel_type_mask;
10358         } else {
10359                 if (strcmp(res->mode_value, "IP")) {
10360                         printf("Please set mode to IP.\n");
10361                         return;
10362                 }
10363
10364                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10365                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10366                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10367                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10368                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10369                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10370                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10371         }
10372
10373         cmd_reconfig_device_queue(res->port_id, 1, 1);
10374 }
10375
10376 cmdline_parse_token_string_t cmd_flow_director_mask =
10377         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10378                                  flow_director_mask, "flow_director_mask");
10379 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10380         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10381                               port_id, UINT16);
10382 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10384                                  vlan, "vlan");
10385 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10386         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10387                               vlan_mask, UINT16);
10388 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10390                                  src_mask, "src_mask");
10391 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10392         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10393                                  ipv4_src);
10394 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10395         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10396                                  ipv6_src);
10397 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10398         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10399                               port_src, UINT16);
10400 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10401         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10402                                  dst_mask, "dst_mask");
10403 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10404         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10405                                  ipv4_dst);
10406 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10407         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10408                                  ipv6_dst);
10409 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10410         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10411                               port_dst, UINT16);
10412
10413 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10415                                  mode, "mode");
10416 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10417         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10418                                  mode_value, "IP");
10419 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10420         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10421                                  mode_value, "MAC-VLAN");
10422 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10423         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10424                                  mode_value, "Tunnel");
10425 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10426         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10427                                  mac, "mac");
10428 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10429         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10430                               mac_addr_byte_mask, UINT8);
10431 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10432         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10433                                  tunnel_type, "tunnel-type");
10434 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10435         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10436                               tunnel_type_mask, UINT8);
10437 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10439                                  tunnel_id, "tunnel-id");
10440 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10441         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10442                               tunnel_id_mask, UINT32);
10443
10444 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10445         .f = cmd_flow_director_mask_parsed,
10446         .data = NULL,
10447         .help_str = "flow_director_mask ... : "
10448                 "Set IP mode flow director's mask on NIC",
10449         .tokens = {
10450                 (void *)&cmd_flow_director_mask,
10451                 (void *)&cmd_flow_director_mask_port_id,
10452                 (void *)&cmd_flow_director_mask_mode,
10453                 (void *)&cmd_flow_director_mask_mode_ip,
10454                 (void *)&cmd_flow_director_mask_vlan,
10455                 (void *)&cmd_flow_director_mask_vlan_value,
10456                 (void *)&cmd_flow_director_mask_src,
10457                 (void *)&cmd_flow_director_mask_ipv4_src,
10458                 (void *)&cmd_flow_director_mask_ipv6_src,
10459                 (void *)&cmd_flow_director_mask_port_src,
10460                 (void *)&cmd_flow_director_mask_dst,
10461                 (void *)&cmd_flow_director_mask_ipv4_dst,
10462                 (void *)&cmd_flow_director_mask_ipv6_dst,
10463                 (void *)&cmd_flow_director_mask_port_dst,
10464                 NULL,
10465         },
10466 };
10467
10468 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10469         .f = cmd_flow_director_mask_parsed,
10470         .data = NULL,
10471         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10472                 "flow director's mask on NIC",
10473         .tokens = {
10474                 (void *)&cmd_flow_director_mask,
10475                 (void *)&cmd_flow_director_mask_port_id,
10476                 (void *)&cmd_flow_director_mask_mode,
10477                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10478                 (void *)&cmd_flow_director_mask_vlan,
10479                 (void *)&cmd_flow_director_mask_vlan_value,
10480                 NULL,
10481         },
10482 };
10483
10484 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10485         .f = cmd_flow_director_mask_parsed,
10486         .data = NULL,
10487         .help_str = "flow_director_mask ... : Set tunnel mode "
10488                 "flow director's mask on NIC",
10489         .tokens = {
10490                 (void *)&cmd_flow_director_mask,
10491                 (void *)&cmd_flow_director_mask_port_id,
10492                 (void *)&cmd_flow_director_mask_mode,
10493                 (void *)&cmd_flow_director_mask_mode_tunnel,
10494                 (void *)&cmd_flow_director_mask_vlan,
10495                 (void *)&cmd_flow_director_mask_vlan_value,
10496                 (void *)&cmd_flow_director_mask_mac,
10497                 (void *)&cmd_flow_director_mask_mac_value,
10498                 (void *)&cmd_flow_director_mask_tunnel_type,
10499                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10500                 (void *)&cmd_flow_director_mask_tunnel_id,
10501                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10502                 NULL,
10503         },
10504 };
10505
10506 /* *** deal with flow director flexible payload configuration *** */
10507 struct cmd_flow_director_flexpayload_result {
10508         cmdline_fixed_string_t flow_director_flexpayload;
10509         portid_t port_id;
10510         cmdline_fixed_string_t payload_layer;
10511         cmdline_fixed_string_t payload_cfg;
10512 };
10513
10514 static inline int
10515 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10516 {
10517         char s[256];
10518         const char *p, *p0 = q_arg;
10519         char *end;
10520         unsigned long int_fld;
10521         char *str_fld[max_num];
10522         int i;
10523         unsigned size;
10524         int ret = -1;
10525
10526         p = strchr(p0, '(');
10527         if (p == NULL)
10528                 return -1;
10529         ++p;
10530         p0 = strchr(p, ')');
10531         if (p0 == NULL)
10532                 return -1;
10533
10534         size = p0 - p;
10535         if (size >= sizeof(s))
10536                 return -1;
10537
10538         snprintf(s, sizeof(s), "%.*s", size, p);
10539         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10540         if (ret < 0 || ret > max_num)
10541                 return -1;
10542         for (i = 0; i < ret; i++) {
10543                 errno = 0;
10544                 int_fld = strtoul(str_fld[i], &end, 0);
10545                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10546                         return -1;
10547                 offsets[i] = (uint16_t)int_fld;
10548         }
10549         return ret;
10550 }
10551
10552 static void
10553 cmd_flow_director_flxpld_parsed(void *parsed_result,
10554                           __rte_unused struct cmdline *cl,
10555                           __rte_unused void *data)
10556 {
10557         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10558         struct rte_eth_flex_payload_cfg flex_cfg;
10559         struct rte_port *port;
10560         int ret = 0;
10561
10562         port = &ports[res->port_id];
10563         /** Check if the port is not started **/
10564         if (port->port_status != RTE_PORT_STOPPED) {
10565                 printf("Please stop port %d first\n", res->port_id);
10566                 return;
10567         }
10568
10569         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10570
10571         if (!strcmp(res->payload_layer, "raw"))
10572                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10573         else if (!strcmp(res->payload_layer, "l2"))
10574                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10575         else if (!strcmp(res->payload_layer, "l3"))
10576                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10577         else if (!strcmp(res->payload_layer, "l4"))
10578                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10579
10580         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10581                             RTE_ETH_FDIR_MAX_FLEXLEN);
10582         if (ret < 0) {
10583                 printf("error: Cannot parse flex payload input.\n");
10584                 return;
10585         }
10586
10587         fdir_set_flex_payload(res->port_id, &flex_cfg);
10588         cmd_reconfig_device_queue(res->port_id, 1, 1);
10589 }
10590
10591 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10592         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10593                                  flow_director_flexpayload,
10594                                  "flow_director_flex_payload");
10595 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10596         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10597                               port_id, UINT16);
10598 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10600                                  payload_layer, "raw#l2#l3#l4");
10601 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10603                                  payload_cfg, NULL);
10604
10605 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10606         .f = cmd_flow_director_flxpld_parsed,
10607         .data = NULL,
10608         .help_str = "flow_director_flexpayload ... : "
10609                 "Set flow director's flex payload on NIC",
10610         .tokens = {
10611                 (void *)&cmd_flow_director_flexpayload,
10612                 (void *)&cmd_flow_director_flexpayload_port_id,
10613                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10614                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10615                 NULL,
10616         },
10617 };
10618
10619 /* Generic flow interface command. */
10620 extern cmdline_parse_inst_t cmd_flow;
10621
10622 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10623 struct cmd_mcast_addr_result {
10624         cmdline_fixed_string_t mcast_addr_cmd;
10625         cmdline_fixed_string_t what;
10626         uint16_t port_num;
10627         struct rte_ether_addr mc_addr;
10628 };
10629
10630 static void cmd_mcast_addr_parsed(void *parsed_result,
10631                 __rte_unused struct cmdline *cl,
10632                 __rte_unused void *data)
10633 {
10634         struct cmd_mcast_addr_result *res = parsed_result;
10635
10636         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10637                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10638                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10639                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10640                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10641                 return;
10642         }
10643         if (strcmp(res->what, "add") == 0)
10644                 mcast_addr_add(res->port_num, &res->mc_addr);
10645         else
10646                 mcast_addr_remove(res->port_num, &res->mc_addr);
10647 }
10648
10649 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10650         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10651                                  mcast_addr_cmd, "mcast_addr");
10652 cmdline_parse_token_string_t cmd_mcast_addr_what =
10653         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10654                                  "add#remove");
10655 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10656         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
10657 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10658         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10659
10660 cmdline_parse_inst_t cmd_mcast_addr = {
10661         .f = cmd_mcast_addr_parsed,
10662         .data = (void *)0,
10663         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10664                 "Add/Remove multicast MAC address on port_id",
10665         .tokens = {
10666                 (void *)&cmd_mcast_addr_cmd,
10667                 (void *)&cmd_mcast_addr_what,
10668                 (void *)&cmd_mcast_addr_portnum,
10669                 (void *)&cmd_mcast_addr_addr,
10670                 NULL,
10671         },
10672 };
10673
10674 /* l2 tunnel config
10675  * only support E-tag now.
10676  */
10677
10678 static enum rte_eth_tunnel_type
10679 str2fdir_l2_tunnel_type(char *string)
10680 {
10681         uint32_t i = 0;
10682
10683         static const struct {
10684                 char str[32];
10685                 enum rte_eth_tunnel_type type;
10686         } l2_tunnel_type_str[] = {
10687                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10688         };
10689
10690         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10691                 if (!strcmp(l2_tunnel_type_str[i].str, string))
10692                         return l2_tunnel_type_str[i].type;
10693         }
10694         return RTE_TUNNEL_TYPE_NONE;
10695 }
10696
10697 /* Enable/disable l2 tunnel */
10698 struct cmd_config_l2_tunnel_en_dis_result {
10699         cmdline_fixed_string_t port;
10700         cmdline_fixed_string_t config;
10701         cmdline_fixed_string_t all;
10702         portid_t id;
10703         cmdline_fixed_string_t l2_tunnel;
10704         cmdline_fixed_string_t l2_tunnel_type;
10705         cmdline_fixed_string_t en_dis;
10706 };
10707
10708 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
10709         TOKEN_STRING_INITIALIZER
10710                 (struct cmd_config_l2_tunnel_en_dis_result,
10711                  port, "port");
10712 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
10713         TOKEN_STRING_INITIALIZER
10714                 (struct cmd_config_l2_tunnel_en_dis_result,
10715                  config, "config");
10716 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
10717         TOKEN_STRING_INITIALIZER
10718                 (struct cmd_config_l2_tunnel_en_dis_result,
10719                  all, "all");
10720 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
10721         TOKEN_NUM_INITIALIZER
10722                 (struct cmd_config_l2_tunnel_en_dis_result,
10723                  id, UINT16);
10724 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
10725         TOKEN_STRING_INITIALIZER
10726                 (struct cmd_config_l2_tunnel_en_dis_result,
10727                  l2_tunnel, "l2-tunnel");
10728 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
10729         TOKEN_STRING_INITIALIZER
10730                 (struct cmd_config_l2_tunnel_en_dis_result,
10731                  l2_tunnel_type, "E-tag");
10732 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
10733         TOKEN_STRING_INITIALIZER
10734                 (struct cmd_config_l2_tunnel_en_dis_result,
10735                  en_dis, "enable#disable");
10736
10737 /* enable/disable l2 tunnel for all ports */
10738 static void
10739 cmd_config_l2_tunnel_en_dis_all_parsed(
10740         void *parsed_result,
10741         __rte_unused struct cmdline *cl,
10742         __rte_unused void *data)
10743 {
10744         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
10745         struct rte_eth_l2_tunnel_conf entry;
10746         portid_t pid;
10747         uint8_t en;
10748
10749         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10750
10751         if (!strcmp("enable", res->en_dis))
10752                 en = 1;
10753         else
10754                 en = 0;
10755
10756         RTE_ETH_FOREACH_DEV(pid) {
10757                 rte_eth_dev_l2_tunnel_offload_set(pid,
10758                                                   &entry,
10759                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10760                                                   en);
10761         }
10762 }
10763
10764 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
10765         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
10766         .data = NULL,
10767         .help_str = "port config all l2-tunnel E-tag enable|disable",
10768         .tokens = {
10769                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10770                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10771                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
10772                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10773                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10774                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10775                 NULL,
10776         },
10777 };
10778
10779 /* enable/disable l2 tunnel for a port */
10780 static void
10781 cmd_config_l2_tunnel_en_dis_specific_parsed(
10782         void *parsed_result,
10783         __rte_unused struct cmdline *cl,
10784         __rte_unused void *data)
10785 {
10786         struct cmd_config_l2_tunnel_en_dis_result *res =
10787                 parsed_result;
10788         struct rte_eth_l2_tunnel_conf entry;
10789
10790         if (port_id_is_invalid(res->id, ENABLED_WARN))
10791                 return;
10792
10793         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10794
10795         if (!strcmp("enable", res->en_dis))
10796                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10797                                                   &entry,
10798                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10799                                                   1);
10800         else
10801                 rte_eth_dev_l2_tunnel_offload_set(res->id,
10802                                                   &entry,
10803                                                   ETH_L2_TUNNEL_ENABLE_MASK,
10804                                                   0);
10805 }
10806
10807 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
10808         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
10809         .data = NULL,
10810         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
10811         .tokens = {
10812                 (void *)&cmd_config_l2_tunnel_en_dis_port,
10813                 (void *)&cmd_config_l2_tunnel_en_dis_config,
10814                 (void *)&cmd_config_l2_tunnel_en_dis_id,
10815                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
10816                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
10817                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
10818                 NULL,
10819         },
10820 };
10821
10822 /* E-tag configuration */
10823
10824 /* Common result structure for all E-tag configuration */
10825 struct cmd_config_e_tag_result {
10826         cmdline_fixed_string_t e_tag;
10827         cmdline_fixed_string_t set;
10828         cmdline_fixed_string_t insertion;
10829         cmdline_fixed_string_t stripping;
10830         cmdline_fixed_string_t forwarding;
10831         cmdline_fixed_string_t filter;
10832         cmdline_fixed_string_t add;
10833         cmdline_fixed_string_t del;
10834         cmdline_fixed_string_t on;
10835         cmdline_fixed_string_t off;
10836         cmdline_fixed_string_t on_off;
10837         cmdline_fixed_string_t port_tag_id;
10838         uint32_t port_tag_id_val;
10839         cmdline_fixed_string_t e_tag_id;
10840         uint16_t e_tag_id_val;
10841         cmdline_fixed_string_t dst_pool;
10842         uint8_t dst_pool_val;
10843         cmdline_fixed_string_t port;
10844         portid_t port_id;
10845         cmdline_fixed_string_t vf;
10846         uint8_t vf_id;
10847 };
10848
10849 /* Common CLI fields for all E-tag configuration */
10850 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10851         TOKEN_STRING_INITIALIZER
10852                 (struct cmd_config_e_tag_result,
10853                  e_tag, "E-tag");
10854 cmdline_parse_token_string_t cmd_config_e_tag_set =
10855         TOKEN_STRING_INITIALIZER
10856                 (struct cmd_config_e_tag_result,
10857                  set, "set");
10858 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10859         TOKEN_STRING_INITIALIZER
10860                 (struct cmd_config_e_tag_result,
10861                  insertion, "insertion");
10862 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10863         TOKEN_STRING_INITIALIZER
10864                 (struct cmd_config_e_tag_result,
10865                  stripping, "stripping");
10866 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10867         TOKEN_STRING_INITIALIZER
10868                 (struct cmd_config_e_tag_result,
10869                  forwarding, "forwarding");
10870 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10871         TOKEN_STRING_INITIALIZER
10872                 (struct cmd_config_e_tag_result,
10873                  filter, "filter");
10874 cmdline_parse_token_string_t cmd_config_e_tag_add =
10875         TOKEN_STRING_INITIALIZER
10876                 (struct cmd_config_e_tag_result,
10877                  add, "add");
10878 cmdline_parse_token_string_t cmd_config_e_tag_del =
10879         TOKEN_STRING_INITIALIZER
10880                 (struct cmd_config_e_tag_result,
10881                  del, "del");
10882 cmdline_parse_token_string_t cmd_config_e_tag_on =
10883         TOKEN_STRING_INITIALIZER
10884                 (struct cmd_config_e_tag_result,
10885                  on, "on");
10886 cmdline_parse_token_string_t cmd_config_e_tag_off =
10887         TOKEN_STRING_INITIALIZER
10888                 (struct cmd_config_e_tag_result,
10889                  off, "off");
10890 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10891         TOKEN_STRING_INITIALIZER
10892                 (struct cmd_config_e_tag_result,
10893                  on_off, "on#off");
10894 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10895         TOKEN_STRING_INITIALIZER
10896                 (struct cmd_config_e_tag_result,
10897                  port_tag_id, "port-tag-id");
10898 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10899         TOKEN_NUM_INITIALIZER
10900                 (struct cmd_config_e_tag_result,
10901                  port_tag_id_val, UINT32);
10902 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10903         TOKEN_STRING_INITIALIZER
10904                 (struct cmd_config_e_tag_result,
10905                  e_tag_id, "e-tag-id");
10906 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10907         TOKEN_NUM_INITIALIZER
10908                 (struct cmd_config_e_tag_result,
10909                  e_tag_id_val, UINT16);
10910 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10911         TOKEN_STRING_INITIALIZER
10912                 (struct cmd_config_e_tag_result,
10913                  dst_pool, "dst-pool");
10914 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10915         TOKEN_NUM_INITIALIZER
10916                 (struct cmd_config_e_tag_result,
10917                  dst_pool_val, UINT8);
10918 cmdline_parse_token_string_t cmd_config_e_tag_port =
10919         TOKEN_STRING_INITIALIZER
10920                 (struct cmd_config_e_tag_result,
10921                  port, "port");
10922 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10923         TOKEN_NUM_INITIALIZER
10924                 (struct cmd_config_e_tag_result,
10925                  port_id, UINT16);
10926 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10927         TOKEN_STRING_INITIALIZER
10928                 (struct cmd_config_e_tag_result,
10929                  vf, "vf");
10930 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10931         TOKEN_NUM_INITIALIZER
10932                 (struct cmd_config_e_tag_result,
10933                  vf_id, UINT8);
10934
10935 /* E-tag insertion configuration */
10936 static void
10937 cmd_config_e_tag_insertion_en_parsed(
10938         void *parsed_result,
10939         __rte_unused struct cmdline *cl,
10940         __rte_unused void *data)
10941 {
10942         struct cmd_config_e_tag_result *res =
10943                 parsed_result;
10944         struct rte_eth_l2_tunnel_conf entry;
10945
10946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10947                 return;
10948
10949         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10950         entry.tunnel_id = res->port_tag_id_val;
10951         entry.vf_id = res->vf_id;
10952         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10953                                           &entry,
10954                                           ETH_L2_TUNNEL_INSERTION_MASK,
10955                                           1);
10956 }
10957
10958 static void
10959 cmd_config_e_tag_insertion_dis_parsed(
10960         void *parsed_result,
10961         __rte_unused struct cmdline *cl,
10962         __rte_unused void *data)
10963 {
10964         struct cmd_config_e_tag_result *res =
10965                 parsed_result;
10966         struct rte_eth_l2_tunnel_conf entry;
10967
10968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10969                 return;
10970
10971         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10972         entry.vf_id = res->vf_id;
10973
10974         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10975                                           &entry,
10976                                           ETH_L2_TUNNEL_INSERTION_MASK,
10977                                           0);
10978 }
10979
10980 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10981         .f = cmd_config_e_tag_insertion_en_parsed,
10982         .data = NULL,
10983         .help_str = "E-tag ... : E-tag insertion enable",
10984         .tokens = {
10985                 (void *)&cmd_config_e_tag_e_tag,
10986                 (void *)&cmd_config_e_tag_set,
10987                 (void *)&cmd_config_e_tag_insertion,
10988                 (void *)&cmd_config_e_tag_on,
10989                 (void *)&cmd_config_e_tag_port_tag_id,
10990                 (void *)&cmd_config_e_tag_port_tag_id_val,
10991                 (void *)&cmd_config_e_tag_port,
10992                 (void *)&cmd_config_e_tag_port_id,
10993                 (void *)&cmd_config_e_tag_vf,
10994                 (void *)&cmd_config_e_tag_vf_id,
10995                 NULL,
10996         },
10997 };
10998
10999 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11000         .f = cmd_config_e_tag_insertion_dis_parsed,
11001         .data = NULL,
11002         .help_str = "E-tag ... : E-tag insertion disable",
11003         .tokens = {
11004                 (void *)&cmd_config_e_tag_e_tag,
11005                 (void *)&cmd_config_e_tag_set,
11006                 (void *)&cmd_config_e_tag_insertion,
11007                 (void *)&cmd_config_e_tag_off,
11008                 (void *)&cmd_config_e_tag_port,
11009                 (void *)&cmd_config_e_tag_port_id,
11010                 (void *)&cmd_config_e_tag_vf,
11011                 (void *)&cmd_config_e_tag_vf_id,
11012                 NULL,
11013         },
11014 };
11015
11016 /* E-tag stripping configuration */
11017 static void
11018 cmd_config_e_tag_stripping_parsed(
11019         void *parsed_result,
11020         __rte_unused struct cmdline *cl,
11021         __rte_unused void *data)
11022 {
11023         struct cmd_config_e_tag_result *res =
11024                 parsed_result;
11025         struct rte_eth_l2_tunnel_conf entry;
11026
11027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11028                 return;
11029
11030         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11031
11032         if (!strcmp(res->on_off, "on"))
11033                 rte_eth_dev_l2_tunnel_offload_set
11034                         (res->port_id,
11035                          &entry,
11036                          ETH_L2_TUNNEL_STRIPPING_MASK,
11037                          1);
11038         else
11039                 rte_eth_dev_l2_tunnel_offload_set
11040                         (res->port_id,
11041                          &entry,
11042                          ETH_L2_TUNNEL_STRIPPING_MASK,
11043                          0);
11044 }
11045
11046 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11047         .f = cmd_config_e_tag_stripping_parsed,
11048         .data = NULL,
11049         .help_str = "E-tag ... : E-tag stripping enable/disable",
11050         .tokens = {
11051                 (void *)&cmd_config_e_tag_e_tag,
11052                 (void *)&cmd_config_e_tag_set,
11053                 (void *)&cmd_config_e_tag_stripping,
11054                 (void *)&cmd_config_e_tag_on_off,
11055                 (void *)&cmd_config_e_tag_port,
11056                 (void *)&cmd_config_e_tag_port_id,
11057                 NULL,
11058         },
11059 };
11060
11061 /* E-tag forwarding configuration */
11062 static void
11063 cmd_config_e_tag_forwarding_parsed(
11064         void *parsed_result,
11065         __rte_unused struct cmdline *cl,
11066         __rte_unused void *data)
11067 {
11068         struct cmd_config_e_tag_result *res = parsed_result;
11069         struct rte_eth_l2_tunnel_conf entry;
11070
11071         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11072                 return;
11073
11074         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11075
11076         if (!strcmp(res->on_off, "on"))
11077                 rte_eth_dev_l2_tunnel_offload_set
11078                         (res->port_id,
11079                          &entry,
11080                          ETH_L2_TUNNEL_FORWARDING_MASK,
11081                          1);
11082         else
11083                 rte_eth_dev_l2_tunnel_offload_set
11084                         (res->port_id,
11085                          &entry,
11086                          ETH_L2_TUNNEL_FORWARDING_MASK,
11087                          0);
11088 }
11089
11090 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11091         .f = cmd_config_e_tag_forwarding_parsed,
11092         .data = NULL,
11093         .help_str = "E-tag ... : E-tag forwarding enable/disable",
11094         .tokens = {
11095                 (void *)&cmd_config_e_tag_e_tag,
11096                 (void *)&cmd_config_e_tag_set,
11097                 (void *)&cmd_config_e_tag_forwarding,
11098                 (void *)&cmd_config_e_tag_on_off,
11099                 (void *)&cmd_config_e_tag_port,
11100                 (void *)&cmd_config_e_tag_port_id,
11101                 NULL,
11102         },
11103 };
11104
11105 /* vf vlan anti spoof configuration */
11106
11107 /* Common result structure for vf vlan anti spoof */
11108 struct cmd_vf_vlan_anti_spoof_result {
11109         cmdline_fixed_string_t set;
11110         cmdline_fixed_string_t vf;
11111         cmdline_fixed_string_t vlan;
11112         cmdline_fixed_string_t antispoof;
11113         portid_t port_id;
11114         uint32_t vf_id;
11115         cmdline_fixed_string_t on_off;
11116 };
11117
11118 /* Common CLI fields for vf vlan anti spoof enable disable */
11119 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11120         TOKEN_STRING_INITIALIZER
11121                 (struct cmd_vf_vlan_anti_spoof_result,
11122                  set, "set");
11123 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11124         TOKEN_STRING_INITIALIZER
11125                 (struct cmd_vf_vlan_anti_spoof_result,
11126                  vf, "vf");
11127 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11128         TOKEN_STRING_INITIALIZER
11129                 (struct cmd_vf_vlan_anti_spoof_result,
11130                  vlan, "vlan");
11131 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11132         TOKEN_STRING_INITIALIZER
11133                 (struct cmd_vf_vlan_anti_spoof_result,
11134                  antispoof, "antispoof");
11135 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11136         TOKEN_NUM_INITIALIZER
11137                 (struct cmd_vf_vlan_anti_spoof_result,
11138                  port_id, UINT16);
11139 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11140         TOKEN_NUM_INITIALIZER
11141                 (struct cmd_vf_vlan_anti_spoof_result,
11142                  vf_id, UINT32);
11143 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11144         TOKEN_STRING_INITIALIZER
11145                 (struct cmd_vf_vlan_anti_spoof_result,
11146                  on_off, "on#off");
11147
11148 static void
11149 cmd_set_vf_vlan_anti_spoof_parsed(
11150         void *parsed_result,
11151         __rte_unused struct cmdline *cl,
11152         __rte_unused void *data)
11153 {
11154         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11155         int ret = -ENOTSUP;
11156
11157         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11158
11159         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11160                 return;
11161
11162 #ifdef RTE_NET_IXGBE
11163         if (ret == -ENOTSUP)
11164                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11165                                 res->vf_id, is_on);
11166 #endif
11167 #ifdef RTE_NET_I40E
11168         if (ret == -ENOTSUP)
11169                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11170                                 res->vf_id, is_on);
11171 #endif
11172 #ifdef RTE_NET_BNXT
11173         if (ret == -ENOTSUP)
11174                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11175                                 res->vf_id, is_on);
11176 #endif
11177
11178         switch (ret) {
11179         case 0:
11180                 break;
11181         case -EINVAL:
11182                 printf("invalid vf_id %d\n", res->vf_id);
11183                 break;
11184         case -ENODEV:
11185                 printf("invalid port_id %d\n", res->port_id);
11186                 break;
11187         case -ENOTSUP:
11188                 printf("function not implemented\n");
11189                 break;
11190         default:
11191                 printf("programming error: (%s)\n", strerror(-ret));
11192         }
11193 }
11194
11195 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11196         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11197         .data = NULL,
11198         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11199         .tokens = {
11200                 (void *)&cmd_vf_vlan_anti_spoof_set,
11201                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11202                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11203                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11204                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11205                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11206                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11207                 NULL,
11208         },
11209 };
11210
11211 /* vf mac anti spoof configuration */
11212
11213 /* Common result structure for vf mac anti spoof */
11214 struct cmd_vf_mac_anti_spoof_result {
11215         cmdline_fixed_string_t set;
11216         cmdline_fixed_string_t vf;
11217         cmdline_fixed_string_t mac;
11218         cmdline_fixed_string_t antispoof;
11219         portid_t port_id;
11220         uint32_t vf_id;
11221         cmdline_fixed_string_t on_off;
11222 };
11223
11224 /* Common CLI fields for vf mac anti spoof enable disable */
11225 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11226         TOKEN_STRING_INITIALIZER
11227                 (struct cmd_vf_mac_anti_spoof_result,
11228                  set, "set");
11229 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_vf_mac_anti_spoof_result,
11232                  vf, "vf");
11233 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11234         TOKEN_STRING_INITIALIZER
11235                 (struct cmd_vf_mac_anti_spoof_result,
11236                  mac, "mac");
11237 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11238         TOKEN_STRING_INITIALIZER
11239                 (struct cmd_vf_mac_anti_spoof_result,
11240                  antispoof, "antispoof");
11241 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11242         TOKEN_NUM_INITIALIZER
11243                 (struct cmd_vf_mac_anti_spoof_result,
11244                  port_id, UINT16);
11245 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11246         TOKEN_NUM_INITIALIZER
11247                 (struct cmd_vf_mac_anti_spoof_result,
11248                  vf_id, UINT32);
11249 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11250         TOKEN_STRING_INITIALIZER
11251                 (struct cmd_vf_mac_anti_spoof_result,
11252                  on_off, "on#off");
11253
11254 static void
11255 cmd_set_vf_mac_anti_spoof_parsed(
11256         void *parsed_result,
11257         __rte_unused struct cmdline *cl,
11258         __rte_unused void *data)
11259 {
11260         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11261         int ret = -ENOTSUP;
11262
11263         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11264
11265         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11266                 return;
11267
11268 #ifdef RTE_NET_IXGBE
11269         if (ret == -ENOTSUP)
11270                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11271                         res->vf_id, is_on);
11272 #endif
11273 #ifdef RTE_NET_I40E
11274         if (ret == -ENOTSUP)
11275                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11276                         res->vf_id, is_on);
11277 #endif
11278 #ifdef RTE_NET_BNXT
11279         if (ret == -ENOTSUP)
11280                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11281                         res->vf_id, is_on);
11282 #endif
11283
11284         switch (ret) {
11285         case 0:
11286                 break;
11287         case -EINVAL:
11288                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11289                 break;
11290         case -ENODEV:
11291                 printf("invalid port_id %d\n", res->port_id);
11292                 break;
11293         case -ENOTSUP:
11294                 printf("function not implemented\n");
11295                 break;
11296         default:
11297                 printf("programming error: (%s)\n", strerror(-ret));
11298         }
11299 }
11300
11301 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11302         .f = cmd_set_vf_mac_anti_spoof_parsed,
11303         .data = NULL,
11304         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11305         .tokens = {
11306                 (void *)&cmd_vf_mac_anti_spoof_set,
11307                 (void *)&cmd_vf_mac_anti_spoof_vf,
11308                 (void *)&cmd_vf_mac_anti_spoof_mac,
11309                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11310                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11311                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11312                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11313                 NULL,
11314         },
11315 };
11316
11317 /* vf vlan strip queue configuration */
11318
11319 /* Common result structure for vf mac anti spoof */
11320 struct cmd_vf_vlan_stripq_result {
11321         cmdline_fixed_string_t set;
11322         cmdline_fixed_string_t vf;
11323         cmdline_fixed_string_t vlan;
11324         cmdline_fixed_string_t stripq;
11325         portid_t port_id;
11326         uint16_t vf_id;
11327         cmdline_fixed_string_t on_off;
11328 };
11329
11330 /* Common CLI fields for vf vlan strip enable disable */
11331 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11332         TOKEN_STRING_INITIALIZER
11333                 (struct cmd_vf_vlan_stripq_result,
11334                  set, "set");
11335 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11336         TOKEN_STRING_INITIALIZER
11337                 (struct cmd_vf_vlan_stripq_result,
11338                  vf, "vf");
11339 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11340         TOKEN_STRING_INITIALIZER
11341                 (struct cmd_vf_vlan_stripq_result,
11342                  vlan, "vlan");
11343 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11344         TOKEN_STRING_INITIALIZER
11345                 (struct cmd_vf_vlan_stripq_result,
11346                  stripq, "stripq");
11347 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11348         TOKEN_NUM_INITIALIZER
11349                 (struct cmd_vf_vlan_stripq_result,
11350                  port_id, UINT16);
11351 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11352         TOKEN_NUM_INITIALIZER
11353                 (struct cmd_vf_vlan_stripq_result,
11354                  vf_id, UINT16);
11355 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11356         TOKEN_STRING_INITIALIZER
11357                 (struct cmd_vf_vlan_stripq_result,
11358                  on_off, "on#off");
11359
11360 static void
11361 cmd_set_vf_vlan_stripq_parsed(
11362         void *parsed_result,
11363         __rte_unused struct cmdline *cl,
11364         __rte_unused void *data)
11365 {
11366         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11367         int ret = -ENOTSUP;
11368
11369         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11370
11371         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11372                 return;
11373
11374 #ifdef RTE_NET_IXGBE
11375         if (ret == -ENOTSUP)
11376                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11377                         res->vf_id, is_on);
11378 #endif
11379 #ifdef RTE_NET_I40E
11380         if (ret == -ENOTSUP)
11381                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11382                         res->vf_id, is_on);
11383 #endif
11384 #ifdef RTE_NET_BNXT
11385         if (ret == -ENOTSUP)
11386                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11387                         res->vf_id, is_on);
11388 #endif
11389
11390         switch (ret) {
11391         case 0:
11392                 break;
11393         case -EINVAL:
11394                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11395                 break;
11396         case -ENODEV:
11397                 printf("invalid port_id %d\n", res->port_id);
11398                 break;
11399         case -ENOTSUP:
11400                 printf("function not implemented\n");
11401                 break;
11402         default:
11403                 printf("programming error: (%s)\n", strerror(-ret));
11404         }
11405 }
11406
11407 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11408         .f = cmd_set_vf_vlan_stripq_parsed,
11409         .data = NULL,
11410         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11411         .tokens = {
11412                 (void *)&cmd_vf_vlan_stripq_set,
11413                 (void *)&cmd_vf_vlan_stripq_vf,
11414                 (void *)&cmd_vf_vlan_stripq_vlan,
11415                 (void *)&cmd_vf_vlan_stripq_stripq,
11416                 (void *)&cmd_vf_vlan_stripq_port_id,
11417                 (void *)&cmd_vf_vlan_stripq_vf_id,
11418                 (void *)&cmd_vf_vlan_stripq_on_off,
11419                 NULL,
11420         },
11421 };
11422
11423 /* vf vlan insert configuration */
11424
11425 /* Common result structure for vf vlan insert */
11426 struct cmd_vf_vlan_insert_result {
11427         cmdline_fixed_string_t set;
11428         cmdline_fixed_string_t vf;
11429         cmdline_fixed_string_t vlan;
11430         cmdline_fixed_string_t insert;
11431         portid_t port_id;
11432         uint16_t vf_id;
11433         uint16_t vlan_id;
11434 };
11435
11436 /* Common CLI fields for vf vlan insert enable disable */
11437 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11438         TOKEN_STRING_INITIALIZER
11439                 (struct cmd_vf_vlan_insert_result,
11440                  set, "set");
11441 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11442         TOKEN_STRING_INITIALIZER
11443                 (struct cmd_vf_vlan_insert_result,
11444                  vf, "vf");
11445 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11446         TOKEN_STRING_INITIALIZER
11447                 (struct cmd_vf_vlan_insert_result,
11448                  vlan, "vlan");
11449 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11450         TOKEN_STRING_INITIALIZER
11451                 (struct cmd_vf_vlan_insert_result,
11452                  insert, "insert");
11453 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11454         TOKEN_NUM_INITIALIZER
11455                 (struct cmd_vf_vlan_insert_result,
11456                  port_id, UINT16);
11457 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11458         TOKEN_NUM_INITIALIZER
11459                 (struct cmd_vf_vlan_insert_result,
11460                  vf_id, UINT16);
11461 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11462         TOKEN_NUM_INITIALIZER
11463                 (struct cmd_vf_vlan_insert_result,
11464                  vlan_id, UINT16);
11465
11466 static void
11467 cmd_set_vf_vlan_insert_parsed(
11468         void *parsed_result,
11469         __rte_unused struct cmdline *cl,
11470         __rte_unused void *data)
11471 {
11472         struct cmd_vf_vlan_insert_result *res = parsed_result;
11473         int ret = -ENOTSUP;
11474
11475         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11476                 return;
11477
11478 #ifdef RTE_NET_IXGBE
11479         if (ret == -ENOTSUP)
11480                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11481                         res->vlan_id);
11482 #endif
11483 #ifdef RTE_NET_I40E
11484         if (ret == -ENOTSUP)
11485                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11486                         res->vlan_id);
11487 #endif
11488 #ifdef RTE_NET_BNXT
11489         if (ret == -ENOTSUP)
11490                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11491                         res->vlan_id);
11492 #endif
11493
11494         switch (ret) {
11495         case 0:
11496                 break;
11497         case -EINVAL:
11498                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11499                 break;
11500         case -ENODEV:
11501                 printf("invalid port_id %d\n", res->port_id);
11502                 break;
11503         case -ENOTSUP:
11504                 printf("function not implemented\n");
11505                 break;
11506         default:
11507                 printf("programming error: (%s)\n", strerror(-ret));
11508         }
11509 }
11510
11511 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11512         .f = cmd_set_vf_vlan_insert_parsed,
11513         .data = NULL,
11514         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11515         .tokens = {
11516                 (void *)&cmd_vf_vlan_insert_set,
11517                 (void *)&cmd_vf_vlan_insert_vf,
11518                 (void *)&cmd_vf_vlan_insert_vlan,
11519                 (void *)&cmd_vf_vlan_insert_insert,
11520                 (void *)&cmd_vf_vlan_insert_port_id,
11521                 (void *)&cmd_vf_vlan_insert_vf_id,
11522                 (void *)&cmd_vf_vlan_insert_vlan_id,
11523                 NULL,
11524         },
11525 };
11526
11527 /* tx loopback configuration */
11528
11529 /* Common result structure for tx loopback */
11530 struct cmd_tx_loopback_result {
11531         cmdline_fixed_string_t set;
11532         cmdline_fixed_string_t tx;
11533         cmdline_fixed_string_t loopback;
11534         portid_t port_id;
11535         cmdline_fixed_string_t on_off;
11536 };
11537
11538 /* Common CLI fields for tx loopback enable disable */
11539 cmdline_parse_token_string_t cmd_tx_loopback_set =
11540         TOKEN_STRING_INITIALIZER
11541                 (struct cmd_tx_loopback_result,
11542                  set, "set");
11543 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11544         TOKEN_STRING_INITIALIZER
11545                 (struct cmd_tx_loopback_result,
11546                  tx, "tx");
11547 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11548         TOKEN_STRING_INITIALIZER
11549                 (struct cmd_tx_loopback_result,
11550                  loopback, "loopback");
11551 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11552         TOKEN_NUM_INITIALIZER
11553                 (struct cmd_tx_loopback_result,
11554                  port_id, UINT16);
11555 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11556         TOKEN_STRING_INITIALIZER
11557                 (struct cmd_tx_loopback_result,
11558                  on_off, "on#off");
11559
11560 static void
11561 cmd_set_tx_loopback_parsed(
11562         void *parsed_result,
11563         __rte_unused struct cmdline *cl,
11564         __rte_unused void *data)
11565 {
11566         struct cmd_tx_loopback_result *res = parsed_result;
11567         int ret = -ENOTSUP;
11568
11569         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11570
11571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11572                 return;
11573
11574 #ifdef RTE_NET_IXGBE
11575         if (ret == -ENOTSUP)
11576                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11577 #endif
11578 #ifdef RTE_NET_I40E
11579         if (ret == -ENOTSUP)
11580                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11581 #endif
11582 #ifdef RTE_NET_BNXT
11583         if (ret == -ENOTSUP)
11584                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11585 #endif
11586 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11587         if (ret == -ENOTSUP)
11588                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11589 #endif
11590
11591         switch (ret) {
11592         case 0:
11593                 break;
11594         case -EINVAL:
11595                 printf("invalid is_on %d\n", is_on);
11596                 break;
11597         case -ENODEV:
11598                 printf("invalid port_id %d\n", res->port_id);
11599                 break;
11600         case -ENOTSUP:
11601                 printf("function not implemented\n");
11602                 break;
11603         default:
11604                 printf("programming error: (%s)\n", strerror(-ret));
11605         }
11606 }
11607
11608 cmdline_parse_inst_t cmd_set_tx_loopback = {
11609         .f = cmd_set_tx_loopback_parsed,
11610         .data = NULL,
11611         .help_str = "set tx loopback <port_id> on|off",
11612         .tokens = {
11613                 (void *)&cmd_tx_loopback_set,
11614                 (void *)&cmd_tx_loopback_tx,
11615                 (void *)&cmd_tx_loopback_loopback,
11616                 (void *)&cmd_tx_loopback_port_id,
11617                 (void *)&cmd_tx_loopback_on_off,
11618                 NULL,
11619         },
11620 };
11621
11622 /* all queues drop enable configuration */
11623
11624 /* Common result structure for all queues drop enable */
11625 struct cmd_all_queues_drop_en_result {
11626         cmdline_fixed_string_t set;
11627         cmdline_fixed_string_t all;
11628         cmdline_fixed_string_t queues;
11629         cmdline_fixed_string_t drop;
11630         portid_t port_id;
11631         cmdline_fixed_string_t on_off;
11632 };
11633
11634 /* Common CLI fields for tx loopback enable disable */
11635 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11636         TOKEN_STRING_INITIALIZER
11637                 (struct cmd_all_queues_drop_en_result,
11638                  set, "set");
11639 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_all_queues_drop_en_result,
11642                  all, "all");
11643 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11644         TOKEN_STRING_INITIALIZER
11645                 (struct cmd_all_queues_drop_en_result,
11646                  queues, "queues");
11647 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_all_queues_drop_en_result,
11650                  drop, "drop");
11651 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11652         TOKEN_NUM_INITIALIZER
11653                 (struct cmd_all_queues_drop_en_result,
11654                  port_id, UINT16);
11655 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_all_queues_drop_en_result,
11658                  on_off, "on#off");
11659
11660 static void
11661 cmd_set_all_queues_drop_en_parsed(
11662         void *parsed_result,
11663         __rte_unused struct cmdline *cl,
11664         __rte_unused void *data)
11665 {
11666         struct cmd_all_queues_drop_en_result *res = parsed_result;
11667         int ret = -ENOTSUP;
11668         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11669
11670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11671                 return;
11672
11673 #ifdef RTE_NET_IXGBE
11674         if (ret == -ENOTSUP)
11675                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11676 #endif
11677 #ifdef RTE_NET_BNXT
11678         if (ret == -ENOTSUP)
11679                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11680 #endif
11681         switch (ret) {
11682         case 0:
11683                 break;
11684         case -EINVAL:
11685                 printf("invalid is_on %d\n", is_on);
11686                 break;
11687         case -ENODEV:
11688                 printf("invalid port_id %d\n", res->port_id);
11689                 break;
11690         case -ENOTSUP:
11691                 printf("function not implemented\n");
11692                 break;
11693         default:
11694                 printf("programming error: (%s)\n", strerror(-ret));
11695         }
11696 }
11697
11698 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11699         .f = cmd_set_all_queues_drop_en_parsed,
11700         .data = NULL,
11701         .help_str = "set all queues drop <port_id> on|off",
11702         .tokens = {
11703                 (void *)&cmd_all_queues_drop_en_set,
11704                 (void *)&cmd_all_queues_drop_en_all,
11705                 (void *)&cmd_all_queues_drop_en_queues,
11706                 (void *)&cmd_all_queues_drop_en_drop,
11707                 (void *)&cmd_all_queues_drop_en_port_id,
11708                 (void *)&cmd_all_queues_drop_en_on_off,
11709                 NULL,
11710         },
11711 };
11712
11713 /* vf split drop enable configuration */
11714
11715 /* Common result structure for vf split drop enable */
11716 struct cmd_vf_split_drop_en_result {
11717         cmdline_fixed_string_t set;
11718         cmdline_fixed_string_t vf;
11719         cmdline_fixed_string_t split;
11720         cmdline_fixed_string_t drop;
11721         portid_t port_id;
11722         uint16_t vf_id;
11723         cmdline_fixed_string_t on_off;
11724 };
11725
11726 /* Common CLI fields for vf split drop enable disable */
11727 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11728         TOKEN_STRING_INITIALIZER
11729                 (struct cmd_vf_split_drop_en_result,
11730                  set, "set");
11731 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11732         TOKEN_STRING_INITIALIZER
11733                 (struct cmd_vf_split_drop_en_result,
11734                  vf, "vf");
11735 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11736         TOKEN_STRING_INITIALIZER
11737                 (struct cmd_vf_split_drop_en_result,
11738                  split, "split");
11739 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11740         TOKEN_STRING_INITIALIZER
11741                 (struct cmd_vf_split_drop_en_result,
11742                  drop, "drop");
11743 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11744         TOKEN_NUM_INITIALIZER
11745                 (struct cmd_vf_split_drop_en_result,
11746                  port_id, UINT16);
11747 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11748         TOKEN_NUM_INITIALIZER
11749                 (struct cmd_vf_split_drop_en_result,
11750                  vf_id, UINT16);
11751 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11752         TOKEN_STRING_INITIALIZER
11753                 (struct cmd_vf_split_drop_en_result,
11754                  on_off, "on#off");
11755
11756 static void
11757 cmd_set_vf_split_drop_en_parsed(
11758         void *parsed_result,
11759         __rte_unused struct cmdline *cl,
11760         __rte_unused void *data)
11761 {
11762         struct cmd_vf_split_drop_en_result *res = parsed_result;
11763         int ret = -ENOTSUP;
11764         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11765
11766         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11767                 return;
11768
11769 #ifdef RTE_NET_IXGBE
11770         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11771                         is_on);
11772 #endif
11773         switch (ret) {
11774         case 0:
11775                 break;
11776         case -EINVAL:
11777                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11778                 break;
11779         case -ENODEV:
11780                 printf("invalid port_id %d\n", res->port_id);
11781                 break;
11782         case -ENOTSUP:
11783                 printf("not supported on port %d\n", res->port_id);
11784                 break;
11785         default:
11786                 printf("programming error: (%s)\n", strerror(-ret));
11787         }
11788 }
11789
11790 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11791         .f = cmd_set_vf_split_drop_en_parsed,
11792         .data = NULL,
11793         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11794         .tokens = {
11795                 (void *)&cmd_vf_split_drop_en_set,
11796                 (void *)&cmd_vf_split_drop_en_vf,
11797                 (void *)&cmd_vf_split_drop_en_split,
11798                 (void *)&cmd_vf_split_drop_en_drop,
11799                 (void *)&cmd_vf_split_drop_en_port_id,
11800                 (void *)&cmd_vf_split_drop_en_vf_id,
11801                 (void *)&cmd_vf_split_drop_en_on_off,
11802                 NULL,
11803         },
11804 };
11805
11806 /* vf mac address configuration */
11807
11808 /* Common result structure for vf mac address */
11809 struct cmd_set_vf_mac_addr_result {
11810         cmdline_fixed_string_t set;
11811         cmdline_fixed_string_t vf;
11812         cmdline_fixed_string_t mac;
11813         cmdline_fixed_string_t addr;
11814         portid_t port_id;
11815         uint16_t vf_id;
11816         struct rte_ether_addr mac_addr;
11817
11818 };
11819
11820 /* Common CLI fields for vf split drop enable disable */
11821 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_set_vf_mac_addr_result,
11824                  set, "set");
11825 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_set_vf_mac_addr_result,
11828                  vf, "vf");
11829 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_set_vf_mac_addr_result,
11832                  mac, "mac");
11833 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_set_vf_mac_addr_result,
11836                  addr, "addr");
11837 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11838         TOKEN_NUM_INITIALIZER
11839                 (struct cmd_set_vf_mac_addr_result,
11840                  port_id, UINT16);
11841 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11842         TOKEN_NUM_INITIALIZER
11843                 (struct cmd_set_vf_mac_addr_result,
11844                  vf_id, UINT16);
11845 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11846         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11847                  mac_addr);
11848
11849 static void
11850 cmd_set_vf_mac_addr_parsed(
11851         void *parsed_result,
11852         __rte_unused struct cmdline *cl,
11853         __rte_unused void *data)
11854 {
11855         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11856         int ret = -ENOTSUP;
11857
11858         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11859                 return;
11860
11861 #ifdef RTE_NET_IXGBE
11862         if (ret == -ENOTSUP)
11863                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11864                                 &res->mac_addr);
11865 #endif
11866 #ifdef RTE_NET_I40E
11867         if (ret == -ENOTSUP)
11868                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11869                                 &res->mac_addr);
11870 #endif
11871 #ifdef RTE_NET_BNXT
11872         if (ret == -ENOTSUP)
11873                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11874                                 &res->mac_addr);
11875 #endif
11876
11877         switch (ret) {
11878         case 0:
11879                 break;
11880         case -EINVAL:
11881                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11882                 break;
11883         case -ENODEV:
11884                 printf("invalid port_id %d\n", res->port_id);
11885                 break;
11886         case -ENOTSUP:
11887                 printf("function not implemented\n");
11888                 break;
11889         default:
11890                 printf("programming error: (%s)\n", strerror(-ret));
11891         }
11892 }
11893
11894 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11895         .f = cmd_set_vf_mac_addr_parsed,
11896         .data = NULL,
11897         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11898         .tokens = {
11899                 (void *)&cmd_set_vf_mac_addr_set,
11900                 (void *)&cmd_set_vf_mac_addr_vf,
11901                 (void *)&cmd_set_vf_mac_addr_mac,
11902                 (void *)&cmd_set_vf_mac_addr_addr,
11903                 (void *)&cmd_set_vf_mac_addr_port_id,
11904                 (void *)&cmd_set_vf_mac_addr_vf_id,
11905                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11906                 NULL,
11907         },
11908 };
11909
11910 /* MACsec configuration */
11911
11912 /* Common result structure for MACsec offload enable */
11913 struct cmd_macsec_offload_on_result {
11914         cmdline_fixed_string_t set;
11915         cmdline_fixed_string_t macsec;
11916         cmdline_fixed_string_t offload;
11917         portid_t port_id;
11918         cmdline_fixed_string_t on;
11919         cmdline_fixed_string_t encrypt;
11920         cmdline_fixed_string_t en_on_off;
11921         cmdline_fixed_string_t replay_protect;
11922         cmdline_fixed_string_t rp_on_off;
11923 };
11924
11925 /* Common CLI fields for MACsec offload disable */
11926 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11927         TOKEN_STRING_INITIALIZER
11928                 (struct cmd_macsec_offload_on_result,
11929                  set, "set");
11930 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11931         TOKEN_STRING_INITIALIZER
11932                 (struct cmd_macsec_offload_on_result,
11933                  macsec, "macsec");
11934 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11935         TOKEN_STRING_INITIALIZER
11936                 (struct cmd_macsec_offload_on_result,
11937                  offload, "offload");
11938 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11939         TOKEN_NUM_INITIALIZER
11940                 (struct cmd_macsec_offload_on_result,
11941                  port_id, UINT16);
11942 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11943         TOKEN_STRING_INITIALIZER
11944                 (struct cmd_macsec_offload_on_result,
11945                  on, "on");
11946 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11947         TOKEN_STRING_INITIALIZER
11948                 (struct cmd_macsec_offload_on_result,
11949                  encrypt, "encrypt");
11950 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11951         TOKEN_STRING_INITIALIZER
11952                 (struct cmd_macsec_offload_on_result,
11953                  en_on_off, "on#off");
11954 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11955         TOKEN_STRING_INITIALIZER
11956                 (struct cmd_macsec_offload_on_result,
11957                  replay_protect, "replay-protect");
11958 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11959         TOKEN_STRING_INITIALIZER
11960                 (struct cmd_macsec_offload_on_result,
11961                  rp_on_off, "on#off");
11962
11963 static void
11964 cmd_set_macsec_offload_on_parsed(
11965         void *parsed_result,
11966         __rte_unused struct cmdline *cl,
11967         __rte_unused void *data)
11968 {
11969         struct cmd_macsec_offload_on_result *res = parsed_result;
11970         int ret = -ENOTSUP;
11971         portid_t port_id = res->port_id;
11972         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11973         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11974         struct rte_eth_dev_info dev_info;
11975
11976         if (port_id_is_invalid(port_id, ENABLED_WARN))
11977                 return;
11978         if (!port_is_stopped(port_id)) {
11979                 printf("Please stop port %d first\n", port_id);
11980                 return;
11981         }
11982
11983         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11984         if (ret != 0)
11985                 return;
11986
11987         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11988 #ifdef RTE_NET_IXGBE
11989                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11990 #endif
11991         }
11992         RTE_SET_USED(en);
11993         RTE_SET_USED(rp);
11994
11995         switch (ret) {
11996         case 0:
11997                 ports[port_id].dev_conf.txmode.offloads |=
11998                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11999                 cmd_reconfig_device_queue(port_id, 1, 1);
12000                 break;
12001         case -ENODEV:
12002                 printf("invalid port_id %d\n", port_id);
12003                 break;
12004         case -ENOTSUP:
12005                 printf("not supported on port %d\n", port_id);
12006                 break;
12007         default:
12008                 printf("programming error: (%s)\n", strerror(-ret));
12009         }
12010 }
12011
12012 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12013         .f = cmd_set_macsec_offload_on_parsed,
12014         .data = NULL,
12015         .help_str = "set macsec offload <port_id> on "
12016                 "encrypt on|off replay-protect on|off",
12017         .tokens = {
12018                 (void *)&cmd_macsec_offload_on_set,
12019                 (void *)&cmd_macsec_offload_on_macsec,
12020                 (void *)&cmd_macsec_offload_on_offload,
12021                 (void *)&cmd_macsec_offload_on_port_id,
12022                 (void *)&cmd_macsec_offload_on_on,
12023                 (void *)&cmd_macsec_offload_on_encrypt,
12024                 (void *)&cmd_macsec_offload_on_en_on_off,
12025                 (void *)&cmd_macsec_offload_on_replay_protect,
12026                 (void *)&cmd_macsec_offload_on_rp_on_off,
12027                 NULL,
12028         },
12029 };
12030
12031 /* Common result structure for MACsec offload disable */
12032 struct cmd_macsec_offload_off_result {
12033         cmdline_fixed_string_t set;
12034         cmdline_fixed_string_t macsec;
12035         cmdline_fixed_string_t offload;
12036         portid_t port_id;
12037         cmdline_fixed_string_t off;
12038 };
12039
12040 /* Common CLI fields for MACsec offload disable */
12041 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12042         TOKEN_STRING_INITIALIZER
12043                 (struct cmd_macsec_offload_off_result,
12044                  set, "set");
12045 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12046         TOKEN_STRING_INITIALIZER
12047                 (struct cmd_macsec_offload_off_result,
12048                  macsec, "macsec");
12049 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12050         TOKEN_STRING_INITIALIZER
12051                 (struct cmd_macsec_offload_off_result,
12052                  offload, "offload");
12053 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12054         TOKEN_NUM_INITIALIZER
12055                 (struct cmd_macsec_offload_off_result,
12056                  port_id, UINT16);
12057 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12058         TOKEN_STRING_INITIALIZER
12059                 (struct cmd_macsec_offload_off_result,
12060                  off, "off");
12061
12062 static void
12063 cmd_set_macsec_offload_off_parsed(
12064         void *parsed_result,
12065         __rte_unused struct cmdline *cl,
12066         __rte_unused void *data)
12067 {
12068         struct cmd_macsec_offload_off_result *res = parsed_result;
12069         int ret = -ENOTSUP;
12070         struct rte_eth_dev_info dev_info;
12071         portid_t port_id = res->port_id;
12072
12073         if (port_id_is_invalid(port_id, ENABLED_WARN))
12074                 return;
12075         if (!port_is_stopped(port_id)) {
12076                 printf("Please stop port %d first\n", port_id);
12077                 return;
12078         }
12079
12080         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12081         if (ret != 0)
12082                 return;
12083
12084         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
12085 #ifdef RTE_NET_IXGBE
12086                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12087 #endif
12088         }
12089         switch (ret) {
12090         case 0:
12091                 ports[port_id].dev_conf.txmode.offloads &=
12092                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
12093                 cmd_reconfig_device_queue(port_id, 1, 1);
12094                 break;
12095         case -ENODEV:
12096                 printf("invalid port_id %d\n", port_id);
12097                 break;
12098         case -ENOTSUP:
12099                 printf("not supported on port %d\n", port_id);
12100                 break;
12101         default:
12102                 printf("programming error: (%s)\n", strerror(-ret));
12103         }
12104 }
12105
12106 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12107         .f = cmd_set_macsec_offload_off_parsed,
12108         .data = NULL,
12109         .help_str = "set macsec offload <port_id> off",
12110         .tokens = {
12111                 (void *)&cmd_macsec_offload_off_set,
12112                 (void *)&cmd_macsec_offload_off_macsec,
12113                 (void *)&cmd_macsec_offload_off_offload,
12114                 (void *)&cmd_macsec_offload_off_port_id,
12115                 (void *)&cmd_macsec_offload_off_off,
12116                 NULL,
12117         },
12118 };
12119
12120 /* Common result structure for MACsec secure connection configure */
12121 struct cmd_macsec_sc_result {
12122         cmdline_fixed_string_t set;
12123         cmdline_fixed_string_t macsec;
12124         cmdline_fixed_string_t sc;
12125         cmdline_fixed_string_t tx_rx;
12126         portid_t port_id;
12127         struct rte_ether_addr mac;
12128         uint16_t pi;
12129 };
12130
12131 /* Common CLI fields for MACsec secure connection configure */
12132 cmdline_parse_token_string_t cmd_macsec_sc_set =
12133         TOKEN_STRING_INITIALIZER
12134                 (struct cmd_macsec_sc_result,
12135                  set, "set");
12136 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12137         TOKEN_STRING_INITIALIZER
12138                 (struct cmd_macsec_sc_result,
12139                  macsec, "macsec");
12140 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12141         TOKEN_STRING_INITIALIZER
12142                 (struct cmd_macsec_sc_result,
12143                  sc, "sc");
12144 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12145         TOKEN_STRING_INITIALIZER
12146                 (struct cmd_macsec_sc_result,
12147                  tx_rx, "tx#rx");
12148 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12149         TOKEN_NUM_INITIALIZER
12150                 (struct cmd_macsec_sc_result,
12151                  port_id, UINT16);
12152 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12153         TOKEN_ETHERADDR_INITIALIZER
12154                 (struct cmd_macsec_sc_result,
12155                  mac);
12156 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12157         TOKEN_NUM_INITIALIZER
12158                 (struct cmd_macsec_sc_result,
12159                  pi, UINT16);
12160
12161 static void
12162 cmd_set_macsec_sc_parsed(
12163         void *parsed_result,
12164         __rte_unused struct cmdline *cl,
12165         __rte_unused void *data)
12166 {
12167         struct cmd_macsec_sc_result *res = parsed_result;
12168         int ret = -ENOTSUP;
12169         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12170
12171 #ifdef RTE_NET_IXGBE
12172         ret = is_tx ?
12173                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12174                                 res->mac.addr_bytes) :
12175                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12176                                 res->mac.addr_bytes, res->pi);
12177 #endif
12178         RTE_SET_USED(is_tx);
12179
12180         switch (ret) {
12181         case 0:
12182                 break;
12183         case -ENODEV:
12184                 printf("invalid port_id %d\n", res->port_id);
12185                 break;
12186         case -ENOTSUP:
12187                 printf("not supported on port %d\n", res->port_id);
12188                 break;
12189         default:
12190                 printf("programming error: (%s)\n", strerror(-ret));
12191         }
12192 }
12193
12194 cmdline_parse_inst_t cmd_set_macsec_sc = {
12195         .f = cmd_set_macsec_sc_parsed,
12196         .data = NULL,
12197         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12198         .tokens = {
12199                 (void *)&cmd_macsec_sc_set,
12200                 (void *)&cmd_macsec_sc_macsec,
12201                 (void *)&cmd_macsec_sc_sc,
12202                 (void *)&cmd_macsec_sc_tx_rx,
12203                 (void *)&cmd_macsec_sc_port_id,
12204                 (void *)&cmd_macsec_sc_mac,
12205                 (void *)&cmd_macsec_sc_pi,
12206                 NULL,
12207         },
12208 };
12209
12210 /* Common result structure for MACsec secure connection configure */
12211 struct cmd_macsec_sa_result {
12212         cmdline_fixed_string_t set;
12213         cmdline_fixed_string_t macsec;
12214         cmdline_fixed_string_t sa;
12215         cmdline_fixed_string_t tx_rx;
12216         portid_t port_id;
12217         uint8_t idx;
12218         uint8_t an;
12219         uint32_t pn;
12220         cmdline_fixed_string_t key;
12221 };
12222
12223 /* Common CLI fields for MACsec secure connection configure */
12224 cmdline_parse_token_string_t cmd_macsec_sa_set =
12225         TOKEN_STRING_INITIALIZER
12226                 (struct cmd_macsec_sa_result,
12227                  set, "set");
12228 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12229         TOKEN_STRING_INITIALIZER
12230                 (struct cmd_macsec_sa_result,
12231                  macsec, "macsec");
12232 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12233         TOKEN_STRING_INITIALIZER
12234                 (struct cmd_macsec_sa_result,
12235                  sa, "sa");
12236 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12237         TOKEN_STRING_INITIALIZER
12238                 (struct cmd_macsec_sa_result,
12239                  tx_rx, "tx#rx");
12240 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12241         TOKEN_NUM_INITIALIZER
12242                 (struct cmd_macsec_sa_result,
12243                  port_id, UINT16);
12244 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12245         TOKEN_NUM_INITIALIZER
12246                 (struct cmd_macsec_sa_result,
12247                  idx, UINT8);
12248 cmdline_parse_token_num_t cmd_macsec_sa_an =
12249         TOKEN_NUM_INITIALIZER
12250                 (struct cmd_macsec_sa_result,
12251                  an, UINT8);
12252 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12253         TOKEN_NUM_INITIALIZER
12254                 (struct cmd_macsec_sa_result,
12255                  pn, UINT32);
12256 cmdline_parse_token_string_t cmd_macsec_sa_key =
12257         TOKEN_STRING_INITIALIZER
12258                 (struct cmd_macsec_sa_result,
12259                  key, NULL);
12260
12261 static void
12262 cmd_set_macsec_sa_parsed(
12263         void *parsed_result,
12264         __rte_unused struct cmdline *cl,
12265         __rte_unused void *data)
12266 {
12267         struct cmd_macsec_sa_result *res = parsed_result;
12268         int ret = -ENOTSUP;
12269         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12270         uint8_t key[16] = { 0 };
12271         uint8_t xdgt0;
12272         uint8_t xdgt1;
12273         int key_len;
12274         int i;
12275
12276         key_len = strlen(res->key) / 2;
12277         if (key_len > 16)
12278                 key_len = 16;
12279
12280         for (i = 0; i < key_len; i++) {
12281                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12282                 if (xdgt0 == 0xFF)
12283                         return;
12284                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12285                 if (xdgt1 == 0xFF)
12286                         return;
12287                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12288         }
12289
12290 #ifdef RTE_NET_IXGBE
12291         ret = is_tx ?
12292                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12293                         res->idx, res->an, res->pn, key) :
12294                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12295                         res->idx, res->an, res->pn, key);
12296 #endif
12297         RTE_SET_USED(is_tx);
12298         RTE_SET_USED(key);
12299
12300         switch (ret) {
12301         case 0:
12302                 break;
12303         case -EINVAL:
12304                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12305                 break;
12306         case -ENODEV:
12307                 printf("invalid port_id %d\n", res->port_id);
12308                 break;
12309         case -ENOTSUP:
12310                 printf("not supported on port %d\n", res->port_id);
12311                 break;
12312         default:
12313                 printf("programming error: (%s)\n", strerror(-ret));
12314         }
12315 }
12316
12317 cmdline_parse_inst_t cmd_set_macsec_sa = {
12318         .f = cmd_set_macsec_sa_parsed,
12319         .data = NULL,
12320         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12321         .tokens = {
12322                 (void *)&cmd_macsec_sa_set,
12323                 (void *)&cmd_macsec_sa_macsec,
12324                 (void *)&cmd_macsec_sa_sa,
12325                 (void *)&cmd_macsec_sa_tx_rx,
12326                 (void *)&cmd_macsec_sa_port_id,
12327                 (void *)&cmd_macsec_sa_idx,
12328                 (void *)&cmd_macsec_sa_an,
12329                 (void *)&cmd_macsec_sa_pn,
12330                 (void *)&cmd_macsec_sa_key,
12331                 NULL,
12332         },
12333 };
12334
12335 /* VF unicast promiscuous mode configuration */
12336
12337 /* Common result structure for VF unicast promiscuous mode */
12338 struct cmd_vf_promisc_result {
12339         cmdline_fixed_string_t set;
12340         cmdline_fixed_string_t vf;
12341         cmdline_fixed_string_t promisc;
12342         portid_t port_id;
12343         uint32_t vf_id;
12344         cmdline_fixed_string_t on_off;
12345 };
12346
12347 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12348 cmdline_parse_token_string_t cmd_vf_promisc_set =
12349         TOKEN_STRING_INITIALIZER
12350                 (struct cmd_vf_promisc_result,
12351                  set, "set");
12352 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_vf_promisc_result,
12355                  vf, "vf");
12356 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12357         TOKEN_STRING_INITIALIZER
12358                 (struct cmd_vf_promisc_result,
12359                  promisc, "promisc");
12360 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12361         TOKEN_NUM_INITIALIZER
12362                 (struct cmd_vf_promisc_result,
12363                  port_id, UINT16);
12364 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12365         TOKEN_NUM_INITIALIZER
12366                 (struct cmd_vf_promisc_result,
12367                  vf_id, UINT32);
12368 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12369         TOKEN_STRING_INITIALIZER
12370                 (struct cmd_vf_promisc_result,
12371                  on_off, "on#off");
12372
12373 static void
12374 cmd_set_vf_promisc_parsed(
12375         void *parsed_result,
12376         __rte_unused struct cmdline *cl,
12377         __rte_unused void *data)
12378 {
12379         struct cmd_vf_promisc_result *res = parsed_result;
12380         int ret = -ENOTSUP;
12381
12382         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12383
12384         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12385                 return;
12386
12387 #ifdef RTE_NET_I40E
12388         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12389                                                   res->vf_id, is_on);
12390 #endif
12391
12392         switch (ret) {
12393         case 0:
12394                 break;
12395         case -EINVAL:
12396                 printf("invalid vf_id %d\n", res->vf_id);
12397                 break;
12398         case -ENODEV:
12399                 printf("invalid port_id %d\n", res->port_id);
12400                 break;
12401         case -ENOTSUP:
12402                 printf("function not implemented\n");
12403                 break;
12404         default:
12405                 printf("programming error: (%s)\n", strerror(-ret));
12406         }
12407 }
12408
12409 cmdline_parse_inst_t cmd_set_vf_promisc = {
12410         .f = cmd_set_vf_promisc_parsed,
12411         .data = NULL,
12412         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12413                 "Set unicast promiscuous mode for a VF from the PF",
12414         .tokens = {
12415                 (void *)&cmd_vf_promisc_set,
12416                 (void *)&cmd_vf_promisc_vf,
12417                 (void *)&cmd_vf_promisc_promisc,
12418                 (void *)&cmd_vf_promisc_port_id,
12419                 (void *)&cmd_vf_promisc_vf_id,
12420                 (void *)&cmd_vf_promisc_on_off,
12421                 NULL,
12422         },
12423 };
12424
12425 /* VF multicast promiscuous mode configuration */
12426
12427 /* Common result structure for VF multicast promiscuous mode */
12428 struct cmd_vf_allmulti_result {
12429         cmdline_fixed_string_t set;
12430         cmdline_fixed_string_t vf;
12431         cmdline_fixed_string_t allmulti;
12432         portid_t port_id;
12433         uint32_t vf_id;
12434         cmdline_fixed_string_t on_off;
12435 };
12436
12437 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12438 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12439         TOKEN_STRING_INITIALIZER
12440                 (struct cmd_vf_allmulti_result,
12441                  set, "set");
12442 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12443         TOKEN_STRING_INITIALIZER
12444                 (struct cmd_vf_allmulti_result,
12445                  vf, "vf");
12446 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12447         TOKEN_STRING_INITIALIZER
12448                 (struct cmd_vf_allmulti_result,
12449                  allmulti, "allmulti");
12450 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12451         TOKEN_NUM_INITIALIZER
12452                 (struct cmd_vf_allmulti_result,
12453                  port_id, UINT16);
12454 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12455         TOKEN_NUM_INITIALIZER
12456                 (struct cmd_vf_allmulti_result,
12457                  vf_id, UINT32);
12458 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12459         TOKEN_STRING_INITIALIZER
12460                 (struct cmd_vf_allmulti_result,
12461                  on_off, "on#off");
12462
12463 static void
12464 cmd_set_vf_allmulti_parsed(
12465         void *parsed_result,
12466         __rte_unused struct cmdline *cl,
12467         __rte_unused void *data)
12468 {
12469         struct cmd_vf_allmulti_result *res = parsed_result;
12470         int ret = -ENOTSUP;
12471
12472         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12473
12474         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12475                 return;
12476
12477 #ifdef RTE_NET_I40E
12478         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12479                                                     res->vf_id, is_on);
12480 #endif
12481
12482         switch (ret) {
12483         case 0:
12484                 break;
12485         case -EINVAL:
12486                 printf("invalid vf_id %d\n", res->vf_id);
12487                 break;
12488         case -ENODEV:
12489                 printf("invalid port_id %d\n", res->port_id);
12490                 break;
12491         case -ENOTSUP:
12492                 printf("function not implemented\n");
12493                 break;
12494         default:
12495                 printf("programming error: (%s)\n", strerror(-ret));
12496         }
12497 }
12498
12499 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12500         .f = cmd_set_vf_allmulti_parsed,
12501         .data = NULL,
12502         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12503                 "Set multicast promiscuous mode for a VF from the PF",
12504         .tokens = {
12505                 (void *)&cmd_vf_allmulti_set,
12506                 (void *)&cmd_vf_allmulti_vf,
12507                 (void *)&cmd_vf_allmulti_allmulti,
12508                 (void *)&cmd_vf_allmulti_port_id,
12509                 (void *)&cmd_vf_allmulti_vf_id,
12510                 (void *)&cmd_vf_allmulti_on_off,
12511                 NULL,
12512         },
12513 };
12514
12515 /* vf broadcast mode configuration */
12516
12517 /* Common result structure for vf broadcast */
12518 struct cmd_set_vf_broadcast_result {
12519         cmdline_fixed_string_t set;
12520         cmdline_fixed_string_t vf;
12521         cmdline_fixed_string_t broadcast;
12522         portid_t port_id;
12523         uint16_t vf_id;
12524         cmdline_fixed_string_t on_off;
12525 };
12526
12527 /* Common CLI fields for vf broadcast enable disable */
12528 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_set_vf_broadcast_result,
12531                  set, "set");
12532 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_set_vf_broadcast_result,
12535                  vf, "vf");
12536 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_set_vf_broadcast_result,
12539                  broadcast, "broadcast");
12540 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12541         TOKEN_NUM_INITIALIZER
12542                 (struct cmd_set_vf_broadcast_result,
12543                  port_id, UINT16);
12544 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12545         TOKEN_NUM_INITIALIZER
12546                 (struct cmd_set_vf_broadcast_result,
12547                  vf_id, UINT16);
12548 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12549         TOKEN_STRING_INITIALIZER
12550                 (struct cmd_set_vf_broadcast_result,
12551                  on_off, "on#off");
12552
12553 static void
12554 cmd_set_vf_broadcast_parsed(
12555         void *parsed_result,
12556         __rte_unused struct cmdline *cl,
12557         __rte_unused void *data)
12558 {
12559         struct cmd_set_vf_broadcast_result *res = parsed_result;
12560         int ret = -ENOTSUP;
12561
12562         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12563
12564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12565                 return;
12566
12567 #ifdef RTE_NET_I40E
12568         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12569                                             res->vf_id, is_on);
12570 #endif
12571
12572         switch (ret) {
12573         case 0:
12574                 break;
12575         case -EINVAL:
12576                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12577                 break;
12578         case -ENODEV:
12579                 printf("invalid port_id %d\n", res->port_id);
12580                 break;
12581         case -ENOTSUP:
12582                 printf("function not implemented\n");
12583                 break;
12584         default:
12585                 printf("programming error: (%s)\n", strerror(-ret));
12586         }
12587 }
12588
12589 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12590         .f = cmd_set_vf_broadcast_parsed,
12591         .data = NULL,
12592         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12593         .tokens = {
12594                 (void *)&cmd_set_vf_broadcast_set,
12595                 (void *)&cmd_set_vf_broadcast_vf,
12596                 (void *)&cmd_set_vf_broadcast_broadcast,
12597                 (void *)&cmd_set_vf_broadcast_port_id,
12598                 (void *)&cmd_set_vf_broadcast_vf_id,
12599                 (void *)&cmd_set_vf_broadcast_on_off,
12600                 NULL,
12601         },
12602 };
12603
12604 /* vf vlan tag configuration */
12605
12606 /* Common result structure for vf vlan tag */
12607 struct cmd_set_vf_vlan_tag_result {
12608         cmdline_fixed_string_t set;
12609         cmdline_fixed_string_t vf;
12610         cmdline_fixed_string_t vlan;
12611         cmdline_fixed_string_t tag;
12612         portid_t port_id;
12613         uint16_t vf_id;
12614         cmdline_fixed_string_t on_off;
12615 };
12616
12617 /* Common CLI fields for vf vlan tag enable disable */
12618 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12619         TOKEN_STRING_INITIALIZER
12620                 (struct cmd_set_vf_vlan_tag_result,
12621                  set, "set");
12622 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12623         TOKEN_STRING_INITIALIZER
12624                 (struct cmd_set_vf_vlan_tag_result,
12625                  vf, "vf");
12626 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12627         TOKEN_STRING_INITIALIZER
12628                 (struct cmd_set_vf_vlan_tag_result,
12629                  vlan, "vlan");
12630 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12631         TOKEN_STRING_INITIALIZER
12632                 (struct cmd_set_vf_vlan_tag_result,
12633                  tag, "tag");
12634 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12635         TOKEN_NUM_INITIALIZER
12636                 (struct cmd_set_vf_vlan_tag_result,
12637                  port_id, UINT16);
12638 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12639         TOKEN_NUM_INITIALIZER
12640                 (struct cmd_set_vf_vlan_tag_result,
12641                  vf_id, UINT16);
12642 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12643         TOKEN_STRING_INITIALIZER
12644                 (struct cmd_set_vf_vlan_tag_result,
12645                  on_off, "on#off");
12646
12647 static void
12648 cmd_set_vf_vlan_tag_parsed(
12649         void *parsed_result,
12650         __rte_unused struct cmdline *cl,
12651         __rte_unused void *data)
12652 {
12653         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12654         int ret = -ENOTSUP;
12655
12656         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12657
12658         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12659                 return;
12660
12661 #ifdef RTE_NET_I40E
12662         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12663                                            res->vf_id, is_on);
12664 #endif
12665
12666         switch (ret) {
12667         case 0:
12668                 break;
12669         case -EINVAL:
12670                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12671                 break;
12672         case -ENODEV:
12673                 printf("invalid port_id %d\n", res->port_id);
12674                 break;
12675         case -ENOTSUP:
12676                 printf("function not implemented\n");
12677                 break;
12678         default:
12679                 printf("programming error: (%s)\n", strerror(-ret));
12680         }
12681 }
12682
12683 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12684         .f = cmd_set_vf_vlan_tag_parsed,
12685         .data = NULL,
12686         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12687         .tokens = {
12688                 (void *)&cmd_set_vf_vlan_tag_set,
12689                 (void *)&cmd_set_vf_vlan_tag_vf,
12690                 (void *)&cmd_set_vf_vlan_tag_vlan,
12691                 (void *)&cmd_set_vf_vlan_tag_tag,
12692                 (void *)&cmd_set_vf_vlan_tag_port_id,
12693                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12694                 (void *)&cmd_set_vf_vlan_tag_on_off,
12695                 NULL,
12696         },
12697 };
12698
12699 /* Common definition of VF and TC TX bandwidth configuration */
12700 struct cmd_vf_tc_bw_result {
12701         cmdline_fixed_string_t set;
12702         cmdline_fixed_string_t vf;
12703         cmdline_fixed_string_t tc;
12704         cmdline_fixed_string_t tx;
12705         cmdline_fixed_string_t min_bw;
12706         cmdline_fixed_string_t max_bw;
12707         cmdline_fixed_string_t strict_link_prio;
12708         portid_t port_id;
12709         uint16_t vf_id;
12710         uint8_t tc_no;
12711         uint32_t bw;
12712         cmdline_fixed_string_t bw_list;
12713         uint8_t tc_map;
12714 };
12715
12716 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12717         TOKEN_STRING_INITIALIZER
12718                 (struct cmd_vf_tc_bw_result,
12719                  set, "set");
12720 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12721         TOKEN_STRING_INITIALIZER
12722                 (struct cmd_vf_tc_bw_result,
12723                  vf, "vf");
12724 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12725         TOKEN_STRING_INITIALIZER
12726                 (struct cmd_vf_tc_bw_result,
12727                  tc, "tc");
12728 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12729         TOKEN_STRING_INITIALIZER
12730                 (struct cmd_vf_tc_bw_result,
12731                  tx, "tx");
12732 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12733         TOKEN_STRING_INITIALIZER
12734                 (struct cmd_vf_tc_bw_result,
12735                  strict_link_prio, "strict-link-priority");
12736 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_vf_tc_bw_result,
12739                  min_bw, "min-bandwidth");
12740 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12741         TOKEN_STRING_INITIALIZER
12742                 (struct cmd_vf_tc_bw_result,
12743                  max_bw, "max-bandwidth");
12744 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12745         TOKEN_NUM_INITIALIZER
12746                 (struct cmd_vf_tc_bw_result,
12747                  port_id, UINT16);
12748 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12749         TOKEN_NUM_INITIALIZER
12750                 (struct cmd_vf_tc_bw_result,
12751                  vf_id, UINT16);
12752 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12753         TOKEN_NUM_INITIALIZER
12754                 (struct cmd_vf_tc_bw_result,
12755                  tc_no, UINT8);
12756 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12757         TOKEN_NUM_INITIALIZER
12758                 (struct cmd_vf_tc_bw_result,
12759                  bw, UINT32);
12760 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12761         TOKEN_STRING_INITIALIZER
12762                 (struct cmd_vf_tc_bw_result,
12763                  bw_list, NULL);
12764 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12765         TOKEN_NUM_INITIALIZER
12766                 (struct cmd_vf_tc_bw_result,
12767                  tc_map, UINT8);
12768
12769 /* VF max bandwidth setting */
12770 static void
12771 cmd_vf_max_bw_parsed(
12772         void *parsed_result,
12773         __rte_unused struct cmdline *cl,
12774         __rte_unused void *data)
12775 {
12776         struct cmd_vf_tc_bw_result *res = parsed_result;
12777         int ret = -ENOTSUP;
12778
12779         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12780                 return;
12781
12782 #ifdef RTE_NET_I40E
12783         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12784                                          res->vf_id, res->bw);
12785 #endif
12786
12787         switch (ret) {
12788         case 0:
12789                 break;
12790         case -EINVAL:
12791                 printf("invalid vf_id %d or bandwidth %d\n",
12792                        res->vf_id, res->bw);
12793                 break;
12794         case -ENODEV:
12795                 printf("invalid port_id %d\n", res->port_id);
12796                 break;
12797         case -ENOTSUP:
12798                 printf("function not implemented\n");
12799                 break;
12800         default:
12801                 printf("programming error: (%s)\n", strerror(-ret));
12802         }
12803 }
12804
12805 cmdline_parse_inst_t cmd_vf_max_bw = {
12806         .f = cmd_vf_max_bw_parsed,
12807         .data = NULL,
12808         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12809         .tokens = {
12810                 (void *)&cmd_vf_tc_bw_set,
12811                 (void *)&cmd_vf_tc_bw_vf,
12812                 (void *)&cmd_vf_tc_bw_tx,
12813                 (void *)&cmd_vf_tc_bw_max_bw,
12814                 (void *)&cmd_vf_tc_bw_port_id,
12815                 (void *)&cmd_vf_tc_bw_vf_id,
12816                 (void *)&cmd_vf_tc_bw_bw,
12817                 NULL,
12818         },
12819 };
12820
12821 static int
12822 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12823                            uint8_t *tc_num,
12824                            char *str)
12825 {
12826         uint32_t size;
12827         const char *p, *p0 = str;
12828         char s[256];
12829         char *end;
12830         char *str_fld[16];
12831         uint16_t i;
12832         int ret;
12833
12834         p = strchr(p0, '(');
12835         if (p == NULL) {
12836                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12837                 return -1;
12838         }
12839         p++;
12840         p0 = strchr(p, ')');
12841         if (p0 == NULL) {
12842                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12843                 return -1;
12844         }
12845         size = p0 - p;
12846         if (size >= sizeof(s)) {
12847                 printf("The string size exceeds the internal buffer size\n");
12848                 return -1;
12849         }
12850         snprintf(s, sizeof(s), "%.*s", size, p);
12851         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12852         if (ret <= 0) {
12853                 printf("Failed to get the bandwidth list. ");
12854                 return -1;
12855         }
12856         *tc_num = ret;
12857         for (i = 0; i < ret; i++)
12858                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12859
12860         return 0;
12861 }
12862
12863 /* TC min bandwidth setting */
12864 static void
12865 cmd_vf_tc_min_bw_parsed(
12866         void *parsed_result,
12867         __rte_unused struct cmdline *cl,
12868         __rte_unused void *data)
12869 {
12870         struct cmd_vf_tc_bw_result *res = parsed_result;
12871         uint8_t tc_num;
12872         uint8_t bw[16];
12873         int ret = -ENOTSUP;
12874
12875         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12876                 return;
12877
12878         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12879         if (ret)
12880                 return;
12881
12882 #ifdef RTE_NET_I40E
12883         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12884                                               tc_num, bw);
12885 #endif
12886
12887         switch (ret) {
12888         case 0:
12889                 break;
12890         case -EINVAL:
12891                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12892                 break;
12893         case -ENODEV:
12894                 printf("invalid port_id %d\n", res->port_id);
12895                 break;
12896         case -ENOTSUP:
12897                 printf("function not implemented\n");
12898                 break;
12899         default:
12900                 printf("programming error: (%s)\n", strerror(-ret));
12901         }
12902 }
12903
12904 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12905         .f = cmd_vf_tc_min_bw_parsed,
12906         .data = NULL,
12907         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12908                     " <bw1, bw2, ...>",
12909         .tokens = {
12910                 (void *)&cmd_vf_tc_bw_set,
12911                 (void *)&cmd_vf_tc_bw_vf,
12912                 (void *)&cmd_vf_tc_bw_tc,
12913                 (void *)&cmd_vf_tc_bw_tx,
12914                 (void *)&cmd_vf_tc_bw_min_bw,
12915                 (void *)&cmd_vf_tc_bw_port_id,
12916                 (void *)&cmd_vf_tc_bw_vf_id,
12917                 (void *)&cmd_vf_tc_bw_bw_list,
12918                 NULL,
12919         },
12920 };
12921
12922 static void
12923 cmd_tc_min_bw_parsed(
12924         void *parsed_result,
12925         __rte_unused struct cmdline *cl,
12926         __rte_unused void *data)
12927 {
12928         struct cmd_vf_tc_bw_result *res = parsed_result;
12929         struct rte_port *port;
12930         uint8_t tc_num;
12931         uint8_t bw[16];
12932         int ret = -ENOTSUP;
12933
12934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12935                 return;
12936
12937         port = &ports[res->port_id];
12938         /** Check if the port is not started **/
12939         if (port->port_status != RTE_PORT_STOPPED) {
12940                 printf("Please stop port %d first\n", res->port_id);
12941                 return;
12942         }
12943
12944         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12945         if (ret)
12946                 return;
12947
12948 #ifdef RTE_NET_IXGBE
12949         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12950 #endif
12951
12952         switch (ret) {
12953         case 0:
12954                 break;
12955         case -EINVAL:
12956                 printf("invalid bandwidth\n");
12957                 break;
12958         case -ENODEV:
12959                 printf("invalid port_id %d\n", res->port_id);
12960                 break;
12961         case -ENOTSUP:
12962                 printf("function not implemented\n");
12963                 break;
12964         default:
12965                 printf("programming error: (%s)\n", strerror(-ret));
12966         }
12967 }
12968
12969 cmdline_parse_inst_t cmd_tc_min_bw = {
12970         .f = cmd_tc_min_bw_parsed,
12971         .data = NULL,
12972         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12973         .tokens = {
12974                 (void *)&cmd_vf_tc_bw_set,
12975                 (void *)&cmd_vf_tc_bw_tc,
12976                 (void *)&cmd_vf_tc_bw_tx,
12977                 (void *)&cmd_vf_tc_bw_min_bw,
12978                 (void *)&cmd_vf_tc_bw_port_id,
12979                 (void *)&cmd_vf_tc_bw_bw_list,
12980                 NULL,
12981         },
12982 };
12983
12984 /* TC max bandwidth setting */
12985 static void
12986 cmd_vf_tc_max_bw_parsed(
12987         void *parsed_result,
12988         __rte_unused struct cmdline *cl,
12989         __rte_unused void *data)
12990 {
12991         struct cmd_vf_tc_bw_result *res = parsed_result;
12992         int ret = -ENOTSUP;
12993
12994         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12995                 return;
12996
12997 #ifdef RTE_NET_I40E
12998         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12999                                             res->tc_no, res->bw);
13000 #endif
13001
13002         switch (ret) {
13003         case 0:
13004                 break;
13005         case -EINVAL:
13006                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13007                        res->vf_id, res->tc_no, res->bw);
13008                 break;
13009         case -ENODEV:
13010                 printf("invalid port_id %d\n", res->port_id);
13011                 break;
13012         case -ENOTSUP:
13013                 printf("function not implemented\n");
13014                 break;
13015         default:
13016                 printf("programming error: (%s)\n", strerror(-ret));
13017         }
13018 }
13019
13020 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13021         .f = cmd_vf_tc_max_bw_parsed,
13022         .data = NULL,
13023         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13024                     " <bandwidth>",
13025         .tokens = {
13026                 (void *)&cmd_vf_tc_bw_set,
13027                 (void *)&cmd_vf_tc_bw_vf,
13028                 (void *)&cmd_vf_tc_bw_tc,
13029                 (void *)&cmd_vf_tc_bw_tx,
13030                 (void *)&cmd_vf_tc_bw_max_bw,
13031                 (void *)&cmd_vf_tc_bw_port_id,
13032                 (void *)&cmd_vf_tc_bw_vf_id,
13033                 (void *)&cmd_vf_tc_bw_tc_no,
13034                 (void *)&cmd_vf_tc_bw_bw,
13035                 NULL,
13036         },
13037 };
13038
13039 /** Set VXLAN encapsulation details */
13040 struct cmd_set_vxlan_result {
13041         cmdline_fixed_string_t set;
13042         cmdline_fixed_string_t vxlan;
13043         cmdline_fixed_string_t pos_token;
13044         cmdline_fixed_string_t ip_version;
13045         uint32_t vlan_present:1;
13046         uint32_t vni;
13047         uint16_t udp_src;
13048         uint16_t udp_dst;
13049         cmdline_ipaddr_t ip_src;
13050         cmdline_ipaddr_t ip_dst;
13051         uint16_t tci;
13052         uint8_t tos;
13053         uint8_t ttl;
13054         struct rte_ether_addr eth_src;
13055         struct rte_ether_addr eth_dst;
13056 };
13057
13058 cmdline_parse_token_string_t cmd_set_vxlan_set =
13059         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13060 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13061         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13062 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13063         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13064                                  "vxlan-tos-ttl");
13065 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13066         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13067                                  "vxlan-with-vlan");
13068 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13069         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13070                                  "ip-version");
13071 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13072         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13073                                  "ipv4#ipv6");
13074 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13075         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13076                                  "vni");
13077 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13078         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
13079 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13080         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13081                                  "udp-src");
13082 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13083         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
13084 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13085         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13086                                  "udp-dst");
13087 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13088         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
13089 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13090         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13091                                  "ip-tos");
13092 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13093         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
13094 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13095         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13096                                  "ip-ttl");
13097 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13098         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
13099 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13100         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13101                                  "ip-src");
13102 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13103         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13104 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13105         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13106                                  "ip-dst");
13107 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13108         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13109 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13110         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13111                                  "vlan-tci");
13112 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13113         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
13114 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13115         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13116                                  "eth-src");
13117 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13118         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13119 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13120         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13121                                  "eth-dst");
13122 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13123         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13124
13125 static void cmd_set_vxlan_parsed(void *parsed_result,
13126         __rte_unused struct cmdline *cl,
13127         __rte_unused void *data)
13128 {
13129         struct cmd_set_vxlan_result *res = parsed_result;
13130         union {
13131                 uint32_t vxlan_id;
13132                 uint8_t vni[4];
13133         } id = {
13134                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13135         };
13136
13137         vxlan_encap_conf.select_tos_ttl = 0;
13138         if (strcmp(res->vxlan, "vxlan") == 0)
13139                 vxlan_encap_conf.select_vlan = 0;
13140         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13141                 vxlan_encap_conf.select_vlan = 1;
13142         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13143                 vxlan_encap_conf.select_vlan = 0;
13144                 vxlan_encap_conf.select_tos_ttl = 1;
13145         }
13146         if (strcmp(res->ip_version, "ipv4") == 0)
13147                 vxlan_encap_conf.select_ipv4 = 1;
13148         else if (strcmp(res->ip_version, "ipv6") == 0)
13149                 vxlan_encap_conf.select_ipv4 = 0;
13150         else
13151                 return;
13152         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13153         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13154         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13155         vxlan_encap_conf.ip_tos = res->tos;
13156         vxlan_encap_conf.ip_ttl = res->ttl;
13157         if (vxlan_encap_conf.select_ipv4) {
13158                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13159                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13160         } else {
13161                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13162                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13163         }
13164         if (vxlan_encap_conf.select_vlan)
13165                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13166         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13167                    RTE_ETHER_ADDR_LEN);
13168         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13169                    RTE_ETHER_ADDR_LEN);
13170 }
13171
13172 cmdline_parse_inst_t cmd_set_vxlan = {
13173         .f = cmd_set_vxlan_parsed,
13174         .data = NULL,
13175         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13176                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13177                 " eth-src <eth-src> eth-dst <eth-dst>",
13178         .tokens = {
13179                 (void *)&cmd_set_vxlan_set,
13180                 (void *)&cmd_set_vxlan_vxlan,
13181                 (void *)&cmd_set_vxlan_ip_version,
13182                 (void *)&cmd_set_vxlan_ip_version_value,
13183                 (void *)&cmd_set_vxlan_vni,
13184                 (void *)&cmd_set_vxlan_vni_value,
13185                 (void *)&cmd_set_vxlan_udp_src,
13186                 (void *)&cmd_set_vxlan_udp_src_value,
13187                 (void *)&cmd_set_vxlan_udp_dst,
13188                 (void *)&cmd_set_vxlan_udp_dst_value,
13189                 (void *)&cmd_set_vxlan_ip_src,
13190                 (void *)&cmd_set_vxlan_ip_src_value,
13191                 (void *)&cmd_set_vxlan_ip_dst,
13192                 (void *)&cmd_set_vxlan_ip_dst_value,
13193                 (void *)&cmd_set_vxlan_eth_src,
13194                 (void *)&cmd_set_vxlan_eth_src_value,
13195                 (void *)&cmd_set_vxlan_eth_dst,
13196                 (void *)&cmd_set_vxlan_eth_dst_value,
13197                 NULL,
13198         },
13199 };
13200
13201 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13202         .f = cmd_set_vxlan_parsed,
13203         .data = NULL,
13204         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13205                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13206                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13207                 " eth-dst <eth-dst>",
13208         .tokens = {
13209                 (void *)&cmd_set_vxlan_set,
13210                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13211                 (void *)&cmd_set_vxlan_ip_version,
13212                 (void *)&cmd_set_vxlan_ip_version_value,
13213                 (void *)&cmd_set_vxlan_vni,
13214                 (void *)&cmd_set_vxlan_vni_value,
13215                 (void *)&cmd_set_vxlan_udp_src,
13216                 (void *)&cmd_set_vxlan_udp_src_value,
13217                 (void *)&cmd_set_vxlan_udp_dst,
13218                 (void *)&cmd_set_vxlan_udp_dst_value,
13219                 (void *)&cmd_set_vxlan_ip_tos,
13220                 (void *)&cmd_set_vxlan_ip_tos_value,
13221                 (void *)&cmd_set_vxlan_ip_ttl,
13222                 (void *)&cmd_set_vxlan_ip_ttl_value,
13223                 (void *)&cmd_set_vxlan_ip_src,
13224                 (void *)&cmd_set_vxlan_ip_src_value,
13225                 (void *)&cmd_set_vxlan_ip_dst,
13226                 (void *)&cmd_set_vxlan_ip_dst_value,
13227                 (void *)&cmd_set_vxlan_eth_src,
13228                 (void *)&cmd_set_vxlan_eth_src_value,
13229                 (void *)&cmd_set_vxlan_eth_dst,
13230                 (void *)&cmd_set_vxlan_eth_dst_value,
13231                 NULL,
13232         },
13233 };
13234
13235 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13236         .f = cmd_set_vxlan_parsed,
13237         .data = NULL,
13238         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13239                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13240                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13241                 " <eth-dst>",
13242         .tokens = {
13243                 (void *)&cmd_set_vxlan_set,
13244                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13245                 (void *)&cmd_set_vxlan_ip_version,
13246                 (void *)&cmd_set_vxlan_ip_version_value,
13247                 (void *)&cmd_set_vxlan_vni,
13248                 (void *)&cmd_set_vxlan_vni_value,
13249                 (void *)&cmd_set_vxlan_udp_src,
13250                 (void *)&cmd_set_vxlan_udp_src_value,
13251                 (void *)&cmd_set_vxlan_udp_dst,
13252                 (void *)&cmd_set_vxlan_udp_dst_value,
13253                 (void *)&cmd_set_vxlan_ip_src,
13254                 (void *)&cmd_set_vxlan_ip_src_value,
13255                 (void *)&cmd_set_vxlan_ip_dst,
13256                 (void *)&cmd_set_vxlan_ip_dst_value,
13257                 (void *)&cmd_set_vxlan_vlan,
13258                 (void *)&cmd_set_vxlan_vlan_value,
13259                 (void *)&cmd_set_vxlan_eth_src,
13260                 (void *)&cmd_set_vxlan_eth_src_value,
13261                 (void *)&cmd_set_vxlan_eth_dst,
13262                 (void *)&cmd_set_vxlan_eth_dst_value,
13263                 NULL,
13264         },
13265 };
13266
13267 /** Set NVGRE encapsulation details */
13268 struct cmd_set_nvgre_result {
13269         cmdline_fixed_string_t set;
13270         cmdline_fixed_string_t nvgre;
13271         cmdline_fixed_string_t pos_token;
13272         cmdline_fixed_string_t ip_version;
13273         uint32_t tni;
13274         cmdline_ipaddr_t ip_src;
13275         cmdline_ipaddr_t ip_dst;
13276         uint16_t tci;
13277         struct rte_ether_addr eth_src;
13278         struct rte_ether_addr eth_dst;
13279 };
13280
13281 cmdline_parse_token_string_t cmd_set_nvgre_set =
13282         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13283 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13284         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13285 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13286         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13287                                  "nvgre-with-vlan");
13288 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13289         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13290                                  "ip-version");
13291 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13292         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13293                                  "ipv4#ipv6");
13294 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13295         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13296                                  "tni");
13297 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13298         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
13299 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13300         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13301                                  "ip-src");
13302 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13303         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13304 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13305         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13306                                  "ip-dst");
13307 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13308         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13309 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13310         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13311                                  "vlan-tci");
13312 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13313         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
13314 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13315         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13316                                  "eth-src");
13317 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13318         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13319 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13320         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13321                                  "eth-dst");
13322 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13323         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13324
13325 static void cmd_set_nvgre_parsed(void *parsed_result,
13326         __rte_unused struct cmdline *cl,
13327         __rte_unused void *data)
13328 {
13329         struct cmd_set_nvgre_result *res = parsed_result;
13330         union {
13331                 uint32_t nvgre_tni;
13332                 uint8_t tni[4];
13333         } id = {
13334                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13335         };
13336
13337         if (strcmp(res->nvgre, "nvgre") == 0)
13338                 nvgre_encap_conf.select_vlan = 0;
13339         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13340                 nvgre_encap_conf.select_vlan = 1;
13341         if (strcmp(res->ip_version, "ipv4") == 0)
13342                 nvgre_encap_conf.select_ipv4 = 1;
13343         else if (strcmp(res->ip_version, "ipv6") == 0)
13344                 nvgre_encap_conf.select_ipv4 = 0;
13345         else
13346                 return;
13347         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13348         if (nvgre_encap_conf.select_ipv4) {
13349                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13350                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13351         } else {
13352                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13353                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13354         }
13355         if (nvgre_encap_conf.select_vlan)
13356                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13357         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13358                    RTE_ETHER_ADDR_LEN);
13359         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13360                    RTE_ETHER_ADDR_LEN);
13361 }
13362
13363 cmdline_parse_inst_t cmd_set_nvgre = {
13364         .f = cmd_set_nvgre_parsed,
13365         .data = NULL,
13366         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13367                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13368                 " eth-dst <eth-dst>",
13369         .tokens = {
13370                 (void *)&cmd_set_nvgre_set,
13371                 (void *)&cmd_set_nvgre_nvgre,
13372                 (void *)&cmd_set_nvgre_ip_version,
13373                 (void *)&cmd_set_nvgre_ip_version_value,
13374                 (void *)&cmd_set_nvgre_tni,
13375                 (void *)&cmd_set_nvgre_tni_value,
13376                 (void *)&cmd_set_nvgre_ip_src,
13377                 (void *)&cmd_set_nvgre_ip_src_value,
13378                 (void *)&cmd_set_nvgre_ip_dst,
13379                 (void *)&cmd_set_nvgre_ip_dst_value,
13380                 (void *)&cmd_set_nvgre_eth_src,
13381                 (void *)&cmd_set_nvgre_eth_src_value,
13382                 (void *)&cmd_set_nvgre_eth_dst,
13383                 (void *)&cmd_set_nvgre_eth_dst_value,
13384                 NULL,
13385         },
13386 };
13387
13388 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13389         .f = cmd_set_nvgre_parsed,
13390         .data = NULL,
13391         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13392                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13393                 " eth-src <eth-src> eth-dst <eth-dst>",
13394         .tokens = {
13395                 (void *)&cmd_set_nvgre_set,
13396                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13397                 (void *)&cmd_set_nvgre_ip_version,
13398                 (void *)&cmd_set_nvgre_ip_version_value,
13399                 (void *)&cmd_set_nvgre_tni,
13400                 (void *)&cmd_set_nvgre_tni_value,
13401                 (void *)&cmd_set_nvgre_ip_src,
13402                 (void *)&cmd_set_nvgre_ip_src_value,
13403                 (void *)&cmd_set_nvgre_ip_dst,
13404                 (void *)&cmd_set_nvgre_ip_dst_value,
13405                 (void *)&cmd_set_nvgre_vlan,
13406                 (void *)&cmd_set_nvgre_vlan_value,
13407                 (void *)&cmd_set_nvgre_eth_src,
13408                 (void *)&cmd_set_nvgre_eth_src_value,
13409                 (void *)&cmd_set_nvgre_eth_dst,
13410                 (void *)&cmd_set_nvgre_eth_dst_value,
13411                 NULL,
13412         },
13413 };
13414
13415 /** Set L2 encapsulation details */
13416 struct cmd_set_l2_encap_result {
13417         cmdline_fixed_string_t set;
13418         cmdline_fixed_string_t l2_encap;
13419         cmdline_fixed_string_t pos_token;
13420         cmdline_fixed_string_t ip_version;
13421         uint32_t vlan_present:1;
13422         uint16_t tci;
13423         struct rte_ether_addr eth_src;
13424         struct rte_ether_addr eth_dst;
13425 };
13426
13427 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13428         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13429 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13430         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13431 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13432         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13433                                  "l2_encap-with-vlan");
13434 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13435         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13436                                  "ip-version");
13437 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13438         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13439                                  "ipv4#ipv6");
13440 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13441         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13442                                  "vlan-tci");
13443 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13444         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
13445 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13446         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13447                                  "eth-src");
13448 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13449         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13450 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13451         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13452                                  "eth-dst");
13453 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13454         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13455
13456 static void cmd_set_l2_encap_parsed(void *parsed_result,
13457         __rte_unused struct cmdline *cl,
13458         __rte_unused void *data)
13459 {
13460         struct cmd_set_l2_encap_result *res = parsed_result;
13461
13462         if (strcmp(res->l2_encap, "l2_encap") == 0)
13463                 l2_encap_conf.select_vlan = 0;
13464         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13465                 l2_encap_conf.select_vlan = 1;
13466         if (strcmp(res->ip_version, "ipv4") == 0)
13467                 l2_encap_conf.select_ipv4 = 1;
13468         else if (strcmp(res->ip_version, "ipv6") == 0)
13469                 l2_encap_conf.select_ipv4 = 0;
13470         else
13471                 return;
13472         if (l2_encap_conf.select_vlan)
13473                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13474         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13475                    RTE_ETHER_ADDR_LEN);
13476         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13477                    RTE_ETHER_ADDR_LEN);
13478 }
13479
13480 cmdline_parse_inst_t cmd_set_l2_encap = {
13481         .f = cmd_set_l2_encap_parsed,
13482         .data = NULL,
13483         .help_str = "set l2_encap ip-version ipv4|ipv6"
13484                 " eth-src <eth-src> eth-dst <eth-dst>",
13485         .tokens = {
13486                 (void *)&cmd_set_l2_encap_set,
13487                 (void *)&cmd_set_l2_encap_l2_encap,
13488                 (void *)&cmd_set_l2_encap_ip_version,
13489                 (void *)&cmd_set_l2_encap_ip_version_value,
13490                 (void *)&cmd_set_l2_encap_eth_src,
13491                 (void *)&cmd_set_l2_encap_eth_src_value,
13492                 (void *)&cmd_set_l2_encap_eth_dst,
13493                 (void *)&cmd_set_l2_encap_eth_dst_value,
13494                 NULL,
13495         },
13496 };
13497
13498 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13499         .f = cmd_set_l2_encap_parsed,
13500         .data = NULL,
13501         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13502                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13503         .tokens = {
13504                 (void *)&cmd_set_l2_encap_set,
13505                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13506                 (void *)&cmd_set_l2_encap_ip_version,
13507                 (void *)&cmd_set_l2_encap_ip_version_value,
13508                 (void *)&cmd_set_l2_encap_vlan,
13509                 (void *)&cmd_set_l2_encap_vlan_value,
13510                 (void *)&cmd_set_l2_encap_eth_src,
13511                 (void *)&cmd_set_l2_encap_eth_src_value,
13512                 (void *)&cmd_set_l2_encap_eth_dst,
13513                 (void *)&cmd_set_l2_encap_eth_dst_value,
13514                 NULL,
13515         },
13516 };
13517
13518 /** Set L2 decapsulation details */
13519 struct cmd_set_l2_decap_result {
13520         cmdline_fixed_string_t set;
13521         cmdline_fixed_string_t l2_decap;
13522         cmdline_fixed_string_t pos_token;
13523         uint32_t vlan_present:1;
13524 };
13525
13526 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13527         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13528 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13529         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13530                                  "l2_decap");
13531 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13532         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13533                                  "l2_decap-with-vlan");
13534
13535 static void cmd_set_l2_decap_parsed(void *parsed_result,
13536         __rte_unused struct cmdline *cl,
13537         __rte_unused void *data)
13538 {
13539         struct cmd_set_l2_decap_result *res = parsed_result;
13540
13541         if (strcmp(res->l2_decap, "l2_decap") == 0)
13542                 l2_decap_conf.select_vlan = 0;
13543         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13544                 l2_decap_conf.select_vlan = 1;
13545 }
13546
13547 cmdline_parse_inst_t cmd_set_l2_decap = {
13548         .f = cmd_set_l2_decap_parsed,
13549         .data = NULL,
13550         .help_str = "set l2_decap",
13551         .tokens = {
13552                 (void *)&cmd_set_l2_decap_set,
13553                 (void *)&cmd_set_l2_decap_l2_decap,
13554                 NULL,
13555         },
13556 };
13557
13558 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13559         .f = cmd_set_l2_decap_parsed,
13560         .data = NULL,
13561         .help_str = "set l2_decap-with-vlan",
13562         .tokens = {
13563                 (void *)&cmd_set_l2_decap_set,
13564                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13565                 NULL,
13566         },
13567 };
13568
13569 /** Set MPLSoGRE encapsulation details */
13570 struct cmd_set_mplsogre_encap_result {
13571         cmdline_fixed_string_t set;
13572         cmdline_fixed_string_t mplsogre;
13573         cmdline_fixed_string_t pos_token;
13574         cmdline_fixed_string_t ip_version;
13575         uint32_t vlan_present:1;
13576         uint32_t label;
13577         cmdline_ipaddr_t ip_src;
13578         cmdline_ipaddr_t ip_dst;
13579         uint16_t tci;
13580         struct rte_ether_addr eth_src;
13581         struct rte_ether_addr eth_dst;
13582 };
13583
13584 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13585         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13586                                  "set");
13587 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13588         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13589                                  "mplsogre_encap");
13590 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13591         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13592                                  mplsogre, "mplsogre_encap-with-vlan");
13593 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13594         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13595                                  pos_token, "ip-version");
13596 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13597         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13598                                  ip_version, "ipv4#ipv6");
13599 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13600         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13601                                  pos_token, "label");
13602 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13603         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13604                               UINT32);
13605 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13606         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13607                                  pos_token, "ip-src");
13608 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13609         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13610 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13611         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13612                                  pos_token, "ip-dst");
13613 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13614         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13615 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13616         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13617                                  pos_token, "vlan-tci");
13618 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13619         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13620                               UINT16);
13621 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13622         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13623                                  pos_token, "eth-src");
13624 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13625         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13626                                     eth_src);
13627 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13628         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13629                                  pos_token, "eth-dst");
13630 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13631         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13632                                     eth_dst);
13633
13634 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13635         __rte_unused struct cmdline *cl,
13636         __rte_unused void *data)
13637 {
13638         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13639         union {
13640                 uint32_t mplsogre_label;
13641                 uint8_t label[4];
13642         } id = {
13643                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13644         };
13645
13646         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13647                 mplsogre_encap_conf.select_vlan = 0;
13648         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13649                 mplsogre_encap_conf.select_vlan = 1;
13650         if (strcmp(res->ip_version, "ipv4") == 0)
13651                 mplsogre_encap_conf.select_ipv4 = 1;
13652         else if (strcmp(res->ip_version, "ipv6") == 0)
13653                 mplsogre_encap_conf.select_ipv4 = 0;
13654         else
13655                 return;
13656         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13657         if (mplsogre_encap_conf.select_ipv4) {
13658                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13659                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13660         } else {
13661                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13662                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13663         }
13664         if (mplsogre_encap_conf.select_vlan)
13665                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13666         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13667                    RTE_ETHER_ADDR_LEN);
13668         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13669                    RTE_ETHER_ADDR_LEN);
13670 }
13671
13672 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13673         .f = cmd_set_mplsogre_encap_parsed,
13674         .data = NULL,
13675         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13676                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13677                 " eth-dst <eth-dst>",
13678         .tokens = {
13679                 (void *)&cmd_set_mplsogre_encap_set,
13680                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13681                 (void *)&cmd_set_mplsogre_encap_ip_version,
13682                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13683                 (void *)&cmd_set_mplsogre_encap_label,
13684                 (void *)&cmd_set_mplsogre_encap_label_value,
13685                 (void *)&cmd_set_mplsogre_encap_ip_src,
13686                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13687                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13688                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13689                 (void *)&cmd_set_mplsogre_encap_eth_src,
13690                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13691                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13692                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13693                 NULL,
13694         },
13695 };
13696
13697 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13698         .f = cmd_set_mplsogre_encap_parsed,
13699         .data = NULL,
13700         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13701                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13702                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13703         .tokens = {
13704                 (void *)&cmd_set_mplsogre_encap_set,
13705                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13706                 (void *)&cmd_set_mplsogre_encap_ip_version,
13707                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13708                 (void *)&cmd_set_mplsogre_encap_label,
13709                 (void *)&cmd_set_mplsogre_encap_label_value,
13710                 (void *)&cmd_set_mplsogre_encap_ip_src,
13711                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13712                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13713                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13714                 (void *)&cmd_set_mplsogre_encap_vlan,
13715                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13716                 (void *)&cmd_set_mplsogre_encap_eth_src,
13717                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13718                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13719                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13720                 NULL,
13721         },
13722 };
13723
13724 /** Set MPLSoGRE decapsulation details */
13725 struct cmd_set_mplsogre_decap_result {
13726         cmdline_fixed_string_t set;
13727         cmdline_fixed_string_t mplsogre;
13728         cmdline_fixed_string_t pos_token;
13729         cmdline_fixed_string_t ip_version;
13730         uint32_t vlan_present:1;
13731 };
13732
13733 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13734         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13735                                  "set");
13736 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13738                                  "mplsogre_decap");
13739 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13740         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13741                                  mplsogre, "mplsogre_decap-with-vlan");
13742 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13743         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13744                                  pos_token, "ip-version");
13745 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13746         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13747                                  ip_version, "ipv4#ipv6");
13748
13749 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13750         __rte_unused struct cmdline *cl,
13751         __rte_unused void *data)
13752 {
13753         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13754
13755         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13756                 mplsogre_decap_conf.select_vlan = 0;
13757         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13758                 mplsogre_decap_conf.select_vlan = 1;
13759         if (strcmp(res->ip_version, "ipv4") == 0)
13760                 mplsogre_decap_conf.select_ipv4 = 1;
13761         else if (strcmp(res->ip_version, "ipv6") == 0)
13762                 mplsogre_decap_conf.select_ipv4 = 0;
13763 }
13764
13765 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13766         .f = cmd_set_mplsogre_decap_parsed,
13767         .data = NULL,
13768         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13769         .tokens = {
13770                 (void *)&cmd_set_mplsogre_decap_set,
13771                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13772                 (void *)&cmd_set_mplsogre_decap_ip_version,
13773                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13774                 NULL,
13775         },
13776 };
13777
13778 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13779         .f = cmd_set_mplsogre_decap_parsed,
13780         .data = NULL,
13781         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13782         .tokens = {
13783                 (void *)&cmd_set_mplsogre_decap_set,
13784                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13785                 (void *)&cmd_set_mplsogre_decap_ip_version,
13786                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13787                 NULL,
13788         },
13789 };
13790
13791 /** Set MPLSoUDP encapsulation details */
13792 struct cmd_set_mplsoudp_encap_result {
13793         cmdline_fixed_string_t set;
13794         cmdline_fixed_string_t mplsoudp;
13795         cmdline_fixed_string_t pos_token;
13796         cmdline_fixed_string_t ip_version;
13797         uint32_t vlan_present:1;
13798         uint32_t label;
13799         uint16_t udp_src;
13800         uint16_t udp_dst;
13801         cmdline_ipaddr_t ip_src;
13802         cmdline_ipaddr_t ip_dst;
13803         uint16_t tci;
13804         struct rte_ether_addr eth_src;
13805         struct rte_ether_addr eth_dst;
13806 };
13807
13808 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13809         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13810                                  "set");
13811 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13812         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13813                                  "mplsoudp_encap");
13814 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13815         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13816                                  mplsoudp, "mplsoudp_encap-with-vlan");
13817 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13818         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13819                                  pos_token, "ip-version");
13820 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13821         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13822                                  ip_version, "ipv4#ipv6");
13823 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13824         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13825                                  pos_token, "label");
13826 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13827         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13828                               UINT32);
13829 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13830         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13831                                  pos_token, "udp-src");
13832 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13833         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13834                               UINT16);
13835 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13836         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13837                                  pos_token, "udp-dst");
13838 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13839         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13840                               UINT16);
13841 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13842         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13843                                  pos_token, "ip-src");
13844 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13845         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13846 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13847         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13848                                  pos_token, "ip-dst");
13849 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13850         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13851 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13852         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13853                                  pos_token, "vlan-tci");
13854 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13855         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13856                               UINT16);
13857 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13858         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13859                                  pos_token, "eth-src");
13860 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13861         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13862                                     eth_src);
13863 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13864         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13865                                  pos_token, "eth-dst");
13866 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13867         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13868                                     eth_dst);
13869
13870 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13871         __rte_unused struct cmdline *cl,
13872         __rte_unused void *data)
13873 {
13874         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13875         union {
13876                 uint32_t mplsoudp_label;
13877                 uint8_t label[4];
13878         } id = {
13879                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13880         };
13881
13882         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13883                 mplsoudp_encap_conf.select_vlan = 0;
13884         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13885                 mplsoudp_encap_conf.select_vlan = 1;
13886         if (strcmp(res->ip_version, "ipv4") == 0)
13887                 mplsoudp_encap_conf.select_ipv4 = 1;
13888         else if (strcmp(res->ip_version, "ipv6") == 0)
13889                 mplsoudp_encap_conf.select_ipv4 = 0;
13890         else
13891                 return;
13892         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13893         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13894         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13895         if (mplsoudp_encap_conf.select_ipv4) {
13896                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13897                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13898         } else {
13899                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13900                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13901         }
13902         if (mplsoudp_encap_conf.select_vlan)
13903                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13904         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13905                    RTE_ETHER_ADDR_LEN);
13906         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13907                    RTE_ETHER_ADDR_LEN);
13908 }
13909
13910 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13911         .f = cmd_set_mplsoudp_encap_parsed,
13912         .data = NULL,
13913         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13914                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13915                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13916         .tokens = {
13917                 (void *)&cmd_set_mplsoudp_encap_set,
13918                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13919                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13920                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13921                 (void *)&cmd_set_mplsoudp_encap_label,
13922                 (void *)&cmd_set_mplsoudp_encap_label_value,
13923                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13924                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13925                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13926                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13927                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13928                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13929                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13930                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13931                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13932                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13933                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13934                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13935                 NULL,
13936         },
13937 };
13938
13939 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13940         .f = cmd_set_mplsoudp_encap_parsed,
13941         .data = NULL,
13942         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13943                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13944                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13945                 " eth-src <eth-src> eth-dst <eth-dst>",
13946         .tokens = {
13947                 (void *)&cmd_set_mplsoudp_encap_set,
13948                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13949                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13950                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13951                 (void *)&cmd_set_mplsoudp_encap_label,
13952                 (void *)&cmd_set_mplsoudp_encap_label_value,
13953                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13954                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13955                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13956                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13957                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13958                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13959                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13960                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13961                 (void *)&cmd_set_mplsoudp_encap_vlan,
13962                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13963                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13964                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13965                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13966                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13967                 NULL,
13968         },
13969 };
13970
13971 /** Set MPLSoUDP decapsulation details */
13972 struct cmd_set_mplsoudp_decap_result {
13973         cmdline_fixed_string_t set;
13974         cmdline_fixed_string_t mplsoudp;
13975         cmdline_fixed_string_t pos_token;
13976         cmdline_fixed_string_t ip_version;
13977         uint32_t vlan_present:1;
13978 };
13979
13980 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13981         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13982                                  "set");
13983 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13985                                  "mplsoudp_decap");
13986 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13987         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13988                                  mplsoudp, "mplsoudp_decap-with-vlan");
13989 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13990         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13991                                  pos_token, "ip-version");
13992 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13993         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13994                                  ip_version, "ipv4#ipv6");
13995
13996 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13997         __rte_unused struct cmdline *cl,
13998         __rte_unused void *data)
13999 {
14000         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14001
14002         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14003                 mplsoudp_decap_conf.select_vlan = 0;
14004         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14005                 mplsoudp_decap_conf.select_vlan = 1;
14006         if (strcmp(res->ip_version, "ipv4") == 0)
14007                 mplsoudp_decap_conf.select_ipv4 = 1;
14008         else if (strcmp(res->ip_version, "ipv6") == 0)
14009                 mplsoudp_decap_conf.select_ipv4 = 0;
14010 }
14011
14012 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14013         .f = cmd_set_mplsoudp_decap_parsed,
14014         .data = NULL,
14015         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14016         .tokens = {
14017                 (void *)&cmd_set_mplsoudp_decap_set,
14018                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14019                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14020                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14021                 NULL,
14022         },
14023 };
14024
14025 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14026         .f = cmd_set_mplsoudp_decap_parsed,
14027         .data = NULL,
14028         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14029         .tokens = {
14030                 (void *)&cmd_set_mplsoudp_decap_set,
14031                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14032                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14033                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14034                 NULL,
14035         },
14036 };
14037
14038 /* Strict link priority scheduling mode setting */
14039 static void
14040 cmd_strict_link_prio_parsed(
14041         void *parsed_result,
14042         __rte_unused struct cmdline *cl,
14043         __rte_unused void *data)
14044 {
14045         struct cmd_vf_tc_bw_result *res = parsed_result;
14046         int ret = -ENOTSUP;
14047
14048         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14049                 return;
14050
14051 #ifdef RTE_NET_I40E
14052         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14053 #endif
14054
14055         switch (ret) {
14056         case 0:
14057                 break;
14058         case -EINVAL:
14059                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14060                 break;
14061         case -ENODEV:
14062                 printf("invalid port_id %d\n", res->port_id);
14063                 break;
14064         case -ENOTSUP:
14065                 printf("function not implemented\n");
14066                 break;
14067         default:
14068                 printf("programming error: (%s)\n", strerror(-ret));
14069         }
14070 }
14071
14072 cmdline_parse_inst_t cmd_strict_link_prio = {
14073         .f = cmd_strict_link_prio_parsed,
14074         .data = NULL,
14075         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14076         .tokens = {
14077                 (void *)&cmd_vf_tc_bw_set,
14078                 (void *)&cmd_vf_tc_bw_tx,
14079                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14080                 (void *)&cmd_vf_tc_bw_port_id,
14081                 (void *)&cmd_vf_tc_bw_tc_map,
14082                 NULL,
14083         },
14084 };
14085
14086 /* Load dynamic device personalization*/
14087 struct cmd_ddp_add_result {
14088         cmdline_fixed_string_t ddp;
14089         cmdline_fixed_string_t add;
14090         portid_t port_id;
14091         char filepath[];
14092 };
14093
14094 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14095         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14096 cmdline_parse_token_string_t cmd_ddp_add_add =
14097         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14098 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14099         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14100 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14101         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14102
14103 static void
14104 cmd_ddp_add_parsed(
14105         void *parsed_result,
14106         __rte_unused struct cmdline *cl,
14107         __rte_unused void *data)
14108 {
14109         struct cmd_ddp_add_result *res = parsed_result;
14110         uint8_t *buff;
14111         uint32_t size;
14112         char *filepath;
14113         char *file_fld[2];
14114         int file_num;
14115         int ret = -ENOTSUP;
14116
14117         if (!all_ports_stopped()) {
14118                 printf("Please stop all ports first\n");
14119                 return;
14120         }
14121
14122         filepath = strdup(res->filepath);
14123         if (filepath == NULL) {
14124                 printf("Failed to allocate memory\n");
14125                 return;
14126         }
14127         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14128
14129         buff = open_file(file_fld[0], &size);
14130         if (!buff) {
14131                 free((void *)filepath);
14132                 return;
14133         }
14134
14135 #ifdef RTE_NET_I40E
14136         if (ret == -ENOTSUP)
14137                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14138                                                buff, size,
14139                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14140 #endif
14141
14142         if (ret == -EEXIST)
14143                 printf("Profile has already existed.\n");
14144         else if (ret < 0)
14145                 printf("Failed to load profile.\n");
14146         else if (file_num == 2)
14147                 save_file(file_fld[1], buff, size);
14148
14149         close_file(buff);
14150         free((void *)filepath);
14151 }
14152
14153 cmdline_parse_inst_t cmd_ddp_add = {
14154         .f = cmd_ddp_add_parsed,
14155         .data = NULL,
14156         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14157         .tokens = {
14158                 (void *)&cmd_ddp_add_ddp,
14159                 (void *)&cmd_ddp_add_add,
14160                 (void *)&cmd_ddp_add_port_id,
14161                 (void *)&cmd_ddp_add_filepath,
14162                 NULL,
14163         },
14164 };
14165
14166 /* Delete dynamic device personalization*/
14167 struct cmd_ddp_del_result {
14168         cmdline_fixed_string_t ddp;
14169         cmdline_fixed_string_t del;
14170         portid_t port_id;
14171         char filepath[];
14172 };
14173
14174 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14175         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14176 cmdline_parse_token_string_t cmd_ddp_del_del =
14177         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14178 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14179         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14180 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14181         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14182
14183 static void
14184 cmd_ddp_del_parsed(
14185         void *parsed_result,
14186         __rte_unused struct cmdline *cl,
14187         __rte_unused void *data)
14188 {
14189         struct cmd_ddp_del_result *res = parsed_result;
14190         uint8_t *buff;
14191         uint32_t size;
14192         int ret = -ENOTSUP;
14193
14194         if (!all_ports_stopped()) {
14195                 printf("Please stop all ports first\n");
14196                 return;
14197         }
14198
14199         buff = open_file(res->filepath, &size);
14200         if (!buff)
14201                 return;
14202
14203 #ifdef RTE_NET_I40E
14204         if (ret == -ENOTSUP)
14205                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14206                                                buff, size,
14207                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14208 #endif
14209
14210         if (ret == -EACCES)
14211                 printf("Profile does not exist.\n");
14212         else if (ret < 0)
14213                 printf("Failed to delete profile.\n");
14214
14215         close_file(buff);
14216 }
14217
14218 cmdline_parse_inst_t cmd_ddp_del = {
14219         .f = cmd_ddp_del_parsed,
14220         .data = NULL,
14221         .help_str = "ddp del <port_id> <backup_profile_path>",
14222         .tokens = {
14223                 (void *)&cmd_ddp_del_ddp,
14224                 (void *)&cmd_ddp_del_del,
14225                 (void *)&cmd_ddp_del_port_id,
14226                 (void *)&cmd_ddp_del_filepath,
14227                 NULL,
14228         },
14229 };
14230
14231 /* Get dynamic device personalization profile info */
14232 struct cmd_ddp_info_result {
14233         cmdline_fixed_string_t ddp;
14234         cmdline_fixed_string_t get;
14235         cmdline_fixed_string_t info;
14236         char filepath[];
14237 };
14238
14239 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14240         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14241 cmdline_parse_token_string_t cmd_ddp_info_get =
14242         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14243 cmdline_parse_token_string_t cmd_ddp_info_info =
14244         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14245 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14246         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14247
14248 static void
14249 cmd_ddp_info_parsed(
14250         void *parsed_result,
14251         __rte_unused struct cmdline *cl,
14252         __rte_unused void *data)
14253 {
14254         struct cmd_ddp_info_result *res = parsed_result;
14255         uint8_t *pkg;
14256         uint32_t pkg_size;
14257         int ret = -ENOTSUP;
14258 #ifdef RTE_NET_I40E
14259         uint32_t i, j, n;
14260         uint8_t *buff;
14261         uint32_t buff_size = 0;
14262         struct rte_pmd_i40e_profile_info info;
14263         uint32_t dev_num = 0;
14264         struct rte_pmd_i40e_ddp_device_id *devs;
14265         uint32_t proto_num = 0;
14266         struct rte_pmd_i40e_proto_info *proto = NULL;
14267         uint32_t pctype_num = 0;
14268         struct rte_pmd_i40e_ptype_info *pctype;
14269         uint32_t ptype_num = 0;
14270         struct rte_pmd_i40e_ptype_info *ptype;
14271         uint8_t proto_id;
14272
14273 #endif
14274
14275         pkg = open_file(res->filepath, &pkg_size);
14276         if (!pkg)
14277                 return;
14278
14279 #ifdef RTE_NET_I40E
14280         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14281                                 (uint8_t *)&info, sizeof(info),
14282                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14283         if (!ret) {
14284                 printf("Global Track id:       0x%x\n", info.track_id);
14285                 printf("Global Version:        %d.%d.%d.%d\n",
14286                         info.version.major,
14287                         info.version.minor,
14288                         info.version.update,
14289                         info.version.draft);
14290                 printf("Global Package name:   %s\n\n", info.name);
14291         }
14292
14293         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14294                                 (uint8_t *)&info, sizeof(info),
14295                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14296         if (!ret) {
14297                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14298                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14299                         info.version.major,
14300                         info.version.minor,
14301                         info.version.update,
14302                         info.version.draft);
14303                 printf("i40e Profile name:     %s\n\n", info.name);
14304         }
14305
14306         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14307                                 (uint8_t *)&buff_size, sizeof(buff_size),
14308                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14309         if (!ret && buff_size) {
14310                 buff = (uint8_t *)malloc(buff_size);
14311                 if (buff) {
14312                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14313                                                 buff, buff_size,
14314                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14315                         if (!ret)
14316                                 printf("Package Notes:\n%s\n\n", buff);
14317                         free(buff);
14318                 }
14319         }
14320
14321         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14322                                 (uint8_t *)&dev_num, sizeof(dev_num),
14323                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14324         if (!ret && dev_num) {
14325                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14326                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14327                 if (devs) {
14328                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14329                                                 (uint8_t *)devs, buff_size,
14330                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14331                         if (!ret) {
14332                                 printf("List of supported devices:\n");
14333                                 for (i = 0; i < dev_num; i++) {
14334                                         printf("  %04X:%04X %04X:%04X\n",
14335                                                 devs[i].vendor_dev_id >> 16,
14336                                                 devs[i].vendor_dev_id & 0xFFFF,
14337                                                 devs[i].sub_vendor_dev_id >> 16,
14338                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14339                                 }
14340                                 printf("\n");
14341                         }
14342                         free(devs);
14343                 }
14344         }
14345
14346         /* get information about protocols and packet types */
14347         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14348                 (uint8_t *)&proto_num, sizeof(proto_num),
14349                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14350         if (ret || !proto_num)
14351                 goto no_print_return;
14352
14353         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14354         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14355         if (!proto)
14356                 goto no_print_return;
14357
14358         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14359                                         buff_size,
14360                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14361         if (!ret) {
14362                 printf("List of used protocols:\n");
14363                 for (i = 0; i < proto_num; i++)
14364                         printf("  %2u: %s\n", proto[i].proto_id,
14365                                proto[i].name);
14366                 printf("\n");
14367         }
14368         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14369                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14370                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14371         if (ret || !pctype_num)
14372                 goto no_print_pctypes;
14373
14374         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14375         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14376         if (!pctype)
14377                 goto no_print_pctypes;
14378
14379         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14380                                         buff_size,
14381                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14382         if (ret) {
14383                 free(pctype);
14384                 goto no_print_pctypes;
14385         }
14386
14387         printf("List of defined packet classification types:\n");
14388         for (i = 0; i < pctype_num; i++) {
14389                 printf("  %2u:", pctype[i].ptype_id);
14390                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14391                         proto_id = pctype[i].protocols[j];
14392                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14393                                 for (n = 0; n < proto_num; n++) {
14394                                         if (proto[n].proto_id == proto_id) {
14395                                                 printf(" %s", proto[n].name);
14396                                                 break;
14397                                         }
14398                                 }
14399                         }
14400                 }
14401                 printf("\n");
14402         }
14403         printf("\n");
14404         free(pctype);
14405
14406 no_print_pctypes:
14407
14408         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14409                                         sizeof(ptype_num),
14410                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14411         if (ret || !ptype_num)
14412                 goto no_print_return;
14413
14414         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14415         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14416         if (!ptype)
14417                 goto no_print_return;
14418
14419         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14420                                         buff_size,
14421                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14422         if (ret) {
14423                 free(ptype);
14424                 goto no_print_return;
14425         }
14426         printf("List of defined packet types:\n");
14427         for (i = 0; i < ptype_num; i++) {
14428                 printf("  %2u:", ptype[i].ptype_id);
14429                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14430                         proto_id = ptype[i].protocols[j];
14431                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14432                                 for (n = 0; n < proto_num; n++) {
14433                                         if (proto[n].proto_id == proto_id) {
14434                                                 printf(" %s", proto[n].name);
14435                                                 break;
14436                                         }
14437                                 }
14438                         }
14439                 }
14440                 printf("\n");
14441         }
14442         free(ptype);
14443         printf("\n");
14444
14445         ret = 0;
14446 no_print_return:
14447         if (proto)
14448                 free(proto);
14449 #endif
14450         if (ret == -ENOTSUP)
14451                 printf("Function not supported in PMD driver\n");
14452         close_file(pkg);
14453 }
14454
14455 cmdline_parse_inst_t cmd_ddp_get_info = {
14456         .f = cmd_ddp_info_parsed,
14457         .data = NULL,
14458         .help_str = "ddp get info <profile_path>",
14459         .tokens = {
14460                 (void *)&cmd_ddp_info_ddp,
14461                 (void *)&cmd_ddp_info_get,
14462                 (void *)&cmd_ddp_info_info,
14463                 (void *)&cmd_ddp_info_filepath,
14464                 NULL,
14465         },
14466 };
14467
14468 /* Get dynamic device personalization profile info list*/
14469 #define PROFILE_INFO_SIZE 48
14470 #define MAX_PROFILE_NUM 16
14471
14472 struct cmd_ddp_get_list_result {
14473         cmdline_fixed_string_t ddp;
14474         cmdline_fixed_string_t get;
14475         cmdline_fixed_string_t list;
14476         portid_t port_id;
14477 };
14478
14479 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14480         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14481 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14482         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14483 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14484         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14485 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14486         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14487
14488 static void
14489 cmd_ddp_get_list_parsed(
14490         __rte_unused void *parsed_result,
14491         __rte_unused struct cmdline *cl,
14492         __rte_unused void *data)
14493 {
14494 #ifdef RTE_NET_I40E
14495         struct cmd_ddp_get_list_result *res = parsed_result;
14496         struct rte_pmd_i40e_profile_list *p_list;
14497         struct rte_pmd_i40e_profile_info *p_info;
14498         uint32_t p_num;
14499         uint32_t size;
14500         uint32_t i;
14501 #endif
14502         int ret = -ENOTSUP;
14503
14504 #ifdef RTE_NET_I40E
14505         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14506         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14507         if (!p_list) {
14508                 printf("%s: Failed to malloc buffer\n", __func__);
14509                 return;
14510         }
14511
14512         if (ret == -ENOTSUP)
14513                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14514                                                 (uint8_t *)p_list, size);
14515
14516         if (!ret) {
14517                 p_num = p_list->p_count;
14518                 printf("Profile number is: %d\n\n", p_num);
14519
14520                 for (i = 0; i < p_num; i++) {
14521                         p_info = &p_list->p_info[i];
14522                         printf("Profile %d:\n", i);
14523                         printf("Track id:     0x%x\n", p_info->track_id);
14524                         printf("Version:      %d.%d.%d.%d\n",
14525                                p_info->version.major,
14526                                p_info->version.minor,
14527                                p_info->version.update,
14528                                p_info->version.draft);
14529                         printf("Profile name: %s\n\n", p_info->name);
14530                 }
14531         }
14532
14533         free(p_list);
14534 #endif
14535
14536         if (ret < 0)
14537                 printf("Failed to get ddp list\n");
14538 }
14539
14540 cmdline_parse_inst_t cmd_ddp_get_list = {
14541         .f = cmd_ddp_get_list_parsed,
14542         .data = NULL,
14543         .help_str = "ddp get list <port_id>",
14544         .tokens = {
14545                 (void *)&cmd_ddp_get_list_ddp,
14546                 (void *)&cmd_ddp_get_list_get,
14547                 (void *)&cmd_ddp_get_list_list,
14548                 (void *)&cmd_ddp_get_list_port_id,
14549                 NULL,
14550         },
14551 };
14552
14553 /* Configure input set */
14554 struct cmd_cfg_input_set_result {
14555         cmdline_fixed_string_t port;
14556         cmdline_fixed_string_t cfg;
14557         portid_t port_id;
14558         cmdline_fixed_string_t pctype;
14559         uint8_t pctype_id;
14560         cmdline_fixed_string_t inset_type;
14561         cmdline_fixed_string_t opt;
14562         cmdline_fixed_string_t field;
14563         uint8_t field_idx;
14564 };
14565
14566 static void
14567 cmd_cfg_input_set_parsed(
14568         __rte_unused void *parsed_result,
14569         __rte_unused struct cmdline *cl,
14570         __rte_unused void *data)
14571 {
14572 #ifdef RTE_NET_I40E
14573         struct cmd_cfg_input_set_result *res = parsed_result;
14574         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14575         struct rte_pmd_i40e_inset inset;
14576 #endif
14577         int ret = -ENOTSUP;
14578
14579         if (!all_ports_stopped()) {
14580                 printf("Please stop all ports first\n");
14581                 return;
14582         }
14583
14584 #ifdef RTE_NET_I40E
14585         if (!strcmp(res->inset_type, "hash_inset"))
14586                 inset_type = INSET_HASH;
14587         else if (!strcmp(res->inset_type, "fdir_inset"))
14588                 inset_type = INSET_FDIR;
14589         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14590                 inset_type = INSET_FDIR_FLX;
14591         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14592                                      &inset, inset_type);
14593         if (ret) {
14594                 printf("Failed to get input set.\n");
14595                 return;
14596         }
14597
14598         if (!strcmp(res->opt, "get")) {
14599                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14600                                                    res->field_idx);
14601                 if (ret)
14602                         printf("Field index %d is enabled.\n", res->field_idx);
14603                 else
14604                         printf("Field index %d is disabled.\n", res->field_idx);
14605                 return;
14606         } else if (!strcmp(res->opt, "set"))
14607                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14608                                                    res->field_idx);
14609         else if (!strcmp(res->opt, "clear"))
14610                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14611                                                      res->field_idx);
14612         if (ret) {
14613                 printf("Failed to configure input set field.\n");
14614                 return;
14615         }
14616
14617         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14618                                      &inset, inset_type);
14619         if (ret) {
14620                 printf("Failed to set input set.\n");
14621                 return;
14622         }
14623 #endif
14624
14625         if (ret == -ENOTSUP)
14626                 printf("Function not supported\n");
14627 }
14628
14629 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14630         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14631                                  port, "port");
14632 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14633         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14634                                  cfg, "config");
14635 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14636         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14637                               port_id, UINT16);
14638 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14639         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14640                                  pctype, "pctype");
14641 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14642         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14643                               pctype_id, UINT8);
14644 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14645         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14646                                  inset_type,
14647                                  "hash_inset#fdir_inset#fdir_flx_inset");
14648 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14649         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14650                                  opt, "get#set#clear");
14651 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14652         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14653                                  field, "field");
14654 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14655         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14656                               field_idx, UINT8);
14657
14658 cmdline_parse_inst_t cmd_cfg_input_set = {
14659         .f = cmd_cfg_input_set_parsed,
14660         .data = NULL,
14661         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14662                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14663         .tokens = {
14664                 (void *)&cmd_cfg_input_set_port,
14665                 (void *)&cmd_cfg_input_set_cfg,
14666                 (void *)&cmd_cfg_input_set_port_id,
14667                 (void *)&cmd_cfg_input_set_pctype,
14668                 (void *)&cmd_cfg_input_set_pctype_id,
14669                 (void *)&cmd_cfg_input_set_inset_type,
14670                 (void *)&cmd_cfg_input_set_opt,
14671                 (void *)&cmd_cfg_input_set_field,
14672                 (void *)&cmd_cfg_input_set_field_idx,
14673                 NULL,
14674         },
14675 };
14676
14677 /* Clear input set */
14678 struct cmd_clear_input_set_result {
14679         cmdline_fixed_string_t port;
14680         cmdline_fixed_string_t cfg;
14681         portid_t port_id;
14682         cmdline_fixed_string_t pctype;
14683         uint8_t pctype_id;
14684         cmdline_fixed_string_t inset_type;
14685         cmdline_fixed_string_t clear;
14686         cmdline_fixed_string_t all;
14687 };
14688
14689 static void
14690 cmd_clear_input_set_parsed(
14691         __rte_unused void *parsed_result,
14692         __rte_unused struct cmdline *cl,
14693         __rte_unused void *data)
14694 {
14695 #ifdef RTE_NET_I40E
14696         struct cmd_clear_input_set_result *res = parsed_result;
14697         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14698         struct rte_pmd_i40e_inset inset;
14699 #endif
14700         int ret = -ENOTSUP;
14701
14702         if (!all_ports_stopped()) {
14703                 printf("Please stop all ports first\n");
14704                 return;
14705         }
14706
14707 #ifdef RTE_NET_I40E
14708         if (!strcmp(res->inset_type, "hash_inset"))
14709                 inset_type = INSET_HASH;
14710         else if (!strcmp(res->inset_type, "fdir_inset"))
14711                 inset_type = INSET_FDIR;
14712         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14713                 inset_type = INSET_FDIR_FLX;
14714
14715         memset(&inset, 0, sizeof(inset));
14716
14717         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14718                                      &inset, inset_type);
14719         if (ret) {
14720                 printf("Failed to clear input set.\n");
14721                 return;
14722         }
14723
14724 #endif
14725
14726         if (ret == -ENOTSUP)
14727                 printf("Function not supported\n");
14728 }
14729
14730 cmdline_parse_token_string_t cmd_clear_input_set_port =
14731         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14732                                  port, "port");
14733 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14734         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14735                                  cfg, "config");
14736 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14737         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14738                               port_id, UINT16);
14739 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14740         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14741                                  pctype, "pctype");
14742 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14743         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14744                               pctype_id, UINT8);
14745 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14746         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14747                                  inset_type,
14748                                  "hash_inset#fdir_inset#fdir_flx_inset");
14749 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14750         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14751                                  clear, "clear");
14752 cmdline_parse_token_string_t cmd_clear_input_set_all =
14753         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14754                                  all, "all");
14755
14756 cmdline_parse_inst_t cmd_clear_input_set = {
14757         .f = cmd_clear_input_set_parsed,
14758         .data = NULL,
14759         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14760                     "fdir_inset|fdir_flx_inset clear all",
14761         .tokens = {
14762                 (void *)&cmd_clear_input_set_port,
14763                 (void *)&cmd_clear_input_set_cfg,
14764                 (void *)&cmd_clear_input_set_port_id,
14765                 (void *)&cmd_clear_input_set_pctype,
14766                 (void *)&cmd_clear_input_set_pctype_id,
14767                 (void *)&cmd_clear_input_set_inset_type,
14768                 (void *)&cmd_clear_input_set_clear,
14769                 (void *)&cmd_clear_input_set_all,
14770                 NULL,
14771         },
14772 };
14773
14774 /* show vf stats */
14775
14776 /* Common result structure for show vf stats */
14777 struct cmd_show_vf_stats_result {
14778         cmdline_fixed_string_t show;
14779         cmdline_fixed_string_t vf;
14780         cmdline_fixed_string_t stats;
14781         portid_t port_id;
14782         uint16_t vf_id;
14783 };
14784
14785 /* Common CLI fields show vf stats*/
14786 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14787         TOKEN_STRING_INITIALIZER
14788                 (struct cmd_show_vf_stats_result,
14789                  show, "show");
14790 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14791         TOKEN_STRING_INITIALIZER
14792                 (struct cmd_show_vf_stats_result,
14793                  vf, "vf");
14794 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14795         TOKEN_STRING_INITIALIZER
14796                 (struct cmd_show_vf_stats_result,
14797                  stats, "stats");
14798 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14799         TOKEN_NUM_INITIALIZER
14800                 (struct cmd_show_vf_stats_result,
14801                  port_id, UINT16);
14802 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14803         TOKEN_NUM_INITIALIZER
14804                 (struct cmd_show_vf_stats_result,
14805                  vf_id, UINT16);
14806
14807 static void
14808 cmd_show_vf_stats_parsed(
14809         void *parsed_result,
14810         __rte_unused struct cmdline *cl,
14811         __rte_unused void *data)
14812 {
14813         struct cmd_show_vf_stats_result *res = parsed_result;
14814         struct rte_eth_stats stats;
14815         int ret = -ENOTSUP;
14816         static const char *nic_stats_border = "########################";
14817
14818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14819                 return;
14820
14821         memset(&stats, 0, sizeof(stats));
14822
14823 #ifdef RTE_NET_I40E
14824         if (ret == -ENOTSUP)
14825                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14826                                                 res->vf_id,
14827                                                 &stats);
14828 #endif
14829 #ifdef RTE_NET_BNXT
14830         if (ret == -ENOTSUP)
14831                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14832                                                 res->vf_id,
14833                                                 &stats);
14834 #endif
14835
14836         switch (ret) {
14837         case 0:
14838                 break;
14839         case -EINVAL:
14840                 printf("invalid vf_id %d\n", res->vf_id);
14841                 break;
14842         case -ENODEV:
14843                 printf("invalid port_id %d\n", res->port_id);
14844                 break;
14845         case -ENOTSUP:
14846                 printf("function not implemented\n");
14847                 break;
14848         default:
14849                 printf("programming error: (%s)\n", strerror(-ret));
14850         }
14851
14852         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14853                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14854
14855         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14856                "%-"PRIu64"\n",
14857                stats.ipackets, stats.imissed, stats.ibytes);
14858         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14859         printf("  RX-nombuf:  %-10"PRIu64"\n",
14860                stats.rx_nombuf);
14861         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14862                "%-"PRIu64"\n",
14863                stats.opackets, stats.oerrors, stats.obytes);
14864
14865         printf("  %s############################%s\n",
14866                                nic_stats_border, nic_stats_border);
14867 }
14868
14869 cmdline_parse_inst_t cmd_show_vf_stats = {
14870         .f = cmd_show_vf_stats_parsed,
14871         .data = NULL,
14872         .help_str = "show vf stats <port_id> <vf_id>",
14873         .tokens = {
14874                 (void *)&cmd_show_vf_stats_show,
14875                 (void *)&cmd_show_vf_stats_vf,
14876                 (void *)&cmd_show_vf_stats_stats,
14877                 (void *)&cmd_show_vf_stats_port_id,
14878                 (void *)&cmd_show_vf_stats_vf_id,
14879                 NULL,
14880         },
14881 };
14882
14883 /* clear vf stats */
14884
14885 /* Common result structure for clear vf stats */
14886 struct cmd_clear_vf_stats_result {
14887         cmdline_fixed_string_t clear;
14888         cmdline_fixed_string_t vf;
14889         cmdline_fixed_string_t stats;
14890         portid_t port_id;
14891         uint16_t vf_id;
14892 };
14893
14894 /* Common CLI fields clear vf stats*/
14895 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14896         TOKEN_STRING_INITIALIZER
14897                 (struct cmd_clear_vf_stats_result,
14898                  clear, "clear");
14899 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14900         TOKEN_STRING_INITIALIZER
14901                 (struct cmd_clear_vf_stats_result,
14902                  vf, "vf");
14903 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_clear_vf_stats_result,
14906                  stats, "stats");
14907 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14908         TOKEN_NUM_INITIALIZER
14909                 (struct cmd_clear_vf_stats_result,
14910                  port_id, UINT16);
14911 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14912         TOKEN_NUM_INITIALIZER
14913                 (struct cmd_clear_vf_stats_result,
14914                  vf_id, UINT16);
14915
14916 static void
14917 cmd_clear_vf_stats_parsed(
14918         void *parsed_result,
14919         __rte_unused struct cmdline *cl,
14920         __rte_unused void *data)
14921 {
14922         struct cmd_clear_vf_stats_result *res = parsed_result;
14923         int ret = -ENOTSUP;
14924
14925         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14926                 return;
14927
14928 #ifdef RTE_NET_I40E
14929         if (ret == -ENOTSUP)
14930                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14931                                                   res->vf_id);
14932 #endif
14933 #ifdef RTE_NET_BNXT
14934         if (ret == -ENOTSUP)
14935                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14936                                                   res->vf_id);
14937 #endif
14938
14939         switch (ret) {
14940         case 0:
14941                 break;
14942         case -EINVAL:
14943                 printf("invalid vf_id %d\n", res->vf_id);
14944                 break;
14945         case -ENODEV:
14946                 printf("invalid port_id %d\n", res->port_id);
14947                 break;
14948         case -ENOTSUP:
14949                 printf("function not implemented\n");
14950                 break;
14951         default:
14952                 printf("programming error: (%s)\n", strerror(-ret));
14953         }
14954 }
14955
14956 cmdline_parse_inst_t cmd_clear_vf_stats = {
14957         .f = cmd_clear_vf_stats_parsed,
14958         .data = NULL,
14959         .help_str = "clear vf stats <port_id> <vf_id>",
14960         .tokens = {
14961                 (void *)&cmd_clear_vf_stats_clear,
14962                 (void *)&cmd_clear_vf_stats_vf,
14963                 (void *)&cmd_clear_vf_stats_stats,
14964                 (void *)&cmd_clear_vf_stats_port_id,
14965                 (void *)&cmd_clear_vf_stats_vf_id,
14966                 NULL,
14967         },
14968 };
14969
14970 /* port config pctype mapping reset */
14971
14972 /* Common result structure for port config pctype mapping reset */
14973 struct cmd_pctype_mapping_reset_result {
14974         cmdline_fixed_string_t port;
14975         cmdline_fixed_string_t config;
14976         portid_t port_id;
14977         cmdline_fixed_string_t pctype;
14978         cmdline_fixed_string_t mapping;
14979         cmdline_fixed_string_t reset;
14980 };
14981
14982 /* Common CLI fields for port config pctype mapping reset*/
14983 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14984         TOKEN_STRING_INITIALIZER
14985                 (struct cmd_pctype_mapping_reset_result,
14986                  port, "port");
14987 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14988         TOKEN_STRING_INITIALIZER
14989                 (struct cmd_pctype_mapping_reset_result,
14990                  config, "config");
14991 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14992         TOKEN_NUM_INITIALIZER
14993                 (struct cmd_pctype_mapping_reset_result,
14994                  port_id, UINT16);
14995 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14996         TOKEN_STRING_INITIALIZER
14997                 (struct cmd_pctype_mapping_reset_result,
14998                  pctype, "pctype");
14999 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15000         TOKEN_STRING_INITIALIZER
15001                 (struct cmd_pctype_mapping_reset_result,
15002                  mapping, "mapping");
15003 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15004         TOKEN_STRING_INITIALIZER
15005                 (struct cmd_pctype_mapping_reset_result,
15006                  reset, "reset");
15007
15008 static void
15009 cmd_pctype_mapping_reset_parsed(
15010         void *parsed_result,
15011         __rte_unused struct cmdline *cl,
15012         __rte_unused void *data)
15013 {
15014         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15015         int ret = -ENOTSUP;
15016
15017         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15018                 return;
15019
15020 #ifdef RTE_NET_I40E
15021         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15022 #endif
15023
15024         switch (ret) {
15025         case 0:
15026                 break;
15027         case -ENODEV:
15028                 printf("invalid port_id %d\n", res->port_id);
15029                 break;
15030         case -ENOTSUP:
15031                 printf("function not implemented\n");
15032                 break;
15033         default:
15034                 printf("programming error: (%s)\n", strerror(-ret));
15035         }
15036 }
15037
15038 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15039         .f = cmd_pctype_mapping_reset_parsed,
15040         .data = NULL,
15041         .help_str = "port config <port_id> pctype mapping reset",
15042         .tokens = {
15043                 (void *)&cmd_pctype_mapping_reset_port,
15044                 (void *)&cmd_pctype_mapping_reset_config,
15045                 (void *)&cmd_pctype_mapping_reset_port_id,
15046                 (void *)&cmd_pctype_mapping_reset_pctype,
15047                 (void *)&cmd_pctype_mapping_reset_mapping,
15048                 (void *)&cmd_pctype_mapping_reset_reset,
15049                 NULL,
15050         },
15051 };
15052
15053 /* show port pctype mapping */
15054
15055 /* Common result structure for show port pctype mapping */
15056 struct cmd_pctype_mapping_get_result {
15057         cmdline_fixed_string_t show;
15058         cmdline_fixed_string_t port;
15059         portid_t port_id;
15060         cmdline_fixed_string_t pctype;
15061         cmdline_fixed_string_t mapping;
15062 };
15063
15064 /* Common CLI fields for pctype mapping get */
15065 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15066         TOKEN_STRING_INITIALIZER
15067                 (struct cmd_pctype_mapping_get_result,
15068                  show, "show");
15069 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15070         TOKEN_STRING_INITIALIZER
15071                 (struct cmd_pctype_mapping_get_result,
15072                  port, "port");
15073 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15074         TOKEN_NUM_INITIALIZER
15075                 (struct cmd_pctype_mapping_get_result,
15076                  port_id, UINT16);
15077 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15078         TOKEN_STRING_INITIALIZER
15079                 (struct cmd_pctype_mapping_get_result,
15080                  pctype, "pctype");
15081 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15082         TOKEN_STRING_INITIALIZER
15083                 (struct cmd_pctype_mapping_get_result,
15084                  mapping, "mapping");
15085
15086 static void
15087 cmd_pctype_mapping_get_parsed(
15088         void *parsed_result,
15089         __rte_unused struct cmdline *cl,
15090         __rte_unused void *data)
15091 {
15092         struct cmd_pctype_mapping_get_result *res = parsed_result;
15093         int ret = -ENOTSUP;
15094 #ifdef RTE_NET_I40E
15095         struct rte_pmd_i40e_flow_type_mapping
15096                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15097         int i, j, first_pctype;
15098 #endif
15099
15100         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15101                 return;
15102
15103 #ifdef RTE_NET_I40E
15104         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15105 #endif
15106
15107         switch (ret) {
15108         case 0:
15109                 break;
15110         case -ENODEV:
15111                 printf("invalid port_id %d\n", res->port_id);
15112                 return;
15113         case -ENOTSUP:
15114                 printf("function not implemented\n");
15115                 return;
15116         default:
15117                 printf("programming error: (%s)\n", strerror(-ret));
15118                 return;
15119         }
15120
15121 #ifdef RTE_NET_I40E
15122         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15123                 if (mapping[i].pctype != 0ULL) {
15124                         first_pctype = 1;
15125
15126                         printf("pctype: ");
15127                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15128                                 if (mapping[i].pctype & (1ULL << j)) {
15129                                         printf(first_pctype ?
15130                                                "%02d" : ",%02d", j);
15131                                         first_pctype = 0;
15132                                 }
15133                         }
15134                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15135                 }
15136         }
15137 #endif
15138 }
15139
15140 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15141         .f = cmd_pctype_mapping_get_parsed,
15142         .data = NULL,
15143         .help_str = "show port <port_id> pctype mapping",
15144         .tokens = {
15145                 (void *)&cmd_pctype_mapping_get_show,
15146                 (void *)&cmd_pctype_mapping_get_port,
15147                 (void *)&cmd_pctype_mapping_get_port_id,
15148                 (void *)&cmd_pctype_mapping_get_pctype,
15149                 (void *)&cmd_pctype_mapping_get_mapping,
15150                 NULL,
15151         },
15152 };
15153
15154 /* port config pctype mapping update */
15155
15156 /* Common result structure for port config pctype mapping update */
15157 struct cmd_pctype_mapping_update_result {
15158         cmdline_fixed_string_t port;
15159         cmdline_fixed_string_t config;
15160         portid_t port_id;
15161         cmdline_fixed_string_t pctype;
15162         cmdline_fixed_string_t mapping;
15163         cmdline_fixed_string_t update;
15164         cmdline_fixed_string_t pctype_list;
15165         uint16_t flow_type;
15166 };
15167
15168 /* Common CLI fields for pctype mapping update*/
15169 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15170         TOKEN_STRING_INITIALIZER
15171                 (struct cmd_pctype_mapping_update_result,
15172                  port, "port");
15173 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15174         TOKEN_STRING_INITIALIZER
15175                 (struct cmd_pctype_mapping_update_result,
15176                  config, "config");
15177 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15178         TOKEN_NUM_INITIALIZER
15179                 (struct cmd_pctype_mapping_update_result,
15180                  port_id, UINT16);
15181 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15182         TOKEN_STRING_INITIALIZER
15183                 (struct cmd_pctype_mapping_update_result,
15184                  pctype, "pctype");
15185 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15186         TOKEN_STRING_INITIALIZER
15187                 (struct cmd_pctype_mapping_update_result,
15188                  mapping, "mapping");
15189 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15190         TOKEN_STRING_INITIALIZER
15191                 (struct cmd_pctype_mapping_update_result,
15192                  update, "update");
15193 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15194         TOKEN_STRING_INITIALIZER
15195                 (struct cmd_pctype_mapping_update_result,
15196                  pctype_list, NULL);
15197 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15198         TOKEN_NUM_INITIALIZER
15199                 (struct cmd_pctype_mapping_update_result,
15200                  flow_type, UINT16);
15201
15202 static void
15203 cmd_pctype_mapping_update_parsed(
15204         void *parsed_result,
15205         __rte_unused struct cmdline *cl,
15206         __rte_unused void *data)
15207 {
15208         struct cmd_pctype_mapping_update_result *res = parsed_result;
15209         int ret = -ENOTSUP;
15210 #ifdef RTE_NET_I40E
15211         struct rte_pmd_i40e_flow_type_mapping mapping;
15212         unsigned int i;
15213         unsigned int nb_item;
15214         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15215 #endif
15216
15217         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15218                 return;
15219
15220 #ifdef RTE_NET_I40E
15221         nb_item = parse_item_list(res->pctype_list, "pctypes",
15222                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15223         mapping.flow_type = res->flow_type;
15224         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15225                 mapping.pctype |= (1ULL << pctype_list[i]);
15226         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15227                                                 &mapping,
15228                                                 1,
15229                                                 0);
15230 #endif
15231
15232         switch (ret) {
15233         case 0:
15234                 break;
15235         case -EINVAL:
15236                 printf("invalid pctype or flow type\n");
15237                 break;
15238         case -ENODEV:
15239                 printf("invalid port_id %d\n", res->port_id);
15240                 break;
15241         case -ENOTSUP:
15242                 printf("function not implemented\n");
15243                 break;
15244         default:
15245                 printf("programming error: (%s)\n", strerror(-ret));
15246         }
15247 }
15248
15249 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15250         .f = cmd_pctype_mapping_update_parsed,
15251         .data = NULL,
15252         .help_str = "port config <port_id> pctype mapping update"
15253         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15254         .tokens = {
15255                 (void *)&cmd_pctype_mapping_update_port,
15256                 (void *)&cmd_pctype_mapping_update_config,
15257                 (void *)&cmd_pctype_mapping_update_port_id,
15258                 (void *)&cmd_pctype_mapping_update_pctype,
15259                 (void *)&cmd_pctype_mapping_update_mapping,
15260                 (void *)&cmd_pctype_mapping_update_update,
15261                 (void *)&cmd_pctype_mapping_update_pc_type,
15262                 (void *)&cmd_pctype_mapping_update_flow_type,
15263                 NULL,
15264         },
15265 };
15266
15267 /* ptype mapping get */
15268
15269 /* Common result structure for ptype mapping get */
15270 struct cmd_ptype_mapping_get_result {
15271         cmdline_fixed_string_t ptype;
15272         cmdline_fixed_string_t mapping;
15273         cmdline_fixed_string_t get;
15274         portid_t port_id;
15275         uint8_t valid_only;
15276 };
15277
15278 /* Common CLI fields for ptype mapping get */
15279 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15280         TOKEN_STRING_INITIALIZER
15281                 (struct cmd_ptype_mapping_get_result,
15282                  ptype, "ptype");
15283 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15284         TOKEN_STRING_INITIALIZER
15285                 (struct cmd_ptype_mapping_get_result,
15286                  mapping, "mapping");
15287 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15288         TOKEN_STRING_INITIALIZER
15289                 (struct cmd_ptype_mapping_get_result,
15290                  get, "get");
15291 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15292         TOKEN_NUM_INITIALIZER
15293                 (struct cmd_ptype_mapping_get_result,
15294                  port_id, UINT16);
15295 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15296         TOKEN_NUM_INITIALIZER
15297                 (struct cmd_ptype_mapping_get_result,
15298                  valid_only, UINT8);
15299
15300 static void
15301 cmd_ptype_mapping_get_parsed(
15302         void *parsed_result,
15303         __rte_unused struct cmdline *cl,
15304         __rte_unused void *data)
15305 {
15306         struct cmd_ptype_mapping_get_result *res = parsed_result;
15307         int ret = -ENOTSUP;
15308 #ifdef RTE_NET_I40E
15309         int max_ptype_num = 256;
15310         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15311         uint16_t count;
15312         int i;
15313 #endif
15314
15315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15316                 return;
15317
15318 #ifdef RTE_NET_I40E
15319         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15320                                         mapping,
15321                                         max_ptype_num,
15322                                         &count,
15323                                         res->valid_only);
15324 #endif
15325
15326         switch (ret) {
15327         case 0:
15328                 break;
15329         case -ENODEV:
15330                 printf("invalid port_id %d\n", res->port_id);
15331                 break;
15332         case -ENOTSUP:
15333                 printf("function not implemented\n");
15334                 break;
15335         default:
15336                 printf("programming error: (%s)\n", strerror(-ret));
15337         }
15338
15339 #ifdef RTE_NET_I40E
15340         if (!ret) {
15341                 for (i = 0; i < count; i++)
15342                         printf("%3d\t0x%08x\n",
15343                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15344         }
15345 #endif
15346 }
15347
15348 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15349         .f = cmd_ptype_mapping_get_parsed,
15350         .data = NULL,
15351         .help_str = "ptype mapping get <port_id> <valid_only>",
15352         .tokens = {
15353                 (void *)&cmd_ptype_mapping_get_ptype,
15354                 (void *)&cmd_ptype_mapping_get_mapping,
15355                 (void *)&cmd_ptype_mapping_get_get,
15356                 (void *)&cmd_ptype_mapping_get_port_id,
15357                 (void *)&cmd_ptype_mapping_get_valid_only,
15358                 NULL,
15359         },
15360 };
15361
15362 /* ptype mapping replace */
15363
15364 /* Common result structure for ptype mapping replace */
15365 struct cmd_ptype_mapping_replace_result {
15366         cmdline_fixed_string_t ptype;
15367         cmdline_fixed_string_t mapping;
15368         cmdline_fixed_string_t replace;
15369         portid_t port_id;
15370         uint32_t target;
15371         uint8_t mask;
15372         uint32_t pkt_type;
15373 };
15374
15375 /* Common CLI fields for ptype mapping replace */
15376 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15377         TOKEN_STRING_INITIALIZER
15378                 (struct cmd_ptype_mapping_replace_result,
15379                  ptype, "ptype");
15380 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15381         TOKEN_STRING_INITIALIZER
15382                 (struct cmd_ptype_mapping_replace_result,
15383                  mapping, "mapping");
15384 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15385         TOKEN_STRING_INITIALIZER
15386                 (struct cmd_ptype_mapping_replace_result,
15387                  replace, "replace");
15388 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15389         TOKEN_NUM_INITIALIZER
15390                 (struct cmd_ptype_mapping_replace_result,
15391                  port_id, UINT16);
15392 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15393         TOKEN_NUM_INITIALIZER
15394                 (struct cmd_ptype_mapping_replace_result,
15395                  target, UINT32);
15396 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15397         TOKEN_NUM_INITIALIZER
15398                 (struct cmd_ptype_mapping_replace_result,
15399                  mask, UINT8);
15400 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15401         TOKEN_NUM_INITIALIZER
15402                 (struct cmd_ptype_mapping_replace_result,
15403                  pkt_type, UINT32);
15404
15405 static void
15406 cmd_ptype_mapping_replace_parsed(
15407         void *parsed_result,
15408         __rte_unused struct cmdline *cl,
15409         __rte_unused void *data)
15410 {
15411         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15412         int ret = -ENOTSUP;
15413
15414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15415                 return;
15416
15417 #ifdef RTE_NET_I40E
15418         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15419                                         res->target,
15420                                         res->mask,
15421                                         res->pkt_type);
15422 #endif
15423
15424         switch (ret) {
15425         case 0:
15426                 break;
15427         case -EINVAL:
15428                 printf("invalid ptype 0x%8x or 0x%8x\n",
15429                                 res->target, res->pkt_type);
15430                 break;
15431         case -ENODEV:
15432                 printf("invalid port_id %d\n", res->port_id);
15433                 break;
15434         case -ENOTSUP:
15435                 printf("function not implemented\n");
15436                 break;
15437         default:
15438                 printf("programming error: (%s)\n", strerror(-ret));
15439         }
15440 }
15441
15442 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15443         .f = cmd_ptype_mapping_replace_parsed,
15444         .data = NULL,
15445         .help_str =
15446                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15447         .tokens = {
15448                 (void *)&cmd_ptype_mapping_replace_ptype,
15449                 (void *)&cmd_ptype_mapping_replace_mapping,
15450                 (void *)&cmd_ptype_mapping_replace_replace,
15451                 (void *)&cmd_ptype_mapping_replace_port_id,
15452                 (void *)&cmd_ptype_mapping_replace_target,
15453                 (void *)&cmd_ptype_mapping_replace_mask,
15454                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15455                 NULL,
15456         },
15457 };
15458
15459 /* ptype mapping reset */
15460
15461 /* Common result structure for ptype mapping reset */
15462 struct cmd_ptype_mapping_reset_result {
15463         cmdline_fixed_string_t ptype;
15464         cmdline_fixed_string_t mapping;
15465         cmdline_fixed_string_t reset;
15466         portid_t port_id;
15467 };
15468
15469 /* Common CLI fields for ptype mapping reset*/
15470 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15471         TOKEN_STRING_INITIALIZER
15472                 (struct cmd_ptype_mapping_reset_result,
15473                  ptype, "ptype");
15474 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15475         TOKEN_STRING_INITIALIZER
15476                 (struct cmd_ptype_mapping_reset_result,
15477                  mapping, "mapping");
15478 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15479         TOKEN_STRING_INITIALIZER
15480                 (struct cmd_ptype_mapping_reset_result,
15481                  reset, "reset");
15482 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15483         TOKEN_NUM_INITIALIZER
15484                 (struct cmd_ptype_mapping_reset_result,
15485                  port_id, UINT16);
15486
15487 static void
15488 cmd_ptype_mapping_reset_parsed(
15489         void *parsed_result,
15490         __rte_unused struct cmdline *cl,
15491         __rte_unused void *data)
15492 {
15493         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15494         int ret = -ENOTSUP;
15495
15496         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15497                 return;
15498
15499 #ifdef RTE_NET_I40E
15500         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15501 #endif
15502
15503         switch (ret) {
15504         case 0:
15505                 break;
15506         case -ENODEV:
15507                 printf("invalid port_id %d\n", res->port_id);
15508                 break;
15509         case -ENOTSUP:
15510                 printf("function not implemented\n");
15511                 break;
15512         default:
15513                 printf("programming error: (%s)\n", strerror(-ret));
15514         }
15515 }
15516
15517 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15518         .f = cmd_ptype_mapping_reset_parsed,
15519         .data = NULL,
15520         .help_str = "ptype mapping reset <port_id>",
15521         .tokens = {
15522                 (void *)&cmd_ptype_mapping_reset_ptype,
15523                 (void *)&cmd_ptype_mapping_reset_mapping,
15524                 (void *)&cmd_ptype_mapping_reset_reset,
15525                 (void *)&cmd_ptype_mapping_reset_port_id,
15526                 NULL,
15527         },
15528 };
15529
15530 /* ptype mapping update */
15531
15532 /* Common result structure for ptype mapping update */
15533 struct cmd_ptype_mapping_update_result {
15534         cmdline_fixed_string_t ptype;
15535         cmdline_fixed_string_t mapping;
15536         cmdline_fixed_string_t reset;
15537         portid_t port_id;
15538         uint8_t hw_ptype;
15539         uint32_t sw_ptype;
15540 };
15541
15542 /* Common CLI fields for ptype mapping update*/
15543 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15544         TOKEN_STRING_INITIALIZER
15545                 (struct cmd_ptype_mapping_update_result,
15546                  ptype, "ptype");
15547 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15548         TOKEN_STRING_INITIALIZER
15549                 (struct cmd_ptype_mapping_update_result,
15550                  mapping, "mapping");
15551 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15552         TOKEN_STRING_INITIALIZER
15553                 (struct cmd_ptype_mapping_update_result,
15554                  reset, "update");
15555 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15556         TOKEN_NUM_INITIALIZER
15557                 (struct cmd_ptype_mapping_update_result,
15558                  port_id, UINT16);
15559 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15560         TOKEN_NUM_INITIALIZER
15561                 (struct cmd_ptype_mapping_update_result,
15562                  hw_ptype, UINT8);
15563 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15564         TOKEN_NUM_INITIALIZER
15565                 (struct cmd_ptype_mapping_update_result,
15566                  sw_ptype, UINT32);
15567
15568 static void
15569 cmd_ptype_mapping_update_parsed(
15570         void *parsed_result,
15571         __rte_unused struct cmdline *cl,
15572         __rte_unused void *data)
15573 {
15574         struct cmd_ptype_mapping_update_result *res = parsed_result;
15575         int ret = -ENOTSUP;
15576 #ifdef RTE_NET_I40E
15577         struct rte_pmd_i40e_ptype_mapping mapping;
15578 #endif
15579         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15580                 return;
15581
15582 #ifdef RTE_NET_I40E
15583         mapping.hw_ptype = res->hw_ptype;
15584         mapping.sw_ptype = res->sw_ptype;
15585         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15586                                                 &mapping,
15587                                                 1,
15588                                                 0);
15589 #endif
15590
15591         switch (ret) {
15592         case 0:
15593                 break;
15594         case -EINVAL:
15595                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15596                 break;
15597         case -ENODEV:
15598                 printf("invalid port_id %d\n", res->port_id);
15599                 break;
15600         case -ENOTSUP:
15601                 printf("function not implemented\n");
15602                 break;
15603         default:
15604                 printf("programming error: (%s)\n", strerror(-ret));
15605         }
15606 }
15607
15608 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15609         .f = cmd_ptype_mapping_update_parsed,
15610         .data = NULL,
15611         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15612         .tokens = {
15613                 (void *)&cmd_ptype_mapping_update_ptype,
15614                 (void *)&cmd_ptype_mapping_update_mapping,
15615                 (void *)&cmd_ptype_mapping_update_update,
15616                 (void *)&cmd_ptype_mapping_update_port_id,
15617                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15618                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15619                 NULL,
15620         },
15621 };
15622
15623 /* Common result structure for file commands */
15624 struct cmd_cmdfile_result {
15625         cmdline_fixed_string_t load;
15626         cmdline_fixed_string_t filename;
15627 };
15628
15629 /* Common CLI fields for file commands */
15630 cmdline_parse_token_string_t cmd_load_cmdfile =
15631         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15632 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15633         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15634
15635 static void
15636 cmd_load_from_file_parsed(
15637         void *parsed_result,
15638         __rte_unused struct cmdline *cl,
15639         __rte_unused void *data)
15640 {
15641         struct cmd_cmdfile_result *res = parsed_result;
15642
15643         cmdline_read_from_file(res->filename);
15644 }
15645
15646 cmdline_parse_inst_t cmd_load_from_file = {
15647         .f = cmd_load_from_file_parsed,
15648         .data = NULL,
15649         .help_str = "load <filename>",
15650         .tokens = {
15651                 (void *)&cmd_load_cmdfile,
15652                 (void *)&cmd_load_cmdfile_filename,
15653                 NULL,
15654         },
15655 };
15656
15657 /* Get Rx offloads capabilities */
15658 struct cmd_rx_offload_get_capa_result {
15659         cmdline_fixed_string_t show;
15660         cmdline_fixed_string_t port;
15661         portid_t port_id;
15662         cmdline_fixed_string_t rx_offload;
15663         cmdline_fixed_string_t capabilities;
15664 };
15665
15666 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15667         TOKEN_STRING_INITIALIZER
15668                 (struct cmd_rx_offload_get_capa_result,
15669                  show, "show");
15670 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15671         TOKEN_STRING_INITIALIZER
15672                 (struct cmd_rx_offload_get_capa_result,
15673                  port, "port");
15674 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15675         TOKEN_NUM_INITIALIZER
15676                 (struct cmd_rx_offload_get_capa_result,
15677                  port_id, UINT16);
15678 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15679         TOKEN_STRING_INITIALIZER
15680                 (struct cmd_rx_offload_get_capa_result,
15681                  rx_offload, "rx_offload");
15682 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15683         TOKEN_STRING_INITIALIZER
15684                 (struct cmd_rx_offload_get_capa_result,
15685                  capabilities, "capabilities");
15686
15687 static void
15688 print_rx_offloads(uint64_t offloads)
15689 {
15690         uint64_t single_offload;
15691         int begin;
15692         int end;
15693         int bit;
15694
15695         if (offloads == 0)
15696                 return;
15697
15698         begin = __builtin_ctzll(offloads);
15699         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15700
15701         single_offload = 1ULL << begin;
15702         for (bit = begin; bit < end; bit++) {
15703                 if (offloads & single_offload)
15704                         printf(" %s",
15705                                rte_eth_dev_rx_offload_name(single_offload));
15706                 single_offload <<= 1;
15707         }
15708 }
15709
15710 static void
15711 cmd_rx_offload_get_capa_parsed(
15712         void *parsed_result,
15713         __rte_unused struct cmdline *cl,
15714         __rte_unused void *data)
15715 {
15716         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15717         struct rte_eth_dev_info dev_info;
15718         portid_t port_id = res->port_id;
15719         uint64_t queue_offloads;
15720         uint64_t port_offloads;
15721         int ret;
15722
15723         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15724         if (ret != 0)
15725                 return;
15726
15727         queue_offloads = dev_info.rx_queue_offload_capa;
15728         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15729
15730         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15731         printf("  Per Queue :");
15732         print_rx_offloads(queue_offloads);
15733
15734         printf("\n");
15735         printf("  Per Port  :");
15736         print_rx_offloads(port_offloads);
15737         printf("\n\n");
15738 }
15739
15740 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15741         .f = cmd_rx_offload_get_capa_parsed,
15742         .data = NULL,
15743         .help_str = "show port <port_id> rx_offload capabilities",
15744         .tokens = {
15745                 (void *)&cmd_rx_offload_get_capa_show,
15746                 (void *)&cmd_rx_offload_get_capa_port,
15747                 (void *)&cmd_rx_offload_get_capa_port_id,
15748                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15749                 (void *)&cmd_rx_offload_get_capa_capabilities,
15750                 NULL,
15751         }
15752 };
15753
15754 /* Get Rx offloads configuration */
15755 struct cmd_rx_offload_get_configuration_result {
15756         cmdline_fixed_string_t show;
15757         cmdline_fixed_string_t port;
15758         portid_t port_id;
15759         cmdline_fixed_string_t rx_offload;
15760         cmdline_fixed_string_t configuration;
15761 };
15762
15763 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15764         TOKEN_STRING_INITIALIZER
15765                 (struct cmd_rx_offload_get_configuration_result,
15766                  show, "show");
15767 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15768         TOKEN_STRING_INITIALIZER
15769                 (struct cmd_rx_offload_get_configuration_result,
15770                  port, "port");
15771 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15772         TOKEN_NUM_INITIALIZER
15773                 (struct cmd_rx_offload_get_configuration_result,
15774                  port_id, UINT16);
15775 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15776         TOKEN_STRING_INITIALIZER
15777                 (struct cmd_rx_offload_get_configuration_result,
15778                  rx_offload, "rx_offload");
15779 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15780         TOKEN_STRING_INITIALIZER
15781                 (struct cmd_rx_offload_get_configuration_result,
15782                  configuration, "configuration");
15783
15784 static void
15785 cmd_rx_offload_get_configuration_parsed(
15786         void *parsed_result,
15787         __rte_unused struct cmdline *cl,
15788         __rte_unused void *data)
15789 {
15790         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15791         struct rte_eth_dev_info dev_info;
15792         portid_t port_id = res->port_id;
15793         struct rte_port *port = &ports[port_id];
15794         uint64_t port_offloads;
15795         uint64_t queue_offloads;
15796         uint16_t nb_rx_queues;
15797         int q;
15798         int ret;
15799
15800         printf("Rx Offloading Configuration of port %d :\n", port_id);
15801
15802         port_offloads = port->dev_conf.rxmode.offloads;
15803         printf("  Port :");
15804         print_rx_offloads(port_offloads);
15805         printf("\n");
15806
15807         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15808         if (ret != 0)
15809                 return;
15810
15811         nb_rx_queues = dev_info.nb_rx_queues;
15812         for (q = 0; q < nb_rx_queues; q++) {
15813                 queue_offloads = port->rx_conf[q].offloads;
15814                 printf("  Queue[%2d] :", q);
15815                 print_rx_offloads(queue_offloads);
15816                 printf("\n");
15817         }
15818         printf("\n");
15819 }
15820
15821 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15822         .f = cmd_rx_offload_get_configuration_parsed,
15823         .data = NULL,
15824         .help_str = "show port <port_id> rx_offload configuration",
15825         .tokens = {
15826                 (void *)&cmd_rx_offload_get_configuration_show,
15827                 (void *)&cmd_rx_offload_get_configuration_port,
15828                 (void *)&cmd_rx_offload_get_configuration_port_id,
15829                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15830                 (void *)&cmd_rx_offload_get_configuration_configuration,
15831                 NULL,
15832         }
15833 };
15834
15835 /* Enable/Disable a per port offloading */
15836 struct cmd_config_per_port_rx_offload_result {
15837         cmdline_fixed_string_t port;
15838         cmdline_fixed_string_t config;
15839         portid_t port_id;
15840         cmdline_fixed_string_t rx_offload;
15841         cmdline_fixed_string_t offload;
15842         cmdline_fixed_string_t on_off;
15843 };
15844
15845 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15846         TOKEN_STRING_INITIALIZER
15847                 (struct cmd_config_per_port_rx_offload_result,
15848                  port, "port");
15849 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15850         TOKEN_STRING_INITIALIZER
15851                 (struct cmd_config_per_port_rx_offload_result,
15852                  config, "config");
15853 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15854         TOKEN_NUM_INITIALIZER
15855                 (struct cmd_config_per_port_rx_offload_result,
15856                  port_id, UINT16);
15857 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15858         TOKEN_STRING_INITIALIZER
15859                 (struct cmd_config_per_port_rx_offload_result,
15860                  rx_offload, "rx_offload");
15861 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15862         TOKEN_STRING_INITIALIZER
15863                 (struct cmd_config_per_port_rx_offload_result,
15864                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15865                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15866                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15867                            "scatter#buffer_split#timestamp#security#"
15868                            "keep_crc#rss_hash");
15869 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15870         TOKEN_STRING_INITIALIZER
15871                 (struct cmd_config_per_port_rx_offload_result,
15872                  on_off, "on#off");
15873
15874 static uint64_t
15875 search_rx_offload(const char *name)
15876 {
15877         uint64_t single_offload;
15878         const char *single_name;
15879         int found = 0;
15880         unsigned int bit;
15881
15882         single_offload = 1;
15883         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15884                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15885                 if (!strcasecmp(single_name, name)) {
15886                         found = 1;
15887                         break;
15888                 }
15889                 single_offload <<= 1;
15890         }
15891
15892         if (found)
15893                 return single_offload;
15894
15895         return 0;
15896 }
15897
15898 static void
15899 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15900                                 __rte_unused struct cmdline *cl,
15901                                 __rte_unused void *data)
15902 {
15903         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15904         portid_t port_id = res->port_id;
15905         struct rte_eth_dev_info dev_info;
15906         struct rte_port *port = &ports[port_id];
15907         uint64_t single_offload;
15908         uint16_t nb_rx_queues;
15909         int q;
15910         int ret;
15911
15912         if (port->port_status != RTE_PORT_STOPPED) {
15913                 printf("Error: Can't config offload when Port %d "
15914                        "is not stopped\n", port_id);
15915                 return;
15916         }
15917
15918         single_offload = search_rx_offload(res->offload);
15919         if (single_offload == 0) {
15920                 printf("Unknown offload name: %s\n", res->offload);
15921                 return;
15922         }
15923
15924         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15925         if (ret != 0)
15926                 return;
15927
15928         nb_rx_queues = dev_info.nb_rx_queues;
15929         if (!strcmp(res->on_off, "on")) {
15930                 port->dev_conf.rxmode.offloads |= single_offload;
15931                 for (q = 0; q < nb_rx_queues; q++)
15932                         port->rx_conf[q].offloads |= single_offload;
15933         } else {
15934                 port->dev_conf.rxmode.offloads &= ~single_offload;
15935                 for (q = 0; q < nb_rx_queues; q++)
15936                         port->rx_conf[q].offloads &= ~single_offload;
15937         }
15938
15939         cmd_reconfig_device_queue(port_id, 1, 1);
15940 }
15941
15942 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15943         .f = cmd_config_per_port_rx_offload_parsed,
15944         .data = NULL,
15945         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15946                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15947                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15948                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15949                     "keep_crc|rss_hash on|off",
15950         .tokens = {
15951                 (void *)&cmd_config_per_port_rx_offload_result_port,
15952                 (void *)&cmd_config_per_port_rx_offload_result_config,
15953                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15954                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15955                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15956                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15957                 NULL,
15958         }
15959 };
15960
15961 /* Enable/Disable a per queue offloading */
15962 struct cmd_config_per_queue_rx_offload_result {
15963         cmdline_fixed_string_t port;
15964         portid_t port_id;
15965         cmdline_fixed_string_t rxq;
15966         uint16_t queue_id;
15967         cmdline_fixed_string_t rx_offload;
15968         cmdline_fixed_string_t offload;
15969         cmdline_fixed_string_t on_off;
15970 };
15971
15972 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15973         TOKEN_STRING_INITIALIZER
15974                 (struct cmd_config_per_queue_rx_offload_result,
15975                  port, "port");
15976 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15977         TOKEN_NUM_INITIALIZER
15978                 (struct cmd_config_per_queue_rx_offload_result,
15979                  port_id, UINT16);
15980 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_config_per_queue_rx_offload_result,
15983                  rxq, "rxq");
15984 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15985         TOKEN_NUM_INITIALIZER
15986                 (struct cmd_config_per_queue_rx_offload_result,
15987                  queue_id, UINT16);
15988 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15989         TOKEN_STRING_INITIALIZER
15990                 (struct cmd_config_per_queue_rx_offload_result,
15991                  rx_offload, "rx_offload");
15992 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15993         TOKEN_STRING_INITIALIZER
15994                 (struct cmd_config_per_queue_rx_offload_result,
15995                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15996                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15997                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15998                            "scatter#buffer_split#timestamp#security#keep_crc");
15999 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16000         TOKEN_STRING_INITIALIZER
16001                 (struct cmd_config_per_queue_rx_offload_result,
16002                  on_off, "on#off");
16003
16004 static void
16005 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16006                                 __rte_unused struct cmdline *cl,
16007                                 __rte_unused void *data)
16008 {
16009         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16010         struct rte_eth_dev_info dev_info;
16011         portid_t port_id = res->port_id;
16012         uint16_t queue_id = res->queue_id;
16013         struct rte_port *port = &ports[port_id];
16014         uint64_t single_offload;
16015         int ret;
16016
16017         if (port->port_status != RTE_PORT_STOPPED) {
16018                 printf("Error: Can't config offload when Port %d "
16019                        "is not stopped\n", port_id);
16020                 return;
16021         }
16022
16023         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16024         if (ret != 0)
16025                 return;
16026
16027         if (queue_id >= dev_info.nb_rx_queues) {
16028                 printf("Error: input queue_id should be 0 ... "
16029                        "%d\n", dev_info.nb_rx_queues - 1);
16030                 return;
16031         }
16032
16033         single_offload = search_rx_offload(res->offload);
16034         if (single_offload == 0) {
16035                 printf("Unknown offload name: %s\n", res->offload);
16036                 return;
16037         }
16038
16039         if (!strcmp(res->on_off, "on"))
16040                 port->rx_conf[queue_id].offloads |= single_offload;
16041         else
16042                 port->rx_conf[queue_id].offloads &= ~single_offload;
16043
16044         cmd_reconfig_device_queue(port_id, 1, 1);
16045 }
16046
16047 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16048         .f = cmd_config_per_queue_rx_offload_parsed,
16049         .data = NULL,
16050         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16051                     "vlan_strip|ipv4_cksum|"
16052                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16053                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16054                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16055                     "keep_crc on|off",
16056         .tokens = {
16057                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16058                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16059                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16060                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16061                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16062                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16063                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16064                 NULL,
16065         }
16066 };
16067
16068 /* Get Tx offloads capabilities */
16069 struct cmd_tx_offload_get_capa_result {
16070         cmdline_fixed_string_t show;
16071         cmdline_fixed_string_t port;
16072         portid_t port_id;
16073         cmdline_fixed_string_t tx_offload;
16074         cmdline_fixed_string_t capabilities;
16075 };
16076
16077 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16078         TOKEN_STRING_INITIALIZER
16079                 (struct cmd_tx_offload_get_capa_result,
16080                  show, "show");
16081 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16082         TOKEN_STRING_INITIALIZER
16083                 (struct cmd_tx_offload_get_capa_result,
16084                  port, "port");
16085 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16086         TOKEN_NUM_INITIALIZER
16087                 (struct cmd_tx_offload_get_capa_result,
16088                  port_id, UINT16);
16089 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16090         TOKEN_STRING_INITIALIZER
16091                 (struct cmd_tx_offload_get_capa_result,
16092                  tx_offload, "tx_offload");
16093 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16094         TOKEN_STRING_INITIALIZER
16095                 (struct cmd_tx_offload_get_capa_result,
16096                  capabilities, "capabilities");
16097
16098 static void
16099 print_tx_offloads(uint64_t offloads)
16100 {
16101         uint64_t single_offload;
16102         int begin;
16103         int end;
16104         int bit;
16105
16106         if (offloads == 0)
16107                 return;
16108
16109         begin = __builtin_ctzll(offloads);
16110         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16111
16112         single_offload = 1ULL << begin;
16113         for (bit = begin; bit < end; bit++) {
16114                 if (offloads & single_offload)
16115                         printf(" %s",
16116                                rte_eth_dev_tx_offload_name(single_offload));
16117                 single_offload <<= 1;
16118         }
16119 }
16120
16121 static void
16122 cmd_tx_offload_get_capa_parsed(
16123         void *parsed_result,
16124         __rte_unused struct cmdline *cl,
16125         __rte_unused void *data)
16126 {
16127         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16128         struct rte_eth_dev_info dev_info;
16129         portid_t port_id = res->port_id;
16130         uint64_t queue_offloads;
16131         uint64_t port_offloads;
16132         int ret;
16133
16134         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16135         if (ret != 0)
16136                 return;
16137
16138         queue_offloads = dev_info.tx_queue_offload_capa;
16139         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16140
16141         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16142         printf("  Per Queue :");
16143         print_tx_offloads(queue_offloads);
16144
16145         printf("\n");
16146         printf("  Per Port  :");
16147         print_tx_offloads(port_offloads);
16148         printf("\n\n");
16149 }
16150
16151 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16152         .f = cmd_tx_offload_get_capa_parsed,
16153         .data = NULL,
16154         .help_str = "show port <port_id> tx_offload capabilities",
16155         .tokens = {
16156                 (void *)&cmd_tx_offload_get_capa_show,
16157                 (void *)&cmd_tx_offload_get_capa_port,
16158                 (void *)&cmd_tx_offload_get_capa_port_id,
16159                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16160                 (void *)&cmd_tx_offload_get_capa_capabilities,
16161                 NULL,
16162         }
16163 };
16164
16165 /* Get Tx offloads configuration */
16166 struct cmd_tx_offload_get_configuration_result {
16167         cmdline_fixed_string_t show;
16168         cmdline_fixed_string_t port;
16169         portid_t port_id;
16170         cmdline_fixed_string_t tx_offload;
16171         cmdline_fixed_string_t configuration;
16172 };
16173
16174 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16175         TOKEN_STRING_INITIALIZER
16176                 (struct cmd_tx_offload_get_configuration_result,
16177                  show, "show");
16178 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16179         TOKEN_STRING_INITIALIZER
16180                 (struct cmd_tx_offload_get_configuration_result,
16181                  port, "port");
16182 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16183         TOKEN_NUM_INITIALIZER
16184                 (struct cmd_tx_offload_get_configuration_result,
16185                  port_id, UINT16);
16186 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16187         TOKEN_STRING_INITIALIZER
16188                 (struct cmd_tx_offload_get_configuration_result,
16189                  tx_offload, "tx_offload");
16190 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16191         TOKEN_STRING_INITIALIZER
16192                 (struct cmd_tx_offload_get_configuration_result,
16193                  configuration, "configuration");
16194
16195 static void
16196 cmd_tx_offload_get_configuration_parsed(
16197         void *parsed_result,
16198         __rte_unused struct cmdline *cl,
16199         __rte_unused void *data)
16200 {
16201         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16202         struct rte_eth_dev_info dev_info;
16203         portid_t port_id = res->port_id;
16204         struct rte_port *port = &ports[port_id];
16205         uint64_t port_offloads;
16206         uint64_t queue_offloads;
16207         uint16_t nb_tx_queues;
16208         int q;
16209         int ret;
16210
16211         printf("Tx Offloading Configuration of port %d :\n", port_id);
16212
16213         port_offloads = port->dev_conf.txmode.offloads;
16214         printf("  Port :");
16215         print_tx_offloads(port_offloads);
16216         printf("\n");
16217
16218         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16219         if (ret != 0)
16220                 return;
16221
16222         nb_tx_queues = dev_info.nb_tx_queues;
16223         for (q = 0; q < nb_tx_queues; q++) {
16224                 queue_offloads = port->tx_conf[q].offloads;
16225                 printf("  Queue[%2d] :", q);
16226                 print_tx_offloads(queue_offloads);
16227                 printf("\n");
16228         }
16229         printf("\n");
16230 }
16231
16232 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16233         .f = cmd_tx_offload_get_configuration_parsed,
16234         .data = NULL,
16235         .help_str = "show port <port_id> tx_offload configuration",
16236         .tokens = {
16237                 (void *)&cmd_tx_offload_get_configuration_show,
16238                 (void *)&cmd_tx_offload_get_configuration_port,
16239                 (void *)&cmd_tx_offload_get_configuration_port_id,
16240                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16241                 (void *)&cmd_tx_offload_get_configuration_configuration,
16242                 NULL,
16243         }
16244 };
16245
16246 /* Enable/Disable a per port offloading */
16247 struct cmd_config_per_port_tx_offload_result {
16248         cmdline_fixed_string_t port;
16249         cmdline_fixed_string_t config;
16250         portid_t port_id;
16251         cmdline_fixed_string_t tx_offload;
16252         cmdline_fixed_string_t offload;
16253         cmdline_fixed_string_t on_off;
16254 };
16255
16256 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16257         TOKEN_STRING_INITIALIZER
16258                 (struct cmd_config_per_port_tx_offload_result,
16259                  port, "port");
16260 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16261         TOKEN_STRING_INITIALIZER
16262                 (struct cmd_config_per_port_tx_offload_result,
16263                  config, "config");
16264 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16265         TOKEN_NUM_INITIALIZER
16266                 (struct cmd_config_per_port_tx_offload_result,
16267                  port_id, UINT16);
16268 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16269         TOKEN_STRING_INITIALIZER
16270                 (struct cmd_config_per_port_tx_offload_result,
16271                  tx_offload, "tx_offload");
16272 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16273         TOKEN_STRING_INITIALIZER
16274                 (struct cmd_config_per_port_tx_offload_result,
16275                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16276                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16277                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16278                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16279                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16280                           "send_on_timestamp");
16281 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16282         TOKEN_STRING_INITIALIZER
16283                 (struct cmd_config_per_port_tx_offload_result,
16284                  on_off, "on#off");
16285
16286 static uint64_t
16287 search_tx_offload(const char *name)
16288 {
16289         uint64_t single_offload;
16290         const char *single_name;
16291         int found = 0;
16292         unsigned int bit;
16293
16294         single_offload = 1;
16295         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16296                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16297                 if (single_name == NULL)
16298                         break;
16299                 if (!strcasecmp(single_name, name)) {
16300                         found = 1;
16301                         break;
16302                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16303                         break;
16304                 single_offload <<= 1;
16305         }
16306
16307         if (found)
16308                 return single_offload;
16309
16310         return 0;
16311 }
16312
16313 static void
16314 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16315                                 __rte_unused struct cmdline *cl,
16316                                 __rte_unused void *data)
16317 {
16318         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16319         portid_t port_id = res->port_id;
16320         struct rte_eth_dev_info dev_info;
16321         struct rte_port *port = &ports[port_id];
16322         uint64_t single_offload;
16323         uint16_t nb_tx_queues;
16324         int q;
16325         int ret;
16326
16327         if (port->port_status != RTE_PORT_STOPPED) {
16328                 printf("Error: Can't config offload when Port %d "
16329                        "is not stopped\n", port_id);
16330                 return;
16331         }
16332
16333         single_offload = search_tx_offload(res->offload);
16334         if (single_offload == 0) {
16335                 printf("Unknown offload name: %s\n", res->offload);
16336                 return;
16337         }
16338
16339         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16340         if (ret != 0)
16341                 return;
16342
16343         nb_tx_queues = dev_info.nb_tx_queues;
16344         if (!strcmp(res->on_off, "on")) {
16345                 port->dev_conf.txmode.offloads |= single_offload;
16346                 for (q = 0; q < nb_tx_queues; q++)
16347                         port->tx_conf[q].offloads |= single_offload;
16348         } else {
16349                 port->dev_conf.txmode.offloads &= ~single_offload;
16350                 for (q = 0; q < nb_tx_queues; q++)
16351                         port->tx_conf[q].offloads &= ~single_offload;
16352         }
16353
16354         cmd_reconfig_device_queue(port_id, 1, 1);
16355 }
16356
16357 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16358         .f = cmd_config_per_port_tx_offload_parsed,
16359         .data = NULL,
16360         .help_str = "port config <port_id> tx_offload "
16361                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16362                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16363                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16364                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16365                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16366                     "send_on_timestamp on|off",
16367         .tokens = {
16368                 (void *)&cmd_config_per_port_tx_offload_result_port,
16369                 (void *)&cmd_config_per_port_tx_offload_result_config,
16370                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16371                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16372                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16373                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16374                 NULL,
16375         }
16376 };
16377
16378 /* Enable/Disable a per queue offloading */
16379 struct cmd_config_per_queue_tx_offload_result {
16380         cmdline_fixed_string_t port;
16381         portid_t port_id;
16382         cmdline_fixed_string_t txq;
16383         uint16_t queue_id;
16384         cmdline_fixed_string_t tx_offload;
16385         cmdline_fixed_string_t offload;
16386         cmdline_fixed_string_t on_off;
16387 };
16388
16389 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16390         TOKEN_STRING_INITIALIZER
16391                 (struct cmd_config_per_queue_tx_offload_result,
16392                  port, "port");
16393 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16394         TOKEN_NUM_INITIALIZER
16395                 (struct cmd_config_per_queue_tx_offload_result,
16396                  port_id, UINT16);
16397 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16398         TOKEN_STRING_INITIALIZER
16399                 (struct cmd_config_per_queue_tx_offload_result,
16400                  txq, "txq");
16401 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16402         TOKEN_NUM_INITIALIZER
16403                 (struct cmd_config_per_queue_tx_offload_result,
16404                  queue_id, UINT16);
16405 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16406         TOKEN_STRING_INITIALIZER
16407                 (struct cmd_config_per_queue_tx_offload_result,
16408                  tx_offload, "tx_offload");
16409 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16410         TOKEN_STRING_INITIALIZER
16411                 (struct cmd_config_per_queue_tx_offload_result,
16412                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16413                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16414                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16415                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16416                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16417 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16418         TOKEN_STRING_INITIALIZER
16419                 (struct cmd_config_per_queue_tx_offload_result,
16420                  on_off, "on#off");
16421
16422 static void
16423 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16424                                 __rte_unused struct cmdline *cl,
16425                                 __rte_unused void *data)
16426 {
16427         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16428         struct rte_eth_dev_info dev_info;
16429         portid_t port_id = res->port_id;
16430         uint16_t queue_id = res->queue_id;
16431         struct rte_port *port = &ports[port_id];
16432         uint64_t single_offload;
16433         int ret;
16434
16435         if (port->port_status != RTE_PORT_STOPPED) {
16436                 printf("Error: Can't config offload when Port %d "
16437                        "is not stopped\n", port_id);
16438                 return;
16439         }
16440
16441         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16442         if (ret != 0)
16443                 return;
16444
16445         if (queue_id >= dev_info.nb_tx_queues) {
16446                 printf("Error: input queue_id should be 0 ... "
16447                        "%d\n", dev_info.nb_tx_queues - 1);
16448                 return;
16449         }
16450
16451         single_offload = search_tx_offload(res->offload);
16452         if (single_offload == 0) {
16453                 printf("Unknown offload name: %s\n", res->offload);
16454                 return;
16455         }
16456
16457         if (!strcmp(res->on_off, "on"))
16458                 port->tx_conf[queue_id].offloads |= single_offload;
16459         else
16460                 port->tx_conf[queue_id].offloads &= ~single_offload;
16461
16462         cmd_reconfig_device_queue(port_id, 1, 1);
16463 }
16464
16465 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16466         .f = cmd_config_per_queue_tx_offload_parsed,
16467         .data = NULL,
16468         .help_str = "port <port_id> txq <queue_id> tx_offload "
16469                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16470                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16471                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16472                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16473                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16474                     "on|off",
16475         .tokens = {
16476                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16477                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16478                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16479                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16480                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16481                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16482                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16483                 NULL,
16484         }
16485 };
16486
16487 /* *** configure tx_metadata for specific port *** */
16488 struct cmd_config_tx_metadata_specific_result {
16489         cmdline_fixed_string_t port;
16490         cmdline_fixed_string_t keyword;
16491         uint16_t port_id;
16492         cmdline_fixed_string_t item;
16493         uint32_t value;
16494 };
16495
16496 static void
16497 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16498                                 __rte_unused struct cmdline *cl,
16499                                 __rte_unused void *data)
16500 {
16501         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16502
16503         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16504                 return;
16505         ports[res->port_id].tx_metadata = res->value;
16506         /* Add/remove callback to insert valid metadata in every Tx packet. */
16507         if (ports[res->port_id].tx_metadata)
16508                 add_tx_md_callback(res->port_id);
16509         else
16510                 remove_tx_md_callback(res->port_id);
16511         rte_flow_dynf_metadata_register();
16512 }
16513
16514 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16515         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16516                         port, "port");
16517 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16518         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16519                         keyword, "config");
16520 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16521         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16522                         port_id, UINT16);
16523 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16524         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16525                         item, "tx_metadata");
16526 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16527         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16528                         value, UINT32);
16529
16530 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16531         .f = cmd_config_tx_metadata_specific_parsed,
16532         .data = NULL,
16533         .help_str = "port config <port_id> tx_metadata <value>",
16534         .tokens = {
16535                 (void *)&cmd_config_tx_metadata_specific_port,
16536                 (void *)&cmd_config_tx_metadata_specific_keyword,
16537                 (void *)&cmd_config_tx_metadata_specific_id,
16538                 (void *)&cmd_config_tx_metadata_specific_item,
16539                 (void *)&cmd_config_tx_metadata_specific_value,
16540                 NULL,
16541         },
16542 };
16543
16544 /* *** set dynf *** */
16545 struct cmd_config_tx_dynf_specific_result {
16546         cmdline_fixed_string_t port;
16547         cmdline_fixed_string_t keyword;
16548         uint16_t port_id;
16549         cmdline_fixed_string_t item;
16550         cmdline_fixed_string_t name;
16551         cmdline_fixed_string_t value;
16552 };
16553
16554 static void
16555 cmd_config_dynf_specific_parsed(void *parsed_result,
16556                                 __rte_unused struct cmdline *cl,
16557                                 __rte_unused void *data)
16558 {
16559         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16560         struct rte_mbuf_dynflag desc_flag;
16561         int flag;
16562         uint64_t old_port_flags;
16563
16564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16565                 return;
16566         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16567         if (flag <= 0) {
16568                 if (strlcpy(desc_flag.name, res->name,
16569                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16570                         printf("Flag name too long\n");
16571                         return;
16572                 }
16573                 desc_flag.flags = 0;
16574                 flag = rte_mbuf_dynflag_register(&desc_flag);
16575                 if (flag < 0) {
16576                         printf("Can't register flag\n");
16577                         return;
16578                 }
16579                 strcpy(dynf_names[flag], desc_flag.name);
16580         }
16581         old_port_flags = ports[res->port_id].mbuf_dynf;
16582         if (!strcmp(res->value, "set")) {
16583                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16584                 if (old_port_flags == 0)
16585                         add_tx_dynf_callback(res->port_id);
16586         } else {
16587                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16588                 if (ports[res->port_id].mbuf_dynf == 0)
16589                         remove_tx_dynf_callback(res->port_id);
16590         }
16591 }
16592
16593 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16594         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16595                         keyword, "port");
16596 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16597         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16598                         keyword, "config");
16599 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16600         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16601                         port_id, UINT16);
16602 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16603         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16604                         item, "dynf");
16605 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16606         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16607                         name, NULL);
16608 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16609         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16610                         value, "set#clear");
16611
16612 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16613         .f = cmd_config_dynf_specific_parsed,
16614         .data = NULL,
16615         .help_str = "port config <port id> dynf <name> set|clear",
16616         .tokens = {
16617                 (void *)&cmd_config_tx_dynf_specific_port,
16618                 (void *)&cmd_config_tx_dynf_specific_keyword,
16619                 (void *)&cmd_config_tx_dynf_specific_port_id,
16620                 (void *)&cmd_config_tx_dynf_specific_item,
16621                 (void *)&cmd_config_tx_dynf_specific_name,
16622                 (void *)&cmd_config_tx_dynf_specific_value,
16623                 NULL,
16624         },
16625 };
16626
16627 /* *** display tx_metadata per port configuration *** */
16628 struct cmd_show_tx_metadata_result {
16629         cmdline_fixed_string_t cmd_show;
16630         cmdline_fixed_string_t cmd_port;
16631         cmdline_fixed_string_t cmd_keyword;
16632         portid_t cmd_pid;
16633 };
16634
16635 static void
16636 cmd_show_tx_metadata_parsed(void *parsed_result,
16637                 __rte_unused struct cmdline *cl,
16638                 __rte_unused void *data)
16639 {
16640         struct cmd_show_tx_metadata_result *res = parsed_result;
16641
16642         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16643                 printf("invalid port id %u\n", res->cmd_pid);
16644                 return;
16645         }
16646         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16647                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16648                        ports[res->cmd_pid].tx_metadata);
16649         }
16650 }
16651
16652 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16653         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16654                         cmd_show, "show");
16655 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16656         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16657                         cmd_port, "port");
16658 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16659         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16660                         cmd_pid, UINT16);
16661 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16662         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16663                         cmd_keyword, "tx_metadata");
16664
16665 cmdline_parse_inst_t cmd_show_tx_metadata = {
16666         .f = cmd_show_tx_metadata_parsed,
16667         .data = NULL,
16668         .help_str = "show port <port_id> tx_metadata",
16669         .tokens = {
16670                 (void *)&cmd_show_tx_metadata_show,
16671                 (void *)&cmd_show_tx_metadata_port,
16672                 (void *)&cmd_show_tx_metadata_pid,
16673                 (void *)&cmd_show_tx_metadata_keyword,
16674                 NULL,
16675         },
16676 };
16677
16678 /* *** show fec capability per port configuration *** */
16679 struct cmd_show_fec_capability_result {
16680         cmdline_fixed_string_t cmd_show;
16681         cmdline_fixed_string_t cmd_port;
16682         cmdline_fixed_string_t cmd_fec;
16683         cmdline_fixed_string_t cmd_keyword;
16684         portid_t cmd_pid;
16685 };
16686
16687 static void
16688 cmd_show_fec_capability_parsed(void *parsed_result,
16689                 __rte_unused struct cmdline *cl,
16690                 __rte_unused void *data)
16691 {
16692 #define FEC_CAP_NUM 2
16693         struct cmd_show_fec_capability_result *res = parsed_result;
16694         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16695         unsigned int num = FEC_CAP_NUM;
16696         unsigned int ret_num;
16697         int ret;
16698
16699         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16700                 printf("Invalid port id %u\n", res->cmd_pid);
16701                 return;
16702         }
16703
16704         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16705         if (ret == -ENOTSUP) {
16706                 printf("Function not implemented\n");
16707                 return;
16708         } else if (ret < 0) {
16709                 printf("Get FEC capability failed\n");
16710                 return;
16711         }
16712
16713         ret_num = (unsigned int)ret;
16714         show_fec_capability(ret_num, speed_fec_capa);
16715 }
16716
16717 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16718         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16719                         cmd_show, "show");
16720 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16721         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16722                         cmd_port, "port");
16723 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16724         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16725                         cmd_pid, UINT16);
16726 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16727         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16728                         cmd_fec, "fec");
16729 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16730         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16731                         cmd_keyword, "capabilities");
16732
16733 cmdline_parse_inst_t cmd_show_capability = {
16734         .f = cmd_show_fec_capability_parsed,
16735         .data = NULL,
16736         .help_str = "show port <port_id> fec capabilities",
16737         .tokens = {
16738                 (void *)&cmd_show_fec_capability_show,
16739                 (void *)&cmd_show_fec_capability_port,
16740                 (void *)&cmd_show_fec_capability_pid,
16741                 (void *)&cmd_show_fec_capability_fec,
16742                 (void *)&cmd_show_fec_capability_keyword,
16743                 NULL,
16744         },
16745 };
16746
16747 /* *** show fec mode per port configuration *** */
16748 struct cmd_show_fec_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_fec_mode_parsed(void *parsed_result,
16757                 __rte_unused struct cmdline *cl,
16758                 __rte_unused void *data)
16759 {
16760 #define FEC_NAME_SIZE 16
16761         struct cmd_show_fec_metadata_result *res = parsed_result;
16762         uint32_t mode;
16763         char buf[FEC_NAME_SIZE];
16764         int ret;
16765
16766         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16767                 printf("Invalid port id %u\n", res->cmd_pid);
16768                 return;
16769         }
16770         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16771         if (ret == -ENOTSUP) {
16772                 printf("Function not implemented\n");
16773                 return;
16774         } else if (ret < 0) {
16775                 printf("Get FEC mode failed\n");
16776                 return;
16777         }
16778
16779         switch (mode) {
16780         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16781                 strlcpy(buf, "off", sizeof(buf));
16782                 break;
16783         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16784                 strlcpy(buf, "auto", sizeof(buf));
16785                 break;
16786         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16787                 strlcpy(buf, "baser", sizeof(buf));
16788                 break;
16789         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16790                 strlcpy(buf, "rs", sizeof(buf));
16791                 break;
16792         default:
16793                 return;
16794         }
16795
16796         printf("%s\n", buf);
16797 }
16798
16799 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16800         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16801                         cmd_show, "show");
16802 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16803         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16804                         cmd_port, "port");
16805 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16806         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16807                         cmd_pid, UINT16);
16808 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16809         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16810                         cmd_keyword, "fec_mode");
16811
16812 cmdline_parse_inst_t cmd_show_fec_mode = {
16813         .f = cmd_show_fec_mode_parsed,
16814         .data = NULL,
16815         .help_str = "show port <port_id> fec_mode",
16816         .tokens = {
16817                 (void *)&cmd_show_fec_mode_show,
16818                 (void *)&cmd_show_fec_mode_port,
16819                 (void *)&cmd_show_fec_mode_pid,
16820                 (void *)&cmd_show_fec_mode_keyword,
16821                 NULL,
16822         },
16823 };
16824
16825 /* *** set fec mode per port configuration *** */
16826 struct cmd_set_port_fec_mode {
16827         cmdline_fixed_string_t set;
16828         cmdline_fixed_string_t port;
16829         portid_t port_id;
16830         cmdline_fixed_string_t fec_mode;
16831         cmdline_fixed_string_t fec_value;
16832 };
16833
16834 /* Common CLI fields for set fec mode */
16835 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16836         TOKEN_STRING_INITIALIZER
16837                 (struct cmd_set_port_fec_mode,
16838                  set, "set");
16839 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16840         TOKEN_STRING_INITIALIZER
16841                 (struct cmd_set_port_fec_mode,
16842                  port, "port");
16843 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16844         TOKEN_NUM_INITIALIZER
16845                 (struct cmd_set_port_fec_mode,
16846                  port_id, UINT16);
16847 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16848         TOKEN_STRING_INITIALIZER
16849                 (struct cmd_set_port_fec_mode,
16850                  fec_mode, "fec_mode");
16851 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16852         TOKEN_STRING_INITIALIZER
16853                 (struct cmd_set_port_fec_mode,
16854                  fec_value, NULL);
16855
16856 static void
16857 cmd_set_port_fec_mode_parsed(
16858         void *parsed_result,
16859         __rte_unused struct cmdline *cl,
16860         __rte_unused void *data)
16861 {
16862         struct cmd_set_port_fec_mode *res = parsed_result;
16863         uint16_t port_id = res->port_id;
16864         uint32_t mode;
16865         int ret;
16866
16867         ret = parse_fec_mode(res->fec_value, &mode);
16868         if (ret < 0) {
16869                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16870                         port_id);
16871                 return;
16872         }
16873
16874         ret = rte_eth_fec_set(port_id, mode);
16875         if (ret == -ENOTSUP) {
16876                 printf("Function not implemented\n");
16877                 return;
16878         } else if (ret < 0) {
16879                 printf("Set FEC mode failed\n");
16880                 return;
16881         }
16882 }
16883
16884 cmdline_parse_inst_t cmd_set_fec_mode = {
16885         .f = cmd_set_port_fec_mode_parsed,
16886         .data = NULL,
16887         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16888         .tokens = {
16889                 (void *)&cmd_set_port_fec_mode_set,
16890                 (void *)&cmd_set_port_fec_mode_port,
16891                 (void *)&cmd_set_port_fec_mode_port_id,
16892                 (void *)&cmd_set_port_fec_mode_str,
16893                 (void *)&cmd_set_port_fec_mode_value,
16894                 NULL,
16895         },
16896 };
16897
16898 /* show port supported ptypes */
16899
16900 /* Common result structure for show port ptypes */
16901 struct cmd_show_port_supported_ptypes_result {
16902         cmdline_fixed_string_t show;
16903         cmdline_fixed_string_t port;
16904         portid_t port_id;
16905         cmdline_fixed_string_t ptypes;
16906 };
16907
16908 /* Common CLI fields for show port ptypes */
16909 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16910         TOKEN_STRING_INITIALIZER
16911                 (struct cmd_show_port_supported_ptypes_result,
16912                  show, "show");
16913 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16914         TOKEN_STRING_INITIALIZER
16915                 (struct cmd_show_port_supported_ptypes_result,
16916                  port, "port");
16917 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16918         TOKEN_NUM_INITIALIZER
16919                 (struct cmd_show_port_supported_ptypes_result,
16920                  port_id, UINT16);
16921 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16922         TOKEN_STRING_INITIALIZER
16923                 (struct cmd_show_port_supported_ptypes_result,
16924                  ptypes, "ptypes");
16925
16926 static void
16927 cmd_show_port_supported_ptypes_parsed(
16928         void *parsed_result,
16929         __rte_unused struct cmdline *cl,
16930         __rte_unused void *data)
16931 {
16932 #define RSVD_PTYPE_MASK       0xf0000000
16933 #define MAX_PTYPES_PER_LAYER  16
16934 #define LTYPE_NAMESIZE        32
16935 #define PTYPE_NAMESIZE        256
16936         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16937         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16938         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16939         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16940         uint16_t port_id = res->port_id;
16941         int ret, i;
16942
16943         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16944         if (ret < 0)
16945                 return;
16946
16947         while (ptype_mask != RSVD_PTYPE_MASK) {
16948
16949                 switch (ptype_mask) {
16950                 case RTE_PTYPE_L2_MASK:
16951                         strlcpy(ltype, "L2", sizeof(ltype));
16952                         break;
16953                 case RTE_PTYPE_L3_MASK:
16954                         strlcpy(ltype, "L3", sizeof(ltype));
16955                         break;
16956                 case RTE_PTYPE_L4_MASK:
16957                         strlcpy(ltype, "L4", sizeof(ltype));
16958                         break;
16959                 case RTE_PTYPE_TUNNEL_MASK:
16960                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16961                         break;
16962                 case RTE_PTYPE_INNER_L2_MASK:
16963                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16964                         break;
16965                 case RTE_PTYPE_INNER_L3_MASK:
16966                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16967                         break;
16968                 case RTE_PTYPE_INNER_L4_MASK:
16969                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16970                         break;
16971                 default:
16972                         return;
16973                 }
16974
16975                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16976                                                        ptype_mask, ptypes,
16977                                                        MAX_PTYPES_PER_LAYER);
16978
16979                 if (ret > 0)
16980                         printf("Supported %s ptypes:\n", ltype);
16981                 else
16982                         printf("%s ptypes unsupported\n", ltype);
16983
16984                 for (i = 0; i < ret; ++i) {
16985                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16986                         printf("%s\n", buf);
16987                 }
16988
16989                 ptype_mask <<= 4;
16990         }
16991 }
16992
16993 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16994         .f = cmd_show_port_supported_ptypes_parsed,
16995         .data = NULL,
16996         .help_str = "show port <port_id> ptypes",
16997         .tokens = {
16998                 (void *)&cmd_show_port_supported_ptypes_show,
16999                 (void *)&cmd_show_port_supported_ptypes_port,
17000                 (void *)&cmd_show_port_supported_ptypes_port_id,
17001                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17002                 NULL,
17003         },
17004 };
17005
17006 /* *** display rx/tx descriptor status *** */
17007 struct cmd_show_rx_tx_desc_status_result {
17008         cmdline_fixed_string_t cmd_show;
17009         cmdline_fixed_string_t cmd_port;
17010         cmdline_fixed_string_t cmd_keyword;
17011         cmdline_fixed_string_t cmd_desc;
17012         cmdline_fixed_string_t cmd_status;
17013         portid_t cmd_pid;
17014         portid_t cmd_qid;
17015         portid_t cmd_did;
17016 };
17017
17018 static void
17019 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17020                 __rte_unused struct cmdline *cl,
17021                 __rte_unused void *data)
17022 {
17023         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17024         int rc;
17025
17026         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17027                 printf("invalid port id %u\n", res->cmd_pid);
17028                 return;
17029         }
17030
17031         if (!strcmp(res->cmd_keyword, "rxq")) {
17032                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17033                                              res->cmd_did);
17034                 if (rc < 0) {
17035                         printf("Invalid queueid = %d\n", res->cmd_qid);
17036                         return;
17037                 }
17038                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17039                         printf("Desc status = AVAILABLE\n");
17040                 else if (rc == RTE_ETH_RX_DESC_DONE)
17041                         printf("Desc status = DONE\n");
17042                 else
17043                         printf("Desc status = UNAVAILABLE\n");
17044         } else if (!strcmp(res->cmd_keyword, "txq")) {
17045                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17046                                              res->cmd_did);
17047                 if (rc < 0) {
17048                         printf("Invalid queueid = %d\n", res->cmd_qid);
17049                         return;
17050                 }
17051                 if (rc == RTE_ETH_TX_DESC_FULL)
17052                         printf("Desc status = FULL\n");
17053                 else if (rc == RTE_ETH_TX_DESC_DONE)
17054                         printf("Desc status = DONE\n");
17055                 else
17056                         printf("Desc status = UNAVAILABLE\n");
17057         }
17058 }
17059
17060 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17061         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17062                         cmd_show, "show");
17063 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17064         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17065                         cmd_port, "port");
17066 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17067         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17068                         cmd_pid, UINT16);
17069 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17070         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17071                         cmd_keyword, "rxq#txq");
17072 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17073         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17074                         cmd_qid, UINT16);
17075 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17076         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17077                         cmd_desc, "desc");
17078 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17079         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17080                         cmd_did, UINT16);
17081 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17082         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17083                         cmd_status, "status");
17084 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17085         .f = cmd_show_rx_tx_desc_status_parsed,
17086         .data = NULL,
17087         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17088                 "status",
17089         .tokens = {
17090                 (void *)&cmd_show_rx_tx_desc_status_show,
17091                 (void *)&cmd_show_rx_tx_desc_status_port,
17092                 (void *)&cmd_show_rx_tx_desc_status_pid,
17093                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17094                 (void *)&cmd_show_rx_tx_desc_status_qid,
17095                 (void *)&cmd_show_rx_tx_desc_status_desc,
17096                 (void *)&cmd_show_rx_tx_desc_status_did,
17097                 (void *)&cmd_show_rx_tx_desc_status_status,
17098                 NULL,
17099         },
17100 };
17101
17102 /* Common result structure for set port ptypes */
17103 struct cmd_set_port_ptypes_result {
17104         cmdline_fixed_string_t set;
17105         cmdline_fixed_string_t port;
17106         portid_t port_id;
17107         cmdline_fixed_string_t ptype_mask;
17108         uint32_t mask;
17109 };
17110
17111 /* Common CLI fields for set port ptypes */
17112 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17113         TOKEN_STRING_INITIALIZER
17114                 (struct cmd_set_port_ptypes_result,
17115                  set, "set");
17116 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17117         TOKEN_STRING_INITIALIZER
17118                 (struct cmd_set_port_ptypes_result,
17119                  port, "port");
17120 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17121         TOKEN_NUM_INITIALIZER
17122                 (struct cmd_set_port_ptypes_result,
17123                  port_id, UINT16);
17124 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17125         TOKEN_STRING_INITIALIZER
17126                 (struct cmd_set_port_ptypes_result,
17127                  ptype_mask, "ptype_mask");
17128 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17129         TOKEN_NUM_INITIALIZER
17130                 (struct cmd_set_port_ptypes_result,
17131                  mask, UINT32);
17132
17133 static void
17134 cmd_set_port_ptypes_parsed(
17135         void *parsed_result,
17136         __rte_unused struct cmdline *cl,
17137         __rte_unused void *data)
17138 {
17139         struct cmd_set_port_ptypes_result *res = parsed_result;
17140 #define PTYPE_NAMESIZE        256
17141         char ptype_name[PTYPE_NAMESIZE];
17142         uint16_t port_id = res->port_id;
17143         uint32_t ptype_mask = res->mask;
17144         int ret, i;
17145
17146         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17147                                                NULL, 0);
17148         if (ret <= 0) {
17149                 printf("Port %d doesn't support any ptypes.\n", port_id);
17150                 return;
17151         }
17152
17153         uint32_t ptypes[ret];
17154
17155         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17156         if (ret < 0) {
17157                 printf("Unable to set requested ptypes for Port %d\n", port_id);
17158                 return;
17159         }
17160
17161         printf("Successfully set following ptypes for Port %d\n", port_id);
17162         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17163                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17164                 printf("%s\n", ptype_name);
17165         }
17166
17167         clear_ptypes = false;
17168 }
17169
17170 cmdline_parse_inst_t cmd_set_port_ptypes = {
17171         .f = cmd_set_port_ptypes_parsed,
17172         .data = NULL,
17173         .help_str = "set port <port_id> ptype_mask <mask>",
17174         .tokens = {
17175                 (void *)&cmd_set_port_ptypes_set,
17176                 (void *)&cmd_set_port_ptypes_port,
17177                 (void *)&cmd_set_port_ptypes_port_id,
17178                 (void *)&cmd_set_port_ptypes_mask_str,
17179                 (void *)&cmd_set_port_ptypes_mask_u32,
17180                 NULL,
17181         },
17182 };
17183
17184 /* *** display mac addresses added to a port *** */
17185 struct cmd_showport_macs_result {
17186         cmdline_fixed_string_t cmd_show;
17187         cmdline_fixed_string_t cmd_port;
17188         cmdline_fixed_string_t cmd_keyword;
17189         portid_t cmd_pid;
17190 };
17191
17192 static void
17193 cmd_showport_macs_parsed(void *parsed_result,
17194                 __rte_unused struct cmdline *cl,
17195                 __rte_unused void *data)
17196 {
17197         struct cmd_showport_macs_result *res = parsed_result;
17198
17199         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17200                 return;
17201
17202         if (!strcmp(res->cmd_keyword, "macs"))
17203                 show_macs(res->cmd_pid);
17204         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17205                 show_mcast_macs(res->cmd_pid);
17206 }
17207
17208 cmdline_parse_token_string_t cmd_showport_macs_show =
17209         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17210                         cmd_show, "show");
17211 cmdline_parse_token_string_t cmd_showport_macs_port =
17212         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17213                         cmd_port, "port");
17214 cmdline_parse_token_num_t cmd_showport_macs_pid =
17215         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17216                         cmd_pid, UINT16);
17217 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17218         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17219                         cmd_keyword, "macs#mcast_macs");
17220
17221 cmdline_parse_inst_t cmd_showport_macs = {
17222         .f = cmd_showport_macs_parsed,
17223         .data = NULL,
17224         .help_str = "show port <port_id> macs|mcast_macs",
17225         .tokens = {
17226                 (void *)&cmd_showport_macs_show,
17227                 (void *)&cmd_showport_macs_port,
17228                 (void *)&cmd_showport_macs_pid,
17229                 (void *)&cmd_showport_macs_keyword,
17230                 NULL,
17231         },
17232 };
17233
17234 /* ******************************************************************************** */
17235
17236 /* list of instructions */
17237 cmdline_parse_ctx_t main_ctx[] = {
17238         (cmdline_parse_inst_t *)&cmd_help_brief,
17239         (cmdline_parse_inst_t *)&cmd_help_long,
17240         (cmdline_parse_inst_t *)&cmd_quit,
17241         (cmdline_parse_inst_t *)&cmd_load_from_file,
17242         (cmdline_parse_inst_t *)&cmd_showport,
17243         (cmdline_parse_inst_t *)&cmd_showqueue,
17244         (cmdline_parse_inst_t *)&cmd_showeeprom,
17245         (cmdline_parse_inst_t *)&cmd_showportall,
17246         (cmdline_parse_inst_t *)&cmd_showdevice,
17247         (cmdline_parse_inst_t *)&cmd_showcfg,
17248         (cmdline_parse_inst_t *)&cmd_showfwdall,
17249         (cmdline_parse_inst_t *)&cmd_start,
17250         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17251         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17252         (cmdline_parse_inst_t *)&cmd_set_link_up,
17253         (cmdline_parse_inst_t *)&cmd_set_link_down,
17254         (cmdline_parse_inst_t *)&cmd_reset,
17255         (cmdline_parse_inst_t *)&cmd_set_numbers,
17256         (cmdline_parse_inst_t *)&cmd_set_log,
17257         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17258         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17259         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17260         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17261         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17262         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17263         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17264         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17265         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17266         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17267         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17268         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17269         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17270         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17271         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17272         (cmdline_parse_inst_t *)&cmd_set_link_check,
17273         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17274         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17275         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17276         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17277 #ifdef RTE_NET_BOND
17278         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17279         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17280         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17281         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17282         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17283         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17284         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17285         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17286         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17287         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17288         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17289 #endif
17290         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17291         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17292         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17293         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17294         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17295         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17296         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17297         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17298         (cmdline_parse_inst_t *)&cmd_csum_set,
17299         (cmdline_parse_inst_t *)&cmd_csum_show,
17300         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17301         (cmdline_parse_inst_t *)&cmd_tso_set,
17302         (cmdline_parse_inst_t *)&cmd_tso_show,
17303         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17304         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17305         (cmdline_parse_inst_t *)&cmd_gro_enable,
17306         (cmdline_parse_inst_t *)&cmd_gro_flush,
17307         (cmdline_parse_inst_t *)&cmd_gro_show,
17308         (cmdline_parse_inst_t *)&cmd_gso_enable,
17309         (cmdline_parse_inst_t *)&cmd_gso_size,
17310         (cmdline_parse_inst_t *)&cmd_gso_show,
17311         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17312         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17313         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17314         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17315         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17316         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17317         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17318         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17319         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17320         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17321         (cmdline_parse_inst_t *)&cmd_config_dcb,
17322         (cmdline_parse_inst_t *)&cmd_read_reg,
17323         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17324         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17325         (cmdline_parse_inst_t *)&cmd_write_reg,
17326         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17327         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17328         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17329         (cmdline_parse_inst_t *)&cmd_stop,
17330         (cmdline_parse_inst_t *)&cmd_mac_addr,
17331         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17332         (cmdline_parse_inst_t *)&cmd_set_qmap,
17333         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17334         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17335         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17336         (cmdline_parse_inst_t *)&cmd_operate_port,
17337         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17338         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17339         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17340         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17341         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17342         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17343         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17344         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17345         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17346         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17347         (cmdline_parse_inst_t *)&cmd_config_mtu,
17348         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17349         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17350         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17351         (cmdline_parse_inst_t *)&cmd_config_rss,
17352         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17353         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17354         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17355         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17356         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17357         (cmdline_parse_inst_t *)&cmd_showport_reta,
17358         (cmdline_parse_inst_t *)&cmd_showport_macs,
17359         (cmdline_parse_inst_t *)&cmd_config_burst,
17360         (cmdline_parse_inst_t *)&cmd_config_thresh,
17361         (cmdline_parse_inst_t *)&cmd_config_threshold,
17362         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17363         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17364         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17365         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17366         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17367         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17368         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17369         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17370         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17371         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17372         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17373         (cmdline_parse_inst_t *)&cmd_dump,
17374         (cmdline_parse_inst_t *)&cmd_dump_one,
17375 #ifdef RTE_NET_I40E
17376         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17377 #endif
17378         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17379         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17380         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17381         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17382         (cmdline_parse_inst_t *)&cmd_flow,
17383         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17384         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17385         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17386         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17387         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17388         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17389         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17390         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17391         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17392         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17393         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17394         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17395         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17396         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17397         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17398         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17399         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17400         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17401         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17402         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17403         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17404         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17405         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17406         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17407         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17408         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17409         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17410         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17411         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17412         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17413         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17414         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17415         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17416         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17417         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17418         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17419         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17420         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17421         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17422         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17423         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17424         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17425         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17426         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17427         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17428         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17429         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17430         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17431         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17432         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17433         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17434         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17435         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17436         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17437         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17438         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17439         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17440         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17441         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17442         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17443         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17444         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17445         (cmdline_parse_inst_t *)&cmd_ddp_add,
17446         (cmdline_parse_inst_t *)&cmd_ddp_del,
17447         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17448         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17449         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17450         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17451         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17452         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17453         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17454         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17455         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17456         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17457         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17458         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17459
17460         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17461         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17462         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17463         (cmdline_parse_inst_t *)&cmd_queue_region,
17464         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17465         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17466         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17467         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17468         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17469         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17470         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17471         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17472         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17473         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17474         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17475         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17476         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17477         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17478         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17479         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17480         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17481         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17482         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17483         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17484         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17485         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17486         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17487         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17488         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17489         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17490         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17491         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17492         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17493         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17494         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17495         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17496         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17497         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17498         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17499         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17500 #ifdef RTE_LIB_BPF
17501         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17502         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17503 #endif
17504         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17505         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17506         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17507         (cmdline_parse_inst_t *)&cmd_set_raw,
17508         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17509         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17510         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17511         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17512         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17513         (cmdline_parse_inst_t *)&cmd_show_capability,
17514         NULL,
17515 };
17516
17517 /* read cmdline commands from file */
17518 void
17519 cmdline_read_from_file(const char *filename)
17520 {
17521         struct cmdline *cl;
17522
17523         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17524         if (cl == NULL) {
17525                 printf("Failed to create file based cmdline context: %s\n",
17526                        filename);
17527                 return;
17528         }
17529
17530         cmdline_interact(cl);
17531         cmdline_quit(cl);
17532
17533         cmdline_free(cl);
17534
17535         printf("Read CLI commands from %s\n", filename);
17536 }
17537
17538 /* prompt function, called from main on MAIN lcore */
17539 void
17540 prompt(void)
17541 {
17542         /* initialize non-constant commands */
17543         cmd_set_fwd_mode_init();
17544         cmd_set_fwd_retry_mode_init();
17545
17546         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17547         if (testpmd_cl == NULL)
17548                 return;
17549         cmdline_interact(testpmd_cl);
17550         cmdline_stdin_exit(testpmd_cl);
17551 }
17552
17553 void
17554 prompt_exit(void)
17555 {
17556         if (testpmd_cl != NULL)
17557                 cmdline_quit(testpmd_cl);
17558 }
17559
17560 static void
17561 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17562 {
17563         if (id == (portid_t)RTE_PORT_ALL) {
17564                 portid_t pid;
17565
17566                 RTE_ETH_FOREACH_DEV(pid) {
17567                         /* check if need_reconfig has been set to 1 */
17568                         if (ports[pid].need_reconfig == 0)
17569                                 ports[pid].need_reconfig = dev;
17570                         /* check if need_reconfig_queues has been set to 1 */
17571                         if (ports[pid].need_reconfig_queues == 0)
17572                                 ports[pid].need_reconfig_queues = queue;
17573                 }
17574         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17575                 /* check if need_reconfig has been set to 1 */
17576                 if (ports[id].need_reconfig == 0)
17577                         ports[id].need_reconfig = dev;
17578                 /* check if need_reconfig_queues has been set to 1 */
17579                 if (ports[id].need_reconfig_queues == 0)
17580                         ports[id].need_reconfig_queues = queue;
17581         }
17582 }