5e2881edf7be258f565ed3646d1c222a36434a19
[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                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) ptype_mask (ptype_mask)\n"
672                         "    set packet types classification for a specific port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         "set port (port_id) fec_mode auto|off|rs|baser\n"
737                         "    set fec mode for a specific port\n\n"
738
739                         , list_pkt_forwarding_modes()
740                 );
741         }
742
743         if (show_all || !strcmp(res->section, "ports")) {
744
745                 cmdline_printf(
746                         cl,
747                         "\n"
748                         "Port Operations:\n"
749                         "----------------\n\n"
750
751                         "port start (port_id|all)\n"
752                         "    Start all ports or port_id.\n\n"
753
754                         "port stop (port_id|all)\n"
755                         "    Stop all ports or port_id.\n\n"
756
757                         "port close (port_id|all)\n"
758                         "    Close all ports or port_id.\n\n"
759
760                         "port reset (port_id|all)\n"
761                         "    Reset all ports or port_id.\n\n"
762
763                         "port attach (ident)\n"
764                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
765
766                         "port detach (port_id)\n"
767                         "    Detach physical or virtual dev by port_id\n\n"
768
769                         "port config (port_id|all)"
770                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
771                         " duplex (half|full|auto)\n"
772                         "    Set speed and duplex for all ports or port_id\n\n"
773
774                         "port config (port_id|all) loopback (mode)\n"
775                         "    Set loopback mode for all ports or port_id\n\n"
776
777                         "port config all (rxq|txq|rxd|txd) (value)\n"
778                         "    Set number for rxq/txq/rxd/txd.\n\n"
779
780                         "port config all max-pkt-len (value)\n"
781                         "    Set the max packet length.\n\n"
782
783                         "port config all max-lro-pkt-size (value)\n"
784                         "    Set the max LRO aggregated packet size.\n\n"
785
786                         "port config all drop-en (on|off)\n"
787                         "    Enable or disable packet drop on all RX queues of all ports when no "
788                         "receive buffers available.\n\n"
789
790                         "port config all rss (all|default|ip|tcp|udp|sctp|"
791                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
792                         "level-outer|level-inner|<flowtype_id>)\n"
793                         "    Set the RSS mode.\n\n"
794
795                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
796                         "    Set the RSS redirection table.\n\n"
797
798                         "port config (port_id) dcb vt (on|off) (traffic_class)"
799                         " pfc (on|off)\n"
800                         "    Set the DCB mode.\n\n"
801
802                         "port config all burst (value)\n"
803                         "    Set the number of packets per burst.\n\n"
804
805                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
806                         " (value)\n"
807                         "    Set the ring prefetch/host/writeback threshold"
808                         " for tx/rx queue.\n\n"
809
810                         "port config all (txfreet|txrst|rxfreet) (value)\n"
811                         "    Set free threshold for rx/tx, or set"
812                         " tx rs bit threshold.\n\n"
813                         "port config mtu X value\n"
814                         "    Set the MTU of port X to a given value\n\n"
815
816                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
817                         "    Set a rx/tx queue's ring size configuration, the new"
818                         " value will take effect after command that (re-)start the port"
819                         " or command that setup the specific queue\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
822                         "    Start/stop a rx/tx queue of port X. Only take effect"
823                         " when port X is started\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
826                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
827                         " take effect when port X is stopped.\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) setup\n"
830                         "    Setup a rx/tx queue of port X.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
855                         "buffer_split|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
863                         "buffer_split|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896
897                         "port config (port_id) dynf (name) set|clear\n"
898                         "    Register a dynf and Set/clear this flag on Tx. "
899                         "Testpmd will set this value to any Tx packet "
900                         "sent from this port\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940 #ifdef RTE_NET_I40E
941                         "flow_director_filter (port_id) mode raw (add|del|update)"
942                         " flow (flow_id) (drop|fwd) queue (queue_id)"
943                         " fd_id (fd_id_value) packet (packet file name)\n"
944                         "    Add/Del a raw type flow director filter.\n\n"
945 #endif
946
947                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
948                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
949                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
950                         "    Set flow director IP mask.\n\n"
951
952                         "flow_director_mask (port_id) mode MAC-VLAN"
953                         " vlan (vlan_value)\n"
954                         "    Set flow director MAC-VLAN mask.\n\n"
955
956                         "flow_director_mask (port_id) mode Tunnel"
957                         " vlan (vlan_value) mac (mac_value)"
958                         " tunnel-type (tunnel_type_value)"
959                         " tunnel-id (tunnel_id_value)\n"
960                         "    Set flow director Tunnel mask.\n\n"
961
962                         "flow_director_flex_payload (port_id)"
963                         " (raw|l2|l3|l4) (config)\n"
964                         "    Configure flex payload selection.\n\n"
965
966                         "flow validate {port_id}"
967                         " [group {group_id}] [priority {level}]"
968                         " [ingress] [egress]"
969                         " pattern {item} [/ {item} [...]] / end"
970                         " actions {action} [/ {action} [...]] / end\n"
971                         "    Check whether a flow rule can be created.\n\n"
972
973                         "flow create {port_id}"
974                         " [group {group_id}] [priority {level}]"
975                         " [ingress] [egress]"
976                         " pattern {item} [/ {item} [...]] / end"
977                         " actions {action} [/ {action} [...]] / end\n"
978                         "    Create a flow rule.\n\n"
979
980                         "flow destroy {port_id} rule {rule_id} [...]\n"
981                         "    Destroy specific flow rules.\n\n"
982
983                         "flow flush {port_id}\n"
984                         "    Destroy all flow rules.\n\n"
985
986                         "flow query {port_id} {rule_id} {action}\n"
987                         "    Query an existing flow rule.\n\n"
988
989                         "flow list {port_id} [group {group_id}] [...]\n"
990                         "    List existing flow rules sorted by priority,"
991                         " filtered by group identifiers.\n\n"
992
993                         "flow isolate {port_id} {boolean}\n"
994                         "    Restrict ingress traffic to the defined"
995                         " flow rules\n\n"
996
997                         "flow aged {port_id} [destroy]\n"
998                         "    List and destroy aged flows"
999                         " flow rules\n\n"
1000
1001                         "flow shared_action {port_id} create"
1002                         " [action_id {shared_action_id}]"
1003                         " [ingress] [egress]"
1004                         " action {action} / end\n"
1005                         "    Create shared action.\n\n"
1006
1007                         "flow shared_action {port_id} update"
1008                         " {shared_action_id} action {action} / end\n"
1009                         "    Update shared action.\n\n"
1010
1011                         "flow shared_action {port_id} destroy"
1012                         " action_id {shared_action_id} [...]\n"
1013                         "    Destroy specific shared actions.\n\n"
1014
1015                         "flow shared_action {port_id} query"
1016                         " {shared_action_id}\n"
1017                         "    Query an existing shared action.\n\n"
1018
1019                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1020                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1021                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1022                         "       Configure the VXLAN encapsulation for flows.\n\n"
1023
1024                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1025                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1026                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1027                         " eth-dst (eth-dst)\n"
1028                         "       Configure the VXLAN encapsulation for flows.\n\n"
1029
1030                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1031                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1032                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1033                         " eth-dst (eth-dst)\n"
1034                         "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1037                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1038                         " (eth-dst)\n"
1039                         "       Configure the NVGRE encapsulation for flows.\n\n"
1040
1041                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1043                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set raw_encap {flow items}\n"
1047                         "       Configure the encapsulation with raw data.\n\n"
1048
1049                         "set raw_decap {flow items}\n"
1050                         "       Configure the decapsulation with raw data.\n\n"
1051
1052                 );
1053         }
1054
1055         if (show_all || !strcmp(res->section, "traffic_management")) {
1056                 cmdline_printf(
1057                         cl,
1058                         "\n"
1059                         "Traffic Management:\n"
1060                         "--------------\n"
1061                         "show port tm cap (port_id)\n"
1062                         "       Display the port TM capability.\n\n"
1063
1064                         "show port tm level cap (port_id) (level_id)\n"
1065                         "       Display the port TM hierarchical level capability.\n\n"
1066
1067                         "show port tm node cap (port_id) (node_id)\n"
1068                         "       Display the port TM node capability.\n\n"
1069
1070                         "show port tm node type (port_id) (node_id)\n"
1071                         "       Display the port TM node type.\n\n"
1072
1073                         "show port tm node stats (port_id) (node_id) (clear)\n"
1074                         "       Display the port TM node stats.\n\n"
1075
1076                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1077                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1078                         " (packet_length_adjust) (packet_mode)\n"
1079                         "       Add port tm node private shaper profile.\n\n"
1080
1081                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1082                         "       Delete port tm node private shaper profile.\n\n"
1083
1084                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1085                         " (shaper_profile_id)\n"
1086                         "       Add/update port tm node shared shaper.\n\n"
1087
1088                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1089                         "       Delete port tm node shared shaper.\n\n"
1090
1091                         "set port tm node shaper profile (port_id) (node_id)"
1092                         " (shaper_profile_id)\n"
1093                         "       Set port tm node shaper profile.\n\n"
1094
1095                         "add port tm node wred profile (port_id) (wred_profile_id)"
1096                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1097                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1098                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1099                         "       Add port tm node wred profile.\n\n"
1100
1101                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1102                         "       Delete port tm node wred profile.\n\n"
1103
1104                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1105                         " (priority) (weight) (level_id) (shaper_profile_id)"
1106                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1107                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1108                         "       Add port tm nonleaf node.\n\n"
1109
1110                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1111                         " (priority) (weight) (level_id) (shaper_profile_id)"
1112                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1113                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1114                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1115
1116                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1117                         " (priority) (weight) (level_id) (shaper_profile_id)"
1118                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1119                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                         "       Add port tm leaf node.\n\n"
1121
1122                         "del port tm node (port_id) (node_id)\n"
1123                         "       Delete port tm node.\n\n"
1124
1125                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1126                         " (priority) (weight)\n"
1127                         "       Set port tm node parent.\n\n"
1128
1129                         "suspend port tm node (port_id) (node_id)"
1130                         "       Suspend tm node.\n\n"
1131
1132                         "resume port tm node (port_id) (node_id)"
1133                         "       Resume tm node.\n\n"
1134
1135                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1136                         "       Commit tm hierarchy.\n\n"
1137
1138                         "set port tm mark ip_ecn (port) (green) (yellow)"
1139                         " (red)\n"
1140                         "    Enables/Disables the traffic management marking"
1141                         " for IP ECN (Explicit Congestion Notification)"
1142                         " packets on a given port\n\n"
1143
1144                         "set port tm mark ip_dscp (port) (green) (yellow)"
1145                         " (red)\n"
1146                         "    Enables/Disables the traffic management marking"
1147                         " on the port for IP dscp packets\n\n"
1148
1149                         "set port tm mark vlan_dei (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for VLAN packets with DEI enabled\n\n"
1153                 );
1154         }
1155
1156         if (show_all || !strcmp(res->section, "devices")) {
1157                 cmdline_printf(
1158                         cl,
1159                         "\n"
1160                         "Device Operations:\n"
1161                         "--------------\n"
1162                         "device detach (identifier)\n"
1163                         "       Detach device by identifier.\n\n"
1164                 );
1165         }
1166
1167 }
1168
1169 cmdline_parse_token_string_t cmd_help_long_help =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1171
1172 cmdline_parse_token_string_t cmd_help_long_section =
1173         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1174                         "all#control#display#config#"
1175                         "ports#registers#filters#traffic_management#devices");
1176
1177 cmdline_parse_inst_t cmd_help_long = {
1178         .f = cmd_help_long_parsed,
1179         .data = NULL,
1180         .help_str = "help all|control|display|config|ports|register|"
1181                 "filters|traffic_management|devices: "
1182                 "Show help",
1183         .tokens = {
1184                 (void *)&cmd_help_long_help,
1185                 (void *)&cmd_help_long_section,
1186                 NULL,
1187         },
1188 };
1189
1190
1191 /* *** start/stop/close all ports *** */
1192 struct cmd_operate_port_result {
1193         cmdline_fixed_string_t keyword;
1194         cmdline_fixed_string_t name;
1195         cmdline_fixed_string_t value;
1196 };
1197
1198 static void cmd_operate_port_parsed(void *parsed_result,
1199                                 __rte_unused struct cmdline *cl,
1200                                 __rte_unused void *data)
1201 {
1202         struct cmd_operate_port_result *res = parsed_result;
1203
1204         if (!strcmp(res->name, "start"))
1205                 start_port(RTE_PORT_ALL);
1206         else if (!strcmp(res->name, "stop"))
1207                 stop_port(RTE_PORT_ALL);
1208         else if (!strcmp(res->name, "close"))
1209                 close_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "reset"))
1211                 reset_port(RTE_PORT_ALL);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1218                                                                 "port");
1219 cmdline_parse_token_string_t cmd_operate_port_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1221                                                 "start#stop#close#reset");
1222 cmdline_parse_token_string_t cmd_operate_port_all_all =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1224
1225 cmdline_parse_inst_t cmd_operate_port = {
1226         .f = cmd_operate_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1229         .tokens = {
1230                 (void *)&cmd_operate_port_all_cmd,
1231                 (void *)&cmd_operate_port_all_port,
1232                 (void *)&cmd_operate_port_all_all,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** start/stop/close specific port *** */
1238 struct cmd_operate_specific_port_result {
1239         cmdline_fixed_string_t keyword;
1240         cmdline_fixed_string_t name;
1241         uint8_t value;
1242 };
1243
1244 static void cmd_operate_specific_port_parsed(void *parsed_result,
1245                         __rte_unused struct cmdline *cl,
1246                                 __rte_unused void *data)
1247 {
1248         struct cmd_operate_specific_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->name, "start"))
1251                 start_port(res->value);
1252         else if (!strcmp(res->name, "stop"))
1253                 stop_port(res->value);
1254         else if (!strcmp(res->name, "close"))
1255                 close_port(res->value);
1256         else if (!strcmp(res->name, "reset"))
1257                 reset_port(res->value);
1258         else
1259                 printf("Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                         keyword, "port");
1265 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                 name, "start#stop#close#reset");
1268 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1269         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1270                                                         value, RTE_UINT8);
1271
1272 cmdline_parse_inst_t cmd_operate_specific_port = {
1273         .f = cmd_operate_specific_port_parsed,
1274         .data = NULL,
1275         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1276         .tokens = {
1277                 (void *)&cmd_operate_specific_port_cmd,
1278                 (void *)&cmd_operate_specific_port_port,
1279                 (void *)&cmd_operate_specific_port_id,
1280                 NULL,
1281         },
1282 };
1283
1284 /* *** enable port setup (after attach) via iterator or event *** */
1285 struct cmd_set_port_setup_on_result {
1286         cmdline_fixed_string_t set;
1287         cmdline_fixed_string_t port;
1288         cmdline_fixed_string_t setup;
1289         cmdline_fixed_string_t on;
1290         cmdline_fixed_string_t mode;
1291 };
1292
1293 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1294                                 __rte_unused struct cmdline *cl,
1295                                 __rte_unused void *data)
1296 {
1297         struct cmd_set_port_setup_on_result *res = parsed_result;
1298
1299         if (strcmp(res->mode, "event") == 0)
1300                 setup_on_probe_event = true;
1301         else if (strcmp(res->mode, "iterator") == 0)
1302                 setup_on_probe_event = false;
1303         else
1304                 printf("Unknown mode\n");
1305 }
1306
1307 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1308         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1309                         set, "set");
1310 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1311         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1312                         port, "port");
1313 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1314         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1315                         setup, "setup");
1316 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1317         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1318                         on, "on");
1319 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1320         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1321                         mode, "iterator#event");
1322
1323 cmdline_parse_inst_t cmd_set_port_setup_on = {
1324         .f = cmd_set_port_setup_on_parsed,
1325         .data = NULL,
1326         .help_str = "set port setup on iterator|event",
1327         .tokens = {
1328                 (void *)&cmd_set_port_setup_on_set,
1329                 (void *)&cmd_set_port_setup_on_port,
1330                 (void *)&cmd_set_port_setup_on_setup,
1331                 (void *)&cmd_set_port_setup_on_on,
1332                 (void *)&cmd_set_port_setup_on_mode,
1333                 NULL,
1334         },
1335 };
1336
1337 /* *** attach a specified port *** */
1338 struct cmd_operate_attach_port_result {
1339         cmdline_fixed_string_t port;
1340         cmdline_fixed_string_t keyword;
1341         cmdline_multi_string_t identifier;
1342 };
1343
1344 static void cmd_operate_attach_port_parsed(void *parsed_result,
1345                                 __rte_unused struct cmdline *cl,
1346                                 __rte_unused void *data)
1347 {
1348         struct cmd_operate_attach_port_result *res = parsed_result;
1349
1350         if (!strcmp(res->keyword, "attach"))
1351                 attach_port(res->identifier);
1352         else
1353                 printf("Unknown parameter\n");
1354 }
1355
1356 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1357         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1358                         port, "port");
1359 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1360         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1361                         keyword, "attach");
1362 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1363         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1364                         identifier, TOKEN_STRING_MULTI);
1365
1366 cmdline_parse_inst_t cmd_operate_attach_port = {
1367         .f = cmd_operate_attach_port_parsed,
1368         .data = NULL,
1369         .help_str = "port attach <identifier>: "
1370                 "(identifier: pci address or virtual dev name)",
1371         .tokens = {
1372                 (void *)&cmd_operate_attach_port_port,
1373                 (void *)&cmd_operate_attach_port_keyword,
1374                 (void *)&cmd_operate_attach_port_identifier,
1375                 NULL,
1376         },
1377 };
1378
1379 /* *** detach a specified port *** */
1380 struct cmd_operate_detach_port_result {
1381         cmdline_fixed_string_t port;
1382         cmdline_fixed_string_t keyword;
1383         portid_t port_id;
1384 };
1385
1386 static void cmd_operate_detach_port_parsed(void *parsed_result,
1387                                 __rte_unused struct cmdline *cl,
1388                                 __rte_unused void *data)
1389 {
1390         struct cmd_operate_detach_port_result *res = parsed_result;
1391
1392         if (!strcmp(res->keyword, "detach")) {
1393                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1394                 detach_port_device(res->port_id);
1395         } else {
1396                 printf("Unknown parameter\n");
1397         }
1398 }
1399
1400 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1401         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1402                         port, "port");
1403 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1404         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1405                         keyword, "detach");
1406 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1407         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1408                         port_id, RTE_UINT16);
1409
1410 cmdline_parse_inst_t cmd_operate_detach_port = {
1411         .f = cmd_operate_detach_port_parsed,
1412         .data = NULL,
1413         .help_str = "port detach <port_id>",
1414         .tokens = {
1415                 (void *)&cmd_operate_detach_port_port,
1416                 (void *)&cmd_operate_detach_port_keyword,
1417                 (void *)&cmd_operate_detach_port_port_id,
1418                 NULL,
1419         },
1420 };
1421
1422 /* *** detach device by identifier *** */
1423 struct cmd_operate_detach_device_result {
1424         cmdline_fixed_string_t device;
1425         cmdline_fixed_string_t keyword;
1426         cmdline_fixed_string_t identifier;
1427 };
1428
1429 static void cmd_operate_detach_device_parsed(void *parsed_result,
1430                                 __rte_unused struct cmdline *cl,
1431                                 __rte_unused void *data)
1432 {
1433         struct cmd_operate_detach_device_result *res = parsed_result;
1434
1435         if (!strcmp(res->keyword, "detach"))
1436                 detach_devargs(res->identifier);
1437         else
1438                 printf("Unknown parameter\n");
1439 }
1440
1441 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1442         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1443                         device, "device");
1444 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1445         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1446                         keyword, "detach");
1447 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1448         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1449                         identifier, NULL);
1450
1451 cmdline_parse_inst_t cmd_operate_detach_device = {
1452         .f = cmd_operate_detach_device_parsed,
1453         .data = NULL,
1454         .help_str = "device detach <identifier>:"
1455                 "(identifier: pci address or virtual dev name)",
1456         .tokens = {
1457                 (void *)&cmd_operate_detach_device_device,
1458                 (void *)&cmd_operate_detach_device_keyword,
1459                 (void *)&cmd_operate_detach_device_identifier,
1460                 NULL,
1461         },
1462 };
1463 /* *** configure speed for all ports *** */
1464 struct cmd_config_speed_all {
1465         cmdline_fixed_string_t port;
1466         cmdline_fixed_string_t keyword;
1467         cmdline_fixed_string_t all;
1468         cmdline_fixed_string_t item1;
1469         cmdline_fixed_string_t item2;
1470         cmdline_fixed_string_t value1;
1471         cmdline_fixed_string_t value2;
1472 };
1473
1474 static int
1475 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1476 {
1477
1478         int duplex;
1479
1480         if (!strcmp(duplexstr, "half")) {
1481                 duplex = ETH_LINK_HALF_DUPLEX;
1482         } else if (!strcmp(duplexstr, "full")) {
1483                 duplex = ETH_LINK_FULL_DUPLEX;
1484         } else if (!strcmp(duplexstr, "auto")) {
1485                 duplex = ETH_LINK_FULL_DUPLEX;
1486         } else {
1487                 printf("Unknown duplex parameter\n");
1488                 return -1;
1489         }
1490
1491         if (!strcmp(speedstr, "10")) {
1492                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1493                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1494         } else if (!strcmp(speedstr, "100")) {
1495                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1496                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1497         } else {
1498                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1499                         printf("Invalid speed/duplex parameters\n");
1500                         return -1;
1501                 }
1502                 if (!strcmp(speedstr, "1000")) {
1503                         *speed = ETH_LINK_SPEED_1G;
1504                 } else if (!strcmp(speedstr, "10000")) {
1505                         *speed = ETH_LINK_SPEED_10G;
1506                 } else if (!strcmp(speedstr, "25000")) {
1507                         *speed = ETH_LINK_SPEED_25G;
1508                 } else if (!strcmp(speedstr, "40000")) {
1509                         *speed = ETH_LINK_SPEED_40G;
1510                 } else if (!strcmp(speedstr, "50000")) {
1511                         *speed = ETH_LINK_SPEED_50G;
1512                 } else if (!strcmp(speedstr, "100000")) {
1513                         *speed = ETH_LINK_SPEED_100G;
1514                 } else if (!strcmp(speedstr, "200000")) {
1515                         *speed = ETH_LINK_SPEED_200G;
1516                 } else if (!strcmp(speedstr, "auto")) {
1517                         *speed = ETH_LINK_SPEED_AUTONEG;
1518                 } else {
1519                         printf("Unknown speed parameter\n");
1520                         return -1;
1521                 }
1522         }
1523
1524         return 0;
1525 }
1526
1527 static void
1528 cmd_config_speed_all_parsed(void *parsed_result,
1529                         __rte_unused struct cmdline *cl,
1530                         __rte_unused void *data)
1531 {
1532         struct cmd_config_speed_all *res = parsed_result;
1533         uint32_t link_speed;
1534         portid_t pid;
1535
1536         if (!all_ports_stopped()) {
1537                 printf("Please stop all ports first\n");
1538                 return;
1539         }
1540
1541         if (parse_and_check_speed_duplex(res->value1, res->value2,
1542                         &link_speed) < 0)
1543                 return;
1544
1545         RTE_ETH_FOREACH_DEV(pid) {
1546                 ports[pid].dev_conf.link_speeds = link_speed;
1547         }
1548
1549         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1550 }
1551
1552 cmdline_parse_token_string_t cmd_config_speed_all_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1554 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1556                                                         "config");
1557 cmdline_parse_token_string_t cmd_config_speed_all_all =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1559 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1561 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1563                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1564 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1566 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1568                                                 "half#full#auto");
1569
1570 cmdline_parse_inst_t cmd_config_speed_all = {
1571         .f = cmd_config_speed_all_parsed,
1572         .data = NULL,
1573         .help_str = "port config all speed "
1574                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1575                                                         "half|full|auto",
1576         .tokens = {
1577                 (void *)&cmd_config_speed_all_port,
1578                 (void *)&cmd_config_speed_all_keyword,
1579                 (void *)&cmd_config_speed_all_all,
1580                 (void *)&cmd_config_speed_all_item1,
1581                 (void *)&cmd_config_speed_all_value1,
1582                 (void *)&cmd_config_speed_all_item2,
1583                 (void *)&cmd_config_speed_all_value2,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** configure speed for specific port *** */
1589 struct cmd_config_speed_specific {
1590         cmdline_fixed_string_t port;
1591         cmdline_fixed_string_t keyword;
1592         portid_t id;
1593         cmdline_fixed_string_t item1;
1594         cmdline_fixed_string_t item2;
1595         cmdline_fixed_string_t value1;
1596         cmdline_fixed_string_t value2;
1597 };
1598
1599 static void
1600 cmd_config_speed_specific_parsed(void *parsed_result,
1601                                 __rte_unused struct cmdline *cl,
1602                                 __rte_unused void *data)
1603 {
1604         struct cmd_config_speed_specific *res = parsed_result;
1605         uint32_t link_speed;
1606
1607         if (!all_ports_stopped()) {
1608                 printf("Please stop all ports first\n");
1609                 return;
1610         }
1611
1612         if (port_id_is_invalid(res->id, ENABLED_WARN))
1613                 return;
1614
1615         if (parse_and_check_speed_duplex(res->value1, res->value2,
1616                         &link_speed) < 0)
1617                 return;
1618
1619         ports[res->id].dev_conf.link_speeds = link_speed;
1620
1621         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1622 }
1623
1624
1625 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1627                                                                 "port");
1628 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1630                                                                 "config");
1631 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1633 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1635                                                                 "speed");
1636 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1638                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1639 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1641                                                                 "duplex");
1642 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1644                                                         "half#full#auto");
1645
1646 cmdline_parse_inst_t cmd_config_speed_specific = {
1647         .f = cmd_config_speed_specific_parsed,
1648         .data = NULL,
1649         .help_str = "port config <port_id> speed "
1650                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1651                                                         "half|full|auto",
1652         .tokens = {
1653                 (void *)&cmd_config_speed_specific_port,
1654                 (void *)&cmd_config_speed_specific_keyword,
1655                 (void *)&cmd_config_speed_specific_id,
1656                 (void *)&cmd_config_speed_specific_item1,
1657                 (void *)&cmd_config_speed_specific_value1,
1658                 (void *)&cmd_config_speed_specific_item2,
1659                 (void *)&cmd_config_speed_specific_value2,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure loopback for all ports *** */
1665 struct cmd_config_loopback_all {
1666         cmdline_fixed_string_t port;
1667         cmdline_fixed_string_t keyword;
1668         cmdline_fixed_string_t all;
1669         cmdline_fixed_string_t item;
1670         uint32_t mode;
1671 };
1672
1673 static void
1674 cmd_config_loopback_all_parsed(void *parsed_result,
1675                         __rte_unused struct cmdline *cl,
1676                         __rte_unused void *data)
1677 {
1678         struct cmd_config_loopback_all *res = parsed_result;
1679         portid_t pid;
1680
1681         if (!all_ports_stopped()) {
1682                 printf("Please stop all ports first\n");
1683                 return;
1684         }
1685
1686         RTE_ETH_FOREACH_DEV(pid) {
1687                 ports[pid].dev_conf.lpbk_mode = res->mode;
1688         }
1689
1690         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1691 }
1692
1693 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1695 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1697                                                         "config");
1698 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1700 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1702                                                         "loopback");
1703 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1704         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1705
1706 cmdline_parse_inst_t cmd_config_loopback_all = {
1707         .f = cmd_config_loopback_all_parsed,
1708         .data = NULL,
1709         .help_str = "port config all loopback <mode>",
1710         .tokens = {
1711                 (void *)&cmd_config_loopback_all_port,
1712                 (void *)&cmd_config_loopback_all_keyword,
1713                 (void *)&cmd_config_loopback_all_all,
1714                 (void *)&cmd_config_loopback_all_item,
1715                 (void *)&cmd_config_loopback_all_mode,
1716                 NULL,
1717         },
1718 };
1719
1720 /* *** configure loopback for specific port *** */
1721 struct cmd_config_loopback_specific {
1722         cmdline_fixed_string_t port;
1723         cmdline_fixed_string_t keyword;
1724         uint16_t port_id;
1725         cmdline_fixed_string_t item;
1726         uint32_t mode;
1727 };
1728
1729 static void
1730 cmd_config_loopback_specific_parsed(void *parsed_result,
1731                                 __rte_unused struct cmdline *cl,
1732                                 __rte_unused void *data)
1733 {
1734         struct cmd_config_loopback_specific *res = parsed_result;
1735
1736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1737                 return;
1738
1739         if (!port_is_stopped(res->port_id)) {
1740                 printf("Please stop port %u first\n", res->port_id);
1741                 return;
1742         }
1743
1744         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1745
1746         cmd_reconfig_device_queue(res->port_id, 1, 1);
1747 }
1748
1749
1750 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1751         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1752                                                                 "port");
1753 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1755                                                                 "config");
1756 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1757         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1758                                                                 RTE_UINT16);
1759 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1761                                                                 "loopback");
1762 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1763         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1764                               RTE_UINT32);
1765
1766 cmdline_parse_inst_t cmd_config_loopback_specific = {
1767         .f = cmd_config_loopback_specific_parsed,
1768         .data = NULL,
1769         .help_str = "port config <port_id> loopback <mode>",
1770         .tokens = {
1771                 (void *)&cmd_config_loopback_specific_port,
1772                 (void *)&cmd_config_loopback_specific_keyword,
1773                 (void *)&cmd_config_loopback_specific_id,
1774                 (void *)&cmd_config_loopback_specific_item,
1775                 (void *)&cmd_config_loopback_specific_mode,
1776                 NULL,
1777         },
1778 };
1779
1780 /* *** configure txq/rxq, txd/rxd *** */
1781 struct cmd_config_rx_tx {
1782         cmdline_fixed_string_t port;
1783         cmdline_fixed_string_t keyword;
1784         cmdline_fixed_string_t all;
1785         cmdline_fixed_string_t name;
1786         uint16_t value;
1787 };
1788
1789 static void
1790 cmd_config_rx_tx_parsed(void *parsed_result,
1791                         __rte_unused struct cmdline *cl,
1792                         __rte_unused void *data)
1793 {
1794         struct cmd_config_rx_tx *res = parsed_result;
1795
1796         if (!all_ports_stopped()) {
1797                 printf("Please stop all ports first\n");
1798                 return;
1799         }
1800         if (!strcmp(res->name, "rxq")) {
1801                 if (!res->value && !nb_txq) {
1802                         printf("Warning: Either rx or tx queues should be non zero\n");
1803                         return;
1804                 }
1805                 if (check_nb_rxq(res->value) != 0)
1806                         return;
1807                 nb_rxq = res->value;
1808         }
1809         else if (!strcmp(res->name, "txq")) {
1810                 if (!res->value && !nb_rxq) {
1811                         printf("Warning: Either rx or tx queues should be non zero\n");
1812                         return;
1813                 }
1814                 if (check_nb_txq(res->value) != 0)
1815                         return;
1816                 nb_txq = res->value;
1817         }
1818         else if (!strcmp(res->name, "rxd")) {
1819                 if (check_nb_rxd(res->value) != 0)
1820                         return;
1821                 nb_rxd = res->value;
1822         } else if (!strcmp(res->name, "txd")) {
1823                 if (check_nb_txd(res->value) != 0)
1824                         return;
1825
1826                 nb_txd = res->value;
1827         } else {
1828                 printf("Unknown parameter\n");
1829                 return;
1830         }
1831
1832         fwd_config_setup();
1833
1834         init_port_config();
1835
1836         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1837 }
1838
1839 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1841 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1843 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1847                                                 "rxq#txq#rxd#txd");
1848 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1850
1851 cmdline_parse_inst_t cmd_config_rx_tx = {
1852         .f = cmd_config_rx_tx_parsed,
1853         .data = NULL,
1854         .help_str = "port config all rxq|txq|rxd|txd <value>",
1855         .tokens = {
1856                 (void *)&cmd_config_rx_tx_port,
1857                 (void *)&cmd_config_rx_tx_keyword,
1858                 (void *)&cmd_config_rx_tx_all,
1859                 (void *)&cmd_config_rx_tx_name,
1860                 (void *)&cmd_config_rx_tx_value,
1861                 NULL,
1862         },
1863 };
1864
1865 /* *** config max packet length *** */
1866 struct cmd_config_max_pkt_len_result {
1867         cmdline_fixed_string_t port;
1868         cmdline_fixed_string_t keyword;
1869         cmdline_fixed_string_t all;
1870         cmdline_fixed_string_t name;
1871         uint32_t value;
1872 };
1873
1874 static void
1875 cmd_config_max_pkt_len_parsed(void *parsed_result,
1876                                 __rte_unused struct cmdline *cl,
1877                                 __rte_unused void *data)
1878 {
1879         struct cmd_config_max_pkt_len_result *res = parsed_result;
1880         portid_t pid;
1881
1882         if (!all_ports_stopped()) {
1883                 printf("Please stop all ports first\n");
1884                 return;
1885         }
1886
1887         RTE_ETH_FOREACH_DEV(pid) {
1888                 struct rte_port *port = &ports[pid];
1889                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1890
1891                 if (!strcmp(res->name, "max-pkt-len")) {
1892                         if (res->value < RTE_ETHER_MIN_LEN) {
1893                                 printf("max-pkt-len can not be less than %d\n",
1894                                                 RTE_ETHER_MIN_LEN);
1895                                 return;
1896                         }
1897                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1898                                 return;
1899
1900                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1901                         if (res->value > RTE_ETHER_MAX_LEN)
1902                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1903                         else
1904                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1905                         port->dev_conf.rxmode.offloads = rx_offloads;
1906                 } else {
1907                         printf("Unknown parameter\n");
1908                         return;
1909                 }
1910         }
1911
1912         init_port_config();
1913
1914         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1915 }
1916
1917 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1918         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1919                                                                 "port");
1920 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1921         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1922                                                                 "config");
1923 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1924         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1925                                                                 "all");
1926 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1927         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1928                                                                 "max-pkt-len");
1929 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1930         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1931                                                                 RTE_UINT32);
1932
1933 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1934         .f = cmd_config_max_pkt_len_parsed,
1935         .data = NULL,
1936         .help_str = "port config all max-pkt-len <value>",
1937         .tokens = {
1938                 (void *)&cmd_config_max_pkt_len_port,
1939                 (void *)&cmd_config_max_pkt_len_keyword,
1940                 (void *)&cmd_config_max_pkt_len_all,
1941                 (void *)&cmd_config_max_pkt_len_name,
1942                 (void *)&cmd_config_max_pkt_len_value,
1943                 NULL,
1944         },
1945 };
1946
1947 /* *** config max LRO aggregated packet size *** */
1948 struct cmd_config_max_lro_pkt_size_result {
1949         cmdline_fixed_string_t port;
1950         cmdline_fixed_string_t keyword;
1951         cmdline_fixed_string_t all;
1952         cmdline_fixed_string_t name;
1953         uint32_t value;
1954 };
1955
1956 static void
1957 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1958                                 __rte_unused struct cmdline *cl,
1959                                 __rte_unused void *data)
1960 {
1961         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1962         portid_t pid;
1963
1964         if (!all_ports_stopped()) {
1965                 printf("Please stop all ports first\n");
1966                 return;
1967         }
1968
1969         RTE_ETH_FOREACH_DEV(pid) {
1970                 struct rte_port *port = &ports[pid];
1971
1972                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1973                         if (res->value ==
1974                                         port->dev_conf.rxmode.max_lro_pkt_size)
1975                                 return;
1976
1977                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1978                 } else {
1979                         printf("Unknown parameter\n");
1980                         return;
1981                 }
1982         }
1983
1984         init_port_config();
1985
1986         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1987 }
1988
1989 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1990         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1991                                  port, "port");
1992 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
1993         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1994                                  keyword, "config");
1995 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
1996         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1997                                  all, "all");
1998 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
1999         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2000                                  name, "max-lro-pkt-size");
2001 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2002         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2003                               value, RTE_UINT32);
2004
2005 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2006         .f = cmd_config_max_lro_pkt_size_parsed,
2007         .data = NULL,
2008         .help_str = "port config all max-lro-pkt-size <value>",
2009         .tokens = {
2010                 (void *)&cmd_config_max_lro_pkt_size_port,
2011                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2012                 (void *)&cmd_config_max_lro_pkt_size_all,
2013                 (void *)&cmd_config_max_lro_pkt_size_name,
2014                 (void *)&cmd_config_max_lro_pkt_size_value,
2015                 NULL,
2016         },
2017 };
2018
2019 /* *** configure port MTU *** */
2020 struct cmd_config_mtu_result {
2021         cmdline_fixed_string_t port;
2022         cmdline_fixed_string_t keyword;
2023         cmdline_fixed_string_t mtu;
2024         portid_t port_id;
2025         uint16_t value;
2026 };
2027
2028 static void
2029 cmd_config_mtu_parsed(void *parsed_result,
2030                       __rte_unused struct cmdline *cl,
2031                       __rte_unused void *data)
2032 {
2033         struct cmd_config_mtu_result *res = parsed_result;
2034
2035         if (res->value < RTE_ETHER_MIN_LEN) {
2036                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2037                 return;
2038         }
2039         port_mtu_set(res->port_id, res->value);
2040 }
2041
2042 cmdline_parse_token_string_t cmd_config_mtu_port =
2043         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2044                                  "port");
2045 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2046         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2047                                  "config");
2048 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2049         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2050                                  "mtu");
2051 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2052         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2053                                  RTE_UINT16);
2054 cmdline_parse_token_num_t cmd_config_mtu_value =
2055         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2056                                  RTE_UINT16);
2057
2058 cmdline_parse_inst_t cmd_config_mtu = {
2059         .f = cmd_config_mtu_parsed,
2060         .data = NULL,
2061         .help_str = "port config mtu <port_id> <value>",
2062         .tokens = {
2063                 (void *)&cmd_config_mtu_port,
2064                 (void *)&cmd_config_mtu_keyword,
2065                 (void *)&cmd_config_mtu_mtu,
2066                 (void *)&cmd_config_mtu_port_id,
2067                 (void *)&cmd_config_mtu_value,
2068                 NULL,
2069         },
2070 };
2071
2072 /* *** configure rx mode *** */
2073 struct cmd_config_rx_mode_flag {
2074         cmdline_fixed_string_t port;
2075         cmdline_fixed_string_t keyword;
2076         cmdline_fixed_string_t all;
2077         cmdline_fixed_string_t name;
2078         cmdline_fixed_string_t value;
2079 };
2080
2081 static void
2082 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2083                                 __rte_unused struct cmdline *cl,
2084                                 __rte_unused void *data)
2085 {
2086         struct cmd_config_rx_mode_flag *res = parsed_result;
2087
2088         if (!all_ports_stopped()) {
2089                 printf("Please stop all ports first\n");
2090                 return;
2091         }
2092
2093         if (!strcmp(res->name, "drop-en")) {
2094                 if (!strcmp(res->value, "on"))
2095                         rx_drop_en = 1;
2096                 else if (!strcmp(res->value, "off"))
2097                         rx_drop_en = 0;
2098                 else {
2099                         printf("Unknown parameter\n");
2100                         return;
2101                 }
2102         } else {
2103                 printf("Unknown parameter\n");
2104                 return;
2105         }
2106
2107         init_port_config();
2108
2109         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2110 }
2111
2112 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2114 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2116                                                                 "config");
2117 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2119 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2121                                         "drop-en");
2122 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2124                                                         "on#off");
2125
2126 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2127         .f = cmd_config_rx_mode_flag_parsed,
2128         .data = NULL,
2129         .help_str = "port config all drop-en on|off",
2130         .tokens = {
2131                 (void *)&cmd_config_rx_mode_flag_port,
2132                 (void *)&cmd_config_rx_mode_flag_keyword,
2133                 (void *)&cmd_config_rx_mode_flag_all,
2134                 (void *)&cmd_config_rx_mode_flag_name,
2135                 (void *)&cmd_config_rx_mode_flag_value,
2136                 NULL,
2137         },
2138 };
2139
2140 /* *** configure rss *** */
2141 struct cmd_config_rss {
2142         cmdline_fixed_string_t port;
2143         cmdline_fixed_string_t keyword;
2144         cmdline_fixed_string_t all;
2145         cmdline_fixed_string_t name;
2146         cmdline_fixed_string_t value;
2147 };
2148
2149 static void
2150 cmd_config_rss_parsed(void *parsed_result,
2151                         __rte_unused struct cmdline *cl,
2152                         __rte_unused void *data)
2153 {
2154         struct cmd_config_rss *res = parsed_result;
2155         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2156         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2157         int use_default = 0;
2158         int all_updated = 1;
2159         int diag;
2160         uint16_t i;
2161         int ret;
2162
2163         if (!strcmp(res->value, "all"))
2164                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2165                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2166                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2167                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2168         else if (!strcmp(res->value, "eth"))
2169                 rss_conf.rss_hf = ETH_RSS_ETH;
2170         else if (!strcmp(res->value, "vlan"))
2171                 rss_conf.rss_hf = ETH_RSS_VLAN;
2172         else if (!strcmp(res->value, "ip"))
2173                 rss_conf.rss_hf = ETH_RSS_IP;
2174         else if (!strcmp(res->value, "udp"))
2175                 rss_conf.rss_hf = ETH_RSS_UDP;
2176         else if (!strcmp(res->value, "tcp"))
2177                 rss_conf.rss_hf = ETH_RSS_TCP;
2178         else if (!strcmp(res->value, "sctp"))
2179                 rss_conf.rss_hf = ETH_RSS_SCTP;
2180         else if (!strcmp(res->value, "ether"))
2181                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2182         else if (!strcmp(res->value, "port"))
2183                 rss_conf.rss_hf = ETH_RSS_PORT;
2184         else if (!strcmp(res->value, "vxlan"))
2185                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2186         else if (!strcmp(res->value, "geneve"))
2187                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2188         else if (!strcmp(res->value, "nvgre"))
2189                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2190         else if (!strcmp(res->value, "l3-pre32"))
2191                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2192         else if (!strcmp(res->value, "l3-pre40"))
2193                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2194         else if (!strcmp(res->value, "l3-pre48"))
2195                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2196         else if (!strcmp(res->value, "l3-pre56"))
2197                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2198         else if (!strcmp(res->value, "l3-pre64"))
2199                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2200         else if (!strcmp(res->value, "l3-pre96"))
2201                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2202         else if (!strcmp(res->value, "l3-src-only"))
2203                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2204         else if (!strcmp(res->value, "l3-dst-only"))
2205                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2206         else if (!strcmp(res->value, "l4-src-only"))
2207                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2208         else if (!strcmp(res->value, "l4-dst-only"))
2209                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2210         else if (!strcmp(res->value, "l2-src-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2212         else if (!strcmp(res->value, "l2-dst-only"))
2213                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2214         else if (!strcmp(res->value, "l2tpv3"))
2215                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2216         else if (!strcmp(res->value, "esp"))
2217                 rss_conf.rss_hf = ETH_RSS_ESP;
2218         else if (!strcmp(res->value, "ah"))
2219                 rss_conf.rss_hf = ETH_RSS_AH;
2220         else if (!strcmp(res->value, "pfcp"))
2221                 rss_conf.rss_hf = ETH_RSS_PFCP;
2222         else if (!strcmp(res->value, "pppoe"))
2223                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2224         else if (!strcmp(res->value, "gtpu"))
2225                 rss_conf.rss_hf = ETH_RSS_GTPU;
2226         else if (!strcmp(res->value, "none"))
2227                 rss_conf.rss_hf = 0;
2228         else if (!strcmp(res->value, "level-default")) {
2229                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2230                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2231         } else if (!strcmp(res->value, "level-outer")) {
2232                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2233                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2234         } else if (!strcmp(res->value, "level-inner")) {
2235                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2236                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2237         } else if (!strcmp(res->value, "default"))
2238                 use_default = 1;
2239         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2240                                                 atoi(res->value) < 64)
2241                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2242         else {
2243                 printf("Unknown parameter\n");
2244                 return;
2245         }
2246         rss_conf.rss_key = NULL;
2247         /* Update global configuration for RSS types. */
2248         RTE_ETH_FOREACH_DEV(i) {
2249                 struct rte_eth_rss_conf local_rss_conf;
2250
2251                 ret = eth_dev_info_get_print_err(i, &dev_info);
2252                 if (ret != 0)
2253                         return;
2254
2255                 if (use_default)
2256                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2257
2258                 local_rss_conf = rss_conf;
2259                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2260                         dev_info.flow_type_rss_offloads;
2261                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2262                         printf("Port %u modified RSS hash function based on hardware support,"
2263                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2264                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2265                 }
2266                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2267                 if (diag < 0) {
2268                         all_updated = 0;
2269                         printf("Configuration of RSS hash at ethernet port %d "
2270                                 "failed with error (%d): %s.\n",
2271                                 i, -diag, strerror(-diag));
2272                 }
2273         }
2274         if (all_updated && !use_default) {
2275                 rss_hf = rss_conf.rss_hf;
2276                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2277         }
2278 }
2279
2280 cmdline_parse_token_string_t cmd_config_rss_port =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2282 cmdline_parse_token_string_t cmd_config_rss_keyword =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2284 cmdline_parse_token_string_t cmd_config_rss_all =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2286 cmdline_parse_token_string_t cmd_config_rss_name =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2288 cmdline_parse_token_string_t cmd_config_rss_value =
2289         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2290
2291 cmdline_parse_inst_t cmd_config_rss = {
2292         .f = cmd_config_rss_parsed,
2293         .data = NULL,
2294         .help_str = "port config all rss "
2295                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2296                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2297                 "level-outer|level-inner|<flowtype_id>",
2298         .tokens = {
2299                 (void *)&cmd_config_rss_port,
2300                 (void *)&cmd_config_rss_keyword,
2301                 (void *)&cmd_config_rss_all,
2302                 (void *)&cmd_config_rss_name,
2303                 (void *)&cmd_config_rss_value,
2304                 NULL,
2305         },
2306 };
2307
2308 /* *** configure rss hash key *** */
2309 struct cmd_config_rss_hash_key {
2310         cmdline_fixed_string_t port;
2311         cmdline_fixed_string_t config;
2312         portid_t port_id;
2313         cmdline_fixed_string_t rss_hash_key;
2314         cmdline_fixed_string_t rss_type;
2315         cmdline_fixed_string_t key;
2316 };
2317
2318 static uint8_t
2319 hexa_digit_to_value(char hexa_digit)
2320 {
2321         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2322                 return (uint8_t) (hexa_digit - '0');
2323         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2324                 return (uint8_t) ((hexa_digit - 'a') + 10);
2325         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2326                 return (uint8_t) ((hexa_digit - 'A') + 10);
2327         /* Invalid hexa digit */
2328         return 0xFF;
2329 }
2330
2331 static uint8_t
2332 parse_and_check_key_hexa_digit(char *key, int idx)
2333 {
2334         uint8_t hexa_v;
2335
2336         hexa_v = hexa_digit_to_value(key[idx]);
2337         if (hexa_v == 0xFF)
2338                 printf("invalid key: character %c at position %d is not a "
2339                        "valid hexa digit\n", key[idx], idx);
2340         return hexa_v;
2341 }
2342
2343 static void
2344 cmd_config_rss_hash_key_parsed(void *parsed_result,
2345                                __rte_unused struct cmdline *cl,
2346                                __rte_unused void *data)
2347 {
2348         struct cmd_config_rss_hash_key *res = parsed_result;
2349         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2350         uint8_t xdgt0;
2351         uint8_t xdgt1;
2352         int i;
2353         struct rte_eth_dev_info dev_info;
2354         uint8_t hash_key_size;
2355         uint32_t key_len;
2356         int ret;
2357
2358         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2359         if (ret != 0)
2360                 return;
2361
2362         if (dev_info.hash_key_size > 0 &&
2363                         dev_info.hash_key_size <= sizeof(hash_key))
2364                 hash_key_size = dev_info.hash_key_size;
2365         else {
2366                 printf("dev_info did not provide a valid hash key size\n");
2367                 return;
2368         }
2369         /* Check the length of the RSS hash key */
2370         key_len = strlen(res->key);
2371         if (key_len != (hash_key_size * 2)) {
2372                 printf("key length: %d invalid - key must be a string of %d"
2373                            " hexa-decimal numbers\n",
2374                            (int) key_len, hash_key_size * 2);
2375                 return;
2376         }
2377         /* Translate RSS hash key into binary representation */
2378         for (i = 0; i < hash_key_size; i++) {
2379                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2380                 if (xdgt0 == 0xFF)
2381                         return;
2382                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2383                 if (xdgt1 == 0xFF)
2384                         return;
2385                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2386         }
2387         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2388                         hash_key_size);
2389 }
2390
2391 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2392         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2393 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2395                                  "config");
2396 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2397         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2398                                  RTE_UINT16);
2399 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2401                                  rss_hash_key, "rss-hash-key");
2402 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2403         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2404                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2405                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2406                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2407                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2408                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2409                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2410                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2411 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2413
2414 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2415         .f = cmd_config_rss_hash_key_parsed,
2416         .data = NULL,
2417         .help_str = "port config <port_id> rss-hash-key "
2418                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2419                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2420                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2421                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2422                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2423                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2424                 "<string of hex digits (variable length, NIC dependent)>",
2425         .tokens = {
2426                 (void *)&cmd_config_rss_hash_key_port,
2427                 (void *)&cmd_config_rss_hash_key_config,
2428                 (void *)&cmd_config_rss_hash_key_port_id,
2429                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2430                 (void *)&cmd_config_rss_hash_key_rss_type,
2431                 (void *)&cmd_config_rss_hash_key_value,
2432                 NULL,
2433         },
2434 };
2435
2436 /* *** configure port rxq/txq ring size *** */
2437 struct cmd_config_rxtx_ring_size {
2438         cmdline_fixed_string_t port;
2439         cmdline_fixed_string_t config;
2440         portid_t portid;
2441         cmdline_fixed_string_t rxtxq;
2442         uint16_t qid;
2443         cmdline_fixed_string_t rsize;
2444         uint16_t size;
2445 };
2446
2447 static void
2448 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2449                                  __rte_unused struct cmdline *cl,
2450                                  __rte_unused void *data)
2451 {
2452         struct cmd_config_rxtx_ring_size *res = parsed_result;
2453         struct rte_port *port;
2454         uint8_t isrx;
2455
2456         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2457                 return;
2458
2459         if (res->portid == (portid_t)RTE_PORT_ALL) {
2460                 printf("Invalid port id\n");
2461                 return;
2462         }
2463
2464         port = &ports[res->portid];
2465
2466         if (!strcmp(res->rxtxq, "rxq"))
2467                 isrx = 1;
2468         else if (!strcmp(res->rxtxq, "txq"))
2469                 isrx = 0;
2470         else {
2471                 printf("Unknown parameter\n");
2472                 return;
2473         }
2474
2475         if (isrx && rx_queue_id_is_invalid(res->qid))
2476                 return;
2477         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2478                 return;
2479
2480         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2481                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2482                        rx_free_thresh);
2483                 return;
2484         }
2485
2486         if (isrx)
2487                 port->nb_rx_desc[res->qid] = res->size;
2488         else
2489                 port->nb_tx_desc[res->qid] = res->size;
2490
2491         cmd_reconfig_device_queue(res->portid, 0, 1);
2492 }
2493
2494 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2496                                  port, "port");
2497 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2498         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                                  config, "config");
2500 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2501         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2502                                  portid, RTE_UINT16);
2503 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2504         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2505                                  rxtxq, "rxq#txq");
2506 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2507         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2508                               qid, RTE_UINT16);
2509 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2510         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                                  rsize, "ring_size");
2512 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2513         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2514                               size, RTE_UINT16);
2515
2516 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2517         .f = cmd_config_rxtx_ring_size_parsed,
2518         .data = NULL,
2519         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2520         .tokens = {
2521                 (void *)&cmd_config_rxtx_ring_size_port,
2522                 (void *)&cmd_config_rxtx_ring_size_config,
2523                 (void *)&cmd_config_rxtx_ring_size_portid,
2524                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2525                 (void *)&cmd_config_rxtx_ring_size_qid,
2526                 (void *)&cmd_config_rxtx_ring_size_rsize,
2527                 (void *)&cmd_config_rxtx_ring_size_size,
2528                 NULL,
2529         },
2530 };
2531
2532 /* *** configure port rxq/txq start/stop *** */
2533 struct cmd_config_rxtx_queue {
2534         cmdline_fixed_string_t port;
2535         portid_t portid;
2536         cmdline_fixed_string_t rxtxq;
2537         uint16_t qid;
2538         cmdline_fixed_string_t opname;
2539 };
2540
2541 static void
2542 cmd_config_rxtx_queue_parsed(void *parsed_result,
2543                         __rte_unused struct cmdline *cl,
2544                         __rte_unused void *data)
2545 {
2546         struct cmd_config_rxtx_queue *res = parsed_result;
2547         uint8_t isrx;
2548         uint8_t isstart;
2549         int ret = 0;
2550
2551         if (test_done == 0) {
2552                 printf("Please stop forwarding first\n");
2553                 return;
2554         }
2555
2556         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2557                 return;
2558
2559         if (port_is_started(res->portid) != 1) {
2560                 printf("Please start port %u first\n", res->portid);
2561                 return;
2562         }
2563
2564         if (!strcmp(res->rxtxq, "rxq"))
2565                 isrx = 1;
2566         else if (!strcmp(res->rxtxq, "txq"))
2567                 isrx = 0;
2568         else {
2569                 printf("Unknown parameter\n");
2570                 return;
2571         }
2572
2573         if (isrx && rx_queue_id_is_invalid(res->qid))
2574                 return;
2575         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2576                 return;
2577
2578         if (!strcmp(res->opname, "start"))
2579                 isstart = 1;
2580         else if (!strcmp(res->opname, "stop"))
2581                 isstart = 0;
2582         else {
2583                 printf("Unknown parameter\n");
2584                 return;
2585         }
2586
2587         if (isstart && isrx)
2588                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2589         else if (!isstart && isrx)
2590                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2591         else if (isstart && !isrx)
2592                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2593         else
2594                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2595
2596         if (ret == -ENOTSUP)
2597                 printf("Function not supported in PMD driver\n");
2598 }
2599
2600 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2601         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2602 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2603         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2604 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2605         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2606 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2607         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2608 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2609         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2610                                                 "start#stop");
2611
2612 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2613         .f = cmd_config_rxtx_queue_parsed,
2614         .data = NULL,
2615         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2616         .tokens = {
2617                 (void *)&cmd_config_rxtx_queue_port,
2618                 (void *)&cmd_config_rxtx_queue_portid,
2619                 (void *)&cmd_config_rxtx_queue_rxtxq,
2620                 (void *)&cmd_config_rxtx_queue_qid,
2621                 (void *)&cmd_config_rxtx_queue_opname,
2622                 NULL,
2623         },
2624 };
2625
2626 /* *** configure port rxq/txq deferred start on/off *** */
2627 struct cmd_config_deferred_start_rxtx_queue {
2628         cmdline_fixed_string_t port;
2629         portid_t port_id;
2630         cmdline_fixed_string_t rxtxq;
2631         uint16_t qid;
2632         cmdline_fixed_string_t opname;
2633         cmdline_fixed_string_t state;
2634 };
2635
2636 static void
2637 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2638                         __rte_unused struct cmdline *cl,
2639                         __rte_unused void *data)
2640 {
2641         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2642         struct rte_port *port;
2643         uint8_t isrx;
2644         uint8_t ison;
2645         uint8_t needreconfig = 0;
2646
2647         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2648                 return;
2649
2650         if (port_is_started(res->port_id) != 0) {
2651                 printf("Please stop port %u first\n", res->port_id);
2652                 return;
2653         }
2654
2655         port = &ports[res->port_id];
2656
2657         isrx = !strcmp(res->rxtxq, "rxq");
2658
2659         if (isrx && rx_queue_id_is_invalid(res->qid))
2660                 return;
2661         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2662                 return;
2663
2664         ison = !strcmp(res->state, "on");
2665
2666         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2667                 port->rx_conf[res->qid].rx_deferred_start = ison;
2668                 needreconfig = 1;
2669         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2670                 port->tx_conf[res->qid].tx_deferred_start = ison;
2671                 needreconfig = 1;
2672         }
2673
2674         if (needreconfig)
2675                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2676 }
2677
2678 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2679         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2680                                                 port, "port");
2681 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2682         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2683                                                 port_id, RTE_UINT16);
2684 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2685         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2686                                                 rxtxq, "rxq#txq");
2687 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2688         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2689                                                 qid, RTE_UINT16);
2690 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2692                                                 opname, "deferred_start");
2693 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2695                                                 state, "on#off");
2696
2697 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2698         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2699         .data = NULL,
2700         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2701         .tokens = {
2702                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2703                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2704                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2705                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2706                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2707                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2708                 NULL,
2709         },
2710 };
2711
2712 /* *** configure port rxq/txq setup *** */
2713 struct cmd_setup_rxtx_queue {
2714         cmdline_fixed_string_t port;
2715         portid_t portid;
2716         cmdline_fixed_string_t rxtxq;
2717         uint16_t qid;
2718         cmdline_fixed_string_t setup;
2719 };
2720
2721 /* Common CLI fields for queue setup */
2722 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2723         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2724 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2725         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2726 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2727         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2728 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2729         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2730 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2731         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2732
2733 static void
2734 cmd_setup_rxtx_queue_parsed(
2735         void *parsed_result,
2736         __rte_unused struct cmdline *cl,
2737         __rte_unused void *data)
2738 {
2739         struct cmd_setup_rxtx_queue *res = parsed_result;
2740         struct rte_port *port;
2741         struct rte_mempool *mp;
2742         unsigned int socket_id;
2743         uint8_t isrx = 0;
2744         int ret;
2745
2746         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2747                 return;
2748
2749         if (res->portid == (portid_t)RTE_PORT_ALL) {
2750                 printf("Invalid port id\n");
2751                 return;
2752         }
2753
2754         if (!strcmp(res->rxtxq, "rxq"))
2755                 isrx = 1;
2756         else if (!strcmp(res->rxtxq, "txq"))
2757                 isrx = 0;
2758         else {
2759                 printf("Unknown parameter\n");
2760                 return;
2761         }
2762
2763         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2764                 printf("Invalid rx queue\n");
2765                 return;
2766         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2767                 printf("Invalid tx queue\n");
2768                 return;
2769         }
2770
2771         port = &ports[res->portid];
2772         if (isrx) {
2773                 socket_id = rxring_numa[res->portid];
2774                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2775                         socket_id = port->socket_id;
2776
2777                 mp = mbuf_pool_find(socket_id, 0);
2778                 if (mp == NULL) {
2779                         printf("Failed to setup RX queue: "
2780                                 "No mempool allocation"
2781                                 " on the socket %d\n",
2782                                 rxring_numa[res->portid]);
2783                         return;
2784                 }
2785                 ret = rx_queue_setup(res->portid,
2786                                      res->qid,
2787                                      port->nb_rx_desc[res->qid],
2788                                      socket_id,
2789                                      &port->rx_conf[res->qid],
2790                                      mp);
2791                 if (ret)
2792                         printf("Failed to setup RX queue\n");
2793         } else {
2794                 socket_id = txring_numa[res->portid];
2795                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2796                         socket_id = port->socket_id;
2797
2798                 ret = rte_eth_tx_queue_setup(res->portid,
2799                                              res->qid,
2800                                              port->nb_tx_desc[res->qid],
2801                                              socket_id,
2802                                              &port->tx_conf[res->qid]);
2803                 if (ret)
2804                         printf("Failed to setup TX queue\n");
2805         }
2806 }
2807
2808 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2809         .f = cmd_setup_rxtx_queue_parsed,
2810         .data = NULL,
2811         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2812         .tokens = {
2813                 (void *)&cmd_setup_rxtx_queue_port,
2814                 (void *)&cmd_setup_rxtx_queue_portid,
2815                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2816                 (void *)&cmd_setup_rxtx_queue_qid,
2817                 (void *)&cmd_setup_rxtx_queue_setup,
2818                 NULL,
2819         },
2820 };
2821
2822
2823 /* *** Configure RSS RETA *** */
2824 struct cmd_config_rss_reta {
2825         cmdline_fixed_string_t port;
2826         cmdline_fixed_string_t keyword;
2827         portid_t port_id;
2828         cmdline_fixed_string_t name;
2829         cmdline_fixed_string_t list_name;
2830         cmdline_fixed_string_t list_of_items;
2831 };
2832
2833 static int
2834 parse_reta_config(const char *str,
2835                   struct rte_eth_rss_reta_entry64 *reta_conf,
2836                   uint16_t nb_entries)
2837 {
2838         int i;
2839         unsigned size;
2840         uint16_t hash_index, idx, shift;
2841         uint16_t nb_queue;
2842         char s[256];
2843         const char *p, *p0 = str;
2844         char *end;
2845         enum fieldnames {
2846                 FLD_HASH_INDEX = 0,
2847                 FLD_QUEUE,
2848                 _NUM_FLD
2849         };
2850         unsigned long int_fld[_NUM_FLD];
2851         char *str_fld[_NUM_FLD];
2852
2853         while ((p = strchr(p0,'(')) != NULL) {
2854                 ++p;
2855                 if((p0 = strchr(p,')')) == NULL)
2856                         return -1;
2857
2858                 size = p0 - p;
2859                 if(size >= sizeof(s))
2860                         return -1;
2861
2862                 snprintf(s, sizeof(s), "%.*s", size, p);
2863                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2864                         return -1;
2865                 for (i = 0; i < _NUM_FLD; i++) {
2866                         errno = 0;
2867                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2868                         if (errno != 0 || end == str_fld[i] ||
2869                                         int_fld[i] > 65535)
2870                                 return -1;
2871                 }
2872
2873                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2874                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2875
2876                 if (hash_index >= nb_entries) {
2877                         printf("Invalid RETA hash index=%d\n", hash_index);
2878                         return -1;
2879                 }
2880
2881                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2882                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2883                 reta_conf[idx].mask |= (1ULL << shift);
2884                 reta_conf[idx].reta[shift] = nb_queue;
2885         }
2886
2887         return 0;
2888 }
2889
2890 static void
2891 cmd_set_rss_reta_parsed(void *parsed_result,
2892                         __rte_unused struct cmdline *cl,
2893                         __rte_unused void *data)
2894 {
2895         int ret;
2896         struct rte_eth_dev_info dev_info;
2897         struct rte_eth_rss_reta_entry64 reta_conf[8];
2898         struct cmd_config_rss_reta *res = parsed_result;
2899
2900         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2901         if (ret != 0)
2902                 return;
2903
2904         if (dev_info.reta_size == 0) {
2905                 printf("Redirection table size is 0 which is "
2906                                         "invalid for RSS\n");
2907                 return;
2908         } else
2909                 printf("The reta size of port %d is %u\n",
2910                         res->port_id, dev_info.reta_size);
2911         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2912                 printf("Currently do not support more than %u entries of "
2913                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2914                 return;
2915         }
2916
2917         memset(reta_conf, 0, sizeof(reta_conf));
2918         if (!strcmp(res->list_name, "reta")) {
2919                 if (parse_reta_config(res->list_of_items, reta_conf,
2920                                                 dev_info.reta_size)) {
2921                         printf("Invalid RSS Redirection Table "
2922                                         "config entered\n");
2923                         return;
2924                 }
2925                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2926                                 reta_conf, dev_info.reta_size);
2927                 if (ret != 0)
2928                         printf("Bad redirection table parameter, "
2929                                         "return code = %d \n", ret);
2930         }
2931 }
2932
2933 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2934         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2935 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2936         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2937 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2938         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2939 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2940         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2941 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2942         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2943 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2944         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2945                                  NULL);
2946 cmdline_parse_inst_t cmd_config_rss_reta = {
2947         .f = cmd_set_rss_reta_parsed,
2948         .data = NULL,
2949         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2950         .tokens = {
2951                 (void *)&cmd_config_rss_reta_port,
2952                 (void *)&cmd_config_rss_reta_keyword,
2953                 (void *)&cmd_config_rss_reta_port_id,
2954                 (void *)&cmd_config_rss_reta_name,
2955                 (void *)&cmd_config_rss_reta_list_name,
2956                 (void *)&cmd_config_rss_reta_list_of_items,
2957                 NULL,
2958         },
2959 };
2960
2961 /* *** SHOW PORT RETA INFO *** */
2962 struct cmd_showport_reta {
2963         cmdline_fixed_string_t show;
2964         cmdline_fixed_string_t port;
2965         portid_t port_id;
2966         cmdline_fixed_string_t rss;
2967         cmdline_fixed_string_t reta;
2968         uint16_t size;
2969         cmdline_fixed_string_t list_of_items;
2970 };
2971
2972 static int
2973 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2974                            uint16_t nb_entries,
2975                            char *str)
2976 {
2977         uint32_t size;
2978         const char *p, *p0 = str;
2979         char s[256];
2980         char *end;
2981         char *str_fld[8];
2982         uint16_t i;
2983         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2984                         RTE_RETA_GROUP_SIZE;
2985         int ret;
2986
2987         p = strchr(p0, '(');
2988         if (p == NULL)
2989                 return -1;
2990         p++;
2991         p0 = strchr(p, ')');
2992         if (p0 == NULL)
2993                 return -1;
2994         size = p0 - p;
2995         if (size >= sizeof(s)) {
2996                 printf("The string size exceeds the internal buffer size\n");
2997                 return -1;
2998         }
2999         snprintf(s, sizeof(s), "%.*s", size, p);
3000         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3001         if (ret <= 0 || ret != num) {
3002                 printf("The bits of masks do not match the number of "
3003                                         "reta entries: %u\n", num);
3004                 return -1;
3005         }
3006         for (i = 0; i < ret; i++)
3007                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3008
3009         return 0;
3010 }
3011
3012 static void
3013 cmd_showport_reta_parsed(void *parsed_result,
3014                          __rte_unused struct cmdline *cl,
3015                          __rte_unused void *data)
3016 {
3017         struct cmd_showport_reta *res = parsed_result;
3018         struct rte_eth_rss_reta_entry64 reta_conf[8];
3019         struct rte_eth_dev_info dev_info;
3020         uint16_t max_reta_size;
3021         int ret;
3022
3023         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3024         if (ret != 0)
3025                 return;
3026
3027         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3028         if (res->size == 0 || res->size > max_reta_size) {
3029                 printf("Invalid redirection table size: %u (1-%u)\n",
3030                         res->size, max_reta_size);
3031                 return;
3032         }
3033
3034         memset(reta_conf, 0, sizeof(reta_conf));
3035         if (showport_parse_reta_config(reta_conf, res->size,
3036                                 res->list_of_items) < 0) {
3037                 printf("Invalid string: %s for reta masks\n",
3038                                         res->list_of_items);
3039                 return;
3040         }
3041         port_rss_reta_info(res->port_id, reta_conf, res->size);
3042 }
3043
3044 cmdline_parse_token_string_t cmd_showport_reta_show =
3045         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3046 cmdline_parse_token_string_t cmd_showport_reta_port =
3047         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3048 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3049         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3050 cmdline_parse_token_string_t cmd_showport_reta_rss =
3051         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3052 cmdline_parse_token_string_t cmd_showport_reta_reta =
3053         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3054 cmdline_parse_token_num_t cmd_showport_reta_size =
3055         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3056 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3057         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3058                                         list_of_items, NULL);
3059
3060 cmdline_parse_inst_t cmd_showport_reta = {
3061         .f = cmd_showport_reta_parsed,
3062         .data = NULL,
3063         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3064         .tokens = {
3065                 (void *)&cmd_showport_reta_show,
3066                 (void *)&cmd_showport_reta_port,
3067                 (void *)&cmd_showport_reta_port_id,
3068                 (void *)&cmd_showport_reta_rss,
3069                 (void *)&cmd_showport_reta_reta,
3070                 (void *)&cmd_showport_reta_size,
3071                 (void *)&cmd_showport_reta_list_of_items,
3072                 NULL,
3073         },
3074 };
3075
3076 /* *** Show RSS hash configuration *** */
3077 struct cmd_showport_rss_hash {
3078         cmdline_fixed_string_t show;
3079         cmdline_fixed_string_t port;
3080         portid_t port_id;
3081         cmdline_fixed_string_t rss_hash;
3082         cmdline_fixed_string_t rss_type;
3083         cmdline_fixed_string_t key; /* optional argument */
3084 };
3085
3086 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3087                                 __rte_unused struct cmdline *cl,
3088                                 void *show_rss_key)
3089 {
3090         struct cmd_showport_rss_hash *res = parsed_result;
3091
3092         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3093 }
3094
3095 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3096         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3097 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3098         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3099 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3100         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3101                                  RTE_UINT16);
3102 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3103         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3104                                  "rss-hash");
3105 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3106         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3107
3108 cmdline_parse_inst_t cmd_showport_rss_hash = {
3109         .f = cmd_showport_rss_hash_parsed,
3110         .data = NULL,
3111         .help_str = "show port <port_id> rss-hash",
3112         .tokens = {
3113                 (void *)&cmd_showport_rss_hash_show,
3114                 (void *)&cmd_showport_rss_hash_port,
3115                 (void *)&cmd_showport_rss_hash_port_id,
3116                 (void *)&cmd_showport_rss_hash_rss_hash,
3117                 NULL,
3118         },
3119 };
3120
3121 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3122         .f = cmd_showport_rss_hash_parsed,
3123         .data = (void *)1,
3124         .help_str = "show port <port_id> rss-hash key",
3125         .tokens = {
3126                 (void *)&cmd_showport_rss_hash_show,
3127                 (void *)&cmd_showport_rss_hash_port,
3128                 (void *)&cmd_showport_rss_hash_port_id,
3129                 (void *)&cmd_showport_rss_hash_rss_hash,
3130                 (void *)&cmd_showport_rss_hash_rss_key,
3131                 NULL,
3132         },
3133 };
3134
3135 /* *** Configure DCB *** */
3136 struct cmd_config_dcb {
3137         cmdline_fixed_string_t port;
3138         cmdline_fixed_string_t config;
3139         portid_t port_id;
3140         cmdline_fixed_string_t dcb;
3141         cmdline_fixed_string_t vt;
3142         cmdline_fixed_string_t vt_en;
3143         uint8_t num_tcs;
3144         cmdline_fixed_string_t pfc;
3145         cmdline_fixed_string_t pfc_en;
3146 };
3147
3148 static void
3149 cmd_config_dcb_parsed(void *parsed_result,
3150                         __rte_unused struct cmdline *cl,
3151                         __rte_unused void *data)
3152 {
3153         struct cmd_config_dcb *res = parsed_result;
3154         portid_t port_id = res->port_id;
3155         struct rte_port *port;
3156         uint8_t pfc_en;
3157         int ret;
3158
3159         port = &ports[port_id];
3160         /** Check if the port is not started **/
3161         if (port->port_status != RTE_PORT_STOPPED) {
3162                 printf("Please stop port %d first\n", port_id);
3163                 return;
3164         }
3165
3166         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3167                 printf("The invalid number of traffic class,"
3168                         " only 4 or 8 allowed.\n");
3169                 return;
3170         }
3171
3172         if (nb_fwd_lcores < res->num_tcs) {
3173                 printf("nb_cores shouldn't be less than number of TCs.\n");
3174                 return;
3175         }
3176         if (!strncmp(res->pfc_en, "on", 2))
3177                 pfc_en = 1;
3178         else
3179                 pfc_en = 0;
3180
3181         /* DCB in VT mode */
3182         if (!strncmp(res->vt_en, "on", 2))
3183                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3184                                 (enum rte_eth_nb_tcs)res->num_tcs,
3185                                 pfc_en);
3186         else
3187                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3188                                 (enum rte_eth_nb_tcs)res->num_tcs,
3189                                 pfc_en);
3190
3191
3192         if (ret != 0) {
3193                 printf("Cannot initialize network ports.\n");
3194                 return;
3195         }
3196
3197         cmd_reconfig_device_queue(port_id, 1, 1);
3198 }
3199
3200 cmdline_parse_token_string_t cmd_config_dcb_port =
3201         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3202 cmdline_parse_token_string_t cmd_config_dcb_config =
3203         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3204 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3205         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3206 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3207         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3208 cmdline_parse_token_string_t cmd_config_dcb_vt =
3209         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3210 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3211         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3212 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3213         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3214 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3215         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3216 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3217         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3218
3219 cmdline_parse_inst_t cmd_config_dcb = {
3220         .f = cmd_config_dcb_parsed,
3221         .data = NULL,
3222         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3223         .tokens = {
3224                 (void *)&cmd_config_dcb_port,
3225                 (void *)&cmd_config_dcb_config,
3226                 (void *)&cmd_config_dcb_port_id,
3227                 (void *)&cmd_config_dcb_dcb,
3228                 (void *)&cmd_config_dcb_vt,
3229                 (void *)&cmd_config_dcb_vt_en,
3230                 (void *)&cmd_config_dcb_num_tcs,
3231                 (void *)&cmd_config_dcb_pfc,
3232                 (void *)&cmd_config_dcb_pfc_en,
3233                 NULL,
3234         },
3235 };
3236
3237 /* *** configure number of packets per burst *** */
3238 struct cmd_config_burst {
3239         cmdline_fixed_string_t port;
3240         cmdline_fixed_string_t keyword;
3241         cmdline_fixed_string_t all;
3242         cmdline_fixed_string_t name;
3243         uint16_t value;
3244 };
3245
3246 static void
3247 cmd_config_burst_parsed(void *parsed_result,
3248                         __rte_unused struct cmdline *cl,
3249                         __rte_unused void *data)
3250 {
3251         struct cmd_config_burst *res = parsed_result;
3252         struct rte_eth_dev_info dev_info;
3253         uint16_t rec_nb_pkts;
3254         int ret;
3255
3256         if (!all_ports_stopped()) {
3257                 printf("Please stop all ports first\n");
3258                 return;
3259         }
3260
3261         if (!strcmp(res->name, "burst")) {
3262                 if (res->value == 0) {
3263                         /* If user gives a value of zero, query the PMD for
3264                          * its recommended Rx burst size. Testpmd uses a single
3265                          * size for all ports, so assume all ports are the same
3266                          * NIC model and use the values from Port 0.
3267                          */
3268                         ret = eth_dev_info_get_print_err(0, &dev_info);
3269                         if (ret != 0)
3270                                 return;
3271
3272                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3273
3274                         if (rec_nb_pkts == 0) {
3275                                 printf("PMD does not recommend a burst size.\n"
3276                                         "User provided value must be between"
3277                                         " 1 and %d\n", MAX_PKT_BURST);
3278                                 return;
3279                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3280                                 printf("PMD recommended burst size of %d"
3281                                         " exceeds maximum value of %d\n",
3282                                         rec_nb_pkts, MAX_PKT_BURST);
3283                                 return;
3284                         }
3285                         printf("Using PMD-provided burst value of %d\n",
3286                                 rec_nb_pkts);
3287                         nb_pkt_per_burst = rec_nb_pkts;
3288                 } else if (res->value > MAX_PKT_BURST) {
3289                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3290                         return;
3291                 } else
3292                         nb_pkt_per_burst = res->value;
3293         } else {
3294                 printf("Unknown parameter\n");
3295                 return;
3296         }
3297
3298         init_port_config();
3299
3300         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3301 }
3302
3303 cmdline_parse_token_string_t cmd_config_burst_port =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3305 cmdline_parse_token_string_t cmd_config_burst_keyword =
3306         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3307 cmdline_parse_token_string_t cmd_config_burst_all =
3308         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3309 cmdline_parse_token_string_t cmd_config_burst_name =
3310         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3311 cmdline_parse_token_num_t cmd_config_burst_value =
3312         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3313
3314 cmdline_parse_inst_t cmd_config_burst = {
3315         .f = cmd_config_burst_parsed,
3316         .data = NULL,
3317         .help_str = "port config all burst <value>",
3318         .tokens = {
3319                 (void *)&cmd_config_burst_port,
3320                 (void *)&cmd_config_burst_keyword,
3321                 (void *)&cmd_config_burst_all,
3322                 (void *)&cmd_config_burst_name,
3323                 (void *)&cmd_config_burst_value,
3324                 NULL,
3325         },
3326 };
3327
3328 /* *** configure rx/tx queues *** */
3329 struct cmd_config_thresh {
3330         cmdline_fixed_string_t port;
3331         cmdline_fixed_string_t keyword;
3332         cmdline_fixed_string_t all;
3333         cmdline_fixed_string_t name;
3334         uint8_t value;
3335 };
3336
3337 static void
3338 cmd_config_thresh_parsed(void *parsed_result,
3339                         __rte_unused struct cmdline *cl,
3340                         __rte_unused void *data)
3341 {
3342         struct cmd_config_thresh *res = parsed_result;
3343
3344         if (!all_ports_stopped()) {
3345                 printf("Please stop all ports first\n");
3346                 return;
3347         }
3348
3349         if (!strcmp(res->name, "txpt"))
3350                 tx_pthresh = res->value;
3351         else if(!strcmp(res->name, "txht"))
3352                 tx_hthresh = res->value;
3353         else if(!strcmp(res->name, "txwt"))
3354                 tx_wthresh = res->value;
3355         else if(!strcmp(res->name, "rxpt"))
3356                 rx_pthresh = res->value;
3357         else if(!strcmp(res->name, "rxht"))
3358                 rx_hthresh = res->value;
3359         else if(!strcmp(res->name, "rxwt"))
3360                 rx_wthresh = res->value;
3361         else {
3362                 printf("Unknown parameter\n");
3363                 return;
3364         }
3365
3366         init_port_config();
3367
3368         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3369 }
3370
3371 cmdline_parse_token_string_t cmd_config_thresh_port =
3372         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3373 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3374         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3375 cmdline_parse_token_string_t cmd_config_thresh_all =
3376         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3377 cmdline_parse_token_string_t cmd_config_thresh_name =
3378         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3379                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3380 cmdline_parse_token_num_t cmd_config_thresh_value =
3381         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3382
3383 cmdline_parse_inst_t cmd_config_thresh = {
3384         .f = cmd_config_thresh_parsed,
3385         .data = NULL,
3386         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3387         .tokens = {
3388                 (void *)&cmd_config_thresh_port,
3389                 (void *)&cmd_config_thresh_keyword,
3390                 (void *)&cmd_config_thresh_all,
3391                 (void *)&cmd_config_thresh_name,
3392                 (void *)&cmd_config_thresh_value,
3393                 NULL,
3394         },
3395 };
3396
3397 /* *** configure free/rs threshold *** */
3398 struct cmd_config_threshold {
3399         cmdline_fixed_string_t port;
3400         cmdline_fixed_string_t keyword;
3401         cmdline_fixed_string_t all;
3402         cmdline_fixed_string_t name;
3403         uint16_t value;
3404 };
3405
3406 static void
3407 cmd_config_threshold_parsed(void *parsed_result,
3408                         __rte_unused struct cmdline *cl,
3409                         __rte_unused void *data)
3410 {
3411         struct cmd_config_threshold *res = parsed_result;
3412
3413         if (!all_ports_stopped()) {
3414                 printf("Please stop all ports first\n");
3415                 return;
3416         }
3417
3418         if (!strcmp(res->name, "txfreet"))
3419                 tx_free_thresh = res->value;
3420         else if (!strcmp(res->name, "txrst"))
3421                 tx_rs_thresh = res->value;
3422         else if (!strcmp(res->name, "rxfreet"))
3423                 rx_free_thresh = res->value;
3424         else {
3425                 printf("Unknown parameter\n");
3426                 return;
3427         }
3428
3429         init_port_config();
3430
3431         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3432 }
3433
3434 cmdline_parse_token_string_t cmd_config_threshold_port =
3435         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3436 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3437         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3438                                                                 "config");
3439 cmdline_parse_token_string_t cmd_config_threshold_all =
3440         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3441 cmdline_parse_token_string_t cmd_config_threshold_name =
3442         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3443                                                 "txfreet#txrst#rxfreet");
3444 cmdline_parse_token_num_t cmd_config_threshold_value =
3445         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3446
3447 cmdline_parse_inst_t cmd_config_threshold = {
3448         .f = cmd_config_threshold_parsed,
3449         .data = NULL,
3450         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3451         .tokens = {
3452                 (void *)&cmd_config_threshold_port,
3453                 (void *)&cmd_config_threshold_keyword,
3454                 (void *)&cmd_config_threshold_all,
3455                 (void *)&cmd_config_threshold_name,
3456                 (void *)&cmd_config_threshold_value,
3457                 NULL,
3458         },
3459 };
3460
3461 /* *** stop *** */
3462 struct cmd_stop_result {
3463         cmdline_fixed_string_t stop;
3464 };
3465
3466 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3467                             __rte_unused struct cmdline *cl,
3468                             __rte_unused void *data)
3469 {
3470         stop_packet_forwarding();
3471 }
3472
3473 cmdline_parse_token_string_t cmd_stop_stop =
3474         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3475
3476 cmdline_parse_inst_t cmd_stop = {
3477         .f = cmd_stop_parsed,
3478         .data = NULL,
3479         .help_str = "stop: Stop packet forwarding",
3480         .tokens = {
3481                 (void *)&cmd_stop_stop,
3482                 NULL,
3483         },
3484 };
3485
3486 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3487
3488 unsigned int
3489 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3490                 unsigned int *parsed_items, int check_unique_values)
3491 {
3492         unsigned int nb_item;
3493         unsigned int value;
3494         unsigned int i;
3495         unsigned int j;
3496         int value_ok;
3497         char c;
3498
3499         /*
3500          * First parse all items in the list and store their value.
3501          */
3502         value = 0;
3503         nb_item = 0;
3504         value_ok = 0;
3505         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3506                 c = str[i];
3507                 if ((c >= '0') && (c <= '9')) {
3508                         value = (unsigned int) (value * 10 + (c - '0'));
3509                         value_ok = 1;
3510                         continue;
3511                 }
3512                 if (c != ',') {
3513                         printf("character %c is not a decimal digit\n", c);
3514                         return 0;
3515                 }
3516                 if (! value_ok) {
3517                         printf("No valid value before comma\n");
3518                         return 0;
3519                 }
3520                 if (nb_item < max_items) {
3521                         parsed_items[nb_item] = value;
3522                         value_ok = 0;
3523                         value = 0;
3524                 }
3525                 nb_item++;
3526         }
3527         if (nb_item >= max_items) {
3528                 printf("Number of %s = %u > %u (maximum items)\n",
3529                        item_name, nb_item + 1, max_items);
3530                 return 0;
3531         }
3532         parsed_items[nb_item++] = value;
3533         if (! check_unique_values)
3534                 return nb_item;
3535
3536         /*
3537          * Then, check that all values in the list are differents.
3538          * No optimization here...
3539          */
3540         for (i = 0; i < nb_item; i++) {
3541                 for (j = i + 1; j < nb_item; j++) {
3542                         if (parsed_items[j] == parsed_items[i]) {
3543                                 printf("duplicated %s %u at index %u and %u\n",
3544                                        item_name, parsed_items[i], i, j);
3545                                 return 0;
3546                         }
3547                 }
3548         }
3549         return nb_item;
3550 }
3551
3552 struct cmd_set_list_result {
3553         cmdline_fixed_string_t cmd_keyword;
3554         cmdline_fixed_string_t list_name;
3555         cmdline_fixed_string_t list_of_items;
3556 };
3557
3558 static void cmd_set_list_parsed(void *parsed_result,
3559                                 __rte_unused struct cmdline *cl,
3560                                 __rte_unused void *data)
3561 {
3562         struct cmd_set_list_result *res;
3563         union {
3564                 unsigned int lcorelist[RTE_MAX_LCORE];
3565                 unsigned int portlist[RTE_MAX_ETHPORTS];
3566         } parsed_items;
3567         unsigned int nb_item;
3568
3569         if (test_done == 0) {
3570                 printf("Please stop forwarding first\n");
3571                 return;
3572         }
3573
3574         res = parsed_result;
3575         if (!strcmp(res->list_name, "corelist")) {
3576                 nb_item = parse_item_list(res->list_of_items, "core",
3577                                           RTE_MAX_LCORE,
3578                                           parsed_items.lcorelist, 1);
3579                 if (nb_item > 0) {
3580                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3581                         fwd_config_setup();
3582                 }
3583                 return;
3584         }
3585         if (!strcmp(res->list_name, "portlist")) {
3586                 nb_item = parse_item_list(res->list_of_items, "port",
3587                                           RTE_MAX_ETHPORTS,
3588                                           parsed_items.portlist, 1);
3589                 if (nb_item > 0) {
3590                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3591                         fwd_config_setup();
3592                 }
3593         }
3594 }
3595
3596 cmdline_parse_token_string_t cmd_set_list_keyword =
3597         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3598                                  "set");
3599 cmdline_parse_token_string_t cmd_set_list_name =
3600         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3601                                  "corelist#portlist");
3602 cmdline_parse_token_string_t cmd_set_list_of_items =
3603         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3604                                  NULL);
3605
3606 cmdline_parse_inst_t cmd_set_fwd_list = {
3607         .f = cmd_set_list_parsed,
3608         .data = NULL,
3609         .help_str = "set corelist|portlist <list0[,list1]*>",
3610         .tokens = {
3611                 (void *)&cmd_set_list_keyword,
3612                 (void *)&cmd_set_list_name,
3613                 (void *)&cmd_set_list_of_items,
3614                 NULL,
3615         },
3616 };
3617
3618 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3619
3620 struct cmd_setmask_result {
3621         cmdline_fixed_string_t set;
3622         cmdline_fixed_string_t mask;
3623         uint64_t hexavalue;
3624 };
3625
3626 static void cmd_set_mask_parsed(void *parsed_result,
3627                                 __rte_unused struct cmdline *cl,
3628                                 __rte_unused void *data)
3629 {
3630         struct cmd_setmask_result *res = parsed_result;
3631
3632         if (test_done == 0) {
3633                 printf("Please stop forwarding first\n");
3634                 return;
3635         }
3636         if (!strcmp(res->mask, "coremask")) {
3637                 set_fwd_lcores_mask(res->hexavalue);
3638                 fwd_config_setup();
3639         } else if (!strcmp(res->mask, "portmask")) {
3640                 set_fwd_ports_mask(res->hexavalue);
3641                 fwd_config_setup();
3642         }
3643 }
3644
3645 cmdline_parse_token_string_t cmd_setmask_set =
3646         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3647 cmdline_parse_token_string_t cmd_setmask_mask =
3648         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3649                                  "coremask#portmask");
3650 cmdline_parse_token_num_t cmd_setmask_value =
3651         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3652
3653 cmdline_parse_inst_t cmd_set_fwd_mask = {
3654         .f = cmd_set_mask_parsed,
3655         .data = NULL,
3656         .help_str = "set coremask|portmask <hexadecimal value>",
3657         .tokens = {
3658                 (void *)&cmd_setmask_set,
3659                 (void *)&cmd_setmask_mask,
3660                 (void *)&cmd_setmask_value,
3661                 NULL,
3662         },
3663 };
3664
3665 /*
3666  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3667  */
3668 struct cmd_set_result {
3669         cmdline_fixed_string_t set;
3670         cmdline_fixed_string_t what;
3671         uint16_t value;
3672 };
3673
3674 static void cmd_set_parsed(void *parsed_result,
3675                            __rte_unused struct cmdline *cl,
3676                            __rte_unused void *data)
3677 {
3678         struct cmd_set_result *res = parsed_result;
3679         if (!strcmp(res->what, "nbport")) {
3680                 set_fwd_ports_number(res->value);
3681                 fwd_config_setup();
3682         } else if (!strcmp(res->what, "nbcore")) {
3683                 set_fwd_lcores_number(res->value);
3684                 fwd_config_setup();
3685         } else if (!strcmp(res->what, "burst"))
3686                 set_nb_pkt_per_burst(res->value);
3687         else if (!strcmp(res->what, "verbose"))
3688                 set_verbose_level(res->value);
3689 }
3690
3691 cmdline_parse_token_string_t cmd_set_set =
3692         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3693 cmdline_parse_token_string_t cmd_set_what =
3694         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3695                                  "nbport#nbcore#burst#verbose");
3696 cmdline_parse_token_num_t cmd_set_value =
3697         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3698
3699 cmdline_parse_inst_t cmd_set_numbers = {
3700         .f = cmd_set_parsed,
3701         .data = NULL,
3702         .help_str = "set nbport|nbcore|burst|verbose <value>",
3703         .tokens = {
3704                 (void *)&cmd_set_set,
3705                 (void *)&cmd_set_what,
3706                 (void *)&cmd_set_value,
3707                 NULL,
3708         },
3709 };
3710
3711 /* *** SET LOG LEVEL CONFIGURATION *** */
3712
3713 struct cmd_set_log_result {
3714         cmdline_fixed_string_t set;
3715         cmdline_fixed_string_t log;
3716         cmdline_fixed_string_t type;
3717         uint32_t level;
3718 };
3719
3720 static void
3721 cmd_set_log_parsed(void *parsed_result,
3722                    __rte_unused struct cmdline *cl,
3723                    __rte_unused void *data)
3724 {
3725         struct cmd_set_log_result *res;
3726         int ret;
3727
3728         res = parsed_result;
3729         if (!strcmp(res->type, "global"))
3730                 rte_log_set_global_level(res->level);
3731         else {
3732                 ret = rte_log_set_level_regexp(res->type, res->level);
3733                 if (ret < 0)
3734                         printf("Unable to set log level\n");
3735         }
3736 }
3737
3738 cmdline_parse_token_string_t cmd_set_log_set =
3739         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3740 cmdline_parse_token_string_t cmd_set_log_log =
3741         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3742 cmdline_parse_token_string_t cmd_set_log_type =
3743         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3744 cmdline_parse_token_num_t cmd_set_log_level =
3745         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3746
3747 cmdline_parse_inst_t cmd_set_log = {
3748         .f = cmd_set_log_parsed,
3749         .data = NULL,
3750         .help_str = "set log global|<type> <level>",
3751         .tokens = {
3752                 (void *)&cmd_set_log_set,
3753                 (void *)&cmd_set_log_log,
3754                 (void *)&cmd_set_log_type,
3755                 (void *)&cmd_set_log_level,
3756                 NULL,
3757         },
3758 };
3759
3760 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3761
3762 struct cmd_set_rxoffs_result {
3763         cmdline_fixed_string_t cmd_keyword;
3764         cmdline_fixed_string_t rxoffs;
3765         cmdline_fixed_string_t seg_offsets;
3766 };
3767
3768 static void
3769 cmd_set_rxoffs_parsed(void *parsed_result,
3770                       __rte_unused struct cmdline *cl,
3771                       __rte_unused void *data)
3772 {
3773         struct cmd_set_rxoffs_result *res;
3774         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3775         unsigned int nb_segs;
3776
3777         res = parsed_result;
3778         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3779                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3780         if (nb_segs > 0)
3781                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3782 }
3783
3784 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3785         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3786                                  cmd_keyword, "set");
3787 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3789                                  rxoffs, "rxoffs");
3790 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3791         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3792                                  seg_offsets, NULL);
3793
3794 cmdline_parse_inst_t cmd_set_rxoffs = {
3795         .f = cmd_set_rxoffs_parsed,
3796         .data = NULL,
3797         .help_str = "set rxoffs <len0[,len1]*>",
3798         .tokens = {
3799                 (void *)&cmd_set_rxoffs_keyword,
3800                 (void *)&cmd_set_rxoffs_name,
3801                 (void *)&cmd_set_rxoffs_offsets,
3802                 NULL,
3803         },
3804 };
3805
3806 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3807
3808 struct cmd_set_rxpkts_result {
3809         cmdline_fixed_string_t cmd_keyword;
3810         cmdline_fixed_string_t rxpkts;
3811         cmdline_fixed_string_t seg_lengths;
3812 };
3813
3814 static void
3815 cmd_set_rxpkts_parsed(void *parsed_result,
3816                       __rte_unused struct cmdline *cl,
3817                       __rte_unused void *data)
3818 {
3819         struct cmd_set_rxpkts_result *res;
3820         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3821         unsigned int nb_segs;
3822
3823         res = parsed_result;
3824         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3825                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3826         if (nb_segs > 0)
3827                 set_rx_pkt_segments(seg_lengths, nb_segs);
3828 }
3829
3830 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3831         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3832                                  cmd_keyword, "set");
3833 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3835                                  rxpkts, "rxpkts");
3836 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3837         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3838                                  seg_lengths, NULL);
3839
3840 cmdline_parse_inst_t cmd_set_rxpkts = {
3841         .f = cmd_set_rxpkts_parsed,
3842         .data = NULL,
3843         .help_str = "set rxpkts <len0[,len1]*>",
3844         .tokens = {
3845                 (void *)&cmd_set_rxpkts_keyword,
3846                 (void *)&cmd_set_rxpkts_name,
3847                 (void *)&cmd_set_rxpkts_lengths,
3848                 NULL,
3849         },
3850 };
3851
3852 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3853
3854 struct cmd_set_txpkts_result {
3855         cmdline_fixed_string_t cmd_keyword;
3856         cmdline_fixed_string_t txpkts;
3857         cmdline_fixed_string_t seg_lengths;
3858 };
3859
3860 static void
3861 cmd_set_txpkts_parsed(void *parsed_result,
3862                       __rte_unused struct cmdline *cl,
3863                       __rte_unused void *data)
3864 {
3865         struct cmd_set_txpkts_result *res;
3866         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3867         unsigned int nb_segs;
3868
3869         res = parsed_result;
3870         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3871                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3872         if (nb_segs > 0)
3873                 set_tx_pkt_segments(seg_lengths, nb_segs);
3874 }
3875
3876 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3877         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3878                                  cmd_keyword, "set");
3879 cmdline_parse_token_string_t cmd_set_txpkts_name =
3880         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3881                                  txpkts, "txpkts");
3882 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3884                                  seg_lengths, NULL);
3885
3886 cmdline_parse_inst_t cmd_set_txpkts = {
3887         .f = cmd_set_txpkts_parsed,
3888         .data = NULL,
3889         .help_str = "set txpkts <len0[,len1]*>",
3890         .tokens = {
3891                 (void *)&cmd_set_txpkts_keyword,
3892                 (void *)&cmd_set_txpkts_name,
3893                 (void *)&cmd_set_txpkts_lengths,
3894                 NULL,
3895         },
3896 };
3897
3898 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3899
3900 struct cmd_set_txsplit_result {
3901         cmdline_fixed_string_t cmd_keyword;
3902         cmdline_fixed_string_t txsplit;
3903         cmdline_fixed_string_t mode;
3904 };
3905
3906 static void
3907 cmd_set_txsplit_parsed(void *parsed_result,
3908                       __rte_unused struct cmdline *cl,
3909                       __rte_unused void *data)
3910 {
3911         struct cmd_set_txsplit_result *res;
3912
3913         res = parsed_result;
3914         set_tx_pkt_split(res->mode);
3915 }
3916
3917 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3918         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3919                                  cmd_keyword, "set");
3920 cmdline_parse_token_string_t cmd_set_txsplit_name =
3921         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3922                                  txsplit, "txsplit");
3923 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3924         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3925                                  mode, NULL);
3926
3927 cmdline_parse_inst_t cmd_set_txsplit = {
3928         .f = cmd_set_txsplit_parsed,
3929         .data = NULL,
3930         .help_str = "set txsplit on|off|rand",
3931         .tokens = {
3932                 (void *)&cmd_set_txsplit_keyword,
3933                 (void *)&cmd_set_txsplit_name,
3934                 (void *)&cmd_set_txsplit_mode,
3935                 NULL,
3936         },
3937 };
3938
3939 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3940
3941 struct cmd_set_txtimes_result {
3942         cmdline_fixed_string_t cmd_keyword;
3943         cmdline_fixed_string_t txtimes;
3944         cmdline_fixed_string_t tx_times;
3945 };
3946
3947 static void
3948 cmd_set_txtimes_parsed(void *parsed_result,
3949                        __rte_unused struct cmdline *cl,
3950                        __rte_unused void *data)
3951 {
3952         struct cmd_set_txtimes_result *res;
3953         unsigned int tx_times[2] = {0, 0};
3954         unsigned int n_times;
3955
3956         res = parsed_result;
3957         n_times = parse_item_list(res->tx_times, "tx times",
3958                                   2, tx_times, 0);
3959         if (n_times == 2)
3960                 set_tx_pkt_times(tx_times);
3961 }
3962
3963 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3964         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3965                                  cmd_keyword, "set");
3966 cmdline_parse_token_string_t cmd_set_txtimes_name =
3967         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3968                                  txtimes, "txtimes");
3969 cmdline_parse_token_string_t cmd_set_txtimes_value =
3970         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3971                                  tx_times, NULL);
3972
3973 cmdline_parse_inst_t cmd_set_txtimes = {
3974         .f = cmd_set_txtimes_parsed,
3975         .data = NULL,
3976         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3977         .tokens = {
3978                 (void *)&cmd_set_txtimes_keyword,
3979                 (void *)&cmd_set_txtimes_name,
3980                 (void *)&cmd_set_txtimes_value,
3981                 NULL,
3982         },
3983 };
3984
3985 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3986 struct cmd_rx_vlan_filter_all_result {
3987         cmdline_fixed_string_t rx_vlan;
3988         cmdline_fixed_string_t what;
3989         cmdline_fixed_string_t all;
3990         portid_t port_id;
3991 };
3992
3993 static void
3994 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3995                               __rte_unused struct cmdline *cl,
3996                               __rte_unused void *data)
3997 {
3998         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3999
4000         if (!strcmp(res->what, "add"))
4001                 rx_vlan_all_filter_set(res->port_id, 1);
4002         else
4003                 rx_vlan_all_filter_set(res->port_id, 0);
4004 }
4005
4006 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4007         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4008                                  rx_vlan, "rx_vlan");
4009 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4010         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4011                                  what, "add#rm");
4012 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4013         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4014                                  all, "all");
4015 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4016         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4017                               port_id, RTE_UINT16);
4018
4019 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4020         .f = cmd_rx_vlan_filter_all_parsed,
4021         .data = NULL,
4022         .help_str = "rx_vlan add|rm all <port_id>: "
4023                 "Add/Remove all identifiers to/from the set of VLAN "
4024                 "identifiers filtered by a port",
4025         .tokens = {
4026                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4027                 (void *)&cmd_rx_vlan_filter_all_what,
4028                 (void *)&cmd_rx_vlan_filter_all_all,
4029                 (void *)&cmd_rx_vlan_filter_all_portid,
4030                 NULL,
4031         },
4032 };
4033
4034 /* *** VLAN OFFLOAD SET ON A PORT *** */
4035 struct cmd_vlan_offload_result {
4036         cmdline_fixed_string_t vlan;
4037         cmdline_fixed_string_t set;
4038         cmdline_fixed_string_t vlan_type;
4039         cmdline_fixed_string_t what;
4040         cmdline_fixed_string_t on;
4041         cmdline_fixed_string_t port_id;
4042 };
4043
4044 static void
4045 cmd_vlan_offload_parsed(void *parsed_result,
4046                           __rte_unused struct cmdline *cl,
4047                           __rte_unused void *data)
4048 {
4049         int on;
4050         struct cmd_vlan_offload_result *res = parsed_result;
4051         char *str;
4052         int i, len = 0;
4053         portid_t port_id = 0;
4054         unsigned int tmp;
4055
4056         str = res->port_id;
4057         len = strnlen(str, STR_TOKEN_SIZE);
4058         i = 0;
4059         /* Get port_id first */
4060         while(i < len){
4061                 if(str[i] == ',')
4062                         break;
4063
4064                 i++;
4065         }
4066         str[i]='\0';
4067         tmp = strtoul(str, NULL, 0);
4068         /* If port_id greater that what portid_t can represent, return */
4069         if(tmp >= RTE_MAX_ETHPORTS)
4070                 return;
4071         port_id = (portid_t)tmp;
4072
4073         if (!strcmp(res->on, "on"))
4074                 on = 1;
4075         else
4076                 on = 0;
4077
4078         if (!strcmp(res->what, "strip"))
4079                 rx_vlan_strip_set(port_id,  on);
4080         else if(!strcmp(res->what, "stripq")){
4081                 uint16_t queue_id = 0;
4082
4083                 /* No queue_id, return */
4084                 if(i + 1 >= len) {
4085                         printf("must specify (port,queue_id)\n");
4086                         return;
4087                 }
4088                 tmp = strtoul(str + i + 1, NULL, 0);
4089                 /* If queue_id greater that what 16-bits can represent, return */
4090                 if(tmp > 0xffff)
4091                         return;
4092
4093                 queue_id = (uint16_t)tmp;
4094                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4095         }
4096         else if (!strcmp(res->what, "filter"))
4097                 rx_vlan_filter_set(port_id, on);
4098         else if (!strcmp(res->what, "qinq_strip"))
4099                 rx_vlan_qinq_strip_set(port_id, on);
4100         else
4101                 vlan_extend_set(port_id, on);
4102
4103         return;
4104 }
4105
4106 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4107         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4108                                  vlan, "vlan");
4109 cmdline_parse_token_string_t cmd_vlan_offload_set =
4110         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4111                                  set, "set");
4112 cmdline_parse_token_string_t cmd_vlan_offload_what =
4113         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4114                                 what, "strip#filter#qinq_strip#extend#stripq");
4115 cmdline_parse_token_string_t cmd_vlan_offload_on =
4116         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4117                               on, "on#off");
4118 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4119         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4120                               port_id, NULL);
4121
4122 cmdline_parse_inst_t cmd_vlan_offload = {
4123         .f = cmd_vlan_offload_parsed,
4124         .data = NULL,
4125         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4126                 "<port_id[,queue_id]>: "
4127                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4128         .tokens = {
4129                 (void *)&cmd_vlan_offload_vlan,
4130                 (void *)&cmd_vlan_offload_set,
4131                 (void *)&cmd_vlan_offload_what,
4132                 (void *)&cmd_vlan_offload_on,
4133                 (void *)&cmd_vlan_offload_portid,
4134                 NULL,
4135         },
4136 };
4137
4138 /* *** VLAN TPID SET ON A PORT *** */
4139 struct cmd_vlan_tpid_result {
4140         cmdline_fixed_string_t vlan;
4141         cmdline_fixed_string_t set;
4142         cmdline_fixed_string_t vlan_type;
4143         cmdline_fixed_string_t what;
4144         uint16_t tp_id;
4145         portid_t port_id;
4146 };
4147
4148 static void
4149 cmd_vlan_tpid_parsed(void *parsed_result,
4150                           __rte_unused struct cmdline *cl,
4151                           __rte_unused void *data)
4152 {
4153         struct cmd_vlan_tpid_result *res = parsed_result;
4154         enum rte_vlan_type vlan_type;
4155
4156         if (!strcmp(res->vlan_type, "inner"))
4157                 vlan_type = ETH_VLAN_TYPE_INNER;
4158         else if (!strcmp(res->vlan_type, "outer"))
4159                 vlan_type = ETH_VLAN_TYPE_OUTER;
4160         else {
4161                 printf("Unknown vlan type\n");
4162                 return;
4163         }
4164         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4165 }
4166
4167 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4168         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4169                                  vlan, "vlan");
4170 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4171         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4172                                  set, "set");
4173 cmdline_parse_token_string_t cmd_vlan_type =
4174         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4175                                  vlan_type, "inner#outer");
4176 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4177         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4178                                  what, "tpid");
4179 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4180         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4181                               tp_id, RTE_UINT16);
4182 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4183         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4184                               port_id, RTE_UINT16);
4185
4186 cmdline_parse_inst_t cmd_vlan_tpid = {
4187         .f = cmd_vlan_tpid_parsed,
4188         .data = NULL,
4189         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4190                 "Set the VLAN Ether type",
4191         .tokens = {
4192                 (void *)&cmd_vlan_tpid_vlan,
4193                 (void *)&cmd_vlan_tpid_set,
4194                 (void *)&cmd_vlan_type,
4195                 (void *)&cmd_vlan_tpid_what,
4196                 (void *)&cmd_vlan_tpid_tpid,
4197                 (void *)&cmd_vlan_tpid_portid,
4198                 NULL,
4199         },
4200 };
4201
4202 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4203 struct cmd_rx_vlan_filter_result {
4204         cmdline_fixed_string_t rx_vlan;
4205         cmdline_fixed_string_t what;
4206         uint16_t vlan_id;
4207         portid_t port_id;
4208 };
4209
4210 static void
4211 cmd_rx_vlan_filter_parsed(void *parsed_result,
4212                           __rte_unused struct cmdline *cl,
4213                           __rte_unused void *data)
4214 {
4215         struct cmd_rx_vlan_filter_result *res = parsed_result;
4216
4217         if (!strcmp(res->what, "add"))
4218                 rx_vft_set(res->port_id, res->vlan_id, 1);
4219         else
4220                 rx_vft_set(res->port_id, res->vlan_id, 0);
4221 }
4222
4223 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4224         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4225                                  rx_vlan, "rx_vlan");
4226 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4227         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4228                                  what, "add#rm");
4229 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4230         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4231                               vlan_id, RTE_UINT16);
4232 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4233         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4234                               port_id, RTE_UINT16);
4235
4236 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4237         .f = cmd_rx_vlan_filter_parsed,
4238         .data = NULL,
4239         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4240                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4241                 "identifiers filtered by a port",
4242         .tokens = {
4243                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4244                 (void *)&cmd_rx_vlan_filter_what,
4245                 (void *)&cmd_rx_vlan_filter_vlanid,
4246                 (void *)&cmd_rx_vlan_filter_portid,
4247                 NULL,
4248         },
4249 };
4250
4251 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4252 struct cmd_tx_vlan_set_result {
4253         cmdline_fixed_string_t tx_vlan;
4254         cmdline_fixed_string_t set;
4255         portid_t port_id;
4256         uint16_t vlan_id;
4257 };
4258
4259 static void
4260 cmd_tx_vlan_set_parsed(void *parsed_result,
4261                        __rte_unused struct cmdline *cl,
4262                        __rte_unused void *data)
4263 {
4264         struct cmd_tx_vlan_set_result *res = parsed_result;
4265
4266         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4267                 return;
4268
4269         if (!port_is_stopped(res->port_id)) {
4270                 printf("Please stop port %d first\n", res->port_id);
4271                 return;
4272         }
4273
4274         tx_vlan_set(res->port_id, res->vlan_id);
4275
4276         cmd_reconfig_device_queue(res->port_id, 1, 1);
4277 }
4278
4279 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4280         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4281                                  tx_vlan, "tx_vlan");
4282 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4283         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4284                                  set, "set");
4285 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4286         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4287                               port_id, RTE_UINT16);
4288 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4290                               vlan_id, RTE_UINT16);
4291
4292 cmdline_parse_inst_t cmd_tx_vlan_set = {
4293         .f = cmd_tx_vlan_set_parsed,
4294         .data = NULL,
4295         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4296                 "Enable hardware insertion of a single VLAN header "
4297                 "with a given TAG Identifier in packets sent on a port",
4298         .tokens = {
4299                 (void *)&cmd_tx_vlan_set_tx_vlan,
4300                 (void *)&cmd_tx_vlan_set_set,
4301                 (void *)&cmd_tx_vlan_set_portid,
4302                 (void *)&cmd_tx_vlan_set_vlanid,
4303                 NULL,
4304         },
4305 };
4306
4307 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4308 struct cmd_tx_vlan_set_qinq_result {
4309         cmdline_fixed_string_t tx_vlan;
4310         cmdline_fixed_string_t set;
4311         portid_t port_id;
4312         uint16_t vlan_id;
4313         uint16_t vlan_id_outer;
4314 };
4315
4316 static void
4317 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4318                             __rte_unused struct cmdline *cl,
4319                             __rte_unused void *data)
4320 {
4321         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4322
4323         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4324                 return;
4325
4326         if (!port_is_stopped(res->port_id)) {
4327                 printf("Please stop port %d first\n", res->port_id);
4328                 return;
4329         }
4330
4331         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4332
4333         cmd_reconfig_device_queue(res->port_id, 1, 1);
4334 }
4335
4336 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4337         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4338                 tx_vlan, "tx_vlan");
4339 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4340         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4341                 set, "set");
4342 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4343         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4344                 port_id, RTE_UINT16);
4345 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4346         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4347                 vlan_id, RTE_UINT16);
4348 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4349         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4350                 vlan_id_outer, RTE_UINT16);
4351
4352 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4353         .f = cmd_tx_vlan_set_qinq_parsed,
4354         .data = NULL,
4355         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4356                 "Enable hardware insertion of double VLAN header "
4357                 "with given TAG Identifiers in packets sent on a port",
4358         .tokens = {
4359                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4360                 (void *)&cmd_tx_vlan_set_qinq_set,
4361                 (void *)&cmd_tx_vlan_set_qinq_portid,
4362                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4363                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4364                 NULL,
4365         },
4366 };
4367
4368 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4369 struct cmd_tx_vlan_set_pvid_result {
4370         cmdline_fixed_string_t tx_vlan;
4371         cmdline_fixed_string_t set;
4372         cmdline_fixed_string_t pvid;
4373         portid_t port_id;
4374         uint16_t vlan_id;
4375         cmdline_fixed_string_t mode;
4376 };
4377
4378 static void
4379 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4380                             __rte_unused struct cmdline *cl,
4381                             __rte_unused void *data)
4382 {
4383         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4384
4385         if (strcmp(res->mode, "on") == 0)
4386                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4387         else
4388                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4389 }
4390
4391 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4392         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4393                                  tx_vlan, "tx_vlan");
4394 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4395         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4396                                  set, "set");
4397 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4398         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4399                                  pvid, "pvid");
4400 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4401         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4402                              port_id, RTE_UINT16);
4403 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4404         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4405                               vlan_id, RTE_UINT16);
4406 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4407         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4408                                  mode, "on#off");
4409
4410 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4411         .f = cmd_tx_vlan_set_pvid_parsed,
4412         .data = NULL,
4413         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4414         .tokens = {
4415                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4416                 (void *)&cmd_tx_vlan_set_pvid_set,
4417                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4418                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4419                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4420                 (void *)&cmd_tx_vlan_set_pvid_mode,
4421                 NULL,
4422         },
4423 };
4424
4425 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4426 struct cmd_tx_vlan_reset_result {
4427         cmdline_fixed_string_t tx_vlan;
4428         cmdline_fixed_string_t reset;
4429         portid_t port_id;
4430 };
4431
4432 static void
4433 cmd_tx_vlan_reset_parsed(void *parsed_result,
4434                          __rte_unused struct cmdline *cl,
4435                          __rte_unused void *data)
4436 {
4437         struct cmd_tx_vlan_reset_result *res = parsed_result;
4438
4439         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4440                 return;
4441
4442         if (!port_is_stopped(res->port_id)) {
4443                 printf("Please stop port %d first\n", res->port_id);
4444                 return;
4445         }
4446
4447         tx_vlan_reset(res->port_id);
4448
4449         cmd_reconfig_device_queue(res->port_id, 1, 1);
4450 }
4451
4452 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4453         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4454                                  tx_vlan, "tx_vlan");
4455 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4457                                  reset, "reset");
4458 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4459         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4460                               port_id, RTE_UINT16);
4461
4462 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4463         .f = cmd_tx_vlan_reset_parsed,
4464         .data = NULL,
4465         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4466                 "VLAN header in packets sent on a port",
4467         .tokens = {
4468                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4469                 (void *)&cmd_tx_vlan_reset_reset,
4470                 (void *)&cmd_tx_vlan_reset_portid,
4471                 NULL,
4472         },
4473 };
4474
4475
4476 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4477 struct cmd_csum_result {
4478         cmdline_fixed_string_t csum;
4479         cmdline_fixed_string_t mode;
4480         cmdline_fixed_string_t proto;
4481         cmdline_fixed_string_t hwsw;
4482         portid_t port_id;
4483 };
4484
4485 static void
4486 csum_show(int port_id)
4487 {
4488         struct rte_eth_dev_info dev_info;
4489         uint64_t tx_offloads;
4490         int ret;
4491
4492         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4493         printf("Parse tunnel is %s\n",
4494                 (ports[port_id].parse_tunnel) ? "on" : "off");
4495         printf("IP checksum offload is %s\n",
4496                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4497         printf("UDP checksum offload is %s\n",
4498                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4499         printf("TCP checksum offload is %s\n",
4500                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4501         printf("SCTP checksum offload is %s\n",
4502                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4503         printf("Outer-Ip checksum offload is %s\n",
4504                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4505         printf("Outer-Udp checksum offload is %s\n",
4506                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4507
4508         /* display warnings if configuration is not supported by the NIC */
4509         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4510         if (ret != 0)
4511                 return;
4512
4513         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4514                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4515                 printf("Warning: hardware IP checksum enabled but not "
4516                         "supported by port %d\n", port_id);
4517         }
4518         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4519                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4520                 printf("Warning: hardware UDP checksum enabled but not "
4521                         "supported by port %d\n", port_id);
4522         }
4523         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4524                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4525                 printf("Warning: hardware TCP checksum enabled but not "
4526                         "supported by port %d\n", port_id);
4527         }
4528         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4529                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4530                 printf("Warning: hardware SCTP checksum enabled but not "
4531                         "supported by port %d\n", port_id);
4532         }
4533         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4534                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4535                 printf("Warning: hardware outer IP checksum enabled but not "
4536                         "supported by port %d\n", port_id);
4537         }
4538         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4539                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4540                         == 0) {
4541                 printf("Warning: hardware outer UDP checksum enabled but not "
4542                         "supported by port %d\n", port_id);
4543         }
4544 }
4545
4546 static void
4547 cmd_config_queue_tx_offloads(struct rte_port *port)
4548 {
4549         int k;
4550
4551         /* Apply queue tx offloads configuration */
4552         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4553                 port->tx_conf[k].offloads =
4554                         port->dev_conf.txmode.offloads;
4555 }
4556
4557 static void
4558 cmd_csum_parsed(void *parsed_result,
4559                        __rte_unused struct cmdline *cl,
4560                        __rte_unused void *data)
4561 {
4562         struct cmd_csum_result *res = parsed_result;
4563         int hw = 0;
4564         uint64_t csum_offloads = 0;
4565         struct rte_eth_dev_info dev_info;
4566         int ret;
4567
4568         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4569                 printf("invalid port %d\n", res->port_id);
4570                 return;
4571         }
4572         if (!port_is_stopped(res->port_id)) {
4573                 printf("Please stop port %d first\n", res->port_id);
4574                 return;
4575         }
4576
4577         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4578         if (ret != 0)
4579                 return;
4580
4581         if (!strcmp(res->mode, "set")) {
4582
4583                 if (!strcmp(res->hwsw, "hw"))
4584                         hw = 1;
4585
4586                 if (!strcmp(res->proto, "ip")) {
4587                         if (hw == 0 || (dev_info.tx_offload_capa &
4588                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4589                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4590                         } else {
4591                                 printf("IP checksum offload is not supported "
4592                                        "by port %u\n", res->port_id);
4593                         }
4594                 } else if (!strcmp(res->proto, "udp")) {
4595                         if (hw == 0 || (dev_info.tx_offload_capa &
4596                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4597                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4598                         } else {
4599                                 printf("UDP checksum offload is not supported "
4600                                        "by port %u\n", res->port_id);
4601                         }
4602                 } else if (!strcmp(res->proto, "tcp")) {
4603                         if (hw == 0 || (dev_info.tx_offload_capa &
4604                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4605                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4606                         } else {
4607                                 printf("TCP checksum offload is not supported "
4608                                        "by port %u\n", res->port_id);
4609                         }
4610                 } else if (!strcmp(res->proto, "sctp")) {
4611                         if (hw == 0 || (dev_info.tx_offload_capa &
4612                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4613                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4614                         } else {
4615                                 printf("SCTP checksum offload is not supported "
4616                                        "by port %u\n", res->port_id);
4617                         }
4618                 } else if (!strcmp(res->proto, "outer-ip")) {
4619                         if (hw == 0 || (dev_info.tx_offload_capa &
4620                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4621                                 csum_offloads |=
4622                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4623                         } else {
4624                                 printf("Outer IP checksum offload is not "
4625                                        "supported by port %u\n", res->port_id);
4626                         }
4627                 } else if (!strcmp(res->proto, "outer-udp")) {
4628                         if (hw == 0 || (dev_info.tx_offload_capa &
4629                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4630                                 csum_offloads |=
4631                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4632                         } else {
4633                                 printf("Outer UDP checksum offload is not "
4634                                        "supported by port %u\n", res->port_id);
4635                         }
4636                 }
4637
4638                 if (hw) {
4639                         ports[res->port_id].dev_conf.txmode.offloads |=
4640                                                         csum_offloads;
4641                 } else {
4642                         ports[res->port_id].dev_conf.txmode.offloads &=
4643                                                         (~csum_offloads);
4644                 }
4645                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4646         }
4647         csum_show(res->port_id);
4648
4649         cmd_reconfig_device_queue(res->port_id, 1, 1);
4650 }
4651
4652 cmdline_parse_token_string_t cmd_csum_csum =
4653         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4654                                 csum, "csum");
4655 cmdline_parse_token_string_t cmd_csum_mode =
4656         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4657                                 mode, "set");
4658 cmdline_parse_token_string_t cmd_csum_proto =
4659         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4660                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4661 cmdline_parse_token_string_t cmd_csum_hwsw =
4662         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4663                                 hwsw, "hw#sw");
4664 cmdline_parse_token_num_t cmd_csum_portid =
4665         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4666                                 port_id, RTE_UINT16);
4667
4668 cmdline_parse_inst_t cmd_csum_set = {
4669         .f = cmd_csum_parsed,
4670         .data = NULL,
4671         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4672                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4673                 "using csum forward engine",
4674         .tokens = {
4675                 (void *)&cmd_csum_csum,
4676                 (void *)&cmd_csum_mode,
4677                 (void *)&cmd_csum_proto,
4678                 (void *)&cmd_csum_hwsw,
4679                 (void *)&cmd_csum_portid,
4680                 NULL,
4681         },
4682 };
4683
4684 cmdline_parse_token_string_t cmd_csum_mode_show =
4685         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4686                                 mode, "show");
4687
4688 cmdline_parse_inst_t cmd_csum_show = {
4689         .f = cmd_csum_parsed,
4690         .data = NULL,
4691         .help_str = "csum show <port_id>: Show checksum offload configuration",
4692         .tokens = {
4693                 (void *)&cmd_csum_csum,
4694                 (void *)&cmd_csum_mode_show,
4695                 (void *)&cmd_csum_portid,
4696                 NULL,
4697         },
4698 };
4699
4700 /* Enable/disable tunnel parsing */
4701 struct cmd_csum_tunnel_result {
4702         cmdline_fixed_string_t csum;
4703         cmdline_fixed_string_t parse;
4704         cmdline_fixed_string_t onoff;
4705         portid_t port_id;
4706 };
4707
4708 static void
4709 cmd_csum_tunnel_parsed(void *parsed_result,
4710                        __rte_unused struct cmdline *cl,
4711                        __rte_unused void *data)
4712 {
4713         struct cmd_csum_tunnel_result *res = parsed_result;
4714
4715         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4716                 return;
4717
4718         if (!strcmp(res->onoff, "on"))
4719                 ports[res->port_id].parse_tunnel = 1;
4720         else
4721                 ports[res->port_id].parse_tunnel = 0;
4722
4723         csum_show(res->port_id);
4724 }
4725
4726 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4727         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4728                                 csum, "csum");
4729 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4730         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4731                                 parse, "parse-tunnel");
4732 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4733         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4734                                 onoff, "on#off");
4735 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4736         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4737                                 port_id, RTE_UINT16);
4738
4739 cmdline_parse_inst_t cmd_csum_tunnel = {
4740         .f = cmd_csum_tunnel_parsed,
4741         .data = NULL,
4742         .help_str = "csum parse-tunnel on|off <port_id>: "
4743                 "Enable/Disable parsing of tunnels for csum engine",
4744         .tokens = {
4745                 (void *)&cmd_csum_tunnel_csum,
4746                 (void *)&cmd_csum_tunnel_parse,
4747                 (void *)&cmd_csum_tunnel_onoff,
4748                 (void *)&cmd_csum_tunnel_portid,
4749                 NULL,
4750         },
4751 };
4752
4753 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4754 struct cmd_tso_set_result {
4755         cmdline_fixed_string_t tso;
4756         cmdline_fixed_string_t mode;
4757         uint16_t tso_segsz;
4758         portid_t port_id;
4759 };
4760
4761 static void
4762 cmd_tso_set_parsed(void *parsed_result,
4763                        __rte_unused struct cmdline *cl,
4764                        __rte_unused void *data)
4765 {
4766         struct cmd_tso_set_result *res = parsed_result;
4767         struct rte_eth_dev_info dev_info;
4768         int ret;
4769
4770         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4771                 return;
4772         if (!port_is_stopped(res->port_id)) {
4773                 printf("Please stop port %d first\n", res->port_id);
4774                 return;
4775         }
4776
4777         if (!strcmp(res->mode, "set"))
4778                 ports[res->port_id].tso_segsz = res->tso_segsz;
4779
4780         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4781         if (ret != 0)
4782                 return;
4783
4784         if ((ports[res->port_id].tso_segsz != 0) &&
4785                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4786                 printf("Error: TSO is not supported by port %d\n",
4787                        res->port_id);
4788                 return;
4789         }
4790
4791         if (ports[res->port_id].tso_segsz == 0) {
4792                 ports[res->port_id].dev_conf.txmode.offloads &=
4793                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4794                 printf("TSO for non-tunneled packets is disabled\n");
4795         } else {
4796                 ports[res->port_id].dev_conf.txmode.offloads |=
4797                                                 DEV_TX_OFFLOAD_TCP_TSO;
4798                 printf("TSO segment size for non-tunneled packets is %d\n",
4799                         ports[res->port_id].tso_segsz);
4800         }
4801         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4802
4803         /* display warnings if configuration is not supported by the NIC */
4804         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4805         if (ret != 0)
4806                 return;
4807
4808         if ((ports[res->port_id].tso_segsz != 0) &&
4809                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4810                 printf("Warning: TSO enabled but not "
4811                         "supported by port %d\n", res->port_id);
4812         }
4813
4814         cmd_reconfig_device_queue(res->port_id, 1, 1);
4815 }
4816
4817 cmdline_parse_token_string_t cmd_tso_set_tso =
4818         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4819                                 tso, "tso");
4820 cmdline_parse_token_string_t cmd_tso_set_mode =
4821         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4822                                 mode, "set");
4823 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4824         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4825                                 tso_segsz, RTE_UINT16);
4826 cmdline_parse_token_num_t cmd_tso_set_portid =
4827         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4828                                 port_id, RTE_UINT16);
4829
4830 cmdline_parse_inst_t cmd_tso_set = {
4831         .f = cmd_tso_set_parsed,
4832         .data = NULL,
4833         .help_str = "tso set <tso_segsz> <port_id>: "
4834                 "Set TSO segment size of non-tunneled packets for csum engine "
4835                 "(0 to disable)",
4836         .tokens = {
4837                 (void *)&cmd_tso_set_tso,
4838                 (void *)&cmd_tso_set_mode,
4839                 (void *)&cmd_tso_set_tso_segsz,
4840                 (void *)&cmd_tso_set_portid,
4841                 NULL,
4842         },
4843 };
4844
4845 cmdline_parse_token_string_t cmd_tso_show_mode =
4846         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4847                                 mode, "show");
4848
4849
4850 cmdline_parse_inst_t cmd_tso_show = {
4851         .f = cmd_tso_set_parsed,
4852         .data = NULL,
4853         .help_str = "tso show <port_id>: "
4854                 "Show TSO segment size of non-tunneled packets for csum engine",
4855         .tokens = {
4856                 (void *)&cmd_tso_set_tso,
4857                 (void *)&cmd_tso_show_mode,
4858                 (void *)&cmd_tso_set_portid,
4859                 NULL,
4860         },
4861 };
4862
4863 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4864 struct cmd_tunnel_tso_set_result {
4865         cmdline_fixed_string_t tso;
4866         cmdline_fixed_string_t mode;
4867         uint16_t tso_segsz;
4868         portid_t port_id;
4869 };
4870
4871 static struct rte_eth_dev_info
4872 check_tunnel_tso_nic_support(portid_t port_id)
4873 {
4874         struct rte_eth_dev_info dev_info;
4875
4876         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4877                 return dev_info;
4878
4879         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4880                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4881                        "not enabled for port %d\n", port_id);
4882         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4883                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4884                        "not enabled for port %d\n", port_id);
4885         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4886                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4887                        "not enabled for port %d\n", port_id);
4888         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4889                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4890                        "not enabled for port %d\n", port_id);
4891         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4892                 printf("Warning: IP TUNNEL TSO not supported therefore "
4893                        "not enabled for port %d\n", port_id);
4894         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4895                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4896                        "not enabled for port %d\n", port_id);
4897         return dev_info;
4898 }
4899
4900 static void
4901 cmd_tunnel_tso_set_parsed(void *parsed_result,
4902                           __rte_unused struct cmdline *cl,
4903                           __rte_unused void *data)
4904 {
4905         struct cmd_tunnel_tso_set_result *res = parsed_result;
4906         struct rte_eth_dev_info dev_info;
4907
4908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4909                 return;
4910         if (!port_is_stopped(res->port_id)) {
4911                 printf("Please stop port %d first\n", res->port_id);
4912                 return;
4913         }
4914
4915         if (!strcmp(res->mode, "set"))
4916                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4917
4918         dev_info = check_tunnel_tso_nic_support(res->port_id);
4919         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4920                 ports[res->port_id].dev_conf.txmode.offloads &=
4921                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4922                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4923                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4924                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4925                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4926                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4927                 printf("TSO for tunneled packets is disabled\n");
4928         } else {
4929                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4930                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4931                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4932                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4933                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4934                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4935
4936                 ports[res->port_id].dev_conf.txmode.offloads |=
4937                         (tso_offloads & dev_info.tx_offload_capa);
4938                 printf("TSO segment size for tunneled packets is %d\n",
4939                         ports[res->port_id].tunnel_tso_segsz);
4940
4941                 /* Below conditions are needed to make it work:
4942                  * (1) tunnel TSO is supported by the NIC;
4943                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4944                  * are recognized;
4945                  * (3) for tunneled pkts with outer L3 of IPv4,
4946                  * "csum set outer-ip" must be set to hw, because after tso,
4947                  * total_len of outer IP header is changed, and the checksum
4948                  * of outer IP header calculated by sw should be wrong; that
4949                  * is not necessary for IPv6 tunneled pkts because there's no
4950                  * checksum in IP header anymore.
4951                  */
4952
4953                 if (!ports[res->port_id].parse_tunnel)
4954                         printf("Warning: csum parse_tunnel must be set "
4955                                 "so that tunneled packets are recognized\n");
4956                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4957                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4958                         printf("Warning: csum set outer-ip must be set to hw "
4959                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4960         }
4961
4962         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4963         cmd_reconfig_device_queue(res->port_id, 1, 1);
4964 }
4965
4966 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4967         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4968                                 tso, "tunnel_tso");
4969 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4970         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4971                                 mode, "set");
4972 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4973         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4974                                 tso_segsz, RTE_UINT16);
4975 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4976         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4977                                 port_id, RTE_UINT16);
4978
4979 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4980         .f = cmd_tunnel_tso_set_parsed,
4981         .data = NULL,
4982         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4983                 "Set TSO segment size of tunneled packets for csum engine "
4984                 "(0 to disable)",
4985         .tokens = {
4986                 (void *)&cmd_tunnel_tso_set_tso,
4987                 (void *)&cmd_tunnel_tso_set_mode,
4988                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4989                 (void *)&cmd_tunnel_tso_set_portid,
4990                 NULL,
4991         },
4992 };
4993
4994 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4995         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4996                                 mode, "show");
4997
4998
4999 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5000         .f = cmd_tunnel_tso_set_parsed,
5001         .data = NULL,
5002         .help_str = "tunnel_tso show <port_id> "
5003                 "Show TSO segment size of tunneled packets for csum engine",
5004         .tokens = {
5005                 (void *)&cmd_tunnel_tso_set_tso,
5006                 (void *)&cmd_tunnel_tso_show_mode,
5007                 (void *)&cmd_tunnel_tso_set_portid,
5008                 NULL,
5009         },
5010 };
5011
5012 /* *** SET GRO FOR A PORT *** */
5013 struct cmd_gro_enable_result {
5014         cmdline_fixed_string_t cmd_set;
5015         cmdline_fixed_string_t cmd_port;
5016         cmdline_fixed_string_t cmd_keyword;
5017         cmdline_fixed_string_t cmd_onoff;
5018         portid_t cmd_pid;
5019 };
5020
5021 static void
5022 cmd_gro_enable_parsed(void *parsed_result,
5023                 __rte_unused struct cmdline *cl,
5024                 __rte_unused void *data)
5025 {
5026         struct cmd_gro_enable_result *res;
5027
5028         res = parsed_result;
5029         if (!strcmp(res->cmd_keyword, "gro"))
5030                 setup_gro(res->cmd_onoff, res->cmd_pid);
5031 }
5032
5033 cmdline_parse_token_string_t cmd_gro_enable_set =
5034         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5035                         cmd_set, "set");
5036 cmdline_parse_token_string_t cmd_gro_enable_port =
5037         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5038                         cmd_keyword, "port");
5039 cmdline_parse_token_num_t cmd_gro_enable_pid =
5040         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5041                         cmd_pid, RTE_UINT16);
5042 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5043         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5044                         cmd_keyword, "gro");
5045 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5046         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5047                         cmd_onoff, "on#off");
5048
5049 cmdline_parse_inst_t cmd_gro_enable = {
5050         .f = cmd_gro_enable_parsed,
5051         .data = NULL,
5052         .help_str = "set port <port_id> gro on|off",
5053         .tokens = {
5054                 (void *)&cmd_gro_enable_set,
5055                 (void *)&cmd_gro_enable_port,
5056                 (void *)&cmd_gro_enable_pid,
5057                 (void *)&cmd_gro_enable_keyword,
5058                 (void *)&cmd_gro_enable_onoff,
5059                 NULL,
5060         },
5061 };
5062
5063 /* *** DISPLAY GRO CONFIGURATION *** */
5064 struct cmd_gro_show_result {
5065         cmdline_fixed_string_t cmd_show;
5066         cmdline_fixed_string_t cmd_port;
5067         cmdline_fixed_string_t cmd_keyword;
5068         portid_t cmd_pid;
5069 };
5070
5071 static void
5072 cmd_gro_show_parsed(void *parsed_result,
5073                 __rte_unused struct cmdline *cl,
5074                 __rte_unused void *data)
5075 {
5076         struct cmd_gro_show_result *res;
5077
5078         res = parsed_result;
5079         if (!strcmp(res->cmd_keyword, "gro"))
5080                 show_gro(res->cmd_pid);
5081 }
5082
5083 cmdline_parse_token_string_t cmd_gro_show_show =
5084         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5085                         cmd_show, "show");
5086 cmdline_parse_token_string_t cmd_gro_show_port =
5087         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5088                         cmd_port, "port");
5089 cmdline_parse_token_num_t cmd_gro_show_pid =
5090         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5091                         cmd_pid, RTE_UINT16);
5092 cmdline_parse_token_string_t cmd_gro_show_keyword =
5093         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5094                         cmd_keyword, "gro");
5095
5096 cmdline_parse_inst_t cmd_gro_show = {
5097         .f = cmd_gro_show_parsed,
5098         .data = NULL,
5099         .help_str = "show port <port_id> gro",
5100         .tokens = {
5101                 (void *)&cmd_gro_show_show,
5102                 (void *)&cmd_gro_show_port,
5103                 (void *)&cmd_gro_show_pid,
5104                 (void *)&cmd_gro_show_keyword,
5105                 NULL,
5106         },
5107 };
5108
5109 /* *** SET FLUSH CYCLES FOR GRO *** */
5110 struct cmd_gro_flush_result {
5111         cmdline_fixed_string_t cmd_set;
5112         cmdline_fixed_string_t cmd_keyword;
5113         cmdline_fixed_string_t cmd_flush;
5114         uint8_t cmd_cycles;
5115 };
5116
5117 static void
5118 cmd_gro_flush_parsed(void *parsed_result,
5119                 __rte_unused struct cmdline *cl,
5120                 __rte_unused void *data)
5121 {
5122         struct cmd_gro_flush_result *res;
5123
5124         res = parsed_result;
5125         if ((!strcmp(res->cmd_keyword, "gro")) &&
5126                         (!strcmp(res->cmd_flush, "flush")))
5127                 setup_gro_flush_cycles(res->cmd_cycles);
5128 }
5129
5130 cmdline_parse_token_string_t cmd_gro_flush_set =
5131         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5132                         cmd_set, "set");
5133 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5134         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5135                         cmd_keyword, "gro");
5136 cmdline_parse_token_string_t cmd_gro_flush_flush =
5137         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5138                         cmd_flush, "flush");
5139 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5140         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5141                         cmd_cycles, RTE_UINT8);
5142
5143 cmdline_parse_inst_t cmd_gro_flush = {
5144         .f = cmd_gro_flush_parsed,
5145         .data = NULL,
5146         .help_str = "set gro flush <cycles>",
5147         .tokens = {
5148                 (void *)&cmd_gro_flush_set,
5149                 (void *)&cmd_gro_flush_keyword,
5150                 (void *)&cmd_gro_flush_flush,
5151                 (void *)&cmd_gro_flush_cycles,
5152                 NULL,
5153         },
5154 };
5155
5156 /* *** ENABLE/DISABLE GSO *** */
5157 struct cmd_gso_enable_result {
5158         cmdline_fixed_string_t cmd_set;
5159         cmdline_fixed_string_t cmd_port;
5160         cmdline_fixed_string_t cmd_keyword;
5161         cmdline_fixed_string_t cmd_mode;
5162         portid_t cmd_pid;
5163 };
5164
5165 static void
5166 cmd_gso_enable_parsed(void *parsed_result,
5167                 __rte_unused struct cmdline *cl,
5168                 __rte_unused void *data)
5169 {
5170         struct cmd_gso_enable_result *res;
5171
5172         res = parsed_result;
5173         if (!strcmp(res->cmd_keyword, "gso"))
5174                 setup_gso(res->cmd_mode, res->cmd_pid);
5175 }
5176
5177 cmdline_parse_token_string_t cmd_gso_enable_set =
5178         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5179                         cmd_set, "set");
5180 cmdline_parse_token_string_t cmd_gso_enable_port =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5182                         cmd_port, "port");
5183 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5185                         cmd_keyword, "gso");
5186 cmdline_parse_token_string_t cmd_gso_enable_mode =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5188                         cmd_mode, "on#off");
5189 cmdline_parse_token_num_t cmd_gso_enable_pid =
5190         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5191                         cmd_pid, RTE_UINT16);
5192
5193 cmdline_parse_inst_t cmd_gso_enable = {
5194         .f = cmd_gso_enable_parsed,
5195         .data = NULL,
5196         .help_str = "set port <port_id> gso on|off",
5197         .tokens = {
5198                 (void *)&cmd_gso_enable_set,
5199                 (void *)&cmd_gso_enable_port,
5200                 (void *)&cmd_gso_enable_pid,
5201                 (void *)&cmd_gso_enable_keyword,
5202                 (void *)&cmd_gso_enable_mode,
5203                 NULL,
5204         },
5205 };
5206
5207 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5208 struct cmd_gso_size_result {
5209         cmdline_fixed_string_t cmd_set;
5210         cmdline_fixed_string_t cmd_keyword;
5211         cmdline_fixed_string_t cmd_segsz;
5212         uint16_t cmd_size;
5213 };
5214
5215 static void
5216 cmd_gso_size_parsed(void *parsed_result,
5217                        __rte_unused struct cmdline *cl,
5218                        __rte_unused void *data)
5219 {
5220         struct cmd_gso_size_result *res = parsed_result;
5221
5222         if (test_done == 0) {
5223                 printf("Before setting GSO segsz, please first"
5224                                 " stop forwarding\n");
5225                 return;
5226         }
5227
5228         if (!strcmp(res->cmd_keyword, "gso") &&
5229                         !strcmp(res->cmd_segsz, "segsz")) {
5230                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5231                         printf("gso_size should be larger than %zu."
5232                                         " Please input a legal value\n",
5233                                         RTE_GSO_SEG_SIZE_MIN);
5234                 else
5235                         gso_max_segment_size = res->cmd_size;
5236         }
5237 }
5238
5239 cmdline_parse_token_string_t cmd_gso_size_set =
5240         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5241                                 cmd_set, "set");
5242 cmdline_parse_token_string_t cmd_gso_size_keyword =
5243         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5244                                 cmd_keyword, "gso");
5245 cmdline_parse_token_string_t cmd_gso_size_segsz =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5247                                 cmd_segsz, "segsz");
5248 cmdline_parse_token_num_t cmd_gso_size_size =
5249         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5250                                 cmd_size, RTE_UINT16);
5251
5252 cmdline_parse_inst_t cmd_gso_size = {
5253         .f = cmd_gso_size_parsed,
5254         .data = NULL,
5255         .help_str = "set gso segsz <length>",
5256         .tokens = {
5257                 (void *)&cmd_gso_size_set,
5258                 (void *)&cmd_gso_size_keyword,
5259                 (void *)&cmd_gso_size_segsz,
5260                 (void *)&cmd_gso_size_size,
5261                 NULL,
5262         },
5263 };
5264
5265 /* *** SHOW GSO CONFIGURATION *** */
5266 struct cmd_gso_show_result {
5267         cmdline_fixed_string_t cmd_show;
5268         cmdline_fixed_string_t cmd_port;
5269         cmdline_fixed_string_t cmd_keyword;
5270         portid_t cmd_pid;
5271 };
5272
5273 static void
5274 cmd_gso_show_parsed(void *parsed_result,
5275                        __rte_unused struct cmdline *cl,
5276                        __rte_unused void *data)
5277 {
5278         struct cmd_gso_show_result *res = parsed_result;
5279
5280         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5281                 printf("invalid port id %u\n", res->cmd_pid);
5282                 return;
5283         }
5284         if (!strcmp(res->cmd_keyword, "gso")) {
5285                 if (gso_ports[res->cmd_pid].enable) {
5286                         printf("Max GSO'd packet size: %uB\n"
5287                                         "Supported GSO types: TCP/IPv4, "
5288                                         "UDP/IPv4, VxLAN with inner "
5289                                         "TCP/IPv4 packet, GRE with inner "
5290                                         "TCP/IPv4 packet\n",
5291                                         gso_max_segment_size);
5292                 } else
5293                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5294         }
5295 }
5296
5297 cmdline_parse_token_string_t cmd_gso_show_show =
5298 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5299                 cmd_show, "show");
5300 cmdline_parse_token_string_t cmd_gso_show_port =
5301 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5302                 cmd_port, "port");
5303 cmdline_parse_token_string_t cmd_gso_show_keyword =
5304         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5305                                 cmd_keyword, "gso");
5306 cmdline_parse_token_num_t cmd_gso_show_pid =
5307         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5308                                 cmd_pid, RTE_UINT16);
5309
5310 cmdline_parse_inst_t cmd_gso_show = {
5311         .f = cmd_gso_show_parsed,
5312         .data = NULL,
5313         .help_str = "show port <port_id> gso",
5314         .tokens = {
5315                 (void *)&cmd_gso_show_show,
5316                 (void *)&cmd_gso_show_port,
5317                 (void *)&cmd_gso_show_pid,
5318                 (void *)&cmd_gso_show_keyword,
5319                 NULL,
5320         },
5321 };
5322
5323 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5324 struct cmd_set_flush_rx {
5325         cmdline_fixed_string_t set;
5326         cmdline_fixed_string_t flush_rx;
5327         cmdline_fixed_string_t mode;
5328 };
5329
5330 static void
5331 cmd_set_flush_rx_parsed(void *parsed_result,
5332                 __rte_unused struct cmdline *cl,
5333                 __rte_unused void *data)
5334 {
5335         struct cmd_set_flush_rx *res = parsed_result;
5336         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5337 }
5338
5339 cmdline_parse_token_string_t cmd_setflushrx_set =
5340         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5341                         set, "set");
5342 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5343         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5344                         flush_rx, "flush_rx");
5345 cmdline_parse_token_string_t cmd_setflushrx_mode =
5346         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5347                         mode, "on#off");
5348
5349
5350 cmdline_parse_inst_t cmd_set_flush_rx = {
5351         .f = cmd_set_flush_rx_parsed,
5352         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5353         .data = NULL,
5354         .tokens = {
5355                 (void *)&cmd_setflushrx_set,
5356                 (void *)&cmd_setflushrx_flush_rx,
5357                 (void *)&cmd_setflushrx_mode,
5358                 NULL,
5359         },
5360 };
5361
5362 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5363 struct cmd_set_link_check {
5364         cmdline_fixed_string_t set;
5365         cmdline_fixed_string_t link_check;
5366         cmdline_fixed_string_t mode;
5367 };
5368
5369 static void
5370 cmd_set_link_check_parsed(void *parsed_result,
5371                 __rte_unused struct cmdline *cl,
5372                 __rte_unused void *data)
5373 {
5374         struct cmd_set_link_check *res = parsed_result;
5375         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5376 }
5377
5378 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5379         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5380                         set, "set");
5381 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5383                         link_check, "link_check");
5384 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5385         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5386                         mode, "on#off");
5387
5388
5389 cmdline_parse_inst_t cmd_set_link_check = {
5390         .f = cmd_set_link_check_parsed,
5391         .help_str = "set link_check on|off: Enable/Disable link status check "
5392                     "when starting/stopping a port",
5393         .data = NULL,
5394         .tokens = {
5395                 (void *)&cmd_setlinkcheck_set,
5396                 (void *)&cmd_setlinkcheck_link_check,
5397                 (void *)&cmd_setlinkcheck_mode,
5398                 NULL,
5399         },
5400 };
5401
5402 /* *** SET NIC BYPASS MODE *** */
5403 struct cmd_set_bypass_mode_result {
5404         cmdline_fixed_string_t set;
5405         cmdline_fixed_string_t bypass;
5406         cmdline_fixed_string_t mode;
5407         cmdline_fixed_string_t value;
5408         portid_t port_id;
5409 };
5410
5411 static void
5412 cmd_set_bypass_mode_parsed(void *parsed_result,
5413                 __rte_unused struct cmdline *cl,
5414                 __rte_unused void *data)
5415 {
5416         struct cmd_set_bypass_mode_result *res = parsed_result;
5417         portid_t port_id = res->port_id;
5418         int32_t rc = -EINVAL;
5419
5420 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5421         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5422
5423         if (!strcmp(res->value, "bypass"))
5424                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5425         else if (!strcmp(res->value, "isolate"))
5426                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5427         else
5428                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5429
5430         /* Set the bypass mode for the relevant port. */
5431         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5432 #endif
5433         if (rc != 0)
5434                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5435 }
5436
5437 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5438         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5439                         set, "set");
5440 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5441         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5442                         bypass, "bypass");
5443 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5444         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5445                         mode, "mode");
5446 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5447         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5448                         value, "normal#bypass#isolate");
5449 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5450         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5451                                 port_id, RTE_UINT16);
5452
5453 cmdline_parse_inst_t cmd_set_bypass_mode = {
5454         .f = cmd_set_bypass_mode_parsed,
5455         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5456                     "Set the NIC bypass mode for port_id",
5457         .data = NULL,
5458         .tokens = {
5459                 (void *)&cmd_setbypass_mode_set,
5460                 (void *)&cmd_setbypass_mode_bypass,
5461                 (void *)&cmd_setbypass_mode_mode,
5462                 (void *)&cmd_setbypass_mode_value,
5463                 (void *)&cmd_setbypass_mode_port,
5464                 NULL,
5465         },
5466 };
5467
5468 /* *** SET NIC BYPASS EVENT *** */
5469 struct cmd_set_bypass_event_result {
5470         cmdline_fixed_string_t set;
5471         cmdline_fixed_string_t bypass;
5472         cmdline_fixed_string_t event;
5473         cmdline_fixed_string_t event_value;
5474         cmdline_fixed_string_t mode;
5475         cmdline_fixed_string_t mode_value;
5476         portid_t port_id;
5477 };
5478
5479 static void
5480 cmd_set_bypass_event_parsed(void *parsed_result,
5481                 __rte_unused struct cmdline *cl,
5482                 __rte_unused void *data)
5483 {
5484         int32_t rc = -EINVAL;
5485         struct cmd_set_bypass_event_result *res = parsed_result;
5486         portid_t port_id = res->port_id;
5487
5488 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5489         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5490         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5491
5492         if (!strcmp(res->event_value, "timeout"))
5493                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5494         else if (!strcmp(res->event_value, "os_on"))
5495                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5496         else if (!strcmp(res->event_value, "os_off"))
5497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5498         else if (!strcmp(res->event_value, "power_on"))
5499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5500         else if (!strcmp(res->event_value, "power_off"))
5501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5502         else
5503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5504
5505         if (!strcmp(res->mode_value, "bypass"))
5506                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5507         else if (!strcmp(res->mode_value, "isolate"))
5508                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5509         else
5510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5511
5512         /* Set the watchdog timeout. */
5513         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5514
5515                 rc = -EINVAL;
5516                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5517                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5518                                                            bypass_timeout);
5519                 }
5520                 if (rc != 0) {
5521                         printf("Failed to set timeout value %u "
5522                         "for port %d, errto code: %d.\n",
5523                         bypass_timeout, port_id, rc);
5524                 }
5525         }
5526
5527         /* Set the bypass event to transition to bypass mode. */
5528         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5529                                               bypass_mode);
5530 #endif
5531
5532         if (rc != 0)
5533                 printf("\t Failed to set bypass event for port = %d.\n",
5534                        port_id);
5535 }
5536
5537 cmdline_parse_token_string_t cmd_setbypass_event_set =
5538         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5539                         set, "set");
5540 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5542                         bypass, "bypass");
5543 cmdline_parse_token_string_t cmd_setbypass_event_event =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5545                         event, "event");
5546 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5548                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5549 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5551                         mode, "mode");
5552 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5554                         mode_value, "normal#bypass#isolate");
5555 cmdline_parse_token_num_t cmd_setbypass_event_port =
5556         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5557                                 port_id, RTE_UINT16);
5558
5559 cmdline_parse_inst_t cmd_set_bypass_event = {
5560         .f = cmd_set_bypass_event_parsed,
5561         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5562                 "power_off mode normal|bypass|isolate <port_id>: "
5563                 "Set the NIC bypass event mode for port_id",
5564         .data = NULL,
5565         .tokens = {
5566                 (void *)&cmd_setbypass_event_set,
5567                 (void *)&cmd_setbypass_event_bypass,
5568                 (void *)&cmd_setbypass_event_event,
5569                 (void *)&cmd_setbypass_event_event_value,
5570                 (void *)&cmd_setbypass_event_mode,
5571                 (void *)&cmd_setbypass_event_mode_value,
5572                 (void *)&cmd_setbypass_event_port,
5573                 NULL,
5574         },
5575 };
5576
5577
5578 /* *** SET NIC BYPASS TIMEOUT *** */
5579 struct cmd_set_bypass_timeout_result {
5580         cmdline_fixed_string_t set;
5581         cmdline_fixed_string_t bypass;
5582         cmdline_fixed_string_t timeout;
5583         cmdline_fixed_string_t value;
5584 };
5585
5586 static void
5587 cmd_set_bypass_timeout_parsed(void *parsed_result,
5588                 __rte_unused struct cmdline *cl,
5589                 __rte_unused void *data)
5590 {
5591         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5592
5593 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5594         if (!strcmp(res->value, "1.5"))
5595                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5596         else if (!strcmp(res->value, "2"))
5597                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5598         else if (!strcmp(res->value, "3"))
5599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5600         else if (!strcmp(res->value, "4"))
5601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5602         else if (!strcmp(res->value, "8"))
5603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5604         else if (!strcmp(res->value, "16"))
5605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5606         else if (!strcmp(res->value, "32"))
5607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5608         else
5609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5610 #endif
5611 }
5612
5613 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5614         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5615                         set, "set");
5616 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5617         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5618                         bypass, "bypass");
5619 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5621                         timeout, "timeout");
5622 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5624                         value, "0#1.5#2#3#4#8#16#32");
5625
5626 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5627         .f = cmd_set_bypass_timeout_parsed,
5628         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5629                 "Set the NIC bypass watchdog timeout in seconds",
5630         .data = NULL,
5631         .tokens = {
5632                 (void *)&cmd_setbypass_timeout_set,
5633                 (void *)&cmd_setbypass_timeout_bypass,
5634                 (void *)&cmd_setbypass_timeout_timeout,
5635                 (void *)&cmd_setbypass_timeout_value,
5636                 NULL,
5637         },
5638 };
5639
5640 /* *** SHOW NIC BYPASS MODE *** */
5641 struct cmd_show_bypass_config_result {
5642         cmdline_fixed_string_t show;
5643         cmdline_fixed_string_t bypass;
5644         cmdline_fixed_string_t config;
5645         portid_t port_id;
5646 };
5647
5648 static void
5649 cmd_show_bypass_config_parsed(void *parsed_result,
5650                 __rte_unused struct cmdline *cl,
5651                 __rte_unused void *data)
5652 {
5653         struct cmd_show_bypass_config_result *res = parsed_result;
5654         portid_t port_id = res->port_id;
5655         int rc = -EINVAL;
5656 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5657         uint32_t event_mode;
5658         uint32_t bypass_mode;
5659         uint32_t timeout = bypass_timeout;
5660         unsigned int i;
5661
5662         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5663                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5664         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5665                 {"UNKNOWN", "normal", "bypass", "isolate"};
5666         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5667                 "NONE",
5668                 "OS/board on",
5669                 "power supply on",
5670                 "OS/board off",
5671                 "power supply off",
5672                 "timeout"};
5673
5674         /* Display the bypass mode.*/
5675         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5676                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5677                 return;
5678         }
5679         else {
5680                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5681                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5682
5683                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5684         }
5685
5686         /* Display the bypass timeout.*/
5687         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5688                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5689
5690         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5691
5692         /* Display the bypass events and associated modes. */
5693         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5694
5695                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5696                         printf("\tFailed to get bypass mode for event = %s\n",
5697                                 events[i]);
5698                 } else {
5699                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5700                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5701
5702                         printf("\tbypass event: %-16s = %s\n", events[i],
5703                                 modes[event_mode]);
5704                 }
5705         }
5706 #endif
5707         if (rc != 0)
5708                 printf("\tFailed to get bypass configuration for port = %d\n",
5709                        port_id);
5710 }
5711
5712 cmdline_parse_token_string_t cmd_showbypass_config_show =
5713         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5714                         show, "show");
5715 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5716         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5717                         bypass, "bypass");
5718 cmdline_parse_token_string_t cmd_showbypass_config_config =
5719         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5720                         config, "config");
5721 cmdline_parse_token_num_t cmd_showbypass_config_port =
5722         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5723                                 port_id, RTE_UINT16);
5724
5725 cmdline_parse_inst_t cmd_show_bypass_config = {
5726         .f = cmd_show_bypass_config_parsed,
5727         .help_str = "show bypass config <port_id>: "
5728                     "Show the NIC bypass config for port_id",
5729         .data = NULL,
5730         .tokens = {
5731                 (void *)&cmd_showbypass_config_show,
5732                 (void *)&cmd_showbypass_config_bypass,
5733                 (void *)&cmd_showbypass_config_config,
5734                 (void *)&cmd_showbypass_config_port,
5735                 NULL,
5736         },
5737 };
5738
5739 #ifdef RTE_NET_BOND
5740 /* *** SET BONDING MODE *** */
5741 struct cmd_set_bonding_mode_result {
5742         cmdline_fixed_string_t set;
5743         cmdline_fixed_string_t bonding;
5744         cmdline_fixed_string_t mode;
5745         uint8_t value;
5746         portid_t port_id;
5747 };
5748
5749 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5750                 __rte_unused  struct cmdline *cl,
5751                 __rte_unused void *data)
5752 {
5753         struct cmd_set_bonding_mode_result *res = parsed_result;
5754         portid_t port_id = res->port_id;
5755
5756         /* Set the bonding mode for the relevant port. */
5757         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5758                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5759 }
5760
5761 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5762 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5763                 set, "set");
5764 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5765 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5766                 bonding, "bonding");
5767 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5768 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5769                 mode, "mode");
5770 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5771 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5772                 value, RTE_UINT8);
5773 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5774 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5775                 port_id, RTE_UINT16);
5776
5777 cmdline_parse_inst_t cmd_set_bonding_mode = {
5778                 .f = cmd_set_bonding_mode_parsed,
5779                 .help_str = "set bonding mode <mode_value> <port_id>: "
5780                         "Set the bonding mode for port_id",
5781                 .data = NULL,
5782                 .tokens = {
5783                                 (void *) &cmd_setbonding_mode_set,
5784                                 (void *) &cmd_setbonding_mode_bonding,
5785                                 (void *) &cmd_setbonding_mode_mode,
5786                                 (void *) &cmd_setbonding_mode_value,
5787                                 (void *) &cmd_setbonding_mode_port,
5788                                 NULL
5789                 }
5790 };
5791
5792 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5793 struct cmd_set_bonding_lacp_dedicated_queues_result {
5794         cmdline_fixed_string_t set;
5795         cmdline_fixed_string_t bonding;
5796         cmdline_fixed_string_t lacp;
5797         cmdline_fixed_string_t dedicated_queues;
5798         portid_t port_id;
5799         cmdline_fixed_string_t mode;
5800 };
5801
5802 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5803                 __rte_unused  struct cmdline *cl,
5804                 __rte_unused void *data)
5805 {
5806         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5807         portid_t port_id = res->port_id;
5808         struct rte_port *port;
5809
5810         port = &ports[port_id];
5811
5812         /** Check if the port is not started **/
5813         if (port->port_status != RTE_PORT_STOPPED) {
5814                 printf("Please stop port %d first\n", port_id);
5815                 return;
5816         }
5817
5818         if (!strcmp(res->mode, "enable")) {
5819                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5820                         printf("Dedicate queues for LACP control packets"
5821                                         " enabled\n");
5822                 else
5823                         printf("Enabling dedicate queues for LACP control "
5824                                         "packets on port %d failed\n", port_id);
5825         } else if (!strcmp(res->mode, "disable")) {
5826                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5827                         printf("Dedicated queues for LACP control packets "
5828                                         "disabled\n");
5829                 else
5830                         printf("Disabling dedicated queues for LACP control "
5831                                         "traffic on port %d failed\n", port_id);
5832         }
5833 }
5834
5835 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5836 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5837                 set, "set");
5838 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5839 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5840                 bonding, "bonding");
5841 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5842 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5843                 lacp, "lacp");
5844 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5845 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5846                 dedicated_queues, "dedicated_queues");
5847 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5848 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5849                 port_id, RTE_UINT16);
5850 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5851 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5852                 mode, "enable#disable");
5853
5854 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5855                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5856                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5857                         "enable|disable: "
5858                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5859                 .data = NULL,
5860                 .tokens = {
5861                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5862                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5863                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5864                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5865                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5866                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5867                         NULL
5868                 }
5869 };
5870
5871 /* *** SET BALANCE XMIT POLICY *** */
5872 struct cmd_set_bonding_balance_xmit_policy_result {
5873         cmdline_fixed_string_t set;
5874         cmdline_fixed_string_t bonding;
5875         cmdline_fixed_string_t balance_xmit_policy;
5876         portid_t port_id;
5877         cmdline_fixed_string_t policy;
5878 };
5879
5880 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5881                 __rte_unused  struct cmdline *cl,
5882                 __rte_unused void *data)
5883 {
5884         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5885         portid_t port_id = res->port_id;
5886         uint8_t policy;
5887
5888         if (!strcmp(res->policy, "l2")) {
5889                 policy = BALANCE_XMIT_POLICY_LAYER2;
5890         } else if (!strcmp(res->policy, "l23")) {
5891                 policy = BALANCE_XMIT_POLICY_LAYER23;
5892         } else if (!strcmp(res->policy, "l34")) {
5893                 policy = BALANCE_XMIT_POLICY_LAYER34;
5894         } else {
5895                 printf("\t Invalid xmit policy selection");
5896                 return;
5897         }
5898
5899         /* Set the bonding mode for the relevant port. */
5900         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5901                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5902                                 port_id);
5903         }
5904 }
5905
5906 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5907 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5908                 set, "set");
5909 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5910 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5911                 bonding, "bonding");
5912 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5913 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5914                 balance_xmit_policy, "balance_xmit_policy");
5915 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5916 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5917                 port_id, RTE_UINT16);
5918 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5920                 policy, "l2#l23#l34");
5921
5922 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5923                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5924                 .help_str = "set bonding balance_xmit_policy <port_id> "
5925                         "l2|l23|l34: "
5926                         "Set the bonding balance_xmit_policy for port_id",
5927                 .data = NULL,
5928                 .tokens = {
5929                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5930                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5931                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5932                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5933                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5934                                 NULL
5935                 }
5936 };
5937
5938 /* *** SHOW NIC BONDING CONFIGURATION *** */
5939 struct cmd_show_bonding_config_result {
5940         cmdline_fixed_string_t show;
5941         cmdline_fixed_string_t bonding;
5942         cmdline_fixed_string_t config;
5943         portid_t port_id;
5944 };
5945
5946 static void cmd_show_bonding_config_parsed(void *parsed_result,
5947                 __rte_unused  struct cmdline *cl,
5948                 __rte_unused void *data)
5949 {
5950         struct cmd_show_bonding_config_result *res = parsed_result;
5951         int bonding_mode, agg_mode;
5952         portid_t slaves[RTE_MAX_ETHPORTS];
5953         int num_slaves, num_active_slaves;
5954         int primary_id;
5955         int i;
5956         portid_t port_id = res->port_id;
5957
5958         /* Display the bonding mode.*/
5959         bonding_mode = rte_eth_bond_mode_get(port_id);
5960         if (bonding_mode < 0) {
5961                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5962                 return;
5963         } else
5964                 printf("\tBonding mode: %d\n", bonding_mode);
5965
5966         if (bonding_mode == BONDING_MODE_BALANCE) {
5967                 int balance_xmit_policy;
5968
5969                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5970                 if (balance_xmit_policy < 0) {
5971                         printf("\tFailed to get balance xmit policy for port = %d\n",
5972                                         port_id);
5973                         return;
5974                 } else {
5975                         printf("\tBalance Xmit Policy: ");
5976
5977                         switch (balance_xmit_policy) {
5978                         case BALANCE_XMIT_POLICY_LAYER2:
5979                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5980                                 break;
5981                         case BALANCE_XMIT_POLICY_LAYER23:
5982                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5983                                 break;
5984                         case BALANCE_XMIT_POLICY_LAYER34:
5985                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5986                                 break;
5987                         }
5988                         printf("\n");
5989                 }
5990         }
5991
5992         if (bonding_mode == BONDING_MODE_8023AD) {
5993                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5994                 printf("\tIEEE802.3AD Aggregator Mode: ");
5995                 switch (agg_mode) {
5996                 case AGG_BANDWIDTH:
5997                         printf("bandwidth");
5998                         break;
5999                 case AGG_STABLE:
6000                         printf("stable");
6001                         break;
6002                 case AGG_COUNT:
6003                         printf("count");
6004                         break;
6005                 }
6006                 printf("\n");
6007         }
6008
6009         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6010
6011         if (num_slaves < 0) {
6012                 printf("\tFailed to get slave list for port = %d\n", port_id);
6013                 return;
6014         }
6015         if (num_slaves > 0) {
6016                 printf("\tSlaves (%d): [", num_slaves);
6017                 for (i = 0; i < num_slaves - 1; i++)
6018                         printf("%d ", slaves[i]);
6019
6020                 printf("%d]\n", slaves[num_slaves - 1]);
6021         } else {
6022                 printf("\tSlaves: []\n");
6023
6024         }
6025
6026         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6027                         RTE_MAX_ETHPORTS);
6028
6029         if (num_active_slaves < 0) {
6030                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6031                 return;
6032         }
6033         if (num_active_slaves > 0) {
6034                 printf("\tActive Slaves (%d): [", num_active_slaves);
6035                 for (i = 0; i < num_active_slaves - 1; i++)
6036                         printf("%d ", slaves[i]);
6037
6038                 printf("%d]\n", slaves[num_active_slaves - 1]);
6039
6040         } else {
6041                 printf("\tActive Slaves: []\n");
6042
6043         }
6044
6045         primary_id = rte_eth_bond_primary_get(port_id);
6046         if (primary_id < 0) {
6047                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6048                 return;
6049         } else
6050                 printf("\tPrimary: [%d]\n", primary_id);
6051
6052 }
6053
6054 cmdline_parse_token_string_t cmd_showbonding_config_show =
6055 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6056                 show, "show");
6057 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6058 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6059                 bonding, "bonding");
6060 cmdline_parse_token_string_t cmd_showbonding_config_config =
6061 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6062                 config, "config");
6063 cmdline_parse_token_num_t cmd_showbonding_config_port =
6064 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6065                 port_id, RTE_UINT16);
6066
6067 cmdline_parse_inst_t cmd_show_bonding_config = {
6068                 .f = cmd_show_bonding_config_parsed,
6069                 .help_str = "show bonding config <port_id>: "
6070                         "Show the bonding config for port_id",
6071                 .data = NULL,
6072                 .tokens = {
6073                                 (void *)&cmd_showbonding_config_show,
6074                                 (void *)&cmd_showbonding_config_bonding,
6075                                 (void *)&cmd_showbonding_config_config,
6076                                 (void *)&cmd_showbonding_config_port,
6077                                 NULL
6078                 }
6079 };
6080
6081 /* *** SET BONDING PRIMARY *** */
6082 struct cmd_set_bonding_primary_result {
6083         cmdline_fixed_string_t set;
6084         cmdline_fixed_string_t bonding;
6085         cmdline_fixed_string_t primary;
6086         portid_t slave_id;
6087         portid_t port_id;
6088 };
6089
6090 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6091                 __rte_unused  struct cmdline *cl,
6092                 __rte_unused void *data)
6093 {
6094         struct cmd_set_bonding_primary_result *res = parsed_result;
6095         portid_t master_port_id = res->port_id;
6096         portid_t slave_port_id = res->slave_id;
6097
6098         /* Set the primary slave for a bonded device. */
6099         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6100                 printf("\t Failed to set primary slave for port = %d.\n",
6101                                 master_port_id);
6102                 return;
6103         }
6104         init_port_config();
6105 }
6106
6107 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6108 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6109                 set, "set");
6110 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6112                 bonding, "bonding");
6113 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6114 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6115                 primary, "primary");
6116 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6117 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6118                 slave_id, RTE_UINT16);
6119 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6120 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6121                 port_id, RTE_UINT16);
6122
6123 cmdline_parse_inst_t cmd_set_bonding_primary = {
6124                 .f = cmd_set_bonding_primary_parsed,
6125                 .help_str = "set bonding primary <slave_id> <port_id>: "
6126                         "Set the primary slave for port_id",
6127                 .data = NULL,
6128                 .tokens = {
6129                                 (void *)&cmd_setbonding_primary_set,
6130                                 (void *)&cmd_setbonding_primary_bonding,
6131                                 (void *)&cmd_setbonding_primary_primary,
6132                                 (void *)&cmd_setbonding_primary_slave,
6133                                 (void *)&cmd_setbonding_primary_port,
6134                                 NULL
6135                 }
6136 };
6137
6138 /* *** ADD SLAVE *** */
6139 struct cmd_add_bonding_slave_result {
6140         cmdline_fixed_string_t add;
6141         cmdline_fixed_string_t bonding;
6142         cmdline_fixed_string_t slave;
6143         portid_t slave_id;
6144         portid_t port_id;
6145 };
6146
6147 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6148                 __rte_unused  struct cmdline *cl,
6149                 __rte_unused void *data)
6150 {
6151         struct cmd_add_bonding_slave_result *res = parsed_result;
6152         portid_t master_port_id = res->port_id;
6153         portid_t slave_port_id = res->slave_id;
6154
6155         /* add the slave for a bonded device. */
6156         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6157                 printf("\t Failed to add slave %d to master port = %d.\n",
6158                                 slave_port_id, master_port_id);
6159                 return;
6160         }
6161         init_port_config();
6162         set_port_slave_flag(slave_port_id);
6163 }
6164
6165 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6166 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6167                 add, "add");
6168 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6169 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6170                 bonding, "bonding");
6171 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6172 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6173                 slave, "slave");
6174 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6175 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6176                 slave_id, RTE_UINT16);
6177 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6178 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6179                 port_id, RTE_UINT16);
6180
6181 cmdline_parse_inst_t cmd_add_bonding_slave = {
6182                 .f = cmd_add_bonding_slave_parsed,
6183                 .help_str = "add bonding slave <slave_id> <port_id>: "
6184                         "Add a slave device to a bonded device",
6185                 .data = NULL,
6186                 .tokens = {
6187                                 (void *)&cmd_addbonding_slave_add,
6188                                 (void *)&cmd_addbonding_slave_bonding,
6189                                 (void *)&cmd_addbonding_slave_slave,
6190                                 (void *)&cmd_addbonding_slave_slaveid,
6191                                 (void *)&cmd_addbonding_slave_port,
6192                                 NULL
6193                 }
6194 };
6195
6196 /* *** REMOVE SLAVE *** */
6197 struct cmd_remove_bonding_slave_result {
6198         cmdline_fixed_string_t remove;
6199         cmdline_fixed_string_t bonding;
6200         cmdline_fixed_string_t slave;
6201         portid_t slave_id;
6202         portid_t port_id;
6203 };
6204
6205 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6206                 __rte_unused  struct cmdline *cl,
6207                 __rte_unused void *data)
6208 {
6209         struct cmd_remove_bonding_slave_result *res = parsed_result;
6210         portid_t master_port_id = res->port_id;
6211         portid_t slave_port_id = res->slave_id;
6212
6213         /* remove the slave from a bonded device. */
6214         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6215                 printf("\t Failed to remove slave %d from master port = %d.\n",
6216                                 slave_port_id, master_port_id);
6217                 return;
6218         }
6219         init_port_config();
6220         clear_port_slave_flag(slave_port_id);
6221 }
6222
6223 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6224                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6225                                 remove, "remove");
6226 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6227                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6228                                 bonding, "bonding");
6229 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6230                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6231                                 slave, "slave");
6232 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6233                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6234                                 slave_id, RTE_UINT16);
6235 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6236                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6237                                 port_id, RTE_UINT16);
6238
6239 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6240                 .f = cmd_remove_bonding_slave_parsed,
6241                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6242                         "Remove a slave device from a bonded device",
6243                 .data = NULL,
6244                 .tokens = {
6245                                 (void *)&cmd_removebonding_slave_remove,
6246                                 (void *)&cmd_removebonding_slave_bonding,
6247                                 (void *)&cmd_removebonding_slave_slave,
6248                                 (void *)&cmd_removebonding_slave_slaveid,
6249                                 (void *)&cmd_removebonding_slave_port,
6250                                 NULL
6251                 }
6252 };
6253
6254 /* *** CREATE BONDED DEVICE *** */
6255 struct cmd_create_bonded_device_result {
6256         cmdline_fixed_string_t create;
6257         cmdline_fixed_string_t bonded;
6258         cmdline_fixed_string_t device;
6259         uint8_t mode;
6260         uint8_t socket;
6261 };
6262
6263 static int bond_dev_num = 0;
6264
6265 static void cmd_create_bonded_device_parsed(void *parsed_result,
6266                 __rte_unused  struct cmdline *cl,
6267                 __rte_unused void *data)
6268 {
6269         struct cmd_create_bonded_device_result *res = parsed_result;
6270         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6271         int port_id;
6272         int ret;
6273
6274         if (test_done == 0) {
6275                 printf("Please stop forwarding first\n");
6276                 return;
6277         }
6278
6279         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6280                         bond_dev_num++);
6281
6282         /* Create a new bonded device. */
6283         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6284         if (port_id < 0) {
6285                 printf("\t Failed to create bonded device.\n");
6286                 return;
6287         } else {
6288                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6289                                 port_id);
6290
6291                 /* Update number of ports */
6292                 nb_ports = rte_eth_dev_count_avail();
6293                 reconfig(port_id, res->socket);
6294                 ret = rte_eth_promiscuous_enable(port_id);
6295                 if (ret != 0)
6296                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6297                                 port_id, rte_strerror(-ret));
6298
6299                 ports[port_id].need_setup = 0;
6300                 ports[port_id].port_status = RTE_PORT_STOPPED;
6301         }
6302
6303 }
6304
6305 cmdline_parse_token_string_t cmd_createbonded_device_create =
6306                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6307                                 create, "create");
6308 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6309                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6310                                 bonded, "bonded");
6311 cmdline_parse_token_string_t cmd_createbonded_device_device =
6312                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6313                                 device, "device");
6314 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6315                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6316                                 mode, RTE_UINT8);
6317 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6318                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6319                                 socket, RTE_UINT8);
6320
6321 cmdline_parse_inst_t cmd_create_bonded_device = {
6322                 .f = cmd_create_bonded_device_parsed,
6323                 .help_str = "create bonded device <mode> <socket>: "
6324                         "Create a new bonded device with specific bonding mode and socket",
6325                 .data = NULL,
6326                 .tokens = {
6327                                 (void *)&cmd_createbonded_device_create,
6328                                 (void *)&cmd_createbonded_device_bonded,
6329                                 (void *)&cmd_createbonded_device_device,
6330                                 (void *)&cmd_createbonded_device_mode,
6331                                 (void *)&cmd_createbonded_device_socket,
6332                                 NULL
6333                 }
6334 };
6335
6336 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6337 struct cmd_set_bond_mac_addr_result {
6338         cmdline_fixed_string_t set;
6339         cmdline_fixed_string_t bonding;
6340         cmdline_fixed_string_t mac_addr;
6341         uint16_t port_num;
6342         struct rte_ether_addr address;
6343 };
6344
6345 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6346                 __rte_unused  struct cmdline *cl,
6347                 __rte_unused void *data)
6348 {
6349         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6350         int ret;
6351
6352         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6353                 return;
6354
6355         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6356
6357         /* check the return value and print it if is < 0 */
6358         if (ret < 0)
6359                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6360 }
6361
6362 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6363                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6364 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6365                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6366                                 "bonding");
6367 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6368                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6369                                 "mac_addr");
6370 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6371                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6372                                 port_num, RTE_UINT16);
6373 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6374                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6375
6376 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6377                 .f = cmd_set_bond_mac_addr_parsed,
6378                 .data = (void *) 0,
6379                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6380                 .tokens = {
6381                                 (void *)&cmd_set_bond_mac_addr_set,
6382                                 (void *)&cmd_set_bond_mac_addr_bonding,
6383                                 (void *)&cmd_set_bond_mac_addr_mac,
6384                                 (void *)&cmd_set_bond_mac_addr_portnum,
6385                                 (void *)&cmd_set_bond_mac_addr_addr,
6386                                 NULL
6387                 }
6388 };
6389
6390
6391 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6392 struct cmd_set_bond_mon_period_result {
6393         cmdline_fixed_string_t set;
6394         cmdline_fixed_string_t bonding;
6395         cmdline_fixed_string_t mon_period;
6396         uint16_t port_num;
6397         uint32_t period_ms;
6398 };
6399
6400 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6401                 __rte_unused  struct cmdline *cl,
6402                 __rte_unused void *data)
6403 {
6404         struct cmd_set_bond_mon_period_result *res = parsed_result;
6405         int ret;
6406
6407         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6408
6409         /* check the return value and print it if is < 0 */
6410         if (ret < 0)
6411                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6412 }
6413
6414 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6415                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6416                                 set, "set");
6417 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6418                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6419                                 bonding, "bonding");
6420 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6421                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6422                                 mon_period,     "mon_period");
6423 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6424                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6425                                 port_num, RTE_UINT16);
6426 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6427                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6428                                 period_ms, RTE_UINT32);
6429
6430 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6431                 .f = cmd_set_bond_mon_period_parsed,
6432                 .data = (void *) 0,
6433                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6434                 .tokens = {
6435                                 (void *)&cmd_set_bond_mon_period_set,
6436                                 (void *)&cmd_set_bond_mon_period_bonding,
6437                                 (void *)&cmd_set_bond_mon_period_mon_period,
6438                                 (void *)&cmd_set_bond_mon_period_portnum,
6439                                 (void *)&cmd_set_bond_mon_period_period_ms,
6440                                 NULL
6441                 }
6442 };
6443
6444
6445
6446 struct cmd_set_bonding_agg_mode_policy_result {
6447         cmdline_fixed_string_t set;
6448         cmdline_fixed_string_t bonding;
6449         cmdline_fixed_string_t agg_mode;
6450         uint16_t port_num;
6451         cmdline_fixed_string_t policy;
6452 };
6453
6454
6455 static void
6456 cmd_set_bonding_agg_mode(void *parsed_result,
6457                 __rte_unused struct cmdline *cl,
6458                 __rte_unused void *data)
6459 {
6460         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6461         uint8_t policy = AGG_BANDWIDTH;
6462
6463         if (!strcmp(res->policy, "bandwidth"))
6464                 policy = AGG_BANDWIDTH;
6465         else if (!strcmp(res->policy, "stable"))
6466                 policy = AGG_STABLE;
6467         else if (!strcmp(res->policy, "count"))
6468                 policy = AGG_COUNT;
6469
6470         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6471 }
6472
6473
6474 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6475         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6476                                 set, "set");
6477 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6479                                 bonding, "bonding");
6480
6481 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6483                                 agg_mode, "agg_mode");
6484
6485 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6486         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6487                                 port_num, RTE_UINT16);
6488
6489 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6490         TOKEN_STRING_INITIALIZER(
6491                         struct cmd_set_bonding_balance_xmit_policy_result,
6492                 policy, "stable#bandwidth#count");
6493
6494 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6495         .f = cmd_set_bonding_agg_mode,
6496         .data = (void *) 0,
6497         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6498         .tokens = {
6499                         (void *)&cmd_set_bonding_agg_mode_set,
6500                         (void *)&cmd_set_bonding_agg_mode_bonding,
6501                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6502                         (void *)&cmd_set_bonding_agg_mode_portnum,
6503                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6504                         NULL
6505                 }
6506 };
6507
6508
6509 #endif /* RTE_NET_BOND */
6510
6511 /* *** SET FORWARDING MODE *** */
6512 struct cmd_set_fwd_mode_result {
6513         cmdline_fixed_string_t set;
6514         cmdline_fixed_string_t fwd;
6515         cmdline_fixed_string_t mode;
6516 };
6517
6518 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6519                                     __rte_unused struct cmdline *cl,
6520                                     __rte_unused void *data)
6521 {
6522         struct cmd_set_fwd_mode_result *res = parsed_result;
6523
6524         retry_enabled = 0;
6525         set_pkt_forwarding_mode(res->mode);
6526 }
6527
6528 cmdline_parse_token_string_t cmd_setfwd_set =
6529         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6530 cmdline_parse_token_string_t cmd_setfwd_fwd =
6531         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6532 cmdline_parse_token_string_t cmd_setfwd_mode =
6533         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6534                 "" /* defined at init */);
6535
6536 cmdline_parse_inst_t cmd_set_fwd_mode = {
6537         .f = cmd_set_fwd_mode_parsed,
6538         .data = NULL,
6539         .help_str = NULL, /* defined at init */
6540         .tokens = {
6541                 (void *)&cmd_setfwd_set,
6542                 (void *)&cmd_setfwd_fwd,
6543                 (void *)&cmd_setfwd_mode,
6544                 NULL,
6545         },
6546 };
6547
6548 static void cmd_set_fwd_mode_init(void)
6549 {
6550         char *modes, *c;
6551         static char token[128];
6552         static char help[256];
6553         cmdline_parse_token_string_t *token_struct;
6554
6555         modes = list_pkt_forwarding_modes();
6556         snprintf(help, sizeof(help), "set fwd %s: "
6557                 "Set packet forwarding mode", modes);
6558         cmd_set_fwd_mode.help_str = help;
6559
6560         /* string token separator is # */
6561         for (c = token; *modes != '\0'; modes++)
6562                 if (*modes == '|')
6563                         *c++ = '#';
6564                 else
6565                         *c++ = *modes;
6566         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6567         token_struct->string_data.str = token;
6568 }
6569
6570 /* *** SET RETRY FORWARDING MODE *** */
6571 struct cmd_set_fwd_retry_mode_result {
6572         cmdline_fixed_string_t set;
6573         cmdline_fixed_string_t fwd;
6574         cmdline_fixed_string_t mode;
6575         cmdline_fixed_string_t retry;
6576 };
6577
6578 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6579                             __rte_unused struct cmdline *cl,
6580                             __rte_unused void *data)
6581 {
6582         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6583
6584         retry_enabled = 1;
6585         set_pkt_forwarding_mode(res->mode);
6586 }
6587
6588 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6589         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6590                         set, "set");
6591 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6592         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6593                         fwd, "fwd");
6594 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6596                         mode,
6597                 "" /* defined at init */);
6598 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6599         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6600                         retry, "retry");
6601
6602 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6603         .f = cmd_set_fwd_retry_mode_parsed,
6604         .data = NULL,
6605         .help_str = NULL, /* defined at init */
6606         .tokens = {
6607                 (void *)&cmd_setfwd_retry_set,
6608                 (void *)&cmd_setfwd_retry_fwd,
6609                 (void *)&cmd_setfwd_retry_mode,
6610                 (void *)&cmd_setfwd_retry_retry,
6611                 NULL,
6612         },
6613 };
6614
6615 static void cmd_set_fwd_retry_mode_init(void)
6616 {
6617         char *modes, *c;
6618         static char token[128];
6619         static char help[256];
6620         cmdline_parse_token_string_t *token_struct;
6621
6622         modes = list_pkt_forwarding_retry_modes();
6623         snprintf(help, sizeof(help), "set fwd %s retry: "
6624                 "Set packet forwarding mode with retry", modes);
6625         cmd_set_fwd_retry_mode.help_str = help;
6626
6627         /* string token separator is # */
6628         for (c = token; *modes != '\0'; modes++)
6629                 if (*modes == '|')
6630                         *c++ = '#';
6631                 else
6632                         *c++ = *modes;
6633         token_struct = (cmdline_parse_token_string_t *)
6634                 cmd_set_fwd_retry_mode.tokens[2];
6635         token_struct->string_data.str = token;
6636 }
6637
6638 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6639 struct cmd_set_burst_tx_retry_result {
6640         cmdline_fixed_string_t set;
6641         cmdline_fixed_string_t burst;
6642         cmdline_fixed_string_t tx;
6643         cmdline_fixed_string_t delay;
6644         uint32_t time;
6645         cmdline_fixed_string_t retry;
6646         uint32_t retry_num;
6647 };
6648
6649 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6650                                         __rte_unused struct cmdline *cl,
6651                                         __rte_unused void *data)
6652 {
6653         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6654
6655         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6656                 && !strcmp(res->tx, "tx")) {
6657                 if (!strcmp(res->delay, "delay"))
6658                         burst_tx_delay_time = res->time;
6659                 if (!strcmp(res->retry, "retry"))
6660                         burst_tx_retry_num = res->retry_num;
6661         }
6662
6663 }
6664
6665 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6666         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6667 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6668         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6669                                  "burst");
6670 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6671         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6674 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6675         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6676                                  RTE_UINT32);
6677 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6678         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6679 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6680         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6681                                  RTE_UINT32);
6682
6683 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6684         .f = cmd_set_burst_tx_retry_parsed,
6685         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6686         .tokens = {
6687                 (void *)&cmd_set_burst_tx_retry_set,
6688                 (void *)&cmd_set_burst_tx_retry_burst,
6689                 (void *)&cmd_set_burst_tx_retry_tx,
6690                 (void *)&cmd_set_burst_tx_retry_delay,
6691                 (void *)&cmd_set_burst_tx_retry_time,
6692                 (void *)&cmd_set_burst_tx_retry_retry,
6693                 (void *)&cmd_set_burst_tx_retry_retry_num,
6694                 NULL,
6695         },
6696 };
6697
6698 /* *** SET PROMISC MODE *** */
6699 struct cmd_set_promisc_mode_result {
6700         cmdline_fixed_string_t set;
6701         cmdline_fixed_string_t promisc;
6702         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6703         uint16_t port_num;               /* valid if "allports" argument == 0 */
6704         cmdline_fixed_string_t mode;
6705 };
6706
6707 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6708                                         __rte_unused struct cmdline *cl,
6709                                         void *allports)
6710 {
6711         struct cmd_set_promisc_mode_result *res = parsed_result;
6712         int enable;
6713         portid_t i;
6714
6715         if (!strcmp(res->mode, "on"))
6716                 enable = 1;
6717         else
6718                 enable = 0;
6719
6720         /* all ports */
6721         if (allports) {
6722                 RTE_ETH_FOREACH_DEV(i)
6723                         eth_set_promisc_mode(i, enable);
6724         } else {
6725                 eth_set_promisc_mode(res->port_num, enable);
6726         }
6727 }
6728
6729 cmdline_parse_token_string_t cmd_setpromisc_set =
6730         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6731 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6732         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6733                                  "promisc");
6734 cmdline_parse_token_string_t cmd_setpromisc_portall =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6736                                  "all");
6737 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6738         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6739                               RTE_UINT16);
6740 cmdline_parse_token_string_t cmd_setpromisc_mode =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6742                                  "on#off");
6743
6744 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6745         .f = cmd_set_promisc_mode_parsed,
6746         .data = (void *)1,
6747         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6748         .tokens = {
6749                 (void *)&cmd_setpromisc_set,
6750                 (void *)&cmd_setpromisc_promisc,
6751                 (void *)&cmd_setpromisc_portall,
6752                 (void *)&cmd_setpromisc_mode,
6753                 NULL,
6754         },
6755 };
6756
6757 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6758         .f = cmd_set_promisc_mode_parsed,
6759         .data = (void *)0,
6760         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6761         .tokens = {
6762                 (void *)&cmd_setpromisc_set,
6763                 (void *)&cmd_setpromisc_promisc,
6764                 (void *)&cmd_setpromisc_portnum,
6765                 (void *)&cmd_setpromisc_mode,
6766                 NULL,
6767         },
6768 };
6769
6770 /* *** SET ALLMULTI MODE *** */
6771 struct cmd_set_allmulti_mode_result {
6772         cmdline_fixed_string_t set;
6773         cmdline_fixed_string_t allmulti;
6774         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6775         uint16_t port_num;               /* valid if "allports" argument == 0 */
6776         cmdline_fixed_string_t mode;
6777 };
6778
6779 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6780                                         __rte_unused struct cmdline *cl,
6781                                         void *allports)
6782 {
6783         struct cmd_set_allmulti_mode_result *res = parsed_result;
6784         int enable;
6785         portid_t i;
6786
6787         if (!strcmp(res->mode, "on"))
6788                 enable = 1;
6789         else
6790                 enable = 0;
6791
6792         /* all ports */
6793         if (allports) {
6794                 RTE_ETH_FOREACH_DEV(i) {
6795                         eth_set_allmulticast_mode(i, enable);
6796                 }
6797         }
6798         else {
6799                 eth_set_allmulticast_mode(res->port_num, enable);
6800         }
6801 }
6802
6803 cmdline_parse_token_string_t cmd_setallmulti_set =
6804         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6805 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6806         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6807                                  "allmulti");
6808 cmdline_parse_token_string_t cmd_setallmulti_portall =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6810                                  "all");
6811 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6812         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6813                               RTE_UINT16);
6814 cmdline_parse_token_string_t cmd_setallmulti_mode =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6816                                  "on#off");
6817
6818 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6819         .f = cmd_set_allmulti_mode_parsed,
6820         .data = (void *)1,
6821         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6822         .tokens = {
6823                 (void *)&cmd_setallmulti_set,
6824                 (void *)&cmd_setallmulti_allmulti,
6825                 (void *)&cmd_setallmulti_portall,
6826                 (void *)&cmd_setallmulti_mode,
6827                 NULL,
6828         },
6829 };
6830
6831 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6832         .f = cmd_set_allmulti_mode_parsed,
6833         .data = (void *)0,
6834         .help_str = "set allmulti <port_id> on|off: "
6835                 "Set allmulti mode on port_id",
6836         .tokens = {
6837                 (void *)&cmd_setallmulti_set,
6838                 (void *)&cmd_setallmulti_allmulti,
6839                 (void *)&cmd_setallmulti_portnum,
6840                 (void *)&cmd_setallmulti_mode,
6841                 NULL,
6842         },
6843 };
6844
6845 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6846 struct cmd_link_flow_ctrl_set_result {
6847         cmdline_fixed_string_t set;
6848         cmdline_fixed_string_t flow_ctrl;
6849         cmdline_fixed_string_t rx;
6850         cmdline_fixed_string_t rx_lfc_mode;
6851         cmdline_fixed_string_t tx;
6852         cmdline_fixed_string_t tx_lfc_mode;
6853         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6854         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6855         cmdline_fixed_string_t autoneg_str;
6856         cmdline_fixed_string_t autoneg;
6857         cmdline_fixed_string_t hw_str;
6858         uint32_t high_water;
6859         cmdline_fixed_string_t lw_str;
6860         uint32_t low_water;
6861         cmdline_fixed_string_t pt_str;
6862         uint16_t pause_time;
6863         cmdline_fixed_string_t xon_str;
6864         uint16_t send_xon;
6865         portid_t port_id;
6866 };
6867
6868 cmdline_parse_token_string_t cmd_lfc_set_set =
6869         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6870                                 set, "set");
6871 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 flow_ctrl, "flow_ctrl");
6874 cmdline_parse_token_string_t cmd_lfc_set_rx =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 rx, "rx");
6877 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 rx_lfc_mode, "on#off");
6880 cmdline_parse_token_string_t cmd_lfc_set_tx =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 tx, "tx");
6883 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 tx_lfc_mode, "on#off");
6886 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 hw_str, "high_water");
6889 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6890         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 high_water, RTE_UINT32);
6892 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 lw_str, "low_water");
6895 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6896         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 low_water, RTE_UINT32);
6898 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 pt_str, "pause_time");
6901 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 pause_time, RTE_UINT16);
6904 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 xon_str, "send_xon");
6907 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 send_xon, RTE_UINT16);
6910 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6913 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 mac_ctrl_frame_fwd_mode, "on#off");
6916 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 autoneg_str, "autoneg");
6919 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 autoneg, "on#off");
6922 cmdline_parse_token_num_t cmd_lfc_set_portid =
6923         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 port_id, RTE_UINT16);
6925
6926 /* forward declaration */
6927 static void
6928 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6929                               void *data);
6930
6931 cmdline_parse_inst_t cmd_link_flow_control_set = {
6932         .f = cmd_link_flow_ctrl_set_parsed,
6933         .data = NULL,
6934         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6935                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6936                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6937         .tokens = {
6938                 (void *)&cmd_lfc_set_set,
6939                 (void *)&cmd_lfc_set_flow_ctrl,
6940                 (void *)&cmd_lfc_set_rx,
6941                 (void *)&cmd_lfc_set_rx_mode,
6942                 (void *)&cmd_lfc_set_tx,
6943                 (void *)&cmd_lfc_set_tx_mode,
6944                 (void *)&cmd_lfc_set_high_water,
6945                 (void *)&cmd_lfc_set_low_water,
6946                 (void *)&cmd_lfc_set_pause_time,
6947                 (void *)&cmd_lfc_set_send_xon,
6948                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6949                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6950                 (void *)&cmd_lfc_set_autoneg_str,
6951                 (void *)&cmd_lfc_set_autoneg,
6952                 (void *)&cmd_lfc_set_portid,
6953                 NULL,
6954         },
6955 };
6956
6957 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6958         .f = cmd_link_flow_ctrl_set_parsed,
6959         .data = (void *)&cmd_link_flow_control_set_rx,
6960         .help_str = "set flow_ctrl rx on|off <port_id>: "
6961                 "Change rx flow control parameter",
6962         .tokens = {
6963                 (void *)&cmd_lfc_set_set,
6964                 (void *)&cmd_lfc_set_flow_ctrl,
6965                 (void *)&cmd_lfc_set_rx,
6966                 (void *)&cmd_lfc_set_rx_mode,
6967                 (void *)&cmd_lfc_set_portid,
6968                 NULL,
6969         },
6970 };
6971
6972 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6973         .f = cmd_link_flow_ctrl_set_parsed,
6974         .data = (void *)&cmd_link_flow_control_set_tx,
6975         .help_str = "set flow_ctrl tx on|off <port_id>: "
6976                 "Change tx flow control parameter",
6977         .tokens = {
6978                 (void *)&cmd_lfc_set_set,
6979                 (void *)&cmd_lfc_set_flow_ctrl,
6980                 (void *)&cmd_lfc_set_tx,
6981                 (void *)&cmd_lfc_set_tx_mode,
6982                 (void *)&cmd_lfc_set_portid,
6983                 NULL,
6984         },
6985 };
6986
6987 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6988         .f = cmd_link_flow_ctrl_set_parsed,
6989         .data = (void *)&cmd_link_flow_control_set_hw,
6990         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6991                 "Change high water flow control parameter",
6992         .tokens = {
6993                 (void *)&cmd_lfc_set_set,
6994                 (void *)&cmd_lfc_set_flow_ctrl,
6995                 (void *)&cmd_lfc_set_high_water_str,
6996                 (void *)&cmd_lfc_set_high_water,
6997                 (void *)&cmd_lfc_set_portid,
6998                 NULL,
6999         },
7000 };
7001
7002 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7003         .f = cmd_link_flow_ctrl_set_parsed,
7004         .data = (void *)&cmd_link_flow_control_set_lw,
7005         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7006                 "Change low water flow control parameter",
7007         .tokens = {
7008                 (void *)&cmd_lfc_set_set,
7009                 (void *)&cmd_lfc_set_flow_ctrl,
7010                 (void *)&cmd_lfc_set_low_water_str,
7011                 (void *)&cmd_lfc_set_low_water,
7012                 (void *)&cmd_lfc_set_portid,
7013                 NULL,
7014         },
7015 };
7016
7017 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7018         .f = cmd_link_flow_ctrl_set_parsed,
7019         .data = (void *)&cmd_link_flow_control_set_pt,
7020         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7021                 "Change pause time flow control parameter",
7022         .tokens = {
7023                 (void *)&cmd_lfc_set_set,
7024                 (void *)&cmd_lfc_set_flow_ctrl,
7025                 (void *)&cmd_lfc_set_pause_time_str,
7026                 (void *)&cmd_lfc_set_pause_time,
7027                 (void *)&cmd_lfc_set_portid,
7028                 NULL,
7029         },
7030 };
7031
7032 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7033         .f = cmd_link_flow_ctrl_set_parsed,
7034         .data = (void *)&cmd_link_flow_control_set_xon,
7035         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7036                 "Change send_xon flow control parameter",
7037         .tokens = {
7038                 (void *)&cmd_lfc_set_set,
7039                 (void *)&cmd_lfc_set_flow_ctrl,
7040                 (void *)&cmd_lfc_set_send_xon_str,
7041                 (void *)&cmd_lfc_set_send_xon,
7042                 (void *)&cmd_lfc_set_portid,
7043                 NULL,
7044         },
7045 };
7046
7047 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7048         .f = cmd_link_flow_ctrl_set_parsed,
7049         .data = (void *)&cmd_link_flow_control_set_macfwd,
7050         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7051                 "Change mac ctrl fwd flow control parameter",
7052         .tokens = {
7053                 (void *)&cmd_lfc_set_set,
7054                 (void *)&cmd_lfc_set_flow_ctrl,
7055                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7056                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7057                 (void *)&cmd_lfc_set_portid,
7058                 NULL,
7059         },
7060 };
7061
7062 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7063         .f = cmd_link_flow_ctrl_set_parsed,
7064         .data = (void *)&cmd_link_flow_control_set_autoneg,
7065         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7066                 "Change autoneg flow control parameter",
7067         .tokens = {
7068                 (void *)&cmd_lfc_set_set,
7069                 (void *)&cmd_lfc_set_flow_ctrl,
7070                 (void *)&cmd_lfc_set_autoneg_str,
7071                 (void *)&cmd_lfc_set_autoneg,
7072                 (void *)&cmd_lfc_set_portid,
7073                 NULL,
7074         },
7075 };
7076
7077 static void
7078 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7079                               __rte_unused struct cmdline *cl,
7080                               void *data)
7081 {
7082         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7083         cmdline_parse_inst_t *cmd = data;
7084         struct rte_eth_fc_conf fc_conf;
7085         int rx_fc_en = 0;
7086         int tx_fc_en = 0;
7087         int ret;
7088
7089         /*
7090          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7091          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7092          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7093          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7094          */
7095         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7096                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7097         };
7098
7099         /* Partial command line, retrieve current configuration */
7100         if (cmd) {
7101                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7102                 if (ret != 0) {
7103                         printf("cannot get current flow ctrl parameters, return"
7104                                "code = %d\n", ret);
7105                         return;
7106                 }
7107
7108                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7109                     (fc_conf.mode == RTE_FC_FULL))
7110                         rx_fc_en = 1;
7111                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7112                     (fc_conf.mode == RTE_FC_FULL))
7113                         tx_fc_en = 1;
7114         }
7115
7116         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7117                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7118
7119         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7120                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7121
7122         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7123
7124         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7125                 fc_conf.high_water = res->high_water;
7126
7127         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7128                 fc_conf.low_water = res->low_water;
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7131                 fc_conf.pause_time = res->pause_time;
7132
7133         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7134                 fc_conf.send_xon = res->send_xon;
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7137                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7138                         fc_conf.mac_ctrl_frame_fwd = 1;
7139                 else
7140                         fc_conf.mac_ctrl_frame_fwd = 0;
7141         }
7142
7143         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7144                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7145
7146         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7147         if (ret != 0)
7148                 printf("bad flow contrl parameter, return code = %d \n", ret);
7149 }
7150
7151 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7152 struct cmd_priority_flow_ctrl_set_result {
7153         cmdline_fixed_string_t set;
7154         cmdline_fixed_string_t pfc_ctrl;
7155         cmdline_fixed_string_t rx;
7156         cmdline_fixed_string_t rx_pfc_mode;
7157         cmdline_fixed_string_t tx;
7158         cmdline_fixed_string_t tx_pfc_mode;
7159         uint32_t high_water;
7160         uint32_t low_water;
7161         uint16_t pause_time;
7162         uint8_t  priority;
7163         portid_t port_id;
7164 };
7165
7166 static void
7167 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7168                        __rte_unused struct cmdline *cl,
7169                        __rte_unused void *data)
7170 {
7171         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7172         struct rte_eth_pfc_conf pfc_conf;
7173         int rx_fc_enable, tx_fc_enable;
7174         int ret;
7175
7176         /*
7177          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7178          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7179          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7180          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7181          */
7182         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7183                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7184         };
7185
7186         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7187         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7188         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7189         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7190         pfc_conf.fc.high_water = res->high_water;
7191         pfc_conf.fc.low_water  = res->low_water;
7192         pfc_conf.fc.pause_time = res->pause_time;
7193         pfc_conf.priority      = res->priority;
7194
7195         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7196         if (ret != 0)
7197                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7198 }
7199
7200 cmdline_parse_token_string_t cmd_pfc_set_set =
7201         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7202                                 set, "set");
7203 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205                                 pfc_ctrl, "pfc_ctrl");
7206 cmdline_parse_token_string_t cmd_pfc_set_rx =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 rx, "rx");
7209 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 rx_pfc_mode, "on#off");
7212 cmdline_parse_token_string_t cmd_pfc_set_tx =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 tx, "tx");
7215 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 tx_pfc_mode, "on#off");
7218 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7219         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 high_water, RTE_UINT32);
7221 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 low_water, RTE_UINT32);
7224 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 pause_time, RTE_UINT16);
7227 cmdline_parse_token_num_t cmd_pfc_set_priority =
7228         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 priority, RTE_UINT8);
7230 cmdline_parse_token_num_t cmd_pfc_set_portid =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 port_id, RTE_UINT16);
7233
7234 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7235         .f = cmd_priority_flow_ctrl_set_parsed,
7236         .data = NULL,
7237         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7238                 "<pause_time> <priority> <port_id>: "
7239                 "Configure the Ethernet priority flow control",
7240         .tokens = {
7241                 (void *)&cmd_pfc_set_set,
7242                 (void *)&cmd_pfc_set_flow_ctrl,
7243                 (void *)&cmd_pfc_set_rx,
7244                 (void *)&cmd_pfc_set_rx_mode,
7245                 (void *)&cmd_pfc_set_tx,
7246                 (void *)&cmd_pfc_set_tx_mode,
7247                 (void *)&cmd_pfc_set_high_water,
7248                 (void *)&cmd_pfc_set_low_water,
7249                 (void *)&cmd_pfc_set_pause_time,
7250                 (void *)&cmd_pfc_set_priority,
7251                 (void *)&cmd_pfc_set_portid,
7252                 NULL,
7253         },
7254 };
7255
7256 /* *** RESET CONFIGURATION *** */
7257 struct cmd_reset_result {
7258         cmdline_fixed_string_t reset;
7259         cmdline_fixed_string_t def;
7260 };
7261
7262 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7263                              struct cmdline *cl,
7264                              __rte_unused void *data)
7265 {
7266         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7267         set_def_fwd_config();
7268 }
7269
7270 cmdline_parse_token_string_t cmd_reset_set =
7271         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7272 cmdline_parse_token_string_t cmd_reset_def =
7273         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7274                                  "default");
7275
7276 cmdline_parse_inst_t cmd_reset = {
7277         .f = cmd_reset_parsed,
7278         .data = NULL,
7279         .help_str = "set default: Reset default forwarding configuration",
7280         .tokens = {
7281                 (void *)&cmd_reset_set,
7282                 (void *)&cmd_reset_def,
7283                 NULL,
7284         },
7285 };
7286
7287 /* *** START FORWARDING *** */
7288 struct cmd_start_result {
7289         cmdline_fixed_string_t start;
7290 };
7291
7292 cmdline_parse_token_string_t cmd_start_start =
7293         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7294
7295 static void cmd_start_parsed(__rte_unused void *parsed_result,
7296                              __rte_unused struct cmdline *cl,
7297                              __rte_unused void *data)
7298 {
7299         start_packet_forwarding(0);
7300 }
7301
7302 cmdline_parse_inst_t cmd_start = {
7303         .f = cmd_start_parsed,
7304         .data = NULL,
7305         .help_str = "start: Start packet forwarding",
7306         .tokens = {
7307                 (void *)&cmd_start_start,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7313 struct cmd_start_tx_first_result {
7314         cmdline_fixed_string_t start;
7315         cmdline_fixed_string_t tx_first;
7316 };
7317
7318 static void
7319 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7320                           __rte_unused struct cmdline *cl,
7321                           __rte_unused void *data)
7322 {
7323         start_packet_forwarding(1);
7324 }
7325
7326 cmdline_parse_token_string_t cmd_start_tx_first_start =
7327         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7328                                  "start");
7329 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7330         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7331                                  tx_first, "tx_first");
7332
7333 cmdline_parse_inst_t cmd_start_tx_first = {
7334         .f = cmd_start_tx_first_parsed,
7335         .data = NULL,
7336         .help_str = "start tx_first: Start packet forwarding, "
7337                 "after sending 1 burst of packets",
7338         .tokens = {
7339                 (void *)&cmd_start_tx_first_start,
7340                 (void *)&cmd_start_tx_first_tx_first,
7341                 NULL,
7342         },
7343 };
7344
7345 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7346 struct cmd_start_tx_first_n_result {
7347         cmdline_fixed_string_t start;
7348         cmdline_fixed_string_t tx_first;
7349         uint32_t tx_num;
7350 };
7351
7352 static void
7353 cmd_start_tx_first_n_parsed(void *parsed_result,
7354                           __rte_unused struct cmdline *cl,
7355                           __rte_unused void *data)
7356 {
7357         struct cmd_start_tx_first_n_result *res = parsed_result;
7358
7359         start_packet_forwarding(res->tx_num);
7360 }
7361
7362 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7363         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7364                         start, "start");
7365 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7366         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7367                         tx_first, "tx_first");
7368 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7369         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7370                         tx_num, RTE_UINT32);
7371
7372 cmdline_parse_inst_t cmd_start_tx_first_n = {
7373         .f = cmd_start_tx_first_n_parsed,
7374         .data = NULL,
7375         .help_str = "start tx_first <num>: "
7376                 "packet forwarding, after sending <num> bursts of packets",
7377         .tokens = {
7378                 (void *)&cmd_start_tx_first_n_start,
7379                 (void *)&cmd_start_tx_first_n_tx_first,
7380                 (void *)&cmd_start_tx_first_n_tx_num,
7381                 NULL,
7382         },
7383 };
7384
7385 /* *** SET LINK UP *** */
7386 struct cmd_set_link_up_result {
7387         cmdline_fixed_string_t set;
7388         cmdline_fixed_string_t link_up;
7389         cmdline_fixed_string_t port;
7390         portid_t port_id;
7391 };
7392
7393 cmdline_parse_token_string_t cmd_set_link_up_set =
7394         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7395 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7396         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7397                                 "link-up");
7398 cmdline_parse_token_string_t cmd_set_link_up_port =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7400 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7401         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7402                                 RTE_UINT16);
7403
7404 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7405                              __rte_unused struct cmdline *cl,
7406                              __rte_unused void *data)
7407 {
7408         struct cmd_set_link_up_result *res = parsed_result;
7409         dev_set_link_up(res->port_id);
7410 }
7411
7412 cmdline_parse_inst_t cmd_set_link_up = {
7413         .f = cmd_set_link_up_parsed,
7414         .data = NULL,
7415         .help_str = "set link-up port <port id>",
7416         .tokens = {
7417                 (void *)&cmd_set_link_up_set,
7418                 (void *)&cmd_set_link_up_link_up,
7419                 (void *)&cmd_set_link_up_port,
7420                 (void *)&cmd_set_link_up_port_id,
7421                 NULL,
7422         },
7423 };
7424
7425 /* *** SET LINK DOWN *** */
7426 struct cmd_set_link_down_result {
7427         cmdline_fixed_string_t set;
7428         cmdline_fixed_string_t link_down;
7429         cmdline_fixed_string_t port;
7430         portid_t port_id;
7431 };
7432
7433 cmdline_parse_token_string_t cmd_set_link_down_set =
7434         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7435 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7436         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7437                                 "link-down");
7438 cmdline_parse_token_string_t cmd_set_link_down_port =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7440 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7441         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7442                                 RTE_UINT16);
7443
7444 static void cmd_set_link_down_parsed(
7445                                 __rte_unused void *parsed_result,
7446                                 __rte_unused struct cmdline *cl,
7447                                 __rte_unused void *data)
7448 {
7449         struct cmd_set_link_down_result *res = parsed_result;
7450         dev_set_link_down(res->port_id);
7451 }
7452
7453 cmdline_parse_inst_t cmd_set_link_down = {
7454         .f = cmd_set_link_down_parsed,
7455         .data = NULL,
7456         .help_str = "set link-down port <port id>",
7457         .tokens = {
7458                 (void *)&cmd_set_link_down_set,
7459                 (void *)&cmd_set_link_down_link_down,
7460                 (void *)&cmd_set_link_down_port,
7461                 (void *)&cmd_set_link_down_port_id,
7462                 NULL,
7463         },
7464 };
7465
7466 /* *** SHOW CFG *** */
7467 struct cmd_showcfg_result {
7468         cmdline_fixed_string_t show;
7469         cmdline_fixed_string_t cfg;
7470         cmdline_fixed_string_t what;
7471 };
7472
7473 static void cmd_showcfg_parsed(void *parsed_result,
7474                                __rte_unused struct cmdline *cl,
7475                                __rte_unused void *data)
7476 {
7477         struct cmd_showcfg_result *res = parsed_result;
7478         if (!strcmp(res->what, "rxtx"))
7479                 rxtx_config_display();
7480         else if (!strcmp(res->what, "cores"))
7481                 fwd_lcores_config_display();
7482         else if (!strcmp(res->what, "fwd"))
7483                 pkt_fwd_config_display(&cur_fwd_config);
7484         else if (!strcmp(res->what, "rxoffs"))
7485                 show_rx_pkt_offsets();
7486         else if (!strcmp(res->what, "rxpkts"))
7487                 show_rx_pkt_segments();
7488         else if (!strcmp(res->what, "txpkts"))
7489                 show_tx_pkt_segments();
7490         else if (!strcmp(res->what, "txtimes"))
7491                 show_tx_pkt_times();
7492 }
7493
7494 cmdline_parse_token_string_t cmd_showcfg_show =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7496 cmdline_parse_token_string_t cmd_showcfg_port =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7498 cmdline_parse_token_string_t cmd_showcfg_what =
7499         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7500                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7501
7502 cmdline_parse_inst_t cmd_showcfg = {
7503         .f = cmd_showcfg_parsed,
7504         .data = NULL,
7505         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7506         .tokens = {
7507                 (void *)&cmd_showcfg_show,
7508                 (void *)&cmd_showcfg_port,
7509                 (void *)&cmd_showcfg_what,
7510                 NULL,
7511         },
7512 };
7513
7514 /* *** SHOW ALL PORT INFO *** */
7515 struct cmd_showportall_result {
7516         cmdline_fixed_string_t show;
7517         cmdline_fixed_string_t port;
7518         cmdline_fixed_string_t what;
7519         cmdline_fixed_string_t all;
7520 };
7521
7522 static void cmd_showportall_parsed(void *parsed_result,
7523                                 __rte_unused struct cmdline *cl,
7524                                 __rte_unused void *data)
7525 {
7526         portid_t i;
7527
7528         struct cmd_showportall_result *res = parsed_result;
7529         if (!strcmp(res->show, "clear")) {
7530                 if (!strcmp(res->what, "stats"))
7531                         RTE_ETH_FOREACH_DEV(i)
7532                                 nic_stats_clear(i);
7533                 else if (!strcmp(res->what, "xstats"))
7534                         RTE_ETH_FOREACH_DEV(i)
7535                                 nic_xstats_clear(i);
7536         } else if (!strcmp(res->what, "info"))
7537                 RTE_ETH_FOREACH_DEV(i)
7538                         port_infos_display(i);
7539         else if (!strcmp(res->what, "summary")) {
7540                 port_summary_header_display();
7541                 RTE_ETH_FOREACH_DEV(i)
7542                         port_summary_display(i);
7543         }
7544         else if (!strcmp(res->what, "stats"))
7545                 RTE_ETH_FOREACH_DEV(i)
7546                         nic_stats_display(i);
7547         else if (!strcmp(res->what, "xstats"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_xstats_display(i);
7550 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7551         else if (!strcmp(res->what, "fdir"))
7552                 RTE_ETH_FOREACH_DEV(i)
7553                         fdir_get_infos(i);
7554 #endif
7555         else if (!strcmp(res->what, "stat_qmap"))
7556                 RTE_ETH_FOREACH_DEV(i)
7557                         nic_stats_mapping_display(i);
7558         else if (!strcmp(res->what, "dcb_tc"))
7559                 RTE_ETH_FOREACH_DEV(i)
7560                         port_dcb_info_display(i);
7561         else if (!strcmp(res->what, "cap"))
7562                 RTE_ETH_FOREACH_DEV(i)
7563                         port_offload_cap_display(i);
7564 }
7565
7566 cmdline_parse_token_string_t cmd_showportall_show =
7567         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7568                                  "show#clear");
7569 cmdline_parse_token_string_t cmd_showportall_port =
7570         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7571 cmdline_parse_token_string_t cmd_showportall_what =
7572         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7573                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7574 cmdline_parse_token_string_t cmd_showportall_all =
7575         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7576 cmdline_parse_inst_t cmd_showportall = {
7577         .f = cmd_showportall_parsed,
7578         .data = NULL,
7579         .help_str = "show|clear port "
7580                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7581         .tokens = {
7582                 (void *)&cmd_showportall_show,
7583                 (void *)&cmd_showportall_port,
7584                 (void *)&cmd_showportall_what,
7585                 (void *)&cmd_showportall_all,
7586                 NULL,
7587         },
7588 };
7589
7590 /* *** SHOW PORT INFO *** */
7591 struct cmd_showport_result {
7592         cmdline_fixed_string_t show;
7593         cmdline_fixed_string_t port;
7594         cmdline_fixed_string_t what;
7595         uint16_t portnum;
7596 };
7597
7598 static void cmd_showport_parsed(void *parsed_result,
7599                                 __rte_unused struct cmdline *cl,
7600                                 __rte_unused void *data)
7601 {
7602         struct cmd_showport_result *res = parsed_result;
7603         if (!strcmp(res->show, "clear")) {
7604                 if (!strcmp(res->what, "stats"))
7605                         nic_stats_clear(res->portnum);
7606                 else if (!strcmp(res->what, "xstats"))
7607                         nic_xstats_clear(res->portnum);
7608         } else if (!strcmp(res->what, "info"))
7609                 port_infos_display(res->portnum);
7610         else if (!strcmp(res->what, "summary")) {
7611                 port_summary_header_display();
7612                 port_summary_display(res->portnum);
7613         }
7614         else if (!strcmp(res->what, "stats"))
7615                 nic_stats_display(res->portnum);
7616         else if (!strcmp(res->what, "xstats"))
7617                 nic_xstats_display(res->portnum);
7618 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7619         else if (!strcmp(res->what, "fdir"))
7620                  fdir_get_infos(res->portnum);
7621 #endif
7622         else if (!strcmp(res->what, "stat_qmap"))
7623                 nic_stats_mapping_display(res->portnum);
7624         else if (!strcmp(res->what, "dcb_tc"))
7625                 port_dcb_info_display(res->portnum);
7626         else if (!strcmp(res->what, "cap"))
7627                 port_offload_cap_display(res->portnum);
7628 }
7629
7630 cmdline_parse_token_string_t cmd_showport_show =
7631         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7632                                  "show#clear");
7633 cmdline_parse_token_string_t cmd_showport_port =
7634         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7635 cmdline_parse_token_string_t cmd_showport_what =
7636         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7637                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7638 cmdline_parse_token_num_t cmd_showport_portnum =
7639         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7640
7641 cmdline_parse_inst_t cmd_showport = {
7642         .f = cmd_showport_parsed,
7643         .data = NULL,
7644         .help_str = "show|clear port "
7645                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7646                 "<port_id>",
7647         .tokens = {
7648                 (void *)&cmd_showport_show,
7649                 (void *)&cmd_showport_port,
7650                 (void *)&cmd_showport_what,
7651                 (void *)&cmd_showport_portnum,
7652                 NULL,
7653         },
7654 };
7655
7656 /* *** SHOW DEVICE INFO *** */
7657 struct cmd_showdevice_result {
7658         cmdline_fixed_string_t show;
7659         cmdline_fixed_string_t device;
7660         cmdline_fixed_string_t what;
7661         cmdline_fixed_string_t identifier;
7662 };
7663
7664 static void cmd_showdevice_parsed(void *parsed_result,
7665                                 __rte_unused struct cmdline *cl,
7666                                 __rte_unused void *data)
7667 {
7668         struct cmd_showdevice_result *res = parsed_result;
7669         if (!strcmp(res->what, "info")) {
7670                 if (!strcmp(res->identifier, "all"))
7671                         device_infos_display(NULL);
7672                 else
7673                         device_infos_display(res->identifier);
7674         }
7675 }
7676
7677 cmdline_parse_token_string_t cmd_showdevice_show =
7678         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7679                                  "show");
7680 cmdline_parse_token_string_t cmd_showdevice_device =
7681         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7682 cmdline_parse_token_string_t cmd_showdevice_what =
7683         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7684                                  "info");
7685 cmdline_parse_token_string_t cmd_showdevice_identifier =
7686         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7687                         identifier, NULL);
7688
7689 cmdline_parse_inst_t cmd_showdevice = {
7690         .f = cmd_showdevice_parsed,
7691         .data = NULL,
7692         .help_str = "show device info <identifier>|all",
7693         .tokens = {
7694                 (void *)&cmd_showdevice_show,
7695                 (void *)&cmd_showdevice_device,
7696                 (void *)&cmd_showdevice_what,
7697                 (void *)&cmd_showdevice_identifier,
7698                 NULL,
7699         },
7700 };
7701
7702 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7703 struct cmd_showeeprom_result {
7704         cmdline_fixed_string_t show;
7705         cmdline_fixed_string_t port;
7706         uint16_t portnum;
7707         cmdline_fixed_string_t type;
7708 };
7709
7710 static void cmd_showeeprom_parsed(void *parsed_result,
7711                 __rte_unused struct cmdline *cl,
7712                 __rte_unused void *data)
7713 {
7714         struct cmd_showeeprom_result *res = parsed_result;
7715
7716         if (!strcmp(res->type, "eeprom"))
7717                 port_eeprom_display(res->portnum);
7718         else if (!strcmp(res->type, "module_eeprom"))
7719                 port_module_eeprom_display(res->portnum);
7720         else
7721                 printf("Unknown argument\n");
7722 }
7723
7724 cmdline_parse_token_string_t cmd_showeeprom_show =
7725         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7726 cmdline_parse_token_string_t cmd_showeeprom_port =
7727         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7728 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7729         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7730                         RTE_UINT16);
7731 cmdline_parse_token_string_t cmd_showeeprom_type =
7732         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7733
7734 cmdline_parse_inst_t cmd_showeeprom = {
7735         .f = cmd_showeeprom_parsed,
7736         .data = NULL,
7737         .help_str = "show port <port_id> module_eeprom|eeprom",
7738         .tokens = {
7739                 (void *)&cmd_showeeprom_show,
7740                 (void *)&cmd_showeeprom_port,
7741                 (void *)&cmd_showeeprom_portnum,
7742                 (void *)&cmd_showeeprom_type,
7743                 NULL,
7744         },
7745 };
7746
7747 /* *** SHOW QUEUE INFO *** */
7748 struct cmd_showqueue_result {
7749         cmdline_fixed_string_t show;
7750         cmdline_fixed_string_t type;
7751         cmdline_fixed_string_t what;
7752         uint16_t portnum;
7753         uint16_t queuenum;
7754 };
7755
7756 static void
7757 cmd_showqueue_parsed(void *parsed_result,
7758         __rte_unused struct cmdline *cl,
7759         __rte_unused void *data)
7760 {
7761         struct cmd_showqueue_result *res = parsed_result;
7762
7763         if (!strcmp(res->type, "rxq"))
7764                 rx_queue_infos_display(res->portnum, res->queuenum);
7765         else if (!strcmp(res->type, "txq"))
7766                 tx_queue_infos_display(res->portnum, res->queuenum);
7767 }
7768
7769 cmdline_parse_token_string_t cmd_showqueue_show =
7770         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7771 cmdline_parse_token_string_t cmd_showqueue_type =
7772         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7773 cmdline_parse_token_string_t cmd_showqueue_what =
7774         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7775 cmdline_parse_token_num_t cmd_showqueue_portnum =
7776         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7777                 RTE_UINT16);
7778 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7779         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7780                 RTE_UINT16);
7781
7782 cmdline_parse_inst_t cmd_showqueue = {
7783         .f = cmd_showqueue_parsed,
7784         .data = NULL,
7785         .help_str = "show rxq|txq info <port_id> <queue_id>",
7786         .tokens = {
7787                 (void *)&cmd_showqueue_show,
7788                 (void *)&cmd_showqueue_type,
7789                 (void *)&cmd_showqueue_what,
7790                 (void *)&cmd_showqueue_portnum,
7791                 (void *)&cmd_showqueue_queuenum,
7792                 NULL,
7793         },
7794 };
7795
7796 /* show/clear fwd engine statistics */
7797 struct fwd_result {
7798         cmdline_fixed_string_t action;
7799         cmdline_fixed_string_t fwd;
7800         cmdline_fixed_string_t stats;
7801         cmdline_fixed_string_t all;
7802 };
7803
7804 cmdline_parse_token_string_t cmd_fwd_action =
7805         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7806 cmdline_parse_token_string_t cmd_fwd_fwd =
7807         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7808 cmdline_parse_token_string_t cmd_fwd_stats =
7809         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7810 cmdline_parse_token_string_t cmd_fwd_all =
7811         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7812
7813 static void
7814 cmd_showfwdall_parsed(void *parsed_result,
7815                       __rte_unused struct cmdline *cl,
7816                       __rte_unused void *data)
7817 {
7818         struct fwd_result *res = parsed_result;
7819
7820         if (!strcmp(res->action, "show"))
7821                 fwd_stats_display();
7822         else
7823                 fwd_stats_reset();
7824 }
7825
7826 static cmdline_parse_inst_t cmd_showfwdall = {
7827         .f = cmd_showfwdall_parsed,
7828         .data = NULL,
7829         .help_str = "show|clear fwd stats all",
7830         .tokens = {
7831                 (void *)&cmd_fwd_action,
7832                 (void *)&cmd_fwd_fwd,
7833                 (void *)&cmd_fwd_stats,
7834                 (void *)&cmd_fwd_all,
7835                 NULL,
7836         },
7837 };
7838
7839 /* *** READ PORT REGISTER *** */
7840 struct cmd_read_reg_result {
7841         cmdline_fixed_string_t read;
7842         cmdline_fixed_string_t reg;
7843         portid_t port_id;
7844         uint32_t reg_off;
7845 };
7846
7847 static void
7848 cmd_read_reg_parsed(void *parsed_result,
7849                     __rte_unused struct cmdline *cl,
7850                     __rte_unused void *data)
7851 {
7852         struct cmd_read_reg_result *res = parsed_result;
7853         port_reg_display(res->port_id, res->reg_off);
7854 }
7855
7856 cmdline_parse_token_string_t cmd_read_reg_read =
7857         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7858 cmdline_parse_token_string_t cmd_read_reg_reg =
7859         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7860 cmdline_parse_token_num_t cmd_read_reg_port_id =
7861         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7862 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7863         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7864
7865 cmdline_parse_inst_t cmd_read_reg = {
7866         .f = cmd_read_reg_parsed,
7867         .data = NULL,
7868         .help_str = "read reg <port_id> <reg_off>",
7869         .tokens = {
7870                 (void *)&cmd_read_reg_read,
7871                 (void *)&cmd_read_reg_reg,
7872                 (void *)&cmd_read_reg_port_id,
7873                 (void *)&cmd_read_reg_reg_off,
7874                 NULL,
7875         },
7876 };
7877
7878 /* *** READ PORT REGISTER BIT FIELD *** */
7879 struct cmd_read_reg_bit_field_result {
7880         cmdline_fixed_string_t read;
7881         cmdline_fixed_string_t regfield;
7882         portid_t port_id;
7883         uint32_t reg_off;
7884         uint8_t bit1_pos;
7885         uint8_t bit2_pos;
7886 };
7887
7888 static void
7889 cmd_read_reg_bit_field_parsed(void *parsed_result,
7890                               __rte_unused struct cmdline *cl,
7891                               __rte_unused void *data)
7892 {
7893         struct cmd_read_reg_bit_field_result *res = parsed_result;
7894         port_reg_bit_field_display(res->port_id, res->reg_off,
7895                                    res->bit1_pos, res->bit2_pos);
7896 }
7897
7898 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7899         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7900                                  "read");
7901 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7902         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7903                                  regfield, "regfield");
7904 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7905         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7906                               RTE_UINT16);
7907 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7908         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7909                               RTE_UINT32);
7910 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7911         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7912                               RTE_UINT8);
7913 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7914         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7915                               RTE_UINT8);
7916
7917 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7918         .f = cmd_read_reg_bit_field_parsed,
7919         .data = NULL,
7920         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7921         "Read register bit field between bit_x and bit_y included",
7922         .tokens = {
7923                 (void *)&cmd_read_reg_bit_field_read,
7924                 (void *)&cmd_read_reg_bit_field_regfield,
7925                 (void *)&cmd_read_reg_bit_field_port_id,
7926                 (void *)&cmd_read_reg_bit_field_reg_off,
7927                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7928                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7929                 NULL,
7930         },
7931 };
7932
7933 /* *** READ PORT REGISTER BIT *** */
7934 struct cmd_read_reg_bit_result {
7935         cmdline_fixed_string_t read;
7936         cmdline_fixed_string_t regbit;
7937         portid_t port_id;
7938         uint32_t reg_off;
7939         uint8_t bit_pos;
7940 };
7941
7942 static void
7943 cmd_read_reg_bit_parsed(void *parsed_result,
7944                         __rte_unused struct cmdline *cl,
7945                         __rte_unused void *data)
7946 {
7947         struct cmd_read_reg_bit_result *res = parsed_result;
7948         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7949 }
7950
7951 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7952         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7953 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7954         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7955                                  regbit, "regbit");
7956 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7957         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7958                                  RTE_UINT16);
7959 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7960         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7961                                  RTE_UINT32);
7962 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7963         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7964                                  RTE_UINT8);
7965
7966 cmdline_parse_inst_t cmd_read_reg_bit = {
7967         .f = cmd_read_reg_bit_parsed,
7968         .data = NULL,
7969         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7970         .tokens = {
7971                 (void *)&cmd_read_reg_bit_read,
7972                 (void *)&cmd_read_reg_bit_regbit,
7973                 (void *)&cmd_read_reg_bit_port_id,
7974                 (void *)&cmd_read_reg_bit_reg_off,
7975                 (void *)&cmd_read_reg_bit_bit_pos,
7976                 NULL,
7977         },
7978 };
7979
7980 /* *** WRITE PORT REGISTER *** */
7981 struct cmd_write_reg_result {
7982         cmdline_fixed_string_t write;
7983         cmdline_fixed_string_t reg;
7984         portid_t port_id;
7985         uint32_t reg_off;
7986         uint32_t value;
7987 };
7988
7989 static void
7990 cmd_write_reg_parsed(void *parsed_result,
7991                      __rte_unused struct cmdline *cl,
7992                      __rte_unused void *data)
7993 {
7994         struct cmd_write_reg_result *res = parsed_result;
7995         port_reg_set(res->port_id, res->reg_off, res->value);
7996 }
7997
7998 cmdline_parse_token_string_t cmd_write_reg_write =
7999         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8000 cmdline_parse_token_string_t cmd_write_reg_reg =
8001         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8002 cmdline_parse_token_num_t cmd_write_reg_port_id =
8003         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8004 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8005         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8006 cmdline_parse_token_num_t cmd_write_reg_value =
8007         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8008
8009 cmdline_parse_inst_t cmd_write_reg = {
8010         .f = cmd_write_reg_parsed,
8011         .data = NULL,
8012         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8013         .tokens = {
8014                 (void *)&cmd_write_reg_write,
8015                 (void *)&cmd_write_reg_reg,
8016                 (void *)&cmd_write_reg_port_id,
8017                 (void *)&cmd_write_reg_reg_off,
8018                 (void *)&cmd_write_reg_value,
8019                 NULL,
8020         },
8021 };
8022
8023 /* *** WRITE PORT REGISTER BIT FIELD *** */
8024 struct cmd_write_reg_bit_field_result {
8025         cmdline_fixed_string_t write;
8026         cmdline_fixed_string_t regfield;
8027         portid_t port_id;
8028         uint32_t reg_off;
8029         uint8_t bit1_pos;
8030         uint8_t bit2_pos;
8031         uint32_t value;
8032 };
8033
8034 static void
8035 cmd_write_reg_bit_field_parsed(void *parsed_result,
8036                                __rte_unused struct cmdline *cl,
8037                                __rte_unused void *data)
8038 {
8039         struct cmd_write_reg_bit_field_result *res = parsed_result;
8040         port_reg_bit_field_set(res->port_id, res->reg_off,
8041                           res->bit1_pos, res->bit2_pos, res->value);
8042 }
8043
8044 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8045         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8046                                  "write");
8047 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8048         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8049                                  regfield, "regfield");
8050 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8051         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8052                               RTE_UINT16);
8053 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8054         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8055                               RTE_UINT32);
8056 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8057         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8058                               RTE_UINT8);
8059 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8060         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8061                               RTE_UINT8);
8062 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8063         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8064                               RTE_UINT32);
8065
8066 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8067         .f = cmd_write_reg_bit_field_parsed,
8068         .data = NULL,
8069         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8070                 "<reg_value>: "
8071                 "Set register bit field between bit_x and bit_y included",
8072         .tokens = {
8073                 (void *)&cmd_write_reg_bit_field_write,
8074                 (void *)&cmd_write_reg_bit_field_regfield,
8075                 (void *)&cmd_write_reg_bit_field_port_id,
8076                 (void *)&cmd_write_reg_bit_field_reg_off,
8077                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8078                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8079                 (void *)&cmd_write_reg_bit_field_value,
8080                 NULL,
8081         },
8082 };
8083
8084 /* *** WRITE PORT REGISTER BIT *** */
8085 struct cmd_write_reg_bit_result {
8086         cmdline_fixed_string_t write;
8087         cmdline_fixed_string_t regbit;
8088         portid_t port_id;
8089         uint32_t reg_off;
8090         uint8_t bit_pos;
8091         uint8_t value;
8092 };
8093
8094 static void
8095 cmd_write_reg_bit_parsed(void *parsed_result,
8096                          __rte_unused struct cmdline *cl,
8097                          __rte_unused void *data)
8098 {
8099         struct cmd_write_reg_bit_result *res = parsed_result;
8100         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8101 }
8102
8103 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8104         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8105                                  "write");
8106 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8107         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8108                                  regbit, "regbit");
8109 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8110         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8111                                  RTE_UINT16);
8112 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8113         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8114                                  RTE_UINT32);
8115 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8116         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8117                                  RTE_UINT8);
8118 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8119         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8120                                  RTE_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,
8167                                  RTE_UINT16);
8168 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8169         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8170                                  RTE_UINT16);
8171 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8172         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8173                                  RTE_UINT16);
8174
8175 cmdline_parse_inst_t cmd_read_rxd_txd = {
8176         .f = cmd_read_rxd_txd_parsed,
8177         .data = NULL,
8178         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8179         .tokens = {
8180                 (void *)&cmd_read_rxd_txd_read,
8181                 (void *)&cmd_read_rxd_txd_rxd_txd,
8182                 (void *)&cmd_read_rxd_txd_port_id,
8183                 (void *)&cmd_read_rxd_txd_queue_id,
8184                 (void *)&cmd_read_rxd_txd_desc_id,
8185                 NULL,
8186         },
8187 };
8188
8189 /* *** QUIT *** */
8190 struct cmd_quit_result {
8191         cmdline_fixed_string_t quit;
8192 };
8193
8194 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8195                             struct cmdline *cl,
8196                             __rte_unused void *data)
8197 {
8198         cmdline_quit(cl);
8199 }
8200
8201 cmdline_parse_token_string_t cmd_quit_quit =
8202         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8203
8204 cmdline_parse_inst_t cmd_quit = {
8205         .f = cmd_quit_parsed,
8206         .data = NULL,
8207         .help_str = "quit: Exit application",
8208         .tokens = {
8209                 (void *)&cmd_quit_quit,
8210                 NULL,
8211         },
8212 };
8213
8214 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8215 struct cmd_mac_addr_result {
8216         cmdline_fixed_string_t mac_addr_cmd;
8217         cmdline_fixed_string_t what;
8218         uint16_t port_num;
8219         struct rte_ether_addr address;
8220 };
8221
8222 static void cmd_mac_addr_parsed(void *parsed_result,
8223                 __rte_unused struct cmdline *cl,
8224                 __rte_unused void *data)
8225 {
8226         struct cmd_mac_addr_result *res = parsed_result;
8227         int ret;
8228
8229         if (strcmp(res->what, "add") == 0)
8230                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8231         else if (strcmp(res->what, "set") == 0)
8232                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8233                                                        &res->address);
8234         else
8235                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8236
8237         /* check the return value and print it if is < 0 */
8238         if(ret < 0)
8239                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8240
8241 }
8242
8243 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8244         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8245                                 "mac_addr");
8246 cmdline_parse_token_string_t cmd_mac_addr_what =
8247         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8248                                 "add#remove#set");
8249 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8250                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8251                                         RTE_UINT16);
8252 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8253                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8254
8255 cmdline_parse_inst_t cmd_mac_addr = {
8256         .f = cmd_mac_addr_parsed,
8257         .data = (void *)0,
8258         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8259                         "Add/Remove/Set MAC address on port_id",
8260         .tokens = {
8261                 (void *)&cmd_mac_addr_cmd,
8262                 (void *)&cmd_mac_addr_what,
8263                 (void *)&cmd_mac_addr_portnum,
8264                 (void *)&cmd_mac_addr_addr,
8265                 NULL,
8266         },
8267 };
8268
8269 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8270 struct cmd_eth_peer_result {
8271         cmdline_fixed_string_t set;
8272         cmdline_fixed_string_t eth_peer;
8273         portid_t port_id;
8274         cmdline_fixed_string_t peer_addr;
8275 };
8276
8277 static void cmd_set_eth_peer_parsed(void *parsed_result,
8278                         __rte_unused struct cmdline *cl,
8279                         __rte_unused void *data)
8280 {
8281                 struct cmd_eth_peer_result *res = parsed_result;
8282
8283                 if (test_done == 0) {
8284                         printf("Please stop forwarding first\n");
8285                         return;
8286                 }
8287                 if (!strcmp(res->eth_peer, "eth-peer")) {
8288                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8289                         fwd_config_setup();
8290                 }
8291 }
8292 cmdline_parse_token_string_t cmd_eth_peer_set =
8293         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8294 cmdline_parse_token_string_t cmd_eth_peer =
8295         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8296 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8297         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8298                 RTE_UINT16);
8299 cmdline_parse_token_string_t cmd_eth_peer_addr =
8300         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8301
8302 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8303         .f = cmd_set_eth_peer_parsed,
8304         .data = NULL,
8305         .help_str = "set eth-peer <port_id> <peer_mac>",
8306         .tokens = {
8307                 (void *)&cmd_eth_peer_set,
8308                 (void *)&cmd_eth_peer,
8309                 (void *)&cmd_eth_peer_port_id,
8310                 (void *)&cmd_eth_peer_addr,
8311                 NULL,
8312         },
8313 };
8314
8315 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8316 struct cmd_set_qmap_result {
8317         cmdline_fixed_string_t set;
8318         cmdline_fixed_string_t qmap;
8319         cmdline_fixed_string_t what;
8320         portid_t port_id;
8321         uint16_t queue_id;
8322         uint8_t map_value;
8323 };
8324
8325 static void
8326 cmd_set_qmap_parsed(void *parsed_result,
8327                        __rte_unused struct cmdline *cl,
8328                        __rte_unused void *data)
8329 {
8330         struct cmd_set_qmap_result *res = parsed_result;
8331         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8332
8333         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8334 }
8335
8336 cmdline_parse_token_string_t cmd_setqmap_set =
8337         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8338                                  set, "set");
8339 cmdline_parse_token_string_t cmd_setqmap_qmap =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8341                                  qmap, "stat_qmap");
8342 cmdline_parse_token_string_t cmd_setqmap_what =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8344                                  what, "tx#rx");
8345 cmdline_parse_token_num_t cmd_setqmap_portid =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8347                               port_id, RTE_UINT16);
8348 cmdline_parse_token_num_t cmd_setqmap_queueid =
8349         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8350                               queue_id, RTE_UINT16);
8351 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8352         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8353                               map_value, RTE_UINT8);
8354
8355 cmdline_parse_inst_t cmd_set_qmap = {
8356         .f = cmd_set_qmap_parsed,
8357         .data = NULL,
8358         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8359                 "Set statistics mapping value on tx|rx queue_id of port_id",
8360         .tokens = {
8361                 (void *)&cmd_setqmap_set,
8362                 (void *)&cmd_setqmap_qmap,
8363                 (void *)&cmd_setqmap_what,
8364                 (void *)&cmd_setqmap_portid,
8365                 (void *)&cmd_setqmap_queueid,
8366                 (void *)&cmd_setqmap_mapvalue,
8367                 NULL,
8368         },
8369 };
8370
8371 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8372 struct cmd_set_xstats_hide_zero_result {
8373         cmdline_fixed_string_t keyword;
8374         cmdline_fixed_string_t name;
8375         cmdline_fixed_string_t on_off;
8376 };
8377
8378 static void
8379 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8380                         __rte_unused struct cmdline *cl,
8381                         __rte_unused void *data)
8382 {
8383         struct cmd_set_xstats_hide_zero_result *res;
8384         uint16_t on_off = 0;
8385
8386         res = parsed_result;
8387         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8388         set_xstats_hide_zero(on_off);
8389 }
8390
8391 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8392         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8393                                  keyword, "set");
8394 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8395         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8396                                  name, "xstats-hide-zero");
8397 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8398         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8399                                  on_off, "on#off");
8400
8401 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8402         .f = cmd_set_xstats_hide_zero_parsed,
8403         .data = NULL,
8404         .help_str = "set xstats-hide-zero on|off",
8405         .tokens = {
8406                 (void *)&cmd_set_xstats_hide_zero_keyword,
8407                 (void *)&cmd_set_xstats_hide_zero_name,
8408                 (void *)&cmd_set_xstats_hide_zero_on_off,
8409                 NULL,
8410         },
8411 };
8412
8413 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8414 struct cmd_set_record_core_cycles_result {
8415         cmdline_fixed_string_t keyword;
8416         cmdline_fixed_string_t name;
8417         cmdline_fixed_string_t on_off;
8418 };
8419
8420 static void
8421 cmd_set_record_core_cycles_parsed(void *parsed_result,
8422                         __rte_unused struct cmdline *cl,
8423                         __rte_unused void *data)
8424 {
8425         struct cmd_set_record_core_cycles_result *res;
8426         uint16_t on_off = 0;
8427
8428         res = parsed_result;
8429         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8430         set_record_core_cycles(on_off);
8431 }
8432
8433 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8434         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8435                                  keyword, "set");
8436 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8437         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8438                                  name, "record-core-cycles");
8439 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8440         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8441                                  on_off, "on#off");
8442
8443 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8444         .f = cmd_set_record_core_cycles_parsed,
8445         .data = NULL,
8446         .help_str = "set record-core-cycles on|off",
8447         .tokens = {
8448                 (void *)&cmd_set_record_core_cycles_keyword,
8449                 (void *)&cmd_set_record_core_cycles_name,
8450                 (void *)&cmd_set_record_core_cycles_on_off,
8451                 NULL,
8452         },
8453 };
8454
8455 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8456 struct cmd_set_record_burst_stats_result {
8457         cmdline_fixed_string_t keyword;
8458         cmdline_fixed_string_t name;
8459         cmdline_fixed_string_t on_off;
8460 };
8461
8462 static void
8463 cmd_set_record_burst_stats_parsed(void *parsed_result,
8464                         __rte_unused struct cmdline *cl,
8465                         __rte_unused void *data)
8466 {
8467         struct cmd_set_record_burst_stats_result *res;
8468         uint16_t on_off = 0;
8469
8470         res = parsed_result;
8471         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8472         set_record_burst_stats(on_off);
8473 }
8474
8475 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8476         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8477                                  keyword, "set");
8478 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8480                                  name, "record-burst-stats");
8481 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8483                                  on_off, "on#off");
8484
8485 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8486         .f = cmd_set_record_burst_stats_parsed,
8487         .data = NULL,
8488         .help_str = "set record-burst-stats on|off",
8489         .tokens = {
8490                 (void *)&cmd_set_record_burst_stats_keyword,
8491                 (void *)&cmd_set_record_burst_stats_name,
8492                 (void *)&cmd_set_record_burst_stats_on_off,
8493                 NULL,
8494         },
8495 };
8496
8497 /* *** CONFIGURE UNICAST HASH TABLE *** */
8498 struct cmd_set_uc_hash_table {
8499         cmdline_fixed_string_t set;
8500         cmdline_fixed_string_t port;
8501         portid_t port_id;
8502         cmdline_fixed_string_t what;
8503         struct rte_ether_addr address;
8504         cmdline_fixed_string_t mode;
8505 };
8506
8507 static void
8508 cmd_set_uc_hash_parsed(void *parsed_result,
8509                        __rte_unused struct cmdline *cl,
8510                        __rte_unused void *data)
8511 {
8512         int ret=0;
8513         struct cmd_set_uc_hash_table *res = parsed_result;
8514
8515         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8516
8517         if (strcmp(res->what, "uta") == 0)
8518                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8519                                                 &res->address,(uint8_t)is_on);
8520         if (ret < 0)
8521                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8522
8523 }
8524
8525 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8527                                  set, "set");
8528 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8529         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8530                                  port, "port");
8531 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8532         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8533                               port_id, RTE_UINT16);
8534 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8535         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8536                                  what, "uta");
8537 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8538         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8539                                 address);
8540 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8541         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8542                                  mode, "on#off");
8543
8544 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8545         .f = cmd_set_uc_hash_parsed,
8546         .data = NULL,
8547         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8548         .tokens = {
8549                 (void *)&cmd_set_uc_hash_set,
8550                 (void *)&cmd_set_uc_hash_port,
8551                 (void *)&cmd_set_uc_hash_portid,
8552                 (void *)&cmd_set_uc_hash_what,
8553                 (void *)&cmd_set_uc_hash_mac,
8554                 (void *)&cmd_set_uc_hash_mode,
8555                 NULL,
8556         },
8557 };
8558
8559 struct cmd_set_uc_all_hash_table {
8560         cmdline_fixed_string_t set;
8561         cmdline_fixed_string_t port;
8562         portid_t port_id;
8563         cmdline_fixed_string_t what;
8564         cmdline_fixed_string_t value;
8565         cmdline_fixed_string_t mode;
8566 };
8567
8568 static void
8569 cmd_set_uc_all_hash_parsed(void *parsed_result,
8570                        __rte_unused struct cmdline *cl,
8571                        __rte_unused void *data)
8572 {
8573         int ret=0;
8574         struct cmd_set_uc_all_hash_table *res = parsed_result;
8575
8576         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8577
8578         if ((strcmp(res->what, "uta") == 0) &&
8579                 (strcmp(res->value, "all") == 0))
8580                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8581         if (ret < 0)
8582                 printf("bad unicast hash table parameter,"
8583                         "return code = %d \n", ret);
8584 }
8585
8586 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8587         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8588                                  set, "set");
8589 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8590         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8591                                  port, "port");
8592 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8593         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8594                               port_id, RTE_UINT16);
8595 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8596         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8597                                  what, "uta");
8598 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8599         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8600                                 value,"all");
8601 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8602         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8603                                  mode, "on#off");
8604
8605 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8606         .f = cmd_set_uc_all_hash_parsed,
8607         .data = NULL,
8608         .help_str = "set port <port_id> uta all on|off",
8609         .tokens = {
8610                 (void *)&cmd_set_uc_all_hash_set,
8611                 (void *)&cmd_set_uc_all_hash_port,
8612                 (void *)&cmd_set_uc_all_hash_portid,
8613                 (void *)&cmd_set_uc_all_hash_what,
8614                 (void *)&cmd_set_uc_all_hash_value,
8615                 (void *)&cmd_set_uc_all_hash_mode,
8616                 NULL,
8617         },
8618 };
8619
8620 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8621 struct cmd_set_vf_traffic {
8622         cmdline_fixed_string_t set;
8623         cmdline_fixed_string_t port;
8624         portid_t port_id;
8625         cmdline_fixed_string_t vf;
8626         uint8_t vf_id;
8627         cmdline_fixed_string_t what;
8628         cmdline_fixed_string_t mode;
8629 };
8630
8631 static void
8632 cmd_set_vf_traffic_parsed(void *parsed_result,
8633                        __rte_unused struct cmdline *cl,
8634                        __rte_unused void *data)
8635 {
8636         struct cmd_set_vf_traffic *res = parsed_result;
8637         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8638         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8639
8640         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8641 }
8642
8643 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8644         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8645                                  set, "set");
8646 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8647         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8648                                  port, "port");
8649 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8650         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8651                               port_id, RTE_UINT16);
8652 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8653         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8654                                  vf, "vf");
8655 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8656         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8657                               vf_id, RTE_UINT8);
8658 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8659         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8660                                  what, "tx#rx");
8661 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8662         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8663                                  mode, "on#off");
8664
8665 cmdline_parse_inst_t cmd_set_vf_traffic = {
8666         .f = cmd_set_vf_traffic_parsed,
8667         .data = NULL,
8668         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8669         .tokens = {
8670                 (void *)&cmd_setvf_traffic_set,
8671                 (void *)&cmd_setvf_traffic_port,
8672                 (void *)&cmd_setvf_traffic_portid,
8673                 (void *)&cmd_setvf_traffic_vf,
8674                 (void *)&cmd_setvf_traffic_vfid,
8675                 (void *)&cmd_setvf_traffic_what,
8676                 (void *)&cmd_setvf_traffic_mode,
8677                 NULL,
8678         },
8679 };
8680
8681 /* *** CONFIGURE VF RECEIVE MODE *** */
8682 struct cmd_set_vf_rxmode {
8683         cmdline_fixed_string_t set;
8684         cmdline_fixed_string_t port;
8685         portid_t port_id;
8686         cmdline_fixed_string_t vf;
8687         uint8_t vf_id;
8688         cmdline_fixed_string_t what;
8689         cmdline_fixed_string_t mode;
8690         cmdline_fixed_string_t on;
8691 };
8692
8693 static void
8694 cmd_set_vf_rxmode_parsed(void *parsed_result,
8695                        __rte_unused struct cmdline *cl,
8696                        __rte_unused void *data)
8697 {
8698         int ret = -ENOTSUP;
8699         uint16_t vf_rxmode = 0;
8700         struct cmd_set_vf_rxmode *res = parsed_result;
8701
8702         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8703         if (!strcmp(res->what,"rxmode")) {
8704                 if (!strcmp(res->mode, "AUPE"))
8705                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8706                 else if (!strcmp(res->mode, "ROPE"))
8707                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8708                 else if (!strcmp(res->mode, "BAM"))
8709                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8710                 else if (!strncmp(res->mode, "MPE",3))
8711                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8712         }
8713
8714         RTE_SET_USED(is_on);
8715
8716 #ifdef RTE_NET_IXGBE
8717         if (ret == -ENOTSUP)
8718                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8719                                                   vf_rxmode, (uint8_t)is_on);
8720 #endif
8721 #ifdef RTE_NET_BNXT
8722         if (ret == -ENOTSUP)
8723                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8724                                                  vf_rxmode, (uint8_t)is_on);
8725 #endif
8726         if (ret < 0)
8727                 printf("bad VF receive mode parameter, return code = %d \n",
8728                 ret);
8729 }
8730
8731 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8732         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8733                                  set, "set");
8734 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8735         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8736                                  port, "port");
8737 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8738         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8739                               port_id, RTE_UINT16);
8740 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8741         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8742                                  vf, "vf");
8743 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8744         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8745                               vf_id, RTE_UINT8);
8746 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8747         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8748                                  what, "rxmode");
8749 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8750         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8751                                  mode, "AUPE#ROPE#BAM#MPE");
8752 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8753         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8754                                  on, "on#off");
8755
8756 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8757         .f = cmd_set_vf_rxmode_parsed,
8758         .data = NULL,
8759         .help_str = "set port <port_id> vf <vf_id> rxmode "
8760                 "AUPE|ROPE|BAM|MPE on|off",
8761         .tokens = {
8762                 (void *)&cmd_set_vf_rxmode_set,
8763                 (void *)&cmd_set_vf_rxmode_port,
8764                 (void *)&cmd_set_vf_rxmode_portid,
8765                 (void *)&cmd_set_vf_rxmode_vf,
8766                 (void *)&cmd_set_vf_rxmode_vfid,
8767                 (void *)&cmd_set_vf_rxmode_what,
8768                 (void *)&cmd_set_vf_rxmode_mode,
8769                 (void *)&cmd_set_vf_rxmode_on,
8770                 NULL,
8771         },
8772 };
8773
8774 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8775 struct cmd_vf_mac_addr_result {
8776         cmdline_fixed_string_t mac_addr_cmd;
8777         cmdline_fixed_string_t what;
8778         cmdline_fixed_string_t port;
8779         uint16_t port_num;
8780         cmdline_fixed_string_t vf;
8781         uint8_t vf_num;
8782         struct rte_ether_addr address;
8783 };
8784
8785 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8786                 __rte_unused struct cmdline *cl,
8787                 __rte_unused void *data)
8788 {
8789         struct cmd_vf_mac_addr_result *res = parsed_result;
8790         int ret = -ENOTSUP;
8791
8792         if (strcmp(res->what, "add") != 0)
8793                 return;
8794
8795 #ifdef RTE_NET_I40E
8796         if (ret == -ENOTSUP)
8797                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8798                                                    &res->address);
8799 #endif
8800 #ifdef RTE_NET_BNXT
8801         if (ret == -ENOTSUP)
8802                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8803                                                 res->vf_num);
8804 #endif
8805
8806         if(ret < 0)
8807                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8808
8809 }
8810
8811 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8812         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8813                                 mac_addr_cmd,"mac_addr");
8814 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8815         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8816                                 what,"add");
8817 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8818         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8819                                 port,"port");
8820 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8821         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8822                                 port_num, RTE_UINT16);
8823 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8824         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8825                                 vf,"vf");
8826 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8827         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8828                                 vf_num, RTE_UINT8);
8829 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8830         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8831                                 address);
8832
8833 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8834         .f = cmd_vf_mac_addr_parsed,
8835         .data = (void *)0,
8836         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8837                 "Add MAC address filtering for a VF on port_id",
8838         .tokens = {
8839                 (void *)&cmd_vf_mac_addr_cmd,
8840                 (void *)&cmd_vf_mac_addr_what,
8841                 (void *)&cmd_vf_mac_addr_port,
8842                 (void *)&cmd_vf_mac_addr_portnum,
8843                 (void *)&cmd_vf_mac_addr_vf,
8844                 (void *)&cmd_vf_mac_addr_vfnum,
8845                 (void *)&cmd_vf_mac_addr_addr,
8846                 NULL,
8847         },
8848 };
8849
8850 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8851 struct cmd_vf_rx_vlan_filter {
8852         cmdline_fixed_string_t rx_vlan;
8853         cmdline_fixed_string_t what;
8854         uint16_t vlan_id;
8855         cmdline_fixed_string_t port;
8856         portid_t port_id;
8857         cmdline_fixed_string_t vf;
8858         uint64_t vf_mask;
8859 };
8860
8861 static void
8862 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8863                           __rte_unused struct cmdline *cl,
8864                           __rte_unused void *data)
8865 {
8866         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8867         int ret = -ENOTSUP;
8868
8869         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8870
8871 #ifdef RTE_NET_IXGBE
8872         if (ret == -ENOTSUP)
8873                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8874                                 res->vlan_id, res->vf_mask, is_add);
8875 #endif
8876 #ifdef RTE_NET_I40E
8877         if (ret == -ENOTSUP)
8878                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8879                                 res->vlan_id, res->vf_mask, is_add);
8880 #endif
8881 #ifdef RTE_NET_BNXT
8882         if (ret == -ENOTSUP)
8883                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8884                                 res->vlan_id, res->vf_mask, is_add);
8885 #endif
8886
8887         switch (ret) {
8888         case 0:
8889                 break;
8890         case -EINVAL:
8891                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8892                                 res->vlan_id, res->vf_mask);
8893                 break;
8894         case -ENODEV:
8895                 printf("invalid port_id %d\n", res->port_id);
8896                 break;
8897         case -ENOTSUP:
8898                 printf("function not implemented or supported\n");
8899                 break;
8900         default:
8901                 printf("programming error: (%s)\n", strerror(-ret));
8902         }
8903 }
8904
8905 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8906         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8907                                  rx_vlan, "rx_vlan");
8908 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8909         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8910                                  what, "add#rm");
8911 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8912         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8913                               vlan_id, RTE_UINT16);
8914 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8915         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8916                                  port, "port");
8917 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8918         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8919                               port_id, RTE_UINT16);
8920 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8921         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8922                                  vf, "vf");
8923 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8924         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8925                               vf_mask, RTE_UINT64);
8926
8927 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8928         .f = cmd_vf_rx_vlan_filter_parsed,
8929         .data = NULL,
8930         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8931                 "(vf_mask = hexadecimal VF mask)",
8932         .tokens = {
8933                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8934                 (void *)&cmd_vf_rx_vlan_filter_what,
8935                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8936                 (void *)&cmd_vf_rx_vlan_filter_port,
8937                 (void *)&cmd_vf_rx_vlan_filter_portid,
8938                 (void *)&cmd_vf_rx_vlan_filter_vf,
8939                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8940                 NULL,
8941         },
8942 };
8943
8944 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8945 struct cmd_queue_rate_limit_result {
8946         cmdline_fixed_string_t set;
8947         cmdline_fixed_string_t port;
8948         uint16_t port_num;
8949         cmdline_fixed_string_t queue;
8950         uint8_t queue_num;
8951         cmdline_fixed_string_t rate;
8952         uint16_t rate_num;
8953 };
8954
8955 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8956                 __rte_unused struct cmdline *cl,
8957                 __rte_unused void *data)
8958 {
8959         struct cmd_queue_rate_limit_result *res = parsed_result;
8960         int ret = 0;
8961
8962         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8963                 && (strcmp(res->queue, "queue") == 0)
8964                 && (strcmp(res->rate, "rate") == 0))
8965                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8966                                         res->rate_num);
8967         if (ret < 0)
8968                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8969
8970 }
8971
8972 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8973         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8974                                 set, "set");
8975 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8976         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8977                                 port, "port");
8978 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8979         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8980                                 port_num, RTE_UINT16);
8981 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8982         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8983                                 queue, "queue");
8984 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8985         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8986                                 queue_num, RTE_UINT8);
8987 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8988         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8989                                 rate, "rate");
8990 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8991         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8992                                 rate_num, RTE_UINT16);
8993
8994 cmdline_parse_inst_t cmd_queue_rate_limit = {
8995         .f = cmd_queue_rate_limit_parsed,
8996         .data = (void *)0,
8997         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8998                 "Set rate limit for a queue on port_id",
8999         .tokens = {
9000                 (void *)&cmd_queue_rate_limit_set,
9001                 (void *)&cmd_queue_rate_limit_port,
9002                 (void *)&cmd_queue_rate_limit_portnum,
9003                 (void *)&cmd_queue_rate_limit_queue,
9004                 (void *)&cmd_queue_rate_limit_queuenum,
9005                 (void *)&cmd_queue_rate_limit_rate,
9006                 (void *)&cmd_queue_rate_limit_ratenum,
9007                 NULL,
9008         },
9009 };
9010
9011 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9012 struct cmd_vf_rate_limit_result {
9013         cmdline_fixed_string_t set;
9014         cmdline_fixed_string_t port;
9015         uint16_t port_num;
9016         cmdline_fixed_string_t vf;
9017         uint8_t vf_num;
9018         cmdline_fixed_string_t rate;
9019         uint16_t rate_num;
9020         cmdline_fixed_string_t q_msk;
9021         uint64_t q_msk_val;
9022 };
9023
9024 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9025                 __rte_unused struct cmdline *cl,
9026                 __rte_unused void *data)
9027 {
9028         struct cmd_vf_rate_limit_result *res = parsed_result;
9029         int ret = 0;
9030
9031         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9032                 && (strcmp(res->vf, "vf") == 0)
9033                 && (strcmp(res->rate, "rate") == 0)
9034                 && (strcmp(res->q_msk, "queue_mask") == 0))
9035                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9036                                         res->rate_num, res->q_msk_val);
9037         if (ret < 0)
9038                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9039
9040 }
9041
9042 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9043         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9044                                 set, "set");
9045 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9046         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9047                                 port, "port");
9048 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9049         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9050                                 port_num, RTE_UINT16);
9051 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9052         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9053                                 vf, "vf");
9054 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9055         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9056                                 vf_num, RTE_UINT8);
9057 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9058         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9059                                 rate, "rate");
9060 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9061         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9062                                 rate_num, RTE_UINT16);
9063 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9064         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9065                                 q_msk, "queue_mask");
9066 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9067         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9068                                 q_msk_val, RTE_UINT64);
9069
9070 cmdline_parse_inst_t cmd_vf_rate_limit = {
9071         .f = cmd_vf_rate_limit_parsed,
9072         .data = (void *)0,
9073         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9074                 "queue_mask <queue_mask_value>: "
9075                 "Set rate limit for queues of VF on port_id",
9076         .tokens = {
9077                 (void *)&cmd_vf_rate_limit_set,
9078                 (void *)&cmd_vf_rate_limit_port,
9079                 (void *)&cmd_vf_rate_limit_portnum,
9080                 (void *)&cmd_vf_rate_limit_vf,
9081                 (void *)&cmd_vf_rate_limit_vfnum,
9082                 (void *)&cmd_vf_rate_limit_rate,
9083                 (void *)&cmd_vf_rate_limit_ratenum,
9084                 (void *)&cmd_vf_rate_limit_q_msk,
9085                 (void *)&cmd_vf_rate_limit_q_msk_val,
9086                 NULL,
9087         },
9088 };
9089
9090 /* *** CONFIGURE TUNNEL UDP PORT *** */
9091 struct cmd_tunnel_udp_config {
9092         cmdline_fixed_string_t cmd;
9093         cmdline_fixed_string_t what;
9094         uint16_t udp_port;
9095         portid_t port_id;
9096 };
9097
9098 static void
9099 cmd_tunnel_udp_config_parsed(void *parsed_result,
9100                           __rte_unused struct cmdline *cl,
9101                           __rte_unused void *data)
9102 {
9103         struct cmd_tunnel_udp_config *res = parsed_result;
9104         struct rte_eth_udp_tunnel tunnel_udp;
9105         int ret;
9106
9107         tunnel_udp.udp_port = res->udp_port;
9108
9109         if (!strcmp(res->cmd, "rx_vxlan_port"))
9110                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9111
9112         if (!strcmp(res->what, "add"))
9113                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9114                                                       &tunnel_udp);
9115         else
9116                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9117                                                          &tunnel_udp);
9118
9119         if (ret < 0)
9120                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9121 }
9122
9123 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9125                                 cmd, "rx_vxlan_port");
9126 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9128                                 what, "add#rm");
9129 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9131                                 udp_port, RTE_UINT16);
9132 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9134                                 port_id, RTE_UINT16);
9135
9136 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9137         .f = cmd_tunnel_udp_config_parsed,
9138         .data = (void *)0,
9139         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9140                 "Add/Remove a tunneling UDP port filter",
9141         .tokens = {
9142                 (void *)&cmd_tunnel_udp_config_cmd,
9143                 (void *)&cmd_tunnel_udp_config_what,
9144                 (void *)&cmd_tunnel_udp_config_udp_port,
9145                 (void *)&cmd_tunnel_udp_config_port_id,
9146                 NULL,
9147         },
9148 };
9149
9150 struct cmd_config_tunnel_udp_port {
9151         cmdline_fixed_string_t port;
9152         cmdline_fixed_string_t config;
9153         portid_t port_id;
9154         cmdline_fixed_string_t udp_tunnel_port;
9155         cmdline_fixed_string_t action;
9156         cmdline_fixed_string_t tunnel_type;
9157         uint16_t udp_port;
9158 };
9159
9160 static void
9161 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9162                                __rte_unused struct cmdline *cl,
9163                                __rte_unused void *data)
9164 {
9165         struct cmd_config_tunnel_udp_port *res = parsed_result;
9166         struct rte_eth_udp_tunnel tunnel_udp;
9167         int ret = 0;
9168
9169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9170                 return;
9171
9172         tunnel_udp.udp_port = res->udp_port;
9173
9174         if (!strcmp(res->tunnel_type, "vxlan")) {
9175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9176         } else if (!strcmp(res->tunnel_type, "geneve")) {
9177                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9178         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9179                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9180         } else {
9181                 printf("Invalid tunnel type\n");
9182                 return;
9183         }
9184
9185         if (!strcmp(res->action, "add"))
9186                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9187                                                       &tunnel_udp);
9188         else
9189                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9190                                                          &tunnel_udp);
9191
9192         if (ret < 0)
9193                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9194 }
9195
9196 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9197         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9198                                  "port");
9199 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9200         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9201                                  "config");
9202 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9203         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9204                               RTE_UINT16);
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9206         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9207                                  udp_tunnel_port,
9208                                  "udp_tunnel_port");
9209 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9210         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9211                                  "add#rm");
9212 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9213         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9214                                  "vxlan#geneve#vxlan-gpe");
9215 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9216         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9217                               RTE_UINT16);
9218
9219 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9220         .f = cmd_cfg_tunnel_udp_port_parsed,
9221         .data = NULL,
9222         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9223         .tokens = {
9224                 (void *)&cmd_config_tunnel_udp_port_port,
9225                 (void *)&cmd_config_tunnel_udp_port_config,
9226                 (void *)&cmd_config_tunnel_udp_port_port_id,
9227                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9228                 (void *)&cmd_config_tunnel_udp_port_action,
9229                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9230                 (void *)&cmd_config_tunnel_udp_port_value,
9231                 NULL,
9232         },
9233 };
9234
9235 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9236 struct cmd_set_mirror_mask_result {
9237         cmdline_fixed_string_t set;
9238         cmdline_fixed_string_t port;
9239         portid_t port_id;
9240         cmdline_fixed_string_t mirror;
9241         uint8_t rule_id;
9242         cmdline_fixed_string_t what;
9243         cmdline_fixed_string_t value;
9244         cmdline_fixed_string_t dstpool;
9245         uint8_t dstpool_id;
9246         cmdline_fixed_string_t on;
9247 };
9248
9249 cmdline_parse_token_string_t cmd_mirror_mask_set =
9250         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9251                                 set, "set");
9252 cmdline_parse_token_string_t cmd_mirror_mask_port =
9253         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9254                                 port, "port");
9255 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9256         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9257                                 port_id, RTE_UINT16);
9258 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9259         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9260                                 mirror, "mirror-rule");
9261 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9262         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9263                                 rule_id, RTE_UINT8);
9264 cmdline_parse_token_string_t cmd_mirror_mask_what =
9265         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9266                                 what, "pool-mirror-up#pool-mirror-down"
9267                                       "#vlan-mirror");
9268 cmdline_parse_token_string_t cmd_mirror_mask_value =
9269         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9270                                 value, NULL);
9271 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9272         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9273                                 dstpool, "dst-pool");
9274 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9275         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9276                                 dstpool_id, RTE_UINT8);
9277 cmdline_parse_token_string_t cmd_mirror_mask_on =
9278         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9279                                 on, "on#off");
9280
9281 static void
9282 cmd_set_mirror_mask_parsed(void *parsed_result,
9283                        __rte_unused struct cmdline *cl,
9284                        __rte_unused void *data)
9285 {
9286         int ret,nb_item,i;
9287         struct cmd_set_mirror_mask_result *res = parsed_result;
9288         struct rte_eth_mirror_conf mr_conf;
9289
9290         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9291
9292         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9293
9294         mr_conf.dst_pool = res->dstpool_id;
9295
9296         if (!strcmp(res->what, "pool-mirror-up")) {
9297                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9298                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9299         } else if (!strcmp(res->what, "pool-mirror-down")) {
9300                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9301                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9302         } else if (!strcmp(res->what, "vlan-mirror")) {
9303                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9304                 nb_item = parse_item_list(res->value, "vlan",
9305                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9306                 if (nb_item <= 0)
9307                         return;
9308
9309                 for (i = 0; i < nb_item; i++) {
9310                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9311                                 printf("Invalid vlan_id: must be < 4096\n");
9312                                 return;
9313                         }
9314
9315                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9316                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9317                 }
9318         }
9319
9320         if (!strcmp(res->on, "on"))
9321                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9322                                                 res->rule_id, 1);
9323         else
9324                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9325                                                 res->rule_id, 0);
9326         if (ret < 0)
9327                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9328 }
9329
9330 cmdline_parse_inst_t cmd_set_mirror_mask = {
9331                 .f = cmd_set_mirror_mask_parsed,
9332                 .data = NULL,
9333                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9334                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9335                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9336                 .tokens = {
9337                         (void *)&cmd_mirror_mask_set,
9338                         (void *)&cmd_mirror_mask_port,
9339                         (void *)&cmd_mirror_mask_portid,
9340                         (void *)&cmd_mirror_mask_mirror,
9341                         (void *)&cmd_mirror_mask_ruleid,
9342                         (void *)&cmd_mirror_mask_what,
9343                         (void *)&cmd_mirror_mask_value,
9344                         (void *)&cmd_mirror_mask_dstpool,
9345                         (void *)&cmd_mirror_mask_poolid,
9346                         (void *)&cmd_mirror_mask_on,
9347                         NULL,
9348                 },
9349 };
9350
9351 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9352 struct cmd_set_mirror_link_result {
9353         cmdline_fixed_string_t set;
9354         cmdline_fixed_string_t port;
9355         portid_t port_id;
9356         cmdline_fixed_string_t mirror;
9357         uint8_t rule_id;
9358         cmdline_fixed_string_t what;
9359         cmdline_fixed_string_t dstpool;
9360         uint8_t dstpool_id;
9361         cmdline_fixed_string_t on;
9362 };
9363
9364 cmdline_parse_token_string_t cmd_mirror_link_set =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9366                                  set, "set");
9367 cmdline_parse_token_string_t cmd_mirror_link_port =
9368         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9369                                 port, "port");
9370 cmdline_parse_token_num_t cmd_mirror_link_portid =
9371         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9372                                 port_id, RTE_UINT16);
9373 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9374         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9375                                 mirror, "mirror-rule");
9376 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9377         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9378                             rule_id, RTE_UINT8);
9379 cmdline_parse_token_string_t cmd_mirror_link_what =
9380         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9381                                 what, "uplink-mirror#downlink-mirror");
9382 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9383         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9384                                 dstpool, "dst-pool");
9385 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9386         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9387                                 dstpool_id, RTE_UINT8);
9388 cmdline_parse_token_string_t cmd_mirror_link_on =
9389         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9390                                 on, "on#off");
9391
9392 static void
9393 cmd_set_mirror_link_parsed(void *parsed_result,
9394                        __rte_unused struct cmdline *cl,
9395                        __rte_unused void *data)
9396 {
9397         int ret;
9398         struct cmd_set_mirror_link_result *res = parsed_result;
9399         struct rte_eth_mirror_conf mr_conf;
9400
9401         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9402         if (!strcmp(res->what, "uplink-mirror"))
9403                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9404         else
9405                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9406
9407         mr_conf.dst_pool = res->dstpool_id;
9408
9409         if (!strcmp(res->on, "on"))
9410                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9411                                                 res->rule_id, 1);
9412         else
9413                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9414                                                 res->rule_id, 0);
9415
9416         /* check the return value and print it if is < 0 */
9417         if (ret < 0)
9418                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9419
9420 }
9421
9422 cmdline_parse_inst_t cmd_set_mirror_link = {
9423                 .f = cmd_set_mirror_link_parsed,
9424                 .data = NULL,
9425                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9426                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9427                 .tokens = {
9428                         (void *)&cmd_mirror_link_set,
9429                         (void *)&cmd_mirror_link_port,
9430                         (void *)&cmd_mirror_link_portid,
9431                         (void *)&cmd_mirror_link_mirror,
9432                         (void *)&cmd_mirror_link_ruleid,
9433                         (void *)&cmd_mirror_link_what,
9434                         (void *)&cmd_mirror_link_dstpool,
9435                         (void *)&cmd_mirror_link_poolid,
9436                         (void *)&cmd_mirror_link_on,
9437                         NULL,
9438                 },
9439 };
9440
9441 /* *** RESET VM MIRROR RULE *** */
9442 struct cmd_rm_mirror_rule_result {
9443         cmdline_fixed_string_t reset;
9444         cmdline_fixed_string_t port;
9445         portid_t port_id;
9446         cmdline_fixed_string_t mirror;
9447         uint8_t rule_id;
9448 };
9449
9450 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9451         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9452                                  reset, "reset");
9453 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9454         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9455                                 port, "port");
9456 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9457         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9458                                 port_id, RTE_UINT16);
9459 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9460         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9461                                 mirror, "mirror-rule");
9462 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9463         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9464                                 rule_id, RTE_UINT8);
9465
9466 static void
9467 cmd_reset_mirror_rule_parsed(void *parsed_result,
9468                        __rte_unused struct cmdline *cl,
9469                        __rte_unused void *data)
9470 {
9471         int ret;
9472         struct cmd_set_mirror_link_result *res = parsed_result;
9473         /* check rule_id */
9474         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9475         if(ret < 0)
9476                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9477 }
9478
9479 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9480                 .f = cmd_reset_mirror_rule_parsed,
9481                 .data = NULL,
9482                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9483                 .tokens = {
9484                         (void *)&cmd_rm_mirror_rule_reset,
9485                         (void *)&cmd_rm_mirror_rule_port,
9486                         (void *)&cmd_rm_mirror_rule_portid,
9487                         (void *)&cmd_rm_mirror_rule_mirror,
9488                         (void *)&cmd_rm_mirror_rule_ruleid,
9489                         NULL,
9490                 },
9491 };
9492
9493 /* ******************************************************************************** */
9494
9495 struct cmd_dump_result {
9496         cmdline_fixed_string_t dump;
9497 };
9498
9499 static void
9500 dump_struct_sizes(void)
9501 {
9502 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9503         DUMP_SIZE(struct rte_mbuf);
9504         DUMP_SIZE(struct rte_mempool);
9505         DUMP_SIZE(struct rte_ring);
9506 #undef DUMP_SIZE
9507 }
9508
9509
9510 /* Dump the socket memory statistics on console */
9511 static void
9512 dump_socket_mem(FILE *f)
9513 {
9514         struct rte_malloc_socket_stats socket_stats;
9515         unsigned int i;
9516         size_t total = 0;
9517         size_t alloc = 0;
9518         size_t free = 0;
9519         unsigned int n_alloc = 0;
9520         unsigned int n_free = 0;
9521         static size_t last_allocs;
9522         static size_t last_total;
9523
9524
9525         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9526                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9527                     !socket_stats.heap_totalsz_bytes)
9528                         continue;
9529                 total += socket_stats.heap_totalsz_bytes;
9530                 alloc += socket_stats.heap_allocsz_bytes;
9531                 free += socket_stats.heap_freesz_bytes;
9532                 n_alloc += socket_stats.alloc_count;
9533                 n_free += socket_stats.free_count;
9534                 fprintf(f,
9535                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9536                         i,
9537                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9538                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9539                         (double)socket_stats.heap_allocsz_bytes * 100 /
9540                         (double)socket_stats.heap_totalsz_bytes,
9541                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9542                         socket_stats.alloc_count,
9543                         socket_stats.free_count);
9544         }
9545         fprintf(f,
9546                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9547                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9548                 (double)alloc * 100 / (double)total,
9549                 (double)free / (1024 * 1024),
9550                 n_alloc, n_free);
9551         if (last_allocs)
9552                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9553                         ((double)total - (double)last_total) / (1024 * 1024),
9554                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9555         last_allocs = alloc;
9556         last_total = total;
9557 }
9558
9559 static void cmd_dump_parsed(void *parsed_result,
9560                             __rte_unused struct cmdline *cl,
9561                             __rte_unused void *data)
9562 {
9563         struct cmd_dump_result *res = parsed_result;
9564
9565         if (!strcmp(res->dump, "dump_physmem"))
9566                 rte_dump_physmem_layout(stdout);
9567         else if (!strcmp(res->dump, "dump_socket_mem"))
9568                 dump_socket_mem(stdout);
9569         else if (!strcmp(res->dump, "dump_memzone"))
9570                 rte_memzone_dump(stdout);
9571         else if (!strcmp(res->dump, "dump_struct_sizes"))
9572                 dump_struct_sizes();
9573         else if (!strcmp(res->dump, "dump_ring"))
9574                 rte_ring_list_dump(stdout);
9575         else if (!strcmp(res->dump, "dump_mempool"))
9576                 rte_mempool_list_dump(stdout);
9577         else if (!strcmp(res->dump, "dump_devargs"))
9578                 rte_devargs_dump(stdout);
9579         else if (!strcmp(res->dump, "dump_log_types"))
9580                 rte_log_dump(stdout);
9581 }
9582
9583 cmdline_parse_token_string_t cmd_dump_dump =
9584         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9585                 "dump_physmem#"
9586                 "dump_memzone#"
9587                 "dump_socket_mem#"
9588                 "dump_struct_sizes#"
9589                 "dump_ring#"
9590                 "dump_mempool#"
9591                 "dump_devargs#"
9592                 "dump_log_types");
9593
9594 cmdline_parse_inst_t cmd_dump = {
9595         .f = cmd_dump_parsed,  /* function to call */
9596         .data = NULL,      /* 2nd arg of func */
9597         .help_str = "Dump status",
9598         .tokens = {        /* token list, NULL terminated */
9599                 (void *)&cmd_dump_dump,
9600                 NULL,
9601         },
9602 };
9603
9604 /* ******************************************************************************** */
9605
9606 struct cmd_dump_one_result {
9607         cmdline_fixed_string_t dump;
9608         cmdline_fixed_string_t name;
9609 };
9610
9611 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9612                                 __rte_unused void *data)
9613 {
9614         struct cmd_dump_one_result *res = parsed_result;
9615
9616         if (!strcmp(res->dump, "dump_ring")) {
9617                 struct rte_ring *r;
9618                 r = rte_ring_lookup(res->name);
9619                 if (r == NULL) {
9620                         cmdline_printf(cl, "Cannot find ring\n");
9621                         return;
9622                 }
9623                 rte_ring_dump(stdout, r);
9624         } else if (!strcmp(res->dump, "dump_mempool")) {
9625                 struct rte_mempool *mp;
9626                 mp = rte_mempool_lookup(res->name);
9627                 if (mp == NULL) {
9628                         cmdline_printf(cl, "Cannot find mempool\n");
9629                         return;
9630                 }
9631                 rte_mempool_dump(stdout, mp);
9632         }
9633 }
9634
9635 cmdline_parse_token_string_t cmd_dump_one_dump =
9636         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9637                                  "dump_ring#dump_mempool");
9638
9639 cmdline_parse_token_string_t cmd_dump_one_name =
9640         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9641
9642 cmdline_parse_inst_t cmd_dump_one = {
9643         .f = cmd_dump_one_parsed,  /* function to call */
9644         .data = NULL,      /* 2nd arg of func */
9645         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9646         .tokens = {        /* token list, NULL terminated */
9647                 (void *)&cmd_dump_one_dump,
9648                 (void *)&cmd_dump_one_name,
9649                 NULL,
9650         },
9651 };
9652
9653 /* *** queue region set *** */
9654 struct cmd_queue_region_result {
9655         cmdline_fixed_string_t set;
9656         cmdline_fixed_string_t port;
9657         portid_t port_id;
9658         cmdline_fixed_string_t cmd;
9659         cmdline_fixed_string_t region;
9660         uint8_t  region_id;
9661         cmdline_fixed_string_t queue_start_index;
9662         uint8_t  queue_id;
9663         cmdline_fixed_string_t queue_num;
9664         uint8_t  queue_num_value;
9665 };
9666
9667 static void
9668 cmd_queue_region_parsed(void *parsed_result,
9669                         __rte_unused struct cmdline *cl,
9670                         __rte_unused void *data)
9671 {
9672         struct cmd_queue_region_result *res = parsed_result;
9673         int ret = -ENOTSUP;
9674 #ifdef RTE_NET_I40E
9675         struct rte_pmd_i40e_queue_region_conf region_conf;
9676         enum rte_pmd_i40e_queue_region_op op_type;
9677 #endif
9678
9679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9680                 return;
9681
9682 #ifdef RTE_NET_I40E
9683         memset(&region_conf, 0, sizeof(region_conf));
9684         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9685         region_conf.region_id = res->region_id;
9686         region_conf.queue_num = res->queue_num_value;
9687         region_conf.queue_start_index = res->queue_id;
9688
9689         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9690                                 op_type, &region_conf);
9691 #endif
9692
9693         switch (ret) {
9694         case 0:
9695                 break;
9696         case -ENOTSUP:
9697                 printf("function not implemented or supported\n");
9698                 break;
9699         default:
9700                 printf("queue region config error: (%s)\n", strerror(-ret));
9701         }
9702 }
9703
9704 cmdline_parse_token_string_t cmd_queue_region_set =
9705 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9706                 set, "set");
9707 cmdline_parse_token_string_t cmd_queue_region_port =
9708         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9709 cmdline_parse_token_num_t cmd_queue_region_port_id =
9710         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9711                                 port_id, RTE_UINT16);
9712 cmdline_parse_token_string_t cmd_queue_region_cmd =
9713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9714                                  cmd, "queue-region");
9715 cmdline_parse_token_string_t cmd_queue_region_id =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                                 region, "region_id");
9718 cmdline_parse_token_num_t cmd_queue_region_index =
9719         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9720                                 region_id, RTE_UINT8);
9721 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9723                                 queue_start_index, "queue_start_index");
9724 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9725         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9726                                 queue_id, RTE_UINT8);
9727 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_num, "queue_num");
9730 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_num_value, RTE_UINT8);
9733
9734 cmdline_parse_inst_t cmd_queue_region = {
9735         .f = cmd_queue_region_parsed,
9736         .data = NULL,
9737         .help_str = "set port <port_id> queue-region region_id <value> "
9738                 "queue_start_index <value> queue_num <value>: Set a queue region",
9739         .tokens = {
9740                 (void *)&cmd_queue_region_set,
9741                 (void *)&cmd_queue_region_port,
9742                 (void *)&cmd_queue_region_port_id,
9743                 (void *)&cmd_queue_region_cmd,
9744                 (void *)&cmd_queue_region_id,
9745                 (void *)&cmd_queue_region_index,
9746                 (void *)&cmd_queue_region_queue_start_index,
9747                 (void *)&cmd_queue_region_queue_id,
9748                 (void *)&cmd_queue_region_queue_num,
9749                 (void *)&cmd_queue_region_queue_num_value,
9750                 NULL,
9751         },
9752 };
9753
9754 /* *** queue region and flowtype set *** */
9755 struct cmd_region_flowtype_result {
9756         cmdline_fixed_string_t set;
9757         cmdline_fixed_string_t port;
9758         portid_t port_id;
9759         cmdline_fixed_string_t cmd;
9760         cmdline_fixed_string_t region;
9761         uint8_t  region_id;
9762         cmdline_fixed_string_t flowtype;
9763         uint8_t  flowtype_id;
9764 };
9765
9766 static void
9767 cmd_region_flowtype_parsed(void *parsed_result,
9768                         __rte_unused struct cmdline *cl,
9769                         __rte_unused void *data)
9770 {
9771         struct cmd_region_flowtype_result *res = parsed_result;
9772         int ret = -ENOTSUP;
9773 #ifdef RTE_NET_I40E
9774         struct rte_pmd_i40e_queue_region_conf region_conf;
9775         enum rte_pmd_i40e_queue_region_op op_type;
9776 #endif
9777
9778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9779                 return;
9780
9781 #ifdef RTE_NET_I40E
9782         memset(&region_conf, 0, sizeof(region_conf));
9783
9784         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9785         region_conf.region_id = res->region_id;
9786         region_conf.hw_flowtype = res->flowtype_id;
9787
9788         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9789                         op_type, &region_conf);
9790 #endif
9791
9792         switch (ret) {
9793         case 0:
9794                 break;
9795         case -ENOTSUP:
9796                 printf("function not implemented or supported\n");
9797                 break;
9798         default:
9799                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9800         }
9801 }
9802
9803 cmdline_parse_token_string_t cmd_region_flowtype_set =
9804 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9805                                 set, "set");
9806 cmdline_parse_token_string_t cmd_region_flowtype_port =
9807         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9808                                 port, "port");
9809 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9810         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 port_id, RTE_UINT16);
9812 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 cmd, "queue-region");
9815 cmdline_parse_token_string_t cmd_region_flowtype_index =
9816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 region, "region_id");
9818 cmdline_parse_token_num_t cmd_region_flowtype_id =
9819         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 region_id, RTE_UINT8);
9821 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9822         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 flowtype, "flowtype");
9824 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9825         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 flowtype_id, RTE_UINT8);
9827 cmdline_parse_inst_t cmd_region_flowtype = {
9828         .f = cmd_region_flowtype_parsed,
9829         .data = NULL,
9830         .help_str = "set port <port_id> queue-region region_id <value> "
9831                 "flowtype <value>: Set a flowtype region index",
9832         .tokens = {
9833                 (void *)&cmd_region_flowtype_set,
9834                 (void *)&cmd_region_flowtype_port,
9835                 (void *)&cmd_region_flowtype_port_index,
9836                 (void *)&cmd_region_flowtype_cmd,
9837                 (void *)&cmd_region_flowtype_index,
9838                 (void *)&cmd_region_flowtype_id,
9839                 (void *)&cmd_region_flowtype_flow_index,
9840                 (void *)&cmd_region_flowtype_flow_id,
9841                 NULL,
9842         },
9843 };
9844
9845 /* *** User Priority (UP) to queue region (region_id) set *** */
9846 struct cmd_user_priority_region_result {
9847         cmdline_fixed_string_t set;
9848         cmdline_fixed_string_t port;
9849         portid_t port_id;
9850         cmdline_fixed_string_t cmd;
9851         cmdline_fixed_string_t user_priority;
9852         uint8_t  user_priority_id;
9853         cmdline_fixed_string_t region;
9854         uint8_t  region_id;
9855 };
9856
9857 static void
9858 cmd_user_priority_region_parsed(void *parsed_result,
9859                         __rte_unused struct cmdline *cl,
9860                         __rte_unused void *data)
9861 {
9862         struct cmd_user_priority_region_result *res = parsed_result;
9863         int ret = -ENOTSUP;
9864 #ifdef RTE_NET_I40E
9865         struct rte_pmd_i40e_queue_region_conf region_conf;
9866         enum rte_pmd_i40e_queue_region_op op_type;
9867 #endif
9868
9869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9870                 return;
9871
9872 #ifdef RTE_NET_I40E
9873         memset(&region_conf, 0, sizeof(region_conf));
9874         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9875         region_conf.user_priority = res->user_priority_id;
9876         region_conf.region_id = res->region_id;
9877
9878         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9879                                 op_type, &region_conf);
9880 #endif
9881
9882         switch (ret) {
9883         case 0:
9884                 break;
9885         case -ENOTSUP:
9886                 printf("function not implemented or supported\n");
9887                 break;
9888         default:
9889                 printf("user_priority region config error: (%s)\n",
9890                                 strerror(-ret));
9891         }
9892 }
9893
9894 cmdline_parse_token_string_t cmd_user_priority_region_set =
9895         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9896                                 set, "set");
9897 cmdline_parse_token_string_t cmd_user_priority_region_port =
9898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9899                                 port, "port");
9900 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9901         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 port_id, RTE_UINT16);
9903 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 cmd, "queue-region");
9906 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 user_priority, "UP");
9909 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9910         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 user_priority_id, RTE_UINT8);
9912 cmdline_parse_token_string_t cmd_user_priority_region_region =
9913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 region, "region_id");
9915 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9916         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 region_id, RTE_UINT8);
9918
9919 cmdline_parse_inst_t cmd_user_priority_region = {
9920         .f = cmd_user_priority_region_parsed,
9921         .data = NULL,
9922         .help_str = "set port <port_id> queue-region UP <value> "
9923                 "region_id <value>: Set the mapping of User Priority (UP) "
9924                 "to queue region (region_id) ",
9925         .tokens = {
9926                 (void *)&cmd_user_priority_region_set,
9927                 (void *)&cmd_user_priority_region_port,
9928                 (void *)&cmd_user_priority_region_port_index,
9929                 (void *)&cmd_user_priority_region_cmd,
9930                 (void *)&cmd_user_priority_region_UP,
9931                 (void *)&cmd_user_priority_region_UP_id,
9932                 (void *)&cmd_user_priority_region_region,
9933                 (void *)&cmd_user_priority_region_region_id,
9934                 NULL,
9935         },
9936 };
9937
9938 /* *** flush all queue region related configuration *** */
9939 struct cmd_flush_queue_region_result {
9940         cmdline_fixed_string_t set;
9941         cmdline_fixed_string_t port;
9942         portid_t port_id;
9943         cmdline_fixed_string_t cmd;
9944         cmdline_fixed_string_t flush;
9945         cmdline_fixed_string_t what;
9946 };
9947
9948 static void
9949 cmd_flush_queue_region_parsed(void *parsed_result,
9950                         __rte_unused struct cmdline *cl,
9951                         __rte_unused void *data)
9952 {
9953         struct cmd_flush_queue_region_result *res = parsed_result;
9954         int ret = -ENOTSUP;
9955 #ifdef RTE_NET_I40E
9956         struct rte_pmd_i40e_queue_region_conf region_conf;
9957         enum rte_pmd_i40e_queue_region_op op_type;
9958 #endif
9959
9960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9961                 return;
9962
9963 #ifdef RTE_NET_I40E
9964         memset(&region_conf, 0, sizeof(region_conf));
9965
9966         if (strcmp(res->what, "on") == 0)
9967                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9968         else
9969                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9970
9971         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9972                                 op_type, &region_conf);
9973 #endif
9974
9975         switch (ret) {
9976         case 0:
9977                 break;
9978         case -ENOTSUP:
9979                 printf("function not implemented or supported\n");
9980                 break;
9981         default:
9982                 printf("queue region config flush error: (%s)\n",
9983                                 strerror(-ret));
9984         }
9985 }
9986
9987 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9988         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9989                                 set, "set");
9990 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9992                                 port, "port");
9993 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9994         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 port_id, RTE_UINT16);
9996 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9997         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 cmd, "queue-region");
9999 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 flush, "flush");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 what, "on#off");
10005
10006 cmdline_parse_inst_t cmd_flush_queue_region = {
10007         .f = cmd_flush_queue_region_parsed,
10008         .data = NULL,
10009         .help_str = "set port <port_id> queue-region flush on|off"
10010                 ": flush all queue region related configuration",
10011         .tokens = {
10012                 (void *)&cmd_flush_queue_region_set,
10013                 (void *)&cmd_flush_queue_region_port,
10014                 (void *)&cmd_flush_queue_region_port_index,
10015                 (void *)&cmd_flush_queue_region_cmd,
10016                 (void *)&cmd_flush_queue_region_flush,
10017                 (void *)&cmd_flush_queue_region_what,
10018                 NULL,
10019         },
10020 };
10021
10022 /* *** get all queue region related configuration info *** */
10023 struct cmd_show_queue_region_info {
10024         cmdline_fixed_string_t show;
10025         cmdline_fixed_string_t port;
10026         portid_t port_id;
10027         cmdline_fixed_string_t cmd;
10028 };
10029
10030 static void
10031 cmd_show_queue_region_info_parsed(void *parsed_result,
10032                         __rte_unused struct cmdline *cl,
10033                         __rte_unused void *data)
10034 {
10035         struct cmd_show_queue_region_info *res = parsed_result;
10036         int ret = -ENOTSUP;
10037 #ifdef RTE_NET_I40E
10038         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10039         enum rte_pmd_i40e_queue_region_op op_type;
10040 #endif
10041
10042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10043                 return;
10044
10045 #ifdef RTE_NET_I40E
10046         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10047
10048         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10049
10050         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10051                                         op_type, &rte_pmd_regions);
10052
10053         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10054 #endif
10055
10056         switch (ret) {
10057         case 0:
10058                 break;
10059         case -ENOTSUP:
10060                 printf("function not implemented or supported\n");
10061                 break;
10062         default:
10063                 printf("queue region config info show error: (%s)\n",
10064                                 strerror(-ret));
10065         }
10066 }
10067
10068 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10069 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10070                                 show, "show");
10071 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10072         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10073                                 port, "port");
10074 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10075         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 port_id, RTE_UINT16);
10077 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10078         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 cmd, "queue-region");
10080
10081 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10082         .f = cmd_show_queue_region_info_parsed,
10083         .data = NULL,
10084         .help_str = "show port <port_id> queue-region"
10085                 ": show all queue region related configuration info",
10086         .tokens = {
10087                 (void *)&cmd_show_queue_region_info_get,
10088                 (void *)&cmd_show_queue_region_info_port,
10089                 (void *)&cmd_show_queue_region_info_port_index,
10090                 (void *)&cmd_show_queue_region_info_cmd,
10091                 NULL,
10092         },
10093 };
10094
10095 /* *** Filters Control *** */
10096
10097 static uint16_t
10098 str2flowtype(char *string)
10099 {
10100         uint8_t i = 0;
10101         static const struct {
10102                 char str[32];
10103                 uint16_t type;
10104         } flowtype_str[] = {
10105                 {"raw", RTE_ETH_FLOW_RAW},
10106                 {"ipv4", RTE_ETH_FLOW_IPV4},
10107                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10108                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10109                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10110                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10111                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10112                 {"ipv6", RTE_ETH_FLOW_IPV6},
10113                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10114                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10115                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10116                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10117                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10118                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10119         };
10120
10121         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10122                 if (!strcmp(flowtype_str[i].str, string))
10123                         return flowtype_str[i].type;
10124         }
10125
10126         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10127                 return (uint16_t)atoi(string);
10128
10129         return RTE_ETH_FLOW_UNKNOWN;
10130 }
10131
10132 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10133 do { \
10134         if ((ip_addr).family == AF_INET) \
10135                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10136         else { \
10137                 printf("invalid parameter.\n"); \
10138                 return; \
10139         } \
10140 } while (0)
10141
10142 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10143 do { \
10144         if ((ip_addr).family == AF_INET6) \
10145                 rte_memcpy(&(ip), \
10146                                  &((ip_addr).addr.ipv6), \
10147                                  sizeof(struct in6_addr)); \
10148         else { \
10149                 printf("invalid parameter.\n"); \
10150                 return; \
10151         } \
10152 } while (0)
10153
10154 #ifdef RTE_NET_I40E
10155
10156 /* *** deal with flow director filter *** */
10157 struct cmd_flow_director_result {
10158         cmdline_fixed_string_t flow_director_filter;
10159         portid_t port_id;
10160         cmdline_fixed_string_t mode;
10161         cmdline_fixed_string_t mode_value;
10162         cmdline_fixed_string_t ops;
10163         cmdline_fixed_string_t flow;
10164         cmdline_fixed_string_t flow_type;
10165         cmdline_fixed_string_t drop;
10166         cmdline_fixed_string_t queue;
10167         uint16_t  queue_id;
10168         cmdline_fixed_string_t fd_id;
10169         uint32_t  fd_id_value;
10170         cmdline_fixed_string_t packet;
10171         char filepath[];
10172 };
10173
10174 static void
10175 cmd_flow_director_filter_parsed(void *parsed_result,
10176                           __rte_unused struct cmdline *cl,
10177                           __rte_unused void *data)
10178 {
10179         struct cmd_flow_director_result *res = parsed_result;
10180         int ret = 0;
10181         struct rte_pmd_i40e_flow_type_mapping
10182                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10183         struct rte_pmd_i40e_pkt_template_conf conf;
10184         uint16_t flow_type = str2flowtype(res->flow_type);
10185         uint16_t i, port = res->port_id;
10186         uint8_t add;
10187
10188         memset(&conf, 0, sizeof(conf));
10189
10190         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10191                 printf("Invalid flow type specified.\n");
10192                 return;
10193         }
10194         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10195                                                  mapping);
10196         if (ret)
10197                 return;
10198         if (mapping[flow_type].pctype == 0ULL) {
10199                 printf("Invalid flow type specified.\n");
10200                 return;
10201         }
10202         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10203                 if (mapping[flow_type].pctype & (1ULL << i)) {
10204                         conf.input.pctype = i;
10205                         break;
10206                 }
10207         }
10208
10209         conf.input.packet = open_file(res->filepath,
10210                                 &conf.input.length);
10211         if (!conf.input.packet)
10212                 return;
10213         if (!strcmp(res->drop, "drop"))
10214                 conf.action.behavior =
10215                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10216         else
10217                 conf.action.behavior =
10218                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10219         conf.action.report_status =
10220                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10221         conf.action.rx_queue = res->queue_id;
10222         conf.soft_id = res->fd_id_value;
10223         add  = strcmp(res->ops, "del") ? 1 : 0;
10224         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10225                                                         &conf,
10226                                                         add);
10227         if (ret < 0)
10228                 printf("flow director config error: (%s)\n",
10229                        strerror(-ret));
10230         close_file(conf.input.packet);
10231 }
10232
10233 cmdline_parse_token_string_t cmd_flow_director_filter =
10234         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10235                                  flow_director_filter, "flow_director_filter");
10236 cmdline_parse_token_num_t cmd_flow_director_port_id =
10237         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10238                               port_id, RTE_UINT16);
10239 cmdline_parse_token_string_t cmd_flow_director_ops =
10240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10241                                  ops, "add#del#update");
10242 cmdline_parse_token_string_t cmd_flow_director_flow =
10243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10244                                  flow, "flow");
10245 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10247                 flow_type, NULL);
10248 cmdline_parse_token_string_t cmd_flow_director_drop =
10249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10250                                  drop, "drop#fwd");
10251 cmdline_parse_token_string_t cmd_flow_director_queue =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  queue, "queue");
10254 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10256                               queue_id, RTE_UINT16);
10257 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10259                                  fd_id, "fd_id");
10260 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10261         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10262                               fd_id_value, RTE_UINT32);
10263
10264 cmdline_parse_token_string_t cmd_flow_director_mode =
10265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10266                                  mode, "mode");
10267 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10269                                  mode_value, "raw");
10270 cmdline_parse_token_string_t cmd_flow_director_packet =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10272                                  packet, "packet");
10273 cmdline_parse_token_string_t cmd_flow_director_filepath =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10275                                  filepath, NULL);
10276
10277 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10278         .f = cmd_flow_director_filter_parsed,
10279         .data = NULL,
10280         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10281                 "director entry on NIC",
10282         .tokens = {
10283                 (void *)&cmd_flow_director_filter,
10284                 (void *)&cmd_flow_director_port_id,
10285                 (void *)&cmd_flow_director_mode,
10286                 (void *)&cmd_flow_director_mode_raw,
10287                 (void *)&cmd_flow_director_ops,
10288                 (void *)&cmd_flow_director_flow,
10289                 (void *)&cmd_flow_director_flow_type,
10290                 (void *)&cmd_flow_director_drop,
10291                 (void *)&cmd_flow_director_queue,
10292                 (void *)&cmd_flow_director_queue_id,
10293                 (void *)&cmd_flow_director_fd_id,
10294                 (void *)&cmd_flow_director_fd_id_value,
10295                 (void *)&cmd_flow_director_packet,
10296                 (void *)&cmd_flow_director_filepath,
10297                 NULL,
10298         },
10299 };
10300
10301 #endif /* RTE_NET_I40E */
10302
10303 /* *** deal with flow director mask *** */
10304 struct cmd_flow_director_mask_result {
10305         cmdline_fixed_string_t flow_director_mask;
10306         portid_t port_id;
10307         cmdline_fixed_string_t mode;
10308         cmdline_fixed_string_t mode_value;
10309         cmdline_fixed_string_t vlan;
10310         uint16_t vlan_mask;
10311         cmdline_fixed_string_t src_mask;
10312         cmdline_ipaddr_t ipv4_src;
10313         cmdline_ipaddr_t ipv6_src;
10314         uint16_t port_src;
10315         cmdline_fixed_string_t dst_mask;
10316         cmdline_ipaddr_t ipv4_dst;
10317         cmdline_ipaddr_t ipv6_dst;
10318         uint16_t port_dst;
10319         cmdline_fixed_string_t mac;
10320         uint8_t mac_addr_byte_mask;
10321         cmdline_fixed_string_t tunnel_id;
10322         uint32_t tunnel_id_mask;
10323         cmdline_fixed_string_t tunnel_type;
10324         uint8_t tunnel_type_mask;
10325 };
10326
10327 static void
10328 cmd_flow_director_mask_parsed(void *parsed_result,
10329                           __rte_unused struct cmdline *cl,
10330                           __rte_unused void *data)
10331 {
10332         struct cmd_flow_director_mask_result *res = parsed_result;
10333         struct rte_eth_fdir_masks *mask;
10334         struct rte_port *port;
10335
10336         port = &ports[res->port_id];
10337         /** Check if the port is not started **/
10338         if (port->port_status != RTE_PORT_STOPPED) {
10339                 printf("Please stop port %d first\n", res->port_id);
10340                 return;
10341         }
10342
10343         mask = &port->dev_conf.fdir_conf.mask;
10344
10345         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10346                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10347                         printf("Please set mode to MAC-VLAN.\n");
10348                         return;
10349                 }
10350
10351                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10352         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10353                 if (strcmp(res->mode_value, "Tunnel")) {
10354                         printf("Please set mode to Tunnel.\n");
10355                         return;
10356                 }
10357
10358                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10359                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10360                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10361                 mask->tunnel_type_mask = res->tunnel_type_mask;
10362         } else {
10363                 if (strcmp(res->mode_value, "IP")) {
10364                         printf("Please set mode to IP.\n");
10365                         return;
10366                 }
10367
10368                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10369                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10370                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10371                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10372                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10373                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10374                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10375         }
10376
10377         cmd_reconfig_device_queue(res->port_id, 1, 1);
10378 }
10379
10380 cmdline_parse_token_string_t cmd_flow_director_mask =
10381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10382                                  flow_director_mask, "flow_director_mask");
10383 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10384         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10385                               port_id, RTE_UINT16);
10386 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10387         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10388                                  vlan, "vlan");
10389 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10390         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10391                               vlan_mask, RTE_UINT16);
10392 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10394                                  src_mask, "src_mask");
10395 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10396         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10397                                  ipv4_src);
10398 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10399         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  ipv6_src);
10401 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10403                               port_src, RTE_UINT16);
10404 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10406                                  dst_mask, "dst_mask");
10407 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10408         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10409                                  ipv4_dst);
10410 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10411         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10412                                  ipv6_dst);
10413 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10414         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10415                               port_dst, RTE_UINT16);
10416
10417 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10418         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10419                                  mode, "mode");
10420 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  mode_value, "IP");
10423 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  mode_value, "MAC-VLAN");
10426 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10428                                  mode_value, "Tunnel");
10429 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10431                                  mac, "mac");
10432 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10434                               mac_addr_byte_mask, RTE_UINT8);
10435 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10437                                  tunnel_type, "tunnel-type");
10438 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10439         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10440                               tunnel_type_mask, RTE_UINT8);
10441 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10443                                  tunnel_id, "tunnel-id");
10444 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10446                               tunnel_id_mask, RTE_UINT32);
10447
10448 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10449         .f = cmd_flow_director_mask_parsed,
10450         .data = NULL,
10451         .help_str = "flow_director_mask ... : "
10452                 "Set IP mode flow director's mask on NIC",
10453         .tokens = {
10454                 (void *)&cmd_flow_director_mask,
10455                 (void *)&cmd_flow_director_mask_port_id,
10456                 (void *)&cmd_flow_director_mask_mode,
10457                 (void *)&cmd_flow_director_mask_mode_ip,
10458                 (void *)&cmd_flow_director_mask_vlan,
10459                 (void *)&cmd_flow_director_mask_vlan_value,
10460                 (void *)&cmd_flow_director_mask_src,
10461                 (void *)&cmd_flow_director_mask_ipv4_src,
10462                 (void *)&cmd_flow_director_mask_ipv6_src,
10463                 (void *)&cmd_flow_director_mask_port_src,
10464                 (void *)&cmd_flow_director_mask_dst,
10465                 (void *)&cmd_flow_director_mask_ipv4_dst,
10466                 (void *)&cmd_flow_director_mask_ipv6_dst,
10467                 (void *)&cmd_flow_director_mask_port_dst,
10468                 NULL,
10469         },
10470 };
10471
10472 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10473         .f = cmd_flow_director_mask_parsed,
10474         .data = NULL,
10475         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10476                 "flow director's mask on NIC",
10477         .tokens = {
10478                 (void *)&cmd_flow_director_mask,
10479                 (void *)&cmd_flow_director_mask_port_id,
10480                 (void *)&cmd_flow_director_mask_mode,
10481                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10482                 (void *)&cmd_flow_director_mask_vlan,
10483                 (void *)&cmd_flow_director_mask_vlan_value,
10484                 NULL,
10485         },
10486 };
10487
10488 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10489         .f = cmd_flow_director_mask_parsed,
10490         .data = NULL,
10491         .help_str = "flow_director_mask ... : Set tunnel mode "
10492                 "flow director's mask on NIC",
10493         .tokens = {
10494                 (void *)&cmd_flow_director_mask,
10495                 (void *)&cmd_flow_director_mask_port_id,
10496                 (void *)&cmd_flow_director_mask_mode,
10497                 (void *)&cmd_flow_director_mask_mode_tunnel,
10498                 (void *)&cmd_flow_director_mask_vlan,
10499                 (void *)&cmd_flow_director_mask_vlan_value,
10500                 (void *)&cmd_flow_director_mask_mac,
10501                 (void *)&cmd_flow_director_mask_mac_value,
10502                 (void *)&cmd_flow_director_mask_tunnel_type,
10503                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10504                 (void *)&cmd_flow_director_mask_tunnel_id,
10505                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10506                 NULL,
10507         },
10508 };
10509
10510 /* *** deal with flow director flexible payload configuration *** */
10511 struct cmd_flow_director_flexpayload_result {
10512         cmdline_fixed_string_t flow_director_flexpayload;
10513         portid_t port_id;
10514         cmdline_fixed_string_t payload_layer;
10515         cmdline_fixed_string_t payload_cfg;
10516 };
10517
10518 static inline int
10519 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10520 {
10521         char s[256];
10522         const char *p, *p0 = q_arg;
10523         char *end;
10524         unsigned long int_fld;
10525         char *str_fld[max_num];
10526         int i;
10527         unsigned size;
10528         int ret = -1;
10529
10530         p = strchr(p0, '(');
10531         if (p == NULL)
10532                 return -1;
10533         ++p;
10534         p0 = strchr(p, ')');
10535         if (p0 == NULL)
10536                 return -1;
10537
10538         size = p0 - p;
10539         if (size >= sizeof(s))
10540                 return -1;
10541
10542         snprintf(s, sizeof(s), "%.*s", size, p);
10543         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10544         if (ret < 0 || ret > max_num)
10545                 return -1;
10546         for (i = 0; i < ret; i++) {
10547                 errno = 0;
10548                 int_fld = strtoul(str_fld[i], &end, 0);
10549                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10550                         return -1;
10551                 offsets[i] = (uint16_t)int_fld;
10552         }
10553         return ret;
10554 }
10555
10556 static void
10557 cmd_flow_director_flxpld_parsed(void *parsed_result,
10558                           __rte_unused struct cmdline *cl,
10559                           __rte_unused void *data)
10560 {
10561         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10562         struct rte_eth_flex_payload_cfg flex_cfg;
10563         struct rte_port *port;
10564         int ret = 0;
10565
10566         port = &ports[res->port_id];
10567         /** Check if the port is not started **/
10568         if (port->port_status != RTE_PORT_STOPPED) {
10569                 printf("Please stop port %d first\n", res->port_id);
10570                 return;
10571         }
10572
10573         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10574
10575         if (!strcmp(res->payload_layer, "raw"))
10576                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10577         else if (!strcmp(res->payload_layer, "l2"))
10578                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10579         else if (!strcmp(res->payload_layer, "l3"))
10580                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10581         else if (!strcmp(res->payload_layer, "l4"))
10582                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10583
10584         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10585                             RTE_ETH_FDIR_MAX_FLEXLEN);
10586         if (ret < 0) {
10587                 printf("error: Cannot parse flex payload input.\n");
10588                 return;
10589         }
10590
10591         fdir_set_flex_payload(res->port_id, &flex_cfg);
10592         cmd_reconfig_device_queue(res->port_id, 1, 1);
10593 }
10594
10595 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10597                                  flow_director_flexpayload,
10598                                  "flow_director_flex_payload");
10599 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10600         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10601                               port_id, RTE_UINT16);
10602 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10604                                  payload_layer, "raw#l2#l3#l4");
10605 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10607                                  payload_cfg, NULL);
10608
10609 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10610         .f = cmd_flow_director_flxpld_parsed,
10611         .data = NULL,
10612         .help_str = "flow_director_flexpayload ... : "
10613                 "Set flow director's flex payload on NIC",
10614         .tokens = {
10615                 (void *)&cmd_flow_director_flexpayload,
10616                 (void *)&cmd_flow_director_flexpayload_port_id,
10617                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10618                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10619                 NULL,
10620         },
10621 };
10622
10623 /* Generic flow interface command. */
10624 extern cmdline_parse_inst_t cmd_flow;
10625
10626 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10627 struct cmd_mcast_addr_result {
10628         cmdline_fixed_string_t mcast_addr_cmd;
10629         cmdline_fixed_string_t what;
10630         uint16_t port_num;
10631         struct rte_ether_addr mc_addr;
10632 };
10633
10634 static void cmd_mcast_addr_parsed(void *parsed_result,
10635                 __rte_unused struct cmdline *cl,
10636                 __rte_unused void *data)
10637 {
10638         struct cmd_mcast_addr_result *res = parsed_result;
10639
10640         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10641                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10642                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10643                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10644                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10645                 return;
10646         }
10647         if (strcmp(res->what, "add") == 0)
10648                 mcast_addr_add(res->port_num, &res->mc_addr);
10649         else
10650                 mcast_addr_remove(res->port_num, &res->mc_addr);
10651 }
10652
10653 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10654         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10655                                  mcast_addr_cmd, "mcast_addr");
10656 cmdline_parse_token_string_t cmd_mcast_addr_what =
10657         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10658                                  "add#remove");
10659 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10660         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10661                                  RTE_UINT16);
10662 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10664
10665 cmdline_parse_inst_t cmd_mcast_addr = {
10666         .f = cmd_mcast_addr_parsed,
10667         .data = (void *)0,
10668         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10669                 "Add/Remove multicast MAC address on port_id",
10670         .tokens = {
10671                 (void *)&cmd_mcast_addr_cmd,
10672                 (void *)&cmd_mcast_addr_what,
10673                 (void *)&cmd_mcast_addr_portnum,
10674                 (void *)&cmd_mcast_addr_addr,
10675                 NULL,
10676         },
10677 };
10678
10679 /* vf vlan anti spoof configuration */
10680
10681 /* Common result structure for vf vlan anti spoof */
10682 struct cmd_vf_vlan_anti_spoof_result {
10683         cmdline_fixed_string_t set;
10684         cmdline_fixed_string_t vf;
10685         cmdline_fixed_string_t vlan;
10686         cmdline_fixed_string_t antispoof;
10687         portid_t port_id;
10688         uint32_t vf_id;
10689         cmdline_fixed_string_t on_off;
10690 };
10691
10692 /* Common CLI fields for vf vlan anti spoof enable disable */
10693 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10694         TOKEN_STRING_INITIALIZER
10695                 (struct cmd_vf_vlan_anti_spoof_result,
10696                  set, "set");
10697 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10698         TOKEN_STRING_INITIALIZER
10699                 (struct cmd_vf_vlan_anti_spoof_result,
10700                  vf, "vf");
10701 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10702         TOKEN_STRING_INITIALIZER
10703                 (struct cmd_vf_vlan_anti_spoof_result,
10704                  vlan, "vlan");
10705 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10706         TOKEN_STRING_INITIALIZER
10707                 (struct cmd_vf_vlan_anti_spoof_result,
10708                  antispoof, "antispoof");
10709 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10710         TOKEN_NUM_INITIALIZER
10711                 (struct cmd_vf_vlan_anti_spoof_result,
10712                  port_id, RTE_UINT16);
10713 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10714         TOKEN_NUM_INITIALIZER
10715                 (struct cmd_vf_vlan_anti_spoof_result,
10716                  vf_id, RTE_UINT32);
10717 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10718         TOKEN_STRING_INITIALIZER
10719                 (struct cmd_vf_vlan_anti_spoof_result,
10720                  on_off, "on#off");
10721
10722 static void
10723 cmd_set_vf_vlan_anti_spoof_parsed(
10724         void *parsed_result,
10725         __rte_unused struct cmdline *cl,
10726         __rte_unused void *data)
10727 {
10728         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10729         int ret = -ENOTSUP;
10730
10731         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10732
10733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10734                 return;
10735
10736 #ifdef RTE_NET_IXGBE
10737         if (ret == -ENOTSUP)
10738                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10739                                 res->vf_id, is_on);
10740 #endif
10741 #ifdef RTE_NET_I40E
10742         if (ret == -ENOTSUP)
10743                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10744                                 res->vf_id, is_on);
10745 #endif
10746 #ifdef RTE_NET_BNXT
10747         if (ret == -ENOTSUP)
10748                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10749                                 res->vf_id, is_on);
10750 #endif
10751
10752         switch (ret) {
10753         case 0:
10754                 break;
10755         case -EINVAL:
10756                 printf("invalid vf_id %d\n", res->vf_id);
10757                 break;
10758         case -ENODEV:
10759                 printf("invalid port_id %d\n", res->port_id);
10760                 break;
10761         case -ENOTSUP:
10762                 printf("function not implemented\n");
10763                 break;
10764         default:
10765                 printf("programming error: (%s)\n", strerror(-ret));
10766         }
10767 }
10768
10769 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10770         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10771         .data = NULL,
10772         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10773         .tokens = {
10774                 (void *)&cmd_vf_vlan_anti_spoof_set,
10775                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10776                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10777                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10778                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10779                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10780                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10781                 NULL,
10782         },
10783 };
10784
10785 /* vf mac anti spoof configuration */
10786
10787 /* Common result structure for vf mac anti spoof */
10788 struct cmd_vf_mac_anti_spoof_result {
10789         cmdline_fixed_string_t set;
10790         cmdline_fixed_string_t vf;
10791         cmdline_fixed_string_t mac;
10792         cmdline_fixed_string_t antispoof;
10793         portid_t port_id;
10794         uint32_t vf_id;
10795         cmdline_fixed_string_t on_off;
10796 };
10797
10798 /* Common CLI fields for vf mac anti spoof enable disable */
10799 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10800         TOKEN_STRING_INITIALIZER
10801                 (struct cmd_vf_mac_anti_spoof_result,
10802                  set, "set");
10803 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10804         TOKEN_STRING_INITIALIZER
10805                 (struct cmd_vf_mac_anti_spoof_result,
10806                  vf, "vf");
10807 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10808         TOKEN_STRING_INITIALIZER
10809                 (struct cmd_vf_mac_anti_spoof_result,
10810                  mac, "mac");
10811 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10812         TOKEN_STRING_INITIALIZER
10813                 (struct cmd_vf_mac_anti_spoof_result,
10814                  antispoof, "antispoof");
10815 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10816         TOKEN_NUM_INITIALIZER
10817                 (struct cmd_vf_mac_anti_spoof_result,
10818                  port_id, RTE_UINT16);
10819 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10820         TOKEN_NUM_INITIALIZER
10821                 (struct cmd_vf_mac_anti_spoof_result,
10822                  vf_id, RTE_UINT32);
10823 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10824         TOKEN_STRING_INITIALIZER
10825                 (struct cmd_vf_mac_anti_spoof_result,
10826                  on_off, "on#off");
10827
10828 static void
10829 cmd_set_vf_mac_anti_spoof_parsed(
10830         void *parsed_result,
10831         __rte_unused struct cmdline *cl,
10832         __rte_unused void *data)
10833 {
10834         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10835         int ret = -ENOTSUP;
10836
10837         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10838
10839         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10840                 return;
10841
10842 #ifdef RTE_NET_IXGBE
10843         if (ret == -ENOTSUP)
10844                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10845                         res->vf_id, is_on);
10846 #endif
10847 #ifdef RTE_NET_I40E
10848         if (ret == -ENOTSUP)
10849                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10850                         res->vf_id, is_on);
10851 #endif
10852 #ifdef RTE_NET_BNXT
10853         if (ret == -ENOTSUP)
10854                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10855                         res->vf_id, is_on);
10856 #endif
10857
10858         switch (ret) {
10859         case 0:
10860                 break;
10861         case -EINVAL:
10862                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10863                 break;
10864         case -ENODEV:
10865                 printf("invalid port_id %d\n", res->port_id);
10866                 break;
10867         case -ENOTSUP:
10868                 printf("function not implemented\n");
10869                 break;
10870         default:
10871                 printf("programming error: (%s)\n", strerror(-ret));
10872         }
10873 }
10874
10875 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10876         .f = cmd_set_vf_mac_anti_spoof_parsed,
10877         .data = NULL,
10878         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10879         .tokens = {
10880                 (void *)&cmd_vf_mac_anti_spoof_set,
10881                 (void *)&cmd_vf_mac_anti_spoof_vf,
10882                 (void *)&cmd_vf_mac_anti_spoof_mac,
10883                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10884                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10885                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10886                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10887                 NULL,
10888         },
10889 };
10890
10891 /* vf vlan strip queue configuration */
10892
10893 /* Common result structure for vf mac anti spoof */
10894 struct cmd_vf_vlan_stripq_result {
10895         cmdline_fixed_string_t set;
10896         cmdline_fixed_string_t vf;
10897         cmdline_fixed_string_t vlan;
10898         cmdline_fixed_string_t stripq;
10899         portid_t port_id;
10900         uint16_t vf_id;
10901         cmdline_fixed_string_t on_off;
10902 };
10903
10904 /* Common CLI fields for vf vlan strip enable disable */
10905 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10906         TOKEN_STRING_INITIALIZER
10907                 (struct cmd_vf_vlan_stripq_result,
10908                  set, "set");
10909 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10910         TOKEN_STRING_INITIALIZER
10911                 (struct cmd_vf_vlan_stripq_result,
10912                  vf, "vf");
10913 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10914         TOKEN_STRING_INITIALIZER
10915                 (struct cmd_vf_vlan_stripq_result,
10916                  vlan, "vlan");
10917 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10918         TOKEN_STRING_INITIALIZER
10919                 (struct cmd_vf_vlan_stripq_result,
10920                  stripq, "stripq");
10921 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10922         TOKEN_NUM_INITIALIZER
10923                 (struct cmd_vf_vlan_stripq_result,
10924                  port_id, RTE_UINT16);
10925 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10926         TOKEN_NUM_INITIALIZER
10927                 (struct cmd_vf_vlan_stripq_result,
10928                  vf_id, RTE_UINT16);
10929 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10930         TOKEN_STRING_INITIALIZER
10931                 (struct cmd_vf_vlan_stripq_result,
10932                  on_off, "on#off");
10933
10934 static void
10935 cmd_set_vf_vlan_stripq_parsed(
10936         void *parsed_result,
10937         __rte_unused struct cmdline *cl,
10938         __rte_unused void *data)
10939 {
10940         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10941         int ret = -ENOTSUP;
10942
10943         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10944
10945         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10946                 return;
10947
10948 #ifdef RTE_NET_IXGBE
10949         if (ret == -ENOTSUP)
10950                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10951                         res->vf_id, is_on);
10952 #endif
10953 #ifdef RTE_NET_I40E
10954         if (ret == -ENOTSUP)
10955                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10956                         res->vf_id, is_on);
10957 #endif
10958 #ifdef RTE_NET_BNXT
10959         if (ret == -ENOTSUP)
10960                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10961                         res->vf_id, is_on);
10962 #endif
10963
10964         switch (ret) {
10965         case 0:
10966                 break;
10967         case -EINVAL:
10968                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10969                 break;
10970         case -ENODEV:
10971                 printf("invalid port_id %d\n", res->port_id);
10972                 break;
10973         case -ENOTSUP:
10974                 printf("function not implemented\n");
10975                 break;
10976         default:
10977                 printf("programming error: (%s)\n", strerror(-ret));
10978         }
10979 }
10980
10981 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10982         .f = cmd_set_vf_vlan_stripq_parsed,
10983         .data = NULL,
10984         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10985         .tokens = {
10986                 (void *)&cmd_vf_vlan_stripq_set,
10987                 (void *)&cmd_vf_vlan_stripq_vf,
10988                 (void *)&cmd_vf_vlan_stripq_vlan,
10989                 (void *)&cmd_vf_vlan_stripq_stripq,
10990                 (void *)&cmd_vf_vlan_stripq_port_id,
10991                 (void *)&cmd_vf_vlan_stripq_vf_id,
10992                 (void *)&cmd_vf_vlan_stripq_on_off,
10993                 NULL,
10994         },
10995 };
10996
10997 /* vf vlan insert configuration */
10998
10999 /* Common result structure for vf vlan insert */
11000 struct cmd_vf_vlan_insert_result {
11001         cmdline_fixed_string_t set;
11002         cmdline_fixed_string_t vf;
11003         cmdline_fixed_string_t vlan;
11004         cmdline_fixed_string_t insert;
11005         portid_t port_id;
11006         uint16_t vf_id;
11007         uint16_t vlan_id;
11008 };
11009
11010 /* Common CLI fields for vf vlan insert enable disable */
11011 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11012         TOKEN_STRING_INITIALIZER
11013                 (struct cmd_vf_vlan_insert_result,
11014                  set, "set");
11015 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11016         TOKEN_STRING_INITIALIZER
11017                 (struct cmd_vf_vlan_insert_result,
11018                  vf, "vf");
11019 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11020         TOKEN_STRING_INITIALIZER
11021                 (struct cmd_vf_vlan_insert_result,
11022                  vlan, "vlan");
11023 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11024         TOKEN_STRING_INITIALIZER
11025                 (struct cmd_vf_vlan_insert_result,
11026                  insert, "insert");
11027 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11028         TOKEN_NUM_INITIALIZER
11029                 (struct cmd_vf_vlan_insert_result,
11030                  port_id, RTE_UINT16);
11031 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11032         TOKEN_NUM_INITIALIZER
11033                 (struct cmd_vf_vlan_insert_result,
11034                  vf_id, RTE_UINT16);
11035 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11036         TOKEN_NUM_INITIALIZER
11037                 (struct cmd_vf_vlan_insert_result,
11038                  vlan_id, RTE_UINT16);
11039
11040 static void
11041 cmd_set_vf_vlan_insert_parsed(
11042         void *parsed_result,
11043         __rte_unused struct cmdline *cl,
11044         __rte_unused void *data)
11045 {
11046         struct cmd_vf_vlan_insert_result *res = parsed_result;
11047         int ret = -ENOTSUP;
11048
11049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11050                 return;
11051
11052 #ifdef RTE_NET_IXGBE
11053         if (ret == -ENOTSUP)
11054                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11055                         res->vlan_id);
11056 #endif
11057 #ifdef RTE_NET_I40E
11058         if (ret == -ENOTSUP)
11059                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11060                         res->vlan_id);
11061 #endif
11062 #ifdef RTE_NET_BNXT
11063         if (ret == -ENOTSUP)
11064                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11065                         res->vlan_id);
11066 #endif
11067
11068         switch (ret) {
11069         case 0:
11070                 break;
11071         case -EINVAL:
11072                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11073                 break;
11074         case -ENODEV:
11075                 printf("invalid port_id %d\n", res->port_id);
11076                 break;
11077         case -ENOTSUP:
11078                 printf("function not implemented\n");
11079                 break;
11080         default:
11081                 printf("programming error: (%s)\n", strerror(-ret));
11082         }
11083 }
11084
11085 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11086         .f = cmd_set_vf_vlan_insert_parsed,
11087         .data = NULL,
11088         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11089         .tokens = {
11090                 (void *)&cmd_vf_vlan_insert_set,
11091                 (void *)&cmd_vf_vlan_insert_vf,
11092                 (void *)&cmd_vf_vlan_insert_vlan,
11093                 (void *)&cmd_vf_vlan_insert_insert,
11094                 (void *)&cmd_vf_vlan_insert_port_id,
11095                 (void *)&cmd_vf_vlan_insert_vf_id,
11096                 (void *)&cmd_vf_vlan_insert_vlan_id,
11097                 NULL,
11098         },
11099 };
11100
11101 /* tx loopback configuration */
11102
11103 /* Common result structure for tx loopback */
11104 struct cmd_tx_loopback_result {
11105         cmdline_fixed_string_t set;
11106         cmdline_fixed_string_t tx;
11107         cmdline_fixed_string_t loopback;
11108         portid_t port_id;
11109         cmdline_fixed_string_t on_off;
11110 };
11111
11112 /* Common CLI fields for tx loopback enable disable */
11113 cmdline_parse_token_string_t cmd_tx_loopback_set =
11114         TOKEN_STRING_INITIALIZER
11115                 (struct cmd_tx_loopback_result,
11116                  set, "set");
11117 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11118         TOKEN_STRING_INITIALIZER
11119                 (struct cmd_tx_loopback_result,
11120                  tx, "tx");
11121 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11122         TOKEN_STRING_INITIALIZER
11123                 (struct cmd_tx_loopback_result,
11124                  loopback, "loopback");
11125 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11126         TOKEN_NUM_INITIALIZER
11127                 (struct cmd_tx_loopback_result,
11128                  port_id, RTE_UINT16);
11129 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11130         TOKEN_STRING_INITIALIZER
11131                 (struct cmd_tx_loopback_result,
11132                  on_off, "on#off");
11133
11134 static void
11135 cmd_set_tx_loopback_parsed(
11136         void *parsed_result,
11137         __rte_unused struct cmdline *cl,
11138         __rte_unused void *data)
11139 {
11140         struct cmd_tx_loopback_result *res = parsed_result;
11141         int ret = -ENOTSUP;
11142
11143         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11144
11145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11146                 return;
11147
11148 #ifdef RTE_NET_IXGBE
11149         if (ret == -ENOTSUP)
11150                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11151 #endif
11152 #ifdef RTE_NET_I40E
11153         if (ret == -ENOTSUP)
11154                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11155 #endif
11156 #ifdef RTE_NET_BNXT
11157         if (ret == -ENOTSUP)
11158                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11159 #endif
11160 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11161         if (ret == -ENOTSUP)
11162                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11163 #endif
11164
11165         switch (ret) {
11166         case 0:
11167                 break;
11168         case -EINVAL:
11169                 printf("invalid is_on %d\n", is_on);
11170                 break;
11171         case -ENODEV:
11172                 printf("invalid port_id %d\n", res->port_id);
11173                 break;
11174         case -ENOTSUP:
11175                 printf("function not implemented\n");
11176                 break;
11177         default:
11178                 printf("programming error: (%s)\n", strerror(-ret));
11179         }
11180 }
11181
11182 cmdline_parse_inst_t cmd_set_tx_loopback = {
11183         .f = cmd_set_tx_loopback_parsed,
11184         .data = NULL,
11185         .help_str = "set tx loopback <port_id> on|off",
11186         .tokens = {
11187                 (void *)&cmd_tx_loopback_set,
11188                 (void *)&cmd_tx_loopback_tx,
11189                 (void *)&cmd_tx_loopback_loopback,
11190                 (void *)&cmd_tx_loopback_port_id,
11191                 (void *)&cmd_tx_loopback_on_off,
11192                 NULL,
11193         },
11194 };
11195
11196 /* all queues drop enable configuration */
11197
11198 /* Common result structure for all queues drop enable */
11199 struct cmd_all_queues_drop_en_result {
11200         cmdline_fixed_string_t set;
11201         cmdline_fixed_string_t all;
11202         cmdline_fixed_string_t queues;
11203         cmdline_fixed_string_t drop;
11204         portid_t port_id;
11205         cmdline_fixed_string_t on_off;
11206 };
11207
11208 /* Common CLI fields for tx loopback enable disable */
11209 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11210         TOKEN_STRING_INITIALIZER
11211                 (struct cmd_all_queues_drop_en_result,
11212                  set, "set");
11213 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11214         TOKEN_STRING_INITIALIZER
11215                 (struct cmd_all_queues_drop_en_result,
11216                  all, "all");
11217 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11218         TOKEN_STRING_INITIALIZER
11219                 (struct cmd_all_queues_drop_en_result,
11220                  queues, "queues");
11221 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11222         TOKEN_STRING_INITIALIZER
11223                 (struct cmd_all_queues_drop_en_result,
11224                  drop, "drop");
11225 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11226         TOKEN_NUM_INITIALIZER
11227                 (struct cmd_all_queues_drop_en_result,
11228                  port_id, RTE_UINT16);
11229 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_all_queues_drop_en_result,
11232                  on_off, "on#off");
11233
11234 static void
11235 cmd_set_all_queues_drop_en_parsed(
11236         void *parsed_result,
11237         __rte_unused struct cmdline *cl,
11238         __rte_unused void *data)
11239 {
11240         struct cmd_all_queues_drop_en_result *res = parsed_result;
11241         int ret = -ENOTSUP;
11242         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11243
11244         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11245                 return;
11246
11247 #ifdef RTE_NET_IXGBE
11248         if (ret == -ENOTSUP)
11249                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11250 #endif
11251 #ifdef RTE_NET_BNXT
11252         if (ret == -ENOTSUP)
11253                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11254 #endif
11255         switch (ret) {
11256         case 0:
11257                 break;
11258         case -EINVAL:
11259                 printf("invalid is_on %d\n", is_on);
11260                 break;
11261         case -ENODEV:
11262                 printf("invalid port_id %d\n", res->port_id);
11263                 break;
11264         case -ENOTSUP:
11265                 printf("function not implemented\n");
11266                 break;
11267         default:
11268                 printf("programming error: (%s)\n", strerror(-ret));
11269         }
11270 }
11271
11272 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11273         .f = cmd_set_all_queues_drop_en_parsed,
11274         .data = NULL,
11275         .help_str = "set all queues drop <port_id> on|off",
11276         .tokens = {
11277                 (void *)&cmd_all_queues_drop_en_set,
11278                 (void *)&cmd_all_queues_drop_en_all,
11279                 (void *)&cmd_all_queues_drop_en_queues,
11280                 (void *)&cmd_all_queues_drop_en_drop,
11281                 (void *)&cmd_all_queues_drop_en_port_id,
11282                 (void *)&cmd_all_queues_drop_en_on_off,
11283                 NULL,
11284         },
11285 };
11286
11287 /* vf split drop enable configuration */
11288
11289 /* Common result structure for vf split drop enable */
11290 struct cmd_vf_split_drop_en_result {
11291         cmdline_fixed_string_t set;
11292         cmdline_fixed_string_t vf;
11293         cmdline_fixed_string_t split;
11294         cmdline_fixed_string_t drop;
11295         portid_t port_id;
11296         uint16_t vf_id;
11297         cmdline_fixed_string_t on_off;
11298 };
11299
11300 /* Common CLI fields for vf split drop enable disable */
11301 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11302         TOKEN_STRING_INITIALIZER
11303                 (struct cmd_vf_split_drop_en_result,
11304                  set, "set");
11305 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11306         TOKEN_STRING_INITIALIZER
11307                 (struct cmd_vf_split_drop_en_result,
11308                  vf, "vf");
11309 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11310         TOKEN_STRING_INITIALIZER
11311                 (struct cmd_vf_split_drop_en_result,
11312                  split, "split");
11313 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11314         TOKEN_STRING_INITIALIZER
11315                 (struct cmd_vf_split_drop_en_result,
11316                  drop, "drop");
11317 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11318         TOKEN_NUM_INITIALIZER
11319                 (struct cmd_vf_split_drop_en_result,
11320                  port_id, RTE_UINT16);
11321 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11322         TOKEN_NUM_INITIALIZER
11323                 (struct cmd_vf_split_drop_en_result,
11324                  vf_id, RTE_UINT16);
11325 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11326         TOKEN_STRING_INITIALIZER
11327                 (struct cmd_vf_split_drop_en_result,
11328                  on_off, "on#off");
11329
11330 static void
11331 cmd_set_vf_split_drop_en_parsed(
11332         void *parsed_result,
11333         __rte_unused struct cmdline *cl,
11334         __rte_unused void *data)
11335 {
11336         struct cmd_vf_split_drop_en_result *res = parsed_result;
11337         int ret = -ENOTSUP;
11338         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11339
11340         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11341                 return;
11342
11343 #ifdef RTE_NET_IXGBE
11344         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11345                         is_on);
11346 #endif
11347         switch (ret) {
11348         case 0:
11349                 break;
11350         case -EINVAL:
11351                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11352                 break;
11353         case -ENODEV:
11354                 printf("invalid port_id %d\n", res->port_id);
11355                 break;
11356         case -ENOTSUP:
11357                 printf("not supported on port %d\n", res->port_id);
11358                 break;
11359         default:
11360                 printf("programming error: (%s)\n", strerror(-ret));
11361         }
11362 }
11363
11364 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11365         .f = cmd_set_vf_split_drop_en_parsed,
11366         .data = NULL,
11367         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11368         .tokens = {
11369                 (void *)&cmd_vf_split_drop_en_set,
11370                 (void *)&cmd_vf_split_drop_en_vf,
11371                 (void *)&cmd_vf_split_drop_en_split,
11372                 (void *)&cmd_vf_split_drop_en_drop,
11373                 (void *)&cmd_vf_split_drop_en_port_id,
11374                 (void *)&cmd_vf_split_drop_en_vf_id,
11375                 (void *)&cmd_vf_split_drop_en_on_off,
11376                 NULL,
11377         },
11378 };
11379
11380 /* vf mac address configuration */
11381
11382 /* Common result structure for vf mac address */
11383 struct cmd_set_vf_mac_addr_result {
11384         cmdline_fixed_string_t set;
11385         cmdline_fixed_string_t vf;
11386         cmdline_fixed_string_t mac;
11387         cmdline_fixed_string_t addr;
11388         portid_t port_id;
11389         uint16_t vf_id;
11390         struct rte_ether_addr mac_addr;
11391
11392 };
11393
11394 /* Common CLI fields for vf split drop enable disable */
11395 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11396         TOKEN_STRING_INITIALIZER
11397                 (struct cmd_set_vf_mac_addr_result,
11398                  set, "set");
11399 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11400         TOKEN_STRING_INITIALIZER
11401                 (struct cmd_set_vf_mac_addr_result,
11402                  vf, "vf");
11403 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11404         TOKEN_STRING_INITIALIZER
11405                 (struct cmd_set_vf_mac_addr_result,
11406                  mac, "mac");
11407 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11408         TOKEN_STRING_INITIALIZER
11409                 (struct cmd_set_vf_mac_addr_result,
11410                  addr, "addr");
11411 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11412         TOKEN_NUM_INITIALIZER
11413                 (struct cmd_set_vf_mac_addr_result,
11414                  port_id, RTE_UINT16);
11415 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11416         TOKEN_NUM_INITIALIZER
11417                 (struct cmd_set_vf_mac_addr_result,
11418                  vf_id, RTE_UINT16);
11419 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11420         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11421                  mac_addr);
11422
11423 static void
11424 cmd_set_vf_mac_addr_parsed(
11425         void *parsed_result,
11426         __rte_unused struct cmdline *cl,
11427         __rte_unused void *data)
11428 {
11429         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11430         int ret = -ENOTSUP;
11431
11432         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11433                 return;
11434
11435 #ifdef RTE_NET_IXGBE
11436         if (ret == -ENOTSUP)
11437                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11438                                 &res->mac_addr);
11439 #endif
11440 #ifdef RTE_NET_I40E
11441         if (ret == -ENOTSUP)
11442                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11443                                 &res->mac_addr);
11444 #endif
11445 #ifdef RTE_NET_BNXT
11446         if (ret == -ENOTSUP)
11447                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11448                                 &res->mac_addr);
11449 #endif
11450
11451         switch (ret) {
11452         case 0:
11453                 break;
11454         case -EINVAL:
11455                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11456                 break;
11457         case -ENODEV:
11458                 printf("invalid port_id %d\n", res->port_id);
11459                 break;
11460         case -ENOTSUP:
11461                 printf("function not implemented\n");
11462                 break;
11463         default:
11464                 printf("programming error: (%s)\n", strerror(-ret));
11465         }
11466 }
11467
11468 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11469         .f = cmd_set_vf_mac_addr_parsed,
11470         .data = NULL,
11471         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11472         .tokens = {
11473                 (void *)&cmd_set_vf_mac_addr_set,
11474                 (void *)&cmd_set_vf_mac_addr_vf,
11475                 (void *)&cmd_set_vf_mac_addr_mac,
11476                 (void *)&cmd_set_vf_mac_addr_addr,
11477                 (void *)&cmd_set_vf_mac_addr_port_id,
11478                 (void *)&cmd_set_vf_mac_addr_vf_id,
11479                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11480                 NULL,
11481         },
11482 };
11483
11484 /* MACsec configuration */
11485
11486 /* Common result structure for MACsec offload enable */
11487 struct cmd_macsec_offload_on_result {
11488         cmdline_fixed_string_t set;
11489         cmdline_fixed_string_t macsec;
11490         cmdline_fixed_string_t offload;
11491         portid_t port_id;
11492         cmdline_fixed_string_t on;
11493         cmdline_fixed_string_t encrypt;
11494         cmdline_fixed_string_t en_on_off;
11495         cmdline_fixed_string_t replay_protect;
11496         cmdline_fixed_string_t rp_on_off;
11497 };
11498
11499 /* Common CLI fields for MACsec offload disable */
11500 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11501         TOKEN_STRING_INITIALIZER
11502                 (struct cmd_macsec_offload_on_result,
11503                  set, "set");
11504 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11505         TOKEN_STRING_INITIALIZER
11506                 (struct cmd_macsec_offload_on_result,
11507                  macsec, "macsec");
11508 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11509         TOKEN_STRING_INITIALIZER
11510                 (struct cmd_macsec_offload_on_result,
11511                  offload, "offload");
11512 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11513         TOKEN_NUM_INITIALIZER
11514                 (struct cmd_macsec_offload_on_result,
11515                  port_id, RTE_UINT16);
11516 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11517         TOKEN_STRING_INITIALIZER
11518                 (struct cmd_macsec_offload_on_result,
11519                  on, "on");
11520 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11521         TOKEN_STRING_INITIALIZER
11522                 (struct cmd_macsec_offload_on_result,
11523                  encrypt, "encrypt");
11524 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11525         TOKEN_STRING_INITIALIZER
11526                 (struct cmd_macsec_offload_on_result,
11527                  en_on_off, "on#off");
11528 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11529         TOKEN_STRING_INITIALIZER
11530                 (struct cmd_macsec_offload_on_result,
11531                  replay_protect, "replay-protect");
11532 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11533         TOKEN_STRING_INITIALIZER
11534                 (struct cmd_macsec_offload_on_result,
11535                  rp_on_off, "on#off");
11536
11537 static void
11538 cmd_set_macsec_offload_on_parsed(
11539         void *parsed_result,
11540         __rte_unused struct cmdline *cl,
11541         __rte_unused void *data)
11542 {
11543         struct cmd_macsec_offload_on_result *res = parsed_result;
11544         int ret = -ENOTSUP;
11545         portid_t port_id = res->port_id;
11546         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11547         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11548         struct rte_eth_dev_info dev_info;
11549
11550         if (port_id_is_invalid(port_id, ENABLED_WARN))
11551                 return;
11552         if (!port_is_stopped(port_id)) {
11553                 printf("Please stop port %d first\n", port_id);
11554                 return;
11555         }
11556
11557         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11558         if (ret != 0)
11559                 return;
11560
11561         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11562 #ifdef RTE_NET_IXGBE
11563                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11564 #endif
11565         }
11566         RTE_SET_USED(en);
11567         RTE_SET_USED(rp);
11568
11569         switch (ret) {
11570         case 0:
11571                 ports[port_id].dev_conf.txmode.offloads |=
11572                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11573                 cmd_reconfig_device_queue(port_id, 1, 1);
11574                 break;
11575         case -ENODEV:
11576                 printf("invalid port_id %d\n", port_id);
11577                 break;
11578         case -ENOTSUP:
11579                 printf("not supported on port %d\n", port_id);
11580                 break;
11581         default:
11582                 printf("programming error: (%s)\n", strerror(-ret));
11583         }
11584 }
11585
11586 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11587         .f = cmd_set_macsec_offload_on_parsed,
11588         .data = NULL,
11589         .help_str = "set macsec offload <port_id> on "
11590                 "encrypt on|off replay-protect on|off",
11591         .tokens = {
11592                 (void *)&cmd_macsec_offload_on_set,
11593                 (void *)&cmd_macsec_offload_on_macsec,
11594                 (void *)&cmd_macsec_offload_on_offload,
11595                 (void *)&cmd_macsec_offload_on_port_id,
11596                 (void *)&cmd_macsec_offload_on_on,
11597                 (void *)&cmd_macsec_offload_on_encrypt,
11598                 (void *)&cmd_macsec_offload_on_en_on_off,
11599                 (void *)&cmd_macsec_offload_on_replay_protect,
11600                 (void *)&cmd_macsec_offload_on_rp_on_off,
11601                 NULL,
11602         },
11603 };
11604
11605 /* Common result structure for MACsec offload disable */
11606 struct cmd_macsec_offload_off_result {
11607         cmdline_fixed_string_t set;
11608         cmdline_fixed_string_t macsec;
11609         cmdline_fixed_string_t offload;
11610         portid_t port_id;
11611         cmdline_fixed_string_t off;
11612 };
11613
11614 /* Common CLI fields for MACsec offload disable */
11615 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11616         TOKEN_STRING_INITIALIZER
11617                 (struct cmd_macsec_offload_off_result,
11618                  set, "set");
11619 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11620         TOKEN_STRING_INITIALIZER
11621                 (struct cmd_macsec_offload_off_result,
11622                  macsec, "macsec");
11623 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11624         TOKEN_STRING_INITIALIZER
11625                 (struct cmd_macsec_offload_off_result,
11626                  offload, "offload");
11627 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11628         TOKEN_NUM_INITIALIZER
11629                 (struct cmd_macsec_offload_off_result,
11630                  port_id, RTE_UINT16);
11631 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11632         TOKEN_STRING_INITIALIZER
11633                 (struct cmd_macsec_offload_off_result,
11634                  off, "off");
11635
11636 static void
11637 cmd_set_macsec_offload_off_parsed(
11638         void *parsed_result,
11639         __rte_unused struct cmdline *cl,
11640         __rte_unused void *data)
11641 {
11642         struct cmd_macsec_offload_off_result *res = parsed_result;
11643         int ret = -ENOTSUP;
11644         struct rte_eth_dev_info dev_info;
11645         portid_t port_id = res->port_id;
11646
11647         if (port_id_is_invalid(port_id, ENABLED_WARN))
11648                 return;
11649         if (!port_is_stopped(port_id)) {
11650                 printf("Please stop port %d first\n", port_id);
11651                 return;
11652         }
11653
11654         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11655         if (ret != 0)
11656                 return;
11657
11658         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11659 #ifdef RTE_NET_IXGBE
11660                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11661 #endif
11662         }
11663         switch (ret) {
11664         case 0:
11665                 ports[port_id].dev_conf.txmode.offloads &=
11666                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11667                 cmd_reconfig_device_queue(port_id, 1, 1);
11668                 break;
11669         case -ENODEV:
11670                 printf("invalid port_id %d\n", port_id);
11671                 break;
11672         case -ENOTSUP:
11673                 printf("not supported on port %d\n", port_id);
11674                 break;
11675         default:
11676                 printf("programming error: (%s)\n", strerror(-ret));
11677         }
11678 }
11679
11680 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11681         .f = cmd_set_macsec_offload_off_parsed,
11682         .data = NULL,
11683         .help_str = "set macsec offload <port_id> off",
11684         .tokens = {
11685                 (void *)&cmd_macsec_offload_off_set,
11686                 (void *)&cmd_macsec_offload_off_macsec,
11687                 (void *)&cmd_macsec_offload_off_offload,
11688                 (void *)&cmd_macsec_offload_off_port_id,
11689                 (void *)&cmd_macsec_offload_off_off,
11690                 NULL,
11691         },
11692 };
11693
11694 /* Common result structure for MACsec secure connection configure */
11695 struct cmd_macsec_sc_result {
11696         cmdline_fixed_string_t set;
11697         cmdline_fixed_string_t macsec;
11698         cmdline_fixed_string_t sc;
11699         cmdline_fixed_string_t tx_rx;
11700         portid_t port_id;
11701         struct rte_ether_addr mac;
11702         uint16_t pi;
11703 };
11704
11705 /* Common CLI fields for MACsec secure connection configure */
11706 cmdline_parse_token_string_t cmd_macsec_sc_set =
11707         TOKEN_STRING_INITIALIZER
11708                 (struct cmd_macsec_sc_result,
11709                  set, "set");
11710 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11711         TOKEN_STRING_INITIALIZER
11712                 (struct cmd_macsec_sc_result,
11713                  macsec, "macsec");
11714 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11715         TOKEN_STRING_INITIALIZER
11716                 (struct cmd_macsec_sc_result,
11717                  sc, "sc");
11718 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11719         TOKEN_STRING_INITIALIZER
11720                 (struct cmd_macsec_sc_result,
11721                  tx_rx, "tx#rx");
11722 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11723         TOKEN_NUM_INITIALIZER
11724                 (struct cmd_macsec_sc_result,
11725                  port_id, RTE_UINT16);
11726 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11727         TOKEN_ETHERADDR_INITIALIZER
11728                 (struct cmd_macsec_sc_result,
11729                  mac);
11730 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11731         TOKEN_NUM_INITIALIZER
11732                 (struct cmd_macsec_sc_result,
11733                  pi, RTE_UINT16);
11734
11735 static void
11736 cmd_set_macsec_sc_parsed(
11737         void *parsed_result,
11738         __rte_unused struct cmdline *cl,
11739         __rte_unused void *data)
11740 {
11741         struct cmd_macsec_sc_result *res = parsed_result;
11742         int ret = -ENOTSUP;
11743         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11744
11745 #ifdef RTE_NET_IXGBE
11746         ret = is_tx ?
11747                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11748                                 res->mac.addr_bytes) :
11749                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11750                                 res->mac.addr_bytes, res->pi);
11751 #endif
11752         RTE_SET_USED(is_tx);
11753
11754         switch (ret) {
11755         case 0:
11756                 break;
11757         case -ENODEV:
11758                 printf("invalid port_id %d\n", res->port_id);
11759                 break;
11760         case -ENOTSUP:
11761                 printf("not supported on port %d\n", res->port_id);
11762                 break;
11763         default:
11764                 printf("programming error: (%s)\n", strerror(-ret));
11765         }
11766 }
11767
11768 cmdline_parse_inst_t cmd_set_macsec_sc = {
11769         .f = cmd_set_macsec_sc_parsed,
11770         .data = NULL,
11771         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11772         .tokens = {
11773                 (void *)&cmd_macsec_sc_set,
11774                 (void *)&cmd_macsec_sc_macsec,
11775                 (void *)&cmd_macsec_sc_sc,
11776                 (void *)&cmd_macsec_sc_tx_rx,
11777                 (void *)&cmd_macsec_sc_port_id,
11778                 (void *)&cmd_macsec_sc_mac,
11779                 (void *)&cmd_macsec_sc_pi,
11780                 NULL,
11781         },
11782 };
11783
11784 /* Common result structure for MACsec secure connection configure */
11785 struct cmd_macsec_sa_result {
11786         cmdline_fixed_string_t set;
11787         cmdline_fixed_string_t macsec;
11788         cmdline_fixed_string_t sa;
11789         cmdline_fixed_string_t tx_rx;
11790         portid_t port_id;
11791         uint8_t idx;
11792         uint8_t an;
11793         uint32_t pn;
11794         cmdline_fixed_string_t key;
11795 };
11796
11797 /* Common CLI fields for MACsec secure connection configure */
11798 cmdline_parse_token_string_t cmd_macsec_sa_set =
11799         TOKEN_STRING_INITIALIZER
11800                 (struct cmd_macsec_sa_result,
11801                  set, "set");
11802 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11803         TOKEN_STRING_INITIALIZER
11804                 (struct cmd_macsec_sa_result,
11805                  macsec, "macsec");
11806 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11807         TOKEN_STRING_INITIALIZER
11808                 (struct cmd_macsec_sa_result,
11809                  sa, "sa");
11810 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11811         TOKEN_STRING_INITIALIZER
11812                 (struct cmd_macsec_sa_result,
11813                  tx_rx, "tx#rx");
11814 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11815         TOKEN_NUM_INITIALIZER
11816                 (struct cmd_macsec_sa_result,
11817                  port_id, RTE_UINT16);
11818 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11819         TOKEN_NUM_INITIALIZER
11820                 (struct cmd_macsec_sa_result,
11821                  idx, RTE_UINT8);
11822 cmdline_parse_token_num_t cmd_macsec_sa_an =
11823         TOKEN_NUM_INITIALIZER
11824                 (struct cmd_macsec_sa_result,
11825                  an, RTE_UINT8);
11826 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11827         TOKEN_NUM_INITIALIZER
11828                 (struct cmd_macsec_sa_result,
11829                  pn, RTE_UINT32);
11830 cmdline_parse_token_string_t cmd_macsec_sa_key =
11831         TOKEN_STRING_INITIALIZER
11832                 (struct cmd_macsec_sa_result,
11833                  key, NULL);
11834
11835 static void
11836 cmd_set_macsec_sa_parsed(
11837         void *parsed_result,
11838         __rte_unused struct cmdline *cl,
11839         __rte_unused void *data)
11840 {
11841         struct cmd_macsec_sa_result *res = parsed_result;
11842         int ret = -ENOTSUP;
11843         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11844         uint8_t key[16] = { 0 };
11845         uint8_t xdgt0;
11846         uint8_t xdgt1;
11847         int key_len;
11848         int i;
11849
11850         key_len = strlen(res->key) / 2;
11851         if (key_len > 16)
11852                 key_len = 16;
11853
11854         for (i = 0; i < key_len; i++) {
11855                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11856                 if (xdgt0 == 0xFF)
11857                         return;
11858                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11859                 if (xdgt1 == 0xFF)
11860                         return;
11861                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11862         }
11863
11864 #ifdef RTE_NET_IXGBE
11865         ret = is_tx ?
11866                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11867                         res->idx, res->an, res->pn, key) :
11868                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11869                         res->idx, res->an, res->pn, key);
11870 #endif
11871         RTE_SET_USED(is_tx);
11872         RTE_SET_USED(key);
11873
11874         switch (ret) {
11875         case 0:
11876                 break;
11877         case -EINVAL:
11878                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11879                 break;
11880         case -ENODEV:
11881                 printf("invalid port_id %d\n", res->port_id);
11882                 break;
11883         case -ENOTSUP:
11884                 printf("not supported on port %d\n", res->port_id);
11885                 break;
11886         default:
11887                 printf("programming error: (%s)\n", strerror(-ret));
11888         }
11889 }
11890
11891 cmdline_parse_inst_t cmd_set_macsec_sa = {
11892         .f = cmd_set_macsec_sa_parsed,
11893         .data = NULL,
11894         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11895         .tokens = {
11896                 (void *)&cmd_macsec_sa_set,
11897                 (void *)&cmd_macsec_sa_macsec,
11898                 (void *)&cmd_macsec_sa_sa,
11899                 (void *)&cmd_macsec_sa_tx_rx,
11900                 (void *)&cmd_macsec_sa_port_id,
11901                 (void *)&cmd_macsec_sa_idx,
11902                 (void *)&cmd_macsec_sa_an,
11903                 (void *)&cmd_macsec_sa_pn,
11904                 (void *)&cmd_macsec_sa_key,
11905                 NULL,
11906         },
11907 };
11908
11909 /* VF unicast promiscuous mode configuration */
11910
11911 /* Common result structure for VF unicast promiscuous mode */
11912 struct cmd_vf_promisc_result {
11913         cmdline_fixed_string_t set;
11914         cmdline_fixed_string_t vf;
11915         cmdline_fixed_string_t promisc;
11916         portid_t port_id;
11917         uint32_t vf_id;
11918         cmdline_fixed_string_t on_off;
11919 };
11920
11921 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11922 cmdline_parse_token_string_t cmd_vf_promisc_set =
11923         TOKEN_STRING_INITIALIZER
11924                 (struct cmd_vf_promisc_result,
11925                  set, "set");
11926 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11927         TOKEN_STRING_INITIALIZER
11928                 (struct cmd_vf_promisc_result,
11929                  vf, "vf");
11930 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11931         TOKEN_STRING_INITIALIZER
11932                 (struct cmd_vf_promisc_result,
11933                  promisc, "promisc");
11934 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11935         TOKEN_NUM_INITIALIZER
11936                 (struct cmd_vf_promisc_result,
11937                  port_id, RTE_UINT16);
11938 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11939         TOKEN_NUM_INITIALIZER
11940                 (struct cmd_vf_promisc_result,
11941                  vf_id, RTE_UINT32);
11942 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11943         TOKEN_STRING_INITIALIZER
11944                 (struct cmd_vf_promisc_result,
11945                  on_off, "on#off");
11946
11947 static void
11948 cmd_set_vf_promisc_parsed(
11949         void *parsed_result,
11950         __rte_unused struct cmdline *cl,
11951         __rte_unused void *data)
11952 {
11953         struct cmd_vf_promisc_result *res = parsed_result;
11954         int ret = -ENOTSUP;
11955
11956         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11957
11958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11959                 return;
11960
11961 #ifdef RTE_NET_I40E
11962         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11963                                                   res->vf_id, is_on);
11964 #endif
11965
11966         switch (ret) {
11967         case 0:
11968                 break;
11969         case -EINVAL:
11970                 printf("invalid vf_id %d\n", res->vf_id);
11971                 break;
11972         case -ENODEV:
11973                 printf("invalid port_id %d\n", res->port_id);
11974                 break;
11975         case -ENOTSUP:
11976                 printf("function not implemented\n");
11977                 break;
11978         default:
11979                 printf("programming error: (%s)\n", strerror(-ret));
11980         }
11981 }
11982
11983 cmdline_parse_inst_t cmd_set_vf_promisc = {
11984         .f = cmd_set_vf_promisc_parsed,
11985         .data = NULL,
11986         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11987                 "Set unicast promiscuous mode for a VF from the PF",
11988         .tokens = {
11989                 (void *)&cmd_vf_promisc_set,
11990                 (void *)&cmd_vf_promisc_vf,
11991                 (void *)&cmd_vf_promisc_promisc,
11992                 (void *)&cmd_vf_promisc_port_id,
11993                 (void *)&cmd_vf_promisc_vf_id,
11994                 (void *)&cmd_vf_promisc_on_off,
11995                 NULL,
11996         },
11997 };
11998
11999 /* VF multicast promiscuous mode configuration */
12000
12001 /* Common result structure for VF multicast promiscuous mode */
12002 struct cmd_vf_allmulti_result {
12003         cmdline_fixed_string_t set;
12004         cmdline_fixed_string_t vf;
12005         cmdline_fixed_string_t allmulti;
12006         portid_t port_id;
12007         uint32_t vf_id;
12008         cmdline_fixed_string_t on_off;
12009 };
12010
12011 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12012 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12013         TOKEN_STRING_INITIALIZER
12014                 (struct cmd_vf_allmulti_result,
12015                  set, "set");
12016 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12017         TOKEN_STRING_INITIALIZER
12018                 (struct cmd_vf_allmulti_result,
12019                  vf, "vf");
12020 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12021         TOKEN_STRING_INITIALIZER
12022                 (struct cmd_vf_allmulti_result,
12023                  allmulti, "allmulti");
12024 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12025         TOKEN_NUM_INITIALIZER
12026                 (struct cmd_vf_allmulti_result,
12027                  port_id, RTE_UINT16);
12028 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12029         TOKEN_NUM_INITIALIZER
12030                 (struct cmd_vf_allmulti_result,
12031                  vf_id, RTE_UINT32);
12032 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12033         TOKEN_STRING_INITIALIZER
12034                 (struct cmd_vf_allmulti_result,
12035                  on_off, "on#off");
12036
12037 static void
12038 cmd_set_vf_allmulti_parsed(
12039         void *parsed_result,
12040         __rte_unused struct cmdline *cl,
12041         __rte_unused void *data)
12042 {
12043         struct cmd_vf_allmulti_result *res = parsed_result;
12044         int ret = -ENOTSUP;
12045
12046         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12047
12048         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12049                 return;
12050
12051 #ifdef RTE_NET_I40E
12052         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12053                                                     res->vf_id, is_on);
12054 #endif
12055
12056         switch (ret) {
12057         case 0:
12058                 break;
12059         case -EINVAL:
12060                 printf("invalid vf_id %d\n", res->vf_id);
12061                 break;
12062         case -ENODEV:
12063                 printf("invalid port_id %d\n", res->port_id);
12064                 break;
12065         case -ENOTSUP:
12066                 printf("function not implemented\n");
12067                 break;
12068         default:
12069                 printf("programming error: (%s)\n", strerror(-ret));
12070         }
12071 }
12072
12073 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12074         .f = cmd_set_vf_allmulti_parsed,
12075         .data = NULL,
12076         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12077                 "Set multicast promiscuous mode for a VF from the PF",
12078         .tokens = {
12079                 (void *)&cmd_vf_allmulti_set,
12080                 (void *)&cmd_vf_allmulti_vf,
12081                 (void *)&cmd_vf_allmulti_allmulti,
12082                 (void *)&cmd_vf_allmulti_port_id,
12083                 (void *)&cmd_vf_allmulti_vf_id,
12084                 (void *)&cmd_vf_allmulti_on_off,
12085                 NULL,
12086         },
12087 };
12088
12089 /* vf broadcast mode configuration */
12090
12091 /* Common result structure for vf broadcast */
12092 struct cmd_set_vf_broadcast_result {
12093         cmdline_fixed_string_t set;
12094         cmdline_fixed_string_t vf;
12095         cmdline_fixed_string_t broadcast;
12096         portid_t port_id;
12097         uint16_t vf_id;
12098         cmdline_fixed_string_t on_off;
12099 };
12100
12101 /* Common CLI fields for vf broadcast enable disable */
12102 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12103         TOKEN_STRING_INITIALIZER
12104                 (struct cmd_set_vf_broadcast_result,
12105                  set, "set");
12106 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12107         TOKEN_STRING_INITIALIZER
12108                 (struct cmd_set_vf_broadcast_result,
12109                  vf, "vf");
12110 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12111         TOKEN_STRING_INITIALIZER
12112                 (struct cmd_set_vf_broadcast_result,
12113                  broadcast, "broadcast");
12114 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12115         TOKEN_NUM_INITIALIZER
12116                 (struct cmd_set_vf_broadcast_result,
12117                  port_id, RTE_UINT16);
12118 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12119         TOKEN_NUM_INITIALIZER
12120                 (struct cmd_set_vf_broadcast_result,
12121                  vf_id, RTE_UINT16);
12122 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12123         TOKEN_STRING_INITIALIZER
12124                 (struct cmd_set_vf_broadcast_result,
12125                  on_off, "on#off");
12126
12127 static void
12128 cmd_set_vf_broadcast_parsed(
12129         void *parsed_result,
12130         __rte_unused struct cmdline *cl,
12131         __rte_unused void *data)
12132 {
12133         struct cmd_set_vf_broadcast_result *res = parsed_result;
12134         int ret = -ENOTSUP;
12135
12136         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12137
12138         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12139                 return;
12140
12141 #ifdef RTE_NET_I40E
12142         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12143                                             res->vf_id, is_on);
12144 #endif
12145
12146         switch (ret) {
12147         case 0:
12148                 break;
12149         case -EINVAL:
12150                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12151                 break;
12152         case -ENODEV:
12153                 printf("invalid port_id %d\n", res->port_id);
12154                 break;
12155         case -ENOTSUP:
12156                 printf("function not implemented\n");
12157                 break;
12158         default:
12159                 printf("programming error: (%s)\n", strerror(-ret));
12160         }
12161 }
12162
12163 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12164         .f = cmd_set_vf_broadcast_parsed,
12165         .data = NULL,
12166         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12167         .tokens = {
12168                 (void *)&cmd_set_vf_broadcast_set,
12169                 (void *)&cmd_set_vf_broadcast_vf,
12170                 (void *)&cmd_set_vf_broadcast_broadcast,
12171                 (void *)&cmd_set_vf_broadcast_port_id,
12172                 (void *)&cmd_set_vf_broadcast_vf_id,
12173                 (void *)&cmd_set_vf_broadcast_on_off,
12174                 NULL,
12175         },
12176 };
12177
12178 /* vf vlan tag configuration */
12179
12180 /* Common result structure for vf vlan tag */
12181 struct cmd_set_vf_vlan_tag_result {
12182         cmdline_fixed_string_t set;
12183         cmdline_fixed_string_t vf;
12184         cmdline_fixed_string_t vlan;
12185         cmdline_fixed_string_t tag;
12186         portid_t port_id;
12187         uint16_t vf_id;
12188         cmdline_fixed_string_t on_off;
12189 };
12190
12191 /* Common CLI fields for vf vlan tag enable disable */
12192 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12193         TOKEN_STRING_INITIALIZER
12194                 (struct cmd_set_vf_vlan_tag_result,
12195                  set, "set");
12196 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12197         TOKEN_STRING_INITIALIZER
12198                 (struct cmd_set_vf_vlan_tag_result,
12199                  vf, "vf");
12200 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12201         TOKEN_STRING_INITIALIZER
12202                 (struct cmd_set_vf_vlan_tag_result,
12203                  vlan, "vlan");
12204 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12205         TOKEN_STRING_INITIALIZER
12206                 (struct cmd_set_vf_vlan_tag_result,
12207                  tag, "tag");
12208 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12209         TOKEN_NUM_INITIALIZER
12210                 (struct cmd_set_vf_vlan_tag_result,
12211                  port_id, RTE_UINT16);
12212 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12213         TOKEN_NUM_INITIALIZER
12214                 (struct cmd_set_vf_vlan_tag_result,
12215                  vf_id, RTE_UINT16);
12216 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12217         TOKEN_STRING_INITIALIZER
12218                 (struct cmd_set_vf_vlan_tag_result,
12219                  on_off, "on#off");
12220
12221 static void
12222 cmd_set_vf_vlan_tag_parsed(
12223         void *parsed_result,
12224         __rte_unused struct cmdline *cl,
12225         __rte_unused void *data)
12226 {
12227         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12228         int ret = -ENOTSUP;
12229
12230         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12231
12232         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12233                 return;
12234
12235 #ifdef RTE_NET_I40E
12236         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12237                                            res->vf_id, is_on);
12238 #endif
12239
12240         switch (ret) {
12241         case 0:
12242                 break;
12243         case -EINVAL:
12244                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12245                 break;
12246         case -ENODEV:
12247                 printf("invalid port_id %d\n", res->port_id);
12248                 break;
12249         case -ENOTSUP:
12250                 printf("function not implemented\n");
12251                 break;
12252         default:
12253                 printf("programming error: (%s)\n", strerror(-ret));
12254         }
12255 }
12256
12257 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12258         .f = cmd_set_vf_vlan_tag_parsed,
12259         .data = NULL,
12260         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12261         .tokens = {
12262                 (void *)&cmd_set_vf_vlan_tag_set,
12263                 (void *)&cmd_set_vf_vlan_tag_vf,
12264                 (void *)&cmd_set_vf_vlan_tag_vlan,
12265                 (void *)&cmd_set_vf_vlan_tag_tag,
12266                 (void *)&cmd_set_vf_vlan_tag_port_id,
12267                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12268                 (void *)&cmd_set_vf_vlan_tag_on_off,
12269                 NULL,
12270         },
12271 };
12272
12273 /* Common definition of VF and TC TX bandwidth configuration */
12274 struct cmd_vf_tc_bw_result {
12275         cmdline_fixed_string_t set;
12276         cmdline_fixed_string_t vf;
12277         cmdline_fixed_string_t tc;
12278         cmdline_fixed_string_t tx;
12279         cmdline_fixed_string_t min_bw;
12280         cmdline_fixed_string_t max_bw;
12281         cmdline_fixed_string_t strict_link_prio;
12282         portid_t port_id;
12283         uint16_t vf_id;
12284         uint8_t tc_no;
12285         uint32_t bw;
12286         cmdline_fixed_string_t bw_list;
12287         uint8_t tc_map;
12288 };
12289
12290 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12291         TOKEN_STRING_INITIALIZER
12292                 (struct cmd_vf_tc_bw_result,
12293                  set, "set");
12294 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12295         TOKEN_STRING_INITIALIZER
12296                 (struct cmd_vf_tc_bw_result,
12297                  vf, "vf");
12298 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12299         TOKEN_STRING_INITIALIZER
12300                 (struct cmd_vf_tc_bw_result,
12301                  tc, "tc");
12302 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12303         TOKEN_STRING_INITIALIZER
12304                 (struct cmd_vf_tc_bw_result,
12305                  tx, "tx");
12306 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12307         TOKEN_STRING_INITIALIZER
12308                 (struct cmd_vf_tc_bw_result,
12309                  strict_link_prio, "strict-link-priority");
12310 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12311         TOKEN_STRING_INITIALIZER
12312                 (struct cmd_vf_tc_bw_result,
12313                  min_bw, "min-bandwidth");
12314 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12315         TOKEN_STRING_INITIALIZER
12316                 (struct cmd_vf_tc_bw_result,
12317                  max_bw, "max-bandwidth");
12318 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12319         TOKEN_NUM_INITIALIZER
12320                 (struct cmd_vf_tc_bw_result,
12321                  port_id, RTE_UINT16);
12322 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12323         TOKEN_NUM_INITIALIZER
12324                 (struct cmd_vf_tc_bw_result,
12325                  vf_id, RTE_UINT16);
12326 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12327         TOKEN_NUM_INITIALIZER
12328                 (struct cmd_vf_tc_bw_result,
12329                  tc_no, RTE_UINT8);
12330 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12331         TOKEN_NUM_INITIALIZER
12332                 (struct cmd_vf_tc_bw_result,
12333                  bw, RTE_UINT32);
12334 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12335         TOKEN_STRING_INITIALIZER
12336                 (struct cmd_vf_tc_bw_result,
12337                  bw_list, NULL);
12338 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12339         TOKEN_NUM_INITIALIZER
12340                 (struct cmd_vf_tc_bw_result,
12341                  tc_map, RTE_UINT8);
12342
12343 /* VF max bandwidth setting */
12344 static void
12345 cmd_vf_max_bw_parsed(
12346         void *parsed_result,
12347         __rte_unused struct cmdline *cl,
12348         __rte_unused void *data)
12349 {
12350         struct cmd_vf_tc_bw_result *res = parsed_result;
12351         int ret = -ENOTSUP;
12352
12353         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12354                 return;
12355
12356 #ifdef RTE_NET_I40E
12357         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12358                                          res->vf_id, res->bw);
12359 #endif
12360
12361         switch (ret) {
12362         case 0:
12363                 break;
12364         case -EINVAL:
12365                 printf("invalid vf_id %d or bandwidth %d\n",
12366                        res->vf_id, res->bw);
12367                 break;
12368         case -ENODEV:
12369                 printf("invalid port_id %d\n", res->port_id);
12370                 break;
12371         case -ENOTSUP:
12372                 printf("function not implemented\n");
12373                 break;
12374         default:
12375                 printf("programming error: (%s)\n", strerror(-ret));
12376         }
12377 }
12378
12379 cmdline_parse_inst_t cmd_vf_max_bw = {
12380         .f = cmd_vf_max_bw_parsed,
12381         .data = NULL,
12382         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12383         .tokens = {
12384                 (void *)&cmd_vf_tc_bw_set,
12385                 (void *)&cmd_vf_tc_bw_vf,
12386                 (void *)&cmd_vf_tc_bw_tx,
12387                 (void *)&cmd_vf_tc_bw_max_bw,
12388                 (void *)&cmd_vf_tc_bw_port_id,
12389                 (void *)&cmd_vf_tc_bw_vf_id,
12390                 (void *)&cmd_vf_tc_bw_bw,
12391                 NULL,
12392         },
12393 };
12394
12395 static int
12396 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12397                            uint8_t *tc_num,
12398                            char *str)
12399 {
12400         uint32_t size;
12401         const char *p, *p0 = str;
12402         char s[256];
12403         char *end;
12404         char *str_fld[16];
12405         uint16_t i;
12406         int ret;
12407
12408         p = strchr(p0, '(');
12409         if (p == NULL) {
12410                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12411                 return -1;
12412         }
12413         p++;
12414         p0 = strchr(p, ')');
12415         if (p0 == NULL) {
12416                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12417                 return -1;
12418         }
12419         size = p0 - p;
12420         if (size >= sizeof(s)) {
12421                 printf("The string size exceeds the internal buffer size\n");
12422                 return -1;
12423         }
12424         snprintf(s, sizeof(s), "%.*s", size, p);
12425         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12426         if (ret <= 0) {
12427                 printf("Failed to get the bandwidth list. ");
12428                 return -1;
12429         }
12430         *tc_num = ret;
12431         for (i = 0; i < ret; i++)
12432                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12433
12434         return 0;
12435 }
12436
12437 /* TC min bandwidth setting */
12438 static void
12439 cmd_vf_tc_min_bw_parsed(
12440         void *parsed_result,
12441         __rte_unused struct cmdline *cl,
12442         __rte_unused void *data)
12443 {
12444         struct cmd_vf_tc_bw_result *res = parsed_result;
12445         uint8_t tc_num;
12446         uint8_t bw[16];
12447         int ret = -ENOTSUP;
12448
12449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12450                 return;
12451
12452         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12453         if (ret)
12454                 return;
12455
12456 #ifdef RTE_NET_I40E
12457         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12458                                               tc_num, bw);
12459 #endif
12460
12461         switch (ret) {
12462         case 0:
12463                 break;
12464         case -EINVAL:
12465                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12466                 break;
12467         case -ENODEV:
12468                 printf("invalid port_id %d\n", res->port_id);
12469                 break;
12470         case -ENOTSUP:
12471                 printf("function not implemented\n");
12472                 break;
12473         default:
12474                 printf("programming error: (%s)\n", strerror(-ret));
12475         }
12476 }
12477
12478 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12479         .f = cmd_vf_tc_min_bw_parsed,
12480         .data = NULL,
12481         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12482                     " <bw1, bw2, ...>",
12483         .tokens = {
12484                 (void *)&cmd_vf_tc_bw_set,
12485                 (void *)&cmd_vf_tc_bw_vf,
12486                 (void *)&cmd_vf_tc_bw_tc,
12487                 (void *)&cmd_vf_tc_bw_tx,
12488                 (void *)&cmd_vf_tc_bw_min_bw,
12489                 (void *)&cmd_vf_tc_bw_port_id,
12490                 (void *)&cmd_vf_tc_bw_vf_id,
12491                 (void *)&cmd_vf_tc_bw_bw_list,
12492                 NULL,
12493         },
12494 };
12495
12496 static void
12497 cmd_tc_min_bw_parsed(
12498         void *parsed_result,
12499         __rte_unused struct cmdline *cl,
12500         __rte_unused void *data)
12501 {
12502         struct cmd_vf_tc_bw_result *res = parsed_result;
12503         struct rte_port *port;
12504         uint8_t tc_num;
12505         uint8_t bw[16];
12506         int ret = -ENOTSUP;
12507
12508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12509                 return;
12510
12511         port = &ports[res->port_id];
12512         /** Check if the port is not started **/
12513         if (port->port_status != RTE_PORT_STOPPED) {
12514                 printf("Please stop port %d first\n", res->port_id);
12515                 return;
12516         }
12517
12518         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12519         if (ret)
12520                 return;
12521
12522 #ifdef RTE_NET_IXGBE
12523         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12524 #endif
12525
12526         switch (ret) {
12527         case 0:
12528                 break;
12529         case -EINVAL:
12530                 printf("invalid bandwidth\n");
12531                 break;
12532         case -ENODEV:
12533                 printf("invalid port_id %d\n", res->port_id);
12534                 break;
12535         case -ENOTSUP:
12536                 printf("function not implemented\n");
12537                 break;
12538         default:
12539                 printf("programming error: (%s)\n", strerror(-ret));
12540         }
12541 }
12542
12543 cmdline_parse_inst_t cmd_tc_min_bw = {
12544         .f = cmd_tc_min_bw_parsed,
12545         .data = NULL,
12546         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12547         .tokens = {
12548                 (void *)&cmd_vf_tc_bw_set,
12549                 (void *)&cmd_vf_tc_bw_tc,
12550                 (void *)&cmd_vf_tc_bw_tx,
12551                 (void *)&cmd_vf_tc_bw_min_bw,
12552                 (void *)&cmd_vf_tc_bw_port_id,
12553                 (void *)&cmd_vf_tc_bw_bw_list,
12554                 NULL,
12555         },
12556 };
12557
12558 /* TC max bandwidth setting */
12559 static void
12560 cmd_vf_tc_max_bw_parsed(
12561         void *parsed_result,
12562         __rte_unused struct cmdline *cl,
12563         __rte_unused void *data)
12564 {
12565         struct cmd_vf_tc_bw_result *res = parsed_result;
12566         int ret = -ENOTSUP;
12567
12568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12569                 return;
12570
12571 #ifdef RTE_NET_I40E
12572         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12573                                             res->tc_no, res->bw);
12574 #endif
12575
12576         switch (ret) {
12577         case 0:
12578                 break;
12579         case -EINVAL:
12580                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12581                        res->vf_id, res->tc_no, res->bw);
12582                 break;
12583         case -ENODEV:
12584                 printf("invalid port_id %d\n", res->port_id);
12585                 break;
12586         case -ENOTSUP:
12587                 printf("function not implemented\n");
12588                 break;
12589         default:
12590                 printf("programming error: (%s)\n", strerror(-ret));
12591         }
12592 }
12593
12594 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12595         .f = cmd_vf_tc_max_bw_parsed,
12596         .data = NULL,
12597         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12598                     " <bandwidth>",
12599         .tokens = {
12600                 (void *)&cmd_vf_tc_bw_set,
12601                 (void *)&cmd_vf_tc_bw_vf,
12602                 (void *)&cmd_vf_tc_bw_tc,
12603                 (void *)&cmd_vf_tc_bw_tx,
12604                 (void *)&cmd_vf_tc_bw_max_bw,
12605                 (void *)&cmd_vf_tc_bw_port_id,
12606                 (void *)&cmd_vf_tc_bw_vf_id,
12607                 (void *)&cmd_vf_tc_bw_tc_no,
12608                 (void *)&cmd_vf_tc_bw_bw,
12609                 NULL,
12610         },
12611 };
12612
12613 /** Set VXLAN encapsulation details */
12614 struct cmd_set_vxlan_result {
12615         cmdline_fixed_string_t set;
12616         cmdline_fixed_string_t vxlan;
12617         cmdline_fixed_string_t pos_token;
12618         cmdline_fixed_string_t ip_version;
12619         uint32_t vlan_present:1;
12620         uint32_t vni;
12621         uint16_t udp_src;
12622         uint16_t udp_dst;
12623         cmdline_ipaddr_t ip_src;
12624         cmdline_ipaddr_t ip_dst;
12625         uint16_t tci;
12626         uint8_t tos;
12627         uint8_t ttl;
12628         struct rte_ether_addr eth_src;
12629         struct rte_ether_addr eth_dst;
12630 };
12631
12632 cmdline_parse_token_string_t cmd_set_vxlan_set =
12633         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12634 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12635         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12636 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12637         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12638                                  "vxlan-tos-ttl");
12639 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12640         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12641                                  "vxlan-with-vlan");
12642 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12643         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12644                                  "ip-version");
12645 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12646         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12647                                  "ipv4#ipv6");
12648 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12649         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12650                                  "vni");
12651 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12652         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12653 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12654         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12655                                  "udp-src");
12656 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12657         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12658 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12659         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12660                                  "udp-dst");
12661 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12662         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12663 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12664         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12665                                  "ip-tos");
12666 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12667         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12668 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12669         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12670                                  "ip-ttl");
12671 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12672         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12673 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12674         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12675                                  "ip-src");
12676 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12677         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12678 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12679         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12680                                  "ip-dst");
12681 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12682         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12683 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12684         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12685                                  "vlan-tci");
12686 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12687         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12688 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12689         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12690                                  "eth-src");
12691 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12692         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12693 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12694         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12695                                  "eth-dst");
12696 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12697         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12698
12699 static void cmd_set_vxlan_parsed(void *parsed_result,
12700         __rte_unused struct cmdline *cl,
12701         __rte_unused void *data)
12702 {
12703         struct cmd_set_vxlan_result *res = parsed_result;
12704         union {
12705                 uint32_t vxlan_id;
12706                 uint8_t vni[4];
12707         } id = {
12708                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12709         };
12710
12711         vxlan_encap_conf.select_tos_ttl = 0;
12712         if (strcmp(res->vxlan, "vxlan") == 0)
12713                 vxlan_encap_conf.select_vlan = 0;
12714         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12715                 vxlan_encap_conf.select_vlan = 1;
12716         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12717                 vxlan_encap_conf.select_vlan = 0;
12718                 vxlan_encap_conf.select_tos_ttl = 1;
12719         }
12720         if (strcmp(res->ip_version, "ipv4") == 0)
12721                 vxlan_encap_conf.select_ipv4 = 1;
12722         else if (strcmp(res->ip_version, "ipv6") == 0)
12723                 vxlan_encap_conf.select_ipv4 = 0;
12724         else
12725                 return;
12726         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12727         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12728         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12729         vxlan_encap_conf.ip_tos = res->tos;
12730         vxlan_encap_conf.ip_ttl = res->ttl;
12731         if (vxlan_encap_conf.select_ipv4) {
12732                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12733                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12734         } else {
12735                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12736                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12737         }
12738         if (vxlan_encap_conf.select_vlan)
12739                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12740         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12741                    RTE_ETHER_ADDR_LEN);
12742         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12743                    RTE_ETHER_ADDR_LEN);
12744 }
12745
12746 cmdline_parse_inst_t cmd_set_vxlan = {
12747         .f = cmd_set_vxlan_parsed,
12748         .data = NULL,
12749         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12750                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12751                 " eth-src <eth-src> eth-dst <eth-dst>",
12752         .tokens = {
12753                 (void *)&cmd_set_vxlan_set,
12754                 (void *)&cmd_set_vxlan_vxlan,
12755                 (void *)&cmd_set_vxlan_ip_version,
12756                 (void *)&cmd_set_vxlan_ip_version_value,
12757                 (void *)&cmd_set_vxlan_vni,
12758                 (void *)&cmd_set_vxlan_vni_value,
12759                 (void *)&cmd_set_vxlan_udp_src,
12760                 (void *)&cmd_set_vxlan_udp_src_value,
12761                 (void *)&cmd_set_vxlan_udp_dst,
12762                 (void *)&cmd_set_vxlan_udp_dst_value,
12763                 (void *)&cmd_set_vxlan_ip_src,
12764                 (void *)&cmd_set_vxlan_ip_src_value,
12765                 (void *)&cmd_set_vxlan_ip_dst,
12766                 (void *)&cmd_set_vxlan_ip_dst_value,
12767                 (void *)&cmd_set_vxlan_eth_src,
12768                 (void *)&cmd_set_vxlan_eth_src_value,
12769                 (void *)&cmd_set_vxlan_eth_dst,
12770                 (void *)&cmd_set_vxlan_eth_dst_value,
12771                 NULL,
12772         },
12773 };
12774
12775 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12776         .f = cmd_set_vxlan_parsed,
12777         .data = NULL,
12778         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12779                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12780                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12781                 " eth-dst <eth-dst>",
12782         .tokens = {
12783                 (void *)&cmd_set_vxlan_set,
12784                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12785                 (void *)&cmd_set_vxlan_ip_version,
12786                 (void *)&cmd_set_vxlan_ip_version_value,
12787                 (void *)&cmd_set_vxlan_vni,
12788                 (void *)&cmd_set_vxlan_vni_value,
12789                 (void *)&cmd_set_vxlan_udp_src,
12790                 (void *)&cmd_set_vxlan_udp_src_value,
12791                 (void *)&cmd_set_vxlan_udp_dst,
12792                 (void *)&cmd_set_vxlan_udp_dst_value,
12793                 (void *)&cmd_set_vxlan_ip_tos,
12794                 (void *)&cmd_set_vxlan_ip_tos_value,
12795                 (void *)&cmd_set_vxlan_ip_ttl,
12796                 (void *)&cmd_set_vxlan_ip_ttl_value,
12797                 (void *)&cmd_set_vxlan_ip_src,
12798                 (void *)&cmd_set_vxlan_ip_src_value,
12799                 (void *)&cmd_set_vxlan_ip_dst,
12800                 (void *)&cmd_set_vxlan_ip_dst_value,
12801                 (void *)&cmd_set_vxlan_eth_src,
12802                 (void *)&cmd_set_vxlan_eth_src_value,
12803                 (void *)&cmd_set_vxlan_eth_dst,
12804                 (void *)&cmd_set_vxlan_eth_dst_value,
12805                 NULL,
12806         },
12807 };
12808
12809 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12810         .f = cmd_set_vxlan_parsed,
12811         .data = NULL,
12812         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12813                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12814                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12815                 " <eth-dst>",
12816         .tokens = {
12817                 (void *)&cmd_set_vxlan_set,
12818                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12819                 (void *)&cmd_set_vxlan_ip_version,
12820                 (void *)&cmd_set_vxlan_ip_version_value,
12821                 (void *)&cmd_set_vxlan_vni,
12822                 (void *)&cmd_set_vxlan_vni_value,
12823                 (void *)&cmd_set_vxlan_udp_src,
12824                 (void *)&cmd_set_vxlan_udp_src_value,
12825                 (void *)&cmd_set_vxlan_udp_dst,
12826                 (void *)&cmd_set_vxlan_udp_dst_value,
12827                 (void *)&cmd_set_vxlan_ip_src,
12828                 (void *)&cmd_set_vxlan_ip_src_value,
12829                 (void *)&cmd_set_vxlan_ip_dst,
12830                 (void *)&cmd_set_vxlan_ip_dst_value,
12831                 (void *)&cmd_set_vxlan_vlan,
12832                 (void *)&cmd_set_vxlan_vlan_value,
12833                 (void *)&cmd_set_vxlan_eth_src,
12834                 (void *)&cmd_set_vxlan_eth_src_value,
12835                 (void *)&cmd_set_vxlan_eth_dst,
12836                 (void *)&cmd_set_vxlan_eth_dst_value,
12837                 NULL,
12838         },
12839 };
12840
12841 /** Set NVGRE encapsulation details */
12842 struct cmd_set_nvgre_result {
12843         cmdline_fixed_string_t set;
12844         cmdline_fixed_string_t nvgre;
12845         cmdline_fixed_string_t pos_token;
12846         cmdline_fixed_string_t ip_version;
12847         uint32_t tni;
12848         cmdline_ipaddr_t ip_src;
12849         cmdline_ipaddr_t ip_dst;
12850         uint16_t tci;
12851         struct rte_ether_addr eth_src;
12852         struct rte_ether_addr eth_dst;
12853 };
12854
12855 cmdline_parse_token_string_t cmd_set_nvgre_set =
12856         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12857 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12858         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12859 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12860         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12861                                  "nvgre-with-vlan");
12862 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12863         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12864                                  "ip-version");
12865 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12866         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12867                                  "ipv4#ipv6");
12868 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12869         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12870                                  "tni");
12871 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12872         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12873 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12874         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12875                                  "ip-src");
12876 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12877         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12878 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12879         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12880                                  "ip-dst");
12881 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12882         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12883 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12884         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12885                                  "vlan-tci");
12886 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12887         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12888 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12889         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12890                                  "eth-src");
12891 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12892         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12893 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12894         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12895                                  "eth-dst");
12896 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12897         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12898
12899 static void cmd_set_nvgre_parsed(void *parsed_result,
12900         __rte_unused struct cmdline *cl,
12901         __rte_unused void *data)
12902 {
12903         struct cmd_set_nvgre_result *res = parsed_result;
12904         union {
12905                 uint32_t nvgre_tni;
12906                 uint8_t tni[4];
12907         } id = {
12908                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12909         };
12910
12911         if (strcmp(res->nvgre, "nvgre") == 0)
12912                 nvgre_encap_conf.select_vlan = 0;
12913         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12914                 nvgre_encap_conf.select_vlan = 1;
12915         if (strcmp(res->ip_version, "ipv4") == 0)
12916                 nvgre_encap_conf.select_ipv4 = 1;
12917         else if (strcmp(res->ip_version, "ipv6") == 0)
12918                 nvgre_encap_conf.select_ipv4 = 0;
12919         else
12920                 return;
12921         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12922         if (nvgre_encap_conf.select_ipv4) {
12923                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12924                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12925         } else {
12926                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12927                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12928         }
12929         if (nvgre_encap_conf.select_vlan)
12930                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12931         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12932                    RTE_ETHER_ADDR_LEN);
12933         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12934                    RTE_ETHER_ADDR_LEN);
12935 }
12936
12937 cmdline_parse_inst_t cmd_set_nvgre = {
12938         .f = cmd_set_nvgre_parsed,
12939         .data = NULL,
12940         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12941                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12942                 " eth-dst <eth-dst>",
12943         .tokens = {
12944                 (void *)&cmd_set_nvgre_set,
12945                 (void *)&cmd_set_nvgre_nvgre,
12946                 (void *)&cmd_set_nvgre_ip_version,
12947                 (void *)&cmd_set_nvgre_ip_version_value,
12948                 (void *)&cmd_set_nvgre_tni,
12949                 (void *)&cmd_set_nvgre_tni_value,
12950                 (void *)&cmd_set_nvgre_ip_src,
12951                 (void *)&cmd_set_nvgre_ip_src_value,
12952                 (void *)&cmd_set_nvgre_ip_dst,
12953                 (void *)&cmd_set_nvgre_ip_dst_value,
12954                 (void *)&cmd_set_nvgre_eth_src,
12955                 (void *)&cmd_set_nvgre_eth_src_value,
12956                 (void *)&cmd_set_nvgre_eth_dst,
12957                 (void *)&cmd_set_nvgre_eth_dst_value,
12958                 NULL,
12959         },
12960 };
12961
12962 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12963         .f = cmd_set_nvgre_parsed,
12964         .data = NULL,
12965         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12966                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12967                 " eth-src <eth-src> eth-dst <eth-dst>",
12968         .tokens = {
12969                 (void *)&cmd_set_nvgre_set,
12970                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12971                 (void *)&cmd_set_nvgre_ip_version,
12972                 (void *)&cmd_set_nvgre_ip_version_value,
12973                 (void *)&cmd_set_nvgre_tni,
12974                 (void *)&cmd_set_nvgre_tni_value,
12975                 (void *)&cmd_set_nvgre_ip_src,
12976                 (void *)&cmd_set_nvgre_ip_src_value,
12977                 (void *)&cmd_set_nvgre_ip_dst,
12978                 (void *)&cmd_set_nvgre_ip_dst_value,
12979                 (void *)&cmd_set_nvgre_vlan,
12980                 (void *)&cmd_set_nvgre_vlan_value,
12981                 (void *)&cmd_set_nvgre_eth_src,
12982                 (void *)&cmd_set_nvgre_eth_src_value,
12983                 (void *)&cmd_set_nvgre_eth_dst,
12984                 (void *)&cmd_set_nvgre_eth_dst_value,
12985                 NULL,
12986         },
12987 };
12988
12989 /** Set L2 encapsulation details */
12990 struct cmd_set_l2_encap_result {
12991         cmdline_fixed_string_t set;
12992         cmdline_fixed_string_t l2_encap;
12993         cmdline_fixed_string_t pos_token;
12994         cmdline_fixed_string_t ip_version;
12995         uint32_t vlan_present:1;
12996         uint16_t tci;
12997         struct rte_ether_addr eth_src;
12998         struct rte_ether_addr eth_dst;
12999 };
13000
13001 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13002         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13003 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13004         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13005 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13006         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13007                                  "l2_encap-with-vlan");
13008 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13009         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13010                                  "ip-version");
13011 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13012         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13013                                  "ipv4#ipv6");
13014 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13015         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13016                                  "vlan-tci");
13017 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13018         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13019 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13020         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13021                                  "eth-src");
13022 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13023         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13024 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13025         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13026                                  "eth-dst");
13027 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13028         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13029
13030 static void cmd_set_l2_encap_parsed(void *parsed_result,
13031         __rte_unused struct cmdline *cl,
13032         __rte_unused void *data)
13033 {
13034         struct cmd_set_l2_encap_result *res = parsed_result;
13035
13036         if (strcmp(res->l2_encap, "l2_encap") == 0)
13037                 l2_encap_conf.select_vlan = 0;
13038         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13039                 l2_encap_conf.select_vlan = 1;
13040         if (strcmp(res->ip_version, "ipv4") == 0)
13041                 l2_encap_conf.select_ipv4 = 1;
13042         else if (strcmp(res->ip_version, "ipv6") == 0)
13043                 l2_encap_conf.select_ipv4 = 0;
13044         else
13045                 return;
13046         if (l2_encap_conf.select_vlan)
13047                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13048         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13049                    RTE_ETHER_ADDR_LEN);
13050         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13051                    RTE_ETHER_ADDR_LEN);
13052 }
13053
13054 cmdline_parse_inst_t cmd_set_l2_encap = {
13055         .f = cmd_set_l2_encap_parsed,
13056         .data = NULL,
13057         .help_str = "set l2_encap ip-version ipv4|ipv6"
13058                 " eth-src <eth-src> eth-dst <eth-dst>",
13059         .tokens = {
13060                 (void *)&cmd_set_l2_encap_set,
13061                 (void *)&cmd_set_l2_encap_l2_encap,
13062                 (void *)&cmd_set_l2_encap_ip_version,
13063                 (void *)&cmd_set_l2_encap_ip_version_value,
13064                 (void *)&cmd_set_l2_encap_eth_src,
13065                 (void *)&cmd_set_l2_encap_eth_src_value,
13066                 (void *)&cmd_set_l2_encap_eth_dst,
13067                 (void *)&cmd_set_l2_encap_eth_dst_value,
13068                 NULL,
13069         },
13070 };
13071
13072 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13073         .f = cmd_set_l2_encap_parsed,
13074         .data = NULL,
13075         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13076                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13077         .tokens = {
13078                 (void *)&cmd_set_l2_encap_set,
13079                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13080                 (void *)&cmd_set_l2_encap_ip_version,
13081                 (void *)&cmd_set_l2_encap_ip_version_value,
13082                 (void *)&cmd_set_l2_encap_vlan,
13083                 (void *)&cmd_set_l2_encap_vlan_value,
13084                 (void *)&cmd_set_l2_encap_eth_src,
13085                 (void *)&cmd_set_l2_encap_eth_src_value,
13086                 (void *)&cmd_set_l2_encap_eth_dst,
13087                 (void *)&cmd_set_l2_encap_eth_dst_value,
13088                 NULL,
13089         },
13090 };
13091
13092 /** Set L2 decapsulation details */
13093 struct cmd_set_l2_decap_result {
13094         cmdline_fixed_string_t set;
13095         cmdline_fixed_string_t l2_decap;
13096         cmdline_fixed_string_t pos_token;
13097         uint32_t vlan_present:1;
13098 };
13099
13100 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13101         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13102 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13103         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13104                                  "l2_decap");
13105 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13106         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13107                                  "l2_decap-with-vlan");
13108
13109 static void cmd_set_l2_decap_parsed(void *parsed_result,
13110         __rte_unused struct cmdline *cl,
13111         __rte_unused void *data)
13112 {
13113         struct cmd_set_l2_decap_result *res = parsed_result;
13114
13115         if (strcmp(res->l2_decap, "l2_decap") == 0)
13116                 l2_decap_conf.select_vlan = 0;
13117         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13118                 l2_decap_conf.select_vlan = 1;
13119 }
13120
13121 cmdline_parse_inst_t cmd_set_l2_decap = {
13122         .f = cmd_set_l2_decap_parsed,
13123         .data = NULL,
13124         .help_str = "set l2_decap",
13125         .tokens = {
13126                 (void *)&cmd_set_l2_decap_set,
13127                 (void *)&cmd_set_l2_decap_l2_decap,
13128                 NULL,
13129         },
13130 };
13131
13132 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13133         .f = cmd_set_l2_decap_parsed,
13134         .data = NULL,
13135         .help_str = "set l2_decap-with-vlan",
13136         .tokens = {
13137                 (void *)&cmd_set_l2_decap_set,
13138                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13139                 NULL,
13140         },
13141 };
13142
13143 /** Set MPLSoGRE encapsulation details */
13144 struct cmd_set_mplsogre_encap_result {
13145         cmdline_fixed_string_t set;
13146         cmdline_fixed_string_t mplsogre;
13147         cmdline_fixed_string_t pos_token;
13148         cmdline_fixed_string_t ip_version;
13149         uint32_t vlan_present:1;
13150         uint32_t label;
13151         cmdline_ipaddr_t ip_src;
13152         cmdline_ipaddr_t ip_dst;
13153         uint16_t tci;
13154         struct rte_ether_addr eth_src;
13155         struct rte_ether_addr eth_dst;
13156 };
13157
13158 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13159         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13160                                  "set");
13161 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13162         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13163                                  "mplsogre_encap");
13164 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13165         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13166                                  mplsogre, "mplsogre_encap-with-vlan");
13167 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13168         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13169                                  pos_token, "ip-version");
13170 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13171         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13172                                  ip_version, "ipv4#ipv6");
13173 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13174         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13175                                  pos_token, "label");
13176 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13177         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13178                               RTE_UINT32);
13179 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13180         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13181                                  pos_token, "ip-src");
13182 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13183         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13184 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13185         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13186                                  pos_token, "ip-dst");
13187 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13188         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13189 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13191                                  pos_token, "vlan-tci");
13192 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13193         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13194                               RTE_UINT16);
13195 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13197                                  pos_token, "eth-src");
13198 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13199         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13200                                     eth_src);
13201 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13203                                  pos_token, "eth-dst");
13204 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13205         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13206                                     eth_dst);
13207
13208 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13209         __rte_unused struct cmdline *cl,
13210         __rte_unused void *data)
13211 {
13212         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13213         union {
13214                 uint32_t mplsogre_label;
13215                 uint8_t label[4];
13216         } id = {
13217                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13218         };
13219
13220         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13221                 mplsogre_encap_conf.select_vlan = 0;
13222         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13223                 mplsogre_encap_conf.select_vlan = 1;
13224         if (strcmp(res->ip_version, "ipv4") == 0)
13225                 mplsogre_encap_conf.select_ipv4 = 1;
13226         else if (strcmp(res->ip_version, "ipv6") == 0)
13227                 mplsogre_encap_conf.select_ipv4 = 0;
13228         else
13229                 return;
13230         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13231         if (mplsogre_encap_conf.select_ipv4) {
13232                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13233                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13234         } else {
13235                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13236                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13237         }
13238         if (mplsogre_encap_conf.select_vlan)
13239                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13240         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13241                    RTE_ETHER_ADDR_LEN);
13242         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13243                    RTE_ETHER_ADDR_LEN);
13244 }
13245
13246 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13247         .f = cmd_set_mplsogre_encap_parsed,
13248         .data = NULL,
13249         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13250                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13251                 " eth-dst <eth-dst>",
13252         .tokens = {
13253                 (void *)&cmd_set_mplsogre_encap_set,
13254                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13255                 (void *)&cmd_set_mplsogre_encap_ip_version,
13256                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13257                 (void *)&cmd_set_mplsogre_encap_label,
13258                 (void *)&cmd_set_mplsogre_encap_label_value,
13259                 (void *)&cmd_set_mplsogre_encap_ip_src,
13260                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13261                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13262                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13263                 (void *)&cmd_set_mplsogre_encap_eth_src,
13264                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13265                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13266                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13267                 NULL,
13268         },
13269 };
13270
13271 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13272         .f = cmd_set_mplsogre_encap_parsed,
13273         .data = NULL,
13274         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13275                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13276                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13277         .tokens = {
13278                 (void *)&cmd_set_mplsogre_encap_set,
13279                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13280                 (void *)&cmd_set_mplsogre_encap_ip_version,
13281                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13282                 (void *)&cmd_set_mplsogre_encap_label,
13283                 (void *)&cmd_set_mplsogre_encap_label_value,
13284                 (void *)&cmd_set_mplsogre_encap_ip_src,
13285                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13286                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13287                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13288                 (void *)&cmd_set_mplsogre_encap_vlan,
13289                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13290                 (void *)&cmd_set_mplsogre_encap_eth_src,
13291                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13292                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13293                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13294                 NULL,
13295         },
13296 };
13297
13298 /** Set MPLSoGRE decapsulation details */
13299 struct cmd_set_mplsogre_decap_result {
13300         cmdline_fixed_string_t set;
13301         cmdline_fixed_string_t mplsogre;
13302         cmdline_fixed_string_t pos_token;
13303         cmdline_fixed_string_t ip_version;
13304         uint32_t vlan_present:1;
13305 };
13306
13307 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13308         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13309                                  "set");
13310 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13311         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13312                                  "mplsogre_decap");
13313 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13314         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13315                                  mplsogre, "mplsogre_decap-with-vlan");
13316 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13317         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13318                                  pos_token, "ip-version");
13319 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13320         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13321                                  ip_version, "ipv4#ipv6");
13322
13323 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13324         __rte_unused struct cmdline *cl,
13325         __rte_unused void *data)
13326 {
13327         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13328
13329         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13330                 mplsogre_decap_conf.select_vlan = 0;
13331         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13332                 mplsogre_decap_conf.select_vlan = 1;
13333         if (strcmp(res->ip_version, "ipv4") == 0)
13334                 mplsogre_decap_conf.select_ipv4 = 1;
13335         else if (strcmp(res->ip_version, "ipv6") == 0)
13336                 mplsogre_decap_conf.select_ipv4 = 0;
13337 }
13338
13339 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13340         .f = cmd_set_mplsogre_decap_parsed,
13341         .data = NULL,
13342         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13343         .tokens = {
13344                 (void *)&cmd_set_mplsogre_decap_set,
13345                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13346                 (void *)&cmd_set_mplsogre_decap_ip_version,
13347                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13348                 NULL,
13349         },
13350 };
13351
13352 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13353         .f = cmd_set_mplsogre_decap_parsed,
13354         .data = NULL,
13355         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13356         .tokens = {
13357                 (void *)&cmd_set_mplsogre_decap_set,
13358                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13359                 (void *)&cmd_set_mplsogre_decap_ip_version,
13360                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13361                 NULL,
13362         },
13363 };
13364
13365 /** Set MPLSoUDP encapsulation details */
13366 struct cmd_set_mplsoudp_encap_result {
13367         cmdline_fixed_string_t set;
13368         cmdline_fixed_string_t mplsoudp;
13369         cmdline_fixed_string_t pos_token;
13370         cmdline_fixed_string_t ip_version;
13371         uint32_t vlan_present:1;
13372         uint32_t label;
13373         uint16_t udp_src;
13374         uint16_t udp_dst;
13375         cmdline_ipaddr_t ip_src;
13376         cmdline_ipaddr_t ip_dst;
13377         uint16_t tci;
13378         struct rte_ether_addr eth_src;
13379         struct rte_ether_addr eth_dst;
13380 };
13381
13382 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13383         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13384                                  "set");
13385 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13386         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13387                                  "mplsoudp_encap");
13388 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13389         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13390                                  mplsoudp, "mplsoudp_encap-with-vlan");
13391 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13392         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13393                                  pos_token, "ip-version");
13394 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13395         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13396                                  ip_version, "ipv4#ipv6");
13397 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13398         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13399                                  pos_token, "label");
13400 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13401         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13402                               RTE_UINT32);
13403 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13404         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13405                                  pos_token, "udp-src");
13406 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13407         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13408                               RTE_UINT16);
13409 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13410         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13411                                  pos_token, "udp-dst");
13412 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13413         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13414                               RTE_UINT16);
13415 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13416         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13417                                  pos_token, "ip-src");
13418 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13419         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13420 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13421         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13422                                  pos_token, "ip-dst");
13423 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13424         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13425 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13426         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13427                                  pos_token, "vlan-tci");
13428 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13429         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13430                               RTE_UINT16);
13431 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13432         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13433                                  pos_token, "eth-src");
13434 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13435         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13436                                     eth_src);
13437 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13438         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13439                                  pos_token, "eth-dst");
13440 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13441         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13442                                     eth_dst);
13443
13444 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13445         __rte_unused struct cmdline *cl,
13446         __rte_unused void *data)
13447 {
13448         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13449         union {
13450                 uint32_t mplsoudp_label;
13451                 uint8_t label[4];
13452         } id = {
13453                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13454         };
13455
13456         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13457                 mplsoudp_encap_conf.select_vlan = 0;
13458         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13459                 mplsoudp_encap_conf.select_vlan = 1;
13460         if (strcmp(res->ip_version, "ipv4") == 0)
13461                 mplsoudp_encap_conf.select_ipv4 = 1;
13462         else if (strcmp(res->ip_version, "ipv6") == 0)
13463                 mplsoudp_encap_conf.select_ipv4 = 0;
13464         else
13465                 return;
13466         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13467         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13468         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13469         if (mplsoudp_encap_conf.select_ipv4) {
13470                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13471                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13472         } else {
13473                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13474                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13475         }
13476         if (mplsoudp_encap_conf.select_vlan)
13477                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13478         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13479                    RTE_ETHER_ADDR_LEN);
13480         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13481                    RTE_ETHER_ADDR_LEN);
13482 }
13483
13484 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13485         .f = cmd_set_mplsoudp_encap_parsed,
13486         .data = NULL,
13487         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13488                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13489                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13490         .tokens = {
13491                 (void *)&cmd_set_mplsoudp_encap_set,
13492                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13493                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13494                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13495                 (void *)&cmd_set_mplsoudp_encap_label,
13496                 (void *)&cmd_set_mplsoudp_encap_label_value,
13497                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13498                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13499                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13500                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13501                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13502                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13503                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13504                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13505                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13506                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13507                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13508                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13509                 NULL,
13510         },
13511 };
13512
13513 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13514         .f = cmd_set_mplsoudp_encap_parsed,
13515         .data = NULL,
13516         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13517                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13518                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13519                 " eth-src <eth-src> eth-dst <eth-dst>",
13520         .tokens = {
13521                 (void *)&cmd_set_mplsoudp_encap_set,
13522                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13523                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13524                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13525                 (void *)&cmd_set_mplsoudp_encap_label,
13526                 (void *)&cmd_set_mplsoudp_encap_label_value,
13527                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13528                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13529                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13530                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13531                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13532                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13533                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13534                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13535                 (void *)&cmd_set_mplsoudp_encap_vlan,
13536                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13537                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13538                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13539                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13540                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13541                 NULL,
13542         },
13543 };
13544
13545 /** Set MPLSoUDP decapsulation details */
13546 struct cmd_set_mplsoudp_decap_result {
13547         cmdline_fixed_string_t set;
13548         cmdline_fixed_string_t mplsoudp;
13549         cmdline_fixed_string_t pos_token;
13550         cmdline_fixed_string_t ip_version;
13551         uint32_t vlan_present:1;
13552 };
13553
13554 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13555         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13556                                  "set");
13557 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13558         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13559                                  "mplsoudp_decap");
13560 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13561         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13562                                  mplsoudp, "mplsoudp_decap-with-vlan");
13563 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13564         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13565                                  pos_token, "ip-version");
13566 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13567         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13568                                  ip_version, "ipv4#ipv6");
13569
13570 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13571         __rte_unused struct cmdline *cl,
13572         __rte_unused void *data)
13573 {
13574         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13575
13576         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13577                 mplsoudp_decap_conf.select_vlan = 0;
13578         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13579                 mplsoudp_decap_conf.select_vlan = 1;
13580         if (strcmp(res->ip_version, "ipv4") == 0)
13581                 mplsoudp_decap_conf.select_ipv4 = 1;
13582         else if (strcmp(res->ip_version, "ipv6") == 0)
13583                 mplsoudp_decap_conf.select_ipv4 = 0;
13584 }
13585
13586 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13587         .f = cmd_set_mplsoudp_decap_parsed,
13588         .data = NULL,
13589         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13590         .tokens = {
13591                 (void *)&cmd_set_mplsoudp_decap_set,
13592                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13593                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13594                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13595                 NULL,
13596         },
13597 };
13598
13599 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13600         .f = cmd_set_mplsoudp_decap_parsed,
13601         .data = NULL,
13602         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13603         .tokens = {
13604                 (void *)&cmd_set_mplsoudp_decap_set,
13605                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13606                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13607                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13608                 NULL,
13609         },
13610 };
13611
13612 /* Strict link priority scheduling mode setting */
13613 static void
13614 cmd_strict_link_prio_parsed(
13615         void *parsed_result,
13616         __rte_unused struct cmdline *cl,
13617         __rte_unused void *data)
13618 {
13619         struct cmd_vf_tc_bw_result *res = parsed_result;
13620         int ret = -ENOTSUP;
13621
13622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13623                 return;
13624
13625 #ifdef RTE_NET_I40E
13626         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13627 #endif
13628
13629         switch (ret) {
13630         case 0:
13631                 break;
13632         case -EINVAL:
13633                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13634                 break;
13635         case -ENODEV:
13636                 printf("invalid port_id %d\n", res->port_id);
13637                 break;
13638         case -ENOTSUP:
13639                 printf("function not implemented\n");
13640                 break;
13641         default:
13642                 printf("programming error: (%s)\n", strerror(-ret));
13643         }
13644 }
13645
13646 cmdline_parse_inst_t cmd_strict_link_prio = {
13647         .f = cmd_strict_link_prio_parsed,
13648         .data = NULL,
13649         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13650         .tokens = {
13651                 (void *)&cmd_vf_tc_bw_set,
13652                 (void *)&cmd_vf_tc_bw_tx,
13653                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13654                 (void *)&cmd_vf_tc_bw_port_id,
13655                 (void *)&cmd_vf_tc_bw_tc_map,
13656                 NULL,
13657         },
13658 };
13659
13660 /* Load dynamic device personalization*/
13661 struct cmd_ddp_add_result {
13662         cmdline_fixed_string_t ddp;
13663         cmdline_fixed_string_t add;
13664         portid_t port_id;
13665         char filepath[];
13666 };
13667
13668 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13669         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13670 cmdline_parse_token_string_t cmd_ddp_add_add =
13671         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13672 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13673         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13674                 RTE_UINT16);
13675 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13676         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13677
13678 static void
13679 cmd_ddp_add_parsed(
13680         void *parsed_result,
13681         __rte_unused struct cmdline *cl,
13682         __rte_unused void *data)
13683 {
13684         struct cmd_ddp_add_result *res = parsed_result;
13685         uint8_t *buff;
13686         uint32_t size;
13687         char *filepath;
13688         char *file_fld[2];
13689         int file_num;
13690         int ret = -ENOTSUP;
13691
13692         if (!all_ports_stopped()) {
13693                 printf("Please stop all ports first\n");
13694                 return;
13695         }
13696
13697         filepath = strdup(res->filepath);
13698         if (filepath == NULL) {
13699                 printf("Failed to allocate memory\n");
13700                 return;
13701         }
13702         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13703
13704         buff = open_file(file_fld[0], &size);
13705         if (!buff) {
13706                 free((void *)filepath);
13707                 return;
13708         }
13709
13710 #ifdef RTE_NET_I40E
13711         if (ret == -ENOTSUP)
13712                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13713                                                buff, size,
13714                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13715 #endif
13716
13717         if (ret == -EEXIST)
13718                 printf("Profile has already existed.\n");
13719         else if (ret < 0)
13720                 printf("Failed to load profile.\n");
13721         else if (file_num == 2)
13722                 save_file(file_fld[1], buff, size);
13723
13724         close_file(buff);
13725         free((void *)filepath);
13726 }
13727
13728 cmdline_parse_inst_t cmd_ddp_add = {
13729         .f = cmd_ddp_add_parsed,
13730         .data = NULL,
13731         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13732         .tokens = {
13733                 (void *)&cmd_ddp_add_ddp,
13734                 (void *)&cmd_ddp_add_add,
13735                 (void *)&cmd_ddp_add_port_id,
13736                 (void *)&cmd_ddp_add_filepath,
13737                 NULL,
13738         },
13739 };
13740
13741 /* Delete dynamic device personalization*/
13742 struct cmd_ddp_del_result {
13743         cmdline_fixed_string_t ddp;
13744         cmdline_fixed_string_t del;
13745         portid_t port_id;
13746         char filepath[];
13747 };
13748
13749 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13750         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13751 cmdline_parse_token_string_t cmd_ddp_del_del =
13752         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13753 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13754         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13755 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13756         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13757
13758 static void
13759 cmd_ddp_del_parsed(
13760         void *parsed_result,
13761         __rte_unused struct cmdline *cl,
13762         __rte_unused void *data)
13763 {
13764         struct cmd_ddp_del_result *res = parsed_result;
13765         uint8_t *buff;
13766         uint32_t size;
13767         int ret = -ENOTSUP;
13768
13769         if (!all_ports_stopped()) {
13770                 printf("Please stop all ports first\n");
13771                 return;
13772         }
13773
13774         buff = open_file(res->filepath, &size);
13775         if (!buff)
13776                 return;
13777
13778 #ifdef RTE_NET_I40E
13779         if (ret == -ENOTSUP)
13780                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13781                                                buff, size,
13782                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13783 #endif
13784
13785         if (ret == -EACCES)
13786                 printf("Profile does not exist.\n");
13787         else if (ret < 0)
13788                 printf("Failed to delete profile.\n");
13789
13790         close_file(buff);
13791 }
13792
13793 cmdline_parse_inst_t cmd_ddp_del = {
13794         .f = cmd_ddp_del_parsed,
13795         .data = NULL,
13796         .help_str = "ddp del <port_id> <backup_profile_path>",
13797         .tokens = {
13798                 (void *)&cmd_ddp_del_ddp,
13799                 (void *)&cmd_ddp_del_del,
13800                 (void *)&cmd_ddp_del_port_id,
13801                 (void *)&cmd_ddp_del_filepath,
13802                 NULL,
13803         },
13804 };
13805
13806 /* Get dynamic device personalization profile info */
13807 struct cmd_ddp_info_result {
13808         cmdline_fixed_string_t ddp;
13809         cmdline_fixed_string_t get;
13810         cmdline_fixed_string_t info;
13811         char filepath[];
13812 };
13813
13814 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13815         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13816 cmdline_parse_token_string_t cmd_ddp_info_get =
13817         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13818 cmdline_parse_token_string_t cmd_ddp_info_info =
13819         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13820 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13821         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13822
13823 static void
13824 cmd_ddp_info_parsed(
13825         void *parsed_result,
13826         __rte_unused struct cmdline *cl,
13827         __rte_unused void *data)
13828 {
13829         struct cmd_ddp_info_result *res = parsed_result;
13830         uint8_t *pkg;
13831         uint32_t pkg_size;
13832         int ret = -ENOTSUP;
13833 #ifdef RTE_NET_I40E
13834         uint32_t i, j, n;
13835         uint8_t *buff;
13836         uint32_t buff_size = 0;
13837         struct rte_pmd_i40e_profile_info info;
13838         uint32_t dev_num = 0;
13839         struct rte_pmd_i40e_ddp_device_id *devs;
13840         uint32_t proto_num = 0;
13841         struct rte_pmd_i40e_proto_info *proto = NULL;
13842         uint32_t pctype_num = 0;
13843         struct rte_pmd_i40e_ptype_info *pctype;
13844         uint32_t ptype_num = 0;
13845         struct rte_pmd_i40e_ptype_info *ptype;
13846         uint8_t proto_id;
13847
13848 #endif
13849
13850         pkg = open_file(res->filepath, &pkg_size);
13851         if (!pkg)
13852                 return;
13853
13854 #ifdef RTE_NET_I40E
13855         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13856                                 (uint8_t *)&info, sizeof(info),
13857                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13858         if (!ret) {
13859                 printf("Global Track id:       0x%x\n", info.track_id);
13860                 printf("Global Version:        %d.%d.%d.%d\n",
13861                         info.version.major,
13862                         info.version.minor,
13863                         info.version.update,
13864                         info.version.draft);
13865                 printf("Global Package name:   %s\n\n", info.name);
13866         }
13867
13868         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13869                                 (uint8_t *)&info, sizeof(info),
13870                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13871         if (!ret) {
13872                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13873                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13874                         info.version.major,
13875                         info.version.minor,
13876                         info.version.update,
13877                         info.version.draft);
13878                 printf("i40e Profile name:     %s\n\n", info.name);
13879         }
13880
13881         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13882                                 (uint8_t *)&buff_size, sizeof(buff_size),
13883                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13884         if (!ret && buff_size) {
13885                 buff = (uint8_t *)malloc(buff_size);
13886                 if (buff) {
13887                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13888                                                 buff, buff_size,
13889                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13890                         if (!ret)
13891                                 printf("Package Notes:\n%s\n\n", buff);
13892                         free(buff);
13893                 }
13894         }
13895
13896         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13897                                 (uint8_t *)&dev_num, sizeof(dev_num),
13898                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13899         if (!ret && dev_num) {
13900                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13901                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13902                 if (devs) {
13903                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13904                                                 (uint8_t *)devs, buff_size,
13905                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13906                         if (!ret) {
13907                                 printf("List of supported devices:\n");
13908                                 for (i = 0; i < dev_num; i++) {
13909                                         printf("  %04X:%04X %04X:%04X\n",
13910                                                 devs[i].vendor_dev_id >> 16,
13911                                                 devs[i].vendor_dev_id & 0xFFFF,
13912                                                 devs[i].sub_vendor_dev_id >> 16,
13913                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13914                                 }
13915                                 printf("\n");
13916                         }
13917                         free(devs);
13918                 }
13919         }
13920
13921         /* get information about protocols and packet types */
13922         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13923                 (uint8_t *)&proto_num, sizeof(proto_num),
13924                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13925         if (ret || !proto_num)
13926                 goto no_print_return;
13927
13928         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13929         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13930         if (!proto)
13931                 goto no_print_return;
13932
13933         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13934                                         buff_size,
13935                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13936         if (!ret) {
13937                 printf("List of used protocols:\n");
13938                 for (i = 0; i < proto_num; i++)
13939                         printf("  %2u: %s\n", proto[i].proto_id,
13940                                proto[i].name);
13941                 printf("\n");
13942         }
13943         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13944                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13945                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13946         if (ret || !pctype_num)
13947                 goto no_print_pctypes;
13948
13949         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13950         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13951         if (!pctype)
13952                 goto no_print_pctypes;
13953
13954         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13955                                         buff_size,
13956                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13957         if (ret) {
13958                 free(pctype);
13959                 goto no_print_pctypes;
13960         }
13961
13962         printf("List of defined packet classification types:\n");
13963         for (i = 0; i < pctype_num; i++) {
13964                 printf("  %2u:", pctype[i].ptype_id);
13965                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13966                         proto_id = pctype[i].protocols[j];
13967                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13968                                 for (n = 0; n < proto_num; n++) {
13969                                         if (proto[n].proto_id == proto_id) {
13970                                                 printf(" %s", proto[n].name);
13971                                                 break;
13972                                         }
13973                                 }
13974                         }
13975                 }
13976                 printf("\n");
13977         }
13978         printf("\n");
13979         free(pctype);
13980
13981 no_print_pctypes:
13982
13983         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13984                                         sizeof(ptype_num),
13985                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13986         if (ret || !ptype_num)
13987                 goto no_print_return;
13988
13989         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13990         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13991         if (!ptype)
13992                 goto no_print_return;
13993
13994         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13995                                         buff_size,
13996                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13997         if (ret) {
13998                 free(ptype);
13999                 goto no_print_return;
14000         }
14001         printf("List of defined packet types:\n");
14002         for (i = 0; i < ptype_num; i++) {
14003                 printf("  %2u:", ptype[i].ptype_id);
14004                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14005                         proto_id = ptype[i].protocols[j];
14006                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14007                                 for (n = 0; n < proto_num; n++) {
14008                                         if (proto[n].proto_id == proto_id) {
14009                                                 printf(" %s", proto[n].name);
14010                                                 break;
14011                                         }
14012                                 }
14013                         }
14014                 }
14015                 printf("\n");
14016         }
14017         free(ptype);
14018         printf("\n");
14019
14020         ret = 0;
14021 no_print_return:
14022         if (proto)
14023                 free(proto);
14024 #endif
14025         if (ret == -ENOTSUP)
14026                 printf("Function not supported in PMD driver\n");
14027         close_file(pkg);
14028 }
14029
14030 cmdline_parse_inst_t cmd_ddp_get_info = {
14031         .f = cmd_ddp_info_parsed,
14032         .data = NULL,
14033         .help_str = "ddp get info <profile_path>",
14034         .tokens = {
14035                 (void *)&cmd_ddp_info_ddp,
14036                 (void *)&cmd_ddp_info_get,
14037                 (void *)&cmd_ddp_info_info,
14038                 (void *)&cmd_ddp_info_filepath,
14039                 NULL,
14040         },
14041 };
14042
14043 /* Get dynamic device personalization profile info list*/
14044 #define PROFILE_INFO_SIZE 48
14045 #define MAX_PROFILE_NUM 16
14046
14047 struct cmd_ddp_get_list_result {
14048         cmdline_fixed_string_t ddp;
14049         cmdline_fixed_string_t get;
14050         cmdline_fixed_string_t list;
14051         portid_t port_id;
14052 };
14053
14054 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14055         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14056 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14057         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14058 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14059         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14060 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14061         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14062                 RTE_UINT16);
14063
14064 static void
14065 cmd_ddp_get_list_parsed(
14066         __rte_unused void *parsed_result,
14067         __rte_unused struct cmdline *cl,
14068         __rte_unused void *data)
14069 {
14070 #ifdef RTE_NET_I40E
14071         struct cmd_ddp_get_list_result *res = parsed_result;
14072         struct rte_pmd_i40e_profile_list *p_list;
14073         struct rte_pmd_i40e_profile_info *p_info;
14074         uint32_t p_num;
14075         uint32_t size;
14076         uint32_t i;
14077 #endif
14078         int ret = -ENOTSUP;
14079
14080 #ifdef RTE_NET_I40E
14081         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14082         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14083         if (!p_list) {
14084                 printf("%s: Failed to malloc buffer\n", __func__);
14085                 return;
14086         }
14087
14088         if (ret == -ENOTSUP)
14089                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14090                                                 (uint8_t *)p_list, size);
14091
14092         if (!ret) {
14093                 p_num = p_list->p_count;
14094                 printf("Profile number is: %d\n\n", p_num);
14095
14096                 for (i = 0; i < p_num; i++) {
14097                         p_info = &p_list->p_info[i];
14098                         printf("Profile %d:\n", i);
14099                         printf("Track id:     0x%x\n", p_info->track_id);
14100                         printf("Version:      %d.%d.%d.%d\n",
14101                                p_info->version.major,
14102                                p_info->version.minor,
14103                                p_info->version.update,
14104                                p_info->version.draft);
14105                         printf("Profile name: %s\n\n", p_info->name);
14106                 }
14107         }
14108
14109         free(p_list);
14110 #endif
14111
14112         if (ret < 0)
14113                 printf("Failed to get ddp list\n");
14114 }
14115
14116 cmdline_parse_inst_t cmd_ddp_get_list = {
14117         .f = cmd_ddp_get_list_parsed,
14118         .data = NULL,
14119         .help_str = "ddp get list <port_id>",
14120         .tokens = {
14121                 (void *)&cmd_ddp_get_list_ddp,
14122                 (void *)&cmd_ddp_get_list_get,
14123                 (void *)&cmd_ddp_get_list_list,
14124                 (void *)&cmd_ddp_get_list_port_id,
14125                 NULL,
14126         },
14127 };
14128
14129 /* Configure input set */
14130 struct cmd_cfg_input_set_result {
14131         cmdline_fixed_string_t port;
14132         cmdline_fixed_string_t cfg;
14133         portid_t port_id;
14134         cmdline_fixed_string_t pctype;
14135         uint8_t pctype_id;
14136         cmdline_fixed_string_t inset_type;
14137         cmdline_fixed_string_t opt;
14138         cmdline_fixed_string_t field;
14139         uint8_t field_idx;
14140 };
14141
14142 static void
14143 cmd_cfg_input_set_parsed(
14144         __rte_unused void *parsed_result,
14145         __rte_unused struct cmdline *cl,
14146         __rte_unused void *data)
14147 {
14148 #ifdef RTE_NET_I40E
14149         struct cmd_cfg_input_set_result *res = parsed_result;
14150         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14151         struct rte_pmd_i40e_inset inset;
14152 #endif
14153         int ret = -ENOTSUP;
14154
14155         if (!all_ports_stopped()) {
14156                 printf("Please stop all ports first\n");
14157                 return;
14158         }
14159
14160 #ifdef RTE_NET_I40E
14161         if (!strcmp(res->inset_type, "hash_inset"))
14162                 inset_type = INSET_HASH;
14163         else if (!strcmp(res->inset_type, "fdir_inset"))
14164                 inset_type = INSET_FDIR;
14165         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14166                 inset_type = INSET_FDIR_FLX;
14167         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14168                                      &inset, inset_type);
14169         if (ret) {
14170                 printf("Failed to get input set.\n");
14171                 return;
14172         }
14173
14174         if (!strcmp(res->opt, "get")) {
14175                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14176                                                    res->field_idx);
14177                 if (ret)
14178                         printf("Field index %d is enabled.\n", res->field_idx);
14179                 else
14180                         printf("Field index %d is disabled.\n", res->field_idx);
14181                 return;
14182         } else if (!strcmp(res->opt, "set"))
14183                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14184                                                    res->field_idx);
14185         else if (!strcmp(res->opt, "clear"))
14186                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14187                                                      res->field_idx);
14188         if (ret) {
14189                 printf("Failed to configure input set field.\n");
14190                 return;
14191         }
14192
14193         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14194                                      &inset, inset_type);
14195         if (ret) {
14196                 printf("Failed to set input set.\n");
14197                 return;
14198         }
14199 #endif
14200
14201         if (ret == -ENOTSUP)
14202                 printf("Function not supported\n");
14203 }
14204
14205 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14206         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14207                                  port, "port");
14208 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14209         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14210                                  cfg, "config");
14211 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14212         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14213                               port_id, RTE_UINT16);
14214 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14215         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14216                                  pctype, "pctype");
14217 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14218         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14219                               pctype_id, RTE_UINT8);
14220 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14221         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14222                                  inset_type,
14223                                  "hash_inset#fdir_inset#fdir_flx_inset");
14224 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14225         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14226                                  opt, "get#set#clear");
14227 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14228         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14229                                  field, "field");
14230 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14231         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14232                               field_idx, RTE_UINT8);
14233
14234 cmdline_parse_inst_t cmd_cfg_input_set = {
14235         .f = cmd_cfg_input_set_parsed,
14236         .data = NULL,
14237         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14238                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14239         .tokens = {
14240                 (void *)&cmd_cfg_input_set_port,
14241                 (void *)&cmd_cfg_input_set_cfg,
14242                 (void *)&cmd_cfg_input_set_port_id,
14243                 (void *)&cmd_cfg_input_set_pctype,
14244                 (void *)&cmd_cfg_input_set_pctype_id,
14245                 (void *)&cmd_cfg_input_set_inset_type,
14246                 (void *)&cmd_cfg_input_set_opt,
14247                 (void *)&cmd_cfg_input_set_field,
14248                 (void *)&cmd_cfg_input_set_field_idx,
14249                 NULL,
14250         },
14251 };
14252
14253 /* Clear input set */
14254 struct cmd_clear_input_set_result {
14255         cmdline_fixed_string_t port;
14256         cmdline_fixed_string_t cfg;
14257         portid_t port_id;
14258         cmdline_fixed_string_t pctype;
14259         uint8_t pctype_id;
14260         cmdline_fixed_string_t inset_type;
14261         cmdline_fixed_string_t clear;
14262         cmdline_fixed_string_t all;
14263 };
14264
14265 static void
14266 cmd_clear_input_set_parsed(
14267         __rte_unused void *parsed_result,
14268         __rte_unused struct cmdline *cl,
14269         __rte_unused void *data)
14270 {
14271 #ifdef RTE_NET_I40E
14272         struct cmd_clear_input_set_result *res = parsed_result;
14273         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14274         struct rte_pmd_i40e_inset inset;
14275 #endif
14276         int ret = -ENOTSUP;
14277
14278         if (!all_ports_stopped()) {
14279                 printf("Please stop all ports first\n");
14280                 return;
14281         }
14282
14283 #ifdef RTE_NET_I40E
14284         if (!strcmp(res->inset_type, "hash_inset"))
14285                 inset_type = INSET_HASH;
14286         else if (!strcmp(res->inset_type, "fdir_inset"))
14287                 inset_type = INSET_FDIR;
14288         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14289                 inset_type = INSET_FDIR_FLX;
14290
14291         memset(&inset, 0, sizeof(inset));
14292
14293         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14294                                      &inset, inset_type);
14295         if (ret) {
14296                 printf("Failed to clear input set.\n");
14297                 return;
14298         }
14299
14300 #endif
14301
14302         if (ret == -ENOTSUP)
14303                 printf("Function not supported\n");
14304 }
14305
14306 cmdline_parse_token_string_t cmd_clear_input_set_port =
14307         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14308                                  port, "port");
14309 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14310         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14311                                  cfg, "config");
14312 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14313         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14314                               port_id, RTE_UINT16);
14315 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14316         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14317                                  pctype, "pctype");
14318 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14319         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14320                               pctype_id, RTE_UINT8);
14321 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14322         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14323                                  inset_type,
14324                                  "hash_inset#fdir_inset#fdir_flx_inset");
14325 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14326         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14327                                  clear, "clear");
14328 cmdline_parse_token_string_t cmd_clear_input_set_all =
14329         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14330                                  all, "all");
14331
14332 cmdline_parse_inst_t cmd_clear_input_set = {
14333         .f = cmd_clear_input_set_parsed,
14334         .data = NULL,
14335         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14336                     "fdir_inset|fdir_flx_inset clear all",
14337         .tokens = {
14338                 (void *)&cmd_clear_input_set_port,
14339                 (void *)&cmd_clear_input_set_cfg,
14340                 (void *)&cmd_clear_input_set_port_id,
14341                 (void *)&cmd_clear_input_set_pctype,
14342                 (void *)&cmd_clear_input_set_pctype_id,
14343                 (void *)&cmd_clear_input_set_inset_type,
14344                 (void *)&cmd_clear_input_set_clear,
14345                 (void *)&cmd_clear_input_set_all,
14346                 NULL,
14347         },
14348 };
14349
14350 /* show vf stats */
14351
14352 /* Common result structure for show vf stats */
14353 struct cmd_show_vf_stats_result {
14354         cmdline_fixed_string_t show;
14355         cmdline_fixed_string_t vf;
14356         cmdline_fixed_string_t stats;
14357         portid_t port_id;
14358         uint16_t vf_id;
14359 };
14360
14361 /* Common CLI fields show vf stats*/
14362 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_show_vf_stats_result,
14365                  show, "show");
14366 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14367         TOKEN_STRING_INITIALIZER
14368                 (struct cmd_show_vf_stats_result,
14369                  vf, "vf");
14370 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14371         TOKEN_STRING_INITIALIZER
14372                 (struct cmd_show_vf_stats_result,
14373                  stats, "stats");
14374 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14375         TOKEN_NUM_INITIALIZER
14376                 (struct cmd_show_vf_stats_result,
14377                  port_id, RTE_UINT16);
14378 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14379         TOKEN_NUM_INITIALIZER
14380                 (struct cmd_show_vf_stats_result,
14381                  vf_id, RTE_UINT16);
14382
14383 static void
14384 cmd_show_vf_stats_parsed(
14385         void *parsed_result,
14386         __rte_unused struct cmdline *cl,
14387         __rte_unused void *data)
14388 {
14389         struct cmd_show_vf_stats_result *res = parsed_result;
14390         struct rte_eth_stats stats;
14391         int ret = -ENOTSUP;
14392         static const char *nic_stats_border = "########################";
14393
14394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14395                 return;
14396
14397         memset(&stats, 0, sizeof(stats));
14398
14399 #ifdef RTE_NET_I40E
14400         if (ret == -ENOTSUP)
14401                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14402                                                 res->vf_id,
14403                                                 &stats);
14404 #endif
14405 #ifdef RTE_NET_BNXT
14406         if (ret == -ENOTSUP)
14407                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14408                                                 res->vf_id,
14409                                                 &stats);
14410 #endif
14411
14412         switch (ret) {
14413         case 0:
14414                 break;
14415         case -EINVAL:
14416                 printf("invalid vf_id %d\n", res->vf_id);
14417                 break;
14418         case -ENODEV:
14419                 printf("invalid port_id %d\n", res->port_id);
14420                 break;
14421         case -ENOTSUP:
14422                 printf("function not implemented\n");
14423                 break;
14424         default:
14425                 printf("programming error: (%s)\n", strerror(-ret));
14426         }
14427
14428         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14429                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14430
14431         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14432                "%-"PRIu64"\n",
14433                stats.ipackets, stats.imissed, stats.ibytes);
14434         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14435         printf("  RX-nombuf:  %-10"PRIu64"\n",
14436                stats.rx_nombuf);
14437         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14438                "%-"PRIu64"\n",
14439                stats.opackets, stats.oerrors, stats.obytes);
14440
14441         printf("  %s############################%s\n",
14442                                nic_stats_border, nic_stats_border);
14443 }
14444
14445 cmdline_parse_inst_t cmd_show_vf_stats = {
14446         .f = cmd_show_vf_stats_parsed,
14447         .data = NULL,
14448         .help_str = "show vf stats <port_id> <vf_id>",
14449         .tokens = {
14450                 (void *)&cmd_show_vf_stats_show,
14451                 (void *)&cmd_show_vf_stats_vf,
14452                 (void *)&cmd_show_vf_stats_stats,
14453                 (void *)&cmd_show_vf_stats_port_id,
14454                 (void *)&cmd_show_vf_stats_vf_id,
14455                 NULL,
14456         },
14457 };
14458
14459 /* clear vf stats */
14460
14461 /* Common result structure for clear vf stats */
14462 struct cmd_clear_vf_stats_result {
14463         cmdline_fixed_string_t clear;
14464         cmdline_fixed_string_t vf;
14465         cmdline_fixed_string_t stats;
14466         portid_t port_id;
14467         uint16_t vf_id;
14468 };
14469
14470 /* Common CLI fields clear vf stats*/
14471 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14472         TOKEN_STRING_INITIALIZER
14473                 (struct cmd_clear_vf_stats_result,
14474                  clear, "clear");
14475 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14476         TOKEN_STRING_INITIALIZER
14477                 (struct cmd_clear_vf_stats_result,
14478                  vf, "vf");
14479 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14480         TOKEN_STRING_INITIALIZER
14481                 (struct cmd_clear_vf_stats_result,
14482                  stats, "stats");
14483 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14484         TOKEN_NUM_INITIALIZER
14485                 (struct cmd_clear_vf_stats_result,
14486                  port_id, RTE_UINT16);
14487 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14488         TOKEN_NUM_INITIALIZER
14489                 (struct cmd_clear_vf_stats_result,
14490                  vf_id, RTE_UINT16);
14491
14492 static void
14493 cmd_clear_vf_stats_parsed(
14494         void *parsed_result,
14495         __rte_unused struct cmdline *cl,
14496         __rte_unused void *data)
14497 {
14498         struct cmd_clear_vf_stats_result *res = parsed_result;
14499         int ret = -ENOTSUP;
14500
14501         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14502                 return;
14503
14504 #ifdef RTE_NET_I40E
14505         if (ret == -ENOTSUP)
14506                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14507                                                   res->vf_id);
14508 #endif
14509 #ifdef RTE_NET_BNXT
14510         if (ret == -ENOTSUP)
14511                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14512                                                   res->vf_id);
14513 #endif
14514
14515         switch (ret) {
14516         case 0:
14517                 break;
14518         case -EINVAL:
14519                 printf("invalid vf_id %d\n", res->vf_id);
14520                 break;
14521         case -ENODEV:
14522                 printf("invalid port_id %d\n", res->port_id);
14523                 break;
14524         case -ENOTSUP:
14525                 printf("function not implemented\n");
14526                 break;
14527         default:
14528                 printf("programming error: (%s)\n", strerror(-ret));
14529         }
14530 }
14531
14532 cmdline_parse_inst_t cmd_clear_vf_stats = {
14533         .f = cmd_clear_vf_stats_parsed,
14534         .data = NULL,
14535         .help_str = "clear vf stats <port_id> <vf_id>",
14536         .tokens = {
14537                 (void *)&cmd_clear_vf_stats_clear,
14538                 (void *)&cmd_clear_vf_stats_vf,
14539                 (void *)&cmd_clear_vf_stats_stats,
14540                 (void *)&cmd_clear_vf_stats_port_id,
14541                 (void *)&cmd_clear_vf_stats_vf_id,
14542                 NULL,
14543         },
14544 };
14545
14546 /* port config pctype mapping reset */
14547
14548 /* Common result structure for port config pctype mapping reset */
14549 struct cmd_pctype_mapping_reset_result {
14550         cmdline_fixed_string_t port;
14551         cmdline_fixed_string_t config;
14552         portid_t port_id;
14553         cmdline_fixed_string_t pctype;
14554         cmdline_fixed_string_t mapping;
14555         cmdline_fixed_string_t reset;
14556 };
14557
14558 /* Common CLI fields for port config pctype mapping reset*/
14559 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14560         TOKEN_STRING_INITIALIZER
14561                 (struct cmd_pctype_mapping_reset_result,
14562                  port, "port");
14563 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14564         TOKEN_STRING_INITIALIZER
14565                 (struct cmd_pctype_mapping_reset_result,
14566                  config, "config");
14567 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14568         TOKEN_NUM_INITIALIZER
14569                 (struct cmd_pctype_mapping_reset_result,
14570                  port_id, RTE_UINT16);
14571 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14572         TOKEN_STRING_INITIALIZER
14573                 (struct cmd_pctype_mapping_reset_result,
14574                  pctype, "pctype");
14575 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_pctype_mapping_reset_result,
14578                  mapping, "mapping");
14579 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14580         TOKEN_STRING_INITIALIZER
14581                 (struct cmd_pctype_mapping_reset_result,
14582                  reset, "reset");
14583
14584 static void
14585 cmd_pctype_mapping_reset_parsed(
14586         void *parsed_result,
14587         __rte_unused struct cmdline *cl,
14588         __rte_unused void *data)
14589 {
14590         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14591         int ret = -ENOTSUP;
14592
14593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14594                 return;
14595
14596 #ifdef RTE_NET_I40E
14597         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14598 #endif
14599
14600         switch (ret) {
14601         case 0:
14602                 break;
14603         case -ENODEV:
14604                 printf("invalid port_id %d\n", res->port_id);
14605                 break;
14606         case -ENOTSUP:
14607                 printf("function not implemented\n");
14608                 break;
14609         default:
14610                 printf("programming error: (%s)\n", strerror(-ret));
14611         }
14612 }
14613
14614 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14615         .f = cmd_pctype_mapping_reset_parsed,
14616         .data = NULL,
14617         .help_str = "port config <port_id> pctype mapping reset",
14618         .tokens = {
14619                 (void *)&cmd_pctype_mapping_reset_port,
14620                 (void *)&cmd_pctype_mapping_reset_config,
14621                 (void *)&cmd_pctype_mapping_reset_port_id,
14622                 (void *)&cmd_pctype_mapping_reset_pctype,
14623                 (void *)&cmd_pctype_mapping_reset_mapping,
14624                 (void *)&cmd_pctype_mapping_reset_reset,
14625                 NULL,
14626         },
14627 };
14628
14629 /* show port pctype mapping */
14630
14631 /* Common result structure for show port pctype mapping */
14632 struct cmd_pctype_mapping_get_result {
14633         cmdline_fixed_string_t show;
14634         cmdline_fixed_string_t port;
14635         portid_t port_id;
14636         cmdline_fixed_string_t pctype;
14637         cmdline_fixed_string_t mapping;
14638 };
14639
14640 /* Common CLI fields for pctype mapping get */
14641 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14642         TOKEN_STRING_INITIALIZER
14643                 (struct cmd_pctype_mapping_get_result,
14644                  show, "show");
14645 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14646         TOKEN_STRING_INITIALIZER
14647                 (struct cmd_pctype_mapping_get_result,
14648                  port, "port");
14649 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14650         TOKEN_NUM_INITIALIZER
14651                 (struct cmd_pctype_mapping_get_result,
14652                  port_id, RTE_UINT16);
14653 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14654         TOKEN_STRING_INITIALIZER
14655                 (struct cmd_pctype_mapping_get_result,
14656                  pctype, "pctype");
14657 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14658         TOKEN_STRING_INITIALIZER
14659                 (struct cmd_pctype_mapping_get_result,
14660                  mapping, "mapping");
14661
14662 static void
14663 cmd_pctype_mapping_get_parsed(
14664         void *parsed_result,
14665         __rte_unused struct cmdline *cl,
14666         __rte_unused void *data)
14667 {
14668         struct cmd_pctype_mapping_get_result *res = parsed_result;
14669         int ret = -ENOTSUP;
14670 #ifdef RTE_NET_I40E
14671         struct rte_pmd_i40e_flow_type_mapping
14672                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14673         int i, j, first_pctype;
14674 #endif
14675
14676         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14677                 return;
14678
14679 #ifdef RTE_NET_I40E
14680         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14681 #endif
14682
14683         switch (ret) {
14684         case 0:
14685                 break;
14686         case -ENODEV:
14687                 printf("invalid port_id %d\n", res->port_id);
14688                 return;
14689         case -ENOTSUP:
14690                 printf("function not implemented\n");
14691                 return;
14692         default:
14693                 printf("programming error: (%s)\n", strerror(-ret));
14694                 return;
14695         }
14696
14697 #ifdef RTE_NET_I40E
14698         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14699                 if (mapping[i].pctype != 0ULL) {
14700                         first_pctype = 1;
14701
14702                         printf("pctype: ");
14703                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14704                                 if (mapping[i].pctype & (1ULL << j)) {
14705                                         printf(first_pctype ?
14706                                                "%02d" : ",%02d", j);
14707                                         first_pctype = 0;
14708                                 }
14709                         }
14710                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14711                 }
14712         }
14713 #endif
14714 }
14715
14716 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14717         .f = cmd_pctype_mapping_get_parsed,
14718         .data = NULL,
14719         .help_str = "show port <port_id> pctype mapping",
14720         .tokens = {
14721                 (void *)&cmd_pctype_mapping_get_show,
14722                 (void *)&cmd_pctype_mapping_get_port,
14723                 (void *)&cmd_pctype_mapping_get_port_id,
14724                 (void *)&cmd_pctype_mapping_get_pctype,
14725                 (void *)&cmd_pctype_mapping_get_mapping,
14726                 NULL,
14727         },
14728 };
14729
14730 /* port config pctype mapping update */
14731
14732 /* Common result structure for port config pctype mapping update */
14733 struct cmd_pctype_mapping_update_result {
14734         cmdline_fixed_string_t port;
14735         cmdline_fixed_string_t config;
14736         portid_t port_id;
14737         cmdline_fixed_string_t pctype;
14738         cmdline_fixed_string_t mapping;
14739         cmdline_fixed_string_t update;
14740         cmdline_fixed_string_t pctype_list;
14741         uint16_t flow_type;
14742 };
14743
14744 /* Common CLI fields for pctype mapping update*/
14745 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14746         TOKEN_STRING_INITIALIZER
14747                 (struct cmd_pctype_mapping_update_result,
14748                  port, "port");
14749 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14750         TOKEN_STRING_INITIALIZER
14751                 (struct cmd_pctype_mapping_update_result,
14752                  config, "config");
14753 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14754         TOKEN_NUM_INITIALIZER
14755                 (struct cmd_pctype_mapping_update_result,
14756                  port_id, RTE_UINT16);
14757 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_pctype_mapping_update_result,
14760                  pctype, "pctype");
14761 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_pctype_mapping_update_result,
14764                  mapping, "mapping");
14765 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14766         TOKEN_STRING_INITIALIZER
14767                 (struct cmd_pctype_mapping_update_result,
14768                  update, "update");
14769 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14770         TOKEN_STRING_INITIALIZER
14771                 (struct cmd_pctype_mapping_update_result,
14772                  pctype_list, NULL);
14773 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14774         TOKEN_NUM_INITIALIZER
14775                 (struct cmd_pctype_mapping_update_result,
14776                  flow_type, RTE_UINT16);
14777
14778 static void
14779 cmd_pctype_mapping_update_parsed(
14780         void *parsed_result,
14781         __rte_unused struct cmdline *cl,
14782         __rte_unused void *data)
14783 {
14784         struct cmd_pctype_mapping_update_result *res = parsed_result;
14785         int ret = -ENOTSUP;
14786 #ifdef RTE_NET_I40E
14787         struct rte_pmd_i40e_flow_type_mapping mapping;
14788         unsigned int i;
14789         unsigned int nb_item;
14790         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14791 #endif
14792
14793         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14794                 return;
14795
14796 #ifdef RTE_NET_I40E
14797         nb_item = parse_item_list(res->pctype_list, "pctypes",
14798                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14799         mapping.flow_type = res->flow_type;
14800         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14801                 mapping.pctype |= (1ULL << pctype_list[i]);
14802         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14803                                                 &mapping,
14804                                                 1,
14805                                                 0);
14806 #endif
14807
14808         switch (ret) {
14809         case 0:
14810                 break;
14811         case -EINVAL:
14812                 printf("invalid pctype or flow type\n");
14813                 break;
14814         case -ENODEV:
14815                 printf("invalid port_id %d\n", res->port_id);
14816                 break;
14817         case -ENOTSUP:
14818                 printf("function not implemented\n");
14819                 break;
14820         default:
14821                 printf("programming error: (%s)\n", strerror(-ret));
14822         }
14823 }
14824
14825 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14826         .f = cmd_pctype_mapping_update_parsed,
14827         .data = NULL,
14828         .help_str = "port config <port_id> pctype mapping update"
14829         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14830         .tokens = {
14831                 (void *)&cmd_pctype_mapping_update_port,
14832                 (void *)&cmd_pctype_mapping_update_config,
14833                 (void *)&cmd_pctype_mapping_update_port_id,
14834                 (void *)&cmd_pctype_mapping_update_pctype,
14835                 (void *)&cmd_pctype_mapping_update_mapping,
14836                 (void *)&cmd_pctype_mapping_update_update,
14837                 (void *)&cmd_pctype_mapping_update_pc_type,
14838                 (void *)&cmd_pctype_mapping_update_flow_type,
14839                 NULL,
14840         },
14841 };
14842
14843 /* ptype mapping get */
14844
14845 /* Common result structure for ptype mapping get */
14846 struct cmd_ptype_mapping_get_result {
14847         cmdline_fixed_string_t ptype;
14848         cmdline_fixed_string_t mapping;
14849         cmdline_fixed_string_t get;
14850         portid_t port_id;
14851         uint8_t valid_only;
14852 };
14853
14854 /* Common CLI fields for ptype mapping get */
14855 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14856         TOKEN_STRING_INITIALIZER
14857                 (struct cmd_ptype_mapping_get_result,
14858                  ptype, "ptype");
14859 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14860         TOKEN_STRING_INITIALIZER
14861                 (struct cmd_ptype_mapping_get_result,
14862                  mapping, "mapping");
14863 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14864         TOKEN_STRING_INITIALIZER
14865                 (struct cmd_ptype_mapping_get_result,
14866                  get, "get");
14867 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14868         TOKEN_NUM_INITIALIZER
14869                 (struct cmd_ptype_mapping_get_result,
14870                  port_id, RTE_UINT16);
14871 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14872         TOKEN_NUM_INITIALIZER
14873                 (struct cmd_ptype_mapping_get_result,
14874                  valid_only, RTE_UINT8);
14875
14876 static void
14877 cmd_ptype_mapping_get_parsed(
14878         void *parsed_result,
14879         __rte_unused struct cmdline *cl,
14880         __rte_unused void *data)
14881 {
14882         struct cmd_ptype_mapping_get_result *res = parsed_result;
14883         int ret = -ENOTSUP;
14884 #ifdef RTE_NET_I40E
14885         int max_ptype_num = 256;
14886         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14887         uint16_t count;
14888         int i;
14889 #endif
14890
14891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14892                 return;
14893
14894 #ifdef RTE_NET_I40E
14895         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14896                                         mapping,
14897                                         max_ptype_num,
14898                                         &count,
14899                                         res->valid_only);
14900 #endif
14901
14902         switch (ret) {
14903         case 0:
14904                 break;
14905         case -ENODEV:
14906                 printf("invalid port_id %d\n", res->port_id);
14907                 break;
14908         case -ENOTSUP:
14909                 printf("function not implemented\n");
14910                 break;
14911         default:
14912                 printf("programming error: (%s)\n", strerror(-ret));
14913         }
14914
14915 #ifdef RTE_NET_I40E
14916         if (!ret) {
14917                 for (i = 0; i < count; i++)
14918                         printf("%3d\t0x%08x\n",
14919                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14920         }
14921 #endif
14922 }
14923
14924 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14925         .f = cmd_ptype_mapping_get_parsed,
14926         .data = NULL,
14927         .help_str = "ptype mapping get <port_id> <valid_only>",
14928         .tokens = {
14929                 (void *)&cmd_ptype_mapping_get_ptype,
14930                 (void *)&cmd_ptype_mapping_get_mapping,
14931                 (void *)&cmd_ptype_mapping_get_get,
14932                 (void *)&cmd_ptype_mapping_get_port_id,
14933                 (void *)&cmd_ptype_mapping_get_valid_only,
14934                 NULL,
14935         },
14936 };
14937
14938 /* ptype mapping replace */
14939
14940 /* Common result structure for ptype mapping replace */
14941 struct cmd_ptype_mapping_replace_result {
14942         cmdline_fixed_string_t ptype;
14943         cmdline_fixed_string_t mapping;
14944         cmdline_fixed_string_t replace;
14945         portid_t port_id;
14946         uint32_t target;
14947         uint8_t mask;
14948         uint32_t pkt_type;
14949 };
14950
14951 /* Common CLI fields for ptype mapping replace */
14952 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14953         TOKEN_STRING_INITIALIZER
14954                 (struct cmd_ptype_mapping_replace_result,
14955                  ptype, "ptype");
14956 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14957         TOKEN_STRING_INITIALIZER
14958                 (struct cmd_ptype_mapping_replace_result,
14959                  mapping, "mapping");
14960 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14961         TOKEN_STRING_INITIALIZER
14962                 (struct cmd_ptype_mapping_replace_result,
14963                  replace, "replace");
14964 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14965         TOKEN_NUM_INITIALIZER
14966                 (struct cmd_ptype_mapping_replace_result,
14967                  port_id, RTE_UINT16);
14968 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14969         TOKEN_NUM_INITIALIZER
14970                 (struct cmd_ptype_mapping_replace_result,
14971                  target, RTE_UINT32);
14972 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14973         TOKEN_NUM_INITIALIZER
14974                 (struct cmd_ptype_mapping_replace_result,
14975                  mask, RTE_UINT8);
14976 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14977         TOKEN_NUM_INITIALIZER
14978                 (struct cmd_ptype_mapping_replace_result,
14979                  pkt_type, RTE_UINT32);
14980
14981 static void
14982 cmd_ptype_mapping_replace_parsed(
14983         void *parsed_result,
14984         __rte_unused struct cmdline *cl,
14985         __rte_unused void *data)
14986 {
14987         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14988         int ret = -ENOTSUP;
14989
14990         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14991                 return;
14992
14993 #ifdef RTE_NET_I40E
14994         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14995                                         res->target,
14996                                         res->mask,
14997                                         res->pkt_type);
14998 #endif
14999
15000         switch (ret) {
15001         case 0:
15002                 break;
15003         case -EINVAL:
15004                 printf("invalid ptype 0x%8x or 0x%8x\n",
15005                                 res->target, res->pkt_type);
15006                 break;
15007         case -ENODEV:
15008                 printf("invalid port_id %d\n", res->port_id);
15009                 break;
15010         case -ENOTSUP:
15011                 printf("function not implemented\n");
15012                 break;
15013         default:
15014                 printf("programming error: (%s)\n", strerror(-ret));
15015         }
15016 }
15017
15018 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15019         .f = cmd_ptype_mapping_replace_parsed,
15020         .data = NULL,
15021         .help_str =
15022                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15023         .tokens = {
15024                 (void *)&cmd_ptype_mapping_replace_ptype,
15025                 (void *)&cmd_ptype_mapping_replace_mapping,
15026                 (void *)&cmd_ptype_mapping_replace_replace,
15027                 (void *)&cmd_ptype_mapping_replace_port_id,
15028                 (void *)&cmd_ptype_mapping_replace_target,
15029                 (void *)&cmd_ptype_mapping_replace_mask,
15030                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15031                 NULL,
15032         },
15033 };
15034
15035 /* ptype mapping reset */
15036
15037 /* Common result structure for ptype mapping reset */
15038 struct cmd_ptype_mapping_reset_result {
15039         cmdline_fixed_string_t ptype;
15040         cmdline_fixed_string_t mapping;
15041         cmdline_fixed_string_t reset;
15042         portid_t port_id;
15043 };
15044
15045 /* Common CLI fields for ptype mapping reset*/
15046 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15047         TOKEN_STRING_INITIALIZER
15048                 (struct cmd_ptype_mapping_reset_result,
15049                  ptype, "ptype");
15050 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15051         TOKEN_STRING_INITIALIZER
15052                 (struct cmd_ptype_mapping_reset_result,
15053                  mapping, "mapping");
15054 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15055         TOKEN_STRING_INITIALIZER
15056                 (struct cmd_ptype_mapping_reset_result,
15057                  reset, "reset");
15058 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15059         TOKEN_NUM_INITIALIZER
15060                 (struct cmd_ptype_mapping_reset_result,
15061                  port_id, RTE_UINT16);
15062
15063 static void
15064 cmd_ptype_mapping_reset_parsed(
15065         void *parsed_result,
15066         __rte_unused struct cmdline *cl,
15067         __rte_unused void *data)
15068 {
15069         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15070         int ret = -ENOTSUP;
15071
15072         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15073                 return;
15074
15075 #ifdef RTE_NET_I40E
15076         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15077 #endif
15078
15079         switch (ret) {
15080         case 0:
15081                 break;
15082         case -ENODEV:
15083                 printf("invalid port_id %d\n", res->port_id);
15084                 break;
15085         case -ENOTSUP:
15086                 printf("function not implemented\n");
15087                 break;
15088         default:
15089                 printf("programming error: (%s)\n", strerror(-ret));
15090         }
15091 }
15092
15093 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15094         .f = cmd_ptype_mapping_reset_parsed,
15095         .data = NULL,
15096         .help_str = "ptype mapping reset <port_id>",
15097         .tokens = {
15098                 (void *)&cmd_ptype_mapping_reset_ptype,
15099                 (void *)&cmd_ptype_mapping_reset_mapping,
15100                 (void *)&cmd_ptype_mapping_reset_reset,
15101                 (void *)&cmd_ptype_mapping_reset_port_id,
15102                 NULL,
15103         },
15104 };
15105
15106 /* ptype mapping update */
15107
15108 /* Common result structure for ptype mapping update */
15109 struct cmd_ptype_mapping_update_result {
15110         cmdline_fixed_string_t ptype;
15111         cmdline_fixed_string_t mapping;
15112         cmdline_fixed_string_t reset;
15113         portid_t port_id;
15114         uint8_t hw_ptype;
15115         uint32_t sw_ptype;
15116 };
15117
15118 /* Common CLI fields for ptype mapping update*/
15119 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15120         TOKEN_STRING_INITIALIZER
15121                 (struct cmd_ptype_mapping_update_result,
15122                  ptype, "ptype");
15123 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15124         TOKEN_STRING_INITIALIZER
15125                 (struct cmd_ptype_mapping_update_result,
15126                  mapping, "mapping");
15127 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15128         TOKEN_STRING_INITIALIZER
15129                 (struct cmd_ptype_mapping_update_result,
15130                  reset, "update");
15131 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15132         TOKEN_NUM_INITIALIZER
15133                 (struct cmd_ptype_mapping_update_result,
15134                  port_id, RTE_UINT16);
15135 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15136         TOKEN_NUM_INITIALIZER
15137                 (struct cmd_ptype_mapping_update_result,
15138                  hw_ptype, RTE_UINT8);
15139 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15140         TOKEN_NUM_INITIALIZER
15141                 (struct cmd_ptype_mapping_update_result,
15142                  sw_ptype, RTE_UINT32);
15143
15144 static void
15145 cmd_ptype_mapping_update_parsed(
15146         void *parsed_result,
15147         __rte_unused struct cmdline *cl,
15148         __rte_unused void *data)
15149 {
15150         struct cmd_ptype_mapping_update_result *res = parsed_result;
15151         int ret = -ENOTSUP;
15152 #ifdef RTE_NET_I40E
15153         struct rte_pmd_i40e_ptype_mapping mapping;
15154 #endif
15155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15156                 return;
15157
15158 #ifdef RTE_NET_I40E
15159         mapping.hw_ptype = res->hw_ptype;
15160         mapping.sw_ptype = res->sw_ptype;
15161         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15162                                                 &mapping,
15163                                                 1,
15164                                                 0);
15165 #endif
15166
15167         switch (ret) {
15168         case 0:
15169                 break;
15170         case -EINVAL:
15171                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15172                 break;
15173         case -ENODEV:
15174                 printf("invalid port_id %d\n", res->port_id);
15175                 break;
15176         case -ENOTSUP:
15177                 printf("function not implemented\n");
15178                 break;
15179         default:
15180                 printf("programming error: (%s)\n", strerror(-ret));
15181         }
15182 }
15183
15184 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15185         .f = cmd_ptype_mapping_update_parsed,
15186         .data = NULL,
15187         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15188         .tokens = {
15189                 (void *)&cmd_ptype_mapping_update_ptype,
15190                 (void *)&cmd_ptype_mapping_update_mapping,
15191                 (void *)&cmd_ptype_mapping_update_update,
15192                 (void *)&cmd_ptype_mapping_update_port_id,
15193                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15194                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15195                 NULL,
15196         },
15197 };
15198
15199 /* Common result structure for file commands */
15200 struct cmd_cmdfile_result {
15201         cmdline_fixed_string_t load;
15202         cmdline_fixed_string_t filename;
15203 };
15204
15205 /* Common CLI fields for file commands */
15206 cmdline_parse_token_string_t cmd_load_cmdfile =
15207         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15208 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15209         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15210
15211 static void
15212 cmd_load_from_file_parsed(
15213         void *parsed_result,
15214         __rte_unused struct cmdline *cl,
15215         __rte_unused void *data)
15216 {
15217         struct cmd_cmdfile_result *res = parsed_result;
15218
15219         cmdline_read_from_file(res->filename);
15220 }
15221
15222 cmdline_parse_inst_t cmd_load_from_file = {
15223         .f = cmd_load_from_file_parsed,
15224         .data = NULL,
15225         .help_str = "load <filename>",
15226         .tokens = {
15227                 (void *)&cmd_load_cmdfile,
15228                 (void *)&cmd_load_cmdfile_filename,
15229                 NULL,
15230         },
15231 };
15232
15233 /* Get Rx offloads capabilities */
15234 struct cmd_rx_offload_get_capa_result {
15235         cmdline_fixed_string_t show;
15236         cmdline_fixed_string_t port;
15237         portid_t port_id;
15238         cmdline_fixed_string_t rx_offload;
15239         cmdline_fixed_string_t capabilities;
15240 };
15241
15242 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15243         TOKEN_STRING_INITIALIZER
15244                 (struct cmd_rx_offload_get_capa_result,
15245                  show, "show");
15246 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15247         TOKEN_STRING_INITIALIZER
15248                 (struct cmd_rx_offload_get_capa_result,
15249                  port, "port");
15250 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15251         TOKEN_NUM_INITIALIZER
15252                 (struct cmd_rx_offload_get_capa_result,
15253                  port_id, RTE_UINT16);
15254 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15255         TOKEN_STRING_INITIALIZER
15256                 (struct cmd_rx_offload_get_capa_result,
15257                  rx_offload, "rx_offload");
15258 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15259         TOKEN_STRING_INITIALIZER
15260                 (struct cmd_rx_offload_get_capa_result,
15261                  capabilities, "capabilities");
15262
15263 static void
15264 print_rx_offloads(uint64_t offloads)
15265 {
15266         uint64_t single_offload;
15267         int begin;
15268         int end;
15269         int bit;
15270
15271         if (offloads == 0)
15272                 return;
15273
15274         begin = __builtin_ctzll(offloads);
15275         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15276
15277         single_offload = 1ULL << begin;
15278         for (bit = begin; bit < end; bit++) {
15279                 if (offloads & single_offload)
15280                         printf(" %s",
15281                                rte_eth_dev_rx_offload_name(single_offload));
15282                 single_offload <<= 1;
15283         }
15284 }
15285
15286 static void
15287 cmd_rx_offload_get_capa_parsed(
15288         void *parsed_result,
15289         __rte_unused struct cmdline *cl,
15290         __rte_unused void *data)
15291 {
15292         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15293         struct rte_eth_dev_info dev_info;
15294         portid_t port_id = res->port_id;
15295         uint64_t queue_offloads;
15296         uint64_t port_offloads;
15297         int ret;
15298
15299         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15300         if (ret != 0)
15301                 return;
15302
15303         queue_offloads = dev_info.rx_queue_offload_capa;
15304         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15305
15306         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15307         printf("  Per Queue :");
15308         print_rx_offloads(queue_offloads);
15309
15310         printf("\n");
15311         printf("  Per Port  :");
15312         print_rx_offloads(port_offloads);
15313         printf("\n\n");
15314 }
15315
15316 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15317         .f = cmd_rx_offload_get_capa_parsed,
15318         .data = NULL,
15319         .help_str = "show port <port_id> rx_offload capabilities",
15320         .tokens = {
15321                 (void *)&cmd_rx_offload_get_capa_show,
15322                 (void *)&cmd_rx_offload_get_capa_port,
15323                 (void *)&cmd_rx_offload_get_capa_port_id,
15324                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15325                 (void *)&cmd_rx_offload_get_capa_capabilities,
15326                 NULL,
15327         }
15328 };
15329
15330 /* Get Rx offloads configuration */
15331 struct cmd_rx_offload_get_configuration_result {
15332         cmdline_fixed_string_t show;
15333         cmdline_fixed_string_t port;
15334         portid_t port_id;
15335         cmdline_fixed_string_t rx_offload;
15336         cmdline_fixed_string_t configuration;
15337 };
15338
15339 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15340         TOKEN_STRING_INITIALIZER
15341                 (struct cmd_rx_offload_get_configuration_result,
15342                  show, "show");
15343 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15344         TOKEN_STRING_INITIALIZER
15345                 (struct cmd_rx_offload_get_configuration_result,
15346                  port, "port");
15347 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15348         TOKEN_NUM_INITIALIZER
15349                 (struct cmd_rx_offload_get_configuration_result,
15350                  port_id, RTE_UINT16);
15351 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15352         TOKEN_STRING_INITIALIZER
15353                 (struct cmd_rx_offload_get_configuration_result,
15354                  rx_offload, "rx_offload");
15355 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15356         TOKEN_STRING_INITIALIZER
15357                 (struct cmd_rx_offload_get_configuration_result,
15358                  configuration, "configuration");
15359
15360 static void
15361 cmd_rx_offload_get_configuration_parsed(
15362         void *parsed_result,
15363         __rte_unused struct cmdline *cl,
15364         __rte_unused void *data)
15365 {
15366         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15367         struct rte_eth_dev_info dev_info;
15368         portid_t port_id = res->port_id;
15369         struct rte_port *port = &ports[port_id];
15370         uint64_t port_offloads;
15371         uint64_t queue_offloads;
15372         uint16_t nb_rx_queues;
15373         int q;
15374         int ret;
15375
15376         printf("Rx Offloading Configuration of port %d :\n", port_id);
15377
15378         port_offloads = port->dev_conf.rxmode.offloads;
15379         printf("  Port :");
15380         print_rx_offloads(port_offloads);
15381         printf("\n");
15382
15383         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15384         if (ret != 0)
15385                 return;
15386
15387         nb_rx_queues = dev_info.nb_rx_queues;
15388         for (q = 0; q < nb_rx_queues; q++) {
15389                 queue_offloads = port->rx_conf[q].offloads;
15390                 printf("  Queue[%2d] :", q);
15391                 print_rx_offloads(queue_offloads);
15392                 printf("\n");
15393         }
15394         printf("\n");
15395 }
15396
15397 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15398         .f = cmd_rx_offload_get_configuration_parsed,
15399         .data = NULL,
15400         .help_str = "show port <port_id> rx_offload configuration",
15401         .tokens = {
15402                 (void *)&cmd_rx_offload_get_configuration_show,
15403                 (void *)&cmd_rx_offload_get_configuration_port,
15404                 (void *)&cmd_rx_offload_get_configuration_port_id,
15405                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15406                 (void *)&cmd_rx_offload_get_configuration_configuration,
15407                 NULL,
15408         }
15409 };
15410
15411 /* Enable/Disable a per port offloading */
15412 struct cmd_config_per_port_rx_offload_result {
15413         cmdline_fixed_string_t port;
15414         cmdline_fixed_string_t config;
15415         portid_t port_id;
15416         cmdline_fixed_string_t rx_offload;
15417         cmdline_fixed_string_t offload;
15418         cmdline_fixed_string_t on_off;
15419 };
15420
15421 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15422         TOKEN_STRING_INITIALIZER
15423                 (struct cmd_config_per_port_rx_offload_result,
15424                  port, "port");
15425 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15426         TOKEN_STRING_INITIALIZER
15427                 (struct cmd_config_per_port_rx_offload_result,
15428                  config, "config");
15429 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15430         TOKEN_NUM_INITIALIZER
15431                 (struct cmd_config_per_port_rx_offload_result,
15432                  port_id, RTE_UINT16);
15433 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15434         TOKEN_STRING_INITIALIZER
15435                 (struct cmd_config_per_port_rx_offload_result,
15436                  rx_offload, "rx_offload");
15437 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15438         TOKEN_STRING_INITIALIZER
15439                 (struct cmd_config_per_port_rx_offload_result,
15440                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15441                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15442                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15443                            "scatter#buffer_split#timestamp#security#"
15444                            "keep_crc#rss_hash");
15445 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15446         TOKEN_STRING_INITIALIZER
15447                 (struct cmd_config_per_port_rx_offload_result,
15448                  on_off, "on#off");
15449
15450 static uint64_t
15451 search_rx_offload(const char *name)
15452 {
15453         uint64_t single_offload;
15454         const char *single_name;
15455         int found = 0;
15456         unsigned int bit;
15457
15458         single_offload = 1;
15459         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15460                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15461                 if (!strcasecmp(single_name, name)) {
15462                         found = 1;
15463                         break;
15464                 }
15465                 single_offload <<= 1;
15466         }
15467
15468         if (found)
15469                 return single_offload;
15470
15471         return 0;
15472 }
15473
15474 static void
15475 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15476                                 __rte_unused struct cmdline *cl,
15477                                 __rte_unused void *data)
15478 {
15479         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15480         portid_t port_id = res->port_id;
15481         struct rte_eth_dev_info dev_info;
15482         struct rte_port *port = &ports[port_id];
15483         uint64_t single_offload;
15484         uint16_t nb_rx_queues;
15485         int q;
15486         int ret;
15487
15488         if (port->port_status != RTE_PORT_STOPPED) {
15489                 printf("Error: Can't config offload when Port %d "
15490                        "is not stopped\n", port_id);
15491                 return;
15492         }
15493
15494         single_offload = search_rx_offload(res->offload);
15495         if (single_offload == 0) {
15496                 printf("Unknown offload name: %s\n", res->offload);
15497                 return;
15498         }
15499
15500         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15501         if (ret != 0)
15502                 return;
15503
15504         nb_rx_queues = dev_info.nb_rx_queues;
15505         if (!strcmp(res->on_off, "on")) {
15506                 port->dev_conf.rxmode.offloads |= single_offload;
15507                 for (q = 0; q < nb_rx_queues; q++)
15508                         port->rx_conf[q].offloads |= single_offload;
15509         } else {
15510                 port->dev_conf.rxmode.offloads &= ~single_offload;
15511                 for (q = 0; q < nb_rx_queues; q++)
15512                         port->rx_conf[q].offloads &= ~single_offload;
15513         }
15514
15515         cmd_reconfig_device_queue(port_id, 1, 1);
15516 }
15517
15518 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15519         .f = cmd_config_per_port_rx_offload_parsed,
15520         .data = NULL,
15521         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15522                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15523                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15524                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15525                     "keep_crc|rss_hash on|off",
15526         .tokens = {
15527                 (void *)&cmd_config_per_port_rx_offload_result_port,
15528                 (void *)&cmd_config_per_port_rx_offload_result_config,
15529                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15530                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15531                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15532                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15533                 NULL,
15534         }
15535 };
15536
15537 /* Enable/Disable a per queue offloading */
15538 struct cmd_config_per_queue_rx_offload_result {
15539         cmdline_fixed_string_t port;
15540         portid_t port_id;
15541         cmdline_fixed_string_t rxq;
15542         uint16_t queue_id;
15543         cmdline_fixed_string_t rx_offload;
15544         cmdline_fixed_string_t offload;
15545         cmdline_fixed_string_t on_off;
15546 };
15547
15548 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15549         TOKEN_STRING_INITIALIZER
15550                 (struct cmd_config_per_queue_rx_offload_result,
15551                  port, "port");
15552 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15553         TOKEN_NUM_INITIALIZER
15554                 (struct cmd_config_per_queue_rx_offload_result,
15555                  port_id, RTE_UINT16);
15556 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15557         TOKEN_STRING_INITIALIZER
15558                 (struct cmd_config_per_queue_rx_offload_result,
15559                  rxq, "rxq");
15560 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15561         TOKEN_NUM_INITIALIZER
15562                 (struct cmd_config_per_queue_rx_offload_result,
15563                  queue_id, RTE_UINT16);
15564 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15565         TOKEN_STRING_INITIALIZER
15566                 (struct cmd_config_per_queue_rx_offload_result,
15567                  rx_offload, "rx_offload");
15568 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15569         TOKEN_STRING_INITIALIZER
15570                 (struct cmd_config_per_queue_rx_offload_result,
15571                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15572                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15573                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15574                            "scatter#buffer_split#timestamp#security#keep_crc");
15575 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15576         TOKEN_STRING_INITIALIZER
15577                 (struct cmd_config_per_queue_rx_offload_result,
15578                  on_off, "on#off");
15579
15580 static void
15581 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15582                                 __rte_unused struct cmdline *cl,
15583                                 __rte_unused void *data)
15584 {
15585         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15586         struct rte_eth_dev_info dev_info;
15587         portid_t port_id = res->port_id;
15588         uint16_t queue_id = res->queue_id;
15589         struct rte_port *port = &ports[port_id];
15590         uint64_t single_offload;
15591         int ret;
15592
15593         if (port->port_status != RTE_PORT_STOPPED) {
15594                 printf("Error: Can't config offload when Port %d "
15595                        "is not stopped\n", port_id);
15596                 return;
15597         }
15598
15599         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15600         if (ret != 0)
15601                 return;
15602
15603         if (queue_id >= dev_info.nb_rx_queues) {
15604                 printf("Error: input queue_id should be 0 ... "
15605                        "%d\n", dev_info.nb_rx_queues - 1);
15606                 return;
15607         }
15608
15609         single_offload = search_rx_offload(res->offload);
15610         if (single_offload == 0) {
15611                 printf("Unknown offload name: %s\n", res->offload);
15612                 return;
15613         }
15614
15615         if (!strcmp(res->on_off, "on"))
15616                 port->rx_conf[queue_id].offloads |= single_offload;
15617         else
15618                 port->rx_conf[queue_id].offloads &= ~single_offload;
15619
15620         cmd_reconfig_device_queue(port_id, 1, 1);
15621 }
15622
15623 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15624         .f = cmd_config_per_queue_rx_offload_parsed,
15625         .data = NULL,
15626         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15627                     "vlan_strip|ipv4_cksum|"
15628                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15629                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15630                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15631                     "keep_crc on|off",
15632         .tokens = {
15633                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15634                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15635                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15636                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15637                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15638                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15639                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15640                 NULL,
15641         }
15642 };
15643
15644 /* Get Tx offloads capabilities */
15645 struct cmd_tx_offload_get_capa_result {
15646         cmdline_fixed_string_t show;
15647         cmdline_fixed_string_t port;
15648         portid_t port_id;
15649         cmdline_fixed_string_t tx_offload;
15650         cmdline_fixed_string_t capabilities;
15651 };
15652
15653 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15654         TOKEN_STRING_INITIALIZER
15655                 (struct cmd_tx_offload_get_capa_result,
15656                  show, "show");
15657 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15658         TOKEN_STRING_INITIALIZER
15659                 (struct cmd_tx_offload_get_capa_result,
15660                  port, "port");
15661 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15662         TOKEN_NUM_INITIALIZER
15663                 (struct cmd_tx_offload_get_capa_result,
15664                  port_id, RTE_UINT16);
15665 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15666         TOKEN_STRING_INITIALIZER
15667                 (struct cmd_tx_offload_get_capa_result,
15668                  tx_offload, "tx_offload");
15669 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_tx_offload_get_capa_result,
15672                  capabilities, "capabilities");
15673
15674 static void
15675 print_tx_offloads(uint64_t offloads)
15676 {
15677         uint64_t single_offload;
15678         int begin;
15679         int end;
15680         int bit;
15681
15682         if (offloads == 0)
15683                 return;
15684
15685         begin = __builtin_ctzll(offloads);
15686         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15687
15688         single_offload = 1ULL << begin;
15689         for (bit = begin; bit < end; bit++) {
15690                 if (offloads & single_offload)
15691                         printf(" %s",
15692                                rte_eth_dev_tx_offload_name(single_offload));
15693                 single_offload <<= 1;
15694         }
15695 }
15696
15697 static void
15698 cmd_tx_offload_get_capa_parsed(
15699         void *parsed_result,
15700         __rte_unused struct cmdline *cl,
15701         __rte_unused void *data)
15702 {
15703         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15704         struct rte_eth_dev_info dev_info;
15705         portid_t port_id = res->port_id;
15706         uint64_t queue_offloads;
15707         uint64_t port_offloads;
15708         int ret;
15709
15710         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15711         if (ret != 0)
15712                 return;
15713
15714         queue_offloads = dev_info.tx_queue_offload_capa;
15715         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15716
15717         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15718         printf("  Per Queue :");
15719         print_tx_offloads(queue_offloads);
15720
15721         printf("\n");
15722         printf("  Per Port  :");
15723         print_tx_offloads(port_offloads);
15724         printf("\n\n");
15725 }
15726
15727 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15728         .f = cmd_tx_offload_get_capa_parsed,
15729         .data = NULL,
15730         .help_str = "show port <port_id> tx_offload capabilities",
15731         .tokens = {
15732                 (void *)&cmd_tx_offload_get_capa_show,
15733                 (void *)&cmd_tx_offload_get_capa_port,
15734                 (void *)&cmd_tx_offload_get_capa_port_id,
15735                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15736                 (void *)&cmd_tx_offload_get_capa_capabilities,
15737                 NULL,
15738         }
15739 };
15740
15741 /* Get Tx offloads configuration */
15742 struct cmd_tx_offload_get_configuration_result {
15743         cmdline_fixed_string_t show;
15744         cmdline_fixed_string_t port;
15745         portid_t port_id;
15746         cmdline_fixed_string_t tx_offload;
15747         cmdline_fixed_string_t configuration;
15748 };
15749
15750 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15751         TOKEN_STRING_INITIALIZER
15752                 (struct cmd_tx_offload_get_configuration_result,
15753                  show, "show");
15754 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15755         TOKEN_STRING_INITIALIZER
15756                 (struct cmd_tx_offload_get_configuration_result,
15757                  port, "port");
15758 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15759         TOKEN_NUM_INITIALIZER
15760                 (struct cmd_tx_offload_get_configuration_result,
15761                  port_id, RTE_UINT16);
15762 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15763         TOKEN_STRING_INITIALIZER
15764                 (struct cmd_tx_offload_get_configuration_result,
15765                  tx_offload, "tx_offload");
15766 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15767         TOKEN_STRING_INITIALIZER
15768                 (struct cmd_tx_offload_get_configuration_result,
15769                  configuration, "configuration");
15770
15771 static void
15772 cmd_tx_offload_get_configuration_parsed(
15773         void *parsed_result,
15774         __rte_unused struct cmdline *cl,
15775         __rte_unused void *data)
15776 {
15777         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15778         struct rte_eth_dev_info dev_info;
15779         portid_t port_id = res->port_id;
15780         struct rte_port *port = &ports[port_id];
15781         uint64_t port_offloads;
15782         uint64_t queue_offloads;
15783         uint16_t nb_tx_queues;
15784         int q;
15785         int ret;
15786
15787         printf("Tx Offloading Configuration of port %d :\n", port_id);
15788
15789         port_offloads = port->dev_conf.txmode.offloads;
15790         printf("  Port :");
15791         print_tx_offloads(port_offloads);
15792         printf("\n");
15793
15794         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15795         if (ret != 0)
15796                 return;
15797
15798         nb_tx_queues = dev_info.nb_tx_queues;
15799         for (q = 0; q < nb_tx_queues; q++) {
15800                 queue_offloads = port->tx_conf[q].offloads;
15801                 printf("  Queue[%2d] :", q);
15802                 print_tx_offloads(queue_offloads);
15803                 printf("\n");
15804         }
15805         printf("\n");
15806 }
15807
15808 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15809         .f = cmd_tx_offload_get_configuration_parsed,
15810         .data = NULL,
15811         .help_str = "show port <port_id> tx_offload configuration",
15812         .tokens = {
15813                 (void *)&cmd_tx_offload_get_configuration_show,
15814                 (void *)&cmd_tx_offload_get_configuration_port,
15815                 (void *)&cmd_tx_offload_get_configuration_port_id,
15816                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15817                 (void *)&cmd_tx_offload_get_configuration_configuration,
15818                 NULL,
15819         }
15820 };
15821
15822 /* Enable/Disable a per port offloading */
15823 struct cmd_config_per_port_tx_offload_result {
15824         cmdline_fixed_string_t port;
15825         cmdline_fixed_string_t config;
15826         portid_t port_id;
15827         cmdline_fixed_string_t tx_offload;
15828         cmdline_fixed_string_t offload;
15829         cmdline_fixed_string_t on_off;
15830 };
15831
15832 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15833         TOKEN_STRING_INITIALIZER
15834                 (struct cmd_config_per_port_tx_offload_result,
15835                  port, "port");
15836 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15837         TOKEN_STRING_INITIALIZER
15838                 (struct cmd_config_per_port_tx_offload_result,
15839                  config, "config");
15840 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15841         TOKEN_NUM_INITIALIZER
15842                 (struct cmd_config_per_port_tx_offload_result,
15843                  port_id, RTE_UINT16);
15844 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15845         TOKEN_STRING_INITIALIZER
15846                 (struct cmd_config_per_port_tx_offload_result,
15847                  tx_offload, "tx_offload");
15848 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15849         TOKEN_STRING_INITIALIZER
15850                 (struct cmd_config_per_port_tx_offload_result,
15851                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15852                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15853                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15854                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15855                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15856                           "send_on_timestamp");
15857 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15858         TOKEN_STRING_INITIALIZER
15859                 (struct cmd_config_per_port_tx_offload_result,
15860                  on_off, "on#off");
15861
15862 static uint64_t
15863 search_tx_offload(const char *name)
15864 {
15865         uint64_t single_offload;
15866         const char *single_name;
15867         int found = 0;
15868         unsigned int bit;
15869
15870         single_offload = 1;
15871         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15872                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15873                 if (single_name == NULL)
15874                         break;
15875                 if (!strcasecmp(single_name, name)) {
15876                         found = 1;
15877                         break;
15878                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15879                         break;
15880                 single_offload <<= 1;
15881         }
15882
15883         if (found)
15884                 return single_offload;
15885
15886         return 0;
15887 }
15888
15889 static void
15890 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15891                                 __rte_unused struct cmdline *cl,
15892                                 __rte_unused void *data)
15893 {
15894         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15895         portid_t port_id = res->port_id;
15896         struct rte_eth_dev_info dev_info;
15897         struct rte_port *port = &ports[port_id];
15898         uint64_t single_offload;
15899         uint16_t nb_tx_queues;
15900         int q;
15901         int ret;
15902
15903         if (port->port_status != RTE_PORT_STOPPED) {
15904                 printf("Error: Can't config offload when Port %d "
15905                        "is not stopped\n", port_id);
15906                 return;
15907         }
15908
15909         single_offload = search_tx_offload(res->offload);
15910         if (single_offload == 0) {
15911                 printf("Unknown offload name: %s\n", res->offload);
15912                 return;
15913         }
15914
15915         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15916         if (ret != 0)
15917                 return;
15918
15919         nb_tx_queues = dev_info.nb_tx_queues;
15920         if (!strcmp(res->on_off, "on")) {
15921                 port->dev_conf.txmode.offloads |= single_offload;
15922                 for (q = 0; q < nb_tx_queues; q++)
15923                         port->tx_conf[q].offloads |= single_offload;
15924         } else {
15925                 port->dev_conf.txmode.offloads &= ~single_offload;
15926                 for (q = 0; q < nb_tx_queues; q++)
15927                         port->tx_conf[q].offloads &= ~single_offload;
15928         }
15929
15930         cmd_reconfig_device_queue(port_id, 1, 1);
15931 }
15932
15933 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15934         .f = cmd_config_per_port_tx_offload_parsed,
15935         .data = NULL,
15936         .help_str = "port config <port_id> tx_offload "
15937                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15938                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15939                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15940                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15941                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15942                     "send_on_timestamp on|off",
15943         .tokens = {
15944                 (void *)&cmd_config_per_port_tx_offload_result_port,
15945                 (void *)&cmd_config_per_port_tx_offload_result_config,
15946                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15947                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15948                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15949                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15950                 NULL,
15951         }
15952 };
15953
15954 /* Enable/Disable a per queue offloading */
15955 struct cmd_config_per_queue_tx_offload_result {
15956         cmdline_fixed_string_t port;
15957         portid_t port_id;
15958         cmdline_fixed_string_t txq;
15959         uint16_t queue_id;
15960         cmdline_fixed_string_t tx_offload;
15961         cmdline_fixed_string_t offload;
15962         cmdline_fixed_string_t on_off;
15963 };
15964
15965 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15966         TOKEN_STRING_INITIALIZER
15967                 (struct cmd_config_per_queue_tx_offload_result,
15968                  port, "port");
15969 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15970         TOKEN_NUM_INITIALIZER
15971                 (struct cmd_config_per_queue_tx_offload_result,
15972                  port_id, RTE_UINT16);
15973 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15974         TOKEN_STRING_INITIALIZER
15975                 (struct cmd_config_per_queue_tx_offload_result,
15976                  txq, "txq");
15977 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15978         TOKEN_NUM_INITIALIZER
15979                 (struct cmd_config_per_queue_tx_offload_result,
15980                  queue_id, RTE_UINT16);
15981 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15982         TOKEN_STRING_INITIALIZER
15983                 (struct cmd_config_per_queue_tx_offload_result,
15984                  tx_offload, "tx_offload");
15985 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15986         TOKEN_STRING_INITIALIZER
15987                 (struct cmd_config_per_queue_tx_offload_result,
15988                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15989                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15990                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15991                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15992                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
15993 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
15994         TOKEN_STRING_INITIALIZER
15995                 (struct cmd_config_per_queue_tx_offload_result,
15996                  on_off, "on#off");
15997
15998 static void
15999 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16000                                 __rte_unused struct cmdline *cl,
16001                                 __rte_unused void *data)
16002 {
16003         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16004         struct rte_eth_dev_info dev_info;
16005         portid_t port_id = res->port_id;
16006         uint16_t queue_id = res->queue_id;
16007         struct rte_port *port = &ports[port_id];
16008         uint64_t single_offload;
16009         int ret;
16010
16011         if (port->port_status != RTE_PORT_STOPPED) {
16012                 printf("Error: Can't config offload when Port %d "
16013                        "is not stopped\n", port_id);
16014                 return;
16015         }
16016
16017         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16018         if (ret != 0)
16019                 return;
16020
16021         if (queue_id >= dev_info.nb_tx_queues) {
16022                 printf("Error: input queue_id should be 0 ... "
16023                        "%d\n", dev_info.nb_tx_queues - 1);
16024                 return;
16025         }
16026
16027         single_offload = search_tx_offload(res->offload);
16028         if (single_offload == 0) {
16029                 printf("Unknown offload name: %s\n", res->offload);
16030                 return;
16031         }
16032
16033         if (!strcmp(res->on_off, "on"))
16034                 port->tx_conf[queue_id].offloads |= single_offload;
16035         else
16036                 port->tx_conf[queue_id].offloads &= ~single_offload;
16037
16038         cmd_reconfig_device_queue(port_id, 1, 1);
16039 }
16040
16041 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16042         .f = cmd_config_per_queue_tx_offload_parsed,
16043         .data = NULL,
16044         .help_str = "port <port_id> txq <queue_id> tx_offload "
16045                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16046                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16047                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16048                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16049                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16050                     "on|off",
16051         .tokens = {
16052                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16053                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16054                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16055                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16056                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16057                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16058                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16059                 NULL,
16060         }
16061 };
16062
16063 /* *** configure tx_metadata for specific port *** */
16064 struct cmd_config_tx_metadata_specific_result {
16065         cmdline_fixed_string_t port;
16066         cmdline_fixed_string_t keyword;
16067         uint16_t port_id;
16068         cmdline_fixed_string_t item;
16069         uint32_t value;
16070 };
16071
16072 static void
16073 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16074                                 __rte_unused struct cmdline *cl,
16075                                 __rte_unused void *data)
16076 {
16077         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16078
16079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16080                 return;
16081         ports[res->port_id].tx_metadata = res->value;
16082         /* Add/remove callback to insert valid metadata in every Tx packet. */
16083         if (ports[res->port_id].tx_metadata)
16084                 add_tx_md_callback(res->port_id);
16085         else
16086                 remove_tx_md_callback(res->port_id);
16087         rte_flow_dynf_metadata_register();
16088 }
16089
16090 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16091         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16092                         port, "port");
16093 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16094         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16095                         keyword, "config");
16096 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16097         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16098                         port_id, RTE_UINT16);
16099 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16100         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16101                         item, "tx_metadata");
16102 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16103         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16104                         value, RTE_UINT32);
16105
16106 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16107         .f = cmd_config_tx_metadata_specific_parsed,
16108         .data = NULL,
16109         .help_str = "port config <port_id> tx_metadata <value>",
16110         .tokens = {
16111                 (void *)&cmd_config_tx_metadata_specific_port,
16112                 (void *)&cmd_config_tx_metadata_specific_keyword,
16113                 (void *)&cmd_config_tx_metadata_specific_id,
16114                 (void *)&cmd_config_tx_metadata_specific_item,
16115                 (void *)&cmd_config_tx_metadata_specific_value,
16116                 NULL,
16117         },
16118 };
16119
16120 /* *** set dynf *** */
16121 struct cmd_config_tx_dynf_specific_result {
16122         cmdline_fixed_string_t port;
16123         cmdline_fixed_string_t keyword;
16124         uint16_t port_id;
16125         cmdline_fixed_string_t item;
16126         cmdline_fixed_string_t name;
16127         cmdline_fixed_string_t value;
16128 };
16129
16130 static void
16131 cmd_config_dynf_specific_parsed(void *parsed_result,
16132                                 __rte_unused struct cmdline *cl,
16133                                 __rte_unused void *data)
16134 {
16135         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16136         struct rte_mbuf_dynflag desc_flag;
16137         int flag;
16138         uint64_t old_port_flags;
16139
16140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16141                 return;
16142         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16143         if (flag <= 0) {
16144                 if (strlcpy(desc_flag.name, res->name,
16145                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16146                         printf("Flag name too long\n");
16147                         return;
16148                 }
16149                 desc_flag.flags = 0;
16150                 flag = rte_mbuf_dynflag_register(&desc_flag);
16151                 if (flag < 0) {
16152                         printf("Can't register flag\n");
16153                         return;
16154                 }
16155                 strcpy(dynf_names[flag], desc_flag.name);
16156         }
16157         old_port_flags = ports[res->port_id].mbuf_dynf;
16158         if (!strcmp(res->value, "set")) {
16159                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16160                 if (old_port_flags == 0)
16161                         add_tx_dynf_callback(res->port_id);
16162         } else {
16163                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16164                 if (ports[res->port_id].mbuf_dynf == 0)
16165                         remove_tx_dynf_callback(res->port_id);
16166         }
16167 }
16168
16169 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16170         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16171                         keyword, "port");
16172 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16173         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16174                         keyword, "config");
16175 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16176         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16177                         port_id, RTE_UINT16);
16178 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16179         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16180                         item, "dynf");
16181 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16182         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16183                         name, NULL);
16184 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16185         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16186                         value, "set#clear");
16187
16188 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16189         .f = cmd_config_dynf_specific_parsed,
16190         .data = NULL,
16191         .help_str = "port config <port id> dynf <name> set|clear",
16192         .tokens = {
16193                 (void *)&cmd_config_tx_dynf_specific_port,
16194                 (void *)&cmd_config_tx_dynf_specific_keyword,
16195                 (void *)&cmd_config_tx_dynf_specific_port_id,
16196                 (void *)&cmd_config_tx_dynf_specific_item,
16197                 (void *)&cmd_config_tx_dynf_specific_name,
16198                 (void *)&cmd_config_tx_dynf_specific_value,
16199                 NULL,
16200         },
16201 };
16202
16203 /* *** display tx_metadata per port configuration *** */
16204 struct cmd_show_tx_metadata_result {
16205         cmdline_fixed_string_t cmd_show;
16206         cmdline_fixed_string_t cmd_port;
16207         cmdline_fixed_string_t cmd_keyword;
16208         portid_t cmd_pid;
16209 };
16210
16211 static void
16212 cmd_show_tx_metadata_parsed(void *parsed_result,
16213                 __rte_unused struct cmdline *cl,
16214                 __rte_unused void *data)
16215 {
16216         struct cmd_show_tx_metadata_result *res = parsed_result;
16217
16218         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16219                 printf("invalid port id %u\n", res->cmd_pid);
16220                 return;
16221         }
16222         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16223                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16224                        ports[res->cmd_pid].tx_metadata);
16225         }
16226 }
16227
16228 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16229         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16230                         cmd_show, "show");
16231 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16232         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16233                         cmd_port, "port");
16234 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16235         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16236                         cmd_pid, RTE_UINT16);
16237 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16238         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16239                         cmd_keyword, "tx_metadata");
16240
16241 cmdline_parse_inst_t cmd_show_tx_metadata = {
16242         .f = cmd_show_tx_metadata_parsed,
16243         .data = NULL,
16244         .help_str = "show port <port_id> tx_metadata",
16245         .tokens = {
16246                 (void *)&cmd_show_tx_metadata_show,
16247                 (void *)&cmd_show_tx_metadata_port,
16248                 (void *)&cmd_show_tx_metadata_pid,
16249                 (void *)&cmd_show_tx_metadata_keyword,
16250                 NULL,
16251         },
16252 };
16253
16254 /* *** show fec capability per port configuration *** */
16255 struct cmd_show_fec_capability_result {
16256         cmdline_fixed_string_t cmd_show;
16257         cmdline_fixed_string_t cmd_port;
16258         cmdline_fixed_string_t cmd_fec;
16259         cmdline_fixed_string_t cmd_keyword;
16260         portid_t cmd_pid;
16261 };
16262
16263 static void
16264 cmd_show_fec_capability_parsed(void *parsed_result,
16265                 __rte_unused struct cmdline *cl,
16266                 __rte_unused void *data)
16267 {
16268 #define FEC_CAP_NUM 2
16269         struct cmd_show_fec_capability_result *res = parsed_result;
16270         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16271         unsigned int num = FEC_CAP_NUM;
16272         unsigned int ret_num;
16273         int ret;
16274
16275         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16276                 printf("Invalid port id %u\n", res->cmd_pid);
16277                 return;
16278         }
16279
16280         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16281         if (ret == -ENOTSUP) {
16282                 printf("Function not implemented\n");
16283                 return;
16284         } else if (ret < 0) {
16285                 printf("Get FEC capability failed\n");
16286                 return;
16287         }
16288
16289         ret_num = (unsigned int)ret;
16290         show_fec_capability(ret_num, speed_fec_capa);
16291 }
16292
16293 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16294         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16295                         cmd_show, "show");
16296 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16297         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16298                         cmd_port, "port");
16299 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16300         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16301                         cmd_pid, RTE_UINT16);
16302 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16303         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16304                         cmd_fec, "fec");
16305 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16306         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16307                         cmd_keyword, "capabilities");
16308
16309 cmdline_parse_inst_t cmd_show_capability = {
16310         .f = cmd_show_fec_capability_parsed,
16311         .data = NULL,
16312         .help_str = "show port <port_id> fec capabilities",
16313         .tokens = {
16314                 (void *)&cmd_show_fec_capability_show,
16315                 (void *)&cmd_show_fec_capability_port,
16316                 (void *)&cmd_show_fec_capability_pid,
16317                 (void *)&cmd_show_fec_capability_fec,
16318                 (void *)&cmd_show_fec_capability_keyword,
16319                 NULL,
16320         },
16321 };
16322
16323 /* *** show fec mode per port configuration *** */
16324 struct cmd_show_fec_metadata_result {
16325         cmdline_fixed_string_t cmd_show;
16326         cmdline_fixed_string_t cmd_port;
16327         cmdline_fixed_string_t cmd_keyword;
16328         portid_t cmd_pid;
16329 };
16330
16331 static void
16332 cmd_show_fec_mode_parsed(void *parsed_result,
16333                 __rte_unused struct cmdline *cl,
16334                 __rte_unused void *data)
16335 {
16336 #define FEC_NAME_SIZE 16
16337         struct cmd_show_fec_metadata_result *res = parsed_result;
16338         uint32_t mode;
16339         char buf[FEC_NAME_SIZE];
16340         int ret;
16341
16342         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16343                 printf("Invalid port id %u\n", res->cmd_pid);
16344                 return;
16345         }
16346         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16347         if (ret == -ENOTSUP) {
16348                 printf("Function not implemented\n");
16349                 return;
16350         } else if (ret < 0) {
16351                 printf("Get FEC mode failed\n");
16352                 return;
16353         }
16354
16355         switch (mode) {
16356         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16357                 strlcpy(buf, "off", sizeof(buf));
16358                 break;
16359         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16360                 strlcpy(buf, "auto", sizeof(buf));
16361                 break;
16362         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16363                 strlcpy(buf, "baser", sizeof(buf));
16364                 break;
16365         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16366                 strlcpy(buf, "rs", sizeof(buf));
16367                 break;
16368         default:
16369                 return;
16370         }
16371
16372         printf("%s\n", buf);
16373 }
16374
16375 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16376         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16377                         cmd_show, "show");
16378 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16379         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16380                         cmd_port, "port");
16381 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16382         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16383                         cmd_pid, RTE_UINT16);
16384 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16385         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16386                         cmd_keyword, "fec_mode");
16387
16388 cmdline_parse_inst_t cmd_show_fec_mode = {
16389         .f = cmd_show_fec_mode_parsed,
16390         .data = NULL,
16391         .help_str = "show port <port_id> fec_mode",
16392         .tokens = {
16393                 (void *)&cmd_show_fec_mode_show,
16394                 (void *)&cmd_show_fec_mode_port,
16395                 (void *)&cmd_show_fec_mode_pid,
16396                 (void *)&cmd_show_fec_mode_keyword,
16397                 NULL,
16398         },
16399 };
16400
16401 /* *** set fec mode per port configuration *** */
16402 struct cmd_set_port_fec_mode {
16403         cmdline_fixed_string_t set;
16404         cmdline_fixed_string_t port;
16405         portid_t port_id;
16406         cmdline_fixed_string_t fec_mode;
16407         cmdline_fixed_string_t fec_value;
16408 };
16409
16410 /* Common CLI fields for set fec mode */
16411 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16412         TOKEN_STRING_INITIALIZER
16413                 (struct cmd_set_port_fec_mode,
16414                  set, "set");
16415 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16416         TOKEN_STRING_INITIALIZER
16417                 (struct cmd_set_port_fec_mode,
16418                  port, "port");
16419 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16420         TOKEN_NUM_INITIALIZER
16421                 (struct cmd_set_port_fec_mode,
16422                  port_id, RTE_UINT16);
16423 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16424         TOKEN_STRING_INITIALIZER
16425                 (struct cmd_set_port_fec_mode,
16426                  fec_mode, "fec_mode");
16427 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16428         TOKEN_STRING_INITIALIZER
16429                 (struct cmd_set_port_fec_mode,
16430                  fec_value, NULL);
16431
16432 static void
16433 cmd_set_port_fec_mode_parsed(
16434         void *parsed_result,
16435         __rte_unused struct cmdline *cl,
16436         __rte_unused void *data)
16437 {
16438         struct cmd_set_port_fec_mode *res = parsed_result;
16439         uint16_t port_id = res->port_id;
16440         uint32_t mode;
16441         int ret;
16442
16443         ret = parse_fec_mode(res->fec_value, &mode);
16444         if (ret < 0) {
16445                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16446                         port_id);
16447                 return;
16448         }
16449
16450         ret = rte_eth_fec_set(port_id, mode);
16451         if (ret == -ENOTSUP) {
16452                 printf("Function not implemented\n");
16453                 return;
16454         } else if (ret < 0) {
16455                 printf("Set FEC mode failed\n");
16456                 return;
16457         }
16458 }
16459
16460 cmdline_parse_inst_t cmd_set_fec_mode = {
16461         .f = cmd_set_port_fec_mode_parsed,
16462         .data = NULL,
16463         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16464         .tokens = {
16465                 (void *)&cmd_set_port_fec_mode_set,
16466                 (void *)&cmd_set_port_fec_mode_port,
16467                 (void *)&cmd_set_port_fec_mode_port_id,
16468                 (void *)&cmd_set_port_fec_mode_str,
16469                 (void *)&cmd_set_port_fec_mode_value,
16470                 NULL,
16471         },
16472 };
16473
16474 /* show port supported ptypes */
16475
16476 /* Common result structure for show port ptypes */
16477 struct cmd_show_port_supported_ptypes_result {
16478         cmdline_fixed_string_t show;
16479         cmdline_fixed_string_t port;
16480         portid_t port_id;
16481         cmdline_fixed_string_t ptypes;
16482 };
16483
16484 /* Common CLI fields for show port ptypes */
16485 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16486         TOKEN_STRING_INITIALIZER
16487                 (struct cmd_show_port_supported_ptypes_result,
16488                  show, "show");
16489 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16490         TOKEN_STRING_INITIALIZER
16491                 (struct cmd_show_port_supported_ptypes_result,
16492                  port, "port");
16493 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16494         TOKEN_NUM_INITIALIZER
16495                 (struct cmd_show_port_supported_ptypes_result,
16496                  port_id, RTE_UINT16);
16497 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16498         TOKEN_STRING_INITIALIZER
16499                 (struct cmd_show_port_supported_ptypes_result,
16500                  ptypes, "ptypes");
16501
16502 static void
16503 cmd_show_port_supported_ptypes_parsed(
16504         void *parsed_result,
16505         __rte_unused struct cmdline *cl,
16506         __rte_unused void *data)
16507 {
16508 #define RSVD_PTYPE_MASK       0xf0000000
16509 #define MAX_PTYPES_PER_LAYER  16
16510 #define LTYPE_NAMESIZE        32
16511 #define PTYPE_NAMESIZE        256
16512         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16513         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16514         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16515         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16516         uint16_t port_id = res->port_id;
16517         int ret, i;
16518
16519         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16520         if (ret < 0)
16521                 return;
16522
16523         while (ptype_mask != RSVD_PTYPE_MASK) {
16524
16525                 switch (ptype_mask) {
16526                 case RTE_PTYPE_L2_MASK:
16527                         strlcpy(ltype, "L2", sizeof(ltype));
16528                         break;
16529                 case RTE_PTYPE_L3_MASK:
16530                         strlcpy(ltype, "L3", sizeof(ltype));
16531                         break;
16532                 case RTE_PTYPE_L4_MASK:
16533                         strlcpy(ltype, "L4", sizeof(ltype));
16534                         break;
16535                 case RTE_PTYPE_TUNNEL_MASK:
16536                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16537                         break;
16538                 case RTE_PTYPE_INNER_L2_MASK:
16539                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16540                         break;
16541                 case RTE_PTYPE_INNER_L3_MASK:
16542                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16543                         break;
16544                 case RTE_PTYPE_INNER_L4_MASK:
16545                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16546                         break;
16547                 default:
16548                         return;
16549                 }
16550
16551                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16552                                                        ptype_mask, ptypes,
16553                                                        MAX_PTYPES_PER_LAYER);
16554
16555                 if (ret > 0)
16556                         printf("Supported %s ptypes:\n", ltype);
16557                 else
16558                         printf("%s ptypes unsupported\n", ltype);
16559
16560                 for (i = 0; i < ret; ++i) {
16561                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16562                         printf("%s\n", buf);
16563                 }
16564
16565                 ptype_mask <<= 4;
16566         }
16567 }
16568
16569 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16570         .f = cmd_show_port_supported_ptypes_parsed,
16571         .data = NULL,
16572         .help_str = "show port <port_id> ptypes",
16573         .tokens = {
16574                 (void *)&cmd_show_port_supported_ptypes_show,
16575                 (void *)&cmd_show_port_supported_ptypes_port,
16576                 (void *)&cmd_show_port_supported_ptypes_port_id,
16577                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16578                 NULL,
16579         },
16580 };
16581
16582 /* *** display rx/tx descriptor status *** */
16583 struct cmd_show_rx_tx_desc_status_result {
16584         cmdline_fixed_string_t cmd_show;
16585         cmdline_fixed_string_t cmd_port;
16586         cmdline_fixed_string_t cmd_keyword;
16587         cmdline_fixed_string_t cmd_desc;
16588         cmdline_fixed_string_t cmd_status;
16589         portid_t cmd_pid;
16590         portid_t cmd_qid;
16591         portid_t cmd_did;
16592 };
16593
16594 static void
16595 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16596                 __rte_unused struct cmdline *cl,
16597                 __rte_unused void *data)
16598 {
16599         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16600         int rc;
16601
16602         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16603                 printf("invalid port id %u\n", res->cmd_pid);
16604                 return;
16605         }
16606
16607         if (!strcmp(res->cmd_keyword, "rxq")) {
16608                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16609                                              res->cmd_did);
16610                 if (rc < 0) {
16611                         printf("Invalid queueid = %d\n", res->cmd_qid);
16612                         return;
16613                 }
16614                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16615                         printf("Desc status = AVAILABLE\n");
16616                 else if (rc == RTE_ETH_RX_DESC_DONE)
16617                         printf("Desc status = DONE\n");
16618                 else
16619                         printf("Desc status = UNAVAILABLE\n");
16620         } else if (!strcmp(res->cmd_keyword, "txq")) {
16621                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16622                                              res->cmd_did);
16623                 if (rc < 0) {
16624                         printf("Invalid queueid = %d\n", res->cmd_qid);
16625                         return;
16626                 }
16627                 if (rc == RTE_ETH_TX_DESC_FULL)
16628                         printf("Desc status = FULL\n");
16629                 else if (rc == RTE_ETH_TX_DESC_DONE)
16630                         printf("Desc status = DONE\n");
16631                 else
16632                         printf("Desc status = UNAVAILABLE\n");
16633         }
16634 }
16635
16636 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16637         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16638                         cmd_show, "show");
16639 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16640         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16641                         cmd_port, "port");
16642 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16643         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16644                         cmd_pid, RTE_UINT16);
16645 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16646         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16647                         cmd_keyword, "rxq#txq");
16648 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16649         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16650                         cmd_qid, RTE_UINT16);
16651 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16652         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16653                         cmd_desc, "desc");
16654 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16655         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16656                         cmd_did, RTE_UINT16);
16657 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16658         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16659                         cmd_status, "status");
16660 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16661         .f = cmd_show_rx_tx_desc_status_parsed,
16662         .data = NULL,
16663         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16664                 "status",
16665         .tokens = {
16666                 (void *)&cmd_show_rx_tx_desc_status_show,
16667                 (void *)&cmd_show_rx_tx_desc_status_port,
16668                 (void *)&cmd_show_rx_tx_desc_status_pid,
16669                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16670                 (void *)&cmd_show_rx_tx_desc_status_qid,
16671                 (void *)&cmd_show_rx_tx_desc_status_desc,
16672                 (void *)&cmd_show_rx_tx_desc_status_did,
16673                 (void *)&cmd_show_rx_tx_desc_status_status,
16674                 NULL,
16675         },
16676 };
16677
16678 /* Common result structure for set port ptypes */
16679 struct cmd_set_port_ptypes_result {
16680         cmdline_fixed_string_t set;
16681         cmdline_fixed_string_t port;
16682         portid_t port_id;
16683         cmdline_fixed_string_t ptype_mask;
16684         uint32_t mask;
16685 };
16686
16687 /* Common CLI fields for set port ptypes */
16688 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16689         TOKEN_STRING_INITIALIZER
16690                 (struct cmd_set_port_ptypes_result,
16691                  set, "set");
16692 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16693         TOKEN_STRING_INITIALIZER
16694                 (struct cmd_set_port_ptypes_result,
16695                  port, "port");
16696 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16697         TOKEN_NUM_INITIALIZER
16698                 (struct cmd_set_port_ptypes_result,
16699                  port_id, RTE_UINT16);
16700 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16701         TOKEN_STRING_INITIALIZER
16702                 (struct cmd_set_port_ptypes_result,
16703                  ptype_mask, "ptype_mask");
16704 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16705         TOKEN_NUM_INITIALIZER
16706                 (struct cmd_set_port_ptypes_result,
16707                  mask, RTE_UINT32);
16708
16709 static void
16710 cmd_set_port_ptypes_parsed(
16711         void *parsed_result,
16712         __rte_unused struct cmdline *cl,
16713         __rte_unused void *data)
16714 {
16715         struct cmd_set_port_ptypes_result *res = parsed_result;
16716 #define PTYPE_NAMESIZE        256
16717         char ptype_name[PTYPE_NAMESIZE];
16718         uint16_t port_id = res->port_id;
16719         uint32_t ptype_mask = res->mask;
16720         int ret, i;
16721
16722         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16723                                                NULL, 0);
16724         if (ret <= 0) {
16725                 printf("Port %d doesn't support any ptypes.\n", port_id);
16726                 return;
16727         }
16728
16729         uint32_t ptypes[ret];
16730
16731         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16732         if (ret < 0) {
16733                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16734                 return;
16735         }
16736
16737         printf("Successfully set following ptypes for Port %d\n", port_id);
16738         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16739                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16740                 printf("%s\n", ptype_name);
16741         }
16742
16743         clear_ptypes = false;
16744 }
16745
16746 cmdline_parse_inst_t cmd_set_port_ptypes = {
16747         .f = cmd_set_port_ptypes_parsed,
16748         .data = NULL,
16749         .help_str = "set port <port_id> ptype_mask <mask>",
16750         .tokens = {
16751                 (void *)&cmd_set_port_ptypes_set,
16752                 (void *)&cmd_set_port_ptypes_port,
16753                 (void *)&cmd_set_port_ptypes_port_id,
16754                 (void *)&cmd_set_port_ptypes_mask_str,
16755                 (void *)&cmd_set_port_ptypes_mask_u32,
16756                 NULL,
16757         },
16758 };
16759
16760 /* *** display mac addresses added to a port *** */
16761 struct cmd_showport_macs_result {
16762         cmdline_fixed_string_t cmd_show;
16763         cmdline_fixed_string_t cmd_port;
16764         cmdline_fixed_string_t cmd_keyword;
16765         portid_t cmd_pid;
16766 };
16767
16768 static void
16769 cmd_showport_macs_parsed(void *parsed_result,
16770                 __rte_unused struct cmdline *cl,
16771                 __rte_unused void *data)
16772 {
16773         struct cmd_showport_macs_result *res = parsed_result;
16774
16775         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16776                 return;
16777
16778         if (!strcmp(res->cmd_keyword, "macs"))
16779                 show_macs(res->cmd_pid);
16780         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16781                 show_mcast_macs(res->cmd_pid);
16782 }
16783
16784 cmdline_parse_token_string_t cmd_showport_macs_show =
16785         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16786                         cmd_show, "show");
16787 cmdline_parse_token_string_t cmd_showport_macs_port =
16788         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16789                         cmd_port, "port");
16790 cmdline_parse_token_num_t cmd_showport_macs_pid =
16791         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16792                         cmd_pid, RTE_UINT16);
16793 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16794         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16795                         cmd_keyword, "macs#mcast_macs");
16796
16797 cmdline_parse_inst_t cmd_showport_macs = {
16798         .f = cmd_showport_macs_parsed,
16799         .data = NULL,
16800         .help_str = "show port <port_id> macs|mcast_macs",
16801         .tokens = {
16802                 (void *)&cmd_showport_macs_show,
16803                 (void *)&cmd_showport_macs_port,
16804                 (void *)&cmd_showport_macs_pid,
16805                 (void *)&cmd_showport_macs_keyword,
16806                 NULL,
16807         },
16808 };
16809
16810 /* ******************************************************************************** */
16811
16812 /* list of instructions */
16813 cmdline_parse_ctx_t main_ctx[] = {
16814         (cmdline_parse_inst_t *)&cmd_help_brief,
16815         (cmdline_parse_inst_t *)&cmd_help_long,
16816         (cmdline_parse_inst_t *)&cmd_quit,
16817         (cmdline_parse_inst_t *)&cmd_load_from_file,
16818         (cmdline_parse_inst_t *)&cmd_showport,
16819         (cmdline_parse_inst_t *)&cmd_showqueue,
16820         (cmdline_parse_inst_t *)&cmd_showeeprom,
16821         (cmdline_parse_inst_t *)&cmd_showportall,
16822         (cmdline_parse_inst_t *)&cmd_showdevice,
16823         (cmdline_parse_inst_t *)&cmd_showcfg,
16824         (cmdline_parse_inst_t *)&cmd_showfwdall,
16825         (cmdline_parse_inst_t *)&cmd_start,
16826         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16827         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16828         (cmdline_parse_inst_t *)&cmd_set_link_up,
16829         (cmdline_parse_inst_t *)&cmd_set_link_down,
16830         (cmdline_parse_inst_t *)&cmd_reset,
16831         (cmdline_parse_inst_t *)&cmd_set_numbers,
16832         (cmdline_parse_inst_t *)&cmd_set_log,
16833         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16834         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16835         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16836         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16837         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16838         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16839         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16840         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16841         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16842         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16843         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16844         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16845         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16846         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16847         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16848         (cmdline_parse_inst_t *)&cmd_set_link_check,
16849         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16850         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16851         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16852         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16853 #ifdef RTE_NET_BOND
16854         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16855         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16856         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16857         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16858         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16859         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16860         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16861         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16862         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16863         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16864         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16865 #endif
16866         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16867         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16868         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16869         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16870         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16871         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16872         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16873         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16874         (cmdline_parse_inst_t *)&cmd_csum_set,
16875         (cmdline_parse_inst_t *)&cmd_csum_show,
16876         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16877         (cmdline_parse_inst_t *)&cmd_tso_set,
16878         (cmdline_parse_inst_t *)&cmd_tso_show,
16879         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16880         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16881         (cmdline_parse_inst_t *)&cmd_gro_enable,
16882         (cmdline_parse_inst_t *)&cmd_gro_flush,
16883         (cmdline_parse_inst_t *)&cmd_gro_show,
16884         (cmdline_parse_inst_t *)&cmd_gso_enable,
16885         (cmdline_parse_inst_t *)&cmd_gso_size,
16886         (cmdline_parse_inst_t *)&cmd_gso_show,
16887         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16888         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16889         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16890         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16891         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16892         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16893         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16894         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16895         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16896         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16897         (cmdline_parse_inst_t *)&cmd_config_dcb,
16898         (cmdline_parse_inst_t *)&cmd_read_reg,
16899         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16900         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16901         (cmdline_parse_inst_t *)&cmd_write_reg,
16902         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16903         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16904         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16905         (cmdline_parse_inst_t *)&cmd_stop,
16906         (cmdline_parse_inst_t *)&cmd_mac_addr,
16907         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16908         (cmdline_parse_inst_t *)&cmd_set_qmap,
16909         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16910         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
16911         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
16912         (cmdline_parse_inst_t *)&cmd_operate_port,
16913         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16914         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16915         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16916         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
16917         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
16918         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16919         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16920         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16921         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16922         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16923         (cmdline_parse_inst_t *)&cmd_config_mtu,
16924         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16925         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
16926         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16927         (cmdline_parse_inst_t *)&cmd_config_rss,
16928         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16929         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16930         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
16931         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16932         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16933         (cmdline_parse_inst_t *)&cmd_showport_reta,
16934         (cmdline_parse_inst_t *)&cmd_showport_macs,
16935         (cmdline_parse_inst_t *)&cmd_config_burst,
16936         (cmdline_parse_inst_t *)&cmd_config_thresh,
16937         (cmdline_parse_inst_t *)&cmd_config_threshold,
16938         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16939         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16940         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16941         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16942         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16943         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16944         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16945         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16946         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16947         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16948         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16949         (cmdline_parse_inst_t *)&cmd_dump,
16950         (cmdline_parse_inst_t *)&cmd_dump_one,
16951 #ifdef RTE_NET_I40E
16952         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16953 #endif
16954         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16955         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16956         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16957         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16958         (cmdline_parse_inst_t *)&cmd_flow,
16959         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16960         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16961         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16962         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16963         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16964         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16965         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16966         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16967         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16968         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16969         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16970         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16971         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16972         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16973         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16974         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16975         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16976         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16977         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16978         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16979         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16980         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16981         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16982         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16983         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16984         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16985         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16986         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16987         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16988         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16989         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16990         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16991         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16992         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16993         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16994         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16995         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16996         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16997         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16998         (cmdline_parse_inst_t *)&cmd_set_vxlan,
16999         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17000         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17001         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17002         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17003         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17004         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17005         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17006         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17007         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17008         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17009         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17010         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17011         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17012         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17013         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17014         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17015         (cmdline_parse_inst_t *)&cmd_ddp_add,
17016         (cmdline_parse_inst_t *)&cmd_ddp_del,
17017         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17018         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17019         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17020         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17021         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17022         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17023         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17024         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17025         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17026         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17027         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17028         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17029
17030         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17031         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17032         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17033         (cmdline_parse_inst_t *)&cmd_queue_region,
17034         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17035         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17036         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17037         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17038         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17039         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17040         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17041         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17042         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17043         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17044         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17045         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17046         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17047         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17048         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17049         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17050         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17051         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17052         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17053         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17054         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17055         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17056         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17057         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17058         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17059         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17060         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17061         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17062         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17063         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17064         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17065         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17066         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17067         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17068         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17069         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17070 #ifdef RTE_LIB_BPF
17071         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17072         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17073 #endif
17074         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17075         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17076         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17077         (cmdline_parse_inst_t *)&cmd_set_raw,
17078         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17079         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17080         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17081         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17082         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17083         (cmdline_parse_inst_t *)&cmd_show_capability,
17084         NULL,
17085 };
17086
17087 /* read cmdline commands from file */
17088 void
17089 cmdline_read_from_file(const char *filename)
17090 {
17091         struct cmdline *cl;
17092
17093         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17094         if (cl == NULL) {
17095                 printf("Failed to create file based cmdline context: %s\n",
17096                        filename);
17097                 return;
17098         }
17099
17100         cmdline_interact(cl);
17101         cmdline_quit(cl);
17102
17103         cmdline_free(cl);
17104
17105         printf("Read CLI commands from %s\n", filename);
17106 }
17107
17108 /* prompt function, called from main on MAIN lcore */
17109 void
17110 prompt(void)
17111 {
17112         /* initialize non-constant commands */
17113         cmd_set_fwd_mode_init();
17114         cmd_set_fwd_retry_mode_init();
17115
17116         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17117         if (testpmd_cl == NULL)
17118                 return;
17119         cmdline_interact(testpmd_cl);
17120         cmdline_stdin_exit(testpmd_cl);
17121 }
17122
17123 void
17124 prompt_exit(void)
17125 {
17126         if (testpmd_cl != NULL)
17127                 cmdline_quit(testpmd_cl);
17128 }
17129
17130 static void
17131 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17132 {
17133         if (id == (portid_t)RTE_PORT_ALL) {
17134                 portid_t pid;
17135
17136                 RTE_ETH_FOREACH_DEV(pid) {
17137                         /* check if need_reconfig has been set to 1 */
17138                         if (ports[pid].need_reconfig == 0)
17139                                 ports[pid].need_reconfig = dev;
17140                         /* check if need_reconfig_queues has been set to 1 */
17141                         if (ports[pid].need_reconfig_queues == 0)
17142                                 ports[pid].need_reconfig_queues = queue;
17143                 }
17144         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17145                 /* check if need_reconfig has been set to 1 */
17146                 if (ports[id].need_reconfig == 0)
17147                         ports[id].need_reconfig = dev;
17148                 /* check if need_reconfig_queues has been set to 1 */
17149                 if (ports[id].need_reconfig_queues == 0)
17150                         ports[id].need_reconfig_queues = queue;
17151         }
17152 }