ethdev: remove L2 tunnel offload control API
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         "    outer-udp concerns the outer UDP layer in"
435                         " case the packet is recognized as a tunnel packet by"
436                         " the forward engine (vxlan, gre and ipip are supported)\n"
437                         "    Please check the NIC datasheet for HW limits.\n\n"
438
439                         "csum parse-tunnel (on|off) (tx_port_id)\n"
440                         "    If disabled, treat tunnel packets as non-tunneled"
441                         " packets (treat inner headers as payload). The port\n"
442                         "    argument is the port used for TX in csum forward"
443                         " engine.\n\n"
444
445                         "csum show (port_id)\n"
446                         "    Display tx checksum offload configuration\n\n"
447
448                         "tso set (segsize) (portid)\n"
449                         "    Enable TCP Segmentation Offload in csum forward"
450                         " engine.\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "tso show (portid)"
454                         "    Display the status of TCP Segmentation Offload.\n\n"
455
456                         "set port (port_id) gro on|off\n"
457                         "    Enable or disable Generic Receive Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "show port (port_id) gro\n"
461                         "    Display GRO configuration.\n\n"
462
463                         "set gro flush (cycles)\n"
464                         "    Set the cycle to flush GROed packets from"
465                         " reassembly tables.\n\n"
466
467                         "set port (port_id) gso (on|off)"
468                         "    Enable or disable Generic Segmentation Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "set gso segsz (length)\n"
472                         "    Set max packet length for output GSO segments,"
473                         " including packet header and payload.\n\n"
474
475                         "show port (port_id) gso\n"
476                         "    Show GSO configuration.\n\n"
477
478                         "set fwd (%s)\n"
479                         "    Set packet forwarding mode.\n\n"
480
481                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
482                         "    Add a MAC address on port_id.\n\n"
483
484                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Remove a MAC address from port_id.\n\n"
486
487                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Set the default MAC address for port_id.\n\n"
489
490                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
491                         "    Add a MAC address for a VF on the port.\n\n"
492
493                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the MAC address for a VF from the PF.\n\n"
495
496                         "set eth-peer (port_id) (peer_addr)\n"
497                         "    set the peer address for certain port.\n\n"
498
499                         "set port (port_id) uta (mac_address|all) (on|off)\n"
500                         "    Add/Remove a or all unicast hash filter(s)"
501                         "from port X.\n\n"
502
503                         "set promisc (port_id|all) (on|off)\n"
504                         "    Set the promiscuous mode on port_id, or all.\n\n"
505
506                         "set allmulti (port_id|all) (on|off)\n"
507                         "    Set the allmulti mode on port_id, or all.\n\n"
508
509                         "set vf promisc (port_id) (vf_id) (on|off)\n"
510                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
511
512                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
513                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
517                         " (on|off) autoneg (on|off) (port_id)\n"
518                         "set flow_ctrl rx (on|off) (portid)\n"
519                         "set flow_ctrl tx (on|off) (portid)\n"
520                         "set flow_ctrl high_water (high_water) (portid)\n"
521                         "set flow_ctrl low_water (low_water) (portid)\n"
522                         "set flow_ctrl pause_time (pause_time) (portid)\n"
523                         "set flow_ctrl send_xon (send_xon) (portid)\n"
524                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
525                         "set flow_ctrl autoneg (on|off) (port_id)\n"
526                         "    Set the link flow control parameter on a port.\n\n"
527
528                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
529                         " (low_water) (pause_time) (priority) (port_id)\n"
530                         "    Set the priority flow control parameter on a"
531                         " port.\n\n"
532
533                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
534                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
535                         " queue on port.\n"
536                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
537                         " on port 0 to mapping 5.\n\n"
538
539                         "set xstats-hide-zero on|off\n"
540                         "    Set the option to hide the zero values"
541                         " for xstats display.\n"
542
543                         "set record-core-cycles on|off\n"
544                         "    Set the option to enable measurement of CPU cycles.\n"
545
546                         "set record-burst-stats on|off\n"
547                         "    Set the option to enable display of RX and TX bursts.\n"
548
549                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
550                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
553                         "|MPE) (on|off)\n"
554                         "    AUPE:accepts untagged VLAN;"
555                         "ROPE:accept unicast hash\n\n"
556                         "    BAM:accepts broadcast packets;"
557                         "MPE:accepts all multicast packets\n\n"
558                         "    Enable/Disable a VF receive mode of a port\n\n"
559
560                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
561                         "    Set rate limit for a queue of a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rate (rate_num) "
564                         "queue_mask (queue_mask_value)\n"
565                         "    Set rate limit for queues in VF of a port\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
569                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
570                         "   Set pool or vlan type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
572                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
573                         " to pool 0.\n\n"
574
575                         "set port (port_id) mirror-rule (rule_id)"
576                         " (uplink-mirror|downlink-mirror) dst-pool"
577                         " (pool_id) (on|off)\n"
578                         "   Set uplink or downlink type mirror rule on a port.\n"
579                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
580                         " 0 on' enable mirror income traffic to pool 0.\n\n"
581
582                         "reset port (port_id) mirror-rule (rule_id)\n"
583                         "   Reset a mirror rule.\n\n"
584
585                         "set flush_rx (on|off)\n"
586                         "   Flush (default) or don't flush RX streams before"
587                         " forwarding. Mainly used with PCAP drivers.\n\n"
588
589                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the bypass mode for the lowest port on bypass enabled"
591                         " NIC.\n\n"
592
593                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
594                         "mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the event required to initiate specified bypass mode for"
596                         " the lowest port on a bypass enabled NIC where:\n"
597                         "       timeout   = enable bypass after watchdog timeout.\n"
598                         "       os_on     = enable bypass when OS/board is powered on.\n"
599                         "       os_off    = enable bypass when OS/board is powered off.\n"
600                         "       power_on  = enable bypass when power supply is turned on.\n"
601                         "       power_off = enable bypass when power supply is turned off."
602                         "\n\n"
603
604                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
605                         "   Set the bypass watchdog timeout to 'n' seconds"
606                         " where 0 = instant.\n\n"
607
608                         "show bypass config (port_id)\n"
609                         "   Show the bypass configuration for a bypass enabled NIC"
610                         " using the lowest port on the NIC.\n\n"
611
612 #ifdef RTE_NET_BOND
613                         "create bonded device (mode) (socket)\n"
614                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
615
616                         "add bonding slave (slave_id) (port_id)\n"
617                         "       Add a slave device to a bonded device.\n\n"
618
619                         "remove bonding slave (slave_id) (port_id)\n"
620                         "       Remove a slave device from a bonded device.\n\n"
621
622                         "set bonding mode (value) (port_id)\n"
623                         "       Set the bonding mode on a bonded device.\n\n"
624
625                         "set bonding primary (slave_id) (port_id)\n"
626                         "       Set the primary slave for a bonded device.\n\n"
627
628                         "show bonding config (port_id)\n"
629                         "       Show the bonding config for port_id.\n\n"
630
631                         "set bonding mac_addr (port_id) (address)\n"
632                         "       Set the MAC address of a bonded device.\n\n"
633
634                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
635                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
636
637                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
638                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
639
640                         "set bonding mon_period (port_id) (value)\n"
641                         "       Set the bonding link status monitoring polling period in ms.\n\n"
642
643                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
644                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
645
646 #endif
647                         "set link-up port (port_id)\n"
648                         "       Set link up for a port.\n\n"
649
650                         "set link-down port (port_id)\n"
651                         "       Set link down for a port.\n\n"
652
653                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) ptype_mask (ptype_mask)\n"
672                         "    set packet types classification for a specific port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         "set port (port_id) fec_mode auto|off|rs|baser\n"
737                         "    set fec mode for a specific port\n\n"
738
739                         , list_pkt_forwarding_modes()
740                 );
741         }
742
743         if (show_all || !strcmp(res->section, "ports")) {
744
745                 cmdline_printf(
746                         cl,
747                         "\n"
748                         "Port Operations:\n"
749                         "----------------\n\n"
750
751                         "port start (port_id|all)\n"
752                         "    Start all ports or port_id.\n\n"
753
754                         "port stop (port_id|all)\n"
755                         "    Stop all ports or port_id.\n\n"
756
757                         "port close (port_id|all)\n"
758                         "    Close all ports or port_id.\n\n"
759
760                         "port reset (port_id|all)\n"
761                         "    Reset all ports or port_id.\n\n"
762
763                         "port attach (ident)\n"
764                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
765
766                         "port detach (port_id)\n"
767                         "    Detach physical or virtual dev by port_id\n\n"
768
769                         "port config (port_id|all)"
770                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
771                         " duplex (half|full|auto)\n"
772                         "    Set speed and duplex for all ports or port_id\n\n"
773
774                         "port config (port_id|all) loopback (mode)\n"
775                         "    Set loopback mode for all ports or port_id\n\n"
776
777                         "port config all (rxq|txq|rxd|txd) (value)\n"
778                         "    Set number for rxq/txq/rxd/txd.\n\n"
779
780                         "port config all max-pkt-len (value)\n"
781                         "    Set the max packet length.\n\n"
782
783                         "port config all max-lro-pkt-size (value)\n"
784                         "    Set the max LRO aggregated packet size.\n\n"
785
786                         "port config all drop-en (on|off)\n"
787                         "    Enable or disable packet drop on all RX queues of all ports when no "
788                         "receive buffers available.\n\n"
789
790                         "port config all rss (all|default|ip|tcp|udp|sctp|"
791                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
792                         "level-outer|level-inner|<flowtype_id>)\n"
793                         "    Set the RSS mode.\n\n"
794
795                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
796                         "    Set the RSS redirection table.\n\n"
797
798                         "port config (port_id) dcb vt (on|off) (traffic_class)"
799                         " pfc (on|off)\n"
800                         "    Set the DCB mode.\n\n"
801
802                         "port config all burst (value)\n"
803                         "    Set the number of packets per burst.\n\n"
804
805                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
806                         " (value)\n"
807                         "    Set the ring prefetch/host/writeback threshold"
808                         " for tx/rx queue.\n\n"
809
810                         "port config all (txfreet|txrst|rxfreet) (value)\n"
811                         "    Set free threshold for rx/tx, or set"
812                         " tx rs bit threshold.\n\n"
813                         "port config mtu X value\n"
814                         "    Set the MTU of port X to a given value\n\n"
815
816                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
817                         "    Set a rx/tx queue's ring size configuration, the new"
818                         " value will take effect after command that (re-)start the port"
819                         " or command that setup the specific queue\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
822                         "    Start/stop a rx/tx queue of port X. Only take effect"
823                         " when port X is started\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
826                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
827                         " take effect when port X is stopped.\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) setup\n"
830                         "    Setup a rx/tx queue of port X.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
855                         "buffer_split|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
863                         "buffer_split|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896
897                         "port config (port_id) dynf (name) set|clear\n"
898                         "    Register a dynf and Set/clear this flag on Tx. "
899                         "Testpmd will set this value to any Tx packet "
900                         "sent from this port\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940 #ifdef RTE_NET_I40E
941                         "flow_director_filter (port_id) mode raw (add|del|update)"
942                         " flow (flow_id) (drop|fwd) queue (queue_id)"
943                         " fd_id (fd_id_value) packet (packet file name)\n"
944                         "    Add/Del a raw type flow director filter.\n\n"
945 #endif
946
947                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
948                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
949                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
950                         "    Set flow director IP mask.\n\n"
951
952                         "flow_director_mask (port_id) mode MAC-VLAN"
953                         " vlan (vlan_value)\n"
954                         "    Set flow director MAC-VLAN mask.\n\n"
955
956                         "flow_director_mask (port_id) mode Tunnel"
957                         " vlan (vlan_value) mac (mac_value)"
958                         " tunnel-type (tunnel_type_value)"
959                         " tunnel-id (tunnel_id_value)\n"
960                         "    Set flow director Tunnel mask.\n\n"
961
962                         "flow_director_flex_payload (port_id)"
963                         " (raw|l2|l3|l4) (config)\n"
964                         "    Configure flex payload selection.\n\n"
965
966                         "flow validate {port_id}"
967                         " [group {group_id}] [priority {level}]"
968                         " [ingress] [egress]"
969                         " pattern {item} [/ {item} [...]] / end"
970                         " actions {action} [/ {action} [...]] / end\n"
971                         "    Check whether a flow rule can be created.\n\n"
972
973                         "flow create {port_id}"
974                         " [group {group_id}] [priority {level}]"
975                         " [ingress] [egress]"
976                         " pattern {item} [/ {item} [...]] / end"
977                         " actions {action} [/ {action} [...]] / end\n"
978                         "    Create a flow rule.\n\n"
979
980                         "flow destroy {port_id} rule {rule_id} [...]\n"
981                         "    Destroy specific flow rules.\n\n"
982
983                         "flow flush {port_id}\n"
984                         "    Destroy all flow rules.\n\n"
985
986                         "flow query {port_id} {rule_id} {action}\n"
987                         "    Query an existing flow rule.\n\n"
988
989                         "flow list {port_id} [group {group_id}] [...]\n"
990                         "    List existing flow rules sorted by priority,"
991                         " filtered by group identifiers.\n\n"
992
993                         "flow isolate {port_id} {boolean}\n"
994                         "    Restrict ingress traffic to the defined"
995                         " flow rules\n\n"
996
997                         "flow aged {port_id} [destroy]\n"
998                         "    List and destroy aged flows"
999                         " flow rules\n\n"
1000
1001                         "flow shared_action {port_id} create"
1002                         " [action_id {shared_action_id}]"
1003                         " [ingress] [egress]"
1004                         " action {action} / end\n"
1005                         "    Create shared action.\n\n"
1006
1007                         "flow shared_action {port_id} update"
1008                         " {shared_action_id} action {action} / end\n"
1009                         "    Update shared action.\n\n"
1010
1011                         "flow shared_action {port_id} destroy"
1012                         " action_id {shared_action_id} [...]\n"
1013                         "    Destroy specific shared actions.\n\n"
1014
1015                         "flow shared_action {port_id} query"
1016                         " {shared_action_id}\n"
1017                         "    Query an existing shared action.\n\n"
1018
1019                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1020                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1021                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1022                         "       Configure the VXLAN encapsulation for flows.\n\n"
1023
1024                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1025                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1026                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1027                         " eth-dst (eth-dst)\n"
1028                         "       Configure the VXLAN encapsulation for flows.\n\n"
1029
1030                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1031                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1032                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1033                         " eth-dst (eth-dst)\n"
1034                         "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1037                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1038                         " (eth-dst)\n"
1039                         "       Configure the NVGRE encapsulation for flows.\n\n"
1040
1041                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1043                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set raw_encap {flow items}\n"
1047                         "       Configure the encapsulation with raw data.\n\n"
1048
1049                         "set raw_decap {flow items}\n"
1050                         "       Configure the decapsulation with raw data.\n\n"
1051
1052                 );
1053         }
1054
1055         if (show_all || !strcmp(res->section, "traffic_management")) {
1056                 cmdline_printf(
1057                         cl,
1058                         "\n"
1059                         "Traffic Management:\n"
1060                         "--------------\n"
1061                         "show port tm cap (port_id)\n"
1062                         "       Display the port TM capability.\n\n"
1063
1064                         "show port tm level cap (port_id) (level_id)\n"
1065                         "       Display the port TM hierarchical level capability.\n\n"
1066
1067                         "show port tm node cap (port_id) (node_id)\n"
1068                         "       Display the port TM node capability.\n\n"
1069
1070                         "show port tm node type (port_id) (node_id)\n"
1071                         "       Display the port TM node type.\n\n"
1072
1073                         "show port tm node stats (port_id) (node_id) (clear)\n"
1074                         "       Display the port TM node stats.\n\n"
1075
1076                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1077                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1078                         " (packet_length_adjust) (packet_mode)\n"
1079                         "       Add port tm node private shaper profile.\n\n"
1080
1081                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1082                         "       Delete port tm node private shaper profile.\n\n"
1083
1084                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1085                         " (shaper_profile_id)\n"
1086                         "       Add/update port tm node shared shaper.\n\n"
1087
1088                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1089                         "       Delete port tm node shared shaper.\n\n"
1090
1091                         "set port tm node shaper profile (port_id) (node_id)"
1092                         " (shaper_profile_id)\n"
1093                         "       Set port tm node shaper profile.\n\n"
1094
1095                         "add port tm node wred profile (port_id) (wred_profile_id)"
1096                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1097                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1098                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1099                         "       Add port tm node wred profile.\n\n"
1100
1101                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1102                         "       Delete port tm node wred profile.\n\n"
1103
1104                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1105                         " (priority) (weight) (level_id) (shaper_profile_id)"
1106                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1107                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1108                         "       Add port tm nonleaf node.\n\n"
1109
1110                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1111                         " (priority) (weight) (level_id) (shaper_profile_id)"
1112                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1113                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1114                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1115
1116                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1117                         " (priority) (weight) (level_id) (shaper_profile_id)"
1118                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1119                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                         "       Add port tm leaf node.\n\n"
1121
1122                         "del port tm node (port_id) (node_id)\n"
1123                         "       Delete port tm node.\n\n"
1124
1125                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1126                         " (priority) (weight)\n"
1127                         "       Set port tm node parent.\n\n"
1128
1129                         "suspend port tm node (port_id) (node_id)"
1130                         "       Suspend tm node.\n\n"
1131
1132                         "resume port tm node (port_id) (node_id)"
1133                         "       Resume tm node.\n\n"
1134
1135                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1136                         "       Commit tm hierarchy.\n\n"
1137
1138                         "set port tm mark ip_ecn (port) (green) (yellow)"
1139                         " (red)\n"
1140                         "    Enables/Disables the traffic management marking"
1141                         " for IP ECN (Explicit Congestion Notification)"
1142                         " packets on a given port\n\n"
1143
1144                         "set port tm mark ip_dscp (port) (green) (yellow)"
1145                         " (red)\n"
1146                         "    Enables/Disables the traffic management marking"
1147                         " on the port for IP dscp packets\n\n"
1148
1149                         "set port tm mark vlan_dei (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for VLAN packets with DEI enabled\n\n"
1153                 );
1154         }
1155
1156         if (show_all || !strcmp(res->section, "devices")) {
1157                 cmdline_printf(
1158                         cl,
1159                         "\n"
1160                         "Device Operations:\n"
1161                         "--------------\n"
1162                         "device detach (identifier)\n"
1163                         "       Detach device by identifier.\n\n"
1164                 );
1165         }
1166
1167 }
1168
1169 cmdline_parse_token_string_t cmd_help_long_help =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1171
1172 cmdline_parse_token_string_t cmd_help_long_section =
1173         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1174                         "all#control#display#config#"
1175                         "ports#registers#filters#traffic_management#devices");
1176
1177 cmdline_parse_inst_t cmd_help_long = {
1178         .f = cmd_help_long_parsed,
1179         .data = NULL,
1180         .help_str = "help all|control|display|config|ports|register|"
1181                 "filters|traffic_management|devices: "
1182                 "Show help",
1183         .tokens = {
1184                 (void *)&cmd_help_long_help,
1185                 (void *)&cmd_help_long_section,
1186                 NULL,
1187         },
1188 };
1189
1190
1191 /* *** start/stop/close all ports *** */
1192 struct cmd_operate_port_result {
1193         cmdline_fixed_string_t keyword;
1194         cmdline_fixed_string_t name;
1195         cmdline_fixed_string_t value;
1196 };
1197
1198 static void cmd_operate_port_parsed(void *parsed_result,
1199                                 __rte_unused struct cmdline *cl,
1200                                 __rte_unused void *data)
1201 {
1202         struct cmd_operate_port_result *res = parsed_result;
1203
1204         if (!strcmp(res->name, "start"))
1205                 start_port(RTE_PORT_ALL);
1206         else if (!strcmp(res->name, "stop"))
1207                 stop_port(RTE_PORT_ALL);
1208         else if (!strcmp(res->name, "close"))
1209                 close_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "reset"))
1211                 reset_port(RTE_PORT_ALL);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1218                                                                 "port");
1219 cmdline_parse_token_string_t cmd_operate_port_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1221                                                 "start#stop#close#reset");
1222 cmdline_parse_token_string_t cmd_operate_port_all_all =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1224
1225 cmdline_parse_inst_t cmd_operate_port = {
1226         .f = cmd_operate_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1229         .tokens = {
1230                 (void *)&cmd_operate_port_all_cmd,
1231                 (void *)&cmd_operate_port_all_port,
1232                 (void *)&cmd_operate_port_all_all,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** start/stop/close specific port *** */
1238 struct cmd_operate_specific_port_result {
1239         cmdline_fixed_string_t keyword;
1240         cmdline_fixed_string_t name;
1241         uint8_t value;
1242 };
1243
1244 static void cmd_operate_specific_port_parsed(void *parsed_result,
1245                         __rte_unused struct cmdline *cl,
1246                                 __rte_unused void *data)
1247 {
1248         struct cmd_operate_specific_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->name, "start"))
1251                 start_port(res->value);
1252         else if (!strcmp(res->name, "stop"))
1253                 stop_port(res->value);
1254         else if (!strcmp(res->name, "close"))
1255                 close_port(res->value);
1256         else if (!strcmp(res->name, "reset"))
1257                 reset_port(res->value);
1258         else
1259                 printf("Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                         keyword, "port");
1265 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                 name, "start#stop#close#reset");
1268 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1269         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1270                                                         value, 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, 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, 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, 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                                                                 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                               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, 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                                                                 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, 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, UINT16);
2053 cmdline_parse_token_num_t cmd_config_mtu_value =
2054         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2055
2056 cmdline_parse_inst_t cmd_config_mtu = {
2057         .f = cmd_config_mtu_parsed,
2058         .data = NULL,
2059         .help_str = "port config mtu <port_id> <value>",
2060         .tokens = {
2061                 (void *)&cmd_config_mtu_port,
2062                 (void *)&cmd_config_mtu_keyword,
2063                 (void *)&cmd_config_mtu_mtu,
2064                 (void *)&cmd_config_mtu_port_id,
2065                 (void *)&cmd_config_mtu_value,
2066                 NULL,
2067         },
2068 };
2069
2070 /* *** configure rx mode *** */
2071 struct cmd_config_rx_mode_flag {
2072         cmdline_fixed_string_t port;
2073         cmdline_fixed_string_t keyword;
2074         cmdline_fixed_string_t all;
2075         cmdline_fixed_string_t name;
2076         cmdline_fixed_string_t value;
2077 };
2078
2079 static void
2080 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2081                                 __rte_unused struct cmdline *cl,
2082                                 __rte_unused void *data)
2083 {
2084         struct cmd_config_rx_mode_flag *res = parsed_result;
2085
2086         if (!all_ports_stopped()) {
2087                 printf("Please stop all ports first\n");
2088                 return;
2089         }
2090
2091         if (!strcmp(res->name, "drop-en")) {
2092                 if (!strcmp(res->value, "on"))
2093                         rx_drop_en = 1;
2094                 else if (!strcmp(res->value, "off"))
2095                         rx_drop_en = 0;
2096                 else {
2097                         printf("Unknown parameter\n");
2098                         return;
2099                 }
2100         } else {
2101                 printf("Unknown parameter\n");
2102                 return;
2103         }
2104
2105         init_port_config();
2106
2107         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2108 }
2109
2110 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2112 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2114                                                                 "config");
2115 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2116         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2117 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2119                                         "drop-en");
2120 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2121         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2122                                                         "on#off");
2123
2124 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2125         .f = cmd_config_rx_mode_flag_parsed,
2126         .data = NULL,
2127         .help_str = "port config all drop-en on|off",
2128         .tokens = {
2129                 (void *)&cmd_config_rx_mode_flag_port,
2130                 (void *)&cmd_config_rx_mode_flag_keyword,
2131                 (void *)&cmd_config_rx_mode_flag_all,
2132                 (void *)&cmd_config_rx_mode_flag_name,
2133                 (void *)&cmd_config_rx_mode_flag_value,
2134                 NULL,
2135         },
2136 };
2137
2138 /* *** configure rss *** */
2139 struct cmd_config_rss {
2140         cmdline_fixed_string_t port;
2141         cmdline_fixed_string_t keyword;
2142         cmdline_fixed_string_t all;
2143         cmdline_fixed_string_t name;
2144         cmdline_fixed_string_t value;
2145 };
2146
2147 static void
2148 cmd_config_rss_parsed(void *parsed_result,
2149                         __rte_unused struct cmdline *cl,
2150                         __rte_unused void *data)
2151 {
2152         struct cmd_config_rss *res = parsed_result;
2153         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2154         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2155         int use_default = 0;
2156         int all_updated = 1;
2157         int diag;
2158         uint16_t i;
2159         int ret;
2160
2161         if (!strcmp(res->value, "all"))
2162                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2163                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2164                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2165                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2166         else if (!strcmp(res->value, "eth"))
2167                 rss_conf.rss_hf = ETH_RSS_ETH;
2168         else if (!strcmp(res->value, "vlan"))
2169                 rss_conf.rss_hf = ETH_RSS_VLAN;
2170         else if (!strcmp(res->value, "ip"))
2171                 rss_conf.rss_hf = ETH_RSS_IP;
2172         else if (!strcmp(res->value, "udp"))
2173                 rss_conf.rss_hf = ETH_RSS_UDP;
2174         else if (!strcmp(res->value, "tcp"))
2175                 rss_conf.rss_hf = ETH_RSS_TCP;
2176         else if (!strcmp(res->value, "sctp"))
2177                 rss_conf.rss_hf = ETH_RSS_SCTP;
2178         else if (!strcmp(res->value, "ether"))
2179                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2180         else if (!strcmp(res->value, "port"))
2181                 rss_conf.rss_hf = ETH_RSS_PORT;
2182         else if (!strcmp(res->value, "vxlan"))
2183                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2184         else if (!strcmp(res->value, "geneve"))
2185                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2186         else if (!strcmp(res->value, "nvgre"))
2187                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2188         else if (!strcmp(res->value, "l3-pre32"))
2189                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2190         else if (!strcmp(res->value, "l3-pre40"))
2191                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2192         else if (!strcmp(res->value, "l3-pre48"))
2193                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2194         else if (!strcmp(res->value, "l3-pre56"))
2195                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2196         else if (!strcmp(res->value, "l3-pre64"))
2197                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2198         else if (!strcmp(res->value, "l3-pre96"))
2199                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2200         else if (!strcmp(res->value, "l3-src-only"))
2201                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2202         else if (!strcmp(res->value, "l3-dst-only"))
2203                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2204         else if (!strcmp(res->value, "l4-src-only"))
2205                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2206         else if (!strcmp(res->value, "l4-dst-only"))
2207                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2208         else if (!strcmp(res->value, "l2-src-only"))
2209                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2210         else if (!strcmp(res->value, "l2-dst-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2212         else if (!strcmp(res->value, "l2tpv3"))
2213                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2214         else if (!strcmp(res->value, "esp"))
2215                 rss_conf.rss_hf = ETH_RSS_ESP;
2216         else if (!strcmp(res->value, "ah"))
2217                 rss_conf.rss_hf = ETH_RSS_AH;
2218         else if (!strcmp(res->value, "pfcp"))
2219                 rss_conf.rss_hf = ETH_RSS_PFCP;
2220         else if (!strcmp(res->value, "pppoe"))
2221                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2222         else if (!strcmp(res->value, "gtpu"))
2223                 rss_conf.rss_hf = ETH_RSS_GTPU;
2224         else if (!strcmp(res->value, "none"))
2225                 rss_conf.rss_hf = 0;
2226         else if (!strcmp(res->value, "level-default")) {
2227                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2228                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2229         } else if (!strcmp(res->value, "level-outer")) {
2230                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2231                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2232         } else if (!strcmp(res->value, "level-inner")) {
2233                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2234                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2235         } else if (!strcmp(res->value, "default"))
2236                 use_default = 1;
2237         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2238                                                 atoi(res->value) < 64)
2239                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2240         else {
2241                 printf("Unknown parameter\n");
2242                 return;
2243         }
2244         rss_conf.rss_key = NULL;
2245         /* Update global configuration for RSS types. */
2246         RTE_ETH_FOREACH_DEV(i) {
2247                 struct rte_eth_rss_conf local_rss_conf;
2248
2249                 ret = eth_dev_info_get_print_err(i, &dev_info);
2250                 if (ret != 0)
2251                         return;
2252
2253                 if (use_default)
2254                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2255
2256                 local_rss_conf = rss_conf;
2257                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2258                         dev_info.flow_type_rss_offloads;
2259                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2260                         printf("Port %u modified RSS hash function based on hardware support,"
2261                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2262                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2263                 }
2264                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2265                 if (diag < 0) {
2266                         all_updated = 0;
2267                         printf("Configuration of RSS hash at ethernet port %d "
2268                                 "failed with error (%d): %s.\n",
2269                                 i, -diag, strerror(-diag));
2270                 }
2271         }
2272         if (all_updated && !use_default) {
2273                 rss_hf = rss_conf.rss_hf;
2274                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2275         }
2276 }
2277
2278 cmdline_parse_token_string_t cmd_config_rss_port =
2279         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2280 cmdline_parse_token_string_t cmd_config_rss_keyword =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2282 cmdline_parse_token_string_t cmd_config_rss_all =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2284 cmdline_parse_token_string_t cmd_config_rss_name =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2286 cmdline_parse_token_string_t cmd_config_rss_value =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2288
2289 cmdline_parse_inst_t cmd_config_rss = {
2290         .f = cmd_config_rss_parsed,
2291         .data = NULL,
2292         .help_str = "port config all rss "
2293                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2294                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2295                 "level-outer|level-inner|<flowtype_id>",
2296         .tokens = {
2297                 (void *)&cmd_config_rss_port,
2298                 (void *)&cmd_config_rss_keyword,
2299                 (void *)&cmd_config_rss_all,
2300                 (void *)&cmd_config_rss_name,
2301                 (void *)&cmd_config_rss_value,
2302                 NULL,
2303         },
2304 };
2305
2306 /* *** configure rss hash key *** */
2307 struct cmd_config_rss_hash_key {
2308         cmdline_fixed_string_t port;
2309         cmdline_fixed_string_t config;
2310         portid_t port_id;
2311         cmdline_fixed_string_t rss_hash_key;
2312         cmdline_fixed_string_t rss_type;
2313         cmdline_fixed_string_t key;
2314 };
2315
2316 static uint8_t
2317 hexa_digit_to_value(char hexa_digit)
2318 {
2319         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2320                 return (uint8_t) (hexa_digit - '0');
2321         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2322                 return (uint8_t) ((hexa_digit - 'a') + 10);
2323         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2324                 return (uint8_t) ((hexa_digit - 'A') + 10);
2325         /* Invalid hexa digit */
2326         return 0xFF;
2327 }
2328
2329 static uint8_t
2330 parse_and_check_key_hexa_digit(char *key, int idx)
2331 {
2332         uint8_t hexa_v;
2333
2334         hexa_v = hexa_digit_to_value(key[idx]);
2335         if (hexa_v == 0xFF)
2336                 printf("invalid key: character %c at position %d is not a "
2337                        "valid hexa digit\n", key[idx], idx);
2338         return hexa_v;
2339 }
2340
2341 static void
2342 cmd_config_rss_hash_key_parsed(void *parsed_result,
2343                                __rte_unused struct cmdline *cl,
2344                                __rte_unused void *data)
2345 {
2346         struct cmd_config_rss_hash_key *res = parsed_result;
2347         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2348         uint8_t xdgt0;
2349         uint8_t xdgt1;
2350         int i;
2351         struct rte_eth_dev_info dev_info;
2352         uint8_t hash_key_size;
2353         uint32_t key_len;
2354         int ret;
2355
2356         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2357         if (ret != 0)
2358                 return;
2359
2360         if (dev_info.hash_key_size > 0 &&
2361                         dev_info.hash_key_size <= sizeof(hash_key))
2362                 hash_key_size = dev_info.hash_key_size;
2363         else {
2364                 printf("dev_info did not provide a valid hash key size\n");
2365                 return;
2366         }
2367         /* Check the length of the RSS hash key */
2368         key_len = strlen(res->key);
2369         if (key_len != (hash_key_size * 2)) {
2370                 printf("key length: %d invalid - key must be a string of %d"
2371                            " hexa-decimal numbers\n",
2372                            (int) key_len, hash_key_size * 2);
2373                 return;
2374         }
2375         /* Translate RSS hash key into binary representation */
2376         for (i = 0; i < hash_key_size; i++) {
2377                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2378                 if (xdgt0 == 0xFF)
2379                         return;
2380                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2381                 if (xdgt1 == 0xFF)
2382                         return;
2383                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2384         }
2385         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2386                         hash_key_size);
2387 }
2388
2389 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2391 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2392         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2393                                  "config");
2394 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2395         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2396 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2398                                  rss_hash_key, "rss-hash-key");
2399 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2401                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2402                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2403                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2404                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2405                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2406                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2407                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2408 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2409         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2410
2411 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2412         .f = cmd_config_rss_hash_key_parsed,
2413         .data = NULL,
2414         .help_str = "port config <port_id> rss-hash-key "
2415                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2416                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2417                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2418                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2419                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2420                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2421                 "<string of hex digits (variable length, NIC dependent)>",
2422         .tokens = {
2423                 (void *)&cmd_config_rss_hash_key_port,
2424                 (void *)&cmd_config_rss_hash_key_config,
2425                 (void *)&cmd_config_rss_hash_key_port_id,
2426                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2427                 (void *)&cmd_config_rss_hash_key_rss_type,
2428                 (void *)&cmd_config_rss_hash_key_value,
2429                 NULL,
2430         },
2431 };
2432
2433 /* *** configure port rxq/txq ring size *** */
2434 struct cmd_config_rxtx_ring_size {
2435         cmdline_fixed_string_t port;
2436         cmdline_fixed_string_t config;
2437         portid_t portid;
2438         cmdline_fixed_string_t rxtxq;
2439         uint16_t qid;
2440         cmdline_fixed_string_t rsize;
2441         uint16_t size;
2442 };
2443
2444 static void
2445 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2446                                  __rte_unused struct cmdline *cl,
2447                                  __rte_unused void *data)
2448 {
2449         struct cmd_config_rxtx_ring_size *res = parsed_result;
2450         struct rte_port *port;
2451         uint8_t isrx;
2452
2453         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2454                 return;
2455
2456         if (res->portid == (portid_t)RTE_PORT_ALL) {
2457                 printf("Invalid port id\n");
2458                 return;
2459         }
2460
2461         port = &ports[res->portid];
2462
2463         if (!strcmp(res->rxtxq, "rxq"))
2464                 isrx = 1;
2465         else if (!strcmp(res->rxtxq, "txq"))
2466                 isrx = 0;
2467         else {
2468                 printf("Unknown parameter\n");
2469                 return;
2470         }
2471
2472         if (isrx && rx_queue_id_is_invalid(res->qid))
2473                 return;
2474         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2475                 return;
2476
2477         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2478                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2479                        rx_free_thresh);
2480                 return;
2481         }
2482
2483         if (isrx)
2484                 port->nb_rx_desc[res->qid] = res->size;
2485         else
2486                 port->nb_tx_desc[res->qid] = res->size;
2487
2488         cmd_reconfig_device_queue(res->portid, 0, 1);
2489 }
2490
2491 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2492         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2493                                  port, "port");
2494 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2496                                  config, "config");
2497 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2498         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                                  portid, UINT16);
2500 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2502                                  rxtxq, "rxq#txq");
2503 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2504         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2505                               qid, UINT16);
2506 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2508                                  rsize, "ring_size");
2509 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2510         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                               size, UINT16);
2512
2513 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2514         .f = cmd_config_rxtx_ring_size_parsed,
2515         .data = NULL,
2516         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2517         .tokens = {
2518                 (void *)&cmd_config_rxtx_ring_size_port,
2519                 (void *)&cmd_config_rxtx_ring_size_config,
2520                 (void *)&cmd_config_rxtx_ring_size_portid,
2521                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2522                 (void *)&cmd_config_rxtx_ring_size_qid,
2523                 (void *)&cmd_config_rxtx_ring_size_rsize,
2524                 (void *)&cmd_config_rxtx_ring_size_size,
2525                 NULL,
2526         },
2527 };
2528
2529 /* *** configure port rxq/txq start/stop *** */
2530 struct cmd_config_rxtx_queue {
2531         cmdline_fixed_string_t port;
2532         portid_t portid;
2533         cmdline_fixed_string_t rxtxq;
2534         uint16_t qid;
2535         cmdline_fixed_string_t opname;
2536 };
2537
2538 static void
2539 cmd_config_rxtx_queue_parsed(void *parsed_result,
2540                         __rte_unused struct cmdline *cl,
2541                         __rte_unused void *data)
2542 {
2543         struct cmd_config_rxtx_queue *res = parsed_result;
2544         uint8_t isrx;
2545         uint8_t isstart;
2546         int ret = 0;
2547
2548         if (test_done == 0) {
2549                 printf("Please stop forwarding first\n");
2550                 return;
2551         }
2552
2553         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2554                 return;
2555
2556         if (port_is_started(res->portid) != 1) {
2557                 printf("Please start port %u first\n", res->portid);
2558                 return;
2559         }
2560
2561         if (!strcmp(res->rxtxq, "rxq"))
2562                 isrx = 1;
2563         else if (!strcmp(res->rxtxq, "txq"))
2564                 isrx = 0;
2565         else {
2566                 printf("Unknown parameter\n");
2567                 return;
2568         }
2569
2570         if (isrx && rx_queue_id_is_invalid(res->qid))
2571                 return;
2572         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2573                 return;
2574
2575         if (!strcmp(res->opname, "start"))
2576                 isstart = 1;
2577         else if (!strcmp(res->opname, "stop"))
2578                 isstart = 0;
2579         else {
2580                 printf("Unknown parameter\n");
2581                 return;
2582         }
2583
2584         if (isstart && isrx)
2585                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2586         else if (!isstart && isrx)
2587                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2588         else if (isstart && !isrx)
2589                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2590         else
2591                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2592
2593         if (ret == -ENOTSUP)
2594                 printf("Function not supported in PMD driver\n");
2595 }
2596
2597 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2599 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2601 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2603 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2604         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2605 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2606         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2607                                                 "start#stop");
2608
2609 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2610         .f = cmd_config_rxtx_queue_parsed,
2611         .data = NULL,
2612         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2613         .tokens = {
2614                 (void *)&cmd_config_rxtx_queue_port,
2615                 (void *)&cmd_config_rxtx_queue_portid,
2616                 (void *)&cmd_config_rxtx_queue_rxtxq,
2617                 (void *)&cmd_config_rxtx_queue_qid,
2618                 (void *)&cmd_config_rxtx_queue_opname,
2619                 NULL,
2620         },
2621 };
2622
2623 /* *** configure port rxq/txq deferred start on/off *** */
2624 struct cmd_config_deferred_start_rxtx_queue {
2625         cmdline_fixed_string_t port;
2626         portid_t port_id;
2627         cmdline_fixed_string_t rxtxq;
2628         uint16_t qid;
2629         cmdline_fixed_string_t opname;
2630         cmdline_fixed_string_t state;
2631 };
2632
2633 static void
2634 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2635                         __rte_unused struct cmdline *cl,
2636                         __rte_unused void *data)
2637 {
2638         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2639         struct rte_port *port;
2640         uint8_t isrx;
2641         uint8_t ison;
2642         uint8_t needreconfig = 0;
2643
2644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2645                 return;
2646
2647         if (port_is_started(res->port_id) != 0) {
2648                 printf("Please stop port %u first\n", res->port_id);
2649                 return;
2650         }
2651
2652         port = &ports[res->port_id];
2653
2654         isrx = !strcmp(res->rxtxq, "rxq");
2655
2656         if (isrx && rx_queue_id_is_invalid(res->qid))
2657                 return;
2658         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2659                 return;
2660
2661         ison = !strcmp(res->state, "on");
2662
2663         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2664                 port->rx_conf[res->qid].rx_deferred_start = ison;
2665                 needreconfig = 1;
2666         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2667                 port->tx_conf[res->qid].tx_deferred_start = ison;
2668                 needreconfig = 1;
2669         }
2670
2671         if (needreconfig)
2672                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2673 }
2674
2675 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2676         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2677                                                 port, "port");
2678 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2679         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2680                                                 port_id, UINT16);
2681 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2683                                                 rxtxq, "rxq#txq");
2684 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2685         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2686                                                 qid, UINT16);
2687 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2689                                                 opname, "deferred_start");
2690 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2692                                                 state, "on#off");
2693
2694 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2695         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2696         .data = NULL,
2697         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2698         .tokens = {
2699                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2700                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2701                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2702                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2703                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2704                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2705                 NULL,
2706         },
2707 };
2708
2709 /* *** configure port rxq/txq setup *** */
2710 struct cmd_setup_rxtx_queue {
2711         cmdline_fixed_string_t port;
2712         portid_t portid;
2713         cmdline_fixed_string_t rxtxq;
2714         uint16_t qid;
2715         cmdline_fixed_string_t setup;
2716 };
2717
2718 /* Common CLI fields for queue setup */
2719 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2720         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2721 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2722         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2723 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2724         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2725 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2726         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2727 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2728         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2729
2730 static void
2731 cmd_setup_rxtx_queue_parsed(
2732         void *parsed_result,
2733         __rte_unused struct cmdline *cl,
2734         __rte_unused void *data)
2735 {
2736         struct cmd_setup_rxtx_queue *res = parsed_result;
2737         struct rte_port *port;
2738         struct rte_mempool *mp;
2739         unsigned int socket_id;
2740         uint8_t isrx = 0;
2741         int ret;
2742
2743         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2744                 return;
2745
2746         if (res->portid == (portid_t)RTE_PORT_ALL) {
2747                 printf("Invalid port id\n");
2748                 return;
2749         }
2750
2751         if (!strcmp(res->rxtxq, "rxq"))
2752                 isrx = 1;
2753         else if (!strcmp(res->rxtxq, "txq"))
2754                 isrx = 0;
2755         else {
2756                 printf("Unknown parameter\n");
2757                 return;
2758         }
2759
2760         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2761                 printf("Invalid rx queue\n");
2762                 return;
2763         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2764                 printf("Invalid tx queue\n");
2765                 return;
2766         }
2767
2768         port = &ports[res->portid];
2769         if (isrx) {
2770                 socket_id = rxring_numa[res->portid];
2771                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2772                         socket_id = port->socket_id;
2773
2774                 mp = mbuf_pool_find(socket_id, 0);
2775                 if (mp == NULL) {
2776                         printf("Failed to setup RX queue: "
2777                                 "No mempool allocation"
2778                                 " on the socket %d\n",
2779                                 rxring_numa[res->portid]);
2780                         return;
2781                 }
2782                 ret = rx_queue_setup(res->portid,
2783                                      res->qid,
2784                                      port->nb_rx_desc[res->qid],
2785                                      socket_id,
2786                                      &port->rx_conf[res->qid],
2787                                      mp);
2788                 if (ret)
2789                         printf("Failed to setup RX queue\n");
2790         } else {
2791                 socket_id = txring_numa[res->portid];
2792                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2793                         socket_id = port->socket_id;
2794
2795                 ret = rte_eth_tx_queue_setup(res->portid,
2796                                              res->qid,
2797                                              port->nb_tx_desc[res->qid],
2798                                              socket_id,
2799                                              &port->tx_conf[res->qid]);
2800                 if (ret)
2801                         printf("Failed to setup TX queue\n");
2802         }
2803 }
2804
2805 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2806         .f = cmd_setup_rxtx_queue_parsed,
2807         .data = NULL,
2808         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2809         .tokens = {
2810                 (void *)&cmd_setup_rxtx_queue_port,
2811                 (void *)&cmd_setup_rxtx_queue_portid,
2812                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2813                 (void *)&cmd_setup_rxtx_queue_qid,
2814                 (void *)&cmd_setup_rxtx_queue_setup,
2815                 NULL,
2816         },
2817 };
2818
2819
2820 /* *** Configure RSS RETA *** */
2821 struct cmd_config_rss_reta {
2822         cmdline_fixed_string_t port;
2823         cmdline_fixed_string_t keyword;
2824         portid_t port_id;
2825         cmdline_fixed_string_t name;
2826         cmdline_fixed_string_t list_name;
2827         cmdline_fixed_string_t list_of_items;
2828 };
2829
2830 static int
2831 parse_reta_config(const char *str,
2832                   struct rte_eth_rss_reta_entry64 *reta_conf,
2833                   uint16_t nb_entries)
2834 {
2835         int i;
2836         unsigned size;
2837         uint16_t hash_index, idx, shift;
2838         uint16_t nb_queue;
2839         char s[256];
2840         const char *p, *p0 = str;
2841         char *end;
2842         enum fieldnames {
2843                 FLD_HASH_INDEX = 0,
2844                 FLD_QUEUE,
2845                 _NUM_FLD
2846         };
2847         unsigned long int_fld[_NUM_FLD];
2848         char *str_fld[_NUM_FLD];
2849
2850         while ((p = strchr(p0,'(')) != NULL) {
2851                 ++p;
2852                 if((p0 = strchr(p,')')) == NULL)
2853                         return -1;
2854
2855                 size = p0 - p;
2856                 if(size >= sizeof(s))
2857                         return -1;
2858
2859                 snprintf(s, sizeof(s), "%.*s", size, p);
2860                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2861                         return -1;
2862                 for (i = 0; i < _NUM_FLD; i++) {
2863                         errno = 0;
2864                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2865                         if (errno != 0 || end == str_fld[i] ||
2866                                         int_fld[i] > 65535)
2867                                 return -1;
2868                 }
2869
2870                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2871                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2872
2873                 if (hash_index >= nb_entries) {
2874                         printf("Invalid RETA hash index=%d\n", hash_index);
2875                         return -1;
2876                 }
2877
2878                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2879                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2880                 reta_conf[idx].mask |= (1ULL << shift);
2881                 reta_conf[idx].reta[shift] = nb_queue;
2882         }
2883
2884         return 0;
2885 }
2886
2887 static void
2888 cmd_set_rss_reta_parsed(void *parsed_result,
2889                         __rte_unused struct cmdline *cl,
2890                         __rte_unused void *data)
2891 {
2892         int ret;
2893         struct rte_eth_dev_info dev_info;
2894         struct rte_eth_rss_reta_entry64 reta_conf[8];
2895         struct cmd_config_rss_reta *res = parsed_result;
2896
2897         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2898         if (ret != 0)
2899                 return;
2900
2901         if (dev_info.reta_size == 0) {
2902                 printf("Redirection table size is 0 which is "
2903                                         "invalid for RSS\n");
2904                 return;
2905         } else
2906                 printf("The reta size of port %d is %u\n",
2907                         res->port_id, dev_info.reta_size);
2908         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2909                 printf("Currently do not support more than %u entries of "
2910                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2911                 return;
2912         }
2913
2914         memset(reta_conf, 0, sizeof(reta_conf));
2915         if (!strcmp(res->list_name, "reta")) {
2916                 if (parse_reta_config(res->list_of_items, reta_conf,
2917                                                 dev_info.reta_size)) {
2918                         printf("Invalid RSS Redirection Table "
2919                                         "config entered\n");
2920                         return;
2921                 }
2922                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2923                                 reta_conf, dev_info.reta_size);
2924                 if (ret != 0)
2925                         printf("Bad redirection table parameter, "
2926                                         "return code = %d \n", ret);
2927         }
2928 }
2929
2930 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2931         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2932 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2933         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2934 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2935         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2936 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2937         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2938 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2939         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2940 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2941         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2942                                  NULL);
2943 cmdline_parse_inst_t cmd_config_rss_reta = {
2944         .f = cmd_set_rss_reta_parsed,
2945         .data = NULL,
2946         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2947         .tokens = {
2948                 (void *)&cmd_config_rss_reta_port,
2949                 (void *)&cmd_config_rss_reta_keyword,
2950                 (void *)&cmd_config_rss_reta_port_id,
2951                 (void *)&cmd_config_rss_reta_name,
2952                 (void *)&cmd_config_rss_reta_list_name,
2953                 (void *)&cmd_config_rss_reta_list_of_items,
2954                 NULL,
2955         },
2956 };
2957
2958 /* *** SHOW PORT RETA INFO *** */
2959 struct cmd_showport_reta {
2960         cmdline_fixed_string_t show;
2961         cmdline_fixed_string_t port;
2962         portid_t port_id;
2963         cmdline_fixed_string_t rss;
2964         cmdline_fixed_string_t reta;
2965         uint16_t size;
2966         cmdline_fixed_string_t list_of_items;
2967 };
2968
2969 static int
2970 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2971                            uint16_t nb_entries,
2972                            char *str)
2973 {
2974         uint32_t size;
2975         const char *p, *p0 = str;
2976         char s[256];
2977         char *end;
2978         char *str_fld[8];
2979         uint16_t i;
2980         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2981                         RTE_RETA_GROUP_SIZE;
2982         int ret;
2983
2984         p = strchr(p0, '(');
2985         if (p == NULL)
2986                 return -1;
2987         p++;
2988         p0 = strchr(p, ')');
2989         if (p0 == NULL)
2990                 return -1;
2991         size = p0 - p;
2992         if (size >= sizeof(s)) {
2993                 printf("The string size exceeds the internal buffer size\n");
2994                 return -1;
2995         }
2996         snprintf(s, sizeof(s), "%.*s", size, p);
2997         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2998         if (ret <= 0 || ret != num) {
2999                 printf("The bits of masks do not match the number of "
3000                                         "reta entries: %u\n", num);
3001                 return -1;
3002         }
3003         for (i = 0; i < ret; i++)
3004                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3005
3006         return 0;
3007 }
3008
3009 static void
3010 cmd_showport_reta_parsed(void *parsed_result,
3011                          __rte_unused struct cmdline *cl,
3012                          __rte_unused void *data)
3013 {
3014         struct cmd_showport_reta *res = parsed_result;
3015         struct rte_eth_rss_reta_entry64 reta_conf[8];
3016         struct rte_eth_dev_info dev_info;
3017         uint16_t max_reta_size;
3018         int ret;
3019
3020         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3021         if (ret != 0)
3022                 return;
3023
3024         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3025         if (res->size == 0 || res->size > max_reta_size) {
3026                 printf("Invalid redirection table size: %u (1-%u)\n",
3027                         res->size, max_reta_size);
3028                 return;
3029         }
3030
3031         memset(reta_conf, 0, sizeof(reta_conf));
3032         if (showport_parse_reta_config(reta_conf, res->size,
3033                                 res->list_of_items) < 0) {
3034                 printf("Invalid string: %s for reta masks\n",
3035                                         res->list_of_items);
3036                 return;
3037         }
3038         port_rss_reta_info(res->port_id, reta_conf, res->size);
3039 }
3040
3041 cmdline_parse_token_string_t cmd_showport_reta_show =
3042         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3043 cmdline_parse_token_string_t cmd_showport_reta_port =
3044         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3045 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3046         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3047 cmdline_parse_token_string_t cmd_showport_reta_rss =
3048         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3049 cmdline_parse_token_string_t cmd_showport_reta_reta =
3050         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3051 cmdline_parse_token_num_t cmd_showport_reta_size =
3052         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3053 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3054         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3055                                         list_of_items, NULL);
3056
3057 cmdline_parse_inst_t cmd_showport_reta = {
3058         .f = cmd_showport_reta_parsed,
3059         .data = NULL,
3060         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3061         .tokens = {
3062                 (void *)&cmd_showport_reta_show,
3063                 (void *)&cmd_showport_reta_port,
3064                 (void *)&cmd_showport_reta_port_id,
3065                 (void *)&cmd_showport_reta_rss,
3066                 (void *)&cmd_showport_reta_reta,
3067                 (void *)&cmd_showport_reta_size,
3068                 (void *)&cmd_showport_reta_list_of_items,
3069                 NULL,
3070         },
3071 };
3072
3073 /* *** Show RSS hash configuration *** */
3074 struct cmd_showport_rss_hash {
3075         cmdline_fixed_string_t show;
3076         cmdline_fixed_string_t port;
3077         portid_t port_id;
3078         cmdline_fixed_string_t rss_hash;
3079         cmdline_fixed_string_t rss_type;
3080         cmdline_fixed_string_t key; /* optional argument */
3081 };
3082
3083 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3084                                 __rte_unused struct cmdline *cl,
3085                                 void *show_rss_key)
3086 {
3087         struct cmd_showport_rss_hash *res = parsed_result;
3088
3089         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3090 }
3091
3092 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3093         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3094 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3095         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3096 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3097         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3098 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3099         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3100                                  "rss-hash");
3101 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3102         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3103
3104 cmdline_parse_inst_t cmd_showport_rss_hash = {
3105         .f = cmd_showport_rss_hash_parsed,
3106         .data = NULL,
3107         .help_str = "show port <port_id> rss-hash",
3108         .tokens = {
3109                 (void *)&cmd_showport_rss_hash_show,
3110                 (void *)&cmd_showport_rss_hash_port,
3111                 (void *)&cmd_showport_rss_hash_port_id,
3112                 (void *)&cmd_showport_rss_hash_rss_hash,
3113                 NULL,
3114         },
3115 };
3116
3117 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3118         .f = cmd_showport_rss_hash_parsed,
3119         .data = (void *)1,
3120         .help_str = "show port <port_id> rss-hash key",
3121         .tokens = {
3122                 (void *)&cmd_showport_rss_hash_show,
3123                 (void *)&cmd_showport_rss_hash_port,
3124                 (void *)&cmd_showport_rss_hash_port_id,
3125                 (void *)&cmd_showport_rss_hash_rss_hash,
3126                 (void *)&cmd_showport_rss_hash_rss_key,
3127                 NULL,
3128         },
3129 };
3130
3131 /* *** Configure DCB *** */
3132 struct cmd_config_dcb {
3133         cmdline_fixed_string_t port;
3134         cmdline_fixed_string_t config;
3135         portid_t port_id;
3136         cmdline_fixed_string_t dcb;
3137         cmdline_fixed_string_t vt;
3138         cmdline_fixed_string_t vt_en;
3139         uint8_t num_tcs;
3140         cmdline_fixed_string_t pfc;
3141         cmdline_fixed_string_t pfc_en;
3142 };
3143
3144 static void
3145 cmd_config_dcb_parsed(void *parsed_result,
3146                         __rte_unused struct cmdline *cl,
3147                         __rte_unused void *data)
3148 {
3149         struct cmd_config_dcb *res = parsed_result;
3150         portid_t port_id = res->port_id;
3151         struct rte_port *port;
3152         uint8_t pfc_en;
3153         int ret;
3154
3155         port = &ports[port_id];
3156         /** Check if the port is not started **/
3157         if (port->port_status != RTE_PORT_STOPPED) {
3158                 printf("Please stop port %d first\n", port_id);
3159                 return;
3160         }
3161
3162         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3163                 printf("The invalid number of traffic class,"
3164                         " only 4 or 8 allowed.\n");
3165                 return;
3166         }
3167
3168         if (nb_fwd_lcores < res->num_tcs) {
3169                 printf("nb_cores shouldn't be less than number of TCs.\n");
3170                 return;
3171         }
3172         if (!strncmp(res->pfc_en, "on", 2))
3173                 pfc_en = 1;
3174         else
3175                 pfc_en = 0;
3176
3177         /* DCB in VT mode */
3178         if (!strncmp(res->vt_en, "on", 2))
3179                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3180                                 (enum rte_eth_nb_tcs)res->num_tcs,
3181                                 pfc_en);
3182         else
3183                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3184                                 (enum rte_eth_nb_tcs)res->num_tcs,
3185                                 pfc_en);
3186
3187
3188         if (ret != 0) {
3189                 printf("Cannot initialize network ports.\n");
3190                 return;
3191         }
3192
3193         cmd_reconfig_device_queue(port_id, 1, 1);
3194 }
3195
3196 cmdline_parse_token_string_t cmd_config_dcb_port =
3197         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3198 cmdline_parse_token_string_t cmd_config_dcb_config =
3199         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3200 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3201         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3202 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3203         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3204 cmdline_parse_token_string_t cmd_config_dcb_vt =
3205         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3206 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3207         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3208 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3209         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3210 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3211         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3212 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3213         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3214
3215 cmdline_parse_inst_t cmd_config_dcb = {
3216         .f = cmd_config_dcb_parsed,
3217         .data = NULL,
3218         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3219         .tokens = {
3220                 (void *)&cmd_config_dcb_port,
3221                 (void *)&cmd_config_dcb_config,
3222                 (void *)&cmd_config_dcb_port_id,
3223                 (void *)&cmd_config_dcb_dcb,
3224                 (void *)&cmd_config_dcb_vt,
3225                 (void *)&cmd_config_dcb_vt_en,
3226                 (void *)&cmd_config_dcb_num_tcs,
3227                 (void *)&cmd_config_dcb_pfc,
3228                 (void *)&cmd_config_dcb_pfc_en,
3229                 NULL,
3230         },
3231 };
3232
3233 /* *** configure number of packets per burst *** */
3234 struct cmd_config_burst {
3235         cmdline_fixed_string_t port;
3236         cmdline_fixed_string_t keyword;
3237         cmdline_fixed_string_t all;
3238         cmdline_fixed_string_t name;
3239         uint16_t value;
3240 };
3241
3242 static void
3243 cmd_config_burst_parsed(void *parsed_result,
3244                         __rte_unused struct cmdline *cl,
3245                         __rte_unused void *data)
3246 {
3247         struct cmd_config_burst *res = parsed_result;
3248         struct rte_eth_dev_info dev_info;
3249         uint16_t rec_nb_pkts;
3250         int ret;
3251
3252         if (!all_ports_stopped()) {
3253                 printf("Please stop all ports first\n");
3254                 return;
3255         }
3256
3257         if (!strcmp(res->name, "burst")) {
3258                 if (res->value == 0) {
3259                         /* If user gives a value of zero, query the PMD for
3260                          * its recommended Rx burst size. Testpmd uses a single
3261                          * size for all ports, so assume all ports are the same
3262                          * NIC model and use the values from Port 0.
3263                          */
3264                         ret = eth_dev_info_get_print_err(0, &dev_info);
3265                         if (ret != 0)
3266                                 return;
3267
3268                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3269
3270                         if (rec_nb_pkts == 0) {
3271                                 printf("PMD does not recommend a burst size.\n"
3272                                         "User provided value must be between"
3273                                         " 1 and %d\n", MAX_PKT_BURST);
3274                                 return;
3275                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3276                                 printf("PMD recommended burst size of %d"
3277                                         " exceeds maximum value of %d\n",
3278                                         rec_nb_pkts, MAX_PKT_BURST);
3279                                 return;
3280                         }
3281                         printf("Using PMD-provided burst value of %d\n",
3282                                 rec_nb_pkts);
3283                         nb_pkt_per_burst = rec_nb_pkts;
3284                 } else if (res->value > MAX_PKT_BURST) {
3285                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3286                         return;
3287                 } else
3288                         nb_pkt_per_burst = res->value;
3289         } else {
3290                 printf("Unknown parameter\n");
3291                 return;
3292         }
3293
3294         init_port_config();
3295
3296         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3297 }
3298
3299 cmdline_parse_token_string_t cmd_config_burst_port =
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3301 cmdline_parse_token_string_t cmd_config_burst_keyword =
3302         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3303 cmdline_parse_token_string_t cmd_config_burst_all =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3305 cmdline_parse_token_string_t cmd_config_burst_name =
3306         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3307 cmdline_parse_token_num_t cmd_config_burst_value =
3308         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3309
3310 cmdline_parse_inst_t cmd_config_burst = {
3311         .f = cmd_config_burst_parsed,
3312         .data = NULL,
3313         .help_str = "port config all burst <value>",
3314         .tokens = {
3315                 (void *)&cmd_config_burst_port,
3316                 (void *)&cmd_config_burst_keyword,
3317                 (void *)&cmd_config_burst_all,
3318                 (void *)&cmd_config_burst_name,
3319                 (void *)&cmd_config_burst_value,
3320                 NULL,
3321         },
3322 };
3323
3324 /* *** configure rx/tx queues *** */
3325 struct cmd_config_thresh {
3326         cmdline_fixed_string_t port;
3327         cmdline_fixed_string_t keyword;
3328         cmdline_fixed_string_t all;
3329         cmdline_fixed_string_t name;
3330         uint8_t value;
3331 };
3332
3333 static void
3334 cmd_config_thresh_parsed(void *parsed_result,
3335                         __rte_unused struct cmdline *cl,
3336                         __rte_unused void *data)
3337 {
3338         struct cmd_config_thresh *res = parsed_result;
3339
3340         if (!all_ports_stopped()) {
3341                 printf("Please stop all ports first\n");
3342                 return;
3343         }
3344
3345         if (!strcmp(res->name, "txpt"))
3346                 tx_pthresh = res->value;
3347         else if(!strcmp(res->name, "txht"))
3348                 tx_hthresh = res->value;
3349         else if(!strcmp(res->name, "txwt"))
3350                 tx_wthresh = res->value;
3351         else if(!strcmp(res->name, "rxpt"))
3352                 rx_pthresh = res->value;
3353         else if(!strcmp(res->name, "rxht"))
3354                 rx_hthresh = res->value;
3355         else if(!strcmp(res->name, "rxwt"))
3356                 rx_wthresh = res->value;
3357         else {
3358                 printf("Unknown parameter\n");
3359                 return;
3360         }
3361
3362         init_port_config();
3363
3364         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3365 }
3366
3367 cmdline_parse_token_string_t cmd_config_thresh_port =
3368         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3369 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3370         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3371 cmdline_parse_token_string_t cmd_config_thresh_all =
3372         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3373 cmdline_parse_token_string_t cmd_config_thresh_name =
3374         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3375                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3376 cmdline_parse_token_num_t cmd_config_thresh_value =
3377         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3378
3379 cmdline_parse_inst_t cmd_config_thresh = {
3380         .f = cmd_config_thresh_parsed,
3381         .data = NULL,
3382         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3383         .tokens = {
3384                 (void *)&cmd_config_thresh_port,
3385                 (void *)&cmd_config_thresh_keyword,
3386                 (void *)&cmd_config_thresh_all,
3387                 (void *)&cmd_config_thresh_name,
3388                 (void *)&cmd_config_thresh_value,
3389                 NULL,
3390         },
3391 };
3392
3393 /* *** configure free/rs threshold *** */
3394 struct cmd_config_threshold {
3395         cmdline_fixed_string_t port;
3396         cmdline_fixed_string_t keyword;
3397         cmdline_fixed_string_t all;
3398         cmdline_fixed_string_t name;
3399         uint16_t value;
3400 };
3401
3402 static void
3403 cmd_config_threshold_parsed(void *parsed_result,
3404                         __rte_unused struct cmdline *cl,
3405                         __rte_unused void *data)
3406 {
3407         struct cmd_config_threshold *res = parsed_result;
3408
3409         if (!all_ports_stopped()) {
3410                 printf("Please stop all ports first\n");
3411                 return;
3412         }
3413
3414         if (!strcmp(res->name, "txfreet"))
3415                 tx_free_thresh = res->value;
3416         else if (!strcmp(res->name, "txrst"))
3417                 tx_rs_thresh = res->value;
3418         else if (!strcmp(res->name, "rxfreet"))
3419                 rx_free_thresh = res->value;
3420         else {
3421                 printf("Unknown parameter\n");
3422                 return;
3423         }
3424
3425         init_port_config();
3426
3427         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3428 }
3429
3430 cmdline_parse_token_string_t cmd_config_threshold_port =
3431         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3432 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3433         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3434                                                                 "config");
3435 cmdline_parse_token_string_t cmd_config_threshold_all =
3436         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3437 cmdline_parse_token_string_t cmd_config_threshold_name =
3438         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3439                                                 "txfreet#txrst#rxfreet");
3440 cmdline_parse_token_num_t cmd_config_threshold_value =
3441         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3442
3443 cmdline_parse_inst_t cmd_config_threshold = {
3444         .f = cmd_config_threshold_parsed,
3445         .data = NULL,
3446         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3447         .tokens = {
3448                 (void *)&cmd_config_threshold_port,
3449                 (void *)&cmd_config_threshold_keyword,
3450                 (void *)&cmd_config_threshold_all,
3451                 (void *)&cmd_config_threshold_name,
3452                 (void *)&cmd_config_threshold_value,
3453                 NULL,
3454         },
3455 };
3456
3457 /* *** stop *** */
3458 struct cmd_stop_result {
3459         cmdline_fixed_string_t stop;
3460 };
3461
3462 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3463                             __rte_unused struct cmdline *cl,
3464                             __rte_unused void *data)
3465 {
3466         stop_packet_forwarding();
3467 }
3468
3469 cmdline_parse_token_string_t cmd_stop_stop =
3470         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3471
3472 cmdline_parse_inst_t cmd_stop = {
3473         .f = cmd_stop_parsed,
3474         .data = NULL,
3475         .help_str = "stop: Stop packet forwarding",
3476         .tokens = {
3477                 (void *)&cmd_stop_stop,
3478                 NULL,
3479         },
3480 };
3481
3482 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3483
3484 unsigned int
3485 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3486                 unsigned int *parsed_items, int check_unique_values)
3487 {
3488         unsigned int nb_item;
3489         unsigned int value;
3490         unsigned int i;
3491         unsigned int j;
3492         int value_ok;
3493         char c;
3494
3495         /*
3496          * First parse all items in the list and store their value.
3497          */
3498         value = 0;
3499         nb_item = 0;
3500         value_ok = 0;
3501         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3502                 c = str[i];
3503                 if ((c >= '0') && (c <= '9')) {
3504                         value = (unsigned int) (value * 10 + (c - '0'));
3505                         value_ok = 1;
3506                         continue;
3507                 }
3508                 if (c != ',') {
3509                         printf("character %c is not a decimal digit\n", c);
3510                         return 0;
3511                 }
3512                 if (! value_ok) {
3513                         printf("No valid value before comma\n");
3514                         return 0;
3515                 }
3516                 if (nb_item < max_items) {
3517                         parsed_items[nb_item] = value;
3518                         value_ok = 0;
3519                         value = 0;
3520                 }
3521                 nb_item++;
3522         }
3523         if (nb_item >= max_items) {
3524                 printf("Number of %s = %u > %u (maximum items)\n",
3525                        item_name, nb_item + 1, max_items);
3526                 return 0;
3527         }
3528         parsed_items[nb_item++] = value;
3529         if (! check_unique_values)
3530                 return nb_item;
3531
3532         /*
3533          * Then, check that all values in the list are differents.
3534          * No optimization here...
3535          */
3536         for (i = 0; i < nb_item; i++) {
3537                 for (j = i + 1; j < nb_item; j++) {
3538                         if (parsed_items[j] == parsed_items[i]) {
3539                                 printf("duplicated %s %u at index %u and %u\n",
3540                                        item_name, parsed_items[i], i, j);
3541                                 return 0;
3542                         }
3543                 }
3544         }
3545         return nb_item;
3546 }
3547
3548 struct cmd_set_list_result {
3549         cmdline_fixed_string_t cmd_keyword;
3550         cmdline_fixed_string_t list_name;
3551         cmdline_fixed_string_t list_of_items;
3552 };
3553
3554 static void cmd_set_list_parsed(void *parsed_result,
3555                                 __rte_unused struct cmdline *cl,
3556                                 __rte_unused void *data)
3557 {
3558         struct cmd_set_list_result *res;
3559         union {
3560                 unsigned int lcorelist[RTE_MAX_LCORE];
3561                 unsigned int portlist[RTE_MAX_ETHPORTS];
3562         } parsed_items;
3563         unsigned int nb_item;
3564
3565         if (test_done == 0) {
3566                 printf("Please stop forwarding first\n");
3567                 return;
3568         }
3569
3570         res = parsed_result;
3571         if (!strcmp(res->list_name, "corelist")) {
3572                 nb_item = parse_item_list(res->list_of_items, "core",
3573                                           RTE_MAX_LCORE,
3574                                           parsed_items.lcorelist, 1);
3575                 if (nb_item > 0) {
3576                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3577                         fwd_config_setup();
3578                 }
3579                 return;
3580         }
3581         if (!strcmp(res->list_name, "portlist")) {
3582                 nb_item = parse_item_list(res->list_of_items, "port",
3583                                           RTE_MAX_ETHPORTS,
3584                                           parsed_items.portlist, 1);
3585                 if (nb_item > 0) {
3586                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3587                         fwd_config_setup();
3588                 }
3589         }
3590 }
3591
3592 cmdline_parse_token_string_t cmd_set_list_keyword =
3593         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3594                                  "set");
3595 cmdline_parse_token_string_t cmd_set_list_name =
3596         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3597                                  "corelist#portlist");
3598 cmdline_parse_token_string_t cmd_set_list_of_items =
3599         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3600                                  NULL);
3601
3602 cmdline_parse_inst_t cmd_set_fwd_list = {
3603         .f = cmd_set_list_parsed,
3604         .data = NULL,
3605         .help_str = "set corelist|portlist <list0[,list1]*>",
3606         .tokens = {
3607                 (void *)&cmd_set_list_keyword,
3608                 (void *)&cmd_set_list_name,
3609                 (void *)&cmd_set_list_of_items,
3610                 NULL,
3611         },
3612 };
3613
3614 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3615
3616 struct cmd_setmask_result {
3617         cmdline_fixed_string_t set;
3618         cmdline_fixed_string_t mask;
3619         uint64_t hexavalue;
3620 };
3621
3622 static void cmd_set_mask_parsed(void *parsed_result,
3623                                 __rte_unused struct cmdline *cl,
3624                                 __rte_unused void *data)
3625 {
3626         struct cmd_setmask_result *res = parsed_result;
3627
3628         if (test_done == 0) {
3629                 printf("Please stop forwarding first\n");
3630                 return;
3631         }
3632         if (!strcmp(res->mask, "coremask")) {
3633                 set_fwd_lcores_mask(res->hexavalue);
3634                 fwd_config_setup();
3635         } else if (!strcmp(res->mask, "portmask")) {
3636                 set_fwd_ports_mask(res->hexavalue);
3637                 fwd_config_setup();
3638         }
3639 }
3640
3641 cmdline_parse_token_string_t cmd_setmask_set =
3642         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3643 cmdline_parse_token_string_t cmd_setmask_mask =
3644         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3645                                  "coremask#portmask");
3646 cmdline_parse_token_num_t cmd_setmask_value =
3647         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3648
3649 cmdline_parse_inst_t cmd_set_fwd_mask = {
3650         .f = cmd_set_mask_parsed,
3651         .data = NULL,
3652         .help_str = "set coremask|portmask <hexadecimal value>",
3653         .tokens = {
3654                 (void *)&cmd_setmask_set,
3655                 (void *)&cmd_setmask_mask,
3656                 (void *)&cmd_setmask_value,
3657                 NULL,
3658         },
3659 };
3660
3661 /*
3662  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3663  */
3664 struct cmd_set_result {
3665         cmdline_fixed_string_t set;
3666         cmdline_fixed_string_t what;
3667         uint16_t value;
3668 };
3669
3670 static void cmd_set_parsed(void *parsed_result,
3671                            __rte_unused struct cmdline *cl,
3672                            __rte_unused void *data)
3673 {
3674         struct cmd_set_result *res = parsed_result;
3675         if (!strcmp(res->what, "nbport")) {
3676                 set_fwd_ports_number(res->value);
3677                 fwd_config_setup();
3678         } else if (!strcmp(res->what, "nbcore")) {
3679                 set_fwd_lcores_number(res->value);
3680                 fwd_config_setup();
3681         } else if (!strcmp(res->what, "burst"))
3682                 set_nb_pkt_per_burst(res->value);
3683         else if (!strcmp(res->what, "verbose"))
3684                 set_verbose_level(res->value);
3685 }
3686
3687 cmdline_parse_token_string_t cmd_set_set =
3688         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3689 cmdline_parse_token_string_t cmd_set_what =
3690         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3691                                  "nbport#nbcore#burst#verbose");
3692 cmdline_parse_token_num_t cmd_set_value =
3693         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3694
3695 cmdline_parse_inst_t cmd_set_numbers = {
3696         .f = cmd_set_parsed,
3697         .data = NULL,
3698         .help_str = "set nbport|nbcore|burst|verbose <value>",
3699         .tokens = {
3700                 (void *)&cmd_set_set,
3701                 (void *)&cmd_set_what,
3702                 (void *)&cmd_set_value,
3703                 NULL,
3704         },
3705 };
3706
3707 /* *** SET LOG LEVEL CONFIGURATION *** */
3708
3709 struct cmd_set_log_result {
3710         cmdline_fixed_string_t set;
3711         cmdline_fixed_string_t log;
3712         cmdline_fixed_string_t type;
3713         uint32_t level;
3714 };
3715
3716 static void
3717 cmd_set_log_parsed(void *parsed_result,
3718                    __rte_unused struct cmdline *cl,
3719                    __rte_unused void *data)
3720 {
3721         struct cmd_set_log_result *res;
3722         int ret;
3723
3724         res = parsed_result;
3725         if (!strcmp(res->type, "global"))
3726                 rte_log_set_global_level(res->level);
3727         else {
3728                 ret = rte_log_set_level_regexp(res->type, res->level);
3729                 if (ret < 0)
3730                         printf("Unable to set log level\n");
3731         }
3732 }
3733
3734 cmdline_parse_token_string_t cmd_set_log_set =
3735         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3736 cmdline_parse_token_string_t cmd_set_log_log =
3737         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3738 cmdline_parse_token_string_t cmd_set_log_type =
3739         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3740 cmdline_parse_token_num_t cmd_set_log_level =
3741         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3742
3743 cmdline_parse_inst_t cmd_set_log = {
3744         .f = cmd_set_log_parsed,
3745         .data = NULL,
3746         .help_str = "set log global|<type> <level>",
3747         .tokens = {
3748                 (void *)&cmd_set_log_set,
3749                 (void *)&cmd_set_log_log,
3750                 (void *)&cmd_set_log_type,
3751                 (void *)&cmd_set_log_level,
3752                 NULL,
3753         },
3754 };
3755
3756 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3757
3758 struct cmd_set_rxoffs_result {
3759         cmdline_fixed_string_t cmd_keyword;
3760         cmdline_fixed_string_t rxoffs;
3761         cmdline_fixed_string_t seg_offsets;
3762 };
3763
3764 static void
3765 cmd_set_rxoffs_parsed(void *parsed_result,
3766                       __rte_unused struct cmdline *cl,
3767                       __rte_unused void *data)
3768 {
3769         struct cmd_set_rxoffs_result *res;
3770         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3771         unsigned int nb_segs;
3772
3773         res = parsed_result;
3774         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3775                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3776         if (nb_segs > 0)
3777                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3778 }
3779
3780 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3781         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3782                                  cmd_keyword, "set");
3783 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3784         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3785                                  rxoffs, "rxoffs");
3786 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3787         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3788                                  seg_offsets, NULL);
3789
3790 cmdline_parse_inst_t cmd_set_rxoffs = {
3791         .f = cmd_set_rxoffs_parsed,
3792         .data = NULL,
3793         .help_str = "set rxoffs <len0[,len1]*>",
3794         .tokens = {
3795                 (void *)&cmd_set_rxoffs_keyword,
3796                 (void *)&cmd_set_rxoffs_name,
3797                 (void *)&cmd_set_rxoffs_offsets,
3798                 NULL,
3799         },
3800 };
3801
3802 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3803
3804 struct cmd_set_rxpkts_result {
3805         cmdline_fixed_string_t cmd_keyword;
3806         cmdline_fixed_string_t rxpkts;
3807         cmdline_fixed_string_t seg_lengths;
3808 };
3809
3810 static void
3811 cmd_set_rxpkts_parsed(void *parsed_result,
3812                       __rte_unused struct cmdline *cl,
3813                       __rte_unused void *data)
3814 {
3815         struct cmd_set_rxpkts_result *res;
3816         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3817         unsigned int nb_segs;
3818
3819         res = parsed_result;
3820         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3821                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3822         if (nb_segs > 0)
3823                 set_rx_pkt_segments(seg_lengths, nb_segs);
3824 }
3825
3826 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3827         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3828                                  cmd_keyword, "set");
3829 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3830         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3831                                  rxpkts, "rxpkts");
3832 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3833         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3834                                  seg_lengths, NULL);
3835
3836 cmdline_parse_inst_t cmd_set_rxpkts = {
3837         .f = cmd_set_rxpkts_parsed,
3838         .data = NULL,
3839         .help_str = "set rxpkts <len0[,len1]*>",
3840         .tokens = {
3841                 (void *)&cmd_set_rxpkts_keyword,
3842                 (void *)&cmd_set_rxpkts_name,
3843                 (void *)&cmd_set_rxpkts_lengths,
3844                 NULL,
3845         },
3846 };
3847
3848 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3849
3850 struct cmd_set_txpkts_result {
3851         cmdline_fixed_string_t cmd_keyword;
3852         cmdline_fixed_string_t txpkts;
3853         cmdline_fixed_string_t seg_lengths;
3854 };
3855
3856 static void
3857 cmd_set_txpkts_parsed(void *parsed_result,
3858                       __rte_unused struct cmdline *cl,
3859                       __rte_unused void *data)
3860 {
3861         struct cmd_set_txpkts_result *res;
3862         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3863         unsigned int nb_segs;
3864
3865         res = parsed_result;
3866         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3867                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3868         if (nb_segs > 0)
3869                 set_tx_pkt_segments(seg_lengths, nb_segs);
3870 }
3871
3872 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3873         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3874                                  cmd_keyword, "set");
3875 cmdline_parse_token_string_t cmd_set_txpkts_name =
3876         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3877                                  txpkts, "txpkts");
3878 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3879         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3880                                  seg_lengths, NULL);
3881
3882 cmdline_parse_inst_t cmd_set_txpkts = {
3883         .f = cmd_set_txpkts_parsed,
3884         .data = NULL,
3885         .help_str = "set txpkts <len0[,len1]*>",
3886         .tokens = {
3887                 (void *)&cmd_set_txpkts_keyword,
3888                 (void *)&cmd_set_txpkts_name,
3889                 (void *)&cmd_set_txpkts_lengths,
3890                 NULL,
3891         },
3892 };
3893
3894 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3895
3896 struct cmd_set_txsplit_result {
3897         cmdline_fixed_string_t cmd_keyword;
3898         cmdline_fixed_string_t txsplit;
3899         cmdline_fixed_string_t mode;
3900 };
3901
3902 static void
3903 cmd_set_txsplit_parsed(void *parsed_result,
3904                       __rte_unused struct cmdline *cl,
3905                       __rte_unused void *data)
3906 {
3907         struct cmd_set_txsplit_result *res;
3908
3909         res = parsed_result;
3910         set_tx_pkt_split(res->mode);
3911 }
3912
3913 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3914         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3915                                  cmd_keyword, "set");
3916 cmdline_parse_token_string_t cmd_set_txsplit_name =
3917         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3918                                  txsplit, "txsplit");
3919 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3920         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3921                                  mode, NULL);
3922
3923 cmdline_parse_inst_t cmd_set_txsplit = {
3924         .f = cmd_set_txsplit_parsed,
3925         .data = NULL,
3926         .help_str = "set txsplit on|off|rand",
3927         .tokens = {
3928                 (void *)&cmd_set_txsplit_keyword,
3929                 (void *)&cmd_set_txsplit_name,
3930                 (void *)&cmd_set_txsplit_mode,
3931                 NULL,
3932         },
3933 };
3934
3935 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3936
3937 struct cmd_set_txtimes_result {
3938         cmdline_fixed_string_t cmd_keyword;
3939         cmdline_fixed_string_t txtimes;
3940         cmdline_fixed_string_t tx_times;
3941 };
3942
3943 static void
3944 cmd_set_txtimes_parsed(void *parsed_result,
3945                        __rte_unused struct cmdline *cl,
3946                        __rte_unused void *data)
3947 {
3948         struct cmd_set_txtimes_result *res;
3949         unsigned int tx_times[2] = {0, 0};
3950         unsigned int n_times;
3951
3952         res = parsed_result;
3953         n_times = parse_item_list(res->tx_times, "tx times",
3954                                   2, tx_times, 0);
3955         if (n_times == 2)
3956                 set_tx_pkt_times(tx_times);
3957 }
3958
3959 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3960         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3961                                  cmd_keyword, "set");
3962 cmdline_parse_token_string_t cmd_set_txtimes_name =
3963         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3964                                  txtimes, "txtimes");
3965 cmdline_parse_token_string_t cmd_set_txtimes_value =
3966         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3967                                  tx_times, NULL);
3968
3969 cmdline_parse_inst_t cmd_set_txtimes = {
3970         .f = cmd_set_txtimes_parsed,
3971         .data = NULL,
3972         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3973         .tokens = {
3974                 (void *)&cmd_set_txtimes_keyword,
3975                 (void *)&cmd_set_txtimes_name,
3976                 (void *)&cmd_set_txtimes_value,
3977                 NULL,
3978         },
3979 };
3980
3981 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3982 struct cmd_rx_vlan_filter_all_result {
3983         cmdline_fixed_string_t rx_vlan;
3984         cmdline_fixed_string_t what;
3985         cmdline_fixed_string_t all;
3986         portid_t port_id;
3987 };
3988
3989 static void
3990 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3991                               __rte_unused struct cmdline *cl,
3992                               __rte_unused void *data)
3993 {
3994         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3995
3996         if (!strcmp(res->what, "add"))
3997                 rx_vlan_all_filter_set(res->port_id, 1);
3998         else
3999                 rx_vlan_all_filter_set(res->port_id, 0);
4000 }
4001
4002 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4003         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4004                                  rx_vlan, "rx_vlan");
4005 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4006         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4007                                  what, "add#rm");
4008 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4009         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4010                                  all, "all");
4011 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4012         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4013                               port_id, UINT16);
4014
4015 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4016         .f = cmd_rx_vlan_filter_all_parsed,
4017         .data = NULL,
4018         .help_str = "rx_vlan add|rm all <port_id>: "
4019                 "Add/Remove all identifiers to/from the set of VLAN "
4020                 "identifiers filtered by a port",
4021         .tokens = {
4022                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4023                 (void *)&cmd_rx_vlan_filter_all_what,
4024                 (void *)&cmd_rx_vlan_filter_all_all,
4025                 (void *)&cmd_rx_vlan_filter_all_portid,
4026                 NULL,
4027         },
4028 };
4029
4030 /* *** VLAN OFFLOAD SET ON A PORT *** */
4031 struct cmd_vlan_offload_result {
4032         cmdline_fixed_string_t vlan;
4033         cmdline_fixed_string_t set;
4034         cmdline_fixed_string_t vlan_type;
4035         cmdline_fixed_string_t what;
4036         cmdline_fixed_string_t on;
4037         cmdline_fixed_string_t port_id;
4038 };
4039
4040 static void
4041 cmd_vlan_offload_parsed(void *parsed_result,
4042                           __rte_unused struct cmdline *cl,
4043                           __rte_unused void *data)
4044 {
4045         int on;
4046         struct cmd_vlan_offload_result *res = parsed_result;
4047         char *str;
4048         int i, len = 0;
4049         portid_t port_id = 0;
4050         unsigned int tmp;
4051
4052         str = res->port_id;
4053         len = strnlen(str, STR_TOKEN_SIZE);
4054         i = 0;
4055         /* Get port_id first */
4056         while(i < len){
4057                 if(str[i] == ',')
4058                         break;
4059
4060                 i++;
4061         }
4062         str[i]='\0';
4063         tmp = strtoul(str, NULL, 0);
4064         /* If port_id greater that what portid_t can represent, return */
4065         if(tmp >= RTE_MAX_ETHPORTS)
4066                 return;
4067         port_id = (portid_t)tmp;
4068
4069         if (!strcmp(res->on, "on"))
4070                 on = 1;
4071         else
4072                 on = 0;
4073
4074         if (!strcmp(res->what, "strip"))
4075                 rx_vlan_strip_set(port_id,  on);
4076         else if(!strcmp(res->what, "stripq")){
4077                 uint16_t queue_id = 0;
4078
4079                 /* No queue_id, return */
4080                 if(i + 1 >= len) {
4081                         printf("must specify (port,queue_id)\n");
4082                         return;
4083                 }
4084                 tmp = strtoul(str + i + 1, NULL, 0);
4085                 /* If queue_id greater that what 16-bits can represent, return */
4086                 if(tmp > 0xffff)
4087                         return;
4088
4089                 queue_id = (uint16_t)tmp;
4090                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4091         }
4092         else if (!strcmp(res->what, "filter"))
4093                 rx_vlan_filter_set(port_id, on);
4094         else if (!strcmp(res->what, "qinq_strip"))
4095                 rx_vlan_qinq_strip_set(port_id, on);
4096         else
4097                 vlan_extend_set(port_id, on);
4098
4099         return;
4100 }
4101
4102 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4103         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4104                                  vlan, "vlan");
4105 cmdline_parse_token_string_t cmd_vlan_offload_set =
4106         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4107                                  set, "set");
4108 cmdline_parse_token_string_t cmd_vlan_offload_what =
4109         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4110                                 what, "strip#filter#qinq_strip#extend#stripq");
4111 cmdline_parse_token_string_t cmd_vlan_offload_on =
4112         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4113                               on, "on#off");
4114 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4115         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4116                               port_id, NULL);
4117
4118 cmdline_parse_inst_t cmd_vlan_offload = {
4119         .f = cmd_vlan_offload_parsed,
4120         .data = NULL,
4121         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4122                 "<port_id[,queue_id]>: "
4123                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4124         .tokens = {
4125                 (void *)&cmd_vlan_offload_vlan,
4126                 (void *)&cmd_vlan_offload_set,
4127                 (void *)&cmd_vlan_offload_what,
4128                 (void *)&cmd_vlan_offload_on,
4129                 (void *)&cmd_vlan_offload_portid,
4130                 NULL,
4131         },
4132 };
4133
4134 /* *** VLAN TPID SET ON A PORT *** */
4135 struct cmd_vlan_tpid_result {
4136         cmdline_fixed_string_t vlan;
4137         cmdline_fixed_string_t set;
4138         cmdline_fixed_string_t vlan_type;
4139         cmdline_fixed_string_t what;
4140         uint16_t tp_id;
4141         portid_t port_id;
4142 };
4143
4144 static void
4145 cmd_vlan_tpid_parsed(void *parsed_result,
4146                           __rte_unused struct cmdline *cl,
4147                           __rte_unused void *data)
4148 {
4149         struct cmd_vlan_tpid_result *res = parsed_result;
4150         enum rte_vlan_type vlan_type;
4151
4152         if (!strcmp(res->vlan_type, "inner"))
4153                 vlan_type = ETH_VLAN_TYPE_INNER;
4154         else if (!strcmp(res->vlan_type, "outer"))
4155                 vlan_type = ETH_VLAN_TYPE_OUTER;
4156         else {
4157                 printf("Unknown vlan type\n");
4158                 return;
4159         }
4160         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4161 }
4162
4163 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4164         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4165                                  vlan, "vlan");
4166 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4167         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4168                                  set, "set");
4169 cmdline_parse_token_string_t cmd_vlan_type =
4170         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4171                                  vlan_type, "inner#outer");
4172 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4173         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4174                                  what, "tpid");
4175 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4176         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4177                               tp_id, UINT16);
4178 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4179         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4180                               port_id, UINT16);
4181
4182 cmdline_parse_inst_t cmd_vlan_tpid = {
4183         .f = cmd_vlan_tpid_parsed,
4184         .data = NULL,
4185         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4186                 "Set the VLAN Ether type",
4187         .tokens = {
4188                 (void *)&cmd_vlan_tpid_vlan,
4189                 (void *)&cmd_vlan_tpid_set,
4190                 (void *)&cmd_vlan_type,
4191                 (void *)&cmd_vlan_tpid_what,
4192                 (void *)&cmd_vlan_tpid_tpid,
4193                 (void *)&cmd_vlan_tpid_portid,
4194                 NULL,
4195         },
4196 };
4197
4198 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4199 struct cmd_rx_vlan_filter_result {
4200         cmdline_fixed_string_t rx_vlan;
4201         cmdline_fixed_string_t what;
4202         uint16_t vlan_id;
4203         portid_t port_id;
4204 };
4205
4206 static void
4207 cmd_rx_vlan_filter_parsed(void *parsed_result,
4208                           __rte_unused struct cmdline *cl,
4209                           __rte_unused void *data)
4210 {
4211         struct cmd_rx_vlan_filter_result *res = parsed_result;
4212
4213         if (!strcmp(res->what, "add"))
4214                 rx_vft_set(res->port_id, res->vlan_id, 1);
4215         else
4216                 rx_vft_set(res->port_id, res->vlan_id, 0);
4217 }
4218
4219 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4220         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4221                                  rx_vlan, "rx_vlan");
4222 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4223         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4224                                  what, "add#rm");
4225 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4226         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4227                               vlan_id, UINT16);
4228 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4229         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4230                               port_id, UINT16);
4231
4232 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4233         .f = cmd_rx_vlan_filter_parsed,
4234         .data = NULL,
4235         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4236                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4237                 "identifiers filtered by a port",
4238         .tokens = {
4239                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4240                 (void *)&cmd_rx_vlan_filter_what,
4241                 (void *)&cmd_rx_vlan_filter_vlanid,
4242                 (void *)&cmd_rx_vlan_filter_portid,
4243                 NULL,
4244         },
4245 };
4246
4247 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4248 struct cmd_tx_vlan_set_result {
4249         cmdline_fixed_string_t tx_vlan;
4250         cmdline_fixed_string_t set;
4251         portid_t port_id;
4252         uint16_t vlan_id;
4253 };
4254
4255 static void
4256 cmd_tx_vlan_set_parsed(void *parsed_result,
4257                        __rte_unused struct cmdline *cl,
4258                        __rte_unused void *data)
4259 {
4260         struct cmd_tx_vlan_set_result *res = parsed_result;
4261
4262         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4263                 return;
4264
4265         if (!port_is_stopped(res->port_id)) {
4266                 printf("Please stop port %d first\n", res->port_id);
4267                 return;
4268         }
4269
4270         tx_vlan_set(res->port_id, res->vlan_id);
4271
4272         cmd_reconfig_device_queue(res->port_id, 1, 1);
4273 }
4274
4275 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4276         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4277                                  tx_vlan, "tx_vlan");
4278 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4279         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4280                                  set, "set");
4281 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4282         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4283                               port_id, UINT16);
4284 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4286                               vlan_id, UINT16);
4287
4288 cmdline_parse_inst_t cmd_tx_vlan_set = {
4289         .f = cmd_tx_vlan_set_parsed,
4290         .data = NULL,
4291         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4292                 "Enable hardware insertion of a single VLAN header "
4293                 "with a given TAG Identifier in packets sent on a port",
4294         .tokens = {
4295                 (void *)&cmd_tx_vlan_set_tx_vlan,
4296                 (void *)&cmd_tx_vlan_set_set,
4297                 (void *)&cmd_tx_vlan_set_portid,
4298                 (void *)&cmd_tx_vlan_set_vlanid,
4299                 NULL,
4300         },
4301 };
4302
4303 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4304 struct cmd_tx_vlan_set_qinq_result {
4305         cmdline_fixed_string_t tx_vlan;
4306         cmdline_fixed_string_t set;
4307         portid_t port_id;
4308         uint16_t vlan_id;
4309         uint16_t vlan_id_outer;
4310 };
4311
4312 static void
4313 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4314                             __rte_unused struct cmdline *cl,
4315                             __rte_unused void *data)
4316 {
4317         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4318
4319         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4320                 return;
4321
4322         if (!port_is_stopped(res->port_id)) {
4323                 printf("Please stop port %d first\n", res->port_id);
4324                 return;
4325         }
4326
4327         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4328
4329         cmd_reconfig_device_queue(res->port_id, 1, 1);
4330 }
4331
4332 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4333         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4334                 tx_vlan, "tx_vlan");
4335 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4336         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4337                 set, "set");
4338 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4339         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4340                 port_id, UINT16);
4341 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4342         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4343                 vlan_id, UINT16);
4344 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4345         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4346                 vlan_id_outer, UINT16);
4347
4348 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4349         .f = cmd_tx_vlan_set_qinq_parsed,
4350         .data = NULL,
4351         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4352                 "Enable hardware insertion of double VLAN header "
4353                 "with given TAG Identifiers in packets sent on a port",
4354         .tokens = {
4355                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4356                 (void *)&cmd_tx_vlan_set_qinq_set,
4357                 (void *)&cmd_tx_vlan_set_qinq_portid,
4358                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4359                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4360                 NULL,
4361         },
4362 };
4363
4364 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4365 struct cmd_tx_vlan_set_pvid_result {
4366         cmdline_fixed_string_t tx_vlan;
4367         cmdline_fixed_string_t set;
4368         cmdline_fixed_string_t pvid;
4369         portid_t port_id;
4370         uint16_t vlan_id;
4371         cmdline_fixed_string_t mode;
4372 };
4373
4374 static void
4375 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4376                             __rte_unused struct cmdline *cl,
4377                             __rte_unused void *data)
4378 {
4379         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4380
4381         if (strcmp(res->mode, "on") == 0)
4382                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4383         else
4384                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4385 }
4386
4387 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4388         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4389                                  tx_vlan, "tx_vlan");
4390 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4391         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4392                                  set, "set");
4393 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4394         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4395                                  pvid, "pvid");
4396 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4397         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4398                              port_id, UINT16);
4399 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4400         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4401                               vlan_id, UINT16);
4402 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4403         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4404                                  mode, "on#off");
4405
4406 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4407         .f = cmd_tx_vlan_set_pvid_parsed,
4408         .data = NULL,
4409         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4410         .tokens = {
4411                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4412                 (void *)&cmd_tx_vlan_set_pvid_set,
4413                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4414                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4415                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4416                 (void *)&cmd_tx_vlan_set_pvid_mode,
4417                 NULL,
4418         },
4419 };
4420
4421 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4422 struct cmd_tx_vlan_reset_result {
4423         cmdline_fixed_string_t tx_vlan;
4424         cmdline_fixed_string_t reset;
4425         portid_t port_id;
4426 };
4427
4428 static void
4429 cmd_tx_vlan_reset_parsed(void *parsed_result,
4430                          __rte_unused struct cmdline *cl,
4431                          __rte_unused void *data)
4432 {
4433         struct cmd_tx_vlan_reset_result *res = parsed_result;
4434
4435         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4436                 return;
4437
4438         if (!port_is_stopped(res->port_id)) {
4439                 printf("Please stop port %d first\n", res->port_id);
4440                 return;
4441         }
4442
4443         tx_vlan_reset(res->port_id);
4444
4445         cmd_reconfig_device_queue(res->port_id, 1, 1);
4446 }
4447
4448 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4449         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4450                                  tx_vlan, "tx_vlan");
4451 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4452         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4453                                  reset, "reset");
4454 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4455         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4456                               port_id, UINT16);
4457
4458 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4459         .f = cmd_tx_vlan_reset_parsed,
4460         .data = NULL,
4461         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4462                 "VLAN header in packets sent on a port",
4463         .tokens = {
4464                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4465                 (void *)&cmd_tx_vlan_reset_reset,
4466                 (void *)&cmd_tx_vlan_reset_portid,
4467                 NULL,
4468         },
4469 };
4470
4471
4472 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4473 struct cmd_csum_result {
4474         cmdline_fixed_string_t csum;
4475         cmdline_fixed_string_t mode;
4476         cmdline_fixed_string_t proto;
4477         cmdline_fixed_string_t hwsw;
4478         portid_t port_id;
4479 };
4480
4481 static void
4482 csum_show(int port_id)
4483 {
4484         struct rte_eth_dev_info dev_info;
4485         uint64_t tx_offloads;
4486         int ret;
4487
4488         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4489         printf("Parse tunnel is %s\n",
4490                 (ports[port_id].parse_tunnel) ? "on" : "off");
4491         printf("IP checksum offload is %s\n",
4492                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4493         printf("UDP checksum offload is %s\n",
4494                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4495         printf("TCP checksum offload is %s\n",
4496                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4497         printf("SCTP checksum offload is %s\n",
4498                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4499         printf("Outer-Ip checksum offload is %s\n",
4500                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4501         printf("Outer-Udp checksum offload is %s\n",
4502                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4503
4504         /* display warnings if configuration is not supported by the NIC */
4505         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4506         if (ret != 0)
4507                 return;
4508
4509         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4510                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4511                 printf("Warning: hardware IP checksum enabled but not "
4512                         "supported by port %d\n", port_id);
4513         }
4514         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4515                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4516                 printf("Warning: hardware UDP checksum enabled but not "
4517                         "supported by port %d\n", port_id);
4518         }
4519         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4520                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4521                 printf("Warning: hardware TCP checksum enabled but not "
4522                         "supported by port %d\n", port_id);
4523         }
4524         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4525                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4526                 printf("Warning: hardware SCTP checksum enabled but not "
4527                         "supported by port %d\n", port_id);
4528         }
4529         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4530                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4531                 printf("Warning: hardware outer IP checksum enabled but not "
4532                         "supported by port %d\n", port_id);
4533         }
4534         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4535                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4536                         == 0) {
4537                 printf("Warning: hardware outer UDP checksum enabled but not "
4538                         "supported by port %d\n", port_id);
4539         }
4540 }
4541
4542 static void
4543 cmd_config_queue_tx_offloads(struct rte_port *port)
4544 {
4545         int k;
4546
4547         /* Apply queue tx offloads configuration */
4548         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4549                 port->tx_conf[k].offloads =
4550                         port->dev_conf.txmode.offloads;
4551 }
4552
4553 static void
4554 cmd_csum_parsed(void *parsed_result,
4555                        __rte_unused struct cmdline *cl,
4556                        __rte_unused void *data)
4557 {
4558         struct cmd_csum_result *res = parsed_result;
4559         int hw = 0;
4560         uint64_t csum_offloads = 0;
4561         struct rte_eth_dev_info dev_info;
4562         int ret;
4563
4564         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4565                 printf("invalid port %d\n", res->port_id);
4566                 return;
4567         }
4568         if (!port_is_stopped(res->port_id)) {
4569                 printf("Please stop port %d first\n", res->port_id);
4570                 return;
4571         }
4572
4573         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4574         if (ret != 0)
4575                 return;
4576
4577         if (!strcmp(res->mode, "set")) {
4578
4579                 if (!strcmp(res->hwsw, "hw"))
4580                         hw = 1;
4581
4582                 if (!strcmp(res->proto, "ip")) {
4583                         if (hw == 0 || (dev_info.tx_offload_capa &
4584                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4585                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4586                         } else {
4587                                 printf("IP checksum offload is not supported "
4588                                        "by port %u\n", res->port_id);
4589                         }
4590                 } else if (!strcmp(res->proto, "udp")) {
4591                         if (hw == 0 || (dev_info.tx_offload_capa &
4592                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4593                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4594                         } else {
4595                                 printf("UDP checksum offload is not supported "
4596                                        "by port %u\n", res->port_id);
4597                         }
4598                 } else if (!strcmp(res->proto, "tcp")) {
4599                         if (hw == 0 || (dev_info.tx_offload_capa &
4600                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4601                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4602                         } else {
4603                                 printf("TCP checksum offload is not supported "
4604                                        "by port %u\n", res->port_id);
4605                         }
4606                 } else if (!strcmp(res->proto, "sctp")) {
4607                         if (hw == 0 || (dev_info.tx_offload_capa &
4608                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4609                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4610                         } else {
4611                                 printf("SCTP checksum offload is not supported "
4612                                        "by port %u\n", res->port_id);
4613                         }
4614                 } else if (!strcmp(res->proto, "outer-ip")) {
4615                         if (hw == 0 || (dev_info.tx_offload_capa &
4616                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4617                                 csum_offloads |=
4618                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4619                         } else {
4620                                 printf("Outer IP checksum offload is not "
4621                                        "supported by port %u\n", res->port_id);
4622                         }
4623                 } else if (!strcmp(res->proto, "outer-udp")) {
4624                         if (hw == 0 || (dev_info.tx_offload_capa &
4625                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4626                                 csum_offloads |=
4627                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4628                         } else {
4629                                 printf("Outer UDP checksum offload is not "
4630                                        "supported by port %u\n", res->port_id);
4631                         }
4632                 }
4633
4634                 if (hw) {
4635                         ports[res->port_id].dev_conf.txmode.offloads |=
4636                                                         csum_offloads;
4637                 } else {
4638                         ports[res->port_id].dev_conf.txmode.offloads &=
4639                                                         (~csum_offloads);
4640                 }
4641                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4642         }
4643         csum_show(res->port_id);
4644
4645         cmd_reconfig_device_queue(res->port_id, 1, 1);
4646 }
4647
4648 cmdline_parse_token_string_t cmd_csum_csum =
4649         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4650                                 csum, "csum");
4651 cmdline_parse_token_string_t cmd_csum_mode =
4652         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4653                                 mode, "set");
4654 cmdline_parse_token_string_t cmd_csum_proto =
4655         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4656                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4657 cmdline_parse_token_string_t cmd_csum_hwsw =
4658         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4659                                 hwsw, "hw#sw");
4660 cmdline_parse_token_num_t cmd_csum_portid =
4661         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4662                                 port_id, UINT16);
4663
4664 cmdline_parse_inst_t cmd_csum_set = {
4665         .f = cmd_csum_parsed,
4666         .data = NULL,
4667         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4668                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4669                 "using csum forward engine",
4670         .tokens = {
4671                 (void *)&cmd_csum_csum,
4672                 (void *)&cmd_csum_mode,
4673                 (void *)&cmd_csum_proto,
4674                 (void *)&cmd_csum_hwsw,
4675                 (void *)&cmd_csum_portid,
4676                 NULL,
4677         },
4678 };
4679
4680 cmdline_parse_token_string_t cmd_csum_mode_show =
4681         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4682                                 mode, "show");
4683
4684 cmdline_parse_inst_t cmd_csum_show = {
4685         .f = cmd_csum_parsed,
4686         .data = NULL,
4687         .help_str = "csum show <port_id>: Show checksum offload configuration",
4688         .tokens = {
4689                 (void *)&cmd_csum_csum,
4690                 (void *)&cmd_csum_mode_show,
4691                 (void *)&cmd_csum_portid,
4692                 NULL,
4693         },
4694 };
4695
4696 /* Enable/disable tunnel parsing */
4697 struct cmd_csum_tunnel_result {
4698         cmdline_fixed_string_t csum;
4699         cmdline_fixed_string_t parse;
4700         cmdline_fixed_string_t onoff;
4701         portid_t port_id;
4702 };
4703
4704 static void
4705 cmd_csum_tunnel_parsed(void *parsed_result,
4706                        __rte_unused struct cmdline *cl,
4707                        __rte_unused void *data)
4708 {
4709         struct cmd_csum_tunnel_result *res = parsed_result;
4710
4711         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4712                 return;
4713
4714         if (!strcmp(res->onoff, "on"))
4715                 ports[res->port_id].parse_tunnel = 1;
4716         else
4717                 ports[res->port_id].parse_tunnel = 0;
4718
4719         csum_show(res->port_id);
4720 }
4721
4722 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4723         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4724                                 csum, "csum");
4725 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4726         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4727                                 parse, "parse-tunnel");
4728 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4729         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4730                                 onoff, "on#off");
4731 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4732         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4733                                 port_id, UINT16);
4734
4735 cmdline_parse_inst_t cmd_csum_tunnel = {
4736         .f = cmd_csum_tunnel_parsed,
4737         .data = NULL,
4738         .help_str = "csum parse-tunnel on|off <port_id>: "
4739                 "Enable/Disable parsing of tunnels for csum engine",
4740         .tokens = {
4741                 (void *)&cmd_csum_tunnel_csum,
4742                 (void *)&cmd_csum_tunnel_parse,
4743                 (void *)&cmd_csum_tunnel_onoff,
4744                 (void *)&cmd_csum_tunnel_portid,
4745                 NULL,
4746         },
4747 };
4748
4749 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4750 struct cmd_tso_set_result {
4751         cmdline_fixed_string_t tso;
4752         cmdline_fixed_string_t mode;
4753         uint16_t tso_segsz;
4754         portid_t port_id;
4755 };
4756
4757 static void
4758 cmd_tso_set_parsed(void *parsed_result,
4759                        __rte_unused struct cmdline *cl,
4760                        __rte_unused void *data)
4761 {
4762         struct cmd_tso_set_result *res = parsed_result;
4763         struct rte_eth_dev_info dev_info;
4764         int ret;
4765
4766         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4767                 return;
4768         if (!port_is_stopped(res->port_id)) {
4769                 printf("Please stop port %d first\n", res->port_id);
4770                 return;
4771         }
4772
4773         if (!strcmp(res->mode, "set"))
4774                 ports[res->port_id].tso_segsz = res->tso_segsz;
4775
4776         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4777         if (ret != 0)
4778                 return;
4779
4780         if ((ports[res->port_id].tso_segsz != 0) &&
4781                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4782                 printf("Error: TSO is not supported by port %d\n",
4783                        res->port_id);
4784                 return;
4785         }
4786
4787         if (ports[res->port_id].tso_segsz == 0) {
4788                 ports[res->port_id].dev_conf.txmode.offloads &=
4789                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4790                 printf("TSO for non-tunneled packets is disabled\n");
4791         } else {
4792                 ports[res->port_id].dev_conf.txmode.offloads |=
4793                                                 DEV_TX_OFFLOAD_TCP_TSO;
4794                 printf("TSO segment size for non-tunneled packets is %d\n",
4795                         ports[res->port_id].tso_segsz);
4796         }
4797         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4798
4799         /* display warnings if configuration is not supported by the NIC */
4800         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4801         if (ret != 0)
4802                 return;
4803
4804         if ((ports[res->port_id].tso_segsz != 0) &&
4805                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4806                 printf("Warning: TSO enabled but not "
4807                         "supported by port %d\n", res->port_id);
4808         }
4809
4810         cmd_reconfig_device_queue(res->port_id, 1, 1);
4811 }
4812
4813 cmdline_parse_token_string_t cmd_tso_set_tso =
4814         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4815                                 tso, "tso");
4816 cmdline_parse_token_string_t cmd_tso_set_mode =
4817         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4818                                 mode, "set");
4819 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4820         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4821                                 tso_segsz, UINT16);
4822 cmdline_parse_token_num_t cmd_tso_set_portid =
4823         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4824                                 port_id, UINT16);
4825
4826 cmdline_parse_inst_t cmd_tso_set = {
4827         .f = cmd_tso_set_parsed,
4828         .data = NULL,
4829         .help_str = "tso set <tso_segsz> <port_id>: "
4830                 "Set TSO segment size of non-tunneled packets for csum engine "
4831                 "(0 to disable)",
4832         .tokens = {
4833                 (void *)&cmd_tso_set_tso,
4834                 (void *)&cmd_tso_set_mode,
4835                 (void *)&cmd_tso_set_tso_segsz,
4836                 (void *)&cmd_tso_set_portid,
4837                 NULL,
4838         },
4839 };
4840
4841 cmdline_parse_token_string_t cmd_tso_show_mode =
4842         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4843                                 mode, "show");
4844
4845
4846 cmdline_parse_inst_t cmd_tso_show = {
4847         .f = cmd_tso_set_parsed,
4848         .data = NULL,
4849         .help_str = "tso show <port_id>: "
4850                 "Show TSO segment size of non-tunneled packets for csum engine",
4851         .tokens = {
4852                 (void *)&cmd_tso_set_tso,
4853                 (void *)&cmd_tso_show_mode,
4854                 (void *)&cmd_tso_set_portid,
4855                 NULL,
4856         },
4857 };
4858
4859 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4860 struct cmd_tunnel_tso_set_result {
4861         cmdline_fixed_string_t tso;
4862         cmdline_fixed_string_t mode;
4863         uint16_t tso_segsz;
4864         portid_t port_id;
4865 };
4866
4867 static struct rte_eth_dev_info
4868 check_tunnel_tso_nic_support(portid_t port_id)
4869 {
4870         struct rte_eth_dev_info dev_info;
4871
4872         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4873                 return dev_info;
4874
4875         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4876                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4877                        "not enabled for port %d\n", port_id);
4878         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4879                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4880                        "not enabled for port %d\n", port_id);
4881         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4882                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4883                        "not enabled for port %d\n", port_id);
4884         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4885                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4886                        "not enabled for port %d\n", port_id);
4887         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4888                 printf("Warning: IP TUNNEL TSO not supported therefore "
4889                        "not enabled for port %d\n", port_id);
4890         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4891                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4892                        "not enabled for port %d\n", port_id);
4893         return dev_info;
4894 }
4895
4896 static void
4897 cmd_tunnel_tso_set_parsed(void *parsed_result,
4898                           __rte_unused struct cmdline *cl,
4899                           __rte_unused void *data)
4900 {
4901         struct cmd_tunnel_tso_set_result *res = parsed_result;
4902         struct rte_eth_dev_info dev_info;
4903
4904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4905                 return;
4906         if (!port_is_stopped(res->port_id)) {
4907                 printf("Please stop port %d first\n", res->port_id);
4908                 return;
4909         }
4910
4911         if (!strcmp(res->mode, "set"))
4912                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4913
4914         dev_info = check_tunnel_tso_nic_support(res->port_id);
4915         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4916                 ports[res->port_id].dev_conf.txmode.offloads &=
4917                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4918                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4919                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4920                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4921                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4922                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4923                 printf("TSO for tunneled packets is disabled\n");
4924         } else {
4925                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4926                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4927                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4928                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4929                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4930                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4931
4932                 ports[res->port_id].dev_conf.txmode.offloads |=
4933                         (tso_offloads & dev_info.tx_offload_capa);
4934                 printf("TSO segment size for tunneled packets is %d\n",
4935                         ports[res->port_id].tunnel_tso_segsz);
4936
4937                 /* Below conditions are needed to make it work:
4938                  * (1) tunnel TSO is supported by the NIC;
4939                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4940                  * are recognized;
4941                  * (3) for tunneled pkts with outer L3 of IPv4,
4942                  * "csum set outer-ip" must be set to hw, because after tso,
4943                  * total_len of outer IP header is changed, and the checksum
4944                  * of outer IP header calculated by sw should be wrong; that
4945                  * is not necessary for IPv6 tunneled pkts because there's no
4946                  * checksum in IP header anymore.
4947                  */
4948
4949                 if (!ports[res->port_id].parse_tunnel)
4950                         printf("Warning: csum parse_tunnel must be set "
4951                                 "so that tunneled packets are recognized\n");
4952                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4953                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4954                         printf("Warning: csum set outer-ip must be set to hw "
4955                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4956         }
4957
4958         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4959         cmd_reconfig_device_queue(res->port_id, 1, 1);
4960 }
4961
4962 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4963         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4964                                 tso, "tunnel_tso");
4965 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4966         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4967                                 mode, "set");
4968 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4969         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4970                                 tso_segsz, UINT16);
4971 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4972         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4973                                 port_id, UINT16);
4974
4975 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4976         .f = cmd_tunnel_tso_set_parsed,
4977         .data = NULL,
4978         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4979                 "Set TSO segment size of tunneled packets for csum engine "
4980                 "(0 to disable)",
4981         .tokens = {
4982                 (void *)&cmd_tunnel_tso_set_tso,
4983                 (void *)&cmd_tunnel_tso_set_mode,
4984                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4985                 (void *)&cmd_tunnel_tso_set_portid,
4986                 NULL,
4987         },
4988 };
4989
4990 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4991         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4992                                 mode, "show");
4993
4994
4995 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4996         .f = cmd_tunnel_tso_set_parsed,
4997         .data = NULL,
4998         .help_str = "tunnel_tso show <port_id> "
4999                 "Show TSO segment size of tunneled packets for csum engine",
5000         .tokens = {
5001                 (void *)&cmd_tunnel_tso_set_tso,
5002                 (void *)&cmd_tunnel_tso_show_mode,
5003                 (void *)&cmd_tunnel_tso_set_portid,
5004                 NULL,
5005         },
5006 };
5007
5008 /* *** SET GRO FOR A PORT *** */
5009 struct cmd_gro_enable_result {
5010         cmdline_fixed_string_t cmd_set;
5011         cmdline_fixed_string_t cmd_port;
5012         cmdline_fixed_string_t cmd_keyword;
5013         cmdline_fixed_string_t cmd_onoff;
5014         portid_t cmd_pid;
5015 };
5016
5017 static void
5018 cmd_gro_enable_parsed(void *parsed_result,
5019                 __rte_unused struct cmdline *cl,
5020                 __rte_unused void *data)
5021 {
5022         struct cmd_gro_enable_result *res;
5023
5024         res = parsed_result;
5025         if (!strcmp(res->cmd_keyword, "gro"))
5026                 setup_gro(res->cmd_onoff, res->cmd_pid);
5027 }
5028
5029 cmdline_parse_token_string_t cmd_gro_enable_set =
5030         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5031                         cmd_set, "set");
5032 cmdline_parse_token_string_t cmd_gro_enable_port =
5033         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5034                         cmd_keyword, "port");
5035 cmdline_parse_token_num_t cmd_gro_enable_pid =
5036         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5037                         cmd_pid, UINT16);
5038 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5039         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5040                         cmd_keyword, "gro");
5041 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5042         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5043                         cmd_onoff, "on#off");
5044
5045 cmdline_parse_inst_t cmd_gro_enable = {
5046         .f = cmd_gro_enable_parsed,
5047         .data = NULL,
5048         .help_str = "set port <port_id> gro on|off",
5049         .tokens = {
5050                 (void *)&cmd_gro_enable_set,
5051                 (void *)&cmd_gro_enable_port,
5052                 (void *)&cmd_gro_enable_pid,
5053                 (void *)&cmd_gro_enable_keyword,
5054                 (void *)&cmd_gro_enable_onoff,
5055                 NULL,
5056         },
5057 };
5058
5059 /* *** DISPLAY GRO CONFIGURATION *** */
5060 struct cmd_gro_show_result {
5061         cmdline_fixed_string_t cmd_show;
5062         cmdline_fixed_string_t cmd_port;
5063         cmdline_fixed_string_t cmd_keyword;
5064         portid_t cmd_pid;
5065 };
5066
5067 static void
5068 cmd_gro_show_parsed(void *parsed_result,
5069                 __rte_unused struct cmdline *cl,
5070                 __rte_unused void *data)
5071 {
5072         struct cmd_gro_show_result *res;
5073
5074         res = parsed_result;
5075         if (!strcmp(res->cmd_keyword, "gro"))
5076                 show_gro(res->cmd_pid);
5077 }
5078
5079 cmdline_parse_token_string_t cmd_gro_show_show =
5080         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5081                         cmd_show, "show");
5082 cmdline_parse_token_string_t cmd_gro_show_port =
5083         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5084                         cmd_port, "port");
5085 cmdline_parse_token_num_t cmd_gro_show_pid =
5086         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5087                         cmd_pid, UINT16);
5088 cmdline_parse_token_string_t cmd_gro_show_keyword =
5089         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5090                         cmd_keyword, "gro");
5091
5092 cmdline_parse_inst_t cmd_gro_show = {
5093         .f = cmd_gro_show_parsed,
5094         .data = NULL,
5095         .help_str = "show port <port_id> gro",
5096         .tokens = {
5097                 (void *)&cmd_gro_show_show,
5098                 (void *)&cmd_gro_show_port,
5099                 (void *)&cmd_gro_show_pid,
5100                 (void *)&cmd_gro_show_keyword,
5101                 NULL,
5102         },
5103 };
5104
5105 /* *** SET FLUSH CYCLES FOR GRO *** */
5106 struct cmd_gro_flush_result {
5107         cmdline_fixed_string_t cmd_set;
5108         cmdline_fixed_string_t cmd_keyword;
5109         cmdline_fixed_string_t cmd_flush;
5110         uint8_t cmd_cycles;
5111 };
5112
5113 static void
5114 cmd_gro_flush_parsed(void *parsed_result,
5115                 __rte_unused struct cmdline *cl,
5116                 __rte_unused void *data)
5117 {
5118         struct cmd_gro_flush_result *res;
5119
5120         res = parsed_result;
5121         if ((!strcmp(res->cmd_keyword, "gro")) &&
5122                         (!strcmp(res->cmd_flush, "flush")))
5123                 setup_gro_flush_cycles(res->cmd_cycles);
5124 }
5125
5126 cmdline_parse_token_string_t cmd_gro_flush_set =
5127         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5128                         cmd_set, "set");
5129 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5130         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5131                         cmd_keyword, "gro");
5132 cmdline_parse_token_string_t cmd_gro_flush_flush =
5133         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5134                         cmd_flush, "flush");
5135 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5136         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5137                         cmd_cycles, UINT8);
5138
5139 cmdline_parse_inst_t cmd_gro_flush = {
5140         .f = cmd_gro_flush_parsed,
5141         .data = NULL,
5142         .help_str = "set gro flush <cycles>",
5143         .tokens = {
5144                 (void *)&cmd_gro_flush_set,
5145                 (void *)&cmd_gro_flush_keyword,
5146                 (void *)&cmd_gro_flush_flush,
5147                 (void *)&cmd_gro_flush_cycles,
5148                 NULL,
5149         },
5150 };
5151
5152 /* *** ENABLE/DISABLE GSO *** */
5153 struct cmd_gso_enable_result {
5154         cmdline_fixed_string_t cmd_set;
5155         cmdline_fixed_string_t cmd_port;
5156         cmdline_fixed_string_t cmd_keyword;
5157         cmdline_fixed_string_t cmd_mode;
5158         portid_t cmd_pid;
5159 };
5160
5161 static void
5162 cmd_gso_enable_parsed(void *parsed_result,
5163                 __rte_unused struct cmdline *cl,
5164                 __rte_unused void *data)
5165 {
5166         struct cmd_gso_enable_result *res;
5167
5168         res = parsed_result;
5169         if (!strcmp(res->cmd_keyword, "gso"))
5170                 setup_gso(res->cmd_mode, res->cmd_pid);
5171 }
5172
5173 cmdline_parse_token_string_t cmd_gso_enable_set =
5174         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5175                         cmd_set, "set");
5176 cmdline_parse_token_string_t cmd_gso_enable_port =
5177         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5178                         cmd_port, "port");
5179 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5180         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5181                         cmd_keyword, "gso");
5182 cmdline_parse_token_string_t cmd_gso_enable_mode =
5183         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5184                         cmd_mode, "on#off");
5185 cmdline_parse_token_num_t cmd_gso_enable_pid =
5186         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5187                         cmd_pid, UINT16);
5188
5189 cmdline_parse_inst_t cmd_gso_enable = {
5190         .f = cmd_gso_enable_parsed,
5191         .data = NULL,
5192         .help_str = "set port <port_id> gso on|off",
5193         .tokens = {
5194                 (void *)&cmd_gso_enable_set,
5195                 (void *)&cmd_gso_enable_port,
5196                 (void *)&cmd_gso_enable_pid,
5197                 (void *)&cmd_gso_enable_keyword,
5198                 (void *)&cmd_gso_enable_mode,
5199                 NULL,
5200         },
5201 };
5202
5203 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5204 struct cmd_gso_size_result {
5205         cmdline_fixed_string_t cmd_set;
5206         cmdline_fixed_string_t cmd_keyword;
5207         cmdline_fixed_string_t cmd_segsz;
5208         uint16_t cmd_size;
5209 };
5210
5211 static void
5212 cmd_gso_size_parsed(void *parsed_result,
5213                        __rte_unused struct cmdline *cl,
5214                        __rte_unused void *data)
5215 {
5216         struct cmd_gso_size_result *res = parsed_result;
5217
5218         if (test_done == 0) {
5219                 printf("Before setting GSO segsz, please first"
5220                                 " stop forwarding\n");
5221                 return;
5222         }
5223
5224         if (!strcmp(res->cmd_keyword, "gso") &&
5225                         !strcmp(res->cmd_segsz, "segsz")) {
5226                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5227                         printf("gso_size should be larger than %zu."
5228                                         " Please input a legal value\n",
5229                                         RTE_GSO_SEG_SIZE_MIN);
5230                 else
5231                         gso_max_segment_size = res->cmd_size;
5232         }
5233 }
5234
5235 cmdline_parse_token_string_t cmd_gso_size_set =
5236         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5237                                 cmd_set, "set");
5238 cmdline_parse_token_string_t cmd_gso_size_keyword =
5239         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5240                                 cmd_keyword, "gso");
5241 cmdline_parse_token_string_t cmd_gso_size_segsz =
5242         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5243                                 cmd_segsz, "segsz");
5244 cmdline_parse_token_num_t cmd_gso_size_size =
5245         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5246                                 cmd_size, UINT16);
5247
5248 cmdline_parse_inst_t cmd_gso_size = {
5249         .f = cmd_gso_size_parsed,
5250         .data = NULL,
5251         .help_str = "set gso segsz <length>",
5252         .tokens = {
5253                 (void *)&cmd_gso_size_set,
5254                 (void *)&cmd_gso_size_keyword,
5255                 (void *)&cmd_gso_size_segsz,
5256                 (void *)&cmd_gso_size_size,
5257                 NULL,
5258         },
5259 };
5260
5261 /* *** SHOW GSO CONFIGURATION *** */
5262 struct cmd_gso_show_result {
5263         cmdline_fixed_string_t cmd_show;
5264         cmdline_fixed_string_t cmd_port;
5265         cmdline_fixed_string_t cmd_keyword;
5266         portid_t cmd_pid;
5267 };
5268
5269 static void
5270 cmd_gso_show_parsed(void *parsed_result,
5271                        __rte_unused struct cmdline *cl,
5272                        __rte_unused void *data)
5273 {
5274         struct cmd_gso_show_result *res = parsed_result;
5275
5276         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5277                 printf("invalid port id %u\n", res->cmd_pid);
5278                 return;
5279         }
5280         if (!strcmp(res->cmd_keyword, "gso")) {
5281                 if (gso_ports[res->cmd_pid].enable) {
5282                         printf("Max GSO'd packet size: %uB\n"
5283                                         "Supported GSO types: TCP/IPv4, "
5284                                         "UDP/IPv4, VxLAN with inner "
5285                                         "TCP/IPv4 packet, GRE with inner "
5286                                         "TCP/IPv4 packet\n",
5287                                         gso_max_segment_size);
5288                 } else
5289                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5290         }
5291 }
5292
5293 cmdline_parse_token_string_t cmd_gso_show_show =
5294 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5295                 cmd_show, "show");
5296 cmdline_parse_token_string_t cmd_gso_show_port =
5297 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5298                 cmd_port, "port");
5299 cmdline_parse_token_string_t cmd_gso_show_keyword =
5300         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5301                                 cmd_keyword, "gso");
5302 cmdline_parse_token_num_t cmd_gso_show_pid =
5303         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5304                                 cmd_pid, UINT16);
5305
5306 cmdline_parse_inst_t cmd_gso_show = {
5307         .f = cmd_gso_show_parsed,
5308         .data = NULL,
5309         .help_str = "show port <port_id> gso",
5310         .tokens = {
5311                 (void *)&cmd_gso_show_show,
5312                 (void *)&cmd_gso_show_port,
5313                 (void *)&cmd_gso_show_pid,
5314                 (void *)&cmd_gso_show_keyword,
5315                 NULL,
5316         },
5317 };
5318
5319 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5320 struct cmd_set_flush_rx {
5321         cmdline_fixed_string_t set;
5322         cmdline_fixed_string_t flush_rx;
5323         cmdline_fixed_string_t mode;
5324 };
5325
5326 static void
5327 cmd_set_flush_rx_parsed(void *parsed_result,
5328                 __rte_unused struct cmdline *cl,
5329                 __rte_unused void *data)
5330 {
5331         struct cmd_set_flush_rx *res = parsed_result;
5332         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5333 }
5334
5335 cmdline_parse_token_string_t cmd_setflushrx_set =
5336         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5337                         set, "set");
5338 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5339         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5340                         flush_rx, "flush_rx");
5341 cmdline_parse_token_string_t cmd_setflushrx_mode =
5342         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5343                         mode, "on#off");
5344
5345
5346 cmdline_parse_inst_t cmd_set_flush_rx = {
5347         .f = cmd_set_flush_rx_parsed,
5348         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5349         .data = NULL,
5350         .tokens = {
5351                 (void *)&cmd_setflushrx_set,
5352                 (void *)&cmd_setflushrx_flush_rx,
5353                 (void *)&cmd_setflushrx_mode,
5354                 NULL,
5355         },
5356 };
5357
5358 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5359 struct cmd_set_link_check {
5360         cmdline_fixed_string_t set;
5361         cmdline_fixed_string_t link_check;
5362         cmdline_fixed_string_t mode;
5363 };
5364
5365 static void
5366 cmd_set_link_check_parsed(void *parsed_result,
5367                 __rte_unused struct cmdline *cl,
5368                 __rte_unused void *data)
5369 {
5370         struct cmd_set_link_check *res = parsed_result;
5371         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5372 }
5373
5374 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5375         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5376                         set, "set");
5377 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5378         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5379                         link_check, "link_check");
5380 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5381         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5382                         mode, "on#off");
5383
5384
5385 cmdline_parse_inst_t cmd_set_link_check = {
5386         .f = cmd_set_link_check_parsed,
5387         .help_str = "set link_check on|off: Enable/Disable link status check "
5388                     "when starting/stopping a port",
5389         .data = NULL,
5390         .tokens = {
5391                 (void *)&cmd_setlinkcheck_set,
5392                 (void *)&cmd_setlinkcheck_link_check,
5393                 (void *)&cmd_setlinkcheck_mode,
5394                 NULL,
5395         },
5396 };
5397
5398 /* *** SET NIC BYPASS MODE *** */
5399 struct cmd_set_bypass_mode_result {
5400         cmdline_fixed_string_t set;
5401         cmdline_fixed_string_t bypass;
5402         cmdline_fixed_string_t mode;
5403         cmdline_fixed_string_t value;
5404         portid_t port_id;
5405 };
5406
5407 static void
5408 cmd_set_bypass_mode_parsed(void *parsed_result,
5409                 __rte_unused struct cmdline *cl,
5410                 __rte_unused void *data)
5411 {
5412         struct cmd_set_bypass_mode_result *res = parsed_result;
5413         portid_t port_id = res->port_id;
5414         int32_t rc = -EINVAL;
5415
5416 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5417         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5418
5419         if (!strcmp(res->value, "bypass"))
5420                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5421         else if (!strcmp(res->value, "isolate"))
5422                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5423         else
5424                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5425
5426         /* Set the bypass mode for the relevant port. */
5427         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5428 #endif
5429         if (rc != 0)
5430                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5431 }
5432
5433 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5434         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5435                         set, "set");
5436 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5437         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5438                         bypass, "bypass");
5439 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5441                         mode, "mode");
5442 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5444                         value, "normal#bypass#isolate");
5445 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5446         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5447                                 port_id, UINT16);
5448
5449 cmdline_parse_inst_t cmd_set_bypass_mode = {
5450         .f = cmd_set_bypass_mode_parsed,
5451         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5452                     "Set the NIC bypass mode for port_id",
5453         .data = NULL,
5454         .tokens = {
5455                 (void *)&cmd_setbypass_mode_set,
5456                 (void *)&cmd_setbypass_mode_bypass,
5457                 (void *)&cmd_setbypass_mode_mode,
5458                 (void *)&cmd_setbypass_mode_value,
5459                 (void *)&cmd_setbypass_mode_port,
5460                 NULL,
5461         },
5462 };
5463
5464 /* *** SET NIC BYPASS EVENT *** */
5465 struct cmd_set_bypass_event_result {
5466         cmdline_fixed_string_t set;
5467         cmdline_fixed_string_t bypass;
5468         cmdline_fixed_string_t event;
5469         cmdline_fixed_string_t event_value;
5470         cmdline_fixed_string_t mode;
5471         cmdline_fixed_string_t mode_value;
5472         portid_t port_id;
5473 };
5474
5475 static void
5476 cmd_set_bypass_event_parsed(void *parsed_result,
5477                 __rte_unused struct cmdline *cl,
5478                 __rte_unused void *data)
5479 {
5480         int32_t rc = -EINVAL;
5481         struct cmd_set_bypass_event_result *res = parsed_result;
5482         portid_t port_id = res->port_id;
5483
5484 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5485         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5486         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5487
5488         if (!strcmp(res->event_value, "timeout"))
5489                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5490         else if (!strcmp(res->event_value, "os_on"))
5491                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5492         else if (!strcmp(res->event_value, "os_off"))
5493                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5494         else if (!strcmp(res->event_value, "power_on"))
5495                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5496         else if (!strcmp(res->event_value, "power_off"))
5497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5498         else
5499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5500
5501         if (!strcmp(res->mode_value, "bypass"))
5502                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5503         else if (!strcmp(res->mode_value, "isolate"))
5504                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5505         else
5506                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5507
5508         /* Set the watchdog timeout. */
5509         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5510
5511                 rc = -EINVAL;
5512                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5513                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5514                                                            bypass_timeout);
5515                 }
5516                 if (rc != 0) {
5517                         printf("Failed to set timeout value %u "
5518                         "for port %d, errto code: %d.\n",
5519                         bypass_timeout, port_id, rc);
5520                 }
5521         }
5522
5523         /* Set the bypass event to transition to bypass mode. */
5524         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5525                                               bypass_mode);
5526 #endif
5527
5528         if (rc != 0)
5529                 printf("\t Failed to set bypass event for port = %d.\n",
5530                        port_id);
5531 }
5532
5533 cmdline_parse_token_string_t cmd_setbypass_event_set =
5534         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5535                         set, "set");
5536 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5537         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5538                         bypass, "bypass");
5539 cmdline_parse_token_string_t cmd_setbypass_event_event =
5540         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5541                         event, "event");
5542 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5543         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5544                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5545 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5547                         mode, "mode");
5548 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5550                         mode_value, "normal#bypass#isolate");
5551 cmdline_parse_token_num_t cmd_setbypass_event_port =
5552         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5553                                 port_id, UINT16);
5554
5555 cmdline_parse_inst_t cmd_set_bypass_event = {
5556         .f = cmd_set_bypass_event_parsed,
5557         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5558                 "power_off mode normal|bypass|isolate <port_id>: "
5559                 "Set the NIC bypass event mode for port_id",
5560         .data = NULL,
5561         .tokens = {
5562                 (void *)&cmd_setbypass_event_set,
5563                 (void *)&cmd_setbypass_event_bypass,
5564                 (void *)&cmd_setbypass_event_event,
5565                 (void *)&cmd_setbypass_event_event_value,
5566                 (void *)&cmd_setbypass_event_mode,
5567                 (void *)&cmd_setbypass_event_mode_value,
5568                 (void *)&cmd_setbypass_event_port,
5569                 NULL,
5570         },
5571 };
5572
5573
5574 /* *** SET NIC BYPASS TIMEOUT *** */
5575 struct cmd_set_bypass_timeout_result {
5576         cmdline_fixed_string_t set;
5577         cmdline_fixed_string_t bypass;
5578         cmdline_fixed_string_t timeout;
5579         cmdline_fixed_string_t value;
5580 };
5581
5582 static void
5583 cmd_set_bypass_timeout_parsed(void *parsed_result,
5584                 __rte_unused struct cmdline *cl,
5585                 __rte_unused void *data)
5586 {
5587         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5588
5589 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5590         if (!strcmp(res->value, "1.5"))
5591                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5592         else if (!strcmp(res->value, "2"))
5593                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5594         else if (!strcmp(res->value, "3"))
5595                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5596         else if (!strcmp(res->value, "4"))
5597                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5598         else if (!strcmp(res->value, "8"))
5599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5600         else if (!strcmp(res->value, "16"))
5601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5602         else if (!strcmp(res->value, "32"))
5603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5604         else
5605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5606 #endif
5607 }
5608
5609 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5611                         set, "set");
5612 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5614                         bypass, "bypass");
5615 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5616         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5617                         timeout, "timeout");
5618 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5619         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5620                         value, "0#1.5#2#3#4#8#16#32");
5621
5622 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5623         .f = cmd_set_bypass_timeout_parsed,
5624         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5625                 "Set the NIC bypass watchdog timeout in seconds",
5626         .data = NULL,
5627         .tokens = {
5628                 (void *)&cmd_setbypass_timeout_set,
5629                 (void *)&cmd_setbypass_timeout_bypass,
5630                 (void *)&cmd_setbypass_timeout_timeout,
5631                 (void *)&cmd_setbypass_timeout_value,
5632                 NULL,
5633         },
5634 };
5635
5636 /* *** SHOW NIC BYPASS MODE *** */
5637 struct cmd_show_bypass_config_result {
5638         cmdline_fixed_string_t show;
5639         cmdline_fixed_string_t bypass;
5640         cmdline_fixed_string_t config;
5641         portid_t port_id;
5642 };
5643
5644 static void
5645 cmd_show_bypass_config_parsed(void *parsed_result,
5646                 __rte_unused struct cmdline *cl,
5647                 __rte_unused void *data)
5648 {
5649         struct cmd_show_bypass_config_result *res = parsed_result;
5650         portid_t port_id = res->port_id;
5651         int rc = -EINVAL;
5652 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5653         uint32_t event_mode;
5654         uint32_t bypass_mode;
5655         uint32_t timeout = bypass_timeout;
5656         unsigned int i;
5657
5658         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5659                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5660         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5661                 {"UNKNOWN", "normal", "bypass", "isolate"};
5662         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5663                 "NONE",
5664                 "OS/board on",
5665                 "power supply on",
5666                 "OS/board off",
5667                 "power supply off",
5668                 "timeout"};
5669
5670         /* Display the bypass mode.*/
5671         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5672                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5673                 return;
5674         }
5675         else {
5676                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5677                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5678
5679                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5680         }
5681
5682         /* Display the bypass timeout.*/
5683         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5684                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5685
5686         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5687
5688         /* Display the bypass events and associated modes. */
5689         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5690
5691                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5692                         printf("\tFailed to get bypass mode for event = %s\n",
5693                                 events[i]);
5694                 } else {
5695                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5696                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5697
5698                         printf("\tbypass event: %-16s = %s\n", events[i],
5699                                 modes[event_mode]);
5700                 }
5701         }
5702 #endif
5703         if (rc != 0)
5704                 printf("\tFailed to get bypass configuration for port = %d\n",
5705                        port_id);
5706 }
5707
5708 cmdline_parse_token_string_t cmd_showbypass_config_show =
5709         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5710                         show, "show");
5711 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5712         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5713                         bypass, "bypass");
5714 cmdline_parse_token_string_t cmd_showbypass_config_config =
5715         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5716                         config, "config");
5717 cmdline_parse_token_num_t cmd_showbypass_config_port =
5718         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5719                                 port_id, UINT16);
5720
5721 cmdline_parse_inst_t cmd_show_bypass_config = {
5722         .f = cmd_show_bypass_config_parsed,
5723         .help_str = "show bypass config <port_id>: "
5724                     "Show the NIC bypass config for port_id",
5725         .data = NULL,
5726         .tokens = {
5727                 (void *)&cmd_showbypass_config_show,
5728                 (void *)&cmd_showbypass_config_bypass,
5729                 (void *)&cmd_showbypass_config_config,
5730                 (void *)&cmd_showbypass_config_port,
5731                 NULL,
5732         },
5733 };
5734
5735 #ifdef RTE_NET_BOND
5736 /* *** SET BONDING MODE *** */
5737 struct cmd_set_bonding_mode_result {
5738         cmdline_fixed_string_t set;
5739         cmdline_fixed_string_t bonding;
5740         cmdline_fixed_string_t mode;
5741         uint8_t value;
5742         portid_t port_id;
5743 };
5744
5745 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5746                 __rte_unused  struct cmdline *cl,
5747                 __rte_unused void *data)
5748 {
5749         struct cmd_set_bonding_mode_result *res = parsed_result;
5750         portid_t port_id = res->port_id;
5751
5752         /* Set the bonding mode for the relevant port. */
5753         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5754                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5755 }
5756
5757 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5758 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5759                 set, "set");
5760 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5761 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5762                 bonding, "bonding");
5763 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5764 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5765                 mode, "mode");
5766 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5767 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5768                 value, UINT8);
5769 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5770 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5771                 port_id, UINT16);
5772
5773 cmdline_parse_inst_t cmd_set_bonding_mode = {
5774                 .f = cmd_set_bonding_mode_parsed,
5775                 .help_str = "set bonding mode <mode_value> <port_id>: "
5776                         "Set the bonding mode for port_id",
5777                 .data = NULL,
5778                 .tokens = {
5779                                 (void *) &cmd_setbonding_mode_set,
5780                                 (void *) &cmd_setbonding_mode_bonding,
5781                                 (void *) &cmd_setbonding_mode_mode,
5782                                 (void *) &cmd_setbonding_mode_value,
5783                                 (void *) &cmd_setbonding_mode_port,
5784                                 NULL
5785                 }
5786 };
5787
5788 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5789 struct cmd_set_bonding_lacp_dedicated_queues_result {
5790         cmdline_fixed_string_t set;
5791         cmdline_fixed_string_t bonding;
5792         cmdline_fixed_string_t lacp;
5793         cmdline_fixed_string_t dedicated_queues;
5794         portid_t port_id;
5795         cmdline_fixed_string_t mode;
5796 };
5797
5798 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5799                 __rte_unused  struct cmdline *cl,
5800                 __rte_unused void *data)
5801 {
5802         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5803         portid_t port_id = res->port_id;
5804         struct rte_port *port;
5805
5806         port = &ports[port_id];
5807
5808         /** Check if the port is not started **/
5809         if (port->port_status != RTE_PORT_STOPPED) {
5810                 printf("Please stop port %d first\n", port_id);
5811                 return;
5812         }
5813
5814         if (!strcmp(res->mode, "enable")) {
5815                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5816                         printf("Dedicate queues for LACP control packets"
5817                                         " enabled\n");
5818                 else
5819                         printf("Enabling dedicate queues for LACP control "
5820                                         "packets on port %d failed\n", port_id);
5821         } else if (!strcmp(res->mode, "disable")) {
5822                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5823                         printf("Dedicated queues for LACP control packets "
5824                                         "disabled\n");
5825                 else
5826                         printf("Disabling dedicated queues for LACP control "
5827                                         "traffic on port %d failed\n", port_id);
5828         }
5829 }
5830
5831 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5832 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5833                 set, "set");
5834 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5835 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5836                 bonding, "bonding");
5837 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5838 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5839                 lacp, "lacp");
5840 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5841 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5842                 dedicated_queues, "dedicated_queues");
5843 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5844 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5845                 port_id, UINT16);
5846 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5848                 mode, "enable#disable");
5849
5850 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5851                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5852                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5853                         "enable|disable: "
5854                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5855                 .data = NULL,
5856                 .tokens = {
5857                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5858                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5859                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5860                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5861                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5862                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5863                         NULL
5864                 }
5865 };
5866
5867 /* *** SET BALANCE XMIT POLICY *** */
5868 struct cmd_set_bonding_balance_xmit_policy_result {
5869         cmdline_fixed_string_t set;
5870         cmdline_fixed_string_t bonding;
5871         cmdline_fixed_string_t balance_xmit_policy;
5872         portid_t port_id;
5873         cmdline_fixed_string_t policy;
5874 };
5875
5876 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5877                 __rte_unused  struct cmdline *cl,
5878                 __rte_unused void *data)
5879 {
5880         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5881         portid_t port_id = res->port_id;
5882         uint8_t policy;
5883
5884         if (!strcmp(res->policy, "l2")) {
5885                 policy = BALANCE_XMIT_POLICY_LAYER2;
5886         } else if (!strcmp(res->policy, "l23")) {
5887                 policy = BALANCE_XMIT_POLICY_LAYER23;
5888         } else if (!strcmp(res->policy, "l34")) {
5889                 policy = BALANCE_XMIT_POLICY_LAYER34;
5890         } else {
5891                 printf("\t Invalid xmit policy selection");
5892                 return;
5893         }
5894
5895         /* Set the bonding mode for the relevant port. */
5896         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5897                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5898                                 port_id);
5899         }
5900 }
5901
5902 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5903 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5904                 set, "set");
5905 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5906 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5907                 bonding, "bonding");
5908 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5910                 balance_xmit_policy, "balance_xmit_policy");
5911 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5912 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5913                 port_id, UINT16);
5914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5916                 policy, "l2#l23#l34");
5917
5918 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5919                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5920                 .help_str = "set bonding balance_xmit_policy <port_id> "
5921                         "l2|l23|l34: "
5922                         "Set the bonding balance_xmit_policy for port_id",
5923                 .data = NULL,
5924                 .tokens = {
5925                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5926                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5927                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5928                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5929                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5930                                 NULL
5931                 }
5932 };
5933
5934 /* *** SHOW NIC BONDING CONFIGURATION *** */
5935 struct cmd_show_bonding_config_result {
5936         cmdline_fixed_string_t show;
5937         cmdline_fixed_string_t bonding;
5938         cmdline_fixed_string_t config;
5939         portid_t port_id;
5940 };
5941
5942 static void cmd_show_bonding_config_parsed(void *parsed_result,
5943                 __rte_unused  struct cmdline *cl,
5944                 __rte_unused void *data)
5945 {
5946         struct cmd_show_bonding_config_result *res = parsed_result;
5947         int bonding_mode, agg_mode;
5948         portid_t slaves[RTE_MAX_ETHPORTS];
5949         int num_slaves, num_active_slaves;
5950         int primary_id;
5951         int i;
5952         portid_t port_id = res->port_id;
5953
5954         /* Display the bonding mode.*/
5955         bonding_mode = rte_eth_bond_mode_get(port_id);
5956         if (bonding_mode < 0) {
5957                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5958                 return;
5959         } else
5960                 printf("\tBonding mode: %d\n", bonding_mode);
5961
5962         if (bonding_mode == BONDING_MODE_BALANCE) {
5963                 int balance_xmit_policy;
5964
5965                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5966                 if (balance_xmit_policy < 0) {
5967                         printf("\tFailed to get balance xmit policy for port = %d\n",
5968                                         port_id);
5969                         return;
5970                 } else {
5971                         printf("\tBalance Xmit Policy: ");
5972
5973                         switch (balance_xmit_policy) {
5974                         case BALANCE_XMIT_POLICY_LAYER2:
5975                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5976                                 break;
5977                         case BALANCE_XMIT_POLICY_LAYER23:
5978                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5979                                 break;
5980                         case BALANCE_XMIT_POLICY_LAYER34:
5981                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5982                                 break;
5983                         }
5984                         printf("\n");
5985                 }
5986         }
5987
5988         if (bonding_mode == BONDING_MODE_8023AD) {
5989                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5990                 printf("\tIEEE802.3AD Aggregator Mode: ");
5991                 switch (agg_mode) {
5992                 case AGG_BANDWIDTH:
5993                         printf("bandwidth");
5994                         break;
5995                 case AGG_STABLE:
5996                         printf("stable");
5997                         break;
5998                 case AGG_COUNT:
5999                         printf("count");
6000                         break;
6001                 }
6002                 printf("\n");
6003         }
6004
6005         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6006
6007         if (num_slaves < 0) {
6008                 printf("\tFailed to get slave list for port = %d\n", port_id);
6009                 return;
6010         }
6011         if (num_slaves > 0) {
6012                 printf("\tSlaves (%d): [", num_slaves);
6013                 for (i = 0; i < num_slaves - 1; i++)
6014                         printf("%d ", slaves[i]);
6015
6016                 printf("%d]\n", slaves[num_slaves - 1]);
6017         } else {
6018                 printf("\tSlaves: []\n");
6019
6020         }
6021
6022         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6023                         RTE_MAX_ETHPORTS);
6024
6025         if (num_active_slaves < 0) {
6026                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6027                 return;
6028         }
6029         if (num_active_slaves > 0) {
6030                 printf("\tActive Slaves (%d): [", num_active_slaves);
6031                 for (i = 0; i < num_active_slaves - 1; i++)
6032                         printf("%d ", slaves[i]);
6033
6034                 printf("%d]\n", slaves[num_active_slaves - 1]);
6035
6036         } else {
6037                 printf("\tActive Slaves: []\n");
6038
6039         }
6040
6041         primary_id = rte_eth_bond_primary_get(port_id);
6042         if (primary_id < 0) {
6043                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6044                 return;
6045         } else
6046                 printf("\tPrimary: [%d]\n", primary_id);
6047
6048 }
6049
6050 cmdline_parse_token_string_t cmd_showbonding_config_show =
6051 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6052                 show, "show");
6053 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6054 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6055                 bonding, "bonding");
6056 cmdline_parse_token_string_t cmd_showbonding_config_config =
6057 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6058                 config, "config");
6059 cmdline_parse_token_num_t cmd_showbonding_config_port =
6060 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6061                 port_id, UINT16);
6062
6063 cmdline_parse_inst_t cmd_show_bonding_config = {
6064                 .f = cmd_show_bonding_config_parsed,
6065                 .help_str = "show bonding config <port_id>: "
6066                         "Show the bonding config for port_id",
6067                 .data = NULL,
6068                 .tokens = {
6069                                 (void *)&cmd_showbonding_config_show,
6070                                 (void *)&cmd_showbonding_config_bonding,
6071                                 (void *)&cmd_showbonding_config_config,
6072                                 (void *)&cmd_showbonding_config_port,
6073                                 NULL
6074                 }
6075 };
6076
6077 /* *** SET BONDING PRIMARY *** */
6078 struct cmd_set_bonding_primary_result {
6079         cmdline_fixed_string_t set;
6080         cmdline_fixed_string_t bonding;
6081         cmdline_fixed_string_t primary;
6082         portid_t slave_id;
6083         portid_t port_id;
6084 };
6085
6086 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6087                 __rte_unused  struct cmdline *cl,
6088                 __rte_unused void *data)
6089 {
6090         struct cmd_set_bonding_primary_result *res = parsed_result;
6091         portid_t master_port_id = res->port_id;
6092         portid_t slave_port_id = res->slave_id;
6093
6094         /* Set the primary slave for a bonded device. */
6095         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6096                 printf("\t Failed to set primary slave for port = %d.\n",
6097                                 master_port_id);
6098                 return;
6099         }
6100         init_port_config();
6101 }
6102
6103 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6104 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6105                 set, "set");
6106 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6107 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6108                 bonding, "bonding");
6109 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6110 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6111                 primary, "primary");
6112 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6113 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6114                 slave_id, UINT16);
6115 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6116 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6117                 port_id, UINT16);
6118
6119 cmdline_parse_inst_t cmd_set_bonding_primary = {
6120                 .f = cmd_set_bonding_primary_parsed,
6121                 .help_str = "set bonding primary <slave_id> <port_id>: "
6122                         "Set the primary slave for port_id",
6123                 .data = NULL,
6124                 .tokens = {
6125                                 (void *)&cmd_setbonding_primary_set,
6126                                 (void *)&cmd_setbonding_primary_bonding,
6127                                 (void *)&cmd_setbonding_primary_primary,
6128                                 (void *)&cmd_setbonding_primary_slave,
6129                                 (void *)&cmd_setbonding_primary_port,
6130                                 NULL
6131                 }
6132 };
6133
6134 /* *** ADD SLAVE *** */
6135 struct cmd_add_bonding_slave_result {
6136         cmdline_fixed_string_t add;
6137         cmdline_fixed_string_t bonding;
6138         cmdline_fixed_string_t slave;
6139         portid_t slave_id;
6140         portid_t port_id;
6141 };
6142
6143 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6144                 __rte_unused  struct cmdline *cl,
6145                 __rte_unused void *data)
6146 {
6147         struct cmd_add_bonding_slave_result *res = parsed_result;
6148         portid_t master_port_id = res->port_id;
6149         portid_t slave_port_id = res->slave_id;
6150
6151         /* add the slave for a bonded device. */
6152         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6153                 printf("\t Failed to add slave %d to master port = %d.\n",
6154                                 slave_port_id, master_port_id);
6155                 return;
6156         }
6157         init_port_config();
6158         set_port_slave_flag(slave_port_id);
6159 }
6160
6161 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6162 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6163                 add, "add");
6164 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6165 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6166                 bonding, "bonding");
6167 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6168 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6169                 slave, "slave");
6170 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6171 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6172                 slave_id, UINT16);
6173 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6174 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6175                 port_id, UINT16);
6176
6177 cmdline_parse_inst_t cmd_add_bonding_slave = {
6178                 .f = cmd_add_bonding_slave_parsed,
6179                 .help_str = "add bonding slave <slave_id> <port_id>: "
6180                         "Add a slave device to a bonded device",
6181                 .data = NULL,
6182                 .tokens = {
6183                                 (void *)&cmd_addbonding_slave_add,
6184                                 (void *)&cmd_addbonding_slave_bonding,
6185                                 (void *)&cmd_addbonding_slave_slave,
6186                                 (void *)&cmd_addbonding_slave_slaveid,
6187                                 (void *)&cmd_addbonding_slave_port,
6188                                 NULL
6189                 }
6190 };
6191
6192 /* *** REMOVE SLAVE *** */
6193 struct cmd_remove_bonding_slave_result {
6194         cmdline_fixed_string_t remove;
6195         cmdline_fixed_string_t bonding;
6196         cmdline_fixed_string_t slave;
6197         portid_t slave_id;
6198         portid_t port_id;
6199 };
6200
6201 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6202                 __rte_unused  struct cmdline *cl,
6203                 __rte_unused void *data)
6204 {
6205         struct cmd_remove_bonding_slave_result *res = parsed_result;
6206         portid_t master_port_id = res->port_id;
6207         portid_t slave_port_id = res->slave_id;
6208
6209         /* remove the slave from a bonded device. */
6210         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6211                 printf("\t Failed to remove slave %d from master port = %d.\n",
6212                                 slave_port_id, master_port_id);
6213                 return;
6214         }
6215         init_port_config();
6216         clear_port_slave_flag(slave_port_id);
6217 }
6218
6219 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6220                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6221                                 remove, "remove");
6222 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6223                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6224                                 bonding, "bonding");
6225 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6226                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6227                                 slave, "slave");
6228 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6229                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6230                                 slave_id, UINT16);
6231 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6232                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6233                                 port_id, UINT16);
6234
6235 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6236                 .f = cmd_remove_bonding_slave_parsed,
6237                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6238                         "Remove a slave device from a bonded device",
6239                 .data = NULL,
6240                 .tokens = {
6241                                 (void *)&cmd_removebonding_slave_remove,
6242                                 (void *)&cmd_removebonding_slave_bonding,
6243                                 (void *)&cmd_removebonding_slave_slave,
6244                                 (void *)&cmd_removebonding_slave_slaveid,
6245                                 (void *)&cmd_removebonding_slave_port,
6246                                 NULL
6247                 }
6248 };
6249
6250 /* *** CREATE BONDED DEVICE *** */
6251 struct cmd_create_bonded_device_result {
6252         cmdline_fixed_string_t create;
6253         cmdline_fixed_string_t bonded;
6254         cmdline_fixed_string_t device;
6255         uint8_t mode;
6256         uint8_t socket;
6257 };
6258
6259 static int bond_dev_num = 0;
6260
6261 static void cmd_create_bonded_device_parsed(void *parsed_result,
6262                 __rte_unused  struct cmdline *cl,
6263                 __rte_unused void *data)
6264 {
6265         struct cmd_create_bonded_device_result *res = parsed_result;
6266         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6267         int port_id;
6268         int ret;
6269
6270         if (test_done == 0) {
6271                 printf("Please stop forwarding first\n");
6272                 return;
6273         }
6274
6275         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6276                         bond_dev_num++);
6277
6278         /* Create a new bonded device. */
6279         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6280         if (port_id < 0) {
6281                 printf("\t Failed to create bonded device.\n");
6282                 return;
6283         } else {
6284                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6285                                 port_id);
6286
6287                 /* Update number of ports */
6288                 nb_ports = rte_eth_dev_count_avail();
6289                 reconfig(port_id, res->socket);
6290                 ret = rte_eth_promiscuous_enable(port_id);
6291                 if (ret != 0)
6292                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6293                                 port_id, rte_strerror(-ret));
6294
6295                 ports[port_id].need_setup = 0;
6296                 ports[port_id].port_status = RTE_PORT_STOPPED;
6297         }
6298
6299 }
6300
6301 cmdline_parse_token_string_t cmd_createbonded_device_create =
6302                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6303                                 create, "create");
6304 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6305                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6306                                 bonded, "bonded");
6307 cmdline_parse_token_string_t cmd_createbonded_device_device =
6308                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6309                                 device, "device");
6310 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6311                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6312                                 mode, UINT8);
6313 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6314                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6315                                 socket, UINT8);
6316
6317 cmdline_parse_inst_t cmd_create_bonded_device = {
6318                 .f = cmd_create_bonded_device_parsed,
6319                 .help_str = "create bonded device <mode> <socket>: "
6320                         "Create a new bonded device with specific bonding mode and socket",
6321                 .data = NULL,
6322                 .tokens = {
6323                                 (void *)&cmd_createbonded_device_create,
6324                                 (void *)&cmd_createbonded_device_bonded,
6325                                 (void *)&cmd_createbonded_device_device,
6326                                 (void *)&cmd_createbonded_device_mode,
6327                                 (void *)&cmd_createbonded_device_socket,
6328                                 NULL
6329                 }
6330 };
6331
6332 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6333 struct cmd_set_bond_mac_addr_result {
6334         cmdline_fixed_string_t set;
6335         cmdline_fixed_string_t bonding;
6336         cmdline_fixed_string_t mac_addr;
6337         uint16_t port_num;
6338         struct rte_ether_addr address;
6339 };
6340
6341 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6342                 __rte_unused  struct cmdline *cl,
6343                 __rte_unused void *data)
6344 {
6345         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6346         int ret;
6347
6348         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6349                 return;
6350
6351         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6352
6353         /* check the return value and print it if is < 0 */
6354         if (ret < 0)
6355                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6356 }
6357
6358 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6359                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6360 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6361                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6362                                 "bonding");
6363 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6364                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6365                                 "mac_addr");
6366 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6367                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6368                                 port_num, UINT16);
6369 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6370                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6371
6372 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6373                 .f = cmd_set_bond_mac_addr_parsed,
6374                 .data = (void *) 0,
6375                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6376                 .tokens = {
6377                                 (void *)&cmd_set_bond_mac_addr_set,
6378                                 (void *)&cmd_set_bond_mac_addr_bonding,
6379                                 (void *)&cmd_set_bond_mac_addr_mac,
6380                                 (void *)&cmd_set_bond_mac_addr_portnum,
6381                                 (void *)&cmd_set_bond_mac_addr_addr,
6382                                 NULL
6383                 }
6384 };
6385
6386
6387 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6388 struct cmd_set_bond_mon_period_result {
6389         cmdline_fixed_string_t set;
6390         cmdline_fixed_string_t bonding;
6391         cmdline_fixed_string_t mon_period;
6392         uint16_t port_num;
6393         uint32_t period_ms;
6394 };
6395
6396 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6397                 __rte_unused  struct cmdline *cl,
6398                 __rte_unused void *data)
6399 {
6400         struct cmd_set_bond_mon_period_result *res = parsed_result;
6401         int ret;
6402
6403         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6404
6405         /* check the return value and print it if is < 0 */
6406         if (ret < 0)
6407                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6408 }
6409
6410 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6411                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6412                                 set, "set");
6413 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6414                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6415                                 bonding, "bonding");
6416 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6417                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6418                                 mon_period,     "mon_period");
6419 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6420                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6421                                 port_num, UINT16);
6422 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6423                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6424                                 period_ms, UINT32);
6425
6426 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6427                 .f = cmd_set_bond_mon_period_parsed,
6428                 .data = (void *) 0,
6429                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6430                 .tokens = {
6431                                 (void *)&cmd_set_bond_mon_period_set,
6432                                 (void *)&cmd_set_bond_mon_period_bonding,
6433                                 (void *)&cmd_set_bond_mon_period_mon_period,
6434                                 (void *)&cmd_set_bond_mon_period_portnum,
6435                                 (void *)&cmd_set_bond_mon_period_period_ms,
6436                                 NULL
6437                 }
6438 };
6439
6440
6441
6442 struct cmd_set_bonding_agg_mode_policy_result {
6443         cmdline_fixed_string_t set;
6444         cmdline_fixed_string_t bonding;
6445         cmdline_fixed_string_t agg_mode;
6446         uint16_t port_num;
6447         cmdline_fixed_string_t policy;
6448 };
6449
6450
6451 static void
6452 cmd_set_bonding_agg_mode(void *parsed_result,
6453                 __rte_unused struct cmdline *cl,
6454                 __rte_unused void *data)
6455 {
6456         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6457         uint8_t policy = AGG_BANDWIDTH;
6458
6459         if (!strcmp(res->policy, "bandwidth"))
6460                 policy = AGG_BANDWIDTH;
6461         else if (!strcmp(res->policy, "stable"))
6462                 policy = AGG_STABLE;
6463         else if (!strcmp(res->policy, "count"))
6464                 policy = AGG_COUNT;
6465
6466         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6467 }
6468
6469
6470 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6471         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6472                                 set, "set");
6473 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6474         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6475                                 bonding, "bonding");
6476
6477 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6479                                 agg_mode, "agg_mode");
6480
6481 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6482         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6483                                 port_num, UINT16);
6484
6485 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6486         TOKEN_STRING_INITIALIZER(
6487                         struct cmd_set_bonding_balance_xmit_policy_result,
6488                 policy, "stable#bandwidth#count");
6489
6490 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6491         .f = cmd_set_bonding_agg_mode,
6492         .data = (void *) 0,
6493         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6494         .tokens = {
6495                         (void *)&cmd_set_bonding_agg_mode_set,
6496                         (void *)&cmd_set_bonding_agg_mode_bonding,
6497                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6498                         (void *)&cmd_set_bonding_agg_mode_portnum,
6499                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6500                         NULL
6501                 }
6502 };
6503
6504
6505 #endif /* RTE_NET_BOND */
6506
6507 /* *** SET FORWARDING MODE *** */
6508 struct cmd_set_fwd_mode_result {
6509         cmdline_fixed_string_t set;
6510         cmdline_fixed_string_t fwd;
6511         cmdline_fixed_string_t mode;
6512 };
6513
6514 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6515                                     __rte_unused struct cmdline *cl,
6516                                     __rte_unused void *data)
6517 {
6518         struct cmd_set_fwd_mode_result *res = parsed_result;
6519
6520         retry_enabled = 0;
6521         set_pkt_forwarding_mode(res->mode);
6522 }
6523
6524 cmdline_parse_token_string_t cmd_setfwd_set =
6525         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6526 cmdline_parse_token_string_t cmd_setfwd_fwd =
6527         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6528 cmdline_parse_token_string_t cmd_setfwd_mode =
6529         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6530                 "" /* defined at init */);
6531
6532 cmdline_parse_inst_t cmd_set_fwd_mode = {
6533         .f = cmd_set_fwd_mode_parsed,
6534         .data = NULL,
6535         .help_str = NULL, /* defined at init */
6536         .tokens = {
6537                 (void *)&cmd_setfwd_set,
6538                 (void *)&cmd_setfwd_fwd,
6539                 (void *)&cmd_setfwd_mode,
6540                 NULL,
6541         },
6542 };
6543
6544 static void cmd_set_fwd_mode_init(void)
6545 {
6546         char *modes, *c;
6547         static char token[128];
6548         static char help[256];
6549         cmdline_parse_token_string_t *token_struct;
6550
6551         modes = list_pkt_forwarding_modes();
6552         snprintf(help, sizeof(help), "set fwd %s: "
6553                 "Set packet forwarding mode", modes);
6554         cmd_set_fwd_mode.help_str = help;
6555
6556         /* string token separator is # */
6557         for (c = token; *modes != '\0'; modes++)
6558                 if (*modes == '|')
6559                         *c++ = '#';
6560                 else
6561                         *c++ = *modes;
6562         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6563         token_struct->string_data.str = token;
6564 }
6565
6566 /* *** SET RETRY FORWARDING MODE *** */
6567 struct cmd_set_fwd_retry_mode_result {
6568         cmdline_fixed_string_t set;
6569         cmdline_fixed_string_t fwd;
6570         cmdline_fixed_string_t mode;
6571         cmdline_fixed_string_t retry;
6572 };
6573
6574 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6575                             __rte_unused struct cmdline *cl,
6576                             __rte_unused void *data)
6577 {
6578         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6579
6580         retry_enabled = 1;
6581         set_pkt_forwarding_mode(res->mode);
6582 }
6583
6584 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6585         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6586                         set, "set");
6587 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6588         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6589                         fwd, "fwd");
6590 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6591         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6592                         mode,
6593                 "" /* defined at init */);
6594 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6596                         retry, "retry");
6597
6598 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6599         .f = cmd_set_fwd_retry_mode_parsed,
6600         .data = NULL,
6601         .help_str = NULL, /* defined at init */
6602         .tokens = {
6603                 (void *)&cmd_setfwd_retry_set,
6604                 (void *)&cmd_setfwd_retry_fwd,
6605                 (void *)&cmd_setfwd_retry_mode,
6606                 (void *)&cmd_setfwd_retry_retry,
6607                 NULL,
6608         },
6609 };
6610
6611 static void cmd_set_fwd_retry_mode_init(void)
6612 {
6613         char *modes, *c;
6614         static char token[128];
6615         static char help[256];
6616         cmdline_parse_token_string_t *token_struct;
6617
6618         modes = list_pkt_forwarding_retry_modes();
6619         snprintf(help, sizeof(help), "set fwd %s retry: "
6620                 "Set packet forwarding mode with retry", modes);
6621         cmd_set_fwd_retry_mode.help_str = help;
6622
6623         /* string token separator is # */
6624         for (c = token; *modes != '\0'; modes++)
6625                 if (*modes == '|')
6626                         *c++ = '#';
6627                 else
6628                         *c++ = *modes;
6629         token_struct = (cmdline_parse_token_string_t *)
6630                 cmd_set_fwd_retry_mode.tokens[2];
6631         token_struct->string_data.str = token;
6632 }
6633
6634 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6635 struct cmd_set_burst_tx_retry_result {
6636         cmdline_fixed_string_t set;
6637         cmdline_fixed_string_t burst;
6638         cmdline_fixed_string_t tx;
6639         cmdline_fixed_string_t delay;
6640         uint32_t time;
6641         cmdline_fixed_string_t retry;
6642         uint32_t retry_num;
6643 };
6644
6645 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6646                                         __rte_unused struct cmdline *cl,
6647                                         __rte_unused void *data)
6648 {
6649         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6650
6651         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6652                 && !strcmp(res->tx, "tx")) {
6653                 if (!strcmp(res->delay, "delay"))
6654                         burst_tx_delay_time = res->time;
6655                 if (!strcmp(res->retry, "retry"))
6656                         burst_tx_retry_num = res->retry_num;
6657         }
6658
6659 }
6660
6661 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6662         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6663 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6664         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6665                                  "burst");
6666 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6667         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6668 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6670 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6671         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6674 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6675         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6676
6677 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6678         .f = cmd_set_burst_tx_retry_parsed,
6679         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6680         .tokens = {
6681                 (void *)&cmd_set_burst_tx_retry_set,
6682                 (void *)&cmd_set_burst_tx_retry_burst,
6683                 (void *)&cmd_set_burst_tx_retry_tx,
6684                 (void *)&cmd_set_burst_tx_retry_delay,
6685                 (void *)&cmd_set_burst_tx_retry_time,
6686                 (void *)&cmd_set_burst_tx_retry_retry,
6687                 (void *)&cmd_set_burst_tx_retry_retry_num,
6688                 NULL,
6689         },
6690 };
6691
6692 /* *** SET PROMISC MODE *** */
6693 struct cmd_set_promisc_mode_result {
6694         cmdline_fixed_string_t set;
6695         cmdline_fixed_string_t promisc;
6696         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6697         uint16_t port_num;               /* valid if "allports" argument == 0 */
6698         cmdline_fixed_string_t mode;
6699 };
6700
6701 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6702                                         __rte_unused struct cmdline *cl,
6703                                         void *allports)
6704 {
6705         struct cmd_set_promisc_mode_result *res = parsed_result;
6706         int enable;
6707         portid_t i;
6708
6709         if (!strcmp(res->mode, "on"))
6710                 enable = 1;
6711         else
6712                 enable = 0;
6713
6714         /* all ports */
6715         if (allports) {
6716                 RTE_ETH_FOREACH_DEV(i)
6717                         eth_set_promisc_mode(i, enable);
6718         } else {
6719                 eth_set_promisc_mode(res->port_num, enable);
6720         }
6721 }
6722
6723 cmdline_parse_token_string_t cmd_setpromisc_set =
6724         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6725 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6726         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6727                                  "promisc");
6728 cmdline_parse_token_string_t cmd_setpromisc_portall =
6729         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6730                                  "all");
6731 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6732         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6733                               UINT16);
6734 cmdline_parse_token_string_t cmd_setpromisc_mode =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6736                                  "on#off");
6737
6738 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6739         .f = cmd_set_promisc_mode_parsed,
6740         .data = (void *)1,
6741         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6742         .tokens = {
6743                 (void *)&cmd_setpromisc_set,
6744                 (void *)&cmd_setpromisc_promisc,
6745                 (void *)&cmd_setpromisc_portall,
6746                 (void *)&cmd_setpromisc_mode,
6747                 NULL,
6748         },
6749 };
6750
6751 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6752         .f = cmd_set_promisc_mode_parsed,
6753         .data = (void *)0,
6754         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6755         .tokens = {
6756                 (void *)&cmd_setpromisc_set,
6757                 (void *)&cmd_setpromisc_promisc,
6758                 (void *)&cmd_setpromisc_portnum,
6759                 (void *)&cmd_setpromisc_mode,
6760                 NULL,
6761         },
6762 };
6763
6764 /* *** SET ALLMULTI MODE *** */
6765 struct cmd_set_allmulti_mode_result {
6766         cmdline_fixed_string_t set;
6767         cmdline_fixed_string_t allmulti;
6768         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6769         uint16_t port_num;               /* valid if "allports" argument == 0 */
6770         cmdline_fixed_string_t mode;
6771 };
6772
6773 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6774                                         __rte_unused struct cmdline *cl,
6775                                         void *allports)
6776 {
6777         struct cmd_set_allmulti_mode_result *res = parsed_result;
6778         int enable;
6779         portid_t i;
6780
6781         if (!strcmp(res->mode, "on"))
6782                 enable = 1;
6783         else
6784                 enable = 0;
6785
6786         /* all ports */
6787         if (allports) {
6788                 RTE_ETH_FOREACH_DEV(i) {
6789                         eth_set_allmulticast_mode(i, enable);
6790                 }
6791         }
6792         else {
6793                 eth_set_allmulticast_mode(res->port_num, enable);
6794         }
6795 }
6796
6797 cmdline_parse_token_string_t cmd_setallmulti_set =
6798         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6799 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6800         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6801                                  "allmulti");
6802 cmdline_parse_token_string_t cmd_setallmulti_portall =
6803         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6804                                  "all");
6805 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6806         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6807                               UINT16);
6808 cmdline_parse_token_string_t cmd_setallmulti_mode =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6810                                  "on#off");
6811
6812 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6813         .f = cmd_set_allmulti_mode_parsed,
6814         .data = (void *)1,
6815         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6816         .tokens = {
6817                 (void *)&cmd_setallmulti_set,
6818                 (void *)&cmd_setallmulti_allmulti,
6819                 (void *)&cmd_setallmulti_portall,
6820                 (void *)&cmd_setallmulti_mode,
6821                 NULL,
6822         },
6823 };
6824
6825 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6826         .f = cmd_set_allmulti_mode_parsed,
6827         .data = (void *)0,
6828         .help_str = "set allmulti <port_id> on|off: "
6829                 "Set allmulti mode on port_id",
6830         .tokens = {
6831                 (void *)&cmd_setallmulti_set,
6832                 (void *)&cmd_setallmulti_allmulti,
6833                 (void *)&cmd_setallmulti_portnum,
6834                 (void *)&cmd_setallmulti_mode,
6835                 NULL,
6836         },
6837 };
6838
6839 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6840 struct cmd_link_flow_ctrl_set_result {
6841         cmdline_fixed_string_t set;
6842         cmdline_fixed_string_t flow_ctrl;
6843         cmdline_fixed_string_t rx;
6844         cmdline_fixed_string_t rx_lfc_mode;
6845         cmdline_fixed_string_t tx;
6846         cmdline_fixed_string_t tx_lfc_mode;
6847         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6848         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6849         cmdline_fixed_string_t autoneg_str;
6850         cmdline_fixed_string_t autoneg;
6851         cmdline_fixed_string_t hw_str;
6852         uint32_t high_water;
6853         cmdline_fixed_string_t lw_str;
6854         uint32_t low_water;
6855         cmdline_fixed_string_t pt_str;
6856         uint16_t pause_time;
6857         cmdline_fixed_string_t xon_str;
6858         uint16_t send_xon;
6859         portid_t port_id;
6860 };
6861
6862 cmdline_parse_token_string_t cmd_lfc_set_set =
6863         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6864                                 set, "set");
6865 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6866         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6867                                 flow_ctrl, "flow_ctrl");
6868 cmdline_parse_token_string_t cmd_lfc_set_rx =
6869         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6870                                 rx, "rx");
6871 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 rx_lfc_mode, "on#off");
6874 cmdline_parse_token_string_t cmd_lfc_set_tx =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 tx, "tx");
6877 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 tx_lfc_mode, "on#off");
6880 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 hw_str, "high_water");
6883 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6884         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 high_water, UINT32);
6886 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 lw_str, "low_water");
6889 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6890         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 low_water, UINT32);
6892 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 pt_str, "pause_time");
6895 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6896         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 pause_time, UINT16);
6898 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 xon_str, "send_xon");
6901 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 send_xon, UINT16);
6904 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6907 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 mac_ctrl_frame_fwd_mode, "on#off");
6910 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 autoneg_str, "autoneg");
6913 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 autoneg, "on#off");
6916 cmdline_parse_token_num_t cmd_lfc_set_portid =
6917         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 port_id, UINT16);
6919
6920 /* forward declaration */
6921 static void
6922 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6923                               void *data);
6924
6925 cmdline_parse_inst_t cmd_link_flow_control_set = {
6926         .f = cmd_link_flow_ctrl_set_parsed,
6927         .data = NULL,
6928         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6929                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6930                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6931         .tokens = {
6932                 (void *)&cmd_lfc_set_set,
6933                 (void *)&cmd_lfc_set_flow_ctrl,
6934                 (void *)&cmd_lfc_set_rx,
6935                 (void *)&cmd_lfc_set_rx_mode,
6936                 (void *)&cmd_lfc_set_tx,
6937                 (void *)&cmd_lfc_set_tx_mode,
6938                 (void *)&cmd_lfc_set_high_water,
6939                 (void *)&cmd_lfc_set_low_water,
6940                 (void *)&cmd_lfc_set_pause_time,
6941                 (void *)&cmd_lfc_set_send_xon,
6942                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6943                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6944                 (void *)&cmd_lfc_set_autoneg_str,
6945                 (void *)&cmd_lfc_set_autoneg,
6946                 (void *)&cmd_lfc_set_portid,
6947                 NULL,
6948         },
6949 };
6950
6951 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6952         .f = cmd_link_flow_ctrl_set_parsed,
6953         .data = (void *)&cmd_link_flow_control_set_rx,
6954         .help_str = "set flow_ctrl rx on|off <port_id>: "
6955                 "Change rx flow control parameter",
6956         .tokens = {
6957                 (void *)&cmd_lfc_set_set,
6958                 (void *)&cmd_lfc_set_flow_ctrl,
6959                 (void *)&cmd_lfc_set_rx,
6960                 (void *)&cmd_lfc_set_rx_mode,
6961                 (void *)&cmd_lfc_set_portid,
6962                 NULL,
6963         },
6964 };
6965
6966 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6967         .f = cmd_link_flow_ctrl_set_parsed,
6968         .data = (void *)&cmd_link_flow_control_set_tx,
6969         .help_str = "set flow_ctrl tx on|off <port_id>: "
6970                 "Change tx flow control parameter",
6971         .tokens = {
6972                 (void *)&cmd_lfc_set_set,
6973                 (void *)&cmd_lfc_set_flow_ctrl,
6974                 (void *)&cmd_lfc_set_tx,
6975                 (void *)&cmd_lfc_set_tx_mode,
6976                 (void *)&cmd_lfc_set_portid,
6977                 NULL,
6978         },
6979 };
6980
6981 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6982         .f = cmd_link_flow_ctrl_set_parsed,
6983         .data = (void *)&cmd_link_flow_control_set_hw,
6984         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6985                 "Change high water flow control parameter",
6986         .tokens = {
6987                 (void *)&cmd_lfc_set_set,
6988                 (void *)&cmd_lfc_set_flow_ctrl,
6989                 (void *)&cmd_lfc_set_high_water_str,
6990                 (void *)&cmd_lfc_set_high_water,
6991                 (void *)&cmd_lfc_set_portid,
6992                 NULL,
6993         },
6994 };
6995
6996 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6997         .f = cmd_link_flow_ctrl_set_parsed,
6998         .data = (void *)&cmd_link_flow_control_set_lw,
6999         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7000                 "Change low water flow control parameter",
7001         .tokens = {
7002                 (void *)&cmd_lfc_set_set,
7003                 (void *)&cmd_lfc_set_flow_ctrl,
7004                 (void *)&cmd_lfc_set_low_water_str,
7005                 (void *)&cmd_lfc_set_low_water,
7006                 (void *)&cmd_lfc_set_portid,
7007                 NULL,
7008         },
7009 };
7010
7011 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7012         .f = cmd_link_flow_ctrl_set_parsed,
7013         .data = (void *)&cmd_link_flow_control_set_pt,
7014         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7015                 "Change pause time flow control parameter",
7016         .tokens = {
7017                 (void *)&cmd_lfc_set_set,
7018                 (void *)&cmd_lfc_set_flow_ctrl,
7019                 (void *)&cmd_lfc_set_pause_time_str,
7020                 (void *)&cmd_lfc_set_pause_time,
7021                 (void *)&cmd_lfc_set_portid,
7022                 NULL,
7023         },
7024 };
7025
7026 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7027         .f = cmd_link_flow_ctrl_set_parsed,
7028         .data = (void *)&cmd_link_flow_control_set_xon,
7029         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7030                 "Change send_xon flow control parameter",
7031         .tokens = {
7032                 (void *)&cmd_lfc_set_set,
7033                 (void *)&cmd_lfc_set_flow_ctrl,
7034                 (void *)&cmd_lfc_set_send_xon_str,
7035                 (void *)&cmd_lfc_set_send_xon,
7036                 (void *)&cmd_lfc_set_portid,
7037                 NULL,
7038         },
7039 };
7040
7041 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7042         .f = cmd_link_flow_ctrl_set_parsed,
7043         .data = (void *)&cmd_link_flow_control_set_macfwd,
7044         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7045                 "Change mac ctrl fwd flow control parameter",
7046         .tokens = {
7047                 (void *)&cmd_lfc_set_set,
7048                 (void *)&cmd_lfc_set_flow_ctrl,
7049                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7050                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7051                 (void *)&cmd_lfc_set_portid,
7052                 NULL,
7053         },
7054 };
7055
7056 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7057         .f = cmd_link_flow_ctrl_set_parsed,
7058         .data = (void *)&cmd_link_flow_control_set_autoneg,
7059         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7060                 "Change autoneg flow control parameter",
7061         .tokens = {
7062                 (void *)&cmd_lfc_set_set,
7063                 (void *)&cmd_lfc_set_flow_ctrl,
7064                 (void *)&cmd_lfc_set_autoneg_str,
7065                 (void *)&cmd_lfc_set_autoneg,
7066                 (void *)&cmd_lfc_set_portid,
7067                 NULL,
7068         },
7069 };
7070
7071 static void
7072 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7073                               __rte_unused struct cmdline *cl,
7074                               void *data)
7075 {
7076         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7077         cmdline_parse_inst_t *cmd = data;
7078         struct rte_eth_fc_conf fc_conf;
7079         int rx_fc_en = 0;
7080         int tx_fc_en = 0;
7081         int ret;
7082
7083         /*
7084          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7085          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7086          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7087          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7088          */
7089         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7090                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7091         };
7092
7093         /* Partial command line, retrieve current configuration */
7094         if (cmd) {
7095                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7096                 if (ret != 0) {
7097                         printf("cannot get current flow ctrl parameters, return"
7098                                "code = %d\n", ret);
7099                         return;
7100                 }
7101
7102                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7103                     (fc_conf.mode == RTE_FC_FULL))
7104                         rx_fc_en = 1;
7105                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7106                     (fc_conf.mode == RTE_FC_FULL))
7107                         tx_fc_en = 1;
7108         }
7109
7110         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7111                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7112
7113         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7114                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7115
7116         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7117
7118         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7119                 fc_conf.high_water = res->high_water;
7120
7121         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7122                 fc_conf.low_water = res->low_water;
7123
7124         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7125                 fc_conf.pause_time = res->pause_time;
7126
7127         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7128                 fc_conf.send_xon = res->send_xon;
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7131                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7132                         fc_conf.mac_ctrl_frame_fwd = 1;
7133                 else
7134                         fc_conf.mac_ctrl_frame_fwd = 0;
7135         }
7136
7137         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7138                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7139
7140         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7141         if (ret != 0)
7142                 printf("bad flow contrl parameter, return code = %d \n", ret);
7143 }
7144
7145 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7146 struct cmd_priority_flow_ctrl_set_result {
7147         cmdline_fixed_string_t set;
7148         cmdline_fixed_string_t pfc_ctrl;
7149         cmdline_fixed_string_t rx;
7150         cmdline_fixed_string_t rx_pfc_mode;
7151         cmdline_fixed_string_t tx;
7152         cmdline_fixed_string_t tx_pfc_mode;
7153         uint32_t high_water;
7154         uint32_t low_water;
7155         uint16_t pause_time;
7156         uint8_t  priority;
7157         portid_t port_id;
7158 };
7159
7160 static void
7161 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7162                        __rte_unused struct cmdline *cl,
7163                        __rte_unused void *data)
7164 {
7165         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7166         struct rte_eth_pfc_conf pfc_conf;
7167         int rx_fc_enable, tx_fc_enable;
7168         int ret;
7169
7170         /*
7171          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7172          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7173          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7174          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7175          */
7176         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7177                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7178         };
7179
7180         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7181         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7182         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7183         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7184         pfc_conf.fc.high_water = res->high_water;
7185         pfc_conf.fc.low_water  = res->low_water;
7186         pfc_conf.fc.pause_time = res->pause_time;
7187         pfc_conf.priority      = res->priority;
7188
7189         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7190         if (ret != 0)
7191                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7192 }
7193
7194 cmdline_parse_token_string_t cmd_pfc_set_set =
7195         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7196                                 set, "set");
7197 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7198         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7199                                 pfc_ctrl, "pfc_ctrl");
7200 cmdline_parse_token_string_t cmd_pfc_set_rx =
7201         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7202                                 rx, "rx");
7203 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205                                 rx_pfc_mode, "on#off");
7206 cmdline_parse_token_string_t cmd_pfc_set_tx =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 tx, "tx");
7209 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 tx_pfc_mode, "on#off");
7212 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7213         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 high_water, UINT32);
7215 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7216         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 low_water, UINT32);
7218 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7219         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 pause_time, UINT16);
7221 cmdline_parse_token_num_t cmd_pfc_set_priority =
7222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 priority, UINT8);
7224 cmdline_parse_token_num_t cmd_pfc_set_portid =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 port_id, UINT16);
7227
7228 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7229         .f = cmd_priority_flow_ctrl_set_parsed,
7230         .data = NULL,
7231         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7232                 "<pause_time> <priority> <port_id>: "
7233                 "Configure the Ethernet priority flow control",
7234         .tokens = {
7235                 (void *)&cmd_pfc_set_set,
7236                 (void *)&cmd_pfc_set_flow_ctrl,
7237                 (void *)&cmd_pfc_set_rx,
7238                 (void *)&cmd_pfc_set_rx_mode,
7239                 (void *)&cmd_pfc_set_tx,
7240                 (void *)&cmd_pfc_set_tx_mode,
7241                 (void *)&cmd_pfc_set_high_water,
7242                 (void *)&cmd_pfc_set_low_water,
7243                 (void *)&cmd_pfc_set_pause_time,
7244                 (void *)&cmd_pfc_set_priority,
7245                 (void *)&cmd_pfc_set_portid,
7246                 NULL,
7247         },
7248 };
7249
7250 /* *** RESET CONFIGURATION *** */
7251 struct cmd_reset_result {
7252         cmdline_fixed_string_t reset;
7253         cmdline_fixed_string_t def;
7254 };
7255
7256 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7257                              struct cmdline *cl,
7258                              __rte_unused void *data)
7259 {
7260         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7261         set_def_fwd_config();
7262 }
7263
7264 cmdline_parse_token_string_t cmd_reset_set =
7265         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7266 cmdline_parse_token_string_t cmd_reset_def =
7267         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7268                                  "default");
7269
7270 cmdline_parse_inst_t cmd_reset = {
7271         .f = cmd_reset_parsed,
7272         .data = NULL,
7273         .help_str = "set default: Reset default forwarding configuration",
7274         .tokens = {
7275                 (void *)&cmd_reset_set,
7276                 (void *)&cmd_reset_def,
7277                 NULL,
7278         },
7279 };
7280
7281 /* *** START FORWARDING *** */
7282 struct cmd_start_result {
7283         cmdline_fixed_string_t start;
7284 };
7285
7286 cmdline_parse_token_string_t cmd_start_start =
7287         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7288
7289 static void cmd_start_parsed(__rte_unused void *parsed_result,
7290                              __rte_unused struct cmdline *cl,
7291                              __rte_unused void *data)
7292 {
7293         start_packet_forwarding(0);
7294 }
7295
7296 cmdline_parse_inst_t cmd_start = {
7297         .f = cmd_start_parsed,
7298         .data = NULL,
7299         .help_str = "start: Start packet forwarding",
7300         .tokens = {
7301                 (void *)&cmd_start_start,
7302                 NULL,
7303         },
7304 };
7305
7306 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7307 struct cmd_start_tx_first_result {
7308         cmdline_fixed_string_t start;
7309         cmdline_fixed_string_t tx_first;
7310 };
7311
7312 static void
7313 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7314                           __rte_unused struct cmdline *cl,
7315                           __rte_unused void *data)
7316 {
7317         start_packet_forwarding(1);
7318 }
7319
7320 cmdline_parse_token_string_t cmd_start_tx_first_start =
7321         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7322                                  "start");
7323 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7324         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7325                                  tx_first, "tx_first");
7326
7327 cmdline_parse_inst_t cmd_start_tx_first = {
7328         .f = cmd_start_tx_first_parsed,
7329         .data = NULL,
7330         .help_str = "start tx_first: Start packet forwarding, "
7331                 "after sending 1 burst of packets",
7332         .tokens = {
7333                 (void *)&cmd_start_tx_first_start,
7334                 (void *)&cmd_start_tx_first_tx_first,
7335                 NULL,
7336         },
7337 };
7338
7339 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7340 struct cmd_start_tx_first_n_result {
7341         cmdline_fixed_string_t start;
7342         cmdline_fixed_string_t tx_first;
7343         uint32_t tx_num;
7344 };
7345
7346 static void
7347 cmd_start_tx_first_n_parsed(void *parsed_result,
7348                           __rte_unused struct cmdline *cl,
7349                           __rte_unused void *data)
7350 {
7351         struct cmd_start_tx_first_n_result *res = parsed_result;
7352
7353         start_packet_forwarding(res->tx_num);
7354 }
7355
7356 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7357         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7358                         start, "start");
7359 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7360         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7361                         tx_first, "tx_first");
7362 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7363         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7364                         tx_num, UINT32);
7365
7366 cmdline_parse_inst_t cmd_start_tx_first_n = {
7367         .f = cmd_start_tx_first_n_parsed,
7368         .data = NULL,
7369         .help_str = "start tx_first <num>: "
7370                 "packet forwarding, after sending <num> bursts of packets",
7371         .tokens = {
7372                 (void *)&cmd_start_tx_first_n_start,
7373                 (void *)&cmd_start_tx_first_n_tx_first,
7374                 (void *)&cmd_start_tx_first_n_tx_num,
7375                 NULL,
7376         },
7377 };
7378
7379 /* *** SET LINK UP *** */
7380 struct cmd_set_link_up_result {
7381         cmdline_fixed_string_t set;
7382         cmdline_fixed_string_t link_up;
7383         cmdline_fixed_string_t port;
7384         portid_t port_id;
7385 };
7386
7387 cmdline_parse_token_string_t cmd_set_link_up_set =
7388         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7389 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7390         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7391                                 "link-up");
7392 cmdline_parse_token_string_t cmd_set_link_up_port =
7393         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7394 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7395         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7396
7397 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7398                              __rte_unused struct cmdline *cl,
7399                              __rte_unused void *data)
7400 {
7401         struct cmd_set_link_up_result *res = parsed_result;
7402         dev_set_link_up(res->port_id);
7403 }
7404
7405 cmdline_parse_inst_t cmd_set_link_up = {
7406         .f = cmd_set_link_up_parsed,
7407         .data = NULL,
7408         .help_str = "set link-up port <port id>",
7409         .tokens = {
7410                 (void *)&cmd_set_link_up_set,
7411                 (void *)&cmd_set_link_up_link_up,
7412                 (void *)&cmd_set_link_up_port,
7413                 (void *)&cmd_set_link_up_port_id,
7414                 NULL,
7415         },
7416 };
7417
7418 /* *** SET LINK DOWN *** */
7419 struct cmd_set_link_down_result {
7420         cmdline_fixed_string_t set;
7421         cmdline_fixed_string_t link_down;
7422         cmdline_fixed_string_t port;
7423         portid_t port_id;
7424 };
7425
7426 cmdline_parse_token_string_t cmd_set_link_down_set =
7427         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7428 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7429         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7430                                 "link-down");
7431 cmdline_parse_token_string_t cmd_set_link_down_port =
7432         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7433 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7434         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7435
7436 static void cmd_set_link_down_parsed(
7437                                 __rte_unused void *parsed_result,
7438                                 __rte_unused struct cmdline *cl,
7439                                 __rte_unused void *data)
7440 {
7441         struct cmd_set_link_down_result *res = parsed_result;
7442         dev_set_link_down(res->port_id);
7443 }
7444
7445 cmdline_parse_inst_t cmd_set_link_down = {
7446         .f = cmd_set_link_down_parsed,
7447         .data = NULL,
7448         .help_str = "set link-down port <port id>",
7449         .tokens = {
7450                 (void *)&cmd_set_link_down_set,
7451                 (void *)&cmd_set_link_down_link_down,
7452                 (void *)&cmd_set_link_down_port,
7453                 (void *)&cmd_set_link_down_port_id,
7454                 NULL,
7455         },
7456 };
7457
7458 /* *** SHOW CFG *** */
7459 struct cmd_showcfg_result {
7460         cmdline_fixed_string_t show;
7461         cmdline_fixed_string_t cfg;
7462         cmdline_fixed_string_t what;
7463 };
7464
7465 static void cmd_showcfg_parsed(void *parsed_result,
7466                                __rte_unused struct cmdline *cl,
7467                                __rte_unused void *data)
7468 {
7469         struct cmd_showcfg_result *res = parsed_result;
7470         if (!strcmp(res->what, "rxtx"))
7471                 rxtx_config_display();
7472         else if (!strcmp(res->what, "cores"))
7473                 fwd_lcores_config_display();
7474         else if (!strcmp(res->what, "fwd"))
7475                 pkt_fwd_config_display(&cur_fwd_config);
7476         else if (!strcmp(res->what, "rxoffs"))
7477                 show_rx_pkt_offsets();
7478         else if (!strcmp(res->what, "rxpkts"))
7479                 show_rx_pkt_segments();
7480         else if (!strcmp(res->what, "txpkts"))
7481                 show_tx_pkt_segments();
7482         else if (!strcmp(res->what, "txtimes"))
7483                 show_tx_pkt_times();
7484 }
7485
7486 cmdline_parse_token_string_t cmd_showcfg_show =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7488 cmdline_parse_token_string_t cmd_showcfg_port =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7490 cmdline_parse_token_string_t cmd_showcfg_what =
7491         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7492                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7493
7494 cmdline_parse_inst_t cmd_showcfg = {
7495         .f = cmd_showcfg_parsed,
7496         .data = NULL,
7497         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7498         .tokens = {
7499                 (void *)&cmd_showcfg_show,
7500                 (void *)&cmd_showcfg_port,
7501                 (void *)&cmd_showcfg_what,
7502                 NULL,
7503         },
7504 };
7505
7506 /* *** SHOW ALL PORT INFO *** */
7507 struct cmd_showportall_result {
7508         cmdline_fixed_string_t show;
7509         cmdline_fixed_string_t port;
7510         cmdline_fixed_string_t what;
7511         cmdline_fixed_string_t all;
7512 };
7513
7514 static void cmd_showportall_parsed(void *parsed_result,
7515                                 __rte_unused struct cmdline *cl,
7516                                 __rte_unused void *data)
7517 {
7518         portid_t i;
7519
7520         struct cmd_showportall_result *res = parsed_result;
7521         if (!strcmp(res->show, "clear")) {
7522                 if (!strcmp(res->what, "stats"))
7523                         RTE_ETH_FOREACH_DEV(i)
7524                                 nic_stats_clear(i);
7525                 else if (!strcmp(res->what, "xstats"))
7526                         RTE_ETH_FOREACH_DEV(i)
7527                                 nic_xstats_clear(i);
7528         } else if (!strcmp(res->what, "info"))
7529                 RTE_ETH_FOREACH_DEV(i)
7530                         port_infos_display(i);
7531         else if (!strcmp(res->what, "summary")) {
7532                 port_summary_header_display();
7533                 RTE_ETH_FOREACH_DEV(i)
7534                         port_summary_display(i);
7535         }
7536         else if (!strcmp(res->what, "stats"))
7537                 RTE_ETH_FOREACH_DEV(i)
7538                         nic_stats_display(i);
7539         else if (!strcmp(res->what, "xstats"))
7540                 RTE_ETH_FOREACH_DEV(i)
7541                         nic_xstats_display(i);
7542 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7543         else if (!strcmp(res->what, "fdir"))
7544                 RTE_ETH_FOREACH_DEV(i)
7545                         fdir_get_infos(i);
7546 #endif
7547         else if (!strcmp(res->what, "stat_qmap"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_stats_mapping_display(i);
7550         else if (!strcmp(res->what, "dcb_tc"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         port_dcb_info_display(i);
7553         else if (!strcmp(res->what, "cap"))
7554                 RTE_ETH_FOREACH_DEV(i)
7555                         port_offload_cap_display(i);
7556 }
7557
7558 cmdline_parse_token_string_t cmd_showportall_show =
7559         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7560                                  "show#clear");
7561 cmdline_parse_token_string_t cmd_showportall_port =
7562         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7563 cmdline_parse_token_string_t cmd_showportall_what =
7564         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7565                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7566 cmdline_parse_token_string_t cmd_showportall_all =
7567         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7568 cmdline_parse_inst_t cmd_showportall = {
7569         .f = cmd_showportall_parsed,
7570         .data = NULL,
7571         .help_str = "show|clear port "
7572                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7573         .tokens = {
7574                 (void *)&cmd_showportall_show,
7575                 (void *)&cmd_showportall_port,
7576                 (void *)&cmd_showportall_what,
7577                 (void *)&cmd_showportall_all,
7578                 NULL,
7579         },
7580 };
7581
7582 /* *** SHOW PORT INFO *** */
7583 struct cmd_showport_result {
7584         cmdline_fixed_string_t show;
7585         cmdline_fixed_string_t port;
7586         cmdline_fixed_string_t what;
7587         uint16_t portnum;
7588 };
7589
7590 static void cmd_showport_parsed(void *parsed_result,
7591                                 __rte_unused struct cmdline *cl,
7592                                 __rte_unused void *data)
7593 {
7594         struct cmd_showport_result *res = parsed_result;
7595         if (!strcmp(res->show, "clear")) {
7596                 if (!strcmp(res->what, "stats"))
7597                         nic_stats_clear(res->portnum);
7598                 else if (!strcmp(res->what, "xstats"))
7599                         nic_xstats_clear(res->portnum);
7600         } else if (!strcmp(res->what, "info"))
7601                 port_infos_display(res->portnum);
7602         else if (!strcmp(res->what, "summary")) {
7603                 port_summary_header_display();
7604                 port_summary_display(res->portnum);
7605         }
7606         else if (!strcmp(res->what, "stats"))
7607                 nic_stats_display(res->portnum);
7608         else if (!strcmp(res->what, "xstats"))
7609                 nic_xstats_display(res->portnum);
7610 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7611         else if (!strcmp(res->what, "fdir"))
7612                  fdir_get_infos(res->portnum);
7613 #endif
7614         else if (!strcmp(res->what, "stat_qmap"))
7615                 nic_stats_mapping_display(res->portnum);
7616         else if (!strcmp(res->what, "dcb_tc"))
7617                 port_dcb_info_display(res->portnum);
7618         else if (!strcmp(res->what, "cap"))
7619                 port_offload_cap_display(res->portnum);
7620 }
7621
7622 cmdline_parse_token_string_t cmd_showport_show =
7623         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7624                                  "show#clear");
7625 cmdline_parse_token_string_t cmd_showport_port =
7626         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7627 cmdline_parse_token_string_t cmd_showport_what =
7628         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7629                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7630 cmdline_parse_token_num_t cmd_showport_portnum =
7631         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7632
7633 cmdline_parse_inst_t cmd_showport = {
7634         .f = cmd_showport_parsed,
7635         .data = NULL,
7636         .help_str = "show|clear port "
7637                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7638                 "<port_id>",
7639         .tokens = {
7640                 (void *)&cmd_showport_show,
7641                 (void *)&cmd_showport_port,
7642                 (void *)&cmd_showport_what,
7643                 (void *)&cmd_showport_portnum,
7644                 NULL,
7645         },
7646 };
7647
7648 /* *** SHOW DEVICE INFO *** */
7649 struct cmd_showdevice_result {
7650         cmdline_fixed_string_t show;
7651         cmdline_fixed_string_t device;
7652         cmdline_fixed_string_t what;
7653         cmdline_fixed_string_t identifier;
7654 };
7655
7656 static void cmd_showdevice_parsed(void *parsed_result,
7657                                 __rte_unused struct cmdline *cl,
7658                                 __rte_unused void *data)
7659 {
7660         struct cmd_showdevice_result *res = parsed_result;
7661         if (!strcmp(res->what, "info")) {
7662                 if (!strcmp(res->identifier, "all"))
7663                         device_infos_display(NULL);
7664                 else
7665                         device_infos_display(res->identifier);
7666         }
7667 }
7668
7669 cmdline_parse_token_string_t cmd_showdevice_show =
7670         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7671                                  "show");
7672 cmdline_parse_token_string_t cmd_showdevice_device =
7673         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7674 cmdline_parse_token_string_t cmd_showdevice_what =
7675         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7676                                  "info");
7677 cmdline_parse_token_string_t cmd_showdevice_identifier =
7678         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7679                         identifier, NULL);
7680
7681 cmdline_parse_inst_t cmd_showdevice = {
7682         .f = cmd_showdevice_parsed,
7683         .data = NULL,
7684         .help_str = "show device info <identifier>|all",
7685         .tokens = {
7686                 (void *)&cmd_showdevice_show,
7687                 (void *)&cmd_showdevice_device,
7688                 (void *)&cmd_showdevice_what,
7689                 (void *)&cmd_showdevice_identifier,
7690                 NULL,
7691         },
7692 };
7693
7694 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7695 struct cmd_showeeprom_result {
7696         cmdline_fixed_string_t show;
7697         cmdline_fixed_string_t port;
7698         uint16_t portnum;
7699         cmdline_fixed_string_t type;
7700 };
7701
7702 static void cmd_showeeprom_parsed(void *parsed_result,
7703                 __rte_unused struct cmdline *cl,
7704                 __rte_unused void *data)
7705 {
7706         struct cmd_showeeprom_result *res = parsed_result;
7707
7708         if (!strcmp(res->type, "eeprom"))
7709                 port_eeprom_display(res->portnum);
7710         else if (!strcmp(res->type, "module_eeprom"))
7711                 port_module_eeprom_display(res->portnum);
7712         else
7713                 printf("Unknown argument\n");
7714 }
7715
7716 cmdline_parse_token_string_t cmd_showeeprom_show =
7717         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7718 cmdline_parse_token_string_t cmd_showeeprom_port =
7719         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7720 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7721         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7722 cmdline_parse_token_string_t cmd_showeeprom_type =
7723         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7724
7725 cmdline_parse_inst_t cmd_showeeprom = {
7726         .f = cmd_showeeprom_parsed,
7727         .data = NULL,
7728         .help_str = "show port <port_id> module_eeprom|eeprom",
7729         .tokens = {
7730                 (void *)&cmd_showeeprom_show,
7731                 (void *)&cmd_showeeprom_port,
7732                 (void *)&cmd_showeeprom_portnum,
7733                 (void *)&cmd_showeeprom_type,
7734                 NULL,
7735         },
7736 };
7737
7738 /* *** SHOW QUEUE INFO *** */
7739 struct cmd_showqueue_result {
7740         cmdline_fixed_string_t show;
7741         cmdline_fixed_string_t type;
7742         cmdline_fixed_string_t what;
7743         uint16_t portnum;
7744         uint16_t queuenum;
7745 };
7746
7747 static void
7748 cmd_showqueue_parsed(void *parsed_result,
7749         __rte_unused struct cmdline *cl,
7750         __rte_unused void *data)
7751 {
7752         struct cmd_showqueue_result *res = parsed_result;
7753
7754         if (!strcmp(res->type, "rxq"))
7755                 rx_queue_infos_display(res->portnum, res->queuenum);
7756         else if (!strcmp(res->type, "txq"))
7757                 tx_queue_infos_display(res->portnum, res->queuenum);
7758 }
7759
7760 cmdline_parse_token_string_t cmd_showqueue_show =
7761         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7762 cmdline_parse_token_string_t cmd_showqueue_type =
7763         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7764 cmdline_parse_token_string_t cmd_showqueue_what =
7765         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7766 cmdline_parse_token_num_t cmd_showqueue_portnum =
7767         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7768 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7769         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7770
7771 cmdline_parse_inst_t cmd_showqueue = {
7772         .f = cmd_showqueue_parsed,
7773         .data = NULL,
7774         .help_str = "show rxq|txq info <port_id> <queue_id>",
7775         .tokens = {
7776                 (void *)&cmd_showqueue_show,
7777                 (void *)&cmd_showqueue_type,
7778                 (void *)&cmd_showqueue_what,
7779                 (void *)&cmd_showqueue_portnum,
7780                 (void *)&cmd_showqueue_queuenum,
7781                 NULL,
7782         },
7783 };
7784
7785 /* show/clear fwd engine statistics */
7786 struct fwd_result {
7787         cmdline_fixed_string_t action;
7788         cmdline_fixed_string_t fwd;
7789         cmdline_fixed_string_t stats;
7790         cmdline_fixed_string_t all;
7791 };
7792
7793 cmdline_parse_token_string_t cmd_fwd_action =
7794         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7795 cmdline_parse_token_string_t cmd_fwd_fwd =
7796         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7797 cmdline_parse_token_string_t cmd_fwd_stats =
7798         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7799 cmdline_parse_token_string_t cmd_fwd_all =
7800         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7801
7802 static void
7803 cmd_showfwdall_parsed(void *parsed_result,
7804                       __rte_unused struct cmdline *cl,
7805                       __rte_unused void *data)
7806 {
7807         struct fwd_result *res = parsed_result;
7808
7809         if (!strcmp(res->action, "show"))
7810                 fwd_stats_display();
7811         else
7812                 fwd_stats_reset();
7813 }
7814
7815 static cmdline_parse_inst_t cmd_showfwdall = {
7816         .f = cmd_showfwdall_parsed,
7817         .data = NULL,
7818         .help_str = "show|clear fwd stats all",
7819         .tokens = {
7820                 (void *)&cmd_fwd_action,
7821                 (void *)&cmd_fwd_fwd,
7822                 (void *)&cmd_fwd_stats,
7823                 (void *)&cmd_fwd_all,
7824                 NULL,
7825         },
7826 };
7827
7828 /* *** READ PORT REGISTER *** */
7829 struct cmd_read_reg_result {
7830         cmdline_fixed_string_t read;
7831         cmdline_fixed_string_t reg;
7832         portid_t port_id;
7833         uint32_t reg_off;
7834 };
7835
7836 static void
7837 cmd_read_reg_parsed(void *parsed_result,
7838                     __rte_unused struct cmdline *cl,
7839                     __rte_unused void *data)
7840 {
7841         struct cmd_read_reg_result *res = parsed_result;
7842         port_reg_display(res->port_id, res->reg_off);
7843 }
7844
7845 cmdline_parse_token_string_t cmd_read_reg_read =
7846         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7847 cmdline_parse_token_string_t cmd_read_reg_reg =
7848         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7849 cmdline_parse_token_num_t cmd_read_reg_port_id =
7850         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7851 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7852         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7853
7854 cmdline_parse_inst_t cmd_read_reg = {
7855         .f = cmd_read_reg_parsed,
7856         .data = NULL,
7857         .help_str = "read reg <port_id> <reg_off>",
7858         .tokens = {
7859                 (void *)&cmd_read_reg_read,
7860                 (void *)&cmd_read_reg_reg,
7861                 (void *)&cmd_read_reg_port_id,
7862                 (void *)&cmd_read_reg_reg_off,
7863                 NULL,
7864         },
7865 };
7866
7867 /* *** READ PORT REGISTER BIT FIELD *** */
7868 struct cmd_read_reg_bit_field_result {
7869         cmdline_fixed_string_t read;
7870         cmdline_fixed_string_t regfield;
7871         portid_t port_id;
7872         uint32_t reg_off;
7873         uint8_t bit1_pos;
7874         uint8_t bit2_pos;
7875 };
7876
7877 static void
7878 cmd_read_reg_bit_field_parsed(void *parsed_result,
7879                               __rte_unused struct cmdline *cl,
7880                               __rte_unused void *data)
7881 {
7882         struct cmd_read_reg_bit_field_result *res = parsed_result;
7883         port_reg_bit_field_display(res->port_id, res->reg_off,
7884                                    res->bit1_pos, res->bit2_pos);
7885 }
7886
7887 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7888         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7889                                  "read");
7890 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7891         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7892                                  regfield, "regfield");
7893 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7894         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7895                               UINT16);
7896 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7897         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7898                               UINT32);
7899 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7900         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7901                               UINT8);
7902 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7903         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7904                               UINT8);
7905
7906 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7907         .f = cmd_read_reg_bit_field_parsed,
7908         .data = NULL,
7909         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7910         "Read register bit field between bit_x and bit_y included",
7911         .tokens = {
7912                 (void *)&cmd_read_reg_bit_field_read,
7913                 (void *)&cmd_read_reg_bit_field_regfield,
7914                 (void *)&cmd_read_reg_bit_field_port_id,
7915                 (void *)&cmd_read_reg_bit_field_reg_off,
7916                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7917                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7918                 NULL,
7919         },
7920 };
7921
7922 /* *** READ PORT REGISTER BIT *** */
7923 struct cmd_read_reg_bit_result {
7924         cmdline_fixed_string_t read;
7925         cmdline_fixed_string_t regbit;
7926         portid_t port_id;
7927         uint32_t reg_off;
7928         uint8_t bit_pos;
7929 };
7930
7931 static void
7932 cmd_read_reg_bit_parsed(void *parsed_result,
7933                         __rte_unused struct cmdline *cl,
7934                         __rte_unused void *data)
7935 {
7936         struct cmd_read_reg_bit_result *res = parsed_result;
7937         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7938 }
7939
7940 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7941         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7942 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7943         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7944                                  regbit, "regbit");
7945 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7946         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7947 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7948         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7949 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7950         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7951
7952 cmdline_parse_inst_t cmd_read_reg_bit = {
7953         .f = cmd_read_reg_bit_parsed,
7954         .data = NULL,
7955         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7956         .tokens = {
7957                 (void *)&cmd_read_reg_bit_read,
7958                 (void *)&cmd_read_reg_bit_regbit,
7959                 (void *)&cmd_read_reg_bit_port_id,
7960                 (void *)&cmd_read_reg_bit_reg_off,
7961                 (void *)&cmd_read_reg_bit_bit_pos,
7962                 NULL,
7963         },
7964 };
7965
7966 /* *** WRITE PORT REGISTER *** */
7967 struct cmd_write_reg_result {
7968         cmdline_fixed_string_t write;
7969         cmdline_fixed_string_t reg;
7970         portid_t port_id;
7971         uint32_t reg_off;
7972         uint32_t value;
7973 };
7974
7975 static void
7976 cmd_write_reg_parsed(void *parsed_result,
7977                      __rte_unused struct cmdline *cl,
7978                      __rte_unused void *data)
7979 {
7980         struct cmd_write_reg_result *res = parsed_result;
7981         port_reg_set(res->port_id, res->reg_off, res->value);
7982 }
7983
7984 cmdline_parse_token_string_t cmd_write_reg_write =
7985         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7986 cmdline_parse_token_string_t cmd_write_reg_reg =
7987         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7988 cmdline_parse_token_num_t cmd_write_reg_port_id =
7989         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7990 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7991         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7992 cmdline_parse_token_num_t cmd_write_reg_value =
7993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7994
7995 cmdline_parse_inst_t cmd_write_reg = {
7996         .f = cmd_write_reg_parsed,
7997         .data = NULL,
7998         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7999         .tokens = {
8000                 (void *)&cmd_write_reg_write,
8001                 (void *)&cmd_write_reg_reg,
8002                 (void *)&cmd_write_reg_port_id,
8003                 (void *)&cmd_write_reg_reg_off,
8004                 (void *)&cmd_write_reg_value,
8005                 NULL,
8006         },
8007 };
8008
8009 /* *** WRITE PORT REGISTER BIT FIELD *** */
8010 struct cmd_write_reg_bit_field_result {
8011         cmdline_fixed_string_t write;
8012         cmdline_fixed_string_t regfield;
8013         portid_t port_id;
8014         uint32_t reg_off;
8015         uint8_t bit1_pos;
8016         uint8_t bit2_pos;
8017         uint32_t value;
8018 };
8019
8020 static void
8021 cmd_write_reg_bit_field_parsed(void *parsed_result,
8022                                __rte_unused struct cmdline *cl,
8023                                __rte_unused void *data)
8024 {
8025         struct cmd_write_reg_bit_field_result *res = parsed_result;
8026         port_reg_bit_field_set(res->port_id, res->reg_off,
8027                           res->bit1_pos, res->bit2_pos, res->value);
8028 }
8029
8030 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8031         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8032                                  "write");
8033 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8034         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8035                                  regfield, "regfield");
8036 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8037         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8038                               UINT16);
8039 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8040         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8041                               UINT32);
8042 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8043         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8044                               UINT8);
8045 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8046         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8047                               UINT8);
8048 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8049         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8050                               UINT32);
8051
8052 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8053         .f = cmd_write_reg_bit_field_parsed,
8054         .data = NULL,
8055         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8056                 "<reg_value>: "
8057                 "Set register bit field between bit_x and bit_y included",
8058         .tokens = {
8059                 (void *)&cmd_write_reg_bit_field_write,
8060                 (void *)&cmd_write_reg_bit_field_regfield,
8061                 (void *)&cmd_write_reg_bit_field_port_id,
8062                 (void *)&cmd_write_reg_bit_field_reg_off,
8063                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8064                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8065                 (void *)&cmd_write_reg_bit_field_value,
8066                 NULL,
8067         },
8068 };
8069
8070 /* *** WRITE PORT REGISTER BIT *** */
8071 struct cmd_write_reg_bit_result {
8072         cmdline_fixed_string_t write;
8073         cmdline_fixed_string_t regbit;
8074         portid_t port_id;
8075         uint32_t reg_off;
8076         uint8_t bit_pos;
8077         uint8_t value;
8078 };
8079
8080 static void
8081 cmd_write_reg_bit_parsed(void *parsed_result,
8082                          __rte_unused struct cmdline *cl,
8083                          __rte_unused void *data)
8084 {
8085         struct cmd_write_reg_bit_result *res = parsed_result;
8086         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8087 }
8088
8089 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8090         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8091                                  "write");
8092 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8093         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8094                                  regbit, "regbit");
8095 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8096         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8097 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8098         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8099 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8100         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8101 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8102         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8103
8104 cmdline_parse_inst_t cmd_write_reg_bit = {
8105         .f = cmd_write_reg_bit_parsed,
8106         .data = NULL,
8107         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8108                 "0 <= bit_x <= 31",
8109         .tokens = {
8110                 (void *)&cmd_write_reg_bit_write,
8111                 (void *)&cmd_write_reg_bit_regbit,
8112                 (void *)&cmd_write_reg_bit_port_id,
8113                 (void *)&cmd_write_reg_bit_reg_off,
8114                 (void *)&cmd_write_reg_bit_bit_pos,
8115                 (void *)&cmd_write_reg_bit_value,
8116                 NULL,
8117         },
8118 };
8119
8120 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8121 struct cmd_read_rxd_txd_result {
8122         cmdline_fixed_string_t read;
8123         cmdline_fixed_string_t rxd_txd;
8124         portid_t port_id;
8125         uint16_t queue_id;
8126         uint16_t desc_id;
8127 };
8128
8129 static void
8130 cmd_read_rxd_txd_parsed(void *parsed_result,
8131                         __rte_unused struct cmdline *cl,
8132                         __rte_unused void *data)
8133 {
8134         struct cmd_read_rxd_txd_result *res = parsed_result;
8135
8136         if (!strcmp(res->rxd_txd, "rxd"))
8137                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8138         else if (!strcmp(res->rxd_txd, "txd"))
8139                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8140 }
8141
8142 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8143         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8144 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8145         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8146                                  "rxd#txd");
8147 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8148         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8149 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8150         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8151 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8152         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8153
8154 cmdline_parse_inst_t cmd_read_rxd_txd = {
8155         .f = cmd_read_rxd_txd_parsed,
8156         .data = NULL,
8157         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8158         .tokens = {
8159                 (void *)&cmd_read_rxd_txd_read,
8160                 (void *)&cmd_read_rxd_txd_rxd_txd,
8161                 (void *)&cmd_read_rxd_txd_port_id,
8162                 (void *)&cmd_read_rxd_txd_queue_id,
8163                 (void *)&cmd_read_rxd_txd_desc_id,
8164                 NULL,
8165         },
8166 };
8167
8168 /* *** QUIT *** */
8169 struct cmd_quit_result {
8170         cmdline_fixed_string_t quit;
8171 };
8172
8173 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8174                             struct cmdline *cl,
8175                             __rte_unused void *data)
8176 {
8177         cmdline_quit(cl);
8178 }
8179
8180 cmdline_parse_token_string_t cmd_quit_quit =
8181         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8182
8183 cmdline_parse_inst_t cmd_quit = {
8184         .f = cmd_quit_parsed,
8185         .data = NULL,
8186         .help_str = "quit: Exit application",
8187         .tokens = {
8188                 (void *)&cmd_quit_quit,
8189                 NULL,
8190         },
8191 };
8192
8193 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8194 struct cmd_mac_addr_result {
8195         cmdline_fixed_string_t mac_addr_cmd;
8196         cmdline_fixed_string_t what;
8197         uint16_t port_num;
8198         struct rte_ether_addr address;
8199 };
8200
8201 static void cmd_mac_addr_parsed(void *parsed_result,
8202                 __rte_unused struct cmdline *cl,
8203                 __rte_unused void *data)
8204 {
8205         struct cmd_mac_addr_result *res = parsed_result;
8206         int ret;
8207
8208         if (strcmp(res->what, "add") == 0)
8209                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8210         else if (strcmp(res->what, "set") == 0)
8211                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8212                                                        &res->address);
8213         else
8214                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8215
8216         /* check the return value and print it if is < 0 */
8217         if(ret < 0)
8218                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8219
8220 }
8221
8222 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8223         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8224                                 "mac_addr");
8225 cmdline_parse_token_string_t cmd_mac_addr_what =
8226         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8227                                 "add#remove#set");
8228 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8229                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8230                                         UINT16);
8231 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8232                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8233
8234 cmdline_parse_inst_t cmd_mac_addr = {
8235         .f = cmd_mac_addr_parsed,
8236         .data = (void *)0,
8237         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8238                         "Add/Remove/Set MAC address on port_id",
8239         .tokens = {
8240                 (void *)&cmd_mac_addr_cmd,
8241                 (void *)&cmd_mac_addr_what,
8242                 (void *)&cmd_mac_addr_portnum,
8243                 (void *)&cmd_mac_addr_addr,
8244                 NULL,
8245         },
8246 };
8247
8248 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8249 struct cmd_eth_peer_result {
8250         cmdline_fixed_string_t set;
8251         cmdline_fixed_string_t eth_peer;
8252         portid_t port_id;
8253         cmdline_fixed_string_t peer_addr;
8254 };
8255
8256 static void cmd_set_eth_peer_parsed(void *parsed_result,
8257                         __rte_unused struct cmdline *cl,
8258                         __rte_unused void *data)
8259 {
8260                 struct cmd_eth_peer_result *res = parsed_result;
8261
8262                 if (test_done == 0) {
8263                         printf("Please stop forwarding first\n");
8264                         return;
8265                 }
8266                 if (!strcmp(res->eth_peer, "eth-peer")) {
8267                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8268                         fwd_config_setup();
8269                 }
8270 }
8271 cmdline_parse_token_string_t cmd_eth_peer_set =
8272         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8273 cmdline_parse_token_string_t cmd_eth_peer =
8274         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8275 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8276         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8277 cmdline_parse_token_string_t cmd_eth_peer_addr =
8278         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8279
8280 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8281         .f = cmd_set_eth_peer_parsed,
8282         .data = NULL,
8283         .help_str = "set eth-peer <port_id> <peer_mac>",
8284         .tokens = {
8285                 (void *)&cmd_eth_peer_set,
8286                 (void *)&cmd_eth_peer,
8287                 (void *)&cmd_eth_peer_port_id,
8288                 (void *)&cmd_eth_peer_addr,
8289                 NULL,
8290         },
8291 };
8292
8293 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8294 struct cmd_set_qmap_result {
8295         cmdline_fixed_string_t set;
8296         cmdline_fixed_string_t qmap;
8297         cmdline_fixed_string_t what;
8298         portid_t port_id;
8299         uint16_t queue_id;
8300         uint8_t map_value;
8301 };
8302
8303 static void
8304 cmd_set_qmap_parsed(void *parsed_result,
8305                        __rte_unused struct cmdline *cl,
8306                        __rte_unused void *data)
8307 {
8308         struct cmd_set_qmap_result *res = parsed_result;
8309         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8310
8311         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8312 }
8313
8314 cmdline_parse_token_string_t cmd_setqmap_set =
8315         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8316                                  set, "set");
8317 cmdline_parse_token_string_t cmd_setqmap_qmap =
8318         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8319                                  qmap, "stat_qmap");
8320 cmdline_parse_token_string_t cmd_setqmap_what =
8321         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8322                                  what, "tx#rx");
8323 cmdline_parse_token_num_t cmd_setqmap_portid =
8324         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8325                               port_id, UINT16);
8326 cmdline_parse_token_num_t cmd_setqmap_queueid =
8327         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8328                               queue_id, UINT16);
8329 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8330         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8331                               map_value, UINT8);
8332
8333 cmdline_parse_inst_t cmd_set_qmap = {
8334         .f = cmd_set_qmap_parsed,
8335         .data = NULL,
8336         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8337                 "Set statistics mapping value on tx|rx queue_id of port_id",
8338         .tokens = {
8339                 (void *)&cmd_setqmap_set,
8340                 (void *)&cmd_setqmap_qmap,
8341                 (void *)&cmd_setqmap_what,
8342                 (void *)&cmd_setqmap_portid,
8343                 (void *)&cmd_setqmap_queueid,
8344                 (void *)&cmd_setqmap_mapvalue,
8345                 NULL,
8346         },
8347 };
8348
8349 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8350 struct cmd_set_xstats_hide_zero_result {
8351         cmdline_fixed_string_t keyword;
8352         cmdline_fixed_string_t name;
8353         cmdline_fixed_string_t on_off;
8354 };
8355
8356 static void
8357 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8358                         __rte_unused struct cmdline *cl,
8359                         __rte_unused void *data)
8360 {
8361         struct cmd_set_xstats_hide_zero_result *res;
8362         uint16_t on_off = 0;
8363
8364         res = parsed_result;
8365         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8366         set_xstats_hide_zero(on_off);
8367 }
8368
8369 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8370         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8371                                  keyword, "set");
8372 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8373         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8374                                  name, "xstats-hide-zero");
8375 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8376         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8377                                  on_off, "on#off");
8378
8379 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8380         .f = cmd_set_xstats_hide_zero_parsed,
8381         .data = NULL,
8382         .help_str = "set xstats-hide-zero on|off",
8383         .tokens = {
8384                 (void *)&cmd_set_xstats_hide_zero_keyword,
8385                 (void *)&cmd_set_xstats_hide_zero_name,
8386                 (void *)&cmd_set_xstats_hide_zero_on_off,
8387                 NULL,
8388         },
8389 };
8390
8391 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8392 struct cmd_set_record_core_cycles_result {
8393         cmdline_fixed_string_t keyword;
8394         cmdline_fixed_string_t name;
8395         cmdline_fixed_string_t on_off;
8396 };
8397
8398 static void
8399 cmd_set_record_core_cycles_parsed(void *parsed_result,
8400                         __rte_unused struct cmdline *cl,
8401                         __rte_unused void *data)
8402 {
8403         struct cmd_set_record_core_cycles_result *res;
8404         uint16_t on_off = 0;
8405
8406         res = parsed_result;
8407         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8408         set_record_core_cycles(on_off);
8409 }
8410
8411 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8412         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8413                                  keyword, "set");
8414 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8415         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8416                                  name, "record-core-cycles");
8417 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8418         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8419                                  on_off, "on#off");
8420
8421 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8422         .f = cmd_set_record_core_cycles_parsed,
8423         .data = NULL,
8424         .help_str = "set record-core-cycles on|off",
8425         .tokens = {
8426                 (void *)&cmd_set_record_core_cycles_keyword,
8427                 (void *)&cmd_set_record_core_cycles_name,
8428                 (void *)&cmd_set_record_core_cycles_on_off,
8429                 NULL,
8430         },
8431 };
8432
8433 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8434 struct cmd_set_record_burst_stats_result {
8435         cmdline_fixed_string_t keyword;
8436         cmdline_fixed_string_t name;
8437         cmdline_fixed_string_t on_off;
8438 };
8439
8440 static void
8441 cmd_set_record_burst_stats_parsed(void *parsed_result,
8442                         __rte_unused struct cmdline *cl,
8443                         __rte_unused void *data)
8444 {
8445         struct cmd_set_record_burst_stats_result *res;
8446         uint16_t on_off = 0;
8447
8448         res = parsed_result;
8449         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8450         set_record_burst_stats(on_off);
8451 }
8452
8453 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8455                                  keyword, "set");
8456 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8457         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8458                                  name, "record-burst-stats");
8459 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8461                                  on_off, "on#off");
8462
8463 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8464         .f = cmd_set_record_burst_stats_parsed,
8465         .data = NULL,
8466         .help_str = "set record-burst-stats on|off",
8467         .tokens = {
8468                 (void *)&cmd_set_record_burst_stats_keyword,
8469                 (void *)&cmd_set_record_burst_stats_name,
8470                 (void *)&cmd_set_record_burst_stats_on_off,
8471                 NULL,
8472         },
8473 };
8474
8475 /* *** CONFIGURE UNICAST HASH TABLE *** */
8476 struct cmd_set_uc_hash_table {
8477         cmdline_fixed_string_t set;
8478         cmdline_fixed_string_t port;
8479         portid_t port_id;
8480         cmdline_fixed_string_t what;
8481         struct rte_ether_addr address;
8482         cmdline_fixed_string_t mode;
8483 };
8484
8485 static void
8486 cmd_set_uc_hash_parsed(void *parsed_result,
8487                        __rte_unused struct cmdline *cl,
8488                        __rte_unused void *data)
8489 {
8490         int ret=0;
8491         struct cmd_set_uc_hash_table *res = parsed_result;
8492
8493         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8494
8495         if (strcmp(res->what, "uta") == 0)
8496                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8497                                                 &res->address,(uint8_t)is_on);
8498         if (ret < 0)
8499                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8500
8501 }
8502
8503 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8504         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8505                                  set, "set");
8506 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8508                                  port, "port");
8509 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8510         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8511                               port_id, UINT16);
8512 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8513         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8514                                  what, "uta");
8515 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8516         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8517                                 address);
8518 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8519         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8520                                  mode, "on#off");
8521
8522 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8523         .f = cmd_set_uc_hash_parsed,
8524         .data = NULL,
8525         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8526         .tokens = {
8527                 (void *)&cmd_set_uc_hash_set,
8528                 (void *)&cmd_set_uc_hash_port,
8529                 (void *)&cmd_set_uc_hash_portid,
8530                 (void *)&cmd_set_uc_hash_what,
8531                 (void *)&cmd_set_uc_hash_mac,
8532                 (void *)&cmd_set_uc_hash_mode,
8533                 NULL,
8534         },
8535 };
8536
8537 struct cmd_set_uc_all_hash_table {
8538         cmdline_fixed_string_t set;
8539         cmdline_fixed_string_t port;
8540         portid_t port_id;
8541         cmdline_fixed_string_t what;
8542         cmdline_fixed_string_t value;
8543         cmdline_fixed_string_t mode;
8544 };
8545
8546 static void
8547 cmd_set_uc_all_hash_parsed(void *parsed_result,
8548                        __rte_unused struct cmdline *cl,
8549                        __rte_unused void *data)
8550 {
8551         int ret=0;
8552         struct cmd_set_uc_all_hash_table *res = parsed_result;
8553
8554         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8555
8556         if ((strcmp(res->what, "uta") == 0) &&
8557                 (strcmp(res->value, "all") == 0))
8558                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8559         if (ret < 0)
8560                 printf("bad unicast hash table parameter,"
8561                         "return code = %d \n", ret);
8562 }
8563
8564 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8565         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8566                                  set, "set");
8567 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8568         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8569                                  port, "port");
8570 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8571         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8572                               port_id, UINT16);
8573 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8574         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8575                                  what, "uta");
8576 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8577         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8578                                 value,"all");
8579 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8580         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8581                                  mode, "on#off");
8582
8583 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8584         .f = cmd_set_uc_all_hash_parsed,
8585         .data = NULL,
8586         .help_str = "set port <port_id> uta all on|off",
8587         .tokens = {
8588                 (void *)&cmd_set_uc_all_hash_set,
8589                 (void *)&cmd_set_uc_all_hash_port,
8590                 (void *)&cmd_set_uc_all_hash_portid,
8591                 (void *)&cmd_set_uc_all_hash_what,
8592                 (void *)&cmd_set_uc_all_hash_value,
8593                 (void *)&cmd_set_uc_all_hash_mode,
8594                 NULL,
8595         },
8596 };
8597
8598 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8599 struct cmd_set_vf_traffic {
8600         cmdline_fixed_string_t set;
8601         cmdline_fixed_string_t port;
8602         portid_t port_id;
8603         cmdline_fixed_string_t vf;
8604         uint8_t vf_id;
8605         cmdline_fixed_string_t what;
8606         cmdline_fixed_string_t mode;
8607 };
8608
8609 static void
8610 cmd_set_vf_traffic_parsed(void *parsed_result,
8611                        __rte_unused struct cmdline *cl,
8612                        __rte_unused void *data)
8613 {
8614         struct cmd_set_vf_traffic *res = parsed_result;
8615         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8616         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8617
8618         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8619 }
8620
8621 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8623                                  set, "set");
8624 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8625         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8626                                  port, "port");
8627 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8628         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8629                               port_id, UINT16);
8630 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8632                                  vf, "vf");
8633 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8634         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8635                               vf_id, UINT8);
8636 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8637         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8638                                  what, "tx#rx");
8639 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8640         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8641                                  mode, "on#off");
8642
8643 cmdline_parse_inst_t cmd_set_vf_traffic = {
8644         .f = cmd_set_vf_traffic_parsed,
8645         .data = NULL,
8646         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8647         .tokens = {
8648                 (void *)&cmd_setvf_traffic_set,
8649                 (void *)&cmd_setvf_traffic_port,
8650                 (void *)&cmd_setvf_traffic_portid,
8651                 (void *)&cmd_setvf_traffic_vf,
8652                 (void *)&cmd_setvf_traffic_vfid,
8653                 (void *)&cmd_setvf_traffic_what,
8654                 (void *)&cmd_setvf_traffic_mode,
8655                 NULL,
8656         },
8657 };
8658
8659 /* *** CONFIGURE VF RECEIVE MODE *** */
8660 struct cmd_set_vf_rxmode {
8661         cmdline_fixed_string_t set;
8662         cmdline_fixed_string_t port;
8663         portid_t port_id;
8664         cmdline_fixed_string_t vf;
8665         uint8_t vf_id;
8666         cmdline_fixed_string_t what;
8667         cmdline_fixed_string_t mode;
8668         cmdline_fixed_string_t on;
8669 };
8670
8671 static void
8672 cmd_set_vf_rxmode_parsed(void *parsed_result,
8673                        __rte_unused struct cmdline *cl,
8674                        __rte_unused void *data)
8675 {
8676         int ret = -ENOTSUP;
8677         uint16_t vf_rxmode = 0;
8678         struct cmd_set_vf_rxmode *res = parsed_result;
8679
8680         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8681         if (!strcmp(res->what,"rxmode")) {
8682                 if (!strcmp(res->mode, "AUPE"))
8683                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8684                 else if (!strcmp(res->mode, "ROPE"))
8685                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8686                 else if (!strcmp(res->mode, "BAM"))
8687                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8688                 else if (!strncmp(res->mode, "MPE",3))
8689                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8690         }
8691
8692         RTE_SET_USED(is_on);
8693
8694 #ifdef RTE_NET_IXGBE
8695         if (ret == -ENOTSUP)
8696                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8697                                                   vf_rxmode, (uint8_t)is_on);
8698 #endif
8699 #ifdef RTE_NET_BNXT
8700         if (ret == -ENOTSUP)
8701                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8702                                                  vf_rxmode, (uint8_t)is_on);
8703 #endif
8704         if (ret < 0)
8705                 printf("bad VF receive mode parameter, return code = %d \n",
8706                 ret);
8707 }
8708
8709 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8710         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8711                                  set, "set");
8712 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8713         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8714                                  port, "port");
8715 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8716         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8717                               port_id, UINT16);
8718 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8719         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8720                                  vf, "vf");
8721 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8722         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8723                               vf_id, UINT8);
8724 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8725         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8726                                  what, "rxmode");
8727 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8728         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8729                                  mode, "AUPE#ROPE#BAM#MPE");
8730 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8731         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8732                                  on, "on#off");
8733
8734 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8735         .f = cmd_set_vf_rxmode_parsed,
8736         .data = NULL,
8737         .help_str = "set port <port_id> vf <vf_id> rxmode "
8738                 "AUPE|ROPE|BAM|MPE on|off",
8739         .tokens = {
8740                 (void *)&cmd_set_vf_rxmode_set,
8741                 (void *)&cmd_set_vf_rxmode_port,
8742                 (void *)&cmd_set_vf_rxmode_portid,
8743                 (void *)&cmd_set_vf_rxmode_vf,
8744                 (void *)&cmd_set_vf_rxmode_vfid,
8745                 (void *)&cmd_set_vf_rxmode_what,
8746                 (void *)&cmd_set_vf_rxmode_mode,
8747                 (void *)&cmd_set_vf_rxmode_on,
8748                 NULL,
8749         },
8750 };
8751
8752 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8753 struct cmd_vf_mac_addr_result {
8754         cmdline_fixed_string_t mac_addr_cmd;
8755         cmdline_fixed_string_t what;
8756         cmdline_fixed_string_t port;
8757         uint16_t port_num;
8758         cmdline_fixed_string_t vf;
8759         uint8_t vf_num;
8760         struct rte_ether_addr address;
8761 };
8762
8763 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8764                 __rte_unused struct cmdline *cl,
8765                 __rte_unused void *data)
8766 {
8767         struct cmd_vf_mac_addr_result *res = parsed_result;
8768         int ret = -ENOTSUP;
8769
8770         if (strcmp(res->what, "add") != 0)
8771                 return;
8772
8773 #ifdef RTE_NET_I40E
8774         if (ret == -ENOTSUP)
8775                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8776                                                    &res->address);
8777 #endif
8778 #ifdef RTE_NET_BNXT
8779         if (ret == -ENOTSUP)
8780                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8781                                                 res->vf_num);
8782 #endif
8783
8784         if(ret < 0)
8785                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8786
8787 }
8788
8789 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8790         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8791                                 mac_addr_cmd,"mac_addr");
8792 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8793         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8794                                 what,"add");
8795 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8796         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8797                                 port,"port");
8798 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8799         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8800                                 port_num, UINT16);
8801 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8802         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8803                                 vf,"vf");
8804 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8805         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8806                                 vf_num, UINT8);
8807 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8808         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8809                                 address);
8810
8811 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8812         .f = cmd_vf_mac_addr_parsed,
8813         .data = (void *)0,
8814         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8815                 "Add MAC address filtering for a VF on port_id",
8816         .tokens = {
8817                 (void *)&cmd_vf_mac_addr_cmd,
8818                 (void *)&cmd_vf_mac_addr_what,
8819                 (void *)&cmd_vf_mac_addr_port,
8820                 (void *)&cmd_vf_mac_addr_portnum,
8821                 (void *)&cmd_vf_mac_addr_vf,
8822                 (void *)&cmd_vf_mac_addr_vfnum,
8823                 (void *)&cmd_vf_mac_addr_addr,
8824                 NULL,
8825         },
8826 };
8827
8828 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8829 struct cmd_vf_rx_vlan_filter {
8830         cmdline_fixed_string_t rx_vlan;
8831         cmdline_fixed_string_t what;
8832         uint16_t vlan_id;
8833         cmdline_fixed_string_t port;
8834         portid_t port_id;
8835         cmdline_fixed_string_t vf;
8836         uint64_t vf_mask;
8837 };
8838
8839 static void
8840 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8841                           __rte_unused struct cmdline *cl,
8842                           __rte_unused void *data)
8843 {
8844         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8845         int ret = -ENOTSUP;
8846
8847         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8848
8849 #ifdef RTE_NET_IXGBE
8850         if (ret == -ENOTSUP)
8851                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8852                                 res->vlan_id, res->vf_mask, is_add);
8853 #endif
8854 #ifdef RTE_NET_I40E
8855         if (ret == -ENOTSUP)
8856                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8857                                 res->vlan_id, res->vf_mask, is_add);
8858 #endif
8859 #ifdef RTE_NET_BNXT
8860         if (ret == -ENOTSUP)
8861                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8862                                 res->vlan_id, res->vf_mask, is_add);
8863 #endif
8864
8865         switch (ret) {
8866         case 0:
8867                 break;
8868         case -EINVAL:
8869                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8870                                 res->vlan_id, res->vf_mask);
8871                 break;
8872         case -ENODEV:
8873                 printf("invalid port_id %d\n", res->port_id);
8874                 break;
8875         case -ENOTSUP:
8876                 printf("function not implemented or supported\n");
8877                 break;
8878         default:
8879                 printf("programming error: (%s)\n", strerror(-ret));
8880         }
8881 }
8882
8883 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8884         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8885                                  rx_vlan, "rx_vlan");
8886 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8887         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8888                                  what, "add#rm");
8889 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8890         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8891                               vlan_id, UINT16);
8892 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8893         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8894                                  port, "port");
8895 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8896         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8897                               port_id, UINT16);
8898 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8899         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8900                                  vf, "vf");
8901 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8902         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8903                               vf_mask, UINT64);
8904
8905 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8906         .f = cmd_vf_rx_vlan_filter_parsed,
8907         .data = NULL,
8908         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8909                 "(vf_mask = hexadecimal VF mask)",
8910         .tokens = {
8911                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8912                 (void *)&cmd_vf_rx_vlan_filter_what,
8913                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8914                 (void *)&cmd_vf_rx_vlan_filter_port,
8915                 (void *)&cmd_vf_rx_vlan_filter_portid,
8916                 (void *)&cmd_vf_rx_vlan_filter_vf,
8917                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8918                 NULL,
8919         },
8920 };
8921
8922 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8923 struct cmd_queue_rate_limit_result {
8924         cmdline_fixed_string_t set;
8925         cmdline_fixed_string_t port;
8926         uint16_t port_num;
8927         cmdline_fixed_string_t queue;
8928         uint8_t queue_num;
8929         cmdline_fixed_string_t rate;
8930         uint16_t rate_num;
8931 };
8932
8933 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8934                 __rte_unused struct cmdline *cl,
8935                 __rte_unused void *data)
8936 {
8937         struct cmd_queue_rate_limit_result *res = parsed_result;
8938         int ret = 0;
8939
8940         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8941                 && (strcmp(res->queue, "queue") == 0)
8942                 && (strcmp(res->rate, "rate") == 0))
8943                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8944                                         res->rate_num);
8945         if (ret < 0)
8946                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8947
8948 }
8949
8950 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8951         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8952                                 set, "set");
8953 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8954         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8955                                 port, "port");
8956 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8957         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8958                                 port_num, UINT16);
8959 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8960         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8961                                 queue, "queue");
8962 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8963         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8964                                 queue_num, UINT8);
8965 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8966         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8967                                 rate, "rate");
8968 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8969         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8970                                 rate_num, UINT16);
8971
8972 cmdline_parse_inst_t cmd_queue_rate_limit = {
8973         .f = cmd_queue_rate_limit_parsed,
8974         .data = (void *)0,
8975         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8976                 "Set rate limit for a queue on port_id",
8977         .tokens = {
8978                 (void *)&cmd_queue_rate_limit_set,
8979                 (void *)&cmd_queue_rate_limit_port,
8980                 (void *)&cmd_queue_rate_limit_portnum,
8981                 (void *)&cmd_queue_rate_limit_queue,
8982                 (void *)&cmd_queue_rate_limit_queuenum,
8983                 (void *)&cmd_queue_rate_limit_rate,
8984                 (void *)&cmd_queue_rate_limit_ratenum,
8985                 NULL,
8986         },
8987 };
8988
8989 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8990 struct cmd_vf_rate_limit_result {
8991         cmdline_fixed_string_t set;
8992         cmdline_fixed_string_t port;
8993         uint16_t port_num;
8994         cmdline_fixed_string_t vf;
8995         uint8_t vf_num;
8996         cmdline_fixed_string_t rate;
8997         uint16_t rate_num;
8998         cmdline_fixed_string_t q_msk;
8999         uint64_t q_msk_val;
9000 };
9001
9002 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9003                 __rte_unused struct cmdline *cl,
9004                 __rte_unused void *data)
9005 {
9006         struct cmd_vf_rate_limit_result *res = parsed_result;
9007         int ret = 0;
9008
9009         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9010                 && (strcmp(res->vf, "vf") == 0)
9011                 && (strcmp(res->rate, "rate") == 0)
9012                 && (strcmp(res->q_msk, "queue_mask") == 0))
9013                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9014                                         res->rate_num, res->q_msk_val);
9015         if (ret < 0)
9016                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9017
9018 }
9019
9020 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9021         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9022                                 set, "set");
9023 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9024         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9025                                 port, "port");
9026 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9027         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9028                                 port_num, UINT16);
9029 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9030         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9031                                 vf, "vf");
9032 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9033         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9034                                 vf_num, UINT8);
9035 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9036         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9037                                 rate, "rate");
9038 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9039         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9040                                 rate_num, UINT16);
9041 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9042         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9043                                 q_msk, "queue_mask");
9044 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9045         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9046                                 q_msk_val, UINT64);
9047
9048 cmdline_parse_inst_t cmd_vf_rate_limit = {
9049         .f = cmd_vf_rate_limit_parsed,
9050         .data = (void *)0,
9051         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9052                 "queue_mask <queue_mask_value>: "
9053                 "Set rate limit for queues of VF on port_id",
9054         .tokens = {
9055                 (void *)&cmd_vf_rate_limit_set,
9056                 (void *)&cmd_vf_rate_limit_port,
9057                 (void *)&cmd_vf_rate_limit_portnum,
9058                 (void *)&cmd_vf_rate_limit_vf,
9059                 (void *)&cmd_vf_rate_limit_vfnum,
9060                 (void *)&cmd_vf_rate_limit_rate,
9061                 (void *)&cmd_vf_rate_limit_ratenum,
9062                 (void *)&cmd_vf_rate_limit_q_msk,
9063                 (void *)&cmd_vf_rate_limit_q_msk_val,
9064                 NULL,
9065         },
9066 };
9067
9068 /* *** CONFIGURE TUNNEL UDP PORT *** */
9069 struct cmd_tunnel_udp_config {
9070         cmdline_fixed_string_t cmd;
9071         cmdline_fixed_string_t what;
9072         uint16_t udp_port;
9073         portid_t port_id;
9074 };
9075
9076 static void
9077 cmd_tunnel_udp_config_parsed(void *parsed_result,
9078                           __rte_unused struct cmdline *cl,
9079                           __rte_unused void *data)
9080 {
9081         struct cmd_tunnel_udp_config *res = parsed_result;
9082         struct rte_eth_udp_tunnel tunnel_udp;
9083         int ret;
9084
9085         tunnel_udp.udp_port = res->udp_port;
9086
9087         if (!strcmp(res->cmd, "rx_vxlan_port"))
9088                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9089
9090         if (!strcmp(res->what, "add"))
9091                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9092                                                       &tunnel_udp);
9093         else
9094                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9095                                                          &tunnel_udp);
9096
9097         if (ret < 0)
9098                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9099 }
9100
9101 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9102         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9103                                 cmd, "rx_vxlan_port");
9104 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9105         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9106                                 what, "add#rm");
9107 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9108         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9109                                 udp_port, UINT16);
9110 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9111         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9112                                 port_id, UINT16);
9113
9114 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9115         .f = cmd_tunnel_udp_config_parsed,
9116         .data = (void *)0,
9117         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9118                 "Add/Remove a tunneling UDP port filter",
9119         .tokens = {
9120                 (void *)&cmd_tunnel_udp_config_cmd,
9121                 (void *)&cmd_tunnel_udp_config_what,
9122                 (void *)&cmd_tunnel_udp_config_udp_port,
9123                 (void *)&cmd_tunnel_udp_config_port_id,
9124                 NULL,
9125         },
9126 };
9127
9128 struct cmd_config_tunnel_udp_port {
9129         cmdline_fixed_string_t port;
9130         cmdline_fixed_string_t config;
9131         portid_t port_id;
9132         cmdline_fixed_string_t udp_tunnel_port;
9133         cmdline_fixed_string_t action;
9134         cmdline_fixed_string_t tunnel_type;
9135         uint16_t udp_port;
9136 };
9137
9138 static void
9139 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9140                                __rte_unused struct cmdline *cl,
9141                                __rte_unused void *data)
9142 {
9143         struct cmd_config_tunnel_udp_port *res = parsed_result;
9144         struct rte_eth_udp_tunnel tunnel_udp;
9145         int ret = 0;
9146
9147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9148                 return;
9149
9150         tunnel_udp.udp_port = res->udp_port;
9151
9152         if (!strcmp(res->tunnel_type, "vxlan")) {
9153                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9154         } else if (!strcmp(res->tunnel_type, "geneve")) {
9155                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9156         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9157                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9158         } else {
9159                 printf("Invalid tunnel type\n");
9160                 return;
9161         }
9162
9163         if (!strcmp(res->action, "add"))
9164                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9165                                                       &tunnel_udp);
9166         else
9167                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9168                                                          &tunnel_udp);
9169
9170         if (ret < 0)
9171                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9172 }
9173
9174 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9175         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9176                                  "port");
9177 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9178         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9179                                  "config");
9180 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9181         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9182                               UINT16);
9183 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9184         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9185                                  udp_tunnel_port,
9186                                  "udp_tunnel_port");
9187 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9188         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9189                                  "add#rm");
9190 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9191         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9192                                  "vxlan#geneve#vxlan-gpe");
9193 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9194         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9195                               UINT16);
9196
9197 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9198         .f = cmd_cfg_tunnel_udp_port_parsed,
9199         .data = NULL,
9200         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9201         .tokens = {
9202                 (void *)&cmd_config_tunnel_udp_port_port,
9203                 (void *)&cmd_config_tunnel_udp_port_config,
9204                 (void *)&cmd_config_tunnel_udp_port_port_id,
9205                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9206                 (void *)&cmd_config_tunnel_udp_port_action,
9207                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9208                 (void *)&cmd_config_tunnel_udp_port_value,
9209                 NULL,
9210         },
9211 };
9212
9213 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9214 struct cmd_set_mirror_mask_result {
9215         cmdline_fixed_string_t set;
9216         cmdline_fixed_string_t port;
9217         portid_t port_id;
9218         cmdline_fixed_string_t mirror;
9219         uint8_t rule_id;
9220         cmdline_fixed_string_t what;
9221         cmdline_fixed_string_t value;
9222         cmdline_fixed_string_t dstpool;
9223         uint8_t dstpool_id;
9224         cmdline_fixed_string_t on;
9225 };
9226
9227 cmdline_parse_token_string_t cmd_mirror_mask_set =
9228         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9229                                 set, "set");
9230 cmdline_parse_token_string_t cmd_mirror_mask_port =
9231         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9232                                 port, "port");
9233 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9234         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9235                                 port_id, UINT16);
9236 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9237         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9238                                 mirror, "mirror-rule");
9239 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9240         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9241                                 rule_id, UINT8);
9242 cmdline_parse_token_string_t cmd_mirror_mask_what =
9243         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9244                                 what, "pool-mirror-up#pool-mirror-down"
9245                                       "#vlan-mirror");
9246 cmdline_parse_token_string_t cmd_mirror_mask_value =
9247         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9248                                 value, NULL);
9249 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9250         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9251                                 dstpool, "dst-pool");
9252 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9253         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9254                                 dstpool_id, UINT8);
9255 cmdline_parse_token_string_t cmd_mirror_mask_on =
9256         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9257                                 on, "on#off");
9258
9259 static void
9260 cmd_set_mirror_mask_parsed(void *parsed_result,
9261                        __rte_unused struct cmdline *cl,
9262                        __rte_unused void *data)
9263 {
9264         int ret,nb_item,i;
9265         struct cmd_set_mirror_mask_result *res = parsed_result;
9266         struct rte_eth_mirror_conf mr_conf;
9267
9268         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9269
9270         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9271
9272         mr_conf.dst_pool = res->dstpool_id;
9273
9274         if (!strcmp(res->what, "pool-mirror-up")) {
9275                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9276                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9277         } else if (!strcmp(res->what, "pool-mirror-down")) {
9278                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9279                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9280         } else if (!strcmp(res->what, "vlan-mirror")) {
9281                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9282                 nb_item = parse_item_list(res->value, "vlan",
9283                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9284                 if (nb_item <= 0)
9285                         return;
9286
9287                 for (i = 0; i < nb_item; i++) {
9288                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9289                                 printf("Invalid vlan_id: must be < 4096\n");
9290                                 return;
9291                         }
9292
9293                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9294                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9295                 }
9296         }
9297
9298         if (!strcmp(res->on, "on"))
9299                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9300                                                 res->rule_id, 1);
9301         else
9302                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9303                                                 res->rule_id, 0);
9304         if (ret < 0)
9305                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9306 }
9307
9308 cmdline_parse_inst_t cmd_set_mirror_mask = {
9309                 .f = cmd_set_mirror_mask_parsed,
9310                 .data = NULL,
9311                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9312                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9313                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9314                 .tokens = {
9315                         (void *)&cmd_mirror_mask_set,
9316                         (void *)&cmd_mirror_mask_port,
9317                         (void *)&cmd_mirror_mask_portid,
9318                         (void *)&cmd_mirror_mask_mirror,
9319                         (void *)&cmd_mirror_mask_ruleid,
9320                         (void *)&cmd_mirror_mask_what,
9321                         (void *)&cmd_mirror_mask_value,
9322                         (void *)&cmd_mirror_mask_dstpool,
9323                         (void *)&cmd_mirror_mask_poolid,
9324                         (void *)&cmd_mirror_mask_on,
9325                         NULL,
9326                 },
9327 };
9328
9329 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9330 struct cmd_set_mirror_link_result {
9331         cmdline_fixed_string_t set;
9332         cmdline_fixed_string_t port;
9333         portid_t port_id;
9334         cmdline_fixed_string_t mirror;
9335         uint8_t rule_id;
9336         cmdline_fixed_string_t what;
9337         cmdline_fixed_string_t dstpool;
9338         uint8_t dstpool_id;
9339         cmdline_fixed_string_t on;
9340 };
9341
9342 cmdline_parse_token_string_t cmd_mirror_link_set =
9343         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9344                                  set, "set");
9345 cmdline_parse_token_string_t cmd_mirror_link_port =
9346         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9347                                 port, "port");
9348 cmdline_parse_token_num_t cmd_mirror_link_portid =
9349         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9350                                 port_id, UINT16);
9351 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9352         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9353                                 mirror, "mirror-rule");
9354 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9355         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9356                             rule_id, UINT8);
9357 cmdline_parse_token_string_t cmd_mirror_link_what =
9358         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9359                                 what, "uplink-mirror#downlink-mirror");
9360 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9361         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9362                                 dstpool, "dst-pool");
9363 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9364         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9365                                 dstpool_id, UINT8);
9366 cmdline_parse_token_string_t cmd_mirror_link_on =
9367         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9368                                 on, "on#off");
9369
9370 static void
9371 cmd_set_mirror_link_parsed(void *parsed_result,
9372                        __rte_unused struct cmdline *cl,
9373                        __rte_unused void *data)
9374 {
9375         int ret;
9376         struct cmd_set_mirror_link_result *res = parsed_result;
9377         struct rte_eth_mirror_conf mr_conf;
9378
9379         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9380         if (!strcmp(res->what, "uplink-mirror"))
9381                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9382         else
9383                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9384
9385         mr_conf.dst_pool = res->dstpool_id;
9386
9387         if (!strcmp(res->on, "on"))
9388                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9389                                                 res->rule_id, 1);
9390         else
9391                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9392                                                 res->rule_id, 0);
9393
9394         /* check the return value and print it if is < 0 */
9395         if (ret < 0)
9396                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9397
9398 }
9399
9400 cmdline_parse_inst_t cmd_set_mirror_link = {
9401                 .f = cmd_set_mirror_link_parsed,
9402                 .data = NULL,
9403                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9404                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9405                 .tokens = {
9406                         (void *)&cmd_mirror_link_set,
9407                         (void *)&cmd_mirror_link_port,
9408                         (void *)&cmd_mirror_link_portid,
9409                         (void *)&cmd_mirror_link_mirror,
9410                         (void *)&cmd_mirror_link_ruleid,
9411                         (void *)&cmd_mirror_link_what,
9412                         (void *)&cmd_mirror_link_dstpool,
9413                         (void *)&cmd_mirror_link_poolid,
9414                         (void *)&cmd_mirror_link_on,
9415                         NULL,
9416                 },
9417 };
9418
9419 /* *** RESET VM MIRROR RULE *** */
9420 struct cmd_rm_mirror_rule_result {
9421         cmdline_fixed_string_t reset;
9422         cmdline_fixed_string_t port;
9423         portid_t port_id;
9424         cmdline_fixed_string_t mirror;
9425         uint8_t rule_id;
9426 };
9427
9428 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9429         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9430                                  reset, "reset");
9431 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9432         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9433                                 port, "port");
9434 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9435         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9436                                 port_id, UINT16);
9437 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9438         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9439                                 mirror, "mirror-rule");
9440 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9441         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9442                                 rule_id, UINT8);
9443
9444 static void
9445 cmd_reset_mirror_rule_parsed(void *parsed_result,
9446                        __rte_unused struct cmdline *cl,
9447                        __rte_unused void *data)
9448 {
9449         int ret;
9450         struct cmd_set_mirror_link_result *res = parsed_result;
9451         /* check rule_id */
9452         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9453         if(ret < 0)
9454                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9455 }
9456
9457 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9458                 .f = cmd_reset_mirror_rule_parsed,
9459                 .data = NULL,
9460                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9461                 .tokens = {
9462                         (void *)&cmd_rm_mirror_rule_reset,
9463                         (void *)&cmd_rm_mirror_rule_port,
9464                         (void *)&cmd_rm_mirror_rule_portid,
9465                         (void *)&cmd_rm_mirror_rule_mirror,
9466                         (void *)&cmd_rm_mirror_rule_ruleid,
9467                         NULL,
9468                 },
9469 };
9470
9471 /* ******************************************************************************** */
9472
9473 struct cmd_dump_result {
9474         cmdline_fixed_string_t dump;
9475 };
9476
9477 static void
9478 dump_struct_sizes(void)
9479 {
9480 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9481         DUMP_SIZE(struct rte_mbuf);
9482         DUMP_SIZE(struct rte_mempool);
9483         DUMP_SIZE(struct rte_ring);
9484 #undef DUMP_SIZE
9485 }
9486
9487
9488 /* Dump the socket memory statistics on console */
9489 static void
9490 dump_socket_mem(FILE *f)
9491 {
9492         struct rte_malloc_socket_stats socket_stats;
9493         unsigned int i;
9494         size_t total = 0;
9495         size_t alloc = 0;
9496         size_t free = 0;
9497         unsigned int n_alloc = 0;
9498         unsigned int n_free = 0;
9499         static size_t last_allocs;
9500         static size_t last_total;
9501
9502
9503         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9504                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9505                     !socket_stats.heap_totalsz_bytes)
9506                         continue;
9507                 total += socket_stats.heap_totalsz_bytes;
9508                 alloc += socket_stats.heap_allocsz_bytes;
9509                 free += socket_stats.heap_freesz_bytes;
9510                 n_alloc += socket_stats.alloc_count;
9511                 n_free += socket_stats.free_count;
9512                 fprintf(f,
9513                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9514                         i,
9515                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9516                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9517                         (double)socket_stats.heap_allocsz_bytes * 100 /
9518                         (double)socket_stats.heap_totalsz_bytes,
9519                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9520                         socket_stats.alloc_count,
9521                         socket_stats.free_count);
9522         }
9523         fprintf(f,
9524                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9525                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9526                 (double)alloc * 100 / (double)total,
9527                 (double)free / (1024 * 1024),
9528                 n_alloc, n_free);
9529         if (last_allocs)
9530                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9531                         ((double)total - (double)last_total) / (1024 * 1024),
9532                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9533         last_allocs = alloc;
9534         last_total = total;
9535 }
9536
9537 static void cmd_dump_parsed(void *parsed_result,
9538                             __rte_unused struct cmdline *cl,
9539                             __rte_unused void *data)
9540 {
9541         struct cmd_dump_result *res = parsed_result;
9542
9543         if (!strcmp(res->dump, "dump_physmem"))
9544                 rte_dump_physmem_layout(stdout);
9545         else if (!strcmp(res->dump, "dump_socket_mem"))
9546                 dump_socket_mem(stdout);
9547         else if (!strcmp(res->dump, "dump_memzone"))
9548                 rte_memzone_dump(stdout);
9549         else if (!strcmp(res->dump, "dump_struct_sizes"))
9550                 dump_struct_sizes();
9551         else if (!strcmp(res->dump, "dump_ring"))
9552                 rte_ring_list_dump(stdout);
9553         else if (!strcmp(res->dump, "dump_mempool"))
9554                 rte_mempool_list_dump(stdout);
9555         else if (!strcmp(res->dump, "dump_devargs"))
9556                 rte_devargs_dump(stdout);
9557         else if (!strcmp(res->dump, "dump_log_types"))
9558                 rte_log_dump(stdout);
9559 }
9560
9561 cmdline_parse_token_string_t cmd_dump_dump =
9562         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9563                 "dump_physmem#"
9564                 "dump_memzone#"
9565                 "dump_socket_mem#"
9566                 "dump_struct_sizes#"
9567                 "dump_ring#"
9568                 "dump_mempool#"
9569                 "dump_devargs#"
9570                 "dump_log_types");
9571
9572 cmdline_parse_inst_t cmd_dump = {
9573         .f = cmd_dump_parsed,  /* function to call */
9574         .data = NULL,      /* 2nd arg of func */
9575         .help_str = "Dump status",
9576         .tokens = {        /* token list, NULL terminated */
9577                 (void *)&cmd_dump_dump,
9578                 NULL,
9579         },
9580 };
9581
9582 /* ******************************************************************************** */
9583
9584 struct cmd_dump_one_result {
9585         cmdline_fixed_string_t dump;
9586         cmdline_fixed_string_t name;
9587 };
9588
9589 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9590                                 __rte_unused void *data)
9591 {
9592         struct cmd_dump_one_result *res = parsed_result;
9593
9594         if (!strcmp(res->dump, "dump_ring")) {
9595                 struct rte_ring *r;
9596                 r = rte_ring_lookup(res->name);
9597                 if (r == NULL) {
9598                         cmdline_printf(cl, "Cannot find ring\n");
9599                         return;
9600                 }
9601                 rte_ring_dump(stdout, r);
9602         } else if (!strcmp(res->dump, "dump_mempool")) {
9603                 struct rte_mempool *mp;
9604                 mp = rte_mempool_lookup(res->name);
9605                 if (mp == NULL) {
9606                         cmdline_printf(cl, "Cannot find mempool\n");
9607                         return;
9608                 }
9609                 rte_mempool_dump(stdout, mp);
9610         }
9611 }
9612
9613 cmdline_parse_token_string_t cmd_dump_one_dump =
9614         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9615                                  "dump_ring#dump_mempool");
9616
9617 cmdline_parse_token_string_t cmd_dump_one_name =
9618         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9619
9620 cmdline_parse_inst_t cmd_dump_one = {
9621         .f = cmd_dump_one_parsed,  /* function to call */
9622         .data = NULL,      /* 2nd arg of func */
9623         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9624         .tokens = {        /* token list, NULL terminated */
9625                 (void *)&cmd_dump_one_dump,
9626                 (void *)&cmd_dump_one_name,
9627                 NULL,
9628         },
9629 };
9630
9631 /* *** queue region set *** */
9632 struct cmd_queue_region_result {
9633         cmdline_fixed_string_t set;
9634         cmdline_fixed_string_t port;
9635         portid_t port_id;
9636         cmdline_fixed_string_t cmd;
9637         cmdline_fixed_string_t region;
9638         uint8_t  region_id;
9639         cmdline_fixed_string_t queue_start_index;
9640         uint8_t  queue_id;
9641         cmdline_fixed_string_t queue_num;
9642         uint8_t  queue_num_value;
9643 };
9644
9645 static void
9646 cmd_queue_region_parsed(void *parsed_result,
9647                         __rte_unused struct cmdline *cl,
9648                         __rte_unused void *data)
9649 {
9650         struct cmd_queue_region_result *res = parsed_result;
9651         int ret = -ENOTSUP;
9652 #ifdef RTE_NET_I40E
9653         struct rte_pmd_i40e_queue_region_conf region_conf;
9654         enum rte_pmd_i40e_queue_region_op op_type;
9655 #endif
9656
9657         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9658                 return;
9659
9660 #ifdef RTE_NET_I40E
9661         memset(&region_conf, 0, sizeof(region_conf));
9662         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9663         region_conf.region_id = res->region_id;
9664         region_conf.queue_num = res->queue_num_value;
9665         region_conf.queue_start_index = res->queue_id;
9666
9667         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9668                                 op_type, &region_conf);
9669 #endif
9670
9671         switch (ret) {
9672         case 0:
9673                 break;
9674         case -ENOTSUP:
9675                 printf("function not implemented or supported\n");
9676                 break;
9677         default:
9678                 printf("queue region config error: (%s)\n", strerror(-ret));
9679         }
9680 }
9681
9682 cmdline_parse_token_string_t cmd_queue_region_set =
9683 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9684                 set, "set");
9685 cmdline_parse_token_string_t cmd_queue_region_port =
9686         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9687 cmdline_parse_token_num_t cmd_queue_region_port_id =
9688         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9689                                 port_id, UINT16);
9690 cmdline_parse_token_string_t cmd_queue_region_cmd =
9691         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9692                                  cmd, "queue-region");
9693 cmdline_parse_token_string_t cmd_queue_region_id =
9694         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9695                                 region, "region_id");
9696 cmdline_parse_token_num_t cmd_queue_region_index =
9697         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9698                                 region_id, UINT8);
9699 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9700         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9701                                 queue_start_index, "queue_start_index");
9702 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9703         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9704                                 queue_id, UINT8);
9705 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9706         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9707                                 queue_num, "queue_num");
9708 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9709         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9710                                 queue_num_value, UINT8);
9711
9712 cmdline_parse_inst_t cmd_queue_region = {
9713         .f = cmd_queue_region_parsed,
9714         .data = NULL,
9715         .help_str = "set port <port_id> queue-region region_id <value> "
9716                 "queue_start_index <value> queue_num <value>: Set a queue region",
9717         .tokens = {
9718                 (void *)&cmd_queue_region_set,
9719                 (void *)&cmd_queue_region_port,
9720                 (void *)&cmd_queue_region_port_id,
9721                 (void *)&cmd_queue_region_cmd,
9722                 (void *)&cmd_queue_region_id,
9723                 (void *)&cmd_queue_region_index,
9724                 (void *)&cmd_queue_region_queue_start_index,
9725                 (void *)&cmd_queue_region_queue_id,
9726                 (void *)&cmd_queue_region_queue_num,
9727                 (void *)&cmd_queue_region_queue_num_value,
9728                 NULL,
9729         },
9730 };
9731
9732 /* *** queue region and flowtype set *** */
9733 struct cmd_region_flowtype_result {
9734         cmdline_fixed_string_t set;
9735         cmdline_fixed_string_t port;
9736         portid_t port_id;
9737         cmdline_fixed_string_t cmd;
9738         cmdline_fixed_string_t region;
9739         uint8_t  region_id;
9740         cmdline_fixed_string_t flowtype;
9741         uint8_t  flowtype_id;
9742 };
9743
9744 static void
9745 cmd_region_flowtype_parsed(void *parsed_result,
9746                         __rte_unused struct cmdline *cl,
9747                         __rte_unused void *data)
9748 {
9749         struct cmd_region_flowtype_result *res = parsed_result;
9750         int ret = -ENOTSUP;
9751 #ifdef RTE_NET_I40E
9752         struct rte_pmd_i40e_queue_region_conf region_conf;
9753         enum rte_pmd_i40e_queue_region_op op_type;
9754 #endif
9755
9756         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9757                 return;
9758
9759 #ifdef RTE_NET_I40E
9760         memset(&region_conf, 0, sizeof(region_conf));
9761
9762         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9763         region_conf.region_id = res->region_id;
9764         region_conf.hw_flowtype = res->flowtype_id;
9765
9766         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9767                         op_type, &region_conf);
9768 #endif
9769
9770         switch (ret) {
9771         case 0:
9772                 break;
9773         case -ENOTSUP:
9774                 printf("function not implemented or supported\n");
9775                 break;
9776         default:
9777                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9778         }
9779 }
9780
9781 cmdline_parse_token_string_t cmd_region_flowtype_set =
9782 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9783                                 set, "set");
9784 cmdline_parse_token_string_t cmd_region_flowtype_port =
9785         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9786                                 port, "port");
9787 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9788         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9789                                 port_id, UINT16);
9790 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9791         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9792                                 cmd, "queue-region");
9793 cmdline_parse_token_string_t cmd_region_flowtype_index =
9794         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9795                                 region, "region_id");
9796 cmdline_parse_token_num_t cmd_region_flowtype_id =
9797         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9798                                 region_id, UINT8);
9799 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9800         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9801                                 flowtype, "flowtype");
9802 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9803         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9804                                 flowtype_id, UINT8);
9805 cmdline_parse_inst_t cmd_region_flowtype = {
9806         .f = cmd_region_flowtype_parsed,
9807         .data = NULL,
9808         .help_str = "set port <port_id> queue-region region_id <value> "
9809                 "flowtype <value>: Set a flowtype region index",
9810         .tokens = {
9811                 (void *)&cmd_region_flowtype_set,
9812                 (void *)&cmd_region_flowtype_port,
9813                 (void *)&cmd_region_flowtype_port_index,
9814                 (void *)&cmd_region_flowtype_cmd,
9815                 (void *)&cmd_region_flowtype_index,
9816                 (void *)&cmd_region_flowtype_id,
9817                 (void *)&cmd_region_flowtype_flow_index,
9818                 (void *)&cmd_region_flowtype_flow_id,
9819                 NULL,
9820         },
9821 };
9822
9823 /* *** User Priority (UP) to queue region (region_id) set *** */
9824 struct cmd_user_priority_region_result {
9825         cmdline_fixed_string_t set;
9826         cmdline_fixed_string_t port;
9827         portid_t port_id;
9828         cmdline_fixed_string_t cmd;
9829         cmdline_fixed_string_t user_priority;
9830         uint8_t  user_priority_id;
9831         cmdline_fixed_string_t region;
9832         uint8_t  region_id;
9833 };
9834
9835 static void
9836 cmd_user_priority_region_parsed(void *parsed_result,
9837                         __rte_unused struct cmdline *cl,
9838                         __rte_unused void *data)
9839 {
9840         struct cmd_user_priority_region_result *res = parsed_result;
9841         int ret = -ENOTSUP;
9842 #ifdef RTE_NET_I40E
9843         struct rte_pmd_i40e_queue_region_conf region_conf;
9844         enum rte_pmd_i40e_queue_region_op op_type;
9845 #endif
9846
9847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9848                 return;
9849
9850 #ifdef RTE_NET_I40E
9851         memset(&region_conf, 0, sizeof(region_conf));
9852         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9853         region_conf.user_priority = res->user_priority_id;
9854         region_conf.region_id = res->region_id;
9855
9856         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9857                                 op_type, &region_conf);
9858 #endif
9859
9860         switch (ret) {
9861         case 0:
9862                 break;
9863         case -ENOTSUP:
9864                 printf("function not implemented or supported\n");
9865                 break;
9866         default:
9867                 printf("user_priority region config error: (%s)\n",
9868                                 strerror(-ret));
9869         }
9870 }
9871
9872 cmdline_parse_token_string_t cmd_user_priority_region_set =
9873         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9874                                 set, "set");
9875 cmdline_parse_token_string_t cmd_user_priority_region_port =
9876         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9877                                 port, "port");
9878 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9879         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9880                                 port_id, UINT16);
9881 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9882         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9883                                 cmd, "queue-region");
9884 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9885         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9886                                 user_priority, "UP");
9887 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9888         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9889                                 user_priority_id, UINT8);
9890 cmdline_parse_token_string_t cmd_user_priority_region_region =
9891         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9892                                 region, "region_id");
9893 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9894         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9895                                 region_id, UINT8);
9896
9897 cmdline_parse_inst_t cmd_user_priority_region = {
9898         .f = cmd_user_priority_region_parsed,
9899         .data = NULL,
9900         .help_str = "set port <port_id> queue-region UP <value> "
9901                 "region_id <value>: Set the mapping of User Priority (UP) "
9902                 "to queue region (region_id) ",
9903         .tokens = {
9904                 (void *)&cmd_user_priority_region_set,
9905                 (void *)&cmd_user_priority_region_port,
9906                 (void *)&cmd_user_priority_region_port_index,
9907                 (void *)&cmd_user_priority_region_cmd,
9908                 (void *)&cmd_user_priority_region_UP,
9909                 (void *)&cmd_user_priority_region_UP_id,
9910                 (void *)&cmd_user_priority_region_region,
9911                 (void *)&cmd_user_priority_region_region_id,
9912                 NULL,
9913         },
9914 };
9915
9916 /* *** flush all queue region related configuration *** */
9917 struct cmd_flush_queue_region_result {
9918         cmdline_fixed_string_t set;
9919         cmdline_fixed_string_t port;
9920         portid_t port_id;
9921         cmdline_fixed_string_t cmd;
9922         cmdline_fixed_string_t flush;
9923         cmdline_fixed_string_t what;
9924 };
9925
9926 static void
9927 cmd_flush_queue_region_parsed(void *parsed_result,
9928                         __rte_unused struct cmdline *cl,
9929                         __rte_unused void *data)
9930 {
9931         struct cmd_flush_queue_region_result *res = parsed_result;
9932         int ret = -ENOTSUP;
9933 #ifdef RTE_NET_I40E
9934         struct rte_pmd_i40e_queue_region_conf region_conf;
9935         enum rte_pmd_i40e_queue_region_op op_type;
9936 #endif
9937
9938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9939                 return;
9940
9941 #ifdef RTE_NET_I40E
9942         memset(&region_conf, 0, sizeof(region_conf));
9943
9944         if (strcmp(res->what, "on") == 0)
9945                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9946         else
9947                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9948
9949         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9950                                 op_type, &region_conf);
9951 #endif
9952
9953         switch (ret) {
9954         case 0:
9955                 break;
9956         case -ENOTSUP:
9957                 printf("function not implemented or supported\n");
9958                 break;
9959         default:
9960                 printf("queue region config flush error: (%s)\n",
9961                                 strerror(-ret));
9962         }
9963 }
9964
9965 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9966         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9967                                 set, "set");
9968 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9969         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9970                                 port, "port");
9971 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9972         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9973                                 port_id, UINT16);
9974 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9975         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9976                                 cmd, "queue-region");
9977 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9978         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9979                                 flush, "flush");
9980 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9981         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9982                                 what, "on#off");
9983
9984 cmdline_parse_inst_t cmd_flush_queue_region = {
9985         .f = cmd_flush_queue_region_parsed,
9986         .data = NULL,
9987         .help_str = "set port <port_id> queue-region flush on|off"
9988                 ": flush all queue region related configuration",
9989         .tokens = {
9990                 (void *)&cmd_flush_queue_region_set,
9991                 (void *)&cmd_flush_queue_region_port,
9992                 (void *)&cmd_flush_queue_region_port_index,
9993                 (void *)&cmd_flush_queue_region_cmd,
9994                 (void *)&cmd_flush_queue_region_flush,
9995                 (void *)&cmd_flush_queue_region_what,
9996                 NULL,
9997         },
9998 };
9999
10000 /* *** get all queue region related configuration info *** */
10001 struct cmd_show_queue_region_info {
10002         cmdline_fixed_string_t show;
10003         cmdline_fixed_string_t port;
10004         portid_t port_id;
10005         cmdline_fixed_string_t cmd;
10006 };
10007
10008 static void
10009 cmd_show_queue_region_info_parsed(void *parsed_result,
10010                         __rte_unused struct cmdline *cl,
10011                         __rte_unused void *data)
10012 {
10013         struct cmd_show_queue_region_info *res = parsed_result;
10014         int ret = -ENOTSUP;
10015 #ifdef RTE_NET_I40E
10016         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10017         enum rte_pmd_i40e_queue_region_op op_type;
10018 #endif
10019
10020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10021                 return;
10022
10023 #ifdef RTE_NET_I40E
10024         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10025
10026         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10027
10028         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10029                                         op_type, &rte_pmd_regions);
10030
10031         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10032 #endif
10033
10034         switch (ret) {
10035         case 0:
10036                 break;
10037         case -ENOTSUP:
10038                 printf("function not implemented or supported\n");
10039                 break;
10040         default:
10041                 printf("queue region config info show error: (%s)\n",
10042                                 strerror(-ret));
10043         }
10044 }
10045
10046 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10047 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10048                                 show, "show");
10049 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10050         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10051                                 port, "port");
10052 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10053         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10054                                 port_id, UINT16);
10055 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10056         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10057                                 cmd, "queue-region");
10058
10059 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10060         .f = cmd_show_queue_region_info_parsed,
10061         .data = NULL,
10062         .help_str = "show port <port_id> queue-region"
10063                 ": show all queue region related configuration info",
10064         .tokens = {
10065                 (void *)&cmd_show_queue_region_info_get,
10066                 (void *)&cmd_show_queue_region_info_port,
10067                 (void *)&cmd_show_queue_region_info_port_index,
10068                 (void *)&cmd_show_queue_region_info_cmd,
10069                 NULL,
10070         },
10071 };
10072
10073 /* *** Filters Control *** */
10074
10075 static uint16_t
10076 str2flowtype(char *string)
10077 {
10078         uint8_t i = 0;
10079         static const struct {
10080                 char str[32];
10081                 uint16_t type;
10082         } flowtype_str[] = {
10083                 {"raw", RTE_ETH_FLOW_RAW},
10084                 {"ipv4", RTE_ETH_FLOW_IPV4},
10085                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10086                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10087                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10088                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10089                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10090                 {"ipv6", RTE_ETH_FLOW_IPV6},
10091                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10092                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10093                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10094                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10095                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10096                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10097         };
10098
10099         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10100                 if (!strcmp(flowtype_str[i].str, string))
10101                         return flowtype_str[i].type;
10102         }
10103
10104         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10105                 return (uint16_t)atoi(string);
10106
10107         return RTE_ETH_FLOW_UNKNOWN;
10108 }
10109
10110 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10111 do { \
10112         if ((ip_addr).family == AF_INET) \
10113                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10114         else { \
10115                 printf("invalid parameter.\n"); \
10116                 return; \
10117         } \
10118 } while (0)
10119
10120 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10121 do { \
10122         if ((ip_addr).family == AF_INET6) \
10123                 rte_memcpy(&(ip), \
10124                                  &((ip_addr).addr.ipv6), \
10125                                  sizeof(struct in6_addr)); \
10126         else { \
10127                 printf("invalid parameter.\n"); \
10128                 return; \
10129         } \
10130 } while (0)
10131
10132 #ifdef RTE_NET_I40E
10133
10134 /* *** deal with flow director filter *** */
10135 struct cmd_flow_director_result {
10136         cmdline_fixed_string_t flow_director_filter;
10137         portid_t port_id;
10138         cmdline_fixed_string_t mode;
10139         cmdline_fixed_string_t mode_value;
10140         cmdline_fixed_string_t ops;
10141         cmdline_fixed_string_t flow;
10142         cmdline_fixed_string_t flow_type;
10143         cmdline_fixed_string_t drop;
10144         cmdline_fixed_string_t queue;
10145         uint16_t  queue_id;
10146         cmdline_fixed_string_t fd_id;
10147         uint32_t  fd_id_value;
10148         cmdline_fixed_string_t packet;
10149         char filepath[];
10150 };
10151
10152 static void
10153 cmd_flow_director_filter_parsed(void *parsed_result,
10154                           __rte_unused struct cmdline *cl,
10155                           __rte_unused void *data)
10156 {
10157         struct cmd_flow_director_result *res = parsed_result;
10158         int ret = 0;
10159         struct rte_pmd_i40e_flow_type_mapping
10160                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10161         struct rte_pmd_i40e_pkt_template_conf conf;
10162         uint16_t flow_type = str2flowtype(res->flow_type);
10163         uint16_t i, port = res->port_id;
10164         uint8_t add;
10165
10166         memset(&conf, 0, sizeof(conf));
10167
10168         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10169                 printf("Invalid flow type specified.\n");
10170                 return;
10171         }
10172         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10173                                                  mapping);
10174         if (ret)
10175                 return;
10176         if (mapping[flow_type].pctype == 0ULL) {
10177                 printf("Invalid flow type specified.\n");
10178                 return;
10179         }
10180         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10181                 if (mapping[flow_type].pctype & (1ULL << i)) {
10182                         conf.input.pctype = i;
10183                         break;
10184                 }
10185         }
10186
10187         conf.input.packet = open_file(res->filepath,
10188                                 &conf.input.length);
10189         if (!conf.input.packet)
10190                 return;
10191         if (!strcmp(res->drop, "drop"))
10192                 conf.action.behavior =
10193                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10194         else
10195                 conf.action.behavior =
10196                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10197         conf.action.report_status =
10198                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10199         conf.action.rx_queue = res->queue_id;
10200         conf.soft_id = res->fd_id_value;
10201         add  = strcmp(res->ops, "del") ? 1 : 0;
10202         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10203                                                         &conf,
10204                                                         add);
10205         if (ret < 0)
10206                 printf("flow director config error: (%s)\n",
10207                        strerror(-ret));
10208         close_file(conf.input.packet);
10209 }
10210
10211 cmdline_parse_token_string_t cmd_flow_director_filter =
10212         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10213                                  flow_director_filter, "flow_director_filter");
10214 cmdline_parse_token_num_t cmd_flow_director_port_id =
10215         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10216                               port_id, UINT16);
10217 cmdline_parse_token_string_t cmd_flow_director_ops =
10218         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10219                                  ops, "add#del#update");
10220 cmdline_parse_token_string_t cmd_flow_director_flow =
10221         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10222                                  flow, "flow");
10223 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10225                 flow_type, NULL);
10226 cmdline_parse_token_string_t cmd_flow_director_drop =
10227         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10228                                  drop, "drop#fwd");
10229 cmdline_parse_token_string_t cmd_flow_director_queue =
10230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10231                                  queue, "queue");
10232 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10233         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10234                               queue_id, UINT16);
10235 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10237                                  fd_id, "fd_id");
10238 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10239         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10240                               fd_id_value, UINT32);
10241
10242 cmdline_parse_token_string_t cmd_flow_director_mode =
10243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10244                                  mode, "mode");
10245 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10247                                  mode_value, "raw");
10248 cmdline_parse_token_string_t cmd_flow_director_packet =
10249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10250                                  packet, "packet");
10251 cmdline_parse_token_string_t cmd_flow_director_filepath =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  filepath, NULL);
10254
10255 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10256         .f = cmd_flow_director_filter_parsed,
10257         .data = NULL,
10258         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10259                 "director entry on NIC",
10260         .tokens = {
10261                 (void *)&cmd_flow_director_filter,
10262                 (void *)&cmd_flow_director_port_id,
10263                 (void *)&cmd_flow_director_mode,
10264                 (void *)&cmd_flow_director_mode_raw,
10265                 (void *)&cmd_flow_director_ops,
10266                 (void *)&cmd_flow_director_flow,
10267                 (void *)&cmd_flow_director_flow_type,
10268                 (void *)&cmd_flow_director_drop,
10269                 (void *)&cmd_flow_director_queue,
10270                 (void *)&cmd_flow_director_queue_id,
10271                 (void *)&cmd_flow_director_fd_id,
10272                 (void *)&cmd_flow_director_fd_id_value,
10273                 (void *)&cmd_flow_director_packet,
10274                 (void *)&cmd_flow_director_filepath,
10275                 NULL,
10276         },
10277 };
10278
10279 #endif /* RTE_NET_I40E */
10280
10281 /* *** deal with flow director mask *** */
10282 struct cmd_flow_director_mask_result {
10283         cmdline_fixed_string_t flow_director_mask;
10284         portid_t port_id;
10285         cmdline_fixed_string_t mode;
10286         cmdline_fixed_string_t mode_value;
10287         cmdline_fixed_string_t vlan;
10288         uint16_t vlan_mask;
10289         cmdline_fixed_string_t src_mask;
10290         cmdline_ipaddr_t ipv4_src;
10291         cmdline_ipaddr_t ipv6_src;
10292         uint16_t port_src;
10293         cmdline_fixed_string_t dst_mask;
10294         cmdline_ipaddr_t ipv4_dst;
10295         cmdline_ipaddr_t ipv6_dst;
10296         uint16_t port_dst;
10297         cmdline_fixed_string_t mac;
10298         uint8_t mac_addr_byte_mask;
10299         cmdline_fixed_string_t tunnel_id;
10300         uint32_t tunnel_id_mask;
10301         cmdline_fixed_string_t tunnel_type;
10302         uint8_t tunnel_type_mask;
10303 };
10304
10305 static void
10306 cmd_flow_director_mask_parsed(void *parsed_result,
10307                           __rte_unused struct cmdline *cl,
10308                           __rte_unused void *data)
10309 {
10310         struct cmd_flow_director_mask_result *res = parsed_result;
10311         struct rte_eth_fdir_masks *mask;
10312         struct rte_port *port;
10313
10314         port = &ports[res->port_id];
10315         /** Check if the port is not started **/
10316         if (port->port_status != RTE_PORT_STOPPED) {
10317                 printf("Please stop port %d first\n", res->port_id);
10318                 return;
10319         }
10320
10321         mask = &port->dev_conf.fdir_conf.mask;
10322
10323         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10324                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10325                         printf("Please set mode to MAC-VLAN.\n");
10326                         return;
10327                 }
10328
10329                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10330         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10331                 if (strcmp(res->mode_value, "Tunnel")) {
10332                         printf("Please set mode to Tunnel.\n");
10333                         return;
10334                 }
10335
10336                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10337                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10338                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10339                 mask->tunnel_type_mask = res->tunnel_type_mask;
10340         } else {
10341                 if (strcmp(res->mode_value, "IP")) {
10342                         printf("Please set mode to IP.\n");
10343                         return;
10344                 }
10345
10346                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10347                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10348                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10349                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10350                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10351                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10352                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10353         }
10354
10355         cmd_reconfig_device_queue(res->port_id, 1, 1);
10356 }
10357
10358 cmdline_parse_token_string_t cmd_flow_director_mask =
10359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10360                                  flow_director_mask, "flow_director_mask");
10361 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10362         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10363                               port_id, UINT16);
10364 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10366                                  vlan, "vlan");
10367 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10368         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10369                               vlan_mask, UINT16);
10370 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10372                                  src_mask, "src_mask");
10373 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10374         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10375                                  ipv4_src);
10376 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10377         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10378                                  ipv6_src);
10379 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10380         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10381                               port_src, UINT16);
10382 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10384                                  dst_mask, "dst_mask");
10385 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10386         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10387                                  ipv4_dst);
10388 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10389         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10390                                  ipv6_dst);
10391 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10392         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10393                               port_dst, UINT16);
10394
10395 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10397                                  mode, "mode");
10398 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  mode_value, "IP");
10401 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10402         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10403                                  mode_value, "MAC-VLAN");
10404 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10406                                  mode_value, "Tunnel");
10407 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10408         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10409                                  mac, "mac");
10410 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10411         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10412                               mac_addr_byte_mask, UINT8);
10413 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10415                                  tunnel_type, "tunnel-type");
10416 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10417         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10418                               tunnel_type_mask, UINT8);
10419 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10420         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10421                                  tunnel_id, "tunnel-id");
10422 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10423         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10424                               tunnel_id_mask, UINT32);
10425
10426 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10427         .f = cmd_flow_director_mask_parsed,
10428         .data = NULL,
10429         .help_str = "flow_director_mask ... : "
10430                 "Set IP mode flow director's mask on NIC",
10431         .tokens = {
10432                 (void *)&cmd_flow_director_mask,
10433                 (void *)&cmd_flow_director_mask_port_id,
10434                 (void *)&cmd_flow_director_mask_mode,
10435                 (void *)&cmd_flow_director_mask_mode_ip,
10436                 (void *)&cmd_flow_director_mask_vlan,
10437                 (void *)&cmd_flow_director_mask_vlan_value,
10438                 (void *)&cmd_flow_director_mask_src,
10439                 (void *)&cmd_flow_director_mask_ipv4_src,
10440                 (void *)&cmd_flow_director_mask_ipv6_src,
10441                 (void *)&cmd_flow_director_mask_port_src,
10442                 (void *)&cmd_flow_director_mask_dst,
10443                 (void *)&cmd_flow_director_mask_ipv4_dst,
10444                 (void *)&cmd_flow_director_mask_ipv6_dst,
10445                 (void *)&cmd_flow_director_mask_port_dst,
10446                 NULL,
10447         },
10448 };
10449
10450 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10451         .f = cmd_flow_director_mask_parsed,
10452         .data = NULL,
10453         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10454                 "flow director's mask on NIC",
10455         .tokens = {
10456                 (void *)&cmd_flow_director_mask,
10457                 (void *)&cmd_flow_director_mask_port_id,
10458                 (void *)&cmd_flow_director_mask_mode,
10459                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10460                 (void *)&cmd_flow_director_mask_vlan,
10461                 (void *)&cmd_flow_director_mask_vlan_value,
10462                 NULL,
10463         },
10464 };
10465
10466 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10467         .f = cmd_flow_director_mask_parsed,
10468         .data = NULL,
10469         .help_str = "flow_director_mask ... : Set tunnel mode "
10470                 "flow director's mask on NIC",
10471         .tokens = {
10472                 (void *)&cmd_flow_director_mask,
10473                 (void *)&cmd_flow_director_mask_port_id,
10474                 (void *)&cmd_flow_director_mask_mode,
10475                 (void *)&cmd_flow_director_mask_mode_tunnel,
10476                 (void *)&cmd_flow_director_mask_vlan,
10477                 (void *)&cmd_flow_director_mask_vlan_value,
10478                 (void *)&cmd_flow_director_mask_mac,
10479                 (void *)&cmd_flow_director_mask_mac_value,
10480                 (void *)&cmd_flow_director_mask_tunnel_type,
10481                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10482                 (void *)&cmd_flow_director_mask_tunnel_id,
10483                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10484                 NULL,
10485         },
10486 };
10487
10488 /* *** deal with flow director flexible payload configuration *** */
10489 struct cmd_flow_director_flexpayload_result {
10490         cmdline_fixed_string_t flow_director_flexpayload;
10491         portid_t port_id;
10492         cmdline_fixed_string_t payload_layer;
10493         cmdline_fixed_string_t payload_cfg;
10494 };
10495
10496 static inline int
10497 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10498 {
10499         char s[256];
10500         const char *p, *p0 = q_arg;
10501         char *end;
10502         unsigned long int_fld;
10503         char *str_fld[max_num];
10504         int i;
10505         unsigned size;
10506         int ret = -1;
10507
10508         p = strchr(p0, '(');
10509         if (p == NULL)
10510                 return -1;
10511         ++p;
10512         p0 = strchr(p, ')');
10513         if (p0 == NULL)
10514                 return -1;
10515
10516         size = p0 - p;
10517         if (size >= sizeof(s))
10518                 return -1;
10519
10520         snprintf(s, sizeof(s), "%.*s", size, p);
10521         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10522         if (ret < 0 || ret > max_num)
10523                 return -1;
10524         for (i = 0; i < ret; i++) {
10525                 errno = 0;
10526                 int_fld = strtoul(str_fld[i], &end, 0);
10527                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10528                         return -1;
10529                 offsets[i] = (uint16_t)int_fld;
10530         }
10531         return ret;
10532 }
10533
10534 static void
10535 cmd_flow_director_flxpld_parsed(void *parsed_result,
10536                           __rte_unused struct cmdline *cl,
10537                           __rte_unused void *data)
10538 {
10539         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10540         struct rte_eth_flex_payload_cfg flex_cfg;
10541         struct rte_port *port;
10542         int ret = 0;
10543
10544         port = &ports[res->port_id];
10545         /** Check if the port is not started **/
10546         if (port->port_status != RTE_PORT_STOPPED) {
10547                 printf("Please stop port %d first\n", res->port_id);
10548                 return;
10549         }
10550
10551         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10552
10553         if (!strcmp(res->payload_layer, "raw"))
10554                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10555         else if (!strcmp(res->payload_layer, "l2"))
10556                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10557         else if (!strcmp(res->payload_layer, "l3"))
10558                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10559         else if (!strcmp(res->payload_layer, "l4"))
10560                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10561
10562         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10563                             RTE_ETH_FDIR_MAX_FLEXLEN);
10564         if (ret < 0) {
10565                 printf("error: Cannot parse flex payload input.\n");
10566                 return;
10567         }
10568
10569         fdir_set_flex_payload(res->port_id, &flex_cfg);
10570         cmd_reconfig_device_queue(res->port_id, 1, 1);
10571 }
10572
10573 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10574         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10575                                  flow_director_flexpayload,
10576                                  "flow_director_flex_payload");
10577 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10578         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10579                               port_id, UINT16);
10580 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10582                                  payload_layer, "raw#l2#l3#l4");
10583 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10585                                  payload_cfg, NULL);
10586
10587 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10588         .f = cmd_flow_director_flxpld_parsed,
10589         .data = NULL,
10590         .help_str = "flow_director_flexpayload ... : "
10591                 "Set flow director's flex payload on NIC",
10592         .tokens = {
10593                 (void *)&cmd_flow_director_flexpayload,
10594                 (void *)&cmd_flow_director_flexpayload_port_id,
10595                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10596                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10597                 NULL,
10598         },
10599 };
10600
10601 /* Generic flow interface command. */
10602 extern cmdline_parse_inst_t cmd_flow;
10603
10604 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10605 struct cmd_mcast_addr_result {
10606         cmdline_fixed_string_t mcast_addr_cmd;
10607         cmdline_fixed_string_t what;
10608         uint16_t port_num;
10609         struct rte_ether_addr mc_addr;
10610 };
10611
10612 static void cmd_mcast_addr_parsed(void *parsed_result,
10613                 __rte_unused struct cmdline *cl,
10614                 __rte_unused void *data)
10615 {
10616         struct cmd_mcast_addr_result *res = parsed_result;
10617
10618         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10619                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10620                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10621                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10622                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10623                 return;
10624         }
10625         if (strcmp(res->what, "add") == 0)
10626                 mcast_addr_add(res->port_num, &res->mc_addr);
10627         else
10628                 mcast_addr_remove(res->port_num, &res->mc_addr);
10629 }
10630
10631 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10632         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10633                                  mcast_addr_cmd, "mcast_addr");
10634 cmdline_parse_token_string_t cmd_mcast_addr_what =
10635         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10636                                  "add#remove");
10637 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10638         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
10639 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10640         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10641
10642 cmdline_parse_inst_t cmd_mcast_addr = {
10643         .f = cmd_mcast_addr_parsed,
10644         .data = (void *)0,
10645         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10646                 "Add/Remove multicast MAC address on port_id",
10647         .tokens = {
10648                 (void *)&cmd_mcast_addr_cmd,
10649                 (void *)&cmd_mcast_addr_what,
10650                 (void *)&cmd_mcast_addr_portnum,
10651                 (void *)&cmd_mcast_addr_addr,
10652                 NULL,
10653         },
10654 };
10655
10656 /* vf vlan anti spoof configuration */
10657
10658 /* Common result structure for vf vlan anti spoof */
10659 struct cmd_vf_vlan_anti_spoof_result {
10660         cmdline_fixed_string_t set;
10661         cmdline_fixed_string_t vf;
10662         cmdline_fixed_string_t vlan;
10663         cmdline_fixed_string_t antispoof;
10664         portid_t port_id;
10665         uint32_t vf_id;
10666         cmdline_fixed_string_t on_off;
10667 };
10668
10669 /* Common CLI fields for vf vlan anti spoof enable disable */
10670 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10671         TOKEN_STRING_INITIALIZER
10672                 (struct cmd_vf_vlan_anti_spoof_result,
10673                  set, "set");
10674 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10675         TOKEN_STRING_INITIALIZER
10676                 (struct cmd_vf_vlan_anti_spoof_result,
10677                  vf, "vf");
10678 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10679         TOKEN_STRING_INITIALIZER
10680                 (struct cmd_vf_vlan_anti_spoof_result,
10681                  vlan, "vlan");
10682 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10683         TOKEN_STRING_INITIALIZER
10684                 (struct cmd_vf_vlan_anti_spoof_result,
10685                  antispoof, "antispoof");
10686 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10687         TOKEN_NUM_INITIALIZER
10688                 (struct cmd_vf_vlan_anti_spoof_result,
10689                  port_id, UINT16);
10690 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10691         TOKEN_NUM_INITIALIZER
10692                 (struct cmd_vf_vlan_anti_spoof_result,
10693                  vf_id, UINT32);
10694 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10695         TOKEN_STRING_INITIALIZER
10696                 (struct cmd_vf_vlan_anti_spoof_result,
10697                  on_off, "on#off");
10698
10699 static void
10700 cmd_set_vf_vlan_anti_spoof_parsed(
10701         void *parsed_result,
10702         __rte_unused struct cmdline *cl,
10703         __rte_unused void *data)
10704 {
10705         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10706         int ret = -ENOTSUP;
10707
10708         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10709
10710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10711                 return;
10712
10713 #ifdef RTE_NET_IXGBE
10714         if (ret == -ENOTSUP)
10715                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10716                                 res->vf_id, is_on);
10717 #endif
10718 #ifdef RTE_NET_I40E
10719         if (ret == -ENOTSUP)
10720                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10721                                 res->vf_id, is_on);
10722 #endif
10723 #ifdef RTE_NET_BNXT
10724         if (ret == -ENOTSUP)
10725                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10726                                 res->vf_id, is_on);
10727 #endif
10728
10729         switch (ret) {
10730         case 0:
10731                 break;
10732         case -EINVAL:
10733                 printf("invalid vf_id %d\n", res->vf_id);
10734                 break;
10735         case -ENODEV:
10736                 printf("invalid port_id %d\n", res->port_id);
10737                 break;
10738         case -ENOTSUP:
10739                 printf("function not implemented\n");
10740                 break;
10741         default:
10742                 printf("programming error: (%s)\n", strerror(-ret));
10743         }
10744 }
10745
10746 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10747         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10748         .data = NULL,
10749         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10750         .tokens = {
10751                 (void *)&cmd_vf_vlan_anti_spoof_set,
10752                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10753                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10754                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10755                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10756                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10757                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10758                 NULL,
10759         },
10760 };
10761
10762 /* vf mac anti spoof configuration */
10763
10764 /* Common result structure for vf mac anti spoof */
10765 struct cmd_vf_mac_anti_spoof_result {
10766         cmdline_fixed_string_t set;
10767         cmdline_fixed_string_t vf;
10768         cmdline_fixed_string_t mac;
10769         cmdline_fixed_string_t antispoof;
10770         portid_t port_id;
10771         uint32_t vf_id;
10772         cmdline_fixed_string_t on_off;
10773 };
10774
10775 /* Common CLI fields for vf mac anti spoof enable disable */
10776 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10777         TOKEN_STRING_INITIALIZER
10778                 (struct cmd_vf_mac_anti_spoof_result,
10779                  set, "set");
10780 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10781         TOKEN_STRING_INITIALIZER
10782                 (struct cmd_vf_mac_anti_spoof_result,
10783                  vf, "vf");
10784 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10785         TOKEN_STRING_INITIALIZER
10786                 (struct cmd_vf_mac_anti_spoof_result,
10787                  mac, "mac");
10788 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10789         TOKEN_STRING_INITIALIZER
10790                 (struct cmd_vf_mac_anti_spoof_result,
10791                  antispoof, "antispoof");
10792 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10793         TOKEN_NUM_INITIALIZER
10794                 (struct cmd_vf_mac_anti_spoof_result,
10795                  port_id, UINT16);
10796 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10797         TOKEN_NUM_INITIALIZER
10798                 (struct cmd_vf_mac_anti_spoof_result,
10799                  vf_id, UINT32);
10800 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10801         TOKEN_STRING_INITIALIZER
10802                 (struct cmd_vf_mac_anti_spoof_result,
10803                  on_off, "on#off");
10804
10805 static void
10806 cmd_set_vf_mac_anti_spoof_parsed(
10807         void *parsed_result,
10808         __rte_unused struct cmdline *cl,
10809         __rte_unused void *data)
10810 {
10811         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10812         int ret = -ENOTSUP;
10813
10814         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10815
10816         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10817                 return;
10818
10819 #ifdef RTE_NET_IXGBE
10820         if (ret == -ENOTSUP)
10821                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10822                         res->vf_id, is_on);
10823 #endif
10824 #ifdef RTE_NET_I40E
10825         if (ret == -ENOTSUP)
10826                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10827                         res->vf_id, is_on);
10828 #endif
10829 #ifdef RTE_NET_BNXT
10830         if (ret == -ENOTSUP)
10831                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10832                         res->vf_id, is_on);
10833 #endif
10834
10835         switch (ret) {
10836         case 0:
10837                 break;
10838         case -EINVAL:
10839                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10840                 break;
10841         case -ENODEV:
10842                 printf("invalid port_id %d\n", res->port_id);
10843                 break;
10844         case -ENOTSUP:
10845                 printf("function not implemented\n");
10846                 break;
10847         default:
10848                 printf("programming error: (%s)\n", strerror(-ret));
10849         }
10850 }
10851
10852 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10853         .f = cmd_set_vf_mac_anti_spoof_parsed,
10854         .data = NULL,
10855         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10856         .tokens = {
10857                 (void *)&cmd_vf_mac_anti_spoof_set,
10858                 (void *)&cmd_vf_mac_anti_spoof_vf,
10859                 (void *)&cmd_vf_mac_anti_spoof_mac,
10860                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10861                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10862                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10863                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10864                 NULL,
10865         },
10866 };
10867
10868 /* vf vlan strip queue configuration */
10869
10870 /* Common result structure for vf mac anti spoof */
10871 struct cmd_vf_vlan_stripq_result {
10872         cmdline_fixed_string_t set;
10873         cmdline_fixed_string_t vf;
10874         cmdline_fixed_string_t vlan;
10875         cmdline_fixed_string_t stripq;
10876         portid_t port_id;
10877         uint16_t vf_id;
10878         cmdline_fixed_string_t on_off;
10879 };
10880
10881 /* Common CLI fields for vf vlan strip enable disable */
10882 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10883         TOKEN_STRING_INITIALIZER
10884                 (struct cmd_vf_vlan_stripq_result,
10885                  set, "set");
10886 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10887         TOKEN_STRING_INITIALIZER
10888                 (struct cmd_vf_vlan_stripq_result,
10889                  vf, "vf");
10890 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10891         TOKEN_STRING_INITIALIZER
10892                 (struct cmd_vf_vlan_stripq_result,
10893                  vlan, "vlan");
10894 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10895         TOKEN_STRING_INITIALIZER
10896                 (struct cmd_vf_vlan_stripq_result,
10897                  stripq, "stripq");
10898 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10899         TOKEN_NUM_INITIALIZER
10900                 (struct cmd_vf_vlan_stripq_result,
10901                  port_id, UINT16);
10902 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10903         TOKEN_NUM_INITIALIZER
10904                 (struct cmd_vf_vlan_stripq_result,
10905                  vf_id, UINT16);
10906 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10907         TOKEN_STRING_INITIALIZER
10908                 (struct cmd_vf_vlan_stripq_result,
10909                  on_off, "on#off");
10910
10911 static void
10912 cmd_set_vf_vlan_stripq_parsed(
10913         void *parsed_result,
10914         __rte_unused struct cmdline *cl,
10915         __rte_unused void *data)
10916 {
10917         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10918         int ret = -ENOTSUP;
10919
10920         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10921
10922         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10923                 return;
10924
10925 #ifdef RTE_NET_IXGBE
10926         if (ret == -ENOTSUP)
10927                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10928                         res->vf_id, is_on);
10929 #endif
10930 #ifdef RTE_NET_I40E
10931         if (ret == -ENOTSUP)
10932                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10933                         res->vf_id, is_on);
10934 #endif
10935 #ifdef RTE_NET_BNXT
10936         if (ret == -ENOTSUP)
10937                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10938                         res->vf_id, is_on);
10939 #endif
10940
10941         switch (ret) {
10942         case 0:
10943                 break;
10944         case -EINVAL:
10945                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10946                 break;
10947         case -ENODEV:
10948                 printf("invalid port_id %d\n", res->port_id);
10949                 break;
10950         case -ENOTSUP:
10951                 printf("function not implemented\n");
10952                 break;
10953         default:
10954                 printf("programming error: (%s)\n", strerror(-ret));
10955         }
10956 }
10957
10958 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10959         .f = cmd_set_vf_vlan_stripq_parsed,
10960         .data = NULL,
10961         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10962         .tokens = {
10963                 (void *)&cmd_vf_vlan_stripq_set,
10964                 (void *)&cmd_vf_vlan_stripq_vf,
10965                 (void *)&cmd_vf_vlan_stripq_vlan,
10966                 (void *)&cmd_vf_vlan_stripq_stripq,
10967                 (void *)&cmd_vf_vlan_stripq_port_id,
10968                 (void *)&cmd_vf_vlan_stripq_vf_id,
10969                 (void *)&cmd_vf_vlan_stripq_on_off,
10970                 NULL,
10971         },
10972 };
10973
10974 /* vf vlan insert configuration */
10975
10976 /* Common result structure for vf vlan insert */
10977 struct cmd_vf_vlan_insert_result {
10978         cmdline_fixed_string_t set;
10979         cmdline_fixed_string_t vf;
10980         cmdline_fixed_string_t vlan;
10981         cmdline_fixed_string_t insert;
10982         portid_t port_id;
10983         uint16_t vf_id;
10984         uint16_t vlan_id;
10985 };
10986
10987 /* Common CLI fields for vf vlan insert enable disable */
10988 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
10989         TOKEN_STRING_INITIALIZER
10990                 (struct cmd_vf_vlan_insert_result,
10991                  set, "set");
10992 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
10993         TOKEN_STRING_INITIALIZER
10994                 (struct cmd_vf_vlan_insert_result,
10995                  vf, "vf");
10996 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
10997         TOKEN_STRING_INITIALIZER
10998                 (struct cmd_vf_vlan_insert_result,
10999                  vlan, "vlan");
11000 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11001         TOKEN_STRING_INITIALIZER
11002                 (struct cmd_vf_vlan_insert_result,
11003                  insert, "insert");
11004 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11005         TOKEN_NUM_INITIALIZER
11006                 (struct cmd_vf_vlan_insert_result,
11007                  port_id, UINT16);
11008 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11009         TOKEN_NUM_INITIALIZER
11010                 (struct cmd_vf_vlan_insert_result,
11011                  vf_id, UINT16);
11012 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11013         TOKEN_NUM_INITIALIZER
11014                 (struct cmd_vf_vlan_insert_result,
11015                  vlan_id, UINT16);
11016
11017 static void
11018 cmd_set_vf_vlan_insert_parsed(
11019         void *parsed_result,
11020         __rte_unused struct cmdline *cl,
11021         __rte_unused void *data)
11022 {
11023         struct cmd_vf_vlan_insert_result *res = parsed_result;
11024         int ret = -ENOTSUP;
11025
11026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11027                 return;
11028
11029 #ifdef RTE_NET_IXGBE
11030         if (ret == -ENOTSUP)
11031                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11032                         res->vlan_id);
11033 #endif
11034 #ifdef RTE_NET_I40E
11035         if (ret == -ENOTSUP)
11036                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11037                         res->vlan_id);
11038 #endif
11039 #ifdef RTE_NET_BNXT
11040         if (ret == -ENOTSUP)
11041                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11042                         res->vlan_id);
11043 #endif
11044
11045         switch (ret) {
11046         case 0:
11047                 break;
11048         case -EINVAL:
11049                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11050                 break;
11051         case -ENODEV:
11052                 printf("invalid port_id %d\n", res->port_id);
11053                 break;
11054         case -ENOTSUP:
11055                 printf("function not implemented\n");
11056                 break;
11057         default:
11058                 printf("programming error: (%s)\n", strerror(-ret));
11059         }
11060 }
11061
11062 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11063         .f = cmd_set_vf_vlan_insert_parsed,
11064         .data = NULL,
11065         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11066         .tokens = {
11067                 (void *)&cmd_vf_vlan_insert_set,
11068                 (void *)&cmd_vf_vlan_insert_vf,
11069                 (void *)&cmd_vf_vlan_insert_vlan,
11070                 (void *)&cmd_vf_vlan_insert_insert,
11071                 (void *)&cmd_vf_vlan_insert_port_id,
11072                 (void *)&cmd_vf_vlan_insert_vf_id,
11073                 (void *)&cmd_vf_vlan_insert_vlan_id,
11074                 NULL,
11075         },
11076 };
11077
11078 /* tx loopback configuration */
11079
11080 /* Common result structure for tx loopback */
11081 struct cmd_tx_loopback_result {
11082         cmdline_fixed_string_t set;
11083         cmdline_fixed_string_t tx;
11084         cmdline_fixed_string_t loopback;
11085         portid_t port_id;
11086         cmdline_fixed_string_t on_off;
11087 };
11088
11089 /* Common CLI fields for tx loopback enable disable */
11090 cmdline_parse_token_string_t cmd_tx_loopback_set =
11091         TOKEN_STRING_INITIALIZER
11092                 (struct cmd_tx_loopback_result,
11093                  set, "set");
11094 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11095         TOKEN_STRING_INITIALIZER
11096                 (struct cmd_tx_loopback_result,
11097                  tx, "tx");
11098 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11099         TOKEN_STRING_INITIALIZER
11100                 (struct cmd_tx_loopback_result,
11101                  loopback, "loopback");
11102 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11103         TOKEN_NUM_INITIALIZER
11104                 (struct cmd_tx_loopback_result,
11105                  port_id, UINT16);
11106 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11107         TOKEN_STRING_INITIALIZER
11108                 (struct cmd_tx_loopback_result,
11109                  on_off, "on#off");
11110
11111 static void
11112 cmd_set_tx_loopback_parsed(
11113         void *parsed_result,
11114         __rte_unused struct cmdline *cl,
11115         __rte_unused void *data)
11116 {
11117         struct cmd_tx_loopback_result *res = parsed_result;
11118         int ret = -ENOTSUP;
11119
11120         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11121
11122         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11123                 return;
11124
11125 #ifdef RTE_NET_IXGBE
11126         if (ret == -ENOTSUP)
11127                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11128 #endif
11129 #ifdef RTE_NET_I40E
11130         if (ret == -ENOTSUP)
11131                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11132 #endif
11133 #ifdef RTE_NET_BNXT
11134         if (ret == -ENOTSUP)
11135                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11136 #endif
11137 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11138         if (ret == -ENOTSUP)
11139                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11140 #endif
11141
11142         switch (ret) {
11143         case 0:
11144                 break;
11145         case -EINVAL:
11146                 printf("invalid is_on %d\n", is_on);
11147                 break;
11148         case -ENODEV:
11149                 printf("invalid port_id %d\n", res->port_id);
11150                 break;
11151         case -ENOTSUP:
11152                 printf("function not implemented\n");
11153                 break;
11154         default:
11155                 printf("programming error: (%s)\n", strerror(-ret));
11156         }
11157 }
11158
11159 cmdline_parse_inst_t cmd_set_tx_loopback = {
11160         .f = cmd_set_tx_loopback_parsed,
11161         .data = NULL,
11162         .help_str = "set tx loopback <port_id> on|off",
11163         .tokens = {
11164                 (void *)&cmd_tx_loopback_set,
11165                 (void *)&cmd_tx_loopback_tx,
11166                 (void *)&cmd_tx_loopback_loopback,
11167                 (void *)&cmd_tx_loopback_port_id,
11168                 (void *)&cmd_tx_loopback_on_off,
11169                 NULL,
11170         },
11171 };
11172
11173 /* all queues drop enable configuration */
11174
11175 /* Common result structure for all queues drop enable */
11176 struct cmd_all_queues_drop_en_result {
11177         cmdline_fixed_string_t set;
11178         cmdline_fixed_string_t all;
11179         cmdline_fixed_string_t queues;
11180         cmdline_fixed_string_t drop;
11181         portid_t port_id;
11182         cmdline_fixed_string_t on_off;
11183 };
11184
11185 /* Common CLI fields for tx loopback enable disable */
11186 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11187         TOKEN_STRING_INITIALIZER
11188                 (struct cmd_all_queues_drop_en_result,
11189                  set, "set");
11190 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11191         TOKEN_STRING_INITIALIZER
11192                 (struct cmd_all_queues_drop_en_result,
11193                  all, "all");
11194 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11195         TOKEN_STRING_INITIALIZER
11196                 (struct cmd_all_queues_drop_en_result,
11197                  queues, "queues");
11198 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11199         TOKEN_STRING_INITIALIZER
11200                 (struct cmd_all_queues_drop_en_result,
11201                  drop, "drop");
11202 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11203         TOKEN_NUM_INITIALIZER
11204                 (struct cmd_all_queues_drop_en_result,
11205                  port_id, UINT16);
11206 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11207         TOKEN_STRING_INITIALIZER
11208                 (struct cmd_all_queues_drop_en_result,
11209                  on_off, "on#off");
11210
11211 static void
11212 cmd_set_all_queues_drop_en_parsed(
11213         void *parsed_result,
11214         __rte_unused struct cmdline *cl,
11215         __rte_unused void *data)
11216 {
11217         struct cmd_all_queues_drop_en_result *res = parsed_result;
11218         int ret = -ENOTSUP;
11219         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11220
11221         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11222                 return;
11223
11224 #ifdef RTE_NET_IXGBE
11225         if (ret == -ENOTSUP)
11226                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11227 #endif
11228 #ifdef RTE_NET_BNXT
11229         if (ret == -ENOTSUP)
11230                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11231 #endif
11232         switch (ret) {
11233         case 0:
11234                 break;
11235         case -EINVAL:
11236                 printf("invalid is_on %d\n", is_on);
11237                 break;
11238         case -ENODEV:
11239                 printf("invalid port_id %d\n", res->port_id);
11240                 break;
11241         case -ENOTSUP:
11242                 printf("function not implemented\n");
11243                 break;
11244         default:
11245                 printf("programming error: (%s)\n", strerror(-ret));
11246         }
11247 }
11248
11249 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11250         .f = cmd_set_all_queues_drop_en_parsed,
11251         .data = NULL,
11252         .help_str = "set all queues drop <port_id> on|off",
11253         .tokens = {
11254                 (void *)&cmd_all_queues_drop_en_set,
11255                 (void *)&cmd_all_queues_drop_en_all,
11256                 (void *)&cmd_all_queues_drop_en_queues,
11257                 (void *)&cmd_all_queues_drop_en_drop,
11258                 (void *)&cmd_all_queues_drop_en_port_id,
11259                 (void *)&cmd_all_queues_drop_en_on_off,
11260                 NULL,
11261         },
11262 };
11263
11264 /* vf split drop enable configuration */
11265
11266 /* Common result structure for vf split drop enable */
11267 struct cmd_vf_split_drop_en_result {
11268         cmdline_fixed_string_t set;
11269         cmdline_fixed_string_t vf;
11270         cmdline_fixed_string_t split;
11271         cmdline_fixed_string_t drop;
11272         portid_t port_id;
11273         uint16_t vf_id;
11274         cmdline_fixed_string_t on_off;
11275 };
11276
11277 /* Common CLI fields for vf split drop enable disable */
11278 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11279         TOKEN_STRING_INITIALIZER
11280                 (struct cmd_vf_split_drop_en_result,
11281                  set, "set");
11282 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11283         TOKEN_STRING_INITIALIZER
11284                 (struct cmd_vf_split_drop_en_result,
11285                  vf, "vf");
11286 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11287         TOKEN_STRING_INITIALIZER
11288                 (struct cmd_vf_split_drop_en_result,
11289                  split, "split");
11290 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11291         TOKEN_STRING_INITIALIZER
11292                 (struct cmd_vf_split_drop_en_result,
11293                  drop, "drop");
11294 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11295         TOKEN_NUM_INITIALIZER
11296                 (struct cmd_vf_split_drop_en_result,
11297                  port_id, UINT16);
11298 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11299         TOKEN_NUM_INITIALIZER
11300                 (struct cmd_vf_split_drop_en_result,
11301                  vf_id, UINT16);
11302 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11303         TOKEN_STRING_INITIALIZER
11304                 (struct cmd_vf_split_drop_en_result,
11305                  on_off, "on#off");
11306
11307 static void
11308 cmd_set_vf_split_drop_en_parsed(
11309         void *parsed_result,
11310         __rte_unused struct cmdline *cl,
11311         __rte_unused void *data)
11312 {
11313         struct cmd_vf_split_drop_en_result *res = parsed_result;
11314         int ret = -ENOTSUP;
11315         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11316
11317         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11318                 return;
11319
11320 #ifdef RTE_NET_IXGBE
11321         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11322                         is_on);
11323 #endif
11324         switch (ret) {
11325         case 0:
11326                 break;
11327         case -EINVAL:
11328                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11329                 break;
11330         case -ENODEV:
11331                 printf("invalid port_id %d\n", res->port_id);
11332                 break;
11333         case -ENOTSUP:
11334                 printf("not supported on port %d\n", res->port_id);
11335                 break;
11336         default:
11337                 printf("programming error: (%s)\n", strerror(-ret));
11338         }
11339 }
11340
11341 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11342         .f = cmd_set_vf_split_drop_en_parsed,
11343         .data = NULL,
11344         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11345         .tokens = {
11346                 (void *)&cmd_vf_split_drop_en_set,
11347                 (void *)&cmd_vf_split_drop_en_vf,
11348                 (void *)&cmd_vf_split_drop_en_split,
11349                 (void *)&cmd_vf_split_drop_en_drop,
11350                 (void *)&cmd_vf_split_drop_en_port_id,
11351                 (void *)&cmd_vf_split_drop_en_vf_id,
11352                 (void *)&cmd_vf_split_drop_en_on_off,
11353                 NULL,
11354         },
11355 };
11356
11357 /* vf mac address configuration */
11358
11359 /* Common result structure for vf mac address */
11360 struct cmd_set_vf_mac_addr_result {
11361         cmdline_fixed_string_t set;
11362         cmdline_fixed_string_t vf;
11363         cmdline_fixed_string_t mac;
11364         cmdline_fixed_string_t addr;
11365         portid_t port_id;
11366         uint16_t vf_id;
11367         struct rte_ether_addr mac_addr;
11368
11369 };
11370
11371 /* Common CLI fields for vf split drop enable disable */
11372 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11373         TOKEN_STRING_INITIALIZER
11374                 (struct cmd_set_vf_mac_addr_result,
11375                  set, "set");
11376 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11377         TOKEN_STRING_INITIALIZER
11378                 (struct cmd_set_vf_mac_addr_result,
11379                  vf, "vf");
11380 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11381         TOKEN_STRING_INITIALIZER
11382                 (struct cmd_set_vf_mac_addr_result,
11383                  mac, "mac");
11384 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11385         TOKEN_STRING_INITIALIZER
11386                 (struct cmd_set_vf_mac_addr_result,
11387                  addr, "addr");
11388 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11389         TOKEN_NUM_INITIALIZER
11390                 (struct cmd_set_vf_mac_addr_result,
11391                  port_id, UINT16);
11392 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11393         TOKEN_NUM_INITIALIZER
11394                 (struct cmd_set_vf_mac_addr_result,
11395                  vf_id, UINT16);
11396 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11397         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11398                  mac_addr);
11399
11400 static void
11401 cmd_set_vf_mac_addr_parsed(
11402         void *parsed_result,
11403         __rte_unused struct cmdline *cl,
11404         __rte_unused void *data)
11405 {
11406         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11407         int ret = -ENOTSUP;
11408
11409         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11410                 return;
11411
11412 #ifdef RTE_NET_IXGBE
11413         if (ret == -ENOTSUP)
11414                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11415                                 &res->mac_addr);
11416 #endif
11417 #ifdef RTE_NET_I40E
11418         if (ret == -ENOTSUP)
11419                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11420                                 &res->mac_addr);
11421 #endif
11422 #ifdef RTE_NET_BNXT
11423         if (ret == -ENOTSUP)
11424                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11425                                 &res->mac_addr);
11426 #endif
11427
11428         switch (ret) {
11429         case 0:
11430                 break;
11431         case -EINVAL:
11432                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11433                 break;
11434         case -ENODEV:
11435                 printf("invalid port_id %d\n", res->port_id);
11436                 break;
11437         case -ENOTSUP:
11438                 printf("function not implemented\n");
11439                 break;
11440         default:
11441                 printf("programming error: (%s)\n", strerror(-ret));
11442         }
11443 }
11444
11445 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11446         .f = cmd_set_vf_mac_addr_parsed,
11447         .data = NULL,
11448         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11449         .tokens = {
11450                 (void *)&cmd_set_vf_mac_addr_set,
11451                 (void *)&cmd_set_vf_mac_addr_vf,
11452                 (void *)&cmd_set_vf_mac_addr_mac,
11453                 (void *)&cmd_set_vf_mac_addr_addr,
11454                 (void *)&cmd_set_vf_mac_addr_port_id,
11455                 (void *)&cmd_set_vf_mac_addr_vf_id,
11456                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11457                 NULL,
11458         },
11459 };
11460
11461 /* MACsec configuration */
11462
11463 /* Common result structure for MACsec offload enable */
11464 struct cmd_macsec_offload_on_result {
11465         cmdline_fixed_string_t set;
11466         cmdline_fixed_string_t macsec;
11467         cmdline_fixed_string_t offload;
11468         portid_t port_id;
11469         cmdline_fixed_string_t on;
11470         cmdline_fixed_string_t encrypt;
11471         cmdline_fixed_string_t en_on_off;
11472         cmdline_fixed_string_t replay_protect;
11473         cmdline_fixed_string_t rp_on_off;
11474 };
11475
11476 /* Common CLI fields for MACsec offload disable */
11477 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11478         TOKEN_STRING_INITIALIZER
11479                 (struct cmd_macsec_offload_on_result,
11480                  set, "set");
11481 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11482         TOKEN_STRING_INITIALIZER
11483                 (struct cmd_macsec_offload_on_result,
11484                  macsec, "macsec");
11485 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11486         TOKEN_STRING_INITIALIZER
11487                 (struct cmd_macsec_offload_on_result,
11488                  offload, "offload");
11489 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11490         TOKEN_NUM_INITIALIZER
11491                 (struct cmd_macsec_offload_on_result,
11492                  port_id, UINT16);
11493 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11494         TOKEN_STRING_INITIALIZER
11495                 (struct cmd_macsec_offload_on_result,
11496                  on, "on");
11497 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11498         TOKEN_STRING_INITIALIZER
11499                 (struct cmd_macsec_offload_on_result,
11500                  encrypt, "encrypt");
11501 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_macsec_offload_on_result,
11504                  en_on_off, "on#off");
11505 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_macsec_offload_on_result,
11508                  replay_protect, "replay-protect");
11509 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_macsec_offload_on_result,
11512                  rp_on_off, "on#off");
11513
11514 static void
11515 cmd_set_macsec_offload_on_parsed(
11516         void *parsed_result,
11517         __rte_unused struct cmdline *cl,
11518         __rte_unused void *data)
11519 {
11520         struct cmd_macsec_offload_on_result *res = parsed_result;
11521         int ret = -ENOTSUP;
11522         portid_t port_id = res->port_id;
11523         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11524         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11525         struct rte_eth_dev_info dev_info;
11526
11527         if (port_id_is_invalid(port_id, ENABLED_WARN))
11528                 return;
11529         if (!port_is_stopped(port_id)) {
11530                 printf("Please stop port %d first\n", port_id);
11531                 return;
11532         }
11533
11534         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11535         if (ret != 0)
11536                 return;
11537
11538         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11539 #ifdef RTE_NET_IXGBE
11540                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11541 #endif
11542         }
11543         RTE_SET_USED(en);
11544         RTE_SET_USED(rp);
11545
11546         switch (ret) {
11547         case 0:
11548                 ports[port_id].dev_conf.txmode.offloads |=
11549                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11550                 cmd_reconfig_device_queue(port_id, 1, 1);
11551                 break;
11552         case -ENODEV:
11553                 printf("invalid port_id %d\n", port_id);
11554                 break;
11555         case -ENOTSUP:
11556                 printf("not supported on port %d\n", port_id);
11557                 break;
11558         default:
11559                 printf("programming error: (%s)\n", strerror(-ret));
11560         }
11561 }
11562
11563 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11564         .f = cmd_set_macsec_offload_on_parsed,
11565         .data = NULL,
11566         .help_str = "set macsec offload <port_id> on "
11567                 "encrypt on|off replay-protect on|off",
11568         .tokens = {
11569                 (void *)&cmd_macsec_offload_on_set,
11570                 (void *)&cmd_macsec_offload_on_macsec,
11571                 (void *)&cmd_macsec_offload_on_offload,
11572                 (void *)&cmd_macsec_offload_on_port_id,
11573                 (void *)&cmd_macsec_offload_on_on,
11574                 (void *)&cmd_macsec_offload_on_encrypt,
11575                 (void *)&cmd_macsec_offload_on_en_on_off,
11576                 (void *)&cmd_macsec_offload_on_replay_protect,
11577                 (void *)&cmd_macsec_offload_on_rp_on_off,
11578                 NULL,
11579         },
11580 };
11581
11582 /* Common result structure for MACsec offload disable */
11583 struct cmd_macsec_offload_off_result {
11584         cmdline_fixed_string_t set;
11585         cmdline_fixed_string_t macsec;
11586         cmdline_fixed_string_t offload;
11587         portid_t port_id;
11588         cmdline_fixed_string_t off;
11589 };
11590
11591 /* Common CLI fields for MACsec offload disable */
11592 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11593         TOKEN_STRING_INITIALIZER
11594                 (struct cmd_macsec_offload_off_result,
11595                  set, "set");
11596 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11597         TOKEN_STRING_INITIALIZER
11598                 (struct cmd_macsec_offload_off_result,
11599                  macsec, "macsec");
11600 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11601         TOKEN_STRING_INITIALIZER
11602                 (struct cmd_macsec_offload_off_result,
11603                  offload, "offload");
11604 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11605         TOKEN_NUM_INITIALIZER
11606                 (struct cmd_macsec_offload_off_result,
11607                  port_id, UINT16);
11608 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11609         TOKEN_STRING_INITIALIZER
11610                 (struct cmd_macsec_offload_off_result,
11611                  off, "off");
11612
11613 static void
11614 cmd_set_macsec_offload_off_parsed(
11615         void *parsed_result,
11616         __rte_unused struct cmdline *cl,
11617         __rte_unused void *data)
11618 {
11619         struct cmd_macsec_offload_off_result *res = parsed_result;
11620         int ret = -ENOTSUP;
11621         struct rte_eth_dev_info dev_info;
11622         portid_t port_id = res->port_id;
11623
11624         if (port_id_is_invalid(port_id, ENABLED_WARN))
11625                 return;
11626         if (!port_is_stopped(port_id)) {
11627                 printf("Please stop port %d first\n", port_id);
11628                 return;
11629         }
11630
11631         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11632         if (ret != 0)
11633                 return;
11634
11635         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11636 #ifdef RTE_NET_IXGBE
11637                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11638 #endif
11639         }
11640         switch (ret) {
11641         case 0:
11642                 ports[port_id].dev_conf.txmode.offloads &=
11643                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11644                 cmd_reconfig_device_queue(port_id, 1, 1);
11645                 break;
11646         case -ENODEV:
11647                 printf("invalid port_id %d\n", port_id);
11648                 break;
11649         case -ENOTSUP:
11650                 printf("not supported on port %d\n", port_id);
11651                 break;
11652         default:
11653                 printf("programming error: (%s)\n", strerror(-ret));
11654         }
11655 }
11656
11657 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11658         .f = cmd_set_macsec_offload_off_parsed,
11659         .data = NULL,
11660         .help_str = "set macsec offload <port_id> off",
11661         .tokens = {
11662                 (void *)&cmd_macsec_offload_off_set,
11663                 (void *)&cmd_macsec_offload_off_macsec,
11664                 (void *)&cmd_macsec_offload_off_offload,
11665                 (void *)&cmd_macsec_offload_off_port_id,
11666                 (void *)&cmd_macsec_offload_off_off,
11667                 NULL,
11668         },
11669 };
11670
11671 /* Common result structure for MACsec secure connection configure */
11672 struct cmd_macsec_sc_result {
11673         cmdline_fixed_string_t set;
11674         cmdline_fixed_string_t macsec;
11675         cmdline_fixed_string_t sc;
11676         cmdline_fixed_string_t tx_rx;
11677         portid_t port_id;
11678         struct rte_ether_addr mac;
11679         uint16_t pi;
11680 };
11681
11682 /* Common CLI fields for MACsec secure connection configure */
11683 cmdline_parse_token_string_t cmd_macsec_sc_set =
11684         TOKEN_STRING_INITIALIZER
11685                 (struct cmd_macsec_sc_result,
11686                  set, "set");
11687 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11688         TOKEN_STRING_INITIALIZER
11689                 (struct cmd_macsec_sc_result,
11690                  macsec, "macsec");
11691 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11692         TOKEN_STRING_INITIALIZER
11693                 (struct cmd_macsec_sc_result,
11694                  sc, "sc");
11695 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11696         TOKEN_STRING_INITIALIZER
11697                 (struct cmd_macsec_sc_result,
11698                  tx_rx, "tx#rx");
11699 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11700         TOKEN_NUM_INITIALIZER
11701                 (struct cmd_macsec_sc_result,
11702                  port_id, UINT16);
11703 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11704         TOKEN_ETHERADDR_INITIALIZER
11705                 (struct cmd_macsec_sc_result,
11706                  mac);
11707 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11708         TOKEN_NUM_INITIALIZER
11709                 (struct cmd_macsec_sc_result,
11710                  pi, UINT16);
11711
11712 static void
11713 cmd_set_macsec_sc_parsed(
11714         void *parsed_result,
11715         __rte_unused struct cmdline *cl,
11716         __rte_unused void *data)
11717 {
11718         struct cmd_macsec_sc_result *res = parsed_result;
11719         int ret = -ENOTSUP;
11720         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11721
11722 #ifdef RTE_NET_IXGBE
11723         ret = is_tx ?
11724                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11725                                 res->mac.addr_bytes) :
11726                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11727                                 res->mac.addr_bytes, res->pi);
11728 #endif
11729         RTE_SET_USED(is_tx);
11730
11731         switch (ret) {
11732         case 0:
11733                 break;
11734         case -ENODEV:
11735                 printf("invalid port_id %d\n", res->port_id);
11736                 break;
11737         case -ENOTSUP:
11738                 printf("not supported on port %d\n", res->port_id);
11739                 break;
11740         default:
11741                 printf("programming error: (%s)\n", strerror(-ret));
11742         }
11743 }
11744
11745 cmdline_parse_inst_t cmd_set_macsec_sc = {
11746         .f = cmd_set_macsec_sc_parsed,
11747         .data = NULL,
11748         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11749         .tokens = {
11750                 (void *)&cmd_macsec_sc_set,
11751                 (void *)&cmd_macsec_sc_macsec,
11752                 (void *)&cmd_macsec_sc_sc,
11753                 (void *)&cmd_macsec_sc_tx_rx,
11754                 (void *)&cmd_macsec_sc_port_id,
11755                 (void *)&cmd_macsec_sc_mac,
11756                 (void *)&cmd_macsec_sc_pi,
11757                 NULL,
11758         },
11759 };
11760
11761 /* Common result structure for MACsec secure connection configure */
11762 struct cmd_macsec_sa_result {
11763         cmdline_fixed_string_t set;
11764         cmdline_fixed_string_t macsec;
11765         cmdline_fixed_string_t sa;
11766         cmdline_fixed_string_t tx_rx;
11767         portid_t port_id;
11768         uint8_t idx;
11769         uint8_t an;
11770         uint32_t pn;
11771         cmdline_fixed_string_t key;
11772 };
11773
11774 /* Common CLI fields for MACsec secure connection configure */
11775 cmdline_parse_token_string_t cmd_macsec_sa_set =
11776         TOKEN_STRING_INITIALIZER
11777                 (struct cmd_macsec_sa_result,
11778                  set, "set");
11779 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11780         TOKEN_STRING_INITIALIZER
11781                 (struct cmd_macsec_sa_result,
11782                  macsec, "macsec");
11783 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11784         TOKEN_STRING_INITIALIZER
11785                 (struct cmd_macsec_sa_result,
11786                  sa, "sa");
11787 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11788         TOKEN_STRING_INITIALIZER
11789                 (struct cmd_macsec_sa_result,
11790                  tx_rx, "tx#rx");
11791 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11792         TOKEN_NUM_INITIALIZER
11793                 (struct cmd_macsec_sa_result,
11794                  port_id, UINT16);
11795 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11796         TOKEN_NUM_INITIALIZER
11797                 (struct cmd_macsec_sa_result,
11798                  idx, UINT8);
11799 cmdline_parse_token_num_t cmd_macsec_sa_an =
11800         TOKEN_NUM_INITIALIZER
11801                 (struct cmd_macsec_sa_result,
11802                  an, UINT8);
11803 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11804         TOKEN_NUM_INITIALIZER
11805                 (struct cmd_macsec_sa_result,
11806                  pn, UINT32);
11807 cmdline_parse_token_string_t cmd_macsec_sa_key =
11808         TOKEN_STRING_INITIALIZER
11809                 (struct cmd_macsec_sa_result,
11810                  key, NULL);
11811
11812 static void
11813 cmd_set_macsec_sa_parsed(
11814         void *parsed_result,
11815         __rte_unused struct cmdline *cl,
11816         __rte_unused void *data)
11817 {
11818         struct cmd_macsec_sa_result *res = parsed_result;
11819         int ret = -ENOTSUP;
11820         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11821         uint8_t key[16] = { 0 };
11822         uint8_t xdgt0;
11823         uint8_t xdgt1;
11824         int key_len;
11825         int i;
11826
11827         key_len = strlen(res->key) / 2;
11828         if (key_len > 16)
11829                 key_len = 16;
11830
11831         for (i = 0; i < key_len; i++) {
11832                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11833                 if (xdgt0 == 0xFF)
11834                         return;
11835                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11836                 if (xdgt1 == 0xFF)
11837                         return;
11838                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11839         }
11840
11841 #ifdef RTE_NET_IXGBE
11842         ret = is_tx ?
11843                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11844                         res->idx, res->an, res->pn, key) :
11845                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11846                         res->idx, res->an, res->pn, key);
11847 #endif
11848         RTE_SET_USED(is_tx);
11849         RTE_SET_USED(key);
11850
11851         switch (ret) {
11852         case 0:
11853                 break;
11854         case -EINVAL:
11855                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11856                 break;
11857         case -ENODEV:
11858                 printf("invalid port_id %d\n", res->port_id);
11859                 break;
11860         case -ENOTSUP:
11861                 printf("not supported on port %d\n", res->port_id);
11862                 break;
11863         default:
11864                 printf("programming error: (%s)\n", strerror(-ret));
11865         }
11866 }
11867
11868 cmdline_parse_inst_t cmd_set_macsec_sa = {
11869         .f = cmd_set_macsec_sa_parsed,
11870         .data = NULL,
11871         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11872         .tokens = {
11873                 (void *)&cmd_macsec_sa_set,
11874                 (void *)&cmd_macsec_sa_macsec,
11875                 (void *)&cmd_macsec_sa_sa,
11876                 (void *)&cmd_macsec_sa_tx_rx,
11877                 (void *)&cmd_macsec_sa_port_id,
11878                 (void *)&cmd_macsec_sa_idx,
11879                 (void *)&cmd_macsec_sa_an,
11880                 (void *)&cmd_macsec_sa_pn,
11881                 (void *)&cmd_macsec_sa_key,
11882                 NULL,
11883         },
11884 };
11885
11886 /* VF unicast promiscuous mode configuration */
11887
11888 /* Common result structure for VF unicast promiscuous mode */
11889 struct cmd_vf_promisc_result {
11890         cmdline_fixed_string_t set;
11891         cmdline_fixed_string_t vf;
11892         cmdline_fixed_string_t promisc;
11893         portid_t port_id;
11894         uint32_t vf_id;
11895         cmdline_fixed_string_t on_off;
11896 };
11897
11898 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11899 cmdline_parse_token_string_t cmd_vf_promisc_set =
11900         TOKEN_STRING_INITIALIZER
11901                 (struct cmd_vf_promisc_result,
11902                  set, "set");
11903 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11904         TOKEN_STRING_INITIALIZER
11905                 (struct cmd_vf_promisc_result,
11906                  vf, "vf");
11907 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11908         TOKEN_STRING_INITIALIZER
11909                 (struct cmd_vf_promisc_result,
11910                  promisc, "promisc");
11911 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11912         TOKEN_NUM_INITIALIZER
11913                 (struct cmd_vf_promisc_result,
11914                  port_id, UINT16);
11915 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11916         TOKEN_NUM_INITIALIZER
11917                 (struct cmd_vf_promisc_result,
11918                  vf_id, UINT32);
11919 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11920         TOKEN_STRING_INITIALIZER
11921                 (struct cmd_vf_promisc_result,
11922                  on_off, "on#off");
11923
11924 static void
11925 cmd_set_vf_promisc_parsed(
11926         void *parsed_result,
11927         __rte_unused struct cmdline *cl,
11928         __rte_unused void *data)
11929 {
11930         struct cmd_vf_promisc_result *res = parsed_result;
11931         int ret = -ENOTSUP;
11932
11933         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11934
11935         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11936                 return;
11937
11938 #ifdef RTE_NET_I40E
11939         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11940                                                   res->vf_id, is_on);
11941 #endif
11942
11943         switch (ret) {
11944         case 0:
11945                 break;
11946         case -EINVAL:
11947                 printf("invalid vf_id %d\n", res->vf_id);
11948                 break;
11949         case -ENODEV:
11950                 printf("invalid port_id %d\n", res->port_id);
11951                 break;
11952         case -ENOTSUP:
11953                 printf("function not implemented\n");
11954                 break;
11955         default:
11956                 printf("programming error: (%s)\n", strerror(-ret));
11957         }
11958 }
11959
11960 cmdline_parse_inst_t cmd_set_vf_promisc = {
11961         .f = cmd_set_vf_promisc_parsed,
11962         .data = NULL,
11963         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11964                 "Set unicast promiscuous mode for a VF from the PF",
11965         .tokens = {
11966                 (void *)&cmd_vf_promisc_set,
11967                 (void *)&cmd_vf_promisc_vf,
11968                 (void *)&cmd_vf_promisc_promisc,
11969                 (void *)&cmd_vf_promisc_port_id,
11970                 (void *)&cmd_vf_promisc_vf_id,
11971                 (void *)&cmd_vf_promisc_on_off,
11972                 NULL,
11973         },
11974 };
11975
11976 /* VF multicast promiscuous mode configuration */
11977
11978 /* Common result structure for VF multicast promiscuous mode */
11979 struct cmd_vf_allmulti_result {
11980         cmdline_fixed_string_t set;
11981         cmdline_fixed_string_t vf;
11982         cmdline_fixed_string_t allmulti;
11983         portid_t port_id;
11984         uint32_t vf_id;
11985         cmdline_fixed_string_t on_off;
11986 };
11987
11988 /* Common CLI fields for VF multicast promiscuous mode enable disable */
11989 cmdline_parse_token_string_t cmd_vf_allmulti_set =
11990         TOKEN_STRING_INITIALIZER
11991                 (struct cmd_vf_allmulti_result,
11992                  set, "set");
11993 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
11994         TOKEN_STRING_INITIALIZER
11995                 (struct cmd_vf_allmulti_result,
11996                  vf, "vf");
11997 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
11998         TOKEN_STRING_INITIALIZER
11999                 (struct cmd_vf_allmulti_result,
12000                  allmulti, "allmulti");
12001 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12002         TOKEN_NUM_INITIALIZER
12003                 (struct cmd_vf_allmulti_result,
12004                  port_id, UINT16);
12005 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12006         TOKEN_NUM_INITIALIZER
12007                 (struct cmd_vf_allmulti_result,
12008                  vf_id, UINT32);
12009 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12010         TOKEN_STRING_INITIALIZER
12011                 (struct cmd_vf_allmulti_result,
12012                  on_off, "on#off");
12013
12014 static void
12015 cmd_set_vf_allmulti_parsed(
12016         void *parsed_result,
12017         __rte_unused struct cmdline *cl,
12018         __rte_unused void *data)
12019 {
12020         struct cmd_vf_allmulti_result *res = parsed_result;
12021         int ret = -ENOTSUP;
12022
12023         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12024
12025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12026                 return;
12027
12028 #ifdef RTE_NET_I40E
12029         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12030                                                     res->vf_id, is_on);
12031 #endif
12032
12033         switch (ret) {
12034         case 0:
12035                 break;
12036         case -EINVAL:
12037                 printf("invalid vf_id %d\n", res->vf_id);
12038                 break;
12039         case -ENODEV:
12040                 printf("invalid port_id %d\n", res->port_id);
12041                 break;
12042         case -ENOTSUP:
12043                 printf("function not implemented\n");
12044                 break;
12045         default:
12046                 printf("programming error: (%s)\n", strerror(-ret));
12047         }
12048 }
12049
12050 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12051         .f = cmd_set_vf_allmulti_parsed,
12052         .data = NULL,
12053         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12054                 "Set multicast promiscuous mode for a VF from the PF",
12055         .tokens = {
12056                 (void *)&cmd_vf_allmulti_set,
12057                 (void *)&cmd_vf_allmulti_vf,
12058                 (void *)&cmd_vf_allmulti_allmulti,
12059                 (void *)&cmd_vf_allmulti_port_id,
12060                 (void *)&cmd_vf_allmulti_vf_id,
12061                 (void *)&cmd_vf_allmulti_on_off,
12062                 NULL,
12063         },
12064 };
12065
12066 /* vf broadcast mode configuration */
12067
12068 /* Common result structure for vf broadcast */
12069 struct cmd_set_vf_broadcast_result {
12070         cmdline_fixed_string_t set;
12071         cmdline_fixed_string_t vf;
12072         cmdline_fixed_string_t broadcast;
12073         portid_t port_id;
12074         uint16_t vf_id;
12075         cmdline_fixed_string_t on_off;
12076 };
12077
12078 /* Common CLI fields for vf broadcast enable disable */
12079 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12080         TOKEN_STRING_INITIALIZER
12081                 (struct cmd_set_vf_broadcast_result,
12082                  set, "set");
12083 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12084         TOKEN_STRING_INITIALIZER
12085                 (struct cmd_set_vf_broadcast_result,
12086                  vf, "vf");
12087 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12088         TOKEN_STRING_INITIALIZER
12089                 (struct cmd_set_vf_broadcast_result,
12090                  broadcast, "broadcast");
12091 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12092         TOKEN_NUM_INITIALIZER
12093                 (struct cmd_set_vf_broadcast_result,
12094                  port_id, UINT16);
12095 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12096         TOKEN_NUM_INITIALIZER
12097                 (struct cmd_set_vf_broadcast_result,
12098                  vf_id, UINT16);
12099 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12100         TOKEN_STRING_INITIALIZER
12101                 (struct cmd_set_vf_broadcast_result,
12102                  on_off, "on#off");
12103
12104 static void
12105 cmd_set_vf_broadcast_parsed(
12106         void *parsed_result,
12107         __rte_unused struct cmdline *cl,
12108         __rte_unused void *data)
12109 {
12110         struct cmd_set_vf_broadcast_result *res = parsed_result;
12111         int ret = -ENOTSUP;
12112
12113         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12114
12115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12116                 return;
12117
12118 #ifdef RTE_NET_I40E
12119         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12120                                             res->vf_id, is_on);
12121 #endif
12122
12123         switch (ret) {
12124         case 0:
12125                 break;
12126         case -EINVAL:
12127                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12128                 break;
12129         case -ENODEV:
12130                 printf("invalid port_id %d\n", res->port_id);
12131                 break;
12132         case -ENOTSUP:
12133                 printf("function not implemented\n");
12134                 break;
12135         default:
12136                 printf("programming error: (%s)\n", strerror(-ret));
12137         }
12138 }
12139
12140 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12141         .f = cmd_set_vf_broadcast_parsed,
12142         .data = NULL,
12143         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12144         .tokens = {
12145                 (void *)&cmd_set_vf_broadcast_set,
12146                 (void *)&cmd_set_vf_broadcast_vf,
12147                 (void *)&cmd_set_vf_broadcast_broadcast,
12148                 (void *)&cmd_set_vf_broadcast_port_id,
12149                 (void *)&cmd_set_vf_broadcast_vf_id,
12150                 (void *)&cmd_set_vf_broadcast_on_off,
12151                 NULL,
12152         },
12153 };
12154
12155 /* vf vlan tag configuration */
12156
12157 /* Common result structure for vf vlan tag */
12158 struct cmd_set_vf_vlan_tag_result {
12159         cmdline_fixed_string_t set;
12160         cmdline_fixed_string_t vf;
12161         cmdline_fixed_string_t vlan;
12162         cmdline_fixed_string_t tag;
12163         portid_t port_id;
12164         uint16_t vf_id;
12165         cmdline_fixed_string_t on_off;
12166 };
12167
12168 /* Common CLI fields for vf vlan tag enable disable */
12169 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_set_vf_vlan_tag_result,
12172                  set, "set");
12173 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_set_vf_vlan_tag_result,
12176                  vf, "vf");
12177 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_set_vf_vlan_tag_result,
12180                  vlan, "vlan");
12181 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12182         TOKEN_STRING_INITIALIZER
12183                 (struct cmd_set_vf_vlan_tag_result,
12184                  tag, "tag");
12185 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12186         TOKEN_NUM_INITIALIZER
12187                 (struct cmd_set_vf_vlan_tag_result,
12188                  port_id, UINT16);
12189 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12190         TOKEN_NUM_INITIALIZER
12191                 (struct cmd_set_vf_vlan_tag_result,
12192                  vf_id, UINT16);
12193 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12194         TOKEN_STRING_INITIALIZER
12195                 (struct cmd_set_vf_vlan_tag_result,
12196                  on_off, "on#off");
12197
12198 static void
12199 cmd_set_vf_vlan_tag_parsed(
12200         void *parsed_result,
12201         __rte_unused struct cmdline *cl,
12202         __rte_unused void *data)
12203 {
12204         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12205         int ret = -ENOTSUP;
12206
12207         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12208
12209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12210                 return;
12211
12212 #ifdef RTE_NET_I40E
12213         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12214                                            res->vf_id, is_on);
12215 #endif
12216
12217         switch (ret) {
12218         case 0:
12219                 break;
12220         case -EINVAL:
12221                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12222                 break;
12223         case -ENODEV:
12224                 printf("invalid port_id %d\n", res->port_id);
12225                 break;
12226         case -ENOTSUP:
12227                 printf("function not implemented\n");
12228                 break;
12229         default:
12230                 printf("programming error: (%s)\n", strerror(-ret));
12231         }
12232 }
12233
12234 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12235         .f = cmd_set_vf_vlan_tag_parsed,
12236         .data = NULL,
12237         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12238         .tokens = {
12239                 (void *)&cmd_set_vf_vlan_tag_set,
12240                 (void *)&cmd_set_vf_vlan_tag_vf,
12241                 (void *)&cmd_set_vf_vlan_tag_vlan,
12242                 (void *)&cmd_set_vf_vlan_tag_tag,
12243                 (void *)&cmd_set_vf_vlan_tag_port_id,
12244                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12245                 (void *)&cmd_set_vf_vlan_tag_on_off,
12246                 NULL,
12247         },
12248 };
12249
12250 /* Common definition of VF and TC TX bandwidth configuration */
12251 struct cmd_vf_tc_bw_result {
12252         cmdline_fixed_string_t set;
12253         cmdline_fixed_string_t vf;
12254         cmdline_fixed_string_t tc;
12255         cmdline_fixed_string_t tx;
12256         cmdline_fixed_string_t min_bw;
12257         cmdline_fixed_string_t max_bw;
12258         cmdline_fixed_string_t strict_link_prio;
12259         portid_t port_id;
12260         uint16_t vf_id;
12261         uint8_t tc_no;
12262         uint32_t bw;
12263         cmdline_fixed_string_t bw_list;
12264         uint8_t tc_map;
12265 };
12266
12267 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_vf_tc_bw_result,
12270                  set, "set");
12271 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12272         TOKEN_STRING_INITIALIZER
12273                 (struct cmd_vf_tc_bw_result,
12274                  vf, "vf");
12275 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12276         TOKEN_STRING_INITIALIZER
12277                 (struct cmd_vf_tc_bw_result,
12278                  tc, "tc");
12279 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_vf_tc_bw_result,
12282                  tx, "tx");
12283 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_vf_tc_bw_result,
12286                  strict_link_prio, "strict-link-priority");
12287 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12288         TOKEN_STRING_INITIALIZER
12289                 (struct cmd_vf_tc_bw_result,
12290                  min_bw, "min-bandwidth");
12291 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_vf_tc_bw_result,
12294                  max_bw, "max-bandwidth");
12295 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12296         TOKEN_NUM_INITIALIZER
12297                 (struct cmd_vf_tc_bw_result,
12298                  port_id, UINT16);
12299 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12300         TOKEN_NUM_INITIALIZER
12301                 (struct cmd_vf_tc_bw_result,
12302                  vf_id, UINT16);
12303 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12304         TOKEN_NUM_INITIALIZER
12305                 (struct cmd_vf_tc_bw_result,
12306                  tc_no, UINT8);
12307 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12308         TOKEN_NUM_INITIALIZER
12309                 (struct cmd_vf_tc_bw_result,
12310                  bw, UINT32);
12311 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12312         TOKEN_STRING_INITIALIZER
12313                 (struct cmd_vf_tc_bw_result,
12314                  bw_list, NULL);
12315 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12316         TOKEN_NUM_INITIALIZER
12317                 (struct cmd_vf_tc_bw_result,
12318                  tc_map, UINT8);
12319
12320 /* VF max bandwidth setting */
12321 static void
12322 cmd_vf_max_bw_parsed(
12323         void *parsed_result,
12324         __rte_unused struct cmdline *cl,
12325         __rte_unused void *data)
12326 {
12327         struct cmd_vf_tc_bw_result *res = parsed_result;
12328         int ret = -ENOTSUP;
12329
12330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12331                 return;
12332
12333 #ifdef RTE_NET_I40E
12334         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12335                                          res->vf_id, res->bw);
12336 #endif
12337
12338         switch (ret) {
12339         case 0:
12340                 break;
12341         case -EINVAL:
12342                 printf("invalid vf_id %d or bandwidth %d\n",
12343                        res->vf_id, res->bw);
12344                 break;
12345         case -ENODEV:
12346                 printf("invalid port_id %d\n", res->port_id);
12347                 break;
12348         case -ENOTSUP:
12349                 printf("function not implemented\n");
12350                 break;
12351         default:
12352                 printf("programming error: (%s)\n", strerror(-ret));
12353         }
12354 }
12355
12356 cmdline_parse_inst_t cmd_vf_max_bw = {
12357         .f = cmd_vf_max_bw_parsed,
12358         .data = NULL,
12359         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12360         .tokens = {
12361                 (void *)&cmd_vf_tc_bw_set,
12362                 (void *)&cmd_vf_tc_bw_vf,
12363                 (void *)&cmd_vf_tc_bw_tx,
12364                 (void *)&cmd_vf_tc_bw_max_bw,
12365                 (void *)&cmd_vf_tc_bw_port_id,
12366                 (void *)&cmd_vf_tc_bw_vf_id,
12367                 (void *)&cmd_vf_tc_bw_bw,
12368                 NULL,
12369         },
12370 };
12371
12372 static int
12373 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12374                            uint8_t *tc_num,
12375                            char *str)
12376 {
12377         uint32_t size;
12378         const char *p, *p0 = str;
12379         char s[256];
12380         char *end;
12381         char *str_fld[16];
12382         uint16_t i;
12383         int ret;
12384
12385         p = strchr(p0, '(');
12386         if (p == NULL) {
12387                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12388                 return -1;
12389         }
12390         p++;
12391         p0 = strchr(p, ')');
12392         if (p0 == NULL) {
12393                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12394                 return -1;
12395         }
12396         size = p0 - p;
12397         if (size >= sizeof(s)) {
12398                 printf("The string size exceeds the internal buffer size\n");
12399                 return -1;
12400         }
12401         snprintf(s, sizeof(s), "%.*s", size, p);
12402         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12403         if (ret <= 0) {
12404                 printf("Failed to get the bandwidth list. ");
12405                 return -1;
12406         }
12407         *tc_num = ret;
12408         for (i = 0; i < ret; i++)
12409                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12410
12411         return 0;
12412 }
12413
12414 /* TC min bandwidth setting */
12415 static void
12416 cmd_vf_tc_min_bw_parsed(
12417         void *parsed_result,
12418         __rte_unused struct cmdline *cl,
12419         __rte_unused void *data)
12420 {
12421         struct cmd_vf_tc_bw_result *res = parsed_result;
12422         uint8_t tc_num;
12423         uint8_t bw[16];
12424         int ret = -ENOTSUP;
12425
12426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12427                 return;
12428
12429         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12430         if (ret)
12431                 return;
12432
12433 #ifdef RTE_NET_I40E
12434         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12435                                               tc_num, bw);
12436 #endif
12437
12438         switch (ret) {
12439         case 0:
12440                 break;
12441         case -EINVAL:
12442                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12443                 break;
12444         case -ENODEV:
12445                 printf("invalid port_id %d\n", res->port_id);
12446                 break;
12447         case -ENOTSUP:
12448                 printf("function not implemented\n");
12449                 break;
12450         default:
12451                 printf("programming error: (%s)\n", strerror(-ret));
12452         }
12453 }
12454
12455 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12456         .f = cmd_vf_tc_min_bw_parsed,
12457         .data = NULL,
12458         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12459                     " <bw1, bw2, ...>",
12460         .tokens = {
12461                 (void *)&cmd_vf_tc_bw_set,
12462                 (void *)&cmd_vf_tc_bw_vf,
12463                 (void *)&cmd_vf_tc_bw_tc,
12464                 (void *)&cmd_vf_tc_bw_tx,
12465                 (void *)&cmd_vf_tc_bw_min_bw,
12466                 (void *)&cmd_vf_tc_bw_port_id,
12467                 (void *)&cmd_vf_tc_bw_vf_id,
12468                 (void *)&cmd_vf_tc_bw_bw_list,
12469                 NULL,
12470         },
12471 };
12472
12473 static void
12474 cmd_tc_min_bw_parsed(
12475         void *parsed_result,
12476         __rte_unused struct cmdline *cl,
12477         __rte_unused void *data)
12478 {
12479         struct cmd_vf_tc_bw_result *res = parsed_result;
12480         struct rte_port *port;
12481         uint8_t tc_num;
12482         uint8_t bw[16];
12483         int ret = -ENOTSUP;
12484
12485         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12486                 return;
12487
12488         port = &ports[res->port_id];
12489         /** Check if the port is not started **/
12490         if (port->port_status != RTE_PORT_STOPPED) {
12491                 printf("Please stop port %d first\n", res->port_id);
12492                 return;
12493         }
12494
12495         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12496         if (ret)
12497                 return;
12498
12499 #ifdef RTE_NET_IXGBE
12500         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12501 #endif
12502
12503         switch (ret) {
12504         case 0:
12505                 break;
12506         case -EINVAL:
12507                 printf("invalid bandwidth\n");
12508                 break;
12509         case -ENODEV:
12510                 printf("invalid port_id %d\n", res->port_id);
12511                 break;
12512         case -ENOTSUP:
12513                 printf("function not implemented\n");
12514                 break;
12515         default:
12516                 printf("programming error: (%s)\n", strerror(-ret));
12517         }
12518 }
12519
12520 cmdline_parse_inst_t cmd_tc_min_bw = {
12521         .f = cmd_tc_min_bw_parsed,
12522         .data = NULL,
12523         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12524         .tokens = {
12525                 (void *)&cmd_vf_tc_bw_set,
12526                 (void *)&cmd_vf_tc_bw_tc,
12527                 (void *)&cmd_vf_tc_bw_tx,
12528                 (void *)&cmd_vf_tc_bw_min_bw,
12529                 (void *)&cmd_vf_tc_bw_port_id,
12530                 (void *)&cmd_vf_tc_bw_bw_list,
12531                 NULL,
12532         },
12533 };
12534
12535 /* TC max bandwidth setting */
12536 static void
12537 cmd_vf_tc_max_bw_parsed(
12538         void *parsed_result,
12539         __rte_unused struct cmdline *cl,
12540         __rte_unused void *data)
12541 {
12542         struct cmd_vf_tc_bw_result *res = parsed_result;
12543         int ret = -ENOTSUP;
12544
12545         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12546                 return;
12547
12548 #ifdef RTE_NET_I40E
12549         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12550                                             res->tc_no, res->bw);
12551 #endif
12552
12553         switch (ret) {
12554         case 0:
12555                 break;
12556         case -EINVAL:
12557                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12558                        res->vf_id, res->tc_no, res->bw);
12559                 break;
12560         case -ENODEV:
12561                 printf("invalid port_id %d\n", res->port_id);
12562                 break;
12563         case -ENOTSUP:
12564                 printf("function not implemented\n");
12565                 break;
12566         default:
12567                 printf("programming error: (%s)\n", strerror(-ret));
12568         }
12569 }
12570
12571 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12572         .f = cmd_vf_tc_max_bw_parsed,
12573         .data = NULL,
12574         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12575                     " <bandwidth>",
12576         .tokens = {
12577                 (void *)&cmd_vf_tc_bw_set,
12578                 (void *)&cmd_vf_tc_bw_vf,
12579                 (void *)&cmd_vf_tc_bw_tc,
12580                 (void *)&cmd_vf_tc_bw_tx,
12581                 (void *)&cmd_vf_tc_bw_max_bw,
12582                 (void *)&cmd_vf_tc_bw_port_id,
12583                 (void *)&cmd_vf_tc_bw_vf_id,
12584                 (void *)&cmd_vf_tc_bw_tc_no,
12585                 (void *)&cmd_vf_tc_bw_bw,
12586                 NULL,
12587         },
12588 };
12589
12590 /** Set VXLAN encapsulation details */
12591 struct cmd_set_vxlan_result {
12592         cmdline_fixed_string_t set;
12593         cmdline_fixed_string_t vxlan;
12594         cmdline_fixed_string_t pos_token;
12595         cmdline_fixed_string_t ip_version;
12596         uint32_t vlan_present:1;
12597         uint32_t vni;
12598         uint16_t udp_src;
12599         uint16_t udp_dst;
12600         cmdline_ipaddr_t ip_src;
12601         cmdline_ipaddr_t ip_dst;
12602         uint16_t tci;
12603         uint8_t tos;
12604         uint8_t ttl;
12605         struct rte_ether_addr eth_src;
12606         struct rte_ether_addr eth_dst;
12607 };
12608
12609 cmdline_parse_token_string_t cmd_set_vxlan_set =
12610         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12611 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12612         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12613 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12614         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12615                                  "vxlan-tos-ttl");
12616 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12617         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12618                                  "vxlan-with-vlan");
12619 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12620         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12621                                  "ip-version");
12622 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12623         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12624                                  "ipv4#ipv6");
12625 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12626         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12627                                  "vni");
12628 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12629         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
12630 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12631         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12632                                  "udp-src");
12633 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12634         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
12635 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12636         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12637                                  "udp-dst");
12638 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12639         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
12640 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12641         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12642                                  "ip-tos");
12643 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12644         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
12645 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12646         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12647                                  "ip-ttl");
12648 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12649         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
12650 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12651         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12652                                  "ip-src");
12653 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12654         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12655 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12656         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12657                                  "ip-dst");
12658 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12659         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12660 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12661         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12662                                  "vlan-tci");
12663 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12664         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
12665 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12666         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12667                                  "eth-src");
12668 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12669         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12670 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12671         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12672                                  "eth-dst");
12673 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12674         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12675
12676 static void cmd_set_vxlan_parsed(void *parsed_result,
12677         __rte_unused struct cmdline *cl,
12678         __rte_unused void *data)
12679 {
12680         struct cmd_set_vxlan_result *res = parsed_result;
12681         union {
12682                 uint32_t vxlan_id;
12683                 uint8_t vni[4];
12684         } id = {
12685                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12686         };
12687
12688         vxlan_encap_conf.select_tos_ttl = 0;
12689         if (strcmp(res->vxlan, "vxlan") == 0)
12690                 vxlan_encap_conf.select_vlan = 0;
12691         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12692                 vxlan_encap_conf.select_vlan = 1;
12693         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12694                 vxlan_encap_conf.select_vlan = 0;
12695                 vxlan_encap_conf.select_tos_ttl = 1;
12696         }
12697         if (strcmp(res->ip_version, "ipv4") == 0)
12698                 vxlan_encap_conf.select_ipv4 = 1;
12699         else if (strcmp(res->ip_version, "ipv6") == 0)
12700                 vxlan_encap_conf.select_ipv4 = 0;
12701         else
12702                 return;
12703         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12704         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12705         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12706         vxlan_encap_conf.ip_tos = res->tos;
12707         vxlan_encap_conf.ip_ttl = res->ttl;
12708         if (vxlan_encap_conf.select_ipv4) {
12709                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12710                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12711         } else {
12712                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12713                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12714         }
12715         if (vxlan_encap_conf.select_vlan)
12716                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12717         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12718                    RTE_ETHER_ADDR_LEN);
12719         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12720                    RTE_ETHER_ADDR_LEN);
12721 }
12722
12723 cmdline_parse_inst_t cmd_set_vxlan = {
12724         .f = cmd_set_vxlan_parsed,
12725         .data = NULL,
12726         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12727                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12728                 " eth-src <eth-src> eth-dst <eth-dst>",
12729         .tokens = {
12730                 (void *)&cmd_set_vxlan_set,
12731                 (void *)&cmd_set_vxlan_vxlan,
12732                 (void *)&cmd_set_vxlan_ip_version,
12733                 (void *)&cmd_set_vxlan_ip_version_value,
12734                 (void *)&cmd_set_vxlan_vni,
12735                 (void *)&cmd_set_vxlan_vni_value,
12736                 (void *)&cmd_set_vxlan_udp_src,
12737                 (void *)&cmd_set_vxlan_udp_src_value,
12738                 (void *)&cmd_set_vxlan_udp_dst,
12739                 (void *)&cmd_set_vxlan_udp_dst_value,
12740                 (void *)&cmd_set_vxlan_ip_src,
12741                 (void *)&cmd_set_vxlan_ip_src_value,
12742                 (void *)&cmd_set_vxlan_ip_dst,
12743                 (void *)&cmd_set_vxlan_ip_dst_value,
12744                 (void *)&cmd_set_vxlan_eth_src,
12745                 (void *)&cmd_set_vxlan_eth_src_value,
12746                 (void *)&cmd_set_vxlan_eth_dst,
12747                 (void *)&cmd_set_vxlan_eth_dst_value,
12748                 NULL,
12749         },
12750 };
12751
12752 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12753         .f = cmd_set_vxlan_parsed,
12754         .data = NULL,
12755         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12756                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12757                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12758                 " eth-dst <eth-dst>",
12759         .tokens = {
12760                 (void *)&cmd_set_vxlan_set,
12761                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12762                 (void *)&cmd_set_vxlan_ip_version,
12763                 (void *)&cmd_set_vxlan_ip_version_value,
12764                 (void *)&cmd_set_vxlan_vni,
12765                 (void *)&cmd_set_vxlan_vni_value,
12766                 (void *)&cmd_set_vxlan_udp_src,
12767                 (void *)&cmd_set_vxlan_udp_src_value,
12768                 (void *)&cmd_set_vxlan_udp_dst,
12769                 (void *)&cmd_set_vxlan_udp_dst_value,
12770                 (void *)&cmd_set_vxlan_ip_tos,
12771                 (void *)&cmd_set_vxlan_ip_tos_value,
12772                 (void *)&cmd_set_vxlan_ip_ttl,
12773                 (void *)&cmd_set_vxlan_ip_ttl_value,
12774                 (void *)&cmd_set_vxlan_ip_src,
12775                 (void *)&cmd_set_vxlan_ip_src_value,
12776                 (void *)&cmd_set_vxlan_ip_dst,
12777                 (void *)&cmd_set_vxlan_ip_dst_value,
12778                 (void *)&cmd_set_vxlan_eth_src,
12779                 (void *)&cmd_set_vxlan_eth_src_value,
12780                 (void *)&cmd_set_vxlan_eth_dst,
12781                 (void *)&cmd_set_vxlan_eth_dst_value,
12782                 NULL,
12783         },
12784 };
12785
12786 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12787         .f = cmd_set_vxlan_parsed,
12788         .data = NULL,
12789         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12790                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12791                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12792                 " <eth-dst>",
12793         .tokens = {
12794                 (void *)&cmd_set_vxlan_set,
12795                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12796                 (void *)&cmd_set_vxlan_ip_version,
12797                 (void *)&cmd_set_vxlan_ip_version_value,
12798                 (void *)&cmd_set_vxlan_vni,
12799                 (void *)&cmd_set_vxlan_vni_value,
12800                 (void *)&cmd_set_vxlan_udp_src,
12801                 (void *)&cmd_set_vxlan_udp_src_value,
12802                 (void *)&cmd_set_vxlan_udp_dst,
12803                 (void *)&cmd_set_vxlan_udp_dst_value,
12804                 (void *)&cmd_set_vxlan_ip_src,
12805                 (void *)&cmd_set_vxlan_ip_src_value,
12806                 (void *)&cmd_set_vxlan_ip_dst,
12807                 (void *)&cmd_set_vxlan_ip_dst_value,
12808                 (void *)&cmd_set_vxlan_vlan,
12809                 (void *)&cmd_set_vxlan_vlan_value,
12810                 (void *)&cmd_set_vxlan_eth_src,
12811                 (void *)&cmd_set_vxlan_eth_src_value,
12812                 (void *)&cmd_set_vxlan_eth_dst,
12813                 (void *)&cmd_set_vxlan_eth_dst_value,
12814                 NULL,
12815         },
12816 };
12817
12818 /** Set NVGRE encapsulation details */
12819 struct cmd_set_nvgre_result {
12820         cmdline_fixed_string_t set;
12821         cmdline_fixed_string_t nvgre;
12822         cmdline_fixed_string_t pos_token;
12823         cmdline_fixed_string_t ip_version;
12824         uint32_t tni;
12825         cmdline_ipaddr_t ip_src;
12826         cmdline_ipaddr_t ip_dst;
12827         uint16_t tci;
12828         struct rte_ether_addr eth_src;
12829         struct rte_ether_addr eth_dst;
12830 };
12831
12832 cmdline_parse_token_string_t cmd_set_nvgre_set =
12833         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12834 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12835         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12836 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12837         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12838                                  "nvgre-with-vlan");
12839 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12840         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12841                                  "ip-version");
12842 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12843         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12844                                  "ipv4#ipv6");
12845 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12846         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12847                                  "tni");
12848 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12849         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
12850 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12851         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12852                                  "ip-src");
12853 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12854         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12855 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12856         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12857                                  "ip-dst");
12858 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12859         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12860 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12861         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12862                                  "vlan-tci");
12863 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12864         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
12865 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12866         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12867                                  "eth-src");
12868 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12869         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12870 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12871         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12872                                  "eth-dst");
12873 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12874         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12875
12876 static void cmd_set_nvgre_parsed(void *parsed_result,
12877         __rte_unused struct cmdline *cl,
12878         __rte_unused void *data)
12879 {
12880         struct cmd_set_nvgre_result *res = parsed_result;
12881         union {
12882                 uint32_t nvgre_tni;
12883                 uint8_t tni[4];
12884         } id = {
12885                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12886         };
12887
12888         if (strcmp(res->nvgre, "nvgre") == 0)
12889                 nvgre_encap_conf.select_vlan = 0;
12890         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12891                 nvgre_encap_conf.select_vlan = 1;
12892         if (strcmp(res->ip_version, "ipv4") == 0)
12893                 nvgre_encap_conf.select_ipv4 = 1;
12894         else if (strcmp(res->ip_version, "ipv6") == 0)
12895                 nvgre_encap_conf.select_ipv4 = 0;
12896         else
12897                 return;
12898         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12899         if (nvgre_encap_conf.select_ipv4) {
12900                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12901                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12902         } else {
12903                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12904                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12905         }
12906         if (nvgre_encap_conf.select_vlan)
12907                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12908         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12909                    RTE_ETHER_ADDR_LEN);
12910         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12911                    RTE_ETHER_ADDR_LEN);
12912 }
12913
12914 cmdline_parse_inst_t cmd_set_nvgre = {
12915         .f = cmd_set_nvgre_parsed,
12916         .data = NULL,
12917         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12918                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12919                 " eth-dst <eth-dst>",
12920         .tokens = {
12921                 (void *)&cmd_set_nvgre_set,
12922                 (void *)&cmd_set_nvgre_nvgre,
12923                 (void *)&cmd_set_nvgre_ip_version,
12924                 (void *)&cmd_set_nvgre_ip_version_value,
12925                 (void *)&cmd_set_nvgre_tni,
12926                 (void *)&cmd_set_nvgre_tni_value,
12927                 (void *)&cmd_set_nvgre_ip_src,
12928                 (void *)&cmd_set_nvgre_ip_src_value,
12929                 (void *)&cmd_set_nvgre_ip_dst,
12930                 (void *)&cmd_set_nvgre_ip_dst_value,
12931                 (void *)&cmd_set_nvgre_eth_src,
12932                 (void *)&cmd_set_nvgre_eth_src_value,
12933                 (void *)&cmd_set_nvgre_eth_dst,
12934                 (void *)&cmd_set_nvgre_eth_dst_value,
12935                 NULL,
12936         },
12937 };
12938
12939 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12940         .f = cmd_set_nvgre_parsed,
12941         .data = NULL,
12942         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12943                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12944                 " eth-src <eth-src> eth-dst <eth-dst>",
12945         .tokens = {
12946                 (void *)&cmd_set_nvgre_set,
12947                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12948                 (void *)&cmd_set_nvgre_ip_version,
12949                 (void *)&cmd_set_nvgre_ip_version_value,
12950                 (void *)&cmd_set_nvgre_tni,
12951                 (void *)&cmd_set_nvgre_tni_value,
12952                 (void *)&cmd_set_nvgre_ip_src,
12953                 (void *)&cmd_set_nvgre_ip_src_value,
12954                 (void *)&cmd_set_nvgre_ip_dst,
12955                 (void *)&cmd_set_nvgre_ip_dst_value,
12956                 (void *)&cmd_set_nvgre_vlan,
12957                 (void *)&cmd_set_nvgre_vlan_value,
12958                 (void *)&cmd_set_nvgre_eth_src,
12959                 (void *)&cmd_set_nvgre_eth_src_value,
12960                 (void *)&cmd_set_nvgre_eth_dst,
12961                 (void *)&cmd_set_nvgre_eth_dst_value,
12962                 NULL,
12963         },
12964 };
12965
12966 /** Set L2 encapsulation details */
12967 struct cmd_set_l2_encap_result {
12968         cmdline_fixed_string_t set;
12969         cmdline_fixed_string_t l2_encap;
12970         cmdline_fixed_string_t pos_token;
12971         cmdline_fixed_string_t ip_version;
12972         uint32_t vlan_present:1;
12973         uint16_t tci;
12974         struct rte_ether_addr eth_src;
12975         struct rte_ether_addr eth_dst;
12976 };
12977
12978 cmdline_parse_token_string_t cmd_set_l2_encap_set =
12979         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
12980 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
12981         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
12982 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
12983         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
12984                                  "l2_encap-with-vlan");
12985 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
12986         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
12987                                  "ip-version");
12988 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
12989         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
12990                                  "ipv4#ipv6");
12991 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
12992         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
12993                                  "vlan-tci");
12994 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
12995         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
12996 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
12997         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
12998                                  "eth-src");
12999 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13000         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13001 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13002         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13003                                  "eth-dst");
13004 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13005         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13006
13007 static void cmd_set_l2_encap_parsed(void *parsed_result,
13008         __rte_unused struct cmdline *cl,
13009         __rte_unused void *data)
13010 {
13011         struct cmd_set_l2_encap_result *res = parsed_result;
13012
13013         if (strcmp(res->l2_encap, "l2_encap") == 0)
13014                 l2_encap_conf.select_vlan = 0;
13015         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13016                 l2_encap_conf.select_vlan = 1;
13017         if (strcmp(res->ip_version, "ipv4") == 0)
13018                 l2_encap_conf.select_ipv4 = 1;
13019         else if (strcmp(res->ip_version, "ipv6") == 0)
13020                 l2_encap_conf.select_ipv4 = 0;
13021         else
13022                 return;
13023         if (l2_encap_conf.select_vlan)
13024                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13025         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13026                    RTE_ETHER_ADDR_LEN);
13027         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13028                    RTE_ETHER_ADDR_LEN);
13029 }
13030
13031 cmdline_parse_inst_t cmd_set_l2_encap = {
13032         .f = cmd_set_l2_encap_parsed,
13033         .data = NULL,
13034         .help_str = "set l2_encap ip-version ipv4|ipv6"
13035                 " eth-src <eth-src> eth-dst <eth-dst>",
13036         .tokens = {
13037                 (void *)&cmd_set_l2_encap_set,
13038                 (void *)&cmd_set_l2_encap_l2_encap,
13039                 (void *)&cmd_set_l2_encap_ip_version,
13040                 (void *)&cmd_set_l2_encap_ip_version_value,
13041                 (void *)&cmd_set_l2_encap_eth_src,
13042                 (void *)&cmd_set_l2_encap_eth_src_value,
13043                 (void *)&cmd_set_l2_encap_eth_dst,
13044                 (void *)&cmd_set_l2_encap_eth_dst_value,
13045                 NULL,
13046         },
13047 };
13048
13049 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13050         .f = cmd_set_l2_encap_parsed,
13051         .data = NULL,
13052         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13053                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13054         .tokens = {
13055                 (void *)&cmd_set_l2_encap_set,
13056                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13057                 (void *)&cmd_set_l2_encap_ip_version,
13058                 (void *)&cmd_set_l2_encap_ip_version_value,
13059                 (void *)&cmd_set_l2_encap_vlan,
13060                 (void *)&cmd_set_l2_encap_vlan_value,
13061                 (void *)&cmd_set_l2_encap_eth_src,
13062                 (void *)&cmd_set_l2_encap_eth_src_value,
13063                 (void *)&cmd_set_l2_encap_eth_dst,
13064                 (void *)&cmd_set_l2_encap_eth_dst_value,
13065                 NULL,
13066         },
13067 };
13068
13069 /** Set L2 decapsulation details */
13070 struct cmd_set_l2_decap_result {
13071         cmdline_fixed_string_t set;
13072         cmdline_fixed_string_t l2_decap;
13073         cmdline_fixed_string_t pos_token;
13074         uint32_t vlan_present:1;
13075 };
13076
13077 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13078         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13079 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13080         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13081                                  "l2_decap");
13082 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13083         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13084                                  "l2_decap-with-vlan");
13085
13086 static void cmd_set_l2_decap_parsed(void *parsed_result,
13087         __rte_unused struct cmdline *cl,
13088         __rte_unused void *data)
13089 {
13090         struct cmd_set_l2_decap_result *res = parsed_result;
13091
13092         if (strcmp(res->l2_decap, "l2_decap") == 0)
13093                 l2_decap_conf.select_vlan = 0;
13094         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13095                 l2_decap_conf.select_vlan = 1;
13096 }
13097
13098 cmdline_parse_inst_t cmd_set_l2_decap = {
13099         .f = cmd_set_l2_decap_parsed,
13100         .data = NULL,
13101         .help_str = "set l2_decap",
13102         .tokens = {
13103                 (void *)&cmd_set_l2_decap_set,
13104                 (void *)&cmd_set_l2_decap_l2_decap,
13105                 NULL,
13106         },
13107 };
13108
13109 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13110         .f = cmd_set_l2_decap_parsed,
13111         .data = NULL,
13112         .help_str = "set l2_decap-with-vlan",
13113         .tokens = {
13114                 (void *)&cmd_set_l2_decap_set,
13115                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13116                 NULL,
13117         },
13118 };
13119
13120 /** Set MPLSoGRE encapsulation details */
13121 struct cmd_set_mplsogre_encap_result {
13122         cmdline_fixed_string_t set;
13123         cmdline_fixed_string_t mplsogre;
13124         cmdline_fixed_string_t pos_token;
13125         cmdline_fixed_string_t ip_version;
13126         uint32_t vlan_present:1;
13127         uint32_t label;
13128         cmdline_ipaddr_t ip_src;
13129         cmdline_ipaddr_t ip_dst;
13130         uint16_t tci;
13131         struct rte_ether_addr eth_src;
13132         struct rte_ether_addr eth_dst;
13133 };
13134
13135 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13136         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13137                                  "set");
13138 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13139         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13140                                  "mplsogre_encap");
13141 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13142         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13143                                  mplsogre, "mplsogre_encap-with-vlan");
13144 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13145         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13146                                  pos_token, "ip-version");
13147 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13148         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13149                                  ip_version, "ipv4#ipv6");
13150 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13151         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13152                                  pos_token, "label");
13153 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13154         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13155                               UINT32);
13156 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13157         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13158                                  pos_token, "ip-src");
13159 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13160         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13161 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13162         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13163                                  pos_token, "ip-dst");
13164 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13165         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13166 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13167         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13168                                  pos_token, "vlan-tci");
13169 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13170         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13171                               UINT16);
13172 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13173         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13174                                  pos_token, "eth-src");
13175 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13176         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13177                                     eth_src);
13178 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13179         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13180                                  pos_token, "eth-dst");
13181 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13182         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13183                                     eth_dst);
13184
13185 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13186         __rte_unused struct cmdline *cl,
13187         __rte_unused void *data)
13188 {
13189         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13190         union {
13191                 uint32_t mplsogre_label;
13192                 uint8_t label[4];
13193         } id = {
13194                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13195         };
13196
13197         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13198                 mplsogre_encap_conf.select_vlan = 0;
13199         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13200                 mplsogre_encap_conf.select_vlan = 1;
13201         if (strcmp(res->ip_version, "ipv4") == 0)
13202                 mplsogre_encap_conf.select_ipv4 = 1;
13203         else if (strcmp(res->ip_version, "ipv6") == 0)
13204                 mplsogre_encap_conf.select_ipv4 = 0;
13205         else
13206                 return;
13207         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13208         if (mplsogre_encap_conf.select_ipv4) {
13209                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13210                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13211         } else {
13212                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13213                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13214         }
13215         if (mplsogre_encap_conf.select_vlan)
13216                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13217         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13218                    RTE_ETHER_ADDR_LEN);
13219         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13220                    RTE_ETHER_ADDR_LEN);
13221 }
13222
13223 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13224         .f = cmd_set_mplsogre_encap_parsed,
13225         .data = NULL,
13226         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13227                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13228                 " eth-dst <eth-dst>",
13229         .tokens = {
13230                 (void *)&cmd_set_mplsogre_encap_set,
13231                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13232                 (void *)&cmd_set_mplsogre_encap_ip_version,
13233                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13234                 (void *)&cmd_set_mplsogre_encap_label,
13235                 (void *)&cmd_set_mplsogre_encap_label_value,
13236                 (void *)&cmd_set_mplsogre_encap_ip_src,
13237                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13238                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13239                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13240                 (void *)&cmd_set_mplsogre_encap_eth_src,
13241                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13242                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13243                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13244                 NULL,
13245         },
13246 };
13247
13248 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13249         .f = cmd_set_mplsogre_encap_parsed,
13250         .data = NULL,
13251         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13252                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13253                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13254         .tokens = {
13255                 (void *)&cmd_set_mplsogre_encap_set,
13256                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13257                 (void *)&cmd_set_mplsogre_encap_ip_version,
13258                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13259                 (void *)&cmd_set_mplsogre_encap_label,
13260                 (void *)&cmd_set_mplsogre_encap_label_value,
13261                 (void *)&cmd_set_mplsogre_encap_ip_src,
13262                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13263                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13264                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13265                 (void *)&cmd_set_mplsogre_encap_vlan,
13266                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13267                 (void *)&cmd_set_mplsogre_encap_eth_src,
13268                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13269                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13270                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13271                 NULL,
13272         },
13273 };
13274
13275 /** Set MPLSoGRE decapsulation details */
13276 struct cmd_set_mplsogre_decap_result {
13277         cmdline_fixed_string_t set;
13278         cmdline_fixed_string_t mplsogre;
13279         cmdline_fixed_string_t pos_token;
13280         cmdline_fixed_string_t ip_version;
13281         uint32_t vlan_present:1;
13282 };
13283
13284 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13285         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13286                                  "set");
13287 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13288         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13289                                  "mplsogre_decap");
13290 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13291         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13292                                  mplsogre, "mplsogre_decap-with-vlan");
13293 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13294         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13295                                  pos_token, "ip-version");
13296 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13297         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13298                                  ip_version, "ipv4#ipv6");
13299
13300 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13301         __rte_unused struct cmdline *cl,
13302         __rte_unused void *data)
13303 {
13304         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13305
13306         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13307                 mplsogre_decap_conf.select_vlan = 0;
13308         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13309                 mplsogre_decap_conf.select_vlan = 1;
13310         if (strcmp(res->ip_version, "ipv4") == 0)
13311                 mplsogre_decap_conf.select_ipv4 = 1;
13312         else if (strcmp(res->ip_version, "ipv6") == 0)
13313                 mplsogre_decap_conf.select_ipv4 = 0;
13314 }
13315
13316 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13317         .f = cmd_set_mplsogre_decap_parsed,
13318         .data = NULL,
13319         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13320         .tokens = {
13321                 (void *)&cmd_set_mplsogre_decap_set,
13322                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13323                 (void *)&cmd_set_mplsogre_decap_ip_version,
13324                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13325                 NULL,
13326         },
13327 };
13328
13329 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13330         .f = cmd_set_mplsogre_decap_parsed,
13331         .data = NULL,
13332         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13333         .tokens = {
13334                 (void *)&cmd_set_mplsogre_decap_set,
13335                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13336                 (void *)&cmd_set_mplsogre_decap_ip_version,
13337                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13338                 NULL,
13339         },
13340 };
13341
13342 /** Set MPLSoUDP encapsulation details */
13343 struct cmd_set_mplsoudp_encap_result {
13344         cmdline_fixed_string_t set;
13345         cmdline_fixed_string_t mplsoudp;
13346         cmdline_fixed_string_t pos_token;
13347         cmdline_fixed_string_t ip_version;
13348         uint32_t vlan_present:1;
13349         uint32_t label;
13350         uint16_t udp_src;
13351         uint16_t udp_dst;
13352         cmdline_ipaddr_t ip_src;
13353         cmdline_ipaddr_t ip_dst;
13354         uint16_t tci;
13355         struct rte_ether_addr eth_src;
13356         struct rte_ether_addr eth_dst;
13357 };
13358
13359 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13360         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13361                                  "set");
13362 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13363         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13364                                  "mplsoudp_encap");
13365 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13366         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13367                                  mplsoudp, "mplsoudp_encap-with-vlan");
13368 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13369         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13370                                  pos_token, "ip-version");
13371 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13372         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13373                                  ip_version, "ipv4#ipv6");
13374 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13375         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13376                                  pos_token, "label");
13377 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13378         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13379                               UINT32);
13380 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13381         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13382                                  pos_token, "udp-src");
13383 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13384         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13385                               UINT16);
13386 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13387         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13388                                  pos_token, "udp-dst");
13389 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13390         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13391                               UINT16);
13392 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13393         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13394                                  pos_token, "ip-src");
13395 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13396         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13397 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13398         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13399                                  pos_token, "ip-dst");
13400 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13401         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13402 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13403         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13404                                  pos_token, "vlan-tci");
13405 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13406         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13407                               UINT16);
13408 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13409         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13410                                  pos_token, "eth-src");
13411 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13412         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13413                                     eth_src);
13414 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13415         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13416                                  pos_token, "eth-dst");
13417 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13418         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13419                                     eth_dst);
13420
13421 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13422         __rte_unused struct cmdline *cl,
13423         __rte_unused void *data)
13424 {
13425         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13426         union {
13427                 uint32_t mplsoudp_label;
13428                 uint8_t label[4];
13429         } id = {
13430                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13431         };
13432
13433         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13434                 mplsoudp_encap_conf.select_vlan = 0;
13435         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13436                 mplsoudp_encap_conf.select_vlan = 1;
13437         if (strcmp(res->ip_version, "ipv4") == 0)
13438                 mplsoudp_encap_conf.select_ipv4 = 1;
13439         else if (strcmp(res->ip_version, "ipv6") == 0)
13440                 mplsoudp_encap_conf.select_ipv4 = 0;
13441         else
13442                 return;
13443         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13444         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13445         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13446         if (mplsoudp_encap_conf.select_ipv4) {
13447                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13448                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13449         } else {
13450                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13451                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13452         }
13453         if (mplsoudp_encap_conf.select_vlan)
13454                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13455         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13456                    RTE_ETHER_ADDR_LEN);
13457         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13458                    RTE_ETHER_ADDR_LEN);
13459 }
13460
13461 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13462         .f = cmd_set_mplsoudp_encap_parsed,
13463         .data = NULL,
13464         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13465                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13466                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13467         .tokens = {
13468                 (void *)&cmd_set_mplsoudp_encap_set,
13469                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13470                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13471                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13472                 (void *)&cmd_set_mplsoudp_encap_label,
13473                 (void *)&cmd_set_mplsoudp_encap_label_value,
13474                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13475                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13476                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13477                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13478                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13479                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13480                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13481                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13482                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13483                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13484                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13485                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13486                 NULL,
13487         },
13488 };
13489
13490 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13491         .f = cmd_set_mplsoudp_encap_parsed,
13492         .data = NULL,
13493         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13494                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13495                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13496                 " eth-src <eth-src> eth-dst <eth-dst>",
13497         .tokens = {
13498                 (void *)&cmd_set_mplsoudp_encap_set,
13499                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13500                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13501                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13502                 (void *)&cmd_set_mplsoudp_encap_label,
13503                 (void *)&cmd_set_mplsoudp_encap_label_value,
13504                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13505                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13506                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13507                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13508                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13509                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13510                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13511                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13512                 (void *)&cmd_set_mplsoudp_encap_vlan,
13513                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13514                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13515                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13516                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13517                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13518                 NULL,
13519         },
13520 };
13521
13522 /** Set MPLSoUDP decapsulation details */
13523 struct cmd_set_mplsoudp_decap_result {
13524         cmdline_fixed_string_t set;
13525         cmdline_fixed_string_t mplsoudp;
13526         cmdline_fixed_string_t pos_token;
13527         cmdline_fixed_string_t ip_version;
13528         uint32_t vlan_present:1;
13529 };
13530
13531 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13532         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13533                                  "set");
13534 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13535         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13536                                  "mplsoudp_decap");
13537 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13538         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13539                                  mplsoudp, "mplsoudp_decap-with-vlan");
13540 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13541         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13542                                  pos_token, "ip-version");
13543 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13544         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13545                                  ip_version, "ipv4#ipv6");
13546
13547 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13548         __rte_unused struct cmdline *cl,
13549         __rte_unused void *data)
13550 {
13551         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13552
13553         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13554                 mplsoudp_decap_conf.select_vlan = 0;
13555         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13556                 mplsoudp_decap_conf.select_vlan = 1;
13557         if (strcmp(res->ip_version, "ipv4") == 0)
13558                 mplsoudp_decap_conf.select_ipv4 = 1;
13559         else if (strcmp(res->ip_version, "ipv6") == 0)
13560                 mplsoudp_decap_conf.select_ipv4 = 0;
13561 }
13562
13563 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13564         .f = cmd_set_mplsoudp_decap_parsed,
13565         .data = NULL,
13566         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13567         .tokens = {
13568                 (void *)&cmd_set_mplsoudp_decap_set,
13569                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13570                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13571                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13572                 NULL,
13573         },
13574 };
13575
13576 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13577         .f = cmd_set_mplsoudp_decap_parsed,
13578         .data = NULL,
13579         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13580         .tokens = {
13581                 (void *)&cmd_set_mplsoudp_decap_set,
13582                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13583                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13584                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13585                 NULL,
13586         },
13587 };
13588
13589 /* Strict link priority scheduling mode setting */
13590 static void
13591 cmd_strict_link_prio_parsed(
13592         void *parsed_result,
13593         __rte_unused struct cmdline *cl,
13594         __rte_unused void *data)
13595 {
13596         struct cmd_vf_tc_bw_result *res = parsed_result;
13597         int ret = -ENOTSUP;
13598
13599         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13600                 return;
13601
13602 #ifdef RTE_NET_I40E
13603         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13604 #endif
13605
13606         switch (ret) {
13607         case 0:
13608                 break;
13609         case -EINVAL:
13610                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13611                 break;
13612         case -ENODEV:
13613                 printf("invalid port_id %d\n", res->port_id);
13614                 break;
13615         case -ENOTSUP:
13616                 printf("function not implemented\n");
13617                 break;
13618         default:
13619                 printf("programming error: (%s)\n", strerror(-ret));
13620         }
13621 }
13622
13623 cmdline_parse_inst_t cmd_strict_link_prio = {
13624         .f = cmd_strict_link_prio_parsed,
13625         .data = NULL,
13626         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13627         .tokens = {
13628                 (void *)&cmd_vf_tc_bw_set,
13629                 (void *)&cmd_vf_tc_bw_tx,
13630                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13631                 (void *)&cmd_vf_tc_bw_port_id,
13632                 (void *)&cmd_vf_tc_bw_tc_map,
13633                 NULL,
13634         },
13635 };
13636
13637 /* Load dynamic device personalization*/
13638 struct cmd_ddp_add_result {
13639         cmdline_fixed_string_t ddp;
13640         cmdline_fixed_string_t add;
13641         portid_t port_id;
13642         char filepath[];
13643 };
13644
13645 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13646         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13647 cmdline_parse_token_string_t cmd_ddp_add_add =
13648         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13649 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13650         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
13651 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13653
13654 static void
13655 cmd_ddp_add_parsed(
13656         void *parsed_result,
13657         __rte_unused struct cmdline *cl,
13658         __rte_unused void *data)
13659 {
13660         struct cmd_ddp_add_result *res = parsed_result;
13661         uint8_t *buff;
13662         uint32_t size;
13663         char *filepath;
13664         char *file_fld[2];
13665         int file_num;
13666         int ret = -ENOTSUP;
13667
13668         if (!all_ports_stopped()) {
13669                 printf("Please stop all ports first\n");
13670                 return;
13671         }
13672
13673         filepath = strdup(res->filepath);
13674         if (filepath == NULL) {
13675                 printf("Failed to allocate memory\n");
13676                 return;
13677         }
13678         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13679
13680         buff = open_file(file_fld[0], &size);
13681         if (!buff) {
13682                 free((void *)filepath);
13683                 return;
13684         }
13685
13686 #ifdef RTE_NET_I40E
13687         if (ret == -ENOTSUP)
13688                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13689                                                buff, size,
13690                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13691 #endif
13692
13693         if (ret == -EEXIST)
13694                 printf("Profile has already existed.\n");
13695         else if (ret < 0)
13696                 printf("Failed to load profile.\n");
13697         else if (file_num == 2)
13698                 save_file(file_fld[1], buff, size);
13699
13700         close_file(buff);
13701         free((void *)filepath);
13702 }
13703
13704 cmdline_parse_inst_t cmd_ddp_add = {
13705         .f = cmd_ddp_add_parsed,
13706         .data = NULL,
13707         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13708         .tokens = {
13709                 (void *)&cmd_ddp_add_ddp,
13710                 (void *)&cmd_ddp_add_add,
13711                 (void *)&cmd_ddp_add_port_id,
13712                 (void *)&cmd_ddp_add_filepath,
13713                 NULL,
13714         },
13715 };
13716
13717 /* Delete dynamic device personalization*/
13718 struct cmd_ddp_del_result {
13719         cmdline_fixed_string_t ddp;
13720         cmdline_fixed_string_t del;
13721         portid_t port_id;
13722         char filepath[];
13723 };
13724
13725 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13726         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13727 cmdline_parse_token_string_t cmd_ddp_del_del =
13728         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13729 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13730         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
13731 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13732         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13733
13734 static void
13735 cmd_ddp_del_parsed(
13736         void *parsed_result,
13737         __rte_unused struct cmdline *cl,
13738         __rte_unused void *data)
13739 {
13740         struct cmd_ddp_del_result *res = parsed_result;
13741         uint8_t *buff;
13742         uint32_t size;
13743         int ret = -ENOTSUP;
13744
13745         if (!all_ports_stopped()) {
13746                 printf("Please stop all ports first\n");
13747                 return;
13748         }
13749
13750         buff = open_file(res->filepath, &size);
13751         if (!buff)
13752                 return;
13753
13754 #ifdef RTE_NET_I40E
13755         if (ret == -ENOTSUP)
13756                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13757                                                buff, size,
13758                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13759 #endif
13760
13761         if (ret == -EACCES)
13762                 printf("Profile does not exist.\n");
13763         else if (ret < 0)
13764                 printf("Failed to delete profile.\n");
13765
13766         close_file(buff);
13767 }
13768
13769 cmdline_parse_inst_t cmd_ddp_del = {
13770         .f = cmd_ddp_del_parsed,
13771         .data = NULL,
13772         .help_str = "ddp del <port_id> <backup_profile_path>",
13773         .tokens = {
13774                 (void *)&cmd_ddp_del_ddp,
13775                 (void *)&cmd_ddp_del_del,
13776                 (void *)&cmd_ddp_del_port_id,
13777                 (void *)&cmd_ddp_del_filepath,
13778                 NULL,
13779         },
13780 };
13781
13782 /* Get dynamic device personalization profile info */
13783 struct cmd_ddp_info_result {
13784         cmdline_fixed_string_t ddp;
13785         cmdline_fixed_string_t get;
13786         cmdline_fixed_string_t info;
13787         char filepath[];
13788 };
13789
13790 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13791         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13792 cmdline_parse_token_string_t cmd_ddp_info_get =
13793         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13794 cmdline_parse_token_string_t cmd_ddp_info_info =
13795         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13796 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13797         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13798
13799 static void
13800 cmd_ddp_info_parsed(
13801         void *parsed_result,
13802         __rte_unused struct cmdline *cl,
13803         __rte_unused void *data)
13804 {
13805         struct cmd_ddp_info_result *res = parsed_result;
13806         uint8_t *pkg;
13807         uint32_t pkg_size;
13808         int ret = -ENOTSUP;
13809 #ifdef RTE_NET_I40E
13810         uint32_t i, j, n;
13811         uint8_t *buff;
13812         uint32_t buff_size = 0;
13813         struct rte_pmd_i40e_profile_info info;
13814         uint32_t dev_num = 0;
13815         struct rte_pmd_i40e_ddp_device_id *devs;
13816         uint32_t proto_num = 0;
13817         struct rte_pmd_i40e_proto_info *proto = NULL;
13818         uint32_t pctype_num = 0;
13819         struct rte_pmd_i40e_ptype_info *pctype;
13820         uint32_t ptype_num = 0;
13821         struct rte_pmd_i40e_ptype_info *ptype;
13822         uint8_t proto_id;
13823
13824 #endif
13825
13826         pkg = open_file(res->filepath, &pkg_size);
13827         if (!pkg)
13828                 return;
13829
13830 #ifdef RTE_NET_I40E
13831         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13832                                 (uint8_t *)&info, sizeof(info),
13833                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13834         if (!ret) {
13835                 printf("Global Track id:       0x%x\n", info.track_id);
13836                 printf("Global Version:        %d.%d.%d.%d\n",
13837                         info.version.major,
13838                         info.version.minor,
13839                         info.version.update,
13840                         info.version.draft);
13841                 printf("Global Package name:   %s\n\n", info.name);
13842         }
13843
13844         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13845                                 (uint8_t *)&info, sizeof(info),
13846                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13847         if (!ret) {
13848                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13849                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13850                         info.version.major,
13851                         info.version.minor,
13852                         info.version.update,
13853                         info.version.draft);
13854                 printf("i40e Profile name:     %s\n\n", info.name);
13855         }
13856
13857         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13858                                 (uint8_t *)&buff_size, sizeof(buff_size),
13859                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13860         if (!ret && buff_size) {
13861                 buff = (uint8_t *)malloc(buff_size);
13862                 if (buff) {
13863                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13864                                                 buff, buff_size,
13865                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13866                         if (!ret)
13867                                 printf("Package Notes:\n%s\n\n", buff);
13868                         free(buff);
13869                 }
13870         }
13871
13872         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13873                                 (uint8_t *)&dev_num, sizeof(dev_num),
13874                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13875         if (!ret && dev_num) {
13876                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13877                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13878                 if (devs) {
13879                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13880                                                 (uint8_t *)devs, buff_size,
13881                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13882                         if (!ret) {
13883                                 printf("List of supported devices:\n");
13884                                 for (i = 0; i < dev_num; i++) {
13885                                         printf("  %04X:%04X %04X:%04X\n",
13886                                                 devs[i].vendor_dev_id >> 16,
13887                                                 devs[i].vendor_dev_id & 0xFFFF,
13888                                                 devs[i].sub_vendor_dev_id >> 16,
13889                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13890                                 }
13891                                 printf("\n");
13892                         }
13893                         free(devs);
13894                 }
13895         }
13896
13897         /* get information about protocols and packet types */
13898         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13899                 (uint8_t *)&proto_num, sizeof(proto_num),
13900                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13901         if (ret || !proto_num)
13902                 goto no_print_return;
13903
13904         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13905         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13906         if (!proto)
13907                 goto no_print_return;
13908
13909         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13910                                         buff_size,
13911                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13912         if (!ret) {
13913                 printf("List of used protocols:\n");
13914                 for (i = 0; i < proto_num; i++)
13915                         printf("  %2u: %s\n", proto[i].proto_id,
13916                                proto[i].name);
13917                 printf("\n");
13918         }
13919         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13920                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13921                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13922         if (ret || !pctype_num)
13923                 goto no_print_pctypes;
13924
13925         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13926         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13927         if (!pctype)
13928                 goto no_print_pctypes;
13929
13930         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13931                                         buff_size,
13932                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13933         if (ret) {
13934                 free(pctype);
13935                 goto no_print_pctypes;
13936         }
13937
13938         printf("List of defined packet classification types:\n");
13939         for (i = 0; i < pctype_num; i++) {
13940                 printf("  %2u:", pctype[i].ptype_id);
13941                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13942                         proto_id = pctype[i].protocols[j];
13943                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13944                                 for (n = 0; n < proto_num; n++) {
13945                                         if (proto[n].proto_id == proto_id) {
13946                                                 printf(" %s", proto[n].name);
13947                                                 break;
13948                                         }
13949                                 }
13950                         }
13951                 }
13952                 printf("\n");
13953         }
13954         printf("\n");
13955         free(pctype);
13956
13957 no_print_pctypes:
13958
13959         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13960                                         sizeof(ptype_num),
13961                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13962         if (ret || !ptype_num)
13963                 goto no_print_return;
13964
13965         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13966         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13967         if (!ptype)
13968                 goto no_print_return;
13969
13970         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13971                                         buff_size,
13972                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13973         if (ret) {
13974                 free(ptype);
13975                 goto no_print_return;
13976         }
13977         printf("List of defined packet types:\n");
13978         for (i = 0; i < ptype_num; i++) {
13979                 printf("  %2u:", ptype[i].ptype_id);
13980                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13981                         proto_id = ptype[i].protocols[j];
13982                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13983                                 for (n = 0; n < proto_num; n++) {
13984                                         if (proto[n].proto_id == proto_id) {
13985                                                 printf(" %s", proto[n].name);
13986                                                 break;
13987                                         }
13988                                 }
13989                         }
13990                 }
13991                 printf("\n");
13992         }
13993         free(ptype);
13994         printf("\n");
13995
13996         ret = 0;
13997 no_print_return:
13998         if (proto)
13999                 free(proto);
14000 #endif
14001         if (ret == -ENOTSUP)
14002                 printf("Function not supported in PMD driver\n");
14003         close_file(pkg);
14004 }
14005
14006 cmdline_parse_inst_t cmd_ddp_get_info = {
14007         .f = cmd_ddp_info_parsed,
14008         .data = NULL,
14009         .help_str = "ddp get info <profile_path>",
14010         .tokens = {
14011                 (void *)&cmd_ddp_info_ddp,
14012                 (void *)&cmd_ddp_info_get,
14013                 (void *)&cmd_ddp_info_info,
14014                 (void *)&cmd_ddp_info_filepath,
14015                 NULL,
14016         },
14017 };
14018
14019 /* Get dynamic device personalization profile info list*/
14020 #define PROFILE_INFO_SIZE 48
14021 #define MAX_PROFILE_NUM 16
14022
14023 struct cmd_ddp_get_list_result {
14024         cmdline_fixed_string_t ddp;
14025         cmdline_fixed_string_t get;
14026         cmdline_fixed_string_t list;
14027         portid_t port_id;
14028 };
14029
14030 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14031         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14032 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14033         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14034 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14035         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14036 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14037         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14038
14039 static void
14040 cmd_ddp_get_list_parsed(
14041         __rte_unused void *parsed_result,
14042         __rte_unused struct cmdline *cl,
14043         __rte_unused void *data)
14044 {
14045 #ifdef RTE_NET_I40E
14046         struct cmd_ddp_get_list_result *res = parsed_result;
14047         struct rte_pmd_i40e_profile_list *p_list;
14048         struct rte_pmd_i40e_profile_info *p_info;
14049         uint32_t p_num;
14050         uint32_t size;
14051         uint32_t i;
14052 #endif
14053         int ret = -ENOTSUP;
14054
14055 #ifdef RTE_NET_I40E
14056         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14057         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14058         if (!p_list) {
14059                 printf("%s: Failed to malloc buffer\n", __func__);
14060                 return;
14061         }
14062
14063         if (ret == -ENOTSUP)
14064                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14065                                                 (uint8_t *)p_list, size);
14066
14067         if (!ret) {
14068                 p_num = p_list->p_count;
14069                 printf("Profile number is: %d\n\n", p_num);
14070
14071                 for (i = 0; i < p_num; i++) {
14072                         p_info = &p_list->p_info[i];
14073                         printf("Profile %d:\n", i);
14074                         printf("Track id:     0x%x\n", p_info->track_id);
14075                         printf("Version:      %d.%d.%d.%d\n",
14076                                p_info->version.major,
14077                                p_info->version.minor,
14078                                p_info->version.update,
14079                                p_info->version.draft);
14080                         printf("Profile name: %s\n\n", p_info->name);
14081                 }
14082         }
14083
14084         free(p_list);
14085 #endif
14086
14087         if (ret < 0)
14088                 printf("Failed to get ddp list\n");
14089 }
14090
14091 cmdline_parse_inst_t cmd_ddp_get_list = {
14092         .f = cmd_ddp_get_list_parsed,
14093         .data = NULL,
14094         .help_str = "ddp get list <port_id>",
14095         .tokens = {
14096                 (void *)&cmd_ddp_get_list_ddp,
14097                 (void *)&cmd_ddp_get_list_get,
14098                 (void *)&cmd_ddp_get_list_list,
14099                 (void *)&cmd_ddp_get_list_port_id,
14100                 NULL,
14101         },
14102 };
14103
14104 /* Configure input set */
14105 struct cmd_cfg_input_set_result {
14106         cmdline_fixed_string_t port;
14107         cmdline_fixed_string_t cfg;
14108         portid_t port_id;
14109         cmdline_fixed_string_t pctype;
14110         uint8_t pctype_id;
14111         cmdline_fixed_string_t inset_type;
14112         cmdline_fixed_string_t opt;
14113         cmdline_fixed_string_t field;
14114         uint8_t field_idx;
14115 };
14116
14117 static void
14118 cmd_cfg_input_set_parsed(
14119         __rte_unused void *parsed_result,
14120         __rte_unused struct cmdline *cl,
14121         __rte_unused void *data)
14122 {
14123 #ifdef RTE_NET_I40E
14124         struct cmd_cfg_input_set_result *res = parsed_result;
14125         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14126         struct rte_pmd_i40e_inset inset;
14127 #endif
14128         int ret = -ENOTSUP;
14129
14130         if (!all_ports_stopped()) {
14131                 printf("Please stop all ports first\n");
14132                 return;
14133         }
14134
14135 #ifdef RTE_NET_I40E
14136         if (!strcmp(res->inset_type, "hash_inset"))
14137                 inset_type = INSET_HASH;
14138         else if (!strcmp(res->inset_type, "fdir_inset"))
14139                 inset_type = INSET_FDIR;
14140         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14141                 inset_type = INSET_FDIR_FLX;
14142         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14143                                      &inset, inset_type);
14144         if (ret) {
14145                 printf("Failed to get input set.\n");
14146                 return;
14147         }
14148
14149         if (!strcmp(res->opt, "get")) {
14150                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14151                                                    res->field_idx);
14152                 if (ret)
14153                         printf("Field index %d is enabled.\n", res->field_idx);
14154                 else
14155                         printf("Field index %d is disabled.\n", res->field_idx);
14156                 return;
14157         } else if (!strcmp(res->opt, "set"))
14158                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14159                                                    res->field_idx);
14160         else if (!strcmp(res->opt, "clear"))
14161                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14162                                                      res->field_idx);
14163         if (ret) {
14164                 printf("Failed to configure input set field.\n");
14165                 return;
14166         }
14167
14168         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14169                                      &inset, inset_type);
14170         if (ret) {
14171                 printf("Failed to set input set.\n");
14172                 return;
14173         }
14174 #endif
14175
14176         if (ret == -ENOTSUP)
14177                 printf("Function not supported\n");
14178 }
14179
14180 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14181         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14182                                  port, "port");
14183 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14184         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14185                                  cfg, "config");
14186 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14187         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14188                               port_id, UINT16);
14189 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14190         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14191                                  pctype, "pctype");
14192 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14193         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14194                               pctype_id, UINT8);
14195 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14196         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14197                                  inset_type,
14198                                  "hash_inset#fdir_inset#fdir_flx_inset");
14199 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14200         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14201                                  opt, "get#set#clear");
14202 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14203         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14204                                  field, "field");
14205 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14206         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14207                               field_idx, UINT8);
14208
14209 cmdline_parse_inst_t cmd_cfg_input_set = {
14210         .f = cmd_cfg_input_set_parsed,
14211         .data = NULL,
14212         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14213                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14214         .tokens = {
14215                 (void *)&cmd_cfg_input_set_port,
14216                 (void *)&cmd_cfg_input_set_cfg,
14217                 (void *)&cmd_cfg_input_set_port_id,
14218                 (void *)&cmd_cfg_input_set_pctype,
14219                 (void *)&cmd_cfg_input_set_pctype_id,
14220                 (void *)&cmd_cfg_input_set_inset_type,
14221                 (void *)&cmd_cfg_input_set_opt,
14222                 (void *)&cmd_cfg_input_set_field,
14223                 (void *)&cmd_cfg_input_set_field_idx,
14224                 NULL,
14225         },
14226 };
14227
14228 /* Clear input set */
14229 struct cmd_clear_input_set_result {
14230         cmdline_fixed_string_t port;
14231         cmdline_fixed_string_t cfg;
14232         portid_t port_id;
14233         cmdline_fixed_string_t pctype;
14234         uint8_t pctype_id;
14235         cmdline_fixed_string_t inset_type;
14236         cmdline_fixed_string_t clear;
14237         cmdline_fixed_string_t all;
14238 };
14239
14240 static void
14241 cmd_clear_input_set_parsed(
14242         __rte_unused void *parsed_result,
14243         __rte_unused struct cmdline *cl,
14244         __rte_unused void *data)
14245 {
14246 #ifdef RTE_NET_I40E
14247         struct cmd_clear_input_set_result *res = parsed_result;
14248         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14249         struct rte_pmd_i40e_inset inset;
14250 #endif
14251         int ret = -ENOTSUP;
14252
14253         if (!all_ports_stopped()) {
14254                 printf("Please stop all ports first\n");
14255                 return;
14256         }
14257
14258 #ifdef RTE_NET_I40E
14259         if (!strcmp(res->inset_type, "hash_inset"))
14260                 inset_type = INSET_HASH;
14261         else if (!strcmp(res->inset_type, "fdir_inset"))
14262                 inset_type = INSET_FDIR;
14263         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14264                 inset_type = INSET_FDIR_FLX;
14265
14266         memset(&inset, 0, sizeof(inset));
14267
14268         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14269                                      &inset, inset_type);
14270         if (ret) {
14271                 printf("Failed to clear input set.\n");
14272                 return;
14273         }
14274
14275 #endif
14276
14277         if (ret == -ENOTSUP)
14278                 printf("Function not supported\n");
14279 }
14280
14281 cmdline_parse_token_string_t cmd_clear_input_set_port =
14282         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14283                                  port, "port");
14284 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14285         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14286                                  cfg, "config");
14287 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14288         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14289                               port_id, UINT16);
14290 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14291         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14292                                  pctype, "pctype");
14293 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14294         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14295                               pctype_id, UINT8);
14296 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14297         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14298                                  inset_type,
14299                                  "hash_inset#fdir_inset#fdir_flx_inset");
14300 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14301         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14302                                  clear, "clear");
14303 cmdline_parse_token_string_t cmd_clear_input_set_all =
14304         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14305                                  all, "all");
14306
14307 cmdline_parse_inst_t cmd_clear_input_set = {
14308         .f = cmd_clear_input_set_parsed,
14309         .data = NULL,
14310         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14311                     "fdir_inset|fdir_flx_inset clear all",
14312         .tokens = {
14313                 (void *)&cmd_clear_input_set_port,
14314                 (void *)&cmd_clear_input_set_cfg,
14315                 (void *)&cmd_clear_input_set_port_id,
14316                 (void *)&cmd_clear_input_set_pctype,
14317                 (void *)&cmd_clear_input_set_pctype_id,
14318                 (void *)&cmd_clear_input_set_inset_type,
14319                 (void *)&cmd_clear_input_set_clear,
14320                 (void *)&cmd_clear_input_set_all,
14321                 NULL,
14322         },
14323 };
14324
14325 /* show vf stats */
14326
14327 /* Common result structure for show vf stats */
14328 struct cmd_show_vf_stats_result {
14329         cmdline_fixed_string_t show;
14330         cmdline_fixed_string_t vf;
14331         cmdline_fixed_string_t stats;
14332         portid_t port_id;
14333         uint16_t vf_id;
14334 };
14335
14336 /* Common CLI fields show vf stats*/
14337 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14338         TOKEN_STRING_INITIALIZER
14339                 (struct cmd_show_vf_stats_result,
14340                  show, "show");
14341 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14342         TOKEN_STRING_INITIALIZER
14343                 (struct cmd_show_vf_stats_result,
14344                  vf, "vf");
14345 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14346         TOKEN_STRING_INITIALIZER
14347                 (struct cmd_show_vf_stats_result,
14348                  stats, "stats");
14349 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14350         TOKEN_NUM_INITIALIZER
14351                 (struct cmd_show_vf_stats_result,
14352                  port_id, UINT16);
14353 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14354         TOKEN_NUM_INITIALIZER
14355                 (struct cmd_show_vf_stats_result,
14356                  vf_id, UINT16);
14357
14358 static void
14359 cmd_show_vf_stats_parsed(
14360         void *parsed_result,
14361         __rte_unused struct cmdline *cl,
14362         __rte_unused void *data)
14363 {
14364         struct cmd_show_vf_stats_result *res = parsed_result;
14365         struct rte_eth_stats stats;
14366         int ret = -ENOTSUP;
14367         static const char *nic_stats_border = "########################";
14368
14369         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14370                 return;
14371
14372         memset(&stats, 0, sizeof(stats));
14373
14374 #ifdef RTE_NET_I40E
14375         if (ret == -ENOTSUP)
14376                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14377                                                 res->vf_id,
14378                                                 &stats);
14379 #endif
14380 #ifdef RTE_NET_BNXT
14381         if (ret == -ENOTSUP)
14382                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14383                                                 res->vf_id,
14384                                                 &stats);
14385 #endif
14386
14387         switch (ret) {
14388         case 0:
14389                 break;
14390         case -EINVAL:
14391                 printf("invalid vf_id %d\n", res->vf_id);
14392                 break;
14393         case -ENODEV:
14394                 printf("invalid port_id %d\n", res->port_id);
14395                 break;
14396         case -ENOTSUP:
14397                 printf("function not implemented\n");
14398                 break;
14399         default:
14400                 printf("programming error: (%s)\n", strerror(-ret));
14401         }
14402
14403         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14404                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14405
14406         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14407                "%-"PRIu64"\n",
14408                stats.ipackets, stats.imissed, stats.ibytes);
14409         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14410         printf("  RX-nombuf:  %-10"PRIu64"\n",
14411                stats.rx_nombuf);
14412         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14413                "%-"PRIu64"\n",
14414                stats.opackets, stats.oerrors, stats.obytes);
14415
14416         printf("  %s############################%s\n",
14417                                nic_stats_border, nic_stats_border);
14418 }
14419
14420 cmdline_parse_inst_t cmd_show_vf_stats = {
14421         .f = cmd_show_vf_stats_parsed,
14422         .data = NULL,
14423         .help_str = "show vf stats <port_id> <vf_id>",
14424         .tokens = {
14425                 (void *)&cmd_show_vf_stats_show,
14426                 (void *)&cmd_show_vf_stats_vf,
14427                 (void *)&cmd_show_vf_stats_stats,
14428                 (void *)&cmd_show_vf_stats_port_id,
14429                 (void *)&cmd_show_vf_stats_vf_id,
14430                 NULL,
14431         },
14432 };
14433
14434 /* clear vf stats */
14435
14436 /* Common result structure for clear vf stats */
14437 struct cmd_clear_vf_stats_result {
14438         cmdline_fixed_string_t clear;
14439         cmdline_fixed_string_t vf;
14440         cmdline_fixed_string_t stats;
14441         portid_t port_id;
14442         uint16_t vf_id;
14443 };
14444
14445 /* Common CLI fields clear vf stats*/
14446 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_clear_vf_stats_result,
14449                  clear, "clear");
14450 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_clear_vf_stats_result,
14453                  vf, "vf");
14454 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14455         TOKEN_STRING_INITIALIZER
14456                 (struct cmd_clear_vf_stats_result,
14457                  stats, "stats");
14458 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14459         TOKEN_NUM_INITIALIZER
14460                 (struct cmd_clear_vf_stats_result,
14461                  port_id, UINT16);
14462 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14463         TOKEN_NUM_INITIALIZER
14464                 (struct cmd_clear_vf_stats_result,
14465                  vf_id, UINT16);
14466
14467 static void
14468 cmd_clear_vf_stats_parsed(
14469         void *parsed_result,
14470         __rte_unused struct cmdline *cl,
14471         __rte_unused void *data)
14472 {
14473         struct cmd_clear_vf_stats_result *res = parsed_result;
14474         int ret = -ENOTSUP;
14475
14476         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14477                 return;
14478
14479 #ifdef RTE_NET_I40E
14480         if (ret == -ENOTSUP)
14481                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14482                                                   res->vf_id);
14483 #endif
14484 #ifdef RTE_NET_BNXT
14485         if (ret == -ENOTSUP)
14486                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14487                                                   res->vf_id);
14488 #endif
14489
14490         switch (ret) {
14491         case 0:
14492                 break;
14493         case -EINVAL:
14494                 printf("invalid vf_id %d\n", res->vf_id);
14495                 break;
14496         case -ENODEV:
14497                 printf("invalid port_id %d\n", res->port_id);
14498                 break;
14499         case -ENOTSUP:
14500                 printf("function not implemented\n");
14501                 break;
14502         default:
14503                 printf("programming error: (%s)\n", strerror(-ret));
14504         }
14505 }
14506
14507 cmdline_parse_inst_t cmd_clear_vf_stats = {
14508         .f = cmd_clear_vf_stats_parsed,
14509         .data = NULL,
14510         .help_str = "clear vf stats <port_id> <vf_id>",
14511         .tokens = {
14512                 (void *)&cmd_clear_vf_stats_clear,
14513                 (void *)&cmd_clear_vf_stats_vf,
14514                 (void *)&cmd_clear_vf_stats_stats,
14515                 (void *)&cmd_clear_vf_stats_port_id,
14516                 (void *)&cmd_clear_vf_stats_vf_id,
14517                 NULL,
14518         },
14519 };
14520
14521 /* port config pctype mapping reset */
14522
14523 /* Common result structure for port config pctype mapping reset */
14524 struct cmd_pctype_mapping_reset_result {
14525         cmdline_fixed_string_t port;
14526         cmdline_fixed_string_t config;
14527         portid_t port_id;
14528         cmdline_fixed_string_t pctype;
14529         cmdline_fixed_string_t mapping;
14530         cmdline_fixed_string_t reset;
14531 };
14532
14533 /* Common CLI fields for port config pctype mapping reset*/
14534 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14535         TOKEN_STRING_INITIALIZER
14536                 (struct cmd_pctype_mapping_reset_result,
14537                  port, "port");
14538 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14539         TOKEN_STRING_INITIALIZER
14540                 (struct cmd_pctype_mapping_reset_result,
14541                  config, "config");
14542 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14543         TOKEN_NUM_INITIALIZER
14544                 (struct cmd_pctype_mapping_reset_result,
14545                  port_id, UINT16);
14546 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14547         TOKEN_STRING_INITIALIZER
14548                 (struct cmd_pctype_mapping_reset_result,
14549                  pctype, "pctype");
14550 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14551         TOKEN_STRING_INITIALIZER
14552                 (struct cmd_pctype_mapping_reset_result,
14553                  mapping, "mapping");
14554 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14555         TOKEN_STRING_INITIALIZER
14556                 (struct cmd_pctype_mapping_reset_result,
14557                  reset, "reset");
14558
14559 static void
14560 cmd_pctype_mapping_reset_parsed(
14561         void *parsed_result,
14562         __rte_unused struct cmdline *cl,
14563         __rte_unused void *data)
14564 {
14565         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14566         int ret = -ENOTSUP;
14567
14568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14569                 return;
14570
14571 #ifdef RTE_NET_I40E
14572         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14573 #endif
14574
14575         switch (ret) {
14576         case 0:
14577                 break;
14578         case -ENODEV:
14579                 printf("invalid port_id %d\n", res->port_id);
14580                 break;
14581         case -ENOTSUP:
14582                 printf("function not implemented\n");
14583                 break;
14584         default:
14585                 printf("programming error: (%s)\n", strerror(-ret));
14586         }
14587 }
14588
14589 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14590         .f = cmd_pctype_mapping_reset_parsed,
14591         .data = NULL,
14592         .help_str = "port config <port_id> pctype mapping reset",
14593         .tokens = {
14594                 (void *)&cmd_pctype_mapping_reset_port,
14595                 (void *)&cmd_pctype_mapping_reset_config,
14596                 (void *)&cmd_pctype_mapping_reset_port_id,
14597                 (void *)&cmd_pctype_mapping_reset_pctype,
14598                 (void *)&cmd_pctype_mapping_reset_mapping,
14599                 (void *)&cmd_pctype_mapping_reset_reset,
14600                 NULL,
14601         },
14602 };
14603
14604 /* show port pctype mapping */
14605
14606 /* Common result structure for show port pctype mapping */
14607 struct cmd_pctype_mapping_get_result {
14608         cmdline_fixed_string_t show;
14609         cmdline_fixed_string_t port;
14610         portid_t port_id;
14611         cmdline_fixed_string_t pctype;
14612         cmdline_fixed_string_t mapping;
14613 };
14614
14615 /* Common CLI fields for pctype mapping get */
14616 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14617         TOKEN_STRING_INITIALIZER
14618                 (struct cmd_pctype_mapping_get_result,
14619                  show, "show");
14620 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14621         TOKEN_STRING_INITIALIZER
14622                 (struct cmd_pctype_mapping_get_result,
14623                  port, "port");
14624 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14625         TOKEN_NUM_INITIALIZER
14626                 (struct cmd_pctype_mapping_get_result,
14627                  port_id, UINT16);
14628 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14629         TOKEN_STRING_INITIALIZER
14630                 (struct cmd_pctype_mapping_get_result,
14631                  pctype, "pctype");
14632 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14633         TOKEN_STRING_INITIALIZER
14634                 (struct cmd_pctype_mapping_get_result,
14635                  mapping, "mapping");
14636
14637 static void
14638 cmd_pctype_mapping_get_parsed(
14639         void *parsed_result,
14640         __rte_unused struct cmdline *cl,
14641         __rte_unused void *data)
14642 {
14643         struct cmd_pctype_mapping_get_result *res = parsed_result;
14644         int ret = -ENOTSUP;
14645 #ifdef RTE_NET_I40E
14646         struct rte_pmd_i40e_flow_type_mapping
14647                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14648         int i, j, first_pctype;
14649 #endif
14650
14651         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14652                 return;
14653
14654 #ifdef RTE_NET_I40E
14655         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14656 #endif
14657
14658         switch (ret) {
14659         case 0:
14660                 break;
14661         case -ENODEV:
14662                 printf("invalid port_id %d\n", res->port_id);
14663                 return;
14664         case -ENOTSUP:
14665                 printf("function not implemented\n");
14666                 return;
14667         default:
14668                 printf("programming error: (%s)\n", strerror(-ret));
14669                 return;
14670         }
14671
14672 #ifdef RTE_NET_I40E
14673         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14674                 if (mapping[i].pctype != 0ULL) {
14675                         first_pctype = 1;
14676
14677                         printf("pctype: ");
14678                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14679                                 if (mapping[i].pctype & (1ULL << j)) {
14680                                         printf(first_pctype ?
14681                                                "%02d" : ",%02d", j);
14682                                         first_pctype = 0;
14683                                 }
14684                         }
14685                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14686                 }
14687         }
14688 #endif
14689 }
14690
14691 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14692         .f = cmd_pctype_mapping_get_parsed,
14693         .data = NULL,
14694         .help_str = "show port <port_id> pctype mapping",
14695         .tokens = {
14696                 (void *)&cmd_pctype_mapping_get_show,
14697                 (void *)&cmd_pctype_mapping_get_port,
14698                 (void *)&cmd_pctype_mapping_get_port_id,
14699                 (void *)&cmd_pctype_mapping_get_pctype,
14700                 (void *)&cmd_pctype_mapping_get_mapping,
14701                 NULL,
14702         },
14703 };
14704
14705 /* port config pctype mapping update */
14706
14707 /* Common result structure for port config pctype mapping update */
14708 struct cmd_pctype_mapping_update_result {
14709         cmdline_fixed_string_t port;
14710         cmdline_fixed_string_t config;
14711         portid_t port_id;
14712         cmdline_fixed_string_t pctype;
14713         cmdline_fixed_string_t mapping;
14714         cmdline_fixed_string_t update;
14715         cmdline_fixed_string_t pctype_list;
14716         uint16_t flow_type;
14717 };
14718
14719 /* Common CLI fields for pctype mapping update*/
14720 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14721         TOKEN_STRING_INITIALIZER
14722                 (struct cmd_pctype_mapping_update_result,
14723                  port, "port");
14724 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14725         TOKEN_STRING_INITIALIZER
14726                 (struct cmd_pctype_mapping_update_result,
14727                  config, "config");
14728 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14729         TOKEN_NUM_INITIALIZER
14730                 (struct cmd_pctype_mapping_update_result,
14731                  port_id, UINT16);
14732 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14733         TOKEN_STRING_INITIALIZER
14734                 (struct cmd_pctype_mapping_update_result,
14735                  pctype, "pctype");
14736 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14737         TOKEN_STRING_INITIALIZER
14738                 (struct cmd_pctype_mapping_update_result,
14739                  mapping, "mapping");
14740 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14741         TOKEN_STRING_INITIALIZER
14742                 (struct cmd_pctype_mapping_update_result,
14743                  update, "update");
14744 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14745         TOKEN_STRING_INITIALIZER
14746                 (struct cmd_pctype_mapping_update_result,
14747                  pctype_list, NULL);
14748 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14749         TOKEN_NUM_INITIALIZER
14750                 (struct cmd_pctype_mapping_update_result,
14751                  flow_type, UINT16);
14752
14753 static void
14754 cmd_pctype_mapping_update_parsed(
14755         void *parsed_result,
14756         __rte_unused struct cmdline *cl,
14757         __rte_unused void *data)
14758 {
14759         struct cmd_pctype_mapping_update_result *res = parsed_result;
14760         int ret = -ENOTSUP;
14761 #ifdef RTE_NET_I40E
14762         struct rte_pmd_i40e_flow_type_mapping mapping;
14763         unsigned int i;
14764         unsigned int nb_item;
14765         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14766 #endif
14767
14768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14769                 return;
14770
14771 #ifdef RTE_NET_I40E
14772         nb_item = parse_item_list(res->pctype_list, "pctypes",
14773                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14774         mapping.flow_type = res->flow_type;
14775         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14776                 mapping.pctype |= (1ULL << pctype_list[i]);
14777         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14778                                                 &mapping,
14779                                                 1,
14780                                                 0);
14781 #endif
14782
14783         switch (ret) {
14784         case 0:
14785                 break;
14786         case -EINVAL:
14787                 printf("invalid pctype or flow type\n");
14788                 break;
14789         case -ENODEV:
14790                 printf("invalid port_id %d\n", res->port_id);
14791                 break;
14792         case -ENOTSUP:
14793                 printf("function not implemented\n");
14794                 break;
14795         default:
14796                 printf("programming error: (%s)\n", strerror(-ret));
14797         }
14798 }
14799
14800 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14801         .f = cmd_pctype_mapping_update_parsed,
14802         .data = NULL,
14803         .help_str = "port config <port_id> pctype mapping update"
14804         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14805         .tokens = {
14806                 (void *)&cmd_pctype_mapping_update_port,
14807                 (void *)&cmd_pctype_mapping_update_config,
14808                 (void *)&cmd_pctype_mapping_update_port_id,
14809                 (void *)&cmd_pctype_mapping_update_pctype,
14810                 (void *)&cmd_pctype_mapping_update_mapping,
14811                 (void *)&cmd_pctype_mapping_update_update,
14812                 (void *)&cmd_pctype_mapping_update_pc_type,
14813                 (void *)&cmd_pctype_mapping_update_flow_type,
14814                 NULL,
14815         },
14816 };
14817
14818 /* ptype mapping get */
14819
14820 /* Common result structure for ptype mapping get */
14821 struct cmd_ptype_mapping_get_result {
14822         cmdline_fixed_string_t ptype;
14823         cmdline_fixed_string_t mapping;
14824         cmdline_fixed_string_t get;
14825         portid_t port_id;
14826         uint8_t valid_only;
14827 };
14828
14829 /* Common CLI fields for ptype mapping get */
14830 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14831         TOKEN_STRING_INITIALIZER
14832                 (struct cmd_ptype_mapping_get_result,
14833                  ptype, "ptype");
14834 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14835         TOKEN_STRING_INITIALIZER
14836                 (struct cmd_ptype_mapping_get_result,
14837                  mapping, "mapping");
14838 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14839         TOKEN_STRING_INITIALIZER
14840                 (struct cmd_ptype_mapping_get_result,
14841                  get, "get");
14842 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14843         TOKEN_NUM_INITIALIZER
14844                 (struct cmd_ptype_mapping_get_result,
14845                  port_id, UINT16);
14846 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14847         TOKEN_NUM_INITIALIZER
14848                 (struct cmd_ptype_mapping_get_result,
14849                  valid_only, UINT8);
14850
14851 static void
14852 cmd_ptype_mapping_get_parsed(
14853         void *parsed_result,
14854         __rte_unused struct cmdline *cl,
14855         __rte_unused void *data)
14856 {
14857         struct cmd_ptype_mapping_get_result *res = parsed_result;
14858         int ret = -ENOTSUP;
14859 #ifdef RTE_NET_I40E
14860         int max_ptype_num = 256;
14861         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14862         uint16_t count;
14863         int i;
14864 #endif
14865
14866         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14867                 return;
14868
14869 #ifdef RTE_NET_I40E
14870         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14871                                         mapping,
14872                                         max_ptype_num,
14873                                         &count,
14874                                         res->valid_only);
14875 #endif
14876
14877         switch (ret) {
14878         case 0:
14879                 break;
14880         case -ENODEV:
14881                 printf("invalid port_id %d\n", res->port_id);
14882                 break;
14883         case -ENOTSUP:
14884                 printf("function not implemented\n");
14885                 break;
14886         default:
14887                 printf("programming error: (%s)\n", strerror(-ret));
14888         }
14889
14890 #ifdef RTE_NET_I40E
14891         if (!ret) {
14892                 for (i = 0; i < count; i++)
14893                         printf("%3d\t0x%08x\n",
14894                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14895         }
14896 #endif
14897 }
14898
14899 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14900         .f = cmd_ptype_mapping_get_parsed,
14901         .data = NULL,
14902         .help_str = "ptype mapping get <port_id> <valid_only>",
14903         .tokens = {
14904                 (void *)&cmd_ptype_mapping_get_ptype,
14905                 (void *)&cmd_ptype_mapping_get_mapping,
14906                 (void *)&cmd_ptype_mapping_get_get,
14907                 (void *)&cmd_ptype_mapping_get_port_id,
14908                 (void *)&cmd_ptype_mapping_get_valid_only,
14909                 NULL,
14910         },
14911 };
14912
14913 /* ptype mapping replace */
14914
14915 /* Common result structure for ptype mapping replace */
14916 struct cmd_ptype_mapping_replace_result {
14917         cmdline_fixed_string_t ptype;
14918         cmdline_fixed_string_t mapping;
14919         cmdline_fixed_string_t replace;
14920         portid_t port_id;
14921         uint32_t target;
14922         uint8_t mask;
14923         uint32_t pkt_type;
14924 };
14925
14926 /* Common CLI fields for ptype mapping replace */
14927 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14928         TOKEN_STRING_INITIALIZER
14929                 (struct cmd_ptype_mapping_replace_result,
14930                  ptype, "ptype");
14931 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14932         TOKEN_STRING_INITIALIZER
14933                 (struct cmd_ptype_mapping_replace_result,
14934                  mapping, "mapping");
14935 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14936         TOKEN_STRING_INITIALIZER
14937                 (struct cmd_ptype_mapping_replace_result,
14938                  replace, "replace");
14939 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14940         TOKEN_NUM_INITIALIZER
14941                 (struct cmd_ptype_mapping_replace_result,
14942                  port_id, UINT16);
14943 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14944         TOKEN_NUM_INITIALIZER
14945                 (struct cmd_ptype_mapping_replace_result,
14946                  target, UINT32);
14947 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14948         TOKEN_NUM_INITIALIZER
14949                 (struct cmd_ptype_mapping_replace_result,
14950                  mask, UINT8);
14951 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14952         TOKEN_NUM_INITIALIZER
14953                 (struct cmd_ptype_mapping_replace_result,
14954                  pkt_type, UINT32);
14955
14956 static void
14957 cmd_ptype_mapping_replace_parsed(
14958         void *parsed_result,
14959         __rte_unused struct cmdline *cl,
14960         __rte_unused void *data)
14961 {
14962         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14963         int ret = -ENOTSUP;
14964
14965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14966                 return;
14967
14968 #ifdef RTE_NET_I40E
14969         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14970                                         res->target,
14971                                         res->mask,
14972                                         res->pkt_type);
14973 #endif
14974
14975         switch (ret) {
14976         case 0:
14977                 break;
14978         case -EINVAL:
14979                 printf("invalid ptype 0x%8x or 0x%8x\n",
14980                                 res->target, res->pkt_type);
14981                 break;
14982         case -ENODEV:
14983                 printf("invalid port_id %d\n", res->port_id);
14984                 break;
14985         case -ENOTSUP:
14986                 printf("function not implemented\n");
14987                 break;
14988         default:
14989                 printf("programming error: (%s)\n", strerror(-ret));
14990         }
14991 }
14992
14993 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14994         .f = cmd_ptype_mapping_replace_parsed,
14995         .data = NULL,
14996         .help_str =
14997                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14998         .tokens = {
14999                 (void *)&cmd_ptype_mapping_replace_ptype,
15000                 (void *)&cmd_ptype_mapping_replace_mapping,
15001                 (void *)&cmd_ptype_mapping_replace_replace,
15002                 (void *)&cmd_ptype_mapping_replace_port_id,
15003                 (void *)&cmd_ptype_mapping_replace_target,
15004                 (void *)&cmd_ptype_mapping_replace_mask,
15005                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15006                 NULL,
15007         },
15008 };
15009
15010 /* ptype mapping reset */
15011
15012 /* Common result structure for ptype mapping reset */
15013 struct cmd_ptype_mapping_reset_result {
15014         cmdline_fixed_string_t ptype;
15015         cmdline_fixed_string_t mapping;
15016         cmdline_fixed_string_t reset;
15017         portid_t port_id;
15018 };
15019
15020 /* Common CLI fields for ptype mapping reset*/
15021 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15022         TOKEN_STRING_INITIALIZER
15023                 (struct cmd_ptype_mapping_reset_result,
15024                  ptype, "ptype");
15025 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15026         TOKEN_STRING_INITIALIZER
15027                 (struct cmd_ptype_mapping_reset_result,
15028                  mapping, "mapping");
15029 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15030         TOKEN_STRING_INITIALIZER
15031                 (struct cmd_ptype_mapping_reset_result,
15032                  reset, "reset");
15033 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15034         TOKEN_NUM_INITIALIZER
15035                 (struct cmd_ptype_mapping_reset_result,
15036                  port_id, UINT16);
15037
15038 static void
15039 cmd_ptype_mapping_reset_parsed(
15040         void *parsed_result,
15041         __rte_unused struct cmdline *cl,
15042         __rte_unused void *data)
15043 {
15044         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15045         int ret = -ENOTSUP;
15046
15047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15048                 return;
15049
15050 #ifdef RTE_NET_I40E
15051         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15052 #endif
15053
15054         switch (ret) {
15055         case 0:
15056                 break;
15057         case -ENODEV:
15058                 printf("invalid port_id %d\n", res->port_id);
15059                 break;
15060         case -ENOTSUP:
15061                 printf("function not implemented\n");
15062                 break;
15063         default:
15064                 printf("programming error: (%s)\n", strerror(-ret));
15065         }
15066 }
15067
15068 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15069         .f = cmd_ptype_mapping_reset_parsed,
15070         .data = NULL,
15071         .help_str = "ptype mapping reset <port_id>",
15072         .tokens = {
15073                 (void *)&cmd_ptype_mapping_reset_ptype,
15074                 (void *)&cmd_ptype_mapping_reset_mapping,
15075                 (void *)&cmd_ptype_mapping_reset_reset,
15076                 (void *)&cmd_ptype_mapping_reset_port_id,
15077                 NULL,
15078         },
15079 };
15080
15081 /* ptype mapping update */
15082
15083 /* Common result structure for ptype mapping update */
15084 struct cmd_ptype_mapping_update_result {
15085         cmdline_fixed_string_t ptype;
15086         cmdline_fixed_string_t mapping;
15087         cmdline_fixed_string_t reset;
15088         portid_t port_id;
15089         uint8_t hw_ptype;
15090         uint32_t sw_ptype;
15091 };
15092
15093 /* Common CLI fields for ptype mapping update*/
15094 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15095         TOKEN_STRING_INITIALIZER
15096                 (struct cmd_ptype_mapping_update_result,
15097                  ptype, "ptype");
15098 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15099         TOKEN_STRING_INITIALIZER
15100                 (struct cmd_ptype_mapping_update_result,
15101                  mapping, "mapping");
15102 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15103         TOKEN_STRING_INITIALIZER
15104                 (struct cmd_ptype_mapping_update_result,
15105                  reset, "update");
15106 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15107         TOKEN_NUM_INITIALIZER
15108                 (struct cmd_ptype_mapping_update_result,
15109                  port_id, UINT16);
15110 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15111         TOKEN_NUM_INITIALIZER
15112                 (struct cmd_ptype_mapping_update_result,
15113                  hw_ptype, UINT8);
15114 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15115         TOKEN_NUM_INITIALIZER
15116                 (struct cmd_ptype_mapping_update_result,
15117                  sw_ptype, UINT32);
15118
15119 static void
15120 cmd_ptype_mapping_update_parsed(
15121         void *parsed_result,
15122         __rte_unused struct cmdline *cl,
15123         __rte_unused void *data)
15124 {
15125         struct cmd_ptype_mapping_update_result *res = parsed_result;
15126         int ret = -ENOTSUP;
15127 #ifdef RTE_NET_I40E
15128         struct rte_pmd_i40e_ptype_mapping mapping;
15129 #endif
15130         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15131                 return;
15132
15133 #ifdef RTE_NET_I40E
15134         mapping.hw_ptype = res->hw_ptype;
15135         mapping.sw_ptype = res->sw_ptype;
15136         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15137                                                 &mapping,
15138                                                 1,
15139                                                 0);
15140 #endif
15141
15142         switch (ret) {
15143         case 0:
15144                 break;
15145         case -EINVAL:
15146                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15147                 break;
15148         case -ENODEV:
15149                 printf("invalid port_id %d\n", res->port_id);
15150                 break;
15151         case -ENOTSUP:
15152                 printf("function not implemented\n");
15153                 break;
15154         default:
15155                 printf("programming error: (%s)\n", strerror(-ret));
15156         }
15157 }
15158
15159 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15160         .f = cmd_ptype_mapping_update_parsed,
15161         .data = NULL,
15162         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15163         .tokens = {
15164                 (void *)&cmd_ptype_mapping_update_ptype,
15165                 (void *)&cmd_ptype_mapping_update_mapping,
15166                 (void *)&cmd_ptype_mapping_update_update,
15167                 (void *)&cmd_ptype_mapping_update_port_id,
15168                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15169                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15170                 NULL,
15171         },
15172 };
15173
15174 /* Common result structure for file commands */
15175 struct cmd_cmdfile_result {
15176         cmdline_fixed_string_t load;
15177         cmdline_fixed_string_t filename;
15178 };
15179
15180 /* Common CLI fields for file commands */
15181 cmdline_parse_token_string_t cmd_load_cmdfile =
15182         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15183 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15184         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15185
15186 static void
15187 cmd_load_from_file_parsed(
15188         void *parsed_result,
15189         __rte_unused struct cmdline *cl,
15190         __rte_unused void *data)
15191 {
15192         struct cmd_cmdfile_result *res = parsed_result;
15193
15194         cmdline_read_from_file(res->filename);
15195 }
15196
15197 cmdline_parse_inst_t cmd_load_from_file = {
15198         .f = cmd_load_from_file_parsed,
15199         .data = NULL,
15200         .help_str = "load <filename>",
15201         .tokens = {
15202                 (void *)&cmd_load_cmdfile,
15203                 (void *)&cmd_load_cmdfile_filename,
15204                 NULL,
15205         },
15206 };
15207
15208 /* Get Rx offloads capabilities */
15209 struct cmd_rx_offload_get_capa_result {
15210         cmdline_fixed_string_t show;
15211         cmdline_fixed_string_t port;
15212         portid_t port_id;
15213         cmdline_fixed_string_t rx_offload;
15214         cmdline_fixed_string_t capabilities;
15215 };
15216
15217 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15218         TOKEN_STRING_INITIALIZER
15219                 (struct cmd_rx_offload_get_capa_result,
15220                  show, "show");
15221 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15222         TOKEN_STRING_INITIALIZER
15223                 (struct cmd_rx_offload_get_capa_result,
15224                  port, "port");
15225 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15226         TOKEN_NUM_INITIALIZER
15227                 (struct cmd_rx_offload_get_capa_result,
15228                  port_id, UINT16);
15229 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15230         TOKEN_STRING_INITIALIZER
15231                 (struct cmd_rx_offload_get_capa_result,
15232                  rx_offload, "rx_offload");
15233 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15234         TOKEN_STRING_INITIALIZER
15235                 (struct cmd_rx_offload_get_capa_result,
15236                  capabilities, "capabilities");
15237
15238 static void
15239 print_rx_offloads(uint64_t offloads)
15240 {
15241         uint64_t single_offload;
15242         int begin;
15243         int end;
15244         int bit;
15245
15246         if (offloads == 0)
15247                 return;
15248
15249         begin = __builtin_ctzll(offloads);
15250         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15251
15252         single_offload = 1ULL << begin;
15253         for (bit = begin; bit < end; bit++) {
15254                 if (offloads & single_offload)
15255                         printf(" %s",
15256                                rte_eth_dev_rx_offload_name(single_offload));
15257                 single_offload <<= 1;
15258         }
15259 }
15260
15261 static void
15262 cmd_rx_offload_get_capa_parsed(
15263         void *parsed_result,
15264         __rte_unused struct cmdline *cl,
15265         __rte_unused void *data)
15266 {
15267         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15268         struct rte_eth_dev_info dev_info;
15269         portid_t port_id = res->port_id;
15270         uint64_t queue_offloads;
15271         uint64_t port_offloads;
15272         int ret;
15273
15274         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15275         if (ret != 0)
15276                 return;
15277
15278         queue_offloads = dev_info.rx_queue_offload_capa;
15279         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15280
15281         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15282         printf("  Per Queue :");
15283         print_rx_offloads(queue_offloads);
15284
15285         printf("\n");
15286         printf("  Per Port  :");
15287         print_rx_offloads(port_offloads);
15288         printf("\n\n");
15289 }
15290
15291 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15292         .f = cmd_rx_offload_get_capa_parsed,
15293         .data = NULL,
15294         .help_str = "show port <port_id> rx_offload capabilities",
15295         .tokens = {
15296                 (void *)&cmd_rx_offload_get_capa_show,
15297                 (void *)&cmd_rx_offload_get_capa_port,
15298                 (void *)&cmd_rx_offload_get_capa_port_id,
15299                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15300                 (void *)&cmd_rx_offload_get_capa_capabilities,
15301                 NULL,
15302         }
15303 };
15304
15305 /* Get Rx offloads configuration */
15306 struct cmd_rx_offload_get_configuration_result {
15307         cmdline_fixed_string_t show;
15308         cmdline_fixed_string_t port;
15309         portid_t port_id;
15310         cmdline_fixed_string_t rx_offload;
15311         cmdline_fixed_string_t configuration;
15312 };
15313
15314 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15315         TOKEN_STRING_INITIALIZER
15316                 (struct cmd_rx_offload_get_configuration_result,
15317                  show, "show");
15318 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15319         TOKEN_STRING_INITIALIZER
15320                 (struct cmd_rx_offload_get_configuration_result,
15321                  port, "port");
15322 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15323         TOKEN_NUM_INITIALIZER
15324                 (struct cmd_rx_offload_get_configuration_result,
15325                  port_id, UINT16);
15326 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15327         TOKEN_STRING_INITIALIZER
15328                 (struct cmd_rx_offload_get_configuration_result,
15329                  rx_offload, "rx_offload");
15330 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15331         TOKEN_STRING_INITIALIZER
15332                 (struct cmd_rx_offload_get_configuration_result,
15333                  configuration, "configuration");
15334
15335 static void
15336 cmd_rx_offload_get_configuration_parsed(
15337         void *parsed_result,
15338         __rte_unused struct cmdline *cl,
15339         __rte_unused void *data)
15340 {
15341         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15342         struct rte_eth_dev_info dev_info;
15343         portid_t port_id = res->port_id;
15344         struct rte_port *port = &ports[port_id];
15345         uint64_t port_offloads;
15346         uint64_t queue_offloads;
15347         uint16_t nb_rx_queues;
15348         int q;
15349         int ret;
15350
15351         printf("Rx Offloading Configuration of port %d :\n", port_id);
15352
15353         port_offloads = port->dev_conf.rxmode.offloads;
15354         printf("  Port :");
15355         print_rx_offloads(port_offloads);
15356         printf("\n");
15357
15358         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15359         if (ret != 0)
15360                 return;
15361
15362         nb_rx_queues = dev_info.nb_rx_queues;
15363         for (q = 0; q < nb_rx_queues; q++) {
15364                 queue_offloads = port->rx_conf[q].offloads;
15365                 printf("  Queue[%2d] :", q);
15366                 print_rx_offloads(queue_offloads);
15367                 printf("\n");
15368         }
15369         printf("\n");
15370 }
15371
15372 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15373         .f = cmd_rx_offload_get_configuration_parsed,
15374         .data = NULL,
15375         .help_str = "show port <port_id> rx_offload configuration",
15376         .tokens = {
15377                 (void *)&cmd_rx_offload_get_configuration_show,
15378                 (void *)&cmd_rx_offload_get_configuration_port,
15379                 (void *)&cmd_rx_offload_get_configuration_port_id,
15380                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15381                 (void *)&cmd_rx_offload_get_configuration_configuration,
15382                 NULL,
15383         }
15384 };
15385
15386 /* Enable/Disable a per port offloading */
15387 struct cmd_config_per_port_rx_offload_result {
15388         cmdline_fixed_string_t port;
15389         cmdline_fixed_string_t config;
15390         portid_t port_id;
15391         cmdline_fixed_string_t rx_offload;
15392         cmdline_fixed_string_t offload;
15393         cmdline_fixed_string_t on_off;
15394 };
15395
15396 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15397         TOKEN_STRING_INITIALIZER
15398                 (struct cmd_config_per_port_rx_offload_result,
15399                  port, "port");
15400 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15401         TOKEN_STRING_INITIALIZER
15402                 (struct cmd_config_per_port_rx_offload_result,
15403                  config, "config");
15404 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15405         TOKEN_NUM_INITIALIZER
15406                 (struct cmd_config_per_port_rx_offload_result,
15407                  port_id, UINT16);
15408 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15409         TOKEN_STRING_INITIALIZER
15410                 (struct cmd_config_per_port_rx_offload_result,
15411                  rx_offload, "rx_offload");
15412 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15413         TOKEN_STRING_INITIALIZER
15414                 (struct cmd_config_per_port_rx_offload_result,
15415                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15416                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15417                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15418                            "scatter#buffer_split#timestamp#security#"
15419                            "keep_crc#rss_hash");
15420 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15421         TOKEN_STRING_INITIALIZER
15422                 (struct cmd_config_per_port_rx_offload_result,
15423                  on_off, "on#off");
15424
15425 static uint64_t
15426 search_rx_offload(const char *name)
15427 {
15428         uint64_t single_offload;
15429         const char *single_name;
15430         int found = 0;
15431         unsigned int bit;
15432
15433         single_offload = 1;
15434         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15435                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15436                 if (!strcasecmp(single_name, name)) {
15437                         found = 1;
15438                         break;
15439                 }
15440                 single_offload <<= 1;
15441         }
15442
15443         if (found)
15444                 return single_offload;
15445
15446         return 0;
15447 }
15448
15449 static void
15450 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15451                                 __rte_unused struct cmdline *cl,
15452                                 __rte_unused void *data)
15453 {
15454         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15455         portid_t port_id = res->port_id;
15456         struct rte_eth_dev_info dev_info;
15457         struct rte_port *port = &ports[port_id];
15458         uint64_t single_offload;
15459         uint16_t nb_rx_queues;
15460         int q;
15461         int ret;
15462
15463         if (port->port_status != RTE_PORT_STOPPED) {
15464                 printf("Error: Can't config offload when Port %d "
15465                        "is not stopped\n", port_id);
15466                 return;
15467         }
15468
15469         single_offload = search_rx_offload(res->offload);
15470         if (single_offload == 0) {
15471                 printf("Unknown offload name: %s\n", res->offload);
15472                 return;
15473         }
15474
15475         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15476         if (ret != 0)
15477                 return;
15478
15479         nb_rx_queues = dev_info.nb_rx_queues;
15480         if (!strcmp(res->on_off, "on")) {
15481                 port->dev_conf.rxmode.offloads |= single_offload;
15482                 for (q = 0; q < nb_rx_queues; q++)
15483                         port->rx_conf[q].offloads |= single_offload;
15484         } else {
15485                 port->dev_conf.rxmode.offloads &= ~single_offload;
15486                 for (q = 0; q < nb_rx_queues; q++)
15487                         port->rx_conf[q].offloads &= ~single_offload;
15488         }
15489
15490         cmd_reconfig_device_queue(port_id, 1, 1);
15491 }
15492
15493 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15494         .f = cmd_config_per_port_rx_offload_parsed,
15495         .data = NULL,
15496         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15497                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15498                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15499                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15500                     "keep_crc|rss_hash on|off",
15501         .tokens = {
15502                 (void *)&cmd_config_per_port_rx_offload_result_port,
15503                 (void *)&cmd_config_per_port_rx_offload_result_config,
15504                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15505                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15506                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15507                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15508                 NULL,
15509         }
15510 };
15511
15512 /* Enable/Disable a per queue offloading */
15513 struct cmd_config_per_queue_rx_offload_result {
15514         cmdline_fixed_string_t port;
15515         portid_t port_id;
15516         cmdline_fixed_string_t rxq;
15517         uint16_t queue_id;
15518         cmdline_fixed_string_t rx_offload;
15519         cmdline_fixed_string_t offload;
15520         cmdline_fixed_string_t on_off;
15521 };
15522
15523 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15524         TOKEN_STRING_INITIALIZER
15525                 (struct cmd_config_per_queue_rx_offload_result,
15526                  port, "port");
15527 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15528         TOKEN_NUM_INITIALIZER
15529                 (struct cmd_config_per_queue_rx_offload_result,
15530                  port_id, UINT16);
15531 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15532         TOKEN_STRING_INITIALIZER
15533                 (struct cmd_config_per_queue_rx_offload_result,
15534                  rxq, "rxq");
15535 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15536         TOKEN_NUM_INITIALIZER
15537                 (struct cmd_config_per_queue_rx_offload_result,
15538                  queue_id, UINT16);
15539 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15540         TOKEN_STRING_INITIALIZER
15541                 (struct cmd_config_per_queue_rx_offload_result,
15542                  rx_offload, "rx_offload");
15543 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15544         TOKEN_STRING_INITIALIZER
15545                 (struct cmd_config_per_queue_rx_offload_result,
15546                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15547                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15548                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15549                            "scatter#buffer_split#timestamp#security#keep_crc");
15550 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15551         TOKEN_STRING_INITIALIZER
15552                 (struct cmd_config_per_queue_rx_offload_result,
15553                  on_off, "on#off");
15554
15555 static void
15556 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15557                                 __rte_unused struct cmdline *cl,
15558                                 __rte_unused void *data)
15559 {
15560         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15561         struct rte_eth_dev_info dev_info;
15562         portid_t port_id = res->port_id;
15563         uint16_t queue_id = res->queue_id;
15564         struct rte_port *port = &ports[port_id];
15565         uint64_t single_offload;
15566         int ret;
15567
15568         if (port->port_status != RTE_PORT_STOPPED) {
15569                 printf("Error: Can't config offload when Port %d "
15570                        "is not stopped\n", port_id);
15571                 return;
15572         }
15573
15574         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15575         if (ret != 0)
15576                 return;
15577
15578         if (queue_id >= dev_info.nb_rx_queues) {
15579                 printf("Error: input queue_id should be 0 ... "
15580                        "%d\n", dev_info.nb_rx_queues - 1);
15581                 return;
15582         }
15583
15584         single_offload = search_rx_offload(res->offload);
15585         if (single_offload == 0) {
15586                 printf("Unknown offload name: %s\n", res->offload);
15587                 return;
15588         }
15589
15590         if (!strcmp(res->on_off, "on"))
15591                 port->rx_conf[queue_id].offloads |= single_offload;
15592         else
15593                 port->rx_conf[queue_id].offloads &= ~single_offload;
15594
15595         cmd_reconfig_device_queue(port_id, 1, 1);
15596 }
15597
15598 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15599         .f = cmd_config_per_queue_rx_offload_parsed,
15600         .data = NULL,
15601         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15602                     "vlan_strip|ipv4_cksum|"
15603                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15604                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15605                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15606                     "keep_crc on|off",
15607         .tokens = {
15608                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15609                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15610                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15611                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15612                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15613                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15614                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15615                 NULL,
15616         }
15617 };
15618
15619 /* Get Tx offloads capabilities */
15620 struct cmd_tx_offload_get_capa_result {
15621         cmdline_fixed_string_t show;
15622         cmdline_fixed_string_t port;
15623         portid_t port_id;
15624         cmdline_fixed_string_t tx_offload;
15625         cmdline_fixed_string_t capabilities;
15626 };
15627
15628 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15629         TOKEN_STRING_INITIALIZER
15630                 (struct cmd_tx_offload_get_capa_result,
15631                  show, "show");
15632 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15633         TOKEN_STRING_INITIALIZER
15634                 (struct cmd_tx_offload_get_capa_result,
15635                  port, "port");
15636 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15637         TOKEN_NUM_INITIALIZER
15638                 (struct cmd_tx_offload_get_capa_result,
15639                  port_id, UINT16);
15640 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15641         TOKEN_STRING_INITIALIZER
15642                 (struct cmd_tx_offload_get_capa_result,
15643                  tx_offload, "tx_offload");
15644 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15645         TOKEN_STRING_INITIALIZER
15646                 (struct cmd_tx_offload_get_capa_result,
15647                  capabilities, "capabilities");
15648
15649 static void
15650 print_tx_offloads(uint64_t offloads)
15651 {
15652         uint64_t single_offload;
15653         int begin;
15654         int end;
15655         int bit;
15656
15657         if (offloads == 0)
15658                 return;
15659
15660         begin = __builtin_ctzll(offloads);
15661         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15662
15663         single_offload = 1ULL << begin;
15664         for (bit = begin; bit < end; bit++) {
15665                 if (offloads & single_offload)
15666                         printf(" %s",
15667                                rte_eth_dev_tx_offload_name(single_offload));
15668                 single_offload <<= 1;
15669         }
15670 }
15671
15672 static void
15673 cmd_tx_offload_get_capa_parsed(
15674         void *parsed_result,
15675         __rte_unused struct cmdline *cl,
15676         __rte_unused void *data)
15677 {
15678         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15679         struct rte_eth_dev_info dev_info;
15680         portid_t port_id = res->port_id;
15681         uint64_t queue_offloads;
15682         uint64_t port_offloads;
15683         int ret;
15684
15685         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15686         if (ret != 0)
15687                 return;
15688
15689         queue_offloads = dev_info.tx_queue_offload_capa;
15690         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15691
15692         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15693         printf("  Per Queue :");
15694         print_tx_offloads(queue_offloads);
15695
15696         printf("\n");
15697         printf("  Per Port  :");
15698         print_tx_offloads(port_offloads);
15699         printf("\n\n");
15700 }
15701
15702 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15703         .f = cmd_tx_offload_get_capa_parsed,
15704         .data = NULL,
15705         .help_str = "show port <port_id> tx_offload capabilities",
15706         .tokens = {
15707                 (void *)&cmd_tx_offload_get_capa_show,
15708                 (void *)&cmd_tx_offload_get_capa_port,
15709                 (void *)&cmd_tx_offload_get_capa_port_id,
15710                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15711                 (void *)&cmd_tx_offload_get_capa_capabilities,
15712                 NULL,
15713         }
15714 };
15715
15716 /* Get Tx offloads configuration */
15717 struct cmd_tx_offload_get_configuration_result {
15718         cmdline_fixed_string_t show;
15719         cmdline_fixed_string_t port;
15720         portid_t port_id;
15721         cmdline_fixed_string_t tx_offload;
15722         cmdline_fixed_string_t configuration;
15723 };
15724
15725 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15726         TOKEN_STRING_INITIALIZER
15727                 (struct cmd_tx_offload_get_configuration_result,
15728                  show, "show");
15729 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15730         TOKEN_STRING_INITIALIZER
15731                 (struct cmd_tx_offload_get_configuration_result,
15732                  port, "port");
15733 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15734         TOKEN_NUM_INITIALIZER
15735                 (struct cmd_tx_offload_get_configuration_result,
15736                  port_id, UINT16);
15737 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15738         TOKEN_STRING_INITIALIZER
15739                 (struct cmd_tx_offload_get_configuration_result,
15740                  tx_offload, "tx_offload");
15741 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15742         TOKEN_STRING_INITIALIZER
15743                 (struct cmd_tx_offload_get_configuration_result,
15744                  configuration, "configuration");
15745
15746 static void
15747 cmd_tx_offload_get_configuration_parsed(
15748         void *parsed_result,
15749         __rte_unused struct cmdline *cl,
15750         __rte_unused void *data)
15751 {
15752         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15753         struct rte_eth_dev_info dev_info;
15754         portid_t port_id = res->port_id;
15755         struct rte_port *port = &ports[port_id];
15756         uint64_t port_offloads;
15757         uint64_t queue_offloads;
15758         uint16_t nb_tx_queues;
15759         int q;
15760         int ret;
15761
15762         printf("Tx Offloading Configuration of port %d :\n", port_id);
15763
15764         port_offloads = port->dev_conf.txmode.offloads;
15765         printf("  Port :");
15766         print_tx_offloads(port_offloads);
15767         printf("\n");
15768
15769         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15770         if (ret != 0)
15771                 return;
15772
15773         nb_tx_queues = dev_info.nb_tx_queues;
15774         for (q = 0; q < nb_tx_queues; q++) {
15775                 queue_offloads = port->tx_conf[q].offloads;
15776                 printf("  Queue[%2d] :", q);
15777                 print_tx_offloads(queue_offloads);
15778                 printf("\n");
15779         }
15780         printf("\n");
15781 }
15782
15783 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15784         .f = cmd_tx_offload_get_configuration_parsed,
15785         .data = NULL,
15786         .help_str = "show port <port_id> tx_offload configuration",
15787         .tokens = {
15788                 (void *)&cmd_tx_offload_get_configuration_show,
15789                 (void *)&cmd_tx_offload_get_configuration_port,
15790                 (void *)&cmd_tx_offload_get_configuration_port_id,
15791                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15792                 (void *)&cmd_tx_offload_get_configuration_configuration,
15793                 NULL,
15794         }
15795 };
15796
15797 /* Enable/Disable a per port offloading */
15798 struct cmd_config_per_port_tx_offload_result {
15799         cmdline_fixed_string_t port;
15800         cmdline_fixed_string_t config;
15801         portid_t port_id;
15802         cmdline_fixed_string_t tx_offload;
15803         cmdline_fixed_string_t offload;
15804         cmdline_fixed_string_t on_off;
15805 };
15806
15807 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15808         TOKEN_STRING_INITIALIZER
15809                 (struct cmd_config_per_port_tx_offload_result,
15810                  port, "port");
15811 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15812         TOKEN_STRING_INITIALIZER
15813                 (struct cmd_config_per_port_tx_offload_result,
15814                  config, "config");
15815 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15816         TOKEN_NUM_INITIALIZER
15817                 (struct cmd_config_per_port_tx_offload_result,
15818                  port_id, UINT16);
15819 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15820         TOKEN_STRING_INITIALIZER
15821                 (struct cmd_config_per_port_tx_offload_result,
15822                  tx_offload, "tx_offload");
15823 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15824         TOKEN_STRING_INITIALIZER
15825                 (struct cmd_config_per_port_tx_offload_result,
15826                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15827                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15828                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15829                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15830                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15831                           "send_on_timestamp");
15832 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15833         TOKEN_STRING_INITIALIZER
15834                 (struct cmd_config_per_port_tx_offload_result,
15835                  on_off, "on#off");
15836
15837 static uint64_t
15838 search_tx_offload(const char *name)
15839 {
15840         uint64_t single_offload;
15841         const char *single_name;
15842         int found = 0;
15843         unsigned int bit;
15844
15845         single_offload = 1;
15846         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15847                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15848                 if (single_name == NULL)
15849                         break;
15850                 if (!strcasecmp(single_name, name)) {
15851                         found = 1;
15852                         break;
15853                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15854                         break;
15855                 single_offload <<= 1;
15856         }
15857
15858         if (found)
15859                 return single_offload;
15860
15861         return 0;
15862 }
15863
15864 static void
15865 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15866                                 __rte_unused struct cmdline *cl,
15867                                 __rte_unused void *data)
15868 {
15869         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15870         portid_t port_id = res->port_id;
15871         struct rte_eth_dev_info dev_info;
15872         struct rte_port *port = &ports[port_id];
15873         uint64_t single_offload;
15874         uint16_t nb_tx_queues;
15875         int q;
15876         int ret;
15877
15878         if (port->port_status != RTE_PORT_STOPPED) {
15879                 printf("Error: Can't config offload when Port %d "
15880                        "is not stopped\n", port_id);
15881                 return;
15882         }
15883
15884         single_offload = search_tx_offload(res->offload);
15885         if (single_offload == 0) {
15886                 printf("Unknown offload name: %s\n", res->offload);
15887                 return;
15888         }
15889
15890         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15891         if (ret != 0)
15892                 return;
15893
15894         nb_tx_queues = dev_info.nb_tx_queues;
15895         if (!strcmp(res->on_off, "on")) {
15896                 port->dev_conf.txmode.offloads |= single_offload;
15897                 for (q = 0; q < nb_tx_queues; q++)
15898                         port->tx_conf[q].offloads |= single_offload;
15899         } else {
15900                 port->dev_conf.txmode.offloads &= ~single_offload;
15901                 for (q = 0; q < nb_tx_queues; q++)
15902                         port->tx_conf[q].offloads &= ~single_offload;
15903         }
15904
15905         cmd_reconfig_device_queue(port_id, 1, 1);
15906 }
15907
15908 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15909         .f = cmd_config_per_port_tx_offload_parsed,
15910         .data = NULL,
15911         .help_str = "port config <port_id> tx_offload "
15912                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15913                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15914                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15915                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15916                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15917                     "send_on_timestamp on|off",
15918         .tokens = {
15919                 (void *)&cmd_config_per_port_tx_offload_result_port,
15920                 (void *)&cmd_config_per_port_tx_offload_result_config,
15921                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15922                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15923                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15924                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15925                 NULL,
15926         }
15927 };
15928
15929 /* Enable/Disable a per queue offloading */
15930 struct cmd_config_per_queue_tx_offload_result {
15931         cmdline_fixed_string_t port;
15932         portid_t port_id;
15933         cmdline_fixed_string_t txq;
15934         uint16_t queue_id;
15935         cmdline_fixed_string_t tx_offload;
15936         cmdline_fixed_string_t offload;
15937         cmdline_fixed_string_t on_off;
15938 };
15939
15940 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15941         TOKEN_STRING_INITIALIZER
15942                 (struct cmd_config_per_queue_tx_offload_result,
15943                  port, "port");
15944 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15945         TOKEN_NUM_INITIALIZER
15946                 (struct cmd_config_per_queue_tx_offload_result,
15947                  port_id, UINT16);
15948 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15949         TOKEN_STRING_INITIALIZER
15950                 (struct cmd_config_per_queue_tx_offload_result,
15951                  txq, "txq");
15952 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15953         TOKEN_NUM_INITIALIZER
15954                 (struct cmd_config_per_queue_tx_offload_result,
15955                  queue_id, UINT16);
15956 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15957         TOKEN_STRING_INITIALIZER
15958                 (struct cmd_config_per_queue_tx_offload_result,
15959                  tx_offload, "tx_offload");
15960 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15961         TOKEN_STRING_INITIALIZER
15962                 (struct cmd_config_per_queue_tx_offload_result,
15963                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15964                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15965                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15966                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15967                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
15968 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
15969         TOKEN_STRING_INITIALIZER
15970                 (struct cmd_config_per_queue_tx_offload_result,
15971                  on_off, "on#off");
15972
15973 static void
15974 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
15975                                 __rte_unused struct cmdline *cl,
15976                                 __rte_unused void *data)
15977 {
15978         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
15979         struct rte_eth_dev_info dev_info;
15980         portid_t port_id = res->port_id;
15981         uint16_t queue_id = res->queue_id;
15982         struct rte_port *port = &ports[port_id];
15983         uint64_t single_offload;
15984         int ret;
15985
15986         if (port->port_status != RTE_PORT_STOPPED) {
15987                 printf("Error: Can't config offload when Port %d "
15988                        "is not stopped\n", port_id);
15989                 return;
15990         }
15991
15992         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15993         if (ret != 0)
15994                 return;
15995
15996         if (queue_id >= dev_info.nb_tx_queues) {
15997                 printf("Error: input queue_id should be 0 ... "
15998                        "%d\n", dev_info.nb_tx_queues - 1);
15999                 return;
16000         }
16001
16002         single_offload = search_tx_offload(res->offload);
16003         if (single_offload == 0) {
16004                 printf("Unknown offload name: %s\n", res->offload);
16005                 return;
16006         }
16007
16008         if (!strcmp(res->on_off, "on"))
16009                 port->tx_conf[queue_id].offloads |= single_offload;
16010         else
16011                 port->tx_conf[queue_id].offloads &= ~single_offload;
16012
16013         cmd_reconfig_device_queue(port_id, 1, 1);
16014 }
16015
16016 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16017         .f = cmd_config_per_queue_tx_offload_parsed,
16018         .data = NULL,
16019         .help_str = "port <port_id> txq <queue_id> tx_offload "
16020                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16021                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16022                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16023                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16024                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16025                     "on|off",
16026         .tokens = {
16027                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16028                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16029                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16030                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16031                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16032                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16033                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16034                 NULL,
16035         }
16036 };
16037
16038 /* *** configure tx_metadata for specific port *** */
16039 struct cmd_config_tx_metadata_specific_result {
16040         cmdline_fixed_string_t port;
16041         cmdline_fixed_string_t keyword;
16042         uint16_t port_id;
16043         cmdline_fixed_string_t item;
16044         uint32_t value;
16045 };
16046
16047 static void
16048 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16049                                 __rte_unused struct cmdline *cl,
16050                                 __rte_unused void *data)
16051 {
16052         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16053
16054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16055                 return;
16056         ports[res->port_id].tx_metadata = res->value;
16057         /* Add/remove callback to insert valid metadata in every Tx packet. */
16058         if (ports[res->port_id].tx_metadata)
16059                 add_tx_md_callback(res->port_id);
16060         else
16061                 remove_tx_md_callback(res->port_id);
16062         rte_flow_dynf_metadata_register();
16063 }
16064
16065 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16066         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16067                         port, "port");
16068 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16069         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16070                         keyword, "config");
16071 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16072         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16073                         port_id, UINT16);
16074 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16075         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16076                         item, "tx_metadata");
16077 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16078         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16079                         value, UINT32);
16080
16081 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16082         .f = cmd_config_tx_metadata_specific_parsed,
16083         .data = NULL,
16084         .help_str = "port config <port_id> tx_metadata <value>",
16085         .tokens = {
16086                 (void *)&cmd_config_tx_metadata_specific_port,
16087                 (void *)&cmd_config_tx_metadata_specific_keyword,
16088                 (void *)&cmd_config_tx_metadata_specific_id,
16089                 (void *)&cmd_config_tx_metadata_specific_item,
16090                 (void *)&cmd_config_tx_metadata_specific_value,
16091                 NULL,
16092         },
16093 };
16094
16095 /* *** set dynf *** */
16096 struct cmd_config_tx_dynf_specific_result {
16097         cmdline_fixed_string_t port;
16098         cmdline_fixed_string_t keyword;
16099         uint16_t port_id;
16100         cmdline_fixed_string_t item;
16101         cmdline_fixed_string_t name;
16102         cmdline_fixed_string_t value;
16103 };
16104
16105 static void
16106 cmd_config_dynf_specific_parsed(void *parsed_result,
16107                                 __rte_unused struct cmdline *cl,
16108                                 __rte_unused void *data)
16109 {
16110         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16111         struct rte_mbuf_dynflag desc_flag;
16112         int flag;
16113         uint64_t old_port_flags;
16114
16115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16116                 return;
16117         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16118         if (flag <= 0) {
16119                 if (strlcpy(desc_flag.name, res->name,
16120                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16121                         printf("Flag name too long\n");
16122                         return;
16123                 }
16124                 desc_flag.flags = 0;
16125                 flag = rte_mbuf_dynflag_register(&desc_flag);
16126                 if (flag < 0) {
16127                         printf("Can't register flag\n");
16128                         return;
16129                 }
16130                 strcpy(dynf_names[flag], desc_flag.name);
16131         }
16132         old_port_flags = ports[res->port_id].mbuf_dynf;
16133         if (!strcmp(res->value, "set")) {
16134                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16135                 if (old_port_flags == 0)
16136                         add_tx_dynf_callback(res->port_id);
16137         } else {
16138                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16139                 if (ports[res->port_id].mbuf_dynf == 0)
16140                         remove_tx_dynf_callback(res->port_id);
16141         }
16142 }
16143
16144 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16145         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16146                         keyword, "port");
16147 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16148         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16149                         keyword, "config");
16150 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16151         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16152                         port_id, UINT16);
16153 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16154         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16155                         item, "dynf");
16156 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16157         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16158                         name, NULL);
16159 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16160         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16161                         value, "set#clear");
16162
16163 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16164         .f = cmd_config_dynf_specific_parsed,
16165         .data = NULL,
16166         .help_str = "port config <port id> dynf <name> set|clear",
16167         .tokens = {
16168                 (void *)&cmd_config_tx_dynf_specific_port,
16169                 (void *)&cmd_config_tx_dynf_specific_keyword,
16170                 (void *)&cmd_config_tx_dynf_specific_port_id,
16171                 (void *)&cmd_config_tx_dynf_specific_item,
16172                 (void *)&cmd_config_tx_dynf_specific_name,
16173                 (void *)&cmd_config_tx_dynf_specific_value,
16174                 NULL,
16175         },
16176 };
16177
16178 /* *** display tx_metadata per port configuration *** */
16179 struct cmd_show_tx_metadata_result {
16180         cmdline_fixed_string_t cmd_show;
16181         cmdline_fixed_string_t cmd_port;
16182         cmdline_fixed_string_t cmd_keyword;
16183         portid_t cmd_pid;
16184 };
16185
16186 static void
16187 cmd_show_tx_metadata_parsed(void *parsed_result,
16188                 __rte_unused struct cmdline *cl,
16189                 __rte_unused void *data)
16190 {
16191         struct cmd_show_tx_metadata_result *res = parsed_result;
16192
16193         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16194                 printf("invalid port id %u\n", res->cmd_pid);
16195                 return;
16196         }
16197         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16198                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16199                        ports[res->cmd_pid].tx_metadata);
16200         }
16201 }
16202
16203 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16204         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16205                         cmd_show, "show");
16206 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16207         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16208                         cmd_port, "port");
16209 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16210         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16211                         cmd_pid, UINT16);
16212 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16213         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16214                         cmd_keyword, "tx_metadata");
16215
16216 cmdline_parse_inst_t cmd_show_tx_metadata = {
16217         .f = cmd_show_tx_metadata_parsed,
16218         .data = NULL,
16219         .help_str = "show port <port_id> tx_metadata",
16220         .tokens = {
16221                 (void *)&cmd_show_tx_metadata_show,
16222                 (void *)&cmd_show_tx_metadata_port,
16223                 (void *)&cmd_show_tx_metadata_pid,
16224                 (void *)&cmd_show_tx_metadata_keyword,
16225                 NULL,
16226         },
16227 };
16228
16229 /* *** show fec capability per port configuration *** */
16230 struct cmd_show_fec_capability_result {
16231         cmdline_fixed_string_t cmd_show;
16232         cmdline_fixed_string_t cmd_port;
16233         cmdline_fixed_string_t cmd_fec;
16234         cmdline_fixed_string_t cmd_keyword;
16235         portid_t cmd_pid;
16236 };
16237
16238 static void
16239 cmd_show_fec_capability_parsed(void *parsed_result,
16240                 __rte_unused struct cmdline *cl,
16241                 __rte_unused void *data)
16242 {
16243 #define FEC_CAP_NUM 2
16244         struct cmd_show_fec_capability_result *res = parsed_result;
16245         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16246         unsigned int num = FEC_CAP_NUM;
16247         unsigned int ret_num;
16248         int ret;
16249
16250         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16251                 printf("Invalid port id %u\n", res->cmd_pid);
16252                 return;
16253         }
16254
16255         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16256         if (ret == -ENOTSUP) {
16257                 printf("Function not implemented\n");
16258                 return;
16259         } else if (ret < 0) {
16260                 printf("Get FEC capability failed\n");
16261                 return;
16262         }
16263
16264         ret_num = (unsigned int)ret;
16265         show_fec_capability(ret_num, speed_fec_capa);
16266 }
16267
16268 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16269         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16270                         cmd_show, "show");
16271 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16272         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16273                         cmd_port, "port");
16274 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16275         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16276                         cmd_pid, UINT16);
16277 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16278         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16279                         cmd_fec, "fec");
16280 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16281         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16282                         cmd_keyword, "capabilities");
16283
16284 cmdline_parse_inst_t cmd_show_capability = {
16285         .f = cmd_show_fec_capability_parsed,
16286         .data = NULL,
16287         .help_str = "show port <port_id> fec capabilities",
16288         .tokens = {
16289                 (void *)&cmd_show_fec_capability_show,
16290                 (void *)&cmd_show_fec_capability_port,
16291                 (void *)&cmd_show_fec_capability_pid,
16292                 (void *)&cmd_show_fec_capability_fec,
16293                 (void *)&cmd_show_fec_capability_keyword,
16294                 NULL,
16295         },
16296 };
16297
16298 /* *** show fec mode per port configuration *** */
16299 struct cmd_show_fec_metadata_result {
16300         cmdline_fixed_string_t cmd_show;
16301         cmdline_fixed_string_t cmd_port;
16302         cmdline_fixed_string_t cmd_keyword;
16303         portid_t cmd_pid;
16304 };
16305
16306 static void
16307 cmd_show_fec_mode_parsed(void *parsed_result,
16308                 __rte_unused struct cmdline *cl,
16309                 __rte_unused void *data)
16310 {
16311 #define FEC_NAME_SIZE 16
16312         struct cmd_show_fec_metadata_result *res = parsed_result;
16313         uint32_t mode;
16314         char buf[FEC_NAME_SIZE];
16315         int ret;
16316
16317         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16318                 printf("Invalid port id %u\n", res->cmd_pid);
16319                 return;
16320         }
16321         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16322         if (ret == -ENOTSUP) {
16323                 printf("Function not implemented\n");
16324                 return;
16325         } else if (ret < 0) {
16326                 printf("Get FEC mode failed\n");
16327                 return;
16328         }
16329
16330         switch (mode) {
16331         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16332                 strlcpy(buf, "off", sizeof(buf));
16333                 break;
16334         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16335                 strlcpy(buf, "auto", sizeof(buf));
16336                 break;
16337         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16338                 strlcpy(buf, "baser", sizeof(buf));
16339                 break;
16340         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16341                 strlcpy(buf, "rs", sizeof(buf));
16342                 break;
16343         default:
16344                 return;
16345         }
16346
16347         printf("%s\n", buf);
16348 }
16349
16350 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16351         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16352                         cmd_show, "show");
16353 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16354         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16355                         cmd_port, "port");
16356 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16357         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16358                         cmd_pid, UINT16);
16359 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16360         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16361                         cmd_keyword, "fec_mode");
16362
16363 cmdline_parse_inst_t cmd_show_fec_mode = {
16364         .f = cmd_show_fec_mode_parsed,
16365         .data = NULL,
16366         .help_str = "show port <port_id> fec_mode",
16367         .tokens = {
16368                 (void *)&cmd_show_fec_mode_show,
16369                 (void *)&cmd_show_fec_mode_port,
16370                 (void *)&cmd_show_fec_mode_pid,
16371                 (void *)&cmd_show_fec_mode_keyword,
16372                 NULL,
16373         },
16374 };
16375
16376 /* *** set fec mode per port configuration *** */
16377 struct cmd_set_port_fec_mode {
16378         cmdline_fixed_string_t set;
16379         cmdline_fixed_string_t port;
16380         portid_t port_id;
16381         cmdline_fixed_string_t fec_mode;
16382         cmdline_fixed_string_t fec_value;
16383 };
16384
16385 /* Common CLI fields for set fec mode */
16386 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16387         TOKEN_STRING_INITIALIZER
16388                 (struct cmd_set_port_fec_mode,
16389                  set, "set");
16390 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16391         TOKEN_STRING_INITIALIZER
16392                 (struct cmd_set_port_fec_mode,
16393                  port, "port");
16394 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16395         TOKEN_NUM_INITIALIZER
16396                 (struct cmd_set_port_fec_mode,
16397                  port_id, UINT16);
16398 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16399         TOKEN_STRING_INITIALIZER
16400                 (struct cmd_set_port_fec_mode,
16401                  fec_mode, "fec_mode");
16402 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16403         TOKEN_STRING_INITIALIZER
16404                 (struct cmd_set_port_fec_mode,
16405                  fec_value, NULL);
16406
16407 static void
16408 cmd_set_port_fec_mode_parsed(
16409         void *parsed_result,
16410         __rte_unused struct cmdline *cl,
16411         __rte_unused void *data)
16412 {
16413         struct cmd_set_port_fec_mode *res = parsed_result;
16414         uint16_t port_id = res->port_id;
16415         uint32_t mode;
16416         int ret;
16417
16418         ret = parse_fec_mode(res->fec_value, &mode);
16419         if (ret < 0) {
16420                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16421                         port_id);
16422                 return;
16423         }
16424
16425         ret = rte_eth_fec_set(port_id, mode);
16426         if (ret == -ENOTSUP) {
16427                 printf("Function not implemented\n");
16428                 return;
16429         } else if (ret < 0) {
16430                 printf("Set FEC mode failed\n");
16431                 return;
16432         }
16433 }
16434
16435 cmdline_parse_inst_t cmd_set_fec_mode = {
16436         .f = cmd_set_port_fec_mode_parsed,
16437         .data = NULL,
16438         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16439         .tokens = {
16440                 (void *)&cmd_set_port_fec_mode_set,
16441                 (void *)&cmd_set_port_fec_mode_port,
16442                 (void *)&cmd_set_port_fec_mode_port_id,
16443                 (void *)&cmd_set_port_fec_mode_str,
16444                 (void *)&cmd_set_port_fec_mode_value,
16445                 NULL,
16446         },
16447 };
16448
16449 /* show port supported ptypes */
16450
16451 /* Common result structure for show port ptypes */
16452 struct cmd_show_port_supported_ptypes_result {
16453         cmdline_fixed_string_t show;
16454         cmdline_fixed_string_t port;
16455         portid_t port_id;
16456         cmdline_fixed_string_t ptypes;
16457 };
16458
16459 /* Common CLI fields for show port ptypes */
16460 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16461         TOKEN_STRING_INITIALIZER
16462                 (struct cmd_show_port_supported_ptypes_result,
16463                  show, "show");
16464 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16465         TOKEN_STRING_INITIALIZER
16466                 (struct cmd_show_port_supported_ptypes_result,
16467                  port, "port");
16468 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16469         TOKEN_NUM_INITIALIZER
16470                 (struct cmd_show_port_supported_ptypes_result,
16471                  port_id, UINT16);
16472 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16473         TOKEN_STRING_INITIALIZER
16474                 (struct cmd_show_port_supported_ptypes_result,
16475                  ptypes, "ptypes");
16476
16477 static void
16478 cmd_show_port_supported_ptypes_parsed(
16479         void *parsed_result,
16480         __rte_unused struct cmdline *cl,
16481         __rte_unused void *data)
16482 {
16483 #define RSVD_PTYPE_MASK       0xf0000000
16484 #define MAX_PTYPES_PER_LAYER  16
16485 #define LTYPE_NAMESIZE        32
16486 #define PTYPE_NAMESIZE        256
16487         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16488         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16489         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16490         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16491         uint16_t port_id = res->port_id;
16492         int ret, i;
16493
16494         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16495         if (ret < 0)
16496                 return;
16497
16498         while (ptype_mask != RSVD_PTYPE_MASK) {
16499
16500                 switch (ptype_mask) {
16501                 case RTE_PTYPE_L2_MASK:
16502                         strlcpy(ltype, "L2", sizeof(ltype));
16503                         break;
16504                 case RTE_PTYPE_L3_MASK:
16505                         strlcpy(ltype, "L3", sizeof(ltype));
16506                         break;
16507                 case RTE_PTYPE_L4_MASK:
16508                         strlcpy(ltype, "L4", sizeof(ltype));
16509                         break;
16510                 case RTE_PTYPE_TUNNEL_MASK:
16511                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16512                         break;
16513                 case RTE_PTYPE_INNER_L2_MASK:
16514                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16515                         break;
16516                 case RTE_PTYPE_INNER_L3_MASK:
16517                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16518                         break;
16519                 case RTE_PTYPE_INNER_L4_MASK:
16520                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16521                         break;
16522                 default:
16523                         return;
16524                 }
16525
16526                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16527                                                        ptype_mask, ptypes,
16528                                                        MAX_PTYPES_PER_LAYER);
16529
16530                 if (ret > 0)
16531                         printf("Supported %s ptypes:\n", ltype);
16532                 else
16533                         printf("%s ptypes unsupported\n", ltype);
16534
16535                 for (i = 0; i < ret; ++i) {
16536                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16537                         printf("%s\n", buf);
16538                 }
16539
16540                 ptype_mask <<= 4;
16541         }
16542 }
16543
16544 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16545         .f = cmd_show_port_supported_ptypes_parsed,
16546         .data = NULL,
16547         .help_str = "show port <port_id> ptypes",
16548         .tokens = {
16549                 (void *)&cmd_show_port_supported_ptypes_show,
16550                 (void *)&cmd_show_port_supported_ptypes_port,
16551                 (void *)&cmd_show_port_supported_ptypes_port_id,
16552                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16553                 NULL,
16554         },
16555 };
16556
16557 /* *** display rx/tx descriptor status *** */
16558 struct cmd_show_rx_tx_desc_status_result {
16559         cmdline_fixed_string_t cmd_show;
16560         cmdline_fixed_string_t cmd_port;
16561         cmdline_fixed_string_t cmd_keyword;
16562         cmdline_fixed_string_t cmd_desc;
16563         cmdline_fixed_string_t cmd_status;
16564         portid_t cmd_pid;
16565         portid_t cmd_qid;
16566         portid_t cmd_did;
16567 };
16568
16569 static void
16570 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16571                 __rte_unused struct cmdline *cl,
16572                 __rte_unused void *data)
16573 {
16574         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16575         int rc;
16576
16577         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16578                 printf("invalid port id %u\n", res->cmd_pid);
16579                 return;
16580         }
16581
16582         if (!strcmp(res->cmd_keyword, "rxq")) {
16583                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16584                                              res->cmd_did);
16585                 if (rc < 0) {
16586                         printf("Invalid queueid = %d\n", res->cmd_qid);
16587                         return;
16588                 }
16589                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16590                         printf("Desc status = AVAILABLE\n");
16591                 else if (rc == RTE_ETH_RX_DESC_DONE)
16592                         printf("Desc status = DONE\n");
16593                 else
16594                         printf("Desc status = UNAVAILABLE\n");
16595         } else if (!strcmp(res->cmd_keyword, "txq")) {
16596                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16597                                              res->cmd_did);
16598                 if (rc < 0) {
16599                         printf("Invalid queueid = %d\n", res->cmd_qid);
16600                         return;
16601                 }
16602                 if (rc == RTE_ETH_TX_DESC_FULL)
16603                         printf("Desc status = FULL\n");
16604                 else if (rc == RTE_ETH_TX_DESC_DONE)
16605                         printf("Desc status = DONE\n");
16606                 else
16607                         printf("Desc status = UNAVAILABLE\n");
16608         }
16609 }
16610
16611 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16612         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16613                         cmd_show, "show");
16614 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16615         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16616                         cmd_port, "port");
16617 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16618         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16619                         cmd_pid, UINT16);
16620 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16621         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16622                         cmd_keyword, "rxq#txq");
16623 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16624         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16625                         cmd_qid, UINT16);
16626 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16627         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16628                         cmd_desc, "desc");
16629 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16630         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16631                         cmd_did, UINT16);
16632 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16633         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16634                         cmd_status, "status");
16635 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16636         .f = cmd_show_rx_tx_desc_status_parsed,
16637         .data = NULL,
16638         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16639                 "status",
16640         .tokens = {
16641                 (void *)&cmd_show_rx_tx_desc_status_show,
16642                 (void *)&cmd_show_rx_tx_desc_status_port,
16643                 (void *)&cmd_show_rx_tx_desc_status_pid,
16644                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16645                 (void *)&cmd_show_rx_tx_desc_status_qid,
16646                 (void *)&cmd_show_rx_tx_desc_status_desc,
16647                 (void *)&cmd_show_rx_tx_desc_status_did,
16648                 (void *)&cmd_show_rx_tx_desc_status_status,
16649                 NULL,
16650         },
16651 };
16652
16653 /* Common result structure for set port ptypes */
16654 struct cmd_set_port_ptypes_result {
16655         cmdline_fixed_string_t set;
16656         cmdline_fixed_string_t port;
16657         portid_t port_id;
16658         cmdline_fixed_string_t ptype_mask;
16659         uint32_t mask;
16660 };
16661
16662 /* Common CLI fields for set port ptypes */
16663 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16664         TOKEN_STRING_INITIALIZER
16665                 (struct cmd_set_port_ptypes_result,
16666                  set, "set");
16667 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16668         TOKEN_STRING_INITIALIZER
16669                 (struct cmd_set_port_ptypes_result,
16670                  port, "port");
16671 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16672         TOKEN_NUM_INITIALIZER
16673                 (struct cmd_set_port_ptypes_result,
16674                  port_id, UINT16);
16675 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16676         TOKEN_STRING_INITIALIZER
16677                 (struct cmd_set_port_ptypes_result,
16678                  ptype_mask, "ptype_mask");
16679 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16680         TOKEN_NUM_INITIALIZER
16681                 (struct cmd_set_port_ptypes_result,
16682                  mask, UINT32);
16683
16684 static void
16685 cmd_set_port_ptypes_parsed(
16686         void *parsed_result,
16687         __rte_unused struct cmdline *cl,
16688         __rte_unused void *data)
16689 {
16690         struct cmd_set_port_ptypes_result *res = parsed_result;
16691 #define PTYPE_NAMESIZE        256
16692         char ptype_name[PTYPE_NAMESIZE];
16693         uint16_t port_id = res->port_id;
16694         uint32_t ptype_mask = res->mask;
16695         int ret, i;
16696
16697         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16698                                                NULL, 0);
16699         if (ret <= 0) {
16700                 printf("Port %d doesn't support any ptypes.\n", port_id);
16701                 return;
16702         }
16703
16704         uint32_t ptypes[ret];
16705
16706         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16707         if (ret < 0) {
16708                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16709                 return;
16710         }
16711
16712         printf("Successfully set following ptypes for Port %d\n", port_id);
16713         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16714                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16715                 printf("%s\n", ptype_name);
16716         }
16717
16718         clear_ptypes = false;
16719 }
16720
16721 cmdline_parse_inst_t cmd_set_port_ptypes = {
16722         .f = cmd_set_port_ptypes_parsed,
16723         .data = NULL,
16724         .help_str = "set port <port_id> ptype_mask <mask>",
16725         .tokens = {
16726                 (void *)&cmd_set_port_ptypes_set,
16727                 (void *)&cmd_set_port_ptypes_port,
16728                 (void *)&cmd_set_port_ptypes_port_id,
16729                 (void *)&cmd_set_port_ptypes_mask_str,
16730                 (void *)&cmd_set_port_ptypes_mask_u32,
16731                 NULL,
16732         },
16733 };
16734
16735 /* *** display mac addresses added to a port *** */
16736 struct cmd_showport_macs_result {
16737         cmdline_fixed_string_t cmd_show;
16738         cmdline_fixed_string_t cmd_port;
16739         cmdline_fixed_string_t cmd_keyword;
16740         portid_t cmd_pid;
16741 };
16742
16743 static void
16744 cmd_showport_macs_parsed(void *parsed_result,
16745                 __rte_unused struct cmdline *cl,
16746                 __rte_unused void *data)
16747 {
16748         struct cmd_showport_macs_result *res = parsed_result;
16749
16750         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16751                 return;
16752
16753         if (!strcmp(res->cmd_keyword, "macs"))
16754                 show_macs(res->cmd_pid);
16755         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16756                 show_mcast_macs(res->cmd_pid);
16757 }
16758
16759 cmdline_parse_token_string_t cmd_showport_macs_show =
16760         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16761                         cmd_show, "show");
16762 cmdline_parse_token_string_t cmd_showport_macs_port =
16763         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16764                         cmd_port, "port");
16765 cmdline_parse_token_num_t cmd_showport_macs_pid =
16766         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16767                         cmd_pid, UINT16);
16768 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16769         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16770                         cmd_keyword, "macs#mcast_macs");
16771
16772 cmdline_parse_inst_t cmd_showport_macs = {
16773         .f = cmd_showport_macs_parsed,
16774         .data = NULL,
16775         .help_str = "show port <port_id> macs|mcast_macs",
16776         .tokens = {
16777                 (void *)&cmd_showport_macs_show,
16778                 (void *)&cmd_showport_macs_port,
16779                 (void *)&cmd_showport_macs_pid,
16780                 (void *)&cmd_showport_macs_keyword,
16781                 NULL,
16782         },
16783 };
16784
16785 /* ******************************************************************************** */
16786
16787 /* list of instructions */
16788 cmdline_parse_ctx_t main_ctx[] = {
16789         (cmdline_parse_inst_t *)&cmd_help_brief,
16790         (cmdline_parse_inst_t *)&cmd_help_long,
16791         (cmdline_parse_inst_t *)&cmd_quit,
16792         (cmdline_parse_inst_t *)&cmd_load_from_file,
16793         (cmdline_parse_inst_t *)&cmd_showport,
16794         (cmdline_parse_inst_t *)&cmd_showqueue,
16795         (cmdline_parse_inst_t *)&cmd_showeeprom,
16796         (cmdline_parse_inst_t *)&cmd_showportall,
16797         (cmdline_parse_inst_t *)&cmd_showdevice,
16798         (cmdline_parse_inst_t *)&cmd_showcfg,
16799         (cmdline_parse_inst_t *)&cmd_showfwdall,
16800         (cmdline_parse_inst_t *)&cmd_start,
16801         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16802         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16803         (cmdline_parse_inst_t *)&cmd_set_link_up,
16804         (cmdline_parse_inst_t *)&cmd_set_link_down,
16805         (cmdline_parse_inst_t *)&cmd_reset,
16806         (cmdline_parse_inst_t *)&cmd_set_numbers,
16807         (cmdline_parse_inst_t *)&cmd_set_log,
16808         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16809         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16810         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16811         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16812         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16813         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16814         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16815         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16816         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16817         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16818         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16819         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16820         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16821         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16822         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16823         (cmdline_parse_inst_t *)&cmd_set_link_check,
16824         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16825         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16826         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16827         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16828 #ifdef RTE_NET_BOND
16829         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16830         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16831         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16832         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16833         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16834         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16835         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16836         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16837         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16838         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16839         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16840 #endif
16841         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16842         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16843         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16844         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16845         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16846         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16847         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16848         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16849         (cmdline_parse_inst_t *)&cmd_csum_set,
16850         (cmdline_parse_inst_t *)&cmd_csum_show,
16851         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16852         (cmdline_parse_inst_t *)&cmd_tso_set,
16853         (cmdline_parse_inst_t *)&cmd_tso_show,
16854         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16855         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16856         (cmdline_parse_inst_t *)&cmd_gro_enable,
16857         (cmdline_parse_inst_t *)&cmd_gro_flush,
16858         (cmdline_parse_inst_t *)&cmd_gro_show,
16859         (cmdline_parse_inst_t *)&cmd_gso_enable,
16860         (cmdline_parse_inst_t *)&cmd_gso_size,
16861         (cmdline_parse_inst_t *)&cmd_gso_show,
16862         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16863         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16864         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16865         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16866         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16867         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16868         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16869         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16870         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16871         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16872         (cmdline_parse_inst_t *)&cmd_config_dcb,
16873         (cmdline_parse_inst_t *)&cmd_read_reg,
16874         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16875         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16876         (cmdline_parse_inst_t *)&cmd_write_reg,
16877         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16878         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16879         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16880         (cmdline_parse_inst_t *)&cmd_stop,
16881         (cmdline_parse_inst_t *)&cmd_mac_addr,
16882         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16883         (cmdline_parse_inst_t *)&cmd_set_qmap,
16884         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16885         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
16886         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
16887         (cmdline_parse_inst_t *)&cmd_operate_port,
16888         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16889         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16890         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16891         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
16892         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
16893         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16894         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16895         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16896         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16897         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16898         (cmdline_parse_inst_t *)&cmd_config_mtu,
16899         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16900         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
16901         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16902         (cmdline_parse_inst_t *)&cmd_config_rss,
16903         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16904         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16905         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
16906         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16907         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16908         (cmdline_parse_inst_t *)&cmd_showport_reta,
16909         (cmdline_parse_inst_t *)&cmd_showport_macs,
16910         (cmdline_parse_inst_t *)&cmd_config_burst,
16911         (cmdline_parse_inst_t *)&cmd_config_thresh,
16912         (cmdline_parse_inst_t *)&cmd_config_threshold,
16913         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16914         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16915         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16916         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16917         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16918         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16919         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16920         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16921         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16922         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16923         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16924         (cmdline_parse_inst_t *)&cmd_dump,
16925         (cmdline_parse_inst_t *)&cmd_dump_one,
16926 #ifdef RTE_NET_I40E
16927         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16928 #endif
16929         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16930         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16931         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16932         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16933         (cmdline_parse_inst_t *)&cmd_flow,
16934         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16935         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16936         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16937         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16938         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16939         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16940         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16941         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16942         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16943         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16944         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16945         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16946         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16947         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16948         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16949         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16950         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16951         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16952         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16953         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16954         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16955         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16956         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16957         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16958         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16959         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16960         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16961         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16962         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16963         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16964         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16965         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16966         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16967         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16968         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16969         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16970         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16971         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16972         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16973         (cmdline_parse_inst_t *)&cmd_set_vxlan,
16974         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
16975         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
16976         (cmdline_parse_inst_t *)&cmd_set_nvgre,
16977         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
16978         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
16979         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
16980         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
16981         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
16982         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
16983         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
16984         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
16985         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
16986         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
16987         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
16988         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
16989         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
16990         (cmdline_parse_inst_t *)&cmd_ddp_add,
16991         (cmdline_parse_inst_t *)&cmd_ddp_del,
16992         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16993         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16994         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16995         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16996         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16997         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16998         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
16999         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17000         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17001         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17002         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17003         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17004
17005         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17006         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17007         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17008         (cmdline_parse_inst_t *)&cmd_queue_region,
17009         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17010         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17011         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17012         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17013         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17014         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17015         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17016         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17017         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17018         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17019         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17020         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17021         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17022         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17023         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17024         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17025         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17026         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17027         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17028         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17029         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17030         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17031         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17032         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17033         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17034         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17035         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17036         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17037         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17038         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17039         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17040         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17041         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17042         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17043         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17044         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17045 #ifdef RTE_LIB_BPF
17046         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17047         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17048 #endif
17049         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17050         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17051         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17052         (cmdline_parse_inst_t *)&cmd_set_raw,
17053         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17054         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17055         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17056         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17057         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17058         (cmdline_parse_inst_t *)&cmd_show_capability,
17059         NULL,
17060 };
17061
17062 /* read cmdline commands from file */
17063 void
17064 cmdline_read_from_file(const char *filename)
17065 {
17066         struct cmdline *cl;
17067
17068         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17069         if (cl == NULL) {
17070                 printf("Failed to create file based cmdline context: %s\n",
17071                        filename);
17072                 return;
17073         }
17074
17075         cmdline_interact(cl);
17076         cmdline_quit(cl);
17077
17078         cmdline_free(cl);
17079
17080         printf("Read CLI commands from %s\n", filename);
17081 }
17082
17083 /* prompt function, called from main on MAIN lcore */
17084 void
17085 prompt(void)
17086 {
17087         /* initialize non-constant commands */
17088         cmd_set_fwd_mode_init();
17089         cmd_set_fwd_retry_mode_init();
17090
17091         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17092         if (testpmd_cl == NULL)
17093                 return;
17094         cmdline_interact(testpmd_cl);
17095         cmdline_stdin_exit(testpmd_cl);
17096 }
17097
17098 void
17099 prompt_exit(void)
17100 {
17101         if (testpmd_cl != NULL)
17102                 cmdline_quit(testpmd_cl);
17103 }
17104
17105 static void
17106 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17107 {
17108         if (id == (portid_t)RTE_PORT_ALL) {
17109                 portid_t pid;
17110
17111                 RTE_ETH_FOREACH_DEV(pid) {
17112                         /* check if need_reconfig has been set to 1 */
17113                         if (ports[pid].need_reconfig == 0)
17114                                 ports[pid].need_reconfig = dev;
17115                         /* check if need_reconfig_queues has been set to 1 */
17116                         if (ports[pid].need_reconfig_queues == 0)
17117                                 ports[pid].need_reconfig_queues = queue;
17118                 }
17119         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17120                 /* check if need_reconfig has been set to 1 */
17121                 if (ports[id].need_reconfig == 0)
17122                         ports[id].need_reconfig = dev;
17123                 /* check if need_reconfig_queues has been set to 1 */
17124                 if (ports[id].need_reconfig_queues == 0)
17125                         ports[id].need_reconfig_queues = queue;
17126         }
17127 }