596dd239fe7640519129b1e4548da43d1be6865c
[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|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) (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|ecpri|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|ecpri (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                         ETH_RSS_ECPRI;
2169         else if (!strcmp(res->value, "eth"))
2170                 rss_conf.rss_hf = ETH_RSS_ETH;
2171         else if (!strcmp(res->value, "vlan"))
2172                 rss_conf.rss_hf = ETH_RSS_VLAN;
2173         else if (!strcmp(res->value, "ip"))
2174                 rss_conf.rss_hf = ETH_RSS_IP;
2175         else if (!strcmp(res->value, "udp"))
2176                 rss_conf.rss_hf = ETH_RSS_UDP;
2177         else if (!strcmp(res->value, "tcp"))
2178                 rss_conf.rss_hf = ETH_RSS_TCP;
2179         else if (!strcmp(res->value, "sctp"))
2180                 rss_conf.rss_hf = ETH_RSS_SCTP;
2181         else if (!strcmp(res->value, "ether"))
2182                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2183         else if (!strcmp(res->value, "port"))
2184                 rss_conf.rss_hf = ETH_RSS_PORT;
2185         else if (!strcmp(res->value, "vxlan"))
2186                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2187         else if (!strcmp(res->value, "geneve"))
2188                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2189         else if (!strcmp(res->value, "nvgre"))
2190                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2191         else if (!strcmp(res->value, "l3-pre32"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2193         else if (!strcmp(res->value, "l3-pre40"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2195         else if (!strcmp(res->value, "l3-pre48"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2197         else if (!strcmp(res->value, "l3-pre56"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2199         else if (!strcmp(res->value, "l3-pre64"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2201         else if (!strcmp(res->value, "l3-pre96"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2203         else if (!strcmp(res->value, "l3-src-only"))
2204                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2205         else if (!strcmp(res->value, "l3-dst-only"))
2206                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2207         else if (!strcmp(res->value, "l4-src-only"))
2208                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2209         else if (!strcmp(res->value, "l4-dst-only"))
2210                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2211         else if (!strcmp(res->value, "l2-src-only"))
2212                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2213         else if (!strcmp(res->value, "l2-dst-only"))
2214                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2215         else if (!strcmp(res->value, "l2tpv3"))
2216                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2217         else if (!strcmp(res->value, "esp"))
2218                 rss_conf.rss_hf = ETH_RSS_ESP;
2219         else if (!strcmp(res->value, "ah"))
2220                 rss_conf.rss_hf = ETH_RSS_AH;
2221         else if (!strcmp(res->value, "pfcp"))
2222                 rss_conf.rss_hf = ETH_RSS_PFCP;
2223         else if (!strcmp(res->value, "pppoe"))
2224                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2225         else if (!strcmp(res->value, "gtpu"))
2226                 rss_conf.rss_hf = ETH_RSS_GTPU;
2227         else if (!strcmp(res->value, "ecpri"))
2228                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2229         else if (!strcmp(res->value, "none"))
2230                 rss_conf.rss_hf = 0;
2231         else if (!strcmp(res->value, "level-default")) {
2232                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2233                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2234         } else if (!strcmp(res->value, "level-outer")) {
2235                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2236                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2237         } else if (!strcmp(res->value, "level-inner")) {
2238                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2239                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2240         } else if (!strcmp(res->value, "default"))
2241                 use_default = 1;
2242         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2243                                                 atoi(res->value) < 64)
2244                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2245         else {
2246                 printf("Unknown parameter\n");
2247                 return;
2248         }
2249         rss_conf.rss_key = NULL;
2250         /* Update global configuration for RSS types. */
2251         RTE_ETH_FOREACH_DEV(i) {
2252                 struct rte_eth_rss_conf local_rss_conf;
2253
2254                 ret = eth_dev_info_get_print_err(i, &dev_info);
2255                 if (ret != 0)
2256                         return;
2257
2258                 if (use_default)
2259                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2260
2261                 local_rss_conf = rss_conf;
2262                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2263                         dev_info.flow_type_rss_offloads;
2264                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2265                         printf("Port %u modified RSS hash function based on hardware support,"
2266                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2267                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2268                 }
2269                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2270                 if (diag < 0) {
2271                         all_updated = 0;
2272                         printf("Configuration of RSS hash at ethernet port %d "
2273                                 "failed with error (%d): %s.\n",
2274                                 i, -diag, strerror(-diag));
2275                 }
2276         }
2277         if (all_updated && !use_default) {
2278                 rss_hf = rss_conf.rss_hf;
2279                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2280         }
2281 }
2282
2283 cmdline_parse_token_string_t cmd_config_rss_port =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2285 cmdline_parse_token_string_t cmd_config_rss_keyword =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2287 cmdline_parse_token_string_t cmd_config_rss_all =
2288         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2289 cmdline_parse_token_string_t cmd_config_rss_name =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2291 cmdline_parse_token_string_t cmd_config_rss_value =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2293
2294 cmdline_parse_inst_t cmd_config_rss = {
2295         .f = cmd_config_rss_parsed,
2296         .data = NULL,
2297         .help_str = "port config all rss "
2298                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2299                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|none|level-default|"
2300                 "level-outer|level-inner|<flowtype_id>",
2301         .tokens = {
2302                 (void *)&cmd_config_rss_port,
2303                 (void *)&cmd_config_rss_keyword,
2304                 (void *)&cmd_config_rss_all,
2305                 (void *)&cmd_config_rss_name,
2306                 (void *)&cmd_config_rss_value,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** configure rss hash key *** */
2312 struct cmd_config_rss_hash_key {
2313         cmdline_fixed_string_t port;
2314         cmdline_fixed_string_t config;
2315         portid_t port_id;
2316         cmdline_fixed_string_t rss_hash_key;
2317         cmdline_fixed_string_t rss_type;
2318         cmdline_fixed_string_t key;
2319 };
2320
2321 static uint8_t
2322 hexa_digit_to_value(char hexa_digit)
2323 {
2324         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2325                 return (uint8_t) (hexa_digit - '0');
2326         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2327                 return (uint8_t) ((hexa_digit - 'a') + 10);
2328         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2329                 return (uint8_t) ((hexa_digit - 'A') + 10);
2330         /* Invalid hexa digit */
2331         return 0xFF;
2332 }
2333
2334 static uint8_t
2335 parse_and_check_key_hexa_digit(char *key, int idx)
2336 {
2337         uint8_t hexa_v;
2338
2339         hexa_v = hexa_digit_to_value(key[idx]);
2340         if (hexa_v == 0xFF)
2341                 printf("invalid key: character %c at position %d is not a "
2342                        "valid hexa digit\n", key[idx], idx);
2343         return hexa_v;
2344 }
2345
2346 static void
2347 cmd_config_rss_hash_key_parsed(void *parsed_result,
2348                                __rte_unused struct cmdline *cl,
2349                                __rte_unused void *data)
2350 {
2351         struct cmd_config_rss_hash_key *res = parsed_result;
2352         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2353         uint8_t xdgt0;
2354         uint8_t xdgt1;
2355         int i;
2356         struct rte_eth_dev_info dev_info;
2357         uint8_t hash_key_size;
2358         uint32_t key_len;
2359         int ret;
2360
2361         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2362         if (ret != 0)
2363                 return;
2364
2365         if (dev_info.hash_key_size > 0 &&
2366                         dev_info.hash_key_size <= sizeof(hash_key))
2367                 hash_key_size = dev_info.hash_key_size;
2368         else {
2369                 printf("dev_info did not provide a valid hash key size\n");
2370                 return;
2371         }
2372         /* Check the length of the RSS hash key */
2373         key_len = strlen(res->key);
2374         if (key_len != (hash_key_size * 2)) {
2375                 printf("key length: %d invalid - key must be a string of %d"
2376                            " hexa-decimal numbers\n",
2377                            (int) key_len, hash_key_size * 2);
2378                 return;
2379         }
2380         /* Translate RSS hash key into binary representation */
2381         for (i = 0; i < hash_key_size; i++) {
2382                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2383                 if (xdgt0 == 0xFF)
2384                         return;
2385                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2386                 if (xdgt1 == 0xFF)
2387                         return;
2388                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2389         }
2390         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2391                         hash_key_size);
2392 }
2393
2394 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2395         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2396 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2398                                  "config");
2399 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2400         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2401                                  RTE_UINT16);
2402 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2403         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2404                                  rss_hash_key, "rss-hash-key");
2405 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2407                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2408                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2409                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2410                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2411                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2412                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2413                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri");
2414 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2415         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2416
2417 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2418         .f = cmd_config_rss_hash_key_parsed,
2419         .data = NULL,
2420         .help_str = "port config <port_id> rss-hash-key "
2421                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2422                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2423                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2424                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2425                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2426                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri "
2427                 "<string of hex digits (variable length, NIC dependent)>",
2428         .tokens = {
2429                 (void *)&cmd_config_rss_hash_key_port,
2430                 (void *)&cmd_config_rss_hash_key_config,
2431                 (void *)&cmd_config_rss_hash_key_port_id,
2432                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2433                 (void *)&cmd_config_rss_hash_key_rss_type,
2434                 (void *)&cmd_config_rss_hash_key_value,
2435                 NULL,
2436         },
2437 };
2438
2439 /* *** configure port rxq/txq ring size *** */
2440 struct cmd_config_rxtx_ring_size {
2441         cmdline_fixed_string_t port;
2442         cmdline_fixed_string_t config;
2443         portid_t portid;
2444         cmdline_fixed_string_t rxtxq;
2445         uint16_t qid;
2446         cmdline_fixed_string_t rsize;
2447         uint16_t size;
2448 };
2449
2450 static void
2451 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2452                                  __rte_unused struct cmdline *cl,
2453                                  __rte_unused void *data)
2454 {
2455         struct cmd_config_rxtx_ring_size *res = parsed_result;
2456         struct rte_port *port;
2457         uint8_t isrx;
2458
2459         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2460                 return;
2461
2462         if (res->portid == (portid_t)RTE_PORT_ALL) {
2463                 printf("Invalid port id\n");
2464                 return;
2465         }
2466
2467         port = &ports[res->portid];
2468
2469         if (!strcmp(res->rxtxq, "rxq"))
2470                 isrx = 1;
2471         else if (!strcmp(res->rxtxq, "txq"))
2472                 isrx = 0;
2473         else {
2474                 printf("Unknown parameter\n");
2475                 return;
2476         }
2477
2478         if (isrx && rx_queue_id_is_invalid(res->qid))
2479                 return;
2480         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2481                 return;
2482
2483         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2484                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2485                        rx_free_thresh);
2486                 return;
2487         }
2488
2489         if (isrx)
2490                 port->nb_rx_desc[res->qid] = res->size;
2491         else
2492                 port->nb_tx_desc[res->qid] = res->size;
2493
2494         cmd_reconfig_device_queue(res->portid, 0, 1);
2495 }
2496
2497 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2498         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                                  port, "port");
2500 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2502                                  config, "config");
2503 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2504         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2505                                  portid, RTE_UINT16);
2506 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2508                                  rxtxq, "rxq#txq");
2509 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2510         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                               qid, RTE_UINT16);
2512 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2513         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2514                                  rsize, "ring_size");
2515 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2516         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2517                               size, RTE_UINT16);
2518
2519 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2520         .f = cmd_config_rxtx_ring_size_parsed,
2521         .data = NULL,
2522         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2523         .tokens = {
2524                 (void *)&cmd_config_rxtx_ring_size_port,
2525                 (void *)&cmd_config_rxtx_ring_size_config,
2526                 (void *)&cmd_config_rxtx_ring_size_portid,
2527                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2528                 (void *)&cmd_config_rxtx_ring_size_qid,
2529                 (void *)&cmd_config_rxtx_ring_size_rsize,
2530                 (void *)&cmd_config_rxtx_ring_size_size,
2531                 NULL,
2532         },
2533 };
2534
2535 /* *** configure port rxq/txq start/stop *** */
2536 struct cmd_config_rxtx_queue {
2537         cmdline_fixed_string_t port;
2538         portid_t portid;
2539         cmdline_fixed_string_t rxtxq;
2540         uint16_t qid;
2541         cmdline_fixed_string_t opname;
2542 };
2543
2544 static void
2545 cmd_config_rxtx_queue_parsed(void *parsed_result,
2546                         __rte_unused struct cmdline *cl,
2547                         __rte_unused void *data)
2548 {
2549         struct cmd_config_rxtx_queue *res = parsed_result;
2550         uint8_t isrx;
2551         uint8_t isstart;
2552         int ret = 0;
2553
2554         if (test_done == 0) {
2555                 printf("Please stop forwarding first\n");
2556                 return;
2557         }
2558
2559         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2560                 return;
2561
2562         if (port_is_started(res->portid) != 1) {
2563                 printf("Please start port %u first\n", res->portid);
2564                 return;
2565         }
2566
2567         if (!strcmp(res->rxtxq, "rxq"))
2568                 isrx = 1;
2569         else if (!strcmp(res->rxtxq, "txq"))
2570                 isrx = 0;
2571         else {
2572                 printf("Unknown parameter\n");
2573                 return;
2574         }
2575
2576         if (isrx && rx_queue_id_is_invalid(res->qid))
2577                 return;
2578         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2579                 return;
2580
2581         if (!strcmp(res->opname, "start"))
2582                 isstart = 1;
2583         else if (!strcmp(res->opname, "stop"))
2584                 isstart = 0;
2585         else {
2586                 printf("Unknown parameter\n");
2587                 return;
2588         }
2589
2590         if (isstart && isrx)
2591                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2592         else if (!isstart && isrx)
2593                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2594         else if (isstart && !isrx)
2595                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2596         else
2597                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2598
2599         if (ret == -ENOTSUP)
2600                 printf("Function not supported in PMD driver\n");
2601 }
2602
2603 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2604         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2605 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2609 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2610         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2611 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2612         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2613                                                 "start#stop");
2614
2615 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2616         .f = cmd_config_rxtx_queue_parsed,
2617         .data = NULL,
2618         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2619         .tokens = {
2620                 (void *)&cmd_config_rxtx_queue_port,
2621                 (void *)&cmd_config_rxtx_queue_portid,
2622                 (void *)&cmd_config_rxtx_queue_rxtxq,
2623                 (void *)&cmd_config_rxtx_queue_qid,
2624                 (void *)&cmd_config_rxtx_queue_opname,
2625                 NULL,
2626         },
2627 };
2628
2629 /* *** configure port rxq/txq deferred start on/off *** */
2630 struct cmd_config_deferred_start_rxtx_queue {
2631         cmdline_fixed_string_t port;
2632         portid_t port_id;
2633         cmdline_fixed_string_t rxtxq;
2634         uint16_t qid;
2635         cmdline_fixed_string_t opname;
2636         cmdline_fixed_string_t state;
2637 };
2638
2639 static void
2640 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2641                         __rte_unused struct cmdline *cl,
2642                         __rte_unused void *data)
2643 {
2644         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2645         struct rte_port *port;
2646         uint8_t isrx;
2647         uint8_t ison;
2648         uint8_t needreconfig = 0;
2649
2650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2651                 return;
2652
2653         if (port_is_started(res->port_id) != 0) {
2654                 printf("Please stop port %u first\n", res->port_id);
2655                 return;
2656         }
2657
2658         port = &ports[res->port_id];
2659
2660         isrx = !strcmp(res->rxtxq, "rxq");
2661
2662         if (isrx && rx_queue_id_is_invalid(res->qid))
2663                 return;
2664         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2665                 return;
2666
2667         ison = !strcmp(res->state, "on");
2668
2669         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2670                 port->rx_conf[res->qid].rx_deferred_start = ison;
2671                 needreconfig = 1;
2672         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2673                 port->tx_conf[res->qid].tx_deferred_start = ison;
2674                 needreconfig = 1;
2675         }
2676
2677         if (needreconfig)
2678                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2679 }
2680
2681 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2683                                                 port, "port");
2684 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2685         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2686                                                 port_id, RTE_UINT16);
2687 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2689                                                 rxtxq, "rxq#txq");
2690 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2691         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2692                                                 qid, RTE_UINT16);
2693 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2695                                                 opname, "deferred_start");
2696 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2697         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2698                                                 state, "on#off");
2699
2700 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2701         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2702         .data = NULL,
2703         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2704         .tokens = {
2705                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2706                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2707                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2708                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2709                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2710                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2711                 NULL,
2712         },
2713 };
2714
2715 /* *** configure port rxq/txq setup *** */
2716 struct cmd_setup_rxtx_queue {
2717         cmdline_fixed_string_t port;
2718         portid_t portid;
2719         cmdline_fixed_string_t rxtxq;
2720         uint16_t qid;
2721         cmdline_fixed_string_t setup;
2722 };
2723
2724 /* Common CLI fields for queue setup */
2725 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2726         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2727 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2728         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2729 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2730         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2731 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2732         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2733 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2734         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2735
2736 static void
2737 cmd_setup_rxtx_queue_parsed(
2738         void *parsed_result,
2739         __rte_unused struct cmdline *cl,
2740         __rte_unused void *data)
2741 {
2742         struct cmd_setup_rxtx_queue *res = parsed_result;
2743         struct rte_port *port;
2744         struct rte_mempool *mp;
2745         unsigned int socket_id;
2746         uint8_t isrx = 0;
2747         int ret;
2748
2749         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2750                 return;
2751
2752         if (res->portid == (portid_t)RTE_PORT_ALL) {
2753                 printf("Invalid port id\n");
2754                 return;
2755         }
2756
2757         if (!strcmp(res->rxtxq, "rxq"))
2758                 isrx = 1;
2759         else if (!strcmp(res->rxtxq, "txq"))
2760                 isrx = 0;
2761         else {
2762                 printf("Unknown parameter\n");
2763                 return;
2764         }
2765
2766         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2767                 printf("Invalid rx queue\n");
2768                 return;
2769         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2770                 printf("Invalid tx queue\n");
2771                 return;
2772         }
2773
2774         port = &ports[res->portid];
2775         if (isrx) {
2776                 socket_id = rxring_numa[res->portid];
2777                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2778                         socket_id = port->socket_id;
2779
2780                 mp = mbuf_pool_find(socket_id, 0);
2781                 if (mp == NULL) {
2782                         printf("Failed to setup RX queue: "
2783                                 "No mempool allocation"
2784                                 " on the socket %d\n",
2785                                 rxring_numa[res->portid]);
2786                         return;
2787                 }
2788                 ret = rx_queue_setup(res->portid,
2789                                      res->qid,
2790                                      port->nb_rx_desc[res->qid],
2791                                      socket_id,
2792                                      &port->rx_conf[res->qid],
2793                                      mp);
2794                 if (ret)
2795                         printf("Failed to setup RX queue\n");
2796         } else {
2797                 socket_id = txring_numa[res->portid];
2798                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2799                         socket_id = port->socket_id;
2800
2801                 ret = rte_eth_tx_queue_setup(res->portid,
2802                                              res->qid,
2803                                              port->nb_tx_desc[res->qid],
2804                                              socket_id,
2805                                              &port->tx_conf[res->qid]);
2806                 if (ret)
2807                         printf("Failed to setup TX queue\n");
2808         }
2809 }
2810
2811 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2812         .f = cmd_setup_rxtx_queue_parsed,
2813         .data = NULL,
2814         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2815         .tokens = {
2816                 (void *)&cmd_setup_rxtx_queue_port,
2817                 (void *)&cmd_setup_rxtx_queue_portid,
2818                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2819                 (void *)&cmd_setup_rxtx_queue_qid,
2820                 (void *)&cmd_setup_rxtx_queue_setup,
2821                 NULL,
2822         },
2823 };
2824
2825
2826 /* *** Configure RSS RETA *** */
2827 struct cmd_config_rss_reta {
2828         cmdline_fixed_string_t port;
2829         cmdline_fixed_string_t keyword;
2830         portid_t port_id;
2831         cmdline_fixed_string_t name;
2832         cmdline_fixed_string_t list_name;
2833         cmdline_fixed_string_t list_of_items;
2834 };
2835
2836 static int
2837 parse_reta_config(const char *str,
2838                   struct rte_eth_rss_reta_entry64 *reta_conf,
2839                   uint16_t nb_entries)
2840 {
2841         int i;
2842         unsigned size;
2843         uint16_t hash_index, idx, shift;
2844         uint16_t nb_queue;
2845         char s[256];
2846         const char *p, *p0 = str;
2847         char *end;
2848         enum fieldnames {
2849                 FLD_HASH_INDEX = 0,
2850                 FLD_QUEUE,
2851                 _NUM_FLD
2852         };
2853         unsigned long int_fld[_NUM_FLD];
2854         char *str_fld[_NUM_FLD];
2855
2856         while ((p = strchr(p0,'(')) != NULL) {
2857                 ++p;
2858                 if((p0 = strchr(p,')')) == NULL)
2859                         return -1;
2860
2861                 size = p0 - p;
2862                 if(size >= sizeof(s))
2863                         return -1;
2864
2865                 snprintf(s, sizeof(s), "%.*s", size, p);
2866                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2867                         return -1;
2868                 for (i = 0; i < _NUM_FLD; i++) {
2869                         errno = 0;
2870                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2871                         if (errno != 0 || end == str_fld[i] ||
2872                                         int_fld[i] > 65535)
2873                                 return -1;
2874                 }
2875
2876                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2877                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2878
2879                 if (hash_index >= nb_entries) {
2880                         printf("Invalid RETA hash index=%d\n", hash_index);
2881                         return -1;
2882                 }
2883
2884                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2885                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2886                 reta_conf[idx].mask |= (1ULL << shift);
2887                 reta_conf[idx].reta[shift] = nb_queue;
2888         }
2889
2890         return 0;
2891 }
2892
2893 static void
2894 cmd_set_rss_reta_parsed(void *parsed_result,
2895                         __rte_unused struct cmdline *cl,
2896                         __rte_unused void *data)
2897 {
2898         int ret;
2899         struct rte_eth_dev_info dev_info;
2900         struct rte_eth_rss_reta_entry64 reta_conf[8];
2901         struct cmd_config_rss_reta *res = parsed_result;
2902
2903         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2904         if (ret != 0)
2905                 return;
2906
2907         if (dev_info.reta_size == 0) {
2908                 printf("Redirection table size is 0 which is "
2909                                         "invalid for RSS\n");
2910                 return;
2911         } else
2912                 printf("The reta size of port %d is %u\n",
2913                         res->port_id, dev_info.reta_size);
2914         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2915                 printf("Currently do not support more than %u entries of "
2916                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2917                 return;
2918         }
2919
2920         memset(reta_conf, 0, sizeof(reta_conf));
2921         if (!strcmp(res->list_name, "reta")) {
2922                 if (parse_reta_config(res->list_of_items, reta_conf,
2923                                                 dev_info.reta_size)) {
2924                         printf("Invalid RSS Redirection Table "
2925                                         "config entered\n");
2926                         return;
2927                 }
2928                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2929                                 reta_conf, dev_info.reta_size);
2930                 if (ret != 0)
2931                         printf("Bad redirection table parameter, "
2932                                         "return code = %d \n", ret);
2933         }
2934 }
2935
2936 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2937         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2938 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2939         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2940 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2941         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2942 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2943         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2944 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2945         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2946 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2947         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2948                                  NULL);
2949 cmdline_parse_inst_t cmd_config_rss_reta = {
2950         .f = cmd_set_rss_reta_parsed,
2951         .data = NULL,
2952         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2953         .tokens = {
2954                 (void *)&cmd_config_rss_reta_port,
2955                 (void *)&cmd_config_rss_reta_keyword,
2956                 (void *)&cmd_config_rss_reta_port_id,
2957                 (void *)&cmd_config_rss_reta_name,
2958                 (void *)&cmd_config_rss_reta_list_name,
2959                 (void *)&cmd_config_rss_reta_list_of_items,
2960                 NULL,
2961         },
2962 };
2963
2964 /* *** SHOW PORT RETA INFO *** */
2965 struct cmd_showport_reta {
2966         cmdline_fixed_string_t show;
2967         cmdline_fixed_string_t port;
2968         portid_t port_id;
2969         cmdline_fixed_string_t rss;
2970         cmdline_fixed_string_t reta;
2971         uint16_t size;
2972         cmdline_fixed_string_t list_of_items;
2973 };
2974
2975 static int
2976 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2977                            uint16_t nb_entries,
2978                            char *str)
2979 {
2980         uint32_t size;
2981         const char *p, *p0 = str;
2982         char s[256];
2983         char *end;
2984         char *str_fld[8];
2985         uint16_t i;
2986         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2987                         RTE_RETA_GROUP_SIZE;
2988         int ret;
2989
2990         p = strchr(p0, '(');
2991         if (p == NULL)
2992                 return -1;
2993         p++;
2994         p0 = strchr(p, ')');
2995         if (p0 == NULL)
2996                 return -1;
2997         size = p0 - p;
2998         if (size >= sizeof(s)) {
2999                 printf("The string size exceeds the internal buffer size\n");
3000                 return -1;
3001         }
3002         snprintf(s, sizeof(s), "%.*s", size, p);
3003         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3004         if (ret <= 0 || ret != num) {
3005                 printf("The bits of masks do not match the number of "
3006                                         "reta entries: %u\n", num);
3007                 return -1;
3008         }
3009         for (i = 0; i < ret; i++)
3010                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3011
3012         return 0;
3013 }
3014
3015 static void
3016 cmd_showport_reta_parsed(void *parsed_result,
3017                          __rte_unused struct cmdline *cl,
3018                          __rte_unused void *data)
3019 {
3020         struct cmd_showport_reta *res = parsed_result;
3021         struct rte_eth_rss_reta_entry64 reta_conf[8];
3022         struct rte_eth_dev_info dev_info;
3023         uint16_t max_reta_size;
3024         int ret;
3025
3026         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3027         if (ret != 0)
3028                 return;
3029
3030         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3031         if (res->size == 0 || res->size > max_reta_size) {
3032                 printf("Invalid redirection table size: %u (1-%u)\n",
3033                         res->size, max_reta_size);
3034                 return;
3035         }
3036
3037         memset(reta_conf, 0, sizeof(reta_conf));
3038         if (showport_parse_reta_config(reta_conf, res->size,
3039                                 res->list_of_items) < 0) {
3040                 printf("Invalid string: %s for reta masks\n",
3041                                         res->list_of_items);
3042                 return;
3043         }
3044         port_rss_reta_info(res->port_id, reta_conf, res->size);
3045 }
3046
3047 cmdline_parse_token_string_t cmd_showport_reta_show =
3048         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3049 cmdline_parse_token_string_t cmd_showport_reta_port =
3050         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3051 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3052         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3053 cmdline_parse_token_string_t cmd_showport_reta_rss =
3054         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3055 cmdline_parse_token_string_t cmd_showport_reta_reta =
3056         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3057 cmdline_parse_token_num_t cmd_showport_reta_size =
3058         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3059 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3060         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3061                                         list_of_items, NULL);
3062
3063 cmdline_parse_inst_t cmd_showport_reta = {
3064         .f = cmd_showport_reta_parsed,
3065         .data = NULL,
3066         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3067         .tokens = {
3068                 (void *)&cmd_showport_reta_show,
3069                 (void *)&cmd_showport_reta_port,
3070                 (void *)&cmd_showport_reta_port_id,
3071                 (void *)&cmd_showport_reta_rss,
3072                 (void *)&cmd_showport_reta_reta,
3073                 (void *)&cmd_showport_reta_size,
3074                 (void *)&cmd_showport_reta_list_of_items,
3075                 NULL,
3076         },
3077 };
3078
3079 /* *** Show RSS hash configuration *** */
3080 struct cmd_showport_rss_hash {
3081         cmdline_fixed_string_t show;
3082         cmdline_fixed_string_t port;
3083         portid_t port_id;
3084         cmdline_fixed_string_t rss_hash;
3085         cmdline_fixed_string_t rss_type;
3086         cmdline_fixed_string_t key; /* optional argument */
3087 };
3088
3089 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3090                                 __rte_unused struct cmdline *cl,
3091                                 void *show_rss_key)
3092 {
3093         struct cmd_showport_rss_hash *res = parsed_result;
3094
3095         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3096 }
3097
3098 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3099         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3100 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3101         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3102 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3103         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3104                                  RTE_UINT16);
3105 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3106         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3107                                  "rss-hash");
3108 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3109         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3110
3111 cmdline_parse_inst_t cmd_showport_rss_hash = {
3112         .f = cmd_showport_rss_hash_parsed,
3113         .data = NULL,
3114         .help_str = "show port <port_id> rss-hash",
3115         .tokens = {
3116                 (void *)&cmd_showport_rss_hash_show,
3117                 (void *)&cmd_showport_rss_hash_port,
3118                 (void *)&cmd_showport_rss_hash_port_id,
3119                 (void *)&cmd_showport_rss_hash_rss_hash,
3120                 NULL,
3121         },
3122 };
3123
3124 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3125         .f = cmd_showport_rss_hash_parsed,
3126         .data = (void *)1,
3127         .help_str = "show port <port_id> rss-hash key",
3128         .tokens = {
3129                 (void *)&cmd_showport_rss_hash_show,
3130                 (void *)&cmd_showport_rss_hash_port,
3131                 (void *)&cmd_showport_rss_hash_port_id,
3132                 (void *)&cmd_showport_rss_hash_rss_hash,
3133                 (void *)&cmd_showport_rss_hash_rss_key,
3134                 NULL,
3135         },
3136 };
3137
3138 /* *** Configure DCB *** */
3139 struct cmd_config_dcb {
3140         cmdline_fixed_string_t port;
3141         cmdline_fixed_string_t config;
3142         portid_t port_id;
3143         cmdline_fixed_string_t dcb;
3144         cmdline_fixed_string_t vt;
3145         cmdline_fixed_string_t vt_en;
3146         uint8_t num_tcs;
3147         cmdline_fixed_string_t pfc;
3148         cmdline_fixed_string_t pfc_en;
3149 };
3150
3151 static void
3152 cmd_config_dcb_parsed(void *parsed_result,
3153                         __rte_unused struct cmdline *cl,
3154                         __rte_unused void *data)
3155 {
3156         struct cmd_config_dcb *res = parsed_result;
3157         portid_t port_id = res->port_id;
3158         struct rte_port *port;
3159         uint8_t pfc_en;
3160         int ret;
3161
3162         port = &ports[port_id];
3163         /** Check if the port is not started **/
3164         if (port->port_status != RTE_PORT_STOPPED) {
3165                 printf("Please stop port %d first\n", port_id);
3166                 return;
3167         }
3168
3169         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3170                 printf("The invalid number of traffic class,"
3171                         " only 4 or 8 allowed.\n");
3172                 return;
3173         }
3174
3175         if (nb_fwd_lcores < res->num_tcs) {
3176                 printf("nb_cores shouldn't be less than number of TCs.\n");
3177                 return;
3178         }
3179         if (!strncmp(res->pfc_en, "on", 2))
3180                 pfc_en = 1;
3181         else
3182                 pfc_en = 0;
3183
3184         /* DCB in VT mode */
3185         if (!strncmp(res->vt_en, "on", 2))
3186                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3187                                 (enum rte_eth_nb_tcs)res->num_tcs,
3188                                 pfc_en);
3189         else
3190                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3191                                 (enum rte_eth_nb_tcs)res->num_tcs,
3192                                 pfc_en);
3193
3194
3195         if (ret != 0) {
3196                 printf("Cannot initialize network ports.\n");
3197                 return;
3198         }
3199
3200         cmd_reconfig_device_queue(port_id, 1, 1);
3201 }
3202
3203 cmdline_parse_token_string_t cmd_config_dcb_port =
3204         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3205 cmdline_parse_token_string_t cmd_config_dcb_config =
3206         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3207 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3208         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3209 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3210         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3211 cmdline_parse_token_string_t cmd_config_dcb_vt =
3212         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3213 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3214         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3215 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3216         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3217 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3218         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3219 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3220         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3221
3222 cmdline_parse_inst_t cmd_config_dcb = {
3223         .f = cmd_config_dcb_parsed,
3224         .data = NULL,
3225         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3226         .tokens = {
3227                 (void *)&cmd_config_dcb_port,
3228                 (void *)&cmd_config_dcb_config,
3229                 (void *)&cmd_config_dcb_port_id,
3230                 (void *)&cmd_config_dcb_dcb,
3231                 (void *)&cmd_config_dcb_vt,
3232                 (void *)&cmd_config_dcb_vt_en,
3233                 (void *)&cmd_config_dcb_num_tcs,
3234                 (void *)&cmd_config_dcb_pfc,
3235                 (void *)&cmd_config_dcb_pfc_en,
3236                 NULL,
3237         },
3238 };
3239
3240 /* *** configure number of packets per burst *** */
3241 struct cmd_config_burst {
3242         cmdline_fixed_string_t port;
3243         cmdline_fixed_string_t keyword;
3244         cmdline_fixed_string_t all;
3245         cmdline_fixed_string_t name;
3246         uint16_t value;
3247 };
3248
3249 static void
3250 cmd_config_burst_parsed(void *parsed_result,
3251                         __rte_unused struct cmdline *cl,
3252                         __rte_unused void *data)
3253 {
3254         struct cmd_config_burst *res = parsed_result;
3255         struct rte_eth_dev_info dev_info;
3256         uint16_t rec_nb_pkts;
3257         int ret;
3258
3259         if (!all_ports_stopped()) {
3260                 printf("Please stop all ports first\n");
3261                 return;
3262         }
3263
3264         if (!strcmp(res->name, "burst")) {
3265                 if (res->value == 0) {
3266                         /* If user gives a value of zero, query the PMD for
3267                          * its recommended Rx burst size. Testpmd uses a single
3268                          * size for all ports, so assume all ports are the same
3269                          * NIC model and use the values from Port 0.
3270                          */
3271                         ret = eth_dev_info_get_print_err(0, &dev_info);
3272                         if (ret != 0)
3273                                 return;
3274
3275                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3276
3277                         if (rec_nb_pkts == 0) {
3278                                 printf("PMD does not recommend a burst size.\n"
3279                                         "User provided value must be between"
3280                                         " 1 and %d\n", MAX_PKT_BURST);
3281                                 return;
3282                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3283                                 printf("PMD recommended burst size of %d"
3284                                         " exceeds maximum value of %d\n",
3285                                         rec_nb_pkts, MAX_PKT_BURST);
3286                                 return;
3287                         }
3288                         printf("Using PMD-provided burst value of %d\n",
3289                                 rec_nb_pkts);
3290                         nb_pkt_per_burst = rec_nb_pkts;
3291                 } else if (res->value > MAX_PKT_BURST) {
3292                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3293                         return;
3294                 } else
3295                         nb_pkt_per_burst = res->value;
3296         } else {
3297                 printf("Unknown parameter\n");
3298                 return;
3299         }
3300
3301         init_port_config();
3302
3303         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3304 }
3305
3306 cmdline_parse_token_string_t cmd_config_burst_port =
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3308 cmdline_parse_token_string_t cmd_config_burst_keyword =
3309         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3310 cmdline_parse_token_string_t cmd_config_burst_all =
3311         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3312 cmdline_parse_token_string_t cmd_config_burst_name =
3313         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3314 cmdline_parse_token_num_t cmd_config_burst_value =
3315         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3316
3317 cmdline_parse_inst_t cmd_config_burst = {
3318         .f = cmd_config_burst_parsed,
3319         .data = NULL,
3320         .help_str = "port config all burst <value>",
3321         .tokens = {
3322                 (void *)&cmd_config_burst_port,
3323                 (void *)&cmd_config_burst_keyword,
3324                 (void *)&cmd_config_burst_all,
3325                 (void *)&cmd_config_burst_name,
3326                 (void *)&cmd_config_burst_value,
3327                 NULL,
3328         },
3329 };
3330
3331 /* *** configure rx/tx queues *** */
3332 struct cmd_config_thresh {
3333         cmdline_fixed_string_t port;
3334         cmdline_fixed_string_t keyword;
3335         cmdline_fixed_string_t all;
3336         cmdline_fixed_string_t name;
3337         uint8_t value;
3338 };
3339
3340 static void
3341 cmd_config_thresh_parsed(void *parsed_result,
3342                         __rte_unused struct cmdline *cl,
3343                         __rte_unused void *data)
3344 {
3345         struct cmd_config_thresh *res = parsed_result;
3346
3347         if (!all_ports_stopped()) {
3348                 printf("Please stop all ports first\n");
3349                 return;
3350         }
3351
3352         if (!strcmp(res->name, "txpt"))
3353                 tx_pthresh = res->value;
3354         else if(!strcmp(res->name, "txht"))
3355                 tx_hthresh = res->value;
3356         else if(!strcmp(res->name, "txwt"))
3357                 tx_wthresh = res->value;
3358         else if(!strcmp(res->name, "rxpt"))
3359                 rx_pthresh = res->value;
3360         else if(!strcmp(res->name, "rxht"))
3361                 rx_hthresh = res->value;
3362         else if(!strcmp(res->name, "rxwt"))
3363                 rx_wthresh = res->value;
3364         else {
3365                 printf("Unknown parameter\n");
3366                 return;
3367         }
3368
3369         init_port_config();
3370
3371         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3372 }
3373
3374 cmdline_parse_token_string_t cmd_config_thresh_port =
3375         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3376 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3378 cmdline_parse_token_string_t cmd_config_thresh_all =
3379         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3380 cmdline_parse_token_string_t cmd_config_thresh_name =
3381         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3382                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3383 cmdline_parse_token_num_t cmd_config_thresh_value =
3384         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3385
3386 cmdline_parse_inst_t cmd_config_thresh = {
3387         .f = cmd_config_thresh_parsed,
3388         .data = NULL,
3389         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3390         .tokens = {
3391                 (void *)&cmd_config_thresh_port,
3392                 (void *)&cmd_config_thresh_keyword,
3393                 (void *)&cmd_config_thresh_all,
3394                 (void *)&cmd_config_thresh_name,
3395                 (void *)&cmd_config_thresh_value,
3396                 NULL,
3397         },
3398 };
3399
3400 /* *** configure free/rs threshold *** */
3401 struct cmd_config_threshold {
3402         cmdline_fixed_string_t port;
3403         cmdline_fixed_string_t keyword;
3404         cmdline_fixed_string_t all;
3405         cmdline_fixed_string_t name;
3406         uint16_t value;
3407 };
3408
3409 static void
3410 cmd_config_threshold_parsed(void *parsed_result,
3411                         __rte_unused struct cmdline *cl,
3412                         __rte_unused void *data)
3413 {
3414         struct cmd_config_threshold *res = parsed_result;
3415
3416         if (!all_ports_stopped()) {
3417                 printf("Please stop all ports first\n");
3418                 return;
3419         }
3420
3421         if (!strcmp(res->name, "txfreet"))
3422                 tx_free_thresh = res->value;
3423         else if (!strcmp(res->name, "txrst"))
3424                 tx_rs_thresh = res->value;
3425         else if (!strcmp(res->name, "rxfreet"))
3426                 rx_free_thresh = res->value;
3427         else {
3428                 printf("Unknown parameter\n");
3429                 return;
3430         }
3431
3432         init_port_config();
3433
3434         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3435 }
3436
3437 cmdline_parse_token_string_t cmd_config_threshold_port =
3438         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3439 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3440         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3441                                                                 "config");
3442 cmdline_parse_token_string_t cmd_config_threshold_all =
3443         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3444 cmdline_parse_token_string_t cmd_config_threshold_name =
3445         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3446                                                 "txfreet#txrst#rxfreet");
3447 cmdline_parse_token_num_t cmd_config_threshold_value =
3448         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3449
3450 cmdline_parse_inst_t cmd_config_threshold = {
3451         .f = cmd_config_threshold_parsed,
3452         .data = NULL,
3453         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3454         .tokens = {
3455                 (void *)&cmd_config_threshold_port,
3456                 (void *)&cmd_config_threshold_keyword,
3457                 (void *)&cmd_config_threshold_all,
3458                 (void *)&cmd_config_threshold_name,
3459                 (void *)&cmd_config_threshold_value,
3460                 NULL,
3461         },
3462 };
3463
3464 /* *** stop *** */
3465 struct cmd_stop_result {
3466         cmdline_fixed_string_t stop;
3467 };
3468
3469 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3470                             __rte_unused struct cmdline *cl,
3471                             __rte_unused void *data)
3472 {
3473         stop_packet_forwarding();
3474 }
3475
3476 cmdline_parse_token_string_t cmd_stop_stop =
3477         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3478
3479 cmdline_parse_inst_t cmd_stop = {
3480         .f = cmd_stop_parsed,
3481         .data = NULL,
3482         .help_str = "stop: Stop packet forwarding",
3483         .tokens = {
3484                 (void *)&cmd_stop_stop,
3485                 NULL,
3486         },
3487 };
3488
3489 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3490
3491 unsigned int
3492 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3493                 unsigned int *parsed_items, int check_unique_values)
3494 {
3495         unsigned int nb_item;
3496         unsigned int value;
3497         unsigned int i;
3498         unsigned int j;
3499         int value_ok;
3500         char c;
3501
3502         /*
3503          * First parse all items in the list and store their value.
3504          */
3505         value = 0;
3506         nb_item = 0;
3507         value_ok = 0;
3508         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3509                 c = str[i];
3510                 if ((c >= '0') && (c <= '9')) {
3511                         value = (unsigned int) (value * 10 + (c - '0'));
3512                         value_ok = 1;
3513                         continue;
3514                 }
3515                 if (c != ',') {
3516                         printf("character %c is not a decimal digit\n", c);
3517                         return 0;
3518                 }
3519                 if (! value_ok) {
3520                         printf("No valid value before comma\n");
3521                         return 0;
3522                 }
3523                 if (nb_item < max_items) {
3524                         parsed_items[nb_item] = value;
3525                         value_ok = 0;
3526                         value = 0;
3527                 }
3528                 nb_item++;
3529         }
3530         if (nb_item >= max_items) {
3531                 printf("Number of %s = %u > %u (maximum items)\n",
3532                        item_name, nb_item + 1, max_items);
3533                 return 0;
3534         }
3535         parsed_items[nb_item++] = value;
3536         if (! check_unique_values)
3537                 return nb_item;
3538
3539         /*
3540          * Then, check that all values in the list are differents.
3541          * No optimization here...
3542          */
3543         for (i = 0; i < nb_item; i++) {
3544                 for (j = i + 1; j < nb_item; j++) {
3545                         if (parsed_items[j] == parsed_items[i]) {
3546                                 printf("duplicated %s %u at index %u and %u\n",
3547                                        item_name, parsed_items[i], i, j);
3548                                 return 0;
3549                         }
3550                 }
3551         }
3552         return nb_item;
3553 }
3554
3555 struct cmd_set_list_result {
3556         cmdline_fixed_string_t cmd_keyword;
3557         cmdline_fixed_string_t list_name;
3558         cmdline_fixed_string_t list_of_items;
3559 };
3560
3561 static void cmd_set_list_parsed(void *parsed_result,
3562                                 __rte_unused struct cmdline *cl,
3563                                 __rte_unused void *data)
3564 {
3565         struct cmd_set_list_result *res;
3566         union {
3567                 unsigned int lcorelist[RTE_MAX_LCORE];
3568                 unsigned int portlist[RTE_MAX_ETHPORTS];
3569         } parsed_items;
3570         unsigned int nb_item;
3571
3572         if (test_done == 0) {
3573                 printf("Please stop forwarding first\n");
3574                 return;
3575         }
3576
3577         res = parsed_result;
3578         if (!strcmp(res->list_name, "corelist")) {
3579                 nb_item = parse_item_list(res->list_of_items, "core",
3580                                           RTE_MAX_LCORE,
3581                                           parsed_items.lcorelist, 1);
3582                 if (nb_item > 0) {
3583                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3584                         fwd_config_setup();
3585                 }
3586                 return;
3587         }
3588         if (!strcmp(res->list_name, "portlist")) {
3589                 nb_item = parse_item_list(res->list_of_items, "port",
3590                                           RTE_MAX_ETHPORTS,
3591                                           parsed_items.portlist, 1);
3592                 if (nb_item > 0) {
3593                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3594                         fwd_config_setup();
3595                 }
3596         }
3597 }
3598
3599 cmdline_parse_token_string_t cmd_set_list_keyword =
3600         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3601                                  "set");
3602 cmdline_parse_token_string_t cmd_set_list_name =
3603         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3604                                  "corelist#portlist");
3605 cmdline_parse_token_string_t cmd_set_list_of_items =
3606         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3607                                  NULL);
3608
3609 cmdline_parse_inst_t cmd_set_fwd_list = {
3610         .f = cmd_set_list_parsed,
3611         .data = NULL,
3612         .help_str = "set corelist|portlist <list0[,list1]*>",
3613         .tokens = {
3614                 (void *)&cmd_set_list_keyword,
3615                 (void *)&cmd_set_list_name,
3616                 (void *)&cmd_set_list_of_items,
3617                 NULL,
3618         },
3619 };
3620
3621 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3622
3623 struct cmd_setmask_result {
3624         cmdline_fixed_string_t set;
3625         cmdline_fixed_string_t mask;
3626         uint64_t hexavalue;
3627 };
3628
3629 static void cmd_set_mask_parsed(void *parsed_result,
3630                                 __rte_unused struct cmdline *cl,
3631                                 __rte_unused void *data)
3632 {
3633         struct cmd_setmask_result *res = parsed_result;
3634
3635         if (test_done == 0) {
3636                 printf("Please stop forwarding first\n");
3637                 return;
3638         }
3639         if (!strcmp(res->mask, "coremask")) {
3640                 set_fwd_lcores_mask(res->hexavalue);
3641                 fwd_config_setup();
3642         } else if (!strcmp(res->mask, "portmask")) {
3643                 set_fwd_ports_mask(res->hexavalue);
3644                 fwd_config_setup();
3645         }
3646 }
3647
3648 cmdline_parse_token_string_t cmd_setmask_set =
3649         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3650 cmdline_parse_token_string_t cmd_setmask_mask =
3651         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3652                                  "coremask#portmask");
3653 cmdline_parse_token_num_t cmd_setmask_value =
3654         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3655
3656 cmdline_parse_inst_t cmd_set_fwd_mask = {
3657         .f = cmd_set_mask_parsed,
3658         .data = NULL,
3659         .help_str = "set coremask|portmask <hexadecimal value>",
3660         .tokens = {
3661                 (void *)&cmd_setmask_set,
3662                 (void *)&cmd_setmask_mask,
3663                 (void *)&cmd_setmask_value,
3664                 NULL,
3665         },
3666 };
3667
3668 /*
3669  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3670  */
3671 struct cmd_set_result {
3672         cmdline_fixed_string_t set;
3673         cmdline_fixed_string_t what;
3674         uint16_t value;
3675 };
3676
3677 static void cmd_set_parsed(void *parsed_result,
3678                            __rte_unused struct cmdline *cl,
3679                            __rte_unused void *data)
3680 {
3681         struct cmd_set_result *res = parsed_result;
3682         if (!strcmp(res->what, "nbport")) {
3683                 set_fwd_ports_number(res->value);
3684                 fwd_config_setup();
3685         } else if (!strcmp(res->what, "nbcore")) {
3686                 set_fwd_lcores_number(res->value);
3687                 fwd_config_setup();
3688         } else if (!strcmp(res->what, "burst"))
3689                 set_nb_pkt_per_burst(res->value);
3690         else if (!strcmp(res->what, "verbose"))
3691                 set_verbose_level(res->value);
3692 }
3693
3694 cmdline_parse_token_string_t cmd_set_set =
3695         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3696 cmdline_parse_token_string_t cmd_set_what =
3697         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3698                                  "nbport#nbcore#burst#verbose");
3699 cmdline_parse_token_num_t cmd_set_value =
3700         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3701
3702 cmdline_parse_inst_t cmd_set_numbers = {
3703         .f = cmd_set_parsed,
3704         .data = NULL,
3705         .help_str = "set nbport|nbcore|burst|verbose <value>",
3706         .tokens = {
3707                 (void *)&cmd_set_set,
3708                 (void *)&cmd_set_what,
3709                 (void *)&cmd_set_value,
3710                 NULL,
3711         },
3712 };
3713
3714 /* *** SET LOG LEVEL CONFIGURATION *** */
3715
3716 struct cmd_set_log_result {
3717         cmdline_fixed_string_t set;
3718         cmdline_fixed_string_t log;
3719         cmdline_fixed_string_t type;
3720         uint32_t level;
3721 };
3722
3723 static void
3724 cmd_set_log_parsed(void *parsed_result,
3725                    __rte_unused struct cmdline *cl,
3726                    __rte_unused void *data)
3727 {
3728         struct cmd_set_log_result *res;
3729         int ret;
3730
3731         res = parsed_result;
3732         if (!strcmp(res->type, "global"))
3733                 rte_log_set_global_level(res->level);
3734         else {
3735                 ret = rte_log_set_level_regexp(res->type, res->level);
3736                 if (ret < 0)
3737                         printf("Unable to set log level\n");
3738         }
3739 }
3740
3741 cmdline_parse_token_string_t cmd_set_log_set =
3742         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3743 cmdline_parse_token_string_t cmd_set_log_log =
3744         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3745 cmdline_parse_token_string_t cmd_set_log_type =
3746         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3747 cmdline_parse_token_num_t cmd_set_log_level =
3748         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3749
3750 cmdline_parse_inst_t cmd_set_log = {
3751         .f = cmd_set_log_parsed,
3752         .data = NULL,
3753         .help_str = "set log global|<type> <level>",
3754         .tokens = {
3755                 (void *)&cmd_set_log_set,
3756                 (void *)&cmd_set_log_log,
3757                 (void *)&cmd_set_log_type,
3758                 (void *)&cmd_set_log_level,
3759                 NULL,
3760         },
3761 };
3762
3763 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3764
3765 struct cmd_set_rxoffs_result {
3766         cmdline_fixed_string_t cmd_keyword;
3767         cmdline_fixed_string_t rxoffs;
3768         cmdline_fixed_string_t seg_offsets;
3769 };
3770
3771 static void
3772 cmd_set_rxoffs_parsed(void *parsed_result,
3773                       __rte_unused struct cmdline *cl,
3774                       __rte_unused void *data)
3775 {
3776         struct cmd_set_rxoffs_result *res;
3777         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3778         unsigned int nb_segs;
3779
3780         res = parsed_result;
3781         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3782                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3783         if (nb_segs > 0)
3784                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3785 }
3786
3787 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3789                                  cmd_keyword, "set");
3790 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3791         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3792                                  rxoffs, "rxoffs");
3793 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3794         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3795                                  seg_offsets, NULL);
3796
3797 cmdline_parse_inst_t cmd_set_rxoffs = {
3798         .f = cmd_set_rxoffs_parsed,
3799         .data = NULL,
3800         .help_str = "set rxoffs <len0[,len1]*>",
3801         .tokens = {
3802                 (void *)&cmd_set_rxoffs_keyword,
3803                 (void *)&cmd_set_rxoffs_name,
3804                 (void *)&cmd_set_rxoffs_offsets,
3805                 NULL,
3806         },
3807 };
3808
3809 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3810
3811 struct cmd_set_rxpkts_result {
3812         cmdline_fixed_string_t cmd_keyword;
3813         cmdline_fixed_string_t rxpkts;
3814         cmdline_fixed_string_t seg_lengths;
3815 };
3816
3817 static void
3818 cmd_set_rxpkts_parsed(void *parsed_result,
3819                       __rte_unused struct cmdline *cl,
3820                       __rte_unused void *data)
3821 {
3822         struct cmd_set_rxpkts_result *res;
3823         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3824         unsigned int nb_segs;
3825
3826         res = parsed_result;
3827         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3828                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3829         if (nb_segs > 0)
3830                 set_rx_pkt_segments(seg_lengths, nb_segs);
3831 }
3832
3833 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3835                                  cmd_keyword, "set");
3836 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3837         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3838                                  rxpkts, "rxpkts");
3839 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3840         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3841                                  seg_lengths, NULL);
3842
3843 cmdline_parse_inst_t cmd_set_rxpkts = {
3844         .f = cmd_set_rxpkts_parsed,
3845         .data = NULL,
3846         .help_str = "set rxpkts <len0[,len1]*>",
3847         .tokens = {
3848                 (void *)&cmd_set_rxpkts_keyword,
3849                 (void *)&cmd_set_rxpkts_name,
3850                 (void *)&cmd_set_rxpkts_lengths,
3851                 NULL,
3852         },
3853 };
3854
3855 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3856
3857 struct cmd_set_txpkts_result {
3858         cmdline_fixed_string_t cmd_keyword;
3859         cmdline_fixed_string_t txpkts;
3860         cmdline_fixed_string_t seg_lengths;
3861 };
3862
3863 static void
3864 cmd_set_txpkts_parsed(void *parsed_result,
3865                       __rte_unused struct cmdline *cl,
3866                       __rte_unused void *data)
3867 {
3868         struct cmd_set_txpkts_result *res;
3869         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3870         unsigned int nb_segs;
3871
3872         res = parsed_result;
3873         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3874                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3875         if (nb_segs > 0)
3876                 set_tx_pkt_segments(seg_lengths, nb_segs);
3877 }
3878
3879 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3880         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3881                                  cmd_keyword, "set");
3882 cmdline_parse_token_string_t cmd_set_txpkts_name =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3884                                  txpkts, "txpkts");
3885 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3886         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3887                                  seg_lengths, NULL);
3888
3889 cmdline_parse_inst_t cmd_set_txpkts = {
3890         .f = cmd_set_txpkts_parsed,
3891         .data = NULL,
3892         .help_str = "set txpkts <len0[,len1]*>",
3893         .tokens = {
3894                 (void *)&cmd_set_txpkts_keyword,
3895                 (void *)&cmd_set_txpkts_name,
3896                 (void *)&cmd_set_txpkts_lengths,
3897                 NULL,
3898         },
3899 };
3900
3901 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3902
3903 struct cmd_set_txsplit_result {
3904         cmdline_fixed_string_t cmd_keyword;
3905         cmdline_fixed_string_t txsplit;
3906         cmdline_fixed_string_t mode;
3907 };
3908
3909 static void
3910 cmd_set_txsplit_parsed(void *parsed_result,
3911                       __rte_unused struct cmdline *cl,
3912                       __rte_unused void *data)
3913 {
3914         struct cmd_set_txsplit_result *res;
3915
3916         res = parsed_result;
3917         set_tx_pkt_split(res->mode);
3918 }
3919
3920 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3921         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3922                                  cmd_keyword, "set");
3923 cmdline_parse_token_string_t cmd_set_txsplit_name =
3924         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3925                                  txsplit, "txsplit");
3926 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3927         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3928                                  mode, NULL);
3929
3930 cmdline_parse_inst_t cmd_set_txsplit = {
3931         .f = cmd_set_txsplit_parsed,
3932         .data = NULL,
3933         .help_str = "set txsplit on|off|rand",
3934         .tokens = {
3935                 (void *)&cmd_set_txsplit_keyword,
3936                 (void *)&cmd_set_txsplit_name,
3937                 (void *)&cmd_set_txsplit_mode,
3938                 NULL,
3939         },
3940 };
3941
3942 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3943
3944 struct cmd_set_txtimes_result {
3945         cmdline_fixed_string_t cmd_keyword;
3946         cmdline_fixed_string_t txtimes;
3947         cmdline_fixed_string_t tx_times;
3948 };
3949
3950 static void
3951 cmd_set_txtimes_parsed(void *parsed_result,
3952                        __rte_unused struct cmdline *cl,
3953                        __rte_unused void *data)
3954 {
3955         struct cmd_set_txtimes_result *res;
3956         unsigned int tx_times[2] = {0, 0};
3957         unsigned int n_times;
3958
3959         res = parsed_result;
3960         n_times = parse_item_list(res->tx_times, "tx times",
3961                                   2, tx_times, 0);
3962         if (n_times == 2)
3963                 set_tx_pkt_times(tx_times);
3964 }
3965
3966 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3967         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3968                                  cmd_keyword, "set");
3969 cmdline_parse_token_string_t cmd_set_txtimes_name =
3970         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3971                                  txtimes, "txtimes");
3972 cmdline_parse_token_string_t cmd_set_txtimes_value =
3973         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3974                                  tx_times, NULL);
3975
3976 cmdline_parse_inst_t cmd_set_txtimes = {
3977         .f = cmd_set_txtimes_parsed,
3978         .data = NULL,
3979         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3980         .tokens = {
3981                 (void *)&cmd_set_txtimes_keyword,
3982                 (void *)&cmd_set_txtimes_name,
3983                 (void *)&cmd_set_txtimes_value,
3984                 NULL,
3985         },
3986 };
3987
3988 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3989 struct cmd_rx_vlan_filter_all_result {
3990         cmdline_fixed_string_t rx_vlan;
3991         cmdline_fixed_string_t what;
3992         cmdline_fixed_string_t all;
3993         portid_t port_id;
3994 };
3995
3996 static void
3997 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3998                               __rte_unused struct cmdline *cl,
3999                               __rte_unused void *data)
4000 {
4001         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4002
4003         if (!strcmp(res->what, "add"))
4004                 rx_vlan_all_filter_set(res->port_id, 1);
4005         else
4006                 rx_vlan_all_filter_set(res->port_id, 0);
4007 }
4008
4009 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4010         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4011                                  rx_vlan, "rx_vlan");
4012 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4013         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4014                                  what, "add#rm");
4015 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4016         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4017                                  all, "all");
4018 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4019         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4020                               port_id, RTE_UINT16);
4021
4022 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4023         .f = cmd_rx_vlan_filter_all_parsed,
4024         .data = NULL,
4025         .help_str = "rx_vlan add|rm all <port_id>: "
4026                 "Add/Remove all identifiers to/from the set of VLAN "
4027                 "identifiers filtered by a port",
4028         .tokens = {
4029                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4030                 (void *)&cmd_rx_vlan_filter_all_what,
4031                 (void *)&cmd_rx_vlan_filter_all_all,
4032                 (void *)&cmd_rx_vlan_filter_all_portid,
4033                 NULL,
4034         },
4035 };
4036
4037 /* *** VLAN OFFLOAD SET ON A PORT *** */
4038 struct cmd_vlan_offload_result {
4039         cmdline_fixed_string_t vlan;
4040         cmdline_fixed_string_t set;
4041         cmdline_fixed_string_t vlan_type;
4042         cmdline_fixed_string_t what;
4043         cmdline_fixed_string_t on;
4044         cmdline_fixed_string_t port_id;
4045 };
4046
4047 static void
4048 cmd_vlan_offload_parsed(void *parsed_result,
4049                           __rte_unused struct cmdline *cl,
4050                           __rte_unused void *data)
4051 {
4052         int on;
4053         struct cmd_vlan_offload_result *res = parsed_result;
4054         char *str;
4055         int i, len = 0;
4056         portid_t port_id = 0;
4057         unsigned int tmp;
4058
4059         str = res->port_id;
4060         len = strnlen(str, STR_TOKEN_SIZE);
4061         i = 0;
4062         /* Get port_id first */
4063         while(i < len){
4064                 if(str[i] == ',')
4065                         break;
4066
4067                 i++;
4068         }
4069         str[i]='\0';
4070         tmp = strtoul(str, NULL, 0);
4071         /* If port_id greater that what portid_t can represent, return */
4072         if(tmp >= RTE_MAX_ETHPORTS)
4073                 return;
4074         port_id = (portid_t)tmp;
4075
4076         if (!strcmp(res->on, "on"))
4077                 on = 1;
4078         else
4079                 on = 0;
4080
4081         if (!strcmp(res->what, "strip"))
4082                 rx_vlan_strip_set(port_id,  on);
4083         else if(!strcmp(res->what, "stripq")){
4084                 uint16_t queue_id = 0;
4085
4086                 /* No queue_id, return */
4087                 if(i + 1 >= len) {
4088                         printf("must specify (port,queue_id)\n");
4089                         return;
4090                 }
4091                 tmp = strtoul(str + i + 1, NULL, 0);
4092                 /* If queue_id greater that what 16-bits can represent, return */
4093                 if(tmp > 0xffff)
4094                         return;
4095
4096                 queue_id = (uint16_t)tmp;
4097                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4098         }
4099         else if (!strcmp(res->what, "filter"))
4100                 rx_vlan_filter_set(port_id, on);
4101         else if (!strcmp(res->what, "qinq_strip"))
4102                 rx_vlan_qinq_strip_set(port_id, on);
4103         else
4104                 vlan_extend_set(port_id, on);
4105
4106         return;
4107 }
4108
4109 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4110         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4111                                  vlan, "vlan");
4112 cmdline_parse_token_string_t cmd_vlan_offload_set =
4113         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4114                                  set, "set");
4115 cmdline_parse_token_string_t cmd_vlan_offload_what =
4116         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4117                                 what, "strip#filter#qinq_strip#extend#stripq");
4118 cmdline_parse_token_string_t cmd_vlan_offload_on =
4119         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4120                               on, "on#off");
4121 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4122         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4123                               port_id, NULL);
4124
4125 cmdline_parse_inst_t cmd_vlan_offload = {
4126         .f = cmd_vlan_offload_parsed,
4127         .data = NULL,
4128         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4129                 "<port_id[,queue_id]>: "
4130                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4131         .tokens = {
4132                 (void *)&cmd_vlan_offload_vlan,
4133                 (void *)&cmd_vlan_offload_set,
4134                 (void *)&cmd_vlan_offload_what,
4135                 (void *)&cmd_vlan_offload_on,
4136                 (void *)&cmd_vlan_offload_portid,
4137                 NULL,
4138         },
4139 };
4140
4141 /* *** VLAN TPID SET ON A PORT *** */
4142 struct cmd_vlan_tpid_result {
4143         cmdline_fixed_string_t vlan;
4144         cmdline_fixed_string_t set;
4145         cmdline_fixed_string_t vlan_type;
4146         cmdline_fixed_string_t what;
4147         uint16_t tp_id;
4148         portid_t port_id;
4149 };
4150
4151 static void
4152 cmd_vlan_tpid_parsed(void *parsed_result,
4153                           __rte_unused struct cmdline *cl,
4154                           __rte_unused void *data)
4155 {
4156         struct cmd_vlan_tpid_result *res = parsed_result;
4157         enum rte_vlan_type vlan_type;
4158
4159         if (!strcmp(res->vlan_type, "inner"))
4160                 vlan_type = ETH_VLAN_TYPE_INNER;
4161         else if (!strcmp(res->vlan_type, "outer"))
4162                 vlan_type = ETH_VLAN_TYPE_OUTER;
4163         else {
4164                 printf("Unknown vlan type\n");
4165                 return;
4166         }
4167         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4168 }
4169
4170 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4171         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4172                                  vlan, "vlan");
4173 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4174         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4175                                  set, "set");
4176 cmdline_parse_token_string_t cmd_vlan_type =
4177         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4178                                  vlan_type, "inner#outer");
4179 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4180         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4181                                  what, "tpid");
4182 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4183         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4184                               tp_id, RTE_UINT16);
4185 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4186         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4187                               port_id, RTE_UINT16);
4188
4189 cmdline_parse_inst_t cmd_vlan_tpid = {
4190         .f = cmd_vlan_tpid_parsed,
4191         .data = NULL,
4192         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4193                 "Set the VLAN Ether type",
4194         .tokens = {
4195                 (void *)&cmd_vlan_tpid_vlan,
4196                 (void *)&cmd_vlan_tpid_set,
4197                 (void *)&cmd_vlan_type,
4198                 (void *)&cmd_vlan_tpid_what,
4199                 (void *)&cmd_vlan_tpid_tpid,
4200                 (void *)&cmd_vlan_tpid_portid,
4201                 NULL,
4202         },
4203 };
4204
4205 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4206 struct cmd_rx_vlan_filter_result {
4207         cmdline_fixed_string_t rx_vlan;
4208         cmdline_fixed_string_t what;
4209         uint16_t vlan_id;
4210         portid_t port_id;
4211 };
4212
4213 static void
4214 cmd_rx_vlan_filter_parsed(void *parsed_result,
4215                           __rte_unused struct cmdline *cl,
4216                           __rte_unused void *data)
4217 {
4218         struct cmd_rx_vlan_filter_result *res = parsed_result;
4219
4220         if (!strcmp(res->what, "add"))
4221                 rx_vft_set(res->port_id, res->vlan_id, 1);
4222         else
4223                 rx_vft_set(res->port_id, res->vlan_id, 0);
4224 }
4225
4226 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4227         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4228                                  rx_vlan, "rx_vlan");
4229 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4230         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4231                                  what, "add#rm");
4232 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4233         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4234                               vlan_id, RTE_UINT16);
4235 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4236         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4237                               port_id, RTE_UINT16);
4238
4239 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4240         .f = cmd_rx_vlan_filter_parsed,
4241         .data = NULL,
4242         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4243                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4244                 "identifiers filtered by a port",
4245         .tokens = {
4246                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4247                 (void *)&cmd_rx_vlan_filter_what,
4248                 (void *)&cmd_rx_vlan_filter_vlanid,
4249                 (void *)&cmd_rx_vlan_filter_portid,
4250                 NULL,
4251         },
4252 };
4253
4254 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4255 struct cmd_tx_vlan_set_result {
4256         cmdline_fixed_string_t tx_vlan;
4257         cmdline_fixed_string_t set;
4258         portid_t port_id;
4259         uint16_t vlan_id;
4260 };
4261
4262 static void
4263 cmd_tx_vlan_set_parsed(void *parsed_result,
4264                        __rte_unused struct cmdline *cl,
4265                        __rte_unused void *data)
4266 {
4267         struct cmd_tx_vlan_set_result *res = parsed_result;
4268
4269         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4270                 return;
4271
4272         if (!port_is_stopped(res->port_id)) {
4273                 printf("Please stop port %d first\n", res->port_id);
4274                 return;
4275         }
4276
4277         tx_vlan_set(res->port_id, res->vlan_id);
4278
4279         cmd_reconfig_device_queue(res->port_id, 1, 1);
4280 }
4281
4282 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4283         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4284                                  tx_vlan, "tx_vlan");
4285 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4286         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4287                                  set, "set");
4288 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4290                               port_id, RTE_UINT16);
4291 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4292         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4293                               vlan_id, RTE_UINT16);
4294
4295 cmdline_parse_inst_t cmd_tx_vlan_set = {
4296         .f = cmd_tx_vlan_set_parsed,
4297         .data = NULL,
4298         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4299                 "Enable hardware insertion of a single VLAN header "
4300                 "with a given TAG Identifier in packets sent on a port",
4301         .tokens = {
4302                 (void *)&cmd_tx_vlan_set_tx_vlan,
4303                 (void *)&cmd_tx_vlan_set_set,
4304                 (void *)&cmd_tx_vlan_set_portid,
4305                 (void *)&cmd_tx_vlan_set_vlanid,
4306                 NULL,
4307         },
4308 };
4309
4310 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4311 struct cmd_tx_vlan_set_qinq_result {
4312         cmdline_fixed_string_t tx_vlan;
4313         cmdline_fixed_string_t set;
4314         portid_t port_id;
4315         uint16_t vlan_id;
4316         uint16_t vlan_id_outer;
4317 };
4318
4319 static void
4320 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4321                             __rte_unused struct cmdline *cl,
4322                             __rte_unused void *data)
4323 {
4324         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4325
4326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4327                 return;
4328
4329         if (!port_is_stopped(res->port_id)) {
4330                 printf("Please stop port %d first\n", res->port_id);
4331                 return;
4332         }
4333
4334         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4335
4336         cmd_reconfig_device_queue(res->port_id, 1, 1);
4337 }
4338
4339 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4340         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4341                 tx_vlan, "tx_vlan");
4342 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4343         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4344                 set, "set");
4345 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4346         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4347                 port_id, RTE_UINT16);
4348 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4349         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4350                 vlan_id, RTE_UINT16);
4351 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4352         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4353                 vlan_id_outer, RTE_UINT16);
4354
4355 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4356         .f = cmd_tx_vlan_set_qinq_parsed,
4357         .data = NULL,
4358         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4359                 "Enable hardware insertion of double VLAN header "
4360                 "with given TAG Identifiers in packets sent on a port",
4361         .tokens = {
4362                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4363                 (void *)&cmd_tx_vlan_set_qinq_set,
4364                 (void *)&cmd_tx_vlan_set_qinq_portid,
4365                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4366                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4367                 NULL,
4368         },
4369 };
4370
4371 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4372 struct cmd_tx_vlan_set_pvid_result {
4373         cmdline_fixed_string_t tx_vlan;
4374         cmdline_fixed_string_t set;
4375         cmdline_fixed_string_t pvid;
4376         portid_t port_id;
4377         uint16_t vlan_id;
4378         cmdline_fixed_string_t mode;
4379 };
4380
4381 static void
4382 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4383                             __rte_unused struct cmdline *cl,
4384                             __rte_unused void *data)
4385 {
4386         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4387
4388         if (strcmp(res->mode, "on") == 0)
4389                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4390         else
4391                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4392 }
4393
4394 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4395         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4396                                  tx_vlan, "tx_vlan");
4397 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4398         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4399                                  set, "set");
4400 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4401         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4402                                  pvid, "pvid");
4403 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4404         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4405                              port_id, RTE_UINT16);
4406 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4407         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4408                               vlan_id, RTE_UINT16);
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4411                                  mode, "on#off");
4412
4413 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4414         .f = cmd_tx_vlan_set_pvid_parsed,
4415         .data = NULL,
4416         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4417         .tokens = {
4418                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4419                 (void *)&cmd_tx_vlan_set_pvid_set,
4420                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4421                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4422                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4423                 (void *)&cmd_tx_vlan_set_pvid_mode,
4424                 NULL,
4425         },
4426 };
4427
4428 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4429 struct cmd_tx_vlan_reset_result {
4430         cmdline_fixed_string_t tx_vlan;
4431         cmdline_fixed_string_t reset;
4432         portid_t port_id;
4433 };
4434
4435 static void
4436 cmd_tx_vlan_reset_parsed(void *parsed_result,
4437                          __rte_unused struct cmdline *cl,
4438                          __rte_unused void *data)
4439 {
4440         struct cmd_tx_vlan_reset_result *res = parsed_result;
4441
4442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4443                 return;
4444
4445         if (!port_is_stopped(res->port_id)) {
4446                 printf("Please stop port %d first\n", res->port_id);
4447                 return;
4448         }
4449
4450         tx_vlan_reset(res->port_id);
4451
4452         cmd_reconfig_device_queue(res->port_id, 1, 1);
4453 }
4454
4455 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4457                                  tx_vlan, "tx_vlan");
4458 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4460                                  reset, "reset");
4461 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4462         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4463                               port_id, RTE_UINT16);
4464
4465 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4466         .f = cmd_tx_vlan_reset_parsed,
4467         .data = NULL,
4468         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4469                 "VLAN header in packets sent on a port",
4470         .tokens = {
4471                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4472                 (void *)&cmd_tx_vlan_reset_reset,
4473                 (void *)&cmd_tx_vlan_reset_portid,
4474                 NULL,
4475         },
4476 };
4477
4478
4479 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4480 struct cmd_csum_result {
4481         cmdline_fixed_string_t csum;
4482         cmdline_fixed_string_t mode;
4483         cmdline_fixed_string_t proto;
4484         cmdline_fixed_string_t hwsw;
4485         portid_t port_id;
4486 };
4487
4488 static void
4489 csum_show(int port_id)
4490 {
4491         struct rte_eth_dev_info dev_info;
4492         uint64_t tx_offloads;
4493         int ret;
4494
4495         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4496         printf("Parse tunnel is %s\n",
4497                 (ports[port_id].parse_tunnel) ? "on" : "off");
4498         printf("IP checksum offload is %s\n",
4499                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4500         printf("UDP checksum offload is %s\n",
4501                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4502         printf("TCP checksum offload is %s\n",
4503                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4504         printf("SCTP checksum offload is %s\n",
4505                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4506         printf("Outer-Ip checksum offload is %s\n",
4507                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4508         printf("Outer-Udp checksum offload is %s\n",
4509                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4510
4511         /* display warnings if configuration is not supported by the NIC */
4512         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4513         if (ret != 0)
4514                 return;
4515
4516         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4517                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4518                 printf("Warning: hardware IP checksum enabled but not "
4519                         "supported by port %d\n", port_id);
4520         }
4521         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4522                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4523                 printf("Warning: hardware UDP checksum enabled but not "
4524                         "supported by port %d\n", port_id);
4525         }
4526         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4527                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4528                 printf("Warning: hardware TCP checksum enabled but not "
4529                         "supported by port %d\n", port_id);
4530         }
4531         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4532                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4533                 printf("Warning: hardware SCTP checksum enabled but not "
4534                         "supported by port %d\n", port_id);
4535         }
4536         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4537                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4538                 printf("Warning: hardware outer IP checksum enabled but not "
4539                         "supported by port %d\n", port_id);
4540         }
4541         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4542                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4543                         == 0) {
4544                 printf("Warning: hardware outer UDP checksum enabled but not "
4545                         "supported by port %d\n", port_id);
4546         }
4547 }
4548
4549 static void
4550 cmd_config_queue_tx_offloads(struct rte_port *port)
4551 {
4552         int k;
4553
4554         /* Apply queue tx offloads configuration */
4555         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4556                 port->tx_conf[k].offloads =
4557                         port->dev_conf.txmode.offloads;
4558 }
4559
4560 static void
4561 cmd_csum_parsed(void *parsed_result,
4562                        __rte_unused struct cmdline *cl,
4563                        __rte_unused void *data)
4564 {
4565         struct cmd_csum_result *res = parsed_result;
4566         int hw = 0;
4567         uint64_t csum_offloads = 0;
4568         struct rte_eth_dev_info dev_info;
4569         int ret;
4570
4571         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4572                 printf("invalid port %d\n", res->port_id);
4573                 return;
4574         }
4575         if (!port_is_stopped(res->port_id)) {
4576                 printf("Please stop port %d first\n", res->port_id);
4577                 return;
4578         }
4579
4580         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4581         if (ret != 0)
4582                 return;
4583
4584         if (!strcmp(res->mode, "set")) {
4585
4586                 if (!strcmp(res->hwsw, "hw"))
4587                         hw = 1;
4588
4589                 if (!strcmp(res->proto, "ip")) {
4590                         if (hw == 0 || (dev_info.tx_offload_capa &
4591                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4592                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4593                         } else {
4594                                 printf("IP checksum offload is not supported "
4595                                        "by port %u\n", res->port_id);
4596                         }
4597                 } else if (!strcmp(res->proto, "udp")) {
4598                         if (hw == 0 || (dev_info.tx_offload_capa &
4599                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4600                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4601                         } else {
4602                                 printf("UDP checksum offload is not supported "
4603                                        "by port %u\n", res->port_id);
4604                         }
4605                 } else if (!strcmp(res->proto, "tcp")) {
4606                         if (hw == 0 || (dev_info.tx_offload_capa &
4607                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4608                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4609                         } else {
4610                                 printf("TCP checksum offload is not supported "
4611                                        "by port %u\n", res->port_id);
4612                         }
4613                 } else if (!strcmp(res->proto, "sctp")) {
4614                         if (hw == 0 || (dev_info.tx_offload_capa &
4615                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4616                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4617                         } else {
4618                                 printf("SCTP checksum offload is not supported "
4619                                        "by port %u\n", res->port_id);
4620                         }
4621                 } else if (!strcmp(res->proto, "outer-ip")) {
4622                         if (hw == 0 || (dev_info.tx_offload_capa &
4623                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4624                                 csum_offloads |=
4625                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4626                         } else {
4627                                 printf("Outer IP checksum offload is not "
4628                                        "supported by port %u\n", res->port_id);
4629                         }
4630                 } else if (!strcmp(res->proto, "outer-udp")) {
4631                         if (hw == 0 || (dev_info.tx_offload_capa &
4632                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4633                                 csum_offloads |=
4634                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4635                         } else {
4636                                 printf("Outer UDP checksum offload is not "
4637                                        "supported by port %u\n", res->port_id);
4638                         }
4639                 }
4640
4641                 if (hw) {
4642                         ports[res->port_id].dev_conf.txmode.offloads |=
4643                                                         csum_offloads;
4644                 } else {
4645                         ports[res->port_id].dev_conf.txmode.offloads &=
4646                                                         (~csum_offloads);
4647                 }
4648                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4649         }
4650         csum_show(res->port_id);
4651
4652         cmd_reconfig_device_queue(res->port_id, 1, 1);
4653 }
4654
4655 cmdline_parse_token_string_t cmd_csum_csum =
4656         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4657                                 csum, "csum");
4658 cmdline_parse_token_string_t cmd_csum_mode =
4659         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4660                                 mode, "set");
4661 cmdline_parse_token_string_t cmd_csum_proto =
4662         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4663                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4664 cmdline_parse_token_string_t cmd_csum_hwsw =
4665         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4666                                 hwsw, "hw#sw");
4667 cmdline_parse_token_num_t cmd_csum_portid =
4668         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4669                                 port_id, RTE_UINT16);
4670
4671 cmdline_parse_inst_t cmd_csum_set = {
4672         .f = cmd_csum_parsed,
4673         .data = NULL,
4674         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4675                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4676                 "using csum forward engine",
4677         .tokens = {
4678                 (void *)&cmd_csum_csum,
4679                 (void *)&cmd_csum_mode,
4680                 (void *)&cmd_csum_proto,
4681                 (void *)&cmd_csum_hwsw,
4682                 (void *)&cmd_csum_portid,
4683                 NULL,
4684         },
4685 };
4686
4687 cmdline_parse_token_string_t cmd_csum_mode_show =
4688         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4689                                 mode, "show");
4690
4691 cmdline_parse_inst_t cmd_csum_show = {
4692         .f = cmd_csum_parsed,
4693         .data = NULL,
4694         .help_str = "csum show <port_id>: Show checksum offload configuration",
4695         .tokens = {
4696                 (void *)&cmd_csum_csum,
4697                 (void *)&cmd_csum_mode_show,
4698                 (void *)&cmd_csum_portid,
4699                 NULL,
4700         },
4701 };
4702
4703 /* Enable/disable tunnel parsing */
4704 struct cmd_csum_tunnel_result {
4705         cmdline_fixed_string_t csum;
4706         cmdline_fixed_string_t parse;
4707         cmdline_fixed_string_t onoff;
4708         portid_t port_id;
4709 };
4710
4711 static void
4712 cmd_csum_tunnel_parsed(void *parsed_result,
4713                        __rte_unused struct cmdline *cl,
4714                        __rte_unused void *data)
4715 {
4716         struct cmd_csum_tunnel_result *res = parsed_result;
4717
4718         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4719                 return;
4720
4721         if (!strcmp(res->onoff, "on"))
4722                 ports[res->port_id].parse_tunnel = 1;
4723         else
4724                 ports[res->port_id].parse_tunnel = 0;
4725
4726         csum_show(res->port_id);
4727 }
4728
4729 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4730         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4731                                 csum, "csum");
4732 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4733         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4734                                 parse, "parse-tunnel");
4735 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4736         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4737                                 onoff, "on#off");
4738 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4739         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4740                                 port_id, RTE_UINT16);
4741
4742 cmdline_parse_inst_t cmd_csum_tunnel = {
4743         .f = cmd_csum_tunnel_parsed,
4744         .data = NULL,
4745         .help_str = "csum parse-tunnel on|off <port_id>: "
4746                 "Enable/Disable parsing of tunnels for csum engine",
4747         .tokens = {
4748                 (void *)&cmd_csum_tunnel_csum,
4749                 (void *)&cmd_csum_tunnel_parse,
4750                 (void *)&cmd_csum_tunnel_onoff,
4751                 (void *)&cmd_csum_tunnel_portid,
4752                 NULL,
4753         },
4754 };
4755
4756 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4757 struct cmd_tso_set_result {
4758         cmdline_fixed_string_t tso;
4759         cmdline_fixed_string_t mode;
4760         uint16_t tso_segsz;
4761         portid_t port_id;
4762 };
4763
4764 static void
4765 cmd_tso_set_parsed(void *parsed_result,
4766                        __rte_unused struct cmdline *cl,
4767                        __rte_unused void *data)
4768 {
4769         struct cmd_tso_set_result *res = parsed_result;
4770         struct rte_eth_dev_info dev_info;
4771         int ret;
4772
4773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4774                 return;
4775         if (!port_is_stopped(res->port_id)) {
4776                 printf("Please stop port %d first\n", res->port_id);
4777                 return;
4778         }
4779
4780         if (!strcmp(res->mode, "set"))
4781                 ports[res->port_id].tso_segsz = res->tso_segsz;
4782
4783         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4784         if (ret != 0)
4785                 return;
4786
4787         if ((ports[res->port_id].tso_segsz != 0) &&
4788                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4789                 printf("Error: TSO is not supported by port %d\n",
4790                        res->port_id);
4791                 return;
4792         }
4793
4794         if (ports[res->port_id].tso_segsz == 0) {
4795                 ports[res->port_id].dev_conf.txmode.offloads &=
4796                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4797                 printf("TSO for non-tunneled packets is disabled\n");
4798         } else {
4799                 ports[res->port_id].dev_conf.txmode.offloads |=
4800                                                 DEV_TX_OFFLOAD_TCP_TSO;
4801                 printf("TSO segment size for non-tunneled packets is %d\n",
4802                         ports[res->port_id].tso_segsz);
4803         }
4804         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4805
4806         /* display warnings if configuration is not supported by the NIC */
4807         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4808         if (ret != 0)
4809                 return;
4810
4811         if ((ports[res->port_id].tso_segsz != 0) &&
4812                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4813                 printf("Warning: TSO enabled but not "
4814                         "supported by port %d\n", res->port_id);
4815         }
4816
4817         cmd_reconfig_device_queue(res->port_id, 1, 1);
4818 }
4819
4820 cmdline_parse_token_string_t cmd_tso_set_tso =
4821         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4822                                 tso, "tso");
4823 cmdline_parse_token_string_t cmd_tso_set_mode =
4824         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4825                                 mode, "set");
4826 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4827         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4828                                 tso_segsz, RTE_UINT16);
4829 cmdline_parse_token_num_t cmd_tso_set_portid =
4830         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4831                                 port_id, RTE_UINT16);
4832
4833 cmdline_parse_inst_t cmd_tso_set = {
4834         .f = cmd_tso_set_parsed,
4835         .data = NULL,
4836         .help_str = "tso set <tso_segsz> <port_id>: "
4837                 "Set TSO segment size of non-tunneled packets for csum engine "
4838                 "(0 to disable)",
4839         .tokens = {
4840                 (void *)&cmd_tso_set_tso,
4841                 (void *)&cmd_tso_set_mode,
4842                 (void *)&cmd_tso_set_tso_segsz,
4843                 (void *)&cmd_tso_set_portid,
4844                 NULL,
4845         },
4846 };
4847
4848 cmdline_parse_token_string_t cmd_tso_show_mode =
4849         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4850                                 mode, "show");
4851
4852
4853 cmdline_parse_inst_t cmd_tso_show = {
4854         .f = cmd_tso_set_parsed,
4855         .data = NULL,
4856         .help_str = "tso show <port_id>: "
4857                 "Show TSO segment size of non-tunneled packets for csum engine",
4858         .tokens = {
4859                 (void *)&cmd_tso_set_tso,
4860                 (void *)&cmd_tso_show_mode,
4861                 (void *)&cmd_tso_set_portid,
4862                 NULL,
4863         },
4864 };
4865
4866 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4867 struct cmd_tunnel_tso_set_result {
4868         cmdline_fixed_string_t tso;
4869         cmdline_fixed_string_t mode;
4870         uint16_t tso_segsz;
4871         portid_t port_id;
4872 };
4873
4874 static struct rte_eth_dev_info
4875 check_tunnel_tso_nic_support(portid_t port_id)
4876 {
4877         struct rte_eth_dev_info dev_info;
4878
4879         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4880                 return dev_info;
4881
4882         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4883                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4884                        "not enabled for port %d\n", port_id);
4885         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4886                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4887                        "not enabled for port %d\n", port_id);
4888         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4889                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4890                        "not enabled for port %d\n", port_id);
4891         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4892                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4893                        "not enabled for port %d\n", port_id);
4894         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4895                 printf("Warning: IP TUNNEL TSO not supported therefore "
4896                        "not enabled for port %d\n", port_id);
4897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4898                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4899                        "not enabled for port %d\n", port_id);
4900         return dev_info;
4901 }
4902
4903 static void
4904 cmd_tunnel_tso_set_parsed(void *parsed_result,
4905                           __rte_unused struct cmdline *cl,
4906                           __rte_unused void *data)
4907 {
4908         struct cmd_tunnel_tso_set_result *res = parsed_result;
4909         struct rte_eth_dev_info dev_info;
4910
4911         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4912                 return;
4913         if (!port_is_stopped(res->port_id)) {
4914                 printf("Please stop port %d first\n", res->port_id);
4915                 return;
4916         }
4917
4918         if (!strcmp(res->mode, "set"))
4919                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4920
4921         dev_info = check_tunnel_tso_nic_support(res->port_id);
4922         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4923                 ports[res->port_id].dev_conf.txmode.offloads &=
4924                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4925                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4926                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4927                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4928                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4929                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4930                 printf("TSO for tunneled packets is disabled\n");
4931         } else {
4932                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4933                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4934                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4935                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4936                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4937                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4938
4939                 ports[res->port_id].dev_conf.txmode.offloads |=
4940                         (tso_offloads & dev_info.tx_offload_capa);
4941                 printf("TSO segment size for tunneled packets is %d\n",
4942                         ports[res->port_id].tunnel_tso_segsz);
4943
4944                 /* Below conditions are needed to make it work:
4945                  * (1) tunnel TSO is supported by the NIC;
4946                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4947                  * are recognized;
4948                  * (3) for tunneled pkts with outer L3 of IPv4,
4949                  * "csum set outer-ip" must be set to hw, because after tso,
4950                  * total_len of outer IP header is changed, and the checksum
4951                  * of outer IP header calculated by sw should be wrong; that
4952                  * is not necessary for IPv6 tunneled pkts because there's no
4953                  * checksum in IP header anymore.
4954                  */
4955
4956                 if (!ports[res->port_id].parse_tunnel)
4957                         printf("Warning: csum parse_tunnel must be set "
4958                                 "so that tunneled packets are recognized\n");
4959                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4960                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4961                         printf("Warning: csum set outer-ip must be set to hw "
4962                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4963         }
4964
4965         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4966         cmd_reconfig_device_queue(res->port_id, 1, 1);
4967 }
4968
4969 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4970         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4971                                 tso, "tunnel_tso");
4972 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4973         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4974                                 mode, "set");
4975 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4976         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4977                                 tso_segsz, RTE_UINT16);
4978 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4979         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4980                                 port_id, RTE_UINT16);
4981
4982 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4983         .f = cmd_tunnel_tso_set_parsed,
4984         .data = NULL,
4985         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4986                 "Set TSO segment size of tunneled packets for csum engine "
4987                 "(0 to disable)",
4988         .tokens = {
4989                 (void *)&cmd_tunnel_tso_set_tso,
4990                 (void *)&cmd_tunnel_tso_set_mode,
4991                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4992                 (void *)&cmd_tunnel_tso_set_portid,
4993                 NULL,
4994         },
4995 };
4996
4997 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4999                                 mode, "show");
5000
5001
5002 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5003         .f = cmd_tunnel_tso_set_parsed,
5004         .data = NULL,
5005         .help_str = "tunnel_tso show <port_id> "
5006                 "Show TSO segment size of tunneled packets for csum engine",
5007         .tokens = {
5008                 (void *)&cmd_tunnel_tso_set_tso,
5009                 (void *)&cmd_tunnel_tso_show_mode,
5010                 (void *)&cmd_tunnel_tso_set_portid,
5011                 NULL,
5012         },
5013 };
5014
5015 /* *** SET GRO FOR A PORT *** */
5016 struct cmd_gro_enable_result {
5017         cmdline_fixed_string_t cmd_set;
5018         cmdline_fixed_string_t cmd_port;
5019         cmdline_fixed_string_t cmd_keyword;
5020         cmdline_fixed_string_t cmd_onoff;
5021         portid_t cmd_pid;
5022 };
5023
5024 static void
5025 cmd_gro_enable_parsed(void *parsed_result,
5026                 __rte_unused struct cmdline *cl,
5027                 __rte_unused void *data)
5028 {
5029         struct cmd_gro_enable_result *res;
5030
5031         res = parsed_result;
5032         if (!strcmp(res->cmd_keyword, "gro"))
5033                 setup_gro(res->cmd_onoff, res->cmd_pid);
5034 }
5035
5036 cmdline_parse_token_string_t cmd_gro_enable_set =
5037         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5038                         cmd_set, "set");
5039 cmdline_parse_token_string_t cmd_gro_enable_port =
5040         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5041                         cmd_keyword, "port");
5042 cmdline_parse_token_num_t cmd_gro_enable_pid =
5043         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5044                         cmd_pid, RTE_UINT16);
5045 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5046         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5047                         cmd_keyword, "gro");
5048 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5049         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5050                         cmd_onoff, "on#off");
5051
5052 cmdline_parse_inst_t cmd_gro_enable = {
5053         .f = cmd_gro_enable_parsed,
5054         .data = NULL,
5055         .help_str = "set port <port_id> gro on|off",
5056         .tokens = {
5057                 (void *)&cmd_gro_enable_set,
5058                 (void *)&cmd_gro_enable_port,
5059                 (void *)&cmd_gro_enable_pid,
5060                 (void *)&cmd_gro_enable_keyword,
5061                 (void *)&cmd_gro_enable_onoff,
5062                 NULL,
5063         },
5064 };
5065
5066 /* *** DISPLAY GRO CONFIGURATION *** */
5067 struct cmd_gro_show_result {
5068         cmdline_fixed_string_t cmd_show;
5069         cmdline_fixed_string_t cmd_port;
5070         cmdline_fixed_string_t cmd_keyword;
5071         portid_t cmd_pid;
5072 };
5073
5074 static void
5075 cmd_gro_show_parsed(void *parsed_result,
5076                 __rte_unused struct cmdline *cl,
5077                 __rte_unused void *data)
5078 {
5079         struct cmd_gro_show_result *res;
5080
5081         res = parsed_result;
5082         if (!strcmp(res->cmd_keyword, "gro"))
5083                 show_gro(res->cmd_pid);
5084 }
5085
5086 cmdline_parse_token_string_t cmd_gro_show_show =
5087         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5088                         cmd_show, "show");
5089 cmdline_parse_token_string_t cmd_gro_show_port =
5090         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5091                         cmd_port, "port");
5092 cmdline_parse_token_num_t cmd_gro_show_pid =
5093         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5094                         cmd_pid, RTE_UINT16);
5095 cmdline_parse_token_string_t cmd_gro_show_keyword =
5096         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5097                         cmd_keyword, "gro");
5098
5099 cmdline_parse_inst_t cmd_gro_show = {
5100         .f = cmd_gro_show_parsed,
5101         .data = NULL,
5102         .help_str = "show port <port_id> gro",
5103         .tokens = {
5104                 (void *)&cmd_gro_show_show,
5105                 (void *)&cmd_gro_show_port,
5106                 (void *)&cmd_gro_show_pid,
5107                 (void *)&cmd_gro_show_keyword,
5108                 NULL,
5109         },
5110 };
5111
5112 /* *** SET FLUSH CYCLES FOR GRO *** */
5113 struct cmd_gro_flush_result {
5114         cmdline_fixed_string_t cmd_set;
5115         cmdline_fixed_string_t cmd_keyword;
5116         cmdline_fixed_string_t cmd_flush;
5117         uint8_t cmd_cycles;
5118 };
5119
5120 static void
5121 cmd_gro_flush_parsed(void *parsed_result,
5122                 __rte_unused struct cmdline *cl,
5123                 __rte_unused void *data)
5124 {
5125         struct cmd_gro_flush_result *res;
5126
5127         res = parsed_result;
5128         if ((!strcmp(res->cmd_keyword, "gro")) &&
5129                         (!strcmp(res->cmd_flush, "flush")))
5130                 setup_gro_flush_cycles(res->cmd_cycles);
5131 }
5132
5133 cmdline_parse_token_string_t cmd_gro_flush_set =
5134         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5135                         cmd_set, "set");
5136 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5137         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5138                         cmd_keyword, "gro");
5139 cmdline_parse_token_string_t cmd_gro_flush_flush =
5140         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5141                         cmd_flush, "flush");
5142 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5143         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5144                         cmd_cycles, RTE_UINT8);
5145
5146 cmdline_parse_inst_t cmd_gro_flush = {
5147         .f = cmd_gro_flush_parsed,
5148         .data = NULL,
5149         .help_str = "set gro flush <cycles>",
5150         .tokens = {
5151                 (void *)&cmd_gro_flush_set,
5152                 (void *)&cmd_gro_flush_keyword,
5153                 (void *)&cmd_gro_flush_flush,
5154                 (void *)&cmd_gro_flush_cycles,
5155                 NULL,
5156         },
5157 };
5158
5159 /* *** ENABLE/DISABLE GSO *** */
5160 struct cmd_gso_enable_result {
5161         cmdline_fixed_string_t cmd_set;
5162         cmdline_fixed_string_t cmd_port;
5163         cmdline_fixed_string_t cmd_keyword;
5164         cmdline_fixed_string_t cmd_mode;
5165         portid_t cmd_pid;
5166 };
5167
5168 static void
5169 cmd_gso_enable_parsed(void *parsed_result,
5170                 __rte_unused struct cmdline *cl,
5171                 __rte_unused void *data)
5172 {
5173         struct cmd_gso_enable_result *res;
5174
5175         res = parsed_result;
5176         if (!strcmp(res->cmd_keyword, "gso"))
5177                 setup_gso(res->cmd_mode, res->cmd_pid);
5178 }
5179
5180 cmdline_parse_token_string_t cmd_gso_enable_set =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5182                         cmd_set, "set");
5183 cmdline_parse_token_string_t cmd_gso_enable_port =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5185                         cmd_port, "port");
5186 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5188                         cmd_keyword, "gso");
5189 cmdline_parse_token_string_t cmd_gso_enable_mode =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5191                         cmd_mode, "on#off");
5192 cmdline_parse_token_num_t cmd_gso_enable_pid =
5193         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5194                         cmd_pid, RTE_UINT16);
5195
5196 cmdline_parse_inst_t cmd_gso_enable = {
5197         .f = cmd_gso_enable_parsed,
5198         .data = NULL,
5199         .help_str = "set port <port_id> gso on|off",
5200         .tokens = {
5201                 (void *)&cmd_gso_enable_set,
5202                 (void *)&cmd_gso_enable_port,
5203                 (void *)&cmd_gso_enable_pid,
5204                 (void *)&cmd_gso_enable_keyword,
5205                 (void *)&cmd_gso_enable_mode,
5206                 NULL,
5207         },
5208 };
5209
5210 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5211 struct cmd_gso_size_result {
5212         cmdline_fixed_string_t cmd_set;
5213         cmdline_fixed_string_t cmd_keyword;
5214         cmdline_fixed_string_t cmd_segsz;
5215         uint16_t cmd_size;
5216 };
5217
5218 static void
5219 cmd_gso_size_parsed(void *parsed_result,
5220                        __rte_unused struct cmdline *cl,
5221                        __rte_unused void *data)
5222 {
5223         struct cmd_gso_size_result *res = parsed_result;
5224
5225         if (test_done == 0) {
5226                 printf("Before setting GSO segsz, please first"
5227                                 " stop forwarding\n");
5228                 return;
5229         }
5230
5231         if (!strcmp(res->cmd_keyword, "gso") &&
5232                         !strcmp(res->cmd_segsz, "segsz")) {
5233                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5234                         printf("gso_size should be larger than %zu."
5235                                         " Please input a legal value\n",
5236                                         RTE_GSO_SEG_SIZE_MIN);
5237                 else
5238                         gso_max_segment_size = res->cmd_size;
5239         }
5240 }
5241
5242 cmdline_parse_token_string_t cmd_gso_size_set =
5243         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5244                                 cmd_set, "set");
5245 cmdline_parse_token_string_t cmd_gso_size_keyword =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5247                                 cmd_keyword, "gso");
5248 cmdline_parse_token_string_t cmd_gso_size_segsz =
5249         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5250                                 cmd_segsz, "segsz");
5251 cmdline_parse_token_num_t cmd_gso_size_size =
5252         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5253                                 cmd_size, RTE_UINT16);
5254
5255 cmdline_parse_inst_t cmd_gso_size = {
5256         .f = cmd_gso_size_parsed,
5257         .data = NULL,
5258         .help_str = "set gso segsz <length>",
5259         .tokens = {
5260                 (void *)&cmd_gso_size_set,
5261                 (void *)&cmd_gso_size_keyword,
5262                 (void *)&cmd_gso_size_segsz,
5263                 (void *)&cmd_gso_size_size,
5264                 NULL,
5265         },
5266 };
5267
5268 /* *** SHOW GSO CONFIGURATION *** */
5269 struct cmd_gso_show_result {
5270         cmdline_fixed_string_t cmd_show;
5271         cmdline_fixed_string_t cmd_port;
5272         cmdline_fixed_string_t cmd_keyword;
5273         portid_t cmd_pid;
5274 };
5275
5276 static void
5277 cmd_gso_show_parsed(void *parsed_result,
5278                        __rte_unused struct cmdline *cl,
5279                        __rte_unused void *data)
5280 {
5281         struct cmd_gso_show_result *res = parsed_result;
5282
5283         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5284                 printf("invalid port id %u\n", res->cmd_pid);
5285                 return;
5286         }
5287         if (!strcmp(res->cmd_keyword, "gso")) {
5288                 if (gso_ports[res->cmd_pid].enable) {
5289                         printf("Max GSO'd packet size: %uB\n"
5290                                         "Supported GSO types: TCP/IPv4, "
5291                                         "UDP/IPv4, VxLAN with inner "
5292                                         "TCP/IPv4 packet, GRE with inner "
5293                                         "TCP/IPv4 packet\n",
5294                                         gso_max_segment_size);
5295                 } else
5296                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5297         }
5298 }
5299
5300 cmdline_parse_token_string_t cmd_gso_show_show =
5301 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5302                 cmd_show, "show");
5303 cmdline_parse_token_string_t cmd_gso_show_port =
5304 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5305                 cmd_port, "port");
5306 cmdline_parse_token_string_t cmd_gso_show_keyword =
5307         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5308                                 cmd_keyword, "gso");
5309 cmdline_parse_token_num_t cmd_gso_show_pid =
5310         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5311                                 cmd_pid, RTE_UINT16);
5312
5313 cmdline_parse_inst_t cmd_gso_show = {
5314         .f = cmd_gso_show_parsed,
5315         .data = NULL,
5316         .help_str = "show port <port_id> gso",
5317         .tokens = {
5318                 (void *)&cmd_gso_show_show,
5319                 (void *)&cmd_gso_show_port,
5320                 (void *)&cmd_gso_show_pid,
5321                 (void *)&cmd_gso_show_keyword,
5322                 NULL,
5323         },
5324 };
5325
5326 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5327 struct cmd_set_flush_rx {
5328         cmdline_fixed_string_t set;
5329         cmdline_fixed_string_t flush_rx;
5330         cmdline_fixed_string_t mode;
5331 };
5332
5333 static void
5334 cmd_set_flush_rx_parsed(void *parsed_result,
5335                 __rte_unused struct cmdline *cl,
5336                 __rte_unused void *data)
5337 {
5338         struct cmd_set_flush_rx *res = parsed_result;
5339         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5340 }
5341
5342 cmdline_parse_token_string_t cmd_setflushrx_set =
5343         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5344                         set, "set");
5345 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5346         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5347                         flush_rx, "flush_rx");
5348 cmdline_parse_token_string_t cmd_setflushrx_mode =
5349         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5350                         mode, "on#off");
5351
5352
5353 cmdline_parse_inst_t cmd_set_flush_rx = {
5354         .f = cmd_set_flush_rx_parsed,
5355         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5356         .data = NULL,
5357         .tokens = {
5358                 (void *)&cmd_setflushrx_set,
5359                 (void *)&cmd_setflushrx_flush_rx,
5360                 (void *)&cmd_setflushrx_mode,
5361                 NULL,
5362         },
5363 };
5364
5365 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5366 struct cmd_set_link_check {
5367         cmdline_fixed_string_t set;
5368         cmdline_fixed_string_t link_check;
5369         cmdline_fixed_string_t mode;
5370 };
5371
5372 static void
5373 cmd_set_link_check_parsed(void *parsed_result,
5374                 __rte_unused struct cmdline *cl,
5375                 __rte_unused void *data)
5376 {
5377         struct cmd_set_link_check *res = parsed_result;
5378         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5379 }
5380
5381 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5383                         set, "set");
5384 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5385         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5386                         link_check, "link_check");
5387 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5388         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5389                         mode, "on#off");
5390
5391
5392 cmdline_parse_inst_t cmd_set_link_check = {
5393         .f = cmd_set_link_check_parsed,
5394         .help_str = "set link_check on|off: Enable/Disable link status check "
5395                     "when starting/stopping a port",
5396         .data = NULL,
5397         .tokens = {
5398                 (void *)&cmd_setlinkcheck_set,
5399                 (void *)&cmd_setlinkcheck_link_check,
5400                 (void *)&cmd_setlinkcheck_mode,
5401                 NULL,
5402         },
5403 };
5404
5405 /* *** SET NIC BYPASS MODE *** */
5406 struct cmd_set_bypass_mode_result {
5407         cmdline_fixed_string_t set;
5408         cmdline_fixed_string_t bypass;
5409         cmdline_fixed_string_t mode;
5410         cmdline_fixed_string_t value;
5411         portid_t port_id;
5412 };
5413
5414 static void
5415 cmd_set_bypass_mode_parsed(void *parsed_result,
5416                 __rte_unused struct cmdline *cl,
5417                 __rte_unused void *data)
5418 {
5419         struct cmd_set_bypass_mode_result *res = parsed_result;
5420         portid_t port_id = res->port_id;
5421         int32_t rc = -EINVAL;
5422
5423 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5424         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5425
5426         if (!strcmp(res->value, "bypass"))
5427                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5428         else if (!strcmp(res->value, "isolate"))
5429                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5430         else
5431                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5432
5433         /* Set the bypass mode for the relevant port. */
5434         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5435 #endif
5436         if (rc != 0)
5437                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5438 }
5439
5440 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5441         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5442                         set, "set");
5443 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5444         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5445                         bypass, "bypass");
5446 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5447         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5448                         mode, "mode");
5449 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5450         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5451                         value, "normal#bypass#isolate");
5452 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5453         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5454                                 port_id, RTE_UINT16);
5455
5456 cmdline_parse_inst_t cmd_set_bypass_mode = {
5457         .f = cmd_set_bypass_mode_parsed,
5458         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5459                     "Set the NIC bypass mode for port_id",
5460         .data = NULL,
5461         .tokens = {
5462                 (void *)&cmd_setbypass_mode_set,
5463                 (void *)&cmd_setbypass_mode_bypass,
5464                 (void *)&cmd_setbypass_mode_mode,
5465                 (void *)&cmd_setbypass_mode_value,
5466                 (void *)&cmd_setbypass_mode_port,
5467                 NULL,
5468         },
5469 };
5470
5471 /* *** SET NIC BYPASS EVENT *** */
5472 struct cmd_set_bypass_event_result {
5473         cmdline_fixed_string_t set;
5474         cmdline_fixed_string_t bypass;
5475         cmdline_fixed_string_t event;
5476         cmdline_fixed_string_t event_value;
5477         cmdline_fixed_string_t mode;
5478         cmdline_fixed_string_t mode_value;
5479         portid_t port_id;
5480 };
5481
5482 static void
5483 cmd_set_bypass_event_parsed(void *parsed_result,
5484                 __rte_unused struct cmdline *cl,
5485                 __rte_unused void *data)
5486 {
5487         int32_t rc = -EINVAL;
5488         struct cmd_set_bypass_event_result *res = parsed_result;
5489         portid_t port_id = res->port_id;
5490
5491 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5492         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5493         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5494
5495         if (!strcmp(res->event_value, "timeout"))
5496                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5497         else if (!strcmp(res->event_value, "os_on"))
5498                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5499         else if (!strcmp(res->event_value, "os_off"))
5500                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5501         else if (!strcmp(res->event_value, "power_on"))
5502                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5503         else if (!strcmp(res->event_value, "power_off"))
5504                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5505         else
5506                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5507
5508         if (!strcmp(res->mode_value, "bypass"))
5509                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5510         else if (!strcmp(res->mode_value, "isolate"))
5511                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5512         else
5513                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5514
5515         /* Set the watchdog timeout. */
5516         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5517
5518                 rc = -EINVAL;
5519                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5520                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5521                                                            bypass_timeout);
5522                 }
5523                 if (rc != 0) {
5524                         printf("Failed to set timeout value %u "
5525                         "for port %d, errto code: %d.\n",
5526                         bypass_timeout, port_id, rc);
5527                 }
5528         }
5529
5530         /* Set the bypass event to transition to bypass mode. */
5531         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5532                                               bypass_mode);
5533 #endif
5534
5535         if (rc != 0)
5536                 printf("\t Failed to set bypass event for port = %d.\n",
5537                        port_id);
5538 }
5539
5540 cmdline_parse_token_string_t cmd_setbypass_event_set =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5542                         set, "set");
5543 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5545                         bypass, "bypass");
5546 cmdline_parse_token_string_t cmd_setbypass_event_event =
5547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5548                         event, "event");
5549 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5551                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5552 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5554                         mode, "mode");
5555 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5557                         mode_value, "normal#bypass#isolate");
5558 cmdline_parse_token_num_t cmd_setbypass_event_port =
5559         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5560                                 port_id, RTE_UINT16);
5561
5562 cmdline_parse_inst_t cmd_set_bypass_event = {
5563         .f = cmd_set_bypass_event_parsed,
5564         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5565                 "power_off mode normal|bypass|isolate <port_id>: "
5566                 "Set the NIC bypass event mode for port_id",
5567         .data = NULL,
5568         .tokens = {
5569                 (void *)&cmd_setbypass_event_set,
5570                 (void *)&cmd_setbypass_event_bypass,
5571                 (void *)&cmd_setbypass_event_event,
5572                 (void *)&cmd_setbypass_event_event_value,
5573                 (void *)&cmd_setbypass_event_mode,
5574                 (void *)&cmd_setbypass_event_mode_value,
5575                 (void *)&cmd_setbypass_event_port,
5576                 NULL,
5577         },
5578 };
5579
5580
5581 /* *** SET NIC BYPASS TIMEOUT *** */
5582 struct cmd_set_bypass_timeout_result {
5583         cmdline_fixed_string_t set;
5584         cmdline_fixed_string_t bypass;
5585         cmdline_fixed_string_t timeout;
5586         cmdline_fixed_string_t value;
5587 };
5588
5589 static void
5590 cmd_set_bypass_timeout_parsed(void *parsed_result,
5591                 __rte_unused struct cmdline *cl,
5592                 __rte_unused void *data)
5593 {
5594         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5595
5596 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5597         if (!strcmp(res->value, "1.5"))
5598                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5599         else if (!strcmp(res->value, "2"))
5600                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5601         else if (!strcmp(res->value, "3"))
5602                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5603         else if (!strcmp(res->value, "4"))
5604                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5605         else if (!strcmp(res->value, "8"))
5606                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5607         else if (!strcmp(res->value, "16"))
5608                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5609         else if (!strcmp(res->value, "32"))
5610                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5611         else
5612                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5613 #endif
5614 }
5615
5616 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5617         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5618                         set, "set");
5619 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5621                         bypass, "bypass");
5622 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5624                         timeout, "timeout");
5625 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5627                         value, "0#1.5#2#3#4#8#16#32");
5628
5629 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5630         .f = cmd_set_bypass_timeout_parsed,
5631         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5632                 "Set the NIC bypass watchdog timeout in seconds",
5633         .data = NULL,
5634         .tokens = {
5635                 (void *)&cmd_setbypass_timeout_set,
5636                 (void *)&cmd_setbypass_timeout_bypass,
5637                 (void *)&cmd_setbypass_timeout_timeout,
5638                 (void *)&cmd_setbypass_timeout_value,
5639                 NULL,
5640         },
5641 };
5642
5643 /* *** SHOW NIC BYPASS MODE *** */
5644 struct cmd_show_bypass_config_result {
5645         cmdline_fixed_string_t show;
5646         cmdline_fixed_string_t bypass;
5647         cmdline_fixed_string_t config;
5648         portid_t port_id;
5649 };
5650
5651 static void
5652 cmd_show_bypass_config_parsed(void *parsed_result,
5653                 __rte_unused struct cmdline *cl,
5654                 __rte_unused void *data)
5655 {
5656         struct cmd_show_bypass_config_result *res = parsed_result;
5657         portid_t port_id = res->port_id;
5658         int rc = -EINVAL;
5659 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5660         uint32_t event_mode;
5661         uint32_t bypass_mode;
5662         uint32_t timeout = bypass_timeout;
5663         unsigned int i;
5664
5665         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5666                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5667         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5668                 {"UNKNOWN", "normal", "bypass", "isolate"};
5669         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5670                 "NONE",
5671                 "OS/board on",
5672                 "power supply on",
5673                 "OS/board off",
5674                 "power supply off",
5675                 "timeout"};
5676
5677         /* Display the bypass mode.*/
5678         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5679                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5680                 return;
5681         }
5682         else {
5683                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5684                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5685
5686                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5687         }
5688
5689         /* Display the bypass timeout.*/
5690         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5691                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5692
5693         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5694
5695         /* Display the bypass events and associated modes. */
5696         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5697
5698                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5699                         printf("\tFailed to get bypass mode for event = %s\n",
5700                                 events[i]);
5701                 } else {
5702                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5703                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5704
5705                         printf("\tbypass event: %-16s = %s\n", events[i],
5706                                 modes[event_mode]);
5707                 }
5708         }
5709 #endif
5710         if (rc != 0)
5711                 printf("\tFailed to get bypass configuration for port = %d\n",
5712                        port_id);
5713 }
5714
5715 cmdline_parse_token_string_t cmd_showbypass_config_show =
5716         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5717                         show, "show");
5718 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5719         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5720                         bypass, "bypass");
5721 cmdline_parse_token_string_t cmd_showbypass_config_config =
5722         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5723                         config, "config");
5724 cmdline_parse_token_num_t cmd_showbypass_config_port =
5725         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5726                                 port_id, RTE_UINT16);
5727
5728 cmdline_parse_inst_t cmd_show_bypass_config = {
5729         .f = cmd_show_bypass_config_parsed,
5730         .help_str = "show bypass config <port_id>: "
5731                     "Show the NIC bypass config for port_id",
5732         .data = NULL,
5733         .tokens = {
5734                 (void *)&cmd_showbypass_config_show,
5735                 (void *)&cmd_showbypass_config_bypass,
5736                 (void *)&cmd_showbypass_config_config,
5737                 (void *)&cmd_showbypass_config_port,
5738                 NULL,
5739         },
5740 };
5741
5742 #ifdef RTE_NET_BOND
5743 /* *** SET BONDING MODE *** */
5744 struct cmd_set_bonding_mode_result {
5745         cmdline_fixed_string_t set;
5746         cmdline_fixed_string_t bonding;
5747         cmdline_fixed_string_t mode;
5748         uint8_t value;
5749         portid_t port_id;
5750 };
5751
5752 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5753                 __rte_unused  struct cmdline *cl,
5754                 __rte_unused void *data)
5755 {
5756         struct cmd_set_bonding_mode_result *res = parsed_result;
5757         portid_t port_id = res->port_id;
5758
5759         /* Set the bonding mode for the relevant port. */
5760         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5761                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5762 }
5763
5764 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5765 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5766                 set, "set");
5767 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5768 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5769                 bonding, "bonding");
5770 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5771 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5772                 mode, "mode");
5773 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5774 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5775                 value, RTE_UINT8);
5776 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5777 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5778                 port_id, RTE_UINT16);
5779
5780 cmdline_parse_inst_t cmd_set_bonding_mode = {
5781                 .f = cmd_set_bonding_mode_parsed,
5782                 .help_str = "set bonding mode <mode_value> <port_id>: "
5783                         "Set the bonding mode for port_id",
5784                 .data = NULL,
5785                 .tokens = {
5786                                 (void *) &cmd_setbonding_mode_set,
5787                                 (void *) &cmd_setbonding_mode_bonding,
5788                                 (void *) &cmd_setbonding_mode_mode,
5789                                 (void *) &cmd_setbonding_mode_value,
5790                                 (void *) &cmd_setbonding_mode_port,
5791                                 NULL
5792                 }
5793 };
5794
5795 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5796 struct cmd_set_bonding_lacp_dedicated_queues_result {
5797         cmdline_fixed_string_t set;
5798         cmdline_fixed_string_t bonding;
5799         cmdline_fixed_string_t lacp;
5800         cmdline_fixed_string_t dedicated_queues;
5801         portid_t port_id;
5802         cmdline_fixed_string_t mode;
5803 };
5804
5805 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5806                 __rte_unused  struct cmdline *cl,
5807                 __rte_unused void *data)
5808 {
5809         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5810         portid_t port_id = res->port_id;
5811         struct rte_port *port;
5812
5813         port = &ports[port_id];
5814
5815         /** Check if the port is not started **/
5816         if (port->port_status != RTE_PORT_STOPPED) {
5817                 printf("Please stop port %d first\n", port_id);
5818                 return;
5819         }
5820
5821         if (!strcmp(res->mode, "enable")) {
5822                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5823                         printf("Dedicate queues for LACP control packets"
5824                                         " enabled\n");
5825                 else
5826                         printf("Enabling dedicate queues for LACP control "
5827                                         "packets on port %d failed\n", port_id);
5828         } else if (!strcmp(res->mode, "disable")) {
5829                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5830                         printf("Dedicated queues for LACP control packets "
5831                                         "disabled\n");
5832                 else
5833                         printf("Disabling dedicated queues for LACP control "
5834                                         "traffic on port %d failed\n", port_id);
5835         }
5836 }
5837
5838 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5839 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5840                 set, "set");
5841 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5842 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5843                 bonding, "bonding");
5844 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5845 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5846                 lacp, "lacp");
5847 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5849                 dedicated_queues, "dedicated_queues");
5850 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5851 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5852                 port_id, RTE_UINT16);
5853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5855                 mode, "enable#disable");
5856
5857 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5858                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5859                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5860                         "enable|disable: "
5861                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5862                 .data = NULL,
5863                 .tokens = {
5864                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5865                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5866                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5867                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5868                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5869                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5870                         NULL
5871                 }
5872 };
5873
5874 /* *** SET BALANCE XMIT POLICY *** */
5875 struct cmd_set_bonding_balance_xmit_policy_result {
5876         cmdline_fixed_string_t set;
5877         cmdline_fixed_string_t bonding;
5878         cmdline_fixed_string_t balance_xmit_policy;
5879         portid_t port_id;
5880         cmdline_fixed_string_t policy;
5881 };
5882
5883 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5884                 __rte_unused  struct cmdline *cl,
5885                 __rte_unused void *data)
5886 {
5887         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5888         portid_t port_id = res->port_id;
5889         uint8_t policy;
5890
5891         if (!strcmp(res->policy, "l2")) {
5892                 policy = BALANCE_XMIT_POLICY_LAYER2;
5893         } else if (!strcmp(res->policy, "l23")) {
5894                 policy = BALANCE_XMIT_POLICY_LAYER23;
5895         } else if (!strcmp(res->policy, "l34")) {
5896                 policy = BALANCE_XMIT_POLICY_LAYER34;
5897         } else {
5898                 printf("\t Invalid xmit policy selection");
5899                 return;
5900         }
5901
5902         /* Set the bonding mode for the relevant port. */
5903         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5904                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5905                                 port_id);
5906         }
5907 }
5908
5909 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5910 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5911                 set, "set");
5912 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5913 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5914                 bonding, "bonding");
5915 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5916 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5917                 balance_xmit_policy, "balance_xmit_policy");
5918 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5919 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5920                 port_id, RTE_UINT16);
5921 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5923                 policy, "l2#l23#l34");
5924
5925 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5926                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5927                 .help_str = "set bonding balance_xmit_policy <port_id> "
5928                         "l2|l23|l34: "
5929                         "Set the bonding balance_xmit_policy for port_id",
5930                 .data = NULL,
5931                 .tokens = {
5932                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5933                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5934                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5935                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5936                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5937                                 NULL
5938                 }
5939 };
5940
5941 /* *** SHOW NIC BONDING CONFIGURATION *** */
5942 struct cmd_show_bonding_config_result {
5943         cmdline_fixed_string_t show;
5944         cmdline_fixed_string_t bonding;
5945         cmdline_fixed_string_t config;
5946         portid_t port_id;
5947 };
5948
5949 static void cmd_show_bonding_config_parsed(void *parsed_result,
5950                 __rte_unused  struct cmdline *cl,
5951                 __rte_unused void *data)
5952 {
5953         struct cmd_show_bonding_config_result *res = parsed_result;
5954         int bonding_mode, agg_mode;
5955         portid_t slaves[RTE_MAX_ETHPORTS];
5956         int num_slaves, num_active_slaves;
5957         int primary_id;
5958         int i;
5959         portid_t port_id = res->port_id;
5960
5961         /* Display the bonding mode.*/
5962         bonding_mode = rte_eth_bond_mode_get(port_id);
5963         if (bonding_mode < 0) {
5964                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5965                 return;
5966         } else
5967                 printf("\tBonding mode: %d\n", bonding_mode);
5968
5969         if (bonding_mode == BONDING_MODE_BALANCE) {
5970                 int balance_xmit_policy;
5971
5972                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5973                 if (balance_xmit_policy < 0) {
5974                         printf("\tFailed to get balance xmit policy for port = %d\n",
5975                                         port_id);
5976                         return;
5977                 } else {
5978                         printf("\tBalance Xmit Policy: ");
5979
5980                         switch (balance_xmit_policy) {
5981                         case BALANCE_XMIT_POLICY_LAYER2:
5982                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5983                                 break;
5984                         case BALANCE_XMIT_POLICY_LAYER23:
5985                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5986                                 break;
5987                         case BALANCE_XMIT_POLICY_LAYER34:
5988                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5989                                 break;
5990                         }
5991                         printf("\n");
5992                 }
5993         }
5994
5995         if (bonding_mode == BONDING_MODE_8023AD) {
5996                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5997                 printf("\tIEEE802.3AD Aggregator Mode: ");
5998                 switch (agg_mode) {
5999                 case AGG_BANDWIDTH:
6000                         printf("bandwidth");
6001                         break;
6002                 case AGG_STABLE:
6003                         printf("stable");
6004                         break;
6005                 case AGG_COUNT:
6006                         printf("count");
6007                         break;
6008                 }
6009                 printf("\n");
6010         }
6011
6012         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6013
6014         if (num_slaves < 0) {
6015                 printf("\tFailed to get slave list for port = %d\n", port_id);
6016                 return;
6017         }
6018         if (num_slaves > 0) {
6019                 printf("\tSlaves (%d): [", num_slaves);
6020                 for (i = 0; i < num_slaves - 1; i++)
6021                         printf("%d ", slaves[i]);
6022
6023                 printf("%d]\n", slaves[num_slaves - 1]);
6024         } else {
6025                 printf("\tSlaves: []\n");
6026
6027         }
6028
6029         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6030                         RTE_MAX_ETHPORTS);
6031
6032         if (num_active_slaves < 0) {
6033                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6034                 return;
6035         }
6036         if (num_active_slaves > 0) {
6037                 printf("\tActive Slaves (%d): [", num_active_slaves);
6038                 for (i = 0; i < num_active_slaves - 1; i++)
6039                         printf("%d ", slaves[i]);
6040
6041                 printf("%d]\n", slaves[num_active_slaves - 1]);
6042
6043         } else {
6044                 printf("\tActive Slaves: []\n");
6045
6046         }
6047
6048         primary_id = rte_eth_bond_primary_get(port_id);
6049         if (primary_id < 0) {
6050                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6051                 return;
6052         } else
6053                 printf("\tPrimary: [%d]\n", primary_id);
6054
6055 }
6056
6057 cmdline_parse_token_string_t cmd_showbonding_config_show =
6058 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6059                 show, "show");
6060 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6061 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6062                 bonding, "bonding");
6063 cmdline_parse_token_string_t cmd_showbonding_config_config =
6064 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6065                 config, "config");
6066 cmdline_parse_token_num_t cmd_showbonding_config_port =
6067 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6068                 port_id, RTE_UINT16);
6069
6070 cmdline_parse_inst_t cmd_show_bonding_config = {
6071                 .f = cmd_show_bonding_config_parsed,
6072                 .help_str = "show bonding config <port_id>: "
6073                         "Show the bonding config for port_id",
6074                 .data = NULL,
6075                 .tokens = {
6076                                 (void *)&cmd_showbonding_config_show,
6077                                 (void *)&cmd_showbonding_config_bonding,
6078                                 (void *)&cmd_showbonding_config_config,
6079                                 (void *)&cmd_showbonding_config_port,
6080                                 NULL
6081                 }
6082 };
6083
6084 /* *** SET BONDING PRIMARY *** */
6085 struct cmd_set_bonding_primary_result {
6086         cmdline_fixed_string_t set;
6087         cmdline_fixed_string_t bonding;
6088         cmdline_fixed_string_t primary;
6089         portid_t slave_id;
6090         portid_t port_id;
6091 };
6092
6093 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6094                 __rte_unused  struct cmdline *cl,
6095                 __rte_unused void *data)
6096 {
6097         struct cmd_set_bonding_primary_result *res = parsed_result;
6098         portid_t master_port_id = res->port_id;
6099         portid_t slave_port_id = res->slave_id;
6100
6101         /* Set the primary slave for a bonded device. */
6102         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6103                 printf("\t Failed to set primary slave for port = %d.\n",
6104                                 master_port_id);
6105                 return;
6106         }
6107         init_port_config();
6108 }
6109
6110 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6112                 set, "set");
6113 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6114 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6115                 bonding, "bonding");
6116 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6117 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6118                 primary, "primary");
6119 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6120 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6121                 slave_id, RTE_UINT16);
6122 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6123 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6124                 port_id, RTE_UINT16);
6125
6126 cmdline_parse_inst_t cmd_set_bonding_primary = {
6127                 .f = cmd_set_bonding_primary_parsed,
6128                 .help_str = "set bonding primary <slave_id> <port_id>: "
6129                         "Set the primary slave for port_id",
6130                 .data = NULL,
6131                 .tokens = {
6132                                 (void *)&cmd_setbonding_primary_set,
6133                                 (void *)&cmd_setbonding_primary_bonding,
6134                                 (void *)&cmd_setbonding_primary_primary,
6135                                 (void *)&cmd_setbonding_primary_slave,
6136                                 (void *)&cmd_setbonding_primary_port,
6137                                 NULL
6138                 }
6139 };
6140
6141 /* *** ADD SLAVE *** */
6142 struct cmd_add_bonding_slave_result {
6143         cmdline_fixed_string_t add;
6144         cmdline_fixed_string_t bonding;
6145         cmdline_fixed_string_t slave;
6146         portid_t slave_id;
6147         portid_t port_id;
6148 };
6149
6150 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6151                 __rte_unused  struct cmdline *cl,
6152                 __rte_unused void *data)
6153 {
6154         struct cmd_add_bonding_slave_result *res = parsed_result;
6155         portid_t master_port_id = res->port_id;
6156         portid_t slave_port_id = res->slave_id;
6157
6158         /* add the slave for a bonded device. */
6159         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6160                 printf("\t Failed to add slave %d to master port = %d.\n",
6161                                 slave_port_id, master_port_id);
6162                 return;
6163         }
6164         init_port_config();
6165         set_port_slave_flag(slave_port_id);
6166 }
6167
6168 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6169 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6170                 add, "add");
6171 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6172 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6173                 bonding, "bonding");
6174 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6175 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6176                 slave, "slave");
6177 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6178 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6179                 slave_id, RTE_UINT16);
6180 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6181 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6182                 port_id, RTE_UINT16);
6183
6184 cmdline_parse_inst_t cmd_add_bonding_slave = {
6185                 .f = cmd_add_bonding_slave_parsed,
6186                 .help_str = "add bonding slave <slave_id> <port_id>: "
6187                         "Add a slave device to a bonded device",
6188                 .data = NULL,
6189                 .tokens = {
6190                                 (void *)&cmd_addbonding_slave_add,
6191                                 (void *)&cmd_addbonding_slave_bonding,
6192                                 (void *)&cmd_addbonding_slave_slave,
6193                                 (void *)&cmd_addbonding_slave_slaveid,
6194                                 (void *)&cmd_addbonding_slave_port,
6195                                 NULL
6196                 }
6197 };
6198
6199 /* *** REMOVE SLAVE *** */
6200 struct cmd_remove_bonding_slave_result {
6201         cmdline_fixed_string_t remove;
6202         cmdline_fixed_string_t bonding;
6203         cmdline_fixed_string_t slave;
6204         portid_t slave_id;
6205         portid_t port_id;
6206 };
6207
6208 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6209                 __rte_unused  struct cmdline *cl,
6210                 __rte_unused void *data)
6211 {
6212         struct cmd_remove_bonding_slave_result *res = parsed_result;
6213         portid_t master_port_id = res->port_id;
6214         portid_t slave_port_id = res->slave_id;
6215
6216         /* remove the slave from a bonded device. */
6217         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6218                 printf("\t Failed to remove slave %d from master port = %d.\n",
6219                                 slave_port_id, master_port_id);
6220                 return;
6221         }
6222         init_port_config();
6223         clear_port_slave_flag(slave_port_id);
6224 }
6225
6226 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6227                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6228                                 remove, "remove");
6229 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6230                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6231                                 bonding, "bonding");
6232 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6233                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6234                                 slave, "slave");
6235 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6236                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6237                                 slave_id, RTE_UINT16);
6238 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6239                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6240                                 port_id, RTE_UINT16);
6241
6242 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6243                 .f = cmd_remove_bonding_slave_parsed,
6244                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6245                         "Remove a slave device from a bonded device",
6246                 .data = NULL,
6247                 .tokens = {
6248                                 (void *)&cmd_removebonding_slave_remove,
6249                                 (void *)&cmd_removebonding_slave_bonding,
6250                                 (void *)&cmd_removebonding_slave_slave,
6251                                 (void *)&cmd_removebonding_slave_slaveid,
6252                                 (void *)&cmd_removebonding_slave_port,
6253                                 NULL
6254                 }
6255 };
6256
6257 /* *** CREATE BONDED DEVICE *** */
6258 struct cmd_create_bonded_device_result {
6259         cmdline_fixed_string_t create;
6260         cmdline_fixed_string_t bonded;
6261         cmdline_fixed_string_t device;
6262         uint8_t mode;
6263         uint8_t socket;
6264 };
6265
6266 static int bond_dev_num = 0;
6267
6268 static void cmd_create_bonded_device_parsed(void *parsed_result,
6269                 __rte_unused  struct cmdline *cl,
6270                 __rte_unused void *data)
6271 {
6272         struct cmd_create_bonded_device_result *res = parsed_result;
6273         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6274         int port_id;
6275         int ret;
6276
6277         if (test_done == 0) {
6278                 printf("Please stop forwarding first\n");
6279                 return;
6280         }
6281
6282         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6283                         bond_dev_num++);
6284
6285         /* Create a new bonded device. */
6286         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6287         if (port_id < 0) {
6288                 printf("\t Failed to create bonded device.\n");
6289                 return;
6290         } else {
6291                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6292                                 port_id);
6293
6294                 /* Update number of ports */
6295                 nb_ports = rte_eth_dev_count_avail();
6296                 reconfig(port_id, res->socket);
6297                 ret = rte_eth_promiscuous_enable(port_id);
6298                 if (ret != 0)
6299                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6300                                 port_id, rte_strerror(-ret));
6301
6302                 ports[port_id].need_setup = 0;
6303                 ports[port_id].port_status = RTE_PORT_STOPPED;
6304         }
6305
6306 }
6307
6308 cmdline_parse_token_string_t cmd_createbonded_device_create =
6309                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6310                                 create, "create");
6311 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6312                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6313                                 bonded, "bonded");
6314 cmdline_parse_token_string_t cmd_createbonded_device_device =
6315                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6316                                 device, "device");
6317 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6318                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6319                                 mode, RTE_UINT8);
6320 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6321                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6322                                 socket, RTE_UINT8);
6323
6324 cmdline_parse_inst_t cmd_create_bonded_device = {
6325                 .f = cmd_create_bonded_device_parsed,
6326                 .help_str = "create bonded device <mode> <socket>: "
6327                         "Create a new bonded device with specific bonding mode and socket",
6328                 .data = NULL,
6329                 .tokens = {
6330                                 (void *)&cmd_createbonded_device_create,
6331                                 (void *)&cmd_createbonded_device_bonded,
6332                                 (void *)&cmd_createbonded_device_device,
6333                                 (void *)&cmd_createbonded_device_mode,
6334                                 (void *)&cmd_createbonded_device_socket,
6335                                 NULL
6336                 }
6337 };
6338
6339 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6340 struct cmd_set_bond_mac_addr_result {
6341         cmdline_fixed_string_t set;
6342         cmdline_fixed_string_t bonding;
6343         cmdline_fixed_string_t mac_addr;
6344         uint16_t port_num;
6345         struct rte_ether_addr address;
6346 };
6347
6348 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6349                 __rte_unused  struct cmdline *cl,
6350                 __rte_unused void *data)
6351 {
6352         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6353         int ret;
6354
6355         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6356                 return;
6357
6358         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6359
6360         /* check the return value and print it if is < 0 */
6361         if (ret < 0)
6362                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6363 }
6364
6365 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6366                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6367 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6368                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6369                                 "bonding");
6370 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6371                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6372                                 "mac_addr");
6373 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6374                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6375                                 port_num, RTE_UINT16);
6376 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6377                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6378
6379 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6380                 .f = cmd_set_bond_mac_addr_parsed,
6381                 .data = (void *) 0,
6382                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6383                 .tokens = {
6384                                 (void *)&cmd_set_bond_mac_addr_set,
6385                                 (void *)&cmd_set_bond_mac_addr_bonding,
6386                                 (void *)&cmd_set_bond_mac_addr_mac,
6387                                 (void *)&cmd_set_bond_mac_addr_portnum,
6388                                 (void *)&cmd_set_bond_mac_addr_addr,
6389                                 NULL
6390                 }
6391 };
6392
6393
6394 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6395 struct cmd_set_bond_mon_period_result {
6396         cmdline_fixed_string_t set;
6397         cmdline_fixed_string_t bonding;
6398         cmdline_fixed_string_t mon_period;
6399         uint16_t port_num;
6400         uint32_t period_ms;
6401 };
6402
6403 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6404                 __rte_unused  struct cmdline *cl,
6405                 __rte_unused void *data)
6406 {
6407         struct cmd_set_bond_mon_period_result *res = parsed_result;
6408         int ret;
6409
6410         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6411
6412         /* check the return value and print it if is < 0 */
6413         if (ret < 0)
6414                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6415 }
6416
6417 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6418                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6419                                 set, "set");
6420 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6421                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6422                                 bonding, "bonding");
6423 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6424                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6425                                 mon_period,     "mon_period");
6426 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6427                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6428                                 port_num, RTE_UINT16);
6429 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6430                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6431                                 period_ms, RTE_UINT32);
6432
6433 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6434                 .f = cmd_set_bond_mon_period_parsed,
6435                 .data = (void *) 0,
6436                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6437                 .tokens = {
6438                                 (void *)&cmd_set_bond_mon_period_set,
6439                                 (void *)&cmd_set_bond_mon_period_bonding,
6440                                 (void *)&cmd_set_bond_mon_period_mon_period,
6441                                 (void *)&cmd_set_bond_mon_period_portnum,
6442                                 (void *)&cmd_set_bond_mon_period_period_ms,
6443                                 NULL
6444                 }
6445 };
6446
6447
6448
6449 struct cmd_set_bonding_agg_mode_policy_result {
6450         cmdline_fixed_string_t set;
6451         cmdline_fixed_string_t bonding;
6452         cmdline_fixed_string_t agg_mode;
6453         uint16_t port_num;
6454         cmdline_fixed_string_t policy;
6455 };
6456
6457
6458 static void
6459 cmd_set_bonding_agg_mode(void *parsed_result,
6460                 __rte_unused struct cmdline *cl,
6461                 __rte_unused void *data)
6462 {
6463         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6464         uint8_t policy = AGG_BANDWIDTH;
6465
6466         if (!strcmp(res->policy, "bandwidth"))
6467                 policy = AGG_BANDWIDTH;
6468         else if (!strcmp(res->policy, "stable"))
6469                 policy = AGG_STABLE;
6470         else if (!strcmp(res->policy, "count"))
6471                 policy = AGG_COUNT;
6472
6473         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6474 }
6475
6476
6477 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6479                                 set, "set");
6480 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6482                                 bonding, "bonding");
6483
6484 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6485         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6486                                 agg_mode, "agg_mode");
6487
6488 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6489         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6490                                 port_num, RTE_UINT16);
6491
6492 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6493         TOKEN_STRING_INITIALIZER(
6494                         struct cmd_set_bonding_balance_xmit_policy_result,
6495                 policy, "stable#bandwidth#count");
6496
6497 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6498         .f = cmd_set_bonding_agg_mode,
6499         .data = (void *) 0,
6500         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6501         .tokens = {
6502                         (void *)&cmd_set_bonding_agg_mode_set,
6503                         (void *)&cmd_set_bonding_agg_mode_bonding,
6504                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6505                         (void *)&cmd_set_bonding_agg_mode_portnum,
6506                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6507                         NULL
6508                 }
6509 };
6510
6511
6512 #endif /* RTE_NET_BOND */
6513
6514 /* *** SET FORWARDING MODE *** */
6515 struct cmd_set_fwd_mode_result {
6516         cmdline_fixed_string_t set;
6517         cmdline_fixed_string_t fwd;
6518         cmdline_fixed_string_t mode;
6519 };
6520
6521 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6522                                     __rte_unused struct cmdline *cl,
6523                                     __rte_unused void *data)
6524 {
6525         struct cmd_set_fwd_mode_result *res = parsed_result;
6526
6527         retry_enabled = 0;
6528         set_pkt_forwarding_mode(res->mode);
6529 }
6530
6531 cmdline_parse_token_string_t cmd_setfwd_set =
6532         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6533 cmdline_parse_token_string_t cmd_setfwd_fwd =
6534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6535 cmdline_parse_token_string_t cmd_setfwd_mode =
6536         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6537                 "" /* defined at init */);
6538
6539 cmdline_parse_inst_t cmd_set_fwd_mode = {
6540         .f = cmd_set_fwd_mode_parsed,
6541         .data = NULL,
6542         .help_str = NULL, /* defined at init */
6543         .tokens = {
6544                 (void *)&cmd_setfwd_set,
6545                 (void *)&cmd_setfwd_fwd,
6546                 (void *)&cmd_setfwd_mode,
6547                 NULL,
6548         },
6549 };
6550
6551 static void cmd_set_fwd_mode_init(void)
6552 {
6553         char *modes, *c;
6554         static char token[128];
6555         static char help[256];
6556         cmdline_parse_token_string_t *token_struct;
6557
6558         modes = list_pkt_forwarding_modes();
6559         snprintf(help, sizeof(help), "set fwd %s: "
6560                 "Set packet forwarding mode", modes);
6561         cmd_set_fwd_mode.help_str = help;
6562
6563         /* string token separator is # */
6564         for (c = token; *modes != '\0'; modes++)
6565                 if (*modes == '|')
6566                         *c++ = '#';
6567                 else
6568                         *c++ = *modes;
6569         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6570         token_struct->string_data.str = token;
6571 }
6572
6573 /* *** SET RETRY FORWARDING MODE *** */
6574 struct cmd_set_fwd_retry_mode_result {
6575         cmdline_fixed_string_t set;
6576         cmdline_fixed_string_t fwd;
6577         cmdline_fixed_string_t mode;
6578         cmdline_fixed_string_t retry;
6579 };
6580
6581 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6582                             __rte_unused struct cmdline *cl,
6583                             __rte_unused void *data)
6584 {
6585         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6586
6587         retry_enabled = 1;
6588         set_pkt_forwarding_mode(res->mode);
6589 }
6590
6591 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6592         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6593                         set, "set");
6594 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6596                         fwd, "fwd");
6597 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6598         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6599                         mode,
6600                 "" /* defined at init */);
6601 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6602         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6603                         retry, "retry");
6604
6605 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6606         .f = cmd_set_fwd_retry_mode_parsed,
6607         .data = NULL,
6608         .help_str = NULL, /* defined at init */
6609         .tokens = {
6610                 (void *)&cmd_setfwd_retry_set,
6611                 (void *)&cmd_setfwd_retry_fwd,
6612                 (void *)&cmd_setfwd_retry_mode,
6613                 (void *)&cmd_setfwd_retry_retry,
6614                 NULL,
6615         },
6616 };
6617
6618 static void cmd_set_fwd_retry_mode_init(void)
6619 {
6620         char *modes, *c;
6621         static char token[128];
6622         static char help[256];
6623         cmdline_parse_token_string_t *token_struct;
6624
6625         modes = list_pkt_forwarding_retry_modes();
6626         snprintf(help, sizeof(help), "set fwd %s retry: "
6627                 "Set packet forwarding mode with retry", modes);
6628         cmd_set_fwd_retry_mode.help_str = help;
6629
6630         /* string token separator is # */
6631         for (c = token; *modes != '\0'; modes++)
6632                 if (*modes == '|')
6633                         *c++ = '#';
6634                 else
6635                         *c++ = *modes;
6636         token_struct = (cmdline_parse_token_string_t *)
6637                 cmd_set_fwd_retry_mode.tokens[2];
6638         token_struct->string_data.str = token;
6639 }
6640
6641 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6642 struct cmd_set_burst_tx_retry_result {
6643         cmdline_fixed_string_t set;
6644         cmdline_fixed_string_t burst;
6645         cmdline_fixed_string_t tx;
6646         cmdline_fixed_string_t delay;
6647         uint32_t time;
6648         cmdline_fixed_string_t retry;
6649         uint32_t retry_num;
6650 };
6651
6652 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6653                                         __rte_unused struct cmdline *cl,
6654                                         __rte_unused void *data)
6655 {
6656         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6657
6658         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6659                 && !strcmp(res->tx, "tx")) {
6660                 if (!strcmp(res->delay, "delay"))
6661                         burst_tx_delay_time = res->time;
6662                 if (!strcmp(res->retry, "retry"))
6663                         burst_tx_retry_num = res->retry_num;
6664         }
6665
6666 }
6667
6668 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6670 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6671         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6672                                  "burst");
6673 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6675 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6677 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6678         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6679                                  RTE_UINT32);
6680 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6682 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6683         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6684                                  RTE_UINT32);
6685
6686 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6687         .f = cmd_set_burst_tx_retry_parsed,
6688         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6689         .tokens = {
6690                 (void *)&cmd_set_burst_tx_retry_set,
6691                 (void *)&cmd_set_burst_tx_retry_burst,
6692                 (void *)&cmd_set_burst_tx_retry_tx,
6693                 (void *)&cmd_set_burst_tx_retry_delay,
6694                 (void *)&cmd_set_burst_tx_retry_time,
6695                 (void *)&cmd_set_burst_tx_retry_retry,
6696                 (void *)&cmd_set_burst_tx_retry_retry_num,
6697                 NULL,
6698         },
6699 };
6700
6701 /* *** SET PROMISC MODE *** */
6702 struct cmd_set_promisc_mode_result {
6703         cmdline_fixed_string_t set;
6704         cmdline_fixed_string_t promisc;
6705         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6706         uint16_t port_num;               /* valid if "allports" argument == 0 */
6707         cmdline_fixed_string_t mode;
6708 };
6709
6710 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6711                                         __rte_unused struct cmdline *cl,
6712                                         void *allports)
6713 {
6714         struct cmd_set_promisc_mode_result *res = parsed_result;
6715         int enable;
6716         portid_t i;
6717
6718         if (!strcmp(res->mode, "on"))
6719                 enable = 1;
6720         else
6721                 enable = 0;
6722
6723         /* all ports */
6724         if (allports) {
6725                 RTE_ETH_FOREACH_DEV(i)
6726                         eth_set_promisc_mode(i, enable);
6727         } else {
6728                 eth_set_promisc_mode(res->port_num, enable);
6729         }
6730 }
6731
6732 cmdline_parse_token_string_t cmd_setpromisc_set =
6733         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6734 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6736                                  "promisc");
6737 cmdline_parse_token_string_t cmd_setpromisc_portall =
6738         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6739                                  "all");
6740 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6741         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6742                               RTE_UINT16);
6743 cmdline_parse_token_string_t cmd_setpromisc_mode =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6745                                  "on#off");
6746
6747 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6748         .f = cmd_set_promisc_mode_parsed,
6749         .data = (void *)1,
6750         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6751         .tokens = {
6752                 (void *)&cmd_setpromisc_set,
6753                 (void *)&cmd_setpromisc_promisc,
6754                 (void *)&cmd_setpromisc_portall,
6755                 (void *)&cmd_setpromisc_mode,
6756                 NULL,
6757         },
6758 };
6759
6760 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6761         .f = cmd_set_promisc_mode_parsed,
6762         .data = (void *)0,
6763         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6764         .tokens = {
6765                 (void *)&cmd_setpromisc_set,
6766                 (void *)&cmd_setpromisc_promisc,
6767                 (void *)&cmd_setpromisc_portnum,
6768                 (void *)&cmd_setpromisc_mode,
6769                 NULL,
6770         },
6771 };
6772
6773 /* *** SET ALLMULTI MODE *** */
6774 struct cmd_set_allmulti_mode_result {
6775         cmdline_fixed_string_t set;
6776         cmdline_fixed_string_t allmulti;
6777         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6778         uint16_t port_num;               /* valid if "allports" argument == 0 */
6779         cmdline_fixed_string_t mode;
6780 };
6781
6782 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6783                                         __rte_unused struct cmdline *cl,
6784                                         void *allports)
6785 {
6786         struct cmd_set_allmulti_mode_result *res = parsed_result;
6787         int enable;
6788         portid_t i;
6789
6790         if (!strcmp(res->mode, "on"))
6791                 enable = 1;
6792         else
6793                 enable = 0;
6794
6795         /* all ports */
6796         if (allports) {
6797                 RTE_ETH_FOREACH_DEV(i) {
6798                         eth_set_allmulticast_mode(i, enable);
6799                 }
6800         }
6801         else {
6802                 eth_set_allmulticast_mode(res->port_num, enable);
6803         }
6804 }
6805
6806 cmdline_parse_token_string_t cmd_setallmulti_set =
6807         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6808 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6810                                  "allmulti");
6811 cmdline_parse_token_string_t cmd_setallmulti_portall =
6812         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6813                                  "all");
6814 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6815         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6816                               RTE_UINT16);
6817 cmdline_parse_token_string_t cmd_setallmulti_mode =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6819                                  "on#off");
6820
6821 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6822         .f = cmd_set_allmulti_mode_parsed,
6823         .data = (void *)1,
6824         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6825         .tokens = {
6826                 (void *)&cmd_setallmulti_set,
6827                 (void *)&cmd_setallmulti_allmulti,
6828                 (void *)&cmd_setallmulti_portall,
6829                 (void *)&cmd_setallmulti_mode,
6830                 NULL,
6831         },
6832 };
6833
6834 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6835         .f = cmd_set_allmulti_mode_parsed,
6836         .data = (void *)0,
6837         .help_str = "set allmulti <port_id> on|off: "
6838                 "Set allmulti mode on port_id",
6839         .tokens = {
6840                 (void *)&cmd_setallmulti_set,
6841                 (void *)&cmd_setallmulti_allmulti,
6842                 (void *)&cmd_setallmulti_portnum,
6843                 (void *)&cmd_setallmulti_mode,
6844                 NULL,
6845         },
6846 };
6847
6848 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6849 struct cmd_link_flow_ctrl_set_result {
6850         cmdline_fixed_string_t set;
6851         cmdline_fixed_string_t flow_ctrl;
6852         cmdline_fixed_string_t rx;
6853         cmdline_fixed_string_t rx_lfc_mode;
6854         cmdline_fixed_string_t tx;
6855         cmdline_fixed_string_t tx_lfc_mode;
6856         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6857         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6858         cmdline_fixed_string_t autoneg_str;
6859         cmdline_fixed_string_t autoneg;
6860         cmdline_fixed_string_t hw_str;
6861         uint32_t high_water;
6862         cmdline_fixed_string_t lw_str;
6863         uint32_t low_water;
6864         cmdline_fixed_string_t pt_str;
6865         uint16_t pause_time;
6866         cmdline_fixed_string_t xon_str;
6867         uint16_t send_xon;
6868         portid_t port_id;
6869 };
6870
6871 cmdline_parse_token_string_t cmd_lfc_set_set =
6872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 set, "set");
6874 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 flow_ctrl, "flow_ctrl");
6877 cmdline_parse_token_string_t cmd_lfc_set_rx =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 rx, "rx");
6880 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 rx_lfc_mode, "on#off");
6883 cmdline_parse_token_string_t cmd_lfc_set_tx =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 tx, "tx");
6886 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 tx_lfc_mode, "on#off");
6889 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 hw_str, "high_water");
6892 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6893         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 high_water, RTE_UINT32);
6895 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 lw_str, "low_water");
6898 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6899         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 low_water, RTE_UINT32);
6901 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 pt_str, "pause_time");
6904 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6905         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 pause_time, RTE_UINT16);
6907 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 xon_str, "send_xon");
6910 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6911         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 send_xon, RTE_UINT16);
6913 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6916 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 mac_ctrl_frame_fwd_mode, "on#off");
6919 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 autoneg_str, "autoneg");
6922 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 autoneg, "on#off");
6925 cmdline_parse_token_num_t cmd_lfc_set_portid =
6926         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 port_id, RTE_UINT16);
6928
6929 /* forward declaration */
6930 static void
6931 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6932                               void *data);
6933
6934 cmdline_parse_inst_t cmd_link_flow_control_set = {
6935         .f = cmd_link_flow_ctrl_set_parsed,
6936         .data = NULL,
6937         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6938                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6939                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6940         .tokens = {
6941                 (void *)&cmd_lfc_set_set,
6942                 (void *)&cmd_lfc_set_flow_ctrl,
6943                 (void *)&cmd_lfc_set_rx,
6944                 (void *)&cmd_lfc_set_rx_mode,
6945                 (void *)&cmd_lfc_set_tx,
6946                 (void *)&cmd_lfc_set_tx_mode,
6947                 (void *)&cmd_lfc_set_high_water,
6948                 (void *)&cmd_lfc_set_low_water,
6949                 (void *)&cmd_lfc_set_pause_time,
6950                 (void *)&cmd_lfc_set_send_xon,
6951                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6952                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6953                 (void *)&cmd_lfc_set_autoneg_str,
6954                 (void *)&cmd_lfc_set_autoneg,
6955                 (void *)&cmd_lfc_set_portid,
6956                 NULL,
6957         },
6958 };
6959
6960 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6961         .f = cmd_link_flow_ctrl_set_parsed,
6962         .data = (void *)&cmd_link_flow_control_set_rx,
6963         .help_str = "set flow_ctrl rx on|off <port_id>: "
6964                 "Change rx flow control parameter",
6965         .tokens = {
6966                 (void *)&cmd_lfc_set_set,
6967                 (void *)&cmd_lfc_set_flow_ctrl,
6968                 (void *)&cmd_lfc_set_rx,
6969                 (void *)&cmd_lfc_set_rx_mode,
6970                 (void *)&cmd_lfc_set_portid,
6971                 NULL,
6972         },
6973 };
6974
6975 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6976         .f = cmd_link_flow_ctrl_set_parsed,
6977         .data = (void *)&cmd_link_flow_control_set_tx,
6978         .help_str = "set flow_ctrl tx on|off <port_id>: "
6979                 "Change tx flow control parameter",
6980         .tokens = {
6981                 (void *)&cmd_lfc_set_set,
6982                 (void *)&cmd_lfc_set_flow_ctrl,
6983                 (void *)&cmd_lfc_set_tx,
6984                 (void *)&cmd_lfc_set_tx_mode,
6985                 (void *)&cmd_lfc_set_portid,
6986                 NULL,
6987         },
6988 };
6989
6990 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6991         .f = cmd_link_flow_ctrl_set_parsed,
6992         .data = (void *)&cmd_link_flow_control_set_hw,
6993         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6994                 "Change high water flow control parameter",
6995         .tokens = {
6996                 (void *)&cmd_lfc_set_set,
6997                 (void *)&cmd_lfc_set_flow_ctrl,
6998                 (void *)&cmd_lfc_set_high_water_str,
6999                 (void *)&cmd_lfc_set_high_water,
7000                 (void *)&cmd_lfc_set_portid,
7001                 NULL,
7002         },
7003 };
7004
7005 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7006         .f = cmd_link_flow_ctrl_set_parsed,
7007         .data = (void *)&cmd_link_flow_control_set_lw,
7008         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7009                 "Change low water flow control parameter",
7010         .tokens = {
7011                 (void *)&cmd_lfc_set_set,
7012                 (void *)&cmd_lfc_set_flow_ctrl,
7013                 (void *)&cmd_lfc_set_low_water_str,
7014                 (void *)&cmd_lfc_set_low_water,
7015                 (void *)&cmd_lfc_set_portid,
7016                 NULL,
7017         },
7018 };
7019
7020 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7021         .f = cmd_link_flow_ctrl_set_parsed,
7022         .data = (void *)&cmd_link_flow_control_set_pt,
7023         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7024                 "Change pause time flow control parameter",
7025         .tokens = {
7026                 (void *)&cmd_lfc_set_set,
7027                 (void *)&cmd_lfc_set_flow_ctrl,
7028                 (void *)&cmd_lfc_set_pause_time_str,
7029                 (void *)&cmd_lfc_set_pause_time,
7030                 (void *)&cmd_lfc_set_portid,
7031                 NULL,
7032         },
7033 };
7034
7035 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7036         .f = cmd_link_flow_ctrl_set_parsed,
7037         .data = (void *)&cmd_link_flow_control_set_xon,
7038         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7039                 "Change send_xon flow control parameter",
7040         .tokens = {
7041                 (void *)&cmd_lfc_set_set,
7042                 (void *)&cmd_lfc_set_flow_ctrl,
7043                 (void *)&cmd_lfc_set_send_xon_str,
7044                 (void *)&cmd_lfc_set_send_xon,
7045                 (void *)&cmd_lfc_set_portid,
7046                 NULL,
7047         },
7048 };
7049
7050 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7051         .f = cmd_link_flow_ctrl_set_parsed,
7052         .data = (void *)&cmd_link_flow_control_set_macfwd,
7053         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7054                 "Change mac ctrl fwd flow control parameter",
7055         .tokens = {
7056                 (void *)&cmd_lfc_set_set,
7057                 (void *)&cmd_lfc_set_flow_ctrl,
7058                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7059                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7060                 (void *)&cmd_lfc_set_portid,
7061                 NULL,
7062         },
7063 };
7064
7065 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7066         .f = cmd_link_flow_ctrl_set_parsed,
7067         .data = (void *)&cmd_link_flow_control_set_autoneg,
7068         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7069                 "Change autoneg flow control parameter",
7070         .tokens = {
7071                 (void *)&cmd_lfc_set_set,
7072                 (void *)&cmd_lfc_set_flow_ctrl,
7073                 (void *)&cmd_lfc_set_autoneg_str,
7074                 (void *)&cmd_lfc_set_autoneg,
7075                 (void *)&cmd_lfc_set_portid,
7076                 NULL,
7077         },
7078 };
7079
7080 static void
7081 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7082                               __rte_unused struct cmdline *cl,
7083                               void *data)
7084 {
7085         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7086         cmdline_parse_inst_t *cmd = data;
7087         struct rte_eth_fc_conf fc_conf;
7088         int rx_fc_en = 0;
7089         int tx_fc_en = 0;
7090         int ret;
7091
7092         /*
7093          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7094          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7095          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7096          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7097          */
7098         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7099                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7100         };
7101
7102         /* Partial command line, retrieve current configuration */
7103         if (cmd) {
7104                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7105                 if (ret != 0) {
7106                         printf("cannot get current flow ctrl parameters, return"
7107                                "code = %d\n", ret);
7108                         return;
7109                 }
7110
7111                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7112                     (fc_conf.mode == RTE_FC_FULL))
7113                         rx_fc_en = 1;
7114                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7115                     (fc_conf.mode == RTE_FC_FULL))
7116                         tx_fc_en = 1;
7117         }
7118
7119         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7120                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7121
7122         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7123                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7124
7125         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7126
7127         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7128                 fc_conf.high_water = res->high_water;
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7131                 fc_conf.low_water = res->low_water;
7132
7133         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7134                 fc_conf.pause_time = res->pause_time;
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7137                 fc_conf.send_xon = res->send_xon;
7138
7139         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7140                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7141                         fc_conf.mac_ctrl_frame_fwd = 1;
7142                 else
7143                         fc_conf.mac_ctrl_frame_fwd = 0;
7144         }
7145
7146         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7147                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7148
7149         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7150         if (ret != 0)
7151                 printf("bad flow contrl parameter, return code = %d \n", ret);
7152 }
7153
7154 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7155 struct cmd_priority_flow_ctrl_set_result {
7156         cmdline_fixed_string_t set;
7157         cmdline_fixed_string_t pfc_ctrl;
7158         cmdline_fixed_string_t rx;
7159         cmdline_fixed_string_t rx_pfc_mode;
7160         cmdline_fixed_string_t tx;
7161         cmdline_fixed_string_t tx_pfc_mode;
7162         uint32_t high_water;
7163         uint32_t low_water;
7164         uint16_t pause_time;
7165         uint8_t  priority;
7166         portid_t port_id;
7167 };
7168
7169 static void
7170 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7171                        __rte_unused struct cmdline *cl,
7172                        __rte_unused void *data)
7173 {
7174         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7175         struct rte_eth_pfc_conf pfc_conf;
7176         int rx_fc_enable, tx_fc_enable;
7177         int ret;
7178
7179         /*
7180          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7181          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7182          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7183          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7184          */
7185         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7186                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7187         };
7188
7189         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7190         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7191         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7192         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7193         pfc_conf.fc.high_water = res->high_water;
7194         pfc_conf.fc.low_water  = res->low_water;
7195         pfc_conf.fc.pause_time = res->pause_time;
7196         pfc_conf.priority      = res->priority;
7197
7198         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7199         if (ret != 0)
7200                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7201 }
7202
7203 cmdline_parse_token_string_t cmd_pfc_set_set =
7204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205                                 set, "set");
7206 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 pfc_ctrl, "pfc_ctrl");
7209 cmdline_parse_token_string_t cmd_pfc_set_rx =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 rx, "rx");
7212 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 rx_pfc_mode, "on#off");
7215 cmdline_parse_token_string_t cmd_pfc_set_tx =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 tx, "tx");
7218 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 tx_pfc_mode, "on#off");
7221 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 high_water, RTE_UINT32);
7224 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 low_water, RTE_UINT32);
7227 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7228         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 pause_time, RTE_UINT16);
7230 cmdline_parse_token_num_t cmd_pfc_set_priority =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 priority, RTE_UINT8);
7233 cmdline_parse_token_num_t cmd_pfc_set_portid =
7234         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 port_id, RTE_UINT16);
7236
7237 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7238         .f = cmd_priority_flow_ctrl_set_parsed,
7239         .data = NULL,
7240         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7241                 "<pause_time> <priority> <port_id>: "
7242                 "Configure the Ethernet priority flow control",
7243         .tokens = {
7244                 (void *)&cmd_pfc_set_set,
7245                 (void *)&cmd_pfc_set_flow_ctrl,
7246                 (void *)&cmd_pfc_set_rx,
7247                 (void *)&cmd_pfc_set_rx_mode,
7248                 (void *)&cmd_pfc_set_tx,
7249                 (void *)&cmd_pfc_set_tx_mode,
7250                 (void *)&cmd_pfc_set_high_water,
7251                 (void *)&cmd_pfc_set_low_water,
7252                 (void *)&cmd_pfc_set_pause_time,
7253                 (void *)&cmd_pfc_set_priority,
7254                 (void *)&cmd_pfc_set_portid,
7255                 NULL,
7256         },
7257 };
7258
7259 /* *** RESET CONFIGURATION *** */
7260 struct cmd_reset_result {
7261         cmdline_fixed_string_t reset;
7262         cmdline_fixed_string_t def;
7263 };
7264
7265 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7266                              struct cmdline *cl,
7267                              __rte_unused void *data)
7268 {
7269         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7270         set_def_fwd_config();
7271 }
7272
7273 cmdline_parse_token_string_t cmd_reset_set =
7274         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7275 cmdline_parse_token_string_t cmd_reset_def =
7276         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7277                                  "default");
7278
7279 cmdline_parse_inst_t cmd_reset = {
7280         .f = cmd_reset_parsed,
7281         .data = NULL,
7282         .help_str = "set default: Reset default forwarding configuration",
7283         .tokens = {
7284                 (void *)&cmd_reset_set,
7285                 (void *)&cmd_reset_def,
7286                 NULL,
7287         },
7288 };
7289
7290 /* *** START FORWARDING *** */
7291 struct cmd_start_result {
7292         cmdline_fixed_string_t start;
7293 };
7294
7295 cmdline_parse_token_string_t cmd_start_start =
7296         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7297
7298 static void cmd_start_parsed(__rte_unused void *parsed_result,
7299                              __rte_unused struct cmdline *cl,
7300                              __rte_unused void *data)
7301 {
7302         start_packet_forwarding(0);
7303 }
7304
7305 cmdline_parse_inst_t cmd_start = {
7306         .f = cmd_start_parsed,
7307         .data = NULL,
7308         .help_str = "start: Start packet forwarding",
7309         .tokens = {
7310                 (void *)&cmd_start_start,
7311                 NULL,
7312         },
7313 };
7314
7315 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7316 struct cmd_start_tx_first_result {
7317         cmdline_fixed_string_t start;
7318         cmdline_fixed_string_t tx_first;
7319 };
7320
7321 static void
7322 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7323                           __rte_unused struct cmdline *cl,
7324                           __rte_unused void *data)
7325 {
7326         start_packet_forwarding(1);
7327 }
7328
7329 cmdline_parse_token_string_t cmd_start_tx_first_start =
7330         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7331                                  "start");
7332 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7333         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7334                                  tx_first, "tx_first");
7335
7336 cmdline_parse_inst_t cmd_start_tx_first = {
7337         .f = cmd_start_tx_first_parsed,
7338         .data = NULL,
7339         .help_str = "start tx_first: Start packet forwarding, "
7340                 "after sending 1 burst of packets",
7341         .tokens = {
7342                 (void *)&cmd_start_tx_first_start,
7343                 (void *)&cmd_start_tx_first_tx_first,
7344                 NULL,
7345         },
7346 };
7347
7348 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7349 struct cmd_start_tx_first_n_result {
7350         cmdline_fixed_string_t start;
7351         cmdline_fixed_string_t tx_first;
7352         uint32_t tx_num;
7353 };
7354
7355 static void
7356 cmd_start_tx_first_n_parsed(void *parsed_result,
7357                           __rte_unused struct cmdline *cl,
7358                           __rte_unused void *data)
7359 {
7360         struct cmd_start_tx_first_n_result *res = parsed_result;
7361
7362         start_packet_forwarding(res->tx_num);
7363 }
7364
7365 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7366         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7367                         start, "start");
7368 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7369         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7370                         tx_first, "tx_first");
7371 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7372         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7373                         tx_num, RTE_UINT32);
7374
7375 cmdline_parse_inst_t cmd_start_tx_first_n = {
7376         .f = cmd_start_tx_first_n_parsed,
7377         .data = NULL,
7378         .help_str = "start tx_first <num>: "
7379                 "packet forwarding, after sending <num> bursts of packets",
7380         .tokens = {
7381                 (void *)&cmd_start_tx_first_n_start,
7382                 (void *)&cmd_start_tx_first_n_tx_first,
7383                 (void *)&cmd_start_tx_first_n_tx_num,
7384                 NULL,
7385         },
7386 };
7387
7388 /* *** SET LINK UP *** */
7389 struct cmd_set_link_up_result {
7390         cmdline_fixed_string_t set;
7391         cmdline_fixed_string_t link_up;
7392         cmdline_fixed_string_t port;
7393         portid_t port_id;
7394 };
7395
7396 cmdline_parse_token_string_t cmd_set_link_up_set =
7397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7398 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7400                                 "link-up");
7401 cmdline_parse_token_string_t cmd_set_link_up_port =
7402         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7403 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7404         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7405                                 RTE_UINT16);
7406
7407 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7408                              __rte_unused struct cmdline *cl,
7409                              __rte_unused void *data)
7410 {
7411         struct cmd_set_link_up_result *res = parsed_result;
7412         dev_set_link_up(res->port_id);
7413 }
7414
7415 cmdline_parse_inst_t cmd_set_link_up = {
7416         .f = cmd_set_link_up_parsed,
7417         .data = NULL,
7418         .help_str = "set link-up port <port id>",
7419         .tokens = {
7420                 (void *)&cmd_set_link_up_set,
7421                 (void *)&cmd_set_link_up_link_up,
7422                 (void *)&cmd_set_link_up_port,
7423                 (void *)&cmd_set_link_up_port_id,
7424                 NULL,
7425         },
7426 };
7427
7428 /* *** SET LINK DOWN *** */
7429 struct cmd_set_link_down_result {
7430         cmdline_fixed_string_t set;
7431         cmdline_fixed_string_t link_down;
7432         cmdline_fixed_string_t port;
7433         portid_t port_id;
7434 };
7435
7436 cmdline_parse_token_string_t cmd_set_link_down_set =
7437         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7438 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7440                                 "link-down");
7441 cmdline_parse_token_string_t cmd_set_link_down_port =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7443 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7444         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7445                                 RTE_UINT16);
7446
7447 static void cmd_set_link_down_parsed(
7448                                 __rte_unused void *parsed_result,
7449                                 __rte_unused struct cmdline *cl,
7450                                 __rte_unused void *data)
7451 {
7452         struct cmd_set_link_down_result *res = parsed_result;
7453         dev_set_link_down(res->port_id);
7454 }
7455
7456 cmdline_parse_inst_t cmd_set_link_down = {
7457         .f = cmd_set_link_down_parsed,
7458         .data = NULL,
7459         .help_str = "set link-down port <port id>",
7460         .tokens = {
7461                 (void *)&cmd_set_link_down_set,
7462                 (void *)&cmd_set_link_down_link_down,
7463                 (void *)&cmd_set_link_down_port,
7464                 (void *)&cmd_set_link_down_port_id,
7465                 NULL,
7466         },
7467 };
7468
7469 /* *** SHOW CFG *** */
7470 struct cmd_showcfg_result {
7471         cmdline_fixed_string_t show;
7472         cmdline_fixed_string_t cfg;
7473         cmdline_fixed_string_t what;
7474 };
7475
7476 static void cmd_showcfg_parsed(void *parsed_result,
7477                                __rte_unused struct cmdline *cl,
7478                                __rte_unused void *data)
7479 {
7480         struct cmd_showcfg_result *res = parsed_result;
7481         if (!strcmp(res->what, "rxtx"))
7482                 rxtx_config_display();
7483         else if (!strcmp(res->what, "cores"))
7484                 fwd_lcores_config_display();
7485         else if (!strcmp(res->what, "fwd"))
7486                 pkt_fwd_config_display(&cur_fwd_config);
7487         else if (!strcmp(res->what, "rxoffs"))
7488                 show_rx_pkt_offsets();
7489         else if (!strcmp(res->what, "rxpkts"))
7490                 show_rx_pkt_segments();
7491         else if (!strcmp(res->what, "txpkts"))
7492                 show_tx_pkt_segments();
7493         else if (!strcmp(res->what, "txtimes"))
7494                 show_tx_pkt_times();
7495 }
7496
7497 cmdline_parse_token_string_t cmd_showcfg_show =
7498         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7499 cmdline_parse_token_string_t cmd_showcfg_port =
7500         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7501 cmdline_parse_token_string_t cmd_showcfg_what =
7502         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7503                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7504
7505 cmdline_parse_inst_t cmd_showcfg = {
7506         .f = cmd_showcfg_parsed,
7507         .data = NULL,
7508         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7509         .tokens = {
7510                 (void *)&cmd_showcfg_show,
7511                 (void *)&cmd_showcfg_port,
7512                 (void *)&cmd_showcfg_what,
7513                 NULL,
7514         },
7515 };
7516
7517 /* *** SHOW ALL PORT INFO *** */
7518 struct cmd_showportall_result {
7519         cmdline_fixed_string_t show;
7520         cmdline_fixed_string_t port;
7521         cmdline_fixed_string_t what;
7522         cmdline_fixed_string_t all;
7523 };
7524
7525 static void cmd_showportall_parsed(void *parsed_result,
7526                                 __rte_unused struct cmdline *cl,
7527                                 __rte_unused void *data)
7528 {
7529         portid_t i;
7530
7531         struct cmd_showportall_result *res = parsed_result;
7532         if (!strcmp(res->show, "clear")) {
7533                 if (!strcmp(res->what, "stats"))
7534                         RTE_ETH_FOREACH_DEV(i)
7535                                 nic_stats_clear(i);
7536                 else if (!strcmp(res->what, "xstats"))
7537                         RTE_ETH_FOREACH_DEV(i)
7538                                 nic_xstats_clear(i);
7539         } else if (!strcmp(res->what, "info"))
7540                 RTE_ETH_FOREACH_DEV(i)
7541                         port_infos_display(i);
7542         else if (!strcmp(res->what, "summary")) {
7543                 port_summary_header_display();
7544                 RTE_ETH_FOREACH_DEV(i)
7545                         port_summary_display(i);
7546         }
7547         else if (!strcmp(res->what, "stats"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_stats_display(i);
7550         else if (!strcmp(res->what, "xstats"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         nic_xstats_display(i);
7553 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7554         else if (!strcmp(res->what, "fdir"))
7555                 RTE_ETH_FOREACH_DEV(i)
7556                         fdir_get_infos(i);
7557 #endif
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#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|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, "dcb_tc"))
7623                 port_dcb_info_display(res->portnum);
7624         else if (!strcmp(res->what, "cap"))
7625                 port_offload_cap_display(res->portnum);
7626 }
7627
7628 cmdline_parse_token_string_t cmd_showport_show =
7629         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7630                                  "show#clear");
7631 cmdline_parse_token_string_t cmd_showport_port =
7632         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7633 cmdline_parse_token_string_t cmd_showport_what =
7634         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7635                                  "info#summary#stats#xstats#fdir#dcb_tc#cap");
7636 cmdline_parse_token_num_t cmd_showport_portnum =
7637         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7638
7639 cmdline_parse_inst_t cmd_showport = {
7640         .f = cmd_showport_parsed,
7641         .data = NULL,
7642         .help_str = "show|clear port "
7643                 "info|summary|stats|xstats|fdir|dcb_tc|cap "
7644                 "<port_id>",
7645         .tokens = {
7646                 (void *)&cmd_showport_show,
7647                 (void *)&cmd_showport_port,
7648                 (void *)&cmd_showport_what,
7649                 (void *)&cmd_showport_portnum,
7650                 NULL,
7651         },
7652 };
7653
7654 /* *** SHOW DEVICE INFO *** */
7655 struct cmd_showdevice_result {
7656         cmdline_fixed_string_t show;
7657         cmdline_fixed_string_t device;
7658         cmdline_fixed_string_t what;
7659         cmdline_fixed_string_t identifier;
7660 };
7661
7662 static void cmd_showdevice_parsed(void *parsed_result,
7663                                 __rte_unused struct cmdline *cl,
7664                                 __rte_unused void *data)
7665 {
7666         struct cmd_showdevice_result *res = parsed_result;
7667         if (!strcmp(res->what, "info")) {
7668                 if (!strcmp(res->identifier, "all"))
7669                         device_infos_display(NULL);
7670                 else
7671                         device_infos_display(res->identifier);
7672         }
7673 }
7674
7675 cmdline_parse_token_string_t cmd_showdevice_show =
7676         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7677                                  "show");
7678 cmdline_parse_token_string_t cmd_showdevice_device =
7679         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7680 cmdline_parse_token_string_t cmd_showdevice_what =
7681         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7682                                  "info");
7683 cmdline_parse_token_string_t cmd_showdevice_identifier =
7684         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7685                         identifier, NULL);
7686
7687 cmdline_parse_inst_t cmd_showdevice = {
7688         .f = cmd_showdevice_parsed,
7689         .data = NULL,
7690         .help_str = "show device info <identifier>|all",
7691         .tokens = {
7692                 (void *)&cmd_showdevice_show,
7693                 (void *)&cmd_showdevice_device,
7694                 (void *)&cmd_showdevice_what,
7695                 (void *)&cmd_showdevice_identifier,
7696                 NULL,
7697         },
7698 };
7699
7700 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7701 struct cmd_showeeprom_result {
7702         cmdline_fixed_string_t show;
7703         cmdline_fixed_string_t port;
7704         uint16_t portnum;
7705         cmdline_fixed_string_t type;
7706 };
7707
7708 static void cmd_showeeprom_parsed(void *parsed_result,
7709                 __rte_unused struct cmdline *cl,
7710                 __rte_unused void *data)
7711 {
7712         struct cmd_showeeprom_result *res = parsed_result;
7713
7714         if (!strcmp(res->type, "eeprom"))
7715                 port_eeprom_display(res->portnum);
7716         else if (!strcmp(res->type, "module_eeprom"))
7717                 port_module_eeprom_display(res->portnum);
7718         else
7719                 printf("Unknown argument\n");
7720 }
7721
7722 cmdline_parse_token_string_t cmd_showeeprom_show =
7723         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7724 cmdline_parse_token_string_t cmd_showeeprom_port =
7725         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7726 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7727         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7728                         RTE_UINT16);
7729 cmdline_parse_token_string_t cmd_showeeprom_type =
7730         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7731
7732 cmdline_parse_inst_t cmd_showeeprom = {
7733         .f = cmd_showeeprom_parsed,
7734         .data = NULL,
7735         .help_str = "show port <port_id> module_eeprom|eeprom",
7736         .tokens = {
7737                 (void *)&cmd_showeeprom_show,
7738                 (void *)&cmd_showeeprom_port,
7739                 (void *)&cmd_showeeprom_portnum,
7740                 (void *)&cmd_showeeprom_type,
7741                 NULL,
7742         },
7743 };
7744
7745 /* *** SHOW QUEUE INFO *** */
7746 struct cmd_showqueue_result {
7747         cmdline_fixed_string_t show;
7748         cmdline_fixed_string_t type;
7749         cmdline_fixed_string_t what;
7750         uint16_t portnum;
7751         uint16_t queuenum;
7752 };
7753
7754 static void
7755 cmd_showqueue_parsed(void *parsed_result,
7756         __rte_unused struct cmdline *cl,
7757         __rte_unused void *data)
7758 {
7759         struct cmd_showqueue_result *res = parsed_result;
7760
7761         if (!strcmp(res->type, "rxq"))
7762                 rx_queue_infos_display(res->portnum, res->queuenum);
7763         else if (!strcmp(res->type, "txq"))
7764                 tx_queue_infos_display(res->portnum, res->queuenum);
7765 }
7766
7767 cmdline_parse_token_string_t cmd_showqueue_show =
7768         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7769 cmdline_parse_token_string_t cmd_showqueue_type =
7770         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7771 cmdline_parse_token_string_t cmd_showqueue_what =
7772         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7773 cmdline_parse_token_num_t cmd_showqueue_portnum =
7774         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7775                 RTE_UINT16);
7776 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7777         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7778                 RTE_UINT16);
7779
7780 cmdline_parse_inst_t cmd_showqueue = {
7781         .f = cmd_showqueue_parsed,
7782         .data = NULL,
7783         .help_str = "show rxq|txq info <port_id> <queue_id>",
7784         .tokens = {
7785                 (void *)&cmd_showqueue_show,
7786                 (void *)&cmd_showqueue_type,
7787                 (void *)&cmd_showqueue_what,
7788                 (void *)&cmd_showqueue_portnum,
7789                 (void *)&cmd_showqueue_queuenum,
7790                 NULL,
7791         },
7792 };
7793
7794 /* show/clear fwd engine statistics */
7795 struct fwd_result {
7796         cmdline_fixed_string_t action;
7797         cmdline_fixed_string_t fwd;
7798         cmdline_fixed_string_t stats;
7799         cmdline_fixed_string_t all;
7800 };
7801
7802 cmdline_parse_token_string_t cmd_fwd_action =
7803         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7804 cmdline_parse_token_string_t cmd_fwd_fwd =
7805         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7806 cmdline_parse_token_string_t cmd_fwd_stats =
7807         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7808 cmdline_parse_token_string_t cmd_fwd_all =
7809         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7810
7811 static void
7812 cmd_showfwdall_parsed(void *parsed_result,
7813                       __rte_unused struct cmdline *cl,
7814                       __rte_unused void *data)
7815 {
7816         struct fwd_result *res = parsed_result;
7817
7818         if (!strcmp(res->action, "show"))
7819                 fwd_stats_display();
7820         else
7821                 fwd_stats_reset();
7822 }
7823
7824 static cmdline_parse_inst_t cmd_showfwdall = {
7825         .f = cmd_showfwdall_parsed,
7826         .data = NULL,
7827         .help_str = "show|clear fwd stats all",
7828         .tokens = {
7829                 (void *)&cmd_fwd_action,
7830                 (void *)&cmd_fwd_fwd,
7831                 (void *)&cmd_fwd_stats,
7832                 (void *)&cmd_fwd_all,
7833                 NULL,
7834         },
7835 };
7836
7837 /* *** READ PORT REGISTER *** */
7838 struct cmd_read_reg_result {
7839         cmdline_fixed_string_t read;
7840         cmdline_fixed_string_t reg;
7841         portid_t port_id;
7842         uint32_t reg_off;
7843 };
7844
7845 static void
7846 cmd_read_reg_parsed(void *parsed_result,
7847                     __rte_unused struct cmdline *cl,
7848                     __rte_unused void *data)
7849 {
7850         struct cmd_read_reg_result *res = parsed_result;
7851         port_reg_display(res->port_id, res->reg_off);
7852 }
7853
7854 cmdline_parse_token_string_t cmd_read_reg_read =
7855         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7856 cmdline_parse_token_string_t cmd_read_reg_reg =
7857         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7858 cmdline_parse_token_num_t cmd_read_reg_port_id =
7859         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7860 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7861         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7862
7863 cmdline_parse_inst_t cmd_read_reg = {
7864         .f = cmd_read_reg_parsed,
7865         .data = NULL,
7866         .help_str = "read reg <port_id> <reg_off>",
7867         .tokens = {
7868                 (void *)&cmd_read_reg_read,
7869                 (void *)&cmd_read_reg_reg,
7870                 (void *)&cmd_read_reg_port_id,
7871                 (void *)&cmd_read_reg_reg_off,
7872                 NULL,
7873         },
7874 };
7875
7876 /* *** READ PORT REGISTER BIT FIELD *** */
7877 struct cmd_read_reg_bit_field_result {
7878         cmdline_fixed_string_t read;
7879         cmdline_fixed_string_t regfield;
7880         portid_t port_id;
7881         uint32_t reg_off;
7882         uint8_t bit1_pos;
7883         uint8_t bit2_pos;
7884 };
7885
7886 static void
7887 cmd_read_reg_bit_field_parsed(void *parsed_result,
7888                               __rte_unused struct cmdline *cl,
7889                               __rte_unused void *data)
7890 {
7891         struct cmd_read_reg_bit_field_result *res = parsed_result;
7892         port_reg_bit_field_display(res->port_id, res->reg_off,
7893                                    res->bit1_pos, res->bit2_pos);
7894 }
7895
7896 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7897         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7898                                  "read");
7899 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7900         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7901                                  regfield, "regfield");
7902 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7903         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7904                               RTE_UINT16);
7905 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7907                               RTE_UINT32);
7908 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7909         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7910                               RTE_UINT8);
7911 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7912         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7913                               RTE_UINT8);
7914
7915 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7916         .f = cmd_read_reg_bit_field_parsed,
7917         .data = NULL,
7918         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7919         "Read register bit field between bit_x and bit_y included",
7920         .tokens = {
7921                 (void *)&cmd_read_reg_bit_field_read,
7922                 (void *)&cmd_read_reg_bit_field_regfield,
7923                 (void *)&cmd_read_reg_bit_field_port_id,
7924                 (void *)&cmd_read_reg_bit_field_reg_off,
7925                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7926                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7927                 NULL,
7928         },
7929 };
7930
7931 /* *** READ PORT REGISTER BIT *** */
7932 struct cmd_read_reg_bit_result {
7933         cmdline_fixed_string_t read;
7934         cmdline_fixed_string_t regbit;
7935         portid_t port_id;
7936         uint32_t reg_off;
7937         uint8_t bit_pos;
7938 };
7939
7940 static void
7941 cmd_read_reg_bit_parsed(void *parsed_result,
7942                         __rte_unused struct cmdline *cl,
7943                         __rte_unused void *data)
7944 {
7945         struct cmd_read_reg_bit_result *res = parsed_result;
7946         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7947 }
7948
7949 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7950         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7951 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7952         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7953                                  regbit, "regbit");
7954 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7955         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7956                                  RTE_UINT16);
7957 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7958         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7959                                  RTE_UINT32);
7960 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7961         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7962                                  RTE_UINT8);
7963
7964 cmdline_parse_inst_t cmd_read_reg_bit = {
7965         .f = cmd_read_reg_bit_parsed,
7966         .data = NULL,
7967         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7968         .tokens = {
7969                 (void *)&cmd_read_reg_bit_read,
7970                 (void *)&cmd_read_reg_bit_regbit,
7971                 (void *)&cmd_read_reg_bit_port_id,
7972                 (void *)&cmd_read_reg_bit_reg_off,
7973                 (void *)&cmd_read_reg_bit_bit_pos,
7974                 NULL,
7975         },
7976 };
7977
7978 /* *** WRITE PORT REGISTER *** */
7979 struct cmd_write_reg_result {
7980         cmdline_fixed_string_t write;
7981         cmdline_fixed_string_t reg;
7982         portid_t port_id;
7983         uint32_t reg_off;
7984         uint32_t value;
7985 };
7986
7987 static void
7988 cmd_write_reg_parsed(void *parsed_result,
7989                      __rte_unused struct cmdline *cl,
7990                      __rte_unused void *data)
7991 {
7992         struct cmd_write_reg_result *res = parsed_result;
7993         port_reg_set(res->port_id, res->reg_off, res->value);
7994 }
7995
7996 cmdline_parse_token_string_t cmd_write_reg_write =
7997         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7998 cmdline_parse_token_string_t cmd_write_reg_reg =
7999         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8000 cmdline_parse_token_num_t cmd_write_reg_port_id =
8001         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8002 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8003         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8004 cmdline_parse_token_num_t cmd_write_reg_value =
8005         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8006
8007 cmdline_parse_inst_t cmd_write_reg = {
8008         .f = cmd_write_reg_parsed,
8009         .data = NULL,
8010         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8011         .tokens = {
8012                 (void *)&cmd_write_reg_write,
8013                 (void *)&cmd_write_reg_reg,
8014                 (void *)&cmd_write_reg_port_id,
8015                 (void *)&cmd_write_reg_reg_off,
8016                 (void *)&cmd_write_reg_value,
8017                 NULL,
8018         },
8019 };
8020
8021 /* *** WRITE PORT REGISTER BIT FIELD *** */
8022 struct cmd_write_reg_bit_field_result {
8023         cmdline_fixed_string_t write;
8024         cmdline_fixed_string_t regfield;
8025         portid_t port_id;
8026         uint32_t reg_off;
8027         uint8_t bit1_pos;
8028         uint8_t bit2_pos;
8029         uint32_t value;
8030 };
8031
8032 static void
8033 cmd_write_reg_bit_field_parsed(void *parsed_result,
8034                                __rte_unused struct cmdline *cl,
8035                                __rte_unused void *data)
8036 {
8037         struct cmd_write_reg_bit_field_result *res = parsed_result;
8038         port_reg_bit_field_set(res->port_id, res->reg_off,
8039                           res->bit1_pos, res->bit2_pos, res->value);
8040 }
8041
8042 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8043         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8044                                  "write");
8045 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8046         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8047                                  regfield, "regfield");
8048 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8049         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8050                               RTE_UINT16);
8051 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8052         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8053                               RTE_UINT32);
8054 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8056                               RTE_UINT8);
8057 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8059                               RTE_UINT8);
8060 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8062                               RTE_UINT32);
8063
8064 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8065         .f = cmd_write_reg_bit_field_parsed,
8066         .data = NULL,
8067         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8068                 "<reg_value>: "
8069                 "Set register bit field between bit_x and bit_y included",
8070         .tokens = {
8071                 (void *)&cmd_write_reg_bit_field_write,
8072                 (void *)&cmd_write_reg_bit_field_regfield,
8073                 (void *)&cmd_write_reg_bit_field_port_id,
8074                 (void *)&cmd_write_reg_bit_field_reg_off,
8075                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8076                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8077                 (void *)&cmd_write_reg_bit_field_value,
8078                 NULL,
8079         },
8080 };
8081
8082 /* *** WRITE PORT REGISTER BIT *** */
8083 struct cmd_write_reg_bit_result {
8084         cmdline_fixed_string_t write;
8085         cmdline_fixed_string_t regbit;
8086         portid_t port_id;
8087         uint32_t reg_off;
8088         uint8_t bit_pos;
8089         uint8_t value;
8090 };
8091
8092 static void
8093 cmd_write_reg_bit_parsed(void *parsed_result,
8094                          __rte_unused struct cmdline *cl,
8095                          __rte_unused void *data)
8096 {
8097         struct cmd_write_reg_bit_result *res = parsed_result;
8098         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8099 }
8100
8101 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8102         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8103                                  "write");
8104 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8105         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8106                                  regbit, "regbit");
8107 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8108         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8109                                  RTE_UINT16);
8110 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8111         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8112                                  RTE_UINT32);
8113 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8114         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8115                                  RTE_UINT8);
8116 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8117         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8118                                  RTE_UINT8);
8119
8120 cmdline_parse_inst_t cmd_write_reg_bit = {
8121         .f = cmd_write_reg_bit_parsed,
8122         .data = NULL,
8123         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8124                 "0 <= bit_x <= 31",
8125         .tokens = {
8126                 (void *)&cmd_write_reg_bit_write,
8127                 (void *)&cmd_write_reg_bit_regbit,
8128                 (void *)&cmd_write_reg_bit_port_id,
8129                 (void *)&cmd_write_reg_bit_reg_off,
8130                 (void *)&cmd_write_reg_bit_bit_pos,
8131                 (void *)&cmd_write_reg_bit_value,
8132                 NULL,
8133         },
8134 };
8135
8136 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8137 struct cmd_read_rxd_txd_result {
8138         cmdline_fixed_string_t read;
8139         cmdline_fixed_string_t rxd_txd;
8140         portid_t port_id;
8141         uint16_t queue_id;
8142         uint16_t desc_id;
8143 };
8144
8145 static void
8146 cmd_read_rxd_txd_parsed(void *parsed_result,
8147                         __rte_unused struct cmdline *cl,
8148                         __rte_unused void *data)
8149 {
8150         struct cmd_read_rxd_txd_result *res = parsed_result;
8151
8152         if (!strcmp(res->rxd_txd, "rxd"))
8153                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8154         else if (!strcmp(res->rxd_txd, "txd"))
8155                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8156 }
8157
8158 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8159         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8160 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8161         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8162                                  "rxd#txd");
8163 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8164         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8165                                  RTE_UINT16);
8166 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8167         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8168                                  RTE_UINT16);
8169 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8170         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8171                                  RTE_UINT16);
8172
8173 cmdline_parse_inst_t cmd_read_rxd_txd = {
8174         .f = cmd_read_rxd_txd_parsed,
8175         .data = NULL,
8176         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8177         .tokens = {
8178                 (void *)&cmd_read_rxd_txd_read,
8179                 (void *)&cmd_read_rxd_txd_rxd_txd,
8180                 (void *)&cmd_read_rxd_txd_port_id,
8181                 (void *)&cmd_read_rxd_txd_queue_id,
8182                 (void *)&cmd_read_rxd_txd_desc_id,
8183                 NULL,
8184         },
8185 };
8186
8187 /* *** QUIT *** */
8188 struct cmd_quit_result {
8189         cmdline_fixed_string_t quit;
8190 };
8191
8192 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8193                             struct cmdline *cl,
8194                             __rte_unused void *data)
8195 {
8196         cmdline_quit(cl);
8197 }
8198
8199 cmdline_parse_token_string_t cmd_quit_quit =
8200         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8201
8202 cmdline_parse_inst_t cmd_quit = {
8203         .f = cmd_quit_parsed,
8204         .data = NULL,
8205         .help_str = "quit: Exit application",
8206         .tokens = {
8207                 (void *)&cmd_quit_quit,
8208                 NULL,
8209         },
8210 };
8211
8212 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8213 struct cmd_mac_addr_result {
8214         cmdline_fixed_string_t mac_addr_cmd;
8215         cmdline_fixed_string_t what;
8216         uint16_t port_num;
8217         struct rte_ether_addr address;
8218 };
8219
8220 static void cmd_mac_addr_parsed(void *parsed_result,
8221                 __rte_unused struct cmdline *cl,
8222                 __rte_unused void *data)
8223 {
8224         struct cmd_mac_addr_result *res = parsed_result;
8225         int ret;
8226
8227         if (strcmp(res->what, "add") == 0)
8228                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8229         else if (strcmp(res->what, "set") == 0)
8230                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8231                                                        &res->address);
8232         else
8233                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8234
8235         /* check the return value and print it if is < 0 */
8236         if(ret < 0)
8237                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8238
8239 }
8240
8241 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8242         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8243                                 "mac_addr");
8244 cmdline_parse_token_string_t cmd_mac_addr_what =
8245         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8246                                 "add#remove#set");
8247 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8248                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8249                                         RTE_UINT16);
8250 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8251                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8252
8253 cmdline_parse_inst_t cmd_mac_addr = {
8254         .f = cmd_mac_addr_parsed,
8255         .data = (void *)0,
8256         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8257                         "Add/Remove/Set MAC address on port_id",
8258         .tokens = {
8259                 (void *)&cmd_mac_addr_cmd,
8260                 (void *)&cmd_mac_addr_what,
8261                 (void *)&cmd_mac_addr_portnum,
8262                 (void *)&cmd_mac_addr_addr,
8263                 NULL,
8264         },
8265 };
8266
8267 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8268 struct cmd_eth_peer_result {
8269         cmdline_fixed_string_t set;
8270         cmdline_fixed_string_t eth_peer;
8271         portid_t port_id;
8272         cmdline_fixed_string_t peer_addr;
8273 };
8274
8275 static void cmd_set_eth_peer_parsed(void *parsed_result,
8276                         __rte_unused struct cmdline *cl,
8277                         __rte_unused void *data)
8278 {
8279                 struct cmd_eth_peer_result *res = parsed_result;
8280
8281                 if (test_done == 0) {
8282                         printf("Please stop forwarding first\n");
8283                         return;
8284                 }
8285                 if (!strcmp(res->eth_peer, "eth-peer")) {
8286                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8287                         fwd_config_setup();
8288                 }
8289 }
8290 cmdline_parse_token_string_t cmd_eth_peer_set =
8291         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8292 cmdline_parse_token_string_t cmd_eth_peer =
8293         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8294 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8295         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8296                 RTE_UINT16);
8297 cmdline_parse_token_string_t cmd_eth_peer_addr =
8298         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8299
8300 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8301         .f = cmd_set_eth_peer_parsed,
8302         .data = NULL,
8303         .help_str = "set eth-peer <port_id> <peer_mac>",
8304         .tokens = {
8305                 (void *)&cmd_eth_peer_set,
8306                 (void *)&cmd_eth_peer,
8307                 (void *)&cmd_eth_peer_port_id,
8308                 (void *)&cmd_eth_peer_addr,
8309                 NULL,
8310         },
8311 };
8312
8313 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8314 struct cmd_set_qmap_result {
8315         cmdline_fixed_string_t set;
8316         cmdline_fixed_string_t qmap;
8317         cmdline_fixed_string_t what;
8318         portid_t port_id;
8319         uint16_t queue_id;
8320         uint8_t map_value;
8321 };
8322
8323 static void
8324 cmd_set_qmap_parsed(void *parsed_result,
8325                        __rte_unused struct cmdline *cl,
8326                        __rte_unused void *data)
8327 {
8328         struct cmd_set_qmap_result *res = parsed_result;
8329         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8330
8331         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8332 }
8333
8334 cmdline_parse_token_string_t cmd_setqmap_set =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8336                                  set, "set");
8337 cmdline_parse_token_string_t cmd_setqmap_qmap =
8338         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8339                                  qmap, "stat_qmap");
8340 cmdline_parse_token_string_t cmd_setqmap_what =
8341         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8342                                  what, "tx#rx");
8343 cmdline_parse_token_num_t cmd_setqmap_portid =
8344         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8345                               port_id, RTE_UINT16);
8346 cmdline_parse_token_num_t cmd_setqmap_queueid =
8347         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8348                               queue_id, RTE_UINT16);
8349 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8350         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8351                               map_value, RTE_UINT8);
8352
8353 cmdline_parse_inst_t cmd_set_qmap = {
8354         .f = cmd_set_qmap_parsed,
8355         .data = NULL,
8356         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8357                 "Set statistics mapping value on tx|rx queue_id of port_id",
8358         .tokens = {
8359                 (void *)&cmd_setqmap_set,
8360                 (void *)&cmd_setqmap_qmap,
8361                 (void *)&cmd_setqmap_what,
8362                 (void *)&cmd_setqmap_portid,
8363                 (void *)&cmd_setqmap_queueid,
8364                 (void *)&cmd_setqmap_mapvalue,
8365                 NULL,
8366         },
8367 };
8368
8369 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8370 struct cmd_set_xstats_hide_zero_result {
8371         cmdline_fixed_string_t keyword;
8372         cmdline_fixed_string_t name;
8373         cmdline_fixed_string_t on_off;
8374 };
8375
8376 static void
8377 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8378                         __rte_unused struct cmdline *cl,
8379                         __rte_unused void *data)
8380 {
8381         struct cmd_set_xstats_hide_zero_result *res;
8382         uint16_t on_off = 0;
8383
8384         res = parsed_result;
8385         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8386         set_xstats_hide_zero(on_off);
8387 }
8388
8389 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8390         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8391                                  keyword, "set");
8392 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8393         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8394                                  name, "xstats-hide-zero");
8395 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8396         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8397                                  on_off, "on#off");
8398
8399 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8400         .f = cmd_set_xstats_hide_zero_parsed,
8401         .data = NULL,
8402         .help_str = "set xstats-hide-zero on|off",
8403         .tokens = {
8404                 (void *)&cmd_set_xstats_hide_zero_keyword,
8405                 (void *)&cmd_set_xstats_hide_zero_name,
8406                 (void *)&cmd_set_xstats_hide_zero_on_off,
8407                 NULL,
8408         },
8409 };
8410
8411 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8412 struct cmd_set_record_core_cycles_result {
8413         cmdline_fixed_string_t keyword;
8414         cmdline_fixed_string_t name;
8415         cmdline_fixed_string_t on_off;
8416 };
8417
8418 static void
8419 cmd_set_record_core_cycles_parsed(void *parsed_result,
8420                         __rte_unused struct cmdline *cl,
8421                         __rte_unused void *data)
8422 {
8423         struct cmd_set_record_core_cycles_result *res;
8424         uint16_t on_off = 0;
8425
8426         res = parsed_result;
8427         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8428         set_record_core_cycles(on_off);
8429 }
8430
8431 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8432         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8433                                  keyword, "set");
8434 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8435         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8436                                  name, "record-core-cycles");
8437 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8438         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8439                                  on_off, "on#off");
8440
8441 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8442         .f = cmd_set_record_core_cycles_parsed,
8443         .data = NULL,
8444         .help_str = "set record-core-cycles on|off",
8445         .tokens = {
8446                 (void *)&cmd_set_record_core_cycles_keyword,
8447                 (void *)&cmd_set_record_core_cycles_name,
8448                 (void *)&cmd_set_record_core_cycles_on_off,
8449                 NULL,
8450         },
8451 };
8452
8453 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8454 struct cmd_set_record_burst_stats_result {
8455         cmdline_fixed_string_t keyword;
8456         cmdline_fixed_string_t name;
8457         cmdline_fixed_string_t on_off;
8458 };
8459
8460 static void
8461 cmd_set_record_burst_stats_parsed(void *parsed_result,
8462                         __rte_unused struct cmdline *cl,
8463                         __rte_unused void *data)
8464 {
8465         struct cmd_set_record_burst_stats_result *res;
8466         uint16_t on_off = 0;
8467
8468         res = parsed_result;
8469         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8470         set_record_burst_stats(on_off);
8471 }
8472
8473 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8474         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8475                                  keyword, "set");
8476 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8477         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8478                                  name, "record-burst-stats");
8479 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8480         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8481                                  on_off, "on#off");
8482
8483 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8484         .f = cmd_set_record_burst_stats_parsed,
8485         .data = NULL,
8486         .help_str = "set record-burst-stats on|off",
8487         .tokens = {
8488                 (void *)&cmd_set_record_burst_stats_keyword,
8489                 (void *)&cmd_set_record_burst_stats_name,
8490                 (void *)&cmd_set_record_burst_stats_on_off,
8491                 NULL,
8492         },
8493 };
8494
8495 /* *** CONFIGURE UNICAST HASH TABLE *** */
8496 struct cmd_set_uc_hash_table {
8497         cmdline_fixed_string_t set;
8498         cmdline_fixed_string_t port;
8499         portid_t port_id;
8500         cmdline_fixed_string_t what;
8501         struct rte_ether_addr address;
8502         cmdline_fixed_string_t mode;
8503 };
8504
8505 static void
8506 cmd_set_uc_hash_parsed(void *parsed_result,
8507                        __rte_unused struct cmdline *cl,
8508                        __rte_unused void *data)
8509 {
8510         int ret=0;
8511         struct cmd_set_uc_hash_table *res = parsed_result;
8512
8513         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8514
8515         if (strcmp(res->what, "uta") == 0)
8516                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8517                                                 &res->address,(uint8_t)is_on);
8518         if (ret < 0)
8519                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8520
8521 }
8522
8523 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8524         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8525                                  set, "set");
8526 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8527         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8528                                  port, "port");
8529 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8530         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8531                               port_id, RTE_UINT16);
8532 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8534                                  what, "uta");
8535 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8536         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8537                                 address);
8538 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8539         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8540                                  mode, "on#off");
8541
8542 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8543         .f = cmd_set_uc_hash_parsed,
8544         .data = NULL,
8545         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8546         .tokens = {
8547                 (void *)&cmd_set_uc_hash_set,
8548                 (void *)&cmd_set_uc_hash_port,
8549                 (void *)&cmd_set_uc_hash_portid,
8550                 (void *)&cmd_set_uc_hash_what,
8551                 (void *)&cmd_set_uc_hash_mac,
8552                 (void *)&cmd_set_uc_hash_mode,
8553                 NULL,
8554         },
8555 };
8556
8557 struct cmd_set_uc_all_hash_table {
8558         cmdline_fixed_string_t set;
8559         cmdline_fixed_string_t port;
8560         portid_t port_id;
8561         cmdline_fixed_string_t what;
8562         cmdline_fixed_string_t value;
8563         cmdline_fixed_string_t mode;
8564 };
8565
8566 static void
8567 cmd_set_uc_all_hash_parsed(void *parsed_result,
8568                        __rte_unused struct cmdline *cl,
8569                        __rte_unused void *data)
8570 {
8571         int ret=0;
8572         struct cmd_set_uc_all_hash_table *res = parsed_result;
8573
8574         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8575
8576         if ((strcmp(res->what, "uta") == 0) &&
8577                 (strcmp(res->value, "all") == 0))
8578                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8579         if (ret < 0)
8580                 printf("bad unicast hash table parameter,"
8581                         "return code = %d \n", ret);
8582 }
8583
8584 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8585         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8586                                  set, "set");
8587 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8588         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8589                                  port, "port");
8590 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8591         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8592                               port_id, RTE_UINT16);
8593 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8594         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8595                                  what, "uta");
8596 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8597         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8598                                 value,"all");
8599 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8600         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8601                                  mode, "on#off");
8602
8603 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8604         .f = cmd_set_uc_all_hash_parsed,
8605         .data = NULL,
8606         .help_str = "set port <port_id> uta all on|off",
8607         .tokens = {
8608                 (void *)&cmd_set_uc_all_hash_set,
8609                 (void *)&cmd_set_uc_all_hash_port,
8610                 (void *)&cmd_set_uc_all_hash_portid,
8611                 (void *)&cmd_set_uc_all_hash_what,
8612                 (void *)&cmd_set_uc_all_hash_value,
8613                 (void *)&cmd_set_uc_all_hash_mode,
8614                 NULL,
8615         },
8616 };
8617
8618 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8619 struct cmd_set_vf_traffic {
8620         cmdline_fixed_string_t set;
8621         cmdline_fixed_string_t port;
8622         portid_t port_id;
8623         cmdline_fixed_string_t vf;
8624         uint8_t vf_id;
8625         cmdline_fixed_string_t what;
8626         cmdline_fixed_string_t mode;
8627 };
8628
8629 static void
8630 cmd_set_vf_traffic_parsed(void *parsed_result,
8631                        __rte_unused struct cmdline *cl,
8632                        __rte_unused void *data)
8633 {
8634         struct cmd_set_vf_traffic *res = parsed_result;
8635         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8636         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8637
8638         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8639 }
8640
8641 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8642         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8643                                  set, "set");
8644 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8645         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8646                                  port, "port");
8647 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8648         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8649                               port_id, RTE_UINT16);
8650 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8651         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8652                                  vf, "vf");
8653 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8654         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8655                               vf_id, RTE_UINT8);
8656 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8657         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8658                                  what, "tx#rx");
8659 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8661                                  mode, "on#off");
8662
8663 cmdline_parse_inst_t cmd_set_vf_traffic = {
8664         .f = cmd_set_vf_traffic_parsed,
8665         .data = NULL,
8666         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8667         .tokens = {
8668                 (void *)&cmd_setvf_traffic_set,
8669                 (void *)&cmd_setvf_traffic_port,
8670                 (void *)&cmd_setvf_traffic_portid,
8671                 (void *)&cmd_setvf_traffic_vf,
8672                 (void *)&cmd_setvf_traffic_vfid,
8673                 (void *)&cmd_setvf_traffic_what,
8674                 (void *)&cmd_setvf_traffic_mode,
8675                 NULL,
8676         },
8677 };
8678
8679 /* *** CONFIGURE VF RECEIVE MODE *** */
8680 struct cmd_set_vf_rxmode {
8681         cmdline_fixed_string_t set;
8682         cmdline_fixed_string_t port;
8683         portid_t port_id;
8684         cmdline_fixed_string_t vf;
8685         uint8_t vf_id;
8686         cmdline_fixed_string_t what;
8687         cmdline_fixed_string_t mode;
8688         cmdline_fixed_string_t on;
8689 };
8690
8691 static void
8692 cmd_set_vf_rxmode_parsed(void *parsed_result,
8693                        __rte_unused struct cmdline *cl,
8694                        __rte_unused void *data)
8695 {
8696         int ret = -ENOTSUP;
8697         uint16_t vf_rxmode = 0;
8698         struct cmd_set_vf_rxmode *res = parsed_result;
8699
8700         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8701         if (!strcmp(res->what,"rxmode")) {
8702                 if (!strcmp(res->mode, "AUPE"))
8703                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8704                 else if (!strcmp(res->mode, "ROPE"))
8705                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8706                 else if (!strcmp(res->mode, "BAM"))
8707                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8708                 else if (!strncmp(res->mode, "MPE",3))
8709                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8710         }
8711
8712         RTE_SET_USED(is_on);
8713
8714 #ifdef RTE_NET_IXGBE
8715         if (ret == -ENOTSUP)
8716                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8717                                                   vf_rxmode, (uint8_t)is_on);
8718 #endif
8719 #ifdef RTE_NET_BNXT
8720         if (ret == -ENOTSUP)
8721                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8722                                                  vf_rxmode, (uint8_t)is_on);
8723 #endif
8724         if (ret < 0)
8725                 printf("bad VF receive mode parameter, return code = %d \n",
8726                 ret);
8727 }
8728
8729 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8730         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8731                                  set, "set");
8732 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8733         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8734                                  port, "port");
8735 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8736         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8737                               port_id, RTE_UINT16);
8738 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8739         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8740                                  vf, "vf");
8741 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8742         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8743                               vf_id, RTE_UINT8);
8744 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8745         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8746                                  what, "rxmode");
8747 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8748         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8749                                  mode, "AUPE#ROPE#BAM#MPE");
8750 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8751         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8752                                  on, "on#off");
8753
8754 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8755         .f = cmd_set_vf_rxmode_parsed,
8756         .data = NULL,
8757         .help_str = "set port <port_id> vf <vf_id> rxmode "
8758                 "AUPE|ROPE|BAM|MPE on|off",
8759         .tokens = {
8760                 (void *)&cmd_set_vf_rxmode_set,
8761                 (void *)&cmd_set_vf_rxmode_port,
8762                 (void *)&cmd_set_vf_rxmode_portid,
8763                 (void *)&cmd_set_vf_rxmode_vf,
8764                 (void *)&cmd_set_vf_rxmode_vfid,
8765                 (void *)&cmd_set_vf_rxmode_what,
8766                 (void *)&cmd_set_vf_rxmode_mode,
8767                 (void *)&cmd_set_vf_rxmode_on,
8768                 NULL,
8769         },
8770 };
8771
8772 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8773 struct cmd_vf_mac_addr_result {
8774         cmdline_fixed_string_t mac_addr_cmd;
8775         cmdline_fixed_string_t what;
8776         cmdline_fixed_string_t port;
8777         uint16_t port_num;
8778         cmdline_fixed_string_t vf;
8779         uint8_t vf_num;
8780         struct rte_ether_addr address;
8781 };
8782
8783 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8784                 __rte_unused struct cmdline *cl,
8785                 __rte_unused void *data)
8786 {
8787         struct cmd_vf_mac_addr_result *res = parsed_result;
8788         int ret = -ENOTSUP;
8789
8790         if (strcmp(res->what, "add") != 0)
8791                 return;
8792
8793 #ifdef RTE_NET_I40E
8794         if (ret == -ENOTSUP)
8795                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8796                                                    &res->address);
8797 #endif
8798 #ifdef RTE_NET_BNXT
8799         if (ret == -ENOTSUP)
8800                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8801                                                 res->vf_num);
8802 #endif
8803
8804         if(ret < 0)
8805                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8806
8807 }
8808
8809 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8810         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8811                                 mac_addr_cmd,"mac_addr");
8812 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8813         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8814                                 what,"add");
8815 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8816         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8817                                 port,"port");
8818 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8819         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8820                                 port_num, RTE_UINT16);
8821 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8822         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8823                                 vf,"vf");
8824 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8825         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8826                                 vf_num, RTE_UINT8);
8827 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8828         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8829                                 address);
8830
8831 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8832         .f = cmd_vf_mac_addr_parsed,
8833         .data = (void *)0,
8834         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8835                 "Add MAC address filtering for a VF on port_id",
8836         .tokens = {
8837                 (void *)&cmd_vf_mac_addr_cmd,
8838                 (void *)&cmd_vf_mac_addr_what,
8839                 (void *)&cmd_vf_mac_addr_port,
8840                 (void *)&cmd_vf_mac_addr_portnum,
8841                 (void *)&cmd_vf_mac_addr_vf,
8842                 (void *)&cmd_vf_mac_addr_vfnum,
8843                 (void *)&cmd_vf_mac_addr_addr,
8844                 NULL,
8845         },
8846 };
8847
8848 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8849 struct cmd_vf_rx_vlan_filter {
8850         cmdline_fixed_string_t rx_vlan;
8851         cmdline_fixed_string_t what;
8852         uint16_t vlan_id;
8853         cmdline_fixed_string_t port;
8854         portid_t port_id;
8855         cmdline_fixed_string_t vf;
8856         uint64_t vf_mask;
8857 };
8858
8859 static void
8860 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8861                           __rte_unused struct cmdline *cl,
8862                           __rte_unused void *data)
8863 {
8864         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8865         int ret = -ENOTSUP;
8866
8867         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8868
8869 #ifdef RTE_NET_IXGBE
8870         if (ret == -ENOTSUP)
8871                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8872                                 res->vlan_id, res->vf_mask, is_add);
8873 #endif
8874 #ifdef RTE_NET_I40E
8875         if (ret == -ENOTSUP)
8876                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8877                                 res->vlan_id, res->vf_mask, is_add);
8878 #endif
8879 #ifdef RTE_NET_BNXT
8880         if (ret == -ENOTSUP)
8881                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8882                                 res->vlan_id, res->vf_mask, is_add);
8883 #endif
8884
8885         switch (ret) {
8886         case 0:
8887                 break;
8888         case -EINVAL:
8889                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8890                                 res->vlan_id, res->vf_mask);
8891                 break;
8892         case -ENODEV:
8893                 printf("invalid port_id %d\n", res->port_id);
8894                 break;
8895         case -ENOTSUP:
8896                 printf("function not implemented or supported\n");
8897                 break;
8898         default:
8899                 printf("programming error: (%s)\n", strerror(-ret));
8900         }
8901 }
8902
8903 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8904         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8905                                  rx_vlan, "rx_vlan");
8906 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8907         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8908                                  what, "add#rm");
8909 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8910         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8911                               vlan_id, RTE_UINT16);
8912 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8913         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8914                                  port, "port");
8915 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8916         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8917                               port_id, RTE_UINT16);
8918 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8919         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8920                                  vf, "vf");
8921 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8922         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8923                               vf_mask, RTE_UINT64);
8924
8925 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8926         .f = cmd_vf_rx_vlan_filter_parsed,
8927         .data = NULL,
8928         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8929                 "(vf_mask = hexadecimal VF mask)",
8930         .tokens = {
8931                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8932                 (void *)&cmd_vf_rx_vlan_filter_what,
8933                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8934                 (void *)&cmd_vf_rx_vlan_filter_port,
8935                 (void *)&cmd_vf_rx_vlan_filter_portid,
8936                 (void *)&cmd_vf_rx_vlan_filter_vf,
8937                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8938                 NULL,
8939         },
8940 };
8941
8942 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8943 struct cmd_queue_rate_limit_result {
8944         cmdline_fixed_string_t set;
8945         cmdline_fixed_string_t port;
8946         uint16_t port_num;
8947         cmdline_fixed_string_t queue;
8948         uint8_t queue_num;
8949         cmdline_fixed_string_t rate;
8950         uint16_t rate_num;
8951 };
8952
8953 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8954                 __rte_unused struct cmdline *cl,
8955                 __rte_unused void *data)
8956 {
8957         struct cmd_queue_rate_limit_result *res = parsed_result;
8958         int ret = 0;
8959
8960         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8961                 && (strcmp(res->queue, "queue") == 0)
8962                 && (strcmp(res->rate, "rate") == 0))
8963                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8964                                         res->rate_num);
8965         if (ret < 0)
8966                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8967
8968 }
8969
8970 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8971         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8972                                 set, "set");
8973 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8974         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8975                                 port, "port");
8976 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8977         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8978                                 port_num, RTE_UINT16);
8979 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8980         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8981                                 queue, "queue");
8982 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8983         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8984                                 queue_num, RTE_UINT8);
8985 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8986         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8987                                 rate, "rate");
8988 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8989         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8990                                 rate_num, RTE_UINT16);
8991
8992 cmdline_parse_inst_t cmd_queue_rate_limit = {
8993         .f = cmd_queue_rate_limit_parsed,
8994         .data = (void *)0,
8995         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8996                 "Set rate limit for a queue on port_id",
8997         .tokens = {
8998                 (void *)&cmd_queue_rate_limit_set,
8999                 (void *)&cmd_queue_rate_limit_port,
9000                 (void *)&cmd_queue_rate_limit_portnum,
9001                 (void *)&cmd_queue_rate_limit_queue,
9002                 (void *)&cmd_queue_rate_limit_queuenum,
9003                 (void *)&cmd_queue_rate_limit_rate,
9004                 (void *)&cmd_queue_rate_limit_ratenum,
9005                 NULL,
9006         },
9007 };
9008
9009 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9010 struct cmd_vf_rate_limit_result {
9011         cmdline_fixed_string_t set;
9012         cmdline_fixed_string_t port;
9013         uint16_t port_num;
9014         cmdline_fixed_string_t vf;
9015         uint8_t vf_num;
9016         cmdline_fixed_string_t rate;
9017         uint16_t rate_num;
9018         cmdline_fixed_string_t q_msk;
9019         uint64_t q_msk_val;
9020 };
9021
9022 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9023                 __rte_unused struct cmdline *cl,
9024                 __rte_unused void *data)
9025 {
9026         struct cmd_vf_rate_limit_result *res = parsed_result;
9027         int ret = 0;
9028
9029         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9030                 && (strcmp(res->vf, "vf") == 0)
9031                 && (strcmp(res->rate, "rate") == 0)
9032                 && (strcmp(res->q_msk, "queue_mask") == 0))
9033                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9034                                         res->rate_num, res->q_msk_val);
9035         if (ret < 0)
9036                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9037
9038 }
9039
9040 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9041         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9042                                 set, "set");
9043 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9044         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9045                                 port, "port");
9046 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9047         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9048                                 port_num, RTE_UINT16);
9049 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9050         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9051                                 vf, "vf");
9052 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9053         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9054                                 vf_num, RTE_UINT8);
9055 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9056         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9057                                 rate, "rate");
9058 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9059         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9060                                 rate_num, RTE_UINT16);
9061 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9062         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9063                                 q_msk, "queue_mask");
9064 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9065         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9066                                 q_msk_val, RTE_UINT64);
9067
9068 cmdline_parse_inst_t cmd_vf_rate_limit = {
9069         .f = cmd_vf_rate_limit_parsed,
9070         .data = (void *)0,
9071         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9072                 "queue_mask <queue_mask_value>: "
9073                 "Set rate limit for queues of VF on port_id",
9074         .tokens = {
9075                 (void *)&cmd_vf_rate_limit_set,
9076                 (void *)&cmd_vf_rate_limit_port,
9077                 (void *)&cmd_vf_rate_limit_portnum,
9078                 (void *)&cmd_vf_rate_limit_vf,
9079                 (void *)&cmd_vf_rate_limit_vfnum,
9080                 (void *)&cmd_vf_rate_limit_rate,
9081                 (void *)&cmd_vf_rate_limit_ratenum,
9082                 (void *)&cmd_vf_rate_limit_q_msk,
9083                 (void *)&cmd_vf_rate_limit_q_msk_val,
9084                 NULL,
9085         },
9086 };
9087
9088 /* *** CONFIGURE TUNNEL UDP PORT *** */
9089 struct cmd_tunnel_udp_config {
9090         cmdline_fixed_string_t cmd;
9091         cmdline_fixed_string_t what;
9092         uint16_t udp_port;
9093         portid_t port_id;
9094 };
9095
9096 static void
9097 cmd_tunnel_udp_config_parsed(void *parsed_result,
9098                           __rte_unused struct cmdline *cl,
9099                           __rte_unused void *data)
9100 {
9101         struct cmd_tunnel_udp_config *res = parsed_result;
9102         struct rte_eth_udp_tunnel tunnel_udp;
9103         int ret;
9104
9105         tunnel_udp.udp_port = res->udp_port;
9106
9107         if (!strcmp(res->cmd, "rx_vxlan_port"))
9108                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9109
9110         if (!strcmp(res->what, "add"))
9111                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9112                                                       &tunnel_udp);
9113         else
9114                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9115                                                          &tunnel_udp);
9116
9117         if (ret < 0)
9118                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9119 }
9120
9121 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9123                                 cmd, "rx_vxlan_port");
9124 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9125         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9126                                 what, "add#rm");
9127 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9128         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9129                                 udp_port, RTE_UINT16);
9130 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9131         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9132                                 port_id, RTE_UINT16);
9133
9134 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9135         .f = cmd_tunnel_udp_config_parsed,
9136         .data = (void *)0,
9137         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9138                 "Add/Remove a tunneling UDP port filter",
9139         .tokens = {
9140                 (void *)&cmd_tunnel_udp_config_cmd,
9141                 (void *)&cmd_tunnel_udp_config_what,
9142                 (void *)&cmd_tunnel_udp_config_udp_port,
9143                 (void *)&cmd_tunnel_udp_config_port_id,
9144                 NULL,
9145         },
9146 };
9147
9148 struct cmd_config_tunnel_udp_port {
9149         cmdline_fixed_string_t port;
9150         cmdline_fixed_string_t config;
9151         portid_t port_id;
9152         cmdline_fixed_string_t udp_tunnel_port;
9153         cmdline_fixed_string_t action;
9154         cmdline_fixed_string_t tunnel_type;
9155         uint16_t udp_port;
9156 };
9157
9158 static void
9159 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9160                                __rte_unused struct cmdline *cl,
9161                                __rte_unused void *data)
9162 {
9163         struct cmd_config_tunnel_udp_port *res = parsed_result;
9164         struct rte_eth_udp_tunnel tunnel_udp;
9165         int ret = 0;
9166
9167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9168                 return;
9169
9170         tunnel_udp.udp_port = res->udp_port;
9171
9172         if (!strcmp(res->tunnel_type, "vxlan")) {
9173                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9174         } else if (!strcmp(res->tunnel_type, "geneve")) {
9175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9176         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9177                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9178         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9179                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
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#ecpri");
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|"
9223                 "geneve|vxlan-gpe|ecpri <udp_port>",
9224         .tokens = {
9225                 (void *)&cmd_config_tunnel_udp_port_port,
9226                 (void *)&cmd_config_tunnel_udp_port_config,
9227                 (void *)&cmd_config_tunnel_udp_port_port_id,
9228                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9229                 (void *)&cmd_config_tunnel_udp_port_action,
9230                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9231                 (void *)&cmd_config_tunnel_udp_port_value,
9232                 NULL,
9233         },
9234 };
9235
9236 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9237 struct cmd_set_mirror_mask_result {
9238         cmdline_fixed_string_t set;
9239         cmdline_fixed_string_t port;
9240         portid_t port_id;
9241         cmdline_fixed_string_t mirror;
9242         uint8_t rule_id;
9243         cmdline_fixed_string_t what;
9244         cmdline_fixed_string_t value;
9245         cmdline_fixed_string_t dstpool;
9246         uint8_t dstpool_id;
9247         cmdline_fixed_string_t on;
9248 };
9249
9250 cmdline_parse_token_string_t cmd_mirror_mask_set =
9251         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9252                                 set, "set");
9253 cmdline_parse_token_string_t cmd_mirror_mask_port =
9254         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9255                                 port, "port");
9256 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9257         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9258                                 port_id, RTE_UINT16);
9259 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9260         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9261                                 mirror, "mirror-rule");
9262 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9263         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9264                                 rule_id, RTE_UINT8);
9265 cmdline_parse_token_string_t cmd_mirror_mask_what =
9266         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9267                                 what, "pool-mirror-up#pool-mirror-down"
9268                                       "#vlan-mirror");
9269 cmdline_parse_token_string_t cmd_mirror_mask_value =
9270         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9271                                 value, NULL);
9272 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9273         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9274                                 dstpool, "dst-pool");
9275 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9276         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9277                                 dstpool_id, RTE_UINT8);
9278 cmdline_parse_token_string_t cmd_mirror_mask_on =
9279         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9280                                 on, "on#off");
9281
9282 static void
9283 cmd_set_mirror_mask_parsed(void *parsed_result,
9284                        __rte_unused struct cmdline *cl,
9285                        __rte_unused void *data)
9286 {
9287         int ret,nb_item,i;
9288         struct cmd_set_mirror_mask_result *res = parsed_result;
9289         struct rte_eth_mirror_conf mr_conf;
9290
9291         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9292
9293         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9294
9295         mr_conf.dst_pool = res->dstpool_id;
9296
9297         if (!strcmp(res->what, "pool-mirror-up")) {
9298                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9299                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9300         } else if (!strcmp(res->what, "pool-mirror-down")) {
9301                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9302                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9303         } else if (!strcmp(res->what, "vlan-mirror")) {
9304                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9305                 nb_item = parse_item_list(res->value, "vlan",
9306                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9307                 if (nb_item <= 0)
9308                         return;
9309
9310                 for (i = 0; i < nb_item; i++) {
9311                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9312                                 printf("Invalid vlan_id: must be < 4096\n");
9313                                 return;
9314                         }
9315
9316                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9317                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9318                 }
9319         }
9320
9321         if (!strcmp(res->on, "on"))
9322                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9323                                                 res->rule_id, 1);
9324         else
9325                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9326                                                 res->rule_id, 0);
9327         if (ret < 0)
9328                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9329 }
9330
9331 cmdline_parse_inst_t cmd_set_mirror_mask = {
9332                 .f = cmd_set_mirror_mask_parsed,
9333                 .data = NULL,
9334                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9335                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9336                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9337                 .tokens = {
9338                         (void *)&cmd_mirror_mask_set,
9339                         (void *)&cmd_mirror_mask_port,
9340                         (void *)&cmd_mirror_mask_portid,
9341                         (void *)&cmd_mirror_mask_mirror,
9342                         (void *)&cmd_mirror_mask_ruleid,
9343                         (void *)&cmd_mirror_mask_what,
9344                         (void *)&cmd_mirror_mask_value,
9345                         (void *)&cmd_mirror_mask_dstpool,
9346                         (void *)&cmd_mirror_mask_poolid,
9347                         (void *)&cmd_mirror_mask_on,
9348                         NULL,
9349                 },
9350 };
9351
9352 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9353 struct cmd_set_mirror_link_result {
9354         cmdline_fixed_string_t set;
9355         cmdline_fixed_string_t port;
9356         portid_t port_id;
9357         cmdline_fixed_string_t mirror;
9358         uint8_t rule_id;
9359         cmdline_fixed_string_t what;
9360         cmdline_fixed_string_t dstpool;
9361         uint8_t dstpool_id;
9362         cmdline_fixed_string_t on;
9363 };
9364
9365 cmdline_parse_token_string_t cmd_mirror_link_set =
9366         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9367                                  set, "set");
9368 cmdline_parse_token_string_t cmd_mirror_link_port =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9370                                 port, "port");
9371 cmdline_parse_token_num_t cmd_mirror_link_portid =
9372         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9373                                 port_id, RTE_UINT16);
9374 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9375         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9376                                 mirror, "mirror-rule");
9377 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9378         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9379                             rule_id, RTE_UINT8);
9380 cmdline_parse_token_string_t cmd_mirror_link_what =
9381         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9382                                 what, "uplink-mirror#downlink-mirror");
9383 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9385                                 dstpool, "dst-pool");
9386 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9387         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9388                                 dstpool_id, RTE_UINT8);
9389 cmdline_parse_token_string_t cmd_mirror_link_on =
9390         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9391                                 on, "on#off");
9392
9393 static void
9394 cmd_set_mirror_link_parsed(void *parsed_result,
9395                        __rte_unused struct cmdline *cl,
9396                        __rte_unused void *data)
9397 {
9398         int ret;
9399         struct cmd_set_mirror_link_result *res = parsed_result;
9400         struct rte_eth_mirror_conf mr_conf;
9401
9402         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9403         if (!strcmp(res->what, "uplink-mirror"))
9404                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9405         else
9406                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9407
9408         mr_conf.dst_pool = res->dstpool_id;
9409
9410         if (!strcmp(res->on, "on"))
9411                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9412                                                 res->rule_id, 1);
9413         else
9414                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9415                                                 res->rule_id, 0);
9416
9417         /* check the return value and print it if is < 0 */
9418         if (ret < 0)
9419                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9420
9421 }
9422
9423 cmdline_parse_inst_t cmd_set_mirror_link = {
9424                 .f = cmd_set_mirror_link_parsed,
9425                 .data = NULL,
9426                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9427                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9428                 .tokens = {
9429                         (void *)&cmd_mirror_link_set,
9430                         (void *)&cmd_mirror_link_port,
9431                         (void *)&cmd_mirror_link_portid,
9432                         (void *)&cmd_mirror_link_mirror,
9433                         (void *)&cmd_mirror_link_ruleid,
9434                         (void *)&cmd_mirror_link_what,
9435                         (void *)&cmd_mirror_link_dstpool,
9436                         (void *)&cmd_mirror_link_poolid,
9437                         (void *)&cmd_mirror_link_on,
9438                         NULL,
9439                 },
9440 };
9441
9442 /* *** RESET VM MIRROR RULE *** */
9443 struct cmd_rm_mirror_rule_result {
9444         cmdline_fixed_string_t reset;
9445         cmdline_fixed_string_t port;
9446         portid_t port_id;
9447         cmdline_fixed_string_t mirror;
9448         uint8_t rule_id;
9449 };
9450
9451 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9452         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9453                                  reset, "reset");
9454 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9455         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9456                                 port, "port");
9457 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9458         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9459                                 port_id, RTE_UINT16);
9460 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9461         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9462                                 mirror, "mirror-rule");
9463 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9464         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9465                                 rule_id, RTE_UINT8);
9466
9467 static void
9468 cmd_reset_mirror_rule_parsed(void *parsed_result,
9469                        __rte_unused struct cmdline *cl,
9470                        __rte_unused void *data)
9471 {
9472         int ret;
9473         struct cmd_set_mirror_link_result *res = parsed_result;
9474         /* check rule_id */
9475         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9476         if(ret < 0)
9477                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9478 }
9479
9480 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9481                 .f = cmd_reset_mirror_rule_parsed,
9482                 .data = NULL,
9483                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9484                 .tokens = {
9485                         (void *)&cmd_rm_mirror_rule_reset,
9486                         (void *)&cmd_rm_mirror_rule_port,
9487                         (void *)&cmd_rm_mirror_rule_portid,
9488                         (void *)&cmd_rm_mirror_rule_mirror,
9489                         (void *)&cmd_rm_mirror_rule_ruleid,
9490                         NULL,
9491                 },
9492 };
9493
9494 /* ******************************************************************************** */
9495
9496 struct cmd_dump_result {
9497         cmdline_fixed_string_t dump;
9498 };
9499
9500 static void
9501 dump_struct_sizes(void)
9502 {
9503 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9504         DUMP_SIZE(struct rte_mbuf);
9505         DUMP_SIZE(struct rte_mempool);
9506         DUMP_SIZE(struct rte_ring);
9507 #undef DUMP_SIZE
9508 }
9509
9510
9511 /* Dump the socket memory statistics on console */
9512 static void
9513 dump_socket_mem(FILE *f)
9514 {
9515         struct rte_malloc_socket_stats socket_stats;
9516         unsigned int i;
9517         size_t total = 0;
9518         size_t alloc = 0;
9519         size_t free = 0;
9520         unsigned int n_alloc = 0;
9521         unsigned int n_free = 0;
9522         static size_t last_allocs;
9523         static size_t last_total;
9524
9525
9526         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9527                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9528                     !socket_stats.heap_totalsz_bytes)
9529                         continue;
9530                 total += socket_stats.heap_totalsz_bytes;
9531                 alloc += socket_stats.heap_allocsz_bytes;
9532                 free += socket_stats.heap_freesz_bytes;
9533                 n_alloc += socket_stats.alloc_count;
9534                 n_free += socket_stats.free_count;
9535                 fprintf(f,
9536                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9537                         i,
9538                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9539                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9540                         (double)socket_stats.heap_allocsz_bytes * 100 /
9541                         (double)socket_stats.heap_totalsz_bytes,
9542                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9543                         socket_stats.alloc_count,
9544                         socket_stats.free_count);
9545         }
9546         fprintf(f,
9547                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9548                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9549                 (double)alloc * 100 / (double)total,
9550                 (double)free / (1024 * 1024),
9551                 n_alloc, n_free);
9552         if (last_allocs)
9553                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9554                         ((double)total - (double)last_total) / (1024 * 1024),
9555                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9556         last_allocs = alloc;
9557         last_total = total;
9558 }
9559
9560 static void cmd_dump_parsed(void *parsed_result,
9561                             __rte_unused struct cmdline *cl,
9562                             __rte_unused void *data)
9563 {
9564         struct cmd_dump_result *res = parsed_result;
9565
9566         if (!strcmp(res->dump, "dump_physmem"))
9567                 rte_dump_physmem_layout(stdout);
9568         else if (!strcmp(res->dump, "dump_socket_mem"))
9569                 dump_socket_mem(stdout);
9570         else if (!strcmp(res->dump, "dump_memzone"))
9571                 rte_memzone_dump(stdout);
9572         else if (!strcmp(res->dump, "dump_struct_sizes"))
9573                 dump_struct_sizes();
9574         else if (!strcmp(res->dump, "dump_ring"))
9575                 rte_ring_list_dump(stdout);
9576         else if (!strcmp(res->dump, "dump_mempool"))
9577                 rte_mempool_list_dump(stdout);
9578         else if (!strcmp(res->dump, "dump_devargs"))
9579                 rte_devargs_dump(stdout);
9580         else if (!strcmp(res->dump, "dump_log_types"))
9581                 rte_log_dump(stdout);
9582 }
9583
9584 cmdline_parse_token_string_t cmd_dump_dump =
9585         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9586                 "dump_physmem#"
9587                 "dump_memzone#"
9588                 "dump_socket_mem#"
9589                 "dump_struct_sizes#"
9590                 "dump_ring#"
9591                 "dump_mempool#"
9592                 "dump_devargs#"
9593                 "dump_log_types");
9594
9595 cmdline_parse_inst_t cmd_dump = {
9596         .f = cmd_dump_parsed,  /* function to call */
9597         .data = NULL,      /* 2nd arg of func */
9598         .help_str = "Dump status",
9599         .tokens = {        /* token list, NULL terminated */
9600                 (void *)&cmd_dump_dump,
9601                 NULL,
9602         },
9603 };
9604
9605 /* ******************************************************************************** */
9606
9607 struct cmd_dump_one_result {
9608         cmdline_fixed_string_t dump;
9609         cmdline_fixed_string_t name;
9610 };
9611
9612 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9613                                 __rte_unused void *data)
9614 {
9615         struct cmd_dump_one_result *res = parsed_result;
9616
9617         if (!strcmp(res->dump, "dump_ring")) {
9618                 struct rte_ring *r;
9619                 r = rte_ring_lookup(res->name);
9620                 if (r == NULL) {
9621                         cmdline_printf(cl, "Cannot find ring\n");
9622                         return;
9623                 }
9624                 rte_ring_dump(stdout, r);
9625         } else if (!strcmp(res->dump, "dump_mempool")) {
9626                 struct rte_mempool *mp;
9627                 mp = rte_mempool_lookup(res->name);
9628                 if (mp == NULL) {
9629                         cmdline_printf(cl, "Cannot find mempool\n");
9630                         return;
9631                 }
9632                 rte_mempool_dump(stdout, mp);
9633         }
9634 }
9635
9636 cmdline_parse_token_string_t cmd_dump_one_dump =
9637         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9638                                  "dump_ring#dump_mempool");
9639
9640 cmdline_parse_token_string_t cmd_dump_one_name =
9641         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9642
9643 cmdline_parse_inst_t cmd_dump_one = {
9644         .f = cmd_dump_one_parsed,  /* function to call */
9645         .data = NULL,      /* 2nd arg of func */
9646         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9647         .tokens = {        /* token list, NULL terminated */
9648                 (void *)&cmd_dump_one_dump,
9649                 (void *)&cmd_dump_one_name,
9650                 NULL,
9651         },
9652 };
9653
9654 /* *** queue region set *** */
9655 struct cmd_queue_region_result {
9656         cmdline_fixed_string_t set;
9657         cmdline_fixed_string_t port;
9658         portid_t port_id;
9659         cmdline_fixed_string_t cmd;
9660         cmdline_fixed_string_t region;
9661         uint8_t  region_id;
9662         cmdline_fixed_string_t queue_start_index;
9663         uint8_t  queue_id;
9664         cmdline_fixed_string_t queue_num;
9665         uint8_t  queue_num_value;
9666 };
9667
9668 static void
9669 cmd_queue_region_parsed(void *parsed_result,
9670                         __rte_unused struct cmdline *cl,
9671                         __rte_unused void *data)
9672 {
9673         struct cmd_queue_region_result *res = parsed_result;
9674         int ret = -ENOTSUP;
9675 #ifdef RTE_NET_I40E
9676         struct rte_pmd_i40e_queue_region_conf region_conf;
9677         enum rte_pmd_i40e_queue_region_op op_type;
9678 #endif
9679
9680         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9681                 return;
9682
9683 #ifdef RTE_NET_I40E
9684         memset(&region_conf, 0, sizeof(region_conf));
9685         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9686         region_conf.region_id = res->region_id;
9687         region_conf.queue_num = res->queue_num_value;
9688         region_conf.queue_start_index = res->queue_id;
9689
9690         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9691                                 op_type, &region_conf);
9692 #endif
9693
9694         switch (ret) {
9695         case 0:
9696                 break;
9697         case -ENOTSUP:
9698                 printf("function not implemented or supported\n");
9699                 break;
9700         default:
9701                 printf("queue region config error: (%s)\n", strerror(-ret));
9702         }
9703 }
9704
9705 cmdline_parse_token_string_t cmd_queue_region_set =
9706 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9707                 set, "set");
9708 cmdline_parse_token_string_t cmd_queue_region_port =
9709         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9710 cmdline_parse_token_num_t cmd_queue_region_port_id =
9711         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9712                                 port_id, RTE_UINT16);
9713 cmdline_parse_token_string_t cmd_queue_region_cmd =
9714         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9715                                  cmd, "queue-region");
9716 cmdline_parse_token_string_t cmd_queue_region_id =
9717         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9718                                 region, "region_id");
9719 cmdline_parse_token_num_t cmd_queue_region_index =
9720         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9721                                 region_id, RTE_UINT8);
9722 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9723         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9724                                 queue_start_index, "queue_start_index");
9725 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9726         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9727                                 queue_id, RTE_UINT8);
9728 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9729         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9730                                 queue_num, "queue_num");
9731 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9732         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9733                                 queue_num_value, RTE_UINT8);
9734
9735 cmdline_parse_inst_t cmd_queue_region = {
9736         .f = cmd_queue_region_parsed,
9737         .data = NULL,
9738         .help_str = "set port <port_id> queue-region region_id <value> "
9739                 "queue_start_index <value> queue_num <value>: Set a queue region",
9740         .tokens = {
9741                 (void *)&cmd_queue_region_set,
9742                 (void *)&cmd_queue_region_port,
9743                 (void *)&cmd_queue_region_port_id,
9744                 (void *)&cmd_queue_region_cmd,
9745                 (void *)&cmd_queue_region_id,
9746                 (void *)&cmd_queue_region_index,
9747                 (void *)&cmd_queue_region_queue_start_index,
9748                 (void *)&cmd_queue_region_queue_id,
9749                 (void *)&cmd_queue_region_queue_num,
9750                 (void *)&cmd_queue_region_queue_num_value,
9751                 NULL,
9752         },
9753 };
9754
9755 /* *** queue region and flowtype set *** */
9756 struct cmd_region_flowtype_result {
9757         cmdline_fixed_string_t set;
9758         cmdline_fixed_string_t port;
9759         portid_t port_id;
9760         cmdline_fixed_string_t cmd;
9761         cmdline_fixed_string_t region;
9762         uint8_t  region_id;
9763         cmdline_fixed_string_t flowtype;
9764         uint8_t  flowtype_id;
9765 };
9766
9767 static void
9768 cmd_region_flowtype_parsed(void *parsed_result,
9769                         __rte_unused struct cmdline *cl,
9770                         __rte_unused void *data)
9771 {
9772         struct cmd_region_flowtype_result *res = parsed_result;
9773         int ret = -ENOTSUP;
9774 #ifdef RTE_NET_I40E
9775         struct rte_pmd_i40e_queue_region_conf region_conf;
9776         enum rte_pmd_i40e_queue_region_op op_type;
9777 #endif
9778
9779         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9780                 return;
9781
9782 #ifdef RTE_NET_I40E
9783         memset(&region_conf, 0, sizeof(region_conf));
9784
9785         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9786         region_conf.region_id = res->region_id;
9787         region_conf.hw_flowtype = res->flowtype_id;
9788
9789         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9790                         op_type, &region_conf);
9791 #endif
9792
9793         switch (ret) {
9794         case 0:
9795                 break;
9796         case -ENOTSUP:
9797                 printf("function not implemented or supported\n");
9798                 break;
9799         default:
9800                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9801         }
9802 }
9803
9804 cmdline_parse_token_string_t cmd_region_flowtype_set =
9805 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9806                                 set, "set");
9807 cmdline_parse_token_string_t cmd_region_flowtype_port =
9808         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9809                                 port, "port");
9810 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9811         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9812                                 port_id, RTE_UINT16);
9813 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9814         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9815                                 cmd, "queue-region");
9816 cmdline_parse_token_string_t cmd_region_flowtype_index =
9817         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9818                                 region, "region_id");
9819 cmdline_parse_token_num_t cmd_region_flowtype_id =
9820         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9821                                 region_id, RTE_UINT8);
9822 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9823         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9824                                 flowtype, "flowtype");
9825 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9826         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9827                                 flowtype_id, RTE_UINT8);
9828 cmdline_parse_inst_t cmd_region_flowtype = {
9829         .f = cmd_region_flowtype_parsed,
9830         .data = NULL,
9831         .help_str = "set port <port_id> queue-region region_id <value> "
9832                 "flowtype <value>: Set a flowtype region index",
9833         .tokens = {
9834                 (void *)&cmd_region_flowtype_set,
9835                 (void *)&cmd_region_flowtype_port,
9836                 (void *)&cmd_region_flowtype_port_index,
9837                 (void *)&cmd_region_flowtype_cmd,
9838                 (void *)&cmd_region_flowtype_index,
9839                 (void *)&cmd_region_flowtype_id,
9840                 (void *)&cmd_region_flowtype_flow_index,
9841                 (void *)&cmd_region_flowtype_flow_id,
9842                 NULL,
9843         },
9844 };
9845
9846 /* *** User Priority (UP) to queue region (region_id) set *** */
9847 struct cmd_user_priority_region_result {
9848         cmdline_fixed_string_t set;
9849         cmdline_fixed_string_t port;
9850         portid_t port_id;
9851         cmdline_fixed_string_t cmd;
9852         cmdline_fixed_string_t user_priority;
9853         uint8_t  user_priority_id;
9854         cmdline_fixed_string_t region;
9855         uint8_t  region_id;
9856 };
9857
9858 static void
9859 cmd_user_priority_region_parsed(void *parsed_result,
9860                         __rte_unused struct cmdline *cl,
9861                         __rte_unused void *data)
9862 {
9863         struct cmd_user_priority_region_result *res = parsed_result;
9864         int ret = -ENOTSUP;
9865 #ifdef RTE_NET_I40E
9866         struct rte_pmd_i40e_queue_region_conf region_conf;
9867         enum rte_pmd_i40e_queue_region_op op_type;
9868 #endif
9869
9870         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9871                 return;
9872
9873 #ifdef RTE_NET_I40E
9874         memset(&region_conf, 0, sizeof(region_conf));
9875         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9876         region_conf.user_priority = res->user_priority_id;
9877         region_conf.region_id = res->region_id;
9878
9879         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9880                                 op_type, &region_conf);
9881 #endif
9882
9883         switch (ret) {
9884         case 0:
9885                 break;
9886         case -ENOTSUP:
9887                 printf("function not implemented or supported\n");
9888                 break;
9889         default:
9890                 printf("user_priority region config error: (%s)\n",
9891                                 strerror(-ret));
9892         }
9893 }
9894
9895 cmdline_parse_token_string_t cmd_user_priority_region_set =
9896         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9897                                 set, "set");
9898 cmdline_parse_token_string_t cmd_user_priority_region_port =
9899         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9900                                 port, "port");
9901 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9902         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9903                                 port_id, RTE_UINT16);
9904 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9905         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9906                                 cmd, "queue-region");
9907 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9908         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9909                                 user_priority, "UP");
9910 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9911         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9912                                 user_priority_id, RTE_UINT8);
9913 cmdline_parse_token_string_t cmd_user_priority_region_region =
9914         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9915                                 region, "region_id");
9916 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9917         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9918                                 region_id, RTE_UINT8);
9919
9920 cmdline_parse_inst_t cmd_user_priority_region = {
9921         .f = cmd_user_priority_region_parsed,
9922         .data = NULL,
9923         .help_str = "set port <port_id> queue-region UP <value> "
9924                 "region_id <value>: Set the mapping of User Priority (UP) "
9925                 "to queue region (region_id) ",
9926         .tokens = {
9927                 (void *)&cmd_user_priority_region_set,
9928                 (void *)&cmd_user_priority_region_port,
9929                 (void *)&cmd_user_priority_region_port_index,
9930                 (void *)&cmd_user_priority_region_cmd,
9931                 (void *)&cmd_user_priority_region_UP,
9932                 (void *)&cmd_user_priority_region_UP_id,
9933                 (void *)&cmd_user_priority_region_region,
9934                 (void *)&cmd_user_priority_region_region_id,
9935                 NULL,
9936         },
9937 };
9938
9939 /* *** flush all queue region related configuration *** */
9940 struct cmd_flush_queue_region_result {
9941         cmdline_fixed_string_t set;
9942         cmdline_fixed_string_t port;
9943         portid_t port_id;
9944         cmdline_fixed_string_t cmd;
9945         cmdline_fixed_string_t flush;
9946         cmdline_fixed_string_t what;
9947 };
9948
9949 static void
9950 cmd_flush_queue_region_parsed(void *parsed_result,
9951                         __rte_unused struct cmdline *cl,
9952                         __rte_unused void *data)
9953 {
9954         struct cmd_flush_queue_region_result *res = parsed_result;
9955         int ret = -ENOTSUP;
9956 #ifdef RTE_NET_I40E
9957         struct rte_pmd_i40e_queue_region_conf region_conf;
9958         enum rte_pmd_i40e_queue_region_op op_type;
9959 #endif
9960
9961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9962                 return;
9963
9964 #ifdef RTE_NET_I40E
9965         memset(&region_conf, 0, sizeof(region_conf));
9966
9967         if (strcmp(res->what, "on") == 0)
9968                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9969         else
9970                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9971
9972         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9973                                 op_type, &region_conf);
9974 #endif
9975
9976         switch (ret) {
9977         case 0:
9978                 break;
9979         case -ENOTSUP:
9980                 printf("function not implemented or supported\n");
9981                 break;
9982         default:
9983                 printf("queue region config flush error: (%s)\n",
9984                                 strerror(-ret));
9985         }
9986 }
9987
9988 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9989         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9990                                 set, "set");
9991 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9992         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9993                                 port, "port");
9994 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9995         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9996                                 port_id, RTE_UINT16);
9997 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9998         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9999                                 cmd, "queue-region");
10000 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10001         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10002                                 flush, "flush");
10003 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10004         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10005                                 what, "on#off");
10006
10007 cmdline_parse_inst_t cmd_flush_queue_region = {
10008         .f = cmd_flush_queue_region_parsed,
10009         .data = NULL,
10010         .help_str = "set port <port_id> queue-region flush on|off"
10011                 ": flush all queue region related configuration",
10012         .tokens = {
10013                 (void *)&cmd_flush_queue_region_set,
10014                 (void *)&cmd_flush_queue_region_port,
10015                 (void *)&cmd_flush_queue_region_port_index,
10016                 (void *)&cmd_flush_queue_region_cmd,
10017                 (void *)&cmd_flush_queue_region_flush,
10018                 (void *)&cmd_flush_queue_region_what,
10019                 NULL,
10020         },
10021 };
10022
10023 /* *** get all queue region related configuration info *** */
10024 struct cmd_show_queue_region_info {
10025         cmdline_fixed_string_t show;
10026         cmdline_fixed_string_t port;
10027         portid_t port_id;
10028         cmdline_fixed_string_t cmd;
10029 };
10030
10031 static void
10032 cmd_show_queue_region_info_parsed(void *parsed_result,
10033                         __rte_unused struct cmdline *cl,
10034                         __rte_unused void *data)
10035 {
10036         struct cmd_show_queue_region_info *res = parsed_result;
10037         int ret = -ENOTSUP;
10038 #ifdef RTE_NET_I40E
10039         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10040         enum rte_pmd_i40e_queue_region_op op_type;
10041 #endif
10042
10043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10044                 return;
10045
10046 #ifdef RTE_NET_I40E
10047         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10048
10049         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10050
10051         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10052                                         op_type, &rte_pmd_regions);
10053
10054         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10055 #endif
10056
10057         switch (ret) {
10058         case 0:
10059                 break;
10060         case -ENOTSUP:
10061                 printf("function not implemented or supported\n");
10062                 break;
10063         default:
10064                 printf("queue region config info show error: (%s)\n",
10065                                 strerror(-ret));
10066         }
10067 }
10068
10069 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10070 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10071                                 show, "show");
10072 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10073         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10074                                 port, "port");
10075 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10076         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10077                                 port_id, RTE_UINT16);
10078 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10079         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10080                                 cmd, "queue-region");
10081
10082 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10083         .f = cmd_show_queue_region_info_parsed,
10084         .data = NULL,
10085         .help_str = "show port <port_id> queue-region"
10086                 ": show all queue region related configuration info",
10087         .tokens = {
10088                 (void *)&cmd_show_queue_region_info_get,
10089                 (void *)&cmd_show_queue_region_info_port,
10090                 (void *)&cmd_show_queue_region_info_port_index,
10091                 (void *)&cmd_show_queue_region_info_cmd,
10092                 NULL,
10093         },
10094 };
10095
10096 /* *** Filters Control *** */
10097
10098 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10099 do { \
10100         if ((ip_addr).family == AF_INET) \
10101                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10102         else { \
10103                 printf("invalid parameter.\n"); \
10104                 return; \
10105         } \
10106 } while (0)
10107
10108 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10109 do { \
10110         if ((ip_addr).family == AF_INET6) \
10111                 rte_memcpy(&(ip), \
10112                                  &((ip_addr).addr.ipv6), \
10113                                  sizeof(struct in6_addr)); \
10114         else { \
10115                 printf("invalid parameter.\n"); \
10116                 return; \
10117         } \
10118 } while (0)
10119
10120 #ifdef RTE_NET_I40E
10121
10122 static uint16_t
10123 str2flowtype(char *string)
10124 {
10125         uint8_t i = 0;
10126         static const struct {
10127                 char str[32];
10128                 uint16_t type;
10129         } flowtype_str[] = {
10130                 {"raw", RTE_ETH_FLOW_RAW},
10131                 {"ipv4", RTE_ETH_FLOW_IPV4},
10132                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10133                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10134                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10135                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10136                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10137                 {"ipv6", RTE_ETH_FLOW_IPV6},
10138                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10139                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10140                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10141                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10142                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10143                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10144         };
10145
10146         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10147                 if (!strcmp(flowtype_str[i].str, string))
10148                         return flowtype_str[i].type;
10149         }
10150
10151         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10152                 return (uint16_t)atoi(string);
10153
10154         return RTE_ETH_FLOW_UNKNOWN;
10155 }
10156
10157 /* *** deal with flow director filter *** */
10158 struct cmd_flow_director_result {
10159         cmdline_fixed_string_t flow_director_filter;
10160         portid_t port_id;
10161         cmdline_fixed_string_t mode;
10162         cmdline_fixed_string_t mode_value;
10163         cmdline_fixed_string_t ops;
10164         cmdline_fixed_string_t flow;
10165         cmdline_fixed_string_t flow_type;
10166         cmdline_fixed_string_t drop;
10167         cmdline_fixed_string_t queue;
10168         uint16_t  queue_id;
10169         cmdline_fixed_string_t fd_id;
10170         uint32_t  fd_id_value;
10171         cmdline_fixed_string_t packet;
10172         char filepath[];
10173 };
10174
10175 static void
10176 cmd_flow_director_filter_parsed(void *parsed_result,
10177                           __rte_unused struct cmdline *cl,
10178                           __rte_unused void *data)
10179 {
10180         struct cmd_flow_director_result *res = parsed_result;
10181         int ret = 0;
10182         struct rte_pmd_i40e_flow_type_mapping
10183                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10184         struct rte_pmd_i40e_pkt_template_conf conf;
10185         uint16_t flow_type = str2flowtype(res->flow_type);
10186         uint16_t i, port = res->port_id;
10187         uint8_t add;
10188
10189         memset(&conf, 0, sizeof(conf));
10190
10191         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10192                 printf("Invalid flow type specified.\n");
10193                 return;
10194         }
10195         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10196                                                  mapping);
10197         if (ret)
10198                 return;
10199         if (mapping[flow_type].pctype == 0ULL) {
10200                 printf("Invalid flow type specified.\n");
10201                 return;
10202         }
10203         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10204                 if (mapping[flow_type].pctype & (1ULL << i)) {
10205                         conf.input.pctype = i;
10206                         break;
10207                 }
10208         }
10209
10210         conf.input.packet = open_file(res->filepath,
10211                                 &conf.input.length);
10212         if (!conf.input.packet)
10213                 return;
10214         if (!strcmp(res->drop, "drop"))
10215                 conf.action.behavior =
10216                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10217         else
10218                 conf.action.behavior =
10219                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10220         conf.action.report_status =
10221                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10222         conf.action.rx_queue = res->queue_id;
10223         conf.soft_id = res->fd_id_value;
10224         add  = strcmp(res->ops, "del") ? 1 : 0;
10225         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10226                                                         &conf,
10227                                                         add);
10228         if (ret < 0)
10229                 printf("flow director config error: (%s)\n",
10230                        strerror(-ret));
10231         close_file(conf.input.packet);
10232 }
10233
10234 cmdline_parse_token_string_t cmd_flow_director_filter =
10235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10236                                  flow_director_filter, "flow_director_filter");
10237 cmdline_parse_token_num_t cmd_flow_director_port_id =
10238         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10239                               port_id, RTE_UINT16);
10240 cmdline_parse_token_string_t cmd_flow_director_ops =
10241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10242                                  ops, "add#del#update");
10243 cmdline_parse_token_string_t cmd_flow_director_flow =
10244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10245                                  flow, "flow");
10246 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10248                 flow_type, NULL);
10249 cmdline_parse_token_string_t cmd_flow_director_drop =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  drop, "drop#fwd");
10252 cmdline_parse_token_string_t cmd_flow_director_queue =
10253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10254                                  queue, "queue");
10255 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10256         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10257                               queue_id, RTE_UINT16);
10258 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10260                                  fd_id, "fd_id");
10261 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10262         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10263                               fd_id_value, RTE_UINT32);
10264
10265 cmdline_parse_token_string_t cmd_flow_director_mode =
10266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10267                                  mode, "mode");
10268 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10270                                  mode_value, "raw");
10271 cmdline_parse_token_string_t cmd_flow_director_packet =
10272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10273                                  packet, "packet");
10274 cmdline_parse_token_string_t cmd_flow_director_filepath =
10275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10276                                  filepath, NULL);
10277
10278 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10279         .f = cmd_flow_director_filter_parsed,
10280         .data = NULL,
10281         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10282                 "director entry on NIC",
10283         .tokens = {
10284                 (void *)&cmd_flow_director_filter,
10285                 (void *)&cmd_flow_director_port_id,
10286                 (void *)&cmd_flow_director_mode,
10287                 (void *)&cmd_flow_director_mode_raw,
10288                 (void *)&cmd_flow_director_ops,
10289                 (void *)&cmd_flow_director_flow,
10290                 (void *)&cmd_flow_director_flow_type,
10291                 (void *)&cmd_flow_director_drop,
10292                 (void *)&cmd_flow_director_queue,
10293                 (void *)&cmd_flow_director_queue_id,
10294                 (void *)&cmd_flow_director_fd_id,
10295                 (void *)&cmd_flow_director_fd_id_value,
10296                 (void *)&cmd_flow_director_packet,
10297                 (void *)&cmd_flow_director_filepath,
10298                 NULL,
10299         },
10300 };
10301
10302 #endif /* RTE_NET_I40E */
10303
10304 /* *** deal with flow director mask *** */
10305 struct cmd_flow_director_mask_result {
10306         cmdline_fixed_string_t flow_director_mask;
10307         portid_t port_id;
10308         cmdline_fixed_string_t mode;
10309         cmdline_fixed_string_t mode_value;
10310         cmdline_fixed_string_t vlan;
10311         uint16_t vlan_mask;
10312         cmdline_fixed_string_t src_mask;
10313         cmdline_ipaddr_t ipv4_src;
10314         cmdline_ipaddr_t ipv6_src;
10315         uint16_t port_src;
10316         cmdline_fixed_string_t dst_mask;
10317         cmdline_ipaddr_t ipv4_dst;
10318         cmdline_ipaddr_t ipv6_dst;
10319         uint16_t port_dst;
10320         cmdline_fixed_string_t mac;
10321         uint8_t mac_addr_byte_mask;
10322         cmdline_fixed_string_t tunnel_id;
10323         uint32_t tunnel_id_mask;
10324         cmdline_fixed_string_t tunnel_type;
10325         uint8_t tunnel_type_mask;
10326 };
10327
10328 static void
10329 cmd_flow_director_mask_parsed(void *parsed_result,
10330                           __rte_unused struct cmdline *cl,
10331                           __rte_unused void *data)
10332 {
10333         struct cmd_flow_director_mask_result *res = parsed_result;
10334         struct rte_eth_fdir_masks *mask;
10335         struct rte_port *port;
10336
10337         port = &ports[res->port_id];
10338         /** Check if the port is not started **/
10339         if (port->port_status != RTE_PORT_STOPPED) {
10340                 printf("Please stop port %d first\n", res->port_id);
10341                 return;
10342         }
10343
10344         mask = &port->dev_conf.fdir_conf.mask;
10345
10346         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10347                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10348                         printf("Please set mode to MAC-VLAN.\n");
10349                         return;
10350                 }
10351
10352                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10353         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10354                 if (strcmp(res->mode_value, "Tunnel")) {
10355                         printf("Please set mode to Tunnel.\n");
10356                         return;
10357                 }
10358
10359                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10360                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10361                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10362                 mask->tunnel_type_mask = res->tunnel_type_mask;
10363         } else {
10364                 if (strcmp(res->mode_value, "IP")) {
10365                         printf("Please set mode to IP.\n");
10366                         return;
10367                 }
10368
10369                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10370                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10371                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10372                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10373                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10374                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10375                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10376         }
10377
10378         cmd_reconfig_device_queue(res->port_id, 1, 1);
10379 }
10380
10381 cmdline_parse_token_string_t cmd_flow_director_mask =
10382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10383                                  flow_director_mask, "flow_director_mask");
10384 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10385         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10386                               port_id, RTE_UINT16);
10387 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10389                                  vlan, "vlan");
10390 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10391         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10392                               vlan_mask, RTE_UINT16);
10393 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10395                                  src_mask, "src_mask");
10396 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10397         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10398                                  ipv4_src);
10399 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10400         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10401                                  ipv6_src);
10402 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10403         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10404                               port_src, RTE_UINT16);
10405 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10407                                  dst_mask, "dst_mask");
10408 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10409         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10410                                  ipv4_dst);
10411 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10412         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10413                                  ipv6_dst);
10414 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10415         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10416                               port_dst, RTE_UINT16);
10417
10418 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10419         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10420                                  mode, "mode");
10421 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10423                                  mode_value, "IP");
10424 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10426                                  mode_value, "MAC-VLAN");
10427 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10429                                  mode_value, "Tunnel");
10430 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10432                                  mac, "mac");
10433 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10434         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10435                               mac_addr_byte_mask, RTE_UINT8);
10436 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10438                                  tunnel_type, "tunnel-type");
10439 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10440         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10441                               tunnel_type_mask, RTE_UINT8);
10442 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10443         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10444                                  tunnel_id, "tunnel-id");
10445 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10446         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10447                               tunnel_id_mask, RTE_UINT32);
10448
10449 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10450         .f = cmd_flow_director_mask_parsed,
10451         .data = NULL,
10452         .help_str = "flow_director_mask ... : "
10453                 "Set IP mode flow director's mask on NIC",
10454         .tokens = {
10455                 (void *)&cmd_flow_director_mask,
10456                 (void *)&cmd_flow_director_mask_port_id,
10457                 (void *)&cmd_flow_director_mask_mode,
10458                 (void *)&cmd_flow_director_mask_mode_ip,
10459                 (void *)&cmd_flow_director_mask_vlan,
10460                 (void *)&cmd_flow_director_mask_vlan_value,
10461                 (void *)&cmd_flow_director_mask_src,
10462                 (void *)&cmd_flow_director_mask_ipv4_src,
10463                 (void *)&cmd_flow_director_mask_ipv6_src,
10464                 (void *)&cmd_flow_director_mask_port_src,
10465                 (void *)&cmd_flow_director_mask_dst,
10466                 (void *)&cmd_flow_director_mask_ipv4_dst,
10467                 (void *)&cmd_flow_director_mask_ipv6_dst,
10468                 (void *)&cmd_flow_director_mask_port_dst,
10469                 NULL,
10470         },
10471 };
10472
10473 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10474         .f = cmd_flow_director_mask_parsed,
10475         .data = NULL,
10476         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10477                 "flow director's mask on NIC",
10478         .tokens = {
10479                 (void *)&cmd_flow_director_mask,
10480                 (void *)&cmd_flow_director_mask_port_id,
10481                 (void *)&cmd_flow_director_mask_mode,
10482                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10483                 (void *)&cmd_flow_director_mask_vlan,
10484                 (void *)&cmd_flow_director_mask_vlan_value,
10485                 NULL,
10486         },
10487 };
10488
10489 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10490         .f = cmd_flow_director_mask_parsed,
10491         .data = NULL,
10492         .help_str = "flow_director_mask ... : Set tunnel mode "
10493                 "flow director's mask on NIC",
10494         .tokens = {
10495                 (void *)&cmd_flow_director_mask,
10496                 (void *)&cmd_flow_director_mask_port_id,
10497                 (void *)&cmd_flow_director_mask_mode,
10498                 (void *)&cmd_flow_director_mask_mode_tunnel,
10499                 (void *)&cmd_flow_director_mask_vlan,
10500                 (void *)&cmd_flow_director_mask_vlan_value,
10501                 (void *)&cmd_flow_director_mask_mac,
10502                 (void *)&cmd_flow_director_mask_mac_value,
10503                 (void *)&cmd_flow_director_mask_tunnel_type,
10504                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10505                 (void *)&cmd_flow_director_mask_tunnel_id,
10506                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10507                 NULL,
10508         },
10509 };
10510
10511 /* *** deal with flow director flexible payload configuration *** */
10512 struct cmd_flow_director_flexpayload_result {
10513         cmdline_fixed_string_t flow_director_flexpayload;
10514         portid_t port_id;
10515         cmdline_fixed_string_t payload_layer;
10516         cmdline_fixed_string_t payload_cfg;
10517 };
10518
10519 static inline int
10520 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10521 {
10522         char s[256];
10523         const char *p, *p0 = q_arg;
10524         char *end;
10525         unsigned long int_fld;
10526         char *str_fld[max_num];
10527         int i;
10528         unsigned size;
10529         int ret = -1;
10530
10531         p = strchr(p0, '(');
10532         if (p == NULL)
10533                 return -1;
10534         ++p;
10535         p0 = strchr(p, ')');
10536         if (p0 == NULL)
10537                 return -1;
10538
10539         size = p0 - p;
10540         if (size >= sizeof(s))
10541                 return -1;
10542
10543         snprintf(s, sizeof(s), "%.*s", size, p);
10544         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10545         if (ret < 0 || ret > max_num)
10546                 return -1;
10547         for (i = 0; i < ret; i++) {
10548                 errno = 0;
10549                 int_fld = strtoul(str_fld[i], &end, 0);
10550                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10551                         return -1;
10552                 offsets[i] = (uint16_t)int_fld;
10553         }
10554         return ret;
10555 }
10556
10557 static void
10558 cmd_flow_director_flxpld_parsed(void *parsed_result,
10559                           __rte_unused struct cmdline *cl,
10560                           __rte_unused void *data)
10561 {
10562         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10563         struct rte_eth_flex_payload_cfg flex_cfg;
10564         struct rte_port *port;
10565         int ret = 0;
10566
10567         port = &ports[res->port_id];
10568         /** Check if the port is not started **/
10569         if (port->port_status != RTE_PORT_STOPPED) {
10570                 printf("Please stop port %d first\n", res->port_id);
10571                 return;
10572         }
10573
10574         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10575
10576         if (!strcmp(res->payload_layer, "raw"))
10577                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10578         else if (!strcmp(res->payload_layer, "l2"))
10579                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10580         else if (!strcmp(res->payload_layer, "l3"))
10581                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10582         else if (!strcmp(res->payload_layer, "l4"))
10583                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10584
10585         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10586                             RTE_ETH_FDIR_MAX_FLEXLEN);
10587         if (ret < 0) {
10588                 printf("error: Cannot parse flex payload input.\n");
10589                 return;
10590         }
10591
10592         fdir_set_flex_payload(res->port_id, &flex_cfg);
10593         cmd_reconfig_device_queue(res->port_id, 1, 1);
10594 }
10595
10596 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10598                                  flow_director_flexpayload,
10599                                  "flow_director_flex_payload");
10600 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10601         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10602                               port_id, RTE_UINT16);
10603 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10604         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10605                                  payload_layer, "raw#l2#l3#l4");
10606 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10607         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10608                                  payload_cfg, NULL);
10609
10610 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10611         .f = cmd_flow_director_flxpld_parsed,
10612         .data = NULL,
10613         .help_str = "flow_director_flexpayload ... : "
10614                 "Set flow director's flex payload on NIC",
10615         .tokens = {
10616                 (void *)&cmd_flow_director_flexpayload,
10617                 (void *)&cmd_flow_director_flexpayload_port_id,
10618                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10619                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10620                 NULL,
10621         },
10622 };
10623
10624 /* Generic flow interface command. */
10625 extern cmdline_parse_inst_t cmd_flow;
10626
10627 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10628 struct cmd_mcast_addr_result {
10629         cmdline_fixed_string_t mcast_addr_cmd;
10630         cmdline_fixed_string_t what;
10631         uint16_t port_num;
10632         struct rte_ether_addr mc_addr;
10633 };
10634
10635 static void cmd_mcast_addr_parsed(void *parsed_result,
10636                 __rte_unused struct cmdline *cl,
10637                 __rte_unused void *data)
10638 {
10639         struct cmd_mcast_addr_result *res = parsed_result;
10640
10641         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10642                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10643                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10644                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10645                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10646                 return;
10647         }
10648         if (strcmp(res->what, "add") == 0)
10649                 mcast_addr_add(res->port_num, &res->mc_addr);
10650         else
10651                 mcast_addr_remove(res->port_num, &res->mc_addr);
10652 }
10653
10654 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10655         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10656                                  mcast_addr_cmd, "mcast_addr");
10657 cmdline_parse_token_string_t cmd_mcast_addr_what =
10658         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10659                                  "add#remove");
10660 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10661         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10662                                  RTE_UINT16);
10663 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10664         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10665
10666 cmdline_parse_inst_t cmd_mcast_addr = {
10667         .f = cmd_mcast_addr_parsed,
10668         .data = (void *)0,
10669         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10670                 "Add/Remove multicast MAC address on port_id",
10671         .tokens = {
10672                 (void *)&cmd_mcast_addr_cmd,
10673                 (void *)&cmd_mcast_addr_what,
10674                 (void *)&cmd_mcast_addr_portnum,
10675                 (void *)&cmd_mcast_addr_addr,
10676                 NULL,
10677         },
10678 };
10679
10680 /* vf vlan anti spoof configuration */
10681
10682 /* Common result structure for vf vlan anti spoof */
10683 struct cmd_vf_vlan_anti_spoof_result {
10684         cmdline_fixed_string_t set;
10685         cmdline_fixed_string_t vf;
10686         cmdline_fixed_string_t vlan;
10687         cmdline_fixed_string_t antispoof;
10688         portid_t port_id;
10689         uint32_t vf_id;
10690         cmdline_fixed_string_t on_off;
10691 };
10692
10693 /* Common CLI fields for vf vlan anti spoof enable disable */
10694 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10695         TOKEN_STRING_INITIALIZER
10696                 (struct cmd_vf_vlan_anti_spoof_result,
10697                  set, "set");
10698 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10699         TOKEN_STRING_INITIALIZER
10700                 (struct cmd_vf_vlan_anti_spoof_result,
10701                  vf, "vf");
10702 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10703         TOKEN_STRING_INITIALIZER
10704                 (struct cmd_vf_vlan_anti_spoof_result,
10705                  vlan, "vlan");
10706 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10707         TOKEN_STRING_INITIALIZER
10708                 (struct cmd_vf_vlan_anti_spoof_result,
10709                  antispoof, "antispoof");
10710 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10711         TOKEN_NUM_INITIALIZER
10712                 (struct cmd_vf_vlan_anti_spoof_result,
10713                  port_id, RTE_UINT16);
10714 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10715         TOKEN_NUM_INITIALIZER
10716                 (struct cmd_vf_vlan_anti_spoof_result,
10717                  vf_id, RTE_UINT32);
10718 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10719         TOKEN_STRING_INITIALIZER
10720                 (struct cmd_vf_vlan_anti_spoof_result,
10721                  on_off, "on#off");
10722
10723 static void
10724 cmd_set_vf_vlan_anti_spoof_parsed(
10725         void *parsed_result,
10726         __rte_unused struct cmdline *cl,
10727         __rte_unused void *data)
10728 {
10729         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10730         int ret = -ENOTSUP;
10731
10732         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10733
10734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10735                 return;
10736
10737 #ifdef RTE_NET_IXGBE
10738         if (ret == -ENOTSUP)
10739                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10740                                 res->vf_id, is_on);
10741 #endif
10742 #ifdef RTE_NET_I40E
10743         if (ret == -ENOTSUP)
10744                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10745                                 res->vf_id, is_on);
10746 #endif
10747 #ifdef RTE_NET_BNXT
10748         if (ret == -ENOTSUP)
10749                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10750                                 res->vf_id, is_on);
10751 #endif
10752
10753         switch (ret) {
10754         case 0:
10755                 break;
10756         case -EINVAL:
10757                 printf("invalid vf_id %d\n", res->vf_id);
10758                 break;
10759         case -ENODEV:
10760                 printf("invalid port_id %d\n", res->port_id);
10761                 break;
10762         case -ENOTSUP:
10763                 printf("function not implemented\n");
10764                 break;
10765         default:
10766                 printf("programming error: (%s)\n", strerror(-ret));
10767         }
10768 }
10769
10770 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10771         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10772         .data = NULL,
10773         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10774         .tokens = {
10775                 (void *)&cmd_vf_vlan_anti_spoof_set,
10776                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10777                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10778                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10779                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10780                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10781                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10782                 NULL,
10783         },
10784 };
10785
10786 /* vf mac anti spoof configuration */
10787
10788 /* Common result structure for vf mac anti spoof */
10789 struct cmd_vf_mac_anti_spoof_result {
10790         cmdline_fixed_string_t set;
10791         cmdline_fixed_string_t vf;
10792         cmdline_fixed_string_t mac;
10793         cmdline_fixed_string_t antispoof;
10794         portid_t port_id;
10795         uint32_t vf_id;
10796         cmdline_fixed_string_t on_off;
10797 };
10798
10799 /* Common CLI fields for vf mac anti spoof enable disable */
10800 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10801         TOKEN_STRING_INITIALIZER
10802                 (struct cmd_vf_mac_anti_spoof_result,
10803                  set, "set");
10804 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10805         TOKEN_STRING_INITIALIZER
10806                 (struct cmd_vf_mac_anti_spoof_result,
10807                  vf, "vf");
10808 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10809         TOKEN_STRING_INITIALIZER
10810                 (struct cmd_vf_mac_anti_spoof_result,
10811                  mac, "mac");
10812 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10813         TOKEN_STRING_INITIALIZER
10814                 (struct cmd_vf_mac_anti_spoof_result,
10815                  antispoof, "antispoof");
10816 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10817         TOKEN_NUM_INITIALIZER
10818                 (struct cmd_vf_mac_anti_spoof_result,
10819                  port_id, RTE_UINT16);
10820 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10821         TOKEN_NUM_INITIALIZER
10822                 (struct cmd_vf_mac_anti_spoof_result,
10823                  vf_id, RTE_UINT32);
10824 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10825         TOKEN_STRING_INITIALIZER
10826                 (struct cmd_vf_mac_anti_spoof_result,
10827                  on_off, "on#off");
10828
10829 static void
10830 cmd_set_vf_mac_anti_spoof_parsed(
10831         void *parsed_result,
10832         __rte_unused struct cmdline *cl,
10833         __rte_unused void *data)
10834 {
10835         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10836         int ret = -ENOTSUP;
10837
10838         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10839
10840         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10841                 return;
10842
10843 #ifdef RTE_NET_IXGBE
10844         if (ret == -ENOTSUP)
10845                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10846                         res->vf_id, is_on);
10847 #endif
10848 #ifdef RTE_NET_I40E
10849         if (ret == -ENOTSUP)
10850                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10851                         res->vf_id, is_on);
10852 #endif
10853 #ifdef RTE_NET_BNXT
10854         if (ret == -ENOTSUP)
10855                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10856                         res->vf_id, is_on);
10857 #endif
10858
10859         switch (ret) {
10860         case 0:
10861                 break;
10862         case -EINVAL:
10863                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10864                 break;
10865         case -ENODEV:
10866                 printf("invalid port_id %d\n", res->port_id);
10867                 break;
10868         case -ENOTSUP:
10869                 printf("function not implemented\n");
10870                 break;
10871         default:
10872                 printf("programming error: (%s)\n", strerror(-ret));
10873         }
10874 }
10875
10876 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10877         .f = cmd_set_vf_mac_anti_spoof_parsed,
10878         .data = NULL,
10879         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10880         .tokens = {
10881                 (void *)&cmd_vf_mac_anti_spoof_set,
10882                 (void *)&cmd_vf_mac_anti_spoof_vf,
10883                 (void *)&cmd_vf_mac_anti_spoof_mac,
10884                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10885                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10886                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10887                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10888                 NULL,
10889         },
10890 };
10891
10892 /* vf vlan strip queue configuration */
10893
10894 /* Common result structure for vf mac anti spoof */
10895 struct cmd_vf_vlan_stripq_result {
10896         cmdline_fixed_string_t set;
10897         cmdline_fixed_string_t vf;
10898         cmdline_fixed_string_t vlan;
10899         cmdline_fixed_string_t stripq;
10900         portid_t port_id;
10901         uint16_t vf_id;
10902         cmdline_fixed_string_t on_off;
10903 };
10904
10905 /* Common CLI fields for vf vlan strip enable disable */
10906 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10907         TOKEN_STRING_INITIALIZER
10908                 (struct cmd_vf_vlan_stripq_result,
10909                  set, "set");
10910 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10911         TOKEN_STRING_INITIALIZER
10912                 (struct cmd_vf_vlan_stripq_result,
10913                  vf, "vf");
10914 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10915         TOKEN_STRING_INITIALIZER
10916                 (struct cmd_vf_vlan_stripq_result,
10917                  vlan, "vlan");
10918 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10919         TOKEN_STRING_INITIALIZER
10920                 (struct cmd_vf_vlan_stripq_result,
10921                  stripq, "stripq");
10922 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10923         TOKEN_NUM_INITIALIZER
10924                 (struct cmd_vf_vlan_stripq_result,
10925                  port_id, RTE_UINT16);
10926 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10927         TOKEN_NUM_INITIALIZER
10928                 (struct cmd_vf_vlan_stripq_result,
10929                  vf_id, RTE_UINT16);
10930 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10931         TOKEN_STRING_INITIALIZER
10932                 (struct cmd_vf_vlan_stripq_result,
10933                  on_off, "on#off");
10934
10935 static void
10936 cmd_set_vf_vlan_stripq_parsed(
10937         void *parsed_result,
10938         __rte_unused struct cmdline *cl,
10939         __rte_unused void *data)
10940 {
10941         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10942         int ret = -ENOTSUP;
10943
10944         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10945
10946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10947                 return;
10948
10949 #ifdef RTE_NET_IXGBE
10950         if (ret == -ENOTSUP)
10951                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10952                         res->vf_id, is_on);
10953 #endif
10954 #ifdef RTE_NET_I40E
10955         if (ret == -ENOTSUP)
10956                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10957                         res->vf_id, is_on);
10958 #endif
10959 #ifdef RTE_NET_BNXT
10960         if (ret == -ENOTSUP)
10961                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10962                         res->vf_id, is_on);
10963 #endif
10964
10965         switch (ret) {
10966         case 0:
10967                 break;
10968         case -EINVAL:
10969                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10970                 break;
10971         case -ENODEV:
10972                 printf("invalid port_id %d\n", res->port_id);
10973                 break;
10974         case -ENOTSUP:
10975                 printf("function not implemented\n");
10976                 break;
10977         default:
10978                 printf("programming error: (%s)\n", strerror(-ret));
10979         }
10980 }
10981
10982 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10983         .f = cmd_set_vf_vlan_stripq_parsed,
10984         .data = NULL,
10985         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10986         .tokens = {
10987                 (void *)&cmd_vf_vlan_stripq_set,
10988                 (void *)&cmd_vf_vlan_stripq_vf,
10989                 (void *)&cmd_vf_vlan_stripq_vlan,
10990                 (void *)&cmd_vf_vlan_stripq_stripq,
10991                 (void *)&cmd_vf_vlan_stripq_port_id,
10992                 (void *)&cmd_vf_vlan_stripq_vf_id,
10993                 (void *)&cmd_vf_vlan_stripq_on_off,
10994                 NULL,
10995         },
10996 };
10997
10998 /* vf vlan insert configuration */
10999
11000 /* Common result structure for vf vlan insert */
11001 struct cmd_vf_vlan_insert_result {
11002         cmdline_fixed_string_t set;
11003         cmdline_fixed_string_t vf;
11004         cmdline_fixed_string_t vlan;
11005         cmdline_fixed_string_t insert;
11006         portid_t port_id;
11007         uint16_t vf_id;
11008         uint16_t vlan_id;
11009 };
11010
11011 /* Common CLI fields for vf vlan insert enable disable */
11012 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11013         TOKEN_STRING_INITIALIZER
11014                 (struct cmd_vf_vlan_insert_result,
11015                  set, "set");
11016 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11017         TOKEN_STRING_INITIALIZER
11018                 (struct cmd_vf_vlan_insert_result,
11019                  vf, "vf");
11020 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11021         TOKEN_STRING_INITIALIZER
11022                 (struct cmd_vf_vlan_insert_result,
11023                  vlan, "vlan");
11024 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11025         TOKEN_STRING_INITIALIZER
11026                 (struct cmd_vf_vlan_insert_result,
11027                  insert, "insert");
11028 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11029         TOKEN_NUM_INITIALIZER
11030                 (struct cmd_vf_vlan_insert_result,
11031                  port_id, RTE_UINT16);
11032 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11033         TOKEN_NUM_INITIALIZER
11034                 (struct cmd_vf_vlan_insert_result,
11035                  vf_id, RTE_UINT16);
11036 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11037         TOKEN_NUM_INITIALIZER
11038                 (struct cmd_vf_vlan_insert_result,
11039                  vlan_id, RTE_UINT16);
11040
11041 static void
11042 cmd_set_vf_vlan_insert_parsed(
11043         void *parsed_result,
11044         __rte_unused struct cmdline *cl,
11045         __rte_unused void *data)
11046 {
11047         struct cmd_vf_vlan_insert_result *res = parsed_result;
11048         int ret = -ENOTSUP;
11049
11050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11051                 return;
11052
11053 #ifdef RTE_NET_IXGBE
11054         if (ret == -ENOTSUP)
11055                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11056                         res->vlan_id);
11057 #endif
11058 #ifdef RTE_NET_I40E
11059         if (ret == -ENOTSUP)
11060                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11061                         res->vlan_id);
11062 #endif
11063 #ifdef RTE_NET_BNXT
11064         if (ret == -ENOTSUP)
11065                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11066                         res->vlan_id);
11067 #endif
11068
11069         switch (ret) {
11070         case 0:
11071                 break;
11072         case -EINVAL:
11073                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11074                 break;
11075         case -ENODEV:
11076                 printf("invalid port_id %d\n", res->port_id);
11077                 break;
11078         case -ENOTSUP:
11079                 printf("function not implemented\n");
11080                 break;
11081         default:
11082                 printf("programming error: (%s)\n", strerror(-ret));
11083         }
11084 }
11085
11086 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11087         .f = cmd_set_vf_vlan_insert_parsed,
11088         .data = NULL,
11089         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11090         .tokens = {
11091                 (void *)&cmd_vf_vlan_insert_set,
11092                 (void *)&cmd_vf_vlan_insert_vf,
11093                 (void *)&cmd_vf_vlan_insert_vlan,
11094                 (void *)&cmd_vf_vlan_insert_insert,
11095                 (void *)&cmd_vf_vlan_insert_port_id,
11096                 (void *)&cmd_vf_vlan_insert_vf_id,
11097                 (void *)&cmd_vf_vlan_insert_vlan_id,
11098                 NULL,
11099         },
11100 };
11101
11102 /* tx loopback configuration */
11103
11104 /* Common result structure for tx loopback */
11105 struct cmd_tx_loopback_result {
11106         cmdline_fixed_string_t set;
11107         cmdline_fixed_string_t tx;
11108         cmdline_fixed_string_t loopback;
11109         portid_t port_id;
11110         cmdline_fixed_string_t on_off;
11111 };
11112
11113 /* Common CLI fields for tx loopback enable disable */
11114 cmdline_parse_token_string_t cmd_tx_loopback_set =
11115         TOKEN_STRING_INITIALIZER
11116                 (struct cmd_tx_loopback_result,
11117                  set, "set");
11118 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11119         TOKEN_STRING_INITIALIZER
11120                 (struct cmd_tx_loopback_result,
11121                  tx, "tx");
11122 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11123         TOKEN_STRING_INITIALIZER
11124                 (struct cmd_tx_loopback_result,
11125                  loopback, "loopback");
11126 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11127         TOKEN_NUM_INITIALIZER
11128                 (struct cmd_tx_loopback_result,
11129                  port_id, RTE_UINT16);
11130 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11131         TOKEN_STRING_INITIALIZER
11132                 (struct cmd_tx_loopback_result,
11133                  on_off, "on#off");
11134
11135 static void
11136 cmd_set_tx_loopback_parsed(
11137         void *parsed_result,
11138         __rte_unused struct cmdline *cl,
11139         __rte_unused void *data)
11140 {
11141         struct cmd_tx_loopback_result *res = parsed_result;
11142         int ret = -ENOTSUP;
11143
11144         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11145
11146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11147                 return;
11148
11149 #ifdef RTE_NET_IXGBE
11150         if (ret == -ENOTSUP)
11151                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11152 #endif
11153 #ifdef RTE_NET_I40E
11154         if (ret == -ENOTSUP)
11155                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11156 #endif
11157 #ifdef RTE_NET_BNXT
11158         if (ret == -ENOTSUP)
11159                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11160 #endif
11161 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11162         if (ret == -ENOTSUP)
11163                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11164 #endif
11165
11166         switch (ret) {
11167         case 0:
11168                 break;
11169         case -EINVAL:
11170                 printf("invalid is_on %d\n", is_on);
11171                 break;
11172         case -ENODEV:
11173                 printf("invalid port_id %d\n", res->port_id);
11174                 break;
11175         case -ENOTSUP:
11176                 printf("function not implemented\n");
11177                 break;
11178         default:
11179                 printf("programming error: (%s)\n", strerror(-ret));
11180         }
11181 }
11182
11183 cmdline_parse_inst_t cmd_set_tx_loopback = {
11184         .f = cmd_set_tx_loopback_parsed,
11185         .data = NULL,
11186         .help_str = "set tx loopback <port_id> on|off",
11187         .tokens = {
11188                 (void *)&cmd_tx_loopback_set,
11189                 (void *)&cmd_tx_loopback_tx,
11190                 (void *)&cmd_tx_loopback_loopback,
11191                 (void *)&cmd_tx_loopback_port_id,
11192                 (void *)&cmd_tx_loopback_on_off,
11193                 NULL,
11194         },
11195 };
11196
11197 /* all queues drop enable configuration */
11198
11199 /* Common result structure for all queues drop enable */
11200 struct cmd_all_queues_drop_en_result {
11201         cmdline_fixed_string_t set;
11202         cmdline_fixed_string_t all;
11203         cmdline_fixed_string_t queues;
11204         cmdline_fixed_string_t drop;
11205         portid_t port_id;
11206         cmdline_fixed_string_t on_off;
11207 };
11208
11209 /* Common CLI fields for tx loopback enable disable */
11210 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11211         TOKEN_STRING_INITIALIZER
11212                 (struct cmd_all_queues_drop_en_result,
11213                  set, "set");
11214 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11215         TOKEN_STRING_INITIALIZER
11216                 (struct cmd_all_queues_drop_en_result,
11217                  all, "all");
11218 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11219         TOKEN_STRING_INITIALIZER
11220                 (struct cmd_all_queues_drop_en_result,
11221                  queues, "queues");
11222 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11223         TOKEN_STRING_INITIALIZER
11224                 (struct cmd_all_queues_drop_en_result,
11225                  drop, "drop");
11226 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11227         TOKEN_NUM_INITIALIZER
11228                 (struct cmd_all_queues_drop_en_result,
11229                  port_id, RTE_UINT16);
11230 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11231         TOKEN_STRING_INITIALIZER
11232                 (struct cmd_all_queues_drop_en_result,
11233                  on_off, "on#off");
11234
11235 static void
11236 cmd_set_all_queues_drop_en_parsed(
11237         void *parsed_result,
11238         __rte_unused struct cmdline *cl,
11239         __rte_unused void *data)
11240 {
11241         struct cmd_all_queues_drop_en_result *res = parsed_result;
11242         int ret = -ENOTSUP;
11243         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11244
11245         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11246                 return;
11247
11248 #ifdef RTE_NET_IXGBE
11249         if (ret == -ENOTSUP)
11250                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11251 #endif
11252 #ifdef RTE_NET_BNXT
11253         if (ret == -ENOTSUP)
11254                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11255 #endif
11256         switch (ret) {
11257         case 0:
11258                 break;
11259         case -EINVAL:
11260                 printf("invalid is_on %d\n", is_on);
11261                 break;
11262         case -ENODEV:
11263                 printf("invalid port_id %d\n", res->port_id);
11264                 break;
11265         case -ENOTSUP:
11266                 printf("function not implemented\n");
11267                 break;
11268         default:
11269                 printf("programming error: (%s)\n", strerror(-ret));
11270         }
11271 }
11272
11273 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11274         .f = cmd_set_all_queues_drop_en_parsed,
11275         .data = NULL,
11276         .help_str = "set all queues drop <port_id> on|off",
11277         .tokens = {
11278                 (void *)&cmd_all_queues_drop_en_set,
11279                 (void *)&cmd_all_queues_drop_en_all,
11280                 (void *)&cmd_all_queues_drop_en_queues,
11281                 (void *)&cmd_all_queues_drop_en_drop,
11282                 (void *)&cmd_all_queues_drop_en_port_id,
11283                 (void *)&cmd_all_queues_drop_en_on_off,
11284                 NULL,
11285         },
11286 };
11287
11288 /* vf split drop enable configuration */
11289
11290 /* Common result structure for vf split drop enable */
11291 struct cmd_vf_split_drop_en_result {
11292         cmdline_fixed_string_t set;
11293         cmdline_fixed_string_t vf;
11294         cmdline_fixed_string_t split;
11295         cmdline_fixed_string_t drop;
11296         portid_t port_id;
11297         uint16_t vf_id;
11298         cmdline_fixed_string_t on_off;
11299 };
11300
11301 /* Common CLI fields for vf split drop enable disable */
11302 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11303         TOKEN_STRING_INITIALIZER
11304                 (struct cmd_vf_split_drop_en_result,
11305                  set, "set");
11306 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11307         TOKEN_STRING_INITIALIZER
11308                 (struct cmd_vf_split_drop_en_result,
11309                  vf, "vf");
11310 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11311         TOKEN_STRING_INITIALIZER
11312                 (struct cmd_vf_split_drop_en_result,
11313                  split, "split");
11314 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11315         TOKEN_STRING_INITIALIZER
11316                 (struct cmd_vf_split_drop_en_result,
11317                  drop, "drop");
11318 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11319         TOKEN_NUM_INITIALIZER
11320                 (struct cmd_vf_split_drop_en_result,
11321                  port_id, RTE_UINT16);
11322 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11323         TOKEN_NUM_INITIALIZER
11324                 (struct cmd_vf_split_drop_en_result,
11325                  vf_id, RTE_UINT16);
11326 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11327         TOKEN_STRING_INITIALIZER
11328                 (struct cmd_vf_split_drop_en_result,
11329                  on_off, "on#off");
11330
11331 static void
11332 cmd_set_vf_split_drop_en_parsed(
11333         void *parsed_result,
11334         __rte_unused struct cmdline *cl,
11335         __rte_unused void *data)
11336 {
11337         struct cmd_vf_split_drop_en_result *res = parsed_result;
11338         int ret = -ENOTSUP;
11339         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11340
11341         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11342                 return;
11343
11344 #ifdef RTE_NET_IXGBE
11345         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11346                         is_on);
11347 #endif
11348         switch (ret) {
11349         case 0:
11350                 break;
11351         case -EINVAL:
11352                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11353                 break;
11354         case -ENODEV:
11355                 printf("invalid port_id %d\n", res->port_id);
11356                 break;
11357         case -ENOTSUP:
11358                 printf("not supported on port %d\n", res->port_id);
11359                 break;
11360         default:
11361                 printf("programming error: (%s)\n", strerror(-ret));
11362         }
11363 }
11364
11365 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11366         .f = cmd_set_vf_split_drop_en_parsed,
11367         .data = NULL,
11368         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11369         .tokens = {
11370                 (void *)&cmd_vf_split_drop_en_set,
11371                 (void *)&cmd_vf_split_drop_en_vf,
11372                 (void *)&cmd_vf_split_drop_en_split,
11373                 (void *)&cmd_vf_split_drop_en_drop,
11374                 (void *)&cmd_vf_split_drop_en_port_id,
11375                 (void *)&cmd_vf_split_drop_en_vf_id,
11376                 (void *)&cmd_vf_split_drop_en_on_off,
11377                 NULL,
11378         },
11379 };
11380
11381 /* vf mac address configuration */
11382
11383 /* Common result structure for vf mac address */
11384 struct cmd_set_vf_mac_addr_result {
11385         cmdline_fixed_string_t set;
11386         cmdline_fixed_string_t vf;
11387         cmdline_fixed_string_t mac;
11388         cmdline_fixed_string_t addr;
11389         portid_t port_id;
11390         uint16_t vf_id;
11391         struct rte_ether_addr mac_addr;
11392
11393 };
11394
11395 /* Common CLI fields for vf split drop enable disable */
11396 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11397         TOKEN_STRING_INITIALIZER
11398                 (struct cmd_set_vf_mac_addr_result,
11399                  set, "set");
11400 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11401         TOKEN_STRING_INITIALIZER
11402                 (struct cmd_set_vf_mac_addr_result,
11403                  vf, "vf");
11404 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11405         TOKEN_STRING_INITIALIZER
11406                 (struct cmd_set_vf_mac_addr_result,
11407                  mac, "mac");
11408 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11409         TOKEN_STRING_INITIALIZER
11410                 (struct cmd_set_vf_mac_addr_result,
11411                  addr, "addr");
11412 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11413         TOKEN_NUM_INITIALIZER
11414                 (struct cmd_set_vf_mac_addr_result,
11415                  port_id, RTE_UINT16);
11416 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11417         TOKEN_NUM_INITIALIZER
11418                 (struct cmd_set_vf_mac_addr_result,
11419                  vf_id, RTE_UINT16);
11420 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11421         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11422                  mac_addr);
11423
11424 static void
11425 cmd_set_vf_mac_addr_parsed(
11426         void *parsed_result,
11427         __rte_unused struct cmdline *cl,
11428         __rte_unused void *data)
11429 {
11430         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11431         int ret = -ENOTSUP;
11432
11433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11434                 return;
11435
11436 #ifdef RTE_NET_IXGBE
11437         if (ret == -ENOTSUP)
11438                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11439                                 &res->mac_addr);
11440 #endif
11441 #ifdef RTE_NET_I40E
11442         if (ret == -ENOTSUP)
11443                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11444                                 &res->mac_addr);
11445 #endif
11446 #ifdef RTE_NET_BNXT
11447         if (ret == -ENOTSUP)
11448                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11449                                 &res->mac_addr);
11450 #endif
11451
11452         switch (ret) {
11453         case 0:
11454                 break;
11455         case -EINVAL:
11456                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11457                 break;
11458         case -ENODEV:
11459                 printf("invalid port_id %d\n", res->port_id);
11460                 break;
11461         case -ENOTSUP:
11462                 printf("function not implemented\n");
11463                 break;
11464         default:
11465                 printf("programming error: (%s)\n", strerror(-ret));
11466         }
11467 }
11468
11469 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11470         .f = cmd_set_vf_mac_addr_parsed,
11471         .data = NULL,
11472         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11473         .tokens = {
11474                 (void *)&cmd_set_vf_mac_addr_set,
11475                 (void *)&cmd_set_vf_mac_addr_vf,
11476                 (void *)&cmd_set_vf_mac_addr_mac,
11477                 (void *)&cmd_set_vf_mac_addr_addr,
11478                 (void *)&cmd_set_vf_mac_addr_port_id,
11479                 (void *)&cmd_set_vf_mac_addr_vf_id,
11480                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11481                 NULL,
11482         },
11483 };
11484
11485 /* MACsec configuration */
11486
11487 /* Common result structure for MACsec offload enable */
11488 struct cmd_macsec_offload_on_result {
11489         cmdline_fixed_string_t set;
11490         cmdline_fixed_string_t macsec;
11491         cmdline_fixed_string_t offload;
11492         portid_t port_id;
11493         cmdline_fixed_string_t on;
11494         cmdline_fixed_string_t encrypt;
11495         cmdline_fixed_string_t en_on_off;
11496         cmdline_fixed_string_t replay_protect;
11497         cmdline_fixed_string_t rp_on_off;
11498 };
11499
11500 /* Common CLI fields for MACsec offload disable */
11501 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_macsec_offload_on_result,
11504                  set, "set");
11505 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_macsec_offload_on_result,
11508                  macsec, "macsec");
11509 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_macsec_offload_on_result,
11512                  offload, "offload");
11513 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11514         TOKEN_NUM_INITIALIZER
11515                 (struct cmd_macsec_offload_on_result,
11516                  port_id, RTE_UINT16);
11517 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_macsec_offload_on_result,
11520                  on, "on");
11521 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_macsec_offload_on_result,
11524                  encrypt, "encrypt");
11525 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11526         TOKEN_STRING_INITIALIZER
11527                 (struct cmd_macsec_offload_on_result,
11528                  en_on_off, "on#off");
11529 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11530         TOKEN_STRING_INITIALIZER
11531                 (struct cmd_macsec_offload_on_result,
11532                  replay_protect, "replay-protect");
11533 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11534         TOKEN_STRING_INITIALIZER
11535                 (struct cmd_macsec_offload_on_result,
11536                  rp_on_off, "on#off");
11537
11538 static void
11539 cmd_set_macsec_offload_on_parsed(
11540         void *parsed_result,
11541         __rte_unused struct cmdline *cl,
11542         __rte_unused void *data)
11543 {
11544         struct cmd_macsec_offload_on_result *res = parsed_result;
11545         int ret = -ENOTSUP;
11546         portid_t port_id = res->port_id;
11547         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11548         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11549         struct rte_eth_dev_info dev_info;
11550
11551         if (port_id_is_invalid(port_id, ENABLED_WARN))
11552                 return;
11553         if (!port_is_stopped(port_id)) {
11554                 printf("Please stop port %d first\n", port_id);
11555                 return;
11556         }
11557
11558         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11559         if (ret != 0)
11560                 return;
11561
11562         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11563 #ifdef RTE_NET_IXGBE
11564                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11565 #endif
11566         }
11567         RTE_SET_USED(en);
11568         RTE_SET_USED(rp);
11569
11570         switch (ret) {
11571         case 0:
11572                 ports[port_id].dev_conf.txmode.offloads |=
11573                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11574                 cmd_reconfig_device_queue(port_id, 1, 1);
11575                 break;
11576         case -ENODEV:
11577                 printf("invalid port_id %d\n", port_id);
11578                 break;
11579         case -ENOTSUP:
11580                 printf("not supported on port %d\n", port_id);
11581                 break;
11582         default:
11583                 printf("programming error: (%s)\n", strerror(-ret));
11584         }
11585 }
11586
11587 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11588         .f = cmd_set_macsec_offload_on_parsed,
11589         .data = NULL,
11590         .help_str = "set macsec offload <port_id> on "
11591                 "encrypt on|off replay-protect on|off",
11592         .tokens = {
11593                 (void *)&cmd_macsec_offload_on_set,
11594                 (void *)&cmd_macsec_offload_on_macsec,
11595                 (void *)&cmd_macsec_offload_on_offload,
11596                 (void *)&cmd_macsec_offload_on_port_id,
11597                 (void *)&cmd_macsec_offload_on_on,
11598                 (void *)&cmd_macsec_offload_on_encrypt,
11599                 (void *)&cmd_macsec_offload_on_en_on_off,
11600                 (void *)&cmd_macsec_offload_on_replay_protect,
11601                 (void *)&cmd_macsec_offload_on_rp_on_off,
11602                 NULL,
11603         },
11604 };
11605
11606 /* Common result structure for MACsec offload disable */
11607 struct cmd_macsec_offload_off_result {
11608         cmdline_fixed_string_t set;
11609         cmdline_fixed_string_t macsec;
11610         cmdline_fixed_string_t offload;
11611         portid_t port_id;
11612         cmdline_fixed_string_t off;
11613 };
11614
11615 /* Common CLI fields for MACsec offload disable */
11616 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11617         TOKEN_STRING_INITIALIZER
11618                 (struct cmd_macsec_offload_off_result,
11619                  set, "set");
11620 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11621         TOKEN_STRING_INITIALIZER
11622                 (struct cmd_macsec_offload_off_result,
11623                  macsec, "macsec");
11624 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11625         TOKEN_STRING_INITIALIZER
11626                 (struct cmd_macsec_offload_off_result,
11627                  offload, "offload");
11628 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11629         TOKEN_NUM_INITIALIZER
11630                 (struct cmd_macsec_offload_off_result,
11631                  port_id, RTE_UINT16);
11632 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11633         TOKEN_STRING_INITIALIZER
11634                 (struct cmd_macsec_offload_off_result,
11635                  off, "off");
11636
11637 static void
11638 cmd_set_macsec_offload_off_parsed(
11639         void *parsed_result,
11640         __rte_unused struct cmdline *cl,
11641         __rte_unused void *data)
11642 {
11643         struct cmd_macsec_offload_off_result *res = parsed_result;
11644         int ret = -ENOTSUP;
11645         struct rte_eth_dev_info dev_info;
11646         portid_t port_id = res->port_id;
11647
11648         if (port_id_is_invalid(port_id, ENABLED_WARN))
11649                 return;
11650         if (!port_is_stopped(port_id)) {
11651                 printf("Please stop port %d first\n", port_id);
11652                 return;
11653         }
11654
11655         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11656         if (ret != 0)
11657                 return;
11658
11659         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11660 #ifdef RTE_NET_IXGBE
11661                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11662 #endif
11663         }
11664         switch (ret) {
11665         case 0:
11666                 ports[port_id].dev_conf.txmode.offloads &=
11667                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11668                 cmd_reconfig_device_queue(port_id, 1, 1);
11669                 break;
11670         case -ENODEV:
11671                 printf("invalid port_id %d\n", port_id);
11672                 break;
11673         case -ENOTSUP:
11674                 printf("not supported on port %d\n", port_id);
11675                 break;
11676         default:
11677                 printf("programming error: (%s)\n", strerror(-ret));
11678         }
11679 }
11680
11681 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11682         .f = cmd_set_macsec_offload_off_parsed,
11683         .data = NULL,
11684         .help_str = "set macsec offload <port_id> off",
11685         .tokens = {
11686                 (void *)&cmd_macsec_offload_off_set,
11687                 (void *)&cmd_macsec_offload_off_macsec,
11688                 (void *)&cmd_macsec_offload_off_offload,
11689                 (void *)&cmd_macsec_offload_off_port_id,
11690                 (void *)&cmd_macsec_offload_off_off,
11691                 NULL,
11692         },
11693 };
11694
11695 /* Common result structure for MACsec secure connection configure */
11696 struct cmd_macsec_sc_result {
11697         cmdline_fixed_string_t set;
11698         cmdline_fixed_string_t macsec;
11699         cmdline_fixed_string_t sc;
11700         cmdline_fixed_string_t tx_rx;
11701         portid_t port_id;
11702         struct rte_ether_addr mac;
11703         uint16_t pi;
11704 };
11705
11706 /* Common CLI fields for MACsec secure connection configure */
11707 cmdline_parse_token_string_t cmd_macsec_sc_set =
11708         TOKEN_STRING_INITIALIZER
11709                 (struct cmd_macsec_sc_result,
11710                  set, "set");
11711 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11712         TOKEN_STRING_INITIALIZER
11713                 (struct cmd_macsec_sc_result,
11714                  macsec, "macsec");
11715 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11716         TOKEN_STRING_INITIALIZER
11717                 (struct cmd_macsec_sc_result,
11718                  sc, "sc");
11719 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11720         TOKEN_STRING_INITIALIZER
11721                 (struct cmd_macsec_sc_result,
11722                  tx_rx, "tx#rx");
11723 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11724         TOKEN_NUM_INITIALIZER
11725                 (struct cmd_macsec_sc_result,
11726                  port_id, RTE_UINT16);
11727 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11728         TOKEN_ETHERADDR_INITIALIZER
11729                 (struct cmd_macsec_sc_result,
11730                  mac);
11731 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11732         TOKEN_NUM_INITIALIZER
11733                 (struct cmd_macsec_sc_result,
11734                  pi, RTE_UINT16);
11735
11736 static void
11737 cmd_set_macsec_sc_parsed(
11738         void *parsed_result,
11739         __rte_unused struct cmdline *cl,
11740         __rte_unused void *data)
11741 {
11742         struct cmd_macsec_sc_result *res = parsed_result;
11743         int ret = -ENOTSUP;
11744         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11745
11746 #ifdef RTE_NET_IXGBE
11747         ret = is_tx ?
11748                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11749                                 res->mac.addr_bytes) :
11750                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11751                                 res->mac.addr_bytes, res->pi);
11752 #endif
11753         RTE_SET_USED(is_tx);
11754
11755         switch (ret) {
11756         case 0:
11757                 break;
11758         case -ENODEV:
11759                 printf("invalid port_id %d\n", res->port_id);
11760                 break;
11761         case -ENOTSUP:
11762                 printf("not supported on port %d\n", res->port_id);
11763                 break;
11764         default:
11765                 printf("programming error: (%s)\n", strerror(-ret));
11766         }
11767 }
11768
11769 cmdline_parse_inst_t cmd_set_macsec_sc = {
11770         .f = cmd_set_macsec_sc_parsed,
11771         .data = NULL,
11772         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11773         .tokens = {
11774                 (void *)&cmd_macsec_sc_set,
11775                 (void *)&cmd_macsec_sc_macsec,
11776                 (void *)&cmd_macsec_sc_sc,
11777                 (void *)&cmd_macsec_sc_tx_rx,
11778                 (void *)&cmd_macsec_sc_port_id,
11779                 (void *)&cmd_macsec_sc_mac,
11780                 (void *)&cmd_macsec_sc_pi,
11781                 NULL,
11782         },
11783 };
11784
11785 /* Common result structure for MACsec secure connection configure */
11786 struct cmd_macsec_sa_result {
11787         cmdline_fixed_string_t set;
11788         cmdline_fixed_string_t macsec;
11789         cmdline_fixed_string_t sa;
11790         cmdline_fixed_string_t tx_rx;
11791         portid_t port_id;
11792         uint8_t idx;
11793         uint8_t an;
11794         uint32_t pn;
11795         cmdline_fixed_string_t key;
11796 };
11797
11798 /* Common CLI fields for MACsec secure connection configure */
11799 cmdline_parse_token_string_t cmd_macsec_sa_set =
11800         TOKEN_STRING_INITIALIZER
11801                 (struct cmd_macsec_sa_result,
11802                  set, "set");
11803 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11804         TOKEN_STRING_INITIALIZER
11805                 (struct cmd_macsec_sa_result,
11806                  macsec, "macsec");
11807 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11808         TOKEN_STRING_INITIALIZER
11809                 (struct cmd_macsec_sa_result,
11810                  sa, "sa");
11811 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11812         TOKEN_STRING_INITIALIZER
11813                 (struct cmd_macsec_sa_result,
11814                  tx_rx, "tx#rx");
11815 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11816         TOKEN_NUM_INITIALIZER
11817                 (struct cmd_macsec_sa_result,
11818                  port_id, RTE_UINT16);
11819 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11820         TOKEN_NUM_INITIALIZER
11821                 (struct cmd_macsec_sa_result,
11822                  idx, RTE_UINT8);
11823 cmdline_parse_token_num_t cmd_macsec_sa_an =
11824         TOKEN_NUM_INITIALIZER
11825                 (struct cmd_macsec_sa_result,
11826                  an, RTE_UINT8);
11827 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11828         TOKEN_NUM_INITIALIZER
11829                 (struct cmd_macsec_sa_result,
11830                  pn, RTE_UINT32);
11831 cmdline_parse_token_string_t cmd_macsec_sa_key =
11832         TOKEN_STRING_INITIALIZER
11833                 (struct cmd_macsec_sa_result,
11834                  key, NULL);
11835
11836 static void
11837 cmd_set_macsec_sa_parsed(
11838         void *parsed_result,
11839         __rte_unused struct cmdline *cl,
11840         __rte_unused void *data)
11841 {
11842         struct cmd_macsec_sa_result *res = parsed_result;
11843         int ret = -ENOTSUP;
11844         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11845         uint8_t key[16] = { 0 };
11846         uint8_t xdgt0;
11847         uint8_t xdgt1;
11848         int key_len;
11849         int i;
11850
11851         key_len = strlen(res->key) / 2;
11852         if (key_len > 16)
11853                 key_len = 16;
11854
11855         for (i = 0; i < key_len; i++) {
11856                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11857                 if (xdgt0 == 0xFF)
11858                         return;
11859                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11860                 if (xdgt1 == 0xFF)
11861                         return;
11862                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11863         }
11864
11865 #ifdef RTE_NET_IXGBE
11866         ret = is_tx ?
11867                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11868                         res->idx, res->an, res->pn, key) :
11869                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11870                         res->idx, res->an, res->pn, key);
11871 #endif
11872         RTE_SET_USED(is_tx);
11873         RTE_SET_USED(key);
11874
11875         switch (ret) {
11876         case 0:
11877                 break;
11878         case -EINVAL:
11879                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11880                 break;
11881         case -ENODEV:
11882                 printf("invalid port_id %d\n", res->port_id);
11883                 break;
11884         case -ENOTSUP:
11885                 printf("not supported on port %d\n", res->port_id);
11886                 break;
11887         default:
11888                 printf("programming error: (%s)\n", strerror(-ret));
11889         }
11890 }
11891
11892 cmdline_parse_inst_t cmd_set_macsec_sa = {
11893         .f = cmd_set_macsec_sa_parsed,
11894         .data = NULL,
11895         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11896         .tokens = {
11897                 (void *)&cmd_macsec_sa_set,
11898                 (void *)&cmd_macsec_sa_macsec,
11899                 (void *)&cmd_macsec_sa_sa,
11900                 (void *)&cmd_macsec_sa_tx_rx,
11901                 (void *)&cmd_macsec_sa_port_id,
11902                 (void *)&cmd_macsec_sa_idx,
11903                 (void *)&cmd_macsec_sa_an,
11904                 (void *)&cmd_macsec_sa_pn,
11905                 (void *)&cmd_macsec_sa_key,
11906                 NULL,
11907         },
11908 };
11909
11910 /* VF unicast promiscuous mode configuration */
11911
11912 /* Common result structure for VF unicast promiscuous mode */
11913 struct cmd_vf_promisc_result {
11914         cmdline_fixed_string_t set;
11915         cmdline_fixed_string_t vf;
11916         cmdline_fixed_string_t promisc;
11917         portid_t port_id;
11918         uint32_t vf_id;
11919         cmdline_fixed_string_t on_off;
11920 };
11921
11922 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11923 cmdline_parse_token_string_t cmd_vf_promisc_set =
11924         TOKEN_STRING_INITIALIZER
11925                 (struct cmd_vf_promisc_result,
11926                  set, "set");
11927 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11928         TOKEN_STRING_INITIALIZER
11929                 (struct cmd_vf_promisc_result,
11930                  vf, "vf");
11931 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11932         TOKEN_STRING_INITIALIZER
11933                 (struct cmd_vf_promisc_result,
11934                  promisc, "promisc");
11935 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11936         TOKEN_NUM_INITIALIZER
11937                 (struct cmd_vf_promisc_result,
11938                  port_id, RTE_UINT16);
11939 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11940         TOKEN_NUM_INITIALIZER
11941                 (struct cmd_vf_promisc_result,
11942                  vf_id, RTE_UINT32);
11943 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11944         TOKEN_STRING_INITIALIZER
11945                 (struct cmd_vf_promisc_result,
11946                  on_off, "on#off");
11947
11948 static void
11949 cmd_set_vf_promisc_parsed(
11950         void *parsed_result,
11951         __rte_unused struct cmdline *cl,
11952         __rte_unused void *data)
11953 {
11954         struct cmd_vf_promisc_result *res = parsed_result;
11955         int ret = -ENOTSUP;
11956
11957         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11958
11959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11960                 return;
11961
11962 #ifdef RTE_NET_I40E
11963         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11964                                                   res->vf_id, is_on);
11965 #endif
11966
11967         switch (ret) {
11968         case 0:
11969                 break;
11970         case -EINVAL:
11971                 printf("invalid vf_id %d\n", res->vf_id);
11972                 break;
11973         case -ENODEV:
11974                 printf("invalid port_id %d\n", res->port_id);
11975                 break;
11976         case -ENOTSUP:
11977                 printf("function not implemented\n");
11978                 break;
11979         default:
11980                 printf("programming error: (%s)\n", strerror(-ret));
11981         }
11982 }
11983
11984 cmdline_parse_inst_t cmd_set_vf_promisc = {
11985         .f = cmd_set_vf_promisc_parsed,
11986         .data = NULL,
11987         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11988                 "Set unicast promiscuous mode for a VF from the PF",
11989         .tokens = {
11990                 (void *)&cmd_vf_promisc_set,
11991                 (void *)&cmd_vf_promisc_vf,
11992                 (void *)&cmd_vf_promisc_promisc,
11993                 (void *)&cmd_vf_promisc_port_id,
11994                 (void *)&cmd_vf_promisc_vf_id,
11995                 (void *)&cmd_vf_promisc_on_off,
11996                 NULL,
11997         },
11998 };
11999
12000 /* VF multicast promiscuous mode configuration */
12001
12002 /* Common result structure for VF multicast promiscuous mode */
12003 struct cmd_vf_allmulti_result {
12004         cmdline_fixed_string_t set;
12005         cmdline_fixed_string_t vf;
12006         cmdline_fixed_string_t allmulti;
12007         portid_t port_id;
12008         uint32_t vf_id;
12009         cmdline_fixed_string_t on_off;
12010 };
12011
12012 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12013 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12014         TOKEN_STRING_INITIALIZER
12015                 (struct cmd_vf_allmulti_result,
12016                  set, "set");
12017 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12018         TOKEN_STRING_INITIALIZER
12019                 (struct cmd_vf_allmulti_result,
12020                  vf, "vf");
12021 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12022         TOKEN_STRING_INITIALIZER
12023                 (struct cmd_vf_allmulti_result,
12024                  allmulti, "allmulti");
12025 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12026         TOKEN_NUM_INITIALIZER
12027                 (struct cmd_vf_allmulti_result,
12028                  port_id, RTE_UINT16);
12029 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12030         TOKEN_NUM_INITIALIZER
12031                 (struct cmd_vf_allmulti_result,
12032                  vf_id, RTE_UINT32);
12033 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12034         TOKEN_STRING_INITIALIZER
12035                 (struct cmd_vf_allmulti_result,
12036                  on_off, "on#off");
12037
12038 static void
12039 cmd_set_vf_allmulti_parsed(
12040         void *parsed_result,
12041         __rte_unused struct cmdline *cl,
12042         __rte_unused void *data)
12043 {
12044         struct cmd_vf_allmulti_result *res = parsed_result;
12045         int ret = -ENOTSUP;
12046
12047         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12048
12049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12050                 return;
12051
12052 #ifdef RTE_NET_I40E
12053         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12054                                                     res->vf_id, is_on);
12055 #endif
12056
12057         switch (ret) {
12058         case 0:
12059                 break;
12060         case -EINVAL:
12061                 printf("invalid vf_id %d\n", res->vf_id);
12062                 break;
12063         case -ENODEV:
12064                 printf("invalid port_id %d\n", res->port_id);
12065                 break;
12066         case -ENOTSUP:
12067                 printf("function not implemented\n");
12068                 break;
12069         default:
12070                 printf("programming error: (%s)\n", strerror(-ret));
12071         }
12072 }
12073
12074 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12075         .f = cmd_set_vf_allmulti_parsed,
12076         .data = NULL,
12077         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12078                 "Set multicast promiscuous mode for a VF from the PF",
12079         .tokens = {
12080                 (void *)&cmd_vf_allmulti_set,
12081                 (void *)&cmd_vf_allmulti_vf,
12082                 (void *)&cmd_vf_allmulti_allmulti,
12083                 (void *)&cmd_vf_allmulti_port_id,
12084                 (void *)&cmd_vf_allmulti_vf_id,
12085                 (void *)&cmd_vf_allmulti_on_off,
12086                 NULL,
12087         },
12088 };
12089
12090 /* vf broadcast mode configuration */
12091
12092 /* Common result structure for vf broadcast */
12093 struct cmd_set_vf_broadcast_result {
12094         cmdline_fixed_string_t set;
12095         cmdline_fixed_string_t vf;
12096         cmdline_fixed_string_t broadcast;
12097         portid_t port_id;
12098         uint16_t vf_id;
12099         cmdline_fixed_string_t on_off;
12100 };
12101
12102 /* Common CLI fields for vf broadcast enable disable */
12103 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_set_vf_broadcast_result,
12106                  set, "set");
12107 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12108         TOKEN_STRING_INITIALIZER
12109                 (struct cmd_set_vf_broadcast_result,
12110                  vf, "vf");
12111 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_set_vf_broadcast_result,
12114                  broadcast, "broadcast");
12115 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12116         TOKEN_NUM_INITIALIZER
12117                 (struct cmd_set_vf_broadcast_result,
12118                  port_id, RTE_UINT16);
12119 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12120         TOKEN_NUM_INITIALIZER
12121                 (struct cmd_set_vf_broadcast_result,
12122                  vf_id, RTE_UINT16);
12123 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12124         TOKEN_STRING_INITIALIZER
12125                 (struct cmd_set_vf_broadcast_result,
12126                  on_off, "on#off");
12127
12128 static void
12129 cmd_set_vf_broadcast_parsed(
12130         void *parsed_result,
12131         __rte_unused struct cmdline *cl,
12132         __rte_unused void *data)
12133 {
12134         struct cmd_set_vf_broadcast_result *res = parsed_result;
12135         int ret = -ENOTSUP;
12136
12137         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12138
12139         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12140                 return;
12141
12142 #ifdef RTE_NET_I40E
12143         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12144                                             res->vf_id, is_on);
12145 #endif
12146
12147         switch (ret) {
12148         case 0:
12149                 break;
12150         case -EINVAL:
12151                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12152                 break;
12153         case -ENODEV:
12154                 printf("invalid port_id %d\n", res->port_id);
12155                 break;
12156         case -ENOTSUP:
12157                 printf("function not implemented\n");
12158                 break;
12159         default:
12160                 printf("programming error: (%s)\n", strerror(-ret));
12161         }
12162 }
12163
12164 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12165         .f = cmd_set_vf_broadcast_parsed,
12166         .data = NULL,
12167         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12168         .tokens = {
12169                 (void *)&cmd_set_vf_broadcast_set,
12170                 (void *)&cmd_set_vf_broadcast_vf,
12171                 (void *)&cmd_set_vf_broadcast_broadcast,
12172                 (void *)&cmd_set_vf_broadcast_port_id,
12173                 (void *)&cmd_set_vf_broadcast_vf_id,
12174                 (void *)&cmd_set_vf_broadcast_on_off,
12175                 NULL,
12176         },
12177 };
12178
12179 /* vf vlan tag configuration */
12180
12181 /* Common result structure for vf vlan tag */
12182 struct cmd_set_vf_vlan_tag_result {
12183         cmdline_fixed_string_t set;
12184         cmdline_fixed_string_t vf;
12185         cmdline_fixed_string_t vlan;
12186         cmdline_fixed_string_t tag;
12187         portid_t port_id;
12188         uint16_t vf_id;
12189         cmdline_fixed_string_t on_off;
12190 };
12191
12192 /* Common CLI fields for vf vlan tag enable disable */
12193 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12194         TOKEN_STRING_INITIALIZER
12195                 (struct cmd_set_vf_vlan_tag_result,
12196                  set, "set");
12197 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12198         TOKEN_STRING_INITIALIZER
12199                 (struct cmd_set_vf_vlan_tag_result,
12200                  vf, "vf");
12201 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12202         TOKEN_STRING_INITIALIZER
12203                 (struct cmd_set_vf_vlan_tag_result,
12204                  vlan, "vlan");
12205 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12206         TOKEN_STRING_INITIALIZER
12207                 (struct cmd_set_vf_vlan_tag_result,
12208                  tag, "tag");
12209 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12210         TOKEN_NUM_INITIALIZER
12211                 (struct cmd_set_vf_vlan_tag_result,
12212                  port_id, RTE_UINT16);
12213 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12214         TOKEN_NUM_INITIALIZER
12215                 (struct cmd_set_vf_vlan_tag_result,
12216                  vf_id, RTE_UINT16);
12217 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_set_vf_vlan_tag_result,
12220                  on_off, "on#off");
12221
12222 static void
12223 cmd_set_vf_vlan_tag_parsed(
12224         void *parsed_result,
12225         __rte_unused struct cmdline *cl,
12226         __rte_unused void *data)
12227 {
12228         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12229         int ret = -ENOTSUP;
12230
12231         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12232
12233         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12234                 return;
12235
12236 #ifdef RTE_NET_I40E
12237         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12238                                            res->vf_id, is_on);
12239 #endif
12240
12241         switch (ret) {
12242         case 0:
12243                 break;
12244         case -EINVAL:
12245                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12246                 break;
12247         case -ENODEV:
12248                 printf("invalid port_id %d\n", res->port_id);
12249                 break;
12250         case -ENOTSUP:
12251                 printf("function not implemented\n");
12252                 break;
12253         default:
12254                 printf("programming error: (%s)\n", strerror(-ret));
12255         }
12256 }
12257
12258 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12259         .f = cmd_set_vf_vlan_tag_parsed,
12260         .data = NULL,
12261         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12262         .tokens = {
12263                 (void *)&cmd_set_vf_vlan_tag_set,
12264                 (void *)&cmd_set_vf_vlan_tag_vf,
12265                 (void *)&cmd_set_vf_vlan_tag_vlan,
12266                 (void *)&cmd_set_vf_vlan_tag_tag,
12267                 (void *)&cmd_set_vf_vlan_tag_port_id,
12268                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12269                 (void *)&cmd_set_vf_vlan_tag_on_off,
12270                 NULL,
12271         },
12272 };
12273
12274 /* Common definition of VF and TC TX bandwidth configuration */
12275 struct cmd_vf_tc_bw_result {
12276         cmdline_fixed_string_t set;
12277         cmdline_fixed_string_t vf;
12278         cmdline_fixed_string_t tc;
12279         cmdline_fixed_string_t tx;
12280         cmdline_fixed_string_t min_bw;
12281         cmdline_fixed_string_t max_bw;
12282         cmdline_fixed_string_t strict_link_prio;
12283         portid_t port_id;
12284         uint16_t vf_id;
12285         uint8_t tc_no;
12286         uint32_t bw;
12287         cmdline_fixed_string_t bw_list;
12288         uint8_t tc_map;
12289 };
12290
12291 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_vf_tc_bw_result,
12294                  set, "set");
12295 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12296         TOKEN_STRING_INITIALIZER
12297                 (struct cmd_vf_tc_bw_result,
12298                  vf, "vf");
12299 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12300         TOKEN_STRING_INITIALIZER
12301                 (struct cmd_vf_tc_bw_result,
12302                  tc, "tc");
12303 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12304         TOKEN_STRING_INITIALIZER
12305                 (struct cmd_vf_tc_bw_result,
12306                  tx, "tx");
12307 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12308         TOKEN_STRING_INITIALIZER
12309                 (struct cmd_vf_tc_bw_result,
12310                  strict_link_prio, "strict-link-priority");
12311 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12312         TOKEN_STRING_INITIALIZER
12313                 (struct cmd_vf_tc_bw_result,
12314                  min_bw, "min-bandwidth");
12315 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12316         TOKEN_STRING_INITIALIZER
12317                 (struct cmd_vf_tc_bw_result,
12318                  max_bw, "max-bandwidth");
12319 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12320         TOKEN_NUM_INITIALIZER
12321                 (struct cmd_vf_tc_bw_result,
12322                  port_id, RTE_UINT16);
12323 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12324         TOKEN_NUM_INITIALIZER
12325                 (struct cmd_vf_tc_bw_result,
12326                  vf_id, RTE_UINT16);
12327 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12328         TOKEN_NUM_INITIALIZER
12329                 (struct cmd_vf_tc_bw_result,
12330                  tc_no, RTE_UINT8);
12331 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12332         TOKEN_NUM_INITIALIZER
12333                 (struct cmd_vf_tc_bw_result,
12334                  bw, RTE_UINT32);
12335 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12336         TOKEN_STRING_INITIALIZER
12337                 (struct cmd_vf_tc_bw_result,
12338                  bw_list, NULL);
12339 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12340         TOKEN_NUM_INITIALIZER
12341                 (struct cmd_vf_tc_bw_result,
12342                  tc_map, RTE_UINT8);
12343
12344 /* VF max bandwidth setting */
12345 static void
12346 cmd_vf_max_bw_parsed(
12347         void *parsed_result,
12348         __rte_unused struct cmdline *cl,
12349         __rte_unused void *data)
12350 {
12351         struct cmd_vf_tc_bw_result *res = parsed_result;
12352         int ret = -ENOTSUP;
12353
12354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12355                 return;
12356
12357 #ifdef RTE_NET_I40E
12358         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12359                                          res->vf_id, res->bw);
12360 #endif
12361
12362         switch (ret) {
12363         case 0:
12364                 break;
12365         case -EINVAL:
12366                 printf("invalid vf_id %d or bandwidth %d\n",
12367                        res->vf_id, res->bw);
12368                 break;
12369         case -ENODEV:
12370                 printf("invalid port_id %d\n", res->port_id);
12371                 break;
12372         case -ENOTSUP:
12373                 printf("function not implemented\n");
12374                 break;
12375         default:
12376                 printf("programming error: (%s)\n", strerror(-ret));
12377         }
12378 }
12379
12380 cmdline_parse_inst_t cmd_vf_max_bw = {
12381         .f = cmd_vf_max_bw_parsed,
12382         .data = NULL,
12383         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12384         .tokens = {
12385                 (void *)&cmd_vf_tc_bw_set,
12386                 (void *)&cmd_vf_tc_bw_vf,
12387                 (void *)&cmd_vf_tc_bw_tx,
12388                 (void *)&cmd_vf_tc_bw_max_bw,
12389                 (void *)&cmd_vf_tc_bw_port_id,
12390                 (void *)&cmd_vf_tc_bw_vf_id,
12391                 (void *)&cmd_vf_tc_bw_bw,
12392                 NULL,
12393         },
12394 };
12395
12396 static int
12397 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12398                            uint8_t *tc_num,
12399                            char *str)
12400 {
12401         uint32_t size;
12402         const char *p, *p0 = str;
12403         char s[256];
12404         char *end;
12405         char *str_fld[16];
12406         uint16_t i;
12407         int ret;
12408
12409         p = strchr(p0, '(');
12410         if (p == NULL) {
12411                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12412                 return -1;
12413         }
12414         p++;
12415         p0 = strchr(p, ')');
12416         if (p0 == NULL) {
12417                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12418                 return -1;
12419         }
12420         size = p0 - p;
12421         if (size >= sizeof(s)) {
12422                 printf("The string size exceeds the internal buffer size\n");
12423                 return -1;
12424         }
12425         snprintf(s, sizeof(s), "%.*s", size, p);
12426         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12427         if (ret <= 0) {
12428                 printf("Failed to get the bandwidth list. ");
12429                 return -1;
12430         }
12431         *tc_num = ret;
12432         for (i = 0; i < ret; i++)
12433                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12434
12435         return 0;
12436 }
12437
12438 /* TC min bandwidth setting */
12439 static void
12440 cmd_vf_tc_min_bw_parsed(
12441         void *parsed_result,
12442         __rte_unused struct cmdline *cl,
12443         __rte_unused void *data)
12444 {
12445         struct cmd_vf_tc_bw_result *res = parsed_result;
12446         uint8_t tc_num;
12447         uint8_t bw[16];
12448         int ret = -ENOTSUP;
12449
12450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12451                 return;
12452
12453         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12454         if (ret)
12455                 return;
12456
12457 #ifdef RTE_NET_I40E
12458         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12459                                               tc_num, bw);
12460 #endif
12461
12462         switch (ret) {
12463         case 0:
12464                 break;
12465         case -EINVAL:
12466                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12467                 break;
12468         case -ENODEV:
12469                 printf("invalid port_id %d\n", res->port_id);
12470                 break;
12471         case -ENOTSUP:
12472                 printf("function not implemented\n");
12473                 break;
12474         default:
12475                 printf("programming error: (%s)\n", strerror(-ret));
12476         }
12477 }
12478
12479 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12480         .f = cmd_vf_tc_min_bw_parsed,
12481         .data = NULL,
12482         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12483                     " <bw1, bw2, ...>",
12484         .tokens = {
12485                 (void *)&cmd_vf_tc_bw_set,
12486                 (void *)&cmd_vf_tc_bw_vf,
12487                 (void *)&cmd_vf_tc_bw_tc,
12488                 (void *)&cmd_vf_tc_bw_tx,
12489                 (void *)&cmd_vf_tc_bw_min_bw,
12490                 (void *)&cmd_vf_tc_bw_port_id,
12491                 (void *)&cmd_vf_tc_bw_vf_id,
12492                 (void *)&cmd_vf_tc_bw_bw_list,
12493                 NULL,
12494         },
12495 };
12496
12497 static void
12498 cmd_tc_min_bw_parsed(
12499         void *parsed_result,
12500         __rte_unused struct cmdline *cl,
12501         __rte_unused void *data)
12502 {
12503         struct cmd_vf_tc_bw_result *res = parsed_result;
12504         struct rte_port *port;
12505         uint8_t tc_num;
12506         uint8_t bw[16];
12507         int ret = -ENOTSUP;
12508
12509         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12510                 return;
12511
12512         port = &ports[res->port_id];
12513         /** Check if the port is not started **/
12514         if (port->port_status != RTE_PORT_STOPPED) {
12515                 printf("Please stop port %d first\n", res->port_id);
12516                 return;
12517         }
12518
12519         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12520         if (ret)
12521                 return;
12522
12523 #ifdef RTE_NET_IXGBE
12524         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12525 #endif
12526
12527         switch (ret) {
12528         case 0:
12529                 break;
12530         case -EINVAL:
12531                 printf("invalid bandwidth\n");
12532                 break;
12533         case -ENODEV:
12534                 printf("invalid port_id %d\n", res->port_id);
12535                 break;
12536         case -ENOTSUP:
12537                 printf("function not implemented\n");
12538                 break;
12539         default:
12540                 printf("programming error: (%s)\n", strerror(-ret));
12541         }
12542 }
12543
12544 cmdline_parse_inst_t cmd_tc_min_bw = {
12545         .f = cmd_tc_min_bw_parsed,
12546         .data = NULL,
12547         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12548         .tokens = {
12549                 (void *)&cmd_vf_tc_bw_set,
12550                 (void *)&cmd_vf_tc_bw_tc,
12551                 (void *)&cmd_vf_tc_bw_tx,
12552                 (void *)&cmd_vf_tc_bw_min_bw,
12553                 (void *)&cmd_vf_tc_bw_port_id,
12554                 (void *)&cmd_vf_tc_bw_bw_list,
12555                 NULL,
12556         },
12557 };
12558
12559 /* TC max bandwidth setting */
12560 static void
12561 cmd_vf_tc_max_bw_parsed(
12562         void *parsed_result,
12563         __rte_unused struct cmdline *cl,
12564         __rte_unused void *data)
12565 {
12566         struct cmd_vf_tc_bw_result *res = parsed_result;
12567         int ret = -ENOTSUP;
12568
12569         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12570                 return;
12571
12572 #ifdef RTE_NET_I40E
12573         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12574                                             res->tc_no, res->bw);
12575 #endif
12576
12577         switch (ret) {
12578         case 0:
12579                 break;
12580         case -EINVAL:
12581                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12582                        res->vf_id, res->tc_no, res->bw);
12583                 break;
12584         case -ENODEV:
12585                 printf("invalid port_id %d\n", res->port_id);
12586                 break;
12587         case -ENOTSUP:
12588                 printf("function not implemented\n");
12589                 break;
12590         default:
12591                 printf("programming error: (%s)\n", strerror(-ret));
12592         }
12593 }
12594
12595 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12596         .f = cmd_vf_tc_max_bw_parsed,
12597         .data = NULL,
12598         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12599                     " <bandwidth>",
12600         .tokens = {
12601                 (void *)&cmd_vf_tc_bw_set,
12602                 (void *)&cmd_vf_tc_bw_vf,
12603                 (void *)&cmd_vf_tc_bw_tc,
12604                 (void *)&cmd_vf_tc_bw_tx,
12605                 (void *)&cmd_vf_tc_bw_max_bw,
12606                 (void *)&cmd_vf_tc_bw_port_id,
12607                 (void *)&cmd_vf_tc_bw_vf_id,
12608                 (void *)&cmd_vf_tc_bw_tc_no,
12609                 (void *)&cmd_vf_tc_bw_bw,
12610                 NULL,
12611         },
12612 };
12613
12614 /** Set VXLAN encapsulation details */
12615 struct cmd_set_vxlan_result {
12616         cmdline_fixed_string_t set;
12617         cmdline_fixed_string_t vxlan;
12618         cmdline_fixed_string_t pos_token;
12619         cmdline_fixed_string_t ip_version;
12620         uint32_t vlan_present:1;
12621         uint32_t vni;
12622         uint16_t udp_src;
12623         uint16_t udp_dst;
12624         cmdline_ipaddr_t ip_src;
12625         cmdline_ipaddr_t ip_dst;
12626         uint16_t tci;
12627         uint8_t tos;
12628         uint8_t ttl;
12629         struct rte_ether_addr eth_src;
12630         struct rte_ether_addr eth_dst;
12631 };
12632
12633 cmdline_parse_token_string_t cmd_set_vxlan_set =
12634         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12635 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12636         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12637 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12638         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12639                                  "vxlan-tos-ttl");
12640 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12641         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12642                                  "vxlan-with-vlan");
12643 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12644         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12645                                  "ip-version");
12646 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12647         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12648                                  "ipv4#ipv6");
12649 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12650         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12651                                  "vni");
12652 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12653         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12654 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12655         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12656                                  "udp-src");
12657 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12658         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12659 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12660         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12661                                  "udp-dst");
12662 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12663         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12664 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12665         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12666                                  "ip-tos");
12667 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12668         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12669 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12670         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12671                                  "ip-ttl");
12672 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12673         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12674 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12675         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12676                                  "ip-src");
12677 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12678         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12679 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12680         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12681                                  "ip-dst");
12682 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12683         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12684 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12685         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12686                                  "vlan-tci");
12687 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12688         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12689 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12690         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12691                                  "eth-src");
12692 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12693         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12694 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12695         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12696                                  "eth-dst");
12697 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12698         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12699
12700 static void cmd_set_vxlan_parsed(void *parsed_result,
12701         __rte_unused struct cmdline *cl,
12702         __rte_unused void *data)
12703 {
12704         struct cmd_set_vxlan_result *res = parsed_result;
12705         union {
12706                 uint32_t vxlan_id;
12707                 uint8_t vni[4];
12708         } id = {
12709                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12710         };
12711
12712         vxlan_encap_conf.select_tos_ttl = 0;
12713         if (strcmp(res->vxlan, "vxlan") == 0)
12714                 vxlan_encap_conf.select_vlan = 0;
12715         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12716                 vxlan_encap_conf.select_vlan = 1;
12717         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12718                 vxlan_encap_conf.select_vlan = 0;
12719                 vxlan_encap_conf.select_tos_ttl = 1;
12720         }
12721         if (strcmp(res->ip_version, "ipv4") == 0)
12722                 vxlan_encap_conf.select_ipv4 = 1;
12723         else if (strcmp(res->ip_version, "ipv6") == 0)
12724                 vxlan_encap_conf.select_ipv4 = 0;
12725         else
12726                 return;
12727         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12728         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12729         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12730         vxlan_encap_conf.ip_tos = res->tos;
12731         vxlan_encap_conf.ip_ttl = res->ttl;
12732         if (vxlan_encap_conf.select_ipv4) {
12733                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12734                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12735         } else {
12736                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12737                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12738         }
12739         if (vxlan_encap_conf.select_vlan)
12740                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12741         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12742                    RTE_ETHER_ADDR_LEN);
12743         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12744                    RTE_ETHER_ADDR_LEN);
12745 }
12746
12747 cmdline_parse_inst_t cmd_set_vxlan = {
12748         .f = cmd_set_vxlan_parsed,
12749         .data = NULL,
12750         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12751                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12752                 " eth-src <eth-src> eth-dst <eth-dst>",
12753         .tokens = {
12754                 (void *)&cmd_set_vxlan_set,
12755                 (void *)&cmd_set_vxlan_vxlan,
12756                 (void *)&cmd_set_vxlan_ip_version,
12757                 (void *)&cmd_set_vxlan_ip_version_value,
12758                 (void *)&cmd_set_vxlan_vni,
12759                 (void *)&cmd_set_vxlan_vni_value,
12760                 (void *)&cmd_set_vxlan_udp_src,
12761                 (void *)&cmd_set_vxlan_udp_src_value,
12762                 (void *)&cmd_set_vxlan_udp_dst,
12763                 (void *)&cmd_set_vxlan_udp_dst_value,
12764                 (void *)&cmd_set_vxlan_ip_src,
12765                 (void *)&cmd_set_vxlan_ip_src_value,
12766                 (void *)&cmd_set_vxlan_ip_dst,
12767                 (void *)&cmd_set_vxlan_ip_dst_value,
12768                 (void *)&cmd_set_vxlan_eth_src,
12769                 (void *)&cmd_set_vxlan_eth_src_value,
12770                 (void *)&cmd_set_vxlan_eth_dst,
12771                 (void *)&cmd_set_vxlan_eth_dst_value,
12772                 NULL,
12773         },
12774 };
12775
12776 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12777         .f = cmd_set_vxlan_parsed,
12778         .data = NULL,
12779         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12780                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12781                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12782                 " eth-dst <eth-dst>",
12783         .tokens = {
12784                 (void *)&cmd_set_vxlan_set,
12785                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12786                 (void *)&cmd_set_vxlan_ip_version,
12787                 (void *)&cmd_set_vxlan_ip_version_value,
12788                 (void *)&cmd_set_vxlan_vni,
12789                 (void *)&cmd_set_vxlan_vni_value,
12790                 (void *)&cmd_set_vxlan_udp_src,
12791                 (void *)&cmd_set_vxlan_udp_src_value,
12792                 (void *)&cmd_set_vxlan_udp_dst,
12793                 (void *)&cmd_set_vxlan_udp_dst_value,
12794                 (void *)&cmd_set_vxlan_ip_tos,
12795                 (void *)&cmd_set_vxlan_ip_tos_value,
12796                 (void *)&cmd_set_vxlan_ip_ttl,
12797                 (void *)&cmd_set_vxlan_ip_ttl_value,
12798                 (void *)&cmd_set_vxlan_ip_src,
12799                 (void *)&cmd_set_vxlan_ip_src_value,
12800                 (void *)&cmd_set_vxlan_ip_dst,
12801                 (void *)&cmd_set_vxlan_ip_dst_value,
12802                 (void *)&cmd_set_vxlan_eth_src,
12803                 (void *)&cmd_set_vxlan_eth_src_value,
12804                 (void *)&cmd_set_vxlan_eth_dst,
12805                 (void *)&cmd_set_vxlan_eth_dst_value,
12806                 NULL,
12807         },
12808 };
12809
12810 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12811         .f = cmd_set_vxlan_parsed,
12812         .data = NULL,
12813         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12814                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12815                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12816                 " <eth-dst>",
12817         .tokens = {
12818                 (void *)&cmd_set_vxlan_set,
12819                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12820                 (void *)&cmd_set_vxlan_ip_version,
12821                 (void *)&cmd_set_vxlan_ip_version_value,
12822                 (void *)&cmd_set_vxlan_vni,
12823                 (void *)&cmd_set_vxlan_vni_value,
12824                 (void *)&cmd_set_vxlan_udp_src,
12825                 (void *)&cmd_set_vxlan_udp_src_value,
12826                 (void *)&cmd_set_vxlan_udp_dst,
12827                 (void *)&cmd_set_vxlan_udp_dst_value,
12828                 (void *)&cmd_set_vxlan_ip_src,
12829                 (void *)&cmd_set_vxlan_ip_src_value,
12830                 (void *)&cmd_set_vxlan_ip_dst,
12831                 (void *)&cmd_set_vxlan_ip_dst_value,
12832                 (void *)&cmd_set_vxlan_vlan,
12833                 (void *)&cmd_set_vxlan_vlan_value,
12834                 (void *)&cmd_set_vxlan_eth_src,
12835                 (void *)&cmd_set_vxlan_eth_src_value,
12836                 (void *)&cmd_set_vxlan_eth_dst,
12837                 (void *)&cmd_set_vxlan_eth_dst_value,
12838                 NULL,
12839         },
12840 };
12841
12842 /** Set NVGRE encapsulation details */
12843 struct cmd_set_nvgre_result {
12844         cmdline_fixed_string_t set;
12845         cmdline_fixed_string_t nvgre;
12846         cmdline_fixed_string_t pos_token;
12847         cmdline_fixed_string_t ip_version;
12848         uint32_t tni;
12849         cmdline_ipaddr_t ip_src;
12850         cmdline_ipaddr_t ip_dst;
12851         uint16_t tci;
12852         struct rte_ether_addr eth_src;
12853         struct rte_ether_addr eth_dst;
12854 };
12855
12856 cmdline_parse_token_string_t cmd_set_nvgre_set =
12857         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12858 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12859         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12860 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12861         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12862                                  "nvgre-with-vlan");
12863 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12864         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12865                                  "ip-version");
12866 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12867         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12868                                  "ipv4#ipv6");
12869 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12870         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12871                                  "tni");
12872 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12873         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12874 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12875         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12876                                  "ip-src");
12877 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12878         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12879 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12880         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12881                                  "ip-dst");
12882 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12883         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12884 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12885         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12886                                  "vlan-tci");
12887 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12888         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12889 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12890         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12891                                  "eth-src");
12892 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12893         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12894 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12895         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12896                                  "eth-dst");
12897 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12898         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12899
12900 static void cmd_set_nvgre_parsed(void *parsed_result,
12901         __rte_unused struct cmdline *cl,
12902         __rte_unused void *data)
12903 {
12904         struct cmd_set_nvgre_result *res = parsed_result;
12905         union {
12906                 uint32_t nvgre_tni;
12907                 uint8_t tni[4];
12908         } id = {
12909                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12910         };
12911
12912         if (strcmp(res->nvgre, "nvgre") == 0)
12913                 nvgre_encap_conf.select_vlan = 0;
12914         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12915                 nvgre_encap_conf.select_vlan = 1;
12916         if (strcmp(res->ip_version, "ipv4") == 0)
12917                 nvgre_encap_conf.select_ipv4 = 1;
12918         else if (strcmp(res->ip_version, "ipv6") == 0)
12919                 nvgre_encap_conf.select_ipv4 = 0;
12920         else
12921                 return;
12922         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12923         if (nvgre_encap_conf.select_ipv4) {
12924                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12925                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12926         } else {
12927                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12928                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12929         }
12930         if (nvgre_encap_conf.select_vlan)
12931                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12932         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12933                    RTE_ETHER_ADDR_LEN);
12934         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12935                    RTE_ETHER_ADDR_LEN);
12936 }
12937
12938 cmdline_parse_inst_t cmd_set_nvgre = {
12939         .f = cmd_set_nvgre_parsed,
12940         .data = NULL,
12941         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12942                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12943                 " eth-dst <eth-dst>",
12944         .tokens = {
12945                 (void *)&cmd_set_nvgre_set,
12946                 (void *)&cmd_set_nvgre_nvgre,
12947                 (void *)&cmd_set_nvgre_ip_version,
12948                 (void *)&cmd_set_nvgre_ip_version_value,
12949                 (void *)&cmd_set_nvgre_tni,
12950                 (void *)&cmd_set_nvgre_tni_value,
12951                 (void *)&cmd_set_nvgre_ip_src,
12952                 (void *)&cmd_set_nvgre_ip_src_value,
12953                 (void *)&cmd_set_nvgre_ip_dst,
12954                 (void *)&cmd_set_nvgre_ip_dst_value,
12955                 (void *)&cmd_set_nvgre_eth_src,
12956                 (void *)&cmd_set_nvgre_eth_src_value,
12957                 (void *)&cmd_set_nvgre_eth_dst,
12958                 (void *)&cmd_set_nvgre_eth_dst_value,
12959                 NULL,
12960         },
12961 };
12962
12963 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12964         .f = cmd_set_nvgre_parsed,
12965         .data = NULL,
12966         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12967                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12968                 " eth-src <eth-src> eth-dst <eth-dst>",
12969         .tokens = {
12970                 (void *)&cmd_set_nvgre_set,
12971                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12972                 (void *)&cmd_set_nvgre_ip_version,
12973                 (void *)&cmd_set_nvgre_ip_version_value,
12974                 (void *)&cmd_set_nvgre_tni,
12975                 (void *)&cmd_set_nvgre_tni_value,
12976                 (void *)&cmd_set_nvgre_ip_src,
12977                 (void *)&cmd_set_nvgre_ip_src_value,
12978                 (void *)&cmd_set_nvgre_ip_dst,
12979                 (void *)&cmd_set_nvgre_ip_dst_value,
12980                 (void *)&cmd_set_nvgre_vlan,
12981                 (void *)&cmd_set_nvgre_vlan_value,
12982                 (void *)&cmd_set_nvgre_eth_src,
12983                 (void *)&cmd_set_nvgre_eth_src_value,
12984                 (void *)&cmd_set_nvgre_eth_dst,
12985                 (void *)&cmd_set_nvgre_eth_dst_value,
12986                 NULL,
12987         },
12988 };
12989
12990 /** Set L2 encapsulation details */
12991 struct cmd_set_l2_encap_result {
12992         cmdline_fixed_string_t set;
12993         cmdline_fixed_string_t l2_encap;
12994         cmdline_fixed_string_t pos_token;
12995         cmdline_fixed_string_t ip_version;
12996         uint32_t vlan_present:1;
12997         uint16_t tci;
12998         struct rte_ether_addr eth_src;
12999         struct rte_ether_addr eth_dst;
13000 };
13001
13002 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13003         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13004 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13005         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13006 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13007         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13008                                  "l2_encap-with-vlan");
13009 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13010         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13011                                  "ip-version");
13012 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13013         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13014                                  "ipv4#ipv6");
13015 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13016         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13017                                  "vlan-tci");
13018 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13019         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13020 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13021         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13022                                  "eth-src");
13023 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13024         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13025 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13026         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13027                                  "eth-dst");
13028 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13029         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13030
13031 static void cmd_set_l2_encap_parsed(void *parsed_result,
13032         __rte_unused struct cmdline *cl,
13033         __rte_unused void *data)
13034 {
13035         struct cmd_set_l2_encap_result *res = parsed_result;
13036
13037         if (strcmp(res->l2_encap, "l2_encap") == 0)
13038                 l2_encap_conf.select_vlan = 0;
13039         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13040                 l2_encap_conf.select_vlan = 1;
13041         if (strcmp(res->ip_version, "ipv4") == 0)
13042                 l2_encap_conf.select_ipv4 = 1;
13043         else if (strcmp(res->ip_version, "ipv6") == 0)
13044                 l2_encap_conf.select_ipv4 = 0;
13045         else
13046                 return;
13047         if (l2_encap_conf.select_vlan)
13048                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13049         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13050                    RTE_ETHER_ADDR_LEN);
13051         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13052                    RTE_ETHER_ADDR_LEN);
13053 }
13054
13055 cmdline_parse_inst_t cmd_set_l2_encap = {
13056         .f = cmd_set_l2_encap_parsed,
13057         .data = NULL,
13058         .help_str = "set l2_encap ip-version ipv4|ipv6"
13059                 " eth-src <eth-src> eth-dst <eth-dst>",
13060         .tokens = {
13061                 (void *)&cmd_set_l2_encap_set,
13062                 (void *)&cmd_set_l2_encap_l2_encap,
13063                 (void *)&cmd_set_l2_encap_ip_version,
13064                 (void *)&cmd_set_l2_encap_ip_version_value,
13065                 (void *)&cmd_set_l2_encap_eth_src,
13066                 (void *)&cmd_set_l2_encap_eth_src_value,
13067                 (void *)&cmd_set_l2_encap_eth_dst,
13068                 (void *)&cmd_set_l2_encap_eth_dst_value,
13069                 NULL,
13070         },
13071 };
13072
13073 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13074         .f = cmd_set_l2_encap_parsed,
13075         .data = NULL,
13076         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13077                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13078         .tokens = {
13079                 (void *)&cmd_set_l2_encap_set,
13080                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13081                 (void *)&cmd_set_l2_encap_ip_version,
13082                 (void *)&cmd_set_l2_encap_ip_version_value,
13083                 (void *)&cmd_set_l2_encap_vlan,
13084                 (void *)&cmd_set_l2_encap_vlan_value,
13085                 (void *)&cmd_set_l2_encap_eth_src,
13086                 (void *)&cmd_set_l2_encap_eth_src_value,
13087                 (void *)&cmd_set_l2_encap_eth_dst,
13088                 (void *)&cmd_set_l2_encap_eth_dst_value,
13089                 NULL,
13090         },
13091 };
13092
13093 /** Set L2 decapsulation details */
13094 struct cmd_set_l2_decap_result {
13095         cmdline_fixed_string_t set;
13096         cmdline_fixed_string_t l2_decap;
13097         cmdline_fixed_string_t pos_token;
13098         uint32_t vlan_present:1;
13099 };
13100
13101 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13102         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13103 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13104         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13105                                  "l2_decap");
13106 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13107         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13108                                  "l2_decap-with-vlan");
13109
13110 static void cmd_set_l2_decap_parsed(void *parsed_result,
13111         __rte_unused struct cmdline *cl,
13112         __rte_unused void *data)
13113 {
13114         struct cmd_set_l2_decap_result *res = parsed_result;
13115
13116         if (strcmp(res->l2_decap, "l2_decap") == 0)
13117                 l2_decap_conf.select_vlan = 0;
13118         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13119                 l2_decap_conf.select_vlan = 1;
13120 }
13121
13122 cmdline_parse_inst_t cmd_set_l2_decap = {
13123         .f = cmd_set_l2_decap_parsed,
13124         .data = NULL,
13125         .help_str = "set l2_decap",
13126         .tokens = {
13127                 (void *)&cmd_set_l2_decap_set,
13128                 (void *)&cmd_set_l2_decap_l2_decap,
13129                 NULL,
13130         },
13131 };
13132
13133 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13134         .f = cmd_set_l2_decap_parsed,
13135         .data = NULL,
13136         .help_str = "set l2_decap-with-vlan",
13137         .tokens = {
13138                 (void *)&cmd_set_l2_decap_set,
13139                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13140                 NULL,
13141         },
13142 };
13143
13144 /** Set MPLSoGRE encapsulation details */
13145 struct cmd_set_mplsogre_encap_result {
13146         cmdline_fixed_string_t set;
13147         cmdline_fixed_string_t mplsogre;
13148         cmdline_fixed_string_t pos_token;
13149         cmdline_fixed_string_t ip_version;
13150         uint32_t vlan_present:1;
13151         uint32_t label;
13152         cmdline_ipaddr_t ip_src;
13153         cmdline_ipaddr_t ip_dst;
13154         uint16_t tci;
13155         struct rte_ether_addr eth_src;
13156         struct rte_ether_addr eth_dst;
13157 };
13158
13159 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13160         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13161                                  "set");
13162 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13163         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13164                                  "mplsogre_encap");
13165 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13166         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13167                                  mplsogre, "mplsogre_encap-with-vlan");
13168 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13169         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13170                                  pos_token, "ip-version");
13171 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13172         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13173                                  ip_version, "ipv4#ipv6");
13174 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13175         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13176                                  pos_token, "label");
13177 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13178         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13179                               RTE_UINT32);
13180 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13182                                  pos_token, "ip-src");
13183 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13184         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13185 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13187                                  pos_token, "ip-dst");
13188 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13189         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13190 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13191         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13192                                  pos_token, "vlan-tci");
13193 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13194         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13195                               RTE_UINT16);
13196 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13197         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13198                                  pos_token, "eth-src");
13199 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13200         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13201                                     eth_src);
13202 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13203         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13204                                  pos_token, "eth-dst");
13205 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13206         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13207                                     eth_dst);
13208
13209 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13210         __rte_unused struct cmdline *cl,
13211         __rte_unused void *data)
13212 {
13213         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13214         union {
13215                 uint32_t mplsogre_label;
13216                 uint8_t label[4];
13217         } id = {
13218                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13219         };
13220
13221         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13222                 mplsogre_encap_conf.select_vlan = 0;
13223         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13224                 mplsogre_encap_conf.select_vlan = 1;
13225         if (strcmp(res->ip_version, "ipv4") == 0)
13226                 mplsogre_encap_conf.select_ipv4 = 1;
13227         else if (strcmp(res->ip_version, "ipv6") == 0)
13228                 mplsogre_encap_conf.select_ipv4 = 0;
13229         else
13230                 return;
13231         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13232         if (mplsogre_encap_conf.select_ipv4) {
13233                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13234                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13235         } else {
13236                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13237                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13238         }
13239         if (mplsogre_encap_conf.select_vlan)
13240                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13241         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13242                    RTE_ETHER_ADDR_LEN);
13243         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13244                    RTE_ETHER_ADDR_LEN);
13245 }
13246
13247 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13248         .f = cmd_set_mplsogre_encap_parsed,
13249         .data = NULL,
13250         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13251                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13252                 " eth-dst <eth-dst>",
13253         .tokens = {
13254                 (void *)&cmd_set_mplsogre_encap_set,
13255                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13256                 (void *)&cmd_set_mplsogre_encap_ip_version,
13257                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13258                 (void *)&cmd_set_mplsogre_encap_label,
13259                 (void *)&cmd_set_mplsogre_encap_label_value,
13260                 (void *)&cmd_set_mplsogre_encap_ip_src,
13261                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13262                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13263                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13264                 (void *)&cmd_set_mplsogre_encap_eth_src,
13265                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13266                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13267                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13268                 NULL,
13269         },
13270 };
13271
13272 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13273         .f = cmd_set_mplsogre_encap_parsed,
13274         .data = NULL,
13275         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13276                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13277                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13278         .tokens = {
13279                 (void *)&cmd_set_mplsogre_encap_set,
13280                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13281                 (void *)&cmd_set_mplsogre_encap_ip_version,
13282                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13283                 (void *)&cmd_set_mplsogre_encap_label,
13284                 (void *)&cmd_set_mplsogre_encap_label_value,
13285                 (void *)&cmd_set_mplsogre_encap_ip_src,
13286                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13287                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13288                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13289                 (void *)&cmd_set_mplsogre_encap_vlan,
13290                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13291                 (void *)&cmd_set_mplsogre_encap_eth_src,
13292                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13293                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13294                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13295                 NULL,
13296         },
13297 };
13298
13299 /** Set MPLSoGRE decapsulation details */
13300 struct cmd_set_mplsogre_decap_result {
13301         cmdline_fixed_string_t set;
13302         cmdline_fixed_string_t mplsogre;
13303         cmdline_fixed_string_t pos_token;
13304         cmdline_fixed_string_t ip_version;
13305         uint32_t vlan_present:1;
13306 };
13307
13308 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13309         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13310                                  "set");
13311 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13312         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13313                                  "mplsogre_decap");
13314 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13315         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13316                                  mplsogre, "mplsogre_decap-with-vlan");
13317 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13318         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13319                                  pos_token, "ip-version");
13320 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13321         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13322                                  ip_version, "ipv4#ipv6");
13323
13324 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13325         __rte_unused struct cmdline *cl,
13326         __rte_unused void *data)
13327 {
13328         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13329
13330         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13331                 mplsogre_decap_conf.select_vlan = 0;
13332         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13333                 mplsogre_decap_conf.select_vlan = 1;
13334         if (strcmp(res->ip_version, "ipv4") == 0)
13335                 mplsogre_decap_conf.select_ipv4 = 1;
13336         else if (strcmp(res->ip_version, "ipv6") == 0)
13337                 mplsogre_decap_conf.select_ipv4 = 0;
13338 }
13339
13340 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13341         .f = cmd_set_mplsogre_decap_parsed,
13342         .data = NULL,
13343         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13344         .tokens = {
13345                 (void *)&cmd_set_mplsogre_decap_set,
13346                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13347                 (void *)&cmd_set_mplsogre_decap_ip_version,
13348                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13349                 NULL,
13350         },
13351 };
13352
13353 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13354         .f = cmd_set_mplsogre_decap_parsed,
13355         .data = NULL,
13356         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13357         .tokens = {
13358                 (void *)&cmd_set_mplsogre_decap_set,
13359                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13360                 (void *)&cmd_set_mplsogre_decap_ip_version,
13361                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13362                 NULL,
13363         },
13364 };
13365
13366 /** Set MPLSoUDP encapsulation details */
13367 struct cmd_set_mplsoudp_encap_result {
13368         cmdline_fixed_string_t set;
13369         cmdline_fixed_string_t mplsoudp;
13370         cmdline_fixed_string_t pos_token;
13371         cmdline_fixed_string_t ip_version;
13372         uint32_t vlan_present:1;
13373         uint32_t label;
13374         uint16_t udp_src;
13375         uint16_t udp_dst;
13376         cmdline_ipaddr_t ip_src;
13377         cmdline_ipaddr_t ip_dst;
13378         uint16_t tci;
13379         struct rte_ether_addr eth_src;
13380         struct rte_ether_addr eth_dst;
13381 };
13382
13383 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13384         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13385                                  "set");
13386 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13387         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13388                                  "mplsoudp_encap");
13389 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13390         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13391                                  mplsoudp, "mplsoudp_encap-with-vlan");
13392 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13393         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13394                                  pos_token, "ip-version");
13395 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13396         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13397                                  ip_version, "ipv4#ipv6");
13398 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13399         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13400                                  pos_token, "label");
13401 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13402         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13403                               RTE_UINT32);
13404 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13405         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13406                                  pos_token, "udp-src");
13407 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13408         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13409                               RTE_UINT16);
13410 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13411         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13412                                  pos_token, "udp-dst");
13413 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13414         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13415                               RTE_UINT16);
13416 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13417         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13418                                  pos_token, "ip-src");
13419 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13420         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13421 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13422         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13423                                  pos_token, "ip-dst");
13424 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13425         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13426 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13427         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13428                                  pos_token, "vlan-tci");
13429 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13430         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13431                               RTE_UINT16);
13432 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13433         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13434                                  pos_token, "eth-src");
13435 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13436         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13437                                     eth_src);
13438 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13439         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13440                                  pos_token, "eth-dst");
13441 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13442         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13443                                     eth_dst);
13444
13445 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13446         __rte_unused struct cmdline *cl,
13447         __rte_unused void *data)
13448 {
13449         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13450         union {
13451                 uint32_t mplsoudp_label;
13452                 uint8_t label[4];
13453         } id = {
13454                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13455         };
13456
13457         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13458                 mplsoudp_encap_conf.select_vlan = 0;
13459         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13460                 mplsoudp_encap_conf.select_vlan = 1;
13461         if (strcmp(res->ip_version, "ipv4") == 0)
13462                 mplsoudp_encap_conf.select_ipv4 = 1;
13463         else if (strcmp(res->ip_version, "ipv6") == 0)
13464                 mplsoudp_encap_conf.select_ipv4 = 0;
13465         else
13466                 return;
13467         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13468         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13469         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13470         if (mplsoudp_encap_conf.select_ipv4) {
13471                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13472                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13473         } else {
13474                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13475                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13476         }
13477         if (mplsoudp_encap_conf.select_vlan)
13478                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13479         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13480                    RTE_ETHER_ADDR_LEN);
13481         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13482                    RTE_ETHER_ADDR_LEN);
13483 }
13484
13485 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13486         .f = cmd_set_mplsoudp_encap_parsed,
13487         .data = NULL,
13488         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13489                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13490                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13491         .tokens = {
13492                 (void *)&cmd_set_mplsoudp_encap_set,
13493                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13494                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13495                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13496                 (void *)&cmd_set_mplsoudp_encap_label,
13497                 (void *)&cmd_set_mplsoudp_encap_label_value,
13498                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13499                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13500                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13501                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13502                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13503                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13504                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13505                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13506                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13507                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13508                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13509                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13510                 NULL,
13511         },
13512 };
13513
13514 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13515         .f = cmd_set_mplsoudp_encap_parsed,
13516         .data = NULL,
13517         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13518                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13519                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13520                 " eth-src <eth-src> eth-dst <eth-dst>",
13521         .tokens = {
13522                 (void *)&cmd_set_mplsoudp_encap_set,
13523                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13524                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13525                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13526                 (void *)&cmd_set_mplsoudp_encap_label,
13527                 (void *)&cmd_set_mplsoudp_encap_label_value,
13528                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13529                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13530                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13531                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13532                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13533                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13534                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13535                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13536                 (void *)&cmd_set_mplsoudp_encap_vlan,
13537                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13538                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13539                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13540                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13541                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13542                 NULL,
13543         },
13544 };
13545
13546 /** Set MPLSoUDP decapsulation details */
13547 struct cmd_set_mplsoudp_decap_result {
13548         cmdline_fixed_string_t set;
13549         cmdline_fixed_string_t mplsoudp;
13550         cmdline_fixed_string_t pos_token;
13551         cmdline_fixed_string_t ip_version;
13552         uint32_t vlan_present:1;
13553 };
13554
13555 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13556         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13557                                  "set");
13558 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13559         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13560                                  "mplsoudp_decap");
13561 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13562         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13563                                  mplsoudp, "mplsoudp_decap-with-vlan");
13564 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13565         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13566                                  pos_token, "ip-version");
13567 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13568         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13569                                  ip_version, "ipv4#ipv6");
13570
13571 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13572         __rte_unused struct cmdline *cl,
13573         __rte_unused void *data)
13574 {
13575         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13576
13577         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13578                 mplsoudp_decap_conf.select_vlan = 0;
13579         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13580                 mplsoudp_decap_conf.select_vlan = 1;
13581         if (strcmp(res->ip_version, "ipv4") == 0)
13582                 mplsoudp_decap_conf.select_ipv4 = 1;
13583         else if (strcmp(res->ip_version, "ipv6") == 0)
13584                 mplsoudp_decap_conf.select_ipv4 = 0;
13585 }
13586
13587 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13588         .f = cmd_set_mplsoudp_decap_parsed,
13589         .data = NULL,
13590         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13591         .tokens = {
13592                 (void *)&cmd_set_mplsoudp_decap_set,
13593                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13594                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13595                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13596                 NULL,
13597         },
13598 };
13599
13600 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13601         .f = cmd_set_mplsoudp_decap_parsed,
13602         .data = NULL,
13603         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13604         .tokens = {
13605                 (void *)&cmd_set_mplsoudp_decap_set,
13606                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13607                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13608                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13609                 NULL,
13610         },
13611 };
13612
13613 /* Strict link priority scheduling mode setting */
13614 static void
13615 cmd_strict_link_prio_parsed(
13616         void *parsed_result,
13617         __rte_unused struct cmdline *cl,
13618         __rte_unused void *data)
13619 {
13620         struct cmd_vf_tc_bw_result *res = parsed_result;
13621         int ret = -ENOTSUP;
13622
13623         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13624                 return;
13625
13626 #ifdef RTE_NET_I40E
13627         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13628 #endif
13629
13630         switch (ret) {
13631         case 0:
13632                 break;
13633         case -EINVAL:
13634                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13635                 break;
13636         case -ENODEV:
13637                 printf("invalid port_id %d\n", res->port_id);
13638                 break;
13639         case -ENOTSUP:
13640                 printf("function not implemented\n");
13641                 break;
13642         default:
13643                 printf("programming error: (%s)\n", strerror(-ret));
13644         }
13645 }
13646
13647 cmdline_parse_inst_t cmd_strict_link_prio = {
13648         .f = cmd_strict_link_prio_parsed,
13649         .data = NULL,
13650         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13651         .tokens = {
13652                 (void *)&cmd_vf_tc_bw_set,
13653                 (void *)&cmd_vf_tc_bw_tx,
13654                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13655                 (void *)&cmd_vf_tc_bw_port_id,
13656                 (void *)&cmd_vf_tc_bw_tc_map,
13657                 NULL,
13658         },
13659 };
13660
13661 /* Load dynamic device personalization*/
13662 struct cmd_ddp_add_result {
13663         cmdline_fixed_string_t ddp;
13664         cmdline_fixed_string_t add;
13665         portid_t port_id;
13666         char filepath[];
13667 };
13668
13669 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13670         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13671 cmdline_parse_token_string_t cmd_ddp_add_add =
13672         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13673 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13674         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13675                 RTE_UINT16);
13676 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13677         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13678
13679 static void
13680 cmd_ddp_add_parsed(
13681         void *parsed_result,
13682         __rte_unused struct cmdline *cl,
13683         __rte_unused void *data)
13684 {
13685         struct cmd_ddp_add_result *res = parsed_result;
13686         uint8_t *buff;
13687         uint32_t size;
13688         char *filepath;
13689         char *file_fld[2];
13690         int file_num;
13691         int ret = -ENOTSUP;
13692
13693         if (!all_ports_stopped()) {
13694                 printf("Please stop all ports first\n");
13695                 return;
13696         }
13697
13698         filepath = strdup(res->filepath);
13699         if (filepath == NULL) {
13700                 printf("Failed to allocate memory\n");
13701                 return;
13702         }
13703         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13704
13705         buff = open_file(file_fld[0], &size);
13706         if (!buff) {
13707                 free((void *)filepath);
13708                 return;
13709         }
13710
13711 #ifdef RTE_NET_I40E
13712         if (ret == -ENOTSUP)
13713                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13714                                                buff, size,
13715                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13716 #endif
13717
13718         if (ret == -EEXIST)
13719                 printf("Profile has already existed.\n");
13720         else if (ret < 0)
13721                 printf("Failed to load profile.\n");
13722         else if (file_num == 2)
13723                 save_file(file_fld[1], buff, size);
13724
13725         close_file(buff);
13726         free((void *)filepath);
13727 }
13728
13729 cmdline_parse_inst_t cmd_ddp_add = {
13730         .f = cmd_ddp_add_parsed,
13731         .data = NULL,
13732         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13733         .tokens = {
13734                 (void *)&cmd_ddp_add_ddp,
13735                 (void *)&cmd_ddp_add_add,
13736                 (void *)&cmd_ddp_add_port_id,
13737                 (void *)&cmd_ddp_add_filepath,
13738                 NULL,
13739         },
13740 };
13741
13742 /* Delete dynamic device personalization*/
13743 struct cmd_ddp_del_result {
13744         cmdline_fixed_string_t ddp;
13745         cmdline_fixed_string_t del;
13746         portid_t port_id;
13747         char filepath[];
13748 };
13749
13750 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13751         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13752 cmdline_parse_token_string_t cmd_ddp_del_del =
13753         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13754 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13755         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13756 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13757         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13758
13759 static void
13760 cmd_ddp_del_parsed(
13761         void *parsed_result,
13762         __rte_unused struct cmdline *cl,
13763         __rte_unused void *data)
13764 {
13765         struct cmd_ddp_del_result *res = parsed_result;
13766         uint8_t *buff;
13767         uint32_t size;
13768         int ret = -ENOTSUP;
13769
13770         if (!all_ports_stopped()) {
13771                 printf("Please stop all ports first\n");
13772                 return;
13773         }
13774
13775         buff = open_file(res->filepath, &size);
13776         if (!buff)
13777                 return;
13778
13779 #ifdef RTE_NET_I40E
13780         if (ret == -ENOTSUP)
13781                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13782                                                buff, size,
13783                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13784 #endif
13785
13786         if (ret == -EACCES)
13787                 printf("Profile does not exist.\n");
13788         else if (ret < 0)
13789                 printf("Failed to delete profile.\n");
13790
13791         close_file(buff);
13792 }
13793
13794 cmdline_parse_inst_t cmd_ddp_del = {
13795         .f = cmd_ddp_del_parsed,
13796         .data = NULL,
13797         .help_str = "ddp del <port_id> <backup_profile_path>",
13798         .tokens = {
13799                 (void *)&cmd_ddp_del_ddp,
13800                 (void *)&cmd_ddp_del_del,
13801                 (void *)&cmd_ddp_del_port_id,
13802                 (void *)&cmd_ddp_del_filepath,
13803                 NULL,
13804         },
13805 };
13806
13807 /* Get dynamic device personalization profile info */
13808 struct cmd_ddp_info_result {
13809         cmdline_fixed_string_t ddp;
13810         cmdline_fixed_string_t get;
13811         cmdline_fixed_string_t info;
13812         char filepath[];
13813 };
13814
13815 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13816         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13817 cmdline_parse_token_string_t cmd_ddp_info_get =
13818         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13819 cmdline_parse_token_string_t cmd_ddp_info_info =
13820         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13821 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13822         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13823
13824 static void
13825 cmd_ddp_info_parsed(
13826         void *parsed_result,
13827         __rte_unused struct cmdline *cl,
13828         __rte_unused void *data)
13829 {
13830         struct cmd_ddp_info_result *res = parsed_result;
13831         uint8_t *pkg;
13832         uint32_t pkg_size;
13833         int ret = -ENOTSUP;
13834 #ifdef RTE_NET_I40E
13835         uint32_t i, j, n;
13836         uint8_t *buff;
13837         uint32_t buff_size = 0;
13838         struct rte_pmd_i40e_profile_info info;
13839         uint32_t dev_num = 0;
13840         struct rte_pmd_i40e_ddp_device_id *devs;
13841         uint32_t proto_num = 0;
13842         struct rte_pmd_i40e_proto_info *proto = NULL;
13843         uint32_t pctype_num = 0;
13844         struct rte_pmd_i40e_ptype_info *pctype;
13845         uint32_t ptype_num = 0;
13846         struct rte_pmd_i40e_ptype_info *ptype;
13847         uint8_t proto_id;
13848
13849 #endif
13850
13851         pkg = open_file(res->filepath, &pkg_size);
13852         if (!pkg)
13853                 return;
13854
13855 #ifdef RTE_NET_I40E
13856         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13857                                 (uint8_t *)&info, sizeof(info),
13858                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13859         if (!ret) {
13860                 printf("Global Track id:       0x%x\n", info.track_id);
13861                 printf("Global Version:        %d.%d.%d.%d\n",
13862                         info.version.major,
13863                         info.version.minor,
13864                         info.version.update,
13865                         info.version.draft);
13866                 printf("Global Package name:   %s\n\n", info.name);
13867         }
13868
13869         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13870                                 (uint8_t *)&info, sizeof(info),
13871                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13872         if (!ret) {
13873                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13874                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13875                         info.version.major,
13876                         info.version.minor,
13877                         info.version.update,
13878                         info.version.draft);
13879                 printf("i40e Profile name:     %s\n\n", info.name);
13880         }
13881
13882         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13883                                 (uint8_t *)&buff_size, sizeof(buff_size),
13884                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13885         if (!ret && buff_size) {
13886                 buff = (uint8_t *)malloc(buff_size);
13887                 if (buff) {
13888                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13889                                                 buff, buff_size,
13890                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13891                         if (!ret)
13892                                 printf("Package Notes:\n%s\n\n", buff);
13893                         free(buff);
13894                 }
13895         }
13896
13897         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13898                                 (uint8_t *)&dev_num, sizeof(dev_num),
13899                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13900         if (!ret && dev_num) {
13901                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13902                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13903                 if (devs) {
13904                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13905                                                 (uint8_t *)devs, buff_size,
13906                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13907                         if (!ret) {
13908                                 printf("List of supported devices:\n");
13909                                 for (i = 0; i < dev_num; i++) {
13910                                         printf("  %04X:%04X %04X:%04X\n",
13911                                                 devs[i].vendor_dev_id >> 16,
13912                                                 devs[i].vendor_dev_id & 0xFFFF,
13913                                                 devs[i].sub_vendor_dev_id >> 16,
13914                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13915                                 }
13916                                 printf("\n");
13917                         }
13918                         free(devs);
13919                 }
13920         }
13921
13922         /* get information about protocols and packet types */
13923         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13924                 (uint8_t *)&proto_num, sizeof(proto_num),
13925                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13926         if (ret || !proto_num)
13927                 goto no_print_return;
13928
13929         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13930         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13931         if (!proto)
13932                 goto no_print_return;
13933
13934         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13935                                         buff_size,
13936                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13937         if (!ret) {
13938                 printf("List of used protocols:\n");
13939                 for (i = 0; i < proto_num; i++)
13940                         printf("  %2u: %s\n", proto[i].proto_id,
13941                                proto[i].name);
13942                 printf("\n");
13943         }
13944         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13945                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13946                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13947         if (ret || !pctype_num)
13948                 goto no_print_pctypes;
13949
13950         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13951         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13952         if (!pctype)
13953                 goto no_print_pctypes;
13954
13955         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13956                                         buff_size,
13957                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13958         if (ret) {
13959                 free(pctype);
13960                 goto no_print_pctypes;
13961         }
13962
13963         printf("List of defined packet classification types:\n");
13964         for (i = 0; i < pctype_num; i++) {
13965                 printf("  %2u:", pctype[i].ptype_id);
13966                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13967                         proto_id = pctype[i].protocols[j];
13968                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13969                                 for (n = 0; n < proto_num; n++) {
13970                                         if (proto[n].proto_id == proto_id) {
13971                                                 printf(" %s", proto[n].name);
13972                                                 break;
13973                                         }
13974                                 }
13975                         }
13976                 }
13977                 printf("\n");
13978         }
13979         printf("\n");
13980         free(pctype);
13981
13982 no_print_pctypes:
13983
13984         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13985                                         sizeof(ptype_num),
13986                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13987         if (ret || !ptype_num)
13988                 goto no_print_return;
13989
13990         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13991         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13992         if (!ptype)
13993                 goto no_print_return;
13994
13995         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13996                                         buff_size,
13997                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13998         if (ret) {
13999                 free(ptype);
14000                 goto no_print_return;
14001         }
14002         printf("List of defined packet types:\n");
14003         for (i = 0; i < ptype_num; i++) {
14004                 printf("  %2u:", ptype[i].ptype_id);
14005                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14006                         proto_id = ptype[i].protocols[j];
14007                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14008                                 for (n = 0; n < proto_num; n++) {
14009                                         if (proto[n].proto_id == proto_id) {
14010                                                 printf(" %s", proto[n].name);
14011                                                 break;
14012                                         }
14013                                 }
14014                         }
14015                 }
14016                 printf("\n");
14017         }
14018         free(ptype);
14019         printf("\n");
14020
14021         ret = 0;
14022 no_print_return:
14023         if (proto)
14024                 free(proto);
14025 #endif
14026         if (ret == -ENOTSUP)
14027                 printf("Function not supported in PMD driver\n");
14028         close_file(pkg);
14029 }
14030
14031 cmdline_parse_inst_t cmd_ddp_get_info = {
14032         .f = cmd_ddp_info_parsed,
14033         .data = NULL,
14034         .help_str = "ddp get info <profile_path>",
14035         .tokens = {
14036                 (void *)&cmd_ddp_info_ddp,
14037                 (void *)&cmd_ddp_info_get,
14038                 (void *)&cmd_ddp_info_info,
14039                 (void *)&cmd_ddp_info_filepath,
14040                 NULL,
14041         },
14042 };
14043
14044 /* Get dynamic device personalization profile info list*/
14045 #define PROFILE_INFO_SIZE 48
14046 #define MAX_PROFILE_NUM 16
14047
14048 struct cmd_ddp_get_list_result {
14049         cmdline_fixed_string_t ddp;
14050         cmdline_fixed_string_t get;
14051         cmdline_fixed_string_t list;
14052         portid_t port_id;
14053 };
14054
14055 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14056         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14057 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14058         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14059 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14060         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14061 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14062         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14063                 RTE_UINT16);
14064
14065 static void
14066 cmd_ddp_get_list_parsed(
14067         __rte_unused void *parsed_result,
14068         __rte_unused struct cmdline *cl,
14069         __rte_unused void *data)
14070 {
14071 #ifdef RTE_NET_I40E
14072         struct cmd_ddp_get_list_result *res = parsed_result;
14073         struct rte_pmd_i40e_profile_list *p_list;
14074         struct rte_pmd_i40e_profile_info *p_info;
14075         uint32_t p_num;
14076         uint32_t size;
14077         uint32_t i;
14078 #endif
14079         int ret = -ENOTSUP;
14080
14081 #ifdef RTE_NET_I40E
14082         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14083         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14084         if (!p_list) {
14085                 printf("%s: Failed to malloc buffer\n", __func__);
14086                 return;
14087         }
14088
14089         if (ret == -ENOTSUP)
14090                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14091                                                 (uint8_t *)p_list, size);
14092
14093         if (!ret) {
14094                 p_num = p_list->p_count;
14095                 printf("Profile number is: %d\n\n", p_num);
14096
14097                 for (i = 0; i < p_num; i++) {
14098                         p_info = &p_list->p_info[i];
14099                         printf("Profile %d:\n", i);
14100                         printf("Track id:     0x%x\n", p_info->track_id);
14101                         printf("Version:      %d.%d.%d.%d\n",
14102                                p_info->version.major,
14103                                p_info->version.minor,
14104                                p_info->version.update,
14105                                p_info->version.draft);
14106                         printf("Profile name: %s\n\n", p_info->name);
14107                 }
14108         }
14109
14110         free(p_list);
14111 #endif
14112
14113         if (ret < 0)
14114                 printf("Failed to get ddp list\n");
14115 }
14116
14117 cmdline_parse_inst_t cmd_ddp_get_list = {
14118         .f = cmd_ddp_get_list_parsed,
14119         .data = NULL,
14120         .help_str = "ddp get list <port_id>",
14121         .tokens = {
14122                 (void *)&cmd_ddp_get_list_ddp,
14123                 (void *)&cmd_ddp_get_list_get,
14124                 (void *)&cmd_ddp_get_list_list,
14125                 (void *)&cmd_ddp_get_list_port_id,
14126                 NULL,
14127         },
14128 };
14129
14130 /* Configure input set */
14131 struct cmd_cfg_input_set_result {
14132         cmdline_fixed_string_t port;
14133         cmdline_fixed_string_t cfg;
14134         portid_t port_id;
14135         cmdline_fixed_string_t pctype;
14136         uint8_t pctype_id;
14137         cmdline_fixed_string_t inset_type;
14138         cmdline_fixed_string_t opt;
14139         cmdline_fixed_string_t field;
14140         uint8_t field_idx;
14141 };
14142
14143 static void
14144 cmd_cfg_input_set_parsed(
14145         __rte_unused void *parsed_result,
14146         __rte_unused struct cmdline *cl,
14147         __rte_unused void *data)
14148 {
14149 #ifdef RTE_NET_I40E
14150         struct cmd_cfg_input_set_result *res = parsed_result;
14151         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14152         struct rte_pmd_i40e_inset inset;
14153 #endif
14154         int ret = -ENOTSUP;
14155
14156         if (!all_ports_stopped()) {
14157                 printf("Please stop all ports first\n");
14158                 return;
14159         }
14160
14161 #ifdef RTE_NET_I40E
14162         if (!strcmp(res->inset_type, "hash_inset"))
14163                 inset_type = INSET_HASH;
14164         else if (!strcmp(res->inset_type, "fdir_inset"))
14165                 inset_type = INSET_FDIR;
14166         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14167                 inset_type = INSET_FDIR_FLX;
14168         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14169                                      &inset, inset_type);
14170         if (ret) {
14171                 printf("Failed to get input set.\n");
14172                 return;
14173         }
14174
14175         if (!strcmp(res->opt, "get")) {
14176                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14177                                                    res->field_idx);
14178                 if (ret)
14179                         printf("Field index %d is enabled.\n", res->field_idx);
14180                 else
14181                         printf("Field index %d is disabled.\n", res->field_idx);
14182                 return;
14183         } else if (!strcmp(res->opt, "set"))
14184                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14185                                                    res->field_idx);
14186         else if (!strcmp(res->opt, "clear"))
14187                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14188                                                      res->field_idx);
14189         if (ret) {
14190                 printf("Failed to configure input set field.\n");
14191                 return;
14192         }
14193
14194         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14195                                      &inset, inset_type);
14196         if (ret) {
14197                 printf("Failed to set input set.\n");
14198                 return;
14199         }
14200 #endif
14201
14202         if (ret == -ENOTSUP)
14203                 printf("Function not supported\n");
14204 }
14205
14206 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14207         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14208                                  port, "port");
14209 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14210         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14211                                  cfg, "config");
14212 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14213         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14214                               port_id, RTE_UINT16);
14215 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14216         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14217                                  pctype, "pctype");
14218 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14219         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14220                               pctype_id, RTE_UINT8);
14221 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14222         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14223                                  inset_type,
14224                                  "hash_inset#fdir_inset#fdir_flx_inset");
14225 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14226         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14227                                  opt, "get#set#clear");
14228 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14229         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14230                                  field, "field");
14231 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14232         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14233                               field_idx, RTE_UINT8);
14234
14235 cmdline_parse_inst_t cmd_cfg_input_set = {
14236         .f = cmd_cfg_input_set_parsed,
14237         .data = NULL,
14238         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14239                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14240         .tokens = {
14241                 (void *)&cmd_cfg_input_set_port,
14242                 (void *)&cmd_cfg_input_set_cfg,
14243                 (void *)&cmd_cfg_input_set_port_id,
14244                 (void *)&cmd_cfg_input_set_pctype,
14245                 (void *)&cmd_cfg_input_set_pctype_id,
14246                 (void *)&cmd_cfg_input_set_inset_type,
14247                 (void *)&cmd_cfg_input_set_opt,
14248                 (void *)&cmd_cfg_input_set_field,
14249                 (void *)&cmd_cfg_input_set_field_idx,
14250                 NULL,
14251         },
14252 };
14253
14254 /* Clear input set */
14255 struct cmd_clear_input_set_result {
14256         cmdline_fixed_string_t port;
14257         cmdline_fixed_string_t cfg;
14258         portid_t port_id;
14259         cmdline_fixed_string_t pctype;
14260         uint8_t pctype_id;
14261         cmdline_fixed_string_t inset_type;
14262         cmdline_fixed_string_t clear;
14263         cmdline_fixed_string_t all;
14264 };
14265
14266 static void
14267 cmd_clear_input_set_parsed(
14268         __rte_unused void *parsed_result,
14269         __rte_unused struct cmdline *cl,
14270         __rte_unused void *data)
14271 {
14272 #ifdef RTE_NET_I40E
14273         struct cmd_clear_input_set_result *res = parsed_result;
14274         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14275         struct rte_pmd_i40e_inset inset;
14276 #endif
14277         int ret = -ENOTSUP;
14278
14279         if (!all_ports_stopped()) {
14280                 printf("Please stop all ports first\n");
14281                 return;
14282         }
14283
14284 #ifdef RTE_NET_I40E
14285         if (!strcmp(res->inset_type, "hash_inset"))
14286                 inset_type = INSET_HASH;
14287         else if (!strcmp(res->inset_type, "fdir_inset"))
14288                 inset_type = INSET_FDIR;
14289         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14290                 inset_type = INSET_FDIR_FLX;
14291
14292         memset(&inset, 0, sizeof(inset));
14293
14294         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14295                                      &inset, inset_type);
14296         if (ret) {
14297                 printf("Failed to clear input set.\n");
14298                 return;
14299         }
14300
14301 #endif
14302
14303         if (ret == -ENOTSUP)
14304                 printf("Function not supported\n");
14305 }
14306
14307 cmdline_parse_token_string_t cmd_clear_input_set_port =
14308         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14309                                  port, "port");
14310 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14311         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14312                                  cfg, "config");
14313 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14314         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14315                               port_id, RTE_UINT16);
14316 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14317         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14318                                  pctype, "pctype");
14319 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14320         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14321                               pctype_id, RTE_UINT8);
14322 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14323         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14324                                  inset_type,
14325                                  "hash_inset#fdir_inset#fdir_flx_inset");
14326 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14327         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14328                                  clear, "clear");
14329 cmdline_parse_token_string_t cmd_clear_input_set_all =
14330         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14331                                  all, "all");
14332
14333 cmdline_parse_inst_t cmd_clear_input_set = {
14334         .f = cmd_clear_input_set_parsed,
14335         .data = NULL,
14336         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14337                     "fdir_inset|fdir_flx_inset clear all",
14338         .tokens = {
14339                 (void *)&cmd_clear_input_set_port,
14340                 (void *)&cmd_clear_input_set_cfg,
14341                 (void *)&cmd_clear_input_set_port_id,
14342                 (void *)&cmd_clear_input_set_pctype,
14343                 (void *)&cmd_clear_input_set_pctype_id,
14344                 (void *)&cmd_clear_input_set_inset_type,
14345                 (void *)&cmd_clear_input_set_clear,
14346                 (void *)&cmd_clear_input_set_all,
14347                 NULL,
14348         },
14349 };
14350
14351 /* show vf stats */
14352
14353 /* Common result structure for show vf stats */
14354 struct cmd_show_vf_stats_result {
14355         cmdline_fixed_string_t show;
14356         cmdline_fixed_string_t vf;
14357         cmdline_fixed_string_t stats;
14358         portid_t port_id;
14359         uint16_t vf_id;
14360 };
14361
14362 /* Common CLI fields show vf stats*/
14363 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14364         TOKEN_STRING_INITIALIZER
14365                 (struct cmd_show_vf_stats_result,
14366                  show, "show");
14367 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_show_vf_stats_result,
14370                  vf, "vf");
14371 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14372         TOKEN_STRING_INITIALIZER
14373                 (struct cmd_show_vf_stats_result,
14374                  stats, "stats");
14375 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14376         TOKEN_NUM_INITIALIZER
14377                 (struct cmd_show_vf_stats_result,
14378                  port_id, RTE_UINT16);
14379 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14380         TOKEN_NUM_INITIALIZER
14381                 (struct cmd_show_vf_stats_result,
14382                  vf_id, RTE_UINT16);
14383
14384 static void
14385 cmd_show_vf_stats_parsed(
14386         void *parsed_result,
14387         __rte_unused struct cmdline *cl,
14388         __rte_unused void *data)
14389 {
14390         struct cmd_show_vf_stats_result *res = parsed_result;
14391         struct rte_eth_stats stats;
14392         int ret = -ENOTSUP;
14393         static const char *nic_stats_border = "########################";
14394
14395         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14396                 return;
14397
14398         memset(&stats, 0, sizeof(stats));
14399
14400 #ifdef RTE_NET_I40E
14401         if (ret == -ENOTSUP)
14402                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14403                                                 res->vf_id,
14404                                                 &stats);
14405 #endif
14406 #ifdef RTE_NET_BNXT
14407         if (ret == -ENOTSUP)
14408                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14409                                                 res->vf_id,
14410                                                 &stats);
14411 #endif
14412
14413         switch (ret) {
14414         case 0:
14415                 break;
14416         case -EINVAL:
14417                 printf("invalid vf_id %d\n", res->vf_id);
14418                 break;
14419         case -ENODEV:
14420                 printf("invalid port_id %d\n", res->port_id);
14421                 break;
14422         case -ENOTSUP:
14423                 printf("function not implemented\n");
14424                 break;
14425         default:
14426                 printf("programming error: (%s)\n", strerror(-ret));
14427         }
14428
14429         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14430                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14431
14432         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14433                "%-"PRIu64"\n",
14434                stats.ipackets, stats.imissed, stats.ibytes);
14435         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14436         printf("  RX-nombuf:  %-10"PRIu64"\n",
14437                stats.rx_nombuf);
14438         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14439                "%-"PRIu64"\n",
14440                stats.opackets, stats.oerrors, stats.obytes);
14441
14442         printf("  %s############################%s\n",
14443                                nic_stats_border, nic_stats_border);
14444 }
14445
14446 cmdline_parse_inst_t cmd_show_vf_stats = {
14447         .f = cmd_show_vf_stats_parsed,
14448         .data = NULL,
14449         .help_str = "show vf stats <port_id> <vf_id>",
14450         .tokens = {
14451                 (void *)&cmd_show_vf_stats_show,
14452                 (void *)&cmd_show_vf_stats_vf,
14453                 (void *)&cmd_show_vf_stats_stats,
14454                 (void *)&cmd_show_vf_stats_port_id,
14455                 (void *)&cmd_show_vf_stats_vf_id,
14456                 NULL,
14457         },
14458 };
14459
14460 /* clear vf stats */
14461
14462 /* Common result structure for clear vf stats */
14463 struct cmd_clear_vf_stats_result {
14464         cmdline_fixed_string_t clear;
14465         cmdline_fixed_string_t vf;
14466         cmdline_fixed_string_t stats;
14467         portid_t port_id;
14468         uint16_t vf_id;
14469 };
14470
14471 /* Common CLI fields clear vf stats*/
14472 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14473         TOKEN_STRING_INITIALIZER
14474                 (struct cmd_clear_vf_stats_result,
14475                  clear, "clear");
14476 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14477         TOKEN_STRING_INITIALIZER
14478                 (struct cmd_clear_vf_stats_result,
14479                  vf, "vf");
14480 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14481         TOKEN_STRING_INITIALIZER
14482                 (struct cmd_clear_vf_stats_result,
14483                  stats, "stats");
14484 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14485         TOKEN_NUM_INITIALIZER
14486                 (struct cmd_clear_vf_stats_result,
14487                  port_id, RTE_UINT16);
14488 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14489         TOKEN_NUM_INITIALIZER
14490                 (struct cmd_clear_vf_stats_result,
14491                  vf_id, RTE_UINT16);
14492
14493 static void
14494 cmd_clear_vf_stats_parsed(
14495         void *parsed_result,
14496         __rte_unused struct cmdline *cl,
14497         __rte_unused void *data)
14498 {
14499         struct cmd_clear_vf_stats_result *res = parsed_result;
14500         int ret = -ENOTSUP;
14501
14502         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14503                 return;
14504
14505 #ifdef RTE_NET_I40E
14506         if (ret == -ENOTSUP)
14507                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14508                                                   res->vf_id);
14509 #endif
14510 #ifdef RTE_NET_BNXT
14511         if (ret == -ENOTSUP)
14512                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14513                                                   res->vf_id);
14514 #endif
14515
14516         switch (ret) {
14517         case 0:
14518                 break;
14519         case -EINVAL:
14520                 printf("invalid vf_id %d\n", res->vf_id);
14521                 break;
14522         case -ENODEV:
14523                 printf("invalid port_id %d\n", res->port_id);
14524                 break;
14525         case -ENOTSUP:
14526                 printf("function not implemented\n");
14527                 break;
14528         default:
14529                 printf("programming error: (%s)\n", strerror(-ret));
14530         }
14531 }
14532
14533 cmdline_parse_inst_t cmd_clear_vf_stats = {
14534         .f = cmd_clear_vf_stats_parsed,
14535         .data = NULL,
14536         .help_str = "clear vf stats <port_id> <vf_id>",
14537         .tokens = {
14538                 (void *)&cmd_clear_vf_stats_clear,
14539                 (void *)&cmd_clear_vf_stats_vf,
14540                 (void *)&cmd_clear_vf_stats_stats,
14541                 (void *)&cmd_clear_vf_stats_port_id,
14542                 (void *)&cmd_clear_vf_stats_vf_id,
14543                 NULL,
14544         },
14545 };
14546
14547 /* port config pctype mapping reset */
14548
14549 /* Common result structure for port config pctype mapping reset */
14550 struct cmd_pctype_mapping_reset_result {
14551         cmdline_fixed_string_t port;
14552         cmdline_fixed_string_t config;
14553         portid_t port_id;
14554         cmdline_fixed_string_t pctype;
14555         cmdline_fixed_string_t mapping;
14556         cmdline_fixed_string_t reset;
14557 };
14558
14559 /* Common CLI fields for port config pctype mapping reset*/
14560 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14561         TOKEN_STRING_INITIALIZER
14562                 (struct cmd_pctype_mapping_reset_result,
14563                  port, "port");
14564 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14565         TOKEN_STRING_INITIALIZER
14566                 (struct cmd_pctype_mapping_reset_result,
14567                  config, "config");
14568 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14569         TOKEN_NUM_INITIALIZER
14570                 (struct cmd_pctype_mapping_reset_result,
14571                  port_id, RTE_UINT16);
14572 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14573         TOKEN_STRING_INITIALIZER
14574                 (struct cmd_pctype_mapping_reset_result,
14575                  pctype, "pctype");
14576 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14577         TOKEN_STRING_INITIALIZER
14578                 (struct cmd_pctype_mapping_reset_result,
14579                  mapping, "mapping");
14580 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14581         TOKEN_STRING_INITIALIZER
14582                 (struct cmd_pctype_mapping_reset_result,
14583                  reset, "reset");
14584
14585 static void
14586 cmd_pctype_mapping_reset_parsed(
14587         void *parsed_result,
14588         __rte_unused struct cmdline *cl,
14589         __rte_unused void *data)
14590 {
14591         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14592         int ret = -ENOTSUP;
14593
14594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14595                 return;
14596
14597 #ifdef RTE_NET_I40E
14598         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14599 #endif
14600
14601         switch (ret) {
14602         case 0:
14603                 break;
14604         case -ENODEV:
14605                 printf("invalid port_id %d\n", res->port_id);
14606                 break;
14607         case -ENOTSUP:
14608                 printf("function not implemented\n");
14609                 break;
14610         default:
14611                 printf("programming error: (%s)\n", strerror(-ret));
14612         }
14613 }
14614
14615 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14616         .f = cmd_pctype_mapping_reset_parsed,
14617         .data = NULL,
14618         .help_str = "port config <port_id> pctype mapping reset",
14619         .tokens = {
14620                 (void *)&cmd_pctype_mapping_reset_port,
14621                 (void *)&cmd_pctype_mapping_reset_config,
14622                 (void *)&cmd_pctype_mapping_reset_port_id,
14623                 (void *)&cmd_pctype_mapping_reset_pctype,
14624                 (void *)&cmd_pctype_mapping_reset_mapping,
14625                 (void *)&cmd_pctype_mapping_reset_reset,
14626                 NULL,
14627         },
14628 };
14629
14630 /* show port pctype mapping */
14631
14632 /* Common result structure for show port pctype mapping */
14633 struct cmd_pctype_mapping_get_result {
14634         cmdline_fixed_string_t show;
14635         cmdline_fixed_string_t port;
14636         portid_t port_id;
14637         cmdline_fixed_string_t pctype;
14638         cmdline_fixed_string_t mapping;
14639 };
14640
14641 /* Common CLI fields for pctype mapping get */
14642 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14643         TOKEN_STRING_INITIALIZER
14644                 (struct cmd_pctype_mapping_get_result,
14645                  show, "show");
14646 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14647         TOKEN_STRING_INITIALIZER
14648                 (struct cmd_pctype_mapping_get_result,
14649                  port, "port");
14650 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14651         TOKEN_NUM_INITIALIZER
14652                 (struct cmd_pctype_mapping_get_result,
14653                  port_id, RTE_UINT16);
14654 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14655         TOKEN_STRING_INITIALIZER
14656                 (struct cmd_pctype_mapping_get_result,
14657                  pctype, "pctype");
14658 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14659         TOKEN_STRING_INITIALIZER
14660                 (struct cmd_pctype_mapping_get_result,
14661                  mapping, "mapping");
14662
14663 static void
14664 cmd_pctype_mapping_get_parsed(
14665         void *parsed_result,
14666         __rte_unused struct cmdline *cl,
14667         __rte_unused void *data)
14668 {
14669         struct cmd_pctype_mapping_get_result *res = parsed_result;
14670         int ret = -ENOTSUP;
14671 #ifdef RTE_NET_I40E
14672         struct rte_pmd_i40e_flow_type_mapping
14673                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14674         int i, j, first_pctype;
14675 #endif
14676
14677         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14678                 return;
14679
14680 #ifdef RTE_NET_I40E
14681         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14682 #endif
14683
14684         switch (ret) {
14685         case 0:
14686                 break;
14687         case -ENODEV:
14688                 printf("invalid port_id %d\n", res->port_id);
14689                 return;
14690         case -ENOTSUP:
14691                 printf("function not implemented\n");
14692                 return;
14693         default:
14694                 printf("programming error: (%s)\n", strerror(-ret));
14695                 return;
14696         }
14697
14698 #ifdef RTE_NET_I40E
14699         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14700                 if (mapping[i].pctype != 0ULL) {
14701                         first_pctype = 1;
14702
14703                         printf("pctype: ");
14704                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14705                                 if (mapping[i].pctype & (1ULL << j)) {
14706                                         printf(first_pctype ?
14707                                                "%02d" : ",%02d", j);
14708                                         first_pctype = 0;
14709                                 }
14710                         }
14711                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14712                 }
14713         }
14714 #endif
14715 }
14716
14717 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14718         .f = cmd_pctype_mapping_get_parsed,
14719         .data = NULL,
14720         .help_str = "show port <port_id> pctype mapping",
14721         .tokens = {
14722                 (void *)&cmd_pctype_mapping_get_show,
14723                 (void *)&cmd_pctype_mapping_get_port,
14724                 (void *)&cmd_pctype_mapping_get_port_id,
14725                 (void *)&cmd_pctype_mapping_get_pctype,
14726                 (void *)&cmd_pctype_mapping_get_mapping,
14727                 NULL,
14728         },
14729 };
14730
14731 /* port config pctype mapping update */
14732
14733 /* Common result structure for port config pctype mapping update */
14734 struct cmd_pctype_mapping_update_result {
14735         cmdline_fixed_string_t port;
14736         cmdline_fixed_string_t config;
14737         portid_t port_id;
14738         cmdline_fixed_string_t pctype;
14739         cmdline_fixed_string_t mapping;
14740         cmdline_fixed_string_t update;
14741         cmdline_fixed_string_t pctype_list;
14742         uint16_t flow_type;
14743 };
14744
14745 /* Common CLI fields for pctype mapping update*/
14746 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14747         TOKEN_STRING_INITIALIZER
14748                 (struct cmd_pctype_mapping_update_result,
14749                  port, "port");
14750 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14751         TOKEN_STRING_INITIALIZER
14752                 (struct cmd_pctype_mapping_update_result,
14753                  config, "config");
14754 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14755         TOKEN_NUM_INITIALIZER
14756                 (struct cmd_pctype_mapping_update_result,
14757                  port_id, RTE_UINT16);
14758 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14759         TOKEN_STRING_INITIALIZER
14760                 (struct cmd_pctype_mapping_update_result,
14761                  pctype, "pctype");
14762 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14763         TOKEN_STRING_INITIALIZER
14764                 (struct cmd_pctype_mapping_update_result,
14765                  mapping, "mapping");
14766 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14767         TOKEN_STRING_INITIALIZER
14768                 (struct cmd_pctype_mapping_update_result,
14769                  update, "update");
14770 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_pctype_mapping_update_result,
14773                  pctype_list, NULL);
14774 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14775         TOKEN_NUM_INITIALIZER
14776                 (struct cmd_pctype_mapping_update_result,
14777                  flow_type, RTE_UINT16);
14778
14779 static void
14780 cmd_pctype_mapping_update_parsed(
14781         void *parsed_result,
14782         __rte_unused struct cmdline *cl,
14783         __rte_unused void *data)
14784 {
14785         struct cmd_pctype_mapping_update_result *res = parsed_result;
14786         int ret = -ENOTSUP;
14787 #ifdef RTE_NET_I40E
14788         struct rte_pmd_i40e_flow_type_mapping mapping;
14789         unsigned int i;
14790         unsigned int nb_item;
14791         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14792 #endif
14793
14794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14795                 return;
14796
14797 #ifdef RTE_NET_I40E
14798         nb_item = parse_item_list(res->pctype_list, "pctypes",
14799                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14800         mapping.flow_type = res->flow_type;
14801         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14802                 mapping.pctype |= (1ULL << pctype_list[i]);
14803         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14804                                                 &mapping,
14805                                                 1,
14806                                                 0);
14807 #endif
14808
14809         switch (ret) {
14810         case 0:
14811                 break;
14812         case -EINVAL:
14813                 printf("invalid pctype or flow type\n");
14814                 break;
14815         case -ENODEV:
14816                 printf("invalid port_id %d\n", res->port_id);
14817                 break;
14818         case -ENOTSUP:
14819                 printf("function not implemented\n");
14820                 break;
14821         default:
14822                 printf("programming error: (%s)\n", strerror(-ret));
14823         }
14824 }
14825
14826 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14827         .f = cmd_pctype_mapping_update_parsed,
14828         .data = NULL,
14829         .help_str = "port config <port_id> pctype mapping update"
14830         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14831         .tokens = {
14832                 (void *)&cmd_pctype_mapping_update_port,
14833                 (void *)&cmd_pctype_mapping_update_config,
14834                 (void *)&cmd_pctype_mapping_update_port_id,
14835                 (void *)&cmd_pctype_mapping_update_pctype,
14836                 (void *)&cmd_pctype_mapping_update_mapping,
14837                 (void *)&cmd_pctype_mapping_update_update,
14838                 (void *)&cmd_pctype_mapping_update_pc_type,
14839                 (void *)&cmd_pctype_mapping_update_flow_type,
14840                 NULL,
14841         },
14842 };
14843
14844 /* ptype mapping get */
14845
14846 /* Common result structure for ptype mapping get */
14847 struct cmd_ptype_mapping_get_result {
14848         cmdline_fixed_string_t ptype;
14849         cmdline_fixed_string_t mapping;
14850         cmdline_fixed_string_t get;
14851         portid_t port_id;
14852         uint8_t valid_only;
14853 };
14854
14855 /* Common CLI fields for ptype mapping get */
14856 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14857         TOKEN_STRING_INITIALIZER
14858                 (struct cmd_ptype_mapping_get_result,
14859                  ptype, "ptype");
14860 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14861         TOKEN_STRING_INITIALIZER
14862                 (struct cmd_ptype_mapping_get_result,
14863                  mapping, "mapping");
14864 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14865         TOKEN_STRING_INITIALIZER
14866                 (struct cmd_ptype_mapping_get_result,
14867                  get, "get");
14868 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14869         TOKEN_NUM_INITIALIZER
14870                 (struct cmd_ptype_mapping_get_result,
14871                  port_id, RTE_UINT16);
14872 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14873         TOKEN_NUM_INITIALIZER
14874                 (struct cmd_ptype_mapping_get_result,
14875                  valid_only, RTE_UINT8);
14876
14877 static void
14878 cmd_ptype_mapping_get_parsed(
14879         void *parsed_result,
14880         __rte_unused struct cmdline *cl,
14881         __rte_unused void *data)
14882 {
14883         struct cmd_ptype_mapping_get_result *res = parsed_result;
14884         int ret = -ENOTSUP;
14885 #ifdef RTE_NET_I40E
14886         int max_ptype_num = 256;
14887         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14888         uint16_t count;
14889         int i;
14890 #endif
14891
14892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14893                 return;
14894
14895 #ifdef RTE_NET_I40E
14896         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14897                                         mapping,
14898                                         max_ptype_num,
14899                                         &count,
14900                                         res->valid_only);
14901 #endif
14902
14903         switch (ret) {
14904         case 0:
14905                 break;
14906         case -ENODEV:
14907                 printf("invalid port_id %d\n", res->port_id);
14908                 break;
14909         case -ENOTSUP:
14910                 printf("function not implemented\n");
14911                 break;
14912         default:
14913                 printf("programming error: (%s)\n", strerror(-ret));
14914         }
14915
14916 #ifdef RTE_NET_I40E
14917         if (!ret) {
14918                 for (i = 0; i < count; i++)
14919                         printf("%3d\t0x%08x\n",
14920                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14921         }
14922 #endif
14923 }
14924
14925 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14926         .f = cmd_ptype_mapping_get_parsed,
14927         .data = NULL,
14928         .help_str = "ptype mapping get <port_id> <valid_only>",
14929         .tokens = {
14930                 (void *)&cmd_ptype_mapping_get_ptype,
14931                 (void *)&cmd_ptype_mapping_get_mapping,
14932                 (void *)&cmd_ptype_mapping_get_get,
14933                 (void *)&cmd_ptype_mapping_get_port_id,
14934                 (void *)&cmd_ptype_mapping_get_valid_only,
14935                 NULL,
14936         },
14937 };
14938
14939 /* ptype mapping replace */
14940
14941 /* Common result structure for ptype mapping replace */
14942 struct cmd_ptype_mapping_replace_result {
14943         cmdline_fixed_string_t ptype;
14944         cmdline_fixed_string_t mapping;
14945         cmdline_fixed_string_t replace;
14946         portid_t port_id;
14947         uint32_t target;
14948         uint8_t mask;
14949         uint32_t pkt_type;
14950 };
14951
14952 /* Common CLI fields for ptype mapping replace */
14953 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14954         TOKEN_STRING_INITIALIZER
14955                 (struct cmd_ptype_mapping_replace_result,
14956                  ptype, "ptype");
14957 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14958         TOKEN_STRING_INITIALIZER
14959                 (struct cmd_ptype_mapping_replace_result,
14960                  mapping, "mapping");
14961 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14962         TOKEN_STRING_INITIALIZER
14963                 (struct cmd_ptype_mapping_replace_result,
14964                  replace, "replace");
14965 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14966         TOKEN_NUM_INITIALIZER
14967                 (struct cmd_ptype_mapping_replace_result,
14968                  port_id, RTE_UINT16);
14969 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14970         TOKEN_NUM_INITIALIZER
14971                 (struct cmd_ptype_mapping_replace_result,
14972                  target, RTE_UINT32);
14973 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14974         TOKEN_NUM_INITIALIZER
14975                 (struct cmd_ptype_mapping_replace_result,
14976                  mask, RTE_UINT8);
14977 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14978         TOKEN_NUM_INITIALIZER
14979                 (struct cmd_ptype_mapping_replace_result,
14980                  pkt_type, RTE_UINT32);
14981
14982 static void
14983 cmd_ptype_mapping_replace_parsed(
14984         void *parsed_result,
14985         __rte_unused struct cmdline *cl,
14986         __rte_unused void *data)
14987 {
14988         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14989         int ret = -ENOTSUP;
14990
14991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14992                 return;
14993
14994 #ifdef RTE_NET_I40E
14995         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14996                                         res->target,
14997                                         res->mask,
14998                                         res->pkt_type);
14999 #endif
15000
15001         switch (ret) {
15002         case 0:
15003                 break;
15004         case -EINVAL:
15005                 printf("invalid ptype 0x%8x or 0x%8x\n",
15006                                 res->target, res->pkt_type);
15007                 break;
15008         case -ENODEV:
15009                 printf("invalid port_id %d\n", res->port_id);
15010                 break;
15011         case -ENOTSUP:
15012                 printf("function not implemented\n");
15013                 break;
15014         default:
15015                 printf("programming error: (%s)\n", strerror(-ret));
15016         }
15017 }
15018
15019 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15020         .f = cmd_ptype_mapping_replace_parsed,
15021         .data = NULL,
15022         .help_str =
15023                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15024         .tokens = {
15025                 (void *)&cmd_ptype_mapping_replace_ptype,
15026                 (void *)&cmd_ptype_mapping_replace_mapping,
15027                 (void *)&cmd_ptype_mapping_replace_replace,
15028                 (void *)&cmd_ptype_mapping_replace_port_id,
15029                 (void *)&cmd_ptype_mapping_replace_target,
15030                 (void *)&cmd_ptype_mapping_replace_mask,
15031                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15032                 NULL,
15033         },
15034 };
15035
15036 /* ptype mapping reset */
15037
15038 /* Common result structure for ptype mapping reset */
15039 struct cmd_ptype_mapping_reset_result {
15040         cmdline_fixed_string_t ptype;
15041         cmdline_fixed_string_t mapping;
15042         cmdline_fixed_string_t reset;
15043         portid_t port_id;
15044 };
15045
15046 /* Common CLI fields for ptype mapping reset*/
15047 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15048         TOKEN_STRING_INITIALIZER
15049                 (struct cmd_ptype_mapping_reset_result,
15050                  ptype, "ptype");
15051 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15052         TOKEN_STRING_INITIALIZER
15053                 (struct cmd_ptype_mapping_reset_result,
15054                  mapping, "mapping");
15055 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15056         TOKEN_STRING_INITIALIZER
15057                 (struct cmd_ptype_mapping_reset_result,
15058                  reset, "reset");
15059 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15060         TOKEN_NUM_INITIALIZER
15061                 (struct cmd_ptype_mapping_reset_result,
15062                  port_id, RTE_UINT16);
15063
15064 static void
15065 cmd_ptype_mapping_reset_parsed(
15066         void *parsed_result,
15067         __rte_unused struct cmdline *cl,
15068         __rte_unused void *data)
15069 {
15070         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15071         int ret = -ENOTSUP;
15072
15073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15074                 return;
15075
15076 #ifdef RTE_NET_I40E
15077         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15078 #endif
15079
15080         switch (ret) {
15081         case 0:
15082                 break;
15083         case -ENODEV:
15084                 printf("invalid port_id %d\n", res->port_id);
15085                 break;
15086         case -ENOTSUP:
15087                 printf("function not implemented\n");
15088                 break;
15089         default:
15090                 printf("programming error: (%s)\n", strerror(-ret));
15091         }
15092 }
15093
15094 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15095         .f = cmd_ptype_mapping_reset_parsed,
15096         .data = NULL,
15097         .help_str = "ptype mapping reset <port_id>",
15098         .tokens = {
15099                 (void *)&cmd_ptype_mapping_reset_ptype,
15100                 (void *)&cmd_ptype_mapping_reset_mapping,
15101                 (void *)&cmd_ptype_mapping_reset_reset,
15102                 (void *)&cmd_ptype_mapping_reset_port_id,
15103                 NULL,
15104         },
15105 };
15106
15107 /* ptype mapping update */
15108
15109 /* Common result structure for ptype mapping update */
15110 struct cmd_ptype_mapping_update_result {
15111         cmdline_fixed_string_t ptype;
15112         cmdline_fixed_string_t mapping;
15113         cmdline_fixed_string_t reset;
15114         portid_t port_id;
15115         uint8_t hw_ptype;
15116         uint32_t sw_ptype;
15117 };
15118
15119 /* Common CLI fields for ptype mapping update*/
15120 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15121         TOKEN_STRING_INITIALIZER
15122                 (struct cmd_ptype_mapping_update_result,
15123                  ptype, "ptype");
15124 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15125         TOKEN_STRING_INITIALIZER
15126                 (struct cmd_ptype_mapping_update_result,
15127                  mapping, "mapping");
15128 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15129         TOKEN_STRING_INITIALIZER
15130                 (struct cmd_ptype_mapping_update_result,
15131                  reset, "update");
15132 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15133         TOKEN_NUM_INITIALIZER
15134                 (struct cmd_ptype_mapping_update_result,
15135                  port_id, RTE_UINT16);
15136 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15137         TOKEN_NUM_INITIALIZER
15138                 (struct cmd_ptype_mapping_update_result,
15139                  hw_ptype, RTE_UINT8);
15140 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15141         TOKEN_NUM_INITIALIZER
15142                 (struct cmd_ptype_mapping_update_result,
15143                  sw_ptype, RTE_UINT32);
15144
15145 static void
15146 cmd_ptype_mapping_update_parsed(
15147         void *parsed_result,
15148         __rte_unused struct cmdline *cl,
15149         __rte_unused void *data)
15150 {
15151         struct cmd_ptype_mapping_update_result *res = parsed_result;
15152         int ret = -ENOTSUP;
15153 #ifdef RTE_NET_I40E
15154         struct rte_pmd_i40e_ptype_mapping mapping;
15155 #endif
15156         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15157                 return;
15158
15159 #ifdef RTE_NET_I40E
15160         mapping.hw_ptype = res->hw_ptype;
15161         mapping.sw_ptype = res->sw_ptype;
15162         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15163                                                 &mapping,
15164                                                 1,
15165                                                 0);
15166 #endif
15167
15168         switch (ret) {
15169         case 0:
15170                 break;
15171         case -EINVAL:
15172                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15173                 break;
15174         case -ENODEV:
15175                 printf("invalid port_id %d\n", res->port_id);
15176                 break;
15177         case -ENOTSUP:
15178                 printf("function not implemented\n");
15179                 break;
15180         default:
15181                 printf("programming error: (%s)\n", strerror(-ret));
15182         }
15183 }
15184
15185 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15186         .f = cmd_ptype_mapping_update_parsed,
15187         .data = NULL,
15188         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15189         .tokens = {
15190                 (void *)&cmd_ptype_mapping_update_ptype,
15191                 (void *)&cmd_ptype_mapping_update_mapping,
15192                 (void *)&cmd_ptype_mapping_update_update,
15193                 (void *)&cmd_ptype_mapping_update_port_id,
15194                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15195                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15196                 NULL,
15197         },
15198 };
15199
15200 /* Common result structure for file commands */
15201 struct cmd_cmdfile_result {
15202         cmdline_fixed_string_t load;
15203         cmdline_fixed_string_t filename;
15204 };
15205
15206 /* Common CLI fields for file commands */
15207 cmdline_parse_token_string_t cmd_load_cmdfile =
15208         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15209 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15210         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15211
15212 static void
15213 cmd_load_from_file_parsed(
15214         void *parsed_result,
15215         __rte_unused struct cmdline *cl,
15216         __rte_unused void *data)
15217 {
15218         struct cmd_cmdfile_result *res = parsed_result;
15219
15220         cmdline_read_from_file(res->filename);
15221 }
15222
15223 cmdline_parse_inst_t cmd_load_from_file = {
15224         .f = cmd_load_from_file_parsed,
15225         .data = NULL,
15226         .help_str = "load <filename>",
15227         .tokens = {
15228                 (void *)&cmd_load_cmdfile,
15229                 (void *)&cmd_load_cmdfile_filename,
15230                 NULL,
15231         },
15232 };
15233
15234 /* Get Rx offloads capabilities */
15235 struct cmd_rx_offload_get_capa_result {
15236         cmdline_fixed_string_t show;
15237         cmdline_fixed_string_t port;
15238         portid_t port_id;
15239         cmdline_fixed_string_t rx_offload;
15240         cmdline_fixed_string_t capabilities;
15241 };
15242
15243 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15244         TOKEN_STRING_INITIALIZER
15245                 (struct cmd_rx_offload_get_capa_result,
15246                  show, "show");
15247 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15248         TOKEN_STRING_INITIALIZER
15249                 (struct cmd_rx_offload_get_capa_result,
15250                  port, "port");
15251 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15252         TOKEN_NUM_INITIALIZER
15253                 (struct cmd_rx_offload_get_capa_result,
15254                  port_id, RTE_UINT16);
15255 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15256         TOKEN_STRING_INITIALIZER
15257                 (struct cmd_rx_offload_get_capa_result,
15258                  rx_offload, "rx_offload");
15259 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15260         TOKEN_STRING_INITIALIZER
15261                 (struct cmd_rx_offload_get_capa_result,
15262                  capabilities, "capabilities");
15263
15264 static void
15265 print_rx_offloads(uint64_t offloads)
15266 {
15267         uint64_t single_offload;
15268         int begin;
15269         int end;
15270         int bit;
15271
15272         if (offloads == 0)
15273                 return;
15274
15275         begin = __builtin_ctzll(offloads);
15276         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15277
15278         single_offload = 1ULL << begin;
15279         for (bit = begin; bit < end; bit++) {
15280                 if (offloads & single_offload)
15281                         printf(" %s",
15282                                rte_eth_dev_rx_offload_name(single_offload));
15283                 single_offload <<= 1;
15284         }
15285 }
15286
15287 static void
15288 cmd_rx_offload_get_capa_parsed(
15289         void *parsed_result,
15290         __rte_unused struct cmdline *cl,
15291         __rte_unused void *data)
15292 {
15293         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15294         struct rte_eth_dev_info dev_info;
15295         portid_t port_id = res->port_id;
15296         uint64_t queue_offloads;
15297         uint64_t port_offloads;
15298         int ret;
15299
15300         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15301         if (ret != 0)
15302                 return;
15303
15304         queue_offloads = dev_info.rx_queue_offload_capa;
15305         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15306
15307         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15308         printf("  Per Queue :");
15309         print_rx_offloads(queue_offloads);
15310
15311         printf("\n");
15312         printf("  Per Port  :");
15313         print_rx_offloads(port_offloads);
15314         printf("\n\n");
15315 }
15316
15317 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15318         .f = cmd_rx_offload_get_capa_parsed,
15319         .data = NULL,
15320         .help_str = "show port <port_id> rx_offload capabilities",
15321         .tokens = {
15322                 (void *)&cmd_rx_offload_get_capa_show,
15323                 (void *)&cmd_rx_offload_get_capa_port,
15324                 (void *)&cmd_rx_offload_get_capa_port_id,
15325                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15326                 (void *)&cmd_rx_offload_get_capa_capabilities,
15327                 NULL,
15328         }
15329 };
15330
15331 /* Get Rx offloads configuration */
15332 struct cmd_rx_offload_get_configuration_result {
15333         cmdline_fixed_string_t show;
15334         cmdline_fixed_string_t port;
15335         portid_t port_id;
15336         cmdline_fixed_string_t rx_offload;
15337         cmdline_fixed_string_t configuration;
15338 };
15339
15340 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15341         TOKEN_STRING_INITIALIZER
15342                 (struct cmd_rx_offload_get_configuration_result,
15343                  show, "show");
15344 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15345         TOKEN_STRING_INITIALIZER
15346                 (struct cmd_rx_offload_get_configuration_result,
15347                  port, "port");
15348 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15349         TOKEN_NUM_INITIALIZER
15350                 (struct cmd_rx_offload_get_configuration_result,
15351                  port_id, RTE_UINT16);
15352 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15353         TOKEN_STRING_INITIALIZER
15354                 (struct cmd_rx_offload_get_configuration_result,
15355                  rx_offload, "rx_offload");
15356 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15357         TOKEN_STRING_INITIALIZER
15358                 (struct cmd_rx_offload_get_configuration_result,
15359                  configuration, "configuration");
15360
15361 static void
15362 cmd_rx_offload_get_configuration_parsed(
15363         void *parsed_result,
15364         __rte_unused struct cmdline *cl,
15365         __rte_unused void *data)
15366 {
15367         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15368         struct rte_eth_dev_info dev_info;
15369         portid_t port_id = res->port_id;
15370         struct rte_port *port = &ports[port_id];
15371         uint64_t port_offloads;
15372         uint64_t queue_offloads;
15373         uint16_t nb_rx_queues;
15374         int q;
15375         int ret;
15376
15377         printf("Rx Offloading Configuration of port %d :\n", port_id);
15378
15379         port_offloads = port->dev_conf.rxmode.offloads;
15380         printf("  Port :");
15381         print_rx_offloads(port_offloads);
15382         printf("\n");
15383
15384         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15385         if (ret != 0)
15386                 return;
15387
15388         nb_rx_queues = dev_info.nb_rx_queues;
15389         for (q = 0; q < nb_rx_queues; q++) {
15390                 queue_offloads = port->rx_conf[q].offloads;
15391                 printf("  Queue[%2d] :", q);
15392                 print_rx_offloads(queue_offloads);
15393                 printf("\n");
15394         }
15395         printf("\n");
15396 }
15397
15398 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15399         .f = cmd_rx_offload_get_configuration_parsed,
15400         .data = NULL,
15401         .help_str = "show port <port_id> rx_offload configuration",
15402         .tokens = {
15403                 (void *)&cmd_rx_offload_get_configuration_show,
15404                 (void *)&cmd_rx_offload_get_configuration_port,
15405                 (void *)&cmd_rx_offload_get_configuration_port_id,
15406                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15407                 (void *)&cmd_rx_offload_get_configuration_configuration,
15408                 NULL,
15409         }
15410 };
15411
15412 /* Enable/Disable a per port offloading */
15413 struct cmd_config_per_port_rx_offload_result {
15414         cmdline_fixed_string_t port;
15415         cmdline_fixed_string_t config;
15416         portid_t port_id;
15417         cmdline_fixed_string_t rx_offload;
15418         cmdline_fixed_string_t offload;
15419         cmdline_fixed_string_t on_off;
15420 };
15421
15422 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15423         TOKEN_STRING_INITIALIZER
15424                 (struct cmd_config_per_port_rx_offload_result,
15425                  port, "port");
15426 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15427         TOKEN_STRING_INITIALIZER
15428                 (struct cmd_config_per_port_rx_offload_result,
15429                  config, "config");
15430 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15431         TOKEN_NUM_INITIALIZER
15432                 (struct cmd_config_per_port_rx_offload_result,
15433                  port_id, RTE_UINT16);
15434 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15435         TOKEN_STRING_INITIALIZER
15436                 (struct cmd_config_per_port_rx_offload_result,
15437                  rx_offload, "rx_offload");
15438 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15439         TOKEN_STRING_INITIALIZER
15440                 (struct cmd_config_per_port_rx_offload_result,
15441                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15442                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15443                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15444                            "scatter#buffer_split#timestamp#security#"
15445                            "keep_crc#rss_hash");
15446 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15447         TOKEN_STRING_INITIALIZER
15448                 (struct cmd_config_per_port_rx_offload_result,
15449                  on_off, "on#off");
15450
15451 static uint64_t
15452 search_rx_offload(const char *name)
15453 {
15454         uint64_t single_offload;
15455         const char *single_name;
15456         int found = 0;
15457         unsigned int bit;
15458
15459         single_offload = 1;
15460         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15461                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15462                 if (!strcasecmp(single_name, name)) {
15463                         found = 1;
15464                         break;
15465                 }
15466                 single_offload <<= 1;
15467         }
15468
15469         if (found)
15470                 return single_offload;
15471
15472         return 0;
15473 }
15474
15475 static void
15476 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15477                                 __rte_unused struct cmdline *cl,
15478                                 __rte_unused void *data)
15479 {
15480         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15481         portid_t port_id = res->port_id;
15482         struct rte_eth_dev_info dev_info;
15483         struct rte_port *port = &ports[port_id];
15484         uint64_t single_offload;
15485         uint16_t nb_rx_queues;
15486         int q;
15487         int ret;
15488
15489         if (port->port_status != RTE_PORT_STOPPED) {
15490                 printf("Error: Can't config offload when Port %d "
15491                        "is not stopped\n", port_id);
15492                 return;
15493         }
15494
15495         single_offload = search_rx_offload(res->offload);
15496         if (single_offload == 0) {
15497                 printf("Unknown offload name: %s\n", res->offload);
15498                 return;
15499         }
15500
15501         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15502         if (ret != 0)
15503                 return;
15504
15505         nb_rx_queues = dev_info.nb_rx_queues;
15506         if (!strcmp(res->on_off, "on")) {
15507                 port->dev_conf.rxmode.offloads |= single_offload;
15508                 for (q = 0; q < nb_rx_queues; q++)
15509                         port->rx_conf[q].offloads |= single_offload;
15510         } else {
15511                 port->dev_conf.rxmode.offloads &= ~single_offload;
15512                 for (q = 0; q < nb_rx_queues; q++)
15513                         port->rx_conf[q].offloads &= ~single_offload;
15514         }
15515
15516         cmd_reconfig_device_queue(port_id, 1, 1);
15517 }
15518
15519 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15520         .f = cmd_config_per_port_rx_offload_parsed,
15521         .data = NULL,
15522         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15523                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15524                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15525                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15526                     "keep_crc|rss_hash on|off",
15527         .tokens = {
15528                 (void *)&cmd_config_per_port_rx_offload_result_port,
15529                 (void *)&cmd_config_per_port_rx_offload_result_config,
15530                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15531                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15532                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15533                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15534                 NULL,
15535         }
15536 };
15537
15538 /* Enable/Disable a per queue offloading */
15539 struct cmd_config_per_queue_rx_offload_result {
15540         cmdline_fixed_string_t port;
15541         portid_t port_id;
15542         cmdline_fixed_string_t rxq;
15543         uint16_t queue_id;
15544         cmdline_fixed_string_t rx_offload;
15545         cmdline_fixed_string_t offload;
15546         cmdline_fixed_string_t on_off;
15547 };
15548
15549 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15550         TOKEN_STRING_INITIALIZER
15551                 (struct cmd_config_per_queue_rx_offload_result,
15552                  port, "port");
15553 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15554         TOKEN_NUM_INITIALIZER
15555                 (struct cmd_config_per_queue_rx_offload_result,
15556                  port_id, RTE_UINT16);
15557 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15558         TOKEN_STRING_INITIALIZER
15559                 (struct cmd_config_per_queue_rx_offload_result,
15560                  rxq, "rxq");
15561 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15562         TOKEN_NUM_INITIALIZER
15563                 (struct cmd_config_per_queue_rx_offload_result,
15564                  queue_id, RTE_UINT16);
15565 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15566         TOKEN_STRING_INITIALIZER
15567                 (struct cmd_config_per_queue_rx_offload_result,
15568                  rx_offload, "rx_offload");
15569 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15570         TOKEN_STRING_INITIALIZER
15571                 (struct cmd_config_per_queue_rx_offload_result,
15572                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15573                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15574                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15575                            "scatter#buffer_split#timestamp#security#keep_crc");
15576 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15577         TOKEN_STRING_INITIALIZER
15578                 (struct cmd_config_per_queue_rx_offload_result,
15579                  on_off, "on#off");
15580
15581 static void
15582 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15583                                 __rte_unused struct cmdline *cl,
15584                                 __rte_unused void *data)
15585 {
15586         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15587         struct rte_eth_dev_info dev_info;
15588         portid_t port_id = res->port_id;
15589         uint16_t queue_id = res->queue_id;
15590         struct rte_port *port = &ports[port_id];
15591         uint64_t single_offload;
15592         int ret;
15593
15594         if (port->port_status != RTE_PORT_STOPPED) {
15595                 printf("Error: Can't config offload when Port %d "
15596                        "is not stopped\n", port_id);
15597                 return;
15598         }
15599
15600         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15601         if (ret != 0)
15602                 return;
15603
15604         if (queue_id >= dev_info.nb_rx_queues) {
15605                 printf("Error: input queue_id should be 0 ... "
15606                        "%d\n", dev_info.nb_rx_queues - 1);
15607                 return;
15608         }
15609
15610         single_offload = search_rx_offload(res->offload);
15611         if (single_offload == 0) {
15612                 printf("Unknown offload name: %s\n", res->offload);
15613                 return;
15614         }
15615
15616         if (!strcmp(res->on_off, "on"))
15617                 port->rx_conf[queue_id].offloads |= single_offload;
15618         else
15619                 port->rx_conf[queue_id].offloads &= ~single_offload;
15620
15621         cmd_reconfig_device_queue(port_id, 1, 1);
15622 }
15623
15624 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15625         .f = cmd_config_per_queue_rx_offload_parsed,
15626         .data = NULL,
15627         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15628                     "vlan_strip|ipv4_cksum|"
15629                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15630                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15631                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15632                     "keep_crc on|off",
15633         .tokens = {
15634                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15635                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15636                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15637                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15638                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15639                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15640                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15641                 NULL,
15642         }
15643 };
15644
15645 /* Get Tx offloads capabilities */
15646 struct cmd_tx_offload_get_capa_result {
15647         cmdline_fixed_string_t show;
15648         cmdline_fixed_string_t port;
15649         portid_t port_id;
15650         cmdline_fixed_string_t tx_offload;
15651         cmdline_fixed_string_t capabilities;
15652 };
15653
15654 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15655         TOKEN_STRING_INITIALIZER
15656                 (struct cmd_tx_offload_get_capa_result,
15657                  show, "show");
15658 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15659         TOKEN_STRING_INITIALIZER
15660                 (struct cmd_tx_offload_get_capa_result,
15661                  port, "port");
15662 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15663         TOKEN_NUM_INITIALIZER
15664                 (struct cmd_tx_offload_get_capa_result,
15665                  port_id, RTE_UINT16);
15666 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15667         TOKEN_STRING_INITIALIZER
15668                 (struct cmd_tx_offload_get_capa_result,
15669                  tx_offload, "tx_offload");
15670 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15671         TOKEN_STRING_INITIALIZER
15672                 (struct cmd_tx_offload_get_capa_result,
15673                  capabilities, "capabilities");
15674
15675 static void
15676 print_tx_offloads(uint64_t offloads)
15677 {
15678         uint64_t single_offload;
15679         int begin;
15680         int end;
15681         int bit;
15682
15683         if (offloads == 0)
15684                 return;
15685
15686         begin = __builtin_ctzll(offloads);
15687         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15688
15689         single_offload = 1ULL << begin;
15690         for (bit = begin; bit < end; bit++) {
15691                 if (offloads & single_offload)
15692                         printf(" %s",
15693                                rte_eth_dev_tx_offload_name(single_offload));
15694                 single_offload <<= 1;
15695         }
15696 }
15697
15698 static void
15699 cmd_tx_offload_get_capa_parsed(
15700         void *parsed_result,
15701         __rte_unused struct cmdline *cl,
15702         __rte_unused void *data)
15703 {
15704         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15705         struct rte_eth_dev_info dev_info;
15706         portid_t port_id = res->port_id;
15707         uint64_t queue_offloads;
15708         uint64_t port_offloads;
15709         int ret;
15710
15711         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15712         if (ret != 0)
15713                 return;
15714
15715         queue_offloads = dev_info.tx_queue_offload_capa;
15716         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15717
15718         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15719         printf("  Per Queue :");
15720         print_tx_offloads(queue_offloads);
15721
15722         printf("\n");
15723         printf("  Per Port  :");
15724         print_tx_offloads(port_offloads);
15725         printf("\n\n");
15726 }
15727
15728 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15729         .f = cmd_tx_offload_get_capa_parsed,
15730         .data = NULL,
15731         .help_str = "show port <port_id> tx_offload capabilities",
15732         .tokens = {
15733                 (void *)&cmd_tx_offload_get_capa_show,
15734                 (void *)&cmd_tx_offload_get_capa_port,
15735                 (void *)&cmd_tx_offload_get_capa_port_id,
15736                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15737                 (void *)&cmd_tx_offload_get_capa_capabilities,
15738                 NULL,
15739         }
15740 };
15741
15742 /* Get Tx offloads configuration */
15743 struct cmd_tx_offload_get_configuration_result {
15744         cmdline_fixed_string_t show;
15745         cmdline_fixed_string_t port;
15746         portid_t port_id;
15747         cmdline_fixed_string_t tx_offload;
15748         cmdline_fixed_string_t configuration;
15749 };
15750
15751 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15752         TOKEN_STRING_INITIALIZER
15753                 (struct cmd_tx_offload_get_configuration_result,
15754                  show, "show");
15755 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15756         TOKEN_STRING_INITIALIZER
15757                 (struct cmd_tx_offload_get_configuration_result,
15758                  port, "port");
15759 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15760         TOKEN_NUM_INITIALIZER
15761                 (struct cmd_tx_offload_get_configuration_result,
15762                  port_id, RTE_UINT16);
15763 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15764         TOKEN_STRING_INITIALIZER
15765                 (struct cmd_tx_offload_get_configuration_result,
15766                  tx_offload, "tx_offload");
15767 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15768         TOKEN_STRING_INITIALIZER
15769                 (struct cmd_tx_offload_get_configuration_result,
15770                  configuration, "configuration");
15771
15772 static void
15773 cmd_tx_offload_get_configuration_parsed(
15774         void *parsed_result,
15775         __rte_unused struct cmdline *cl,
15776         __rte_unused void *data)
15777 {
15778         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15779         struct rte_eth_dev_info dev_info;
15780         portid_t port_id = res->port_id;
15781         struct rte_port *port = &ports[port_id];
15782         uint64_t port_offloads;
15783         uint64_t queue_offloads;
15784         uint16_t nb_tx_queues;
15785         int q;
15786         int ret;
15787
15788         printf("Tx Offloading Configuration of port %d :\n", port_id);
15789
15790         port_offloads = port->dev_conf.txmode.offloads;
15791         printf("  Port :");
15792         print_tx_offloads(port_offloads);
15793         printf("\n");
15794
15795         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15796         if (ret != 0)
15797                 return;
15798
15799         nb_tx_queues = dev_info.nb_tx_queues;
15800         for (q = 0; q < nb_tx_queues; q++) {
15801                 queue_offloads = port->tx_conf[q].offloads;
15802                 printf("  Queue[%2d] :", q);
15803                 print_tx_offloads(queue_offloads);
15804                 printf("\n");
15805         }
15806         printf("\n");
15807 }
15808
15809 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15810         .f = cmd_tx_offload_get_configuration_parsed,
15811         .data = NULL,
15812         .help_str = "show port <port_id> tx_offload configuration",
15813         .tokens = {
15814                 (void *)&cmd_tx_offload_get_configuration_show,
15815                 (void *)&cmd_tx_offload_get_configuration_port,
15816                 (void *)&cmd_tx_offload_get_configuration_port_id,
15817                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15818                 (void *)&cmd_tx_offload_get_configuration_configuration,
15819                 NULL,
15820         }
15821 };
15822
15823 /* Enable/Disable a per port offloading */
15824 struct cmd_config_per_port_tx_offload_result {
15825         cmdline_fixed_string_t port;
15826         cmdline_fixed_string_t config;
15827         portid_t port_id;
15828         cmdline_fixed_string_t tx_offload;
15829         cmdline_fixed_string_t offload;
15830         cmdline_fixed_string_t on_off;
15831 };
15832
15833 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15834         TOKEN_STRING_INITIALIZER
15835                 (struct cmd_config_per_port_tx_offload_result,
15836                  port, "port");
15837 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15838         TOKEN_STRING_INITIALIZER
15839                 (struct cmd_config_per_port_tx_offload_result,
15840                  config, "config");
15841 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15842         TOKEN_NUM_INITIALIZER
15843                 (struct cmd_config_per_port_tx_offload_result,
15844                  port_id, RTE_UINT16);
15845 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15846         TOKEN_STRING_INITIALIZER
15847                 (struct cmd_config_per_port_tx_offload_result,
15848                  tx_offload, "tx_offload");
15849 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15850         TOKEN_STRING_INITIALIZER
15851                 (struct cmd_config_per_port_tx_offload_result,
15852                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15853                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15854                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15855                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15856                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15857                           "send_on_timestamp");
15858 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15859         TOKEN_STRING_INITIALIZER
15860                 (struct cmd_config_per_port_tx_offload_result,
15861                  on_off, "on#off");
15862
15863 static uint64_t
15864 search_tx_offload(const char *name)
15865 {
15866         uint64_t single_offload;
15867         const char *single_name;
15868         int found = 0;
15869         unsigned int bit;
15870
15871         single_offload = 1;
15872         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15873                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15874                 if (single_name == NULL)
15875                         break;
15876                 if (!strcasecmp(single_name, name)) {
15877                         found = 1;
15878                         break;
15879                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15880                         break;
15881                 single_offload <<= 1;
15882         }
15883
15884         if (found)
15885                 return single_offload;
15886
15887         return 0;
15888 }
15889
15890 static void
15891 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15892                                 __rte_unused struct cmdline *cl,
15893                                 __rte_unused void *data)
15894 {
15895         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15896         portid_t port_id = res->port_id;
15897         struct rte_eth_dev_info dev_info;
15898         struct rte_port *port = &ports[port_id];
15899         uint64_t single_offload;
15900         uint16_t nb_tx_queues;
15901         int q;
15902         int ret;
15903
15904         if (port->port_status != RTE_PORT_STOPPED) {
15905                 printf("Error: Can't config offload when Port %d "
15906                        "is not stopped\n", port_id);
15907                 return;
15908         }
15909
15910         single_offload = search_tx_offload(res->offload);
15911         if (single_offload == 0) {
15912                 printf("Unknown offload name: %s\n", res->offload);
15913                 return;
15914         }
15915
15916         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15917         if (ret != 0)
15918                 return;
15919
15920         nb_tx_queues = dev_info.nb_tx_queues;
15921         if (!strcmp(res->on_off, "on")) {
15922                 port->dev_conf.txmode.offloads |= single_offload;
15923                 for (q = 0; q < nb_tx_queues; q++)
15924                         port->tx_conf[q].offloads |= single_offload;
15925         } else {
15926                 port->dev_conf.txmode.offloads &= ~single_offload;
15927                 for (q = 0; q < nb_tx_queues; q++)
15928                         port->tx_conf[q].offloads &= ~single_offload;
15929         }
15930
15931         cmd_reconfig_device_queue(port_id, 1, 1);
15932 }
15933
15934 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15935         .f = cmd_config_per_port_tx_offload_parsed,
15936         .data = NULL,
15937         .help_str = "port config <port_id> tx_offload "
15938                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15939                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15940                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15941                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15942                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15943                     "send_on_timestamp on|off",
15944         .tokens = {
15945                 (void *)&cmd_config_per_port_tx_offload_result_port,
15946                 (void *)&cmd_config_per_port_tx_offload_result_config,
15947                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15948                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15949                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15950                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15951                 NULL,
15952         }
15953 };
15954
15955 /* Enable/Disable a per queue offloading */
15956 struct cmd_config_per_queue_tx_offload_result {
15957         cmdline_fixed_string_t port;
15958         portid_t port_id;
15959         cmdline_fixed_string_t txq;
15960         uint16_t queue_id;
15961         cmdline_fixed_string_t tx_offload;
15962         cmdline_fixed_string_t offload;
15963         cmdline_fixed_string_t on_off;
15964 };
15965
15966 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15967         TOKEN_STRING_INITIALIZER
15968                 (struct cmd_config_per_queue_tx_offload_result,
15969                  port, "port");
15970 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15971         TOKEN_NUM_INITIALIZER
15972                 (struct cmd_config_per_queue_tx_offload_result,
15973                  port_id, RTE_UINT16);
15974 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15975         TOKEN_STRING_INITIALIZER
15976                 (struct cmd_config_per_queue_tx_offload_result,
15977                  txq, "txq");
15978 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15979         TOKEN_NUM_INITIALIZER
15980                 (struct cmd_config_per_queue_tx_offload_result,
15981                  queue_id, RTE_UINT16);
15982 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15983         TOKEN_STRING_INITIALIZER
15984                 (struct cmd_config_per_queue_tx_offload_result,
15985                  tx_offload, "tx_offload");
15986 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15987         TOKEN_STRING_INITIALIZER
15988                 (struct cmd_config_per_queue_tx_offload_result,
15989                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15990                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15991                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15992                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15993                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
15994 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
15995         TOKEN_STRING_INITIALIZER
15996                 (struct cmd_config_per_queue_tx_offload_result,
15997                  on_off, "on#off");
15998
15999 static void
16000 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16001                                 __rte_unused struct cmdline *cl,
16002                                 __rte_unused void *data)
16003 {
16004         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16005         struct rte_eth_dev_info dev_info;
16006         portid_t port_id = res->port_id;
16007         uint16_t queue_id = res->queue_id;
16008         struct rte_port *port = &ports[port_id];
16009         uint64_t single_offload;
16010         int ret;
16011
16012         if (port->port_status != RTE_PORT_STOPPED) {
16013                 printf("Error: Can't config offload when Port %d "
16014                        "is not stopped\n", port_id);
16015                 return;
16016         }
16017
16018         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16019         if (ret != 0)
16020                 return;
16021
16022         if (queue_id >= dev_info.nb_tx_queues) {
16023                 printf("Error: input queue_id should be 0 ... "
16024                        "%d\n", dev_info.nb_tx_queues - 1);
16025                 return;
16026         }
16027
16028         single_offload = search_tx_offload(res->offload);
16029         if (single_offload == 0) {
16030                 printf("Unknown offload name: %s\n", res->offload);
16031                 return;
16032         }
16033
16034         if (!strcmp(res->on_off, "on"))
16035                 port->tx_conf[queue_id].offloads |= single_offload;
16036         else
16037                 port->tx_conf[queue_id].offloads &= ~single_offload;
16038
16039         cmd_reconfig_device_queue(port_id, 1, 1);
16040 }
16041
16042 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16043         .f = cmd_config_per_queue_tx_offload_parsed,
16044         .data = NULL,
16045         .help_str = "port <port_id> txq <queue_id> tx_offload "
16046                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16047                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16048                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16049                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16050                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16051                     "on|off",
16052         .tokens = {
16053                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16054                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16055                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16056                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16057                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16058                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16059                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16060                 NULL,
16061         }
16062 };
16063
16064 /* *** configure tx_metadata for specific port *** */
16065 struct cmd_config_tx_metadata_specific_result {
16066         cmdline_fixed_string_t port;
16067         cmdline_fixed_string_t keyword;
16068         uint16_t port_id;
16069         cmdline_fixed_string_t item;
16070         uint32_t value;
16071 };
16072
16073 static void
16074 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16075                                 __rte_unused struct cmdline *cl,
16076                                 __rte_unused void *data)
16077 {
16078         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16079
16080         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16081                 return;
16082         ports[res->port_id].tx_metadata = res->value;
16083         /* Add/remove callback to insert valid metadata in every Tx packet. */
16084         if (ports[res->port_id].tx_metadata)
16085                 add_tx_md_callback(res->port_id);
16086         else
16087                 remove_tx_md_callback(res->port_id);
16088         rte_flow_dynf_metadata_register();
16089 }
16090
16091 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16092         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16093                         port, "port");
16094 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16095         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16096                         keyword, "config");
16097 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16098         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16099                         port_id, RTE_UINT16);
16100 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16101         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16102                         item, "tx_metadata");
16103 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16104         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16105                         value, RTE_UINT32);
16106
16107 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16108         .f = cmd_config_tx_metadata_specific_parsed,
16109         .data = NULL,
16110         .help_str = "port config <port_id> tx_metadata <value>",
16111         .tokens = {
16112                 (void *)&cmd_config_tx_metadata_specific_port,
16113                 (void *)&cmd_config_tx_metadata_specific_keyword,
16114                 (void *)&cmd_config_tx_metadata_specific_id,
16115                 (void *)&cmd_config_tx_metadata_specific_item,
16116                 (void *)&cmd_config_tx_metadata_specific_value,
16117                 NULL,
16118         },
16119 };
16120
16121 /* *** set dynf *** */
16122 struct cmd_config_tx_dynf_specific_result {
16123         cmdline_fixed_string_t port;
16124         cmdline_fixed_string_t keyword;
16125         uint16_t port_id;
16126         cmdline_fixed_string_t item;
16127         cmdline_fixed_string_t name;
16128         cmdline_fixed_string_t value;
16129 };
16130
16131 static void
16132 cmd_config_dynf_specific_parsed(void *parsed_result,
16133                                 __rte_unused struct cmdline *cl,
16134                                 __rte_unused void *data)
16135 {
16136         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16137         struct rte_mbuf_dynflag desc_flag;
16138         int flag;
16139         uint64_t old_port_flags;
16140
16141         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16142                 return;
16143         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16144         if (flag <= 0) {
16145                 if (strlcpy(desc_flag.name, res->name,
16146                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16147                         printf("Flag name too long\n");
16148                         return;
16149                 }
16150                 desc_flag.flags = 0;
16151                 flag = rte_mbuf_dynflag_register(&desc_flag);
16152                 if (flag < 0) {
16153                         printf("Can't register flag\n");
16154                         return;
16155                 }
16156                 strcpy(dynf_names[flag], desc_flag.name);
16157         }
16158         old_port_flags = ports[res->port_id].mbuf_dynf;
16159         if (!strcmp(res->value, "set")) {
16160                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16161                 if (old_port_flags == 0)
16162                         add_tx_dynf_callback(res->port_id);
16163         } else {
16164                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16165                 if (ports[res->port_id].mbuf_dynf == 0)
16166                         remove_tx_dynf_callback(res->port_id);
16167         }
16168 }
16169
16170 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16171         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16172                         keyword, "port");
16173 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16174         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16175                         keyword, "config");
16176 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16177         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16178                         port_id, RTE_UINT16);
16179 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16180         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16181                         item, "dynf");
16182 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16183         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16184                         name, NULL);
16185 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16186         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16187                         value, "set#clear");
16188
16189 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16190         .f = cmd_config_dynf_specific_parsed,
16191         .data = NULL,
16192         .help_str = "port config <port id> dynf <name> set|clear",
16193         .tokens = {
16194                 (void *)&cmd_config_tx_dynf_specific_port,
16195                 (void *)&cmd_config_tx_dynf_specific_keyword,
16196                 (void *)&cmd_config_tx_dynf_specific_port_id,
16197                 (void *)&cmd_config_tx_dynf_specific_item,
16198                 (void *)&cmd_config_tx_dynf_specific_name,
16199                 (void *)&cmd_config_tx_dynf_specific_value,
16200                 NULL,
16201         },
16202 };
16203
16204 /* *** display tx_metadata per port configuration *** */
16205 struct cmd_show_tx_metadata_result {
16206         cmdline_fixed_string_t cmd_show;
16207         cmdline_fixed_string_t cmd_port;
16208         cmdline_fixed_string_t cmd_keyword;
16209         portid_t cmd_pid;
16210 };
16211
16212 static void
16213 cmd_show_tx_metadata_parsed(void *parsed_result,
16214                 __rte_unused struct cmdline *cl,
16215                 __rte_unused void *data)
16216 {
16217         struct cmd_show_tx_metadata_result *res = parsed_result;
16218
16219         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16220                 printf("invalid port id %u\n", res->cmd_pid);
16221                 return;
16222         }
16223         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16224                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16225                        ports[res->cmd_pid].tx_metadata);
16226         }
16227 }
16228
16229 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16230         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16231                         cmd_show, "show");
16232 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16233         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16234                         cmd_port, "port");
16235 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16236         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16237                         cmd_pid, RTE_UINT16);
16238 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16239         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16240                         cmd_keyword, "tx_metadata");
16241
16242 cmdline_parse_inst_t cmd_show_tx_metadata = {
16243         .f = cmd_show_tx_metadata_parsed,
16244         .data = NULL,
16245         .help_str = "show port <port_id> tx_metadata",
16246         .tokens = {
16247                 (void *)&cmd_show_tx_metadata_show,
16248                 (void *)&cmd_show_tx_metadata_port,
16249                 (void *)&cmd_show_tx_metadata_pid,
16250                 (void *)&cmd_show_tx_metadata_keyword,
16251                 NULL,
16252         },
16253 };
16254
16255 /* *** show fec capability per port configuration *** */
16256 struct cmd_show_fec_capability_result {
16257         cmdline_fixed_string_t cmd_show;
16258         cmdline_fixed_string_t cmd_port;
16259         cmdline_fixed_string_t cmd_fec;
16260         cmdline_fixed_string_t cmd_keyword;
16261         portid_t cmd_pid;
16262 };
16263
16264 static void
16265 cmd_show_fec_capability_parsed(void *parsed_result,
16266                 __rte_unused struct cmdline *cl,
16267                 __rte_unused void *data)
16268 {
16269 #define FEC_CAP_NUM 2
16270         struct cmd_show_fec_capability_result *res = parsed_result;
16271         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16272         unsigned int num = FEC_CAP_NUM;
16273         unsigned int ret_num;
16274         int ret;
16275
16276         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16277                 printf("Invalid port id %u\n", res->cmd_pid);
16278                 return;
16279         }
16280
16281         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16282         if (ret == -ENOTSUP) {
16283                 printf("Function not implemented\n");
16284                 return;
16285         } else if (ret < 0) {
16286                 printf("Get FEC capability failed\n");
16287                 return;
16288         }
16289
16290         ret_num = (unsigned int)ret;
16291         show_fec_capability(ret_num, speed_fec_capa);
16292 }
16293
16294 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16295         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16296                         cmd_show, "show");
16297 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16298         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16299                         cmd_port, "port");
16300 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16301         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16302                         cmd_pid, RTE_UINT16);
16303 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16304         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16305                         cmd_fec, "fec");
16306 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16307         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16308                         cmd_keyword, "capabilities");
16309
16310 cmdline_parse_inst_t cmd_show_capability = {
16311         .f = cmd_show_fec_capability_parsed,
16312         .data = NULL,
16313         .help_str = "show port <port_id> fec capabilities",
16314         .tokens = {
16315                 (void *)&cmd_show_fec_capability_show,
16316                 (void *)&cmd_show_fec_capability_port,
16317                 (void *)&cmd_show_fec_capability_pid,
16318                 (void *)&cmd_show_fec_capability_fec,
16319                 (void *)&cmd_show_fec_capability_keyword,
16320                 NULL,
16321         },
16322 };
16323
16324 /* *** show fec mode per port configuration *** */
16325 struct cmd_show_fec_metadata_result {
16326         cmdline_fixed_string_t cmd_show;
16327         cmdline_fixed_string_t cmd_port;
16328         cmdline_fixed_string_t cmd_keyword;
16329         portid_t cmd_pid;
16330 };
16331
16332 static void
16333 cmd_show_fec_mode_parsed(void *parsed_result,
16334                 __rte_unused struct cmdline *cl,
16335                 __rte_unused void *data)
16336 {
16337 #define FEC_NAME_SIZE 16
16338         struct cmd_show_fec_metadata_result *res = parsed_result;
16339         uint32_t mode;
16340         char buf[FEC_NAME_SIZE];
16341         int ret;
16342
16343         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16344                 printf("Invalid port id %u\n", res->cmd_pid);
16345                 return;
16346         }
16347         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16348         if (ret == -ENOTSUP) {
16349                 printf("Function not implemented\n");
16350                 return;
16351         } else if (ret < 0) {
16352                 printf("Get FEC mode failed\n");
16353                 return;
16354         }
16355
16356         switch (mode) {
16357         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16358                 strlcpy(buf, "off", sizeof(buf));
16359                 break;
16360         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16361                 strlcpy(buf, "auto", sizeof(buf));
16362                 break;
16363         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16364                 strlcpy(buf, "baser", sizeof(buf));
16365                 break;
16366         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16367                 strlcpy(buf, "rs", sizeof(buf));
16368                 break;
16369         default:
16370                 return;
16371         }
16372
16373         printf("%s\n", buf);
16374 }
16375
16376 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16377         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16378                         cmd_show, "show");
16379 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16380         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16381                         cmd_port, "port");
16382 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16383         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16384                         cmd_pid, RTE_UINT16);
16385 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16386         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16387                         cmd_keyword, "fec_mode");
16388
16389 cmdline_parse_inst_t cmd_show_fec_mode = {
16390         .f = cmd_show_fec_mode_parsed,
16391         .data = NULL,
16392         .help_str = "show port <port_id> fec_mode",
16393         .tokens = {
16394                 (void *)&cmd_show_fec_mode_show,
16395                 (void *)&cmd_show_fec_mode_port,
16396                 (void *)&cmd_show_fec_mode_pid,
16397                 (void *)&cmd_show_fec_mode_keyword,
16398                 NULL,
16399         },
16400 };
16401
16402 /* *** set fec mode per port configuration *** */
16403 struct cmd_set_port_fec_mode {
16404         cmdline_fixed_string_t set;
16405         cmdline_fixed_string_t port;
16406         portid_t port_id;
16407         cmdline_fixed_string_t fec_mode;
16408         cmdline_fixed_string_t fec_value;
16409 };
16410
16411 /* Common CLI fields for set fec mode */
16412 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16413         TOKEN_STRING_INITIALIZER
16414                 (struct cmd_set_port_fec_mode,
16415                  set, "set");
16416 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16417         TOKEN_STRING_INITIALIZER
16418                 (struct cmd_set_port_fec_mode,
16419                  port, "port");
16420 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16421         TOKEN_NUM_INITIALIZER
16422                 (struct cmd_set_port_fec_mode,
16423                  port_id, RTE_UINT16);
16424 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16425         TOKEN_STRING_INITIALIZER
16426                 (struct cmd_set_port_fec_mode,
16427                  fec_mode, "fec_mode");
16428 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16429         TOKEN_STRING_INITIALIZER
16430                 (struct cmd_set_port_fec_mode,
16431                  fec_value, NULL);
16432
16433 static void
16434 cmd_set_port_fec_mode_parsed(
16435         void *parsed_result,
16436         __rte_unused struct cmdline *cl,
16437         __rte_unused void *data)
16438 {
16439         struct cmd_set_port_fec_mode *res = parsed_result;
16440         uint16_t port_id = res->port_id;
16441         uint32_t mode;
16442         int ret;
16443
16444         ret = parse_fec_mode(res->fec_value, &mode);
16445         if (ret < 0) {
16446                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16447                         port_id);
16448                 return;
16449         }
16450
16451         ret = rte_eth_fec_set(port_id, mode);
16452         if (ret == -ENOTSUP) {
16453                 printf("Function not implemented\n");
16454                 return;
16455         } else if (ret < 0) {
16456                 printf("Set FEC mode failed\n");
16457                 return;
16458         }
16459 }
16460
16461 cmdline_parse_inst_t cmd_set_fec_mode = {
16462         .f = cmd_set_port_fec_mode_parsed,
16463         .data = NULL,
16464         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16465         .tokens = {
16466                 (void *)&cmd_set_port_fec_mode_set,
16467                 (void *)&cmd_set_port_fec_mode_port,
16468                 (void *)&cmd_set_port_fec_mode_port_id,
16469                 (void *)&cmd_set_port_fec_mode_str,
16470                 (void *)&cmd_set_port_fec_mode_value,
16471                 NULL,
16472         },
16473 };
16474
16475 /* show port supported ptypes */
16476
16477 /* Common result structure for show port ptypes */
16478 struct cmd_show_port_supported_ptypes_result {
16479         cmdline_fixed_string_t show;
16480         cmdline_fixed_string_t port;
16481         portid_t port_id;
16482         cmdline_fixed_string_t ptypes;
16483 };
16484
16485 /* Common CLI fields for show port ptypes */
16486 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16487         TOKEN_STRING_INITIALIZER
16488                 (struct cmd_show_port_supported_ptypes_result,
16489                  show, "show");
16490 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16491         TOKEN_STRING_INITIALIZER
16492                 (struct cmd_show_port_supported_ptypes_result,
16493                  port, "port");
16494 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16495         TOKEN_NUM_INITIALIZER
16496                 (struct cmd_show_port_supported_ptypes_result,
16497                  port_id, RTE_UINT16);
16498 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16499         TOKEN_STRING_INITIALIZER
16500                 (struct cmd_show_port_supported_ptypes_result,
16501                  ptypes, "ptypes");
16502
16503 static void
16504 cmd_show_port_supported_ptypes_parsed(
16505         void *parsed_result,
16506         __rte_unused struct cmdline *cl,
16507         __rte_unused void *data)
16508 {
16509 #define RSVD_PTYPE_MASK       0xf0000000
16510 #define MAX_PTYPES_PER_LAYER  16
16511 #define LTYPE_NAMESIZE        32
16512 #define PTYPE_NAMESIZE        256
16513         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16514         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16515         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16516         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16517         uint16_t port_id = res->port_id;
16518         int ret, i;
16519
16520         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16521         if (ret < 0)
16522                 return;
16523
16524         while (ptype_mask != RSVD_PTYPE_MASK) {
16525
16526                 switch (ptype_mask) {
16527                 case RTE_PTYPE_L2_MASK:
16528                         strlcpy(ltype, "L2", sizeof(ltype));
16529                         break;
16530                 case RTE_PTYPE_L3_MASK:
16531                         strlcpy(ltype, "L3", sizeof(ltype));
16532                         break;
16533                 case RTE_PTYPE_L4_MASK:
16534                         strlcpy(ltype, "L4", sizeof(ltype));
16535                         break;
16536                 case RTE_PTYPE_TUNNEL_MASK:
16537                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16538                         break;
16539                 case RTE_PTYPE_INNER_L2_MASK:
16540                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16541                         break;
16542                 case RTE_PTYPE_INNER_L3_MASK:
16543                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16544                         break;
16545                 case RTE_PTYPE_INNER_L4_MASK:
16546                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16547                         break;
16548                 default:
16549                         return;
16550                 }
16551
16552                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16553                                                        ptype_mask, ptypes,
16554                                                        MAX_PTYPES_PER_LAYER);
16555
16556                 if (ret > 0)
16557                         printf("Supported %s ptypes:\n", ltype);
16558                 else
16559                         printf("%s ptypes unsupported\n", ltype);
16560
16561                 for (i = 0; i < ret; ++i) {
16562                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16563                         printf("%s\n", buf);
16564                 }
16565
16566                 ptype_mask <<= 4;
16567         }
16568 }
16569
16570 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16571         .f = cmd_show_port_supported_ptypes_parsed,
16572         .data = NULL,
16573         .help_str = "show port <port_id> ptypes",
16574         .tokens = {
16575                 (void *)&cmd_show_port_supported_ptypes_show,
16576                 (void *)&cmd_show_port_supported_ptypes_port,
16577                 (void *)&cmd_show_port_supported_ptypes_port_id,
16578                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16579                 NULL,
16580         },
16581 };
16582
16583 /* *** display rx/tx descriptor status *** */
16584 struct cmd_show_rx_tx_desc_status_result {
16585         cmdline_fixed_string_t cmd_show;
16586         cmdline_fixed_string_t cmd_port;
16587         cmdline_fixed_string_t cmd_keyword;
16588         cmdline_fixed_string_t cmd_desc;
16589         cmdline_fixed_string_t cmd_status;
16590         portid_t cmd_pid;
16591         portid_t cmd_qid;
16592         portid_t cmd_did;
16593 };
16594
16595 static void
16596 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16597                 __rte_unused struct cmdline *cl,
16598                 __rte_unused void *data)
16599 {
16600         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16601         int rc;
16602
16603         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16604                 printf("invalid port id %u\n", res->cmd_pid);
16605                 return;
16606         }
16607
16608         if (!strcmp(res->cmd_keyword, "rxq")) {
16609                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16610                                              res->cmd_did);
16611                 if (rc < 0) {
16612                         printf("Invalid queueid = %d\n", res->cmd_qid);
16613                         return;
16614                 }
16615                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16616                         printf("Desc status = AVAILABLE\n");
16617                 else if (rc == RTE_ETH_RX_DESC_DONE)
16618                         printf("Desc status = DONE\n");
16619                 else
16620                         printf("Desc status = UNAVAILABLE\n");
16621         } else if (!strcmp(res->cmd_keyword, "txq")) {
16622                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16623                                              res->cmd_did);
16624                 if (rc < 0) {
16625                         printf("Invalid queueid = %d\n", res->cmd_qid);
16626                         return;
16627                 }
16628                 if (rc == RTE_ETH_TX_DESC_FULL)
16629                         printf("Desc status = FULL\n");
16630                 else if (rc == RTE_ETH_TX_DESC_DONE)
16631                         printf("Desc status = DONE\n");
16632                 else
16633                         printf("Desc status = UNAVAILABLE\n");
16634         }
16635 }
16636
16637 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16638         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16639                         cmd_show, "show");
16640 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16641         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16642                         cmd_port, "port");
16643 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16644         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16645                         cmd_pid, RTE_UINT16);
16646 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16647         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16648                         cmd_keyword, "rxq#txq");
16649 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16650         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16651                         cmd_qid, RTE_UINT16);
16652 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16653         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16654                         cmd_desc, "desc");
16655 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16656         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16657                         cmd_did, RTE_UINT16);
16658 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16659         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16660                         cmd_status, "status");
16661 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16662         .f = cmd_show_rx_tx_desc_status_parsed,
16663         .data = NULL,
16664         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16665                 "status",
16666         .tokens = {
16667                 (void *)&cmd_show_rx_tx_desc_status_show,
16668                 (void *)&cmd_show_rx_tx_desc_status_port,
16669                 (void *)&cmd_show_rx_tx_desc_status_pid,
16670                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16671                 (void *)&cmd_show_rx_tx_desc_status_qid,
16672                 (void *)&cmd_show_rx_tx_desc_status_desc,
16673                 (void *)&cmd_show_rx_tx_desc_status_did,
16674                 (void *)&cmd_show_rx_tx_desc_status_status,
16675                 NULL,
16676         },
16677 };
16678
16679 /* Common result structure for set port ptypes */
16680 struct cmd_set_port_ptypes_result {
16681         cmdline_fixed_string_t set;
16682         cmdline_fixed_string_t port;
16683         portid_t port_id;
16684         cmdline_fixed_string_t ptype_mask;
16685         uint32_t mask;
16686 };
16687
16688 /* Common CLI fields for set port ptypes */
16689 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16690         TOKEN_STRING_INITIALIZER
16691                 (struct cmd_set_port_ptypes_result,
16692                  set, "set");
16693 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16694         TOKEN_STRING_INITIALIZER
16695                 (struct cmd_set_port_ptypes_result,
16696                  port, "port");
16697 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16698         TOKEN_NUM_INITIALIZER
16699                 (struct cmd_set_port_ptypes_result,
16700                  port_id, RTE_UINT16);
16701 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16702         TOKEN_STRING_INITIALIZER
16703                 (struct cmd_set_port_ptypes_result,
16704                  ptype_mask, "ptype_mask");
16705 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16706         TOKEN_NUM_INITIALIZER
16707                 (struct cmd_set_port_ptypes_result,
16708                  mask, RTE_UINT32);
16709
16710 static void
16711 cmd_set_port_ptypes_parsed(
16712         void *parsed_result,
16713         __rte_unused struct cmdline *cl,
16714         __rte_unused void *data)
16715 {
16716         struct cmd_set_port_ptypes_result *res = parsed_result;
16717 #define PTYPE_NAMESIZE        256
16718         char ptype_name[PTYPE_NAMESIZE];
16719         uint16_t port_id = res->port_id;
16720         uint32_t ptype_mask = res->mask;
16721         int ret, i;
16722
16723         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16724                                                NULL, 0);
16725         if (ret <= 0) {
16726                 printf("Port %d doesn't support any ptypes.\n", port_id);
16727                 return;
16728         }
16729
16730         uint32_t ptypes[ret];
16731
16732         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16733         if (ret < 0) {
16734                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16735                 return;
16736         }
16737
16738         printf("Successfully set following ptypes for Port %d\n", port_id);
16739         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16740                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16741                 printf("%s\n", ptype_name);
16742         }
16743
16744         clear_ptypes = false;
16745 }
16746
16747 cmdline_parse_inst_t cmd_set_port_ptypes = {
16748         .f = cmd_set_port_ptypes_parsed,
16749         .data = NULL,
16750         .help_str = "set port <port_id> ptype_mask <mask>",
16751         .tokens = {
16752                 (void *)&cmd_set_port_ptypes_set,
16753                 (void *)&cmd_set_port_ptypes_port,
16754                 (void *)&cmd_set_port_ptypes_port_id,
16755                 (void *)&cmd_set_port_ptypes_mask_str,
16756                 (void *)&cmd_set_port_ptypes_mask_u32,
16757                 NULL,
16758         },
16759 };
16760
16761 /* *** display mac addresses added to a port *** */
16762 struct cmd_showport_macs_result {
16763         cmdline_fixed_string_t cmd_show;
16764         cmdline_fixed_string_t cmd_port;
16765         cmdline_fixed_string_t cmd_keyword;
16766         portid_t cmd_pid;
16767 };
16768
16769 static void
16770 cmd_showport_macs_parsed(void *parsed_result,
16771                 __rte_unused struct cmdline *cl,
16772                 __rte_unused void *data)
16773 {
16774         struct cmd_showport_macs_result *res = parsed_result;
16775
16776         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16777                 return;
16778
16779         if (!strcmp(res->cmd_keyword, "macs"))
16780                 show_macs(res->cmd_pid);
16781         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16782                 show_mcast_macs(res->cmd_pid);
16783 }
16784
16785 cmdline_parse_token_string_t cmd_showport_macs_show =
16786         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16787                         cmd_show, "show");
16788 cmdline_parse_token_string_t cmd_showport_macs_port =
16789         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16790                         cmd_port, "port");
16791 cmdline_parse_token_num_t cmd_showport_macs_pid =
16792         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16793                         cmd_pid, RTE_UINT16);
16794 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16795         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16796                         cmd_keyword, "macs#mcast_macs");
16797
16798 cmdline_parse_inst_t cmd_showport_macs = {
16799         .f = cmd_showport_macs_parsed,
16800         .data = NULL,
16801         .help_str = "show port <port_id> macs|mcast_macs",
16802         .tokens = {
16803                 (void *)&cmd_showport_macs_show,
16804                 (void *)&cmd_showport_macs_port,
16805                 (void *)&cmd_showport_macs_pid,
16806                 (void *)&cmd_showport_macs_keyword,
16807                 NULL,
16808         },
16809 };
16810
16811 /* ******************************************************************************** */
16812
16813 /* list of instructions */
16814 cmdline_parse_ctx_t main_ctx[] = {
16815         (cmdline_parse_inst_t *)&cmd_help_brief,
16816         (cmdline_parse_inst_t *)&cmd_help_long,
16817         (cmdline_parse_inst_t *)&cmd_quit,
16818         (cmdline_parse_inst_t *)&cmd_load_from_file,
16819         (cmdline_parse_inst_t *)&cmd_showport,
16820         (cmdline_parse_inst_t *)&cmd_showqueue,
16821         (cmdline_parse_inst_t *)&cmd_showeeprom,
16822         (cmdline_parse_inst_t *)&cmd_showportall,
16823         (cmdline_parse_inst_t *)&cmd_showdevice,
16824         (cmdline_parse_inst_t *)&cmd_showcfg,
16825         (cmdline_parse_inst_t *)&cmd_showfwdall,
16826         (cmdline_parse_inst_t *)&cmd_start,
16827         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16828         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16829         (cmdline_parse_inst_t *)&cmd_set_link_up,
16830         (cmdline_parse_inst_t *)&cmd_set_link_down,
16831         (cmdline_parse_inst_t *)&cmd_reset,
16832         (cmdline_parse_inst_t *)&cmd_set_numbers,
16833         (cmdline_parse_inst_t *)&cmd_set_log,
16834         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16835         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16836         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16837         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16838         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16839         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16840         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16841         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16842         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16843         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16844         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16845         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16846         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16847         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16848         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16849         (cmdline_parse_inst_t *)&cmd_set_link_check,
16850         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16851         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16852         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16853         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16854 #ifdef RTE_NET_BOND
16855         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16856         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16857         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16858         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16859         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16860         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16861         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16862         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16863         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16864         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16865         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16866 #endif
16867         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16868         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16869         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16870         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16871         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16872         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16873         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16874         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16875         (cmdline_parse_inst_t *)&cmd_csum_set,
16876         (cmdline_parse_inst_t *)&cmd_csum_show,
16877         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16878         (cmdline_parse_inst_t *)&cmd_tso_set,
16879         (cmdline_parse_inst_t *)&cmd_tso_show,
16880         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16881         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16882         (cmdline_parse_inst_t *)&cmd_gro_enable,
16883         (cmdline_parse_inst_t *)&cmd_gro_flush,
16884         (cmdline_parse_inst_t *)&cmd_gro_show,
16885         (cmdline_parse_inst_t *)&cmd_gso_enable,
16886         (cmdline_parse_inst_t *)&cmd_gso_size,
16887         (cmdline_parse_inst_t *)&cmd_gso_show,
16888         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16889         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16890         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16891         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16892         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16893         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16894         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16895         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16896         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16897         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16898         (cmdline_parse_inst_t *)&cmd_config_dcb,
16899         (cmdline_parse_inst_t *)&cmd_read_reg,
16900         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16901         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16902         (cmdline_parse_inst_t *)&cmd_write_reg,
16903         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16904         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16905         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16906         (cmdline_parse_inst_t *)&cmd_stop,
16907         (cmdline_parse_inst_t *)&cmd_mac_addr,
16908         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16909         (cmdline_parse_inst_t *)&cmd_set_qmap,
16910         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16911         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
16912         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
16913         (cmdline_parse_inst_t *)&cmd_operate_port,
16914         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16915         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16916         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16917         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
16918         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
16919         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16920         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16921         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16922         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16923         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16924         (cmdline_parse_inst_t *)&cmd_config_mtu,
16925         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16926         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
16927         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16928         (cmdline_parse_inst_t *)&cmd_config_rss,
16929         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16930         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16931         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
16932         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16933         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16934         (cmdline_parse_inst_t *)&cmd_showport_reta,
16935         (cmdline_parse_inst_t *)&cmd_showport_macs,
16936         (cmdline_parse_inst_t *)&cmd_config_burst,
16937         (cmdline_parse_inst_t *)&cmd_config_thresh,
16938         (cmdline_parse_inst_t *)&cmd_config_threshold,
16939         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16940         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16941         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16942         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16943         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16944         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16945         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16946         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16947         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16948         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16949         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16950         (cmdline_parse_inst_t *)&cmd_dump,
16951         (cmdline_parse_inst_t *)&cmd_dump_one,
16952 #ifdef RTE_NET_I40E
16953         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16954 #endif
16955         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16956         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16957         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16958         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16959         (cmdline_parse_inst_t *)&cmd_flow,
16960         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16961         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16962         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16963         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16964         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16965         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16966         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16967         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16968         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16969         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16970         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16971         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16972         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16973         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16974         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16975         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16976         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16977         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16978         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16979         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16980         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16981         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16982         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16983         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16984         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16985         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16986         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16987         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16988         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16989         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16990         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16991         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16992         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16993         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16994         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16995         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16996         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16997         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16998         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16999         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17000         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17001         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17002         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17003         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17004         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17005         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17006         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17007         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17008         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17009         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17010         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17011         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17012         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17013         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17014         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17015         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17016         (cmdline_parse_inst_t *)&cmd_ddp_add,
17017         (cmdline_parse_inst_t *)&cmd_ddp_del,
17018         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17019         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17020         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17021         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17022         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17023         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17024         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17025         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17026         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17027         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17028         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17029         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17030
17031         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17032         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17033         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17034         (cmdline_parse_inst_t *)&cmd_queue_region,
17035         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17036         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17037         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17038         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17039         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17040         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17041         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17042         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17043         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17044         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17045         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17046         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17047         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17048         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17049         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17050         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17051         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17052         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17053         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17054         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17055         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17056         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17057         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17058         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17059         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17060         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17061         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17062         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17063         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17064         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17065         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17066         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17067         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17068         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17069         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17070         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17071 #ifdef RTE_LIB_BPF
17072         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17073         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17074 #endif
17075         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17076         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17077         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17078         (cmdline_parse_inst_t *)&cmd_set_raw,
17079         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17080         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17081         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17082         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17083         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17084         (cmdline_parse_inst_t *)&cmd_show_capability,
17085         NULL,
17086 };
17087
17088 /* read cmdline commands from file */
17089 void
17090 cmdline_read_from_file(const char *filename)
17091 {
17092         struct cmdline *cl;
17093
17094         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17095         if (cl == NULL) {
17096                 printf("Failed to create file based cmdline context: %s\n",
17097                        filename);
17098                 return;
17099         }
17100
17101         cmdline_interact(cl);
17102         cmdline_quit(cl);
17103
17104         cmdline_free(cl);
17105
17106         printf("Read CLI commands from %s\n", filename);
17107 }
17108
17109 /* prompt function, called from main on MAIN lcore */
17110 void
17111 prompt(void)
17112 {
17113         /* initialize non-constant commands */
17114         cmd_set_fwd_mode_init();
17115         cmd_set_fwd_retry_mode_init();
17116
17117         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17118         if (testpmd_cl == NULL)
17119                 return;
17120         cmdline_interact(testpmd_cl);
17121         cmdline_stdin_exit(testpmd_cl);
17122 }
17123
17124 void
17125 prompt_exit(void)
17126 {
17127         if (testpmd_cl != NULL)
17128                 cmdline_quit(testpmd_cl);
17129 }
17130
17131 static void
17132 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17133 {
17134         if (id == (portid_t)RTE_PORT_ALL) {
17135                 portid_t pid;
17136
17137                 RTE_ETH_FOREACH_DEV(pid) {
17138                         /* check if need_reconfig has been set to 1 */
17139                         if (ports[pid].need_reconfig == 0)
17140                                 ports[pid].need_reconfig = dev;
17141                         /* check if need_reconfig_queues has been set to 1 */
17142                         if (ports[pid].need_reconfig_queues == 0)
17143                                 ports[pid].need_reconfig_queues = queue;
17144                 }
17145         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17146                 /* check if need_reconfig has been set to 1 */
17147                 if (ports[id].need_reconfig == 0)
17148                         ports[id].need_reconfig = dev;
17149                 /* check if need_reconfig_queues has been set to 1 */
17150                 if (ports[id].need_reconfig_queues == 0)
17151                         ports[id].need_reconfig_queues = queue;
17152         }
17153 }