app/testpmd: display Rx queue used descriptor count
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) rxq (queue_id) desc used count\n"
250                         "    Show current number of filled receive"
251                         " packet descriptors.\n\n"
252
253                         "show port (port_id) macs|mcast_macs"
254                         "       Display list of mac addresses added to port.\n\n"
255
256                         "show port (port_id) fec capabilities"
257                         "       Show fec capabilities of a port.\n\n"
258
259                         "show port (port_id) fec_mode"
260                         "       Show fec mode of a port.\n\n"
261                 );
262         }
263
264         if (show_all || !strcmp(res->section, "config")) {
265                 cmdline_printf(
266                         cl,
267                         "\n"
268                         "Configuration:\n"
269                         "--------------\n"
270                         "Configuration changes only become active when"
271                         " forwarding is started/restarted.\n\n"
272
273                         "set default\n"
274                         "    Reset forwarding to the default configuration.\n\n"
275
276                         "set verbose (level)\n"
277                         "    Set the debug verbosity level X.\n\n"
278
279                         "set log global|(type) (level)\n"
280                         "    Set the log level.\n\n"
281
282                         "set nbport (num)\n"
283                         "    Set number of ports.\n\n"
284
285                         "set nbcore (num)\n"
286                         "    Set number of cores.\n\n"
287
288                         "set coremask (mask)\n"
289                         "    Set the forwarding cores hexadecimal mask.\n\n"
290
291                         "set portmask (mask)\n"
292                         "    Set the forwarding ports hexadecimal mask.\n\n"
293
294                         "set burst (num)\n"
295                         "    Set number of packets per burst.\n\n"
296
297                         "set burst tx delay (microseconds) retry (num)\n"
298                         "    Set the transmit delay time and number of retries,"
299                         " effective when retry is enabled.\n\n"
300
301                         "set rxoffs (x[,y]*)\n"
302                         "    Set the offset of each packet segment on"
303                         " receiving if split feature is engaged."
304                         " Affects only the queues configured with split"
305                         " offloads.\n\n"
306
307                         "set rxpkts (x[,y]*)\n"
308                         "    Set the length of each segment to scatter"
309                         " packets on receiving if split feature is engaged."
310                         " Affects only the queues configured with split"
311                         " offloads.\n\n"
312
313                         "set txpkts (x[,y]*)\n"
314                         "    Set the length of each segment of TXONLY"
315                         " and optionally CSUM packets.\n\n"
316
317                         "set txsplit (off|on|rand)\n"
318                         "    Set the split policy for the TX packets."
319                         " Right now only applicable for CSUM and TXONLY"
320                         " modes\n\n"
321
322                         "set txtimes (x, y)\n"
323                         "    Set the scheduling on timestamps"
324                         " timings for the TXONLY mode\n\n"
325
326                         "set corelist (x[,y]*)\n"
327                         "    Set the list of forwarding cores.\n\n"
328
329                         "set portlist (x[,y]*)\n"
330                         "    Set the list of forwarding ports.\n\n"
331
332                         "set port setup on (iterator|event)\n"
333                         "    Select how attached port is retrieved for setup.\n\n"
334
335                         "set tx loopback (port_id) (on|off)\n"
336                         "    Enable or disable tx loopback.\n\n"
337
338                         "set all queues drop (port_id) (on|off)\n"
339                         "    Set drop enable bit for all queues.\n\n"
340
341                         "set vf split drop (port_id) (vf_id) (on|off)\n"
342                         "    Set split drop enable bit for a VF from the PF.\n\n"
343
344                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
345                         "    Set MAC antispoof for a VF from the PF.\n\n"
346
347                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
348                         "    Enable MACsec offload.\n\n"
349
350                         "set macsec offload (port_id) off\n"
351                         "    Disable MACsec offload.\n\n"
352
353                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
354                         "    Configure MACsec secure connection (SC).\n\n"
355
356                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
357                         "    Configure MACsec secure association (SA).\n\n"
358
359                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
360                         "    Set VF broadcast for a VF from the PF.\n\n"
361
362                         "vlan set stripq (on|off) (port_id,queue_id)\n"
363                         "    Set the VLAN strip for a queue on a port.\n\n"
364
365                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
366                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
367
368                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
369                         "    Set VLAN insert for a VF from the PF.\n\n"
370
371                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
372                         "    Set VLAN antispoof for a VF from the PF.\n\n"
373
374                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
375                         "    Set VLAN tag for a VF from the PF.\n\n"
376
377                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
378                         "    Set a VF's max bandwidth(Mbps).\n\n"
379
380                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
381                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
382
383                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
384                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
385
386                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
387                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
388
389                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
390                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
391
392                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
393                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
394
395                         "vlan set (inner|outer) tpid (value) (port_id)\n"
396                         "    Set the VLAN TPID for Packet Filtering on"
397                         " a port\n\n"
398
399                         "rx_vlan add (vlan_id|all) (port_id)\n"
400                         "    Add a vlan_id, or all identifiers, to the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan rm (vlan_id|all) (port_id)\n"
404                         "    Remove a vlan_id, or all identifiers, from the set"
405                         " of VLAN identifiers filtered by port_id.\n\n"
406
407                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Add a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
412                         "    Remove a vlan_id, to the set of VLAN identifiers"
413                         "filtered for VF(s) from port_id.\n\n"
414
415                         "rx_vxlan_port add (udp_port) (port_id)\n"
416                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
417
418                         "rx_vxlan_port rm (udp_port) (port_id)\n"
419                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
420
421                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
422                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
423                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
424
425                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
426                         "    Set port based TX VLAN insertion.\n\n"
427
428                         "tx_vlan reset (port_id)\n"
429                         "    Disable hardware insertion of a VLAN header in"
430                         " packets sent on a port.\n\n"
431
432                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
433                         "    Select hardware or software calculation of the"
434                         " checksum when transmitting a packet using the"
435                         " csum forward engine.\n"
436                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
437                         "    outer-ip concerns the outer IP layer in"
438                         "    outer-udp concerns the outer UDP layer in"
439                         " case the packet is recognized as a tunnel packet by"
440                         " the forward engine (vxlan, gre and ipip are supported)\n"
441                         "    Please check the NIC datasheet for HW limits.\n\n"
442
443                         "csum parse-tunnel (on|off) (tx_port_id)\n"
444                         "    If disabled, treat tunnel packets as non-tunneled"
445                         " packets (treat inner headers as payload). The port\n"
446                         "    argument is the port used for TX in csum forward"
447                         " engine.\n\n"
448
449                         "csum show (port_id)\n"
450                         "    Display tx checksum offload configuration\n\n"
451
452                         "tso set (segsize) (portid)\n"
453                         "    Enable TCP Segmentation Offload in csum forward"
454                         " engine.\n"
455                         "    Please check the NIC datasheet for HW limits.\n\n"
456
457                         "tso show (portid)"
458                         "    Display the status of TCP Segmentation Offload.\n\n"
459
460                         "set port (port_id) gro on|off\n"
461                         "    Enable or disable Generic Receive Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "show port (port_id) gro\n"
465                         "    Display GRO configuration.\n\n"
466
467                         "set gro flush (cycles)\n"
468                         "    Set the cycle to flush GROed packets from"
469                         " reassembly tables.\n\n"
470
471                         "set port (port_id) gso (on|off)"
472                         "    Enable or disable Generic Segmentation Offload in"
473                         " csum forwarding engine.\n\n"
474
475                         "set gso segsz (length)\n"
476                         "    Set max packet length for output GSO segments,"
477                         " including packet header and payload.\n\n"
478
479                         "show port (port_id) gso\n"
480                         "    Show GSO configuration.\n\n"
481
482                         "set fwd (%s)\n"
483                         "    Set packet forwarding mode.\n\n"
484
485                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
486                         "    Add a MAC address on port_id.\n\n"
487
488                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
489                         "    Remove a MAC address from port_id.\n\n"
490
491                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Set the default MAC address for port_id.\n\n"
493
494                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
495                         "    Add a MAC address for a VF on the port.\n\n"
496
497                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the MAC address for a VF from the PF.\n\n"
499
500                         "set eth-peer (port_id) (peer_addr)\n"
501                         "    set the peer address for certain port.\n\n"
502
503                         "set port (port_id) uta (mac_address|all) (on|off)\n"
504                         "    Add/Remove a or all unicast hash filter(s)"
505                         "from port X.\n\n"
506
507                         "set promisc (port_id|all) (on|off)\n"
508                         "    Set the promiscuous mode on port_id, or all.\n\n"
509
510                         "set allmulti (port_id|all) (on|off)\n"
511                         "    Set the allmulti mode on port_id, or all.\n\n"
512
513                         "set vf promisc (port_id) (vf_id) (on|off)\n"
514                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
515
516                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
517                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
518
519                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
520                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
521                         " (on|off) autoneg (on|off) (port_id)\n"
522                         "set flow_ctrl rx (on|off) (portid)\n"
523                         "set flow_ctrl tx (on|off) (portid)\n"
524                         "set flow_ctrl high_water (high_water) (portid)\n"
525                         "set flow_ctrl low_water (low_water) (portid)\n"
526                         "set flow_ctrl pause_time (pause_time) (portid)\n"
527                         "set flow_ctrl send_xon (send_xon) (portid)\n"
528                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
529                         "set flow_ctrl autoneg (on|off) (port_id)\n"
530                         "    Set the link flow control parameter on a port.\n\n"
531
532                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
533                         " (low_water) (pause_time) (priority) (port_id)\n"
534                         "    Set the priority flow control parameter on a"
535                         " port.\n\n"
536
537                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
538                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
539                         " queue on port.\n"
540                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
541                         " on port 0 to mapping 5.\n\n"
542
543                         "set xstats-hide-zero on|off\n"
544                         "    Set the option to hide the zero values"
545                         " for xstats display.\n"
546
547                         "set record-core-cycles on|off\n"
548                         "    Set the option to enable measurement of CPU cycles.\n"
549
550                         "set record-burst-stats on|off\n"
551                         "    Set the option to enable display of RX and TX bursts.\n"
552
553                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
554                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
555
556                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
557                         "|MPE) (on|off)\n"
558                         "    AUPE:accepts untagged VLAN;"
559                         "ROPE:accept unicast hash\n\n"
560                         "    BAM:accepts broadcast packets;"
561                         "MPE:accepts all multicast packets\n\n"
562                         "    Enable/Disable a VF receive mode of a port\n\n"
563
564                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
565                         "    Set rate limit for a queue of a port\n\n"
566
567                         "set port (port_id) vf (vf_id) rate (rate_num) "
568                         "queue_mask (queue_mask_value)\n"
569                         "    Set rate limit for queues in VF of a port\n\n"
570
571                         "set port (port_id) mirror-rule (rule_id)"
572                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
573                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
574                         "   Set pool or vlan type mirror rule on a port.\n"
575                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
576                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
577                         " to pool 0.\n\n"
578
579                         "set port (port_id) mirror-rule (rule_id)"
580                         " (uplink-mirror|downlink-mirror) dst-pool"
581                         " (pool_id) (on|off)\n"
582                         "   Set uplink or downlink type mirror rule on a port.\n"
583                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
584                         " 0 on' enable mirror income traffic to pool 0.\n\n"
585
586                         "reset port (port_id) mirror-rule (rule_id)\n"
587                         "   Reset a mirror rule.\n\n"
588
589                         "set flush_rx (on|off)\n"
590                         "   Flush (default) or don't flush RX streams before"
591                         " forwarding. Mainly used with PCAP drivers.\n\n"
592
593                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
594                         "   Set the bypass mode for the lowest port on bypass enabled"
595                         " NIC.\n\n"
596
597                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
598                         "mode (normal|bypass|isolate) (port_id)\n"
599                         "   Set the event required to initiate specified bypass mode for"
600                         " the lowest port on a bypass enabled NIC where:\n"
601                         "       timeout   = enable bypass after watchdog timeout.\n"
602                         "       os_on     = enable bypass when OS/board is powered on.\n"
603                         "       os_off    = enable bypass when OS/board is powered off.\n"
604                         "       power_on  = enable bypass when power supply is turned on.\n"
605                         "       power_off = enable bypass when power supply is turned off."
606                         "\n\n"
607
608                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
609                         "   Set the bypass watchdog timeout to 'n' seconds"
610                         " where 0 = instant.\n\n"
611
612                         "show bypass config (port_id)\n"
613                         "   Show the bypass configuration for a bypass enabled NIC"
614                         " using the lowest port on the NIC.\n\n"
615
616 #ifdef RTE_NET_BOND
617                         "create bonded device (mode) (socket)\n"
618                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
619
620                         "add bonding slave (slave_id) (port_id)\n"
621                         "       Add a slave device to a bonded device.\n\n"
622
623                         "remove bonding slave (slave_id) (port_id)\n"
624                         "       Remove a slave device from a bonded device.\n\n"
625
626                         "set bonding mode (value) (port_id)\n"
627                         "       Set the bonding mode on a bonded device.\n\n"
628
629                         "set bonding primary (slave_id) (port_id)\n"
630                         "       Set the primary slave for a bonded device.\n\n"
631
632                         "show bonding config (port_id)\n"
633                         "       Show the bonding config for port_id.\n\n"
634
635                         "set bonding mac_addr (port_id) (address)\n"
636                         "       Set the MAC address of a bonded device.\n\n"
637
638                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
639                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
640
641                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
642                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
643
644                         "set bonding mon_period (port_id) (value)\n"
645                         "       Set the bonding link status monitoring polling period in ms.\n\n"
646
647                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
648                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
649
650 #endif
651                         "set link-up port (port_id)\n"
652                         "       Set link up for a port.\n\n"
653
654                         "set link-down port (port_id)\n"
655                         "       Set link down for a port.\n\n"
656
657                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
658                         "    Load a profile package on a port\n\n"
659
660                         "ddp del (port_id) (backup_profile_path)\n"
661                         "    Delete a profile package from a port\n\n"
662
663                         "ptype mapping get (port_id) (valid_only)\n"
664                         "    Get ptype mapping on a port\n\n"
665
666                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
667                         "    Replace target with the pkt_type in ptype mapping\n\n"
668
669                         "ptype mapping reset (port_id)\n"
670                         "    Reset ptype mapping on a port\n\n"
671
672                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
673                         "    Update a ptype mapping item on a port\n\n"
674
675                         "set port (port_id) ptype_mask (ptype_mask)\n"
676                         "    set packet types classification for a specific port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         "set port (port_id) fec_mode auto|off|rs|baser\n"
741                         "    set fec mode for a specific port\n\n"
742
743                         , list_pkt_forwarding_modes()
744                 );
745         }
746
747         if (show_all || !strcmp(res->section, "ports")) {
748
749                 cmdline_printf(
750                         cl,
751                         "\n"
752                         "Port Operations:\n"
753                         "----------------\n\n"
754
755                         "port start (port_id|all)\n"
756                         "    Start all ports or port_id.\n\n"
757
758                         "port stop (port_id|all)\n"
759                         "    Stop all ports or port_id.\n\n"
760
761                         "port close (port_id|all)\n"
762                         "    Close all ports or port_id.\n\n"
763
764                         "port reset (port_id|all)\n"
765                         "    Reset all ports or port_id.\n\n"
766
767                         "port attach (ident)\n"
768                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
769
770                         "port detach (port_id)\n"
771                         "    Detach physical or virtual dev by port_id\n\n"
772
773                         "port config (port_id|all)"
774                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
775                         " duplex (half|full|auto)\n"
776                         "    Set speed and duplex for all ports or port_id\n\n"
777
778                         "port config (port_id|all) loopback (mode)\n"
779                         "    Set loopback mode for all ports or port_id\n\n"
780
781                         "port config all (rxq|txq|rxd|txd) (value)\n"
782                         "    Set number for rxq/txq/rxd/txd.\n\n"
783
784                         "port config all max-pkt-len (value)\n"
785                         "    Set the max packet length.\n\n"
786
787                         "port config all max-lro-pkt-size (value)\n"
788                         "    Set the max LRO aggregated packet size.\n\n"
789
790                         "port config all drop-en (on|off)\n"
791                         "    Enable or disable packet drop on all RX queues of all ports when no "
792                         "receive buffers available.\n\n"
793
794                         "port config all rss (all|default|ip|tcp|udp|sctp|"
795                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
796                         "level-outer|level-inner|<flowtype_id>)\n"
797                         "    Set the RSS mode.\n\n"
798
799                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
800                         "    Set the RSS redirection table.\n\n"
801
802                         "port config (port_id) dcb vt (on|off) (traffic_class)"
803                         " pfc (on|off)\n"
804                         "    Set the DCB mode.\n\n"
805
806                         "port config all burst (value)\n"
807                         "    Set the number of packets per burst.\n\n"
808
809                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
810                         " (value)\n"
811                         "    Set the ring prefetch/host/writeback threshold"
812                         " for tx/rx queue.\n\n"
813
814                         "port config all (txfreet|txrst|rxfreet) (value)\n"
815                         "    Set free threshold for rx/tx, or set"
816                         " tx rs bit threshold.\n\n"
817                         "port config mtu X value\n"
818                         "    Set the MTU of port X to a given value\n\n"
819
820                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
821                         "    Set a rx/tx queue's ring size configuration, the new"
822                         " value will take effect after command that (re-)start the port"
823                         " or command that setup the specific queue\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
826                         "    Start/stop a rx/tx queue of port X. Only take effect"
827                         " when port X is started\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
830                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
831                         " take effect when port X is stopped.\n\n"
832
833                         "port (port_id) (rxq|txq) (queue_id) setup\n"
834                         "    Setup a rx/tx queue of port X.\n\n"
835
836                         "port config (port_id) pctype mapping reset\n"
837                         "    Reset flow type to pctype mapping on a port\n\n"
838
839                         "port config (port_id) pctype mapping update"
840                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
841                         "    Update a flow type to pctype mapping item on a port\n\n"
842
843                         "port config (port_id) pctype (pctype_id) hash_inset|"
844                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
845                         " (field_idx)\n"
846                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset clear all"
850                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
851
852                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
853                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
854
855                         "port config <port_id> rx_offload vlan_strip|"
856                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
857                         "outer_ipv4_cksum|macsec_strip|header_split|"
858                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
859                         "buffer_split|timestamp|security|keep_crc on|off\n"
860                         "     Enable or disable a per port Rx offloading"
861                         " on all Rx queues of a port\n\n"
862
863                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
864                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
865                         "outer_ipv4_cksum|macsec_strip|header_split|"
866                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
867                         "buffer_split|timestamp|security|keep_crc on|off\n"
868                         "    Enable or disable a per queue Rx offloading"
869                         " only on a specific Rx queue\n\n"
870
871                         "port config (port_id) tx_offload vlan_insert|"
872                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
873                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
874                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
875                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
876                         "security on|off\n"
877                         "    Enable or disable a per port Tx offloading"
878                         " on all Tx queues of a port\n\n"
879
880                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
881                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
884                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
885                         " on|off\n"
886                         "    Enable or disable a per queue Tx offloading"
887                         " only on a specific Tx queue\n\n"
888
889                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
890                         "    Load an eBPF program as a callback"
891                         " for particular RX/TX queue\n\n"
892
893                         "bpf-unload rx|tx (port) (queue)\n"
894                         "    Unload previously loaded eBPF program"
895                         " for particular RX/TX queue\n\n"
896
897                         "port config (port_id) tx_metadata (value)\n"
898                         "    Set Tx metadata value per port. Testpmd will add this value"
899                         " to any Tx packet sent from this port\n\n"
900
901                         "port config (port_id) dynf (name) set|clear\n"
902                         "    Register a dynf and Set/clear this flag on Tx. "
903                         "Testpmd will set this value to any Tx packet "
904                         "sent from this port\n\n"
905                 );
906         }
907
908         if (show_all || !strcmp(res->section, "registers")) {
909
910                 cmdline_printf(
911                         cl,
912                         "\n"
913                         "Registers:\n"
914                         "----------\n\n"
915
916                         "read reg (port_id) (address)\n"
917                         "    Display value of a port register.\n\n"
918
919                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
920                         "    Display a port register bit field.\n\n"
921
922                         "read regbit (port_id) (address) (bit_x)\n"
923                         "    Display a single port register bit.\n\n"
924
925                         "write reg (port_id) (address) (value)\n"
926                         "    Set value of a port register.\n\n"
927
928                         "write regfield (port_id) (address) (bit_x) (bit_y)"
929                         " (value)\n"
930                         "    Set bit field of a port register.\n\n"
931
932                         "write regbit (port_id) (address) (bit_x) (value)\n"
933                         "    Set single bit value of a port register.\n\n"
934                 );
935         }
936         if (show_all || !strcmp(res->section, "filters")) {
937
938                 cmdline_printf(
939                         cl,
940                         "\n"
941                         "filters:\n"
942                         "--------\n\n"
943
944 #ifdef RTE_NET_I40E
945                         "flow_director_filter (port_id) mode raw (add|del|update)"
946                         " flow (flow_id) (drop|fwd) queue (queue_id)"
947                         " fd_id (fd_id_value) packet (packet file name)\n"
948                         "    Add/Del a raw type flow director filter.\n\n"
949 #endif
950
951                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
952                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
953                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
954                         "    Set flow director IP mask.\n\n"
955
956                         "flow_director_mask (port_id) mode MAC-VLAN"
957                         " vlan (vlan_value)\n"
958                         "    Set flow director MAC-VLAN mask.\n\n"
959
960                         "flow_director_mask (port_id) mode Tunnel"
961                         " vlan (vlan_value) mac (mac_value)"
962                         " tunnel-type (tunnel_type_value)"
963                         " tunnel-id (tunnel_id_value)\n"
964                         "    Set flow director Tunnel mask.\n\n"
965
966                         "flow_director_flex_payload (port_id)"
967                         " (raw|l2|l3|l4) (config)\n"
968                         "    Configure flex payload selection.\n\n"
969
970                         "flow validate {port_id}"
971                         " [group {group_id}] [priority {level}]"
972                         " [ingress] [egress]"
973                         " pattern {item} [/ {item} [...]] / end"
974                         " actions {action} [/ {action} [...]] / end\n"
975                         "    Check whether a flow rule can be created.\n\n"
976
977                         "flow create {port_id}"
978                         " [group {group_id}] [priority {level}]"
979                         " [ingress] [egress]"
980                         " pattern {item} [/ {item} [...]] / end"
981                         " actions {action} [/ {action} [...]] / end\n"
982                         "    Create a flow rule.\n\n"
983
984                         "flow destroy {port_id} rule {rule_id} [...]\n"
985                         "    Destroy specific flow rules.\n\n"
986
987                         "flow flush {port_id}\n"
988                         "    Destroy all flow rules.\n\n"
989
990                         "flow query {port_id} {rule_id} {action}\n"
991                         "    Query an existing flow rule.\n\n"
992
993                         "flow list {port_id} [group {group_id}] [...]\n"
994                         "    List existing flow rules sorted by priority,"
995                         " filtered by group identifiers.\n\n"
996
997                         "flow isolate {port_id} {boolean}\n"
998                         "    Restrict ingress traffic to the defined"
999                         " flow rules\n\n"
1000
1001                         "flow aged {port_id} [destroy]\n"
1002                         "    List and destroy aged flows"
1003                         " flow rules\n\n"
1004
1005                         "flow shared_action {port_id} create"
1006                         " [action_id {shared_action_id}]"
1007                         " [ingress] [egress]"
1008                         " action {action} / end\n"
1009                         "    Create shared action.\n\n"
1010
1011                         "flow shared_action {port_id} update"
1012                         " {shared_action_id} action {action} / end\n"
1013                         "    Update shared action.\n\n"
1014
1015                         "flow shared_action {port_id} destroy"
1016                         " action_id {shared_action_id} [...]\n"
1017                         "    Destroy specific shared actions.\n\n"
1018
1019                         "flow shared_action {port_id} query"
1020                         " {shared_action_id}\n"
1021                         "    Query an existing shared action.\n\n"
1022
1023                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1024                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1025                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1026                         "       Configure the VXLAN encapsulation for flows.\n\n"
1027
1028                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1029                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1030                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1031                         " eth-dst (eth-dst)\n"
1032                         "       Configure the VXLAN encapsulation for flows.\n\n"
1033
1034                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1035                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1036                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1037                         " eth-dst (eth-dst)\n"
1038                         "       Configure the VXLAN encapsulation for flows.\n\n"
1039
1040                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1041                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1042                         " (eth-dst)\n"
1043                         "       Configure the NVGRE encapsulation for flows.\n\n"
1044
1045                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1046                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1047                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1048                         "       Configure the NVGRE encapsulation for flows.\n\n"
1049
1050                         "set raw_encap {flow items}\n"
1051                         "       Configure the encapsulation with raw data.\n\n"
1052
1053                         "set raw_decap {flow items}\n"
1054                         "       Configure the decapsulation with raw data.\n\n"
1055
1056                 );
1057         }
1058
1059         if (show_all || !strcmp(res->section, "traffic_management")) {
1060                 cmdline_printf(
1061                         cl,
1062                         "\n"
1063                         "Traffic Management:\n"
1064                         "--------------\n"
1065                         "show port tm cap (port_id)\n"
1066                         "       Display the port TM capability.\n\n"
1067
1068                         "show port tm level cap (port_id) (level_id)\n"
1069                         "       Display the port TM hierarchical level capability.\n\n"
1070
1071                         "show port tm node cap (port_id) (node_id)\n"
1072                         "       Display the port TM node capability.\n\n"
1073
1074                         "show port tm node type (port_id) (node_id)\n"
1075                         "       Display the port TM node type.\n\n"
1076
1077                         "show port tm node stats (port_id) (node_id) (clear)\n"
1078                         "       Display the port TM node stats.\n\n"
1079
1080                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1081                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1082                         " (packet_length_adjust) (packet_mode)\n"
1083                         "       Add port tm node private shaper profile.\n\n"
1084
1085                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1086                         "       Delete port tm node private shaper profile.\n\n"
1087
1088                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1089                         " (shaper_profile_id)\n"
1090                         "       Add/update port tm node shared shaper.\n\n"
1091
1092                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1093                         "       Delete port tm node shared shaper.\n\n"
1094
1095                         "set port tm node shaper profile (port_id) (node_id)"
1096                         " (shaper_profile_id)\n"
1097                         "       Set port tm node shaper profile.\n\n"
1098
1099                         "add port tm node wred profile (port_id) (wred_profile_id)"
1100                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1101                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1102                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1103                         "       Add port tm node wred profile.\n\n"
1104
1105                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1106                         "       Delete port tm node wred profile.\n\n"
1107
1108                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1109                         " (priority) (weight) (level_id) (shaper_profile_id)"
1110                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1111                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1112                         "       Add port tm nonleaf node.\n\n"
1113
1114                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1115                         " (priority) (weight) (level_id) (shaper_profile_id)"
1116                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1117                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1118                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1119
1120                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1121                         " (priority) (weight) (level_id) (shaper_profile_id)"
1122                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1123                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1124                         "       Add port tm leaf node.\n\n"
1125
1126                         "del port tm node (port_id) (node_id)\n"
1127                         "       Delete port tm node.\n\n"
1128
1129                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1130                         " (priority) (weight)\n"
1131                         "       Set port tm node parent.\n\n"
1132
1133                         "suspend port tm node (port_id) (node_id)"
1134                         "       Suspend tm node.\n\n"
1135
1136                         "resume port tm node (port_id) (node_id)"
1137                         "       Resume tm node.\n\n"
1138
1139                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1140                         "       Commit tm hierarchy.\n\n"
1141
1142                         "set port tm mark ip_ecn (port) (green) (yellow)"
1143                         " (red)\n"
1144                         "    Enables/Disables the traffic management marking"
1145                         " for IP ECN (Explicit Congestion Notification)"
1146                         " packets on a given port\n\n"
1147
1148                         "set port tm mark ip_dscp (port) (green) (yellow)"
1149                         " (red)\n"
1150                         "    Enables/Disables the traffic management marking"
1151                         " on the port for IP dscp packets\n\n"
1152
1153                         "set port tm mark vlan_dei (port) (green) (yellow)"
1154                         " (red)\n"
1155                         "    Enables/Disables the traffic management marking"
1156                         " on the port for VLAN packets with DEI enabled\n\n"
1157                 );
1158         }
1159
1160         if (show_all || !strcmp(res->section, "devices")) {
1161                 cmdline_printf(
1162                         cl,
1163                         "\n"
1164                         "Device Operations:\n"
1165                         "--------------\n"
1166                         "device detach (identifier)\n"
1167                         "       Detach device by identifier.\n\n"
1168                 );
1169         }
1170
1171 }
1172
1173 cmdline_parse_token_string_t cmd_help_long_help =
1174         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1175
1176 cmdline_parse_token_string_t cmd_help_long_section =
1177         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1178                         "all#control#display#config#"
1179                         "ports#registers#filters#traffic_management#devices");
1180
1181 cmdline_parse_inst_t cmd_help_long = {
1182         .f = cmd_help_long_parsed,
1183         .data = NULL,
1184         .help_str = "help all|control|display|config|ports|register|"
1185                 "filters|traffic_management|devices: "
1186                 "Show help",
1187         .tokens = {
1188                 (void *)&cmd_help_long_help,
1189                 (void *)&cmd_help_long_section,
1190                 NULL,
1191         },
1192 };
1193
1194
1195 /* *** start/stop/close all ports *** */
1196 struct cmd_operate_port_result {
1197         cmdline_fixed_string_t keyword;
1198         cmdline_fixed_string_t name;
1199         cmdline_fixed_string_t value;
1200 };
1201
1202 static void cmd_operate_port_parsed(void *parsed_result,
1203                                 __rte_unused struct cmdline *cl,
1204                                 __rte_unused void *data)
1205 {
1206         struct cmd_operate_port_result *res = parsed_result;
1207
1208         if (!strcmp(res->name, "start"))
1209                 start_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "stop"))
1211                 stop_port(RTE_PORT_ALL);
1212         else if (!strcmp(res->name, "close"))
1213                 close_port(RTE_PORT_ALL);
1214         else if (!strcmp(res->name, "reset"))
1215                 reset_port(RTE_PORT_ALL);
1216         else
1217                 printf("Unknown parameter\n");
1218 }
1219
1220 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1221         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1222                                                                 "port");
1223 cmdline_parse_token_string_t cmd_operate_port_all_port =
1224         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1225                                                 "start#stop#close#reset");
1226 cmdline_parse_token_string_t cmd_operate_port_all_all =
1227         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1228
1229 cmdline_parse_inst_t cmd_operate_port = {
1230         .f = cmd_operate_port_parsed,
1231         .data = NULL,
1232         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1233         .tokens = {
1234                 (void *)&cmd_operate_port_all_cmd,
1235                 (void *)&cmd_operate_port_all_port,
1236                 (void *)&cmd_operate_port_all_all,
1237                 NULL,
1238         },
1239 };
1240
1241 /* *** start/stop/close specific port *** */
1242 struct cmd_operate_specific_port_result {
1243         cmdline_fixed_string_t keyword;
1244         cmdline_fixed_string_t name;
1245         uint8_t value;
1246 };
1247
1248 static void cmd_operate_specific_port_parsed(void *parsed_result,
1249                         __rte_unused struct cmdline *cl,
1250                                 __rte_unused void *data)
1251 {
1252         struct cmd_operate_specific_port_result *res = parsed_result;
1253
1254         if (!strcmp(res->name, "start"))
1255                 start_port(res->value);
1256         else if (!strcmp(res->name, "stop"))
1257                 stop_port(res->value);
1258         else if (!strcmp(res->name, "close"))
1259                 close_port(res->value);
1260         else if (!strcmp(res->name, "reset"))
1261                 reset_port(res->value);
1262         else
1263                 printf("Unknown parameter\n");
1264 }
1265
1266 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1267         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1268                                                         keyword, "port");
1269 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1270         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1271                                                 name, "start#stop#close#reset");
1272 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1273         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1274                                                         value, RTE_UINT8);
1275
1276 cmdline_parse_inst_t cmd_operate_specific_port = {
1277         .f = cmd_operate_specific_port_parsed,
1278         .data = NULL,
1279         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1280         .tokens = {
1281                 (void *)&cmd_operate_specific_port_cmd,
1282                 (void *)&cmd_operate_specific_port_port,
1283                 (void *)&cmd_operate_specific_port_id,
1284                 NULL,
1285         },
1286 };
1287
1288 /* *** enable port setup (after attach) via iterator or event *** */
1289 struct cmd_set_port_setup_on_result {
1290         cmdline_fixed_string_t set;
1291         cmdline_fixed_string_t port;
1292         cmdline_fixed_string_t setup;
1293         cmdline_fixed_string_t on;
1294         cmdline_fixed_string_t mode;
1295 };
1296
1297 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1298                                 __rte_unused struct cmdline *cl,
1299                                 __rte_unused void *data)
1300 {
1301         struct cmd_set_port_setup_on_result *res = parsed_result;
1302
1303         if (strcmp(res->mode, "event") == 0)
1304                 setup_on_probe_event = true;
1305         else if (strcmp(res->mode, "iterator") == 0)
1306                 setup_on_probe_event = false;
1307         else
1308                 printf("Unknown mode\n");
1309 }
1310
1311 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1312         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1313                         set, "set");
1314 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1315         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1316                         port, "port");
1317 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1318         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1319                         setup, "setup");
1320 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1321         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1322                         on, "on");
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1324         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325                         mode, "iterator#event");
1326
1327 cmdline_parse_inst_t cmd_set_port_setup_on = {
1328         .f = cmd_set_port_setup_on_parsed,
1329         .data = NULL,
1330         .help_str = "set port setup on iterator|event",
1331         .tokens = {
1332                 (void *)&cmd_set_port_setup_on_set,
1333                 (void *)&cmd_set_port_setup_on_port,
1334                 (void *)&cmd_set_port_setup_on_setup,
1335                 (void *)&cmd_set_port_setup_on_on,
1336                 (void *)&cmd_set_port_setup_on_mode,
1337                 NULL,
1338         },
1339 };
1340
1341 /* *** attach a specified port *** */
1342 struct cmd_operate_attach_port_result {
1343         cmdline_fixed_string_t port;
1344         cmdline_fixed_string_t keyword;
1345         cmdline_multi_string_t identifier;
1346 };
1347
1348 static void cmd_operate_attach_port_parsed(void *parsed_result,
1349                                 __rte_unused struct cmdline *cl,
1350                                 __rte_unused void *data)
1351 {
1352         struct cmd_operate_attach_port_result *res = parsed_result;
1353
1354         if (!strcmp(res->keyword, "attach"))
1355                 attach_port(res->identifier);
1356         else
1357                 printf("Unknown parameter\n");
1358 }
1359
1360 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1361         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1362                         port, "port");
1363 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1364         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1365                         keyword, "attach");
1366 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1367         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1368                         identifier, TOKEN_STRING_MULTI);
1369
1370 cmdline_parse_inst_t cmd_operate_attach_port = {
1371         .f = cmd_operate_attach_port_parsed,
1372         .data = NULL,
1373         .help_str = "port attach <identifier>: "
1374                 "(identifier: pci address or virtual dev name)",
1375         .tokens = {
1376                 (void *)&cmd_operate_attach_port_port,
1377                 (void *)&cmd_operate_attach_port_keyword,
1378                 (void *)&cmd_operate_attach_port_identifier,
1379                 NULL,
1380         },
1381 };
1382
1383 /* *** detach a specified port *** */
1384 struct cmd_operate_detach_port_result {
1385         cmdline_fixed_string_t port;
1386         cmdline_fixed_string_t keyword;
1387         portid_t port_id;
1388 };
1389
1390 static void cmd_operate_detach_port_parsed(void *parsed_result,
1391                                 __rte_unused struct cmdline *cl,
1392                                 __rte_unused void *data)
1393 {
1394         struct cmd_operate_detach_port_result *res = parsed_result;
1395
1396         if (!strcmp(res->keyword, "detach")) {
1397                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1398                 detach_port_device(res->port_id);
1399         } else {
1400                 printf("Unknown parameter\n");
1401         }
1402 }
1403
1404 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1405         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1406                         port, "port");
1407 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1408         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1409                         keyword, "detach");
1410 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1411         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1412                         port_id, RTE_UINT16);
1413
1414 cmdline_parse_inst_t cmd_operate_detach_port = {
1415         .f = cmd_operate_detach_port_parsed,
1416         .data = NULL,
1417         .help_str = "port detach <port_id>",
1418         .tokens = {
1419                 (void *)&cmd_operate_detach_port_port,
1420                 (void *)&cmd_operate_detach_port_keyword,
1421                 (void *)&cmd_operate_detach_port_port_id,
1422                 NULL,
1423         },
1424 };
1425
1426 /* *** detach device by identifier *** */
1427 struct cmd_operate_detach_device_result {
1428         cmdline_fixed_string_t device;
1429         cmdline_fixed_string_t keyword;
1430         cmdline_fixed_string_t identifier;
1431 };
1432
1433 static void cmd_operate_detach_device_parsed(void *parsed_result,
1434                                 __rte_unused struct cmdline *cl,
1435                                 __rte_unused void *data)
1436 {
1437         struct cmd_operate_detach_device_result *res = parsed_result;
1438
1439         if (!strcmp(res->keyword, "detach"))
1440                 detach_devargs(res->identifier);
1441         else
1442                 printf("Unknown parameter\n");
1443 }
1444
1445 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1446         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1447                         device, "device");
1448 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1449         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1450                         keyword, "detach");
1451 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1453                         identifier, NULL);
1454
1455 cmdline_parse_inst_t cmd_operate_detach_device = {
1456         .f = cmd_operate_detach_device_parsed,
1457         .data = NULL,
1458         .help_str = "device detach <identifier>:"
1459                 "(identifier: pci address or virtual dev name)",
1460         .tokens = {
1461                 (void *)&cmd_operate_detach_device_device,
1462                 (void *)&cmd_operate_detach_device_keyword,
1463                 (void *)&cmd_operate_detach_device_identifier,
1464                 NULL,
1465         },
1466 };
1467 /* *** configure speed for all ports *** */
1468 struct cmd_config_speed_all {
1469         cmdline_fixed_string_t port;
1470         cmdline_fixed_string_t keyword;
1471         cmdline_fixed_string_t all;
1472         cmdline_fixed_string_t item1;
1473         cmdline_fixed_string_t item2;
1474         cmdline_fixed_string_t value1;
1475         cmdline_fixed_string_t value2;
1476 };
1477
1478 static int
1479 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1480 {
1481
1482         int duplex;
1483
1484         if (!strcmp(duplexstr, "half")) {
1485                 duplex = ETH_LINK_HALF_DUPLEX;
1486         } else if (!strcmp(duplexstr, "full")) {
1487                 duplex = ETH_LINK_FULL_DUPLEX;
1488         } else if (!strcmp(duplexstr, "auto")) {
1489                 duplex = ETH_LINK_FULL_DUPLEX;
1490         } else {
1491                 printf("Unknown duplex parameter\n");
1492                 return -1;
1493         }
1494
1495         if (!strcmp(speedstr, "10")) {
1496                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1497                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1498         } else if (!strcmp(speedstr, "100")) {
1499                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1500                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1501         } else {
1502                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1503                         printf("Invalid speed/duplex parameters\n");
1504                         return -1;
1505                 }
1506                 if (!strcmp(speedstr, "1000")) {
1507                         *speed = ETH_LINK_SPEED_1G;
1508                 } else if (!strcmp(speedstr, "10000")) {
1509                         *speed = ETH_LINK_SPEED_10G;
1510                 } else if (!strcmp(speedstr, "25000")) {
1511                         *speed = ETH_LINK_SPEED_25G;
1512                 } else if (!strcmp(speedstr, "40000")) {
1513                         *speed = ETH_LINK_SPEED_40G;
1514                 } else if (!strcmp(speedstr, "50000")) {
1515                         *speed = ETH_LINK_SPEED_50G;
1516                 } else if (!strcmp(speedstr, "100000")) {
1517                         *speed = ETH_LINK_SPEED_100G;
1518                 } else if (!strcmp(speedstr, "200000")) {
1519                         *speed = ETH_LINK_SPEED_200G;
1520                 } else if (!strcmp(speedstr, "auto")) {
1521                         *speed = ETH_LINK_SPEED_AUTONEG;
1522                 } else {
1523                         printf("Unknown speed parameter\n");
1524                         return -1;
1525                 }
1526         }
1527
1528         return 0;
1529 }
1530
1531 static void
1532 cmd_config_speed_all_parsed(void *parsed_result,
1533                         __rte_unused struct cmdline *cl,
1534                         __rte_unused void *data)
1535 {
1536         struct cmd_config_speed_all *res = parsed_result;
1537         uint32_t link_speed;
1538         portid_t pid;
1539
1540         if (!all_ports_stopped()) {
1541                 printf("Please stop all ports first\n");
1542                 return;
1543         }
1544
1545         if (parse_and_check_speed_duplex(res->value1, res->value2,
1546                         &link_speed) < 0)
1547                 return;
1548
1549         RTE_ETH_FOREACH_DEV(pid) {
1550                 ports[pid].dev_conf.link_speeds = link_speed;
1551         }
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_speed_all_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1558 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1560                                                         "config");
1561 cmdline_parse_token_string_t cmd_config_speed_all_all =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1563 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1565 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1567                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1568 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1570 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1572                                                 "half#full#auto");
1573
1574 cmdline_parse_inst_t cmd_config_speed_all = {
1575         .f = cmd_config_speed_all_parsed,
1576         .data = NULL,
1577         .help_str = "port config all speed "
1578                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1579                                                         "half|full|auto",
1580         .tokens = {
1581                 (void *)&cmd_config_speed_all_port,
1582                 (void *)&cmd_config_speed_all_keyword,
1583                 (void *)&cmd_config_speed_all_all,
1584                 (void *)&cmd_config_speed_all_item1,
1585                 (void *)&cmd_config_speed_all_value1,
1586                 (void *)&cmd_config_speed_all_item2,
1587                 (void *)&cmd_config_speed_all_value2,
1588                 NULL,
1589         },
1590 };
1591
1592 /* *** configure speed for specific port *** */
1593 struct cmd_config_speed_specific {
1594         cmdline_fixed_string_t port;
1595         cmdline_fixed_string_t keyword;
1596         portid_t id;
1597         cmdline_fixed_string_t item1;
1598         cmdline_fixed_string_t item2;
1599         cmdline_fixed_string_t value1;
1600         cmdline_fixed_string_t value2;
1601 };
1602
1603 static void
1604 cmd_config_speed_specific_parsed(void *parsed_result,
1605                                 __rte_unused struct cmdline *cl,
1606                                 __rte_unused void *data)
1607 {
1608         struct cmd_config_speed_specific *res = parsed_result;
1609         uint32_t link_speed;
1610
1611         if (!all_ports_stopped()) {
1612                 printf("Please stop all ports first\n");
1613                 return;
1614         }
1615
1616         if (port_id_is_invalid(res->id, ENABLED_WARN))
1617                 return;
1618
1619         if (parse_and_check_speed_duplex(res->value1, res->value2,
1620                         &link_speed) < 0)
1621                 return;
1622
1623         ports[res->id].dev_conf.link_speeds = link_speed;
1624
1625         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1626 }
1627
1628
1629 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1630         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1631                                                                 "port");
1632 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1633         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1634                                                                 "config");
1635 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1636         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1637 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1638         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1639                                                                 "speed");
1640 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1642                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1643 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1645                                                                 "duplex");
1646 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1648                                                         "half#full#auto");
1649
1650 cmdline_parse_inst_t cmd_config_speed_specific = {
1651         .f = cmd_config_speed_specific_parsed,
1652         .data = NULL,
1653         .help_str = "port config <port_id> speed "
1654                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1655                                                         "half|full|auto",
1656         .tokens = {
1657                 (void *)&cmd_config_speed_specific_port,
1658                 (void *)&cmd_config_speed_specific_keyword,
1659                 (void *)&cmd_config_speed_specific_id,
1660                 (void *)&cmd_config_speed_specific_item1,
1661                 (void *)&cmd_config_speed_specific_value1,
1662                 (void *)&cmd_config_speed_specific_item2,
1663                 (void *)&cmd_config_speed_specific_value2,
1664                 NULL,
1665         },
1666 };
1667
1668 /* *** configure loopback for all ports *** */
1669 struct cmd_config_loopback_all {
1670         cmdline_fixed_string_t port;
1671         cmdline_fixed_string_t keyword;
1672         cmdline_fixed_string_t all;
1673         cmdline_fixed_string_t item;
1674         uint32_t mode;
1675 };
1676
1677 static void
1678 cmd_config_loopback_all_parsed(void *parsed_result,
1679                         __rte_unused struct cmdline *cl,
1680                         __rte_unused void *data)
1681 {
1682         struct cmd_config_loopback_all *res = parsed_result;
1683         portid_t pid;
1684
1685         if (!all_ports_stopped()) {
1686                 printf("Please stop all ports first\n");
1687                 return;
1688         }
1689
1690         RTE_ETH_FOREACH_DEV(pid) {
1691                 ports[pid].dev_conf.lpbk_mode = res->mode;
1692         }
1693
1694         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1695 }
1696
1697 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1698         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1699 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1700         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1701                                                         "config");
1702 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1704 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1705         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1706                                                         "loopback");
1707 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1708         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1709
1710 cmdline_parse_inst_t cmd_config_loopback_all = {
1711         .f = cmd_config_loopback_all_parsed,
1712         .data = NULL,
1713         .help_str = "port config all loopback <mode>",
1714         .tokens = {
1715                 (void *)&cmd_config_loopback_all_port,
1716                 (void *)&cmd_config_loopback_all_keyword,
1717                 (void *)&cmd_config_loopback_all_all,
1718                 (void *)&cmd_config_loopback_all_item,
1719                 (void *)&cmd_config_loopback_all_mode,
1720                 NULL,
1721         },
1722 };
1723
1724 /* *** configure loopback for specific port *** */
1725 struct cmd_config_loopback_specific {
1726         cmdline_fixed_string_t port;
1727         cmdline_fixed_string_t keyword;
1728         uint16_t port_id;
1729         cmdline_fixed_string_t item;
1730         uint32_t mode;
1731 };
1732
1733 static void
1734 cmd_config_loopback_specific_parsed(void *parsed_result,
1735                                 __rte_unused struct cmdline *cl,
1736                                 __rte_unused void *data)
1737 {
1738         struct cmd_config_loopback_specific *res = parsed_result;
1739
1740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1741                 return;
1742
1743         if (!port_is_stopped(res->port_id)) {
1744                 printf("Please stop port %u first\n", res->port_id);
1745                 return;
1746         }
1747
1748         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1749
1750         cmd_reconfig_device_queue(res->port_id, 1, 1);
1751 }
1752
1753
1754 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1756                                                                 "port");
1757 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1759                                                                 "config");
1760 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1761         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1762                                                                 RTE_UINT16);
1763 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1765                                                                 "loopback");
1766 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1767         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1768                               RTE_UINT32);
1769
1770 cmdline_parse_inst_t cmd_config_loopback_specific = {
1771         .f = cmd_config_loopback_specific_parsed,
1772         .data = NULL,
1773         .help_str = "port config <port_id> loopback <mode>",
1774         .tokens = {
1775                 (void *)&cmd_config_loopback_specific_port,
1776                 (void *)&cmd_config_loopback_specific_keyword,
1777                 (void *)&cmd_config_loopback_specific_id,
1778                 (void *)&cmd_config_loopback_specific_item,
1779                 (void *)&cmd_config_loopback_specific_mode,
1780                 NULL,
1781         },
1782 };
1783
1784 /* *** configure txq/rxq, txd/rxd *** */
1785 struct cmd_config_rx_tx {
1786         cmdline_fixed_string_t port;
1787         cmdline_fixed_string_t keyword;
1788         cmdline_fixed_string_t all;
1789         cmdline_fixed_string_t name;
1790         uint16_t value;
1791 };
1792
1793 static void
1794 cmd_config_rx_tx_parsed(void *parsed_result,
1795                         __rte_unused struct cmdline *cl,
1796                         __rte_unused void *data)
1797 {
1798         struct cmd_config_rx_tx *res = parsed_result;
1799
1800         if (!all_ports_stopped()) {
1801                 printf("Please stop all ports first\n");
1802                 return;
1803         }
1804         if (!strcmp(res->name, "rxq")) {
1805                 if (!res->value && !nb_txq) {
1806                         printf("Warning: Either rx or tx queues should be non zero\n");
1807                         return;
1808                 }
1809                 if (check_nb_rxq(res->value) != 0)
1810                         return;
1811                 nb_rxq = res->value;
1812         }
1813         else if (!strcmp(res->name, "txq")) {
1814                 if (!res->value && !nb_rxq) {
1815                         printf("Warning: Either rx or tx queues should be non zero\n");
1816                         return;
1817                 }
1818                 if (check_nb_txq(res->value) != 0)
1819                         return;
1820                 nb_txq = res->value;
1821         }
1822         else if (!strcmp(res->name, "rxd")) {
1823                 if (check_nb_rxd(res->value) != 0)
1824                         return;
1825                 nb_rxd = res->value;
1826         } else if (!strcmp(res->name, "txd")) {
1827                 if (check_nb_txd(res->value) != 0)
1828                         return;
1829
1830                 nb_txd = res->value;
1831         } else {
1832                 printf("Unknown parameter\n");
1833                 return;
1834         }
1835
1836         fwd_config_setup();
1837
1838         init_port_config();
1839
1840         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1841 }
1842
1843 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1847 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1849 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1851                                                 "rxq#txq#rxd#txd");
1852 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1853         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1854
1855 cmdline_parse_inst_t cmd_config_rx_tx = {
1856         .f = cmd_config_rx_tx_parsed,
1857         .data = NULL,
1858         .help_str = "port config all rxq|txq|rxd|txd <value>",
1859         .tokens = {
1860                 (void *)&cmd_config_rx_tx_port,
1861                 (void *)&cmd_config_rx_tx_keyword,
1862                 (void *)&cmd_config_rx_tx_all,
1863                 (void *)&cmd_config_rx_tx_name,
1864                 (void *)&cmd_config_rx_tx_value,
1865                 NULL,
1866         },
1867 };
1868
1869 /* *** config max packet length *** */
1870 struct cmd_config_max_pkt_len_result {
1871         cmdline_fixed_string_t port;
1872         cmdline_fixed_string_t keyword;
1873         cmdline_fixed_string_t all;
1874         cmdline_fixed_string_t name;
1875         uint32_t value;
1876 };
1877
1878 static void
1879 cmd_config_max_pkt_len_parsed(void *parsed_result,
1880                                 __rte_unused struct cmdline *cl,
1881                                 __rte_unused void *data)
1882 {
1883         struct cmd_config_max_pkt_len_result *res = parsed_result;
1884         uint32_t max_rx_pkt_len_backup = 0;
1885         portid_t pid;
1886         int ret;
1887
1888         if (!all_ports_stopped()) {
1889                 printf("Please stop all ports first\n");
1890                 return;
1891         }
1892
1893         RTE_ETH_FOREACH_DEV(pid) {
1894                 struct rte_port *port = &ports[pid];
1895
1896                 if (!strcmp(res->name, "max-pkt-len")) {
1897                         if (res->value < RTE_ETHER_MIN_LEN) {
1898                                 printf("max-pkt-len can not be less than %d\n",
1899                                                 RTE_ETHER_MIN_LEN);
1900                                 return;
1901                         }
1902                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1903                                 return;
1904
1905                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1906                         if (ret != 0) {
1907                                 printf("rte_eth_dev_info_get() failed for port %u\n",
1908                                         pid);
1909                                 return;
1910                         }
1911
1912                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1913
1914                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1915                         if (update_jumbo_frame_offload(pid) != 0)
1916                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1917                 } else {
1918                         printf("Unknown parameter\n");
1919                         return;
1920                 }
1921         }
1922
1923         init_port_config();
1924
1925         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1926 }
1927
1928 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1929         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1930                                                                 "port");
1931 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1932         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1933                                                                 "config");
1934 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1936                                                                 "all");
1937 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1939                                                                 "max-pkt-len");
1940 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1941         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1942                                                                 RTE_UINT32);
1943
1944 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1945         .f = cmd_config_max_pkt_len_parsed,
1946         .data = NULL,
1947         .help_str = "port config all max-pkt-len <value>",
1948         .tokens = {
1949                 (void *)&cmd_config_max_pkt_len_port,
1950                 (void *)&cmd_config_max_pkt_len_keyword,
1951                 (void *)&cmd_config_max_pkt_len_all,
1952                 (void *)&cmd_config_max_pkt_len_name,
1953                 (void *)&cmd_config_max_pkt_len_value,
1954                 NULL,
1955         },
1956 };
1957
1958 /* *** config max LRO aggregated packet size *** */
1959 struct cmd_config_max_lro_pkt_size_result {
1960         cmdline_fixed_string_t port;
1961         cmdline_fixed_string_t keyword;
1962         cmdline_fixed_string_t all;
1963         cmdline_fixed_string_t name;
1964         uint32_t value;
1965 };
1966
1967 static void
1968 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1969                                 __rte_unused struct cmdline *cl,
1970                                 __rte_unused void *data)
1971 {
1972         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1973         portid_t pid;
1974
1975         if (!all_ports_stopped()) {
1976                 printf("Please stop all ports first\n");
1977                 return;
1978         }
1979
1980         RTE_ETH_FOREACH_DEV(pid) {
1981                 struct rte_port *port = &ports[pid];
1982
1983                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1984                         if (res->value ==
1985                                         port->dev_conf.rxmode.max_lro_pkt_size)
1986                                 return;
1987
1988                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1989                 } else {
1990                         printf("Unknown parameter\n");
1991                         return;
1992                 }
1993         }
1994
1995         init_port_config();
1996
1997         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1998 }
1999
2000 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2001         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2002                                  port, "port");
2003 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2005                                  keyword, "config");
2006 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2008                                  all, "all");
2009 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2011                                  name, "max-lro-pkt-size");
2012 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2013         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2014                               value, RTE_UINT32);
2015
2016 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2017         .f = cmd_config_max_lro_pkt_size_parsed,
2018         .data = NULL,
2019         .help_str = "port config all max-lro-pkt-size <value>",
2020         .tokens = {
2021                 (void *)&cmd_config_max_lro_pkt_size_port,
2022                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2023                 (void *)&cmd_config_max_lro_pkt_size_all,
2024                 (void *)&cmd_config_max_lro_pkt_size_name,
2025                 (void *)&cmd_config_max_lro_pkt_size_value,
2026                 NULL,
2027         },
2028 };
2029
2030 /* *** configure port MTU *** */
2031 struct cmd_config_mtu_result {
2032         cmdline_fixed_string_t port;
2033         cmdline_fixed_string_t keyword;
2034         cmdline_fixed_string_t mtu;
2035         portid_t port_id;
2036         uint16_t value;
2037 };
2038
2039 static void
2040 cmd_config_mtu_parsed(void *parsed_result,
2041                       __rte_unused struct cmdline *cl,
2042                       __rte_unused void *data)
2043 {
2044         struct cmd_config_mtu_result *res = parsed_result;
2045
2046         if (res->value < RTE_ETHER_MIN_LEN) {
2047                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2048                 return;
2049         }
2050         port_mtu_set(res->port_id, res->value);
2051 }
2052
2053 cmdline_parse_token_string_t cmd_config_mtu_port =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2055                                  "port");
2056 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2058                                  "config");
2059 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2060         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2061                                  "mtu");
2062 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2063         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2064                                  RTE_UINT16);
2065 cmdline_parse_token_num_t cmd_config_mtu_value =
2066         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2067                                  RTE_UINT16);
2068
2069 cmdline_parse_inst_t cmd_config_mtu = {
2070         .f = cmd_config_mtu_parsed,
2071         .data = NULL,
2072         .help_str = "port config mtu <port_id> <value>",
2073         .tokens = {
2074                 (void *)&cmd_config_mtu_port,
2075                 (void *)&cmd_config_mtu_keyword,
2076                 (void *)&cmd_config_mtu_mtu,
2077                 (void *)&cmd_config_mtu_port_id,
2078                 (void *)&cmd_config_mtu_value,
2079                 NULL,
2080         },
2081 };
2082
2083 /* *** configure rx mode *** */
2084 struct cmd_config_rx_mode_flag {
2085         cmdline_fixed_string_t port;
2086         cmdline_fixed_string_t keyword;
2087         cmdline_fixed_string_t all;
2088         cmdline_fixed_string_t name;
2089         cmdline_fixed_string_t value;
2090 };
2091
2092 static void
2093 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2094                                 __rte_unused struct cmdline *cl,
2095                                 __rte_unused void *data)
2096 {
2097         struct cmd_config_rx_mode_flag *res = parsed_result;
2098
2099         if (!all_ports_stopped()) {
2100                 printf("Please stop all ports first\n");
2101                 return;
2102         }
2103
2104         if (!strcmp(res->name, "drop-en")) {
2105                 if (!strcmp(res->value, "on"))
2106                         rx_drop_en = 1;
2107                 else if (!strcmp(res->value, "off"))
2108                         rx_drop_en = 0;
2109                 else {
2110                         printf("Unknown parameter\n");
2111                         return;
2112                 }
2113         } else {
2114                 printf("Unknown parameter\n");
2115                 return;
2116         }
2117
2118         init_port_config();
2119
2120         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2121 }
2122
2123 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2124         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2125 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2126         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2127                                                                 "config");
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2129         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2130 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2131         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2132                                         "drop-en");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2135                                                         "on#off");
2136
2137 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2138         .f = cmd_config_rx_mode_flag_parsed,
2139         .data = NULL,
2140         .help_str = "port config all drop-en on|off",
2141         .tokens = {
2142                 (void *)&cmd_config_rx_mode_flag_port,
2143                 (void *)&cmd_config_rx_mode_flag_keyword,
2144                 (void *)&cmd_config_rx_mode_flag_all,
2145                 (void *)&cmd_config_rx_mode_flag_name,
2146                 (void *)&cmd_config_rx_mode_flag_value,
2147                 NULL,
2148         },
2149 };
2150
2151 /* *** configure rss *** */
2152 struct cmd_config_rss {
2153         cmdline_fixed_string_t port;
2154         cmdline_fixed_string_t keyword;
2155         cmdline_fixed_string_t all;
2156         cmdline_fixed_string_t name;
2157         cmdline_fixed_string_t value;
2158 };
2159
2160 static void
2161 cmd_config_rss_parsed(void *parsed_result,
2162                         __rte_unused struct cmdline *cl,
2163                         __rte_unused void *data)
2164 {
2165         struct cmd_config_rss *res = parsed_result;
2166         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2167         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2168         int use_default = 0;
2169         int all_updated = 1;
2170         int diag;
2171         uint16_t i;
2172         int ret;
2173
2174         if (!strcmp(res->value, "all"))
2175                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2176                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2177                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2178                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2179                         ETH_RSS_ECPRI;
2180         else if (!strcmp(res->value, "eth"))
2181                 rss_conf.rss_hf = ETH_RSS_ETH;
2182         else if (!strcmp(res->value, "vlan"))
2183                 rss_conf.rss_hf = ETH_RSS_VLAN;
2184         else if (!strcmp(res->value, "ip"))
2185                 rss_conf.rss_hf = ETH_RSS_IP;
2186         else if (!strcmp(res->value, "udp"))
2187                 rss_conf.rss_hf = ETH_RSS_UDP;
2188         else if (!strcmp(res->value, "tcp"))
2189                 rss_conf.rss_hf = ETH_RSS_TCP;
2190         else if (!strcmp(res->value, "sctp"))
2191                 rss_conf.rss_hf = ETH_RSS_SCTP;
2192         else if (!strcmp(res->value, "ether"))
2193                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2194         else if (!strcmp(res->value, "port"))
2195                 rss_conf.rss_hf = ETH_RSS_PORT;
2196         else if (!strcmp(res->value, "vxlan"))
2197                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2198         else if (!strcmp(res->value, "geneve"))
2199                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2200         else if (!strcmp(res->value, "nvgre"))
2201                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2202         else if (!strcmp(res->value, "l3-pre32"))
2203                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2204         else if (!strcmp(res->value, "l3-pre40"))
2205                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2206         else if (!strcmp(res->value, "l3-pre48"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2208         else if (!strcmp(res->value, "l3-pre56"))
2209                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2210         else if (!strcmp(res->value, "l3-pre64"))
2211                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2212         else if (!strcmp(res->value, "l3-pre96"))
2213                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2214         else if (!strcmp(res->value, "l3-src-only"))
2215                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2216         else if (!strcmp(res->value, "l3-dst-only"))
2217                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2218         else if (!strcmp(res->value, "l4-src-only"))
2219                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2220         else if (!strcmp(res->value, "l4-dst-only"))
2221                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2222         else if (!strcmp(res->value, "l2-src-only"))
2223                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2224         else if (!strcmp(res->value, "l2-dst-only"))
2225                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2226         else if (!strcmp(res->value, "l2tpv3"))
2227                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2228         else if (!strcmp(res->value, "esp"))
2229                 rss_conf.rss_hf = ETH_RSS_ESP;
2230         else if (!strcmp(res->value, "ah"))
2231                 rss_conf.rss_hf = ETH_RSS_AH;
2232         else if (!strcmp(res->value, "pfcp"))
2233                 rss_conf.rss_hf = ETH_RSS_PFCP;
2234         else if (!strcmp(res->value, "pppoe"))
2235                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2236         else if (!strcmp(res->value, "gtpu"))
2237                 rss_conf.rss_hf = ETH_RSS_GTPU;
2238         else if (!strcmp(res->value, "ecpri"))
2239                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2240         else if (!strcmp(res->value, "mpls"))
2241                 rss_conf.rss_hf = ETH_RSS_MPLS;
2242         else if (!strcmp(res->value, "none"))
2243                 rss_conf.rss_hf = 0;
2244         else if (!strcmp(res->value, "level-default")) {
2245                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2246                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2247         } else if (!strcmp(res->value, "level-outer")) {
2248                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2249                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2250         } else if (!strcmp(res->value, "level-inner")) {
2251                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2252                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2253         } else if (!strcmp(res->value, "default"))
2254                 use_default = 1;
2255         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2256                                                 atoi(res->value) < 64)
2257                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2258         else {
2259                 printf("Unknown parameter\n");
2260                 return;
2261         }
2262         rss_conf.rss_key = NULL;
2263         /* Update global configuration for RSS types. */
2264         RTE_ETH_FOREACH_DEV(i) {
2265                 struct rte_eth_rss_conf local_rss_conf;
2266
2267                 ret = eth_dev_info_get_print_err(i, &dev_info);
2268                 if (ret != 0)
2269                         return;
2270
2271                 if (use_default)
2272                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2273
2274                 local_rss_conf = rss_conf;
2275                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2276                         dev_info.flow_type_rss_offloads;
2277                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2278                         printf("Port %u modified RSS hash function based on hardware support,"
2279                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2280                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2281                 }
2282                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2283                 if (diag < 0) {
2284                         all_updated = 0;
2285                         printf("Configuration of RSS hash at ethernet port %d "
2286                                 "failed with error (%d): %s.\n",
2287                                 i, -diag, strerror(-diag));
2288                 }
2289         }
2290         if (all_updated && !use_default) {
2291                 rss_hf = rss_conf.rss_hf;
2292                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2293         }
2294 }
2295
2296 cmdline_parse_token_string_t cmd_config_rss_port =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2298 cmdline_parse_token_string_t cmd_config_rss_keyword =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2300 cmdline_parse_token_string_t cmd_config_rss_all =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2302 cmdline_parse_token_string_t cmd_config_rss_name =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2304 cmdline_parse_token_string_t cmd_config_rss_value =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2306
2307 cmdline_parse_inst_t cmd_config_rss = {
2308         .f = cmd_config_rss_parsed,
2309         .data = NULL,
2310         .help_str = "port config all rss "
2311                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2312                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2313                 "level-outer|level-inner|<flowtype_id>",
2314         .tokens = {
2315                 (void *)&cmd_config_rss_port,
2316                 (void *)&cmd_config_rss_keyword,
2317                 (void *)&cmd_config_rss_all,
2318                 (void *)&cmd_config_rss_name,
2319                 (void *)&cmd_config_rss_value,
2320                 NULL,
2321         },
2322 };
2323
2324 /* *** configure rss hash key *** */
2325 struct cmd_config_rss_hash_key {
2326         cmdline_fixed_string_t port;
2327         cmdline_fixed_string_t config;
2328         portid_t port_id;
2329         cmdline_fixed_string_t rss_hash_key;
2330         cmdline_fixed_string_t rss_type;
2331         cmdline_fixed_string_t key;
2332 };
2333
2334 static uint8_t
2335 hexa_digit_to_value(char hexa_digit)
2336 {
2337         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2338                 return (uint8_t) (hexa_digit - '0');
2339         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2340                 return (uint8_t) ((hexa_digit - 'a') + 10);
2341         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2342                 return (uint8_t) ((hexa_digit - 'A') + 10);
2343         /* Invalid hexa digit */
2344         return 0xFF;
2345 }
2346
2347 static uint8_t
2348 parse_and_check_key_hexa_digit(char *key, int idx)
2349 {
2350         uint8_t hexa_v;
2351
2352         hexa_v = hexa_digit_to_value(key[idx]);
2353         if (hexa_v == 0xFF)
2354                 printf("invalid key: character %c at position %d is not a "
2355                        "valid hexa digit\n", key[idx], idx);
2356         return hexa_v;
2357 }
2358
2359 static void
2360 cmd_config_rss_hash_key_parsed(void *parsed_result,
2361                                __rte_unused struct cmdline *cl,
2362                                __rte_unused void *data)
2363 {
2364         struct cmd_config_rss_hash_key *res = parsed_result;
2365         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2366         uint8_t xdgt0;
2367         uint8_t xdgt1;
2368         int i;
2369         struct rte_eth_dev_info dev_info;
2370         uint8_t hash_key_size;
2371         uint32_t key_len;
2372         int ret;
2373
2374         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2375         if (ret != 0)
2376                 return;
2377
2378         if (dev_info.hash_key_size > 0 &&
2379                         dev_info.hash_key_size <= sizeof(hash_key))
2380                 hash_key_size = dev_info.hash_key_size;
2381         else {
2382                 printf("dev_info did not provide a valid hash key size\n");
2383                 return;
2384         }
2385         /* Check the length of the RSS hash key */
2386         key_len = strlen(res->key);
2387         if (key_len != (hash_key_size * 2)) {
2388                 printf("key length: %d invalid - key must be a string of %d"
2389                            " hexa-decimal numbers\n",
2390                            (int) key_len, hash_key_size * 2);
2391                 return;
2392         }
2393         /* Translate RSS hash key into binary representation */
2394         for (i = 0; i < hash_key_size; i++) {
2395                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2396                 if (xdgt0 == 0xFF)
2397                         return;
2398                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2399                 if (xdgt1 == 0xFF)
2400                         return;
2401                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2402         }
2403         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2404                         hash_key_size);
2405 }
2406
2407 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2408         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2409 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2411                                  "config");
2412 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2413         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2414                                  RTE_UINT16);
2415 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2416         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2417                                  rss_hash_key, "rss-hash-key");
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2420                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2421                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2422                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2423                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2424                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2425                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2426                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri");
2427 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2428         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2429
2430 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2431         .f = cmd_config_rss_hash_key_parsed,
2432         .data = NULL,
2433         .help_str = "port config <port_id> rss-hash-key "
2434                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2435                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2436                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2437                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2438                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2439                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri "
2440                 "<string of hex digits (variable length, NIC dependent)>",
2441         .tokens = {
2442                 (void *)&cmd_config_rss_hash_key_port,
2443                 (void *)&cmd_config_rss_hash_key_config,
2444                 (void *)&cmd_config_rss_hash_key_port_id,
2445                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2446                 (void *)&cmd_config_rss_hash_key_rss_type,
2447                 (void *)&cmd_config_rss_hash_key_value,
2448                 NULL,
2449         },
2450 };
2451
2452 /* *** configure port rxq/txq ring size *** */
2453 struct cmd_config_rxtx_ring_size {
2454         cmdline_fixed_string_t port;
2455         cmdline_fixed_string_t config;
2456         portid_t portid;
2457         cmdline_fixed_string_t rxtxq;
2458         uint16_t qid;
2459         cmdline_fixed_string_t rsize;
2460         uint16_t size;
2461 };
2462
2463 static void
2464 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2465                                  __rte_unused struct cmdline *cl,
2466                                  __rte_unused void *data)
2467 {
2468         struct cmd_config_rxtx_ring_size *res = parsed_result;
2469         struct rte_port *port;
2470         uint8_t isrx;
2471
2472         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2473                 return;
2474
2475         if (res->portid == (portid_t)RTE_PORT_ALL) {
2476                 printf("Invalid port id\n");
2477                 return;
2478         }
2479
2480         port = &ports[res->portid];
2481
2482         if (!strcmp(res->rxtxq, "rxq"))
2483                 isrx = 1;
2484         else if (!strcmp(res->rxtxq, "txq"))
2485                 isrx = 0;
2486         else {
2487                 printf("Unknown parameter\n");
2488                 return;
2489         }
2490
2491         if (isrx && rx_queue_id_is_invalid(res->qid))
2492                 return;
2493         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2494                 return;
2495
2496         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2497                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2498                        rx_free_thresh);
2499                 return;
2500         }
2501
2502         if (isrx)
2503                 port->nb_rx_desc[res->qid] = res->size;
2504         else
2505                 port->nb_tx_desc[res->qid] = res->size;
2506
2507         cmd_reconfig_device_queue(res->portid, 0, 1);
2508 }
2509
2510 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2511         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2512                                  port, "port");
2513 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2514         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2515                                  config, "config");
2516 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2517         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2518                                  portid, RTE_UINT16);
2519 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2520         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2521                                  rxtxq, "rxq#txq");
2522 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2523         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2524                               qid, RTE_UINT16);
2525 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2526         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2527                                  rsize, "ring_size");
2528 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2529         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2530                               size, RTE_UINT16);
2531
2532 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2533         .f = cmd_config_rxtx_ring_size_parsed,
2534         .data = NULL,
2535         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2536         .tokens = {
2537                 (void *)&cmd_config_rxtx_ring_size_port,
2538                 (void *)&cmd_config_rxtx_ring_size_config,
2539                 (void *)&cmd_config_rxtx_ring_size_portid,
2540                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2541                 (void *)&cmd_config_rxtx_ring_size_qid,
2542                 (void *)&cmd_config_rxtx_ring_size_rsize,
2543                 (void *)&cmd_config_rxtx_ring_size_size,
2544                 NULL,
2545         },
2546 };
2547
2548 /* *** configure port rxq/txq start/stop *** */
2549 struct cmd_config_rxtx_queue {
2550         cmdline_fixed_string_t port;
2551         portid_t portid;
2552         cmdline_fixed_string_t rxtxq;
2553         uint16_t qid;
2554         cmdline_fixed_string_t opname;
2555 };
2556
2557 static void
2558 cmd_config_rxtx_queue_parsed(void *parsed_result,
2559                         __rte_unused struct cmdline *cl,
2560                         __rte_unused void *data)
2561 {
2562         struct cmd_config_rxtx_queue *res = parsed_result;
2563         uint8_t isrx;
2564         uint8_t isstart;
2565         int ret = 0;
2566
2567         if (test_done == 0) {
2568                 printf("Please stop forwarding first\n");
2569                 return;
2570         }
2571
2572         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2573                 return;
2574
2575         if (port_is_started(res->portid) != 1) {
2576                 printf("Please start port %u first\n", res->portid);
2577                 return;
2578         }
2579
2580         if (!strcmp(res->rxtxq, "rxq"))
2581                 isrx = 1;
2582         else if (!strcmp(res->rxtxq, "txq"))
2583                 isrx = 0;
2584         else {
2585                 printf("Unknown parameter\n");
2586                 return;
2587         }
2588
2589         if (isrx && rx_queue_id_is_invalid(res->qid))
2590                 return;
2591         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2592                 return;
2593
2594         if (!strcmp(res->opname, "start"))
2595                 isstart = 1;
2596         else if (!strcmp(res->opname, "stop"))
2597                 isstart = 0;
2598         else {
2599                 printf("Unknown parameter\n");
2600                 return;
2601         }
2602
2603         if (isstart && isrx)
2604                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2605         else if (!isstart && isrx)
2606                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2607         else if (isstart && !isrx)
2608                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2609         else
2610                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2611
2612         if (ret == -ENOTSUP)
2613                 printf("Function not supported in PMD driver\n");
2614 }
2615
2616 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2617         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2618 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2619         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2620 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2621         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2622 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2623         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2624 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2625         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2626                                                 "start#stop");
2627
2628 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2629         .f = cmd_config_rxtx_queue_parsed,
2630         .data = NULL,
2631         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2632         .tokens = {
2633                 (void *)&cmd_config_rxtx_queue_port,
2634                 (void *)&cmd_config_rxtx_queue_portid,
2635                 (void *)&cmd_config_rxtx_queue_rxtxq,
2636                 (void *)&cmd_config_rxtx_queue_qid,
2637                 (void *)&cmd_config_rxtx_queue_opname,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure port rxq/txq deferred start on/off *** */
2643 struct cmd_config_deferred_start_rxtx_queue {
2644         cmdline_fixed_string_t port;
2645         portid_t port_id;
2646         cmdline_fixed_string_t rxtxq;
2647         uint16_t qid;
2648         cmdline_fixed_string_t opname;
2649         cmdline_fixed_string_t state;
2650 };
2651
2652 static void
2653 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2654                         __rte_unused struct cmdline *cl,
2655                         __rte_unused void *data)
2656 {
2657         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2658         struct rte_port *port;
2659         uint8_t isrx;
2660         uint8_t ison;
2661         uint8_t needreconfig = 0;
2662
2663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2664                 return;
2665
2666         if (port_is_started(res->port_id) != 0) {
2667                 printf("Please stop port %u first\n", res->port_id);
2668                 return;
2669         }
2670
2671         port = &ports[res->port_id];
2672
2673         isrx = !strcmp(res->rxtxq, "rxq");
2674
2675         if (isrx && rx_queue_id_is_invalid(res->qid))
2676                 return;
2677         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2678                 return;
2679
2680         ison = !strcmp(res->state, "on");
2681
2682         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2683                 port->rx_conf[res->qid].rx_deferred_start = ison;
2684                 needreconfig = 1;
2685         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2686                 port->tx_conf[res->qid].tx_deferred_start = ison;
2687                 needreconfig = 1;
2688         }
2689
2690         if (needreconfig)
2691                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2692 }
2693
2694 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2695         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2696                                                 port, "port");
2697 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2698         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2699                                                 port_id, RTE_UINT16);
2700 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2701         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2702                                                 rxtxq, "rxq#txq");
2703 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2704         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2705                                                 qid, RTE_UINT16);
2706 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2707         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2708                                                 opname, "deferred_start");
2709 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2710         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2711                                                 state, "on#off");
2712
2713 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2714         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2715         .data = NULL,
2716         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2717         .tokens = {
2718                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2719                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2720                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2721                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2722                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2723                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2724                 NULL,
2725         },
2726 };
2727
2728 /* *** configure port rxq/txq setup *** */
2729 struct cmd_setup_rxtx_queue {
2730         cmdline_fixed_string_t port;
2731         portid_t portid;
2732         cmdline_fixed_string_t rxtxq;
2733         uint16_t qid;
2734         cmdline_fixed_string_t setup;
2735 };
2736
2737 /* Common CLI fields for queue setup */
2738 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2739         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2740 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2741         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2742 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2743         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2744 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2745         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2746 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2747         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2748
2749 static void
2750 cmd_setup_rxtx_queue_parsed(
2751         void *parsed_result,
2752         __rte_unused struct cmdline *cl,
2753         __rte_unused void *data)
2754 {
2755         struct cmd_setup_rxtx_queue *res = parsed_result;
2756         struct rte_port *port;
2757         struct rte_mempool *mp;
2758         unsigned int socket_id;
2759         uint8_t isrx = 0;
2760         int ret;
2761
2762         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2763                 return;
2764
2765         if (res->portid == (portid_t)RTE_PORT_ALL) {
2766                 printf("Invalid port id\n");
2767                 return;
2768         }
2769
2770         if (!strcmp(res->rxtxq, "rxq"))
2771                 isrx = 1;
2772         else if (!strcmp(res->rxtxq, "txq"))
2773                 isrx = 0;
2774         else {
2775                 printf("Unknown parameter\n");
2776                 return;
2777         }
2778
2779         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2780                 printf("Invalid rx queue\n");
2781                 return;
2782         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2783                 printf("Invalid tx queue\n");
2784                 return;
2785         }
2786
2787         port = &ports[res->portid];
2788         if (isrx) {
2789                 socket_id = rxring_numa[res->portid];
2790                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2791                         socket_id = port->socket_id;
2792
2793                 mp = mbuf_pool_find(socket_id, 0);
2794                 if (mp == NULL) {
2795                         printf("Failed to setup RX queue: "
2796                                 "No mempool allocation"
2797                                 " on the socket %d\n",
2798                                 rxring_numa[res->portid]);
2799                         return;
2800                 }
2801                 ret = rx_queue_setup(res->portid,
2802                                      res->qid,
2803                                      port->nb_rx_desc[res->qid],
2804                                      socket_id,
2805                                      &port->rx_conf[res->qid],
2806                                      mp);
2807                 if (ret)
2808                         printf("Failed to setup RX queue\n");
2809         } else {
2810                 socket_id = txring_numa[res->portid];
2811                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2812                         socket_id = port->socket_id;
2813
2814                 ret = rte_eth_tx_queue_setup(res->portid,
2815                                              res->qid,
2816                                              port->nb_tx_desc[res->qid],
2817                                              socket_id,
2818                                              &port->tx_conf[res->qid]);
2819                 if (ret)
2820                         printf("Failed to setup TX queue\n");
2821         }
2822 }
2823
2824 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2825         .f = cmd_setup_rxtx_queue_parsed,
2826         .data = NULL,
2827         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2828         .tokens = {
2829                 (void *)&cmd_setup_rxtx_queue_port,
2830                 (void *)&cmd_setup_rxtx_queue_portid,
2831                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2832                 (void *)&cmd_setup_rxtx_queue_qid,
2833                 (void *)&cmd_setup_rxtx_queue_setup,
2834                 NULL,
2835         },
2836 };
2837
2838
2839 /* *** Configure RSS RETA *** */
2840 struct cmd_config_rss_reta {
2841         cmdline_fixed_string_t port;
2842         cmdline_fixed_string_t keyword;
2843         portid_t port_id;
2844         cmdline_fixed_string_t name;
2845         cmdline_fixed_string_t list_name;
2846         cmdline_fixed_string_t list_of_items;
2847 };
2848
2849 static int
2850 parse_reta_config(const char *str,
2851                   struct rte_eth_rss_reta_entry64 *reta_conf,
2852                   uint16_t nb_entries)
2853 {
2854         int i;
2855         unsigned size;
2856         uint16_t hash_index, idx, shift;
2857         uint16_t nb_queue;
2858         char s[256];
2859         const char *p, *p0 = str;
2860         char *end;
2861         enum fieldnames {
2862                 FLD_HASH_INDEX = 0,
2863                 FLD_QUEUE,
2864                 _NUM_FLD
2865         };
2866         unsigned long int_fld[_NUM_FLD];
2867         char *str_fld[_NUM_FLD];
2868
2869         while ((p = strchr(p0,'(')) != NULL) {
2870                 ++p;
2871                 if((p0 = strchr(p,')')) == NULL)
2872                         return -1;
2873
2874                 size = p0 - p;
2875                 if(size >= sizeof(s))
2876                         return -1;
2877
2878                 snprintf(s, sizeof(s), "%.*s", size, p);
2879                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2880                         return -1;
2881                 for (i = 0; i < _NUM_FLD; i++) {
2882                         errno = 0;
2883                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2884                         if (errno != 0 || end == str_fld[i] ||
2885                                         int_fld[i] > 65535)
2886                                 return -1;
2887                 }
2888
2889                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2890                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2891
2892                 if (hash_index >= nb_entries) {
2893                         printf("Invalid RETA hash index=%d\n", hash_index);
2894                         return -1;
2895                 }
2896
2897                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2898                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2899                 reta_conf[idx].mask |= (1ULL << shift);
2900                 reta_conf[idx].reta[shift] = nb_queue;
2901         }
2902
2903         return 0;
2904 }
2905
2906 static void
2907 cmd_set_rss_reta_parsed(void *parsed_result,
2908                         __rte_unused struct cmdline *cl,
2909                         __rte_unused void *data)
2910 {
2911         int ret;
2912         struct rte_eth_dev_info dev_info;
2913         struct rte_eth_rss_reta_entry64 reta_conf[8];
2914         struct cmd_config_rss_reta *res = parsed_result;
2915
2916         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2917         if (ret != 0)
2918                 return;
2919
2920         if (dev_info.reta_size == 0) {
2921                 printf("Redirection table size is 0 which is "
2922                                         "invalid for RSS\n");
2923                 return;
2924         } else
2925                 printf("The reta size of port %d is %u\n",
2926                         res->port_id, dev_info.reta_size);
2927         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2928                 printf("Currently do not support more than %u entries of "
2929                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2930                 return;
2931         }
2932
2933         memset(reta_conf, 0, sizeof(reta_conf));
2934         if (!strcmp(res->list_name, "reta")) {
2935                 if (parse_reta_config(res->list_of_items, reta_conf,
2936                                                 dev_info.reta_size)) {
2937                         printf("Invalid RSS Redirection Table "
2938                                         "config entered\n");
2939                         return;
2940                 }
2941                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2942                                 reta_conf, dev_info.reta_size);
2943                 if (ret != 0)
2944                         printf("Bad redirection table parameter, "
2945                                         "return code = %d \n", ret);
2946         }
2947 }
2948
2949 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2950         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2951 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2952         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2953 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2954         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2955 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2956         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2957 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2958         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2959 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2960         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2961                                  NULL);
2962 cmdline_parse_inst_t cmd_config_rss_reta = {
2963         .f = cmd_set_rss_reta_parsed,
2964         .data = NULL,
2965         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2966         .tokens = {
2967                 (void *)&cmd_config_rss_reta_port,
2968                 (void *)&cmd_config_rss_reta_keyword,
2969                 (void *)&cmd_config_rss_reta_port_id,
2970                 (void *)&cmd_config_rss_reta_name,
2971                 (void *)&cmd_config_rss_reta_list_name,
2972                 (void *)&cmd_config_rss_reta_list_of_items,
2973                 NULL,
2974         },
2975 };
2976
2977 /* *** SHOW PORT RETA INFO *** */
2978 struct cmd_showport_reta {
2979         cmdline_fixed_string_t show;
2980         cmdline_fixed_string_t port;
2981         portid_t port_id;
2982         cmdline_fixed_string_t rss;
2983         cmdline_fixed_string_t reta;
2984         uint16_t size;
2985         cmdline_fixed_string_t list_of_items;
2986 };
2987
2988 static int
2989 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2990                            uint16_t nb_entries,
2991                            char *str)
2992 {
2993         uint32_t size;
2994         const char *p, *p0 = str;
2995         char s[256];
2996         char *end;
2997         char *str_fld[8];
2998         uint16_t i;
2999         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3000                         RTE_RETA_GROUP_SIZE;
3001         int ret;
3002
3003         p = strchr(p0, '(');
3004         if (p == NULL)
3005                 return -1;
3006         p++;
3007         p0 = strchr(p, ')');
3008         if (p0 == NULL)
3009                 return -1;
3010         size = p0 - p;
3011         if (size >= sizeof(s)) {
3012                 printf("The string size exceeds the internal buffer size\n");
3013                 return -1;
3014         }
3015         snprintf(s, sizeof(s), "%.*s", size, p);
3016         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3017         if (ret <= 0 || ret != num) {
3018                 printf("The bits of masks do not match the number of "
3019                                         "reta entries: %u\n", num);
3020                 return -1;
3021         }
3022         for (i = 0; i < ret; i++)
3023                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3024
3025         return 0;
3026 }
3027
3028 static void
3029 cmd_showport_reta_parsed(void *parsed_result,
3030                          __rte_unused struct cmdline *cl,
3031                          __rte_unused void *data)
3032 {
3033         struct cmd_showport_reta *res = parsed_result;
3034         struct rte_eth_rss_reta_entry64 reta_conf[8];
3035         struct rte_eth_dev_info dev_info;
3036         uint16_t max_reta_size;
3037         int ret;
3038
3039         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3040         if (ret != 0)
3041                 return;
3042
3043         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3044         if (res->size == 0 || res->size > max_reta_size) {
3045                 printf("Invalid redirection table size: %u (1-%u)\n",
3046                         res->size, max_reta_size);
3047                 return;
3048         }
3049
3050         memset(reta_conf, 0, sizeof(reta_conf));
3051         if (showport_parse_reta_config(reta_conf, res->size,
3052                                 res->list_of_items) < 0) {
3053                 printf("Invalid string: %s for reta masks\n",
3054                                         res->list_of_items);
3055                 return;
3056         }
3057         port_rss_reta_info(res->port_id, reta_conf, res->size);
3058 }
3059
3060 cmdline_parse_token_string_t cmd_showport_reta_show =
3061         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3062 cmdline_parse_token_string_t cmd_showport_reta_port =
3063         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3064 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3065         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3066 cmdline_parse_token_string_t cmd_showport_reta_rss =
3067         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3068 cmdline_parse_token_string_t cmd_showport_reta_reta =
3069         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3070 cmdline_parse_token_num_t cmd_showport_reta_size =
3071         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3072 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3073         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3074                                         list_of_items, NULL);
3075
3076 cmdline_parse_inst_t cmd_showport_reta = {
3077         .f = cmd_showport_reta_parsed,
3078         .data = NULL,
3079         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3080         .tokens = {
3081                 (void *)&cmd_showport_reta_show,
3082                 (void *)&cmd_showport_reta_port,
3083                 (void *)&cmd_showport_reta_port_id,
3084                 (void *)&cmd_showport_reta_rss,
3085                 (void *)&cmd_showport_reta_reta,
3086                 (void *)&cmd_showport_reta_size,
3087                 (void *)&cmd_showport_reta_list_of_items,
3088                 NULL,
3089         },
3090 };
3091
3092 /* *** Show RSS hash configuration *** */
3093 struct cmd_showport_rss_hash {
3094         cmdline_fixed_string_t show;
3095         cmdline_fixed_string_t port;
3096         portid_t port_id;
3097         cmdline_fixed_string_t rss_hash;
3098         cmdline_fixed_string_t rss_type;
3099         cmdline_fixed_string_t key; /* optional argument */
3100 };
3101
3102 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3103                                 __rte_unused struct cmdline *cl,
3104                                 void *show_rss_key)
3105 {
3106         struct cmd_showport_rss_hash *res = parsed_result;
3107
3108         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3109 }
3110
3111 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3112         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3113 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3114         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3115 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3116         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3117                                  RTE_UINT16);
3118 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3119         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3120                                  "rss-hash");
3121 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3122         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3123
3124 cmdline_parse_inst_t cmd_showport_rss_hash = {
3125         .f = cmd_showport_rss_hash_parsed,
3126         .data = NULL,
3127         .help_str = "show port <port_id> rss-hash",
3128         .tokens = {
3129                 (void *)&cmd_showport_rss_hash_show,
3130                 (void *)&cmd_showport_rss_hash_port,
3131                 (void *)&cmd_showport_rss_hash_port_id,
3132                 (void *)&cmd_showport_rss_hash_rss_hash,
3133                 NULL,
3134         },
3135 };
3136
3137 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3138         .f = cmd_showport_rss_hash_parsed,
3139         .data = (void *)1,
3140         .help_str = "show port <port_id> rss-hash key",
3141         .tokens = {
3142                 (void *)&cmd_showport_rss_hash_show,
3143                 (void *)&cmd_showport_rss_hash_port,
3144                 (void *)&cmd_showport_rss_hash_port_id,
3145                 (void *)&cmd_showport_rss_hash_rss_hash,
3146                 (void *)&cmd_showport_rss_hash_rss_key,
3147                 NULL,
3148         },
3149 };
3150
3151 /* *** Configure DCB *** */
3152 struct cmd_config_dcb {
3153         cmdline_fixed_string_t port;
3154         cmdline_fixed_string_t config;
3155         portid_t port_id;
3156         cmdline_fixed_string_t dcb;
3157         cmdline_fixed_string_t vt;
3158         cmdline_fixed_string_t vt_en;
3159         uint8_t num_tcs;
3160         cmdline_fixed_string_t pfc;
3161         cmdline_fixed_string_t pfc_en;
3162 };
3163
3164 static void
3165 cmd_config_dcb_parsed(void *parsed_result,
3166                         __rte_unused struct cmdline *cl,
3167                         __rte_unused void *data)
3168 {
3169         struct cmd_config_dcb *res = parsed_result;
3170         portid_t port_id = res->port_id;
3171         struct rte_port *port;
3172         uint8_t pfc_en;
3173         int ret;
3174
3175         port = &ports[port_id];
3176         /** Check if the port is not started **/
3177         if (port->port_status != RTE_PORT_STOPPED) {
3178                 printf("Please stop port %d first\n", port_id);
3179                 return;
3180         }
3181
3182         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3183                 printf("The invalid number of traffic class,"
3184                         " only 4 or 8 allowed.\n");
3185                 return;
3186         }
3187
3188         if (nb_fwd_lcores < res->num_tcs) {
3189                 printf("nb_cores shouldn't be less than number of TCs.\n");
3190                 return;
3191         }
3192         if (!strncmp(res->pfc_en, "on", 2))
3193                 pfc_en = 1;
3194         else
3195                 pfc_en = 0;
3196
3197         /* DCB in VT mode */
3198         if (!strncmp(res->vt_en, "on", 2))
3199                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3200                                 (enum rte_eth_nb_tcs)res->num_tcs,
3201                                 pfc_en);
3202         else
3203                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3204                                 (enum rte_eth_nb_tcs)res->num_tcs,
3205                                 pfc_en);
3206
3207
3208         if (ret != 0) {
3209                 printf("Cannot initialize network ports.\n");
3210                 return;
3211         }
3212
3213         cmd_reconfig_device_queue(port_id, 1, 1);
3214 }
3215
3216 cmdline_parse_token_string_t cmd_config_dcb_port =
3217         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3218 cmdline_parse_token_string_t cmd_config_dcb_config =
3219         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3220 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3221         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3222 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3223         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3224 cmdline_parse_token_string_t cmd_config_dcb_vt =
3225         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3226 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3227         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3228 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3229         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3230 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3231         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3232 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3233         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3234
3235 cmdline_parse_inst_t cmd_config_dcb = {
3236         .f = cmd_config_dcb_parsed,
3237         .data = NULL,
3238         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3239         .tokens = {
3240                 (void *)&cmd_config_dcb_port,
3241                 (void *)&cmd_config_dcb_config,
3242                 (void *)&cmd_config_dcb_port_id,
3243                 (void *)&cmd_config_dcb_dcb,
3244                 (void *)&cmd_config_dcb_vt,
3245                 (void *)&cmd_config_dcb_vt_en,
3246                 (void *)&cmd_config_dcb_num_tcs,
3247                 (void *)&cmd_config_dcb_pfc,
3248                 (void *)&cmd_config_dcb_pfc_en,
3249                 NULL,
3250         },
3251 };
3252
3253 /* *** configure number of packets per burst *** */
3254 struct cmd_config_burst {
3255         cmdline_fixed_string_t port;
3256         cmdline_fixed_string_t keyword;
3257         cmdline_fixed_string_t all;
3258         cmdline_fixed_string_t name;
3259         uint16_t value;
3260 };
3261
3262 static void
3263 cmd_config_burst_parsed(void *parsed_result,
3264                         __rte_unused struct cmdline *cl,
3265                         __rte_unused void *data)
3266 {
3267         struct cmd_config_burst *res = parsed_result;
3268         struct rte_eth_dev_info dev_info;
3269         uint16_t rec_nb_pkts;
3270         int ret;
3271
3272         if (!all_ports_stopped()) {
3273                 printf("Please stop all ports first\n");
3274                 return;
3275         }
3276
3277         if (!strcmp(res->name, "burst")) {
3278                 if (res->value == 0) {
3279                         /* If user gives a value of zero, query the PMD for
3280                          * its recommended Rx burst size. Testpmd uses a single
3281                          * size for all ports, so assume all ports are the same
3282                          * NIC model and use the values from Port 0.
3283                          */
3284                         ret = eth_dev_info_get_print_err(0, &dev_info);
3285                         if (ret != 0)
3286                                 return;
3287
3288                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3289
3290                         if (rec_nb_pkts == 0) {
3291                                 printf("PMD does not recommend a burst size.\n"
3292                                         "User provided value must be between"
3293                                         " 1 and %d\n", MAX_PKT_BURST);
3294                                 return;
3295                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3296                                 printf("PMD recommended burst size of %d"
3297                                         " exceeds maximum value of %d\n",
3298                                         rec_nb_pkts, MAX_PKT_BURST);
3299                                 return;
3300                         }
3301                         printf("Using PMD-provided burst value of %d\n",
3302                                 rec_nb_pkts);
3303                         nb_pkt_per_burst = rec_nb_pkts;
3304                 } else if (res->value > MAX_PKT_BURST) {
3305                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3306                         return;
3307                 } else
3308                         nb_pkt_per_burst = res->value;
3309         } else {
3310                 printf("Unknown parameter\n");
3311                 return;
3312         }
3313
3314         init_port_config();
3315
3316         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3317 }
3318
3319 cmdline_parse_token_string_t cmd_config_burst_port =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3321 cmdline_parse_token_string_t cmd_config_burst_keyword =
3322         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3323 cmdline_parse_token_string_t cmd_config_burst_all =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3325 cmdline_parse_token_string_t cmd_config_burst_name =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3327 cmdline_parse_token_num_t cmd_config_burst_value =
3328         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3329
3330 cmdline_parse_inst_t cmd_config_burst = {
3331         .f = cmd_config_burst_parsed,
3332         .data = NULL,
3333         .help_str = "port config all burst <value>",
3334         .tokens = {
3335                 (void *)&cmd_config_burst_port,
3336                 (void *)&cmd_config_burst_keyword,
3337                 (void *)&cmd_config_burst_all,
3338                 (void *)&cmd_config_burst_name,
3339                 (void *)&cmd_config_burst_value,
3340                 NULL,
3341         },
3342 };
3343
3344 /* *** configure rx/tx queues *** */
3345 struct cmd_config_thresh {
3346         cmdline_fixed_string_t port;
3347         cmdline_fixed_string_t keyword;
3348         cmdline_fixed_string_t all;
3349         cmdline_fixed_string_t name;
3350         uint8_t value;
3351 };
3352
3353 static void
3354 cmd_config_thresh_parsed(void *parsed_result,
3355                         __rte_unused struct cmdline *cl,
3356                         __rte_unused void *data)
3357 {
3358         struct cmd_config_thresh *res = parsed_result;
3359
3360         if (!all_ports_stopped()) {
3361                 printf("Please stop all ports first\n");
3362                 return;
3363         }
3364
3365         if (!strcmp(res->name, "txpt"))
3366                 tx_pthresh = res->value;
3367         else if(!strcmp(res->name, "txht"))
3368                 tx_hthresh = res->value;
3369         else if(!strcmp(res->name, "txwt"))
3370                 tx_wthresh = res->value;
3371         else if(!strcmp(res->name, "rxpt"))
3372                 rx_pthresh = res->value;
3373         else if(!strcmp(res->name, "rxht"))
3374                 rx_hthresh = res->value;
3375         else if(!strcmp(res->name, "rxwt"))
3376                 rx_wthresh = res->value;
3377         else {
3378                 printf("Unknown parameter\n");
3379                 return;
3380         }
3381
3382         init_port_config();
3383
3384         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3385 }
3386
3387 cmdline_parse_token_string_t cmd_config_thresh_port =
3388         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3389 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3391 cmdline_parse_token_string_t cmd_config_thresh_all =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3393 cmdline_parse_token_string_t cmd_config_thresh_name =
3394         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3395                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3396 cmdline_parse_token_num_t cmd_config_thresh_value =
3397         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3398
3399 cmdline_parse_inst_t cmd_config_thresh = {
3400         .f = cmd_config_thresh_parsed,
3401         .data = NULL,
3402         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3403         .tokens = {
3404                 (void *)&cmd_config_thresh_port,
3405                 (void *)&cmd_config_thresh_keyword,
3406                 (void *)&cmd_config_thresh_all,
3407                 (void *)&cmd_config_thresh_name,
3408                 (void *)&cmd_config_thresh_value,
3409                 NULL,
3410         },
3411 };
3412
3413 /* *** configure free/rs threshold *** */
3414 struct cmd_config_threshold {
3415         cmdline_fixed_string_t port;
3416         cmdline_fixed_string_t keyword;
3417         cmdline_fixed_string_t all;
3418         cmdline_fixed_string_t name;
3419         uint16_t value;
3420 };
3421
3422 static void
3423 cmd_config_threshold_parsed(void *parsed_result,
3424                         __rte_unused struct cmdline *cl,
3425                         __rte_unused void *data)
3426 {
3427         struct cmd_config_threshold *res = parsed_result;
3428
3429         if (!all_ports_stopped()) {
3430                 printf("Please stop all ports first\n");
3431                 return;
3432         }
3433
3434         if (!strcmp(res->name, "txfreet"))
3435                 tx_free_thresh = res->value;
3436         else if (!strcmp(res->name, "txrst"))
3437                 tx_rs_thresh = res->value;
3438         else if (!strcmp(res->name, "rxfreet"))
3439                 rx_free_thresh = res->value;
3440         else {
3441                 printf("Unknown parameter\n");
3442                 return;
3443         }
3444
3445         init_port_config();
3446
3447         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3448 }
3449
3450 cmdline_parse_token_string_t cmd_config_threshold_port =
3451         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3452 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3453         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3454                                                                 "config");
3455 cmdline_parse_token_string_t cmd_config_threshold_all =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3457 cmdline_parse_token_string_t cmd_config_threshold_name =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3459                                                 "txfreet#txrst#rxfreet");
3460 cmdline_parse_token_num_t cmd_config_threshold_value =
3461         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3462
3463 cmdline_parse_inst_t cmd_config_threshold = {
3464         .f = cmd_config_threshold_parsed,
3465         .data = NULL,
3466         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3467         .tokens = {
3468                 (void *)&cmd_config_threshold_port,
3469                 (void *)&cmd_config_threshold_keyword,
3470                 (void *)&cmd_config_threshold_all,
3471                 (void *)&cmd_config_threshold_name,
3472                 (void *)&cmd_config_threshold_value,
3473                 NULL,
3474         },
3475 };
3476
3477 /* *** stop *** */
3478 struct cmd_stop_result {
3479         cmdline_fixed_string_t stop;
3480 };
3481
3482 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3483                             __rte_unused struct cmdline *cl,
3484                             __rte_unused void *data)
3485 {
3486         stop_packet_forwarding();
3487 }
3488
3489 cmdline_parse_token_string_t cmd_stop_stop =
3490         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3491
3492 cmdline_parse_inst_t cmd_stop = {
3493         .f = cmd_stop_parsed,
3494         .data = NULL,
3495         .help_str = "stop: Stop packet forwarding",
3496         .tokens = {
3497                 (void *)&cmd_stop_stop,
3498                 NULL,
3499         },
3500 };
3501
3502 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3503
3504 unsigned int
3505 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3506                 unsigned int *parsed_items, int check_unique_values)
3507 {
3508         unsigned int nb_item;
3509         unsigned int value;
3510         unsigned int i;
3511         unsigned int j;
3512         int value_ok;
3513         char c;
3514
3515         /*
3516          * First parse all items in the list and store their value.
3517          */
3518         value = 0;
3519         nb_item = 0;
3520         value_ok = 0;
3521         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3522                 c = str[i];
3523                 if ((c >= '0') && (c <= '9')) {
3524                         value = (unsigned int) (value * 10 + (c - '0'));
3525                         value_ok = 1;
3526                         continue;
3527                 }
3528                 if (c != ',') {
3529                         printf("character %c is not a decimal digit\n", c);
3530                         return 0;
3531                 }
3532                 if (! value_ok) {
3533                         printf("No valid value before comma\n");
3534                         return 0;
3535                 }
3536                 if (nb_item < max_items) {
3537                         parsed_items[nb_item] = value;
3538                         value_ok = 0;
3539                         value = 0;
3540                 }
3541                 nb_item++;
3542         }
3543         if (nb_item >= max_items) {
3544                 printf("Number of %s = %u > %u (maximum items)\n",
3545                        item_name, nb_item + 1, max_items);
3546                 return 0;
3547         }
3548         parsed_items[nb_item++] = value;
3549         if (! check_unique_values)
3550                 return nb_item;
3551
3552         /*
3553          * Then, check that all values in the list are differents.
3554          * No optimization here...
3555          */
3556         for (i = 0; i < nb_item; i++) {
3557                 for (j = i + 1; j < nb_item; j++) {
3558                         if (parsed_items[j] == parsed_items[i]) {
3559                                 printf("duplicated %s %u at index %u and %u\n",
3560                                        item_name, parsed_items[i], i, j);
3561                                 return 0;
3562                         }
3563                 }
3564         }
3565         return nb_item;
3566 }
3567
3568 struct cmd_set_list_result {
3569         cmdline_fixed_string_t cmd_keyword;
3570         cmdline_fixed_string_t list_name;
3571         cmdline_fixed_string_t list_of_items;
3572 };
3573
3574 static void cmd_set_list_parsed(void *parsed_result,
3575                                 __rte_unused struct cmdline *cl,
3576                                 __rte_unused void *data)
3577 {
3578         struct cmd_set_list_result *res;
3579         union {
3580                 unsigned int lcorelist[RTE_MAX_LCORE];
3581                 unsigned int portlist[RTE_MAX_ETHPORTS];
3582         } parsed_items;
3583         unsigned int nb_item;
3584
3585         if (test_done == 0) {
3586                 printf("Please stop forwarding first\n");
3587                 return;
3588         }
3589
3590         res = parsed_result;
3591         if (!strcmp(res->list_name, "corelist")) {
3592                 nb_item = parse_item_list(res->list_of_items, "core",
3593                                           RTE_MAX_LCORE,
3594                                           parsed_items.lcorelist, 1);
3595                 if (nb_item > 0) {
3596                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3597                         fwd_config_setup();
3598                 }
3599                 return;
3600         }
3601         if (!strcmp(res->list_name, "portlist")) {
3602                 nb_item = parse_item_list(res->list_of_items, "port",
3603                                           RTE_MAX_ETHPORTS,
3604                                           parsed_items.portlist, 1);
3605                 if (nb_item > 0) {
3606                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3607                         fwd_config_setup();
3608                 }
3609         }
3610 }
3611
3612 cmdline_parse_token_string_t cmd_set_list_keyword =
3613         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3614                                  "set");
3615 cmdline_parse_token_string_t cmd_set_list_name =
3616         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3617                                  "corelist#portlist");
3618 cmdline_parse_token_string_t cmd_set_list_of_items =
3619         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3620                                  NULL);
3621
3622 cmdline_parse_inst_t cmd_set_fwd_list = {
3623         .f = cmd_set_list_parsed,
3624         .data = NULL,
3625         .help_str = "set corelist|portlist <list0[,list1]*>",
3626         .tokens = {
3627                 (void *)&cmd_set_list_keyword,
3628                 (void *)&cmd_set_list_name,
3629                 (void *)&cmd_set_list_of_items,
3630                 NULL,
3631         },
3632 };
3633
3634 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3635
3636 struct cmd_setmask_result {
3637         cmdline_fixed_string_t set;
3638         cmdline_fixed_string_t mask;
3639         uint64_t hexavalue;
3640 };
3641
3642 static void cmd_set_mask_parsed(void *parsed_result,
3643                                 __rte_unused struct cmdline *cl,
3644                                 __rte_unused void *data)
3645 {
3646         struct cmd_setmask_result *res = parsed_result;
3647
3648         if (test_done == 0) {
3649                 printf("Please stop forwarding first\n");
3650                 return;
3651         }
3652         if (!strcmp(res->mask, "coremask")) {
3653                 set_fwd_lcores_mask(res->hexavalue);
3654                 fwd_config_setup();
3655         } else if (!strcmp(res->mask, "portmask")) {
3656                 set_fwd_ports_mask(res->hexavalue);
3657                 fwd_config_setup();
3658         }
3659 }
3660
3661 cmdline_parse_token_string_t cmd_setmask_set =
3662         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3663 cmdline_parse_token_string_t cmd_setmask_mask =
3664         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3665                                  "coremask#portmask");
3666 cmdline_parse_token_num_t cmd_setmask_value =
3667         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3668
3669 cmdline_parse_inst_t cmd_set_fwd_mask = {
3670         .f = cmd_set_mask_parsed,
3671         .data = NULL,
3672         .help_str = "set coremask|portmask <hexadecimal value>",
3673         .tokens = {
3674                 (void *)&cmd_setmask_set,
3675                 (void *)&cmd_setmask_mask,
3676                 (void *)&cmd_setmask_value,
3677                 NULL,
3678         },
3679 };
3680
3681 /*
3682  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3683  */
3684 struct cmd_set_result {
3685         cmdline_fixed_string_t set;
3686         cmdline_fixed_string_t what;
3687         uint16_t value;
3688 };
3689
3690 static void cmd_set_parsed(void *parsed_result,
3691                            __rte_unused struct cmdline *cl,
3692                            __rte_unused void *data)
3693 {
3694         struct cmd_set_result *res = parsed_result;
3695         if (!strcmp(res->what, "nbport")) {
3696                 set_fwd_ports_number(res->value);
3697                 fwd_config_setup();
3698         } else if (!strcmp(res->what, "nbcore")) {
3699                 set_fwd_lcores_number(res->value);
3700                 fwd_config_setup();
3701         } else if (!strcmp(res->what, "burst"))
3702                 set_nb_pkt_per_burst(res->value);
3703         else if (!strcmp(res->what, "verbose"))
3704                 set_verbose_level(res->value);
3705 }
3706
3707 cmdline_parse_token_string_t cmd_set_set =
3708         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3709 cmdline_parse_token_string_t cmd_set_what =
3710         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3711                                  "nbport#nbcore#burst#verbose");
3712 cmdline_parse_token_num_t cmd_set_value =
3713         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3714
3715 cmdline_parse_inst_t cmd_set_numbers = {
3716         .f = cmd_set_parsed,
3717         .data = NULL,
3718         .help_str = "set nbport|nbcore|burst|verbose <value>",
3719         .tokens = {
3720                 (void *)&cmd_set_set,
3721                 (void *)&cmd_set_what,
3722                 (void *)&cmd_set_value,
3723                 NULL,
3724         },
3725 };
3726
3727 /* *** SET LOG LEVEL CONFIGURATION *** */
3728
3729 struct cmd_set_log_result {
3730         cmdline_fixed_string_t set;
3731         cmdline_fixed_string_t log;
3732         cmdline_fixed_string_t type;
3733         uint32_t level;
3734 };
3735
3736 static void
3737 cmd_set_log_parsed(void *parsed_result,
3738                    __rte_unused struct cmdline *cl,
3739                    __rte_unused void *data)
3740 {
3741         struct cmd_set_log_result *res;
3742         int ret;
3743
3744         res = parsed_result;
3745         if (!strcmp(res->type, "global"))
3746                 rte_log_set_global_level(res->level);
3747         else {
3748                 ret = rte_log_set_level_regexp(res->type, res->level);
3749                 if (ret < 0)
3750                         printf("Unable to set log level\n");
3751         }
3752 }
3753
3754 cmdline_parse_token_string_t cmd_set_log_set =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3756 cmdline_parse_token_string_t cmd_set_log_log =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3758 cmdline_parse_token_string_t cmd_set_log_type =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3760 cmdline_parse_token_num_t cmd_set_log_level =
3761         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3762
3763 cmdline_parse_inst_t cmd_set_log = {
3764         .f = cmd_set_log_parsed,
3765         .data = NULL,
3766         .help_str = "set log global|<type> <level>",
3767         .tokens = {
3768                 (void *)&cmd_set_log_set,
3769                 (void *)&cmd_set_log_log,
3770                 (void *)&cmd_set_log_type,
3771                 (void *)&cmd_set_log_level,
3772                 NULL,
3773         },
3774 };
3775
3776 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3777
3778 struct cmd_set_rxoffs_result {
3779         cmdline_fixed_string_t cmd_keyword;
3780         cmdline_fixed_string_t rxoffs;
3781         cmdline_fixed_string_t seg_offsets;
3782 };
3783
3784 static void
3785 cmd_set_rxoffs_parsed(void *parsed_result,
3786                       __rte_unused struct cmdline *cl,
3787                       __rte_unused void *data)
3788 {
3789         struct cmd_set_rxoffs_result *res;
3790         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3791         unsigned int nb_segs;
3792
3793         res = parsed_result;
3794         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3795                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3796         if (nb_segs > 0)
3797                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3798         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3799 }
3800
3801 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3802         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3803                                  cmd_keyword, "set");
3804 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3805         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3806                                  rxoffs, "rxoffs");
3807 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3808         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3809                                  seg_offsets, NULL);
3810
3811 cmdline_parse_inst_t cmd_set_rxoffs = {
3812         .f = cmd_set_rxoffs_parsed,
3813         .data = NULL,
3814         .help_str = "set rxoffs <len0[,len1]*>",
3815         .tokens = {
3816                 (void *)&cmd_set_rxoffs_keyword,
3817                 (void *)&cmd_set_rxoffs_name,
3818                 (void *)&cmd_set_rxoffs_offsets,
3819                 NULL,
3820         },
3821 };
3822
3823 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3824
3825 struct cmd_set_rxpkts_result {
3826         cmdline_fixed_string_t cmd_keyword;
3827         cmdline_fixed_string_t rxpkts;
3828         cmdline_fixed_string_t seg_lengths;
3829 };
3830
3831 static void
3832 cmd_set_rxpkts_parsed(void *parsed_result,
3833                       __rte_unused struct cmdline *cl,
3834                       __rte_unused void *data)
3835 {
3836         struct cmd_set_rxpkts_result *res;
3837         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3838         unsigned int nb_segs;
3839
3840         res = parsed_result;
3841         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3842                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3843         if (nb_segs > 0)
3844                 set_rx_pkt_segments(seg_lengths, nb_segs);
3845         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3846 }
3847
3848 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3849         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3850                                  cmd_keyword, "set");
3851 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3853                                  rxpkts, "rxpkts");
3854 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3855         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3856                                  seg_lengths, NULL);
3857
3858 cmdline_parse_inst_t cmd_set_rxpkts = {
3859         .f = cmd_set_rxpkts_parsed,
3860         .data = NULL,
3861         .help_str = "set rxpkts <len0[,len1]*>",
3862         .tokens = {
3863                 (void *)&cmd_set_rxpkts_keyword,
3864                 (void *)&cmd_set_rxpkts_name,
3865                 (void *)&cmd_set_rxpkts_lengths,
3866                 NULL,
3867         },
3868 };
3869
3870 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3871
3872 struct cmd_set_txpkts_result {
3873         cmdline_fixed_string_t cmd_keyword;
3874         cmdline_fixed_string_t txpkts;
3875         cmdline_fixed_string_t seg_lengths;
3876 };
3877
3878 static void
3879 cmd_set_txpkts_parsed(void *parsed_result,
3880                       __rte_unused struct cmdline *cl,
3881                       __rte_unused void *data)
3882 {
3883         struct cmd_set_txpkts_result *res;
3884         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3885         unsigned int nb_segs;
3886
3887         res = parsed_result;
3888         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3889                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3890         if (nb_segs > 0)
3891                 set_tx_pkt_segments(seg_lengths, nb_segs);
3892 }
3893
3894 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3895         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3896                                  cmd_keyword, "set");
3897 cmdline_parse_token_string_t cmd_set_txpkts_name =
3898         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3899                                  txpkts, "txpkts");
3900 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3902                                  seg_lengths, NULL);
3903
3904 cmdline_parse_inst_t cmd_set_txpkts = {
3905         .f = cmd_set_txpkts_parsed,
3906         .data = NULL,
3907         .help_str = "set txpkts <len0[,len1]*>",
3908         .tokens = {
3909                 (void *)&cmd_set_txpkts_keyword,
3910                 (void *)&cmd_set_txpkts_name,
3911                 (void *)&cmd_set_txpkts_lengths,
3912                 NULL,
3913         },
3914 };
3915
3916 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3917
3918 struct cmd_set_txsplit_result {
3919         cmdline_fixed_string_t cmd_keyword;
3920         cmdline_fixed_string_t txsplit;
3921         cmdline_fixed_string_t mode;
3922 };
3923
3924 static void
3925 cmd_set_txsplit_parsed(void *parsed_result,
3926                       __rte_unused struct cmdline *cl,
3927                       __rte_unused void *data)
3928 {
3929         struct cmd_set_txsplit_result *res;
3930
3931         res = parsed_result;
3932         set_tx_pkt_split(res->mode);
3933 }
3934
3935 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3936         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3937                                  cmd_keyword, "set");
3938 cmdline_parse_token_string_t cmd_set_txsplit_name =
3939         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3940                                  txsplit, "txsplit");
3941 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3942         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3943                                  mode, NULL);
3944
3945 cmdline_parse_inst_t cmd_set_txsplit = {
3946         .f = cmd_set_txsplit_parsed,
3947         .data = NULL,
3948         .help_str = "set txsplit on|off|rand",
3949         .tokens = {
3950                 (void *)&cmd_set_txsplit_keyword,
3951                 (void *)&cmd_set_txsplit_name,
3952                 (void *)&cmd_set_txsplit_mode,
3953                 NULL,
3954         },
3955 };
3956
3957 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3958
3959 struct cmd_set_txtimes_result {
3960         cmdline_fixed_string_t cmd_keyword;
3961         cmdline_fixed_string_t txtimes;
3962         cmdline_fixed_string_t tx_times;
3963 };
3964
3965 static void
3966 cmd_set_txtimes_parsed(void *parsed_result,
3967                        __rte_unused struct cmdline *cl,
3968                        __rte_unused void *data)
3969 {
3970         struct cmd_set_txtimes_result *res;
3971         unsigned int tx_times[2] = {0, 0};
3972         unsigned int n_times;
3973
3974         res = parsed_result;
3975         n_times = parse_item_list(res->tx_times, "tx times",
3976                                   2, tx_times, 0);
3977         if (n_times == 2)
3978                 set_tx_pkt_times(tx_times);
3979 }
3980
3981 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3982         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3983                                  cmd_keyword, "set");
3984 cmdline_parse_token_string_t cmd_set_txtimes_name =
3985         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3986                                  txtimes, "txtimes");
3987 cmdline_parse_token_string_t cmd_set_txtimes_value =
3988         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3989                                  tx_times, NULL);
3990
3991 cmdline_parse_inst_t cmd_set_txtimes = {
3992         .f = cmd_set_txtimes_parsed,
3993         .data = NULL,
3994         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3995         .tokens = {
3996                 (void *)&cmd_set_txtimes_keyword,
3997                 (void *)&cmd_set_txtimes_name,
3998                 (void *)&cmd_set_txtimes_value,
3999                 NULL,
4000         },
4001 };
4002
4003 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4004 struct cmd_rx_vlan_filter_all_result {
4005         cmdline_fixed_string_t rx_vlan;
4006         cmdline_fixed_string_t what;
4007         cmdline_fixed_string_t all;
4008         portid_t port_id;
4009 };
4010
4011 static void
4012 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4013                               __rte_unused struct cmdline *cl,
4014                               __rte_unused void *data)
4015 {
4016         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4017
4018         if (!strcmp(res->what, "add"))
4019                 rx_vlan_all_filter_set(res->port_id, 1);
4020         else
4021                 rx_vlan_all_filter_set(res->port_id, 0);
4022 }
4023
4024 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4025         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4026                                  rx_vlan, "rx_vlan");
4027 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4028         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4029                                  what, "add#rm");
4030 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4031         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4032                                  all, "all");
4033 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4034         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4035                               port_id, RTE_UINT16);
4036
4037 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4038         .f = cmd_rx_vlan_filter_all_parsed,
4039         .data = NULL,
4040         .help_str = "rx_vlan add|rm all <port_id>: "
4041                 "Add/Remove all identifiers to/from the set of VLAN "
4042                 "identifiers filtered by a port",
4043         .tokens = {
4044                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4045                 (void *)&cmd_rx_vlan_filter_all_what,
4046                 (void *)&cmd_rx_vlan_filter_all_all,
4047                 (void *)&cmd_rx_vlan_filter_all_portid,
4048                 NULL,
4049         },
4050 };
4051
4052 /* *** VLAN OFFLOAD SET ON A PORT *** */
4053 struct cmd_vlan_offload_result {
4054         cmdline_fixed_string_t vlan;
4055         cmdline_fixed_string_t set;
4056         cmdline_fixed_string_t vlan_type;
4057         cmdline_fixed_string_t what;
4058         cmdline_fixed_string_t on;
4059         cmdline_fixed_string_t port_id;
4060 };
4061
4062 static void
4063 cmd_vlan_offload_parsed(void *parsed_result,
4064                           __rte_unused struct cmdline *cl,
4065                           __rte_unused void *data)
4066 {
4067         int on;
4068         struct cmd_vlan_offload_result *res = parsed_result;
4069         char *str;
4070         int i, len = 0;
4071         portid_t port_id = 0;
4072         unsigned int tmp;
4073
4074         str = res->port_id;
4075         len = strnlen(str, STR_TOKEN_SIZE);
4076         i = 0;
4077         /* Get port_id first */
4078         while(i < len){
4079                 if(str[i] == ',')
4080                         break;
4081
4082                 i++;
4083         }
4084         str[i]='\0';
4085         tmp = strtoul(str, NULL, 0);
4086         /* If port_id greater that what portid_t can represent, return */
4087         if(tmp >= RTE_MAX_ETHPORTS)
4088                 return;
4089         port_id = (portid_t)tmp;
4090
4091         if (!strcmp(res->on, "on"))
4092                 on = 1;
4093         else
4094                 on = 0;
4095
4096         if (!strcmp(res->what, "strip"))
4097                 rx_vlan_strip_set(port_id,  on);
4098         else if(!strcmp(res->what, "stripq")){
4099                 uint16_t queue_id = 0;
4100
4101                 /* No queue_id, return */
4102                 if(i + 1 >= len) {
4103                         printf("must specify (port,queue_id)\n");
4104                         return;
4105                 }
4106                 tmp = strtoul(str + i + 1, NULL, 0);
4107                 /* If queue_id greater that what 16-bits can represent, return */
4108                 if(tmp > 0xffff)
4109                         return;
4110
4111                 queue_id = (uint16_t)tmp;
4112                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4113         }
4114         else if (!strcmp(res->what, "filter"))
4115                 rx_vlan_filter_set(port_id, on);
4116         else if (!strcmp(res->what, "qinq_strip"))
4117                 rx_vlan_qinq_strip_set(port_id, on);
4118         else
4119                 vlan_extend_set(port_id, on);
4120
4121         return;
4122 }
4123
4124 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4125         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4126                                  vlan, "vlan");
4127 cmdline_parse_token_string_t cmd_vlan_offload_set =
4128         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4129                                  set, "set");
4130 cmdline_parse_token_string_t cmd_vlan_offload_what =
4131         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4132                                 what, "strip#filter#qinq_strip#extend#stripq");
4133 cmdline_parse_token_string_t cmd_vlan_offload_on =
4134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4135                               on, "on#off");
4136 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4138                               port_id, NULL);
4139
4140 cmdline_parse_inst_t cmd_vlan_offload = {
4141         .f = cmd_vlan_offload_parsed,
4142         .data = NULL,
4143         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4144                 "<port_id[,queue_id]>: "
4145                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4146         .tokens = {
4147                 (void *)&cmd_vlan_offload_vlan,
4148                 (void *)&cmd_vlan_offload_set,
4149                 (void *)&cmd_vlan_offload_what,
4150                 (void *)&cmd_vlan_offload_on,
4151                 (void *)&cmd_vlan_offload_portid,
4152                 NULL,
4153         },
4154 };
4155
4156 /* *** VLAN TPID SET ON A PORT *** */
4157 struct cmd_vlan_tpid_result {
4158         cmdline_fixed_string_t vlan;
4159         cmdline_fixed_string_t set;
4160         cmdline_fixed_string_t vlan_type;
4161         cmdline_fixed_string_t what;
4162         uint16_t tp_id;
4163         portid_t port_id;
4164 };
4165
4166 static void
4167 cmd_vlan_tpid_parsed(void *parsed_result,
4168                           __rte_unused struct cmdline *cl,
4169                           __rte_unused void *data)
4170 {
4171         struct cmd_vlan_tpid_result *res = parsed_result;
4172         enum rte_vlan_type vlan_type;
4173
4174         if (!strcmp(res->vlan_type, "inner"))
4175                 vlan_type = ETH_VLAN_TYPE_INNER;
4176         else if (!strcmp(res->vlan_type, "outer"))
4177                 vlan_type = ETH_VLAN_TYPE_OUTER;
4178         else {
4179                 printf("Unknown vlan type\n");
4180                 return;
4181         }
4182         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4183 }
4184
4185 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4186         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4187                                  vlan, "vlan");
4188 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4189         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4190                                  set, "set");
4191 cmdline_parse_token_string_t cmd_vlan_type =
4192         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4193                                  vlan_type, "inner#outer");
4194 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4196                                  what, "tpid");
4197 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4198         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4199                               tp_id, RTE_UINT16);
4200 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4201         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4202                               port_id, RTE_UINT16);
4203
4204 cmdline_parse_inst_t cmd_vlan_tpid = {
4205         .f = cmd_vlan_tpid_parsed,
4206         .data = NULL,
4207         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4208                 "Set the VLAN Ether type",
4209         .tokens = {
4210                 (void *)&cmd_vlan_tpid_vlan,
4211                 (void *)&cmd_vlan_tpid_set,
4212                 (void *)&cmd_vlan_type,
4213                 (void *)&cmd_vlan_tpid_what,
4214                 (void *)&cmd_vlan_tpid_tpid,
4215                 (void *)&cmd_vlan_tpid_portid,
4216                 NULL,
4217         },
4218 };
4219
4220 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4221 struct cmd_rx_vlan_filter_result {
4222         cmdline_fixed_string_t rx_vlan;
4223         cmdline_fixed_string_t what;
4224         uint16_t vlan_id;
4225         portid_t port_id;
4226 };
4227
4228 static void
4229 cmd_rx_vlan_filter_parsed(void *parsed_result,
4230                           __rte_unused struct cmdline *cl,
4231                           __rte_unused void *data)
4232 {
4233         struct cmd_rx_vlan_filter_result *res = parsed_result;
4234
4235         if (!strcmp(res->what, "add"))
4236                 rx_vft_set(res->port_id, res->vlan_id, 1);
4237         else
4238                 rx_vft_set(res->port_id, res->vlan_id, 0);
4239 }
4240
4241 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4242         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4243                                  rx_vlan, "rx_vlan");
4244 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4245         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4246                                  what, "add#rm");
4247 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4248         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4249                               vlan_id, RTE_UINT16);
4250 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4251         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4252                               port_id, RTE_UINT16);
4253
4254 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4255         .f = cmd_rx_vlan_filter_parsed,
4256         .data = NULL,
4257         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4258                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4259                 "identifiers filtered by a port",
4260         .tokens = {
4261                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4262                 (void *)&cmd_rx_vlan_filter_what,
4263                 (void *)&cmd_rx_vlan_filter_vlanid,
4264                 (void *)&cmd_rx_vlan_filter_portid,
4265                 NULL,
4266         },
4267 };
4268
4269 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4270 struct cmd_tx_vlan_set_result {
4271         cmdline_fixed_string_t tx_vlan;
4272         cmdline_fixed_string_t set;
4273         portid_t port_id;
4274         uint16_t vlan_id;
4275 };
4276
4277 static void
4278 cmd_tx_vlan_set_parsed(void *parsed_result,
4279                        __rte_unused struct cmdline *cl,
4280                        __rte_unused void *data)
4281 {
4282         struct cmd_tx_vlan_set_result *res = parsed_result;
4283
4284         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4285                 return;
4286
4287         if (!port_is_stopped(res->port_id)) {
4288                 printf("Please stop port %d first\n", res->port_id);
4289                 return;
4290         }
4291
4292         tx_vlan_set(res->port_id, res->vlan_id);
4293
4294         cmd_reconfig_device_queue(res->port_id, 1, 1);
4295 }
4296
4297 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4298         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4299                                  tx_vlan, "tx_vlan");
4300 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4301         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4302                                  set, "set");
4303 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4304         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4305                               port_id, RTE_UINT16);
4306 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4308                               vlan_id, RTE_UINT16);
4309
4310 cmdline_parse_inst_t cmd_tx_vlan_set = {
4311         .f = cmd_tx_vlan_set_parsed,
4312         .data = NULL,
4313         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4314                 "Enable hardware insertion of a single VLAN header "
4315                 "with a given TAG Identifier in packets sent on a port",
4316         .tokens = {
4317                 (void *)&cmd_tx_vlan_set_tx_vlan,
4318                 (void *)&cmd_tx_vlan_set_set,
4319                 (void *)&cmd_tx_vlan_set_portid,
4320                 (void *)&cmd_tx_vlan_set_vlanid,
4321                 NULL,
4322         },
4323 };
4324
4325 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4326 struct cmd_tx_vlan_set_qinq_result {
4327         cmdline_fixed_string_t tx_vlan;
4328         cmdline_fixed_string_t set;
4329         portid_t port_id;
4330         uint16_t vlan_id;
4331         uint16_t vlan_id_outer;
4332 };
4333
4334 static void
4335 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4336                             __rte_unused struct cmdline *cl,
4337                             __rte_unused void *data)
4338 {
4339         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4340
4341         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4342                 return;
4343
4344         if (!port_is_stopped(res->port_id)) {
4345                 printf("Please stop port %d first\n", res->port_id);
4346                 return;
4347         }
4348
4349         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4350
4351         cmd_reconfig_device_queue(res->port_id, 1, 1);
4352 }
4353
4354 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4355         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4356                 tx_vlan, "tx_vlan");
4357 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4358         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4359                 set, "set");
4360 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4362                 port_id, RTE_UINT16);
4363 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4364         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4365                 vlan_id, RTE_UINT16);
4366 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4367         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4368                 vlan_id_outer, RTE_UINT16);
4369
4370 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4371         .f = cmd_tx_vlan_set_qinq_parsed,
4372         .data = NULL,
4373         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4374                 "Enable hardware insertion of double VLAN header "
4375                 "with given TAG Identifiers in packets sent on a port",
4376         .tokens = {
4377                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4378                 (void *)&cmd_tx_vlan_set_qinq_set,
4379                 (void *)&cmd_tx_vlan_set_qinq_portid,
4380                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4381                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4382                 NULL,
4383         },
4384 };
4385
4386 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4387 struct cmd_tx_vlan_set_pvid_result {
4388         cmdline_fixed_string_t tx_vlan;
4389         cmdline_fixed_string_t set;
4390         cmdline_fixed_string_t pvid;
4391         portid_t port_id;
4392         uint16_t vlan_id;
4393         cmdline_fixed_string_t mode;
4394 };
4395
4396 static void
4397 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4398                             __rte_unused struct cmdline *cl,
4399                             __rte_unused void *data)
4400 {
4401         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4402
4403         if (strcmp(res->mode, "on") == 0)
4404                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4405         else
4406                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4407 }
4408
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4411                                  tx_vlan, "tx_vlan");
4412 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4413         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4414                                  set, "set");
4415 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4416         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4417                                  pvid, "pvid");
4418 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4419         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4420                              port_id, RTE_UINT16);
4421 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4422         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4423                               vlan_id, RTE_UINT16);
4424 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4426                                  mode, "on#off");
4427
4428 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4429         .f = cmd_tx_vlan_set_pvid_parsed,
4430         .data = NULL,
4431         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4432         .tokens = {
4433                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4434                 (void *)&cmd_tx_vlan_set_pvid_set,
4435                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4436                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4437                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4438                 (void *)&cmd_tx_vlan_set_pvid_mode,
4439                 NULL,
4440         },
4441 };
4442
4443 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4444 struct cmd_tx_vlan_reset_result {
4445         cmdline_fixed_string_t tx_vlan;
4446         cmdline_fixed_string_t reset;
4447         portid_t port_id;
4448 };
4449
4450 static void
4451 cmd_tx_vlan_reset_parsed(void *parsed_result,
4452                          __rte_unused struct cmdline *cl,
4453                          __rte_unused void *data)
4454 {
4455         struct cmd_tx_vlan_reset_result *res = parsed_result;
4456
4457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4458                 return;
4459
4460         if (!port_is_stopped(res->port_id)) {
4461                 printf("Please stop port %d first\n", res->port_id);
4462                 return;
4463         }
4464
4465         tx_vlan_reset(res->port_id);
4466
4467         cmd_reconfig_device_queue(res->port_id, 1, 1);
4468 }
4469
4470 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4471         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4472                                  tx_vlan, "tx_vlan");
4473 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4474         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4475                                  reset, "reset");
4476 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4477         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4478                               port_id, RTE_UINT16);
4479
4480 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4481         .f = cmd_tx_vlan_reset_parsed,
4482         .data = NULL,
4483         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4484                 "VLAN header in packets sent on a port",
4485         .tokens = {
4486                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4487                 (void *)&cmd_tx_vlan_reset_reset,
4488                 (void *)&cmd_tx_vlan_reset_portid,
4489                 NULL,
4490         },
4491 };
4492
4493
4494 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4495 struct cmd_csum_result {
4496         cmdline_fixed_string_t csum;
4497         cmdline_fixed_string_t mode;
4498         cmdline_fixed_string_t proto;
4499         cmdline_fixed_string_t hwsw;
4500         portid_t port_id;
4501 };
4502
4503 static void
4504 csum_show(int port_id)
4505 {
4506         struct rte_eth_dev_info dev_info;
4507         uint64_t tx_offloads;
4508         int ret;
4509
4510         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4511         printf("Parse tunnel is %s\n",
4512                 (ports[port_id].parse_tunnel) ? "on" : "off");
4513         printf("IP checksum offload is %s\n",
4514                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4515         printf("UDP checksum offload is %s\n",
4516                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4517         printf("TCP checksum offload is %s\n",
4518                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4519         printf("SCTP checksum offload is %s\n",
4520                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4521         printf("Outer-Ip checksum offload is %s\n",
4522                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4523         printf("Outer-Udp checksum offload is %s\n",
4524                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4525
4526         /* display warnings if configuration is not supported by the NIC */
4527         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4528         if (ret != 0)
4529                 return;
4530
4531         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4532                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4533                 printf("Warning: hardware IP checksum enabled but not "
4534                         "supported by port %d\n", port_id);
4535         }
4536         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4537                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4538                 printf("Warning: hardware UDP checksum enabled but not "
4539                         "supported by port %d\n", port_id);
4540         }
4541         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4542                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4543                 printf("Warning: hardware TCP checksum enabled but not "
4544                         "supported by port %d\n", port_id);
4545         }
4546         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4547                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4548                 printf("Warning: hardware SCTP checksum enabled but not "
4549                         "supported by port %d\n", port_id);
4550         }
4551         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4552                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4553                 printf("Warning: hardware outer IP checksum enabled but not "
4554                         "supported by port %d\n", port_id);
4555         }
4556         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4557                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4558                         == 0) {
4559                 printf("Warning: hardware outer UDP checksum enabled but not "
4560                         "supported by port %d\n", port_id);
4561         }
4562 }
4563
4564 static void
4565 cmd_config_queue_tx_offloads(struct rte_port *port)
4566 {
4567         int k;
4568
4569         /* Apply queue tx offloads configuration */
4570         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4571                 port->tx_conf[k].offloads =
4572                         port->dev_conf.txmode.offloads;
4573 }
4574
4575 static void
4576 cmd_csum_parsed(void *parsed_result,
4577                        __rte_unused struct cmdline *cl,
4578                        __rte_unused void *data)
4579 {
4580         struct cmd_csum_result *res = parsed_result;
4581         int hw = 0;
4582         uint64_t csum_offloads = 0;
4583         struct rte_eth_dev_info dev_info;
4584         int ret;
4585
4586         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4587                 printf("invalid port %d\n", res->port_id);
4588                 return;
4589         }
4590         if (!port_is_stopped(res->port_id)) {
4591                 printf("Please stop port %d first\n", res->port_id);
4592                 return;
4593         }
4594
4595         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4596         if (ret != 0)
4597                 return;
4598
4599         if (!strcmp(res->mode, "set")) {
4600
4601                 if (!strcmp(res->hwsw, "hw"))
4602                         hw = 1;
4603
4604                 if (!strcmp(res->proto, "ip")) {
4605                         if (hw == 0 || (dev_info.tx_offload_capa &
4606                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4607                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4608                         } else {
4609                                 printf("IP checksum offload is not supported "
4610                                        "by port %u\n", res->port_id);
4611                         }
4612                 } else if (!strcmp(res->proto, "udp")) {
4613                         if (hw == 0 || (dev_info.tx_offload_capa &
4614                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4615                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4616                         } else {
4617                                 printf("UDP checksum offload is not supported "
4618                                        "by port %u\n", res->port_id);
4619                         }
4620                 } else if (!strcmp(res->proto, "tcp")) {
4621                         if (hw == 0 || (dev_info.tx_offload_capa &
4622                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4623                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4624                         } else {
4625                                 printf("TCP checksum offload is not supported "
4626                                        "by port %u\n", res->port_id);
4627                         }
4628                 } else if (!strcmp(res->proto, "sctp")) {
4629                         if (hw == 0 || (dev_info.tx_offload_capa &
4630                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4631                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4632                         } else {
4633                                 printf("SCTP checksum offload is not supported "
4634                                        "by port %u\n", res->port_id);
4635                         }
4636                 } else if (!strcmp(res->proto, "outer-ip")) {
4637                         if (hw == 0 || (dev_info.tx_offload_capa &
4638                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4639                                 csum_offloads |=
4640                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4641                         } else {
4642                                 printf("Outer IP checksum offload is not "
4643                                        "supported by port %u\n", res->port_id);
4644                         }
4645                 } else if (!strcmp(res->proto, "outer-udp")) {
4646                         if (hw == 0 || (dev_info.tx_offload_capa &
4647                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4648                                 csum_offloads |=
4649                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4650                         } else {
4651                                 printf("Outer UDP checksum offload is not "
4652                                        "supported by port %u\n", res->port_id);
4653                         }
4654                 }
4655
4656                 if (hw) {
4657                         ports[res->port_id].dev_conf.txmode.offloads |=
4658                                                         csum_offloads;
4659                 } else {
4660                         ports[res->port_id].dev_conf.txmode.offloads &=
4661                                                         (~csum_offloads);
4662                 }
4663                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4664         }
4665         csum_show(res->port_id);
4666
4667         cmd_reconfig_device_queue(res->port_id, 1, 1);
4668 }
4669
4670 cmdline_parse_token_string_t cmd_csum_csum =
4671         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4672                                 csum, "csum");
4673 cmdline_parse_token_string_t cmd_csum_mode =
4674         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4675                                 mode, "set");
4676 cmdline_parse_token_string_t cmd_csum_proto =
4677         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4678                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4679 cmdline_parse_token_string_t cmd_csum_hwsw =
4680         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4681                                 hwsw, "hw#sw");
4682 cmdline_parse_token_num_t cmd_csum_portid =
4683         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4684                                 port_id, RTE_UINT16);
4685
4686 cmdline_parse_inst_t cmd_csum_set = {
4687         .f = cmd_csum_parsed,
4688         .data = NULL,
4689         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4690                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4691                 "using csum forward engine",
4692         .tokens = {
4693                 (void *)&cmd_csum_csum,
4694                 (void *)&cmd_csum_mode,
4695                 (void *)&cmd_csum_proto,
4696                 (void *)&cmd_csum_hwsw,
4697                 (void *)&cmd_csum_portid,
4698                 NULL,
4699         },
4700 };
4701
4702 cmdline_parse_token_string_t cmd_csum_mode_show =
4703         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4704                                 mode, "show");
4705
4706 cmdline_parse_inst_t cmd_csum_show = {
4707         .f = cmd_csum_parsed,
4708         .data = NULL,
4709         .help_str = "csum show <port_id>: Show checksum offload configuration",
4710         .tokens = {
4711                 (void *)&cmd_csum_csum,
4712                 (void *)&cmd_csum_mode_show,
4713                 (void *)&cmd_csum_portid,
4714                 NULL,
4715         },
4716 };
4717
4718 /* Enable/disable tunnel parsing */
4719 struct cmd_csum_tunnel_result {
4720         cmdline_fixed_string_t csum;
4721         cmdline_fixed_string_t parse;
4722         cmdline_fixed_string_t onoff;
4723         portid_t port_id;
4724 };
4725
4726 static void
4727 cmd_csum_tunnel_parsed(void *parsed_result,
4728                        __rte_unused struct cmdline *cl,
4729                        __rte_unused void *data)
4730 {
4731         struct cmd_csum_tunnel_result *res = parsed_result;
4732
4733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4734                 return;
4735
4736         if (!strcmp(res->onoff, "on"))
4737                 ports[res->port_id].parse_tunnel = 1;
4738         else
4739                 ports[res->port_id].parse_tunnel = 0;
4740
4741         csum_show(res->port_id);
4742 }
4743
4744 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4745         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4746                                 csum, "csum");
4747 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4748         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4749                                 parse, "parse-tunnel");
4750 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4751         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4752                                 onoff, "on#off");
4753 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4754         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4755                                 port_id, RTE_UINT16);
4756
4757 cmdline_parse_inst_t cmd_csum_tunnel = {
4758         .f = cmd_csum_tunnel_parsed,
4759         .data = NULL,
4760         .help_str = "csum parse-tunnel on|off <port_id>: "
4761                 "Enable/Disable parsing of tunnels for csum engine",
4762         .tokens = {
4763                 (void *)&cmd_csum_tunnel_csum,
4764                 (void *)&cmd_csum_tunnel_parse,
4765                 (void *)&cmd_csum_tunnel_onoff,
4766                 (void *)&cmd_csum_tunnel_portid,
4767                 NULL,
4768         },
4769 };
4770
4771 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4772 struct cmd_tso_set_result {
4773         cmdline_fixed_string_t tso;
4774         cmdline_fixed_string_t mode;
4775         uint16_t tso_segsz;
4776         portid_t port_id;
4777 };
4778
4779 static void
4780 cmd_tso_set_parsed(void *parsed_result,
4781                        __rte_unused struct cmdline *cl,
4782                        __rte_unused void *data)
4783 {
4784         struct cmd_tso_set_result *res = parsed_result;
4785         struct rte_eth_dev_info dev_info;
4786         int ret;
4787
4788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4789                 return;
4790         if (!port_is_stopped(res->port_id)) {
4791                 printf("Please stop port %d first\n", res->port_id);
4792                 return;
4793         }
4794
4795         if (!strcmp(res->mode, "set"))
4796                 ports[res->port_id].tso_segsz = res->tso_segsz;
4797
4798         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4799         if (ret != 0)
4800                 return;
4801
4802         if ((ports[res->port_id].tso_segsz != 0) &&
4803                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4804                 printf("Error: TSO is not supported by port %d\n",
4805                        res->port_id);
4806                 return;
4807         }
4808
4809         if (ports[res->port_id].tso_segsz == 0) {
4810                 ports[res->port_id].dev_conf.txmode.offloads &=
4811                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4812                 printf("TSO for non-tunneled packets is disabled\n");
4813         } else {
4814                 ports[res->port_id].dev_conf.txmode.offloads |=
4815                                                 DEV_TX_OFFLOAD_TCP_TSO;
4816                 printf("TSO segment size for non-tunneled packets is %d\n",
4817                         ports[res->port_id].tso_segsz);
4818         }
4819         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4820
4821         /* display warnings if configuration is not supported by the NIC */
4822         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4823         if (ret != 0)
4824                 return;
4825
4826         if ((ports[res->port_id].tso_segsz != 0) &&
4827                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4828                 printf("Warning: TSO enabled but not "
4829                         "supported by port %d\n", res->port_id);
4830         }
4831
4832         cmd_reconfig_device_queue(res->port_id, 1, 1);
4833 }
4834
4835 cmdline_parse_token_string_t cmd_tso_set_tso =
4836         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4837                                 tso, "tso");
4838 cmdline_parse_token_string_t cmd_tso_set_mode =
4839         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4840                                 mode, "set");
4841 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4842         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4843                                 tso_segsz, RTE_UINT16);
4844 cmdline_parse_token_num_t cmd_tso_set_portid =
4845         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4846                                 port_id, RTE_UINT16);
4847
4848 cmdline_parse_inst_t cmd_tso_set = {
4849         .f = cmd_tso_set_parsed,
4850         .data = NULL,
4851         .help_str = "tso set <tso_segsz> <port_id>: "
4852                 "Set TSO segment size of non-tunneled packets for csum engine "
4853                 "(0 to disable)",
4854         .tokens = {
4855                 (void *)&cmd_tso_set_tso,
4856                 (void *)&cmd_tso_set_mode,
4857                 (void *)&cmd_tso_set_tso_segsz,
4858                 (void *)&cmd_tso_set_portid,
4859                 NULL,
4860         },
4861 };
4862
4863 cmdline_parse_token_string_t cmd_tso_show_mode =
4864         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4865                                 mode, "show");
4866
4867
4868 cmdline_parse_inst_t cmd_tso_show = {
4869         .f = cmd_tso_set_parsed,
4870         .data = NULL,
4871         .help_str = "tso show <port_id>: "
4872                 "Show TSO segment size of non-tunneled packets for csum engine",
4873         .tokens = {
4874                 (void *)&cmd_tso_set_tso,
4875                 (void *)&cmd_tso_show_mode,
4876                 (void *)&cmd_tso_set_portid,
4877                 NULL,
4878         },
4879 };
4880
4881 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4882 struct cmd_tunnel_tso_set_result {
4883         cmdline_fixed_string_t tso;
4884         cmdline_fixed_string_t mode;
4885         uint16_t tso_segsz;
4886         portid_t port_id;
4887 };
4888
4889 static struct rte_eth_dev_info
4890 check_tunnel_tso_nic_support(portid_t port_id)
4891 {
4892         struct rte_eth_dev_info dev_info;
4893
4894         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4895                 return dev_info;
4896
4897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4898                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4899                        "not enabled for port %d\n", port_id);
4900         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4901                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4902                        "not enabled for port %d\n", port_id);
4903         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4904                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4905                        "not enabled for port %d\n", port_id);
4906         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4907                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4908                        "not enabled for port %d\n", port_id);
4909         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4910                 printf("Warning: IP TUNNEL TSO not supported therefore "
4911                        "not enabled for port %d\n", port_id);
4912         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4913                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4914                        "not enabled for port %d\n", port_id);
4915         return dev_info;
4916 }
4917
4918 static void
4919 cmd_tunnel_tso_set_parsed(void *parsed_result,
4920                           __rte_unused struct cmdline *cl,
4921                           __rte_unused void *data)
4922 {
4923         struct cmd_tunnel_tso_set_result *res = parsed_result;
4924         struct rte_eth_dev_info dev_info;
4925
4926         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4927                 return;
4928         if (!port_is_stopped(res->port_id)) {
4929                 printf("Please stop port %d first\n", res->port_id);
4930                 return;
4931         }
4932
4933         if (!strcmp(res->mode, "set"))
4934                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4935
4936         dev_info = check_tunnel_tso_nic_support(res->port_id);
4937         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4938                 ports[res->port_id].dev_conf.txmode.offloads &=
4939                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4940                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4941                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4942                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4943                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4944                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4945                 printf("TSO for tunneled packets is disabled\n");
4946         } else {
4947                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4948                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4949                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4950                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4951                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4952                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4953
4954                 ports[res->port_id].dev_conf.txmode.offloads |=
4955                         (tso_offloads & dev_info.tx_offload_capa);
4956                 printf("TSO segment size for tunneled packets is %d\n",
4957                         ports[res->port_id].tunnel_tso_segsz);
4958
4959                 /* Below conditions are needed to make it work:
4960                  * (1) tunnel TSO is supported by the NIC;
4961                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4962                  * are recognized;
4963                  * (3) for tunneled pkts with outer L3 of IPv4,
4964                  * "csum set outer-ip" must be set to hw, because after tso,
4965                  * total_len of outer IP header is changed, and the checksum
4966                  * of outer IP header calculated by sw should be wrong; that
4967                  * is not necessary for IPv6 tunneled pkts because there's no
4968                  * checksum in IP header anymore.
4969                  */
4970
4971                 if (!ports[res->port_id].parse_tunnel)
4972                         printf("Warning: csum parse_tunnel must be set "
4973                                 "so that tunneled packets are recognized\n");
4974                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4975                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4976                         printf("Warning: csum set outer-ip must be set to hw "
4977                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4978         }
4979
4980         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4981         cmd_reconfig_device_queue(res->port_id, 1, 1);
4982 }
4983
4984 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4985         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4986                                 tso, "tunnel_tso");
4987 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4988         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4989                                 mode, "set");
4990 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4991         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4992                                 tso_segsz, RTE_UINT16);
4993 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4994         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4995                                 port_id, RTE_UINT16);
4996
4997 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4998         .f = cmd_tunnel_tso_set_parsed,
4999         .data = NULL,
5000         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5001                 "Set TSO segment size of tunneled packets for csum engine "
5002                 "(0 to disable)",
5003         .tokens = {
5004                 (void *)&cmd_tunnel_tso_set_tso,
5005                 (void *)&cmd_tunnel_tso_set_mode,
5006                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5007                 (void *)&cmd_tunnel_tso_set_portid,
5008                 NULL,
5009         },
5010 };
5011
5012 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5013         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5014                                 mode, "show");
5015
5016
5017 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5018         .f = cmd_tunnel_tso_set_parsed,
5019         .data = NULL,
5020         .help_str = "tunnel_tso show <port_id> "
5021                 "Show TSO segment size of tunneled packets for csum engine",
5022         .tokens = {
5023                 (void *)&cmd_tunnel_tso_set_tso,
5024                 (void *)&cmd_tunnel_tso_show_mode,
5025                 (void *)&cmd_tunnel_tso_set_portid,
5026                 NULL,
5027         },
5028 };
5029
5030 /* *** SET GRO FOR A PORT *** */
5031 struct cmd_gro_enable_result {
5032         cmdline_fixed_string_t cmd_set;
5033         cmdline_fixed_string_t cmd_port;
5034         cmdline_fixed_string_t cmd_keyword;
5035         cmdline_fixed_string_t cmd_onoff;
5036         portid_t cmd_pid;
5037 };
5038
5039 static void
5040 cmd_gro_enable_parsed(void *parsed_result,
5041                 __rte_unused struct cmdline *cl,
5042                 __rte_unused void *data)
5043 {
5044         struct cmd_gro_enable_result *res;
5045
5046         res = parsed_result;
5047         if (!strcmp(res->cmd_keyword, "gro"))
5048                 setup_gro(res->cmd_onoff, res->cmd_pid);
5049 }
5050
5051 cmdline_parse_token_string_t cmd_gro_enable_set =
5052         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5053                         cmd_set, "set");
5054 cmdline_parse_token_string_t cmd_gro_enable_port =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5056                         cmd_keyword, "port");
5057 cmdline_parse_token_num_t cmd_gro_enable_pid =
5058         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5059                         cmd_pid, RTE_UINT16);
5060 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5061         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5062                         cmd_keyword, "gro");
5063 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5064         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5065                         cmd_onoff, "on#off");
5066
5067 cmdline_parse_inst_t cmd_gro_enable = {
5068         .f = cmd_gro_enable_parsed,
5069         .data = NULL,
5070         .help_str = "set port <port_id> gro on|off",
5071         .tokens = {
5072                 (void *)&cmd_gro_enable_set,
5073                 (void *)&cmd_gro_enable_port,
5074                 (void *)&cmd_gro_enable_pid,
5075                 (void *)&cmd_gro_enable_keyword,
5076                 (void *)&cmd_gro_enable_onoff,
5077                 NULL,
5078         },
5079 };
5080
5081 /* *** DISPLAY GRO CONFIGURATION *** */
5082 struct cmd_gro_show_result {
5083         cmdline_fixed_string_t cmd_show;
5084         cmdline_fixed_string_t cmd_port;
5085         cmdline_fixed_string_t cmd_keyword;
5086         portid_t cmd_pid;
5087 };
5088
5089 static void
5090 cmd_gro_show_parsed(void *parsed_result,
5091                 __rte_unused struct cmdline *cl,
5092                 __rte_unused void *data)
5093 {
5094         struct cmd_gro_show_result *res;
5095
5096         res = parsed_result;
5097         if (!strcmp(res->cmd_keyword, "gro"))
5098                 show_gro(res->cmd_pid);
5099 }
5100
5101 cmdline_parse_token_string_t cmd_gro_show_show =
5102         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5103                         cmd_show, "show");
5104 cmdline_parse_token_string_t cmd_gro_show_port =
5105         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5106                         cmd_port, "port");
5107 cmdline_parse_token_num_t cmd_gro_show_pid =
5108         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5109                         cmd_pid, RTE_UINT16);
5110 cmdline_parse_token_string_t cmd_gro_show_keyword =
5111         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5112                         cmd_keyword, "gro");
5113
5114 cmdline_parse_inst_t cmd_gro_show = {
5115         .f = cmd_gro_show_parsed,
5116         .data = NULL,
5117         .help_str = "show port <port_id> gro",
5118         .tokens = {
5119                 (void *)&cmd_gro_show_show,
5120                 (void *)&cmd_gro_show_port,
5121                 (void *)&cmd_gro_show_pid,
5122                 (void *)&cmd_gro_show_keyword,
5123                 NULL,
5124         },
5125 };
5126
5127 /* *** SET FLUSH CYCLES FOR GRO *** */
5128 struct cmd_gro_flush_result {
5129         cmdline_fixed_string_t cmd_set;
5130         cmdline_fixed_string_t cmd_keyword;
5131         cmdline_fixed_string_t cmd_flush;
5132         uint8_t cmd_cycles;
5133 };
5134
5135 static void
5136 cmd_gro_flush_parsed(void *parsed_result,
5137                 __rte_unused struct cmdline *cl,
5138                 __rte_unused void *data)
5139 {
5140         struct cmd_gro_flush_result *res;
5141
5142         res = parsed_result;
5143         if ((!strcmp(res->cmd_keyword, "gro")) &&
5144                         (!strcmp(res->cmd_flush, "flush")))
5145                 setup_gro_flush_cycles(res->cmd_cycles);
5146 }
5147
5148 cmdline_parse_token_string_t cmd_gro_flush_set =
5149         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5150                         cmd_set, "set");
5151 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5152         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5153                         cmd_keyword, "gro");
5154 cmdline_parse_token_string_t cmd_gro_flush_flush =
5155         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5156                         cmd_flush, "flush");
5157 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5158         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5159                         cmd_cycles, RTE_UINT8);
5160
5161 cmdline_parse_inst_t cmd_gro_flush = {
5162         .f = cmd_gro_flush_parsed,
5163         .data = NULL,
5164         .help_str = "set gro flush <cycles>",
5165         .tokens = {
5166                 (void *)&cmd_gro_flush_set,
5167                 (void *)&cmd_gro_flush_keyword,
5168                 (void *)&cmd_gro_flush_flush,
5169                 (void *)&cmd_gro_flush_cycles,
5170                 NULL,
5171         },
5172 };
5173
5174 /* *** ENABLE/DISABLE GSO *** */
5175 struct cmd_gso_enable_result {
5176         cmdline_fixed_string_t cmd_set;
5177         cmdline_fixed_string_t cmd_port;
5178         cmdline_fixed_string_t cmd_keyword;
5179         cmdline_fixed_string_t cmd_mode;
5180         portid_t cmd_pid;
5181 };
5182
5183 static void
5184 cmd_gso_enable_parsed(void *parsed_result,
5185                 __rte_unused struct cmdline *cl,
5186                 __rte_unused void *data)
5187 {
5188         struct cmd_gso_enable_result *res;
5189
5190         res = parsed_result;
5191         if (!strcmp(res->cmd_keyword, "gso"))
5192                 setup_gso(res->cmd_mode, res->cmd_pid);
5193 }
5194
5195 cmdline_parse_token_string_t cmd_gso_enable_set =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5197                         cmd_set, "set");
5198 cmdline_parse_token_string_t cmd_gso_enable_port =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5200                         cmd_port, "port");
5201 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5202         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5203                         cmd_keyword, "gso");
5204 cmdline_parse_token_string_t cmd_gso_enable_mode =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5206                         cmd_mode, "on#off");
5207 cmdline_parse_token_num_t cmd_gso_enable_pid =
5208         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5209                         cmd_pid, RTE_UINT16);
5210
5211 cmdline_parse_inst_t cmd_gso_enable = {
5212         .f = cmd_gso_enable_parsed,
5213         .data = NULL,
5214         .help_str = "set port <port_id> gso on|off",
5215         .tokens = {
5216                 (void *)&cmd_gso_enable_set,
5217                 (void *)&cmd_gso_enable_port,
5218                 (void *)&cmd_gso_enable_pid,
5219                 (void *)&cmd_gso_enable_keyword,
5220                 (void *)&cmd_gso_enable_mode,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5226 struct cmd_gso_size_result {
5227         cmdline_fixed_string_t cmd_set;
5228         cmdline_fixed_string_t cmd_keyword;
5229         cmdline_fixed_string_t cmd_segsz;
5230         uint16_t cmd_size;
5231 };
5232
5233 static void
5234 cmd_gso_size_parsed(void *parsed_result,
5235                        __rte_unused struct cmdline *cl,
5236                        __rte_unused void *data)
5237 {
5238         struct cmd_gso_size_result *res = parsed_result;
5239
5240         if (test_done == 0) {
5241                 printf("Before setting GSO segsz, please first"
5242                                 " stop forwarding\n");
5243                 return;
5244         }
5245
5246         if (!strcmp(res->cmd_keyword, "gso") &&
5247                         !strcmp(res->cmd_segsz, "segsz")) {
5248                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5249                         printf("gso_size should be larger than %zu."
5250                                         " Please input a legal value\n",
5251                                         RTE_GSO_SEG_SIZE_MIN);
5252                 else
5253                         gso_max_segment_size = res->cmd_size;
5254         }
5255 }
5256
5257 cmdline_parse_token_string_t cmd_gso_size_set =
5258         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5259                                 cmd_set, "set");
5260 cmdline_parse_token_string_t cmd_gso_size_keyword =
5261         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5262                                 cmd_keyword, "gso");
5263 cmdline_parse_token_string_t cmd_gso_size_segsz =
5264         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5265                                 cmd_segsz, "segsz");
5266 cmdline_parse_token_num_t cmd_gso_size_size =
5267         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5268                                 cmd_size, RTE_UINT16);
5269
5270 cmdline_parse_inst_t cmd_gso_size = {
5271         .f = cmd_gso_size_parsed,
5272         .data = NULL,
5273         .help_str = "set gso segsz <length>",
5274         .tokens = {
5275                 (void *)&cmd_gso_size_set,
5276                 (void *)&cmd_gso_size_keyword,
5277                 (void *)&cmd_gso_size_segsz,
5278                 (void *)&cmd_gso_size_size,
5279                 NULL,
5280         },
5281 };
5282
5283 /* *** SHOW GSO CONFIGURATION *** */
5284 struct cmd_gso_show_result {
5285         cmdline_fixed_string_t cmd_show;
5286         cmdline_fixed_string_t cmd_port;
5287         cmdline_fixed_string_t cmd_keyword;
5288         portid_t cmd_pid;
5289 };
5290
5291 static void
5292 cmd_gso_show_parsed(void *parsed_result,
5293                        __rte_unused struct cmdline *cl,
5294                        __rte_unused void *data)
5295 {
5296         struct cmd_gso_show_result *res = parsed_result;
5297
5298         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5299                 printf("invalid port id %u\n", res->cmd_pid);
5300                 return;
5301         }
5302         if (!strcmp(res->cmd_keyword, "gso")) {
5303                 if (gso_ports[res->cmd_pid].enable) {
5304                         printf("Max GSO'd packet size: %uB\n"
5305                                         "Supported GSO types: TCP/IPv4, "
5306                                         "UDP/IPv4, VxLAN with inner "
5307                                         "TCP/IPv4 packet, GRE with inner "
5308                                         "TCP/IPv4 packet\n",
5309                                         gso_max_segment_size);
5310                 } else
5311                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5312         }
5313 }
5314
5315 cmdline_parse_token_string_t cmd_gso_show_show =
5316 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5317                 cmd_show, "show");
5318 cmdline_parse_token_string_t cmd_gso_show_port =
5319 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5320                 cmd_port, "port");
5321 cmdline_parse_token_string_t cmd_gso_show_keyword =
5322         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5323                                 cmd_keyword, "gso");
5324 cmdline_parse_token_num_t cmd_gso_show_pid =
5325         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5326                                 cmd_pid, RTE_UINT16);
5327
5328 cmdline_parse_inst_t cmd_gso_show = {
5329         .f = cmd_gso_show_parsed,
5330         .data = NULL,
5331         .help_str = "show port <port_id> gso",
5332         .tokens = {
5333                 (void *)&cmd_gso_show_show,
5334                 (void *)&cmd_gso_show_port,
5335                 (void *)&cmd_gso_show_pid,
5336                 (void *)&cmd_gso_show_keyword,
5337                 NULL,
5338         },
5339 };
5340
5341 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5342 struct cmd_set_flush_rx {
5343         cmdline_fixed_string_t set;
5344         cmdline_fixed_string_t flush_rx;
5345         cmdline_fixed_string_t mode;
5346 };
5347
5348 static void
5349 cmd_set_flush_rx_parsed(void *parsed_result,
5350                 __rte_unused struct cmdline *cl,
5351                 __rte_unused void *data)
5352 {
5353         struct cmd_set_flush_rx *res = parsed_result;
5354         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5355 }
5356
5357 cmdline_parse_token_string_t cmd_setflushrx_set =
5358         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5359                         set, "set");
5360 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5362                         flush_rx, "flush_rx");
5363 cmdline_parse_token_string_t cmd_setflushrx_mode =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5365                         mode, "on#off");
5366
5367
5368 cmdline_parse_inst_t cmd_set_flush_rx = {
5369         .f = cmd_set_flush_rx_parsed,
5370         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5371         .data = NULL,
5372         .tokens = {
5373                 (void *)&cmd_setflushrx_set,
5374                 (void *)&cmd_setflushrx_flush_rx,
5375                 (void *)&cmd_setflushrx_mode,
5376                 NULL,
5377         },
5378 };
5379
5380 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5381 struct cmd_set_link_check {
5382         cmdline_fixed_string_t set;
5383         cmdline_fixed_string_t link_check;
5384         cmdline_fixed_string_t mode;
5385 };
5386
5387 static void
5388 cmd_set_link_check_parsed(void *parsed_result,
5389                 __rte_unused struct cmdline *cl,
5390                 __rte_unused void *data)
5391 {
5392         struct cmd_set_link_check *res = parsed_result;
5393         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5394 }
5395
5396 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5398                         set, "set");
5399 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5401                         link_check, "link_check");
5402 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5403         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5404                         mode, "on#off");
5405
5406
5407 cmdline_parse_inst_t cmd_set_link_check = {
5408         .f = cmd_set_link_check_parsed,
5409         .help_str = "set link_check on|off: Enable/Disable link status check "
5410                     "when starting/stopping a port",
5411         .data = NULL,
5412         .tokens = {
5413                 (void *)&cmd_setlinkcheck_set,
5414                 (void *)&cmd_setlinkcheck_link_check,
5415                 (void *)&cmd_setlinkcheck_mode,
5416                 NULL,
5417         },
5418 };
5419
5420 /* *** SET NIC BYPASS MODE *** */
5421 struct cmd_set_bypass_mode_result {
5422         cmdline_fixed_string_t set;
5423         cmdline_fixed_string_t bypass;
5424         cmdline_fixed_string_t mode;
5425         cmdline_fixed_string_t value;
5426         portid_t port_id;
5427 };
5428
5429 static void
5430 cmd_set_bypass_mode_parsed(void *parsed_result,
5431                 __rte_unused struct cmdline *cl,
5432                 __rte_unused void *data)
5433 {
5434         struct cmd_set_bypass_mode_result *res = parsed_result;
5435         portid_t port_id = res->port_id;
5436         int32_t rc = -EINVAL;
5437
5438 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5439         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5440
5441         if (!strcmp(res->value, "bypass"))
5442                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5443         else if (!strcmp(res->value, "isolate"))
5444                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5445         else
5446                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5447
5448         /* Set the bypass mode for the relevant port. */
5449         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5450 #endif
5451         if (rc != 0)
5452                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5453 }
5454
5455 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5457                         set, "set");
5458 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5460                         bypass, "bypass");
5461 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5463                         mode, "mode");
5464 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5466                         value, "normal#bypass#isolate");
5467 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5468         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5469                                 port_id, RTE_UINT16);
5470
5471 cmdline_parse_inst_t cmd_set_bypass_mode = {
5472         .f = cmd_set_bypass_mode_parsed,
5473         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5474                     "Set the NIC bypass mode for port_id",
5475         .data = NULL,
5476         .tokens = {
5477                 (void *)&cmd_setbypass_mode_set,
5478                 (void *)&cmd_setbypass_mode_bypass,
5479                 (void *)&cmd_setbypass_mode_mode,
5480                 (void *)&cmd_setbypass_mode_value,
5481                 (void *)&cmd_setbypass_mode_port,
5482                 NULL,
5483         },
5484 };
5485
5486 /* *** SET NIC BYPASS EVENT *** */
5487 struct cmd_set_bypass_event_result {
5488         cmdline_fixed_string_t set;
5489         cmdline_fixed_string_t bypass;
5490         cmdline_fixed_string_t event;
5491         cmdline_fixed_string_t event_value;
5492         cmdline_fixed_string_t mode;
5493         cmdline_fixed_string_t mode_value;
5494         portid_t port_id;
5495 };
5496
5497 static void
5498 cmd_set_bypass_event_parsed(void *parsed_result,
5499                 __rte_unused struct cmdline *cl,
5500                 __rte_unused void *data)
5501 {
5502         int32_t rc = -EINVAL;
5503         struct cmd_set_bypass_event_result *res = parsed_result;
5504         portid_t port_id = res->port_id;
5505
5506 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5507         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5508         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5509
5510         if (!strcmp(res->event_value, "timeout"))
5511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5512         else if (!strcmp(res->event_value, "os_on"))
5513                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5514         else if (!strcmp(res->event_value, "os_off"))
5515                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5516         else if (!strcmp(res->event_value, "power_on"))
5517                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5518         else if (!strcmp(res->event_value, "power_off"))
5519                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5520         else
5521                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5522
5523         if (!strcmp(res->mode_value, "bypass"))
5524                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5525         else if (!strcmp(res->mode_value, "isolate"))
5526                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5527         else
5528                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5529
5530         /* Set the watchdog timeout. */
5531         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5532
5533                 rc = -EINVAL;
5534                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5535                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5536                                                            bypass_timeout);
5537                 }
5538                 if (rc != 0) {
5539                         printf("Failed to set timeout value %u "
5540                         "for port %d, errto code: %d.\n",
5541                         bypass_timeout, port_id, rc);
5542                 }
5543         }
5544
5545         /* Set the bypass event to transition to bypass mode. */
5546         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5547                                               bypass_mode);
5548 #endif
5549
5550         if (rc != 0)
5551                 printf("\t Failed to set bypass event for port = %d.\n",
5552                        port_id);
5553 }
5554
5555 cmdline_parse_token_string_t cmd_setbypass_event_set =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5557                         set, "set");
5558 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5560                         bypass, "bypass");
5561 cmdline_parse_token_string_t cmd_setbypass_event_event =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5563                         event, "event");
5564 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5566                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5567 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5569                         mode, "mode");
5570 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5572                         mode_value, "normal#bypass#isolate");
5573 cmdline_parse_token_num_t cmd_setbypass_event_port =
5574         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5575                                 port_id, RTE_UINT16);
5576
5577 cmdline_parse_inst_t cmd_set_bypass_event = {
5578         .f = cmd_set_bypass_event_parsed,
5579         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5580                 "power_off mode normal|bypass|isolate <port_id>: "
5581                 "Set the NIC bypass event mode for port_id",
5582         .data = NULL,
5583         .tokens = {
5584                 (void *)&cmd_setbypass_event_set,
5585                 (void *)&cmd_setbypass_event_bypass,
5586                 (void *)&cmd_setbypass_event_event,
5587                 (void *)&cmd_setbypass_event_event_value,
5588                 (void *)&cmd_setbypass_event_mode,
5589                 (void *)&cmd_setbypass_event_mode_value,
5590                 (void *)&cmd_setbypass_event_port,
5591                 NULL,
5592         },
5593 };
5594
5595
5596 /* *** SET NIC BYPASS TIMEOUT *** */
5597 struct cmd_set_bypass_timeout_result {
5598         cmdline_fixed_string_t set;
5599         cmdline_fixed_string_t bypass;
5600         cmdline_fixed_string_t timeout;
5601         cmdline_fixed_string_t value;
5602 };
5603
5604 static void
5605 cmd_set_bypass_timeout_parsed(void *parsed_result,
5606                 __rte_unused struct cmdline *cl,
5607                 __rte_unused void *data)
5608 {
5609         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5610
5611 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5612         if (!strcmp(res->value, "1.5"))
5613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5614         else if (!strcmp(res->value, "2"))
5615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5616         else if (!strcmp(res->value, "3"))
5617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5618         else if (!strcmp(res->value, "4"))
5619                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5620         else if (!strcmp(res->value, "8"))
5621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5622         else if (!strcmp(res->value, "16"))
5623                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5624         else if (!strcmp(res->value, "32"))
5625                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5626         else
5627                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5628 #endif
5629 }
5630
5631 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5633                         set, "set");
5634 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5636                         bypass, "bypass");
5637 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5639                         timeout, "timeout");
5640 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5642                         value, "0#1.5#2#3#4#8#16#32");
5643
5644 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5645         .f = cmd_set_bypass_timeout_parsed,
5646         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5647                 "Set the NIC bypass watchdog timeout in seconds",
5648         .data = NULL,
5649         .tokens = {
5650                 (void *)&cmd_setbypass_timeout_set,
5651                 (void *)&cmd_setbypass_timeout_bypass,
5652                 (void *)&cmd_setbypass_timeout_timeout,
5653                 (void *)&cmd_setbypass_timeout_value,
5654                 NULL,
5655         },
5656 };
5657
5658 /* *** SHOW NIC BYPASS MODE *** */
5659 struct cmd_show_bypass_config_result {
5660         cmdline_fixed_string_t show;
5661         cmdline_fixed_string_t bypass;
5662         cmdline_fixed_string_t config;
5663         portid_t port_id;
5664 };
5665
5666 static void
5667 cmd_show_bypass_config_parsed(void *parsed_result,
5668                 __rte_unused struct cmdline *cl,
5669                 __rte_unused void *data)
5670 {
5671         struct cmd_show_bypass_config_result *res = parsed_result;
5672         portid_t port_id = res->port_id;
5673         int rc = -EINVAL;
5674 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5675         uint32_t event_mode;
5676         uint32_t bypass_mode;
5677         uint32_t timeout = bypass_timeout;
5678         unsigned int i;
5679
5680         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5681                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5682         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5683                 {"UNKNOWN", "normal", "bypass", "isolate"};
5684         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5685                 "NONE",
5686                 "OS/board on",
5687                 "power supply on",
5688                 "OS/board off",
5689                 "power supply off",
5690                 "timeout"};
5691
5692         /* Display the bypass mode.*/
5693         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5694                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5695                 return;
5696         }
5697         else {
5698                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5699                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5700
5701                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5702         }
5703
5704         /* Display the bypass timeout.*/
5705         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5706                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5707
5708         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5709
5710         /* Display the bypass events and associated modes. */
5711         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5712
5713                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5714                         printf("\tFailed to get bypass mode for event = %s\n",
5715                                 events[i]);
5716                 } else {
5717                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5718                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5719
5720                         printf("\tbypass event: %-16s = %s\n", events[i],
5721                                 modes[event_mode]);
5722                 }
5723         }
5724 #endif
5725         if (rc != 0)
5726                 printf("\tFailed to get bypass configuration for port = %d\n",
5727                        port_id);
5728 }
5729
5730 cmdline_parse_token_string_t cmd_showbypass_config_show =
5731         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5732                         show, "show");
5733 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5734         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5735                         bypass, "bypass");
5736 cmdline_parse_token_string_t cmd_showbypass_config_config =
5737         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5738                         config, "config");
5739 cmdline_parse_token_num_t cmd_showbypass_config_port =
5740         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5741                                 port_id, RTE_UINT16);
5742
5743 cmdline_parse_inst_t cmd_show_bypass_config = {
5744         .f = cmd_show_bypass_config_parsed,
5745         .help_str = "show bypass config <port_id>: "
5746                     "Show the NIC bypass config for port_id",
5747         .data = NULL,
5748         .tokens = {
5749                 (void *)&cmd_showbypass_config_show,
5750                 (void *)&cmd_showbypass_config_bypass,
5751                 (void *)&cmd_showbypass_config_config,
5752                 (void *)&cmd_showbypass_config_port,
5753                 NULL,
5754         },
5755 };
5756
5757 #ifdef RTE_NET_BOND
5758 /* *** SET BONDING MODE *** */
5759 struct cmd_set_bonding_mode_result {
5760         cmdline_fixed_string_t set;
5761         cmdline_fixed_string_t bonding;
5762         cmdline_fixed_string_t mode;
5763         uint8_t value;
5764         portid_t port_id;
5765 };
5766
5767 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5768                 __rte_unused  struct cmdline *cl,
5769                 __rte_unused void *data)
5770 {
5771         struct cmd_set_bonding_mode_result *res = parsed_result;
5772         portid_t port_id = res->port_id;
5773
5774         /* Set the bonding mode for the relevant port. */
5775         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5776                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5777 }
5778
5779 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5780 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5781                 set, "set");
5782 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5783 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5784                 bonding, "bonding");
5785 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5786 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5787                 mode, "mode");
5788 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5789 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5790                 value, RTE_UINT8);
5791 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5792 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5793                 port_id, RTE_UINT16);
5794
5795 cmdline_parse_inst_t cmd_set_bonding_mode = {
5796                 .f = cmd_set_bonding_mode_parsed,
5797                 .help_str = "set bonding mode <mode_value> <port_id>: "
5798                         "Set the bonding mode for port_id",
5799                 .data = NULL,
5800                 .tokens = {
5801                                 (void *) &cmd_setbonding_mode_set,
5802                                 (void *) &cmd_setbonding_mode_bonding,
5803                                 (void *) &cmd_setbonding_mode_mode,
5804                                 (void *) &cmd_setbonding_mode_value,
5805                                 (void *) &cmd_setbonding_mode_port,
5806                                 NULL
5807                 }
5808 };
5809
5810 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5811 struct cmd_set_bonding_lacp_dedicated_queues_result {
5812         cmdline_fixed_string_t set;
5813         cmdline_fixed_string_t bonding;
5814         cmdline_fixed_string_t lacp;
5815         cmdline_fixed_string_t dedicated_queues;
5816         portid_t port_id;
5817         cmdline_fixed_string_t mode;
5818 };
5819
5820 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5821                 __rte_unused  struct cmdline *cl,
5822                 __rte_unused void *data)
5823 {
5824         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5825         portid_t port_id = res->port_id;
5826         struct rte_port *port;
5827
5828         port = &ports[port_id];
5829
5830         /** Check if the port is not started **/
5831         if (port->port_status != RTE_PORT_STOPPED) {
5832                 printf("Please stop port %d first\n", port_id);
5833                 return;
5834         }
5835
5836         if (!strcmp(res->mode, "enable")) {
5837                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5838                         printf("Dedicate queues for LACP control packets"
5839                                         " enabled\n");
5840                 else
5841                         printf("Enabling dedicate queues for LACP control "
5842                                         "packets on port %d failed\n", port_id);
5843         } else if (!strcmp(res->mode, "disable")) {
5844                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5845                         printf("Dedicated queues for LACP control packets "
5846                                         "disabled\n");
5847                 else
5848                         printf("Disabling dedicated queues for LACP control "
5849                                         "traffic on port %d failed\n", port_id);
5850         }
5851 }
5852
5853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5855                 set, "set");
5856 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5858                 bonding, "bonding");
5859 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5861                 lacp, "lacp");
5862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5864                 dedicated_queues, "dedicated_queues");
5865 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5866 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5867                 port_id, RTE_UINT16);
5868 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5869 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5870                 mode, "enable#disable");
5871
5872 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5873                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5874                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5875                         "enable|disable: "
5876                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5877                 .data = NULL,
5878                 .tokens = {
5879                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5880                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5881                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5882                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5883                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5884                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5885                         NULL
5886                 }
5887 };
5888
5889 /* *** SET BALANCE XMIT POLICY *** */
5890 struct cmd_set_bonding_balance_xmit_policy_result {
5891         cmdline_fixed_string_t set;
5892         cmdline_fixed_string_t bonding;
5893         cmdline_fixed_string_t balance_xmit_policy;
5894         portid_t port_id;
5895         cmdline_fixed_string_t policy;
5896 };
5897
5898 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5899                 __rte_unused  struct cmdline *cl,
5900                 __rte_unused void *data)
5901 {
5902         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5903         portid_t port_id = res->port_id;
5904         uint8_t policy;
5905
5906         if (!strcmp(res->policy, "l2")) {
5907                 policy = BALANCE_XMIT_POLICY_LAYER2;
5908         } else if (!strcmp(res->policy, "l23")) {
5909                 policy = BALANCE_XMIT_POLICY_LAYER23;
5910         } else if (!strcmp(res->policy, "l34")) {
5911                 policy = BALANCE_XMIT_POLICY_LAYER34;
5912         } else {
5913                 printf("\t Invalid xmit policy selection");
5914                 return;
5915         }
5916
5917         /* Set the bonding mode for the relevant port. */
5918         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5919                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5920                                 port_id);
5921         }
5922 }
5923
5924 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5926                 set, "set");
5927 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5929                 bonding, "bonding");
5930 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5932                 balance_xmit_policy, "balance_xmit_policy");
5933 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5934 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5935                 port_id, RTE_UINT16);
5936 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5938                 policy, "l2#l23#l34");
5939
5940 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5941                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5942                 .help_str = "set bonding balance_xmit_policy <port_id> "
5943                         "l2|l23|l34: "
5944                         "Set the bonding balance_xmit_policy for port_id",
5945                 .data = NULL,
5946                 .tokens = {
5947                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5948                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5949                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5950                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5951                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5952                                 NULL
5953                 }
5954 };
5955
5956 /* *** SHOW NIC BONDING CONFIGURATION *** */
5957 struct cmd_show_bonding_config_result {
5958         cmdline_fixed_string_t show;
5959         cmdline_fixed_string_t bonding;
5960         cmdline_fixed_string_t config;
5961         portid_t port_id;
5962 };
5963
5964 static void cmd_show_bonding_config_parsed(void *parsed_result,
5965                 __rte_unused  struct cmdline *cl,
5966                 __rte_unused void *data)
5967 {
5968         struct cmd_show_bonding_config_result *res = parsed_result;
5969         int bonding_mode, agg_mode;
5970         portid_t slaves[RTE_MAX_ETHPORTS];
5971         int num_slaves, num_active_slaves;
5972         int primary_id;
5973         int i;
5974         portid_t port_id = res->port_id;
5975
5976         /* Display the bonding mode.*/
5977         bonding_mode = rte_eth_bond_mode_get(port_id);
5978         if (bonding_mode < 0) {
5979                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5980                 return;
5981         } else
5982                 printf("\tBonding mode: %d\n", bonding_mode);
5983
5984         if (bonding_mode == BONDING_MODE_BALANCE) {
5985                 int balance_xmit_policy;
5986
5987                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5988                 if (balance_xmit_policy < 0) {
5989                         printf("\tFailed to get balance xmit policy for port = %d\n",
5990                                         port_id);
5991                         return;
5992                 } else {
5993                         printf("\tBalance Xmit Policy: ");
5994
5995                         switch (balance_xmit_policy) {
5996                         case BALANCE_XMIT_POLICY_LAYER2:
5997                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5998                                 break;
5999                         case BALANCE_XMIT_POLICY_LAYER23:
6000                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6001                                 break;
6002                         case BALANCE_XMIT_POLICY_LAYER34:
6003                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6004                                 break;
6005                         }
6006                         printf("\n");
6007                 }
6008         }
6009
6010         if (bonding_mode == BONDING_MODE_8023AD) {
6011                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6012                 printf("\tIEEE802.3AD Aggregator Mode: ");
6013                 switch (agg_mode) {
6014                 case AGG_BANDWIDTH:
6015                         printf("bandwidth");
6016                         break;
6017                 case AGG_STABLE:
6018                         printf("stable");
6019                         break;
6020                 case AGG_COUNT:
6021                         printf("count");
6022                         break;
6023                 }
6024                 printf("\n");
6025         }
6026
6027         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6028
6029         if (num_slaves < 0) {
6030                 printf("\tFailed to get slave list for port = %d\n", port_id);
6031                 return;
6032         }
6033         if (num_slaves > 0) {
6034                 printf("\tSlaves (%d): [", num_slaves);
6035                 for (i = 0; i < num_slaves - 1; i++)
6036                         printf("%d ", slaves[i]);
6037
6038                 printf("%d]\n", slaves[num_slaves - 1]);
6039         } else {
6040                 printf("\tSlaves: []\n");
6041
6042         }
6043
6044         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6045                         RTE_MAX_ETHPORTS);
6046
6047         if (num_active_slaves < 0) {
6048                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6049                 return;
6050         }
6051         if (num_active_slaves > 0) {
6052                 printf("\tActive Slaves (%d): [", num_active_slaves);
6053                 for (i = 0; i < num_active_slaves - 1; i++)
6054                         printf("%d ", slaves[i]);
6055
6056                 printf("%d]\n", slaves[num_active_slaves - 1]);
6057
6058         } else {
6059                 printf("\tActive Slaves: []\n");
6060
6061         }
6062
6063         primary_id = rte_eth_bond_primary_get(port_id);
6064         if (primary_id < 0) {
6065                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6066                 return;
6067         } else
6068                 printf("\tPrimary: [%d]\n", primary_id);
6069
6070 }
6071
6072 cmdline_parse_token_string_t cmd_showbonding_config_show =
6073 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6074                 show, "show");
6075 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6076 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6077                 bonding, "bonding");
6078 cmdline_parse_token_string_t cmd_showbonding_config_config =
6079 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6080                 config, "config");
6081 cmdline_parse_token_num_t cmd_showbonding_config_port =
6082 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6083                 port_id, RTE_UINT16);
6084
6085 cmdline_parse_inst_t cmd_show_bonding_config = {
6086                 .f = cmd_show_bonding_config_parsed,
6087                 .help_str = "show bonding config <port_id>: "
6088                         "Show the bonding config for port_id",
6089                 .data = NULL,
6090                 .tokens = {
6091                                 (void *)&cmd_showbonding_config_show,
6092                                 (void *)&cmd_showbonding_config_bonding,
6093                                 (void *)&cmd_showbonding_config_config,
6094                                 (void *)&cmd_showbonding_config_port,
6095                                 NULL
6096                 }
6097 };
6098
6099 /* *** SET BONDING PRIMARY *** */
6100 struct cmd_set_bonding_primary_result {
6101         cmdline_fixed_string_t set;
6102         cmdline_fixed_string_t bonding;
6103         cmdline_fixed_string_t primary;
6104         portid_t slave_id;
6105         portid_t port_id;
6106 };
6107
6108 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6109                 __rte_unused  struct cmdline *cl,
6110                 __rte_unused void *data)
6111 {
6112         struct cmd_set_bonding_primary_result *res = parsed_result;
6113         portid_t master_port_id = res->port_id;
6114         portid_t slave_port_id = res->slave_id;
6115
6116         /* Set the primary slave for a bonded device. */
6117         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6118                 printf("\t Failed to set primary slave for port = %d.\n",
6119                                 master_port_id);
6120                 return;
6121         }
6122         init_port_config();
6123 }
6124
6125 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6126 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6127                 set, "set");
6128 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6129 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6130                 bonding, "bonding");
6131 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6132 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6133                 primary, "primary");
6134 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6135 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6136                 slave_id, RTE_UINT16);
6137 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6138 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6139                 port_id, RTE_UINT16);
6140
6141 cmdline_parse_inst_t cmd_set_bonding_primary = {
6142                 .f = cmd_set_bonding_primary_parsed,
6143                 .help_str = "set bonding primary <slave_id> <port_id>: "
6144                         "Set the primary slave for port_id",
6145                 .data = NULL,
6146                 .tokens = {
6147                                 (void *)&cmd_setbonding_primary_set,
6148                                 (void *)&cmd_setbonding_primary_bonding,
6149                                 (void *)&cmd_setbonding_primary_primary,
6150                                 (void *)&cmd_setbonding_primary_slave,
6151                                 (void *)&cmd_setbonding_primary_port,
6152                                 NULL
6153                 }
6154 };
6155
6156 /* *** ADD SLAVE *** */
6157 struct cmd_add_bonding_slave_result {
6158         cmdline_fixed_string_t add;
6159         cmdline_fixed_string_t bonding;
6160         cmdline_fixed_string_t slave;
6161         portid_t slave_id;
6162         portid_t port_id;
6163 };
6164
6165 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6166                 __rte_unused  struct cmdline *cl,
6167                 __rte_unused void *data)
6168 {
6169         struct cmd_add_bonding_slave_result *res = parsed_result;
6170         portid_t master_port_id = res->port_id;
6171         portid_t slave_port_id = res->slave_id;
6172
6173         /* add the slave for a bonded device. */
6174         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6175                 printf("\t Failed to add slave %d to master port = %d.\n",
6176                                 slave_port_id, master_port_id);
6177                 return;
6178         }
6179         init_port_config();
6180         set_port_slave_flag(slave_port_id);
6181 }
6182
6183 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6184 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6185                 add, "add");
6186 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6187 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6188                 bonding, "bonding");
6189 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6190 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6191                 slave, "slave");
6192 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6193 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6194                 slave_id, RTE_UINT16);
6195 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6196 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6197                 port_id, RTE_UINT16);
6198
6199 cmdline_parse_inst_t cmd_add_bonding_slave = {
6200                 .f = cmd_add_bonding_slave_parsed,
6201                 .help_str = "add bonding slave <slave_id> <port_id>: "
6202                         "Add a slave device to a bonded device",
6203                 .data = NULL,
6204                 .tokens = {
6205                                 (void *)&cmd_addbonding_slave_add,
6206                                 (void *)&cmd_addbonding_slave_bonding,
6207                                 (void *)&cmd_addbonding_slave_slave,
6208                                 (void *)&cmd_addbonding_slave_slaveid,
6209                                 (void *)&cmd_addbonding_slave_port,
6210                                 NULL
6211                 }
6212 };
6213
6214 /* *** REMOVE SLAVE *** */
6215 struct cmd_remove_bonding_slave_result {
6216         cmdline_fixed_string_t remove;
6217         cmdline_fixed_string_t bonding;
6218         cmdline_fixed_string_t slave;
6219         portid_t slave_id;
6220         portid_t port_id;
6221 };
6222
6223 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6224                 __rte_unused  struct cmdline *cl,
6225                 __rte_unused void *data)
6226 {
6227         struct cmd_remove_bonding_slave_result *res = parsed_result;
6228         portid_t master_port_id = res->port_id;
6229         portid_t slave_port_id = res->slave_id;
6230
6231         /* remove the slave from a bonded device. */
6232         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6233                 printf("\t Failed to remove slave %d from master port = %d.\n",
6234                                 slave_port_id, master_port_id);
6235                 return;
6236         }
6237         init_port_config();
6238         clear_port_slave_flag(slave_port_id);
6239 }
6240
6241 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6243                                 remove, "remove");
6244 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6246                                 bonding, "bonding");
6247 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6248                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6249                                 slave, "slave");
6250 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6251                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6252                                 slave_id, RTE_UINT16);
6253 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6254                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6255                                 port_id, RTE_UINT16);
6256
6257 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6258                 .f = cmd_remove_bonding_slave_parsed,
6259                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6260                         "Remove a slave device from a bonded device",
6261                 .data = NULL,
6262                 .tokens = {
6263                                 (void *)&cmd_removebonding_slave_remove,
6264                                 (void *)&cmd_removebonding_slave_bonding,
6265                                 (void *)&cmd_removebonding_slave_slave,
6266                                 (void *)&cmd_removebonding_slave_slaveid,
6267                                 (void *)&cmd_removebonding_slave_port,
6268                                 NULL
6269                 }
6270 };
6271
6272 /* *** CREATE BONDED DEVICE *** */
6273 struct cmd_create_bonded_device_result {
6274         cmdline_fixed_string_t create;
6275         cmdline_fixed_string_t bonded;
6276         cmdline_fixed_string_t device;
6277         uint8_t mode;
6278         uint8_t socket;
6279 };
6280
6281 static int bond_dev_num = 0;
6282
6283 static void cmd_create_bonded_device_parsed(void *parsed_result,
6284                 __rte_unused  struct cmdline *cl,
6285                 __rte_unused void *data)
6286 {
6287         struct cmd_create_bonded_device_result *res = parsed_result;
6288         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6289         int port_id;
6290         int ret;
6291
6292         if (test_done == 0) {
6293                 printf("Please stop forwarding first\n");
6294                 return;
6295         }
6296
6297         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6298                         bond_dev_num++);
6299
6300         /* Create a new bonded device. */
6301         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6302         if (port_id < 0) {
6303                 printf("\t Failed to create bonded device.\n");
6304                 return;
6305         } else {
6306                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6307                                 port_id);
6308
6309                 /* Update number of ports */
6310                 nb_ports = rte_eth_dev_count_avail();
6311                 reconfig(port_id, res->socket);
6312                 ret = rte_eth_promiscuous_enable(port_id);
6313                 if (ret != 0)
6314                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6315                                 port_id, rte_strerror(-ret));
6316
6317                 ports[port_id].need_setup = 0;
6318                 ports[port_id].port_status = RTE_PORT_STOPPED;
6319         }
6320
6321 }
6322
6323 cmdline_parse_token_string_t cmd_createbonded_device_create =
6324                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6325                                 create, "create");
6326 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6327                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6328                                 bonded, "bonded");
6329 cmdline_parse_token_string_t cmd_createbonded_device_device =
6330                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6331                                 device, "device");
6332 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6333                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6334                                 mode, RTE_UINT8);
6335 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6336                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6337                                 socket, RTE_UINT8);
6338
6339 cmdline_parse_inst_t cmd_create_bonded_device = {
6340                 .f = cmd_create_bonded_device_parsed,
6341                 .help_str = "create bonded device <mode> <socket>: "
6342                         "Create a new bonded device with specific bonding mode and socket",
6343                 .data = NULL,
6344                 .tokens = {
6345                                 (void *)&cmd_createbonded_device_create,
6346                                 (void *)&cmd_createbonded_device_bonded,
6347                                 (void *)&cmd_createbonded_device_device,
6348                                 (void *)&cmd_createbonded_device_mode,
6349                                 (void *)&cmd_createbonded_device_socket,
6350                                 NULL
6351                 }
6352 };
6353
6354 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6355 struct cmd_set_bond_mac_addr_result {
6356         cmdline_fixed_string_t set;
6357         cmdline_fixed_string_t bonding;
6358         cmdline_fixed_string_t mac_addr;
6359         uint16_t port_num;
6360         struct rte_ether_addr address;
6361 };
6362
6363 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6364                 __rte_unused  struct cmdline *cl,
6365                 __rte_unused void *data)
6366 {
6367         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6368         int ret;
6369
6370         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6371                 return;
6372
6373         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6374
6375         /* check the return value and print it if is < 0 */
6376         if (ret < 0)
6377                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6378 }
6379
6380 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6381                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6382 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6383                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6384                                 "bonding");
6385 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6386                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6387                                 "mac_addr");
6388 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6389                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6390                                 port_num, RTE_UINT16);
6391 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6392                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6393
6394 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6395                 .f = cmd_set_bond_mac_addr_parsed,
6396                 .data = (void *) 0,
6397                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6398                 .tokens = {
6399                                 (void *)&cmd_set_bond_mac_addr_set,
6400                                 (void *)&cmd_set_bond_mac_addr_bonding,
6401                                 (void *)&cmd_set_bond_mac_addr_mac,
6402                                 (void *)&cmd_set_bond_mac_addr_portnum,
6403                                 (void *)&cmd_set_bond_mac_addr_addr,
6404                                 NULL
6405                 }
6406 };
6407
6408
6409 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6410 struct cmd_set_bond_mon_period_result {
6411         cmdline_fixed_string_t set;
6412         cmdline_fixed_string_t bonding;
6413         cmdline_fixed_string_t mon_period;
6414         uint16_t port_num;
6415         uint32_t period_ms;
6416 };
6417
6418 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6419                 __rte_unused  struct cmdline *cl,
6420                 __rte_unused void *data)
6421 {
6422         struct cmd_set_bond_mon_period_result *res = parsed_result;
6423         int ret;
6424
6425         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6426
6427         /* check the return value and print it if is < 0 */
6428         if (ret < 0)
6429                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6430 }
6431
6432 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6433                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6434                                 set, "set");
6435 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6436                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6437                                 bonding, "bonding");
6438 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6439                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6440                                 mon_period,     "mon_period");
6441 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6442                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6443                                 port_num, RTE_UINT16);
6444 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6445                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6446                                 period_ms, RTE_UINT32);
6447
6448 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6449                 .f = cmd_set_bond_mon_period_parsed,
6450                 .data = (void *) 0,
6451                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6452                 .tokens = {
6453                                 (void *)&cmd_set_bond_mon_period_set,
6454                                 (void *)&cmd_set_bond_mon_period_bonding,
6455                                 (void *)&cmd_set_bond_mon_period_mon_period,
6456                                 (void *)&cmd_set_bond_mon_period_portnum,
6457                                 (void *)&cmd_set_bond_mon_period_period_ms,
6458                                 NULL
6459                 }
6460 };
6461
6462
6463
6464 struct cmd_set_bonding_agg_mode_policy_result {
6465         cmdline_fixed_string_t set;
6466         cmdline_fixed_string_t bonding;
6467         cmdline_fixed_string_t agg_mode;
6468         uint16_t port_num;
6469         cmdline_fixed_string_t policy;
6470 };
6471
6472
6473 static void
6474 cmd_set_bonding_agg_mode(void *parsed_result,
6475                 __rte_unused struct cmdline *cl,
6476                 __rte_unused void *data)
6477 {
6478         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6479         uint8_t policy = AGG_BANDWIDTH;
6480
6481         if (!strcmp(res->policy, "bandwidth"))
6482                 policy = AGG_BANDWIDTH;
6483         else if (!strcmp(res->policy, "stable"))
6484                 policy = AGG_STABLE;
6485         else if (!strcmp(res->policy, "count"))
6486                 policy = AGG_COUNT;
6487
6488         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6489 }
6490
6491
6492 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6493         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6494                                 set, "set");
6495 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6497                                 bonding, "bonding");
6498
6499 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6501                                 agg_mode, "agg_mode");
6502
6503 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6504         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6505                                 port_num, RTE_UINT16);
6506
6507 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6508         TOKEN_STRING_INITIALIZER(
6509                         struct cmd_set_bonding_balance_xmit_policy_result,
6510                 policy, "stable#bandwidth#count");
6511
6512 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6513         .f = cmd_set_bonding_agg_mode,
6514         .data = (void *) 0,
6515         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6516         .tokens = {
6517                         (void *)&cmd_set_bonding_agg_mode_set,
6518                         (void *)&cmd_set_bonding_agg_mode_bonding,
6519                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6520                         (void *)&cmd_set_bonding_agg_mode_portnum,
6521                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6522                         NULL
6523                 }
6524 };
6525
6526
6527 #endif /* RTE_NET_BOND */
6528
6529 /* *** SET FORWARDING MODE *** */
6530 struct cmd_set_fwd_mode_result {
6531         cmdline_fixed_string_t set;
6532         cmdline_fixed_string_t fwd;
6533         cmdline_fixed_string_t mode;
6534 };
6535
6536 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6537                                     __rte_unused struct cmdline *cl,
6538                                     __rte_unused void *data)
6539 {
6540         struct cmd_set_fwd_mode_result *res = parsed_result;
6541
6542         retry_enabled = 0;
6543         set_pkt_forwarding_mode(res->mode);
6544 }
6545
6546 cmdline_parse_token_string_t cmd_setfwd_set =
6547         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6548 cmdline_parse_token_string_t cmd_setfwd_fwd =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6550 cmdline_parse_token_string_t cmd_setfwd_mode =
6551         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6552                 "" /* defined at init */);
6553
6554 cmdline_parse_inst_t cmd_set_fwd_mode = {
6555         .f = cmd_set_fwd_mode_parsed,
6556         .data = NULL,
6557         .help_str = NULL, /* defined at init */
6558         .tokens = {
6559                 (void *)&cmd_setfwd_set,
6560                 (void *)&cmd_setfwd_fwd,
6561                 (void *)&cmd_setfwd_mode,
6562                 NULL,
6563         },
6564 };
6565
6566 static void cmd_set_fwd_mode_init(void)
6567 {
6568         char *modes, *c;
6569         static char token[128];
6570         static char help[256];
6571         cmdline_parse_token_string_t *token_struct;
6572
6573         modes = list_pkt_forwarding_modes();
6574         snprintf(help, sizeof(help), "set fwd %s: "
6575                 "Set packet forwarding mode", modes);
6576         cmd_set_fwd_mode.help_str = help;
6577
6578         /* string token separator is # */
6579         for (c = token; *modes != '\0'; modes++)
6580                 if (*modes == '|')
6581                         *c++ = '#';
6582                 else
6583                         *c++ = *modes;
6584         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6585         token_struct->string_data.str = token;
6586 }
6587
6588 /* *** SET RETRY FORWARDING MODE *** */
6589 struct cmd_set_fwd_retry_mode_result {
6590         cmdline_fixed_string_t set;
6591         cmdline_fixed_string_t fwd;
6592         cmdline_fixed_string_t mode;
6593         cmdline_fixed_string_t retry;
6594 };
6595
6596 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6597                             __rte_unused struct cmdline *cl,
6598                             __rte_unused void *data)
6599 {
6600         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6601
6602         retry_enabled = 1;
6603         set_pkt_forwarding_mode(res->mode);
6604 }
6605
6606 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6608                         set, "set");
6609 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6610         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6611                         fwd, "fwd");
6612 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6613         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6614                         mode,
6615                 "" /* defined at init */);
6616 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6617         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6618                         retry, "retry");
6619
6620 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6621         .f = cmd_set_fwd_retry_mode_parsed,
6622         .data = NULL,
6623         .help_str = NULL, /* defined at init */
6624         .tokens = {
6625                 (void *)&cmd_setfwd_retry_set,
6626                 (void *)&cmd_setfwd_retry_fwd,
6627                 (void *)&cmd_setfwd_retry_mode,
6628                 (void *)&cmd_setfwd_retry_retry,
6629                 NULL,
6630         },
6631 };
6632
6633 static void cmd_set_fwd_retry_mode_init(void)
6634 {
6635         char *modes, *c;
6636         static char token[128];
6637         static char help[256];
6638         cmdline_parse_token_string_t *token_struct;
6639
6640         modes = list_pkt_forwarding_retry_modes();
6641         snprintf(help, sizeof(help), "set fwd %s retry: "
6642                 "Set packet forwarding mode with retry", modes);
6643         cmd_set_fwd_retry_mode.help_str = help;
6644
6645         /* string token separator is # */
6646         for (c = token; *modes != '\0'; modes++)
6647                 if (*modes == '|')
6648                         *c++ = '#';
6649                 else
6650                         *c++ = *modes;
6651         token_struct = (cmdline_parse_token_string_t *)
6652                 cmd_set_fwd_retry_mode.tokens[2];
6653         token_struct->string_data.str = token;
6654 }
6655
6656 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6657 struct cmd_set_burst_tx_retry_result {
6658         cmdline_fixed_string_t set;
6659         cmdline_fixed_string_t burst;
6660         cmdline_fixed_string_t tx;
6661         cmdline_fixed_string_t delay;
6662         uint32_t time;
6663         cmdline_fixed_string_t retry;
6664         uint32_t retry_num;
6665 };
6666
6667 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6668                                         __rte_unused struct cmdline *cl,
6669                                         __rte_unused void *data)
6670 {
6671         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6672
6673         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6674                 && !strcmp(res->tx, "tx")) {
6675                 if (!strcmp(res->delay, "delay"))
6676                         burst_tx_delay_time = res->time;
6677                 if (!strcmp(res->retry, "retry"))
6678                         burst_tx_retry_num = res->retry_num;
6679         }
6680
6681 }
6682
6683 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6685 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6686         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6687                                  "burst");
6688 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6689         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6690 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6692 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6693         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6694                                  RTE_UINT32);
6695 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6696         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6697 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6698         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6699                                  RTE_UINT32);
6700
6701 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6702         .f = cmd_set_burst_tx_retry_parsed,
6703         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6704         .tokens = {
6705                 (void *)&cmd_set_burst_tx_retry_set,
6706                 (void *)&cmd_set_burst_tx_retry_burst,
6707                 (void *)&cmd_set_burst_tx_retry_tx,
6708                 (void *)&cmd_set_burst_tx_retry_delay,
6709                 (void *)&cmd_set_burst_tx_retry_time,
6710                 (void *)&cmd_set_burst_tx_retry_retry,
6711                 (void *)&cmd_set_burst_tx_retry_retry_num,
6712                 NULL,
6713         },
6714 };
6715
6716 /* *** SET PROMISC MODE *** */
6717 struct cmd_set_promisc_mode_result {
6718         cmdline_fixed_string_t set;
6719         cmdline_fixed_string_t promisc;
6720         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6721         uint16_t port_num;               /* valid if "allports" argument == 0 */
6722         cmdline_fixed_string_t mode;
6723 };
6724
6725 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6726                                         __rte_unused struct cmdline *cl,
6727                                         void *allports)
6728 {
6729         struct cmd_set_promisc_mode_result *res = parsed_result;
6730         int enable;
6731         portid_t i;
6732
6733         if (!strcmp(res->mode, "on"))
6734                 enable = 1;
6735         else
6736                 enable = 0;
6737
6738         /* all ports */
6739         if (allports) {
6740                 RTE_ETH_FOREACH_DEV(i)
6741                         eth_set_promisc_mode(i, enable);
6742         } else {
6743                 eth_set_promisc_mode(res->port_num, enable);
6744         }
6745 }
6746
6747 cmdline_parse_token_string_t cmd_setpromisc_set =
6748         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6749 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6750         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6751                                  "promisc");
6752 cmdline_parse_token_string_t cmd_setpromisc_portall =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6754                                  "all");
6755 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6756         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6757                               RTE_UINT16);
6758 cmdline_parse_token_string_t cmd_setpromisc_mode =
6759         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6760                                  "on#off");
6761
6762 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6763         .f = cmd_set_promisc_mode_parsed,
6764         .data = (void *)1,
6765         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6766         .tokens = {
6767                 (void *)&cmd_setpromisc_set,
6768                 (void *)&cmd_setpromisc_promisc,
6769                 (void *)&cmd_setpromisc_portall,
6770                 (void *)&cmd_setpromisc_mode,
6771                 NULL,
6772         },
6773 };
6774
6775 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6776         .f = cmd_set_promisc_mode_parsed,
6777         .data = (void *)0,
6778         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6779         .tokens = {
6780                 (void *)&cmd_setpromisc_set,
6781                 (void *)&cmd_setpromisc_promisc,
6782                 (void *)&cmd_setpromisc_portnum,
6783                 (void *)&cmd_setpromisc_mode,
6784                 NULL,
6785         },
6786 };
6787
6788 /* *** SET ALLMULTI MODE *** */
6789 struct cmd_set_allmulti_mode_result {
6790         cmdline_fixed_string_t set;
6791         cmdline_fixed_string_t allmulti;
6792         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6793         uint16_t port_num;               /* valid if "allports" argument == 0 */
6794         cmdline_fixed_string_t mode;
6795 };
6796
6797 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6798                                         __rte_unused struct cmdline *cl,
6799                                         void *allports)
6800 {
6801         struct cmd_set_allmulti_mode_result *res = parsed_result;
6802         int enable;
6803         portid_t i;
6804
6805         if (!strcmp(res->mode, "on"))
6806                 enable = 1;
6807         else
6808                 enable = 0;
6809
6810         /* all ports */
6811         if (allports) {
6812                 RTE_ETH_FOREACH_DEV(i) {
6813                         eth_set_allmulticast_mode(i, enable);
6814                 }
6815         }
6816         else {
6817                 eth_set_allmulticast_mode(res->port_num, enable);
6818         }
6819 }
6820
6821 cmdline_parse_token_string_t cmd_setallmulti_set =
6822         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6823 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6824         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6825                                  "allmulti");
6826 cmdline_parse_token_string_t cmd_setallmulti_portall =
6827         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6828                                  "all");
6829 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6830         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6831                               RTE_UINT16);
6832 cmdline_parse_token_string_t cmd_setallmulti_mode =
6833         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6834                                  "on#off");
6835
6836 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6837         .f = cmd_set_allmulti_mode_parsed,
6838         .data = (void *)1,
6839         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6840         .tokens = {
6841                 (void *)&cmd_setallmulti_set,
6842                 (void *)&cmd_setallmulti_allmulti,
6843                 (void *)&cmd_setallmulti_portall,
6844                 (void *)&cmd_setallmulti_mode,
6845                 NULL,
6846         },
6847 };
6848
6849 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6850         .f = cmd_set_allmulti_mode_parsed,
6851         .data = (void *)0,
6852         .help_str = "set allmulti <port_id> on|off: "
6853                 "Set allmulti mode on port_id",
6854         .tokens = {
6855                 (void *)&cmd_setallmulti_set,
6856                 (void *)&cmd_setallmulti_allmulti,
6857                 (void *)&cmd_setallmulti_portnum,
6858                 (void *)&cmd_setallmulti_mode,
6859                 NULL,
6860         },
6861 };
6862
6863 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6864 struct cmd_link_flow_ctrl_set_result {
6865         cmdline_fixed_string_t set;
6866         cmdline_fixed_string_t flow_ctrl;
6867         cmdline_fixed_string_t rx;
6868         cmdline_fixed_string_t rx_lfc_mode;
6869         cmdline_fixed_string_t tx;
6870         cmdline_fixed_string_t tx_lfc_mode;
6871         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6872         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6873         cmdline_fixed_string_t autoneg_str;
6874         cmdline_fixed_string_t autoneg;
6875         cmdline_fixed_string_t hw_str;
6876         uint32_t high_water;
6877         cmdline_fixed_string_t lw_str;
6878         uint32_t low_water;
6879         cmdline_fixed_string_t pt_str;
6880         uint16_t pause_time;
6881         cmdline_fixed_string_t xon_str;
6882         uint16_t send_xon;
6883         portid_t port_id;
6884 };
6885
6886 cmdline_parse_token_string_t cmd_lfc_set_set =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 set, "set");
6889 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 flow_ctrl, "flow_ctrl");
6892 cmdline_parse_token_string_t cmd_lfc_set_rx =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 rx, "rx");
6895 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 rx_lfc_mode, "on#off");
6898 cmdline_parse_token_string_t cmd_lfc_set_tx =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 tx, "tx");
6901 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 tx_lfc_mode, "on#off");
6904 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 hw_str, "high_water");
6907 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 high_water, RTE_UINT32);
6910 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 lw_str, "low_water");
6913 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6914         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 low_water, RTE_UINT32);
6916 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 pt_str, "pause_time");
6919 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6920         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 pause_time, RTE_UINT16);
6922 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 xon_str, "send_xon");
6925 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6926         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 send_xon, RTE_UINT16);
6928 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6929         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6931 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6933                                 mac_ctrl_frame_fwd_mode, "on#off");
6934 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6935         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6936                                 autoneg_str, "autoneg");
6937 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6938         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6939                                 autoneg, "on#off");
6940 cmdline_parse_token_num_t cmd_lfc_set_portid =
6941         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6942                                 port_id, RTE_UINT16);
6943
6944 /* forward declaration */
6945 static void
6946 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6947                               void *data);
6948
6949 cmdline_parse_inst_t cmd_link_flow_control_set = {
6950         .f = cmd_link_flow_ctrl_set_parsed,
6951         .data = NULL,
6952         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6953                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6954                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6955         .tokens = {
6956                 (void *)&cmd_lfc_set_set,
6957                 (void *)&cmd_lfc_set_flow_ctrl,
6958                 (void *)&cmd_lfc_set_rx,
6959                 (void *)&cmd_lfc_set_rx_mode,
6960                 (void *)&cmd_lfc_set_tx,
6961                 (void *)&cmd_lfc_set_tx_mode,
6962                 (void *)&cmd_lfc_set_high_water,
6963                 (void *)&cmd_lfc_set_low_water,
6964                 (void *)&cmd_lfc_set_pause_time,
6965                 (void *)&cmd_lfc_set_send_xon,
6966                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6967                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6968                 (void *)&cmd_lfc_set_autoneg_str,
6969                 (void *)&cmd_lfc_set_autoneg,
6970                 (void *)&cmd_lfc_set_portid,
6971                 NULL,
6972         },
6973 };
6974
6975 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6976         .f = cmd_link_flow_ctrl_set_parsed,
6977         .data = (void *)&cmd_link_flow_control_set_rx,
6978         .help_str = "set flow_ctrl rx on|off <port_id>: "
6979                 "Change rx flow control parameter",
6980         .tokens = {
6981                 (void *)&cmd_lfc_set_set,
6982                 (void *)&cmd_lfc_set_flow_ctrl,
6983                 (void *)&cmd_lfc_set_rx,
6984                 (void *)&cmd_lfc_set_rx_mode,
6985                 (void *)&cmd_lfc_set_portid,
6986                 NULL,
6987         },
6988 };
6989
6990 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6991         .f = cmd_link_flow_ctrl_set_parsed,
6992         .data = (void *)&cmd_link_flow_control_set_tx,
6993         .help_str = "set flow_ctrl tx on|off <port_id>: "
6994                 "Change tx flow control parameter",
6995         .tokens = {
6996                 (void *)&cmd_lfc_set_set,
6997                 (void *)&cmd_lfc_set_flow_ctrl,
6998                 (void *)&cmd_lfc_set_tx,
6999                 (void *)&cmd_lfc_set_tx_mode,
7000                 (void *)&cmd_lfc_set_portid,
7001                 NULL,
7002         },
7003 };
7004
7005 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7006         .f = cmd_link_flow_ctrl_set_parsed,
7007         .data = (void *)&cmd_link_flow_control_set_hw,
7008         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7009                 "Change high water flow control parameter",
7010         .tokens = {
7011                 (void *)&cmd_lfc_set_set,
7012                 (void *)&cmd_lfc_set_flow_ctrl,
7013                 (void *)&cmd_lfc_set_high_water_str,
7014                 (void *)&cmd_lfc_set_high_water,
7015                 (void *)&cmd_lfc_set_portid,
7016                 NULL,
7017         },
7018 };
7019
7020 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7021         .f = cmd_link_flow_ctrl_set_parsed,
7022         .data = (void *)&cmd_link_flow_control_set_lw,
7023         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7024                 "Change low water flow control parameter",
7025         .tokens = {
7026                 (void *)&cmd_lfc_set_set,
7027                 (void *)&cmd_lfc_set_flow_ctrl,
7028                 (void *)&cmd_lfc_set_low_water_str,
7029                 (void *)&cmd_lfc_set_low_water,
7030                 (void *)&cmd_lfc_set_portid,
7031                 NULL,
7032         },
7033 };
7034
7035 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7036         .f = cmd_link_flow_ctrl_set_parsed,
7037         .data = (void *)&cmd_link_flow_control_set_pt,
7038         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7039                 "Change pause time flow control parameter",
7040         .tokens = {
7041                 (void *)&cmd_lfc_set_set,
7042                 (void *)&cmd_lfc_set_flow_ctrl,
7043                 (void *)&cmd_lfc_set_pause_time_str,
7044                 (void *)&cmd_lfc_set_pause_time,
7045                 (void *)&cmd_lfc_set_portid,
7046                 NULL,
7047         },
7048 };
7049
7050 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7051         .f = cmd_link_flow_ctrl_set_parsed,
7052         .data = (void *)&cmd_link_flow_control_set_xon,
7053         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7054                 "Change send_xon flow control parameter",
7055         .tokens = {
7056                 (void *)&cmd_lfc_set_set,
7057                 (void *)&cmd_lfc_set_flow_ctrl,
7058                 (void *)&cmd_lfc_set_send_xon_str,
7059                 (void *)&cmd_lfc_set_send_xon,
7060                 (void *)&cmd_lfc_set_portid,
7061                 NULL,
7062         },
7063 };
7064
7065 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7066         .f = cmd_link_flow_ctrl_set_parsed,
7067         .data = (void *)&cmd_link_flow_control_set_macfwd,
7068         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7069                 "Change mac ctrl fwd flow control parameter",
7070         .tokens = {
7071                 (void *)&cmd_lfc_set_set,
7072                 (void *)&cmd_lfc_set_flow_ctrl,
7073                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7074                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7075                 (void *)&cmd_lfc_set_portid,
7076                 NULL,
7077         },
7078 };
7079
7080 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7081         .f = cmd_link_flow_ctrl_set_parsed,
7082         .data = (void *)&cmd_link_flow_control_set_autoneg,
7083         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7084                 "Change autoneg flow control parameter",
7085         .tokens = {
7086                 (void *)&cmd_lfc_set_set,
7087                 (void *)&cmd_lfc_set_flow_ctrl,
7088                 (void *)&cmd_lfc_set_autoneg_str,
7089                 (void *)&cmd_lfc_set_autoneg,
7090                 (void *)&cmd_lfc_set_portid,
7091                 NULL,
7092         },
7093 };
7094
7095 static void
7096 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7097                               __rte_unused struct cmdline *cl,
7098                               void *data)
7099 {
7100         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7101         cmdline_parse_inst_t *cmd = data;
7102         struct rte_eth_fc_conf fc_conf;
7103         int rx_fc_en = 0;
7104         int tx_fc_en = 0;
7105         int ret;
7106
7107         /*
7108          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7109          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7110          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7111          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7112          */
7113         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7114                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7115         };
7116
7117         /* Partial command line, retrieve current configuration */
7118         if (cmd) {
7119                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7120                 if (ret != 0) {
7121                         printf("cannot get current flow ctrl parameters, return"
7122                                "code = %d\n", ret);
7123                         return;
7124                 }
7125
7126                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7127                     (fc_conf.mode == RTE_FC_FULL))
7128                         rx_fc_en = 1;
7129                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7130                     (fc_conf.mode == RTE_FC_FULL))
7131                         tx_fc_en = 1;
7132         }
7133
7134         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7135                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7136
7137         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7138                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7139
7140         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7141
7142         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7143                 fc_conf.high_water = res->high_water;
7144
7145         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7146                 fc_conf.low_water = res->low_water;
7147
7148         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7149                 fc_conf.pause_time = res->pause_time;
7150
7151         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7152                 fc_conf.send_xon = res->send_xon;
7153
7154         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7155                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7156                         fc_conf.mac_ctrl_frame_fwd = 1;
7157                 else
7158                         fc_conf.mac_ctrl_frame_fwd = 0;
7159         }
7160
7161         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7162                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7163
7164         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7165         if (ret != 0)
7166                 printf("bad flow contrl parameter, return code = %d \n", ret);
7167 }
7168
7169 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7170 struct cmd_priority_flow_ctrl_set_result {
7171         cmdline_fixed_string_t set;
7172         cmdline_fixed_string_t pfc_ctrl;
7173         cmdline_fixed_string_t rx;
7174         cmdline_fixed_string_t rx_pfc_mode;
7175         cmdline_fixed_string_t tx;
7176         cmdline_fixed_string_t tx_pfc_mode;
7177         uint32_t high_water;
7178         uint32_t low_water;
7179         uint16_t pause_time;
7180         uint8_t  priority;
7181         portid_t port_id;
7182 };
7183
7184 static void
7185 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7186                        __rte_unused struct cmdline *cl,
7187                        __rte_unused void *data)
7188 {
7189         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7190         struct rte_eth_pfc_conf pfc_conf;
7191         int rx_fc_enable, tx_fc_enable;
7192         int ret;
7193
7194         /*
7195          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7196          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7197          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7198          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7199          */
7200         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7201                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7202         };
7203
7204         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7205         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7206         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7207         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7208         pfc_conf.fc.high_water = res->high_water;
7209         pfc_conf.fc.low_water  = res->low_water;
7210         pfc_conf.fc.pause_time = res->pause_time;
7211         pfc_conf.priority      = res->priority;
7212
7213         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7214         if (ret != 0)
7215                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7216 }
7217
7218 cmdline_parse_token_string_t cmd_pfc_set_set =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 set, "set");
7221 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7222         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 pfc_ctrl, "pfc_ctrl");
7224 cmdline_parse_token_string_t cmd_pfc_set_rx =
7225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 rx, "rx");
7227 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 rx_pfc_mode, "on#off");
7230 cmdline_parse_token_string_t cmd_pfc_set_tx =
7231         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 tx, "tx");
7233 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7234         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 tx_pfc_mode, "on#off");
7236 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7237         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 high_water, RTE_UINT32);
7239 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7240         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7241                                 low_water, RTE_UINT32);
7242 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7244                                 pause_time, RTE_UINT16);
7245 cmdline_parse_token_num_t cmd_pfc_set_priority =
7246         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7247                                 priority, RTE_UINT8);
7248 cmdline_parse_token_num_t cmd_pfc_set_portid =
7249         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7250                                 port_id, RTE_UINT16);
7251
7252 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7253         .f = cmd_priority_flow_ctrl_set_parsed,
7254         .data = NULL,
7255         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7256                 "<pause_time> <priority> <port_id>: "
7257                 "Configure the Ethernet priority flow control",
7258         .tokens = {
7259                 (void *)&cmd_pfc_set_set,
7260                 (void *)&cmd_pfc_set_flow_ctrl,
7261                 (void *)&cmd_pfc_set_rx,
7262                 (void *)&cmd_pfc_set_rx_mode,
7263                 (void *)&cmd_pfc_set_tx,
7264                 (void *)&cmd_pfc_set_tx_mode,
7265                 (void *)&cmd_pfc_set_high_water,
7266                 (void *)&cmd_pfc_set_low_water,
7267                 (void *)&cmd_pfc_set_pause_time,
7268                 (void *)&cmd_pfc_set_priority,
7269                 (void *)&cmd_pfc_set_portid,
7270                 NULL,
7271         },
7272 };
7273
7274 /* *** RESET CONFIGURATION *** */
7275 struct cmd_reset_result {
7276         cmdline_fixed_string_t reset;
7277         cmdline_fixed_string_t def;
7278 };
7279
7280 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7281                              struct cmdline *cl,
7282                              __rte_unused void *data)
7283 {
7284         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7285         set_def_fwd_config();
7286 }
7287
7288 cmdline_parse_token_string_t cmd_reset_set =
7289         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7290 cmdline_parse_token_string_t cmd_reset_def =
7291         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7292                                  "default");
7293
7294 cmdline_parse_inst_t cmd_reset = {
7295         .f = cmd_reset_parsed,
7296         .data = NULL,
7297         .help_str = "set default: Reset default forwarding configuration",
7298         .tokens = {
7299                 (void *)&cmd_reset_set,
7300                 (void *)&cmd_reset_def,
7301                 NULL,
7302         },
7303 };
7304
7305 /* *** START FORWARDING *** */
7306 struct cmd_start_result {
7307         cmdline_fixed_string_t start;
7308 };
7309
7310 cmdline_parse_token_string_t cmd_start_start =
7311         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7312
7313 static void cmd_start_parsed(__rte_unused void *parsed_result,
7314                              __rte_unused struct cmdline *cl,
7315                              __rte_unused void *data)
7316 {
7317         start_packet_forwarding(0);
7318 }
7319
7320 cmdline_parse_inst_t cmd_start = {
7321         .f = cmd_start_parsed,
7322         .data = NULL,
7323         .help_str = "start: Start packet forwarding",
7324         .tokens = {
7325                 (void *)&cmd_start_start,
7326                 NULL,
7327         },
7328 };
7329
7330 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7331 struct cmd_start_tx_first_result {
7332         cmdline_fixed_string_t start;
7333         cmdline_fixed_string_t tx_first;
7334 };
7335
7336 static void
7337 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7338                           __rte_unused struct cmdline *cl,
7339                           __rte_unused void *data)
7340 {
7341         start_packet_forwarding(1);
7342 }
7343
7344 cmdline_parse_token_string_t cmd_start_tx_first_start =
7345         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7346                                  "start");
7347 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7348         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7349                                  tx_first, "tx_first");
7350
7351 cmdline_parse_inst_t cmd_start_tx_first = {
7352         .f = cmd_start_tx_first_parsed,
7353         .data = NULL,
7354         .help_str = "start tx_first: Start packet forwarding, "
7355                 "after sending 1 burst of packets",
7356         .tokens = {
7357                 (void *)&cmd_start_tx_first_start,
7358                 (void *)&cmd_start_tx_first_tx_first,
7359                 NULL,
7360         },
7361 };
7362
7363 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7364 struct cmd_start_tx_first_n_result {
7365         cmdline_fixed_string_t start;
7366         cmdline_fixed_string_t tx_first;
7367         uint32_t tx_num;
7368 };
7369
7370 static void
7371 cmd_start_tx_first_n_parsed(void *parsed_result,
7372                           __rte_unused struct cmdline *cl,
7373                           __rte_unused void *data)
7374 {
7375         struct cmd_start_tx_first_n_result *res = parsed_result;
7376
7377         start_packet_forwarding(res->tx_num);
7378 }
7379
7380 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7381         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7382                         start, "start");
7383 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7384         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7385                         tx_first, "tx_first");
7386 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7387         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7388                         tx_num, RTE_UINT32);
7389
7390 cmdline_parse_inst_t cmd_start_tx_first_n = {
7391         .f = cmd_start_tx_first_n_parsed,
7392         .data = NULL,
7393         .help_str = "start tx_first <num>: "
7394                 "packet forwarding, after sending <num> bursts of packets",
7395         .tokens = {
7396                 (void *)&cmd_start_tx_first_n_start,
7397                 (void *)&cmd_start_tx_first_n_tx_first,
7398                 (void *)&cmd_start_tx_first_n_tx_num,
7399                 NULL,
7400         },
7401 };
7402
7403 /* *** SET LINK UP *** */
7404 struct cmd_set_link_up_result {
7405         cmdline_fixed_string_t set;
7406         cmdline_fixed_string_t link_up;
7407         cmdline_fixed_string_t port;
7408         portid_t port_id;
7409 };
7410
7411 cmdline_parse_token_string_t cmd_set_link_up_set =
7412         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7413 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7414         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7415                                 "link-up");
7416 cmdline_parse_token_string_t cmd_set_link_up_port =
7417         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7418 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7419         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7420                                 RTE_UINT16);
7421
7422 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7423                              __rte_unused struct cmdline *cl,
7424                              __rte_unused void *data)
7425 {
7426         struct cmd_set_link_up_result *res = parsed_result;
7427         dev_set_link_up(res->port_id);
7428 }
7429
7430 cmdline_parse_inst_t cmd_set_link_up = {
7431         .f = cmd_set_link_up_parsed,
7432         .data = NULL,
7433         .help_str = "set link-up port <port id>",
7434         .tokens = {
7435                 (void *)&cmd_set_link_up_set,
7436                 (void *)&cmd_set_link_up_link_up,
7437                 (void *)&cmd_set_link_up_port,
7438                 (void *)&cmd_set_link_up_port_id,
7439                 NULL,
7440         },
7441 };
7442
7443 /* *** SET LINK DOWN *** */
7444 struct cmd_set_link_down_result {
7445         cmdline_fixed_string_t set;
7446         cmdline_fixed_string_t link_down;
7447         cmdline_fixed_string_t port;
7448         portid_t port_id;
7449 };
7450
7451 cmdline_parse_token_string_t cmd_set_link_down_set =
7452         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7453 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7454         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7455                                 "link-down");
7456 cmdline_parse_token_string_t cmd_set_link_down_port =
7457         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7458 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7459         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7460                                 RTE_UINT16);
7461
7462 static void cmd_set_link_down_parsed(
7463                                 __rte_unused void *parsed_result,
7464                                 __rte_unused struct cmdline *cl,
7465                                 __rte_unused void *data)
7466 {
7467         struct cmd_set_link_down_result *res = parsed_result;
7468         dev_set_link_down(res->port_id);
7469 }
7470
7471 cmdline_parse_inst_t cmd_set_link_down = {
7472         .f = cmd_set_link_down_parsed,
7473         .data = NULL,
7474         .help_str = "set link-down port <port id>",
7475         .tokens = {
7476                 (void *)&cmd_set_link_down_set,
7477                 (void *)&cmd_set_link_down_link_down,
7478                 (void *)&cmd_set_link_down_port,
7479                 (void *)&cmd_set_link_down_port_id,
7480                 NULL,
7481         },
7482 };
7483
7484 /* *** SHOW CFG *** */
7485 struct cmd_showcfg_result {
7486         cmdline_fixed_string_t show;
7487         cmdline_fixed_string_t cfg;
7488         cmdline_fixed_string_t what;
7489 };
7490
7491 static void cmd_showcfg_parsed(void *parsed_result,
7492                                __rte_unused struct cmdline *cl,
7493                                __rte_unused void *data)
7494 {
7495         struct cmd_showcfg_result *res = parsed_result;
7496         if (!strcmp(res->what, "rxtx"))
7497                 rxtx_config_display();
7498         else if (!strcmp(res->what, "cores"))
7499                 fwd_lcores_config_display();
7500         else if (!strcmp(res->what, "fwd"))
7501                 pkt_fwd_config_display(&cur_fwd_config);
7502         else if (!strcmp(res->what, "rxoffs"))
7503                 show_rx_pkt_offsets();
7504         else if (!strcmp(res->what, "rxpkts"))
7505                 show_rx_pkt_segments();
7506         else if (!strcmp(res->what, "txpkts"))
7507                 show_tx_pkt_segments();
7508         else if (!strcmp(res->what, "txtimes"))
7509                 show_tx_pkt_times();
7510 }
7511
7512 cmdline_parse_token_string_t cmd_showcfg_show =
7513         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7514 cmdline_parse_token_string_t cmd_showcfg_port =
7515         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7516 cmdline_parse_token_string_t cmd_showcfg_what =
7517         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7518                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7519
7520 cmdline_parse_inst_t cmd_showcfg = {
7521         .f = cmd_showcfg_parsed,
7522         .data = NULL,
7523         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7524         .tokens = {
7525                 (void *)&cmd_showcfg_show,
7526                 (void *)&cmd_showcfg_port,
7527                 (void *)&cmd_showcfg_what,
7528                 NULL,
7529         },
7530 };
7531
7532 /* *** SHOW ALL PORT INFO *** */
7533 struct cmd_showportall_result {
7534         cmdline_fixed_string_t show;
7535         cmdline_fixed_string_t port;
7536         cmdline_fixed_string_t what;
7537         cmdline_fixed_string_t all;
7538 };
7539
7540 static void cmd_showportall_parsed(void *parsed_result,
7541                                 __rte_unused struct cmdline *cl,
7542                                 __rte_unused void *data)
7543 {
7544         portid_t i;
7545
7546         struct cmd_showportall_result *res = parsed_result;
7547         if (!strcmp(res->show, "clear")) {
7548                 if (!strcmp(res->what, "stats"))
7549                         RTE_ETH_FOREACH_DEV(i)
7550                                 nic_stats_clear(i);
7551                 else if (!strcmp(res->what, "xstats"))
7552                         RTE_ETH_FOREACH_DEV(i)
7553                                 nic_xstats_clear(i);
7554         } else if (!strcmp(res->what, "info"))
7555                 RTE_ETH_FOREACH_DEV(i)
7556                         port_infos_display(i);
7557         else if (!strcmp(res->what, "summary")) {
7558                 port_summary_header_display();
7559                 RTE_ETH_FOREACH_DEV(i)
7560                         port_summary_display(i);
7561         }
7562         else if (!strcmp(res->what, "stats"))
7563                 RTE_ETH_FOREACH_DEV(i)
7564                         nic_stats_display(i);
7565         else if (!strcmp(res->what, "xstats"))
7566                 RTE_ETH_FOREACH_DEV(i)
7567                         nic_xstats_display(i);
7568 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7569         else if (!strcmp(res->what, "fdir"))
7570                 RTE_ETH_FOREACH_DEV(i)
7571                         fdir_get_infos(i);
7572 #endif
7573         else if (!strcmp(res->what, "dcb_tc"))
7574                 RTE_ETH_FOREACH_DEV(i)
7575                         port_dcb_info_display(i);
7576         else if (!strcmp(res->what, "cap"))
7577                 RTE_ETH_FOREACH_DEV(i)
7578                         port_offload_cap_display(i);
7579 }
7580
7581 cmdline_parse_token_string_t cmd_showportall_show =
7582         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7583                                  "show#clear");
7584 cmdline_parse_token_string_t cmd_showportall_port =
7585         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7586 cmdline_parse_token_string_t cmd_showportall_what =
7587         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7588                                  "info#summary#stats#xstats#fdir#dcb_tc#cap");
7589 cmdline_parse_token_string_t cmd_showportall_all =
7590         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7591 cmdline_parse_inst_t cmd_showportall = {
7592         .f = cmd_showportall_parsed,
7593         .data = NULL,
7594         .help_str = "show|clear port "
7595                 "info|summary|stats|xstats|fdir|dcb_tc|cap all",
7596         .tokens = {
7597                 (void *)&cmd_showportall_show,
7598                 (void *)&cmd_showportall_port,
7599                 (void *)&cmd_showportall_what,
7600                 (void *)&cmd_showportall_all,
7601                 NULL,
7602         },
7603 };
7604
7605 /* *** SHOW PORT INFO *** */
7606 struct cmd_showport_result {
7607         cmdline_fixed_string_t show;
7608         cmdline_fixed_string_t port;
7609         cmdline_fixed_string_t what;
7610         uint16_t portnum;
7611 };
7612
7613 static void cmd_showport_parsed(void *parsed_result,
7614                                 __rte_unused struct cmdline *cl,
7615                                 __rte_unused void *data)
7616 {
7617         struct cmd_showport_result *res = parsed_result;
7618         if (!strcmp(res->show, "clear")) {
7619                 if (!strcmp(res->what, "stats"))
7620                         nic_stats_clear(res->portnum);
7621                 else if (!strcmp(res->what, "xstats"))
7622                         nic_xstats_clear(res->portnum);
7623         } else if (!strcmp(res->what, "info"))
7624                 port_infos_display(res->portnum);
7625         else if (!strcmp(res->what, "summary")) {
7626                 port_summary_header_display();
7627                 port_summary_display(res->portnum);
7628         }
7629         else if (!strcmp(res->what, "stats"))
7630                 nic_stats_display(res->portnum);
7631         else if (!strcmp(res->what, "xstats"))
7632                 nic_xstats_display(res->portnum);
7633 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7634         else if (!strcmp(res->what, "fdir"))
7635                  fdir_get_infos(res->portnum);
7636 #endif
7637         else if (!strcmp(res->what, "dcb_tc"))
7638                 port_dcb_info_display(res->portnum);
7639         else if (!strcmp(res->what, "cap"))
7640                 port_offload_cap_display(res->portnum);
7641 }
7642
7643 cmdline_parse_token_string_t cmd_showport_show =
7644         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7645                                  "show#clear");
7646 cmdline_parse_token_string_t cmd_showport_port =
7647         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7648 cmdline_parse_token_string_t cmd_showport_what =
7649         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7650                                  "info#summary#stats#xstats#fdir#dcb_tc#cap");
7651 cmdline_parse_token_num_t cmd_showport_portnum =
7652         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7653
7654 cmdline_parse_inst_t cmd_showport = {
7655         .f = cmd_showport_parsed,
7656         .data = NULL,
7657         .help_str = "show|clear port "
7658                 "info|summary|stats|xstats|fdir|dcb_tc|cap "
7659                 "<port_id>",
7660         .tokens = {
7661                 (void *)&cmd_showport_show,
7662                 (void *)&cmd_showport_port,
7663                 (void *)&cmd_showport_what,
7664                 (void *)&cmd_showport_portnum,
7665                 NULL,
7666         },
7667 };
7668
7669 /* *** SHOW DEVICE INFO *** */
7670 struct cmd_showdevice_result {
7671         cmdline_fixed_string_t show;
7672         cmdline_fixed_string_t device;
7673         cmdline_fixed_string_t what;
7674         cmdline_fixed_string_t identifier;
7675 };
7676
7677 static void cmd_showdevice_parsed(void *parsed_result,
7678                                 __rte_unused struct cmdline *cl,
7679                                 __rte_unused void *data)
7680 {
7681         struct cmd_showdevice_result *res = parsed_result;
7682         if (!strcmp(res->what, "info")) {
7683                 if (!strcmp(res->identifier, "all"))
7684                         device_infos_display(NULL);
7685                 else
7686                         device_infos_display(res->identifier);
7687         }
7688 }
7689
7690 cmdline_parse_token_string_t cmd_showdevice_show =
7691         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7692                                  "show");
7693 cmdline_parse_token_string_t cmd_showdevice_device =
7694         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7695 cmdline_parse_token_string_t cmd_showdevice_what =
7696         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7697                                  "info");
7698 cmdline_parse_token_string_t cmd_showdevice_identifier =
7699         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7700                         identifier, NULL);
7701
7702 cmdline_parse_inst_t cmd_showdevice = {
7703         .f = cmd_showdevice_parsed,
7704         .data = NULL,
7705         .help_str = "show device info <identifier>|all",
7706         .tokens = {
7707                 (void *)&cmd_showdevice_show,
7708                 (void *)&cmd_showdevice_device,
7709                 (void *)&cmd_showdevice_what,
7710                 (void *)&cmd_showdevice_identifier,
7711                 NULL,
7712         },
7713 };
7714
7715 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7716 struct cmd_showeeprom_result {
7717         cmdline_fixed_string_t show;
7718         cmdline_fixed_string_t port;
7719         uint16_t portnum;
7720         cmdline_fixed_string_t type;
7721 };
7722
7723 static void cmd_showeeprom_parsed(void *parsed_result,
7724                 __rte_unused struct cmdline *cl,
7725                 __rte_unused void *data)
7726 {
7727         struct cmd_showeeprom_result *res = parsed_result;
7728
7729         if (!strcmp(res->type, "eeprom"))
7730                 port_eeprom_display(res->portnum);
7731         else if (!strcmp(res->type, "module_eeprom"))
7732                 port_module_eeprom_display(res->portnum);
7733         else
7734                 printf("Unknown argument\n");
7735 }
7736
7737 cmdline_parse_token_string_t cmd_showeeprom_show =
7738         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7739 cmdline_parse_token_string_t cmd_showeeprom_port =
7740         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7741 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7742         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7743                         RTE_UINT16);
7744 cmdline_parse_token_string_t cmd_showeeprom_type =
7745         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7746
7747 cmdline_parse_inst_t cmd_showeeprom = {
7748         .f = cmd_showeeprom_parsed,
7749         .data = NULL,
7750         .help_str = "show port <port_id> module_eeprom|eeprom",
7751         .tokens = {
7752                 (void *)&cmd_showeeprom_show,
7753                 (void *)&cmd_showeeprom_port,
7754                 (void *)&cmd_showeeprom_portnum,
7755                 (void *)&cmd_showeeprom_type,
7756                 NULL,
7757         },
7758 };
7759
7760 /* *** SHOW QUEUE INFO *** */
7761 struct cmd_showqueue_result {
7762         cmdline_fixed_string_t show;
7763         cmdline_fixed_string_t type;
7764         cmdline_fixed_string_t what;
7765         uint16_t portnum;
7766         uint16_t queuenum;
7767 };
7768
7769 static void
7770 cmd_showqueue_parsed(void *parsed_result,
7771         __rte_unused struct cmdline *cl,
7772         __rte_unused void *data)
7773 {
7774         struct cmd_showqueue_result *res = parsed_result;
7775
7776         if (!strcmp(res->type, "rxq"))
7777                 rx_queue_infos_display(res->portnum, res->queuenum);
7778         else if (!strcmp(res->type, "txq"))
7779                 tx_queue_infos_display(res->portnum, res->queuenum);
7780 }
7781
7782 cmdline_parse_token_string_t cmd_showqueue_show =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7784 cmdline_parse_token_string_t cmd_showqueue_type =
7785         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7786 cmdline_parse_token_string_t cmd_showqueue_what =
7787         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7788 cmdline_parse_token_num_t cmd_showqueue_portnum =
7789         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7790                 RTE_UINT16);
7791 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7792         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7793                 RTE_UINT16);
7794
7795 cmdline_parse_inst_t cmd_showqueue = {
7796         .f = cmd_showqueue_parsed,
7797         .data = NULL,
7798         .help_str = "show rxq|txq info <port_id> <queue_id>",
7799         .tokens = {
7800                 (void *)&cmd_showqueue_show,
7801                 (void *)&cmd_showqueue_type,
7802                 (void *)&cmd_showqueue_what,
7803                 (void *)&cmd_showqueue_portnum,
7804                 (void *)&cmd_showqueue_queuenum,
7805                 NULL,
7806         },
7807 };
7808
7809 /* show/clear fwd engine statistics */
7810 struct fwd_result {
7811         cmdline_fixed_string_t action;
7812         cmdline_fixed_string_t fwd;
7813         cmdline_fixed_string_t stats;
7814         cmdline_fixed_string_t all;
7815 };
7816
7817 cmdline_parse_token_string_t cmd_fwd_action =
7818         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7819 cmdline_parse_token_string_t cmd_fwd_fwd =
7820         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7821 cmdline_parse_token_string_t cmd_fwd_stats =
7822         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7823 cmdline_parse_token_string_t cmd_fwd_all =
7824         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7825
7826 static void
7827 cmd_showfwdall_parsed(void *parsed_result,
7828                       __rte_unused struct cmdline *cl,
7829                       __rte_unused void *data)
7830 {
7831         struct fwd_result *res = parsed_result;
7832
7833         if (!strcmp(res->action, "show"))
7834                 fwd_stats_display();
7835         else
7836                 fwd_stats_reset();
7837 }
7838
7839 static cmdline_parse_inst_t cmd_showfwdall = {
7840         .f = cmd_showfwdall_parsed,
7841         .data = NULL,
7842         .help_str = "show|clear fwd stats all",
7843         .tokens = {
7844                 (void *)&cmd_fwd_action,
7845                 (void *)&cmd_fwd_fwd,
7846                 (void *)&cmd_fwd_stats,
7847                 (void *)&cmd_fwd_all,
7848                 NULL,
7849         },
7850 };
7851
7852 /* *** READ PORT REGISTER *** */
7853 struct cmd_read_reg_result {
7854         cmdline_fixed_string_t read;
7855         cmdline_fixed_string_t reg;
7856         portid_t port_id;
7857         uint32_t reg_off;
7858 };
7859
7860 static void
7861 cmd_read_reg_parsed(void *parsed_result,
7862                     __rte_unused struct cmdline *cl,
7863                     __rte_unused void *data)
7864 {
7865         struct cmd_read_reg_result *res = parsed_result;
7866         port_reg_display(res->port_id, res->reg_off);
7867 }
7868
7869 cmdline_parse_token_string_t cmd_read_reg_read =
7870         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7871 cmdline_parse_token_string_t cmd_read_reg_reg =
7872         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7873 cmdline_parse_token_num_t cmd_read_reg_port_id =
7874         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7875 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7876         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7877
7878 cmdline_parse_inst_t cmd_read_reg = {
7879         .f = cmd_read_reg_parsed,
7880         .data = NULL,
7881         .help_str = "read reg <port_id> <reg_off>",
7882         .tokens = {
7883                 (void *)&cmd_read_reg_read,
7884                 (void *)&cmd_read_reg_reg,
7885                 (void *)&cmd_read_reg_port_id,
7886                 (void *)&cmd_read_reg_reg_off,
7887                 NULL,
7888         },
7889 };
7890
7891 /* *** READ PORT REGISTER BIT FIELD *** */
7892 struct cmd_read_reg_bit_field_result {
7893         cmdline_fixed_string_t read;
7894         cmdline_fixed_string_t regfield;
7895         portid_t port_id;
7896         uint32_t reg_off;
7897         uint8_t bit1_pos;
7898         uint8_t bit2_pos;
7899 };
7900
7901 static void
7902 cmd_read_reg_bit_field_parsed(void *parsed_result,
7903                               __rte_unused struct cmdline *cl,
7904                               __rte_unused void *data)
7905 {
7906         struct cmd_read_reg_bit_field_result *res = parsed_result;
7907         port_reg_bit_field_display(res->port_id, res->reg_off,
7908                                    res->bit1_pos, res->bit2_pos);
7909 }
7910
7911 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7912         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7913                                  "read");
7914 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7915         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7916                                  regfield, "regfield");
7917 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7918         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7919                               RTE_UINT16);
7920 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7921         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7922                               RTE_UINT32);
7923 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7924         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7925                               RTE_UINT8);
7926 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7927         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7928                               RTE_UINT8);
7929
7930 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7931         .f = cmd_read_reg_bit_field_parsed,
7932         .data = NULL,
7933         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7934         "Read register bit field between bit_x and bit_y included",
7935         .tokens = {
7936                 (void *)&cmd_read_reg_bit_field_read,
7937                 (void *)&cmd_read_reg_bit_field_regfield,
7938                 (void *)&cmd_read_reg_bit_field_port_id,
7939                 (void *)&cmd_read_reg_bit_field_reg_off,
7940                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7941                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7942                 NULL,
7943         },
7944 };
7945
7946 /* *** READ PORT REGISTER BIT *** */
7947 struct cmd_read_reg_bit_result {
7948         cmdline_fixed_string_t read;
7949         cmdline_fixed_string_t regbit;
7950         portid_t port_id;
7951         uint32_t reg_off;
7952         uint8_t bit_pos;
7953 };
7954
7955 static void
7956 cmd_read_reg_bit_parsed(void *parsed_result,
7957                         __rte_unused struct cmdline *cl,
7958                         __rte_unused void *data)
7959 {
7960         struct cmd_read_reg_bit_result *res = parsed_result;
7961         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7962 }
7963
7964 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7965         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7966 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7967         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7968                                  regbit, "regbit");
7969 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7970         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7971                                  RTE_UINT16);
7972 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7973         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7974                                  RTE_UINT32);
7975 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7976         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7977                                  RTE_UINT8);
7978
7979 cmdline_parse_inst_t cmd_read_reg_bit = {
7980         .f = cmd_read_reg_bit_parsed,
7981         .data = NULL,
7982         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7983         .tokens = {
7984                 (void *)&cmd_read_reg_bit_read,
7985                 (void *)&cmd_read_reg_bit_regbit,
7986                 (void *)&cmd_read_reg_bit_port_id,
7987                 (void *)&cmd_read_reg_bit_reg_off,
7988                 (void *)&cmd_read_reg_bit_bit_pos,
7989                 NULL,
7990         },
7991 };
7992
7993 /* *** WRITE PORT REGISTER *** */
7994 struct cmd_write_reg_result {
7995         cmdline_fixed_string_t write;
7996         cmdline_fixed_string_t reg;
7997         portid_t port_id;
7998         uint32_t reg_off;
7999         uint32_t value;
8000 };
8001
8002 static void
8003 cmd_write_reg_parsed(void *parsed_result,
8004                      __rte_unused struct cmdline *cl,
8005                      __rte_unused void *data)
8006 {
8007         struct cmd_write_reg_result *res = parsed_result;
8008         port_reg_set(res->port_id, res->reg_off, res->value);
8009 }
8010
8011 cmdline_parse_token_string_t cmd_write_reg_write =
8012         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8013 cmdline_parse_token_string_t cmd_write_reg_reg =
8014         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8015 cmdline_parse_token_num_t cmd_write_reg_port_id =
8016         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8017 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8018         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8019 cmdline_parse_token_num_t cmd_write_reg_value =
8020         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8021
8022 cmdline_parse_inst_t cmd_write_reg = {
8023         .f = cmd_write_reg_parsed,
8024         .data = NULL,
8025         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8026         .tokens = {
8027                 (void *)&cmd_write_reg_write,
8028                 (void *)&cmd_write_reg_reg,
8029                 (void *)&cmd_write_reg_port_id,
8030                 (void *)&cmd_write_reg_reg_off,
8031                 (void *)&cmd_write_reg_value,
8032                 NULL,
8033         },
8034 };
8035
8036 /* *** WRITE PORT REGISTER BIT FIELD *** */
8037 struct cmd_write_reg_bit_field_result {
8038         cmdline_fixed_string_t write;
8039         cmdline_fixed_string_t regfield;
8040         portid_t port_id;
8041         uint32_t reg_off;
8042         uint8_t bit1_pos;
8043         uint8_t bit2_pos;
8044         uint32_t value;
8045 };
8046
8047 static void
8048 cmd_write_reg_bit_field_parsed(void *parsed_result,
8049                                __rte_unused struct cmdline *cl,
8050                                __rte_unused void *data)
8051 {
8052         struct cmd_write_reg_bit_field_result *res = parsed_result;
8053         port_reg_bit_field_set(res->port_id, res->reg_off,
8054                           res->bit1_pos, res->bit2_pos, res->value);
8055 }
8056
8057 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8058         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8059                                  "write");
8060 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8061         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8062                                  regfield, "regfield");
8063 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8064         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8065                               RTE_UINT16);
8066 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8067         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8068                               RTE_UINT32);
8069 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8070         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8071                               RTE_UINT8);
8072 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8073         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8074                               RTE_UINT8);
8075 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8076         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8077                               RTE_UINT32);
8078
8079 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8080         .f = cmd_write_reg_bit_field_parsed,
8081         .data = NULL,
8082         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8083                 "<reg_value>: "
8084                 "Set register bit field between bit_x and bit_y included",
8085         .tokens = {
8086                 (void *)&cmd_write_reg_bit_field_write,
8087                 (void *)&cmd_write_reg_bit_field_regfield,
8088                 (void *)&cmd_write_reg_bit_field_port_id,
8089                 (void *)&cmd_write_reg_bit_field_reg_off,
8090                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8091                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8092                 (void *)&cmd_write_reg_bit_field_value,
8093                 NULL,
8094         },
8095 };
8096
8097 /* *** WRITE PORT REGISTER BIT *** */
8098 struct cmd_write_reg_bit_result {
8099         cmdline_fixed_string_t write;
8100         cmdline_fixed_string_t regbit;
8101         portid_t port_id;
8102         uint32_t reg_off;
8103         uint8_t bit_pos;
8104         uint8_t value;
8105 };
8106
8107 static void
8108 cmd_write_reg_bit_parsed(void *parsed_result,
8109                          __rte_unused struct cmdline *cl,
8110                          __rte_unused void *data)
8111 {
8112         struct cmd_write_reg_bit_result *res = parsed_result;
8113         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8114 }
8115
8116 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8117         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8118                                  "write");
8119 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8120         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8121                                  regbit, "regbit");
8122 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8123         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8124                                  RTE_UINT16);
8125 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8126         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8127                                  RTE_UINT32);
8128 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8129         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8130                                  RTE_UINT8);
8131 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8132         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8133                                  RTE_UINT8);
8134
8135 cmdline_parse_inst_t cmd_write_reg_bit = {
8136         .f = cmd_write_reg_bit_parsed,
8137         .data = NULL,
8138         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8139                 "0 <= bit_x <= 31",
8140         .tokens = {
8141                 (void *)&cmd_write_reg_bit_write,
8142                 (void *)&cmd_write_reg_bit_regbit,
8143                 (void *)&cmd_write_reg_bit_port_id,
8144                 (void *)&cmd_write_reg_bit_reg_off,
8145                 (void *)&cmd_write_reg_bit_bit_pos,
8146                 (void *)&cmd_write_reg_bit_value,
8147                 NULL,
8148         },
8149 };
8150
8151 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8152 struct cmd_read_rxd_txd_result {
8153         cmdline_fixed_string_t read;
8154         cmdline_fixed_string_t rxd_txd;
8155         portid_t port_id;
8156         uint16_t queue_id;
8157         uint16_t desc_id;
8158 };
8159
8160 static void
8161 cmd_read_rxd_txd_parsed(void *parsed_result,
8162                         __rte_unused struct cmdline *cl,
8163                         __rte_unused void *data)
8164 {
8165         struct cmd_read_rxd_txd_result *res = parsed_result;
8166
8167         if (!strcmp(res->rxd_txd, "rxd"))
8168                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8169         else if (!strcmp(res->rxd_txd, "txd"))
8170                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8171 }
8172
8173 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8174         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8175 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8176         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8177                                  "rxd#txd");
8178 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8179         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8180                                  RTE_UINT16);
8181 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8182         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8183                                  RTE_UINT16);
8184 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8185         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8186                                  RTE_UINT16);
8187
8188 cmdline_parse_inst_t cmd_read_rxd_txd = {
8189         .f = cmd_read_rxd_txd_parsed,
8190         .data = NULL,
8191         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8192         .tokens = {
8193                 (void *)&cmd_read_rxd_txd_read,
8194                 (void *)&cmd_read_rxd_txd_rxd_txd,
8195                 (void *)&cmd_read_rxd_txd_port_id,
8196                 (void *)&cmd_read_rxd_txd_queue_id,
8197                 (void *)&cmd_read_rxd_txd_desc_id,
8198                 NULL,
8199         },
8200 };
8201
8202 /* *** QUIT *** */
8203 struct cmd_quit_result {
8204         cmdline_fixed_string_t quit;
8205 };
8206
8207 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8208                             struct cmdline *cl,
8209                             __rte_unused void *data)
8210 {
8211         cmdline_quit(cl);
8212 }
8213
8214 cmdline_parse_token_string_t cmd_quit_quit =
8215         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8216
8217 cmdline_parse_inst_t cmd_quit = {
8218         .f = cmd_quit_parsed,
8219         .data = NULL,
8220         .help_str = "quit: Exit application",
8221         .tokens = {
8222                 (void *)&cmd_quit_quit,
8223                 NULL,
8224         },
8225 };
8226
8227 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8228 struct cmd_mac_addr_result {
8229         cmdline_fixed_string_t mac_addr_cmd;
8230         cmdline_fixed_string_t what;
8231         uint16_t port_num;
8232         struct rte_ether_addr address;
8233 };
8234
8235 static void cmd_mac_addr_parsed(void *parsed_result,
8236                 __rte_unused struct cmdline *cl,
8237                 __rte_unused void *data)
8238 {
8239         struct cmd_mac_addr_result *res = parsed_result;
8240         int ret;
8241
8242         if (strcmp(res->what, "add") == 0)
8243                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8244         else if (strcmp(res->what, "set") == 0)
8245                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8246                                                        &res->address);
8247         else
8248                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8249
8250         /* check the return value and print it if is < 0 */
8251         if(ret < 0)
8252                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8253
8254 }
8255
8256 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8257         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8258                                 "mac_addr");
8259 cmdline_parse_token_string_t cmd_mac_addr_what =
8260         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8261                                 "add#remove#set");
8262 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8263                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8264                                         RTE_UINT16);
8265 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8266                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8267
8268 cmdline_parse_inst_t cmd_mac_addr = {
8269         .f = cmd_mac_addr_parsed,
8270         .data = (void *)0,
8271         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8272                         "Add/Remove/Set MAC address on port_id",
8273         .tokens = {
8274                 (void *)&cmd_mac_addr_cmd,
8275                 (void *)&cmd_mac_addr_what,
8276                 (void *)&cmd_mac_addr_portnum,
8277                 (void *)&cmd_mac_addr_addr,
8278                 NULL,
8279         },
8280 };
8281
8282 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8283 struct cmd_eth_peer_result {
8284         cmdline_fixed_string_t set;
8285         cmdline_fixed_string_t eth_peer;
8286         portid_t port_id;
8287         cmdline_fixed_string_t peer_addr;
8288 };
8289
8290 static void cmd_set_eth_peer_parsed(void *parsed_result,
8291                         __rte_unused struct cmdline *cl,
8292                         __rte_unused void *data)
8293 {
8294                 struct cmd_eth_peer_result *res = parsed_result;
8295
8296                 if (test_done == 0) {
8297                         printf("Please stop forwarding first\n");
8298                         return;
8299                 }
8300                 if (!strcmp(res->eth_peer, "eth-peer")) {
8301                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8302                         fwd_config_setup();
8303                 }
8304 }
8305 cmdline_parse_token_string_t cmd_eth_peer_set =
8306         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8307 cmdline_parse_token_string_t cmd_eth_peer =
8308         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8309 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8310         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8311                 RTE_UINT16);
8312 cmdline_parse_token_string_t cmd_eth_peer_addr =
8313         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8314
8315 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8316         .f = cmd_set_eth_peer_parsed,
8317         .data = NULL,
8318         .help_str = "set eth-peer <port_id> <peer_mac>",
8319         .tokens = {
8320                 (void *)&cmd_eth_peer_set,
8321                 (void *)&cmd_eth_peer,
8322                 (void *)&cmd_eth_peer_port_id,
8323                 (void *)&cmd_eth_peer_addr,
8324                 NULL,
8325         },
8326 };
8327
8328 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8329 struct cmd_set_qmap_result {
8330         cmdline_fixed_string_t set;
8331         cmdline_fixed_string_t qmap;
8332         cmdline_fixed_string_t what;
8333         portid_t port_id;
8334         uint16_t queue_id;
8335         uint8_t map_value;
8336 };
8337
8338 static void
8339 cmd_set_qmap_parsed(void *parsed_result,
8340                        __rte_unused struct cmdline *cl,
8341                        __rte_unused void *data)
8342 {
8343         struct cmd_set_qmap_result *res = parsed_result;
8344         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8345
8346         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8347 }
8348
8349 cmdline_parse_token_string_t cmd_setqmap_set =
8350         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8351                                  set, "set");
8352 cmdline_parse_token_string_t cmd_setqmap_qmap =
8353         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8354                                  qmap, "stat_qmap");
8355 cmdline_parse_token_string_t cmd_setqmap_what =
8356         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8357                                  what, "tx#rx");
8358 cmdline_parse_token_num_t cmd_setqmap_portid =
8359         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8360                               port_id, RTE_UINT16);
8361 cmdline_parse_token_num_t cmd_setqmap_queueid =
8362         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8363                               queue_id, RTE_UINT16);
8364 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8365         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8366                               map_value, RTE_UINT8);
8367
8368 cmdline_parse_inst_t cmd_set_qmap = {
8369         .f = cmd_set_qmap_parsed,
8370         .data = NULL,
8371         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8372                 "Set statistics mapping value on tx|rx queue_id of port_id",
8373         .tokens = {
8374                 (void *)&cmd_setqmap_set,
8375                 (void *)&cmd_setqmap_qmap,
8376                 (void *)&cmd_setqmap_what,
8377                 (void *)&cmd_setqmap_portid,
8378                 (void *)&cmd_setqmap_queueid,
8379                 (void *)&cmd_setqmap_mapvalue,
8380                 NULL,
8381         },
8382 };
8383
8384 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8385 struct cmd_set_xstats_hide_zero_result {
8386         cmdline_fixed_string_t keyword;
8387         cmdline_fixed_string_t name;
8388         cmdline_fixed_string_t on_off;
8389 };
8390
8391 static void
8392 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8393                         __rte_unused struct cmdline *cl,
8394                         __rte_unused void *data)
8395 {
8396         struct cmd_set_xstats_hide_zero_result *res;
8397         uint16_t on_off = 0;
8398
8399         res = parsed_result;
8400         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8401         set_xstats_hide_zero(on_off);
8402 }
8403
8404 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8405         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8406                                  keyword, "set");
8407 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8408         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8409                                  name, "xstats-hide-zero");
8410 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8411         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8412                                  on_off, "on#off");
8413
8414 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8415         .f = cmd_set_xstats_hide_zero_parsed,
8416         .data = NULL,
8417         .help_str = "set xstats-hide-zero on|off",
8418         .tokens = {
8419                 (void *)&cmd_set_xstats_hide_zero_keyword,
8420                 (void *)&cmd_set_xstats_hide_zero_name,
8421                 (void *)&cmd_set_xstats_hide_zero_on_off,
8422                 NULL,
8423         },
8424 };
8425
8426 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8427 struct cmd_set_record_core_cycles_result {
8428         cmdline_fixed_string_t keyword;
8429         cmdline_fixed_string_t name;
8430         cmdline_fixed_string_t on_off;
8431 };
8432
8433 static void
8434 cmd_set_record_core_cycles_parsed(void *parsed_result,
8435                         __rte_unused struct cmdline *cl,
8436                         __rte_unused void *data)
8437 {
8438         struct cmd_set_record_core_cycles_result *res;
8439         uint16_t on_off = 0;
8440
8441         res = parsed_result;
8442         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8443         set_record_core_cycles(on_off);
8444 }
8445
8446 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8447         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8448                                  keyword, "set");
8449 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8450         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8451                                  name, "record-core-cycles");
8452 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8453         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8454                                  on_off, "on#off");
8455
8456 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8457         .f = cmd_set_record_core_cycles_parsed,
8458         .data = NULL,
8459         .help_str = "set record-core-cycles on|off",
8460         .tokens = {
8461                 (void *)&cmd_set_record_core_cycles_keyword,
8462                 (void *)&cmd_set_record_core_cycles_name,
8463                 (void *)&cmd_set_record_core_cycles_on_off,
8464                 NULL,
8465         },
8466 };
8467
8468 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8469 struct cmd_set_record_burst_stats_result {
8470         cmdline_fixed_string_t keyword;
8471         cmdline_fixed_string_t name;
8472         cmdline_fixed_string_t on_off;
8473 };
8474
8475 static void
8476 cmd_set_record_burst_stats_parsed(void *parsed_result,
8477                         __rte_unused struct cmdline *cl,
8478                         __rte_unused void *data)
8479 {
8480         struct cmd_set_record_burst_stats_result *res;
8481         uint16_t on_off = 0;
8482
8483         res = parsed_result;
8484         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8485         set_record_burst_stats(on_off);
8486 }
8487
8488 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8489         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8490                                  keyword, "set");
8491 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8492         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8493                                  name, "record-burst-stats");
8494 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8495         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8496                                  on_off, "on#off");
8497
8498 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8499         .f = cmd_set_record_burst_stats_parsed,
8500         .data = NULL,
8501         .help_str = "set record-burst-stats on|off",
8502         .tokens = {
8503                 (void *)&cmd_set_record_burst_stats_keyword,
8504                 (void *)&cmd_set_record_burst_stats_name,
8505                 (void *)&cmd_set_record_burst_stats_on_off,
8506                 NULL,
8507         },
8508 };
8509
8510 /* *** CONFIGURE UNICAST HASH TABLE *** */
8511 struct cmd_set_uc_hash_table {
8512         cmdline_fixed_string_t set;
8513         cmdline_fixed_string_t port;
8514         portid_t port_id;
8515         cmdline_fixed_string_t what;
8516         struct rte_ether_addr address;
8517         cmdline_fixed_string_t mode;
8518 };
8519
8520 static void
8521 cmd_set_uc_hash_parsed(void *parsed_result,
8522                        __rte_unused struct cmdline *cl,
8523                        __rte_unused void *data)
8524 {
8525         int ret=0;
8526         struct cmd_set_uc_hash_table *res = parsed_result;
8527
8528         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8529
8530         if (strcmp(res->what, "uta") == 0)
8531                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8532                                                 &res->address,(uint8_t)is_on);
8533         if (ret < 0)
8534                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8535
8536 }
8537
8538 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8539         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8540                                  set, "set");
8541 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8542         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8543                                  port, "port");
8544 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8545         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8546                               port_id, RTE_UINT16);
8547 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8548         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8549                                  what, "uta");
8550 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8551         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8552                                 address);
8553 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8554         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8555                                  mode, "on#off");
8556
8557 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8558         .f = cmd_set_uc_hash_parsed,
8559         .data = NULL,
8560         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8561         .tokens = {
8562                 (void *)&cmd_set_uc_hash_set,
8563                 (void *)&cmd_set_uc_hash_port,
8564                 (void *)&cmd_set_uc_hash_portid,
8565                 (void *)&cmd_set_uc_hash_what,
8566                 (void *)&cmd_set_uc_hash_mac,
8567                 (void *)&cmd_set_uc_hash_mode,
8568                 NULL,
8569         },
8570 };
8571
8572 struct cmd_set_uc_all_hash_table {
8573         cmdline_fixed_string_t set;
8574         cmdline_fixed_string_t port;
8575         portid_t port_id;
8576         cmdline_fixed_string_t what;
8577         cmdline_fixed_string_t value;
8578         cmdline_fixed_string_t mode;
8579 };
8580
8581 static void
8582 cmd_set_uc_all_hash_parsed(void *parsed_result,
8583                        __rte_unused struct cmdline *cl,
8584                        __rte_unused void *data)
8585 {
8586         int ret=0;
8587         struct cmd_set_uc_all_hash_table *res = parsed_result;
8588
8589         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8590
8591         if ((strcmp(res->what, "uta") == 0) &&
8592                 (strcmp(res->value, "all") == 0))
8593                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8594         if (ret < 0)
8595                 printf("bad unicast hash table parameter,"
8596                         "return code = %d \n", ret);
8597 }
8598
8599 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8600         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8601                                  set, "set");
8602 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8603         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8604                                  port, "port");
8605 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8606         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8607                               port_id, RTE_UINT16);
8608 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8609         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8610                                  what, "uta");
8611 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8613                                 value,"all");
8614 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8615         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8616                                  mode, "on#off");
8617
8618 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8619         .f = cmd_set_uc_all_hash_parsed,
8620         .data = NULL,
8621         .help_str = "set port <port_id> uta all on|off",
8622         .tokens = {
8623                 (void *)&cmd_set_uc_all_hash_set,
8624                 (void *)&cmd_set_uc_all_hash_port,
8625                 (void *)&cmd_set_uc_all_hash_portid,
8626                 (void *)&cmd_set_uc_all_hash_what,
8627                 (void *)&cmd_set_uc_all_hash_value,
8628                 (void *)&cmd_set_uc_all_hash_mode,
8629                 NULL,
8630         },
8631 };
8632
8633 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8634 struct cmd_set_vf_traffic {
8635         cmdline_fixed_string_t set;
8636         cmdline_fixed_string_t port;
8637         portid_t port_id;
8638         cmdline_fixed_string_t vf;
8639         uint8_t vf_id;
8640         cmdline_fixed_string_t what;
8641         cmdline_fixed_string_t mode;
8642 };
8643
8644 static void
8645 cmd_set_vf_traffic_parsed(void *parsed_result,
8646                        __rte_unused struct cmdline *cl,
8647                        __rte_unused void *data)
8648 {
8649         struct cmd_set_vf_traffic *res = parsed_result;
8650         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8651         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8652
8653         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8654 }
8655
8656 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8657         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8658                                  set, "set");
8659 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8661                                  port, "port");
8662 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8663         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8664                               port_id, RTE_UINT16);
8665 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8666         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8667                                  vf, "vf");
8668 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8669         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8670                               vf_id, RTE_UINT8);
8671 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8672         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8673                                  what, "tx#rx");
8674 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8675         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8676                                  mode, "on#off");
8677
8678 cmdline_parse_inst_t cmd_set_vf_traffic = {
8679         .f = cmd_set_vf_traffic_parsed,
8680         .data = NULL,
8681         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8682         .tokens = {
8683                 (void *)&cmd_setvf_traffic_set,
8684                 (void *)&cmd_setvf_traffic_port,
8685                 (void *)&cmd_setvf_traffic_portid,
8686                 (void *)&cmd_setvf_traffic_vf,
8687                 (void *)&cmd_setvf_traffic_vfid,
8688                 (void *)&cmd_setvf_traffic_what,
8689                 (void *)&cmd_setvf_traffic_mode,
8690                 NULL,
8691         },
8692 };
8693
8694 /* *** CONFIGURE VF RECEIVE MODE *** */
8695 struct cmd_set_vf_rxmode {
8696         cmdline_fixed_string_t set;
8697         cmdline_fixed_string_t port;
8698         portid_t port_id;
8699         cmdline_fixed_string_t vf;
8700         uint8_t vf_id;
8701         cmdline_fixed_string_t what;
8702         cmdline_fixed_string_t mode;
8703         cmdline_fixed_string_t on;
8704 };
8705
8706 static void
8707 cmd_set_vf_rxmode_parsed(void *parsed_result,
8708                        __rte_unused struct cmdline *cl,
8709                        __rte_unused void *data)
8710 {
8711         int ret = -ENOTSUP;
8712         uint16_t vf_rxmode = 0;
8713         struct cmd_set_vf_rxmode *res = parsed_result;
8714
8715         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8716         if (!strcmp(res->what,"rxmode")) {
8717                 if (!strcmp(res->mode, "AUPE"))
8718                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8719                 else if (!strcmp(res->mode, "ROPE"))
8720                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8721                 else if (!strcmp(res->mode, "BAM"))
8722                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8723                 else if (!strncmp(res->mode, "MPE",3))
8724                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8725         }
8726
8727         RTE_SET_USED(is_on);
8728
8729 #ifdef RTE_NET_IXGBE
8730         if (ret == -ENOTSUP)
8731                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8732                                                   vf_rxmode, (uint8_t)is_on);
8733 #endif
8734 #ifdef RTE_NET_BNXT
8735         if (ret == -ENOTSUP)
8736                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8737                                                  vf_rxmode, (uint8_t)is_on);
8738 #endif
8739         if (ret < 0)
8740                 printf("bad VF receive mode parameter, return code = %d \n",
8741                 ret);
8742 }
8743
8744 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8745         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8746                                  set, "set");
8747 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8748         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8749                                  port, "port");
8750 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8751         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8752                               port_id, RTE_UINT16);
8753 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8754         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8755                                  vf, "vf");
8756 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8757         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8758                               vf_id, RTE_UINT8);
8759 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8760         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8761                                  what, "rxmode");
8762 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8763         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8764                                  mode, "AUPE#ROPE#BAM#MPE");
8765 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8766         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8767                                  on, "on#off");
8768
8769 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8770         .f = cmd_set_vf_rxmode_parsed,
8771         .data = NULL,
8772         .help_str = "set port <port_id> vf <vf_id> rxmode "
8773                 "AUPE|ROPE|BAM|MPE on|off",
8774         .tokens = {
8775                 (void *)&cmd_set_vf_rxmode_set,
8776                 (void *)&cmd_set_vf_rxmode_port,
8777                 (void *)&cmd_set_vf_rxmode_portid,
8778                 (void *)&cmd_set_vf_rxmode_vf,
8779                 (void *)&cmd_set_vf_rxmode_vfid,
8780                 (void *)&cmd_set_vf_rxmode_what,
8781                 (void *)&cmd_set_vf_rxmode_mode,
8782                 (void *)&cmd_set_vf_rxmode_on,
8783                 NULL,
8784         },
8785 };
8786
8787 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8788 struct cmd_vf_mac_addr_result {
8789         cmdline_fixed_string_t mac_addr_cmd;
8790         cmdline_fixed_string_t what;
8791         cmdline_fixed_string_t port;
8792         uint16_t port_num;
8793         cmdline_fixed_string_t vf;
8794         uint8_t vf_num;
8795         struct rte_ether_addr address;
8796 };
8797
8798 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8799                 __rte_unused struct cmdline *cl,
8800                 __rte_unused void *data)
8801 {
8802         struct cmd_vf_mac_addr_result *res = parsed_result;
8803         int ret = -ENOTSUP;
8804
8805         if (strcmp(res->what, "add") != 0)
8806                 return;
8807
8808 #ifdef RTE_NET_I40E
8809         if (ret == -ENOTSUP)
8810                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8811                                                    &res->address);
8812 #endif
8813 #ifdef RTE_NET_BNXT
8814         if (ret == -ENOTSUP)
8815                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8816                                                 res->vf_num);
8817 #endif
8818
8819         if(ret < 0)
8820                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8821
8822 }
8823
8824 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8825         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8826                                 mac_addr_cmd,"mac_addr");
8827 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8828         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8829                                 what,"add");
8830 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8831         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8832                                 port,"port");
8833 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8834         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8835                                 port_num, RTE_UINT16);
8836 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8837         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8838                                 vf,"vf");
8839 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8840         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8841                                 vf_num, RTE_UINT8);
8842 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8843         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8844                                 address);
8845
8846 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8847         .f = cmd_vf_mac_addr_parsed,
8848         .data = (void *)0,
8849         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8850                 "Add MAC address filtering for a VF on port_id",
8851         .tokens = {
8852                 (void *)&cmd_vf_mac_addr_cmd,
8853                 (void *)&cmd_vf_mac_addr_what,
8854                 (void *)&cmd_vf_mac_addr_port,
8855                 (void *)&cmd_vf_mac_addr_portnum,
8856                 (void *)&cmd_vf_mac_addr_vf,
8857                 (void *)&cmd_vf_mac_addr_vfnum,
8858                 (void *)&cmd_vf_mac_addr_addr,
8859                 NULL,
8860         },
8861 };
8862
8863 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8864 struct cmd_vf_rx_vlan_filter {
8865         cmdline_fixed_string_t rx_vlan;
8866         cmdline_fixed_string_t what;
8867         uint16_t vlan_id;
8868         cmdline_fixed_string_t port;
8869         portid_t port_id;
8870         cmdline_fixed_string_t vf;
8871         uint64_t vf_mask;
8872 };
8873
8874 static void
8875 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8876                           __rte_unused struct cmdline *cl,
8877                           __rte_unused void *data)
8878 {
8879         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8880         int ret = -ENOTSUP;
8881
8882         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8883
8884 #ifdef RTE_NET_IXGBE
8885         if (ret == -ENOTSUP)
8886                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8887                                 res->vlan_id, res->vf_mask, is_add);
8888 #endif
8889 #ifdef RTE_NET_I40E
8890         if (ret == -ENOTSUP)
8891                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8892                                 res->vlan_id, res->vf_mask, is_add);
8893 #endif
8894 #ifdef RTE_NET_BNXT
8895         if (ret == -ENOTSUP)
8896                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8897                                 res->vlan_id, res->vf_mask, is_add);
8898 #endif
8899
8900         switch (ret) {
8901         case 0:
8902                 break;
8903         case -EINVAL:
8904                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8905                                 res->vlan_id, res->vf_mask);
8906                 break;
8907         case -ENODEV:
8908                 printf("invalid port_id %d\n", res->port_id);
8909                 break;
8910         case -ENOTSUP:
8911                 printf("function not implemented or supported\n");
8912                 break;
8913         default:
8914                 printf("programming error: (%s)\n", strerror(-ret));
8915         }
8916 }
8917
8918 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8919         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8920                                  rx_vlan, "rx_vlan");
8921 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8922         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8923                                  what, "add#rm");
8924 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8925         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8926                               vlan_id, RTE_UINT16);
8927 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8928         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8929                                  port, "port");
8930 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8931         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8932                               port_id, RTE_UINT16);
8933 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8934         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8935                                  vf, "vf");
8936 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8937         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8938                               vf_mask, RTE_UINT64);
8939
8940 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8941         .f = cmd_vf_rx_vlan_filter_parsed,
8942         .data = NULL,
8943         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8944                 "(vf_mask = hexadecimal VF mask)",
8945         .tokens = {
8946                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8947                 (void *)&cmd_vf_rx_vlan_filter_what,
8948                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8949                 (void *)&cmd_vf_rx_vlan_filter_port,
8950                 (void *)&cmd_vf_rx_vlan_filter_portid,
8951                 (void *)&cmd_vf_rx_vlan_filter_vf,
8952                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8953                 NULL,
8954         },
8955 };
8956
8957 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8958 struct cmd_queue_rate_limit_result {
8959         cmdline_fixed_string_t set;
8960         cmdline_fixed_string_t port;
8961         uint16_t port_num;
8962         cmdline_fixed_string_t queue;
8963         uint8_t queue_num;
8964         cmdline_fixed_string_t rate;
8965         uint16_t rate_num;
8966 };
8967
8968 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8969                 __rte_unused struct cmdline *cl,
8970                 __rte_unused void *data)
8971 {
8972         struct cmd_queue_rate_limit_result *res = parsed_result;
8973         int ret = 0;
8974
8975         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8976                 && (strcmp(res->queue, "queue") == 0)
8977                 && (strcmp(res->rate, "rate") == 0))
8978                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8979                                         res->rate_num);
8980         if (ret < 0)
8981                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8982
8983 }
8984
8985 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8986         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8987                                 set, "set");
8988 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8989         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8990                                 port, "port");
8991 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8992         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8993                                 port_num, RTE_UINT16);
8994 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8995         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8996                                 queue, "queue");
8997 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8998         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8999                                 queue_num, RTE_UINT8);
9000 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9001         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9002                                 rate, "rate");
9003 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9004         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9005                                 rate_num, RTE_UINT16);
9006
9007 cmdline_parse_inst_t cmd_queue_rate_limit = {
9008         .f = cmd_queue_rate_limit_parsed,
9009         .data = (void *)0,
9010         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9011                 "Set rate limit for a queue on port_id",
9012         .tokens = {
9013                 (void *)&cmd_queue_rate_limit_set,
9014                 (void *)&cmd_queue_rate_limit_port,
9015                 (void *)&cmd_queue_rate_limit_portnum,
9016                 (void *)&cmd_queue_rate_limit_queue,
9017                 (void *)&cmd_queue_rate_limit_queuenum,
9018                 (void *)&cmd_queue_rate_limit_rate,
9019                 (void *)&cmd_queue_rate_limit_ratenum,
9020                 NULL,
9021         },
9022 };
9023
9024 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9025 struct cmd_vf_rate_limit_result {
9026         cmdline_fixed_string_t set;
9027         cmdline_fixed_string_t port;
9028         uint16_t port_num;
9029         cmdline_fixed_string_t vf;
9030         uint8_t vf_num;
9031         cmdline_fixed_string_t rate;
9032         uint16_t rate_num;
9033         cmdline_fixed_string_t q_msk;
9034         uint64_t q_msk_val;
9035 };
9036
9037 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9038                 __rte_unused struct cmdline *cl,
9039                 __rte_unused void *data)
9040 {
9041         struct cmd_vf_rate_limit_result *res = parsed_result;
9042         int ret = 0;
9043
9044         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9045                 && (strcmp(res->vf, "vf") == 0)
9046                 && (strcmp(res->rate, "rate") == 0)
9047                 && (strcmp(res->q_msk, "queue_mask") == 0))
9048                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9049                                         res->rate_num, res->q_msk_val);
9050         if (ret < 0)
9051                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9052
9053 }
9054
9055 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9056         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9057                                 set, "set");
9058 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9059         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9060                                 port, "port");
9061 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9062         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9063                                 port_num, RTE_UINT16);
9064 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9065         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9066                                 vf, "vf");
9067 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9068         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9069                                 vf_num, RTE_UINT8);
9070 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9071         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9072                                 rate, "rate");
9073 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9074         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9075                                 rate_num, RTE_UINT16);
9076 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9077         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9078                                 q_msk, "queue_mask");
9079 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9080         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9081                                 q_msk_val, RTE_UINT64);
9082
9083 cmdline_parse_inst_t cmd_vf_rate_limit = {
9084         .f = cmd_vf_rate_limit_parsed,
9085         .data = (void *)0,
9086         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9087                 "queue_mask <queue_mask_value>: "
9088                 "Set rate limit for queues of VF on port_id",
9089         .tokens = {
9090                 (void *)&cmd_vf_rate_limit_set,
9091                 (void *)&cmd_vf_rate_limit_port,
9092                 (void *)&cmd_vf_rate_limit_portnum,
9093                 (void *)&cmd_vf_rate_limit_vf,
9094                 (void *)&cmd_vf_rate_limit_vfnum,
9095                 (void *)&cmd_vf_rate_limit_rate,
9096                 (void *)&cmd_vf_rate_limit_ratenum,
9097                 (void *)&cmd_vf_rate_limit_q_msk,
9098                 (void *)&cmd_vf_rate_limit_q_msk_val,
9099                 NULL,
9100         },
9101 };
9102
9103 /* *** CONFIGURE TUNNEL UDP PORT *** */
9104 struct cmd_tunnel_udp_config {
9105         cmdline_fixed_string_t cmd;
9106         cmdline_fixed_string_t what;
9107         uint16_t udp_port;
9108         portid_t port_id;
9109 };
9110
9111 static void
9112 cmd_tunnel_udp_config_parsed(void *parsed_result,
9113                           __rte_unused struct cmdline *cl,
9114                           __rte_unused void *data)
9115 {
9116         struct cmd_tunnel_udp_config *res = parsed_result;
9117         struct rte_eth_udp_tunnel tunnel_udp;
9118         int ret;
9119
9120         tunnel_udp.udp_port = res->udp_port;
9121
9122         if (!strcmp(res->cmd, "rx_vxlan_port"))
9123                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9124
9125         if (!strcmp(res->what, "add"))
9126                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9127                                                       &tunnel_udp);
9128         else
9129                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9130                                                          &tunnel_udp);
9131
9132         if (ret < 0)
9133                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9134 }
9135
9136 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9137         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9138                                 cmd, "rx_vxlan_port");
9139 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9140         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9141                                 what, "add#rm");
9142 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9143         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9144                                 udp_port, RTE_UINT16);
9145 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9146         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9147                                 port_id, RTE_UINT16);
9148
9149 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9150         .f = cmd_tunnel_udp_config_parsed,
9151         .data = (void *)0,
9152         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9153                 "Add/Remove a tunneling UDP port filter",
9154         .tokens = {
9155                 (void *)&cmd_tunnel_udp_config_cmd,
9156                 (void *)&cmd_tunnel_udp_config_what,
9157                 (void *)&cmd_tunnel_udp_config_udp_port,
9158                 (void *)&cmd_tunnel_udp_config_port_id,
9159                 NULL,
9160         },
9161 };
9162
9163 struct cmd_config_tunnel_udp_port {
9164         cmdline_fixed_string_t port;
9165         cmdline_fixed_string_t config;
9166         portid_t port_id;
9167         cmdline_fixed_string_t udp_tunnel_port;
9168         cmdline_fixed_string_t action;
9169         cmdline_fixed_string_t tunnel_type;
9170         uint16_t udp_port;
9171 };
9172
9173 static void
9174 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9175                                __rte_unused struct cmdline *cl,
9176                                __rte_unused void *data)
9177 {
9178         struct cmd_config_tunnel_udp_port *res = parsed_result;
9179         struct rte_eth_udp_tunnel tunnel_udp;
9180         int ret = 0;
9181
9182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9183                 return;
9184
9185         tunnel_udp.udp_port = res->udp_port;
9186
9187         if (!strcmp(res->tunnel_type, "vxlan")) {
9188                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9189         } else if (!strcmp(res->tunnel_type, "geneve")) {
9190                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9191         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9192                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9193         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9194                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9195         } else {
9196                 printf("Invalid tunnel type\n");
9197                 return;
9198         }
9199
9200         if (!strcmp(res->action, "add"))
9201                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9202                                                       &tunnel_udp);
9203         else
9204                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9205                                                          &tunnel_udp);
9206
9207         if (ret < 0)
9208                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9209 }
9210
9211 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9212         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9213                                  "port");
9214 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9215         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9216                                  "config");
9217 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9218         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9219                               RTE_UINT16);
9220 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9221         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9222                                  udp_tunnel_port,
9223                                  "udp_tunnel_port");
9224 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9225         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9226                                  "add#rm");
9227 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9228         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9229                                  "vxlan#geneve#vxlan-gpe#ecpri");
9230 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9231         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9232                               RTE_UINT16);
9233
9234 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9235         .f = cmd_cfg_tunnel_udp_port_parsed,
9236         .data = NULL,
9237         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9238                 "geneve|vxlan-gpe|ecpri <udp_port>",
9239         .tokens = {
9240                 (void *)&cmd_config_tunnel_udp_port_port,
9241                 (void *)&cmd_config_tunnel_udp_port_config,
9242                 (void *)&cmd_config_tunnel_udp_port_port_id,
9243                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9244                 (void *)&cmd_config_tunnel_udp_port_action,
9245                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9246                 (void *)&cmd_config_tunnel_udp_port_value,
9247                 NULL,
9248         },
9249 };
9250
9251 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9252 struct cmd_set_mirror_mask_result {
9253         cmdline_fixed_string_t set;
9254         cmdline_fixed_string_t port;
9255         portid_t port_id;
9256         cmdline_fixed_string_t mirror;
9257         uint8_t rule_id;
9258         cmdline_fixed_string_t what;
9259         cmdline_fixed_string_t value;
9260         cmdline_fixed_string_t dstpool;
9261         uint8_t dstpool_id;
9262         cmdline_fixed_string_t on;
9263 };
9264
9265 cmdline_parse_token_string_t cmd_mirror_mask_set =
9266         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9267                                 set, "set");
9268 cmdline_parse_token_string_t cmd_mirror_mask_port =
9269         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9270                                 port, "port");
9271 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9272         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9273                                 port_id, RTE_UINT16);
9274 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9275         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9276                                 mirror, "mirror-rule");
9277 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9278         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9279                                 rule_id, RTE_UINT8);
9280 cmdline_parse_token_string_t cmd_mirror_mask_what =
9281         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9282                                 what, "pool-mirror-up#pool-mirror-down"
9283                                       "#vlan-mirror");
9284 cmdline_parse_token_string_t cmd_mirror_mask_value =
9285         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9286                                 value, NULL);
9287 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9288         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9289                                 dstpool, "dst-pool");
9290 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9291         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9292                                 dstpool_id, RTE_UINT8);
9293 cmdline_parse_token_string_t cmd_mirror_mask_on =
9294         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9295                                 on, "on#off");
9296
9297 static void
9298 cmd_set_mirror_mask_parsed(void *parsed_result,
9299                        __rte_unused struct cmdline *cl,
9300                        __rte_unused void *data)
9301 {
9302         int ret,nb_item,i;
9303         struct cmd_set_mirror_mask_result *res = parsed_result;
9304         struct rte_eth_mirror_conf mr_conf;
9305
9306         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9307
9308         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9309
9310         mr_conf.dst_pool = res->dstpool_id;
9311
9312         if (!strcmp(res->what, "pool-mirror-up")) {
9313                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9314                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9315         } else if (!strcmp(res->what, "pool-mirror-down")) {
9316                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9317                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9318         } else if (!strcmp(res->what, "vlan-mirror")) {
9319                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9320                 nb_item = parse_item_list(res->value, "vlan",
9321                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9322                 if (nb_item <= 0)
9323                         return;
9324
9325                 for (i = 0; i < nb_item; i++) {
9326                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9327                                 printf("Invalid vlan_id: must be < 4096\n");
9328                                 return;
9329                         }
9330
9331                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9332                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9333                 }
9334         }
9335
9336         if (!strcmp(res->on, "on"))
9337                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9338                                                 res->rule_id, 1);
9339         else
9340                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9341                                                 res->rule_id, 0);
9342         if (ret < 0)
9343                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9344 }
9345
9346 cmdline_parse_inst_t cmd_set_mirror_mask = {
9347                 .f = cmd_set_mirror_mask_parsed,
9348                 .data = NULL,
9349                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9350                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9351                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9352                 .tokens = {
9353                         (void *)&cmd_mirror_mask_set,
9354                         (void *)&cmd_mirror_mask_port,
9355                         (void *)&cmd_mirror_mask_portid,
9356                         (void *)&cmd_mirror_mask_mirror,
9357                         (void *)&cmd_mirror_mask_ruleid,
9358                         (void *)&cmd_mirror_mask_what,
9359                         (void *)&cmd_mirror_mask_value,
9360                         (void *)&cmd_mirror_mask_dstpool,
9361                         (void *)&cmd_mirror_mask_poolid,
9362                         (void *)&cmd_mirror_mask_on,
9363                         NULL,
9364                 },
9365 };
9366
9367 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9368 struct cmd_set_mirror_link_result {
9369         cmdline_fixed_string_t set;
9370         cmdline_fixed_string_t port;
9371         portid_t port_id;
9372         cmdline_fixed_string_t mirror;
9373         uint8_t rule_id;
9374         cmdline_fixed_string_t what;
9375         cmdline_fixed_string_t dstpool;
9376         uint8_t dstpool_id;
9377         cmdline_fixed_string_t on;
9378 };
9379
9380 cmdline_parse_token_string_t cmd_mirror_link_set =
9381         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9382                                  set, "set");
9383 cmdline_parse_token_string_t cmd_mirror_link_port =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9385                                 port, "port");
9386 cmdline_parse_token_num_t cmd_mirror_link_portid =
9387         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9388                                 port_id, RTE_UINT16);
9389 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9390         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9391                                 mirror, "mirror-rule");
9392 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9393         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9394                             rule_id, RTE_UINT8);
9395 cmdline_parse_token_string_t cmd_mirror_link_what =
9396         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9397                                 what, "uplink-mirror#downlink-mirror");
9398 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9399         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9400                                 dstpool, "dst-pool");
9401 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9402         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9403                                 dstpool_id, RTE_UINT8);
9404 cmdline_parse_token_string_t cmd_mirror_link_on =
9405         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9406                                 on, "on#off");
9407
9408 static void
9409 cmd_set_mirror_link_parsed(void *parsed_result,
9410                        __rte_unused struct cmdline *cl,
9411                        __rte_unused void *data)
9412 {
9413         int ret;
9414         struct cmd_set_mirror_link_result *res = parsed_result;
9415         struct rte_eth_mirror_conf mr_conf;
9416
9417         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9418         if (!strcmp(res->what, "uplink-mirror"))
9419                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9420         else
9421                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9422
9423         mr_conf.dst_pool = res->dstpool_id;
9424
9425         if (!strcmp(res->on, "on"))
9426                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9427                                                 res->rule_id, 1);
9428         else
9429                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9430                                                 res->rule_id, 0);
9431
9432         /* check the return value and print it if is < 0 */
9433         if (ret < 0)
9434                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9435
9436 }
9437
9438 cmdline_parse_inst_t cmd_set_mirror_link = {
9439                 .f = cmd_set_mirror_link_parsed,
9440                 .data = NULL,
9441                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9442                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9443                 .tokens = {
9444                         (void *)&cmd_mirror_link_set,
9445                         (void *)&cmd_mirror_link_port,
9446                         (void *)&cmd_mirror_link_portid,
9447                         (void *)&cmd_mirror_link_mirror,
9448                         (void *)&cmd_mirror_link_ruleid,
9449                         (void *)&cmd_mirror_link_what,
9450                         (void *)&cmd_mirror_link_dstpool,
9451                         (void *)&cmd_mirror_link_poolid,
9452                         (void *)&cmd_mirror_link_on,
9453                         NULL,
9454                 },
9455 };
9456
9457 /* *** RESET VM MIRROR RULE *** */
9458 struct cmd_rm_mirror_rule_result {
9459         cmdline_fixed_string_t reset;
9460         cmdline_fixed_string_t port;
9461         portid_t port_id;
9462         cmdline_fixed_string_t mirror;
9463         uint8_t rule_id;
9464 };
9465
9466 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9467         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9468                                  reset, "reset");
9469 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9470         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9471                                 port, "port");
9472 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9473         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9474                                 port_id, RTE_UINT16);
9475 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9476         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9477                                 mirror, "mirror-rule");
9478 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9479         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9480                                 rule_id, RTE_UINT8);
9481
9482 static void
9483 cmd_reset_mirror_rule_parsed(void *parsed_result,
9484                        __rte_unused struct cmdline *cl,
9485                        __rte_unused void *data)
9486 {
9487         int ret;
9488         struct cmd_set_mirror_link_result *res = parsed_result;
9489         /* check rule_id */
9490         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9491         if(ret < 0)
9492                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9493 }
9494
9495 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9496                 .f = cmd_reset_mirror_rule_parsed,
9497                 .data = NULL,
9498                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9499                 .tokens = {
9500                         (void *)&cmd_rm_mirror_rule_reset,
9501                         (void *)&cmd_rm_mirror_rule_port,
9502                         (void *)&cmd_rm_mirror_rule_portid,
9503                         (void *)&cmd_rm_mirror_rule_mirror,
9504                         (void *)&cmd_rm_mirror_rule_ruleid,
9505                         NULL,
9506                 },
9507 };
9508
9509 /* ******************************************************************************** */
9510
9511 struct cmd_dump_result {
9512         cmdline_fixed_string_t dump;
9513 };
9514
9515 static void
9516 dump_struct_sizes(void)
9517 {
9518 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9519         DUMP_SIZE(struct rte_mbuf);
9520         DUMP_SIZE(struct rte_mempool);
9521         DUMP_SIZE(struct rte_ring);
9522 #undef DUMP_SIZE
9523 }
9524
9525
9526 /* Dump the socket memory statistics on console */
9527 static void
9528 dump_socket_mem(FILE *f)
9529 {
9530         struct rte_malloc_socket_stats socket_stats;
9531         unsigned int i;
9532         size_t total = 0;
9533         size_t alloc = 0;
9534         size_t free = 0;
9535         unsigned int n_alloc = 0;
9536         unsigned int n_free = 0;
9537         static size_t last_allocs;
9538         static size_t last_total;
9539
9540
9541         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9542                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9543                     !socket_stats.heap_totalsz_bytes)
9544                         continue;
9545                 total += socket_stats.heap_totalsz_bytes;
9546                 alloc += socket_stats.heap_allocsz_bytes;
9547                 free += socket_stats.heap_freesz_bytes;
9548                 n_alloc += socket_stats.alloc_count;
9549                 n_free += socket_stats.free_count;
9550                 fprintf(f,
9551                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9552                         i,
9553                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9554                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9555                         (double)socket_stats.heap_allocsz_bytes * 100 /
9556                         (double)socket_stats.heap_totalsz_bytes,
9557                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9558                         socket_stats.alloc_count,
9559                         socket_stats.free_count);
9560         }
9561         fprintf(f,
9562                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9563                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9564                 (double)alloc * 100 / (double)total,
9565                 (double)free / (1024 * 1024),
9566                 n_alloc, n_free);
9567         if (last_allocs)
9568                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9569                         ((double)total - (double)last_total) / (1024 * 1024),
9570                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9571         last_allocs = alloc;
9572         last_total = total;
9573 }
9574
9575 static void cmd_dump_parsed(void *parsed_result,
9576                             __rte_unused struct cmdline *cl,
9577                             __rte_unused void *data)
9578 {
9579         struct cmd_dump_result *res = parsed_result;
9580
9581         if (!strcmp(res->dump, "dump_physmem"))
9582                 rte_dump_physmem_layout(stdout);
9583         else if (!strcmp(res->dump, "dump_socket_mem"))
9584                 dump_socket_mem(stdout);
9585         else if (!strcmp(res->dump, "dump_memzone"))
9586                 rte_memzone_dump(stdout);
9587         else if (!strcmp(res->dump, "dump_struct_sizes"))
9588                 dump_struct_sizes();
9589         else if (!strcmp(res->dump, "dump_ring"))
9590                 rte_ring_list_dump(stdout);
9591         else if (!strcmp(res->dump, "dump_mempool"))
9592                 rte_mempool_list_dump(stdout);
9593         else if (!strcmp(res->dump, "dump_devargs"))
9594                 rte_devargs_dump(stdout);
9595         else if (!strcmp(res->dump, "dump_log_types"))
9596                 rte_log_dump(stdout);
9597 }
9598
9599 cmdline_parse_token_string_t cmd_dump_dump =
9600         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9601                 "dump_physmem#"
9602                 "dump_memzone#"
9603                 "dump_socket_mem#"
9604                 "dump_struct_sizes#"
9605                 "dump_ring#"
9606                 "dump_mempool#"
9607                 "dump_devargs#"
9608                 "dump_log_types");
9609
9610 cmdline_parse_inst_t cmd_dump = {
9611         .f = cmd_dump_parsed,  /* function to call */
9612         .data = NULL,      /* 2nd arg of func */
9613         .help_str = "Dump status",
9614         .tokens = {        /* token list, NULL terminated */
9615                 (void *)&cmd_dump_dump,
9616                 NULL,
9617         },
9618 };
9619
9620 /* ******************************************************************************** */
9621
9622 struct cmd_dump_one_result {
9623         cmdline_fixed_string_t dump;
9624         cmdline_fixed_string_t name;
9625 };
9626
9627 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9628                                 __rte_unused void *data)
9629 {
9630         struct cmd_dump_one_result *res = parsed_result;
9631
9632         if (!strcmp(res->dump, "dump_ring")) {
9633                 struct rte_ring *r;
9634                 r = rte_ring_lookup(res->name);
9635                 if (r == NULL) {
9636                         cmdline_printf(cl, "Cannot find ring\n");
9637                         return;
9638                 }
9639                 rte_ring_dump(stdout, r);
9640         } else if (!strcmp(res->dump, "dump_mempool")) {
9641                 struct rte_mempool *mp;
9642                 mp = rte_mempool_lookup(res->name);
9643                 if (mp == NULL) {
9644                         cmdline_printf(cl, "Cannot find mempool\n");
9645                         return;
9646                 }
9647                 rte_mempool_dump(stdout, mp);
9648         }
9649 }
9650
9651 cmdline_parse_token_string_t cmd_dump_one_dump =
9652         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9653                                  "dump_ring#dump_mempool");
9654
9655 cmdline_parse_token_string_t cmd_dump_one_name =
9656         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9657
9658 cmdline_parse_inst_t cmd_dump_one = {
9659         .f = cmd_dump_one_parsed,  /* function to call */
9660         .data = NULL,      /* 2nd arg of func */
9661         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9662         .tokens = {        /* token list, NULL terminated */
9663                 (void *)&cmd_dump_one_dump,
9664                 (void *)&cmd_dump_one_name,
9665                 NULL,
9666         },
9667 };
9668
9669 /* *** queue region set *** */
9670 struct cmd_queue_region_result {
9671         cmdline_fixed_string_t set;
9672         cmdline_fixed_string_t port;
9673         portid_t port_id;
9674         cmdline_fixed_string_t cmd;
9675         cmdline_fixed_string_t region;
9676         uint8_t  region_id;
9677         cmdline_fixed_string_t queue_start_index;
9678         uint8_t  queue_id;
9679         cmdline_fixed_string_t queue_num;
9680         uint8_t  queue_num_value;
9681 };
9682
9683 static void
9684 cmd_queue_region_parsed(void *parsed_result,
9685                         __rte_unused struct cmdline *cl,
9686                         __rte_unused void *data)
9687 {
9688         struct cmd_queue_region_result *res = parsed_result;
9689         int ret = -ENOTSUP;
9690 #ifdef RTE_NET_I40E
9691         struct rte_pmd_i40e_queue_region_conf region_conf;
9692         enum rte_pmd_i40e_queue_region_op op_type;
9693 #endif
9694
9695         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9696                 return;
9697
9698 #ifdef RTE_NET_I40E
9699         memset(&region_conf, 0, sizeof(region_conf));
9700         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9701         region_conf.region_id = res->region_id;
9702         region_conf.queue_num = res->queue_num_value;
9703         region_conf.queue_start_index = res->queue_id;
9704
9705         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9706                                 op_type, &region_conf);
9707 #endif
9708
9709         switch (ret) {
9710         case 0:
9711                 break;
9712         case -ENOTSUP:
9713                 printf("function not implemented or supported\n");
9714                 break;
9715         default:
9716                 printf("queue region config error: (%s)\n", strerror(-ret));
9717         }
9718 }
9719
9720 cmdline_parse_token_string_t cmd_queue_region_set =
9721 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9722                 set, "set");
9723 cmdline_parse_token_string_t cmd_queue_region_port =
9724         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9725 cmdline_parse_token_num_t cmd_queue_region_port_id =
9726         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9727                                 port_id, RTE_UINT16);
9728 cmdline_parse_token_string_t cmd_queue_region_cmd =
9729         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9730                                  cmd, "queue-region");
9731 cmdline_parse_token_string_t cmd_queue_region_id =
9732         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9733                                 region, "region_id");
9734 cmdline_parse_token_num_t cmd_queue_region_index =
9735         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9736                                 region_id, RTE_UINT8);
9737 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9738         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9739                                 queue_start_index, "queue_start_index");
9740 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9741         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9742                                 queue_id, RTE_UINT8);
9743 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9744         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9745                                 queue_num, "queue_num");
9746 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9747         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9748                                 queue_num_value, RTE_UINT8);
9749
9750 cmdline_parse_inst_t cmd_queue_region = {
9751         .f = cmd_queue_region_parsed,
9752         .data = NULL,
9753         .help_str = "set port <port_id> queue-region region_id <value> "
9754                 "queue_start_index <value> queue_num <value>: Set a queue region",
9755         .tokens = {
9756                 (void *)&cmd_queue_region_set,
9757                 (void *)&cmd_queue_region_port,
9758                 (void *)&cmd_queue_region_port_id,
9759                 (void *)&cmd_queue_region_cmd,
9760                 (void *)&cmd_queue_region_id,
9761                 (void *)&cmd_queue_region_index,
9762                 (void *)&cmd_queue_region_queue_start_index,
9763                 (void *)&cmd_queue_region_queue_id,
9764                 (void *)&cmd_queue_region_queue_num,
9765                 (void *)&cmd_queue_region_queue_num_value,
9766                 NULL,
9767         },
9768 };
9769
9770 /* *** queue region and flowtype set *** */
9771 struct cmd_region_flowtype_result {
9772         cmdline_fixed_string_t set;
9773         cmdline_fixed_string_t port;
9774         portid_t port_id;
9775         cmdline_fixed_string_t cmd;
9776         cmdline_fixed_string_t region;
9777         uint8_t  region_id;
9778         cmdline_fixed_string_t flowtype;
9779         uint8_t  flowtype_id;
9780 };
9781
9782 static void
9783 cmd_region_flowtype_parsed(void *parsed_result,
9784                         __rte_unused struct cmdline *cl,
9785                         __rte_unused void *data)
9786 {
9787         struct cmd_region_flowtype_result *res = parsed_result;
9788         int ret = -ENOTSUP;
9789 #ifdef RTE_NET_I40E
9790         struct rte_pmd_i40e_queue_region_conf region_conf;
9791         enum rte_pmd_i40e_queue_region_op op_type;
9792 #endif
9793
9794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9795                 return;
9796
9797 #ifdef RTE_NET_I40E
9798         memset(&region_conf, 0, sizeof(region_conf));
9799
9800         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9801         region_conf.region_id = res->region_id;
9802         region_conf.hw_flowtype = res->flowtype_id;
9803
9804         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9805                         op_type, &region_conf);
9806 #endif
9807
9808         switch (ret) {
9809         case 0:
9810                 break;
9811         case -ENOTSUP:
9812                 printf("function not implemented or supported\n");
9813                 break;
9814         default:
9815                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9816         }
9817 }
9818
9819 cmdline_parse_token_string_t cmd_region_flowtype_set =
9820 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9821                                 set, "set");
9822 cmdline_parse_token_string_t cmd_region_flowtype_port =
9823         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9824                                 port, "port");
9825 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9826         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9827                                 port_id, RTE_UINT16);
9828 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9829         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9830                                 cmd, "queue-region");
9831 cmdline_parse_token_string_t cmd_region_flowtype_index =
9832         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9833                                 region, "region_id");
9834 cmdline_parse_token_num_t cmd_region_flowtype_id =
9835         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9836                                 region_id, RTE_UINT8);
9837 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9838         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9839                                 flowtype, "flowtype");
9840 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9841         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9842                                 flowtype_id, RTE_UINT8);
9843 cmdline_parse_inst_t cmd_region_flowtype = {
9844         .f = cmd_region_flowtype_parsed,
9845         .data = NULL,
9846         .help_str = "set port <port_id> queue-region region_id <value> "
9847                 "flowtype <value>: Set a flowtype region index",
9848         .tokens = {
9849                 (void *)&cmd_region_flowtype_set,
9850                 (void *)&cmd_region_flowtype_port,
9851                 (void *)&cmd_region_flowtype_port_index,
9852                 (void *)&cmd_region_flowtype_cmd,
9853                 (void *)&cmd_region_flowtype_index,
9854                 (void *)&cmd_region_flowtype_id,
9855                 (void *)&cmd_region_flowtype_flow_index,
9856                 (void *)&cmd_region_flowtype_flow_id,
9857                 NULL,
9858         },
9859 };
9860
9861 /* *** User Priority (UP) to queue region (region_id) set *** */
9862 struct cmd_user_priority_region_result {
9863         cmdline_fixed_string_t set;
9864         cmdline_fixed_string_t port;
9865         portid_t port_id;
9866         cmdline_fixed_string_t cmd;
9867         cmdline_fixed_string_t user_priority;
9868         uint8_t  user_priority_id;
9869         cmdline_fixed_string_t region;
9870         uint8_t  region_id;
9871 };
9872
9873 static void
9874 cmd_user_priority_region_parsed(void *parsed_result,
9875                         __rte_unused struct cmdline *cl,
9876                         __rte_unused void *data)
9877 {
9878         struct cmd_user_priority_region_result *res = parsed_result;
9879         int ret = -ENOTSUP;
9880 #ifdef RTE_NET_I40E
9881         struct rte_pmd_i40e_queue_region_conf region_conf;
9882         enum rte_pmd_i40e_queue_region_op op_type;
9883 #endif
9884
9885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9886                 return;
9887
9888 #ifdef RTE_NET_I40E
9889         memset(&region_conf, 0, sizeof(region_conf));
9890         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9891         region_conf.user_priority = res->user_priority_id;
9892         region_conf.region_id = res->region_id;
9893
9894         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9895                                 op_type, &region_conf);
9896 #endif
9897
9898         switch (ret) {
9899         case 0:
9900                 break;
9901         case -ENOTSUP:
9902                 printf("function not implemented or supported\n");
9903                 break;
9904         default:
9905                 printf("user_priority region config error: (%s)\n",
9906                                 strerror(-ret));
9907         }
9908 }
9909
9910 cmdline_parse_token_string_t cmd_user_priority_region_set =
9911         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9912                                 set, "set");
9913 cmdline_parse_token_string_t cmd_user_priority_region_port =
9914         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9915                                 port, "port");
9916 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9917         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9918                                 port_id, RTE_UINT16);
9919 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9920         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9921                                 cmd, "queue-region");
9922 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9923         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9924                                 user_priority, "UP");
9925 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9926         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9927                                 user_priority_id, RTE_UINT8);
9928 cmdline_parse_token_string_t cmd_user_priority_region_region =
9929         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9930                                 region, "region_id");
9931 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9932         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9933                                 region_id, RTE_UINT8);
9934
9935 cmdline_parse_inst_t cmd_user_priority_region = {
9936         .f = cmd_user_priority_region_parsed,
9937         .data = NULL,
9938         .help_str = "set port <port_id> queue-region UP <value> "
9939                 "region_id <value>: Set the mapping of User Priority (UP) "
9940                 "to queue region (region_id) ",
9941         .tokens = {
9942                 (void *)&cmd_user_priority_region_set,
9943                 (void *)&cmd_user_priority_region_port,
9944                 (void *)&cmd_user_priority_region_port_index,
9945                 (void *)&cmd_user_priority_region_cmd,
9946                 (void *)&cmd_user_priority_region_UP,
9947                 (void *)&cmd_user_priority_region_UP_id,
9948                 (void *)&cmd_user_priority_region_region,
9949                 (void *)&cmd_user_priority_region_region_id,
9950                 NULL,
9951         },
9952 };
9953
9954 /* *** flush all queue region related configuration *** */
9955 struct cmd_flush_queue_region_result {
9956         cmdline_fixed_string_t set;
9957         cmdline_fixed_string_t port;
9958         portid_t port_id;
9959         cmdline_fixed_string_t cmd;
9960         cmdline_fixed_string_t flush;
9961         cmdline_fixed_string_t what;
9962 };
9963
9964 static void
9965 cmd_flush_queue_region_parsed(void *parsed_result,
9966                         __rte_unused struct cmdline *cl,
9967                         __rte_unused void *data)
9968 {
9969         struct cmd_flush_queue_region_result *res = parsed_result;
9970         int ret = -ENOTSUP;
9971 #ifdef RTE_NET_I40E
9972         struct rte_pmd_i40e_queue_region_conf region_conf;
9973         enum rte_pmd_i40e_queue_region_op op_type;
9974 #endif
9975
9976         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9977                 return;
9978
9979 #ifdef RTE_NET_I40E
9980         memset(&region_conf, 0, sizeof(region_conf));
9981
9982         if (strcmp(res->what, "on") == 0)
9983                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9984         else
9985                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9986
9987         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9988                                 op_type, &region_conf);
9989 #endif
9990
9991         switch (ret) {
9992         case 0:
9993                 break;
9994         case -ENOTSUP:
9995                 printf("function not implemented or supported\n");
9996                 break;
9997         default:
9998                 printf("queue region config flush error: (%s)\n",
9999                                 strerror(-ret));
10000         }
10001 }
10002
10003 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10004         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10005                                 set, "set");
10006 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10007         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10008                                 port, "port");
10009 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10010         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10011                                 port_id, RTE_UINT16);
10012 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10013         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10014                                 cmd, "queue-region");
10015 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10016         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10017                                 flush, "flush");
10018 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10019         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10020                                 what, "on#off");
10021
10022 cmdline_parse_inst_t cmd_flush_queue_region = {
10023         .f = cmd_flush_queue_region_parsed,
10024         .data = NULL,
10025         .help_str = "set port <port_id> queue-region flush on|off"
10026                 ": flush all queue region related configuration",
10027         .tokens = {
10028                 (void *)&cmd_flush_queue_region_set,
10029                 (void *)&cmd_flush_queue_region_port,
10030                 (void *)&cmd_flush_queue_region_port_index,
10031                 (void *)&cmd_flush_queue_region_cmd,
10032                 (void *)&cmd_flush_queue_region_flush,
10033                 (void *)&cmd_flush_queue_region_what,
10034                 NULL,
10035         },
10036 };
10037
10038 /* *** get all queue region related configuration info *** */
10039 struct cmd_show_queue_region_info {
10040         cmdline_fixed_string_t show;
10041         cmdline_fixed_string_t port;
10042         portid_t port_id;
10043         cmdline_fixed_string_t cmd;
10044 };
10045
10046 static void
10047 cmd_show_queue_region_info_parsed(void *parsed_result,
10048                         __rte_unused struct cmdline *cl,
10049                         __rte_unused void *data)
10050 {
10051         struct cmd_show_queue_region_info *res = parsed_result;
10052         int ret = -ENOTSUP;
10053 #ifdef RTE_NET_I40E
10054         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10055         enum rte_pmd_i40e_queue_region_op op_type;
10056 #endif
10057
10058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10059                 return;
10060
10061 #ifdef RTE_NET_I40E
10062         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10063
10064         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10065
10066         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10067                                         op_type, &rte_pmd_regions);
10068
10069         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10070 #endif
10071
10072         switch (ret) {
10073         case 0:
10074                 break;
10075         case -ENOTSUP:
10076                 printf("function not implemented or supported\n");
10077                 break;
10078         default:
10079                 printf("queue region config info show error: (%s)\n",
10080                                 strerror(-ret));
10081         }
10082 }
10083
10084 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10085 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10086                                 show, "show");
10087 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10088         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10089                                 port, "port");
10090 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10091         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10092                                 port_id, RTE_UINT16);
10093 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10094         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10095                                 cmd, "queue-region");
10096
10097 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10098         .f = cmd_show_queue_region_info_parsed,
10099         .data = NULL,
10100         .help_str = "show port <port_id> queue-region"
10101                 ": show all queue region related configuration info",
10102         .tokens = {
10103                 (void *)&cmd_show_queue_region_info_get,
10104                 (void *)&cmd_show_queue_region_info_port,
10105                 (void *)&cmd_show_queue_region_info_port_index,
10106                 (void *)&cmd_show_queue_region_info_cmd,
10107                 NULL,
10108         },
10109 };
10110
10111 /* *** Filters Control *** */
10112
10113 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10114 do { \
10115         if ((ip_addr).family == AF_INET) \
10116                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10117         else { \
10118                 printf("invalid parameter.\n"); \
10119                 return; \
10120         } \
10121 } while (0)
10122
10123 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10124 do { \
10125         if ((ip_addr).family == AF_INET6) \
10126                 rte_memcpy(&(ip), \
10127                                  &((ip_addr).addr.ipv6), \
10128                                  sizeof(struct in6_addr)); \
10129         else { \
10130                 printf("invalid parameter.\n"); \
10131                 return; \
10132         } \
10133 } while (0)
10134
10135 #ifdef RTE_NET_I40E
10136
10137 static uint16_t
10138 str2flowtype(char *string)
10139 {
10140         uint8_t i = 0;
10141         static const struct {
10142                 char str[32];
10143                 uint16_t type;
10144         } flowtype_str[] = {
10145                 {"raw", RTE_ETH_FLOW_RAW},
10146                 {"ipv4", RTE_ETH_FLOW_IPV4},
10147                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10148                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10149                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10150                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10151                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10152                 {"ipv6", RTE_ETH_FLOW_IPV6},
10153                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10154                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10155                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10156                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10157                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10158                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10159         };
10160
10161         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10162                 if (!strcmp(flowtype_str[i].str, string))
10163                         return flowtype_str[i].type;
10164         }
10165
10166         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10167                 return (uint16_t)atoi(string);
10168
10169         return RTE_ETH_FLOW_UNKNOWN;
10170 }
10171
10172 /* *** deal with flow director filter *** */
10173 struct cmd_flow_director_result {
10174         cmdline_fixed_string_t flow_director_filter;
10175         portid_t port_id;
10176         cmdline_fixed_string_t mode;
10177         cmdline_fixed_string_t mode_value;
10178         cmdline_fixed_string_t ops;
10179         cmdline_fixed_string_t flow;
10180         cmdline_fixed_string_t flow_type;
10181         cmdline_fixed_string_t drop;
10182         cmdline_fixed_string_t queue;
10183         uint16_t  queue_id;
10184         cmdline_fixed_string_t fd_id;
10185         uint32_t  fd_id_value;
10186         cmdline_fixed_string_t packet;
10187         char filepath[];
10188 };
10189
10190 static void
10191 cmd_flow_director_filter_parsed(void *parsed_result,
10192                           __rte_unused struct cmdline *cl,
10193                           __rte_unused void *data)
10194 {
10195         struct cmd_flow_director_result *res = parsed_result;
10196         int ret = 0;
10197         struct rte_pmd_i40e_flow_type_mapping
10198                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10199         struct rte_pmd_i40e_pkt_template_conf conf;
10200         uint16_t flow_type = str2flowtype(res->flow_type);
10201         uint16_t i, port = res->port_id;
10202         uint8_t add;
10203
10204         memset(&conf, 0, sizeof(conf));
10205
10206         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10207                 printf("Invalid flow type specified.\n");
10208                 return;
10209         }
10210         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10211                                                  mapping);
10212         if (ret)
10213                 return;
10214         if (mapping[flow_type].pctype == 0ULL) {
10215                 printf("Invalid flow type specified.\n");
10216                 return;
10217         }
10218         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10219                 if (mapping[flow_type].pctype & (1ULL << i)) {
10220                         conf.input.pctype = i;
10221                         break;
10222                 }
10223         }
10224
10225         conf.input.packet = open_file(res->filepath,
10226                                 &conf.input.length);
10227         if (!conf.input.packet)
10228                 return;
10229         if (!strcmp(res->drop, "drop"))
10230                 conf.action.behavior =
10231                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10232         else
10233                 conf.action.behavior =
10234                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10235         conf.action.report_status =
10236                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10237         conf.action.rx_queue = res->queue_id;
10238         conf.soft_id = res->fd_id_value;
10239         add  = strcmp(res->ops, "del") ? 1 : 0;
10240         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10241                                                         &conf,
10242                                                         add);
10243         if (ret < 0)
10244                 printf("flow director config error: (%s)\n",
10245                        strerror(-ret));
10246         close_file(conf.input.packet);
10247 }
10248
10249 cmdline_parse_token_string_t cmd_flow_director_filter =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  flow_director_filter, "flow_director_filter");
10252 cmdline_parse_token_num_t cmd_flow_director_port_id =
10253         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10254                               port_id, RTE_UINT16);
10255 cmdline_parse_token_string_t cmd_flow_director_ops =
10256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10257                                  ops, "add#del#update");
10258 cmdline_parse_token_string_t cmd_flow_director_flow =
10259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10260                                  flow, "flow");
10261 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10263                 flow_type, NULL);
10264 cmdline_parse_token_string_t cmd_flow_director_drop =
10265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10266                                  drop, "drop#fwd");
10267 cmdline_parse_token_string_t cmd_flow_director_queue =
10268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10269                                  queue, "queue");
10270 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10271         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10272                               queue_id, RTE_UINT16);
10273 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10275                                  fd_id, "fd_id");
10276 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10277         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10278                               fd_id_value, RTE_UINT32);
10279
10280 cmdline_parse_token_string_t cmd_flow_director_mode =
10281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10282                                  mode, "mode");
10283 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10285                                  mode_value, "raw");
10286 cmdline_parse_token_string_t cmd_flow_director_packet =
10287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10288                                  packet, "packet");
10289 cmdline_parse_token_string_t cmd_flow_director_filepath =
10290         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10291                                  filepath, NULL);
10292
10293 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10294         .f = cmd_flow_director_filter_parsed,
10295         .data = NULL,
10296         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10297                 "director entry on NIC",
10298         .tokens = {
10299                 (void *)&cmd_flow_director_filter,
10300                 (void *)&cmd_flow_director_port_id,
10301                 (void *)&cmd_flow_director_mode,
10302                 (void *)&cmd_flow_director_mode_raw,
10303                 (void *)&cmd_flow_director_ops,
10304                 (void *)&cmd_flow_director_flow,
10305                 (void *)&cmd_flow_director_flow_type,
10306                 (void *)&cmd_flow_director_drop,
10307                 (void *)&cmd_flow_director_queue,
10308                 (void *)&cmd_flow_director_queue_id,
10309                 (void *)&cmd_flow_director_fd_id,
10310                 (void *)&cmd_flow_director_fd_id_value,
10311                 (void *)&cmd_flow_director_packet,
10312                 (void *)&cmd_flow_director_filepath,
10313                 NULL,
10314         },
10315 };
10316
10317 #endif /* RTE_NET_I40E */
10318
10319 /* *** deal with flow director mask *** */
10320 struct cmd_flow_director_mask_result {
10321         cmdline_fixed_string_t flow_director_mask;
10322         portid_t port_id;
10323         cmdline_fixed_string_t mode;
10324         cmdline_fixed_string_t mode_value;
10325         cmdline_fixed_string_t vlan;
10326         uint16_t vlan_mask;
10327         cmdline_fixed_string_t src_mask;
10328         cmdline_ipaddr_t ipv4_src;
10329         cmdline_ipaddr_t ipv6_src;
10330         uint16_t port_src;
10331         cmdline_fixed_string_t dst_mask;
10332         cmdline_ipaddr_t ipv4_dst;
10333         cmdline_ipaddr_t ipv6_dst;
10334         uint16_t port_dst;
10335         cmdline_fixed_string_t mac;
10336         uint8_t mac_addr_byte_mask;
10337         cmdline_fixed_string_t tunnel_id;
10338         uint32_t tunnel_id_mask;
10339         cmdline_fixed_string_t tunnel_type;
10340         uint8_t tunnel_type_mask;
10341 };
10342
10343 static void
10344 cmd_flow_director_mask_parsed(void *parsed_result,
10345                           __rte_unused struct cmdline *cl,
10346                           __rte_unused void *data)
10347 {
10348         struct cmd_flow_director_mask_result *res = parsed_result;
10349         struct rte_eth_fdir_masks *mask;
10350         struct rte_port *port;
10351
10352         port = &ports[res->port_id];
10353         /** Check if the port is not started **/
10354         if (port->port_status != RTE_PORT_STOPPED) {
10355                 printf("Please stop port %d first\n", res->port_id);
10356                 return;
10357         }
10358
10359         mask = &port->dev_conf.fdir_conf.mask;
10360
10361         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10362                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10363                         printf("Please set mode to MAC-VLAN.\n");
10364                         return;
10365                 }
10366
10367                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10368         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10369                 if (strcmp(res->mode_value, "Tunnel")) {
10370                         printf("Please set mode to Tunnel.\n");
10371                         return;
10372                 }
10373
10374                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10375                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10376                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10377                 mask->tunnel_type_mask = res->tunnel_type_mask;
10378         } else {
10379                 if (strcmp(res->mode_value, "IP")) {
10380                         printf("Please set mode to IP.\n");
10381                         return;
10382                 }
10383
10384                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10385                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10386                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10387                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10388                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10389                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10390                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10391         }
10392
10393         cmd_reconfig_device_queue(res->port_id, 1, 1);
10394 }
10395
10396 cmdline_parse_token_string_t cmd_flow_director_mask =
10397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10398                                  flow_director_mask, "flow_director_mask");
10399 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10400         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10401                               port_id, RTE_UINT16);
10402 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10403         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10404                                  vlan, "vlan");
10405 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10406         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10407                               vlan_mask, RTE_UINT16);
10408 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10409         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10410                                  src_mask, "src_mask");
10411 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10412         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10413                                  ipv4_src);
10414 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10415         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10416                                  ipv6_src);
10417 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10418         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10419                               port_src, RTE_UINT16);
10420 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  dst_mask, "dst_mask");
10423 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10424         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  ipv4_dst);
10426 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10427         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10428                                  ipv6_dst);
10429 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10430         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10431                               port_dst, RTE_UINT16);
10432
10433 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10435                                  mode, "mode");
10436 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10438                                  mode_value, "IP");
10439 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10441                                  mode_value, "MAC-VLAN");
10442 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10443         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10444                                  mode_value, "Tunnel");
10445 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10447                                  mac, "mac");
10448 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10449         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10450                               mac_addr_byte_mask, RTE_UINT8);
10451 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10453                                  tunnel_type, "tunnel-type");
10454 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10455         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10456                               tunnel_type_mask, RTE_UINT8);
10457 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10458         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10459                                  tunnel_id, "tunnel-id");
10460 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10461         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10462                               tunnel_id_mask, RTE_UINT32);
10463
10464 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10465         .f = cmd_flow_director_mask_parsed,
10466         .data = NULL,
10467         .help_str = "flow_director_mask ... : "
10468                 "Set IP mode flow director's mask on NIC",
10469         .tokens = {
10470                 (void *)&cmd_flow_director_mask,
10471                 (void *)&cmd_flow_director_mask_port_id,
10472                 (void *)&cmd_flow_director_mask_mode,
10473                 (void *)&cmd_flow_director_mask_mode_ip,
10474                 (void *)&cmd_flow_director_mask_vlan,
10475                 (void *)&cmd_flow_director_mask_vlan_value,
10476                 (void *)&cmd_flow_director_mask_src,
10477                 (void *)&cmd_flow_director_mask_ipv4_src,
10478                 (void *)&cmd_flow_director_mask_ipv6_src,
10479                 (void *)&cmd_flow_director_mask_port_src,
10480                 (void *)&cmd_flow_director_mask_dst,
10481                 (void *)&cmd_flow_director_mask_ipv4_dst,
10482                 (void *)&cmd_flow_director_mask_ipv6_dst,
10483                 (void *)&cmd_flow_director_mask_port_dst,
10484                 NULL,
10485         },
10486 };
10487
10488 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10489         .f = cmd_flow_director_mask_parsed,
10490         .data = NULL,
10491         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10492                 "flow director's mask on NIC",
10493         .tokens = {
10494                 (void *)&cmd_flow_director_mask,
10495                 (void *)&cmd_flow_director_mask_port_id,
10496                 (void *)&cmd_flow_director_mask_mode,
10497                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10498                 (void *)&cmd_flow_director_mask_vlan,
10499                 (void *)&cmd_flow_director_mask_vlan_value,
10500                 NULL,
10501         },
10502 };
10503
10504 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10505         .f = cmd_flow_director_mask_parsed,
10506         .data = NULL,
10507         .help_str = "flow_director_mask ... : Set tunnel mode "
10508                 "flow director's mask on NIC",
10509         .tokens = {
10510                 (void *)&cmd_flow_director_mask,
10511                 (void *)&cmd_flow_director_mask_port_id,
10512                 (void *)&cmd_flow_director_mask_mode,
10513                 (void *)&cmd_flow_director_mask_mode_tunnel,
10514                 (void *)&cmd_flow_director_mask_vlan,
10515                 (void *)&cmd_flow_director_mask_vlan_value,
10516                 (void *)&cmd_flow_director_mask_mac,
10517                 (void *)&cmd_flow_director_mask_mac_value,
10518                 (void *)&cmd_flow_director_mask_tunnel_type,
10519                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10520                 (void *)&cmd_flow_director_mask_tunnel_id,
10521                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10522                 NULL,
10523         },
10524 };
10525
10526 /* *** deal with flow director flexible payload configuration *** */
10527 struct cmd_flow_director_flexpayload_result {
10528         cmdline_fixed_string_t flow_director_flexpayload;
10529         portid_t port_id;
10530         cmdline_fixed_string_t payload_layer;
10531         cmdline_fixed_string_t payload_cfg;
10532 };
10533
10534 static inline int
10535 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10536 {
10537         char s[256];
10538         const char *p, *p0 = q_arg;
10539         char *end;
10540         unsigned long int_fld;
10541         char *str_fld[max_num];
10542         int i;
10543         unsigned size;
10544         int ret = -1;
10545
10546         p = strchr(p0, '(');
10547         if (p == NULL)
10548                 return -1;
10549         ++p;
10550         p0 = strchr(p, ')');
10551         if (p0 == NULL)
10552                 return -1;
10553
10554         size = p0 - p;
10555         if (size >= sizeof(s))
10556                 return -1;
10557
10558         snprintf(s, sizeof(s), "%.*s", size, p);
10559         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10560         if (ret < 0 || ret > max_num)
10561                 return -1;
10562         for (i = 0; i < ret; i++) {
10563                 errno = 0;
10564                 int_fld = strtoul(str_fld[i], &end, 0);
10565                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10566                         return -1;
10567                 offsets[i] = (uint16_t)int_fld;
10568         }
10569         return ret;
10570 }
10571
10572 static void
10573 cmd_flow_director_flxpld_parsed(void *parsed_result,
10574                           __rte_unused struct cmdline *cl,
10575                           __rte_unused void *data)
10576 {
10577         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10578         struct rte_eth_flex_payload_cfg flex_cfg;
10579         struct rte_port *port;
10580         int ret = 0;
10581
10582         port = &ports[res->port_id];
10583         /** Check if the port is not started **/
10584         if (port->port_status != RTE_PORT_STOPPED) {
10585                 printf("Please stop port %d first\n", res->port_id);
10586                 return;
10587         }
10588
10589         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10590
10591         if (!strcmp(res->payload_layer, "raw"))
10592                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10593         else if (!strcmp(res->payload_layer, "l2"))
10594                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10595         else if (!strcmp(res->payload_layer, "l3"))
10596                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10597         else if (!strcmp(res->payload_layer, "l4"))
10598                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10599
10600         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10601                             RTE_ETH_FDIR_MAX_FLEXLEN);
10602         if (ret < 0) {
10603                 printf("error: Cannot parse flex payload input.\n");
10604                 return;
10605         }
10606
10607         fdir_set_flex_payload(res->port_id, &flex_cfg);
10608         cmd_reconfig_device_queue(res->port_id, 1, 1);
10609 }
10610
10611 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10612         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10613                                  flow_director_flexpayload,
10614                                  "flow_director_flex_payload");
10615 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10616         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10617                               port_id, RTE_UINT16);
10618 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10619         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10620                                  payload_layer, "raw#l2#l3#l4");
10621 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10622         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10623                                  payload_cfg, NULL);
10624
10625 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10626         .f = cmd_flow_director_flxpld_parsed,
10627         .data = NULL,
10628         .help_str = "flow_director_flexpayload ... : "
10629                 "Set flow director's flex payload on NIC",
10630         .tokens = {
10631                 (void *)&cmd_flow_director_flexpayload,
10632                 (void *)&cmd_flow_director_flexpayload_port_id,
10633                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10634                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10635                 NULL,
10636         },
10637 };
10638
10639 /* Generic flow interface command. */
10640 extern cmdline_parse_inst_t cmd_flow;
10641
10642 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10643 struct cmd_mcast_addr_result {
10644         cmdline_fixed_string_t mcast_addr_cmd;
10645         cmdline_fixed_string_t what;
10646         uint16_t port_num;
10647         struct rte_ether_addr mc_addr;
10648 };
10649
10650 static void cmd_mcast_addr_parsed(void *parsed_result,
10651                 __rte_unused struct cmdline *cl,
10652                 __rte_unused void *data)
10653 {
10654         struct cmd_mcast_addr_result *res = parsed_result;
10655
10656         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10657                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10658                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10659                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10660                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10661                 return;
10662         }
10663         if (strcmp(res->what, "add") == 0)
10664                 mcast_addr_add(res->port_num, &res->mc_addr);
10665         else
10666                 mcast_addr_remove(res->port_num, &res->mc_addr);
10667 }
10668
10669 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10670         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10671                                  mcast_addr_cmd, "mcast_addr");
10672 cmdline_parse_token_string_t cmd_mcast_addr_what =
10673         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10674                                  "add#remove");
10675 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10676         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10677                                  RTE_UINT16);
10678 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10679         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10680
10681 cmdline_parse_inst_t cmd_mcast_addr = {
10682         .f = cmd_mcast_addr_parsed,
10683         .data = (void *)0,
10684         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10685                 "Add/Remove multicast MAC address on port_id",
10686         .tokens = {
10687                 (void *)&cmd_mcast_addr_cmd,
10688                 (void *)&cmd_mcast_addr_what,
10689                 (void *)&cmd_mcast_addr_portnum,
10690                 (void *)&cmd_mcast_addr_addr,
10691                 NULL,
10692         },
10693 };
10694
10695 /* vf vlan anti spoof configuration */
10696
10697 /* Common result structure for vf vlan anti spoof */
10698 struct cmd_vf_vlan_anti_spoof_result {
10699         cmdline_fixed_string_t set;
10700         cmdline_fixed_string_t vf;
10701         cmdline_fixed_string_t vlan;
10702         cmdline_fixed_string_t antispoof;
10703         portid_t port_id;
10704         uint32_t vf_id;
10705         cmdline_fixed_string_t on_off;
10706 };
10707
10708 /* Common CLI fields for vf vlan anti spoof enable disable */
10709 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10710         TOKEN_STRING_INITIALIZER
10711                 (struct cmd_vf_vlan_anti_spoof_result,
10712                  set, "set");
10713 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10714         TOKEN_STRING_INITIALIZER
10715                 (struct cmd_vf_vlan_anti_spoof_result,
10716                  vf, "vf");
10717 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10718         TOKEN_STRING_INITIALIZER
10719                 (struct cmd_vf_vlan_anti_spoof_result,
10720                  vlan, "vlan");
10721 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10722         TOKEN_STRING_INITIALIZER
10723                 (struct cmd_vf_vlan_anti_spoof_result,
10724                  antispoof, "antispoof");
10725 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10726         TOKEN_NUM_INITIALIZER
10727                 (struct cmd_vf_vlan_anti_spoof_result,
10728                  port_id, RTE_UINT16);
10729 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10730         TOKEN_NUM_INITIALIZER
10731                 (struct cmd_vf_vlan_anti_spoof_result,
10732                  vf_id, RTE_UINT32);
10733 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10734         TOKEN_STRING_INITIALIZER
10735                 (struct cmd_vf_vlan_anti_spoof_result,
10736                  on_off, "on#off");
10737
10738 static void
10739 cmd_set_vf_vlan_anti_spoof_parsed(
10740         void *parsed_result,
10741         __rte_unused struct cmdline *cl,
10742         __rte_unused void *data)
10743 {
10744         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10745         int ret = -ENOTSUP;
10746
10747         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10748
10749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10750                 return;
10751
10752 #ifdef RTE_NET_IXGBE
10753         if (ret == -ENOTSUP)
10754                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10755                                 res->vf_id, is_on);
10756 #endif
10757 #ifdef RTE_NET_I40E
10758         if (ret == -ENOTSUP)
10759                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10760                                 res->vf_id, is_on);
10761 #endif
10762 #ifdef RTE_NET_BNXT
10763         if (ret == -ENOTSUP)
10764                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10765                                 res->vf_id, is_on);
10766 #endif
10767
10768         switch (ret) {
10769         case 0:
10770                 break;
10771         case -EINVAL:
10772                 printf("invalid vf_id %d\n", res->vf_id);
10773                 break;
10774         case -ENODEV:
10775                 printf("invalid port_id %d\n", res->port_id);
10776                 break;
10777         case -ENOTSUP:
10778                 printf("function not implemented\n");
10779                 break;
10780         default:
10781                 printf("programming error: (%s)\n", strerror(-ret));
10782         }
10783 }
10784
10785 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10786         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10787         .data = NULL,
10788         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10789         .tokens = {
10790                 (void *)&cmd_vf_vlan_anti_spoof_set,
10791                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10792                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10793                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10794                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10795                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10796                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10797                 NULL,
10798         },
10799 };
10800
10801 /* vf mac anti spoof configuration */
10802
10803 /* Common result structure for vf mac anti spoof */
10804 struct cmd_vf_mac_anti_spoof_result {
10805         cmdline_fixed_string_t set;
10806         cmdline_fixed_string_t vf;
10807         cmdline_fixed_string_t mac;
10808         cmdline_fixed_string_t antispoof;
10809         portid_t port_id;
10810         uint32_t vf_id;
10811         cmdline_fixed_string_t on_off;
10812 };
10813
10814 /* Common CLI fields for vf mac anti spoof enable disable */
10815 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10816         TOKEN_STRING_INITIALIZER
10817                 (struct cmd_vf_mac_anti_spoof_result,
10818                  set, "set");
10819 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10820         TOKEN_STRING_INITIALIZER
10821                 (struct cmd_vf_mac_anti_spoof_result,
10822                  vf, "vf");
10823 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10824         TOKEN_STRING_INITIALIZER
10825                 (struct cmd_vf_mac_anti_spoof_result,
10826                  mac, "mac");
10827 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10828         TOKEN_STRING_INITIALIZER
10829                 (struct cmd_vf_mac_anti_spoof_result,
10830                  antispoof, "antispoof");
10831 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10832         TOKEN_NUM_INITIALIZER
10833                 (struct cmd_vf_mac_anti_spoof_result,
10834                  port_id, RTE_UINT16);
10835 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10836         TOKEN_NUM_INITIALIZER
10837                 (struct cmd_vf_mac_anti_spoof_result,
10838                  vf_id, RTE_UINT32);
10839 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10840         TOKEN_STRING_INITIALIZER
10841                 (struct cmd_vf_mac_anti_spoof_result,
10842                  on_off, "on#off");
10843
10844 static void
10845 cmd_set_vf_mac_anti_spoof_parsed(
10846         void *parsed_result,
10847         __rte_unused struct cmdline *cl,
10848         __rte_unused void *data)
10849 {
10850         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10851         int ret = -ENOTSUP;
10852
10853         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10854
10855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10856                 return;
10857
10858 #ifdef RTE_NET_IXGBE
10859         if (ret == -ENOTSUP)
10860                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10861                         res->vf_id, is_on);
10862 #endif
10863 #ifdef RTE_NET_I40E
10864         if (ret == -ENOTSUP)
10865                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10866                         res->vf_id, is_on);
10867 #endif
10868 #ifdef RTE_NET_BNXT
10869         if (ret == -ENOTSUP)
10870                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10871                         res->vf_id, is_on);
10872 #endif
10873
10874         switch (ret) {
10875         case 0:
10876                 break;
10877         case -EINVAL:
10878                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10879                 break;
10880         case -ENODEV:
10881                 printf("invalid port_id %d\n", res->port_id);
10882                 break;
10883         case -ENOTSUP:
10884                 printf("function not implemented\n");
10885                 break;
10886         default:
10887                 printf("programming error: (%s)\n", strerror(-ret));
10888         }
10889 }
10890
10891 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10892         .f = cmd_set_vf_mac_anti_spoof_parsed,
10893         .data = NULL,
10894         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10895         .tokens = {
10896                 (void *)&cmd_vf_mac_anti_spoof_set,
10897                 (void *)&cmd_vf_mac_anti_spoof_vf,
10898                 (void *)&cmd_vf_mac_anti_spoof_mac,
10899                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10900                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10901                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10902                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10903                 NULL,
10904         },
10905 };
10906
10907 /* vf vlan strip queue configuration */
10908
10909 /* Common result structure for vf mac anti spoof */
10910 struct cmd_vf_vlan_stripq_result {
10911         cmdline_fixed_string_t set;
10912         cmdline_fixed_string_t vf;
10913         cmdline_fixed_string_t vlan;
10914         cmdline_fixed_string_t stripq;
10915         portid_t port_id;
10916         uint16_t vf_id;
10917         cmdline_fixed_string_t on_off;
10918 };
10919
10920 /* Common CLI fields for vf vlan strip enable disable */
10921 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10922         TOKEN_STRING_INITIALIZER
10923                 (struct cmd_vf_vlan_stripq_result,
10924                  set, "set");
10925 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10926         TOKEN_STRING_INITIALIZER
10927                 (struct cmd_vf_vlan_stripq_result,
10928                  vf, "vf");
10929 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10930         TOKEN_STRING_INITIALIZER
10931                 (struct cmd_vf_vlan_stripq_result,
10932                  vlan, "vlan");
10933 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10934         TOKEN_STRING_INITIALIZER
10935                 (struct cmd_vf_vlan_stripq_result,
10936                  stripq, "stripq");
10937 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10938         TOKEN_NUM_INITIALIZER
10939                 (struct cmd_vf_vlan_stripq_result,
10940                  port_id, RTE_UINT16);
10941 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10942         TOKEN_NUM_INITIALIZER
10943                 (struct cmd_vf_vlan_stripq_result,
10944                  vf_id, RTE_UINT16);
10945 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10946         TOKEN_STRING_INITIALIZER
10947                 (struct cmd_vf_vlan_stripq_result,
10948                  on_off, "on#off");
10949
10950 static void
10951 cmd_set_vf_vlan_stripq_parsed(
10952         void *parsed_result,
10953         __rte_unused struct cmdline *cl,
10954         __rte_unused void *data)
10955 {
10956         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10957         int ret = -ENOTSUP;
10958
10959         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10960
10961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10962                 return;
10963
10964 #ifdef RTE_NET_IXGBE
10965         if (ret == -ENOTSUP)
10966                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10967                         res->vf_id, is_on);
10968 #endif
10969 #ifdef RTE_NET_I40E
10970         if (ret == -ENOTSUP)
10971                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10972                         res->vf_id, is_on);
10973 #endif
10974 #ifdef RTE_NET_BNXT
10975         if (ret == -ENOTSUP)
10976                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10977                         res->vf_id, is_on);
10978 #endif
10979
10980         switch (ret) {
10981         case 0:
10982                 break;
10983         case -EINVAL:
10984                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10985                 break;
10986         case -ENODEV:
10987                 printf("invalid port_id %d\n", res->port_id);
10988                 break;
10989         case -ENOTSUP:
10990                 printf("function not implemented\n");
10991                 break;
10992         default:
10993                 printf("programming error: (%s)\n", strerror(-ret));
10994         }
10995 }
10996
10997 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10998         .f = cmd_set_vf_vlan_stripq_parsed,
10999         .data = NULL,
11000         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11001         .tokens = {
11002                 (void *)&cmd_vf_vlan_stripq_set,
11003                 (void *)&cmd_vf_vlan_stripq_vf,
11004                 (void *)&cmd_vf_vlan_stripq_vlan,
11005                 (void *)&cmd_vf_vlan_stripq_stripq,
11006                 (void *)&cmd_vf_vlan_stripq_port_id,
11007                 (void *)&cmd_vf_vlan_stripq_vf_id,
11008                 (void *)&cmd_vf_vlan_stripq_on_off,
11009                 NULL,
11010         },
11011 };
11012
11013 /* vf vlan insert configuration */
11014
11015 /* Common result structure for vf vlan insert */
11016 struct cmd_vf_vlan_insert_result {
11017         cmdline_fixed_string_t set;
11018         cmdline_fixed_string_t vf;
11019         cmdline_fixed_string_t vlan;
11020         cmdline_fixed_string_t insert;
11021         portid_t port_id;
11022         uint16_t vf_id;
11023         uint16_t vlan_id;
11024 };
11025
11026 /* Common CLI fields for vf vlan insert enable disable */
11027 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11028         TOKEN_STRING_INITIALIZER
11029                 (struct cmd_vf_vlan_insert_result,
11030                  set, "set");
11031 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11032         TOKEN_STRING_INITIALIZER
11033                 (struct cmd_vf_vlan_insert_result,
11034                  vf, "vf");
11035 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11036         TOKEN_STRING_INITIALIZER
11037                 (struct cmd_vf_vlan_insert_result,
11038                  vlan, "vlan");
11039 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11040         TOKEN_STRING_INITIALIZER
11041                 (struct cmd_vf_vlan_insert_result,
11042                  insert, "insert");
11043 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11044         TOKEN_NUM_INITIALIZER
11045                 (struct cmd_vf_vlan_insert_result,
11046                  port_id, RTE_UINT16);
11047 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11048         TOKEN_NUM_INITIALIZER
11049                 (struct cmd_vf_vlan_insert_result,
11050                  vf_id, RTE_UINT16);
11051 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11052         TOKEN_NUM_INITIALIZER
11053                 (struct cmd_vf_vlan_insert_result,
11054                  vlan_id, RTE_UINT16);
11055
11056 static void
11057 cmd_set_vf_vlan_insert_parsed(
11058         void *parsed_result,
11059         __rte_unused struct cmdline *cl,
11060         __rte_unused void *data)
11061 {
11062         struct cmd_vf_vlan_insert_result *res = parsed_result;
11063         int ret = -ENOTSUP;
11064
11065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11066                 return;
11067
11068 #ifdef RTE_NET_IXGBE
11069         if (ret == -ENOTSUP)
11070                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11071                         res->vlan_id);
11072 #endif
11073 #ifdef RTE_NET_I40E
11074         if (ret == -ENOTSUP)
11075                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11076                         res->vlan_id);
11077 #endif
11078 #ifdef RTE_NET_BNXT
11079         if (ret == -ENOTSUP)
11080                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11081                         res->vlan_id);
11082 #endif
11083
11084         switch (ret) {
11085         case 0:
11086                 break;
11087         case -EINVAL:
11088                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11089                 break;
11090         case -ENODEV:
11091                 printf("invalid port_id %d\n", res->port_id);
11092                 break;
11093         case -ENOTSUP:
11094                 printf("function not implemented\n");
11095                 break;
11096         default:
11097                 printf("programming error: (%s)\n", strerror(-ret));
11098         }
11099 }
11100
11101 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11102         .f = cmd_set_vf_vlan_insert_parsed,
11103         .data = NULL,
11104         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11105         .tokens = {
11106                 (void *)&cmd_vf_vlan_insert_set,
11107                 (void *)&cmd_vf_vlan_insert_vf,
11108                 (void *)&cmd_vf_vlan_insert_vlan,
11109                 (void *)&cmd_vf_vlan_insert_insert,
11110                 (void *)&cmd_vf_vlan_insert_port_id,
11111                 (void *)&cmd_vf_vlan_insert_vf_id,
11112                 (void *)&cmd_vf_vlan_insert_vlan_id,
11113                 NULL,
11114         },
11115 };
11116
11117 /* tx loopback configuration */
11118
11119 /* Common result structure for tx loopback */
11120 struct cmd_tx_loopback_result {
11121         cmdline_fixed_string_t set;
11122         cmdline_fixed_string_t tx;
11123         cmdline_fixed_string_t loopback;
11124         portid_t port_id;
11125         cmdline_fixed_string_t on_off;
11126 };
11127
11128 /* Common CLI fields for tx loopback enable disable */
11129 cmdline_parse_token_string_t cmd_tx_loopback_set =
11130         TOKEN_STRING_INITIALIZER
11131                 (struct cmd_tx_loopback_result,
11132                  set, "set");
11133 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11134         TOKEN_STRING_INITIALIZER
11135                 (struct cmd_tx_loopback_result,
11136                  tx, "tx");
11137 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11138         TOKEN_STRING_INITIALIZER
11139                 (struct cmd_tx_loopback_result,
11140                  loopback, "loopback");
11141 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11142         TOKEN_NUM_INITIALIZER
11143                 (struct cmd_tx_loopback_result,
11144                  port_id, RTE_UINT16);
11145 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11146         TOKEN_STRING_INITIALIZER
11147                 (struct cmd_tx_loopback_result,
11148                  on_off, "on#off");
11149
11150 static void
11151 cmd_set_tx_loopback_parsed(
11152         void *parsed_result,
11153         __rte_unused struct cmdline *cl,
11154         __rte_unused void *data)
11155 {
11156         struct cmd_tx_loopback_result *res = parsed_result;
11157         int ret = -ENOTSUP;
11158
11159         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11160
11161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11162                 return;
11163
11164 #ifdef RTE_NET_IXGBE
11165         if (ret == -ENOTSUP)
11166                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11167 #endif
11168 #ifdef RTE_NET_I40E
11169         if (ret == -ENOTSUP)
11170                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11171 #endif
11172 #ifdef RTE_NET_BNXT
11173         if (ret == -ENOTSUP)
11174                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11175 #endif
11176 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11177         if (ret == -ENOTSUP)
11178                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11179 #endif
11180
11181         switch (ret) {
11182         case 0:
11183                 break;
11184         case -EINVAL:
11185                 printf("invalid is_on %d\n", is_on);
11186                 break;
11187         case -ENODEV:
11188                 printf("invalid port_id %d\n", res->port_id);
11189                 break;
11190         case -ENOTSUP:
11191                 printf("function not implemented\n");
11192                 break;
11193         default:
11194                 printf("programming error: (%s)\n", strerror(-ret));
11195         }
11196 }
11197
11198 cmdline_parse_inst_t cmd_set_tx_loopback = {
11199         .f = cmd_set_tx_loopback_parsed,
11200         .data = NULL,
11201         .help_str = "set tx loopback <port_id> on|off",
11202         .tokens = {
11203                 (void *)&cmd_tx_loopback_set,
11204                 (void *)&cmd_tx_loopback_tx,
11205                 (void *)&cmd_tx_loopback_loopback,
11206                 (void *)&cmd_tx_loopback_port_id,
11207                 (void *)&cmd_tx_loopback_on_off,
11208                 NULL,
11209         },
11210 };
11211
11212 /* all queues drop enable configuration */
11213
11214 /* Common result structure for all queues drop enable */
11215 struct cmd_all_queues_drop_en_result {
11216         cmdline_fixed_string_t set;
11217         cmdline_fixed_string_t all;
11218         cmdline_fixed_string_t queues;
11219         cmdline_fixed_string_t drop;
11220         portid_t port_id;
11221         cmdline_fixed_string_t on_off;
11222 };
11223
11224 /* Common CLI fields for tx loopback enable disable */
11225 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11226         TOKEN_STRING_INITIALIZER
11227                 (struct cmd_all_queues_drop_en_result,
11228                  set, "set");
11229 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_all_queues_drop_en_result,
11232                  all, "all");
11233 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11234         TOKEN_STRING_INITIALIZER
11235                 (struct cmd_all_queues_drop_en_result,
11236                  queues, "queues");
11237 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11238         TOKEN_STRING_INITIALIZER
11239                 (struct cmd_all_queues_drop_en_result,
11240                  drop, "drop");
11241 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11242         TOKEN_NUM_INITIALIZER
11243                 (struct cmd_all_queues_drop_en_result,
11244                  port_id, RTE_UINT16);
11245 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11246         TOKEN_STRING_INITIALIZER
11247                 (struct cmd_all_queues_drop_en_result,
11248                  on_off, "on#off");
11249
11250 static void
11251 cmd_set_all_queues_drop_en_parsed(
11252         void *parsed_result,
11253         __rte_unused struct cmdline *cl,
11254         __rte_unused void *data)
11255 {
11256         struct cmd_all_queues_drop_en_result *res = parsed_result;
11257         int ret = -ENOTSUP;
11258         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11259
11260         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11261                 return;
11262
11263 #ifdef RTE_NET_IXGBE
11264         if (ret == -ENOTSUP)
11265                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11266 #endif
11267 #ifdef RTE_NET_BNXT
11268         if (ret == -ENOTSUP)
11269                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11270 #endif
11271         switch (ret) {
11272         case 0:
11273                 break;
11274         case -EINVAL:
11275                 printf("invalid is_on %d\n", is_on);
11276                 break;
11277         case -ENODEV:
11278                 printf("invalid port_id %d\n", res->port_id);
11279                 break;
11280         case -ENOTSUP:
11281                 printf("function not implemented\n");
11282                 break;
11283         default:
11284                 printf("programming error: (%s)\n", strerror(-ret));
11285         }
11286 }
11287
11288 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11289         .f = cmd_set_all_queues_drop_en_parsed,
11290         .data = NULL,
11291         .help_str = "set all queues drop <port_id> on|off",
11292         .tokens = {
11293                 (void *)&cmd_all_queues_drop_en_set,
11294                 (void *)&cmd_all_queues_drop_en_all,
11295                 (void *)&cmd_all_queues_drop_en_queues,
11296                 (void *)&cmd_all_queues_drop_en_drop,
11297                 (void *)&cmd_all_queues_drop_en_port_id,
11298                 (void *)&cmd_all_queues_drop_en_on_off,
11299                 NULL,
11300         },
11301 };
11302
11303 /* vf split drop enable configuration */
11304
11305 /* Common result structure for vf split drop enable */
11306 struct cmd_vf_split_drop_en_result {
11307         cmdline_fixed_string_t set;
11308         cmdline_fixed_string_t vf;
11309         cmdline_fixed_string_t split;
11310         cmdline_fixed_string_t drop;
11311         portid_t port_id;
11312         uint16_t vf_id;
11313         cmdline_fixed_string_t on_off;
11314 };
11315
11316 /* Common CLI fields for vf split drop enable disable */
11317 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11318         TOKEN_STRING_INITIALIZER
11319                 (struct cmd_vf_split_drop_en_result,
11320                  set, "set");
11321 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11322         TOKEN_STRING_INITIALIZER
11323                 (struct cmd_vf_split_drop_en_result,
11324                  vf, "vf");
11325 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11326         TOKEN_STRING_INITIALIZER
11327                 (struct cmd_vf_split_drop_en_result,
11328                  split, "split");
11329 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11330         TOKEN_STRING_INITIALIZER
11331                 (struct cmd_vf_split_drop_en_result,
11332                  drop, "drop");
11333 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11334         TOKEN_NUM_INITIALIZER
11335                 (struct cmd_vf_split_drop_en_result,
11336                  port_id, RTE_UINT16);
11337 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11338         TOKEN_NUM_INITIALIZER
11339                 (struct cmd_vf_split_drop_en_result,
11340                  vf_id, RTE_UINT16);
11341 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11342         TOKEN_STRING_INITIALIZER
11343                 (struct cmd_vf_split_drop_en_result,
11344                  on_off, "on#off");
11345
11346 static void
11347 cmd_set_vf_split_drop_en_parsed(
11348         void *parsed_result,
11349         __rte_unused struct cmdline *cl,
11350         __rte_unused void *data)
11351 {
11352         struct cmd_vf_split_drop_en_result *res = parsed_result;
11353         int ret = -ENOTSUP;
11354         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11355
11356         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11357                 return;
11358
11359 #ifdef RTE_NET_IXGBE
11360         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11361                         is_on);
11362 #endif
11363         switch (ret) {
11364         case 0:
11365                 break;
11366         case -EINVAL:
11367                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11368                 break;
11369         case -ENODEV:
11370                 printf("invalid port_id %d\n", res->port_id);
11371                 break;
11372         case -ENOTSUP:
11373                 printf("not supported on port %d\n", res->port_id);
11374                 break;
11375         default:
11376                 printf("programming error: (%s)\n", strerror(-ret));
11377         }
11378 }
11379
11380 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11381         .f = cmd_set_vf_split_drop_en_parsed,
11382         .data = NULL,
11383         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11384         .tokens = {
11385                 (void *)&cmd_vf_split_drop_en_set,
11386                 (void *)&cmd_vf_split_drop_en_vf,
11387                 (void *)&cmd_vf_split_drop_en_split,
11388                 (void *)&cmd_vf_split_drop_en_drop,
11389                 (void *)&cmd_vf_split_drop_en_port_id,
11390                 (void *)&cmd_vf_split_drop_en_vf_id,
11391                 (void *)&cmd_vf_split_drop_en_on_off,
11392                 NULL,
11393         },
11394 };
11395
11396 /* vf mac address configuration */
11397
11398 /* Common result structure for vf mac address */
11399 struct cmd_set_vf_mac_addr_result {
11400         cmdline_fixed_string_t set;
11401         cmdline_fixed_string_t vf;
11402         cmdline_fixed_string_t mac;
11403         cmdline_fixed_string_t addr;
11404         portid_t port_id;
11405         uint16_t vf_id;
11406         struct rte_ether_addr mac_addr;
11407
11408 };
11409
11410 /* Common CLI fields for vf split drop enable disable */
11411 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11412         TOKEN_STRING_INITIALIZER
11413                 (struct cmd_set_vf_mac_addr_result,
11414                  set, "set");
11415 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11416         TOKEN_STRING_INITIALIZER
11417                 (struct cmd_set_vf_mac_addr_result,
11418                  vf, "vf");
11419 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11420         TOKEN_STRING_INITIALIZER
11421                 (struct cmd_set_vf_mac_addr_result,
11422                  mac, "mac");
11423 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11424         TOKEN_STRING_INITIALIZER
11425                 (struct cmd_set_vf_mac_addr_result,
11426                  addr, "addr");
11427 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11428         TOKEN_NUM_INITIALIZER
11429                 (struct cmd_set_vf_mac_addr_result,
11430                  port_id, RTE_UINT16);
11431 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11432         TOKEN_NUM_INITIALIZER
11433                 (struct cmd_set_vf_mac_addr_result,
11434                  vf_id, RTE_UINT16);
11435 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11436         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11437                  mac_addr);
11438
11439 static void
11440 cmd_set_vf_mac_addr_parsed(
11441         void *parsed_result,
11442         __rte_unused struct cmdline *cl,
11443         __rte_unused void *data)
11444 {
11445         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11446         int ret = -ENOTSUP;
11447
11448         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11449                 return;
11450
11451 #ifdef RTE_NET_IXGBE
11452         if (ret == -ENOTSUP)
11453                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11454                                 &res->mac_addr);
11455 #endif
11456 #ifdef RTE_NET_I40E
11457         if (ret == -ENOTSUP)
11458                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11459                                 &res->mac_addr);
11460 #endif
11461 #ifdef RTE_NET_BNXT
11462         if (ret == -ENOTSUP)
11463                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11464                                 &res->mac_addr);
11465 #endif
11466
11467         switch (ret) {
11468         case 0:
11469                 break;
11470         case -EINVAL:
11471                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11472                 break;
11473         case -ENODEV:
11474                 printf("invalid port_id %d\n", res->port_id);
11475                 break;
11476         case -ENOTSUP:
11477                 printf("function not implemented\n");
11478                 break;
11479         default:
11480                 printf("programming error: (%s)\n", strerror(-ret));
11481         }
11482 }
11483
11484 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11485         .f = cmd_set_vf_mac_addr_parsed,
11486         .data = NULL,
11487         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11488         .tokens = {
11489                 (void *)&cmd_set_vf_mac_addr_set,
11490                 (void *)&cmd_set_vf_mac_addr_vf,
11491                 (void *)&cmd_set_vf_mac_addr_mac,
11492                 (void *)&cmd_set_vf_mac_addr_addr,
11493                 (void *)&cmd_set_vf_mac_addr_port_id,
11494                 (void *)&cmd_set_vf_mac_addr_vf_id,
11495                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11496                 NULL,
11497         },
11498 };
11499
11500 /* MACsec configuration */
11501
11502 /* Common result structure for MACsec offload enable */
11503 struct cmd_macsec_offload_on_result {
11504         cmdline_fixed_string_t set;
11505         cmdline_fixed_string_t macsec;
11506         cmdline_fixed_string_t offload;
11507         portid_t port_id;
11508         cmdline_fixed_string_t on;
11509         cmdline_fixed_string_t encrypt;
11510         cmdline_fixed_string_t en_on_off;
11511         cmdline_fixed_string_t replay_protect;
11512         cmdline_fixed_string_t rp_on_off;
11513 };
11514
11515 /* Common CLI fields for MACsec offload disable */
11516 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11517         TOKEN_STRING_INITIALIZER
11518                 (struct cmd_macsec_offload_on_result,
11519                  set, "set");
11520 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11521         TOKEN_STRING_INITIALIZER
11522                 (struct cmd_macsec_offload_on_result,
11523                  macsec, "macsec");
11524 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11525         TOKEN_STRING_INITIALIZER
11526                 (struct cmd_macsec_offload_on_result,
11527                  offload, "offload");
11528 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11529         TOKEN_NUM_INITIALIZER
11530                 (struct cmd_macsec_offload_on_result,
11531                  port_id, RTE_UINT16);
11532 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11533         TOKEN_STRING_INITIALIZER
11534                 (struct cmd_macsec_offload_on_result,
11535                  on, "on");
11536 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11537         TOKEN_STRING_INITIALIZER
11538                 (struct cmd_macsec_offload_on_result,
11539                  encrypt, "encrypt");
11540 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11541         TOKEN_STRING_INITIALIZER
11542                 (struct cmd_macsec_offload_on_result,
11543                  en_on_off, "on#off");
11544 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11545         TOKEN_STRING_INITIALIZER
11546                 (struct cmd_macsec_offload_on_result,
11547                  replay_protect, "replay-protect");
11548 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11549         TOKEN_STRING_INITIALIZER
11550                 (struct cmd_macsec_offload_on_result,
11551                  rp_on_off, "on#off");
11552
11553 static void
11554 cmd_set_macsec_offload_on_parsed(
11555         void *parsed_result,
11556         __rte_unused struct cmdline *cl,
11557         __rte_unused void *data)
11558 {
11559         struct cmd_macsec_offload_on_result *res = parsed_result;
11560         int ret = -ENOTSUP;
11561         portid_t port_id = res->port_id;
11562         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11563         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11564         struct rte_eth_dev_info dev_info;
11565
11566         if (port_id_is_invalid(port_id, ENABLED_WARN))
11567                 return;
11568         if (!port_is_stopped(port_id)) {
11569                 printf("Please stop port %d first\n", port_id);
11570                 return;
11571         }
11572
11573         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11574         if (ret != 0)
11575                 return;
11576
11577         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11578 #ifdef RTE_NET_IXGBE
11579                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11580 #endif
11581         }
11582         RTE_SET_USED(en);
11583         RTE_SET_USED(rp);
11584
11585         switch (ret) {
11586         case 0:
11587                 ports[port_id].dev_conf.txmode.offloads |=
11588                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11589                 cmd_reconfig_device_queue(port_id, 1, 1);
11590                 break;
11591         case -ENODEV:
11592                 printf("invalid port_id %d\n", port_id);
11593                 break;
11594         case -ENOTSUP:
11595                 printf("not supported on port %d\n", port_id);
11596                 break;
11597         default:
11598                 printf("programming error: (%s)\n", strerror(-ret));
11599         }
11600 }
11601
11602 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11603         .f = cmd_set_macsec_offload_on_parsed,
11604         .data = NULL,
11605         .help_str = "set macsec offload <port_id> on "
11606                 "encrypt on|off replay-protect on|off",
11607         .tokens = {
11608                 (void *)&cmd_macsec_offload_on_set,
11609                 (void *)&cmd_macsec_offload_on_macsec,
11610                 (void *)&cmd_macsec_offload_on_offload,
11611                 (void *)&cmd_macsec_offload_on_port_id,
11612                 (void *)&cmd_macsec_offload_on_on,
11613                 (void *)&cmd_macsec_offload_on_encrypt,
11614                 (void *)&cmd_macsec_offload_on_en_on_off,
11615                 (void *)&cmd_macsec_offload_on_replay_protect,
11616                 (void *)&cmd_macsec_offload_on_rp_on_off,
11617                 NULL,
11618         },
11619 };
11620
11621 /* Common result structure for MACsec offload disable */
11622 struct cmd_macsec_offload_off_result {
11623         cmdline_fixed_string_t set;
11624         cmdline_fixed_string_t macsec;
11625         cmdline_fixed_string_t offload;
11626         portid_t port_id;
11627         cmdline_fixed_string_t off;
11628 };
11629
11630 /* Common CLI fields for MACsec offload disable */
11631 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11632         TOKEN_STRING_INITIALIZER
11633                 (struct cmd_macsec_offload_off_result,
11634                  set, "set");
11635 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11636         TOKEN_STRING_INITIALIZER
11637                 (struct cmd_macsec_offload_off_result,
11638                  macsec, "macsec");
11639 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_macsec_offload_off_result,
11642                  offload, "offload");
11643 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11644         TOKEN_NUM_INITIALIZER
11645                 (struct cmd_macsec_offload_off_result,
11646                  port_id, RTE_UINT16);
11647 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11648         TOKEN_STRING_INITIALIZER
11649                 (struct cmd_macsec_offload_off_result,
11650                  off, "off");
11651
11652 static void
11653 cmd_set_macsec_offload_off_parsed(
11654         void *parsed_result,
11655         __rte_unused struct cmdline *cl,
11656         __rte_unused void *data)
11657 {
11658         struct cmd_macsec_offload_off_result *res = parsed_result;
11659         int ret = -ENOTSUP;
11660         struct rte_eth_dev_info dev_info;
11661         portid_t port_id = res->port_id;
11662
11663         if (port_id_is_invalid(port_id, ENABLED_WARN))
11664                 return;
11665         if (!port_is_stopped(port_id)) {
11666                 printf("Please stop port %d first\n", port_id);
11667                 return;
11668         }
11669
11670         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11671         if (ret != 0)
11672                 return;
11673
11674         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11675 #ifdef RTE_NET_IXGBE
11676                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11677 #endif
11678         }
11679         switch (ret) {
11680         case 0:
11681                 ports[port_id].dev_conf.txmode.offloads &=
11682                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11683                 cmd_reconfig_device_queue(port_id, 1, 1);
11684                 break;
11685         case -ENODEV:
11686                 printf("invalid port_id %d\n", port_id);
11687                 break;
11688         case -ENOTSUP:
11689                 printf("not supported on port %d\n", port_id);
11690                 break;
11691         default:
11692                 printf("programming error: (%s)\n", strerror(-ret));
11693         }
11694 }
11695
11696 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11697         .f = cmd_set_macsec_offload_off_parsed,
11698         .data = NULL,
11699         .help_str = "set macsec offload <port_id> off",
11700         .tokens = {
11701                 (void *)&cmd_macsec_offload_off_set,
11702                 (void *)&cmd_macsec_offload_off_macsec,
11703                 (void *)&cmd_macsec_offload_off_offload,
11704                 (void *)&cmd_macsec_offload_off_port_id,
11705                 (void *)&cmd_macsec_offload_off_off,
11706                 NULL,
11707         },
11708 };
11709
11710 /* Common result structure for MACsec secure connection configure */
11711 struct cmd_macsec_sc_result {
11712         cmdline_fixed_string_t set;
11713         cmdline_fixed_string_t macsec;
11714         cmdline_fixed_string_t sc;
11715         cmdline_fixed_string_t tx_rx;
11716         portid_t port_id;
11717         struct rte_ether_addr mac;
11718         uint16_t pi;
11719 };
11720
11721 /* Common CLI fields for MACsec secure connection configure */
11722 cmdline_parse_token_string_t cmd_macsec_sc_set =
11723         TOKEN_STRING_INITIALIZER
11724                 (struct cmd_macsec_sc_result,
11725                  set, "set");
11726 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11727         TOKEN_STRING_INITIALIZER
11728                 (struct cmd_macsec_sc_result,
11729                  macsec, "macsec");
11730 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11731         TOKEN_STRING_INITIALIZER
11732                 (struct cmd_macsec_sc_result,
11733                  sc, "sc");
11734 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11735         TOKEN_STRING_INITIALIZER
11736                 (struct cmd_macsec_sc_result,
11737                  tx_rx, "tx#rx");
11738 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11739         TOKEN_NUM_INITIALIZER
11740                 (struct cmd_macsec_sc_result,
11741                  port_id, RTE_UINT16);
11742 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11743         TOKEN_ETHERADDR_INITIALIZER
11744                 (struct cmd_macsec_sc_result,
11745                  mac);
11746 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11747         TOKEN_NUM_INITIALIZER
11748                 (struct cmd_macsec_sc_result,
11749                  pi, RTE_UINT16);
11750
11751 static void
11752 cmd_set_macsec_sc_parsed(
11753         void *parsed_result,
11754         __rte_unused struct cmdline *cl,
11755         __rte_unused void *data)
11756 {
11757         struct cmd_macsec_sc_result *res = parsed_result;
11758         int ret = -ENOTSUP;
11759         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11760
11761 #ifdef RTE_NET_IXGBE
11762         ret = is_tx ?
11763                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11764                                 res->mac.addr_bytes) :
11765                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11766                                 res->mac.addr_bytes, res->pi);
11767 #endif
11768         RTE_SET_USED(is_tx);
11769
11770         switch (ret) {
11771         case 0:
11772                 break;
11773         case -ENODEV:
11774                 printf("invalid port_id %d\n", res->port_id);
11775                 break;
11776         case -ENOTSUP:
11777                 printf("not supported on port %d\n", res->port_id);
11778                 break;
11779         default:
11780                 printf("programming error: (%s)\n", strerror(-ret));
11781         }
11782 }
11783
11784 cmdline_parse_inst_t cmd_set_macsec_sc = {
11785         .f = cmd_set_macsec_sc_parsed,
11786         .data = NULL,
11787         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11788         .tokens = {
11789                 (void *)&cmd_macsec_sc_set,
11790                 (void *)&cmd_macsec_sc_macsec,
11791                 (void *)&cmd_macsec_sc_sc,
11792                 (void *)&cmd_macsec_sc_tx_rx,
11793                 (void *)&cmd_macsec_sc_port_id,
11794                 (void *)&cmd_macsec_sc_mac,
11795                 (void *)&cmd_macsec_sc_pi,
11796                 NULL,
11797         },
11798 };
11799
11800 /* Common result structure for MACsec secure connection configure */
11801 struct cmd_macsec_sa_result {
11802         cmdline_fixed_string_t set;
11803         cmdline_fixed_string_t macsec;
11804         cmdline_fixed_string_t sa;
11805         cmdline_fixed_string_t tx_rx;
11806         portid_t port_id;
11807         uint8_t idx;
11808         uint8_t an;
11809         uint32_t pn;
11810         cmdline_fixed_string_t key;
11811 };
11812
11813 /* Common CLI fields for MACsec secure connection configure */
11814 cmdline_parse_token_string_t cmd_macsec_sa_set =
11815         TOKEN_STRING_INITIALIZER
11816                 (struct cmd_macsec_sa_result,
11817                  set, "set");
11818 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11819         TOKEN_STRING_INITIALIZER
11820                 (struct cmd_macsec_sa_result,
11821                  macsec, "macsec");
11822 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11823         TOKEN_STRING_INITIALIZER
11824                 (struct cmd_macsec_sa_result,
11825                  sa, "sa");
11826 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11827         TOKEN_STRING_INITIALIZER
11828                 (struct cmd_macsec_sa_result,
11829                  tx_rx, "tx#rx");
11830 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11831         TOKEN_NUM_INITIALIZER
11832                 (struct cmd_macsec_sa_result,
11833                  port_id, RTE_UINT16);
11834 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11835         TOKEN_NUM_INITIALIZER
11836                 (struct cmd_macsec_sa_result,
11837                  idx, RTE_UINT8);
11838 cmdline_parse_token_num_t cmd_macsec_sa_an =
11839         TOKEN_NUM_INITIALIZER
11840                 (struct cmd_macsec_sa_result,
11841                  an, RTE_UINT8);
11842 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11843         TOKEN_NUM_INITIALIZER
11844                 (struct cmd_macsec_sa_result,
11845                  pn, RTE_UINT32);
11846 cmdline_parse_token_string_t cmd_macsec_sa_key =
11847         TOKEN_STRING_INITIALIZER
11848                 (struct cmd_macsec_sa_result,
11849                  key, NULL);
11850
11851 static void
11852 cmd_set_macsec_sa_parsed(
11853         void *parsed_result,
11854         __rte_unused struct cmdline *cl,
11855         __rte_unused void *data)
11856 {
11857         struct cmd_macsec_sa_result *res = parsed_result;
11858         int ret = -ENOTSUP;
11859         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11860         uint8_t key[16] = { 0 };
11861         uint8_t xdgt0;
11862         uint8_t xdgt1;
11863         int key_len;
11864         int i;
11865
11866         key_len = strlen(res->key) / 2;
11867         if (key_len > 16)
11868                 key_len = 16;
11869
11870         for (i = 0; i < key_len; i++) {
11871                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11872                 if (xdgt0 == 0xFF)
11873                         return;
11874                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11875                 if (xdgt1 == 0xFF)
11876                         return;
11877                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11878         }
11879
11880 #ifdef RTE_NET_IXGBE
11881         ret = is_tx ?
11882                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11883                         res->idx, res->an, res->pn, key) :
11884                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11885                         res->idx, res->an, res->pn, key);
11886 #endif
11887         RTE_SET_USED(is_tx);
11888         RTE_SET_USED(key);
11889
11890         switch (ret) {
11891         case 0:
11892                 break;
11893         case -EINVAL:
11894                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11895                 break;
11896         case -ENODEV:
11897                 printf("invalid port_id %d\n", res->port_id);
11898                 break;
11899         case -ENOTSUP:
11900                 printf("not supported on port %d\n", res->port_id);
11901                 break;
11902         default:
11903                 printf("programming error: (%s)\n", strerror(-ret));
11904         }
11905 }
11906
11907 cmdline_parse_inst_t cmd_set_macsec_sa = {
11908         .f = cmd_set_macsec_sa_parsed,
11909         .data = NULL,
11910         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11911         .tokens = {
11912                 (void *)&cmd_macsec_sa_set,
11913                 (void *)&cmd_macsec_sa_macsec,
11914                 (void *)&cmd_macsec_sa_sa,
11915                 (void *)&cmd_macsec_sa_tx_rx,
11916                 (void *)&cmd_macsec_sa_port_id,
11917                 (void *)&cmd_macsec_sa_idx,
11918                 (void *)&cmd_macsec_sa_an,
11919                 (void *)&cmd_macsec_sa_pn,
11920                 (void *)&cmd_macsec_sa_key,
11921                 NULL,
11922         },
11923 };
11924
11925 /* VF unicast promiscuous mode configuration */
11926
11927 /* Common result structure for VF unicast promiscuous mode */
11928 struct cmd_vf_promisc_result {
11929         cmdline_fixed_string_t set;
11930         cmdline_fixed_string_t vf;
11931         cmdline_fixed_string_t promisc;
11932         portid_t port_id;
11933         uint32_t vf_id;
11934         cmdline_fixed_string_t on_off;
11935 };
11936
11937 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11938 cmdline_parse_token_string_t cmd_vf_promisc_set =
11939         TOKEN_STRING_INITIALIZER
11940                 (struct cmd_vf_promisc_result,
11941                  set, "set");
11942 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11943         TOKEN_STRING_INITIALIZER
11944                 (struct cmd_vf_promisc_result,
11945                  vf, "vf");
11946 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11947         TOKEN_STRING_INITIALIZER
11948                 (struct cmd_vf_promisc_result,
11949                  promisc, "promisc");
11950 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11951         TOKEN_NUM_INITIALIZER
11952                 (struct cmd_vf_promisc_result,
11953                  port_id, RTE_UINT16);
11954 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11955         TOKEN_NUM_INITIALIZER
11956                 (struct cmd_vf_promisc_result,
11957                  vf_id, RTE_UINT32);
11958 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11959         TOKEN_STRING_INITIALIZER
11960                 (struct cmd_vf_promisc_result,
11961                  on_off, "on#off");
11962
11963 static void
11964 cmd_set_vf_promisc_parsed(
11965         void *parsed_result,
11966         __rte_unused struct cmdline *cl,
11967         __rte_unused void *data)
11968 {
11969         struct cmd_vf_promisc_result *res = parsed_result;
11970         int ret = -ENOTSUP;
11971
11972         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11973
11974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11975                 return;
11976
11977 #ifdef RTE_NET_I40E
11978         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11979                                                   res->vf_id, is_on);
11980 #endif
11981
11982         switch (ret) {
11983         case 0:
11984                 break;
11985         case -EINVAL:
11986                 printf("invalid vf_id %d\n", res->vf_id);
11987                 break;
11988         case -ENODEV:
11989                 printf("invalid port_id %d\n", res->port_id);
11990                 break;
11991         case -ENOTSUP:
11992                 printf("function not implemented\n");
11993                 break;
11994         default:
11995                 printf("programming error: (%s)\n", strerror(-ret));
11996         }
11997 }
11998
11999 cmdline_parse_inst_t cmd_set_vf_promisc = {
12000         .f = cmd_set_vf_promisc_parsed,
12001         .data = NULL,
12002         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12003                 "Set unicast promiscuous mode for a VF from the PF",
12004         .tokens = {
12005                 (void *)&cmd_vf_promisc_set,
12006                 (void *)&cmd_vf_promisc_vf,
12007                 (void *)&cmd_vf_promisc_promisc,
12008                 (void *)&cmd_vf_promisc_port_id,
12009                 (void *)&cmd_vf_promisc_vf_id,
12010                 (void *)&cmd_vf_promisc_on_off,
12011                 NULL,
12012         },
12013 };
12014
12015 /* VF multicast promiscuous mode configuration */
12016
12017 /* Common result structure for VF multicast promiscuous mode */
12018 struct cmd_vf_allmulti_result {
12019         cmdline_fixed_string_t set;
12020         cmdline_fixed_string_t vf;
12021         cmdline_fixed_string_t allmulti;
12022         portid_t port_id;
12023         uint32_t vf_id;
12024         cmdline_fixed_string_t on_off;
12025 };
12026
12027 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12028 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12029         TOKEN_STRING_INITIALIZER
12030                 (struct cmd_vf_allmulti_result,
12031                  set, "set");
12032 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12033         TOKEN_STRING_INITIALIZER
12034                 (struct cmd_vf_allmulti_result,
12035                  vf, "vf");
12036 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12037         TOKEN_STRING_INITIALIZER
12038                 (struct cmd_vf_allmulti_result,
12039                  allmulti, "allmulti");
12040 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12041         TOKEN_NUM_INITIALIZER
12042                 (struct cmd_vf_allmulti_result,
12043                  port_id, RTE_UINT16);
12044 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12045         TOKEN_NUM_INITIALIZER
12046                 (struct cmd_vf_allmulti_result,
12047                  vf_id, RTE_UINT32);
12048 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12049         TOKEN_STRING_INITIALIZER
12050                 (struct cmd_vf_allmulti_result,
12051                  on_off, "on#off");
12052
12053 static void
12054 cmd_set_vf_allmulti_parsed(
12055         void *parsed_result,
12056         __rte_unused struct cmdline *cl,
12057         __rte_unused void *data)
12058 {
12059         struct cmd_vf_allmulti_result *res = parsed_result;
12060         int ret = -ENOTSUP;
12061
12062         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12063
12064         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12065                 return;
12066
12067 #ifdef RTE_NET_I40E
12068         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12069                                                     res->vf_id, is_on);
12070 #endif
12071
12072         switch (ret) {
12073         case 0:
12074                 break;
12075         case -EINVAL:
12076                 printf("invalid vf_id %d\n", res->vf_id);
12077                 break;
12078         case -ENODEV:
12079                 printf("invalid port_id %d\n", res->port_id);
12080                 break;
12081         case -ENOTSUP:
12082                 printf("function not implemented\n");
12083                 break;
12084         default:
12085                 printf("programming error: (%s)\n", strerror(-ret));
12086         }
12087 }
12088
12089 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12090         .f = cmd_set_vf_allmulti_parsed,
12091         .data = NULL,
12092         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12093                 "Set multicast promiscuous mode for a VF from the PF",
12094         .tokens = {
12095                 (void *)&cmd_vf_allmulti_set,
12096                 (void *)&cmd_vf_allmulti_vf,
12097                 (void *)&cmd_vf_allmulti_allmulti,
12098                 (void *)&cmd_vf_allmulti_port_id,
12099                 (void *)&cmd_vf_allmulti_vf_id,
12100                 (void *)&cmd_vf_allmulti_on_off,
12101                 NULL,
12102         },
12103 };
12104
12105 /* vf broadcast mode configuration */
12106
12107 /* Common result structure for vf broadcast */
12108 struct cmd_set_vf_broadcast_result {
12109         cmdline_fixed_string_t set;
12110         cmdline_fixed_string_t vf;
12111         cmdline_fixed_string_t broadcast;
12112         portid_t port_id;
12113         uint16_t vf_id;
12114         cmdline_fixed_string_t on_off;
12115 };
12116
12117 /* Common CLI fields for vf broadcast enable disable */
12118 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12119         TOKEN_STRING_INITIALIZER
12120                 (struct cmd_set_vf_broadcast_result,
12121                  set, "set");
12122 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12123         TOKEN_STRING_INITIALIZER
12124                 (struct cmd_set_vf_broadcast_result,
12125                  vf, "vf");
12126 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12127         TOKEN_STRING_INITIALIZER
12128                 (struct cmd_set_vf_broadcast_result,
12129                  broadcast, "broadcast");
12130 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12131         TOKEN_NUM_INITIALIZER
12132                 (struct cmd_set_vf_broadcast_result,
12133                  port_id, RTE_UINT16);
12134 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12135         TOKEN_NUM_INITIALIZER
12136                 (struct cmd_set_vf_broadcast_result,
12137                  vf_id, RTE_UINT16);
12138 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12139         TOKEN_STRING_INITIALIZER
12140                 (struct cmd_set_vf_broadcast_result,
12141                  on_off, "on#off");
12142
12143 static void
12144 cmd_set_vf_broadcast_parsed(
12145         void *parsed_result,
12146         __rte_unused struct cmdline *cl,
12147         __rte_unused void *data)
12148 {
12149         struct cmd_set_vf_broadcast_result *res = parsed_result;
12150         int ret = -ENOTSUP;
12151
12152         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12153
12154         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12155                 return;
12156
12157 #ifdef RTE_NET_I40E
12158         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12159                                             res->vf_id, is_on);
12160 #endif
12161
12162         switch (ret) {
12163         case 0:
12164                 break;
12165         case -EINVAL:
12166                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12167                 break;
12168         case -ENODEV:
12169                 printf("invalid port_id %d\n", res->port_id);
12170                 break;
12171         case -ENOTSUP:
12172                 printf("function not implemented\n");
12173                 break;
12174         default:
12175                 printf("programming error: (%s)\n", strerror(-ret));
12176         }
12177 }
12178
12179 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12180         .f = cmd_set_vf_broadcast_parsed,
12181         .data = NULL,
12182         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12183         .tokens = {
12184                 (void *)&cmd_set_vf_broadcast_set,
12185                 (void *)&cmd_set_vf_broadcast_vf,
12186                 (void *)&cmd_set_vf_broadcast_broadcast,
12187                 (void *)&cmd_set_vf_broadcast_port_id,
12188                 (void *)&cmd_set_vf_broadcast_vf_id,
12189                 (void *)&cmd_set_vf_broadcast_on_off,
12190                 NULL,
12191         },
12192 };
12193
12194 /* vf vlan tag configuration */
12195
12196 /* Common result structure for vf vlan tag */
12197 struct cmd_set_vf_vlan_tag_result {
12198         cmdline_fixed_string_t set;
12199         cmdline_fixed_string_t vf;
12200         cmdline_fixed_string_t vlan;
12201         cmdline_fixed_string_t tag;
12202         portid_t port_id;
12203         uint16_t vf_id;
12204         cmdline_fixed_string_t on_off;
12205 };
12206
12207 /* Common CLI fields for vf vlan tag enable disable */
12208 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12209         TOKEN_STRING_INITIALIZER
12210                 (struct cmd_set_vf_vlan_tag_result,
12211                  set, "set");
12212 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12213         TOKEN_STRING_INITIALIZER
12214                 (struct cmd_set_vf_vlan_tag_result,
12215                  vf, "vf");
12216 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12217         TOKEN_STRING_INITIALIZER
12218                 (struct cmd_set_vf_vlan_tag_result,
12219                  vlan, "vlan");
12220 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12221         TOKEN_STRING_INITIALIZER
12222                 (struct cmd_set_vf_vlan_tag_result,
12223                  tag, "tag");
12224 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12225         TOKEN_NUM_INITIALIZER
12226                 (struct cmd_set_vf_vlan_tag_result,
12227                  port_id, RTE_UINT16);
12228 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12229         TOKEN_NUM_INITIALIZER
12230                 (struct cmd_set_vf_vlan_tag_result,
12231                  vf_id, RTE_UINT16);
12232 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12233         TOKEN_STRING_INITIALIZER
12234                 (struct cmd_set_vf_vlan_tag_result,
12235                  on_off, "on#off");
12236
12237 static void
12238 cmd_set_vf_vlan_tag_parsed(
12239         void *parsed_result,
12240         __rte_unused struct cmdline *cl,
12241         __rte_unused void *data)
12242 {
12243         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12244         int ret = -ENOTSUP;
12245
12246         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12247
12248         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12249                 return;
12250
12251 #ifdef RTE_NET_I40E
12252         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12253                                            res->vf_id, is_on);
12254 #endif
12255
12256         switch (ret) {
12257         case 0:
12258                 break;
12259         case -EINVAL:
12260                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12261                 break;
12262         case -ENODEV:
12263                 printf("invalid port_id %d\n", res->port_id);
12264                 break;
12265         case -ENOTSUP:
12266                 printf("function not implemented\n");
12267                 break;
12268         default:
12269                 printf("programming error: (%s)\n", strerror(-ret));
12270         }
12271 }
12272
12273 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12274         .f = cmd_set_vf_vlan_tag_parsed,
12275         .data = NULL,
12276         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12277         .tokens = {
12278                 (void *)&cmd_set_vf_vlan_tag_set,
12279                 (void *)&cmd_set_vf_vlan_tag_vf,
12280                 (void *)&cmd_set_vf_vlan_tag_vlan,
12281                 (void *)&cmd_set_vf_vlan_tag_tag,
12282                 (void *)&cmd_set_vf_vlan_tag_port_id,
12283                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12284                 (void *)&cmd_set_vf_vlan_tag_on_off,
12285                 NULL,
12286         },
12287 };
12288
12289 /* Common definition of VF and TC TX bandwidth configuration */
12290 struct cmd_vf_tc_bw_result {
12291         cmdline_fixed_string_t set;
12292         cmdline_fixed_string_t vf;
12293         cmdline_fixed_string_t tc;
12294         cmdline_fixed_string_t tx;
12295         cmdline_fixed_string_t min_bw;
12296         cmdline_fixed_string_t max_bw;
12297         cmdline_fixed_string_t strict_link_prio;
12298         portid_t port_id;
12299         uint16_t vf_id;
12300         uint8_t tc_no;
12301         uint32_t bw;
12302         cmdline_fixed_string_t bw_list;
12303         uint8_t tc_map;
12304 };
12305
12306 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12307         TOKEN_STRING_INITIALIZER
12308                 (struct cmd_vf_tc_bw_result,
12309                  set, "set");
12310 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12311         TOKEN_STRING_INITIALIZER
12312                 (struct cmd_vf_tc_bw_result,
12313                  vf, "vf");
12314 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12315         TOKEN_STRING_INITIALIZER
12316                 (struct cmd_vf_tc_bw_result,
12317                  tc, "tc");
12318 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12319         TOKEN_STRING_INITIALIZER
12320                 (struct cmd_vf_tc_bw_result,
12321                  tx, "tx");
12322 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_vf_tc_bw_result,
12325                  strict_link_prio, "strict-link-priority");
12326 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_vf_tc_bw_result,
12329                  min_bw, "min-bandwidth");
12330 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12331         TOKEN_STRING_INITIALIZER
12332                 (struct cmd_vf_tc_bw_result,
12333                  max_bw, "max-bandwidth");
12334 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12335         TOKEN_NUM_INITIALIZER
12336                 (struct cmd_vf_tc_bw_result,
12337                  port_id, RTE_UINT16);
12338 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12339         TOKEN_NUM_INITIALIZER
12340                 (struct cmd_vf_tc_bw_result,
12341                  vf_id, RTE_UINT16);
12342 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12343         TOKEN_NUM_INITIALIZER
12344                 (struct cmd_vf_tc_bw_result,
12345                  tc_no, RTE_UINT8);
12346 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12347         TOKEN_NUM_INITIALIZER
12348                 (struct cmd_vf_tc_bw_result,
12349                  bw, RTE_UINT32);
12350 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12351         TOKEN_STRING_INITIALIZER
12352                 (struct cmd_vf_tc_bw_result,
12353                  bw_list, NULL);
12354 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12355         TOKEN_NUM_INITIALIZER
12356                 (struct cmd_vf_tc_bw_result,
12357                  tc_map, RTE_UINT8);
12358
12359 /* VF max bandwidth setting */
12360 static void
12361 cmd_vf_max_bw_parsed(
12362         void *parsed_result,
12363         __rte_unused struct cmdline *cl,
12364         __rte_unused void *data)
12365 {
12366         struct cmd_vf_tc_bw_result *res = parsed_result;
12367         int ret = -ENOTSUP;
12368
12369         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12370                 return;
12371
12372 #ifdef RTE_NET_I40E
12373         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12374                                          res->vf_id, res->bw);
12375 #endif
12376
12377         switch (ret) {
12378         case 0:
12379                 break;
12380         case -EINVAL:
12381                 printf("invalid vf_id %d or bandwidth %d\n",
12382                        res->vf_id, res->bw);
12383                 break;
12384         case -ENODEV:
12385                 printf("invalid port_id %d\n", res->port_id);
12386                 break;
12387         case -ENOTSUP:
12388                 printf("function not implemented\n");
12389                 break;
12390         default:
12391                 printf("programming error: (%s)\n", strerror(-ret));
12392         }
12393 }
12394
12395 cmdline_parse_inst_t cmd_vf_max_bw = {
12396         .f = cmd_vf_max_bw_parsed,
12397         .data = NULL,
12398         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12399         .tokens = {
12400                 (void *)&cmd_vf_tc_bw_set,
12401                 (void *)&cmd_vf_tc_bw_vf,
12402                 (void *)&cmd_vf_tc_bw_tx,
12403                 (void *)&cmd_vf_tc_bw_max_bw,
12404                 (void *)&cmd_vf_tc_bw_port_id,
12405                 (void *)&cmd_vf_tc_bw_vf_id,
12406                 (void *)&cmd_vf_tc_bw_bw,
12407                 NULL,
12408         },
12409 };
12410
12411 static int
12412 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12413                            uint8_t *tc_num,
12414                            char *str)
12415 {
12416         uint32_t size;
12417         const char *p, *p0 = str;
12418         char s[256];
12419         char *end;
12420         char *str_fld[16];
12421         uint16_t i;
12422         int ret;
12423
12424         p = strchr(p0, '(');
12425         if (p == NULL) {
12426                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12427                 return -1;
12428         }
12429         p++;
12430         p0 = strchr(p, ')');
12431         if (p0 == NULL) {
12432                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12433                 return -1;
12434         }
12435         size = p0 - p;
12436         if (size >= sizeof(s)) {
12437                 printf("The string size exceeds the internal buffer size\n");
12438                 return -1;
12439         }
12440         snprintf(s, sizeof(s), "%.*s", size, p);
12441         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12442         if (ret <= 0) {
12443                 printf("Failed to get the bandwidth list. ");
12444                 return -1;
12445         }
12446         *tc_num = ret;
12447         for (i = 0; i < ret; i++)
12448                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12449
12450         return 0;
12451 }
12452
12453 /* TC min bandwidth setting */
12454 static void
12455 cmd_vf_tc_min_bw_parsed(
12456         void *parsed_result,
12457         __rte_unused struct cmdline *cl,
12458         __rte_unused void *data)
12459 {
12460         struct cmd_vf_tc_bw_result *res = parsed_result;
12461         uint8_t tc_num;
12462         uint8_t bw[16];
12463         int ret = -ENOTSUP;
12464
12465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12466                 return;
12467
12468         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12469         if (ret)
12470                 return;
12471
12472 #ifdef RTE_NET_I40E
12473         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12474                                               tc_num, bw);
12475 #endif
12476
12477         switch (ret) {
12478         case 0:
12479                 break;
12480         case -EINVAL:
12481                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12482                 break;
12483         case -ENODEV:
12484                 printf("invalid port_id %d\n", res->port_id);
12485                 break;
12486         case -ENOTSUP:
12487                 printf("function not implemented\n");
12488                 break;
12489         default:
12490                 printf("programming error: (%s)\n", strerror(-ret));
12491         }
12492 }
12493
12494 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12495         .f = cmd_vf_tc_min_bw_parsed,
12496         .data = NULL,
12497         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12498                     " <bw1, bw2, ...>",
12499         .tokens = {
12500                 (void *)&cmd_vf_tc_bw_set,
12501                 (void *)&cmd_vf_tc_bw_vf,
12502                 (void *)&cmd_vf_tc_bw_tc,
12503                 (void *)&cmd_vf_tc_bw_tx,
12504                 (void *)&cmd_vf_tc_bw_min_bw,
12505                 (void *)&cmd_vf_tc_bw_port_id,
12506                 (void *)&cmd_vf_tc_bw_vf_id,
12507                 (void *)&cmd_vf_tc_bw_bw_list,
12508                 NULL,
12509         },
12510 };
12511
12512 static void
12513 cmd_tc_min_bw_parsed(
12514         void *parsed_result,
12515         __rte_unused struct cmdline *cl,
12516         __rte_unused void *data)
12517 {
12518         struct cmd_vf_tc_bw_result *res = parsed_result;
12519         struct rte_port *port;
12520         uint8_t tc_num;
12521         uint8_t bw[16];
12522         int ret = -ENOTSUP;
12523
12524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12525                 return;
12526
12527         port = &ports[res->port_id];
12528         /** Check if the port is not started **/
12529         if (port->port_status != RTE_PORT_STOPPED) {
12530                 printf("Please stop port %d first\n", res->port_id);
12531                 return;
12532         }
12533
12534         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12535         if (ret)
12536                 return;
12537
12538 #ifdef RTE_NET_IXGBE
12539         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12540 #endif
12541
12542         switch (ret) {
12543         case 0:
12544                 break;
12545         case -EINVAL:
12546                 printf("invalid bandwidth\n");
12547                 break;
12548         case -ENODEV:
12549                 printf("invalid port_id %d\n", res->port_id);
12550                 break;
12551         case -ENOTSUP:
12552                 printf("function not implemented\n");
12553                 break;
12554         default:
12555                 printf("programming error: (%s)\n", strerror(-ret));
12556         }
12557 }
12558
12559 cmdline_parse_inst_t cmd_tc_min_bw = {
12560         .f = cmd_tc_min_bw_parsed,
12561         .data = NULL,
12562         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12563         .tokens = {
12564                 (void *)&cmd_vf_tc_bw_set,
12565                 (void *)&cmd_vf_tc_bw_tc,
12566                 (void *)&cmd_vf_tc_bw_tx,
12567                 (void *)&cmd_vf_tc_bw_min_bw,
12568                 (void *)&cmd_vf_tc_bw_port_id,
12569                 (void *)&cmd_vf_tc_bw_bw_list,
12570                 NULL,
12571         },
12572 };
12573
12574 /* TC max bandwidth setting */
12575 static void
12576 cmd_vf_tc_max_bw_parsed(
12577         void *parsed_result,
12578         __rte_unused struct cmdline *cl,
12579         __rte_unused void *data)
12580 {
12581         struct cmd_vf_tc_bw_result *res = parsed_result;
12582         int ret = -ENOTSUP;
12583
12584         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12585                 return;
12586
12587 #ifdef RTE_NET_I40E
12588         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12589                                             res->tc_no, res->bw);
12590 #endif
12591
12592         switch (ret) {
12593         case 0:
12594                 break;
12595         case -EINVAL:
12596                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12597                        res->vf_id, res->tc_no, res->bw);
12598                 break;
12599         case -ENODEV:
12600                 printf("invalid port_id %d\n", res->port_id);
12601                 break;
12602         case -ENOTSUP:
12603                 printf("function not implemented\n");
12604                 break;
12605         default:
12606                 printf("programming error: (%s)\n", strerror(-ret));
12607         }
12608 }
12609
12610 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12611         .f = cmd_vf_tc_max_bw_parsed,
12612         .data = NULL,
12613         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12614                     " <bandwidth>",
12615         .tokens = {
12616                 (void *)&cmd_vf_tc_bw_set,
12617                 (void *)&cmd_vf_tc_bw_vf,
12618                 (void *)&cmd_vf_tc_bw_tc,
12619                 (void *)&cmd_vf_tc_bw_tx,
12620                 (void *)&cmd_vf_tc_bw_max_bw,
12621                 (void *)&cmd_vf_tc_bw_port_id,
12622                 (void *)&cmd_vf_tc_bw_vf_id,
12623                 (void *)&cmd_vf_tc_bw_tc_no,
12624                 (void *)&cmd_vf_tc_bw_bw,
12625                 NULL,
12626         },
12627 };
12628
12629 /** Set VXLAN encapsulation details */
12630 struct cmd_set_vxlan_result {
12631         cmdline_fixed_string_t set;
12632         cmdline_fixed_string_t vxlan;
12633         cmdline_fixed_string_t pos_token;
12634         cmdline_fixed_string_t ip_version;
12635         uint32_t vlan_present:1;
12636         uint32_t vni;
12637         uint16_t udp_src;
12638         uint16_t udp_dst;
12639         cmdline_ipaddr_t ip_src;
12640         cmdline_ipaddr_t ip_dst;
12641         uint16_t tci;
12642         uint8_t tos;
12643         uint8_t ttl;
12644         struct rte_ether_addr eth_src;
12645         struct rte_ether_addr eth_dst;
12646 };
12647
12648 cmdline_parse_token_string_t cmd_set_vxlan_set =
12649         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12650 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12651         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12652 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12653         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12654                                  "vxlan-tos-ttl");
12655 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12656         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12657                                  "vxlan-with-vlan");
12658 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12659         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12660                                  "ip-version");
12661 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12662         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12663                                  "ipv4#ipv6");
12664 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12665         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12666                                  "vni");
12667 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12668         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12669 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12670         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12671                                  "udp-src");
12672 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12673         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12674 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12675         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12676                                  "udp-dst");
12677 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12678         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12679 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12680         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12681                                  "ip-tos");
12682 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12683         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12684 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12685         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12686                                  "ip-ttl");
12687 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12688         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12689 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12690         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12691                                  "ip-src");
12692 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12693         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12694 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12695         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12696                                  "ip-dst");
12697 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12698         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12699 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12700         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12701                                  "vlan-tci");
12702 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12703         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12704 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12705         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12706                                  "eth-src");
12707 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12708         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12709 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12710         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12711                                  "eth-dst");
12712 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12713         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12714
12715 static void cmd_set_vxlan_parsed(void *parsed_result,
12716         __rte_unused struct cmdline *cl,
12717         __rte_unused void *data)
12718 {
12719         struct cmd_set_vxlan_result *res = parsed_result;
12720         union {
12721                 uint32_t vxlan_id;
12722                 uint8_t vni[4];
12723         } id = {
12724                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12725         };
12726
12727         vxlan_encap_conf.select_tos_ttl = 0;
12728         if (strcmp(res->vxlan, "vxlan") == 0)
12729                 vxlan_encap_conf.select_vlan = 0;
12730         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12731                 vxlan_encap_conf.select_vlan = 1;
12732         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12733                 vxlan_encap_conf.select_vlan = 0;
12734                 vxlan_encap_conf.select_tos_ttl = 1;
12735         }
12736         if (strcmp(res->ip_version, "ipv4") == 0)
12737                 vxlan_encap_conf.select_ipv4 = 1;
12738         else if (strcmp(res->ip_version, "ipv6") == 0)
12739                 vxlan_encap_conf.select_ipv4 = 0;
12740         else
12741                 return;
12742         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12743         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12744         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12745         vxlan_encap_conf.ip_tos = res->tos;
12746         vxlan_encap_conf.ip_ttl = res->ttl;
12747         if (vxlan_encap_conf.select_ipv4) {
12748                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12749                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12750         } else {
12751                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12752                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12753         }
12754         if (vxlan_encap_conf.select_vlan)
12755                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12756         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12757                    RTE_ETHER_ADDR_LEN);
12758         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12759                    RTE_ETHER_ADDR_LEN);
12760 }
12761
12762 cmdline_parse_inst_t cmd_set_vxlan = {
12763         .f = cmd_set_vxlan_parsed,
12764         .data = NULL,
12765         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12766                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12767                 " eth-src <eth-src> eth-dst <eth-dst>",
12768         .tokens = {
12769                 (void *)&cmd_set_vxlan_set,
12770                 (void *)&cmd_set_vxlan_vxlan,
12771                 (void *)&cmd_set_vxlan_ip_version,
12772                 (void *)&cmd_set_vxlan_ip_version_value,
12773                 (void *)&cmd_set_vxlan_vni,
12774                 (void *)&cmd_set_vxlan_vni_value,
12775                 (void *)&cmd_set_vxlan_udp_src,
12776                 (void *)&cmd_set_vxlan_udp_src_value,
12777                 (void *)&cmd_set_vxlan_udp_dst,
12778                 (void *)&cmd_set_vxlan_udp_dst_value,
12779                 (void *)&cmd_set_vxlan_ip_src,
12780                 (void *)&cmd_set_vxlan_ip_src_value,
12781                 (void *)&cmd_set_vxlan_ip_dst,
12782                 (void *)&cmd_set_vxlan_ip_dst_value,
12783                 (void *)&cmd_set_vxlan_eth_src,
12784                 (void *)&cmd_set_vxlan_eth_src_value,
12785                 (void *)&cmd_set_vxlan_eth_dst,
12786                 (void *)&cmd_set_vxlan_eth_dst_value,
12787                 NULL,
12788         },
12789 };
12790
12791 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12792         .f = cmd_set_vxlan_parsed,
12793         .data = NULL,
12794         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12795                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12796                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12797                 " eth-dst <eth-dst>",
12798         .tokens = {
12799                 (void *)&cmd_set_vxlan_set,
12800                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12801                 (void *)&cmd_set_vxlan_ip_version,
12802                 (void *)&cmd_set_vxlan_ip_version_value,
12803                 (void *)&cmd_set_vxlan_vni,
12804                 (void *)&cmd_set_vxlan_vni_value,
12805                 (void *)&cmd_set_vxlan_udp_src,
12806                 (void *)&cmd_set_vxlan_udp_src_value,
12807                 (void *)&cmd_set_vxlan_udp_dst,
12808                 (void *)&cmd_set_vxlan_udp_dst_value,
12809                 (void *)&cmd_set_vxlan_ip_tos,
12810                 (void *)&cmd_set_vxlan_ip_tos_value,
12811                 (void *)&cmd_set_vxlan_ip_ttl,
12812                 (void *)&cmd_set_vxlan_ip_ttl_value,
12813                 (void *)&cmd_set_vxlan_ip_src,
12814                 (void *)&cmd_set_vxlan_ip_src_value,
12815                 (void *)&cmd_set_vxlan_ip_dst,
12816                 (void *)&cmd_set_vxlan_ip_dst_value,
12817                 (void *)&cmd_set_vxlan_eth_src,
12818                 (void *)&cmd_set_vxlan_eth_src_value,
12819                 (void *)&cmd_set_vxlan_eth_dst,
12820                 (void *)&cmd_set_vxlan_eth_dst_value,
12821                 NULL,
12822         },
12823 };
12824
12825 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12826         .f = cmd_set_vxlan_parsed,
12827         .data = NULL,
12828         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12829                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12830                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12831                 " <eth-dst>",
12832         .tokens = {
12833                 (void *)&cmd_set_vxlan_set,
12834                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12835                 (void *)&cmd_set_vxlan_ip_version,
12836                 (void *)&cmd_set_vxlan_ip_version_value,
12837                 (void *)&cmd_set_vxlan_vni,
12838                 (void *)&cmd_set_vxlan_vni_value,
12839                 (void *)&cmd_set_vxlan_udp_src,
12840                 (void *)&cmd_set_vxlan_udp_src_value,
12841                 (void *)&cmd_set_vxlan_udp_dst,
12842                 (void *)&cmd_set_vxlan_udp_dst_value,
12843                 (void *)&cmd_set_vxlan_ip_src,
12844                 (void *)&cmd_set_vxlan_ip_src_value,
12845                 (void *)&cmd_set_vxlan_ip_dst,
12846                 (void *)&cmd_set_vxlan_ip_dst_value,
12847                 (void *)&cmd_set_vxlan_vlan,
12848                 (void *)&cmd_set_vxlan_vlan_value,
12849                 (void *)&cmd_set_vxlan_eth_src,
12850                 (void *)&cmd_set_vxlan_eth_src_value,
12851                 (void *)&cmd_set_vxlan_eth_dst,
12852                 (void *)&cmd_set_vxlan_eth_dst_value,
12853                 NULL,
12854         },
12855 };
12856
12857 /** Set NVGRE encapsulation details */
12858 struct cmd_set_nvgre_result {
12859         cmdline_fixed_string_t set;
12860         cmdline_fixed_string_t nvgre;
12861         cmdline_fixed_string_t pos_token;
12862         cmdline_fixed_string_t ip_version;
12863         uint32_t tni;
12864         cmdline_ipaddr_t ip_src;
12865         cmdline_ipaddr_t ip_dst;
12866         uint16_t tci;
12867         struct rte_ether_addr eth_src;
12868         struct rte_ether_addr eth_dst;
12869 };
12870
12871 cmdline_parse_token_string_t cmd_set_nvgre_set =
12872         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12873 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12874         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12875 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12876         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12877                                  "nvgre-with-vlan");
12878 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12879         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12880                                  "ip-version");
12881 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12882         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12883                                  "ipv4#ipv6");
12884 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12885         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12886                                  "tni");
12887 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12888         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12889 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12890         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12891                                  "ip-src");
12892 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12893         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12894 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12895         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12896                                  "ip-dst");
12897 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12898         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12899 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12900         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12901                                  "vlan-tci");
12902 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12903         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12904 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12905         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12906                                  "eth-src");
12907 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12908         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12909 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12910         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12911                                  "eth-dst");
12912 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12913         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12914
12915 static void cmd_set_nvgre_parsed(void *parsed_result,
12916         __rte_unused struct cmdline *cl,
12917         __rte_unused void *data)
12918 {
12919         struct cmd_set_nvgre_result *res = parsed_result;
12920         union {
12921                 uint32_t nvgre_tni;
12922                 uint8_t tni[4];
12923         } id = {
12924                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12925         };
12926
12927         if (strcmp(res->nvgre, "nvgre") == 0)
12928                 nvgre_encap_conf.select_vlan = 0;
12929         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12930                 nvgre_encap_conf.select_vlan = 1;
12931         if (strcmp(res->ip_version, "ipv4") == 0)
12932                 nvgre_encap_conf.select_ipv4 = 1;
12933         else if (strcmp(res->ip_version, "ipv6") == 0)
12934                 nvgre_encap_conf.select_ipv4 = 0;
12935         else
12936                 return;
12937         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12938         if (nvgre_encap_conf.select_ipv4) {
12939                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12940                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12941         } else {
12942                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12943                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12944         }
12945         if (nvgre_encap_conf.select_vlan)
12946                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12947         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12948                    RTE_ETHER_ADDR_LEN);
12949         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12950                    RTE_ETHER_ADDR_LEN);
12951 }
12952
12953 cmdline_parse_inst_t cmd_set_nvgre = {
12954         .f = cmd_set_nvgre_parsed,
12955         .data = NULL,
12956         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12957                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12958                 " eth-dst <eth-dst>",
12959         .tokens = {
12960                 (void *)&cmd_set_nvgre_set,
12961                 (void *)&cmd_set_nvgre_nvgre,
12962                 (void *)&cmd_set_nvgre_ip_version,
12963                 (void *)&cmd_set_nvgre_ip_version_value,
12964                 (void *)&cmd_set_nvgre_tni,
12965                 (void *)&cmd_set_nvgre_tni_value,
12966                 (void *)&cmd_set_nvgre_ip_src,
12967                 (void *)&cmd_set_nvgre_ip_src_value,
12968                 (void *)&cmd_set_nvgre_ip_dst,
12969                 (void *)&cmd_set_nvgre_ip_dst_value,
12970                 (void *)&cmd_set_nvgre_eth_src,
12971                 (void *)&cmd_set_nvgre_eth_src_value,
12972                 (void *)&cmd_set_nvgre_eth_dst,
12973                 (void *)&cmd_set_nvgre_eth_dst_value,
12974                 NULL,
12975         },
12976 };
12977
12978 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12979         .f = cmd_set_nvgre_parsed,
12980         .data = NULL,
12981         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12982                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12983                 " eth-src <eth-src> eth-dst <eth-dst>",
12984         .tokens = {
12985                 (void *)&cmd_set_nvgre_set,
12986                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12987                 (void *)&cmd_set_nvgre_ip_version,
12988                 (void *)&cmd_set_nvgre_ip_version_value,
12989                 (void *)&cmd_set_nvgre_tni,
12990                 (void *)&cmd_set_nvgre_tni_value,
12991                 (void *)&cmd_set_nvgre_ip_src,
12992                 (void *)&cmd_set_nvgre_ip_src_value,
12993                 (void *)&cmd_set_nvgre_ip_dst,
12994                 (void *)&cmd_set_nvgre_ip_dst_value,
12995                 (void *)&cmd_set_nvgre_vlan,
12996                 (void *)&cmd_set_nvgre_vlan_value,
12997                 (void *)&cmd_set_nvgre_eth_src,
12998                 (void *)&cmd_set_nvgre_eth_src_value,
12999                 (void *)&cmd_set_nvgre_eth_dst,
13000                 (void *)&cmd_set_nvgre_eth_dst_value,
13001                 NULL,
13002         },
13003 };
13004
13005 /** Set L2 encapsulation details */
13006 struct cmd_set_l2_encap_result {
13007         cmdline_fixed_string_t set;
13008         cmdline_fixed_string_t l2_encap;
13009         cmdline_fixed_string_t pos_token;
13010         cmdline_fixed_string_t ip_version;
13011         uint32_t vlan_present:1;
13012         uint16_t tci;
13013         struct rte_ether_addr eth_src;
13014         struct rte_ether_addr eth_dst;
13015 };
13016
13017 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13018         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13019 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13020         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13021 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13022         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13023                                  "l2_encap-with-vlan");
13024 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13025         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13026                                  "ip-version");
13027 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13028         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13029                                  "ipv4#ipv6");
13030 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13031         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13032                                  "vlan-tci");
13033 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13034         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13035 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13036         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13037                                  "eth-src");
13038 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13039         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13040 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13041         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13042                                  "eth-dst");
13043 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13044         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13045
13046 static void cmd_set_l2_encap_parsed(void *parsed_result,
13047         __rte_unused struct cmdline *cl,
13048         __rte_unused void *data)
13049 {
13050         struct cmd_set_l2_encap_result *res = parsed_result;
13051
13052         if (strcmp(res->l2_encap, "l2_encap") == 0)
13053                 l2_encap_conf.select_vlan = 0;
13054         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13055                 l2_encap_conf.select_vlan = 1;
13056         if (strcmp(res->ip_version, "ipv4") == 0)
13057                 l2_encap_conf.select_ipv4 = 1;
13058         else if (strcmp(res->ip_version, "ipv6") == 0)
13059                 l2_encap_conf.select_ipv4 = 0;
13060         else
13061                 return;
13062         if (l2_encap_conf.select_vlan)
13063                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13064         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13065                    RTE_ETHER_ADDR_LEN);
13066         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13067                    RTE_ETHER_ADDR_LEN);
13068 }
13069
13070 cmdline_parse_inst_t cmd_set_l2_encap = {
13071         .f = cmd_set_l2_encap_parsed,
13072         .data = NULL,
13073         .help_str = "set l2_encap ip-version ipv4|ipv6"
13074                 " eth-src <eth-src> eth-dst <eth-dst>",
13075         .tokens = {
13076                 (void *)&cmd_set_l2_encap_set,
13077                 (void *)&cmd_set_l2_encap_l2_encap,
13078                 (void *)&cmd_set_l2_encap_ip_version,
13079                 (void *)&cmd_set_l2_encap_ip_version_value,
13080                 (void *)&cmd_set_l2_encap_eth_src,
13081                 (void *)&cmd_set_l2_encap_eth_src_value,
13082                 (void *)&cmd_set_l2_encap_eth_dst,
13083                 (void *)&cmd_set_l2_encap_eth_dst_value,
13084                 NULL,
13085         },
13086 };
13087
13088 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13089         .f = cmd_set_l2_encap_parsed,
13090         .data = NULL,
13091         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13092                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13093         .tokens = {
13094                 (void *)&cmd_set_l2_encap_set,
13095                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13096                 (void *)&cmd_set_l2_encap_ip_version,
13097                 (void *)&cmd_set_l2_encap_ip_version_value,
13098                 (void *)&cmd_set_l2_encap_vlan,
13099                 (void *)&cmd_set_l2_encap_vlan_value,
13100                 (void *)&cmd_set_l2_encap_eth_src,
13101                 (void *)&cmd_set_l2_encap_eth_src_value,
13102                 (void *)&cmd_set_l2_encap_eth_dst,
13103                 (void *)&cmd_set_l2_encap_eth_dst_value,
13104                 NULL,
13105         },
13106 };
13107
13108 /** Set L2 decapsulation details */
13109 struct cmd_set_l2_decap_result {
13110         cmdline_fixed_string_t set;
13111         cmdline_fixed_string_t l2_decap;
13112         cmdline_fixed_string_t pos_token;
13113         uint32_t vlan_present:1;
13114 };
13115
13116 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13117         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13118 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13119         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13120                                  "l2_decap");
13121 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13122         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13123                                  "l2_decap-with-vlan");
13124
13125 static void cmd_set_l2_decap_parsed(void *parsed_result,
13126         __rte_unused struct cmdline *cl,
13127         __rte_unused void *data)
13128 {
13129         struct cmd_set_l2_decap_result *res = parsed_result;
13130
13131         if (strcmp(res->l2_decap, "l2_decap") == 0)
13132                 l2_decap_conf.select_vlan = 0;
13133         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13134                 l2_decap_conf.select_vlan = 1;
13135 }
13136
13137 cmdline_parse_inst_t cmd_set_l2_decap = {
13138         .f = cmd_set_l2_decap_parsed,
13139         .data = NULL,
13140         .help_str = "set l2_decap",
13141         .tokens = {
13142                 (void *)&cmd_set_l2_decap_set,
13143                 (void *)&cmd_set_l2_decap_l2_decap,
13144                 NULL,
13145         },
13146 };
13147
13148 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13149         .f = cmd_set_l2_decap_parsed,
13150         .data = NULL,
13151         .help_str = "set l2_decap-with-vlan",
13152         .tokens = {
13153                 (void *)&cmd_set_l2_decap_set,
13154                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13155                 NULL,
13156         },
13157 };
13158
13159 /** Set MPLSoGRE encapsulation details */
13160 struct cmd_set_mplsogre_encap_result {
13161         cmdline_fixed_string_t set;
13162         cmdline_fixed_string_t mplsogre;
13163         cmdline_fixed_string_t pos_token;
13164         cmdline_fixed_string_t ip_version;
13165         uint32_t vlan_present:1;
13166         uint32_t label;
13167         cmdline_ipaddr_t ip_src;
13168         cmdline_ipaddr_t ip_dst;
13169         uint16_t tci;
13170         struct rte_ether_addr eth_src;
13171         struct rte_ether_addr eth_dst;
13172 };
13173
13174 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13175         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13176                                  "set");
13177 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13178         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13179                                  "mplsogre_encap");
13180 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13182                                  mplsogre, "mplsogre_encap-with-vlan");
13183 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13185                                  pos_token, "ip-version");
13186 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13187         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13188                                  ip_version, "ipv4#ipv6");
13189 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13191                                  pos_token, "label");
13192 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13193         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13194                               RTE_UINT32);
13195 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13197                                  pos_token, "ip-src");
13198 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13199         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13200 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13202                                  pos_token, "ip-dst");
13203 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13204         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13205 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13207                                  pos_token, "vlan-tci");
13208 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13209         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13210                               RTE_UINT16);
13211 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13212         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13213                                  pos_token, "eth-src");
13214 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13215         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13216                                     eth_src);
13217 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13218         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13219                                  pos_token, "eth-dst");
13220 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13221         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13222                                     eth_dst);
13223
13224 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13225         __rte_unused struct cmdline *cl,
13226         __rte_unused void *data)
13227 {
13228         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13229         union {
13230                 uint32_t mplsogre_label;
13231                 uint8_t label[4];
13232         } id = {
13233                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13234         };
13235
13236         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13237                 mplsogre_encap_conf.select_vlan = 0;
13238         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13239                 mplsogre_encap_conf.select_vlan = 1;
13240         if (strcmp(res->ip_version, "ipv4") == 0)
13241                 mplsogre_encap_conf.select_ipv4 = 1;
13242         else if (strcmp(res->ip_version, "ipv6") == 0)
13243                 mplsogre_encap_conf.select_ipv4 = 0;
13244         else
13245                 return;
13246         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13247         if (mplsogre_encap_conf.select_ipv4) {
13248                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13249                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13250         } else {
13251                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13252                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13253         }
13254         if (mplsogre_encap_conf.select_vlan)
13255                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13256         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13257                    RTE_ETHER_ADDR_LEN);
13258         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13259                    RTE_ETHER_ADDR_LEN);
13260 }
13261
13262 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13263         .f = cmd_set_mplsogre_encap_parsed,
13264         .data = NULL,
13265         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13266                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13267                 " eth-dst <eth-dst>",
13268         .tokens = {
13269                 (void *)&cmd_set_mplsogre_encap_set,
13270                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13271                 (void *)&cmd_set_mplsogre_encap_ip_version,
13272                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13273                 (void *)&cmd_set_mplsogre_encap_label,
13274                 (void *)&cmd_set_mplsogre_encap_label_value,
13275                 (void *)&cmd_set_mplsogre_encap_ip_src,
13276                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13277                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13278                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13279                 (void *)&cmd_set_mplsogre_encap_eth_src,
13280                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13281                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13282                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13283                 NULL,
13284         },
13285 };
13286
13287 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13288         .f = cmd_set_mplsogre_encap_parsed,
13289         .data = NULL,
13290         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13291                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13292                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13293         .tokens = {
13294                 (void *)&cmd_set_mplsogre_encap_set,
13295                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13296                 (void *)&cmd_set_mplsogre_encap_ip_version,
13297                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13298                 (void *)&cmd_set_mplsogre_encap_label,
13299                 (void *)&cmd_set_mplsogre_encap_label_value,
13300                 (void *)&cmd_set_mplsogre_encap_ip_src,
13301                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13302                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13303                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13304                 (void *)&cmd_set_mplsogre_encap_vlan,
13305                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13306                 (void *)&cmd_set_mplsogre_encap_eth_src,
13307                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13308                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13309                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13310                 NULL,
13311         },
13312 };
13313
13314 /** Set MPLSoGRE decapsulation details */
13315 struct cmd_set_mplsogre_decap_result {
13316         cmdline_fixed_string_t set;
13317         cmdline_fixed_string_t mplsogre;
13318         cmdline_fixed_string_t pos_token;
13319         cmdline_fixed_string_t ip_version;
13320         uint32_t vlan_present:1;
13321 };
13322
13323 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13324         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13325                                  "set");
13326 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13328                                  "mplsogre_decap");
13329 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13330         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13331                                  mplsogre, "mplsogre_decap-with-vlan");
13332 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13333         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13334                                  pos_token, "ip-version");
13335 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13336         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13337                                  ip_version, "ipv4#ipv6");
13338
13339 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13340         __rte_unused struct cmdline *cl,
13341         __rte_unused void *data)
13342 {
13343         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13344
13345         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13346                 mplsogre_decap_conf.select_vlan = 0;
13347         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13348                 mplsogre_decap_conf.select_vlan = 1;
13349         if (strcmp(res->ip_version, "ipv4") == 0)
13350                 mplsogre_decap_conf.select_ipv4 = 1;
13351         else if (strcmp(res->ip_version, "ipv6") == 0)
13352                 mplsogre_decap_conf.select_ipv4 = 0;
13353 }
13354
13355 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13356         .f = cmd_set_mplsogre_decap_parsed,
13357         .data = NULL,
13358         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13359         .tokens = {
13360                 (void *)&cmd_set_mplsogre_decap_set,
13361                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13362                 (void *)&cmd_set_mplsogre_decap_ip_version,
13363                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13364                 NULL,
13365         },
13366 };
13367
13368 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13369         .f = cmd_set_mplsogre_decap_parsed,
13370         .data = NULL,
13371         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13372         .tokens = {
13373                 (void *)&cmd_set_mplsogre_decap_set,
13374                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13375                 (void *)&cmd_set_mplsogre_decap_ip_version,
13376                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13377                 NULL,
13378         },
13379 };
13380
13381 /** Set MPLSoUDP encapsulation details */
13382 struct cmd_set_mplsoudp_encap_result {
13383         cmdline_fixed_string_t set;
13384         cmdline_fixed_string_t mplsoudp;
13385         cmdline_fixed_string_t pos_token;
13386         cmdline_fixed_string_t ip_version;
13387         uint32_t vlan_present:1;
13388         uint32_t label;
13389         uint16_t udp_src;
13390         uint16_t udp_dst;
13391         cmdline_ipaddr_t ip_src;
13392         cmdline_ipaddr_t ip_dst;
13393         uint16_t tci;
13394         struct rte_ether_addr eth_src;
13395         struct rte_ether_addr eth_dst;
13396 };
13397
13398 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13399         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13400                                  "set");
13401 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13402         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13403                                  "mplsoudp_encap");
13404 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13405         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13406                                  mplsoudp, "mplsoudp_encap-with-vlan");
13407 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13408         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13409                                  pos_token, "ip-version");
13410 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13411         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13412                                  ip_version, "ipv4#ipv6");
13413 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13414         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13415                                  pos_token, "label");
13416 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13417         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13418                               RTE_UINT32);
13419 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13420         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13421                                  pos_token, "udp-src");
13422 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13423         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13424                               RTE_UINT16);
13425 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13426         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13427                                  pos_token, "udp-dst");
13428 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13429         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13430                               RTE_UINT16);
13431 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13432         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13433                                  pos_token, "ip-src");
13434 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13435         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13436 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13437         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13438                                  pos_token, "ip-dst");
13439 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13440         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13441 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13442         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13443                                  pos_token, "vlan-tci");
13444 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13445         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13446                               RTE_UINT16);
13447 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13448         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13449                                  pos_token, "eth-src");
13450 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13451         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13452                                     eth_src);
13453 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13454         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13455                                  pos_token, "eth-dst");
13456 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13457         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13458                                     eth_dst);
13459
13460 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13461         __rte_unused struct cmdline *cl,
13462         __rte_unused void *data)
13463 {
13464         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13465         union {
13466                 uint32_t mplsoudp_label;
13467                 uint8_t label[4];
13468         } id = {
13469                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13470         };
13471
13472         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13473                 mplsoudp_encap_conf.select_vlan = 0;
13474         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13475                 mplsoudp_encap_conf.select_vlan = 1;
13476         if (strcmp(res->ip_version, "ipv4") == 0)
13477                 mplsoudp_encap_conf.select_ipv4 = 1;
13478         else if (strcmp(res->ip_version, "ipv6") == 0)
13479                 mplsoudp_encap_conf.select_ipv4 = 0;
13480         else
13481                 return;
13482         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13483         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13484         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13485         if (mplsoudp_encap_conf.select_ipv4) {
13486                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13487                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13488         } else {
13489                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13490                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13491         }
13492         if (mplsoudp_encap_conf.select_vlan)
13493                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13494         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13495                    RTE_ETHER_ADDR_LEN);
13496         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13497                    RTE_ETHER_ADDR_LEN);
13498 }
13499
13500 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13501         .f = cmd_set_mplsoudp_encap_parsed,
13502         .data = NULL,
13503         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13504                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13505                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13506         .tokens = {
13507                 (void *)&cmd_set_mplsoudp_encap_set,
13508                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13509                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13510                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13511                 (void *)&cmd_set_mplsoudp_encap_label,
13512                 (void *)&cmd_set_mplsoudp_encap_label_value,
13513                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13514                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13515                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13516                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13517                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13518                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13519                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13520                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13521                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13522                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13523                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13524                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13525                 NULL,
13526         },
13527 };
13528
13529 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13530         .f = cmd_set_mplsoudp_encap_parsed,
13531         .data = NULL,
13532         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13533                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13534                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13535                 " eth-src <eth-src> eth-dst <eth-dst>",
13536         .tokens = {
13537                 (void *)&cmd_set_mplsoudp_encap_set,
13538                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13539                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13540                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13541                 (void *)&cmd_set_mplsoudp_encap_label,
13542                 (void *)&cmd_set_mplsoudp_encap_label_value,
13543                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13544                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13545                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13546                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13547                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13548                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13549                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13550                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13551                 (void *)&cmd_set_mplsoudp_encap_vlan,
13552                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13553                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13554                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13555                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13556                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13557                 NULL,
13558         },
13559 };
13560
13561 /** Set MPLSoUDP decapsulation details */
13562 struct cmd_set_mplsoudp_decap_result {
13563         cmdline_fixed_string_t set;
13564         cmdline_fixed_string_t mplsoudp;
13565         cmdline_fixed_string_t pos_token;
13566         cmdline_fixed_string_t ip_version;
13567         uint32_t vlan_present:1;
13568 };
13569
13570 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13571         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13572                                  "set");
13573 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13574         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13575                                  "mplsoudp_decap");
13576 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13577         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13578                                  mplsoudp, "mplsoudp_decap-with-vlan");
13579 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13580         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13581                                  pos_token, "ip-version");
13582 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13583         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13584                                  ip_version, "ipv4#ipv6");
13585
13586 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13587         __rte_unused struct cmdline *cl,
13588         __rte_unused void *data)
13589 {
13590         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13591
13592         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13593                 mplsoudp_decap_conf.select_vlan = 0;
13594         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13595                 mplsoudp_decap_conf.select_vlan = 1;
13596         if (strcmp(res->ip_version, "ipv4") == 0)
13597                 mplsoudp_decap_conf.select_ipv4 = 1;
13598         else if (strcmp(res->ip_version, "ipv6") == 0)
13599                 mplsoudp_decap_conf.select_ipv4 = 0;
13600 }
13601
13602 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13603         .f = cmd_set_mplsoudp_decap_parsed,
13604         .data = NULL,
13605         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13606         .tokens = {
13607                 (void *)&cmd_set_mplsoudp_decap_set,
13608                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13609                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13610                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13611                 NULL,
13612         },
13613 };
13614
13615 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13616         .f = cmd_set_mplsoudp_decap_parsed,
13617         .data = NULL,
13618         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13619         .tokens = {
13620                 (void *)&cmd_set_mplsoudp_decap_set,
13621                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13622                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13623                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13624                 NULL,
13625         },
13626 };
13627
13628 /* Strict link priority scheduling mode setting */
13629 static void
13630 cmd_strict_link_prio_parsed(
13631         void *parsed_result,
13632         __rte_unused struct cmdline *cl,
13633         __rte_unused void *data)
13634 {
13635         struct cmd_vf_tc_bw_result *res = parsed_result;
13636         int ret = -ENOTSUP;
13637
13638         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13639                 return;
13640
13641 #ifdef RTE_NET_I40E
13642         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13643 #endif
13644
13645         switch (ret) {
13646         case 0:
13647                 break;
13648         case -EINVAL:
13649                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13650                 break;
13651         case -ENODEV:
13652                 printf("invalid port_id %d\n", res->port_id);
13653                 break;
13654         case -ENOTSUP:
13655                 printf("function not implemented\n");
13656                 break;
13657         default:
13658                 printf("programming error: (%s)\n", strerror(-ret));
13659         }
13660 }
13661
13662 cmdline_parse_inst_t cmd_strict_link_prio = {
13663         .f = cmd_strict_link_prio_parsed,
13664         .data = NULL,
13665         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13666         .tokens = {
13667                 (void *)&cmd_vf_tc_bw_set,
13668                 (void *)&cmd_vf_tc_bw_tx,
13669                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13670                 (void *)&cmd_vf_tc_bw_port_id,
13671                 (void *)&cmd_vf_tc_bw_tc_map,
13672                 NULL,
13673         },
13674 };
13675
13676 /* Load dynamic device personalization*/
13677 struct cmd_ddp_add_result {
13678         cmdline_fixed_string_t ddp;
13679         cmdline_fixed_string_t add;
13680         portid_t port_id;
13681         char filepath[];
13682 };
13683
13684 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13685         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13686 cmdline_parse_token_string_t cmd_ddp_add_add =
13687         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13688 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13689         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13690                 RTE_UINT16);
13691 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13692         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13693
13694 static void
13695 cmd_ddp_add_parsed(
13696         void *parsed_result,
13697         __rte_unused struct cmdline *cl,
13698         __rte_unused void *data)
13699 {
13700         struct cmd_ddp_add_result *res = parsed_result;
13701         uint8_t *buff;
13702         uint32_t size;
13703         char *filepath;
13704         char *file_fld[2];
13705         int file_num;
13706         int ret = -ENOTSUP;
13707
13708         if (!all_ports_stopped()) {
13709                 printf("Please stop all ports first\n");
13710                 return;
13711         }
13712
13713         filepath = strdup(res->filepath);
13714         if (filepath == NULL) {
13715                 printf("Failed to allocate memory\n");
13716                 return;
13717         }
13718         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13719
13720         buff = open_file(file_fld[0], &size);
13721         if (!buff) {
13722                 free((void *)filepath);
13723                 return;
13724         }
13725
13726 #ifdef RTE_NET_I40E
13727         if (ret == -ENOTSUP)
13728                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13729                                                buff, size,
13730                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13731 #endif
13732
13733         if (ret == -EEXIST)
13734                 printf("Profile has already existed.\n");
13735         else if (ret < 0)
13736                 printf("Failed to load profile.\n");
13737         else if (file_num == 2)
13738                 save_file(file_fld[1], buff, size);
13739
13740         close_file(buff);
13741         free((void *)filepath);
13742 }
13743
13744 cmdline_parse_inst_t cmd_ddp_add = {
13745         .f = cmd_ddp_add_parsed,
13746         .data = NULL,
13747         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13748         .tokens = {
13749                 (void *)&cmd_ddp_add_ddp,
13750                 (void *)&cmd_ddp_add_add,
13751                 (void *)&cmd_ddp_add_port_id,
13752                 (void *)&cmd_ddp_add_filepath,
13753                 NULL,
13754         },
13755 };
13756
13757 /* Delete dynamic device personalization*/
13758 struct cmd_ddp_del_result {
13759         cmdline_fixed_string_t ddp;
13760         cmdline_fixed_string_t del;
13761         portid_t port_id;
13762         char filepath[];
13763 };
13764
13765 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13766         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13767 cmdline_parse_token_string_t cmd_ddp_del_del =
13768         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13769 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13770         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13771 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13772         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13773
13774 static void
13775 cmd_ddp_del_parsed(
13776         void *parsed_result,
13777         __rte_unused struct cmdline *cl,
13778         __rte_unused void *data)
13779 {
13780         struct cmd_ddp_del_result *res = parsed_result;
13781         uint8_t *buff;
13782         uint32_t size;
13783         int ret = -ENOTSUP;
13784
13785         if (!all_ports_stopped()) {
13786                 printf("Please stop all ports first\n");
13787                 return;
13788         }
13789
13790         buff = open_file(res->filepath, &size);
13791         if (!buff)
13792                 return;
13793
13794 #ifdef RTE_NET_I40E
13795         if (ret == -ENOTSUP)
13796                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13797                                                buff, size,
13798                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13799 #endif
13800
13801         if (ret == -EACCES)
13802                 printf("Profile does not exist.\n");
13803         else if (ret < 0)
13804                 printf("Failed to delete profile.\n");
13805
13806         close_file(buff);
13807 }
13808
13809 cmdline_parse_inst_t cmd_ddp_del = {
13810         .f = cmd_ddp_del_parsed,
13811         .data = NULL,
13812         .help_str = "ddp del <port_id> <backup_profile_path>",
13813         .tokens = {
13814                 (void *)&cmd_ddp_del_ddp,
13815                 (void *)&cmd_ddp_del_del,
13816                 (void *)&cmd_ddp_del_port_id,
13817                 (void *)&cmd_ddp_del_filepath,
13818                 NULL,
13819         },
13820 };
13821
13822 /* Get dynamic device personalization profile info */
13823 struct cmd_ddp_info_result {
13824         cmdline_fixed_string_t ddp;
13825         cmdline_fixed_string_t get;
13826         cmdline_fixed_string_t info;
13827         char filepath[];
13828 };
13829
13830 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13831         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13832 cmdline_parse_token_string_t cmd_ddp_info_get =
13833         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13834 cmdline_parse_token_string_t cmd_ddp_info_info =
13835         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13836 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13837         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13838
13839 static void
13840 cmd_ddp_info_parsed(
13841         void *parsed_result,
13842         __rte_unused struct cmdline *cl,
13843         __rte_unused void *data)
13844 {
13845         struct cmd_ddp_info_result *res = parsed_result;
13846         uint8_t *pkg;
13847         uint32_t pkg_size;
13848         int ret = -ENOTSUP;
13849 #ifdef RTE_NET_I40E
13850         uint32_t i, j, n;
13851         uint8_t *buff;
13852         uint32_t buff_size = 0;
13853         struct rte_pmd_i40e_profile_info info;
13854         uint32_t dev_num = 0;
13855         struct rte_pmd_i40e_ddp_device_id *devs;
13856         uint32_t proto_num = 0;
13857         struct rte_pmd_i40e_proto_info *proto = NULL;
13858         uint32_t pctype_num = 0;
13859         struct rte_pmd_i40e_ptype_info *pctype;
13860         uint32_t ptype_num = 0;
13861         struct rte_pmd_i40e_ptype_info *ptype;
13862         uint8_t proto_id;
13863
13864 #endif
13865
13866         pkg = open_file(res->filepath, &pkg_size);
13867         if (!pkg)
13868                 return;
13869
13870 #ifdef RTE_NET_I40E
13871         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13872                                 (uint8_t *)&info, sizeof(info),
13873                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13874         if (!ret) {
13875                 printf("Global Track id:       0x%x\n", info.track_id);
13876                 printf("Global Version:        %d.%d.%d.%d\n",
13877                         info.version.major,
13878                         info.version.minor,
13879                         info.version.update,
13880                         info.version.draft);
13881                 printf("Global Package name:   %s\n\n", info.name);
13882         }
13883
13884         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13885                                 (uint8_t *)&info, sizeof(info),
13886                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13887         if (!ret) {
13888                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13889                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13890                         info.version.major,
13891                         info.version.minor,
13892                         info.version.update,
13893                         info.version.draft);
13894                 printf("i40e Profile name:     %s\n\n", info.name);
13895         }
13896
13897         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13898                                 (uint8_t *)&buff_size, sizeof(buff_size),
13899                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13900         if (!ret && buff_size) {
13901                 buff = (uint8_t *)malloc(buff_size);
13902                 if (buff) {
13903                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13904                                                 buff, buff_size,
13905                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13906                         if (!ret)
13907                                 printf("Package Notes:\n%s\n\n", buff);
13908                         free(buff);
13909                 }
13910         }
13911
13912         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13913                                 (uint8_t *)&dev_num, sizeof(dev_num),
13914                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13915         if (!ret && dev_num) {
13916                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13917                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13918                 if (devs) {
13919                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13920                                                 (uint8_t *)devs, buff_size,
13921                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13922                         if (!ret) {
13923                                 printf("List of supported devices:\n");
13924                                 for (i = 0; i < dev_num; i++) {
13925                                         printf("  %04X:%04X %04X:%04X\n",
13926                                                 devs[i].vendor_dev_id >> 16,
13927                                                 devs[i].vendor_dev_id & 0xFFFF,
13928                                                 devs[i].sub_vendor_dev_id >> 16,
13929                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13930                                 }
13931                                 printf("\n");
13932                         }
13933                         free(devs);
13934                 }
13935         }
13936
13937         /* get information about protocols and packet types */
13938         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13939                 (uint8_t *)&proto_num, sizeof(proto_num),
13940                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13941         if (ret || !proto_num)
13942                 goto no_print_return;
13943
13944         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13945         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13946         if (!proto)
13947                 goto no_print_return;
13948
13949         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13950                                         buff_size,
13951                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13952         if (!ret) {
13953                 printf("List of used protocols:\n");
13954                 for (i = 0; i < proto_num; i++)
13955                         printf("  %2u: %s\n", proto[i].proto_id,
13956                                proto[i].name);
13957                 printf("\n");
13958         }
13959         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13960                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13961                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13962         if (ret || !pctype_num)
13963                 goto no_print_pctypes;
13964
13965         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13966         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13967         if (!pctype)
13968                 goto no_print_pctypes;
13969
13970         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13971                                         buff_size,
13972                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13973         if (ret) {
13974                 free(pctype);
13975                 goto no_print_pctypes;
13976         }
13977
13978         printf("List of defined packet classification types:\n");
13979         for (i = 0; i < pctype_num; i++) {
13980                 printf("  %2u:", pctype[i].ptype_id);
13981                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13982                         proto_id = pctype[i].protocols[j];
13983                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13984                                 for (n = 0; n < proto_num; n++) {
13985                                         if (proto[n].proto_id == proto_id) {
13986                                                 printf(" %s", proto[n].name);
13987                                                 break;
13988                                         }
13989                                 }
13990                         }
13991                 }
13992                 printf("\n");
13993         }
13994         printf("\n");
13995         free(pctype);
13996
13997 no_print_pctypes:
13998
13999         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14000                                         sizeof(ptype_num),
14001                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14002         if (ret || !ptype_num)
14003                 goto no_print_return;
14004
14005         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14006         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14007         if (!ptype)
14008                 goto no_print_return;
14009
14010         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14011                                         buff_size,
14012                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14013         if (ret) {
14014                 free(ptype);
14015                 goto no_print_return;
14016         }
14017         printf("List of defined packet types:\n");
14018         for (i = 0; i < ptype_num; i++) {
14019                 printf("  %2u:", ptype[i].ptype_id);
14020                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14021                         proto_id = ptype[i].protocols[j];
14022                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14023                                 for (n = 0; n < proto_num; n++) {
14024                                         if (proto[n].proto_id == proto_id) {
14025                                                 printf(" %s", proto[n].name);
14026                                                 break;
14027                                         }
14028                                 }
14029                         }
14030                 }
14031                 printf("\n");
14032         }
14033         free(ptype);
14034         printf("\n");
14035
14036         ret = 0;
14037 no_print_return:
14038         if (proto)
14039                 free(proto);
14040 #endif
14041         if (ret == -ENOTSUP)
14042                 printf("Function not supported in PMD driver\n");
14043         close_file(pkg);
14044 }
14045
14046 cmdline_parse_inst_t cmd_ddp_get_info = {
14047         .f = cmd_ddp_info_parsed,
14048         .data = NULL,
14049         .help_str = "ddp get info <profile_path>",
14050         .tokens = {
14051                 (void *)&cmd_ddp_info_ddp,
14052                 (void *)&cmd_ddp_info_get,
14053                 (void *)&cmd_ddp_info_info,
14054                 (void *)&cmd_ddp_info_filepath,
14055                 NULL,
14056         },
14057 };
14058
14059 /* Get dynamic device personalization profile info list*/
14060 #define PROFILE_INFO_SIZE 48
14061 #define MAX_PROFILE_NUM 16
14062
14063 struct cmd_ddp_get_list_result {
14064         cmdline_fixed_string_t ddp;
14065         cmdline_fixed_string_t get;
14066         cmdline_fixed_string_t list;
14067         portid_t port_id;
14068 };
14069
14070 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14071         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14072 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14073         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14074 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14075         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14076 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14077         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14078                 RTE_UINT16);
14079
14080 static void
14081 cmd_ddp_get_list_parsed(
14082         __rte_unused void *parsed_result,
14083         __rte_unused struct cmdline *cl,
14084         __rte_unused void *data)
14085 {
14086 #ifdef RTE_NET_I40E
14087         struct cmd_ddp_get_list_result *res = parsed_result;
14088         struct rte_pmd_i40e_profile_list *p_list;
14089         struct rte_pmd_i40e_profile_info *p_info;
14090         uint32_t p_num;
14091         uint32_t size;
14092         uint32_t i;
14093 #endif
14094         int ret = -ENOTSUP;
14095
14096 #ifdef RTE_NET_I40E
14097         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14098         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14099         if (!p_list) {
14100                 printf("%s: Failed to malloc buffer\n", __func__);
14101                 return;
14102         }
14103
14104         if (ret == -ENOTSUP)
14105                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14106                                                 (uint8_t *)p_list, size);
14107
14108         if (!ret) {
14109                 p_num = p_list->p_count;
14110                 printf("Profile number is: %d\n\n", p_num);
14111
14112                 for (i = 0; i < p_num; i++) {
14113                         p_info = &p_list->p_info[i];
14114                         printf("Profile %d:\n", i);
14115                         printf("Track id:     0x%x\n", p_info->track_id);
14116                         printf("Version:      %d.%d.%d.%d\n",
14117                                p_info->version.major,
14118                                p_info->version.minor,
14119                                p_info->version.update,
14120                                p_info->version.draft);
14121                         printf("Profile name: %s\n\n", p_info->name);
14122                 }
14123         }
14124
14125         free(p_list);
14126 #endif
14127
14128         if (ret < 0)
14129                 printf("Failed to get ddp list\n");
14130 }
14131
14132 cmdline_parse_inst_t cmd_ddp_get_list = {
14133         .f = cmd_ddp_get_list_parsed,
14134         .data = NULL,
14135         .help_str = "ddp get list <port_id>",
14136         .tokens = {
14137                 (void *)&cmd_ddp_get_list_ddp,
14138                 (void *)&cmd_ddp_get_list_get,
14139                 (void *)&cmd_ddp_get_list_list,
14140                 (void *)&cmd_ddp_get_list_port_id,
14141                 NULL,
14142         },
14143 };
14144
14145 /* Configure input set */
14146 struct cmd_cfg_input_set_result {
14147         cmdline_fixed_string_t port;
14148         cmdline_fixed_string_t cfg;
14149         portid_t port_id;
14150         cmdline_fixed_string_t pctype;
14151         uint8_t pctype_id;
14152         cmdline_fixed_string_t inset_type;
14153         cmdline_fixed_string_t opt;
14154         cmdline_fixed_string_t field;
14155         uint8_t field_idx;
14156 };
14157
14158 static void
14159 cmd_cfg_input_set_parsed(
14160         __rte_unused void *parsed_result,
14161         __rte_unused struct cmdline *cl,
14162         __rte_unused void *data)
14163 {
14164 #ifdef RTE_NET_I40E
14165         struct cmd_cfg_input_set_result *res = parsed_result;
14166         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14167         struct rte_pmd_i40e_inset inset;
14168 #endif
14169         int ret = -ENOTSUP;
14170
14171         if (!all_ports_stopped()) {
14172                 printf("Please stop all ports first\n");
14173                 return;
14174         }
14175
14176 #ifdef RTE_NET_I40E
14177         if (!strcmp(res->inset_type, "hash_inset"))
14178                 inset_type = INSET_HASH;
14179         else if (!strcmp(res->inset_type, "fdir_inset"))
14180                 inset_type = INSET_FDIR;
14181         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14182                 inset_type = INSET_FDIR_FLX;
14183         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14184                                      &inset, inset_type);
14185         if (ret) {
14186                 printf("Failed to get input set.\n");
14187                 return;
14188         }
14189
14190         if (!strcmp(res->opt, "get")) {
14191                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14192                                                    res->field_idx);
14193                 if (ret)
14194                         printf("Field index %d is enabled.\n", res->field_idx);
14195                 else
14196                         printf("Field index %d is disabled.\n", res->field_idx);
14197                 return;
14198         } else if (!strcmp(res->opt, "set"))
14199                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14200                                                    res->field_idx);
14201         else if (!strcmp(res->opt, "clear"))
14202                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14203                                                      res->field_idx);
14204         if (ret) {
14205                 printf("Failed to configure input set field.\n");
14206                 return;
14207         }
14208
14209         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14210                                      &inset, inset_type);
14211         if (ret) {
14212                 printf("Failed to set input set.\n");
14213                 return;
14214         }
14215 #endif
14216
14217         if (ret == -ENOTSUP)
14218                 printf("Function not supported\n");
14219 }
14220
14221 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14222         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14223                                  port, "port");
14224 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14225         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14226                                  cfg, "config");
14227 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14228         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14229                               port_id, RTE_UINT16);
14230 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14231         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14232                                  pctype, "pctype");
14233 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14234         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14235                               pctype_id, RTE_UINT8);
14236 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14237         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14238                                  inset_type,
14239                                  "hash_inset#fdir_inset#fdir_flx_inset");
14240 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14241         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14242                                  opt, "get#set#clear");
14243 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14244         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14245                                  field, "field");
14246 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14247         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14248                               field_idx, RTE_UINT8);
14249
14250 cmdline_parse_inst_t cmd_cfg_input_set = {
14251         .f = cmd_cfg_input_set_parsed,
14252         .data = NULL,
14253         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14254                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14255         .tokens = {
14256                 (void *)&cmd_cfg_input_set_port,
14257                 (void *)&cmd_cfg_input_set_cfg,
14258                 (void *)&cmd_cfg_input_set_port_id,
14259                 (void *)&cmd_cfg_input_set_pctype,
14260                 (void *)&cmd_cfg_input_set_pctype_id,
14261                 (void *)&cmd_cfg_input_set_inset_type,
14262                 (void *)&cmd_cfg_input_set_opt,
14263                 (void *)&cmd_cfg_input_set_field,
14264                 (void *)&cmd_cfg_input_set_field_idx,
14265                 NULL,
14266         },
14267 };
14268
14269 /* Clear input set */
14270 struct cmd_clear_input_set_result {
14271         cmdline_fixed_string_t port;
14272         cmdline_fixed_string_t cfg;
14273         portid_t port_id;
14274         cmdline_fixed_string_t pctype;
14275         uint8_t pctype_id;
14276         cmdline_fixed_string_t inset_type;
14277         cmdline_fixed_string_t clear;
14278         cmdline_fixed_string_t all;
14279 };
14280
14281 static void
14282 cmd_clear_input_set_parsed(
14283         __rte_unused void *parsed_result,
14284         __rte_unused struct cmdline *cl,
14285         __rte_unused void *data)
14286 {
14287 #ifdef RTE_NET_I40E
14288         struct cmd_clear_input_set_result *res = parsed_result;
14289         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14290         struct rte_pmd_i40e_inset inset;
14291 #endif
14292         int ret = -ENOTSUP;
14293
14294         if (!all_ports_stopped()) {
14295                 printf("Please stop all ports first\n");
14296                 return;
14297         }
14298
14299 #ifdef RTE_NET_I40E
14300         if (!strcmp(res->inset_type, "hash_inset"))
14301                 inset_type = INSET_HASH;
14302         else if (!strcmp(res->inset_type, "fdir_inset"))
14303                 inset_type = INSET_FDIR;
14304         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14305                 inset_type = INSET_FDIR_FLX;
14306
14307         memset(&inset, 0, sizeof(inset));
14308
14309         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14310                                      &inset, inset_type);
14311         if (ret) {
14312                 printf("Failed to clear input set.\n");
14313                 return;
14314         }
14315
14316 #endif
14317
14318         if (ret == -ENOTSUP)
14319                 printf("Function not supported\n");
14320 }
14321
14322 cmdline_parse_token_string_t cmd_clear_input_set_port =
14323         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14324                                  port, "port");
14325 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14326         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14327                                  cfg, "config");
14328 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14329         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14330                               port_id, RTE_UINT16);
14331 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14332         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14333                                  pctype, "pctype");
14334 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14335         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14336                               pctype_id, RTE_UINT8);
14337 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14338         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14339                                  inset_type,
14340                                  "hash_inset#fdir_inset#fdir_flx_inset");
14341 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14342         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14343                                  clear, "clear");
14344 cmdline_parse_token_string_t cmd_clear_input_set_all =
14345         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14346                                  all, "all");
14347
14348 cmdline_parse_inst_t cmd_clear_input_set = {
14349         .f = cmd_clear_input_set_parsed,
14350         .data = NULL,
14351         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14352                     "fdir_inset|fdir_flx_inset clear all",
14353         .tokens = {
14354                 (void *)&cmd_clear_input_set_port,
14355                 (void *)&cmd_clear_input_set_cfg,
14356                 (void *)&cmd_clear_input_set_port_id,
14357                 (void *)&cmd_clear_input_set_pctype,
14358                 (void *)&cmd_clear_input_set_pctype_id,
14359                 (void *)&cmd_clear_input_set_inset_type,
14360                 (void *)&cmd_clear_input_set_clear,
14361                 (void *)&cmd_clear_input_set_all,
14362                 NULL,
14363         },
14364 };
14365
14366 /* show vf stats */
14367
14368 /* Common result structure for show vf stats */
14369 struct cmd_show_vf_stats_result {
14370         cmdline_fixed_string_t show;
14371         cmdline_fixed_string_t vf;
14372         cmdline_fixed_string_t stats;
14373         portid_t port_id;
14374         uint16_t vf_id;
14375 };
14376
14377 /* Common CLI fields show vf stats*/
14378 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_show_vf_stats_result,
14381                  show, "show");
14382 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_show_vf_stats_result,
14385                  vf, "vf");
14386 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14387         TOKEN_STRING_INITIALIZER
14388                 (struct cmd_show_vf_stats_result,
14389                  stats, "stats");
14390 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14391         TOKEN_NUM_INITIALIZER
14392                 (struct cmd_show_vf_stats_result,
14393                  port_id, RTE_UINT16);
14394 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14395         TOKEN_NUM_INITIALIZER
14396                 (struct cmd_show_vf_stats_result,
14397                  vf_id, RTE_UINT16);
14398
14399 static void
14400 cmd_show_vf_stats_parsed(
14401         void *parsed_result,
14402         __rte_unused struct cmdline *cl,
14403         __rte_unused void *data)
14404 {
14405         struct cmd_show_vf_stats_result *res = parsed_result;
14406         struct rte_eth_stats stats;
14407         int ret = -ENOTSUP;
14408         static const char *nic_stats_border = "########################";
14409
14410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14411                 return;
14412
14413         memset(&stats, 0, sizeof(stats));
14414
14415 #ifdef RTE_NET_I40E
14416         if (ret == -ENOTSUP)
14417                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14418                                                 res->vf_id,
14419                                                 &stats);
14420 #endif
14421 #ifdef RTE_NET_BNXT
14422         if (ret == -ENOTSUP)
14423                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14424                                                 res->vf_id,
14425                                                 &stats);
14426 #endif
14427
14428         switch (ret) {
14429         case 0:
14430                 break;
14431         case -EINVAL:
14432                 printf("invalid vf_id %d\n", res->vf_id);
14433                 break;
14434         case -ENODEV:
14435                 printf("invalid port_id %d\n", res->port_id);
14436                 break;
14437         case -ENOTSUP:
14438                 printf("function not implemented\n");
14439                 break;
14440         default:
14441                 printf("programming error: (%s)\n", strerror(-ret));
14442         }
14443
14444         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14445                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14446
14447         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14448                "%-"PRIu64"\n",
14449                stats.ipackets, stats.imissed, stats.ibytes);
14450         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14451         printf("  RX-nombuf:  %-10"PRIu64"\n",
14452                stats.rx_nombuf);
14453         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14454                "%-"PRIu64"\n",
14455                stats.opackets, stats.oerrors, stats.obytes);
14456
14457         printf("  %s############################%s\n",
14458                                nic_stats_border, nic_stats_border);
14459 }
14460
14461 cmdline_parse_inst_t cmd_show_vf_stats = {
14462         .f = cmd_show_vf_stats_parsed,
14463         .data = NULL,
14464         .help_str = "show vf stats <port_id> <vf_id>",
14465         .tokens = {
14466                 (void *)&cmd_show_vf_stats_show,
14467                 (void *)&cmd_show_vf_stats_vf,
14468                 (void *)&cmd_show_vf_stats_stats,
14469                 (void *)&cmd_show_vf_stats_port_id,
14470                 (void *)&cmd_show_vf_stats_vf_id,
14471                 NULL,
14472         },
14473 };
14474
14475 /* clear vf stats */
14476
14477 /* Common result structure for clear vf stats */
14478 struct cmd_clear_vf_stats_result {
14479         cmdline_fixed_string_t clear;
14480         cmdline_fixed_string_t vf;
14481         cmdline_fixed_string_t stats;
14482         portid_t port_id;
14483         uint16_t vf_id;
14484 };
14485
14486 /* Common CLI fields clear vf stats*/
14487 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14488         TOKEN_STRING_INITIALIZER
14489                 (struct cmd_clear_vf_stats_result,
14490                  clear, "clear");
14491 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14492         TOKEN_STRING_INITIALIZER
14493                 (struct cmd_clear_vf_stats_result,
14494                  vf, "vf");
14495 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14496         TOKEN_STRING_INITIALIZER
14497                 (struct cmd_clear_vf_stats_result,
14498                  stats, "stats");
14499 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14500         TOKEN_NUM_INITIALIZER
14501                 (struct cmd_clear_vf_stats_result,
14502                  port_id, RTE_UINT16);
14503 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14504         TOKEN_NUM_INITIALIZER
14505                 (struct cmd_clear_vf_stats_result,
14506                  vf_id, RTE_UINT16);
14507
14508 static void
14509 cmd_clear_vf_stats_parsed(
14510         void *parsed_result,
14511         __rte_unused struct cmdline *cl,
14512         __rte_unused void *data)
14513 {
14514         struct cmd_clear_vf_stats_result *res = parsed_result;
14515         int ret = -ENOTSUP;
14516
14517         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14518                 return;
14519
14520 #ifdef RTE_NET_I40E
14521         if (ret == -ENOTSUP)
14522                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14523                                                   res->vf_id);
14524 #endif
14525 #ifdef RTE_NET_BNXT
14526         if (ret == -ENOTSUP)
14527                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14528                                                   res->vf_id);
14529 #endif
14530
14531         switch (ret) {
14532         case 0:
14533                 break;
14534         case -EINVAL:
14535                 printf("invalid vf_id %d\n", res->vf_id);
14536                 break;
14537         case -ENODEV:
14538                 printf("invalid port_id %d\n", res->port_id);
14539                 break;
14540         case -ENOTSUP:
14541                 printf("function not implemented\n");
14542                 break;
14543         default:
14544                 printf("programming error: (%s)\n", strerror(-ret));
14545         }
14546 }
14547
14548 cmdline_parse_inst_t cmd_clear_vf_stats = {
14549         .f = cmd_clear_vf_stats_parsed,
14550         .data = NULL,
14551         .help_str = "clear vf stats <port_id> <vf_id>",
14552         .tokens = {
14553                 (void *)&cmd_clear_vf_stats_clear,
14554                 (void *)&cmd_clear_vf_stats_vf,
14555                 (void *)&cmd_clear_vf_stats_stats,
14556                 (void *)&cmd_clear_vf_stats_port_id,
14557                 (void *)&cmd_clear_vf_stats_vf_id,
14558                 NULL,
14559         },
14560 };
14561
14562 /* port config pctype mapping reset */
14563
14564 /* Common result structure for port config pctype mapping reset */
14565 struct cmd_pctype_mapping_reset_result {
14566         cmdline_fixed_string_t port;
14567         cmdline_fixed_string_t config;
14568         portid_t port_id;
14569         cmdline_fixed_string_t pctype;
14570         cmdline_fixed_string_t mapping;
14571         cmdline_fixed_string_t reset;
14572 };
14573
14574 /* Common CLI fields for port config pctype mapping reset*/
14575 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_pctype_mapping_reset_result,
14578                  port, "port");
14579 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14580         TOKEN_STRING_INITIALIZER
14581                 (struct cmd_pctype_mapping_reset_result,
14582                  config, "config");
14583 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14584         TOKEN_NUM_INITIALIZER
14585                 (struct cmd_pctype_mapping_reset_result,
14586                  port_id, RTE_UINT16);
14587 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14588         TOKEN_STRING_INITIALIZER
14589                 (struct cmd_pctype_mapping_reset_result,
14590                  pctype, "pctype");
14591 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14592         TOKEN_STRING_INITIALIZER
14593                 (struct cmd_pctype_mapping_reset_result,
14594                  mapping, "mapping");
14595 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14596         TOKEN_STRING_INITIALIZER
14597                 (struct cmd_pctype_mapping_reset_result,
14598                  reset, "reset");
14599
14600 static void
14601 cmd_pctype_mapping_reset_parsed(
14602         void *parsed_result,
14603         __rte_unused struct cmdline *cl,
14604         __rte_unused void *data)
14605 {
14606         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14607         int ret = -ENOTSUP;
14608
14609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14610                 return;
14611
14612 #ifdef RTE_NET_I40E
14613         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14614 #endif
14615
14616         switch (ret) {
14617         case 0:
14618                 break;
14619         case -ENODEV:
14620                 printf("invalid port_id %d\n", res->port_id);
14621                 break;
14622         case -ENOTSUP:
14623                 printf("function not implemented\n");
14624                 break;
14625         default:
14626                 printf("programming error: (%s)\n", strerror(-ret));
14627         }
14628 }
14629
14630 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14631         .f = cmd_pctype_mapping_reset_parsed,
14632         .data = NULL,
14633         .help_str = "port config <port_id> pctype mapping reset",
14634         .tokens = {
14635                 (void *)&cmd_pctype_mapping_reset_port,
14636                 (void *)&cmd_pctype_mapping_reset_config,
14637                 (void *)&cmd_pctype_mapping_reset_port_id,
14638                 (void *)&cmd_pctype_mapping_reset_pctype,
14639                 (void *)&cmd_pctype_mapping_reset_mapping,
14640                 (void *)&cmd_pctype_mapping_reset_reset,
14641                 NULL,
14642         },
14643 };
14644
14645 /* show port pctype mapping */
14646
14647 /* Common result structure for show port pctype mapping */
14648 struct cmd_pctype_mapping_get_result {
14649         cmdline_fixed_string_t show;
14650         cmdline_fixed_string_t port;
14651         portid_t port_id;
14652         cmdline_fixed_string_t pctype;
14653         cmdline_fixed_string_t mapping;
14654 };
14655
14656 /* Common CLI fields for pctype mapping get */
14657 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14658         TOKEN_STRING_INITIALIZER
14659                 (struct cmd_pctype_mapping_get_result,
14660                  show, "show");
14661 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14662         TOKEN_STRING_INITIALIZER
14663                 (struct cmd_pctype_mapping_get_result,
14664                  port, "port");
14665 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14666         TOKEN_NUM_INITIALIZER
14667                 (struct cmd_pctype_mapping_get_result,
14668                  port_id, RTE_UINT16);
14669 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_pctype_mapping_get_result,
14672                  pctype, "pctype");
14673 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_pctype_mapping_get_result,
14676                  mapping, "mapping");
14677
14678 static void
14679 cmd_pctype_mapping_get_parsed(
14680         void *parsed_result,
14681         __rte_unused struct cmdline *cl,
14682         __rte_unused void *data)
14683 {
14684         struct cmd_pctype_mapping_get_result *res = parsed_result;
14685         int ret = -ENOTSUP;
14686 #ifdef RTE_NET_I40E
14687         struct rte_pmd_i40e_flow_type_mapping
14688                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14689         int i, j, first_pctype;
14690 #endif
14691
14692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14693                 return;
14694
14695 #ifdef RTE_NET_I40E
14696         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14697 #endif
14698
14699         switch (ret) {
14700         case 0:
14701                 break;
14702         case -ENODEV:
14703                 printf("invalid port_id %d\n", res->port_id);
14704                 return;
14705         case -ENOTSUP:
14706                 printf("function not implemented\n");
14707                 return;
14708         default:
14709                 printf("programming error: (%s)\n", strerror(-ret));
14710                 return;
14711         }
14712
14713 #ifdef RTE_NET_I40E
14714         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14715                 if (mapping[i].pctype != 0ULL) {
14716                         first_pctype = 1;
14717
14718                         printf("pctype: ");
14719                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14720                                 if (mapping[i].pctype & (1ULL << j)) {
14721                                         printf(first_pctype ?
14722                                                "%02d" : ",%02d", j);
14723                                         first_pctype = 0;
14724                                 }
14725                         }
14726                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14727                 }
14728         }
14729 #endif
14730 }
14731
14732 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14733         .f = cmd_pctype_mapping_get_parsed,
14734         .data = NULL,
14735         .help_str = "show port <port_id> pctype mapping",
14736         .tokens = {
14737                 (void *)&cmd_pctype_mapping_get_show,
14738                 (void *)&cmd_pctype_mapping_get_port,
14739                 (void *)&cmd_pctype_mapping_get_port_id,
14740                 (void *)&cmd_pctype_mapping_get_pctype,
14741                 (void *)&cmd_pctype_mapping_get_mapping,
14742                 NULL,
14743         },
14744 };
14745
14746 /* port config pctype mapping update */
14747
14748 /* Common result structure for port config pctype mapping update */
14749 struct cmd_pctype_mapping_update_result {
14750         cmdline_fixed_string_t port;
14751         cmdline_fixed_string_t config;
14752         portid_t port_id;
14753         cmdline_fixed_string_t pctype;
14754         cmdline_fixed_string_t mapping;
14755         cmdline_fixed_string_t update;
14756         cmdline_fixed_string_t pctype_list;
14757         uint16_t flow_type;
14758 };
14759
14760 /* Common CLI fields for pctype mapping update*/
14761 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_pctype_mapping_update_result,
14764                  port, "port");
14765 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14766         TOKEN_STRING_INITIALIZER
14767                 (struct cmd_pctype_mapping_update_result,
14768                  config, "config");
14769 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14770         TOKEN_NUM_INITIALIZER
14771                 (struct cmd_pctype_mapping_update_result,
14772                  port_id, RTE_UINT16);
14773 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14774         TOKEN_STRING_INITIALIZER
14775                 (struct cmd_pctype_mapping_update_result,
14776                  pctype, "pctype");
14777 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14778         TOKEN_STRING_INITIALIZER
14779                 (struct cmd_pctype_mapping_update_result,
14780                  mapping, "mapping");
14781 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14782         TOKEN_STRING_INITIALIZER
14783                 (struct cmd_pctype_mapping_update_result,
14784                  update, "update");
14785 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14786         TOKEN_STRING_INITIALIZER
14787                 (struct cmd_pctype_mapping_update_result,
14788                  pctype_list, NULL);
14789 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14790         TOKEN_NUM_INITIALIZER
14791                 (struct cmd_pctype_mapping_update_result,
14792                  flow_type, RTE_UINT16);
14793
14794 static void
14795 cmd_pctype_mapping_update_parsed(
14796         void *parsed_result,
14797         __rte_unused struct cmdline *cl,
14798         __rte_unused void *data)
14799 {
14800         struct cmd_pctype_mapping_update_result *res = parsed_result;
14801         int ret = -ENOTSUP;
14802 #ifdef RTE_NET_I40E
14803         struct rte_pmd_i40e_flow_type_mapping mapping;
14804         unsigned int i;
14805         unsigned int nb_item;
14806         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14807 #endif
14808
14809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14810                 return;
14811
14812 #ifdef RTE_NET_I40E
14813         nb_item = parse_item_list(res->pctype_list, "pctypes",
14814                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14815         mapping.flow_type = res->flow_type;
14816         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14817                 mapping.pctype |= (1ULL << pctype_list[i]);
14818         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14819                                                 &mapping,
14820                                                 1,
14821                                                 0);
14822 #endif
14823
14824         switch (ret) {
14825         case 0:
14826                 break;
14827         case -EINVAL:
14828                 printf("invalid pctype or flow type\n");
14829                 break;
14830         case -ENODEV:
14831                 printf("invalid port_id %d\n", res->port_id);
14832                 break;
14833         case -ENOTSUP:
14834                 printf("function not implemented\n");
14835                 break;
14836         default:
14837                 printf("programming error: (%s)\n", strerror(-ret));
14838         }
14839 }
14840
14841 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14842         .f = cmd_pctype_mapping_update_parsed,
14843         .data = NULL,
14844         .help_str = "port config <port_id> pctype mapping update"
14845         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14846         .tokens = {
14847                 (void *)&cmd_pctype_mapping_update_port,
14848                 (void *)&cmd_pctype_mapping_update_config,
14849                 (void *)&cmd_pctype_mapping_update_port_id,
14850                 (void *)&cmd_pctype_mapping_update_pctype,
14851                 (void *)&cmd_pctype_mapping_update_mapping,
14852                 (void *)&cmd_pctype_mapping_update_update,
14853                 (void *)&cmd_pctype_mapping_update_pc_type,
14854                 (void *)&cmd_pctype_mapping_update_flow_type,
14855                 NULL,
14856         },
14857 };
14858
14859 /* ptype mapping get */
14860
14861 /* Common result structure for ptype mapping get */
14862 struct cmd_ptype_mapping_get_result {
14863         cmdline_fixed_string_t ptype;
14864         cmdline_fixed_string_t mapping;
14865         cmdline_fixed_string_t get;
14866         portid_t port_id;
14867         uint8_t valid_only;
14868 };
14869
14870 /* Common CLI fields for ptype mapping get */
14871 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14872         TOKEN_STRING_INITIALIZER
14873                 (struct cmd_ptype_mapping_get_result,
14874                  ptype, "ptype");
14875 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14876         TOKEN_STRING_INITIALIZER
14877                 (struct cmd_ptype_mapping_get_result,
14878                  mapping, "mapping");
14879 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14880         TOKEN_STRING_INITIALIZER
14881                 (struct cmd_ptype_mapping_get_result,
14882                  get, "get");
14883 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14884         TOKEN_NUM_INITIALIZER
14885                 (struct cmd_ptype_mapping_get_result,
14886                  port_id, RTE_UINT16);
14887 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14888         TOKEN_NUM_INITIALIZER
14889                 (struct cmd_ptype_mapping_get_result,
14890                  valid_only, RTE_UINT8);
14891
14892 static void
14893 cmd_ptype_mapping_get_parsed(
14894         void *parsed_result,
14895         __rte_unused struct cmdline *cl,
14896         __rte_unused void *data)
14897 {
14898         struct cmd_ptype_mapping_get_result *res = parsed_result;
14899         int ret = -ENOTSUP;
14900 #ifdef RTE_NET_I40E
14901         int max_ptype_num = 256;
14902         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14903         uint16_t count;
14904         int i;
14905 #endif
14906
14907         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14908                 return;
14909
14910 #ifdef RTE_NET_I40E
14911         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14912                                         mapping,
14913                                         max_ptype_num,
14914                                         &count,
14915                                         res->valid_only);
14916 #endif
14917
14918         switch (ret) {
14919         case 0:
14920                 break;
14921         case -ENODEV:
14922                 printf("invalid port_id %d\n", res->port_id);
14923                 break;
14924         case -ENOTSUP:
14925                 printf("function not implemented\n");
14926                 break;
14927         default:
14928                 printf("programming error: (%s)\n", strerror(-ret));
14929         }
14930
14931 #ifdef RTE_NET_I40E
14932         if (!ret) {
14933                 for (i = 0; i < count; i++)
14934                         printf("%3d\t0x%08x\n",
14935                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14936         }
14937 #endif
14938 }
14939
14940 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14941         .f = cmd_ptype_mapping_get_parsed,
14942         .data = NULL,
14943         .help_str = "ptype mapping get <port_id> <valid_only>",
14944         .tokens = {
14945                 (void *)&cmd_ptype_mapping_get_ptype,
14946                 (void *)&cmd_ptype_mapping_get_mapping,
14947                 (void *)&cmd_ptype_mapping_get_get,
14948                 (void *)&cmd_ptype_mapping_get_port_id,
14949                 (void *)&cmd_ptype_mapping_get_valid_only,
14950                 NULL,
14951         },
14952 };
14953
14954 /* ptype mapping replace */
14955
14956 /* Common result structure for ptype mapping replace */
14957 struct cmd_ptype_mapping_replace_result {
14958         cmdline_fixed_string_t ptype;
14959         cmdline_fixed_string_t mapping;
14960         cmdline_fixed_string_t replace;
14961         portid_t port_id;
14962         uint32_t target;
14963         uint8_t mask;
14964         uint32_t pkt_type;
14965 };
14966
14967 /* Common CLI fields for ptype mapping replace */
14968 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14969         TOKEN_STRING_INITIALIZER
14970                 (struct cmd_ptype_mapping_replace_result,
14971                  ptype, "ptype");
14972 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14973         TOKEN_STRING_INITIALIZER
14974                 (struct cmd_ptype_mapping_replace_result,
14975                  mapping, "mapping");
14976 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14977         TOKEN_STRING_INITIALIZER
14978                 (struct cmd_ptype_mapping_replace_result,
14979                  replace, "replace");
14980 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14981         TOKEN_NUM_INITIALIZER
14982                 (struct cmd_ptype_mapping_replace_result,
14983                  port_id, RTE_UINT16);
14984 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14985         TOKEN_NUM_INITIALIZER
14986                 (struct cmd_ptype_mapping_replace_result,
14987                  target, RTE_UINT32);
14988 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14989         TOKEN_NUM_INITIALIZER
14990                 (struct cmd_ptype_mapping_replace_result,
14991                  mask, RTE_UINT8);
14992 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14993         TOKEN_NUM_INITIALIZER
14994                 (struct cmd_ptype_mapping_replace_result,
14995                  pkt_type, RTE_UINT32);
14996
14997 static void
14998 cmd_ptype_mapping_replace_parsed(
14999         void *parsed_result,
15000         __rte_unused struct cmdline *cl,
15001         __rte_unused void *data)
15002 {
15003         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15004         int ret = -ENOTSUP;
15005
15006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15007                 return;
15008
15009 #ifdef RTE_NET_I40E
15010         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15011                                         res->target,
15012                                         res->mask,
15013                                         res->pkt_type);
15014 #endif
15015
15016         switch (ret) {
15017         case 0:
15018                 break;
15019         case -EINVAL:
15020                 printf("invalid ptype 0x%8x or 0x%8x\n",
15021                                 res->target, res->pkt_type);
15022                 break;
15023         case -ENODEV:
15024                 printf("invalid port_id %d\n", res->port_id);
15025                 break;
15026         case -ENOTSUP:
15027                 printf("function not implemented\n");
15028                 break;
15029         default:
15030                 printf("programming error: (%s)\n", strerror(-ret));
15031         }
15032 }
15033
15034 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15035         .f = cmd_ptype_mapping_replace_parsed,
15036         .data = NULL,
15037         .help_str =
15038                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15039         .tokens = {
15040                 (void *)&cmd_ptype_mapping_replace_ptype,
15041                 (void *)&cmd_ptype_mapping_replace_mapping,
15042                 (void *)&cmd_ptype_mapping_replace_replace,
15043                 (void *)&cmd_ptype_mapping_replace_port_id,
15044                 (void *)&cmd_ptype_mapping_replace_target,
15045                 (void *)&cmd_ptype_mapping_replace_mask,
15046                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15047                 NULL,
15048         },
15049 };
15050
15051 /* ptype mapping reset */
15052
15053 /* Common result structure for ptype mapping reset */
15054 struct cmd_ptype_mapping_reset_result {
15055         cmdline_fixed_string_t ptype;
15056         cmdline_fixed_string_t mapping;
15057         cmdline_fixed_string_t reset;
15058         portid_t port_id;
15059 };
15060
15061 /* Common CLI fields for ptype mapping reset*/
15062 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15063         TOKEN_STRING_INITIALIZER
15064                 (struct cmd_ptype_mapping_reset_result,
15065                  ptype, "ptype");
15066 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15067         TOKEN_STRING_INITIALIZER
15068                 (struct cmd_ptype_mapping_reset_result,
15069                  mapping, "mapping");
15070 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15071         TOKEN_STRING_INITIALIZER
15072                 (struct cmd_ptype_mapping_reset_result,
15073                  reset, "reset");
15074 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15075         TOKEN_NUM_INITIALIZER
15076                 (struct cmd_ptype_mapping_reset_result,
15077                  port_id, RTE_UINT16);
15078
15079 static void
15080 cmd_ptype_mapping_reset_parsed(
15081         void *parsed_result,
15082         __rte_unused struct cmdline *cl,
15083         __rte_unused void *data)
15084 {
15085         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15086         int ret = -ENOTSUP;
15087
15088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15089                 return;
15090
15091 #ifdef RTE_NET_I40E
15092         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15093 #endif
15094
15095         switch (ret) {
15096         case 0:
15097                 break;
15098         case -ENODEV:
15099                 printf("invalid port_id %d\n", res->port_id);
15100                 break;
15101         case -ENOTSUP:
15102                 printf("function not implemented\n");
15103                 break;
15104         default:
15105                 printf("programming error: (%s)\n", strerror(-ret));
15106         }
15107 }
15108
15109 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15110         .f = cmd_ptype_mapping_reset_parsed,
15111         .data = NULL,
15112         .help_str = "ptype mapping reset <port_id>",
15113         .tokens = {
15114                 (void *)&cmd_ptype_mapping_reset_ptype,
15115                 (void *)&cmd_ptype_mapping_reset_mapping,
15116                 (void *)&cmd_ptype_mapping_reset_reset,
15117                 (void *)&cmd_ptype_mapping_reset_port_id,
15118                 NULL,
15119         },
15120 };
15121
15122 /* ptype mapping update */
15123
15124 /* Common result structure for ptype mapping update */
15125 struct cmd_ptype_mapping_update_result {
15126         cmdline_fixed_string_t ptype;
15127         cmdline_fixed_string_t mapping;
15128         cmdline_fixed_string_t reset;
15129         portid_t port_id;
15130         uint8_t hw_ptype;
15131         uint32_t sw_ptype;
15132 };
15133
15134 /* Common CLI fields for ptype mapping update*/
15135 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_ptype_mapping_update_result,
15138                  ptype, "ptype");
15139 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_ptype_mapping_update_result,
15142                  mapping, "mapping");
15143 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_ptype_mapping_update_result,
15146                  reset, "update");
15147 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15148         TOKEN_NUM_INITIALIZER
15149                 (struct cmd_ptype_mapping_update_result,
15150                  port_id, RTE_UINT16);
15151 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15152         TOKEN_NUM_INITIALIZER
15153                 (struct cmd_ptype_mapping_update_result,
15154                  hw_ptype, RTE_UINT8);
15155 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15156         TOKEN_NUM_INITIALIZER
15157                 (struct cmd_ptype_mapping_update_result,
15158                  sw_ptype, RTE_UINT32);
15159
15160 static void
15161 cmd_ptype_mapping_update_parsed(
15162         void *parsed_result,
15163         __rte_unused struct cmdline *cl,
15164         __rte_unused void *data)
15165 {
15166         struct cmd_ptype_mapping_update_result *res = parsed_result;
15167         int ret = -ENOTSUP;
15168 #ifdef RTE_NET_I40E
15169         struct rte_pmd_i40e_ptype_mapping mapping;
15170 #endif
15171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15172                 return;
15173
15174 #ifdef RTE_NET_I40E
15175         mapping.hw_ptype = res->hw_ptype;
15176         mapping.sw_ptype = res->sw_ptype;
15177         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15178                                                 &mapping,
15179                                                 1,
15180                                                 0);
15181 #endif
15182
15183         switch (ret) {
15184         case 0:
15185                 break;
15186         case -EINVAL:
15187                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15188                 break;
15189         case -ENODEV:
15190                 printf("invalid port_id %d\n", res->port_id);
15191                 break;
15192         case -ENOTSUP:
15193                 printf("function not implemented\n");
15194                 break;
15195         default:
15196                 printf("programming error: (%s)\n", strerror(-ret));
15197         }
15198 }
15199
15200 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15201         .f = cmd_ptype_mapping_update_parsed,
15202         .data = NULL,
15203         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15204         .tokens = {
15205                 (void *)&cmd_ptype_mapping_update_ptype,
15206                 (void *)&cmd_ptype_mapping_update_mapping,
15207                 (void *)&cmd_ptype_mapping_update_update,
15208                 (void *)&cmd_ptype_mapping_update_port_id,
15209                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15210                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15211                 NULL,
15212         },
15213 };
15214
15215 /* Common result structure for file commands */
15216 struct cmd_cmdfile_result {
15217         cmdline_fixed_string_t load;
15218         cmdline_fixed_string_t filename;
15219 };
15220
15221 /* Common CLI fields for file commands */
15222 cmdline_parse_token_string_t cmd_load_cmdfile =
15223         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15224 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15225         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15226
15227 static void
15228 cmd_load_from_file_parsed(
15229         void *parsed_result,
15230         __rte_unused struct cmdline *cl,
15231         __rte_unused void *data)
15232 {
15233         struct cmd_cmdfile_result *res = parsed_result;
15234
15235         cmdline_read_from_file(res->filename);
15236 }
15237
15238 cmdline_parse_inst_t cmd_load_from_file = {
15239         .f = cmd_load_from_file_parsed,
15240         .data = NULL,
15241         .help_str = "load <filename>",
15242         .tokens = {
15243                 (void *)&cmd_load_cmdfile,
15244                 (void *)&cmd_load_cmdfile_filename,
15245                 NULL,
15246         },
15247 };
15248
15249 /* Get Rx offloads capabilities */
15250 struct cmd_rx_offload_get_capa_result {
15251         cmdline_fixed_string_t show;
15252         cmdline_fixed_string_t port;
15253         portid_t port_id;
15254         cmdline_fixed_string_t rx_offload;
15255         cmdline_fixed_string_t capabilities;
15256 };
15257
15258 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15259         TOKEN_STRING_INITIALIZER
15260                 (struct cmd_rx_offload_get_capa_result,
15261                  show, "show");
15262 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15263         TOKEN_STRING_INITIALIZER
15264                 (struct cmd_rx_offload_get_capa_result,
15265                  port, "port");
15266 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15267         TOKEN_NUM_INITIALIZER
15268                 (struct cmd_rx_offload_get_capa_result,
15269                  port_id, RTE_UINT16);
15270 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15271         TOKEN_STRING_INITIALIZER
15272                 (struct cmd_rx_offload_get_capa_result,
15273                  rx_offload, "rx_offload");
15274 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15275         TOKEN_STRING_INITIALIZER
15276                 (struct cmd_rx_offload_get_capa_result,
15277                  capabilities, "capabilities");
15278
15279 static void
15280 print_rx_offloads(uint64_t offloads)
15281 {
15282         uint64_t single_offload;
15283         int begin;
15284         int end;
15285         int bit;
15286
15287         if (offloads == 0)
15288                 return;
15289
15290         begin = __builtin_ctzll(offloads);
15291         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15292
15293         single_offload = 1ULL << begin;
15294         for (bit = begin; bit < end; bit++) {
15295                 if (offloads & single_offload)
15296                         printf(" %s",
15297                                rte_eth_dev_rx_offload_name(single_offload));
15298                 single_offload <<= 1;
15299         }
15300 }
15301
15302 static void
15303 cmd_rx_offload_get_capa_parsed(
15304         void *parsed_result,
15305         __rte_unused struct cmdline *cl,
15306         __rte_unused void *data)
15307 {
15308         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15309         struct rte_eth_dev_info dev_info;
15310         portid_t port_id = res->port_id;
15311         uint64_t queue_offloads;
15312         uint64_t port_offloads;
15313         int ret;
15314
15315         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15316         if (ret != 0)
15317                 return;
15318
15319         queue_offloads = dev_info.rx_queue_offload_capa;
15320         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15321
15322         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15323         printf("  Per Queue :");
15324         print_rx_offloads(queue_offloads);
15325
15326         printf("\n");
15327         printf("  Per Port  :");
15328         print_rx_offloads(port_offloads);
15329         printf("\n\n");
15330 }
15331
15332 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15333         .f = cmd_rx_offload_get_capa_parsed,
15334         .data = NULL,
15335         .help_str = "show port <port_id> rx_offload capabilities",
15336         .tokens = {
15337                 (void *)&cmd_rx_offload_get_capa_show,
15338                 (void *)&cmd_rx_offload_get_capa_port,
15339                 (void *)&cmd_rx_offload_get_capa_port_id,
15340                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15341                 (void *)&cmd_rx_offload_get_capa_capabilities,
15342                 NULL,
15343         }
15344 };
15345
15346 /* Get Rx offloads configuration */
15347 struct cmd_rx_offload_get_configuration_result {
15348         cmdline_fixed_string_t show;
15349         cmdline_fixed_string_t port;
15350         portid_t port_id;
15351         cmdline_fixed_string_t rx_offload;
15352         cmdline_fixed_string_t configuration;
15353 };
15354
15355 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15356         TOKEN_STRING_INITIALIZER
15357                 (struct cmd_rx_offload_get_configuration_result,
15358                  show, "show");
15359 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15360         TOKEN_STRING_INITIALIZER
15361                 (struct cmd_rx_offload_get_configuration_result,
15362                  port, "port");
15363 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15364         TOKEN_NUM_INITIALIZER
15365                 (struct cmd_rx_offload_get_configuration_result,
15366                  port_id, RTE_UINT16);
15367 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15368         TOKEN_STRING_INITIALIZER
15369                 (struct cmd_rx_offload_get_configuration_result,
15370                  rx_offload, "rx_offload");
15371 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15372         TOKEN_STRING_INITIALIZER
15373                 (struct cmd_rx_offload_get_configuration_result,
15374                  configuration, "configuration");
15375
15376 static void
15377 cmd_rx_offload_get_configuration_parsed(
15378         void *parsed_result,
15379         __rte_unused struct cmdline *cl,
15380         __rte_unused void *data)
15381 {
15382         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15383         struct rte_eth_dev_info dev_info;
15384         portid_t port_id = res->port_id;
15385         struct rte_port *port = &ports[port_id];
15386         uint64_t port_offloads;
15387         uint64_t queue_offloads;
15388         uint16_t nb_rx_queues;
15389         int q;
15390         int ret;
15391
15392         printf("Rx Offloading Configuration of port %d :\n", port_id);
15393
15394         port_offloads = port->dev_conf.rxmode.offloads;
15395         printf("  Port :");
15396         print_rx_offloads(port_offloads);
15397         printf("\n");
15398
15399         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15400         if (ret != 0)
15401                 return;
15402
15403         nb_rx_queues = dev_info.nb_rx_queues;
15404         for (q = 0; q < nb_rx_queues; q++) {
15405                 queue_offloads = port->rx_conf[q].offloads;
15406                 printf("  Queue[%2d] :", q);
15407                 print_rx_offloads(queue_offloads);
15408                 printf("\n");
15409         }
15410         printf("\n");
15411 }
15412
15413 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15414         .f = cmd_rx_offload_get_configuration_parsed,
15415         .data = NULL,
15416         .help_str = "show port <port_id> rx_offload configuration",
15417         .tokens = {
15418                 (void *)&cmd_rx_offload_get_configuration_show,
15419                 (void *)&cmd_rx_offload_get_configuration_port,
15420                 (void *)&cmd_rx_offload_get_configuration_port_id,
15421                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15422                 (void *)&cmd_rx_offload_get_configuration_configuration,
15423                 NULL,
15424         }
15425 };
15426
15427 /* Enable/Disable a per port offloading */
15428 struct cmd_config_per_port_rx_offload_result {
15429         cmdline_fixed_string_t port;
15430         cmdline_fixed_string_t config;
15431         portid_t port_id;
15432         cmdline_fixed_string_t rx_offload;
15433         cmdline_fixed_string_t offload;
15434         cmdline_fixed_string_t on_off;
15435 };
15436
15437 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15438         TOKEN_STRING_INITIALIZER
15439                 (struct cmd_config_per_port_rx_offload_result,
15440                  port, "port");
15441 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15442         TOKEN_STRING_INITIALIZER
15443                 (struct cmd_config_per_port_rx_offload_result,
15444                  config, "config");
15445 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15446         TOKEN_NUM_INITIALIZER
15447                 (struct cmd_config_per_port_rx_offload_result,
15448                  port_id, RTE_UINT16);
15449 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15450         TOKEN_STRING_INITIALIZER
15451                 (struct cmd_config_per_port_rx_offload_result,
15452                  rx_offload, "rx_offload");
15453 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15454         TOKEN_STRING_INITIALIZER
15455                 (struct cmd_config_per_port_rx_offload_result,
15456                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15457                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15458                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15459                            "scatter#buffer_split#timestamp#security#"
15460                            "keep_crc#rss_hash");
15461 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15462         TOKEN_STRING_INITIALIZER
15463                 (struct cmd_config_per_port_rx_offload_result,
15464                  on_off, "on#off");
15465
15466 static uint64_t
15467 search_rx_offload(const char *name)
15468 {
15469         uint64_t single_offload;
15470         const char *single_name;
15471         int found = 0;
15472         unsigned int bit;
15473
15474         single_offload = 1;
15475         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15476                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15477                 if (!strcasecmp(single_name, name)) {
15478                         found = 1;
15479                         break;
15480                 }
15481                 single_offload <<= 1;
15482         }
15483
15484         if (found)
15485                 return single_offload;
15486
15487         return 0;
15488 }
15489
15490 static void
15491 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15492                                 __rte_unused struct cmdline *cl,
15493                                 __rte_unused void *data)
15494 {
15495         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15496         portid_t port_id = res->port_id;
15497         struct rte_eth_dev_info dev_info;
15498         struct rte_port *port = &ports[port_id];
15499         uint64_t single_offload;
15500         uint16_t nb_rx_queues;
15501         int q;
15502         int ret;
15503
15504         if (port->port_status != RTE_PORT_STOPPED) {
15505                 printf("Error: Can't config offload when Port %d "
15506                        "is not stopped\n", port_id);
15507                 return;
15508         }
15509
15510         single_offload = search_rx_offload(res->offload);
15511         if (single_offload == 0) {
15512                 printf("Unknown offload name: %s\n", res->offload);
15513                 return;
15514         }
15515
15516         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15517         if (ret != 0)
15518                 return;
15519
15520         nb_rx_queues = dev_info.nb_rx_queues;
15521         if (!strcmp(res->on_off, "on")) {
15522                 port->dev_conf.rxmode.offloads |= single_offload;
15523                 for (q = 0; q < nb_rx_queues; q++)
15524                         port->rx_conf[q].offloads |= single_offload;
15525         } else {
15526                 port->dev_conf.rxmode.offloads &= ~single_offload;
15527                 for (q = 0; q < nb_rx_queues; q++)
15528                         port->rx_conf[q].offloads &= ~single_offload;
15529         }
15530
15531         cmd_reconfig_device_queue(port_id, 1, 1);
15532 }
15533
15534 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15535         .f = cmd_config_per_port_rx_offload_parsed,
15536         .data = NULL,
15537         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15538                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15539                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15540                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15541                     "keep_crc|rss_hash on|off",
15542         .tokens = {
15543                 (void *)&cmd_config_per_port_rx_offload_result_port,
15544                 (void *)&cmd_config_per_port_rx_offload_result_config,
15545                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15546                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15547                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15548                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15549                 NULL,
15550         }
15551 };
15552
15553 /* Enable/Disable a per queue offloading */
15554 struct cmd_config_per_queue_rx_offload_result {
15555         cmdline_fixed_string_t port;
15556         portid_t port_id;
15557         cmdline_fixed_string_t rxq;
15558         uint16_t queue_id;
15559         cmdline_fixed_string_t rx_offload;
15560         cmdline_fixed_string_t offload;
15561         cmdline_fixed_string_t on_off;
15562 };
15563
15564 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15565         TOKEN_STRING_INITIALIZER
15566                 (struct cmd_config_per_queue_rx_offload_result,
15567                  port, "port");
15568 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15569         TOKEN_NUM_INITIALIZER
15570                 (struct cmd_config_per_queue_rx_offload_result,
15571                  port_id, RTE_UINT16);
15572 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15573         TOKEN_STRING_INITIALIZER
15574                 (struct cmd_config_per_queue_rx_offload_result,
15575                  rxq, "rxq");
15576 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15577         TOKEN_NUM_INITIALIZER
15578                 (struct cmd_config_per_queue_rx_offload_result,
15579                  queue_id, RTE_UINT16);
15580 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15581         TOKEN_STRING_INITIALIZER
15582                 (struct cmd_config_per_queue_rx_offload_result,
15583                  rx_offload, "rx_offload");
15584 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15585         TOKEN_STRING_INITIALIZER
15586                 (struct cmd_config_per_queue_rx_offload_result,
15587                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15588                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15589                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15590                            "scatter#buffer_split#timestamp#security#keep_crc");
15591 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15592         TOKEN_STRING_INITIALIZER
15593                 (struct cmd_config_per_queue_rx_offload_result,
15594                  on_off, "on#off");
15595
15596 static void
15597 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15598                                 __rte_unused struct cmdline *cl,
15599                                 __rte_unused void *data)
15600 {
15601         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15602         struct rte_eth_dev_info dev_info;
15603         portid_t port_id = res->port_id;
15604         uint16_t queue_id = res->queue_id;
15605         struct rte_port *port = &ports[port_id];
15606         uint64_t single_offload;
15607         int ret;
15608
15609         if (port->port_status != RTE_PORT_STOPPED) {
15610                 printf("Error: Can't config offload when Port %d "
15611                        "is not stopped\n", port_id);
15612                 return;
15613         }
15614
15615         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15616         if (ret != 0)
15617                 return;
15618
15619         if (queue_id >= dev_info.nb_rx_queues) {
15620                 printf("Error: input queue_id should be 0 ... "
15621                        "%d\n", dev_info.nb_rx_queues - 1);
15622                 return;
15623         }
15624
15625         single_offload = search_rx_offload(res->offload);
15626         if (single_offload == 0) {
15627                 printf("Unknown offload name: %s\n", res->offload);
15628                 return;
15629         }
15630
15631         if (!strcmp(res->on_off, "on"))
15632                 port->rx_conf[queue_id].offloads |= single_offload;
15633         else
15634                 port->rx_conf[queue_id].offloads &= ~single_offload;
15635
15636         cmd_reconfig_device_queue(port_id, 1, 1);
15637 }
15638
15639 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15640         .f = cmd_config_per_queue_rx_offload_parsed,
15641         .data = NULL,
15642         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15643                     "vlan_strip|ipv4_cksum|"
15644                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15645                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15646                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15647                     "keep_crc on|off",
15648         .tokens = {
15649                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15650                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15651                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15652                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15653                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15654                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15655                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15656                 NULL,
15657         }
15658 };
15659
15660 /* Get Tx offloads capabilities */
15661 struct cmd_tx_offload_get_capa_result {
15662         cmdline_fixed_string_t show;
15663         cmdline_fixed_string_t port;
15664         portid_t port_id;
15665         cmdline_fixed_string_t tx_offload;
15666         cmdline_fixed_string_t capabilities;
15667 };
15668
15669 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_tx_offload_get_capa_result,
15672                  show, "show");
15673 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15674         TOKEN_STRING_INITIALIZER
15675                 (struct cmd_tx_offload_get_capa_result,
15676                  port, "port");
15677 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15678         TOKEN_NUM_INITIALIZER
15679                 (struct cmd_tx_offload_get_capa_result,
15680                  port_id, RTE_UINT16);
15681 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15682         TOKEN_STRING_INITIALIZER
15683                 (struct cmd_tx_offload_get_capa_result,
15684                  tx_offload, "tx_offload");
15685 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15686         TOKEN_STRING_INITIALIZER
15687                 (struct cmd_tx_offload_get_capa_result,
15688                  capabilities, "capabilities");
15689
15690 static void
15691 print_tx_offloads(uint64_t offloads)
15692 {
15693         uint64_t single_offload;
15694         int begin;
15695         int end;
15696         int bit;
15697
15698         if (offloads == 0)
15699                 return;
15700
15701         begin = __builtin_ctzll(offloads);
15702         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15703
15704         single_offload = 1ULL << begin;
15705         for (bit = begin; bit < end; bit++) {
15706                 if (offloads & single_offload)
15707                         printf(" %s",
15708                                rte_eth_dev_tx_offload_name(single_offload));
15709                 single_offload <<= 1;
15710         }
15711 }
15712
15713 static void
15714 cmd_tx_offload_get_capa_parsed(
15715         void *parsed_result,
15716         __rte_unused struct cmdline *cl,
15717         __rte_unused void *data)
15718 {
15719         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15720         struct rte_eth_dev_info dev_info;
15721         portid_t port_id = res->port_id;
15722         uint64_t queue_offloads;
15723         uint64_t port_offloads;
15724         int ret;
15725
15726         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15727         if (ret != 0)
15728                 return;
15729
15730         queue_offloads = dev_info.tx_queue_offload_capa;
15731         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15732
15733         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15734         printf("  Per Queue :");
15735         print_tx_offloads(queue_offloads);
15736
15737         printf("\n");
15738         printf("  Per Port  :");
15739         print_tx_offloads(port_offloads);
15740         printf("\n\n");
15741 }
15742
15743 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15744         .f = cmd_tx_offload_get_capa_parsed,
15745         .data = NULL,
15746         .help_str = "show port <port_id> tx_offload capabilities",
15747         .tokens = {
15748                 (void *)&cmd_tx_offload_get_capa_show,
15749                 (void *)&cmd_tx_offload_get_capa_port,
15750                 (void *)&cmd_tx_offload_get_capa_port_id,
15751                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15752                 (void *)&cmd_tx_offload_get_capa_capabilities,
15753                 NULL,
15754         }
15755 };
15756
15757 /* Get Tx offloads configuration */
15758 struct cmd_tx_offload_get_configuration_result {
15759         cmdline_fixed_string_t show;
15760         cmdline_fixed_string_t port;
15761         portid_t port_id;
15762         cmdline_fixed_string_t tx_offload;
15763         cmdline_fixed_string_t configuration;
15764 };
15765
15766 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15767         TOKEN_STRING_INITIALIZER
15768                 (struct cmd_tx_offload_get_configuration_result,
15769                  show, "show");
15770 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15771         TOKEN_STRING_INITIALIZER
15772                 (struct cmd_tx_offload_get_configuration_result,
15773                  port, "port");
15774 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15775         TOKEN_NUM_INITIALIZER
15776                 (struct cmd_tx_offload_get_configuration_result,
15777                  port_id, RTE_UINT16);
15778 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15779         TOKEN_STRING_INITIALIZER
15780                 (struct cmd_tx_offload_get_configuration_result,
15781                  tx_offload, "tx_offload");
15782 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15783         TOKEN_STRING_INITIALIZER
15784                 (struct cmd_tx_offload_get_configuration_result,
15785                  configuration, "configuration");
15786
15787 static void
15788 cmd_tx_offload_get_configuration_parsed(
15789         void *parsed_result,
15790         __rte_unused struct cmdline *cl,
15791         __rte_unused void *data)
15792 {
15793         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15794         struct rte_eth_dev_info dev_info;
15795         portid_t port_id = res->port_id;
15796         struct rte_port *port = &ports[port_id];
15797         uint64_t port_offloads;
15798         uint64_t queue_offloads;
15799         uint16_t nb_tx_queues;
15800         int q;
15801         int ret;
15802
15803         printf("Tx Offloading Configuration of port %d :\n", port_id);
15804
15805         port_offloads = port->dev_conf.txmode.offloads;
15806         printf("  Port :");
15807         print_tx_offloads(port_offloads);
15808         printf("\n");
15809
15810         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15811         if (ret != 0)
15812                 return;
15813
15814         nb_tx_queues = dev_info.nb_tx_queues;
15815         for (q = 0; q < nb_tx_queues; q++) {
15816                 queue_offloads = port->tx_conf[q].offloads;
15817                 printf("  Queue[%2d] :", q);
15818                 print_tx_offloads(queue_offloads);
15819                 printf("\n");
15820         }
15821         printf("\n");
15822 }
15823
15824 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15825         .f = cmd_tx_offload_get_configuration_parsed,
15826         .data = NULL,
15827         .help_str = "show port <port_id> tx_offload configuration",
15828         .tokens = {
15829                 (void *)&cmd_tx_offload_get_configuration_show,
15830                 (void *)&cmd_tx_offload_get_configuration_port,
15831                 (void *)&cmd_tx_offload_get_configuration_port_id,
15832                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15833                 (void *)&cmd_tx_offload_get_configuration_configuration,
15834                 NULL,
15835         }
15836 };
15837
15838 /* Enable/Disable a per port offloading */
15839 struct cmd_config_per_port_tx_offload_result {
15840         cmdline_fixed_string_t port;
15841         cmdline_fixed_string_t config;
15842         portid_t port_id;
15843         cmdline_fixed_string_t tx_offload;
15844         cmdline_fixed_string_t offload;
15845         cmdline_fixed_string_t on_off;
15846 };
15847
15848 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15849         TOKEN_STRING_INITIALIZER
15850                 (struct cmd_config_per_port_tx_offload_result,
15851                  port, "port");
15852 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15853         TOKEN_STRING_INITIALIZER
15854                 (struct cmd_config_per_port_tx_offload_result,
15855                  config, "config");
15856 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15857         TOKEN_NUM_INITIALIZER
15858                 (struct cmd_config_per_port_tx_offload_result,
15859                  port_id, RTE_UINT16);
15860 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15861         TOKEN_STRING_INITIALIZER
15862                 (struct cmd_config_per_port_tx_offload_result,
15863                  tx_offload, "tx_offload");
15864 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15865         TOKEN_STRING_INITIALIZER
15866                 (struct cmd_config_per_port_tx_offload_result,
15867                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15868                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15869                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15870                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15871                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15872                           "send_on_timestamp");
15873 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15874         TOKEN_STRING_INITIALIZER
15875                 (struct cmd_config_per_port_tx_offload_result,
15876                  on_off, "on#off");
15877
15878 static uint64_t
15879 search_tx_offload(const char *name)
15880 {
15881         uint64_t single_offload;
15882         const char *single_name;
15883         int found = 0;
15884         unsigned int bit;
15885
15886         single_offload = 1;
15887         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15888                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15889                 if (single_name == NULL)
15890                         break;
15891                 if (!strcasecmp(single_name, name)) {
15892                         found = 1;
15893                         break;
15894                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15895                         break;
15896                 single_offload <<= 1;
15897         }
15898
15899         if (found)
15900                 return single_offload;
15901
15902         return 0;
15903 }
15904
15905 static void
15906 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15907                                 __rte_unused struct cmdline *cl,
15908                                 __rte_unused void *data)
15909 {
15910         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15911         portid_t port_id = res->port_id;
15912         struct rte_eth_dev_info dev_info;
15913         struct rte_port *port = &ports[port_id];
15914         uint64_t single_offload;
15915         uint16_t nb_tx_queues;
15916         int q;
15917         int ret;
15918
15919         if (port->port_status != RTE_PORT_STOPPED) {
15920                 printf("Error: Can't config offload when Port %d "
15921                        "is not stopped\n", port_id);
15922                 return;
15923         }
15924
15925         single_offload = search_tx_offload(res->offload);
15926         if (single_offload == 0) {
15927                 printf("Unknown offload name: %s\n", res->offload);
15928                 return;
15929         }
15930
15931         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15932         if (ret != 0)
15933                 return;
15934
15935         nb_tx_queues = dev_info.nb_tx_queues;
15936         if (!strcmp(res->on_off, "on")) {
15937                 port->dev_conf.txmode.offloads |= single_offload;
15938                 for (q = 0; q < nb_tx_queues; q++)
15939                         port->tx_conf[q].offloads |= single_offload;
15940         } else {
15941                 port->dev_conf.txmode.offloads &= ~single_offload;
15942                 for (q = 0; q < nb_tx_queues; q++)
15943                         port->tx_conf[q].offloads &= ~single_offload;
15944         }
15945
15946         cmd_reconfig_device_queue(port_id, 1, 1);
15947 }
15948
15949 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15950         .f = cmd_config_per_port_tx_offload_parsed,
15951         .data = NULL,
15952         .help_str = "port config <port_id> tx_offload "
15953                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15954                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15955                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15956                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15957                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15958                     "send_on_timestamp on|off",
15959         .tokens = {
15960                 (void *)&cmd_config_per_port_tx_offload_result_port,
15961                 (void *)&cmd_config_per_port_tx_offload_result_config,
15962                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15963                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15964                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15965                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15966                 NULL,
15967         }
15968 };
15969
15970 /* Enable/Disable a per queue offloading */
15971 struct cmd_config_per_queue_tx_offload_result {
15972         cmdline_fixed_string_t port;
15973         portid_t port_id;
15974         cmdline_fixed_string_t txq;
15975         uint16_t queue_id;
15976         cmdline_fixed_string_t tx_offload;
15977         cmdline_fixed_string_t offload;
15978         cmdline_fixed_string_t on_off;
15979 };
15980
15981 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15982         TOKEN_STRING_INITIALIZER
15983                 (struct cmd_config_per_queue_tx_offload_result,
15984                  port, "port");
15985 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15986         TOKEN_NUM_INITIALIZER
15987                 (struct cmd_config_per_queue_tx_offload_result,
15988                  port_id, RTE_UINT16);
15989 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15990         TOKEN_STRING_INITIALIZER
15991                 (struct cmd_config_per_queue_tx_offload_result,
15992                  txq, "txq");
15993 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15994         TOKEN_NUM_INITIALIZER
15995                 (struct cmd_config_per_queue_tx_offload_result,
15996                  queue_id, RTE_UINT16);
15997 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15998         TOKEN_STRING_INITIALIZER
15999                 (struct cmd_config_per_queue_tx_offload_result,
16000                  tx_offload, "tx_offload");
16001 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16002         TOKEN_STRING_INITIALIZER
16003                 (struct cmd_config_per_queue_tx_offload_result,
16004                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16005                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16006                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16007                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16008                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16009 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16010         TOKEN_STRING_INITIALIZER
16011                 (struct cmd_config_per_queue_tx_offload_result,
16012                  on_off, "on#off");
16013
16014 static void
16015 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16016                                 __rte_unused struct cmdline *cl,
16017                                 __rte_unused void *data)
16018 {
16019         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16020         struct rte_eth_dev_info dev_info;
16021         portid_t port_id = res->port_id;
16022         uint16_t queue_id = res->queue_id;
16023         struct rte_port *port = &ports[port_id];
16024         uint64_t single_offload;
16025         int ret;
16026
16027         if (port->port_status != RTE_PORT_STOPPED) {
16028                 printf("Error: Can't config offload when Port %d "
16029                        "is not stopped\n", port_id);
16030                 return;
16031         }
16032
16033         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16034         if (ret != 0)
16035                 return;
16036
16037         if (queue_id >= dev_info.nb_tx_queues) {
16038                 printf("Error: input queue_id should be 0 ... "
16039                        "%d\n", dev_info.nb_tx_queues - 1);
16040                 return;
16041         }
16042
16043         single_offload = search_tx_offload(res->offload);
16044         if (single_offload == 0) {
16045                 printf("Unknown offload name: %s\n", res->offload);
16046                 return;
16047         }
16048
16049         if (!strcmp(res->on_off, "on"))
16050                 port->tx_conf[queue_id].offloads |= single_offload;
16051         else
16052                 port->tx_conf[queue_id].offloads &= ~single_offload;
16053
16054         cmd_reconfig_device_queue(port_id, 1, 1);
16055 }
16056
16057 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16058         .f = cmd_config_per_queue_tx_offload_parsed,
16059         .data = NULL,
16060         .help_str = "port <port_id> txq <queue_id> tx_offload "
16061                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16062                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16063                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16064                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16065                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16066                     "on|off",
16067         .tokens = {
16068                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16069                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16070                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16071                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16072                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16073                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16074                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16075                 NULL,
16076         }
16077 };
16078
16079 /* *** configure tx_metadata for specific port *** */
16080 struct cmd_config_tx_metadata_specific_result {
16081         cmdline_fixed_string_t port;
16082         cmdline_fixed_string_t keyword;
16083         uint16_t port_id;
16084         cmdline_fixed_string_t item;
16085         uint32_t value;
16086 };
16087
16088 static void
16089 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16090                                 __rte_unused struct cmdline *cl,
16091                                 __rte_unused void *data)
16092 {
16093         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16094
16095         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16096                 return;
16097         ports[res->port_id].tx_metadata = res->value;
16098         /* Add/remove callback to insert valid metadata in every Tx packet. */
16099         if (ports[res->port_id].tx_metadata)
16100                 add_tx_md_callback(res->port_id);
16101         else
16102                 remove_tx_md_callback(res->port_id);
16103         rte_flow_dynf_metadata_register();
16104 }
16105
16106 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16107         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16108                         port, "port");
16109 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16110         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16111                         keyword, "config");
16112 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16113         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16114                         port_id, RTE_UINT16);
16115 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16116         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16117                         item, "tx_metadata");
16118 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16119         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16120                         value, RTE_UINT32);
16121
16122 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16123         .f = cmd_config_tx_metadata_specific_parsed,
16124         .data = NULL,
16125         .help_str = "port config <port_id> tx_metadata <value>",
16126         .tokens = {
16127                 (void *)&cmd_config_tx_metadata_specific_port,
16128                 (void *)&cmd_config_tx_metadata_specific_keyword,
16129                 (void *)&cmd_config_tx_metadata_specific_id,
16130                 (void *)&cmd_config_tx_metadata_specific_item,
16131                 (void *)&cmd_config_tx_metadata_specific_value,
16132                 NULL,
16133         },
16134 };
16135
16136 /* *** set dynf *** */
16137 struct cmd_config_tx_dynf_specific_result {
16138         cmdline_fixed_string_t port;
16139         cmdline_fixed_string_t keyword;
16140         uint16_t port_id;
16141         cmdline_fixed_string_t item;
16142         cmdline_fixed_string_t name;
16143         cmdline_fixed_string_t value;
16144 };
16145
16146 static void
16147 cmd_config_dynf_specific_parsed(void *parsed_result,
16148                                 __rte_unused struct cmdline *cl,
16149                                 __rte_unused void *data)
16150 {
16151         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16152         struct rte_mbuf_dynflag desc_flag;
16153         int flag;
16154         uint64_t old_port_flags;
16155
16156         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16157                 return;
16158         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16159         if (flag <= 0) {
16160                 if (strlcpy(desc_flag.name, res->name,
16161                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16162                         printf("Flag name too long\n");
16163                         return;
16164                 }
16165                 desc_flag.flags = 0;
16166                 flag = rte_mbuf_dynflag_register(&desc_flag);
16167                 if (flag < 0) {
16168                         printf("Can't register flag\n");
16169                         return;
16170                 }
16171                 strcpy(dynf_names[flag], desc_flag.name);
16172         }
16173         old_port_flags = ports[res->port_id].mbuf_dynf;
16174         if (!strcmp(res->value, "set")) {
16175                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16176                 if (old_port_flags == 0)
16177                         add_tx_dynf_callback(res->port_id);
16178         } else {
16179                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16180                 if (ports[res->port_id].mbuf_dynf == 0)
16181                         remove_tx_dynf_callback(res->port_id);
16182         }
16183 }
16184
16185 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16186         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16187                         keyword, "port");
16188 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16189         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16190                         keyword, "config");
16191 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16192         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16193                         port_id, RTE_UINT16);
16194 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16195         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16196                         item, "dynf");
16197 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16198         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16199                         name, NULL);
16200 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16201         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16202                         value, "set#clear");
16203
16204 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16205         .f = cmd_config_dynf_specific_parsed,
16206         .data = NULL,
16207         .help_str = "port config <port id> dynf <name> set|clear",
16208         .tokens = {
16209                 (void *)&cmd_config_tx_dynf_specific_port,
16210                 (void *)&cmd_config_tx_dynf_specific_keyword,
16211                 (void *)&cmd_config_tx_dynf_specific_port_id,
16212                 (void *)&cmd_config_tx_dynf_specific_item,
16213                 (void *)&cmd_config_tx_dynf_specific_name,
16214                 (void *)&cmd_config_tx_dynf_specific_value,
16215                 NULL,
16216         },
16217 };
16218
16219 /* *** display tx_metadata per port configuration *** */
16220 struct cmd_show_tx_metadata_result {
16221         cmdline_fixed_string_t cmd_show;
16222         cmdline_fixed_string_t cmd_port;
16223         cmdline_fixed_string_t cmd_keyword;
16224         portid_t cmd_pid;
16225 };
16226
16227 static void
16228 cmd_show_tx_metadata_parsed(void *parsed_result,
16229                 __rte_unused struct cmdline *cl,
16230                 __rte_unused void *data)
16231 {
16232         struct cmd_show_tx_metadata_result *res = parsed_result;
16233
16234         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16235                 printf("invalid port id %u\n", res->cmd_pid);
16236                 return;
16237         }
16238         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16239                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16240                        ports[res->cmd_pid].tx_metadata);
16241         }
16242 }
16243
16244 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16245         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16246                         cmd_show, "show");
16247 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16248         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16249                         cmd_port, "port");
16250 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16251         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16252                         cmd_pid, RTE_UINT16);
16253 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16254         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16255                         cmd_keyword, "tx_metadata");
16256
16257 cmdline_parse_inst_t cmd_show_tx_metadata = {
16258         .f = cmd_show_tx_metadata_parsed,
16259         .data = NULL,
16260         .help_str = "show port <port_id> tx_metadata",
16261         .tokens = {
16262                 (void *)&cmd_show_tx_metadata_show,
16263                 (void *)&cmd_show_tx_metadata_port,
16264                 (void *)&cmd_show_tx_metadata_pid,
16265                 (void *)&cmd_show_tx_metadata_keyword,
16266                 NULL,
16267         },
16268 };
16269
16270 /* *** show fec capability per port configuration *** */
16271 struct cmd_show_fec_capability_result {
16272         cmdline_fixed_string_t cmd_show;
16273         cmdline_fixed_string_t cmd_port;
16274         cmdline_fixed_string_t cmd_fec;
16275         cmdline_fixed_string_t cmd_keyword;
16276         portid_t cmd_pid;
16277 };
16278
16279 static void
16280 cmd_show_fec_capability_parsed(void *parsed_result,
16281                 __rte_unused struct cmdline *cl,
16282                 __rte_unused void *data)
16283 {
16284         struct cmd_show_fec_capability_result *res = parsed_result;
16285         struct rte_eth_fec_capa *speed_fec_capa;
16286         unsigned int num;
16287         int ret;
16288
16289         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16290                 printf("Invalid port id %u\n", res->cmd_pid);
16291                 return;
16292         }
16293
16294         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16295         if (ret == -ENOTSUP) {
16296                 printf("Function not implemented\n");
16297                 return;
16298         } else if (ret < 0) {
16299                 printf("Get FEC capability failed: %d\n", ret);
16300                 return;
16301         }
16302
16303         num = (unsigned int)ret;
16304         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16305         if (speed_fec_capa == NULL) {
16306                 printf("Failed to alloc FEC capability buffer\n");
16307                 return;
16308         }
16309
16310         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16311         if (ret < 0) {
16312                 printf("Error getting FEC capability: %d\n", ret);
16313                 goto out;
16314         }
16315
16316         show_fec_capability(num, speed_fec_capa);
16317 out:
16318         free(speed_fec_capa);
16319 }
16320
16321 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16322         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16323                         cmd_show, "show");
16324 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16325         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16326                         cmd_port, "port");
16327 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16328         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16329                         cmd_pid, RTE_UINT16);
16330 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16331         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16332                         cmd_fec, "fec");
16333 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16334         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16335                         cmd_keyword, "capabilities");
16336
16337 cmdline_parse_inst_t cmd_show_capability = {
16338         .f = cmd_show_fec_capability_parsed,
16339         .data = NULL,
16340         .help_str = "show port <port_id> fec capabilities",
16341         .tokens = {
16342                 (void *)&cmd_show_fec_capability_show,
16343                 (void *)&cmd_show_fec_capability_port,
16344                 (void *)&cmd_show_fec_capability_pid,
16345                 (void *)&cmd_show_fec_capability_fec,
16346                 (void *)&cmd_show_fec_capability_keyword,
16347                 NULL,
16348         },
16349 };
16350
16351 /* *** show fec mode per port configuration *** */
16352 struct cmd_show_fec_metadata_result {
16353         cmdline_fixed_string_t cmd_show;
16354         cmdline_fixed_string_t cmd_port;
16355         cmdline_fixed_string_t cmd_keyword;
16356         portid_t cmd_pid;
16357 };
16358
16359 static void
16360 cmd_show_fec_mode_parsed(void *parsed_result,
16361                 __rte_unused struct cmdline *cl,
16362                 __rte_unused void *data)
16363 {
16364 #define FEC_NAME_SIZE 16
16365         struct cmd_show_fec_metadata_result *res = parsed_result;
16366         uint32_t mode;
16367         char buf[FEC_NAME_SIZE];
16368         int ret;
16369
16370         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16371                 printf("Invalid port id %u\n", res->cmd_pid);
16372                 return;
16373         }
16374         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16375         if (ret == -ENOTSUP) {
16376                 printf("Function not implemented\n");
16377                 return;
16378         } else if (ret < 0) {
16379                 printf("Get FEC mode failed\n");
16380                 return;
16381         }
16382
16383         switch (mode) {
16384         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16385                 strlcpy(buf, "off", sizeof(buf));
16386                 break;
16387         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16388                 strlcpy(buf, "auto", sizeof(buf));
16389                 break;
16390         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16391                 strlcpy(buf, "baser", sizeof(buf));
16392                 break;
16393         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16394                 strlcpy(buf, "rs", sizeof(buf));
16395                 break;
16396         default:
16397                 return;
16398         }
16399
16400         printf("%s\n", buf);
16401 }
16402
16403 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16404         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16405                         cmd_show, "show");
16406 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16407         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16408                         cmd_port, "port");
16409 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16410         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16411                         cmd_pid, RTE_UINT16);
16412 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16413         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16414                         cmd_keyword, "fec_mode");
16415
16416 cmdline_parse_inst_t cmd_show_fec_mode = {
16417         .f = cmd_show_fec_mode_parsed,
16418         .data = NULL,
16419         .help_str = "show port <port_id> fec_mode",
16420         .tokens = {
16421                 (void *)&cmd_show_fec_mode_show,
16422                 (void *)&cmd_show_fec_mode_port,
16423                 (void *)&cmd_show_fec_mode_pid,
16424                 (void *)&cmd_show_fec_mode_keyword,
16425                 NULL,
16426         },
16427 };
16428
16429 /* *** set fec mode per port configuration *** */
16430 struct cmd_set_port_fec_mode {
16431         cmdline_fixed_string_t set;
16432         cmdline_fixed_string_t port;
16433         portid_t port_id;
16434         cmdline_fixed_string_t fec_mode;
16435         cmdline_fixed_string_t fec_value;
16436 };
16437
16438 /* Common CLI fields for set fec mode */
16439 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16440         TOKEN_STRING_INITIALIZER
16441                 (struct cmd_set_port_fec_mode,
16442                  set, "set");
16443 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16444         TOKEN_STRING_INITIALIZER
16445                 (struct cmd_set_port_fec_mode,
16446                  port, "port");
16447 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16448         TOKEN_NUM_INITIALIZER
16449                 (struct cmd_set_port_fec_mode,
16450                  port_id, RTE_UINT16);
16451 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16452         TOKEN_STRING_INITIALIZER
16453                 (struct cmd_set_port_fec_mode,
16454                  fec_mode, "fec_mode");
16455 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16456         TOKEN_STRING_INITIALIZER
16457                 (struct cmd_set_port_fec_mode,
16458                  fec_value, NULL);
16459
16460 static void
16461 cmd_set_port_fec_mode_parsed(
16462         void *parsed_result,
16463         __rte_unused struct cmdline *cl,
16464         __rte_unused void *data)
16465 {
16466         struct cmd_set_port_fec_mode *res = parsed_result;
16467         uint16_t port_id = res->port_id;
16468         uint32_t mode;
16469         int ret;
16470
16471         ret = parse_fec_mode(res->fec_value, &mode);
16472         if (ret < 0) {
16473                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16474                         port_id);
16475                 return;
16476         }
16477
16478         ret = rte_eth_fec_set(port_id, mode);
16479         if (ret == -ENOTSUP) {
16480                 printf("Function not implemented\n");
16481                 return;
16482         } else if (ret < 0) {
16483                 printf("Set FEC mode failed\n");
16484                 return;
16485         }
16486 }
16487
16488 cmdline_parse_inst_t cmd_set_fec_mode = {
16489         .f = cmd_set_port_fec_mode_parsed,
16490         .data = NULL,
16491         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16492         .tokens = {
16493                 (void *)&cmd_set_port_fec_mode_set,
16494                 (void *)&cmd_set_port_fec_mode_port,
16495                 (void *)&cmd_set_port_fec_mode_port_id,
16496                 (void *)&cmd_set_port_fec_mode_str,
16497                 (void *)&cmd_set_port_fec_mode_value,
16498                 NULL,
16499         },
16500 };
16501
16502 /* show port supported ptypes */
16503
16504 /* Common result structure for show port ptypes */
16505 struct cmd_show_port_supported_ptypes_result {
16506         cmdline_fixed_string_t show;
16507         cmdline_fixed_string_t port;
16508         portid_t port_id;
16509         cmdline_fixed_string_t ptypes;
16510 };
16511
16512 /* Common CLI fields for show port ptypes */
16513 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16514         TOKEN_STRING_INITIALIZER
16515                 (struct cmd_show_port_supported_ptypes_result,
16516                  show, "show");
16517 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16518         TOKEN_STRING_INITIALIZER
16519                 (struct cmd_show_port_supported_ptypes_result,
16520                  port, "port");
16521 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16522         TOKEN_NUM_INITIALIZER
16523                 (struct cmd_show_port_supported_ptypes_result,
16524                  port_id, RTE_UINT16);
16525 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16526         TOKEN_STRING_INITIALIZER
16527                 (struct cmd_show_port_supported_ptypes_result,
16528                  ptypes, "ptypes");
16529
16530 static void
16531 cmd_show_port_supported_ptypes_parsed(
16532         void *parsed_result,
16533         __rte_unused struct cmdline *cl,
16534         __rte_unused void *data)
16535 {
16536 #define RSVD_PTYPE_MASK       0xf0000000
16537 #define MAX_PTYPES_PER_LAYER  16
16538 #define LTYPE_NAMESIZE        32
16539 #define PTYPE_NAMESIZE        256
16540         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16541         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16542         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16543         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16544         uint16_t port_id = res->port_id;
16545         int ret, i;
16546
16547         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16548         if (ret < 0)
16549                 return;
16550
16551         while (ptype_mask != RSVD_PTYPE_MASK) {
16552
16553                 switch (ptype_mask) {
16554                 case RTE_PTYPE_L2_MASK:
16555                         strlcpy(ltype, "L2", sizeof(ltype));
16556                         break;
16557                 case RTE_PTYPE_L3_MASK:
16558                         strlcpy(ltype, "L3", sizeof(ltype));
16559                         break;
16560                 case RTE_PTYPE_L4_MASK:
16561                         strlcpy(ltype, "L4", sizeof(ltype));
16562                         break;
16563                 case RTE_PTYPE_TUNNEL_MASK:
16564                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16565                         break;
16566                 case RTE_PTYPE_INNER_L2_MASK:
16567                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16568                         break;
16569                 case RTE_PTYPE_INNER_L3_MASK:
16570                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16571                         break;
16572                 case RTE_PTYPE_INNER_L4_MASK:
16573                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16574                         break;
16575                 default:
16576                         return;
16577                 }
16578
16579                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16580                                                        ptype_mask, ptypes,
16581                                                        MAX_PTYPES_PER_LAYER);
16582
16583                 if (ret > 0)
16584                         printf("Supported %s ptypes:\n", ltype);
16585                 else
16586                         printf("%s ptypes unsupported\n", ltype);
16587
16588                 for (i = 0; i < ret; ++i) {
16589                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16590                         printf("%s\n", buf);
16591                 }
16592
16593                 ptype_mask <<= 4;
16594         }
16595 }
16596
16597 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16598         .f = cmd_show_port_supported_ptypes_parsed,
16599         .data = NULL,
16600         .help_str = "show port <port_id> ptypes",
16601         .tokens = {
16602                 (void *)&cmd_show_port_supported_ptypes_show,
16603                 (void *)&cmd_show_port_supported_ptypes_port,
16604                 (void *)&cmd_show_port_supported_ptypes_port_id,
16605                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16606                 NULL,
16607         },
16608 };
16609
16610 /* *** display rx/tx descriptor status *** */
16611 struct cmd_show_rx_tx_desc_status_result {
16612         cmdline_fixed_string_t cmd_show;
16613         cmdline_fixed_string_t cmd_port;
16614         cmdline_fixed_string_t cmd_keyword;
16615         cmdline_fixed_string_t cmd_desc;
16616         cmdline_fixed_string_t cmd_status;
16617         portid_t cmd_pid;
16618         portid_t cmd_qid;
16619         portid_t cmd_did;
16620 };
16621
16622 static void
16623 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16624                 __rte_unused struct cmdline *cl,
16625                 __rte_unused void *data)
16626 {
16627         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16628         int rc;
16629
16630         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16631                 printf("invalid port id %u\n", res->cmd_pid);
16632                 return;
16633         }
16634
16635         if (!strcmp(res->cmd_keyword, "rxq")) {
16636                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16637                                              res->cmd_did);
16638                 if (rc < 0) {
16639                         printf("Invalid queueid = %d\n", res->cmd_qid);
16640                         return;
16641                 }
16642                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16643                         printf("Desc status = AVAILABLE\n");
16644                 else if (rc == RTE_ETH_RX_DESC_DONE)
16645                         printf("Desc status = DONE\n");
16646                 else
16647                         printf("Desc status = UNAVAILABLE\n");
16648         } else if (!strcmp(res->cmd_keyword, "txq")) {
16649                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16650                                              res->cmd_did);
16651                 if (rc < 0) {
16652                         printf("Invalid queueid = %d\n", res->cmd_qid);
16653                         return;
16654                 }
16655                 if (rc == RTE_ETH_TX_DESC_FULL)
16656                         printf("Desc status = FULL\n");
16657                 else if (rc == RTE_ETH_TX_DESC_DONE)
16658                         printf("Desc status = DONE\n");
16659                 else
16660                         printf("Desc status = UNAVAILABLE\n");
16661         }
16662 }
16663
16664 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16665         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16666                         cmd_show, "show");
16667 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16668         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16669                         cmd_port, "port");
16670 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16671         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16672                         cmd_pid, RTE_UINT16);
16673 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16674         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16675                         cmd_keyword, "rxq#txq");
16676 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16677         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16678                         cmd_qid, RTE_UINT16);
16679 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16680         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16681                         cmd_desc, "desc");
16682 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16683         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16684                         cmd_did, RTE_UINT16);
16685 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16686         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16687                         cmd_status, "status");
16688 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16689         .f = cmd_show_rx_tx_desc_status_parsed,
16690         .data = NULL,
16691         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16692                 "status",
16693         .tokens = {
16694                 (void *)&cmd_show_rx_tx_desc_status_show,
16695                 (void *)&cmd_show_rx_tx_desc_status_port,
16696                 (void *)&cmd_show_rx_tx_desc_status_pid,
16697                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16698                 (void *)&cmd_show_rx_tx_desc_status_qid,
16699                 (void *)&cmd_show_rx_tx_desc_status_desc,
16700                 (void *)&cmd_show_rx_tx_desc_status_did,
16701                 (void *)&cmd_show_rx_tx_desc_status_status,
16702                 NULL,
16703         },
16704 };
16705
16706 /* *** display rx queue desc used count *** */
16707 struct cmd_show_rx_queue_desc_used_count_result {
16708         cmdline_fixed_string_t cmd_show;
16709         cmdline_fixed_string_t cmd_port;
16710         cmdline_fixed_string_t cmd_rxq;
16711         cmdline_fixed_string_t cmd_desc;
16712         cmdline_fixed_string_t cmd_used;
16713         cmdline_fixed_string_t cmd_count;
16714         portid_t cmd_pid;
16715         portid_t cmd_qid;
16716 };
16717
16718 static void
16719 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
16720                 __rte_unused struct cmdline *cl,
16721                 __rte_unused void *data)
16722 {
16723         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
16724         int rc;
16725
16726         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16727                 printf("invalid port id %u\n", res->cmd_pid);
16728                 return;
16729         }
16730
16731         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
16732         if (rc < 0) {
16733                 printf("Invalid queueid = %d\n", res->cmd_qid);
16734                 return;
16735         }
16736         printf("Used desc count = %d\n", rc);
16737 }
16738
16739 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
16740         TOKEN_STRING_INITIALIZER
16741                 (struct cmd_show_rx_queue_desc_used_count_result,
16742                  cmd_show, "show");
16743 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
16744         TOKEN_STRING_INITIALIZER
16745                 (struct cmd_show_rx_queue_desc_used_count_result,
16746                  cmd_port, "port");
16747 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
16748         TOKEN_NUM_INITIALIZER
16749                 (struct cmd_show_rx_queue_desc_used_count_result,
16750                  cmd_pid, RTE_UINT16);
16751 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
16752         TOKEN_STRING_INITIALIZER
16753                 (struct cmd_show_rx_queue_desc_used_count_result,
16754                  cmd_rxq, "rxq");
16755 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
16756         TOKEN_NUM_INITIALIZER
16757                 (struct cmd_show_rx_queue_desc_used_count_result,
16758                  cmd_qid, RTE_UINT16);
16759 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
16760         TOKEN_STRING_INITIALIZER
16761                 (struct cmd_show_rx_queue_desc_used_count_result,
16762                  cmd_count, "desc");
16763 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
16764         TOKEN_STRING_INITIALIZER
16765                 (struct cmd_show_rx_queue_desc_used_count_result,
16766                  cmd_count, "used");
16767 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
16768         TOKEN_STRING_INITIALIZER
16769                 (struct cmd_show_rx_queue_desc_used_count_result,
16770                  cmd_count, "count");
16771 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
16772         .f = cmd_show_rx_queue_desc_used_count_parsed,
16773         .data = NULL,
16774         .help_str = "show port <port_id> rxq <queue_id> desc used count",
16775         .tokens = {
16776                 (void *)&cmd_show_rx_queue_desc_used_count_show,
16777                 (void *)&cmd_show_rx_queue_desc_used_count_port,
16778                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
16779                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
16780                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
16781                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
16782                 (void *)&cmd_show_rx_queue_desc_used_count_used,
16783                 (void *)&cmd_show_rx_queue_desc_used_count_count,
16784                 NULL,
16785         },
16786 };
16787
16788 /* Common result structure for set port ptypes */
16789 struct cmd_set_port_ptypes_result {
16790         cmdline_fixed_string_t set;
16791         cmdline_fixed_string_t port;
16792         portid_t port_id;
16793         cmdline_fixed_string_t ptype_mask;
16794         uint32_t mask;
16795 };
16796
16797 /* Common CLI fields for set port ptypes */
16798 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16799         TOKEN_STRING_INITIALIZER
16800                 (struct cmd_set_port_ptypes_result,
16801                  set, "set");
16802 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16803         TOKEN_STRING_INITIALIZER
16804                 (struct cmd_set_port_ptypes_result,
16805                  port, "port");
16806 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16807         TOKEN_NUM_INITIALIZER
16808                 (struct cmd_set_port_ptypes_result,
16809                  port_id, RTE_UINT16);
16810 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16811         TOKEN_STRING_INITIALIZER
16812                 (struct cmd_set_port_ptypes_result,
16813                  ptype_mask, "ptype_mask");
16814 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16815         TOKEN_NUM_INITIALIZER
16816                 (struct cmd_set_port_ptypes_result,
16817                  mask, RTE_UINT32);
16818
16819 static void
16820 cmd_set_port_ptypes_parsed(
16821         void *parsed_result,
16822         __rte_unused struct cmdline *cl,
16823         __rte_unused void *data)
16824 {
16825         struct cmd_set_port_ptypes_result *res = parsed_result;
16826 #define PTYPE_NAMESIZE        256
16827         char ptype_name[PTYPE_NAMESIZE];
16828         uint16_t port_id = res->port_id;
16829         uint32_t ptype_mask = res->mask;
16830         int ret, i;
16831
16832         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16833                                                NULL, 0);
16834         if (ret <= 0) {
16835                 printf("Port %d doesn't support any ptypes.\n", port_id);
16836                 return;
16837         }
16838
16839         uint32_t ptypes[ret];
16840
16841         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16842         if (ret < 0) {
16843                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16844                 return;
16845         }
16846
16847         printf("Successfully set following ptypes for Port %d\n", port_id);
16848         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16849                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16850                 printf("%s\n", ptype_name);
16851         }
16852
16853         clear_ptypes = false;
16854 }
16855
16856 cmdline_parse_inst_t cmd_set_port_ptypes = {
16857         .f = cmd_set_port_ptypes_parsed,
16858         .data = NULL,
16859         .help_str = "set port <port_id> ptype_mask <mask>",
16860         .tokens = {
16861                 (void *)&cmd_set_port_ptypes_set,
16862                 (void *)&cmd_set_port_ptypes_port,
16863                 (void *)&cmd_set_port_ptypes_port_id,
16864                 (void *)&cmd_set_port_ptypes_mask_str,
16865                 (void *)&cmd_set_port_ptypes_mask_u32,
16866                 NULL,
16867         },
16868 };
16869
16870 /* *** display mac addresses added to a port *** */
16871 struct cmd_showport_macs_result {
16872         cmdline_fixed_string_t cmd_show;
16873         cmdline_fixed_string_t cmd_port;
16874         cmdline_fixed_string_t cmd_keyword;
16875         portid_t cmd_pid;
16876 };
16877
16878 static void
16879 cmd_showport_macs_parsed(void *parsed_result,
16880                 __rte_unused struct cmdline *cl,
16881                 __rte_unused void *data)
16882 {
16883         struct cmd_showport_macs_result *res = parsed_result;
16884
16885         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16886                 return;
16887
16888         if (!strcmp(res->cmd_keyword, "macs"))
16889                 show_macs(res->cmd_pid);
16890         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16891                 show_mcast_macs(res->cmd_pid);
16892 }
16893
16894 cmdline_parse_token_string_t cmd_showport_macs_show =
16895         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16896                         cmd_show, "show");
16897 cmdline_parse_token_string_t cmd_showport_macs_port =
16898         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16899                         cmd_port, "port");
16900 cmdline_parse_token_num_t cmd_showport_macs_pid =
16901         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16902                         cmd_pid, RTE_UINT16);
16903 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16904         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16905                         cmd_keyword, "macs#mcast_macs");
16906
16907 cmdline_parse_inst_t cmd_showport_macs = {
16908         .f = cmd_showport_macs_parsed,
16909         .data = NULL,
16910         .help_str = "show port <port_id> macs|mcast_macs",
16911         .tokens = {
16912                 (void *)&cmd_showport_macs_show,
16913                 (void *)&cmd_showport_macs_port,
16914                 (void *)&cmd_showport_macs_pid,
16915                 (void *)&cmd_showport_macs_keyword,
16916                 NULL,
16917         },
16918 };
16919
16920 /* ******************************************************************************** */
16921
16922 /* list of instructions */
16923 cmdline_parse_ctx_t main_ctx[] = {
16924         (cmdline_parse_inst_t *)&cmd_help_brief,
16925         (cmdline_parse_inst_t *)&cmd_help_long,
16926         (cmdline_parse_inst_t *)&cmd_quit,
16927         (cmdline_parse_inst_t *)&cmd_load_from_file,
16928         (cmdline_parse_inst_t *)&cmd_showport,
16929         (cmdline_parse_inst_t *)&cmd_showqueue,
16930         (cmdline_parse_inst_t *)&cmd_showeeprom,
16931         (cmdline_parse_inst_t *)&cmd_showportall,
16932         (cmdline_parse_inst_t *)&cmd_showdevice,
16933         (cmdline_parse_inst_t *)&cmd_showcfg,
16934         (cmdline_parse_inst_t *)&cmd_showfwdall,
16935         (cmdline_parse_inst_t *)&cmd_start,
16936         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16937         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16938         (cmdline_parse_inst_t *)&cmd_set_link_up,
16939         (cmdline_parse_inst_t *)&cmd_set_link_down,
16940         (cmdline_parse_inst_t *)&cmd_reset,
16941         (cmdline_parse_inst_t *)&cmd_set_numbers,
16942         (cmdline_parse_inst_t *)&cmd_set_log,
16943         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16944         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16945         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16946         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16947         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16948         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16949         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16950         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16951         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16952         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16953         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16954         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16955         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16956         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16957         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16958         (cmdline_parse_inst_t *)&cmd_set_link_check,
16959         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16960         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16961         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16962         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16963 #ifdef RTE_NET_BOND
16964         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16965         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16966         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16967         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16968         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16969         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16970         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16971         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16972         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16973         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16974         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16975 #endif
16976         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16977         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16978         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16979         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16980         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16981         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16982         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16983         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16984         (cmdline_parse_inst_t *)&cmd_csum_set,
16985         (cmdline_parse_inst_t *)&cmd_csum_show,
16986         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16987         (cmdline_parse_inst_t *)&cmd_tso_set,
16988         (cmdline_parse_inst_t *)&cmd_tso_show,
16989         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16990         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16991         (cmdline_parse_inst_t *)&cmd_gro_enable,
16992         (cmdline_parse_inst_t *)&cmd_gro_flush,
16993         (cmdline_parse_inst_t *)&cmd_gro_show,
16994         (cmdline_parse_inst_t *)&cmd_gso_enable,
16995         (cmdline_parse_inst_t *)&cmd_gso_size,
16996         (cmdline_parse_inst_t *)&cmd_gso_show,
16997         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16998         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16999         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17000         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17001         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17002         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17003         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17004         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17005         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17006         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17007         (cmdline_parse_inst_t *)&cmd_config_dcb,
17008         (cmdline_parse_inst_t *)&cmd_read_reg,
17009         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17010         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17011         (cmdline_parse_inst_t *)&cmd_write_reg,
17012         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17013         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17014         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17015         (cmdline_parse_inst_t *)&cmd_stop,
17016         (cmdline_parse_inst_t *)&cmd_mac_addr,
17017         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17018         (cmdline_parse_inst_t *)&cmd_set_qmap,
17019         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17020         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17021         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17022         (cmdline_parse_inst_t *)&cmd_operate_port,
17023         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17024         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17025         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17026         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17027         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17028         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17029         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17030         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17031         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17032         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17033         (cmdline_parse_inst_t *)&cmd_config_mtu,
17034         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17035         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17036         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17037         (cmdline_parse_inst_t *)&cmd_config_rss,
17038         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17039         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17040         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17041         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17042         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17043         (cmdline_parse_inst_t *)&cmd_showport_reta,
17044         (cmdline_parse_inst_t *)&cmd_showport_macs,
17045         (cmdline_parse_inst_t *)&cmd_config_burst,
17046         (cmdline_parse_inst_t *)&cmd_config_thresh,
17047         (cmdline_parse_inst_t *)&cmd_config_threshold,
17048         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17049         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17050         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17051         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17052         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17053         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17054         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17055         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17056         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17057         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17058         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17059         (cmdline_parse_inst_t *)&cmd_dump,
17060         (cmdline_parse_inst_t *)&cmd_dump_one,
17061 #ifdef RTE_NET_I40E
17062         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17063 #endif
17064         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17065         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17066         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17067         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17068         (cmdline_parse_inst_t *)&cmd_flow,
17069         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17070         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17071         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17072         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17073         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17074         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17075         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17076         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17077         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17078         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17079         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17080         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17081         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17082         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17083         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17084         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17085         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17086         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17087         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17088         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17089         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17090         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17091         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17092         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17093         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17094         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17095         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17096         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17097         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17098         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17099         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17100         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17101         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17102         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17103         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17104         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17105         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17106         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17107         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17108         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17109         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17110         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17111         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17112         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17113         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17114         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17115         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17116         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17117         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17118         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17119         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17120         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17121         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17122         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17123         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17124         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17125         (cmdline_parse_inst_t *)&cmd_ddp_add,
17126         (cmdline_parse_inst_t *)&cmd_ddp_del,
17127         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17128         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17129         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17130         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17131         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17132         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17133         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17134         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17135         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17136         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17137         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17138         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17139
17140         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17141         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17142         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17143         (cmdline_parse_inst_t *)&cmd_queue_region,
17144         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17145         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17146         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17147         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17148         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17149         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17150         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17151         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17152         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17153         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17154         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17155         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17156         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17157         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17158         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17159         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17160         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17161         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17162         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17163         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17164         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17165         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17166         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17167         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17168         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17169         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17170         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17171         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17172         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17173         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17174         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17175         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17176         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17177         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17178         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17179         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17180 #ifdef RTE_LIB_BPF
17181         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17182         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17183 #endif
17184         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17185         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17186         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17187         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17188         (cmdline_parse_inst_t *)&cmd_set_raw,
17189         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17190         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17191         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17192         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17193         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17194         (cmdline_parse_inst_t *)&cmd_show_capability,
17195         NULL,
17196 };
17197
17198 /* read cmdline commands from file */
17199 void
17200 cmdline_read_from_file(const char *filename)
17201 {
17202         struct cmdline *cl;
17203
17204         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17205         if (cl == NULL) {
17206                 printf("Failed to create file based cmdline context: %s\n",
17207                        filename);
17208                 return;
17209         }
17210
17211         cmdline_interact(cl);
17212         cmdline_quit(cl);
17213
17214         cmdline_free(cl);
17215
17216         printf("Read CLI commands from %s\n", filename);
17217 }
17218
17219 /* prompt function, called from main on MAIN lcore */
17220 void
17221 prompt(void)
17222 {
17223         int ret;
17224         /* initialize non-constant commands */
17225         cmd_set_fwd_mode_init();
17226         cmd_set_fwd_retry_mode_init();
17227
17228         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17229         if (testpmd_cl == NULL)
17230                 return;
17231
17232         ret = atexit(prompt_exit);
17233         if (ret != 0)
17234                 printf("Cannot set exit function for cmdline\n");
17235
17236         cmdline_interact(testpmd_cl);
17237         if (ret != 0)
17238                 cmdline_stdin_exit(testpmd_cl);
17239 }
17240
17241 void
17242 prompt_exit(void)
17243 {
17244         if (testpmd_cl != NULL) {
17245                 cmdline_quit(testpmd_cl);
17246                 cmdline_stdin_exit(testpmd_cl);
17247         }
17248 }
17249
17250 static void
17251 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17252 {
17253         if (id == (portid_t)RTE_PORT_ALL) {
17254                 portid_t pid;
17255
17256                 RTE_ETH_FOREACH_DEV(pid) {
17257                         /* check if need_reconfig has been set to 1 */
17258                         if (ports[pid].need_reconfig == 0)
17259                                 ports[pid].need_reconfig = dev;
17260                         /* check if need_reconfig_queues has been set to 1 */
17261                         if (ports[pid].need_reconfig_queues == 0)
17262                                 ports[pid].need_reconfig_queues = queue;
17263                 }
17264         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17265                 /* check if need_reconfig has been set to 1 */
17266                 if (ports[id].need_reconfig == 0)
17267                         ports[id].need_reconfig = dev;
17268                 /* check if need_reconfig_queues has been set to 1 */
17269                 if (ports[id].need_reconfig_queues == 0)
17270                         ports[id].need_reconfig_queues = queue;
17271         }
17272 }