app/testpmd: avoid exit without terminal restore
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         "    outer-udp concerns the outer UDP layer in"
435                         " case the packet is recognized as a tunnel packet by"
436                         " the forward engine (vxlan, gre and ipip are supported)\n"
437                         "    Please check the NIC datasheet for HW limits.\n\n"
438
439                         "csum parse-tunnel (on|off) (tx_port_id)\n"
440                         "    If disabled, treat tunnel packets as non-tunneled"
441                         " packets (treat inner headers as payload). The port\n"
442                         "    argument is the port used for TX in csum forward"
443                         " engine.\n\n"
444
445                         "csum show (port_id)\n"
446                         "    Display tx checksum offload configuration\n\n"
447
448                         "tso set (segsize) (portid)\n"
449                         "    Enable TCP Segmentation Offload in csum forward"
450                         " engine.\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "tso show (portid)"
454                         "    Display the status of TCP Segmentation Offload.\n\n"
455
456                         "set port (port_id) gro on|off\n"
457                         "    Enable or disable Generic Receive Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "show port (port_id) gro\n"
461                         "    Display GRO configuration.\n\n"
462
463                         "set gro flush (cycles)\n"
464                         "    Set the cycle to flush GROed packets from"
465                         " reassembly tables.\n\n"
466
467                         "set port (port_id) gso (on|off)"
468                         "    Enable or disable Generic Segmentation Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "set gso segsz (length)\n"
472                         "    Set max packet length for output GSO segments,"
473                         " including packet header and payload.\n\n"
474
475                         "show port (port_id) gso\n"
476                         "    Show GSO configuration.\n\n"
477
478                         "set fwd (%s)\n"
479                         "    Set packet forwarding mode.\n\n"
480
481                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
482                         "    Add a MAC address on port_id.\n\n"
483
484                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Remove a MAC address from port_id.\n\n"
486
487                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Set the default MAC address for port_id.\n\n"
489
490                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
491                         "    Add a MAC address for a VF on the port.\n\n"
492
493                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the MAC address for a VF from the PF.\n\n"
495
496                         "set eth-peer (port_id) (peer_addr)\n"
497                         "    set the peer address for certain port.\n\n"
498
499                         "set port (port_id) uta (mac_address|all) (on|off)\n"
500                         "    Add/Remove a or all unicast hash filter(s)"
501                         "from port X.\n\n"
502
503                         "set promisc (port_id|all) (on|off)\n"
504                         "    Set the promiscuous mode on port_id, or all.\n\n"
505
506                         "set allmulti (port_id|all) (on|off)\n"
507                         "    Set the allmulti mode on port_id, or all.\n\n"
508
509                         "set vf promisc (port_id) (vf_id) (on|off)\n"
510                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
511
512                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
513                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
517                         " (on|off) autoneg (on|off) (port_id)\n"
518                         "set flow_ctrl rx (on|off) (portid)\n"
519                         "set flow_ctrl tx (on|off) (portid)\n"
520                         "set flow_ctrl high_water (high_water) (portid)\n"
521                         "set flow_ctrl low_water (low_water) (portid)\n"
522                         "set flow_ctrl pause_time (pause_time) (portid)\n"
523                         "set flow_ctrl send_xon (send_xon) (portid)\n"
524                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
525                         "set flow_ctrl autoneg (on|off) (port_id)\n"
526                         "    Set the link flow control parameter on a port.\n\n"
527
528                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
529                         " (low_water) (pause_time) (priority) (port_id)\n"
530                         "    Set the priority flow control parameter on a"
531                         " port.\n\n"
532
533                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
534                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
535                         " queue on port.\n"
536                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
537                         " on port 0 to mapping 5.\n\n"
538
539                         "set xstats-hide-zero on|off\n"
540                         "    Set the option to hide the zero values"
541                         " for xstats display.\n"
542
543                         "set record-core-cycles on|off\n"
544                         "    Set the option to enable measurement of CPU cycles.\n"
545
546                         "set record-burst-stats on|off\n"
547                         "    Set the option to enable display of RX and TX bursts.\n"
548
549                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
550                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
553                         "|MPE) (on|off)\n"
554                         "    AUPE:accepts untagged VLAN;"
555                         "ROPE:accept unicast hash\n\n"
556                         "    BAM:accepts broadcast packets;"
557                         "MPE:accepts all multicast packets\n\n"
558                         "    Enable/Disable a VF receive mode of a port\n\n"
559
560                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
561                         "    Set rate limit for a queue of a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rate (rate_num) "
564                         "queue_mask (queue_mask_value)\n"
565                         "    Set rate limit for queues in VF of a port\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
569                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
570                         "   Set pool or vlan type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
572                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
573                         " to pool 0.\n\n"
574
575                         "set port (port_id) mirror-rule (rule_id)"
576                         " (uplink-mirror|downlink-mirror) dst-pool"
577                         " (pool_id) (on|off)\n"
578                         "   Set uplink or downlink type mirror rule on a port.\n"
579                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
580                         " 0 on' enable mirror income traffic to pool 0.\n\n"
581
582                         "reset port (port_id) mirror-rule (rule_id)\n"
583                         "   Reset a mirror rule.\n\n"
584
585                         "set flush_rx (on|off)\n"
586                         "   Flush (default) or don't flush RX streams before"
587                         " forwarding. Mainly used with PCAP drivers.\n\n"
588
589                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the bypass mode for the lowest port on bypass enabled"
591                         " NIC.\n\n"
592
593                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
594                         "mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the event required to initiate specified bypass mode for"
596                         " the lowest port on a bypass enabled NIC where:\n"
597                         "       timeout   = enable bypass after watchdog timeout.\n"
598                         "       os_on     = enable bypass when OS/board is powered on.\n"
599                         "       os_off    = enable bypass when OS/board is powered off.\n"
600                         "       power_on  = enable bypass when power supply is turned on.\n"
601                         "       power_off = enable bypass when power supply is turned off."
602                         "\n\n"
603
604                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
605                         "   Set the bypass watchdog timeout to 'n' seconds"
606                         " where 0 = instant.\n\n"
607
608                         "show bypass config (port_id)\n"
609                         "   Show the bypass configuration for a bypass enabled NIC"
610                         " using the lowest port on the NIC.\n\n"
611
612 #ifdef RTE_NET_BOND
613                         "create bonded device (mode) (socket)\n"
614                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
615
616                         "add bonding slave (slave_id) (port_id)\n"
617                         "       Add a slave device to a bonded device.\n\n"
618
619                         "remove bonding slave (slave_id) (port_id)\n"
620                         "       Remove a slave device from a bonded device.\n\n"
621
622                         "set bonding mode (value) (port_id)\n"
623                         "       Set the bonding mode on a bonded device.\n\n"
624
625                         "set bonding primary (slave_id) (port_id)\n"
626                         "       Set the primary slave for a bonded device.\n\n"
627
628                         "show bonding config (port_id)\n"
629                         "       Show the bonding config for port_id.\n\n"
630
631                         "set bonding mac_addr (port_id) (address)\n"
632                         "       Set the MAC address of a bonded device.\n\n"
633
634                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
635                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
636
637                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
638                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
639
640                         "set bonding mon_period (port_id) (value)\n"
641                         "       Set the bonding link status monitoring polling period in ms.\n\n"
642
643                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
644                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
645
646 #endif
647                         "set link-up port (port_id)\n"
648                         "       Set link up for a port.\n\n"
649
650                         "set link-down port (port_id)\n"
651                         "       Set link down for a port.\n\n"
652
653                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) ptype_mask (ptype_mask)\n"
672                         "    set packet types classification for a specific port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         "set port (port_id) fec_mode auto|off|rs|baser\n"
737                         "    set fec mode for a specific port\n\n"
738
739                         , list_pkt_forwarding_modes()
740                 );
741         }
742
743         if (show_all || !strcmp(res->section, "ports")) {
744
745                 cmdline_printf(
746                         cl,
747                         "\n"
748                         "Port Operations:\n"
749                         "----------------\n\n"
750
751                         "port start (port_id|all)\n"
752                         "    Start all ports or port_id.\n\n"
753
754                         "port stop (port_id|all)\n"
755                         "    Stop all ports or port_id.\n\n"
756
757                         "port close (port_id|all)\n"
758                         "    Close all ports or port_id.\n\n"
759
760                         "port reset (port_id|all)\n"
761                         "    Reset all ports or port_id.\n\n"
762
763                         "port attach (ident)\n"
764                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
765
766                         "port detach (port_id)\n"
767                         "    Detach physical or virtual dev by port_id\n\n"
768
769                         "port config (port_id|all)"
770                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
771                         " duplex (half|full|auto)\n"
772                         "    Set speed and duplex for all ports or port_id\n\n"
773
774                         "port config (port_id|all) loopback (mode)\n"
775                         "    Set loopback mode for all ports or port_id\n\n"
776
777                         "port config all (rxq|txq|rxd|txd) (value)\n"
778                         "    Set number for rxq/txq/rxd/txd.\n\n"
779
780                         "port config all max-pkt-len (value)\n"
781                         "    Set the max packet length.\n\n"
782
783                         "port config all max-lro-pkt-size (value)\n"
784                         "    Set the max LRO aggregated packet size.\n\n"
785
786                         "port config all drop-en (on|off)\n"
787                         "    Enable or disable packet drop on all RX queues of all ports when no "
788                         "receive buffers available.\n\n"
789
790                         "port config all rss (all|default|ip|tcp|udp|sctp|"
791                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
792                         "level-outer|level-inner|<flowtype_id>)\n"
793                         "    Set the RSS mode.\n\n"
794
795                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
796                         "    Set the RSS redirection table.\n\n"
797
798                         "port config (port_id) dcb vt (on|off) (traffic_class)"
799                         " pfc (on|off)\n"
800                         "    Set the DCB mode.\n\n"
801
802                         "port config all burst (value)\n"
803                         "    Set the number of packets per burst.\n\n"
804
805                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
806                         " (value)\n"
807                         "    Set the ring prefetch/host/writeback threshold"
808                         " for tx/rx queue.\n\n"
809
810                         "port config all (txfreet|txrst|rxfreet) (value)\n"
811                         "    Set free threshold for rx/tx, or set"
812                         " tx rs bit threshold.\n\n"
813                         "port config mtu X value\n"
814                         "    Set the MTU of port X to a given value\n\n"
815
816                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
817                         "    Set a rx/tx queue's ring size configuration, the new"
818                         " value will take effect after command that (re-)start the port"
819                         " or command that setup the specific queue\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
822                         "    Start/stop a rx/tx queue of port X. Only take effect"
823                         " when port X is started\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
826                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
827                         " take effect when port X is stopped.\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) setup\n"
830                         "    Setup a rx/tx queue of port X.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
855                         "buffer_split|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
863                         "buffer_split|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896
897                         "port config (port_id) dynf (name) set|clear\n"
898                         "    Register a dynf and Set/clear this flag on Tx. "
899                         "Testpmd will set this value to any Tx packet "
900                         "sent from this port\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940 #ifdef RTE_NET_I40E
941                         "flow_director_filter (port_id) mode raw (add|del|update)"
942                         " flow (flow_id) (drop|fwd) queue (queue_id)"
943                         " fd_id (fd_id_value) packet (packet file name)\n"
944                         "    Add/Del a raw type flow director filter.\n\n"
945 #endif
946
947                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
948                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
949                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
950                         "    Set flow director IP mask.\n\n"
951
952                         "flow_director_mask (port_id) mode MAC-VLAN"
953                         " vlan (vlan_value)\n"
954                         "    Set flow director MAC-VLAN mask.\n\n"
955
956                         "flow_director_mask (port_id) mode Tunnel"
957                         " vlan (vlan_value) mac (mac_value)"
958                         " tunnel-type (tunnel_type_value)"
959                         " tunnel-id (tunnel_id_value)\n"
960                         "    Set flow director Tunnel mask.\n\n"
961
962                         "flow_director_flex_payload (port_id)"
963                         " (raw|l2|l3|l4) (config)\n"
964                         "    Configure flex payload selection.\n\n"
965
966                         "flow validate {port_id}"
967                         " [group {group_id}] [priority {level}]"
968                         " [ingress] [egress]"
969                         " pattern {item} [/ {item} [...]] / end"
970                         " actions {action} [/ {action} [...]] / end\n"
971                         "    Check whether a flow rule can be created.\n\n"
972
973                         "flow create {port_id}"
974                         " [group {group_id}] [priority {level}]"
975                         " [ingress] [egress]"
976                         " pattern {item} [/ {item} [...]] / end"
977                         " actions {action} [/ {action} [...]] / end\n"
978                         "    Create a flow rule.\n\n"
979
980                         "flow destroy {port_id} rule {rule_id} [...]\n"
981                         "    Destroy specific flow rules.\n\n"
982
983                         "flow flush {port_id}\n"
984                         "    Destroy all flow rules.\n\n"
985
986                         "flow query {port_id} {rule_id} {action}\n"
987                         "    Query an existing flow rule.\n\n"
988
989                         "flow list {port_id} [group {group_id}] [...]\n"
990                         "    List existing flow rules sorted by priority,"
991                         " filtered by group identifiers.\n\n"
992
993                         "flow isolate {port_id} {boolean}\n"
994                         "    Restrict ingress traffic to the defined"
995                         " flow rules\n\n"
996
997                         "flow aged {port_id} [destroy]\n"
998                         "    List and destroy aged flows"
999                         " flow rules\n\n"
1000
1001                         "flow shared_action {port_id} create"
1002                         " [action_id {shared_action_id}]"
1003                         " [ingress] [egress]"
1004                         " action {action} / end\n"
1005                         "    Create shared action.\n\n"
1006
1007                         "flow shared_action {port_id} update"
1008                         " {shared_action_id} action {action} / end\n"
1009                         "    Update shared action.\n\n"
1010
1011                         "flow shared_action {port_id} destroy"
1012                         " action_id {shared_action_id} [...]\n"
1013                         "    Destroy specific shared actions.\n\n"
1014
1015                         "flow shared_action {port_id} query"
1016                         " {shared_action_id}\n"
1017                         "    Query an existing shared action.\n\n"
1018
1019                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1020                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1021                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1022                         "       Configure the VXLAN encapsulation for flows.\n\n"
1023
1024                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1025                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1026                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1027                         " eth-dst (eth-dst)\n"
1028                         "       Configure the VXLAN encapsulation for flows.\n\n"
1029
1030                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1031                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1032                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1033                         " eth-dst (eth-dst)\n"
1034                         "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1037                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1038                         " (eth-dst)\n"
1039                         "       Configure the NVGRE encapsulation for flows.\n\n"
1040
1041                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1043                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set raw_encap {flow items}\n"
1047                         "       Configure the encapsulation with raw data.\n\n"
1048
1049                         "set raw_decap {flow items}\n"
1050                         "       Configure the decapsulation with raw data.\n\n"
1051
1052                 );
1053         }
1054
1055         if (show_all || !strcmp(res->section, "traffic_management")) {
1056                 cmdline_printf(
1057                         cl,
1058                         "\n"
1059                         "Traffic Management:\n"
1060                         "--------------\n"
1061                         "show port tm cap (port_id)\n"
1062                         "       Display the port TM capability.\n\n"
1063
1064                         "show port tm level cap (port_id) (level_id)\n"
1065                         "       Display the port TM hierarchical level capability.\n\n"
1066
1067                         "show port tm node cap (port_id) (node_id)\n"
1068                         "       Display the port TM node capability.\n\n"
1069
1070                         "show port tm node type (port_id) (node_id)\n"
1071                         "       Display the port TM node type.\n\n"
1072
1073                         "show port tm node stats (port_id) (node_id) (clear)\n"
1074                         "       Display the port TM node stats.\n\n"
1075
1076                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1077                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1078                         " (packet_length_adjust) (packet_mode)\n"
1079                         "       Add port tm node private shaper profile.\n\n"
1080
1081                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1082                         "       Delete port tm node private shaper profile.\n\n"
1083
1084                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1085                         " (shaper_profile_id)\n"
1086                         "       Add/update port tm node shared shaper.\n\n"
1087
1088                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1089                         "       Delete port tm node shared shaper.\n\n"
1090
1091                         "set port tm node shaper profile (port_id) (node_id)"
1092                         " (shaper_profile_id)\n"
1093                         "       Set port tm node shaper profile.\n\n"
1094
1095                         "add port tm node wred profile (port_id) (wred_profile_id)"
1096                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1097                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1098                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1099                         "       Add port tm node wred profile.\n\n"
1100
1101                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1102                         "       Delete port tm node wred profile.\n\n"
1103
1104                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1105                         " (priority) (weight) (level_id) (shaper_profile_id)"
1106                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1107                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1108                         "       Add port tm nonleaf node.\n\n"
1109
1110                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1111                         " (priority) (weight) (level_id) (shaper_profile_id)"
1112                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1113                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1114                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1115
1116                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1117                         " (priority) (weight) (level_id) (shaper_profile_id)"
1118                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1119                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                         "       Add port tm leaf node.\n\n"
1121
1122                         "del port tm node (port_id) (node_id)\n"
1123                         "       Delete port tm node.\n\n"
1124
1125                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1126                         " (priority) (weight)\n"
1127                         "       Set port tm node parent.\n\n"
1128
1129                         "suspend port tm node (port_id) (node_id)"
1130                         "       Suspend tm node.\n\n"
1131
1132                         "resume port tm node (port_id) (node_id)"
1133                         "       Resume tm node.\n\n"
1134
1135                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1136                         "       Commit tm hierarchy.\n\n"
1137
1138                         "set port tm mark ip_ecn (port) (green) (yellow)"
1139                         " (red)\n"
1140                         "    Enables/Disables the traffic management marking"
1141                         " for IP ECN (Explicit Congestion Notification)"
1142                         " packets on a given port\n\n"
1143
1144                         "set port tm mark ip_dscp (port) (green) (yellow)"
1145                         " (red)\n"
1146                         "    Enables/Disables the traffic management marking"
1147                         " on the port for IP dscp packets\n\n"
1148
1149                         "set port tm mark vlan_dei (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for VLAN packets with DEI enabled\n\n"
1153                 );
1154         }
1155
1156         if (show_all || !strcmp(res->section, "devices")) {
1157                 cmdline_printf(
1158                         cl,
1159                         "\n"
1160                         "Device Operations:\n"
1161                         "--------------\n"
1162                         "device detach (identifier)\n"
1163                         "       Detach device by identifier.\n\n"
1164                 );
1165         }
1166
1167 }
1168
1169 cmdline_parse_token_string_t cmd_help_long_help =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1171
1172 cmdline_parse_token_string_t cmd_help_long_section =
1173         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1174                         "all#control#display#config#"
1175                         "ports#registers#filters#traffic_management#devices");
1176
1177 cmdline_parse_inst_t cmd_help_long = {
1178         .f = cmd_help_long_parsed,
1179         .data = NULL,
1180         .help_str = "help all|control|display|config|ports|register|"
1181                 "filters|traffic_management|devices: "
1182                 "Show help",
1183         .tokens = {
1184                 (void *)&cmd_help_long_help,
1185                 (void *)&cmd_help_long_section,
1186                 NULL,
1187         },
1188 };
1189
1190
1191 /* *** start/stop/close all ports *** */
1192 struct cmd_operate_port_result {
1193         cmdline_fixed_string_t keyword;
1194         cmdline_fixed_string_t name;
1195         cmdline_fixed_string_t value;
1196 };
1197
1198 static void cmd_operate_port_parsed(void *parsed_result,
1199                                 __rte_unused struct cmdline *cl,
1200                                 __rte_unused void *data)
1201 {
1202         struct cmd_operate_port_result *res = parsed_result;
1203
1204         if (!strcmp(res->name, "start"))
1205                 start_port(RTE_PORT_ALL);
1206         else if (!strcmp(res->name, "stop"))
1207                 stop_port(RTE_PORT_ALL);
1208         else if (!strcmp(res->name, "close"))
1209                 close_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "reset"))
1211                 reset_port(RTE_PORT_ALL);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1218                                                                 "port");
1219 cmdline_parse_token_string_t cmd_operate_port_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1221                                                 "start#stop#close#reset");
1222 cmdline_parse_token_string_t cmd_operate_port_all_all =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1224
1225 cmdline_parse_inst_t cmd_operate_port = {
1226         .f = cmd_operate_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1229         .tokens = {
1230                 (void *)&cmd_operate_port_all_cmd,
1231                 (void *)&cmd_operate_port_all_port,
1232                 (void *)&cmd_operate_port_all_all,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** start/stop/close specific port *** */
1238 struct cmd_operate_specific_port_result {
1239         cmdline_fixed_string_t keyword;
1240         cmdline_fixed_string_t name;
1241         uint8_t value;
1242 };
1243
1244 static void cmd_operate_specific_port_parsed(void *parsed_result,
1245                         __rte_unused struct cmdline *cl,
1246                                 __rte_unused void *data)
1247 {
1248         struct cmd_operate_specific_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->name, "start"))
1251                 start_port(res->value);
1252         else if (!strcmp(res->name, "stop"))
1253                 stop_port(res->value);
1254         else if (!strcmp(res->name, "close"))
1255                 close_port(res->value);
1256         else if (!strcmp(res->name, "reset"))
1257                 reset_port(res->value);
1258         else
1259                 printf("Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                         keyword, "port");
1265 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                 name, "start#stop#close#reset");
1268 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1269         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1270                                                         value, RTE_UINT8);
1271
1272 cmdline_parse_inst_t cmd_operate_specific_port = {
1273         .f = cmd_operate_specific_port_parsed,
1274         .data = NULL,
1275         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1276         .tokens = {
1277                 (void *)&cmd_operate_specific_port_cmd,
1278                 (void *)&cmd_operate_specific_port_port,
1279                 (void *)&cmd_operate_specific_port_id,
1280                 NULL,
1281         },
1282 };
1283
1284 /* *** enable port setup (after attach) via iterator or event *** */
1285 struct cmd_set_port_setup_on_result {
1286         cmdline_fixed_string_t set;
1287         cmdline_fixed_string_t port;
1288         cmdline_fixed_string_t setup;
1289         cmdline_fixed_string_t on;
1290         cmdline_fixed_string_t mode;
1291 };
1292
1293 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1294                                 __rte_unused struct cmdline *cl,
1295                                 __rte_unused void *data)
1296 {
1297         struct cmd_set_port_setup_on_result *res = parsed_result;
1298
1299         if (strcmp(res->mode, "event") == 0)
1300                 setup_on_probe_event = true;
1301         else if (strcmp(res->mode, "iterator") == 0)
1302                 setup_on_probe_event = false;
1303         else
1304                 printf("Unknown mode\n");
1305 }
1306
1307 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1308         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1309                         set, "set");
1310 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1311         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1312                         port, "port");
1313 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1314         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1315                         setup, "setup");
1316 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1317         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1318                         on, "on");
1319 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1320         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1321                         mode, "iterator#event");
1322
1323 cmdline_parse_inst_t cmd_set_port_setup_on = {
1324         .f = cmd_set_port_setup_on_parsed,
1325         .data = NULL,
1326         .help_str = "set port setup on iterator|event",
1327         .tokens = {
1328                 (void *)&cmd_set_port_setup_on_set,
1329                 (void *)&cmd_set_port_setup_on_port,
1330                 (void *)&cmd_set_port_setup_on_setup,
1331                 (void *)&cmd_set_port_setup_on_on,
1332                 (void *)&cmd_set_port_setup_on_mode,
1333                 NULL,
1334         },
1335 };
1336
1337 /* *** attach a specified port *** */
1338 struct cmd_operate_attach_port_result {
1339         cmdline_fixed_string_t port;
1340         cmdline_fixed_string_t keyword;
1341         cmdline_multi_string_t identifier;
1342 };
1343
1344 static void cmd_operate_attach_port_parsed(void *parsed_result,
1345                                 __rte_unused struct cmdline *cl,
1346                                 __rte_unused void *data)
1347 {
1348         struct cmd_operate_attach_port_result *res = parsed_result;
1349
1350         if (!strcmp(res->keyword, "attach"))
1351                 attach_port(res->identifier);
1352         else
1353                 printf("Unknown parameter\n");
1354 }
1355
1356 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1357         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1358                         port, "port");
1359 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1360         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1361                         keyword, "attach");
1362 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1363         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1364                         identifier, TOKEN_STRING_MULTI);
1365
1366 cmdline_parse_inst_t cmd_operate_attach_port = {
1367         .f = cmd_operate_attach_port_parsed,
1368         .data = NULL,
1369         .help_str = "port attach <identifier>: "
1370                 "(identifier: pci address or virtual dev name)",
1371         .tokens = {
1372                 (void *)&cmd_operate_attach_port_port,
1373                 (void *)&cmd_operate_attach_port_keyword,
1374                 (void *)&cmd_operate_attach_port_identifier,
1375                 NULL,
1376         },
1377 };
1378
1379 /* *** detach a specified port *** */
1380 struct cmd_operate_detach_port_result {
1381         cmdline_fixed_string_t port;
1382         cmdline_fixed_string_t keyword;
1383         portid_t port_id;
1384 };
1385
1386 static void cmd_operate_detach_port_parsed(void *parsed_result,
1387                                 __rte_unused struct cmdline *cl,
1388                                 __rte_unused void *data)
1389 {
1390         struct cmd_operate_detach_port_result *res = parsed_result;
1391
1392         if (!strcmp(res->keyword, "detach")) {
1393                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1394                 detach_port_device(res->port_id);
1395         } else {
1396                 printf("Unknown parameter\n");
1397         }
1398 }
1399
1400 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1401         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1402                         port, "port");
1403 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1404         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1405                         keyword, "detach");
1406 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1407         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1408                         port_id, RTE_UINT16);
1409
1410 cmdline_parse_inst_t cmd_operate_detach_port = {
1411         .f = cmd_operate_detach_port_parsed,
1412         .data = NULL,
1413         .help_str = "port detach <port_id>",
1414         .tokens = {
1415                 (void *)&cmd_operate_detach_port_port,
1416                 (void *)&cmd_operate_detach_port_keyword,
1417                 (void *)&cmd_operate_detach_port_port_id,
1418                 NULL,
1419         },
1420 };
1421
1422 /* *** detach device by identifier *** */
1423 struct cmd_operate_detach_device_result {
1424         cmdline_fixed_string_t device;
1425         cmdline_fixed_string_t keyword;
1426         cmdline_fixed_string_t identifier;
1427 };
1428
1429 static void cmd_operate_detach_device_parsed(void *parsed_result,
1430                                 __rte_unused struct cmdline *cl,
1431                                 __rte_unused void *data)
1432 {
1433         struct cmd_operate_detach_device_result *res = parsed_result;
1434
1435         if (!strcmp(res->keyword, "detach"))
1436                 detach_devargs(res->identifier);
1437         else
1438                 printf("Unknown parameter\n");
1439 }
1440
1441 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1442         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1443                         device, "device");
1444 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1445         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1446                         keyword, "detach");
1447 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1448         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1449                         identifier, NULL);
1450
1451 cmdline_parse_inst_t cmd_operate_detach_device = {
1452         .f = cmd_operate_detach_device_parsed,
1453         .data = NULL,
1454         .help_str = "device detach <identifier>:"
1455                 "(identifier: pci address or virtual dev name)",
1456         .tokens = {
1457                 (void *)&cmd_operate_detach_device_device,
1458                 (void *)&cmd_operate_detach_device_keyword,
1459                 (void *)&cmd_operate_detach_device_identifier,
1460                 NULL,
1461         },
1462 };
1463 /* *** configure speed for all ports *** */
1464 struct cmd_config_speed_all {
1465         cmdline_fixed_string_t port;
1466         cmdline_fixed_string_t keyword;
1467         cmdline_fixed_string_t all;
1468         cmdline_fixed_string_t item1;
1469         cmdline_fixed_string_t item2;
1470         cmdline_fixed_string_t value1;
1471         cmdline_fixed_string_t value2;
1472 };
1473
1474 static int
1475 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1476 {
1477
1478         int duplex;
1479
1480         if (!strcmp(duplexstr, "half")) {
1481                 duplex = ETH_LINK_HALF_DUPLEX;
1482         } else if (!strcmp(duplexstr, "full")) {
1483                 duplex = ETH_LINK_FULL_DUPLEX;
1484         } else if (!strcmp(duplexstr, "auto")) {
1485                 duplex = ETH_LINK_FULL_DUPLEX;
1486         } else {
1487                 printf("Unknown duplex parameter\n");
1488                 return -1;
1489         }
1490
1491         if (!strcmp(speedstr, "10")) {
1492                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1493                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1494         } else if (!strcmp(speedstr, "100")) {
1495                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1496                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1497         } else {
1498                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1499                         printf("Invalid speed/duplex parameters\n");
1500                         return -1;
1501                 }
1502                 if (!strcmp(speedstr, "1000")) {
1503                         *speed = ETH_LINK_SPEED_1G;
1504                 } else if (!strcmp(speedstr, "10000")) {
1505                         *speed = ETH_LINK_SPEED_10G;
1506                 } else if (!strcmp(speedstr, "25000")) {
1507                         *speed = ETH_LINK_SPEED_25G;
1508                 } else if (!strcmp(speedstr, "40000")) {
1509                         *speed = ETH_LINK_SPEED_40G;
1510                 } else if (!strcmp(speedstr, "50000")) {
1511                         *speed = ETH_LINK_SPEED_50G;
1512                 } else if (!strcmp(speedstr, "100000")) {
1513                         *speed = ETH_LINK_SPEED_100G;
1514                 } else if (!strcmp(speedstr, "200000")) {
1515                         *speed = ETH_LINK_SPEED_200G;
1516                 } else if (!strcmp(speedstr, "auto")) {
1517                         *speed = ETH_LINK_SPEED_AUTONEG;
1518                 } else {
1519                         printf("Unknown speed parameter\n");
1520                         return -1;
1521                 }
1522         }
1523
1524         return 0;
1525 }
1526
1527 static void
1528 cmd_config_speed_all_parsed(void *parsed_result,
1529                         __rte_unused struct cmdline *cl,
1530                         __rte_unused void *data)
1531 {
1532         struct cmd_config_speed_all *res = parsed_result;
1533         uint32_t link_speed;
1534         portid_t pid;
1535
1536         if (!all_ports_stopped()) {
1537                 printf("Please stop all ports first\n");
1538                 return;
1539         }
1540
1541         if (parse_and_check_speed_duplex(res->value1, res->value2,
1542                         &link_speed) < 0)
1543                 return;
1544
1545         RTE_ETH_FOREACH_DEV(pid) {
1546                 ports[pid].dev_conf.link_speeds = link_speed;
1547         }
1548
1549         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1550 }
1551
1552 cmdline_parse_token_string_t cmd_config_speed_all_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1554 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1556                                                         "config");
1557 cmdline_parse_token_string_t cmd_config_speed_all_all =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1559 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1561 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1563                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1564 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1566 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1568                                                 "half#full#auto");
1569
1570 cmdline_parse_inst_t cmd_config_speed_all = {
1571         .f = cmd_config_speed_all_parsed,
1572         .data = NULL,
1573         .help_str = "port config all speed "
1574                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1575                                                         "half|full|auto",
1576         .tokens = {
1577                 (void *)&cmd_config_speed_all_port,
1578                 (void *)&cmd_config_speed_all_keyword,
1579                 (void *)&cmd_config_speed_all_all,
1580                 (void *)&cmd_config_speed_all_item1,
1581                 (void *)&cmd_config_speed_all_value1,
1582                 (void *)&cmd_config_speed_all_item2,
1583                 (void *)&cmd_config_speed_all_value2,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** configure speed for specific port *** */
1589 struct cmd_config_speed_specific {
1590         cmdline_fixed_string_t port;
1591         cmdline_fixed_string_t keyword;
1592         portid_t id;
1593         cmdline_fixed_string_t item1;
1594         cmdline_fixed_string_t item2;
1595         cmdline_fixed_string_t value1;
1596         cmdline_fixed_string_t value2;
1597 };
1598
1599 static void
1600 cmd_config_speed_specific_parsed(void *parsed_result,
1601                                 __rte_unused struct cmdline *cl,
1602                                 __rte_unused void *data)
1603 {
1604         struct cmd_config_speed_specific *res = parsed_result;
1605         uint32_t link_speed;
1606
1607         if (!all_ports_stopped()) {
1608                 printf("Please stop all ports first\n");
1609                 return;
1610         }
1611
1612         if (port_id_is_invalid(res->id, ENABLED_WARN))
1613                 return;
1614
1615         if (parse_and_check_speed_duplex(res->value1, res->value2,
1616                         &link_speed) < 0)
1617                 return;
1618
1619         ports[res->id].dev_conf.link_speeds = link_speed;
1620
1621         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1622 }
1623
1624
1625 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1627                                                                 "port");
1628 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1630                                                                 "config");
1631 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1633 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1635                                                                 "speed");
1636 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1638                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1639 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1641                                                                 "duplex");
1642 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1644                                                         "half#full#auto");
1645
1646 cmdline_parse_inst_t cmd_config_speed_specific = {
1647         .f = cmd_config_speed_specific_parsed,
1648         .data = NULL,
1649         .help_str = "port config <port_id> speed "
1650                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1651                                                         "half|full|auto",
1652         .tokens = {
1653                 (void *)&cmd_config_speed_specific_port,
1654                 (void *)&cmd_config_speed_specific_keyword,
1655                 (void *)&cmd_config_speed_specific_id,
1656                 (void *)&cmd_config_speed_specific_item1,
1657                 (void *)&cmd_config_speed_specific_value1,
1658                 (void *)&cmd_config_speed_specific_item2,
1659                 (void *)&cmd_config_speed_specific_value2,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure loopback for all ports *** */
1665 struct cmd_config_loopback_all {
1666         cmdline_fixed_string_t port;
1667         cmdline_fixed_string_t keyword;
1668         cmdline_fixed_string_t all;
1669         cmdline_fixed_string_t item;
1670         uint32_t mode;
1671 };
1672
1673 static void
1674 cmd_config_loopback_all_parsed(void *parsed_result,
1675                         __rte_unused struct cmdline *cl,
1676                         __rte_unused void *data)
1677 {
1678         struct cmd_config_loopback_all *res = parsed_result;
1679         portid_t pid;
1680
1681         if (!all_ports_stopped()) {
1682                 printf("Please stop all ports first\n");
1683                 return;
1684         }
1685
1686         RTE_ETH_FOREACH_DEV(pid) {
1687                 ports[pid].dev_conf.lpbk_mode = res->mode;
1688         }
1689
1690         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1691 }
1692
1693 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1695 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1697                                                         "config");
1698 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1700 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1702                                                         "loopback");
1703 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1704         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1705
1706 cmdline_parse_inst_t cmd_config_loopback_all = {
1707         .f = cmd_config_loopback_all_parsed,
1708         .data = NULL,
1709         .help_str = "port config all loopback <mode>",
1710         .tokens = {
1711                 (void *)&cmd_config_loopback_all_port,
1712                 (void *)&cmd_config_loopback_all_keyword,
1713                 (void *)&cmd_config_loopback_all_all,
1714                 (void *)&cmd_config_loopback_all_item,
1715                 (void *)&cmd_config_loopback_all_mode,
1716                 NULL,
1717         },
1718 };
1719
1720 /* *** configure loopback for specific port *** */
1721 struct cmd_config_loopback_specific {
1722         cmdline_fixed_string_t port;
1723         cmdline_fixed_string_t keyword;
1724         uint16_t port_id;
1725         cmdline_fixed_string_t item;
1726         uint32_t mode;
1727 };
1728
1729 static void
1730 cmd_config_loopback_specific_parsed(void *parsed_result,
1731                                 __rte_unused struct cmdline *cl,
1732                                 __rte_unused void *data)
1733 {
1734         struct cmd_config_loopback_specific *res = parsed_result;
1735
1736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1737                 return;
1738
1739         if (!port_is_stopped(res->port_id)) {
1740                 printf("Please stop port %u first\n", res->port_id);
1741                 return;
1742         }
1743
1744         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1745
1746         cmd_reconfig_device_queue(res->port_id, 1, 1);
1747 }
1748
1749
1750 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1751         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1752                                                                 "port");
1753 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1755                                                                 "config");
1756 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1757         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1758                                                                 RTE_UINT16);
1759 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1761                                                                 "loopback");
1762 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1763         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1764                               RTE_UINT32);
1765
1766 cmdline_parse_inst_t cmd_config_loopback_specific = {
1767         .f = cmd_config_loopback_specific_parsed,
1768         .data = NULL,
1769         .help_str = "port config <port_id> loopback <mode>",
1770         .tokens = {
1771                 (void *)&cmd_config_loopback_specific_port,
1772                 (void *)&cmd_config_loopback_specific_keyword,
1773                 (void *)&cmd_config_loopback_specific_id,
1774                 (void *)&cmd_config_loopback_specific_item,
1775                 (void *)&cmd_config_loopback_specific_mode,
1776                 NULL,
1777         },
1778 };
1779
1780 /* *** configure txq/rxq, txd/rxd *** */
1781 struct cmd_config_rx_tx {
1782         cmdline_fixed_string_t port;
1783         cmdline_fixed_string_t keyword;
1784         cmdline_fixed_string_t all;
1785         cmdline_fixed_string_t name;
1786         uint16_t value;
1787 };
1788
1789 static void
1790 cmd_config_rx_tx_parsed(void *parsed_result,
1791                         __rte_unused struct cmdline *cl,
1792                         __rte_unused void *data)
1793 {
1794         struct cmd_config_rx_tx *res = parsed_result;
1795
1796         if (!all_ports_stopped()) {
1797                 printf("Please stop all ports first\n");
1798                 return;
1799         }
1800         if (!strcmp(res->name, "rxq")) {
1801                 if (!res->value && !nb_txq) {
1802                         printf("Warning: Either rx or tx queues should be non zero\n");
1803                         return;
1804                 }
1805                 if (check_nb_rxq(res->value) != 0)
1806                         return;
1807                 nb_rxq = res->value;
1808         }
1809         else if (!strcmp(res->name, "txq")) {
1810                 if (!res->value && !nb_rxq) {
1811                         printf("Warning: Either rx or tx queues should be non zero\n");
1812                         return;
1813                 }
1814                 if (check_nb_txq(res->value) != 0)
1815                         return;
1816                 nb_txq = res->value;
1817         }
1818         else if (!strcmp(res->name, "rxd")) {
1819                 if (check_nb_rxd(res->value) != 0)
1820                         return;
1821                 nb_rxd = res->value;
1822         } else if (!strcmp(res->name, "txd")) {
1823                 if (check_nb_txd(res->value) != 0)
1824                         return;
1825
1826                 nb_txd = res->value;
1827         } else {
1828                 printf("Unknown parameter\n");
1829                 return;
1830         }
1831
1832         fwd_config_setup();
1833
1834         init_port_config();
1835
1836         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1837 }
1838
1839 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1841 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1843 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1847                                                 "rxq#txq#rxd#txd");
1848 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1850
1851 cmdline_parse_inst_t cmd_config_rx_tx = {
1852         .f = cmd_config_rx_tx_parsed,
1853         .data = NULL,
1854         .help_str = "port config all rxq|txq|rxd|txd <value>",
1855         .tokens = {
1856                 (void *)&cmd_config_rx_tx_port,
1857                 (void *)&cmd_config_rx_tx_keyword,
1858                 (void *)&cmd_config_rx_tx_all,
1859                 (void *)&cmd_config_rx_tx_name,
1860                 (void *)&cmd_config_rx_tx_value,
1861                 NULL,
1862         },
1863 };
1864
1865 /* *** config max packet length *** */
1866 struct cmd_config_max_pkt_len_result {
1867         cmdline_fixed_string_t port;
1868         cmdline_fixed_string_t keyword;
1869         cmdline_fixed_string_t all;
1870         cmdline_fixed_string_t name;
1871         uint32_t value;
1872 };
1873
1874 static void
1875 cmd_config_max_pkt_len_parsed(void *parsed_result,
1876                                 __rte_unused struct cmdline *cl,
1877                                 __rte_unused void *data)
1878 {
1879         struct cmd_config_max_pkt_len_result *res = parsed_result;
1880         uint32_t max_rx_pkt_len_backup = 0;
1881         portid_t pid;
1882         int ret;
1883
1884         if (!all_ports_stopped()) {
1885                 printf("Please stop all ports first\n");
1886                 return;
1887         }
1888
1889         RTE_ETH_FOREACH_DEV(pid) {
1890                 struct rte_port *port = &ports[pid];
1891
1892                 if (!strcmp(res->name, "max-pkt-len")) {
1893                         if (res->value < RTE_ETHER_MIN_LEN) {
1894                                 printf("max-pkt-len can not be less than %d\n",
1895                                                 RTE_ETHER_MIN_LEN);
1896                                 return;
1897                         }
1898                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1899                                 return;
1900
1901                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1902                         if (ret != 0) {
1903                                 printf("rte_eth_dev_info_get() failed for port %u\n",
1904                                         pid);
1905                                 return;
1906                         }
1907
1908                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1909
1910                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1911                         if (update_jumbo_frame_offload(pid) != 0)
1912                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1913                 } else {
1914                         printf("Unknown parameter\n");
1915                         return;
1916                 }
1917         }
1918
1919         init_port_config();
1920
1921         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1922 }
1923
1924 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1925         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1926                                                                 "port");
1927 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1929                                                                 "config");
1930 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1931         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1932                                                                 "all");
1933 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1934         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1935                                                                 "max-pkt-len");
1936 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1937         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1938                                                                 RTE_UINT32);
1939
1940 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1941         .f = cmd_config_max_pkt_len_parsed,
1942         .data = NULL,
1943         .help_str = "port config all max-pkt-len <value>",
1944         .tokens = {
1945                 (void *)&cmd_config_max_pkt_len_port,
1946                 (void *)&cmd_config_max_pkt_len_keyword,
1947                 (void *)&cmd_config_max_pkt_len_all,
1948                 (void *)&cmd_config_max_pkt_len_name,
1949                 (void *)&cmd_config_max_pkt_len_value,
1950                 NULL,
1951         },
1952 };
1953
1954 /* *** config max LRO aggregated packet size *** */
1955 struct cmd_config_max_lro_pkt_size_result {
1956         cmdline_fixed_string_t port;
1957         cmdline_fixed_string_t keyword;
1958         cmdline_fixed_string_t all;
1959         cmdline_fixed_string_t name;
1960         uint32_t value;
1961 };
1962
1963 static void
1964 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1965                                 __rte_unused struct cmdline *cl,
1966                                 __rte_unused void *data)
1967 {
1968         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1969         portid_t pid;
1970
1971         if (!all_ports_stopped()) {
1972                 printf("Please stop all ports first\n");
1973                 return;
1974         }
1975
1976         RTE_ETH_FOREACH_DEV(pid) {
1977                 struct rte_port *port = &ports[pid];
1978
1979                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1980                         if (res->value ==
1981                                         port->dev_conf.rxmode.max_lro_pkt_size)
1982                                 return;
1983
1984                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1985                 } else {
1986                         printf("Unknown parameter\n");
1987                         return;
1988                 }
1989         }
1990
1991         init_port_config();
1992
1993         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1994 }
1995
1996 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1997         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1998                                  port, "port");
1999 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2001                                  keyword, "config");
2002 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2003         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2004                                  all, "all");
2005 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2007                                  name, "max-lro-pkt-size");
2008 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2009         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2010                               value, RTE_UINT32);
2011
2012 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2013         .f = cmd_config_max_lro_pkt_size_parsed,
2014         .data = NULL,
2015         .help_str = "port config all max-lro-pkt-size <value>",
2016         .tokens = {
2017                 (void *)&cmd_config_max_lro_pkt_size_port,
2018                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2019                 (void *)&cmd_config_max_lro_pkt_size_all,
2020                 (void *)&cmd_config_max_lro_pkt_size_name,
2021                 (void *)&cmd_config_max_lro_pkt_size_value,
2022                 NULL,
2023         },
2024 };
2025
2026 /* *** configure port MTU *** */
2027 struct cmd_config_mtu_result {
2028         cmdline_fixed_string_t port;
2029         cmdline_fixed_string_t keyword;
2030         cmdline_fixed_string_t mtu;
2031         portid_t port_id;
2032         uint16_t value;
2033 };
2034
2035 static void
2036 cmd_config_mtu_parsed(void *parsed_result,
2037                       __rte_unused struct cmdline *cl,
2038                       __rte_unused void *data)
2039 {
2040         struct cmd_config_mtu_result *res = parsed_result;
2041
2042         if (res->value < RTE_ETHER_MIN_LEN) {
2043                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2044                 return;
2045         }
2046         port_mtu_set(res->port_id, res->value);
2047 }
2048
2049 cmdline_parse_token_string_t cmd_config_mtu_port =
2050         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2051                                  "port");
2052 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2054                                  "config");
2055 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2057                                  "mtu");
2058 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2059         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2060                                  RTE_UINT16);
2061 cmdline_parse_token_num_t cmd_config_mtu_value =
2062         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2063                                  RTE_UINT16);
2064
2065 cmdline_parse_inst_t cmd_config_mtu = {
2066         .f = cmd_config_mtu_parsed,
2067         .data = NULL,
2068         .help_str = "port config mtu <port_id> <value>",
2069         .tokens = {
2070                 (void *)&cmd_config_mtu_port,
2071                 (void *)&cmd_config_mtu_keyword,
2072                 (void *)&cmd_config_mtu_mtu,
2073                 (void *)&cmd_config_mtu_port_id,
2074                 (void *)&cmd_config_mtu_value,
2075                 NULL,
2076         },
2077 };
2078
2079 /* *** configure rx mode *** */
2080 struct cmd_config_rx_mode_flag {
2081         cmdline_fixed_string_t port;
2082         cmdline_fixed_string_t keyword;
2083         cmdline_fixed_string_t all;
2084         cmdline_fixed_string_t name;
2085         cmdline_fixed_string_t value;
2086 };
2087
2088 static void
2089 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2090                                 __rte_unused struct cmdline *cl,
2091                                 __rte_unused void *data)
2092 {
2093         struct cmd_config_rx_mode_flag *res = parsed_result;
2094
2095         if (!all_ports_stopped()) {
2096                 printf("Please stop all ports first\n");
2097                 return;
2098         }
2099
2100         if (!strcmp(res->name, "drop-en")) {
2101                 if (!strcmp(res->value, "on"))
2102                         rx_drop_en = 1;
2103                 else if (!strcmp(res->value, "off"))
2104                         rx_drop_en = 0;
2105                 else {
2106                         printf("Unknown parameter\n");
2107                         return;
2108                 }
2109         } else {
2110                 printf("Unknown parameter\n");
2111                 return;
2112         }
2113
2114         init_port_config();
2115
2116         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2117 }
2118
2119 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2121 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2122         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2123                                                                 "config");
2124 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2125         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2128                                         "drop-en");
2129 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2130         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2131                                                         "on#off");
2132
2133 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2134         .f = cmd_config_rx_mode_flag_parsed,
2135         .data = NULL,
2136         .help_str = "port config all drop-en on|off",
2137         .tokens = {
2138                 (void *)&cmd_config_rx_mode_flag_port,
2139                 (void *)&cmd_config_rx_mode_flag_keyword,
2140                 (void *)&cmd_config_rx_mode_flag_all,
2141                 (void *)&cmd_config_rx_mode_flag_name,
2142                 (void *)&cmd_config_rx_mode_flag_value,
2143                 NULL,
2144         },
2145 };
2146
2147 /* *** configure rss *** */
2148 struct cmd_config_rss {
2149         cmdline_fixed_string_t port;
2150         cmdline_fixed_string_t keyword;
2151         cmdline_fixed_string_t all;
2152         cmdline_fixed_string_t name;
2153         cmdline_fixed_string_t value;
2154 };
2155
2156 static void
2157 cmd_config_rss_parsed(void *parsed_result,
2158                         __rte_unused struct cmdline *cl,
2159                         __rte_unused void *data)
2160 {
2161         struct cmd_config_rss *res = parsed_result;
2162         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2163         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2164         int use_default = 0;
2165         int all_updated = 1;
2166         int diag;
2167         uint16_t i;
2168         int ret;
2169
2170         if (!strcmp(res->value, "all"))
2171                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2172                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2173                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2174                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2175                         ETH_RSS_ECPRI;
2176         else if (!strcmp(res->value, "eth"))
2177                 rss_conf.rss_hf = ETH_RSS_ETH;
2178         else if (!strcmp(res->value, "vlan"))
2179                 rss_conf.rss_hf = ETH_RSS_VLAN;
2180         else if (!strcmp(res->value, "ip"))
2181                 rss_conf.rss_hf = ETH_RSS_IP;
2182         else if (!strcmp(res->value, "udp"))
2183                 rss_conf.rss_hf = ETH_RSS_UDP;
2184         else if (!strcmp(res->value, "tcp"))
2185                 rss_conf.rss_hf = ETH_RSS_TCP;
2186         else if (!strcmp(res->value, "sctp"))
2187                 rss_conf.rss_hf = ETH_RSS_SCTP;
2188         else if (!strcmp(res->value, "ether"))
2189                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2190         else if (!strcmp(res->value, "port"))
2191                 rss_conf.rss_hf = ETH_RSS_PORT;
2192         else if (!strcmp(res->value, "vxlan"))
2193                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2194         else if (!strcmp(res->value, "geneve"))
2195                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2196         else if (!strcmp(res->value, "nvgre"))
2197                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2198         else if (!strcmp(res->value, "l3-pre32"))
2199                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2200         else if (!strcmp(res->value, "l3-pre40"))
2201                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2202         else if (!strcmp(res->value, "l3-pre48"))
2203                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2204         else if (!strcmp(res->value, "l3-pre56"))
2205                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2206         else if (!strcmp(res->value, "l3-pre64"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2208         else if (!strcmp(res->value, "l3-pre96"))
2209                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2210         else if (!strcmp(res->value, "l3-src-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2212         else if (!strcmp(res->value, "l3-dst-only"))
2213                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2214         else if (!strcmp(res->value, "l4-src-only"))
2215                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2216         else if (!strcmp(res->value, "l4-dst-only"))
2217                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2218         else if (!strcmp(res->value, "l2-src-only"))
2219                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2220         else if (!strcmp(res->value, "l2-dst-only"))
2221                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2222         else if (!strcmp(res->value, "l2tpv3"))
2223                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2224         else if (!strcmp(res->value, "esp"))
2225                 rss_conf.rss_hf = ETH_RSS_ESP;
2226         else if (!strcmp(res->value, "ah"))
2227                 rss_conf.rss_hf = ETH_RSS_AH;
2228         else if (!strcmp(res->value, "pfcp"))
2229                 rss_conf.rss_hf = ETH_RSS_PFCP;
2230         else if (!strcmp(res->value, "pppoe"))
2231                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2232         else if (!strcmp(res->value, "gtpu"))
2233                 rss_conf.rss_hf = ETH_RSS_GTPU;
2234         else if (!strcmp(res->value, "ecpri"))
2235                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2236         else if (!strcmp(res->value, "mpls"))
2237                 rss_conf.rss_hf = ETH_RSS_MPLS;
2238         else if (!strcmp(res->value, "none"))
2239                 rss_conf.rss_hf = 0;
2240         else if (!strcmp(res->value, "level-default")) {
2241                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2242                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2243         } else if (!strcmp(res->value, "level-outer")) {
2244                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2245                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2246         } else if (!strcmp(res->value, "level-inner")) {
2247                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2248                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2249         } else if (!strcmp(res->value, "default"))
2250                 use_default = 1;
2251         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2252                                                 atoi(res->value) < 64)
2253                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2254         else {
2255                 printf("Unknown parameter\n");
2256                 return;
2257         }
2258         rss_conf.rss_key = NULL;
2259         /* Update global configuration for RSS types. */
2260         RTE_ETH_FOREACH_DEV(i) {
2261                 struct rte_eth_rss_conf local_rss_conf;
2262
2263                 ret = eth_dev_info_get_print_err(i, &dev_info);
2264                 if (ret != 0)
2265                         return;
2266
2267                 if (use_default)
2268                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2269
2270                 local_rss_conf = rss_conf;
2271                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2272                         dev_info.flow_type_rss_offloads;
2273                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2274                         printf("Port %u modified RSS hash function based on hardware support,"
2275                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2276                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2277                 }
2278                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2279                 if (diag < 0) {
2280                         all_updated = 0;
2281                         printf("Configuration of RSS hash at ethernet port %d "
2282                                 "failed with error (%d): %s.\n",
2283                                 i, -diag, strerror(-diag));
2284                 }
2285         }
2286         if (all_updated && !use_default) {
2287                 rss_hf = rss_conf.rss_hf;
2288                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2289         }
2290 }
2291
2292 cmdline_parse_token_string_t cmd_config_rss_port =
2293         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2294 cmdline_parse_token_string_t cmd_config_rss_keyword =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2296 cmdline_parse_token_string_t cmd_config_rss_all =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2298 cmdline_parse_token_string_t cmd_config_rss_name =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2300 cmdline_parse_token_string_t cmd_config_rss_value =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2302
2303 cmdline_parse_inst_t cmd_config_rss = {
2304         .f = cmd_config_rss_parsed,
2305         .data = NULL,
2306         .help_str = "port config all rss "
2307                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2308                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2309                 "level-outer|level-inner|<flowtype_id>",
2310         .tokens = {
2311                 (void *)&cmd_config_rss_port,
2312                 (void *)&cmd_config_rss_keyword,
2313                 (void *)&cmd_config_rss_all,
2314                 (void *)&cmd_config_rss_name,
2315                 (void *)&cmd_config_rss_value,
2316                 NULL,
2317         },
2318 };
2319
2320 /* *** configure rss hash key *** */
2321 struct cmd_config_rss_hash_key {
2322         cmdline_fixed_string_t port;
2323         cmdline_fixed_string_t config;
2324         portid_t port_id;
2325         cmdline_fixed_string_t rss_hash_key;
2326         cmdline_fixed_string_t rss_type;
2327         cmdline_fixed_string_t key;
2328 };
2329
2330 static uint8_t
2331 hexa_digit_to_value(char hexa_digit)
2332 {
2333         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2334                 return (uint8_t) (hexa_digit - '0');
2335         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2336                 return (uint8_t) ((hexa_digit - 'a') + 10);
2337         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2338                 return (uint8_t) ((hexa_digit - 'A') + 10);
2339         /* Invalid hexa digit */
2340         return 0xFF;
2341 }
2342
2343 static uint8_t
2344 parse_and_check_key_hexa_digit(char *key, int idx)
2345 {
2346         uint8_t hexa_v;
2347
2348         hexa_v = hexa_digit_to_value(key[idx]);
2349         if (hexa_v == 0xFF)
2350                 printf("invalid key: character %c at position %d is not a "
2351                        "valid hexa digit\n", key[idx], idx);
2352         return hexa_v;
2353 }
2354
2355 static void
2356 cmd_config_rss_hash_key_parsed(void *parsed_result,
2357                                __rte_unused struct cmdline *cl,
2358                                __rte_unused void *data)
2359 {
2360         struct cmd_config_rss_hash_key *res = parsed_result;
2361         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2362         uint8_t xdgt0;
2363         uint8_t xdgt1;
2364         int i;
2365         struct rte_eth_dev_info dev_info;
2366         uint8_t hash_key_size;
2367         uint32_t key_len;
2368         int ret;
2369
2370         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2371         if (ret != 0)
2372                 return;
2373
2374         if (dev_info.hash_key_size > 0 &&
2375                         dev_info.hash_key_size <= sizeof(hash_key))
2376                 hash_key_size = dev_info.hash_key_size;
2377         else {
2378                 printf("dev_info did not provide a valid hash key size\n");
2379                 return;
2380         }
2381         /* Check the length of the RSS hash key */
2382         key_len = strlen(res->key);
2383         if (key_len != (hash_key_size * 2)) {
2384                 printf("key length: %d invalid - key must be a string of %d"
2385                            " hexa-decimal numbers\n",
2386                            (int) key_len, hash_key_size * 2);
2387                 return;
2388         }
2389         /* Translate RSS hash key into binary representation */
2390         for (i = 0; i < hash_key_size; i++) {
2391                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2392                 if (xdgt0 == 0xFF)
2393                         return;
2394                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2395                 if (xdgt1 == 0xFF)
2396                         return;
2397                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2398         }
2399         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2400                         hash_key_size);
2401 }
2402
2403 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2404         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2405 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2407                                  "config");
2408 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2409         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2410                                  RTE_UINT16);
2411 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2413                                  rss_hash_key, "rss-hash-key");
2414 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2415         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2416                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2417                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2418                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2419                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2420                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2421                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2422                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri");
2423 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2424         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2425
2426 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2427         .f = cmd_config_rss_hash_key_parsed,
2428         .data = NULL,
2429         .help_str = "port config <port_id> rss-hash-key "
2430                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2431                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2432                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2433                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2434                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2435                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri "
2436                 "<string of hex digits (variable length, NIC dependent)>",
2437         .tokens = {
2438                 (void *)&cmd_config_rss_hash_key_port,
2439                 (void *)&cmd_config_rss_hash_key_config,
2440                 (void *)&cmd_config_rss_hash_key_port_id,
2441                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2442                 (void *)&cmd_config_rss_hash_key_rss_type,
2443                 (void *)&cmd_config_rss_hash_key_value,
2444                 NULL,
2445         },
2446 };
2447
2448 /* *** configure port rxq/txq ring size *** */
2449 struct cmd_config_rxtx_ring_size {
2450         cmdline_fixed_string_t port;
2451         cmdline_fixed_string_t config;
2452         portid_t portid;
2453         cmdline_fixed_string_t rxtxq;
2454         uint16_t qid;
2455         cmdline_fixed_string_t rsize;
2456         uint16_t size;
2457 };
2458
2459 static void
2460 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2461                                  __rte_unused struct cmdline *cl,
2462                                  __rte_unused void *data)
2463 {
2464         struct cmd_config_rxtx_ring_size *res = parsed_result;
2465         struct rte_port *port;
2466         uint8_t isrx;
2467
2468         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2469                 return;
2470
2471         if (res->portid == (portid_t)RTE_PORT_ALL) {
2472                 printf("Invalid port id\n");
2473                 return;
2474         }
2475
2476         port = &ports[res->portid];
2477
2478         if (!strcmp(res->rxtxq, "rxq"))
2479                 isrx = 1;
2480         else if (!strcmp(res->rxtxq, "txq"))
2481                 isrx = 0;
2482         else {
2483                 printf("Unknown parameter\n");
2484                 return;
2485         }
2486
2487         if (isrx && rx_queue_id_is_invalid(res->qid))
2488                 return;
2489         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2490                 return;
2491
2492         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2493                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2494                        rx_free_thresh);
2495                 return;
2496         }
2497
2498         if (isrx)
2499                 port->nb_rx_desc[res->qid] = res->size;
2500         else
2501                 port->nb_tx_desc[res->qid] = res->size;
2502
2503         cmd_reconfig_device_queue(res->portid, 0, 1);
2504 }
2505
2506 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2508                                  port, "port");
2509 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2510         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                                  config, "config");
2512 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2513         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2514                                  portid, RTE_UINT16);
2515 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2516         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2517                                  rxtxq, "rxq#txq");
2518 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2519         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2520                               qid, RTE_UINT16);
2521 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2522         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2523                                  rsize, "ring_size");
2524 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2525         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2526                               size, RTE_UINT16);
2527
2528 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2529         .f = cmd_config_rxtx_ring_size_parsed,
2530         .data = NULL,
2531         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2532         .tokens = {
2533                 (void *)&cmd_config_rxtx_ring_size_port,
2534                 (void *)&cmd_config_rxtx_ring_size_config,
2535                 (void *)&cmd_config_rxtx_ring_size_portid,
2536                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2537                 (void *)&cmd_config_rxtx_ring_size_qid,
2538                 (void *)&cmd_config_rxtx_ring_size_rsize,
2539                 (void *)&cmd_config_rxtx_ring_size_size,
2540                 NULL,
2541         },
2542 };
2543
2544 /* *** configure port rxq/txq start/stop *** */
2545 struct cmd_config_rxtx_queue {
2546         cmdline_fixed_string_t port;
2547         portid_t portid;
2548         cmdline_fixed_string_t rxtxq;
2549         uint16_t qid;
2550         cmdline_fixed_string_t opname;
2551 };
2552
2553 static void
2554 cmd_config_rxtx_queue_parsed(void *parsed_result,
2555                         __rte_unused struct cmdline *cl,
2556                         __rte_unused void *data)
2557 {
2558         struct cmd_config_rxtx_queue *res = parsed_result;
2559         uint8_t isrx;
2560         uint8_t isstart;
2561         int ret = 0;
2562
2563         if (test_done == 0) {
2564                 printf("Please stop forwarding first\n");
2565                 return;
2566         }
2567
2568         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2569                 return;
2570
2571         if (port_is_started(res->portid) != 1) {
2572                 printf("Please start port %u first\n", res->portid);
2573                 return;
2574         }
2575
2576         if (!strcmp(res->rxtxq, "rxq"))
2577                 isrx = 1;
2578         else if (!strcmp(res->rxtxq, "txq"))
2579                 isrx = 0;
2580         else {
2581                 printf("Unknown parameter\n");
2582                 return;
2583         }
2584
2585         if (isrx && rx_queue_id_is_invalid(res->qid))
2586                 return;
2587         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2588                 return;
2589
2590         if (!strcmp(res->opname, "start"))
2591                 isstart = 1;
2592         else if (!strcmp(res->opname, "stop"))
2593                 isstart = 0;
2594         else {
2595                 printf("Unknown parameter\n");
2596                 return;
2597         }
2598
2599         if (isstart && isrx)
2600                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2601         else if (!isstart && isrx)
2602                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2603         else if (isstart && !isrx)
2604                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2605         else
2606                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2607
2608         if (ret == -ENOTSUP)
2609                 printf("Function not supported in PMD driver\n");
2610 }
2611
2612 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2613         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2614 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2615         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2616 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2617         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2618 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2619         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2620 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2621         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2622                                                 "start#stop");
2623
2624 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2625         .f = cmd_config_rxtx_queue_parsed,
2626         .data = NULL,
2627         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2628         .tokens = {
2629                 (void *)&cmd_config_rxtx_queue_port,
2630                 (void *)&cmd_config_rxtx_queue_portid,
2631                 (void *)&cmd_config_rxtx_queue_rxtxq,
2632                 (void *)&cmd_config_rxtx_queue_qid,
2633                 (void *)&cmd_config_rxtx_queue_opname,
2634                 NULL,
2635         },
2636 };
2637
2638 /* *** configure port rxq/txq deferred start on/off *** */
2639 struct cmd_config_deferred_start_rxtx_queue {
2640         cmdline_fixed_string_t port;
2641         portid_t port_id;
2642         cmdline_fixed_string_t rxtxq;
2643         uint16_t qid;
2644         cmdline_fixed_string_t opname;
2645         cmdline_fixed_string_t state;
2646 };
2647
2648 static void
2649 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2650                         __rte_unused struct cmdline *cl,
2651                         __rte_unused void *data)
2652 {
2653         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2654         struct rte_port *port;
2655         uint8_t isrx;
2656         uint8_t ison;
2657         uint8_t needreconfig = 0;
2658
2659         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2660                 return;
2661
2662         if (port_is_started(res->port_id) != 0) {
2663                 printf("Please stop port %u first\n", res->port_id);
2664                 return;
2665         }
2666
2667         port = &ports[res->port_id];
2668
2669         isrx = !strcmp(res->rxtxq, "rxq");
2670
2671         if (isrx && rx_queue_id_is_invalid(res->qid))
2672                 return;
2673         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2674                 return;
2675
2676         ison = !strcmp(res->state, "on");
2677
2678         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2679                 port->rx_conf[res->qid].rx_deferred_start = ison;
2680                 needreconfig = 1;
2681         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2682                 port->tx_conf[res->qid].tx_deferred_start = ison;
2683                 needreconfig = 1;
2684         }
2685
2686         if (needreconfig)
2687                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2688 }
2689
2690 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2692                                                 port, "port");
2693 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2694         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2695                                                 port_id, RTE_UINT16);
2696 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2697         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2698                                                 rxtxq, "rxq#txq");
2699 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2700         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2701                                                 qid, RTE_UINT16);
2702 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2703         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2704                                                 opname, "deferred_start");
2705 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2706         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2707                                                 state, "on#off");
2708
2709 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2710         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2711         .data = NULL,
2712         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2713         .tokens = {
2714                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2715                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2716                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2717                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2718                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2719                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2720                 NULL,
2721         },
2722 };
2723
2724 /* *** configure port rxq/txq setup *** */
2725 struct cmd_setup_rxtx_queue {
2726         cmdline_fixed_string_t port;
2727         portid_t portid;
2728         cmdline_fixed_string_t rxtxq;
2729         uint16_t qid;
2730         cmdline_fixed_string_t setup;
2731 };
2732
2733 /* Common CLI fields for queue setup */
2734 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2735         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2736 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2737         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2738 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2739         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2740 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2741         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2742 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2743         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2744
2745 static void
2746 cmd_setup_rxtx_queue_parsed(
2747         void *parsed_result,
2748         __rte_unused struct cmdline *cl,
2749         __rte_unused void *data)
2750 {
2751         struct cmd_setup_rxtx_queue *res = parsed_result;
2752         struct rte_port *port;
2753         struct rte_mempool *mp;
2754         unsigned int socket_id;
2755         uint8_t isrx = 0;
2756         int ret;
2757
2758         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2759                 return;
2760
2761         if (res->portid == (portid_t)RTE_PORT_ALL) {
2762                 printf("Invalid port id\n");
2763                 return;
2764         }
2765
2766         if (!strcmp(res->rxtxq, "rxq"))
2767                 isrx = 1;
2768         else if (!strcmp(res->rxtxq, "txq"))
2769                 isrx = 0;
2770         else {
2771                 printf("Unknown parameter\n");
2772                 return;
2773         }
2774
2775         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2776                 printf("Invalid rx queue\n");
2777                 return;
2778         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2779                 printf("Invalid tx queue\n");
2780                 return;
2781         }
2782
2783         port = &ports[res->portid];
2784         if (isrx) {
2785                 socket_id = rxring_numa[res->portid];
2786                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2787                         socket_id = port->socket_id;
2788
2789                 mp = mbuf_pool_find(socket_id, 0);
2790                 if (mp == NULL) {
2791                         printf("Failed to setup RX queue: "
2792                                 "No mempool allocation"
2793                                 " on the socket %d\n",
2794                                 rxring_numa[res->portid]);
2795                         return;
2796                 }
2797                 ret = rx_queue_setup(res->portid,
2798                                      res->qid,
2799                                      port->nb_rx_desc[res->qid],
2800                                      socket_id,
2801                                      &port->rx_conf[res->qid],
2802                                      mp);
2803                 if (ret)
2804                         printf("Failed to setup RX queue\n");
2805         } else {
2806                 socket_id = txring_numa[res->portid];
2807                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2808                         socket_id = port->socket_id;
2809
2810                 ret = rte_eth_tx_queue_setup(res->portid,
2811                                              res->qid,
2812                                              port->nb_tx_desc[res->qid],
2813                                              socket_id,
2814                                              &port->tx_conf[res->qid]);
2815                 if (ret)
2816                         printf("Failed to setup TX queue\n");
2817         }
2818 }
2819
2820 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2821         .f = cmd_setup_rxtx_queue_parsed,
2822         .data = NULL,
2823         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2824         .tokens = {
2825                 (void *)&cmd_setup_rxtx_queue_port,
2826                 (void *)&cmd_setup_rxtx_queue_portid,
2827                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2828                 (void *)&cmd_setup_rxtx_queue_qid,
2829                 (void *)&cmd_setup_rxtx_queue_setup,
2830                 NULL,
2831         },
2832 };
2833
2834
2835 /* *** Configure RSS RETA *** */
2836 struct cmd_config_rss_reta {
2837         cmdline_fixed_string_t port;
2838         cmdline_fixed_string_t keyword;
2839         portid_t port_id;
2840         cmdline_fixed_string_t name;
2841         cmdline_fixed_string_t list_name;
2842         cmdline_fixed_string_t list_of_items;
2843 };
2844
2845 static int
2846 parse_reta_config(const char *str,
2847                   struct rte_eth_rss_reta_entry64 *reta_conf,
2848                   uint16_t nb_entries)
2849 {
2850         int i;
2851         unsigned size;
2852         uint16_t hash_index, idx, shift;
2853         uint16_t nb_queue;
2854         char s[256];
2855         const char *p, *p0 = str;
2856         char *end;
2857         enum fieldnames {
2858                 FLD_HASH_INDEX = 0,
2859                 FLD_QUEUE,
2860                 _NUM_FLD
2861         };
2862         unsigned long int_fld[_NUM_FLD];
2863         char *str_fld[_NUM_FLD];
2864
2865         while ((p = strchr(p0,'(')) != NULL) {
2866                 ++p;
2867                 if((p0 = strchr(p,')')) == NULL)
2868                         return -1;
2869
2870                 size = p0 - p;
2871                 if(size >= sizeof(s))
2872                         return -1;
2873
2874                 snprintf(s, sizeof(s), "%.*s", size, p);
2875                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2876                         return -1;
2877                 for (i = 0; i < _NUM_FLD; i++) {
2878                         errno = 0;
2879                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2880                         if (errno != 0 || end == str_fld[i] ||
2881                                         int_fld[i] > 65535)
2882                                 return -1;
2883                 }
2884
2885                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2886                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2887
2888                 if (hash_index >= nb_entries) {
2889                         printf("Invalid RETA hash index=%d\n", hash_index);
2890                         return -1;
2891                 }
2892
2893                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2894                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2895                 reta_conf[idx].mask |= (1ULL << shift);
2896                 reta_conf[idx].reta[shift] = nb_queue;
2897         }
2898
2899         return 0;
2900 }
2901
2902 static void
2903 cmd_set_rss_reta_parsed(void *parsed_result,
2904                         __rte_unused struct cmdline *cl,
2905                         __rte_unused void *data)
2906 {
2907         int ret;
2908         struct rte_eth_dev_info dev_info;
2909         struct rte_eth_rss_reta_entry64 reta_conf[8];
2910         struct cmd_config_rss_reta *res = parsed_result;
2911
2912         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2913         if (ret != 0)
2914                 return;
2915
2916         if (dev_info.reta_size == 0) {
2917                 printf("Redirection table size is 0 which is "
2918                                         "invalid for RSS\n");
2919                 return;
2920         } else
2921                 printf("The reta size of port %d is %u\n",
2922                         res->port_id, dev_info.reta_size);
2923         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2924                 printf("Currently do not support more than %u entries of "
2925                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2926                 return;
2927         }
2928
2929         memset(reta_conf, 0, sizeof(reta_conf));
2930         if (!strcmp(res->list_name, "reta")) {
2931                 if (parse_reta_config(res->list_of_items, reta_conf,
2932                                                 dev_info.reta_size)) {
2933                         printf("Invalid RSS Redirection Table "
2934                                         "config entered\n");
2935                         return;
2936                 }
2937                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2938                                 reta_conf, dev_info.reta_size);
2939                 if (ret != 0)
2940                         printf("Bad redirection table parameter, "
2941                                         "return code = %d \n", ret);
2942         }
2943 }
2944
2945 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2946         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2947 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2948         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2949 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2950         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2951 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2952         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2953 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2954         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2955 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2956         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2957                                  NULL);
2958 cmdline_parse_inst_t cmd_config_rss_reta = {
2959         .f = cmd_set_rss_reta_parsed,
2960         .data = NULL,
2961         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2962         .tokens = {
2963                 (void *)&cmd_config_rss_reta_port,
2964                 (void *)&cmd_config_rss_reta_keyword,
2965                 (void *)&cmd_config_rss_reta_port_id,
2966                 (void *)&cmd_config_rss_reta_name,
2967                 (void *)&cmd_config_rss_reta_list_name,
2968                 (void *)&cmd_config_rss_reta_list_of_items,
2969                 NULL,
2970         },
2971 };
2972
2973 /* *** SHOW PORT RETA INFO *** */
2974 struct cmd_showport_reta {
2975         cmdline_fixed_string_t show;
2976         cmdline_fixed_string_t port;
2977         portid_t port_id;
2978         cmdline_fixed_string_t rss;
2979         cmdline_fixed_string_t reta;
2980         uint16_t size;
2981         cmdline_fixed_string_t list_of_items;
2982 };
2983
2984 static int
2985 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2986                            uint16_t nb_entries,
2987                            char *str)
2988 {
2989         uint32_t size;
2990         const char *p, *p0 = str;
2991         char s[256];
2992         char *end;
2993         char *str_fld[8];
2994         uint16_t i;
2995         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2996                         RTE_RETA_GROUP_SIZE;
2997         int ret;
2998
2999         p = strchr(p0, '(');
3000         if (p == NULL)
3001                 return -1;
3002         p++;
3003         p0 = strchr(p, ')');
3004         if (p0 == NULL)
3005                 return -1;
3006         size = p0 - p;
3007         if (size >= sizeof(s)) {
3008                 printf("The string size exceeds the internal buffer size\n");
3009                 return -1;
3010         }
3011         snprintf(s, sizeof(s), "%.*s", size, p);
3012         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3013         if (ret <= 0 || ret != num) {
3014                 printf("The bits of masks do not match the number of "
3015                                         "reta entries: %u\n", num);
3016                 return -1;
3017         }
3018         for (i = 0; i < ret; i++)
3019                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3020
3021         return 0;
3022 }
3023
3024 static void
3025 cmd_showport_reta_parsed(void *parsed_result,
3026                          __rte_unused struct cmdline *cl,
3027                          __rte_unused void *data)
3028 {
3029         struct cmd_showport_reta *res = parsed_result;
3030         struct rte_eth_rss_reta_entry64 reta_conf[8];
3031         struct rte_eth_dev_info dev_info;
3032         uint16_t max_reta_size;
3033         int ret;
3034
3035         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3036         if (ret != 0)
3037                 return;
3038
3039         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3040         if (res->size == 0 || res->size > max_reta_size) {
3041                 printf("Invalid redirection table size: %u (1-%u)\n",
3042                         res->size, max_reta_size);
3043                 return;
3044         }
3045
3046         memset(reta_conf, 0, sizeof(reta_conf));
3047         if (showport_parse_reta_config(reta_conf, res->size,
3048                                 res->list_of_items) < 0) {
3049                 printf("Invalid string: %s for reta masks\n",
3050                                         res->list_of_items);
3051                 return;
3052         }
3053         port_rss_reta_info(res->port_id, reta_conf, res->size);
3054 }
3055
3056 cmdline_parse_token_string_t cmd_showport_reta_show =
3057         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3058 cmdline_parse_token_string_t cmd_showport_reta_port =
3059         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3060 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3061         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3062 cmdline_parse_token_string_t cmd_showport_reta_rss =
3063         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3064 cmdline_parse_token_string_t cmd_showport_reta_reta =
3065         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3066 cmdline_parse_token_num_t cmd_showport_reta_size =
3067         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3068 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3069         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3070                                         list_of_items, NULL);
3071
3072 cmdline_parse_inst_t cmd_showport_reta = {
3073         .f = cmd_showport_reta_parsed,
3074         .data = NULL,
3075         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3076         .tokens = {
3077                 (void *)&cmd_showport_reta_show,
3078                 (void *)&cmd_showport_reta_port,
3079                 (void *)&cmd_showport_reta_port_id,
3080                 (void *)&cmd_showport_reta_rss,
3081                 (void *)&cmd_showport_reta_reta,
3082                 (void *)&cmd_showport_reta_size,
3083                 (void *)&cmd_showport_reta_list_of_items,
3084                 NULL,
3085         },
3086 };
3087
3088 /* *** Show RSS hash configuration *** */
3089 struct cmd_showport_rss_hash {
3090         cmdline_fixed_string_t show;
3091         cmdline_fixed_string_t port;
3092         portid_t port_id;
3093         cmdline_fixed_string_t rss_hash;
3094         cmdline_fixed_string_t rss_type;
3095         cmdline_fixed_string_t key; /* optional argument */
3096 };
3097
3098 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3099                                 __rte_unused struct cmdline *cl,
3100                                 void *show_rss_key)
3101 {
3102         struct cmd_showport_rss_hash *res = parsed_result;
3103
3104         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3105 }
3106
3107 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3108         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3109 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3110         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3111 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3112         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3113                                  RTE_UINT16);
3114 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3115         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3116                                  "rss-hash");
3117 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3118         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3119
3120 cmdline_parse_inst_t cmd_showport_rss_hash = {
3121         .f = cmd_showport_rss_hash_parsed,
3122         .data = NULL,
3123         .help_str = "show port <port_id> rss-hash",
3124         .tokens = {
3125                 (void *)&cmd_showport_rss_hash_show,
3126                 (void *)&cmd_showport_rss_hash_port,
3127                 (void *)&cmd_showport_rss_hash_port_id,
3128                 (void *)&cmd_showport_rss_hash_rss_hash,
3129                 NULL,
3130         },
3131 };
3132
3133 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3134         .f = cmd_showport_rss_hash_parsed,
3135         .data = (void *)1,
3136         .help_str = "show port <port_id> rss-hash key",
3137         .tokens = {
3138                 (void *)&cmd_showport_rss_hash_show,
3139                 (void *)&cmd_showport_rss_hash_port,
3140                 (void *)&cmd_showport_rss_hash_port_id,
3141                 (void *)&cmd_showport_rss_hash_rss_hash,
3142                 (void *)&cmd_showport_rss_hash_rss_key,
3143                 NULL,
3144         },
3145 };
3146
3147 /* *** Configure DCB *** */
3148 struct cmd_config_dcb {
3149         cmdline_fixed_string_t port;
3150         cmdline_fixed_string_t config;
3151         portid_t port_id;
3152         cmdline_fixed_string_t dcb;
3153         cmdline_fixed_string_t vt;
3154         cmdline_fixed_string_t vt_en;
3155         uint8_t num_tcs;
3156         cmdline_fixed_string_t pfc;
3157         cmdline_fixed_string_t pfc_en;
3158 };
3159
3160 static void
3161 cmd_config_dcb_parsed(void *parsed_result,
3162                         __rte_unused struct cmdline *cl,
3163                         __rte_unused void *data)
3164 {
3165         struct cmd_config_dcb *res = parsed_result;
3166         portid_t port_id = res->port_id;
3167         struct rte_port *port;
3168         uint8_t pfc_en;
3169         int ret;
3170
3171         port = &ports[port_id];
3172         /** Check if the port is not started **/
3173         if (port->port_status != RTE_PORT_STOPPED) {
3174                 printf("Please stop port %d first\n", port_id);
3175                 return;
3176         }
3177
3178         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3179                 printf("The invalid number of traffic class,"
3180                         " only 4 or 8 allowed.\n");
3181                 return;
3182         }
3183
3184         if (nb_fwd_lcores < res->num_tcs) {
3185                 printf("nb_cores shouldn't be less than number of TCs.\n");
3186                 return;
3187         }
3188         if (!strncmp(res->pfc_en, "on", 2))
3189                 pfc_en = 1;
3190         else
3191                 pfc_en = 0;
3192
3193         /* DCB in VT mode */
3194         if (!strncmp(res->vt_en, "on", 2))
3195                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3196                                 (enum rte_eth_nb_tcs)res->num_tcs,
3197                                 pfc_en);
3198         else
3199                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3200                                 (enum rte_eth_nb_tcs)res->num_tcs,
3201                                 pfc_en);
3202
3203
3204         if (ret != 0) {
3205                 printf("Cannot initialize network ports.\n");
3206                 return;
3207         }
3208
3209         cmd_reconfig_device_queue(port_id, 1, 1);
3210 }
3211
3212 cmdline_parse_token_string_t cmd_config_dcb_port =
3213         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3214 cmdline_parse_token_string_t cmd_config_dcb_config =
3215         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3216 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3217         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3218 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3219         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3220 cmdline_parse_token_string_t cmd_config_dcb_vt =
3221         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3222 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3223         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3224 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3225         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3226 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3227         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3228 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3229         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3230
3231 cmdline_parse_inst_t cmd_config_dcb = {
3232         .f = cmd_config_dcb_parsed,
3233         .data = NULL,
3234         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3235         .tokens = {
3236                 (void *)&cmd_config_dcb_port,
3237                 (void *)&cmd_config_dcb_config,
3238                 (void *)&cmd_config_dcb_port_id,
3239                 (void *)&cmd_config_dcb_dcb,
3240                 (void *)&cmd_config_dcb_vt,
3241                 (void *)&cmd_config_dcb_vt_en,
3242                 (void *)&cmd_config_dcb_num_tcs,
3243                 (void *)&cmd_config_dcb_pfc,
3244                 (void *)&cmd_config_dcb_pfc_en,
3245                 NULL,
3246         },
3247 };
3248
3249 /* *** configure number of packets per burst *** */
3250 struct cmd_config_burst {
3251         cmdline_fixed_string_t port;
3252         cmdline_fixed_string_t keyword;
3253         cmdline_fixed_string_t all;
3254         cmdline_fixed_string_t name;
3255         uint16_t value;
3256 };
3257
3258 static void
3259 cmd_config_burst_parsed(void *parsed_result,
3260                         __rte_unused struct cmdline *cl,
3261                         __rte_unused void *data)
3262 {
3263         struct cmd_config_burst *res = parsed_result;
3264         struct rte_eth_dev_info dev_info;
3265         uint16_t rec_nb_pkts;
3266         int ret;
3267
3268         if (!all_ports_stopped()) {
3269                 printf("Please stop all ports first\n");
3270                 return;
3271         }
3272
3273         if (!strcmp(res->name, "burst")) {
3274                 if (res->value == 0) {
3275                         /* If user gives a value of zero, query the PMD for
3276                          * its recommended Rx burst size. Testpmd uses a single
3277                          * size for all ports, so assume all ports are the same
3278                          * NIC model and use the values from Port 0.
3279                          */
3280                         ret = eth_dev_info_get_print_err(0, &dev_info);
3281                         if (ret != 0)
3282                                 return;
3283
3284                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3285
3286                         if (rec_nb_pkts == 0) {
3287                                 printf("PMD does not recommend a burst size.\n"
3288                                         "User provided value must be between"
3289                                         " 1 and %d\n", MAX_PKT_BURST);
3290                                 return;
3291                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3292                                 printf("PMD recommended burst size of %d"
3293                                         " exceeds maximum value of %d\n",
3294                                         rec_nb_pkts, MAX_PKT_BURST);
3295                                 return;
3296                         }
3297                         printf("Using PMD-provided burst value of %d\n",
3298                                 rec_nb_pkts);
3299                         nb_pkt_per_burst = rec_nb_pkts;
3300                 } else if (res->value > MAX_PKT_BURST) {
3301                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3302                         return;
3303                 } else
3304                         nb_pkt_per_burst = res->value;
3305         } else {
3306                 printf("Unknown parameter\n");
3307                 return;
3308         }
3309
3310         init_port_config();
3311
3312         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3313 }
3314
3315 cmdline_parse_token_string_t cmd_config_burst_port =
3316         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3317 cmdline_parse_token_string_t cmd_config_burst_keyword =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3319 cmdline_parse_token_string_t cmd_config_burst_all =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3321 cmdline_parse_token_string_t cmd_config_burst_name =
3322         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3323 cmdline_parse_token_num_t cmd_config_burst_value =
3324         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3325
3326 cmdline_parse_inst_t cmd_config_burst = {
3327         .f = cmd_config_burst_parsed,
3328         .data = NULL,
3329         .help_str = "port config all burst <value>",
3330         .tokens = {
3331                 (void *)&cmd_config_burst_port,
3332                 (void *)&cmd_config_burst_keyword,
3333                 (void *)&cmd_config_burst_all,
3334                 (void *)&cmd_config_burst_name,
3335                 (void *)&cmd_config_burst_value,
3336                 NULL,
3337         },
3338 };
3339
3340 /* *** configure rx/tx queues *** */
3341 struct cmd_config_thresh {
3342         cmdline_fixed_string_t port;
3343         cmdline_fixed_string_t keyword;
3344         cmdline_fixed_string_t all;
3345         cmdline_fixed_string_t name;
3346         uint8_t value;
3347 };
3348
3349 static void
3350 cmd_config_thresh_parsed(void *parsed_result,
3351                         __rte_unused struct cmdline *cl,
3352                         __rte_unused void *data)
3353 {
3354         struct cmd_config_thresh *res = parsed_result;
3355
3356         if (!all_ports_stopped()) {
3357                 printf("Please stop all ports first\n");
3358                 return;
3359         }
3360
3361         if (!strcmp(res->name, "txpt"))
3362                 tx_pthresh = res->value;
3363         else if(!strcmp(res->name, "txht"))
3364                 tx_hthresh = res->value;
3365         else if(!strcmp(res->name, "txwt"))
3366                 tx_wthresh = res->value;
3367         else if(!strcmp(res->name, "rxpt"))
3368                 rx_pthresh = res->value;
3369         else if(!strcmp(res->name, "rxht"))
3370                 rx_hthresh = res->value;
3371         else if(!strcmp(res->name, "rxwt"))
3372                 rx_wthresh = res->value;
3373         else {
3374                 printf("Unknown parameter\n");
3375                 return;
3376         }
3377
3378         init_port_config();
3379
3380         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3381 }
3382
3383 cmdline_parse_token_string_t cmd_config_thresh_port =
3384         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3385 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3386         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3387 cmdline_parse_token_string_t cmd_config_thresh_all =
3388         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3389 cmdline_parse_token_string_t cmd_config_thresh_name =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3391                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3392 cmdline_parse_token_num_t cmd_config_thresh_value =
3393         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3394
3395 cmdline_parse_inst_t cmd_config_thresh = {
3396         .f = cmd_config_thresh_parsed,
3397         .data = NULL,
3398         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3399         .tokens = {
3400                 (void *)&cmd_config_thresh_port,
3401                 (void *)&cmd_config_thresh_keyword,
3402                 (void *)&cmd_config_thresh_all,
3403                 (void *)&cmd_config_thresh_name,
3404                 (void *)&cmd_config_thresh_value,
3405                 NULL,
3406         },
3407 };
3408
3409 /* *** configure free/rs threshold *** */
3410 struct cmd_config_threshold {
3411         cmdline_fixed_string_t port;
3412         cmdline_fixed_string_t keyword;
3413         cmdline_fixed_string_t all;
3414         cmdline_fixed_string_t name;
3415         uint16_t value;
3416 };
3417
3418 static void
3419 cmd_config_threshold_parsed(void *parsed_result,
3420                         __rte_unused struct cmdline *cl,
3421                         __rte_unused void *data)
3422 {
3423         struct cmd_config_threshold *res = parsed_result;
3424
3425         if (!all_ports_stopped()) {
3426                 printf("Please stop all ports first\n");
3427                 return;
3428         }
3429
3430         if (!strcmp(res->name, "txfreet"))
3431                 tx_free_thresh = res->value;
3432         else if (!strcmp(res->name, "txrst"))
3433                 tx_rs_thresh = res->value;
3434         else if (!strcmp(res->name, "rxfreet"))
3435                 rx_free_thresh = res->value;
3436         else {
3437                 printf("Unknown parameter\n");
3438                 return;
3439         }
3440
3441         init_port_config();
3442
3443         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3444 }
3445
3446 cmdline_parse_token_string_t cmd_config_threshold_port =
3447         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3448 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3449         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3450                                                                 "config");
3451 cmdline_parse_token_string_t cmd_config_threshold_all =
3452         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3453 cmdline_parse_token_string_t cmd_config_threshold_name =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3455                                                 "txfreet#txrst#rxfreet");
3456 cmdline_parse_token_num_t cmd_config_threshold_value =
3457         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3458
3459 cmdline_parse_inst_t cmd_config_threshold = {
3460         .f = cmd_config_threshold_parsed,
3461         .data = NULL,
3462         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3463         .tokens = {
3464                 (void *)&cmd_config_threshold_port,
3465                 (void *)&cmd_config_threshold_keyword,
3466                 (void *)&cmd_config_threshold_all,
3467                 (void *)&cmd_config_threshold_name,
3468                 (void *)&cmd_config_threshold_value,
3469                 NULL,
3470         },
3471 };
3472
3473 /* *** stop *** */
3474 struct cmd_stop_result {
3475         cmdline_fixed_string_t stop;
3476 };
3477
3478 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3479                             __rte_unused struct cmdline *cl,
3480                             __rte_unused void *data)
3481 {
3482         stop_packet_forwarding();
3483 }
3484
3485 cmdline_parse_token_string_t cmd_stop_stop =
3486         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3487
3488 cmdline_parse_inst_t cmd_stop = {
3489         .f = cmd_stop_parsed,
3490         .data = NULL,
3491         .help_str = "stop: Stop packet forwarding",
3492         .tokens = {
3493                 (void *)&cmd_stop_stop,
3494                 NULL,
3495         },
3496 };
3497
3498 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3499
3500 unsigned int
3501 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3502                 unsigned int *parsed_items, int check_unique_values)
3503 {
3504         unsigned int nb_item;
3505         unsigned int value;
3506         unsigned int i;
3507         unsigned int j;
3508         int value_ok;
3509         char c;
3510
3511         /*
3512          * First parse all items in the list and store their value.
3513          */
3514         value = 0;
3515         nb_item = 0;
3516         value_ok = 0;
3517         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3518                 c = str[i];
3519                 if ((c >= '0') && (c <= '9')) {
3520                         value = (unsigned int) (value * 10 + (c - '0'));
3521                         value_ok = 1;
3522                         continue;
3523                 }
3524                 if (c != ',') {
3525                         printf("character %c is not a decimal digit\n", c);
3526                         return 0;
3527                 }
3528                 if (! value_ok) {
3529                         printf("No valid value before comma\n");
3530                         return 0;
3531                 }
3532                 if (nb_item < max_items) {
3533                         parsed_items[nb_item] = value;
3534                         value_ok = 0;
3535                         value = 0;
3536                 }
3537                 nb_item++;
3538         }
3539         if (nb_item >= max_items) {
3540                 printf("Number of %s = %u > %u (maximum items)\n",
3541                        item_name, nb_item + 1, max_items);
3542                 return 0;
3543         }
3544         parsed_items[nb_item++] = value;
3545         if (! check_unique_values)
3546                 return nb_item;
3547
3548         /*
3549          * Then, check that all values in the list are differents.
3550          * No optimization here...
3551          */
3552         for (i = 0; i < nb_item; i++) {
3553                 for (j = i + 1; j < nb_item; j++) {
3554                         if (parsed_items[j] == parsed_items[i]) {
3555                                 printf("duplicated %s %u at index %u and %u\n",
3556                                        item_name, parsed_items[i], i, j);
3557                                 return 0;
3558                         }
3559                 }
3560         }
3561         return nb_item;
3562 }
3563
3564 struct cmd_set_list_result {
3565         cmdline_fixed_string_t cmd_keyword;
3566         cmdline_fixed_string_t list_name;
3567         cmdline_fixed_string_t list_of_items;
3568 };
3569
3570 static void cmd_set_list_parsed(void *parsed_result,
3571                                 __rte_unused struct cmdline *cl,
3572                                 __rte_unused void *data)
3573 {
3574         struct cmd_set_list_result *res;
3575         union {
3576                 unsigned int lcorelist[RTE_MAX_LCORE];
3577                 unsigned int portlist[RTE_MAX_ETHPORTS];
3578         } parsed_items;
3579         unsigned int nb_item;
3580
3581         if (test_done == 0) {
3582                 printf("Please stop forwarding first\n");
3583                 return;
3584         }
3585
3586         res = parsed_result;
3587         if (!strcmp(res->list_name, "corelist")) {
3588                 nb_item = parse_item_list(res->list_of_items, "core",
3589                                           RTE_MAX_LCORE,
3590                                           parsed_items.lcorelist, 1);
3591                 if (nb_item > 0) {
3592                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3593                         fwd_config_setup();
3594                 }
3595                 return;
3596         }
3597         if (!strcmp(res->list_name, "portlist")) {
3598                 nb_item = parse_item_list(res->list_of_items, "port",
3599                                           RTE_MAX_ETHPORTS,
3600                                           parsed_items.portlist, 1);
3601                 if (nb_item > 0) {
3602                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3603                         fwd_config_setup();
3604                 }
3605         }
3606 }
3607
3608 cmdline_parse_token_string_t cmd_set_list_keyword =
3609         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3610                                  "set");
3611 cmdline_parse_token_string_t cmd_set_list_name =
3612         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3613                                  "corelist#portlist");
3614 cmdline_parse_token_string_t cmd_set_list_of_items =
3615         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3616                                  NULL);
3617
3618 cmdline_parse_inst_t cmd_set_fwd_list = {
3619         .f = cmd_set_list_parsed,
3620         .data = NULL,
3621         .help_str = "set corelist|portlist <list0[,list1]*>",
3622         .tokens = {
3623                 (void *)&cmd_set_list_keyword,
3624                 (void *)&cmd_set_list_name,
3625                 (void *)&cmd_set_list_of_items,
3626                 NULL,
3627         },
3628 };
3629
3630 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3631
3632 struct cmd_setmask_result {
3633         cmdline_fixed_string_t set;
3634         cmdline_fixed_string_t mask;
3635         uint64_t hexavalue;
3636 };
3637
3638 static void cmd_set_mask_parsed(void *parsed_result,
3639                                 __rte_unused struct cmdline *cl,
3640                                 __rte_unused void *data)
3641 {
3642         struct cmd_setmask_result *res = parsed_result;
3643
3644         if (test_done == 0) {
3645                 printf("Please stop forwarding first\n");
3646                 return;
3647         }
3648         if (!strcmp(res->mask, "coremask")) {
3649                 set_fwd_lcores_mask(res->hexavalue);
3650                 fwd_config_setup();
3651         } else if (!strcmp(res->mask, "portmask")) {
3652                 set_fwd_ports_mask(res->hexavalue);
3653                 fwd_config_setup();
3654         }
3655 }
3656
3657 cmdline_parse_token_string_t cmd_setmask_set =
3658         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3659 cmdline_parse_token_string_t cmd_setmask_mask =
3660         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3661                                  "coremask#portmask");
3662 cmdline_parse_token_num_t cmd_setmask_value =
3663         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3664
3665 cmdline_parse_inst_t cmd_set_fwd_mask = {
3666         .f = cmd_set_mask_parsed,
3667         .data = NULL,
3668         .help_str = "set coremask|portmask <hexadecimal value>",
3669         .tokens = {
3670                 (void *)&cmd_setmask_set,
3671                 (void *)&cmd_setmask_mask,
3672                 (void *)&cmd_setmask_value,
3673                 NULL,
3674         },
3675 };
3676
3677 /*
3678  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3679  */
3680 struct cmd_set_result {
3681         cmdline_fixed_string_t set;
3682         cmdline_fixed_string_t what;
3683         uint16_t value;
3684 };
3685
3686 static void cmd_set_parsed(void *parsed_result,
3687                            __rte_unused struct cmdline *cl,
3688                            __rte_unused void *data)
3689 {
3690         struct cmd_set_result *res = parsed_result;
3691         if (!strcmp(res->what, "nbport")) {
3692                 set_fwd_ports_number(res->value);
3693                 fwd_config_setup();
3694         } else if (!strcmp(res->what, "nbcore")) {
3695                 set_fwd_lcores_number(res->value);
3696                 fwd_config_setup();
3697         } else if (!strcmp(res->what, "burst"))
3698                 set_nb_pkt_per_burst(res->value);
3699         else if (!strcmp(res->what, "verbose"))
3700                 set_verbose_level(res->value);
3701 }
3702
3703 cmdline_parse_token_string_t cmd_set_set =
3704         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3705 cmdline_parse_token_string_t cmd_set_what =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3707                                  "nbport#nbcore#burst#verbose");
3708 cmdline_parse_token_num_t cmd_set_value =
3709         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3710
3711 cmdline_parse_inst_t cmd_set_numbers = {
3712         .f = cmd_set_parsed,
3713         .data = NULL,
3714         .help_str = "set nbport|nbcore|burst|verbose <value>",
3715         .tokens = {
3716                 (void *)&cmd_set_set,
3717                 (void *)&cmd_set_what,
3718                 (void *)&cmd_set_value,
3719                 NULL,
3720         },
3721 };
3722
3723 /* *** SET LOG LEVEL CONFIGURATION *** */
3724
3725 struct cmd_set_log_result {
3726         cmdline_fixed_string_t set;
3727         cmdline_fixed_string_t log;
3728         cmdline_fixed_string_t type;
3729         uint32_t level;
3730 };
3731
3732 static void
3733 cmd_set_log_parsed(void *parsed_result,
3734                    __rte_unused struct cmdline *cl,
3735                    __rte_unused void *data)
3736 {
3737         struct cmd_set_log_result *res;
3738         int ret;
3739
3740         res = parsed_result;
3741         if (!strcmp(res->type, "global"))
3742                 rte_log_set_global_level(res->level);
3743         else {
3744                 ret = rte_log_set_level_regexp(res->type, res->level);
3745                 if (ret < 0)
3746                         printf("Unable to set log level\n");
3747         }
3748 }
3749
3750 cmdline_parse_token_string_t cmd_set_log_set =
3751         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3752 cmdline_parse_token_string_t cmd_set_log_log =
3753         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3754 cmdline_parse_token_string_t cmd_set_log_type =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3756 cmdline_parse_token_num_t cmd_set_log_level =
3757         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3758
3759 cmdline_parse_inst_t cmd_set_log = {
3760         .f = cmd_set_log_parsed,
3761         .data = NULL,
3762         .help_str = "set log global|<type> <level>",
3763         .tokens = {
3764                 (void *)&cmd_set_log_set,
3765                 (void *)&cmd_set_log_log,
3766                 (void *)&cmd_set_log_type,
3767                 (void *)&cmd_set_log_level,
3768                 NULL,
3769         },
3770 };
3771
3772 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3773
3774 struct cmd_set_rxoffs_result {
3775         cmdline_fixed_string_t cmd_keyword;
3776         cmdline_fixed_string_t rxoffs;
3777         cmdline_fixed_string_t seg_offsets;
3778 };
3779
3780 static void
3781 cmd_set_rxoffs_parsed(void *parsed_result,
3782                       __rte_unused struct cmdline *cl,
3783                       __rte_unused void *data)
3784 {
3785         struct cmd_set_rxoffs_result *res;
3786         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3787         unsigned int nb_segs;
3788
3789         res = parsed_result;
3790         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3791                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3792         if (nb_segs > 0)
3793                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3794 }
3795
3796 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3797         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3798                                  cmd_keyword, "set");
3799 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3800         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3801                                  rxoffs, "rxoffs");
3802 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3803         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3804                                  seg_offsets, NULL);
3805
3806 cmdline_parse_inst_t cmd_set_rxoffs = {
3807         .f = cmd_set_rxoffs_parsed,
3808         .data = NULL,
3809         .help_str = "set rxoffs <len0[,len1]*>",
3810         .tokens = {
3811                 (void *)&cmd_set_rxoffs_keyword,
3812                 (void *)&cmd_set_rxoffs_name,
3813                 (void *)&cmd_set_rxoffs_offsets,
3814                 NULL,
3815         },
3816 };
3817
3818 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3819
3820 struct cmd_set_rxpkts_result {
3821         cmdline_fixed_string_t cmd_keyword;
3822         cmdline_fixed_string_t rxpkts;
3823         cmdline_fixed_string_t seg_lengths;
3824 };
3825
3826 static void
3827 cmd_set_rxpkts_parsed(void *parsed_result,
3828                       __rte_unused struct cmdline *cl,
3829                       __rte_unused void *data)
3830 {
3831         struct cmd_set_rxpkts_result *res;
3832         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3833         unsigned int nb_segs;
3834
3835         res = parsed_result;
3836         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3837                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3838         if (nb_segs > 0)
3839                 set_rx_pkt_segments(seg_lengths, nb_segs);
3840 }
3841
3842 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3843         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3844                                  cmd_keyword, "set");
3845 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3846         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3847                                  rxpkts, "rxpkts");
3848 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3849         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3850                                  seg_lengths, NULL);
3851
3852 cmdline_parse_inst_t cmd_set_rxpkts = {
3853         .f = cmd_set_rxpkts_parsed,
3854         .data = NULL,
3855         .help_str = "set rxpkts <len0[,len1]*>",
3856         .tokens = {
3857                 (void *)&cmd_set_rxpkts_keyword,
3858                 (void *)&cmd_set_rxpkts_name,
3859                 (void *)&cmd_set_rxpkts_lengths,
3860                 NULL,
3861         },
3862 };
3863
3864 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3865
3866 struct cmd_set_txpkts_result {
3867         cmdline_fixed_string_t cmd_keyword;
3868         cmdline_fixed_string_t txpkts;
3869         cmdline_fixed_string_t seg_lengths;
3870 };
3871
3872 static void
3873 cmd_set_txpkts_parsed(void *parsed_result,
3874                       __rte_unused struct cmdline *cl,
3875                       __rte_unused void *data)
3876 {
3877         struct cmd_set_txpkts_result *res;
3878         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3879         unsigned int nb_segs;
3880
3881         res = parsed_result;
3882         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3883                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3884         if (nb_segs > 0)
3885                 set_tx_pkt_segments(seg_lengths, nb_segs);
3886 }
3887
3888 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3889         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3890                                  cmd_keyword, "set");
3891 cmdline_parse_token_string_t cmd_set_txpkts_name =
3892         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3893                                  txpkts, "txpkts");
3894 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3895         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3896                                  seg_lengths, NULL);
3897
3898 cmdline_parse_inst_t cmd_set_txpkts = {
3899         .f = cmd_set_txpkts_parsed,
3900         .data = NULL,
3901         .help_str = "set txpkts <len0[,len1]*>",
3902         .tokens = {
3903                 (void *)&cmd_set_txpkts_keyword,
3904                 (void *)&cmd_set_txpkts_name,
3905                 (void *)&cmd_set_txpkts_lengths,
3906                 NULL,
3907         },
3908 };
3909
3910 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3911
3912 struct cmd_set_txsplit_result {
3913         cmdline_fixed_string_t cmd_keyword;
3914         cmdline_fixed_string_t txsplit;
3915         cmdline_fixed_string_t mode;
3916 };
3917
3918 static void
3919 cmd_set_txsplit_parsed(void *parsed_result,
3920                       __rte_unused struct cmdline *cl,
3921                       __rte_unused void *data)
3922 {
3923         struct cmd_set_txsplit_result *res;
3924
3925         res = parsed_result;
3926         set_tx_pkt_split(res->mode);
3927 }
3928
3929 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3930         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3931                                  cmd_keyword, "set");
3932 cmdline_parse_token_string_t cmd_set_txsplit_name =
3933         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3934                                  txsplit, "txsplit");
3935 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3936         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3937                                  mode, NULL);
3938
3939 cmdline_parse_inst_t cmd_set_txsplit = {
3940         .f = cmd_set_txsplit_parsed,
3941         .data = NULL,
3942         .help_str = "set txsplit on|off|rand",
3943         .tokens = {
3944                 (void *)&cmd_set_txsplit_keyword,
3945                 (void *)&cmd_set_txsplit_name,
3946                 (void *)&cmd_set_txsplit_mode,
3947                 NULL,
3948         },
3949 };
3950
3951 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3952
3953 struct cmd_set_txtimes_result {
3954         cmdline_fixed_string_t cmd_keyword;
3955         cmdline_fixed_string_t txtimes;
3956         cmdline_fixed_string_t tx_times;
3957 };
3958
3959 static void
3960 cmd_set_txtimes_parsed(void *parsed_result,
3961                        __rte_unused struct cmdline *cl,
3962                        __rte_unused void *data)
3963 {
3964         struct cmd_set_txtimes_result *res;
3965         unsigned int tx_times[2] = {0, 0};
3966         unsigned int n_times;
3967
3968         res = parsed_result;
3969         n_times = parse_item_list(res->tx_times, "tx times",
3970                                   2, tx_times, 0);
3971         if (n_times == 2)
3972                 set_tx_pkt_times(tx_times);
3973 }
3974
3975 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3976         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3977                                  cmd_keyword, "set");
3978 cmdline_parse_token_string_t cmd_set_txtimes_name =
3979         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3980                                  txtimes, "txtimes");
3981 cmdline_parse_token_string_t cmd_set_txtimes_value =
3982         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3983                                  tx_times, NULL);
3984
3985 cmdline_parse_inst_t cmd_set_txtimes = {
3986         .f = cmd_set_txtimes_parsed,
3987         .data = NULL,
3988         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3989         .tokens = {
3990                 (void *)&cmd_set_txtimes_keyword,
3991                 (void *)&cmd_set_txtimes_name,
3992                 (void *)&cmd_set_txtimes_value,
3993                 NULL,
3994         },
3995 };
3996
3997 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3998 struct cmd_rx_vlan_filter_all_result {
3999         cmdline_fixed_string_t rx_vlan;
4000         cmdline_fixed_string_t what;
4001         cmdline_fixed_string_t all;
4002         portid_t port_id;
4003 };
4004
4005 static void
4006 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4007                               __rte_unused struct cmdline *cl,
4008                               __rte_unused void *data)
4009 {
4010         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4011
4012         if (!strcmp(res->what, "add"))
4013                 rx_vlan_all_filter_set(res->port_id, 1);
4014         else
4015                 rx_vlan_all_filter_set(res->port_id, 0);
4016 }
4017
4018 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4019         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4020                                  rx_vlan, "rx_vlan");
4021 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4022         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4023                                  what, "add#rm");
4024 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4025         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4026                                  all, "all");
4027 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4028         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4029                               port_id, RTE_UINT16);
4030
4031 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4032         .f = cmd_rx_vlan_filter_all_parsed,
4033         .data = NULL,
4034         .help_str = "rx_vlan add|rm all <port_id>: "
4035                 "Add/Remove all identifiers to/from the set of VLAN "
4036                 "identifiers filtered by a port",
4037         .tokens = {
4038                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4039                 (void *)&cmd_rx_vlan_filter_all_what,
4040                 (void *)&cmd_rx_vlan_filter_all_all,
4041                 (void *)&cmd_rx_vlan_filter_all_portid,
4042                 NULL,
4043         },
4044 };
4045
4046 /* *** VLAN OFFLOAD SET ON A PORT *** */
4047 struct cmd_vlan_offload_result {
4048         cmdline_fixed_string_t vlan;
4049         cmdline_fixed_string_t set;
4050         cmdline_fixed_string_t vlan_type;
4051         cmdline_fixed_string_t what;
4052         cmdline_fixed_string_t on;
4053         cmdline_fixed_string_t port_id;
4054 };
4055
4056 static void
4057 cmd_vlan_offload_parsed(void *parsed_result,
4058                           __rte_unused struct cmdline *cl,
4059                           __rte_unused void *data)
4060 {
4061         int on;
4062         struct cmd_vlan_offload_result *res = parsed_result;
4063         char *str;
4064         int i, len = 0;
4065         portid_t port_id = 0;
4066         unsigned int tmp;
4067
4068         str = res->port_id;
4069         len = strnlen(str, STR_TOKEN_SIZE);
4070         i = 0;
4071         /* Get port_id first */
4072         while(i < len){
4073                 if(str[i] == ',')
4074                         break;
4075
4076                 i++;
4077         }
4078         str[i]='\0';
4079         tmp = strtoul(str, NULL, 0);
4080         /* If port_id greater that what portid_t can represent, return */
4081         if(tmp >= RTE_MAX_ETHPORTS)
4082                 return;
4083         port_id = (portid_t)tmp;
4084
4085         if (!strcmp(res->on, "on"))
4086                 on = 1;
4087         else
4088                 on = 0;
4089
4090         if (!strcmp(res->what, "strip"))
4091                 rx_vlan_strip_set(port_id,  on);
4092         else if(!strcmp(res->what, "stripq")){
4093                 uint16_t queue_id = 0;
4094
4095                 /* No queue_id, return */
4096                 if(i + 1 >= len) {
4097                         printf("must specify (port,queue_id)\n");
4098                         return;
4099                 }
4100                 tmp = strtoul(str + i + 1, NULL, 0);
4101                 /* If queue_id greater that what 16-bits can represent, return */
4102                 if(tmp > 0xffff)
4103                         return;
4104
4105                 queue_id = (uint16_t)tmp;
4106                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4107         }
4108         else if (!strcmp(res->what, "filter"))
4109                 rx_vlan_filter_set(port_id, on);
4110         else if (!strcmp(res->what, "qinq_strip"))
4111                 rx_vlan_qinq_strip_set(port_id, on);
4112         else
4113                 vlan_extend_set(port_id, on);
4114
4115         return;
4116 }
4117
4118 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4119         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4120                                  vlan, "vlan");
4121 cmdline_parse_token_string_t cmd_vlan_offload_set =
4122         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4123                                  set, "set");
4124 cmdline_parse_token_string_t cmd_vlan_offload_what =
4125         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4126                                 what, "strip#filter#qinq_strip#extend#stripq");
4127 cmdline_parse_token_string_t cmd_vlan_offload_on =
4128         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4129                               on, "on#off");
4130 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4131         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4132                               port_id, NULL);
4133
4134 cmdline_parse_inst_t cmd_vlan_offload = {
4135         .f = cmd_vlan_offload_parsed,
4136         .data = NULL,
4137         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4138                 "<port_id[,queue_id]>: "
4139                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4140         .tokens = {
4141                 (void *)&cmd_vlan_offload_vlan,
4142                 (void *)&cmd_vlan_offload_set,
4143                 (void *)&cmd_vlan_offload_what,
4144                 (void *)&cmd_vlan_offload_on,
4145                 (void *)&cmd_vlan_offload_portid,
4146                 NULL,
4147         },
4148 };
4149
4150 /* *** VLAN TPID SET ON A PORT *** */
4151 struct cmd_vlan_tpid_result {
4152         cmdline_fixed_string_t vlan;
4153         cmdline_fixed_string_t set;
4154         cmdline_fixed_string_t vlan_type;
4155         cmdline_fixed_string_t what;
4156         uint16_t tp_id;
4157         portid_t port_id;
4158 };
4159
4160 static void
4161 cmd_vlan_tpid_parsed(void *parsed_result,
4162                           __rte_unused struct cmdline *cl,
4163                           __rte_unused void *data)
4164 {
4165         struct cmd_vlan_tpid_result *res = parsed_result;
4166         enum rte_vlan_type vlan_type;
4167
4168         if (!strcmp(res->vlan_type, "inner"))
4169                 vlan_type = ETH_VLAN_TYPE_INNER;
4170         else if (!strcmp(res->vlan_type, "outer"))
4171                 vlan_type = ETH_VLAN_TYPE_OUTER;
4172         else {
4173                 printf("Unknown vlan type\n");
4174                 return;
4175         }
4176         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4177 }
4178
4179 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4180         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4181                                  vlan, "vlan");
4182 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4183         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4184                                  set, "set");
4185 cmdline_parse_token_string_t cmd_vlan_type =
4186         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4187                                  vlan_type, "inner#outer");
4188 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4189         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4190                                  what, "tpid");
4191 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4192         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4193                               tp_id, RTE_UINT16);
4194 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4195         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4196                               port_id, RTE_UINT16);
4197
4198 cmdline_parse_inst_t cmd_vlan_tpid = {
4199         .f = cmd_vlan_tpid_parsed,
4200         .data = NULL,
4201         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4202                 "Set the VLAN Ether type",
4203         .tokens = {
4204                 (void *)&cmd_vlan_tpid_vlan,
4205                 (void *)&cmd_vlan_tpid_set,
4206                 (void *)&cmd_vlan_type,
4207                 (void *)&cmd_vlan_tpid_what,
4208                 (void *)&cmd_vlan_tpid_tpid,
4209                 (void *)&cmd_vlan_tpid_portid,
4210                 NULL,
4211         },
4212 };
4213
4214 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4215 struct cmd_rx_vlan_filter_result {
4216         cmdline_fixed_string_t rx_vlan;
4217         cmdline_fixed_string_t what;
4218         uint16_t vlan_id;
4219         portid_t port_id;
4220 };
4221
4222 static void
4223 cmd_rx_vlan_filter_parsed(void *parsed_result,
4224                           __rte_unused struct cmdline *cl,
4225                           __rte_unused void *data)
4226 {
4227         struct cmd_rx_vlan_filter_result *res = parsed_result;
4228
4229         if (!strcmp(res->what, "add"))
4230                 rx_vft_set(res->port_id, res->vlan_id, 1);
4231         else
4232                 rx_vft_set(res->port_id, res->vlan_id, 0);
4233 }
4234
4235 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4236         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4237                                  rx_vlan, "rx_vlan");
4238 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4239         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4240                                  what, "add#rm");
4241 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4242         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4243                               vlan_id, RTE_UINT16);
4244 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4245         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4246                               port_id, RTE_UINT16);
4247
4248 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4249         .f = cmd_rx_vlan_filter_parsed,
4250         .data = NULL,
4251         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4252                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4253                 "identifiers filtered by a port",
4254         .tokens = {
4255                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4256                 (void *)&cmd_rx_vlan_filter_what,
4257                 (void *)&cmd_rx_vlan_filter_vlanid,
4258                 (void *)&cmd_rx_vlan_filter_portid,
4259                 NULL,
4260         },
4261 };
4262
4263 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4264 struct cmd_tx_vlan_set_result {
4265         cmdline_fixed_string_t tx_vlan;
4266         cmdline_fixed_string_t set;
4267         portid_t port_id;
4268         uint16_t vlan_id;
4269 };
4270
4271 static void
4272 cmd_tx_vlan_set_parsed(void *parsed_result,
4273                        __rte_unused struct cmdline *cl,
4274                        __rte_unused void *data)
4275 {
4276         struct cmd_tx_vlan_set_result *res = parsed_result;
4277
4278         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4279                 return;
4280
4281         if (!port_is_stopped(res->port_id)) {
4282                 printf("Please stop port %d first\n", res->port_id);
4283                 return;
4284         }
4285
4286         tx_vlan_set(res->port_id, res->vlan_id);
4287
4288         cmd_reconfig_device_queue(res->port_id, 1, 1);
4289 }
4290
4291 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4292         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4293                                  tx_vlan, "tx_vlan");
4294 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4295         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4296                                  set, "set");
4297 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4298         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4299                               port_id, RTE_UINT16);
4300 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4301         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4302                               vlan_id, RTE_UINT16);
4303
4304 cmdline_parse_inst_t cmd_tx_vlan_set = {
4305         .f = cmd_tx_vlan_set_parsed,
4306         .data = NULL,
4307         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4308                 "Enable hardware insertion of a single VLAN header "
4309                 "with a given TAG Identifier in packets sent on a port",
4310         .tokens = {
4311                 (void *)&cmd_tx_vlan_set_tx_vlan,
4312                 (void *)&cmd_tx_vlan_set_set,
4313                 (void *)&cmd_tx_vlan_set_portid,
4314                 (void *)&cmd_tx_vlan_set_vlanid,
4315                 NULL,
4316         },
4317 };
4318
4319 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4320 struct cmd_tx_vlan_set_qinq_result {
4321         cmdline_fixed_string_t tx_vlan;
4322         cmdline_fixed_string_t set;
4323         portid_t port_id;
4324         uint16_t vlan_id;
4325         uint16_t vlan_id_outer;
4326 };
4327
4328 static void
4329 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4330                             __rte_unused struct cmdline *cl,
4331                             __rte_unused void *data)
4332 {
4333         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4334
4335         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4336                 return;
4337
4338         if (!port_is_stopped(res->port_id)) {
4339                 printf("Please stop port %d first\n", res->port_id);
4340                 return;
4341         }
4342
4343         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4344
4345         cmd_reconfig_device_queue(res->port_id, 1, 1);
4346 }
4347
4348 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4349         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4350                 tx_vlan, "tx_vlan");
4351 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4352         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4353                 set, "set");
4354 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4355         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4356                 port_id, RTE_UINT16);
4357 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4358         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4359                 vlan_id, RTE_UINT16);
4360 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4361         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4362                 vlan_id_outer, RTE_UINT16);
4363
4364 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4365         .f = cmd_tx_vlan_set_qinq_parsed,
4366         .data = NULL,
4367         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4368                 "Enable hardware insertion of double VLAN header "
4369                 "with given TAG Identifiers in packets sent on a port",
4370         .tokens = {
4371                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4372                 (void *)&cmd_tx_vlan_set_qinq_set,
4373                 (void *)&cmd_tx_vlan_set_qinq_portid,
4374                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4375                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4376                 NULL,
4377         },
4378 };
4379
4380 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4381 struct cmd_tx_vlan_set_pvid_result {
4382         cmdline_fixed_string_t tx_vlan;
4383         cmdline_fixed_string_t set;
4384         cmdline_fixed_string_t pvid;
4385         portid_t port_id;
4386         uint16_t vlan_id;
4387         cmdline_fixed_string_t mode;
4388 };
4389
4390 static void
4391 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4392                             __rte_unused struct cmdline *cl,
4393                             __rte_unused void *data)
4394 {
4395         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4396
4397         if (strcmp(res->mode, "on") == 0)
4398                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4399         else
4400                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4401 }
4402
4403 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4404         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4405                                  tx_vlan, "tx_vlan");
4406 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4407         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4408                                  set, "set");
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4411                                  pvid, "pvid");
4412 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4413         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4414                              port_id, RTE_UINT16);
4415 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4416         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4417                               vlan_id, RTE_UINT16);
4418 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4419         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4420                                  mode, "on#off");
4421
4422 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4423         .f = cmd_tx_vlan_set_pvid_parsed,
4424         .data = NULL,
4425         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4426         .tokens = {
4427                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4428                 (void *)&cmd_tx_vlan_set_pvid_set,
4429                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4430                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4431                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4432                 (void *)&cmd_tx_vlan_set_pvid_mode,
4433                 NULL,
4434         },
4435 };
4436
4437 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4438 struct cmd_tx_vlan_reset_result {
4439         cmdline_fixed_string_t tx_vlan;
4440         cmdline_fixed_string_t reset;
4441         portid_t port_id;
4442 };
4443
4444 static void
4445 cmd_tx_vlan_reset_parsed(void *parsed_result,
4446                          __rte_unused struct cmdline *cl,
4447                          __rte_unused void *data)
4448 {
4449         struct cmd_tx_vlan_reset_result *res = parsed_result;
4450
4451         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4452                 return;
4453
4454         if (!port_is_stopped(res->port_id)) {
4455                 printf("Please stop port %d first\n", res->port_id);
4456                 return;
4457         }
4458
4459         tx_vlan_reset(res->port_id);
4460
4461         cmd_reconfig_device_queue(res->port_id, 1, 1);
4462 }
4463
4464 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4465         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4466                                  tx_vlan, "tx_vlan");
4467 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4468         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4469                                  reset, "reset");
4470 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4471         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4472                               port_id, RTE_UINT16);
4473
4474 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4475         .f = cmd_tx_vlan_reset_parsed,
4476         .data = NULL,
4477         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4478                 "VLAN header in packets sent on a port",
4479         .tokens = {
4480                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4481                 (void *)&cmd_tx_vlan_reset_reset,
4482                 (void *)&cmd_tx_vlan_reset_portid,
4483                 NULL,
4484         },
4485 };
4486
4487
4488 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4489 struct cmd_csum_result {
4490         cmdline_fixed_string_t csum;
4491         cmdline_fixed_string_t mode;
4492         cmdline_fixed_string_t proto;
4493         cmdline_fixed_string_t hwsw;
4494         portid_t port_id;
4495 };
4496
4497 static void
4498 csum_show(int port_id)
4499 {
4500         struct rte_eth_dev_info dev_info;
4501         uint64_t tx_offloads;
4502         int ret;
4503
4504         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4505         printf("Parse tunnel is %s\n",
4506                 (ports[port_id].parse_tunnel) ? "on" : "off");
4507         printf("IP checksum offload is %s\n",
4508                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4509         printf("UDP checksum offload is %s\n",
4510                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4511         printf("TCP checksum offload is %s\n",
4512                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4513         printf("SCTP checksum offload is %s\n",
4514                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4515         printf("Outer-Ip checksum offload is %s\n",
4516                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4517         printf("Outer-Udp checksum offload is %s\n",
4518                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4519
4520         /* display warnings if configuration is not supported by the NIC */
4521         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4522         if (ret != 0)
4523                 return;
4524
4525         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4526                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4527                 printf("Warning: hardware IP checksum enabled but not "
4528                         "supported by port %d\n", port_id);
4529         }
4530         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4531                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4532                 printf("Warning: hardware UDP checksum enabled but not "
4533                         "supported by port %d\n", port_id);
4534         }
4535         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4536                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4537                 printf("Warning: hardware TCP checksum enabled but not "
4538                         "supported by port %d\n", port_id);
4539         }
4540         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4541                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4542                 printf("Warning: hardware SCTP checksum enabled but not "
4543                         "supported by port %d\n", port_id);
4544         }
4545         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4546                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4547                 printf("Warning: hardware outer IP checksum enabled but not "
4548                         "supported by port %d\n", port_id);
4549         }
4550         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4551                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4552                         == 0) {
4553                 printf("Warning: hardware outer UDP checksum enabled but not "
4554                         "supported by port %d\n", port_id);
4555         }
4556 }
4557
4558 static void
4559 cmd_config_queue_tx_offloads(struct rte_port *port)
4560 {
4561         int k;
4562
4563         /* Apply queue tx offloads configuration */
4564         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4565                 port->tx_conf[k].offloads =
4566                         port->dev_conf.txmode.offloads;
4567 }
4568
4569 static void
4570 cmd_csum_parsed(void *parsed_result,
4571                        __rte_unused struct cmdline *cl,
4572                        __rte_unused void *data)
4573 {
4574         struct cmd_csum_result *res = parsed_result;
4575         int hw = 0;
4576         uint64_t csum_offloads = 0;
4577         struct rte_eth_dev_info dev_info;
4578         int ret;
4579
4580         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4581                 printf("invalid port %d\n", res->port_id);
4582                 return;
4583         }
4584         if (!port_is_stopped(res->port_id)) {
4585                 printf("Please stop port %d first\n", res->port_id);
4586                 return;
4587         }
4588
4589         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4590         if (ret != 0)
4591                 return;
4592
4593         if (!strcmp(res->mode, "set")) {
4594
4595                 if (!strcmp(res->hwsw, "hw"))
4596                         hw = 1;
4597
4598                 if (!strcmp(res->proto, "ip")) {
4599                         if (hw == 0 || (dev_info.tx_offload_capa &
4600                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4601                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4602                         } else {
4603                                 printf("IP checksum offload is not supported "
4604                                        "by port %u\n", res->port_id);
4605                         }
4606                 } else if (!strcmp(res->proto, "udp")) {
4607                         if (hw == 0 || (dev_info.tx_offload_capa &
4608                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4609                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4610                         } else {
4611                                 printf("UDP checksum offload is not supported "
4612                                        "by port %u\n", res->port_id);
4613                         }
4614                 } else if (!strcmp(res->proto, "tcp")) {
4615                         if (hw == 0 || (dev_info.tx_offload_capa &
4616                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4617                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4618                         } else {
4619                                 printf("TCP checksum offload is not supported "
4620                                        "by port %u\n", res->port_id);
4621                         }
4622                 } else if (!strcmp(res->proto, "sctp")) {
4623                         if (hw == 0 || (dev_info.tx_offload_capa &
4624                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4625                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4626                         } else {
4627                                 printf("SCTP checksum offload is not supported "
4628                                        "by port %u\n", res->port_id);
4629                         }
4630                 } else if (!strcmp(res->proto, "outer-ip")) {
4631                         if (hw == 0 || (dev_info.tx_offload_capa &
4632                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4633                                 csum_offloads |=
4634                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4635                         } else {
4636                                 printf("Outer IP checksum offload is not "
4637                                        "supported by port %u\n", res->port_id);
4638                         }
4639                 } else if (!strcmp(res->proto, "outer-udp")) {
4640                         if (hw == 0 || (dev_info.tx_offload_capa &
4641                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4642                                 csum_offloads |=
4643                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4644                         } else {
4645                                 printf("Outer UDP checksum offload is not "
4646                                        "supported by port %u\n", res->port_id);
4647                         }
4648                 }
4649
4650                 if (hw) {
4651                         ports[res->port_id].dev_conf.txmode.offloads |=
4652                                                         csum_offloads;
4653                 } else {
4654                         ports[res->port_id].dev_conf.txmode.offloads &=
4655                                                         (~csum_offloads);
4656                 }
4657                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4658         }
4659         csum_show(res->port_id);
4660
4661         cmd_reconfig_device_queue(res->port_id, 1, 1);
4662 }
4663
4664 cmdline_parse_token_string_t cmd_csum_csum =
4665         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4666                                 csum, "csum");
4667 cmdline_parse_token_string_t cmd_csum_mode =
4668         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4669                                 mode, "set");
4670 cmdline_parse_token_string_t cmd_csum_proto =
4671         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4672                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4673 cmdline_parse_token_string_t cmd_csum_hwsw =
4674         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4675                                 hwsw, "hw#sw");
4676 cmdline_parse_token_num_t cmd_csum_portid =
4677         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4678                                 port_id, RTE_UINT16);
4679
4680 cmdline_parse_inst_t cmd_csum_set = {
4681         .f = cmd_csum_parsed,
4682         .data = NULL,
4683         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4684                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4685                 "using csum forward engine",
4686         .tokens = {
4687                 (void *)&cmd_csum_csum,
4688                 (void *)&cmd_csum_mode,
4689                 (void *)&cmd_csum_proto,
4690                 (void *)&cmd_csum_hwsw,
4691                 (void *)&cmd_csum_portid,
4692                 NULL,
4693         },
4694 };
4695
4696 cmdline_parse_token_string_t cmd_csum_mode_show =
4697         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4698                                 mode, "show");
4699
4700 cmdline_parse_inst_t cmd_csum_show = {
4701         .f = cmd_csum_parsed,
4702         .data = NULL,
4703         .help_str = "csum show <port_id>: Show checksum offload configuration",
4704         .tokens = {
4705                 (void *)&cmd_csum_csum,
4706                 (void *)&cmd_csum_mode_show,
4707                 (void *)&cmd_csum_portid,
4708                 NULL,
4709         },
4710 };
4711
4712 /* Enable/disable tunnel parsing */
4713 struct cmd_csum_tunnel_result {
4714         cmdline_fixed_string_t csum;
4715         cmdline_fixed_string_t parse;
4716         cmdline_fixed_string_t onoff;
4717         portid_t port_id;
4718 };
4719
4720 static void
4721 cmd_csum_tunnel_parsed(void *parsed_result,
4722                        __rte_unused struct cmdline *cl,
4723                        __rte_unused void *data)
4724 {
4725         struct cmd_csum_tunnel_result *res = parsed_result;
4726
4727         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4728                 return;
4729
4730         if (!strcmp(res->onoff, "on"))
4731                 ports[res->port_id].parse_tunnel = 1;
4732         else
4733                 ports[res->port_id].parse_tunnel = 0;
4734
4735         csum_show(res->port_id);
4736 }
4737
4738 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4739         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4740                                 csum, "csum");
4741 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4742         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4743                                 parse, "parse-tunnel");
4744 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4745         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4746                                 onoff, "on#off");
4747 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4748         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4749                                 port_id, RTE_UINT16);
4750
4751 cmdline_parse_inst_t cmd_csum_tunnel = {
4752         .f = cmd_csum_tunnel_parsed,
4753         .data = NULL,
4754         .help_str = "csum parse-tunnel on|off <port_id>: "
4755                 "Enable/Disable parsing of tunnels for csum engine",
4756         .tokens = {
4757                 (void *)&cmd_csum_tunnel_csum,
4758                 (void *)&cmd_csum_tunnel_parse,
4759                 (void *)&cmd_csum_tunnel_onoff,
4760                 (void *)&cmd_csum_tunnel_portid,
4761                 NULL,
4762         },
4763 };
4764
4765 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4766 struct cmd_tso_set_result {
4767         cmdline_fixed_string_t tso;
4768         cmdline_fixed_string_t mode;
4769         uint16_t tso_segsz;
4770         portid_t port_id;
4771 };
4772
4773 static void
4774 cmd_tso_set_parsed(void *parsed_result,
4775                        __rte_unused struct cmdline *cl,
4776                        __rte_unused void *data)
4777 {
4778         struct cmd_tso_set_result *res = parsed_result;
4779         struct rte_eth_dev_info dev_info;
4780         int ret;
4781
4782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4783                 return;
4784         if (!port_is_stopped(res->port_id)) {
4785                 printf("Please stop port %d first\n", res->port_id);
4786                 return;
4787         }
4788
4789         if (!strcmp(res->mode, "set"))
4790                 ports[res->port_id].tso_segsz = res->tso_segsz;
4791
4792         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4793         if (ret != 0)
4794                 return;
4795
4796         if ((ports[res->port_id].tso_segsz != 0) &&
4797                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4798                 printf("Error: TSO is not supported by port %d\n",
4799                        res->port_id);
4800                 return;
4801         }
4802
4803         if (ports[res->port_id].tso_segsz == 0) {
4804                 ports[res->port_id].dev_conf.txmode.offloads &=
4805                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4806                 printf("TSO for non-tunneled packets is disabled\n");
4807         } else {
4808                 ports[res->port_id].dev_conf.txmode.offloads |=
4809                                                 DEV_TX_OFFLOAD_TCP_TSO;
4810                 printf("TSO segment size for non-tunneled packets is %d\n",
4811                         ports[res->port_id].tso_segsz);
4812         }
4813         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4814
4815         /* display warnings if configuration is not supported by the NIC */
4816         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4817         if (ret != 0)
4818                 return;
4819
4820         if ((ports[res->port_id].tso_segsz != 0) &&
4821                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4822                 printf("Warning: TSO enabled but not "
4823                         "supported by port %d\n", res->port_id);
4824         }
4825
4826         cmd_reconfig_device_queue(res->port_id, 1, 1);
4827 }
4828
4829 cmdline_parse_token_string_t cmd_tso_set_tso =
4830         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4831                                 tso, "tso");
4832 cmdline_parse_token_string_t cmd_tso_set_mode =
4833         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4834                                 mode, "set");
4835 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4836         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4837                                 tso_segsz, RTE_UINT16);
4838 cmdline_parse_token_num_t cmd_tso_set_portid =
4839         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4840                                 port_id, RTE_UINT16);
4841
4842 cmdline_parse_inst_t cmd_tso_set = {
4843         .f = cmd_tso_set_parsed,
4844         .data = NULL,
4845         .help_str = "tso set <tso_segsz> <port_id>: "
4846                 "Set TSO segment size of non-tunneled packets for csum engine "
4847                 "(0 to disable)",
4848         .tokens = {
4849                 (void *)&cmd_tso_set_tso,
4850                 (void *)&cmd_tso_set_mode,
4851                 (void *)&cmd_tso_set_tso_segsz,
4852                 (void *)&cmd_tso_set_portid,
4853                 NULL,
4854         },
4855 };
4856
4857 cmdline_parse_token_string_t cmd_tso_show_mode =
4858         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4859                                 mode, "show");
4860
4861
4862 cmdline_parse_inst_t cmd_tso_show = {
4863         .f = cmd_tso_set_parsed,
4864         .data = NULL,
4865         .help_str = "tso show <port_id>: "
4866                 "Show TSO segment size of non-tunneled packets for csum engine",
4867         .tokens = {
4868                 (void *)&cmd_tso_set_tso,
4869                 (void *)&cmd_tso_show_mode,
4870                 (void *)&cmd_tso_set_portid,
4871                 NULL,
4872         },
4873 };
4874
4875 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4876 struct cmd_tunnel_tso_set_result {
4877         cmdline_fixed_string_t tso;
4878         cmdline_fixed_string_t mode;
4879         uint16_t tso_segsz;
4880         portid_t port_id;
4881 };
4882
4883 static struct rte_eth_dev_info
4884 check_tunnel_tso_nic_support(portid_t port_id)
4885 {
4886         struct rte_eth_dev_info dev_info;
4887
4888         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4889                 return dev_info;
4890
4891         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4892                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4893                        "not enabled for port %d\n", port_id);
4894         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4895                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4896                        "not enabled for port %d\n", port_id);
4897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4898                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4899                        "not enabled for port %d\n", port_id);
4900         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4901                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4902                        "not enabled for port %d\n", port_id);
4903         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4904                 printf("Warning: IP TUNNEL TSO not supported therefore "
4905                        "not enabled for port %d\n", port_id);
4906         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4907                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4908                        "not enabled for port %d\n", port_id);
4909         return dev_info;
4910 }
4911
4912 static void
4913 cmd_tunnel_tso_set_parsed(void *parsed_result,
4914                           __rte_unused struct cmdline *cl,
4915                           __rte_unused void *data)
4916 {
4917         struct cmd_tunnel_tso_set_result *res = parsed_result;
4918         struct rte_eth_dev_info dev_info;
4919
4920         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4921                 return;
4922         if (!port_is_stopped(res->port_id)) {
4923                 printf("Please stop port %d first\n", res->port_id);
4924                 return;
4925         }
4926
4927         if (!strcmp(res->mode, "set"))
4928                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4929
4930         dev_info = check_tunnel_tso_nic_support(res->port_id);
4931         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4932                 ports[res->port_id].dev_conf.txmode.offloads &=
4933                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4934                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4935                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4936                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4937                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4938                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4939                 printf("TSO for tunneled packets is disabled\n");
4940         } else {
4941                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4942                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4943                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4944                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4945                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4946                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4947
4948                 ports[res->port_id].dev_conf.txmode.offloads |=
4949                         (tso_offloads & dev_info.tx_offload_capa);
4950                 printf("TSO segment size for tunneled packets is %d\n",
4951                         ports[res->port_id].tunnel_tso_segsz);
4952
4953                 /* Below conditions are needed to make it work:
4954                  * (1) tunnel TSO is supported by the NIC;
4955                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4956                  * are recognized;
4957                  * (3) for tunneled pkts with outer L3 of IPv4,
4958                  * "csum set outer-ip" must be set to hw, because after tso,
4959                  * total_len of outer IP header is changed, and the checksum
4960                  * of outer IP header calculated by sw should be wrong; that
4961                  * is not necessary for IPv6 tunneled pkts because there's no
4962                  * checksum in IP header anymore.
4963                  */
4964
4965                 if (!ports[res->port_id].parse_tunnel)
4966                         printf("Warning: csum parse_tunnel must be set "
4967                                 "so that tunneled packets are recognized\n");
4968                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4969                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4970                         printf("Warning: csum set outer-ip must be set to hw "
4971                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4972         }
4973
4974         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4975         cmd_reconfig_device_queue(res->port_id, 1, 1);
4976 }
4977
4978 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4979         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4980                                 tso, "tunnel_tso");
4981 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4982         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4983                                 mode, "set");
4984 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4985         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4986                                 tso_segsz, RTE_UINT16);
4987 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4988         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4989                                 port_id, RTE_UINT16);
4990
4991 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4992         .f = cmd_tunnel_tso_set_parsed,
4993         .data = NULL,
4994         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4995                 "Set TSO segment size of tunneled packets for csum engine "
4996                 "(0 to disable)",
4997         .tokens = {
4998                 (void *)&cmd_tunnel_tso_set_tso,
4999                 (void *)&cmd_tunnel_tso_set_mode,
5000                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5001                 (void *)&cmd_tunnel_tso_set_portid,
5002                 NULL,
5003         },
5004 };
5005
5006 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5007         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5008                                 mode, "show");
5009
5010
5011 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5012         .f = cmd_tunnel_tso_set_parsed,
5013         .data = NULL,
5014         .help_str = "tunnel_tso show <port_id> "
5015                 "Show TSO segment size of tunneled packets for csum engine",
5016         .tokens = {
5017                 (void *)&cmd_tunnel_tso_set_tso,
5018                 (void *)&cmd_tunnel_tso_show_mode,
5019                 (void *)&cmd_tunnel_tso_set_portid,
5020                 NULL,
5021         },
5022 };
5023
5024 /* *** SET GRO FOR A PORT *** */
5025 struct cmd_gro_enable_result {
5026         cmdline_fixed_string_t cmd_set;
5027         cmdline_fixed_string_t cmd_port;
5028         cmdline_fixed_string_t cmd_keyword;
5029         cmdline_fixed_string_t cmd_onoff;
5030         portid_t cmd_pid;
5031 };
5032
5033 static void
5034 cmd_gro_enable_parsed(void *parsed_result,
5035                 __rte_unused struct cmdline *cl,
5036                 __rte_unused void *data)
5037 {
5038         struct cmd_gro_enable_result *res;
5039
5040         res = parsed_result;
5041         if (!strcmp(res->cmd_keyword, "gro"))
5042                 setup_gro(res->cmd_onoff, res->cmd_pid);
5043 }
5044
5045 cmdline_parse_token_string_t cmd_gro_enable_set =
5046         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5047                         cmd_set, "set");
5048 cmdline_parse_token_string_t cmd_gro_enable_port =
5049         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5050                         cmd_keyword, "port");
5051 cmdline_parse_token_num_t cmd_gro_enable_pid =
5052         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5053                         cmd_pid, RTE_UINT16);
5054 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5056                         cmd_keyword, "gro");
5057 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5059                         cmd_onoff, "on#off");
5060
5061 cmdline_parse_inst_t cmd_gro_enable = {
5062         .f = cmd_gro_enable_parsed,
5063         .data = NULL,
5064         .help_str = "set port <port_id> gro on|off",
5065         .tokens = {
5066                 (void *)&cmd_gro_enable_set,
5067                 (void *)&cmd_gro_enable_port,
5068                 (void *)&cmd_gro_enable_pid,
5069                 (void *)&cmd_gro_enable_keyword,
5070                 (void *)&cmd_gro_enable_onoff,
5071                 NULL,
5072         },
5073 };
5074
5075 /* *** DISPLAY GRO CONFIGURATION *** */
5076 struct cmd_gro_show_result {
5077         cmdline_fixed_string_t cmd_show;
5078         cmdline_fixed_string_t cmd_port;
5079         cmdline_fixed_string_t cmd_keyword;
5080         portid_t cmd_pid;
5081 };
5082
5083 static void
5084 cmd_gro_show_parsed(void *parsed_result,
5085                 __rte_unused struct cmdline *cl,
5086                 __rte_unused void *data)
5087 {
5088         struct cmd_gro_show_result *res;
5089
5090         res = parsed_result;
5091         if (!strcmp(res->cmd_keyword, "gro"))
5092                 show_gro(res->cmd_pid);
5093 }
5094
5095 cmdline_parse_token_string_t cmd_gro_show_show =
5096         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5097                         cmd_show, "show");
5098 cmdline_parse_token_string_t cmd_gro_show_port =
5099         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5100                         cmd_port, "port");
5101 cmdline_parse_token_num_t cmd_gro_show_pid =
5102         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5103                         cmd_pid, RTE_UINT16);
5104 cmdline_parse_token_string_t cmd_gro_show_keyword =
5105         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5106                         cmd_keyword, "gro");
5107
5108 cmdline_parse_inst_t cmd_gro_show = {
5109         .f = cmd_gro_show_parsed,
5110         .data = NULL,
5111         .help_str = "show port <port_id> gro",
5112         .tokens = {
5113                 (void *)&cmd_gro_show_show,
5114                 (void *)&cmd_gro_show_port,
5115                 (void *)&cmd_gro_show_pid,
5116                 (void *)&cmd_gro_show_keyword,
5117                 NULL,
5118         },
5119 };
5120
5121 /* *** SET FLUSH CYCLES FOR GRO *** */
5122 struct cmd_gro_flush_result {
5123         cmdline_fixed_string_t cmd_set;
5124         cmdline_fixed_string_t cmd_keyword;
5125         cmdline_fixed_string_t cmd_flush;
5126         uint8_t cmd_cycles;
5127 };
5128
5129 static void
5130 cmd_gro_flush_parsed(void *parsed_result,
5131                 __rte_unused struct cmdline *cl,
5132                 __rte_unused void *data)
5133 {
5134         struct cmd_gro_flush_result *res;
5135
5136         res = parsed_result;
5137         if ((!strcmp(res->cmd_keyword, "gro")) &&
5138                         (!strcmp(res->cmd_flush, "flush")))
5139                 setup_gro_flush_cycles(res->cmd_cycles);
5140 }
5141
5142 cmdline_parse_token_string_t cmd_gro_flush_set =
5143         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5144                         cmd_set, "set");
5145 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5146         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5147                         cmd_keyword, "gro");
5148 cmdline_parse_token_string_t cmd_gro_flush_flush =
5149         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5150                         cmd_flush, "flush");
5151 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5152         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5153                         cmd_cycles, RTE_UINT8);
5154
5155 cmdline_parse_inst_t cmd_gro_flush = {
5156         .f = cmd_gro_flush_parsed,
5157         .data = NULL,
5158         .help_str = "set gro flush <cycles>",
5159         .tokens = {
5160                 (void *)&cmd_gro_flush_set,
5161                 (void *)&cmd_gro_flush_keyword,
5162                 (void *)&cmd_gro_flush_flush,
5163                 (void *)&cmd_gro_flush_cycles,
5164                 NULL,
5165         },
5166 };
5167
5168 /* *** ENABLE/DISABLE GSO *** */
5169 struct cmd_gso_enable_result {
5170         cmdline_fixed_string_t cmd_set;
5171         cmdline_fixed_string_t cmd_port;
5172         cmdline_fixed_string_t cmd_keyword;
5173         cmdline_fixed_string_t cmd_mode;
5174         portid_t cmd_pid;
5175 };
5176
5177 static void
5178 cmd_gso_enable_parsed(void *parsed_result,
5179                 __rte_unused struct cmdline *cl,
5180                 __rte_unused void *data)
5181 {
5182         struct cmd_gso_enable_result *res;
5183
5184         res = parsed_result;
5185         if (!strcmp(res->cmd_keyword, "gso"))
5186                 setup_gso(res->cmd_mode, res->cmd_pid);
5187 }
5188
5189 cmdline_parse_token_string_t cmd_gso_enable_set =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5191                         cmd_set, "set");
5192 cmdline_parse_token_string_t cmd_gso_enable_port =
5193         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5194                         cmd_port, "port");
5195 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5197                         cmd_keyword, "gso");
5198 cmdline_parse_token_string_t cmd_gso_enable_mode =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5200                         cmd_mode, "on#off");
5201 cmdline_parse_token_num_t cmd_gso_enable_pid =
5202         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5203                         cmd_pid, RTE_UINT16);
5204
5205 cmdline_parse_inst_t cmd_gso_enable = {
5206         .f = cmd_gso_enable_parsed,
5207         .data = NULL,
5208         .help_str = "set port <port_id> gso on|off",
5209         .tokens = {
5210                 (void *)&cmd_gso_enable_set,
5211                 (void *)&cmd_gso_enable_port,
5212                 (void *)&cmd_gso_enable_pid,
5213                 (void *)&cmd_gso_enable_keyword,
5214                 (void *)&cmd_gso_enable_mode,
5215                 NULL,
5216         },
5217 };
5218
5219 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5220 struct cmd_gso_size_result {
5221         cmdline_fixed_string_t cmd_set;
5222         cmdline_fixed_string_t cmd_keyword;
5223         cmdline_fixed_string_t cmd_segsz;
5224         uint16_t cmd_size;
5225 };
5226
5227 static void
5228 cmd_gso_size_parsed(void *parsed_result,
5229                        __rte_unused struct cmdline *cl,
5230                        __rte_unused void *data)
5231 {
5232         struct cmd_gso_size_result *res = parsed_result;
5233
5234         if (test_done == 0) {
5235                 printf("Before setting GSO segsz, please first"
5236                                 " stop forwarding\n");
5237                 return;
5238         }
5239
5240         if (!strcmp(res->cmd_keyword, "gso") &&
5241                         !strcmp(res->cmd_segsz, "segsz")) {
5242                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5243                         printf("gso_size should be larger than %zu."
5244                                         " Please input a legal value\n",
5245                                         RTE_GSO_SEG_SIZE_MIN);
5246                 else
5247                         gso_max_segment_size = res->cmd_size;
5248         }
5249 }
5250
5251 cmdline_parse_token_string_t cmd_gso_size_set =
5252         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5253                                 cmd_set, "set");
5254 cmdline_parse_token_string_t cmd_gso_size_keyword =
5255         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5256                                 cmd_keyword, "gso");
5257 cmdline_parse_token_string_t cmd_gso_size_segsz =
5258         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5259                                 cmd_segsz, "segsz");
5260 cmdline_parse_token_num_t cmd_gso_size_size =
5261         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5262                                 cmd_size, RTE_UINT16);
5263
5264 cmdline_parse_inst_t cmd_gso_size = {
5265         .f = cmd_gso_size_parsed,
5266         .data = NULL,
5267         .help_str = "set gso segsz <length>",
5268         .tokens = {
5269                 (void *)&cmd_gso_size_set,
5270                 (void *)&cmd_gso_size_keyword,
5271                 (void *)&cmd_gso_size_segsz,
5272                 (void *)&cmd_gso_size_size,
5273                 NULL,
5274         },
5275 };
5276
5277 /* *** SHOW GSO CONFIGURATION *** */
5278 struct cmd_gso_show_result {
5279         cmdline_fixed_string_t cmd_show;
5280         cmdline_fixed_string_t cmd_port;
5281         cmdline_fixed_string_t cmd_keyword;
5282         portid_t cmd_pid;
5283 };
5284
5285 static void
5286 cmd_gso_show_parsed(void *parsed_result,
5287                        __rte_unused struct cmdline *cl,
5288                        __rte_unused void *data)
5289 {
5290         struct cmd_gso_show_result *res = parsed_result;
5291
5292         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5293                 printf("invalid port id %u\n", res->cmd_pid);
5294                 return;
5295         }
5296         if (!strcmp(res->cmd_keyword, "gso")) {
5297                 if (gso_ports[res->cmd_pid].enable) {
5298                         printf("Max GSO'd packet size: %uB\n"
5299                                         "Supported GSO types: TCP/IPv4, "
5300                                         "UDP/IPv4, VxLAN with inner "
5301                                         "TCP/IPv4 packet, GRE with inner "
5302                                         "TCP/IPv4 packet\n",
5303                                         gso_max_segment_size);
5304                 } else
5305                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5306         }
5307 }
5308
5309 cmdline_parse_token_string_t cmd_gso_show_show =
5310 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5311                 cmd_show, "show");
5312 cmdline_parse_token_string_t cmd_gso_show_port =
5313 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5314                 cmd_port, "port");
5315 cmdline_parse_token_string_t cmd_gso_show_keyword =
5316         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5317                                 cmd_keyword, "gso");
5318 cmdline_parse_token_num_t cmd_gso_show_pid =
5319         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5320                                 cmd_pid, RTE_UINT16);
5321
5322 cmdline_parse_inst_t cmd_gso_show = {
5323         .f = cmd_gso_show_parsed,
5324         .data = NULL,
5325         .help_str = "show port <port_id> gso",
5326         .tokens = {
5327                 (void *)&cmd_gso_show_show,
5328                 (void *)&cmd_gso_show_port,
5329                 (void *)&cmd_gso_show_pid,
5330                 (void *)&cmd_gso_show_keyword,
5331                 NULL,
5332         },
5333 };
5334
5335 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5336 struct cmd_set_flush_rx {
5337         cmdline_fixed_string_t set;
5338         cmdline_fixed_string_t flush_rx;
5339         cmdline_fixed_string_t mode;
5340 };
5341
5342 static void
5343 cmd_set_flush_rx_parsed(void *parsed_result,
5344                 __rte_unused struct cmdline *cl,
5345                 __rte_unused void *data)
5346 {
5347         struct cmd_set_flush_rx *res = parsed_result;
5348         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5349 }
5350
5351 cmdline_parse_token_string_t cmd_setflushrx_set =
5352         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5353                         set, "set");
5354 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5355         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5356                         flush_rx, "flush_rx");
5357 cmdline_parse_token_string_t cmd_setflushrx_mode =
5358         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5359                         mode, "on#off");
5360
5361
5362 cmdline_parse_inst_t cmd_set_flush_rx = {
5363         .f = cmd_set_flush_rx_parsed,
5364         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5365         .data = NULL,
5366         .tokens = {
5367                 (void *)&cmd_setflushrx_set,
5368                 (void *)&cmd_setflushrx_flush_rx,
5369                 (void *)&cmd_setflushrx_mode,
5370                 NULL,
5371         },
5372 };
5373
5374 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5375 struct cmd_set_link_check {
5376         cmdline_fixed_string_t set;
5377         cmdline_fixed_string_t link_check;
5378         cmdline_fixed_string_t mode;
5379 };
5380
5381 static void
5382 cmd_set_link_check_parsed(void *parsed_result,
5383                 __rte_unused struct cmdline *cl,
5384                 __rte_unused void *data)
5385 {
5386         struct cmd_set_link_check *res = parsed_result;
5387         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5388 }
5389
5390 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5391         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5392                         set, "set");
5393 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5394         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5395                         link_check, "link_check");
5396 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5398                         mode, "on#off");
5399
5400
5401 cmdline_parse_inst_t cmd_set_link_check = {
5402         .f = cmd_set_link_check_parsed,
5403         .help_str = "set link_check on|off: Enable/Disable link status check "
5404                     "when starting/stopping a port",
5405         .data = NULL,
5406         .tokens = {
5407                 (void *)&cmd_setlinkcheck_set,
5408                 (void *)&cmd_setlinkcheck_link_check,
5409                 (void *)&cmd_setlinkcheck_mode,
5410                 NULL,
5411         },
5412 };
5413
5414 /* *** SET NIC BYPASS MODE *** */
5415 struct cmd_set_bypass_mode_result {
5416         cmdline_fixed_string_t set;
5417         cmdline_fixed_string_t bypass;
5418         cmdline_fixed_string_t mode;
5419         cmdline_fixed_string_t value;
5420         portid_t port_id;
5421 };
5422
5423 static void
5424 cmd_set_bypass_mode_parsed(void *parsed_result,
5425                 __rte_unused struct cmdline *cl,
5426                 __rte_unused void *data)
5427 {
5428         struct cmd_set_bypass_mode_result *res = parsed_result;
5429         portid_t port_id = res->port_id;
5430         int32_t rc = -EINVAL;
5431
5432 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5433         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5434
5435         if (!strcmp(res->value, "bypass"))
5436                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5437         else if (!strcmp(res->value, "isolate"))
5438                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5439         else
5440                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5441
5442         /* Set the bypass mode for the relevant port. */
5443         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5444 #endif
5445         if (rc != 0)
5446                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5447 }
5448
5449 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5450         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5451                         set, "set");
5452 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5453         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5454                         bypass, "bypass");
5455 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5457                         mode, "mode");
5458 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5460                         value, "normal#bypass#isolate");
5461 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5462         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5463                                 port_id, RTE_UINT16);
5464
5465 cmdline_parse_inst_t cmd_set_bypass_mode = {
5466         .f = cmd_set_bypass_mode_parsed,
5467         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5468                     "Set the NIC bypass mode for port_id",
5469         .data = NULL,
5470         .tokens = {
5471                 (void *)&cmd_setbypass_mode_set,
5472                 (void *)&cmd_setbypass_mode_bypass,
5473                 (void *)&cmd_setbypass_mode_mode,
5474                 (void *)&cmd_setbypass_mode_value,
5475                 (void *)&cmd_setbypass_mode_port,
5476                 NULL,
5477         },
5478 };
5479
5480 /* *** SET NIC BYPASS EVENT *** */
5481 struct cmd_set_bypass_event_result {
5482         cmdline_fixed_string_t set;
5483         cmdline_fixed_string_t bypass;
5484         cmdline_fixed_string_t event;
5485         cmdline_fixed_string_t event_value;
5486         cmdline_fixed_string_t mode;
5487         cmdline_fixed_string_t mode_value;
5488         portid_t port_id;
5489 };
5490
5491 static void
5492 cmd_set_bypass_event_parsed(void *parsed_result,
5493                 __rte_unused struct cmdline *cl,
5494                 __rte_unused void *data)
5495 {
5496         int32_t rc = -EINVAL;
5497         struct cmd_set_bypass_event_result *res = parsed_result;
5498         portid_t port_id = res->port_id;
5499
5500 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5501         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5502         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5503
5504         if (!strcmp(res->event_value, "timeout"))
5505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5506         else if (!strcmp(res->event_value, "os_on"))
5507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5508         else if (!strcmp(res->event_value, "os_off"))
5509                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5510         else if (!strcmp(res->event_value, "power_on"))
5511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5512         else if (!strcmp(res->event_value, "power_off"))
5513                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5514         else
5515                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5516
5517         if (!strcmp(res->mode_value, "bypass"))
5518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5519         else if (!strcmp(res->mode_value, "isolate"))
5520                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5521         else
5522                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5523
5524         /* Set the watchdog timeout. */
5525         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5526
5527                 rc = -EINVAL;
5528                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5529                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5530                                                            bypass_timeout);
5531                 }
5532                 if (rc != 0) {
5533                         printf("Failed to set timeout value %u "
5534                         "for port %d, errto code: %d.\n",
5535                         bypass_timeout, port_id, rc);
5536                 }
5537         }
5538
5539         /* Set the bypass event to transition to bypass mode. */
5540         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5541                                               bypass_mode);
5542 #endif
5543
5544         if (rc != 0)
5545                 printf("\t Failed to set bypass event for port = %d.\n",
5546                        port_id);
5547 }
5548
5549 cmdline_parse_token_string_t cmd_setbypass_event_set =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5551                         set, "set");
5552 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5554                         bypass, "bypass");
5555 cmdline_parse_token_string_t cmd_setbypass_event_event =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5557                         event, "event");
5558 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5560                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5561 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5563                         mode, "mode");
5564 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5566                         mode_value, "normal#bypass#isolate");
5567 cmdline_parse_token_num_t cmd_setbypass_event_port =
5568         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5569                                 port_id, RTE_UINT16);
5570
5571 cmdline_parse_inst_t cmd_set_bypass_event = {
5572         .f = cmd_set_bypass_event_parsed,
5573         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5574                 "power_off mode normal|bypass|isolate <port_id>: "
5575                 "Set the NIC bypass event mode for port_id",
5576         .data = NULL,
5577         .tokens = {
5578                 (void *)&cmd_setbypass_event_set,
5579                 (void *)&cmd_setbypass_event_bypass,
5580                 (void *)&cmd_setbypass_event_event,
5581                 (void *)&cmd_setbypass_event_event_value,
5582                 (void *)&cmd_setbypass_event_mode,
5583                 (void *)&cmd_setbypass_event_mode_value,
5584                 (void *)&cmd_setbypass_event_port,
5585                 NULL,
5586         },
5587 };
5588
5589
5590 /* *** SET NIC BYPASS TIMEOUT *** */
5591 struct cmd_set_bypass_timeout_result {
5592         cmdline_fixed_string_t set;
5593         cmdline_fixed_string_t bypass;
5594         cmdline_fixed_string_t timeout;
5595         cmdline_fixed_string_t value;
5596 };
5597
5598 static void
5599 cmd_set_bypass_timeout_parsed(void *parsed_result,
5600                 __rte_unused struct cmdline *cl,
5601                 __rte_unused void *data)
5602 {
5603         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5604
5605 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5606         if (!strcmp(res->value, "1.5"))
5607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5608         else if (!strcmp(res->value, "2"))
5609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5610         else if (!strcmp(res->value, "3"))
5611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5612         else if (!strcmp(res->value, "4"))
5613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5614         else if (!strcmp(res->value, "8"))
5615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5616         else if (!strcmp(res->value, "16"))
5617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5618         else if (!strcmp(res->value, "32"))
5619                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5620         else
5621                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5622 #endif
5623 }
5624
5625 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5627                         set, "set");
5628 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5630                         bypass, "bypass");
5631 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5633                         timeout, "timeout");
5634 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5636                         value, "0#1.5#2#3#4#8#16#32");
5637
5638 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5639         .f = cmd_set_bypass_timeout_parsed,
5640         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5641                 "Set the NIC bypass watchdog timeout in seconds",
5642         .data = NULL,
5643         .tokens = {
5644                 (void *)&cmd_setbypass_timeout_set,
5645                 (void *)&cmd_setbypass_timeout_bypass,
5646                 (void *)&cmd_setbypass_timeout_timeout,
5647                 (void *)&cmd_setbypass_timeout_value,
5648                 NULL,
5649         },
5650 };
5651
5652 /* *** SHOW NIC BYPASS MODE *** */
5653 struct cmd_show_bypass_config_result {
5654         cmdline_fixed_string_t show;
5655         cmdline_fixed_string_t bypass;
5656         cmdline_fixed_string_t config;
5657         portid_t port_id;
5658 };
5659
5660 static void
5661 cmd_show_bypass_config_parsed(void *parsed_result,
5662                 __rte_unused struct cmdline *cl,
5663                 __rte_unused void *data)
5664 {
5665         struct cmd_show_bypass_config_result *res = parsed_result;
5666         portid_t port_id = res->port_id;
5667         int rc = -EINVAL;
5668 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5669         uint32_t event_mode;
5670         uint32_t bypass_mode;
5671         uint32_t timeout = bypass_timeout;
5672         unsigned int i;
5673
5674         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5675                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5676         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5677                 {"UNKNOWN", "normal", "bypass", "isolate"};
5678         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5679                 "NONE",
5680                 "OS/board on",
5681                 "power supply on",
5682                 "OS/board off",
5683                 "power supply off",
5684                 "timeout"};
5685
5686         /* Display the bypass mode.*/
5687         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5688                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5689                 return;
5690         }
5691         else {
5692                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5693                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5694
5695                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5696         }
5697
5698         /* Display the bypass timeout.*/
5699         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5700                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5701
5702         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5703
5704         /* Display the bypass events and associated modes. */
5705         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5706
5707                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5708                         printf("\tFailed to get bypass mode for event = %s\n",
5709                                 events[i]);
5710                 } else {
5711                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5712                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5713
5714                         printf("\tbypass event: %-16s = %s\n", events[i],
5715                                 modes[event_mode]);
5716                 }
5717         }
5718 #endif
5719         if (rc != 0)
5720                 printf("\tFailed to get bypass configuration for port = %d\n",
5721                        port_id);
5722 }
5723
5724 cmdline_parse_token_string_t cmd_showbypass_config_show =
5725         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5726                         show, "show");
5727 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5728         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5729                         bypass, "bypass");
5730 cmdline_parse_token_string_t cmd_showbypass_config_config =
5731         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5732                         config, "config");
5733 cmdline_parse_token_num_t cmd_showbypass_config_port =
5734         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5735                                 port_id, RTE_UINT16);
5736
5737 cmdline_parse_inst_t cmd_show_bypass_config = {
5738         .f = cmd_show_bypass_config_parsed,
5739         .help_str = "show bypass config <port_id>: "
5740                     "Show the NIC bypass config for port_id",
5741         .data = NULL,
5742         .tokens = {
5743                 (void *)&cmd_showbypass_config_show,
5744                 (void *)&cmd_showbypass_config_bypass,
5745                 (void *)&cmd_showbypass_config_config,
5746                 (void *)&cmd_showbypass_config_port,
5747                 NULL,
5748         },
5749 };
5750
5751 #ifdef RTE_NET_BOND
5752 /* *** SET BONDING MODE *** */
5753 struct cmd_set_bonding_mode_result {
5754         cmdline_fixed_string_t set;
5755         cmdline_fixed_string_t bonding;
5756         cmdline_fixed_string_t mode;
5757         uint8_t value;
5758         portid_t port_id;
5759 };
5760
5761 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5762                 __rte_unused  struct cmdline *cl,
5763                 __rte_unused void *data)
5764 {
5765         struct cmd_set_bonding_mode_result *res = parsed_result;
5766         portid_t port_id = res->port_id;
5767
5768         /* Set the bonding mode for the relevant port. */
5769         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5770                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5771 }
5772
5773 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5774 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5775                 set, "set");
5776 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5777 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5778                 bonding, "bonding");
5779 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5780 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5781                 mode, "mode");
5782 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5783 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5784                 value, RTE_UINT8);
5785 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5786 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5787                 port_id, RTE_UINT16);
5788
5789 cmdline_parse_inst_t cmd_set_bonding_mode = {
5790                 .f = cmd_set_bonding_mode_parsed,
5791                 .help_str = "set bonding mode <mode_value> <port_id>: "
5792                         "Set the bonding mode for port_id",
5793                 .data = NULL,
5794                 .tokens = {
5795                                 (void *) &cmd_setbonding_mode_set,
5796                                 (void *) &cmd_setbonding_mode_bonding,
5797                                 (void *) &cmd_setbonding_mode_mode,
5798                                 (void *) &cmd_setbonding_mode_value,
5799                                 (void *) &cmd_setbonding_mode_port,
5800                                 NULL
5801                 }
5802 };
5803
5804 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5805 struct cmd_set_bonding_lacp_dedicated_queues_result {
5806         cmdline_fixed_string_t set;
5807         cmdline_fixed_string_t bonding;
5808         cmdline_fixed_string_t lacp;
5809         cmdline_fixed_string_t dedicated_queues;
5810         portid_t port_id;
5811         cmdline_fixed_string_t mode;
5812 };
5813
5814 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5815                 __rte_unused  struct cmdline *cl,
5816                 __rte_unused void *data)
5817 {
5818         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5819         portid_t port_id = res->port_id;
5820         struct rte_port *port;
5821
5822         port = &ports[port_id];
5823
5824         /** Check if the port is not started **/
5825         if (port->port_status != RTE_PORT_STOPPED) {
5826                 printf("Please stop port %d first\n", port_id);
5827                 return;
5828         }
5829
5830         if (!strcmp(res->mode, "enable")) {
5831                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5832                         printf("Dedicate queues for LACP control packets"
5833                                         " enabled\n");
5834                 else
5835                         printf("Enabling dedicate queues for LACP control "
5836                                         "packets on port %d failed\n", port_id);
5837         } else if (!strcmp(res->mode, "disable")) {
5838                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5839                         printf("Dedicated queues for LACP control packets "
5840                                         "disabled\n");
5841                 else
5842                         printf("Disabling dedicated queues for LACP control "
5843                                         "traffic on port %d failed\n", port_id);
5844         }
5845 }
5846
5847 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5849                 set, "set");
5850 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5851 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5852                 bonding, "bonding");
5853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5855                 lacp, "lacp");
5856 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5858                 dedicated_queues, "dedicated_queues");
5859 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5860 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5861                 port_id, RTE_UINT16);
5862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5864                 mode, "enable#disable");
5865
5866 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5867                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5868                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5869                         "enable|disable: "
5870                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5871                 .data = NULL,
5872                 .tokens = {
5873                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5874                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5875                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5876                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5877                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5878                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5879                         NULL
5880                 }
5881 };
5882
5883 /* *** SET BALANCE XMIT POLICY *** */
5884 struct cmd_set_bonding_balance_xmit_policy_result {
5885         cmdline_fixed_string_t set;
5886         cmdline_fixed_string_t bonding;
5887         cmdline_fixed_string_t balance_xmit_policy;
5888         portid_t port_id;
5889         cmdline_fixed_string_t policy;
5890 };
5891
5892 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5893                 __rte_unused  struct cmdline *cl,
5894                 __rte_unused void *data)
5895 {
5896         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5897         portid_t port_id = res->port_id;
5898         uint8_t policy;
5899
5900         if (!strcmp(res->policy, "l2")) {
5901                 policy = BALANCE_XMIT_POLICY_LAYER2;
5902         } else if (!strcmp(res->policy, "l23")) {
5903                 policy = BALANCE_XMIT_POLICY_LAYER23;
5904         } else if (!strcmp(res->policy, "l34")) {
5905                 policy = BALANCE_XMIT_POLICY_LAYER34;
5906         } else {
5907                 printf("\t Invalid xmit policy selection");
5908                 return;
5909         }
5910
5911         /* Set the bonding mode for the relevant port. */
5912         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5913                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5914                                 port_id);
5915         }
5916 }
5917
5918 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5920                 set, "set");
5921 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5923                 bonding, "bonding");
5924 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5926                 balance_xmit_policy, "balance_xmit_policy");
5927 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5928 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5929                 port_id, RTE_UINT16);
5930 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5932                 policy, "l2#l23#l34");
5933
5934 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5935                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5936                 .help_str = "set bonding balance_xmit_policy <port_id> "
5937                         "l2|l23|l34: "
5938                         "Set the bonding balance_xmit_policy for port_id",
5939                 .data = NULL,
5940                 .tokens = {
5941                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5942                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5943                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5944                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5945                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5946                                 NULL
5947                 }
5948 };
5949
5950 /* *** SHOW NIC BONDING CONFIGURATION *** */
5951 struct cmd_show_bonding_config_result {
5952         cmdline_fixed_string_t show;
5953         cmdline_fixed_string_t bonding;
5954         cmdline_fixed_string_t config;
5955         portid_t port_id;
5956 };
5957
5958 static void cmd_show_bonding_config_parsed(void *parsed_result,
5959                 __rte_unused  struct cmdline *cl,
5960                 __rte_unused void *data)
5961 {
5962         struct cmd_show_bonding_config_result *res = parsed_result;
5963         int bonding_mode, agg_mode;
5964         portid_t slaves[RTE_MAX_ETHPORTS];
5965         int num_slaves, num_active_slaves;
5966         int primary_id;
5967         int i;
5968         portid_t port_id = res->port_id;
5969
5970         /* Display the bonding mode.*/
5971         bonding_mode = rte_eth_bond_mode_get(port_id);
5972         if (bonding_mode < 0) {
5973                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5974                 return;
5975         } else
5976                 printf("\tBonding mode: %d\n", bonding_mode);
5977
5978         if (bonding_mode == BONDING_MODE_BALANCE) {
5979                 int balance_xmit_policy;
5980
5981                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5982                 if (balance_xmit_policy < 0) {
5983                         printf("\tFailed to get balance xmit policy for port = %d\n",
5984                                         port_id);
5985                         return;
5986                 } else {
5987                         printf("\tBalance Xmit Policy: ");
5988
5989                         switch (balance_xmit_policy) {
5990                         case BALANCE_XMIT_POLICY_LAYER2:
5991                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5992                                 break;
5993                         case BALANCE_XMIT_POLICY_LAYER23:
5994                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5995                                 break;
5996                         case BALANCE_XMIT_POLICY_LAYER34:
5997                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5998                                 break;
5999                         }
6000                         printf("\n");
6001                 }
6002         }
6003
6004         if (bonding_mode == BONDING_MODE_8023AD) {
6005                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6006                 printf("\tIEEE802.3AD Aggregator Mode: ");
6007                 switch (agg_mode) {
6008                 case AGG_BANDWIDTH:
6009                         printf("bandwidth");
6010                         break;
6011                 case AGG_STABLE:
6012                         printf("stable");
6013                         break;
6014                 case AGG_COUNT:
6015                         printf("count");
6016                         break;
6017                 }
6018                 printf("\n");
6019         }
6020
6021         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6022
6023         if (num_slaves < 0) {
6024                 printf("\tFailed to get slave list for port = %d\n", port_id);
6025                 return;
6026         }
6027         if (num_slaves > 0) {
6028                 printf("\tSlaves (%d): [", num_slaves);
6029                 for (i = 0; i < num_slaves - 1; i++)
6030                         printf("%d ", slaves[i]);
6031
6032                 printf("%d]\n", slaves[num_slaves - 1]);
6033         } else {
6034                 printf("\tSlaves: []\n");
6035
6036         }
6037
6038         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6039                         RTE_MAX_ETHPORTS);
6040
6041         if (num_active_slaves < 0) {
6042                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6043                 return;
6044         }
6045         if (num_active_slaves > 0) {
6046                 printf("\tActive Slaves (%d): [", num_active_slaves);
6047                 for (i = 0; i < num_active_slaves - 1; i++)
6048                         printf("%d ", slaves[i]);
6049
6050                 printf("%d]\n", slaves[num_active_slaves - 1]);
6051
6052         } else {
6053                 printf("\tActive Slaves: []\n");
6054
6055         }
6056
6057         primary_id = rte_eth_bond_primary_get(port_id);
6058         if (primary_id < 0) {
6059                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6060                 return;
6061         } else
6062                 printf("\tPrimary: [%d]\n", primary_id);
6063
6064 }
6065
6066 cmdline_parse_token_string_t cmd_showbonding_config_show =
6067 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6068                 show, "show");
6069 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6070 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6071                 bonding, "bonding");
6072 cmdline_parse_token_string_t cmd_showbonding_config_config =
6073 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6074                 config, "config");
6075 cmdline_parse_token_num_t cmd_showbonding_config_port =
6076 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6077                 port_id, RTE_UINT16);
6078
6079 cmdline_parse_inst_t cmd_show_bonding_config = {
6080                 .f = cmd_show_bonding_config_parsed,
6081                 .help_str = "show bonding config <port_id>: "
6082                         "Show the bonding config for port_id",
6083                 .data = NULL,
6084                 .tokens = {
6085                                 (void *)&cmd_showbonding_config_show,
6086                                 (void *)&cmd_showbonding_config_bonding,
6087                                 (void *)&cmd_showbonding_config_config,
6088                                 (void *)&cmd_showbonding_config_port,
6089                                 NULL
6090                 }
6091 };
6092
6093 /* *** SET BONDING PRIMARY *** */
6094 struct cmd_set_bonding_primary_result {
6095         cmdline_fixed_string_t set;
6096         cmdline_fixed_string_t bonding;
6097         cmdline_fixed_string_t primary;
6098         portid_t slave_id;
6099         portid_t port_id;
6100 };
6101
6102 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6103                 __rte_unused  struct cmdline *cl,
6104                 __rte_unused void *data)
6105 {
6106         struct cmd_set_bonding_primary_result *res = parsed_result;
6107         portid_t master_port_id = res->port_id;
6108         portid_t slave_port_id = res->slave_id;
6109
6110         /* Set the primary slave for a bonded device. */
6111         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6112                 printf("\t Failed to set primary slave for port = %d.\n",
6113                                 master_port_id);
6114                 return;
6115         }
6116         init_port_config();
6117 }
6118
6119 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6120 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6121                 set, "set");
6122 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6123 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6124                 bonding, "bonding");
6125 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6126 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6127                 primary, "primary");
6128 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6129 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6130                 slave_id, RTE_UINT16);
6131 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6132 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6133                 port_id, RTE_UINT16);
6134
6135 cmdline_parse_inst_t cmd_set_bonding_primary = {
6136                 .f = cmd_set_bonding_primary_parsed,
6137                 .help_str = "set bonding primary <slave_id> <port_id>: "
6138                         "Set the primary slave for port_id",
6139                 .data = NULL,
6140                 .tokens = {
6141                                 (void *)&cmd_setbonding_primary_set,
6142                                 (void *)&cmd_setbonding_primary_bonding,
6143                                 (void *)&cmd_setbonding_primary_primary,
6144                                 (void *)&cmd_setbonding_primary_slave,
6145                                 (void *)&cmd_setbonding_primary_port,
6146                                 NULL
6147                 }
6148 };
6149
6150 /* *** ADD SLAVE *** */
6151 struct cmd_add_bonding_slave_result {
6152         cmdline_fixed_string_t add;
6153         cmdline_fixed_string_t bonding;
6154         cmdline_fixed_string_t slave;
6155         portid_t slave_id;
6156         portid_t port_id;
6157 };
6158
6159 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6160                 __rte_unused  struct cmdline *cl,
6161                 __rte_unused void *data)
6162 {
6163         struct cmd_add_bonding_slave_result *res = parsed_result;
6164         portid_t master_port_id = res->port_id;
6165         portid_t slave_port_id = res->slave_id;
6166
6167         /* add the slave for a bonded device. */
6168         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6169                 printf("\t Failed to add slave %d to master port = %d.\n",
6170                                 slave_port_id, master_port_id);
6171                 return;
6172         }
6173         init_port_config();
6174         set_port_slave_flag(slave_port_id);
6175 }
6176
6177 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6178 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6179                 add, "add");
6180 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6181 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6182                 bonding, "bonding");
6183 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6184 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6185                 slave, "slave");
6186 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6187 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6188                 slave_id, RTE_UINT16);
6189 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6190 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6191                 port_id, RTE_UINT16);
6192
6193 cmdline_parse_inst_t cmd_add_bonding_slave = {
6194                 .f = cmd_add_bonding_slave_parsed,
6195                 .help_str = "add bonding slave <slave_id> <port_id>: "
6196                         "Add a slave device to a bonded device",
6197                 .data = NULL,
6198                 .tokens = {
6199                                 (void *)&cmd_addbonding_slave_add,
6200                                 (void *)&cmd_addbonding_slave_bonding,
6201                                 (void *)&cmd_addbonding_slave_slave,
6202                                 (void *)&cmd_addbonding_slave_slaveid,
6203                                 (void *)&cmd_addbonding_slave_port,
6204                                 NULL
6205                 }
6206 };
6207
6208 /* *** REMOVE SLAVE *** */
6209 struct cmd_remove_bonding_slave_result {
6210         cmdline_fixed_string_t remove;
6211         cmdline_fixed_string_t bonding;
6212         cmdline_fixed_string_t slave;
6213         portid_t slave_id;
6214         portid_t port_id;
6215 };
6216
6217 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6218                 __rte_unused  struct cmdline *cl,
6219                 __rte_unused void *data)
6220 {
6221         struct cmd_remove_bonding_slave_result *res = parsed_result;
6222         portid_t master_port_id = res->port_id;
6223         portid_t slave_port_id = res->slave_id;
6224
6225         /* remove the slave from a bonded device. */
6226         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6227                 printf("\t Failed to remove slave %d from master port = %d.\n",
6228                                 slave_port_id, master_port_id);
6229                 return;
6230         }
6231         init_port_config();
6232         clear_port_slave_flag(slave_port_id);
6233 }
6234
6235 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6236                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6237                                 remove, "remove");
6238 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6239                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6240                                 bonding, "bonding");
6241 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6243                                 slave, "slave");
6244 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6245                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6246                                 slave_id, RTE_UINT16);
6247 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6248                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6249                                 port_id, RTE_UINT16);
6250
6251 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6252                 .f = cmd_remove_bonding_slave_parsed,
6253                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6254                         "Remove a slave device from a bonded device",
6255                 .data = NULL,
6256                 .tokens = {
6257                                 (void *)&cmd_removebonding_slave_remove,
6258                                 (void *)&cmd_removebonding_slave_bonding,
6259                                 (void *)&cmd_removebonding_slave_slave,
6260                                 (void *)&cmd_removebonding_slave_slaveid,
6261                                 (void *)&cmd_removebonding_slave_port,
6262                                 NULL
6263                 }
6264 };
6265
6266 /* *** CREATE BONDED DEVICE *** */
6267 struct cmd_create_bonded_device_result {
6268         cmdline_fixed_string_t create;
6269         cmdline_fixed_string_t bonded;
6270         cmdline_fixed_string_t device;
6271         uint8_t mode;
6272         uint8_t socket;
6273 };
6274
6275 static int bond_dev_num = 0;
6276
6277 static void cmd_create_bonded_device_parsed(void *parsed_result,
6278                 __rte_unused  struct cmdline *cl,
6279                 __rte_unused void *data)
6280 {
6281         struct cmd_create_bonded_device_result *res = parsed_result;
6282         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6283         int port_id;
6284         int ret;
6285
6286         if (test_done == 0) {
6287                 printf("Please stop forwarding first\n");
6288                 return;
6289         }
6290
6291         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6292                         bond_dev_num++);
6293
6294         /* Create a new bonded device. */
6295         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6296         if (port_id < 0) {
6297                 printf("\t Failed to create bonded device.\n");
6298                 return;
6299         } else {
6300                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6301                                 port_id);
6302
6303                 /* Update number of ports */
6304                 nb_ports = rte_eth_dev_count_avail();
6305                 reconfig(port_id, res->socket);
6306                 ret = rte_eth_promiscuous_enable(port_id);
6307                 if (ret != 0)
6308                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6309                                 port_id, rte_strerror(-ret));
6310
6311                 ports[port_id].need_setup = 0;
6312                 ports[port_id].port_status = RTE_PORT_STOPPED;
6313         }
6314
6315 }
6316
6317 cmdline_parse_token_string_t cmd_createbonded_device_create =
6318                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6319                                 create, "create");
6320 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6321                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6322                                 bonded, "bonded");
6323 cmdline_parse_token_string_t cmd_createbonded_device_device =
6324                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6325                                 device, "device");
6326 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6327                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6328                                 mode, RTE_UINT8);
6329 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6330                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6331                                 socket, RTE_UINT8);
6332
6333 cmdline_parse_inst_t cmd_create_bonded_device = {
6334                 .f = cmd_create_bonded_device_parsed,
6335                 .help_str = "create bonded device <mode> <socket>: "
6336                         "Create a new bonded device with specific bonding mode and socket",
6337                 .data = NULL,
6338                 .tokens = {
6339                                 (void *)&cmd_createbonded_device_create,
6340                                 (void *)&cmd_createbonded_device_bonded,
6341                                 (void *)&cmd_createbonded_device_device,
6342                                 (void *)&cmd_createbonded_device_mode,
6343                                 (void *)&cmd_createbonded_device_socket,
6344                                 NULL
6345                 }
6346 };
6347
6348 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6349 struct cmd_set_bond_mac_addr_result {
6350         cmdline_fixed_string_t set;
6351         cmdline_fixed_string_t bonding;
6352         cmdline_fixed_string_t mac_addr;
6353         uint16_t port_num;
6354         struct rte_ether_addr address;
6355 };
6356
6357 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6358                 __rte_unused  struct cmdline *cl,
6359                 __rte_unused void *data)
6360 {
6361         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6362         int ret;
6363
6364         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6365                 return;
6366
6367         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6368
6369         /* check the return value and print it if is < 0 */
6370         if (ret < 0)
6371                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6372 }
6373
6374 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6375                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6376 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6377                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6378                                 "bonding");
6379 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6380                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6381                                 "mac_addr");
6382 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6383                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6384                                 port_num, RTE_UINT16);
6385 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6386                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6387
6388 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6389                 .f = cmd_set_bond_mac_addr_parsed,
6390                 .data = (void *) 0,
6391                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6392                 .tokens = {
6393                                 (void *)&cmd_set_bond_mac_addr_set,
6394                                 (void *)&cmd_set_bond_mac_addr_bonding,
6395                                 (void *)&cmd_set_bond_mac_addr_mac,
6396                                 (void *)&cmd_set_bond_mac_addr_portnum,
6397                                 (void *)&cmd_set_bond_mac_addr_addr,
6398                                 NULL
6399                 }
6400 };
6401
6402
6403 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6404 struct cmd_set_bond_mon_period_result {
6405         cmdline_fixed_string_t set;
6406         cmdline_fixed_string_t bonding;
6407         cmdline_fixed_string_t mon_period;
6408         uint16_t port_num;
6409         uint32_t period_ms;
6410 };
6411
6412 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6413                 __rte_unused  struct cmdline *cl,
6414                 __rte_unused void *data)
6415 {
6416         struct cmd_set_bond_mon_period_result *res = parsed_result;
6417         int ret;
6418
6419         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6420
6421         /* check the return value and print it if is < 0 */
6422         if (ret < 0)
6423                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6424 }
6425
6426 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6427                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6428                                 set, "set");
6429 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6430                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6431                                 bonding, "bonding");
6432 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6433                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6434                                 mon_period,     "mon_period");
6435 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6436                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6437                                 port_num, RTE_UINT16);
6438 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6439                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6440                                 period_ms, RTE_UINT32);
6441
6442 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6443                 .f = cmd_set_bond_mon_period_parsed,
6444                 .data = (void *) 0,
6445                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6446                 .tokens = {
6447                                 (void *)&cmd_set_bond_mon_period_set,
6448                                 (void *)&cmd_set_bond_mon_period_bonding,
6449                                 (void *)&cmd_set_bond_mon_period_mon_period,
6450                                 (void *)&cmd_set_bond_mon_period_portnum,
6451                                 (void *)&cmd_set_bond_mon_period_period_ms,
6452                                 NULL
6453                 }
6454 };
6455
6456
6457
6458 struct cmd_set_bonding_agg_mode_policy_result {
6459         cmdline_fixed_string_t set;
6460         cmdline_fixed_string_t bonding;
6461         cmdline_fixed_string_t agg_mode;
6462         uint16_t port_num;
6463         cmdline_fixed_string_t policy;
6464 };
6465
6466
6467 static void
6468 cmd_set_bonding_agg_mode(void *parsed_result,
6469                 __rte_unused struct cmdline *cl,
6470                 __rte_unused void *data)
6471 {
6472         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6473         uint8_t policy = AGG_BANDWIDTH;
6474
6475         if (!strcmp(res->policy, "bandwidth"))
6476                 policy = AGG_BANDWIDTH;
6477         else if (!strcmp(res->policy, "stable"))
6478                 policy = AGG_STABLE;
6479         else if (!strcmp(res->policy, "count"))
6480                 policy = AGG_COUNT;
6481
6482         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6483 }
6484
6485
6486 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6487         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6488                                 set, "set");
6489 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6490         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6491                                 bonding, "bonding");
6492
6493 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6494         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6495                                 agg_mode, "agg_mode");
6496
6497 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6498         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6499                                 port_num, RTE_UINT16);
6500
6501 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6502         TOKEN_STRING_INITIALIZER(
6503                         struct cmd_set_bonding_balance_xmit_policy_result,
6504                 policy, "stable#bandwidth#count");
6505
6506 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6507         .f = cmd_set_bonding_agg_mode,
6508         .data = (void *) 0,
6509         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6510         .tokens = {
6511                         (void *)&cmd_set_bonding_agg_mode_set,
6512                         (void *)&cmd_set_bonding_agg_mode_bonding,
6513                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6514                         (void *)&cmd_set_bonding_agg_mode_portnum,
6515                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6516                         NULL
6517                 }
6518 };
6519
6520
6521 #endif /* RTE_NET_BOND */
6522
6523 /* *** SET FORWARDING MODE *** */
6524 struct cmd_set_fwd_mode_result {
6525         cmdline_fixed_string_t set;
6526         cmdline_fixed_string_t fwd;
6527         cmdline_fixed_string_t mode;
6528 };
6529
6530 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6531                                     __rte_unused struct cmdline *cl,
6532                                     __rte_unused void *data)
6533 {
6534         struct cmd_set_fwd_mode_result *res = parsed_result;
6535
6536         retry_enabled = 0;
6537         set_pkt_forwarding_mode(res->mode);
6538 }
6539
6540 cmdline_parse_token_string_t cmd_setfwd_set =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6542 cmdline_parse_token_string_t cmd_setfwd_fwd =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6544 cmdline_parse_token_string_t cmd_setfwd_mode =
6545         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6546                 "" /* defined at init */);
6547
6548 cmdline_parse_inst_t cmd_set_fwd_mode = {
6549         .f = cmd_set_fwd_mode_parsed,
6550         .data = NULL,
6551         .help_str = NULL, /* defined at init */
6552         .tokens = {
6553                 (void *)&cmd_setfwd_set,
6554                 (void *)&cmd_setfwd_fwd,
6555                 (void *)&cmd_setfwd_mode,
6556                 NULL,
6557         },
6558 };
6559
6560 static void cmd_set_fwd_mode_init(void)
6561 {
6562         char *modes, *c;
6563         static char token[128];
6564         static char help[256];
6565         cmdline_parse_token_string_t *token_struct;
6566
6567         modes = list_pkt_forwarding_modes();
6568         snprintf(help, sizeof(help), "set fwd %s: "
6569                 "Set packet forwarding mode", modes);
6570         cmd_set_fwd_mode.help_str = help;
6571
6572         /* string token separator is # */
6573         for (c = token; *modes != '\0'; modes++)
6574                 if (*modes == '|')
6575                         *c++ = '#';
6576                 else
6577                         *c++ = *modes;
6578         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6579         token_struct->string_data.str = token;
6580 }
6581
6582 /* *** SET RETRY FORWARDING MODE *** */
6583 struct cmd_set_fwd_retry_mode_result {
6584         cmdline_fixed_string_t set;
6585         cmdline_fixed_string_t fwd;
6586         cmdline_fixed_string_t mode;
6587         cmdline_fixed_string_t retry;
6588 };
6589
6590 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6591                             __rte_unused struct cmdline *cl,
6592                             __rte_unused void *data)
6593 {
6594         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6595
6596         retry_enabled = 1;
6597         set_pkt_forwarding_mode(res->mode);
6598 }
6599
6600 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6601         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6602                         set, "set");
6603 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6604         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6605                         fwd, "fwd");
6606 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6608                         mode,
6609                 "" /* defined at init */);
6610 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6611         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6612                         retry, "retry");
6613
6614 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6615         .f = cmd_set_fwd_retry_mode_parsed,
6616         .data = NULL,
6617         .help_str = NULL, /* defined at init */
6618         .tokens = {
6619                 (void *)&cmd_setfwd_retry_set,
6620                 (void *)&cmd_setfwd_retry_fwd,
6621                 (void *)&cmd_setfwd_retry_mode,
6622                 (void *)&cmd_setfwd_retry_retry,
6623                 NULL,
6624         },
6625 };
6626
6627 static void cmd_set_fwd_retry_mode_init(void)
6628 {
6629         char *modes, *c;
6630         static char token[128];
6631         static char help[256];
6632         cmdline_parse_token_string_t *token_struct;
6633
6634         modes = list_pkt_forwarding_retry_modes();
6635         snprintf(help, sizeof(help), "set fwd %s retry: "
6636                 "Set packet forwarding mode with retry", modes);
6637         cmd_set_fwd_retry_mode.help_str = help;
6638
6639         /* string token separator is # */
6640         for (c = token; *modes != '\0'; modes++)
6641                 if (*modes == '|')
6642                         *c++ = '#';
6643                 else
6644                         *c++ = *modes;
6645         token_struct = (cmdline_parse_token_string_t *)
6646                 cmd_set_fwd_retry_mode.tokens[2];
6647         token_struct->string_data.str = token;
6648 }
6649
6650 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6651 struct cmd_set_burst_tx_retry_result {
6652         cmdline_fixed_string_t set;
6653         cmdline_fixed_string_t burst;
6654         cmdline_fixed_string_t tx;
6655         cmdline_fixed_string_t delay;
6656         uint32_t time;
6657         cmdline_fixed_string_t retry;
6658         uint32_t retry_num;
6659 };
6660
6661 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6662                                         __rte_unused struct cmdline *cl,
6663                                         __rte_unused void *data)
6664 {
6665         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6666
6667         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6668                 && !strcmp(res->tx, "tx")) {
6669                 if (!strcmp(res->delay, "delay"))
6670                         burst_tx_delay_time = res->time;
6671                 if (!strcmp(res->retry, "retry"))
6672                         burst_tx_retry_num = res->retry_num;
6673         }
6674
6675 }
6676
6677 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6678         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6679 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6680         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6681                                  "burst");
6682 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6683         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6684 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6686 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6687         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6688                                  RTE_UINT32);
6689 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6690         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6691 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6692         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6693                                  RTE_UINT32);
6694
6695 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6696         .f = cmd_set_burst_tx_retry_parsed,
6697         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6698         .tokens = {
6699                 (void *)&cmd_set_burst_tx_retry_set,
6700                 (void *)&cmd_set_burst_tx_retry_burst,
6701                 (void *)&cmd_set_burst_tx_retry_tx,
6702                 (void *)&cmd_set_burst_tx_retry_delay,
6703                 (void *)&cmd_set_burst_tx_retry_time,
6704                 (void *)&cmd_set_burst_tx_retry_retry,
6705                 (void *)&cmd_set_burst_tx_retry_retry_num,
6706                 NULL,
6707         },
6708 };
6709
6710 /* *** SET PROMISC MODE *** */
6711 struct cmd_set_promisc_mode_result {
6712         cmdline_fixed_string_t set;
6713         cmdline_fixed_string_t promisc;
6714         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6715         uint16_t port_num;               /* valid if "allports" argument == 0 */
6716         cmdline_fixed_string_t mode;
6717 };
6718
6719 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6720                                         __rte_unused struct cmdline *cl,
6721                                         void *allports)
6722 {
6723         struct cmd_set_promisc_mode_result *res = parsed_result;
6724         int enable;
6725         portid_t i;
6726
6727         if (!strcmp(res->mode, "on"))
6728                 enable = 1;
6729         else
6730                 enable = 0;
6731
6732         /* all ports */
6733         if (allports) {
6734                 RTE_ETH_FOREACH_DEV(i)
6735                         eth_set_promisc_mode(i, enable);
6736         } else {
6737                 eth_set_promisc_mode(res->port_num, enable);
6738         }
6739 }
6740
6741 cmdline_parse_token_string_t cmd_setpromisc_set =
6742         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6743 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6745                                  "promisc");
6746 cmdline_parse_token_string_t cmd_setpromisc_portall =
6747         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6748                                  "all");
6749 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6750         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6751                               RTE_UINT16);
6752 cmdline_parse_token_string_t cmd_setpromisc_mode =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6754                                  "on#off");
6755
6756 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6757         .f = cmd_set_promisc_mode_parsed,
6758         .data = (void *)1,
6759         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6760         .tokens = {
6761                 (void *)&cmd_setpromisc_set,
6762                 (void *)&cmd_setpromisc_promisc,
6763                 (void *)&cmd_setpromisc_portall,
6764                 (void *)&cmd_setpromisc_mode,
6765                 NULL,
6766         },
6767 };
6768
6769 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6770         .f = cmd_set_promisc_mode_parsed,
6771         .data = (void *)0,
6772         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6773         .tokens = {
6774                 (void *)&cmd_setpromisc_set,
6775                 (void *)&cmd_setpromisc_promisc,
6776                 (void *)&cmd_setpromisc_portnum,
6777                 (void *)&cmd_setpromisc_mode,
6778                 NULL,
6779         },
6780 };
6781
6782 /* *** SET ALLMULTI MODE *** */
6783 struct cmd_set_allmulti_mode_result {
6784         cmdline_fixed_string_t set;
6785         cmdline_fixed_string_t allmulti;
6786         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6787         uint16_t port_num;               /* valid if "allports" argument == 0 */
6788         cmdline_fixed_string_t mode;
6789 };
6790
6791 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6792                                         __rte_unused struct cmdline *cl,
6793                                         void *allports)
6794 {
6795         struct cmd_set_allmulti_mode_result *res = parsed_result;
6796         int enable;
6797         portid_t i;
6798
6799         if (!strcmp(res->mode, "on"))
6800                 enable = 1;
6801         else
6802                 enable = 0;
6803
6804         /* all ports */
6805         if (allports) {
6806                 RTE_ETH_FOREACH_DEV(i) {
6807                         eth_set_allmulticast_mode(i, enable);
6808                 }
6809         }
6810         else {
6811                 eth_set_allmulticast_mode(res->port_num, enable);
6812         }
6813 }
6814
6815 cmdline_parse_token_string_t cmd_setallmulti_set =
6816         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6817 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6819                                  "allmulti");
6820 cmdline_parse_token_string_t cmd_setallmulti_portall =
6821         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6822                                  "all");
6823 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6824         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6825                               RTE_UINT16);
6826 cmdline_parse_token_string_t cmd_setallmulti_mode =
6827         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6828                                  "on#off");
6829
6830 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6831         .f = cmd_set_allmulti_mode_parsed,
6832         .data = (void *)1,
6833         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6834         .tokens = {
6835                 (void *)&cmd_setallmulti_set,
6836                 (void *)&cmd_setallmulti_allmulti,
6837                 (void *)&cmd_setallmulti_portall,
6838                 (void *)&cmd_setallmulti_mode,
6839                 NULL,
6840         },
6841 };
6842
6843 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6844         .f = cmd_set_allmulti_mode_parsed,
6845         .data = (void *)0,
6846         .help_str = "set allmulti <port_id> on|off: "
6847                 "Set allmulti mode on port_id",
6848         .tokens = {
6849                 (void *)&cmd_setallmulti_set,
6850                 (void *)&cmd_setallmulti_allmulti,
6851                 (void *)&cmd_setallmulti_portnum,
6852                 (void *)&cmd_setallmulti_mode,
6853                 NULL,
6854         },
6855 };
6856
6857 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6858 struct cmd_link_flow_ctrl_set_result {
6859         cmdline_fixed_string_t set;
6860         cmdline_fixed_string_t flow_ctrl;
6861         cmdline_fixed_string_t rx;
6862         cmdline_fixed_string_t rx_lfc_mode;
6863         cmdline_fixed_string_t tx;
6864         cmdline_fixed_string_t tx_lfc_mode;
6865         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6866         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6867         cmdline_fixed_string_t autoneg_str;
6868         cmdline_fixed_string_t autoneg;
6869         cmdline_fixed_string_t hw_str;
6870         uint32_t high_water;
6871         cmdline_fixed_string_t lw_str;
6872         uint32_t low_water;
6873         cmdline_fixed_string_t pt_str;
6874         uint16_t pause_time;
6875         cmdline_fixed_string_t xon_str;
6876         uint16_t send_xon;
6877         portid_t port_id;
6878 };
6879
6880 cmdline_parse_token_string_t cmd_lfc_set_set =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 set, "set");
6883 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 flow_ctrl, "flow_ctrl");
6886 cmdline_parse_token_string_t cmd_lfc_set_rx =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 rx, "rx");
6889 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 rx_lfc_mode, "on#off");
6892 cmdline_parse_token_string_t cmd_lfc_set_tx =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 tx, "tx");
6895 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 tx_lfc_mode, "on#off");
6898 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 hw_str, "high_water");
6901 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 high_water, RTE_UINT32);
6904 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 lw_str, "low_water");
6907 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 low_water, RTE_UINT32);
6910 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 pt_str, "pause_time");
6913 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6914         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 pause_time, RTE_UINT16);
6916 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 xon_str, "send_xon");
6919 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6920         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 send_xon, RTE_UINT16);
6922 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6925 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 mac_ctrl_frame_fwd_mode, "on#off");
6928 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6929         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 autoneg_str, "autoneg");
6931 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6933                                 autoneg, "on#off");
6934 cmdline_parse_token_num_t cmd_lfc_set_portid =
6935         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6936                                 port_id, RTE_UINT16);
6937
6938 /* forward declaration */
6939 static void
6940 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6941                               void *data);
6942
6943 cmdline_parse_inst_t cmd_link_flow_control_set = {
6944         .f = cmd_link_flow_ctrl_set_parsed,
6945         .data = NULL,
6946         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6947                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6948                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6949         .tokens = {
6950                 (void *)&cmd_lfc_set_set,
6951                 (void *)&cmd_lfc_set_flow_ctrl,
6952                 (void *)&cmd_lfc_set_rx,
6953                 (void *)&cmd_lfc_set_rx_mode,
6954                 (void *)&cmd_lfc_set_tx,
6955                 (void *)&cmd_lfc_set_tx_mode,
6956                 (void *)&cmd_lfc_set_high_water,
6957                 (void *)&cmd_lfc_set_low_water,
6958                 (void *)&cmd_lfc_set_pause_time,
6959                 (void *)&cmd_lfc_set_send_xon,
6960                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6961                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6962                 (void *)&cmd_lfc_set_autoneg_str,
6963                 (void *)&cmd_lfc_set_autoneg,
6964                 (void *)&cmd_lfc_set_portid,
6965                 NULL,
6966         },
6967 };
6968
6969 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6970         .f = cmd_link_flow_ctrl_set_parsed,
6971         .data = (void *)&cmd_link_flow_control_set_rx,
6972         .help_str = "set flow_ctrl rx on|off <port_id>: "
6973                 "Change rx flow control parameter",
6974         .tokens = {
6975                 (void *)&cmd_lfc_set_set,
6976                 (void *)&cmd_lfc_set_flow_ctrl,
6977                 (void *)&cmd_lfc_set_rx,
6978                 (void *)&cmd_lfc_set_rx_mode,
6979                 (void *)&cmd_lfc_set_portid,
6980                 NULL,
6981         },
6982 };
6983
6984 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6985         .f = cmd_link_flow_ctrl_set_parsed,
6986         .data = (void *)&cmd_link_flow_control_set_tx,
6987         .help_str = "set flow_ctrl tx on|off <port_id>: "
6988                 "Change tx flow control parameter",
6989         .tokens = {
6990                 (void *)&cmd_lfc_set_set,
6991                 (void *)&cmd_lfc_set_flow_ctrl,
6992                 (void *)&cmd_lfc_set_tx,
6993                 (void *)&cmd_lfc_set_tx_mode,
6994                 (void *)&cmd_lfc_set_portid,
6995                 NULL,
6996         },
6997 };
6998
6999 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7000         .f = cmd_link_flow_ctrl_set_parsed,
7001         .data = (void *)&cmd_link_flow_control_set_hw,
7002         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7003                 "Change high water flow control parameter",
7004         .tokens = {
7005                 (void *)&cmd_lfc_set_set,
7006                 (void *)&cmd_lfc_set_flow_ctrl,
7007                 (void *)&cmd_lfc_set_high_water_str,
7008                 (void *)&cmd_lfc_set_high_water,
7009                 (void *)&cmd_lfc_set_portid,
7010                 NULL,
7011         },
7012 };
7013
7014 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7015         .f = cmd_link_flow_ctrl_set_parsed,
7016         .data = (void *)&cmd_link_flow_control_set_lw,
7017         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7018                 "Change low water flow control parameter",
7019         .tokens = {
7020                 (void *)&cmd_lfc_set_set,
7021                 (void *)&cmd_lfc_set_flow_ctrl,
7022                 (void *)&cmd_lfc_set_low_water_str,
7023                 (void *)&cmd_lfc_set_low_water,
7024                 (void *)&cmd_lfc_set_portid,
7025                 NULL,
7026         },
7027 };
7028
7029 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7030         .f = cmd_link_flow_ctrl_set_parsed,
7031         .data = (void *)&cmd_link_flow_control_set_pt,
7032         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7033                 "Change pause time flow control parameter",
7034         .tokens = {
7035                 (void *)&cmd_lfc_set_set,
7036                 (void *)&cmd_lfc_set_flow_ctrl,
7037                 (void *)&cmd_lfc_set_pause_time_str,
7038                 (void *)&cmd_lfc_set_pause_time,
7039                 (void *)&cmd_lfc_set_portid,
7040                 NULL,
7041         },
7042 };
7043
7044 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7045         .f = cmd_link_flow_ctrl_set_parsed,
7046         .data = (void *)&cmd_link_flow_control_set_xon,
7047         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7048                 "Change send_xon flow control parameter",
7049         .tokens = {
7050                 (void *)&cmd_lfc_set_set,
7051                 (void *)&cmd_lfc_set_flow_ctrl,
7052                 (void *)&cmd_lfc_set_send_xon_str,
7053                 (void *)&cmd_lfc_set_send_xon,
7054                 (void *)&cmd_lfc_set_portid,
7055                 NULL,
7056         },
7057 };
7058
7059 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7060         .f = cmd_link_flow_ctrl_set_parsed,
7061         .data = (void *)&cmd_link_flow_control_set_macfwd,
7062         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7063                 "Change mac ctrl fwd flow control parameter",
7064         .tokens = {
7065                 (void *)&cmd_lfc_set_set,
7066                 (void *)&cmd_lfc_set_flow_ctrl,
7067                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7068                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7069                 (void *)&cmd_lfc_set_portid,
7070                 NULL,
7071         },
7072 };
7073
7074 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7075         .f = cmd_link_flow_ctrl_set_parsed,
7076         .data = (void *)&cmd_link_flow_control_set_autoneg,
7077         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7078                 "Change autoneg flow control parameter",
7079         .tokens = {
7080                 (void *)&cmd_lfc_set_set,
7081                 (void *)&cmd_lfc_set_flow_ctrl,
7082                 (void *)&cmd_lfc_set_autoneg_str,
7083                 (void *)&cmd_lfc_set_autoneg,
7084                 (void *)&cmd_lfc_set_portid,
7085                 NULL,
7086         },
7087 };
7088
7089 static void
7090 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7091                               __rte_unused struct cmdline *cl,
7092                               void *data)
7093 {
7094         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7095         cmdline_parse_inst_t *cmd = data;
7096         struct rte_eth_fc_conf fc_conf;
7097         int rx_fc_en = 0;
7098         int tx_fc_en = 0;
7099         int ret;
7100
7101         /*
7102          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7103          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7104          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7105          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7106          */
7107         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7108                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7109         };
7110
7111         /* Partial command line, retrieve current configuration */
7112         if (cmd) {
7113                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7114                 if (ret != 0) {
7115                         printf("cannot get current flow ctrl parameters, return"
7116                                "code = %d\n", ret);
7117                         return;
7118                 }
7119
7120                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7121                     (fc_conf.mode == RTE_FC_FULL))
7122                         rx_fc_en = 1;
7123                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7124                     (fc_conf.mode == RTE_FC_FULL))
7125                         tx_fc_en = 1;
7126         }
7127
7128         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7129                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7130
7131         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7132                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7133
7134         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7137                 fc_conf.high_water = res->high_water;
7138
7139         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7140                 fc_conf.low_water = res->low_water;
7141
7142         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7143                 fc_conf.pause_time = res->pause_time;
7144
7145         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7146                 fc_conf.send_xon = res->send_xon;
7147
7148         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7149                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7150                         fc_conf.mac_ctrl_frame_fwd = 1;
7151                 else
7152                         fc_conf.mac_ctrl_frame_fwd = 0;
7153         }
7154
7155         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7156                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7157
7158         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7159         if (ret != 0)
7160                 printf("bad flow contrl parameter, return code = %d \n", ret);
7161 }
7162
7163 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7164 struct cmd_priority_flow_ctrl_set_result {
7165         cmdline_fixed_string_t set;
7166         cmdline_fixed_string_t pfc_ctrl;
7167         cmdline_fixed_string_t rx;
7168         cmdline_fixed_string_t rx_pfc_mode;
7169         cmdline_fixed_string_t tx;
7170         cmdline_fixed_string_t tx_pfc_mode;
7171         uint32_t high_water;
7172         uint32_t low_water;
7173         uint16_t pause_time;
7174         uint8_t  priority;
7175         portid_t port_id;
7176 };
7177
7178 static void
7179 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7180                        __rte_unused struct cmdline *cl,
7181                        __rte_unused void *data)
7182 {
7183         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7184         struct rte_eth_pfc_conf pfc_conf;
7185         int rx_fc_enable, tx_fc_enable;
7186         int ret;
7187
7188         /*
7189          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7190          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7191          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7192          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7193          */
7194         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7195                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7196         };
7197
7198         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7199         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7200         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7201         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7202         pfc_conf.fc.high_water = res->high_water;
7203         pfc_conf.fc.low_water  = res->low_water;
7204         pfc_conf.fc.pause_time = res->pause_time;
7205         pfc_conf.priority      = res->priority;
7206
7207         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7208         if (ret != 0)
7209                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7210 }
7211
7212 cmdline_parse_token_string_t cmd_pfc_set_set =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 set, "set");
7215 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 pfc_ctrl, "pfc_ctrl");
7218 cmdline_parse_token_string_t cmd_pfc_set_rx =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 rx, "rx");
7221 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7222         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 rx_pfc_mode, "on#off");
7224 cmdline_parse_token_string_t cmd_pfc_set_tx =
7225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 tx, "tx");
7227 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 tx_pfc_mode, "on#off");
7230 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 high_water, RTE_UINT32);
7233 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7234         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 low_water, RTE_UINT32);
7236 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7237         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 pause_time, RTE_UINT16);
7239 cmdline_parse_token_num_t cmd_pfc_set_priority =
7240         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7241                                 priority, RTE_UINT8);
7242 cmdline_parse_token_num_t cmd_pfc_set_portid =
7243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7244                                 port_id, RTE_UINT16);
7245
7246 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7247         .f = cmd_priority_flow_ctrl_set_parsed,
7248         .data = NULL,
7249         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7250                 "<pause_time> <priority> <port_id>: "
7251                 "Configure the Ethernet priority flow control",
7252         .tokens = {
7253                 (void *)&cmd_pfc_set_set,
7254                 (void *)&cmd_pfc_set_flow_ctrl,
7255                 (void *)&cmd_pfc_set_rx,
7256                 (void *)&cmd_pfc_set_rx_mode,
7257                 (void *)&cmd_pfc_set_tx,
7258                 (void *)&cmd_pfc_set_tx_mode,
7259                 (void *)&cmd_pfc_set_high_water,
7260                 (void *)&cmd_pfc_set_low_water,
7261                 (void *)&cmd_pfc_set_pause_time,
7262                 (void *)&cmd_pfc_set_priority,
7263                 (void *)&cmd_pfc_set_portid,
7264                 NULL,
7265         },
7266 };
7267
7268 /* *** RESET CONFIGURATION *** */
7269 struct cmd_reset_result {
7270         cmdline_fixed_string_t reset;
7271         cmdline_fixed_string_t def;
7272 };
7273
7274 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7275                              struct cmdline *cl,
7276                              __rte_unused void *data)
7277 {
7278         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7279         set_def_fwd_config();
7280 }
7281
7282 cmdline_parse_token_string_t cmd_reset_set =
7283         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7284 cmdline_parse_token_string_t cmd_reset_def =
7285         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7286                                  "default");
7287
7288 cmdline_parse_inst_t cmd_reset = {
7289         .f = cmd_reset_parsed,
7290         .data = NULL,
7291         .help_str = "set default: Reset default forwarding configuration",
7292         .tokens = {
7293                 (void *)&cmd_reset_set,
7294                 (void *)&cmd_reset_def,
7295                 NULL,
7296         },
7297 };
7298
7299 /* *** START FORWARDING *** */
7300 struct cmd_start_result {
7301         cmdline_fixed_string_t start;
7302 };
7303
7304 cmdline_parse_token_string_t cmd_start_start =
7305         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7306
7307 static void cmd_start_parsed(__rte_unused void *parsed_result,
7308                              __rte_unused struct cmdline *cl,
7309                              __rte_unused void *data)
7310 {
7311         start_packet_forwarding(0);
7312 }
7313
7314 cmdline_parse_inst_t cmd_start = {
7315         .f = cmd_start_parsed,
7316         .data = NULL,
7317         .help_str = "start: Start packet forwarding",
7318         .tokens = {
7319                 (void *)&cmd_start_start,
7320                 NULL,
7321         },
7322 };
7323
7324 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7325 struct cmd_start_tx_first_result {
7326         cmdline_fixed_string_t start;
7327         cmdline_fixed_string_t tx_first;
7328 };
7329
7330 static void
7331 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7332                           __rte_unused struct cmdline *cl,
7333                           __rte_unused void *data)
7334 {
7335         start_packet_forwarding(1);
7336 }
7337
7338 cmdline_parse_token_string_t cmd_start_tx_first_start =
7339         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7340                                  "start");
7341 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7342         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7343                                  tx_first, "tx_first");
7344
7345 cmdline_parse_inst_t cmd_start_tx_first = {
7346         .f = cmd_start_tx_first_parsed,
7347         .data = NULL,
7348         .help_str = "start tx_first: Start packet forwarding, "
7349                 "after sending 1 burst of packets",
7350         .tokens = {
7351                 (void *)&cmd_start_tx_first_start,
7352                 (void *)&cmd_start_tx_first_tx_first,
7353                 NULL,
7354         },
7355 };
7356
7357 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7358 struct cmd_start_tx_first_n_result {
7359         cmdline_fixed_string_t start;
7360         cmdline_fixed_string_t tx_first;
7361         uint32_t tx_num;
7362 };
7363
7364 static void
7365 cmd_start_tx_first_n_parsed(void *parsed_result,
7366                           __rte_unused struct cmdline *cl,
7367                           __rte_unused void *data)
7368 {
7369         struct cmd_start_tx_first_n_result *res = parsed_result;
7370
7371         start_packet_forwarding(res->tx_num);
7372 }
7373
7374 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7375         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7376                         start, "start");
7377 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7378         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7379                         tx_first, "tx_first");
7380 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7381         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7382                         tx_num, RTE_UINT32);
7383
7384 cmdline_parse_inst_t cmd_start_tx_first_n = {
7385         .f = cmd_start_tx_first_n_parsed,
7386         .data = NULL,
7387         .help_str = "start tx_first <num>: "
7388                 "packet forwarding, after sending <num> bursts of packets",
7389         .tokens = {
7390                 (void *)&cmd_start_tx_first_n_start,
7391                 (void *)&cmd_start_tx_first_n_tx_first,
7392                 (void *)&cmd_start_tx_first_n_tx_num,
7393                 NULL,
7394         },
7395 };
7396
7397 /* *** SET LINK UP *** */
7398 struct cmd_set_link_up_result {
7399         cmdline_fixed_string_t set;
7400         cmdline_fixed_string_t link_up;
7401         cmdline_fixed_string_t port;
7402         portid_t port_id;
7403 };
7404
7405 cmdline_parse_token_string_t cmd_set_link_up_set =
7406         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7407 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7409                                 "link-up");
7410 cmdline_parse_token_string_t cmd_set_link_up_port =
7411         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7412 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7413         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7414                                 RTE_UINT16);
7415
7416 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7417                              __rte_unused struct cmdline *cl,
7418                              __rte_unused void *data)
7419 {
7420         struct cmd_set_link_up_result *res = parsed_result;
7421         dev_set_link_up(res->port_id);
7422 }
7423
7424 cmdline_parse_inst_t cmd_set_link_up = {
7425         .f = cmd_set_link_up_parsed,
7426         .data = NULL,
7427         .help_str = "set link-up port <port id>",
7428         .tokens = {
7429                 (void *)&cmd_set_link_up_set,
7430                 (void *)&cmd_set_link_up_link_up,
7431                 (void *)&cmd_set_link_up_port,
7432                 (void *)&cmd_set_link_up_port_id,
7433                 NULL,
7434         },
7435 };
7436
7437 /* *** SET LINK DOWN *** */
7438 struct cmd_set_link_down_result {
7439         cmdline_fixed_string_t set;
7440         cmdline_fixed_string_t link_down;
7441         cmdline_fixed_string_t port;
7442         portid_t port_id;
7443 };
7444
7445 cmdline_parse_token_string_t cmd_set_link_down_set =
7446         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7447 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7448         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7449                                 "link-down");
7450 cmdline_parse_token_string_t cmd_set_link_down_port =
7451         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7452 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7453         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7454                                 RTE_UINT16);
7455
7456 static void cmd_set_link_down_parsed(
7457                                 __rte_unused void *parsed_result,
7458                                 __rte_unused struct cmdline *cl,
7459                                 __rte_unused void *data)
7460 {
7461         struct cmd_set_link_down_result *res = parsed_result;
7462         dev_set_link_down(res->port_id);
7463 }
7464
7465 cmdline_parse_inst_t cmd_set_link_down = {
7466         .f = cmd_set_link_down_parsed,
7467         .data = NULL,
7468         .help_str = "set link-down port <port id>",
7469         .tokens = {
7470                 (void *)&cmd_set_link_down_set,
7471                 (void *)&cmd_set_link_down_link_down,
7472                 (void *)&cmd_set_link_down_port,
7473                 (void *)&cmd_set_link_down_port_id,
7474                 NULL,
7475         },
7476 };
7477
7478 /* *** SHOW CFG *** */
7479 struct cmd_showcfg_result {
7480         cmdline_fixed_string_t show;
7481         cmdline_fixed_string_t cfg;
7482         cmdline_fixed_string_t what;
7483 };
7484
7485 static void cmd_showcfg_parsed(void *parsed_result,
7486                                __rte_unused struct cmdline *cl,
7487                                __rte_unused void *data)
7488 {
7489         struct cmd_showcfg_result *res = parsed_result;
7490         if (!strcmp(res->what, "rxtx"))
7491                 rxtx_config_display();
7492         else if (!strcmp(res->what, "cores"))
7493                 fwd_lcores_config_display();
7494         else if (!strcmp(res->what, "fwd"))
7495                 pkt_fwd_config_display(&cur_fwd_config);
7496         else if (!strcmp(res->what, "rxoffs"))
7497                 show_rx_pkt_offsets();
7498         else if (!strcmp(res->what, "rxpkts"))
7499                 show_rx_pkt_segments();
7500         else if (!strcmp(res->what, "txpkts"))
7501                 show_tx_pkt_segments();
7502         else if (!strcmp(res->what, "txtimes"))
7503                 show_tx_pkt_times();
7504 }
7505
7506 cmdline_parse_token_string_t cmd_showcfg_show =
7507         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7508 cmdline_parse_token_string_t cmd_showcfg_port =
7509         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7510 cmdline_parse_token_string_t cmd_showcfg_what =
7511         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7512                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7513
7514 cmdline_parse_inst_t cmd_showcfg = {
7515         .f = cmd_showcfg_parsed,
7516         .data = NULL,
7517         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7518         .tokens = {
7519                 (void *)&cmd_showcfg_show,
7520                 (void *)&cmd_showcfg_port,
7521                 (void *)&cmd_showcfg_what,
7522                 NULL,
7523         },
7524 };
7525
7526 /* *** SHOW ALL PORT INFO *** */
7527 struct cmd_showportall_result {
7528         cmdline_fixed_string_t show;
7529         cmdline_fixed_string_t port;
7530         cmdline_fixed_string_t what;
7531         cmdline_fixed_string_t all;
7532 };
7533
7534 static void cmd_showportall_parsed(void *parsed_result,
7535                                 __rte_unused struct cmdline *cl,
7536                                 __rte_unused void *data)
7537 {
7538         portid_t i;
7539
7540         struct cmd_showportall_result *res = parsed_result;
7541         if (!strcmp(res->show, "clear")) {
7542                 if (!strcmp(res->what, "stats"))
7543                         RTE_ETH_FOREACH_DEV(i)
7544                                 nic_stats_clear(i);
7545                 else if (!strcmp(res->what, "xstats"))
7546                         RTE_ETH_FOREACH_DEV(i)
7547                                 nic_xstats_clear(i);
7548         } else if (!strcmp(res->what, "info"))
7549                 RTE_ETH_FOREACH_DEV(i)
7550                         port_infos_display(i);
7551         else if (!strcmp(res->what, "summary")) {
7552                 port_summary_header_display();
7553                 RTE_ETH_FOREACH_DEV(i)
7554                         port_summary_display(i);
7555         }
7556         else if (!strcmp(res->what, "stats"))
7557                 RTE_ETH_FOREACH_DEV(i)
7558                         nic_stats_display(i);
7559         else if (!strcmp(res->what, "xstats"))
7560                 RTE_ETH_FOREACH_DEV(i)
7561                         nic_xstats_display(i);
7562 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7563         else if (!strcmp(res->what, "fdir"))
7564                 RTE_ETH_FOREACH_DEV(i)
7565                         fdir_get_infos(i);
7566 #endif
7567         else if (!strcmp(res->what, "dcb_tc"))
7568                 RTE_ETH_FOREACH_DEV(i)
7569                         port_dcb_info_display(i);
7570         else if (!strcmp(res->what, "cap"))
7571                 RTE_ETH_FOREACH_DEV(i)
7572                         port_offload_cap_display(i);
7573 }
7574
7575 cmdline_parse_token_string_t cmd_showportall_show =
7576         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7577                                  "show#clear");
7578 cmdline_parse_token_string_t cmd_showportall_port =
7579         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7580 cmdline_parse_token_string_t cmd_showportall_what =
7581         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7582                                  "info#summary#stats#xstats#fdir#dcb_tc#cap");
7583 cmdline_parse_token_string_t cmd_showportall_all =
7584         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7585 cmdline_parse_inst_t cmd_showportall = {
7586         .f = cmd_showportall_parsed,
7587         .data = NULL,
7588         .help_str = "show|clear port "
7589                 "info|summary|stats|xstats|fdir|dcb_tc|cap all",
7590         .tokens = {
7591                 (void *)&cmd_showportall_show,
7592                 (void *)&cmd_showportall_port,
7593                 (void *)&cmd_showportall_what,
7594                 (void *)&cmd_showportall_all,
7595                 NULL,
7596         },
7597 };
7598
7599 /* *** SHOW PORT INFO *** */
7600 struct cmd_showport_result {
7601         cmdline_fixed_string_t show;
7602         cmdline_fixed_string_t port;
7603         cmdline_fixed_string_t what;
7604         uint16_t portnum;
7605 };
7606
7607 static void cmd_showport_parsed(void *parsed_result,
7608                                 __rte_unused struct cmdline *cl,
7609                                 __rte_unused void *data)
7610 {
7611         struct cmd_showport_result *res = parsed_result;
7612         if (!strcmp(res->show, "clear")) {
7613                 if (!strcmp(res->what, "stats"))
7614                         nic_stats_clear(res->portnum);
7615                 else if (!strcmp(res->what, "xstats"))
7616                         nic_xstats_clear(res->portnum);
7617         } else if (!strcmp(res->what, "info"))
7618                 port_infos_display(res->portnum);
7619         else if (!strcmp(res->what, "summary")) {
7620                 port_summary_header_display();
7621                 port_summary_display(res->portnum);
7622         }
7623         else if (!strcmp(res->what, "stats"))
7624                 nic_stats_display(res->portnum);
7625         else if (!strcmp(res->what, "xstats"))
7626                 nic_xstats_display(res->portnum);
7627 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7628         else if (!strcmp(res->what, "fdir"))
7629                  fdir_get_infos(res->portnum);
7630 #endif
7631         else if (!strcmp(res->what, "dcb_tc"))
7632                 port_dcb_info_display(res->portnum);
7633         else if (!strcmp(res->what, "cap"))
7634                 port_offload_cap_display(res->portnum);
7635 }
7636
7637 cmdline_parse_token_string_t cmd_showport_show =
7638         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7639                                  "show#clear");
7640 cmdline_parse_token_string_t cmd_showport_port =
7641         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7642 cmdline_parse_token_string_t cmd_showport_what =
7643         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7644                                  "info#summary#stats#xstats#fdir#dcb_tc#cap");
7645 cmdline_parse_token_num_t cmd_showport_portnum =
7646         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7647
7648 cmdline_parse_inst_t cmd_showport = {
7649         .f = cmd_showport_parsed,
7650         .data = NULL,
7651         .help_str = "show|clear port "
7652                 "info|summary|stats|xstats|fdir|dcb_tc|cap "
7653                 "<port_id>",
7654         .tokens = {
7655                 (void *)&cmd_showport_show,
7656                 (void *)&cmd_showport_port,
7657                 (void *)&cmd_showport_what,
7658                 (void *)&cmd_showport_portnum,
7659                 NULL,
7660         },
7661 };
7662
7663 /* *** SHOW DEVICE INFO *** */
7664 struct cmd_showdevice_result {
7665         cmdline_fixed_string_t show;
7666         cmdline_fixed_string_t device;
7667         cmdline_fixed_string_t what;
7668         cmdline_fixed_string_t identifier;
7669 };
7670
7671 static void cmd_showdevice_parsed(void *parsed_result,
7672                                 __rte_unused struct cmdline *cl,
7673                                 __rte_unused void *data)
7674 {
7675         struct cmd_showdevice_result *res = parsed_result;
7676         if (!strcmp(res->what, "info")) {
7677                 if (!strcmp(res->identifier, "all"))
7678                         device_infos_display(NULL);
7679                 else
7680                         device_infos_display(res->identifier);
7681         }
7682 }
7683
7684 cmdline_parse_token_string_t cmd_showdevice_show =
7685         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7686                                  "show");
7687 cmdline_parse_token_string_t cmd_showdevice_device =
7688         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7689 cmdline_parse_token_string_t cmd_showdevice_what =
7690         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7691                                  "info");
7692 cmdline_parse_token_string_t cmd_showdevice_identifier =
7693         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7694                         identifier, NULL);
7695
7696 cmdline_parse_inst_t cmd_showdevice = {
7697         .f = cmd_showdevice_parsed,
7698         .data = NULL,
7699         .help_str = "show device info <identifier>|all",
7700         .tokens = {
7701                 (void *)&cmd_showdevice_show,
7702                 (void *)&cmd_showdevice_device,
7703                 (void *)&cmd_showdevice_what,
7704                 (void *)&cmd_showdevice_identifier,
7705                 NULL,
7706         },
7707 };
7708
7709 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7710 struct cmd_showeeprom_result {
7711         cmdline_fixed_string_t show;
7712         cmdline_fixed_string_t port;
7713         uint16_t portnum;
7714         cmdline_fixed_string_t type;
7715 };
7716
7717 static void cmd_showeeprom_parsed(void *parsed_result,
7718                 __rte_unused struct cmdline *cl,
7719                 __rte_unused void *data)
7720 {
7721         struct cmd_showeeprom_result *res = parsed_result;
7722
7723         if (!strcmp(res->type, "eeprom"))
7724                 port_eeprom_display(res->portnum);
7725         else if (!strcmp(res->type, "module_eeprom"))
7726                 port_module_eeprom_display(res->portnum);
7727         else
7728                 printf("Unknown argument\n");
7729 }
7730
7731 cmdline_parse_token_string_t cmd_showeeprom_show =
7732         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7733 cmdline_parse_token_string_t cmd_showeeprom_port =
7734         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7735 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7736         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7737                         RTE_UINT16);
7738 cmdline_parse_token_string_t cmd_showeeprom_type =
7739         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7740
7741 cmdline_parse_inst_t cmd_showeeprom = {
7742         .f = cmd_showeeprom_parsed,
7743         .data = NULL,
7744         .help_str = "show port <port_id> module_eeprom|eeprom",
7745         .tokens = {
7746                 (void *)&cmd_showeeprom_show,
7747                 (void *)&cmd_showeeprom_port,
7748                 (void *)&cmd_showeeprom_portnum,
7749                 (void *)&cmd_showeeprom_type,
7750                 NULL,
7751         },
7752 };
7753
7754 /* *** SHOW QUEUE INFO *** */
7755 struct cmd_showqueue_result {
7756         cmdline_fixed_string_t show;
7757         cmdline_fixed_string_t type;
7758         cmdline_fixed_string_t what;
7759         uint16_t portnum;
7760         uint16_t queuenum;
7761 };
7762
7763 static void
7764 cmd_showqueue_parsed(void *parsed_result,
7765         __rte_unused struct cmdline *cl,
7766         __rte_unused void *data)
7767 {
7768         struct cmd_showqueue_result *res = parsed_result;
7769
7770         if (!strcmp(res->type, "rxq"))
7771                 rx_queue_infos_display(res->portnum, res->queuenum);
7772         else if (!strcmp(res->type, "txq"))
7773                 tx_queue_infos_display(res->portnum, res->queuenum);
7774 }
7775
7776 cmdline_parse_token_string_t cmd_showqueue_show =
7777         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7778 cmdline_parse_token_string_t cmd_showqueue_type =
7779         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7780 cmdline_parse_token_string_t cmd_showqueue_what =
7781         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7782 cmdline_parse_token_num_t cmd_showqueue_portnum =
7783         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7784                 RTE_UINT16);
7785 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7786         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7787                 RTE_UINT16);
7788
7789 cmdline_parse_inst_t cmd_showqueue = {
7790         .f = cmd_showqueue_parsed,
7791         .data = NULL,
7792         .help_str = "show rxq|txq info <port_id> <queue_id>",
7793         .tokens = {
7794                 (void *)&cmd_showqueue_show,
7795                 (void *)&cmd_showqueue_type,
7796                 (void *)&cmd_showqueue_what,
7797                 (void *)&cmd_showqueue_portnum,
7798                 (void *)&cmd_showqueue_queuenum,
7799                 NULL,
7800         },
7801 };
7802
7803 /* show/clear fwd engine statistics */
7804 struct fwd_result {
7805         cmdline_fixed_string_t action;
7806         cmdline_fixed_string_t fwd;
7807         cmdline_fixed_string_t stats;
7808         cmdline_fixed_string_t all;
7809 };
7810
7811 cmdline_parse_token_string_t cmd_fwd_action =
7812         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7813 cmdline_parse_token_string_t cmd_fwd_fwd =
7814         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7815 cmdline_parse_token_string_t cmd_fwd_stats =
7816         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7817 cmdline_parse_token_string_t cmd_fwd_all =
7818         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7819
7820 static void
7821 cmd_showfwdall_parsed(void *parsed_result,
7822                       __rte_unused struct cmdline *cl,
7823                       __rte_unused void *data)
7824 {
7825         struct fwd_result *res = parsed_result;
7826
7827         if (!strcmp(res->action, "show"))
7828                 fwd_stats_display();
7829         else
7830                 fwd_stats_reset();
7831 }
7832
7833 static cmdline_parse_inst_t cmd_showfwdall = {
7834         .f = cmd_showfwdall_parsed,
7835         .data = NULL,
7836         .help_str = "show|clear fwd stats all",
7837         .tokens = {
7838                 (void *)&cmd_fwd_action,
7839                 (void *)&cmd_fwd_fwd,
7840                 (void *)&cmd_fwd_stats,
7841                 (void *)&cmd_fwd_all,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** READ PORT REGISTER *** */
7847 struct cmd_read_reg_result {
7848         cmdline_fixed_string_t read;
7849         cmdline_fixed_string_t reg;
7850         portid_t port_id;
7851         uint32_t reg_off;
7852 };
7853
7854 static void
7855 cmd_read_reg_parsed(void *parsed_result,
7856                     __rte_unused struct cmdline *cl,
7857                     __rte_unused void *data)
7858 {
7859         struct cmd_read_reg_result *res = parsed_result;
7860         port_reg_display(res->port_id, res->reg_off);
7861 }
7862
7863 cmdline_parse_token_string_t cmd_read_reg_read =
7864         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7865 cmdline_parse_token_string_t cmd_read_reg_reg =
7866         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7867 cmdline_parse_token_num_t cmd_read_reg_port_id =
7868         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7869 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7870         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7871
7872 cmdline_parse_inst_t cmd_read_reg = {
7873         .f = cmd_read_reg_parsed,
7874         .data = NULL,
7875         .help_str = "read reg <port_id> <reg_off>",
7876         .tokens = {
7877                 (void *)&cmd_read_reg_read,
7878                 (void *)&cmd_read_reg_reg,
7879                 (void *)&cmd_read_reg_port_id,
7880                 (void *)&cmd_read_reg_reg_off,
7881                 NULL,
7882         },
7883 };
7884
7885 /* *** READ PORT REGISTER BIT FIELD *** */
7886 struct cmd_read_reg_bit_field_result {
7887         cmdline_fixed_string_t read;
7888         cmdline_fixed_string_t regfield;
7889         portid_t port_id;
7890         uint32_t reg_off;
7891         uint8_t bit1_pos;
7892         uint8_t bit2_pos;
7893 };
7894
7895 static void
7896 cmd_read_reg_bit_field_parsed(void *parsed_result,
7897                               __rte_unused struct cmdline *cl,
7898                               __rte_unused void *data)
7899 {
7900         struct cmd_read_reg_bit_field_result *res = parsed_result;
7901         port_reg_bit_field_display(res->port_id, res->reg_off,
7902                                    res->bit1_pos, res->bit2_pos);
7903 }
7904
7905 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7906         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7907                                  "read");
7908 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7909         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7910                                  regfield, "regfield");
7911 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7912         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7913                               RTE_UINT16);
7914 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7915         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7916                               RTE_UINT32);
7917 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7918         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7919                               RTE_UINT8);
7920 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7921         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7922                               RTE_UINT8);
7923
7924 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7925         .f = cmd_read_reg_bit_field_parsed,
7926         .data = NULL,
7927         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7928         "Read register bit field between bit_x and bit_y included",
7929         .tokens = {
7930                 (void *)&cmd_read_reg_bit_field_read,
7931                 (void *)&cmd_read_reg_bit_field_regfield,
7932                 (void *)&cmd_read_reg_bit_field_port_id,
7933                 (void *)&cmd_read_reg_bit_field_reg_off,
7934                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7935                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7936                 NULL,
7937         },
7938 };
7939
7940 /* *** READ PORT REGISTER BIT *** */
7941 struct cmd_read_reg_bit_result {
7942         cmdline_fixed_string_t read;
7943         cmdline_fixed_string_t regbit;
7944         portid_t port_id;
7945         uint32_t reg_off;
7946         uint8_t bit_pos;
7947 };
7948
7949 static void
7950 cmd_read_reg_bit_parsed(void *parsed_result,
7951                         __rte_unused struct cmdline *cl,
7952                         __rte_unused void *data)
7953 {
7954         struct cmd_read_reg_bit_result *res = parsed_result;
7955         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7956 }
7957
7958 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7959         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7960 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7961         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7962                                  regbit, "regbit");
7963 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7964         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7965                                  RTE_UINT16);
7966 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7967         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7968                                  RTE_UINT32);
7969 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7970         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7971                                  RTE_UINT8);
7972
7973 cmdline_parse_inst_t cmd_read_reg_bit = {
7974         .f = cmd_read_reg_bit_parsed,
7975         .data = NULL,
7976         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7977         .tokens = {
7978                 (void *)&cmd_read_reg_bit_read,
7979                 (void *)&cmd_read_reg_bit_regbit,
7980                 (void *)&cmd_read_reg_bit_port_id,
7981                 (void *)&cmd_read_reg_bit_reg_off,
7982                 (void *)&cmd_read_reg_bit_bit_pos,
7983                 NULL,
7984         },
7985 };
7986
7987 /* *** WRITE PORT REGISTER *** */
7988 struct cmd_write_reg_result {
7989         cmdline_fixed_string_t write;
7990         cmdline_fixed_string_t reg;
7991         portid_t port_id;
7992         uint32_t reg_off;
7993         uint32_t value;
7994 };
7995
7996 static void
7997 cmd_write_reg_parsed(void *parsed_result,
7998                      __rte_unused struct cmdline *cl,
7999                      __rte_unused void *data)
8000 {
8001         struct cmd_write_reg_result *res = parsed_result;
8002         port_reg_set(res->port_id, res->reg_off, res->value);
8003 }
8004
8005 cmdline_parse_token_string_t cmd_write_reg_write =
8006         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8007 cmdline_parse_token_string_t cmd_write_reg_reg =
8008         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8009 cmdline_parse_token_num_t cmd_write_reg_port_id =
8010         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8011 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8012         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8013 cmdline_parse_token_num_t cmd_write_reg_value =
8014         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8015
8016 cmdline_parse_inst_t cmd_write_reg = {
8017         .f = cmd_write_reg_parsed,
8018         .data = NULL,
8019         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8020         .tokens = {
8021                 (void *)&cmd_write_reg_write,
8022                 (void *)&cmd_write_reg_reg,
8023                 (void *)&cmd_write_reg_port_id,
8024                 (void *)&cmd_write_reg_reg_off,
8025                 (void *)&cmd_write_reg_value,
8026                 NULL,
8027         },
8028 };
8029
8030 /* *** WRITE PORT REGISTER BIT FIELD *** */
8031 struct cmd_write_reg_bit_field_result {
8032         cmdline_fixed_string_t write;
8033         cmdline_fixed_string_t regfield;
8034         portid_t port_id;
8035         uint32_t reg_off;
8036         uint8_t bit1_pos;
8037         uint8_t bit2_pos;
8038         uint32_t value;
8039 };
8040
8041 static void
8042 cmd_write_reg_bit_field_parsed(void *parsed_result,
8043                                __rte_unused struct cmdline *cl,
8044                                __rte_unused void *data)
8045 {
8046         struct cmd_write_reg_bit_field_result *res = parsed_result;
8047         port_reg_bit_field_set(res->port_id, res->reg_off,
8048                           res->bit1_pos, res->bit2_pos, res->value);
8049 }
8050
8051 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8052         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8053                                  "write");
8054 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8055         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8056                                  regfield, "regfield");
8057 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8058         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8059                               RTE_UINT16);
8060 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8062                               RTE_UINT32);
8063 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8064         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8065                               RTE_UINT8);
8066 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8067         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8068                               RTE_UINT8);
8069 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8070         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8071                               RTE_UINT32);
8072
8073 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8074         .f = cmd_write_reg_bit_field_parsed,
8075         .data = NULL,
8076         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8077                 "<reg_value>: "
8078                 "Set register bit field between bit_x and bit_y included",
8079         .tokens = {
8080                 (void *)&cmd_write_reg_bit_field_write,
8081                 (void *)&cmd_write_reg_bit_field_regfield,
8082                 (void *)&cmd_write_reg_bit_field_port_id,
8083                 (void *)&cmd_write_reg_bit_field_reg_off,
8084                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8085                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8086                 (void *)&cmd_write_reg_bit_field_value,
8087                 NULL,
8088         },
8089 };
8090
8091 /* *** WRITE PORT REGISTER BIT *** */
8092 struct cmd_write_reg_bit_result {
8093         cmdline_fixed_string_t write;
8094         cmdline_fixed_string_t regbit;
8095         portid_t port_id;
8096         uint32_t reg_off;
8097         uint8_t bit_pos;
8098         uint8_t value;
8099 };
8100
8101 static void
8102 cmd_write_reg_bit_parsed(void *parsed_result,
8103                          __rte_unused struct cmdline *cl,
8104                          __rte_unused void *data)
8105 {
8106         struct cmd_write_reg_bit_result *res = parsed_result;
8107         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8108 }
8109
8110 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8111         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8112                                  "write");
8113 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8114         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8115                                  regbit, "regbit");
8116 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8117         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8118                                  RTE_UINT16);
8119 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8120         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8121                                  RTE_UINT32);
8122 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8123         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8124                                  RTE_UINT8);
8125 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8126         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8127                                  RTE_UINT8);
8128
8129 cmdline_parse_inst_t cmd_write_reg_bit = {
8130         .f = cmd_write_reg_bit_parsed,
8131         .data = NULL,
8132         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8133                 "0 <= bit_x <= 31",
8134         .tokens = {
8135                 (void *)&cmd_write_reg_bit_write,
8136                 (void *)&cmd_write_reg_bit_regbit,
8137                 (void *)&cmd_write_reg_bit_port_id,
8138                 (void *)&cmd_write_reg_bit_reg_off,
8139                 (void *)&cmd_write_reg_bit_bit_pos,
8140                 (void *)&cmd_write_reg_bit_value,
8141                 NULL,
8142         },
8143 };
8144
8145 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8146 struct cmd_read_rxd_txd_result {
8147         cmdline_fixed_string_t read;
8148         cmdline_fixed_string_t rxd_txd;
8149         portid_t port_id;
8150         uint16_t queue_id;
8151         uint16_t desc_id;
8152 };
8153
8154 static void
8155 cmd_read_rxd_txd_parsed(void *parsed_result,
8156                         __rte_unused struct cmdline *cl,
8157                         __rte_unused void *data)
8158 {
8159         struct cmd_read_rxd_txd_result *res = parsed_result;
8160
8161         if (!strcmp(res->rxd_txd, "rxd"))
8162                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8163         else if (!strcmp(res->rxd_txd, "txd"))
8164                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8165 }
8166
8167 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8168         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8169 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8170         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8171                                  "rxd#txd");
8172 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8173         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8174                                  RTE_UINT16);
8175 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8176         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8177                                  RTE_UINT16);
8178 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8179         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8180                                  RTE_UINT16);
8181
8182 cmdline_parse_inst_t cmd_read_rxd_txd = {
8183         .f = cmd_read_rxd_txd_parsed,
8184         .data = NULL,
8185         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8186         .tokens = {
8187                 (void *)&cmd_read_rxd_txd_read,
8188                 (void *)&cmd_read_rxd_txd_rxd_txd,
8189                 (void *)&cmd_read_rxd_txd_port_id,
8190                 (void *)&cmd_read_rxd_txd_queue_id,
8191                 (void *)&cmd_read_rxd_txd_desc_id,
8192                 NULL,
8193         },
8194 };
8195
8196 /* *** QUIT *** */
8197 struct cmd_quit_result {
8198         cmdline_fixed_string_t quit;
8199 };
8200
8201 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8202                             struct cmdline *cl,
8203                             __rte_unused void *data)
8204 {
8205         cmdline_quit(cl);
8206 }
8207
8208 cmdline_parse_token_string_t cmd_quit_quit =
8209         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8210
8211 cmdline_parse_inst_t cmd_quit = {
8212         .f = cmd_quit_parsed,
8213         .data = NULL,
8214         .help_str = "quit: Exit application",
8215         .tokens = {
8216                 (void *)&cmd_quit_quit,
8217                 NULL,
8218         },
8219 };
8220
8221 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8222 struct cmd_mac_addr_result {
8223         cmdline_fixed_string_t mac_addr_cmd;
8224         cmdline_fixed_string_t what;
8225         uint16_t port_num;
8226         struct rte_ether_addr address;
8227 };
8228
8229 static void cmd_mac_addr_parsed(void *parsed_result,
8230                 __rte_unused struct cmdline *cl,
8231                 __rte_unused void *data)
8232 {
8233         struct cmd_mac_addr_result *res = parsed_result;
8234         int ret;
8235
8236         if (strcmp(res->what, "add") == 0)
8237                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8238         else if (strcmp(res->what, "set") == 0)
8239                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8240                                                        &res->address);
8241         else
8242                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8243
8244         /* check the return value and print it if is < 0 */
8245         if(ret < 0)
8246                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8247
8248 }
8249
8250 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8251         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8252                                 "mac_addr");
8253 cmdline_parse_token_string_t cmd_mac_addr_what =
8254         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8255                                 "add#remove#set");
8256 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8257                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8258                                         RTE_UINT16);
8259 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8260                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8261
8262 cmdline_parse_inst_t cmd_mac_addr = {
8263         .f = cmd_mac_addr_parsed,
8264         .data = (void *)0,
8265         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8266                         "Add/Remove/Set MAC address on port_id",
8267         .tokens = {
8268                 (void *)&cmd_mac_addr_cmd,
8269                 (void *)&cmd_mac_addr_what,
8270                 (void *)&cmd_mac_addr_portnum,
8271                 (void *)&cmd_mac_addr_addr,
8272                 NULL,
8273         },
8274 };
8275
8276 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8277 struct cmd_eth_peer_result {
8278         cmdline_fixed_string_t set;
8279         cmdline_fixed_string_t eth_peer;
8280         portid_t port_id;
8281         cmdline_fixed_string_t peer_addr;
8282 };
8283
8284 static void cmd_set_eth_peer_parsed(void *parsed_result,
8285                         __rte_unused struct cmdline *cl,
8286                         __rte_unused void *data)
8287 {
8288                 struct cmd_eth_peer_result *res = parsed_result;
8289
8290                 if (test_done == 0) {
8291                         printf("Please stop forwarding first\n");
8292                         return;
8293                 }
8294                 if (!strcmp(res->eth_peer, "eth-peer")) {
8295                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8296                         fwd_config_setup();
8297                 }
8298 }
8299 cmdline_parse_token_string_t cmd_eth_peer_set =
8300         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8301 cmdline_parse_token_string_t cmd_eth_peer =
8302         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8303 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8304         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8305                 RTE_UINT16);
8306 cmdline_parse_token_string_t cmd_eth_peer_addr =
8307         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8308
8309 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8310         .f = cmd_set_eth_peer_parsed,
8311         .data = NULL,
8312         .help_str = "set eth-peer <port_id> <peer_mac>",
8313         .tokens = {
8314                 (void *)&cmd_eth_peer_set,
8315                 (void *)&cmd_eth_peer,
8316                 (void *)&cmd_eth_peer_port_id,
8317                 (void *)&cmd_eth_peer_addr,
8318                 NULL,
8319         },
8320 };
8321
8322 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8323 struct cmd_set_qmap_result {
8324         cmdline_fixed_string_t set;
8325         cmdline_fixed_string_t qmap;
8326         cmdline_fixed_string_t what;
8327         portid_t port_id;
8328         uint16_t queue_id;
8329         uint8_t map_value;
8330 };
8331
8332 static void
8333 cmd_set_qmap_parsed(void *parsed_result,
8334                        __rte_unused struct cmdline *cl,
8335                        __rte_unused void *data)
8336 {
8337         struct cmd_set_qmap_result *res = parsed_result;
8338         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8339
8340         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8341 }
8342
8343 cmdline_parse_token_string_t cmd_setqmap_set =
8344         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8345                                  set, "set");
8346 cmdline_parse_token_string_t cmd_setqmap_qmap =
8347         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8348                                  qmap, "stat_qmap");
8349 cmdline_parse_token_string_t cmd_setqmap_what =
8350         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8351                                  what, "tx#rx");
8352 cmdline_parse_token_num_t cmd_setqmap_portid =
8353         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8354                               port_id, RTE_UINT16);
8355 cmdline_parse_token_num_t cmd_setqmap_queueid =
8356         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8357                               queue_id, RTE_UINT16);
8358 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8359         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8360                               map_value, RTE_UINT8);
8361
8362 cmdline_parse_inst_t cmd_set_qmap = {
8363         .f = cmd_set_qmap_parsed,
8364         .data = NULL,
8365         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8366                 "Set statistics mapping value on tx|rx queue_id of port_id",
8367         .tokens = {
8368                 (void *)&cmd_setqmap_set,
8369                 (void *)&cmd_setqmap_qmap,
8370                 (void *)&cmd_setqmap_what,
8371                 (void *)&cmd_setqmap_portid,
8372                 (void *)&cmd_setqmap_queueid,
8373                 (void *)&cmd_setqmap_mapvalue,
8374                 NULL,
8375         },
8376 };
8377
8378 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8379 struct cmd_set_xstats_hide_zero_result {
8380         cmdline_fixed_string_t keyword;
8381         cmdline_fixed_string_t name;
8382         cmdline_fixed_string_t on_off;
8383 };
8384
8385 static void
8386 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8387                         __rte_unused struct cmdline *cl,
8388                         __rte_unused void *data)
8389 {
8390         struct cmd_set_xstats_hide_zero_result *res;
8391         uint16_t on_off = 0;
8392
8393         res = parsed_result;
8394         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8395         set_xstats_hide_zero(on_off);
8396 }
8397
8398 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8399         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8400                                  keyword, "set");
8401 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8402         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8403                                  name, "xstats-hide-zero");
8404 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8405         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8406                                  on_off, "on#off");
8407
8408 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8409         .f = cmd_set_xstats_hide_zero_parsed,
8410         .data = NULL,
8411         .help_str = "set xstats-hide-zero on|off",
8412         .tokens = {
8413                 (void *)&cmd_set_xstats_hide_zero_keyword,
8414                 (void *)&cmd_set_xstats_hide_zero_name,
8415                 (void *)&cmd_set_xstats_hide_zero_on_off,
8416                 NULL,
8417         },
8418 };
8419
8420 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8421 struct cmd_set_record_core_cycles_result {
8422         cmdline_fixed_string_t keyword;
8423         cmdline_fixed_string_t name;
8424         cmdline_fixed_string_t on_off;
8425 };
8426
8427 static void
8428 cmd_set_record_core_cycles_parsed(void *parsed_result,
8429                         __rte_unused struct cmdline *cl,
8430                         __rte_unused void *data)
8431 {
8432         struct cmd_set_record_core_cycles_result *res;
8433         uint16_t on_off = 0;
8434
8435         res = parsed_result;
8436         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8437         set_record_core_cycles(on_off);
8438 }
8439
8440 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8441         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8442                                  keyword, "set");
8443 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8444         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8445                                  name, "record-core-cycles");
8446 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8447         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8448                                  on_off, "on#off");
8449
8450 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8451         .f = cmd_set_record_core_cycles_parsed,
8452         .data = NULL,
8453         .help_str = "set record-core-cycles on|off",
8454         .tokens = {
8455                 (void *)&cmd_set_record_core_cycles_keyword,
8456                 (void *)&cmd_set_record_core_cycles_name,
8457                 (void *)&cmd_set_record_core_cycles_on_off,
8458                 NULL,
8459         },
8460 };
8461
8462 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8463 struct cmd_set_record_burst_stats_result {
8464         cmdline_fixed_string_t keyword;
8465         cmdline_fixed_string_t name;
8466         cmdline_fixed_string_t on_off;
8467 };
8468
8469 static void
8470 cmd_set_record_burst_stats_parsed(void *parsed_result,
8471                         __rte_unused struct cmdline *cl,
8472                         __rte_unused void *data)
8473 {
8474         struct cmd_set_record_burst_stats_result *res;
8475         uint16_t on_off = 0;
8476
8477         res = parsed_result;
8478         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8479         set_record_burst_stats(on_off);
8480 }
8481
8482 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8483         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8484                                  keyword, "set");
8485 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8486         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8487                                  name, "record-burst-stats");
8488 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8489         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8490                                  on_off, "on#off");
8491
8492 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8493         .f = cmd_set_record_burst_stats_parsed,
8494         .data = NULL,
8495         .help_str = "set record-burst-stats on|off",
8496         .tokens = {
8497                 (void *)&cmd_set_record_burst_stats_keyword,
8498                 (void *)&cmd_set_record_burst_stats_name,
8499                 (void *)&cmd_set_record_burst_stats_on_off,
8500                 NULL,
8501         },
8502 };
8503
8504 /* *** CONFIGURE UNICAST HASH TABLE *** */
8505 struct cmd_set_uc_hash_table {
8506         cmdline_fixed_string_t set;
8507         cmdline_fixed_string_t port;
8508         portid_t port_id;
8509         cmdline_fixed_string_t what;
8510         struct rte_ether_addr address;
8511         cmdline_fixed_string_t mode;
8512 };
8513
8514 static void
8515 cmd_set_uc_hash_parsed(void *parsed_result,
8516                        __rte_unused struct cmdline *cl,
8517                        __rte_unused void *data)
8518 {
8519         int ret=0;
8520         struct cmd_set_uc_hash_table *res = parsed_result;
8521
8522         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8523
8524         if (strcmp(res->what, "uta") == 0)
8525                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8526                                                 &res->address,(uint8_t)is_on);
8527         if (ret < 0)
8528                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8529
8530 }
8531
8532 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8534                                  set, "set");
8535 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8536         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8537                                  port, "port");
8538 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8539         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8540                               port_id, RTE_UINT16);
8541 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8542         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8543                                  what, "uta");
8544 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8545         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8546                                 address);
8547 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8548         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8549                                  mode, "on#off");
8550
8551 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8552         .f = cmd_set_uc_hash_parsed,
8553         .data = NULL,
8554         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8555         .tokens = {
8556                 (void *)&cmd_set_uc_hash_set,
8557                 (void *)&cmd_set_uc_hash_port,
8558                 (void *)&cmd_set_uc_hash_portid,
8559                 (void *)&cmd_set_uc_hash_what,
8560                 (void *)&cmd_set_uc_hash_mac,
8561                 (void *)&cmd_set_uc_hash_mode,
8562                 NULL,
8563         },
8564 };
8565
8566 struct cmd_set_uc_all_hash_table {
8567         cmdline_fixed_string_t set;
8568         cmdline_fixed_string_t port;
8569         portid_t port_id;
8570         cmdline_fixed_string_t what;
8571         cmdline_fixed_string_t value;
8572         cmdline_fixed_string_t mode;
8573 };
8574
8575 static void
8576 cmd_set_uc_all_hash_parsed(void *parsed_result,
8577                        __rte_unused struct cmdline *cl,
8578                        __rte_unused void *data)
8579 {
8580         int ret=0;
8581         struct cmd_set_uc_all_hash_table *res = parsed_result;
8582
8583         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8584
8585         if ((strcmp(res->what, "uta") == 0) &&
8586                 (strcmp(res->value, "all") == 0))
8587                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8588         if (ret < 0)
8589                 printf("bad unicast hash table parameter,"
8590                         "return code = %d \n", ret);
8591 }
8592
8593 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8594         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8595                                  set, "set");
8596 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8597         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8598                                  port, "port");
8599 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8600         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8601                               port_id, RTE_UINT16);
8602 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8603         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8604                                  what, "uta");
8605 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8606         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8607                                 value,"all");
8608 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8609         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8610                                  mode, "on#off");
8611
8612 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8613         .f = cmd_set_uc_all_hash_parsed,
8614         .data = NULL,
8615         .help_str = "set port <port_id> uta all on|off",
8616         .tokens = {
8617                 (void *)&cmd_set_uc_all_hash_set,
8618                 (void *)&cmd_set_uc_all_hash_port,
8619                 (void *)&cmd_set_uc_all_hash_portid,
8620                 (void *)&cmd_set_uc_all_hash_what,
8621                 (void *)&cmd_set_uc_all_hash_value,
8622                 (void *)&cmd_set_uc_all_hash_mode,
8623                 NULL,
8624         },
8625 };
8626
8627 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8628 struct cmd_set_vf_traffic {
8629         cmdline_fixed_string_t set;
8630         cmdline_fixed_string_t port;
8631         portid_t port_id;
8632         cmdline_fixed_string_t vf;
8633         uint8_t vf_id;
8634         cmdline_fixed_string_t what;
8635         cmdline_fixed_string_t mode;
8636 };
8637
8638 static void
8639 cmd_set_vf_traffic_parsed(void *parsed_result,
8640                        __rte_unused struct cmdline *cl,
8641                        __rte_unused void *data)
8642 {
8643         struct cmd_set_vf_traffic *res = parsed_result;
8644         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8645         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8646
8647         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8648 }
8649
8650 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8651         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8652                                  set, "set");
8653 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8654         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8655                                  port, "port");
8656 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8657         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8658                               port_id, RTE_UINT16);
8659 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8661                                  vf, "vf");
8662 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8663         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8664                               vf_id, RTE_UINT8);
8665 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8666         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8667                                  what, "tx#rx");
8668 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8669         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8670                                  mode, "on#off");
8671
8672 cmdline_parse_inst_t cmd_set_vf_traffic = {
8673         .f = cmd_set_vf_traffic_parsed,
8674         .data = NULL,
8675         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8676         .tokens = {
8677                 (void *)&cmd_setvf_traffic_set,
8678                 (void *)&cmd_setvf_traffic_port,
8679                 (void *)&cmd_setvf_traffic_portid,
8680                 (void *)&cmd_setvf_traffic_vf,
8681                 (void *)&cmd_setvf_traffic_vfid,
8682                 (void *)&cmd_setvf_traffic_what,
8683                 (void *)&cmd_setvf_traffic_mode,
8684                 NULL,
8685         },
8686 };
8687
8688 /* *** CONFIGURE VF RECEIVE MODE *** */
8689 struct cmd_set_vf_rxmode {
8690         cmdline_fixed_string_t set;
8691         cmdline_fixed_string_t port;
8692         portid_t port_id;
8693         cmdline_fixed_string_t vf;
8694         uint8_t vf_id;
8695         cmdline_fixed_string_t what;
8696         cmdline_fixed_string_t mode;
8697         cmdline_fixed_string_t on;
8698 };
8699
8700 static void
8701 cmd_set_vf_rxmode_parsed(void *parsed_result,
8702                        __rte_unused struct cmdline *cl,
8703                        __rte_unused void *data)
8704 {
8705         int ret = -ENOTSUP;
8706         uint16_t vf_rxmode = 0;
8707         struct cmd_set_vf_rxmode *res = parsed_result;
8708
8709         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8710         if (!strcmp(res->what,"rxmode")) {
8711                 if (!strcmp(res->mode, "AUPE"))
8712                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8713                 else if (!strcmp(res->mode, "ROPE"))
8714                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8715                 else if (!strcmp(res->mode, "BAM"))
8716                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8717                 else if (!strncmp(res->mode, "MPE",3))
8718                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8719         }
8720
8721         RTE_SET_USED(is_on);
8722
8723 #ifdef RTE_NET_IXGBE
8724         if (ret == -ENOTSUP)
8725                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8726                                                   vf_rxmode, (uint8_t)is_on);
8727 #endif
8728 #ifdef RTE_NET_BNXT
8729         if (ret == -ENOTSUP)
8730                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8731                                                  vf_rxmode, (uint8_t)is_on);
8732 #endif
8733         if (ret < 0)
8734                 printf("bad VF receive mode parameter, return code = %d \n",
8735                 ret);
8736 }
8737
8738 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8739         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8740                                  set, "set");
8741 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8742         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8743                                  port, "port");
8744 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8745         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8746                               port_id, RTE_UINT16);
8747 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8748         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8749                                  vf, "vf");
8750 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8751         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8752                               vf_id, RTE_UINT8);
8753 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8754         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8755                                  what, "rxmode");
8756 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8757         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8758                                  mode, "AUPE#ROPE#BAM#MPE");
8759 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8760         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8761                                  on, "on#off");
8762
8763 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8764         .f = cmd_set_vf_rxmode_parsed,
8765         .data = NULL,
8766         .help_str = "set port <port_id> vf <vf_id> rxmode "
8767                 "AUPE|ROPE|BAM|MPE on|off",
8768         .tokens = {
8769                 (void *)&cmd_set_vf_rxmode_set,
8770                 (void *)&cmd_set_vf_rxmode_port,
8771                 (void *)&cmd_set_vf_rxmode_portid,
8772                 (void *)&cmd_set_vf_rxmode_vf,
8773                 (void *)&cmd_set_vf_rxmode_vfid,
8774                 (void *)&cmd_set_vf_rxmode_what,
8775                 (void *)&cmd_set_vf_rxmode_mode,
8776                 (void *)&cmd_set_vf_rxmode_on,
8777                 NULL,
8778         },
8779 };
8780
8781 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8782 struct cmd_vf_mac_addr_result {
8783         cmdline_fixed_string_t mac_addr_cmd;
8784         cmdline_fixed_string_t what;
8785         cmdline_fixed_string_t port;
8786         uint16_t port_num;
8787         cmdline_fixed_string_t vf;
8788         uint8_t vf_num;
8789         struct rte_ether_addr address;
8790 };
8791
8792 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8793                 __rte_unused struct cmdline *cl,
8794                 __rte_unused void *data)
8795 {
8796         struct cmd_vf_mac_addr_result *res = parsed_result;
8797         int ret = -ENOTSUP;
8798
8799         if (strcmp(res->what, "add") != 0)
8800                 return;
8801
8802 #ifdef RTE_NET_I40E
8803         if (ret == -ENOTSUP)
8804                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8805                                                    &res->address);
8806 #endif
8807 #ifdef RTE_NET_BNXT
8808         if (ret == -ENOTSUP)
8809                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8810                                                 res->vf_num);
8811 #endif
8812
8813         if(ret < 0)
8814                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8815
8816 }
8817
8818 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8819         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8820                                 mac_addr_cmd,"mac_addr");
8821 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8822         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8823                                 what,"add");
8824 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8825         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8826                                 port,"port");
8827 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8828         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8829                                 port_num, RTE_UINT16);
8830 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8831         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8832                                 vf,"vf");
8833 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8834         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8835                                 vf_num, RTE_UINT8);
8836 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8837         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8838                                 address);
8839
8840 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8841         .f = cmd_vf_mac_addr_parsed,
8842         .data = (void *)0,
8843         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8844                 "Add MAC address filtering for a VF on port_id",
8845         .tokens = {
8846                 (void *)&cmd_vf_mac_addr_cmd,
8847                 (void *)&cmd_vf_mac_addr_what,
8848                 (void *)&cmd_vf_mac_addr_port,
8849                 (void *)&cmd_vf_mac_addr_portnum,
8850                 (void *)&cmd_vf_mac_addr_vf,
8851                 (void *)&cmd_vf_mac_addr_vfnum,
8852                 (void *)&cmd_vf_mac_addr_addr,
8853                 NULL,
8854         },
8855 };
8856
8857 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8858 struct cmd_vf_rx_vlan_filter {
8859         cmdline_fixed_string_t rx_vlan;
8860         cmdline_fixed_string_t what;
8861         uint16_t vlan_id;
8862         cmdline_fixed_string_t port;
8863         portid_t port_id;
8864         cmdline_fixed_string_t vf;
8865         uint64_t vf_mask;
8866 };
8867
8868 static void
8869 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8870                           __rte_unused struct cmdline *cl,
8871                           __rte_unused void *data)
8872 {
8873         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8874         int ret = -ENOTSUP;
8875
8876         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8877
8878 #ifdef RTE_NET_IXGBE
8879         if (ret == -ENOTSUP)
8880                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8881                                 res->vlan_id, res->vf_mask, is_add);
8882 #endif
8883 #ifdef RTE_NET_I40E
8884         if (ret == -ENOTSUP)
8885                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8886                                 res->vlan_id, res->vf_mask, is_add);
8887 #endif
8888 #ifdef RTE_NET_BNXT
8889         if (ret == -ENOTSUP)
8890                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8891                                 res->vlan_id, res->vf_mask, is_add);
8892 #endif
8893
8894         switch (ret) {
8895         case 0:
8896                 break;
8897         case -EINVAL:
8898                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8899                                 res->vlan_id, res->vf_mask);
8900                 break;
8901         case -ENODEV:
8902                 printf("invalid port_id %d\n", res->port_id);
8903                 break;
8904         case -ENOTSUP:
8905                 printf("function not implemented or supported\n");
8906                 break;
8907         default:
8908                 printf("programming error: (%s)\n", strerror(-ret));
8909         }
8910 }
8911
8912 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8913         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8914                                  rx_vlan, "rx_vlan");
8915 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8916         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8917                                  what, "add#rm");
8918 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8919         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8920                               vlan_id, RTE_UINT16);
8921 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8922         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8923                                  port, "port");
8924 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8925         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8926                               port_id, RTE_UINT16);
8927 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8928         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8929                                  vf, "vf");
8930 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8931         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8932                               vf_mask, RTE_UINT64);
8933
8934 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8935         .f = cmd_vf_rx_vlan_filter_parsed,
8936         .data = NULL,
8937         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8938                 "(vf_mask = hexadecimal VF mask)",
8939         .tokens = {
8940                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8941                 (void *)&cmd_vf_rx_vlan_filter_what,
8942                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8943                 (void *)&cmd_vf_rx_vlan_filter_port,
8944                 (void *)&cmd_vf_rx_vlan_filter_portid,
8945                 (void *)&cmd_vf_rx_vlan_filter_vf,
8946                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8947                 NULL,
8948         },
8949 };
8950
8951 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8952 struct cmd_queue_rate_limit_result {
8953         cmdline_fixed_string_t set;
8954         cmdline_fixed_string_t port;
8955         uint16_t port_num;
8956         cmdline_fixed_string_t queue;
8957         uint8_t queue_num;
8958         cmdline_fixed_string_t rate;
8959         uint16_t rate_num;
8960 };
8961
8962 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8963                 __rte_unused struct cmdline *cl,
8964                 __rte_unused void *data)
8965 {
8966         struct cmd_queue_rate_limit_result *res = parsed_result;
8967         int ret = 0;
8968
8969         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8970                 && (strcmp(res->queue, "queue") == 0)
8971                 && (strcmp(res->rate, "rate") == 0))
8972                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8973                                         res->rate_num);
8974         if (ret < 0)
8975                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8976
8977 }
8978
8979 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8980         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8981                                 set, "set");
8982 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8983         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8984                                 port, "port");
8985 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8986         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8987                                 port_num, RTE_UINT16);
8988 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8989         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8990                                 queue, "queue");
8991 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8992         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8993                                 queue_num, RTE_UINT8);
8994 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8995         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8996                                 rate, "rate");
8997 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8998         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8999                                 rate_num, RTE_UINT16);
9000
9001 cmdline_parse_inst_t cmd_queue_rate_limit = {
9002         .f = cmd_queue_rate_limit_parsed,
9003         .data = (void *)0,
9004         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9005                 "Set rate limit for a queue on port_id",
9006         .tokens = {
9007                 (void *)&cmd_queue_rate_limit_set,
9008                 (void *)&cmd_queue_rate_limit_port,
9009                 (void *)&cmd_queue_rate_limit_portnum,
9010                 (void *)&cmd_queue_rate_limit_queue,
9011                 (void *)&cmd_queue_rate_limit_queuenum,
9012                 (void *)&cmd_queue_rate_limit_rate,
9013                 (void *)&cmd_queue_rate_limit_ratenum,
9014                 NULL,
9015         },
9016 };
9017
9018 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9019 struct cmd_vf_rate_limit_result {
9020         cmdline_fixed_string_t set;
9021         cmdline_fixed_string_t port;
9022         uint16_t port_num;
9023         cmdline_fixed_string_t vf;
9024         uint8_t vf_num;
9025         cmdline_fixed_string_t rate;
9026         uint16_t rate_num;
9027         cmdline_fixed_string_t q_msk;
9028         uint64_t q_msk_val;
9029 };
9030
9031 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9032                 __rte_unused struct cmdline *cl,
9033                 __rte_unused void *data)
9034 {
9035         struct cmd_vf_rate_limit_result *res = parsed_result;
9036         int ret = 0;
9037
9038         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9039                 && (strcmp(res->vf, "vf") == 0)
9040                 && (strcmp(res->rate, "rate") == 0)
9041                 && (strcmp(res->q_msk, "queue_mask") == 0))
9042                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9043                                         res->rate_num, res->q_msk_val);
9044         if (ret < 0)
9045                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9046
9047 }
9048
9049 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9050         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9051                                 set, "set");
9052 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9053         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9054                                 port, "port");
9055 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9056         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9057                                 port_num, RTE_UINT16);
9058 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9059         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9060                                 vf, "vf");
9061 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9062         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9063                                 vf_num, RTE_UINT8);
9064 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9065         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9066                                 rate, "rate");
9067 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9068         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9069                                 rate_num, RTE_UINT16);
9070 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9071         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9072                                 q_msk, "queue_mask");
9073 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9074         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9075                                 q_msk_val, RTE_UINT64);
9076
9077 cmdline_parse_inst_t cmd_vf_rate_limit = {
9078         .f = cmd_vf_rate_limit_parsed,
9079         .data = (void *)0,
9080         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9081                 "queue_mask <queue_mask_value>: "
9082                 "Set rate limit for queues of VF on port_id",
9083         .tokens = {
9084                 (void *)&cmd_vf_rate_limit_set,
9085                 (void *)&cmd_vf_rate_limit_port,
9086                 (void *)&cmd_vf_rate_limit_portnum,
9087                 (void *)&cmd_vf_rate_limit_vf,
9088                 (void *)&cmd_vf_rate_limit_vfnum,
9089                 (void *)&cmd_vf_rate_limit_rate,
9090                 (void *)&cmd_vf_rate_limit_ratenum,
9091                 (void *)&cmd_vf_rate_limit_q_msk,
9092                 (void *)&cmd_vf_rate_limit_q_msk_val,
9093                 NULL,
9094         },
9095 };
9096
9097 /* *** CONFIGURE TUNNEL UDP PORT *** */
9098 struct cmd_tunnel_udp_config {
9099         cmdline_fixed_string_t cmd;
9100         cmdline_fixed_string_t what;
9101         uint16_t udp_port;
9102         portid_t port_id;
9103 };
9104
9105 static void
9106 cmd_tunnel_udp_config_parsed(void *parsed_result,
9107                           __rte_unused struct cmdline *cl,
9108                           __rte_unused void *data)
9109 {
9110         struct cmd_tunnel_udp_config *res = parsed_result;
9111         struct rte_eth_udp_tunnel tunnel_udp;
9112         int ret;
9113
9114         tunnel_udp.udp_port = res->udp_port;
9115
9116         if (!strcmp(res->cmd, "rx_vxlan_port"))
9117                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9118
9119         if (!strcmp(res->what, "add"))
9120                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9121                                                       &tunnel_udp);
9122         else
9123                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9124                                                          &tunnel_udp);
9125
9126         if (ret < 0)
9127                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9128 }
9129
9130 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9131         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9132                                 cmd, "rx_vxlan_port");
9133 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9134         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9135                                 what, "add#rm");
9136 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9137         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9138                                 udp_port, RTE_UINT16);
9139 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9140         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9141                                 port_id, RTE_UINT16);
9142
9143 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9144         .f = cmd_tunnel_udp_config_parsed,
9145         .data = (void *)0,
9146         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9147                 "Add/Remove a tunneling UDP port filter",
9148         .tokens = {
9149                 (void *)&cmd_tunnel_udp_config_cmd,
9150                 (void *)&cmd_tunnel_udp_config_what,
9151                 (void *)&cmd_tunnel_udp_config_udp_port,
9152                 (void *)&cmd_tunnel_udp_config_port_id,
9153                 NULL,
9154         },
9155 };
9156
9157 struct cmd_config_tunnel_udp_port {
9158         cmdline_fixed_string_t port;
9159         cmdline_fixed_string_t config;
9160         portid_t port_id;
9161         cmdline_fixed_string_t udp_tunnel_port;
9162         cmdline_fixed_string_t action;
9163         cmdline_fixed_string_t tunnel_type;
9164         uint16_t udp_port;
9165 };
9166
9167 static void
9168 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9169                                __rte_unused struct cmdline *cl,
9170                                __rte_unused void *data)
9171 {
9172         struct cmd_config_tunnel_udp_port *res = parsed_result;
9173         struct rte_eth_udp_tunnel tunnel_udp;
9174         int ret = 0;
9175
9176         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9177                 return;
9178
9179         tunnel_udp.udp_port = res->udp_port;
9180
9181         if (!strcmp(res->tunnel_type, "vxlan")) {
9182                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9183         } else if (!strcmp(res->tunnel_type, "geneve")) {
9184                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9185         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9186                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9187         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9188                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9189         } else {
9190                 printf("Invalid tunnel type\n");
9191                 return;
9192         }
9193
9194         if (!strcmp(res->action, "add"))
9195                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9196                                                       &tunnel_udp);
9197         else
9198                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9199                                                          &tunnel_udp);
9200
9201         if (ret < 0)
9202                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9203 }
9204
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9206         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9207                                  "port");
9208 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9209         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9210                                  "config");
9211 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9212         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9213                               RTE_UINT16);
9214 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9215         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9216                                  udp_tunnel_port,
9217                                  "udp_tunnel_port");
9218 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9219         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9220                                  "add#rm");
9221 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9222         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9223                                  "vxlan#geneve#vxlan-gpe#ecpri");
9224 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9225         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9226                               RTE_UINT16);
9227
9228 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9229         .f = cmd_cfg_tunnel_udp_port_parsed,
9230         .data = NULL,
9231         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9232                 "geneve|vxlan-gpe|ecpri <udp_port>",
9233         .tokens = {
9234                 (void *)&cmd_config_tunnel_udp_port_port,
9235                 (void *)&cmd_config_tunnel_udp_port_config,
9236                 (void *)&cmd_config_tunnel_udp_port_port_id,
9237                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9238                 (void *)&cmd_config_tunnel_udp_port_action,
9239                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9240                 (void *)&cmd_config_tunnel_udp_port_value,
9241                 NULL,
9242         },
9243 };
9244
9245 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9246 struct cmd_set_mirror_mask_result {
9247         cmdline_fixed_string_t set;
9248         cmdline_fixed_string_t port;
9249         portid_t port_id;
9250         cmdline_fixed_string_t mirror;
9251         uint8_t rule_id;
9252         cmdline_fixed_string_t what;
9253         cmdline_fixed_string_t value;
9254         cmdline_fixed_string_t dstpool;
9255         uint8_t dstpool_id;
9256         cmdline_fixed_string_t on;
9257 };
9258
9259 cmdline_parse_token_string_t cmd_mirror_mask_set =
9260         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9261                                 set, "set");
9262 cmdline_parse_token_string_t cmd_mirror_mask_port =
9263         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9264                                 port, "port");
9265 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9266         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9267                                 port_id, RTE_UINT16);
9268 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9269         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9270                                 mirror, "mirror-rule");
9271 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9272         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9273                                 rule_id, RTE_UINT8);
9274 cmdline_parse_token_string_t cmd_mirror_mask_what =
9275         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9276                                 what, "pool-mirror-up#pool-mirror-down"
9277                                       "#vlan-mirror");
9278 cmdline_parse_token_string_t cmd_mirror_mask_value =
9279         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9280                                 value, NULL);
9281 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9282         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9283                                 dstpool, "dst-pool");
9284 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9285         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9286                                 dstpool_id, RTE_UINT8);
9287 cmdline_parse_token_string_t cmd_mirror_mask_on =
9288         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9289                                 on, "on#off");
9290
9291 static void
9292 cmd_set_mirror_mask_parsed(void *parsed_result,
9293                        __rte_unused struct cmdline *cl,
9294                        __rte_unused void *data)
9295 {
9296         int ret,nb_item,i;
9297         struct cmd_set_mirror_mask_result *res = parsed_result;
9298         struct rte_eth_mirror_conf mr_conf;
9299
9300         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9301
9302         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9303
9304         mr_conf.dst_pool = res->dstpool_id;
9305
9306         if (!strcmp(res->what, "pool-mirror-up")) {
9307                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9308                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9309         } else if (!strcmp(res->what, "pool-mirror-down")) {
9310                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9311                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9312         } else if (!strcmp(res->what, "vlan-mirror")) {
9313                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9314                 nb_item = parse_item_list(res->value, "vlan",
9315                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9316                 if (nb_item <= 0)
9317                         return;
9318
9319                 for (i = 0; i < nb_item; i++) {
9320                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9321                                 printf("Invalid vlan_id: must be < 4096\n");
9322                                 return;
9323                         }
9324
9325                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9326                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9327                 }
9328         }
9329
9330         if (!strcmp(res->on, "on"))
9331                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9332                                                 res->rule_id, 1);
9333         else
9334                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9335                                                 res->rule_id, 0);
9336         if (ret < 0)
9337                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9338 }
9339
9340 cmdline_parse_inst_t cmd_set_mirror_mask = {
9341                 .f = cmd_set_mirror_mask_parsed,
9342                 .data = NULL,
9343                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9344                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9345                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9346                 .tokens = {
9347                         (void *)&cmd_mirror_mask_set,
9348                         (void *)&cmd_mirror_mask_port,
9349                         (void *)&cmd_mirror_mask_portid,
9350                         (void *)&cmd_mirror_mask_mirror,
9351                         (void *)&cmd_mirror_mask_ruleid,
9352                         (void *)&cmd_mirror_mask_what,
9353                         (void *)&cmd_mirror_mask_value,
9354                         (void *)&cmd_mirror_mask_dstpool,
9355                         (void *)&cmd_mirror_mask_poolid,
9356                         (void *)&cmd_mirror_mask_on,
9357                         NULL,
9358                 },
9359 };
9360
9361 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9362 struct cmd_set_mirror_link_result {
9363         cmdline_fixed_string_t set;
9364         cmdline_fixed_string_t port;
9365         portid_t port_id;
9366         cmdline_fixed_string_t mirror;
9367         uint8_t rule_id;
9368         cmdline_fixed_string_t what;
9369         cmdline_fixed_string_t dstpool;
9370         uint8_t dstpool_id;
9371         cmdline_fixed_string_t on;
9372 };
9373
9374 cmdline_parse_token_string_t cmd_mirror_link_set =
9375         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9376                                  set, "set");
9377 cmdline_parse_token_string_t cmd_mirror_link_port =
9378         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9379                                 port, "port");
9380 cmdline_parse_token_num_t cmd_mirror_link_portid =
9381         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9382                                 port_id, RTE_UINT16);
9383 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9385                                 mirror, "mirror-rule");
9386 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9387         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9388                             rule_id, RTE_UINT8);
9389 cmdline_parse_token_string_t cmd_mirror_link_what =
9390         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9391                                 what, "uplink-mirror#downlink-mirror");
9392 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9393         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9394                                 dstpool, "dst-pool");
9395 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9396         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9397                                 dstpool_id, RTE_UINT8);
9398 cmdline_parse_token_string_t cmd_mirror_link_on =
9399         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9400                                 on, "on#off");
9401
9402 static void
9403 cmd_set_mirror_link_parsed(void *parsed_result,
9404                        __rte_unused struct cmdline *cl,
9405                        __rte_unused void *data)
9406 {
9407         int ret;
9408         struct cmd_set_mirror_link_result *res = parsed_result;
9409         struct rte_eth_mirror_conf mr_conf;
9410
9411         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9412         if (!strcmp(res->what, "uplink-mirror"))
9413                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9414         else
9415                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9416
9417         mr_conf.dst_pool = res->dstpool_id;
9418
9419         if (!strcmp(res->on, "on"))
9420                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9421                                                 res->rule_id, 1);
9422         else
9423                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9424                                                 res->rule_id, 0);
9425
9426         /* check the return value and print it if is < 0 */
9427         if (ret < 0)
9428                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9429
9430 }
9431
9432 cmdline_parse_inst_t cmd_set_mirror_link = {
9433                 .f = cmd_set_mirror_link_parsed,
9434                 .data = NULL,
9435                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9436                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9437                 .tokens = {
9438                         (void *)&cmd_mirror_link_set,
9439                         (void *)&cmd_mirror_link_port,
9440                         (void *)&cmd_mirror_link_portid,
9441                         (void *)&cmd_mirror_link_mirror,
9442                         (void *)&cmd_mirror_link_ruleid,
9443                         (void *)&cmd_mirror_link_what,
9444                         (void *)&cmd_mirror_link_dstpool,
9445                         (void *)&cmd_mirror_link_poolid,
9446                         (void *)&cmd_mirror_link_on,
9447                         NULL,
9448                 },
9449 };
9450
9451 /* *** RESET VM MIRROR RULE *** */
9452 struct cmd_rm_mirror_rule_result {
9453         cmdline_fixed_string_t reset;
9454         cmdline_fixed_string_t port;
9455         portid_t port_id;
9456         cmdline_fixed_string_t mirror;
9457         uint8_t rule_id;
9458 };
9459
9460 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9461         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9462                                  reset, "reset");
9463 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9464         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9465                                 port, "port");
9466 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9467         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9468                                 port_id, RTE_UINT16);
9469 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9470         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9471                                 mirror, "mirror-rule");
9472 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9473         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9474                                 rule_id, RTE_UINT8);
9475
9476 static void
9477 cmd_reset_mirror_rule_parsed(void *parsed_result,
9478                        __rte_unused struct cmdline *cl,
9479                        __rte_unused void *data)
9480 {
9481         int ret;
9482         struct cmd_set_mirror_link_result *res = parsed_result;
9483         /* check rule_id */
9484         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9485         if(ret < 0)
9486                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9487 }
9488
9489 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9490                 .f = cmd_reset_mirror_rule_parsed,
9491                 .data = NULL,
9492                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9493                 .tokens = {
9494                         (void *)&cmd_rm_mirror_rule_reset,
9495                         (void *)&cmd_rm_mirror_rule_port,
9496                         (void *)&cmd_rm_mirror_rule_portid,
9497                         (void *)&cmd_rm_mirror_rule_mirror,
9498                         (void *)&cmd_rm_mirror_rule_ruleid,
9499                         NULL,
9500                 },
9501 };
9502
9503 /* ******************************************************************************** */
9504
9505 struct cmd_dump_result {
9506         cmdline_fixed_string_t dump;
9507 };
9508
9509 static void
9510 dump_struct_sizes(void)
9511 {
9512 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9513         DUMP_SIZE(struct rte_mbuf);
9514         DUMP_SIZE(struct rte_mempool);
9515         DUMP_SIZE(struct rte_ring);
9516 #undef DUMP_SIZE
9517 }
9518
9519
9520 /* Dump the socket memory statistics on console */
9521 static void
9522 dump_socket_mem(FILE *f)
9523 {
9524         struct rte_malloc_socket_stats socket_stats;
9525         unsigned int i;
9526         size_t total = 0;
9527         size_t alloc = 0;
9528         size_t free = 0;
9529         unsigned int n_alloc = 0;
9530         unsigned int n_free = 0;
9531         static size_t last_allocs;
9532         static size_t last_total;
9533
9534
9535         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9536                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9537                     !socket_stats.heap_totalsz_bytes)
9538                         continue;
9539                 total += socket_stats.heap_totalsz_bytes;
9540                 alloc += socket_stats.heap_allocsz_bytes;
9541                 free += socket_stats.heap_freesz_bytes;
9542                 n_alloc += socket_stats.alloc_count;
9543                 n_free += socket_stats.free_count;
9544                 fprintf(f,
9545                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9546                         i,
9547                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9548                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9549                         (double)socket_stats.heap_allocsz_bytes * 100 /
9550                         (double)socket_stats.heap_totalsz_bytes,
9551                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9552                         socket_stats.alloc_count,
9553                         socket_stats.free_count);
9554         }
9555         fprintf(f,
9556                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9557                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9558                 (double)alloc * 100 / (double)total,
9559                 (double)free / (1024 * 1024),
9560                 n_alloc, n_free);
9561         if (last_allocs)
9562                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9563                         ((double)total - (double)last_total) / (1024 * 1024),
9564                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9565         last_allocs = alloc;
9566         last_total = total;
9567 }
9568
9569 static void cmd_dump_parsed(void *parsed_result,
9570                             __rte_unused struct cmdline *cl,
9571                             __rte_unused void *data)
9572 {
9573         struct cmd_dump_result *res = parsed_result;
9574
9575         if (!strcmp(res->dump, "dump_physmem"))
9576                 rte_dump_physmem_layout(stdout);
9577         else if (!strcmp(res->dump, "dump_socket_mem"))
9578                 dump_socket_mem(stdout);
9579         else if (!strcmp(res->dump, "dump_memzone"))
9580                 rte_memzone_dump(stdout);
9581         else if (!strcmp(res->dump, "dump_struct_sizes"))
9582                 dump_struct_sizes();
9583         else if (!strcmp(res->dump, "dump_ring"))
9584                 rte_ring_list_dump(stdout);
9585         else if (!strcmp(res->dump, "dump_mempool"))
9586                 rte_mempool_list_dump(stdout);
9587         else if (!strcmp(res->dump, "dump_devargs"))
9588                 rte_devargs_dump(stdout);
9589         else if (!strcmp(res->dump, "dump_log_types"))
9590                 rte_log_dump(stdout);
9591 }
9592
9593 cmdline_parse_token_string_t cmd_dump_dump =
9594         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9595                 "dump_physmem#"
9596                 "dump_memzone#"
9597                 "dump_socket_mem#"
9598                 "dump_struct_sizes#"
9599                 "dump_ring#"
9600                 "dump_mempool#"
9601                 "dump_devargs#"
9602                 "dump_log_types");
9603
9604 cmdline_parse_inst_t cmd_dump = {
9605         .f = cmd_dump_parsed,  /* function to call */
9606         .data = NULL,      /* 2nd arg of func */
9607         .help_str = "Dump status",
9608         .tokens = {        /* token list, NULL terminated */
9609                 (void *)&cmd_dump_dump,
9610                 NULL,
9611         },
9612 };
9613
9614 /* ******************************************************************************** */
9615
9616 struct cmd_dump_one_result {
9617         cmdline_fixed_string_t dump;
9618         cmdline_fixed_string_t name;
9619 };
9620
9621 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9622                                 __rte_unused void *data)
9623 {
9624         struct cmd_dump_one_result *res = parsed_result;
9625
9626         if (!strcmp(res->dump, "dump_ring")) {
9627                 struct rte_ring *r;
9628                 r = rte_ring_lookup(res->name);
9629                 if (r == NULL) {
9630                         cmdline_printf(cl, "Cannot find ring\n");
9631                         return;
9632                 }
9633                 rte_ring_dump(stdout, r);
9634         } else if (!strcmp(res->dump, "dump_mempool")) {
9635                 struct rte_mempool *mp;
9636                 mp = rte_mempool_lookup(res->name);
9637                 if (mp == NULL) {
9638                         cmdline_printf(cl, "Cannot find mempool\n");
9639                         return;
9640                 }
9641                 rte_mempool_dump(stdout, mp);
9642         }
9643 }
9644
9645 cmdline_parse_token_string_t cmd_dump_one_dump =
9646         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9647                                  "dump_ring#dump_mempool");
9648
9649 cmdline_parse_token_string_t cmd_dump_one_name =
9650         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9651
9652 cmdline_parse_inst_t cmd_dump_one = {
9653         .f = cmd_dump_one_parsed,  /* function to call */
9654         .data = NULL,      /* 2nd arg of func */
9655         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9656         .tokens = {        /* token list, NULL terminated */
9657                 (void *)&cmd_dump_one_dump,
9658                 (void *)&cmd_dump_one_name,
9659                 NULL,
9660         },
9661 };
9662
9663 /* *** queue region set *** */
9664 struct cmd_queue_region_result {
9665         cmdline_fixed_string_t set;
9666         cmdline_fixed_string_t port;
9667         portid_t port_id;
9668         cmdline_fixed_string_t cmd;
9669         cmdline_fixed_string_t region;
9670         uint8_t  region_id;
9671         cmdline_fixed_string_t queue_start_index;
9672         uint8_t  queue_id;
9673         cmdline_fixed_string_t queue_num;
9674         uint8_t  queue_num_value;
9675 };
9676
9677 static void
9678 cmd_queue_region_parsed(void *parsed_result,
9679                         __rte_unused struct cmdline *cl,
9680                         __rte_unused void *data)
9681 {
9682         struct cmd_queue_region_result *res = parsed_result;
9683         int ret = -ENOTSUP;
9684 #ifdef RTE_NET_I40E
9685         struct rte_pmd_i40e_queue_region_conf region_conf;
9686         enum rte_pmd_i40e_queue_region_op op_type;
9687 #endif
9688
9689         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9690                 return;
9691
9692 #ifdef RTE_NET_I40E
9693         memset(&region_conf, 0, sizeof(region_conf));
9694         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9695         region_conf.region_id = res->region_id;
9696         region_conf.queue_num = res->queue_num_value;
9697         region_conf.queue_start_index = res->queue_id;
9698
9699         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9700                                 op_type, &region_conf);
9701 #endif
9702
9703         switch (ret) {
9704         case 0:
9705                 break;
9706         case -ENOTSUP:
9707                 printf("function not implemented or supported\n");
9708                 break;
9709         default:
9710                 printf("queue region config error: (%s)\n", strerror(-ret));
9711         }
9712 }
9713
9714 cmdline_parse_token_string_t cmd_queue_region_set =
9715 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9716                 set, "set");
9717 cmdline_parse_token_string_t cmd_queue_region_port =
9718         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9719 cmdline_parse_token_num_t cmd_queue_region_port_id =
9720         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9721                                 port_id, RTE_UINT16);
9722 cmdline_parse_token_string_t cmd_queue_region_cmd =
9723         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9724                                  cmd, "queue-region");
9725 cmdline_parse_token_string_t cmd_queue_region_id =
9726         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9727                                 region, "region_id");
9728 cmdline_parse_token_num_t cmd_queue_region_index =
9729         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9730                                 region_id, RTE_UINT8);
9731 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9732         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9733                                 queue_start_index, "queue_start_index");
9734 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9735         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9736                                 queue_id, RTE_UINT8);
9737 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9738         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9739                                 queue_num, "queue_num");
9740 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9741         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9742                                 queue_num_value, RTE_UINT8);
9743
9744 cmdline_parse_inst_t cmd_queue_region = {
9745         .f = cmd_queue_region_parsed,
9746         .data = NULL,
9747         .help_str = "set port <port_id> queue-region region_id <value> "
9748                 "queue_start_index <value> queue_num <value>: Set a queue region",
9749         .tokens = {
9750                 (void *)&cmd_queue_region_set,
9751                 (void *)&cmd_queue_region_port,
9752                 (void *)&cmd_queue_region_port_id,
9753                 (void *)&cmd_queue_region_cmd,
9754                 (void *)&cmd_queue_region_id,
9755                 (void *)&cmd_queue_region_index,
9756                 (void *)&cmd_queue_region_queue_start_index,
9757                 (void *)&cmd_queue_region_queue_id,
9758                 (void *)&cmd_queue_region_queue_num,
9759                 (void *)&cmd_queue_region_queue_num_value,
9760                 NULL,
9761         },
9762 };
9763
9764 /* *** queue region and flowtype set *** */
9765 struct cmd_region_flowtype_result {
9766         cmdline_fixed_string_t set;
9767         cmdline_fixed_string_t port;
9768         portid_t port_id;
9769         cmdline_fixed_string_t cmd;
9770         cmdline_fixed_string_t region;
9771         uint8_t  region_id;
9772         cmdline_fixed_string_t flowtype;
9773         uint8_t  flowtype_id;
9774 };
9775
9776 static void
9777 cmd_region_flowtype_parsed(void *parsed_result,
9778                         __rte_unused struct cmdline *cl,
9779                         __rte_unused void *data)
9780 {
9781         struct cmd_region_flowtype_result *res = parsed_result;
9782         int ret = -ENOTSUP;
9783 #ifdef RTE_NET_I40E
9784         struct rte_pmd_i40e_queue_region_conf region_conf;
9785         enum rte_pmd_i40e_queue_region_op op_type;
9786 #endif
9787
9788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9789                 return;
9790
9791 #ifdef RTE_NET_I40E
9792         memset(&region_conf, 0, sizeof(region_conf));
9793
9794         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9795         region_conf.region_id = res->region_id;
9796         region_conf.hw_flowtype = res->flowtype_id;
9797
9798         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9799                         op_type, &region_conf);
9800 #endif
9801
9802         switch (ret) {
9803         case 0:
9804                 break;
9805         case -ENOTSUP:
9806                 printf("function not implemented or supported\n");
9807                 break;
9808         default:
9809                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9810         }
9811 }
9812
9813 cmdline_parse_token_string_t cmd_region_flowtype_set =
9814 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9815                                 set, "set");
9816 cmdline_parse_token_string_t cmd_region_flowtype_port =
9817         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9818                                 port, "port");
9819 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9820         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9821                                 port_id, RTE_UINT16);
9822 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9823         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9824                                 cmd, "queue-region");
9825 cmdline_parse_token_string_t cmd_region_flowtype_index =
9826         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9827                                 region, "region_id");
9828 cmdline_parse_token_num_t cmd_region_flowtype_id =
9829         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9830                                 region_id, RTE_UINT8);
9831 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9832         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9833                                 flowtype, "flowtype");
9834 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9835         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9836                                 flowtype_id, RTE_UINT8);
9837 cmdline_parse_inst_t cmd_region_flowtype = {
9838         .f = cmd_region_flowtype_parsed,
9839         .data = NULL,
9840         .help_str = "set port <port_id> queue-region region_id <value> "
9841                 "flowtype <value>: Set a flowtype region index",
9842         .tokens = {
9843                 (void *)&cmd_region_flowtype_set,
9844                 (void *)&cmd_region_flowtype_port,
9845                 (void *)&cmd_region_flowtype_port_index,
9846                 (void *)&cmd_region_flowtype_cmd,
9847                 (void *)&cmd_region_flowtype_index,
9848                 (void *)&cmd_region_flowtype_id,
9849                 (void *)&cmd_region_flowtype_flow_index,
9850                 (void *)&cmd_region_flowtype_flow_id,
9851                 NULL,
9852         },
9853 };
9854
9855 /* *** User Priority (UP) to queue region (region_id) set *** */
9856 struct cmd_user_priority_region_result {
9857         cmdline_fixed_string_t set;
9858         cmdline_fixed_string_t port;
9859         portid_t port_id;
9860         cmdline_fixed_string_t cmd;
9861         cmdline_fixed_string_t user_priority;
9862         uint8_t  user_priority_id;
9863         cmdline_fixed_string_t region;
9864         uint8_t  region_id;
9865 };
9866
9867 static void
9868 cmd_user_priority_region_parsed(void *parsed_result,
9869                         __rte_unused struct cmdline *cl,
9870                         __rte_unused void *data)
9871 {
9872         struct cmd_user_priority_region_result *res = parsed_result;
9873         int ret = -ENOTSUP;
9874 #ifdef RTE_NET_I40E
9875         struct rte_pmd_i40e_queue_region_conf region_conf;
9876         enum rte_pmd_i40e_queue_region_op op_type;
9877 #endif
9878
9879         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9880                 return;
9881
9882 #ifdef RTE_NET_I40E
9883         memset(&region_conf, 0, sizeof(region_conf));
9884         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9885         region_conf.user_priority = res->user_priority_id;
9886         region_conf.region_id = res->region_id;
9887
9888         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9889                                 op_type, &region_conf);
9890 #endif
9891
9892         switch (ret) {
9893         case 0:
9894                 break;
9895         case -ENOTSUP:
9896                 printf("function not implemented or supported\n");
9897                 break;
9898         default:
9899                 printf("user_priority region config error: (%s)\n",
9900                                 strerror(-ret));
9901         }
9902 }
9903
9904 cmdline_parse_token_string_t cmd_user_priority_region_set =
9905         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9906                                 set, "set");
9907 cmdline_parse_token_string_t cmd_user_priority_region_port =
9908         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9909                                 port, "port");
9910 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9911         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9912                                 port_id, RTE_UINT16);
9913 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9914         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9915                                 cmd, "queue-region");
9916 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9917         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9918                                 user_priority, "UP");
9919 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9920         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9921                                 user_priority_id, RTE_UINT8);
9922 cmdline_parse_token_string_t cmd_user_priority_region_region =
9923         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9924                                 region, "region_id");
9925 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9926         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9927                                 region_id, RTE_UINT8);
9928
9929 cmdline_parse_inst_t cmd_user_priority_region = {
9930         .f = cmd_user_priority_region_parsed,
9931         .data = NULL,
9932         .help_str = "set port <port_id> queue-region UP <value> "
9933                 "region_id <value>: Set the mapping of User Priority (UP) "
9934                 "to queue region (region_id) ",
9935         .tokens = {
9936                 (void *)&cmd_user_priority_region_set,
9937                 (void *)&cmd_user_priority_region_port,
9938                 (void *)&cmd_user_priority_region_port_index,
9939                 (void *)&cmd_user_priority_region_cmd,
9940                 (void *)&cmd_user_priority_region_UP,
9941                 (void *)&cmd_user_priority_region_UP_id,
9942                 (void *)&cmd_user_priority_region_region,
9943                 (void *)&cmd_user_priority_region_region_id,
9944                 NULL,
9945         },
9946 };
9947
9948 /* *** flush all queue region related configuration *** */
9949 struct cmd_flush_queue_region_result {
9950         cmdline_fixed_string_t set;
9951         cmdline_fixed_string_t port;
9952         portid_t port_id;
9953         cmdline_fixed_string_t cmd;
9954         cmdline_fixed_string_t flush;
9955         cmdline_fixed_string_t what;
9956 };
9957
9958 static void
9959 cmd_flush_queue_region_parsed(void *parsed_result,
9960                         __rte_unused struct cmdline *cl,
9961                         __rte_unused void *data)
9962 {
9963         struct cmd_flush_queue_region_result *res = parsed_result;
9964         int ret = -ENOTSUP;
9965 #ifdef RTE_NET_I40E
9966         struct rte_pmd_i40e_queue_region_conf region_conf;
9967         enum rte_pmd_i40e_queue_region_op op_type;
9968 #endif
9969
9970         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9971                 return;
9972
9973 #ifdef RTE_NET_I40E
9974         memset(&region_conf, 0, sizeof(region_conf));
9975
9976         if (strcmp(res->what, "on") == 0)
9977                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9978         else
9979                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9980
9981         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9982                                 op_type, &region_conf);
9983 #endif
9984
9985         switch (ret) {
9986         case 0:
9987                 break;
9988         case -ENOTSUP:
9989                 printf("function not implemented or supported\n");
9990                 break;
9991         default:
9992                 printf("queue region config flush error: (%s)\n",
9993                                 strerror(-ret));
9994         }
9995 }
9996
9997 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9998         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9999                                 set, "set");
10000 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10001         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10002                                 port, "port");
10003 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10004         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10005                                 port_id, RTE_UINT16);
10006 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10007         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10008                                 cmd, "queue-region");
10009 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10010         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10011                                 flush, "flush");
10012 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10013         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10014                                 what, "on#off");
10015
10016 cmdline_parse_inst_t cmd_flush_queue_region = {
10017         .f = cmd_flush_queue_region_parsed,
10018         .data = NULL,
10019         .help_str = "set port <port_id> queue-region flush on|off"
10020                 ": flush all queue region related configuration",
10021         .tokens = {
10022                 (void *)&cmd_flush_queue_region_set,
10023                 (void *)&cmd_flush_queue_region_port,
10024                 (void *)&cmd_flush_queue_region_port_index,
10025                 (void *)&cmd_flush_queue_region_cmd,
10026                 (void *)&cmd_flush_queue_region_flush,
10027                 (void *)&cmd_flush_queue_region_what,
10028                 NULL,
10029         },
10030 };
10031
10032 /* *** get all queue region related configuration info *** */
10033 struct cmd_show_queue_region_info {
10034         cmdline_fixed_string_t show;
10035         cmdline_fixed_string_t port;
10036         portid_t port_id;
10037         cmdline_fixed_string_t cmd;
10038 };
10039
10040 static void
10041 cmd_show_queue_region_info_parsed(void *parsed_result,
10042                         __rte_unused struct cmdline *cl,
10043                         __rte_unused void *data)
10044 {
10045         struct cmd_show_queue_region_info *res = parsed_result;
10046         int ret = -ENOTSUP;
10047 #ifdef RTE_NET_I40E
10048         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10049         enum rte_pmd_i40e_queue_region_op op_type;
10050 #endif
10051
10052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10053                 return;
10054
10055 #ifdef RTE_NET_I40E
10056         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10057
10058         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10059
10060         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10061                                         op_type, &rte_pmd_regions);
10062
10063         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10064 #endif
10065
10066         switch (ret) {
10067         case 0:
10068                 break;
10069         case -ENOTSUP:
10070                 printf("function not implemented or supported\n");
10071                 break;
10072         default:
10073                 printf("queue region config info show error: (%s)\n",
10074                                 strerror(-ret));
10075         }
10076 }
10077
10078 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10079 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10080                                 show, "show");
10081 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10082         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10083                                 port, "port");
10084 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10085         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10086                                 port_id, RTE_UINT16);
10087 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10088         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10089                                 cmd, "queue-region");
10090
10091 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10092         .f = cmd_show_queue_region_info_parsed,
10093         .data = NULL,
10094         .help_str = "show port <port_id> queue-region"
10095                 ": show all queue region related configuration info",
10096         .tokens = {
10097                 (void *)&cmd_show_queue_region_info_get,
10098                 (void *)&cmd_show_queue_region_info_port,
10099                 (void *)&cmd_show_queue_region_info_port_index,
10100                 (void *)&cmd_show_queue_region_info_cmd,
10101                 NULL,
10102         },
10103 };
10104
10105 /* *** Filters Control *** */
10106
10107 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10108 do { \
10109         if ((ip_addr).family == AF_INET) \
10110                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10111         else { \
10112                 printf("invalid parameter.\n"); \
10113                 return; \
10114         } \
10115 } while (0)
10116
10117 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10118 do { \
10119         if ((ip_addr).family == AF_INET6) \
10120                 rte_memcpy(&(ip), \
10121                                  &((ip_addr).addr.ipv6), \
10122                                  sizeof(struct in6_addr)); \
10123         else { \
10124                 printf("invalid parameter.\n"); \
10125                 return; \
10126         } \
10127 } while (0)
10128
10129 #ifdef RTE_NET_I40E
10130
10131 static uint16_t
10132 str2flowtype(char *string)
10133 {
10134         uint8_t i = 0;
10135         static const struct {
10136                 char str[32];
10137                 uint16_t type;
10138         } flowtype_str[] = {
10139                 {"raw", RTE_ETH_FLOW_RAW},
10140                 {"ipv4", RTE_ETH_FLOW_IPV4},
10141                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10142                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10143                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10144                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10145                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10146                 {"ipv6", RTE_ETH_FLOW_IPV6},
10147                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10148                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10149                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10150                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10151                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10152                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10153         };
10154
10155         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10156                 if (!strcmp(flowtype_str[i].str, string))
10157                         return flowtype_str[i].type;
10158         }
10159
10160         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10161                 return (uint16_t)atoi(string);
10162
10163         return RTE_ETH_FLOW_UNKNOWN;
10164 }
10165
10166 /* *** deal with flow director filter *** */
10167 struct cmd_flow_director_result {
10168         cmdline_fixed_string_t flow_director_filter;
10169         portid_t port_id;
10170         cmdline_fixed_string_t mode;
10171         cmdline_fixed_string_t mode_value;
10172         cmdline_fixed_string_t ops;
10173         cmdline_fixed_string_t flow;
10174         cmdline_fixed_string_t flow_type;
10175         cmdline_fixed_string_t drop;
10176         cmdline_fixed_string_t queue;
10177         uint16_t  queue_id;
10178         cmdline_fixed_string_t fd_id;
10179         uint32_t  fd_id_value;
10180         cmdline_fixed_string_t packet;
10181         char filepath[];
10182 };
10183
10184 static void
10185 cmd_flow_director_filter_parsed(void *parsed_result,
10186                           __rte_unused struct cmdline *cl,
10187                           __rte_unused void *data)
10188 {
10189         struct cmd_flow_director_result *res = parsed_result;
10190         int ret = 0;
10191         struct rte_pmd_i40e_flow_type_mapping
10192                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10193         struct rte_pmd_i40e_pkt_template_conf conf;
10194         uint16_t flow_type = str2flowtype(res->flow_type);
10195         uint16_t i, port = res->port_id;
10196         uint8_t add;
10197
10198         memset(&conf, 0, sizeof(conf));
10199
10200         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10201                 printf("Invalid flow type specified.\n");
10202                 return;
10203         }
10204         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10205                                                  mapping);
10206         if (ret)
10207                 return;
10208         if (mapping[flow_type].pctype == 0ULL) {
10209                 printf("Invalid flow type specified.\n");
10210                 return;
10211         }
10212         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10213                 if (mapping[flow_type].pctype & (1ULL << i)) {
10214                         conf.input.pctype = i;
10215                         break;
10216                 }
10217         }
10218
10219         conf.input.packet = open_file(res->filepath,
10220                                 &conf.input.length);
10221         if (!conf.input.packet)
10222                 return;
10223         if (!strcmp(res->drop, "drop"))
10224                 conf.action.behavior =
10225                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10226         else
10227                 conf.action.behavior =
10228                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10229         conf.action.report_status =
10230                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10231         conf.action.rx_queue = res->queue_id;
10232         conf.soft_id = res->fd_id_value;
10233         add  = strcmp(res->ops, "del") ? 1 : 0;
10234         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10235                                                         &conf,
10236                                                         add);
10237         if (ret < 0)
10238                 printf("flow director config error: (%s)\n",
10239                        strerror(-ret));
10240         close_file(conf.input.packet);
10241 }
10242
10243 cmdline_parse_token_string_t cmd_flow_director_filter =
10244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10245                                  flow_director_filter, "flow_director_filter");
10246 cmdline_parse_token_num_t cmd_flow_director_port_id =
10247         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10248                               port_id, RTE_UINT16);
10249 cmdline_parse_token_string_t cmd_flow_director_ops =
10250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10251                                  ops, "add#del#update");
10252 cmdline_parse_token_string_t cmd_flow_director_flow =
10253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10254                                  flow, "flow");
10255 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10257                 flow_type, NULL);
10258 cmdline_parse_token_string_t cmd_flow_director_drop =
10259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10260                                  drop, "drop#fwd");
10261 cmdline_parse_token_string_t cmd_flow_director_queue =
10262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10263                                  queue, "queue");
10264 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10265         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10266                               queue_id, RTE_UINT16);
10267 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10269                                  fd_id, "fd_id");
10270 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10271         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10272                               fd_id_value, RTE_UINT32);
10273
10274 cmdline_parse_token_string_t cmd_flow_director_mode =
10275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10276                                  mode, "mode");
10277 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10279                                  mode_value, "raw");
10280 cmdline_parse_token_string_t cmd_flow_director_packet =
10281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10282                                  packet, "packet");
10283 cmdline_parse_token_string_t cmd_flow_director_filepath =
10284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10285                                  filepath, NULL);
10286
10287 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10288         .f = cmd_flow_director_filter_parsed,
10289         .data = NULL,
10290         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10291                 "director entry on NIC",
10292         .tokens = {
10293                 (void *)&cmd_flow_director_filter,
10294                 (void *)&cmd_flow_director_port_id,
10295                 (void *)&cmd_flow_director_mode,
10296                 (void *)&cmd_flow_director_mode_raw,
10297                 (void *)&cmd_flow_director_ops,
10298                 (void *)&cmd_flow_director_flow,
10299                 (void *)&cmd_flow_director_flow_type,
10300                 (void *)&cmd_flow_director_drop,
10301                 (void *)&cmd_flow_director_queue,
10302                 (void *)&cmd_flow_director_queue_id,
10303                 (void *)&cmd_flow_director_fd_id,
10304                 (void *)&cmd_flow_director_fd_id_value,
10305                 (void *)&cmd_flow_director_packet,
10306                 (void *)&cmd_flow_director_filepath,
10307                 NULL,
10308         },
10309 };
10310
10311 #endif /* RTE_NET_I40E */
10312
10313 /* *** deal with flow director mask *** */
10314 struct cmd_flow_director_mask_result {
10315         cmdline_fixed_string_t flow_director_mask;
10316         portid_t port_id;
10317         cmdline_fixed_string_t mode;
10318         cmdline_fixed_string_t mode_value;
10319         cmdline_fixed_string_t vlan;
10320         uint16_t vlan_mask;
10321         cmdline_fixed_string_t src_mask;
10322         cmdline_ipaddr_t ipv4_src;
10323         cmdline_ipaddr_t ipv6_src;
10324         uint16_t port_src;
10325         cmdline_fixed_string_t dst_mask;
10326         cmdline_ipaddr_t ipv4_dst;
10327         cmdline_ipaddr_t ipv6_dst;
10328         uint16_t port_dst;
10329         cmdline_fixed_string_t mac;
10330         uint8_t mac_addr_byte_mask;
10331         cmdline_fixed_string_t tunnel_id;
10332         uint32_t tunnel_id_mask;
10333         cmdline_fixed_string_t tunnel_type;
10334         uint8_t tunnel_type_mask;
10335 };
10336
10337 static void
10338 cmd_flow_director_mask_parsed(void *parsed_result,
10339                           __rte_unused struct cmdline *cl,
10340                           __rte_unused void *data)
10341 {
10342         struct cmd_flow_director_mask_result *res = parsed_result;
10343         struct rte_eth_fdir_masks *mask;
10344         struct rte_port *port;
10345
10346         port = &ports[res->port_id];
10347         /** Check if the port is not started **/
10348         if (port->port_status != RTE_PORT_STOPPED) {
10349                 printf("Please stop port %d first\n", res->port_id);
10350                 return;
10351         }
10352
10353         mask = &port->dev_conf.fdir_conf.mask;
10354
10355         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10356                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10357                         printf("Please set mode to MAC-VLAN.\n");
10358                         return;
10359                 }
10360
10361                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10362         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10363                 if (strcmp(res->mode_value, "Tunnel")) {
10364                         printf("Please set mode to Tunnel.\n");
10365                         return;
10366                 }
10367
10368                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10369                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10370                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10371                 mask->tunnel_type_mask = res->tunnel_type_mask;
10372         } else {
10373                 if (strcmp(res->mode_value, "IP")) {
10374                         printf("Please set mode to IP.\n");
10375                         return;
10376                 }
10377
10378                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10379                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10380                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10381                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10382                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10383                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10384                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10385         }
10386
10387         cmd_reconfig_device_queue(res->port_id, 1, 1);
10388 }
10389
10390 cmdline_parse_token_string_t cmd_flow_director_mask =
10391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10392                                  flow_director_mask, "flow_director_mask");
10393 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10394         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10395                               port_id, RTE_UINT16);
10396 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10398                                  vlan, "vlan");
10399 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10400         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10401                               vlan_mask, RTE_UINT16);
10402 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10403         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10404                                  src_mask, "src_mask");
10405 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10406         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10407                                  ipv4_src);
10408 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10409         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10410                                  ipv6_src);
10411 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10412         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10413                               port_src, RTE_UINT16);
10414 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10415         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10416                                  dst_mask, "dst_mask");
10417 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10418         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10419                                  ipv4_dst);
10420 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10421         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  ipv6_dst);
10423 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10424         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10425                               port_dst, RTE_UINT16);
10426
10427 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10429                                  mode, "mode");
10430 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10432                                  mode_value, "IP");
10433 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10435                                  mode_value, "MAC-VLAN");
10436 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10438                                  mode_value, "Tunnel");
10439 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10441                                  mac, "mac");
10442 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10444                               mac_addr_byte_mask, RTE_UINT8);
10445 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10447                                  tunnel_type, "tunnel-type");
10448 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10449         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10450                               tunnel_type_mask, RTE_UINT8);
10451 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10453                                  tunnel_id, "tunnel-id");
10454 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10455         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10456                               tunnel_id_mask, RTE_UINT32);
10457
10458 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10459         .f = cmd_flow_director_mask_parsed,
10460         .data = NULL,
10461         .help_str = "flow_director_mask ... : "
10462                 "Set IP mode flow director's mask on NIC",
10463         .tokens = {
10464                 (void *)&cmd_flow_director_mask,
10465                 (void *)&cmd_flow_director_mask_port_id,
10466                 (void *)&cmd_flow_director_mask_mode,
10467                 (void *)&cmd_flow_director_mask_mode_ip,
10468                 (void *)&cmd_flow_director_mask_vlan,
10469                 (void *)&cmd_flow_director_mask_vlan_value,
10470                 (void *)&cmd_flow_director_mask_src,
10471                 (void *)&cmd_flow_director_mask_ipv4_src,
10472                 (void *)&cmd_flow_director_mask_ipv6_src,
10473                 (void *)&cmd_flow_director_mask_port_src,
10474                 (void *)&cmd_flow_director_mask_dst,
10475                 (void *)&cmd_flow_director_mask_ipv4_dst,
10476                 (void *)&cmd_flow_director_mask_ipv6_dst,
10477                 (void *)&cmd_flow_director_mask_port_dst,
10478                 NULL,
10479         },
10480 };
10481
10482 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10483         .f = cmd_flow_director_mask_parsed,
10484         .data = NULL,
10485         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10486                 "flow director's mask on NIC",
10487         .tokens = {
10488                 (void *)&cmd_flow_director_mask,
10489                 (void *)&cmd_flow_director_mask_port_id,
10490                 (void *)&cmd_flow_director_mask_mode,
10491                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10492                 (void *)&cmd_flow_director_mask_vlan,
10493                 (void *)&cmd_flow_director_mask_vlan_value,
10494                 NULL,
10495         },
10496 };
10497
10498 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10499         .f = cmd_flow_director_mask_parsed,
10500         .data = NULL,
10501         .help_str = "flow_director_mask ... : Set tunnel mode "
10502                 "flow director's mask on NIC",
10503         .tokens = {
10504                 (void *)&cmd_flow_director_mask,
10505                 (void *)&cmd_flow_director_mask_port_id,
10506                 (void *)&cmd_flow_director_mask_mode,
10507                 (void *)&cmd_flow_director_mask_mode_tunnel,
10508                 (void *)&cmd_flow_director_mask_vlan,
10509                 (void *)&cmd_flow_director_mask_vlan_value,
10510                 (void *)&cmd_flow_director_mask_mac,
10511                 (void *)&cmd_flow_director_mask_mac_value,
10512                 (void *)&cmd_flow_director_mask_tunnel_type,
10513                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10514                 (void *)&cmd_flow_director_mask_tunnel_id,
10515                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10516                 NULL,
10517         },
10518 };
10519
10520 /* *** deal with flow director flexible payload configuration *** */
10521 struct cmd_flow_director_flexpayload_result {
10522         cmdline_fixed_string_t flow_director_flexpayload;
10523         portid_t port_id;
10524         cmdline_fixed_string_t payload_layer;
10525         cmdline_fixed_string_t payload_cfg;
10526 };
10527
10528 static inline int
10529 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10530 {
10531         char s[256];
10532         const char *p, *p0 = q_arg;
10533         char *end;
10534         unsigned long int_fld;
10535         char *str_fld[max_num];
10536         int i;
10537         unsigned size;
10538         int ret = -1;
10539
10540         p = strchr(p0, '(');
10541         if (p == NULL)
10542                 return -1;
10543         ++p;
10544         p0 = strchr(p, ')');
10545         if (p0 == NULL)
10546                 return -1;
10547
10548         size = p0 - p;
10549         if (size >= sizeof(s))
10550                 return -1;
10551
10552         snprintf(s, sizeof(s), "%.*s", size, p);
10553         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10554         if (ret < 0 || ret > max_num)
10555                 return -1;
10556         for (i = 0; i < ret; i++) {
10557                 errno = 0;
10558                 int_fld = strtoul(str_fld[i], &end, 0);
10559                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10560                         return -1;
10561                 offsets[i] = (uint16_t)int_fld;
10562         }
10563         return ret;
10564 }
10565
10566 static void
10567 cmd_flow_director_flxpld_parsed(void *parsed_result,
10568                           __rte_unused struct cmdline *cl,
10569                           __rte_unused void *data)
10570 {
10571         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10572         struct rte_eth_flex_payload_cfg flex_cfg;
10573         struct rte_port *port;
10574         int ret = 0;
10575
10576         port = &ports[res->port_id];
10577         /** Check if the port is not started **/
10578         if (port->port_status != RTE_PORT_STOPPED) {
10579                 printf("Please stop port %d first\n", res->port_id);
10580                 return;
10581         }
10582
10583         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10584
10585         if (!strcmp(res->payload_layer, "raw"))
10586                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10587         else if (!strcmp(res->payload_layer, "l2"))
10588                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10589         else if (!strcmp(res->payload_layer, "l3"))
10590                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10591         else if (!strcmp(res->payload_layer, "l4"))
10592                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10593
10594         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10595                             RTE_ETH_FDIR_MAX_FLEXLEN);
10596         if (ret < 0) {
10597                 printf("error: Cannot parse flex payload input.\n");
10598                 return;
10599         }
10600
10601         fdir_set_flex_payload(res->port_id, &flex_cfg);
10602         cmd_reconfig_device_queue(res->port_id, 1, 1);
10603 }
10604
10605 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10607                                  flow_director_flexpayload,
10608                                  "flow_director_flex_payload");
10609 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10610         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10611                               port_id, RTE_UINT16);
10612 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10613         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10614                                  payload_layer, "raw#l2#l3#l4");
10615 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10616         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10617                                  payload_cfg, NULL);
10618
10619 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10620         .f = cmd_flow_director_flxpld_parsed,
10621         .data = NULL,
10622         .help_str = "flow_director_flexpayload ... : "
10623                 "Set flow director's flex payload on NIC",
10624         .tokens = {
10625                 (void *)&cmd_flow_director_flexpayload,
10626                 (void *)&cmd_flow_director_flexpayload_port_id,
10627                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10628                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10629                 NULL,
10630         },
10631 };
10632
10633 /* Generic flow interface command. */
10634 extern cmdline_parse_inst_t cmd_flow;
10635
10636 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10637 struct cmd_mcast_addr_result {
10638         cmdline_fixed_string_t mcast_addr_cmd;
10639         cmdline_fixed_string_t what;
10640         uint16_t port_num;
10641         struct rte_ether_addr mc_addr;
10642 };
10643
10644 static void cmd_mcast_addr_parsed(void *parsed_result,
10645                 __rte_unused struct cmdline *cl,
10646                 __rte_unused void *data)
10647 {
10648         struct cmd_mcast_addr_result *res = parsed_result;
10649
10650         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10651                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10652                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10653                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10654                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10655                 return;
10656         }
10657         if (strcmp(res->what, "add") == 0)
10658                 mcast_addr_add(res->port_num, &res->mc_addr);
10659         else
10660                 mcast_addr_remove(res->port_num, &res->mc_addr);
10661 }
10662
10663 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10664         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10665                                  mcast_addr_cmd, "mcast_addr");
10666 cmdline_parse_token_string_t cmd_mcast_addr_what =
10667         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10668                                  "add#remove");
10669 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10670         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10671                                  RTE_UINT16);
10672 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10673         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10674
10675 cmdline_parse_inst_t cmd_mcast_addr = {
10676         .f = cmd_mcast_addr_parsed,
10677         .data = (void *)0,
10678         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10679                 "Add/Remove multicast MAC address on port_id",
10680         .tokens = {
10681                 (void *)&cmd_mcast_addr_cmd,
10682                 (void *)&cmd_mcast_addr_what,
10683                 (void *)&cmd_mcast_addr_portnum,
10684                 (void *)&cmd_mcast_addr_addr,
10685                 NULL,
10686         },
10687 };
10688
10689 /* vf vlan anti spoof configuration */
10690
10691 /* Common result structure for vf vlan anti spoof */
10692 struct cmd_vf_vlan_anti_spoof_result {
10693         cmdline_fixed_string_t set;
10694         cmdline_fixed_string_t vf;
10695         cmdline_fixed_string_t vlan;
10696         cmdline_fixed_string_t antispoof;
10697         portid_t port_id;
10698         uint32_t vf_id;
10699         cmdline_fixed_string_t on_off;
10700 };
10701
10702 /* Common CLI fields for vf vlan anti spoof enable disable */
10703 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10704         TOKEN_STRING_INITIALIZER
10705                 (struct cmd_vf_vlan_anti_spoof_result,
10706                  set, "set");
10707 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10708         TOKEN_STRING_INITIALIZER
10709                 (struct cmd_vf_vlan_anti_spoof_result,
10710                  vf, "vf");
10711 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10712         TOKEN_STRING_INITIALIZER
10713                 (struct cmd_vf_vlan_anti_spoof_result,
10714                  vlan, "vlan");
10715 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10716         TOKEN_STRING_INITIALIZER
10717                 (struct cmd_vf_vlan_anti_spoof_result,
10718                  antispoof, "antispoof");
10719 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10720         TOKEN_NUM_INITIALIZER
10721                 (struct cmd_vf_vlan_anti_spoof_result,
10722                  port_id, RTE_UINT16);
10723 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10724         TOKEN_NUM_INITIALIZER
10725                 (struct cmd_vf_vlan_anti_spoof_result,
10726                  vf_id, RTE_UINT32);
10727 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10728         TOKEN_STRING_INITIALIZER
10729                 (struct cmd_vf_vlan_anti_spoof_result,
10730                  on_off, "on#off");
10731
10732 static void
10733 cmd_set_vf_vlan_anti_spoof_parsed(
10734         void *parsed_result,
10735         __rte_unused struct cmdline *cl,
10736         __rte_unused void *data)
10737 {
10738         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10739         int ret = -ENOTSUP;
10740
10741         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10742
10743         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10744                 return;
10745
10746 #ifdef RTE_NET_IXGBE
10747         if (ret == -ENOTSUP)
10748                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10749                                 res->vf_id, is_on);
10750 #endif
10751 #ifdef RTE_NET_I40E
10752         if (ret == -ENOTSUP)
10753                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10754                                 res->vf_id, is_on);
10755 #endif
10756 #ifdef RTE_NET_BNXT
10757         if (ret == -ENOTSUP)
10758                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10759                                 res->vf_id, is_on);
10760 #endif
10761
10762         switch (ret) {
10763         case 0:
10764                 break;
10765         case -EINVAL:
10766                 printf("invalid vf_id %d\n", res->vf_id);
10767                 break;
10768         case -ENODEV:
10769                 printf("invalid port_id %d\n", res->port_id);
10770                 break;
10771         case -ENOTSUP:
10772                 printf("function not implemented\n");
10773                 break;
10774         default:
10775                 printf("programming error: (%s)\n", strerror(-ret));
10776         }
10777 }
10778
10779 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10780         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10781         .data = NULL,
10782         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10783         .tokens = {
10784                 (void *)&cmd_vf_vlan_anti_spoof_set,
10785                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10786                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10787                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10788                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10789                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10790                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10791                 NULL,
10792         },
10793 };
10794
10795 /* vf mac anti spoof configuration */
10796
10797 /* Common result structure for vf mac anti spoof */
10798 struct cmd_vf_mac_anti_spoof_result {
10799         cmdline_fixed_string_t set;
10800         cmdline_fixed_string_t vf;
10801         cmdline_fixed_string_t mac;
10802         cmdline_fixed_string_t antispoof;
10803         portid_t port_id;
10804         uint32_t vf_id;
10805         cmdline_fixed_string_t on_off;
10806 };
10807
10808 /* Common CLI fields for vf mac anti spoof enable disable */
10809 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10810         TOKEN_STRING_INITIALIZER
10811                 (struct cmd_vf_mac_anti_spoof_result,
10812                  set, "set");
10813 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10814         TOKEN_STRING_INITIALIZER
10815                 (struct cmd_vf_mac_anti_spoof_result,
10816                  vf, "vf");
10817 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10818         TOKEN_STRING_INITIALIZER
10819                 (struct cmd_vf_mac_anti_spoof_result,
10820                  mac, "mac");
10821 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10822         TOKEN_STRING_INITIALIZER
10823                 (struct cmd_vf_mac_anti_spoof_result,
10824                  antispoof, "antispoof");
10825 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10826         TOKEN_NUM_INITIALIZER
10827                 (struct cmd_vf_mac_anti_spoof_result,
10828                  port_id, RTE_UINT16);
10829 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10830         TOKEN_NUM_INITIALIZER
10831                 (struct cmd_vf_mac_anti_spoof_result,
10832                  vf_id, RTE_UINT32);
10833 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10834         TOKEN_STRING_INITIALIZER
10835                 (struct cmd_vf_mac_anti_spoof_result,
10836                  on_off, "on#off");
10837
10838 static void
10839 cmd_set_vf_mac_anti_spoof_parsed(
10840         void *parsed_result,
10841         __rte_unused struct cmdline *cl,
10842         __rte_unused void *data)
10843 {
10844         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10845         int ret = -ENOTSUP;
10846
10847         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10848
10849         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10850                 return;
10851
10852 #ifdef RTE_NET_IXGBE
10853         if (ret == -ENOTSUP)
10854                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10855                         res->vf_id, is_on);
10856 #endif
10857 #ifdef RTE_NET_I40E
10858         if (ret == -ENOTSUP)
10859                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10860                         res->vf_id, is_on);
10861 #endif
10862 #ifdef RTE_NET_BNXT
10863         if (ret == -ENOTSUP)
10864                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10865                         res->vf_id, is_on);
10866 #endif
10867
10868         switch (ret) {
10869         case 0:
10870                 break;
10871         case -EINVAL:
10872                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10873                 break;
10874         case -ENODEV:
10875                 printf("invalid port_id %d\n", res->port_id);
10876                 break;
10877         case -ENOTSUP:
10878                 printf("function not implemented\n");
10879                 break;
10880         default:
10881                 printf("programming error: (%s)\n", strerror(-ret));
10882         }
10883 }
10884
10885 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10886         .f = cmd_set_vf_mac_anti_spoof_parsed,
10887         .data = NULL,
10888         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10889         .tokens = {
10890                 (void *)&cmd_vf_mac_anti_spoof_set,
10891                 (void *)&cmd_vf_mac_anti_spoof_vf,
10892                 (void *)&cmd_vf_mac_anti_spoof_mac,
10893                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10894                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10895                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10896                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10897                 NULL,
10898         },
10899 };
10900
10901 /* vf vlan strip queue configuration */
10902
10903 /* Common result structure for vf mac anti spoof */
10904 struct cmd_vf_vlan_stripq_result {
10905         cmdline_fixed_string_t set;
10906         cmdline_fixed_string_t vf;
10907         cmdline_fixed_string_t vlan;
10908         cmdline_fixed_string_t stripq;
10909         portid_t port_id;
10910         uint16_t vf_id;
10911         cmdline_fixed_string_t on_off;
10912 };
10913
10914 /* Common CLI fields for vf vlan strip enable disable */
10915 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10916         TOKEN_STRING_INITIALIZER
10917                 (struct cmd_vf_vlan_stripq_result,
10918                  set, "set");
10919 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10920         TOKEN_STRING_INITIALIZER
10921                 (struct cmd_vf_vlan_stripq_result,
10922                  vf, "vf");
10923 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10924         TOKEN_STRING_INITIALIZER
10925                 (struct cmd_vf_vlan_stripq_result,
10926                  vlan, "vlan");
10927 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10928         TOKEN_STRING_INITIALIZER
10929                 (struct cmd_vf_vlan_stripq_result,
10930                  stripq, "stripq");
10931 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10932         TOKEN_NUM_INITIALIZER
10933                 (struct cmd_vf_vlan_stripq_result,
10934                  port_id, RTE_UINT16);
10935 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10936         TOKEN_NUM_INITIALIZER
10937                 (struct cmd_vf_vlan_stripq_result,
10938                  vf_id, RTE_UINT16);
10939 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10940         TOKEN_STRING_INITIALIZER
10941                 (struct cmd_vf_vlan_stripq_result,
10942                  on_off, "on#off");
10943
10944 static void
10945 cmd_set_vf_vlan_stripq_parsed(
10946         void *parsed_result,
10947         __rte_unused struct cmdline *cl,
10948         __rte_unused void *data)
10949 {
10950         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10951         int ret = -ENOTSUP;
10952
10953         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10954
10955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10956                 return;
10957
10958 #ifdef RTE_NET_IXGBE
10959         if (ret == -ENOTSUP)
10960                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10961                         res->vf_id, is_on);
10962 #endif
10963 #ifdef RTE_NET_I40E
10964         if (ret == -ENOTSUP)
10965                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10966                         res->vf_id, is_on);
10967 #endif
10968 #ifdef RTE_NET_BNXT
10969         if (ret == -ENOTSUP)
10970                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10971                         res->vf_id, is_on);
10972 #endif
10973
10974         switch (ret) {
10975         case 0:
10976                 break;
10977         case -EINVAL:
10978                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10979                 break;
10980         case -ENODEV:
10981                 printf("invalid port_id %d\n", res->port_id);
10982                 break;
10983         case -ENOTSUP:
10984                 printf("function not implemented\n");
10985                 break;
10986         default:
10987                 printf("programming error: (%s)\n", strerror(-ret));
10988         }
10989 }
10990
10991 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10992         .f = cmd_set_vf_vlan_stripq_parsed,
10993         .data = NULL,
10994         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10995         .tokens = {
10996                 (void *)&cmd_vf_vlan_stripq_set,
10997                 (void *)&cmd_vf_vlan_stripq_vf,
10998                 (void *)&cmd_vf_vlan_stripq_vlan,
10999                 (void *)&cmd_vf_vlan_stripq_stripq,
11000                 (void *)&cmd_vf_vlan_stripq_port_id,
11001                 (void *)&cmd_vf_vlan_stripq_vf_id,
11002                 (void *)&cmd_vf_vlan_stripq_on_off,
11003                 NULL,
11004         },
11005 };
11006
11007 /* vf vlan insert configuration */
11008
11009 /* Common result structure for vf vlan insert */
11010 struct cmd_vf_vlan_insert_result {
11011         cmdline_fixed_string_t set;
11012         cmdline_fixed_string_t vf;
11013         cmdline_fixed_string_t vlan;
11014         cmdline_fixed_string_t insert;
11015         portid_t port_id;
11016         uint16_t vf_id;
11017         uint16_t vlan_id;
11018 };
11019
11020 /* Common CLI fields for vf vlan insert enable disable */
11021 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11022         TOKEN_STRING_INITIALIZER
11023                 (struct cmd_vf_vlan_insert_result,
11024                  set, "set");
11025 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11026         TOKEN_STRING_INITIALIZER
11027                 (struct cmd_vf_vlan_insert_result,
11028                  vf, "vf");
11029 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11030         TOKEN_STRING_INITIALIZER
11031                 (struct cmd_vf_vlan_insert_result,
11032                  vlan, "vlan");
11033 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11034         TOKEN_STRING_INITIALIZER
11035                 (struct cmd_vf_vlan_insert_result,
11036                  insert, "insert");
11037 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11038         TOKEN_NUM_INITIALIZER
11039                 (struct cmd_vf_vlan_insert_result,
11040                  port_id, RTE_UINT16);
11041 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11042         TOKEN_NUM_INITIALIZER
11043                 (struct cmd_vf_vlan_insert_result,
11044                  vf_id, RTE_UINT16);
11045 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11046         TOKEN_NUM_INITIALIZER
11047                 (struct cmd_vf_vlan_insert_result,
11048                  vlan_id, RTE_UINT16);
11049
11050 static void
11051 cmd_set_vf_vlan_insert_parsed(
11052         void *parsed_result,
11053         __rte_unused struct cmdline *cl,
11054         __rte_unused void *data)
11055 {
11056         struct cmd_vf_vlan_insert_result *res = parsed_result;
11057         int ret = -ENOTSUP;
11058
11059         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11060                 return;
11061
11062 #ifdef RTE_NET_IXGBE
11063         if (ret == -ENOTSUP)
11064                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11065                         res->vlan_id);
11066 #endif
11067 #ifdef RTE_NET_I40E
11068         if (ret == -ENOTSUP)
11069                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11070                         res->vlan_id);
11071 #endif
11072 #ifdef RTE_NET_BNXT
11073         if (ret == -ENOTSUP)
11074                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11075                         res->vlan_id);
11076 #endif
11077
11078         switch (ret) {
11079         case 0:
11080                 break;
11081         case -EINVAL:
11082                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11083                 break;
11084         case -ENODEV:
11085                 printf("invalid port_id %d\n", res->port_id);
11086                 break;
11087         case -ENOTSUP:
11088                 printf("function not implemented\n");
11089                 break;
11090         default:
11091                 printf("programming error: (%s)\n", strerror(-ret));
11092         }
11093 }
11094
11095 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11096         .f = cmd_set_vf_vlan_insert_parsed,
11097         .data = NULL,
11098         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11099         .tokens = {
11100                 (void *)&cmd_vf_vlan_insert_set,
11101                 (void *)&cmd_vf_vlan_insert_vf,
11102                 (void *)&cmd_vf_vlan_insert_vlan,
11103                 (void *)&cmd_vf_vlan_insert_insert,
11104                 (void *)&cmd_vf_vlan_insert_port_id,
11105                 (void *)&cmd_vf_vlan_insert_vf_id,
11106                 (void *)&cmd_vf_vlan_insert_vlan_id,
11107                 NULL,
11108         },
11109 };
11110
11111 /* tx loopback configuration */
11112
11113 /* Common result structure for tx loopback */
11114 struct cmd_tx_loopback_result {
11115         cmdline_fixed_string_t set;
11116         cmdline_fixed_string_t tx;
11117         cmdline_fixed_string_t loopback;
11118         portid_t port_id;
11119         cmdline_fixed_string_t on_off;
11120 };
11121
11122 /* Common CLI fields for tx loopback enable disable */
11123 cmdline_parse_token_string_t cmd_tx_loopback_set =
11124         TOKEN_STRING_INITIALIZER
11125                 (struct cmd_tx_loopback_result,
11126                  set, "set");
11127 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11128         TOKEN_STRING_INITIALIZER
11129                 (struct cmd_tx_loopback_result,
11130                  tx, "tx");
11131 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11132         TOKEN_STRING_INITIALIZER
11133                 (struct cmd_tx_loopback_result,
11134                  loopback, "loopback");
11135 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11136         TOKEN_NUM_INITIALIZER
11137                 (struct cmd_tx_loopback_result,
11138                  port_id, RTE_UINT16);
11139 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11140         TOKEN_STRING_INITIALIZER
11141                 (struct cmd_tx_loopback_result,
11142                  on_off, "on#off");
11143
11144 static void
11145 cmd_set_tx_loopback_parsed(
11146         void *parsed_result,
11147         __rte_unused struct cmdline *cl,
11148         __rte_unused void *data)
11149 {
11150         struct cmd_tx_loopback_result *res = parsed_result;
11151         int ret = -ENOTSUP;
11152
11153         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11154
11155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11156                 return;
11157
11158 #ifdef RTE_NET_IXGBE
11159         if (ret == -ENOTSUP)
11160                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11161 #endif
11162 #ifdef RTE_NET_I40E
11163         if (ret == -ENOTSUP)
11164                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11165 #endif
11166 #ifdef RTE_NET_BNXT
11167         if (ret == -ENOTSUP)
11168                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11169 #endif
11170 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11171         if (ret == -ENOTSUP)
11172                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11173 #endif
11174
11175         switch (ret) {
11176         case 0:
11177                 break;
11178         case -EINVAL:
11179                 printf("invalid is_on %d\n", is_on);
11180                 break;
11181         case -ENODEV:
11182                 printf("invalid port_id %d\n", res->port_id);
11183                 break;
11184         case -ENOTSUP:
11185                 printf("function not implemented\n");
11186                 break;
11187         default:
11188                 printf("programming error: (%s)\n", strerror(-ret));
11189         }
11190 }
11191
11192 cmdline_parse_inst_t cmd_set_tx_loopback = {
11193         .f = cmd_set_tx_loopback_parsed,
11194         .data = NULL,
11195         .help_str = "set tx loopback <port_id> on|off",
11196         .tokens = {
11197                 (void *)&cmd_tx_loopback_set,
11198                 (void *)&cmd_tx_loopback_tx,
11199                 (void *)&cmd_tx_loopback_loopback,
11200                 (void *)&cmd_tx_loopback_port_id,
11201                 (void *)&cmd_tx_loopback_on_off,
11202                 NULL,
11203         },
11204 };
11205
11206 /* all queues drop enable configuration */
11207
11208 /* Common result structure for all queues drop enable */
11209 struct cmd_all_queues_drop_en_result {
11210         cmdline_fixed_string_t set;
11211         cmdline_fixed_string_t all;
11212         cmdline_fixed_string_t queues;
11213         cmdline_fixed_string_t drop;
11214         portid_t port_id;
11215         cmdline_fixed_string_t on_off;
11216 };
11217
11218 /* Common CLI fields for tx loopback enable disable */
11219 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11220         TOKEN_STRING_INITIALIZER
11221                 (struct cmd_all_queues_drop_en_result,
11222                  set, "set");
11223 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11224         TOKEN_STRING_INITIALIZER
11225                 (struct cmd_all_queues_drop_en_result,
11226                  all, "all");
11227 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11228         TOKEN_STRING_INITIALIZER
11229                 (struct cmd_all_queues_drop_en_result,
11230                  queues, "queues");
11231 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11232         TOKEN_STRING_INITIALIZER
11233                 (struct cmd_all_queues_drop_en_result,
11234                  drop, "drop");
11235 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11236         TOKEN_NUM_INITIALIZER
11237                 (struct cmd_all_queues_drop_en_result,
11238                  port_id, RTE_UINT16);
11239 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11240         TOKEN_STRING_INITIALIZER
11241                 (struct cmd_all_queues_drop_en_result,
11242                  on_off, "on#off");
11243
11244 static void
11245 cmd_set_all_queues_drop_en_parsed(
11246         void *parsed_result,
11247         __rte_unused struct cmdline *cl,
11248         __rte_unused void *data)
11249 {
11250         struct cmd_all_queues_drop_en_result *res = parsed_result;
11251         int ret = -ENOTSUP;
11252         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11253
11254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11255                 return;
11256
11257 #ifdef RTE_NET_IXGBE
11258         if (ret == -ENOTSUP)
11259                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11260 #endif
11261 #ifdef RTE_NET_BNXT
11262         if (ret == -ENOTSUP)
11263                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11264 #endif
11265         switch (ret) {
11266         case 0:
11267                 break;
11268         case -EINVAL:
11269                 printf("invalid is_on %d\n", is_on);
11270                 break;
11271         case -ENODEV:
11272                 printf("invalid port_id %d\n", res->port_id);
11273                 break;
11274         case -ENOTSUP:
11275                 printf("function not implemented\n");
11276                 break;
11277         default:
11278                 printf("programming error: (%s)\n", strerror(-ret));
11279         }
11280 }
11281
11282 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11283         .f = cmd_set_all_queues_drop_en_parsed,
11284         .data = NULL,
11285         .help_str = "set all queues drop <port_id> on|off",
11286         .tokens = {
11287                 (void *)&cmd_all_queues_drop_en_set,
11288                 (void *)&cmd_all_queues_drop_en_all,
11289                 (void *)&cmd_all_queues_drop_en_queues,
11290                 (void *)&cmd_all_queues_drop_en_drop,
11291                 (void *)&cmd_all_queues_drop_en_port_id,
11292                 (void *)&cmd_all_queues_drop_en_on_off,
11293                 NULL,
11294         },
11295 };
11296
11297 /* vf split drop enable configuration */
11298
11299 /* Common result structure for vf split drop enable */
11300 struct cmd_vf_split_drop_en_result {
11301         cmdline_fixed_string_t set;
11302         cmdline_fixed_string_t vf;
11303         cmdline_fixed_string_t split;
11304         cmdline_fixed_string_t drop;
11305         portid_t port_id;
11306         uint16_t vf_id;
11307         cmdline_fixed_string_t on_off;
11308 };
11309
11310 /* Common CLI fields for vf split drop enable disable */
11311 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11312         TOKEN_STRING_INITIALIZER
11313                 (struct cmd_vf_split_drop_en_result,
11314                  set, "set");
11315 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11316         TOKEN_STRING_INITIALIZER
11317                 (struct cmd_vf_split_drop_en_result,
11318                  vf, "vf");
11319 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11320         TOKEN_STRING_INITIALIZER
11321                 (struct cmd_vf_split_drop_en_result,
11322                  split, "split");
11323 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11324         TOKEN_STRING_INITIALIZER
11325                 (struct cmd_vf_split_drop_en_result,
11326                  drop, "drop");
11327 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11328         TOKEN_NUM_INITIALIZER
11329                 (struct cmd_vf_split_drop_en_result,
11330                  port_id, RTE_UINT16);
11331 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11332         TOKEN_NUM_INITIALIZER
11333                 (struct cmd_vf_split_drop_en_result,
11334                  vf_id, RTE_UINT16);
11335 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11336         TOKEN_STRING_INITIALIZER
11337                 (struct cmd_vf_split_drop_en_result,
11338                  on_off, "on#off");
11339
11340 static void
11341 cmd_set_vf_split_drop_en_parsed(
11342         void *parsed_result,
11343         __rte_unused struct cmdline *cl,
11344         __rte_unused void *data)
11345 {
11346         struct cmd_vf_split_drop_en_result *res = parsed_result;
11347         int ret = -ENOTSUP;
11348         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11349
11350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11351                 return;
11352
11353 #ifdef RTE_NET_IXGBE
11354         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11355                         is_on);
11356 #endif
11357         switch (ret) {
11358         case 0:
11359                 break;
11360         case -EINVAL:
11361                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11362                 break;
11363         case -ENODEV:
11364                 printf("invalid port_id %d\n", res->port_id);
11365                 break;
11366         case -ENOTSUP:
11367                 printf("not supported on port %d\n", res->port_id);
11368                 break;
11369         default:
11370                 printf("programming error: (%s)\n", strerror(-ret));
11371         }
11372 }
11373
11374 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11375         .f = cmd_set_vf_split_drop_en_parsed,
11376         .data = NULL,
11377         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11378         .tokens = {
11379                 (void *)&cmd_vf_split_drop_en_set,
11380                 (void *)&cmd_vf_split_drop_en_vf,
11381                 (void *)&cmd_vf_split_drop_en_split,
11382                 (void *)&cmd_vf_split_drop_en_drop,
11383                 (void *)&cmd_vf_split_drop_en_port_id,
11384                 (void *)&cmd_vf_split_drop_en_vf_id,
11385                 (void *)&cmd_vf_split_drop_en_on_off,
11386                 NULL,
11387         },
11388 };
11389
11390 /* vf mac address configuration */
11391
11392 /* Common result structure for vf mac address */
11393 struct cmd_set_vf_mac_addr_result {
11394         cmdline_fixed_string_t set;
11395         cmdline_fixed_string_t vf;
11396         cmdline_fixed_string_t mac;
11397         cmdline_fixed_string_t addr;
11398         portid_t port_id;
11399         uint16_t vf_id;
11400         struct rte_ether_addr mac_addr;
11401
11402 };
11403
11404 /* Common CLI fields for vf split drop enable disable */
11405 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11406         TOKEN_STRING_INITIALIZER
11407                 (struct cmd_set_vf_mac_addr_result,
11408                  set, "set");
11409 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11410         TOKEN_STRING_INITIALIZER
11411                 (struct cmd_set_vf_mac_addr_result,
11412                  vf, "vf");
11413 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11414         TOKEN_STRING_INITIALIZER
11415                 (struct cmd_set_vf_mac_addr_result,
11416                  mac, "mac");
11417 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11418         TOKEN_STRING_INITIALIZER
11419                 (struct cmd_set_vf_mac_addr_result,
11420                  addr, "addr");
11421 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11422         TOKEN_NUM_INITIALIZER
11423                 (struct cmd_set_vf_mac_addr_result,
11424                  port_id, RTE_UINT16);
11425 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11426         TOKEN_NUM_INITIALIZER
11427                 (struct cmd_set_vf_mac_addr_result,
11428                  vf_id, RTE_UINT16);
11429 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11430         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11431                  mac_addr);
11432
11433 static void
11434 cmd_set_vf_mac_addr_parsed(
11435         void *parsed_result,
11436         __rte_unused struct cmdline *cl,
11437         __rte_unused void *data)
11438 {
11439         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11440         int ret = -ENOTSUP;
11441
11442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11443                 return;
11444
11445 #ifdef RTE_NET_IXGBE
11446         if (ret == -ENOTSUP)
11447                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11448                                 &res->mac_addr);
11449 #endif
11450 #ifdef RTE_NET_I40E
11451         if (ret == -ENOTSUP)
11452                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11453                                 &res->mac_addr);
11454 #endif
11455 #ifdef RTE_NET_BNXT
11456         if (ret == -ENOTSUP)
11457                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11458                                 &res->mac_addr);
11459 #endif
11460
11461         switch (ret) {
11462         case 0:
11463                 break;
11464         case -EINVAL:
11465                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11466                 break;
11467         case -ENODEV:
11468                 printf("invalid port_id %d\n", res->port_id);
11469                 break;
11470         case -ENOTSUP:
11471                 printf("function not implemented\n");
11472                 break;
11473         default:
11474                 printf("programming error: (%s)\n", strerror(-ret));
11475         }
11476 }
11477
11478 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11479         .f = cmd_set_vf_mac_addr_parsed,
11480         .data = NULL,
11481         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11482         .tokens = {
11483                 (void *)&cmd_set_vf_mac_addr_set,
11484                 (void *)&cmd_set_vf_mac_addr_vf,
11485                 (void *)&cmd_set_vf_mac_addr_mac,
11486                 (void *)&cmd_set_vf_mac_addr_addr,
11487                 (void *)&cmd_set_vf_mac_addr_port_id,
11488                 (void *)&cmd_set_vf_mac_addr_vf_id,
11489                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11490                 NULL,
11491         },
11492 };
11493
11494 /* MACsec configuration */
11495
11496 /* Common result structure for MACsec offload enable */
11497 struct cmd_macsec_offload_on_result {
11498         cmdline_fixed_string_t set;
11499         cmdline_fixed_string_t macsec;
11500         cmdline_fixed_string_t offload;
11501         portid_t port_id;
11502         cmdline_fixed_string_t on;
11503         cmdline_fixed_string_t encrypt;
11504         cmdline_fixed_string_t en_on_off;
11505         cmdline_fixed_string_t replay_protect;
11506         cmdline_fixed_string_t rp_on_off;
11507 };
11508
11509 /* Common CLI fields for MACsec offload disable */
11510 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11511         TOKEN_STRING_INITIALIZER
11512                 (struct cmd_macsec_offload_on_result,
11513                  set, "set");
11514 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11515         TOKEN_STRING_INITIALIZER
11516                 (struct cmd_macsec_offload_on_result,
11517                  macsec, "macsec");
11518 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11519         TOKEN_STRING_INITIALIZER
11520                 (struct cmd_macsec_offload_on_result,
11521                  offload, "offload");
11522 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11523         TOKEN_NUM_INITIALIZER
11524                 (struct cmd_macsec_offload_on_result,
11525                  port_id, RTE_UINT16);
11526 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11527         TOKEN_STRING_INITIALIZER
11528                 (struct cmd_macsec_offload_on_result,
11529                  on, "on");
11530 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11531         TOKEN_STRING_INITIALIZER
11532                 (struct cmd_macsec_offload_on_result,
11533                  encrypt, "encrypt");
11534 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_macsec_offload_on_result,
11537                  en_on_off, "on#off");
11538 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11539         TOKEN_STRING_INITIALIZER
11540                 (struct cmd_macsec_offload_on_result,
11541                  replay_protect, "replay-protect");
11542 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11543         TOKEN_STRING_INITIALIZER
11544                 (struct cmd_macsec_offload_on_result,
11545                  rp_on_off, "on#off");
11546
11547 static void
11548 cmd_set_macsec_offload_on_parsed(
11549         void *parsed_result,
11550         __rte_unused struct cmdline *cl,
11551         __rte_unused void *data)
11552 {
11553         struct cmd_macsec_offload_on_result *res = parsed_result;
11554         int ret = -ENOTSUP;
11555         portid_t port_id = res->port_id;
11556         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11557         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11558         struct rte_eth_dev_info dev_info;
11559
11560         if (port_id_is_invalid(port_id, ENABLED_WARN))
11561                 return;
11562         if (!port_is_stopped(port_id)) {
11563                 printf("Please stop port %d first\n", port_id);
11564                 return;
11565         }
11566
11567         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11568         if (ret != 0)
11569                 return;
11570
11571         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11572 #ifdef RTE_NET_IXGBE
11573                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11574 #endif
11575         }
11576         RTE_SET_USED(en);
11577         RTE_SET_USED(rp);
11578
11579         switch (ret) {
11580         case 0:
11581                 ports[port_id].dev_conf.txmode.offloads |=
11582                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11583                 cmd_reconfig_device_queue(port_id, 1, 1);
11584                 break;
11585         case -ENODEV:
11586                 printf("invalid port_id %d\n", port_id);
11587                 break;
11588         case -ENOTSUP:
11589                 printf("not supported on port %d\n", port_id);
11590                 break;
11591         default:
11592                 printf("programming error: (%s)\n", strerror(-ret));
11593         }
11594 }
11595
11596 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11597         .f = cmd_set_macsec_offload_on_parsed,
11598         .data = NULL,
11599         .help_str = "set macsec offload <port_id> on "
11600                 "encrypt on|off replay-protect on|off",
11601         .tokens = {
11602                 (void *)&cmd_macsec_offload_on_set,
11603                 (void *)&cmd_macsec_offload_on_macsec,
11604                 (void *)&cmd_macsec_offload_on_offload,
11605                 (void *)&cmd_macsec_offload_on_port_id,
11606                 (void *)&cmd_macsec_offload_on_on,
11607                 (void *)&cmd_macsec_offload_on_encrypt,
11608                 (void *)&cmd_macsec_offload_on_en_on_off,
11609                 (void *)&cmd_macsec_offload_on_replay_protect,
11610                 (void *)&cmd_macsec_offload_on_rp_on_off,
11611                 NULL,
11612         },
11613 };
11614
11615 /* Common result structure for MACsec offload disable */
11616 struct cmd_macsec_offload_off_result {
11617         cmdline_fixed_string_t set;
11618         cmdline_fixed_string_t macsec;
11619         cmdline_fixed_string_t offload;
11620         portid_t port_id;
11621         cmdline_fixed_string_t off;
11622 };
11623
11624 /* Common CLI fields for MACsec offload disable */
11625 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11626         TOKEN_STRING_INITIALIZER
11627                 (struct cmd_macsec_offload_off_result,
11628                  set, "set");
11629 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11630         TOKEN_STRING_INITIALIZER
11631                 (struct cmd_macsec_offload_off_result,
11632                  macsec, "macsec");
11633 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11634         TOKEN_STRING_INITIALIZER
11635                 (struct cmd_macsec_offload_off_result,
11636                  offload, "offload");
11637 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11638         TOKEN_NUM_INITIALIZER
11639                 (struct cmd_macsec_offload_off_result,
11640                  port_id, RTE_UINT16);
11641 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11642         TOKEN_STRING_INITIALIZER
11643                 (struct cmd_macsec_offload_off_result,
11644                  off, "off");
11645
11646 static void
11647 cmd_set_macsec_offload_off_parsed(
11648         void *parsed_result,
11649         __rte_unused struct cmdline *cl,
11650         __rte_unused void *data)
11651 {
11652         struct cmd_macsec_offload_off_result *res = parsed_result;
11653         int ret = -ENOTSUP;
11654         struct rte_eth_dev_info dev_info;
11655         portid_t port_id = res->port_id;
11656
11657         if (port_id_is_invalid(port_id, ENABLED_WARN))
11658                 return;
11659         if (!port_is_stopped(port_id)) {
11660                 printf("Please stop port %d first\n", port_id);
11661                 return;
11662         }
11663
11664         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11665         if (ret != 0)
11666                 return;
11667
11668         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11669 #ifdef RTE_NET_IXGBE
11670                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11671 #endif
11672         }
11673         switch (ret) {
11674         case 0:
11675                 ports[port_id].dev_conf.txmode.offloads &=
11676                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11677                 cmd_reconfig_device_queue(port_id, 1, 1);
11678                 break;
11679         case -ENODEV:
11680                 printf("invalid port_id %d\n", port_id);
11681                 break;
11682         case -ENOTSUP:
11683                 printf("not supported on port %d\n", port_id);
11684                 break;
11685         default:
11686                 printf("programming error: (%s)\n", strerror(-ret));
11687         }
11688 }
11689
11690 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11691         .f = cmd_set_macsec_offload_off_parsed,
11692         .data = NULL,
11693         .help_str = "set macsec offload <port_id> off",
11694         .tokens = {
11695                 (void *)&cmd_macsec_offload_off_set,
11696                 (void *)&cmd_macsec_offload_off_macsec,
11697                 (void *)&cmd_macsec_offload_off_offload,
11698                 (void *)&cmd_macsec_offload_off_port_id,
11699                 (void *)&cmd_macsec_offload_off_off,
11700                 NULL,
11701         },
11702 };
11703
11704 /* Common result structure for MACsec secure connection configure */
11705 struct cmd_macsec_sc_result {
11706         cmdline_fixed_string_t set;
11707         cmdline_fixed_string_t macsec;
11708         cmdline_fixed_string_t sc;
11709         cmdline_fixed_string_t tx_rx;
11710         portid_t port_id;
11711         struct rte_ether_addr mac;
11712         uint16_t pi;
11713 };
11714
11715 /* Common CLI fields for MACsec secure connection configure */
11716 cmdline_parse_token_string_t cmd_macsec_sc_set =
11717         TOKEN_STRING_INITIALIZER
11718                 (struct cmd_macsec_sc_result,
11719                  set, "set");
11720 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11721         TOKEN_STRING_INITIALIZER
11722                 (struct cmd_macsec_sc_result,
11723                  macsec, "macsec");
11724 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11725         TOKEN_STRING_INITIALIZER
11726                 (struct cmd_macsec_sc_result,
11727                  sc, "sc");
11728 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11729         TOKEN_STRING_INITIALIZER
11730                 (struct cmd_macsec_sc_result,
11731                  tx_rx, "tx#rx");
11732 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11733         TOKEN_NUM_INITIALIZER
11734                 (struct cmd_macsec_sc_result,
11735                  port_id, RTE_UINT16);
11736 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11737         TOKEN_ETHERADDR_INITIALIZER
11738                 (struct cmd_macsec_sc_result,
11739                  mac);
11740 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11741         TOKEN_NUM_INITIALIZER
11742                 (struct cmd_macsec_sc_result,
11743                  pi, RTE_UINT16);
11744
11745 static void
11746 cmd_set_macsec_sc_parsed(
11747         void *parsed_result,
11748         __rte_unused struct cmdline *cl,
11749         __rte_unused void *data)
11750 {
11751         struct cmd_macsec_sc_result *res = parsed_result;
11752         int ret = -ENOTSUP;
11753         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11754
11755 #ifdef RTE_NET_IXGBE
11756         ret = is_tx ?
11757                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11758                                 res->mac.addr_bytes) :
11759                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11760                                 res->mac.addr_bytes, res->pi);
11761 #endif
11762         RTE_SET_USED(is_tx);
11763
11764         switch (ret) {
11765         case 0:
11766                 break;
11767         case -ENODEV:
11768                 printf("invalid port_id %d\n", res->port_id);
11769                 break;
11770         case -ENOTSUP:
11771                 printf("not supported on port %d\n", res->port_id);
11772                 break;
11773         default:
11774                 printf("programming error: (%s)\n", strerror(-ret));
11775         }
11776 }
11777
11778 cmdline_parse_inst_t cmd_set_macsec_sc = {
11779         .f = cmd_set_macsec_sc_parsed,
11780         .data = NULL,
11781         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11782         .tokens = {
11783                 (void *)&cmd_macsec_sc_set,
11784                 (void *)&cmd_macsec_sc_macsec,
11785                 (void *)&cmd_macsec_sc_sc,
11786                 (void *)&cmd_macsec_sc_tx_rx,
11787                 (void *)&cmd_macsec_sc_port_id,
11788                 (void *)&cmd_macsec_sc_mac,
11789                 (void *)&cmd_macsec_sc_pi,
11790                 NULL,
11791         },
11792 };
11793
11794 /* Common result structure for MACsec secure connection configure */
11795 struct cmd_macsec_sa_result {
11796         cmdline_fixed_string_t set;
11797         cmdline_fixed_string_t macsec;
11798         cmdline_fixed_string_t sa;
11799         cmdline_fixed_string_t tx_rx;
11800         portid_t port_id;
11801         uint8_t idx;
11802         uint8_t an;
11803         uint32_t pn;
11804         cmdline_fixed_string_t key;
11805 };
11806
11807 /* Common CLI fields for MACsec secure connection configure */
11808 cmdline_parse_token_string_t cmd_macsec_sa_set =
11809         TOKEN_STRING_INITIALIZER
11810                 (struct cmd_macsec_sa_result,
11811                  set, "set");
11812 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11813         TOKEN_STRING_INITIALIZER
11814                 (struct cmd_macsec_sa_result,
11815                  macsec, "macsec");
11816 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11817         TOKEN_STRING_INITIALIZER
11818                 (struct cmd_macsec_sa_result,
11819                  sa, "sa");
11820 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11821         TOKEN_STRING_INITIALIZER
11822                 (struct cmd_macsec_sa_result,
11823                  tx_rx, "tx#rx");
11824 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11825         TOKEN_NUM_INITIALIZER
11826                 (struct cmd_macsec_sa_result,
11827                  port_id, RTE_UINT16);
11828 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11829         TOKEN_NUM_INITIALIZER
11830                 (struct cmd_macsec_sa_result,
11831                  idx, RTE_UINT8);
11832 cmdline_parse_token_num_t cmd_macsec_sa_an =
11833         TOKEN_NUM_INITIALIZER
11834                 (struct cmd_macsec_sa_result,
11835                  an, RTE_UINT8);
11836 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11837         TOKEN_NUM_INITIALIZER
11838                 (struct cmd_macsec_sa_result,
11839                  pn, RTE_UINT32);
11840 cmdline_parse_token_string_t cmd_macsec_sa_key =
11841         TOKEN_STRING_INITIALIZER
11842                 (struct cmd_macsec_sa_result,
11843                  key, NULL);
11844
11845 static void
11846 cmd_set_macsec_sa_parsed(
11847         void *parsed_result,
11848         __rte_unused struct cmdline *cl,
11849         __rte_unused void *data)
11850 {
11851         struct cmd_macsec_sa_result *res = parsed_result;
11852         int ret = -ENOTSUP;
11853         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11854         uint8_t key[16] = { 0 };
11855         uint8_t xdgt0;
11856         uint8_t xdgt1;
11857         int key_len;
11858         int i;
11859
11860         key_len = strlen(res->key) / 2;
11861         if (key_len > 16)
11862                 key_len = 16;
11863
11864         for (i = 0; i < key_len; i++) {
11865                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11866                 if (xdgt0 == 0xFF)
11867                         return;
11868                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11869                 if (xdgt1 == 0xFF)
11870                         return;
11871                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11872         }
11873
11874 #ifdef RTE_NET_IXGBE
11875         ret = is_tx ?
11876                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11877                         res->idx, res->an, res->pn, key) :
11878                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11879                         res->idx, res->an, res->pn, key);
11880 #endif
11881         RTE_SET_USED(is_tx);
11882         RTE_SET_USED(key);
11883
11884         switch (ret) {
11885         case 0:
11886                 break;
11887         case -EINVAL:
11888                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11889                 break;
11890         case -ENODEV:
11891                 printf("invalid port_id %d\n", res->port_id);
11892                 break;
11893         case -ENOTSUP:
11894                 printf("not supported on port %d\n", res->port_id);
11895                 break;
11896         default:
11897                 printf("programming error: (%s)\n", strerror(-ret));
11898         }
11899 }
11900
11901 cmdline_parse_inst_t cmd_set_macsec_sa = {
11902         .f = cmd_set_macsec_sa_parsed,
11903         .data = NULL,
11904         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11905         .tokens = {
11906                 (void *)&cmd_macsec_sa_set,
11907                 (void *)&cmd_macsec_sa_macsec,
11908                 (void *)&cmd_macsec_sa_sa,
11909                 (void *)&cmd_macsec_sa_tx_rx,
11910                 (void *)&cmd_macsec_sa_port_id,
11911                 (void *)&cmd_macsec_sa_idx,
11912                 (void *)&cmd_macsec_sa_an,
11913                 (void *)&cmd_macsec_sa_pn,
11914                 (void *)&cmd_macsec_sa_key,
11915                 NULL,
11916         },
11917 };
11918
11919 /* VF unicast promiscuous mode configuration */
11920
11921 /* Common result structure for VF unicast promiscuous mode */
11922 struct cmd_vf_promisc_result {
11923         cmdline_fixed_string_t set;
11924         cmdline_fixed_string_t vf;
11925         cmdline_fixed_string_t promisc;
11926         portid_t port_id;
11927         uint32_t vf_id;
11928         cmdline_fixed_string_t on_off;
11929 };
11930
11931 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11932 cmdline_parse_token_string_t cmd_vf_promisc_set =
11933         TOKEN_STRING_INITIALIZER
11934                 (struct cmd_vf_promisc_result,
11935                  set, "set");
11936 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11937         TOKEN_STRING_INITIALIZER
11938                 (struct cmd_vf_promisc_result,
11939                  vf, "vf");
11940 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11941         TOKEN_STRING_INITIALIZER
11942                 (struct cmd_vf_promisc_result,
11943                  promisc, "promisc");
11944 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11945         TOKEN_NUM_INITIALIZER
11946                 (struct cmd_vf_promisc_result,
11947                  port_id, RTE_UINT16);
11948 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11949         TOKEN_NUM_INITIALIZER
11950                 (struct cmd_vf_promisc_result,
11951                  vf_id, RTE_UINT32);
11952 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11953         TOKEN_STRING_INITIALIZER
11954                 (struct cmd_vf_promisc_result,
11955                  on_off, "on#off");
11956
11957 static void
11958 cmd_set_vf_promisc_parsed(
11959         void *parsed_result,
11960         __rte_unused struct cmdline *cl,
11961         __rte_unused void *data)
11962 {
11963         struct cmd_vf_promisc_result *res = parsed_result;
11964         int ret = -ENOTSUP;
11965
11966         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11967
11968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11969                 return;
11970
11971 #ifdef RTE_NET_I40E
11972         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11973                                                   res->vf_id, is_on);
11974 #endif
11975
11976         switch (ret) {
11977         case 0:
11978                 break;
11979         case -EINVAL:
11980                 printf("invalid vf_id %d\n", res->vf_id);
11981                 break;
11982         case -ENODEV:
11983                 printf("invalid port_id %d\n", res->port_id);
11984                 break;
11985         case -ENOTSUP:
11986                 printf("function not implemented\n");
11987                 break;
11988         default:
11989                 printf("programming error: (%s)\n", strerror(-ret));
11990         }
11991 }
11992
11993 cmdline_parse_inst_t cmd_set_vf_promisc = {
11994         .f = cmd_set_vf_promisc_parsed,
11995         .data = NULL,
11996         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11997                 "Set unicast promiscuous mode for a VF from the PF",
11998         .tokens = {
11999                 (void *)&cmd_vf_promisc_set,
12000                 (void *)&cmd_vf_promisc_vf,
12001                 (void *)&cmd_vf_promisc_promisc,
12002                 (void *)&cmd_vf_promisc_port_id,
12003                 (void *)&cmd_vf_promisc_vf_id,
12004                 (void *)&cmd_vf_promisc_on_off,
12005                 NULL,
12006         },
12007 };
12008
12009 /* VF multicast promiscuous mode configuration */
12010
12011 /* Common result structure for VF multicast promiscuous mode */
12012 struct cmd_vf_allmulti_result {
12013         cmdline_fixed_string_t set;
12014         cmdline_fixed_string_t vf;
12015         cmdline_fixed_string_t allmulti;
12016         portid_t port_id;
12017         uint32_t vf_id;
12018         cmdline_fixed_string_t on_off;
12019 };
12020
12021 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12022 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12023         TOKEN_STRING_INITIALIZER
12024                 (struct cmd_vf_allmulti_result,
12025                  set, "set");
12026 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12027         TOKEN_STRING_INITIALIZER
12028                 (struct cmd_vf_allmulti_result,
12029                  vf, "vf");
12030 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12031         TOKEN_STRING_INITIALIZER
12032                 (struct cmd_vf_allmulti_result,
12033                  allmulti, "allmulti");
12034 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12035         TOKEN_NUM_INITIALIZER
12036                 (struct cmd_vf_allmulti_result,
12037                  port_id, RTE_UINT16);
12038 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12039         TOKEN_NUM_INITIALIZER
12040                 (struct cmd_vf_allmulti_result,
12041                  vf_id, RTE_UINT32);
12042 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12043         TOKEN_STRING_INITIALIZER
12044                 (struct cmd_vf_allmulti_result,
12045                  on_off, "on#off");
12046
12047 static void
12048 cmd_set_vf_allmulti_parsed(
12049         void *parsed_result,
12050         __rte_unused struct cmdline *cl,
12051         __rte_unused void *data)
12052 {
12053         struct cmd_vf_allmulti_result *res = parsed_result;
12054         int ret = -ENOTSUP;
12055
12056         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12057
12058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12059                 return;
12060
12061 #ifdef RTE_NET_I40E
12062         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12063                                                     res->vf_id, is_on);
12064 #endif
12065
12066         switch (ret) {
12067         case 0:
12068                 break;
12069         case -EINVAL:
12070                 printf("invalid vf_id %d\n", res->vf_id);
12071                 break;
12072         case -ENODEV:
12073                 printf("invalid port_id %d\n", res->port_id);
12074                 break;
12075         case -ENOTSUP:
12076                 printf("function not implemented\n");
12077                 break;
12078         default:
12079                 printf("programming error: (%s)\n", strerror(-ret));
12080         }
12081 }
12082
12083 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12084         .f = cmd_set_vf_allmulti_parsed,
12085         .data = NULL,
12086         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12087                 "Set multicast promiscuous mode for a VF from the PF",
12088         .tokens = {
12089                 (void *)&cmd_vf_allmulti_set,
12090                 (void *)&cmd_vf_allmulti_vf,
12091                 (void *)&cmd_vf_allmulti_allmulti,
12092                 (void *)&cmd_vf_allmulti_port_id,
12093                 (void *)&cmd_vf_allmulti_vf_id,
12094                 (void *)&cmd_vf_allmulti_on_off,
12095                 NULL,
12096         },
12097 };
12098
12099 /* vf broadcast mode configuration */
12100
12101 /* Common result structure for vf broadcast */
12102 struct cmd_set_vf_broadcast_result {
12103         cmdline_fixed_string_t set;
12104         cmdline_fixed_string_t vf;
12105         cmdline_fixed_string_t broadcast;
12106         portid_t port_id;
12107         uint16_t vf_id;
12108         cmdline_fixed_string_t on_off;
12109 };
12110
12111 /* Common CLI fields for vf broadcast enable disable */
12112 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12113         TOKEN_STRING_INITIALIZER
12114                 (struct cmd_set_vf_broadcast_result,
12115                  set, "set");
12116 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12117         TOKEN_STRING_INITIALIZER
12118                 (struct cmd_set_vf_broadcast_result,
12119                  vf, "vf");
12120 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12121         TOKEN_STRING_INITIALIZER
12122                 (struct cmd_set_vf_broadcast_result,
12123                  broadcast, "broadcast");
12124 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12125         TOKEN_NUM_INITIALIZER
12126                 (struct cmd_set_vf_broadcast_result,
12127                  port_id, RTE_UINT16);
12128 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12129         TOKEN_NUM_INITIALIZER
12130                 (struct cmd_set_vf_broadcast_result,
12131                  vf_id, RTE_UINT16);
12132 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12133         TOKEN_STRING_INITIALIZER
12134                 (struct cmd_set_vf_broadcast_result,
12135                  on_off, "on#off");
12136
12137 static void
12138 cmd_set_vf_broadcast_parsed(
12139         void *parsed_result,
12140         __rte_unused struct cmdline *cl,
12141         __rte_unused void *data)
12142 {
12143         struct cmd_set_vf_broadcast_result *res = parsed_result;
12144         int ret = -ENOTSUP;
12145
12146         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12147
12148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12149                 return;
12150
12151 #ifdef RTE_NET_I40E
12152         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12153                                             res->vf_id, is_on);
12154 #endif
12155
12156         switch (ret) {
12157         case 0:
12158                 break;
12159         case -EINVAL:
12160                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12161                 break;
12162         case -ENODEV:
12163                 printf("invalid port_id %d\n", res->port_id);
12164                 break;
12165         case -ENOTSUP:
12166                 printf("function not implemented\n");
12167                 break;
12168         default:
12169                 printf("programming error: (%s)\n", strerror(-ret));
12170         }
12171 }
12172
12173 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12174         .f = cmd_set_vf_broadcast_parsed,
12175         .data = NULL,
12176         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12177         .tokens = {
12178                 (void *)&cmd_set_vf_broadcast_set,
12179                 (void *)&cmd_set_vf_broadcast_vf,
12180                 (void *)&cmd_set_vf_broadcast_broadcast,
12181                 (void *)&cmd_set_vf_broadcast_port_id,
12182                 (void *)&cmd_set_vf_broadcast_vf_id,
12183                 (void *)&cmd_set_vf_broadcast_on_off,
12184                 NULL,
12185         },
12186 };
12187
12188 /* vf vlan tag configuration */
12189
12190 /* Common result structure for vf vlan tag */
12191 struct cmd_set_vf_vlan_tag_result {
12192         cmdline_fixed_string_t set;
12193         cmdline_fixed_string_t vf;
12194         cmdline_fixed_string_t vlan;
12195         cmdline_fixed_string_t tag;
12196         portid_t port_id;
12197         uint16_t vf_id;
12198         cmdline_fixed_string_t on_off;
12199 };
12200
12201 /* Common CLI fields for vf vlan tag enable disable */
12202 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_set_vf_vlan_tag_result,
12205                  set, "set");
12206 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12207         TOKEN_STRING_INITIALIZER
12208                 (struct cmd_set_vf_vlan_tag_result,
12209                  vf, "vf");
12210 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12211         TOKEN_STRING_INITIALIZER
12212                 (struct cmd_set_vf_vlan_tag_result,
12213                  vlan, "vlan");
12214 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12215         TOKEN_STRING_INITIALIZER
12216                 (struct cmd_set_vf_vlan_tag_result,
12217                  tag, "tag");
12218 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12219         TOKEN_NUM_INITIALIZER
12220                 (struct cmd_set_vf_vlan_tag_result,
12221                  port_id, RTE_UINT16);
12222 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12223         TOKEN_NUM_INITIALIZER
12224                 (struct cmd_set_vf_vlan_tag_result,
12225                  vf_id, RTE_UINT16);
12226 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12227         TOKEN_STRING_INITIALIZER
12228                 (struct cmd_set_vf_vlan_tag_result,
12229                  on_off, "on#off");
12230
12231 static void
12232 cmd_set_vf_vlan_tag_parsed(
12233         void *parsed_result,
12234         __rte_unused struct cmdline *cl,
12235         __rte_unused void *data)
12236 {
12237         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12238         int ret = -ENOTSUP;
12239
12240         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12241
12242         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12243                 return;
12244
12245 #ifdef RTE_NET_I40E
12246         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12247                                            res->vf_id, is_on);
12248 #endif
12249
12250         switch (ret) {
12251         case 0:
12252                 break;
12253         case -EINVAL:
12254                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12255                 break;
12256         case -ENODEV:
12257                 printf("invalid port_id %d\n", res->port_id);
12258                 break;
12259         case -ENOTSUP:
12260                 printf("function not implemented\n");
12261                 break;
12262         default:
12263                 printf("programming error: (%s)\n", strerror(-ret));
12264         }
12265 }
12266
12267 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12268         .f = cmd_set_vf_vlan_tag_parsed,
12269         .data = NULL,
12270         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12271         .tokens = {
12272                 (void *)&cmd_set_vf_vlan_tag_set,
12273                 (void *)&cmd_set_vf_vlan_tag_vf,
12274                 (void *)&cmd_set_vf_vlan_tag_vlan,
12275                 (void *)&cmd_set_vf_vlan_tag_tag,
12276                 (void *)&cmd_set_vf_vlan_tag_port_id,
12277                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12278                 (void *)&cmd_set_vf_vlan_tag_on_off,
12279                 NULL,
12280         },
12281 };
12282
12283 /* Common definition of VF and TC TX bandwidth configuration */
12284 struct cmd_vf_tc_bw_result {
12285         cmdline_fixed_string_t set;
12286         cmdline_fixed_string_t vf;
12287         cmdline_fixed_string_t tc;
12288         cmdline_fixed_string_t tx;
12289         cmdline_fixed_string_t min_bw;
12290         cmdline_fixed_string_t max_bw;
12291         cmdline_fixed_string_t strict_link_prio;
12292         portid_t port_id;
12293         uint16_t vf_id;
12294         uint8_t tc_no;
12295         uint32_t bw;
12296         cmdline_fixed_string_t bw_list;
12297         uint8_t tc_map;
12298 };
12299
12300 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12301         TOKEN_STRING_INITIALIZER
12302                 (struct cmd_vf_tc_bw_result,
12303                  set, "set");
12304 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12305         TOKEN_STRING_INITIALIZER
12306                 (struct cmd_vf_tc_bw_result,
12307                  vf, "vf");
12308 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12309         TOKEN_STRING_INITIALIZER
12310                 (struct cmd_vf_tc_bw_result,
12311                  tc, "tc");
12312 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12313         TOKEN_STRING_INITIALIZER
12314                 (struct cmd_vf_tc_bw_result,
12315                  tx, "tx");
12316 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12317         TOKEN_STRING_INITIALIZER
12318                 (struct cmd_vf_tc_bw_result,
12319                  strict_link_prio, "strict-link-priority");
12320 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12321         TOKEN_STRING_INITIALIZER
12322                 (struct cmd_vf_tc_bw_result,
12323                  min_bw, "min-bandwidth");
12324 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12325         TOKEN_STRING_INITIALIZER
12326                 (struct cmd_vf_tc_bw_result,
12327                  max_bw, "max-bandwidth");
12328 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12329         TOKEN_NUM_INITIALIZER
12330                 (struct cmd_vf_tc_bw_result,
12331                  port_id, RTE_UINT16);
12332 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12333         TOKEN_NUM_INITIALIZER
12334                 (struct cmd_vf_tc_bw_result,
12335                  vf_id, RTE_UINT16);
12336 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12337         TOKEN_NUM_INITIALIZER
12338                 (struct cmd_vf_tc_bw_result,
12339                  tc_no, RTE_UINT8);
12340 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12341         TOKEN_NUM_INITIALIZER
12342                 (struct cmd_vf_tc_bw_result,
12343                  bw, RTE_UINT32);
12344 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12345         TOKEN_STRING_INITIALIZER
12346                 (struct cmd_vf_tc_bw_result,
12347                  bw_list, NULL);
12348 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12349         TOKEN_NUM_INITIALIZER
12350                 (struct cmd_vf_tc_bw_result,
12351                  tc_map, RTE_UINT8);
12352
12353 /* VF max bandwidth setting */
12354 static void
12355 cmd_vf_max_bw_parsed(
12356         void *parsed_result,
12357         __rte_unused struct cmdline *cl,
12358         __rte_unused void *data)
12359 {
12360         struct cmd_vf_tc_bw_result *res = parsed_result;
12361         int ret = -ENOTSUP;
12362
12363         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12364                 return;
12365
12366 #ifdef RTE_NET_I40E
12367         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12368                                          res->vf_id, res->bw);
12369 #endif
12370
12371         switch (ret) {
12372         case 0:
12373                 break;
12374         case -EINVAL:
12375                 printf("invalid vf_id %d or bandwidth %d\n",
12376                        res->vf_id, res->bw);
12377                 break;
12378         case -ENODEV:
12379                 printf("invalid port_id %d\n", res->port_id);
12380                 break;
12381         case -ENOTSUP:
12382                 printf("function not implemented\n");
12383                 break;
12384         default:
12385                 printf("programming error: (%s)\n", strerror(-ret));
12386         }
12387 }
12388
12389 cmdline_parse_inst_t cmd_vf_max_bw = {
12390         .f = cmd_vf_max_bw_parsed,
12391         .data = NULL,
12392         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12393         .tokens = {
12394                 (void *)&cmd_vf_tc_bw_set,
12395                 (void *)&cmd_vf_tc_bw_vf,
12396                 (void *)&cmd_vf_tc_bw_tx,
12397                 (void *)&cmd_vf_tc_bw_max_bw,
12398                 (void *)&cmd_vf_tc_bw_port_id,
12399                 (void *)&cmd_vf_tc_bw_vf_id,
12400                 (void *)&cmd_vf_tc_bw_bw,
12401                 NULL,
12402         },
12403 };
12404
12405 static int
12406 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12407                            uint8_t *tc_num,
12408                            char *str)
12409 {
12410         uint32_t size;
12411         const char *p, *p0 = str;
12412         char s[256];
12413         char *end;
12414         char *str_fld[16];
12415         uint16_t i;
12416         int ret;
12417
12418         p = strchr(p0, '(');
12419         if (p == NULL) {
12420                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12421                 return -1;
12422         }
12423         p++;
12424         p0 = strchr(p, ')');
12425         if (p0 == NULL) {
12426                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12427                 return -1;
12428         }
12429         size = p0 - p;
12430         if (size >= sizeof(s)) {
12431                 printf("The string size exceeds the internal buffer size\n");
12432                 return -1;
12433         }
12434         snprintf(s, sizeof(s), "%.*s", size, p);
12435         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12436         if (ret <= 0) {
12437                 printf("Failed to get the bandwidth list. ");
12438                 return -1;
12439         }
12440         *tc_num = ret;
12441         for (i = 0; i < ret; i++)
12442                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12443
12444         return 0;
12445 }
12446
12447 /* TC min bandwidth setting */
12448 static void
12449 cmd_vf_tc_min_bw_parsed(
12450         void *parsed_result,
12451         __rte_unused struct cmdline *cl,
12452         __rte_unused void *data)
12453 {
12454         struct cmd_vf_tc_bw_result *res = parsed_result;
12455         uint8_t tc_num;
12456         uint8_t bw[16];
12457         int ret = -ENOTSUP;
12458
12459         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12460                 return;
12461
12462         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12463         if (ret)
12464                 return;
12465
12466 #ifdef RTE_NET_I40E
12467         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12468                                               tc_num, bw);
12469 #endif
12470
12471         switch (ret) {
12472         case 0:
12473                 break;
12474         case -EINVAL:
12475                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12476                 break;
12477         case -ENODEV:
12478                 printf("invalid port_id %d\n", res->port_id);
12479                 break;
12480         case -ENOTSUP:
12481                 printf("function not implemented\n");
12482                 break;
12483         default:
12484                 printf("programming error: (%s)\n", strerror(-ret));
12485         }
12486 }
12487
12488 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12489         .f = cmd_vf_tc_min_bw_parsed,
12490         .data = NULL,
12491         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12492                     " <bw1, bw2, ...>",
12493         .tokens = {
12494                 (void *)&cmd_vf_tc_bw_set,
12495                 (void *)&cmd_vf_tc_bw_vf,
12496                 (void *)&cmd_vf_tc_bw_tc,
12497                 (void *)&cmd_vf_tc_bw_tx,
12498                 (void *)&cmd_vf_tc_bw_min_bw,
12499                 (void *)&cmd_vf_tc_bw_port_id,
12500                 (void *)&cmd_vf_tc_bw_vf_id,
12501                 (void *)&cmd_vf_tc_bw_bw_list,
12502                 NULL,
12503         },
12504 };
12505
12506 static void
12507 cmd_tc_min_bw_parsed(
12508         void *parsed_result,
12509         __rte_unused struct cmdline *cl,
12510         __rte_unused void *data)
12511 {
12512         struct cmd_vf_tc_bw_result *res = parsed_result;
12513         struct rte_port *port;
12514         uint8_t tc_num;
12515         uint8_t bw[16];
12516         int ret = -ENOTSUP;
12517
12518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12519                 return;
12520
12521         port = &ports[res->port_id];
12522         /** Check if the port is not started **/
12523         if (port->port_status != RTE_PORT_STOPPED) {
12524                 printf("Please stop port %d first\n", res->port_id);
12525                 return;
12526         }
12527
12528         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12529         if (ret)
12530                 return;
12531
12532 #ifdef RTE_NET_IXGBE
12533         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12534 #endif
12535
12536         switch (ret) {
12537         case 0:
12538                 break;
12539         case -EINVAL:
12540                 printf("invalid bandwidth\n");
12541                 break;
12542         case -ENODEV:
12543                 printf("invalid port_id %d\n", res->port_id);
12544                 break;
12545         case -ENOTSUP:
12546                 printf("function not implemented\n");
12547                 break;
12548         default:
12549                 printf("programming error: (%s)\n", strerror(-ret));
12550         }
12551 }
12552
12553 cmdline_parse_inst_t cmd_tc_min_bw = {
12554         .f = cmd_tc_min_bw_parsed,
12555         .data = NULL,
12556         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12557         .tokens = {
12558                 (void *)&cmd_vf_tc_bw_set,
12559                 (void *)&cmd_vf_tc_bw_tc,
12560                 (void *)&cmd_vf_tc_bw_tx,
12561                 (void *)&cmd_vf_tc_bw_min_bw,
12562                 (void *)&cmd_vf_tc_bw_port_id,
12563                 (void *)&cmd_vf_tc_bw_bw_list,
12564                 NULL,
12565         },
12566 };
12567
12568 /* TC max bandwidth setting */
12569 static void
12570 cmd_vf_tc_max_bw_parsed(
12571         void *parsed_result,
12572         __rte_unused struct cmdline *cl,
12573         __rte_unused void *data)
12574 {
12575         struct cmd_vf_tc_bw_result *res = parsed_result;
12576         int ret = -ENOTSUP;
12577
12578         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12579                 return;
12580
12581 #ifdef RTE_NET_I40E
12582         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12583                                             res->tc_no, res->bw);
12584 #endif
12585
12586         switch (ret) {
12587         case 0:
12588                 break;
12589         case -EINVAL:
12590                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12591                        res->vf_id, res->tc_no, res->bw);
12592                 break;
12593         case -ENODEV:
12594                 printf("invalid port_id %d\n", res->port_id);
12595                 break;
12596         case -ENOTSUP:
12597                 printf("function not implemented\n");
12598                 break;
12599         default:
12600                 printf("programming error: (%s)\n", strerror(-ret));
12601         }
12602 }
12603
12604 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12605         .f = cmd_vf_tc_max_bw_parsed,
12606         .data = NULL,
12607         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12608                     " <bandwidth>",
12609         .tokens = {
12610                 (void *)&cmd_vf_tc_bw_set,
12611                 (void *)&cmd_vf_tc_bw_vf,
12612                 (void *)&cmd_vf_tc_bw_tc,
12613                 (void *)&cmd_vf_tc_bw_tx,
12614                 (void *)&cmd_vf_tc_bw_max_bw,
12615                 (void *)&cmd_vf_tc_bw_port_id,
12616                 (void *)&cmd_vf_tc_bw_vf_id,
12617                 (void *)&cmd_vf_tc_bw_tc_no,
12618                 (void *)&cmd_vf_tc_bw_bw,
12619                 NULL,
12620         },
12621 };
12622
12623 /** Set VXLAN encapsulation details */
12624 struct cmd_set_vxlan_result {
12625         cmdline_fixed_string_t set;
12626         cmdline_fixed_string_t vxlan;
12627         cmdline_fixed_string_t pos_token;
12628         cmdline_fixed_string_t ip_version;
12629         uint32_t vlan_present:1;
12630         uint32_t vni;
12631         uint16_t udp_src;
12632         uint16_t udp_dst;
12633         cmdline_ipaddr_t ip_src;
12634         cmdline_ipaddr_t ip_dst;
12635         uint16_t tci;
12636         uint8_t tos;
12637         uint8_t ttl;
12638         struct rte_ether_addr eth_src;
12639         struct rte_ether_addr eth_dst;
12640 };
12641
12642 cmdline_parse_token_string_t cmd_set_vxlan_set =
12643         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12644 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12645         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12646 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12647         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12648                                  "vxlan-tos-ttl");
12649 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12650         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12651                                  "vxlan-with-vlan");
12652 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12653         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12654                                  "ip-version");
12655 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12656         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12657                                  "ipv4#ipv6");
12658 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12659         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12660                                  "vni");
12661 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12662         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12663 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12664         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12665                                  "udp-src");
12666 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12667         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12668 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12669         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12670                                  "udp-dst");
12671 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12672         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12673 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12674         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12675                                  "ip-tos");
12676 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12677         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12678 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12679         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12680                                  "ip-ttl");
12681 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12682         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12683 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12684         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12685                                  "ip-src");
12686 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12687         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12688 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12689         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12690                                  "ip-dst");
12691 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12692         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12693 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12694         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12695                                  "vlan-tci");
12696 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12697         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12698 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12699         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12700                                  "eth-src");
12701 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12702         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12703 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12704         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12705                                  "eth-dst");
12706 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12707         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12708
12709 static void cmd_set_vxlan_parsed(void *parsed_result,
12710         __rte_unused struct cmdline *cl,
12711         __rte_unused void *data)
12712 {
12713         struct cmd_set_vxlan_result *res = parsed_result;
12714         union {
12715                 uint32_t vxlan_id;
12716                 uint8_t vni[4];
12717         } id = {
12718                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12719         };
12720
12721         vxlan_encap_conf.select_tos_ttl = 0;
12722         if (strcmp(res->vxlan, "vxlan") == 0)
12723                 vxlan_encap_conf.select_vlan = 0;
12724         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12725                 vxlan_encap_conf.select_vlan = 1;
12726         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12727                 vxlan_encap_conf.select_vlan = 0;
12728                 vxlan_encap_conf.select_tos_ttl = 1;
12729         }
12730         if (strcmp(res->ip_version, "ipv4") == 0)
12731                 vxlan_encap_conf.select_ipv4 = 1;
12732         else if (strcmp(res->ip_version, "ipv6") == 0)
12733                 vxlan_encap_conf.select_ipv4 = 0;
12734         else
12735                 return;
12736         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12737         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12738         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12739         vxlan_encap_conf.ip_tos = res->tos;
12740         vxlan_encap_conf.ip_ttl = res->ttl;
12741         if (vxlan_encap_conf.select_ipv4) {
12742                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12743                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12744         } else {
12745                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12746                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12747         }
12748         if (vxlan_encap_conf.select_vlan)
12749                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12750         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12751                    RTE_ETHER_ADDR_LEN);
12752         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12753                    RTE_ETHER_ADDR_LEN);
12754 }
12755
12756 cmdline_parse_inst_t cmd_set_vxlan = {
12757         .f = cmd_set_vxlan_parsed,
12758         .data = NULL,
12759         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12760                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12761                 " eth-src <eth-src> eth-dst <eth-dst>",
12762         .tokens = {
12763                 (void *)&cmd_set_vxlan_set,
12764                 (void *)&cmd_set_vxlan_vxlan,
12765                 (void *)&cmd_set_vxlan_ip_version,
12766                 (void *)&cmd_set_vxlan_ip_version_value,
12767                 (void *)&cmd_set_vxlan_vni,
12768                 (void *)&cmd_set_vxlan_vni_value,
12769                 (void *)&cmd_set_vxlan_udp_src,
12770                 (void *)&cmd_set_vxlan_udp_src_value,
12771                 (void *)&cmd_set_vxlan_udp_dst,
12772                 (void *)&cmd_set_vxlan_udp_dst_value,
12773                 (void *)&cmd_set_vxlan_ip_src,
12774                 (void *)&cmd_set_vxlan_ip_src_value,
12775                 (void *)&cmd_set_vxlan_ip_dst,
12776                 (void *)&cmd_set_vxlan_ip_dst_value,
12777                 (void *)&cmd_set_vxlan_eth_src,
12778                 (void *)&cmd_set_vxlan_eth_src_value,
12779                 (void *)&cmd_set_vxlan_eth_dst,
12780                 (void *)&cmd_set_vxlan_eth_dst_value,
12781                 NULL,
12782         },
12783 };
12784
12785 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12786         .f = cmd_set_vxlan_parsed,
12787         .data = NULL,
12788         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12789                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12790                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12791                 " eth-dst <eth-dst>",
12792         .tokens = {
12793                 (void *)&cmd_set_vxlan_set,
12794                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12795                 (void *)&cmd_set_vxlan_ip_version,
12796                 (void *)&cmd_set_vxlan_ip_version_value,
12797                 (void *)&cmd_set_vxlan_vni,
12798                 (void *)&cmd_set_vxlan_vni_value,
12799                 (void *)&cmd_set_vxlan_udp_src,
12800                 (void *)&cmd_set_vxlan_udp_src_value,
12801                 (void *)&cmd_set_vxlan_udp_dst,
12802                 (void *)&cmd_set_vxlan_udp_dst_value,
12803                 (void *)&cmd_set_vxlan_ip_tos,
12804                 (void *)&cmd_set_vxlan_ip_tos_value,
12805                 (void *)&cmd_set_vxlan_ip_ttl,
12806                 (void *)&cmd_set_vxlan_ip_ttl_value,
12807                 (void *)&cmd_set_vxlan_ip_src,
12808                 (void *)&cmd_set_vxlan_ip_src_value,
12809                 (void *)&cmd_set_vxlan_ip_dst,
12810                 (void *)&cmd_set_vxlan_ip_dst_value,
12811                 (void *)&cmd_set_vxlan_eth_src,
12812                 (void *)&cmd_set_vxlan_eth_src_value,
12813                 (void *)&cmd_set_vxlan_eth_dst,
12814                 (void *)&cmd_set_vxlan_eth_dst_value,
12815                 NULL,
12816         },
12817 };
12818
12819 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12820         .f = cmd_set_vxlan_parsed,
12821         .data = NULL,
12822         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12823                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12824                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12825                 " <eth-dst>",
12826         .tokens = {
12827                 (void *)&cmd_set_vxlan_set,
12828                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12829                 (void *)&cmd_set_vxlan_ip_version,
12830                 (void *)&cmd_set_vxlan_ip_version_value,
12831                 (void *)&cmd_set_vxlan_vni,
12832                 (void *)&cmd_set_vxlan_vni_value,
12833                 (void *)&cmd_set_vxlan_udp_src,
12834                 (void *)&cmd_set_vxlan_udp_src_value,
12835                 (void *)&cmd_set_vxlan_udp_dst,
12836                 (void *)&cmd_set_vxlan_udp_dst_value,
12837                 (void *)&cmd_set_vxlan_ip_src,
12838                 (void *)&cmd_set_vxlan_ip_src_value,
12839                 (void *)&cmd_set_vxlan_ip_dst,
12840                 (void *)&cmd_set_vxlan_ip_dst_value,
12841                 (void *)&cmd_set_vxlan_vlan,
12842                 (void *)&cmd_set_vxlan_vlan_value,
12843                 (void *)&cmd_set_vxlan_eth_src,
12844                 (void *)&cmd_set_vxlan_eth_src_value,
12845                 (void *)&cmd_set_vxlan_eth_dst,
12846                 (void *)&cmd_set_vxlan_eth_dst_value,
12847                 NULL,
12848         },
12849 };
12850
12851 /** Set NVGRE encapsulation details */
12852 struct cmd_set_nvgre_result {
12853         cmdline_fixed_string_t set;
12854         cmdline_fixed_string_t nvgre;
12855         cmdline_fixed_string_t pos_token;
12856         cmdline_fixed_string_t ip_version;
12857         uint32_t tni;
12858         cmdline_ipaddr_t ip_src;
12859         cmdline_ipaddr_t ip_dst;
12860         uint16_t tci;
12861         struct rte_ether_addr eth_src;
12862         struct rte_ether_addr eth_dst;
12863 };
12864
12865 cmdline_parse_token_string_t cmd_set_nvgre_set =
12866         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12867 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12868         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12869 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12870         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12871                                  "nvgre-with-vlan");
12872 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12873         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12874                                  "ip-version");
12875 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12876         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12877                                  "ipv4#ipv6");
12878 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12879         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12880                                  "tni");
12881 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12882         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12883 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12884         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12885                                  "ip-src");
12886 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12887         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12888 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12889         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12890                                  "ip-dst");
12891 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12892         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12893 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12894         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12895                                  "vlan-tci");
12896 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12897         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12898 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12899         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12900                                  "eth-src");
12901 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12902         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12903 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12904         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12905                                  "eth-dst");
12906 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12907         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12908
12909 static void cmd_set_nvgre_parsed(void *parsed_result,
12910         __rte_unused struct cmdline *cl,
12911         __rte_unused void *data)
12912 {
12913         struct cmd_set_nvgre_result *res = parsed_result;
12914         union {
12915                 uint32_t nvgre_tni;
12916                 uint8_t tni[4];
12917         } id = {
12918                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12919         };
12920
12921         if (strcmp(res->nvgre, "nvgre") == 0)
12922                 nvgre_encap_conf.select_vlan = 0;
12923         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12924                 nvgre_encap_conf.select_vlan = 1;
12925         if (strcmp(res->ip_version, "ipv4") == 0)
12926                 nvgre_encap_conf.select_ipv4 = 1;
12927         else if (strcmp(res->ip_version, "ipv6") == 0)
12928                 nvgre_encap_conf.select_ipv4 = 0;
12929         else
12930                 return;
12931         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12932         if (nvgre_encap_conf.select_ipv4) {
12933                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12934                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12935         } else {
12936                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12937                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12938         }
12939         if (nvgre_encap_conf.select_vlan)
12940                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12941         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12942                    RTE_ETHER_ADDR_LEN);
12943         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12944                    RTE_ETHER_ADDR_LEN);
12945 }
12946
12947 cmdline_parse_inst_t cmd_set_nvgre = {
12948         .f = cmd_set_nvgre_parsed,
12949         .data = NULL,
12950         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12951                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12952                 " eth-dst <eth-dst>",
12953         .tokens = {
12954                 (void *)&cmd_set_nvgre_set,
12955                 (void *)&cmd_set_nvgre_nvgre,
12956                 (void *)&cmd_set_nvgre_ip_version,
12957                 (void *)&cmd_set_nvgre_ip_version_value,
12958                 (void *)&cmd_set_nvgre_tni,
12959                 (void *)&cmd_set_nvgre_tni_value,
12960                 (void *)&cmd_set_nvgre_ip_src,
12961                 (void *)&cmd_set_nvgre_ip_src_value,
12962                 (void *)&cmd_set_nvgre_ip_dst,
12963                 (void *)&cmd_set_nvgre_ip_dst_value,
12964                 (void *)&cmd_set_nvgre_eth_src,
12965                 (void *)&cmd_set_nvgre_eth_src_value,
12966                 (void *)&cmd_set_nvgre_eth_dst,
12967                 (void *)&cmd_set_nvgre_eth_dst_value,
12968                 NULL,
12969         },
12970 };
12971
12972 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12973         .f = cmd_set_nvgre_parsed,
12974         .data = NULL,
12975         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12976                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12977                 " eth-src <eth-src> eth-dst <eth-dst>",
12978         .tokens = {
12979                 (void *)&cmd_set_nvgre_set,
12980                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12981                 (void *)&cmd_set_nvgre_ip_version,
12982                 (void *)&cmd_set_nvgre_ip_version_value,
12983                 (void *)&cmd_set_nvgre_tni,
12984                 (void *)&cmd_set_nvgre_tni_value,
12985                 (void *)&cmd_set_nvgre_ip_src,
12986                 (void *)&cmd_set_nvgre_ip_src_value,
12987                 (void *)&cmd_set_nvgre_ip_dst,
12988                 (void *)&cmd_set_nvgre_ip_dst_value,
12989                 (void *)&cmd_set_nvgre_vlan,
12990                 (void *)&cmd_set_nvgre_vlan_value,
12991                 (void *)&cmd_set_nvgre_eth_src,
12992                 (void *)&cmd_set_nvgre_eth_src_value,
12993                 (void *)&cmd_set_nvgre_eth_dst,
12994                 (void *)&cmd_set_nvgre_eth_dst_value,
12995                 NULL,
12996         },
12997 };
12998
12999 /** Set L2 encapsulation details */
13000 struct cmd_set_l2_encap_result {
13001         cmdline_fixed_string_t set;
13002         cmdline_fixed_string_t l2_encap;
13003         cmdline_fixed_string_t pos_token;
13004         cmdline_fixed_string_t ip_version;
13005         uint32_t vlan_present:1;
13006         uint16_t tci;
13007         struct rte_ether_addr eth_src;
13008         struct rte_ether_addr eth_dst;
13009 };
13010
13011 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13012         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13013 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13014         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13015 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13016         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13017                                  "l2_encap-with-vlan");
13018 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13019         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13020                                  "ip-version");
13021 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13022         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13023                                  "ipv4#ipv6");
13024 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13025         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13026                                  "vlan-tci");
13027 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13028         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13029 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13030         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13031                                  "eth-src");
13032 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13033         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13034 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13035         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13036                                  "eth-dst");
13037 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13038         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13039
13040 static void cmd_set_l2_encap_parsed(void *parsed_result,
13041         __rte_unused struct cmdline *cl,
13042         __rte_unused void *data)
13043 {
13044         struct cmd_set_l2_encap_result *res = parsed_result;
13045
13046         if (strcmp(res->l2_encap, "l2_encap") == 0)
13047                 l2_encap_conf.select_vlan = 0;
13048         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13049                 l2_encap_conf.select_vlan = 1;
13050         if (strcmp(res->ip_version, "ipv4") == 0)
13051                 l2_encap_conf.select_ipv4 = 1;
13052         else if (strcmp(res->ip_version, "ipv6") == 0)
13053                 l2_encap_conf.select_ipv4 = 0;
13054         else
13055                 return;
13056         if (l2_encap_conf.select_vlan)
13057                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13058         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13059                    RTE_ETHER_ADDR_LEN);
13060         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13061                    RTE_ETHER_ADDR_LEN);
13062 }
13063
13064 cmdline_parse_inst_t cmd_set_l2_encap = {
13065         .f = cmd_set_l2_encap_parsed,
13066         .data = NULL,
13067         .help_str = "set l2_encap ip-version ipv4|ipv6"
13068                 " eth-src <eth-src> eth-dst <eth-dst>",
13069         .tokens = {
13070                 (void *)&cmd_set_l2_encap_set,
13071                 (void *)&cmd_set_l2_encap_l2_encap,
13072                 (void *)&cmd_set_l2_encap_ip_version,
13073                 (void *)&cmd_set_l2_encap_ip_version_value,
13074                 (void *)&cmd_set_l2_encap_eth_src,
13075                 (void *)&cmd_set_l2_encap_eth_src_value,
13076                 (void *)&cmd_set_l2_encap_eth_dst,
13077                 (void *)&cmd_set_l2_encap_eth_dst_value,
13078                 NULL,
13079         },
13080 };
13081
13082 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13083         .f = cmd_set_l2_encap_parsed,
13084         .data = NULL,
13085         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13086                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13087         .tokens = {
13088                 (void *)&cmd_set_l2_encap_set,
13089                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13090                 (void *)&cmd_set_l2_encap_ip_version,
13091                 (void *)&cmd_set_l2_encap_ip_version_value,
13092                 (void *)&cmd_set_l2_encap_vlan,
13093                 (void *)&cmd_set_l2_encap_vlan_value,
13094                 (void *)&cmd_set_l2_encap_eth_src,
13095                 (void *)&cmd_set_l2_encap_eth_src_value,
13096                 (void *)&cmd_set_l2_encap_eth_dst,
13097                 (void *)&cmd_set_l2_encap_eth_dst_value,
13098                 NULL,
13099         },
13100 };
13101
13102 /** Set L2 decapsulation details */
13103 struct cmd_set_l2_decap_result {
13104         cmdline_fixed_string_t set;
13105         cmdline_fixed_string_t l2_decap;
13106         cmdline_fixed_string_t pos_token;
13107         uint32_t vlan_present:1;
13108 };
13109
13110 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13111         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13112 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13113         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13114                                  "l2_decap");
13115 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13116         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13117                                  "l2_decap-with-vlan");
13118
13119 static void cmd_set_l2_decap_parsed(void *parsed_result,
13120         __rte_unused struct cmdline *cl,
13121         __rte_unused void *data)
13122 {
13123         struct cmd_set_l2_decap_result *res = parsed_result;
13124
13125         if (strcmp(res->l2_decap, "l2_decap") == 0)
13126                 l2_decap_conf.select_vlan = 0;
13127         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13128                 l2_decap_conf.select_vlan = 1;
13129 }
13130
13131 cmdline_parse_inst_t cmd_set_l2_decap = {
13132         .f = cmd_set_l2_decap_parsed,
13133         .data = NULL,
13134         .help_str = "set l2_decap",
13135         .tokens = {
13136                 (void *)&cmd_set_l2_decap_set,
13137                 (void *)&cmd_set_l2_decap_l2_decap,
13138                 NULL,
13139         },
13140 };
13141
13142 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13143         .f = cmd_set_l2_decap_parsed,
13144         .data = NULL,
13145         .help_str = "set l2_decap-with-vlan",
13146         .tokens = {
13147                 (void *)&cmd_set_l2_decap_set,
13148                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13149                 NULL,
13150         },
13151 };
13152
13153 /** Set MPLSoGRE encapsulation details */
13154 struct cmd_set_mplsogre_encap_result {
13155         cmdline_fixed_string_t set;
13156         cmdline_fixed_string_t mplsogre;
13157         cmdline_fixed_string_t pos_token;
13158         cmdline_fixed_string_t ip_version;
13159         uint32_t vlan_present:1;
13160         uint32_t label;
13161         cmdline_ipaddr_t ip_src;
13162         cmdline_ipaddr_t ip_dst;
13163         uint16_t tci;
13164         struct rte_ether_addr eth_src;
13165         struct rte_ether_addr eth_dst;
13166 };
13167
13168 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13169         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13170                                  "set");
13171 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13172         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13173                                  "mplsogre_encap");
13174 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13175         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13176                                  mplsogre, "mplsogre_encap-with-vlan");
13177 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13178         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13179                                  pos_token, "ip-version");
13180 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13182                                  ip_version, "ipv4#ipv6");
13183 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13185                                  pos_token, "label");
13186 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13187         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13188                               RTE_UINT32);
13189 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13191                                  pos_token, "ip-src");
13192 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13193         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13194 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13196                                  pos_token, "ip-dst");
13197 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13198         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13199 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13200         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13201                                  pos_token, "vlan-tci");
13202 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13203         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13204                               RTE_UINT16);
13205 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13207                                  pos_token, "eth-src");
13208 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13209         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13210                                     eth_src);
13211 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13212         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13213                                  pos_token, "eth-dst");
13214 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13215         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13216                                     eth_dst);
13217
13218 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13219         __rte_unused struct cmdline *cl,
13220         __rte_unused void *data)
13221 {
13222         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13223         union {
13224                 uint32_t mplsogre_label;
13225                 uint8_t label[4];
13226         } id = {
13227                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13228         };
13229
13230         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13231                 mplsogre_encap_conf.select_vlan = 0;
13232         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13233                 mplsogre_encap_conf.select_vlan = 1;
13234         if (strcmp(res->ip_version, "ipv4") == 0)
13235                 mplsogre_encap_conf.select_ipv4 = 1;
13236         else if (strcmp(res->ip_version, "ipv6") == 0)
13237                 mplsogre_encap_conf.select_ipv4 = 0;
13238         else
13239                 return;
13240         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13241         if (mplsogre_encap_conf.select_ipv4) {
13242                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13243                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13244         } else {
13245                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13246                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13247         }
13248         if (mplsogre_encap_conf.select_vlan)
13249                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13250         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13251                    RTE_ETHER_ADDR_LEN);
13252         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13253                    RTE_ETHER_ADDR_LEN);
13254 }
13255
13256 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13257         .f = cmd_set_mplsogre_encap_parsed,
13258         .data = NULL,
13259         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13260                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13261                 " eth-dst <eth-dst>",
13262         .tokens = {
13263                 (void *)&cmd_set_mplsogre_encap_set,
13264                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13265                 (void *)&cmd_set_mplsogre_encap_ip_version,
13266                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13267                 (void *)&cmd_set_mplsogre_encap_label,
13268                 (void *)&cmd_set_mplsogre_encap_label_value,
13269                 (void *)&cmd_set_mplsogre_encap_ip_src,
13270                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13271                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13272                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13273                 (void *)&cmd_set_mplsogre_encap_eth_src,
13274                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13275                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13276                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13277                 NULL,
13278         },
13279 };
13280
13281 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13282         .f = cmd_set_mplsogre_encap_parsed,
13283         .data = NULL,
13284         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13285                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13286                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13287         .tokens = {
13288                 (void *)&cmd_set_mplsogre_encap_set,
13289                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13290                 (void *)&cmd_set_mplsogre_encap_ip_version,
13291                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13292                 (void *)&cmd_set_mplsogre_encap_label,
13293                 (void *)&cmd_set_mplsogre_encap_label_value,
13294                 (void *)&cmd_set_mplsogre_encap_ip_src,
13295                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13296                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13297                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13298                 (void *)&cmd_set_mplsogre_encap_vlan,
13299                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13300                 (void *)&cmd_set_mplsogre_encap_eth_src,
13301                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13302                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13303                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13304                 NULL,
13305         },
13306 };
13307
13308 /** Set MPLSoGRE decapsulation details */
13309 struct cmd_set_mplsogre_decap_result {
13310         cmdline_fixed_string_t set;
13311         cmdline_fixed_string_t mplsogre;
13312         cmdline_fixed_string_t pos_token;
13313         cmdline_fixed_string_t ip_version;
13314         uint32_t vlan_present:1;
13315 };
13316
13317 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13318         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13319                                  "set");
13320 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13321         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13322                                  "mplsogre_decap");
13323 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13324         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13325                                  mplsogre, "mplsogre_decap-with-vlan");
13326 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13328                                  pos_token, "ip-version");
13329 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13330         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13331                                  ip_version, "ipv4#ipv6");
13332
13333 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13334         __rte_unused struct cmdline *cl,
13335         __rte_unused void *data)
13336 {
13337         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13338
13339         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13340                 mplsogre_decap_conf.select_vlan = 0;
13341         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13342                 mplsogre_decap_conf.select_vlan = 1;
13343         if (strcmp(res->ip_version, "ipv4") == 0)
13344                 mplsogre_decap_conf.select_ipv4 = 1;
13345         else if (strcmp(res->ip_version, "ipv6") == 0)
13346                 mplsogre_decap_conf.select_ipv4 = 0;
13347 }
13348
13349 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13350         .f = cmd_set_mplsogre_decap_parsed,
13351         .data = NULL,
13352         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13353         .tokens = {
13354                 (void *)&cmd_set_mplsogre_decap_set,
13355                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13356                 (void *)&cmd_set_mplsogre_decap_ip_version,
13357                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13358                 NULL,
13359         },
13360 };
13361
13362 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13363         .f = cmd_set_mplsogre_decap_parsed,
13364         .data = NULL,
13365         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13366         .tokens = {
13367                 (void *)&cmd_set_mplsogre_decap_set,
13368                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13369                 (void *)&cmd_set_mplsogre_decap_ip_version,
13370                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13371                 NULL,
13372         },
13373 };
13374
13375 /** Set MPLSoUDP encapsulation details */
13376 struct cmd_set_mplsoudp_encap_result {
13377         cmdline_fixed_string_t set;
13378         cmdline_fixed_string_t mplsoudp;
13379         cmdline_fixed_string_t pos_token;
13380         cmdline_fixed_string_t ip_version;
13381         uint32_t vlan_present:1;
13382         uint32_t label;
13383         uint16_t udp_src;
13384         uint16_t udp_dst;
13385         cmdline_ipaddr_t ip_src;
13386         cmdline_ipaddr_t ip_dst;
13387         uint16_t tci;
13388         struct rte_ether_addr eth_src;
13389         struct rte_ether_addr eth_dst;
13390 };
13391
13392 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13393         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13394                                  "set");
13395 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13396         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13397                                  "mplsoudp_encap");
13398 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13399         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13400                                  mplsoudp, "mplsoudp_encap-with-vlan");
13401 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13402         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13403                                  pos_token, "ip-version");
13404 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13405         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13406                                  ip_version, "ipv4#ipv6");
13407 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13408         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13409                                  pos_token, "label");
13410 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13411         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13412                               RTE_UINT32);
13413 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13414         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13415                                  pos_token, "udp-src");
13416 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13417         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13418                               RTE_UINT16);
13419 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13420         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13421                                  pos_token, "udp-dst");
13422 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13423         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13424                               RTE_UINT16);
13425 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13426         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13427                                  pos_token, "ip-src");
13428 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13429         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13430 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13431         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13432                                  pos_token, "ip-dst");
13433 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13434         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13435 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13436         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13437                                  pos_token, "vlan-tci");
13438 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13439         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13440                               RTE_UINT16);
13441 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13442         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13443                                  pos_token, "eth-src");
13444 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13445         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13446                                     eth_src);
13447 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13448         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13449                                  pos_token, "eth-dst");
13450 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13451         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13452                                     eth_dst);
13453
13454 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13455         __rte_unused struct cmdline *cl,
13456         __rte_unused void *data)
13457 {
13458         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13459         union {
13460                 uint32_t mplsoudp_label;
13461                 uint8_t label[4];
13462         } id = {
13463                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13464         };
13465
13466         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13467                 mplsoudp_encap_conf.select_vlan = 0;
13468         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13469                 mplsoudp_encap_conf.select_vlan = 1;
13470         if (strcmp(res->ip_version, "ipv4") == 0)
13471                 mplsoudp_encap_conf.select_ipv4 = 1;
13472         else if (strcmp(res->ip_version, "ipv6") == 0)
13473                 mplsoudp_encap_conf.select_ipv4 = 0;
13474         else
13475                 return;
13476         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13477         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13478         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13479         if (mplsoudp_encap_conf.select_ipv4) {
13480                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13481                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13482         } else {
13483                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13484                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13485         }
13486         if (mplsoudp_encap_conf.select_vlan)
13487                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13488         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13489                    RTE_ETHER_ADDR_LEN);
13490         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13491                    RTE_ETHER_ADDR_LEN);
13492 }
13493
13494 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13495         .f = cmd_set_mplsoudp_encap_parsed,
13496         .data = NULL,
13497         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13498                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13499                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13500         .tokens = {
13501                 (void *)&cmd_set_mplsoudp_encap_set,
13502                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13503                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13504                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13505                 (void *)&cmd_set_mplsoudp_encap_label,
13506                 (void *)&cmd_set_mplsoudp_encap_label_value,
13507                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13508                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13509                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13510                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13511                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13512                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13513                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13514                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13515                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13516                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13517                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13518                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13519                 NULL,
13520         },
13521 };
13522
13523 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13524         .f = cmd_set_mplsoudp_encap_parsed,
13525         .data = NULL,
13526         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13527                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13528                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13529                 " eth-src <eth-src> eth-dst <eth-dst>",
13530         .tokens = {
13531                 (void *)&cmd_set_mplsoudp_encap_set,
13532                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13533                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13534                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13535                 (void *)&cmd_set_mplsoudp_encap_label,
13536                 (void *)&cmd_set_mplsoudp_encap_label_value,
13537                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13538                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13539                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13540                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13541                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13542                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13543                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13544                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13545                 (void *)&cmd_set_mplsoudp_encap_vlan,
13546                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13547                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13548                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13549                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13550                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13551                 NULL,
13552         },
13553 };
13554
13555 /** Set MPLSoUDP decapsulation details */
13556 struct cmd_set_mplsoudp_decap_result {
13557         cmdline_fixed_string_t set;
13558         cmdline_fixed_string_t mplsoudp;
13559         cmdline_fixed_string_t pos_token;
13560         cmdline_fixed_string_t ip_version;
13561         uint32_t vlan_present:1;
13562 };
13563
13564 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13565         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13566                                  "set");
13567 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13568         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13569                                  "mplsoudp_decap");
13570 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13571         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13572                                  mplsoudp, "mplsoudp_decap-with-vlan");
13573 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13574         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13575                                  pos_token, "ip-version");
13576 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13577         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13578                                  ip_version, "ipv4#ipv6");
13579
13580 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13581         __rte_unused struct cmdline *cl,
13582         __rte_unused void *data)
13583 {
13584         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13585
13586         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13587                 mplsoudp_decap_conf.select_vlan = 0;
13588         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13589                 mplsoudp_decap_conf.select_vlan = 1;
13590         if (strcmp(res->ip_version, "ipv4") == 0)
13591                 mplsoudp_decap_conf.select_ipv4 = 1;
13592         else if (strcmp(res->ip_version, "ipv6") == 0)
13593                 mplsoudp_decap_conf.select_ipv4 = 0;
13594 }
13595
13596 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13597         .f = cmd_set_mplsoudp_decap_parsed,
13598         .data = NULL,
13599         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13600         .tokens = {
13601                 (void *)&cmd_set_mplsoudp_decap_set,
13602                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13603                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13604                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13605                 NULL,
13606         },
13607 };
13608
13609 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13610         .f = cmd_set_mplsoudp_decap_parsed,
13611         .data = NULL,
13612         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13613         .tokens = {
13614                 (void *)&cmd_set_mplsoudp_decap_set,
13615                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13616                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13617                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13618                 NULL,
13619         },
13620 };
13621
13622 /* Strict link priority scheduling mode setting */
13623 static void
13624 cmd_strict_link_prio_parsed(
13625         void *parsed_result,
13626         __rte_unused struct cmdline *cl,
13627         __rte_unused void *data)
13628 {
13629         struct cmd_vf_tc_bw_result *res = parsed_result;
13630         int ret = -ENOTSUP;
13631
13632         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13633                 return;
13634
13635 #ifdef RTE_NET_I40E
13636         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13637 #endif
13638
13639         switch (ret) {
13640         case 0:
13641                 break;
13642         case -EINVAL:
13643                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13644                 break;
13645         case -ENODEV:
13646                 printf("invalid port_id %d\n", res->port_id);
13647                 break;
13648         case -ENOTSUP:
13649                 printf("function not implemented\n");
13650                 break;
13651         default:
13652                 printf("programming error: (%s)\n", strerror(-ret));
13653         }
13654 }
13655
13656 cmdline_parse_inst_t cmd_strict_link_prio = {
13657         .f = cmd_strict_link_prio_parsed,
13658         .data = NULL,
13659         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13660         .tokens = {
13661                 (void *)&cmd_vf_tc_bw_set,
13662                 (void *)&cmd_vf_tc_bw_tx,
13663                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13664                 (void *)&cmd_vf_tc_bw_port_id,
13665                 (void *)&cmd_vf_tc_bw_tc_map,
13666                 NULL,
13667         },
13668 };
13669
13670 /* Load dynamic device personalization*/
13671 struct cmd_ddp_add_result {
13672         cmdline_fixed_string_t ddp;
13673         cmdline_fixed_string_t add;
13674         portid_t port_id;
13675         char filepath[];
13676 };
13677
13678 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13679         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13680 cmdline_parse_token_string_t cmd_ddp_add_add =
13681         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13682 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13683         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13684                 RTE_UINT16);
13685 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13686         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13687
13688 static void
13689 cmd_ddp_add_parsed(
13690         void *parsed_result,
13691         __rte_unused struct cmdline *cl,
13692         __rte_unused void *data)
13693 {
13694         struct cmd_ddp_add_result *res = parsed_result;
13695         uint8_t *buff;
13696         uint32_t size;
13697         char *filepath;
13698         char *file_fld[2];
13699         int file_num;
13700         int ret = -ENOTSUP;
13701
13702         if (!all_ports_stopped()) {
13703                 printf("Please stop all ports first\n");
13704                 return;
13705         }
13706
13707         filepath = strdup(res->filepath);
13708         if (filepath == NULL) {
13709                 printf("Failed to allocate memory\n");
13710                 return;
13711         }
13712         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13713
13714         buff = open_file(file_fld[0], &size);
13715         if (!buff) {
13716                 free((void *)filepath);
13717                 return;
13718         }
13719
13720 #ifdef RTE_NET_I40E
13721         if (ret == -ENOTSUP)
13722                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13723                                                buff, size,
13724                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13725 #endif
13726
13727         if (ret == -EEXIST)
13728                 printf("Profile has already existed.\n");
13729         else if (ret < 0)
13730                 printf("Failed to load profile.\n");
13731         else if (file_num == 2)
13732                 save_file(file_fld[1], buff, size);
13733
13734         close_file(buff);
13735         free((void *)filepath);
13736 }
13737
13738 cmdline_parse_inst_t cmd_ddp_add = {
13739         .f = cmd_ddp_add_parsed,
13740         .data = NULL,
13741         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13742         .tokens = {
13743                 (void *)&cmd_ddp_add_ddp,
13744                 (void *)&cmd_ddp_add_add,
13745                 (void *)&cmd_ddp_add_port_id,
13746                 (void *)&cmd_ddp_add_filepath,
13747                 NULL,
13748         },
13749 };
13750
13751 /* Delete dynamic device personalization*/
13752 struct cmd_ddp_del_result {
13753         cmdline_fixed_string_t ddp;
13754         cmdline_fixed_string_t del;
13755         portid_t port_id;
13756         char filepath[];
13757 };
13758
13759 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13760         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13761 cmdline_parse_token_string_t cmd_ddp_del_del =
13762         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13763 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13764         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13765 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13766         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13767
13768 static void
13769 cmd_ddp_del_parsed(
13770         void *parsed_result,
13771         __rte_unused struct cmdline *cl,
13772         __rte_unused void *data)
13773 {
13774         struct cmd_ddp_del_result *res = parsed_result;
13775         uint8_t *buff;
13776         uint32_t size;
13777         int ret = -ENOTSUP;
13778
13779         if (!all_ports_stopped()) {
13780                 printf("Please stop all ports first\n");
13781                 return;
13782         }
13783
13784         buff = open_file(res->filepath, &size);
13785         if (!buff)
13786                 return;
13787
13788 #ifdef RTE_NET_I40E
13789         if (ret == -ENOTSUP)
13790                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13791                                                buff, size,
13792                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13793 #endif
13794
13795         if (ret == -EACCES)
13796                 printf("Profile does not exist.\n");
13797         else if (ret < 0)
13798                 printf("Failed to delete profile.\n");
13799
13800         close_file(buff);
13801 }
13802
13803 cmdline_parse_inst_t cmd_ddp_del = {
13804         .f = cmd_ddp_del_parsed,
13805         .data = NULL,
13806         .help_str = "ddp del <port_id> <backup_profile_path>",
13807         .tokens = {
13808                 (void *)&cmd_ddp_del_ddp,
13809                 (void *)&cmd_ddp_del_del,
13810                 (void *)&cmd_ddp_del_port_id,
13811                 (void *)&cmd_ddp_del_filepath,
13812                 NULL,
13813         },
13814 };
13815
13816 /* Get dynamic device personalization profile info */
13817 struct cmd_ddp_info_result {
13818         cmdline_fixed_string_t ddp;
13819         cmdline_fixed_string_t get;
13820         cmdline_fixed_string_t info;
13821         char filepath[];
13822 };
13823
13824 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13825         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13826 cmdline_parse_token_string_t cmd_ddp_info_get =
13827         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13828 cmdline_parse_token_string_t cmd_ddp_info_info =
13829         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13830 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13831         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13832
13833 static void
13834 cmd_ddp_info_parsed(
13835         void *parsed_result,
13836         __rte_unused struct cmdline *cl,
13837         __rte_unused void *data)
13838 {
13839         struct cmd_ddp_info_result *res = parsed_result;
13840         uint8_t *pkg;
13841         uint32_t pkg_size;
13842         int ret = -ENOTSUP;
13843 #ifdef RTE_NET_I40E
13844         uint32_t i, j, n;
13845         uint8_t *buff;
13846         uint32_t buff_size = 0;
13847         struct rte_pmd_i40e_profile_info info;
13848         uint32_t dev_num = 0;
13849         struct rte_pmd_i40e_ddp_device_id *devs;
13850         uint32_t proto_num = 0;
13851         struct rte_pmd_i40e_proto_info *proto = NULL;
13852         uint32_t pctype_num = 0;
13853         struct rte_pmd_i40e_ptype_info *pctype;
13854         uint32_t ptype_num = 0;
13855         struct rte_pmd_i40e_ptype_info *ptype;
13856         uint8_t proto_id;
13857
13858 #endif
13859
13860         pkg = open_file(res->filepath, &pkg_size);
13861         if (!pkg)
13862                 return;
13863
13864 #ifdef RTE_NET_I40E
13865         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13866                                 (uint8_t *)&info, sizeof(info),
13867                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13868         if (!ret) {
13869                 printf("Global Track id:       0x%x\n", info.track_id);
13870                 printf("Global Version:        %d.%d.%d.%d\n",
13871                         info.version.major,
13872                         info.version.minor,
13873                         info.version.update,
13874                         info.version.draft);
13875                 printf("Global Package name:   %s\n\n", info.name);
13876         }
13877
13878         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13879                                 (uint8_t *)&info, sizeof(info),
13880                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13881         if (!ret) {
13882                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13883                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13884                         info.version.major,
13885                         info.version.minor,
13886                         info.version.update,
13887                         info.version.draft);
13888                 printf("i40e Profile name:     %s\n\n", info.name);
13889         }
13890
13891         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13892                                 (uint8_t *)&buff_size, sizeof(buff_size),
13893                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13894         if (!ret && buff_size) {
13895                 buff = (uint8_t *)malloc(buff_size);
13896                 if (buff) {
13897                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13898                                                 buff, buff_size,
13899                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13900                         if (!ret)
13901                                 printf("Package Notes:\n%s\n\n", buff);
13902                         free(buff);
13903                 }
13904         }
13905
13906         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13907                                 (uint8_t *)&dev_num, sizeof(dev_num),
13908                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13909         if (!ret && dev_num) {
13910                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13911                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13912                 if (devs) {
13913                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13914                                                 (uint8_t *)devs, buff_size,
13915                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13916                         if (!ret) {
13917                                 printf("List of supported devices:\n");
13918                                 for (i = 0; i < dev_num; i++) {
13919                                         printf("  %04X:%04X %04X:%04X\n",
13920                                                 devs[i].vendor_dev_id >> 16,
13921                                                 devs[i].vendor_dev_id & 0xFFFF,
13922                                                 devs[i].sub_vendor_dev_id >> 16,
13923                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13924                                 }
13925                                 printf("\n");
13926                         }
13927                         free(devs);
13928                 }
13929         }
13930
13931         /* get information about protocols and packet types */
13932         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13933                 (uint8_t *)&proto_num, sizeof(proto_num),
13934                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13935         if (ret || !proto_num)
13936                 goto no_print_return;
13937
13938         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13939         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13940         if (!proto)
13941                 goto no_print_return;
13942
13943         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13944                                         buff_size,
13945                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13946         if (!ret) {
13947                 printf("List of used protocols:\n");
13948                 for (i = 0; i < proto_num; i++)
13949                         printf("  %2u: %s\n", proto[i].proto_id,
13950                                proto[i].name);
13951                 printf("\n");
13952         }
13953         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13954                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13955                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13956         if (ret || !pctype_num)
13957                 goto no_print_pctypes;
13958
13959         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13960         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13961         if (!pctype)
13962                 goto no_print_pctypes;
13963
13964         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13965                                         buff_size,
13966                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13967         if (ret) {
13968                 free(pctype);
13969                 goto no_print_pctypes;
13970         }
13971
13972         printf("List of defined packet classification types:\n");
13973         for (i = 0; i < pctype_num; i++) {
13974                 printf("  %2u:", pctype[i].ptype_id);
13975                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13976                         proto_id = pctype[i].protocols[j];
13977                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13978                                 for (n = 0; n < proto_num; n++) {
13979                                         if (proto[n].proto_id == proto_id) {
13980                                                 printf(" %s", proto[n].name);
13981                                                 break;
13982                                         }
13983                                 }
13984                         }
13985                 }
13986                 printf("\n");
13987         }
13988         printf("\n");
13989         free(pctype);
13990
13991 no_print_pctypes:
13992
13993         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13994                                         sizeof(ptype_num),
13995                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13996         if (ret || !ptype_num)
13997                 goto no_print_return;
13998
13999         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14000         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14001         if (!ptype)
14002                 goto no_print_return;
14003
14004         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14005                                         buff_size,
14006                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14007         if (ret) {
14008                 free(ptype);
14009                 goto no_print_return;
14010         }
14011         printf("List of defined packet types:\n");
14012         for (i = 0; i < ptype_num; i++) {
14013                 printf("  %2u:", ptype[i].ptype_id);
14014                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14015                         proto_id = ptype[i].protocols[j];
14016                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14017                                 for (n = 0; n < proto_num; n++) {
14018                                         if (proto[n].proto_id == proto_id) {
14019                                                 printf(" %s", proto[n].name);
14020                                                 break;
14021                                         }
14022                                 }
14023                         }
14024                 }
14025                 printf("\n");
14026         }
14027         free(ptype);
14028         printf("\n");
14029
14030         ret = 0;
14031 no_print_return:
14032         if (proto)
14033                 free(proto);
14034 #endif
14035         if (ret == -ENOTSUP)
14036                 printf("Function not supported in PMD driver\n");
14037         close_file(pkg);
14038 }
14039
14040 cmdline_parse_inst_t cmd_ddp_get_info = {
14041         .f = cmd_ddp_info_parsed,
14042         .data = NULL,
14043         .help_str = "ddp get info <profile_path>",
14044         .tokens = {
14045                 (void *)&cmd_ddp_info_ddp,
14046                 (void *)&cmd_ddp_info_get,
14047                 (void *)&cmd_ddp_info_info,
14048                 (void *)&cmd_ddp_info_filepath,
14049                 NULL,
14050         },
14051 };
14052
14053 /* Get dynamic device personalization profile info list*/
14054 #define PROFILE_INFO_SIZE 48
14055 #define MAX_PROFILE_NUM 16
14056
14057 struct cmd_ddp_get_list_result {
14058         cmdline_fixed_string_t ddp;
14059         cmdline_fixed_string_t get;
14060         cmdline_fixed_string_t list;
14061         portid_t port_id;
14062 };
14063
14064 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14065         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14066 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14067         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14068 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14069         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14070 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14071         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14072                 RTE_UINT16);
14073
14074 static void
14075 cmd_ddp_get_list_parsed(
14076         __rte_unused void *parsed_result,
14077         __rte_unused struct cmdline *cl,
14078         __rte_unused void *data)
14079 {
14080 #ifdef RTE_NET_I40E
14081         struct cmd_ddp_get_list_result *res = parsed_result;
14082         struct rte_pmd_i40e_profile_list *p_list;
14083         struct rte_pmd_i40e_profile_info *p_info;
14084         uint32_t p_num;
14085         uint32_t size;
14086         uint32_t i;
14087 #endif
14088         int ret = -ENOTSUP;
14089
14090 #ifdef RTE_NET_I40E
14091         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14092         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14093         if (!p_list) {
14094                 printf("%s: Failed to malloc buffer\n", __func__);
14095                 return;
14096         }
14097
14098         if (ret == -ENOTSUP)
14099                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14100                                                 (uint8_t *)p_list, size);
14101
14102         if (!ret) {
14103                 p_num = p_list->p_count;
14104                 printf("Profile number is: %d\n\n", p_num);
14105
14106                 for (i = 0; i < p_num; i++) {
14107                         p_info = &p_list->p_info[i];
14108                         printf("Profile %d:\n", i);
14109                         printf("Track id:     0x%x\n", p_info->track_id);
14110                         printf("Version:      %d.%d.%d.%d\n",
14111                                p_info->version.major,
14112                                p_info->version.minor,
14113                                p_info->version.update,
14114                                p_info->version.draft);
14115                         printf("Profile name: %s\n\n", p_info->name);
14116                 }
14117         }
14118
14119         free(p_list);
14120 #endif
14121
14122         if (ret < 0)
14123                 printf("Failed to get ddp list\n");
14124 }
14125
14126 cmdline_parse_inst_t cmd_ddp_get_list = {
14127         .f = cmd_ddp_get_list_parsed,
14128         .data = NULL,
14129         .help_str = "ddp get list <port_id>",
14130         .tokens = {
14131                 (void *)&cmd_ddp_get_list_ddp,
14132                 (void *)&cmd_ddp_get_list_get,
14133                 (void *)&cmd_ddp_get_list_list,
14134                 (void *)&cmd_ddp_get_list_port_id,
14135                 NULL,
14136         },
14137 };
14138
14139 /* Configure input set */
14140 struct cmd_cfg_input_set_result {
14141         cmdline_fixed_string_t port;
14142         cmdline_fixed_string_t cfg;
14143         portid_t port_id;
14144         cmdline_fixed_string_t pctype;
14145         uint8_t pctype_id;
14146         cmdline_fixed_string_t inset_type;
14147         cmdline_fixed_string_t opt;
14148         cmdline_fixed_string_t field;
14149         uint8_t field_idx;
14150 };
14151
14152 static void
14153 cmd_cfg_input_set_parsed(
14154         __rte_unused void *parsed_result,
14155         __rte_unused struct cmdline *cl,
14156         __rte_unused void *data)
14157 {
14158 #ifdef RTE_NET_I40E
14159         struct cmd_cfg_input_set_result *res = parsed_result;
14160         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14161         struct rte_pmd_i40e_inset inset;
14162 #endif
14163         int ret = -ENOTSUP;
14164
14165         if (!all_ports_stopped()) {
14166                 printf("Please stop all ports first\n");
14167                 return;
14168         }
14169
14170 #ifdef RTE_NET_I40E
14171         if (!strcmp(res->inset_type, "hash_inset"))
14172                 inset_type = INSET_HASH;
14173         else if (!strcmp(res->inset_type, "fdir_inset"))
14174                 inset_type = INSET_FDIR;
14175         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14176                 inset_type = INSET_FDIR_FLX;
14177         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14178                                      &inset, inset_type);
14179         if (ret) {
14180                 printf("Failed to get input set.\n");
14181                 return;
14182         }
14183
14184         if (!strcmp(res->opt, "get")) {
14185                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14186                                                    res->field_idx);
14187                 if (ret)
14188                         printf("Field index %d is enabled.\n", res->field_idx);
14189                 else
14190                         printf("Field index %d is disabled.\n", res->field_idx);
14191                 return;
14192         } else if (!strcmp(res->opt, "set"))
14193                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14194                                                    res->field_idx);
14195         else if (!strcmp(res->opt, "clear"))
14196                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14197                                                      res->field_idx);
14198         if (ret) {
14199                 printf("Failed to configure input set field.\n");
14200                 return;
14201         }
14202
14203         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14204                                      &inset, inset_type);
14205         if (ret) {
14206                 printf("Failed to set input set.\n");
14207                 return;
14208         }
14209 #endif
14210
14211         if (ret == -ENOTSUP)
14212                 printf("Function not supported\n");
14213 }
14214
14215 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14216         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14217                                  port, "port");
14218 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14219         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14220                                  cfg, "config");
14221 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14222         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14223                               port_id, RTE_UINT16);
14224 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14225         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14226                                  pctype, "pctype");
14227 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14228         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14229                               pctype_id, RTE_UINT8);
14230 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14231         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14232                                  inset_type,
14233                                  "hash_inset#fdir_inset#fdir_flx_inset");
14234 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14235         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14236                                  opt, "get#set#clear");
14237 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14238         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14239                                  field, "field");
14240 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14241         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14242                               field_idx, RTE_UINT8);
14243
14244 cmdline_parse_inst_t cmd_cfg_input_set = {
14245         .f = cmd_cfg_input_set_parsed,
14246         .data = NULL,
14247         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14248                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14249         .tokens = {
14250                 (void *)&cmd_cfg_input_set_port,
14251                 (void *)&cmd_cfg_input_set_cfg,
14252                 (void *)&cmd_cfg_input_set_port_id,
14253                 (void *)&cmd_cfg_input_set_pctype,
14254                 (void *)&cmd_cfg_input_set_pctype_id,
14255                 (void *)&cmd_cfg_input_set_inset_type,
14256                 (void *)&cmd_cfg_input_set_opt,
14257                 (void *)&cmd_cfg_input_set_field,
14258                 (void *)&cmd_cfg_input_set_field_idx,
14259                 NULL,
14260         },
14261 };
14262
14263 /* Clear input set */
14264 struct cmd_clear_input_set_result {
14265         cmdline_fixed_string_t port;
14266         cmdline_fixed_string_t cfg;
14267         portid_t port_id;
14268         cmdline_fixed_string_t pctype;
14269         uint8_t pctype_id;
14270         cmdline_fixed_string_t inset_type;
14271         cmdline_fixed_string_t clear;
14272         cmdline_fixed_string_t all;
14273 };
14274
14275 static void
14276 cmd_clear_input_set_parsed(
14277         __rte_unused void *parsed_result,
14278         __rte_unused struct cmdline *cl,
14279         __rte_unused void *data)
14280 {
14281 #ifdef RTE_NET_I40E
14282         struct cmd_clear_input_set_result *res = parsed_result;
14283         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14284         struct rte_pmd_i40e_inset inset;
14285 #endif
14286         int ret = -ENOTSUP;
14287
14288         if (!all_ports_stopped()) {
14289                 printf("Please stop all ports first\n");
14290                 return;
14291         }
14292
14293 #ifdef RTE_NET_I40E
14294         if (!strcmp(res->inset_type, "hash_inset"))
14295                 inset_type = INSET_HASH;
14296         else if (!strcmp(res->inset_type, "fdir_inset"))
14297                 inset_type = INSET_FDIR;
14298         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14299                 inset_type = INSET_FDIR_FLX;
14300
14301         memset(&inset, 0, sizeof(inset));
14302
14303         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14304                                      &inset, inset_type);
14305         if (ret) {
14306                 printf("Failed to clear input set.\n");
14307                 return;
14308         }
14309
14310 #endif
14311
14312         if (ret == -ENOTSUP)
14313                 printf("Function not supported\n");
14314 }
14315
14316 cmdline_parse_token_string_t cmd_clear_input_set_port =
14317         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14318                                  port, "port");
14319 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14320         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14321                                  cfg, "config");
14322 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14323         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14324                               port_id, RTE_UINT16);
14325 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14326         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14327                                  pctype, "pctype");
14328 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14329         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14330                               pctype_id, RTE_UINT8);
14331 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14332         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14333                                  inset_type,
14334                                  "hash_inset#fdir_inset#fdir_flx_inset");
14335 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14336         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14337                                  clear, "clear");
14338 cmdline_parse_token_string_t cmd_clear_input_set_all =
14339         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14340                                  all, "all");
14341
14342 cmdline_parse_inst_t cmd_clear_input_set = {
14343         .f = cmd_clear_input_set_parsed,
14344         .data = NULL,
14345         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14346                     "fdir_inset|fdir_flx_inset clear all",
14347         .tokens = {
14348                 (void *)&cmd_clear_input_set_port,
14349                 (void *)&cmd_clear_input_set_cfg,
14350                 (void *)&cmd_clear_input_set_port_id,
14351                 (void *)&cmd_clear_input_set_pctype,
14352                 (void *)&cmd_clear_input_set_pctype_id,
14353                 (void *)&cmd_clear_input_set_inset_type,
14354                 (void *)&cmd_clear_input_set_clear,
14355                 (void *)&cmd_clear_input_set_all,
14356                 NULL,
14357         },
14358 };
14359
14360 /* show vf stats */
14361
14362 /* Common result structure for show vf stats */
14363 struct cmd_show_vf_stats_result {
14364         cmdline_fixed_string_t show;
14365         cmdline_fixed_string_t vf;
14366         cmdline_fixed_string_t stats;
14367         portid_t port_id;
14368         uint16_t vf_id;
14369 };
14370
14371 /* Common CLI fields show vf stats*/
14372 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14373         TOKEN_STRING_INITIALIZER
14374                 (struct cmd_show_vf_stats_result,
14375                  show, "show");
14376 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14377         TOKEN_STRING_INITIALIZER
14378                 (struct cmd_show_vf_stats_result,
14379                  vf, "vf");
14380 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14381         TOKEN_STRING_INITIALIZER
14382                 (struct cmd_show_vf_stats_result,
14383                  stats, "stats");
14384 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14385         TOKEN_NUM_INITIALIZER
14386                 (struct cmd_show_vf_stats_result,
14387                  port_id, RTE_UINT16);
14388 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14389         TOKEN_NUM_INITIALIZER
14390                 (struct cmd_show_vf_stats_result,
14391                  vf_id, RTE_UINT16);
14392
14393 static void
14394 cmd_show_vf_stats_parsed(
14395         void *parsed_result,
14396         __rte_unused struct cmdline *cl,
14397         __rte_unused void *data)
14398 {
14399         struct cmd_show_vf_stats_result *res = parsed_result;
14400         struct rte_eth_stats stats;
14401         int ret = -ENOTSUP;
14402         static const char *nic_stats_border = "########################";
14403
14404         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14405                 return;
14406
14407         memset(&stats, 0, sizeof(stats));
14408
14409 #ifdef RTE_NET_I40E
14410         if (ret == -ENOTSUP)
14411                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14412                                                 res->vf_id,
14413                                                 &stats);
14414 #endif
14415 #ifdef RTE_NET_BNXT
14416         if (ret == -ENOTSUP)
14417                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14418                                                 res->vf_id,
14419                                                 &stats);
14420 #endif
14421
14422         switch (ret) {
14423         case 0:
14424                 break;
14425         case -EINVAL:
14426                 printf("invalid vf_id %d\n", res->vf_id);
14427                 break;
14428         case -ENODEV:
14429                 printf("invalid port_id %d\n", res->port_id);
14430                 break;
14431         case -ENOTSUP:
14432                 printf("function not implemented\n");
14433                 break;
14434         default:
14435                 printf("programming error: (%s)\n", strerror(-ret));
14436         }
14437
14438         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14439                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14440
14441         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14442                "%-"PRIu64"\n",
14443                stats.ipackets, stats.imissed, stats.ibytes);
14444         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14445         printf("  RX-nombuf:  %-10"PRIu64"\n",
14446                stats.rx_nombuf);
14447         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14448                "%-"PRIu64"\n",
14449                stats.opackets, stats.oerrors, stats.obytes);
14450
14451         printf("  %s############################%s\n",
14452                                nic_stats_border, nic_stats_border);
14453 }
14454
14455 cmdline_parse_inst_t cmd_show_vf_stats = {
14456         .f = cmd_show_vf_stats_parsed,
14457         .data = NULL,
14458         .help_str = "show vf stats <port_id> <vf_id>",
14459         .tokens = {
14460                 (void *)&cmd_show_vf_stats_show,
14461                 (void *)&cmd_show_vf_stats_vf,
14462                 (void *)&cmd_show_vf_stats_stats,
14463                 (void *)&cmd_show_vf_stats_port_id,
14464                 (void *)&cmd_show_vf_stats_vf_id,
14465                 NULL,
14466         },
14467 };
14468
14469 /* clear vf stats */
14470
14471 /* Common result structure for clear vf stats */
14472 struct cmd_clear_vf_stats_result {
14473         cmdline_fixed_string_t clear;
14474         cmdline_fixed_string_t vf;
14475         cmdline_fixed_string_t stats;
14476         portid_t port_id;
14477         uint16_t vf_id;
14478 };
14479
14480 /* Common CLI fields clear vf stats*/
14481 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14482         TOKEN_STRING_INITIALIZER
14483                 (struct cmd_clear_vf_stats_result,
14484                  clear, "clear");
14485 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14486         TOKEN_STRING_INITIALIZER
14487                 (struct cmd_clear_vf_stats_result,
14488                  vf, "vf");
14489 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14490         TOKEN_STRING_INITIALIZER
14491                 (struct cmd_clear_vf_stats_result,
14492                  stats, "stats");
14493 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14494         TOKEN_NUM_INITIALIZER
14495                 (struct cmd_clear_vf_stats_result,
14496                  port_id, RTE_UINT16);
14497 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14498         TOKEN_NUM_INITIALIZER
14499                 (struct cmd_clear_vf_stats_result,
14500                  vf_id, RTE_UINT16);
14501
14502 static void
14503 cmd_clear_vf_stats_parsed(
14504         void *parsed_result,
14505         __rte_unused struct cmdline *cl,
14506         __rte_unused void *data)
14507 {
14508         struct cmd_clear_vf_stats_result *res = parsed_result;
14509         int ret = -ENOTSUP;
14510
14511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14512                 return;
14513
14514 #ifdef RTE_NET_I40E
14515         if (ret == -ENOTSUP)
14516                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14517                                                   res->vf_id);
14518 #endif
14519 #ifdef RTE_NET_BNXT
14520         if (ret == -ENOTSUP)
14521                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14522                                                   res->vf_id);
14523 #endif
14524
14525         switch (ret) {
14526         case 0:
14527                 break;
14528         case -EINVAL:
14529                 printf("invalid vf_id %d\n", res->vf_id);
14530                 break;
14531         case -ENODEV:
14532                 printf("invalid port_id %d\n", res->port_id);
14533                 break;
14534         case -ENOTSUP:
14535                 printf("function not implemented\n");
14536                 break;
14537         default:
14538                 printf("programming error: (%s)\n", strerror(-ret));
14539         }
14540 }
14541
14542 cmdline_parse_inst_t cmd_clear_vf_stats = {
14543         .f = cmd_clear_vf_stats_parsed,
14544         .data = NULL,
14545         .help_str = "clear vf stats <port_id> <vf_id>",
14546         .tokens = {
14547                 (void *)&cmd_clear_vf_stats_clear,
14548                 (void *)&cmd_clear_vf_stats_vf,
14549                 (void *)&cmd_clear_vf_stats_stats,
14550                 (void *)&cmd_clear_vf_stats_port_id,
14551                 (void *)&cmd_clear_vf_stats_vf_id,
14552                 NULL,
14553         },
14554 };
14555
14556 /* port config pctype mapping reset */
14557
14558 /* Common result structure for port config pctype mapping reset */
14559 struct cmd_pctype_mapping_reset_result {
14560         cmdline_fixed_string_t port;
14561         cmdline_fixed_string_t config;
14562         portid_t port_id;
14563         cmdline_fixed_string_t pctype;
14564         cmdline_fixed_string_t mapping;
14565         cmdline_fixed_string_t reset;
14566 };
14567
14568 /* Common CLI fields for port config pctype mapping reset*/
14569 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_pctype_mapping_reset_result,
14572                  port, "port");
14573 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14574         TOKEN_STRING_INITIALIZER
14575                 (struct cmd_pctype_mapping_reset_result,
14576                  config, "config");
14577 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14578         TOKEN_NUM_INITIALIZER
14579                 (struct cmd_pctype_mapping_reset_result,
14580                  port_id, RTE_UINT16);
14581 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14582         TOKEN_STRING_INITIALIZER
14583                 (struct cmd_pctype_mapping_reset_result,
14584                  pctype, "pctype");
14585 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14586         TOKEN_STRING_INITIALIZER
14587                 (struct cmd_pctype_mapping_reset_result,
14588                  mapping, "mapping");
14589 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_pctype_mapping_reset_result,
14592                  reset, "reset");
14593
14594 static void
14595 cmd_pctype_mapping_reset_parsed(
14596         void *parsed_result,
14597         __rte_unused struct cmdline *cl,
14598         __rte_unused void *data)
14599 {
14600         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14601         int ret = -ENOTSUP;
14602
14603         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14604                 return;
14605
14606 #ifdef RTE_NET_I40E
14607         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14608 #endif
14609
14610         switch (ret) {
14611         case 0:
14612                 break;
14613         case -ENODEV:
14614                 printf("invalid port_id %d\n", res->port_id);
14615                 break;
14616         case -ENOTSUP:
14617                 printf("function not implemented\n");
14618                 break;
14619         default:
14620                 printf("programming error: (%s)\n", strerror(-ret));
14621         }
14622 }
14623
14624 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14625         .f = cmd_pctype_mapping_reset_parsed,
14626         .data = NULL,
14627         .help_str = "port config <port_id> pctype mapping reset",
14628         .tokens = {
14629                 (void *)&cmd_pctype_mapping_reset_port,
14630                 (void *)&cmd_pctype_mapping_reset_config,
14631                 (void *)&cmd_pctype_mapping_reset_port_id,
14632                 (void *)&cmd_pctype_mapping_reset_pctype,
14633                 (void *)&cmd_pctype_mapping_reset_mapping,
14634                 (void *)&cmd_pctype_mapping_reset_reset,
14635                 NULL,
14636         },
14637 };
14638
14639 /* show port pctype mapping */
14640
14641 /* Common result structure for show port pctype mapping */
14642 struct cmd_pctype_mapping_get_result {
14643         cmdline_fixed_string_t show;
14644         cmdline_fixed_string_t port;
14645         portid_t port_id;
14646         cmdline_fixed_string_t pctype;
14647         cmdline_fixed_string_t mapping;
14648 };
14649
14650 /* Common CLI fields for pctype mapping get */
14651 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14652         TOKEN_STRING_INITIALIZER
14653                 (struct cmd_pctype_mapping_get_result,
14654                  show, "show");
14655 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14656         TOKEN_STRING_INITIALIZER
14657                 (struct cmd_pctype_mapping_get_result,
14658                  port, "port");
14659 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14660         TOKEN_NUM_INITIALIZER
14661                 (struct cmd_pctype_mapping_get_result,
14662                  port_id, RTE_UINT16);
14663 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14664         TOKEN_STRING_INITIALIZER
14665                 (struct cmd_pctype_mapping_get_result,
14666                  pctype, "pctype");
14667 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14668         TOKEN_STRING_INITIALIZER
14669                 (struct cmd_pctype_mapping_get_result,
14670                  mapping, "mapping");
14671
14672 static void
14673 cmd_pctype_mapping_get_parsed(
14674         void *parsed_result,
14675         __rte_unused struct cmdline *cl,
14676         __rte_unused void *data)
14677 {
14678         struct cmd_pctype_mapping_get_result *res = parsed_result;
14679         int ret = -ENOTSUP;
14680 #ifdef RTE_NET_I40E
14681         struct rte_pmd_i40e_flow_type_mapping
14682                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14683         int i, j, first_pctype;
14684 #endif
14685
14686         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14687                 return;
14688
14689 #ifdef RTE_NET_I40E
14690         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14691 #endif
14692
14693         switch (ret) {
14694         case 0:
14695                 break;
14696         case -ENODEV:
14697                 printf("invalid port_id %d\n", res->port_id);
14698                 return;
14699         case -ENOTSUP:
14700                 printf("function not implemented\n");
14701                 return;
14702         default:
14703                 printf("programming error: (%s)\n", strerror(-ret));
14704                 return;
14705         }
14706
14707 #ifdef RTE_NET_I40E
14708         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14709                 if (mapping[i].pctype != 0ULL) {
14710                         first_pctype = 1;
14711
14712                         printf("pctype: ");
14713                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14714                                 if (mapping[i].pctype & (1ULL << j)) {
14715                                         printf(first_pctype ?
14716                                                "%02d" : ",%02d", j);
14717                                         first_pctype = 0;
14718                                 }
14719                         }
14720                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14721                 }
14722         }
14723 #endif
14724 }
14725
14726 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14727         .f = cmd_pctype_mapping_get_parsed,
14728         .data = NULL,
14729         .help_str = "show port <port_id> pctype mapping",
14730         .tokens = {
14731                 (void *)&cmd_pctype_mapping_get_show,
14732                 (void *)&cmd_pctype_mapping_get_port,
14733                 (void *)&cmd_pctype_mapping_get_port_id,
14734                 (void *)&cmd_pctype_mapping_get_pctype,
14735                 (void *)&cmd_pctype_mapping_get_mapping,
14736                 NULL,
14737         },
14738 };
14739
14740 /* port config pctype mapping update */
14741
14742 /* Common result structure for port config pctype mapping update */
14743 struct cmd_pctype_mapping_update_result {
14744         cmdline_fixed_string_t port;
14745         cmdline_fixed_string_t config;
14746         portid_t port_id;
14747         cmdline_fixed_string_t pctype;
14748         cmdline_fixed_string_t mapping;
14749         cmdline_fixed_string_t update;
14750         cmdline_fixed_string_t pctype_list;
14751         uint16_t flow_type;
14752 };
14753
14754 /* Common CLI fields for pctype mapping update*/
14755 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14756         TOKEN_STRING_INITIALIZER
14757                 (struct cmd_pctype_mapping_update_result,
14758                  port, "port");
14759 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14760         TOKEN_STRING_INITIALIZER
14761                 (struct cmd_pctype_mapping_update_result,
14762                  config, "config");
14763 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14764         TOKEN_NUM_INITIALIZER
14765                 (struct cmd_pctype_mapping_update_result,
14766                  port_id, RTE_UINT16);
14767 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_pctype_mapping_update_result,
14770                  pctype, "pctype");
14771 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_pctype_mapping_update_result,
14774                  mapping, "mapping");
14775 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14776         TOKEN_STRING_INITIALIZER
14777                 (struct cmd_pctype_mapping_update_result,
14778                  update, "update");
14779 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14780         TOKEN_STRING_INITIALIZER
14781                 (struct cmd_pctype_mapping_update_result,
14782                  pctype_list, NULL);
14783 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14784         TOKEN_NUM_INITIALIZER
14785                 (struct cmd_pctype_mapping_update_result,
14786                  flow_type, RTE_UINT16);
14787
14788 static void
14789 cmd_pctype_mapping_update_parsed(
14790         void *parsed_result,
14791         __rte_unused struct cmdline *cl,
14792         __rte_unused void *data)
14793 {
14794         struct cmd_pctype_mapping_update_result *res = parsed_result;
14795         int ret = -ENOTSUP;
14796 #ifdef RTE_NET_I40E
14797         struct rte_pmd_i40e_flow_type_mapping mapping;
14798         unsigned int i;
14799         unsigned int nb_item;
14800         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14801 #endif
14802
14803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14804                 return;
14805
14806 #ifdef RTE_NET_I40E
14807         nb_item = parse_item_list(res->pctype_list, "pctypes",
14808                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14809         mapping.flow_type = res->flow_type;
14810         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14811                 mapping.pctype |= (1ULL << pctype_list[i]);
14812         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14813                                                 &mapping,
14814                                                 1,
14815                                                 0);
14816 #endif
14817
14818         switch (ret) {
14819         case 0:
14820                 break;
14821         case -EINVAL:
14822                 printf("invalid pctype or flow type\n");
14823                 break;
14824         case -ENODEV:
14825                 printf("invalid port_id %d\n", res->port_id);
14826                 break;
14827         case -ENOTSUP:
14828                 printf("function not implemented\n");
14829                 break;
14830         default:
14831                 printf("programming error: (%s)\n", strerror(-ret));
14832         }
14833 }
14834
14835 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14836         .f = cmd_pctype_mapping_update_parsed,
14837         .data = NULL,
14838         .help_str = "port config <port_id> pctype mapping update"
14839         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14840         .tokens = {
14841                 (void *)&cmd_pctype_mapping_update_port,
14842                 (void *)&cmd_pctype_mapping_update_config,
14843                 (void *)&cmd_pctype_mapping_update_port_id,
14844                 (void *)&cmd_pctype_mapping_update_pctype,
14845                 (void *)&cmd_pctype_mapping_update_mapping,
14846                 (void *)&cmd_pctype_mapping_update_update,
14847                 (void *)&cmd_pctype_mapping_update_pc_type,
14848                 (void *)&cmd_pctype_mapping_update_flow_type,
14849                 NULL,
14850         },
14851 };
14852
14853 /* ptype mapping get */
14854
14855 /* Common result structure for ptype mapping get */
14856 struct cmd_ptype_mapping_get_result {
14857         cmdline_fixed_string_t ptype;
14858         cmdline_fixed_string_t mapping;
14859         cmdline_fixed_string_t get;
14860         portid_t port_id;
14861         uint8_t valid_only;
14862 };
14863
14864 /* Common CLI fields for ptype mapping get */
14865 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_ptype_mapping_get_result,
14868                  ptype, "ptype");
14869 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_ptype_mapping_get_result,
14872                  mapping, "mapping");
14873 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14874         TOKEN_STRING_INITIALIZER
14875                 (struct cmd_ptype_mapping_get_result,
14876                  get, "get");
14877 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14878         TOKEN_NUM_INITIALIZER
14879                 (struct cmd_ptype_mapping_get_result,
14880                  port_id, RTE_UINT16);
14881 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14882         TOKEN_NUM_INITIALIZER
14883                 (struct cmd_ptype_mapping_get_result,
14884                  valid_only, RTE_UINT8);
14885
14886 static void
14887 cmd_ptype_mapping_get_parsed(
14888         void *parsed_result,
14889         __rte_unused struct cmdline *cl,
14890         __rte_unused void *data)
14891 {
14892         struct cmd_ptype_mapping_get_result *res = parsed_result;
14893         int ret = -ENOTSUP;
14894 #ifdef RTE_NET_I40E
14895         int max_ptype_num = 256;
14896         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14897         uint16_t count;
14898         int i;
14899 #endif
14900
14901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14902                 return;
14903
14904 #ifdef RTE_NET_I40E
14905         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14906                                         mapping,
14907                                         max_ptype_num,
14908                                         &count,
14909                                         res->valid_only);
14910 #endif
14911
14912         switch (ret) {
14913         case 0:
14914                 break;
14915         case -ENODEV:
14916                 printf("invalid port_id %d\n", res->port_id);
14917                 break;
14918         case -ENOTSUP:
14919                 printf("function not implemented\n");
14920                 break;
14921         default:
14922                 printf("programming error: (%s)\n", strerror(-ret));
14923         }
14924
14925 #ifdef RTE_NET_I40E
14926         if (!ret) {
14927                 for (i = 0; i < count; i++)
14928                         printf("%3d\t0x%08x\n",
14929                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14930         }
14931 #endif
14932 }
14933
14934 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14935         .f = cmd_ptype_mapping_get_parsed,
14936         .data = NULL,
14937         .help_str = "ptype mapping get <port_id> <valid_only>",
14938         .tokens = {
14939                 (void *)&cmd_ptype_mapping_get_ptype,
14940                 (void *)&cmd_ptype_mapping_get_mapping,
14941                 (void *)&cmd_ptype_mapping_get_get,
14942                 (void *)&cmd_ptype_mapping_get_port_id,
14943                 (void *)&cmd_ptype_mapping_get_valid_only,
14944                 NULL,
14945         },
14946 };
14947
14948 /* ptype mapping replace */
14949
14950 /* Common result structure for ptype mapping replace */
14951 struct cmd_ptype_mapping_replace_result {
14952         cmdline_fixed_string_t ptype;
14953         cmdline_fixed_string_t mapping;
14954         cmdline_fixed_string_t replace;
14955         portid_t port_id;
14956         uint32_t target;
14957         uint8_t mask;
14958         uint32_t pkt_type;
14959 };
14960
14961 /* Common CLI fields for ptype mapping replace */
14962 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14963         TOKEN_STRING_INITIALIZER
14964                 (struct cmd_ptype_mapping_replace_result,
14965                  ptype, "ptype");
14966 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14967         TOKEN_STRING_INITIALIZER
14968                 (struct cmd_ptype_mapping_replace_result,
14969                  mapping, "mapping");
14970 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14971         TOKEN_STRING_INITIALIZER
14972                 (struct cmd_ptype_mapping_replace_result,
14973                  replace, "replace");
14974 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14975         TOKEN_NUM_INITIALIZER
14976                 (struct cmd_ptype_mapping_replace_result,
14977                  port_id, RTE_UINT16);
14978 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14979         TOKEN_NUM_INITIALIZER
14980                 (struct cmd_ptype_mapping_replace_result,
14981                  target, RTE_UINT32);
14982 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14983         TOKEN_NUM_INITIALIZER
14984                 (struct cmd_ptype_mapping_replace_result,
14985                  mask, RTE_UINT8);
14986 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14987         TOKEN_NUM_INITIALIZER
14988                 (struct cmd_ptype_mapping_replace_result,
14989                  pkt_type, RTE_UINT32);
14990
14991 static void
14992 cmd_ptype_mapping_replace_parsed(
14993         void *parsed_result,
14994         __rte_unused struct cmdline *cl,
14995         __rte_unused void *data)
14996 {
14997         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14998         int ret = -ENOTSUP;
14999
15000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15001                 return;
15002
15003 #ifdef RTE_NET_I40E
15004         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15005                                         res->target,
15006                                         res->mask,
15007                                         res->pkt_type);
15008 #endif
15009
15010         switch (ret) {
15011         case 0:
15012                 break;
15013         case -EINVAL:
15014                 printf("invalid ptype 0x%8x or 0x%8x\n",
15015                                 res->target, res->pkt_type);
15016                 break;
15017         case -ENODEV:
15018                 printf("invalid port_id %d\n", res->port_id);
15019                 break;
15020         case -ENOTSUP:
15021                 printf("function not implemented\n");
15022                 break;
15023         default:
15024                 printf("programming error: (%s)\n", strerror(-ret));
15025         }
15026 }
15027
15028 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15029         .f = cmd_ptype_mapping_replace_parsed,
15030         .data = NULL,
15031         .help_str =
15032                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15033         .tokens = {
15034                 (void *)&cmd_ptype_mapping_replace_ptype,
15035                 (void *)&cmd_ptype_mapping_replace_mapping,
15036                 (void *)&cmd_ptype_mapping_replace_replace,
15037                 (void *)&cmd_ptype_mapping_replace_port_id,
15038                 (void *)&cmd_ptype_mapping_replace_target,
15039                 (void *)&cmd_ptype_mapping_replace_mask,
15040                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15041                 NULL,
15042         },
15043 };
15044
15045 /* ptype mapping reset */
15046
15047 /* Common result structure for ptype mapping reset */
15048 struct cmd_ptype_mapping_reset_result {
15049         cmdline_fixed_string_t ptype;
15050         cmdline_fixed_string_t mapping;
15051         cmdline_fixed_string_t reset;
15052         portid_t port_id;
15053 };
15054
15055 /* Common CLI fields for ptype mapping reset*/
15056 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15057         TOKEN_STRING_INITIALIZER
15058                 (struct cmd_ptype_mapping_reset_result,
15059                  ptype, "ptype");
15060 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15061         TOKEN_STRING_INITIALIZER
15062                 (struct cmd_ptype_mapping_reset_result,
15063                  mapping, "mapping");
15064 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15065         TOKEN_STRING_INITIALIZER
15066                 (struct cmd_ptype_mapping_reset_result,
15067                  reset, "reset");
15068 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15069         TOKEN_NUM_INITIALIZER
15070                 (struct cmd_ptype_mapping_reset_result,
15071                  port_id, RTE_UINT16);
15072
15073 static void
15074 cmd_ptype_mapping_reset_parsed(
15075         void *parsed_result,
15076         __rte_unused struct cmdline *cl,
15077         __rte_unused void *data)
15078 {
15079         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15080         int ret = -ENOTSUP;
15081
15082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15083                 return;
15084
15085 #ifdef RTE_NET_I40E
15086         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15087 #endif
15088
15089         switch (ret) {
15090         case 0:
15091                 break;
15092         case -ENODEV:
15093                 printf("invalid port_id %d\n", res->port_id);
15094                 break;
15095         case -ENOTSUP:
15096                 printf("function not implemented\n");
15097                 break;
15098         default:
15099                 printf("programming error: (%s)\n", strerror(-ret));
15100         }
15101 }
15102
15103 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15104         .f = cmd_ptype_mapping_reset_parsed,
15105         .data = NULL,
15106         .help_str = "ptype mapping reset <port_id>",
15107         .tokens = {
15108                 (void *)&cmd_ptype_mapping_reset_ptype,
15109                 (void *)&cmd_ptype_mapping_reset_mapping,
15110                 (void *)&cmd_ptype_mapping_reset_reset,
15111                 (void *)&cmd_ptype_mapping_reset_port_id,
15112                 NULL,
15113         },
15114 };
15115
15116 /* ptype mapping update */
15117
15118 /* Common result structure for ptype mapping update */
15119 struct cmd_ptype_mapping_update_result {
15120         cmdline_fixed_string_t ptype;
15121         cmdline_fixed_string_t mapping;
15122         cmdline_fixed_string_t reset;
15123         portid_t port_id;
15124         uint8_t hw_ptype;
15125         uint32_t sw_ptype;
15126 };
15127
15128 /* Common CLI fields for ptype mapping update*/
15129 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15130         TOKEN_STRING_INITIALIZER
15131                 (struct cmd_ptype_mapping_update_result,
15132                  ptype, "ptype");
15133 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15134         TOKEN_STRING_INITIALIZER
15135                 (struct cmd_ptype_mapping_update_result,
15136                  mapping, "mapping");
15137 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15138         TOKEN_STRING_INITIALIZER
15139                 (struct cmd_ptype_mapping_update_result,
15140                  reset, "update");
15141 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15142         TOKEN_NUM_INITIALIZER
15143                 (struct cmd_ptype_mapping_update_result,
15144                  port_id, RTE_UINT16);
15145 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15146         TOKEN_NUM_INITIALIZER
15147                 (struct cmd_ptype_mapping_update_result,
15148                  hw_ptype, RTE_UINT8);
15149 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15150         TOKEN_NUM_INITIALIZER
15151                 (struct cmd_ptype_mapping_update_result,
15152                  sw_ptype, RTE_UINT32);
15153
15154 static void
15155 cmd_ptype_mapping_update_parsed(
15156         void *parsed_result,
15157         __rte_unused struct cmdline *cl,
15158         __rte_unused void *data)
15159 {
15160         struct cmd_ptype_mapping_update_result *res = parsed_result;
15161         int ret = -ENOTSUP;
15162 #ifdef RTE_NET_I40E
15163         struct rte_pmd_i40e_ptype_mapping mapping;
15164 #endif
15165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15166                 return;
15167
15168 #ifdef RTE_NET_I40E
15169         mapping.hw_ptype = res->hw_ptype;
15170         mapping.sw_ptype = res->sw_ptype;
15171         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15172                                                 &mapping,
15173                                                 1,
15174                                                 0);
15175 #endif
15176
15177         switch (ret) {
15178         case 0:
15179                 break;
15180         case -EINVAL:
15181                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15182                 break;
15183         case -ENODEV:
15184                 printf("invalid port_id %d\n", res->port_id);
15185                 break;
15186         case -ENOTSUP:
15187                 printf("function not implemented\n");
15188                 break;
15189         default:
15190                 printf("programming error: (%s)\n", strerror(-ret));
15191         }
15192 }
15193
15194 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15195         .f = cmd_ptype_mapping_update_parsed,
15196         .data = NULL,
15197         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15198         .tokens = {
15199                 (void *)&cmd_ptype_mapping_update_ptype,
15200                 (void *)&cmd_ptype_mapping_update_mapping,
15201                 (void *)&cmd_ptype_mapping_update_update,
15202                 (void *)&cmd_ptype_mapping_update_port_id,
15203                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15204                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15205                 NULL,
15206         },
15207 };
15208
15209 /* Common result structure for file commands */
15210 struct cmd_cmdfile_result {
15211         cmdline_fixed_string_t load;
15212         cmdline_fixed_string_t filename;
15213 };
15214
15215 /* Common CLI fields for file commands */
15216 cmdline_parse_token_string_t cmd_load_cmdfile =
15217         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15218 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15219         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15220
15221 static void
15222 cmd_load_from_file_parsed(
15223         void *parsed_result,
15224         __rte_unused struct cmdline *cl,
15225         __rte_unused void *data)
15226 {
15227         struct cmd_cmdfile_result *res = parsed_result;
15228
15229         cmdline_read_from_file(res->filename);
15230 }
15231
15232 cmdline_parse_inst_t cmd_load_from_file = {
15233         .f = cmd_load_from_file_parsed,
15234         .data = NULL,
15235         .help_str = "load <filename>",
15236         .tokens = {
15237                 (void *)&cmd_load_cmdfile,
15238                 (void *)&cmd_load_cmdfile_filename,
15239                 NULL,
15240         },
15241 };
15242
15243 /* Get Rx offloads capabilities */
15244 struct cmd_rx_offload_get_capa_result {
15245         cmdline_fixed_string_t show;
15246         cmdline_fixed_string_t port;
15247         portid_t port_id;
15248         cmdline_fixed_string_t rx_offload;
15249         cmdline_fixed_string_t capabilities;
15250 };
15251
15252 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15253         TOKEN_STRING_INITIALIZER
15254                 (struct cmd_rx_offload_get_capa_result,
15255                  show, "show");
15256 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15257         TOKEN_STRING_INITIALIZER
15258                 (struct cmd_rx_offload_get_capa_result,
15259                  port, "port");
15260 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15261         TOKEN_NUM_INITIALIZER
15262                 (struct cmd_rx_offload_get_capa_result,
15263                  port_id, RTE_UINT16);
15264 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15265         TOKEN_STRING_INITIALIZER
15266                 (struct cmd_rx_offload_get_capa_result,
15267                  rx_offload, "rx_offload");
15268 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15269         TOKEN_STRING_INITIALIZER
15270                 (struct cmd_rx_offload_get_capa_result,
15271                  capabilities, "capabilities");
15272
15273 static void
15274 print_rx_offloads(uint64_t offloads)
15275 {
15276         uint64_t single_offload;
15277         int begin;
15278         int end;
15279         int bit;
15280
15281         if (offloads == 0)
15282                 return;
15283
15284         begin = __builtin_ctzll(offloads);
15285         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15286
15287         single_offload = 1ULL << begin;
15288         for (bit = begin; bit < end; bit++) {
15289                 if (offloads & single_offload)
15290                         printf(" %s",
15291                                rte_eth_dev_rx_offload_name(single_offload));
15292                 single_offload <<= 1;
15293         }
15294 }
15295
15296 static void
15297 cmd_rx_offload_get_capa_parsed(
15298         void *parsed_result,
15299         __rte_unused struct cmdline *cl,
15300         __rte_unused void *data)
15301 {
15302         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15303         struct rte_eth_dev_info dev_info;
15304         portid_t port_id = res->port_id;
15305         uint64_t queue_offloads;
15306         uint64_t port_offloads;
15307         int ret;
15308
15309         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15310         if (ret != 0)
15311                 return;
15312
15313         queue_offloads = dev_info.rx_queue_offload_capa;
15314         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15315
15316         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15317         printf("  Per Queue :");
15318         print_rx_offloads(queue_offloads);
15319
15320         printf("\n");
15321         printf("  Per Port  :");
15322         print_rx_offloads(port_offloads);
15323         printf("\n\n");
15324 }
15325
15326 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15327         .f = cmd_rx_offload_get_capa_parsed,
15328         .data = NULL,
15329         .help_str = "show port <port_id> rx_offload capabilities",
15330         .tokens = {
15331                 (void *)&cmd_rx_offload_get_capa_show,
15332                 (void *)&cmd_rx_offload_get_capa_port,
15333                 (void *)&cmd_rx_offload_get_capa_port_id,
15334                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15335                 (void *)&cmd_rx_offload_get_capa_capabilities,
15336                 NULL,
15337         }
15338 };
15339
15340 /* Get Rx offloads configuration */
15341 struct cmd_rx_offload_get_configuration_result {
15342         cmdline_fixed_string_t show;
15343         cmdline_fixed_string_t port;
15344         portid_t port_id;
15345         cmdline_fixed_string_t rx_offload;
15346         cmdline_fixed_string_t configuration;
15347 };
15348
15349 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15350         TOKEN_STRING_INITIALIZER
15351                 (struct cmd_rx_offload_get_configuration_result,
15352                  show, "show");
15353 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15354         TOKEN_STRING_INITIALIZER
15355                 (struct cmd_rx_offload_get_configuration_result,
15356                  port, "port");
15357 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15358         TOKEN_NUM_INITIALIZER
15359                 (struct cmd_rx_offload_get_configuration_result,
15360                  port_id, RTE_UINT16);
15361 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15362         TOKEN_STRING_INITIALIZER
15363                 (struct cmd_rx_offload_get_configuration_result,
15364                  rx_offload, "rx_offload");
15365 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15366         TOKEN_STRING_INITIALIZER
15367                 (struct cmd_rx_offload_get_configuration_result,
15368                  configuration, "configuration");
15369
15370 static void
15371 cmd_rx_offload_get_configuration_parsed(
15372         void *parsed_result,
15373         __rte_unused struct cmdline *cl,
15374         __rte_unused void *data)
15375 {
15376         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15377         struct rte_eth_dev_info dev_info;
15378         portid_t port_id = res->port_id;
15379         struct rte_port *port = &ports[port_id];
15380         uint64_t port_offloads;
15381         uint64_t queue_offloads;
15382         uint16_t nb_rx_queues;
15383         int q;
15384         int ret;
15385
15386         printf("Rx Offloading Configuration of port %d :\n", port_id);
15387
15388         port_offloads = port->dev_conf.rxmode.offloads;
15389         printf("  Port :");
15390         print_rx_offloads(port_offloads);
15391         printf("\n");
15392
15393         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15394         if (ret != 0)
15395                 return;
15396
15397         nb_rx_queues = dev_info.nb_rx_queues;
15398         for (q = 0; q < nb_rx_queues; q++) {
15399                 queue_offloads = port->rx_conf[q].offloads;
15400                 printf("  Queue[%2d] :", q);
15401                 print_rx_offloads(queue_offloads);
15402                 printf("\n");
15403         }
15404         printf("\n");
15405 }
15406
15407 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15408         .f = cmd_rx_offload_get_configuration_parsed,
15409         .data = NULL,
15410         .help_str = "show port <port_id> rx_offload configuration",
15411         .tokens = {
15412                 (void *)&cmd_rx_offload_get_configuration_show,
15413                 (void *)&cmd_rx_offload_get_configuration_port,
15414                 (void *)&cmd_rx_offload_get_configuration_port_id,
15415                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15416                 (void *)&cmd_rx_offload_get_configuration_configuration,
15417                 NULL,
15418         }
15419 };
15420
15421 /* Enable/Disable a per port offloading */
15422 struct cmd_config_per_port_rx_offload_result {
15423         cmdline_fixed_string_t port;
15424         cmdline_fixed_string_t config;
15425         portid_t port_id;
15426         cmdline_fixed_string_t rx_offload;
15427         cmdline_fixed_string_t offload;
15428         cmdline_fixed_string_t on_off;
15429 };
15430
15431 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15432         TOKEN_STRING_INITIALIZER
15433                 (struct cmd_config_per_port_rx_offload_result,
15434                  port, "port");
15435 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15436         TOKEN_STRING_INITIALIZER
15437                 (struct cmd_config_per_port_rx_offload_result,
15438                  config, "config");
15439 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15440         TOKEN_NUM_INITIALIZER
15441                 (struct cmd_config_per_port_rx_offload_result,
15442                  port_id, RTE_UINT16);
15443 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15444         TOKEN_STRING_INITIALIZER
15445                 (struct cmd_config_per_port_rx_offload_result,
15446                  rx_offload, "rx_offload");
15447 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15448         TOKEN_STRING_INITIALIZER
15449                 (struct cmd_config_per_port_rx_offload_result,
15450                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15451                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15452                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15453                            "scatter#buffer_split#timestamp#security#"
15454                            "keep_crc#rss_hash");
15455 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15456         TOKEN_STRING_INITIALIZER
15457                 (struct cmd_config_per_port_rx_offload_result,
15458                  on_off, "on#off");
15459
15460 static uint64_t
15461 search_rx_offload(const char *name)
15462 {
15463         uint64_t single_offload;
15464         const char *single_name;
15465         int found = 0;
15466         unsigned int bit;
15467
15468         single_offload = 1;
15469         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15470                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15471                 if (!strcasecmp(single_name, name)) {
15472                         found = 1;
15473                         break;
15474                 }
15475                 single_offload <<= 1;
15476         }
15477
15478         if (found)
15479                 return single_offload;
15480
15481         return 0;
15482 }
15483
15484 static void
15485 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15486                                 __rte_unused struct cmdline *cl,
15487                                 __rte_unused void *data)
15488 {
15489         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15490         portid_t port_id = res->port_id;
15491         struct rte_eth_dev_info dev_info;
15492         struct rte_port *port = &ports[port_id];
15493         uint64_t single_offload;
15494         uint16_t nb_rx_queues;
15495         int q;
15496         int ret;
15497
15498         if (port->port_status != RTE_PORT_STOPPED) {
15499                 printf("Error: Can't config offload when Port %d "
15500                        "is not stopped\n", port_id);
15501                 return;
15502         }
15503
15504         single_offload = search_rx_offload(res->offload);
15505         if (single_offload == 0) {
15506                 printf("Unknown offload name: %s\n", res->offload);
15507                 return;
15508         }
15509
15510         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15511         if (ret != 0)
15512                 return;
15513
15514         nb_rx_queues = dev_info.nb_rx_queues;
15515         if (!strcmp(res->on_off, "on")) {
15516                 port->dev_conf.rxmode.offloads |= single_offload;
15517                 for (q = 0; q < nb_rx_queues; q++)
15518                         port->rx_conf[q].offloads |= single_offload;
15519         } else {
15520                 port->dev_conf.rxmode.offloads &= ~single_offload;
15521                 for (q = 0; q < nb_rx_queues; q++)
15522                         port->rx_conf[q].offloads &= ~single_offload;
15523         }
15524
15525         cmd_reconfig_device_queue(port_id, 1, 1);
15526 }
15527
15528 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15529         .f = cmd_config_per_port_rx_offload_parsed,
15530         .data = NULL,
15531         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15532                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15533                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15534                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15535                     "keep_crc|rss_hash on|off",
15536         .tokens = {
15537                 (void *)&cmd_config_per_port_rx_offload_result_port,
15538                 (void *)&cmd_config_per_port_rx_offload_result_config,
15539                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15540                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15541                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15542                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15543                 NULL,
15544         }
15545 };
15546
15547 /* Enable/Disable a per queue offloading */
15548 struct cmd_config_per_queue_rx_offload_result {
15549         cmdline_fixed_string_t port;
15550         portid_t port_id;
15551         cmdline_fixed_string_t rxq;
15552         uint16_t queue_id;
15553         cmdline_fixed_string_t rx_offload;
15554         cmdline_fixed_string_t offload;
15555         cmdline_fixed_string_t on_off;
15556 };
15557
15558 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15559         TOKEN_STRING_INITIALIZER
15560                 (struct cmd_config_per_queue_rx_offload_result,
15561                  port, "port");
15562 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15563         TOKEN_NUM_INITIALIZER
15564                 (struct cmd_config_per_queue_rx_offload_result,
15565                  port_id, RTE_UINT16);
15566 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15567         TOKEN_STRING_INITIALIZER
15568                 (struct cmd_config_per_queue_rx_offload_result,
15569                  rxq, "rxq");
15570 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15571         TOKEN_NUM_INITIALIZER
15572                 (struct cmd_config_per_queue_rx_offload_result,
15573                  queue_id, RTE_UINT16);
15574 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15575         TOKEN_STRING_INITIALIZER
15576                 (struct cmd_config_per_queue_rx_offload_result,
15577                  rx_offload, "rx_offload");
15578 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15579         TOKEN_STRING_INITIALIZER
15580                 (struct cmd_config_per_queue_rx_offload_result,
15581                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15582                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15583                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15584                            "scatter#buffer_split#timestamp#security#keep_crc");
15585 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15586         TOKEN_STRING_INITIALIZER
15587                 (struct cmd_config_per_queue_rx_offload_result,
15588                  on_off, "on#off");
15589
15590 static void
15591 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15592                                 __rte_unused struct cmdline *cl,
15593                                 __rte_unused void *data)
15594 {
15595         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15596         struct rte_eth_dev_info dev_info;
15597         portid_t port_id = res->port_id;
15598         uint16_t queue_id = res->queue_id;
15599         struct rte_port *port = &ports[port_id];
15600         uint64_t single_offload;
15601         int ret;
15602
15603         if (port->port_status != RTE_PORT_STOPPED) {
15604                 printf("Error: Can't config offload when Port %d "
15605                        "is not stopped\n", port_id);
15606                 return;
15607         }
15608
15609         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15610         if (ret != 0)
15611                 return;
15612
15613         if (queue_id >= dev_info.nb_rx_queues) {
15614                 printf("Error: input queue_id should be 0 ... "
15615                        "%d\n", dev_info.nb_rx_queues - 1);
15616                 return;
15617         }
15618
15619         single_offload = search_rx_offload(res->offload);
15620         if (single_offload == 0) {
15621                 printf("Unknown offload name: %s\n", res->offload);
15622                 return;
15623         }
15624
15625         if (!strcmp(res->on_off, "on"))
15626                 port->rx_conf[queue_id].offloads |= single_offload;
15627         else
15628                 port->rx_conf[queue_id].offloads &= ~single_offload;
15629
15630         cmd_reconfig_device_queue(port_id, 1, 1);
15631 }
15632
15633 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15634         .f = cmd_config_per_queue_rx_offload_parsed,
15635         .data = NULL,
15636         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15637                     "vlan_strip|ipv4_cksum|"
15638                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15639                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15640                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15641                     "keep_crc on|off",
15642         .tokens = {
15643                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15644                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15645                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15646                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15647                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15648                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15649                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15650                 NULL,
15651         }
15652 };
15653
15654 /* Get Tx offloads capabilities */
15655 struct cmd_tx_offload_get_capa_result {
15656         cmdline_fixed_string_t show;
15657         cmdline_fixed_string_t port;
15658         portid_t port_id;
15659         cmdline_fixed_string_t tx_offload;
15660         cmdline_fixed_string_t capabilities;
15661 };
15662
15663 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15664         TOKEN_STRING_INITIALIZER
15665                 (struct cmd_tx_offload_get_capa_result,
15666                  show, "show");
15667 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15668         TOKEN_STRING_INITIALIZER
15669                 (struct cmd_tx_offload_get_capa_result,
15670                  port, "port");
15671 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15672         TOKEN_NUM_INITIALIZER
15673                 (struct cmd_tx_offload_get_capa_result,
15674                  port_id, RTE_UINT16);
15675 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15676         TOKEN_STRING_INITIALIZER
15677                 (struct cmd_tx_offload_get_capa_result,
15678                  tx_offload, "tx_offload");
15679 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15680         TOKEN_STRING_INITIALIZER
15681                 (struct cmd_tx_offload_get_capa_result,
15682                  capabilities, "capabilities");
15683
15684 static void
15685 print_tx_offloads(uint64_t offloads)
15686 {
15687         uint64_t single_offload;
15688         int begin;
15689         int end;
15690         int bit;
15691
15692         if (offloads == 0)
15693                 return;
15694
15695         begin = __builtin_ctzll(offloads);
15696         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15697
15698         single_offload = 1ULL << begin;
15699         for (bit = begin; bit < end; bit++) {
15700                 if (offloads & single_offload)
15701                         printf(" %s",
15702                                rte_eth_dev_tx_offload_name(single_offload));
15703                 single_offload <<= 1;
15704         }
15705 }
15706
15707 static void
15708 cmd_tx_offload_get_capa_parsed(
15709         void *parsed_result,
15710         __rte_unused struct cmdline *cl,
15711         __rte_unused void *data)
15712 {
15713         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15714         struct rte_eth_dev_info dev_info;
15715         portid_t port_id = res->port_id;
15716         uint64_t queue_offloads;
15717         uint64_t port_offloads;
15718         int ret;
15719
15720         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15721         if (ret != 0)
15722                 return;
15723
15724         queue_offloads = dev_info.tx_queue_offload_capa;
15725         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15726
15727         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15728         printf("  Per Queue :");
15729         print_tx_offloads(queue_offloads);
15730
15731         printf("\n");
15732         printf("  Per Port  :");
15733         print_tx_offloads(port_offloads);
15734         printf("\n\n");
15735 }
15736
15737 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15738         .f = cmd_tx_offload_get_capa_parsed,
15739         .data = NULL,
15740         .help_str = "show port <port_id> tx_offload capabilities",
15741         .tokens = {
15742                 (void *)&cmd_tx_offload_get_capa_show,
15743                 (void *)&cmd_tx_offload_get_capa_port,
15744                 (void *)&cmd_tx_offload_get_capa_port_id,
15745                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15746                 (void *)&cmd_tx_offload_get_capa_capabilities,
15747                 NULL,
15748         }
15749 };
15750
15751 /* Get Tx offloads configuration */
15752 struct cmd_tx_offload_get_configuration_result {
15753         cmdline_fixed_string_t show;
15754         cmdline_fixed_string_t port;
15755         portid_t port_id;
15756         cmdline_fixed_string_t tx_offload;
15757         cmdline_fixed_string_t configuration;
15758 };
15759
15760 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15761         TOKEN_STRING_INITIALIZER
15762                 (struct cmd_tx_offload_get_configuration_result,
15763                  show, "show");
15764 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15765         TOKEN_STRING_INITIALIZER
15766                 (struct cmd_tx_offload_get_configuration_result,
15767                  port, "port");
15768 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15769         TOKEN_NUM_INITIALIZER
15770                 (struct cmd_tx_offload_get_configuration_result,
15771                  port_id, RTE_UINT16);
15772 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15773         TOKEN_STRING_INITIALIZER
15774                 (struct cmd_tx_offload_get_configuration_result,
15775                  tx_offload, "tx_offload");
15776 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15777         TOKEN_STRING_INITIALIZER
15778                 (struct cmd_tx_offload_get_configuration_result,
15779                  configuration, "configuration");
15780
15781 static void
15782 cmd_tx_offload_get_configuration_parsed(
15783         void *parsed_result,
15784         __rte_unused struct cmdline *cl,
15785         __rte_unused void *data)
15786 {
15787         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15788         struct rte_eth_dev_info dev_info;
15789         portid_t port_id = res->port_id;
15790         struct rte_port *port = &ports[port_id];
15791         uint64_t port_offloads;
15792         uint64_t queue_offloads;
15793         uint16_t nb_tx_queues;
15794         int q;
15795         int ret;
15796
15797         printf("Tx Offloading Configuration of port %d :\n", port_id);
15798
15799         port_offloads = port->dev_conf.txmode.offloads;
15800         printf("  Port :");
15801         print_tx_offloads(port_offloads);
15802         printf("\n");
15803
15804         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15805         if (ret != 0)
15806                 return;
15807
15808         nb_tx_queues = dev_info.nb_tx_queues;
15809         for (q = 0; q < nb_tx_queues; q++) {
15810                 queue_offloads = port->tx_conf[q].offloads;
15811                 printf("  Queue[%2d] :", q);
15812                 print_tx_offloads(queue_offloads);
15813                 printf("\n");
15814         }
15815         printf("\n");
15816 }
15817
15818 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15819         .f = cmd_tx_offload_get_configuration_parsed,
15820         .data = NULL,
15821         .help_str = "show port <port_id> tx_offload configuration",
15822         .tokens = {
15823                 (void *)&cmd_tx_offload_get_configuration_show,
15824                 (void *)&cmd_tx_offload_get_configuration_port,
15825                 (void *)&cmd_tx_offload_get_configuration_port_id,
15826                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15827                 (void *)&cmd_tx_offload_get_configuration_configuration,
15828                 NULL,
15829         }
15830 };
15831
15832 /* Enable/Disable a per port offloading */
15833 struct cmd_config_per_port_tx_offload_result {
15834         cmdline_fixed_string_t port;
15835         cmdline_fixed_string_t config;
15836         portid_t port_id;
15837         cmdline_fixed_string_t tx_offload;
15838         cmdline_fixed_string_t offload;
15839         cmdline_fixed_string_t on_off;
15840 };
15841
15842 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15843         TOKEN_STRING_INITIALIZER
15844                 (struct cmd_config_per_port_tx_offload_result,
15845                  port, "port");
15846 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15847         TOKEN_STRING_INITIALIZER
15848                 (struct cmd_config_per_port_tx_offload_result,
15849                  config, "config");
15850 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15851         TOKEN_NUM_INITIALIZER
15852                 (struct cmd_config_per_port_tx_offload_result,
15853                  port_id, RTE_UINT16);
15854 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15855         TOKEN_STRING_INITIALIZER
15856                 (struct cmd_config_per_port_tx_offload_result,
15857                  tx_offload, "tx_offload");
15858 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15859         TOKEN_STRING_INITIALIZER
15860                 (struct cmd_config_per_port_tx_offload_result,
15861                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15862                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15863                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15864                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15865                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15866                           "send_on_timestamp");
15867 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15868         TOKEN_STRING_INITIALIZER
15869                 (struct cmd_config_per_port_tx_offload_result,
15870                  on_off, "on#off");
15871
15872 static uint64_t
15873 search_tx_offload(const char *name)
15874 {
15875         uint64_t single_offload;
15876         const char *single_name;
15877         int found = 0;
15878         unsigned int bit;
15879
15880         single_offload = 1;
15881         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15882                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15883                 if (single_name == NULL)
15884                         break;
15885                 if (!strcasecmp(single_name, name)) {
15886                         found = 1;
15887                         break;
15888                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15889                         break;
15890                 single_offload <<= 1;
15891         }
15892
15893         if (found)
15894                 return single_offload;
15895
15896         return 0;
15897 }
15898
15899 static void
15900 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15901                                 __rte_unused struct cmdline *cl,
15902                                 __rte_unused void *data)
15903 {
15904         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15905         portid_t port_id = res->port_id;
15906         struct rte_eth_dev_info dev_info;
15907         struct rte_port *port = &ports[port_id];
15908         uint64_t single_offload;
15909         uint16_t nb_tx_queues;
15910         int q;
15911         int ret;
15912
15913         if (port->port_status != RTE_PORT_STOPPED) {
15914                 printf("Error: Can't config offload when Port %d "
15915                        "is not stopped\n", port_id);
15916                 return;
15917         }
15918
15919         single_offload = search_tx_offload(res->offload);
15920         if (single_offload == 0) {
15921                 printf("Unknown offload name: %s\n", res->offload);
15922                 return;
15923         }
15924
15925         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15926         if (ret != 0)
15927                 return;
15928
15929         nb_tx_queues = dev_info.nb_tx_queues;
15930         if (!strcmp(res->on_off, "on")) {
15931                 port->dev_conf.txmode.offloads |= single_offload;
15932                 for (q = 0; q < nb_tx_queues; q++)
15933                         port->tx_conf[q].offloads |= single_offload;
15934         } else {
15935                 port->dev_conf.txmode.offloads &= ~single_offload;
15936                 for (q = 0; q < nb_tx_queues; q++)
15937                         port->tx_conf[q].offloads &= ~single_offload;
15938         }
15939
15940         cmd_reconfig_device_queue(port_id, 1, 1);
15941 }
15942
15943 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15944         .f = cmd_config_per_port_tx_offload_parsed,
15945         .data = NULL,
15946         .help_str = "port config <port_id> tx_offload "
15947                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15948                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15949                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15950                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15951                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15952                     "send_on_timestamp on|off",
15953         .tokens = {
15954                 (void *)&cmd_config_per_port_tx_offload_result_port,
15955                 (void *)&cmd_config_per_port_tx_offload_result_config,
15956                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15957                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15958                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15959                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15960                 NULL,
15961         }
15962 };
15963
15964 /* Enable/Disable a per queue offloading */
15965 struct cmd_config_per_queue_tx_offload_result {
15966         cmdline_fixed_string_t port;
15967         portid_t port_id;
15968         cmdline_fixed_string_t txq;
15969         uint16_t queue_id;
15970         cmdline_fixed_string_t tx_offload;
15971         cmdline_fixed_string_t offload;
15972         cmdline_fixed_string_t on_off;
15973 };
15974
15975 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15976         TOKEN_STRING_INITIALIZER
15977                 (struct cmd_config_per_queue_tx_offload_result,
15978                  port, "port");
15979 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15980         TOKEN_NUM_INITIALIZER
15981                 (struct cmd_config_per_queue_tx_offload_result,
15982                  port_id, RTE_UINT16);
15983 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15984         TOKEN_STRING_INITIALIZER
15985                 (struct cmd_config_per_queue_tx_offload_result,
15986                  txq, "txq");
15987 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15988         TOKEN_NUM_INITIALIZER
15989                 (struct cmd_config_per_queue_tx_offload_result,
15990                  queue_id, RTE_UINT16);
15991 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15992         TOKEN_STRING_INITIALIZER
15993                 (struct cmd_config_per_queue_tx_offload_result,
15994                  tx_offload, "tx_offload");
15995 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15996         TOKEN_STRING_INITIALIZER
15997                 (struct cmd_config_per_queue_tx_offload_result,
15998                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15999                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16000                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16001                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16002                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16003 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16004         TOKEN_STRING_INITIALIZER
16005                 (struct cmd_config_per_queue_tx_offload_result,
16006                  on_off, "on#off");
16007
16008 static void
16009 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16010                                 __rte_unused struct cmdline *cl,
16011                                 __rte_unused void *data)
16012 {
16013         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16014         struct rte_eth_dev_info dev_info;
16015         portid_t port_id = res->port_id;
16016         uint16_t queue_id = res->queue_id;
16017         struct rte_port *port = &ports[port_id];
16018         uint64_t single_offload;
16019         int ret;
16020
16021         if (port->port_status != RTE_PORT_STOPPED) {
16022                 printf("Error: Can't config offload when Port %d "
16023                        "is not stopped\n", port_id);
16024                 return;
16025         }
16026
16027         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16028         if (ret != 0)
16029                 return;
16030
16031         if (queue_id >= dev_info.nb_tx_queues) {
16032                 printf("Error: input queue_id should be 0 ... "
16033                        "%d\n", dev_info.nb_tx_queues - 1);
16034                 return;
16035         }
16036
16037         single_offload = search_tx_offload(res->offload);
16038         if (single_offload == 0) {
16039                 printf("Unknown offload name: %s\n", res->offload);
16040                 return;
16041         }
16042
16043         if (!strcmp(res->on_off, "on"))
16044                 port->tx_conf[queue_id].offloads |= single_offload;
16045         else
16046                 port->tx_conf[queue_id].offloads &= ~single_offload;
16047
16048         cmd_reconfig_device_queue(port_id, 1, 1);
16049 }
16050
16051 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16052         .f = cmd_config_per_queue_tx_offload_parsed,
16053         .data = NULL,
16054         .help_str = "port <port_id> txq <queue_id> tx_offload "
16055                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16056                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16057                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16058                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16059                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16060                     "on|off",
16061         .tokens = {
16062                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16063                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16064                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16065                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16066                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16067                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16068                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16069                 NULL,
16070         }
16071 };
16072
16073 /* *** configure tx_metadata for specific port *** */
16074 struct cmd_config_tx_metadata_specific_result {
16075         cmdline_fixed_string_t port;
16076         cmdline_fixed_string_t keyword;
16077         uint16_t port_id;
16078         cmdline_fixed_string_t item;
16079         uint32_t value;
16080 };
16081
16082 static void
16083 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16084                                 __rte_unused struct cmdline *cl,
16085                                 __rte_unused void *data)
16086 {
16087         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16088
16089         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16090                 return;
16091         ports[res->port_id].tx_metadata = res->value;
16092         /* Add/remove callback to insert valid metadata in every Tx packet. */
16093         if (ports[res->port_id].tx_metadata)
16094                 add_tx_md_callback(res->port_id);
16095         else
16096                 remove_tx_md_callback(res->port_id);
16097         rte_flow_dynf_metadata_register();
16098 }
16099
16100 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16101         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16102                         port, "port");
16103 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16104         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16105                         keyword, "config");
16106 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16107         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16108                         port_id, RTE_UINT16);
16109 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16110         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16111                         item, "tx_metadata");
16112 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16113         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16114                         value, RTE_UINT32);
16115
16116 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16117         .f = cmd_config_tx_metadata_specific_parsed,
16118         .data = NULL,
16119         .help_str = "port config <port_id> tx_metadata <value>",
16120         .tokens = {
16121                 (void *)&cmd_config_tx_metadata_specific_port,
16122                 (void *)&cmd_config_tx_metadata_specific_keyword,
16123                 (void *)&cmd_config_tx_metadata_specific_id,
16124                 (void *)&cmd_config_tx_metadata_specific_item,
16125                 (void *)&cmd_config_tx_metadata_specific_value,
16126                 NULL,
16127         },
16128 };
16129
16130 /* *** set dynf *** */
16131 struct cmd_config_tx_dynf_specific_result {
16132         cmdline_fixed_string_t port;
16133         cmdline_fixed_string_t keyword;
16134         uint16_t port_id;
16135         cmdline_fixed_string_t item;
16136         cmdline_fixed_string_t name;
16137         cmdline_fixed_string_t value;
16138 };
16139
16140 static void
16141 cmd_config_dynf_specific_parsed(void *parsed_result,
16142                                 __rte_unused struct cmdline *cl,
16143                                 __rte_unused void *data)
16144 {
16145         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16146         struct rte_mbuf_dynflag desc_flag;
16147         int flag;
16148         uint64_t old_port_flags;
16149
16150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16151                 return;
16152         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16153         if (flag <= 0) {
16154                 if (strlcpy(desc_flag.name, res->name,
16155                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16156                         printf("Flag name too long\n");
16157                         return;
16158                 }
16159                 desc_flag.flags = 0;
16160                 flag = rte_mbuf_dynflag_register(&desc_flag);
16161                 if (flag < 0) {
16162                         printf("Can't register flag\n");
16163                         return;
16164                 }
16165                 strcpy(dynf_names[flag], desc_flag.name);
16166         }
16167         old_port_flags = ports[res->port_id].mbuf_dynf;
16168         if (!strcmp(res->value, "set")) {
16169                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16170                 if (old_port_flags == 0)
16171                         add_tx_dynf_callback(res->port_id);
16172         } else {
16173                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16174                 if (ports[res->port_id].mbuf_dynf == 0)
16175                         remove_tx_dynf_callback(res->port_id);
16176         }
16177 }
16178
16179 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16180         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16181                         keyword, "port");
16182 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16183         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16184                         keyword, "config");
16185 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16186         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16187                         port_id, RTE_UINT16);
16188 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16189         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16190                         item, "dynf");
16191 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16192         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16193                         name, NULL);
16194 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16195         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16196                         value, "set#clear");
16197
16198 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16199         .f = cmd_config_dynf_specific_parsed,
16200         .data = NULL,
16201         .help_str = "port config <port id> dynf <name> set|clear",
16202         .tokens = {
16203                 (void *)&cmd_config_tx_dynf_specific_port,
16204                 (void *)&cmd_config_tx_dynf_specific_keyword,
16205                 (void *)&cmd_config_tx_dynf_specific_port_id,
16206                 (void *)&cmd_config_tx_dynf_specific_item,
16207                 (void *)&cmd_config_tx_dynf_specific_name,
16208                 (void *)&cmd_config_tx_dynf_specific_value,
16209                 NULL,
16210         },
16211 };
16212
16213 /* *** display tx_metadata per port configuration *** */
16214 struct cmd_show_tx_metadata_result {
16215         cmdline_fixed_string_t cmd_show;
16216         cmdline_fixed_string_t cmd_port;
16217         cmdline_fixed_string_t cmd_keyword;
16218         portid_t cmd_pid;
16219 };
16220
16221 static void
16222 cmd_show_tx_metadata_parsed(void *parsed_result,
16223                 __rte_unused struct cmdline *cl,
16224                 __rte_unused void *data)
16225 {
16226         struct cmd_show_tx_metadata_result *res = parsed_result;
16227
16228         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16229                 printf("invalid port id %u\n", res->cmd_pid);
16230                 return;
16231         }
16232         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16233                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16234                        ports[res->cmd_pid].tx_metadata);
16235         }
16236 }
16237
16238 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16239         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16240                         cmd_show, "show");
16241 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16242         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16243                         cmd_port, "port");
16244 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16245         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16246                         cmd_pid, RTE_UINT16);
16247 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16248         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16249                         cmd_keyword, "tx_metadata");
16250
16251 cmdline_parse_inst_t cmd_show_tx_metadata = {
16252         .f = cmd_show_tx_metadata_parsed,
16253         .data = NULL,
16254         .help_str = "show port <port_id> tx_metadata",
16255         .tokens = {
16256                 (void *)&cmd_show_tx_metadata_show,
16257                 (void *)&cmd_show_tx_metadata_port,
16258                 (void *)&cmd_show_tx_metadata_pid,
16259                 (void *)&cmd_show_tx_metadata_keyword,
16260                 NULL,
16261         },
16262 };
16263
16264 /* *** show fec capability per port configuration *** */
16265 struct cmd_show_fec_capability_result {
16266         cmdline_fixed_string_t cmd_show;
16267         cmdline_fixed_string_t cmd_port;
16268         cmdline_fixed_string_t cmd_fec;
16269         cmdline_fixed_string_t cmd_keyword;
16270         portid_t cmd_pid;
16271 };
16272
16273 static void
16274 cmd_show_fec_capability_parsed(void *parsed_result,
16275                 __rte_unused struct cmdline *cl,
16276                 __rte_unused void *data)
16277 {
16278         struct cmd_show_fec_capability_result *res = parsed_result;
16279         struct rte_eth_fec_capa *speed_fec_capa;
16280         unsigned int num;
16281         int ret;
16282
16283         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16284                 printf("Invalid port id %u\n", res->cmd_pid);
16285                 return;
16286         }
16287
16288         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16289         if (ret == -ENOTSUP) {
16290                 printf("Function not implemented\n");
16291                 return;
16292         } else if (ret < 0) {
16293                 printf("Get FEC capability failed: %d\n", ret);
16294                 return;
16295         }
16296
16297         num = (unsigned int)ret;
16298         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16299         if (speed_fec_capa == NULL) {
16300                 printf("Failed to alloc FEC capability buffer\n");
16301                 return;
16302         }
16303
16304         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16305         if (ret < 0) {
16306                 printf("Error getting FEC capability: %d\n", ret);
16307                 goto out;
16308         }
16309
16310         show_fec_capability(num, speed_fec_capa);
16311 out:
16312         free(speed_fec_capa);
16313 }
16314
16315 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16316         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16317                         cmd_show, "show");
16318 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16319         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16320                         cmd_port, "port");
16321 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16322         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16323                         cmd_pid, RTE_UINT16);
16324 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16325         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16326                         cmd_fec, "fec");
16327 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16328         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16329                         cmd_keyword, "capabilities");
16330
16331 cmdline_parse_inst_t cmd_show_capability = {
16332         .f = cmd_show_fec_capability_parsed,
16333         .data = NULL,
16334         .help_str = "show port <port_id> fec capabilities",
16335         .tokens = {
16336                 (void *)&cmd_show_fec_capability_show,
16337                 (void *)&cmd_show_fec_capability_port,
16338                 (void *)&cmd_show_fec_capability_pid,
16339                 (void *)&cmd_show_fec_capability_fec,
16340                 (void *)&cmd_show_fec_capability_keyword,
16341                 NULL,
16342         },
16343 };
16344
16345 /* *** show fec mode per port configuration *** */
16346 struct cmd_show_fec_metadata_result {
16347         cmdline_fixed_string_t cmd_show;
16348         cmdline_fixed_string_t cmd_port;
16349         cmdline_fixed_string_t cmd_keyword;
16350         portid_t cmd_pid;
16351 };
16352
16353 static void
16354 cmd_show_fec_mode_parsed(void *parsed_result,
16355                 __rte_unused struct cmdline *cl,
16356                 __rte_unused void *data)
16357 {
16358 #define FEC_NAME_SIZE 16
16359         struct cmd_show_fec_metadata_result *res = parsed_result;
16360         uint32_t mode;
16361         char buf[FEC_NAME_SIZE];
16362         int ret;
16363
16364         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16365                 printf("Invalid port id %u\n", res->cmd_pid);
16366                 return;
16367         }
16368         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16369         if (ret == -ENOTSUP) {
16370                 printf("Function not implemented\n");
16371                 return;
16372         } else if (ret < 0) {
16373                 printf("Get FEC mode failed\n");
16374                 return;
16375         }
16376
16377         switch (mode) {
16378         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16379                 strlcpy(buf, "off", sizeof(buf));
16380                 break;
16381         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16382                 strlcpy(buf, "auto", sizeof(buf));
16383                 break;
16384         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16385                 strlcpy(buf, "baser", sizeof(buf));
16386                 break;
16387         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16388                 strlcpy(buf, "rs", sizeof(buf));
16389                 break;
16390         default:
16391                 return;
16392         }
16393
16394         printf("%s\n", buf);
16395 }
16396
16397 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16398         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16399                         cmd_show, "show");
16400 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16401         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16402                         cmd_port, "port");
16403 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16404         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16405                         cmd_pid, RTE_UINT16);
16406 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16407         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16408                         cmd_keyword, "fec_mode");
16409
16410 cmdline_parse_inst_t cmd_show_fec_mode = {
16411         .f = cmd_show_fec_mode_parsed,
16412         .data = NULL,
16413         .help_str = "show port <port_id> fec_mode",
16414         .tokens = {
16415                 (void *)&cmd_show_fec_mode_show,
16416                 (void *)&cmd_show_fec_mode_port,
16417                 (void *)&cmd_show_fec_mode_pid,
16418                 (void *)&cmd_show_fec_mode_keyword,
16419                 NULL,
16420         },
16421 };
16422
16423 /* *** set fec mode per port configuration *** */
16424 struct cmd_set_port_fec_mode {
16425         cmdline_fixed_string_t set;
16426         cmdline_fixed_string_t port;
16427         portid_t port_id;
16428         cmdline_fixed_string_t fec_mode;
16429         cmdline_fixed_string_t fec_value;
16430 };
16431
16432 /* Common CLI fields for set fec mode */
16433 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16434         TOKEN_STRING_INITIALIZER
16435                 (struct cmd_set_port_fec_mode,
16436                  set, "set");
16437 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16438         TOKEN_STRING_INITIALIZER
16439                 (struct cmd_set_port_fec_mode,
16440                  port, "port");
16441 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16442         TOKEN_NUM_INITIALIZER
16443                 (struct cmd_set_port_fec_mode,
16444                  port_id, RTE_UINT16);
16445 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16446         TOKEN_STRING_INITIALIZER
16447                 (struct cmd_set_port_fec_mode,
16448                  fec_mode, "fec_mode");
16449 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16450         TOKEN_STRING_INITIALIZER
16451                 (struct cmd_set_port_fec_mode,
16452                  fec_value, NULL);
16453
16454 static void
16455 cmd_set_port_fec_mode_parsed(
16456         void *parsed_result,
16457         __rte_unused struct cmdline *cl,
16458         __rte_unused void *data)
16459 {
16460         struct cmd_set_port_fec_mode *res = parsed_result;
16461         uint16_t port_id = res->port_id;
16462         uint32_t mode;
16463         int ret;
16464
16465         ret = parse_fec_mode(res->fec_value, &mode);
16466         if (ret < 0) {
16467                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16468                         port_id);
16469                 return;
16470         }
16471
16472         ret = rte_eth_fec_set(port_id, mode);
16473         if (ret == -ENOTSUP) {
16474                 printf("Function not implemented\n");
16475                 return;
16476         } else if (ret < 0) {
16477                 printf("Set FEC mode failed\n");
16478                 return;
16479         }
16480 }
16481
16482 cmdline_parse_inst_t cmd_set_fec_mode = {
16483         .f = cmd_set_port_fec_mode_parsed,
16484         .data = NULL,
16485         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16486         .tokens = {
16487                 (void *)&cmd_set_port_fec_mode_set,
16488                 (void *)&cmd_set_port_fec_mode_port,
16489                 (void *)&cmd_set_port_fec_mode_port_id,
16490                 (void *)&cmd_set_port_fec_mode_str,
16491                 (void *)&cmd_set_port_fec_mode_value,
16492                 NULL,
16493         },
16494 };
16495
16496 /* show port supported ptypes */
16497
16498 /* Common result structure for show port ptypes */
16499 struct cmd_show_port_supported_ptypes_result {
16500         cmdline_fixed_string_t show;
16501         cmdline_fixed_string_t port;
16502         portid_t port_id;
16503         cmdline_fixed_string_t ptypes;
16504 };
16505
16506 /* Common CLI fields for show port ptypes */
16507 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16508         TOKEN_STRING_INITIALIZER
16509                 (struct cmd_show_port_supported_ptypes_result,
16510                  show, "show");
16511 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16512         TOKEN_STRING_INITIALIZER
16513                 (struct cmd_show_port_supported_ptypes_result,
16514                  port, "port");
16515 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16516         TOKEN_NUM_INITIALIZER
16517                 (struct cmd_show_port_supported_ptypes_result,
16518                  port_id, RTE_UINT16);
16519 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16520         TOKEN_STRING_INITIALIZER
16521                 (struct cmd_show_port_supported_ptypes_result,
16522                  ptypes, "ptypes");
16523
16524 static void
16525 cmd_show_port_supported_ptypes_parsed(
16526         void *parsed_result,
16527         __rte_unused struct cmdline *cl,
16528         __rte_unused void *data)
16529 {
16530 #define RSVD_PTYPE_MASK       0xf0000000
16531 #define MAX_PTYPES_PER_LAYER  16
16532 #define LTYPE_NAMESIZE        32
16533 #define PTYPE_NAMESIZE        256
16534         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16535         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16536         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16537         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16538         uint16_t port_id = res->port_id;
16539         int ret, i;
16540
16541         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16542         if (ret < 0)
16543                 return;
16544
16545         while (ptype_mask != RSVD_PTYPE_MASK) {
16546
16547                 switch (ptype_mask) {
16548                 case RTE_PTYPE_L2_MASK:
16549                         strlcpy(ltype, "L2", sizeof(ltype));
16550                         break;
16551                 case RTE_PTYPE_L3_MASK:
16552                         strlcpy(ltype, "L3", sizeof(ltype));
16553                         break;
16554                 case RTE_PTYPE_L4_MASK:
16555                         strlcpy(ltype, "L4", sizeof(ltype));
16556                         break;
16557                 case RTE_PTYPE_TUNNEL_MASK:
16558                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16559                         break;
16560                 case RTE_PTYPE_INNER_L2_MASK:
16561                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16562                         break;
16563                 case RTE_PTYPE_INNER_L3_MASK:
16564                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16565                         break;
16566                 case RTE_PTYPE_INNER_L4_MASK:
16567                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16568                         break;
16569                 default:
16570                         return;
16571                 }
16572
16573                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16574                                                        ptype_mask, ptypes,
16575                                                        MAX_PTYPES_PER_LAYER);
16576
16577                 if (ret > 0)
16578                         printf("Supported %s ptypes:\n", ltype);
16579                 else
16580                         printf("%s ptypes unsupported\n", ltype);
16581
16582                 for (i = 0; i < ret; ++i) {
16583                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16584                         printf("%s\n", buf);
16585                 }
16586
16587                 ptype_mask <<= 4;
16588         }
16589 }
16590
16591 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16592         .f = cmd_show_port_supported_ptypes_parsed,
16593         .data = NULL,
16594         .help_str = "show port <port_id> ptypes",
16595         .tokens = {
16596                 (void *)&cmd_show_port_supported_ptypes_show,
16597                 (void *)&cmd_show_port_supported_ptypes_port,
16598                 (void *)&cmd_show_port_supported_ptypes_port_id,
16599                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16600                 NULL,
16601         },
16602 };
16603
16604 /* *** display rx/tx descriptor status *** */
16605 struct cmd_show_rx_tx_desc_status_result {
16606         cmdline_fixed_string_t cmd_show;
16607         cmdline_fixed_string_t cmd_port;
16608         cmdline_fixed_string_t cmd_keyword;
16609         cmdline_fixed_string_t cmd_desc;
16610         cmdline_fixed_string_t cmd_status;
16611         portid_t cmd_pid;
16612         portid_t cmd_qid;
16613         portid_t cmd_did;
16614 };
16615
16616 static void
16617 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16618                 __rte_unused struct cmdline *cl,
16619                 __rte_unused void *data)
16620 {
16621         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16622         int rc;
16623
16624         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16625                 printf("invalid port id %u\n", res->cmd_pid);
16626                 return;
16627         }
16628
16629         if (!strcmp(res->cmd_keyword, "rxq")) {
16630                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16631                                              res->cmd_did);
16632                 if (rc < 0) {
16633                         printf("Invalid queueid = %d\n", res->cmd_qid);
16634                         return;
16635                 }
16636                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16637                         printf("Desc status = AVAILABLE\n");
16638                 else if (rc == RTE_ETH_RX_DESC_DONE)
16639                         printf("Desc status = DONE\n");
16640                 else
16641                         printf("Desc status = UNAVAILABLE\n");
16642         } else if (!strcmp(res->cmd_keyword, "txq")) {
16643                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16644                                              res->cmd_did);
16645                 if (rc < 0) {
16646                         printf("Invalid queueid = %d\n", res->cmd_qid);
16647                         return;
16648                 }
16649                 if (rc == RTE_ETH_TX_DESC_FULL)
16650                         printf("Desc status = FULL\n");
16651                 else if (rc == RTE_ETH_TX_DESC_DONE)
16652                         printf("Desc status = DONE\n");
16653                 else
16654                         printf("Desc status = UNAVAILABLE\n");
16655         }
16656 }
16657
16658 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16659         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16660                         cmd_show, "show");
16661 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16662         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16663                         cmd_port, "port");
16664 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16665         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16666                         cmd_pid, RTE_UINT16);
16667 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16668         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16669                         cmd_keyword, "rxq#txq");
16670 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16671         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16672                         cmd_qid, RTE_UINT16);
16673 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16674         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16675                         cmd_desc, "desc");
16676 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16677         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16678                         cmd_did, RTE_UINT16);
16679 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16680         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16681                         cmd_status, "status");
16682 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16683         .f = cmd_show_rx_tx_desc_status_parsed,
16684         .data = NULL,
16685         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16686                 "status",
16687         .tokens = {
16688                 (void *)&cmd_show_rx_tx_desc_status_show,
16689                 (void *)&cmd_show_rx_tx_desc_status_port,
16690                 (void *)&cmd_show_rx_tx_desc_status_pid,
16691                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16692                 (void *)&cmd_show_rx_tx_desc_status_qid,
16693                 (void *)&cmd_show_rx_tx_desc_status_desc,
16694                 (void *)&cmd_show_rx_tx_desc_status_did,
16695                 (void *)&cmd_show_rx_tx_desc_status_status,
16696                 NULL,
16697         },
16698 };
16699
16700 /* Common result structure for set port ptypes */
16701 struct cmd_set_port_ptypes_result {
16702         cmdline_fixed_string_t set;
16703         cmdline_fixed_string_t port;
16704         portid_t port_id;
16705         cmdline_fixed_string_t ptype_mask;
16706         uint32_t mask;
16707 };
16708
16709 /* Common CLI fields for set port ptypes */
16710 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16711         TOKEN_STRING_INITIALIZER
16712                 (struct cmd_set_port_ptypes_result,
16713                  set, "set");
16714 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16715         TOKEN_STRING_INITIALIZER
16716                 (struct cmd_set_port_ptypes_result,
16717                  port, "port");
16718 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16719         TOKEN_NUM_INITIALIZER
16720                 (struct cmd_set_port_ptypes_result,
16721                  port_id, RTE_UINT16);
16722 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16723         TOKEN_STRING_INITIALIZER
16724                 (struct cmd_set_port_ptypes_result,
16725                  ptype_mask, "ptype_mask");
16726 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16727         TOKEN_NUM_INITIALIZER
16728                 (struct cmd_set_port_ptypes_result,
16729                  mask, RTE_UINT32);
16730
16731 static void
16732 cmd_set_port_ptypes_parsed(
16733         void *parsed_result,
16734         __rte_unused struct cmdline *cl,
16735         __rte_unused void *data)
16736 {
16737         struct cmd_set_port_ptypes_result *res = parsed_result;
16738 #define PTYPE_NAMESIZE        256
16739         char ptype_name[PTYPE_NAMESIZE];
16740         uint16_t port_id = res->port_id;
16741         uint32_t ptype_mask = res->mask;
16742         int ret, i;
16743
16744         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16745                                                NULL, 0);
16746         if (ret <= 0) {
16747                 printf("Port %d doesn't support any ptypes.\n", port_id);
16748                 return;
16749         }
16750
16751         uint32_t ptypes[ret];
16752
16753         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16754         if (ret < 0) {
16755                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16756                 return;
16757         }
16758
16759         printf("Successfully set following ptypes for Port %d\n", port_id);
16760         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16761                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16762                 printf("%s\n", ptype_name);
16763         }
16764
16765         clear_ptypes = false;
16766 }
16767
16768 cmdline_parse_inst_t cmd_set_port_ptypes = {
16769         .f = cmd_set_port_ptypes_parsed,
16770         .data = NULL,
16771         .help_str = "set port <port_id> ptype_mask <mask>",
16772         .tokens = {
16773                 (void *)&cmd_set_port_ptypes_set,
16774                 (void *)&cmd_set_port_ptypes_port,
16775                 (void *)&cmd_set_port_ptypes_port_id,
16776                 (void *)&cmd_set_port_ptypes_mask_str,
16777                 (void *)&cmd_set_port_ptypes_mask_u32,
16778                 NULL,
16779         },
16780 };
16781
16782 /* *** display mac addresses added to a port *** */
16783 struct cmd_showport_macs_result {
16784         cmdline_fixed_string_t cmd_show;
16785         cmdline_fixed_string_t cmd_port;
16786         cmdline_fixed_string_t cmd_keyword;
16787         portid_t cmd_pid;
16788 };
16789
16790 static void
16791 cmd_showport_macs_parsed(void *parsed_result,
16792                 __rte_unused struct cmdline *cl,
16793                 __rte_unused void *data)
16794 {
16795         struct cmd_showport_macs_result *res = parsed_result;
16796
16797         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16798                 return;
16799
16800         if (!strcmp(res->cmd_keyword, "macs"))
16801                 show_macs(res->cmd_pid);
16802         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16803                 show_mcast_macs(res->cmd_pid);
16804 }
16805
16806 cmdline_parse_token_string_t cmd_showport_macs_show =
16807         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16808                         cmd_show, "show");
16809 cmdline_parse_token_string_t cmd_showport_macs_port =
16810         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16811                         cmd_port, "port");
16812 cmdline_parse_token_num_t cmd_showport_macs_pid =
16813         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16814                         cmd_pid, RTE_UINT16);
16815 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16816         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16817                         cmd_keyword, "macs#mcast_macs");
16818
16819 cmdline_parse_inst_t cmd_showport_macs = {
16820         .f = cmd_showport_macs_parsed,
16821         .data = NULL,
16822         .help_str = "show port <port_id> macs|mcast_macs",
16823         .tokens = {
16824                 (void *)&cmd_showport_macs_show,
16825                 (void *)&cmd_showport_macs_port,
16826                 (void *)&cmd_showport_macs_pid,
16827                 (void *)&cmd_showport_macs_keyword,
16828                 NULL,
16829         },
16830 };
16831
16832 /* ******************************************************************************** */
16833
16834 /* list of instructions */
16835 cmdline_parse_ctx_t main_ctx[] = {
16836         (cmdline_parse_inst_t *)&cmd_help_brief,
16837         (cmdline_parse_inst_t *)&cmd_help_long,
16838         (cmdline_parse_inst_t *)&cmd_quit,
16839         (cmdline_parse_inst_t *)&cmd_load_from_file,
16840         (cmdline_parse_inst_t *)&cmd_showport,
16841         (cmdline_parse_inst_t *)&cmd_showqueue,
16842         (cmdline_parse_inst_t *)&cmd_showeeprom,
16843         (cmdline_parse_inst_t *)&cmd_showportall,
16844         (cmdline_parse_inst_t *)&cmd_showdevice,
16845         (cmdline_parse_inst_t *)&cmd_showcfg,
16846         (cmdline_parse_inst_t *)&cmd_showfwdall,
16847         (cmdline_parse_inst_t *)&cmd_start,
16848         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16849         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16850         (cmdline_parse_inst_t *)&cmd_set_link_up,
16851         (cmdline_parse_inst_t *)&cmd_set_link_down,
16852         (cmdline_parse_inst_t *)&cmd_reset,
16853         (cmdline_parse_inst_t *)&cmd_set_numbers,
16854         (cmdline_parse_inst_t *)&cmd_set_log,
16855         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16856         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16857         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16858         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16859         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16860         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16861         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16862         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16863         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16864         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16865         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16866         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16867         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16868         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16869         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16870         (cmdline_parse_inst_t *)&cmd_set_link_check,
16871         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16872         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16873         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16874         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16875 #ifdef RTE_NET_BOND
16876         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16877         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16878         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16879         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16880         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16881         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16882         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16883         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16884         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16885         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16886         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16887 #endif
16888         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16889         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16890         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16891         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16892         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16893         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16894         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16895         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16896         (cmdline_parse_inst_t *)&cmd_csum_set,
16897         (cmdline_parse_inst_t *)&cmd_csum_show,
16898         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16899         (cmdline_parse_inst_t *)&cmd_tso_set,
16900         (cmdline_parse_inst_t *)&cmd_tso_show,
16901         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16902         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16903         (cmdline_parse_inst_t *)&cmd_gro_enable,
16904         (cmdline_parse_inst_t *)&cmd_gro_flush,
16905         (cmdline_parse_inst_t *)&cmd_gro_show,
16906         (cmdline_parse_inst_t *)&cmd_gso_enable,
16907         (cmdline_parse_inst_t *)&cmd_gso_size,
16908         (cmdline_parse_inst_t *)&cmd_gso_show,
16909         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16910         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16911         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16912         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16913         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16914         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16915         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16916         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16917         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16918         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16919         (cmdline_parse_inst_t *)&cmd_config_dcb,
16920         (cmdline_parse_inst_t *)&cmd_read_reg,
16921         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16922         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16923         (cmdline_parse_inst_t *)&cmd_write_reg,
16924         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16925         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16926         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16927         (cmdline_parse_inst_t *)&cmd_stop,
16928         (cmdline_parse_inst_t *)&cmd_mac_addr,
16929         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16930         (cmdline_parse_inst_t *)&cmd_set_qmap,
16931         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16932         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
16933         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
16934         (cmdline_parse_inst_t *)&cmd_operate_port,
16935         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16936         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16937         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16938         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
16939         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
16940         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16941         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16942         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16943         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16944         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16945         (cmdline_parse_inst_t *)&cmd_config_mtu,
16946         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16947         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
16948         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16949         (cmdline_parse_inst_t *)&cmd_config_rss,
16950         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16951         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16952         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
16953         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16954         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16955         (cmdline_parse_inst_t *)&cmd_showport_reta,
16956         (cmdline_parse_inst_t *)&cmd_showport_macs,
16957         (cmdline_parse_inst_t *)&cmd_config_burst,
16958         (cmdline_parse_inst_t *)&cmd_config_thresh,
16959         (cmdline_parse_inst_t *)&cmd_config_threshold,
16960         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16961         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16962         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16963         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16964         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16965         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16966         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16967         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16968         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16969         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16970         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16971         (cmdline_parse_inst_t *)&cmd_dump,
16972         (cmdline_parse_inst_t *)&cmd_dump_one,
16973 #ifdef RTE_NET_I40E
16974         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16975 #endif
16976         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16977         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16978         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16979         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16980         (cmdline_parse_inst_t *)&cmd_flow,
16981         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16982         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16983         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16984         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16985         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16986         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16987         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16988         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16989         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16990         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16991         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16992         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16993         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16994         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16995         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16996         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16997         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16998         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16999         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17000         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17001         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17002         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17003         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17004         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17005         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17006         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17007         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17008         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17009         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17010         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17011         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17012         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17013         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17014         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17015         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17016         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17017         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17018         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17019         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17020         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17021         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17022         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17023         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17024         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17025         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17026         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17027         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17028         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17029         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17030         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17031         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17032         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17033         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17034         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17035         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17036         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17037         (cmdline_parse_inst_t *)&cmd_ddp_add,
17038         (cmdline_parse_inst_t *)&cmd_ddp_del,
17039         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17040         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17041         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17042         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17043         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17044         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17045         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17046         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17047         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17048         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17049         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17050         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17051
17052         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17053         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17054         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17055         (cmdline_parse_inst_t *)&cmd_queue_region,
17056         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17057         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17058         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17059         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17060         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17061         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17062         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17063         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17064         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17065         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17066         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17067         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17068         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17069         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17070         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17071         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17072         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17073         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17074         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17075         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17076         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17077         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17078         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17079         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17080         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17081         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17082         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17083         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17084         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17085         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17086         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17087         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17088         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17089         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17090         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17091         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17092 #ifdef RTE_LIB_BPF
17093         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17094         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17095 #endif
17096         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17097         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17098         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17099         (cmdline_parse_inst_t *)&cmd_set_raw,
17100         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17101         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17102         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17103         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17104         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17105         (cmdline_parse_inst_t *)&cmd_show_capability,
17106         NULL,
17107 };
17108
17109 /* read cmdline commands from file */
17110 void
17111 cmdline_read_from_file(const char *filename)
17112 {
17113         struct cmdline *cl;
17114
17115         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17116         if (cl == NULL) {
17117                 printf("Failed to create file based cmdline context: %s\n",
17118                        filename);
17119                 return;
17120         }
17121
17122         cmdline_interact(cl);
17123         cmdline_quit(cl);
17124
17125         cmdline_free(cl);
17126
17127         printf("Read CLI commands from %s\n", filename);
17128 }
17129
17130 /* prompt function, called from main on MAIN lcore */
17131 void
17132 prompt(void)
17133 {
17134         int ret;
17135         /* initialize non-constant commands */
17136         cmd_set_fwd_mode_init();
17137         cmd_set_fwd_retry_mode_init();
17138
17139         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17140         if (testpmd_cl == NULL)
17141                 return;
17142
17143         ret = atexit(prompt_exit);
17144         if (ret != 0)
17145                 printf("Cannot set exit function for cmdline\n");
17146
17147         cmdline_interact(testpmd_cl);
17148         if (ret != 0)
17149                 cmdline_stdin_exit(testpmd_cl);
17150 }
17151
17152 void
17153 prompt_exit(void)
17154 {
17155         if (testpmd_cl != NULL) {
17156                 cmdline_quit(testpmd_cl);
17157                 cmdline_stdin_exit(testpmd_cl);
17158         }
17159 }
17160
17161 static void
17162 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17163 {
17164         if (id == (portid_t)RTE_PORT_ALL) {
17165                 portid_t pid;
17166
17167                 RTE_ETH_FOREACH_DEV(pid) {
17168                         /* check if need_reconfig has been set to 1 */
17169                         if (ports[pid].need_reconfig == 0)
17170                                 ports[pid].need_reconfig = dev;
17171                         /* check if need_reconfig_queues has been set to 1 */
17172                         if (ports[pid].need_reconfig_queues == 0)
17173                                 ports[pid].need_reconfig_queues = queue;
17174                 }
17175         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17176                 /* check if need_reconfig has been set to 1 */
17177                 if (ports[id].need_reconfig == 0)
17178                         ports[id].need_reconfig = dev;
17179                 /* check if need_reconfig_queues has been set to 1 */
17180                 if (ports[id].need_reconfig_queues == 0)
17181                         ports[id].need_reconfig_queues = queue;
17182         }
17183 }