ethdev: add eCPRI RSS offload type
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         "    outer-udp concerns the outer UDP layer in"
435                         " case the packet is recognized as a tunnel packet by"
436                         " the forward engine (vxlan, gre and ipip are supported)\n"
437                         "    Please check the NIC datasheet for HW limits.\n\n"
438
439                         "csum parse-tunnel (on|off) (tx_port_id)\n"
440                         "    If disabled, treat tunnel packets as non-tunneled"
441                         " packets (treat inner headers as payload). The port\n"
442                         "    argument is the port used for TX in csum forward"
443                         " engine.\n\n"
444
445                         "csum show (port_id)\n"
446                         "    Display tx checksum offload configuration\n\n"
447
448                         "tso set (segsize) (portid)\n"
449                         "    Enable TCP Segmentation Offload in csum forward"
450                         " engine.\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "tso show (portid)"
454                         "    Display the status of TCP Segmentation Offload.\n\n"
455
456                         "set port (port_id) gro on|off\n"
457                         "    Enable or disable Generic Receive Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "show port (port_id) gro\n"
461                         "    Display GRO configuration.\n\n"
462
463                         "set gro flush (cycles)\n"
464                         "    Set the cycle to flush GROed packets from"
465                         " reassembly tables.\n\n"
466
467                         "set port (port_id) gso (on|off)"
468                         "    Enable or disable Generic Segmentation Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "set gso segsz (length)\n"
472                         "    Set max packet length for output GSO segments,"
473                         " including packet header and payload.\n\n"
474
475                         "show port (port_id) gso\n"
476                         "    Show GSO configuration.\n\n"
477
478                         "set fwd (%s)\n"
479                         "    Set packet forwarding mode.\n\n"
480
481                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
482                         "    Add a MAC address on port_id.\n\n"
483
484                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Remove a MAC address from port_id.\n\n"
486
487                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Set the default MAC address for port_id.\n\n"
489
490                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
491                         "    Add a MAC address for a VF on the port.\n\n"
492
493                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the MAC address for a VF from the PF.\n\n"
495
496                         "set eth-peer (port_id) (peer_addr)\n"
497                         "    set the peer address for certain port.\n\n"
498
499                         "set port (port_id) uta (mac_address|all) (on|off)\n"
500                         "    Add/Remove a or all unicast hash filter(s)"
501                         "from port X.\n\n"
502
503                         "set promisc (port_id|all) (on|off)\n"
504                         "    Set the promiscuous mode on port_id, or all.\n\n"
505
506                         "set allmulti (port_id|all) (on|off)\n"
507                         "    Set the allmulti mode on port_id, or all.\n\n"
508
509                         "set vf promisc (port_id) (vf_id) (on|off)\n"
510                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
511
512                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
513                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
517                         " (on|off) autoneg (on|off) (port_id)\n"
518                         "set flow_ctrl rx (on|off) (portid)\n"
519                         "set flow_ctrl tx (on|off) (portid)\n"
520                         "set flow_ctrl high_water (high_water) (portid)\n"
521                         "set flow_ctrl low_water (low_water) (portid)\n"
522                         "set flow_ctrl pause_time (pause_time) (portid)\n"
523                         "set flow_ctrl send_xon (send_xon) (portid)\n"
524                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
525                         "set flow_ctrl autoneg (on|off) (port_id)\n"
526                         "    Set the link flow control parameter on a port.\n\n"
527
528                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
529                         " (low_water) (pause_time) (priority) (port_id)\n"
530                         "    Set the priority flow control parameter on a"
531                         " port.\n\n"
532
533                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
534                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
535                         " queue on port.\n"
536                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
537                         " on port 0 to mapping 5.\n\n"
538
539                         "set xstats-hide-zero on|off\n"
540                         "    Set the option to hide the zero values"
541                         " for xstats display.\n"
542
543                         "set record-core-cycles on|off\n"
544                         "    Set the option to enable measurement of CPU cycles.\n"
545
546                         "set record-burst-stats on|off\n"
547                         "    Set the option to enable display of RX and TX bursts.\n"
548
549                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
550                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
553                         "|MPE) (on|off)\n"
554                         "    AUPE:accepts untagged VLAN;"
555                         "ROPE:accept unicast hash\n\n"
556                         "    BAM:accepts broadcast packets;"
557                         "MPE:accepts all multicast packets\n\n"
558                         "    Enable/Disable a VF receive mode of a port\n\n"
559
560                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
561                         "    Set rate limit for a queue of a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rate (rate_num) "
564                         "queue_mask (queue_mask_value)\n"
565                         "    Set rate limit for queues in VF of a port\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
569                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
570                         "   Set pool or vlan type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
572                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
573                         " to pool 0.\n\n"
574
575                         "set port (port_id) mirror-rule (rule_id)"
576                         " (uplink-mirror|downlink-mirror) dst-pool"
577                         " (pool_id) (on|off)\n"
578                         "   Set uplink or downlink type mirror rule on a port.\n"
579                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
580                         " 0 on' enable mirror income traffic to pool 0.\n\n"
581
582                         "reset port (port_id) mirror-rule (rule_id)\n"
583                         "   Reset a mirror rule.\n\n"
584
585                         "set flush_rx (on|off)\n"
586                         "   Flush (default) or don't flush RX streams before"
587                         " forwarding. Mainly used with PCAP drivers.\n\n"
588
589                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the bypass mode for the lowest port on bypass enabled"
591                         " NIC.\n\n"
592
593                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
594                         "mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the event required to initiate specified bypass mode for"
596                         " the lowest port on a bypass enabled NIC where:\n"
597                         "       timeout   = enable bypass after watchdog timeout.\n"
598                         "       os_on     = enable bypass when OS/board is powered on.\n"
599                         "       os_off    = enable bypass when OS/board is powered off.\n"
600                         "       power_on  = enable bypass when power supply is turned on.\n"
601                         "       power_off = enable bypass when power supply is turned off."
602                         "\n\n"
603
604                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
605                         "   Set the bypass watchdog timeout to 'n' seconds"
606                         " where 0 = instant.\n\n"
607
608                         "show bypass config (port_id)\n"
609                         "   Show the bypass configuration for a bypass enabled NIC"
610                         " using the lowest port on the NIC.\n\n"
611
612 #ifdef RTE_NET_BOND
613                         "create bonded device (mode) (socket)\n"
614                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
615
616                         "add bonding slave (slave_id) (port_id)\n"
617                         "       Add a slave device to a bonded device.\n\n"
618
619                         "remove bonding slave (slave_id) (port_id)\n"
620                         "       Remove a slave device from a bonded device.\n\n"
621
622                         "set bonding mode (value) (port_id)\n"
623                         "       Set the bonding mode on a bonded device.\n\n"
624
625                         "set bonding primary (slave_id) (port_id)\n"
626                         "       Set the primary slave for a bonded device.\n\n"
627
628                         "show bonding config (port_id)\n"
629                         "       Show the bonding config for port_id.\n\n"
630
631                         "set bonding mac_addr (port_id) (address)\n"
632                         "       Set the MAC address of a bonded device.\n\n"
633
634                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
635                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
636
637                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
638                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
639
640                         "set bonding mon_period (port_id) (value)\n"
641                         "       Set the bonding link status monitoring polling period in ms.\n\n"
642
643                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
644                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
645
646 #endif
647                         "set link-up port (port_id)\n"
648                         "       Set link up for a port.\n\n"
649
650                         "set link-down port (port_id)\n"
651                         "       Set link down for a port.\n\n"
652
653                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) ptype_mask (ptype_mask)\n"
672                         "    set packet types classification for a specific port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         "set port (port_id) fec_mode auto|off|rs|baser\n"
737                         "    set fec mode for a specific port\n\n"
738
739                         , list_pkt_forwarding_modes()
740                 );
741         }
742
743         if (show_all || !strcmp(res->section, "ports")) {
744
745                 cmdline_printf(
746                         cl,
747                         "\n"
748                         "Port Operations:\n"
749                         "----------------\n\n"
750
751                         "port start (port_id|all)\n"
752                         "    Start all ports or port_id.\n\n"
753
754                         "port stop (port_id|all)\n"
755                         "    Stop all ports or port_id.\n\n"
756
757                         "port close (port_id|all)\n"
758                         "    Close all ports or port_id.\n\n"
759
760                         "port reset (port_id|all)\n"
761                         "    Reset all ports or port_id.\n\n"
762
763                         "port attach (ident)\n"
764                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
765
766                         "port detach (port_id)\n"
767                         "    Detach physical or virtual dev by port_id\n\n"
768
769                         "port config (port_id|all)"
770                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
771                         " duplex (half|full|auto)\n"
772                         "    Set speed and duplex for all ports or port_id\n\n"
773
774                         "port config (port_id|all) loopback (mode)\n"
775                         "    Set loopback mode for all ports or port_id\n\n"
776
777                         "port config all (rxq|txq|rxd|txd) (value)\n"
778                         "    Set number for rxq/txq/rxd/txd.\n\n"
779
780                         "port config all max-pkt-len (value)\n"
781                         "    Set the max packet length.\n\n"
782
783                         "port config all max-lro-pkt-size (value)\n"
784                         "    Set the max LRO aggregated packet size.\n\n"
785
786                         "port config all drop-en (on|off)\n"
787                         "    Enable or disable packet drop on all RX queues of all ports when no "
788                         "receive buffers available.\n\n"
789
790                         "port config all rss (all|default|ip|tcp|udp|sctp|"
791                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|none|level-default|"
792                         "level-outer|level-inner|<flowtype_id>)\n"
793                         "    Set the RSS mode.\n\n"
794
795                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
796                         "    Set the RSS redirection table.\n\n"
797
798                         "port config (port_id) dcb vt (on|off) (traffic_class)"
799                         " pfc (on|off)\n"
800                         "    Set the DCB mode.\n\n"
801
802                         "port config all burst (value)\n"
803                         "    Set the number of packets per burst.\n\n"
804
805                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
806                         " (value)\n"
807                         "    Set the ring prefetch/host/writeback threshold"
808                         " for tx/rx queue.\n\n"
809
810                         "port config all (txfreet|txrst|rxfreet) (value)\n"
811                         "    Set free threshold for rx/tx, or set"
812                         " tx rs bit threshold.\n\n"
813                         "port config mtu X value\n"
814                         "    Set the MTU of port X to a given value\n\n"
815
816                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
817                         "    Set a rx/tx queue's ring size configuration, the new"
818                         " value will take effect after command that (re-)start the port"
819                         " or command that setup the specific queue\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
822                         "    Start/stop a rx/tx queue of port X. Only take effect"
823                         " when port X is started\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
826                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
827                         " take effect when port X is stopped.\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) setup\n"
830                         "    Setup a rx/tx queue of port X.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
855                         "buffer_split|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
863                         "buffer_split|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896
897                         "port config (port_id) dynf (name) set|clear\n"
898                         "    Register a dynf and Set/clear this flag on Tx. "
899                         "Testpmd will set this value to any Tx packet "
900                         "sent from this port\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940 #ifdef RTE_NET_I40E
941                         "flow_director_filter (port_id) mode raw (add|del|update)"
942                         " flow (flow_id) (drop|fwd) queue (queue_id)"
943                         " fd_id (fd_id_value) packet (packet file name)\n"
944                         "    Add/Del a raw type flow director filter.\n\n"
945 #endif
946
947                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
948                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
949                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
950                         "    Set flow director IP mask.\n\n"
951
952                         "flow_director_mask (port_id) mode MAC-VLAN"
953                         " vlan (vlan_value)\n"
954                         "    Set flow director MAC-VLAN mask.\n\n"
955
956                         "flow_director_mask (port_id) mode Tunnel"
957                         " vlan (vlan_value) mac (mac_value)"
958                         " tunnel-type (tunnel_type_value)"
959                         " tunnel-id (tunnel_id_value)\n"
960                         "    Set flow director Tunnel mask.\n\n"
961
962                         "flow_director_flex_payload (port_id)"
963                         " (raw|l2|l3|l4) (config)\n"
964                         "    Configure flex payload selection.\n\n"
965
966                         "flow validate {port_id}"
967                         " [group {group_id}] [priority {level}]"
968                         " [ingress] [egress]"
969                         " pattern {item} [/ {item} [...]] / end"
970                         " actions {action} [/ {action} [...]] / end\n"
971                         "    Check whether a flow rule can be created.\n\n"
972
973                         "flow create {port_id}"
974                         " [group {group_id}] [priority {level}]"
975                         " [ingress] [egress]"
976                         " pattern {item} [/ {item} [...]] / end"
977                         " actions {action} [/ {action} [...]] / end\n"
978                         "    Create a flow rule.\n\n"
979
980                         "flow destroy {port_id} rule {rule_id} [...]\n"
981                         "    Destroy specific flow rules.\n\n"
982
983                         "flow flush {port_id}\n"
984                         "    Destroy all flow rules.\n\n"
985
986                         "flow query {port_id} {rule_id} {action}\n"
987                         "    Query an existing flow rule.\n\n"
988
989                         "flow list {port_id} [group {group_id}] [...]\n"
990                         "    List existing flow rules sorted by priority,"
991                         " filtered by group identifiers.\n\n"
992
993                         "flow isolate {port_id} {boolean}\n"
994                         "    Restrict ingress traffic to the defined"
995                         " flow rules\n\n"
996
997                         "flow aged {port_id} [destroy]\n"
998                         "    List and destroy aged flows"
999                         " flow rules\n\n"
1000
1001                         "flow shared_action {port_id} create"
1002                         " [action_id {shared_action_id}]"
1003                         " [ingress] [egress]"
1004                         " action {action} / end\n"
1005                         "    Create shared action.\n\n"
1006
1007                         "flow shared_action {port_id} update"
1008                         " {shared_action_id} action {action} / end\n"
1009                         "    Update shared action.\n\n"
1010
1011                         "flow shared_action {port_id} destroy"
1012                         " action_id {shared_action_id} [...]\n"
1013                         "    Destroy specific shared actions.\n\n"
1014
1015                         "flow shared_action {port_id} query"
1016                         " {shared_action_id}\n"
1017                         "    Query an existing shared action.\n\n"
1018
1019                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1020                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1021                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1022                         "       Configure the VXLAN encapsulation for flows.\n\n"
1023
1024                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1025                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1026                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1027                         " eth-dst (eth-dst)\n"
1028                         "       Configure the VXLAN encapsulation for flows.\n\n"
1029
1030                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1031                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1032                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1033                         " eth-dst (eth-dst)\n"
1034                         "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1037                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1038                         " (eth-dst)\n"
1039                         "       Configure the NVGRE encapsulation for flows.\n\n"
1040
1041                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1043                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set raw_encap {flow items}\n"
1047                         "       Configure the encapsulation with raw data.\n\n"
1048
1049                         "set raw_decap {flow items}\n"
1050                         "       Configure the decapsulation with raw data.\n\n"
1051
1052                 );
1053         }
1054
1055         if (show_all || !strcmp(res->section, "traffic_management")) {
1056                 cmdline_printf(
1057                         cl,
1058                         "\n"
1059                         "Traffic Management:\n"
1060                         "--------------\n"
1061                         "show port tm cap (port_id)\n"
1062                         "       Display the port TM capability.\n\n"
1063
1064                         "show port tm level cap (port_id) (level_id)\n"
1065                         "       Display the port TM hierarchical level capability.\n\n"
1066
1067                         "show port tm node cap (port_id) (node_id)\n"
1068                         "       Display the port TM node capability.\n\n"
1069
1070                         "show port tm node type (port_id) (node_id)\n"
1071                         "       Display the port TM node type.\n\n"
1072
1073                         "show port tm node stats (port_id) (node_id) (clear)\n"
1074                         "       Display the port TM node stats.\n\n"
1075
1076                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1077                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1078                         " (packet_length_adjust) (packet_mode)\n"
1079                         "       Add port tm node private shaper profile.\n\n"
1080
1081                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1082                         "       Delete port tm node private shaper profile.\n\n"
1083
1084                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1085                         " (shaper_profile_id)\n"
1086                         "       Add/update port tm node shared shaper.\n\n"
1087
1088                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1089                         "       Delete port tm node shared shaper.\n\n"
1090
1091                         "set port tm node shaper profile (port_id) (node_id)"
1092                         " (shaper_profile_id)\n"
1093                         "       Set port tm node shaper profile.\n\n"
1094
1095                         "add port tm node wred profile (port_id) (wred_profile_id)"
1096                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1097                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1098                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1099                         "       Add port tm node wred profile.\n\n"
1100
1101                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1102                         "       Delete port tm node wred profile.\n\n"
1103
1104                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1105                         " (priority) (weight) (level_id) (shaper_profile_id)"
1106                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1107                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1108                         "       Add port tm nonleaf node.\n\n"
1109
1110                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1111                         " (priority) (weight) (level_id) (shaper_profile_id)"
1112                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1113                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1114                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1115
1116                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1117                         " (priority) (weight) (level_id) (shaper_profile_id)"
1118                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1119                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                         "       Add port tm leaf node.\n\n"
1121
1122                         "del port tm node (port_id) (node_id)\n"
1123                         "       Delete port tm node.\n\n"
1124
1125                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1126                         " (priority) (weight)\n"
1127                         "       Set port tm node parent.\n\n"
1128
1129                         "suspend port tm node (port_id) (node_id)"
1130                         "       Suspend tm node.\n\n"
1131
1132                         "resume port tm node (port_id) (node_id)"
1133                         "       Resume tm node.\n\n"
1134
1135                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1136                         "       Commit tm hierarchy.\n\n"
1137
1138                         "set port tm mark ip_ecn (port) (green) (yellow)"
1139                         " (red)\n"
1140                         "    Enables/Disables the traffic management marking"
1141                         " for IP ECN (Explicit Congestion Notification)"
1142                         " packets on a given port\n\n"
1143
1144                         "set port tm mark ip_dscp (port) (green) (yellow)"
1145                         " (red)\n"
1146                         "    Enables/Disables the traffic management marking"
1147                         " on the port for IP dscp packets\n\n"
1148
1149                         "set port tm mark vlan_dei (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for VLAN packets with DEI enabled\n\n"
1153                 );
1154         }
1155
1156         if (show_all || !strcmp(res->section, "devices")) {
1157                 cmdline_printf(
1158                         cl,
1159                         "\n"
1160                         "Device Operations:\n"
1161                         "--------------\n"
1162                         "device detach (identifier)\n"
1163                         "       Detach device by identifier.\n\n"
1164                 );
1165         }
1166
1167 }
1168
1169 cmdline_parse_token_string_t cmd_help_long_help =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1171
1172 cmdline_parse_token_string_t cmd_help_long_section =
1173         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1174                         "all#control#display#config#"
1175                         "ports#registers#filters#traffic_management#devices");
1176
1177 cmdline_parse_inst_t cmd_help_long = {
1178         .f = cmd_help_long_parsed,
1179         .data = NULL,
1180         .help_str = "help all|control|display|config|ports|register|"
1181                 "filters|traffic_management|devices: "
1182                 "Show help",
1183         .tokens = {
1184                 (void *)&cmd_help_long_help,
1185                 (void *)&cmd_help_long_section,
1186                 NULL,
1187         },
1188 };
1189
1190
1191 /* *** start/stop/close all ports *** */
1192 struct cmd_operate_port_result {
1193         cmdline_fixed_string_t keyword;
1194         cmdline_fixed_string_t name;
1195         cmdline_fixed_string_t value;
1196 };
1197
1198 static void cmd_operate_port_parsed(void *parsed_result,
1199                                 __rte_unused struct cmdline *cl,
1200                                 __rte_unused void *data)
1201 {
1202         struct cmd_operate_port_result *res = parsed_result;
1203
1204         if (!strcmp(res->name, "start"))
1205                 start_port(RTE_PORT_ALL);
1206         else if (!strcmp(res->name, "stop"))
1207                 stop_port(RTE_PORT_ALL);
1208         else if (!strcmp(res->name, "close"))
1209                 close_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "reset"))
1211                 reset_port(RTE_PORT_ALL);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1218                                                                 "port");
1219 cmdline_parse_token_string_t cmd_operate_port_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1221                                                 "start#stop#close#reset");
1222 cmdline_parse_token_string_t cmd_operate_port_all_all =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1224
1225 cmdline_parse_inst_t cmd_operate_port = {
1226         .f = cmd_operate_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1229         .tokens = {
1230                 (void *)&cmd_operate_port_all_cmd,
1231                 (void *)&cmd_operate_port_all_port,
1232                 (void *)&cmd_operate_port_all_all,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** start/stop/close specific port *** */
1238 struct cmd_operate_specific_port_result {
1239         cmdline_fixed_string_t keyword;
1240         cmdline_fixed_string_t name;
1241         uint8_t value;
1242 };
1243
1244 static void cmd_operate_specific_port_parsed(void *parsed_result,
1245                         __rte_unused struct cmdline *cl,
1246                                 __rte_unused void *data)
1247 {
1248         struct cmd_operate_specific_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->name, "start"))
1251                 start_port(res->value);
1252         else if (!strcmp(res->name, "stop"))
1253                 stop_port(res->value);
1254         else if (!strcmp(res->name, "close"))
1255                 close_port(res->value);
1256         else if (!strcmp(res->name, "reset"))
1257                 reset_port(res->value);
1258         else
1259                 printf("Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                         keyword, "port");
1265 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                 name, "start#stop#close#reset");
1268 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1269         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1270                                                         value, RTE_UINT8);
1271
1272 cmdline_parse_inst_t cmd_operate_specific_port = {
1273         .f = cmd_operate_specific_port_parsed,
1274         .data = NULL,
1275         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1276         .tokens = {
1277                 (void *)&cmd_operate_specific_port_cmd,
1278                 (void *)&cmd_operate_specific_port_port,
1279                 (void *)&cmd_operate_specific_port_id,
1280                 NULL,
1281         },
1282 };
1283
1284 /* *** enable port setup (after attach) via iterator or event *** */
1285 struct cmd_set_port_setup_on_result {
1286         cmdline_fixed_string_t set;
1287         cmdline_fixed_string_t port;
1288         cmdline_fixed_string_t setup;
1289         cmdline_fixed_string_t on;
1290         cmdline_fixed_string_t mode;
1291 };
1292
1293 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1294                                 __rte_unused struct cmdline *cl,
1295                                 __rte_unused void *data)
1296 {
1297         struct cmd_set_port_setup_on_result *res = parsed_result;
1298
1299         if (strcmp(res->mode, "event") == 0)
1300                 setup_on_probe_event = true;
1301         else if (strcmp(res->mode, "iterator") == 0)
1302                 setup_on_probe_event = false;
1303         else
1304                 printf("Unknown mode\n");
1305 }
1306
1307 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1308         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1309                         set, "set");
1310 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1311         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1312                         port, "port");
1313 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1314         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1315                         setup, "setup");
1316 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1317         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1318                         on, "on");
1319 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1320         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1321                         mode, "iterator#event");
1322
1323 cmdline_parse_inst_t cmd_set_port_setup_on = {
1324         .f = cmd_set_port_setup_on_parsed,
1325         .data = NULL,
1326         .help_str = "set port setup on iterator|event",
1327         .tokens = {
1328                 (void *)&cmd_set_port_setup_on_set,
1329                 (void *)&cmd_set_port_setup_on_port,
1330                 (void *)&cmd_set_port_setup_on_setup,
1331                 (void *)&cmd_set_port_setup_on_on,
1332                 (void *)&cmd_set_port_setup_on_mode,
1333                 NULL,
1334         },
1335 };
1336
1337 /* *** attach a specified port *** */
1338 struct cmd_operate_attach_port_result {
1339         cmdline_fixed_string_t port;
1340         cmdline_fixed_string_t keyword;
1341         cmdline_multi_string_t identifier;
1342 };
1343
1344 static void cmd_operate_attach_port_parsed(void *parsed_result,
1345                                 __rte_unused struct cmdline *cl,
1346                                 __rte_unused void *data)
1347 {
1348         struct cmd_operate_attach_port_result *res = parsed_result;
1349
1350         if (!strcmp(res->keyword, "attach"))
1351                 attach_port(res->identifier);
1352         else
1353                 printf("Unknown parameter\n");
1354 }
1355
1356 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1357         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1358                         port, "port");
1359 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1360         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1361                         keyword, "attach");
1362 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1363         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1364                         identifier, TOKEN_STRING_MULTI);
1365
1366 cmdline_parse_inst_t cmd_operate_attach_port = {
1367         .f = cmd_operate_attach_port_parsed,
1368         .data = NULL,
1369         .help_str = "port attach <identifier>: "
1370                 "(identifier: pci address or virtual dev name)",
1371         .tokens = {
1372                 (void *)&cmd_operate_attach_port_port,
1373                 (void *)&cmd_operate_attach_port_keyword,
1374                 (void *)&cmd_operate_attach_port_identifier,
1375                 NULL,
1376         },
1377 };
1378
1379 /* *** detach a specified port *** */
1380 struct cmd_operate_detach_port_result {
1381         cmdline_fixed_string_t port;
1382         cmdline_fixed_string_t keyword;
1383         portid_t port_id;
1384 };
1385
1386 static void cmd_operate_detach_port_parsed(void *parsed_result,
1387                                 __rte_unused struct cmdline *cl,
1388                                 __rte_unused void *data)
1389 {
1390         struct cmd_operate_detach_port_result *res = parsed_result;
1391
1392         if (!strcmp(res->keyword, "detach")) {
1393                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1394                 detach_port_device(res->port_id);
1395         } else {
1396                 printf("Unknown parameter\n");
1397         }
1398 }
1399
1400 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1401         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1402                         port, "port");
1403 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1404         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1405                         keyword, "detach");
1406 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1407         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1408                         port_id, RTE_UINT16);
1409
1410 cmdline_parse_inst_t cmd_operate_detach_port = {
1411         .f = cmd_operate_detach_port_parsed,
1412         .data = NULL,
1413         .help_str = "port detach <port_id>",
1414         .tokens = {
1415                 (void *)&cmd_operate_detach_port_port,
1416                 (void *)&cmd_operate_detach_port_keyword,
1417                 (void *)&cmd_operate_detach_port_port_id,
1418                 NULL,
1419         },
1420 };
1421
1422 /* *** detach device by identifier *** */
1423 struct cmd_operate_detach_device_result {
1424         cmdline_fixed_string_t device;
1425         cmdline_fixed_string_t keyword;
1426         cmdline_fixed_string_t identifier;
1427 };
1428
1429 static void cmd_operate_detach_device_parsed(void *parsed_result,
1430                                 __rte_unused struct cmdline *cl,
1431                                 __rte_unused void *data)
1432 {
1433         struct cmd_operate_detach_device_result *res = parsed_result;
1434
1435         if (!strcmp(res->keyword, "detach"))
1436                 detach_devargs(res->identifier);
1437         else
1438                 printf("Unknown parameter\n");
1439 }
1440
1441 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1442         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1443                         device, "device");
1444 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1445         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1446                         keyword, "detach");
1447 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1448         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1449                         identifier, NULL);
1450
1451 cmdline_parse_inst_t cmd_operate_detach_device = {
1452         .f = cmd_operate_detach_device_parsed,
1453         .data = NULL,
1454         .help_str = "device detach <identifier>:"
1455                 "(identifier: pci address or virtual dev name)",
1456         .tokens = {
1457                 (void *)&cmd_operate_detach_device_device,
1458                 (void *)&cmd_operate_detach_device_keyword,
1459                 (void *)&cmd_operate_detach_device_identifier,
1460                 NULL,
1461         },
1462 };
1463 /* *** configure speed for all ports *** */
1464 struct cmd_config_speed_all {
1465         cmdline_fixed_string_t port;
1466         cmdline_fixed_string_t keyword;
1467         cmdline_fixed_string_t all;
1468         cmdline_fixed_string_t item1;
1469         cmdline_fixed_string_t item2;
1470         cmdline_fixed_string_t value1;
1471         cmdline_fixed_string_t value2;
1472 };
1473
1474 static int
1475 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1476 {
1477
1478         int duplex;
1479
1480         if (!strcmp(duplexstr, "half")) {
1481                 duplex = ETH_LINK_HALF_DUPLEX;
1482         } else if (!strcmp(duplexstr, "full")) {
1483                 duplex = ETH_LINK_FULL_DUPLEX;
1484         } else if (!strcmp(duplexstr, "auto")) {
1485                 duplex = ETH_LINK_FULL_DUPLEX;
1486         } else {
1487                 printf("Unknown duplex parameter\n");
1488                 return -1;
1489         }
1490
1491         if (!strcmp(speedstr, "10")) {
1492                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1493                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1494         } else if (!strcmp(speedstr, "100")) {
1495                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1496                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1497         } else {
1498                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1499                         printf("Invalid speed/duplex parameters\n");
1500                         return -1;
1501                 }
1502                 if (!strcmp(speedstr, "1000")) {
1503                         *speed = ETH_LINK_SPEED_1G;
1504                 } else if (!strcmp(speedstr, "10000")) {
1505                         *speed = ETH_LINK_SPEED_10G;
1506                 } else if (!strcmp(speedstr, "25000")) {
1507                         *speed = ETH_LINK_SPEED_25G;
1508                 } else if (!strcmp(speedstr, "40000")) {
1509                         *speed = ETH_LINK_SPEED_40G;
1510                 } else if (!strcmp(speedstr, "50000")) {
1511                         *speed = ETH_LINK_SPEED_50G;
1512                 } else if (!strcmp(speedstr, "100000")) {
1513                         *speed = ETH_LINK_SPEED_100G;
1514                 } else if (!strcmp(speedstr, "200000")) {
1515                         *speed = ETH_LINK_SPEED_200G;
1516                 } else if (!strcmp(speedstr, "auto")) {
1517                         *speed = ETH_LINK_SPEED_AUTONEG;
1518                 } else {
1519                         printf("Unknown speed parameter\n");
1520                         return -1;
1521                 }
1522         }
1523
1524         return 0;
1525 }
1526
1527 static void
1528 cmd_config_speed_all_parsed(void *parsed_result,
1529                         __rte_unused struct cmdline *cl,
1530                         __rte_unused void *data)
1531 {
1532         struct cmd_config_speed_all *res = parsed_result;
1533         uint32_t link_speed;
1534         portid_t pid;
1535
1536         if (!all_ports_stopped()) {
1537                 printf("Please stop all ports first\n");
1538                 return;
1539         }
1540
1541         if (parse_and_check_speed_duplex(res->value1, res->value2,
1542                         &link_speed) < 0)
1543                 return;
1544
1545         RTE_ETH_FOREACH_DEV(pid) {
1546                 ports[pid].dev_conf.link_speeds = link_speed;
1547         }
1548
1549         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1550 }
1551
1552 cmdline_parse_token_string_t cmd_config_speed_all_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1554 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1556                                                         "config");
1557 cmdline_parse_token_string_t cmd_config_speed_all_all =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1559 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1561 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1563                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1564 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1566 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1568                                                 "half#full#auto");
1569
1570 cmdline_parse_inst_t cmd_config_speed_all = {
1571         .f = cmd_config_speed_all_parsed,
1572         .data = NULL,
1573         .help_str = "port config all speed "
1574                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1575                                                         "half|full|auto",
1576         .tokens = {
1577                 (void *)&cmd_config_speed_all_port,
1578                 (void *)&cmd_config_speed_all_keyword,
1579                 (void *)&cmd_config_speed_all_all,
1580                 (void *)&cmd_config_speed_all_item1,
1581                 (void *)&cmd_config_speed_all_value1,
1582                 (void *)&cmd_config_speed_all_item2,
1583                 (void *)&cmd_config_speed_all_value2,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** configure speed for specific port *** */
1589 struct cmd_config_speed_specific {
1590         cmdline_fixed_string_t port;
1591         cmdline_fixed_string_t keyword;
1592         portid_t id;
1593         cmdline_fixed_string_t item1;
1594         cmdline_fixed_string_t item2;
1595         cmdline_fixed_string_t value1;
1596         cmdline_fixed_string_t value2;
1597 };
1598
1599 static void
1600 cmd_config_speed_specific_parsed(void *parsed_result,
1601                                 __rte_unused struct cmdline *cl,
1602                                 __rte_unused void *data)
1603 {
1604         struct cmd_config_speed_specific *res = parsed_result;
1605         uint32_t link_speed;
1606
1607         if (!all_ports_stopped()) {
1608                 printf("Please stop all ports first\n");
1609                 return;
1610         }
1611
1612         if (port_id_is_invalid(res->id, ENABLED_WARN))
1613                 return;
1614
1615         if (parse_and_check_speed_duplex(res->value1, res->value2,
1616                         &link_speed) < 0)
1617                 return;
1618
1619         ports[res->id].dev_conf.link_speeds = link_speed;
1620
1621         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1622 }
1623
1624
1625 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1627                                                                 "port");
1628 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1630                                                                 "config");
1631 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1633 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1635                                                                 "speed");
1636 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1638                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1639 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1641                                                                 "duplex");
1642 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1644                                                         "half#full#auto");
1645
1646 cmdline_parse_inst_t cmd_config_speed_specific = {
1647         .f = cmd_config_speed_specific_parsed,
1648         .data = NULL,
1649         .help_str = "port config <port_id> speed "
1650                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1651                                                         "half|full|auto",
1652         .tokens = {
1653                 (void *)&cmd_config_speed_specific_port,
1654                 (void *)&cmd_config_speed_specific_keyword,
1655                 (void *)&cmd_config_speed_specific_id,
1656                 (void *)&cmd_config_speed_specific_item1,
1657                 (void *)&cmd_config_speed_specific_value1,
1658                 (void *)&cmd_config_speed_specific_item2,
1659                 (void *)&cmd_config_speed_specific_value2,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure loopback for all ports *** */
1665 struct cmd_config_loopback_all {
1666         cmdline_fixed_string_t port;
1667         cmdline_fixed_string_t keyword;
1668         cmdline_fixed_string_t all;
1669         cmdline_fixed_string_t item;
1670         uint32_t mode;
1671 };
1672
1673 static void
1674 cmd_config_loopback_all_parsed(void *parsed_result,
1675                         __rte_unused struct cmdline *cl,
1676                         __rte_unused void *data)
1677 {
1678         struct cmd_config_loopback_all *res = parsed_result;
1679         portid_t pid;
1680
1681         if (!all_ports_stopped()) {
1682                 printf("Please stop all ports first\n");
1683                 return;
1684         }
1685
1686         RTE_ETH_FOREACH_DEV(pid) {
1687                 ports[pid].dev_conf.lpbk_mode = res->mode;
1688         }
1689
1690         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1691 }
1692
1693 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1695 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1697                                                         "config");
1698 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1700 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1702                                                         "loopback");
1703 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1704         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1705
1706 cmdline_parse_inst_t cmd_config_loopback_all = {
1707         .f = cmd_config_loopback_all_parsed,
1708         .data = NULL,
1709         .help_str = "port config all loopback <mode>",
1710         .tokens = {
1711                 (void *)&cmd_config_loopback_all_port,
1712                 (void *)&cmd_config_loopback_all_keyword,
1713                 (void *)&cmd_config_loopback_all_all,
1714                 (void *)&cmd_config_loopback_all_item,
1715                 (void *)&cmd_config_loopback_all_mode,
1716                 NULL,
1717         },
1718 };
1719
1720 /* *** configure loopback for specific port *** */
1721 struct cmd_config_loopback_specific {
1722         cmdline_fixed_string_t port;
1723         cmdline_fixed_string_t keyword;
1724         uint16_t port_id;
1725         cmdline_fixed_string_t item;
1726         uint32_t mode;
1727 };
1728
1729 static void
1730 cmd_config_loopback_specific_parsed(void *parsed_result,
1731                                 __rte_unused struct cmdline *cl,
1732                                 __rte_unused void *data)
1733 {
1734         struct cmd_config_loopback_specific *res = parsed_result;
1735
1736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1737                 return;
1738
1739         if (!port_is_stopped(res->port_id)) {
1740                 printf("Please stop port %u first\n", res->port_id);
1741                 return;
1742         }
1743
1744         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1745
1746         cmd_reconfig_device_queue(res->port_id, 1, 1);
1747 }
1748
1749
1750 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1751         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1752                                                                 "port");
1753 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1755                                                                 "config");
1756 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1757         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1758                                                                 RTE_UINT16);
1759 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1761                                                                 "loopback");
1762 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1763         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1764                               RTE_UINT32);
1765
1766 cmdline_parse_inst_t cmd_config_loopback_specific = {
1767         .f = cmd_config_loopback_specific_parsed,
1768         .data = NULL,
1769         .help_str = "port config <port_id> loopback <mode>",
1770         .tokens = {
1771                 (void *)&cmd_config_loopback_specific_port,
1772                 (void *)&cmd_config_loopback_specific_keyword,
1773                 (void *)&cmd_config_loopback_specific_id,
1774                 (void *)&cmd_config_loopback_specific_item,
1775                 (void *)&cmd_config_loopback_specific_mode,
1776                 NULL,
1777         },
1778 };
1779
1780 /* *** configure txq/rxq, txd/rxd *** */
1781 struct cmd_config_rx_tx {
1782         cmdline_fixed_string_t port;
1783         cmdline_fixed_string_t keyword;
1784         cmdline_fixed_string_t all;
1785         cmdline_fixed_string_t name;
1786         uint16_t value;
1787 };
1788
1789 static void
1790 cmd_config_rx_tx_parsed(void *parsed_result,
1791                         __rte_unused struct cmdline *cl,
1792                         __rte_unused void *data)
1793 {
1794         struct cmd_config_rx_tx *res = parsed_result;
1795
1796         if (!all_ports_stopped()) {
1797                 printf("Please stop all ports first\n");
1798                 return;
1799         }
1800         if (!strcmp(res->name, "rxq")) {
1801                 if (!res->value && !nb_txq) {
1802                         printf("Warning: Either rx or tx queues should be non zero\n");
1803                         return;
1804                 }
1805                 if (check_nb_rxq(res->value) != 0)
1806                         return;
1807                 nb_rxq = res->value;
1808         }
1809         else if (!strcmp(res->name, "txq")) {
1810                 if (!res->value && !nb_rxq) {
1811                         printf("Warning: Either rx or tx queues should be non zero\n");
1812                         return;
1813                 }
1814                 if (check_nb_txq(res->value) != 0)
1815                         return;
1816                 nb_txq = res->value;
1817         }
1818         else if (!strcmp(res->name, "rxd")) {
1819                 if (check_nb_rxd(res->value) != 0)
1820                         return;
1821                 nb_rxd = res->value;
1822         } else if (!strcmp(res->name, "txd")) {
1823                 if (check_nb_txd(res->value) != 0)
1824                         return;
1825
1826                 nb_txd = res->value;
1827         } else {
1828                 printf("Unknown parameter\n");
1829                 return;
1830         }
1831
1832         fwd_config_setup();
1833
1834         init_port_config();
1835
1836         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1837 }
1838
1839 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1841 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1843 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1847                                                 "rxq#txq#rxd#txd");
1848 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1850
1851 cmdline_parse_inst_t cmd_config_rx_tx = {
1852         .f = cmd_config_rx_tx_parsed,
1853         .data = NULL,
1854         .help_str = "port config all rxq|txq|rxd|txd <value>",
1855         .tokens = {
1856                 (void *)&cmd_config_rx_tx_port,
1857                 (void *)&cmd_config_rx_tx_keyword,
1858                 (void *)&cmd_config_rx_tx_all,
1859                 (void *)&cmd_config_rx_tx_name,
1860                 (void *)&cmd_config_rx_tx_value,
1861                 NULL,
1862         },
1863 };
1864
1865 /* *** config max packet length *** */
1866 struct cmd_config_max_pkt_len_result {
1867         cmdline_fixed_string_t port;
1868         cmdline_fixed_string_t keyword;
1869         cmdline_fixed_string_t all;
1870         cmdline_fixed_string_t name;
1871         uint32_t value;
1872 };
1873
1874 static void
1875 cmd_config_max_pkt_len_parsed(void *parsed_result,
1876                                 __rte_unused struct cmdline *cl,
1877                                 __rte_unused void *data)
1878 {
1879         struct cmd_config_max_pkt_len_result *res = parsed_result;
1880         portid_t pid;
1881
1882         if (!all_ports_stopped()) {
1883                 printf("Please stop all ports first\n");
1884                 return;
1885         }
1886
1887         RTE_ETH_FOREACH_DEV(pid) {
1888                 struct rte_port *port = &ports[pid];
1889                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1890
1891                 if (!strcmp(res->name, "max-pkt-len")) {
1892                         if (res->value < RTE_ETHER_MIN_LEN) {
1893                                 printf("max-pkt-len can not be less than %d\n",
1894                                                 RTE_ETHER_MIN_LEN);
1895                                 return;
1896                         }
1897                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1898                                 return;
1899
1900                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1901                         if (res->value > RTE_ETHER_MAX_LEN)
1902                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1903                         else
1904                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1905                         port->dev_conf.rxmode.offloads = rx_offloads;
1906                 } else {
1907                         printf("Unknown parameter\n");
1908                         return;
1909                 }
1910         }
1911
1912         init_port_config();
1913
1914         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1915 }
1916
1917 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1918         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1919                                                                 "port");
1920 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1921         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1922                                                                 "config");
1923 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1924         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1925                                                                 "all");
1926 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1927         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1928                                                                 "max-pkt-len");
1929 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1930         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1931                                                                 RTE_UINT32);
1932
1933 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1934         .f = cmd_config_max_pkt_len_parsed,
1935         .data = NULL,
1936         .help_str = "port config all max-pkt-len <value>",
1937         .tokens = {
1938                 (void *)&cmd_config_max_pkt_len_port,
1939                 (void *)&cmd_config_max_pkt_len_keyword,
1940                 (void *)&cmd_config_max_pkt_len_all,
1941                 (void *)&cmd_config_max_pkt_len_name,
1942                 (void *)&cmd_config_max_pkt_len_value,
1943                 NULL,
1944         },
1945 };
1946
1947 /* *** config max LRO aggregated packet size *** */
1948 struct cmd_config_max_lro_pkt_size_result {
1949         cmdline_fixed_string_t port;
1950         cmdline_fixed_string_t keyword;
1951         cmdline_fixed_string_t all;
1952         cmdline_fixed_string_t name;
1953         uint32_t value;
1954 };
1955
1956 static void
1957 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1958                                 __rte_unused struct cmdline *cl,
1959                                 __rte_unused void *data)
1960 {
1961         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1962         portid_t pid;
1963
1964         if (!all_ports_stopped()) {
1965                 printf("Please stop all ports first\n");
1966                 return;
1967         }
1968
1969         RTE_ETH_FOREACH_DEV(pid) {
1970                 struct rte_port *port = &ports[pid];
1971
1972                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1973                         if (res->value ==
1974                                         port->dev_conf.rxmode.max_lro_pkt_size)
1975                                 return;
1976
1977                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1978                 } else {
1979                         printf("Unknown parameter\n");
1980                         return;
1981                 }
1982         }
1983
1984         init_port_config();
1985
1986         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1987 }
1988
1989 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1990         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1991                                  port, "port");
1992 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
1993         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1994                                  keyword, "config");
1995 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
1996         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1997                                  all, "all");
1998 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
1999         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2000                                  name, "max-lro-pkt-size");
2001 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2002         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2003                               value, RTE_UINT32);
2004
2005 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2006         .f = cmd_config_max_lro_pkt_size_parsed,
2007         .data = NULL,
2008         .help_str = "port config all max-lro-pkt-size <value>",
2009         .tokens = {
2010                 (void *)&cmd_config_max_lro_pkt_size_port,
2011                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2012                 (void *)&cmd_config_max_lro_pkt_size_all,
2013                 (void *)&cmd_config_max_lro_pkt_size_name,
2014                 (void *)&cmd_config_max_lro_pkt_size_value,
2015                 NULL,
2016         },
2017 };
2018
2019 /* *** configure port MTU *** */
2020 struct cmd_config_mtu_result {
2021         cmdline_fixed_string_t port;
2022         cmdline_fixed_string_t keyword;
2023         cmdline_fixed_string_t mtu;
2024         portid_t port_id;
2025         uint16_t value;
2026 };
2027
2028 static void
2029 cmd_config_mtu_parsed(void *parsed_result,
2030                       __rte_unused struct cmdline *cl,
2031                       __rte_unused void *data)
2032 {
2033         struct cmd_config_mtu_result *res = parsed_result;
2034
2035         if (res->value < RTE_ETHER_MIN_LEN) {
2036                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2037                 return;
2038         }
2039         port_mtu_set(res->port_id, res->value);
2040 }
2041
2042 cmdline_parse_token_string_t cmd_config_mtu_port =
2043         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2044                                  "port");
2045 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2046         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2047                                  "config");
2048 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2049         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2050                                  "mtu");
2051 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2052         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2053                                  RTE_UINT16);
2054 cmdline_parse_token_num_t cmd_config_mtu_value =
2055         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2056                                  RTE_UINT16);
2057
2058 cmdline_parse_inst_t cmd_config_mtu = {
2059         .f = cmd_config_mtu_parsed,
2060         .data = NULL,
2061         .help_str = "port config mtu <port_id> <value>",
2062         .tokens = {
2063                 (void *)&cmd_config_mtu_port,
2064                 (void *)&cmd_config_mtu_keyword,
2065                 (void *)&cmd_config_mtu_mtu,
2066                 (void *)&cmd_config_mtu_port_id,
2067                 (void *)&cmd_config_mtu_value,
2068                 NULL,
2069         },
2070 };
2071
2072 /* *** configure rx mode *** */
2073 struct cmd_config_rx_mode_flag {
2074         cmdline_fixed_string_t port;
2075         cmdline_fixed_string_t keyword;
2076         cmdline_fixed_string_t all;
2077         cmdline_fixed_string_t name;
2078         cmdline_fixed_string_t value;
2079 };
2080
2081 static void
2082 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2083                                 __rte_unused struct cmdline *cl,
2084                                 __rte_unused void *data)
2085 {
2086         struct cmd_config_rx_mode_flag *res = parsed_result;
2087
2088         if (!all_ports_stopped()) {
2089                 printf("Please stop all ports first\n");
2090                 return;
2091         }
2092
2093         if (!strcmp(res->name, "drop-en")) {
2094                 if (!strcmp(res->value, "on"))
2095                         rx_drop_en = 1;
2096                 else if (!strcmp(res->value, "off"))
2097                         rx_drop_en = 0;
2098                 else {
2099                         printf("Unknown parameter\n");
2100                         return;
2101                 }
2102         } else {
2103                 printf("Unknown parameter\n");
2104                 return;
2105         }
2106
2107         init_port_config();
2108
2109         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2110 }
2111
2112 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2114 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2116                                                                 "config");
2117 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2119 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2121                                         "drop-en");
2122 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2124                                                         "on#off");
2125
2126 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2127         .f = cmd_config_rx_mode_flag_parsed,
2128         .data = NULL,
2129         .help_str = "port config all drop-en on|off",
2130         .tokens = {
2131                 (void *)&cmd_config_rx_mode_flag_port,
2132                 (void *)&cmd_config_rx_mode_flag_keyword,
2133                 (void *)&cmd_config_rx_mode_flag_all,
2134                 (void *)&cmd_config_rx_mode_flag_name,
2135                 (void *)&cmd_config_rx_mode_flag_value,
2136                 NULL,
2137         },
2138 };
2139
2140 /* *** configure rss *** */
2141 struct cmd_config_rss {
2142         cmdline_fixed_string_t port;
2143         cmdline_fixed_string_t keyword;
2144         cmdline_fixed_string_t all;
2145         cmdline_fixed_string_t name;
2146         cmdline_fixed_string_t value;
2147 };
2148
2149 static void
2150 cmd_config_rss_parsed(void *parsed_result,
2151                         __rte_unused struct cmdline *cl,
2152                         __rte_unused void *data)
2153 {
2154         struct cmd_config_rss *res = parsed_result;
2155         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2156         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2157         int use_default = 0;
2158         int all_updated = 1;
2159         int diag;
2160         uint16_t i;
2161         int ret;
2162
2163         if (!strcmp(res->value, "all"))
2164                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2165                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2166                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2167                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2168                         ETH_RSS_ECPRI;
2169         else if (!strcmp(res->value, "eth"))
2170                 rss_conf.rss_hf = ETH_RSS_ETH;
2171         else if (!strcmp(res->value, "vlan"))
2172                 rss_conf.rss_hf = ETH_RSS_VLAN;
2173         else if (!strcmp(res->value, "ip"))
2174                 rss_conf.rss_hf = ETH_RSS_IP;
2175         else if (!strcmp(res->value, "udp"))
2176                 rss_conf.rss_hf = ETH_RSS_UDP;
2177         else if (!strcmp(res->value, "tcp"))
2178                 rss_conf.rss_hf = ETH_RSS_TCP;
2179         else if (!strcmp(res->value, "sctp"))
2180                 rss_conf.rss_hf = ETH_RSS_SCTP;
2181         else if (!strcmp(res->value, "ether"))
2182                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2183         else if (!strcmp(res->value, "port"))
2184                 rss_conf.rss_hf = ETH_RSS_PORT;
2185         else if (!strcmp(res->value, "vxlan"))
2186                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2187         else if (!strcmp(res->value, "geneve"))
2188                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2189         else if (!strcmp(res->value, "nvgre"))
2190                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2191         else if (!strcmp(res->value, "l3-pre32"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2193         else if (!strcmp(res->value, "l3-pre40"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2195         else if (!strcmp(res->value, "l3-pre48"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2197         else if (!strcmp(res->value, "l3-pre56"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2199         else if (!strcmp(res->value, "l3-pre64"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2201         else if (!strcmp(res->value, "l3-pre96"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2203         else if (!strcmp(res->value, "l3-src-only"))
2204                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2205         else if (!strcmp(res->value, "l3-dst-only"))
2206                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2207         else if (!strcmp(res->value, "l4-src-only"))
2208                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2209         else if (!strcmp(res->value, "l4-dst-only"))
2210                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2211         else if (!strcmp(res->value, "l2-src-only"))
2212                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2213         else if (!strcmp(res->value, "l2-dst-only"))
2214                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2215         else if (!strcmp(res->value, "l2tpv3"))
2216                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2217         else if (!strcmp(res->value, "esp"))
2218                 rss_conf.rss_hf = ETH_RSS_ESP;
2219         else if (!strcmp(res->value, "ah"))
2220                 rss_conf.rss_hf = ETH_RSS_AH;
2221         else if (!strcmp(res->value, "pfcp"))
2222                 rss_conf.rss_hf = ETH_RSS_PFCP;
2223         else if (!strcmp(res->value, "pppoe"))
2224                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2225         else if (!strcmp(res->value, "gtpu"))
2226                 rss_conf.rss_hf = ETH_RSS_GTPU;
2227         else if (!strcmp(res->value, "ecpri"))
2228                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2229         else if (!strcmp(res->value, "none"))
2230                 rss_conf.rss_hf = 0;
2231         else if (!strcmp(res->value, "level-default")) {
2232                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2233                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2234         } else if (!strcmp(res->value, "level-outer")) {
2235                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2236                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2237         } else if (!strcmp(res->value, "level-inner")) {
2238                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2239                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2240         } else if (!strcmp(res->value, "default"))
2241                 use_default = 1;
2242         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2243                                                 atoi(res->value) < 64)
2244                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2245         else {
2246                 printf("Unknown parameter\n");
2247                 return;
2248         }
2249         rss_conf.rss_key = NULL;
2250         /* Update global configuration for RSS types. */
2251         RTE_ETH_FOREACH_DEV(i) {
2252                 struct rte_eth_rss_conf local_rss_conf;
2253
2254                 ret = eth_dev_info_get_print_err(i, &dev_info);
2255                 if (ret != 0)
2256                         return;
2257
2258                 if (use_default)
2259                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2260
2261                 local_rss_conf = rss_conf;
2262                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2263                         dev_info.flow_type_rss_offloads;
2264                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2265                         printf("Port %u modified RSS hash function based on hardware support,"
2266                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2267                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2268                 }
2269                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2270                 if (diag < 0) {
2271                         all_updated = 0;
2272                         printf("Configuration of RSS hash at ethernet port %d "
2273                                 "failed with error (%d): %s.\n",
2274                                 i, -diag, strerror(-diag));
2275                 }
2276         }
2277         if (all_updated && !use_default) {
2278                 rss_hf = rss_conf.rss_hf;
2279                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2280         }
2281 }
2282
2283 cmdline_parse_token_string_t cmd_config_rss_port =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2285 cmdline_parse_token_string_t cmd_config_rss_keyword =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2287 cmdline_parse_token_string_t cmd_config_rss_all =
2288         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2289 cmdline_parse_token_string_t cmd_config_rss_name =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2291 cmdline_parse_token_string_t cmd_config_rss_value =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2293
2294 cmdline_parse_inst_t cmd_config_rss = {
2295         .f = cmd_config_rss_parsed,
2296         .data = NULL,
2297         .help_str = "port config all rss "
2298                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2299                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|none|level-default|"
2300                 "level-outer|level-inner|<flowtype_id>",
2301         .tokens = {
2302                 (void *)&cmd_config_rss_port,
2303                 (void *)&cmd_config_rss_keyword,
2304                 (void *)&cmd_config_rss_all,
2305                 (void *)&cmd_config_rss_name,
2306                 (void *)&cmd_config_rss_value,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** configure rss hash key *** */
2312 struct cmd_config_rss_hash_key {
2313         cmdline_fixed_string_t port;
2314         cmdline_fixed_string_t config;
2315         portid_t port_id;
2316         cmdline_fixed_string_t rss_hash_key;
2317         cmdline_fixed_string_t rss_type;
2318         cmdline_fixed_string_t key;
2319 };
2320
2321 static uint8_t
2322 hexa_digit_to_value(char hexa_digit)
2323 {
2324         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2325                 return (uint8_t) (hexa_digit - '0');
2326         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2327                 return (uint8_t) ((hexa_digit - 'a') + 10);
2328         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2329                 return (uint8_t) ((hexa_digit - 'A') + 10);
2330         /* Invalid hexa digit */
2331         return 0xFF;
2332 }
2333
2334 static uint8_t
2335 parse_and_check_key_hexa_digit(char *key, int idx)
2336 {
2337         uint8_t hexa_v;
2338
2339         hexa_v = hexa_digit_to_value(key[idx]);
2340         if (hexa_v == 0xFF)
2341                 printf("invalid key: character %c at position %d is not a "
2342                        "valid hexa digit\n", key[idx], idx);
2343         return hexa_v;
2344 }
2345
2346 static void
2347 cmd_config_rss_hash_key_parsed(void *parsed_result,
2348                                __rte_unused struct cmdline *cl,
2349                                __rte_unused void *data)
2350 {
2351         struct cmd_config_rss_hash_key *res = parsed_result;
2352         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2353         uint8_t xdgt0;
2354         uint8_t xdgt1;
2355         int i;
2356         struct rte_eth_dev_info dev_info;
2357         uint8_t hash_key_size;
2358         uint32_t key_len;
2359         int ret;
2360
2361         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2362         if (ret != 0)
2363                 return;
2364
2365         if (dev_info.hash_key_size > 0 &&
2366                         dev_info.hash_key_size <= sizeof(hash_key))
2367                 hash_key_size = dev_info.hash_key_size;
2368         else {
2369                 printf("dev_info did not provide a valid hash key size\n");
2370                 return;
2371         }
2372         /* Check the length of the RSS hash key */
2373         key_len = strlen(res->key);
2374         if (key_len != (hash_key_size * 2)) {
2375                 printf("key length: %d invalid - key must be a string of %d"
2376                            " hexa-decimal numbers\n",
2377                            (int) key_len, hash_key_size * 2);
2378                 return;
2379         }
2380         /* Translate RSS hash key into binary representation */
2381         for (i = 0; i < hash_key_size; i++) {
2382                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2383                 if (xdgt0 == 0xFF)
2384                         return;
2385                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2386                 if (xdgt1 == 0xFF)
2387                         return;
2388                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2389         }
2390         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2391                         hash_key_size);
2392 }
2393
2394 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2395         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2396 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2398                                  "config");
2399 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2400         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2401                                  RTE_UINT16);
2402 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2403         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2404                                  rss_hash_key, "rss-hash-key");
2405 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2407                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2408                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2409                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2410                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2411                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2412                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2413                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri");
2414 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2415         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2416
2417 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2418         .f = cmd_config_rss_hash_key_parsed,
2419         .data = NULL,
2420         .help_str = "port config <port_id> rss-hash-key "
2421                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2422                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2423                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2424                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2425                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2426                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri "
2427                 "<string of hex digits (variable length, NIC dependent)>",
2428         .tokens = {
2429                 (void *)&cmd_config_rss_hash_key_port,
2430                 (void *)&cmd_config_rss_hash_key_config,
2431                 (void *)&cmd_config_rss_hash_key_port_id,
2432                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2433                 (void *)&cmd_config_rss_hash_key_rss_type,
2434                 (void *)&cmd_config_rss_hash_key_value,
2435                 NULL,
2436         },
2437 };
2438
2439 /* *** configure port rxq/txq ring size *** */
2440 struct cmd_config_rxtx_ring_size {
2441         cmdline_fixed_string_t port;
2442         cmdline_fixed_string_t config;
2443         portid_t portid;
2444         cmdline_fixed_string_t rxtxq;
2445         uint16_t qid;
2446         cmdline_fixed_string_t rsize;
2447         uint16_t size;
2448 };
2449
2450 static void
2451 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2452                                  __rte_unused struct cmdline *cl,
2453                                  __rte_unused void *data)
2454 {
2455         struct cmd_config_rxtx_ring_size *res = parsed_result;
2456         struct rte_port *port;
2457         uint8_t isrx;
2458
2459         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2460                 return;
2461
2462         if (res->portid == (portid_t)RTE_PORT_ALL) {
2463                 printf("Invalid port id\n");
2464                 return;
2465         }
2466
2467         port = &ports[res->portid];
2468
2469         if (!strcmp(res->rxtxq, "rxq"))
2470                 isrx = 1;
2471         else if (!strcmp(res->rxtxq, "txq"))
2472                 isrx = 0;
2473         else {
2474                 printf("Unknown parameter\n");
2475                 return;
2476         }
2477
2478         if (isrx && rx_queue_id_is_invalid(res->qid))
2479                 return;
2480         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2481                 return;
2482
2483         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2484                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2485                        rx_free_thresh);
2486                 return;
2487         }
2488
2489         if (isrx)
2490                 port->nb_rx_desc[res->qid] = res->size;
2491         else
2492                 port->nb_tx_desc[res->qid] = res->size;
2493
2494         cmd_reconfig_device_queue(res->portid, 0, 1);
2495 }
2496
2497 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2498         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                                  port, "port");
2500 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2502                                  config, "config");
2503 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2504         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2505                                  portid, RTE_UINT16);
2506 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2508                                  rxtxq, "rxq#txq");
2509 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2510         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2511                               qid, RTE_UINT16);
2512 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2513         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2514                                  rsize, "ring_size");
2515 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2516         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2517                               size, RTE_UINT16);
2518
2519 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2520         .f = cmd_config_rxtx_ring_size_parsed,
2521         .data = NULL,
2522         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2523         .tokens = {
2524                 (void *)&cmd_config_rxtx_ring_size_port,
2525                 (void *)&cmd_config_rxtx_ring_size_config,
2526                 (void *)&cmd_config_rxtx_ring_size_portid,
2527                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2528                 (void *)&cmd_config_rxtx_ring_size_qid,
2529                 (void *)&cmd_config_rxtx_ring_size_rsize,
2530                 (void *)&cmd_config_rxtx_ring_size_size,
2531                 NULL,
2532         },
2533 };
2534
2535 /* *** configure port rxq/txq start/stop *** */
2536 struct cmd_config_rxtx_queue {
2537         cmdline_fixed_string_t port;
2538         portid_t portid;
2539         cmdline_fixed_string_t rxtxq;
2540         uint16_t qid;
2541         cmdline_fixed_string_t opname;
2542 };
2543
2544 static void
2545 cmd_config_rxtx_queue_parsed(void *parsed_result,
2546                         __rte_unused struct cmdline *cl,
2547                         __rte_unused void *data)
2548 {
2549         struct cmd_config_rxtx_queue *res = parsed_result;
2550         uint8_t isrx;
2551         uint8_t isstart;
2552         int ret = 0;
2553
2554         if (test_done == 0) {
2555                 printf("Please stop forwarding first\n");
2556                 return;
2557         }
2558
2559         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2560                 return;
2561
2562         if (port_is_started(res->portid) != 1) {
2563                 printf("Please start port %u first\n", res->portid);
2564                 return;
2565         }
2566
2567         if (!strcmp(res->rxtxq, "rxq"))
2568                 isrx = 1;
2569         else if (!strcmp(res->rxtxq, "txq"))
2570                 isrx = 0;
2571         else {
2572                 printf("Unknown parameter\n");
2573                 return;
2574         }
2575
2576         if (isrx && rx_queue_id_is_invalid(res->qid))
2577                 return;
2578         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2579                 return;
2580
2581         if (!strcmp(res->opname, "start"))
2582                 isstart = 1;
2583         else if (!strcmp(res->opname, "stop"))
2584                 isstart = 0;
2585         else {
2586                 printf("Unknown parameter\n");
2587                 return;
2588         }
2589
2590         if (isstart && isrx)
2591                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2592         else if (!isstart && isrx)
2593                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2594         else if (isstart && !isrx)
2595                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2596         else
2597                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2598
2599         if (ret == -ENOTSUP)
2600                 printf("Function not supported in PMD driver\n");
2601 }
2602
2603 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2604         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2605 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2609 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2610         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2611 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2612         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2613                                                 "start#stop");
2614
2615 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2616         .f = cmd_config_rxtx_queue_parsed,
2617         .data = NULL,
2618         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2619         .tokens = {
2620                 (void *)&cmd_config_rxtx_queue_port,
2621                 (void *)&cmd_config_rxtx_queue_portid,
2622                 (void *)&cmd_config_rxtx_queue_rxtxq,
2623                 (void *)&cmd_config_rxtx_queue_qid,
2624                 (void *)&cmd_config_rxtx_queue_opname,
2625                 NULL,
2626         },
2627 };
2628
2629 /* *** configure port rxq/txq deferred start on/off *** */
2630 struct cmd_config_deferred_start_rxtx_queue {
2631         cmdline_fixed_string_t port;
2632         portid_t port_id;
2633         cmdline_fixed_string_t rxtxq;
2634         uint16_t qid;
2635         cmdline_fixed_string_t opname;
2636         cmdline_fixed_string_t state;
2637 };
2638
2639 static void
2640 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2641                         __rte_unused struct cmdline *cl,
2642                         __rte_unused void *data)
2643 {
2644         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2645         struct rte_port *port;
2646         uint8_t isrx;
2647         uint8_t ison;
2648         uint8_t needreconfig = 0;
2649
2650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2651                 return;
2652
2653         if (port_is_started(res->port_id) != 0) {
2654                 printf("Please stop port %u first\n", res->port_id);
2655                 return;
2656         }
2657
2658         port = &ports[res->port_id];
2659
2660         isrx = !strcmp(res->rxtxq, "rxq");
2661
2662         if (isrx && rx_queue_id_is_invalid(res->qid))
2663                 return;
2664         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2665                 return;
2666
2667         ison = !strcmp(res->state, "on");
2668
2669         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2670                 port->rx_conf[res->qid].rx_deferred_start = ison;
2671                 needreconfig = 1;
2672         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2673                 port->tx_conf[res->qid].tx_deferred_start = ison;
2674                 needreconfig = 1;
2675         }
2676
2677         if (needreconfig)
2678                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2679 }
2680
2681 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2683                                                 port, "port");
2684 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2685         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2686                                                 port_id, RTE_UINT16);
2687 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2689                                                 rxtxq, "rxq#txq");
2690 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2691         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2692                                                 qid, RTE_UINT16);
2693 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2695                                                 opname, "deferred_start");
2696 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2697         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2698                                                 state, "on#off");
2699
2700 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2701         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2702         .data = NULL,
2703         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2704         .tokens = {
2705                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2706                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2707                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2708                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2709                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2710                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2711                 NULL,
2712         },
2713 };
2714
2715 /* *** configure port rxq/txq setup *** */
2716 struct cmd_setup_rxtx_queue {
2717         cmdline_fixed_string_t port;
2718         portid_t portid;
2719         cmdline_fixed_string_t rxtxq;
2720         uint16_t qid;
2721         cmdline_fixed_string_t setup;
2722 };
2723
2724 /* Common CLI fields for queue setup */
2725 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2726         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2727 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2728         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2729 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2730         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2731 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2732         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2733 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2734         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2735
2736 static void
2737 cmd_setup_rxtx_queue_parsed(
2738         void *parsed_result,
2739         __rte_unused struct cmdline *cl,
2740         __rte_unused void *data)
2741 {
2742         struct cmd_setup_rxtx_queue *res = parsed_result;
2743         struct rte_port *port;
2744         struct rte_mempool *mp;
2745         unsigned int socket_id;
2746         uint8_t isrx = 0;
2747         int ret;
2748
2749         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2750                 return;
2751
2752         if (res->portid == (portid_t)RTE_PORT_ALL) {
2753                 printf("Invalid port id\n");
2754                 return;
2755         }
2756
2757         if (!strcmp(res->rxtxq, "rxq"))
2758                 isrx = 1;
2759         else if (!strcmp(res->rxtxq, "txq"))
2760                 isrx = 0;
2761         else {
2762                 printf("Unknown parameter\n");
2763                 return;
2764         }
2765
2766         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2767                 printf("Invalid rx queue\n");
2768                 return;
2769         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2770                 printf("Invalid tx queue\n");
2771                 return;
2772         }
2773
2774         port = &ports[res->portid];
2775         if (isrx) {
2776                 socket_id = rxring_numa[res->portid];
2777                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2778                         socket_id = port->socket_id;
2779
2780                 mp = mbuf_pool_find(socket_id, 0);
2781                 if (mp == NULL) {
2782                         printf("Failed to setup RX queue: "
2783                                 "No mempool allocation"
2784                                 " on the socket %d\n",
2785                                 rxring_numa[res->portid]);
2786                         return;
2787                 }
2788                 ret = rx_queue_setup(res->portid,
2789                                      res->qid,
2790                                      port->nb_rx_desc[res->qid],
2791                                      socket_id,
2792                                      &port->rx_conf[res->qid],
2793                                      mp);
2794                 if (ret)
2795                         printf("Failed to setup RX queue\n");
2796         } else {
2797                 socket_id = txring_numa[res->portid];
2798                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2799                         socket_id = port->socket_id;
2800
2801                 ret = rte_eth_tx_queue_setup(res->portid,
2802                                              res->qid,
2803                                              port->nb_tx_desc[res->qid],
2804                                              socket_id,
2805                                              &port->tx_conf[res->qid]);
2806                 if (ret)
2807                         printf("Failed to setup TX queue\n");
2808         }
2809 }
2810
2811 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2812         .f = cmd_setup_rxtx_queue_parsed,
2813         .data = NULL,
2814         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2815         .tokens = {
2816                 (void *)&cmd_setup_rxtx_queue_port,
2817                 (void *)&cmd_setup_rxtx_queue_portid,
2818                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2819                 (void *)&cmd_setup_rxtx_queue_qid,
2820                 (void *)&cmd_setup_rxtx_queue_setup,
2821                 NULL,
2822         },
2823 };
2824
2825
2826 /* *** Configure RSS RETA *** */
2827 struct cmd_config_rss_reta {
2828         cmdline_fixed_string_t port;
2829         cmdline_fixed_string_t keyword;
2830         portid_t port_id;
2831         cmdline_fixed_string_t name;
2832         cmdline_fixed_string_t list_name;
2833         cmdline_fixed_string_t list_of_items;
2834 };
2835
2836 static int
2837 parse_reta_config(const char *str,
2838                   struct rte_eth_rss_reta_entry64 *reta_conf,
2839                   uint16_t nb_entries)
2840 {
2841         int i;
2842         unsigned size;
2843         uint16_t hash_index, idx, shift;
2844         uint16_t nb_queue;
2845         char s[256];
2846         const char *p, *p0 = str;
2847         char *end;
2848         enum fieldnames {
2849                 FLD_HASH_INDEX = 0,
2850                 FLD_QUEUE,
2851                 _NUM_FLD
2852         };
2853         unsigned long int_fld[_NUM_FLD];
2854         char *str_fld[_NUM_FLD];
2855
2856         while ((p = strchr(p0,'(')) != NULL) {
2857                 ++p;
2858                 if((p0 = strchr(p,')')) == NULL)
2859                         return -1;
2860
2861                 size = p0 - p;
2862                 if(size >= sizeof(s))
2863                         return -1;
2864
2865                 snprintf(s, sizeof(s), "%.*s", size, p);
2866                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2867                         return -1;
2868                 for (i = 0; i < _NUM_FLD; i++) {
2869                         errno = 0;
2870                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2871                         if (errno != 0 || end == str_fld[i] ||
2872                                         int_fld[i] > 65535)
2873                                 return -1;
2874                 }
2875
2876                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2877                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2878
2879                 if (hash_index >= nb_entries) {
2880                         printf("Invalid RETA hash index=%d\n", hash_index);
2881                         return -1;
2882                 }
2883
2884                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2885                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2886                 reta_conf[idx].mask |= (1ULL << shift);
2887                 reta_conf[idx].reta[shift] = nb_queue;
2888         }
2889
2890         return 0;
2891 }
2892
2893 static void
2894 cmd_set_rss_reta_parsed(void *parsed_result,
2895                         __rte_unused struct cmdline *cl,
2896                         __rte_unused void *data)
2897 {
2898         int ret;
2899         struct rte_eth_dev_info dev_info;
2900         struct rte_eth_rss_reta_entry64 reta_conf[8];
2901         struct cmd_config_rss_reta *res = parsed_result;
2902
2903         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2904         if (ret != 0)
2905                 return;
2906
2907         if (dev_info.reta_size == 0) {
2908                 printf("Redirection table size is 0 which is "
2909                                         "invalid for RSS\n");
2910                 return;
2911         } else
2912                 printf("The reta size of port %d is %u\n",
2913                         res->port_id, dev_info.reta_size);
2914         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2915                 printf("Currently do not support more than %u entries of "
2916                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2917                 return;
2918         }
2919
2920         memset(reta_conf, 0, sizeof(reta_conf));
2921         if (!strcmp(res->list_name, "reta")) {
2922                 if (parse_reta_config(res->list_of_items, reta_conf,
2923                                                 dev_info.reta_size)) {
2924                         printf("Invalid RSS Redirection Table "
2925                                         "config entered\n");
2926                         return;
2927                 }
2928                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2929                                 reta_conf, dev_info.reta_size);
2930                 if (ret != 0)
2931                         printf("Bad redirection table parameter, "
2932                                         "return code = %d \n", ret);
2933         }
2934 }
2935
2936 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2937         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2938 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2939         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2940 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2941         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2942 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2943         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2944 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2945         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2946 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2947         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2948                                  NULL);
2949 cmdline_parse_inst_t cmd_config_rss_reta = {
2950         .f = cmd_set_rss_reta_parsed,
2951         .data = NULL,
2952         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2953         .tokens = {
2954                 (void *)&cmd_config_rss_reta_port,
2955                 (void *)&cmd_config_rss_reta_keyword,
2956                 (void *)&cmd_config_rss_reta_port_id,
2957                 (void *)&cmd_config_rss_reta_name,
2958                 (void *)&cmd_config_rss_reta_list_name,
2959                 (void *)&cmd_config_rss_reta_list_of_items,
2960                 NULL,
2961         },
2962 };
2963
2964 /* *** SHOW PORT RETA INFO *** */
2965 struct cmd_showport_reta {
2966         cmdline_fixed_string_t show;
2967         cmdline_fixed_string_t port;
2968         portid_t port_id;
2969         cmdline_fixed_string_t rss;
2970         cmdline_fixed_string_t reta;
2971         uint16_t size;
2972         cmdline_fixed_string_t list_of_items;
2973 };
2974
2975 static int
2976 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2977                            uint16_t nb_entries,
2978                            char *str)
2979 {
2980         uint32_t size;
2981         const char *p, *p0 = str;
2982         char s[256];
2983         char *end;
2984         char *str_fld[8];
2985         uint16_t i;
2986         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2987                         RTE_RETA_GROUP_SIZE;
2988         int ret;
2989
2990         p = strchr(p0, '(');
2991         if (p == NULL)
2992                 return -1;
2993         p++;
2994         p0 = strchr(p, ')');
2995         if (p0 == NULL)
2996                 return -1;
2997         size = p0 - p;
2998         if (size >= sizeof(s)) {
2999                 printf("The string size exceeds the internal buffer size\n");
3000                 return -1;
3001         }
3002         snprintf(s, sizeof(s), "%.*s", size, p);
3003         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3004         if (ret <= 0 || ret != num) {
3005                 printf("The bits of masks do not match the number of "
3006                                         "reta entries: %u\n", num);
3007                 return -1;
3008         }
3009         for (i = 0; i < ret; i++)
3010                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3011
3012         return 0;
3013 }
3014
3015 static void
3016 cmd_showport_reta_parsed(void *parsed_result,
3017                          __rte_unused struct cmdline *cl,
3018                          __rte_unused void *data)
3019 {
3020         struct cmd_showport_reta *res = parsed_result;
3021         struct rte_eth_rss_reta_entry64 reta_conf[8];
3022         struct rte_eth_dev_info dev_info;
3023         uint16_t max_reta_size;
3024         int ret;
3025
3026         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3027         if (ret != 0)
3028                 return;
3029
3030         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3031         if (res->size == 0 || res->size > max_reta_size) {
3032                 printf("Invalid redirection table size: %u (1-%u)\n",
3033                         res->size, max_reta_size);
3034                 return;
3035         }
3036
3037         memset(reta_conf, 0, sizeof(reta_conf));
3038         if (showport_parse_reta_config(reta_conf, res->size,
3039                                 res->list_of_items) < 0) {
3040                 printf("Invalid string: %s for reta masks\n",
3041                                         res->list_of_items);
3042                 return;
3043         }
3044         port_rss_reta_info(res->port_id, reta_conf, res->size);
3045 }
3046
3047 cmdline_parse_token_string_t cmd_showport_reta_show =
3048         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3049 cmdline_parse_token_string_t cmd_showport_reta_port =
3050         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3051 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3052         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3053 cmdline_parse_token_string_t cmd_showport_reta_rss =
3054         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3055 cmdline_parse_token_string_t cmd_showport_reta_reta =
3056         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3057 cmdline_parse_token_num_t cmd_showport_reta_size =
3058         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3059 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3060         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3061                                         list_of_items, NULL);
3062
3063 cmdline_parse_inst_t cmd_showport_reta = {
3064         .f = cmd_showport_reta_parsed,
3065         .data = NULL,
3066         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3067         .tokens = {
3068                 (void *)&cmd_showport_reta_show,
3069                 (void *)&cmd_showport_reta_port,
3070                 (void *)&cmd_showport_reta_port_id,
3071                 (void *)&cmd_showport_reta_rss,
3072                 (void *)&cmd_showport_reta_reta,
3073                 (void *)&cmd_showport_reta_size,
3074                 (void *)&cmd_showport_reta_list_of_items,
3075                 NULL,
3076         },
3077 };
3078
3079 /* *** Show RSS hash configuration *** */
3080 struct cmd_showport_rss_hash {
3081         cmdline_fixed_string_t show;
3082         cmdline_fixed_string_t port;
3083         portid_t port_id;
3084         cmdline_fixed_string_t rss_hash;
3085         cmdline_fixed_string_t rss_type;
3086         cmdline_fixed_string_t key; /* optional argument */
3087 };
3088
3089 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3090                                 __rte_unused struct cmdline *cl,
3091                                 void *show_rss_key)
3092 {
3093         struct cmd_showport_rss_hash *res = parsed_result;
3094
3095         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3096 }
3097
3098 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3099         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3100 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3101         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3102 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3103         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3104                                  RTE_UINT16);
3105 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3106         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3107                                  "rss-hash");
3108 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3109         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3110
3111 cmdline_parse_inst_t cmd_showport_rss_hash = {
3112         .f = cmd_showport_rss_hash_parsed,
3113         .data = NULL,
3114         .help_str = "show port <port_id> rss-hash",
3115         .tokens = {
3116                 (void *)&cmd_showport_rss_hash_show,
3117                 (void *)&cmd_showport_rss_hash_port,
3118                 (void *)&cmd_showport_rss_hash_port_id,
3119                 (void *)&cmd_showport_rss_hash_rss_hash,
3120                 NULL,
3121         },
3122 };
3123
3124 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3125         .f = cmd_showport_rss_hash_parsed,
3126         .data = (void *)1,
3127         .help_str = "show port <port_id> rss-hash key",
3128         .tokens = {
3129                 (void *)&cmd_showport_rss_hash_show,
3130                 (void *)&cmd_showport_rss_hash_port,
3131                 (void *)&cmd_showport_rss_hash_port_id,
3132                 (void *)&cmd_showport_rss_hash_rss_hash,
3133                 (void *)&cmd_showport_rss_hash_rss_key,
3134                 NULL,
3135         },
3136 };
3137
3138 /* *** Configure DCB *** */
3139 struct cmd_config_dcb {
3140         cmdline_fixed_string_t port;
3141         cmdline_fixed_string_t config;
3142         portid_t port_id;
3143         cmdline_fixed_string_t dcb;
3144         cmdline_fixed_string_t vt;
3145         cmdline_fixed_string_t vt_en;
3146         uint8_t num_tcs;
3147         cmdline_fixed_string_t pfc;
3148         cmdline_fixed_string_t pfc_en;
3149 };
3150
3151 static void
3152 cmd_config_dcb_parsed(void *parsed_result,
3153                         __rte_unused struct cmdline *cl,
3154                         __rte_unused void *data)
3155 {
3156         struct cmd_config_dcb *res = parsed_result;
3157         portid_t port_id = res->port_id;
3158         struct rte_port *port;
3159         uint8_t pfc_en;
3160         int ret;
3161
3162         port = &ports[port_id];
3163         /** Check if the port is not started **/
3164         if (port->port_status != RTE_PORT_STOPPED) {
3165                 printf("Please stop port %d first\n", port_id);
3166                 return;
3167         }
3168
3169         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3170                 printf("The invalid number of traffic class,"
3171                         " only 4 or 8 allowed.\n");
3172                 return;
3173         }
3174
3175         if (nb_fwd_lcores < res->num_tcs) {
3176                 printf("nb_cores shouldn't be less than number of TCs.\n");
3177                 return;
3178         }
3179         if (!strncmp(res->pfc_en, "on", 2))
3180                 pfc_en = 1;
3181         else
3182                 pfc_en = 0;
3183
3184         /* DCB in VT mode */
3185         if (!strncmp(res->vt_en, "on", 2))
3186                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3187                                 (enum rte_eth_nb_tcs)res->num_tcs,
3188                                 pfc_en);
3189         else
3190                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3191                                 (enum rte_eth_nb_tcs)res->num_tcs,
3192                                 pfc_en);
3193
3194
3195         if (ret != 0) {
3196                 printf("Cannot initialize network ports.\n");
3197                 return;
3198         }
3199
3200         cmd_reconfig_device_queue(port_id, 1, 1);
3201 }
3202
3203 cmdline_parse_token_string_t cmd_config_dcb_port =
3204         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3205 cmdline_parse_token_string_t cmd_config_dcb_config =
3206         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3207 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3208         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3209 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3210         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3211 cmdline_parse_token_string_t cmd_config_dcb_vt =
3212         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3213 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3214         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3215 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3216         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3217 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3218         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3219 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3220         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3221
3222 cmdline_parse_inst_t cmd_config_dcb = {
3223         .f = cmd_config_dcb_parsed,
3224         .data = NULL,
3225         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3226         .tokens = {
3227                 (void *)&cmd_config_dcb_port,
3228                 (void *)&cmd_config_dcb_config,
3229                 (void *)&cmd_config_dcb_port_id,
3230                 (void *)&cmd_config_dcb_dcb,
3231                 (void *)&cmd_config_dcb_vt,
3232                 (void *)&cmd_config_dcb_vt_en,
3233                 (void *)&cmd_config_dcb_num_tcs,
3234                 (void *)&cmd_config_dcb_pfc,
3235                 (void *)&cmd_config_dcb_pfc_en,
3236                 NULL,
3237         },
3238 };
3239
3240 /* *** configure number of packets per burst *** */
3241 struct cmd_config_burst {
3242         cmdline_fixed_string_t port;
3243         cmdline_fixed_string_t keyword;
3244         cmdline_fixed_string_t all;
3245         cmdline_fixed_string_t name;
3246         uint16_t value;
3247 };
3248
3249 static void
3250 cmd_config_burst_parsed(void *parsed_result,
3251                         __rte_unused struct cmdline *cl,
3252                         __rte_unused void *data)
3253 {
3254         struct cmd_config_burst *res = parsed_result;
3255         struct rte_eth_dev_info dev_info;
3256         uint16_t rec_nb_pkts;
3257         int ret;
3258
3259         if (!all_ports_stopped()) {
3260                 printf("Please stop all ports first\n");
3261                 return;
3262         }
3263
3264         if (!strcmp(res->name, "burst")) {
3265                 if (res->value == 0) {
3266                         /* If user gives a value of zero, query the PMD for
3267                          * its recommended Rx burst size. Testpmd uses a single
3268                          * size for all ports, so assume all ports are the same
3269                          * NIC model and use the values from Port 0.
3270                          */
3271                         ret = eth_dev_info_get_print_err(0, &dev_info);
3272                         if (ret != 0)
3273                                 return;
3274
3275                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3276
3277                         if (rec_nb_pkts == 0) {
3278                                 printf("PMD does not recommend a burst size.\n"
3279                                         "User provided value must be between"
3280                                         " 1 and %d\n", MAX_PKT_BURST);
3281                                 return;
3282                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3283                                 printf("PMD recommended burst size of %d"
3284                                         " exceeds maximum value of %d\n",
3285                                         rec_nb_pkts, MAX_PKT_BURST);
3286                                 return;
3287                         }
3288                         printf("Using PMD-provided burst value of %d\n",
3289                                 rec_nb_pkts);
3290                         nb_pkt_per_burst = rec_nb_pkts;
3291                 } else if (res->value > MAX_PKT_BURST) {
3292                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3293                         return;
3294                 } else
3295                         nb_pkt_per_burst = res->value;
3296         } else {
3297                 printf("Unknown parameter\n");
3298                 return;
3299         }
3300
3301         init_port_config();
3302
3303         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3304 }
3305
3306 cmdline_parse_token_string_t cmd_config_burst_port =
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3308 cmdline_parse_token_string_t cmd_config_burst_keyword =
3309         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3310 cmdline_parse_token_string_t cmd_config_burst_all =
3311         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3312 cmdline_parse_token_string_t cmd_config_burst_name =
3313         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3314 cmdline_parse_token_num_t cmd_config_burst_value =
3315         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3316
3317 cmdline_parse_inst_t cmd_config_burst = {
3318         .f = cmd_config_burst_parsed,
3319         .data = NULL,
3320         .help_str = "port config all burst <value>",
3321         .tokens = {
3322                 (void *)&cmd_config_burst_port,
3323                 (void *)&cmd_config_burst_keyword,
3324                 (void *)&cmd_config_burst_all,
3325                 (void *)&cmd_config_burst_name,
3326                 (void *)&cmd_config_burst_value,
3327                 NULL,
3328         },
3329 };
3330
3331 /* *** configure rx/tx queues *** */
3332 struct cmd_config_thresh {
3333         cmdline_fixed_string_t port;
3334         cmdline_fixed_string_t keyword;
3335         cmdline_fixed_string_t all;
3336         cmdline_fixed_string_t name;
3337         uint8_t value;
3338 };
3339
3340 static void
3341 cmd_config_thresh_parsed(void *parsed_result,
3342                         __rte_unused struct cmdline *cl,
3343                         __rte_unused void *data)
3344 {
3345         struct cmd_config_thresh *res = parsed_result;
3346
3347         if (!all_ports_stopped()) {
3348                 printf("Please stop all ports first\n");
3349                 return;
3350         }
3351
3352         if (!strcmp(res->name, "txpt"))
3353                 tx_pthresh = res->value;
3354         else if(!strcmp(res->name, "txht"))
3355                 tx_hthresh = res->value;
3356         else if(!strcmp(res->name, "txwt"))
3357                 tx_wthresh = res->value;
3358         else if(!strcmp(res->name, "rxpt"))
3359                 rx_pthresh = res->value;
3360         else if(!strcmp(res->name, "rxht"))
3361                 rx_hthresh = res->value;
3362         else if(!strcmp(res->name, "rxwt"))
3363                 rx_wthresh = res->value;
3364         else {
3365                 printf("Unknown parameter\n");
3366                 return;
3367         }
3368
3369         init_port_config();
3370
3371         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3372 }
3373
3374 cmdline_parse_token_string_t cmd_config_thresh_port =
3375         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3376 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3378 cmdline_parse_token_string_t cmd_config_thresh_all =
3379         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3380 cmdline_parse_token_string_t cmd_config_thresh_name =
3381         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3382                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3383 cmdline_parse_token_num_t cmd_config_thresh_value =
3384         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3385
3386 cmdline_parse_inst_t cmd_config_thresh = {
3387         .f = cmd_config_thresh_parsed,
3388         .data = NULL,
3389         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3390         .tokens = {
3391                 (void *)&cmd_config_thresh_port,
3392                 (void *)&cmd_config_thresh_keyword,
3393                 (void *)&cmd_config_thresh_all,
3394                 (void *)&cmd_config_thresh_name,
3395                 (void *)&cmd_config_thresh_value,
3396                 NULL,
3397         },
3398 };
3399
3400 /* *** configure free/rs threshold *** */
3401 struct cmd_config_threshold {
3402         cmdline_fixed_string_t port;
3403         cmdline_fixed_string_t keyword;
3404         cmdline_fixed_string_t all;
3405         cmdline_fixed_string_t name;
3406         uint16_t value;
3407 };
3408
3409 static void
3410 cmd_config_threshold_parsed(void *parsed_result,
3411                         __rte_unused struct cmdline *cl,
3412                         __rte_unused void *data)
3413 {
3414         struct cmd_config_threshold *res = parsed_result;
3415
3416         if (!all_ports_stopped()) {
3417                 printf("Please stop all ports first\n");
3418                 return;
3419         }
3420
3421         if (!strcmp(res->name, "txfreet"))
3422                 tx_free_thresh = res->value;
3423         else if (!strcmp(res->name, "txrst"))
3424                 tx_rs_thresh = res->value;
3425         else if (!strcmp(res->name, "rxfreet"))
3426                 rx_free_thresh = res->value;
3427         else {
3428                 printf("Unknown parameter\n");
3429                 return;
3430         }
3431
3432         init_port_config();
3433
3434         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3435 }
3436
3437 cmdline_parse_token_string_t cmd_config_threshold_port =
3438         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3439 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3440         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3441                                                                 "config");
3442 cmdline_parse_token_string_t cmd_config_threshold_all =
3443         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3444 cmdline_parse_token_string_t cmd_config_threshold_name =
3445         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3446                                                 "txfreet#txrst#rxfreet");
3447 cmdline_parse_token_num_t cmd_config_threshold_value =
3448         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3449
3450 cmdline_parse_inst_t cmd_config_threshold = {
3451         .f = cmd_config_threshold_parsed,
3452         .data = NULL,
3453         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3454         .tokens = {
3455                 (void *)&cmd_config_threshold_port,
3456                 (void *)&cmd_config_threshold_keyword,
3457                 (void *)&cmd_config_threshold_all,
3458                 (void *)&cmd_config_threshold_name,
3459                 (void *)&cmd_config_threshold_value,
3460                 NULL,
3461         },
3462 };
3463
3464 /* *** stop *** */
3465 struct cmd_stop_result {
3466         cmdline_fixed_string_t stop;
3467 };
3468
3469 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3470                             __rte_unused struct cmdline *cl,
3471                             __rte_unused void *data)
3472 {
3473         stop_packet_forwarding();
3474 }
3475
3476 cmdline_parse_token_string_t cmd_stop_stop =
3477         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3478
3479 cmdline_parse_inst_t cmd_stop = {
3480         .f = cmd_stop_parsed,
3481         .data = NULL,
3482         .help_str = "stop: Stop packet forwarding",
3483         .tokens = {
3484                 (void *)&cmd_stop_stop,
3485                 NULL,
3486         },
3487 };
3488
3489 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3490
3491 unsigned int
3492 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3493                 unsigned int *parsed_items, int check_unique_values)
3494 {
3495         unsigned int nb_item;
3496         unsigned int value;
3497         unsigned int i;
3498         unsigned int j;
3499         int value_ok;
3500         char c;
3501
3502         /*
3503          * First parse all items in the list and store their value.
3504          */
3505         value = 0;
3506         nb_item = 0;
3507         value_ok = 0;
3508         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3509                 c = str[i];
3510                 if ((c >= '0') && (c <= '9')) {
3511                         value = (unsigned int) (value * 10 + (c - '0'));
3512                         value_ok = 1;
3513                         continue;
3514                 }
3515                 if (c != ',') {
3516                         printf("character %c is not a decimal digit\n", c);
3517                         return 0;
3518                 }
3519                 if (! value_ok) {
3520                         printf("No valid value before comma\n");
3521                         return 0;
3522                 }
3523                 if (nb_item < max_items) {
3524                         parsed_items[nb_item] = value;
3525                         value_ok = 0;
3526                         value = 0;
3527                 }
3528                 nb_item++;
3529         }
3530         if (nb_item >= max_items) {
3531                 printf("Number of %s = %u > %u (maximum items)\n",
3532                        item_name, nb_item + 1, max_items);
3533                 return 0;
3534         }
3535         parsed_items[nb_item++] = value;
3536         if (! check_unique_values)
3537                 return nb_item;
3538
3539         /*
3540          * Then, check that all values in the list are differents.
3541          * No optimization here...
3542          */
3543         for (i = 0; i < nb_item; i++) {
3544                 for (j = i + 1; j < nb_item; j++) {
3545                         if (parsed_items[j] == parsed_items[i]) {
3546                                 printf("duplicated %s %u at index %u and %u\n",
3547                                        item_name, parsed_items[i], i, j);
3548                                 return 0;
3549                         }
3550                 }
3551         }
3552         return nb_item;
3553 }
3554
3555 struct cmd_set_list_result {
3556         cmdline_fixed_string_t cmd_keyword;
3557         cmdline_fixed_string_t list_name;
3558         cmdline_fixed_string_t list_of_items;
3559 };
3560
3561 static void cmd_set_list_parsed(void *parsed_result,
3562                                 __rte_unused struct cmdline *cl,
3563                                 __rte_unused void *data)
3564 {
3565         struct cmd_set_list_result *res;
3566         union {
3567                 unsigned int lcorelist[RTE_MAX_LCORE];
3568                 unsigned int portlist[RTE_MAX_ETHPORTS];
3569         } parsed_items;
3570         unsigned int nb_item;
3571
3572         if (test_done == 0) {
3573                 printf("Please stop forwarding first\n");
3574                 return;
3575         }
3576
3577         res = parsed_result;
3578         if (!strcmp(res->list_name, "corelist")) {
3579                 nb_item = parse_item_list(res->list_of_items, "core",
3580                                           RTE_MAX_LCORE,
3581                                           parsed_items.lcorelist, 1);
3582                 if (nb_item > 0) {
3583                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3584                         fwd_config_setup();
3585                 }
3586                 return;
3587         }
3588         if (!strcmp(res->list_name, "portlist")) {
3589                 nb_item = parse_item_list(res->list_of_items, "port",
3590                                           RTE_MAX_ETHPORTS,
3591                                           parsed_items.portlist, 1);
3592                 if (nb_item > 0) {
3593                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3594                         fwd_config_setup();
3595                 }
3596         }
3597 }
3598
3599 cmdline_parse_token_string_t cmd_set_list_keyword =
3600         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3601                                  "set");
3602 cmdline_parse_token_string_t cmd_set_list_name =
3603         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3604                                  "corelist#portlist");
3605 cmdline_parse_token_string_t cmd_set_list_of_items =
3606         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3607                                  NULL);
3608
3609 cmdline_parse_inst_t cmd_set_fwd_list = {
3610         .f = cmd_set_list_parsed,
3611         .data = NULL,
3612         .help_str = "set corelist|portlist <list0[,list1]*>",
3613         .tokens = {
3614                 (void *)&cmd_set_list_keyword,
3615                 (void *)&cmd_set_list_name,
3616                 (void *)&cmd_set_list_of_items,
3617                 NULL,
3618         },
3619 };
3620
3621 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3622
3623 struct cmd_setmask_result {
3624         cmdline_fixed_string_t set;
3625         cmdline_fixed_string_t mask;
3626         uint64_t hexavalue;
3627 };
3628
3629 static void cmd_set_mask_parsed(void *parsed_result,
3630                                 __rte_unused struct cmdline *cl,
3631                                 __rte_unused void *data)
3632 {
3633         struct cmd_setmask_result *res = parsed_result;
3634
3635         if (test_done == 0) {
3636                 printf("Please stop forwarding first\n");
3637                 return;
3638         }
3639         if (!strcmp(res->mask, "coremask")) {
3640                 set_fwd_lcores_mask(res->hexavalue);
3641                 fwd_config_setup();
3642         } else if (!strcmp(res->mask, "portmask")) {
3643                 set_fwd_ports_mask(res->hexavalue);
3644                 fwd_config_setup();
3645         }
3646 }
3647
3648 cmdline_parse_token_string_t cmd_setmask_set =
3649         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3650 cmdline_parse_token_string_t cmd_setmask_mask =
3651         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3652                                  "coremask#portmask");
3653 cmdline_parse_token_num_t cmd_setmask_value =
3654         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3655
3656 cmdline_parse_inst_t cmd_set_fwd_mask = {
3657         .f = cmd_set_mask_parsed,
3658         .data = NULL,
3659         .help_str = "set coremask|portmask <hexadecimal value>",
3660         .tokens = {
3661                 (void *)&cmd_setmask_set,
3662                 (void *)&cmd_setmask_mask,
3663                 (void *)&cmd_setmask_value,
3664                 NULL,
3665         },
3666 };
3667
3668 /*
3669  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3670  */
3671 struct cmd_set_result {
3672         cmdline_fixed_string_t set;
3673         cmdline_fixed_string_t what;
3674         uint16_t value;
3675 };
3676
3677 static void cmd_set_parsed(void *parsed_result,
3678                            __rte_unused struct cmdline *cl,
3679                            __rte_unused void *data)
3680 {
3681         struct cmd_set_result *res = parsed_result;
3682         if (!strcmp(res->what, "nbport")) {
3683                 set_fwd_ports_number(res->value);
3684                 fwd_config_setup();
3685         } else if (!strcmp(res->what, "nbcore")) {
3686                 set_fwd_lcores_number(res->value);
3687                 fwd_config_setup();
3688         } else if (!strcmp(res->what, "burst"))
3689                 set_nb_pkt_per_burst(res->value);
3690         else if (!strcmp(res->what, "verbose"))
3691                 set_verbose_level(res->value);
3692 }
3693
3694 cmdline_parse_token_string_t cmd_set_set =
3695         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3696 cmdline_parse_token_string_t cmd_set_what =
3697         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3698                                  "nbport#nbcore#burst#verbose");
3699 cmdline_parse_token_num_t cmd_set_value =
3700         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3701
3702 cmdline_parse_inst_t cmd_set_numbers = {
3703         .f = cmd_set_parsed,
3704         .data = NULL,
3705         .help_str = "set nbport|nbcore|burst|verbose <value>",
3706         .tokens = {
3707                 (void *)&cmd_set_set,
3708                 (void *)&cmd_set_what,
3709                 (void *)&cmd_set_value,
3710                 NULL,
3711         },
3712 };
3713
3714 /* *** SET LOG LEVEL CONFIGURATION *** */
3715
3716 struct cmd_set_log_result {
3717         cmdline_fixed_string_t set;
3718         cmdline_fixed_string_t log;
3719         cmdline_fixed_string_t type;
3720         uint32_t level;
3721 };
3722
3723 static void
3724 cmd_set_log_parsed(void *parsed_result,
3725                    __rte_unused struct cmdline *cl,
3726                    __rte_unused void *data)
3727 {
3728         struct cmd_set_log_result *res;
3729         int ret;
3730
3731         res = parsed_result;
3732         if (!strcmp(res->type, "global"))
3733                 rte_log_set_global_level(res->level);
3734         else {
3735                 ret = rte_log_set_level_regexp(res->type, res->level);
3736                 if (ret < 0)
3737                         printf("Unable to set log level\n");
3738         }
3739 }
3740
3741 cmdline_parse_token_string_t cmd_set_log_set =
3742         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3743 cmdline_parse_token_string_t cmd_set_log_log =
3744         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3745 cmdline_parse_token_string_t cmd_set_log_type =
3746         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3747 cmdline_parse_token_num_t cmd_set_log_level =
3748         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3749
3750 cmdline_parse_inst_t cmd_set_log = {
3751         .f = cmd_set_log_parsed,
3752         .data = NULL,
3753         .help_str = "set log global|<type> <level>",
3754         .tokens = {
3755                 (void *)&cmd_set_log_set,
3756                 (void *)&cmd_set_log_log,
3757                 (void *)&cmd_set_log_type,
3758                 (void *)&cmd_set_log_level,
3759                 NULL,
3760         },
3761 };
3762
3763 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3764
3765 struct cmd_set_rxoffs_result {
3766         cmdline_fixed_string_t cmd_keyword;
3767         cmdline_fixed_string_t rxoffs;
3768         cmdline_fixed_string_t seg_offsets;
3769 };
3770
3771 static void
3772 cmd_set_rxoffs_parsed(void *parsed_result,
3773                       __rte_unused struct cmdline *cl,
3774                       __rte_unused void *data)
3775 {
3776         struct cmd_set_rxoffs_result *res;
3777         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3778         unsigned int nb_segs;
3779
3780         res = parsed_result;
3781         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3782                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3783         if (nb_segs > 0)
3784                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3785 }
3786
3787 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3789                                  cmd_keyword, "set");
3790 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3791         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3792                                  rxoffs, "rxoffs");
3793 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3794         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3795                                  seg_offsets, NULL);
3796
3797 cmdline_parse_inst_t cmd_set_rxoffs = {
3798         .f = cmd_set_rxoffs_parsed,
3799         .data = NULL,
3800         .help_str = "set rxoffs <len0[,len1]*>",
3801         .tokens = {
3802                 (void *)&cmd_set_rxoffs_keyword,
3803                 (void *)&cmd_set_rxoffs_name,
3804                 (void *)&cmd_set_rxoffs_offsets,
3805                 NULL,
3806         },
3807 };
3808
3809 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3810
3811 struct cmd_set_rxpkts_result {
3812         cmdline_fixed_string_t cmd_keyword;
3813         cmdline_fixed_string_t rxpkts;
3814         cmdline_fixed_string_t seg_lengths;
3815 };
3816
3817 static void
3818 cmd_set_rxpkts_parsed(void *parsed_result,
3819                       __rte_unused struct cmdline *cl,
3820                       __rte_unused void *data)
3821 {
3822         struct cmd_set_rxpkts_result *res;
3823         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3824         unsigned int nb_segs;
3825
3826         res = parsed_result;
3827         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3828                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3829         if (nb_segs > 0)
3830                 set_rx_pkt_segments(seg_lengths, nb_segs);
3831 }
3832
3833 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3835                                  cmd_keyword, "set");
3836 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3837         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3838                                  rxpkts, "rxpkts");
3839 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3840         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3841                                  seg_lengths, NULL);
3842
3843 cmdline_parse_inst_t cmd_set_rxpkts = {
3844         .f = cmd_set_rxpkts_parsed,
3845         .data = NULL,
3846         .help_str = "set rxpkts <len0[,len1]*>",
3847         .tokens = {
3848                 (void *)&cmd_set_rxpkts_keyword,
3849                 (void *)&cmd_set_rxpkts_name,
3850                 (void *)&cmd_set_rxpkts_lengths,
3851                 NULL,
3852         },
3853 };
3854
3855 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3856
3857 struct cmd_set_txpkts_result {
3858         cmdline_fixed_string_t cmd_keyword;
3859         cmdline_fixed_string_t txpkts;
3860         cmdline_fixed_string_t seg_lengths;
3861 };
3862
3863 static void
3864 cmd_set_txpkts_parsed(void *parsed_result,
3865                       __rte_unused struct cmdline *cl,
3866                       __rte_unused void *data)
3867 {
3868         struct cmd_set_txpkts_result *res;
3869         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3870         unsigned int nb_segs;
3871
3872         res = parsed_result;
3873         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3874                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3875         if (nb_segs > 0)
3876                 set_tx_pkt_segments(seg_lengths, nb_segs);
3877 }
3878
3879 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3880         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3881                                  cmd_keyword, "set");
3882 cmdline_parse_token_string_t cmd_set_txpkts_name =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3884                                  txpkts, "txpkts");
3885 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3886         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3887                                  seg_lengths, NULL);
3888
3889 cmdline_parse_inst_t cmd_set_txpkts = {
3890         .f = cmd_set_txpkts_parsed,
3891         .data = NULL,
3892         .help_str = "set txpkts <len0[,len1]*>",
3893         .tokens = {
3894                 (void *)&cmd_set_txpkts_keyword,
3895                 (void *)&cmd_set_txpkts_name,
3896                 (void *)&cmd_set_txpkts_lengths,
3897                 NULL,
3898         },
3899 };
3900
3901 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3902
3903 struct cmd_set_txsplit_result {
3904         cmdline_fixed_string_t cmd_keyword;
3905         cmdline_fixed_string_t txsplit;
3906         cmdline_fixed_string_t mode;
3907 };
3908
3909 static void
3910 cmd_set_txsplit_parsed(void *parsed_result,
3911                       __rte_unused struct cmdline *cl,
3912                       __rte_unused void *data)
3913 {
3914         struct cmd_set_txsplit_result *res;
3915
3916         res = parsed_result;
3917         set_tx_pkt_split(res->mode);
3918 }
3919
3920 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3921         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3922                                  cmd_keyword, "set");
3923 cmdline_parse_token_string_t cmd_set_txsplit_name =
3924         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3925                                  txsplit, "txsplit");
3926 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3927         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3928                                  mode, NULL);
3929
3930 cmdline_parse_inst_t cmd_set_txsplit = {
3931         .f = cmd_set_txsplit_parsed,
3932         .data = NULL,
3933         .help_str = "set txsplit on|off|rand",
3934         .tokens = {
3935                 (void *)&cmd_set_txsplit_keyword,
3936                 (void *)&cmd_set_txsplit_name,
3937                 (void *)&cmd_set_txsplit_mode,
3938                 NULL,
3939         },
3940 };
3941
3942 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3943
3944 struct cmd_set_txtimes_result {
3945         cmdline_fixed_string_t cmd_keyword;
3946         cmdline_fixed_string_t txtimes;
3947         cmdline_fixed_string_t tx_times;
3948 };
3949
3950 static void
3951 cmd_set_txtimes_parsed(void *parsed_result,
3952                        __rte_unused struct cmdline *cl,
3953                        __rte_unused void *data)
3954 {
3955         struct cmd_set_txtimes_result *res;
3956         unsigned int tx_times[2] = {0, 0};
3957         unsigned int n_times;
3958
3959         res = parsed_result;
3960         n_times = parse_item_list(res->tx_times, "tx times",
3961                                   2, tx_times, 0);
3962         if (n_times == 2)
3963                 set_tx_pkt_times(tx_times);
3964 }
3965
3966 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3967         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3968                                  cmd_keyword, "set");
3969 cmdline_parse_token_string_t cmd_set_txtimes_name =
3970         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3971                                  txtimes, "txtimes");
3972 cmdline_parse_token_string_t cmd_set_txtimes_value =
3973         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3974                                  tx_times, NULL);
3975
3976 cmdline_parse_inst_t cmd_set_txtimes = {
3977         .f = cmd_set_txtimes_parsed,
3978         .data = NULL,
3979         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3980         .tokens = {
3981                 (void *)&cmd_set_txtimes_keyword,
3982                 (void *)&cmd_set_txtimes_name,
3983                 (void *)&cmd_set_txtimes_value,
3984                 NULL,
3985         },
3986 };
3987
3988 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3989 struct cmd_rx_vlan_filter_all_result {
3990         cmdline_fixed_string_t rx_vlan;
3991         cmdline_fixed_string_t what;
3992         cmdline_fixed_string_t all;
3993         portid_t port_id;
3994 };
3995
3996 static void
3997 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3998                               __rte_unused struct cmdline *cl,
3999                               __rte_unused void *data)
4000 {
4001         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4002
4003         if (!strcmp(res->what, "add"))
4004                 rx_vlan_all_filter_set(res->port_id, 1);
4005         else
4006                 rx_vlan_all_filter_set(res->port_id, 0);
4007 }
4008
4009 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4010         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4011                                  rx_vlan, "rx_vlan");
4012 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4013         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4014                                  what, "add#rm");
4015 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4016         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4017                                  all, "all");
4018 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4019         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4020                               port_id, RTE_UINT16);
4021
4022 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4023         .f = cmd_rx_vlan_filter_all_parsed,
4024         .data = NULL,
4025         .help_str = "rx_vlan add|rm all <port_id>: "
4026                 "Add/Remove all identifiers to/from the set of VLAN "
4027                 "identifiers filtered by a port",
4028         .tokens = {
4029                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4030                 (void *)&cmd_rx_vlan_filter_all_what,
4031                 (void *)&cmd_rx_vlan_filter_all_all,
4032                 (void *)&cmd_rx_vlan_filter_all_portid,
4033                 NULL,
4034         },
4035 };
4036
4037 /* *** VLAN OFFLOAD SET ON A PORT *** */
4038 struct cmd_vlan_offload_result {
4039         cmdline_fixed_string_t vlan;
4040         cmdline_fixed_string_t set;
4041         cmdline_fixed_string_t vlan_type;
4042         cmdline_fixed_string_t what;
4043         cmdline_fixed_string_t on;
4044         cmdline_fixed_string_t port_id;
4045 };
4046
4047 static void
4048 cmd_vlan_offload_parsed(void *parsed_result,
4049                           __rte_unused struct cmdline *cl,
4050                           __rte_unused void *data)
4051 {
4052         int on;
4053         struct cmd_vlan_offload_result *res = parsed_result;
4054         char *str;
4055         int i, len = 0;
4056         portid_t port_id = 0;
4057         unsigned int tmp;
4058
4059         str = res->port_id;
4060         len = strnlen(str, STR_TOKEN_SIZE);
4061         i = 0;
4062         /* Get port_id first */
4063         while(i < len){
4064                 if(str[i] == ',')
4065                         break;
4066
4067                 i++;
4068         }
4069         str[i]='\0';
4070         tmp = strtoul(str, NULL, 0);
4071         /* If port_id greater that what portid_t can represent, return */
4072         if(tmp >= RTE_MAX_ETHPORTS)
4073                 return;
4074         port_id = (portid_t)tmp;
4075
4076         if (!strcmp(res->on, "on"))
4077                 on = 1;
4078         else
4079                 on = 0;
4080
4081         if (!strcmp(res->what, "strip"))
4082                 rx_vlan_strip_set(port_id,  on);
4083         else if(!strcmp(res->what, "stripq")){
4084                 uint16_t queue_id = 0;
4085
4086                 /* No queue_id, return */
4087                 if(i + 1 >= len) {
4088                         printf("must specify (port,queue_id)\n");
4089                         return;
4090                 }
4091                 tmp = strtoul(str + i + 1, NULL, 0);
4092                 /* If queue_id greater that what 16-bits can represent, return */
4093                 if(tmp > 0xffff)
4094                         return;
4095
4096                 queue_id = (uint16_t)tmp;
4097                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4098         }
4099         else if (!strcmp(res->what, "filter"))
4100                 rx_vlan_filter_set(port_id, on);
4101         else if (!strcmp(res->what, "qinq_strip"))
4102                 rx_vlan_qinq_strip_set(port_id, on);
4103         else
4104                 vlan_extend_set(port_id, on);
4105
4106         return;
4107 }
4108
4109 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4110         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4111                                  vlan, "vlan");
4112 cmdline_parse_token_string_t cmd_vlan_offload_set =
4113         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4114                                  set, "set");
4115 cmdline_parse_token_string_t cmd_vlan_offload_what =
4116         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4117                                 what, "strip#filter#qinq_strip#extend#stripq");
4118 cmdline_parse_token_string_t cmd_vlan_offload_on =
4119         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4120                               on, "on#off");
4121 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4122         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4123                               port_id, NULL);
4124
4125 cmdline_parse_inst_t cmd_vlan_offload = {
4126         .f = cmd_vlan_offload_parsed,
4127         .data = NULL,
4128         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4129                 "<port_id[,queue_id]>: "
4130                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4131         .tokens = {
4132                 (void *)&cmd_vlan_offload_vlan,
4133                 (void *)&cmd_vlan_offload_set,
4134                 (void *)&cmd_vlan_offload_what,
4135                 (void *)&cmd_vlan_offload_on,
4136                 (void *)&cmd_vlan_offload_portid,
4137                 NULL,
4138         },
4139 };
4140
4141 /* *** VLAN TPID SET ON A PORT *** */
4142 struct cmd_vlan_tpid_result {
4143         cmdline_fixed_string_t vlan;
4144         cmdline_fixed_string_t set;
4145         cmdline_fixed_string_t vlan_type;
4146         cmdline_fixed_string_t what;
4147         uint16_t tp_id;
4148         portid_t port_id;
4149 };
4150
4151 static void
4152 cmd_vlan_tpid_parsed(void *parsed_result,
4153                           __rte_unused struct cmdline *cl,
4154                           __rte_unused void *data)
4155 {
4156         struct cmd_vlan_tpid_result *res = parsed_result;
4157         enum rte_vlan_type vlan_type;
4158
4159         if (!strcmp(res->vlan_type, "inner"))
4160                 vlan_type = ETH_VLAN_TYPE_INNER;
4161         else if (!strcmp(res->vlan_type, "outer"))
4162                 vlan_type = ETH_VLAN_TYPE_OUTER;
4163         else {
4164                 printf("Unknown vlan type\n");
4165                 return;
4166         }
4167         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4168 }
4169
4170 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4171         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4172                                  vlan, "vlan");
4173 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4174         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4175                                  set, "set");
4176 cmdline_parse_token_string_t cmd_vlan_type =
4177         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4178                                  vlan_type, "inner#outer");
4179 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4180         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4181                                  what, "tpid");
4182 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4183         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4184                               tp_id, RTE_UINT16);
4185 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4186         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4187                               port_id, RTE_UINT16);
4188
4189 cmdline_parse_inst_t cmd_vlan_tpid = {
4190         .f = cmd_vlan_tpid_parsed,
4191         .data = NULL,
4192         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4193                 "Set the VLAN Ether type",
4194         .tokens = {
4195                 (void *)&cmd_vlan_tpid_vlan,
4196                 (void *)&cmd_vlan_tpid_set,
4197                 (void *)&cmd_vlan_type,
4198                 (void *)&cmd_vlan_tpid_what,
4199                 (void *)&cmd_vlan_tpid_tpid,
4200                 (void *)&cmd_vlan_tpid_portid,
4201                 NULL,
4202         },
4203 };
4204
4205 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4206 struct cmd_rx_vlan_filter_result {
4207         cmdline_fixed_string_t rx_vlan;
4208         cmdline_fixed_string_t what;
4209         uint16_t vlan_id;
4210         portid_t port_id;
4211 };
4212
4213 static void
4214 cmd_rx_vlan_filter_parsed(void *parsed_result,
4215                           __rte_unused struct cmdline *cl,
4216                           __rte_unused void *data)
4217 {
4218         struct cmd_rx_vlan_filter_result *res = parsed_result;
4219
4220         if (!strcmp(res->what, "add"))
4221                 rx_vft_set(res->port_id, res->vlan_id, 1);
4222         else
4223                 rx_vft_set(res->port_id, res->vlan_id, 0);
4224 }
4225
4226 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4227         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4228                                  rx_vlan, "rx_vlan");
4229 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4230         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4231                                  what, "add#rm");
4232 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4233         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4234                               vlan_id, RTE_UINT16);
4235 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4236         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4237                               port_id, RTE_UINT16);
4238
4239 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4240         .f = cmd_rx_vlan_filter_parsed,
4241         .data = NULL,
4242         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4243                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4244                 "identifiers filtered by a port",
4245         .tokens = {
4246                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4247                 (void *)&cmd_rx_vlan_filter_what,
4248                 (void *)&cmd_rx_vlan_filter_vlanid,
4249                 (void *)&cmd_rx_vlan_filter_portid,
4250                 NULL,
4251         },
4252 };
4253
4254 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4255 struct cmd_tx_vlan_set_result {
4256         cmdline_fixed_string_t tx_vlan;
4257         cmdline_fixed_string_t set;
4258         portid_t port_id;
4259         uint16_t vlan_id;
4260 };
4261
4262 static void
4263 cmd_tx_vlan_set_parsed(void *parsed_result,
4264                        __rte_unused struct cmdline *cl,
4265                        __rte_unused void *data)
4266 {
4267         struct cmd_tx_vlan_set_result *res = parsed_result;
4268
4269         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4270                 return;
4271
4272         if (!port_is_stopped(res->port_id)) {
4273                 printf("Please stop port %d first\n", res->port_id);
4274                 return;
4275         }
4276
4277         tx_vlan_set(res->port_id, res->vlan_id);
4278
4279         cmd_reconfig_device_queue(res->port_id, 1, 1);
4280 }
4281
4282 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4283         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4284                                  tx_vlan, "tx_vlan");
4285 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4286         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4287                                  set, "set");
4288 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4290                               port_id, RTE_UINT16);
4291 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4292         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4293                               vlan_id, RTE_UINT16);
4294
4295 cmdline_parse_inst_t cmd_tx_vlan_set = {
4296         .f = cmd_tx_vlan_set_parsed,
4297         .data = NULL,
4298         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4299                 "Enable hardware insertion of a single VLAN header "
4300                 "with a given TAG Identifier in packets sent on a port",
4301         .tokens = {
4302                 (void *)&cmd_tx_vlan_set_tx_vlan,
4303                 (void *)&cmd_tx_vlan_set_set,
4304                 (void *)&cmd_tx_vlan_set_portid,
4305                 (void *)&cmd_tx_vlan_set_vlanid,
4306                 NULL,
4307         },
4308 };
4309
4310 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4311 struct cmd_tx_vlan_set_qinq_result {
4312         cmdline_fixed_string_t tx_vlan;
4313         cmdline_fixed_string_t set;
4314         portid_t port_id;
4315         uint16_t vlan_id;
4316         uint16_t vlan_id_outer;
4317 };
4318
4319 static void
4320 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4321                             __rte_unused struct cmdline *cl,
4322                             __rte_unused void *data)
4323 {
4324         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4325
4326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4327                 return;
4328
4329         if (!port_is_stopped(res->port_id)) {
4330                 printf("Please stop port %d first\n", res->port_id);
4331                 return;
4332         }
4333
4334         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4335
4336         cmd_reconfig_device_queue(res->port_id, 1, 1);
4337 }
4338
4339 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4340         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4341                 tx_vlan, "tx_vlan");
4342 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4343         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4344                 set, "set");
4345 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4346         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4347                 port_id, RTE_UINT16);
4348 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4349         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4350                 vlan_id, RTE_UINT16);
4351 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4352         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4353                 vlan_id_outer, RTE_UINT16);
4354
4355 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4356         .f = cmd_tx_vlan_set_qinq_parsed,
4357         .data = NULL,
4358         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4359                 "Enable hardware insertion of double VLAN header "
4360                 "with given TAG Identifiers in packets sent on a port",
4361         .tokens = {
4362                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4363                 (void *)&cmd_tx_vlan_set_qinq_set,
4364                 (void *)&cmd_tx_vlan_set_qinq_portid,
4365                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4366                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4367                 NULL,
4368         },
4369 };
4370
4371 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4372 struct cmd_tx_vlan_set_pvid_result {
4373         cmdline_fixed_string_t tx_vlan;
4374         cmdline_fixed_string_t set;
4375         cmdline_fixed_string_t pvid;
4376         portid_t port_id;
4377         uint16_t vlan_id;
4378         cmdline_fixed_string_t mode;
4379 };
4380
4381 static void
4382 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4383                             __rte_unused struct cmdline *cl,
4384                             __rte_unused void *data)
4385 {
4386         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4387
4388         if (strcmp(res->mode, "on") == 0)
4389                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4390         else
4391                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4392 }
4393
4394 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4395         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4396                                  tx_vlan, "tx_vlan");
4397 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4398         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4399                                  set, "set");
4400 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4401         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4402                                  pvid, "pvid");
4403 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4404         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4405                              port_id, RTE_UINT16);
4406 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4407         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4408                               vlan_id, RTE_UINT16);
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4411                                  mode, "on#off");
4412
4413 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4414         .f = cmd_tx_vlan_set_pvid_parsed,
4415         .data = NULL,
4416         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4417         .tokens = {
4418                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4419                 (void *)&cmd_tx_vlan_set_pvid_set,
4420                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4421                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4422                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4423                 (void *)&cmd_tx_vlan_set_pvid_mode,
4424                 NULL,
4425         },
4426 };
4427
4428 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4429 struct cmd_tx_vlan_reset_result {
4430         cmdline_fixed_string_t tx_vlan;
4431         cmdline_fixed_string_t reset;
4432         portid_t port_id;
4433 };
4434
4435 static void
4436 cmd_tx_vlan_reset_parsed(void *parsed_result,
4437                          __rte_unused struct cmdline *cl,
4438                          __rte_unused void *data)
4439 {
4440         struct cmd_tx_vlan_reset_result *res = parsed_result;
4441
4442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4443                 return;
4444
4445         if (!port_is_stopped(res->port_id)) {
4446                 printf("Please stop port %d first\n", res->port_id);
4447                 return;
4448         }
4449
4450         tx_vlan_reset(res->port_id);
4451
4452         cmd_reconfig_device_queue(res->port_id, 1, 1);
4453 }
4454
4455 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4457                                  tx_vlan, "tx_vlan");
4458 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4460                                  reset, "reset");
4461 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4462         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4463                               port_id, RTE_UINT16);
4464
4465 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4466         .f = cmd_tx_vlan_reset_parsed,
4467         .data = NULL,
4468         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4469                 "VLAN header in packets sent on a port",
4470         .tokens = {
4471                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4472                 (void *)&cmd_tx_vlan_reset_reset,
4473                 (void *)&cmd_tx_vlan_reset_portid,
4474                 NULL,
4475         },
4476 };
4477
4478
4479 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4480 struct cmd_csum_result {
4481         cmdline_fixed_string_t csum;
4482         cmdline_fixed_string_t mode;
4483         cmdline_fixed_string_t proto;
4484         cmdline_fixed_string_t hwsw;
4485         portid_t port_id;
4486 };
4487
4488 static void
4489 csum_show(int port_id)
4490 {
4491         struct rte_eth_dev_info dev_info;
4492         uint64_t tx_offloads;
4493         int ret;
4494
4495         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4496         printf("Parse tunnel is %s\n",
4497                 (ports[port_id].parse_tunnel) ? "on" : "off");
4498         printf("IP checksum offload is %s\n",
4499                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4500         printf("UDP checksum offload is %s\n",
4501                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4502         printf("TCP checksum offload is %s\n",
4503                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4504         printf("SCTP checksum offload is %s\n",
4505                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4506         printf("Outer-Ip checksum offload is %s\n",
4507                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4508         printf("Outer-Udp checksum offload is %s\n",
4509                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4510
4511         /* display warnings if configuration is not supported by the NIC */
4512         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4513         if (ret != 0)
4514                 return;
4515
4516         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4517                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4518                 printf("Warning: hardware IP checksum enabled but not "
4519                         "supported by port %d\n", port_id);
4520         }
4521         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4522                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4523                 printf("Warning: hardware UDP checksum enabled but not "
4524                         "supported by port %d\n", port_id);
4525         }
4526         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4527                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4528                 printf("Warning: hardware TCP checksum enabled but not "
4529                         "supported by port %d\n", port_id);
4530         }
4531         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4532                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4533                 printf("Warning: hardware SCTP checksum enabled but not "
4534                         "supported by port %d\n", port_id);
4535         }
4536         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4537                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4538                 printf("Warning: hardware outer IP checksum enabled but not "
4539                         "supported by port %d\n", port_id);
4540         }
4541         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4542                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4543                         == 0) {
4544                 printf("Warning: hardware outer UDP checksum enabled but not "
4545                         "supported by port %d\n", port_id);
4546         }
4547 }
4548
4549 static void
4550 cmd_config_queue_tx_offloads(struct rte_port *port)
4551 {
4552         int k;
4553
4554         /* Apply queue tx offloads configuration */
4555         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4556                 port->tx_conf[k].offloads =
4557                         port->dev_conf.txmode.offloads;
4558 }
4559
4560 static void
4561 cmd_csum_parsed(void *parsed_result,
4562                        __rte_unused struct cmdline *cl,
4563                        __rte_unused void *data)
4564 {
4565         struct cmd_csum_result *res = parsed_result;
4566         int hw = 0;
4567         uint64_t csum_offloads = 0;
4568         struct rte_eth_dev_info dev_info;
4569         int ret;
4570
4571         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4572                 printf("invalid port %d\n", res->port_id);
4573                 return;
4574         }
4575         if (!port_is_stopped(res->port_id)) {
4576                 printf("Please stop port %d first\n", res->port_id);
4577                 return;
4578         }
4579
4580         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4581         if (ret != 0)
4582                 return;
4583
4584         if (!strcmp(res->mode, "set")) {
4585
4586                 if (!strcmp(res->hwsw, "hw"))
4587                         hw = 1;
4588
4589                 if (!strcmp(res->proto, "ip")) {
4590                         if (hw == 0 || (dev_info.tx_offload_capa &
4591                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4592                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4593                         } else {
4594                                 printf("IP checksum offload is not supported "
4595                                        "by port %u\n", res->port_id);
4596                         }
4597                 } else if (!strcmp(res->proto, "udp")) {
4598                         if (hw == 0 || (dev_info.tx_offload_capa &
4599                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4600                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4601                         } else {
4602                                 printf("UDP checksum offload is not supported "
4603                                        "by port %u\n", res->port_id);
4604                         }
4605                 } else if (!strcmp(res->proto, "tcp")) {
4606                         if (hw == 0 || (dev_info.tx_offload_capa &
4607                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4608                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4609                         } else {
4610                                 printf("TCP checksum offload is not supported "
4611                                        "by port %u\n", res->port_id);
4612                         }
4613                 } else if (!strcmp(res->proto, "sctp")) {
4614                         if (hw == 0 || (dev_info.tx_offload_capa &
4615                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4616                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4617                         } else {
4618                                 printf("SCTP checksum offload is not supported "
4619                                        "by port %u\n", res->port_id);
4620                         }
4621                 } else if (!strcmp(res->proto, "outer-ip")) {
4622                         if (hw == 0 || (dev_info.tx_offload_capa &
4623                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4624                                 csum_offloads |=
4625                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4626                         } else {
4627                                 printf("Outer IP checksum offload is not "
4628                                        "supported by port %u\n", res->port_id);
4629                         }
4630                 } else if (!strcmp(res->proto, "outer-udp")) {
4631                         if (hw == 0 || (dev_info.tx_offload_capa &
4632                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4633                                 csum_offloads |=
4634                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4635                         } else {
4636                                 printf("Outer UDP checksum offload is not "
4637                                        "supported by port %u\n", res->port_id);
4638                         }
4639                 }
4640
4641                 if (hw) {
4642                         ports[res->port_id].dev_conf.txmode.offloads |=
4643                                                         csum_offloads;
4644                 } else {
4645                         ports[res->port_id].dev_conf.txmode.offloads &=
4646                                                         (~csum_offloads);
4647                 }
4648                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4649         }
4650         csum_show(res->port_id);
4651
4652         cmd_reconfig_device_queue(res->port_id, 1, 1);
4653 }
4654
4655 cmdline_parse_token_string_t cmd_csum_csum =
4656         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4657                                 csum, "csum");
4658 cmdline_parse_token_string_t cmd_csum_mode =
4659         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4660                                 mode, "set");
4661 cmdline_parse_token_string_t cmd_csum_proto =
4662         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4663                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4664 cmdline_parse_token_string_t cmd_csum_hwsw =
4665         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4666                                 hwsw, "hw#sw");
4667 cmdline_parse_token_num_t cmd_csum_portid =
4668         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4669                                 port_id, RTE_UINT16);
4670
4671 cmdline_parse_inst_t cmd_csum_set = {
4672         .f = cmd_csum_parsed,
4673         .data = NULL,
4674         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4675                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4676                 "using csum forward engine",
4677         .tokens = {
4678                 (void *)&cmd_csum_csum,
4679                 (void *)&cmd_csum_mode,
4680                 (void *)&cmd_csum_proto,
4681                 (void *)&cmd_csum_hwsw,
4682                 (void *)&cmd_csum_portid,
4683                 NULL,
4684         },
4685 };
4686
4687 cmdline_parse_token_string_t cmd_csum_mode_show =
4688         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4689                                 mode, "show");
4690
4691 cmdline_parse_inst_t cmd_csum_show = {
4692         .f = cmd_csum_parsed,
4693         .data = NULL,
4694         .help_str = "csum show <port_id>: Show checksum offload configuration",
4695         .tokens = {
4696                 (void *)&cmd_csum_csum,
4697                 (void *)&cmd_csum_mode_show,
4698                 (void *)&cmd_csum_portid,
4699                 NULL,
4700         },
4701 };
4702
4703 /* Enable/disable tunnel parsing */
4704 struct cmd_csum_tunnel_result {
4705         cmdline_fixed_string_t csum;
4706         cmdline_fixed_string_t parse;
4707         cmdline_fixed_string_t onoff;
4708         portid_t port_id;
4709 };
4710
4711 static void
4712 cmd_csum_tunnel_parsed(void *parsed_result,
4713                        __rte_unused struct cmdline *cl,
4714                        __rte_unused void *data)
4715 {
4716         struct cmd_csum_tunnel_result *res = parsed_result;
4717
4718         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4719                 return;
4720
4721         if (!strcmp(res->onoff, "on"))
4722                 ports[res->port_id].parse_tunnel = 1;
4723         else
4724                 ports[res->port_id].parse_tunnel = 0;
4725
4726         csum_show(res->port_id);
4727 }
4728
4729 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4730         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4731                                 csum, "csum");
4732 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4733         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4734                                 parse, "parse-tunnel");
4735 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4736         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4737                                 onoff, "on#off");
4738 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4739         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4740                                 port_id, RTE_UINT16);
4741
4742 cmdline_parse_inst_t cmd_csum_tunnel = {
4743         .f = cmd_csum_tunnel_parsed,
4744         .data = NULL,
4745         .help_str = "csum parse-tunnel on|off <port_id>: "
4746                 "Enable/Disable parsing of tunnels for csum engine",
4747         .tokens = {
4748                 (void *)&cmd_csum_tunnel_csum,
4749                 (void *)&cmd_csum_tunnel_parse,
4750                 (void *)&cmd_csum_tunnel_onoff,
4751                 (void *)&cmd_csum_tunnel_portid,
4752                 NULL,
4753         },
4754 };
4755
4756 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4757 struct cmd_tso_set_result {
4758         cmdline_fixed_string_t tso;
4759         cmdline_fixed_string_t mode;
4760         uint16_t tso_segsz;
4761         portid_t port_id;
4762 };
4763
4764 static void
4765 cmd_tso_set_parsed(void *parsed_result,
4766                        __rte_unused struct cmdline *cl,
4767                        __rte_unused void *data)
4768 {
4769         struct cmd_tso_set_result *res = parsed_result;
4770         struct rte_eth_dev_info dev_info;
4771         int ret;
4772
4773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4774                 return;
4775         if (!port_is_stopped(res->port_id)) {
4776                 printf("Please stop port %d first\n", res->port_id);
4777                 return;
4778         }
4779
4780         if (!strcmp(res->mode, "set"))
4781                 ports[res->port_id].tso_segsz = res->tso_segsz;
4782
4783         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4784         if (ret != 0)
4785                 return;
4786
4787         if ((ports[res->port_id].tso_segsz != 0) &&
4788                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4789                 printf("Error: TSO is not supported by port %d\n",
4790                        res->port_id);
4791                 return;
4792         }
4793
4794         if (ports[res->port_id].tso_segsz == 0) {
4795                 ports[res->port_id].dev_conf.txmode.offloads &=
4796                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4797                 printf("TSO for non-tunneled packets is disabled\n");
4798         } else {
4799                 ports[res->port_id].dev_conf.txmode.offloads |=
4800                                                 DEV_TX_OFFLOAD_TCP_TSO;
4801                 printf("TSO segment size for non-tunneled packets is %d\n",
4802                         ports[res->port_id].tso_segsz);
4803         }
4804         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4805
4806         /* display warnings if configuration is not supported by the NIC */
4807         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4808         if (ret != 0)
4809                 return;
4810
4811         if ((ports[res->port_id].tso_segsz != 0) &&
4812                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4813                 printf("Warning: TSO enabled but not "
4814                         "supported by port %d\n", res->port_id);
4815         }
4816
4817         cmd_reconfig_device_queue(res->port_id, 1, 1);
4818 }
4819
4820 cmdline_parse_token_string_t cmd_tso_set_tso =
4821         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4822                                 tso, "tso");
4823 cmdline_parse_token_string_t cmd_tso_set_mode =
4824         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4825                                 mode, "set");
4826 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4827         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4828                                 tso_segsz, RTE_UINT16);
4829 cmdline_parse_token_num_t cmd_tso_set_portid =
4830         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4831                                 port_id, RTE_UINT16);
4832
4833 cmdline_parse_inst_t cmd_tso_set = {
4834         .f = cmd_tso_set_parsed,
4835         .data = NULL,
4836         .help_str = "tso set <tso_segsz> <port_id>: "
4837                 "Set TSO segment size of non-tunneled packets for csum engine "
4838                 "(0 to disable)",
4839         .tokens = {
4840                 (void *)&cmd_tso_set_tso,
4841                 (void *)&cmd_tso_set_mode,
4842                 (void *)&cmd_tso_set_tso_segsz,
4843                 (void *)&cmd_tso_set_portid,
4844                 NULL,
4845         },
4846 };
4847
4848 cmdline_parse_token_string_t cmd_tso_show_mode =
4849         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4850                                 mode, "show");
4851
4852
4853 cmdline_parse_inst_t cmd_tso_show = {
4854         .f = cmd_tso_set_parsed,
4855         .data = NULL,
4856         .help_str = "tso show <port_id>: "
4857                 "Show TSO segment size of non-tunneled packets for csum engine",
4858         .tokens = {
4859                 (void *)&cmd_tso_set_tso,
4860                 (void *)&cmd_tso_show_mode,
4861                 (void *)&cmd_tso_set_portid,
4862                 NULL,
4863         },
4864 };
4865
4866 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4867 struct cmd_tunnel_tso_set_result {
4868         cmdline_fixed_string_t tso;
4869         cmdline_fixed_string_t mode;
4870         uint16_t tso_segsz;
4871         portid_t port_id;
4872 };
4873
4874 static struct rte_eth_dev_info
4875 check_tunnel_tso_nic_support(portid_t port_id)
4876 {
4877         struct rte_eth_dev_info dev_info;
4878
4879         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4880                 return dev_info;
4881
4882         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4883                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4884                        "not enabled for port %d\n", port_id);
4885         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4886                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4887                        "not enabled for port %d\n", port_id);
4888         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4889                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4890                        "not enabled for port %d\n", port_id);
4891         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4892                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4893                        "not enabled for port %d\n", port_id);
4894         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4895                 printf("Warning: IP TUNNEL TSO not supported therefore "
4896                        "not enabled for port %d\n", port_id);
4897         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4898                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4899                        "not enabled for port %d\n", port_id);
4900         return dev_info;
4901 }
4902
4903 static void
4904 cmd_tunnel_tso_set_parsed(void *parsed_result,
4905                           __rte_unused struct cmdline *cl,
4906                           __rte_unused void *data)
4907 {
4908         struct cmd_tunnel_tso_set_result *res = parsed_result;
4909         struct rte_eth_dev_info dev_info;
4910
4911         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4912                 return;
4913         if (!port_is_stopped(res->port_id)) {
4914                 printf("Please stop port %d first\n", res->port_id);
4915                 return;
4916         }
4917
4918         if (!strcmp(res->mode, "set"))
4919                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4920
4921         dev_info = check_tunnel_tso_nic_support(res->port_id);
4922         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4923                 ports[res->port_id].dev_conf.txmode.offloads &=
4924                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4925                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4926                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4927                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4928                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4929                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4930                 printf("TSO for tunneled packets is disabled\n");
4931         } else {
4932                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4933                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4934                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4935                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4936                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4937                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4938
4939                 ports[res->port_id].dev_conf.txmode.offloads |=
4940                         (tso_offloads & dev_info.tx_offload_capa);
4941                 printf("TSO segment size for tunneled packets is %d\n",
4942                         ports[res->port_id].tunnel_tso_segsz);
4943
4944                 /* Below conditions are needed to make it work:
4945                  * (1) tunnel TSO is supported by the NIC;
4946                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4947                  * are recognized;
4948                  * (3) for tunneled pkts with outer L3 of IPv4,
4949                  * "csum set outer-ip" must be set to hw, because after tso,
4950                  * total_len of outer IP header is changed, and the checksum
4951                  * of outer IP header calculated by sw should be wrong; that
4952                  * is not necessary for IPv6 tunneled pkts because there's no
4953                  * checksum in IP header anymore.
4954                  */
4955
4956                 if (!ports[res->port_id].parse_tunnel)
4957                         printf("Warning: csum parse_tunnel must be set "
4958                                 "so that tunneled packets are recognized\n");
4959                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4960                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4961                         printf("Warning: csum set outer-ip must be set to hw "
4962                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4963         }
4964
4965         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4966         cmd_reconfig_device_queue(res->port_id, 1, 1);
4967 }
4968
4969 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4970         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4971                                 tso, "tunnel_tso");
4972 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4973         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4974                                 mode, "set");
4975 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4976         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4977                                 tso_segsz, RTE_UINT16);
4978 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4979         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4980                                 port_id, RTE_UINT16);
4981
4982 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4983         .f = cmd_tunnel_tso_set_parsed,
4984         .data = NULL,
4985         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4986                 "Set TSO segment size of tunneled packets for csum engine "
4987                 "(0 to disable)",
4988         .tokens = {
4989                 (void *)&cmd_tunnel_tso_set_tso,
4990                 (void *)&cmd_tunnel_tso_set_mode,
4991                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4992                 (void *)&cmd_tunnel_tso_set_portid,
4993                 NULL,
4994         },
4995 };
4996
4997 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4999                                 mode, "show");
5000
5001
5002 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5003         .f = cmd_tunnel_tso_set_parsed,
5004         .data = NULL,
5005         .help_str = "tunnel_tso show <port_id> "
5006                 "Show TSO segment size of tunneled packets for csum engine",
5007         .tokens = {
5008                 (void *)&cmd_tunnel_tso_set_tso,
5009                 (void *)&cmd_tunnel_tso_show_mode,
5010                 (void *)&cmd_tunnel_tso_set_portid,
5011                 NULL,
5012         },
5013 };
5014
5015 /* *** SET GRO FOR A PORT *** */
5016 struct cmd_gro_enable_result {
5017         cmdline_fixed_string_t cmd_set;
5018         cmdline_fixed_string_t cmd_port;
5019         cmdline_fixed_string_t cmd_keyword;
5020         cmdline_fixed_string_t cmd_onoff;
5021         portid_t cmd_pid;
5022 };
5023
5024 static void
5025 cmd_gro_enable_parsed(void *parsed_result,
5026                 __rte_unused struct cmdline *cl,
5027                 __rte_unused void *data)
5028 {
5029         struct cmd_gro_enable_result *res;
5030
5031         res = parsed_result;
5032         if (!strcmp(res->cmd_keyword, "gro"))
5033                 setup_gro(res->cmd_onoff, res->cmd_pid);
5034 }
5035
5036 cmdline_parse_token_string_t cmd_gro_enable_set =
5037         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5038                         cmd_set, "set");
5039 cmdline_parse_token_string_t cmd_gro_enable_port =
5040         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5041                         cmd_keyword, "port");
5042 cmdline_parse_token_num_t cmd_gro_enable_pid =
5043         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5044                         cmd_pid, RTE_UINT16);
5045 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5046         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5047                         cmd_keyword, "gro");
5048 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5049         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5050                         cmd_onoff, "on#off");
5051
5052 cmdline_parse_inst_t cmd_gro_enable = {
5053         .f = cmd_gro_enable_parsed,
5054         .data = NULL,
5055         .help_str = "set port <port_id> gro on|off",
5056         .tokens = {
5057                 (void *)&cmd_gro_enable_set,
5058                 (void *)&cmd_gro_enable_port,
5059                 (void *)&cmd_gro_enable_pid,
5060                 (void *)&cmd_gro_enable_keyword,
5061                 (void *)&cmd_gro_enable_onoff,
5062                 NULL,
5063         },
5064 };
5065
5066 /* *** DISPLAY GRO CONFIGURATION *** */
5067 struct cmd_gro_show_result {
5068         cmdline_fixed_string_t cmd_show;
5069         cmdline_fixed_string_t cmd_port;
5070         cmdline_fixed_string_t cmd_keyword;
5071         portid_t cmd_pid;
5072 };
5073
5074 static void
5075 cmd_gro_show_parsed(void *parsed_result,
5076                 __rte_unused struct cmdline *cl,
5077                 __rte_unused void *data)
5078 {
5079         struct cmd_gro_show_result *res;
5080
5081         res = parsed_result;
5082         if (!strcmp(res->cmd_keyword, "gro"))
5083                 show_gro(res->cmd_pid);
5084 }
5085
5086 cmdline_parse_token_string_t cmd_gro_show_show =
5087         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5088                         cmd_show, "show");
5089 cmdline_parse_token_string_t cmd_gro_show_port =
5090         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5091                         cmd_port, "port");
5092 cmdline_parse_token_num_t cmd_gro_show_pid =
5093         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5094                         cmd_pid, RTE_UINT16);
5095 cmdline_parse_token_string_t cmd_gro_show_keyword =
5096         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5097                         cmd_keyword, "gro");
5098
5099 cmdline_parse_inst_t cmd_gro_show = {
5100         .f = cmd_gro_show_parsed,
5101         .data = NULL,
5102         .help_str = "show port <port_id> gro",
5103         .tokens = {
5104                 (void *)&cmd_gro_show_show,
5105                 (void *)&cmd_gro_show_port,
5106                 (void *)&cmd_gro_show_pid,
5107                 (void *)&cmd_gro_show_keyword,
5108                 NULL,
5109         },
5110 };
5111
5112 /* *** SET FLUSH CYCLES FOR GRO *** */
5113 struct cmd_gro_flush_result {
5114         cmdline_fixed_string_t cmd_set;
5115         cmdline_fixed_string_t cmd_keyword;
5116         cmdline_fixed_string_t cmd_flush;
5117         uint8_t cmd_cycles;
5118 };
5119
5120 static void
5121 cmd_gro_flush_parsed(void *parsed_result,
5122                 __rte_unused struct cmdline *cl,
5123                 __rte_unused void *data)
5124 {
5125         struct cmd_gro_flush_result *res;
5126
5127         res = parsed_result;
5128         if ((!strcmp(res->cmd_keyword, "gro")) &&
5129                         (!strcmp(res->cmd_flush, "flush")))
5130                 setup_gro_flush_cycles(res->cmd_cycles);
5131 }
5132
5133 cmdline_parse_token_string_t cmd_gro_flush_set =
5134         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5135                         cmd_set, "set");
5136 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5137         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5138                         cmd_keyword, "gro");
5139 cmdline_parse_token_string_t cmd_gro_flush_flush =
5140         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5141                         cmd_flush, "flush");
5142 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5143         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5144                         cmd_cycles, RTE_UINT8);
5145
5146 cmdline_parse_inst_t cmd_gro_flush = {
5147         .f = cmd_gro_flush_parsed,
5148         .data = NULL,
5149         .help_str = "set gro flush <cycles>",
5150         .tokens = {
5151                 (void *)&cmd_gro_flush_set,
5152                 (void *)&cmd_gro_flush_keyword,
5153                 (void *)&cmd_gro_flush_flush,
5154                 (void *)&cmd_gro_flush_cycles,
5155                 NULL,
5156         },
5157 };
5158
5159 /* *** ENABLE/DISABLE GSO *** */
5160 struct cmd_gso_enable_result {
5161         cmdline_fixed_string_t cmd_set;
5162         cmdline_fixed_string_t cmd_port;
5163         cmdline_fixed_string_t cmd_keyword;
5164         cmdline_fixed_string_t cmd_mode;
5165         portid_t cmd_pid;
5166 };
5167
5168 static void
5169 cmd_gso_enable_parsed(void *parsed_result,
5170                 __rte_unused struct cmdline *cl,
5171                 __rte_unused void *data)
5172 {
5173         struct cmd_gso_enable_result *res;
5174
5175         res = parsed_result;
5176         if (!strcmp(res->cmd_keyword, "gso"))
5177                 setup_gso(res->cmd_mode, res->cmd_pid);
5178 }
5179
5180 cmdline_parse_token_string_t cmd_gso_enable_set =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5182                         cmd_set, "set");
5183 cmdline_parse_token_string_t cmd_gso_enable_port =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5185                         cmd_port, "port");
5186 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5188                         cmd_keyword, "gso");
5189 cmdline_parse_token_string_t cmd_gso_enable_mode =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5191                         cmd_mode, "on#off");
5192 cmdline_parse_token_num_t cmd_gso_enable_pid =
5193         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5194                         cmd_pid, RTE_UINT16);
5195
5196 cmdline_parse_inst_t cmd_gso_enable = {
5197         .f = cmd_gso_enable_parsed,
5198         .data = NULL,
5199         .help_str = "set port <port_id> gso on|off",
5200         .tokens = {
5201                 (void *)&cmd_gso_enable_set,
5202                 (void *)&cmd_gso_enable_port,
5203                 (void *)&cmd_gso_enable_pid,
5204                 (void *)&cmd_gso_enable_keyword,
5205                 (void *)&cmd_gso_enable_mode,
5206                 NULL,
5207         },
5208 };
5209
5210 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5211 struct cmd_gso_size_result {
5212         cmdline_fixed_string_t cmd_set;
5213         cmdline_fixed_string_t cmd_keyword;
5214         cmdline_fixed_string_t cmd_segsz;
5215         uint16_t cmd_size;
5216 };
5217
5218 static void
5219 cmd_gso_size_parsed(void *parsed_result,
5220                        __rte_unused struct cmdline *cl,
5221                        __rte_unused void *data)
5222 {
5223         struct cmd_gso_size_result *res = parsed_result;
5224
5225         if (test_done == 0) {
5226                 printf("Before setting GSO segsz, please first"
5227                                 " stop forwarding\n");
5228                 return;
5229         }
5230
5231         if (!strcmp(res->cmd_keyword, "gso") &&
5232                         !strcmp(res->cmd_segsz, "segsz")) {
5233                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5234                         printf("gso_size should be larger than %zu."
5235                                         " Please input a legal value\n",
5236                                         RTE_GSO_SEG_SIZE_MIN);
5237                 else
5238                         gso_max_segment_size = res->cmd_size;
5239         }
5240 }
5241
5242 cmdline_parse_token_string_t cmd_gso_size_set =
5243         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5244                                 cmd_set, "set");
5245 cmdline_parse_token_string_t cmd_gso_size_keyword =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5247                                 cmd_keyword, "gso");
5248 cmdline_parse_token_string_t cmd_gso_size_segsz =
5249         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5250                                 cmd_segsz, "segsz");
5251 cmdline_parse_token_num_t cmd_gso_size_size =
5252         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5253                                 cmd_size, RTE_UINT16);
5254
5255 cmdline_parse_inst_t cmd_gso_size = {
5256         .f = cmd_gso_size_parsed,
5257         .data = NULL,
5258         .help_str = "set gso segsz <length>",
5259         .tokens = {
5260                 (void *)&cmd_gso_size_set,
5261                 (void *)&cmd_gso_size_keyword,
5262                 (void *)&cmd_gso_size_segsz,
5263                 (void *)&cmd_gso_size_size,
5264                 NULL,
5265         },
5266 };
5267
5268 /* *** SHOW GSO CONFIGURATION *** */
5269 struct cmd_gso_show_result {
5270         cmdline_fixed_string_t cmd_show;
5271         cmdline_fixed_string_t cmd_port;
5272         cmdline_fixed_string_t cmd_keyword;
5273         portid_t cmd_pid;
5274 };
5275
5276 static void
5277 cmd_gso_show_parsed(void *parsed_result,
5278                        __rte_unused struct cmdline *cl,
5279                        __rte_unused void *data)
5280 {
5281         struct cmd_gso_show_result *res = parsed_result;
5282
5283         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5284                 printf("invalid port id %u\n", res->cmd_pid);
5285                 return;
5286         }
5287         if (!strcmp(res->cmd_keyword, "gso")) {
5288                 if (gso_ports[res->cmd_pid].enable) {
5289                         printf("Max GSO'd packet size: %uB\n"
5290                                         "Supported GSO types: TCP/IPv4, "
5291                                         "UDP/IPv4, VxLAN with inner "
5292                                         "TCP/IPv4 packet, GRE with inner "
5293                                         "TCP/IPv4 packet\n",
5294                                         gso_max_segment_size);
5295                 } else
5296                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5297         }
5298 }
5299
5300 cmdline_parse_token_string_t cmd_gso_show_show =
5301 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5302                 cmd_show, "show");
5303 cmdline_parse_token_string_t cmd_gso_show_port =
5304 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5305                 cmd_port, "port");
5306 cmdline_parse_token_string_t cmd_gso_show_keyword =
5307         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5308                                 cmd_keyword, "gso");
5309 cmdline_parse_token_num_t cmd_gso_show_pid =
5310         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5311                                 cmd_pid, RTE_UINT16);
5312
5313 cmdline_parse_inst_t cmd_gso_show = {
5314         .f = cmd_gso_show_parsed,
5315         .data = NULL,
5316         .help_str = "show port <port_id> gso",
5317         .tokens = {
5318                 (void *)&cmd_gso_show_show,
5319                 (void *)&cmd_gso_show_port,
5320                 (void *)&cmd_gso_show_pid,
5321                 (void *)&cmd_gso_show_keyword,
5322                 NULL,
5323         },
5324 };
5325
5326 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5327 struct cmd_set_flush_rx {
5328         cmdline_fixed_string_t set;
5329         cmdline_fixed_string_t flush_rx;
5330         cmdline_fixed_string_t mode;
5331 };
5332
5333 static void
5334 cmd_set_flush_rx_parsed(void *parsed_result,
5335                 __rte_unused struct cmdline *cl,
5336                 __rte_unused void *data)
5337 {
5338         struct cmd_set_flush_rx *res = parsed_result;
5339         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5340 }
5341
5342 cmdline_parse_token_string_t cmd_setflushrx_set =
5343         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5344                         set, "set");
5345 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5346         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5347                         flush_rx, "flush_rx");
5348 cmdline_parse_token_string_t cmd_setflushrx_mode =
5349         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5350                         mode, "on#off");
5351
5352
5353 cmdline_parse_inst_t cmd_set_flush_rx = {
5354         .f = cmd_set_flush_rx_parsed,
5355         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5356         .data = NULL,
5357         .tokens = {
5358                 (void *)&cmd_setflushrx_set,
5359                 (void *)&cmd_setflushrx_flush_rx,
5360                 (void *)&cmd_setflushrx_mode,
5361                 NULL,
5362         },
5363 };
5364
5365 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5366 struct cmd_set_link_check {
5367         cmdline_fixed_string_t set;
5368         cmdline_fixed_string_t link_check;
5369         cmdline_fixed_string_t mode;
5370 };
5371
5372 static void
5373 cmd_set_link_check_parsed(void *parsed_result,
5374                 __rte_unused struct cmdline *cl,
5375                 __rte_unused void *data)
5376 {
5377         struct cmd_set_link_check *res = parsed_result;
5378         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5379 }
5380
5381 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5383                         set, "set");
5384 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5385         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5386                         link_check, "link_check");
5387 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5388         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5389                         mode, "on#off");
5390
5391
5392 cmdline_parse_inst_t cmd_set_link_check = {
5393         .f = cmd_set_link_check_parsed,
5394         .help_str = "set link_check on|off: Enable/Disable link status check "
5395                     "when starting/stopping a port",
5396         .data = NULL,
5397         .tokens = {
5398                 (void *)&cmd_setlinkcheck_set,
5399                 (void *)&cmd_setlinkcheck_link_check,
5400                 (void *)&cmd_setlinkcheck_mode,
5401                 NULL,
5402         },
5403 };
5404
5405 /* *** SET NIC BYPASS MODE *** */
5406 struct cmd_set_bypass_mode_result {
5407         cmdline_fixed_string_t set;
5408         cmdline_fixed_string_t bypass;
5409         cmdline_fixed_string_t mode;
5410         cmdline_fixed_string_t value;
5411         portid_t port_id;
5412 };
5413
5414 static void
5415 cmd_set_bypass_mode_parsed(void *parsed_result,
5416                 __rte_unused struct cmdline *cl,
5417                 __rte_unused void *data)
5418 {
5419         struct cmd_set_bypass_mode_result *res = parsed_result;
5420         portid_t port_id = res->port_id;
5421         int32_t rc = -EINVAL;
5422
5423 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5424         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5425
5426         if (!strcmp(res->value, "bypass"))
5427                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5428         else if (!strcmp(res->value, "isolate"))
5429                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5430         else
5431                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5432
5433         /* Set the bypass mode for the relevant port. */
5434         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5435 #endif
5436         if (rc != 0)
5437                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5438 }
5439
5440 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5441         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5442                         set, "set");
5443 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5444         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5445                         bypass, "bypass");
5446 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5447         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5448                         mode, "mode");
5449 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5450         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5451                         value, "normal#bypass#isolate");
5452 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5453         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5454                                 port_id, RTE_UINT16);
5455
5456 cmdline_parse_inst_t cmd_set_bypass_mode = {
5457         .f = cmd_set_bypass_mode_parsed,
5458         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5459                     "Set the NIC bypass mode for port_id",
5460         .data = NULL,
5461         .tokens = {
5462                 (void *)&cmd_setbypass_mode_set,
5463                 (void *)&cmd_setbypass_mode_bypass,
5464                 (void *)&cmd_setbypass_mode_mode,
5465                 (void *)&cmd_setbypass_mode_value,
5466                 (void *)&cmd_setbypass_mode_port,
5467                 NULL,
5468         },
5469 };
5470
5471 /* *** SET NIC BYPASS EVENT *** */
5472 struct cmd_set_bypass_event_result {
5473         cmdline_fixed_string_t set;
5474         cmdline_fixed_string_t bypass;
5475         cmdline_fixed_string_t event;
5476         cmdline_fixed_string_t event_value;
5477         cmdline_fixed_string_t mode;
5478         cmdline_fixed_string_t mode_value;
5479         portid_t port_id;
5480 };
5481
5482 static void
5483 cmd_set_bypass_event_parsed(void *parsed_result,
5484                 __rte_unused struct cmdline *cl,
5485                 __rte_unused void *data)
5486 {
5487         int32_t rc = -EINVAL;
5488         struct cmd_set_bypass_event_result *res = parsed_result;
5489         portid_t port_id = res->port_id;
5490
5491 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5492         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5493         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5494
5495         if (!strcmp(res->event_value, "timeout"))
5496                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5497         else if (!strcmp(res->event_value, "os_on"))
5498                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5499         else if (!strcmp(res->event_value, "os_off"))
5500                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5501         else if (!strcmp(res->event_value, "power_on"))
5502                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5503         else if (!strcmp(res->event_value, "power_off"))
5504                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5505         else
5506                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5507
5508         if (!strcmp(res->mode_value, "bypass"))
5509                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5510         else if (!strcmp(res->mode_value, "isolate"))
5511                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5512         else
5513                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5514
5515         /* Set the watchdog timeout. */
5516         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5517
5518                 rc = -EINVAL;
5519                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5520                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5521                                                            bypass_timeout);
5522                 }
5523                 if (rc != 0) {
5524                         printf("Failed to set timeout value %u "
5525                         "for port %d, errto code: %d.\n",
5526                         bypass_timeout, port_id, rc);
5527                 }
5528         }
5529
5530         /* Set the bypass event to transition to bypass mode. */
5531         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5532                                               bypass_mode);
5533 #endif
5534
5535         if (rc != 0)
5536                 printf("\t Failed to set bypass event for port = %d.\n",
5537                        port_id);
5538 }
5539
5540 cmdline_parse_token_string_t cmd_setbypass_event_set =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5542                         set, "set");
5543 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5545                         bypass, "bypass");
5546 cmdline_parse_token_string_t cmd_setbypass_event_event =
5547         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5548                         event, "event");
5549 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5551                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5552 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5554                         mode, "mode");
5555 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5557                         mode_value, "normal#bypass#isolate");
5558 cmdline_parse_token_num_t cmd_setbypass_event_port =
5559         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5560                                 port_id, RTE_UINT16);
5561
5562 cmdline_parse_inst_t cmd_set_bypass_event = {
5563         .f = cmd_set_bypass_event_parsed,
5564         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5565                 "power_off mode normal|bypass|isolate <port_id>: "
5566                 "Set the NIC bypass event mode for port_id",
5567         .data = NULL,
5568         .tokens = {
5569                 (void *)&cmd_setbypass_event_set,
5570                 (void *)&cmd_setbypass_event_bypass,
5571                 (void *)&cmd_setbypass_event_event,
5572                 (void *)&cmd_setbypass_event_event_value,
5573                 (void *)&cmd_setbypass_event_mode,
5574                 (void *)&cmd_setbypass_event_mode_value,
5575                 (void *)&cmd_setbypass_event_port,
5576                 NULL,
5577         },
5578 };
5579
5580
5581 /* *** SET NIC BYPASS TIMEOUT *** */
5582 struct cmd_set_bypass_timeout_result {
5583         cmdline_fixed_string_t set;
5584         cmdline_fixed_string_t bypass;
5585         cmdline_fixed_string_t timeout;
5586         cmdline_fixed_string_t value;
5587 };
5588
5589 static void
5590 cmd_set_bypass_timeout_parsed(void *parsed_result,
5591                 __rte_unused struct cmdline *cl,
5592                 __rte_unused void *data)
5593 {
5594         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5595
5596 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5597         if (!strcmp(res->value, "1.5"))
5598                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5599         else if (!strcmp(res->value, "2"))
5600                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5601         else if (!strcmp(res->value, "3"))
5602                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5603         else if (!strcmp(res->value, "4"))
5604                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5605         else if (!strcmp(res->value, "8"))
5606                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5607         else if (!strcmp(res->value, "16"))
5608                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5609         else if (!strcmp(res->value, "32"))
5610                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5611         else
5612                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5613 #endif
5614 }
5615
5616 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5617         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5618                         set, "set");
5619 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5620         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5621                         bypass, "bypass");
5622 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5624                         timeout, "timeout");
5625 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5627                         value, "0#1.5#2#3#4#8#16#32");
5628
5629 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5630         .f = cmd_set_bypass_timeout_parsed,
5631         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5632                 "Set the NIC bypass watchdog timeout in seconds",
5633         .data = NULL,
5634         .tokens = {
5635                 (void *)&cmd_setbypass_timeout_set,
5636                 (void *)&cmd_setbypass_timeout_bypass,
5637                 (void *)&cmd_setbypass_timeout_timeout,
5638                 (void *)&cmd_setbypass_timeout_value,
5639                 NULL,
5640         },
5641 };
5642
5643 /* *** SHOW NIC BYPASS MODE *** */
5644 struct cmd_show_bypass_config_result {
5645         cmdline_fixed_string_t show;
5646         cmdline_fixed_string_t bypass;
5647         cmdline_fixed_string_t config;
5648         portid_t port_id;
5649 };
5650
5651 static void
5652 cmd_show_bypass_config_parsed(void *parsed_result,
5653                 __rte_unused struct cmdline *cl,
5654                 __rte_unused void *data)
5655 {
5656         struct cmd_show_bypass_config_result *res = parsed_result;
5657         portid_t port_id = res->port_id;
5658         int rc = -EINVAL;
5659 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5660         uint32_t event_mode;
5661         uint32_t bypass_mode;
5662         uint32_t timeout = bypass_timeout;
5663         unsigned int i;
5664
5665         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5666                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5667         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5668                 {"UNKNOWN", "normal", "bypass", "isolate"};
5669         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5670                 "NONE",
5671                 "OS/board on",
5672                 "power supply on",
5673                 "OS/board off",
5674                 "power supply off",
5675                 "timeout"};
5676
5677         /* Display the bypass mode.*/
5678         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5679                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5680                 return;
5681         }
5682         else {
5683                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5684                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5685
5686                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5687         }
5688
5689         /* Display the bypass timeout.*/
5690         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5691                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5692
5693         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5694
5695         /* Display the bypass events and associated modes. */
5696         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5697
5698                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5699                         printf("\tFailed to get bypass mode for event = %s\n",
5700                                 events[i]);
5701                 } else {
5702                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5703                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5704
5705                         printf("\tbypass event: %-16s = %s\n", events[i],
5706                                 modes[event_mode]);
5707                 }
5708         }
5709 #endif
5710         if (rc != 0)
5711                 printf("\tFailed to get bypass configuration for port = %d\n",
5712                        port_id);
5713 }
5714
5715 cmdline_parse_token_string_t cmd_showbypass_config_show =
5716         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5717                         show, "show");
5718 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5719         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5720                         bypass, "bypass");
5721 cmdline_parse_token_string_t cmd_showbypass_config_config =
5722         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5723                         config, "config");
5724 cmdline_parse_token_num_t cmd_showbypass_config_port =
5725         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5726                                 port_id, RTE_UINT16);
5727
5728 cmdline_parse_inst_t cmd_show_bypass_config = {
5729         .f = cmd_show_bypass_config_parsed,
5730         .help_str = "show bypass config <port_id>: "
5731                     "Show the NIC bypass config for port_id",
5732         .data = NULL,
5733         .tokens = {
5734                 (void *)&cmd_showbypass_config_show,
5735                 (void *)&cmd_showbypass_config_bypass,
5736                 (void *)&cmd_showbypass_config_config,
5737                 (void *)&cmd_showbypass_config_port,
5738                 NULL,
5739         },
5740 };
5741
5742 #ifdef RTE_NET_BOND
5743 /* *** SET BONDING MODE *** */
5744 struct cmd_set_bonding_mode_result {
5745         cmdline_fixed_string_t set;
5746         cmdline_fixed_string_t bonding;
5747         cmdline_fixed_string_t mode;
5748         uint8_t value;
5749         portid_t port_id;
5750 };
5751
5752 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5753                 __rte_unused  struct cmdline *cl,
5754                 __rte_unused void *data)
5755 {
5756         struct cmd_set_bonding_mode_result *res = parsed_result;
5757         portid_t port_id = res->port_id;
5758
5759         /* Set the bonding mode for the relevant port. */
5760         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5761                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5762 }
5763
5764 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5765 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5766                 set, "set");
5767 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5768 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5769                 bonding, "bonding");
5770 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5771 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5772                 mode, "mode");
5773 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5774 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5775                 value, RTE_UINT8);
5776 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5777 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5778                 port_id, RTE_UINT16);
5779
5780 cmdline_parse_inst_t cmd_set_bonding_mode = {
5781                 .f = cmd_set_bonding_mode_parsed,
5782                 .help_str = "set bonding mode <mode_value> <port_id>: "
5783                         "Set the bonding mode for port_id",
5784                 .data = NULL,
5785                 .tokens = {
5786                                 (void *) &cmd_setbonding_mode_set,
5787                                 (void *) &cmd_setbonding_mode_bonding,
5788                                 (void *) &cmd_setbonding_mode_mode,
5789                                 (void *) &cmd_setbonding_mode_value,
5790                                 (void *) &cmd_setbonding_mode_port,
5791                                 NULL
5792                 }
5793 };
5794
5795 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5796 struct cmd_set_bonding_lacp_dedicated_queues_result {
5797         cmdline_fixed_string_t set;
5798         cmdline_fixed_string_t bonding;
5799         cmdline_fixed_string_t lacp;
5800         cmdline_fixed_string_t dedicated_queues;
5801         portid_t port_id;
5802         cmdline_fixed_string_t mode;
5803 };
5804
5805 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5806                 __rte_unused  struct cmdline *cl,
5807                 __rte_unused void *data)
5808 {
5809         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5810         portid_t port_id = res->port_id;
5811         struct rte_port *port;
5812
5813         port = &ports[port_id];
5814
5815         /** Check if the port is not started **/
5816         if (port->port_status != RTE_PORT_STOPPED) {
5817                 printf("Please stop port %d first\n", port_id);
5818                 return;
5819         }
5820
5821         if (!strcmp(res->mode, "enable")) {
5822                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5823                         printf("Dedicate queues for LACP control packets"
5824                                         " enabled\n");
5825                 else
5826                         printf("Enabling dedicate queues for LACP control "
5827                                         "packets on port %d failed\n", port_id);
5828         } else if (!strcmp(res->mode, "disable")) {
5829                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5830                         printf("Dedicated queues for LACP control packets "
5831                                         "disabled\n");
5832                 else
5833                         printf("Disabling dedicated queues for LACP control "
5834                                         "traffic on port %d failed\n", port_id);
5835         }
5836 }
5837
5838 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5839 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5840                 set, "set");
5841 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5842 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5843                 bonding, "bonding");
5844 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5845 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5846                 lacp, "lacp");
5847 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5849                 dedicated_queues, "dedicated_queues");
5850 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5851 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5852                 port_id, RTE_UINT16);
5853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5855                 mode, "enable#disable");
5856
5857 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5858                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5859                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5860                         "enable|disable: "
5861                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5862                 .data = NULL,
5863                 .tokens = {
5864                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5865                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5866                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5867                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5868                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5869                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5870                         NULL
5871                 }
5872 };
5873
5874 /* *** SET BALANCE XMIT POLICY *** */
5875 struct cmd_set_bonding_balance_xmit_policy_result {
5876         cmdline_fixed_string_t set;
5877         cmdline_fixed_string_t bonding;
5878         cmdline_fixed_string_t balance_xmit_policy;
5879         portid_t port_id;
5880         cmdline_fixed_string_t policy;
5881 };
5882
5883 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5884                 __rte_unused  struct cmdline *cl,
5885                 __rte_unused void *data)
5886 {
5887         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5888         portid_t port_id = res->port_id;
5889         uint8_t policy;
5890
5891         if (!strcmp(res->policy, "l2")) {
5892                 policy = BALANCE_XMIT_POLICY_LAYER2;
5893         } else if (!strcmp(res->policy, "l23")) {
5894                 policy = BALANCE_XMIT_POLICY_LAYER23;
5895         } else if (!strcmp(res->policy, "l34")) {
5896                 policy = BALANCE_XMIT_POLICY_LAYER34;
5897         } else {
5898                 printf("\t Invalid xmit policy selection");
5899                 return;
5900         }
5901
5902         /* Set the bonding mode for the relevant port. */
5903         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5904                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5905                                 port_id);
5906         }
5907 }
5908
5909 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5910 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5911                 set, "set");
5912 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5913 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5914                 bonding, "bonding");
5915 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5916 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5917                 balance_xmit_policy, "balance_xmit_policy");
5918 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5919 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5920                 port_id, RTE_UINT16);
5921 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5923                 policy, "l2#l23#l34");
5924
5925 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5926                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5927                 .help_str = "set bonding balance_xmit_policy <port_id> "
5928                         "l2|l23|l34: "
5929                         "Set the bonding balance_xmit_policy for port_id",
5930                 .data = NULL,
5931                 .tokens = {
5932                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5933                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5934                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5935                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5936                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5937                                 NULL
5938                 }
5939 };
5940
5941 /* *** SHOW NIC BONDING CONFIGURATION *** */
5942 struct cmd_show_bonding_config_result {
5943         cmdline_fixed_string_t show;
5944         cmdline_fixed_string_t bonding;
5945         cmdline_fixed_string_t config;
5946         portid_t port_id;
5947 };
5948
5949 static void cmd_show_bonding_config_parsed(void *parsed_result,
5950                 __rte_unused  struct cmdline *cl,
5951                 __rte_unused void *data)
5952 {
5953         struct cmd_show_bonding_config_result *res = parsed_result;
5954         int bonding_mode, agg_mode;
5955         portid_t slaves[RTE_MAX_ETHPORTS];
5956         int num_slaves, num_active_slaves;
5957         int primary_id;
5958         int i;
5959         portid_t port_id = res->port_id;
5960
5961         /* Display the bonding mode.*/
5962         bonding_mode = rte_eth_bond_mode_get(port_id);
5963         if (bonding_mode < 0) {
5964                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5965                 return;
5966         } else
5967                 printf("\tBonding mode: %d\n", bonding_mode);
5968
5969         if (bonding_mode == BONDING_MODE_BALANCE) {
5970                 int balance_xmit_policy;
5971
5972                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5973                 if (balance_xmit_policy < 0) {
5974                         printf("\tFailed to get balance xmit policy for port = %d\n",
5975                                         port_id);
5976                         return;
5977                 } else {
5978                         printf("\tBalance Xmit Policy: ");
5979
5980                         switch (balance_xmit_policy) {
5981                         case BALANCE_XMIT_POLICY_LAYER2:
5982                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5983                                 break;
5984                         case BALANCE_XMIT_POLICY_LAYER23:
5985                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5986                                 break;
5987                         case BALANCE_XMIT_POLICY_LAYER34:
5988                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5989                                 break;
5990                         }
5991                         printf("\n");
5992                 }
5993         }
5994
5995         if (bonding_mode == BONDING_MODE_8023AD) {
5996                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5997                 printf("\tIEEE802.3AD Aggregator Mode: ");
5998                 switch (agg_mode) {
5999                 case AGG_BANDWIDTH:
6000                         printf("bandwidth");
6001                         break;
6002                 case AGG_STABLE:
6003                         printf("stable");
6004                         break;
6005                 case AGG_COUNT:
6006                         printf("count");
6007                         break;
6008                 }
6009                 printf("\n");
6010         }
6011
6012         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6013
6014         if (num_slaves < 0) {
6015                 printf("\tFailed to get slave list for port = %d\n", port_id);
6016                 return;
6017         }
6018         if (num_slaves > 0) {
6019                 printf("\tSlaves (%d): [", num_slaves);
6020                 for (i = 0; i < num_slaves - 1; i++)
6021                         printf("%d ", slaves[i]);
6022
6023                 printf("%d]\n", slaves[num_slaves - 1]);
6024         } else {
6025                 printf("\tSlaves: []\n");
6026
6027         }
6028
6029         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6030                         RTE_MAX_ETHPORTS);
6031
6032         if (num_active_slaves < 0) {
6033                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6034                 return;
6035         }
6036         if (num_active_slaves > 0) {
6037                 printf("\tActive Slaves (%d): [", num_active_slaves);
6038                 for (i = 0; i < num_active_slaves - 1; i++)
6039                         printf("%d ", slaves[i]);
6040
6041                 printf("%d]\n", slaves[num_active_slaves - 1]);
6042
6043         } else {
6044                 printf("\tActive Slaves: []\n");
6045
6046         }
6047
6048         primary_id = rte_eth_bond_primary_get(port_id);
6049         if (primary_id < 0) {
6050                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6051                 return;
6052         } else
6053                 printf("\tPrimary: [%d]\n", primary_id);
6054
6055 }
6056
6057 cmdline_parse_token_string_t cmd_showbonding_config_show =
6058 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6059                 show, "show");
6060 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6061 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6062                 bonding, "bonding");
6063 cmdline_parse_token_string_t cmd_showbonding_config_config =
6064 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6065                 config, "config");
6066 cmdline_parse_token_num_t cmd_showbonding_config_port =
6067 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6068                 port_id, RTE_UINT16);
6069
6070 cmdline_parse_inst_t cmd_show_bonding_config = {
6071                 .f = cmd_show_bonding_config_parsed,
6072                 .help_str = "show bonding config <port_id>: "
6073                         "Show the bonding config for port_id",
6074                 .data = NULL,
6075                 .tokens = {
6076                                 (void *)&cmd_showbonding_config_show,
6077                                 (void *)&cmd_showbonding_config_bonding,
6078                                 (void *)&cmd_showbonding_config_config,
6079                                 (void *)&cmd_showbonding_config_port,
6080                                 NULL
6081                 }
6082 };
6083
6084 /* *** SET BONDING PRIMARY *** */
6085 struct cmd_set_bonding_primary_result {
6086         cmdline_fixed_string_t set;
6087         cmdline_fixed_string_t bonding;
6088         cmdline_fixed_string_t primary;
6089         portid_t slave_id;
6090         portid_t port_id;
6091 };
6092
6093 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6094                 __rte_unused  struct cmdline *cl,
6095                 __rte_unused void *data)
6096 {
6097         struct cmd_set_bonding_primary_result *res = parsed_result;
6098         portid_t master_port_id = res->port_id;
6099         portid_t slave_port_id = res->slave_id;
6100
6101         /* Set the primary slave for a bonded device. */
6102         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6103                 printf("\t Failed to set primary slave for port = %d.\n",
6104                                 master_port_id);
6105                 return;
6106         }
6107         init_port_config();
6108 }
6109
6110 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6112                 set, "set");
6113 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6114 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6115                 bonding, "bonding");
6116 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6117 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6118                 primary, "primary");
6119 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6120 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6121                 slave_id, RTE_UINT16);
6122 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6123 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6124                 port_id, RTE_UINT16);
6125
6126 cmdline_parse_inst_t cmd_set_bonding_primary = {
6127                 .f = cmd_set_bonding_primary_parsed,
6128                 .help_str = "set bonding primary <slave_id> <port_id>: "
6129                         "Set the primary slave for port_id",
6130                 .data = NULL,
6131                 .tokens = {
6132                                 (void *)&cmd_setbonding_primary_set,
6133                                 (void *)&cmd_setbonding_primary_bonding,
6134                                 (void *)&cmd_setbonding_primary_primary,
6135                                 (void *)&cmd_setbonding_primary_slave,
6136                                 (void *)&cmd_setbonding_primary_port,
6137                                 NULL
6138                 }
6139 };
6140
6141 /* *** ADD SLAVE *** */
6142 struct cmd_add_bonding_slave_result {
6143         cmdline_fixed_string_t add;
6144         cmdline_fixed_string_t bonding;
6145         cmdline_fixed_string_t slave;
6146         portid_t slave_id;
6147         portid_t port_id;
6148 };
6149
6150 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6151                 __rte_unused  struct cmdline *cl,
6152                 __rte_unused void *data)
6153 {
6154         struct cmd_add_bonding_slave_result *res = parsed_result;
6155         portid_t master_port_id = res->port_id;
6156         portid_t slave_port_id = res->slave_id;
6157
6158         /* add the slave for a bonded device. */
6159         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6160                 printf("\t Failed to add slave %d to master port = %d.\n",
6161                                 slave_port_id, master_port_id);
6162                 return;
6163         }
6164         init_port_config();
6165         set_port_slave_flag(slave_port_id);
6166 }
6167
6168 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6169 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6170                 add, "add");
6171 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6172 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6173                 bonding, "bonding");
6174 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6175 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6176                 slave, "slave");
6177 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6178 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6179                 slave_id, RTE_UINT16);
6180 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6181 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6182                 port_id, RTE_UINT16);
6183
6184 cmdline_parse_inst_t cmd_add_bonding_slave = {
6185                 .f = cmd_add_bonding_slave_parsed,
6186                 .help_str = "add bonding slave <slave_id> <port_id>: "
6187                         "Add a slave device to a bonded device",
6188                 .data = NULL,
6189                 .tokens = {
6190                                 (void *)&cmd_addbonding_slave_add,
6191                                 (void *)&cmd_addbonding_slave_bonding,
6192                                 (void *)&cmd_addbonding_slave_slave,
6193                                 (void *)&cmd_addbonding_slave_slaveid,
6194                                 (void *)&cmd_addbonding_slave_port,
6195                                 NULL
6196                 }
6197 };
6198
6199 /* *** REMOVE SLAVE *** */
6200 struct cmd_remove_bonding_slave_result {
6201         cmdline_fixed_string_t remove;
6202         cmdline_fixed_string_t bonding;
6203         cmdline_fixed_string_t slave;
6204         portid_t slave_id;
6205         portid_t port_id;
6206 };
6207
6208 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6209                 __rte_unused  struct cmdline *cl,
6210                 __rte_unused void *data)
6211 {
6212         struct cmd_remove_bonding_slave_result *res = parsed_result;
6213         portid_t master_port_id = res->port_id;
6214         portid_t slave_port_id = res->slave_id;
6215
6216         /* remove the slave from a bonded device. */
6217         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6218                 printf("\t Failed to remove slave %d from master port = %d.\n",
6219                                 slave_port_id, master_port_id);
6220                 return;
6221         }
6222         init_port_config();
6223         clear_port_slave_flag(slave_port_id);
6224 }
6225
6226 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6227                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6228                                 remove, "remove");
6229 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6230                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6231                                 bonding, "bonding");
6232 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6233                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6234                                 slave, "slave");
6235 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6236                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6237                                 slave_id, RTE_UINT16);
6238 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6239                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6240                                 port_id, RTE_UINT16);
6241
6242 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6243                 .f = cmd_remove_bonding_slave_parsed,
6244                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6245                         "Remove a slave device from a bonded device",
6246                 .data = NULL,
6247                 .tokens = {
6248                                 (void *)&cmd_removebonding_slave_remove,
6249                                 (void *)&cmd_removebonding_slave_bonding,
6250                                 (void *)&cmd_removebonding_slave_slave,
6251                                 (void *)&cmd_removebonding_slave_slaveid,
6252                                 (void *)&cmd_removebonding_slave_port,
6253                                 NULL
6254                 }
6255 };
6256
6257 /* *** CREATE BONDED DEVICE *** */
6258 struct cmd_create_bonded_device_result {
6259         cmdline_fixed_string_t create;
6260         cmdline_fixed_string_t bonded;
6261         cmdline_fixed_string_t device;
6262         uint8_t mode;
6263         uint8_t socket;
6264 };
6265
6266 static int bond_dev_num = 0;
6267
6268 static void cmd_create_bonded_device_parsed(void *parsed_result,
6269                 __rte_unused  struct cmdline *cl,
6270                 __rte_unused void *data)
6271 {
6272         struct cmd_create_bonded_device_result *res = parsed_result;
6273         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6274         int port_id;
6275         int ret;
6276
6277         if (test_done == 0) {
6278                 printf("Please stop forwarding first\n");
6279                 return;
6280         }
6281
6282         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6283                         bond_dev_num++);
6284
6285         /* Create a new bonded device. */
6286         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6287         if (port_id < 0) {
6288                 printf("\t Failed to create bonded device.\n");
6289                 return;
6290         } else {
6291                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6292                                 port_id);
6293
6294                 /* Update number of ports */
6295                 nb_ports = rte_eth_dev_count_avail();
6296                 reconfig(port_id, res->socket);
6297                 ret = rte_eth_promiscuous_enable(port_id);
6298                 if (ret != 0)
6299                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6300                                 port_id, rte_strerror(-ret));
6301
6302                 ports[port_id].need_setup = 0;
6303                 ports[port_id].port_status = RTE_PORT_STOPPED;
6304         }
6305
6306 }
6307
6308 cmdline_parse_token_string_t cmd_createbonded_device_create =
6309                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6310                                 create, "create");
6311 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6312                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6313                                 bonded, "bonded");
6314 cmdline_parse_token_string_t cmd_createbonded_device_device =
6315                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6316                                 device, "device");
6317 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6318                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6319                                 mode, RTE_UINT8);
6320 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6321                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6322                                 socket, RTE_UINT8);
6323
6324 cmdline_parse_inst_t cmd_create_bonded_device = {
6325                 .f = cmd_create_bonded_device_parsed,
6326                 .help_str = "create bonded device <mode> <socket>: "
6327                         "Create a new bonded device with specific bonding mode and socket",
6328                 .data = NULL,
6329                 .tokens = {
6330                                 (void *)&cmd_createbonded_device_create,
6331                                 (void *)&cmd_createbonded_device_bonded,
6332                                 (void *)&cmd_createbonded_device_device,
6333                                 (void *)&cmd_createbonded_device_mode,
6334                                 (void *)&cmd_createbonded_device_socket,
6335                                 NULL
6336                 }
6337 };
6338
6339 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6340 struct cmd_set_bond_mac_addr_result {
6341         cmdline_fixed_string_t set;
6342         cmdline_fixed_string_t bonding;
6343         cmdline_fixed_string_t mac_addr;
6344         uint16_t port_num;
6345         struct rte_ether_addr address;
6346 };
6347
6348 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6349                 __rte_unused  struct cmdline *cl,
6350                 __rte_unused void *data)
6351 {
6352         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6353         int ret;
6354
6355         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6356                 return;
6357
6358         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6359
6360         /* check the return value and print it if is < 0 */
6361         if (ret < 0)
6362                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6363 }
6364
6365 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6366                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6367 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6368                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6369                                 "bonding");
6370 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6371                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6372                                 "mac_addr");
6373 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6374                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6375                                 port_num, RTE_UINT16);
6376 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6377                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6378
6379 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6380                 .f = cmd_set_bond_mac_addr_parsed,
6381                 .data = (void *) 0,
6382                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6383                 .tokens = {
6384                                 (void *)&cmd_set_bond_mac_addr_set,
6385                                 (void *)&cmd_set_bond_mac_addr_bonding,
6386                                 (void *)&cmd_set_bond_mac_addr_mac,
6387                                 (void *)&cmd_set_bond_mac_addr_portnum,
6388                                 (void *)&cmd_set_bond_mac_addr_addr,
6389                                 NULL
6390                 }
6391 };
6392
6393
6394 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6395 struct cmd_set_bond_mon_period_result {
6396         cmdline_fixed_string_t set;
6397         cmdline_fixed_string_t bonding;
6398         cmdline_fixed_string_t mon_period;
6399         uint16_t port_num;
6400         uint32_t period_ms;
6401 };
6402
6403 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6404                 __rte_unused  struct cmdline *cl,
6405                 __rte_unused void *data)
6406 {
6407         struct cmd_set_bond_mon_period_result *res = parsed_result;
6408         int ret;
6409
6410         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6411
6412         /* check the return value and print it if is < 0 */
6413         if (ret < 0)
6414                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6415 }
6416
6417 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6418                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6419                                 set, "set");
6420 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6421                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6422                                 bonding, "bonding");
6423 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6424                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6425                                 mon_period,     "mon_period");
6426 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6427                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6428                                 port_num, RTE_UINT16);
6429 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6430                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6431                                 period_ms, RTE_UINT32);
6432
6433 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6434                 .f = cmd_set_bond_mon_period_parsed,
6435                 .data = (void *) 0,
6436                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6437                 .tokens = {
6438                                 (void *)&cmd_set_bond_mon_period_set,
6439                                 (void *)&cmd_set_bond_mon_period_bonding,
6440                                 (void *)&cmd_set_bond_mon_period_mon_period,
6441                                 (void *)&cmd_set_bond_mon_period_portnum,
6442                                 (void *)&cmd_set_bond_mon_period_period_ms,
6443                                 NULL
6444                 }
6445 };
6446
6447
6448
6449 struct cmd_set_bonding_agg_mode_policy_result {
6450         cmdline_fixed_string_t set;
6451         cmdline_fixed_string_t bonding;
6452         cmdline_fixed_string_t agg_mode;
6453         uint16_t port_num;
6454         cmdline_fixed_string_t policy;
6455 };
6456
6457
6458 static void
6459 cmd_set_bonding_agg_mode(void *parsed_result,
6460                 __rte_unused struct cmdline *cl,
6461                 __rte_unused void *data)
6462 {
6463         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6464         uint8_t policy = AGG_BANDWIDTH;
6465
6466         if (!strcmp(res->policy, "bandwidth"))
6467                 policy = AGG_BANDWIDTH;
6468         else if (!strcmp(res->policy, "stable"))
6469                 policy = AGG_STABLE;
6470         else if (!strcmp(res->policy, "count"))
6471                 policy = AGG_COUNT;
6472
6473         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6474 }
6475
6476
6477 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6479                                 set, "set");
6480 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6482                                 bonding, "bonding");
6483
6484 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6485         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6486                                 agg_mode, "agg_mode");
6487
6488 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6489         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6490                                 port_num, RTE_UINT16);
6491
6492 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6493         TOKEN_STRING_INITIALIZER(
6494                         struct cmd_set_bonding_balance_xmit_policy_result,
6495                 policy, "stable#bandwidth#count");
6496
6497 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6498         .f = cmd_set_bonding_agg_mode,
6499         .data = (void *) 0,
6500         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6501         .tokens = {
6502                         (void *)&cmd_set_bonding_agg_mode_set,
6503                         (void *)&cmd_set_bonding_agg_mode_bonding,
6504                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6505                         (void *)&cmd_set_bonding_agg_mode_portnum,
6506                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6507                         NULL
6508                 }
6509 };
6510
6511
6512 #endif /* RTE_NET_BOND */
6513
6514 /* *** SET FORWARDING MODE *** */
6515 struct cmd_set_fwd_mode_result {
6516         cmdline_fixed_string_t set;
6517         cmdline_fixed_string_t fwd;
6518         cmdline_fixed_string_t mode;
6519 };
6520
6521 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6522                                     __rte_unused struct cmdline *cl,
6523                                     __rte_unused void *data)
6524 {
6525         struct cmd_set_fwd_mode_result *res = parsed_result;
6526
6527         retry_enabled = 0;
6528         set_pkt_forwarding_mode(res->mode);
6529 }
6530
6531 cmdline_parse_token_string_t cmd_setfwd_set =
6532         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6533 cmdline_parse_token_string_t cmd_setfwd_fwd =
6534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6535 cmdline_parse_token_string_t cmd_setfwd_mode =
6536         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6537                 "" /* defined at init */);
6538
6539 cmdline_parse_inst_t cmd_set_fwd_mode = {
6540         .f = cmd_set_fwd_mode_parsed,
6541         .data = NULL,
6542         .help_str = NULL, /* defined at init */
6543         .tokens = {
6544                 (void *)&cmd_setfwd_set,
6545                 (void *)&cmd_setfwd_fwd,
6546                 (void *)&cmd_setfwd_mode,
6547                 NULL,
6548         },
6549 };
6550
6551 static void cmd_set_fwd_mode_init(void)
6552 {
6553         char *modes, *c;
6554         static char token[128];
6555         static char help[256];
6556         cmdline_parse_token_string_t *token_struct;
6557
6558         modes = list_pkt_forwarding_modes();
6559         snprintf(help, sizeof(help), "set fwd %s: "
6560                 "Set packet forwarding mode", modes);
6561         cmd_set_fwd_mode.help_str = help;
6562
6563         /* string token separator is # */
6564         for (c = token; *modes != '\0'; modes++)
6565                 if (*modes == '|')
6566                         *c++ = '#';
6567                 else
6568                         *c++ = *modes;
6569         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6570         token_struct->string_data.str = token;
6571 }
6572
6573 /* *** SET RETRY FORWARDING MODE *** */
6574 struct cmd_set_fwd_retry_mode_result {
6575         cmdline_fixed_string_t set;
6576         cmdline_fixed_string_t fwd;
6577         cmdline_fixed_string_t mode;
6578         cmdline_fixed_string_t retry;
6579 };
6580
6581 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6582                             __rte_unused struct cmdline *cl,
6583                             __rte_unused void *data)
6584 {
6585         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6586
6587         retry_enabled = 1;
6588         set_pkt_forwarding_mode(res->mode);
6589 }
6590
6591 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6592         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6593                         set, "set");
6594 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6596                         fwd, "fwd");
6597 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6598         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6599                         mode,
6600                 "" /* defined at init */);
6601 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6602         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6603                         retry, "retry");
6604
6605 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6606         .f = cmd_set_fwd_retry_mode_parsed,
6607         .data = NULL,
6608         .help_str = NULL, /* defined at init */
6609         .tokens = {
6610                 (void *)&cmd_setfwd_retry_set,
6611                 (void *)&cmd_setfwd_retry_fwd,
6612                 (void *)&cmd_setfwd_retry_mode,
6613                 (void *)&cmd_setfwd_retry_retry,
6614                 NULL,
6615         },
6616 };
6617
6618 static void cmd_set_fwd_retry_mode_init(void)
6619 {
6620         char *modes, *c;
6621         static char token[128];
6622         static char help[256];
6623         cmdline_parse_token_string_t *token_struct;
6624
6625         modes = list_pkt_forwarding_retry_modes();
6626         snprintf(help, sizeof(help), "set fwd %s retry: "
6627                 "Set packet forwarding mode with retry", modes);
6628         cmd_set_fwd_retry_mode.help_str = help;
6629
6630         /* string token separator is # */
6631         for (c = token; *modes != '\0'; modes++)
6632                 if (*modes == '|')
6633                         *c++ = '#';
6634                 else
6635                         *c++ = *modes;
6636         token_struct = (cmdline_parse_token_string_t *)
6637                 cmd_set_fwd_retry_mode.tokens[2];
6638         token_struct->string_data.str = token;
6639 }
6640
6641 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6642 struct cmd_set_burst_tx_retry_result {
6643         cmdline_fixed_string_t set;
6644         cmdline_fixed_string_t burst;
6645         cmdline_fixed_string_t tx;
6646         cmdline_fixed_string_t delay;
6647         uint32_t time;
6648         cmdline_fixed_string_t retry;
6649         uint32_t retry_num;
6650 };
6651
6652 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6653                                         __rte_unused struct cmdline *cl,
6654                                         __rte_unused void *data)
6655 {
6656         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6657
6658         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6659                 && !strcmp(res->tx, "tx")) {
6660                 if (!strcmp(res->delay, "delay"))
6661                         burst_tx_delay_time = res->time;
6662                 if (!strcmp(res->retry, "retry"))
6663                         burst_tx_retry_num = res->retry_num;
6664         }
6665
6666 }
6667
6668 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6670 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6671         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6672                                  "burst");
6673 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6675 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6677 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6678         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6679                                  RTE_UINT32);
6680 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6682 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6683         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6684                                  RTE_UINT32);
6685
6686 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6687         .f = cmd_set_burst_tx_retry_parsed,
6688         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6689         .tokens = {
6690                 (void *)&cmd_set_burst_tx_retry_set,
6691                 (void *)&cmd_set_burst_tx_retry_burst,
6692                 (void *)&cmd_set_burst_tx_retry_tx,
6693                 (void *)&cmd_set_burst_tx_retry_delay,
6694                 (void *)&cmd_set_burst_tx_retry_time,
6695                 (void *)&cmd_set_burst_tx_retry_retry,
6696                 (void *)&cmd_set_burst_tx_retry_retry_num,
6697                 NULL,
6698         },
6699 };
6700
6701 /* *** SET PROMISC MODE *** */
6702 struct cmd_set_promisc_mode_result {
6703         cmdline_fixed_string_t set;
6704         cmdline_fixed_string_t promisc;
6705         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6706         uint16_t port_num;               /* valid if "allports" argument == 0 */
6707         cmdline_fixed_string_t mode;
6708 };
6709
6710 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6711                                         __rte_unused struct cmdline *cl,
6712                                         void *allports)
6713 {
6714         struct cmd_set_promisc_mode_result *res = parsed_result;
6715         int enable;
6716         portid_t i;
6717
6718         if (!strcmp(res->mode, "on"))
6719                 enable = 1;
6720         else
6721                 enable = 0;
6722
6723         /* all ports */
6724         if (allports) {
6725                 RTE_ETH_FOREACH_DEV(i)
6726                         eth_set_promisc_mode(i, enable);
6727         } else {
6728                 eth_set_promisc_mode(res->port_num, enable);
6729         }
6730 }
6731
6732 cmdline_parse_token_string_t cmd_setpromisc_set =
6733         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6734 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6736                                  "promisc");
6737 cmdline_parse_token_string_t cmd_setpromisc_portall =
6738         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6739                                  "all");
6740 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6741         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6742                               RTE_UINT16);
6743 cmdline_parse_token_string_t cmd_setpromisc_mode =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6745                                  "on#off");
6746
6747 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6748         .f = cmd_set_promisc_mode_parsed,
6749         .data = (void *)1,
6750         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6751         .tokens = {
6752                 (void *)&cmd_setpromisc_set,
6753                 (void *)&cmd_setpromisc_promisc,
6754                 (void *)&cmd_setpromisc_portall,
6755                 (void *)&cmd_setpromisc_mode,
6756                 NULL,
6757         },
6758 };
6759
6760 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6761         .f = cmd_set_promisc_mode_parsed,
6762         .data = (void *)0,
6763         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6764         .tokens = {
6765                 (void *)&cmd_setpromisc_set,
6766                 (void *)&cmd_setpromisc_promisc,
6767                 (void *)&cmd_setpromisc_portnum,
6768                 (void *)&cmd_setpromisc_mode,
6769                 NULL,
6770         },
6771 };
6772
6773 /* *** SET ALLMULTI MODE *** */
6774 struct cmd_set_allmulti_mode_result {
6775         cmdline_fixed_string_t set;
6776         cmdline_fixed_string_t allmulti;
6777         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6778         uint16_t port_num;               /* valid if "allports" argument == 0 */
6779         cmdline_fixed_string_t mode;
6780 };
6781
6782 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6783                                         __rte_unused struct cmdline *cl,
6784                                         void *allports)
6785 {
6786         struct cmd_set_allmulti_mode_result *res = parsed_result;
6787         int enable;
6788         portid_t i;
6789
6790         if (!strcmp(res->mode, "on"))
6791                 enable = 1;
6792         else
6793                 enable = 0;
6794
6795         /* all ports */
6796         if (allports) {
6797                 RTE_ETH_FOREACH_DEV(i) {
6798                         eth_set_allmulticast_mode(i, enable);
6799                 }
6800         }
6801         else {
6802                 eth_set_allmulticast_mode(res->port_num, enable);
6803         }
6804 }
6805
6806 cmdline_parse_token_string_t cmd_setallmulti_set =
6807         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6808 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6810                                  "allmulti");
6811 cmdline_parse_token_string_t cmd_setallmulti_portall =
6812         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6813                                  "all");
6814 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6815         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6816                               RTE_UINT16);
6817 cmdline_parse_token_string_t cmd_setallmulti_mode =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6819                                  "on#off");
6820
6821 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6822         .f = cmd_set_allmulti_mode_parsed,
6823         .data = (void *)1,
6824         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6825         .tokens = {
6826                 (void *)&cmd_setallmulti_set,
6827                 (void *)&cmd_setallmulti_allmulti,
6828                 (void *)&cmd_setallmulti_portall,
6829                 (void *)&cmd_setallmulti_mode,
6830                 NULL,
6831         },
6832 };
6833
6834 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6835         .f = cmd_set_allmulti_mode_parsed,
6836         .data = (void *)0,
6837         .help_str = "set allmulti <port_id> on|off: "
6838                 "Set allmulti mode on port_id",
6839         .tokens = {
6840                 (void *)&cmd_setallmulti_set,
6841                 (void *)&cmd_setallmulti_allmulti,
6842                 (void *)&cmd_setallmulti_portnum,
6843                 (void *)&cmd_setallmulti_mode,
6844                 NULL,
6845         },
6846 };
6847
6848 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6849 struct cmd_link_flow_ctrl_set_result {
6850         cmdline_fixed_string_t set;
6851         cmdline_fixed_string_t flow_ctrl;
6852         cmdline_fixed_string_t rx;
6853         cmdline_fixed_string_t rx_lfc_mode;
6854         cmdline_fixed_string_t tx;
6855         cmdline_fixed_string_t tx_lfc_mode;
6856         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6857         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6858         cmdline_fixed_string_t autoneg_str;
6859         cmdline_fixed_string_t autoneg;
6860         cmdline_fixed_string_t hw_str;
6861         uint32_t high_water;
6862         cmdline_fixed_string_t lw_str;
6863         uint32_t low_water;
6864         cmdline_fixed_string_t pt_str;
6865         uint16_t pause_time;
6866         cmdline_fixed_string_t xon_str;
6867         uint16_t send_xon;
6868         portid_t port_id;
6869 };
6870
6871 cmdline_parse_token_string_t cmd_lfc_set_set =
6872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 set, "set");
6874 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 flow_ctrl, "flow_ctrl");
6877 cmdline_parse_token_string_t cmd_lfc_set_rx =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 rx, "rx");
6880 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 rx_lfc_mode, "on#off");
6883 cmdline_parse_token_string_t cmd_lfc_set_tx =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 tx, "tx");
6886 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 tx_lfc_mode, "on#off");
6889 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 hw_str, "high_water");
6892 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6893         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 high_water, RTE_UINT32);
6895 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 lw_str, "low_water");
6898 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6899         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 low_water, RTE_UINT32);
6901 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 pt_str, "pause_time");
6904 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6905         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 pause_time, RTE_UINT16);
6907 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 xon_str, "send_xon");
6910 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6911         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 send_xon, RTE_UINT16);
6913 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6916 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 mac_ctrl_frame_fwd_mode, "on#off");
6919 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 autoneg_str, "autoneg");
6922 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 autoneg, "on#off");
6925 cmdline_parse_token_num_t cmd_lfc_set_portid =
6926         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 port_id, RTE_UINT16);
6928
6929 /* forward declaration */
6930 static void
6931 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6932                               void *data);
6933
6934 cmdline_parse_inst_t cmd_link_flow_control_set = {
6935         .f = cmd_link_flow_ctrl_set_parsed,
6936         .data = NULL,
6937         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6938                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6939                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6940         .tokens = {
6941                 (void *)&cmd_lfc_set_set,
6942                 (void *)&cmd_lfc_set_flow_ctrl,
6943                 (void *)&cmd_lfc_set_rx,
6944                 (void *)&cmd_lfc_set_rx_mode,
6945                 (void *)&cmd_lfc_set_tx,
6946                 (void *)&cmd_lfc_set_tx_mode,
6947                 (void *)&cmd_lfc_set_high_water,
6948                 (void *)&cmd_lfc_set_low_water,
6949                 (void *)&cmd_lfc_set_pause_time,
6950                 (void *)&cmd_lfc_set_send_xon,
6951                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6952                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6953                 (void *)&cmd_lfc_set_autoneg_str,
6954                 (void *)&cmd_lfc_set_autoneg,
6955                 (void *)&cmd_lfc_set_portid,
6956                 NULL,
6957         },
6958 };
6959
6960 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6961         .f = cmd_link_flow_ctrl_set_parsed,
6962         .data = (void *)&cmd_link_flow_control_set_rx,
6963         .help_str = "set flow_ctrl rx on|off <port_id>: "
6964                 "Change rx flow control parameter",
6965         .tokens = {
6966                 (void *)&cmd_lfc_set_set,
6967                 (void *)&cmd_lfc_set_flow_ctrl,
6968                 (void *)&cmd_lfc_set_rx,
6969                 (void *)&cmd_lfc_set_rx_mode,
6970                 (void *)&cmd_lfc_set_portid,
6971                 NULL,
6972         },
6973 };
6974
6975 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6976         .f = cmd_link_flow_ctrl_set_parsed,
6977         .data = (void *)&cmd_link_flow_control_set_tx,
6978         .help_str = "set flow_ctrl tx on|off <port_id>: "
6979                 "Change tx flow control parameter",
6980         .tokens = {
6981                 (void *)&cmd_lfc_set_set,
6982                 (void *)&cmd_lfc_set_flow_ctrl,
6983                 (void *)&cmd_lfc_set_tx,
6984                 (void *)&cmd_lfc_set_tx_mode,
6985                 (void *)&cmd_lfc_set_portid,
6986                 NULL,
6987         },
6988 };
6989
6990 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6991         .f = cmd_link_flow_ctrl_set_parsed,
6992         .data = (void *)&cmd_link_flow_control_set_hw,
6993         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6994                 "Change high water flow control parameter",
6995         .tokens = {
6996                 (void *)&cmd_lfc_set_set,
6997                 (void *)&cmd_lfc_set_flow_ctrl,
6998                 (void *)&cmd_lfc_set_high_water_str,
6999                 (void *)&cmd_lfc_set_high_water,
7000                 (void *)&cmd_lfc_set_portid,
7001                 NULL,
7002         },
7003 };
7004
7005 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7006         .f = cmd_link_flow_ctrl_set_parsed,
7007         .data = (void *)&cmd_link_flow_control_set_lw,
7008         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7009                 "Change low water flow control parameter",
7010         .tokens = {
7011                 (void *)&cmd_lfc_set_set,
7012                 (void *)&cmd_lfc_set_flow_ctrl,
7013                 (void *)&cmd_lfc_set_low_water_str,
7014                 (void *)&cmd_lfc_set_low_water,
7015                 (void *)&cmd_lfc_set_portid,
7016                 NULL,
7017         },
7018 };
7019
7020 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7021         .f = cmd_link_flow_ctrl_set_parsed,
7022         .data = (void *)&cmd_link_flow_control_set_pt,
7023         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7024                 "Change pause time flow control parameter",
7025         .tokens = {
7026                 (void *)&cmd_lfc_set_set,
7027                 (void *)&cmd_lfc_set_flow_ctrl,
7028                 (void *)&cmd_lfc_set_pause_time_str,
7029                 (void *)&cmd_lfc_set_pause_time,
7030                 (void *)&cmd_lfc_set_portid,
7031                 NULL,
7032         },
7033 };
7034
7035 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7036         .f = cmd_link_flow_ctrl_set_parsed,
7037         .data = (void *)&cmd_link_flow_control_set_xon,
7038         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7039                 "Change send_xon flow control parameter",
7040         .tokens = {
7041                 (void *)&cmd_lfc_set_set,
7042                 (void *)&cmd_lfc_set_flow_ctrl,
7043                 (void *)&cmd_lfc_set_send_xon_str,
7044                 (void *)&cmd_lfc_set_send_xon,
7045                 (void *)&cmd_lfc_set_portid,
7046                 NULL,
7047         },
7048 };
7049
7050 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7051         .f = cmd_link_flow_ctrl_set_parsed,
7052         .data = (void *)&cmd_link_flow_control_set_macfwd,
7053         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7054                 "Change mac ctrl fwd flow control parameter",
7055         .tokens = {
7056                 (void *)&cmd_lfc_set_set,
7057                 (void *)&cmd_lfc_set_flow_ctrl,
7058                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7059                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7060                 (void *)&cmd_lfc_set_portid,
7061                 NULL,
7062         },
7063 };
7064
7065 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7066         .f = cmd_link_flow_ctrl_set_parsed,
7067         .data = (void *)&cmd_link_flow_control_set_autoneg,
7068         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7069                 "Change autoneg flow control parameter",
7070         .tokens = {
7071                 (void *)&cmd_lfc_set_set,
7072                 (void *)&cmd_lfc_set_flow_ctrl,
7073                 (void *)&cmd_lfc_set_autoneg_str,
7074                 (void *)&cmd_lfc_set_autoneg,
7075                 (void *)&cmd_lfc_set_portid,
7076                 NULL,
7077         },
7078 };
7079
7080 static void
7081 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7082                               __rte_unused struct cmdline *cl,
7083                               void *data)
7084 {
7085         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7086         cmdline_parse_inst_t *cmd = data;
7087         struct rte_eth_fc_conf fc_conf;
7088         int rx_fc_en = 0;
7089         int tx_fc_en = 0;
7090         int ret;
7091
7092         /*
7093          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7094          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7095          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7096          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7097          */
7098         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7099                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7100         };
7101
7102         /* Partial command line, retrieve current configuration */
7103         if (cmd) {
7104                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7105                 if (ret != 0) {
7106                         printf("cannot get current flow ctrl parameters, return"
7107                                "code = %d\n", ret);
7108                         return;
7109                 }
7110
7111                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7112                     (fc_conf.mode == RTE_FC_FULL))
7113                         rx_fc_en = 1;
7114                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7115                     (fc_conf.mode == RTE_FC_FULL))
7116                         tx_fc_en = 1;
7117         }
7118
7119         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7120                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7121
7122         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7123                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7124
7125         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7126
7127         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7128                 fc_conf.high_water = res->high_water;
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7131                 fc_conf.low_water = res->low_water;
7132
7133         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7134                 fc_conf.pause_time = res->pause_time;
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7137                 fc_conf.send_xon = res->send_xon;
7138
7139         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7140                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7141                         fc_conf.mac_ctrl_frame_fwd = 1;
7142                 else
7143                         fc_conf.mac_ctrl_frame_fwd = 0;
7144         }
7145
7146         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7147                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7148
7149         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7150         if (ret != 0)
7151                 printf("bad flow contrl parameter, return code = %d \n", ret);
7152 }
7153
7154 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7155 struct cmd_priority_flow_ctrl_set_result {
7156         cmdline_fixed_string_t set;
7157         cmdline_fixed_string_t pfc_ctrl;
7158         cmdline_fixed_string_t rx;
7159         cmdline_fixed_string_t rx_pfc_mode;
7160         cmdline_fixed_string_t tx;
7161         cmdline_fixed_string_t tx_pfc_mode;
7162         uint32_t high_water;
7163         uint32_t low_water;
7164         uint16_t pause_time;
7165         uint8_t  priority;
7166         portid_t port_id;
7167 };
7168
7169 static void
7170 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7171                        __rte_unused struct cmdline *cl,
7172                        __rte_unused void *data)
7173 {
7174         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7175         struct rte_eth_pfc_conf pfc_conf;
7176         int rx_fc_enable, tx_fc_enable;
7177         int ret;
7178
7179         /*
7180          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7181          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7182          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7183          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7184          */
7185         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7186                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7187         };
7188
7189         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7190         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7191         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7192         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7193         pfc_conf.fc.high_water = res->high_water;
7194         pfc_conf.fc.low_water  = res->low_water;
7195         pfc_conf.fc.pause_time = res->pause_time;
7196         pfc_conf.priority      = res->priority;
7197
7198         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7199         if (ret != 0)
7200                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7201 }
7202
7203 cmdline_parse_token_string_t cmd_pfc_set_set =
7204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205                                 set, "set");
7206 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 pfc_ctrl, "pfc_ctrl");
7209 cmdline_parse_token_string_t cmd_pfc_set_rx =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 rx, "rx");
7212 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 rx_pfc_mode, "on#off");
7215 cmdline_parse_token_string_t cmd_pfc_set_tx =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 tx, "tx");
7218 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 tx_pfc_mode, "on#off");
7221 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 high_water, RTE_UINT32);
7224 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 low_water, RTE_UINT32);
7227 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7228         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 pause_time, RTE_UINT16);
7230 cmdline_parse_token_num_t cmd_pfc_set_priority =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 priority, RTE_UINT8);
7233 cmdline_parse_token_num_t cmd_pfc_set_portid =
7234         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 port_id, RTE_UINT16);
7236
7237 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7238         .f = cmd_priority_flow_ctrl_set_parsed,
7239         .data = NULL,
7240         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7241                 "<pause_time> <priority> <port_id>: "
7242                 "Configure the Ethernet priority flow control",
7243         .tokens = {
7244                 (void *)&cmd_pfc_set_set,
7245                 (void *)&cmd_pfc_set_flow_ctrl,
7246                 (void *)&cmd_pfc_set_rx,
7247                 (void *)&cmd_pfc_set_rx_mode,
7248                 (void *)&cmd_pfc_set_tx,
7249                 (void *)&cmd_pfc_set_tx_mode,
7250                 (void *)&cmd_pfc_set_high_water,
7251                 (void *)&cmd_pfc_set_low_water,
7252                 (void *)&cmd_pfc_set_pause_time,
7253                 (void *)&cmd_pfc_set_priority,
7254                 (void *)&cmd_pfc_set_portid,
7255                 NULL,
7256         },
7257 };
7258
7259 /* *** RESET CONFIGURATION *** */
7260 struct cmd_reset_result {
7261         cmdline_fixed_string_t reset;
7262         cmdline_fixed_string_t def;
7263 };
7264
7265 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7266                              struct cmdline *cl,
7267                              __rte_unused void *data)
7268 {
7269         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7270         set_def_fwd_config();
7271 }
7272
7273 cmdline_parse_token_string_t cmd_reset_set =
7274         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7275 cmdline_parse_token_string_t cmd_reset_def =
7276         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7277                                  "default");
7278
7279 cmdline_parse_inst_t cmd_reset = {
7280         .f = cmd_reset_parsed,
7281         .data = NULL,
7282         .help_str = "set default: Reset default forwarding configuration",
7283         .tokens = {
7284                 (void *)&cmd_reset_set,
7285                 (void *)&cmd_reset_def,
7286                 NULL,
7287         },
7288 };
7289
7290 /* *** START FORWARDING *** */
7291 struct cmd_start_result {
7292         cmdline_fixed_string_t start;
7293 };
7294
7295 cmdline_parse_token_string_t cmd_start_start =
7296         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7297
7298 static void cmd_start_parsed(__rte_unused void *parsed_result,
7299                              __rte_unused struct cmdline *cl,
7300                              __rte_unused void *data)
7301 {
7302         start_packet_forwarding(0);
7303 }
7304
7305 cmdline_parse_inst_t cmd_start = {
7306         .f = cmd_start_parsed,
7307         .data = NULL,
7308         .help_str = "start: Start packet forwarding",
7309         .tokens = {
7310                 (void *)&cmd_start_start,
7311                 NULL,
7312         },
7313 };
7314
7315 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7316 struct cmd_start_tx_first_result {
7317         cmdline_fixed_string_t start;
7318         cmdline_fixed_string_t tx_first;
7319 };
7320
7321 static void
7322 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7323                           __rte_unused struct cmdline *cl,
7324                           __rte_unused void *data)
7325 {
7326         start_packet_forwarding(1);
7327 }
7328
7329 cmdline_parse_token_string_t cmd_start_tx_first_start =
7330         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7331                                  "start");
7332 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7333         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7334                                  tx_first, "tx_first");
7335
7336 cmdline_parse_inst_t cmd_start_tx_first = {
7337         .f = cmd_start_tx_first_parsed,
7338         .data = NULL,
7339         .help_str = "start tx_first: Start packet forwarding, "
7340                 "after sending 1 burst of packets",
7341         .tokens = {
7342                 (void *)&cmd_start_tx_first_start,
7343                 (void *)&cmd_start_tx_first_tx_first,
7344                 NULL,
7345         },
7346 };
7347
7348 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7349 struct cmd_start_tx_first_n_result {
7350         cmdline_fixed_string_t start;
7351         cmdline_fixed_string_t tx_first;
7352         uint32_t tx_num;
7353 };
7354
7355 static void
7356 cmd_start_tx_first_n_parsed(void *parsed_result,
7357                           __rte_unused struct cmdline *cl,
7358                           __rte_unused void *data)
7359 {
7360         struct cmd_start_tx_first_n_result *res = parsed_result;
7361
7362         start_packet_forwarding(res->tx_num);
7363 }
7364
7365 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7366         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7367                         start, "start");
7368 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7369         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7370                         tx_first, "tx_first");
7371 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7372         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7373                         tx_num, RTE_UINT32);
7374
7375 cmdline_parse_inst_t cmd_start_tx_first_n = {
7376         .f = cmd_start_tx_first_n_parsed,
7377         .data = NULL,
7378         .help_str = "start tx_first <num>: "
7379                 "packet forwarding, after sending <num> bursts of packets",
7380         .tokens = {
7381                 (void *)&cmd_start_tx_first_n_start,
7382                 (void *)&cmd_start_tx_first_n_tx_first,
7383                 (void *)&cmd_start_tx_first_n_tx_num,
7384                 NULL,
7385         },
7386 };
7387
7388 /* *** SET LINK UP *** */
7389 struct cmd_set_link_up_result {
7390         cmdline_fixed_string_t set;
7391         cmdline_fixed_string_t link_up;
7392         cmdline_fixed_string_t port;
7393         portid_t port_id;
7394 };
7395
7396 cmdline_parse_token_string_t cmd_set_link_up_set =
7397         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7398 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7400                                 "link-up");
7401 cmdline_parse_token_string_t cmd_set_link_up_port =
7402         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7403 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7404         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7405                                 RTE_UINT16);
7406
7407 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7408                              __rte_unused struct cmdline *cl,
7409                              __rte_unused void *data)
7410 {
7411         struct cmd_set_link_up_result *res = parsed_result;
7412         dev_set_link_up(res->port_id);
7413 }
7414
7415 cmdline_parse_inst_t cmd_set_link_up = {
7416         .f = cmd_set_link_up_parsed,
7417         .data = NULL,
7418         .help_str = "set link-up port <port id>",
7419         .tokens = {
7420                 (void *)&cmd_set_link_up_set,
7421                 (void *)&cmd_set_link_up_link_up,
7422                 (void *)&cmd_set_link_up_port,
7423                 (void *)&cmd_set_link_up_port_id,
7424                 NULL,
7425         },
7426 };
7427
7428 /* *** SET LINK DOWN *** */
7429 struct cmd_set_link_down_result {
7430         cmdline_fixed_string_t set;
7431         cmdline_fixed_string_t link_down;
7432         cmdline_fixed_string_t port;
7433         portid_t port_id;
7434 };
7435
7436 cmdline_parse_token_string_t cmd_set_link_down_set =
7437         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7438 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7440                                 "link-down");
7441 cmdline_parse_token_string_t cmd_set_link_down_port =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7443 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7444         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7445                                 RTE_UINT16);
7446
7447 static void cmd_set_link_down_parsed(
7448                                 __rte_unused void *parsed_result,
7449                                 __rte_unused struct cmdline *cl,
7450                                 __rte_unused void *data)
7451 {
7452         struct cmd_set_link_down_result *res = parsed_result;
7453         dev_set_link_down(res->port_id);
7454 }
7455
7456 cmdline_parse_inst_t cmd_set_link_down = {
7457         .f = cmd_set_link_down_parsed,
7458         .data = NULL,
7459         .help_str = "set link-down port <port id>",
7460         .tokens = {
7461                 (void *)&cmd_set_link_down_set,
7462                 (void *)&cmd_set_link_down_link_down,
7463                 (void *)&cmd_set_link_down_port,
7464                 (void *)&cmd_set_link_down_port_id,
7465                 NULL,
7466         },
7467 };
7468
7469 /* *** SHOW CFG *** */
7470 struct cmd_showcfg_result {
7471         cmdline_fixed_string_t show;
7472         cmdline_fixed_string_t cfg;
7473         cmdline_fixed_string_t what;
7474 };
7475
7476 static void cmd_showcfg_parsed(void *parsed_result,
7477                                __rte_unused struct cmdline *cl,
7478                                __rte_unused void *data)
7479 {
7480         struct cmd_showcfg_result *res = parsed_result;
7481         if (!strcmp(res->what, "rxtx"))
7482                 rxtx_config_display();
7483         else if (!strcmp(res->what, "cores"))
7484                 fwd_lcores_config_display();
7485         else if (!strcmp(res->what, "fwd"))
7486                 pkt_fwd_config_display(&cur_fwd_config);
7487         else if (!strcmp(res->what, "rxoffs"))
7488                 show_rx_pkt_offsets();
7489         else if (!strcmp(res->what, "rxpkts"))
7490                 show_rx_pkt_segments();
7491         else if (!strcmp(res->what, "txpkts"))
7492                 show_tx_pkt_segments();
7493         else if (!strcmp(res->what, "txtimes"))
7494                 show_tx_pkt_times();
7495 }
7496
7497 cmdline_parse_token_string_t cmd_showcfg_show =
7498         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7499 cmdline_parse_token_string_t cmd_showcfg_port =
7500         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7501 cmdline_parse_token_string_t cmd_showcfg_what =
7502         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7503                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7504
7505 cmdline_parse_inst_t cmd_showcfg = {
7506         .f = cmd_showcfg_parsed,
7507         .data = NULL,
7508         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7509         .tokens = {
7510                 (void *)&cmd_showcfg_show,
7511                 (void *)&cmd_showcfg_port,
7512                 (void *)&cmd_showcfg_what,
7513                 NULL,
7514         },
7515 };
7516
7517 /* *** SHOW ALL PORT INFO *** */
7518 struct cmd_showportall_result {
7519         cmdline_fixed_string_t show;
7520         cmdline_fixed_string_t port;
7521         cmdline_fixed_string_t what;
7522         cmdline_fixed_string_t all;
7523 };
7524
7525 static void cmd_showportall_parsed(void *parsed_result,
7526                                 __rte_unused struct cmdline *cl,
7527                                 __rte_unused void *data)
7528 {
7529         portid_t i;
7530
7531         struct cmd_showportall_result *res = parsed_result;
7532         if (!strcmp(res->show, "clear")) {
7533                 if (!strcmp(res->what, "stats"))
7534                         RTE_ETH_FOREACH_DEV(i)
7535                                 nic_stats_clear(i);
7536                 else if (!strcmp(res->what, "xstats"))
7537                         RTE_ETH_FOREACH_DEV(i)
7538                                 nic_xstats_clear(i);
7539         } else if (!strcmp(res->what, "info"))
7540                 RTE_ETH_FOREACH_DEV(i)
7541                         port_infos_display(i);
7542         else if (!strcmp(res->what, "summary")) {
7543                 port_summary_header_display();
7544                 RTE_ETH_FOREACH_DEV(i)
7545                         port_summary_display(i);
7546         }
7547         else if (!strcmp(res->what, "stats"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_stats_display(i);
7550         else if (!strcmp(res->what, "xstats"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         nic_xstats_display(i);
7553 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7554         else if (!strcmp(res->what, "fdir"))
7555                 RTE_ETH_FOREACH_DEV(i)
7556                         fdir_get_infos(i);
7557 #endif
7558         else if (!strcmp(res->what, "stat_qmap"))
7559                 RTE_ETH_FOREACH_DEV(i)
7560                         nic_stats_mapping_display(i);
7561         else if (!strcmp(res->what, "dcb_tc"))
7562                 RTE_ETH_FOREACH_DEV(i)
7563                         port_dcb_info_display(i);
7564         else if (!strcmp(res->what, "cap"))
7565                 RTE_ETH_FOREACH_DEV(i)
7566                         port_offload_cap_display(i);
7567 }
7568
7569 cmdline_parse_token_string_t cmd_showportall_show =
7570         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7571                                  "show#clear");
7572 cmdline_parse_token_string_t cmd_showportall_port =
7573         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7574 cmdline_parse_token_string_t cmd_showportall_what =
7575         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7576                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7577 cmdline_parse_token_string_t cmd_showportall_all =
7578         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7579 cmdline_parse_inst_t cmd_showportall = {
7580         .f = cmd_showportall_parsed,
7581         .data = NULL,
7582         .help_str = "show|clear port "
7583                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7584         .tokens = {
7585                 (void *)&cmd_showportall_show,
7586                 (void *)&cmd_showportall_port,
7587                 (void *)&cmd_showportall_what,
7588                 (void *)&cmd_showportall_all,
7589                 NULL,
7590         },
7591 };
7592
7593 /* *** SHOW PORT INFO *** */
7594 struct cmd_showport_result {
7595         cmdline_fixed_string_t show;
7596         cmdline_fixed_string_t port;
7597         cmdline_fixed_string_t what;
7598         uint16_t portnum;
7599 };
7600
7601 static void cmd_showport_parsed(void *parsed_result,
7602                                 __rte_unused struct cmdline *cl,
7603                                 __rte_unused void *data)
7604 {
7605         struct cmd_showport_result *res = parsed_result;
7606         if (!strcmp(res->show, "clear")) {
7607                 if (!strcmp(res->what, "stats"))
7608                         nic_stats_clear(res->portnum);
7609                 else if (!strcmp(res->what, "xstats"))
7610                         nic_xstats_clear(res->portnum);
7611         } else if (!strcmp(res->what, "info"))
7612                 port_infos_display(res->portnum);
7613         else if (!strcmp(res->what, "summary")) {
7614                 port_summary_header_display();
7615                 port_summary_display(res->portnum);
7616         }
7617         else if (!strcmp(res->what, "stats"))
7618                 nic_stats_display(res->portnum);
7619         else if (!strcmp(res->what, "xstats"))
7620                 nic_xstats_display(res->portnum);
7621 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7622         else if (!strcmp(res->what, "fdir"))
7623                  fdir_get_infos(res->portnum);
7624 #endif
7625         else if (!strcmp(res->what, "stat_qmap"))
7626                 nic_stats_mapping_display(res->portnum);
7627         else if (!strcmp(res->what, "dcb_tc"))
7628                 port_dcb_info_display(res->portnum);
7629         else if (!strcmp(res->what, "cap"))
7630                 port_offload_cap_display(res->portnum);
7631 }
7632
7633 cmdline_parse_token_string_t cmd_showport_show =
7634         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7635                                  "show#clear");
7636 cmdline_parse_token_string_t cmd_showport_port =
7637         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7638 cmdline_parse_token_string_t cmd_showport_what =
7639         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7640                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7641 cmdline_parse_token_num_t cmd_showport_portnum =
7642         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7643
7644 cmdline_parse_inst_t cmd_showport = {
7645         .f = cmd_showport_parsed,
7646         .data = NULL,
7647         .help_str = "show|clear port "
7648                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7649                 "<port_id>",
7650         .tokens = {
7651                 (void *)&cmd_showport_show,
7652                 (void *)&cmd_showport_port,
7653                 (void *)&cmd_showport_what,
7654                 (void *)&cmd_showport_portnum,
7655                 NULL,
7656         },
7657 };
7658
7659 /* *** SHOW DEVICE INFO *** */
7660 struct cmd_showdevice_result {
7661         cmdline_fixed_string_t show;
7662         cmdline_fixed_string_t device;
7663         cmdline_fixed_string_t what;
7664         cmdline_fixed_string_t identifier;
7665 };
7666
7667 static void cmd_showdevice_parsed(void *parsed_result,
7668                                 __rte_unused struct cmdline *cl,
7669                                 __rte_unused void *data)
7670 {
7671         struct cmd_showdevice_result *res = parsed_result;
7672         if (!strcmp(res->what, "info")) {
7673                 if (!strcmp(res->identifier, "all"))
7674                         device_infos_display(NULL);
7675                 else
7676                         device_infos_display(res->identifier);
7677         }
7678 }
7679
7680 cmdline_parse_token_string_t cmd_showdevice_show =
7681         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7682                                  "show");
7683 cmdline_parse_token_string_t cmd_showdevice_device =
7684         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7685 cmdline_parse_token_string_t cmd_showdevice_what =
7686         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7687                                  "info");
7688 cmdline_parse_token_string_t cmd_showdevice_identifier =
7689         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7690                         identifier, NULL);
7691
7692 cmdline_parse_inst_t cmd_showdevice = {
7693         .f = cmd_showdevice_parsed,
7694         .data = NULL,
7695         .help_str = "show device info <identifier>|all",
7696         .tokens = {
7697                 (void *)&cmd_showdevice_show,
7698                 (void *)&cmd_showdevice_device,
7699                 (void *)&cmd_showdevice_what,
7700                 (void *)&cmd_showdevice_identifier,
7701                 NULL,
7702         },
7703 };
7704
7705 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7706 struct cmd_showeeprom_result {
7707         cmdline_fixed_string_t show;
7708         cmdline_fixed_string_t port;
7709         uint16_t portnum;
7710         cmdline_fixed_string_t type;
7711 };
7712
7713 static void cmd_showeeprom_parsed(void *parsed_result,
7714                 __rte_unused struct cmdline *cl,
7715                 __rte_unused void *data)
7716 {
7717         struct cmd_showeeprom_result *res = parsed_result;
7718
7719         if (!strcmp(res->type, "eeprom"))
7720                 port_eeprom_display(res->portnum);
7721         else if (!strcmp(res->type, "module_eeprom"))
7722                 port_module_eeprom_display(res->portnum);
7723         else
7724                 printf("Unknown argument\n");
7725 }
7726
7727 cmdline_parse_token_string_t cmd_showeeprom_show =
7728         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7729 cmdline_parse_token_string_t cmd_showeeprom_port =
7730         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7731 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7732         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7733                         RTE_UINT16);
7734 cmdline_parse_token_string_t cmd_showeeprom_type =
7735         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7736
7737 cmdline_parse_inst_t cmd_showeeprom = {
7738         .f = cmd_showeeprom_parsed,
7739         .data = NULL,
7740         .help_str = "show port <port_id> module_eeprom|eeprom",
7741         .tokens = {
7742                 (void *)&cmd_showeeprom_show,
7743                 (void *)&cmd_showeeprom_port,
7744                 (void *)&cmd_showeeprom_portnum,
7745                 (void *)&cmd_showeeprom_type,
7746                 NULL,
7747         },
7748 };
7749
7750 /* *** SHOW QUEUE INFO *** */
7751 struct cmd_showqueue_result {
7752         cmdline_fixed_string_t show;
7753         cmdline_fixed_string_t type;
7754         cmdline_fixed_string_t what;
7755         uint16_t portnum;
7756         uint16_t queuenum;
7757 };
7758
7759 static void
7760 cmd_showqueue_parsed(void *parsed_result,
7761         __rte_unused struct cmdline *cl,
7762         __rte_unused void *data)
7763 {
7764         struct cmd_showqueue_result *res = parsed_result;
7765
7766         if (!strcmp(res->type, "rxq"))
7767                 rx_queue_infos_display(res->portnum, res->queuenum);
7768         else if (!strcmp(res->type, "txq"))
7769                 tx_queue_infos_display(res->portnum, res->queuenum);
7770 }
7771
7772 cmdline_parse_token_string_t cmd_showqueue_show =
7773         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7774 cmdline_parse_token_string_t cmd_showqueue_type =
7775         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7776 cmdline_parse_token_string_t cmd_showqueue_what =
7777         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7778 cmdline_parse_token_num_t cmd_showqueue_portnum =
7779         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7780                 RTE_UINT16);
7781 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7782         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7783                 RTE_UINT16);
7784
7785 cmdline_parse_inst_t cmd_showqueue = {
7786         .f = cmd_showqueue_parsed,
7787         .data = NULL,
7788         .help_str = "show rxq|txq info <port_id> <queue_id>",
7789         .tokens = {
7790                 (void *)&cmd_showqueue_show,
7791                 (void *)&cmd_showqueue_type,
7792                 (void *)&cmd_showqueue_what,
7793                 (void *)&cmd_showqueue_portnum,
7794                 (void *)&cmd_showqueue_queuenum,
7795                 NULL,
7796         },
7797 };
7798
7799 /* show/clear fwd engine statistics */
7800 struct fwd_result {
7801         cmdline_fixed_string_t action;
7802         cmdline_fixed_string_t fwd;
7803         cmdline_fixed_string_t stats;
7804         cmdline_fixed_string_t all;
7805 };
7806
7807 cmdline_parse_token_string_t cmd_fwd_action =
7808         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7809 cmdline_parse_token_string_t cmd_fwd_fwd =
7810         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7811 cmdline_parse_token_string_t cmd_fwd_stats =
7812         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7813 cmdline_parse_token_string_t cmd_fwd_all =
7814         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7815
7816 static void
7817 cmd_showfwdall_parsed(void *parsed_result,
7818                       __rte_unused struct cmdline *cl,
7819                       __rte_unused void *data)
7820 {
7821         struct fwd_result *res = parsed_result;
7822
7823         if (!strcmp(res->action, "show"))
7824                 fwd_stats_display();
7825         else
7826                 fwd_stats_reset();
7827 }
7828
7829 static cmdline_parse_inst_t cmd_showfwdall = {
7830         .f = cmd_showfwdall_parsed,
7831         .data = NULL,
7832         .help_str = "show|clear fwd stats all",
7833         .tokens = {
7834                 (void *)&cmd_fwd_action,
7835                 (void *)&cmd_fwd_fwd,
7836                 (void *)&cmd_fwd_stats,
7837                 (void *)&cmd_fwd_all,
7838                 NULL,
7839         },
7840 };
7841
7842 /* *** READ PORT REGISTER *** */
7843 struct cmd_read_reg_result {
7844         cmdline_fixed_string_t read;
7845         cmdline_fixed_string_t reg;
7846         portid_t port_id;
7847         uint32_t reg_off;
7848 };
7849
7850 static void
7851 cmd_read_reg_parsed(void *parsed_result,
7852                     __rte_unused struct cmdline *cl,
7853                     __rte_unused void *data)
7854 {
7855         struct cmd_read_reg_result *res = parsed_result;
7856         port_reg_display(res->port_id, res->reg_off);
7857 }
7858
7859 cmdline_parse_token_string_t cmd_read_reg_read =
7860         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7861 cmdline_parse_token_string_t cmd_read_reg_reg =
7862         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7863 cmdline_parse_token_num_t cmd_read_reg_port_id =
7864         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7865 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7866         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7867
7868 cmdline_parse_inst_t cmd_read_reg = {
7869         .f = cmd_read_reg_parsed,
7870         .data = NULL,
7871         .help_str = "read reg <port_id> <reg_off>",
7872         .tokens = {
7873                 (void *)&cmd_read_reg_read,
7874                 (void *)&cmd_read_reg_reg,
7875                 (void *)&cmd_read_reg_port_id,
7876                 (void *)&cmd_read_reg_reg_off,
7877                 NULL,
7878         },
7879 };
7880
7881 /* *** READ PORT REGISTER BIT FIELD *** */
7882 struct cmd_read_reg_bit_field_result {
7883         cmdline_fixed_string_t read;
7884         cmdline_fixed_string_t regfield;
7885         portid_t port_id;
7886         uint32_t reg_off;
7887         uint8_t bit1_pos;
7888         uint8_t bit2_pos;
7889 };
7890
7891 static void
7892 cmd_read_reg_bit_field_parsed(void *parsed_result,
7893                               __rte_unused struct cmdline *cl,
7894                               __rte_unused void *data)
7895 {
7896         struct cmd_read_reg_bit_field_result *res = parsed_result;
7897         port_reg_bit_field_display(res->port_id, res->reg_off,
7898                                    res->bit1_pos, res->bit2_pos);
7899 }
7900
7901 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7902         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7903                                  "read");
7904 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7905         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7906                                  regfield, "regfield");
7907 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7908         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7909                               RTE_UINT16);
7910 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7911         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7912                               RTE_UINT32);
7913 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7914         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7915                               RTE_UINT8);
7916 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7917         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7918                               RTE_UINT8);
7919
7920 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7921         .f = cmd_read_reg_bit_field_parsed,
7922         .data = NULL,
7923         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7924         "Read register bit field between bit_x and bit_y included",
7925         .tokens = {
7926                 (void *)&cmd_read_reg_bit_field_read,
7927                 (void *)&cmd_read_reg_bit_field_regfield,
7928                 (void *)&cmd_read_reg_bit_field_port_id,
7929                 (void *)&cmd_read_reg_bit_field_reg_off,
7930                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7931                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7932                 NULL,
7933         },
7934 };
7935
7936 /* *** READ PORT REGISTER BIT *** */
7937 struct cmd_read_reg_bit_result {
7938         cmdline_fixed_string_t read;
7939         cmdline_fixed_string_t regbit;
7940         portid_t port_id;
7941         uint32_t reg_off;
7942         uint8_t bit_pos;
7943 };
7944
7945 static void
7946 cmd_read_reg_bit_parsed(void *parsed_result,
7947                         __rte_unused struct cmdline *cl,
7948                         __rte_unused void *data)
7949 {
7950         struct cmd_read_reg_bit_result *res = parsed_result;
7951         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7952 }
7953
7954 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7955         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7956 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7957         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7958                                  regbit, "regbit");
7959 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7960         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7961                                  RTE_UINT16);
7962 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7963         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7964                                  RTE_UINT32);
7965 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7966         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7967                                  RTE_UINT8);
7968
7969 cmdline_parse_inst_t cmd_read_reg_bit = {
7970         .f = cmd_read_reg_bit_parsed,
7971         .data = NULL,
7972         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7973         .tokens = {
7974                 (void *)&cmd_read_reg_bit_read,
7975                 (void *)&cmd_read_reg_bit_regbit,
7976                 (void *)&cmd_read_reg_bit_port_id,
7977                 (void *)&cmd_read_reg_bit_reg_off,
7978                 (void *)&cmd_read_reg_bit_bit_pos,
7979                 NULL,
7980         },
7981 };
7982
7983 /* *** WRITE PORT REGISTER *** */
7984 struct cmd_write_reg_result {
7985         cmdline_fixed_string_t write;
7986         cmdline_fixed_string_t reg;
7987         portid_t port_id;
7988         uint32_t reg_off;
7989         uint32_t value;
7990 };
7991
7992 static void
7993 cmd_write_reg_parsed(void *parsed_result,
7994                      __rte_unused struct cmdline *cl,
7995                      __rte_unused void *data)
7996 {
7997         struct cmd_write_reg_result *res = parsed_result;
7998         port_reg_set(res->port_id, res->reg_off, res->value);
7999 }
8000
8001 cmdline_parse_token_string_t cmd_write_reg_write =
8002         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8003 cmdline_parse_token_string_t cmd_write_reg_reg =
8004         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8005 cmdline_parse_token_num_t cmd_write_reg_port_id =
8006         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8007 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8008         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8009 cmdline_parse_token_num_t cmd_write_reg_value =
8010         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8011
8012 cmdline_parse_inst_t cmd_write_reg = {
8013         .f = cmd_write_reg_parsed,
8014         .data = NULL,
8015         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8016         .tokens = {
8017                 (void *)&cmd_write_reg_write,
8018                 (void *)&cmd_write_reg_reg,
8019                 (void *)&cmd_write_reg_port_id,
8020                 (void *)&cmd_write_reg_reg_off,
8021                 (void *)&cmd_write_reg_value,
8022                 NULL,
8023         },
8024 };
8025
8026 /* *** WRITE PORT REGISTER BIT FIELD *** */
8027 struct cmd_write_reg_bit_field_result {
8028         cmdline_fixed_string_t write;
8029         cmdline_fixed_string_t regfield;
8030         portid_t port_id;
8031         uint32_t reg_off;
8032         uint8_t bit1_pos;
8033         uint8_t bit2_pos;
8034         uint32_t value;
8035 };
8036
8037 static void
8038 cmd_write_reg_bit_field_parsed(void *parsed_result,
8039                                __rte_unused struct cmdline *cl,
8040                                __rte_unused void *data)
8041 {
8042         struct cmd_write_reg_bit_field_result *res = parsed_result;
8043         port_reg_bit_field_set(res->port_id, res->reg_off,
8044                           res->bit1_pos, res->bit2_pos, res->value);
8045 }
8046
8047 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8048         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8049                                  "write");
8050 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8051         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8052                                  regfield, "regfield");
8053 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8054         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8055                               RTE_UINT16);
8056 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8057         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8058                               RTE_UINT32);
8059 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8060         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8061                               RTE_UINT8);
8062 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8063         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8064                               RTE_UINT8);
8065 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8066         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8067                               RTE_UINT32);
8068
8069 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8070         .f = cmd_write_reg_bit_field_parsed,
8071         .data = NULL,
8072         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8073                 "<reg_value>: "
8074                 "Set register bit field between bit_x and bit_y included",
8075         .tokens = {
8076                 (void *)&cmd_write_reg_bit_field_write,
8077                 (void *)&cmd_write_reg_bit_field_regfield,
8078                 (void *)&cmd_write_reg_bit_field_port_id,
8079                 (void *)&cmd_write_reg_bit_field_reg_off,
8080                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8081                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8082                 (void *)&cmd_write_reg_bit_field_value,
8083                 NULL,
8084         },
8085 };
8086
8087 /* *** WRITE PORT REGISTER BIT *** */
8088 struct cmd_write_reg_bit_result {
8089         cmdline_fixed_string_t write;
8090         cmdline_fixed_string_t regbit;
8091         portid_t port_id;
8092         uint32_t reg_off;
8093         uint8_t bit_pos;
8094         uint8_t value;
8095 };
8096
8097 static void
8098 cmd_write_reg_bit_parsed(void *parsed_result,
8099                          __rte_unused struct cmdline *cl,
8100                          __rte_unused void *data)
8101 {
8102         struct cmd_write_reg_bit_result *res = parsed_result;
8103         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8104 }
8105
8106 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8107         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8108                                  "write");
8109 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8110         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8111                                  regbit, "regbit");
8112 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8113         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8114                                  RTE_UINT16);
8115 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8116         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8117                                  RTE_UINT32);
8118 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8119         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8120                                  RTE_UINT8);
8121 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8122         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8123                                  RTE_UINT8);
8124
8125 cmdline_parse_inst_t cmd_write_reg_bit = {
8126         .f = cmd_write_reg_bit_parsed,
8127         .data = NULL,
8128         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8129                 "0 <= bit_x <= 31",
8130         .tokens = {
8131                 (void *)&cmd_write_reg_bit_write,
8132                 (void *)&cmd_write_reg_bit_regbit,
8133                 (void *)&cmd_write_reg_bit_port_id,
8134                 (void *)&cmd_write_reg_bit_reg_off,
8135                 (void *)&cmd_write_reg_bit_bit_pos,
8136                 (void *)&cmd_write_reg_bit_value,
8137                 NULL,
8138         },
8139 };
8140
8141 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8142 struct cmd_read_rxd_txd_result {
8143         cmdline_fixed_string_t read;
8144         cmdline_fixed_string_t rxd_txd;
8145         portid_t port_id;
8146         uint16_t queue_id;
8147         uint16_t desc_id;
8148 };
8149
8150 static void
8151 cmd_read_rxd_txd_parsed(void *parsed_result,
8152                         __rte_unused struct cmdline *cl,
8153                         __rte_unused void *data)
8154 {
8155         struct cmd_read_rxd_txd_result *res = parsed_result;
8156
8157         if (!strcmp(res->rxd_txd, "rxd"))
8158                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8159         else if (!strcmp(res->rxd_txd, "txd"))
8160                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8161 }
8162
8163 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8164         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8165 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8166         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8167                                  "rxd#txd");
8168 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8169         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8170                                  RTE_UINT16);
8171 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8172         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8173                                  RTE_UINT16);
8174 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8175         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8176                                  RTE_UINT16);
8177
8178 cmdline_parse_inst_t cmd_read_rxd_txd = {
8179         .f = cmd_read_rxd_txd_parsed,
8180         .data = NULL,
8181         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8182         .tokens = {
8183                 (void *)&cmd_read_rxd_txd_read,
8184                 (void *)&cmd_read_rxd_txd_rxd_txd,
8185                 (void *)&cmd_read_rxd_txd_port_id,
8186                 (void *)&cmd_read_rxd_txd_queue_id,
8187                 (void *)&cmd_read_rxd_txd_desc_id,
8188                 NULL,
8189         },
8190 };
8191
8192 /* *** QUIT *** */
8193 struct cmd_quit_result {
8194         cmdline_fixed_string_t quit;
8195 };
8196
8197 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8198                             struct cmdline *cl,
8199                             __rte_unused void *data)
8200 {
8201         cmdline_quit(cl);
8202 }
8203
8204 cmdline_parse_token_string_t cmd_quit_quit =
8205         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8206
8207 cmdline_parse_inst_t cmd_quit = {
8208         .f = cmd_quit_parsed,
8209         .data = NULL,
8210         .help_str = "quit: Exit application",
8211         .tokens = {
8212                 (void *)&cmd_quit_quit,
8213                 NULL,
8214         },
8215 };
8216
8217 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8218 struct cmd_mac_addr_result {
8219         cmdline_fixed_string_t mac_addr_cmd;
8220         cmdline_fixed_string_t what;
8221         uint16_t port_num;
8222         struct rte_ether_addr address;
8223 };
8224
8225 static void cmd_mac_addr_parsed(void *parsed_result,
8226                 __rte_unused struct cmdline *cl,
8227                 __rte_unused void *data)
8228 {
8229         struct cmd_mac_addr_result *res = parsed_result;
8230         int ret;
8231
8232         if (strcmp(res->what, "add") == 0)
8233                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8234         else if (strcmp(res->what, "set") == 0)
8235                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8236                                                        &res->address);
8237         else
8238                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8239
8240         /* check the return value and print it if is < 0 */
8241         if(ret < 0)
8242                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8243
8244 }
8245
8246 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8247         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8248                                 "mac_addr");
8249 cmdline_parse_token_string_t cmd_mac_addr_what =
8250         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8251                                 "add#remove#set");
8252 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8253                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8254                                         RTE_UINT16);
8255 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8256                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8257
8258 cmdline_parse_inst_t cmd_mac_addr = {
8259         .f = cmd_mac_addr_parsed,
8260         .data = (void *)0,
8261         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8262                         "Add/Remove/Set MAC address on port_id",
8263         .tokens = {
8264                 (void *)&cmd_mac_addr_cmd,
8265                 (void *)&cmd_mac_addr_what,
8266                 (void *)&cmd_mac_addr_portnum,
8267                 (void *)&cmd_mac_addr_addr,
8268                 NULL,
8269         },
8270 };
8271
8272 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8273 struct cmd_eth_peer_result {
8274         cmdline_fixed_string_t set;
8275         cmdline_fixed_string_t eth_peer;
8276         portid_t port_id;
8277         cmdline_fixed_string_t peer_addr;
8278 };
8279
8280 static void cmd_set_eth_peer_parsed(void *parsed_result,
8281                         __rte_unused struct cmdline *cl,
8282                         __rte_unused void *data)
8283 {
8284                 struct cmd_eth_peer_result *res = parsed_result;
8285
8286                 if (test_done == 0) {
8287                         printf("Please stop forwarding first\n");
8288                         return;
8289                 }
8290                 if (!strcmp(res->eth_peer, "eth-peer")) {
8291                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8292                         fwd_config_setup();
8293                 }
8294 }
8295 cmdline_parse_token_string_t cmd_eth_peer_set =
8296         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8297 cmdline_parse_token_string_t cmd_eth_peer =
8298         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8299 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8300         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8301                 RTE_UINT16);
8302 cmdline_parse_token_string_t cmd_eth_peer_addr =
8303         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8304
8305 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8306         .f = cmd_set_eth_peer_parsed,
8307         .data = NULL,
8308         .help_str = "set eth-peer <port_id> <peer_mac>",
8309         .tokens = {
8310                 (void *)&cmd_eth_peer_set,
8311                 (void *)&cmd_eth_peer,
8312                 (void *)&cmd_eth_peer_port_id,
8313                 (void *)&cmd_eth_peer_addr,
8314                 NULL,
8315         },
8316 };
8317
8318 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8319 struct cmd_set_qmap_result {
8320         cmdline_fixed_string_t set;
8321         cmdline_fixed_string_t qmap;
8322         cmdline_fixed_string_t what;
8323         portid_t port_id;
8324         uint16_t queue_id;
8325         uint8_t map_value;
8326 };
8327
8328 static void
8329 cmd_set_qmap_parsed(void *parsed_result,
8330                        __rte_unused struct cmdline *cl,
8331                        __rte_unused void *data)
8332 {
8333         struct cmd_set_qmap_result *res = parsed_result;
8334         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8335
8336         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8337 }
8338
8339 cmdline_parse_token_string_t cmd_setqmap_set =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8341                                  set, "set");
8342 cmdline_parse_token_string_t cmd_setqmap_qmap =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8344                                  qmap, "stat_qmap");
8345 cmdline_parse_token_string_t cmd_setqmap_what =
8346         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8347                                  what, "tx#rx");
8348 cmdline_parse_token_num_t cmd_setqmap_portid =
8349         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8350                               port_id, RTE_UINT16);
8351 cmdline_parse_token_num_t cmd_setqmap_queueid =
8352         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8353                               queue_id, RTE_UINT16);
8354 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8355         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8356                               map_value, RTE_UINT8);
8357
8358 cmdline_parse_inst_t cmd_set_qmap = {
8359         .f = cmd_set_qmap_parsed,
8360         .data = NULL,
8361         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8362                 "Set statistics mapping value on tx|rx queue_id of port_id",
8363         .tokens = {
8364                 (void *)&cmd_setqmap_set,
8365                 (void *)&cmd_setqmap_qmap,
8366                 (void *)&cmd_setqmap_what,
8367                 (void *)&cmd_setqmap_portid,
8368                 (void *)&cmd_setqmap_queueid,
8369                 (void *)&cmd_setqmap_mapvalue,
8370                 NULL,
8371         },
8372 };
8373
8374 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8375 struct cmd_set_xstats_hide_zero_result {
8376         cmdline_fixed_string_t keyword;
8377         cmdline_fixed_string_t name;
8378         cmdline_fixed_string_t on_off;
8379 };
8380
8381 static void
8382 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8383                         __rte_unused struct cmdline *cl,
8384                         __rte_unused void *data)
8385 {
8386         struct cmd_set_xstats_hide_zero_result *res;
8387         uint16_t on_off = 0;
8388
8389         res = parsed_result;
8390         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8391         set_xstats_hide_zero(on_off);
8392 }
8393
8394 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8395         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8396                                  keyword, "set");
8397 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8398         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8399                                  name, "xstats-hide-zero");
8400 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8401         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8402                                  on_off, "on#off");
8403
8404 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8405         .f = cmd_set_xstats_hide_zero_parsed,
8406         .data = NULL,
8407         .help_str = "set xstats-hide-zero on|off",
8408         .tokens = {
8409                 (void *)&cmd_set_xstats_hide_zero_keyword,
8410                 (void *)&cmd_set_xstats_hide_zero_name,
8411                 (void *)&cmd_set_xstats_hide_zero_on_off,
8412                 NULL,
8413         },
8414 };
8415
8416 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8417 struct cmd_set_record_core_cycles_result {
8418         cmdline_fixed_string_t keyword;
8419         cmdline_fixed_string_t name;
8420         cmdline_fixed_string_t on_off;
8421 };
8422
8423 static void
8424 cmd_set_record_core_cycles_parsed(void *parsed_result,
8425                         __rte_unused struct cmdline *cl,
8426                         __rte_unused void *data)
8427 {
8428         struct cmd_set_record_core_cycles_result *res;
8429         uint16_t on_off = 0;
8430
8431         res = parsed_result;
8432         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8433         set_record_core_cycles(on_off);
8434 }
8435
8436 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8437         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8438                                  keyword, "set");
8439 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8440         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8441                                  name, "record-core-cycles");
8442 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8443         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8444                                  on_off, "on#off");
8445
8446 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8447         .f = cmd_set_record_core_cycles_parsed,
8448         .data = NULL,
8449         .help_str = "set record-core-cycles on|off",
8450         .tokens = {
8451                 (void *)&cmd_set_record_core_cycles_keyword,
8452                 (void *)&cmd_set_record_core_cycles_name,
8453                 (void *)&cmd_set_record_core_cycles_on_off,
8454                 NULL,
8455         },
8456 };
8457
8458 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8459 struct cmd_set_record_burst_stats_result {
8460         cmdline_fixed_string_t keyword;
8461         cmdline_fixed_string_t name;
8462         cmdline_fixed_string_t on_off;
8463 };
8464
8465 static void
8466 cmd_set_record_burst_stats_parsed(void *parsed_result,
8467                         __rte_unused struct cmdline *cl,
8468                         __rte_unused void *data)
8469 {
8470         struct cmd_set_record_burst_stats_result *res;
8471         uint16_t on_off = 0;
8472
8473         res = parsed_result;
8474         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8475         set_record_burst_stats(on_off);
8476 }
8477
8478 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8480                                  keyword, "set");
8481 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8483                                  name, "record-burst-stats");
8484 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8485         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8486                                  on_off, "on#off");
8487
8488 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8489         .f = cmd_set_record_burst_stats_parsed,
8490         .data = NULL,
8491         .help_str = "set record-burst-stats on|off",
8492         .tokens = {
8493                 (void *)&cmd_set_record_burst_stats_keyword,
8494                 (void *)&cmd_set_record_burst_stats_name,
8495                 (void *)&cmd_set_record_burst_stats_on_off,
8496                 NULL,
8497         },
8498 };
8499
8500 /* *** CONFIGURE UNICAST HASH TABLE *** */
8501 struct cmd_set_uc_hash_table {
8502         cmdline_fixed_string_t set;
8503         cmdline_fixed_string_t port;
8504         portid_t port_id;
8505         cmdline_fixed_string_t what;
8506         struct rte_ether_addr address;
8507         cmdline_fixed_string_t mode;
8508 };
8509
8510 static void
8511 cmd_set_uc_hash_parsed(void *parsed_result,
8512                        __rte_unused struct cmdline *cl,
8513                        __rte_unused void *data)
8514 {
8515         int ret=0;
8516         struct cmd_set_uc_hash_table *res = parsed_result;
8517
8518         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8519
8520         if (strcmp(res->what, "uta") == 0)
8521                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8522                                                 &res->address,(uint8_t)is_on);
8523         if (ret < 0)
8524                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8525
8526 }
8527
8528 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8529         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8530                                  set, "set");
8531 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8532         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8533                                  port, "port");
8534 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8535         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8536                               port_id, RTE_UINT16);
8537 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8538         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8539                                  what, "uta");
8540 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8541         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8542                                 address);
8543 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8544         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8545                                  mode, "on#off");
8546
8547 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8548         .f = cmd_set_uc_hash_parsed,
8549         .data = NULL,
8550         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8551         .tokens = {
8552                 (void *)&cmd_set_uc_hash_set,
8553                 (void *)&cmd_set_uc_hash_port,
8554                 (void *)&cmd_set_uc_hash_portid,
8555                 (void *)&cmd_set_uc_hash_what,
8556                 (void *)&cmd_set_uc_hash_mac,
8557                 (void *)&cmd_set_uc_hash_mode,
8558                 NULL,
8559         },
8560 };
8561
8562 struct cmd_set_uc_all_hash_table {
8563         cmdline_fixed_string_t set;
8564         cmdline_fixed_string_t port;
8565         portid_t port_id;
8566         cmdline_fixed_string_t what;
8567         cmdline_fixed_string_t value;
8568         cmdline_fixed_string_t mode;
8569 };
8570
8571 static void
8572 cmd_set_uc_all_hash_parsed(void *parsed_result,
8573                        __rte_unused struct cmdline *cl,
8574                        __rte_unused void *data)
8575 {
8576         int ret=0;
8577         struct cmd_set_uc_all_hash_table *res = parsed_result;
8578
8579         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8580
8581         if ((strcmp(res->what, "uta") == 0) &&
8582                 (strcmp(res->value, "all") == 0))
8583                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8584         if (ret < 0)
8585                 printf("bad unicast hash table parameter,"
8586                         "return code = %d \n", ret);
8587 }
8588
8589 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8590         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8591                                  set, "set");
8592 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8593         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8594                                  port, "port");
8595 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8596         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8597                               port_id, RTE_UINT16);
8598 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8599         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8600                                  what, "uta");
8601 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8602         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8603                                 value,"all");
8604 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8605         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8606                                  mode, "on#off");
8607
8608 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8609         .f = cmd_set_uc_all_hash_parsed,
8610         .data = NULL,
8611         .help_str = "set port <port_id> uta all on|off",
8612         .tokens = {
8613                 (void *)&cmd_set_uc_all_hash_set,
8614                 (void *)&cmd_set_uc_all_hash_port,
8615                 (void *)&cmd_set_uc_all_hash_portid,
8616                 (void *)&cmd_set_uc_all_hash_what,
8617                 (void *)&cmd_set_uc_all_hash_value,
8618                 (void *)&cmd_set_uc_all_hash_mode,
8619                 NULL,
8620         },
8621 };
8622
8623 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8624 struct cmd_set_vf_traffic {
8625         cmdline_fixed_string_t set;
8626         cmdline_fixed_string_t port;
8627         portid_t port_id;
8628         cmdline_fixed_string_t vf;
8629         uint8_t vf_id;
8630         cmdline_fixed_string_t what;
8631         cmdline_fixed_string_t mode;
8632 };
8633
8634 static void
8635 cmd_set_vf_traffic_parsed(void *parsed_result,
8636                        __rte_unused struct cmdline *cl,
8637                        __rte_unused void *data)
8638 {
8639         struct cmd_set_vf_traffic *res = parsed_result;
8640         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8641         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8642
8643         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8644 }
8645
8646 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8647         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8648                                  set, "set");
8649 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8650         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8651                                  port, "port");
8652 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8653         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8654                               port_id, RTE_UINT16);
8655 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8656         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8657                                  vf, "vf");
8658 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8659         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8660                               vf_id, RTE_UINT8);
8661 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8662         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8663                                  what, "tx#rx");
8664 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8665         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8666                                  mode, "on#off");
8667
8668 cmdline_parse_inst_t cmd_set_vf_traffic = {
8669         .f = cmd_set_vf_traffic_parsed,
8670         .data = NULL,
8671         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8672         .tokens = {
8673                 (void *)&cmd_setvf_traffic_set,
8674                 (void *)&cmd_setvf_traffic_port,
8675                 (void *)&cmd_setvf_traffic_portid,
8676                 (void *)&cmd_setvf_traffic_vf,
8677                 (void *)&cmd_setvf_traffic_vfid,
8678                 (void *)&cmd_setvf_traffic_what,
8679                 (void *)&cmd_setvf_traffic_mode,
8680                 NULL,
8681         },
8682 };
8683
8684 /* *** CONFIGURE VF RECEIVE MODE *** */
8685 struct cmd_set_vf_rxmode {
8686         cmdline_fixed_string_t set;
8687         cmdline_fixed_string_t port;
8688         portid_t port_id;
8689         cmdline_fixed_string_t vf;
8690         uint8_t vf_id;
8691         cmdline_fixed_string_t what;
8692         cmdline_fixed_string_t mode;
8693         cmdline_fixed_string_t on;
8694 };
8695
8696 static void
8697 cmd_set_vf_rxmode_parsed(void *parsed_result,
8698                        __rte_unused struct cmdline *cl,
8699                        __rte_unused void *data)
8700 {
8701         int ret = -ENOTSUP;
8702         uint16_t vf_rxmode = 0;
8703         struct cmd_set_vf_rxmode *res = parsed_result;
8704
8705         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8706         if (!strcmp(res->what,"rxmode")) {
8707                 if (!strcmp(res->mode, "AUPE"))
8708                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8709                 else if (!strcmp(res->mode, "ROPE"))
8710                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8711                 else if (!strcmp(res->mode, "BAM"))
8712                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8713                 else if (!strncmp(res->mode, "MPE",3))
8714                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8715         }
8716
8717         RTE_SET_USED(is_on);
8718
8719 #ifdef RTE_NET_IXGBE
8720         if (ret == -ENOTSUP)
8721                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8722                                                   vf_rxmode, (uint8_t)is_on);
8723 #endif
8724 #ifdef RTE_NET_BNXT
8725         if (ret == -ENOTSUP)
8726                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8727                                                  vf_rxmode, (uint8_t)is_on);
8728 #endif
8729         if (ret < 0)
8730                 printf("bad VF receive mode parameter, return code = %d \n",
8731                 ret);
8732 }
8733
8734 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8735         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8736                                  set, "set");
8737 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8738         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8739                                  port, "port");
8740 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8741         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8742                               port_id, RTE_UINT16);
8743 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8744         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8745                                  vf, "vf");
8746 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8747         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8748                               vf_id, RTE_UINT8);
8749 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8750         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8751                                  what, "rxmode");
8752 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8753         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8754                                  mode, "AUPE#ROPE#BAM#MPE");
8755 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8756         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8757                                  on, "on#off");
8758
8759 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8760         .f = cmd_set_vf_rxmode_parsed,
8761         .data = NULL,
8762         .help_str = "set port <port_id> vf <vf_id> rxmode "
8763                 "AUPE|ROPE|BAM|MPE on|off",
8764         .tokens = {
8765                 (void *)&cmd_set_vf_rxmode_set,
8766                 (void *)&cmd_set_vf_rxmode_port,
8767                 (void *)&cmd_set_vf_rxmode_portid,
8768                 (void *)&cmd_set_vf_rxmode_vf,
8769                 (void *)&cmd_set_vf_rxmode_vfid,
8770                 (void *)&cmd_set_vf_rxmode_what,
8771                 (void *)&cmd_set_vf_rxmode_mode,
8772                 (void *)&cmd_set_vf_rxmode_on,
8773                 NULL,
8774         },
8775 };
8776
8777 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8778 struct cmd_vf_mac_addr_result {
8779         cmdline_fixed_string_t mac_addr_cmd;
8780         cmdline_fixed_string_t what;
8781         cmdline_fixed_string_t port;
8782         uint16_t port_num;
8783         cmdline_fixed_string_t vf;
8784         uint8_t vf_num;
8785         struct rte_ether_addr address;
8786 };
8787
8788 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8789                 __rte_unused struct cmdline *cl,
8790                 __rte_unused void *data)
8791 {
8792         struct cmd_vf_mac_addr_result *res = parsed_result;
8793         int ret = -ENOTSUP;
8794
8795         if (strcmp(res->what, "add") != 0)
8796                 return;
8797
8798 #ifdef RTE_NET_I40E
8799         if (ret == -ENOTSUP)
8800                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8801                                                    &res->address);
8802 #endif
8803 #ifdef RTE_NET_BNXT
8804         if (ret == -ENOTSUP)
8805                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8806                                                 res->vf_num);
8807 #endif
8808
8809         if(ret < 0)
8810                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8811
8812 }
8813
8814 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8815         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8816                                 mac_addr_cmd,"mac_addr");
8817 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8818         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8819                                 what,"add");
8820 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8821         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8822                                 port,"port");
8823 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8824         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8825                                 port_num, RTE_UINT16);
8826 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8827         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8828                                 vf,"vf");
8829 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8830         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8831                                 vf_num, RTE_UINT8);
8832 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8833         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8834                                 address);
8835
8836 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8837         .f = cmd_vf_mac_addr_parsed,
8838         .data = (void *)0,
8839         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8840                 "Add MAC address filtering for a VF on port_id",
8841         .tokens = {
8842                 (void *)&cmd_vf_mac_addr_cmd,
8843                 (void *)&cmd_vf_mac_addr_what,
8844                 (void *)&cmd_vf_mac_addr_port,
8845                 (void *)&cmd_vf_mac_addr_portnum,
8846                 (void *)&cmd_vf_mac_addr_vf,
8847                 (void *)&cmd_vf_mac_addr_vfnum,
8848                 (void *)&cmd_vf_mac_addr_addr,
8849                 NULL,
8850         },
8851 };
8852
8853 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8854 struct cmd_vf_rx_vlan_filter {
8855         cmdline_fixed_string_t rx_vlan;
8856         cmdline_fixed_string_t what;
8857         uint16_t vlan_id;
8858         cmdline_fixed_string_t port;
8859         portid_t port_id;
8860         cmdline_fixed_string_t vf;
8861         uint64_t vf_mask;
8862 };
8863
8864 static void
8865 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8866                           __rte_unused struct cmdline *cl,
8867                           __rte_unused void *data)
8868 {
8869         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8870         int ret = -ENOTSUP;
8871
8872         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8873
8874 #ifdef RTE_NET_IXGBE
8875         if (ret == -ENOTSUP)
8876                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8877                                 res->vlan_id, res->vf_mask, is_add);
8878 #endif
8879 #ifdef RTE_NET_I40E
8880         if (ret == -ENOTSUP)
8881                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8882                                 res->vlan_id, res->vf_mask, is_add);
8883 #endif
8884 #ifdef RTE_NET_BNXT
8885         if (ret == -ENOTSUP)
8886                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8887                                 res->vlan_id, res->vf_mask, is_add);
8888 #endif
8889
8890         switch (ret) {
8891         case 0:
8892                 break;
8893         case -EINVAL:
8894                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8895                                 res->vlan_id, res->vf_mask);
8896                 break;
8897         case -ENODEV:
8898                 printf("invalid port_id %d\n", res->port_id);
8899                 break;
8900         case -ENOTSUP:
8901                 printf("function not implemented or supported\n");
8902                 break;
8903         default:
8904                 printf("programming error: (%s)\n", strerror(-ret));
8905         }
8906 }
8907
8908 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8909         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8910                                  rx_vlan, "rx_vlan");
8911 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8912         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8913                                  what, "add#rm");
8914 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8915         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8916                               vlan_id, RTE_UINT16);
8917 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8918         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8919                                  port, "port");
8920 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8921         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8922                               port_id, RTE_UINT16);
8923 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8924         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8925                                  vf, "vf");
8926 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8927         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8928                               vf_mask, RTE_UINT64);
8929
8930 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8931         .f = cmd_vf_rx_vlan_filter_parsed,
8932         .data = NULL,
8933         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8934                 "(vf_mask = hexadecimal VF mask)",
8935         .tokens = {
8936                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8937                 (void *)&cmd_vf_rx_vlan_filter_what,
8938                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8939                 (void *)&cmd_vf_rx_vlan_filter_port,
8940                 (void *)&cmd_vf_rx_vlan_filter_portid,
8941                 (void *)&cmd_vf_rx_vlan_filter_vf,
8942                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8943                 NULL,
8944         },
8945 };
8946
8947 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8948 struct cmd_queue_rate_limit_result {
8949         cmdline_fixed_string_t set;
8950         cmdline_fixed_string_t port;
8951         uint16_t port_num;
8952         cmdline_fixed_string_t queue;
8953         uint8_t queue_num;
8954         cmdline_fixed_string_t rate;
8955         uint16_t rate_num;
8956 };
8957
8958 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8959                 __rte_unused struct cmdline *cl,
8960                 __rte_unused void *data)
8961 {
8962         struct cmd_queue_rate_limit_result *res = parsed_result;
8963         int ret = 0;
8964
8965         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8966                 && (strcmp(res->queue, "queue") == 0)
8967                 && (strcmp(res->rate, "rate") == 0))
8968                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8969                                         res->rate_num);
8970         if (ret < 0)
8971                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8972
8973 }
8974
8975 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8976         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8977                                 set, "set");
8978 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8979         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8980                                 port, "port");
8981 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8982         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8983                                 port_num, RTE_UINT16);
8984 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8985         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8986                                 queue, "queue");
8987 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8988         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8989                                 queue_num, RTE_UINT8);
8990 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8991         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8992                                 rate, "rate");
8993 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8994         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8995                                 rate_num, RTE_UINT16);
8996
8997 cmdline_parse_inst_t cmd_queue_rate_limit = {
8998         .f = cmd_queue_rate_limit_parsed,
8999         .data = (void *)0,
9000         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9001                 "Set rate limit for a queue on port_id",
9002         .tokens = {
9003                 (void *)&cmd_queue_rate_limit_set,
9004                 (void *)&cmd_queue_rate_limit_port,
9005                 (void *)&cmd_queue_rate_limit_portnum,
9006                 (void *)&cmd_queue_rate_limit_queue,
9007                 (void *)&cmd_queue_rate_limit_queuenum,
9008                 (void *)&cmd_queue_rate_limit_rate,
9009                 (void *)&cmd_queue_rate_limit_ratenum,
9010                 NULL,
9011         },
9012 };
9013
9014 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9015 struct cmd_vf_rate_limit_result {
9016         cmdline_fixed_string_t set;
9017         cmdline_fixed_string_t port;
9018         uint16_t port_num;
9019         cmdline_fixed_string_t vf;
9020         uint8_t vf_num;
9021         cmdline_fixed_string_t rate;
9022         uint16_t rate_num;
9023         cmdline_fixed_string_t q_msk;
9024         uint64_t q_msk_val;
9025 };
9026
9027 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9028                 __rte_unused struct cmdline *cl,
9029                 __rte_unused void *data)
9030 {
9031         struct cmd_vf_rate_limit_result *res = parsed_result;
9032         int ret = 0;
9033
9034         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9035                 && (strcmp(res->vf, "vf") == 0)
9036                 && (strcmp(res->rate, "rate") == 0)
9037                 && (strcmp(res->q_msk, "queue_mask") == 0))
9038                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9039                                         res->rate_num, res->q_msk_val);
9040         if (ret < 0)
9041                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9042
9043 }
9044
9045 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9046         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9047                                 set, "set");
9048 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9049         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9050                                 port, "port");
9051 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9052         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9053                                 port_num, RTE_UINT16);
9054 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9055         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9056                                 vf, "vf");
9057 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9058         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9059                                 vf_num, RTE_UINT8);
9060 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9061         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9062                                 rate, "rate");
9063 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9064         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9065                                 rate_num, RTE_UINT16);
9066 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9067         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9068                                 q_msk, "queue_mask");
9069 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9070         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9071                                 q_msk_val, RTE_UINT64);
9072
9073 cmdline_parse_inst_t cmd_vf_rate_limit = {
9074         .f = cmd_vf_rate_limit_parsed,
9075         .data = (void *)0,
9076         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9077                 "queue_mask <queue_mask_value>: "
9078                 "Set rate limit for queues of VF on port_id",
9079         .tokens = {
9080                 (void *)&cmd_vf_rate_limit_set,
9081                 (void *)&cmd_vf_rate_limit_port,
9082                 (void *)&cmd_vf_rate_limit_portnum,
9083                 (void *)&cmd_vf_rate_limit_vf,
9084                 (void *)&cmd_vf_rate_limit_vfnum,
9085                 (void *)&cmd_vf_rate_limit_rate,
9086                 (void *)&cmd_vf_rate_limit_ratenum,
9087                 (void *)&cmd_vf_rate_limit_q_msk,
9088                 (void *)&cmd_vf_rate_limit_q_msk_val,
9089                 NULL,
9090         },
9091 };
9092
9093 /* *** CONFIGURE TUNNEL UDP PORT *** */
9094 struct cmd_tunnel_udp_config {
9095         cmdline_fixed_string_t cmd;
9096         cmdline_fixed_string_t what;
9097         uint16_t udp_port;
9098         portid_t port_id;
9099 };
9100
9101 static void
9102 cmd_tunnel_udp_config_parsed(void *parsed_result,
9103                           __rte_unused struct cmdline *cl,
9104                           __rte_unused void *data)
9105 {
9106         struct cmd_tunnel_udp_config *res = parsed_result;
9107         struct rte_eth_udp_tunnel tunnel_udp;
9108         int ret;
9109
9110         tunnel_udp.udp_port = res->udp_port;
9111
9112         if (!strcmp(res->cmd, "rx_vxlan_port"))
9113                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9114
9115         if (!strcmp(res->what, "add"))
9116                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9117                                                       &tunnel_udp);
9118         else
9119                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9120                                                          &tunnel_udp);
9121
9122         if (ret < 0)
9123                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9124 }
9125
9126 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9128                                 cmd, "rx_vxlan_port");
9129 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9130         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9131                                 what, "add#rm");
9132 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9134                                 udp_port, RTE_UINT16);
9135 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9136         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9137                                 port_id, RTE_UINT16);
9138
9139 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9140         .f = cmd_tunnel_udp_config_parsed,
9141         .data = (void *)0,
9142         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9143                 "Add/Remove a tunneling UDP port filter",
9144         .tokens = {
9145                 (void *)&cmd_tunnel_udp_config_cmd,
9146                 (void *)&cmd_tunnel_udp_config_what,
9147                 (void *)&cmd_tunnel_udp_config_udp_port,
9148                 (void *)&cmd_tunnel_udp_config_port_id,
9149                 NULL,
9150         },
9151 };
9152
9153 struct cmd_config_tunnel_udp_port {
9154         cmdline_fixed_string_t port;
9155         cmdline_fixed_string_t config;
9156         portid_t port_id;
9157         cmdline_fixed_string_t udp_tunnel_port;
9158         cmdline_fixed_string_t action;
9159         cmdline_fixed_string_t tunnel_type;
9160         uint16_t udp_port;
9161 };
9162
9163 static void
9164 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9165                                __rte_unused struct cmdline *cl,
9166                                __rte_unused void *data)
9167 {
9168         struct cmd_config_tunnel_udp_port *res = parsed_result;
9169         struct rte_eth_udp_tunnel tunnel_udp;
9170         int ret = 0;
9171
9172         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9173                 return;
9174
9175         tunnel_udp.udp_port = res->udp_port;
9176
9177         if (!strcmp(res->tunnel_type, "vxlan")) {
9178                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9179         } else if (!strcmp(res->tunnel_type, "geneve")) {
9180                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9181         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9182                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9183         } else {
9184                 printf("Invalid tunnel type\n");
9185                 return;
9186         }
9187
9188         if (!strcmp(res->action, "add"))
9189                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9190                                                       &tunnel_udp);
9191         else
9192                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9193                                                          &tunnel_udp);
9194
9195         if (ret < 0)
9196                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9197 }
9198
9199 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9200         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9201                                  "port");
9202 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9203         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9204                                  "config");
9205 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9206         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9207                               RTE_UINT16);
9208 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9209         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9210                                  udp_tunnel_port,
9211                                  "udp_tunnel_port");
9212 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9213         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9214                                  "add#rm");
9215 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9216         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9217                                  "vxlan#geneve#vxlan-gpe");
9218 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9219         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9220                               RTE_UINT16);
9221
9222 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9223         .f = cmd_cfg_tunnel_udp_port_parsed,
9224         .data = NULL,
9225         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9226         .tokens = {
9227                 (void *)&cmd_config_tunnel_udp_port_port,
9228                 (void *)&cmd_config_tunnel_udp_port_config,
9229                 (void *)&cmd_config_tunnel_udp_port_port_id,
9230                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9231                 (void *)&cmd_config_tunnel_udp_port_action,
9232                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9233                 (void *)&cmd_config_tunnel_udp_port_value,
9234                 NULL,
9235         },
9236 };
9237
9238 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9239 struct cmd_set_mirror_mask_result {
9240         cmdline_fixed_string_t set;
9241         cmdline_fixed_string_t port;
9242         portid_t port_id;
9243         cmdline_fixed_string_t mirror;
9244         uint8_t rule_id;
9245         cmdline_fixed_string_t what;
9246         cmdline_fixed_string_t value;
9247         cmdline_fixed_string_t dstpool;
9248         uint8_t dstpool_id;
9249         cmdline_fixed_string_t on;
9250 };
9251
9252 cmdline_parse_token_string_t cmd_mirror_mask_set =
9253         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9254                                 set, "set");
9255 cmdline_parse_token_string_t cmd_mirror_mask_port =
9256         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9257                                 port, "port");
9258 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9259         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9260                                 port_id, RTE_UINT16);
9261 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9262         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9263                                 mirror, "mirror-rule");
9264 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9265         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9266                                 rule_id, RTE_UINT8);
9267 cmdline_parse_token_string_t cmd_mirror_mask_what =
9268         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9269                                 what, "pool-mirror-up#pool-mirror-down"
9270                                       "#vlan-mirror");
9271 cmdline_parse_token_string_t cmd_mirror_mask_value =
9272         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9273                                 value, NULL);
9274 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9275         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9276                                 dstpool, "dst-pool");
9277 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9278         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9279                                 dstpool_id, RTE_UINT8);
9280 cmdline_parse_token_string_t cmd_mirror_mask_on =
9281         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9282                                 on, "on#off");
9283
9284 static void
9285 cmd_set_mirror_mask_parsed(void *parsed_result,
9286                        __rte_unused struct cmdline *cl,
9287                        __rte_unused void *data)
9288 {
9289         int ret,nb_item,i;
9290         struct cmd_set_mirror_mask_result *res = parsed_result;
9291         struct rte_eth_mirror_conf mr_conf;
9292
9293         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9294
9295         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9296
9297         mr_conf.dst_pool = res->dstpool_id;
9298
9299         if (!strcmp(res->what, "pool-mirror-up")) {
9300                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9301                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9302         } else if (!strcmp(res->what, "pool-mirror-down")) {
9303                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9304                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9305         } else if (!strcmp(res->what, "vlan-mirror")) {
9306                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9307                 nb_item = parse_item_list(res->value, "vlan",
9308                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9309                 if (nb_item <= 0)
9310                         return;
9311
9312                 for (i = 0; i < nb_item; i++) {
9313                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9314                                 printf("Invalid vlan_id: must be < 4096\n");
9315                                 return;
9316                         }
9317
9318                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9319                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9320                 }
9321         }
9322
9323         if (!strcmp(res->on, "on"))
9324                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9325                                                 res->rule_id, 1);
9326         else
9327                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9328                                                 res->rule_id, 0);
9329         if (ret < 0)
9330                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9331 }
9332
9333 cmdline_parse_inst_t cmd_set_mirror_mask = {
9334                 .f = cmd_set_mirror_mask_parsed,
9335                 .data = NULL,
9336                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9337                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9338                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9339                 .tokens = {
9340                         (void *)&cmd_mirror_mask_set,
9341                         (void *)&cmd_mirror_mask_port,
9342                         (void *)&cmd_mirror_mask_portid,
9343                         (void *)&cmd_mirror_mask_mirror,
9344                         (void *)&cmd_mirror_mask_ruleid,
9345                         (void *)&cmd_mirror_mask_what,
9346                         (void *)&cmd_mirror_mask_value,
9347                         (void *)&cmd_mirror_mask_dstpool,
9348                         (void *)&cmd_mirror_mask_poolid,
9349                         (void *)&cmd_mirror_mask_on,
9350                         NULL,
9351                 },
9352 };
9353
9354 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9355 struct cmd_set_mirror_link_result {
9356         cmdline_fixed_string_t set;
9357         cmdline_fixed_string_t port;
9358         portid_t port_id;
9359         cmdline_fixed_string_t mirror;
9360         uint8_t rule_id;
9361         cmdline_fixed_string_t what;
9362         cmdline_fixed_string_t dstpool;
9363         uint8_t dstpool_id;
9364         cmdline_fixed_string_t on;
9365 };
9366
9367 cmdline_parse_token_string_t cmd_mirror_link_set =
9368         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9369                                  set, "set");
9370 cmdline_parse_token_string_t cmd_mirror_link_port =
9371         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9372                                 port, "port");
9373 cmdline_parse_token_num_t cmd_mirror_link_portid =
9374         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9375                                 port_id, RTE_UINT16);
9376 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9377         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9378                                 mirror, "mirror-rule");
9379 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9380         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9381                             rule_id, RTE_UINT8);
9382 cmdline_parse_token_string_t cmd_mirror_link_what =
9383         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9384                                 what, "uplink-mirror#downlink-mirror");
9385 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9386         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9387                                 dstpool, "dst-pool");
9388 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9389         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9390                                 dstpool_id, RTE_UINT8);
9391 cmdline_parse_token_string_t cmd_mirror_link_on =
9392         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9393                                 on, "on#off");
9394
9395 static void
9396 cmd_set_mirror_link_parsed(void *parsed_result,
9397                        __rte_unused struct cmdline *cl,
9398                        __rte_unused void *data)
9399 {
9400         int ret;
9401         struct cmd_set_mirror_link_result *res = parsed_result;
9402         struct rte_eth_mirror_conf mr_conf;
9403
9404         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9405         if (!strcmp(res->what, "uplink-mirror"))
9406                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9407         else
9408                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9409
9410         mr_conf.dst_pool = res->dstpool_id;
9411
9412         if (!strcmp(res->on, "on"))
9413                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9414                                                 res->rule_id, 1);
9415         else
9416                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9417                                                 res->rule_id, 0);
9418
9419         /* check the return value and print it if is < 0 */
9420         if (ret < 0)
9421                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9422
9423 }
9424
9425 cmdline_parse_inst_t cmd_set_mirror_link = {
9426                 .f = cmd_set_mirror_link_parsed,
9427                 .data = NULL,
9428                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9429                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9430                 .tokens = {
9431                         (void *)&cmd_mirror_link_set,
9432                         (void *)&cmd_mirror_link_port,
9433                         (void *)&cmd_mirror_link_portid,
9434                         (void *)&cmd_mirror_link_mirror,
9435                         (void *)&cmd_mirror_link_ruleid,
9436                         (void *)&cmd_mirror_link_what,
9437                         (void *)&cmd_mirror_link_dstpool,
9438                         (void *)&cmd_mirror_link_poolid,
9439                         (void *)&cmd_mirror_link_on,
9440                         NULL,
9441                 },
9442 };
9443
9444 /* *** RESET VM MIRROR RULE *** */
9445 struct cmd_rm_mirror_rule_result {
9446         cmdline_fixed_string_t reset;
9447         cmdline_fixed_string_t port;
9448         portid_t port_id;
9449         cmdline_fixed_string_t mirror;
9450         uint8_t rule_id;
9451 };
9452
9453 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9454         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9455                                  reset, "reset");
9456 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9457         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9458                                 port, "port");
9459 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9460         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9461                                 port_id, RTE_UINT16);
9462 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9463         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9464                                 mirror, "mirror-rule");
9465 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9466         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9467                                 rule_id, RTE_UINT8);
9468
9469 static void
9470 cmd_reset_mirror_rule_parsed(void *parsed_result,
9471                        __rte_unused struct cmdline *cl,
9472                        __rte_unused void *data)
9473 {
9474         int ret;
9475         struct cmd_set_mirror_link_result *res = parsed_result;
9476         /* check rule_id */
9477         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9478         if(ret < 0)
9479                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9480 }
9481
9482 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9483                 .f = cmd_reset_mirror_rule_parsed,
9484                 .data = NULL,
9485                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9486                 .tokens = {
9487                         (void *)&cmd_rm_mirror_rule_reset,
9488                         (void *)&cmd_rm_mirror_rule_port,
9489                         (void *)&cmd_rm_mirror_rule_portid,
9490                         (void *)&cmd_rm_mirror_rule_mirror,
9491                         (void *)&cmd_rm_mirror_rule_ruleid,
9492                         NULL,
9493                 },
9494 };
9495
9496 /* ******************************************************************************** */
9497
9498 struct cmd_dump_result {
9499         cmdline_fixed_string_t dump;
9500 };
9501
9502 static void
9503 dump_struct_sizes(void)
9504 {
9505 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9506         DUMP_SIZE(struct rte_mbuf);
9507         DUMP_SIZE(struct rte_mempool);
9508         DUMP_SIZE(struct rte_ring);
9509 #undef DUMP_SIZE
9510 }
9511
9512
9513 /* Dump the socket memory statistics on console */
9514 static void
9515 dump_socket_mem(FILE *f)
9516 {
9517         struct rte_malloc_socket_stats socket_stats;
9518         unsigned int i;
9519         size_t total = 0;
9520         size_t alloc = 0;
9521         size_t free = 0;
9522         unsigned int n_alloc = 0;
9523         unsigned int n_free = 0;
9524         static size_t last_allocs;
9525         static size_t last_total;
9526
9527
9528         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9529                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9530                     !socket_stats.heap_totalsz_bytes)
9531                         continue;
9532                 total += socket_stats.heap_totalsz_bytes;
9533                 alloc += socket_stats.heap_allocsz_bytes;
9534                 free += socket_stats.heap_freesz_bytes;
9535                 n_alloc += socket_stats.alloc_count;
9536                 n_free += socket_stats.free_count;
9537                 fprintf(f,
9538                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9539                         i,
9540                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9541                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9542                         (double)socket_stats.heap_allocsz_bytes * 100 /
9543                         (double)socket_stats.heap_totalsz_bytes,
9544                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9545                         socket_stats.alloc_count,
9546                         socket_stats.free_count);
9547         }
9548         fprintf(f,
9549                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9550                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9551                 (double)alloc * 100 / (double)total,
9552                 (double)free / (1024 * 1024),
9553                 n_alloc, n_free);
9554         if (last_allocs)
9555                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9556                         ((double)total - (double)last_total) / (1024 * 1024),
9557                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9558         last_allocs = alloc;
9559         last_total = total;
9560 }
9561
9562 static void cmd_dump_parsed(void *parsed_result,
9563                             __rte_unused struct cmdline *cl,
9564                             __rte_unused void *data)
9565 {
9566         struct cmd_dump_result *res = parsed_result;
9567
9568         if (!strcmp(res->dump, "dump_physmem"))
9569                 rte_dump_physmem_layout(stdout);
9570         else if (!strcmp(res->dump, "dump_socket_mem"))
9571                 dump_socket_mem(stdout);
9572         else if (!strcmp(res->dump, "dump_memzone"))
9573                 rte_memzone_dump(stdout);
9574         else if (!strcmp(res->dump, "dump_struct_sizes"))
9575                 dump_struct_sizes();
9576         else if (!strcmp(res->dump, "dump_ring"))
9577                 rte_ring_list_dump(stdout);
9578         else if (!strcmp(res->dump, "dump_mempool"))
9579                 rte_mempool_list_dump(stdout);
9580         else if (!strcmp(res->dump, "dump_devargs"))
9581                 rte_devargs_dump(stdout);
9582         else if (!strcmp(res->dump, "dump_log_types"))
9583                 rte_log_dump(stdout);
9584 }
9585
9586 cmdline_parse_token_string_t cmd_dump_dump =
9587         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9588                 "dump_physmem#"
9589                 "dump_memzone#"
9590                 "dump_socket_mem#"
9591                 "dump_struct_sizes#"
9592                 "dump_ring#"
9593                 "dump_mempool#"
9594                 "dump_devargs#"
9595                 "dump_log_types");
9596
9597 cmdline_parse_inst_t cmd_dump = {
9598         .f = cmd_dump_parsed,  /* function to call */
9599         .data = NULL,      /* 2nd arg of func */
9600         .help_str = "Dump status",
9601         .tokens = {        /* token list, NULL terminated */
9602                 (void *)&cmd_dump_dump,
9603                 NULL,
9604         },
9605 };
9606
9607 /* ******************************************************************************** */
9608
9609 struct cmd_dump_one_result {
9610         cmdline_fixed_string_t dump;
9611         cmdline_fixed_string_t name;
9612 };
9613
9614 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9615                                 __rte_unused void *data)
9616 {
9617         struct cmd_dump_one_result *res = parsed_result;
9618
9619         if (!strcmp(res->dump, "dump_ring")) {
9620                 struct rte_ring *r;
9621                 r = rte_ring_lookup(res->name);
9622                 if (r == NULL) {
9623                         cmdline_printf(cl, "Cannot find ring\n");
9624                         return;
9625                 }
9626                 rte_ring_dump(stdout, r);
9627         } else if (!strcmp(res->dump, "dump_mempool")) {
9628                 struct rte_mempool *mp;
9629                 mp = rte_mempool_lookup(res->name);
9630                 if (mp == NULL) {
9631                         cmdline_printf(cl, "Cannot find mempool\n");
9632                         return;
9633                 }
9634                 rte_mempool_dump(stdout, mp);
9635         }
9636 }
9637
9638 cmdline_parse_token_string_t cmd_dump_one_dump =
9639         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9640                                  "dump_ring#dump_mempool");
9641
9642 cmdline_parse_token_string_t cmd_dump_one_name =
9643         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9644
9645 cmdline_parse_inst_t cmd_dump_one = {
9646         .f = cmd_dump_one_parsed,  /* function to call */
9647         .data = NULL,      /* 2nd arg of func */
9648         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9649         .tokens = {        /* token list, NULL terminated */
9650                 (void *)&cmd_dump_one_dump,
9651                 (void *)&cmd_dump_one_name,
9652                 NULL,
9653         },
9654 };
9655
9656 /* *** queue region set *** */
9657 struct cmd_queue_region_result {
9658         cmdline_fixed_string_t set;
9659         cmdline_fixed_string_t port;
9660         portid_t port_id;
9661         cmdline_fixed_string_t cmd;
9662         cmdline_fixed_string_t region;
9663         uint8_t  region_id;
9664         cmdline_fixed_string_t queue_start_index;
9665         uint8_t  queue_id;
9666         cmdline_fixed_string_t queue_num;
9667         uint8_t  queue_num_value;
9668 };
9669
9670 static void
9671 cmd_queue_region_parsed(void *parsed_result,
9672                         __rte_unused struct cmdline *cl,
9673                         __rte_unused void *data)
9674 {
9675         struct cmd_queue_region_result *res = parsed_result;
9676         int ret = -ENOTSUP;
9677 #ifdef RTE_NET_I40E
9678         struct rte_pmd_i40e_queue_region_conf region_conf;
9679         enum rte_pmd_i40e_queue_region_op op_type;
9680 #endif
9681
9682         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9683                 return;
9684
9685 #ifdef RTE_NET_I40E
9686         memset(&region_conf, 0, sizeof(region_conf));
9687         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9688         region_conf.region_id = res->region_id;
9689         region_conf.queue_num = res->queue_num_value;
9690         region_conf.queue_start_index = res->queue_id;
9691
9692         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9693                                 op_type, &region_conf);
9694 #endif
9695
9696         switch (ret) {
9697         case 0:
9698                 break;
9699         case -ENOTSUP:
9700                 printf("function not implemented or supported\n");
9701                 break;
9702         default:
9703                 printf("queue region config error: (%s)\n", strerror(-ret));
9704         }
9705 }
9706
9707 cmdline_parse_token_string_t cmd_queue_region_set =
9708 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9709                 set, "set");
9710 cmdline_parse_token_string_t cmd_queue_region_port =
9711         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9712 cmdline_parse_token_num_t cmd_queue_region_port_id =
9713         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9714                                 port_id, RTE_UINT16);
9715 cmdline_parse_token_string_t cmd_queue_region_cmd =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                                  cmd, "queue-region");
9718 cmdline_parse_token_string_t cmd_queue_region_id =
9719         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9720                                 region, "region_id");
9721 cmdline_parse_token_num_t cmd_queue_region_index =
9722         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9723                                 region_id, RTE_UINT8);
9724 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9725         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9726                                 queue_start_index, "queue_start_index");
9727 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9728         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_id, RTE_UINT8);
9730 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9731         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_num, "queue_num");
9733 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9734         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9735                                 queue_num_value, RTE_UINT8);
9736
9737 cmdline_parse_inst_t cmd_queue_region = {
9738         .f = cmd_queue_region_parsed,
9739         .data = NULL,
9740         .help_str = "set port <port_id> queue-region region_id <value> "
9741                 "queue_start_index <value> queue_num <value>: Set a queue region",
9742         .tokens = {
9743                 (void *)&cmd_queue_region_set,
9744                 (void *)&cmd_queue_region_port,
9745                 (void *)&cmd_queue_region_port_id,
9746                 (void *)&cmd_queue_region_cmd,
9747                 (void *)&cmd_queue_region_id,
9748                 (void *)&cmd_queue_region_index,
9749                 (void *)&cmd_queue_region_queue_start_index,
9750                 (void *)&cmd_queue_region_queue_id,
9751                 (void *)&cmd_queue_region_queue_num,
9752                 (void *)&cmd_queue_region_queue_num_value,
9753                 NULL,
9754         },
9755 };
9756
9757 /* *** queue region and flowtype set *** */
9758 struct cmd_region_flowtype_result {
9759         cmdline_fixed_string_t set;
9760         cmdline_fixed_string_t port;
9761         portid_t port_id;
9762         cmdline_fixed_string_t cmd;
9763         cmdline_fixed_string_t region;
9764         uint8_t  region_id;
9765         cmdline_fixed_string_t flowtype;
9766         uint8_t  flowtype_id;
9767 };
9768
9769 static void
9770 cmd_region_flowtype_parsed(void *parsed_result,
9771                         __rte_unused struct cmdline *cl,
9772                         __rte_unused void *data)
9773 {
9774         struct cmd_region_flowtype_result *res = parsed_result;
9775         int ret = -ENOTSUP;
9776 #ifdef RTE_NET_I40E
9777         struct rte_pmd_i40e_queue_region_conf region_conf;
9778         enum rte_pmd_i40e_queue_region_op op_type;
9779 #endif
9780
9781         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9782                 return;
9783
9784 #ifdef RTE_NET_I40E
9785         memset(&region_conf, 0, sizeof(region_conf));
9786
9787         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9788         region_conf.region_id = res->region_id;
9789         region_conf.hw_flowtype = res->flowtype_id;
9790
9791         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9792                         op_type, &region_conf);
9793 #endif
9794
9795         switch (ret) {
9796         case 0:
9797                 break;
9798         case -ENOTSUP:
9799                 printf("function not implemented or supported\n");
9800                 break;
9801         default:
9802                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9803         }
9804 }
9805
9806 cmdline_parse_token_string_t cmd_region_flowtype_set =
9807 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9808                                 set, "set");
9809 cmdline_parse_token_string_t cmd_region_flowtype_port =
9810         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 port, "port");
9812 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9813         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 port_id, RTE_UINT16);
9815 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 cmd, "queue-region");
9818 cmdline_parse_token_string_t cmd_region_flowtype_index =
9819         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 region, "region_id");
9821 cmdline_parse_token_num_t cmd_region_flowtype_id =
9822         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 region_id, RTE_UINT8);
9824 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9825         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 flowtype, "flowtype");
9827 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9828         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9829                                 flowtype_id, RTE_UINT8);
9830 cmdline_parse_inst_t cmd_region_flowtype = {
9831         .f = cmd_region_flowtype_parsed,
9832         .data = NULL,
9833         .help_str = "set port <port_id> queue-region region_id <value> "
9834                 "flowtype <value>: Set a flowtype region index",
9835         .tokens = {
9836                 (void *)&cmd_region_flowtype_set,
9837                 (void *)&cmd_region_flowtype_port,
9838                 (void *)&cmd_region_flowtype_port_index,
9839                 (void *)&cmd_region_flowtype_cmd,
9840                 (void *)&cmd_region_flowtype_index,
9841                 (void *)&cmd_region_flowtype_id,
9842                 (void *)&cmd_region_flowtype_flow_index,
9843                 (void *)&cmd_region_flowtype_flow_id,
9844                 NULL,
9845         },
9846 };
9847
9848 /* *** User Priority (UP) to queue region (region_id) set *** */
9849 struct cmd_user_priority_region_result {
9850         cmdline_fixed_string_t set;
9851         cmdline_fixed_string_t port;
9852         portid_t port_id;
9853         cmdline_fixed_string_t cmd;
9854         cmdline_fixed_string_t user_priority;
9855         uint8_t  user_priority_id;
9856         cmdline_fixed_string_t region;
9857         uint8_t  region_id;
9858 };
9859
9860 static void
9861 cmd_user_priority_region_parsed(void *parsed_result,
9862                         __rte_unused struct cmdline *cl,
9863                         __rte_unused void *data)
9864 {
9865         struct cmd_user_priority_region_result *res = parsed_result;
9866         int ret = -ENOTSUP;
9867 #ifdef RTE_NET_I40E
9868         struct rte_pmd_i40e_queue_region_conf region_conf;
9869         enum rte_pmd_i40e_queue_region_op op_type;
9870 #endif
9871
9872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9873                 return;
9874
9875 #ifdef RTE_NET_I40E
9876         memset(&region_conf, 0, sizeof(region_conf));
9877         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9878         region_conf.user_priority = res->user_priority_id;
9879         region_conf.region_id = res->region_id;
9880
9881         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9882                                 op_type, &region_conf);
9883 #endif
9884
9885         switch (ret) {
9886         case 0:
9887                 break;
9888         case -ENOTSUP:
9889                 printf("function not implemented or supported\n");
9890                 break;
9891         default:
9892                 printf("user_priority region config error: (%s)\n",
9893                                 strerror(-ret));
9894         }
9895 }
9896
9897 cmdline_parse_token_string_t cmd_user_priority_region_set =
9898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9899                                 set, "set");
9900 cmdline_parse_token_string_t cmd_user_priority_region_port =
9901         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 port, "port");
9903 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9904         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 port_id, RTE_UINT16);
9906 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 cmd, "queue-region");
9909 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9910         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 user_priority, "UP");
9912 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9913         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 user_priority_id, RTE_UINT8);
9915 cmdline_parse_token_string_t cmd_user_priority_region_region =
9916         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 region, "region_id");
9918 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9919         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9920                                 region_id, RTE_UINT8);
9921
9922 cmdline_parse_inst_t cmd_user_priority_region = {
9923         .f = cmd_user_priority_region_parsed,
9924         .data = NULL,
9925         .help_str = "set port <port_id> queue-region UP <value> "
9926                 "region_id <value>: Set the mapping of User Priority (UP) "
9927                 "to queue region (region_id) ",
9928         .tokens = {
9929                 (void *)&cmd_user_priority_region_set,
9930                 (void *)&cmd_user_priority_region_port,
9931                 (void *)&cmd_user_priority_region_port_index,
9932                 (void *)&cmd_user_priority_region_cmd,
9933                 (void *)&cmd_user_priority_region_UP,
9934                 (void *)&cmd_user_priority_region_UP_id,
9935                 (void *)&cmd_user_priority_region_region,
9936                 (void *)&cmd_user_priority_region_region_id,
9937                 NULL,
9938         },
9939 };
9940
9941 /* *** flush all queue region related configuration *** */
9942 struct cmd_flush_queue_region_result {
9943         cmdline_fixed_string_t set;
9944         cmdline_fixed_string_t port;
9945         portid_t port_id;
9946         cmdline_fixed_string_t cmd;
9947         cmdline_fixed_string_t flush;
9948         cmdline_fixed_string_t what;
9949 };
9950
9951 static void
9952 cmd_flush_queue_region_parsed(void *parsed_result,
9953                         __rte_unused struct cmdline *cl,
9954                         __rte_unused void *data)
9955 {
9956         struct cmd_flush_queue_region_result *res = parsed_result;
9957         int ret = -ENOTSUP;
9958 #ifdef RTE_NET_I40E
9959         struct rte_pmd_i40e_queue_region_conf region_conf;
9960         enum rte_pmd_i40e_queue_region_op op_type;
9961 #endif
9962
9963         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9964                 return;
9965
9966 #ifdef RTE_NET_I40E
9967         memset(&region_conf, 0, sizeof(region_conf));
9968
9969         if (strcmp(res->what, "on") == 0)
9970                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9971         else
9972                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9973
9974         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9975                                 op_type, &region_conf);
9976 #endif
9977
9978         switch (ret) {
9979         case 0:
9980                 break;
9981         case -ENOTSUP:
9982                 printf("function not implemented or supported\n");
9983                 break;
9984         default:
9985                 printf("queue region config flush error: (%s)\n",
9986                                 strerror(-ret));
9987         }
9988 }
9989
9990 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9992                                 set, "set");
9993 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9994         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 port, "port");
9996 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9997         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 port_id, RTE_UINT16);
9999 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 cmd, "queue-region");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 flush, "flush");
10005 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10006         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10007                                 what, "on#off");
10008
10009 cmdline_parse_inst_t cmd_flush_queue_region = {
10010         .f = cmd_flush_queue_region_parsed,
10011         .data = NULL,
10012         .help_str = "set port <port_id> queue-region flush on|off"
10013                 ": flush all queue region related configuration",
10014         .tokens = {
10015                 (void *)&cmd_flush_queue_region_set,
10016                 (void *)&cmd_flush_queue_region_port,
10017                 (void *)&cmd_flush_queue_region_port_index,
10018                 (void *)&cmd_flush_queue_region_cmd,
10019                 (void *)&cmd_flush_queue_region_flush,
10020                 (void *)&cmd_flush_queue_region_what,
10021                 NULL,
10022         },
10023 };
10024
10025 /* *** get all queue region related configuration info *** */
10026 struct cmd_show_queue_region_info {
10027         cmdline_fixed_string_t show;
10028         cmdline_fixed_string_t port;
10029         portid_t port_id;
10030         cmdline_fixed_string_t cmd;
10031 };
10032
10033 static void
10034 cmd_show_queue_region_info_parsed(void *parsed_result,
10035                         __rte_unused struct cmdline *cl,
10036                         __rte_unused void *data)
10037 {
10038         struct cmd_show_queue_region_info *res = parsed_result;
10039         int ret = -ENOTSUP;
10040 #ifdef RTE_NET_I40E
10041         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10042         enum rte_pmd_i40e_queue_region_op op_type;
10043 #endif
10044
10045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10046                 return;
10047
10048 #ifdef RTE_NET_I40E
10049         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10050
10051         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10052
10053         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10054                                         op_type, &rte_pmd_regions);
10055
10056         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10057 #endif
10058
10059         switch (ret) {
10060         case 0:
10061                 break;
10062         case -ENOTSUP:
10063                 printf("function not implemented or supported\n");
10064                 break;
10065         default:
10066                 printf("queue region config info show error: (%s)\n",
10067                                 strerror(-ret));
10068         }
10069 }
10070
10071 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10072 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10073                                 show, "show");
10074 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10075         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 port, "port");
10077 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10078         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 port_id, RTE_UINT16);
10080 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10081         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10082                                 cmd, "queue-region");
10083
10084 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10085         .f = cmd_show_queue_region_info_parsed,
10086         .data = NULL,
10087         .help_str = "show port <port_id> queue-region"
10088                 ": show all queue region related configuration info",
10089         .tokens = {
10090                 (void *)&cmd_show_queue_region_info_get,
10091                 (void *)&cmd_show_queue_region_info_port,
10092                 (void *)&cmd_show_queue_region_info_port_index,
10093                 (void *)&cmd_show_queue_region_info_cmd,
10094                 NULL,
10095         },
10096 };
10097
10098 /* *** Filters Control *** */
10099
10100 static uint16_t
10101 str2flowtype(char *string)
10102 {
10103         uint8_t i = 0;
10104         static const struct {
10105                 char str[32];
10106                 uint16_t type;
10107         } flowtype_str[] = {
10108                 {"raw", RTE_ETH_FLOW_RAW},
10109                 {"ipv4", RTE_ETH_FLOW_IPV4},
10110                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10111                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10112                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10113                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10114                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10115                 {"ipv6", RTE_ETH_FLOW_IPV6},
10116                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10117                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10118                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10119                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10120                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10121                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10122         };
10123
10124         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10125                 if (!strcmp(flowtype_str[i].str, string))
10126                         return flowtype_str[i].type;
10127         }
10128
10129         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10130                 return (uint16_t)atoi(string);
10131
10132         return RTE_ETH_FLOW_UNKNOWN;
10133 }
10134
10135 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10136 do { \
10137         if ((ip_addr).family == AF_INET) \
10138                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10139         else { \
10140                 printf("invalid parameter.\n"); \
10141                 return; \
10142         } \
10143 } while (0)
10144
10145 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10146 do { \
10147         if ((ip_addr).family == AF_INET6) \
10148                 rte_memcpy(&(ip), \
10149                                  &((ip_addr).addr.ipv6), \
10150                                  sizeof(struct in6_addr)); \
10151         else { \
10152                 printf("invalid parameter.\n"); \
10153                 return; \
10154         } \
10155 } while (0)
10156
10157 #ifdef RTE_NET_I40E
10158
10159 /* *** deal with flow director filter *** */
10160 struct cmd_flow_director_result {
10161         cmdline_fixed_string_t flow_director_filter;
10162         portid_t port_id;
10163         cmdline_fixed_string_t mode;
10164         cmdline_fixed_string_t mode_value;
10165         cmdline_fixed_string_t ops;
10166         cmdline_fixed_string_t flow;
10167         cmdline_fixed_string_t flow_type;
10168         cmdline_fixed_string_t drop;
10169         cmdline_fixed_string_t queue;
10170         uint16_t  queue_id;
10171         cmdline_fixed_string_t fd_id;
10172         uint32_t  fd_id_value;
10173         cmdline_fixed_string_t packet;
10174         char filepath[];
10175 };
10176
10177 static void
10178 cmd_flow_director_filter_parsed(void *parsed_result,
10179                           __rte_unused struct cmdline *cl,
10180                           __rte_unused void *data)
10181 {
10182         struct cmd_flow_director_result *res = parsed_result;
10183         int ret = 0;
10184         struct rte_pmd_i40e_flow_type_mapping
10185                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10186         struct rte_pmd_i40e_pkt_template_conf conf;
10187         uint16_t flow_type = str2flowtype(res->flow_type);
10188         uint16_t i, port = res->port_id;
10189         uint8_t add;
10190
10191         memset(&conf, 0, sizeof(conf));
10192
10193         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10194                 printf("Invalid flow type specified.\n");
10195                 return;
10196         }
10197         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10198                                                  mapping);
10199         if (ret)
10200                 return;
10201         if (mapping[flow_type].pctype == 0ULL) {
10202                 printf("Invalid flow type specified.\n");
10203                 return;
10204         }
10205         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10206                 if (mapping[flow_type].pctype & (1ULL << i)) {
10207                         conf.input.pctype = i;
10208                         break;
10209                 }
10210         }
10211
10212         conf.input.packet = open_file(res->filepath,
10213                                 &conf.input.length);
10214         if (!conf.input.packet)
10215                 return;
10216         if (!strcmp(res->drop, "drop"))
10217                 conf.action.behavior =
10218                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10219         else
10220                 conf.action.behavior =
10221                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10222         conf.action.report_status =
10223                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10224         conf.action.rx_queue = res->queue_id;
10225         conf.soft_id = res->fd_id_value;
10226         add  = strcmp(res->ops, "del") ? 1 : 0;
10227         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10228                                                         &conf,
10229                                                         add);
10230         if (ret < 0)
10231                 printf("flow director config error: (%s)\n",
10232                        strerror(-ret));
10233         close_file(conf.input.packet);
10234 }
10235
10236 cmdline_parse_token_string_t cmd_flow_director_filter =
10237         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10238                                  flow_director_filter, "flow_director_filter");
10239 cmdline_parse_token_num_t cmd_flow_director_port_id =
10240         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10241                               port_id, RTE_UINT16);
10242 cmdline_parse_token_string_t cmd_flow_director_ops =
10243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10244                                  ops, "add#del#update");
10245 cmdline_parse_token_string_t cmd_flow_director_flow =
10246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10247                                  flow, "flow");
10248 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10250                 flow_type, NULL);
10251 cmdline_parse_token_string_t cmd_flow_director_drop =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  drop, "drop#fwd");
10254 cmdline_parse_token_string_t cmd_flow_director_queue =
10255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10256                                  queue, "queue");
10257 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10258         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10259                               queue_id, RTE_UINT16);
10260 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10262                                  fd_id, "fd_id");
10263 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10264         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10265                               fd_id_value, RTE_UINT32);
10266
10267 cmdline_parse_token_string_t cmd_flow_director_mode =
10268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10269                                  mode, "mode");
10270 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10272                                  mode_value, "raw");
10273 cmdline_parse_token_string_t cmd_flow_director_packet =
10274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10275                                  packet, "packet");
10276 cmdline_parse_token_string_t cmd_flow_director_filepath =
10277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10278                                  filepath, NULL);
10279
10280 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10281         .f = cmd_flow_director_filter_parsed,
10282         .data = NULL,
10283         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10284                 "director entry on NIC",
10285         .tokens = {
10286                 (void *)&cmd_flow_director_filter,
10287                 (void *)&cmd_flow_director_port_id,
10288                 (void *)&cmd_flow_director_mode,
10289                 (void *)&cmd_flow_director_mode_raw,
10290                 (void *)&cmd_flow_director_ops,
10291                 (void *)&cmd_flow_director_flow,
10292                 (void *)&cmd_flow_director_flow_type,
10293                 (void *)&cmd_flow_director_drop,
10294                 (void *)&cmd_flow_director_queue,
10295                 (void *)&cmd_flow_director_queue_id,
10296                 (void *)&cmd_flow_director_fd_id,
10297                 (void *)&cmd_flow_director_fd_id_value,
10298                 (void *)&cmd_flow_director_packet,
10299                 (void *)&cmd_flow_director_filepath,
10300                 NULL,
10301         },
10302 };
10303
10304 #endif /* RTE_NET_I40E */
10305
10306 /* *** deal with flow director mask *** */
10307 struct cmd_flow_director_mask_result {
10308         cmdline_fixed_string_t flow_director_mask;
10309         portid_t port_id;
10310         cmdline_fixed_string_t mode;
10311         cmdline_fixed_string_t mode_value;
10312         cmdline_fixed_string_t vlan;
10313         uint16_t vlan_mask;
10314         cmdline_fixed_string_t src_mask;
10315         cmdline_ipaddr_t ipv4_src;
10316         cmdline_ipaddr_t ipv6_src;
10317         uint16_t port_src;
10318         cmdline_fixed_string_t dst_mask;
10319         cmdline_ipaddr_t ipv4_dst;
10320         cmdline_ipaddr_t ipv6_dst;
10321         uint16_t port_dst;
10322         cmdline_fixed_string_t mac;
10323         uint8_t mac_addr_byte_mask;
10324         cmdline_fixed_string_t tunnel_id;
10325         uint32_t tunnel_id_mask;
10326         cmdline_fixed_string_t tunnel_type;
10327         uint8_t tunnel_type_mask;
10328 };
10329
10330 static void
10331 cmd_flow_director_mask_parsed(void *parsed_result,
10332                           __rte_unused struct cmdline *cl,
10333                           __rte_unused void *data)
10334 {
10335         struct cmd_flow_director_mask_result *res = parsed_result;
10336         struct rte_eth_fdir_masks *mask;
10337         struct rte_port *port;
10338
10339         port = &ports[res->port_id];
10340         /** Check if the port is not started **/
10341         if (port->port_status != RTE_PORT_STOPPED) {
10342                 printf("Please stop port %d first\n", res->port_id);
10343                 return;
10344         }
10345
10346         mask = &port->dev_conf.fdir_conf.mask;
10347
10348         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10349                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10350                         printf("Please set mode to MAC-VLAN.\n");
10351                         return;
10352                 }
10353
10354                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10355         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10356                 if (strcmp(res->mode_value, "Tunnel")) {
10357                         printf("Please set mode to Tunnel.\n");
10358                         return;
10359                 }
10360
10361                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10362                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10363                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10364                 mask->tunnel_type_mask = res->tunnel_type_mask;
10365         } else {
10366                 if (strcmp(res->mode_value, "IP")) {
10367                         printf("Please set mode to IP.\n");
10368                         return;
10369                 }
10370
10371                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10372                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10373                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10374                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10375                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10376                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10377                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10378         }
10379
10380         cmd_reconfig_device_queue(res->port_id, 1, 1);
10381 }
10382
10383 cmdline_parse_token_string_t cmd_flow_director_mask =
10384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10385                                  flow_director_mask, "flow_director_mask");
10386 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10387         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10388                               port_id, RTE_UINT16);
10389 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10390         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10391                                  vlan, "vlan");
10392 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10393         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10394                               vlan_mask, RTE_UINT16);
10395 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10397                                  src_mask, "src_mask");
10398 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10399         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  ipv4_src);
10401 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10402         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10403                                  ipv6_src);
10404 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10405         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10406                               port_src, RTE_UINT16);
10407 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10408         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10409                                  dst_mask, "dst_mask");
10410 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10411         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10412                                  ipv4_dst);
10413 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10414         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10415                                  ipv6_dst);
10416 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10417         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10418                               port_dst, RTE_UINT16);
10419
10420 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10422                                  mode, "mode");
10423 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10425                                  mode_value, "IP");
10426 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10428                                  mode_value, "MAC-VLAN");
10429 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10431                                  mode_value, "Tunnel");
10432 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10433         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10434                                  mac, "mac");
10435 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10436         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10437                               mac_addr_byte_mask, RTE_UINT8);
10438 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10440                                  tunnel_type, "tunnel-type");
10441 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10442         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10443                               tunnel_type_mask, RTE_UINT8);
10444 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10446                                  tunnel_id, "tunnel-id");
10447 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10448         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10449                               tunnel_id_mask, RTE_UINT32);
10450
10451 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10452         .f = cmd_flow_director_mask_parsed,
10453         .data = NULL,
10454         .help_str = "flow_director_mask ... : "
10455                 "Set IP mode flow director's mask on NIC",
10456         .tokens = {
10457                 (void *)&cmd_flow_director_mask,
10458                 (void *)&cmd_flow_director_mask_port_id,
10459                 (void *)&cmd_flow_director_mask_mode,
10460                 (void *)&cmd_flow_director_mask_mode_ip,
10461                 (void *)&cmd_flow_director_mask_vlan,
10462                 (void *)&cmd_flow_director_mask_vlan_value,
10463                 (void *)&cmd_flow_director_mask_src,
10464                 (void *)&cmd_flow_director_mask_ipv4_src,
10465                 (void *)&cmd_flow_director_mask_ipv6_src,
10466                 (void *)&cmd_flow_director_mask_port_src,
10467                 (void *)&cmd_flow_director_mask_dst,
10468                 (void *)&cmd_flow_director_mask_ipv4_dst,
10469                 (void *)&cmd_flow_director_mask_ipv6_dst,
10470                 (void *)&cmd_flow_director_mask_port_dst,
10471                 NULL,
10472         },
10473 };
10474
10475 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10476         .f = cmd_flow_director_mask_parsed,
10477         .data = NULL,
10478         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10479                 "flow director's mask on NIC",
10480         .tokens = {
10481                 (void *)&cmd_flow_director_mask,
10482                 (void *)&cmd_flow_director_mask_port_id,
10483                 (void *)&cmd_flow_director_mask_mode,
10484                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10485                 (void *)&cmd_flow_director_mask_vlan,
10486                 (void *)&cmd_flow_director_mask_vlan_value,
10487                 NULL,
10488         },
10489 };
10490
10491 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10492         .f = cmd_flow_director_mask_parsed,
10493         .data = NULL,
10494         .help_str = "flow_director_mask ... : Set tunnel mode "
10495                 "flow director's mask on NIC",
10496         .tokens = {
10497                 (void *)&cmd_flow_director_mask,
10498                 (void *)&cmd_flow_director_mask_port_id,
10499                 (void *)&cmd_flow_director_mask_mode,
10500                 (void *)&cmd_flow_director_mask_mode_tunnel,
10501                 (void *)&cmd_flow_director_mask_vlan,
10502                 (void *)&cmd_flow_director_mask_vlan_value,
10503                 (void *)&cmd_flow_director_mask_mac,
10504                 (void *)&cmd_flow_director_mask_mac_value,
10505                 (void *)&cmd_flow_director_mask_tunnel_type,
10506                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10507                 (void *)&cmd_flow_director_mask_tunnel_id,
10508                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10509                 NULL,
10510         },
10511 };
10512
10513 /* *** deal with flow director flexible payload configuration *** */
10514 struct cmd_flow_director_flexpayload_result {
10515         cmdline_fixed_string_t flow_director_flexpayload;
10516         portid_t port_id;
10517         cmdline_fixed_string_t payload_layer;
10518         cmdline_fixed_string_t payload_cfg;
10519 };
10520
10521 static inline int
10522 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10523 {
10524         char s[256];
10525         const char *p, *p0 = q_arg;
10526         char *end;
10527         unsigned long int_fld;
10528         char *str_fld[max_num];
10529         int i;
10530         unsigned size;
10531         int ret = -1;
10532
10533         p = strchr(p0, '(');
10534         if (p == NULL)
10535                 return -1;
10536         ++p;
10537         p0 = strchr(p, ')');
10538         if (p0 == NULL)
10539                 return -1;
10540
10541         size = p0 - p;
10542         if (size >= sizeof(s))
10543                 return -1;
10544
10545         snprintf(s, sizeof(s), "%.*s", size, p);
10546         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10547         if (ret < 0 || ret > max_num)
10548                 return -1;
10549         for (i = 0; i < ret; i++) {
10550                 errno = 0;
10551                 int_fld = strtoul(str_fld[i], &end, 0);
10552                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10553                         return -1;
10554                 offsets[i] = (uint16_t)int_fld;
10555         }
10556         return ret;
10557 }
10558
10559 static void
10560 cmd_flow_director_flxpld_parsed(void *parsed_result,
10561                           __rte_unused struct cmdline *cl,
10562                           __rte_unused void *data)
10563 {
10564         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10565         struct rte_eth_flex_payload_cfg flex_cfg;
10566         struct rte_port *port;
10567         int ret = 0;
10568
10569         port = &ports[res->port_id];
10570         /** Check if the port is not started **/
10571         if (port->port_status != RTE_PORT_STOPPED) {
10572                 printf("Please stop port %d first\n", res->port_id);
10573                 return;
10574         }
10575
10576         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10577
10578         if (!strcmp(res->payload_layer, "raw"))
10579                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10580         else if (!strcmp(res->payload_layer, "l2"))
10581                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10582         else if (!strcmp(res->payload_layer, "l3"))
10583                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10584         else if (!strcmp(res->payload_layer, "l4"))
10585                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10586
10587         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10588                             RTE_ETH_FDIR_MAX_FLEXLEN);
10589         if (ret < 0) {
10590                 printf("error: Cannot parse flex payload input.\n");
10591                 return;
10592         }
10593
10594         fdir_set_flex_payload(res->port_id, &flex_cfg);
10595         cmd_reconfig_device_queue(res->port_id, 1, 1);
10596 }
10597
10598 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10600                                  flow_director_flexpayload,
10601                                  "flow_director_flex_payload");
10602 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10603         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10604                               port_id, RTE_UINT16);
10605 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10607                                  payload_layer, "raw#l2#l3#l4");
10608 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10610                                  payload_cfg, NULL);
10611
10612 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10613         .f = cmd_flow_director_flxpld_parsed,
10614         .data = NULL,
10615         .help_str = "flow_director_flexpayload ... : "
10616                 "Set flow director's flex payload on NIC",
10617         .tokens = {
10618                 (void *)&cmd_flow_director_flexpayload,
10619                 (void *)&cmd_flow_director_flexpayload_port_id,
10620                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10621                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10622                 NULL,
10623         },
10624 };
10625
10626 /* Generic flow interface command. */
10627 extern cmdline_parse_inst_t cmd_flow;
10628
10629 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10630 struct cmd_mcast_addr_result {
10631         cmdline_fixed_string_t mcast_addr_cmd;
10632         cmdline_fixed_string_t what;
10633         uint16_t port_num;
10634         struct rte_ether_addr mc_addr;
10635 };
10636
10637 static void cmd_mcast_addr_parsed(void *parsed_result,
10638                 __rte_unused struct cmdline *cl,
10639                 __rte_unused void *data)
10640 {
10641         struct cmd_mcast_addr_result *res = parsed_result;
10642
10643         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10644                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10645                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10646                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10647                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10648                 return;
10649         }
10650         if (strcmp(res->what, "add") == 0)
10651                 mcast_addr_add(res->port_num, &res->mc_addr);
10652         else
10653                 mcast_addr_remove(res->port_num, &res->mc_addr);
10654 }
10655
10656 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10657         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10658                                  mcast_addr_cmd, "mcast_addr");
10659 cmdline_parse_token_string_t cmd_mcast_addr_what =
10660         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10661                                  "add#remove");
10662 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10663         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10664                                  RTE_UINT16);
10665 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10667
10668 cmdline_parse_inst_t cmd_mcast_addr = {
10669         .f = cmd_mcast_addr_parsed,
10670         .data = (void *)0,
10671         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10672                 "Add/Remove multicast MAC address on port_id",
10673         .tokens = {
10674                 (void *)&cmd_mcast_addr_cmd,
10675                 (void *)&cmd_mcast_addr_what,
10676                 (void *)&cmd_mcast_addr_portnum,
10677                 (void *)&cmd_mcast_addr_addr,
10678                 NULL,
10679         },
10680 };
10681
10682 /* vf vlan anti spoof configuration */
10683
10684 /* Common result structure for vf vlan anti spoof */
10685 struct cmd_vf_vlan_anti_spoof_result {
10686         cmdline_fixed_string_t set;
10687         cmdline_fixed_string_t vf;
10688         cmdline_fixed_string_t vlan;
10689         cmdline_fixed_string_t antispoof;
10690         portid_t port_id;
10691         uint32_t vf_id;
10692         cmdline_fixed_string_t on_off;
10693 };
10694
10695 /* Common CLI fields for vf vlan anti spoof enable disable */
10696 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10697         TOKEN_STRING_INITIALIZER
10698                 (struct cmd_vf_vlan_anti_spoof_result,
10699                  set, "set");
10700 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10701         TOKEN_STRING_INITIALIZER
10702                 (struct cmd_vf_vlan_anti_spoof_result,
10703                  vf, "vf");
10704 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10705         TOKEN_STRING_INITIALIZER
10706                 (struct cmd_vf_vlan_anti_spoof_result,
10707                  vlan, "vlan");
10708 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10709         TOKEN_STRING_INITIALIZER
10710                 (struct cmd_vf_vlan_anti_spoof_result,
10711                  antispoof, "antispoof");
10712 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10713         TOKEN_NUM_INITIALIZER
10714                 (struct cmd_vf_vlan_anti_spoof_result,
10715                  port_id, RTE_UINT16);
10716 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10717         TOKEN_NUM_INITIALIZER
10718                 (struct cmd_vf_vlan_anti_spoof_result,
10719                  vf_id, RTE_UINT32);
10720 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10721         TOKEN_STRING_INITIALIZER
10722                 (struct cmd_vf_vlan_anti_spoof_result,
10723                  on_off, "on#off");
10724
10725 static void
10726 cmd_set_vf_vlan_anti_spoof_parsed(
10727         void *parsed_result,
10728         __rte_unused struct cmdline *cl,
10729         __rte_unused void *data)
10730 {
10731         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10732         int ret = -ENOTSUP;
10733
10734         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10735
10736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10737                 return;
10738
10739 #ifdef RTE_NET_IXGBE
10740         if (ret == -ENOTSUP)
10741                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10742                                 res->vf_id, is_on);
10743 #endif
10744 #ifdef RTE_NET_I40E
10745         if (ret == -ENOTSUP)
10746                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10747                                 res->vf_id, is_on);
10748 #endif
10749 #ifdef RTE_NET_BNXT
10750         if (ret == -ENOTSUP)
10751                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10752                                 res->vf_id, is_on);
10753 #endif
10754
10755         switch (ret) {
10756         case 0:
10757                 break;
10758         case -EINVAL:
10759                 printf("invalid vf_id %d\n", res->vf_id);
10760                 break;
10761         case -ENODEV:
10762                 printf("invalid port_id %d\n", res->port_id);
10763                 break;
10764         case -ENOTSUP:
10765                 printf("function not implemented\n");
10766                 break;
10767         default:
10768                 printf("programming error: (%s)\n", strerror(-ret));
10769         }
10770 }
10771
10772 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10773         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10774         .data = NULL,
10775         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10776         .tokens = {
10777                 (void *)&cmd_vf_vlan_anti_spoof_set,
10778                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10779                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10780                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10781                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10782                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10783                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10784                 NULL,
10785         },
10786 };
10787
10788 /* vf mac anti spoof configuration */
10789
10790 /* Common result structure for vf mac anti spoof */
10791 struct cmd_vf_mac_anti_spoof_result {
10792         cmdline_fixed_string_t set;
10793         cmdline_fixed_string_t vf;
10794         cmdline_fixed_string_t mac;
10795         cmdline_fixed_string_t antispoof;
10796         portid_t port_id;
10797         uint32_t vf_id;
10798         cmdline_fixed_string_t on_off;
10799 };
10800
10801 /* Common CLI fields for vf mac anti spoof enable disable */
10802 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10803         TOKEN_STRING_INITIALIZER
10804                 (struct cmd_vf_mac_anti_spoof_result,
10805                  set, "set");
10806 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10807         TOKEN_STRING_INITIALIZER
10808                 (struct cmd_vf_mac_anti_spoof_result,
10809                  vf, "vf");
10810 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10811         TOKEN_STRING_INITIALIZER
10812                 (struct cmd_vf_mac_anti_spoof_result,
10813                  mac, "mac");
10814 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10815         TOKEN_STRING_INITIALIZER
10816                 (struct cmd_vf_mac_anti_spoof_result,
10817                  antispoof, "antispoof");
10818 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10819         TOKEN_NUM_INITIALIZER
10820                 (struct cmd_vf_mac_anti_spoof_result,
10821                  port_id, RTE_UINT16);
10822 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10823         TOKEN_NUM_INITIALIZER
10824                 (struct cmd_vf_mac_anti_spoof_result,
10825                  vf_id, RTE_UINT32);
10826 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10827         TOKEN_STRING_INITIALIZER
10828                 (struct cmd_vf_mac_anti_spoof_result,
10829                  on_off, "on#off");
10830
10831 static void
10832 cmd_set_vf_mac_anti_spoof_parsed(
10833         void *parsed_result,
10834         __rte_unused struct cmdline *cl,
10835         __rte_unused void *data)
10836 {
10837         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10838         int ret = -ENOTSUP;
10839
10840         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10841
10842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10843                 return;
10844
10845 #ifdef RTE_NET_IXGBE
10846         if (ret == -ENOTSUP)
10847                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10848                         res->vf_id, is_on);
10849 #endif
10850 #ifdef RTE_NET_I40E
10851         if (ret == -ENOTSUP)
10852                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10853                         res->vf_id, is_on);
10854 #endif
10855 #ifdef RTE_NET_BNXT
10856         if (ret == -ENOTSUP)
10857                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10858                         res->vf_id, is_on);
10859 #endif
10860
10861         switch (ret) {
10862         case 0:
10863                 break;
10864         case -EINVAL:
10865                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10866                 break;
10867         case -ENODEV:
10868                 printf("invalid port_id %d\n", res->port_id);
10869                 break;
10870         case -ENOTSUP:
10871                 printf("function not implemented\n");
10872                 break;
10873         default:
10874                 printf("programming error: (%s)\n", strerror(-ret));
10875         }
10876 }
10877
10878 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10879         .f = cmd_set_vf_mac_anti_spoof_parsed,
10880         .data = NULL,
10881         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10882         .tokens = {
10883                 (void *)&cmd_vf_mac_anti_spoof_set,
10884                 (void *)&cmd_vf_mac_anti_spoof_vf,
10885                 (void *)&cmd_vf_mac_anti_spoof_mac,
10886                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10887                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10888                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10889                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10890                 NULL,
10891         },
10892 };
10893
10894 /* vf vlan strip queue configuration */
10895
10896 /* Common result structure for vf mac anti spoof */
10897 struct cmd_vf_vlan_stripq_result {
10898         cmdline_fixed_string_t set;
10899         cmdline_fixed_string_t vf;
10900         cmdline_fixed_string_t vlan;
10901         cmdline_fixed_string_t stripq;
10902         portid_t port_id;
10903         uint16_t vf_id;
10904         cmdline_fixed_string_t on_off;
10905 };
10906
10907 /* Common CLI fields for vf vlan strip enable disable */
10908 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10909         TOKEN_STRING_INITIALIZER
10910                 (struct cmd_vf_vlan_stripq_result,
10911                  set, "set");
10912 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10913         TOKEN_STRING_INITIALIZER
10914                 (struct cmd_vf_vlan_stripq_result,
10915                  vf, "vf");
10916 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10917         TOKEN_STRING_INITIALIZER
10918                 (struct cmd_vf_vlan_stripq_result,
10919                  vlan, "vlan");
10920 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10921         TOKEN_STRING_INITIALIZER
10922                 (struct cmd_vf_vlan_stripq_result,
10923                  stripq, "stripq");
10924 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10925         TOKEN_NUM_INITIALIZER
10926                 (struct cmd_vf_vlan_stripq_result,
10927                  port_id, RTE_UINT16);
10928 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10929         TOKEN_NUM_INITIALIZER
10930                 (struct cmd_vf_vlan_stripq_result,
10931                  vf_id, RTE_UINT16);
10932 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10933         TOKEN_STRING_INITIALIZER
10934                 (struct cmd_vf_vlan_stripq_result,
10935                  on_off, "on#off");
10936
10937 static void
10938 cmd_set_vf_vlan_stripq_parsed(
10939         void *parsed_result,
10940         __rte_unused struct cmdline *cl,
10941         __rte_unused void *data)
10942 {
10943         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10944         int ret = -ENOTSUP;
10945
10946         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10947
10948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10949                 return;
10950
10951 #ifdef RTE_NET_IXGBE
10952         if (ret == -ENOTSUP)
10953                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10954                         res->vf_id, is_on);
10955 #endif
10956 #ifdef RTE_NET_I40E
10957         if (ret == -ENOTSUP)
10958                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10959                         res->vf_id, is_on);
10960 #endif
10961 #ifdef RTE_NET_BNXT
10962         if (ret == -ENOTSUP)
10963                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10964                         res->vf_id, is_on);
10965 #endif
10966
10967         switch (ret) {
10968         case 0:
10969                 break;
10970         case -EINVAL:
10971                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10972                 break;
10973         case -ENODEV:
10974                 printf("invalid port_id %d\n", res->port_id);
10975                 break;
10976         case -ENOTSUP:
10977                 printf("function not implemented\n");
10978                 break;
10979         default:
10980                 printf("programming error: (%s)\n", strerror(-ret));
10981         }
10982 }
10983
10984 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10985         .f = cmd_set_vf_vlan_stripq_parsed,
10986         .data = NULL,
10987         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10988         .tokens = {
10989                 (void *)&cmd_vf_vlan_stripq_set,
10990                 (void *)&cmd_vf_vlan_stripq_vf,
10991                 (void *)&cmd_vf_vlan_stripq_vlan,
10992                 (void *)&cmd_vf_vlan_stripq_stripq,
10993                 (void *)&cmd_vf_vlan_stripq_port_id,
10994                 (void *)&cmd_vf_vlan_stripq_vf_id,
10995                 (void *)&cmd_vf_vlan_stripq_on_off,
10996                 NULL,
10997         },
10998 };
10999
11000 /* vf vlan insert configuration */
11001
11002 /* Common result structure for vf vlan insert */
11003 struct cmd_vf_vlan_insert_result {
11004         cmdline_fixed_string_t set;
11005         cmdline_fixed_string_t vf;
11006         cmdline_fixed_string_t vlan;
11007         cmdline_fixed_string_t insert;
11008         portid_t port_id;
11009         uint16_t vf_id;
11010         uint16_t vlan_id;
11011 };
11012
11013 /* Common CLI fields for vf vlan insert enable disable */
11014 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11015         TOKEN_STRING_INITIALIZER
11016                 (struct cmd_vf_vlan_insert_result,
11017                  set, "set");
11018 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11019         TOKEN_STRING_INITIALIZER
11020                 (struct cmd_vf_vlan_insert_result,
11021                  vf, "vf");
11022 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11023         TOKEN_STRING_INITIALIZER
11024                 (struct cmd_vf_vlan_insert_result,
11025                  vlan, "vlan");
11026 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11027         TOKEN_STRING_INITIALIZER
11028                 (struct cmd_vf_vlan_insert_result,
11029                  insert, "insert");
11030 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11031         TOKEN_NUM_INITIALIZER
11032                 (struct cmd_vf_vlan_insert_result,
11033                  port_id, RTE_UINT16);
11034 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11035         TOKEN_NUM_INITIALIZER
11036                 (struct cmd_vf_vlan_insert_result,
11037                  vf_id, RTE_UINT16);
11038 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11039         TOKEN_NUM_INITIALIZER
11040                 (struct cmd_vf_vlan_insert_result,
11041                  vlan_id, RTE_UINT16);
11042
11043 static void
11044 cmd_set_vf_vlan_insert_parsed(
11045         void *parsed_result,
11046         __rte_unused struct cmdline *cl,
11047         __rte_unused void *data)
11048 {
11049         struct cmd_vf_vlan_insert_result *res = parsed_result;
11050         int ret = -ENOTSUP;
11051
11052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11053                 return;
11054
11055 #ifdef RTE_NET_IXGBE
11056         if (ret == -ENOTSUP)
11057                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11058                         res->vlan_id);
11059 #endif
11060 #ifdef RTE_NET_I40E
11061         if (ret == -ENOTSUP)
11062                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11063                         res->vlan_id);
11064 #endif
11065 #ifdef RTE_NET_BNXT
11066         if (ret == -ENOTSUP)
11067                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11068                         res->vlan_id);
11069 #endif
11070
11071         switch (ret) {
11072         case 0:
11073                 break;
11074         case -EINVAL:
11075                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11076                 break;
11077         case -ENODEV:
11078                 printf("invalid port_id %d\n", res->port_id);
11079                 break;
11080         case -ENOTSUP:
11081                 printf("function not implemented\n");
11082                 break;
11083         default:
11084                 printf("programming error: (%s)\n", strerror(-ret));
11085         }
11086 }
11087
11088 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11089         .f = cmd_set_vf_vlan_insert_parsed,
11090         .data = NULL,
11091         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11092         .tokens = {
11093                 (void *)&cmd_vf_vlan_insert_set,
11094                 (void *)&cmd_vf_vlan_insert_vf,
11095                 (void *)&cmd_vf_vlan_insert_vlan,
11096                 (void *)&cmd_vf_vlan_insert_insert,
11097                 (void *)&cmd_vf_vlan_insert_port_id,
11098                 (void *)&cmd_vf_vlan_insert_vf_id,
11099                 (void *)&cmd_vf_vlan_insert_vlan_id,
11100                 NULL,
11101         },
11102 };
11103
11104 /* tx loopback configuration */
11105
11106 /* Common result structure for tx loopback */
11107 struct cmd_tx_loopback_result {
11108         cmdline_fixed_string_t set;
11109         cmdline_fixed_string_t tx;
11110         cmdline_fixed_string_t loopback;
11111         portid_t port_id;
11112         cmdline_fixed_string_t on_off;
11113 };
11114
11115 /* Common CLI fields for tx loopback enable disable */
11116 cmdline_parse_token_string_t cmd_tx_loopback_set =
11117         TOKEN_STRING_INITIALIZER
11118                 (struct cmd_tx_loopback_result,
11119                  set, "set");
11120 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11121         TOKEN_STRING_INITIALIZER
11122                 (struct cmd_tx_loopback_result,
11123                  tx, "tx");
11124 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11125         TOKEN_STRING_INITIALIZER
11126                 (struct cmd_tx_loopback_result,
11127                  loopback, "loopback");
11128 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11129         TOKEN_NUM_INITIALIZER
11130                 (struct cmd_tx_loopback_result,
11131                  port_id, RTE_UINT16);
11132 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11133         TOKEN_STRING_INITIALIZER
11134                 (struct cmd_tx_loopback_result,
11135                  on_off, "on#off");
11136
11137 static void
11138 cmd_set_tx_loopback_parsed(
11139         void *parsed_result,
11140         __rte_unused struct cmdline *cl,
11141         __rte_unused void *data)
11142 {
11143         struct cmd_tx_loopback_result *res = parsed_result;
11144         int ret = -ENOTSUP;
11145
11146         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11147
11148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11149                 return;
11150
11151 #ifdef RTE_NET_IXGBE
11152         if (ret == -ENOTSUP)
11153                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11154 #endif
11155 #ifdef RTE_NET_I40E
11156         if (ret == -ENOTSUP)
11157                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11158 #endif
11159 #ifdef RTE_NET_BNXT
11160         if (ret == -ENOTSUP)
11161                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11162 #endif
11163 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11164         if (ret == -ENOTSUP)
11165                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11166 #endif
11167
11168         switch (ret) {
11169         case 0:
11170                 break;
11171         case -EINVAL:
11172                 printf("invalid is_on %d\n", is_on);
11173                 break;
11174         case -ENODEV:
11175                 printf("invalid port_id %d\n", res->port_id);
11176                 break;
11177         case -ENOTSUP:
11178                 printf("function not implemented\n");
11179                 break;
11180         default:
11181                 printf("programming error: (%s)\n", strerror(-ret));
11182         }
11183 }
11184
11185 cmdline_parse_inst_t cmd_set_tx_loopback = {
11186         .f = cmd_set_tx_loopback_parsed,
11187         .data = NULL,
11188         .help_str = "set tx loopback <port_id> on|off",
11189         .tokens = {
11190                 (void *)&cmd_tx_loopback_set,
11191                 (void *)&cmd_tx_loopback_tx,
11192                 (void *)&cmd_tx_loopback_loopback,
11193                 (void *)&cmd_tx_loopback_port_id,
11194                 (void *)&cmd_tx_loopback_on_off,
11195                 NULL,
11196         },
11197 };
11198
11199 /* all queues drop enable configuration */
11200
11201 /* Common result structure for all queues drop enable */
11202 struct cmd_all_queues_drop_en_result {
11203         cmdline_fixed_string_t set;
11204         cmdline_fixed_string_t all;
11205         cmdline_fixed_string_t queues;
11206         cmdline_fixed_string_t drop;
11207         portid_t port_id;
11208         cmdline_fixed_string_t on_off;
11209 };
11210
11211 /* Common CLI fields for tx loopback enable disable */
11212 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11213         TOKEN_STRING_INITIALIZER
11214                 (struct cmd_all_queues_drop_en_result,
11215                  set, "set");
11216 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11217         TOKEN_STRING_INITIALIZER
11218                 (struct cmd_all_queues_drop_en_result,
11219                  all, "all");
11220 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11221         TOKEN_STRING_INITIALIZER
11222                 (struct cmd_all_queues_drop_en_result,
11223                  queues, "queues");
11224 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11225         TOKEN_STRING_INITIALIZER
11226                 (struct cmd_all_queues_drop_en_result,
11227                  drop, "drop");
11228 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11229         TOKEN_NUM_INITIALIZER
11230                 (struct cmd_all_queues_drop_en_result,
11231                  port_id, RTE_UINT16);
11232 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11233         TOKEN_STRING_INITIALIZER
11234                 (struct cmd_all_queues_drop_en_result,
11235                  on_off, "on#off");
11236
11237 static void
11238 cmd_set_all_queues_drop_en_parsed(
11239         void *parsed_result,
11240         __rte_unused struct cmdline *cl,
11241         __rte_unused void *data)
11242 {
11243         struct cmd_all_queues_drop_en_result *res = parsed_result;
11244         int ret = -ENOTSUP;
11245         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11246
11247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11248                 return;
11249
11250 #ifdef RTE_NET_IXGBE
11251         if (ret == -ENOTSUP)
11252                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11253 #endif
11254 #ifdef RTE_NET_BNXT
11255         if (ret == -ENOTSUP)
11256                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11257 #endif
11258         switch (ret) {
11259         case 0:
11260                 break;
11261         case -EINVAL:
11262                 printf("invalid is_on %d\n", is_on);
11263                 break;
11264         case -ENODEV:
11265                 printf("invalid port_id %d\n", res->port_id);
11266                 break;
11267         case -ENOTSUP:
11268                 printf("function not implemented\n");
11269                 break;
11270         default:
11271                 printf("programming error: (%s)\n", strerror(-ret));
11272         }
11273 }
11274
11275 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11276         .f = cmd_set_all_queues_drop_en_parsed,
11277         .data = NULL,
11278         .help_str = "set all queues drop <port_id> on|off",
11279         .tokens = {
11280                 (void *)&cmd_all_queues_drop_en_set,
11281                 (void *)&cmd_all_queues_drop_en_all,
11282                 (void *)&cmd_all_queues_drop_en_queues,
11283                 (void *)&cmd_all_queues_drop_en_drop,
11284                 (void *)&cmd_all_queues_drop_en_port_id,
11285                 (void *)&cmd_all_queues_drop_en_on_off,
11286                 NULL,
11287         },
11288 };
11289
11290 /* vf split drop enable configuration */
11291
11292 /* Common result structure for vf split drop enable */
11293 struct cmd_vf_split_drop_en_result {
11294         cmdline_fixed_string_t set;
11295         cmdline_fixed_string_t vf;
11296         cmdline_fixed_string_t split;
11297         cmdline_fixed_string_t drop;
11298         portid_t port_id;
11299         uint16_t vf_id;
11300         cmdline_fixed_string_t on_off;
11301 };
11302
11303 /* Common CLI fields for vf split drop enable disable */
11304 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11305         TOKEN_STRING_INITIALIZER
11306                 (struct cmd_vf_split_drop_en_result,
11307                  set, "set");
11308 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11309         TOKEN_STRING_INITIALIZER
11310                 (struct cmd_vf_split_drop_en_result,
11311                  vf, "vf");
11312 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11313         TOKEN_STRING_INITIALIZER
11314                 (struct cmd_vf_split_drop_en_result,
11315                  split, "split");
11316 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11317         TOKEN_STRING_INITIALIZER
11318                 (struct cmd_vf_split_drop_en_result,
11319                  drop, "drop");
11320 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11321         TOKEN_NUM_INITIALIZER
11322                 (struct cmd_vf_split_drop_en_result,
11323                  port_id, RTE_UINT16);
11324 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11325         TOKEN_NUM_INITIALIZER
11326                 (struct cmd_vf_split_drop_en_result,
11327                  vf_id, RTE_UINT16);
11328 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11329         TOKEN_STRING_INITIALIZER
11330                 (struct cmd_vf_split_drop_en_result,
11331                  on_off, "on#off");
11332
11333 static void
11334 cmd_set_vf_split_drop_en_parsed(
11335         void *parsed_result,
11336         __rte_unused struct cmdline *cl,
11337         __rte_unused void *data)
11338 {
11339         struct cmd_vf_split_drop_en_result *res = parsed_result;
11340         int ret = -ENOTSUP;
11341         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11342
11343         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11344                 return;
11345
11346 #ifdef RTE_NET_IXGBE
11347         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11348                         is_on);
11349 #endif
11350         switch (ret) {
11351         case 0:
11352                 break;
11353         case -EINVAL:
11354                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11355                 break;
11356         case -ENODEV:
11357                 printf("invalid port_id %d\n", res->port_id);
11358                 break;
11359         case -ENOTSUP:
11360                 printf("not supported on port %d\n", res->port_id);
11361                 break;
11362         default:
11363                 printf("programming error: (%s)\n", strerror(-ret));
11364         }
11365 }
11366
11367 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11368         .f = cmd_set_vf_split_drop_en_parsed,
11369         .data = NULL,
11370         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11371         .tokens = {
11372                 (void *)&cmd_vf_split_drop_en_set,
11373                 (void *)&cmd_vf_split_drop_en_vf,
11374                 (void *)&cmd_vf_split_drop_en_split,
11375                 (void *)&cmd_vf_split_drop_en_drop,
11376                 (void *)&cmd_vf_split_drop_en_port_id,
11377                 (void *)&cmd_vf_split_drop_en_vf_id,
11378                 (void *)&cmd_vf_split_drop_en_on_off,
11379                 NULL,
11380         },
11381 };
11382
11383 /* vf mac address configuration */
11384
11385 /* Common result structure for vf mac address */
11386 struct cmd_set_vf_mac_addr_result {
11387         cmdline_fixed_string_t set;
11388         cmdline_fixed_string_t vf;
11389         cmdline_fixed_string_t mac;
11390         cmdline_fixed_string_t addr;
11391         portid_t port_id;
11392         uint16_t vf_id;
11393         struct rte_ether_addr mac_addr;
11394
11395 };
11396
11397 /* Common CLI fields for vf split drop enable disable */
11398 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11399         TOKEN_STRING_INITIALIZER
11400                 (struct cmd_set_vf_mac_addr_result,
11401                  set, "set");
11402 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11403         TOKEN_STRING_INITIALIZER
11404                 (struct cmd_set_vf_mac_addr_result,
11405                  vf, "vf");
11406 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11407         TOKEN_STRING_INITIALIZER
11408                 (struct cmd_set_vf_mac_addr_result,
11409                  mac, "mac");
11410 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11411         TOKEN_STRING_INITIALIZER
11412                 (struct cmd_set_vf_mac_addr_result,
11413                  addr, "addr");
11414 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11415         TOKEN_NUM_INITIALIZER
11416                 (struct cmd_set_vf_mac_addr_result,
11417                  port_id, RTE_UINT16);
11418 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11419         TOKEN_NUM_INITIALIZER
11420                 (struct cmd_set_vf_mac_addr_result,
11421                  vf_id, RTE_UINT16);
11422 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11423         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11424                  mac_addr);
11425
11426 static void
11427 cmd_set_vf_mac_addr_parsed(
11428         void *parsed_result,
11429         __rte_unused struct cmdline *cl,
11430         __rte_unused void *data)
11431 {
11432         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11433         int ret = -ENOTSUP;
11434
11435         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11436                 return;
11437
11438 #ifdef RTE_NET_IXGBE
11439         if (ret == -ENOTSUP)
11440                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11441                                 &res->mac_addr);
11442 #endif
11443 #ifdef RTE_NET_I40E
11444         if (ret == -ENOTSUP)
11445                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11446                                 &res->mac_addr);
11447 #endif
11448 #ifdef RTE_NET_BNXT
11449         if (ret == -ENOTSUP)
11450                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11451                                 &res->mac_addr);
11452 #endif
11453
11454         switch (ret) {
11455         case 0:
11456                 break;
11457         case -EINVAL:
11458                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11459                 break;
11460         case -ENODEV:
11461                 printf("invalid port_id %d\n", res->port_id);
11462                 break;
11463         case -ENOTSUP:
11464                 printf("function not implemented\n");
11465                 break;
11466         default:
11467                 printf("programming error: (%s)\n", strerror(-ret));
11468         }
11469 }
11470
11471 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11472         .f = cmd_set_vf_mac_addr_parsed,
11473         .data = NULL,
11474         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11475         .tokens = {
11476                 (void *)&cmd_set_vf_mac_addr_set,
11477                 (void *)&cmd_set_vf_mac_addr_vf,
11478                 (void *)&cmd_set_vf_mac_addr_mac,
11479                 (void *)&cmd_set_vf_mac_addr_addr,
11480                 (void *)&cmd_set_vf_mac_addr_port_id,
11481                 (void *)&cmd_set_vf_mac_addr_vf_id,
11482                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11483                 NULL,
11484         },
11485 };
11486
11487 /* MACsec configuration */
11488
11489 /* Common result structure for MACsec offload enable */
11490 struct cmd_macsec_offload_on_result {
11491         cmdline_fixed_string_t set;
11492         cmdline_fixed_string_t macsec;
11493         cmdline_fixed_string_t offload;
11494         portid_t port_id;
11495         cmdline_fixed_string_t on;
11496         cmdline_fixed_string_t encrypt;
11497         cmdline_fixed_string_t en_on_off;
11498         cmdline_fixed_string_t replay_protect;
11499         cmdline_fixed_string_t rp_on_off;
11500 };
11501
11502 /* Common CLI fields for MACsec offload disable */
11503 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11504         TOKEN_STRING_INITIALIZER
11505                 (struct cmd_macsec_offload_on_result,
11506                  set, "set");
11507 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11508         TOKEN_STRING_INITIALIZER
11509                 (struct cmd_macsec_offload_on_result,
11510                  macsec, "macsec");
11511 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11512         TOKEN_STRING_INITIALIZER
11513                 (struct cmd_macsec_offload_on_result,
11514                  offload, "offload");
11515 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11516         TOKEN_NUM_INITIALIZER
11517                 (struct cmd_macsec_offload_on_result,
11518                  port_id, RTE_UINT16);
11519 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11520         TOKEN_STRING_INITIALIZER
11521                 (struct cmd_macsec_offload_on_result,
11522                  on, "on");
11523 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11524         TOKEN_STRING_INITIALIZER
11525                 (struct cmd_macsec_offload_on_result,
11526                  encrypt, "encrypt");
11527 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11528         TOKEN_STRING_INITIALIZER
11529                 (struct cmd_macsec_offload_on_result,
11530                  en_on_off, "on#off");
11531 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11532         TOKEN_STRING_INITIALIZER
11533                 (struct cmd_macsec_offload_on_result,
11534                  replay_protect, "replay-protect");
11535 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11536         TOKEN_STRING_INITIALIZER
11537                 (struct cmd_macsec_offload_on_result,
11538                  rp_on_off, "on#off");
11539
11540 static void
11541 cmd_set_macsec_offload_on_parsed(
11542         void *parsed_result,
11543         __rte_unused struct cmdline *cl,
11544         __rte_unused void *data)
11545 {
11546         struct cmd_macsec_offload_on_result *res = parsed_result;
11547         int ret = -ENOTSUP;
11548         portid_t port_id = res->port_id;
11549         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11550         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11551         struct rte_eth_dev_info dev_info;
11552
11553         if (port_id_is_invalid(port_id, ENABLED_WARN))
11554                 return;
11555         if (!port_is_stopped(port_id)) {
11556                 printf("Please stop port %d first\n", port_id);
11557                 return;
11558         }
11559
11560         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11561         if (ret != 0)
11562                 return;
11563
11564         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11565 #ifdef RTE_NET_IXGBE
11566                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11567 #endif
11568         }
11569         RTE_SET_USED(en);
11570         RTE_SET_USED(rp);
11571
11572         switch (ret) {
11573         case 0:
11574                 ports[port_id].dev_conf.txmode.offloads |=
11575                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11576                 cmd_reconfig_device_queue(port_id, 1, 1);
11577                 break;
11578         case -ENODEV:
11579                 printf("invalid port_id %d\n", port_id);
11580                 break;
11581         case -ENOTSUP:
11582                 printf("not supported on port %d\n", port_id);
11583                 break;
11584         default:
11585                 printf("programming error: (%s)\n", strerror(-ret));
11586         }
11587 }
11588
11589 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11590         .f = cmd_set_macsec_offload_on_parsed,
11591         .data = NULL,
11592         .help_str = "set macsec offload <port_id> on "
11593                 "encrypt on|off replay-protect on|off",
11594         .tokens = {
11595                 (void *)&cmd_macsec_offload_on_set,
11596                 (void *)&cmd_macsec_offload_on_macsec,
11597                 (void *)&cmd_macsec_offload_on_offload,
11598                 (void *)&cmd_macsec_offload_on_port_id,
11599                 (void *)&cmd_macsec_offload_on_on,
11600                 (void *)&cmd_macsec_offload_on_encrypt,
11601                 (void *)&cmd_macsec_offload_on_en_on_off,
11602                 (void *)&cmd_macsec_offload_on_replay_protect,
11603                 (void *)&cmd_macsec_offload_on_rp_on_off,
11604                 NULL,
11605         },
11606 };
11607
11608 /* Common result structure for MACsec offload disable */
11609 struct cmd_macsec_offload_off_result {
11610         cmdline_fixed_string_t set;
11611         cmdline_fixed_string_t macsec;
11612         cmdline_fixed_string_t offload;
11613         portid_t port_id;
11614         cmdline_fixed_string_t off;
11615 };
11616
11617 /* Common CLI fields for MACsec offload disable */
11618 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11619         TOKEN_STRING_INITIALIZER
11620                 (struct cmd_macsec_offload_off_result,
11621                  set, "set");
11622 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11623         TOKEN_STRING_INITIALIZER
11624                 (struct cmd_macsec_offload_off_result,
11625                  macsec, "macsec");
11626 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11627         TOKEN_STRING_INITIALIZER
11628                 (struct cmd_macsec_offload_off_result,
11629                  offload, "offload");
11630 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11631         TOKEN_NUM_INITIALIZER
11632                 (struct cmd_macsec_offload_off_result,
11633                  port_id, RTE_UINT16);
11634 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11635         TOKEN_STRING_INITIALIZER
11636                 (struct cmd_macsec_offload_off_result,
11637                  off, "off");
11638
11639 static void
11640 cmd_set_macsec_offload_off_parsed(
11641         void *parsed_result,
11642         __rte_unused struct cmdline *cl,
11643         __rte_unused void *data)
11644 {
11645         struct cmd_macsec_offload_off_result *res = parsed_result;
11646         int ret = -ENOTSUP;
11647         struct rte_eth_dev_info dev_info;
11648         portid_t port_id = res->port_id;
11649
11650         if (port_id_is_invalid(port_id, ENABLED_WARN))
11651                 return;
11652         if (!port_is_stopped(port_id)) {
11653                 printf("Please stop port %d first\n", port_id);
11654                 return;
11655         }
11656
11657         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11658         if (ret != 0)
11659                 return;
11660
11661         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11662 #ifdef RTE_NET_IXGBE
11663                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11664 #endif
11665         }
11666         switch (ret) {
11667         case 0:
11668                 ports[port_id].dev_conf.txmode.offloads &=
11669                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11670                 cmd_reconfig_device_queue(port_id, 1, 1);
11671                 break;
11672         case -ENODEV:
11673                 printf("invalid port_id %d\n", port_id);
11674                 break;
11675         case -ENOTSUP:
11676                 printf("not supported on port %d\n", port_id);
11677                 break;
11678         default:
11679                 printf("programming error: (%s)\n", strerror(-ret));
11680         }
11681 }
11682
11683 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11684         .f = cmd_set_macsec_offload_off_parsed,
11685         .data = NULL,
11686         .help_str = "set macsec offload <port_id> off",
11687         .tokens = {
11688                 (void *)&cmd_macsec_offload_off_set,
11689                 (void *)&cmd_macsec_offload_off_macsec,
11690                 (void *)&cmd_macsec_offload_off_offload,
11691                 (void *)&cmd_macsec_offload_off_port_id,
11692                 (void *)&cmd_macsec_offload_off_off,
11693                 NULL,
11694         },
11695 };
11696
11697 /* Common result structure for MACsec secure connection configure */
11698 struct cmd_macsec_sc_result {
11699         cmdline_fixed_string_t set;
11700         cmdline_fixed_string_t macsec;
11701         cmdline_fixed_string_t sc;
11702         cmdline_fixed_string_t tx_rx;
11703         portid_t port_id;
11704         struct rte_ether_addr mac;
11705         uint16_t pi;
11706 };
11707
11708 /* Common CLI fields for MACsec secure connection configure */
11709 cmdline_parse_token_string_t cmd_macsec_sc_set =
11710         TOKEN_STRING_INITIALIZER
11711                 (struct cmd_macsec_sc_result,
11712                  set, "set");
11713 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11714         TOKEN_STRING_INITIALIZER
11715                 (struct cmd_macsec_sc_result,
11716                  macsec, "macsec");
11717 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11718         TOKEN_STRING_INITIALIZER
11719                 (struct cmd_macsec_sc_result,
11720                  sc, "sc");
11721 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11722         TOKEN_STRING_INITIALIZER
11723                 (struct cmd_macsec_sc_result,
11724                  tx_rx, "tx#rx");
11725 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11726         TOKEN_NUM_INITIALIZER
11727                 (struct cmd_macsec_sc_result,
11728                  port_id, RTE_UINT16);
11729 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11730         TOKEN_ETHERADDR_INITIALIZER
11731                 (struct cmd_macsec_sc_result,
11732                  mac);
11733 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11734         TOKEN_NUM_INITIALIZER
11735                 (struct cmd_macsec_sc_result,
11736                  pi, RTE_UINT16);
11737
11738 static void
11739 cmd_set_macsec_sc_parsed(
11740         void *parsed_result,
11741         __rte_unused struct cmdline *cl,
11742         __rte_unused void *data)
11743 {
11744         struct cmd_macsec_sc_result *res = parsed_result;
11745         int ret = -ENOTSUP;
11746         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11747
11748 #ifdef RTE_NET_IXGBE
11749         ret = is_tx ?
11750                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11751                                 res->mac.addr_bytes) :
11752                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11753                                 res->mac.addr_bytes, res->pi);
11754 #endif
11755         RTE_SET_USED(is_tx);
11756
11757         switch (ret) {
11758         case 0:
11759                 break;
11760         case -ENODEV:
11761                 printf("invalid port_id %d\n", res->port_id);
11762                 break;
11763         case -ENOTSUP:
11764                 printf("not supported on port %d\n", res->port_id);
11765                 break;
11766         default:
11767                 printf("programming error: (%s)\n", strerror(-ret));
11768         }
11769 }
11770
11771 cmdline_parse_inst_t cmd_set_macsec_sc = {
11772         .f = cmd_set_macsec_sc_parsed,
11773         .data = NULL,
11774         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11775         .tokens = {
11776                 (void *)&cmd_macsec_sc_set,
11777                 (void *)&cmd_macsec_sc_macsec,
11778                 (void *)&cmd_macsec_sc_sc,
11779                 (void *)&cmd_macsec_sc_tx_rx,
11780                 (void *)&cmd_macsec_sc_port_id,
11781                 (void *)&cmd_macsec_sc_mac,
11782                 (void *)&cmd_macsec_sc_pi,
11783                 NULL,
11784         },
11785 };
11786
11787 /* Common result structure for MACsec secure connection configure */
11788 struct cmd_macsec_sa_result {
11789         cmdline_fixed_string_t set;
11790         cmdline_fixed_string_t macsec;
11791         cmdline_fixed_string_t sa;
11792         cmdline_fixed_string_t tx_rx;
11793         portid_t port_id;
11794         uint8_t idx;
11795         uint8_t an;
11796         uint32_t pn;
11797         cmdline_fixed_string_t key;
11798 };
11799
11800 /* Common CLI fields for MACsec secure connection configure */
11801 cmdline_parse_token_string_t cmd_macsec_sa_set =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_macsec_sa_result,
11804                  set, "set");
11805 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_macsec_sa_result,
11808                  macsec, "macsec");
11809 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_macsec_sa_result,
11812                  sa, "sa");
11813 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_macsec_sa_result,
11816                  tx_rx, "tx#rx");
11817 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11818         TOKEN_NUM_INITIALIZER
11819                 (struct cmd_macsec_sa_result,
11820                  port_id, RTE_UINT16);
11821 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11822         TOKEN_NUM_INITIALIZER
11823                 (struct cmd_macsec_sa_result,
11824                  idx, RTE_UINT8);
11825 cmdline_parse_token_num_t cmd_macsec_sa_an =
11826         TOKEN_NUM_INITIALIZER
11827                 (struct cmd_macsec_sa_result,
11828                  an, RTE_UINT8);
11829 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11830         TOKEN_NUM_INITIALIZER
11831                 (struct cmd_macsec_sa_result,
11832                  pn, RTE_UINT32);
11833 cmdline_parse_token_string_t cmd_macsec_sa_key =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_macsec_sa_result,
11836                  key, NULL);
11837
11838 static void
11839 cmd_set_macsec_sa_parsed(
11840         void *parsed_result,
11841         __rte_unused struct cmdline *cl,
11842         __rte_unused void *data)
11843 {
11844         struct cmd_macsec_sa_result *res = parsed_result;
11845         int ret = -ENOTSUP;
11846         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11847         uint8_t key[16] = { 0 };
11848         uint8_t xdgt0;
11849         uint8_t xdgt1;
11850         int key_len;
11851         int i;
11852
11853         key_len = strlen(res->key) / 2;
11854         if (key_len > 16)
11855                 key_len = 16;
11856
11857         for (i = 0; i < key_len; i++) {
11858                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11859                 if (xdgt0 == 0xFF)
11860                         return;
11861                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11862                 if (xdgt1 == 0xFF)
11863                         return;
11864                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11865         }
11866
11867 #ifdef RTE_NET_IXGBE
11868         ret = is_tx ?
11869                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11870                         res->idx, res->an, res->pn, key) :
11871                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11872                         res->idx, res->an, res->pn, key);
11873 #endif
11874         RTE_SET_USED(is_tx);
11875         RTE_SET_USED(key);
11876
11877         switch (ret) {
11878         case 0:
11879                 break;
11880         case -EINVAL:
11881                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11882                 break;
11883         case -ENODEV:
11884                 printf("invalid port_id %d\n", res->port_id);
11885                 break;
11886         case -ENOTSUP:
11887                 printf("not supported on port %d\n", res->port_id);
11888                 break;
11889         default:
11890                 printf("programming error: (%s)\n", strerror(-ret));
11891         }
11892 }
11893
11894 cmdline_parse_inst_t cmd_set_macsec_sa = {
11895         .f = cmd_set_macsec_sa_parsed,
11896         .data = NULL,
11897         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11898         .tokens = {
11899                 (void *)&cmd_macsec_sa_set,
11900                 (void *)&cmd_macsec_sa_macsec,
11901                 (void *)&cmd_macsec_sa_sa,
11902                 (void *)&cmd_macsec_sa_tx_rx,
11903                 (void *)&cmd_macsec_sa_port_id,
11904                 (void *)&cmd_macsec_sa_idx,
11905                 (void *)&cmd_macsec_sa_an,
11906                 (void *)&cmd_macsec_sa_pn,
11907                 (void *)&cmd_macsec_sa_key,
11908                 NULL,
11909         },
11910 };
11911
11912 /* VF unicast promiscuous mode configuration */
11913
11914 /* Common result structure for VF unicast promiscuous mode */
11915 struct cmd_vf_promisc_result {
11916         cmdline_fixed_string_t set;
11917         cmdline_fixed_string_t vf;
11918         cmdline_fixed_string_t promisc;
11919         portid_t port_id;
11920         uint32_t vf_id;
11921         cmdline_fixed_string_t on_off;
11922 };
11923
11924 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11925 cmdline_parse_token_string_t cmd_vf_promisc_set =
11926         TOKEN_STRING_INITIALIZER
11927                 (struct cmd_vf_promisc_result,
11928                  set, "set");
11929 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11930         TOKEN_STRING_INITIALIZER
11931                 (struct cmd_vf_promisc_result,
11932                  vf, "vf");
11933 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11934         TOKEN_STRING_INITIALIZER
11935                 (struct cmd_vf_promisc_result,
11936                  promisc, "promisc");
11937 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11938         TOKEN_NUM_INITIALIZER
11939                 (struct cmd_vf_promisc_result,
11940                  port_id, RTE_UINT16);
11941 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11942         TOKEN_NUM_INITIALIZER
11943                 (struct cmd_vf_promisc_result,
11944                  vf_id, RTE_UINT32);
11945 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11946         TOKEN_STRING_INITIALIZER
11947                 (struct cmd_vf_promisc_result,
11948                  on_off, "on#off");
11949
11950 static void
11951 cmd_set_vf_promisc_parsed(
11952         void *parsed_result,
11953         __rte_unused struct cmdline *cl,
11954         __rte_unused void *data)
11955 {
11956         struct cmd_vf_promisc_result *res = parsed_result;
11957         int ret = -ENOTSUP;
11958
11959         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11960
11961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11962                 return;
11963
11964 #ifdef RTE_NET_I40E
11965         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11966                                                   res->vf_id, is_on);
11967 #endif
11968
11969         switch (ret) {
11970         case 0:
11971                 break;
11972         case -EINVAL:
11973                 printf("invalid vf_id %d\n", res->vf_id);
11974                 break;
11975         case -ENODEV:
11976                 printf("invalid port_id %d\n", res->port_id);
11977                 break;
11978         case -ENOTSUP:
11979                 printf("function not implemented\n");
11980                 break;
11981         default:
11982                 printf("programming error: (%s)\n", strerror(-ret));
11983         }
11984 }
11985
11986 cmdline_parse_inst_t cmd_set_vf_promisc = {
11987         .f = cmd_set_vf_promisc_parsed,
11988         .data = NULL,
11989         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11990                 "Set unicast promiscuous mode for a VF from the PF",
11991         .tokens = {
11992                 (void *)&cmd_vf_promisc_set,
11993                 (void *)&cmd_vf_promisc_vf,
11994                 (void *)&cmd_vf_promisc_promisc,
11995                 (void *)&cmd_vf_promisc_port_id,
11996                 (void *)&cmd_vf_promisc_vf_id,
11997                 (void *)&cmd_vf_promisc_on_off,
11998                 NULL,
11999         },
12000 };
12001
12002 /* VF multicast promiscuous mode configuration */
12003
12004 /* Common result structure for VF multicast promiscuous mode */
12005 struct cmd_vf_allmulti_result {
12006         cmdline_fixed_string_t set;
12007         cmdline_fixed_string_t vf;
12008         cmdline_fixed_string_t allmulti;
12009         portid_t port_id;
12010         uint32_t vf_id;
12011         cmdline_fixed_string_t on_off;
12012 };
12013
12014 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12015 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_vf_allmulti_result,
12018                  set, "set");
12019 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12020         TOKEN_STRING_INITIALIZER
12021                 (struct cmd_vf_allmulti_result,
12022                  vf, "vf");
12023 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_vf_allmulti_result,
12026                  allmulti, "allmulti");
12027 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12028         TOKEN_NUM_INITIALIZER
12029                 (struct cmd_vf_allmulti_result,
12030                  port_id, RTE_UINT16);
12031 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12032         TOKEN_NUM_INITIALIZER
12033                 (struct cmd_vf_allmulti_result,
12034                  vf_id, RTE_UINT32);
12035 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12036         TOKEN_STRING_INITIALIZER
12037                 (struct cmd_vf_allmulti_result,
12038                  on_off, "on#off");
12039
12040 static void
12041 cmd_set_vf_allmulti_parsed(
12042         void *parsed_result,
12043         __rte_unused struct cmdline *cl,
12044         __rte_unused void *data)
12045 {
12046         struct cmd_vf_allmulti_result *res = parsed_result;
12047         int ret = -ENOTSUP;
12048
12049         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12050
12051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12052                 return;
12053
12054 #ifdef RTE_NET_I40E
12055         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12056                                                     res->vf_id, is_on);
12057 #endif
12058
12059         switch (ret) {
12060         case 0:
12061                 break;
12062         case -EINVAL:
12063                 printf("invalid vf_id %d\n", res->vf_id);
12064                 break;
12065         case -ENODEV:
12066                 printf("invalid port_id %d\n", res->port_id);
12067                 break;
12068         case -ENOTSUP:
12069                 printf("function not implemented\n");
12070                 break;
12071         default:
12072                 printf("programming error: (%s)\n", strerror(-ret));
12073         }
12074 }
12075
12076 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12077         .f = cmd_set_vf_allmulti_parsed,
12078         .data = NULL,
12079         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12080                 "Set multicast promiscuous mode for a VF from the PF",
12081         .tokens = {
12082                 (void *)&cmd_vf_allmulti_set,
12083                 (void *)&cmd_vf_allmulti_vf,
12084                 (void *)&cmd_vf_allmulti_allmulti,
12085                 (void *)&cmd_vf_allmulti_port_id,
12086                 (void *)&cmd_vf_allmulti_vf_id,
12087                 (void *)&cmd_vf_allmulti_on_off,
12088                 NULL,
12089         },
12090 };
12091
12092 /* vf broadcast mode configuration */
12093
12094 /* Common result structure for vf broadcast */
12095 struct cmd_set_vf_broadcast_result {
12096         cmdline_fixed_string_t set;
12097         cmdline_fixed_string_t vf;
12098         cmdline_fixed_string_t broadcast;
12099         portid_t port_id;
12100         uint16_t vf_id;
12101         cmdline_fixed_string_t on_off;
12102 };
12103
12104 /* Common CLI fields for vf broadcast enable disable */
12105 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12106         TOKEN_STRING_INITIALIZER
12107                 (struct cmd_set_vf_broadcast_result,
12108                  set, "set");
12109 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12110         TOKEN_STRING_INITIALIZER
12111                 (struct cmd_set_vf_broadcast_result,
12112                  vf, "vf");
12113 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12114         TOKEN_STRING_INITIALIZER
12115                 (struct cmd_set_vf_broadcast_result,
12116                  broadcast, "broadcast");
12117 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12118         TOKEN_NUM_INITIALIZER
12119                 (struct cmd_set_vf_broadcast_result,
12120                  port_id, RTE_UINT16);
12121 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12122         TOKEN_NUM_INITIALIZER
12123                 (struct cmd_set_vf_broadcast_result,
12124                  vf_id, RTE_UINT16);
12125 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12126         TOKEN_STRING_INITIALIZER
12127                 (struct cmd_set_vf_broadcast_result,
12128                  on_off, "on#off");
12129
12130 static void
12131 cmd_set_vf_broadcast_parsed(
12132         void *parsed_result,
12133         __rte_unused struct cmdline *cl,
12134         __rte_unused void *data)
12135 {
12136         struct cmd_set_vf_broadcast_result *res = parsed_result;
12137         int ret = -ENOTSUP;
12138
12139         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12140
12141         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12142                 return;
12143
12144 #ifdef RTE_NET_I40E
12145         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12146                                             res->vf_id, is_on);
12147 #endif
12148
12149         switch (ret) {
12150         case 0:
12151                 break;
12152         case -EINVAL:
12153                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12154                 break;
12155         case -ENODEV:
12156                 printf("invalid port_id %d\n", res->port_id);
12157                 break;
12158         case -ENOTSUP:
12159                 printf("function not implemented\n");
12160                 break;
12161         default:
12162                 printf("programming error: (%s)\n", strerror(-ret));
12163         }
12164 }
12165
12166 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12167         .f = cmd_set_vf_broadcast_parsed,
12168         .data = NULL,
12169         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12170         .tokens = {
12171                 (void *)&cmd_set_vf_broadcast_set,
12172                 (void *)&cmd_set_vf_broadcast_vf,
12173                 (void *)&cmd_set_vf_broadcast_broadcast,
12174                 (void *)&cmd_set_vf_broadcast_port_id,
12175                 (void *)&cmd_set_vf_broadcast_vf_id,
12176                 (void *)&cmd_set_vf_broadcast_on_off,
12177                 NULL,
12178         },
12179 };
12180
12181 /* vf vlan tag configuration */
12182
12183 /* Common result structure for vf vlan tag */
12184 struct cmd_set_vf_vlan_tag_result {
12185         cmdline_fixed_string_t set;
12186         cmdline_fixed_string_t vf;
12187         cmdline_fixed_string_t vlan;
12188         cmdline_fixed_string_t tag;
12189         portid_t port_id;
12190         uint16_t vf_id;
12191         cmdline_fixed_string_t on_off;
12192 };
12193
12194 /* Common CLI fields for vf vlan tag enable disable */
12195 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12196         TOKEN_STRING_INITIALIZER
12197                 (struct cmd_set_vf_vlan_tag_result,
12198                  set, "set");
12199 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12200         TOKEN_STRING_INITIALIZER
12201                 (struct cmd_set_vf_vlan_tag_result,
12202                  vf, "vf");
12203 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12204         TOKEN_STRING_INITIALIZER
12205                 (struct cmd_set_vf_vlan_tag_result,
12206                  vlan, "vlan");
12207 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12208         TOKEN_STRING_INITIALIZER
12209                 (struct cmd_set_vf_vlan_tag_result,
12210                  tag, "tag");
12211 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12212         TOKEN_NUM_INITIALIZER
12213                 (struct cmd_set_vf_vlan_tag_result,
12214                  port_id, RTE_UINT16);
12215 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12216         TOKEN_NUM_INITIALIZER
12217                 (struct cmd_set_vf_vlan_tag_result,
12218                  vf_id, RTE_UINT16);
12219 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12220         TOKEN_STRING_INITIALIZER
12221                 (struct cmd_set_vf_vlan_tag_result,
12222                  on_off, "on#off");
12223
12224 static void
12225 cmd_set_vf_vlan_tag_parsed(
12226         void *parsed_result,
12227         __rte_unused struct cmdline *cl,
12228         __rte_unused void *data)
12229 {
12230         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12231         int ret = -ENOTSUP;
12232
12233         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12234
12235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12236                 return;
12237
12238 #ifdef RTE_NET_I40E
12239         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12240                                            res->vf_id, is_on);
12241 #endif
12242
12243         switch (ret) {
12244         case 0:
12245                 break;
12246         case -EINVAL:
12247                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12248                 break;
12249         case -ENODEV:
12250                 printf("invalid port_id %d\n", res->port_id);
12251                 break;
12252         case -ENOTSUP:
12253                 printf("function not implemented\n");
12254                 break;
12255         default:
12256                 printf("programming error: (%s)\n", strerror(-ret));
12257         }
12258 }
12259
12260 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12261         .f = cmd_set_vf_vlan_tag_parsed,
12262         .data = NULL,
12263         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12264         .tokens = {
12265                 (void *)&cmd_set_vf_vlan_tag_set,
12266                 (void *)&cmd_set_vf_vlan_tag_vf,
12267                 (void *)&cmd_set_vf_vlan_tag_vlan,
12268                 (void *)&cmd_set_vf_vlan_tag_tag,
12269                 (void *)&cmd_set_vf_vlan_tag_port_id,
12270                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12271                 (void *)&cmd_set_vf_vlan_tag_on_off,
12272                 NULL,
12273         },
12274 };
12275
12276 /* Common definition of VF and TC TX bandwidth configuration */
12277 struct cmd_vf_tc_bw_result {
12278         cmdline_fixed_string_t set;
12279         cmdline_fixed_string_t vf;
12280         cmdline_fixed_string_t tc;
12281         cmdline_fixed_string_t tx;
12282         cmdline_fixed_string_t min_bw;
12283         cmdline_fixed_string_t max_bw;
12284         cmdline_fixed_string_t strict_link_prio;
12285         portid_t port_id;
12286         uint16_t vf_id;
12287         uint8_t tc_no;
12288         uint32_t bw;
12289         cmdline_fixed_string_t bw_list;
12290         uint8_t tc_map;
12291 };
12292
12293 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12294         TOKEN_STRING_INITIALIZER
12295                 (struct cmd_vf_tc_bw_result,
12296                  set, "set");
12297 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12298         TOKEN_STRING_INITIALIZER
12299                 (struct cmd_vf_tc_bw_result,
12300                  vf, "vf");
12301 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12302         TOKEN_STRING_INITIALIZER
12303                 (struct cmd_vf_tc_bw_result,
12304                  tc, "tc");
12305 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12306         TOKEN_STRING_INITIALIZER
12307                 (struct cmd_vf_tc_bw_result,
12308                  tx, "tx");
12309 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12310         TOKEN_STRING_INITIALIZER
12311                 (struct cmd_vf_tc_bw_result,
12312                  strict_link_prio, "strict-link-priority");
12313 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12314         TOKEN_STRING_INITIALIZER
12315                 (struct cmd_vf_tc_bw_result,
12316                  min_bw, "min-bandwidth");
12317 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12318         TOKEN_STRING_INITIALIZER
12319                 (struct cmd_vf_tc_bw_result,
12320                  max_bw, "max-bandwidth");
12321 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12322         TOKEN_NUM_INITIALIZER
12323                 (struct cmd_vf_tc_bw_result,
12324                  port_id, RTE_UINT16);
12325 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12326         TOKEN_NUM_INITIALIZER
12327                 (struct cmd_vf_tc_bw_result,
12328                  vf_id, RTE_UINT16);
12329 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12330         TOKEN_NUM_INITIALIZER
12331                 (struct cmd_vf_tc_bw_result,
12332                  tc_no, RTE_UINT8);
12333 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12334         TOKEN_NUM_INITIALIZER
12335                 (struct cmd_vf_tc_bw_result,
12336                  bw, RTE_UINT32);
12337 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12338         TOKEN_STRING_INITIALIZER
12339                 (struct cmd_vf_tc_bw_result,
12340                  bw_list, NULL);
12341 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12342         TOKEN_NUM_INITIALIZER
12343                 (struct cmd_vf_tc_bw_result,
12344                  tc_map, RTE_UINT8);
12345
12346 /* VF max bandwidth setting */
12347 static void
12348 cmd_vf_max_bw_parsed(
12349         void *parsed_result,
12350         __rte_unused struct cmdline *cl,
12351         __rte_unused void *data)
12352 {
12353         struct cmd_vf_tc_bw_result *res = parsed_result;
12354         int ret = -ENOTSUP;
12355
12356         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12357                 return;
12358
12359 #ifdef RTE_NET_I40E
12360         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12361                                          res->vf_id, res->bw);
12362 #endif
12363
12364         switch (ret) {
12365         case 0:
12366                 break;
12367         case -EINVAL:
12368                 printf("invalid vf_id %d or bandwidth %d\n",
12369                        res->vf_id, res->bw);
12370                 break;
12371         case -ENODEV:
12372                 printf("invalid port_id %d\n", res->port_id);
12373                 break;
12374         case -ENOTSUP:
12375                 printf("function not implemented\n");
12376                 break;
12377         default:
12378                 printf("programming error: (%s)\n", strerror(-ret));
12379         }
12380 }
12381
12382 cmdline_parse_inst_t cmd_vf_max_bw = {
12383         .f = cmd_vf_max_bw_parsed,
12384         .data = NULL,
12385         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12386         .tokens = {
12387                 (void *)&cmd_vf_tc_bw_set,
12388                 (void *)&cmd_vf_tc_bw_vf,
12389                 (void *)&cmd_vf_tc_bw_tx,
12390                 (void *)&cmd_vf_tc_bw_max_bw,
12391                 (void *)&cmd_vf_tc_bw_port_id,
12392                 (void *)&cmd_vf_tc_bw_vf_id,
12393                 (void *)&cmd_vf_tc_bw_bw,
12394                 NULL,
12395         },
12396 };
12397
12398 static int
12399 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12400                            uint8_t *tc_num,
12401                            char *str)
12402 {
12403         uint32_t size;
12404         const char *p, *p0 = str;
12405         char s[256];
12406         char *end;
12407         char *str_fld[16];
12408         uint16_t i;
12409         int ret;
12410
12411         p = strchr(p0, '(');
12412         if (p == NULL) {
12413                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12414                 return -1;
12415         }
12416         p++;
12417         p0 = strchr(p, ')');
12418         if (p0 == NULL) {
12419                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12420                 return -1;
12421         }
12422         size = p0 - p;
12423         if (size >= sizeof(s)) {
12424                 printf("The string size exceeds the internal buffer size\n");
12425                 return -1;
12426         }
12427         snprintf(s, sizeof(s), "%.*s", size, p);
12428         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12429         if (ret <= 0) {
12430                 printf("Failed to get the bandwidth list. ");
12431                 return -1;
12432         }
12433         *tc_num = ret;
12434         for (i = 0; i < ret; i++)
12435                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12436
12437         return 0;
12438 }
12439
12440 /* TC min bandwidth setting */
12441 static void
12442 cmd_vf_tc_min_bw_parsed(
12443         void *parsed_result,
12444         __rte_unused struct cmdline *cl,
12445         __rte_unused void *data)
12446 {
12447         struct cmd_vf_tc_bw_result *res = parsed_result;
12448         uint8_t tc_num;
12449         uint8_t bw[16];
12450         int ret = -ENOTSUP;
12451
12452         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12453                 return;
12454
12455         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12456         if (ret)
12457                 return;
12458
12459 #ifdef RTE_NET_I40E
12460         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12461                                               tc_num, bw);
12462 #endif
12463
12464         switch (ret) {
12465         case 0:
12466                 break;
12467         case -EINVAL:
12468                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12469                 break;
12470         case -ENODEV:
12471                 printf("invalid port_id %d\n", res->port_id);
12472                 break;
12473         case -ENOTSUP:
12474                 printf("function not implemented\n");
12475                 break;
12476         default:
12477                 printf("programming error: (%s)\n", strerror(-ret));
12478         }
12479 }
12480
12481 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12482         .f = cmd_vf_tc_min_bw_parsed,
12483         .data = NULL,
12484         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12485                     " <bw1, bw2, ...>",
12486         .tokens = {
12487                 (void *)&cmd_vf_tc_bw_set,
12488                 (void *)&cmd_vf_tc_bw_vf,
12489                 (void *)&cmd_vf_tc_bw_tc,
12490                 (void *)&cmd_vf_tc_bw_tx,
12491                 (void *)&cmd_vf_tc_bw_min_bw,
12492                 (void *)&cmd_vf_tc_bw_port_id,
12493                 (void *)&cmd_vf_tc_bw_vf_id,
12494                 (void *)&cmd_vf_tc_bw_bw_list,
12495                 NULL,
12496         },
12497 };
12498
12499 static void
12500 cmd_tc_min_bw_parsed(
12501         void *parsed_result,
12502         __rte_unused struct cmdline *cl,
12503         __rte_unused void *data)
12504 {
12505         struct cmd_vf_tc_bw_result *res = parsed_result;
12506         struct rte_port *port;
12507         uint8_t tc_num;
12508         uint8_t bw[16];
12509         int ret = -ENOTSUP;
12510
12511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12512                 return;
12513
12514         port = &ports[res->port_id];
12515         /** Check if the port is not started **/
12516         if (port->port_status != RTE_PORT_STOPPED) {
12517                 printf("Please stop port %d first\n", res->port_id);
12518                 return;
12519         }
12520
12521         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12522         if (ret)
12523                 return;
12524
12525 #ifdef RTE_NET_IXGBE
12526         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12527 #endif
12528
12529         switch (ret) {
12530         case 0:
12531                 break;
12532         case -EINVAL:
12533                 printf("invalid bandwidth\n");
12534                 break;
12535         case -ENODEV:
12536                 printf("invalid port_id %d\n", res->port_id);
12537                 break;
12538         case -ENOTSUP:
12539                 printf("function not implemented\n");
12540                 break;
12541         default:
12542                 printf("programming error: (%s)\n", strerror(-ret));
12543         }
12544 }
12545
12546 cmdline_parse_inst_t cmd_tc_min_bw = {
12547         .f = cmd_tc_min_bw_parsed,
12548         .data = NULL,
12549         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12550         .tokens = {
12551                 (void *)&cmd_vf_tc_bw_set,
12552                 (void *)&cmd_vf_tc_bw_tc,
12553                 (void *)&cmd_vf_tc_bw_tx,
12554                 (void *)&cmd_vf_tc_bw_min_bw,
12555                 (void *)&cmd_vf_tc_bw_port_id,
12556                 (void *)&cmd_vf_tc_bw_bw_list,
12557                 NULL,
12558         },
12559 };
12560
12561 /* TC max bandwidth setting */
12562 static void
12563 cmd_vf_tc_max_bw_parsed(
12564         void *parsed_result,
12565         __rte_unused struct cmdline *cl,
12566         __rte_unused void *data)
12567 {
12568         struct cmd_vf_tc_bw_result *res = parsed_result;
12569         int ret = -ENOTSUP;
12570
12571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12572                 return;
12573
12574 #ifdef RTE_NET_I40E
12575         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12576                                             res->tc_no, res->bw);
12577 #endif
12578
12579         switch (ret) {
12580         case 0:
12581                 break;
12582         case -EINVAL:
12583                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12584                        res->vf_id, res->tc_no, res->bw);
12585                 break;
12586         case -ENODEV:
12587                 printf("invalid port_id %d\n", res->port_id);
12588                 break;
12589         case -ENOTSUP:
12590                 printf("function not implemented\n");
12591                 break;
12592         default:
12593                 printf("programming error: (%s)\n", strerror(-ret));
12594         }
12595 }
12596
12597 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12598         .f = cmd_vf_tc_max_bw_parsed,
12599         .data = NULL,
12600         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12601                     " <bandwidth>",
12602         .tokens = {
12603                 (void *)&cmd_vf_tc_bw_set,
12604                 (void *)&cmd_vf_tc_bw_vf,
12605                 (void *)&cmd_vf_tc_bw_tc,
12606                 (void *)&cmd_vf_tc_bw_tx,
12607                 (void *)&cmd_vf_tc_bw_max_bw,
12608                 (void *)&cmd_vf_tc_bw_port_id,
12609                 (void *)&cmd_vf_tc_bw_vf_id,
12610                 (void *)&cmd_vf_tc_bw_tc_no,
12611                 (void *)&cmd_vf_tc_bw_bw,
12612                 NULL,
12613         },
12614 };
12615
12616 /** Set VXLAN encapsulation details */
12617 struct cmd_set_vxlan_result {
12618         cmdline_fixed_string_t set;
12619         cmdline_fixed_string_t vxlan;
12620         cmdline_fixed_string_t pos_token;
12621         cmdline_fixed_string_t ip_version;
12622         uint32_t vlan_present:1;
12623         uint32_t vni;
12624         uint16_t udp_src;
12625         uint16_t udp_dst;
12626         cmdline_ipaddr_t ip_src;
12627         cmdline_ipaddr_t ip_dst;
12628         uint16_t tci;
12629         uint8_t tos;
12630         uint8_t ttl;
12631         struct rte_ether_addr eth_src;
12632         struct rte_ether_addr eth_dst;
12633 };
12634
12635 cmdline_parse_token_string_t cmd_set_vxlan_set =
12636         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12637 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12638         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12639 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12640         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12641                                  "vxlan-tos-ttl");
12642 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12643         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12644                                  "vxlan-with-vlan");
12645 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12646         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12647                                  "ip-version");
12648 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12649         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12650                                  "ipv4#ipv6");
12651 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12652         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12653                                  "vni");
12654 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12655         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12656 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12657         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12658                                  "udp-src");
12659 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12660         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12661 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12662         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12663                                  "udp-dst");
12664 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12665         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12666 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12667         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12668                                  "ip-tos");
12669 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12670         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12671 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12672         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12673                                  "ip-ttl");
12674 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12675         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12676 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12677         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12678                                  "ip-src");
12679 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12680         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12681 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12682         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12683                                  "ip-dst");
12684 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12685         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12686 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12687         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12688                                  "vlan-tci");
12689 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12690         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12691 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12692         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12693                                  "eth-src");
12694 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12695         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12696 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12697         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12698                                  "eth-dst");
12699 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12700         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12701
12702 static void cmd_set_vxlan_parsed(void *parsed_result,
12703         __rte_unused struct cmdline *cl,
12704         __rte_unused void *data)
12705 {
12706         struct cmd_set_vxlan_result *res = parsed_result;
12707         union {
12708                 uint32_t vxlan_id;
12709                 uint8_t vni[4];
12710         } id = {
12711                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12712         };
12713
12714         vxlan_encap_conf.select_tos_ttl = 0;
12715         if (strcmp(res->vxlan, "vxlan") == 0)
12716                 vxlan_encap_conf.select_vlan = 0;
12717         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12718                 vxlan_encap_conf.select_vlan = 1;
12719         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12720                 vxlan_encap_conf.select_vlan = 0;
12721                 vxlan_encap_conf.select_tos_ttl = 1;
12722         }
12723         if (strcmp(res->ip_version, "ipv4") == 0)
12724                 vxlan_encap_conf.select_ipv4 = 1;
12725         else if (strcmp(res->ip_version, "ipv6") == 0)
12726                 vxlan_encap_conf.select_ipv4 = 0;
12727         else
12728                 return;
12729         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12730         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12731         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12732         vxlan_encap_conf.ip_tos = res->tos;
12733         vxlan_encap_conf.ip_ttl = res->ttl;
12734         if (vxlan_encap_conf.select_ipv4) {
12735                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12736                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12737         } else {
12738                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12739                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12740         }
12741         if (vxlan_encap_conf.select_vlan)
12742                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12743         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12744                    RTE_ETHER_ADDR_LEN);
12745         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12746                    RTE_ETHER_ADDR_LEN);
12747 }
12748
12749 cmdline_parse_inst_t cmd_set_vxlan = {
12750         .f = cmd_set_vxlan_parsed,
12751         .data = NULL,
12752         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12753                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12754                 " eth-src <eth-src> eth-dst <eth-dst>",
12755         .tokens = {
12756                 (void *)&cmd_set_vxlan_set,
12757                 (void *)&cmd_set_vxlan_vxlan,
12758                 (void *)&cmd_set_vxlan_ip_version,
12759                 (void *)&cmd_set_vxlan_ip_version_value,
12760                 (void *)&cmd_set_vxlan_vni,
12761                 (void *)&cmd_set_vxlan_vni_value,
12762                 (void *)&cmd_set_vxlan_udp_src,
12763                 (void *)&cmd_set_vxlan_udp_src_value,
12764                 (void *)&cmd_set_vxlan_udp_dst,
12765                 (void *)&cmd_set_vxlan_udp_dst_value,
12766                 (void *)&cmd_set_vxlan_ip_src,
12767                 (void *)&cmd_set_vxlan_ip_src_value,
12768                 (void *)&cmd_set_vxlan_ip_dst,
12769                 (void *)&cmd_set_vxlan_ip_dst_value,
12770                 (void *)&cmd_set_vxlan_eth_src,
12771                 (void *)&cmd_set_vxlan_eth_src_value,
12772                 (void *)&cmd_set_vxlan_eth_dst,
12773                 (void *)&cmd_set_vxlan_eth_dst_value,
12774                 NULL,
12775         },
12776 };
12777
12778 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12779         .f = cmd_set_vxlan_parsed,
12780         .data = NULL,
12781         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12782                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12783                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12784                 " eth-dst <eth-dst>",
12785         .tokens = {
12786                 (void *)&cmd_set_vxlan_set,
12787                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12788                 (void *)&cmd_set_vxlan_ip_version,
12789                 (void *)&cmd_set_vxlan_ip_version_value,
12790                 (void *)&cmd_set_vxlan_vni,
12791                 (void *)&cmd_set_vxlan_vni_value,
12792                 (void *)&cmd_set_vxlan_udp_src,
12793                 (void *)&cmd_set_vxlan_udp_src_value,
12794                 (void *)&cmd_set_vxlan_udp_dst,
12795                 (void *)&cmd_set_vxlan_udp_dst_value,
12796                 (void *)&cmd_set_vxlan_ip_tos,
12797                 (void *)&cmd_set_vxlan_ip_tos_value,
12798                 (void *)&cmd_set_vxlan_ip_ttl,
12799                 (void *)&cmd_set_vxlan_ip_ttl_value,
12800                 (void *)&cmd_set_vxlan_ip_src,
12801                 (void *)&cmd_set_vxlan_ip_src_value,
12802                 (void *)&cmd_set_vxlan_ip_dst,
12803                 (void *)&cmd_set_vxlan_ip_dst_value,
12804                 (void *)&cmd_set_vxlan_eth_src,
12805                 (void *)&cmd_set_vxlan_eth_src_value,
12806                 (void *)&cmd_set_vxlan_eth_dst,
12807                 (void *)&cmd_set_vxlan_eth_dst_value,
12808                 NULL,
12809         },
12810 };
12811
12812 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12813         .f = cmd_set_vxlan_parsed,
12814         .data = NULL,
12815         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12816                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12817                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12818                 " <eth-dst>",
12819         .tokens = {
12820                 (void *)&cmd_set_vxlan_set,
12821                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12822                 (void *)&cmd_set_vxlan_ip_version,
12823                 (void *)&cmd_set_vxlan_ip_version_value,
12824                 (void *)&cmd_set_vxlan_vni,
12825                 (void *)&cmd_set_vxlan_vni_value,
12826                 (void *)&cmd_set_vxlan_udp_src,
12827                 (void *)&cmd_set_vxlan_udp_src_value,
12828                 (void *)&cmd_set_vxlan_udp_dst,
12829                 (void *)&cmd_set_vxlan_udp_dst_value,
12830                 (void *)&cmd_set_vxlan_ip_src,
12831                 (void *)&cmd_set_vxlan_ip_src_value,
12832                 (void *)&cmd_set_vxlan_ip_dst,
12833                 (void *)&cmd_set_vxlan_ip_dst_value,
12834                 (void *)&cmd_set_vxlan_vlan,
12835                 (void *)&cmd_set_vxlan_vlan_value,
12836                 (void *)&cmd_set_vxlan_eth_src,
12837                 (void *)&cmd_set_vxlan_eth_src_value,
12838                 (void *)&cmd_set_vxlan_eth_dst,
12839                 (void *)&cmd_set_vxlan_eth_dst_value,
12840                 NULL,
12841         },
12842 };
12843
12844 /** Set NVGRE encapsulation details */
12845 struct cmd_set_nvgre_result {
12846         cmdline_fixed_string_t set;
12847         cmdline_fixed_string_t nvgre;
12848         cmdline_fixed_string_t pos_token;
12849         cmdline_fixed_string_t ip_version;
12850         uint32_t tni;
12851         cmdline_ipaddr_t ip_src;
12852         cmdline_ipaddr_t ip_dst;
12853         uint16_t tci;
12854         struct rte_ether_addr eth_src;
12855         struct rte_ether_addr eth_dst;
12856 };
12857
12858 cmdline_parse_token_string_t cmd_set_nvgre_set =
12859         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12860 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12861         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12862 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12863         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12864                                  "nvgre-with-vlan");
12865 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12866         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12867                                  "ip-version");
12868 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12869         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12870                                  "ipv4#ipv6");
12871 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12872         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12873                                  "tni");
12874 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12875         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12876 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12877         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12878                                  "ip-src");
12879 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12880         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12881 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12882         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12883                                  "ip-dst");
12884 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12885         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12886 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12887         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12888                                  "vlan-tci");
12889 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12890         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12891 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12892         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12893                                  "eth-src");
12894 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12895         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12896 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12897         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12898                                  "eth-dst");
12899 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12900         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12901
12902 static void cmd_set_nvgre_parsed(void *parsed_result,
12903         __rte_unused struct cmdline *cl,
12904         __rte_unused void *data)
12905 {
12906         struct cmd_set_nvgre_result *res = parsed_result;
12907         union {
12908                 uint32_t nvgre_tni;
12909                 uint8_t tni[4];
12910         } id = {
12911                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12912         };
12913
12914         if (strcmp(res->nvgre, "nvgre") == 0)
12915                 nvgre_encap_conf.select_vlan = 0;
12916         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12917                 nvgre_encap_conf.select_vlan = 1;
12918         if (strcmp(res->ip_version, "ipv4") == 0)
12919                 nvgre_encap_conf.select_ipv4 = 1;
12920         else if (strcmp(res->ip_version, "ipv6") == 0)
12921                 nvgre_encap_conf.select_ipv4 = 0;
12922         else
12923                 return;
12924         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12925         if (nvgre_encap_conf.select_ipv4) {
12926                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12927                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12928         } else {
12929                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12930                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12931         }
12932         if (nvgre_encap_conf.select_vlan)
12933                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12934         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12935                    RTE_ETHER_ADDR_LEN);
12936         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12937                    RTE_ETHER_ADDR_LEN);
12938 }
12939
12940 cmdline_parse_inst_t cmd_set_nvgre = {
12941         .f = cmd_set_nvgre_parsed,
12942         .data = NULL,
12943         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12944                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12945                 " eth-dst <eth-dst>",
12946         .tokens = {
12947                 (void *)&cmd_set_nvgre_set,
12948                 (void *)&cmd_set_nvgre_nvgre,
12949                 (void *)&cmd_set_nvgre_ip_version,
12950                 (void *)&cmd_set_nvgre_ip_version_value,
12951                 (void *)&cmd_set_nvgre_tni,
12952                 (void *)&cmd_set_nvgre_tni_value,
12953                 (void *)&cmd_set_nvgre_ip_src,
12954                 (void *)&cmd_set_nvgre_ip_src_value,
12955                 (void *)&cmd_set_nvgre_ip_dst,
12956                 (void *)&cmd_set_nvgre_ip_dst_value,
12957                 (void *)&cmd_set_nvgre_eth_src,
12958                 (void *)&cmd_set_nvgre_eth_src_value,
12959                 (void *)&cmd_set_nvgre_eth_dst,
12960                 (void *)&cmd_set_nvgre_eth_dst_value,
12961                 NULL,
12962         },
12963 };
12964
12965 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12966         .f = cmd_set_nvgre_parsed,
12967         .data = NULL,
12968         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12969                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12970                 " eth-src <eth-src> eth-dst <eth-dst>",
12971         .tokens = {
12972                 (void *)&cmd_set_nvgre_set,
12973                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12974                 (void *)&cmd_set_nvgre_ip_version,
12975                 (void *)&cmd_set_nvgre_ip_version_value,
12976                 (void *)&cmd_set_nvgre_tni,
12977                 (void *)&cmd_set_nvgre_tni_value,
12978                 (void *)&cmd_set_nvgre_ip_src,
12979                 (void *)&cmd_set_nvgre_ip_src_value,
12980                 (void *)&cmd_set_nvgre_ip_dst,
12981                 (void *)&cmd_set_nvgre_ip_dst_value,
12982                 (void *)&cmd_set_nvgre_vlan,
12983                 (void *)&cmd_set_nvgre_vlan_value,
12984                 (void *)&cmd_set_nvgre_eth_src,
12985                 (void *)&cmd_set_nvgre_eth_src_value,
12986                 (void *)&cmd_set_nvgre_eth_dst,
12987                 (void *)&cmd_set_nvgre_eth_dst_value,
12988                 NULL,
12989         },
12990 };
12991
12992 /** Set L2 encapsulation details */
12993 struct cmd_set_l2_encap_result {
12994         cmdline_fixed_string_t set;
12995         cmdline_fixed_string_t l2_encap;
12996         cmdline_fixed_string_t pos_token;
12997         cmdline_fixed_string_t ip_version;
12998         uint32_t vlan_present:1;
12999         uint16_t tci;
13000         struct rte_ether_addr eth_src;
13001         struct rte_ether_addr eth_dst;
13002 };
13003
13004 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13005         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13006 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13007         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13008 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13009         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13010                                  "l2_encap-with-vlan");
13011 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13012         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13013                                  "ip-version");
13014 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13015         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13016                                  "ipv4#ipv6");
13017 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13018         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13019                                  "vlan-tci");
13020 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13021         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13022 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13023         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13024                                  "eth-src");
13025 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13026         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13027 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13028         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13029                                  "eth-dst");
13030 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13031         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13032
13033 static void cmd_set_l2_encap_parsed(void *parsed_result,
13034         __rte_unused struct cmdline *cl,
13035         __rte_unused void *data)
13036 {
13037         struct cmd_set_l2_encap_result *res = parsed_result;
13038
13039         if (strcmp(res->l2_encap, "l2_encap") == 0)
13040                 l2_encap_conf.select_vlan = 0;
13041         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13042                 l2_encap_conf.select_vlan = 1;
13043         if (strcmp(res->ip_version, "ipv4") == 0)
13044                 l2_encap_conf.select_ipv4 = 1;
13045         else if (strcmp(res->ip_version, "ipv6") == 0)
13046                 l2_encap_conf.select_ipv4 = 0;
13047         else
13048                 return;
13049         if (l2_encap_conf.select_vlan)
13050                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13051         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13052                    RTE_ETHER_ADDR_LEN);
13053         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13054                    RTE_ETHER_ADDR_LEN);
13055 }
13056
13057 cmdline_parse_inst_t cmd_set_l2_encap = {
13058         .f = cmd_set_l2_encap_parsed,
13059         .data = NULL,
13060         .help_str = "set l2_encap ip-version ipv4|ipv6"
13061                 " eth-src <eth-src> eth-dst <eth-dst>",
13062         .tokens = {
13063                 (void *)&cmd_set_l2_encap_set,
13064                 (void *)&cmd_set_l2_encap_l2_encap,
13065                 (void *)&cmd_set_l2_encap_ip_version,
13066                 (void *)&cmd_set_l2_encap_ip_version_value,
13067                 (void *)&cmd_set_l2_encap_eth_src,
13068                 (void *)&cmd_set_l2_encap_eth_src_value,
13069                 (void *)&cmd_set_l2_encap_eth_dst,
13070                 (void *)&cmd_set_l2_encap_eth_dst_value,
13071                 NULL,
13072         },
13073 };
13074
13075 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13076         .f = cmd_set_l2_encap_parsed,
13077         .data = NULL,
13078         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13079                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13080         .tokens = {
13081                 (void *)&cmd_set_l2_encap_set,
13082                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13083                 (void *)&cmd_set_l2_encap_ip_version,
13084                 (void *)&cmd_set_l2_encap_ip_version_value,
13085                 (void *)&cmd_set_l2_encap_vlan,
13086                 (void *)&cmd_set_l2_encap_vlan_value,
13087                 (void *)&cmd_set_l2_encap_eth_src,
13088                 (void *)&cmd_set_l2_encap_eth_src_value,
13089                 (void *)&cmd_set_l2_encap_eth_dst,
13090                 (void *)&cmd_set_l2_encap_eth_dst_value,
13091                 NULL,
13092         },
13093 };
13094
13095 /** Set L2 decapsulation details */
13096 struct cmd_set_l2_decap_result {
13097         cmdline_fixed_string_t set;
13098         cmdline_fixed_string_t l2_decap;
13099         cmdline_fixed_string_t pos_token;
13100         uint32_t vlan_present:1;
13101 };
13102
13103 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13104         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13105 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13106         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13107                                  "l2_decap");
13108 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13109         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13110                                  "l2_decap-with-vlan");
13111
13112 static void cmd_set_l2_decap_parsed(void *parsed_result,
13113         __rte_unused struct cmdline *cl,
13114         __rte_unused void *data)
13115 {
13116         struct cmd_set_l2_decap_result *res = parsed_result;
13117
13118         if (strcmp(res->l2_decap, "l2_decap") == 0)
13119                 l2_decap_conf.select_vlan = 0;
13120         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13121                 l2_decap_conf.select_vlan = 1;
13122 }
13123
13124 cmdline_parse_inst_t cmd_set_l2_decap = {
13125         .f = cmd_set_l2_decap_parsed,
13126         .data = NULL,
13127         .help_str = "set l2_decap",
13128         .tokens = {
13129                 (void *)&cmd_set_l2_decap_set,
13130                 (void *)&cmd_set_l2_decap_l2_decap,
13131                 NULL,
13132         },
13133 };
13134
13135 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13136         .f = cmd_set_l2_decap_parsed,
13137         .data = NULL,
13138         .help_str = "set l2_decap-with-vlan",
13139         .tokens = {
13140                 (void *)&cmd_set_l2_decap_set,
13141                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13142                 NULL,
13143         },
13144 };
13145
13146 /** Set MPLSoGRE encapsulation details */
13147 struct cmd_set_mplsogre_encap_result {
13148         cmdline_fixed_string_t set;
13149         cmdline_fixed_string_t mplsogre;
13150         cmdline_fixed_string_t pos_token;
13151         cmdline_fixed_string_t ip_version;
13152         uint32_t vlan_present:1;
13153         uint32_t label;
13154         cmdline_ipaddr_t ip_src;
13155         cmdline_ipaddr_t ip_dst;
13156         uint16_t tci;
13157         struct rte_ether_addr eth_src;
13158         struct rte_ether_addr eth_dst;
13159 };
13160
13161 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13162         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13163                                  "set");
13164 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13165         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13166                                  "mplsogre_encap");
13167 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13168         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13169                                  mplsogre, "mplsogre_encap-with-vlan");
13170 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13171         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13172                                  pos_token, "ip-version");
13173 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13174         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13175                                  ip_version, "ipv4#ipv6");
13176 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13177         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13178                                  pos_token, "label");
13179 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13180         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13181                               RTE_UINT32);
13182 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13183         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13184                                  pos_token, "ip-src");
13185 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13186         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13187 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13188         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13189                                  pos_token, "ip-dst");
13190 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13191         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13192 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13193         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13194                                  pos_token, "vlan-tci");
13195 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13196         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13197                               RTE_UINT16);
13198 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13200                                  pos_token, "eth-src");
13201 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13202         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13203                                     eth_src);
13204 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13205         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13206                                  pos_token, "eth-dst");
13207 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13209                                     eth_dst);
13210
13211 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13212         __rte_unused struct cmdline *cl,
13213         __rte_unused void *data)
13214 {
13215         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13216         union {
13217                 uint32_t mplsogre_label;
13218                 uint8_t label[4];
13219         } id = {
13220                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13221         };
13222
13223         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13224                 mplsogre_encap_conf.select_vlan = 0;
13225         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13226                 mplsogre_encap_conf.select_vlan = 1;
13227         if (strcmp(res->ip_version, "ipv4") == 0)
13228                 mplsogre_encap_conf.select_ipv4 = 1;
13229         else if (strcmp(res->ip_version, "ipv6") == 0)
13230                 mplsogre_encap_conf.select_ipv4 = 0;
13231         else
13232                 return;
13233         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13234         if (mplsogre_encap_conf.select_ipv4) {
13235                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13236                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13237         } else {
13238                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13239                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13240         }
13241         if (mplsogre_encap_conf.select_vlan)
13242                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13243         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13244                    RTE_ETHER_ADDR_LEN);
13245         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13246                    RTE_ETHER_ADDR_LEN);
13247 }
13248
13249 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13250         .f = cmd_set_mplsogre_encap_parsed,
13251         .data = NULL,
13252         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13253                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13254                 " eth-dst <eth-dst>",
13255         .tokens = {
13256                 (void *)&cmd_set_mplsogre_encap_set,
13257                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13258                 (void *)&cmd_set_mplsogre_encap_ip_version,
13259                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13260                 (void *)&cmd_set_mplsogre_encap_label,
13261                 (void *)&cmd_set_mplsogre_encap_label_value,
13262                 (void *)&cmd_set_mplsogre_encap_ip_src,
13263                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13264                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13265                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13266                 (void *)&cmd_set_mplsogre_encap_eth_src,
13267                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13268                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13269                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13270                 NULL,
13271         },
13272 };
13273
13274 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13275         .f = cmd_set_mplsogre_encap_parsed,
13276         .data = NULL,
13277         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13278                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13279                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13280         .tokens = {
13281                 (void *)&cmd_set_mplsogre_encap_set,
13282                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13283                 (void *)&cmd_set_mplsogre_encap_ip_version,
13284                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13285                 (void *)&cmd_set_mplsogre_encap_label,
13286                 (void *)&cmd_set_mplsogre_encap_label_value,
13287                 (void *)&cmd_set_mplsogre_encap_ip_src,
13288                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13289                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13290                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13291                 (void *)&cmd_set_mplsogre_encap_vlan,
13292                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13293                 (void *)&cmd_set_mplsogre_encap_eth_src,
13294                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13295                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13296                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13297                 NULL,
13298         },
13299 };
13300
13301 /** Set MPLSoGRE decapsulation details */
13302 struct cmd_set_mplsogre_decap_result {
13303         cmdline_fixed_string_t set;
13304         cmdline_fixed_string_t mplsogre;
13305         cmdline_fixed_string_t pos_token;
13306         cmdline_fixed_string_t ip_version;
13307         uint32_t vlan_present:1;
13308 };
13309
13310 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13311         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13312                                  "set");
13313 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13314         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13315                                  "mplsogre_decap");
13316 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13317         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13318                                  mplsogre, "mplsogre_decap-with-vlan");
13319 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13320         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13321                                  pos_token, "ip-version");
13322 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13323         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13324                                  ip_version, "ipv4#ipv6");
13325
13326 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13327         __rte_unused struct cmdline *cl,
13328         __rte_unused void *data)
13329 {
13330         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13331
13332         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13333                 mplsogre_decap_conf.select_vlan = 0;
13334         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13335                 mplsogre_decap_conf.select_vlan = 1;
13336         if (strcmp(res->ip_version, "ipv4") == 0)
13337                 mplsogre_decap_conf.select_ipv4 = 1;
13338         else if (strcmp(res->ip_version, "ipv6") == 0)
13339                 mplsogre_decap_conf.select_ipv4 = 0;
13340 }
13341
13342 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13343         .f = cmd_set_mplsogre_decap_parsed,
13344         .data = NULL,
13345         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13346         .tokens = {
13347                 (void *)&cmd_set_mplsogre_decap_set,
13348                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13349                 (void *)&cmd_set_mplsogre_decap_ip_version,
13350                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13351                 NULL,
13352         },
13353 };
13354
13355 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13356         .f = cmd_set_mplsogre_decap_parsed,
13357         .data = NULL,
13358         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13359         .tokens = {
13360                 (void *)&cmd_set_mplsogre_decap_set,
13361                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13362                 (void *)&cmd_set_mplsogre_decap_ip_version,
13363                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13364                 NULL,
13365         },
13366 };
13367
13368 /** Set MPLSoUDP encapsulation details */
13369 struct cmd_set_mplsoudp_encap_result {
13370         cmdline_fixed_string_t set;
13371         cmdline_fixed_string_t mplsoudp;
13372         cmdline_fixed_string_t pos_token;
13373         cmdline_fixed_string_t ip_version;
13374         uint32_t vlan_present:1;
13375         uint32_t label;
13376         uint16_t udp_src;
13377         uint16_t udp_dst;
13378         cmdline_ipaddr_t ip_src;
13379         cmdline_ipaddr_t ip_dst;
13380         uint16_t tci;
13381         struct rte_ether_addr eth_src;
13382         struct rte_ether_addr eth_dst;
13383 };
13384
13385 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13386         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13387                                  "set");
13388 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13389         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13390                                  "mplsoudp_encap");
13391 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13392         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13393                                  mplsoudp, "mplsoudp_encap-with-vlan");
13394 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13395         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13396                                  pos_token, "ip-version");
13397 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13398         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13399                                  ip_version, "ipv4#ipv6");
13400 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13401         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13402                                  pos_token, "label");
13403 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13404         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13405                               RTE_UINT32);
13406 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13407         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13408                                  pos_token, "udp-src");
13409 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13410         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13411                               RTE_UINT16);
13412 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13413         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13414                                  pos_token, "udp-dst");
13415 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13416         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13417                               RTE_UINT16);
13418 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13419         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13420                                  pos_token, "ip-src");
13421 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13422         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13423 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13424         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13425                                  pos_token, "ip-dst");
13426 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13427         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13428 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13429         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13430                                  pos_token, "vlan-tci");
13431 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13432         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13433                               RTE_UINT16);
13434 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13435         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13436                                  pos_token, "eth-src");
13437 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13438         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13439                                     eth_src);
13440 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13441         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13442                                  pos_token, "eth-dst");
13443 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13444         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13445                                     eth_dst);
13446
13447 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13448         __rte_unused struct cmdline *cl,
13449         __rte_unused void *data)
13450 {
13451         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13452         union {
13453                 uint32_t mplsoudp_label;
13454                 uint8_t label[4];
13455         } id = {
13456                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13457         };
13458
13459         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13460                 mplsoudp_encap_conf.select_vlan = 0;
13461         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13462                 mplsoudp_encap_conf.select_vlan = 1;
13463         if (strcmp(res->ip_version, "ipv4") == 0)
13464                 mplsoudp_encap_conf.select_ipv4 = 1;
13465         else if (strcmp(res->ip_version, "ipv6") == 0)
13466                 mplsoudp_encap_conf.select_ipv4 = 0;
13467         else
13468                 return;
13469         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13470         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13471         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13472         if (mplsoudp_encap_conf.select_ipv4) {
13473                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13474                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13475         } else {
13476                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13477                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13478         }
13479         if (mplsoudp_encap_conf.select_vlan)
13480                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13481         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13482                    RTE_ETHER_ADDR_LEN);
13483         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13484                    RTE_ETHER_ADDR_LEN);
13485 }
13486
13487 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13488         .f = cmd_set_mplsoudp_encap_parsed,
13489         .data = NULL,
13490         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13491                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13492                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13493         .tokens = {
13494                 (void *)&cmd_set_mplsoudp_encap_set,
13495                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13496                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13497                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13498                 (void *)&cmd_set_mplsoudp_encap_label,
13499                 (void *)&cmd_set_mplsoudp_encap_label_value,
13500                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13501                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13502                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13503                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13504                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13505                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13506                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13507                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13508                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13509                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13510                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13511                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13512                 NULL,
13513         },
13514 };
13515
13516 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13517         .f = cmd_set_mplsoudp_encap_parsed,
13518         .data = NULL,
13519         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13520                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13521                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13522                 " eth-src <eth-src> eth-dst <eth-dst>",
13523         .tokens = {
13524                 (void *)&cmd_set_mplsoudp_encap_set,
13525                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13526                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13527                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13528                 (void *)&cmd_set_mplsoudp_encap_label,
13529                 (void *)&cmd_set_mplsoudp_encap_label_value,
13530                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13531                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13532                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13533                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13534                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13535                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13536                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13537                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13538                 (void *)&cmd_set_mplsoudp_encap_vlan,
13539                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13540                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13541                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13542                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13543                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13544                 NULL,
13545         },
13546 };
13547
13548 /** Set MPLSoUDP decapsulation details */
13549 struct cmd_set_mplsoudp_decap_result {
13550         cmdline_fixed_string_t set;
13551         cmdline_fixed_string_t mplsoudp;
13552         cmdline_fixed_string_t pos_token;
13553         cmdline_fixed_string_t ip_version;
13554         uint32_t vlan_present:1;
13555 };
13556
13557 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13558         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13559                                  "set");
13560 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13561         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13562                                  "mplsoudp_decap");
13563 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13564         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13565                                  mplsoudp, "mplsoudp_decap-with-vlan");
13566 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13567         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13568                                  pos_token, "ip-version");
13569 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13570         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13571                                  ip_version, "ipv4#ipv6");
13572
13573 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13574         __rte_unused struct cmdline *cl,
13575         __rte_unused void *data)
13576 {
13577         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13578
13579         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13580                 mplsoudp_decap_conf.select_vlan = 0;
13581         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13582                 mplsoudp_decap_conf.select_vlan = 1;
13583         if (strcmp(res->ip_version, "ipv4") == 0)
13584                 mplsoudp_decap_conf.select_ipv4 = 1;
13585         else if (strcmp(res->ip_version, "ipv6") == 0)
13586                 mplsoudp_decap_conf.select_ipv4 = 0;
13587 }
13588
13589 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13590         .f = cmd_set_mplsoudp_decap_parsed,
13591         .data = NULL,
13592         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13593         .tokens = {
13594                 (void *)&cmd_set_mplsoudp_decap_set,
13595                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13596                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13597                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13598                 NULL,
13599         },
13600 };
13601
13602 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13603         .f = cmd_set_mplsoudp_decap_parsed,
13604         .data = NULL,
13605         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13606         .tokens = {
13607                 (void *)&cmd_set_mplsoudp_decap_set,
13608                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13609                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13610                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13611                 NULL,
13612         },
13613 };
13614
13615 /* Strict link priority scheduling mode setting */
13616 static void
13617 cmd_strict_link_prio_parsed(
13618         void *parsed_result,
13619         __rte_unused struct cmdline *cl,
13620         __rte_unused void *data)
13621 {
13622         struct cmd_vf_tc_bw_result *res = parsed_result;
13623         int ret = -ENOTSUP;
13624
13625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13626                 return;
13627
13628 #ifdef RTE_NET_I40E
13629         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13630 #endif
13631
13632         switch (ret) {
13633         case 0:
13634                 break;
13635         case -EINVAL:
13636                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13637                 break;
13638         case -ENODEV:
13639                 printf("invalid port_id %d\n", res->port_id);
13640                 break;
13641         case -ENOTSUP:
13642                 printf("function not implemented\n");
13643                 break;
13644         default:
13645                 printf("programming error: (%s)\n", strerror(-ret));
13646         }
13647 }
13648
13649 cmdline_parse_inst_t cmd_strict_link_prio = {
13650         .f = cmd_strict_link_prio_parsed,
13651         .data = NULL,
13652         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13653         .tokens = {
13654                 (void *)&cmd_vf_tc_bw_set,
13655                 (void *)&cmd_vf_tc_bw_tx,
13656                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13657                 (void *)&cmd_vf_tc_bw_port_id,
13658                 (void *)&cmd_vf_tc_bw_tc_map,
13659                 NULL,
13660         },
13661 };
13662
13663 /* Load dynamic device personalization*/
13664 struct cmd_ddp_add_result {
13665         cmdline_fixed_string_t ddp;
13666         cmdline_fixed_string_t add;
13667         portid_t port_id;
13668         char filepath[];
13669 };
13670
13671 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13672         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13673 cmdline_parse_token_string_t cmd_ddp_add_add =
13674         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13675 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13676         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13677                 RTE_UINT16);
13678 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13679         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13680
13681 static void
13682 cmd_ddp_add_parsed(
13683         void *parsed_result,
13684         __rte_unused struct cmdline *cl,
13685         __rte_unused void *data)
13686 {
13687         struct cmd_ddp_add_result *res = parsed_result;
13688         uint8_t *buff;
13689         uint32_t size;
13690         char *filepath;
13691         char *file_fld[2];
13692         int file_num;
13693         int ret = -ENOTSUP;
13694
13695         if (!all_ports_stopped()) {
13696                 printf("Please stop all ports first\n");
13697                 return;
13698         }
13699
13700         filepath = strdup(res->filepath);
13701         if (filepath == NULL) {
13702                 printf("Failed to allocate memory\n");
13703                 return;
13704         }
13705         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13706
13707         buff = open_file(file_fld[0], &size);
13708         if (!buff) {
13709                 free((void *)filepath);
13710                 return;
13711         }
13712
13713 #ifdef RTE_NET_I40E
13714         if (ret == -ENOTSUP)
13715                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13716                                                buff, size,
13717                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13718 #endif
13719
13720         if (ret == -EEXIST)
13721                 printf("Profile has already existed.\n");
13722         else if (ret < 0)
13723                 printf("Failed to load profile.\n");
13724         else if (file_num == 2)
13725                 save_file(file_fld[1], buff, size);
13726
13727         close_file(buff);
13728         free((void *)filepath);
13729 }
13730
13731 cmdline_parse_inst_t cmd_ddp_add = {
13732         .f = cmd_ddp_add_parsed,
13733         .data = NULL,
13734         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13735         .tokens = {
13736                 (void *)&cmd_ddp_add_ddp,
13737                 (void *)&cmd_ddp_add_add,
13738                 (void *)&cmd_ddp_add_port_id,
13739                 (void *)&cmd_ddp_add_filepath,
13740                 NULL,
13741         },
13742 };
13743
13744 /* Delete dynamic device personalization*/
13745 struct cmd_ddp_del_result {
13746         cmdline_fixed_string_t ddp;
13747         cmdline_fixed_string_t del;
13748         portid_t port_id;
13749         char filepath[];
13750 };
13751
13752 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13753         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13754 cmdline_parse_token_string_t cmd_ddp_del_del =
13755         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13756 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13757         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13758 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13759         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13760
13761 static void
13762 cmd_ddp_del_parsed(
13763         void *parsed_result,
13764         __rte_unused struct cmdline *cl,
13765         __rte_unused void *data)
13766 {
13767         struct cmd_ddp_del_result *res = parsed_result;
13768         uint8_t *buff;
13769         uint32_t size;
13770         int ret = -ENOTSUP;
13771
13772         if (!all_ports_stopped()) {
13773                 printf("Please stop all ports first\n");
13774                 return;
13775         }
13776
13777         buff = open_file(res->filepath, &size);
13778         if (!buff)
13779                 return;
13780
13781 #ifdef RTE_NET_I40E
13782         if (ret == -ENOTSUP)
13783                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13784                                                buff, size,
13785                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13786 #endif
13787
13788         if (ret == -EACCES)
13789                 printf("Profile does not exist.\n");
13790         else if (ret < 0)
13791                 printf("Failed to delete profile.\n");
13792
13793         close_file(buff);
13794 }
13795
13796 cmdline_parse_inst_t cmd_ddp_del = {
13797         .f = cmd_ddp_del_parsed,
13798         .data = NULL,
13799         .help_str = "ddp del <port_id> <backup_profile_path>",
13800         .tokens = {
13801                 (void *)&cmd_ddp_del_ddp,
13802                 (void *)&cmd_ddp_del_del,
13803                 (void *)&cmd_ddp_del_port_id,
13804                 (void *)&cmd_ddp_del_filepath,
13805                 NULL,
13806         },
13807 };
13808
13809 /* Get dynamic device personalization profile info */
13810 struct cmd_ddp_info_result {
13811         cmdline_fixed_string_t ddp;
13812         cmdline_fixed_string_t get;
13813         cmdline_fixed_string_t info;
13814         char filepath[];
13815 };
13816
13817 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13818         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13819 cmdline_parse_token_string_t cmd_ddp_info_get =
13820         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13821 cmdline_parse_token_string_t cmd_ddp_info_info =
13822         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13823 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13824         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13825
13826 static void
13827 cmd_ddp_info_parsed(
13828         void *parsed_result,
13829         __rte_unused struct cmdline *cl,
13830         __rte_unused void *data)
13831 {
13832         struct cmd_ddp_info_result *res = parsed_result;
13833         uint8_t *pkg;
13834         uint32_t pkg_size;
13835         int ret = -ENOTSUP;
13836 #ifdef RTE_NET_I40E
13837         uint32_t i, j, n;
13838         uint8_t *buff;
13839         uint32_t buff_size = 0;
13840         struct rte_pmd_i40e_profile_info info;
13841         uint32_t dev_num = 0;
13842         struct rte_pmd_i40e_ddp_device_id *devs;
13843         uint32_t proto_num = 0;
13844         struct rte_pmd_i40e_proto_info *proto = NULL;
13845         uint32_t pctype_num = 0;
13846         struct rte_pmd_i40e_ptype_info *pctype;
13847         uint32_t ptype_num = 0;
13848         struct rte_pmd_i40e_ptype_info *ptype;
13849         uint8_t proto_id;
13850
13851 #endif
13852
13853         pkg = open_file(res->filepath, &pkg_size);
13854         if (!pkg)
13855                 return;
13856
13857 #ifdef RTE_NET_I40E
13858         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13859                                 (uint8_t *)&info, sizeof(info),
13860                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13861         if (!ret) {
13862                 printf("Global Track id:       0x%x\n", info.track_id);
13863                 printf("Global Version:        %d.%d.%d.%d\n",
13864                         info.version.major,
13865                         info.version.minor,
13866                         info.version.update,
13867                         info.version.draft);
13868                 printf("Global Package name:   %s\n\n", info.name);
13869         }
13870
13871         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13872                                 (uint8_t *)&info, sizeof(info),
13873                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13874         if (!ret) {
13875                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13876                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13877                         info.version.major,
13878                         info.version.minor,
13879                         info.version.update,
13880                         info.version.draft);
13881                 printf("i40e Profile name:     %s\n\n", info.name);
13882         }
13883
13884         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13885                                 (uint8_t *)&buff_size, sizeof(buff_size),
13886                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13887         if (!ret && buff_size) {
13888                 buff = (uint8_t *)malloc(buff_size);
13889                 if (buff) {
13890                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13891                                                 buff, buff_size,
13892                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13893                         if (!ret)
13894                                 printf("Package Notes:\n%s\n\n", buff);
13895                         free(buff);
13896                 }
13897         }
13898
13899         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13900                                 (uint8_t *)&dev_num, sizeof(dev_num),
13901                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13902         if (!ret && dev_num) {
13903                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13904                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13905                 if (devs) {
13906                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13907                                                 (uint8_t *)devs, buff_size,
13908                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13909                         if (!ret) {
13910                                 printf("List of supported devices:\n");
13911                                 for (i = 0; i < dev_num; i++) {
13912                                         printf("  %04X:%04X %04X:%04X\n",
13913                                                 devs[i].vendor_dev_id >> 16,
13914                                                 devs[i].vendor_dev_id & 0xFFFF,
13915                                                 devs[i].sub_vendor_dev_id >> 16,
13916                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13917                                 }
13918                                 printf("\n");
13919                         }
13920                         free(devs);
13921                 }
13922         }
13923
13924         /* get information about protocols and packet types */
13925         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13926                 (uint8_t *)&proto_num, sizeof(proto_num),
13927                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13928         if (ret || !proto_num)
13929                 goto no_print_return;
13930
13931         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13932         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13933         if (!proto)
13934                 goto no_print_return;
13935
13936         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13937                                         buff_size,
13938                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13939         if (!ret) {
13940                 printf("List of used protocols:\n");
13941                 for (i = 0; i < proto_num; i++)
13942                         printf("  %2u: %s\n", proto[i].proto_id,
13943                                proto[i].name);
13944                 printf("\n");
13945         }
13946         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13947                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13948                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13949         if (ret || !pctype_num)
13950                 goto no_print_pctypes;
13951
13952         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13953         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13954         if (!pctype)
13955                 goto no_print_pctypes;
13956
13957         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13958                                         buff_size,
13959                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13960         if (ret) {
13961                 free(pctype);
13962                 goto no_print_pctypes;
13963         }
13964
13965         printf("List of defined packet classification types:\n");
13966         for (i = 0; i < pctype_num; i++) {
13967                 printf("  %2u:", pctype[i].ptype_id);
13968                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13969                         proto_id = pctype[i].protocols[j];
13970                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13971                                 for (n = 0; n < proto_num; n++) {
13972                                         if (proto[n].proto_id == proto_id) {
13973                                                 printf(" %s", proto[n].name);
13974                                                 break;
13975                                         }
13976                                 }
13977                         }
13978                 }
13979                 printf("\n");
13980         }
13981         printf("\n");
13982         free(pctype);
13983
13984 no_print_pctypes:
13985
13986         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13987                                         sizeof(ptype_num),
13988                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13989         if (ret || !ptype_num)
13990                 goto no_print_return;
13991
13992         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13993         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13994         if (!ptype)
13995                 goto no_print_return;
13996
13997         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13998                                         buff_size,
13999                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14000         if (ret) {
14001                 free(ptype);
14002                 goto no_print_return;
14003         }
14004         printf("List of defined packet types:\n");
14005         for (i = 0; i < ptype_num; i++) {
14006                 printf("  %2u:", ptype[i].ptype_id);
14007                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14008                         proto_id = ptype[i].protocols[j];
14009                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14010                                 for (n = 0; n < proto_num; n++) {
14011                                         if (proto[n].proto_id == proto_id) {
14012                                                 printf(" %s", proto[n].name);
14013                                                 break;
14014                                         }
14015                                 }
14016                         }
14017                 }
14018                 printf("\n");
14019         }
14020         free(ptype);
14021         printf("\n");
14022
14023         ret = 0;
14024 no_print_return:
14025         if (proto)
14026                 free(proto);
14027 #endif
14028         if (ret == -ENOTSUP)
14029                 printf("Function not supported in PMD driver\n");
14030         close_file(pkg);
14031 }
14032
14033 cmdline_parse_inst_t cmd_ddp_get_info = {
14034         .f = cmd_ddp_info_parsed,
14035         .data = NULL,
14036         .help_str = "ddp get info <profile_path>",
14037         .tokens = {
14038                 (void *)&cmd_ddp_info_ddp,
14039                 (void *)&cmd_ddp_info_get,
14040                 (void *)&cmd_ddp_info_info,
14041                 (void *)&cmd_ddp_info_filepath,
14042                 NULL,
14043         },
14044 };
14045
14046 /* Get dynamic device personalization profile info list*/
14047 #define PROFILE_INFO_SIZE 48
14048 #define MAX_PROFILE_NUM 16
14049
14050 struct cmd_ddp_get_list_result {
14051         cmdline_fixed_string_t ddp;
14052         cmdline_fixed_string_t get;
14053         cmdline_fixed_string_t list;
14054         portid_t port_id;
14055 };
14056
14057 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14058         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14059 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14060         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14061 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14062         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14063 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14064         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14065                 RTE_UINT16);
14066
14067 static void
14068 cmd_ddp_get_list_parsed(
14069         __rte_unused void *parsed_result,
14070         __rte_unused struct cmdline *cl,
14071         __rte_unused void *data)
14072 {
14073 #ifdef RTE_NET_I40E
14074         struct cmd_ddp_get_list_result *res = parsed_result;
14075         struct rte_pmd_i40e_profile_list *p_list;
14076         struct rte_pmd_i40e_profile_info *p_info;
14077         uint32_t p_num;
14078         uint32_t size;
14079         uint32_t i;
14080 #endif
14081         int ret = -ENOTSUP;
14082
14083 #ifdef RTE_NET_I40E
14084         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14085         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14086         if (!p_list) {
14087                 printf("%s: Failed to malloc buffer\n", __func__);
14088                 return;
14089         }
14090
14091         if (ret == -ENOTSUP)
14092                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14093                                                 (uint8_t *)p_list, size);
14094
14095         if (!ret) {
14096                 p_num = p_list->p_count;
14097                 printf("Profile number is: %d\n\n", p_num);
14098
14099                 for (i = 0; i < p_num; i++) {
14100                         p_info = &p_list->p_info[i];
14101                         printf("Profile %d:\n", i);
14102                         printf("Track id:     0x%x\n", p_info->track_id);
14103                         printf("Version:      %d.%d.%d.%d\n",
14104                                p_info->version.major,
14105                                p_info->version.minor,
14106                                p_info->version.update,
14107                                p_info->version.draft);
14108                         printf("Profile name: %s\n\n", p_info->name);
14109                 }
14110         }
14111
14112         free(p_list);
14113 #endif
14114
14115         if (ret < 0)
14116                 printf("Failed to get ddp list\n");
14117 }
14118
14119 cmdline_parse_inst_t cmd_ddp_get_list = {
14120         .f = cmd_ddp_get_list_parsed,
14121         .data = NULL,
14122         .help_str = "ddp get list <port_id>",
14123         .tokens = {
14124                 (void *)&cmd_ddp_get_list_ddp,
14125                 (void *)&cmd_ddp_get_list_get,
14126                 (void *)&cmd_ddp_get_list_list,
14127                 (void *)&cmd_ddp_get_list_port_id,
14128                 NULL,
14129         },
14130 };
14131
14132 /* Configure input set */
14133 struct cmd_cfg_input_set_result {
14134         cmdline_fixed_string_t port;
14135         cmdline_fixed_string_t cfg;
14136         portid_t port_id;
14137         cmdline_fixed_string_t pctype;
14138         uint8_t pctype_id;
14139         cmdline_fixed_string_t inset_type;
14140         cmdline_fixed_string_t opt;
14141         cmdline_fixed_string_t field;
14142         uint8_t field_idx;
14143 };
14144
14145 static void
14146 cmd_cfg_input_set_parsed(
14147         __rte_unused void *parsed_result,
14148         __rte_unused struct cmdline *cl,
14149         __rte_unused void *data)
14150 {
14151 #ifdef RTE_NET_I40E
14152         struct cmd_cfg_input_set_result *res = parsed_result;
14153         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14154         struct rte_pmd_i40e_inset inset;
14155 #endif
14156         int ret = -ENOTSUP;
14157
14158         if (!all_ports_stopped()) {
14159                 printf("Please stop all ports first\n");
14160                 return;
14161         }
14162
14163 #ifdef RTE_NET_I40E
14164         if (!strcmp(res->inset_type, "hash_inset"))
14165                 inset_type = INSET_HASH;
14166         else if (!strcmp(res->inset_type, "fdir_inset"))
14167                 inset_type = INSET_FDIR;
14168         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14169                 inset_type = INSET_FDIR_FLX;
14170         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14171                                      &inset, inset_type);
14172         if (ret) {
14173                 printf("Failed to get input set.\n");
14174                 return;
14175         }
14176
14177         if (!strcmp(res->opt, "get")) {
14178                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14179                                                    res->field_idx);
14180                 if (ret)
14181                         printf("Field index %d is enabled.\n", res->field_idx);
14182                 else
14183                         printf("Field index %d is disabled.\n", res->field_idx);
14184                 return;
14185         } else if (!strcmp(res->opt, "set"))
14186                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14187                                                    res->field_idx);
14188         else if (!strcmp(res->opt, "clear"))
14189                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14190                                                      res->field_idx);
14191         if (ret) {
14192                 printf("Failed to configure input set field.\n");
14193                 return;
14194         }
14195
14196         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14197                                      &inset, inset_type);
14198         if (ret) {
14199                 printf("Failed to set input set.\n");
14200                 return;
14201         }
14202 #endif
14203
14204         if (ret == -ENOTSUP)
14205                 printf("Function not supported\n");
14206 }
14207
14208 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14209         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14210                                  port, "port");
14211 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14212         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14213                                  cfg, "config");
14214 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14215         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14216                               port_id, RTE_UINT16);
14217 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14218         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14219                                  pctype, "pctype");
14220 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14221         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14222                               pctype_id, RTE_UINT8);
14223 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14224         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14225                                  inset_type,
14226                                  "hash_inset#fdir_inset#fdir_flx_inset");
14227 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14228         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14229                                  opt, "get#set#clear");
14230 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14231         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14232                                  field, "field");
14233 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14234         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14235                               field_idx, RTE_UINT8);
14236
14237 cmdline_parse_inst_t cmd_cfg_input_set = {
14238         .f = cmd_cfg_input_set_parsed,
14239         .data = NULL,
14240         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14241                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14242         .tokens = {
14243                 (void *)&cmd_cfg_input_set_port,
14244                 (void *)&cmd_cfg_input_set_cfg,
14245                 (void *)&cmd_cfg_input_set_port_id,
14246                 (void *)&cmd_cfg_input_set_pctype,
14247                 (void *)&cmd_cfg_input_set_pctype_id,
14248                 (void *)&cmd_cfg_input_set_inset_type,
14249                 (void *)&cmd_cfg_input_set_opt,
14250                 (void *)&cmd_cfg_input_set_field,
14251                 (void *)&cmd_cfg_input_set_field_idx,
14252                 NULL,
14253         },
14254 };
14255
14256 /* Clear input set */
14257 struct cmd_clear_input_set_result {
14258         cmdline_fixed_string_t port;
14259         cmdline_fixed_string_t cfg;
14260         portid_t port_id;
14261         cmdline_fixed_string_t pctype;
14262         uint8_t pctype_id;
14263         cmdline_fixed_string_t inset_type;
14264         cmdline_fixed_string_t clear;
14265         cmdline_fixed_string_t all;
14266 };
14267
14268 static void
14269 cmd_clear_input_set_parsed(
14270         __rte_unused void *parsed_result,
14271         __rte_unused struct cmdline *cl,
14272         __rte_unused void *data)
14273 {
14274 #ifdef RTE_NET_I40E
14275         struct cmd_clear_input_set_result *res = parsed_result;
14276         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14277         struct rte_pmd_i40e_inset inset;
14278 #endif
14279         int ret = -ENOTSUP;
14280
14281         if (!all_ports_stopped()) {
14282                 printf("Please stop all ports first\n");
14283                 return;
14284         }
14285
14286 #ifdef RTE_NET_I40E
14287         if (!strcmp(res->inset_type, "hash_inset"))
14288                 inset_type = INSET_HASH;
14289         else if (!strcmp(res->inset_type, "fdir_inset"))
14290                 inset_type = INSET_FDIR;
14291         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14292                 inset_type = INSET_FDIR_FLX;
14293
14294         memset(&inset, 0, sizeof(inset));
14295
14296         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14297                                      &inset, inset_type);
14298         if (ret) {
14299                 printf("Failed to clear input set.\n");
14300                 return;
14301         }
14302
14303 #endif
14304
14305         if (ret == -ENOTSUP)
14306                 printf("Function not supported\n");
14307 }
14308
14309 cmdline_parse_token_string_t cmd_clear_input_set_port =
14310         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14311                                  port, "port");
14312 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14313         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14314                                  cfg, "config");
14315 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14316         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14317                               port_id, RTE_UINT16);
14318 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14319         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14320                                  pctype, "pctype");
14321 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14322         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14323                               pctype_id, RTE_UINT8);
14324 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14325         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14326                                  inset_type,
14327                                  "hash_inset#fdir_inset#fdir_flx_inset");
14328 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14329         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14330                                  clear, "clear");
14331 cmdline_parse_token_string_t cmd_clear_input_set_all =
14332         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14333                                  all, "all");
14334
14335 cmdline_parse_inst_t cmd_clear_input_set = {
14336         .f = cmd_clear_input_set_parsed,
14337         .data = NULL,
14338         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14339                     "fdir_inset|fdir_flx_inset clear all",
14340         .tokens = {
14341                 (void *)&cmd_clear_input_set_port,
14342                 (void *)&cmd_clear_input_set_cfg,
14343                 (void *)&cmd_clear_input_set_port_id,
14344                 (void *)&cmd_clear_input_set_pctype,
14345                 (void *)&cmd_clear_input_set_pctype_id,
14346                 (void *)&cmd_clear_input_set_inset_type,
14347                 (void *)&cmd_clear_input_set_clear,
14348                 (void *)&cmd_clear_input_set_all,
14349                 NULL,
14350         },
14351 };
14352
14353 /* show vf stats */
14354
14355 /* Common result structure for show vf stats */
14356 struct cmd_show_vf_stats_result {
14357         cmdline_fixed_string_t show;
14358         cmdline_fixed_string_t vf;
14359         cmdline_fixed_string_t stats;
14360         portid_t port_id;
14361         uint16_t vf_id;
14362 };
14363
14364 /* Common CLI fields show vf stats*/
14365 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14366         TOKEN_STRING_INITIALIZER
14367                 (struct cmd_show_vf_stats_result,
14368                  show, "show");
14369 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_show_vf_stats_result,
14372                  vf, "vf");
14373 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_show_vf_stats_result,
14376                  stats, "stats");
14377 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14378         TOKEN_NUM_INITIALIZER
14379                 (struct cmd_show_vf_stats_result,
14380                  port_id, RTE_UINT16);
14381 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14382         TOKEN_NUM_INITIALIZER
14383                 (struct cmd_show_vf_stats_result,
14384                  vf_id, RTE_UINT16);
14385
14386 static void
14387 cmd_show_vf_stats_parsed(
14388         void *parsed_result,
14389         __rte_unused struct cmdline *cl,
14390         __rte_unused void *data)
14391 {
14392         struct cmd_show_vf_stats_result *res = parsed_result;
14393         struct rte_eth_stats stats;
14394         int ret = -ENOTSUP;
14395         static const char *nic_stats_border = "########################";
14396
14397         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14398                 return;
14399
14400         memset(&stats, 0, sizeof(stats));
14401
14402 #ifdef RTE_NET_I40E
14403         if (ret == -ENOTSUP)
14404                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14405                                                 res->vf_id,
14406                                                 &stats);
14407 #endif
14408 #ifdef RTE_NET_BNXT
14409         if (ret == -ENOTSUP)
14410                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14411                                                 res->vf_id,
14412                                                 &stats);
14413 #endif
14414
14415         switch (ret) {
14416         case 0:
14417                 break;
14418         case -EINVAL:
14419                 printf("invalid vf_id %d\n", res->vf_id);
14420                 break;
14421         case -ENODEV:
14422                 printf("invalid port_id %d\n", res->port_id);
14423                 break;
14424         case -ENOTSUP:
14425                 printf("function not implemented\n");
14426                 break;
14427         default:
14428                 printf("programming error: (%s)\n", strerror(-ret));
14429         }
14430
14431         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14432                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14433
14434         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14435                "%-"PRIu64"\n",
14436                stats.ipackets, stats.imissed, stats.ibytes);
14437         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14438         printf("  RX-nombuf:  %-10"PRIu64"\n",
14439                stats.rx_nombuf);
14440         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14441                "%-"PRIu64"\n",
14442                stats.opackets, stats.oerrors, stats.obytes);
14443
14444         printf("  %s############################%s\n",
14445                                nic_stats_border, nic_stats_border);
14446 }
14447
14448 cmdline_parse_inst_t cmd_show_vf_stats = {
14449         .f = cmd_show_vf_stats_parsed,
14450         .data = NULL,
14451         .help_str = "show vf stats <port_id> <vf_id>",
14452         .tokens = {
14453                 (void *)&cmd_show_vf_stats_show,
14454                 (void *)&cmd_show_vf_stats_vf,
14455                 (void *)&cmd_show_vf_stats_stats,
14456                 (void *)&cmd_show_vf_stats_port_id,
14457                 (void *)&cmd_show_vf_stats_vf_id,
14458                 NULL,
14459         },
14460 };
14461
14462 /* clear vf stats */
14463
14464 /* Common result structure for clear vf stats */
14465 struct cmd_clear_vf_stats_result {
14466         cmdline_fixed_string_t clear;
14467         cmdline_fixed_string_t vf;
14468         cmdline_fixed_string_t stats;
14469         portid_t port_id;
14470         uint16_t vf_id;
14471 };
14472
14473 /* Common CLI fields clear vf stats*/
14474 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14475         TOKEN_STRING_INITIALIZER
14476                 (struct cmd_clear_vf_stats_result,
14477                  clear, "clear");
14478 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14479         TOKEN_STRING_INITIALIZER
14480                 (struct cmd_clear_vf_stats_result,
14481                  vf, "vf");
14482 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14483         TOKEN_STRING_INITIALIZER
14484                 (struct cmd_clear_vf_stats_result,
14485                  stats, "stats");
14486 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14487         TOKEN_NUM_INITIALIZER
14488                 (struct cmd_clear_vf_stats_result,
14489                  port_id, RTE_UINT16);
14490 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14491         TOKEN_NUM_INITIALIZER
14492                 (struct cmd_clear_vf_stats_result,
14493                  vf_id, RTE_UINT16);
14494
14495 static void
14496 cmd_clear_vf_stats_parsed(
14497         void *parsed_result,
14498         __rte_unused struct cmdline *cl,
14499         __rte_unused void *data)
14500 {
14501         struct cmd_clear_vf_stats_result *res = parsed_result;
14502         int ret = -ENOTSUP;
14503
14504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14505                 return;
14506
14507 #ifdef RTE_NET_I40E
14508         if (ret == -ENOTSUP)
14509                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14510                                                   res->vf_id);
14511 #endif
14512 #ifdef RTE_NET_BNXT
14513         if (ret == -ENOTSUP)
14514                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14515                                                   res->vf_id);
14516 #endif
14517
14518         switch (ret) {
14519         case 0:
14520                 break;
14521         case -EINVAL:
14522                 printf("invalid vf_id %d\n", res->vf_id);
14523                 break;
14524         case -ENODEV:
14525                 printf("invalid port_id %d\n", res->port_id);
14526                 break;
14527         case -ENOTSUP:
14528                 printf("function not implemented\n");
14529                 break;
14530         default:
14531                 printf("programming error: (%s)\n", strerror(-ret));
14532         }
14533 }
14534
14535 cmdline_parse_inst_t cmd_clear_vf_stats = {
14536         .f = cmd_clear_vf_stats_parsed,
14537         .data = NULL,
14538         .help_str = "clear vf stats <port_id> <vf_id>",
14539         .tokens = {
14540                 (void *)&cmd_clear_vf_stats_clear,
14541                 (void *)&cmd_clear_vf_stats_vf,
14542                 (void *)&cmd_clear_vf_stats_stats,
14543                 (void *)&cmd_clear_vf_stats_port_id,
14544                 (void *)&cmd_clear_vf_stats_vf_id,
14545                 NULL,
14546         },
14547 };
14548
14549 /* port config pctype mapping reset */
14550
14551 /* Common result structure for port config pctype mapping reset */
14552 struct cmd_pctype_mapping_reset_result {
14553         cmdline_fixed_string_t port;
14554         cmdline_fixed_string_t config;
14555         portid_t port_id;
14556         cmdline_fixed_string_t pctype;
14557         cmdline_fixed_string_t mapping;
14558         cmdline_fixed_string_t reset;
14559 };
14560
14561 /* Common CLI fields for port config pctype mapping reset*/
14562 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14563         TOKEN_STRING_INITIALIZER
14564                 (struct cmd_pctype_mapping_reset_result,
14565                  port, "port");
14566 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14567         TOKEN_STRING_INITIALIZER
14568                 (struct cmd_pctype_mapping_reset_result,
14569                  config, "config");
14570 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14571         TOKEN_NUM_INITIALIZER
14572                 (struct cmd_pctype_mapping_reset_result,
14573                  port_id, RTE_UINT16);
14574 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14575         TOKEN_STRING_INITIALIZER
14576                 (struct cmd_pctype_mapping_reset_result,
14577                  pctype, "pctype");
14578 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14579         TOKEN_STRING_INITIALIZER
14580                 (struct cmd_pctype_mapping_reset_result,
14581                  mapping, "mapping");
14582 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14583         TOKEN_STRING_INITIALIZER
14584                 (struct cmd_pctype_mapping_reset_result,
14585                  reset, "reset");
14586
14587 static void
14588 cmd_pctype_mapping_reset_parsed(
14589         void *parsed_result,
14590         __rte_unused struct cmdline *cl,
14591         __rte_unused void *data)
14592 {
14593         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14594         int ret = -ENOTSUP;
14595
14596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14597                 return;
14598
14599 #ifdef RTE_NET_I40E
14600         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14601 #endif
14602
14603         switch (ret) {
14604         case 0:
14605                 break;
14606         case -ENODEV:
14607                 printf("invalid port_id %d\n", res->port_id);
14608                 break;
14609         case -ENOTSUP:
14610                 printf("function not implemented\n");
14611                 break;
14612         default:
14613                 printf("programming error: (%s)\n", strerror(-ret));
14614         }
14615 }
14616
14617 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14618         .f = cmd_pctype_mapping_reset_parsed,
14619         .data = NULL,
14620         .help_str = "port config <port_id> pctype mapping reset",
14621         .tokens = {
14622                 (void *)&cmd_pctype_mapping_reset_port,
14623                 (void *)&cmd_pctype_mapping_reset_config,
14624                 (void *)&cmd_pctype_mapping_reset_port_id,
14625                 (void *)&cmd_pctype_mapping_reset_pctype,
14626                 (void *)&cmd_pctype_mapping_reset_mapping,
14627                 (void *)&cmd_pctype_mapping_reset_reset,
14628                 NULL,
14629         },
14630 };
14631
14632 /* show port pctype mapping */
14633
14634 /* Common result structure for show port pctype mapping */
14635 struct cmd_pctype_mapping_get_result {
14636         cmdline_fixed_string_t show;
14637         cmdline_fixed_string_t port;
14638         portid_t port_id;
14639         cmdline_fixed_string_t pctype;
14640         cmdline_fixed_string_t mapping;
14641 };
14642
14643 /* Common CLI fields for pctype mapping get */
14644 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14645         TOKEN_STRING_INITIALIZER
14646                 (struct cmd_pctype_mapping_get_result,
14647                  show, "show");
14648 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14649         TOKEN_STRING_INITIALIZER
14650                 (struct cmd_pctype_mapping_get_result,
14651                  port, "port");
14652 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14653         TOKEN_NUM_INITIALIZER
14654                 (struct cmd_pctype_mapping_get_result,
14655                  port_id, RTE_UINT16);
14656 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14657         TOKEN_STRING_INITIALIZER
14658                 (struct cmd_pctype_mapping_get_result,
14659                  pctype, "pctype");
14660 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14661         TOKEN_STRING_INITIALIZER
14662                 (struct cmd_pctype_mapping_get_result,
14663                  mapping, "mapping");
14664
14665 static void
14666 cmd_pctype_mapping_get_parsed(
14667         void *parsed_result,
14668         __rte_unused struct cmdline *cl,
14669         __rte_unused void *data)
14670 {
14671         struct cmd_pctype_mapping_get_result *res = parsed_result;
14672         int ret = -ENOTSUP;
14673 #ifdef RTE_NET_I40E
14674         struct rte_pmd_i40e_flow_type_mapping
14675                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14676         int i, j, first_pctype;
14677 #endif
14678
14679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14680                 return;
14681
14682 #ifdef RTE_NET_I40E
14683         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14684 #endif
14685
14686         switch (ret) {
14687         case 0:
14688                 break;
14689         case -ENODEV:
14690                 printf("invalid port_id %d\n", res->port_id);
14691                 return;
14692         case -ENOTSUP:
14693                 printf("function not implemented\n");
14694                 return;
14695         default:
14696                 printf("programming error: (%s)\n", strerror(-ret));
14697                 return;
14698         }
14699
14700 #ifdef RTE_NET_I40E
14701         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14702                 if (mapping[i].pctype != 0ULL) {
14703                         first_pctype = 1;
14704
14705                         printf("pctype: ");
14706                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14707                                 if (mapping[i].pctype & (1ULL << j)) {
14708                                         printf(first_pctype ?
14709                                                "%02d" : ",%02d", j);
14710                                         first_pctype = 0;
14711                                 }
14712                         }
14713                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14714                 }
14715         }
14716 #endif
14717 }
14718
14719 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14720         .f = cmd_pctype_mapping_get_parsed,
14721         .data = NULL,
14722         .help_str = "show port <port_id> pctype mapping",
14723         .tokens = {
14724                 (void *)&cmd_pctype_mapping_get_show,
14725                 (void *)&cmd_pctype_mapping_get_port,
14726                 (void *)&cmd_pctype_mapping_get_port_id,
14727                 (void *)&cmd_pctype_mapping_get_pctype,
14728                 (void *)&cmd_pctype_mapping_get_mapping,
14729                 NULL,
14730         },
14731 };
14732
14733 /* port config pctype mapping update */
14734
14735 /* Common result structure for port config pctype mapping update */
14736 struct cmd_pctype_mapping_update_result {
14737         cmdline_fixed_string_t port;
14738         cmdline_fixed_string_t config;
14739         portid_t port_id;
14740         cmdline_fixed_string_t pctype;
14741         cmdline_fixed_string_t mapping;
14742         cmdline_fixed_string_t update;
14743         cmdline_fixed_string_t pctype_list;
14744         uint16_t flow_type;
14745 };
14746
14747 /* Common CLI fields for pctype mapping update*/
14748 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14749         TOKEN_STRING_INITIALIZER
14750                 (struct cmd_pctype_mapping_update_result,
14751                  port, "port");
14752 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14753         TOKEN_STRING_INITIALIZER
14754                 (struct cmd_pctype_mapping_update_result,
14755                  config, "config");
14756 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14757         TOKEN_NUM_INITIALIZER
14758                 (struct cmd_pctype_mapping_update_result,
14759                  port_id, RTE_UINT16);
14760 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14761         TOKEN_STRING_INITIALIZER
14762                 (struct cmd_pctype_mapping_update_result,
14763                  pctype, "pctype");
14764 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14765         TOKEN_STRING_INITIALIZER
14766                 (struct cmd_pctype_mapping_update_result,
14767                  mapping, "mapping");
14768 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14769         TOKEN_STRING_INITIALIZER
14770                 (struct cmd_pctype_mapping_update_result,
14771                  update, "update");
14772 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14773         TOKEN_STRING_INITIALIZER
14774                 (struct cmd_pctype_mapping_update_result,
14775                  pctype_list, NULL);
14776 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14777         TOKEN_NUM_INITIALIZER
14778                 (struct cmd_pctype_mapping_update_result,
14779                  flow_type, RTE_UINT16);
14780
14781 static void
14782 cmd_pctype_mapping_update_parsed(
14783         void *parsed_result,
14784         __rte_unused struct cmdline *cl,
14785         __rte_unused void *data)
14786 {
14787         struct cmd_pctype_mapping_update_result *res = parsed_result;
14788         int ret = -ENOTSUP;
14789 #ifdef RTE_NET_I40E
14790         struct rte_pmd_i40e_flow_type_mapping mapping;
14791         unsigned int i;
14792         unsigned int nb_item;
14793         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14794 #endif
14795
14796         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14797                 return;
14798
14799 #ifdef RTE_NET_I40E
14800         nb_item = parse_item_list(res->pctype_list, "pctypes",
14801                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14802         mapping.flow_type = res->flow_type;
14803         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14804                 mapping.pctype |= (1ULL << pctype_list[i]);
14805         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14806                                                 &mapping,
14807                                                 1,
14808                                                 0);
14809 #endif
14810
14811         switch (ret) {
14812         case 0:
14813                 break;
14814         case -EINVAL:
14815                 printf("invalid pctype or flow type\n");
14816                 break;
14817         case -ENODEV:
14818                 printf("invalid port_id %d\n", res->port_id);
14819                 break;
14820         case -ENOTSUP:
14821                 printf("function not implemented\n");
14822                 break;
14823         default:
14824                 printf("programming error: (%s)\n", strerror(-ret));
14825         }
14826 }
14827
14828 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14829         .f = cmd_pctype_mapping_update_parsed,
14830         .data = NULL,
14831         .help_str = "port config <port_id> pctype mapping update"
14832         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14833         .tokens = {
14834                 (void *)&cmd_pctype_mapping_update_port,
14835                 (void *)&cmd_pctype_mapping_update_config,
14836                 (void *)&cmd_pctype_mapping_update_port_id,
14837                 (void *)&cmd_pctype_mapping_update_pctype,
14838                 (void *)&cmd_pctype_mapping_update_mapping,
14839                 (void *)&cmd_pctype_mapping_update_update,
14840                 (void *)&cmd_pctype_mapping_update_pc_type,
14841                 (void *)&cmd_pctype_mapping_update_flow_type,
14842                 NULL,
14843         },
14844 };
14845
14846 /* ptype mapping get */
14847
14848 /* Common result structure for ptype mapping get */
14849 struct cmd_ptype_mapping_get_result {
14850         cmdline_fixed_string_t ptype;
14851         cmdline_fixed_string_t mapping;
14852         cmdline_fixed_string_t get;
14853         portid_t port_id;
14854         uint8_t valid_only;
14855 };
14856
14857 /* Common CLI fields for ptype mapping get */
14858 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14859         TOKEN_STRING_INITIALIZER
14860                 (struct cmd_ptype_mapping_get_result,
14861                  ptype, "ptype");
14862 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14863         TOKEN_STRING_INITIALIZER
14864                 (struct cmd_ptype_mapping_get_result,
14865                  mapping, "mapping");
14866 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14867         TOKEN_STRING_INITIALIZER
14868                 (struct cmd_ptype_mapping_get_result,
14869                  get, "get");
14870 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14871         TOKEN_NUM_INITIALIZER
14872                 (struct cmd_ptype_mapping_get_result,
14873                  port_id, RTE_UINT16);
14874 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14875         TOKEN_NUM_INITIALIZER
14876                 (struct cmd_ptype_mapping_get_result,
14877                  valid_only, RTE_UINT8);
14878
14879 static void
14880 cmd_ptype_mapping_get_parsed(
14881         void *parsed_result,
14882         __rte_unused struct cmdline *cl,
14883         __rte_unused void *data)
14884 {
14885         struct cmd_ptype_mapping_get_result *res = parsed_result;
14886         int ret = -ENOTSUP;
14887 #ifdef RTE_NET_I40E
14888         int max_ptype_num = 256;
14889         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14890         uint16_t count;
14891         int i;
14892 #endif
14893
14894         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14895                 return;
14896
14897 #ifdef RTE_NET_I40E
14898         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14899                                         mapping,
14900                                         max_ptype_num,
14901                                         &count,
14902                                         res->valid_only);
14903 #endif
14904
14905         switch (ret) {
14906         case 0:
14907                 break;
14908         case -ENODEV:
14909                 printf("invalid port_id %d\n", res->port_id);
14910                 break;
14911         case -ENOTSUP:
14912                 printf("function not implemented\n");
14913                 break;
14914         default:
14915                 printf("programming error: (%s)\n", strerror(-ret));
14916         }
14917
14918 #ifdef RTE_NET_I40E
14919         if (!ret) {
14920                 for (i = 0; i < count; i++)
14921                         printf("%3d\t0x%08x\n",
14922                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14923         }
14924 #endif
14925 }
14926
14927 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14928         .f = cmd_ptype_mapping_get_parsed,
14929         .data = NULL,
14930         .help_str = "ptype mapping get <port_id> <valid_only>",
14931         .tokens = {
14932                 (void *)&cmd_ptype_mapping_get_ptype,
14933                 (void *)&cmd_ptype_mapping_get_mapping,
14934                 (void *)&cmd_ptype_mapping_get_get,
14935                 (void *)&cmd_ptype_mapping_get_port_id,
14936                 (void *)&cmd_ptype_mapping_get_valid_only,
14937                 NULL,
14938         },
14939 };
14940
14941 /* ptype mapping replace */
14942
14943 /* Common result structure for ptype mapping replace */
14944 struct cmd_ptype_mapping_replace_result {
14945         cmdline_fixed_string_t ptype;
14946         cmdline_fixed_string_t mapping;
14947         cmdline_fixed_string_t replace;
14948         portid_t port_id;
14949         uint32_t target;
14950         uint8_t mask;
14951         uint32_t pkt_type;
14952 };
14953
14954 /* Common CLI fields for ptype mapping replace */
14955 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14956         TOKEN_STRING_INITIALIZER
14957                 (struct cmd_ptype_mapping_replace_result,
14958                  ptype, "ptype");
14959 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14960         TOKEN_STRING_INITIALIZER
14961                 (struct cmd_ptype_mapping_replace_result,
14962                  mapping, "mapping");
14963 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_ptype_mapping_replace_result,
14966                  replace, "replace");
14967 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14968         TOKEN_NUM_INITIALIZER
14969                 (struct cmd_ptype_mapping_replace_result,
14970                  port_id, RTE_UINT16);
14971 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14972         TOKEN_NUM_INITIALIZER
14973                 (struct cmd_ptype_mapping_replace_result,
14974                  target, RTE_UINT32);
14975 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14976         TOKEN_NUM_INITIALIZER
14977                 (struct cmd_ptype_mapping_replace_result,
14978                  mask, RTE_UINT8);
14979 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14980         TOKEN_NUM_INITIALIZER
14981                 (struct cmd_ptype_mapping_replace_result,
14982                  pkt_type, RTE_UINT32);
14983
14984 static void
14985 cmd_ptype_mapping_replace_parsed(
14986         void *parsed_result,
14987         __rte_unused struct cmdline *cl,
14988         __rte_unused void *data)
14989 {
14990         struct cmd_ptype_mapping_replace_result *res = parsed_result;
14991         int ret = -ENOTSUP;
14992
14993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14994                 return;
14995
14996 #ifdef RTE_NET_I40E
14997         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14998                                         res->target,
14999                                         res->mask,
15000                                         res->pkt_type);
15001 #endif
15002
15003         switch (ret) {
15004         case 0:
15005                 break;
15006         case -EINVAL:
15007                 printf("invalid ptype 0x%8x or 0x%8x\n",
15008                                 res->target, res->pkt_type);
15009                 break;
15010         case -ENODEV:
15011                 printf("invalid port_id %d\n", res->port_id);
15012                 break;
15013         case -ENOTSUP:
15014                 printf("function not implemented\n");
15015                 break;
15016         default:
15017                 printf("programming error: (%s)\n", strerror(-ret));
15018         }
15019 }
15020
15021 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15022         .f = cmd_ptype_mapping_replace_parsed,
15023         .data = NULL,
15024         .help_str =
15025                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15026         .tokens = {
15027                 (void *)&cmd_ptype_mapping_replace_ptype,
15028                 (void *)&cmd_ptype_mapping_replace_mapping,
15029                 (void *)&cmd_ptype_mapping_replace_replace,
15030                 (void *)&cmd_ptype_mapping_replace_port_id,
15031                 (void *)&cmd_ptype_mapping_replace_target,
15032                 (void *)&cmd_ptype_mapping_replace_mask,
15033                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15034                 NULL,
15035         },
15036 };
15037
15038 /* ptype mapping reset */
15039
15040 /* Common result structure for ptype mapping reset */
15041 struct cmd_ptype_mapping_reset_result {
15042         cmdline_fixed_string_t ptype;
15043         cmdline_fixed_string_t mapping;
15044         cmdline_fixed_string_t reset;
15045         portid_t port_id;
15046 };
15047
15048 /* Common CLI fields for ptype mapping reset*/
15049 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15050         TOKEN_STRING_INITIALIZER
15051                 (struct cmd_ptype_mapping_reset_result,
15052                  ptype, "ptype");
15053 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15054         TOKEN_STRING_INITIALIZER
15055                 (struct cmd_ptype_mapping_reset_result,
15056                  mapping, "mapping");
15057 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15058         TOKEN_STRING_INITIALIZER
15059                 (struct cmd_ptype_mapping_reset_result,
15060                  reset, "reset");
15061 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15062         TOKEN_NUM_INITIALIZER
15063                 (struct cmd_ptype_mapping_reset_result,
15064                  port_id, RTE_UINT16);
15065
15066 static void
15067 cmd_ptype_mapping_reset_parsed(
15068         void *parsed_result,
15069         __rte_unused struct cmdline *cl,
15070         __rte_unused void *data)
15071 {
15072         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15073         int ret = -ENOTSUP;
15074
15075         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15076                 return;
15077
15078 #ifdef RTE_NET_I40E
15079         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15080 #endif
15081
15082         switch (ret) {
15083         case 0:
15084                 break;
15085         case -ENODEV:
15086                 printf("invalid port_id %d\n", res->port_id);
15087                 break;
15088         case -ENOTSUP:
15089                 printf("function not implemented\n");
15090                 break;
15091         default:
15092                 printf("programming error: (%s)\n", strerror(-ret));
15093         }
15094 }
15095
15096 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15097         .f = cmd_ptype_mapping_reset_parsed,
15098         .data = NULL,
15099         .help_str = "ptype mapping reset <port_id>",
15100         .tokens = {
15101                 (void *)&cmd_ptype_mapping_reset_ptype,
15102                 (void *)&cmd_ptype_mapping_reset_mapping,
15103                 (void *)&cmd_ptype_mapping_reset_reset,
15104                 (void *)&cmd_ptype_mapping_reset_port_id,
15105                 NULL,
15106         },
15107 };
15108
15109 /* ptype mapping update */
15110
15111 /* Common result structure for ptype mapping update */
15112 struct cmd_ptype_mapping_update_result {
15113         cmdline_fixed_string_t ptype;
15114         cmdline_fixed_string_t mapping;
15115         cmdline_fixed_string_t reset;
15116         portid_t port_id;
15117         uint8_t hw_ptype;
15118         uint32_t sw_ptype;
15119 };
15120
15121 /* Common CLI fields for ptype mapping update*/
15122 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15123         TOKEN_STRING_INITIALIZER
15124                 (struct cmd_ptype_mapping_update_result,
15125                  ptype, "ptype");
15126 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15127         TOKEN_STRING_INITIALIZER
15128                 (struct cmd_ptype_mapping_update_result,
15129                  mapping, "mapping");
15130 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15131         TOKEN_STRING_INITIALIZER
15132                 (struct cmd_ptype_mapping_update_result,
15133                  reset, "update");
15134 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15135         TOKEN_NUM_INITIALIZER
15136                 (struct cmd_ptype_mapping_update_result,
15137                  port_id, RTE_UINT16);
15138 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15139         TOKEN_NUM_INITIALIZER
15140                 (struct cmd_ptype_mapping_update_result,
15141                  hw_ptype, RTE_UINT8);
15142 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15143         TOKEN_NUM_INITIALIZER
15144                 (struct cmd_ptype_mapping_update_result,
15145                  sw_ptype, RTE_UINT32);
15146
15147 static void
15148 cmd_ptype_mapping_update_parsed(
15149         void *parsed_result,
15150         __rte_unused struct cmdline *cl,
15151         __rte_unused void *data)
15152 {
15153         struct cmd_ptype_mapping_update_result *res = parsed_result;
15154         int ret = -ENOTSUP;
15155 #ifdef RTE_NET_I40E
15156         struct rte_pmd_i40e_ptype_mapping mapping;
15157 #endif
15158         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15159                 return;
15160
15161 #ifdef RTE_NET_I40E
15162         mapping.hw_ptype = res->hw_ptype;
15163         mapping.sw_ptype = res->sw_ptype;
15164         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15165                                                 &mapping,
15166                                                 1,
15167                                                 0);
15168 #endif
15169
15170         switch (ret) {
15171         case 0:
15172                 break;
15173         case -EINVAL:
15174                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15175                 break;
15176         case -ENODEV:
15177                 printf("invalid port_id %d\n", res->port_id);
15178                 break;
15179         case -ENOTSUP:
15180                 printf("function not implemented\n");
15181                 break;
15182         default:
15183                 printf("programming error: (%s)\n", strerror(-ret));
15184         }
15185 }
15186
15187 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15188         .f = cmd_ptype_mapping_update_parsed,
15189         .data = NULL,
15190         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15191         .tokens = {
15192                 (void *)&cmd_ptype_mapping_update_ptype,
15193                 (void *)&cmd_ptype_mapping_update_mapping,
15194                 (void *)&cmd_ptype_mapping_update_update,
15195                 (void *)&cmd_ptype_mapping_update_port_id,
15196                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15197                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15198                 NULL,
15199         },
15200 };
15201
15202 /* Common result structure for file commands */
15203 struct cmd_cmdfile_result {
15204         cmdline_fixed_string_t load;
15205         cmdline_fixed_string_t filename;
15206 };
15207
15208 /* Common CLI fields for file commands */
15209 cmdline_parse_token_string_t cmd_load_cmdfile =
15210         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15211 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15212         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15213
15214 static void
15215 cmd_load_from_file_parsed(
15216         void *parsed_result,
15217         __rte_unused struct cmdline *cl,
15218         __rte_unused void *data)
15219 {
15220         struct cmd_cmdfile_result *res = parsed_result;
15221
15222         cmdline_read_from_file(res->filename);
15223 }
15224
15225 cmdline_parse_inst_t cmd_load_from_file = {
15226         .f = cmd_load_from_file_parsed,
15227         .data = NULL,
15228         .help_str = "load <filename>",
15229         .tokens = {
15230                 (void *)&cmd_load_cmdfile,
15231                 (void *)&cmd_load_cmdfile_filename,
15232                 NULL,
15233         },
15234 };
15235
15236 /* Get Rx offloads capabilities */
15237 struct cmd_rx_offload_get_capa_result {
15238         cmdline_fixed_string_t show;
15239         cmdline_fixed_string_t port;
15240         portid_t port_id;
15241         cmdline_fixed_string_t rx_offload;
15242         cmdline_fixed_string_t capabilities;
15243 };
15244
15245 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15246         TOKEN_STRING_INITIALIZER
15247                 (struct cmd_rx_offload_get_capa_result,
15248                  show, "show");
15249 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15250         TOKEN_STRING_INITIALIZER
15251                 (struct cmd_rx_offload_get_capa_result,
15252                  port, "port");
15253 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15254         TOKEN_NUM_INITIALIZER
15255                 (struct cmd_rx_offload_get_capa_result,
15256                  port_id, RTE_UINT16);
15257 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15258         TOKEN_STRING_INITIALIZER
15259                 (struct cmd_rx_offload_get_capa_result,
15260                  rx_offload, "rx_offload");
15261 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15262         TOKEN_STRING_INITIALIZER
15263                 (struct cmd_rx_offload_get_capa_result,
15264                  capabilities, "capabilities");
15265
15266 static void
15267 print_rx_offloads(uint64_t offloads)
15268 {
15269         uint64_t single_offload;
15270         int begin;
15271         int end;
15272         int bit;
15273
15274         if (offloads == 0)
15275                 return;
15276
15277         begin = __builtin_ctzll(offloads);
15278         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15279
15280         single_offload = 1ULL << begin;
15281         for (bit = begin; bit < end; bit++) {
15282                 if (offloads & single_offload)
15283                         printf(" %s",
15284                                rte_eth_dev_rx_offload_name(single_offload));
15285                 single_offload <<= 1;
15286         }
15287 }
15288
15289 static void
15290 cmd_rx_offload_get_capa_parsed(
15291         void *parsed_result,
15292         __rte_unused struct cmdline *cl,
15293         __rte_unused void *data)
15294 {
15295         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15296         struct rte_eth_dev_info dev_info;
15297         portid_t port_id = res->port_id;
15298         uint64_t queue_offloads;
15299         uint64_t port_offloads;
15300         int ret;
15301
15302         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15303         if (ret != 0)
15304                 return;
15305
15306         queue_offloads = dev_info.rx_queue_offload_capa;
15307         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15308
15309         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15310         printf("  Per Queue :");
15311         print_rx_offloads(queue_offloads);
15312
15313         printf("\n");
15314         printf("  Per Port  :");
15315         print_rx_offloads(port_offloads);
15316         printf("\n\n");
15317 }
15318
15319 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15320         .f = cmd_rx_offload_get_capa_parsed,
15321         .data = NULL,
15322         .help_str = "show port <port_id> rx_offload capabilities",
15323         .tokens = {
15324                 (void *)&cmd_rx_offload_get_capa_show,
15325                 (void *)&cmd_rx_offload_get_capa_port,
15326                 (void *)&cmd_rx_offload_get_capa_port_id,
15327                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15328                 (void *)&cmd_rx_offload_get_capa_capabilities,
15329                 NULL,
15330         }
15331 };
15332
15333 /* Get Rx offloads configuration */
15334 struct cmd_rx_offload_get_configuration_result {
15335         cmdline_fixed_string_t show;
15336         cmdline_fixed_string_t port;
15337         portid_t port_id;
15338         cmdline_fixed_string_t rx_offload;
15339         cmdline_fixed_string_t configuration;
15340 };
15341
15342 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15343         TOKEN_STRING_INITIALIZER
15344                 (struct cmd_rx_offload_get_configuration_result,
15345                  show, "show");
15346 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15347         TOKEN_STRING_INITIALIZER
15348                 (struct cmd_rx_offload_get_configuration_result,
15349                  port, "port");
15350 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15351         TOKEN_NUM_INITIALIZER
15352                 (struct cmd_rx_offload_get_configuration_result,
15353                  port_id, RTE_UINT16);
15354 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15355         TOKEN_STRING_INITIALIZER
15356                 (struct cmd_rx_offload_get_configuration_result,
15357                  rx_offload, "rx_offload");
15358 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15359         TOKEN_STRING_INITIALIZER
15360                 (struct cmd_rx_offload_get_configuration_result,
15361                  configuration, "configuration");
15362
15363 static void
15364 cmd_rx_offload_get_configuration_parsed(
15365         void *parsed_result,
15366         __rte_unused struct cmdline *cl,
15367         __rte_unused void *data)
15368 {
15369         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15370         struct rte_eth_dev_info dev_info;
15371         portid_t port_id = res->port_id;
15372         struct rte_port *port = &ports[port_id];
15373         uint64_t port_offloads;
15374         uint64_t queue_offloads;
15375         uint16_t nb_rx_queues;
15376         int q;
15377         int ret;
15378
15379         printf("Rx Offloading Configuration of port %d :\n", port_id);
15380
15381         port_offloads = port->dev_conf.rxmode.offloads;
15382         printf("  Port :");
15383         print_rx_offloads(port_offloads);
15384         printf("\n");
15385
15386         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15387         if (ret != 0)
15388                 return;
15389
15390         nb_rx_queues = dev_info.nb_rx_queues;
15391         for (q = 0; q < nb_rx_queues; q++) {
15392                 queue_offloads = port->rx_conf[q].offloads;
15393                 printf("  Queue[%2d] :", q);
15394                 print_rx_offloads(queue_offloads);
15395                 printf("\n");
15396         }
15397         printf("\n");
15398 }
15399
15400 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15401         .f = cmd_rx_offload_get_configuration_parsed,
15402         .data = NULL,
15403         .help_str = "show port <port_id> rx_offload configuration",
15404         .tokens = {
15405                 (void *)&cmd_rx_offload_get_configuration_show,
15406                 (void *)&cmd_rx_offload_get_configuration_port,
15407                 (void *)&cmd_rx_offload_get_configuration_port_id,
15408                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15409                 (void *)&cmd_rx_offload_get_configuration_configuration,
15410                 NULL,
15411         }
15412 };
15413
15414 /* Enable/Disable a per port offloading */
15415 struct cmd_config_per_port_rx_offload_result {
15416         cmdline_fixed_string_t port;
15417         cmdline_fixed_string_t config;
15418         portid_t port_id;
15419         cmdline_fixed_string_t rx_offload;
15420         cmdline_fixed_string_t offload;
15421         cmdline_fixed_string_t on_off;
15422 };
15423
15424 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15425         TOKEN_STRING_INITIALIZER
15426                 (struct cmd_config_per_port_rx_offload_result,
15427                  port, "port");
15428 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15429         TOKEN_STRING_INITIALIZER
15430                 (struct cmd_config_per_port_rx_offload_result,
15431                  config, "config");
15432 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15433         TOKEN_NUM_INITIALIZER
15434                 (struct cmd_config_per_port_rx_offload_result,
15435                  port_id, RTE_UINT16);
15436 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15437         TOKEN_STRING_INITIALIZER
15438                 (struct cmd_config_per_port_rx_offload_result,
15439                  rx_offload, "rx_offload");
15440 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15441         TOKEN_STRING_INITIALIZER
15442                 (struct cmd_config_per_port_rx_offload_result,
15443                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15444                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15445                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15446                            "scatter#buffer_split#timestamp#security#"
15447                            "keep_crc#rss_hash");
15448 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15449         TOKEN_STRING_INITIALIZER
15450                 (struct cmd_config_per_port_rx_offload_result,
15451                  on_off, "on#off");
15452
15453 static uint64_t
15454 search_rx_offload(const char *name)
15455 {
15456         uint64_t single_offload;
15457         const char *single_name;
15458         int found = 0;
15459         unsigned int bit;
15460
15461         single_offload = 1;
15462         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15463                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15464                 if (!strcasecmp(single_name, name)) {
15465                         found = 1;
15466                         break;
15467                 }
15468                 single_offload <<= 1;
15469         }
15470
15471         if (found)
15472                 return single_offload;
15473
15474         return 0;
15475 }
15476
15477 static void
15478 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15479                                 __rte_unused struct cmdline *cl,
15480                                 __rte_unused void *data)
15481 {
15482         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15483         portid_t port_id = res->port_id;
15484         struct rte_eth_dev_info dev_info;
15485         struct rte_port *port = &ports[port_id];
15486         uint64_t single_offload;
15487         uint16_t nb_rx_queues;
15488         int q;
15489         int ret;
15490
15491         if (port->port_status != RTE_PORT_STOPPED) {
15492                 printf("Error: Can't config offload when Port %d "
15493                        "is not stopped\n", port_id);
15494                 return;
15495         }
15496
15497         single_offload = search_rx_offload(res->offload);
15498         if (single_offload == 0) {
15499                 printf("Unknown offload name: %s\n", res->offload);
15500                 return;
15501         }
15502
15503         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15504         if (ret != 0)
15505                 return;
15506
15507         nb_rx_queues = dev_info.nb_rx_queues;
15508         if (!strcmp(res->on_off, "on")) {
15509                 port->dev_conf.rxmode.offloads |= single_offload;
15510                 for (q = 0; q < nb_rx_queues; q++)
15511                         port->rx_conf[q].offloads |= single_offload;
15512         } else {
15513                 port->dev_conf.rxmode.offloads &= ~single_offload;
15514                 for (q = 0; q < nb_rx_queues; q++)
15515                         port->rx_conf[q].offloads &= ~single_offload;
15516         }
15517
15518         cmd_reconfig_device_queue(port_id, 1, 1);
15519 }
15520
15521 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15522         .f = cmd_config_per_port_rx_offload_parsed,
15523         .data = NULL,
15524         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15525                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15526                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15527                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15528                     "keep_crc|rss_hash on|off",
15529         .tokens = {
15530                 (void *)&cmd_config_per_port_rx_offload_result_port,
15531                 (void *)&cmd_config_per_port_rx_offload_result_config,
15532                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15533                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15534                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15535                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15536                 NULL,
15537         }
15538 };
15539
15540 /* Enable/Disable a per queue offloading */
15541 struct cmd_config_per_queue_rx_offload_result {
15542         cmdline_fixed_string_t port;
15543         portid_t port_id;
15544         cmdline_fixed_string_t rxq;
15545         uint16_t queue_id;
15546         cmdline_fixed_string_t rx_offload;
15547         cmdline_fixed_string_t offload;
15548         cmdline_fixed_string_t on_off;
15549 };
15550
15551 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15552         TOKEN_STRING_INITIALIZER
15553                 (struct cmd_config_per_queue_rx_offload_result,
15554                  port, "port");
15555 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15556         TOKEN_NUM_INITIALIZER
15557                 (struct cmd_config_per_queue_rx_offload_result,
15558                  port_id, RTE_UINT16);
15559 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15560         TOKEN_STRING_INITIALIZER
15561                 (struct cmd_config_per_queue_rx_offload_result,
15562                  rxq, "rxq");
15563 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15564         TOKEN_NUM_INITIALIZER
15565                 (struct cmd_config_per_queue_rx_offload_result,
15566                  queue_id, RTE_UINT16);
15567 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15568         TOKEN_STRING_INITIALIZER
15569                 (struct cmd_config_per_queue_rx_offload_result,
15570                  rx_offload, "rx_offload");
15571 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15572         TOKEN_STRING_INITIALIZER
15573                 (struct cmd_config_per_queue_rx_offload_result,
15574                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15575                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15576                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15577                            "scatter#buffer_split#timestamp#security#keep_crc");
15578 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15579         TOKEN_STRING_INITIALIZER
15580                 (struct cmd_config_per_queue_rx_offload_result,
15581                  on_off, "on#off");
15582
15583 static void
15584 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15585                                 __rte_unused struct cmdline *cl,
15586                                 __rte_unused void *data)
15587 {
15588         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15589         struct rte_eth_dev_info dev_info;
15590         portid_t port_id = res->port_id;
15591         uint16_t queue_id = res->queue_id;
15592         struct rte_port *port = &ports[port_id];
15593         uint64_t single_offload;
15594         int ret;
15595
15596         if (port->port_status != RTE_PORT_STOPPED) {
15597                 printf("Error: Can't config offload when Port %d "
15598                        "is not stopped\n", port_id);
15599                 return;
15600         }
15601
15602         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15603         if (ret != 0)
15604                 return;
15605
15606         if (queue_id >= dev_info.nb_rx_queues) {
15607                 printf("Error: input queue_id should be 0 ... "
15608                        "%d\n", dev_info.nb_rx_queues - 1);
15609                 return;
15610         }
15611
15612         single_offload = search_rx_offload(res->offload);
15613         if (single_offload == 0) {
15614                 printf("Unknown offload name: %s\n", res->offload);
15615                 return;
15616         }
15617
15618         if (!strcmp(res->on_off, "on"))
15619                 port->rx_conf[queue_id].offloads |= single_offload;
15620         else
15621                 port->rx_conf[queue_id].offloads &= ~single_offload;
15622
15623         cmd_reconfig_device_queue(port_id, 1, 1);
15624 }
15625
15626 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15627         .f = cmd_config_per_queue_rx_offload_parsed,
15628         .data = NULL,
15629         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15630                     "vlan_strip|ipv4_cksum|"
15631                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15632                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15633                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15634                     "keep_crc on|off",
15635         .tokens = {
15636                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15637                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15638                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15639                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15640                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15641                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15642                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15643                 NULL,
15644         }
15645 };
15646
15647 /* Get Tx offloads capabilities */
15648 struct cmd_tx_offload_get_capa_result {
15649         cmdline_fixed_string_t show;
15650         cmdline_fixed_string_t port;
15651         portid_t port_id;
15652         cmdline_fixed_string_t tx_offload;
15653         cmdline_fixed_string_t capabilities;
15654 };
15655
15656 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15657         TOKEN_STRING_INITIALIZER
15658                 (struct cmd_tx_offload_get_capa_result,
15659                  show, "show");
15660 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15661         TOKEN_STRING_INITIALIZER
15662                 (struct cmd_tx_offload_get_capa_result,
15663                  port, "port");
15664 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15665         TOKEN_NUM_INITIALIZER
15666                 (struct cmd_tx_offload_get_capa_result,
15667                  port_id, RTE_UINT16);
15668 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15669         TOKEN_STRING_INITIALIZER
15670                 (struct cmd_tx_offload_get_capa_result,
15671                  tx_offload, "tx_offload");
15672 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15673         TOKEN_STRING_INITIALIZER
15674                 (struct cmd_tx_offload_get_capa_result,
15675                  capabilities, "capabilities");
15676
15677 static void
15678 print_tx_offloads(uint64_t offloads)
15679 {
15680         uint64_t single_offload;
15681         int begin;
15682         int end;
15683         int bit;
15684
15685         if (offloads == 0)
15686                 return;
15687
15688         begin = __builtin_ctzll(offloads);
15689         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15690
15691         single_offload = 1ULL << begin;
15692         for (bit = begin; bit < end; bit++) {
15693                 if (offloads & single_offload)
15694                         printf(" %s",
15695                                rte_eth_dev_tx_offload_name(single_offload));
15696                 single_offload <<= 1;
15697         }
15698 }
15699
15700 static void
15701 cmd_tx_offload_get_capa_parsed(
15702         void *parsed_result,
15703         __rte_unused struct cmdline *cl,
15704         __rte_unused void *data)
15705 {
15706         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15707         struct rte_eth_dev_info dev_info;
15708         portid_t port_id = res->port_id;
15709         uint64_t queue_offloads;
15710         uint64_t port_offloads;
15711         int ret;
15712
15713         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15714         if (ret != 0)
15715                 return;
15716
15717         queue_offloads = dev_info.tx_queue_offload_capa;
15718         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15719
15720         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15721         printf("  Per Queue :");
15722         print_tx_offloads(queue_offloads);
15723
15724         printf("\n");
15725         printf("  Per Port  :");
15726         print_tx_offloads(port_offloads);
15727         printf("\n\n");
15728 }
15729
15730 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15731         .f = cmd_tx_offload_get_capa_parsed,
15732         .data = NULL,
15733         .help_str = "show port <port_id> tx_offload capabilities",
15734         .tokens = {
15735                 (void *)&cmd_tx_offload_get_capa_show,
15736                 (void *)&cmd_tx_offload_get_capa_port,
15737                 (void *)&cmd_tx_offload_get_capa_port_id,
15738                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15739                 (void *)&cmd_tx_offload_get_capa_capabilities,
15740                 NULL,
15741         }
15742 };
15743
15744 /* Get Tx offloads configuration */
15745 struct cmd_tx_offload_get_configuration_result {
15746         cmdline_fixed_string_t show;
15747         cmdline_fixed_string_t port;
15748         portid_t port_id;
15749         cmdline_fixed_string_t tx_offload;
15750         cmdline_fixed_string_t configuration;
15751 };
15752
15753 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15754         TOKEN_STRING_INITIALIZER
15755                 (struct cmd_tx_offload_get_configuration_result,
15756                  show, "show");
15757 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15758         TOKEN_STRING_INITIALIZER
15759                 (struct cmd_tx_offload_get_configuration_result,
15760                  port, "port");
15761 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15762         TOKEN_NUM_INITIALIZER
15763                 (struct cmd_tx_offload_get_configuration_result,
15764                  port_id, RTE_UINT16);
15765 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15766         TOKEN_STRING_INITIALIZER
15767                 (struct cmd_tx_offload_get_configuration_result,
15768                  tx_offload, "tx_offload");
15769 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15770         TOKEN_STRING_INITIALIZER
15771                 (struct cmd_tx_offload_get_configuration_result,
15772                  configuration, "configuration");
15773
15774 static void
15775 cmd_tx_offload_get_configuration_parsed(
15776         void *parsed_result,
15777         __rte_unused struct cmdline *cl,
15778         __rte_unused void *data)
15779 {
15780         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15781         struct rte_eth_dev_info dev_info;
15782         portid_t port_id = res->port_id;
15783         struct rte_port *port = &ports[port_id];
15784         uint64_t port_offloads;
15785         uint64_t queue_offloads;
15786         uint16_t nb_tx_queues;
15787         int q;
15788         int ret;
15789
15790         printf("Tx Offloading Configuration of port %d :\n", port_id);
15791
15792         port_offloads = port->dev_conf.txmode.offloads;
15793         printf("  Port :");
15794         print_tx_offloads(port_offloads);
15795         printf("\n");
15796
15797         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15798         if (ret != 0)
15799                 return;
15800
15801         nb_tx_queues = dev_info.nb_tx_queues;
15802         for (q = 0; q < nb_tx_queues; q++) {
15803                 queue_offloads = port->tx_conf[q].offloads;
15804                 printf("  Queue[%2d] :", q);
15805                 print_tx_offloads(queue_offloads);
15806                 printf("\n");
15807         }
15808         printf("\n");
15809 }
15810
15811 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15812         .f = cmd_tx_offload_get_configuration_parsed,
15813         .data = NULL,
15814         .help_str = "show port <port_id> tx_offload configuration",
15815         .tokens = {
15816                 (void *)&cmd_tx_offload_get_configuration_show,
15817                 (void *)&cmd_tx_offload_get_configuration_port,
15818                 (void *)&cmd_tx_offload_get_configuration_port_id,
15819                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15820                 (void *)&cmd_tx_offload_get_configuration_configuration,
15821                 NULL,
15822         }
15823 };
15824
15825 /* Enable/Disable a per port offloading */
15826 struct cmd_config_per_port_tx_offload_result {
15827         cmdline_fixed_string_t port;
15828         cmdline_fixed_string_t config;
15829         portid_t port_id;
15830         cmdline_fixed_string_t tx_offload;
15831         cmdline_fixed_string_t offload;
15832         cmdline_fixed_string_t on_off;
15833 };
15834
15835 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15836         TOKEN_STRING_INITIALIZER
15837                 (struct cmd_config_per_port_tx_offload_result,
15838                  port, "port");
15839 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15840         TOKEN_STRING_INITIALIZER
15841                 (struct cmd_config_per_port_tx_offload_result,
15842                  config, "config");
15843 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15844         TOKEN_NUM_INITIALIZER
15845                 (struct cmd_config_per_port_tx_offload_result,
15846                  port_id, RTE_UINT16);
15847 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15848         TOKEN_STRING_INITIALIZER
15849                 (struct cmd_config_per_port_tx_offload_result,
15850                  tx_offload, "tx_offload");
15851 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15852         TOKEN_STRING_INITIALIZER
15853                 (struct cmd_config_per_port_tx_offload_result,
15854                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15855                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15856                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15857                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15858                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15859                           "send_on_timestamp");
15860 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15861         TOKEN_STRING_INITIALIZER
15862                 (struct cmd_config_per_port_tx_offload_result,
15863                  on_off, "on#off");
15864
15865 static uint64_t
15866 search_tx_offload(const char *name)
15867 {
15868         uint64_t single_offload;
15869         const char *single_name;
15870         int found = 0;
15871         unsigned int bit;
15872
15873         single_offload = 1;
15874         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15875                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15876                 if (single_name == NULL)
15877                         break;
15878                 if (!strcasecmp(single_name, name)) {
15879                         found = 1;
15880                         break;
15881                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15882                         break;
15883                 single_offload <<= 1;
15884         }
15885
15886         if (found)
15887                 return single_offload;
15888
15889         return 0;
15890 }
15891
15892 static void
15893 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15894                                 __rte_unused struct cmdline *cl,
15895                                 __rte_unused void *data)
15896 {
15897         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15898         portid_t port_id = res->port_id;
15899         struct rte_eth_dev_info dev_info;
15900         struct rte_port *port = &ports[port_id];
15901         uint64_t single_offload;
15902         uint16_t nb_tx_queues;
15903         int q;
15904         int ret;
15905
15906         if (port->port_status != RTE_PORT_STOPPED) {
15907                 printf("Error: Can't config offload when Port %d "
15908                        "is not stopped\n", port_id);
15909                 return;
15910         }
15911
15912         single_offload = search_tx_offload(res->offload);
15913         if (single_offload == 0) {
15914                 printf("Unknown offload name: %s\n", res->offload);
15915                 return;
15916         }
15917
15918         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15919         if (ret != 0)
15920                 return;
15921
15922         nb_tx_queues = dev_info.nb_tx_queues;
15923         if (!strcmp(res->on_off, "on")) {
15924                 port->dev_conf.txmode.offloads |= single_offload;
15925                 for (q = 0; q < nb_tx_queues; q++)
15926                         port->tx_conf[q].offloads |= single_offload;
15927         } else {
15928                 port->dev_conf.txmode.offloads &= ~single_offload;
15929                 for (q = 0; q < nb_tx_queues; q++)
15930                         port->tx_conf[q].offloads &= ~single_offload;
15931         }
15932
15933         cmd_reconfig_device_queue(port_id, 1, 1);
15934 }
15935
15936 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15937         .f = cmd_config_per_port_tx_offload_parsed,
15938         .data = NULL,
15939         .help_str = "port config <port_id> tx_offload "
15940                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15941                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15942                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15943                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15944                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15945                     "send_on_timestamp on|off",
15946         .tokens = {
15947                 (void *)&cmd_config_per_port_tx_offload_result_port,
15948                 (void *)&cmd_config_per_port_tx_offload_result_config,
15949                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15950                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15951                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15952                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15953                 NULL,
15954         }
15955 };
15956
15957 /* Enable/Disable a per queue offloading */
15958 struct cmd_config_per_queue_tx_offload_result {
15959         cmdline_fixed_string_t port;
15960         portid_t port_id;
15961         cmdline_fixed_string_t txq;
15962         uint16_t queue_id;
15963         cmdline_fixed_string_t tx_offload;
15964         cmdline_fixed_string_t offload;
15965         cmdline_fixed_string_t on_off;
15966 };
15967
15968 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15969         TOKEN_STRING_INITIALIZER
15970                 (struct cmd_config_per_queue_tx_offload_result,
15971                  port, "port");
15972 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15973         TOKEN_NUM_INITIALIZER
15974                 (struct cmd_config_per_queue_tx_offload_result,
15975                  port_id, RTE_UINT16);
15976 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15977         TOKEN_STRING_INITIALIZER
15978                 (struct cmd_config_per_queue_tx_offload_result,
15979                  txq, "txq");
15980 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15981         TOKEN_NUM_INITIALIZER
15982                 (struct cmd_config_per_queue_tx_offload_result,
15983                  queue_id, RTE_UINT16);
15984 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15985         TOKEN_STRING_INITIALIZER
15986                 (struct cmd_config_per_queue_tx_offload_result,
15987                  tx_offload, "tx_offload");
15988 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15989         TOKEN_STRING_INITIALIZER
15990                 (struct cmd_config_per_queue_tx_offload_result,
15991                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15992                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15993                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15994                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15995                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
15996 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
15997         TOKEN_STRING_INITIALIZER
15998                 (struct cmd_config_per_queue_tx_offload_result,
15999                  on_off, "on#off");
16000
16001 static void
16002 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16003                                 __rte_unused struct cmdline *cl,
16004                                 __rte_unused void *data)
16005 {
16006         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16007         struct rte_eth_dev_info dev_info;
16008         portid_t port_id = res->port_id;
16009         uint16_t queue_id = res->queue_id;
16010         struct rte_port *port = &ports[port_id];
16011         uint64_t single_offload;
16012         int ret;
16013
16014         if (port->port_status != RTE_PORT_STOPPED) {
16015                 printf("Error: Can't config offload when Port %d "
16016                        "is not stopped\n", port_id);
16017                 return;
16018         }
16019
16020         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16021         if (ret != 0)
16022                 return;
16023
16024         if (queue_id >= dev_info.nb_tx_queues) {
16025                 printf("Error: input queue_id should be 0 ... "
16026                        "%d\n", dev_info.nb_tx_queues - 1);
16027                 return;
16028         }
16029
16030         single_offload = search_tx_offload(res->offload);
16031         if (single_offload == 0) {
16032                 printf("Unknown offload name: %s\n", res->offload);
16033                 return;
16034         }
16035
16036         if (!strcmp(res->on_off, "on"))
16037                 port->tx_conf[queue_id].offloads |= single_offload;
16038         else
16039                 port->tx_conf[queue_id].offloads &= ~single_offload;
16040
16041         cmd_reconfig_device_queue(port_id, 1, 1);
16042 }
16043
16044 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16045         .f = cmd_config_per_queue_tx_offload_parsed,
16046         .data = NULL,
16047         .help_str = "port <port_id> txq <queue_id> tx_offload "
16048                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16049                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16050                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16051                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16052                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16053                     "on|off",
16054         .tokens = {
16055                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16056                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16057                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16058                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16059                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16060                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16061                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16062                 NULL,
16063         }
16064 };
16065
16066 /* *** configure tx_metadata for specific port *** */
16067 struct cmd_config_tx_metadata_specific_result {
16068         cmdline_fixed_string_t port;
16069         cmdline_fixed_string_t keyword;
16070         uint16_t port_id;
16071         cmdline_fixed_string_t item;
16072         uint32_t value;
16073 };
16074
16075 static void
16076 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16077                                 __rte_unused struct cmdline *cl,
16078                                 __rte_unused void *data)
16079 {
16080         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16081
16082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16083                 return;
16084         ports[res->port_id].tx_metadata = res->value;
16085         /* Add/remove callback to insert valid metadata in every Tx packet. */
16086         if (ports[res->port_id].tx_metadata)
16087                 add_tx_md_callback(res->port_id);
16088         else
16089                 remove_tx_md_callback(res->port_id);
16090         rte_flow_dynf_metadata_register();
16091 }
16092
16093 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16094         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16095                         port, "port");
16096 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16097         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16098                         keyword, "config");
16099 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16100         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16101                         port_id, RTE_UINT16);
16102 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16103         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16104                         item, "tx_metadata");
16105 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16106         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16107                         value, RTE_UINT32);
16108
16109 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16110         .f = cmd_config_tx_metadata_specific_parsed,
16111         .data = NULL,
16112         .help_str = "port config <port_id> tx_metadata <value>",
16113         .tokens = {
16114                 (void *)&cmd_config_tx_metadata_specific_port,
16115                 (void *)&cmd_config_tx_metadata_specific_keyword,
16116                 (void *)&cmd_config_tx_metadata_specific_id,
16117                 (void *)&cmd_config_tx_metadata_specific_item,
16118                 (void *)&cmd_config_tx_metadata_specific_value,
16119                 NULL,
16120         },
16121 };
16122
16123 /* *** set dynf *** */
16124 struct cmd_config_tx_dynf_specific_result {
16125         cmdline_fixed_string_t port;
16126         cmdline_fixed_string_t keyword;
16127         uint16_t port_id;
16128         cmdline_fixed_string_t item;
16129         cmdline_fixed_string_t name;
16130         cmdline_fixed_string_t value;
16131 };
16132
16133 static void
16134 cmd_config_dynf_specific_parsed(void *parsed_result,
16135                                 __rte_unused struct cmdline *cl,
16136                                 __rte_unused void *data)
16137 {
16138         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16139         struct rte_mbuf_dynflag desc_flag;
16140         int flag;
16141         uint64_t old_port_flags;
16142
16143         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16144                 return;
16145         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16146         if (flag <= 0) {
16147                 if (strlcpy(desc_flag.name, res->name,
16148                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16149                         printf("Flag name too long\n");
16150                         return;
16151                 }
16152                 desc_flag.flags = 0;
16153                 flag = rte_mbuf_dynflag_register(&desc_flag);
16154                 if (flag < 0) {
16155                         printf("Can't register flag\n");
16156                         return;
16157                 }
16158                 strcpy(dynf_names[flag], desc_flag.name);
16159         }
16160         old_port_flags = ports[res->port_id].mbuf_dynf;
16161         if (!strcmp(res->value, "set")) {
16162                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16163                 if (old_port_flags == 0)
16164                         add_tx_dynf_callback(res->port_id);
16165         } else {
16166                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16167                 if (ports[res->port_id].mbuf_dynf == 0)
16168                         remove_tx_dynf_callback(res->port_id);
16169         }
16170 }
16171
16172 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16173         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16174                         keyword, "port");
16175 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16176         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16177                         keyword, "config");
16178 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16179         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16180                         port_id, RTE_UINT16);
16181 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16182         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16183                         item, "dynf");
16184 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16185         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16186                         name, NULL);
16187 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16188         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16189                         value, "set#clear");
16190
16191 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16192         .f = cmd_config_dynf_specific_parsed,
16193         .data = NULL,
16194         .help_str = "port config <port id> dynf <name> set|clear",
16195         .tokens = {
16196                 (void *)&cmd_config_tx_dynf_specific_port,
16197                 (void *)&cmd_config_tx_dynf_specific_keyword,
16198                 (void *)&cmd_config_tx_dynf_specific_port_id,
16199                 (void *)&cmd_config_tx_dynf_specific_item,
16200                 (void *)&cmd_config_tx_dynf_specific_name,
16201                 (void *)&cmd_config_tx_dynf_specific_value,
16202                 NULL,
16203         },
16204 };
16205
16206 /* *** display tx_metadata per port configuration *** */
16207 struct cmd_show_tx_metadata_result {
16208         cmdline_fixed_string_t cmd_show;
16209         cmdline_fixed_string_t cmd_port;
16210         cmdline_fixed_string_t cmd_keyword;
16211         portid_t cmd_pid;
16212 };
16213
16214 static void
16215 cmd_show_tx_metadata_parsed(void *parsed_result,
16216                 __rte_unused struct cmdline *cl,
16217                 __rte_unused void *data)
16218 {
16219         struct cmd_show_tx_metadata_result *res = parsed_result;
16220
16221         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16222                 printf("invalid port id %u\n", res->cmd_pid);
16223                 return;
16224         }
16225         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16226                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16227                        ports[res->cmd_pid].tx_metadata);
16228         }
16229 }
16230
16231 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16232         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16233                         cmd_show, "show");
16234 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16235         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16236                         cmd_port, "port");
16237 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16238         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16239                         cmd_pid, RTE_UINT16);
16240 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16241         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16242                         cmd_keyword, "tx_metadata");
16243
16244 cmdline_parse_inst_t cmd_show_tx_metadata = {
16245         .f = cmd_show_tx_metadata_parsed,
16246         .data = NULL,
16247         .help_str = "show port <port_id> tx_metadata",
16248         .tokens = {
16249                 (void *)&cmd_show_tx_metadata_show,
16250                 (void *)&cmd_show_tx_metadata_port,
16251                 (void *)&cmd_show_tx_metadata_pid,
16252                 (void *)&cmd_show_tx_metadata_keyword,
16253                 NULL,
16254         },
16255 };
16256
16257 /* *** show fec capability per port configuration *** */
16258 struct cmd_show_fec_capability_result {
16259         cmdline_fixed_string_t cmd_show;
16260         cmdline_fixed_string_t cmd_port;
16261         cmdline_fixed_string_t cmd_fec;
16262         cmdline_fixed_string_t cmd_keyword;
16263         portid_t cmd_pid;
16264 };
16265
16266 static void
16267 cmd_show_fec_capability_parsed(void *parsed_result,
16268                 __rte_unused struct cmdline *cl,
16269                 __rte_unused void *data)
16270 {
16271 #define FEC_CAP_NUM 2
16272         struct cmd_show_fec_capability_result *res = parsed_result;
16273         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
16274         unsigned int num = FEC_CAP_NUM;
16275         unsigned int ret_num;
16276         int ret;
16277
16278         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16279                 printf("Invalid port id %u\n", res->cmd_pid);
16280                 return;
16281         }
16282
16283         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16284         if (ret == -ENOTSUP) {
16285                 printf("Function not implemented\n");
16286                 return;
16287         } else if (ret < 0) {
16288                 printf("Get FEC capability failed\n");
16289                 return;
16290         }
16291
16292         ret_num = (unsigned int)ret;
16293         show_fec_capability(ret_num, speed_fec_capa);
16294 }
16295
16296 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16297         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16298                         cmd_show, "show");
16299 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16300         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16301                         cmd_port, "port");
16302 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16303         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16304                         cmd_pid, RTE_UINT16);
16305 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16306         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16307                         cmd_fec, "fec");
16308 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16309         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16310                         cmd_keyword, "capabilities");
16311
16312 cmdline_parse_inst_t cmd_show_capability = {
16313         .f = cmd_show_fec_capability_parsed,
16314         .data = NULL,
16315         .help_str = "show port <port_id> fec capabilities",
16316         .tokens = {
16317                 (void *)&cmd_show_fec_capability_show,
16318                 (void *)&cmd_show_fec_capability_port,
16319                 (void *)&cmd_show_fec_capability_pid,
16320                 (void *)&cmd_show_fec_capability_fec,
16321                 (void *)&cmd_show_fec_capability_keyword,
16322                 NULL,
16323         },
16324 };
16325
16326 /* *** show fec mode per port configuration *** */
16327 struct cmd_show_fec_metadata_result {
16328         cmdline_fixed_string_t cmd_show;
16329         cmdline_fixed_string_t cmd_port;
16330         cmdline_fixed_string_t cmd_keyword;
16331         portid_t cmd_pid;
16332 };
16333
16334 static void
16335 cmd_show_fec_mode_parsed(void *parsed_result,
16336                 __rte_unused struct cmdline *cl,
16337                 __rte_unused void *data)
16338 {
16339 #define FEC_NAME_SIZE 16
16340         struct cmd_show_fec_metadata_result *res = parsed_result;
16341         uint32_t mode;
16342         char buf[FEC_NAME_SIZE];
16343         int ret;
16344
16345         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16346                 printf("Invalid port id %u\n", res->cmd_pid);
16347                 return;
16348         }
16349         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16350         if (ret == -ENOTSUP) {
16351                 printf("Function not implemented\n");
16352                 return;
16353         } else if (ret < 0) {
16354                 printf("Get FEC mode failed\n");
16355                 return;
16356         }
16357
16358         switch (mode) {
16359         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16360                 strlcpy(buf, "off", sizeof(buf));
16361                 break;
16362         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16363                 strlcpy(buf, "auto", sizeof(buf));
16364                 break;
16365         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16366                 strlcpy(buf, "baser", sizeof(buf));
16367                 break;
16368         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16369                 strlcpy(buf, "rs", sizeof(buf));
16370                 break;
16371         default:
16372                 return;
16373         }
16374
16375         printf("%s\n", buf);
16376 }
16377
16378 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16379         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16380                         cmd_show, "show");
16381 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16382         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16383                         cmd_port, "port");
16384 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16385         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16386                         cmd_pid, RTE_UINT16);
16387 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16388         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16389                         cmd_keyword, "fec_mode");
16390
16391 cmdline_parse_inst_t cmd_show_fec_mode = {
16392         .f = cmd_show_fec_mode_parsed,
16393         .data = NULL,
16394         .help_str = "show port <port_id> fec_mode",
16395         .tokens = {
16396                 (void *)&cmd_show_fec_mode_show,
16397                 (void *)&cmd_show_fec_mode_port,
16398                 (void *)&cmd_show_fec_mode_pid,
16399                 (void *)&cmd_show_fec_mode_keyword,
16400                 NULL,
16401         },
16402 };
16403
16404 /* *** set fec mode per port configuration *** */
16405 struct cmd_set_port_fec_mode {
16406         cmdline_fixed_string_t set;
16407         cmdline_fixed_string_t port;
16408         portid_t port_id;
16409         cmdline_fixed_string_t fec_mode;
16410         cmdline_fixed_string_t fec_value;
16411 };
16412
16413 /* Common CLI fields for set fec mode */
16414 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16415         TOKEN_STRING_INITIALIZER
16416                 (struct cmd_set_port_fec_mode,
16417                  set, "set");
16418 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16419         TOKEN_STRING_INITIALIZER
16420                 (struct cmd_set_port_fec_mode,
16421                  port, "port");
16422 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16423         TOKEN_NUM_INITIALIZER
16424                 (struct cmd_set_port_fec_mode,
16425                  port_id, RTE_UINT16);
16426 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16427         TOKEN_STRING_INITIALIZER
16428                 (struct cmd_set_port_fec_mode,
16429                  fec_mode, "fec_mode");
16430 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16431         TOKEN_STRING_INITIALIZER
16432                 (struct cmd_set_port_fec_mode,
16433                  fec_value, NULL);
16434
16435 static void
16436 cmd_set_port_fec_mode_parsed(
16437         void *parsed_result,
16438         __rte_unused struct cmdline *cl,
16439         __rte_unused void *data)
16440 {
16441         struct cmd_set_port_fec_mode *res = parsed_result;
16442         uint16_t port_id = res->port_id;
16443         uint32_t mode;
16444         int ret;
16445
16446         ret = parse_fec_mode(res->fec_value, &mode);
16447         if (ret < 0) {
16448                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16449                         port_id);
16450                 return;
16451         }
16452
16453         ret = rte_eth_fec_set(port_id, mode);
16454         if (ret == -ENOTSUP) {
16455                 printf("Function not implemented\n");
16456                 return;
16457         } else if (ret < 0) {
16458                 printf("Set FEC mode failed\n");
16459                 return;
16460         }
16461 }
16462
16463 cmdline_parse_inst_t cmd_set_fec_mode = {
16464         .f = cmd_set_port_fec_mode_parsed,
16465         .data = NULL,
16466         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16467         .tokens = {
16468                 (void *)&cmd_set_port_fec_mode_set,
16469                 (void *)&cmd_set_port_fec_mode_port,
16470                 (void *)&cmd_set_port_fec_mode_port_id,
16471                 (void *)&cmd_set_port_fec_mode_str,
16472                 (void *)&cmd_set_port_fec_mode_value,
16473                 NULL,
16474         },
16475 };
16476
16477 /* show port supported ptypes */
16478
16479 /* Common result structure for show port ptypes */
16480 struct cmd_show_port_supported_ptypes_result {
16481         cmdline_fixed_string_t show;
16482         cmdline_fixed_string_t port;
16483         portid_t port_id;
16484         cmdline_fixed_string_t ptypes;
16485 };
16486
16487 /* Common CLI fields for show port ptypes */
16488 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16489         TOKEN_STRING_INITIALIZER
16490                 (struct cmd_show_port_supported_ptypes_result,
16491                  show, "show");
16492 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16493         TOKEN_STRING_INITIALIZER
16494                 (struct cmd_show_port_supported_ptypes_result,
16495                  port, "port");
16496 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16497         TOKEN_NUM_INITIALIZER
16498                 (struct cmd_show_port_supported_ptypes_result,
16499                  port_id, RTE_UINT16);
16500 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16501         TOKEN_STRING_INITIALIZER
16502                 (struct cmd_show_port_supported_ptypes_result,
16503                  ptypes, "ptypes");
16504
16505 static void
16506 cmd_show_port_supported_ptypes_parsed(
16507         void *parsed_result,
16508         __rte_unused struct cmdline *cl,
16509         __rte_unused void *data)
16510 {
16511 #define RSVD_PTYPE_MASK       0xf0000000
16512 #define MAX_PTYPES_PER_LAYER  16
16513 #define LTYPE_NAMESIZE        32
16514 #define PTYPE_NAMESIZE        256
16515         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16516         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16517         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16518         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16519         uint16_t port_id = res->port_id;
16520         int ret, i;
16521
16522         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16523         if (ret < 0)
16524                 return;
16525
16526         while (ptype_mask != RSVD_PTYPE_MASK) {
16527
16528                 switch (ptype_mask) {
16529                 case RTE_PTYPE_L2_MASK:
16530                         strlcpy(ltype, "L2", sizeof(ltype));
16531                         break;
16532                 case RTE_PTYPE_L3_MASK:
16533                         strlcpy(ltype, "L3", sizeof(ltype));
16534                         break;
16535                 case RTE_PTYPE_L4_MASK:
16536                         strlcpy(ltype, "L4", sizeof(ltype));
16537                         break;
16538                 case RTE_PTYPE_TUNNEL_MASK:
16539                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16540                         break;
16541                 case RTE_PTYPE_INNER_L2_MASK:
16542                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16543                         break;
16544                 case RTE_PTYPE_INNER_L3_MASK:
16545                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16546                         break;
16547                 case RTE_PTYPE_INNER_L4_MASK:
16548                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16549                         break;
16550                 default:
16551                         return;
16552                 }
16553
16554                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16555                                                        ptype_mask, ptypes,
16556                                                        MAX_PTYPES_PER_LAYER);
16557
16558                 if (ret > 0)
16559                         printf("Supported %s ptypes:\n", ltype);
16560                 else
16561                         printf("%s ptypes unsupported\n", ltype);
16562
16563                 for (i = 0; i < ret; ++i) {
16564                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16565                         printf("%s\n", buf);
16566                 }
16567
16568                 ptype_mask <<= 4;
16569         }
16570 }
16571
16572 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16573         .f = cmd_show_port_supported_ptypes_parsed,
16574         .data = NULL,
16575         .help_str = "show port <port_id> ptypes",
16576         .tokens = {
16577                 (void *)&cmd_show_port_supported_ptypes_show,
16578                 (void *)&cmd_show_port_supported_ptypes_port,
16579                 (void *)&cmd_show_port_supported_ptypes_port_id,
16580                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16581                 NULL,
16582         },
16583 };
16584
16585 /* *** display rx/tx descriptor status *** */
16586 struct cmd_show_rx_tx_desc_status_result {
16587         cmdline_fixed_string_t cmd_show;
16588         cmdline_fixed_string_t cmd_port;
16589         cmdline_fixed_string_t cmd_keyword;
16590         cmdline_fixed_string_t cmd_desc;
16591         cmdline_fixed_string_t cmd_status;
16592         portid_t cmd_pid;
16593         portid_t cmd_qid;
16594         portid_t cmd_did;
16595 };
16596
16597 static void
16598 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16599                 __rte_unused struct cmdline *cl,
16600                 __rte_unused void *data)
16601 {
16602         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16603         int rc;
16604
16605         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16606                 printf("invalid port id %u\n", res->cmd_pid);
16607                 return;
16608         }
16609
16610         if (!strcmp(res->cmd_keyword, "rxq")) {
16611                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16612                                              res->cmd_did);
16613                 if (rc < 0) {
16614                         printf("Invalid queueid = %d\n", res->cmd_qid);
16615                         return;
16616                 }
16617                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16618                         printf("Desc status = AVAILABLE\n");
16619                 else if (rc == RTE_ETH_RX_DESC_DONE)
16620                         printf("Desc status = DONE\n");
16621                 else
16622                         printf("Desc status = UNAVAILABLE\n");
16623         } else if (!strcmp(res->cmd_keyword, "txq")) {
16624                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16625                                              res->cmd_did);
16626                 if (rc < 0) {
16627                         printf("Invalid queueid = %d\n", res->cmd_qid);
16628                         return;
16629                 }
16630                 if (rc == RTE_ETH_TX_DESC_FULL)
16631                         printf("Desc status = FULL\n");
16632                 else if (rc == RTE_ETH_TX_DESC_DONE)
16633                         printf("Desc status = DONE\n");
16634                 else
16635                         printf("Desc status = UNAVAILABLE\n");
16636         }
16637 }
16638
16639 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16640         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16641                         cmd_show, "show");
16642 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16643         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16644                         cmd_port, "port");
16645 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16646         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16647                         cmd_pid, RTE_UINT16);
16648 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16649         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16650                         cmd_keyword, "rxq#txq");
16651 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16652         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16653                         cmd_qid, RTE_UINT16);
16654 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16655         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16656                         cmd_desc, "desc");
16657 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16658         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16659                         cmd_did, RTE_UINT16);
16660 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16661         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16662                         cmd_status, "status");
16663 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16664         .f = cmd_show_rx_tx_desc_status_parsed,
16665         .data = NULL,
16666         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16667                 "status",
16668         .tokens = {
16669                 (void *)&cmd_show_rx_tx_desc_status_show,
16670                 (void *)&cmd_show_rx_tx_desc_status_port,
16671                 (void *)&cmd_show_rx_tx_desc_status_pid,
16672                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16673                 (void *)&cmd_show_rx_tx_desc_status_qid,
16674                 (void *)&cmd_show_rx_tx_desc_status_desc,
16675                 (void *)&cmd_show_rx_tx_desc_status_did,
16676                 (void *)&cmd_show_rx_tx_desc_status_status,
16677                 NULL,
16678         },
16679 };
16680
16681 /* Common result structure for set port ptypes */
16682 struct cmd_set_port_ptypes_result {
16683         cmdline_fixed_string_t set;
16684         cmdline_fixed_string_t port;
16685         portid_t port_id;
16686         cmdline_fixed_string_t ptype_mask;
16687         uint32_t mask;
16688 };
16689
16690 /* Common CLI fields for set port ptypes */
16691 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16692         TOKEN_STRING_INITIALIZER
16693                 (struct cmd_set_port_ptypes_result,
16694                  set, "set");
16695 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16696         TOKEN_STRING_INITIALIZER
16697                 (struct cmd_set_port_ptypes_result,
16698                  port, "port");
16699 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16700         TOKEN_NUM_INITIALIZER
16701                 (struct cmd_set_port_ptypes_result,
16702                  port_id, RTE_UINT16);
16703 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16704         TOKEN_STRING_INITIALIZER
16705                 (struct cmd_set_port_ptypes_result,
16706                  ptype_mask, "ptype_mask");
16707 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16708         TOKEN_NUM_INITIALIZER
16709                 (struct cmd_set_port_ptypes_result,
16710                  mask, RTE_UINT32);
16711
16712 static void
16713 cmd_set_port_ptypes_parsed(
16714         void *parsed_result,
16715         __rte_unused struct cmdline *cl,
16716         __rte_unused void *data)
16717 {
16718         struct cmd_set_port_ptypes_result *res = parsed_result;
16719 #define PTYPE_NAMESIZE        256
16720         char ptype_name[PTYPE_NAMESIZE];
16721         uint16_t port_id = res->port_id;
16722         uint32_t ptype_mask = res->mask;
16723         int ret, i;
16724
16725         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16726                                                NULL, 0);
16727         if (ret <= 0) {
16728                 printf("Port %d doesn't support any ptypes.\n", port_id);
16729                 return;
16730         }
16731
16732         uint32_t ptypes[ret];
16733
16734         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16735         if (ret < 0) {
16736                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16737                 return;
16738         }
16739
16740         printf("Successfully set following ptypes for Port %d\n", port_id);
16741         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16742                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16743                 printf("%s\n", ptype_name);
16744         }
16745
16746         clear_ptypes = false;
16747 }
16748
16749 cmdline_parse_inst_t cmd_set_port_ptypes = {
16750         .f = cmd_set_port_ptypes_parsed,
16751         .data = NULL,
16752         .help_str = "set port <port_id> ptype_mask <mask>",
16753         .tokens = {
16754                 (void *)&cmd_set_port_ptypes_set,
16755                 (void *)&cmd_set_port_ptypes_port,
16756                 (void *)&cmd_set_port_ptypes_port_id,
16757                 (void *)&cmd_set_port_ptypes_mask_str,
16758                 (void *)&cmd_set_port_ptypes_mask_u32,
16759                 NULL,
16760         },
16761 };
16762
16763 /* *** display mac addresses added to a port *** */
16764 struct cmd_showport_macs_result {
16765         cmdline_fixed_string_t cmd_show;
16766         cmdline_fixed_string_t cmd_port;
16767         cmdline_fixed_string_t cmd_keyword;
16768         portid_t cmd_pid;
16769 };
16770
16771 static void
16772 cmd_showport_macs_parsed(void *parsed_result,
16773                 __rte_unused struct cmdline *cl,
16774                 __rte_unused void *data)
16775 {
16776         struct cmd_showport_macs_result *res = parsed_result;
16777
16778         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16779                 return;
16780
16781         if (!strcmp(res->cmd_keyword, "macs"))
16782                 show_macs(res->cmd_pid);
16783         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16784                 show_mcast_macs(res->cmd_pid);
16785 }
16786
16787 cmdline_parse_token_string_t cmd_showport_macs_show =
16788         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16789                         cmd_show, "show");
16790 cmdline_parse_token_string_t cmd_showport_macs_port =
16791         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16792                         cmd_port, "port");
16793 cmdline_parse_token_num_t cmd_showport_macs_pid =
16794         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16795                         cmd_pid, RTE_UINT16);
16796 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16797         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16798                         cmd_keyword, "macs#mcast_macs");
16799
16800 cmdline_parse_inst_t cmd_showport_macs = {
16801         .f = cmd_showport_macs_parsed,
16802         .data = NULL,
16803         .help_str = "show port <port_id> macs|mcast_macs",
16804         .tokens = {
16805                 (void *)&cmd_showport_macs_show,
16806                 (void *)&cmd_showport_macs_port,
16807                 (void *)&cmd_showport_macs_pid,
16808                 (void *)&cmd_showport_macs_keyword,
16809                 NULL,
16810         },
16811 };
16812
16813 /* ******************************************************************************** */
16814
16815 /* list of instructions */
16816 cmdline_parse_ctx_t main_ctx[] = {
16817         (cmdline_parse_inst_t *)&cmd_help_brief,
16818         (cmdline_parse_inst_t *)&cmd_help_long,
16819         (cmdline_parse_inst_t *)&cmd_quit,
16820         (cmdline_parse_inst_t *)&cmd_load_from_file,
16821         (cmdline_parse_inst_t *)&cmd_showport,
16822         (cmdline_parse_inst_t *)&cmd_showqueue,
16823         (cmdline_parse_inst_t *)&cmd_showeeprom,
16824         (cmdline_parse_inst_t *)&cmd_showportall,
16825         (cmdline_parse_inst_t *)&cmd_showdevice,
16826         (cmdline_parse_inst_t *)&cmd_showcfg,
16827         (cmdline_parse_inst_t *)&cmd_showfwdall,
16828         (cmdline_parse_inst_t *)&cmd_start,
16829         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16830         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16831         (cmdline_parse_inst_t *)&cmd_set_link_up,
16832         (cmdline_parse_inst_t *)&cmd_set_link_down,
16833         (cmdline_parse_inst_t *)&cmd_reset,
16834         (cmdline_parse_inst_t *)&cmd_set_numbers,
16835         (cmdline_parse_inst_t *)&cmd_set_log,
16836         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16837         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16838         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16839         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16840         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16841         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16842         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16843         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16844         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16845         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16846         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16847         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16848         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16849         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16850         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16851         (cmdline_parse_inst_t *)&cmd_set_link_check,
16852         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16853         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16854         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16855         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16856 #ifdef RTE_NET_BOND
16857         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16858         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16859         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16860         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16861         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16862         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16863         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16864         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16865         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16866         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16867         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16868 #endif
16869         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16870         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16871         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16872         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16873         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16874         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16875         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16876         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16877         (cmdline_parse_inst_t *)&cmd_csum_set,
16878         (cmdline_parse_inst_t *)&cmd_csum_show,
16879         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16880         (cmdline_parse_inst_t *)&cmd_tso_set,
16881         (cmdline_parse_inst_t *)&cmd_tso_show,
16882         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16883         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16884         (cmdline_parse_inst_t *)&cmd_gro_enable,
16885         (cmdline_parse_inst_t *)&cmd_gro_flush,
16886         (cmdline_parse_inst_t *)&cmd_gro_show,
16887         (cmdline_parse_inst_t *)&cmd_gso_enable,
16888         (cmdline_parse_inst_t *)&cmd_gso_size,
16889         (cmdline_parse_inst_t *)&cmd_gso_show,
16890         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16891         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16892         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16893         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16894         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16895         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16896         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16897         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16898         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16899         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16900         (cmdline_parse_inst_t *)&cmd_config_dcb,
16901         (cmdline_parse_inst_t *)&cmd_read_reg,
16902         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16903         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16904         (cmdline_parse_inst_t *)&cmd_write_reg,
16905         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16906         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16907         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16908         (cmdline_parse_inst_t *)&cmd_stop,
16909         (cmdline_parse_inst_t *)&cmd_mac_addr,
16910         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16911         (cmdline_parse_inst_t *)&cmd_set_qmap,
16912         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16913         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
16914         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
16915         (cmdline_parse_inst_t *)&cmd_operate_port,
16916         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16917         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16918         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16919         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
16920         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
16921         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16922         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16923         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16924         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16925         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16926         (cmdline_parse_inst_t *)&cmd_config_mtu,
16927         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16928         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
16929         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16930         (cmdline_parse_inst_t *)&cmd_config_rss,
16931         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16932         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16933         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
16934         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16935         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16936         (cmdline_parse_inst_t *)&cmd_showport_reta,
16937         (cmdline_parse_inst_t *)&cmd_showport_macs,
16938         (cmdline_parse_inst_t *)&cmd_config_burst,
16939         (cmdline_parse_inst_t *)&cmd_config_thresh,
16940         (cmdline_parse_inst_t *)&cmd_config_threshold,
16941         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16942         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16943         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16944         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16945         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16946         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16947         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16948         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16949         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16950         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16951         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16952         (cmdline_parse_inst_t *)&cmd_dump,
16953         (cmdline_parse_inst_t *)&cmd_dump_one,
16954 #ifdef RTE_NET_I40E
16955         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16956 #endif
16957         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16958         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16959         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16960         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16961         (cmdline_parse_inst_t *)&cmd_flow,
16962         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16963         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16964         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16965         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16966         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16967         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16968         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16969         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16970         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16971         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16972         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16973         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16974         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16975         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16976         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16977         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16978         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16979         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16980         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16981         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16982         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16983         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16984         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16985         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16986         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16987         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16988         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16989         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16990         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16991         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16992         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16993         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16994         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16995         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16996         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16997         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16998         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16999         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17000         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17001         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17002         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17003         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17004         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17005         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17006         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17007         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17008         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17009         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17010         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17011         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17012         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17013         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17014         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17015         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17016         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17017         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17018         (cmdline_parse_inst_t *)&cmd_ddp_add,
17019         (cmdline_parse_inst_t *)&cmd_ddp_del,
17020         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17021         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17022         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17023         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17024         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17025         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17026         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17027         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17028         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17029         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17030         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17031         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17032
17033         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17034         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17035         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17036         (cmdline_parse_inst_t *)&cmd_queue_region,
17037         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17038         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17039         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17040         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17041         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17042         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17043         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17044         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17045         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17046         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17047         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17048         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17049         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17050         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17051         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17052         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17053         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17054         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17055         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17056         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17057         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17058         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17059         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17060         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17061         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17062         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17063         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17064         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17065         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17066         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17067         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17068         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17069         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17070         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17071         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17072         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17073 #ifdef RTE_LIB_BPF
17074         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17075         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17076 #endif
17077         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17078         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17079         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17080         (cmdline_parse_inst_t *)&cmd_set_raw,
17081         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17082         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17083         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17084         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17085         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17086         (cmdline_parse_inst_t *)&cmd_show_capability,
17087         NULL,
17088 };
17089
17090 /* read cmdline commands from file */
17091 void
17092 cmdline_read_from_file(const char *filename)
17093 {
17094         struct cmdline *cl;
17095
17096         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17097         if (cl == NULL) {
17098                 printf("Failed to create file based cmdline context: %s\n",
17099                        filename);
17100                 return;
17101         }
17102
17103         cmdline_interact(cl);
17104         cmdline_quit(cl);
17105
17106         cmdline_free(cl);
17107
17108         printf("Read CLI commands from %s\n", filename);
17109 }
17110
17111 /* prompt function, called from main on MAIN lcore */
17112 void
17113 prompt(void)
17114 {
17115         /* initialize non-constant commands */
17116         cmd_set_fwd_mode_init();
17117         cmd_set_fwd_retry_mode_init();
17118
17119         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17120         if (testpmd_cl == NULL)
17121                 return;
17122         cmdline_interact(testpmd_cl);
17123         cmdline_stdin_exit(testpmd_cl);
17124 }
17125
17126 void
17127 prompt_exit(void)
17128 {
17129         if (testpmd_cl != NULL)
17130                 cmdline_quit(testpmd_cl);
17131 }
17132
17133 static void
17134 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17135 {
17136         if (id == (portid_t)RTE_PORT_ALL) {
17137                 portid_t pid;
17138
17139                 RTE_ETH_FOREACH_DEV(pid) {
17140                         /* check if need_reconfig has been set to 1 */
17141                         if (ports[pid].need_reconfig == 0)
17142                                 ports[pid].need_reconfig = dev;
17143                         /* check if need_reconfig_queues has been set to 1 */
17144                         if (ports[pid].need_reconfig_queues == 0)
17145                                 ports[pid].need_reconfig_queues = queue;
17146                 }
17147         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17148                 /* check if need_reconfig has been set to 1 */
17149                 if (ports[id].need_reconfig == 0)
17150                         ports[id].need_reconfig = dev;
17151                 /* check if need_reconfig_queues has been set to 1 */
17152                 if (ports[id].need_reconfig_queues == 0)
17153                         ports[id].need_reconfig_queues = queue;
17154         }
17155 }