dpdk/app/test-pmd/cmdline.c
<<
>>
Prefs
   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 <unistd.h>
  12#include <inttypes.h>
  13#include <sys/queue.h>
  14
  15#include <rte_common.h>
  16#include <rte_byteorder.h>
  17#include <rte_log.h>
  18#include <rte_debug.h>
  19#include <rte_cycles.h>
  20#include <rte_memory.h>
  21#include <rte_memzone.h>
  22#include <rte_malloc.h>
  23#include <rte_launch.h>
  24#include <rte_eal.h>
  25#include <rte_per_lcore.h>
  26#include <rte_lcore.h>
  27#include <rte_atomic.h>
  28#include <rte_branch_prediction.h>
  29#include <rte_ring.h>
  30#include <rte_mempool.h>
  31#include <rte_interrupts.h>
  32#include <rte_pci.h>
  33#include <rte_ether.h>
  34#include <rte_ethdev.h>
  35#include <rte_string_fns.h>
  36#include <rte_devargs.h>
  37#include <rte_flow.h>
  38#include <rte_gro.h>
  39#include <rte_mbuf_dyn.h>
  40
  41#include <cmdline_rdline.h>
  42#include <cmdline_parse.h>
  43#include <cmdline_parse_num.h>
  44#include <cmdline_parse_string.h>
  45#include <cmdline_parse_ipaddr.h>
  46#include <cmdline_parse_etheraddr.h>
  47#include <cmdline_socket.h>
  48#include <cmdline.h>
  49#ifdef RTE_NET_BOND
  50#include <rte_eth_bond.h>
  51#include <rte_eth_bond_8023ad.h>
  52#endif
  53#if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
  54#include <rte_pmd_dpaa.h>
  55#endif
  56#ifdef RTE_NET_IXGBE
  57#include <rte_pmd_ixgbe.h>
  58#endif
  59#ifdef RTE_NET_I40E
  60#include <rte_pmd_i40e.h>
  61#endif
  62#ifdef RTE_NET_BNXT
  63#include <rte_pmd_bnxt.h>
  64#endif
  65#include "testpmd.h"
  66#include "cmdline_mtr.h"
  67#include "cmdline_tm.h"
  68#include "bpf_cmd.h"
  69
  70static struct cmdline *testpmd_cl;
  71
  72static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
  73
  74/* *** Help command with introduction. *** */
  75struct cmd_help_brief_result {
  76        cmdline_fixed_string_t help;
  77};
  78
  79static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
  80                                  struct cmdline *cl,
  81                                  __rte_unused void *data)
  82{
  83        cmdline_printf(
  84                cl,
  85                "\n"
  86                "Help is available for the following sections:\n\n"
  87                "    help control                    : Start and stop forwarding.\n"
  88                "    help display                    : Displaying port, stats and config "
  89                "information.\n"
  90                "    help config                     : Configuration information.\n"
  91                "    help ports                      : Configuring ports.\n"
  92                "    help registers                  : Reading and setting port registers.\n"
  93                "    help filters                    : Filters configuration help.\n"
  94                "    help traffic_management         : Traffic Management commands.\n"
  95                "    help devices                    : Device related cmds.\n"
  96                "    help all                        : All of the above sections.\n\n"
  97        );
  98
  99}
 100
 101cmdline_parse_token_string_t cmd_help_brief_help =
 102        TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
 103
 104cmdline_parse_inst_t cmd_help_brief = {
 105        .f = cmd_help_brief_parsed,
 106        .data = NULL,
 107        .help_str = "help: Show help",
 108        .tokens = {
 109                (void *)&cmd_help_brief_help,
 110                NULL,
 111        },
 112};
 113
 114/* *** Help command with help sections. *** */
 115struct cmd_help_long_result {
 116        cmdline_fixed_string_t help;
 117        cmdline_fixed_string_t section;
 118};
 119
 120static void cmd_help_long_parsed(void *parsed_result,
 121                                 struct cmdline *cl,
 122                                 __rte_unused void *data)
 123{
 124        int show_all = 0;
 125        struct cmd_help_long_result *res = parsed_result;
 126
 127        if (!strcmp(res->section, "all"))
 128                show_all = 1;
 129
 130        if (show_all || !strcmp(res->section, "control")) {
 131
 132                cmdline_printf(
 133                        cl,
 134                        "\n"
 135                        "Control forwarding:\n"
 136                        "-------------------\n\n"
 137
 138                        "start\n"
 139                        "    Start packet forwarding with current configuration.\n\n"
 140
 141                        "start tx_first\n"
 142                        "    Start packet forwarding with current config"
 143                        " after sending one burst of packets.\n\n"
 144
 145                        "stop\n"
 146                        "    Stop packet forwarding, and display accumulated"
 147                        " statistics.\n\n"
 148
 149                        "quit\n"
 150                        "    Quit to prompt.\n\n"
 151                );
 152        }
 153
 154        if (show_all || !strcmp(res->section, "display")) {
 155
 156                cmdline_printf(
 157                        cl,
 158                        "\n"
 159                        "Display:\n"
 160                        "--------\n\n"
 161
 162                        "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
 163                        "    Display information for port_id, or all.\n\n"
 164
 165                        "show port port_id (module_eeprom|eeprom)\n"
 166                        "    Display the module EEPROM or EEPROM information for port_id.\n\n"
 167
 168                        "show port X rss reta (size) (mask0,mask1,...)\n"
 169                        "    Display the rss redirection table entry indicated"
 170                        " by masks on port X. size is used to indicate the"
 171                        " hardware supported reta size\n\n"
 172
 173                        "show port (port_id) rss-hash [key]\n"
 174                        "    Display the RSS hash functions and RSS hash key of port\n\n"
 175
 176                        "clear port (info|stats|xstats|fdir) (port_id|all)\n"
 177                        "    Clear information for port_id, or all.\n\n"
 178
 179                        "show (rxq|txq) info (port_id) (queue_id)\n"
 180                        "    Display information for configured RX/TX queue.\n\n"
 181
 182                        "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
 183                        "    Display the given configuration.\n\n"
 184
 185                        "read rxd (port_id) (queue_id) (rxd_id)\n"
 186                        "    Display an RX descriptor of a port RX queue.\n\n"
 187
 188                        "read txd (port_id) (queue_id) (txd_id)\n"
 189                        "    Display a TX descriptor of a port TX queue.\n\n"
 190
 191                        "ddp get list (port_id)\n"
 192                        "    Get ddp profile info list\n\n"
 193
 194                        "ddp get info (profile_path)\n"
 195                        "    Get ddp profile information.\n\n"
 196
 197                        "show vf stats (port_id) (vf_id)\n"
 198                        "    Display a VF's statistics.\n\n"
 199
 200                        "clear vf stats (port_id) (vf_id)\n"
 201                        "    Reset a VF's statistics.\n\n"
 202
 203                        "show port (port_id) pctype mapping\n"
 204                        "    Get flow ptype to pctype mapping on a port\n\n"
 205
 206                        "show port meter stats (port_id) (meter_id) (clear)\n"
 207                        "    Get meter stats on a port\n\n"
 208
 209                        "show fwd stats all\n"
 210                        "    Display statistics for all fwd engines.\n\n"
 211
 212                        "clear fwd stats all\n"
 213                        "    Clear statistics for all fwd engines.\n\n"
 214
 215                        "show port (port_id) rx_offload capabilities\n"
 216                        "    List all per queue and per port Rx offloading"
 217                        " capabilities of a port\n\n"
 218
 219                        "show port (port_id) rx_offload configuration\n"
 220                        "    List port level and all queue level"
 221                        " Rx offloading configuration\n\n"
 222
 223                        "show port (port_id) tx_offload capabilities\n"
 224                        "    List all per queue and per port"
 225                        " Tx offloading capabilities of a port\n\n"
 226
 227                        "show port (port_id) tx_offload configuration\n"
 228                        "    List port level and all queue level"
 229                        " Tx offloading configuration\n\n"
 230
 231                        "show port (port_id) tx_metadata\n"
 232                        "    Show Tx metadata value set"
 233                        " for a specific port\n\n"
 234
 235                        "show port (port_id) ptypes\n"
 236                        "    Show port supported ptypes"
 237                        " for a specific port\n\n"
 238
 239                        "show device info (<identifier>|all)"
 240                        "       Show general information about devices probed.\n\n"
 241
 242                        "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
 243                        "       Show status of rx|tx descriptor.\n\n"
 244
 245                        "show port (port_id) rxq (queue_id) desc used count\n"
 246                        "    Show current number of filled receive"
 247                        " packet descriptors.\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                        "show port (port_id) flow_ctrl"
 259                        "       Show flow control info of a port.\n\n"
 260                );
 261        }
 262
 263        if (show_all || !strcmp(res->section, "config")) {
 264                cmdline_printf(
 265                        cl,
 266                        "\n"
 267                        "Configuration:\n"
 268                        "--------------\n"
 269                        "Configuration changes only become active when"
 270                        " forwarding is started/restarted.\n\n"
 271
 272                        "set default\n"
 273                        "    Reset forwarding to the default configuration.\n\n"
 274
 275                        "set verbose (level)\n"
 276                        "    Set the debug verbosity level X.\n\n"
 277
 278                        "set log global|(type) (level)\n"
 279                        "    Set the log level.\n\n"
 280
 281                        "set nbport (num)\n"
 282                        "    Set number of ports.\n\n"
 283
 284                        "set nbcore (num)\n"
 285                        "    Set number of cores.\n\n"
 286
 287                        "set coremask (mask)\n"
 288                        "    Set the forwarding cores hexadecimal mask.\n\n"
 289
 290                        "set portmask (mask)\n"
 291                        "    Set the forwarding ports hexadecimal mask.\n\n"
 292
 293                        "set burst (num)\n"
 294                        "    Set number of packets per burst.\n\n"
 295
 296                        "set burst tx delay (microseconds) retry (num)\n"
 297                        "    Set the transmit delay time and number of retries,"
 298                        " effective when retry is enabled.\n\n"
 299
 300                        "set rxoffs (x[,y]*)\n"
 301                        "    Set the offset of each packet segment on"
 302                        " receiving if split feature is engaged."
 303                        " Affects only the queues configured with split"
 304                        " offloads.\n\n"
 305
 306                        "set rxpkts (x[,y]*)\n"
 307                        "    Set the length of each segment to scatter"
 308                        " packets on receiving if split feature is engaged."
 309                        " Affects only the queues configured with split"
 310                        " offloads.\n\n"
 311
 312                        "set txpkts (x[,y]*)\n"
 313                        "    Set the length of each segment of TXONLY"
 314                        " and optionally CSUM packets.\n\n"
 315
 316                        "set txsplit (off|on|rand)\n"
 317                        "    Set the split policy for the TX packets."
 318                        " Right now only applicable for CSUM and TXONLY"
 319                        " modes\n\n"
 320
 321                        "set txtimes (x, y)\n"
 322                        "    Set the scheduling on timestamps"
 323                        " timings for the TXONLY mode\n\n"
 324
 325                        "set corelist (x[,y]*)\n"
 326                        "    Set the list of forwarding cores.\n\n"
 327
 328                        "set portlist (x[,y]*)\n"
 329                        "    Set the list of forwarding ports.\n\n"
 330
 331                        "set port setup on (iterator|event)\n"
 332                        "    Select how attached port is retrieved for setup.\n\n"
 333
 334                        "set tx loopback (port_id) (on|off)\n"
 335                        "    Enable or disable tx loopback.\n\n"
 336
 337                        "set all queues drop (port_id) (on|off)\n"
 338                        "    Set drop enable bit for all queues.\n\n"
 339
 340                        "set vf split drop (port_id) (vf_id) (on|off)\n"
 341                        "    Set split drop enable bit for a VF from the PF.\n\n"
 342
 343                        "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
 344                        "    Set MAC antispoof for a VF from the PF.\n\n"
 345
 346                        "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
 347                        "    Enable MACsec offload.\n\n"
 348
 349                        "set macsec offload (port_id) off\n"
 350                        "    Disable MACsec offload.\n\n"
 351
 352                        "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
 353                        "    Configure MACsec secure connection (SC).\n\n"
 354
 355                        "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
 356                        "    Configure MACsec secure association (SA).\n\n"
 357
 358                        "set vf broadcast (port_id) (vf_id) (on|off)\n"
 359                        "    Set VF broadcast for a VF from the PF.\n\n"
 360
 361                        "vlan set stripq (on|off) (port_id,queue_id)\n"
 362                        "    Set the VLAN strip for a queue on a port.\n\n"
 363
 364                        "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
 365                        "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
 366
 367                        "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
 368                        "    Set VLAN insert for a VF from the PF.\n\n"
 369
 370                        "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
 371                        "    Set VLAN antispoof for a VF from the PF.\n\n"
 372
 373                        "set vf vlan tag (port_id) (vf_id) (on|off)\n"
 374                        "    Set VLAN tag for a VF from the PF.\n\n"
 375
 376                        "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
 377                        "    Set a VF's max bandwidth(Mbps).\n\n"
 378
 379                        "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
 380                        "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
 381
 382                        "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
 383                        "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
 384
 385                        "set tx strict-link-priority (port_id) (tc_bitmap)\n"
 386                        "    Set some TCs' strict link priority mode on a physical port.\n\n"
 387
 388                        "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
 389                        "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
 390
 391                        "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
 392                        "    Set the VLAN strip or filter or qinq strip or extend\n\n"
 393
 394                        "vlan set (inner|outer) tpid (value) (port_id)\n"
 395                        "    Set the VLAN TPID for Packet Filtering on"
 396                        " a port\n\n"
 397
 398                        "rx_vlan add (vlan_id|all) (port_id)\n"
 399                        "    Add a vlan_id, or all identifiers, to the set"
 400                        " of VLAN identifiers filtered by port_id.\n\n"
 401
 402                        "rx_vlan rm (vlan_id|all) (port_id)\n"
 403                        "    Remove a vlan_id, or all identifiers, from the set"
 404                        " of VLAN identifiers filtered by port_id.\n\n"
 405
 406                        "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
 407                        "    Add a vlan_id, to the set of VLAN identifiers"
 408                        "filtered for VF(s) from port_id.\n\n"
 409
 410                        "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
 411                        "    Remove a vlan_id, to the set of VLAN identifiers"
 412                        "filtered for VF(s) from port_id.\n\n"
 413
 414                        "rx_vxlan_port add (udp_port) (port_id)\n"
 415                        "    Add an UDP port for VXLAN packet filter on a port\n\n"
 416
 417                        "rx_vxlan_port rm (udp_port) (port_id)\n"
 418                        "    Remove an UDP port for VXLAN packet filter on a port\n\n"
 419
 420                        "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
 421                        "    Set hardware insertion of VLAN IDs (single or double VLAN "
 422                        "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
 423
 424                        "tx_vlan set pvid port_id vlan_id (on|off)\n"
 425                        "    Set port based TX VLAN insertion.\n\n"
 426
 427                        "tx_vlan reset (port_id)\n"
 428                        "    Disable hardware insertion of a VLAN header in"
 429                        " packets sent on a port.\n\n"
 430
 431                        "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
 432                        "    Select hardware or software calculation of the"
 433                        " checksum when transmitting a packet using the"
 434                        " csum forward engine.\n"
 435                        "    ip|udp|tcp|sctp always concern the inner layer.\n"
 436                        "    outer-ip concerns the outer IP layer in"
 437                        "    outer-udp concerns the outer UDP layer in"
 438                        " case the packet is recognized as a tunnel packet by"
 439                        " the forward engine (vxlan, gre and ipip are supported)\n"
 440                        "    Please check the NIC datasheet for HW limits.\n\n"
 441
 442                        "csum parse-tunnel (on|off) (tx_port_id)\n"
 443                        "    If disabled, treat tunnel packets as non-tunneled"
 444                        " packets (treat inner headers as payload). The port\n"
 445                        "    argument is the port used for TX in csum forward"
 446                        " engine.\n\n"
 447
 448                        "csum show (port_id)\n"
 449                        "    Display tx checksum offload configuration\n\n"
 450
 451                        "tso set (segsize) (portid)\n"
 452                        "    Enable TCP Segmentation Offload in csum forward"
 453                        " engine.\n"
 454                        "    Please check the NIC datasheet for HW limits.\n\n"
 455
 456                        "tso show (portid)"
 457                        "    Display the status of TCP Segmentation Offload.\n\n"
 458
 459                        "set port (port_id) gro on|off\n"
 460                        "    Enable or disable Generic Receive Offload in"
 461                        " csum forwarding engine.\n\n"
 462
 463                        "show port (port_id) gro\n"
 464                        "    Display GRO configuration.\n\n"
 465
 466                        "set gro flush (cycles)\n"
 467                        "    Set the cycle to flush GROed packets from"
 468                        " reassembly tables.\n\n"
 469
 470                        "set port (port_id) gso (on|off)"
 471                        "    Enable or disable Generic Segmentation Offload in"
 472                        " csum forwarding engine.\n\n"
 473
 474                        "set gso segsz (length)\n"
 475                        "    Set max packet length for output GSO segments,"
 476                        " including packet header and payload.\n\n"
 477
 478                        "show port (port_id) gso\n"
 479                        "    Show GSO configuration.\n\n"
 480
 481                        "set fwd (%s)\n"
 482                        "    Set packet forwarding mode.\n\n"
 483
 484                        "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
 485                        "    Add a MAC address on port_id.\n\n"
 486
 487                        "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
 488                        "    Remove a MAC address from port_id.\n\n"
 489
 490                        "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
 491                        "    Set the default MAC address for port_id.\n\n"
 492
 493                        "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
 494                        "    Add a MAC address for a VF on the port.\n\n"
 495
 496                        "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
 497                        "    Set the MAC address for a VF from the PF.\n\n"
 498
 499                        "set eth-peer (port_id) (peer_addr)\n"
 500                        "    set the peer address for certain port.\n\n"
 501
 502                        "set port (port_id) uta (mac_address|all) (on|off)\n"
 503                        "    Add/Remove a or all unicast hash filter(s)"
 504                        "from port X.\n\n"
 505
 506                        "set promisc (port_id|all) (on|off)\n"
 507                        "    Set the promiscuous mode on port_id, or all.\n\n"
 508
 509                        "set allmulti (port_id|all) (on|off)\n"
 510                        "    Set the allmulti mode on port_id, or all.\n\n"
 511
 512                        "set vf promisc (port_id) (vf_id) (on|off)\n"
 513                        "    Set unicast promiscuous mode for a VF from the PF.\n\n"
 514
 515                        "set vf allmulti (port_id) (vf_id) (on|off)\n"
 516                        "    Set multicast promiscuous mode for a VF from the PF.\n\n"
 517
 518                        "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
 519                        " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
 520                        " (on|off) autoneg (on|off) (port_id)\n"
 521                        "set flow_ctrl rx (on|off) (portid)\n"
 522                        "set flow_ctrl tx (on|off) (portid)\n"
 523                        "set flow_ctrl high_water (high_water) (portid)\n"
 524                        "set flow_ctrl low_water (low_water) (portid)\n"
 525                        "set flow_ctrl pause_time (pause_time) (portid)\n"
 526                        "set flow_ctrl send_xon (send_xon) (portid)\n"
 527                        "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
 528                        "set flow_ctrl autoneg (on|off) (port_id)\n"
 529                        "    Set the link flow control parameter on a port.\n\n"
 530
 531                        "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
 532                        " (low_water) (pause_time) (priority) (port_id)\n"
 533                        "    Set the priority flow control parameter on a"
 534                        " port.\n\n"
 535
 536                        "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
 537                        "    Set statistics mapping (qmapping 0..15) for RX/TX"
 538                        " queue on port.\n"
 539                        "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
 540                        " on port 0 to mapping 5.\n\n"
 541
 542                        "set xstats-hide-zero on|off\n"
 543                        "    Set the option to hide the zero values"
 544                        " for xstats display.\n"
 545
 546                        "set record-core-cycles on|off\n"
 547                        "    Set the option to enable measurement of CPU cycles.\n"
 548
 549                        "set record-burst-stats on|off\n"
 550                        "    Set the option to enable display of RX and TX bursts.\n"
 551
 552                        "set port (port_id) vf (vf_id) rx|tx on|off\n"
 553                        "    Enable/Disable a VF receive/tranmit from a port\n\n"
 554
 555                        "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
 556                        "|MPE) (on|off)\n"
 557                        "    AUPE:accepts untagged VLAN;"
 558                        "ROPE:accept unicast hash\n\n"
 559                        "    BAM:accepts broadcast packets;"
 560                        "MPE:accepts all multicast packets\n\n"
 561                        "    Enable/Disable a VF receive mode of a port\n\n"
 562
 563                        "set port (port_id) queue (queue_id) rate (rate_num)\n"
 564                        "    Set rate limit for a queue of a port\n\n"
 565
 566                        "set port (port_id) vf (vf_id) rate (rate_num) "
 567                        "queue_mask (queue_mask_value)\n"
 568                        "    Set rate limit for queues in VF of a port\n\n"
 569
 570                        "set port (port_id) mirror-rule (rule_id)"
 571                        " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
 572                        " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
 573                        "   Set pool or vlan type mirror rule on a port.\n"
 574                        "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
 575                        " dst-pool 0 on' enable mirror traffic with vlan 0,1"
 576                        " to pool 0.\n\n"
 577
 578                        "set port (port_id) mirror-rule (rule_id)"
 579                        " (uplink-mirror|downlink-mirror) dst-pool"
 580                        " (pool_id) (on|off)\n"
 581                        "   Set uplink or downlink type mirror rule on a port.\n"
 582                        "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
 583                        " 0 on' enable mirror income traffic to pool 0.\n\n"
 584
 585                        "reset port (port_id) mirror-rule (rule_id)\n"
 586                        "   Reset a mirror rule.\n\n"
 587
 588                        "set flush_rx (on|off)\n"
 589                        "   Flush (default) or don't flush RX streams before"
 590                        " forwarding. Mainly used with PCAP drivers.\n\n"
 591
 592                        "set bypass mode (normal|bypass|isolate) (port_id)\n"
 593                        "   Set the bypass mode for the lowest port on bypass enabled"
 594                        " NIC.\n\n"
 595
 596                        "set bypass event (timeout|os_on|os_off|power_on|power_off) "
 597                        "mode (normal|bypass|isolate) (port_id)\n"
 598                        "   Set the event required to initiate specified bypass mode for"
 599                        " the lowest port on a bypass enabled NIC where:\n"
 600                        "       timeout   = enable bypass after watchdog timeout.\n"
 601                        "       os_on     = enable bypass when OS/board is powered on.\n"
 602                        "       os_off    = enable bypass when OS/board is powered off.\n"
 603                        "       power_on  = enable bypass when power supply is turned on.\n"
 604                        "       power_off = enable bypass when power supply is turned off."
 605                        "\n\n"
 606
 607                        "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
 608                        "   Set the bypass watchdog timeout to 'n' seconds"
 609                        " where 0 = instant.\n\n"
 610
 611                        "show bypass config (port_id)\n"
 612                        "   Show the bypass configuration for a bypass enabled NIC"
 613                        " using the lowest port on the NIC.\n\n"
 614
 615#ifdef RTE_NET_BOND
 616                        "create bonded device (mode) (socket)\n"
 617                        "       Create a new bonded device with specific bonding mode and socket.\n\n"
 618
 619                        "add bonding slave (slave_id) (port_id)\n"
 620                        "       Add a slave device to a bonded device.\n\n"
 621
 622                        "remove bonding slave (slave_id) (port_id)\n"
 623                        "       Remove a slave device from a bonded device.\n\n"
 624
 625                        "set bonding mode (value) (port_id)\n"
 626                        "       Set the bonding mode on a bonded device.\n\n"
 627
 628                        "set bonding primary (slave_id) (port_id)\n"
 629                        "       Set the primary slave for a bonded device.\n\n"
 630
 631                        "show bonding config (port_id)\n"
 632                        "       Show the bonding config for port_id.\n\n"
 633
 634                        "set bonding mac_addr (port_id) (address)\n"
 635                        "       Set the MAC address of a bonded device.\n\n"
 636
 637                        "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
 638                        "       Set Aggregation mode for IEEE802.3AD (mode 4)"
 639
 640                        "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
 641                        "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
 642
 643                        "set bonding mon_period (port_id) (value)\n"
 644                        "       Set the bonding link status monitoring polling period in ms.\n\n"
 645
 646                        "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
 647                        "       Enable/disable dedicated queues for LACP control traffic.\n\n"
 648
 649#endif
 650                        "set link-up port (port_id)\n"
 651                        "       Set link up for a port.\n\n"
 652
 653                        "set link-down port (port_id)\n"
 654                        "       Set link down for a port.\n\n"
 655
 656                        "ddp add (port_id) (profile_path[,backup_profile_path])\n"
 657                        "    Load a profile package on a port\n\n"
 658
 659                        "ddp del (port_id) (backup_profile_path)\n"
 660                        "    Delete a profile package from a port\n\n"
 661
 662                        "ptype mapping get (port_id) (valid_only)\n"
 663                        "    Get ptype mapping on a port\n\n"
 664
 665                        "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
 666                        "    Replace target with the pkt_type in ptype mapping\n\n"
 667
 668                        "ptype mapping reset (port_id)\n"
 669                        "    Reset ptype mapping on a port\n\n"
 670
 671                        "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
 672                        "    Update a ptype mapping item on a port\n\n"
 673
 674                        "set port (port_id) ptype_mask (ptype_mask)\n"
 675                        "    set packet types classification for a specific port\n\n"
 676
 677                        "set port (port_id) queue-region region_id (value) "
 678                        "queue_start_index (value) queue_num (value)\n"
 679                        "    Set a queue region on a port\n\n"
 680
 681                        "set port (port_id) queue-region region_id (value) "
 682                        "flowtype (value)\n"
 683                        "    Set a flowtype region index on a port\n\n"
 684
 685                        "set port (port_id) queue-region UP (value) region_id (value)\n"
 686                        "    Set the mapping of User Priority to "
 687                        "queue region on a port\n\n"
 688
 689                        "set port (port_id) queue-region flush (on|off)\n"
 690                        "    flush all queue region related configuration\n\n"
 691
 692                        "show port meter cap (port_id)\n"
 693                        "    Show port meter capability information\n\n"
 694
 695                        "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
 696                        "    meter profile add - srtcm rfc 2697\n\n"
 697
 698                        "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
 699                        "    meter profile add - trtcm rfc 2698\n\n"
 700
 701                        "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
 702                        "    meter profile add - trtcm rfc 4115\n\n"
 703
 704                        "del port meter profile (port_id) (profile_id)\n"
 705                        "    meter profile delete\n\n"
 706
 707                        "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
 708                        "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
 709                        "(dscp_tbl_entry63)]\n"
 710                        "    meter create\n\n"
 711
 712                        "enable port meter (port_id) (mtr_id)\n"
 713                        "    meter enable\n\n"
 714
 715                        "disable port meter (port_id) (mtr_id)\n"
 716                        "    meter disable\n\n"
 717
 718                        "del port meter (port_id) (mtr_id)\n"
 719                        "    meter delete\n\n"
 720
 721                        "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
 722                        "y_actions (actions) r_actions (actions)\n"
 723                        "    meter policy add\n\n"
 724
 725                        "del port meter policy (port_id) (policy_id)\n"
 726                        "    meter policy delete\n\n"
 727
 728                        "set port meter profile (port_id) (mtr_id) (profile_id)\n"
 729                        "    meter update meter profile\n\n"
 730
 731                        "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
 732                        "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
 733                        "    update meter dscp table entries\n\n"
 734
 735                        "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
 736                        "(action0) [(action1) (action2)]\n"
 737                        "    meter update policer action\n\n"
 738
 739                        "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
 740                        "    meter update stats\n\n"
 741
 742                        "show port (port_id) queue-region\n"
 743                        "    show all queue region related configuration info\n\n"
 744
 745                        "set port (port_id) fec_mode auto|off|rs|baser\n"
 746                        "    set fec mode for a specific port\n\n"
 747
 748                        , list_pkt_forwarding_modes()
 749                );
 750        }
 751
 752        if (show_all || !strcmp(res->section, "ports")) {
 753
 754                cmdline_printf(
 755                        cl,
 756                        "\n"
 757                        "Port Operations:\n"
 758                        "----------------\n\n"
 759
 760                        "port start (port_id|all)\n"
 761                        "    Start all ports or port_id.\n\n"
 762
 763                        "port stop (port_id|all)\n"
 764                        "    Stop all ports or port_id.\n\n"
 765
 766                        "port close (port_id|all)\n"
 767                        "    Close all ports or port_id.\n\n"
 768
 769                        "port reset (port_id|all)\n"
 770                        "    Reset all ports or port_id.\n\n"
 771
 772                        "port attach (ident)\n"
 773                        "    Attach physical or virtual dev by pci address or virtual device name\n\n"
 774
 775                        "port detach (port_id)\n"
 776                        "    Detach physical or virtual dev by port_id\n\n"
 777
 778                        "port config (port_id|all)"
 779                        " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
 780                        " duplex (half|full|auto)\n"
 781                        "    Set speed and duplex for all ports or port_id\n\n"
 782
 783                        "port config (port_id|all) loopback (mode)\n"
 784                        "    Set loopback mode for all ports or port_id\n\n"
 785
 786                        "port config all (rxq|txq|rxd|txd) (value)\n"
 787                        "    Set number for rxq/txq/rxd/txd.\n\n"
 788
 789                        "port config all max-pkt-len (value)\n"
 790                        "    Set the max packet length.\n\n"
 791
 792                        "port config all max-lro-pkt-size (value)\n"
 793                        "    Set the max LRO aggregated packet size.\n\n"
 794
 795                        "port config all drop-en (on|off)\n"
 796                        "    Enable or disable packet drop on all RX queues of all ports when no "
 797                        "receive buffers available.\n\n"
 798
 799                        "port config all rss (all|default|ip|tcp|udp|sctp|"
 800                        "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
 801                        "level-outer|level-inner|<flowtype_id>)\n"
 802                        "    Set the RSS mode.\n\n"
 803
 804                        "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
 805                        "    Set the RSS redirection table.\n\n"
 806
 807                        "port config (port_id) dcb vt (on|off) (traffic_class)"
 808                        " pfc (on|off)\n"
 809                        "    Set the DCB mode.\n\n"
 810
 811                        "port config all burst (value)\n"
 812                        "    Set the number of packets per burst.\n\n"
 813
 814                        "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
 815                        " (value)\n"
 816                        "    Set the ring prefetch/host/writeback threshold"
 817                        " for tx/rx queue.\n\n"
 818
 819                        "port config all (txfreet|txrst|rxfreet) (value)\n"
 820                        "    Set free threshold for rx/tx, or set"
 821                        " tx rs bit threshold.\n\n"
 822                        "port config mtu X value\n"
 823                        "    Set the MTU of port X to a given value\n\n"
 824
 825                        "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
 826                        "    Set a rx/tx queue's ring size configuration, the new"
 827                        " value will take effect after command that (re-)start the port"
 828                        " or command that setup the specific queue\n\n"
 829
 830                        "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
 831                        "    Start/stop a rx/tx queue of port X. Only take effect"
 832                        " when port X is started\n\n"
 833
 834                        "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
 835                        "    Switch on/off a deferred start of port X rx/tx queue. Only"
 836                        " take effect when port X is stopped.\n\n"
 837
 838                        "port (port_id) (rxq|txq) (queue_id) setup\n"
 839                        "    Setup a rx/tx queue of port X.\n\n"
 840
 841                        "port config (port_id) pctype mapping reset\n"
 842                        "    Reset flow type to pctype mapping on a port\n\n"
 843
 844                        "port config (port_id) pctype mapping update"
 845                        " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
 846                        "    Update a flow type to pctype mapping item on a port\n\n"
 847
 848                        "port config (port_id) pctype (pctype_id) hash_inset|"
 849                        "fdir_inset|fdir_flx_inset get|set|clear field\n"
 850                        " (field_idx)\n"
 851                        "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
 852
 853                        "port config (port_id) pctype (pctype_id) hash_inset|"
 854                        "fdir_inset|fdir_flx_inset clear all"
 855                        "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
 856
 857                        "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
 858                        "    Add/remove UDP tunnel port for tunneling offload\n\n"
 859
 860                        "port config <port_id> rx_offload vlan_strip|"
 861                        "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
 862                        "outer_ipv4_cksum|macsec_strip|header_split|"
 863                        "vlan_filter|vlan_extend|jumbo_frame|scatter|"
 864                        "buffer_split|timestamp|security|keep_crc on|off\n"
 865                        "     Enable or disable a per port Rx offloading"
 866                        " on all Rx queues of a port\n\n"
 867
 868                        "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
 869                        "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
 870                        "outer_ipv4_cksum|macsec_strip|header_split|"
 871                        "vlan_filter|vlan_extend|jumbo_frame|scatter|"
 872                        "buffer_split|timestamp|security|keep_crc on|off\n"
 873                        "    Enable or disable a per queue Rx offloading"
 874                        " only on a specific Rx queue\n\n"
 875
 876                        "port config (port_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|"
 880                        "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
 881                        "security on|off\n"
 882                        "    Enable or disable a per port Tx offloading"
 883                        " on all Tx queues of a port\n\n"
 884
 885                        "port (port_id) txq (queue_id) tx_offload vlan_insert|"
 886                        "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
 887                        "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
 888                        "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
 889                        "|mt_lockfree|multi_segs|mbuf_fast_free|security"
 890                        " on|off\n"
 891                        "    Enable or disable a per queue Tx offloading"
 892                        " only on a specific Tx queue\n\n"
 893
 894                        "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
 895                        "    Load an eBPF program as a callback"
 896                        " for particular RX/TX queue\n\n"
 897
 898                        "bpf-unload rx|tx (port) (queue)\n"
 899                        "    Unload previously loaded eBPF program"
 900                        " for particular RX/TX queue\n\n"
 901
 902                        "port config (port_id) tx_metadata (value)\n"
 903                        "    Set Tx metadata value per port. Testpmd will add this value"
 904                        " to any Tx packet sent from this port\n\n"
 905
 906                        "port config (port_id) dynf (name) set|clear\n"
 907                        "    Register a dynf and Set/clear this flag on Tx. "
 908                        "Testpmd will set this value to any Tx packet "
 909                        "sent from this port\n\n"
 910
 911                        "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
 912                        "    Cleanup txq mbufs for a specific Tx queue\n\n"
 913                );
 914        }
 915
 916        if (show_all || !strcmp(res->section, "registers")) {
 917
 918                cmdline_printf(
 919                        cl,
 920                        "\n"
 921                        "Registers:\n"
 922                        "----------\n\n"
 923
 924                        "read reg (port_id) (address)\n"
 925                        "    Display value of a port register.\n\n"
 926
 927                        "read regfield (port_id) (address) (bit_x) (bit_y)\n"
 928                        "    Display a port register bit field.\n\n"
 929
 930                        "read regbit (port_id) (address) (bit_x)\n"
 931                        "    Display a single port register bit.\n\n"
 932
 933                        "write reg (port_id) (address) (value)\n"
 934                        "    Set value of a port register.\n\n"
 935
 936                        "write regfield (port_id) (address) (bit_x) (bit_y)"
 937                        " (value)\n"
 938                        "    Set bit field of a port register.\n\n"
 939
 940                        "write regbit (port_id) (address) (bit_x) (value)\n"
 941                        "    Set single bit value of a port register.\n\n"
 942                );
 943        }
 944        if (show_all || !strcmp(res->section, "filters")) {
 945
 946                cmdline_printf(
 947                        cl,
 948                        "\n"
 949                        "filters:\n"
 950                        "--------\n\n"
 951
 952#ifdef RTE_NET_I40E
 953                        "flow_director_filter (port_id) mode raw (add|del|update)"
 954                        " flow (flow_id) (drop|fwd) queue (queue_id)"
 955                        " fd_id (fd_id_value) packet (packet file name)\n"
 956                        "    Add/Del a raw type flow director filter.\n\n"
 957#endif
 958
 959                        "flow_director_mask (port_id) mode IP vlan (vlan_value)"
 960                        " src_mask (ipv4_src) (ipv6_src) (src_port)"
 961                        " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
 962                        "    Set flow director IP mask.\n\n"
 963
 964                        "flow_director_mask (port_id) mode MAC-VLAN"
 965                        " vlan (vlan_value)\n"
 966                        "    Set flow director MAC-VLAN mask.\n\n"
 967
 968                        "flow_director_mask (port_id) mode Tunnel"
 969                        " vlan (vlan_value) mac (mac_value)"
 970                        " tunnel-type (tunnel_type_value)"
 971                        " tunnel-id (tunnel_id_value)\n"
 972                        "    Set flow director Tunnel mask.\n\n"
 973
 974                        "flow_director_flex_payload (port_id)"
 975                        " (raw|l2|l3|l4) (config)\n"
 976                        "    Configure flex payload selection.\n\n"
 977
 978                        "flow validate {port_id}"
 979                        " [group {group_id}] [priority {level}]"
 980                        " [ingress] [egress]"
 981                        " pattern {item} [/ {item} [...]] / end"
 982                        " actions {action} [/ {action} [...]] / end\n"
 983                        "    Check whether a flow rule can be created.\n\n"
 984
 985                        "flow create {port_id}"
 986                        " [group {group_id}] [priority {level}]"
 987                        " [ingress] [egress]"
 988                        " pattern {item} [/ {item} [...]] / end"
 989                        " actions {action} [/ {action} [...]] / end\n"
 990                        "    Create a flow rule.\n\n"
 991
 992                        "flow destroy {port_id} rule {rule_id} [...]\n"
 993                        "    Destroy specific flow rules.\n\n"
 994
 995                        "flow flush {port_id}\n"
 996                        "    Destroy all flow rules.\n\n"
 997
 998                        "flow query {port_id} {rule_id} {action}\n"
 999                        "    Query an existing flow rule.\n\n"
1000
1001                        "flow list {port_id} [group {group_id}] [...]\n"
1002                        "    List existing flow rules sorted by priority,"
1003                        " filtered by group identifiers.\n\n"
1004
1005                        "flow isolate {port_id} {boolean}\n"
1006                        "    Restrict ingress traffic to the defined"
1007                        " flow rules\n\n"
1008
1009                        "flow aged {port_id} [destroy]\n"
1010                        "    List and destroy aged flows"
1011                        " flow rules\n\n"
1012
1013                        "flow indirect_action {port_id} create"
1014                        " [action_id {indirect_action_id}]"
1015                        " [ingress] [egress]"
1016                        " action {action} / end\n"
1017                        "    Create indirect action.\n\n"
1018
1019                        "flow indirect_action {port_id} update"
1020                        " {indirect_action_id} action {action} / end\n"
1021                        "    Update indirect action.\n\n"
1022
1023                        "flow indirect_action {port_id} destroy"
1024                        " action_id {indirect_action_id} [...]\n"
1025                        "    Destroy specific indirect actions.\n\n"
1026
1027                        "flow indirect_action {port_id} query"
1028                        " {indirect_action_id}\n"
1029                        "    Query an existing indirect action.\n\n"
1030
1031                        "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1032                        " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1033                        " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1034                        "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                        "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1037                        " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1038                        " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1039                        " eth-dst (eth-dst)\n"
1040                        "       Configure the VXLAN encapsulation for flows.\n\n"
1041
1042                        "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1043                        " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1044                        " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1045                        " eth-dst (eth-dst)\n"
1046                        "       Configure the VXLAN encapsulation for flows.\n\n"
1047
1048                        "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1049                        " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1050                        " (eth-dst)\n"
1051                        "       Configure the NVGRE encapsulation for flows.\n\n"
1052
1053                        "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1054                        " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1055                        " eth-src (eth-src) eth-dst (eth-dst)\n"
1056                        "       Configure the NVGRE encapsulation for flows.\n\n"
1057
1058                        "set raw_encap {flow items}\n"
1059                        "       Configure the encapsulation with raw data.\n\n"
1060
1061                        "set raw_decap {flow items}\n"
1062                        "       Configure the decapsulation with raw data.\n\n"
1063
1064                );
1065        }
1066
1067        if (show_all || !strcmp(res->section, "traffic_management")) {
1068                cmdline_printf(
1069                        cl,
1070                        "\n"
1071                        "Traffic Management:\n"
1072                        "--------------\n"
1073                        "show port tm cap (port_id)\n"
1074                        "       Display the port TM capability.\n\n"
1075
1076                        "show port tm level cap (port_id) (level_id)\n"
1077                        "       Display the port TM hierarchical level capability.\n\n"
1078
1079                        "show port tm node cap (port_id) (node_id)\n"
1080                        "       Display the port TM node capability.\n\n"
1081
1082                        "show port tm node type (port_id) (node_id)\n"
1083                        "       Display the port TM node type.\n\n"
1084
1085                        "show port tm node stats (port_id) (node_id) (clear)\n"
1086                        "       Display the port TM node stats.\n\n"
1087
1088                        "add port tm node shaper profile (port_id) (shaper_profile_id)"
1089                        " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1090                        " (packet_length_adjust) (packet_mode)\n"
1091                        "       Add port tm node private shaper profile.\n\n"
1092
1093                        "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1094                        "       Delete port tm node private shaper profile.\n\n"
1095
1096                        "add port tm node shared shaper (port_id) (shared_shaper_id)"
1097                        " (shaper_profile_id)\n"
1098                        "       Add/update port tm node shared shaper.\n\n"
1099
1100                        "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1101                        "       Delete port tm node shared shaper.\n\n"
1102
1103                        "set port tm node shaper profile (port_id) (node_id)"
1104                        " (shaper_profile_id)\n"
1105                        "       Set port tm node shaper profile.\n\n"
1106
1107                        "add port tm node wred profile (port_id) (wred_profile_id)"
1108                        " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1109                        " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1110                        " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1111                        "       Add port tm node wred profile.\n\n"
1112
1113                        "del port tm node wred profile (port_id) (wred_profile_id)\n"
1114                        "       Delete port tm node wred profile.\n\n"
1115
1116                        "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1117                        " (priority) (weight) (level_id) (shaper_profile_id)"
1118                        " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1119                        " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                        "       Add port tm nonleaf node.\n\n"
1121
1122                        "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1123                        " (priority) (weight) (level_id) (shaper_profile_id)"
1124                        " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1125                        " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1126                        "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1127
1128                        "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1129                        " (priority) (weight) (level_id) (shaper_profile_id)"
1130                        " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1131                        " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1132                        "       Add port tm leaf node.\n\n"
1133
1134                        "del port tm node (port_id) (node_id)\n"
1135                        "       Delete port tm node.\n\n"
1136
1137                        "set port tm node parent (port_id) (node_id) (parent_node_id)"
1138                        " (priority) (weight)\n"
1139                        "       Set port tm node parent.\n\n"
1140
1141                        "suspend port tm node (port_id) (node_id)"
1142                        "       Suspend tm node.\n\n"
1143
1144                        "resume port tm node (port_id) (node_id)"
1145                        "       Resume tm node.\n\n"
1146
1147                        "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1148                        "       Commit tm hierarchy.\n\n"
1149
1150                        "set port tm mark ip_ecn (port) (green) (yellow)"
1151                        " (red)\n"
1152                        "    Enables/Disables the traffic management marking"
1153                        " for IP ECN (Explicit Congestion Notification)"
1154                        " packets on a given port\n\n"
1155
1156                        "set port tm mark ip_dscp (port) (green) (yellow)"
1157                        " (red)\n"
1158                        "    Enables/Disables the traffic management marking"
1159                        " on the port for IP dscp packets\n\n"
1160
1161                        "set port tm mark vlan_dei (port) (green) (yellow)"
1162                        " (red)\n"
1163                        "    Enables/Disables the traffic management marking"
1164                        " on the port for VLAN packets with DEI enabled\n\n"
1165                );
1166        }
1167
1168        if (show_all || !strcmp(res->section, "devices")) {
1169                cmdline_printf(
1170                        cl,
1171                        "\n"
1172                        "Device Operations:\n"
1173                        "--------------\n"
1174                        "device detach (identifier)\n"
1175                        "       Detach device by identifier.\n\n"
1176                );
1177        }
1178
1179}
1180
1181cmdline_parse_token_string_t cmd_help_long_help =
1182        TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1183
1184cmdline_parse_token_string_t cmd_help_long_section =
1185        TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1186                        "all#control#display#config#"
1187                        "ports#registers#filters#traffic_management#devices");
1188
1189cmdline_parse_inst_t cmd_help_long = {
1190        .f = cmd_help_long_parsed,
1191        .data = NULL,
1192        .help_str = "help all|control|display|config|ports|register|"
1193                "filters|traffic_management|devices: "
1194                "Show help",
1195        .tokens = {
1196                (void *)&cmd_help_long_help,
1197                (void *)&cmd_help_long_section,
1198                NULL,
1199        },
1200};
1201
1202
1203/* *** start/stop/close all ports *** */
1204struct cmd_operate_port_result {
1205        cmdline_fixed_string_t keyword;
1206        cmdline_fixed_string_t name;
1207        cmdline_fixed_string_t value;
1208};
1209
1210static void cmd_operate_port_parsed(void *parsed_result,
1211                                __rte_unused struct cmdline *cl,
1212                                __rte_unused void *data)
1213{
1214        struct cmd_operate_port_result *res = parsed_result;
1215
1216        if (!strcmp(res->name, "start"))
1217                start_port(RTE_PORT_ALL);
1218        else if (!strcmp(res->name, "stop"))
1219                stop_port(RTE_PORT_ALL);
1220        else if (!strcmp(res->name, "close"))
1221                close_port(RTE_PORT_ALL);
1222        else if (!strcmp(res->name, "reset"))
1223                reset_port(RTE_PORT_ALL);
1224        else
1225                fprintf(stderr, "Unknown parameter\n");
1226}
1227
1228cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1229        TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1230                                                                "port");
1231cmdline_parse_token_string_t cmd_operate_port_all_port =
1232        TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1233                                                "start#stop#close#reset");
1234cmdline_parse_token_string_t cmd_operate_port_all_all =
1235        TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1236
1237cmdline_parse_inst_t cmd_operate_port = {
1238        .f = cmd_operate_port_parsed,
1239        .data = NULL,
1240        .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1241        .tokens = {
1242                (void *)&cmd_operate_port_all_cmd,
1243                (void *)&cmd_operate_port_all_port,
1244                (void *)&cmd_operate_port_all_all,
1245                NULL,
1246        },
1247};
1248
1249/* *** start/stop/close specific port *** */
1250struct cmd_operate_specific_port_result {
1251        cmdline_fixed_string_t keyword;
1252        cmdline_fixed_string_t name;
1253        uint8_t value;
1254};
1255
1256static void cmd_operate_specific_port_parsed(void *parsed_result,
1257                        __rte_unused struct cmdline *cl,
1258                                __rte_unused void *data)
1259{
1260        struct cmd_operate_specific_port_result *res = parsed_result;
1261
1262        if (!strcmp(res->name, "start"))
1263                start_port(res->value);
1264        else if (!strcmp(res->name, "stop"))
1265                stop_port(res->value);
1266        else if (!strcmp(res->name, "close"))
1267                close_port(res->value);
1268        else if (!strcmp(res->name, "reset"))
1269                reset_port(res->value);
1270        else
1271                fprintf(stderr, "Unknown parameter\n");
1272}
1273
1274cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1275        TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1276                                                        keyword, "port");
1277cmdline_parse_token_string_t cmd_operate_specific_port_port =
1278        TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1279                                                name, "start#stop#close#reset");
1280cmdline_parse_token_num_t cmd_operate_specific_port_id =
1281        TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1282                                                        value, RTE_UINT8);
1283
1284cmdline_parse_inst_t cmd_operate_specific_port = {
1285        .f = cmd_operate_specific_port_parsed,
1286        .data = NULL,
1287        .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1288        .tokens = {
1289                (void *)&cmd_operate_specific_port_cmd,
1290                (void *)&cmd_operate_specific_port_port,
1291                (void *)&cmd_operate_specific_port_id,
1292                NULL,
1293        },
1294};
1295
1296/* *** enable port setup (after attach) via iterator or event *** */
1297struct cmd_set_port_setup_on_result {
1298        cmdline_fixed_string_t set;
1299        cmdline_fixed_string_t port;
1300        cmdline_fixed_string_t setup;
1301        cmdline_fixed_string_t on;
1302        cmdline_fixed_string_t mode;
1303};
1304
1305static void cmd_set_port_setup_on_parsed(void *parsed_result,
1306                                __rte_unused struct cmdline *cl,
1307                                __rte_unused void *data)
1308{
1309        struct cmd_set_port_setup_on_result *res = parsed_result;
1310
1311        if (strcmp(res->mode, "event") == 0)
1312                setup_on_probe_event = true;
1313        else if (strcmp(res->mode, "iterator") == 0)
1314                setup_on_probe_event = false;
1315        else
1316                fprintf(stderr, "Unknown mode\n");
1317}
1318
1319cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1320        TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1321                        set, "set");
1322cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1323        TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1324                        port, "port");
1325cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1326        TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1327                        setup, "setup");
1328cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1329        TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1330                        on, "on");
1331cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1332        TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1333                        mode, "iterator#event");
1334
1335cmdline_parse_inst_t cmd_set_port_setup_on = {
1336        .f = cmd_set_port_setup_on_parsed,
1337        .data = NULL,
1338        .help_str = "set port setup on iterator|event",
1339        .tokens = {
1340                (void *)&cmd_set_port_setup_on_set,
1341                (void *)&cmd_set_port_setup_on_port,
1342                (void *)&cmd_set_port_setup_on_setup,
1343                (void *)&cmd_set_port_setup_on_on,
1344                (void *)&cmd_set_port_setup_on_mode,
1345                NULL,
1346        },
1347};
1348
1349/* *** attach a specified port *** */
1350struct cmd_operate_attach_port_result {
1351        cmdline_fixed_string_t port;
1352        cmdline_fixed_string_t keyword;
1353        cmdline_multi_string_t identifier;
1354};
1355
1356static void cmd_operate_attach_port_parsed(void *parsed_result,
1357                                __rte_unused struct cmdline *cl,
1358                                __rte_unused void *data)
1359{
1360        struct cmd_operate_attach_port_result *res = parsed_result;
1361
1362        if (!strcmp(res->keyword, "attach"))
1363                attach_port(res->identifier);
1364        else
1365                fprintf(stderr, "Unknown parameter\n");
1366}
1367
1368cmdline_parse_token_string_t cmd_operate_attach_port_port =
1369        TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1370                        port, "port");
1371cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1372        TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1373                        keyword, "attach");
1374cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1375        TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1376                        identifier, TOKEN_STRING_MULTI);
1377
1378cmdline_parse_inst_t cmd_operate_attach_port = {
1379        .f = cmd_operate_attach_port_parsed,
1380        .data = NULL,
1381        .help_str = "port attach <identifier>: "
1382                "(identifier: pci address or virtual dev name)",
1383        .tokens = {
1384                (void *)&cmd_operate_attach_port_port,
1385                (void *)&cmd_operate_attach_port_keyword,
1386                (void *)&cmd_operate_attach_port_identifier,
1387                NULL,
1388        },
1389};
1390
1391/* *** detach a specified port *** */
1392struct cmd_operate_detach_port_result {
1393        cmdline_fixed_string_t port;
1394        cmdline_fixed_string_t keyword;
1395        portid_t port_id;
1396};
1397
1398static void cmd_operate_detach_port_parsed(void *parsed_result,
1399                                __rte_unused struct cmdline *cl,
1400                                __rte_unused void *data)
1401{
1402        struct cmd_operate_detach_port_result *res = parsed_result;
1403
1404        if (!strcmp(res->keyword, "detach")) {
1405                RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1406                detach_port_device(res->port_id);
1407        } else {
1408                fprintf(stderr, "Unknown parameter\n");
1409        }
1410}
1411
1412cmdline_parse_token_string_t cmd_operate_detach_port_port =
1413        TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1414                        port, "port");
1415cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1416        TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1417                        keyword, "detach");
1418cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1419        TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1420                        port_id, RTE_UINT16);
1421
1422cmdline_parse_inst_t cmd_operate_detach_port = {
1423        .f = cmd_operate_detach_port_parsed,
1424        .data = NULL,
1425        .help_str = "port detach <port_id>",
1426        .tokens = {
1427                (void *)&cmd_operate_detach_port_port,
1428                (void *)&cmd_operate_detach_port_keyword,
1429                (void *)&cmd_operate_detach_port_port_id,
1430                NULL,
1431        },
1432};
1433
1434/* *** detach device by identifier *** */
1435struct cmd_operate_detach_device_result {
1436        cmdline_fixed_string_t device;
1437        cmdline_fixed_string_t keyword;
1438        cmdline_fixed_string_t identifier;
1439};
1440
1441static void cmd_operate_detach_device_parsed(void *parsed_result,
1442                                __rte_unused struct cmdline *cl,
1443                                __rte_unused void *data)
1444{
1445        struct cmd_operate_detach_device_result *res = parsed_result;
1446
1447        if (!strcmp(res->keyword, "detach"))
1448                detach_devargs(res->identifier);
1449        else
1450                fprintf(stderr, "Unknown parameter\n");
1451}
1452
1453cmdline_parse_token_string_t cmd_operate_detach_device_device =
1454        TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1455                        device, "device");
1456cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1457        TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1458                        keyword, "detach");
1459cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1460        TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1461                        identifier, NULL);
1462
1463cmdline_parse_inst_t cmd_operate_detach_device = {
1464        .f = cmd_operate_detach_device_parsed,
1465        .data = NULL,
1466        .help_str = "device detach <identifier>:"
1467                "(identifier: pci address or virtual dev name)",
1468        .tokens = {
1469                (void *)&cmd_operate_detach_device_device,
1470                (void *)&cmd_operate_detach_device_keyword,
1471                (void *)&cmd_operate_detach_device_identifier,
1472                NULL,
1473        },
1474};
1475/* *** configure speed for all ports *** */
1476struct cmd_config_speed_all {
1477        cmdline_fixed_string_t port;
1478        cmdline_fixed_string_t keyword;
1479        cmdline_fixed_string_t all;
1480        cmdline_fixed_string_t item1;
1481        cmdline_fixed_string_t item2;
1482        cmdline_fixed_string_t value1;
1483        cmdline_fixed_string_t value2;
1484};
1485
1486static int
1487parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1488{
1489
1490        int duplex;
1491
1492        if (!strcmp(duplexstr, "half")) {
1493                duplex = ETH_LINK_HALF_DUPLEX;
1494        } else if (!strcmp(duplexstr, "full")) {
1495                duplex = ETH_LINK_FULL_DUPLEX;
1496        } else if (!strcmp(duplexstr, "auto")) {
1497                duplex = ETH_LINK_FULL_DUPLEX;
1498        } else {
1499                fprintf(stderr, "Unknown duplex parameter\n");
1500                return -1;
1501        }
1502
1503        if (!strcmp(speedstr, "10")) {
1504                *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1505                                ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1506        } else if (!strcmp(speedstr, "100")) {
1507                *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1508                                ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1509        } else {
1510                if (duplex != ETH_LINK_FULL_DUPLEX) {
1511                        fprintf(stderr, "Invalid speed/duplex parameters\n");
1512                        return -1;
1513                }
1514                if (!strcmp(speedstr, "1000")) {
1515                        *speed = ETH_LINK_SPEED_1G;
1516                } else if (!strcmp(speedstr, "10000")) {
1517                        *speed = ETH_LINK_SPEED_10G;
1518                } else if (!strcmp(speedstr, "25000")) {
1519                        *speed = ETH_LINK_SPEED_25G;
1520                } else if (!strcmp(speedstr, "40000")) {
1521                        *speed = ETH_LINK_SPEED_40G;
1522                } else if (!strcmp(speedstr, "50000")) {
1523                        *speed = ETH_LINK_SPEED_50G;
1524                } else if (!strcmp(speedstr, "100000")) {
1525                        *speed = ETH_LINK_SPEED_100G;
1526                } else if (!strcmp(speedstr, "200000")) {
1527                        *speed = ETH_LINK_SPEED_200G;
1528                } else if (!strcmp(speedstr, "auto")) {
1529                        *speed = ETH_LINK_SPEED_AUTONEG;
1530                } else {
1531                        fprintf(stderr, "Unknown speed parameter\n");
1532                        return -1;
1533                }
1534        }
1535
1536        if (*speed != ETH_LINK_SPEED_AUTONEG)
1537                *speed |= ETH_LINK_SPEED_FIXED;
1538
1539        return 0;
1540}
1541
1542static void
1543cmd_config_speed_all_parsed(void *parsed_result,
1544                        __rte_unused struct cmdline *cl,
1545                        __rte_unused void *data)
1546{
1547        struct cmd_config_speed_all *res = parsed_result;
1548        uint32_t link_speed;
1549        portid_t pid;
1550
1551        if (!all_ports_stopped()) {
1552                fprintf(stderr, "Please stop all ports first\n");
1553                return;
1554        }
1555
1556        if (parse_and_check_speed_duplex(res->value1, res->value2,
1557                        &link_speed) < 0)
1558                return;
1559
1560        RTE_ETH_FOREACH_DEV(pid) {
1561                ports[pid].dev_conf.link_speeds = link_speed;
1562        }
1563
1564        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1565}
1566
1567cmdline_parse_token_string_t cmd_config_speed_all_port =
1568        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1569cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1570        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1571                                                        "config");
1572cmdline_parse_token_string_t cmd_config_speed_all_all =
1573        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1574cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1575        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1576cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1577        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1578                                "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1579cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1580        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1581cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1582        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1583                                                "half#full#auto");
1584
1585cmdline_parse_inst_t cmd_config_speed_all = {
1586        .f = cmd_config_speed_all_parsed,
1587        .data = NULL,
1588        .help_str = "port config all speed "
1589                "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1590                                                        "half|full|auto",
1591        .tokens = {
1592                (void *)&cmd_config_speed_all_port,
1593                (void *)&cmd_config_speed_all_keyword,
1594                (void *)&cmd_config_speed_all_all,
1595                (void *)&cmd_config_speed_all_item1,
1596                (void *)&cmd_config_speed_all_value1,
1597                (void *)&cmd_config_speed_all_item2,
1598                (void *)&cmd_config_speed_all_value2,
1599                NULL,
1600        },
1601};
1602
1603/* *** configure speed for specific port *** */
1604struct cmd_config_speed_specific {
1605        cmdline_fixed_string_t port;
1606        cmdline_fixed_string_t keyword;
1607        portid_t id;
1608        cmdline_fixed_string_t item1;
1609        cmdline_fixed_string_t item2;
1610        cmdline_fixed_string_t value1;
1611        cmdline_fixed_string_t value2;
1612};
1613
1614static void
1615cmd_config_speed_specific_parsed(void *parsed_result,
1616                                __rte_unused struct cmdline *cl,
1617                                __rte_unused void *data)
1618{
1619        struct cmd_config_speed_specific *res = parsed_result;
1620        uint32_t link_speed;
1621
1622        if (port_id_is_invalid(res->id, ENABLED_WARN))
1623                return;
1624
1625        if (!port_is_stopped(res->id)) {
1626                fprintf(stderr, "Please stop port %d first\n", res->id);
1627                return;
1628        }
1629
1630        if (parse_and_check_speed_duplex(res->value1, res->value2,
1631                        &link_speed) < 0)
1632                return;
1633
1634        ports[res->id].dev_conf.link_speeds = link_speed;
1635
1636        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1637}
1638
1639
1640cmdline_parse_token_string_t cmd_config_speed_specific_port =
1641        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1642                                                                "port");
1643cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1644        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1645                                                                "config");
1646cmdline_parse_token_num_t cmd_config_speed_specific_id =
1647        TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1648cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1649        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1650                                                                "speed");
1651cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1652        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1653                                "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1654cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1655        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1656                                                                "duplex");
1657cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1658        TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1659                                                        "half#full#auto");
1660
1661cmdline_parse_inst_t cmd_config_speed_specific = {
1662        .f = cmd_config_speed_specific_parsed,
1663        .data = NULL,
1664        .help_str = "port config <port_id> speed "
1665                "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1666                                                        "half|full|auto",
1667        .tokens = {
1668                (void *)&cmd_config_speed_specific_port,
1669                (void *)&cmd_config_speed_specific_keyword,
1670                (void *)&cmd_config_speed_specific_id,
1671                (void *)&cmd_config_speed_specific_item1,
1672                (void *)&cmd_config_speed_specific_value1,
1673                (void *)&cmd_config_speed_specific_item2,
1674                (void *)&cmd_config_speed_specific_value2,
1675                NULL,
1676        },
1677};
1678
1679/* *** configure loopback for all ports *** */
1680struct cmd_config_loopback_all {
1681        cmdline_fixed_string_t port;
1682        cmdline_fixed_string_t keyword;
1683        cmdline_fixed_string_t all;
1684        cmdline_fixed_string_t item;
1685        uint32_t mode;
1686};
1687
1688static void
1689cmd_config_loopback_all_parsed(void *parsed_result,
1690                        __rte_unused struct cmdline *cl,
1691                        __rte_unused void *data)
1692{
1693        struct cmd_config_loopback_all *res = parsed_result;
1694        portid_t pid;
1695
1696        if (!all_ports_stopped()) {
1697                fprintf(stderr, "Please stop all ports first\n");
1698                return;
1699        }
1700
1701        RTE_ETH_FOREACH_DEV(pid) {
1702                ports[pid].dev_conf.lpbk_mode = res->mode;
1703        }
1704
1705        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1706}
1707
1708cmdline_parse_token_string_t cmd_config_loopback_all_port =
1709        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1710cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1711        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1712                                                        "config");
1713cmdline_parse_token_string_t cmd_config_loopback_all_all =
1714        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1715cmdline_parse_token_string_t cmd_config_loopback_all_item =
1716        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1717                                                        "loopback");
1718cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1719        TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1720
1721cmdline_parse_inst_t cmd_config_loopback_all = {
1722        .f = cmd_config_loopback_all_parsed,
1723        .data = NULL,
1724        .help_str = "port config all loopback <mode>",
1725        .tokens = {
1726                (void *)&cmd_config_loopback_all_port,
1727                (void *)&cmd_config_loopback_all_keyword,
1728                (void *)&cmd_config_loopback_all_all,
1729                (void *)&cmd_config_loopback_all_item,
1730                (void *)&cmd_config_loopback_all_mode,
1731                NULL,
1732        },
1733};
1734
1735/* *** configure loopback for specific port *** */
1736struct cmd_config_loopback_specific {
1737        cmdline_fixed_string_t port;
1738        cmdline_fixed_string_t keyword;
1739        uint16_t port_id;
1740        cmdline_fixed_string_t item;
1741        uint32_t mode;
1742};
1743
1744static void
1745cmd_config_loopback_specific_parsed(void *parsed_result,
1746                                __rte_unused struct cmdline *cl,
1747                                __rte_unused void *data)
1748{
1749        struct cmd_config_loopback_specific *res = parsed_result;
1750
1751        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1752                return;
1753
1754        if (!port_is_stopped(res->port_id)) {
1755                fprintf(stderr, "Please stop port %u first\n", res->port_id);
1756                return;
1757        }
1758
1759        ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1760
1761        cmd_reconfig_device_queue(res->port_id, 1, 1);
1762}
1763
1764
1765cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1766        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1767                                                                "port");
1768cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1769        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1770                                                                "config");
1771cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1772        TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1773                                                                RTE_UINT16);
1774cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1775        TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1776                                                                "loopback");
1777cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1778        TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1779                              RTE_UINT32);
1780
1781cmdline_parse_inst_t cmd_config_loopback_specific = {
1782        .f = cmd_config_loopback_specific_parsed,
1783        .data = NULL,
1784        .help_str = "port config <port_id> loopback <mode>",
1785        .tokens = {
1786                (void *)&cmd_config_loopback_specific_port,
1787                (void *)&cmd_config_loopback_specific_keyword,
1788                (void *)&cmd_config_loopback_specific_id,
1789                (void *)&cmd_config_loopback_specific_item,
1790                (void *)&cmd_config_loopback_specific_mode,
1791                NULL,
1792        },
1793};
1794
1795/* *** configure txq/rxq, txd/rxd *** */
1796struct cmd_config_rx_tx {
1797        cmdline_fixed_string_t port;
1798        cmdline_fixed_string_t keyword;
1799        cmdline_fixed_string_t all;
1800        cmdline_fixed_string_t name;
1801        uint16_t value;
1802};
1803
1804static void
1805cmd_config_rx_tx_parsed(void *parsed_result,
1806                        __rte_unused struct cmdline *cl,
1807                        __rte_unused void *data)
1808{
1809        struct cmd_config_rx_tx *res = parsed_result;
1810
1811        if (!all_ports_stopped()) {
1812                fprintf(stderr, "Please stop all ports first\n");
1813                return;
1814        }
1815        if (!strcmp(res->name, "rxq")) {
1816                if (!res->value && !nb_txq) {
1817                        fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1818                        return;
1819                }
1820                if (check_nb_rxq(res->value) != 0)
1821                        return;
1822                nb_rxq = res->value;
1823        }
1824        else if (!strcmp(res->name, "txq")) {
1825                if (!res->value && !nb_rxq) {
1826                        fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1827                        return;
1828                }
1829                if (check_nb_txq(res->value) != 0)
1830                        return;
1831                nb_txq = res->value;
1832        }
1833        else if (!strcmp(res->name, "rxd")) {
1834                if (check_nb_rxd(res->value) != 0)
1835                        return;
1836                nb_rxd = res->value;
1837        } else if (!strcmp(res->name, "txd")) {
1838                if (check_nb_txd(res->value) != 0)
1839                        return;
1840
1841                nb_txd = res->value;
1842        } else {
1843                fprintf(stderr, "Unknown parameter\n");
1844                return;
1845        }
1846
1847        fwd_config_setup();
1848
1849        init_port_config();
1850
1851        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1852}
1853
1854cmdline_parse_token_string_t cmd_config_rx_tx_port =
1855        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1856cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1857        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1858cmdline_parse_token_string_t cmd_config_rx_tx_all =
1859        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1860cmdline_parse_token_string_t cmd_config_rx_tx_name =
1861        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1862                                                "rxq#txq#rxd#txd");
1863cmdline_parse_token_num_t cmd_config_rx_tx_value =
1864        TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1865
1866cmdline_parse_inst_t cmd_config_rx_tx = {
1867        .f = cmd_config_rx_tx_parsed,
1868        .data = NULL,
1869        .help_str = "port config all rxq|txq|rxd|txd <value>",
1870        .tokens = {
1871                (void *)&cmd_config_rx_tx_port,
1872                (void *)&cmd_config_rx_tx_keyword,
1873                (void *)&cmd_config_rx_tx_all,
1874                (void *)&cmd_config_rx_tx_name,
1875                (void *)&cmd_config_rx_tx_value,
1876                NULL,
1877        },
1878};
1879
1880/* *** config max packet length *** */
1881struct cmd_config_max_pkt_len_result {
1882        cmdline_fixed_string_t port;
1883        cmdline_fixed_string_t keyword;
1884        cmdline_fixed_string_t all;
1885        cmdline_fixed_string_t name;
1886        uint32_t value;
1887};
1888
1889static void
1890cmd_config_max_pkt_len_parsed(void *parsed_result,
1891                                __rte_unused struct cmdline *cl,
1892                                __rte_unused void *data)
1893{
1894        struct cmd_config_max_pkt_len_result *res = parsed_result;
1895        uint32_t max_rx_pkt_len_backup = 0;
1896        portid_t pid;
1897        int ret;
1898
1899        if (!all_ports_stopped()) {
1900                fprintf(stderr, "Please stop all ports first\n");
1901                return;
1902        }
1903
1904        RTE_ETH_FOREACH_DEV(pid) {
1905                struct rte_port *port = &ports[pid];
1906
1907                if (!strcmp(res->name, "max-pkt-len")) {
1908                        if (res->value < RTE_ETHER_MIN_LEN) {
1909                                fprintf(stderr,
1910                                        "max-pkt-len can not be less than %d\n",
1911                                        RTE_ETHER_MIN_LEN);
1912                                return;
1913                        }
1914                        if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1915                                return;
1916
1917                        ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1918                        if (ret != 0) {
1919                                fprintf(stderr,
1920                                        "rte_eth_dev_info_get() failed for port %u\n",
1921                                        pid);
1922                                return;
1923                        }
1924
1925                        max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1926
1927                        port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1928                        if (update_jumbo_frame_offload(pid) != 0)
1929                                port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1930                } else {
1931                        fprintf(stderr, "Unknown parameter\n");
1932                        return;
1933                }
1934        }
1935
1936        init_port_config();
1937
1938        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1939}
1940
1941cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1942        TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1943                                                                "port");
1944cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1945        TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1946                                                                "config");
1947cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1948        TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1949                                                                "all");
1950cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1951        TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1952                                                                "max-pkt-len");
1953cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1954        TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1955                                                                RTE_UINT32);
1956
1957cmdline_parse_inst_t cmd_config_max_pkt_len = {
1958        .f = cmd_config_max_pkt_len_parsed,
1959        .data = NULL,
1960        .help_str = "port config all max-pkt-len <value>",
1961        .tokens = {
1962                (void *)&cmd_config_max_pkt_len_port,
1963                (void *)&cmd_config_max_pkt_len_keyword,
1964                (void *)&cmd_config_max_pkt_len_all,
1965                (void *)&cmd_config_max_pkt_len_name,
1966                (void *)&cmd_config_max_pkt_len_value,
1967                NULL,
1968        },
1969};
1970
1971/* *** config max LRO aggregated packet size *** */
1972struct cmd_config_max_lro_pkt_size_result {
1973        cmdline_fixed_string_t port;
1974        cmdline_fixed_string_t keyword;
1975        cmdline_fixed_string_t all;
1976        cmdline_fixed_string_t name;
1977        uint32_t value;
1978};
1979
1980static void
1981cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1982                                __rte_unused struct cmdline *cl,
1983                                __rte_unused void *data)
1984{
1985        struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1986        portid_t pid;
1987
1988        if (!all_ports_stopped()) {
1989                fprintf(stderr, "Please stop all ports first\n");
1990                return;
1991        }
1992
1993        RTE_ETH_FOREACH_DEV(pid) {
1994                struct rte_port *port = &ports[pid];
1995
1996                if (!strcmp(res->name, "max-lro-pkt-size")) {
1997                        if (res->value ==
1998                                        port->dev_conf.rxmode.max_lro_pkt_size)
1999                                return;
2000
2001                        port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2002                } else {
2003                        fprintf(stderr, "Unknown parameter\n");
2004                        return;
2005                }
2006        }
2007
2008        init_port_config();
2009
2010        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2011}
2012
2013cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2014        TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2015                                 port, "port");
2016cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2017        TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2018                                 keyword, "config");
2019cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2020        TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2021                                 all, "all");
2022cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2023        TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2024                                 name, "max-lro-pkt-size");
2025cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2026        TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2027                              value, RTE_UINT32);
2028
2029cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2030        .f = cmd_config_max_lro_pkt_size_parsed,
2031        .data = NULL,
2032        .help_str = "port config all max-lro-pkt-size <value>",
2033        .tokens = {
2034                (void *)&cmd_config_max_lro_pkt_size_port,
2035                (void *)&cmd_config_max_lro_pkt_size_keyword,
2036                (void *)&cmd_config_max_lro_pkt_size_all,
2037                (void *)&cmd_config_max_lro_pkt_size_name,
2038                (void *)&cmd_config_max_lro_pkt_size_value,
2039                NULL,
2040        },
2041};
2042
2043/* *** configure port MTU *** */
2044struct cmd_config_mtu_result {
2045        cmdline_fixed_string_t port;
2046        cmdline_fixed_string_t keyword;
2047        cmdline_fixed_string_t mtu;
2048        portid_t port_id;
2049        uint16_t value;
2050};
2051
2052static void
2053cmd_config_mtu_parsed(void *parsed_result,
2054                      __rte_unused struct cmdline *cl,
2055                      __rte_unused void *data)
2056{
2057        struct cmd_config_mtu_result *res = parsed_result;
2058
2059        if (res->value < RTE_ETHER_MIN_LEN) {
2060                fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2061                return;
2062        }
2063        port_mtu_set(res->port_id, res->value);
2064}
2065
2066cmdline_parse_token_string_t cmd_config_mtu_port =
2067        TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2068                                 "port");
2069cmdline_parse_token_string_t cmd_config_mtu_keyword =
2070        TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2071                                 "config");
2072cmdline_parse_token_string_t cmd_config_mtu_mtu =
2073        TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2074                                 "mtu");
2075cmdline_parse_token_num_t cmd_config_mtu_port_id =
2076        TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2077                                 RTE_UINT16);
2078cmdline_parse_token_num_t cmd_config_mtu_value =
2079        TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2080                                 RTE_UINT16);
2081
2082cmdline_parse_inst_t cmd_config_mtu = {
2083        .f = cmd_config_mtu_parsed,
2084        .data = NULL,
2085        .help_str = "port config mtu <port_id> <value>",
2086        .tokens = {
2087                (void *)&cmd_config_mtu_port,
2088                (void *)&cmd_config_mtu_keyword,
2089                (void *)&cmd_config_mtu_mtu,
2090                (void *)&cmd_config_mtu_port_id,
2091                (void *)&cmd_config_mtu_value,
2092                NULL,
2093        },
2094};
2095
2096/* *** configure rx mode *** */
2097struct cmd_config_rx_mode_flag {
2098        cmdline_fixed_string_t port;
2099        cmdline_fixed_string_t keyword;
2100        cmdline_fixed_string_t all;
2101        cmdline_fixed_string_t name;
2102        cmdline_fixed_string_t value;
2103};
2104
2105static void
2106cmd_config_rx_mode_flag_parsed(void *parsed_result,
2107                                __rte_unused struct cmdline *cl,
2108                                __rte_unused void *data)
2109{
2110        struct cmd_config_rx_mode_flag *res = parsed_result;
2111
2112        if (!all_ports_stopped()) {
2113                fprintf(stderr, "Please stop all ports first\n");
2114                return;
2115        }
2116
2117        if (!strcmp(res->name, "drop-en")) {
2118                if (!strcmp(res->value, "on"))
2119                        rx_drop_en = 1;
2120                else if (!strcmp(res->value, "off"))
2121                        rx_drop_en = 0;
2122                else {
2123                        fprintf(stderr, "Unknown parameter\n");
2124                        return;
2125                }
2126        } else {
2127                fprintf(stderr, "Unknown parameter\n");
2128                return;
2129        }
2130
2131        init_port_config();
2132
2133        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2134}
2135
2136cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2137        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2138cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2139        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2140                                                                "config");
2141cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2142        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2143cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2144        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2145                                        "drop-en");
2146cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2147        TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2148                                                        "on#off");
2149
2150cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2151        .f = cmd_config_rx_mode_flag_parsed,
2152        .data = NULL,
2153        .help_str = "port config all drop-en on|off",
2154        .tokens = {
2155                (void *)&cmd_config_rx_mode_flag_port,
2156                (void *)&cmd_config_rx_mode_flag_keyword,
2157                (void *)&cmd_config_rx_mode_flag_all,
2158                (void *)&cmd_config_rx_mode_flag_name,
2159                (void *)&cmd_config_rx_mode_flag_value,
2160                NULL,
2161        },
2162};
2163
2164/* *** configure rss *** */
2165struct cmd_config_rss {
2166        cmdline_fixed_string_t port;
2167        cmdline_fixed_string_t keyword;
2168        cmdline_fixed_string_t all;
2169        cmdline_fixed_string_t name;
2170        cmdline_fixed_string_t value;
2171};
2172
2173static void
2174cmd_config_rss_parsed(void *parsed_result,
2175                        __rte_unused struct cmdline *cl,
2176                        __rte_unused void *data)
2177{
2178        struct cmd_config_rss *res = parsed_result;
2179        struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2180        struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2181        int use_default = 0;
2182        int all_updated = 1;
2183        int diag;
2184        uint16_t i;
2185        int ret;
2186
2187        if (!strcmp(res->value, "all"))
2188                rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2189                        ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2190                        ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2191                        ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2192                        ETH_RSS_ECPRI;
2193        else if (!strcmp(res->value, "eth"))
2194                rss_conf.rss_hf = ETH_RSS_ETH;
2195        else if (!strcmp(res->value, "vlan"))
2196                rss_conf.rss_hf = ETH_RSS_VLAN;
2197        else if (!strcmp(res->value, "ip"))
2198                rss_conf.rss_hf = ETH_RSS_IP;
2199        else if (!strcmp(res->value, "udp"))
2200                rss_conf.rss_hf = ETH_RSS_UDP;
2201        else if (!strcmp(res->value, "tcp"))
2202                rss_conf.rss_hf = ETH_RSS_TCP;
2203        else if (!strcmp(res->value, "sctp"))
2204                rss_conf.rss_hf = ETH_RSS_SCTP;
2205        else if (!strcmp(res->value, "ether"))
2206                rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2207        else if (!strcmp(res->value, "port"))
2208                rss_conf.rss_hf = ETH_RSS_PORT;
2209        else if (!strcmp(res->value, "vxlan"))
2210                rss_conf.rss_hf = ETH_RSS_VXLAN;
2211        else if (!strcmp(res->value, "geneve"))
2212                rss_conf.rss_hf = ETH_RSS_GENEVE;
2213        else if (!strcmp(res->value, "nvgre"))
2214                rss_conf.rss_hf = ETH_RSS_NVGRE;
2215        else if (!strcmp(res->value, "l3-pre32"))
2216                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2217        else if (!strcmp(res->value, "l3-pre40"))
2218                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2219        else if (!strcmp(res->value, "l3-pre48"))
2220                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2221        else if (!strcmp(res->value, "l3-pre56"))
2222                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2223        else if (!strcmp(res->value, "l3-pre64"))
2224                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2225        else if (!strcmp(res->value, "l3-pre96"))
2226                rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2227        else if (!strcmp(res->value, "l3-src-only"))
2228                rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2229        else if (!strcmp(res->value, "l3-dst-only"))
2230                rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2231        else if (!strcmp(res->value, "l4-src-only"))
2232                rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2233        else if (!strcmp(res->value, "l4-dst-only"))
2234                rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2235        else if (!strcmp(res->value, "l2-src-only"))
2236                rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2237        else if (!strcmp(res->value, "l2-dst-only"))
2238                rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2239        else if (!strcmp(res->value, "l2tpv3"))
2240                rss_conf.rss_hf = ETH_RSS_L2TPV3;
2241        else if (!strcmp(res->value, "esp"))
2242                rss_conf.rss_hf = ETH_RSS_ESP;
2243        else if (!strcmp(res->value, "ah"))
2244                rss_conf.rss_hf = ETH_RSS_AH;
2245        else if (!strcmp(res->value, "pfcp"))
2246                rss_conf.rss_hf = ETH_RSS_PFCP;
2247        else if (!strcmp(res->value, "pppoe"))
2248                rss_conf.rss_hf = ETH_RSS_PPPOE;
2249        else if (!strcmp(res->value, "gtpu"))
2250                rss_conf.rss_hf = ETH_RSS_GTPU;
2251        else if (!strcmp(res->value, "ecpri"))
2252                rss_conf.rss_hf = ETH_RSS_ECPRI;
2253        else if (!strcmp(res->value, "mpls"))
2254                rss_conf.rss_hf = ETH_RSS_MPLS;
2255        else if (!strcmp(res->value, "none"))
2256                rss_conf.rss_hf = 0;
2257        else if (!strcmp(res->value, "level-default")) {
2258                rss_hf &= (~ETH_RSS_LEVEL_MASK);
2259                rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2260        } else if (!strcmp(res->value, "level-outer")) {
2261                rss_hf &= (~ETH_RSS_LEVEL_MASK);
2262                rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2263        } else if (!strcmp(res->value, "level-inner")) {
2264                rss_hf &= (~ETH_RSS_LEVEL_MASK);
2265                rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2266        } else if (!strcmp(res->value, "default"))
2267                use_default = 1;
2268        else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2269                                                atoi(res->value) < 64)
2270                rss_conf.rss_hf = 1ULL << atoi(res->value);
2271        else {
2272                fprintf(stderr, "Unknown parameter\n");
2273                return;
2274        }
2275        rss_conf.rss_key = NULL;
2276        /* Update global configuration for RSS types. */
2277        RTE_ETH_FOREACH_DEV(i) {
2278                struct rte_eth_rss_conf local_rss_conf;
2279
2280                ret = eth_dev_info_get_print_err(i, &dev_info);
2281                if (ret != 0)
2282                        return;
2283
2284                if (use_default)
2285                        rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2286
2287                local_rss_conf = rss_conf;
2288                local_rss_conf.rss_hf = rss_conf.rss_hf &
2289                        dev_info.flow_type_rss_offloads;
2290                if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2291                        printf("Port %u modified RSS hash function based on hardware support,"
2292                                "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2293                                i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2294                }
2295                diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2296                if (diag < 0) {
2297                        all_updated = 0;
2298                        fprintf(stderr,
2299                                "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2300                                i, -diag, strerror(-diag));
2301                }
2302        }
2303        if (all_updated && !use_default) {
2304                rss_hf = rss_conf.rss_hf;
2305                printf("rss_hf %#"PRIx64"\n", rss_hf);
2306        }
2307}
2308
2309cmdline_parse_token_string_t cmd_config_rss_port =
2310        TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2311cmdline_parse_token_string_t cmd_config_rss_keyword =
2312        TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2313cmdline_parse_token_string_t cmd_config_rss_all =
2314        TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2315cmdline_parse_token_string_t cmd_config_rss_name =
2316        TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2317cmdline_parse_token_string_t cmd_config_rss_value =
2318        TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2319
2320cmdline_parse_inst_t cmd_config_rss = {
2321        .f = cmd_config_rss_parsed,
2322        .data = NULL,
2323        .help_str = "port config all rss "
2324                "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2325                "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2326                "level-outer|level-inner|<flowtype_id>",
2327        .tokens = {
2328                (void *)&cmd_config_rss_port,
2329                (void *)&cmd_config_rss_keyword,
2330                (void *)&cmd_config_rss_all,
2331                (void *)&cmd_config_rss_name,
2332                (void *)&cmd_config_rss_value,
2333                NULL,
2334        },
2335};
2336
2337/* *** configure rss hash key *** */
2338struct cmd_config_rss_hash_key {
2339        cmdline_fixed_string_t port;
2340        cmdline_fixed_string_t config;
2341        portid_t port_id;
2342        cmdline_fixed_string_t rss_hash_key;
2343        cmdline_fixed_string_t rss_type;
2344        cmdline_fixed_string_t key;
2345};
2346
2347static uint8_t
2348hexa_digit_to_value(char hexa_digit)
2349{
2350        if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2351                return (uint8_t) (hexa_digit - '0');
2352        if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2353                return (uint8_t) ((hexa_digit - 'a') + 10);
2354        if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2355                return (uint8_t) ((hexa_digit - 'A') + 10);
2356        /* Invalid hexa digit */
2357        return 0xFF;
2358}
2359
2360static uint8_t
2361parse_and_check_key_hexa_digit(char *key, int idx)
2362{
2363        uint8_t hexa_v;
2364
2365        hexa_v = hexa_digit_to_value(key[idx]);
2366        if (hexa_v == 0xFF)
2367                fprintf(stderr,
2368                        "invalid key: character %c at position %d is not a valid hexa digit\n",
2369                        key[idx], idx);
2370        return hexa_v;
2371}
2372
2373static void
2374cmd_config_rss_hash_key_parsed(void *parsed_result,
2375                               __rte_unused struct cmdline *cl,
2376                               __rte_unused void *data)
2377{
2378        struct cmd_config_rss_hash_key *res = parsed_result;
2379        uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2380        uint8_t xdgt0;
2381        uint8_t xdgt1;
2382        int i;
2383        struct rte_eth_dev_info dev_info;
2384        uint8_t hash_key_size;
2385        uint32_t key_len;
2386        int ret;
2387
2388        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2389        if (ret != 0)
2390                return;
2391
2392        if (dev_info.hash_key_size > 0 &&
2393                        dev_info.hash_key_size <= sizeof(hash_key))
2394                hash_key_size = dev_info.hash_key_size;
2395        else {
2396                fprintf(stderr,
2397                        "dev_info did not provide a valid hash key size\n");
2398                return;
2399        }
2400        /* Check the length of the RSS hash key */
2401        key_len = strlen(res->key);
2402        if (key_len != (hash_key_size * 2)) {
2403                fprintf(stderr,
2404                        "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2405                        (int)key_len, hash_key_size * 2);
2406                return;
2407        }
2408        /* Translate RSS hash key into binary representation */
2409        for (i = 0; i < hash_key_size; i++) {
2410                xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2411                if (xdgt0 == 0xFF)
2412                        return;
2413                xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2414                if (xdgt1 == 0xFF)
2415                        return;
2416                hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2417        }
2418        port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2419                        hash_key_size);
2420}
2421
2422cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2423        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2424cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2425        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2426                                 "config");
2427cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2428        TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2429                                 RTE_UINT16);
2430cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2431        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2432                                 rss_hash_key, "rss-hash-key");
2433cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2434        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2435                                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2436                                 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2437                                 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2438                                 "ipv6-tcp-ex#ipv6-udp-ex#"
2439                                 "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2440                                 "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2441                                 "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2442cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2443        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2444
2445cmdline_parse_inst_t cmd_config_rss_hash_key = {
2446        .f = cmd_config_rss_hash_key_parsed,
2447        .data = NULL,
2448        .help_str = "port config <port_id> rss-hash-key "
2449                "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2450                "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2451                "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2452                "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2453                "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2454                "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2455                "<string of hex digits (variable length, NIC dependent)>",
2456        .tokens = {
2457                (void *)&cmd_config_rss_hash_key_port,
2458                (void *)&cmd_config_rss_hash_key_config,
2459                (void *)&cmd_config_rss_hash_key_port_id,
2460                (void *)&cmd_config_rss_hash_key_rss_hash_key,
2461                (void *)&cmd_config_rss_hash_key_rss_type,
2462                (void *)&cmd_config_rss_hash_key_value,
2463                NULL,
2464        },
2465};
2466
2467/* *** cleanup txq mbufs *** */
2468struct cmd_cleanup_txq_mbufs_result {
2469        cmdline_fixed_string_t port;
2470        cmdline_fixed_string_t keyword;
2471        cmdline_fixed_string_t name;
2472        uint16_t port_id;
2473        uint16_t queue_id;
2474        uint32_t free_cnt;
2475};
2476
2477static void
2478cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2479                             __rte_unused struct cmdline *cl,
2480                             __rte_unused void *data)
2481{
2482        struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2483        uint16_t port_id = res->port_id;
2484        uint16_t queue_id = res->queue_id;
2485        uint32_t free_cnt = res->free_cnt;
2486        struct rte_eth_txq_info qinfo;
2487        int ret;
2488
2489        if (test_done == 0) {
2490                fprintf(stderr, "Please stop forwarding first\n");
2491                return;
2492        }
2493
2494        if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2495                fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2496                        port_id, queue_id);
2497                return;
2498        }
2499
2500        if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2501                fprintf(stderr, "Tx queue %u not started\n", queue_id);
2502                return;
2503        }
2504
2505        ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2506        if (ret < 0) {
2507                fprintf(stderr,
2508                        "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2509                        port_id, queue_id, strerror(-ret), ret);
2510                return;
2511        }
2512
2513        printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2514               port_id, queue_id, ret);
2515}
2516
2517cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2518        TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2519                                 "port");
2520cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2521        TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2522                                 "cleanup");
2523cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2524        TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2525                              RTE_UINT16);
2526cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2527        TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2528                                 "txq");
2529cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2530        TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2531                              RTE_UINT16);
2532cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2533        TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2534                              RTE_UINT32);
2535
2536cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2537        .f = cmd_cleanup_txq_mbufs_parsed,
2538        .data = NULL,
2539        .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2540        .tokens = {
2541                (void *)&cmd_cleanup_txq_mbufs_port,
2542                (void *)&cmd_cleanup_txq_mbufs_cleanup,
2543                (void *)&cmd_cleanup_txq_mbufs_port_id,
2544                (void *)&cmd_cleanup_txq_mbufs_txq,
2545                (void *)&cmd_cleanup_txq_mbufs_queue_id,
2546                (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2547                NULL,
2548        },
2549};
2550
2551/* *** configure port rxq/txq ring size *** */
2552struct cmd_config_rxtx_ring_size {
2553        cmdline_fixed_string_t port;
2554        cmdline_fixed_string_t config;
2555        portid_t portid;
2556        cmdline_fixed_string_t rxtxq;
2557        uint16_t qid;
2558        cmdline_fixed_string_t rsize;
2559        uint16_t size;
2560};
2561
2562static void
2563cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2564                                 __rte_unused struct cmdline *cl,
2565                                 __rte_unused void *data)
2566{
2567        struct cmd_config_rxtx_ring_size *res = parsed_result;
2568        struct rte_port *port;
2569        uint8_t isrx;
2570
2571        if (port_id_is_invalid(res->portid, ENABLED_WARN))
2572                return;
2573
2574        if (res->portid == (portid_t)RTE_PORT_ALL) {
2575                fprintf(stderr, "Invalid port id\n");
2576                return;
2577        }
2578
2579        port = &ports[res->portid];
2580
2581        if (!strcmp(res->rxtxq, "rxq"))
2582                isrx = 1;
2583        else if (!strcmp(res->rxtxq, "txq"))
2584                isrx = 0;
2585        else {
2586                fprintf(stderr, "Unknown parameter\n");
2587                return;
2588        }
2589
2590        if (isrx && rx_queue_id_is_invalid(res->qid))
2591                return;
2592        else if (!isrx && tx_queue_id_is_invalid(res->qid))
2593                return;
2594
2595        if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2596                fprintf(stderr,
2597                        "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2598                        rx_free_thresh);
2599                return;
2600        }
2601
2602        if (isrx)
2603                port->nb_rx_desc[res->qid] = res->size;
2604        else
2605                port->nb_tx_desc[res->qid] = res->size;
2606
2607        cmd_reconfig_device_queue(res->portid, 0, 1);
2608}
2609
2610cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2611        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                                 port, "port");
2613cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2614        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615                                 config, "config");
2616cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2617        TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618                                 portid, RTE_UINT16);
2619cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2620        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2621                                 rxtxq, "rxq#txq");
2622cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2623        TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2624                              qid, RTE_UINT16);
2625cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2626        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2627                                 rsize, "ring_size");
2628cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2629        TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2630                              size, RTE_UINT16);
2631
2632cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2633        .f = cmd_config_rxtx_ring_size_parsed,
2634        .data = NULL,
2635        .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2636        .tokens = {
2637                (void *)&cmd_config_rxtx_ring_size_port,
2638                (void *)&cmd_config_rxtx_ring_size_config,
2639                (void *)&cmd_config_rxtx_ring_size_portid,
2640                (void *)&cmd_config_rxtx_ring_size_rxtxq,
2641                (void *)&cmd_config_rxtx_ring_size_qid,
2642                (void *)&cmd_config_rxtx_ring_size_rsize,
2643                (void *)&cmd_config_rxtx_ring_size_size,
2644                NULL,
2645        },
2646};
2647
2648/* *** configure port rxq/txq start/stop *** */
2649struct cmd_config_rxtx_queue {
2650        cmdline_fixed_string_t port;
2651        portid_t portid;
2652        cmdline_fixed_string_t rxtxq;
2653        uint16_t qid;
2654        cmdline_fixed_string_t opname;
2655};
2656
2657static void
2658cmd_config_rxtx_queue_parsed(void *parsed_result,
2659                        __rte_unused struct cmdline *cl,
2660                        __rte_unused void *data)
2661{
2662        struct cmd_config_rxtx_queue *res = parsed_result;
2663        uint8_t isrx;
2664        uint8_t isstart;
2665        int ret = 0;
2666
2667        if (test_done == 0) {
2668                fprintf(stderr, "Please stop forwarding first\n");
2669                return;
2670        }
2671
2672        if (port_id_is_invalid(res->portid, ENABLED_WARN))
2673                return;
2674
2675        if (port_is_started(res->portid) != 1) {
2676                fprintf(stderr, "Please start port %u first\n", res->portid);
2677                return;
2678        }
2679
2680        if (!strcmp(res->rxtxq, "rxq"))
2681                isrx = 1;
2682        else if (!strcmp(res->rxtxq, "txq"))
2683                isrx = 0;
2684        else {
2685                fprintf(stderr, "Unknown parameter\n");
2686                return;
2687        }
2688
2689        if (isrx && rx_queue_id_is_invalid(res->qid))
2690                return;
2691        else if (!isrx && tx_queue_id_is_invalid(res->qid))
2692                return;
2693
2694        if (!strcmp(res->opname, "start"))
2695                isstart = 1;
2696        else if (!strcmp(res->opname, "stop"))
2697                isstart = 0;
2698        else {
2699                fprintf(stderr, "Unknown parameter\n");
2700                return;
2701        }
2702
2703        if (isstart && isrx)
2704                ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2705        else if (!isstart && isrx)
2706                ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2707        else if (isstart && !isrx)
2708                ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2709        else
2710                ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2711
2712        if (ret == -ENOTSUP)
2713                fprintf(stderr, "Function not supported in PMD driver\n");
2714}
2715
2716cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2717        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2718cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2719        TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2720cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2721        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2722cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2723        TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2724cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2725        TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2726                                                "start#stop");
2727
2728cmdline_parse_inst_t cmd_config_rxtx_queue = {
2729        .f = cmd_config_rxtx_queue_parsed,
2730        .data = NULL,
2731        .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2732        .tokens = {
2733                (void *)&cmd_config_rxtx_queue_port,
2734                (void *)&cmd_config_rxtx_queue_portid,
2735                (void *)&cmd_config_rxtx_queue_rxtxq,
2736                (void *)&cmd_config_rxtx_queue_qid,
2737                (void *)&cmd_config_rxtx_queue_opname,
2738                NULL,
2739        },
2740};
2741
2742/* *** configure port rxq/txq deferred start on/off *** */
2743struct cmd_config_deferred_start_rxtx_queue {
2744        cmdline_fixed_string_t port;
2745        portid_t port_id;
2746        cmdline_fixed_string_t rxtxq;
2747        uint16_t qid;
2748        cmdline_fixed_string_t opname;
2749        cmdline_fixed_string_t state;
2750};
2751
2752static void
2753cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2754                        __rte_unused struct cmdline *cl,
2755                        __rte_unused void *data)
2756{
2757        struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2758        struct rte_port *port;
2759        uint8_t isrx;
2760        uint8_t ison;
2761        uint8_t needreconfig = 0;
2762
2763        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2764                return;
2765
2766        if (port_is_started(res->port_id) != 0) {
2767                fprintf(stderr, "Please stop port %u first\n", res->port_id);
2768                return;
2769        }
2770
2771        port = &ports[res->port_id];
2772
2773        isrx = !strcmp(res->rxtxq, "rxq");
2774
2775        if (isrx && rx_queue_id_is_invalid(res->qid))
2776                return;
2777        else if (!isrx && tx_queue_id_is_invalid(res->qid))
2778                return;
2779
2780        ison = !strcmp(res->state, "on");
2781
2782        if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2783                port->rx_conf[res->qid].rx_deferred_start = ison;
2784                needreconfig = 1;
2785        } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2786                port->tx_conf[res->qid].tx_deferred_start = ison;
2787                needreconfig = 1;
2788        }
2789
2790        if (needreconfig)
2791                cmd_reconfig_device_queue(res->port_id, 0, 1);
2792}
2793
2794cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2795        TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796                                                port, "port");
2797cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2798        TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                port_id, RTE_UINT16);
2800cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2801        TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2802                                                rxtxq, "rxq#txq");
2803cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2804        TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2805                                                qid, RTE_UINT16);
2806cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2807        TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2808                                                opname, "deferred_start");
2809cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2810        TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2811                                                state, "on#off");
2812
2813cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2814        .f = cmd_config_deferred_start_rxtx_queue_parsed,
2815        .data = NULL,
2816        .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2817        .tokens = {
2818                (void *)&cmd_config_deferred_start_rxtx_queue_port,
2819                (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2820                (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2821                (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2822                (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2823                (void *)&cmd_config_deferred_start_rxtx_queue_state,
2824                NULL,
2825        },
2826};
2827
2828/* *** configure port rxq/txq setup *** */
2829struct cmd_setup_rxtx_queue {
2830        cmdline_fixed_string_t port;
2831        portid_t portid;
2832        cmdline_fixed_string_t rxtxq;
2833        uint16_t qid;
2834        cmdline_fixed_string_t setup;
2835};
2836
2837/* Common CLI fields for queue setup */
2838cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2839        TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2840cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2841        TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2842cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2843        TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2844cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2845        TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2846cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2847        TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2848
2849static void
2850cmd_setup_rxtx_queue_parsed(
2851        void *parsed_result,
2852        __rte_unused struct cmdline *cl,
2853        __rte_unused void *data)
2854{
2855        struct cmd_setup_rxtx_queue *res = parsed_result;
2856        struct rte_port *port;
2857        struct rte_mempool *mp;
2858        unsigned int socket_id;
2859        uint8_t isrx = 0;
2860        int ret;
2861
2862        if (port_id_is_invalid(res->portid, ENABLED_WARN))
2863                return;
2864
2865        if (res->portid == (portid_t)RTE_PORT_ALL) {
2866                fprintf(stderr, "Invalid port id\n");
2867                return;
2868        }
2869
2870        if (!strcmp(res->rxtxq, "rxq"))
2871                isrx = 1;
2872        else if (!strcmp(res->rxtxq, "txq"))
2873                isrx = 0;
2874        else {
2875                fprintf(stderr, "Unknown parameter\n");
2876                return;
2877        }
2878
2879        if (isrx && rx_queue_id_is_invalid(res->qid)) {
2880                fprintf(stderr, "Invalid rx queue\n");
2881                return;
2882        } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2883                fprintf(stderr, "Invalid tx queue\n");
2884                return;
2885        }
2886
2887        port = &ports[res->portid];
2888        if (isrx) {
2889                socket_id = rxring_numa[res->portid];
2890                if (!numa_support || socket_id == NUMA_NO_CONFIG)
2891                        socket_id = port->socket_id;
2892
2893                mp = mbuf_pool_find(socket_id, 0);
2894                if (mp == NULL) {
2895                        fprintf(stderr,
2896                                "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2897                                rxring_numa[res->portid]);
2898                        return;
2899                }
2900                ret = rx_queue_setup(res->portid,
2901                                     res->qid,
2902                                     port->nb_rx_desc[res->qid],
2903                                     socket_id,
2904                                     &port->rx_conf[res->qid],
2905                                     mp);
2906                if (ret)
2907                        fprintf(stderr, "Failed to setup RX queue\n");
2908        } else {
2909                socket_id = txring_numa[res->portid];
2910                if (!numa_support || socket_id == NUMA_NO_CONFIG)
2911                        socket_id = port->socket_id;
2912
2913                if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2914                        fprintf(stderr,
2915                                "Failed to setup TX queue: not enough descriptors\n");
2916                        return;
2917                }
2918                ret = rte_eth_tx_queue_setup(res->portid,
2919                                             res->qid,
2920                                             port->nb_tx_desc[res->qid],
2921                                             socket_id,
2922                                             &port->tx_conf[res->qid]);
2923                if (ret)
2924                        fprintf(stderr, "Failed to setup TX queue\n");
2925        }
2926}
2927
2928cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2929        .f = cmd_setup_rxtx_queue_parsed,
2930        .data = NULL,
2931        .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2932        .tokens = {
2933                (void *)&cmd_setup_rxtx_queue_port,
2934                (void *)&cmd_setup_rxtx_queue_portid,
2935                (void *)&cmd_setup_rxtx_queue_rxtxq,
2936                (void *)&cmd_setup_rxtx_queue_qid,
2937                (void *)&cmd_setup_rxtx_queue_setup,
2938                NULL,
2939        },
2940};
2941
2942
2943/* *** Configure RSS RETA *** */
2944struct cmd_config_rss_reta {
2945        cmdline_fixed_string_t port;
2946        cmdline_fixed_string_t keyword;
2947        portid_t port_id;
2948        cmdline_fixed_string_t name;
2949        cmdline_fixed_string_t list_name;
2950        cmdline_fixed_string_t list_of_items;
2951};
2952
2953static int
2954parse_reta_config(const char *str,
2955                  struct rte_eth_rss_reta_entry64 *reta_conf,
2956                  uint16_t nb_entries)
2957{
2958        int i;
2959        unsigned size;
2960        uint16_t hash_index, idx, shift;
2961        uint16_t nb_queue;
2962        char s[256];
2963        const char *p, *p0 = str;
2964        char *end;
2965        enum fieldnames {
2966                FLD_HASH_INDEX = 0,
2967                FLD_QUEUE,
2968                _NUM_FLD
2969        };
2970        unsigned long int_fld[_NUM_FLD];
2971        char *str_fld[_NUM_FLD];
2972
2973        while ((p = strchr(p0,'(')) != NULL) {
2974                ++p;
2975                if((p0 = strchr(p,')')) == NULL)
2976                        return -1;
2977
2978                size = p0 - p;
2979                if(size >= sizeof(s))
2980                        return -1;
2981
2982                snprintf(s, sizeof(s), "%.*s", size, p);
2983                if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2984                        return -1;
2985                for (i = 0; i < _NUM_FLD; i++) {
2986                        errno = 0;
2987                        int_fld[i] = strtoul(str_fld[i], &end, 0);
2988                        if (errno != 0 || end == str_fld[i] ||
2989                                        int_fld[i] > 65535)
2990                                return -1;
2991                }
2992
2993                hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2994                nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2995
2996                if (hash_index >= nb_entries) {
2997                        fprintf(stderr, "Invalid RETA hash index=%d\n",
2998                                hash_index);
2999                        return -1;
3000                }
3001
3002                idx = hash_index / RTE_RETA_GROUP_SIZE;
3003                shift = hash_index % RTE_RETA_GROUP_SIZE;
3004                reta_conf[idx].mask |= (1ULL << shift);
3005                reta_conf[idx].reta[shift] = nb_queue;
3006        }
3007
3008        return 0;
3009}
3010
3011static void
3012cmd_set_rss_reta_parsed(void *parsed_result,
3013                        __rte_unused struct cmdline *cl,
3014                        __rte_unused void *data)
3015{
3016        int ret;
3017        struct rte_eth_dev_info dev_info;
3018        struct rte_eth_rss_reta_entry64 reta_conf[8];
3019        struct cmd_config_rss_reta *res = parsed_result;
3020
3021        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3022        if (ret != 0)
3023                return;
3024
3025        if (dev_info.reta_size == 0) {
3026                fprintf(stderr,
3027                        "Redirection table size is 0 which is invalid for RSS\n");
3028                return;
3029        } else
3030                printf("The reta size of port %d is %u\n",
3031                        res->port_id, dev_info.reta_size);
3032        if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3033                fprintf(stderr,
3034                        "Currently do not support more than %u entries of redirection table\n",
3035                        ETH_RSS_RETA_SIZE_512);
3036                return;
3037        }
3038
3039        memset(reta_conf, 0, sizeof(reta_conf));
3040        if (!strcmp(res->list_name, "reta")) {
3041                if (parse_reta_config(res->list_of_items, reta_conf,
3042                                                dev_info.reta_size)) {
3043                        fprintf(stderr,
3044                                "Invalid RSS Redirection Table config entered\n");
3045                        return;
3046                }
3047                ret = rte_eth_dev_rss_reta_update(res->port_id,
3048                                reta_conf, dev_info.reta_size);
3049                if (ret != 0)
3050                        fprintf(stderr,
3051                                "Bad redirection table parameter, return code = %d\n",
3052                                ret);
3053        }
3054}
3055
3056cmdline_parse_token_string_t cmd_config_rss_reta_port =
3057        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3058cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3059        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3060cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3061        TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3062cmdline_parse_token_string_t cmd_config_rss_reta_name =
3063        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3064cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3065        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3066cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3067        TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3068                                 NULL);
3069cmdline_parse_inst_t cmd_config_rss_reta = {
3070        .f = cmd_set_rss_reta_parsed,
3071        .data = NULL,
3072        .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3073        .tokens = {
3074                (void *)&cmd_config_rss_reta_port,
3075                (void *)&cmd_config_rss_reta_keyword,
3076                (void *)&cmd_config_rss_reta_port_id,
3077                (void *)&cmd_config_rss_reta_name,
3078                (void *)&cmd_config_rss_reta_list_name,
3079                (void *)&cmd_config_rss_reta_list_of_items,
3080                NULL,
3081        },
3082};
3083
3084/* *** SHOW PORT RETA INFO *** */
3085struct cmd_showport_reta {
3086        cmdline_fixed_string_t show;
3087        cmdline_fixed_string_t port;
3088        portid_t port_id;
3089        cmdline_fixed_string_t rss;
3090        cmdline_fixed_string_t reta;
3091        uint16_t size;
3092        cmdline_fixed_string_t list_of_items;
3093};
3094
3095static int
3096showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3097                           uint16_t nb_entries,
3098                           char *str)
3099{
3100        uint32_t size;
3101        const char *p, *p0 = str;
3102        char s[256];
3103        char *end;
3104        char *str_fld[8];
3105        uint16_t i;
3106        uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3107                        RTE_RETA_GROUP_SIZE;
3108        int ret;
3109
3110        p = strchr(p0, '(');
3111        if (p == NULL)
3112                return -1;
3113        p++;
3114        p0 = strchr(p, ')');
3115        if (p0 == NULL)
3116                return -1;
3117        size = p0 - p;
3118        if (size >= sizeof(s)) {
3119                fprintf(stderr,
3120                        "The string size exceeds the internal buffer size\n");
3121                return -1;
3122        }
3123        snprintf(s, sizeof(s), "%.*s", size, p);
3124        ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3125        if (ret <= 0 || ret != num) {
3126                fprintf(stderr,
3127                        "The bits of masks do not match the number of reta entries: %u\n",
3128                        num);
3129                return -1;
3130        }
3131        for (i = 0; i < ret; i++)
3132                conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3133
3134        return 0;
3135}
3136
3137static void
3138cmd_showport_reta_parsed(void *parsed_result,
3139                         __rte_unused struct cmdline *cl,
3140                         __rte_unused void *data)
3141{
3142        struct cmd_showport_reta *res = parsed_result;
3143        struct rte_eth_rss_reta_entry64 reta_conf[8];
3144        struct rte_eth_dev_info dev_info;
3145        uint16_t max_reta_size;
3146        int ret;
3147
3148        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3149        if (ret != 0)
3150                return;
3151
3152        max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3153        if (res->size == 0 || res->size > max_reta_size) {
3154                fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3155                        res->size, max_reta_size);
3156                return;
3157        }
3158
3159        memset(reta_conf, 0, sizeof(reta_conf));
3160        if (showport_parse_reta_config(reta_conf, res->size,
3161                                res->list_of_items) < 0) {
3162                fprintf(stderr, "Invalid string: %s for reta masks\n",
3163                        res->list_of_items);
3164                return;
3165        }
3166        port_rss_reta_info(res->port_id, reta_conf, res->size);
3167}
3168
3169cmdline_parse_token_string_t cmd_showport_reta_show =
3170        TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3171cmdline_parse_token_string_t cmd_showport_reta_port =
3172        TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3173cmdline_parse_token_num_t cmd_showport_reta_port_id =
3174        TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3175cmdline_parse_token_string_t cmd_showport_reta_rss =
3176        TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3177cmdline_parse_token_string_t cmd_showport_reta_reta =
3178        TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3179cmdline_parse_token_num_t cmd_showport_reta_size =
3180        TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3181cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3182        TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3183                                        list_of_items, NULL);
3184
3185cmdline_parse_inst_t cmd_showport_reta = {
3186        .f = cmd_showport_reta_parsed,
3187        .data = NULL,
3188        .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3189        .tokens = {
3190                (void *)&cmd_showport_reta_show,
3191                (void *)&cmd_showport_reta_port,
3192                (void *)&cmd_showport_reta_port_id,
3193                (void *)&cmd_showport_reta_rss,
3194                (void *)&cmd_showport_reta_reta,
3195                (void *)&cmd_showport_reta_size,
3196                (void *)&cmd_showport_reta_list_of_items,
3197                NULL,
3198        },
3199};
3200
3201/* *** Show RSS hash configuration *** */
3202struct cmd_showport_rss_hash {
3203        cmdline_fixed_string_t show;
3204        cmdline_fixed_string_t port;
3205        portid_t port_id;
3206        cmdline_fixed_string_t rss_hash;
3207        cmdline_fixed_string_t rss_type;
3208        cmdline_fixed_string_t key; /* optional argument */
3209};
3210
3211static void cmd_showport_rss_hash_parsed(void *parsed_result,
3212                                __rte_unused struct cmdline *cl,
3213                                void *show_rss_key)
3214{
3215        struct cmd_showport_rss_hash *res = parsed_result;
3216
3217        port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3218}
3219
3220cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3221        TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3222cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3223        TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3224cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3225        TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3226                                 RTE_UINT16);
3227cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3228        TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3229                                 "rss-hash");
3230cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3231        TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3232
3233cmdline_parse_inst_t cmd_showport_rss_hash = {
3234        .f = cmd_showport_rss_hash_parsed,
3235        .data = NULL,
3236        .help_str = "show port <port_id> rss-hash",
3237        .tokens = {
3238                (void *)&cmd_showport_rss_hash_show,
3239                (void *)&cmd_showport_rss_hash_port,
3240                (void *)&cmd_showport_rss_hash_port_id,
3241                (void *)&cmd_showport_rss_hash_rss_hash,
3242                NULL,
3243        },
3244};
3245
3246cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3247        .f = cmd_showport_rss_hash_parsed,
3248        .data = (void *)1,
3249        .help_str = "show port <port_id> rss-hash key",
3250        .tokens = {
3251                (void *)&cmd_showport_rss_hash_show,
3252                (void *)&cmd_showport_rss_hash_port,
3253                (void *)&cmd_showport_rss_hash_port_id,
3254                (void *)&cmd_showport_rss_hash_rss_hash,
3255                (void *)&cmd_showport_rss_hash_rss_key,
3256                NULL,
3257        },
3258};
3259
3260/* *** Configure DCB *** */
3261struct cmd_config_dcb {
3262        cmdline_fixed_string_t port;
3263        cmdline_fixed_string_t config;
3264        portid_t port_id;
3265        cmdline_fixed_string_t dcb;
3266        cmdline_fixed_string_t vt;
3267        cmdline_fixed_string_t vt_en;
3268        uint8_t num_tcs;
3269        cmdline_fixed_string_t pfc;
3270        cmdline_fixed_string_t pfc_en;
3271};
3272
3273static void
3274cmd_config_dcb_parsed(void *parsed_result,
3275                        __rte_unused struct cmdline *cl,
3276                        __rte_unused void *data)
3277{
3278        struct cmd_config_dcb *res = parsed_result;
3279        struct rte_eth_dcb_info dcb_info;
3280        portid_t port_id = res->port_id;
3281        struct rte_port *port;
3282        uint8_t pfc_en;
3283        int ret;
3284
3285        port = &ports[port_id];
3286        /** Check if the port is not started **/
3287        if (port->port_status != RTE_PORT_STOPPED) {
3288                fprintf(stderr, "Please stop port %d first\n", port_id);
3289                return;
3290        }
3291
3292        if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3293                fprintf(stderr,
3294                        "The invalid number of traffic class, only 4 or 8 allowed.\n");
3295                return;
3296        }
3297
3298        if (nb_fwd_lcores < res->num_tcs) {
3299                fprintf(stderr,
3300                        "nb_cores shouldn't be less than number of TCs.\n");
3301                return;
3302        }
3303
3304        /* Check whether the port supports the report of DCB info. */
3305        ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3306        if (ret == -ENOTSUP) {
3307                fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3308                return;
3309        }
3310
3311        if (!strncmp(res->pfc_en, "on", 2))
3312                pfc_en = 1;
3313        else
3314                pfc_en = 0;
3315
3316        /* DCB in VT mode */
3317        if (!strncmp(res->vt_en, "on", 2))
3318                ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3319                                (enum rte_eth_nb_tcs)res->num_tcs,
3320                                pfc_en);
3321        else
3322                ret = init_port_dcb_config(port_id, DCB_ENABLED,
3323                                (enum rte_eth_nb_tcs)res->num_tcs,
3324                                pfc_en);
3325        if (ret != 0) {
3326                fprintf(stderr, "Cannot initialize network ports.\n");
3327                return;
3328        }
3329
3330        fwd_config_setup();
3331
3332        cmd_reconfig_device_queue(port_id, 1, 1);
3333}
3334
3335cmdline_parse_token_string_t cmd_config_dcb_port =
3336        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3337cmdline_parse_token_string_t cmd_config_dcb_config =
3338        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3339cmdline_parse_token_num_t cmd_config_dcb_port_id =
3340        TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3341cmdline_parse_token_string_t cmd_config_dcb_dcb =
3342        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3343cmdline_parse_token_string_t cmd_config_dcb_vt =
3344        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3345cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3346        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3347cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3348        TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3349cmdline_parse_token_string_t cmd_config_dcb_pfc=
3350        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3351cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3352        TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3353
3354cmdline_parse_inst_t cmd_config_dcb = {
3355        .f = cmd_config_dcb_parsed,
3356        .data = NULL,
3357        .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3358        .tokens = {
3359                (void *)&cmd_config_dcb_port,
3360                (void *)&cmd_config_dcb_config,
3361                (void *)&cmd_config_dcb_port_id,
3362                (void *)&cmd_config_dcb_dcb,
3363                (void *)&cmd_config_dcb_vt,
3364                (void *)&cmd_config_dcb_vt_en,
3365                (void *)&cmd_config_dcb_num_tcs,
3366                (void *)&cmd_config_dcb_pfc,
3367                (void *)&cmd_config_dcb_pfc_en,
3368                NULL,
3369        },
3370};
3371
3372/* *** configure number of packets per burst *** */
3373struct cmd_config_burst {
3374        cmdline_fixed_string_t port;
3375        cmdline_fixed_string_t keyword;
3376        cmdline_fixed_string_t all;
3377        cmdline_fixed_string_t name;
3378        uint16_t value;
3379};
3380
3381static void
3382cmd_config_burst_parsed(void *parsed_result,
3383                        __rte_unused struct cmdline *cl,
3384                        __rte_unused void *data)
3385{
3386        struct cmd_config_burst *res = parsed_result;
3387        struct rte_eth_dev_info dev_info;
3388        uint16_t rec_nb_pkts;
3389        int ret;
3390
3391        if (!all_ports_stopped()) {
3392                fprintf(stderr, "Please stop all ports first\n");
3393                return;
3394        }
3395
3396        if (!strcmp(res->name, "burst")) {
3397                if (res->value == 0) {
3398                        /* If user gives a value of zero, query the PMD for
3399                         * its recommended Rx burst size. Testpmd uses a single
3400                         * size for all ports, so assume all ports are the same
3401                         * NIC model and use the values from Port 0.
3402                         */
3403                        ret = eth_dev_info_get_print_err(0, &dev_info);
3404                        if (ret != 0)
3405                                return;
3406
3407                        rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3408
3409                        if (rec_nb_pkts == 0) {
3410                                printf("PMD does not recommend a burst size.\n"
3411                                        "User provided value must be between"
3412                                        " 1 and %d\n", MAX_PKT_BURST);
3413                                return;
3414                        } else if (rec_nb_pkts > MAX_PKT_BURST) {
3415                                printf("PMD recommended burst size of %d"
3416                                        " exceeds maximum value of %d\n",
3417                                        rec_nb_pkts, MAX_PKT_BURST);
3418                                return;
3419                        }
3420                        printf("Using PMD-provided burst value of %d\n",
3421                                rec_nb_pkts);
3422                        nb_pkt_per_burst = rec_nb_pkts;
3423                } else if (res->value > MAX_PKT_BURST) {
3424                        fprintf(stderr, "burst must be >= 1 && <= %d\n",
3425                                MAX_PKT_BURST);
3426                        return;
3427                } else
3428                        nb_pkt_per_burst = res->value;
3429        } else {
3430                fprintf(stderr, "Unknown parameter\n");
3431                return;
3432        }
3433
3434        init_port_config();
3435
3436        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3437}
3438
3439cmdline_parse_token_string_t cmd_config_burst_port =
3440        TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3441cmdline_parse_token_string_t cmd_config_burst_keyword =
3442        TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3443cmdline_parse_token_string_t cmd_config_burst_all =
3444        TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3445cmdline_parse_token_string_t cmd_config_burst_name =
3446        TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3447cmdline_parse_token_num_t cmd_config_burst_value =
3448        TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3449
3450cmdline_parse_inst_t cmd_config_burst = {
3451        .f = cmd_config_burst_parsed,
3452        .data = NULL,
3453        .help_str = "port config all burst <value>",
3454        .tokens = {
3455                (void *)&cmd_config_burst_port,
3456                (void *)&cmd_config_burst_keyword,
3457                (void *)&cmd_config_burst_all,
3458                (void *)&cmd_config_burst_name,
3459                (void *)&cmd_config_burst_value,
3460                NULL,
3461        },
3462};
3463
3464/* *** configure rx/tx queues *** */
3465struct cmd_config_thresh {
3466        cmdline_fixed_string_t port;
3467        cmdline_fixed_string_t keyword;
3468        cmdline_fixed_string_t all;
3469        cmdline_fixed_string_t name;
3470        uint8_t value;
3471};
3472
3473static void
3474cmd_config_thresh_parsed(void *parsed_result,
3475                        __rte_unused struct cmdline *cl,
3476                        __rte_unused void *data)
3477{
3478        struct cmd_config_thresh *res = parsed_result;
3479
3480        if (!all_ports_stopped()) {
3481                fprintf(stderr, "Please stop all ports first\n");
3482                return;
3483        }
3484
3485        if (!strcmp(res->name, "txpt"))
3486                tx_pthresh = res->value;
3487        else if(!strcmp(res->name, "txht"))
3488                tx_hthresh = res->value;
3489        else if(!strcmp(res->name, "txwt"))
3490                tx_wthresh = res->value;
3491        else if(!strcmp(res->name, "rxpt"))
3492                rx_pthresh = res->value;
3493        else if(!strcmp(res->name, "rxht"))
3494                rx_hthresh = res->value;
3495        else if(!strcmp(res->name, "rxwt"))
3496                rx_wthresh = res->value;
3497        else {
3498                fprintf(stderr, "Unknown parameter\n");
3499                return;
3500        }
3501
3502        init_port_config();
3503
3504        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3505}
3506
3507cmdline_parse_token_string_t cmd_config_thresh_port =
3508        TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3509cmdline_parse_token_string_t cmd_config_thresh_keyword =
3510        TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3511cmdline_parse_token_string_t cmd_config_thresh_all =
3512        TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3513cmdline_parse_token_string_t cmd_config_thresh_name =
3514        TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3515                                "txpt#txht#txwt#rxpt#rxht#rxwt");
3516cmdline_parse_token_num_t cmd_config_thresh_value =
3517        TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3518
3519cmdline_parse_inst_t cmd_config_thresh = {
3520        .f = cmd_config_thresh_parsed,
3521        .data = NULL,
3522        .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3523        .tokens = {
3524                (void *)&cmd_config_thresh_port,
3525                (void *)&cmd_config_thresh_keyword,
3526                (void *)&cmd_config_thresh_all,
3527                (void *)&cmd_config_thresh_name,
3528                (void *)&cmd_config_thresh_value,
3529                NULL,
3530        },
3531};
3532
3533/* *** configure free/rs threshold *** */
3534struct cmd_config_threshold {
3535        cmdline_fixed_string_t port;
3536        cmdline_fixed_string_t keyword;
3537        cmdline_fixed_string_t all;
3538        cmdline_fixed_string_t name;
3539        uint16_t value;
3540};
3541
3542static void
3543cmd_config_threshold_parsed(void *parsed_result,
3544                        __rte_unused struct cmdline *cl,
3545                        __rte_unused void *data)
3546{
3547        struct cmd_config_threshold *res = parsed_result;
3548
3549        if (!all_ports_stopped()) {
3550                fprintf(stderr, "Please stop all ports first\n");
3551                return;
3552        }
3553
3554        if (!strcmp(res->name, "txfreet"))
3555                tx_free_thresh = res->value;
3556        else if (!strcmp(res->name, "txrst"))
3557                tx_rs_thresh = res->value;
3558        else if (!strcmp(res->name, "rxfreet"))
3559                rx_free_thresh = res->value;
3560        else {
3561                fprintf(stderr, "Unknown parameter\n");
3562                return;
3563        }
3564
3565        init_port_config();
3566
3567        cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3568}
3569
3570cmdline_parse_token_string_t cmd_config_threshold_port =
3571        TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3572cmdline_parse_token_string_t cmd_config_threshold_keyword =
3573        TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3574                                                                "config");
3575cmdline_parse_token_string_t cmd_config_threshold_all =
3576        TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3577cmdline_parse_token_string_t cmd_config_threshold_name =
3578        TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3579                                                "txfreet#txrst#rxfreet");
3580cmdline_parse_token_num_t cmd_config_threshold_value =
3581        TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3582
3583cmdline_parse_inst_t cmd_config_threshold = {
3584        .f = cmd_config_threshold_parsed,
3585        .data = NULL,
3586        .help_str = "port config all txfreet|txrst|rxfreet <value>",
3587        .tokens = {
3588                (void *)&cmd_config_threshold_port,
3589                (void *)&cmd_config_threshold_keyword,
3590                (void *)&cmd_config_threshold_all,
3591                (void *)&cmd_config_threshold_name,
3592                (void *)&cmd_config_threshold_value,
3593                NULL,
3594        },
3595};
3596
3597/* *** stop *** */
3598struct cmd_stop_result {
3599        cmdline_fixed_string_t stop;
3600};
3601
3602static void cmd_stop_parsed(__rte_unused void *parsed_result,
3603                            __rte_unused struct cmdline *cl,
3604                            __rte_unused void *data)
3605{
3606        stop_packet_forwarding();
3607}
3608
3609cmdline_parse_token_string_t cmd_stop_stop =
3610        TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3611
3612cmdline_parse_inst_t cmd_stop = {
3613        .f = cmd_stop_parsed,
3614        .data = NULL,
3615        .help_str = "stop: Stop packet forwarding",
3616        .tokens = {
3617                (void *)&cmd_stop_stop,
3618                NULL,
3619        },
3620};
3621
3622/* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3623
3624unsigned int
3625parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3626                unsigned int *parsed_items, int check_unique_values)
3627{
3628        unsigned int nb_item;
3629        unsigned int value;
3630        unsigned int i;
3631        unsigned int j;
3632        int value_ok;
3633        char c;
3634
3635        /*
3636         * First parse all items in the list and store their value.
3637         */
3638        value = 0;
3639        nb_item = 0;
3640        value_ok = 0;
3641        for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3642                c = str[i];
3643                if ((c >= '0') && (c <= '9')) {
3644                        value = (unsigned int) (value * 10 + (c - '0'));
3645                        value_ok = 1;
3646                        continue;
3647                }
3648                if (c != ',') {
3649                        fprintf(stderr, "character %c is not a decimal digit\n", c);
3650                        return 0;
3651                }
3652                if (! value_ok) {
3653                        fprintf(stderr, "No valid value before comma\n");
3654                        return 0;
3655                }
3656                if (nb_item < max_items) {
3657                        parsed_items[nb_item] = value;
3658                        value_ok = 0;
3659                        value = 0;
3660                }
3661                nb_item++;
3662        }
3663        if (nb_item >= max_items) {
3664                fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3665                        item_name, nb_item + 1, max_items);
3666                return 0;
3667        }
3668        parsed_items[nb_item++] = value;
3669        if (! check_unique_values)
3670                return nb_item;
3671
3672        /*
3673         * Then, check that all values in the list are differents.
3674         * No optimization here...
3675         */
3676        for (i = 0; i < nb_item; i++) {
3677                for (j = i + 1; j < nb_item; j++) {
3678                        if (parsed_items[j] == parsed_items[i]) {
3679                                fprintf(stderr,
3680                                        "duplicated %s %u at index %u and %u\n",
3681                                        item_name, parsed_items[i], i, j);
3682                                return 0;
3683                        }
3684                }
3685        }
3686        return nb_item;
3687}
3688
3689struct cmd_set_list_result {
3690        cmdline_fixed_string_t cmd_keyword;
3691        cmdline_fixed_string_t list_name;
3692        cmdline_fixed_string_t list_of_items;
3693};
3694
3695static void cmd_set_list_parsed(void *parsed_result,
3696                                __rte_unused struct cmdline *cl,
3697                                __rte_unused void *data)
3698{
3699        struct cmd_set_list_result *res;
3700        union {
3701                unsigned int lcorelist[RTE_MAX_LCORE];
3702                unsigned int portlist[RTE_MAX_ETHPORTS];
3703        } parsed_items;
3704        unsigned int nb_item;
3705
3706        if (test_done == 0) {
3707                fprintf(stderr, "Please stop forwarding first\n");
3708                return;
3709        }
3710
3711        res = parsed_result;
3712        if (!strcmp(res->list_name, "corelist")) {
3713                nb_item = parse_item_list(res->list_of_items, "core",
3714                                          RTE_MAX_LCORE,
3715                                          parsed_items.lcorelist, 1);
3716                if (nb_item > 0) {
3717                        set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3718                        fwd_config_setup();
3719                }
3720                return;
3721        }
3722        if (!strcmp(res->list_name, "portlist")) {
3723                nb_item = parse_item_list(res->list_of_items, "port",
3724                                          RTE_MAX_ETHPORTS,
3725                                          parsed_items.portlist, 1);
3726                if (nb_item > 0) {
3727                        set_fwd_ports_list(parsed_items.portlist, nb_item);
3728                        fwd_config_setup();
3729                }
3730        }
3731}
3732
3733cmdline_parse_token_string_t cmd_set_list_keyword =
3734        TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3735                                 "set");
3736cmdline_parse_token_string_t cmd_set_list_name =
3737        TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3738                                 "corelist#portlist");
3739cmdline_parse_token_string_t cmd_set_list_of_items =
3740        TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3741                                 NULL);
3742
3743cmdline_parse_inst_t cmd_set_fwd_list = {
3744        .f = cmd_set_list_parsed,
3745        .data = NULL,
3746        .help_str = "set corelist|portlist <list0[,list1]*>",
3747        .tokens = {
3748                (void *)&cmd_set_list_keyword,
3749                (void *)&cmd_set_list_name,
3750                (void *)&cmd_set_list_of_items,
3751                NULL,
3752        },
3753};
3754
3755/* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3756
3757struct cmd_setmask_result {
3758        cmdline_fixed_string_t set;
3759        cmdline_fixed_string_t mask;
3760        uint64_t hexavalue;
3761};
3762
3763static void cmd_set_mask_parsed(void *parsed_result,
3764                                __rte_unused struct cmdline *cl,
3765                                __rte_unused void *data)
3766{
3767        struct cmd_setmask_result *res = parsed_result;
3768
3769        if (test_done == 0) {
3770                fprintf(stderr, "Please stop forwarding first\n");
3771                return;
3772        }
3773        if (!strcmp(res->mask, "coremask")) {
3774                set_fwd_lcores_mask(res->hexavalue);
3775                fwd_config_setup();
3776        } else if (!strcmp(res->mask, "portmask")) {
3777                set_fwd_ports_mask(res->hexavalue);
3778                fwd_config_setup();
3779        }
3780}
3781
3782cmdline_parse_token_string_t cmd_setmask_set =
3783        TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3784cmdline_parse_token_string_t cmd_setmask_mask =
3785        TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3786                                 "coremask#portmask");
3787cmdline_parse_token_num_t cmd_setmask_value =
3788        TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3789
3790cmdline_parse_inst_t cmd_set_fwd_mask = {
3791        .f = cmd_set_mask_parsed,
3792        .data = NULL,
3793        .help_str = "set coremask|portmask <hexadecimal value>",
3794        .tokens = {
3795                (void *)&cmd_setmask_set,
3796                (void *)&cmd_setmask_mask,
3797                (void *)&cmd_setmask_value,
3798                NULL,
3799        },
3800};
3801
3802/*
3803 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3804 */
3805struct cmd_set_result {
3806        cmdline_fixed_string_t set;
3807        cmdline_fixed_string_t what;
3808        uint16_t value;
3809};
3810
3811static void cmd_set_parsed(void *parsed_result,
3812                           __rte_unused struct cmdline *cl,
3813                           __rte_unused void *data)
3814{
3815        struct cmd_set_result *res = parsed_result;
3816        if (!strcmp(res->what, "nbport")) {
3817                set_fwd_ports_number(res->value);
3818                fwd_config_setup();
3819        } else if (!strcmp(res->what, "nbcore")) {
3820                set_fwd_lcores_number(res->value);
3821                fwd_config_setup();
3822        } else if (!strcmp(res->what, "burst"))
3823                set_nb_pkt_per_burst(res->value);
3824        else if (!strcmp(res->what, "verbose"))
3825                set_verbose_level(res->value);
3826}
3827
3828cmdline_parse_token_string_t cmd_set_set =
3829        TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3830cmdline_parse_token_string_t cmd_set_what =
3831        TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3832                                 "nbport#nbcore#burst#verbose");
3833cmdline_parse_token_num_t cmd_set_value =
3834        TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3835
3836cmdline_parse_inst_t cmd_set_numbers = {
3837        .f = cmd_set_parsed,
3838        .data = NULL,
3839        .help_str = "set nbport|nbcore|burst|verbose <value>",
3840        .tokens = {
3841                (void *)&cmd_set_set,
3842                (void *)&cmd_set_what,
3843                (void *)&cmd_set_value,
3844                NULL,
3845        },
3846};
3847
3848/* *** SET LOG LEVEL CONFIGURATION *** */
3849
3850struct cmd_set_log_result {
3851        cmdline_fixed_string_t set;
3852        cmdline_fixed_string_t log;
3853        cmdline_fixed_string_t type;
3854        uint32_t level;
3855};
3856
3857static void
3858cmd_set_log_parsed(void *parsed_result,
3859                   __rte_unused struct cmdline *cl,
3860                   __rte_unused void *data)
3861{
3862        struct cmd_set_log_result *res;
3863        int ret;
3864
3865        res = parsed_result;
3866        if (!strcmp(res->type, "global"))
3867                rte_log_set_global_level(res->level);
3868        else {
3869                ret = rte_log_set_level_regexp(res->type, res->level);
3870                if (ret < 0)
3871                        fprintf(stderr, "Unable to set log level\n");
3872        }
3873}
3874
3875cmdline_parse_token_string_t cmd_set_log_set =
3876        TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3877cmdline_parse_token_string_t cmd_set_log_log =
3878        TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3879cmdline_parse_token_string_t cmd_set_log_type =
3880        TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3881cmdline_parse_token_num_t cmd_set_log_level =
3882        TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3883
3884cmdline_parse_inst_t cmd_set_log = {
3885        .f = cmd_set_log_parsed,
3886        .data = NULL,
3887        .help_str = "set log global|<type> <level>",
3888        .tokens = {
3889                (void *)&cmd_set_log_set,
3890                (void *)&cmd_set_log_log,
3891                (void *)&cmd_set_log_type,
3892                (void *)&cmd_set_log_level,
3893                NULL,
3894        },
3895};
3896
3897/* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3898
3899struct cmd_set_rxoffs_result {
3900        cmdline_fixed_string_t cmd_keyword;
3901        cmdline_fixed_string_t rxoffs;
3902        cmdline_fixed_string_t seg_offsets;
3903};
3904
3905static void
3906cmd_set_rxoffs_parsed(void *parsed_result,
3907                      __rte_unused struct cmdline *cl,
3908                      __rte_unused void *data)
3909{
3910        struct cmd_set_rxoffs_result *res;
3911        unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3912        unsigned int nb_segs;
3913
3914        res = parsed_result;
3915        nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3916                                  MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3917        if (nb_segs > 0)
3918                set_rx_pkt_offsets(seg_offsets, nb_segs);
3919        cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3920}
3921
3922cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3923        TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3924                                 cmd_keyword, "set");
3925cmdline_parse_token_string_t cmd_set_rxoffs_name =
3926        TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3927                                 rxoffs, "rxoffs");
3928cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3929        TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3930                                 seg_offsets, NULL);
3931
3932cmdline_parse_inst_t cmd_set_rxoffs = {
3933        .f = cmd_set_rxoffs_parsed,
3934        .data = NULL,
3935        .help_str = "set rxoffs <len0[,len1]*>",
3936        .tokens = {
3937                (void *)&cmd_set_rxoffs_keyword,
3938                (void *)&cmd_set_rxoffs_name,
3939                (void *)&cmd_set_rxoffs_offsets,
3940                NULL,
3941        },
3942};
3943
3944/* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3945
3946struct cmd_set_rxpkts_result {
3947        cmdline_fixed_string_t cmd_keyword;
3948        cmdline_fixed_string_t rxpkts;
3949        cmdline_fixed_string_t seg_lengths;
3950};
3951
3952static void
3953cmd_set_rxpkts_parsed(void *parsed_result,
3954                      __rte_unused struct cmdline *cl,
3955                      __rte_unused void *data)
3956{
3957        struct cmd_set_rxpkts_result *res;
3958        unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3959        unsigned int nb_segs;
3960
3961        res = parsed_result;
3962        nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3963                                  MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3964        if (nb_segs > 0)
3965                set_rx_pkt_segments(seg_lengths, nb_segs);
3966        cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3967}
3968
3969cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3970        TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3971                                 cmd_keyword, "set");
3972cmdline_parse_token_string_t cmd_set_rxpkts_name =
3973        TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3974                                 rxpkts, "rxpkts");
3975cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3976        TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3977                                 seg_lengths, NULL);
3978
3979cmdline_parse_inst_t cmd_set_rxpkts = {
3980        .f = cmd_set_rxpkts_parsed,
3981        .data = NULL,
3982        .help_str = "set rxpkts <len0[,len1]*>",
3983        .tokens = {
3984                (void *)&cmd_set_rxpkts_keyword,
3985                (void *)&cmd_set_rxpkts_name,
3986                (void *)&cmd_set_rxpkts_lengths,
3987                NULL,
3988        },
3989};
3990
3991/* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3992
3993struct cmd_set_txpkts_result {
3994        cmdline_fixed_string_t cmd_keyword;
3995        cmdline_fixed_string_t txpkts;
3996        cmdline_fixed_string_t seg_lengths;
3997};
3998
3999static void
4000cmd_set_txpkts_parsed(void *parsed_result,
4001                      __rte_unused struct cmdline *cl,
4002                      __rte_unused void *data)
4003{
4004        struct cmd_set_txpkts_result *res;
4005        unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4006        unsigned int nb_segs;
4007
4008        res = parsed_result;
4009        nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4010                                  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4011        if (nb_segs > 0)
4012                set_tx_pkt_segments(seg_lengths, nb_segs);
4013}
4014
4015cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4016        TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4017                                 cmd_keyword, "set");
4018cmdline_parse_token_string_t cmd_set_txpkts_name =
4019        TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4020                                 txpkts, "txpkts");
4021cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4022        TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4023                                 seg_lengths, NULL);
4024
4025cmdline_parse_inst_t cmd_set_txpkts = {
4026        .f = cmd_set_txpkts_parsed,
4027        .data = NULL,
4028        .help_str = "set txpkts <len0[,len1]*>",
4029        .tokens = {
4030                (void *)&cmd_set_txpkts_keyword,
4031                (void *)&cmd_set_txpkts_name,
4032                (void *)&cmd_set_txpkts_lengths,
4033                NULL,
4034        },
4035};
4036
4037/* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4038
4039struct cmd_set_txsplit_result {
4040        cmdline_fixed_string_t cmd_keyword;
4041        cmdline_fixed_string_t txsplit;
4042        cmdline_fixed_string_t mode;
4043};
4044
4045static void
4046cmd_set_txsplit_parsed(void *parsed_result,
4047                      __rte_unused struct cmdline *cl,
4048                      __rte_unused void *data)
4049{
4050        struct cmd_set_txsplit_result *res;
4051
4052        res = parsed_result;
4053        set_tx_pkt_split(res->mode);
4054}
4055
4056cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4057        TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4058                                 cmd_keyword, "set");
4059cmdline_parse_token_string_t cmd_set_txsplit_name =
4060        TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4061                                 txsplit, "txsplit");
4062cmdline_parse_token_string_t cmd_set_txsplit_mode =
4063        TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4064                                 mode, NULL);
4065
4066cmdline_parse_inst_t cmd_set_txsplit = {
4067        .f = cmd_set_txsplit_parsed,
4068        .data = NULL,
4069        .help_str = "set txsplit on|off|rand",
4070        .tokens = {
4071                (void *)&cmd_set_txsplit_keyword,
4072                (void *)&cmd_set_txsplit_name,
4073                (void *)&cmd_set_txsplit_mode,
4074                NULL,
4075        },
4076};
4077
4078/* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4079
4080struct cmd_set_txtimes_result {
4081        cmdline_fixed_string_t cmd_keyword;
4082        cmdline_fixed_string_t txtimes;
4083        cmdline_fixed_string_t tx_times;
4084};
4085
4086static void
4087cmd_set_txtimes_parsed(void *parsed_result,
4088                       __rte_unused struct cmdline *cl,
4089                       __rte_unused void *data)
4090{
4091        struct cmd_set_txtimes_result *res;
4092        unsigned int tx_times[2] = {0, 0};
4093        unsigned int n_times;
4094
4095        res = parsed_result;
4096        n_times = parse_item_list(res->tx_times, "tx times",
4097                                  2, tx_times, 0);
4098        if (n_times == 2)
4099                set_tx_pkt_times(tx_times);
4100}
4101
4102cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4103        TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4104                                 cmd_keyword, "set");
4105cmdline_parse_token_string_t cmd_set_txtimes_name =
4106        TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4107                                 txtimes, "txtimes");
4108cmdline_parse_token_string_t cmd_set_txtimes_value =
4109        TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4110                                 tx_times, NULL);
4111
4112cmdline_parse_inst_t cmd_set_txtimes = {
4113        .f = cmd_set_txtimes_parsed,
4114        .data = NULL,
4115        .help_str = "set txtimes <inter_burst>,<intra_burst>",
4116        .tokens = {
4117                (void *)&cmd_set_txtimes_keyword,
4118                (void *)&cmd_set_txtimes_name,
4119                (void *)&cmd_set_txtimes_value,
4120                NULL,
4121        },
4122};
4123
4124/* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4125struct cmd_rx_vlan_filter_all_result {
4126        cmdline_fixed_string_t rx_vlan;
4127        cmdline_fixed_string_t what;
4128        cmdline_fixed_string_t all;
4129        portid_t port_id;
4130};
4131
4132static void
4133cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4134                              __rte_unused struct cmdline *cl,
4135                              __rte_unused void *data)
4136{
4137        struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4138
4139        if (!strcmp(res->what, "add"))
4140                rx_vlan_all_filter_set(res->port_id, 1);
4141        else
4142                rx_vlan_all_filter_set(res->port_id, 0);
4143}
4144
4145cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4146        TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4147                                 rx_vlan, "rx_vlan");
4148cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4149        TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4150                                 what, "add#rm");
4151cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4152        TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4153                                 all, "all");
4154cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4155        TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4156                              port_id, RTE_UINT16);
4157
4158cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4159        .f = cmd_rx_vlan_filter_all_parsed,
4160        .data = NULL,
4161        .help_str = "rx_vlan add|rm all <port_id>: "
4162                "Add/Remove all identifiers to/from the set of VLAN "
4163                "identifiers filtered by a port",
4164        .tokens = {
4165                (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4166                (void *)&cmd_rx_vlan_filter_all_what,
4167                (void *)&cmd_rx_vlan_filter_all_all,
4168                (void *)&cmd_rx_vlan_filter_all_portid,
4169                NULL,
4170        },
4171};
4172
4173/* *** VLAN OFFLOAD SET ON A PORT *** */
4174struct cmd_vlan_offload_result {
4175        cmdline_fixed_string_t vlan;
4176        cmdline_fixed_string_t set;
4177        cmdline_fixed_string_t vlan_type;
4178        cmdline_fixed_string_t what;
4179        cmdline_fixed_string_t on;
4180        cmdline_fixed_string_t port_id;
4181};
4182
4183static void
4184cmd_vlan_offload_parsed(void *parsed_result,
4185                          __rte_unused struct cmdline *cl,
4186                          __rte_unused void *data)
4187{
4188        int on;
4189        struct cmd_vlan_offload_result *res = parsed_result;
4190        char *str;
4191        int i, len = 0;
4192        portid_t port_id = 0;
4193        unsigned int tmp;
4194
4195        str = res->port_id;
4196        len = strnlen(str, STR_TOKEN_SIZE);
4197        i = 0;
4198        /* Get port_id first */
4199        while(i < len){
4200                if(str[i] == ',')
4201                        break;
4202
4203                i++;
4204        }
4205        str[i]='\0';
4206        tmp = strtoul(str, NULL, 0);
4207        /* If port_id greater that what portid_t can represent, return */
4208        if(tmp >= RTE_MAX_ETHPORTS)
4209                return;
4210        port_id = (portid_t)tmp;
4211
4212        if (!strcmp(res->on, "on"))
4213                on = 1;
4214        else
4215                on = 0;
4216
4217        if (!strcmp(res->what, "strip"))
4218                rx_vlan_strip_set(port_id,  on);
4219        else if(!strcmp(res->what, "stripq")){
4220                uint16_t queue_id = 0;
4221
4222                /* No queue_id, return */
4223                if(i + 1 >= len) {
4224                        fprintf(stderr, "must specify (port,queue_id)\n");
4225                        return;
4226                }
4227                tmp = strtoul(str + i + 1, NULL, 0);
4228                /* If queue_id greater that what 16-bits can represent, return */
4229                if(tmp > 0xffff)
4230                        return;
4231
4232                queue_id = (uint16_t)tmp;
4233                rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4234        }
4235        else if (!strcmp(res->what, "filter"))
4236                rx_vlan_filter_set(port_id, on);
4237        else if (!strcmp(res->what, "qinq_strip"))
4238                rx_vlan_qinq_strip_set(port_id, on);
4239        else
4240                vlan_extend_set(port_id, on);
4241
4242        return;
4243}
4244
4245cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4246        TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4247                                 vlan, "vlan");
4248cmdline_parse_token_string_t cmd_vlan_offload_set =
4249        TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4250                                 set, "set");
4251cmdline_parse_token_string_t cmd_vlan_offload_what =
4252        TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4253                                what, "strip#filter#qinq_strip#extend#stripq");
4254cmdline_parse_token_string_t cmd_vlan_offload_on =
4255        TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4256                              on, "on#off");
4257cmdline_parse_token_string_t cmd_vlan_offload_portid =
4258        TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4259                              port_id, NULL);
4260
4261cmdline_parse_inst_t cmd_vlan_offload = {
4262        .f = cmd_vlan_offload_parsed,
4263        .data = NULL,
4264        .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4265                "<port_id[,queue_id]>: "
4266                "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4267        .tokens = {
4268                (void *)&cmd_vlan_offload_vlan,
4269                (void *)&cmd_vlan_offload_set,
4270                (void *)&cmd_vlan_offload_what,
4271                (void *)&cmd_vlan_offload_on,
4272                (void *)&cmd_vlan_offload_portid,
4273                NULL,
4274        },
4275};
4276
4277/* *** VLAN TPID SET ON A PORT *** */
4278struct cmd_vlan_tpid_result {
4279        cmdline_fixed_string_t vlan;
4280        cmdline_fixed_string_t set;
4281        cmdline_fixed_string_t vlan_type;
4282        cmdline_fixed_string_t what;
4283        uint16_t tp_id;
4284        portid_t port_id;
4285};
4286
4287static void
4288cmd_vlan_tpid_parsed(void *parsed_result,
4289                          __rte_unused struct cmdline *cl,
4290                          __rte_unused void *data)
4291{
4292        struct cmd_vlan_tpid_result *res = parsed_result;
4293        enum rte_vlan_type vlan_type;
4294
4295        if (!strcmp(res->vlan_type, "inner"))
4296                vlan_type = ETH_VLAN_TYPE_INNER;
4297        else if (!strcmp(res->vlan_type, "outer"))
4298                vlan_type = ETH_VLAN_TYPE_OUTER;
4299        else {
4300                fprintf(stderr, "Unknown vlan type\n");
4301                return;
4302        }
4303        vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4304}
4305
4306cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4307        TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4308                                 vlan, "vlan");
4309cmdline_parse_token_string_t cmd_vlan_tpid_set =
4310        TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4311                                 set, "set");
4312cmdline_parse_token_string_t cmd_vlan_type =
4313        TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4314                                 vlan_type, "inner#outer");
4315cmdline_parse_token_string_t cmd_vlan_tpid_what =
4316        TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4317                                 what, "tpid");
4318cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4319        TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4320                              tp_id, RTE_UINT16);
4321cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4322        TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4323                              port_id, RTE_UINT16);
4324
4325cmdline_parse_inst_t cmd_vlan_tpid = {
4326        .f = cmd_vlan_tpid_parsed,
4327        .data = NULL,
4328        .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4329                "Set the VLAN Ether type",
4330        .tokens = {
4331                (void *)&cmd_vlan_tpid_vlan,
4332                (void *)&cmd_vlan_tpid_set,
4333                (void *)&cmd_vlan_type,
4334                (void *)&cmd_vlan_tpid_what,
4335                (void *)&cmd_vlan_tpid_tpid,
4336                (void *)&cmd_vlan_tpid_portid,
4337                NULL,
4338        },
4339};
4340
4341/* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4342struct cmd_rx_vlan_filter_result {
4343        cmdline_fixed_string_t rx_vlan;
4344        cmdline_fixed_string_t what;
4345        uint16_t vlan_id;
4346        portid_t port_id;
4347};
4348
4349static void
4350cmd_rx_vlan_filter_parsed(void *parsed_result,
4351                          __rte_unused struct cmdline *cl,
4352                          __rte_unused void *data)
4353{
4354        struct cmd_rx_vlan_filter_result *res = parsed_result;
4355
4356        if (!strcmp(res->what, "add"))
4357                rx_vft_set(res->port_id, res->vlan_id, 1);
4358        else
4359                rx_vft_set(res->port_id, res->vlan_id, 0);
4360}
4361
4362cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4363        TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4364                                 rx_vlan, "rx_vlan");
4365cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4366        TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4367                                 what, "add#rm");
4368cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4369        TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4370                              vlan_id, RTE_UINT16);
4371cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4372        TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4373                              port_id, RTE_UINT16);
4374
4375cmdline_parse_inst_t cmd_rx_vlan_filter = {
4376        .f = cmd_rx_vlan_filter_parsed,
4377        .data = NULL,
4378        .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4379                "Add/Remove a VLAN identifier to/from the set of VLAN "
4380                "identifiers filtered by a port",
4381        .tokens = {
4382                (void *)&cmd_rx_vlan_filter_rx_vlan,
4383                (void *)&cmd_rx_vlan_filter_what,
4384                (void *)&cmd_rx_vlan_filter_vlanid,
4385                (void *)&cmd_rx_vlan_filter_portid,
4386                NULL,
4387        },
4388};
4389
4390/* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4391struct cmd_tx_vlan_set_result {
4392        cmdline_fixed_string_t tx_vlan;
4393        cmdline_fixed_string_t set;
4394        portid_t port_id;
4395        uint16_t vlan_id;
4396};
4397
4398static void
4399cmd_tx_vlan_set_parsed(void *parsed_result,
4400                       __rte_unused struct cmdline *cl,
4401                       __rte_unused void *data)
4402{
4403        struct cmd_tx_vlan_set_result *res = parsed_result;
4404
4405        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4406                return;
4407
4408        if (!port_is_stopped(res->port_id)) {
4409                fprintf(stderr, "Please stop port %d first\n", res->port_id);
4410                return;
4411        }
4412
4413        tx_vlan_set(res->port_id, res->vlan_id);
4414
4415        cmd_reconfig_device_queue(res->port_id, 1, 1);
4416}
4417
4418cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4419        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4420                                 tx_vlan, "tx_vlan");
4421cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4422        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4423                                 set, "set");
4424cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4425        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4426                              port_id, RTE_UINT16);
4427cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4428        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4429                              vlan_id, RTE_UINT16);
4430
4431cmdline_parse_inst_t cmd_tx_vlan_set = {
4432        .f = cmd_tx_vlan_set_parsed,
4433        .data = NULL,
4434        .help_str = "tx_vlan set <port_id> <vlan_id>: "
4435                "Enable hardware insertion of a single VLAN header "
4436                "with a given TAG Identifier in packets sent on a port",
4437        .tokens = {
4438                (void *)&cmd_tx_vlan_set_tx_vlan,
4439                (void *)&cmd_tx_vlan_set_set,
4440                (void *)&cmd_tx_vlan_set_portid,
4441                (void *)&cmd_tx_vlan_set_vlanid,
4442                NULL,
4443        },
4444};
4445
4446/* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4447struct cmd_tx_vlan_set_qinq_result {
4448        cmdline_fixed_string_t tx_vlan;
4449        cmdline_fixed_string_t set;
4450        portid_t port_id;
4451        uint16_t vlan_id;
4452        uint16_t vlan_id_outer;
4453};
4454
4455static void
4456cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4457                            __rte_unused struct cmdline *cl,
4458                            __rte_unused void *data)
4459{
4460        struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4461
4462        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4463                return;
4464
4465        if (!port_is_stopped(res->port_id)) {
4466                fprintf(stderr, "Please stop port %d first\n", res->port_id);
4467                return;
4468        }
4469
4470        tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4471
4472        cmd_reconfig_device_queue(res->port_id, 1, 1);
4473}
4474
4475cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4476        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4477                tx_vlan, "tx_vlan");
4478cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4479        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4480                set, "set");
4481cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4482        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4483                port_id, RTE_UINT16);
4484cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4485        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4486                vlan_id, RTE_UINT16);
4487cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4488        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4489                vlan_id_outer, RTE_UINT16);
4490
4491cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4492        .f = cmd_tx_vlan_set_qinq_parsed,
4493        .data = NULL,
4494        .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4495                "Enable hardware insertion of double VLAN header "
4496                "with given TAG Identifiers in packets sent on a port",
4497        .tokens = {
4498                (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4499                (void *)&cmd_tx_vlan_set_qinq_set,
4500                (void *)&cmd_tx_vlan_set_qinq_portid,
4501                (void *)&cmd_tx_vlan_set_qinq_vlanid,
4502                (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4503                NULL,
4504        },
4505};
4506
4507/* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4508struct cmd_tx_vlan_set_pvid_result {
4509        cmdline_fixed_string_t tx_vlan;
4510        cmdline_fixed_string_t set;
4511        cmdline_fixed_string_t pvid;
4512        portid_t port_id;
4513        uint16_t vlan_id;
4514        cmdline_fixed_string_t mode;
4515};
4516
4517static void
4518cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4519                            __rte_unused struct cmdline *cl,
4520                            __rte_unused void *data)
4521{
4522        struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4523
4524        if (strcmp(res->mode, "on") == 0)
4525                tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4526        else
4527                tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4528}
4529
4530cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4531        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4532                                 tx_vlan, "tx_vlan");
4533cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4534        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4535                                 set, "set");
4536cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4537        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4538                                 pvid, "pvid");
4539cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4540        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4541                             port_id, RTE_UINT16);
4542cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4543        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4544                              vlan_id, RTE_UINT16);
4545cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4546        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4547                                 mode, "on#off");
4548
4549cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4550        .f = cmd_tx_vlan_set_pvid_parsed,
4551        .data = NULL,
4552        .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4553        .tokens = {
4554                (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4555                (void *)&cmd_tx_vlan_set_pvid_set,
4556                (void *)&cmd_tx_vlan_set_pvid_pvid,
4557                (void *)&cmd_tx_vlan_set_pvid_port_id,
4558                (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4559                (void *)&cmd_tx_vlan_set_pvid_mode,
4560                NULL,
4561        },
4562};
4563
4564/* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4565struct cmd_tx_vlan_reset_result {
4566        cmdline_fixed_string_t tx_vlan;
4567        cmdline_fixed_string_t reset;
4568        portid_t port_id;
4569};
4570
4571static void
4572cmd_tx_vlan_reset_parsed(void *parsed_result,
4573                         __rte_unused struct cmdline *cl,
4574                         __rte_unused void *data)
4575{
4576        struct cmd_tx_vlan_reset_result *res = parsed_result;
4577
4578        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4579                return;
4580
4581        if (!port_is_stopped(res->port_id)) {
4582                fprintf(stderr, "Please stop port %d first\n", res->port_id);
4583                return;
4584        }
4585
4586        tx_vlan_reset(res->port_id);
4587
4588        cmd_reconfig_device_queue(res->port_id, 1, 1);
4589}
4590
4591cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4592        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4593                                 tx_vlan, "tx_vlan");
4594cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4595        TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4596                                 reset, "reset");
4597cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4598        TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4599                              port_id, RTE_UINT16);
4600
4601cmdline_parse_inst_t cmd_tx_vlan_reset = {
4602        .f = cmd_tx_vlan_reset_parsed,
4603        .data = NULL,
4604        .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4605                "VLAN header in packets sent on a port",
4606        .tokens = {
4607                (void *)&cmd_tx_vlan_reset_tx_vlan,
4608                (void *)&cmd_tx_vlan_reset_reset,
4609                (void *)&cmd_tx_vlan_reset_portid,
4610                NULL,
4611        },
4612};
4613
4614
4615/* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4616struct cmd_csum_result {
4617        cmdline_fixed_string_t csum;
4618        cmdline_fixed_string_t mode;
4619        cmdline_fixed_string_t proto;
4620        cmdline_fixed_string_t hwsw;
4621        portid_t port_id;
4622};
4623
4624static void
4625csum_show(int port_id)
4626{
4627        struct rte_eth_dev_info dev_info;
4628        uint64_t tx_offloads;
4629        int ret;
4630
4631        tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4632        printf("Parse tunnel is %s\n",
4633                (ports[port_id].parse_tunnel) ? "on" : "off");
4634        printf("IP checksum offload is %s\n",
4635                (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4636        printf("UDP checksum offload is %s\n",
4637                (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4638        printf("TCP checksum offload is %s\n",
4639                (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4640        printf("SCTP checksum offload is %s\n",
4641                (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4642        printf("Outer-Ip checksum offload is %s\n",
4643                (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4644        printf("Outer-Udp checksum offload is %s\n",
4645                (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4646
4647        /* display warnings if configuration is not supported by the NIC */
4648        ret = eth_dev_info_get_print_err(port_id, &dev_info);
4649        if (ret != 0)
4650                return;
4651
4652        if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4653                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4654                fprintf(stderr,
4655                        "Warning: hardware IP checksum enabled but not supported by port %d\n",
4656                        port_id);
4657        }
4658        if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4659                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4660                fprintf(stderr,
4661                        "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4662                        port_id);
4663        }
4664        if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4665                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4666                fprintf(stderr,
4667                        "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4668                        port_id);
4669        }
4670        if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4671                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4672                fprintf(stderr,
4673                        "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4674                        port_id);
4675        }
4676        if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4677                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4678                fprintf(stderr,
4679                        "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4680                        port_id);
4681        }
4682        if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4683                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4684                        == 0) {
4685                fprintf(stderr,
4686                        "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4687                        port_id);
4688        }
4689}
4690
4691static void
4692cmd_config_queue_tx_offloads(struct rte_port *port)
4693{
4694        int k;
4695
4696        /* Apply queue tx offloads configuration */
4697        for (k = 0; k < port->dev_info.max_tx_queues; k++)
4698                port->tx_conf[k].offloads =
4699                        port->dev_conf.txmode.offloads;
4700}
4701
4702static void
4703cmd_csum_parsed(void *parsed_result,
4704                       __rte_unused struct cmdline *cl,
4705                       __rte_unused void *data)
4706{
4707        struct cmd_csum_result *res = parsed_result;
4708        int hw = 0;
4709        uint64_t csum_offloads = 0;
4710        struct rte_eth_dev_info dev_info;
4711        int ret;
4712
4713        if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4714                fprintf(stderr, "invalid port %d\n", res->port_id);
4715                return;
4716        }
4717        if (!port_is_stopped(res->port_id)) {
4718                fprintf(stderr, "Please stop port %d first\n", res->port_id);
4719                return;
4720        }
4721
4722        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4723        if (ret != 0)
4724                return;
4725
4726        if (!strcmp(res->mode, "set")) {
4727
4728                if (!strcmp(res->hwsw, "hw"))
4729                        hw = 1;
4730
4731                if (!strcmp(res->proto, "ip")) {
4732                        if (hw == 0 || (dev_info.tx_offload_capa &
4733                                                DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4734                                csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4735                        } else {
4736                                fprintf(stderr,
4737                                        "IP checksum offload is not supported by port %u\n",
4738                                        res->port_id);
4739                        }
4740                } else if (!strcmp(res->proto, "udp")) {
4741                        if (hw == 0 || (dev_info.tx_offload_capa &
4742                                                DEV_TX_OFFLOAD_UDP_CKSUM)) {
4743                                csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4744                        } else {
4745                                fprintf(stderr,
4746                                        "UDP checksum offload is not supported by port %u\n",
4747                                        res->port_id);
4748                        }
4749                } else if (!strcmp(res->proto, "tcp")) {
4750                        if (hw == 0 || (dev_info.tx_offload_capa &
4751                                                DEV_TX_OFFLOAD_TCP_CKSUM)) {
4752                                csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4753                        } else {
4754                                fprintf(stderr,
4755                                        "TCP checksum offload is not supported by port %u\n",
4756                                        res->port_id);
4757                        }
4758                } else if (!strcmp(res->proto, "sctp")) {
4759                        if (hw == 0 || (dev_info.tx_offload_capa &
4760                                                DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4761                                csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4762                        } else {
4763                                fprintf(stderr,
4764                                        "SCTP checksum offload is not supported by port %u\n",
4765                                        res->port_id);
4766                        }
4767                } else if (!strcmp(res->proto, "outer-ip")) {
4768                        if (hw == 0 || (dev_info.tx_offload_capa &
4769                                        DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4770                                csum_offloads |=
4771                                                DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4772                        } else {
4773                                fprintf(stderr,
4774                                        "Outer IP checksum offload is not supported by port %u\n",
4775                                        res->port_id);
4776                        }
4777                } else if (!strcmp(res->proto, "outer-udp")) {
4778                        if (hw == 0 || (dev_info.tx_offload_capa &
4779                                        DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4780                                csum_offloads |=
4781                                                DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4782                        } else {
4783                                fprintf(stderr,
4784                                        "Outer UDP checksum offload is not supported by port %u\n",
4785                                        res->port_id);
4786                        }
4787                }
4788
4789                if (hw) {
4790                        ports[res->port_id].dev_conf.txmode.offloads |=
4791                                                        csum_offloads;
4792                } else {
4793                        ports[res->port_id].dev_conf.txmode.offloads &=
4794                                                        (~csum_offloads);
4795                }
4796                cmd_config_queue_tx_offloads(&ports[res->port_id]);
4797        }
4798        csum_show(res->port_id);
4799
4800        cmd_reconfig_device_queue(res->port_id, 1, 1);
4801}
4802
4803cmdline_parse_token_string_t cmd_csum_csum =
4804        TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4805                                csum, "csum");
4806cmdline_parse_token_string_t cmd_csum_mode =
4807        TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4808                                mode, "set");
4809cmdline_parse_token_string_t cmd_csum_proto =
4810        TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4811                                proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4812cmdline_parse_token_string_t cmd_csum_hwsw =
4813        TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4814                                hwsw, "hw#sw");
4815cmdline_parse_token_num_t cmd_csum_portid =
4816        TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4817                                port_id, RTE_UINT16);
4818
4819cmdline_parse_inst_t cmd_csum_set = {
4820        .f = cmd_csum_parsed,
4821        .data = NULL,
4822        .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4823                "Enable/Disable hardware calculation of L3/L4 checksum when "
4824                "using csum forward engine",
4825        .tokens = {
4826                (void *)&cmd_csum_csum,
4827                (void *)&cmd_csum_mode,
4828                (void *)&cmd_csum_proto,
4829                (void *)&cmd_csum_hwsw,
4830                (void *)&cmd_csum_portid,
4831                NULL,
4832        },
4833};
4834
4835cmdline_parse_token_string_t cmd_csum_mode_show =
4836        TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4837                                mode, "show");
4838
4839cmdline_parse_inst_t cmd_csum_show = {
4840        .f = cmd_csum_parsed,
4841        .data = NULL,
4842        .help_str = "csum show <port_id>: Show checksum offload configuration",
4843        .tokens = {
4844                (void *)&cmd_csum_csum,
4845                (void *)&cmd_csum_mode_show,
4846                (void *)&cmd_csum_portid,
4847                NULL,
4848        },
4849};
4850
4851/* Enable/disable tunnel parsing */
4852struct cmd_csum_tunnel_result {
4853        cmdline_fixed_string_t csum;
4854        cmdline_fixed_string_t parse;
4855        cmdline_fixed_string_t onoff;
4856        portid_t port_id;
4857};
4858
4859static void
4860cmd_csum_tunnel_parsed(void *parsed_result,
4861                       __rte_unused struct cmdline *cl,
4862                       __rte_unused void *data)
4863{
4864        struct cmd_csum_tunnel_result *res = parsed_result;
4865
4866        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4867                return;
4868
4869        if (!strcmp(res->onoff, "on"))
4870                ports[res->port_id].parse_tunnel = 1;
4871        else
4872                ports[res->port_id].parse_tunnel = 0;
4873
4874        csum_show(res->port_id);
4875}
4876
4877cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4878        TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4879                                csum, "csum");
4880cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4881        TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4882                                parse, "parse-tunnel");
4883cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4884        TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4885                                onoff, "on#off");
4886cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4887        TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4888                                port_id, RTE_UINT16);
4889
4890cmdline_parse_inst_t cmd_csum_tunnel = {
4891        .f = cmd_csum_tunnel_parsed,
4892        .data = NULL,
4893        .help_str = "csum parse-tunnel on|off <port_id>: "
4894                "Enable/Disable parsing of tunnels for csum engine",
4895        .tokens = {
4896                (void *)&cmd_csum_tunnel_csum,
4897                (void *)&cmd_csum_tunnel_parse,
4898                (void *)&cmd_csum_tunnel_onoff,
4899                (void *)&cmd_csum_tunnel_portid,
4900                NULL,
4901        },
4902};
4903
4904/* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4905struct cmd_tso_set_result {
4906        cmdline_fixed_string_t tso;
4907        cmdline_fixed_string_t mode;
4908        uint16_t tso_segsz;
4909        portid_t port_id;
4910};
4911
4912static void
4913cmd_tso_set_parsed(void *parsed_result,
4914                       __rte_unused struct cmdline *cl,
4915                       __rte_unused void *data)
4916{
4917        struct cmd_tso_set_result *res = parsed_result;
4918        struct rte_eth_dev_info dev_info;
4919        int ret;
4920
4921        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4922                return;
4923        if (!port_is_stopped(res->port_id)) {
4924                fprintf(stderr, "Please stop port %d first\n", res->port_id);
4925                return;
4926        }
4927
4928        if (!strcmp(res->mode, "set"))
4929                ports[res->port_id].tso_segsz = res->tso_segsz;
4930
4931        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4932        if (ret != 0)
4933                return;
4934
4935        if ((ports[res->port_id].tso_segsz != 0) &&
4936                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4937                fprintf(stderr, "Error: TSO is not supported by port %d\n",
4938                        res->port_id);
4939                return;
4940        }
4941
4942        if (ports[res->port_id].tso_segsz == 0) {
4943                ports[res->port_id].dev_conf.txmode.offloads &=
4944                                                ~DEV_TX_OFFLOAD_TCP_TSO;
4945                printf("TSO for non-tunneled packets is disabled\n");
4946        } else {
4947                ports[res->port_id].dev_conf.txmode.offloads |=
4948                                                DEV_TX_OFFLOAD_TCP_TSO;
4949                printf("TSO segment size for non-tunneled packets is %d\n",
4950                        ports[res->port_id].tso_segsz);
4951        }
4952        cmd_config_queue_tx_offloads(&ports[res->port_id]);
4953
4954        /* display warnings if configuration is not supported by the NIC */
4955        ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4956        if (ret != 0)
4957                return;
4958
4959        if ((ports[res->port_id].tso_segsz != 0) &&
4960                (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4961                fprintf(stderr,
4962                        "Warning: TSO enabled but not supported by port %d\n",
4963                        res->port_id);
4964        }
4965
4966        cmd_reconfig_device_queue(res->port_id, 1, 1);
4967}
4968
4969cmdline_parse_token_string_t cmd_tso_set_tso =
4970        TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4971                                tso, "tso");
4972cmdline_parse_token_string_t cmd_tso_set_mode =
4973        TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4974                                mode, "set");
4975cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4976        TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4977                                tso_segsz, RTE_UINT16);
4978cmdline_parse_token_num_t cmd_tso_set_portid =
4979        TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4980                                port_id, RTE_UINT16);
4981
4982cmdline_parse_inst_t cmd_tso_set = {
4983        .f = cmd_tso_set_parsed,
4984        .data = NULL,
4985        .help_str = "tso set <tso_segsz> <port_id>: "
4986                "Set TSO segment size of non-tunneled packets for csum engine "
4987                "(0 to disable)",
4988        .tokens = {
4989                (void *)&cmd_tso_set_tso,
4990                (void *)&cmd_tso_set_mode,
4991                (void *)&cmd_tso_set_tso_segsz,
4992                (void *)&cmd_tso_set_portid,
4993                NULL,
4994        },
4995};
4996
4997cmdline_parse_token_string_t cmd_tso_show_mode =
4998        TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4999                                mode, "show");
5000
5001
5002cmdline_parse_inst_t cmd_tso_show = {
5003        .f = cmd_tso_set_parsed,
5004        .data = NULL,
5005        .help_str = "tso show <port_id>: "
5006                "Show TSO segment size of non-tunneled packets for csum engine",
5007        .tokens = {
5008                (void *)&cmd_tso_set_tso,
5009                (void *)&cmd_tso_show_mode,
5010                (void *)&cmd_tso_set_portid,
5011                NULL,
5012        },
5013};
5014
5015/* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5016struct cmd_tunnel_tso_set_result {
5017        cmdline_fixed_string_t tso;
5018        cmdline_fixed_string_t mode;
5019        uint16_t tso_segsz;
5020        portid_t port_id;
5021};
5022
5023static struct rte_eth_dev_info
5024check_tunnel_tso_nic_support(portid_t port_id)
5025{
5026        struct rte_eth_dev_info dev_info;
5027
5028        if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5029                return dev_info;
5030
5031        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5032                fprintf(stderr,
5033                        "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5034                        port_id);
5035        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5036                fprintf(stderr,
5037                        "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5038                        port_id);
5039        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5040                fprintf(stderr,
5041                        "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5042                        port_id);
5043        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5044                fprintf(stderr,
5045                        "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5046                        port_id);
5047        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5048                fprintf(stderr,
5049                        "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5050                        port_id);
5051        if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5052                fprintf(stderr,
5053                        "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5054                        port_id);
5055        return dev_info;
5056}
5057
5058static void
5059cmd_tunnel_tso_set_parsed(void *parsed_result,
5060                          __rte_unused struct cmdline *cl,
5061                          __rte_unused void *data)
5062{
5063        struct cmd_tunnel_tso_set_result *res = parsed_result;
5064        struct rte_eth_dev_info dev_info;
5065
5066        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5067                return;
5068        if (!port_is_stopped(res->port_id)) {
5069                fprintf(stderr, "Please stop port %d first\n", res->port_id);
5070                return;
5071        }
5072
5073        if (!strcmp(res->mode, "set"))
5074                ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5075
5076        dev_info = check_tunnel_tso_nic_support(res->port_id);
5077        if (ports[res->port_id].tunnel_tso_segsz == 0) {
5078                ports[res->port_id].dev_conf.txmode.offloads &=
5079                        ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5080                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5081                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5082                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5083                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5084                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5085                printf("TSO for tunneled packets is disabled\n");
5086        } else {
5087                uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5088                                         DEV_TX_OFFLOAD_GRE_TNL_TSO |
5089                                         DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5090                                         DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5091                                         DEV_TX_OFFLOAD_IP_TNL_TSO |
5092                                         DEV_TX_OFFLOAD_UDP_TNL_TSO);
5093
5094                ports[res->port_id].dev_conf.txmode.offloads |=
5095                        (tso_offloads & dev_info.tx_offload_capa);
5096                printf("TSO segment size for tunneled packets is %d\n",
5097                        ports[res->port_id].tunnel_tso_segsz);
5098
5099                /* Below conditions are needed to make it work:
5100                 * (1) tunnel TSO is supported by the NIC;
5101                 * (2) "csum parse_tunnel" must be set so that tunneled pkts
5102                 * are recognized;
5103                 * (3) for tunneled pkts with outer L3 of IPv4,
5104                 * "csum set outer-ip" must be set to hw, because after tso,
5105                 * total_len of outer IP header is changed, and the checksum
5106                 * of outer IP header calculated by sw should be wrong; that
5107                 * is not necessary for IPv6 tunneled pkts because there's no
5108                 * checksum in IP header anymore.
5109                 */
5110
5111                if (!ports[res->port_id].parse_tunnel)
5112                        fprintf(stderr,
5113                                "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5114                if (!(ports[res->port_id].dev_conf.txmode.offloads &
5115                      DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5116                        fprintf(stderr,
5117                                "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5118        }
5119
5120        cmd_config_queue_tx_offloads(&ports[res->port_id]);
5121        cmd_reconfig_device_queue(res->port_id, 1, 1);
5122}
5123
5124cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5125        TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5126                                tso, "tunnel_tso");
5127cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5128        TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5129                                mode, "set");
5130cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5131        TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5132                                tso_segsz, RTE_UINT16);
5133cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5134        TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5135                                port_id, RTE_UINT16);
5136
5137cmdline_parse_inst_t cmd_tunnel_tso_set = {
5138        .f = cmd_tunnel_tso_set_parsed,
5139        .data = NULL,
5140        .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5141                "Set TSO segment size of tunneled packets for csum engine "
5142                "(0 to disable)",
5143        .tokens = {
5144                (void *)&cmd_tunnel_tso_set_tso,
5145                (void *)&cmd_tunnel_tso_set_mode,
5146                (void *)&cmd_tunnel_tso_set_tso_segsz,
5147                (void *)&cmd_tunnel_tso_set_portid,
5148                NULL,
5149        },
5150};
5151
5152cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5153        TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5154                                mode, "show");
5155
5156
5157cmdline_parse_inst_t cmd_tunnel_tso_show = {
5158        .f = cmd_tunnel_tso_set_parsed,
5159        .data = NULL,
5160        .help_str = "tunnel_tso show <port_id> "
5161                "Show TSO segment size of tunneled packets for csum engine",
5162        .tokens = {
5163                (void *)&cmd_tunnel_tso_set_tso,
5164                (void *)&cmd_tunnel_tso_show_mode,
5165                (void *)&cmd_tunnel_tso_set_portid,
5166                NULL,
5167        },
5168};
5169
5170/* *** SET GRO FOR A PORT *** */
5171struct cmd_gro_enable_result {
5172        cmdline_fixed_string_t cmd_set;
5173        cmdline_fixed_string_t cmd_port;
5174        cmdline_fixed_string_t cmd_keyword;
5175        cmdline_fixed_string_t cmd_onoff;
5176        portid_t cmd_pid;
5177};
5178
5179static void
5180cmd_gro_enable_parsed(void *parsed_result,
5181                __rte_unused struct cmdline *cl,
5182                __rte_unused void *data)
5183{
5184        struct cmd_gro_enable_result *res;
5185
5186        res = parsed_result;
5187        if (!strcmp(res->cmd_keyword, "gro"))
5188                setup_gro(res->cmd_onoff, res->cmd_pid);
5189}
5190
5191cmdline_parse_token_string_t cmd_gro_enable_set =
5192        TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5193                        cmd_set, "set");
5194cmdline_parse_token_string_t cmd_gro_enable_port =
5195        TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5196                        cmd_keyword, "port");
5197cmdline_parse_token_num_t cmd_gro_enable_pid =
5198        TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5199                        cmd_pid, RTE_UINT16);
5200cmdline_parse_token_string_t cmd_gro_enable_keyword =
5201        TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5202                        cmd_keyword, "gro");
5203cmdline_parse_token_string_t cmd_gro_enable_onoff =
5204        TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5205                        cmd_onoff, "on#off");
5206
5207cmdline_parse_inst_t cmd_gro_enable = {
5208        .f = cmd_gro_enable_parsed,
5209        .data = NULL,
5210        .help_str = "set port <port_id> gro on|off",
5211        .tokens = {
5212                (void *)&cmd_gro_enable_set,
5213                (void *)&cmd_gro_enable_port,
5214                (void *)&cmd_gro_enable_pid,
5215                (void *)&cmd_gro_enable_keyword,
5216                (void *)&cmd_gro_enable_onoff,
5217                NULL,
5218        },
5219};
5220
5221/* *** DISPLAY GRO CONFIGURATION *** */
5222struct cmd_gro_show_result {
5223        cmdline_fixed_string_t cmd_show;
5224        cmdline_fixed_string_t cmd_port;
5225        cmdline_fixed_string_t cmd_keyword;
5226        portid_t cmd_pid;
5227};
5228
5229static void
5230cmd_gro_show_parsed(void *parsed_result,
5231                __rte_unused struct cmdline *cl,
5232                __rte_unused void *data)
5233{
5234        struct cmd_gro_show_result *res;
5235
5236        res = parsed_result;
5237        if (!strcmp(res->cmd_keyword, "gro"))
5238                show_gro(res->cmd_pid);
5239}
5240
5241cmdline_parse_token_string_t cmd_gro_show_show =
5242        TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5243                        cmd_show, "show");
5244cmdline_parse_token_string_t cmd_gro_show_port =
5245        TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5246                        cmd_port, "port");
5247cmdline_parse_token_num_t cmd_gro_show_pid =
5248        TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5249                        cmd_pid, RTE_UINT16);
5250cmdline_parse_token_string_t cmd_gro_show_keyword =
5251        TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5252                        cmd_keyword, "gro");
5253
5254cmdline_parse_inst_t cmd_gro_show = {
5255        .f = cmd_gro_show_parsed,
5256        .data = NULL,
5257        .help_str = "show port <port_id> gro",
5258        .tokens = {
5259                (void *)&cmd_gro_show_show,
5260                (void *)&cmd_gro_show_port,
5261                (void *)&cmd_gro_show_pid,
5262                (void *)&cmd_gro_show_keyword,
5263                NULL,
5264        },
5265};
5266
5267/* *** SET FLUSH CYCLES FOR GRO *** */
5268struct cmd_gro_flush_result {
5269        cmdline_fixed_string_t cmd_set;
5270        cmdline_fixed_string_t cmd_keyword;
5271        cmdline_fixed_string_t cmd_flush;
5272        uint8_t cmd_cycles;
5273};
5274
5275static void
5276cmd_gro_flush_parsed(void *parsed_result,
5277                __rte_unused struct cmdline *cl,
5278                __rte_unused void *data)
5279{
5280        struct cmd_gro_flush_result *res;
5281
5282        res = parsed_result;
5283        if ((!strcmp(res->cmd_keyword, "gro")) &&
5284                        (!strcmp(res->cmd_flush, "flush")))
5285                setup_gro_flush_cycles(res->cmd_cycles);
5286}
5287
5288cmdline_parse_token_string_t cmd_gro_flush_set =
5289        TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5290                        cmd_set, "set");
5291cmdline_parse_token_string_t cmd_gro_flush_keyword =
5292        TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5293                        cmd_keyword, "gro");
5294cmdline_parse_token_string_t cmd_gro_flush_flush =
5295        TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5296                        cmd_flush, "flush");
5297cmdline_parse_token_num_t cmd_gro_flush_cycles =
5298        TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5299                        cmd_cycles, RTE_UINT8);
5300
5301cmdline_parse_inst_t cmd_gro_flush = {
5302        .f = cmd_gro_flush_parsed,
5303        .data = NULL,
5304        .help_str = "set gro flush <cycles>",
5305        .tokens = {
5306                (void *)&cmd_gro_flush_set,
5307                (void *)&cmd_gro_flush_keyword,
5308                (void *)&cmd_gro_flush_flush,
5309                (void *)&cmd_gro_flush_cycles,
5310                NULL,
5311        },
5312};
5313
5314/* *** ENABLE/DISABLE GSO *** */
5315struct cmd_gso_enable_result {
5316        cmdline_fixed_string_t cmd_set;
5317        cmdline_fixed_string_t cmd_port;
5318        cmdline_fixed_string_t cmd_keyword;
5319        cmdline_fixed_string_t cmd_mode;
5320        portid_t cmd_pid;
5321};
5322
5323static void
5324cmd_gso_enable_parsed(void *parsed_result,
5325                __rte_unused struct cmdline *cl,
5326                __rte_unused void *data)
5327{
5328        struct cmd_gso_enable_result *res;
5329
5330        res = parsed_result;
5331        if (!strcmp(res->cmd_keyword, "gso"))
5332                setup_gso(res->cmd_mode, res->cmd_pid);
5333}
5334
5335cmdline_parse_token_string_t cmd_gso_enable_set =
5336        TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5337                        cmd_set, "set");
5338cmdline_parse_token_string_t cmd_gso_enable_port =
5339        TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5340                        cmd_port, "port");
5341cmdline_parse_token_string_t cmd_gso_enable_keyword =
5342        TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5343                        cmd_keyword, "gso");
5344cmdline_parse_token_string_t cmd_gso_enable_mode =
5345        TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5346                        cmd_mode, "on#off");
5347cmdline_parse_token_num_t cmd_gso_enable_pid =
5348        TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5349                        cmd_pid, RTE_UINT16);
5350
5351cmdline_parse_inst_t cmd_gso_enable = {
5352        .f = cmd_gso_enable_parsed,
5353        .data = NULL,
5354        .help_str = "set port <port_id> gso on|off",
5355        .tokens = {
5356                (void *)&cmd_gso_enable_set,
5357                (void *)&cmd_gso_enable_port,
5358                (void *)&cmd_gso_enable_pid,
5359                (void *)&cmd_gso_enable_keyword,
5360                (void *)&cmd_gso_enable_mode,
5361                NULL,
5362        },
5363};
5364
5365/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5366struct cmd_gso_size_result {
5367        cmdline_fixed_string_t cmd_set;
5368        cmdline_fixed_string_t cmd_keyword;
5369        cmdline_fixed_string_t cmd_segsz;
5370        uint16_t cmd_size;
5371};
5372
5373static void
5374cmd_gso_size_parsed(void *parsed_result,
5375                       __rte_unused struct cmdline *cl,
5376                       __rte_unused void *data)
5377{
5378        struct cmd_gso_size_result *res = parsed_result;
5379
5380        if (test_done == 0) {
5381                fprintf(stderr,
5382                        "Before setting GSO segsz, please first stop forwarding\n");
5383                return;
5384        }
5385
5386        if (!strcmp(res->cmd_keyword, "gso") &&
5387                        !strcmp(res->cmd_segsz, "segsz")) {
5388                if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5389                        fprintf(stderr,
5390                                "gso_size should be larger than %zu. Please input a legal value\n",
5391                                RTE_GSO_SEG_SIZE_MIN);
5392                else
5393                        gso_max_segment_size = res->cmd_size;
5394        }
5395}
5396
5397cmdline_parse_token_string_t cmd_gso_size_set =
5398        TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5399                                cmd_set, "set");
5400cmdline_parse_token_string_t cmd_gso_size_keyword =
5401        TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5402                                cmd_keyword, "gso");
5403cmdline_parse_token_string_t cmd_gso_size_segsz =
5404        TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5405                                cmd_segsz, "segsz");
5406cmdline_parse_token_num_t cmd_gso_size_size =
5407        TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5408                                cmd_size, RTE_UINT16);
5409
5410cmdline_parse_inst_t cmd_gso_size = {
5411        .f = cmd_gso_size_parsed,
5412        .data = NULL,
5413        .help_str = "set gso segsz <length>",
5414        .tokens = {
5415                (void *)&cmd_gso_size_set,
5416                (void *)&cmd_gso_size_keyword,
5417                (void *)&cmd_gso_size_segsz,
5418                (void *)&cmd_gso_size_size,
5419                NULL,
5420        },
5421};
5422
5423/* *** SHOW GSO CONFIGURATION *** */
5424struct cmd_gso_show_result {
5425        cmdline_fixed_string_t cmd_show;
5426        cmdline_fixed_string_t cmd_port;
5427        cmdline_fixed_string_t cmd_keyword;
5428        portid_t cmd_pid;
5429};
5430
5431static void
5432cmd_gso_show_parsed(void *parsed_result,
5433                       __rte_unused struct cmdline *cl,
5434                       __rte_unused void *data)
5435{
5436        struct cmd_gso_show_result *res = parsed_result;
5437
5438        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5439                fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5440                return;
5441        }
5442        if (!strcmp(res->cmd_keyword, "gso")) {
5443                if (gso_ports[res->cmd_pid].enable) {
5444                        printf("Max GSO'd packet size: %uB\n"
5445                                        "Supported GSO types: TCP/IPv4, "
5446                                        "UDP/IPv4, VxLAN with inner "
5447                                        "TCP/IPv4 packet, GRE with inner "
5448                                        "TCP/IPv4 packet\n",
5449                                        gso_max_segment_size);
5450                } else
5451                        printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5452        }
5453}
5454
5455cmdline_parse_token_string_t cmd_gso_show_show =
5456TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5457                cmd_show, "show");
5458cmdline_parse_token_string_t cmd_gso_show_port =
5459TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5460                cmd_port, "port");
5461cmdline_parse_token_string_t cmd_gso_show_keyword =
5462        TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5463                                cmd_keyword, "gso");
5464cmdline_parse_token_num_t cmd_gso_show_pid =
5465        TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5466                                cmd_pid, RTE_UINT16);
5467
5468cmdline_parse_inst_t cmd_gso_show = {
5469        .f = cmd_gso_show_parsed,
5470        .data = NULL,
5471        .help_str = "show port <port_id> gso",
5472        .tokens = {
5473                (void *)&cmd_gso_show_show,
5474                (void *)&cmd_gso_show_port,
5475                (void *)&cmd_gso_show_pid,
5476                (void *)&cmd_gso_show_keyword,
5477                NULL,
5478        },
5479};
5480
5481/* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5482struct cmd_set_flush_rx {
5483        cmdline_fixed_string_t set;
5484        cmdline_fixed_string_t flush_rx;
5485        cmdline_fixed_string_t mode;
5486};
5487
5488static void
5489cmd_set_flush_rx_parsed(void *parsed_result,
5490                __rte_unused struct cmdline *cl,
5491                __rte_unused void *data)
5492{
5493        struct cmd_set_flush_rx *res = parsed_result;
5494        no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5495}
5496
5497cmdline_parse_token_string_t cmd_setflushrx_set =
5498        TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5499                        set, "set");
5500cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5501        TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5502                        flush_rx, "flush_rx");
5503cmdline_parse_token_string_t cmd_setflushrx_mode =
5504        TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5505                        mode, "on#off");
5506
5507
5508cmdline_parse_inst_t cmd_set_flush_rx = {
5509        .f = cmd_set_flush_rx_parsed,
5510        .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5511        .data = NULL,
5512        .tokens = {
5513                (void *)&cmd_setflushrx_set,
5514                (void *)&cmd_setflushrx_flush_rx,
5515                (void *)&cmd_setflushrx_mode,
5516                NULL,
5517        },
5518};
5519
5520/* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5521struct cmd_set_link_check {
5522        cmdline_fixed_string_t set;
5523        cmdline_fixed_string_t link_check;
5524        cmdline_fixed_string_t mode;
5525};
5526
5527static void
5528cmd_set_link_check_parsed(void *parsed_result,
5529                __rte_unused struct cmdline *cl,
5530                __rte_unused void *data)
5531{
5532        struct cmd_set_link_check *res = parsed_result;
5533        no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5534}
5535
5536cmdline_parse_token_string_t cmd_setlinkcheck_set =
5537        TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5538                        set, "set");
5539cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5540        TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5541                        link_check, "link_check");
5542cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5543        TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5544                        mode, "on#off");
5545
5546
5547cmdline_parse_inst_t cmd_set_link_check = {
5548        .f = cmd_set_link_check_parsed,
5549        .help_str = "set link_check on|off: Enable/Disable link status check "
5550                    "when starting/stopping a port",
5551        .data = NULL,
5552        .tokens = {
5553                (void *)&cmd_setlinkcheck_set,
5554                (void *)&cmd_setlinkcheck_link_check,
5555                (void *)&cmd_setlinkcheck_mode,
5556                NULL,
5557        },
5558};
5559
5560/* *** SET NIC BYPASS MODE *** */
5561struct cmd_set_bypass_mode_result {
5562        cmdline_fixed_string_t set;
5563        cmdline_fixed_string_t bypass;
5564        cmdline_fixed_string_t mode;
5565        cmdline_fixed_string_t value;
5566        portid_t port_id;
5567};
5568
5569static void
5570cmd_set_bypass_mode_parsed(void *parsed_result,
5571                __rte_unused struct cmdline *cl,
5572                __rte_unused void *data)
5573{
5574        struct cmd_set_bypass_mode_result *res = parsed_result;
5575        portid_t port_id = res->port_id;
5576        int32_t rc = -EINVAL;
5577
5578#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5579        uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5580
5581        if (!strcmp(res->value, "bypass"))
5582                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5583        else if (!strcmp(res->value, "isolate"))
5584                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5585        else
5586                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5587
5588        /* Set the bypass mode for the relevant port. */
5589        rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5590#endif
5591        if (rc != 0)
5592                fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5593                        port_id);
5594}
5595
5596cmdline_parse_token_string_t cmd_setbypass_mode_set =
5597        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5598                        set, "set");
5599cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5600        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5601                        bypass, "bypass");
5602cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5603        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5604                        mode, "mode");
5605cmdline_parse_token_string_t cmd_setbypass_mode_value =
5606        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5607                        value, "normal#bypass#isolate");
5608cmdline_parse_token_num_t cmd_setbypass_mode_port =
5609        TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5610                                port_id, RTE_UINT16);
5611
5612cmdline_parse_inst_t cmd_set_bypass_mode = {
5613        .f = cmd_set_bypass_mode_parsed,
5614        .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5615                    "Set the NIC bypass mode for port_id",
5616        .data = NULL,
5617        .tokens = {
5618                (void *)&cmd_setbypass_mode_set,
5619                (void *)&cmd_setbypass_mode_bypass,
5620                (void *)&cmd_setbypass_mode_mode,
5621                (void *)&cmd_setbypass_mode_value,
5622                (void *)&cmd_setbypass_mode_port,
5623                NULL,
5624        },
5625};
5626
5627/* *** SET NIC BYPASS EVENT *** */
5628struct cmd_set_bypass_event_result {
5629        cmdline_fixed_string_t set;
5630        cmdline_fixed_string_t bypass;
5631        cmdline_fixed_string_t event;
5632        cmdline_fixed_string_t event_value;
5633        cmdline_fixed_string_t mode;
5634        cmdline_fixed_string_t mode_value;
5635        portid_t port_id;
5636};
5637
5638static void
5639cmd_set_bypass_event_parsed(void *parsed_result,
5640                __rte_unused struct cmdline *cl,
5641                __rte_unused void *data)
5642{
5643        int32_t rc = -EINVAL;
5644        struct cmd_set_bypass_event_result *res = parsed_result;
5645        portid_t port_id = res->port_id;
5646
5647#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5648        uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5649        uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5650
5651        if (!strcmp(res->event_value, "timeout"))
5652                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5653        else if (!strcmp(res->event_value, "os_on"))
5654                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5655        else if (!strcmp(res->event_value, "os_off"))
5656                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5657        else if (!strcmp(res->event_value, "power_on"))
5658                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5659        else if (!strcmp(res->event_value, "power_off"))
5660                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5661        else
5662                bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5663
5664        if (!strcmp(res->mode_value, "bypass"))
5665                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5666        else if (!strcmp(res->mode_value, "isolate"))
5667                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5668        else
5669                bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5670
5671        /* Set the watchdog timeout. */
5672        if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5673
5674                rc = -EINVAL;
5675                if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5676                        rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5677                                                           bypass_timeout);
5678                }
5679                if (rc != 0) {
5680                        fprintf(stderr,
5681                                "Failed to set timeout value %u for port %d, errto code: %d.\n",
5682                                bypass_timeout, port_id, rc);
5683                }
5684        }
5685
5686        /* Set the bypass event to transition to bypass mode. */
5687        rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5688                                              bypass_mode);
5689#endif
5690
5691        if (rc != 0)
5692                fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5693                        port_id);
5694}
5695
5696cmdline_parse_token_string_t cmd_setbypass_event_set =
5697        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5698                        set, "set");
5699cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5700        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5701                        bypass, "bypass");
5702cmdline_parse_token_string_t cmd_setbypass_event_event =
5703        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5704                        event, "event");
5705cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5706        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5707                        event_value, "none#timeout#os_off#os_on#power_on#power_off");
5708cmdline_parse_token_string_t cmd_setbypass_event_mode =
5709        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5710                        mode, "mode");
5711cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5712        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5713                        mode_value, "normal#bypass#isolate");
5714cmdline_parse_token_num_t cmd_setbypass_event_port =
5715        TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5716                                port_id, RTE_UINT16);
5717
5718cmdline_parse_inst_t cmd_set_bypass_event = {
5719        .f = cmd_set_bypass_event_parsed,
5720        .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5721                "power_off mode normal|bypass|isolate <port_id>: "
5722                "Set the NIC bypass event mode for port_id",
5723        .data = NULL,
5724        .tokens = {
5725                (void *)&cmd_setbypass_event_set,
5726                (void *)&cmd_setbypass_event_bypass,
5727                (void *)&cmd_setbypass_event_event,
5728                (void *)&cmd_setbypass_event_event_value,
5729                (void *)&cmd_setbypass_event_mode,
5730                (void *)&cmd_setbypass_event_mode_value,
5731                (void *)&cmd_setbypass_event_port,
5732                NULL,
5733        },
5734};
5735
5736
5737/* *** SET NIC BYPASS TIMEOUT *** */
5738struct cmd_set_bypass_timeout_result {
5739        cmdline_fixed_string_t set;
5740        cmdline_fixed_string_t bypass;
5741        cmdline_fixed_string_t timeout;
5742        cmdline_fixed_string_t value;
5743};
5744
5745static void
5746cmd_set_bypass_timeout_parsed(void *parsed_result,
5747                __rte_unused struct cmdline *cl,
5748                __rte_unused void *data)
5749{
5750        __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5751
5752#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5753        if (!strcmp(res->value, "1.5"))
5754                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5755        else if (!strcmp(res->value, "2"))
5756                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5757        else if (!strcmp(res->value, "3"))
5758                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5759        else if (!strcmp(res->value, "4"))
5760                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5761        else if (!strcmp(res->value, "8"))
5762                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5763        else if (!strcmp(res->value, "16"))
5764                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5765        else if (!strcmp(res->value, "32"))
5766                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5767        else
5768                bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5769#endif
5770}
5771
5772cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5773        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5774                        set, "set");
5775cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5776        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5777                        bypass, "bypass");
5778cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5779        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5780                        timeout, "timeout");
5781cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5782        TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5783                        value, "0#1.5#2#3#4#8#16#32");
5784
5785cmdline_parse_inst_t cmd_set_bypass_timeout = {
5786        .f = cmd_set_bypass_timeout_parsed,
5787        .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5788                "Set the NIC bypass watchdog timeout in seconds",
5789        .data = NULL,
5790        .tokens = {
5791                (void *)&cmd_setbypass_timeout_set,
5792                (void *)&cmd_setbypass_timeout_bypass,
5793                (void *)&cmd_setbypass_timeout_timeout,
5794                (void *)&cmd_setbypass_timeout_value,
5795                NULL,
5796        },
5797};
5798
5799/* *** SHOW NIC BYPASS MODE *** */
5800struct cmd_show_bypass_config_result {
5801        cmdline_fixed_string_t show;
5802        cmdline_fixed_string_t bypass;
5803        cmdline_fixed_string_t config;
5804        portid_t port_id;
5805};
5806
5807static void
5808cmd_show_bypass_config_parsed(void *parsed_result,
5809                __rte_unused struct cmdline *cl,
5810                __rte_unused void *data)
5811{
5812        struct cmd_show_bypass_config_result *res = parsed_result;
5813        portid_t port_id = res->port_id;
5814        int rc = -EINVAL;
5815#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5816        uint32_t event_mode;
5817        uint32_t bypass_mode;
5818        uint32_t timeout = bypass_timeout;
5819        unsigned int i;
5820
5821        static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5822                {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5823        static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5824                {"UNKNOWN", "normal", "bypass", "isolate"};
5825        static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5826                "NONE",
5827                "OS/board on",
5828                "power supply on",
5829                "OS/board off",
5830                "power supply off",
5831                "timeout"};
5832
5833        /* Display the bypass mode.*/
5834        if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5835                fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5836                        port_id);
5837                return;
5838        }
5839        else {
5840                if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5841                        bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5842
5843                printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5844        }
5845
5846        /* Display the bypass timeout.*/
5847        if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5848                timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5849
5850        printf("\tbypass timeout = %s\n", timeouts[timeout]);
5851
5852        /* Display the bypass events and associated modes. */
5853        for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5854
5855                if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5856                        fprintf(stderr,
5857                                "\tFailed to get bypass mode for event = %s\n",
5858                                events[i]);
5859                } else {
5860                        if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5861                                event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5862
5863                        printf("\tbypass event: %-16s = %s\n", events[i],
5864                                modes[event_mode]);
5865                }
5866        }
5867#endif
5868        if (rc != 0)
5869                fprintf(stderr,
5870                        "\tFailed to get bypass configuration for port = %d\n",
5871                       port_id);
5872}
5873
5874cmdline_parse_token_string_t cmd_showbypass_config_show =
5875        TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5876                        show, "show");
5877cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5878        TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5879                        bypass, "bypass");
5880cmdline_parse_token_string_t cmd_showbypass_config_config =
5881        TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5882                        config, "config");
5883cmdline_parse_token_num_t cmd_showbypass_config_port =
5884        TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5885                                port_id, RTE_UINT16);
5886
5887cmdline_parse_inst_t cmd_show_bypass_config = {
5888        .f = cmd_show_bypass_config_parsed,
5889        .help_str = "show bypass config <port_id>: "
5890                    "Show the NIC bypass config for port_id",
5891        .data = NULL,
5892        .tokens = {
5893                (void *)&cmd_showbypass_config_show,
5894                (void *)&cmd_showbypass_config_bypass,
5895                (void *)&cmd_showbypass_config_config,
5896                (void *)&cmd_showbypass_config_port,
5897                NULL,
5898        },
5899};
5900
5901#ifdef RTE_NET_BOND
5902/* *** SET BONDING MODE *** */
5903struct cmd_set_bonding_mode_result {
5904        cmdline_fixed_string_t set;
5905        cmdline_fixed_string_t bonding;
5906        cmdline_fixed_string_t mode;
5907        uint8_t value;
5908        portid_t port_id;
5909};
5910
5911static void cmd_set_bonding_mode_parsed(void *parsed_result,
5912                __rte_unused  struct cmdline *cl,
5913                __rte_unused void *data)
5914{
5915        struct cmd_set_bonding_mode_result *res = parsed_result;
5916        portid_t port_id = res->port_id;
5917
5918        /* Set the bonding mode for the relevant port. */
5919        if (0 != rte_eth_bond_mode_set(port_id, res->value))
5920                fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5921                        port_id);
5922}
5923
5924cmdline_parse_token_string_t cmd_setbonding_mode_set =
5925TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5926                set, "set");
5927cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5928TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5929                bonding, "bonding");
5930cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5931TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5932                mode, "mode");
5933cmdline_parse_token_num_t cmd_setbonding_mode_value =
5934TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5935                value, RTE_UINT8);
5936cmdline_parse_token_num_t cmd_setbonding_mode_port =
5937TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5938                port_id, RTE_UINT16);
5939
5940cmdline_parse_inst_t cmd_set_bonding_mode = {
5941                .f = cmd_set_bonding_mode_parsed,
5942                .help_str = "set bonding mode <mode_value> <port_id>: "
5943                        "Set the bonding mode for port_id",
5944                .data = NULL,
5945                .tokens = {
5946                                (void *) &cmd_setbonding_mode_set,
5947                                (void *) &cmd_setbonding_mode_bonding,
5948                                (void *) &cmd_setbonding_mode_mode,
5949                                (void *) &cmd_setbonding_mode_value,
5950                                (void *) &cmd_setbonding_mode_port,
5951                                NULL
5952                }
5953};
5954
5955/* *** SET BONDING SLOW_QUEUE SW/HW *** */
5956struct cmd_set_bonding_lacp_dedicated_queues_result {
5957        cmdline_fixed_string_t set;
5958        cmdline_fixed_string_t bonding;
5959        cmdline_fixed_string_t lacp;
5960        cmdline_fixed_string_t dedicated_queues;
5961        portid_t port_id;
5962        cmdline_fixed_string_t mode;
5963};
5964
5965static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5966                __rte_unused  struct cmdline *cl,
5967                __rte_unused void *data)
5968{
5969        struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5970        portid_t port_id = res->port_id;
5971        struct rte_port *port;
5972
5973        port = &ports[port_id];
5974
5975        /** Check if the port is not started **/
5976        if (port->port_status != RTE_PORT_STOPPED) {
5977                fprintf(stderr, "Please stop port %d first\n", port_id);
5978                return;
5979        }
5980
5981        if (!strcmp(res->mode, "enable")) {
5982                if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5983                        printf("Dedicate queues for LACP control packets"
5984                                        " enabled\n");
5985                else
5986                        printf("Enabling dedicate queues for LACP control "
5987                                        "packets on port %d failed\n", port_id);
5988        } else if (!strcmp(res->mode, "disable")) {
5989                if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5990                        printf("Dedicated queues for LACP control packets "
5991                                        "disabled\n");
5992                else
5993                        printf("Disabling dedicated queues for LACP control "
5994                                        "traffic on port %d failed\n", port_id);
5995        }
5996}
5997
5998cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5999TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6000                set, "set");
6001cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6002TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6003                bonding, "bonding");
6004cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6005TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6006                lacp, "lacp");
6007cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6008TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6009                dedicated_queues, "dedicated_queues");
6010cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6011TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6012                port_id, RTE_UINT16);
6013cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6014TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6015                mode, "enable#disable");
6016
6017cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6018                .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6019                .help_str = "set bonding lacp dedicated_queues <port_id> "
6020                        "enable|disable: "
6021                        "Enable/disable dedicated queues for LACP control traffic for port_id",
6022                .data = NULL,
6023                .tokens = {
6024                        (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6025                        (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6026                        (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6027                        (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6028                        (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6029                        (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6030                        NULL
6031                }
6032};
6033
6034/* *** SET BALANCE XMIT POLICY *** */
6035struct cmd_set_bonding_balance_xmit_policy_result {
6036        cmdline_fixed_string_t set;
6037        cmdline_fixed_string_t bonding;
6038        cmdline_fixed_string_t balance_xmit_policy;
6039        portid_t port_id;
6040        cmdline_fixed_string_t policy;
6041};
6042
6043static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6044                __rte_unused  struct cmdline *cl,
6045                __rte_unused void *data)
6046{
6047        struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6048        portid_t port_id = res->port_id;
6049        uint8_t policy;
6050
6051        if (!strcmp(res->policy, "l2")) {
6052                policy = BALANCE_XMIT_POLICY_LAYER2;
6053        } else if (!strcmp(res->policy, "l23")) {
6054                policy = BALANCE_XMIT_POLICY_LAYER23;
6055        } else if (!strcmp(res->policy, "l34")) {
6056                policy = BALANCE_XMIT_POLICY_LAYER34;
6057        } else {
6058                fprintf(stderr, "\t Invalid xmit policy selection");
6059                return;
6060        }
6061
6062        /* Set the bonding mode for the relevant port. */
6063        if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6064                fprintf(stderr,
6065                        "\t Failed to set bonding balance xmit policy for port = %d.\n",
6066                        port_id);
6067        }
6068}
6069
6070cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6071TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6072                set, "set");
6073cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6074TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6075                bonding, "bonding");
6076cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6077TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6078                balance_xmit_policy, "balance_xmit_policy");
6079cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6080TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6081                port_id, RTE_UINT16);
6082cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6083TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6084                policy, "l2#l23#l34");
6085
6086cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6087                .f = cmd_set_bonding_balance_xmit_policy_parsed,
6088                .help_str = "set bonding balance_xmit_policy <port_id> "
6089                        "l2|l23|l34: "
6090                        "Set the bonding balance_xmit_policy for port_id",
6091                .data = NULL,
6092                .tokens = {
6093                                (void *)&cmd_setbonding_balance_xmit_policy_set,
6094                                (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6095                                (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6096                                (void *)&cmd_setbonding_balance_xmit_policy_port,
6097                                (void *)&cmd_setbonding_balance_xmit_policy_policy,
6098                                NULL
6099                }
6100};
6101
6102/* *** SHOW NIC BONDING CONFIGURATION *** */
6103struct cmd_show_bonding_config_result {
6104        cmdline_fixed_string_t show;
6105        cmdline_fixed_string_t bonding;
6106        cmdline_fixed_string_t config;
6107        portid_t port_id;
6108};
6109
6110static void cmd_show_bonding_config_parsed(void *parsed_result,
6111                __rte_unused  struct cmdline *cl,
6112                __rte_unused void *data)
6113{
6114        struct cmd_show_bonding_config_result *res = parsed_result;
6115        int bonding_mode, agg_mode;
6116        portid_t slaves[RTE_MAX_ETHPORTS];
6117        int num_slaves, num_active_slaves;
6118        int primary_id;
6119        int i;
6120        portid_t port_id = res->port_id;
6121
6122        /* Display the bonding mode.*/
6123        bonding_mode = rte_eth_bond_mode_get(port_id);
6124        if (bonding_mode < 0) {
6125                fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6126                        port_id);
6127                return;
6128        } else
6129                printf("\tBonding mode: %d\n", bonding_mode);
6130
6131        if (bonding_mode == BONDING_MODE_BALANCE) {
6132                int balance_xmit_policy;
6133
6134                balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6135                if (balance_xmit_policy < 0) {
6136                        fprintf(stderr,
6137                                "\tFailed to get balance xmit policy for port = %d\n",
6138                                port_id);
6139                        return;
6140                } else {
6141                        printf("\tBalance Xmit Policy: ");
6142
6143                        switch (balance_xmit_policy) {
6144                        case BALANCE_XMIT_POLICY_LAYER2:
6145                                printf("BALANCE_XMIT_POLICY_LAYER2");
6146                                break;
6147                        case BALANCE_XMIT_POLICY_LAYER23:
6148                                printf("BALANCE_XMIT_POLICY_LAYER23");
6149                                break;
6150                        case BALANCE_XMIT_POLICY_LAYER34:
6151                                printf("BALANCE_XMIT_POLICY_LAYER34");
6152                                break;
6153                        }
6154                        printf("\n");
6155                }
6156        }
6157
6158        if (bonding_mode == BONDING_MODE_8023AD) {
6159                agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6160                printf("\tIEEE802.3AD Aggregator Mode: ");
6161                switch (agg_mode) {
6162                case AGG_BANDWIDTH:
6163                        printf("bandwidth");
6164                        break;
6165                case AGG_STABLE:
6166                        printf("stable");
6167                        break;
6168                case AGG_COUNT:
6169                        printf("count");
6170                        break;
6171                }
6172                printf("\n");
6173        }
6174
6175        num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6176
6177        if (num_slaves < 0) {
6178                fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6179                        port_id);
6180                return;
6181        }
6182        if (num_slaves > 0) {
6183                printf("\tSlaves (%d): [", num_slaves);
6184                for (i = 0; i < num_slaves - 1; i++)
6185                        printf("%d ", slaves[i]);
6186
6187                printf("%d]\n", slaves[num_slaves - 1]);
6188        } else {
6189                printf("\tSlaves: []\n");
6190
6191        }
6192
6193        num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6194                        RTE_MAX_ETHPORTS);
6195
6196        if (num_active_slaves < 0) {
6197                fprintf(stderr,
6198                        "\tFailed to get active slave list for port = %d\n",
6199                        port_id);
6200                return;
6201        }
6202        if (num_active_slaves > 0) {
6203                printf("\tActive Slaves (%d): [", num_active_slaves);
6204                for (i = 0; i < num_active_slaves - 1; i++)
6205                        printf("%d ", slaves[i]);
6206
6207                printf("%d]\n", slaves[num_active_slaves - 1]);
6208
6209        } else {
6210                printf("\tActive Slaves: []\n");
6211
6212        }
6213
6214        primary_id = rte_eth_bond_primary_get(port_id);
6215        if (primary_id < 0) {
6216                fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6217                        port_id);
6218                return;
6219        } else
6220                printf("\tPrimary: [%d]\n", primary_id);
6221
6222}
6223
6224cmdline_parse_token_string_t cmd_showbonding_config_show =
6225TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6226                show, "show");
6227cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6228TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6229                bonding, "bonding");
6230cmdline_parse_token_string_t cmd_showbonding_config_config =
6231TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6232                config, "config");
6233cmdline_parse_token_num_t cmd_showbonding_config_port =
6234TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6235                port_id, RTE_UINT16);
6236
6237cmdline_parse_inst_t cmd_show_bonding_config = {
6238                .f = cmd_show_bonding_config_parsed,
6239                .help_str = "show bonding config <port_id>: "
6240                        "Show the bonding config for port_id",
6241                .data = NULL,
6242                .tokens = {
6243                                (void *)&cmd_showbonding_config_show,
6244                                (void *)&cmd_showbonding_config_bonding,
6245                                (void *)&cmd_showbonding_config_config,
6246                                (void *)&cmd_showbonding_config_port,
6247                                NULL
6248                }
6249};
6250
6251/* *** SET BONDING PRIMARY *** */
6252struct cmd_set_bonding_primary_result {
6253        cmdline_fixed_string_t set;
6254        cmdline_fixed_string_t bonding;
6255        cmdline_fixed_string_t primary;
6256        portid_t slave_id;
6257        portid_t port_id;
6258};
6259
6260static void cmd_set_bonding_primary_parsed(void *parsed_result,
6261                __rte_unused  struct cmdline *cl,
6262                __rte_unused void *data)
6263{
6264        struct cmd_set_bonding_primary_result *res = parsed_result;
6265        portid_t master_port_id = res->port_id;
6266        portid_t slave_port_id = res->slave_id;
6267
6268        /* Set the primary slave for a bonded device. */
6269        if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6270                fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6271                        master_port_id);
6272                return;
6273        }
6274        init_port_config();
6275}
6276
6277cmdline_parse_token_string_t cmd_setbonding_primary_set =
6278TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6279                set, "set");
6280cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6281TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6282                bonding, "bonding");
6283cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6284TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6285                primary, "primary");
6286cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6287TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6288                slave_id, RTE_UINT16);
6289cmdline_parse_token_num_t cmd_setbonding_primary_port =
6290TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6291                port_id, RTE_UINT16);
6292
6293cmdline_parse_inst_t cmd_set_bonding_primary = {
6294                .f = cmd_set_bonding_primary_parsed,
6295                .help_str = "set bonding primary <slave_id> <port_id>: "
6296                        "Set the primary slave for port_id",
6297                .data = NULL,
6298                .tokens = {
6299                                (void *)&cmd_setbonding_primary_set,
6300                                (void *)&cmd_setbonding_primary_bonding,
6301                                (void *)&cmd_setbonding_primary_primary,
6302                                (void *)&cmd_setbonding_primary_slave,
6303                                (void *)&cmd_setbonding_primary_port,
6304                                NULL
6305                }
6306};
6307
6308/* *** ADD SLAVE *** */
6309struct cmd_add_bonding_slave_result {
6310        cmdline_fixed_string_t add;
6311        cmdline_fixed_string_t bonding;
6312        cmdline_fixed_string_t slave;
6313        portid_t slave_id;
6314        portid_t port_id;
6315};
6316
6317static void cmd_add_bonding_slave_parsed(void *parsed_result,
6318                __rte_unused  struct cmdline *cl,
6319                __rte_unused void *data)
6320{
6321        struct cmd_add_bonding_slave_result *res = parsed_result;
6322        portid_t master_port_id = res->port_id;
6323        portid_t slave_port_id = res->slave_id;
6324
6325        /* add the slave for a bonded device. */
6326        if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6327                fprintf(stderr,
6328                        "\t Failed to add slave %d to master port = %d.\n",
6329                        slave_port_id, master_port_id);
6330                return;
6331        }
6332        init_port_config();
6333        set_port_slave_flag(slave_port_id);
6334}
6335
6336cmdline_parse_token_string_t cmd_addbonding_slave_add =
6337TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6338                add, "add");
6339cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6340TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6341                bonding, "bonding");
6342cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6343TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6344                slave, "slave");
6345cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6346TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6347                slave_id, RTE_UINT16);
6348cmdline_parse_token_num_t cmd_addbonding_slave_port =
6349TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6350                port_id, RTE_UINT16);
6351
6352cmdline_parse_inst_t cmd_add_bonding_slave = {
6353                .f = cmd_add_bonding_slave_parsed,
6354                .help_str = "add bonding slave <slave_id> <port_id>: "
6355                        "Add a slave device to a bonded device",
6356                .data = NULL,
6357                .tokens = {
6358                                (void *)&cmd_addbonding_slave_add,
6359                                (void *)&cmd_addbonding_slave_bonding,
6360                                (void *)&cmd_addbonding_slave_slave,
6361                                (void *)&cmd_addbonding_slave_slaveid,
6362                                (void *)&cmd_addbonding_slave_port,
6363                                NULL
6364                }
6365};
6366
6367/* *** REMOVE SLAVE *** */
6368struct cmd_remove_bonding_slave_result {
6369        cmdline_fixed_string_t remove;
6370        cmdline_fixed_string_t bonding;
6371        cmdline_fixed_string_t slave;
6372        portid_t slave_id;
6373        portid_t port_id;
6374};
6375
6376static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6377                __rte_unused  struct cmdline *cl,
6378                __rte_unused void *data)
6379{
6380        struct cmd_remove_bonding_slave_result *res = parsed_result;
6381        portid_t master_port_id = res->port_id;
6382        portid_t slave_port_id = res->slave_id;
6383
6384        /* remove the slave from a bonded device. */
6385        if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6386                fprintf(stderr,
6387                        "\t Failed to remove slave %d from master port = %d.\n",
6388                        slave_port_id, master_port_id);
6389                return;
6390        }
6391        init_port_config();
6392        clear_port_slave_flag(slave_port_id);
6393}
6394
6395cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6396                TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6397                                remove, "remove");
6398cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6399                TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6400                                bonding, "bonding");
6401cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6402                TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6403                                slave, "slave");
6404cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6405                TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6406                                slave_id, RTE_UINT16);
6407cmdline_parse_token_num_t cmd_removebonding_slave_port =
6408                TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6409                                port_id, RTE_UINT16);
6410
6411cmdline_parse_inst_t cmd_remove_bonding_slave = {
6412                .f = cmd_remove_bonding_slave_parsed,
6413                .help_str = "remove bonding slave <slave_id> <port_id>: "
6414                        "Remove a slave device from a bonded device",
6415                .data = NULL,
6416                .tokens = {
6417                                (void *)&cmd_removebonding_slave_remove,
6418                                (void *)&cmd_removebonding_slave_bonding,
6419                                (void *)&cmd_removebonding_slave_slave,
6420                                (void *)&cmd_removebonding_slave_slaveid,
6421                                (void *)&cmd_removebonding_slave_port,
6422                                NULL
6423                }
6424};
6425
6426/* *** CREATE BONDED DEVICE *** */
6427struct cmd_create_bonded_device_result {
6428        cmdline_fixed_string_t create;
6429        cmdline_fixed_string_t bonded;
6430        cmdline_fixed_string_t device;
6431        uint8_t mode;
6432        uint8_t socket;
6433};
6434
6435static int bond_dev_num = 0;
6436
6437static void cmd_create_bonded_device_parsed(void *parsed_result,
6438                __rte_unused  struct cmdline *cl,
6439                __rte_unused void *data)
6440{
6441        struct cmd_create_bonded_device_result *res = parsed_result;
6442        char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6443        int port_id;
6444        int ret;
6445
6446        if (test_done == 0) {
6447                fprintf(stderr, "Please stop forwarding first\n");
6448                return;
6449        }
6450
6451        snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6452                        bond_dev_num++);
6453
6454        /* Create a new bonded device. */
6455        port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6456        if (port_id < 0) {
6457                fprintf(stderr, "\t Failed to create bonded device.\n");
6458                return;
6459        } else {
6460                printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6461                                port_id);
6462
6463                /* Update number of ports */
6464                nb_ports = rte_eth_dev_count_avail();
6465                reconfig(port_id, res->socket);
6466                ret = rte_eth_promiscuous_enable(port_id);
6467                if (ret != 0)
6468                        fprintf(stderr,
6469                                "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6470                                port_id, rte_strerror(-ret));
6471
6472                ports[port_id].need_setup = 0;
6473                ports[port_id].port_status = RTE_PORT_STOPPED;
6474        }
6475
6476}
6477
6478cmdline_parse_token_string_t cmd_createbonded_device_create =
6479                TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6480                                create, "create");
6481cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6482                TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6483                                bonded, "bonded");
6484cmdline_parse_token_string_t cmd_createbonded_device_device =
6485                TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6486                                device, "device");
6487cmdline_parse_token_num_t cmd_createbonded_device_mode =
6488                TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6489                                mode, RTE_UINT8);
6490cmdline_parse_token_num_t cmd_createbonded_device_socket =
6491                TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6492                                socket, RTE_UINT8);
6493
6494cmdline_parse_inst_t cmd_create_bonded_device = {
6495                .f = cmd_create_bonded_device_parsed,
6496                .help_str = "create bonded device <mode> <socket>: "
6497                        "Create a new bonded device with specific bonding mode and socket",
6498                .data = NULL,
6499                .tokens = {
6500                                (void *)&cmd_createbonded_device_create,
6501                                (void *)&cmd_createbonded_device_bonded,
6502                                (void *)&cmd_createbonded_device_device,
6503                                (void *)&cmd_createbonded_device_mode,
6504                                (void *)&cmd_createbonded_device_socket,
6505                                NULL
6506                }
6507};
6508
6509/* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6510struct cmd_set_bond_mac_addr_result {
6511        cmdline_fixed_string_t set;
6512        cmdline_fixed_string_t bonding;
6513        cmdline_fixed_string_t mac_addr;
6514        uint16_t port_num;
6515        struct rte_ether_addr address;
6516};
6517
6518static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6519                __rte_unused  struct cmdline *cl,
6520                __rte_unused void *data)
6521{
6522        struct cmd_set_bond_mac_addr_result *res = parsed_result;
6523        int ret;
6524
6525        if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6526                return;
6527
6528        ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6529
6530        /* check the return value and print it if is < 0 */
6531        if (ret < 0)
6532                fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6533                        strerror(-ret));
6534}
6535
6536cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6537                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6538cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6539                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6540                                "bonding");
6541cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6542                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6543                                "mac_addr");
6544cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6545                TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6546                                port_num, RTE_UINT16);
6547cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6548                TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6549
6550cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6551                .f = cmd_set_bond_mac_addr_parsed,
6552                .data = (void *) 0,
6553                .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6554                .tokens = {
6555                                (void *)&cmd_set_bond_mac_addr_set,
6556                                (void *)&cmd_set_bond_mac_addr_bonding,
6557                                (void *)&cmd_set_bond_mac_addr_mac,
6558                                (void *)&cmd_set_bond_mac_addr_portnum,
6559                                (void *)&cmd_set_bond_mac_addr_addr,
6560                                NULL
6561                }
6562};
6563
6564
6565/* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6566struct cmd_set_bond_mon_period_result {
6567        cmdline_fixed_string_t set;
6568        cmdline_fixed_string_t bonding;
6569        cmdline_fixed_string_t mon_period;
6570        uint16_t port_num;
6571        uint32_t period_ms;
6572};
6573
6574static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6575                __rte_unused  struct cmdline *cl,
6576                __rte_unused void *data)
6577{
6578        struct cmd_set_bond_mon_period_result *res = parsed_result;
6579        int ret;
6580
6581        ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6582
6583        /* check the return value and print it if is < 0 */
6584        if (ret < 0)
6585                fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6586                        strerror(-ret));
6587}
6588
6589cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6590                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6591                                set, "set");
6592cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6593                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6594                                bonding, "bonding");
6595cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6596                TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6597                                mon_period,     "mon_period");
6598cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6599                TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6600                                port_num, RTE_UINT16);
6601cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6602                TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6603                                period_ms, RTE_UINT32);
6604
6605cmdline_parse_inst_t cmd_set_bond_mon_period = {
6606                .f = cmd_set_bond_mon_period_parsed,
6607                .data = (void *) 0,
6608                .help_str = "set bonding mon_period <port_id> <period_ms>",
6609                .tokens = {
6610                                (void *)&cmd_set_bond_mon_period_set,
6611                                (void *)&cmd_set_bond_mon_period_bonding,
6612                                (void *)&cmd_set_bond_mon_period_mon_period,
6613                                (void *)&cmd_set_bond_mon_period_portnum,
6614                                (void *)&cmd_set_bond_mon_period_period_ms,
6615                                NULL
6616                }
6617};
6618
6619
6620
6621struct cmd_set_bonding_agg_mode_policy_result {
6622        cmdline_fixed_string_t set;
6623        cmdline_fixed_string_t bonding;
6624        cmdline_fixed_string_t agg_mode;
6625        uint16_t port_num;
6626        cmdline_fixed_string_t policy;
6627};
6628
6629
6630static void
6631cmd_set_bonding_agg_mode(void *parsed_result,
6632                __rte_unused struct cmdline *cl,
6633                __rte_unused void *data)
6634{
6635        struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6636        uint8_t policy = AGG_BANDWIDTH;
6637
6638        if (!strcmp(res->policy, "bandwidth"))
6639                policy = AGG_BANDWIDTH;
6640        else if (!strcmp(res->policy, "stable"))
6641                policy = AGG_STABLE;
6642        else if (!strcmp(res->policy, "count"))
6643                policy = AGG_COUNT;
6644
6645        rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6646}
6647
6648
6649cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6650        TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6651                                set, "set");
6652cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6653        TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6654                                bonding, "bonding");
6655
6656cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6657        TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6658                                agg_mode, "agg_mode");
6659
6660cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6661        TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6662                                port_num, RTE_UINT16);
6663
6664cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6665        TOKEN_STRING_INITIALIZER(
6666                        struct cmd_set_bonding_balance_xmit_policy_result,
6667                policy, "stable#bandwidth#count");
6668
6669cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6670        .f = cmd_set_bonding_agg_mode,
6671        .data = (void *) 0,
6672        .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6673        .tokens = {
6674                        (void *)&cmd_set_bonding_agg_mode_set,
6675                        (void *)&cmd_set_bonding_agg_mode_bonding,
6676                        (void *)&cmd_set_bonding_agg_mode_agg_mode,
6677                        (void *)&cmd_set_bonding_agg_mode_portnum,
6678                        (void *)&cmd_set_bonding_agg_mode_policy_string,
6679                        NULL
6680                }
6681};
6682
6683
6684#endif /* RTE_NET_BOND */
6685
6686/* *** SET FORWARDING MODE *** */
6687struct cmd_set_fwd_mode_result {
6688        cmdline_fixed_string_t set;
6689        cmdline_fixed_string_t fwd;
6690        cmdline_fixed_string_t mode;
6691};
6692
6693static void cmd_set_fwd_mode_parsed(void *parsed_result,
6694                                    __rte_unused struct cmdline *cl,
6695                                    __rte_unused void *data)
6696{
6697        struct cmd_set_fwd_mode_result *res = parsed_result;
6698
6699        retry_enabled = 0;
6700        set_pkt_forwarding_mode(res->mode);
6701}
6702
6703cmdline_parse_token_string_t cmd_setfwd_set =
6704        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6705cmdline_parse_token_string_t cmd_setfwd_fwd =
6706        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6707cmdline_parse_token_string_t cmd_setfwd_mode =
6708        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6709                "" /* defined at init */);
6710
6711cmdline_parse_inst_t cmd_set_fwd_mode = {
6712        .f = cmd_set_fwd_mode_parsed,
6713        .data = NULL,
6714        .help_str = NULL, /* defined at init */
6715        .tokens = {
6716                (void *)&cmd_setfwd_set,
6717                (void *)&cmd_setfwd_fwd,
6718                (void *)&cmd_setfwd_mode,
6719                NULL,
6720        },
6721};
6722
6723static void cmd_set_fwd_mode_init(void)
6724{
6725        char *modes, *c;
6726        static char token[128];
6727        static char help[256];
6728        cmdline_parse_token_string_t *token_struct;
6729
6730        modes = list_pkt_forwarding_modes();
6731        snprintf(help, sizeof(help), "set fwd %s: "
6732                "Set packet forwarding mode", modes);
6733        cmd_set_fwd_mode.help_str = help;
6734
6735        /* string token separator is # */
6736        for (c = token; *modes != '\0'; modes++)
6737                if (*modes == '|')
6738                        *c++ = '#';
6739                else
6740                        *c++ = *modes;
6741        token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6742        token_struct->string_data.str = token;
6743}
6744
6745/* *** SET RETRY FORWARDING MODE *** */
6746struct cmd_set_fwd_retry_mode_result {
6747        cmdline_fixed_string_t set;
6748        cmdline_fixed_string_t fwd;
6749        cmdline_fixed_string_t mode;
6750        cmdline_fixed_string_t retry;
6751};
6752
6753static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6754                            __rte_unused struct cmdline *cl,
6755                            __rte_unused void *data)
6756{
6757        struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6758
6759        retry_enabled = 1;
6760        set_pkt_forwarding_mode(res->mode);
6761}
6762
6763cmdline_parse_token_string_t cmd_setfwd_retry_set =
6764        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6765                        set, "set");
6766cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6767        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6768                        fwd, "fwd");
6769cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6770        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6771                        mode,
6772                "" /* defined at init */);
6773cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6774        TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6775                        retry, "retry");
6776
6777cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6778        .f = cmd_set_fwd_retry_mode_parsed,
6779        .data = NULL,
6780        .help_str = NULL, /* defined at init */
6781        .tokens = {
6782                (void *)&cmd_setfwd_retry_set,
6783                (void *)&cmd_setfwd_retry_fwd,
6784                (void *)&cmd_setfwd_retry_mode,
6785                (void *)&cmd_setfwd_retry_retry,
6786                NULL,
6787        },
6788};
6789
6790static void cmd_set_fwd_retry_mode_init(void)
6791{
6792        char *modes, *c;
6793        static char token[128];
6794        static char help[256];
6795        cmdline_parse_token_string_t *token_struct;
6796
6797        modes = list_pkt_forwarding_retry_modes();
6798        snprintf(help, sizeof(help), "set fwd %s retry: "
6799                "Set packet forwarding mode with retry", modes);
6800        cmd_set_fwd_retry_mode.help_str = help;
6801
6802        /* string token separator is # */
6803        for (c = token; *modes != '\0'; modes++)
6804                if (*modes == '|')
6805                        *c++ = '#';
6806                else
6807                        *c++ = *modes;
6808        token_struct = (cmdline_parse_token_string_t *)
6809                cmd_set_fwd_retry_mode.tokens[2];
6810        token_struct->string_data.str = token;
6811}
6812
6813/* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6814struct cmd_set_burst_tx_retry_result {
6815        cmdline_fixed_string_t set;
6816        cmdline_fixed_string_t burst;
6817        cmdline_fixed_string_t tx;
6818        cmdline_fixed_string_t delay;
6819        uint32_t time;
6820        cmdline_fixed_string_t retry;
6821        uint32_t retry_num;
6822};
6823
6824static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6825                                        __rte_unused struct cmdline *cl,
6826                                        __rte_unused void *data)
6827{
6828        struct cmd_set_burst_tx_retry_result *res = parsed_result;
6829
6830        if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6831                && !strcmp(res->tx, "tx")) {
6832                if (!strcmp(res->delay, "delay"))
6833                        burst_tx_delay_time = res->time;
6834                if (!strcmp(res->retry, "retry"))
6835                        burst_tx_retry_num = res->retry_num;
6836        }
6837
6838}
6839
6840cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6841        TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6842cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6843        TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6844                                 "burst");
6845cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6846        TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6847cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6848        TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6849cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6850        TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6851                                 RTE_UINT32);
6852cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6853        TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6854cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6855        TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6856                                 RTE_UINT32);
6857
6858cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6859        .f = cmd_set_burst_tx_retry_parsed,
6860        .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6861        .tokens = {
6862                (void *)&cmd_set_burst_tx_retry_set,
6863                (void *)&cmd_set_burst_tx_retry_burst,
6864                (void *)&cmd_set_burst_tx_retry_tx,
6865                (void *)&cmd_set_burst_tx_retry_delay,
6866                (void *)&cmd_set_burst_tx_retry_time,
6867                (void *)&cmd_set_burst_tx_retry_retry,
6868                (void *)&cmd_set_burst_tx_retry_retry_num,
6869                NULL,
6870        },
6871};
6872
6873/* *** SET PROMISC MODE *** */
6874struct cmd_set_promisc_mode_result {
6875        cmdline_fixed_string_t set;
6876        cmdline_fixed_string_t promisc;
6877        cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6878        uint16_t port_num;               /* valid if "allports" argument == 0 */
6879        cmdline_fixed_string_t mode;
6880};
6881
6882static void cmd_set_promisc_mode_parsed(void *parsed_result,
6883                                        __rte_unused struct cmdline *cl,
6884                                        void *allports)
6885{
6886        struct cmd_set_promisc_mode_result *res = parsed_result;
6887        int enable;
6888        portid_t i;
6889
6890        if (!strcmp(res->mode, "on"))
6891                enable = 1;
6892        else
6893                enable = 0;
6894
6895        /* all ports */
6896        if (allports) {
6897                RTE_ETH_FOREACH_DEV(i)
6898                        eth_set_promisc_mode(i, enable);
6899        } else {
6900                eth_set_promisc_mode(res->port_num, enable);
6901        }
6902}
6903
6904cmdline_parse_token_string_t cmd_setpromisc_set =
6905        TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6906cmdline_parse_token_string_t cmd_setpromisc_promisc =
6907        TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6908                                 "promisc");
6909cmdline_parse_token_string_t cmd_setpromisc_portall =
6910        TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6911                                 "all");
6912cmdline_parse_token_num_t cmd_setpromisc_portnum =
6913        TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6914                              RTE_UINT16);
6915cmdline_parse_token_string_t cmd_setpromisc_mode =
6916        TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6917                                 "on#off");
6918
6919cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6920        .f = cmd_set_promisc_mode_parsed,
6921        .data = (void *)1,
6922        .help_str = "set promisc all on|off: Set promisc mode for all ports",
6923        .tokens = {
6924                (void *)&cmd_setpromisc_set,
6925                (void *)&cmd_setpromisc_promisc,
6926                (void *)&cmd_setpromisc_portall,
6927                (void *)&cmd_setpromisc_mode,
6928                NULL,
6929        },
6930};
6931
6932cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6933        .f = cmd_set_promisc_mode_parsed,
6934        .data = (void *)0,
6935        .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6936        .tokens = {
6937                (void *)&cmd_setpromisc_set,
6938                (void *)&cmd_setpromisc_promisc,
6939                (void *)&cmd_setpromisc_portnum,
6940                (void *)&cmd_setpromisc_mode,
6941                NULL,
6942        },
6943};
6944
6945/* *** SET ALLMULTI MODE *** */
6946struct cmd_set_allmulti_mode_result {
6947        cmdline_fixed_string_t set;
6948        cmdline_fixed_string_t allmulti;
6949        cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6950        uint16_t port_num;               /* valid if "allports" argument == 0 */
6951        cmdline_fixed_string_t mode;
6952};
6953
6954static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6955                                        __rte_unused struct cmdline *cl,
6956                                        void *allports)
6957{
6958        struct cmd_set_allmulti_mode_result *res = parsed_result;
6959        int enable;
6960        portid_t i;
6961
6962        if (!strcmp(res->mode, "on"))
6963                enable = 1;
6964        else
6965                enable = 0;
6966
6967        /* all ports */
6968        if (allports) {
6969                RTE_ETH_FOREACH_DEV(i) {
6970                        eth_set_allmulticast_mode(i, enable);
6971                }
6972        }
6973        else {
6974                eth_set_allmulticast_mode(res->port_num, enable);
6975        }
6976}
6977
6978cmdline_parse_token_string_t cmd_setallmulti_set =
6979        TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6980cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6981        TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6982                                 "allmulti");
6983cmdline_parse_token_string_t cmd_setallmulti_portall =
6984        TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6985                                 "all");
6986cmdline_parse_token_num_t cmd_setallmulti_portnum =
6987        TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6988                              RTE_UINT16);
6989cmdline_parse_token_string_t cmd_setallmulti_mode =
6990        TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6991                                 "on#off");
6992
6993cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6994        .f = cmd_set_allmulti_mode_parsed,
6995        .data = (void *)1,
6996        .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6997        .tokens = {
6998                (void *)&cmd_setallmulti_set,
6999                (void *)&cmd_setallmulti_allmulti,
7000                (void *)&cmd_setallmulti_portall,
7001                (void *)&cmd_setallmulti_mode,
7002                NULL,
7003        },
7004};
7005
7006cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7007        .f = cmd_set_allmulti_mode_parsed,
7008        .data = (void *)0,
7009        .help_str = "set allmulti <port_id> on|off: "
7010                "Set allmulti mode on port_id",
7011        .tokens = {
7012                (void *)&cmd_setallmulti_set,
7013                (void *)&cmd_setallmulti_allmulti,
7014                (void *)&cmd_setallmulti_portnum,
7015                (void *)&cmd_setallmulti_mode,
7016                NULL,
7017        },
7018};
7019
7020/* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7021struct cmd_link_flow_ctrl_show {
7022        cmdline_fixed_string_t show;
7023        cmdline_fixed_string_t port;
7024        portid_t port_id;
7025        cmdline_fixed_string_t flow_ctrl;
7026};
7027
7028cmdline_parse_token_string_t cmd_lfc_show_show =
7029        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7030                                show, "show");
7031cmdline_parse_token_string_t cmd_lfc_show_port =
7032        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7033                                port, "port");
7034cmdline_parse_token_num_t cmd_lfc_show_portid =
7035        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7036                                port_id, RTE_UINT16);
7037cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7038        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7039                                flow_ctrl, "flow_ctrl");
7040
7041static void
7042cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7043                              __rte_unused struct cmdline *cl,
7044                              __rte_unused void *data)
7045{
7046        struct cmd_link_flow_ctrl_show *res = parsed_result;
7047        static const char *info_border = "*********************";
7048        struct rte_eth_fc_conf fc_conf;
7049        bool rx_fc_en = false;
7050        bool tx_fc_en = false;
7051        int ret;
7052
7053        ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7054        if (ret != 0) {
7055                fprintf(stderr,
7056                        "Failed to get current flow ctrl information: err = %d\n",
7057                        ret);
7058                return;
7059        }
7060
7061        if (fc_conf.mode == RTE_FC_RX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7062                rx_fc_en = true;
7063        if (fc_conf.mode == RTE_FC_TX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7064                tx_fc_en = true;
7065
7066        printf("\n%s Flow control infos for port %-2d %s\n",
7067                info_border, res->port_id, info_border);
7068        printf("FC mode:\n");
7069        printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7070        printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7071        printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7072        printf("Pause time: 0x%x\n", fc_conf.pause_time);
7073        printf("High waterline: 0x%x\n", fc_conf.high_water);
7074        printf("Low waterline: 0x%x\n", fc_conf.low_water);
7075        printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7076        printf("Forward MAC control frames: %s\n",
7077                fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7078        printf("\n%s**************   End  ***********%s\n",
7079                info_border, info_border);
7080}
7081
7082cmdline_parse_inst_t cmd_link_flow_control_show = {
7083        .f = cmd_link_flow_ctrl_show_parsed,
7084        .data = NULL,
7085        .help_str = "show port <port_id> flow_ctrl",
7086        .tokens = {
7087                (void *)&cmd_lfc_show_show,
7088                (void *)&cmd_lfc_show_port,
7089                (void *)&cmd_lfc_show_portid,
7090                (void *)&cmd_lfc_show_flow_ctrl,
7091                NULL,
7092        },
7093};
7094
7095/* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7096struct cmd_link_flow_ctrl_set_result {
7097        cmdline_fixed_string_t set;
7098        cmdline_fixed_string_t flow_ctrl;
7099        cmdline_fixed_string_t rx;
7100        cmdline_fixed_string_t rx_lfc_mode;
7101        cmdline_fixed_string_t tx;
7102        cmdline_fixed_string_t tx_lfc_mode;
7103        cmdline_fixed_string_t mac_ctrl_frame_fwd;
7104        cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7105        cmdline_fixed_string_t autoneg_str;
7106        cmdline_fixed_string_t autoneg;
7107        cmdline_fixed_string_t hw_str;
7108        uint32_t high_water;
7109        cmdline_fixed_string_t lw_str;
7110        uint32_t low_water;
7111        cmdline_fixed_string_t pt_str;
7112        uint16_t pause_time;
7113        cmdline_fixed_string_t xon_str;
7114        uint16_t send_xon;
7115        portid_t port_id;
7116};
7117
7118cmdline_parse_token_string_t cmd_lfc_set_set =
7119        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7120                                set, "set");
7121cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7122        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7123                                flow_ctrl, "flow_ctrl");
7124cmdline_parse_token_string_t cmd_lfc_set_rx =
7125        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7126                                rx, "rx");
7127cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7128        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7129                                rx_lfc_mode, "on#off");
7130cmdline_parse_token_string_t cmd_lfc_set_tx =
7131        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7132                                tx, "tx");
7133cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7134        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7135                                tx_lfc_mode, "on#off");
7136cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7137        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7138                                hw_str, "high_water");
7139cmdline_parse_token_num_t cmd_lfc_set_high_water =
7140        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7141                                high_water, RTE_UINT32);
7142cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7143        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7144                                lw_str, "low_water");
7145cmdline_parse_token_num_t cmd_lfc_set_low_water =
7146        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7147                                low_water, RTE_UINT32);
7148cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7149        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7150                                pt_str, "pause_time");
7151cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7152        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7153                                pause_time, RTE_UINT16);
7154cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7155        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7156                                xon_str, "send_xon");
7157cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7158        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7159                                send_xon, RTE_UINT16);
7160cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7161        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7162                                mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7163cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7164        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7165                                mac_ctrl_frame_fwd_mode, "on#off");
7166cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7167        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7168                                autoneg_str, "autoneg");
7169cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7170        TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7171                                autoneg, "on#off");
7172cmdline_parse_token_num_t cmd_lfc_set_portid =
7173        TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7174                                port_id, RTE_UINT16);
7175
7176/* forward declaration */
7177static void
7178cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7179                              void *data);
7180
7181cmdline_parse_inst_t cmd_link_flow_control_set = {
7182        .f = cmd_link_flow_ctrl_set_parsed,
7183        .data = NULL,
7184        .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7185                "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7186                "autoneg on|off <port_id>: Configure the Ethernet flow control",
7187        .tokens = {
7188                (void *)&cmd_lfc_set_set,
7189                (void *)&cmd_lfc_set_flow_ctrl,
7190                (void *)&cmd_lfc_set_rx,
7191                (void *)&cmd_lfc_set_rx_mode,
7192                (void *)&cmd_lfc_set_tx,
7193                (void *)&cmd_lfc_set_tx_mode,
7194                (void *)&cmd_lfc_set_high_water,
7195                (void *)&cmd_lfc_set_low_water,
7196                (void *)&cmd_lfc_set_pause_time,
7197                (void *)&cmd_lfc_set_send_xon,
7198                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7199                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7200                (void *)&cmd_lfc_set_autoneg_str,
7201                (void *)&cmd_lfc_set_autoneg,
7202                (void *)&cmd_lfc_set_portid,
7203                NULL,
7204        },
7205};
7206
7207cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7208        .f = cmd_link_flow_ctrl_set_parsed,
7209        .data = (void *)&cmd_link_flow_control_set_rx,
7210        .help_str = "set flow_ctrl rx on|off <port_id>: "
7211                "Change rx flow control parameter",
7212        .tokens = {
7213                (void *)&cmd_lfc_set_set,
7214                (void *)&cmd_lfc_set_flow_ctrl,
7215                (void *)&cmd_lfc_set_rx,
7216                (void *)&cmd_lfc_set_rx_mode,
7217                (void *)&cmd_lfc_set_portid,
7218                NULL,
7219        },
7220};
7221
7222cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7223        .f = cmd_link_flow_ctrl_set_parsed,
7224        .data = (void *)&cmd_link_flow_control_set_tx,
7225        .help_str = "set flow_ctrl tx on|off <port_id>: "
7226                "Change tx flow control parameter",
7227        .tokens = {
7228                (void *)&cmd_lfc_set_set,
7229                (void *)&cmd_lfc_set_flow_ctrl,
7230                (void *)&cmd_lfc_set_tx,
7231                (void *)&cmd_lfc_set_tx_mode,
7232                (void *)&cmd_lfc_set_portid,
7233                NULL,
7234        },
7235};
7236
7237cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7238        .f = cmd_link_flow_ctrl_set_parsed,
7239        .data = (void *)&cmd_link_flow_control_set_hw,
7240        .help_str = "set flow_ctrl high_water <value> <port_id>: "
7241                "Change high water flow control parameter",
7242        .tokens = {
7243                (void *)&cmd_lfc_set_set,
7244                (void *)&cmd_lfc_set_flow_ctrl,
7245                (void *)&cmd_lfc_set_high_water_str,
7246                (void *)&cmd_lfc_set_high_water,
7247                (void *)&cmd_lfc_set_portid,
7248                NULL,
7249        },
7250};
7251
7252cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7253        .f = cmd_link_flow_ctrl_set_parsed,
7254        .data = (void *)&cmd_link_flow_control_set_lw,
7255        .help_str = "set flow_ctrl low_water <value> <port_id>: "
7256                "Change low water flow control parameter",
7257        .tokens = {
7258                (void *)&cmd_lfc_set_set,
7259                (void *)&cmd_lfc_set_flow_ctrl,
7260                (void *)&cmd_lfc_set_low_water_str,
7261                (void *)&cmd_lfc_set_low_water,
7262                (void *)&cmd_lfc_set_portid,
7263                NULL,
7264        },
7265};
7266
7267cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7268        .f = cmd_link_flow_ctrl_set_parsed,
7269        .data = (void *)&cmd_link_flow_control_set_pt,
7270        .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7271                "Change pause time flow control parameter",
7272        .tokens = {
7273                (void *)&cmd_lfc_set_set,
7274                (void *)&cmd_lfc_set_flow_ctrl,
7275                (void *)&cmd_lfc_set_pause_time_str,
7276                (void *)&cmd_lfc_set_pause_time,
7277                (void *)&cmd_lfc_set_portid,
7278                NULL,
7279        },
7280};
7281
7282cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7283        .f = cmd_link_flow_ctrl_set_parsed,
7284        .data = (void *)&cmd_link_flow_control_set_xon,
7285        .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7286                "Change send_xon flow control parameter",
7287        .tokens = {
7288                (void *)&cmd_lfc_set_set,
7289                (void *)&cmd_lfc_set_flow_ctrl,
7290                (void *)&cmd_lfc_set_send_xon_str,
7291                (void *)&cmd_lfc_set_send_xon,
7292                (void *)&cmd_lfc_set_portid,
7293                NULL,
7294        },
7295};
7296
7297cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7298        .f = cmd_link_flow_ctrl_set_parsed,
7299        .data = (void *)&cmd_link_flow_control_set_macfwd,
7300        .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7301                "Change mac ctrl fwd flow control parameter",
7302        .tokens = {
7303                (void *)&cmd_lfc_set_set,
7304                (void *)&cmd_lfc_set_flow_ctrl,
7305                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7306                (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7307                (void *)&cmd_lfc_set_portid,
7308                NULL,
7309        },
7310};
7311
7312cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7313        .f = cmd_link_flow_ctrl_set_parsed,
7314        .data = (void *)&cmd_link_flow_control_set_autoneg,
7315        .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7316                "Change autoneg flow control parameter",
7317        .tokens = {
7318                (void *)&cmd_lfc_set_set,
7319                (void *)&cmd_lfc_set_flow_ctrl,
7320                (void *)&cmd_lfc_set_autoneg_str,
7321                (void *)&cmd_lfc_set_autoneg,
7322                (void *)&cmd_lfc_set_portid,
7323                NULL,
7324        },
7325};
7326
7327static void
7328cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7329                              __rte_unused struct cmdline *cl,
7330                              void *data)
7331{
7332        struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7333        cmdline_parse_inst_t *cmd = data;
7334        struct rte_eth_fc_conf fc_conf;
7335        int rx_fc_en = 0;
7336        int tx_fc_en = 0;
7337        int ret;
7338
7339        /*
7340         * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7341         * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7342         * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7343         * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7344         */
7345        static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7346                        {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7347        };
7348
7349        /* Partial command line, retrieve current configuration */
7350        if (cmd) {
7351                ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7352                if (ret != 0) {
7353                        fprintf(stderr,
7354                                "cannot get current flow ctrl parameters, return code = %d\n",
7355                                ret);
7356                        return;
7357                }
7358
7359                if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7360                    (fc_conf.mode == RTE_FC_FULL))
7361                        rx_fc_en = 1;
7362                if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7363                    (fc_conf.mode == RTE_FC_FULL))
7364                        tx_fc_en = 1;
7365        }
7366
7367        if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7368                rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7369
7370        if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7371                tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7372
7373        fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7374
7375        if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7376                fc_conf.high_water = res->high_water;
7377
7378        if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7379                fc_conf.low_water = res->low_water;
7380
7381        if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7382                fc_conf.pause_time = res->pause_time;
7383
7384        if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7385                fc_conf.send_xon = res->send_xon;
7386
7387        if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7388                if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7389                        fc_conf.mac_ctrl_frame_fwd = 1;
7390                else
7391                        fc_conf.mac_ctrl_frame_fwd = 0;
7392        }
7393
7394        if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7395                fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7396
7397        ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7398        if (ret != 0)
7399                fprintf(stderr,
7400                        "bad flow control parameter, return code = %d\n",
7401                        ret);
7402}
7403
7404/* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7405struct cmd_priority_flow_ctrl_set_result {
7406        cmdline_fixed_string_t set;
7407        cmdline_fixed_string_t pfc_ctrl;
7408        cmdline_fixed_string_t rx;
7409        cmdline_fixed_string_t rx_pfc_mode;
7410        cmdline_fixed_string_t tx;
7411        cmdline_fixed_string_t tx_pfc_mode;
7412        uint32_t high_water;
7413        uint32_t low_water;
7414        uint16_t pause_time;
7415        uint8_t  priority;
7416        portid_t port_id;
7417};
7418
7419static void
7420cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7421                       __rte_unused struct cmdline *cl,
7422                       __rte_unused void *data)
7423{
7424        struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7425        struct rte_eth_pfc_conf pfc_conf;
7426        int rx_fc_enable, tx_fc_enable;
7427        int ret;
7428
7429        /*
7430         * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7431         * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7432         * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7433         * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7434         */
7435        static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7436                {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7437        };
7438
7439        memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7440        rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7441        tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7442        pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7443        pfc_conf.fc.high_water = res->high_water;
7444        pfc_conf.fc.low_water  = res->low_water;
7445        pfc_conf.fc.pause_time = res->pause_time;
7446        pfc_conf.priority      = res->priority;
7447
7448        ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7449        if (ret != 0)
7450                fprintf(stderr,
7451                        "bad priority flow control parameter, return code = %d\n",
7452                        ret);
7453}
7454
7455cmdline_parse_token_string_t cmd_pfc_set_set =
7456        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7457                                set, "set");
7458cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7459        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7460                                pfc_ctrl, "pfc_ctrl");
7461cmdline_parse_token_string_t cmd_pfc_set_rx =
7462        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7463                                rx, "rx");
7464cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7465        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7466                                rx_pfc_mode, "on#off");
7467cmdline_parse_token_string_t cmd_pfc_set_tx =
7468        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7469                                tx, "tx");
7470cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7471        TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7472                                tx_pfc_mode, "on#off");
7473cmdline_parse_token_num_t cmd_pfc_set_high_water =
7474        TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7475                                high_water, RTE_UINT32);
7476cmdline_parse_token_num_t cmd_pfc_set_low_water =
7477        TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7478                                low_water, RTE_UINT32);
7479cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7480        TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7481                                pause_time, RTE_UINT16);
7482cmdline_parse_token_num_t cmd_pfc_set_priority =
7483        TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7484                                priority, RTE_UINT8);
7485cmdline_parse_token_num_t cmd_pfc_set_portid =
7486        TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7487                                port_id, RTE_UINT16);
7488
7489cmdline_parse_inst_t cmd_priority_flow_control_set = {
7490        .f = cmd_priority_flow_ctrl_set_parsed,
7491        .data = NULL,
7492        .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7493                "<pause_time> <priority> <port_id>: "
7494                "Configure the Ethernet priority flow control",
7495        .tokens = {
7496                (void *)&cmd_pfc_set_set,
7497                (void *)&cmd_pfc_set_flow_ctrl,
7498                (void *)&cmd_pfc_set_rx,
7499                (void *)&cmd_pfc_set_rx_mode,
7500                (void *)&cmd_pfc_set_tx,
7501                (void *)&cmd_pfc_set_tx_mode,
7502                (void *)&cmd_pfc_set_high_water,
7503                (void *)&cmd_pfc_set_low_water,
7504                (void *)&cmd_pfc_set_pause_time,
7505                (void *)&cmd_pfc_set_priority,
7506                (void *)&cmd_pfc_set_portid,
7507                NULL,
7508        },
7509};
7510
7511/* *** RESET CONFIGURATION *** */
7512struct cmd_reset_result {
7513        cmdline_fixed_string_t reset;
7514        cmdline_fixed_string_t def;
7515};
7516
7517static void cmd_reset_parsed(__rte_unused void *parsed_result,
7518                             struct cmdline *cl,
7519                             __rte_unused void *data)
7520{
7521        cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7522        set_def_fwd_config();
7523}
7524
7525cmdline_parse_token_string_t cmd_reset_set =
7526        TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7527cmdline_parse_token_string_t cmd_reset_def =
7528        TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7529                                 "default");
7530
7531cmdline_parse_inst_t cmd_reset = {
7532        .f = cmd_reset_parsed,
7533        .data = NULL,
7534        .help_str = "set default: Reset default forwarding configuration",
7535        .tokens = {
7536                (void *)&cmd_reset_set,
7537                (void *)&cmd_reset_def,
7538                NULL,
7539        },
7540};
7541
7542/* *** START FORWARDING *** */
7543struct cmd_start_result {
7544        cmdline_fixed_string_t start;
7545};
7546
7547cmdline_parse_token_string_t cmd_start_start =
7548        TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7549
7550static void cmd_start_parsed(__rte_unused void *parsed_result,
7551                             __rte_unused struct cmdline *cl,
7552                             __rte_unused void *data)
7553{
7554        start_packet_forwarding(0);
7555}
7556
7557cmdline_parse_inst_t cmd_start = {
7558        .f = cmd_start_parsed,
7559        .data = NULL,
7560        .help_str = "start: Start packet forwarding",
7561        .tokens = {
7562                (void *)&cmd_start_start,
7563                NULL,
7564        },
7565};
7566
7567/* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7568struct cmd_start_tx_first_result {
7569        cmdline_fixed_string_t start;
7570        cmdline_fixed_string_t tx_first;
7571};
7572
7573static void
7574cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7575                          __rte_unused struct cmdline *cl,
7576                          __rte_unused void *data)
7577{
7578        start_packet_forwarding(1);
7579}
7580
7581cmdline_parse_token_string_t cmd_start_tx_first_start =
7582        TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7583                                 "start");
7584cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7585        TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7586                                 tx_first, "tx_first");
7587
7588cmdline_parse_inst_t cmd_start_tx_first = {
7589        .f = cmd_start_tx_first_parsed,
7590        .data = NULL,
7591        .help_str = "start tx_first: Start packet forwarding, "
7592                "after sending 1 burst of packets",
7593        .tokens = {
7594                (void *)&cmd_start_tx_first_start,
7595                (void *)&cmd_start_tx_first_tx_first,
7596                NULL,
7597        },
7598};
7599
7600/* *** START FORWARDING WITH N TX BURST FIRST *** */
7601struct cmd_start_tx_first_n_result {
7602        cmdline_fixed_string_t start;
7603        cmdline_fixed_string_t tx_first;
7604        uint32_t tx_num;
7605};
7606
7607static void
7608cmd_start_tx_first_n_parsed(void *parsed_result,
7609                          __rte_unused struct cmdline *cl,
7610                          __rte_unused void *data)
7611{
7612        struct cmd_start_tx_first_n_result *res = parsed_result;
7613
7614        start_packet_forwarding(res->tx_num);
7615}
7616
7617cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7618        TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7619                        start, "start");
7620cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7621        TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7622                        tx_first, "tx_first");
7623cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7624        TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7625                        tx_num, RTE_UINT32);
7626
7627cmdline_parse_inst_t cmd_start_tx_first_n = {
7628        .f = cmd_start_tx_first_n_parsed,
7629        .data = NULL,
7630        .help_str = "start tx_first <num>: "
7631                "packet forwarding, after sending <num> bursts of packets",
7632        .tokens = {
7633                (void *)&cmd_start_tx_first_n_start,
7634                (void *)&cmd_start_tx_first_n_tx_first,
7635                (void *)&cmd_start_tx_first_n_tx_num,
7636                NULL,
7637        },
7638};
7639
7640/* *** SET LINK UP *** */
7641struct cmd_set_link_up_result {
7642        cmdline_fixed_string_t set;
7643        cmdline_fixed_string_t link_up;
7644        cmdline_fixed_string_t port;
7645        portid_t port_id;
7646};
7647
7648cmdline_parse_token_string_t cmd_set_link_up_set =
7649        TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7650cmdline_parse_token_string_t cmd_set_link_up_link_up =
7651        TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7652                                "link-up");
7653cmdline_parse_token_string_t cmd_set_link_up_port =
7654        TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7655cmdline_parse_token_num_t cmd_set_link_up_port_id =
7656        TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7657                                RTE_UINT16);
7658
7659static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7660                             __rte_unused struct cmdline *cl,
7661                             __rte_unused void *data)
7662{
7663        struct cmd_set_link_up_result *res = parsed_result;
7664        dev_set_link_up(res->port_id);
7665}
7666
7667cmdline_parse_inst_t cmd_set_link_up = {
7668        .f = cmd_set_link_up_parsed,
7669        .data = NULL,
7670        .help_str = "set link-up port <port id>",
7671        .tokens = {
7672                (void *)&cmd_set_link_up_set,
7673                (void *)&cmd_set_link_up_link_up,
7674                (void *)&cmd_set_link_up_port,
7675                (void *)&cmd_set_link_up_port_id,
7676                NULL,
7677        },
7678};
7679
7680/* *** SET LINK DOWN *** */
7681struct cmd_set_link_down_result {
7682        cmdline_fixed_string_t set;
7683        cmdline_fixed_string_t link_down;
7684        cmdline_fixed_string_t port;
7685        portid_t port_id;
7686};
7687
7688cmdline_parse_token_string_t cmd_set_link_down_set =
7689        TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7690cmdline_parse_token_string_t cmd_set_link_down_link_down =
7691        TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7692                                "link-down");
7693cmdline_parse_token_string_t cmd_set_link_down_port =
7694        TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7695cmdline_parse_token_num_t cmd_set_link_down_port_id =
7696        TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7697                                RTE_UINT16);
7698
7699static void cmd_set_link_down_parsed(
7700                                __rte_unused void *parsed_result,
7701                                __rte_unused struct cmdline *cl,
7702                                __rte_unused void *data)
7703{
7704        struct cmd_set_link_down_result *res = parsed_result;
7705        dev_set_link_down(res->port_id);
7706}
7707
7708cmdline_parse_inst_t cmd_set_link_down = {
7709        .f = cmd_set_link_down_parsed,
7710        .data = NULL,
7711        .help_str = "set link-down port <port id>",
7712        .tokens = {
7713                (void *)&cmd_set_link_down_set,
7714                (void *)&cmd_set_link_down_link_down,
7715                (void *)&cmd_set_link_down_port,
7716                (void *)&cmd_set_link_down_port_id,
7717                NULL,
7718        },
7719};
7720
7721/* *** SHOW CFG *** */
7722struct cmd_showcfg_result {
7723        cmdline_fixed_string_t show;
7724        cmdline_fixed_string_t cfg;
7725        cmdline_fixed_string_t what;
7726};
7727
7728static void cmd_showcfg_parsed(void *parsed_result,
7729                               __rte_unused struct cmdline *cl,
7730                               __rte_unused void *data)
7731{
7732        struct cmd_showcfg_result *res = parsed_result;
7733        if (!strcmp(res->what, "rxtx"))
7734                rxtx_config_display();
7735        else if (!strcmp(res->what, "cores"))
7736                fwd_lcores_config_display();
7737        else if (!strcmp(res->what, "fwd"))
7738                pkt_fwd_config_display(&cur_fwd_config);
7739        else if (!strcmp(res->what, "rxoffs"))
7740                show_rx_pkt_offsets();
7741        else if (!strcmp(res->what, "rxpkts"))
7742                show_rx_pkt_segments();
7743        else if (!strcmp(res->what, "txpkts"))
7744                show_tx_pkt_segments();
7745        else if (!strcmp(res->what, "txtimes"))
7746                show_tx_pkt_times();
7747}
7748
7749cmdline_parse_token_string_t cmd_showcfg_show =
7750        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7751cmdline_parse_token_string_t cmd_showcfg_port =
7752        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7753cmdline_parse_token_string_t cmd_showcfg_what =
7754        TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7755                                 "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7756
7757cmdline_parse_inst_t cmd_showcfg = {
7758        .f = cmd_showcfg_parsed,
7759        .data = NULL,
7760        .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7761        .tokens = {
7762                (void *)&cmd_showcfg_show,
7763                (void *)&cmd_showcfg_port,
7764                (void *)&cmd_showcfg_what,
7765                NULL,
7766        },
7767};
7768
7769/* *** SHOW ALL PORT INFO *** */
7770struct cmd_showportall_result {
7771        cmdline_fixed_string_t show;
7772        cmdline_fixed_string_t port;
7773        cmdline_fixed_string_t what;
7774        cmdline_fixed_string_t all;
7775};
7776
7777static void cmd_showportall_parsed(void *parsed_result,
7778                                __rte_unused struct cmdline *cl,
7779                                __rte_unused void *data)
7780{
7781        portid_t i;
7782
7783        struct cmd_showportall_result *res = parsed_result;
7784        if (!strcmp(res->show, "clear")) {
7785                if (!strcmp(res->what, "stats"))
7786                        RTE_ETH_FOREACH_DEV(i)
7787                                nic_stats_clear(i);
7788                else if (!strcmp(res->what, "xstats"))
7789                        RTE_ETH_FOREACH_DEV(i)
7790                                nic_xstats_clear(i);
7791        } else if (!strcmp(res->what, "info"))
7792                RTE_ETH_FOREACH_DEV(i)
7793                        port_infos_display(i);
7794        else if (!strcmp(res->what, "summary")) {
7795                port_summary_header_display();
7796                RTE_ETH_FOREACH_DEV(i)
7797                        port_summary_display(i);
7798        }
7799        else if (!strcmp(res->what, "stats"))
7800                RTE_ETH_FOREACH_DEV(i)
7801                        nic_stats_display(i);
7802        else if (!strcmp(res->what, "xstats"))
7803                RTE_ETH_FOREACH_DEV(i)
7804                        nic_xstats_display(i);
7805#if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7806        else if (!strcmp(res->what, "fdir"))
7807                RTE_ETH_FOREACH_DEV(i)
7808                        fdir_get_infos(i);
7809#endif
7810        else if (!strcmp(res->what, "dcb_tc"))
7811                RTE_ETH_FOREACH_DEV(i)
7812                        port_dcb_info_display(i);
7813}
7814
7815cmdline_parse_token_string_t cmd_showportall_show =
7816        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7817                                 "show#clear");
7818cmdline_parse_token_string_t cmd_showportall_port =
7819        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7820cmdline_parse_token_string_t cmd_showportall_what =
7821        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7822                                 "info#summary#stats#xstats#fdir#dcb_tc");
7823cmdline_parse_token_string_t cmd_showportall_all =
7824        TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7825cmdline_parse_inst_t cmd_showportall = {
7826        .f = cmd_showportall_parsed,
7827        .data = NULL,
7828        .help_str = "show|clear port "
7829                "info|summary|stats|xstats|fdir|dcb_tc all",
7830        .tokens = {
7831                (void *)&cmd_showportall_show,
7832                (void *)&cmd_showportall_port,
7833                (void *)&cmd_showportall_what,
7834                (void *)&cmd_showportall_all,
7835                NULL,
7836        },
7837};
7838
7839/* *** SHOW PORT INFO *** */
7840struct cmd_showport_result {
7841        cmdline_fixed_string_t show;
7842        cmdline_fixed_string_t port;
7843        cmdline_fixed_string_t what;
7844        uint16_t portnum;
7845};
7846
7847static void cmd_showport_parsed(void *parsed_result,
7848                                __rte_unused struct cmdline *cl,
7849                                __rte_unused void *data)
7850{
7851        struct cmd_showport_result *res = parsed_result;
7852        if (!strcmp(res->show, "clear")) {
7853                if (!strcmp(res->what, "stats"))
7854                        nic_stats_clear(res->portnum);
7855                else if (!strcmp(res->what, "xstats"))
7856                        nic_xstats_clear(res->portnum);
7857        } else if (!strcmp(res->what, "info"))
7858                port_infos_display(res->portnum);
7859        else if (!strcmp(res->what, "summary")) {
7860                port_summary_header_display();
7861                port_summary_display(res->portnum);
7862        }
7863        else if (!strcmp(res->what, "stats"))
7864                nic_stats_display(res->portnum);
7865        else if (!strcmp(res->what, "xstats"))
7866                nic_xstats_display(res->portnum);
7867#if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7868        else if (!strcmp(res->what, "fdir"))
7869                 fdir_get_infos(res->portnum);
7870#endif
7871        else if (!strcmp(res->what, "dcb_tc"))
7872                port_dcb_info_display(res->portnum);
7873}
7874
7875cmdline_parse_token_string_t cmd_showport_show =
7876        TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7877                                 "show#clear");
7878cmdline_parse_token_string_t cmd_showport_port =
7879        TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7880cmdline_parse_token_string_t cmd_showport_what =
7881        TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7882                                 "info#summary#stats#xstats#fdir#dcb_tc");
7883cmdline_parse_token_num_t cmd_showport_portnum =
7884        TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7885
7886cmdline_parse_inst_t cmd_showport = {
7887        .f = cmd_showport_parsed,
7888        .data = NULL,
7889        .help_str = "show|clear port "
7890                "info|summary|stats|xstats|fdir|dcb_tc "
7891                "<port_id>",
7892        .tokens = {
7893                (void *)&cmd_showport_show,
7894                (void *)&cmd_showport_port,
7895                (void *)&cmd_showport_what,
7896                (void *)&cmd_showport_portnum,
7897                NULL,
7898        },
7899};
7900
7901/* *** SHOW DEVICE INFO *** */
7902struct cmd_showdevice_result {
7903        cmdline_fixed_string_t show;
7904        cmdline_fixed_string_t device;
7905        cmdline_fixed_string_t what;
7906        cmdline_fixed_string_t identifier;
7907};
7908
7909static void cmd_showdevice_parsed(void *parsed_result,
7910                                __rte_unused struct cmdline *cl,
7911                                __rte_unused void *data)
7912{
7913        struct cmd_showdevice_result *res = parsed_result;
7914        if (!strcmp(res->what, "info")) {
7915                if (!strcmp(res->identifier, "all"))
7916                        device_infos_display(NULL);
7917                else
7918                        device_infos_display(res->identifier);
7919        }
7920}
7921
7922cmdline_parse_token_string_t cmd_showdevice_show =
7923        TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7924                                 "show");
7925cmdline_parse_token_string_t cmd_showdevice_device =
7926        TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7927cmdline_parse_token_string_t cmd_showdevice_what =
7928        TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7929                                 "info");
7930cmdline_parse_token_string_t cmd_showdevice_identifier =
7931        TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7932                        identifier, NULL);
7933
7934cmdline_parse_inst_t cmd_showdevice = {
7935        .f = cmd_showdevice_parsed,
7936        .data = NULL,
7937        .help_str = "show device info <identifier>|all",
7938        .tokens = {
7939                (void *)&cmd_showdevice_show,
7940                (void *)&cmd_showdevice_device,
7941                (void *)&cmd_showdevice_what,
7942                (void *)&cmd_showdevice_identifier,
7943                NULL,
7944        },
7945};
7946
7947/* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7948struct cmd_showeeprom_result {
7949        cmdline_fixed_string_t show;
7950        cmdline_fixed_string_t port;
7951        uint16_t portnum;
7952        cmdline_fixed_string_t type;
7953};
7954
7955static void cmd_showeeprom_parsed(void *parsed_result,
7956                __rte_unused struct cmdline *cl,
7957                __rte_unused void *data)
7958{
7959        struct cmd_showeeprom_result *res = parsed_result;
7960
7961        if (!strcmp(res->type, "eeprom"))
7962                port_eeprom_display(res->portnum);
7963        else if (!strcmp(res->type, "module_eeprom"))
7964                port_module_eeprom_display(res->portnum);
7965        else
7966                fprintf(stderr, "Unknown argument\n");
7967}
7968
7969cmdline_parse_token_string_t cmd_showeeprom_show =
7970        TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7971cmdline_parse_token_string_t cmd_showeeprom_port =
7972        TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7973cmdline_parse_token_num_t cmd_showeeprom_portnum =
7974        TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7975                        RTE_UINT16);
7976cmdline_parse_token_string_t cmd_showeeprom_type =
7977        TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7978
7979cmdline_parse_inst_t cmd_showeeprom = {
7980        .f = cmd_showeeprom_parsed,
7981        .data = NULL,
7982        .help_str = "show port <port_id> module_eeprom|eeprom",
7983        .tokens = {
7984                (void *)&cmd_showeeprom_show,
7985                (void *)&cmd_showeeprom_port,
7986                (void *)&cmd_showeeprom_portnum,
7987                (void *)&cmd_showeeprom_type,
7988                NULL,
7989        },
7990};
7991
7992/* *** SHOW QUEUE INFO *** */
7993struct cmd_showqueue_result {
7994        cmdline_fixed_string_t show;
7995        cmdline_fixed_string_t type;
7996        cmdline_fixed_string_t what;
7997        uint16_t portnum;
7998        uint16_t queuenum;
7999};
8000
8001static void
8002cmd_showqueue_parsed(void *parsed_result,
8003        __rte_unused struct cmdline *cl,
8004        __rte_unused void *data)
8005{
8006        struct cmd_showqueue_result *res = parsed_result;
8007
8008        if (!strcmp(res->type, "rxq"))
8009                rx_queue_infos_display(res->portnum, res->queuenum);
8010        else if (!strcmp(res->type, "txq"))
8011                tx_queue_infos_display(res->portnum, res->queuenum);
8012}
8013
8014cmdline_parse_token_string_t cmd_showqueue_show =
8015        TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8016cmdline_parse_token_string_t cmd_showqueue_type =
8017        TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8018cmdline_parse_token_string_t cmd_showqueue_what =
8019        TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8020cmdline_parse_token_num_t cmd_showqueue_portnum =
8021        TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8022                RTE_UINT16);
8023cmdline_parse_token_num_t cmd_showqueue_queuenum =
8024        TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8025                RTE_UINT16);
8026
8027cmdline_parse_inst_t cmd_showqueue = {
8028        .f = cmd_showqueue_parsed,
8029        .data = NULL,
8030        .help_str = "show rxq|txq info <port_id> <queue_id>",
8031        .tokens = {
8032                (void *)&cmd_showqueue_show,
8033                (void *)&cmd_showqueue_type,
8034                (void *)&cmd_showqueue_what,
8035                (void *)&cmd_showqueue_portnum,
8036                (void *)&cmd_showqueue_queuenum,
8037                NULL,
8038        },
8039};
8040
8041/* show/clear fwd engine statistics */
8042struct fwd_result {
8043        cmdline_fixed_string_t action;
8044        cmdline_fixed_string_t fwd;
8045        cmdline_fixed_string_t stats;
8046        cmdline_fixed_string_t all;
8047};
8048
8049cmdline_parse_token_string_t cmd_fwd_action =
8050        TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8051cmdline_parse_token_string_t cmd_fwd_fwd =
8052        TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8053cmdline_parse_token_string_t cmd_fwd_stats =
8054        TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8055cmdline_parse_token_string_t cmd_fwd_all =
8056        TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8057
8058static void
8059cmd_showfwdall_parsed(void *parsed_result,
8060                      __rte_unused struct cmdline *cl,
8061                      __rte_unused void *data)
8062{
8063        struct fwd_result *res = parsed_result;
8064
8065        if (!strcmp(res->action, "show"))
8066                fwd_stats_display();
8067        else
8068                fwd_stats_reset();
8069}
8070
8071static cmdline_parse_inst_t cmd_showfwdall = {
8072        .f = cmd_showfwdall_parsed,
8073        .data = NULL,
8074        .help_str = "show|clear fwd stats all",
8075        .tokens = {
8076                (void *)&cmd_fwd_action,
8077                (void *)&cmd_fwd_fwd,
8078                (void *)&cmd_fwd_stats,
8079                (void *)&cmd_fwd_all,
8080                NULL,
8081        },
8082};
8083
8084/* *** READ PORT REGISTER *** */
8085struct cmd_read_reg_result {
8086        cmdline_fixed_string_t read;
8087        cmdline_fixed_string_t reg;
8088        portid_t port_id;
8089        uint32_t reg_off;
8090};
8091
8092static void
8093cmd_read_reg_parsed(void *parsed_result,
8094                    __rte_unused struct cmdline *cl,
8095                    __rte_unused void *data)
8096{
8097        struct cmd_read_reg_result *res = parsed_result;
8098        port_reg_display(res->port_id, res->reg_off);
8099}
8100
8101cmdline_parse_token_string_t cmd_read_reg_read =
8102        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8103cmdline_parse_token_string_t cmd_read_reg_reg =
8104        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8105cmdline_parse_token_num_t cmd_read_reg_port_id =
8106        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8107cmdline_parse_token_num_t cmd_read_reg_reg_off =
8108        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8109
8110cmdline_parse_inst_t cmd_read_reg = {
8111        .f = cmd_read_reg_parsed,
8112        .data = NULL,
8113        .help_str = "read reg <port_id> <reg_off>",
8114        .tokens = {
8115                (void *)&cmd_read_reg_read,
8116                (void *)&cmd_read_reg_reg,
8117                (void *)&cmd_read_reg_port_id,
8118                (void *)&cmd_read_reg_reg_off,
8119                NULL,
8120        },
8121};
8122
8123/* *** READ PORT REGISTER BIT FIELD *** */
8124struct cmd_read_reg_bit_field_result {
8125        cmdline_fixed_string_t read;
8126        cmdline_fixed_string_t regfield;
8127        portid_t port_id;
8128        uint32_t reg_off;
8129        uint8_t bit1_pos;
8130        uint8_t bit2_pos;
8131};
8132
8133static void
8134cmd_read_reg_bit_field_parsed(void *parsed_result,
8135                              __rte_unused struct cmdline *cl,
8136                              __rte_unused void *data)
8137{
8138        struct cmd_read_reg_bit_field_result *res = parsed_result;
8139        port_reg_bit_field_display(res->port_id, res->reg_off,
8140                                   res->bit1_pos, res->bit2_pos);
8141}
8142
8143cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8144        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8145                                 "read");
8146cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8147        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8148                                 regfield, "regfield");
8149cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8150        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8151                              RTE_UINT16);
8152cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8153        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8154                              RTE_UINT32);
8155cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8156        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8157                              RTE_UINT8);
8158cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8159        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8160                              RTE_UINT8);
8161
8162cmdline_parse_inst_t cmd_read_reg_bit_field = {
8163        .f = cmd_read_reg_bit_field_parsed,
8164        .data = NULL,
8165        .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8166        "Read register bit field between bit_x and bit_y included",
8167        .tokens = {
8168                (void *)&cmd_read_reg_bit_field_read,
8169                (void *)&cmd_read_reg_bit_field_regfield,
8170                (void *)&cmd_read_reg_bit_field_port_id,
8171                (void *)&cmd_read_reg_bit_field_reg_off,
8172                (void *)&cmd_read_reg_bit_field_bit1_pos,
8173                (void *)&cmd_read_reg_bit_field_bit2_pos,
8174                NULL,
8175        },
8176};
8177
8178/* *** READ PORT REGISTER BIT *** */
8179struct cmd_read_reg_bit_result {
8180        cmdline_fixed_string_t read;
8181        cmdline_fixed_string_t regbit;
8182        portid_t port_id;
8183        uint32_t reg_off;
8184        uint8_t bit_pos;
8185};
8186
8187static void
8188cmd_read_reg_bit_parsed(void *parsed_result,
8189                        __rte_unused struct cmdline *cl,
8190                        __rte_unused void *data)
8191{
8192        struct cmd_read_reg_bit_result *res = parsed_result;
8193        port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8194}
8195
8196cmdline_parse_token_string_t cmd_read_reg_bit_read =
8197        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8198cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8199        TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8200                                 regbit, "regbit");
8201cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8202        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8203                                 RTE_UINT16);
8204cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8205        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8206                                 RTE_UINT32);
8207cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8208        TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8209                                 RTE_UINT8);
8210
8211cmdline_parse_inst_t cmd_read_reg_bit = {
8212        .f = cmd_read_reg_bit_parsed,
8213        .data = NULL,
8214        .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8215        .tokens = {
8216                (void *)&cmd_read_reg_bit_read,
8217                (void *)&cmd_read_reg_bit_regbit,
8218                (void *)&cmd_read_reg_bit_port_id,
8219                (void *)&cmd_read_reg_bit_reg_off,
8220                (void *)&cmd_read_reg_bit_bit_pos,
8221                NULL,
8222        },
8223};
8224
8225/* *** WRITE PORT REGISTER *** */
8226struct cmd_write_reg_result {
8227        cmdline_fixed_string_t write;
8228        cmdline_fixed_string_t reg;
8229        portid_t port_id;
8230        uint32_t reg_off;
8231        uint32_t value;
8232};
8233
8234static void
8235cmd_write_reg_parsed(void *parsed_result,
8236                     __rte_unused struct cmdline *cl,
8237                     __rte_unused void *data)
8238{
8239        struct cmd_write_reg_result *res = parsed_result;
8240        port_reg_set(res->port_id, res->reg_off, res->value);
8241}
8242
8243cmdline_parse_token_string_t cmd_write_reg_write =
8244        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8245cmdline_parse_token_string_t cmd_write_reg_reg =
8246        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8247cmdline_parse_token_num_t cmd_write_reg_port_id =
8248        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8249cmdline_parse_token_num_t cmd_write_reg_reg_off =
8250        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8251cmdline_parse_token_num_t cmd_write_reg_value =
8252        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8253
8254cmdline_parse_inst_t cmd_write_reg = {
8255        .f = cmd_write_reg_parsed,
8256        .data = NULL,
8257        .help_str = "write reg <port_id> <reg_off> <reg_value>",
8258        .tokens = {
8259                (void *)&cmd_write_reg_write,
8260                (void *)&cmd_write_reg_reg,
8261                (void *)&cmd_write_reg_port_id,
8262                (void *)&cmd_write_reg_reg_off,
8263                (void *)&cmd_write_reg_value,
8264                NULL,
8265        },
8266};
8267
8268/* *** WRITE PORT REGISTER BIT FIELD *** */
8269struct cmd_write_reg_bit_field_result {
8270        cmdline_fixed_string_t write;
8271        cmdline_fixed_string_t regfield;
8272        portid_t port_id;
8273        uint32_t reg_off;
8274        uint8_t bit1_pos;
8275        uint8_t bit2_pos;
8276        uint32_t value;
8277};
8278
8279static void
8280cmd_write_reg_bit_field_parsed(void *parsed_result,
8281                               __rte_unused struct cmdline *cl,
8282                               __rte_unused void *data)
8283{
8284        struct cmd_write_reg_bit_field_result *res = parsed_result;
8285        port_reg_bit_field_set(res->port_id, res->reg_off,
8286                          res->bit1_pos, res->bit2_pos, res->value);
8287}
8288
8289cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8290        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8291                                 "write");
8292cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8293        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8294                                 regfield, "regfield");
8295cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8296        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8297                              RTE_UINT16);
8298cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8299        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8300                              RTE_UINT32);
8301cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8302        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8303                              RTE_UINT8);
8304cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8305        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8306                              RTE_UINT8);
8307cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8308        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8309                              RTE_UINT32);
8310
8311cmdline_parse_inst_t cmd_write_reg_bit_field = {
8312        .f = cmd_write_reg_bit_field_parsed,
8313        .data = NULL,
8314        .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8315                "<reg_value>: "
8316                "Set register bit field between bit_x and bit_y included",
8317        .tokens = {
8318                (void *)&cmd_write_reg_bit_field_write,
8319                (void *)&cmd_write_reg_bit_field_regfield,
8320                (void *)&cmd_write_reg_bit_field_port_id,
8321                (void *)&cmd_write_reg_bit_field_reg_off,
8322                (void *)&cmd_write_reg_bit_field_bit1_pos,
8323                (void *)&cmd_write_reg_bit_field_bit2_pos,
8324                (void *)&cmd_write_reg_bit_field_value,
8325                NULL,
8326        },
8327};
8328
8329/* *** WRITE PORT REGISTER BIT *** */
8330struct cmd_write_reg_bit_result {
8331        cmdline_fixed_string_t write;
8332        cmdline_fixed_string_t regbit;
8333        portid_t port_id;
8334        uint32_t reg_off;
8335        uint8_t bit_pos;
8336        uint8_t value;
8337};
8338
8339static void
8340cmd_write_reg_bit_parsed(void *parsed_result,
8341                         __rte_unused struct cmdline *cl,
8342                         __rte_unused void *data)
8343{
8344        struct cmd_write_reg_bit_result *res = parsed_result;
8345        port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8346}
8347
8348cmdline_parse_token_string_t cmd_write_reg_bit_write =
8349        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8350                                 "write");
8351cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8352        TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8353                                 regbit, "regbit");
8354cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8355        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8356                                 RTE_UINT16);
8357cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8358        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8359                                 RTE_UINT32);
8360cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8361        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8362                                 RTE_UINT8);
8363cmdline_parse_token_num_t cmd_write_reg_bit_value =
8364        TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8365                                 RTE_UINT8);
8366
8367cmdline_parse_inst_t cmd_write_reg_bit = {
8368        .f = cmd_write_reg_bit_parsed,
8369        .data = NULL,
8370        .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8371                "0 <= bit_x <= 31",
8372        .tokens = {
8373                (void *)&cmd_write_reg_bit_write,
8374                (void *)&cmd_write_reg_bit_regbit,
8375                (void *)&cmd_write_reg_bit_port_id,
8376                (void *)&cmd_write_reg_bit_reg_off,
8377                (void *)&cmd_write_reg_bit_bit_pos,
8378                (void *)&cmd_write_reg_bit_value,
8379                NULL,
8380        },
8381};
8382
8383/* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8384struct cmd_read_rxd_txd_result {
8385        cmdline_fixed_string_t read;
8386        cmdline_fixed_string_t rxd_txd;
8387        portid_t port_id;
8388        uint16_t queue_id;
8389        uint16_t desc_id;
8390};
8391
8392static void
8393cmd_read_rxd_txd_parsed(void *parsed_result,
8394                        __rte_unused struct cmdline *cl,
8395                        __rte_unused void *data)
8396{
8397        struct cmd_read_rxd_txd_result *res = parsed_result;
8398
8399        if (!strcmp(res->rxd_txd, "rxd"))
8400                rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8401        else if (!strcmp(res->rxd_txd, "txd"))
8402                tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8403}
8404
8405cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8406        TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8407cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8408        TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8409                                 "rxd#txd");
8410cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8411        TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8412                                 RTE_UINT16);
8413cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8414        TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8415                                 RTE_UINT16);
8416cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8417        TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8418                                 RTE_UINT16);
8419
8420cmdline_parse_inst_t cmd_read_rxd_txd = {
8421        .f = cmd_read_rxd_txd_parsed,
8422        .data = NULL,
8423        .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8424        .tokens = {
8425                (void *)&cmd_read_rxd_txd_read,
8426                (void *)&cmd_read_rxd_txd_rxd_txd,
8427                (void *)&cmd_read_rxd_txd_port_id,
8428                (void *)&cmd_read_rxd_txd_queue_id,
8429                (void *)&cmd_read_rxd_txd_desc_id,
8430                NULL,
8431        },
8432};
8433
8434/* *** QUIT *** */
8435struct cmd_quit_result {
8436        cmdline_fixed_string_t quit;
8437};
8438
8439static void cmd_quit_parsed(__rte_unused void *parsed_result,
8440                            struct cmdline *cl,
8441                            __rte_unused void *data)
8442{
8443        cmdline_quit(cl);
8444}
8445
8446cmdline_parse_token_string_t cmd_quit_quit =
8447        TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8448
8449cmdline_parse_inst_t cmd_quit = {
8450        .f = cmd_quit_parsed,
8451        .data = NULL,
8452        .help_str = "quit: Exit application",
8453        .tokens = {
8454                (void *)&cmd_quit_quit,
8455                NULL,
8456        },
8457};
8458
8459/* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8460struct cmd_mac_addr_result {
8461        cmdline_fixed_string_t mac_addr_cmd;
8462        cmdline_fixed_string_t what;
8463        uint16_t port_num;
8464        struct rte_ether_addr address;
8465};
8466
8467static void cmd_mac_addr_parsed(void *parsed_result,
8468                __rte_unused struct cmdline *cl,
8469                __rte_unused void *data)
8470{
8471        struct cmd_mac_addr_result *res = parsed_result;
8472        int ret;
8473
8474        if (strcmp(res->what, "add") == 0)
8475                ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8476        else if (strcmp(res->what, "set") == 0)
8477                ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8478                                                       &res->address);
8479        else
8480                ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8481
8482        /* check the return value and print it if is < 0 */
8483        if(ret < 0)
8484                fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8485
8486}
8487
8488cmdline_parse_token_string_t cmd_mac_addr_cmd =
8489        TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8490                                "mac_addr");
8491cmdline_parse_token_string_t cmd_mac_addr_what =
8492        TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8493                                "add#remove#set");
8494cmdline_parse_token_num_t cmd_mac_addr_portnum =
8495                TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8496                                        RTE_UINT16);
8497cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8498                TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8499
8500cmdline_parse_inst_t cmd_mac_addr = {
8501        .f = cmd_mac_addr_parsed,
8502        .data = (void *)0,
8503        .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8504                        "Add/Remove/Set MAC address on port_id",
8505        .tokens = {
8506                (void *)&cmd_mac_addr_cmd,
8507                (void *)&cmd_mac_addr_what,
8508                (void *)&cmd_mac_addr_portnum,
8509                (void *)&cmd_mac_addr_addr,
8510                NULL,
8511        },
8512};
8513
8514/* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8515struct cmd_eth_peer_result {
8516        cmdline_fixed_string_t set;
8517        cmdline_fixed_string_t eth_peer;
8518        portid_t port_id;
8519        cmdline_fixed_string_t peer_addr;
8520};
8521
8522static void cmd_set_eth_peer_parsed(void *parsed_result,
8523                        __rte_unused struct cmdline *cl,
8524                        __rte_unused void *data)
8525{
8526                struct cmd_eth_peer_result *res = parsed_result;
8527
8528                if (test_done == 0) {
8529                        fprintf(stderr, "Please stop forwarding first\n");
8530                        return;
8531                }
8532                if (!strcmp(res->eth_peer, "eth-peer")) {
8533                        set_fwd_eth_peer(res->port_id, res->peer_addr);
8534                        fwd_config_setup();
8535                }
8536}
8537cmdline_parse_token_string_t cmd_eth_peer_set =
8538        TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8539cmdline_parse_token_string_t cmd_eth_peer =
8540        TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8541cmdline_parse_token_num_t cmd_eth_peer_port_id =
8542        TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8543                RTE_UINT16);
8544cmdline_parse_token_string_t cmd_eth_peer_addr =
8545        TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8546
8547cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8548        .f = cmd_set_eth_peer_parsed,
8549        .data = NULL,
8550        .help_str = "set eth-peer <port_id> <peer_mac>",
8551        .tokens = {
8552                (void *)&cmd_eth_peer_set,
8553                (void *)&cmd_eth_peer,
8554                (void *)&cmd_eth_peer_port_id,
8555                (void *)&cmd_eth_peer_addr,
8556                NULL,
8557        },
8558};
8559
8560/* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8561struct cmd_set_qmap_result {
8562        cmdline_fixed_string_t set;
8563        cmdline_fixed_string_t qmap;
8564        cmdline_fixed_string_t what;
8565        portid_t port_id;
8566        uint16_t queue_id;
8567        uint8_t map_value;
8568};
8569
8570static void
8571cmd_set_qmap_parsed(void *parsed_result,
8572                       __rte_unused struct cmdline *cl,
8573                       __rte_unused void *data)
8574{
8575        struct cmd_set_qmap_result *res = parsed_result;
8576        int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8577
8578        set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8579}
8580
8581cmdline_parse_token_string_t cmd_setqmap_set =
8582        TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8583                                 set, "set");
8584cmdline_parse_token_string_t cmd_setqmap_qmap =
8585        TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8586                                 qmap, "stat_qmap");
8587cmdline_parse_token_string_t cmd_setqmap_what =
8588        TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8589                                 what, "tx#rx");
8590cmdline_parse_token_num_t cmd_setqmap_portid =
8591        TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8592                              port_id, RTE_UINT16);
8593cmdline_parse_token_num_t cmd_setqmap_queueid =
8594        TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8595                              queue_id, RTE_UINT16);
8596cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8597        TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8598                              map_value, RTE_UINT8);
8599
8600cmdline_parse_inst_t cmd_set_qmap = {
8601        .f = cmd_set_qmap_parsed,
8602        .data = NULL,
8603        .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8604                "Set statistics mapping value on tx|rx queue_id of port_id",
8605        .tokens = {
8606                (void *)&cmd_setqmap_set,
8607                (void *)&cmd_setqmap_qmap,
8608                (void *)&cmd_setqmap_what,
8609                (void *)&cmd_setqmap_portid,
8610                (void *)&cmd_setqmap_queueid,
8611                (void *)&cmd_setqmap_mapvalue,
8612                NULL,
8613        },
8614};
8615
8616/* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8617struct cmd_set_xstats_hide_zero_result {
8618        cmdline_fixed_string_t keyword;
8619        cmdline_fixed_string_t name;
8620        cmdline_fixed_string_t on_off;
8621};
8622
8623static void
8624cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8625                        __rte_unused struct cmdline *cl,
8626                        __rte_unused void *data)
8627{
8628        struct cmd_set_xstats_hide_zero_result *res;
8629        uint16_t on_off = 0;
8630
8631        res = parsed_result;
8632        on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8633        set_xstats_hide_zero(on_off);
8634}
8635
8636cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8637        TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8638                                 keyword, "set");
8639cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8640        TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8641                                 name, "xstats-hide-zero");
8642cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8643        TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8644                                 on_off, "on#off");
8645
8646cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8647        .f = cmd_set_xstats_hide_zero_parsed,
8648        .data = NULL,
8649        .help_str = "set xstats-hide-zero on|off",
8650        .tokens = {
8651                (void *)&cmd_set_xstats_hide_zero_keyword,
8652                (void *)&cmd_set_xstats_hide_zero_name,
8653                (void *)&cmd_set_xstats_hide_zero_on_off,
8654                NULL,
8655        },
8656};
8657
8658/* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8659struct cmd_set_record_core_cycles_result {
8660        cmdline_fixed_string_t keyword;
8661        cmdline_fixed_string_t name;
8662        cmdline_fixed_string_t on_off;
8663};
8664
8665static void
8666cmd_set_record_core_cycles_parsed(void *parsed_result,
8667                        __rte_unused struct cmdline *cl,
8668                        __rte_unused void *data)
8669{
8670        struct cmd_set_record_core_cycles_result *res;
8671        uint16_t on_off = 0;
8672
8673        res = parsed_result;
8674        on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8675        set_record_core_cycles(on_off);
8676}
8677
8678cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8679        TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8680                                 keyword, "set");
8681cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8682        TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8683                                 name, "record-core-cycles");
8684cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8685        TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8686                                 on_off, "on#off");
8687
8688cmdline_parse_inst_t cmd_set_record_core_cycles = {
8689        .f = cmd_set_record_core_cycles_parsed,
8690        .data = NULL,
8691        .help_str = "set record-core-cycles on|off",
8692        .tokens = {
8693                (void *)&cmd_set_record_core_cycles_keyword,
8694                (void *)&cmd_set_record_core_cycles_name,
8695                (void *)&cmd_set_record_core_cycles_on_off,
8696                NULL,
8697        },
8698};
8699
8700/* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8701struct cmd_set_record_burst_stats_result {
8702        cmdline_fixed_string_t keyword;
8703        cmdline_fixed_string_t name;
8704        cmdline_fixed_string_t on_off;
8705};
8706
8707static void
8708cmd_set_record_burst_stats_parsed(void *parsed_result,
8709                        __rte_unused struct cmdline *cl,
8710                        __rte_unused void *data)
8711{
8712        struct cmd_set_record_burst_stats_result *res;
8713        uint16_t on_off = 0;
8714
8715        res = parsed_result;
8716        on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8717        set_record_burst_stats(on_off);
8718}
8719
8720cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8721        TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8722                                 keyword, "set");
8723cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8724        TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8725                                 name, "record-burst-stats");
8726cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8727        TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8728                                 on_off, "on#off");
8729
8730cmdline_parse_inst_t cmd_set_record_burst_stats = {
8731        .f = cmd_set_record_burst_stats_parsed,
8732        .data = NULL,
8733        .help_str = "set record-burst-stats on|off",
8734        .tokens = {
8735                (void *)&cmd_set_record_burst_stats_keyword,
8736                (void *)&cmd_set_record_burst_stats_name,
8737                (void *)&cmd_set_record_burst_stats_on_off,
8738                NULL,
8739        },
8740};
8741
8742/* *** CONFIGURE UNICAST HASH TABLE *** */
8743struct cmd_set_uc_hash_table {
8744        cmdline_fixed_string_t set;
8745        cmdline_fixed_string_t port;
8746        portid_t port_id;
8747        cmdline_fixed_string_t what;
8748        struct rte_ether_addr address;
8749        cmdline_fixed_string_t mode;
8750};
8751
8752static void
8753cmd_set_uc_hash_parsed(void *parsed_result,
8754                       __rte_unused struct cmdline *cl,
8755                       __rte_unused void *data)
8756{
8757        int ret=0;
8758        struct cmd_set_uc_hash_table *res = parsed_result;
8759
8760        int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8761
8762        if (strcmp(res->what, "uta") == 0)
8763                ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8764                                                &res->address,(uint8_t)is_on);
8765        if (ret < 0)
8766                fprintf(stderr,
8767                        "bad unicast hash table parameter, return code = %d\n",
8768                        ret);
8769
8770}
8771
8772cmdline_parse_token_string_t cmd_set_uc_hash_set =
8773        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8774                                 set, "set");
8775cmdline_parse_token_string_t cmd_set_uc_hash_port =
8776        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8777                                 port, "port");
8778cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8779        TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8780                              port_id, RTE_UINT16);
8781cmdline_parse_token_string_t cmd_set_uc_hash_what =
8782        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8783                                 what, "uta");
8784cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8785        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8786                                address);
8787cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8788        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8789                                 mode, "on#off");
8790
8791cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8792        .f = cmd_set_uc_hash_parsed,
8793        .data = NULL,
8794        .help_str = "set port <port_id> uta <mac_addr> on|off)",
8795        .tokens = {
8796                (void *)&cmd_set_uc_hash_set,
8797                (void *)&cmd_set_uc_hash_port,
8798                (void *)&cmd_set_uc_hash_portid,
8799                (void *)&cmd_set_uc_hash_what,
8800                (void *)&cmd_set_uc_hash_mac,
8801                (void *)&cmd_set_uc_hash_mode,
8802                NULL,
8803        },
8804};
8805
8806struct cmd_set_uc_all_hash_table {
8807        cmdline_fixed_string_t set;
8808        cmdline_fixed_string_t port;
8809        portid_t port_id;
8810        cmdline_fixed_string_t what;
8811        cmdline_fixed_string_t value;
8812        cmdline_fixed_string_t mode;
8813};
8814
8815static void
8816cmd_set_uc_all_hash_parsed(void *parsed_result,
8817                       __rte_unused struct cmdline *cl,
8818                       __rte_unused void *data)
8819{
8820        int ret=0;
8821        struct cmd_set_uc_all_hash_table *res = parsed_result;
8822
8823        int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8824
8825        if ((strcmp(res->what, "uta") == 0) &&
8826                (strcmp(res->value, "all") == 0))
8827                ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8828        if (ret < 0)
8829                fprintf(stderr,
8830                        "bad unicast hash table parameter, return code = %d\n",
8831                        ret);
8832}
8833
8834cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8835        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8836                                 set, "set");
8837cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8838        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8839                                 port, "port");
8840cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8841        TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8842                              port_id, RTE_UINT16);
8843cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8844        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8845                                 what, "uta");
8846cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8847        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8848                                value,"all");
8849cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8850        TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8851                                 mode, "on#off");
8852
8853cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8854        .f = cmd_set_uc_all_hash_parsed,
8855        .data = NULL,
8856        .help_str = "set port <port_id> uta all on|off",
8857        .tokens = {
8858                (void *)&cmd_set_uc_all_hash_set,
8859                (void *)&cmd_set_uc_all_hash_port,
8860                (void *)&cmd_set_uc_all_hash_portid,
8861                (void *)&cmd_set_uc_all_hash_what,
8862                (void *)&cmd_set_uc_all_hash_value,
8863                (void *)&cmd_set_uc_all_hash_mode,
8864                NULL,
8865        },
8866};
8867
8868/* *** CONFIGURE VF TRAFFIC CONTROL *** */
8869struct cmd_set_vf_traffic {
8870        cmdline_fixed_string_t set;
8871        cmdline_fixed_string_t port;
8872        portid_t port_id;
8873        cmdline_fixed_string_t vf;
8874        uint8_t vf_id;
8875        cmdline_fixed_string_t what;
8876        cmdline_fixed_string_t mode;
8877};
8878
8879static void
8880cmd_set_vf_traffic_parsed(void *parsed_result,
8881                       __rte_unused struct cmdline *cl,
8882                       __rte_unused void *data)
8883{
8884        struct cmd_set_vf_traffic *res = parsed_result;
8885        int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8886        int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8887
8888        set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8889}
8890
8891cmdline_parse_token_string_t cmd_setvf_traffic_set =
8892        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8893                                 set, "set");
8894cmdline_parse_token_string_t cmd_setvf_traffic_port =
8895        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8896                                 port, "port");
8897cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8898        TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8899                              port_id, RTE_UINT16);
8900cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8901        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8902                                 vf, "vf");
8903cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8904        TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8905                              vf_id, RTE_UINT8);
8906cmdline_parse_token_string_t cmd_setvf_traffic_what =
8907        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8908                                 what, "tx#rx");
8909cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8910        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8911                                 mode, "on#off");
8912
8913cmdline_parse_inst_t cmd_set_vf_traffic = {
8914        .f = cmd_set_vf_traffic_parsed,
8915        .data = NULL,
8916        .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8917        .tokens = {
8918                (void *)&cmd_setvf_traffic_set,
8919                (void *)&cmd_setvf_traffic_port,
8920                (void *)&cmd_setvf_traffic_portid,
8921                (void *)&cmd_setvf_traffic_vf,
8922                (void *)&cmd_setvf_traffic_vfid,
8923                (void *)&cmd_setvf_traffic_what,
8924                (void *)&cmd_setvf_traffic_mode,
8925                NULL,
8926        },
8927};
8928
8929/* *** CONFIGURE VF RECEIVE MODE *** */
8930struct cmd_set_vf_rxmode {
8931        cmdline_fixed_string_t set;
8932        cmdline_fixed_string_t port;
8933        portid_t port_id;
8934        cmdline_fixed_string_t vf;
8935        uint8_t vf_id;
8936        cmdline_fixed_string_t what;
8937        cmdline_fixed_string_t mode;
8938        cmdline_fixed_string_t on;
8939};
8940
8941static void
8942cmd_set_vf_rxmode_parsed(void *parsed_result,
8943                       __rte_unused struct cmdline *cl,
8944                       __rte_unused void *data)
8945{
8946        int ret = -ENOTSUP;
8947        uint16_t vf_rxmode = 0;
8948        struct cmd_set_vf_rxmode *res = parsed_result;
8949
8950        int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8951        if (!strcmp(res->what,"rxmode")) {
8952                if (!strcmp(res->mode, "AUPE"))
8953                        vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8954                else if (!strcmp(res->mode, "ROPE"))
8955                        vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8956                else if (!strcmp(res->mode, "BAM"))
8957                        vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8958                else if (!strncmp(res->mode, "MPE",3))
8959                        vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8960        }
8961
8962        RTE_SET_USED(is_on);
8963
8964#ifdef RTE_NET_IXGBE
8965        if (ret == -ENOTSUP)
8966                ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8967                                                  vf_rxmode, (uint8_t)is_on);
8968#endif
8969#ifdef RTE_NET_BNXT
8970        if (ret == -ENOTSUP)
8971                ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8972                                                 vf_rxmode, (uint8_t)is_on);
8973#endif
8974        if (ret < 0)
8975                fprintf(stderr,
8976                        "bad VF receive mode parameter, return code = %d\n",
8977                        ret);
8978}
8979
8980cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8981        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8982                                 set, "set");
8983cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8984        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8985                                 port, "port");
8986cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8987        TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8988                              port_id, RTE_UINT16);
8989cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8990        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8991                                 vf, "vf");
8992cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8993        TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8994                              vf_id, RTE_UINT8);
8995cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8996        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8997                                 what, "rxmode");
8998cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8999        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9000                                 mode, "AUPE#ROPE#BAM#MPE");
9001cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9002        TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9003                                 on, "on#off");
9004
9005cmdline_parse_inst_t cmd_set_vf_rxmode = {
9006        .f = cmd_set_vf_rxmode_parsed,
9007        .data = NULL,
9008        .help_str = "set port <port_id> vf <vf_id> rxmode "
9009                "AUPE|ROPE|BAM|MPE on|off",
9010        .tokens = {
9011                (void *)&cmd_set_vf_rxmode_set,
9012                (void *)&cmd_set_vf_rxmode_port,
9013                (void *)&cmd_set_vf_rxmode_portid,
9014                (void *)&cmd_set_vf_rxmode_vf,
9015                (void *)&cmd_set_vf_rxmode_vfid,
9016                (void *)&cmd_set_vf_rxmode_what,
9017                (void *)&cmd_set_vf_rxmode_mode,
9018                (void *)&cmd_set_vf_rxmode_on,
9019                NULL,
9020        },
9021};
9022
9023/* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9024struct cmd_vf_mac_addr_result {
9025        cmdline_fixed_string_t mac_addr_cmd;
9026        cmdline_fixed_string_t what;
9027        cmdline_fixed_string_t port;
9028        uint16_t port_num;
9029        cmdline_fixed_string_t vf;
9030        uint8_t vf_num;
9031        struct rte_ether_addr address;
9032};
9033
9034static void cmd_vf_mac_addr_parsed(void *parsed_result,
9035                __rte_unused struct cmdline *cl,
9036                __rte_unused void *data)
9037{
9038        struct cmd_vf_mac_addr_result *res = parsed_result;
9039        int ret = -ENOTSUP;
9040
9041        if (strcmp(res->what, "add") != 0)
9042                return;
9043
9044#ifdef RTE_NET_I40E
9045        if (ret == -ENOTSUP)
9046                ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9047                                                   &res->address);
9048#endif
9049#ifdef RTE_NET_BNXT
9050        if (ret == -ENOTSUP)
9051                ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9052                                                res->vf_num);
9053#endif
9054
9055        if(ret < 0)
9056                fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9057
9058}
9059
9060cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9061        TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9062                                mac_addr_cmd,"mac_addr");
9063cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9064        TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9065                                what,"add");
9066cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9067        TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9068                                port,"port");
9069cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9070        TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9071                                port_num, RTE_UINT16);
9072cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9073        TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9074                                vf,"vf");
9075cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9076        TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9077                                vf_num, RTE_UINT8);
9078cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9079        TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9080                                address);
9081
9082cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9083        .f = cmd_vf_mac_addr_parsed,
9084        .data = (void *)0,
9085        .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9086                "Add MAC address filtering for a VF on port_id",
9087        .tokens = {
9088                (void *)&cmd_vf_mac_addr_cmd,
9089                (void *)&cmd_vf_mac_addr_what,
9090                (void *)&cmd_vf_mac_addr_port,
9091                (void *)&cmd_vf_mac_addr_portnum,
9092                (void *)&cmd_vf_mac_addr_vf,
9093                (void *)&cmd_vf_mac_addr_vfnum,
9094                (void *)&cmd_vf_mac_addr_addr,
9095                NULL,
9096        },
9097};
9098
9099/* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9100struct cmd_vf_rx_vlan_filter {
9101        cmdline_fixed_string_t rx_vlan;
9102        cmdline_fixed_string_t what;
9103        uint16_t vlan_id;
9104        cmdline_fixed_string_t port;
9105        portid_t port_id;
9106        cmdline_fixed_string_t vf;
9107        uint64_t vf_mask;
9108};
9109
9110static void
9111cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9112                          __rte_unused struct cmdline *cl,
9113                          __rte_unused void *data)
9114{
9115        struct cmd_vf_rx_vlan_filter *res = parsed_result;
9116        int ret = -ENOTSUP;
9117
9118        __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9119
9120#ifdef RTE_NET_IXGBE
9121        if (ret == -ENOTSUP)
9122                ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9123                                res->vlan_id, res->vf_mask, is_add);
9124#endif
9125#ifdef RTE_NET_I40E
9126        if (ret == -ENOTSUP)
9127                ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9128                                res->vlan_id, res->vf_mask, is_add);
9129#endif
9130#ifdef RTE_NET_BNXT
9131        if (ret == -ENOTSUP)
9132                ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9133                                res->vlan_id, res->vf_mask, is_add);
9134#endif
9135
9136        switch (ret) {
9137        case 0:
9138                break;
9139        case -EINVAL:
9140                fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9141                        res->vlan_id, res->vf_mask);
9142                break;
9143        case -ENODEV:
9144                fprintf(stderr, "invalid port_id %d\n", res->port_id);
9145                break;
9146        case -ENOTSUP:
9147                fprintf(stderr, "function not implemented or supported\n");
9148                break;
9149        default:
9150                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9151        }
9152}
9153
9154cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9155        TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9156                                 rx_vlan, "rx_vlan");
9157cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9158        TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9159                                 what, "add#rm");
9160cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9161        TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9162                              vlan_id, RTE_UINT16);
9163cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9164        TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9165                                 port, "port");
9166cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9167        TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9168                              port_id, RTE_UINT16);
9169cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9170        TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9171                                 vf, "vf");
9172cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9173        TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9174                              vf_mask, RTE_UINT64);
9175
9176cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9177        .f = cmd_vf_rx_vlan_filter_parsed,
9178        .data = NULL,
9179        .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9180                "(vf_mask = hexadecimal VF mask)",
9181        .tokens = {
9182                (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9183                (void *)&cmd_vf_rx_vlan_filter_what,
9184                (void *)&cmd_vf_rx_vlan_filter_vlanid,
9185                (void *)&cmd_vf_rx_vlan_filter_port,
9186                (void *)&cmd_vf_rx_vlan_filter_portid,
9187                (void *)&cmd_vf_rx_vlan_filter_vf,
9188                (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9189                NULL,
9190        },
9191};
9192
9193/* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9194struct cmd_queue_rate_limit_result {
9195        cmdline_fixed_string_t set;
9196        cmdline_fixed_string_t port;
9197        uint16_t port_num;
9198        cmdline_fixed_string_t queue;
9199        uint8_t queue_num;
9200        cmdline_fixed_string_t rate;
9201        uint16_t rate_num;
9202};
9203
9204static void cmd_queue_rate_limit_parsed(void *parsed_result,
9205                __rte_unused struct cmdline *cl,
9206                __rte_unused void *data)
9207{
9208        struct cmd_queue_rate_limit_result *res = parsed_result;
9209        int ret = 0;
9210
9211        if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9212                && (strcmp(res->queue, "queue") == 0)
9213                && (strcmp(res->rate, "rate") == 0))
9214                ret = set_queue_rate_limit(res->port_num, res->queue_num,
9215                                        res->rate_num);
9216        if (ret < 0)
9217                fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9218                        strerror(-ret));
9219
9220}
9221
9222cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9223        TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9224                                set, "set");
9225cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9226        TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9227                                port, "port");
9228cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9229        TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9230                                port_num, RTE_UINT16);
9231cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9232        TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9233                                queue, "queue");
9234cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9235        TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9236                                queue_num, RTE_UINT8);
9237cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9238        TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9239                                rate, "rate");
9240cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9241        TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9242                                rate_num, RTE_UINT16);
9243
9244cmdline_parse_inst_t cmd_queue_rate_limit = {
9245        .f = cmd_queue_rate_limit_parsed,
9246        .data = (void *)0,
9247        .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9248                "Set rate limit for a queue on port_id",
9249        .tokens = {
9250                (void *)&cmd_queue_rate_limit_set,
9251                (void *)&cmd_queue_rate_limit_port,
9252                (void *)&cmd_queue_rate_limit_portnum,
9253                (void *)&cmd_queue_rate_limit_queue,
9254                (void *)&cmd_queue_rate_limit_queuenum,
9255                (void *)&cmd_queue_rate_limit_rate,
9256                (void *)&cmd_queue_rate_limit_ratenum,
9257                NULL,
9258        },
9259};
9260
9261/* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9262struct cmd_vf_rate_limit_result {
9263        cmdline_fixed_string_t set;
9264        cmdline_fixed_string_t port;
9265        uint16_t port_num;
9266        cmdline_fixed_string_t vf;
9267        uint8_t vf_num;
9268        cmdline_fixed_string_t rate;
9269        uint16_t rate_num;
9270        cmdline_fixed_string_t q_msk;
9271        uint64_t q_msk_val;
9272};
9273
9274static void cmd_vf_rate_limit_parsed(void *parsed_result,
9275                __rte_unused struct cmdline *cl,
9276                __rte_unused void *data)
9277{
9278        struct cmd_vf_rate_limit_result *res = parsed_result;
9279        int ret = 0;
9280
9281        if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9282                && (strcmp(res->vf, "vf") == 0)
9283                && (strcmp(res->rate, "rate") == 0)
9284                && (strcmp(res->q_msk, "queue_mask") == 0))
9285                ret = set_vf_rate_limit(res->port_num, res->vf_num,
9286                                        res->rate_num, res->q_msk_val);
9287        if (ret < 0)
9288                fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9289                        strerror(-ret));
9290
9291}
9292
9293cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9294        TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9295                                set, "set");
9296cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9297        TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9298                                port, "port");
9299cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9300        TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9301                                port_num, RTE_UINT16);
9302cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9303        TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9304                                vf, "vf");
9305cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9306        TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9307                                vf_num, RTE_UINT8);
9308cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9309        TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9310                                rate, "rate");
9311cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9312        TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9313                                rate_num, RTE_UINT16);
9314cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9315        TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9316                                q_msk, "queue_mask");
9317cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9318        TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9319                                q_msk_val, RTE_UINT64);
9320
9321cmdline_parse_inst_t cmd_vf_rate_limit = {
9322        .f = cmd_vf_rate_limit_parsed,
9323        .data = (void *)0,
9324        .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9325                "queue_mask <queue_mask_value>: "
9326                "Set rate limit for queues of VF on port_id",
9327        .tokens = {
9328                (void *)&cmd_vf_rate_limit_set,
9329                (void *)&cmd_vf_rate_limit_port,
9330                (void *)&cmd_vf_rate_limit_portnum,
9331                (void *)&cmd_vf_rate_limit_vf,
9332                (void *)&cmd_vf_rate_limit_vfnum,
9333                (void *)&cmd_vf_rate_limit_rate,
9334                (void *)&cmd_vf_rate_limit_ratenum,
9335                (void *)&cmd_vf_rate_limit_q_msk,
9336                (void *)&cmd_vf_rate_limit_q_msk_val,
9337                NULL,
9338        },
9339};
9340
9341/* *** CONFIGURE TUNNEL UDP PORT *** */
9342struct cmd_tunnel_udp_config {
9343        cmdline_fixed_string_t rx_vxlan_port;
9344        cmdline_fixed_string_t what;
9345        uint16_t udp_port;
9346        portid_t port_id;
9347};
9348
9349static void
9350cmd_tunnel_udp_config_parsed(void *parsed_result,
9351                          __rte_unused struct cmdline *cl,
9352                          __rte_unused void *data)
9353{
9354        struct cmd_tunnel_udp_config *res = parsed_result;
9355        struct rte_eth_udp_tunnel tunnel_udp;
9356        int ret;
9357
9358        tunnel_udp.udp_port = res->udp_port;
9359        tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9360
9361        if (!strcmp(res->what, "add"))
9362                ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9363                                                      &tunnel_udp);
9364        else
9365                ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9366                                                         &tunnel_udp);
9367
9368        if (ret < 0)
9369                fprintf(stderr, "udp tunneling add error: (%s)\n",
9370                        strerror(-ret));
9371}
9372
9373cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9374        TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9375                                rx_vxlan_port, "rx_vxlan_port");
9376cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9377        TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9378                                what, "add#rm");
9379cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9380        TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9381                                udp_port, RTE_UINT16);
9382cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9383        TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9384                                port_id, RTE_UINT16);
9385
9386cmdline_parse_inst_t cmd_tunnel_udp_config = {
9387        .f = cmd_tunnel_udp_config_parsed,
9388        .data = (void *)0,
9389        .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9390                "Add/Remove a tunneling UDP port filter",
9391        .tokens = {
9392                (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9393                (void *)&cmd_tunnel_udp_config_what,
9394                (void *)&cmd_tunnel_udp_config_udp_port,
9395                (void *)&cmd_tunnel_udp_config_port_id,
9396                NULL,
9397        },
9398};
9399
9400struct cmd_config_tunnel_udp_port {
9401        cmdline_fixed_string_t port;
9402        cmdline_fixed_string_t config;
9403        portid_t port_id;
9404        cmdline_fixed_string_t udp_tunnel_port;
9405        cmdline_fixed_string_t action;
9406        cmdline_fixed_string_t tunnel_type;
9407        uint16_t udp_port;
9408};
9409
9410static void
9411cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9412                               __rte_unused struct cmdline *cl,
9413                               __rte_unused void *data)
9414{
9415        struct cmd_config_tunnel_udp_port *res = parsed_result;
9416        struct rte_eth_udp_tunnel tunnel_udp;
9417        int ret = 0;
9418
9419        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9420                return;
9421
9422        tunnel_udp.udp_port = res->udp_port;
9423
9424        if (!strcmp(res->tunnel_type, "vxlan")) {
9425                tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9426        } else if (!strcmp(res->tunnel_type, "geneve")) {
9427                tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9428        } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9429                tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9430        } else if (!strcmp(res->tunnel_type, "ecpri")) {
9431                tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9432        } else {
9433                fprintf(stderr, "Invalid tunnel type\n");
9434                return;
9435        }
9436
9437        if (!strcmp(res->action, "add"))
9438                ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9439                                                      &tunnel_udp);
9440        else
9441                ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9442                                                         &tunnel_udp);
9443
9444        if (ret < 0)
9445                fprintf(stderr, "udp tunneling port add error: (%s)\n",
9446                        strerror(-ret));
9447}
9448
9449cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9450        TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9451                                 "port");
9452cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9453        TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9454                                 "config");
9455cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9456        TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9457                              RTE_UINT16);
9458cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9459        TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9460                                 udp_tunnel_port,
9461                                 "udp_tunnel_port");
9462cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9463        TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9464                                 "add#rm");
9465cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9466        TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9467                                 "vxlan#geneve#vxlan-gpe#ecpri");
9468cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9469        TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9470                              RTE_UINT16);
9471
9472cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9473        .f = cmd_cfg_tunnel_udp_port_parsed,
9474        .data = NULL,
9475        .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9476                "geneve|vxlan-gpe|ecpri <udp_port>",
9477        .tokens = {
9478                (void *)&cmd_config_tunnel_udp_port_port,
9479                (void *)&cmd_config_tunnel_udp_port_config,
9480                (void *)&cmd_config_tunnel_udp_port_port_id,
9481                (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9482                (void *)&cmd_config_tunnel_udp_port_action,
9483                (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9484                (void *)&cmd_config_tunnel_udp_port_value,
9485                NULL,
9486        },
9487};
9488
9489/* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9490struct cmd_set_mirror_mask_result {
9491        cmdline_fixed_string_t set;
9492        cmdline_fixed_string_t port;
9493        portid_t port_id;
9494        cmdline_fixed_string_t mirror;
9495        uint8_t rule_id;
9496        cmdline_fixed_string_t what;
9497        cmdline_fixed_string_t value;
9498        cmdline_fixed_string_t dstpool;
9499        uint8_t dstpool_id;
9500        cmdline_fixed_string_t on;
9501};
9502
9503cmdline_parse_token_string_t cmd_mirror_mask_set =
9504        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9505                                set, "set");
9506cmdline_parse_token_string_t cmd_mirror_mask_port =
9507        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9508                                port, "port");
9509cmdline_parse_token_num_t cmd_mirror_mask_portid =
9510        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9511                                port_id, RTE_UINT16);
9512cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9513        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9514                                mirror, "mirror-rule");
9515cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9516        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9517                                rule_id, RTE_UINT8);
9518cmdline_parse_token_string_t cmd_mirror_mask_what =
9519        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9520                                what, "pool-mirror-up#pool-mirror-down"
9521                                      "#vlan-mirror");
9522cmdline_parse_token_string_t cmd_mirror_mask_value =
9523        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9524                                value, NULL);
9525cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9526        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9527                                dstpool, "dst-pool");
9528cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9529        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9530                                dstpool_id, RTE_UINT8);
9531cmdline_parse_token_string_t cmd_mirror_mask_on =
9532        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9533                                on, "on#off");
9534
9535static void
9536cmd_set_mirror_mask_parsed(void *parsed_result,
9537                       __rte_unused struct cmdline *cl,
9538                       __rte_unused void *data)
9539{
9540        int ret,nb_item,i;
9541        struct cmd_set_mirror_mask_result *res = parsed_result;
9542        struct rte_eth_mirror_conf mr_conf;
9543
9544        memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9545
9546        unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9547
9548        mr_conf.dst_pool = res->dstpool_id;
9549
9550        if (!strcmp(res->what, "pool-mirror-up")) {
9551                mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9552                mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9553        } else if (!strcmp(res->what, "pool-mirror-down")) {
9554                mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9555                mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9556        } else if (!strcmp(res->what, "vlan-mirror")) {
9557                mr_conf.rule_type = ETH_MIRROR_VLAN;
9558                nb_item = parse_item_list(res->value, "vlan",
9559                                ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9560                if (nb_item <= 0)
9561                        return;
9562
9563                for (i = 0; i < nb_item; i++) {
9564                        if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9565                                fprintf(stderr,
9566                                        "Invalid vlan_id: must be < 4096\n");
9567                                return;
9568                        }
9569
9570                        mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9571                        mr_conf.vlan.vlan_mask |= 1ULL << i;
9572                }
9573        }
9574
9575        if (!strcmp(res->on, "on"))
9576                ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9577                                                res->rule_id, 1);
9578        else
9579                ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9580                                                res->rule_id, 0);
9581        if (ret < 0)
9582                fprintf(stderr, "mirror rule add error: (%s)\n",
9583                        strerror(-ret));
9584}
9585
9586cmdline_parse_inst_t cmd_set_mirror_mask = {
9587                .f = cmd_set_mirror_mask_parsed,
9588                .data = NULL,
9589                .help_str = "set port <port_id> mirror-rule <rule_id> "
9590                        "pool-mirror-up|pool-mirror-down|vlan-mirror "
9591                        "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9592                .tokens = {
9593                        (void *)&cmd_mirror_mask_set,
9594                        (void *)&cmd_mirror_mask_port,
9595                        (void *)&cmd_mirror_mask_portid,
9596                        (void *)&cmd_mirror_mask_mirror,
9597                        (void *)&cmd_mirror_mask_ruleid,
9598                        (void *)&cmd_mirror_mask_what,
9599                        (void *)&cmd_mirror_mask_value,
9600                        (void *)&cmd_mirror_mask_dstpool,
9601                        (void *)&cmd_mirror_mask_poolid,
9602                        (void *)&cmd_mirror_mask_on,
9603                        NULL,
9604                },
9605};
9606
9607/* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9608struct cmd_set_mirror_link_result {
9609        cmdline_fixed_string_t set;
9610        cmdline_fixed_string_t port;
9611        portid_t port_id;
9612        cmdline_fixed_string_t mirror;
9613        uint8_t rule_id;
9614        cmdline_fixed_string_t what;
9615        cmdline_fixed_string_t dstpool;
9616        uint8_t dstpool_id;
9617        cmdline_fixed_string_t on;
9618};
9619
9620cmdline_parse_token_string_t cmd_mirror_link_set =
9621        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9622                                 set, "set");
9623cmdline_parse_token_string_t cmd_mirror_link_port =
9624        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9625                                port, "port");
9626cmdline_parse_token_num_t cmd_mirror_link_portid =
9627        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9628                                port_id, RTE_UINT16);
9629cmdline_parse_token_string_t cmd_mirror_link_mirror =
9630        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9631                                mirror, "mirror-rule");
9632cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9633        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9634                            rule_id, RTE_UINT8);
9635cmdline_parse_token_string_t cmd_mirror_link_what =
9636        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9637                                what, "uplink-mirror#downlink-mirror");
9638cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9639        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9640                                dstpool, "dst-pool");
9641cmdline_parse_token_num_t cmd_mirror_link_poolid =
9642        TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9643                                dstpool_id, RTE_UINT8);
9644cmdline_parse_token_string_t cmd_mirror_link_on =
9645        TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9646                                on, "on#off");
9647
9648static void
9649cmd_set_mirror_link_parsed(void *parsed_result,
9650                       __rte_unused struct cmdline *cl,
9651                       __rte_unused void *data)
9652{
9653        int ret;
9654        struct cmd_set_mirror_link_result *res = parsed_result;
9655        struct rte_eth_mirror_conf mr_conf;
9656
9657        memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9658        if (!strcmp(res->what, "uplink-mirror"))
9659                mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9660        else
9661                mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9662
9663        mr_conf.dst_pool = res->dstpool_id;
9664
9665        if (!strcmp(res->on, "on"))
9666                ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9667                                                res->rule_id, 1);
9668        else
9669                ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9670                                                res->rule_id, 0);
9671
9672        /* check the return value and print it if is < 0 */
9673        if (ret < 0)
9674                fprintf(stderr, "mirror rule add error: (%s)\n",
9675                        strerror(-ret));
9676
9677}
9678
9679cmdline_parse_inst_t cmd_set_mirror_link = {
9680                .f = cmd_set_mirror_link_parsed,
9681                .data = NULL,
9682                .help_str = "set port <port_id> mirror-rule <rule_id> "
9683                        "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9684                .tokens = {
9685                        (void *)&cmd_mirror_link_set,
9686                        (void *)&cmd_mirror_link_port,
9687                        (void *)&cmd_mirror_link_portid,
9688                        (void *)&cmd_mirror_link_mirror,
9689                        (void *)&cmd_mirror_link_ruleid,
9690                        (void *)&cmd_mirror_link_what,
9691                        (void *)&cmd_mirror_link_dstpool,
9692                        (void *)&cmd_mirror_link_poolid,
9693                        (void *)&cmd_mirror_link_on,
9694                        NULL,
9695                },
9696};
9697
9698/* *** RESET VM MIRROR RULE *** */
9699struct cmd_rm_mirror_rule_result {
9700        cmdline_fixed_string_t reset;
9701        cmdline_fixed_string_t port;
9702        portid_t port_id;
9703        cmdline_fixed_string_t mirror;
9704        uint8_t rule_id;
9705};
9706
9707cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9708        TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9709                                 reset, "reset");
9710cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9711        TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9712                                port, "port");
9713cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9714        TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9715                                port_id, RTE_UINT16);
9716cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9717        TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9718                                mirror, "mirror-rule");
9719cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9720        TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9721                                rule_id, RTE_UINT8);
9722
9723static void
9724cmd_reset_mirror_rule_parsed(void *parsed_result,
9725                       __rte_unused struct cmdline *cl,
9726                       __rte_unused void *data)
9727{
9728        int ret;
9729        struct cmd_set_mirror_link_result *res = parsed_result;
9730        /* check rule_id */
9731        ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9732        if(ret < 0)
9733                fprintf(stderr, "mirror rule remove error: (%s)\n",
9734                        strerror(-ret));
9735}
9736
9737cmdline_parse_inst_t cmd_reset_mirror_rule = {
9738                .f = cmd_reset_mirror_rule_parsed,
9739                .data = NULL,
9740                .help_str = "reset port <port_id> mirror-rule <rule_id>",
9741                .tokens = {
9742                        (void *)&cmd_rm_mirror_rule_reset,
9743                        (void *)&cmd_rm_mirror_rule_port,
9744                        (void *)&cmd_rm_mirror_rule_portid,
9745                        (void *)&cmd_rm_mirror_rule_mirror,
9746                        (void *)&cmd_rm_mirror_rule_ruleid,
9747                        NULL,
9748                },
9749};
9750
9751/* ******************************************************************************** */
9752
9753struct cmd_dump_result {
9754        cmdline_fixed_string_t dump;
9755};
9756
9757static void
9758dump_struct_sizes(void)
9759{
9760#define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9761        DUMP_SIZE(struct rte_mbuf);
9762        DUMP_SIZE(struct rte_mempool);
9763        DUMP_SIZE(struct rte_ring);
9764#undef DUMP_SIZE
9765}
9766
9767
9768/* Dump the socket memory statistics on console */
9769static void
9770dump_socket_mem(FILE *f)
9771{
9772        struct rte_malloc_socket_stats socket_stats;
9773        unsigned int i;
9774        size_t total = 0;
9775        size_t alloc = 0;
9776        size_t free = 0;
9777        unsigned int n_alloc = 0;
9778        unsigned int n_free = 0;
9779        static size_t last_allocs;
9780        static size_t last_total;
9781
9782
9783        for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9784                if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9785                    !socket_stats.heap_totalsz_bytes)
9786                        continue;
9787                total += socket_stats.heap_totalsz_bytes;
9788                alloc += socket_stats.heap_allocsz_bytes;
9789                free += socket_stats.heap_freesz_bytes;
9790                n_alloc += socket_stats.alloc_count;
9791                n_free += socket_stats.free_count;
9792                fprintf(f,
9793                        "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9794                        i,
9795                        (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9796                        (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9797                        (double)socket_stats.heap_allocsz_bytes * 100 /
9798                        (double)socket_stats.heap_totalsz_bytes,
9799                        (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9800                        socket_stats.alloc_count,
9801                        socket_stats.free_count);
9802        }
9803        fprintf(f,
9804                "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9805                (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9806                total ? ((double)alloc * 100 / (double)total) : 0,
9807                (double)free / (1024 * 1024),
9808                n_alloc, n_free);
9809        if (last_allocs)
9810                fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9811                        ((double)total - (double)last_total) / (1024 * 1024),
9812                        (double)(alloc - (double)last_allocs) / 1024 / 1024);
9813        last_allocs = alloc;
9814        last_total = total;
9815}
9816
9817static void cmd_dump_parsed(void *parsed_result,
9818                            __rte_unused struct cmdline *cl,
9819                            __rte_unused void *data)
9820{
9821        struct cmd_dump_result *res = parsed_result;
9822
9823        if (!strcmp(res->dump, "dump_physmem"))
9824                rte_dump_physmem_layout(stdout);
9825        else if (!strcmp(res->dump, "dump_socket_mem"))
9826                dump_socket_mem(stdout);
9827        else if (!strcmp(res->dump, "dump_memzone"))
9828                rte_memzone_dump(stdout);
9829        else if (!strcmp(res->dump, "dump_struct_sizes"))
9830                dump_struct_sizes();
9831        else if (!strcmp(res->dump, "dump_ring"))
9832                rte_ring_list_dump(stdout);
9833        else if (!strcmp(res->dump, "dump_mempool"))
9834                rte_mempool_list_dump(stdout);
9835        else if (!strcmp(res->dump, "dump_devargs"))
9836                rte_devargs_dump(stdout);
9837        else if (!strcmp(res->dump, "dump_log_types"))
9838                rte_log_dump(stdout);
9839}
9840
9841cmdline_parse_token_string_t cmd_dump_dump =
9842        TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9843                "dump_physmem#"
9844                "dump_memzone#"
9845                "dump_socket_mem#"
9846                "dump_struct_sizes#"
9847                "dump_ring#"
9848                "dump_mempool#"
9849                "dump_devargs#"
9850                "dump_log_types");
9851
9852cmdline_parse_inst_t cmd_dump = {
9853        .f = cmd_dump_parsed,  /* function to call */
9854        .data = NULL,      /* 2nd arg of func */
9855        .help_str = "Dump status",
9856        .tokens = {        /* token list, NULL terminated */
9857                (void *)&cmd_dump_dump,
9858                NULL,
9859        },
9860};
9861
9862/* ******************************************************************************** */
9863
9864struct cmd_dump_one_result {
9865        cmdline_fixed_string_t dump;
9866        cmdline_fixed_string_t name;
9867};
9868
9869static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9870                                __rte_unused void *data)
9871{
9872        struct cmd_dump_one_result *res = parsed_result;
9873
9874        if (!strcmp(res->dump, "dump_ring")) {
9875                struct rte_ring *r;
9876                r = rte_ring_lookup(res->name);
9877                if (r == NULL) {
9878                        cmdline_printf(cl, "Cannot find ring\n");
9879                        return;
9880                }
9881                rte_ring_dump(stdout, r);
9882        } else if (!strcmp(res->dump, "dump_mempool")) {
9883                struct rte_mempool *mp;
9884                mp = rte_mempool_lookup(res->name);
9885                if (mp == NULL) {
9886                        cmdline_printf(cl, "Cannot find mempool\n");
9887                        return;
9888                }
9889                rte_mempool_dump(stdout, mp);
9890        }
9891}
9892
9893cmdline_parse_token_string_t cmd_dump_one_dump =
9894        TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9895                                 "dump_ring#dump_mempool");
9896
9897cmdline_parse_token_string_t cmd_dump_one_name =
9898        TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9899
9900cmdline_parse_inst_t cmd_dump_one = {
9901        .f = cmd_dump_one_parsed,  /* function to call */
9902        .data = NULL,      /* 2nd arg of func */
9903        .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9904        .tokens = {        /* token list, NULL terminated */
9905                (void *)&cmd_dump_one_dump,
9906                (void *)&cmd_dump_one_name,
9907                NULL,
9908        },
9909};
9910
9911/* *** queue region set *** */
9912struct cmd_queue_region_result {
9913        cmdline_fixed_string_t set;
9914        cmdline_fixed_string_t port;
9915        portid_t port_id;
9916        cmdline_fixed_string_t cmd;
9917        cmdline_fixed_string_t region;
9918        uint8_t  region_id;
9919        cmdline_fixed_string_t queue_start_index;
9920        uint8_t  queue_id;
9921        cmdline_fixed_string_t queue_num;
9922        uint8_t  queue_num_value;
9923};
9924
9925static void
9926cmd_queue_region_parsed(void *parsed_result,
9927                        __rte_unused struct cmdline *cl,
9928                        __rte_unused void *data)
9929{
9930        struct cmd_queue_region_result *res = parsed_result;
9931        int ret = -ENOTSUP;
9932#ifdef RTE_NET_I40E
9933        struct rte_pmd_i40e_queue_region_conf region_conf;
9934        enum rte_pmd_i40e_queue_region_op op_type;
9935#endif
9936
9937        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9938                return;
9939
9940#ifdef RTE_NET_I40E
9941        memset(&region_conf, 0, sizeof(region_conf));
9942        op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9943        region_conf.region_id = res->region_id;
9944        region_conf.queue_num = res->queue_num_value;
9945        region_conf.queue_start_index = res->queue_id;
9946
9947        ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9948                                op_type, &region_conf);
9949#endif
9950
9951        switch (ret) {
9952        case 0:
9953                break;
9954        case -ENOTSUP:
9955                fprintf(stderr, "function not implemented or supported\n");
9956                break;
9957        default:
9958                fprintf(stderr, "queue region config error: (%s)\n",
9959                        strerror(-ret));
9960        }
9961}
9962
9963cmdline_parse_token_string_t cmd_queue_region_set =
9964TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9965                set, "set");
9966cmdline_parse_token_string_t cmd_queue_region_port =
9967        TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9968cmdline_parse_token_num_t cmd_queue_region_port_id =
9969        TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9970                                port_id, RTE_UINT16);
9971cmdline_parse_token_string_t cmd_queue_region_cmd =
9972        TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9973                                 cmd, "queue-region");
9974cmdline_parse_token_string_t cmd_queue_region_id =
9975        TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9976                                region, "region_id");
9977cmdline_parse_token_num_t cmd_queue_region_index =
9978        TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9979                                region_id, RTE_UINT8);
9980cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9981        TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9982                                queue_start_index, "queue_start_index");
9983cmdline_parse_token_num_t cmd_queue_region_queue_id =
9984        TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9985                                queue_id, RTE_UINT8);
9986cmdline_parse_token_string_t cmd_queue_region_queue_num =
9987        TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9988                                queue_num, "queue_num");
9989cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9990        TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9991                                queue_num_value, RTE_UINT8);
9992
9993cmdline_parse_inst_t cmd_queue_region = {
9994        .f = cmd_queue_region_parsed,
9995        .data = NULL,
9996        .help_str = "set port <port_id> queue-region region_id <value> "
9997                "queue_start_index <value> queue_num <value>: Set a queue region",
9998        .tokens = {
9999                (void *)&cmd_queue_region_set,
10000                (void *)&cmd_queue_region_port,
10001                (void *)&cmd_queue_region_port_id,
10002                (void *)&cmd_queue_region_cmd,
10003                (void *)&cmd_queue_region_id,
10004                (void *)&cmd_queue_region_index,
10005                (void *)&cmd_queue_region_queue_start_index,
10006                (void *)&cmd_queue_region_queue_id,
10007                (void *)&cmd_queue_region_queue_num,
10008                (void *)&cmd_queue_region_queue_num_value,
10009                NULL,
10010        },
10011};
10012
10013/* *** queue region and flowtype set *** */
10014struct cmd_region_flowtype_result {
10015        cmdline_fixed_string_t set;
10016        cmdline_fixed_string_t port;
10017        portid_t port_id;
10018        cmdline_fixed_string_t cmd;
10019        cmdline_fixed_string_t region;
10020        uint8_t  region_id;
10021        cmdline_fixed_string_t flowtype;
10022        uint8_t  flowtype_id;
10023};
10024
10025static void
10026cmd_region_flowtype_parsed(void *parsed_result,
10027                        __rte_unused struct cmdline *cl,
10028                        __rte_unused void *data)
10029{
10030        struct cmd_region_flowtype_result *res = parsed_result;
10031        int ret = -ENOTSUP;
10032#ifdef RTE_NET_I40E
10033        struct rte_pmd_i40e_queue_region_conf region_conf;
10034        enum rte_pmd_i40e_queue_region_op op_type;
10035#endif
10036
10037        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10038                return;
10039
10040#ifdef RTE_NET_I40E
10041        memset(&region_conf, 0, sizeof(region_conf));
10042
10043        op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10044        region_conf.region_id = res->region_id;
10045        region_conf.hw_flowtype = res->flowtype_id;
10046
10047        ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10048                        op_type, &region_conf);
10049#endif
10050
10051        switch (ret) {
10052        case 0:
10053                break;
10054        case -ENOTSUP:
10055                fprintf(stderr, "function not implemented or supported\n");
10056                break;
10057        default:
10058                fprintf(stderr, "region flowtype config error: (%s)\n",
10059                        strerror(-ret));
10060        }
10061}
10062
10063cmdline_parse_token_string_t cmd_region_flowtype_set =
10064TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10065                                set, "set");
10066cmdline_parse_token_string_t cmd_region_flowtype_port =
10067        TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10068                                port, "port");
10069cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10070        TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10071                                port_id, RTE_UINT16);
10072cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10073        TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10074                                cmd, "queue-region");
10075cmdline_parse_token_string_t cmd_region_flowtype_index =
10076        TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10077                                region, "region_id");
10078cmdline_parse_token_num_t cmd_region_flowtype_id =
10079        TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10080                                region_id, RTE_UINT8);
10081cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10082        TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10083                                flowtype, "flowtype");
10084cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10085        TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10086                                flowtype_id, RTE_UINT8);
10087cmdline_parse_inst_t cmd_region_flowtype = {
10088        .f = cmd_region_flowtype_parsed,
10089        .data = NULL,
10090        .help_str = "set port <port_id> queue-region region_id <value> "
10091                "flowtype <value>: Set a flowtype region index",
10092        .tokens = {
10093                (void *)&cmd_region_flowtype_set,
10094                (void *)&cmd_region_flowtype_port,
10095                (void *)&cmd_region_flowtype_port_index,
10096                (void *)&cmd_region_flowtype_cmd,
10097                (void *)&cmd_region_flowtype_index,
10098                (void *)&cmd_region_flowtype_id,
10099                (void *)&cmd_region_flowtype_flow_index,
10100                (void *)&cmd_region_flowtype_flow_id,
10101                NULL,
10102        },
10103};
10104
10105/* *** User Priority (UP) to queue region (region_id) set *** */
10106struct cmd_user_priority_region_result {
10107        cmdline_fixed_string_t set;
10108        cmdline_fixed_string_t port;
10109        portid_t port_id;
10110        cmdline_fixed_string_t cmd;
10111        cmdline_fixed_string_t user_priority;
10112        uint8_t  user_priority_id;
10113        cmdline_fixed_string_t region;
10114        uint8_t  region_id;
10115};
10116
10117static void
10118cmd_user_priority_region_parsed(void *parsed_result,
10119                        __rte_unused struct cmdline *cl,
10120                        __rte_unused void *data)
10121{
10122        struct cmd_user_priority_region_result *res = parsed_result;
10123        int ret = -ENOTSUP;
10124#ifdef RTE_NET_I40E
10125        struct rte_pmd_i40e_queue_region_conf region_conf;
10126        enum rte_pmd_i40e_queue_region_op op_type;
10127#endif
10128
10129        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10130                return;
10131
10132#ifdef RTE_NET_I40E
10133        memset(&region_conf, 0, sizeof(region_conf));
10134        op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10135        region_conf.user_priority = res->user_priority_id;
10136        region_conf.region_id = res->region_id;
10137
10138        ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10139                                op_type, &region_conf);
10140#endif
10141
10142        switch (ret) {
10143        case 0:
10144                break;
10145        case -ENOTSUP:
10146                fprintf(stderr, "function not implemented or supported\n");
10147                break;
10148        default:
10149                fprintf(stderr, "user_priority region config error: (%s)\n",
10150                        strerror(-ret));
10151        }
10152}
10153
10154cmdline_parse_token_string_t cmd_user_priority_region_set =
10155        TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10156                                set, "set");
10157cmdline_parse_token_string_t cmd_user_priority_region_port =
10158        TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10159                                port, "port");
10160cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10161        TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10162                                port_id, RTE_UINT16);
10163cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10164        TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10165                                cmd, "queue-region");
10166cmdline_parse_token_string_t cmd_user_priority_region_UP =
10167        TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10168                                user_priority, "UP");
10169cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10170        TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10171                                user_priority_id, RTE_UINT8);
10172cmdline_parse_token_string_t cmd_user_priority_region_region =
10173        TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10174                                region, "region_id");
10175cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10176        TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10177                                region_id, RTE_UINT8);
10178
10179cmdline_parse_inst_t cmd_user_priority_region = {
10180        .f = cmd_user_priority_region_parsed,
10181        .data = NULL,
10182        .help_str = "set port <port_id> queue-region UP <value> "
10183                "region_id <value>: Set the mapping of User Priority (UP) "
10184                "to queue region (region_id) ",
10185        .tokens = {
10186                (void *)&cmd_user_priority_region_set,
10187                (void *)&cmd_user_priority_region_port,
10188                (void *)&cmd_user_priority_region_port_index,
10189                (void *)&cmd_user_priority_region_cmd,
10190                (void *)&cmd_user_priority_region_UP,
10191                (void *)&cmd_user_priority_region_UP_id,
10192                (void *)&cmd_user_priority_region_region,
10193                (void *)&cmd_user_priority_region_region_id,
10194                NULL,
10195        },
10196};
10197
10198/* *** flush all queue region related configuration *** */
10199struct cmd_flush_queue_region_result {
10200        cmdline_fixed_string_t set;
10201        cmdline_fixed_string_t port;
10202        portid_t port_id;
10203        cmdline_fixed_string_t cmd;
10204        cmdline_fixed_string_t flush;
10205        cmdline_fixed_string_t what;
10206};
10207
10208static void
10209cmd_flush_queue_region_parsed(void *parsed_result,
10210                        __rte_unused struct cmdline *cl,
10211                        __rte_unused void *data)
10212{
10213        struct cmd_flush_queue_region_result *res = parsed_result;
10214        int ret = -ENOTSUP;
10215#ifdef RTE_NET_I40E
10216        struct rte_pmd_i40e_queue_region_conf region_conf;
10217        enum rte_pmd_i40e_queue_region_op op_type;
10218#endif
10219
10220        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10221                return;
10222
10223#ifdef RTE_NET_I40E
10224        memset(&region_conf, 0, sizeof(region_conf));
10225
10226        if (strcmp(res->what, "on") == 0)
10227                op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10228        else
10229                op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10230
10231        ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10232                                op_type, &region_conf);
10233#endif
10234
10235        switch (ret) {
10236        case 0:
10237                break;
10238        case -ENOTSUP:
10239                fprintf(stderr, "function not implemented or supported\n");
10240                break;
10241        default:
10242                fprintf(stderr, "queue region config flush error: (%s)\n",
10243                        strerror(-ret));
10244        }
10245}
10246
10247cmdline_parse_token_string_t cmd_flush_queue_region_set =
10248        TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10249                                set, "set");
10250cmdline_parse_token_string_t cmd_flush_queue_region_port =
10251        TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10252                                port, "port");
10253cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10254        TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10255                                port_id, RTE_UINT16);
10256cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10257        TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10258                                cmd, "queue-region");
10259cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10260        TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10261                                flush, "flush");
10262cmdline_parse_token_string_t cmd_flush_queue_region_what =
10263        TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10264                                what, "on#off");
10265
10266cmdline_parse_inst_t cmd_flush_queue_region = {
10267        .f = cmd_flush_queue_region_parsed,
10268        .data = NULL,
10269        .help_str = "set port <port_id> queue-region flush on|off"
10270                ": flush all queue region related configuration",
10271        .tokens = {
10272                (void *)&cmd_flush_queue_region_set,
10273                (void *)&cmd_flush_queue_region_port,
10274                (void *)&cmd_flush_queue_region_port_index,
10275                (void *)&cmd_flush_queue_region_cmd,
10276                (void *)&cmd_flush_queue_region_flush,
10277                (void *)&cmd_flush_queue_region_what,
10278                NULL,
10279        },
10280};
10281
10282/* *** get all queue region related configuration info *** */
10283struct cmd_show_queue_region_info {
10284        cmdline_fixed_string_t show;
10285        cmdline_fixed_string_t port;
10286        portid_t port_id;
10287        cmdline_fixed_string_t cmd;
10288};
10289
10290static void
10291cmd_show_queue_region_info_parsed(void *parsed_result,
10292                        __rte_unused struct cmdline *cl,
10293                        __rte_unused void *data)
10294{
10295        struct cmd_show_queue_region_info *res = parsed_result;
10296        int ret = -ENOTSUP;
10297#ifdef RTE_NET_I40E
10298        struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10299        enum rte_pmd_i40e_queue_region_op op_type;
10300#endif
10301
10302        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10303                return;
10304
10305#ifdef RTE_NET_I40E
10306        memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10307
10308        op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10309
10310        ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10311                                        op_type, &rte_pmd_regions);
10312
10313        port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10314#endif
10315
10316        switch (ret) {
10317        case 0:
10318                break;
10319        case -ENOTSUP:
10320                fprintf(stderr, "function not implemented or supported\n");
10321                break;
10322        default:
10323                fprintf(stderr, "queue region config info show error: (%s)\n",
10324                        strerror(-ret));
10325        }
10326}
10327
10328cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10329TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10330                                show, "show");
10331cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10332        TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10333                                port, "port");
10334cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10335        TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10336                                port_id, RTE_UINT16);
10337cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10338        TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10339                                cmd, "queue-region");
10340
10341cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10342        .f = cmd_show_queue_region_info_parsed,
10343        .data = NULL,
10344        .help_str = "show port <port_id> queue-region"
10345                ": show all queue region related configuration info",
10346        .tokens = {
10347                (void *)&cmd_show_queue_region_info_get,
10348                (void *)&cmd_show_queue_region_info_port,
10349                (void *)&cmd_show_queue_region_info_port_index,
10350                (void *)&cmd_show_queue_region_info_cmd,
10351                NULL,
10352        },
10353};
10354
10355/* *** Filters Control *** */
10356
10357#define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10358do { \
10359        if ((ip_addr).family == AF_INET) \
10360                (ip) = (ip_addr).addr.ipv4.s_addr; \
10361        else { \
10362                fprintf(stderr, "invalid parameter.\n"); \
10363                return; \
10364        } \
10365} while (0)
10366
10367#define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10368do { \
10369        if ((ip_addr).family == AF_INET6) \
10370                rte_memcpy(&(ip), \
10371                                 &((ip_addr).addr.ipv6), \
10372                                 sizeof(struct in6_addr)); \
10373        else { \
10374                fprintf(stderr, "invalid parameter.\n"); \
10375                return; \
10376        } \
10377} while (0)
10378
10379#ifdef RTE_NET_I40E
10380
10381static uint16_t
10382str2flowtype(char *string)
10383{
10384        uint8_t i = 0;
10385        static const struct {
10386                char str[32];
10387                uint16_t type;
10388        } flowtype_str[] = {
10389                {"raw", RTE_ETH_FLOW_RAW},
10390                {"ipv4", RTE_ETH_FLOW_IPV4},
10391                {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10392                {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10393                {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10394                {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10395                {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10396                {"ipv6", RTE_ETH_FLOW_IPV6},
10397                {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10398                {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10399                {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10400                {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10401                {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10402                {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10403        };
10404
10405        for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10406                if (!strcmp(flowtype_str[i].str, string))
10407                        return flowtype_str[i].type;
10408        }
10409
10410        if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10411                return (uint16_t)atoi(string);
10412
10413        return RTE_ETH_FLOW_UNKNOWN;
10414}
10415
10416/* *** deal with flow director filter *** */
10417struct cmd_flow_director_result {
10418        cmdline_fixed_string_t flow_director_filter;
10419        portid_t port_id;
10420        cmdline_fixed_string_t mode;
10421        cmdline_fixed_string_t mode_value;
10422        cmdline_fixed_string_t ops;
10423        cmdline_fixed_string_t flow;
10424        cmdline_fixed_string_t flow_type;
10425        cmdline_fixed_string_t drop;
10426        cmdline_fixed_string_t queue;
10427        uint16_t  queue_id;
10428        cmdline_fixed_string_t fd_id;
10429        uint32_t  fd_id_value;
10430        cmdline_fixed_string_t packet;
10431        char filepath[];
10432};
10433
10434static void
10435cmd_flow_director_filter_parsed(void *parsed_result,
10436                          __rte_unused struct cmdline *cl,
10437                          __rte_unused void *data)
10438{
10439        struct cmd_flow_director_result *res = parsed_result;
10440        int ret = 0;
10441        struct rte_pmd_i40e_flow_type_mapping
10442                        mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10443        struct rte_pmd_i40e_pkt_template_conf conf;
10444        uint16_t flow_type = str2flowtype(res->flow_type);
10445        uint16_t i, port = res->port_id;
10446        uint8_t add;
10447
10448        memset(&conf, 0, sizeof(conf));
10449
10450        if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10451                fprintf(stderr, "Invalid flow type specified.\n");
10452                return;
10453        }
10454        ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10455                                                 mapping);
10456        if (ret)
10457                return;
10458        if (mapping[flow_type].pctype == 0ULL) {
10459                fprintf(stderr, "Invalid flow type specified.\n");
10460                return;
10461        }
10462        for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10463                if (mapping[flow_type].pctype & (1ULL << i)) {
10464                        conf.input.pctype = i;
10465                        break;
10466                }
10467        }
10468
10469        conf.input.packet = open_file(res->filepath,
10470                                &conf.input.length);
10471        if (!conf.input.packet)
10472                return;
10473        if (!strcmp(res->drop, "drop"))
10474                conf.action.behavior =
10475                        RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10476        else
10477                conf.action.behavior =
10478                        RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10479        conf.action.report_status =
10480                        RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10481        conf.action.rx_queue = res->queue_id;
10482        conf.soft_id = res->fd_id_value;
10483        add  = strcmp(res->ops, "del") ? 1 : 0;
10484        ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10485                                                        &conf,
10486                                                        add);
10487        if (ret < 0)
10488                fprintf(stderr, "flow director config error: (%s)\n",
10489                        strerror(-ret));
10490        close_file(conf.input.packet);
10491}
10492
10493cmdline_parse_token_string_t cmd_flow_director_filter =
10494        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10495                                 flow_director_filter, "flow_director_filter");
10496cmdline_parse_token_num_t cmd_flow_director_port_id =
10497        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10498                              port_id, RTE_UINT16);
10499cmdline_parse_token_string_t cmd_flow_director_ops =
10500        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10501                                 ops, "add#del#update");
10502cmdline_parse_token_string_t cmd_flow_director_flow =
10503        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10504                                 flow, "flow");
10505cmdline_parse_token_string_t cmd_flow_director_flow_type =
10506        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10507                flow_type, NULL);
10508cmdline_parse_token_string_t cmd_flow_director_drop =
10509        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10510                                 drop, "drop#fwd");
10511cmdline_parse_token_string_t cmd_flow_director_queue =
10512        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10513                                 queue, "queue");
10514cmdline_parse_token_num_t cmd_flow_director_queue_id =
10515        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10516                              queue_id, RTE_UINT16);
10517cmdline_parse_token_string_t cmd_flow_director_fd_id =
10518        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10519                                 fd_id, "fd_id");
10520cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10521        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10522                              fd_id_value, RTE_UINT32);
10523
10524cmdline_parse_token_string_t cmd_flow_director_mode =
10525        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10526                                 mode, "mode");
10527cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10528        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10529                                 mode_value, "raw");
10530cmdline_parse_token_string_t cmd_flow_director_packet =
10531        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10532                                 packet, "packet");
10533cmdline_parse_token_string_t cmd_flow_director_filepath =
10534        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10535                                 filepath, NULL);
10536
10537cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10538        .f = cmd_flow_director_filter_parsed,
10539        .data = NULL,
10540        .help_str = "flow_director_filter ... : Add or delete a raw flow "
10541                "director entry on NIC",
10542        .tokens = {
10543                (void *)&cmd_flow_director_filter,
10544                (void *)&cmd_flow_director_port_id,
10545                (void *)&cmd_flow_director_mode,
10546                (void *)&cmd_flow_director_mode_raw,
10547                (void *)&cmd_flow_director_ops,
10548                (void *)&cmd_flow_director_flow,
10549                (void *)&cmd_flow_director_flow_type,
10550                (void *)&cmd_flow_director_drop,
10551                (void *)&cmd_flow_director_queue,
10552                (void *)&cmd_flow_director_queue_id,
10553                (void *)&cmd_flow_director_fd_id,
10554                (void *)&cmd_flow_director_fd_id_value,
10555                (void *)&cmd_flow_director_packet,
10556                (void *)&cmd_flow_director_filepath,
10557                NULL,
10558        },
10559};
10560
10561#endif /* RTE_NET_I40E */
10562
10563/* *** deal with flow director mask *** */
10564struct cmd_flow_director_mask_result {
10565        cmdline_fixed_string_t flow_director_mask;
10566        portid_t port_id;
10567        cmdline_fixed_string_t mode;
10568        cmdline_fixed_string_t mode_value;
10569        cmdline_fixed_string_t vlan;
10570        uint16_t vlan_mask;
10571        cmdline_fixed_string_t src_mask;
10572        cmdline_ipaddr_t ipv4_src;
10573        cmdline_ipaddr_t ipv6_src;
10574        uint16_t port_src;
10575        cmdline_fixed_string_t dst_mask;
10576        cmdline_ipaddr_t ipv4_dst;
10577        cmdline_ipaddr_t ipv6_dst;
10578        uint16_t port_dst;
10579        cmdline_fixed_string_t mac;
10580        uint8_t mac_addr_byte_mask;
10581        cmdline_fixed_string_t tunnel_id;
10582        uint32_t tunnel_id_mask;
10583        cmdline_fixed_string_t tunnel_type;
10584        uint8_t tunnel_type_mask;
10585};
10586
10587static void
10588cmd_flow_director_mask_parsed(void *parsed_result,
10589                          __rte_unused struct cmdline *cl,
10590                          __rte_unused void *data)
10591{
10592        struct cmd_flow_director_mask_result *res = parsed_result;
10593        struct rte_eth_fdir_masks *mask;
10594        struct rte_port *port;
10595
10596        port = &ports[res->port_id];
10597        /** Check if the port is not started **/
10598        if (port->port_status != RTE_PORT_STOPPED) {
10599                fprintf(stderr, "Please stop port %d first\n", res->port_id);
10600                return;
10601        }
10602
10603        mask = &port->dev_conf.fdir_conf.mask;
10604
10605        if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10606                if (strcmp(res->mode_value, "MAC-VLAN")) {
10607                        fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10608                        return;
10609                }
10610
10611                mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10612        } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10613                if (strcmp(res->mode_value, "Tunnel")) {
10614                        fprintf(stderr, "Please set mode to Tunnel.\n");
10615                        return;
10616                }
10617
10618                mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10619                mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10620                mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10621                mask->tunnel_type_mask = res->tunnel_type_mask;
10622        } else {
10623                if (strcmp(res->mode_value, "IP")) {
10624                        fprintf(stderr, "Please set mode to IP.\n");
10625                        return;
10626                }
10627
10628                mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10629                IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10630                IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10631                IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10632                IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10633                mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10634                mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10635        }
10636
10637        cmd_reconfig_device_queue(res->port_id, 1, 1);
10638}
10639
10640cmdline_parse_token_string_t cmd_flow_director_mask =
10641        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10642                                 flow_director_mask, "flow_director_mask");
10643cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10644        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10645                              port_id, RTE_UINT16);
10646cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10647        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10648                                 vlan, "vlan");
10649cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10650        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10651                              vlan_mask, RTE_UINT16);
10652cmdline_parse_token_string_t cmd_flow_director_mask_src =
10653        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10654                                 src_mask, "src_mask");
10655cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10656        TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10657                                 ipv4_src);
10658cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10659        TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10660                                 ipv6_src);
10661cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10662        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10663                              port_src, RTE_UINT16);
10664cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10665        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10666                                 dst_mask, "dst_mask");
10667cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10668        TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10669                                 ipv4_dst);
10670cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10671        TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10672                                 ipv6_dst);
10673cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10674        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10675                              port_dst, RTE_UINT16);
10676
10677cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10678        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10679                                 mode, "mode");
10680cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10681        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10682                                 mode_value, "IP");
10683cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10684        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10685                                 mode_value, "MAC-VLAN");
10686cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10687        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10688                                 mode_value, "Tunnel");
10689cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10690        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10691                                 mac, "mac");
10692cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10693        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10694                              mac_addr_byte_mask, RTE_UINT8);
10695cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10696        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10697                                 tunnel_type, "tunnel-type");
10698cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10699        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10700                              tunnel_type_mask, RTE_UINT8);
10701cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10702        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10703                                 tunnel_id, "tunnel-id");
10704cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10705        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10706                              tunnel_id_mask, RTE_UINT32);
10707
10708cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10709        .f = cmd_flow_director_mask_parsed,
10710        .data = NULL,
10711        .help_str = "flow_director_mask ... : "
10712                "Set IP mode flow director's mask on NIC",
10713        .tokens = {
10714                (void *)&cmd_flow_director_mask,
10715                (void *)&cmd_flow_director_mask_port_id,
10716                (void *)&cmd_flow_director_mask_mode,
10717                (void *)&cmd_flow_director_mask_mode_ip,
10718                (void *)&cmd_flow_director_mask_vlan,
10719                (void *)&cmd_flow_director_mask_vlan_value,
10720                (void *)&cmd_flow_director_mask_src,
10721                (void *)&cmd_flow_director_mask_ipv4_src,
10722                (void *)&cmd_flow_director_mask_ipv6_src,
10723                (void *)&cmd_flow_director_mask_port_src,
10724                (void *)&cmd_flow_director_mask_dst,
10725                (void *)&cmd_flow_director_mask_ipv4_dst,
10726                (void *)&cmd_flow_director_mask_ipv6_dst,
10727                (void *)&cmd_flow_director_mask_port_dst,
10728                NULL,
10729        },
10730};
10731
10732cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10733        .f = cmd_flow_director_mask_parsed,
10734        .data = NULL,
10735        .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10736                "flow director's mask on NIC",
10737        .tokens = {
10738                (void *)&cmd_flow_director_mask,
10739                (void *)&cmd_flow_director_mask_port_id,
10740                (void *)&cmd_flow_director_mask_mode,
10741                (void *)&cmd_flow_director_mask_mode_mac_vlan,
10742                (void *)&cmd_flow_director_mask_vlan,
10743                (void *)&cmd_flow_director_mask_vlan_value,
10744                NULL,
10745        },
10746};
10747
10748cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10749        .f = cmd_flow_director_mask_parsed,
10750        .data = NULL,
10751        .help_str = "flow_director_mask ... : Set tunnel mode "
10752                "flow director's mask on NIC",
10753        .tokens = {
10754                (void *)&cmd_flow_director_mask,
10755                (void *)&cmd_flow_director_mask_port_id,
10756                (void *)&cmd_flow_director_mask_mode,
10757                (void *)&cmd_flow_director_mask_mode_tunnel,
10758                (void *)&cmd_flow_director_mask_vlan,
10759                (void *)&cmd_flow_director_mask_vlan_value,
10760                (void *)&cmd_flow_director_mask_mac,
10761                (void *)&cmd_flow_director_mask_mac_value,
10762                (void *)&cmd_flow_director_mask_tunnel_type,
10763                (void *)&cmd_flow_director_mask_tunnel_type_value,
10764                (void *)&cmd_flow_director_mask_tunnel_id,
10765                (void *)&cmd_flow_director_mask_tunnel_id_value,
10766                NULL,
10767        },
10768};
10769
10770/* *** deal with flow director flexible payload configuration *** */
10771struct cmd_flow_director_flexpayload_result {
10772        cmdline_fixed_string_t flow_director_flexpayload;
10773        portid_t port_id;
10774        cmdline_fixed_string_t payload_layer;
10775        cmdline_fixed_string_t payload_cfg;
10776};
10777
10778static inline int
10779parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10780{
10781        char s[256];
10782        const char *p, *p0 = q_arg;
10783        char *end;
10784        unsigned long int_fld;
10785        char *str_fld[max_num];
10786        int i;
10787        unsigned size;
10788        int ret = -1;
10789
10790        p = strchr(p0, '(');
10791        if (p == NULL)
10792                return -1;
10793        ++p;
10794        p0 = strchr(p, ')');
10795        if (p0 == NULL)
10796                return -1;
10797
10798        size = p0 - p;
10799        if (size >= sizeof(s))
10800                return -1;
10801
10802        snprintf(s, sizeof(s), "%.*s", size, p);
10803        ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10804        if (ret < 0 || ret > max_num)
10805                return -1;
10806        for (i = 0; i < ret; i++) {
10807                errno = 0;
10808                int_fld = strtoul(str_fld[i], &end, 0);
10809                if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10810                        return -1;
10811                offsets[i] = (uint16_t)int_fld;
10812        }
10813        return ret;
10814}
10815
10816static void
10817cmd_flow_director_flxpld_parsed(void *parsed_result,
10818                          __rte_unused struct cmdline *cl,
10819                          __rte_unused void *data)
10820{
10821        struct cmd_flow_director_flexpayload_result *res = parsed_result;
10822        struct rte_eth_flex_payload_cfg flex_cfg;
10823        struct rte_port *port;
10824        int ret = 0;
10825
10826        port = &ports[res->port_id];
10827        /** Check if the port is not started **/
10828        if (port->port_status != RTE_PORT_STOPPED) {
10829                fprintf(stderr, "Please stop port %d first\n", res->port_id);
10830                return;
10831        }
10832
10833        memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10834
10835        if (!strcmp(res->payload_layer, "raw"))
10836                flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10837        else if (!strcmp(res->payload_layer, "l2"))
10838                flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10839        else if (!strcmp(res->payload_layer, "l3"))
10840                flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10841        else if (!strcmp(res->payload_layer, "l4"))
10842                flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10843
10844        ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10845                            RTE_ETH_FDIR_MAX_FLEXLEN);
10846        if (ret < 0) {
10847                fprintf(stderr, "error: Cannot parse flex payload input.\n");
10848                return;
10849        }
10850
10851        fdir_set_flex_payload(res->port_id, &flex_cfg);
10852        cmd_reconfig_device_queue(res->port_id, 1, 1);
10853}
10854
10855cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10856        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10857                                 flow_director_flexpayload,
10858                                 "flow_director_flex_payload");
10859cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10860        TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10861                              port_id, RTE_UINT16);
10862cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10863        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10864                                 payload_layer, "raw#l2#l3#l4");
10865cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10866        TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10867                                 payload_cfg, NULL);
10868
10869cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10870        .f = cmd_flow_director_flxpld_parsed,
10871        .data = NULL,
10872        .help_str = "flow_director_flexpayload ... : "
10873                "Set flow director's flex payload on NIC",
10874        .tokens = {
10875                (void *)&cmd_flow_director_flexpayload,
10876                (void *)&cmd_flow_director_flexpayload_port_id,
10877                (void *)&cmd_flow_director_flexpayload_payload_layer,
10878                (void *)&cmd_flow_director_flexpayload_payload_cfg,
10879                NULL,
10880        },
10881};
10882
10883/* Generic flow interface command. */
10884extern cmdline_parse_inst_t cmd_flow;
10885
10886/* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10887struct cmd_mcast_addr_result {
10888        cmdline_fixed_string_t mcast_addr_cmd;
10889        cmdline_fixed_string_t what;
10890        uint16_t port_num;
10891        struct rte_ether_addr mc_addr;
10892};
10893
10894static void cmd_mcast_addr_parsed(void *parsed_result,
10895                __rte_unused struct cmdline *cl,
10896                __rte_unused void *data)
10897{
10898        struct cmd_mcast_addr_result *res = parsed_result;
10899
10900        if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10901                fprintf(stderr,
10902                        "Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10903                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10904                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10905                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10906                return;
10907        }
10908        if (strcmp(res->what, "add") == 0)
10909                mcast_addr_add(res->port_num, &res->mc_addr);
10910        else
10911                mcast_addr_remove(res->port_num, &res->mc_addr);
10912}
10913
10914cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10915        TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10916                                 mcast_addr_cmd, "mcast_addr");
10917cmdline_parse_token_string_t cmd_mcast_addr_what =
10918        TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10919                                 "add#remove");
10920cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10921        TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10922                                 RTE_UINT16);
10923cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10924        TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10925
10926cmdline_parse_inst_t cmd_mcast_addr = {
10927        .f = cmd_mcast_addr_parsed,
10928        .data = (void *)0,
10929        .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10930                "Add/Remove multicast MAC address on port_id",
10931        .tokens = {
10932                (void *)&cmd_mcast_addr_cmd,
10933                (void *)&cmd_mcast_addr_what,
10934                (void *)&cmd_mcast_addr_portnum,
10935                (void *)&cmd_mcast_addr_addr,
10936                NULL,
10937        },
10938};
10939
10940/* vf vlan anti spoof configuration */
10941
10942/* Common result structure for vf vlan anti spoof */
10943struct cmd_vf_vlan_anti_spoof_result {
10944        cmdline_fixed_string_t set;
10945        cmdline_fixed_string_t vf;
10946        cmdline_fixed_string_t vlan;
10947        cmdline_fixed_string_t antispoof;
10948        portid_t port_id;
10949        uint32_t vf_id;
10950        cmdline_fixed_string_t on_off;
10951};
10952
10953/* Common CLI fields for vf vlan anti spoof enable disable */
10954cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10955        TOKEN_STRING_INITIALIZER
10956                (struct cmd_vf_vlan_anti_spoof_result,
10957                 set, "set");
10958cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10959        TOKEN_STRING_INITIALIZER
10960                (struct cmd_vf_vlan_anti_spoof_result,
10961                 vf, "vf");
10962cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10963        TOKEN_STRING_INITIALIZER
10964                (struct cmd_vf_vlan_anti_spoof_result,
10965                 vlan, "vlan");
10966cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10967        TOKEN_STRING_INITIALIZER
10968                (struct cmd_vf_vlan_anti_spoof_result,
10969                 antispoof, "antispoof");
10970cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10971        TOKEN_NUM_INITIALIZER
10972                (struct cmd_vf_vlan_anti_spoof_result,
10973                 port_id, RTE_UINT16);
10974cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10975        TOKEN_NUM_INITIALIZER
10976                (struct cmd_vf_vlan_anti_spoof_result,
10977                 vf_id, RTE_UINT32);
10978cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10979        TOKEN_STRING_INITIALIZER
10980                (struct cmd_vf_vlan_anti_spoof_result,
10981                 on_off, "on#off");
10982
10983static void
10984cmd_set_vf_vlan_anti_spoof_parsed(
10985        void *parsed_result,
10986        __rte_unused struct cmdline *cl,
10987        __rte_unused void *data)
10988{
10989        struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10990        int ret = -ENOTSUP;
10991
10992        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10993
10994        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10995                return;
10996
10997#ifdef RTE_NET_IXGBE
10998        if (ret == -ENOTSUP)
10999                ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11000                                res->vf_id, is_on);
11001#endif
11002#ifdef RTE_NET_I40E
11003        if (ret == -ENOTSUP)
11004                ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11005                                res->vf_id, is_on);
11006#endif
11007#ifdef RTE_NET_BNXT
11008        if (ret == -ENOTSUP)
11009                ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11010                                res->vf_id, is_on);
11011#endif
11012
11013        switch (ret) {
11014        case 0:
11015                break;
11016        case -EINVAL:
11017                fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11018                break;
11019        case -ENODEV:
11020                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11021                break;
11022        case -ENOTSUP:
11023                fprintf(stderr, "function not implemented\n");
11024                break;
11025        default:
11026                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11027        }
11028}
11029
11030cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11031        .f = cmd_set_vf_vlan_anti_spoof_parsed,
11032        .data = NULL,
11033        .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11034        .tokens = {
11035                (void *)&cmd_vf_vlan_anti_spoof_set,
11036                (void *)&cmd_vf_vlan_anti_spoof_vf,
11037                (void *)&cmd_vf_vlan_anti_spoof_vlan,
11038                (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11039                (void *)&cmd_vf_vlan_anti_spoof_port_id,
11040                (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11041                (void *)&cmd_vf_vlan_anti_spoof_on_off,
11042                NULL,
11043        },
11044};
11045
11046/* vf mac anti spoof configuration */
11047
11048/* Common result structure for vf mac anti spoof */
11049struct cmd_vf_mac_anti_spoof_result {
11050        cmdline_fixed_string_t set;
11051        cmdline_fixed_string_t vf;
11052        cmdline_fixed_string_t mac;
11053        cmdline_fixed_string_t antispoof;
11054        portid_t port_id;
11055        uint32_t vf_id;
11056        cmdline_fixed_string_t on_off;
11057};
11058
11059/* Common CLI fields for vf mac anti spoof enable disable */
11060cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11061        TOKEN_STRING_INITIALIZER
11062                (struct cmd_vf_mac_anti_spoof_result,
11063                 set, "set");
11064cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11065        TOKEN_STRING_INITIALIZER
11066                (struct cmd_vf_mac_anti_spoof_result,
11067                 vf, "vf");
11068cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11069        TOKEN_STRING_INITIALIZER
11070                (struct cmd_vf_mac_anti_spoof_result,
11071                 mac, "mac");
11072cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11073        TOKEN_STRING_INITIALIZER
11074                (struct cmd_vf_mac_anti_spoof_result,
11075                 antispoof, "antispoof");
11076cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11077        TOKEN_NUM_INITIALIZER
11078                (struct cmd_vf_mac_anti_spoof_result,
11079                 port_id, RTE_UINT16);
11080cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11081        TOKEN_NUM_INITIALIZER
11082                (struct cmd_vf_mac_anti_spoof_result,
11083                 vf_id, RTE_UINT32);
11084cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11085        TOKEN_STRING_INITIALIZER
11086                (struct cmd_vf_mac_anti_spoof_result,
11087                 on_off, "on#off");
11088
11089static void
11090cmd_set_vf_mac_anti_spoof_parsed(
11091        void *parsed_result,
11092        __rte_unused struct cmdline *cl,
11093        __rte_unused void *data)
11094{
11095        struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11096        int ret = -ENOTSUP;
11097
11098        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11099
11100        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11101                return;
11102
11103#ifdef RTE_NET_IXGBE
11104        if (ret == -ENOTSUP)
11105                ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11106                        res->vf_id, is_on);
11107#endif
11108#ifdef RTE_NET_I40E
11109        if (ret == -ENOTSUP)
11110                ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11111                        res->vf_id, is_on);
11112#endif
11113#ifdef RTE_NET_BNXT
11114        if (ret == -ENOTSUP)
11115                ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11116                        res->vf_id, is_on);
11117#endif
11118
11119        switch (ret) {
11120        case 0:
11121                break;
11122        case -EINVAL:
11123                fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11124                        res->vf_id, is_on);
11125                break;
11126        case -ENODEV:
11127                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11128                break;
11129        case -ENOTSUP:
11130                fprintf(stderr, "function not implemented\n");
11131                break;
11132        default:
11133                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11134        }
11135}
11136
11137cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11138        .f = cmd_set_vf_mac_anti_spoof_parsed,
11139        .data = NULL,
11140        .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11141        .tokens = {
11142                (void *)&cmd_vf_mac_anti_spoof_set,
11143                (void *)&cmd_vf_mac_anti_spoof_vf,
11144                (void *)&cmd_vf_mac_anti_spoof_mac,
11145                (void *)&cmd_vf_mac_anti_spoof_antispoof,
11146                (void *)&cmd_vf_mac_anti_spoof_port_id,
11147                (void *)&cmd_vf_mac_anti_spoof_vf_id,
11148                (void *)&cmd_vf_mac_anti_spoof_on_off,
11149                NULL,
11150        },
11151};
11152
11153/* vf vlan strip queue configuration */
11154
11155/* Common result structure for vf mac anti spoof */
11156struct cmd_vf_vlan_stripq_result {
11157        cmdline_fixed_string_t set;
11158        cmdline_fixed_string_t vf;
11159        cmdline_fixed_string_t vlan;
11160        cmdline_fixed_string_t stripq;
11161        portid_t port_id;
11162        uint16_t vf_id;
11163        cmdline_fixed_string_t on_off;
11164};
11165
11166/* Common CLI fields for vf vlan strip enable disable */
11167cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11168        TOKEN_STRING_INITIALIZER
11169                (struct cmd_vf_vlan_stripq_result,
11170                 set, "set");
11171cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11172        TOKEN_STRING_INITIALIZER
11173                (struct cmd_vf_vlan_stripq_result,
11174                 vf, "vf");
11175cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11176        TOKEN_STRING_INITIALIZER
11177                (struct cmd_vf_vlan_stripq_result,
11178                 vlan, "vlan");
11179cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11180        TOKEN_STRING_INITIALIZER
11181                (struct cmd_vf_vlan_stripq_result,
11182                 stripq, "stripq");
11183cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11184        TOKEN_NUM_INITIALIZER
11185                (struct cmd_vf_vlan_stripq_result,
11186                 port_id, RTE_UINT16);
11187cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11188        TOKEN_NUM_INITIALIZER
11189                (struct cmd_vf_vlan_stripq_result,
11190                 vf_id, RTE_UINT16);
11191cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11192        TOKEN_STRING_INITIALIZER
11193                (struct cmd_vf_vlan_stripq_result,
11194                 on_off, "on#off");
11195
11196static void
11197cmd_set_vf_vlan_stripq_parsed(
11198        void *parsed_result,
11199        __rte_unused struct cmdline *cl,
11200        __rte_unused void *data)
11201{
11202        struct cmd_vf_vlan_stripq_result *res = parsed_result;
11203        int ret = -ENOTSUP;
11204
11205        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11206
11207        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11208                return;
11209
11210#ifdef RTE_NET_IXGBE
11211        if (ret == -ENOTSUP)
11212                ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11213                        res->vf_id, is_on);
11214#endif
11215#ifdef RTE_NET_I40E
11216        if (ret == -ENOTSUP)
11217                ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11218                        res->vf_id, is_on);
11219#endif
11220#ifdef RTE_NET_BNXT
11221        if (ret == -ENOTSUP)
11222                ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11223                        res->vf_id, is_on);
11224#endif
11225
11226        switch (ret) {
11227        case 0:
11228                break;
11229        case -EINVAL:
11230                fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11231                        res->vf_id, is_on);
11232                break;
11233        case -ENODEV:
11234                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11235                break;
11236        case -ENOTSUP:
11237                fprintf(stderr, "function not implemented\n");
11238                break;
11239        default:
11240                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11241        }
11242}
11243
11244cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11245        .f = cmd_set_vf_vlan_stripq_parsed,
11246        .data = NULL,
11247        .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11248        .tokens = {
11249                (void *)&cmd_vf_vlan_stripq_set,
11250                (void *)&cmd_vf_vlan_stripq_vf,
11251                (void *)&cmd_vf_vlan_stripq_vlan,
11252                (void *)&cmd_vf_vlan_stripq_stripq,
11253                (void *)&cmd_vf_vlan_stripq_port_id,
11254                (void *)&cmd_vf_vlan_stripq_vf_id,
11255                (void *)&cmd_vf_vlan_stripq_on_off,
11256                NULL,
11257        },
11258};
11259
11260/* vf vlan insert configuration */
11261
11262/* Common result structure for vf vlan insert */
11263struct cmd_vf_vlan_insert_result {
11264        cmdline_fixed_string_t set;
11265        cmdline_fixed_string_t vf;
11266        cmdline_fixed_string_t vlan;
11267        cmdline_fixed_string_t insert;
11268        portid_t port_id;
11269        uint16_t vf_id;
11270        uint16_t vlan_id;
11271};
11272
11273/* Common CLI fields for vf vlan insert enable disable */
11274cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11275        TOKEN_STRING_INITIALIZER
11276                (struct cmd_vf_vlan_insert_result,
11277                 set, "set");
11278cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11279        TOKEN_STRING_INITIALIZER
11280                (struct cmd_vf_vlan_insert_result,
11281                 vf, "vf");
11282cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11283        TOKEN_STRING_INITIALIZER
11284                (struct cmd_vf_vlan_insert_result,
11285                 vlan, "vlan");
11286cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11287        TOKEN_STRING_INITIALIZER
11288                (struct cmd_vf_vlan_insert_result,
11289                 insert, "insert");
11290cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11291        TOKEN_NUM_INITIALIZER
11292                (struct cmd_vf_vlan_insert_result,
11293                 port_id, RTE_UINT16);
11294cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11295        TOKEN_NUM_INITIALIZER
11296                (struct cmd_vf_vlan_insert_result,
11297                 vf_id, RTE_UINT16);
11298cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11299        TOKEN_NUM_INITIALIZER
11300                (struct cmd_vf_vlan_insert_result,
11301                 vlan_id, RTE_UINT16);
11302
11303static void
11304cmd_set_vf_vlan_insert_parsed(
11305        void *parsed_result,
11306        __rte_unused struct cmdline *cl,
11307        __rte_unused void *data)
11308{
11309        struct cmd_vf_vlan_insert_result *res = parsed_result;
11310        int ret = -ENOTSUP;
11311
11312        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11313                return;
11314
11315#ifdef RTE_NET_IXGBE
11316        if (ret == -ENOTSUP)
11317                ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11318                        res->vlan_id);
11319#endif
11320#ifdef RTE_NET_I40E
11321        if (ret == -ENOTSUP)
11322                ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11323                        res->vlan_id);
11324#endif
11325#ifdef RTE_NET_BNXT
11326        if (ret == -ENOTSUP)
11327                ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11328                        res->vlan_id);
11329#endif
11330
11331        switch (ret) {
11332        case 0:
11333                break;
11334        case -EINVAL:
11335                fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11336                        res->vf_id, res->vlan_id);
11337                break;
11338        case -ENODEV:
11339                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11340                break;
11341        case -ENOTSUP:
11342                fprintf(stderr, "function not implemented\n");
11343                break;
11344        default:
11345                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11346        }
11347}
11348
11349cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11350        .f = cmd_set_vf_vlan_insert_parsed,
11351        .data = NULL,
11352        .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11353        .tokens = {
11354                (void *)&cmd_vf_vlan_insert_set,
11355                (void *)&cmd_vf_vlan_insert_vf,
11356                (void *)&cmd_vf_vlan_insert_vlan,
11357                (void *)&cmd_vf_vlan_insert_insert,
11358                (void *)&cmd_vf_vlan_insert_port_id,
11359                (void *)&cmd_vf_vlan_insert_vf_id,
11360                (void *)&cmd_vf_vlan_insert_vlan_id,
11361                NULL,
11362        },
11363};
11364
11365/* tx loopback configuration */
11366
11367/* Common result structure for tx loopback */
11368struct cmd_tx_loopback_result {
11369        cmdline_fixed_string_t set;
11370        cmdline_fixed_string_t tx;
11371        cmdline_fixed_string_t loopback;
11372        portid_t port_id;
11373        cmdline_fixed_string_t on_off;
11374};
11375
11376/* Common CLI fields for tx loopback enable disable */
11377cmdline_parse_token_string_t cmd_tx_loopback_set =
11378        TOKEN_STRING_INITIALIZER
11379                (struct cmd_tx_loopback_result,
11380                 set, "set");
11381cmdline_parse_token_string_t cmd_tx_loopback_tx =
11382        TOKEN_STRING_INITIALIZER
11383                (struct cmd_tx_loopback_result,
11384                 tx, "tx");
11385cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11386        TOKEN_STRING_INITIALIZER
11387                (struct cmd_tx_loopback_result,
11388                 loopback, "loopback");
11389cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11390        TOKEN_NUM_INITIALIZER
11391                (struct cmd_tx_loopback_result,
11392                 port_id, RTE_UINT16);
11393cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11394        TOKEN_STRING_INITIALIZER
11395                (struct cmd_tx_loopback_result,
11396                 on_off, "on#off");
11397
11398static void
11399cmd_set_tx_loopback_parsed(
11400        void *parsed_result,
11401        __rte_unused struct cmdline *cl,
11402        __rte_unused void *data)
11403{
11404        struct cmd_tx_loopback_result *res = parsed_result;
11405        int ret = -ENOTSUP;
11406
11407        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11408
11409        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11410                return;
11411
11412#ifdef RTE_NET_IXGBE
11413        if (ret == -ENOTSUP)
11414                ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11415#endif
11416#ifdef RTE_NET_I40E
11417        if (ret == -ENOTSUP)
11418                ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11419#endif
11420#ifdef RTE_NET_BNXT
11421        if (ret == -ENOTSUP)
11422                ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11423#endif
11424#if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11425        if (ret == -ENOTSUP)
11426                ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11427#endif
11428
11429        switch (ret) {
11430        case 0:
11431                break;
11432        case -EINVAL:
11433                fprintf(stderr, "invalid is_on %d\n", is_on);
11434                break;
11435        case -ENODEV:
11436                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11437                break;
11438        case -ENOTSUP:
11439                fprintf(stderr, "function not implemented\n");
11440                break;
11441        default:
11442                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11443        }
11444}
11445
11446cmdline_parse_inst_t cmd_set_tx_loopback = {
11447        .f = cmd_set_tx_loopback_parsed,
11448        .data = NULL,
11449        .help_str = "set tx loopback <port_id> on|off",
11450        .tokens = {
11451                (void *)&cmd_tx_loopback_set,
11452                (void *)&cmd_tx_loopback_tx,
11453                (void *)&cmd_tx_loopback_loopback,
11454                (void *)&cmd_tx_loopback_port_id,
11455                (void *)&cmd_tx_loopback_on_off,
11456                NULL,
11457        },
11458};
11459
11460/* all queues drop enable configuration */
11461
11462/* Common result structure for all queues drop enable */
11463struct cmd_all_queues_drop_en_result {
11464        cmdline_fixed_string_t set;
11465        cmdline_fixed_string_t all;
11466        cmdline_fixed_string_t queues;
11467        cmdline_fixed_string_t drop;
11468        portid_t port_id;
11469        cmdline_fixed_string_t on_off;
11470};
11471
11472/* Common CLI fields for tx loopback enable disable */
11473cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11474        TOKEN_STRING_INITIALIZER
11475                (struct cmd_all_queues_drop_en_result,
11476                 set, "set");
11477cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11478        TOKEN_STRING_INITIALIZER
11479                (struct cmd_all_queues_drop_en_result,
11480                 all, "all");
11481cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11482        TOKEN_STRING_INITIALIZER
11483                (struct cmd_all_queues_drop_en_result,
11484                 queues, "queues");
11485cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11486        TOKEN_STRING_INITIALIZER
11487                (struct cmd_all_queues_drop_en_result,
11488                 drop, "drop");
11489cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11490        TOKEN_NUM_INITIALIZER
11491                (struct cmd_all_queues_drop_en_result,
11492                 port_id, RTE_UINT16);
11493cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11494        TOKEN_STRING_INITIALIZER
11495                (struct cmd_all_queues_drop_en_result,
11496                 on_off, "on#off");
11497
11498static void
11499cmd_set_all_queues_drop_en_parsed(
11500        void *parsed_result,
11501        __rte_unused struct cmdline *cl,
11502        __rte_unused void *data)
11503{
11504        struct cmd_all_queues_drop_en_result *res = parsed_result;
11505        int ret = -ENOTSUP;
11506        int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11507
11508        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11509                return;
11510
11511#ifdef RTE_NET_IXGBE
11512        if (ret == -ENOTSUP)
11513                ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11514#endif
11515#ifdef RTE_NET_BNXT
11516        if (ret == -ENOTSUP)
11517                ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11518#endif
11519        switch (ret) {
11520        case 0:
11521                break;
11522        case -EINVAL:
11523                fprintf(stderr, "invalid is_on %d\n", is_on);
11524                break;
11525        case -ENODEV:
11526                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11527                break;
11528        case -ENOTSUP:
11529                fprintf(stderr, "function not implemented\n");
11530                break;
11531        default:
11532                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11533        }
11534}
11535
11536cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11537        .f = cmd_set_all_queues_drop_en_parsed,
11538        .data = NULL,
11539        .help_str = "set all queues drop <port_id> on|off",
11540        .tokens = {
11541                (void *)&cmd_all_queues_drop_en_set,
11542                (void *)&cmd_all_queues_drop_en_all,
11543                (void *)&cmd_all_queues_drop_en_queues,
11544                (void *)&cmd_all_queues_drop_en_drop,
11545                (void *)&cmd_all_queues_drop_en_port_id,
11546                (void *)&cmd_all_queues_drop_en_on_off,
11547                NULL,
11548        },
11549};
11550
11551/* vf split drop enable configuration */
11552
11553/* Common result structure for vf split drop enable */
11554struct cmd_vf_split_drop_en_result {
11555        cmdline_fixed_string_t set;
11556        cmdline_fixed_string_t vf;
11557        cmdline_fixed_string_t split;
11558        cmdline_fixed_string_t drop;
11559        portid_t port_id;
11560        uint16_t vf_id;
11561        cmdline_fixed_string_t on_off;
11562};
11563
11564/* Common CLI fields for vf split drop enable disable */
11565cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11566        TOKEN_STRING_INITIALIZER
11567                (struct cmd_vf_split_drop_en_result,
11568                 set, "set");
11569cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11570        TOKEN_STRING_INITIALIZER
11571                (struct cmd_vf_split_drop_en_result,
11572                 vf, "vf");
11573cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11574        TOKEN_STRING_INITIALIZER
11575                (struct cmd_vf_split_drop_en_result,
11576                 split, "split");
11577cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11578        TOKEN_STRING_INITIALIZER
11579                (struct cmd_vf_split_drop_en_result,
11580                 drop, "drop");
11581cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11582        TOKEN_NUM_INITIALIZER
11583                (struct cmd_vf_split_drop_en_result,
11584                 port_id, RTE_UINT16);
11585cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11586        TOKEN_NUM_INITIALIZER
11587                (struct cmd_vf_split_drop_en_result,
11588                 vf_id, RTE_UINT16);
11589cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11590        TOKEN_STRING_INITIALIZER
11591                (struct cmd_vf_split_drop_en_result,
11592                 on_off, "on#off");
11593
11594static void
11595cmd_set_vf_split_drop_en_parsed(
11596        void *parsed_result,
11597        __rte_unused struct cmdline *cl,
11598        __rte_unused void *data)
11599{
11600        struct cmd_vf_split_drop_en_result *res = parsed_result;
11601        int ret = -ENOTSUP;
11602        int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11603
11604        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11605                return;
11606
11607#ifdef RTE_NET_IXGBE
11608        ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11609                        is_on);
11610#endif
11611        switch (ret) {
11612        case 0:
11613                break;
11614        case -EINVAL:
11615                fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11616                        res->vf_id, is_on);
11617                break;
11618        case -ENODEV:
11619                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11620                break;
11621        case -ENOTSUP:
11622                fprintf(stderr, "not supported on port %d\n", res->port_id);
11623                break;
11624        default:
11625                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11626        }
11627}
11628
11629cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11630        .f = cmd_set_vf_split_drop_en_parsed,
11631        .data = NULL,
11632        .help_str = "set vf split drop <port_id> <vf_id> on|off",
11633        .tokens = {
11634                (void *)&cmd_vf_split_drop_en_set,
11635                (void *)&cmd_vf_split_drop_en_vf,
11636                (void *)&cmd_vf_split_drop_en_split,
11637                (void *)&cmd_vf_split_drop_en_drop,
11638                (void *)&cmd_vf_split_drop_en_port_id,
11639                (void *)&cmd_vf_split_drop_en_vf_id,
11640                (void *)&cmd_vf_split_drop_en_on_off,
11641                NULL,
11642        },
11643};
11644
11645/* vf mac address configuration */
11646
11647/* Common result structure for vf mac address */
11648struct cmd_set_vf_mac_addr_result {
11649        cmdline_fixed_string_t set;
11650        cmdline_fixed_string_t vf;
11651        cmdline_fixed_string_t mac;
11652        cmdline_fixed_string_t addr;
11653        portid_t port_id;
11654        uint16_t vf_id;
11655        struct rte_ether_addr mac_addr;
11656
11657};
11658
11659/* Common CLI fields for vf split drop enable disable */
11660cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11661        TOKEN_STRING_INITIALIZER
11662                (struct cmd_set_vf_mac_addr_result,
11663                 set, "set");
11664cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11665        TOKEN_STRING_INITIALIZER
11666                (struct cmd_set_vf_mac_addr_result,
11667                 vf, "vf");
11668cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11669        TOKEN_STRING_INITIALIZER
11670                (struct cmd_set_vf_mac_addr_result,
11671                 mac, "mac");
11672cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11673        TOKEN_STRING_INITIALIZER
11674                (struct cmd_set_vf_mac_addr_result,
11675                 addr, "addr");
11676cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11677        TOKEN_NUM_INITIALIZER
11678                (struct cmd_set_vf_mac_addr_result,
11679                 port_id, RTE_UINT16);
11680cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11681        TOKEN_NUM_INITIALIZER
11682                (struct cmd_set_vf_mac_addr_result,
11683                 vf_id, RTE_UINT16);
11684cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11685        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11686                 mac_addr);
11687
11688static void
11689cmd_set_vf_mac_addr_parsed(
11690        void *parsed_result,
11691        __rte_unused struct cmdline *cl,
11692        __rte_unused void *data)
11693{
11694        struct cmd_set_vf_mac_addr_result *res = parsed_result;
11695        int ret = -ENOTSUP;
11696
11697        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11698                return;
11699
11700#ifdef RTE_NET_IXGBE
11701        if (ret == -ENOTSUP)
11702                ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11703                                &res->mac_addr);
11704#endif
11705#ifdef RTE_NET_I40E
11706        if (ret == -ENOTSUP)
11707                ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11708                                &res->mac_addr);
11709#endif
11710#ifdef RTE_NET_BNXT
11711        if (ret == -ENOTSUP)
11712                ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11713                                &res->mac_addr);
11714#endif
11715
11716        switch (ret) {
11717        case 0:
11718                break;
11719        case -EINVAL:
11720                fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11721                break;
11722        case -ENODEV:
11723                fprintf(stderr, "invalid port_id %d\n", res->port_id);
11724                break;
11725        case -ENOTSUP:
11726                fprintf(stderr, "function not implemented\n");
11727                break;
11728        default:
11729                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11730        }
11731}
11732
11733cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11734        .f = cmd_set_vf_mac_addr_parsed,
11735        .data = NULL,
11736        .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11737        .tokens = {
11738                (void *)&cmd_set_vf_mac_addr_set,
11739                (void *)&cmd_set_vf_mac_addr_vf,
11740                (void *)&cmd_set_vf_mac_addr_mac,
11741                (void *)&cmd_set_vf_mac_addr_addr,
11742                (void *)&cmd_set_vf_mac_addr_port_id,
11743                (void *)&cmd_set_vf_mac_addr_vf_id,
11744                (void *)&cmd_set_vf_mac_addr_mac_addr,
11745                NULL,
11746        },
11747};
11748
11749/* MACsec configuration */
11750
11751/* Common result structure for MACsec offload enable */
11752struct cmd_macsec_offload_on_result {
11753        cmdline_fixed_string_t set;
11754        cmdline_fixed_string_t macsec;
11755        cmdline_fixed_string_t offload;
11756        portid_t port_id;
11757        cmdline_fixed_string_t on;
11758        cmdline_fixed_string_t encrypt;
11759        cmdline_fixed_string_t en_on_off;
11760        cmdline_fixed_string_t replay_protect;
11761        cmdline_fixed_string_t rp_on_off;
11762};
11763
11764/* Common CLI fields for MACsec offload disable */
11765cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11766        TOKEN_STRING_INITIALIZER
11767                (struct cmd_macsec_offload_on_result,
11768                 set, "set");
11769cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11770        TOKEN_STRING_INITIALIZER
11771                (struct cmd_macsec_offload_on_result,
11772                 macsec, "macsec");
11773cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11774        TOKEN_STRING_INITIALIZER
11775                (struct cmd_macsec_offload_on_result,
11776                 offload, "offload");
11777cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11778        TOKEN_NUM_INITIALIZER
11779                (struct cmd_macsec_offload_on_result,
11780                 port_id, RTE_UINT16);
11781cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11782        TOKEN_STRING_INITIALIZER
11783                (struct cmd_macsec_offload_on_result,
11784                 on, "on");
11785cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11786        TOKEN_STRING_INITIALIZER
11787                (struct cmd_macsec_offload_on_result,
11788                 encrypt, "encrypt");
11789cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11790        TOKEN_STRING_INITIALIZER
11791                (struct cmd_macsec_offload_on_result,
11792                 en_on_off, "on#off");
11793cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11794        TOKEN_STRING_INITIALIZER
11795                (struct cmd_macsec_offload_on_result,
11796                 replay_protect, "replay-protect");
11797cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11798        TOKEN_STRING_INITIALIZER
11799                (struct cmd_macsec_offload_on_result,
11800                 rp_on_off, "on#off");
11801
11802static void
11803cmd_set_macsec_offload_on_parsed(
11804        void *parsed_result,
11805        __rte_unused struct cmdline *cl,
11806        __rte_unused void *data)
11807{
11808        struct cmd_macsec_offload_on_result *res = parsed_result;
11809        int ret = -ENOTSUP;
11810        portid_t port_id = res->port_id;
11811        int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11812        int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11813        struct rte_eth_dev_info dev_info;
11814
11815        if (port_id_is_invalid(port_id, ENABLED_WARN))
11816                return;
11817        if (!port_is_stopped(port_id)) {
11818                fprintf(stderr, "Please stop port %d first\n", port_id);
11819                return;
11820        }
11821
11822        ret = eth_dev_info_get_print_err(port_id, &dev_info);
11823        if (ret != 0)
11824                return;
11825
11826        if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11827#ifdef RTE_NET_IXGBE
11828                ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11829#endif
11830        }
11831        RTE_SET_USED(en);
11832        RTE_SET_USED(rp);
11833
11834        switch (ret) {
11835        case 0:
11836                ports[port_id].dev_conf.txmode.offloads |=
11837                                                DEV_TX_OFFLOAD_MACSEC_INSERT;
11838                cmd_reconfig_device_queue(port_id, 1, 1);
11839                break;
11840        case -ENODEV:
11841                fprintf(stderr, "invalid port_id %d\n", port_id);
11842                break;
11843        case -ENOTSUP:
11844                fprintf(stderr, "not supported on port %d\n", port_id);
11845                break;
11846        default:
11847                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11848        }
11849}
11850
11851cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11852        .f = cmd_set_macsec_offload_on_parsed,
11853        .data = NULL,
11854        .help_str = "set macsec offload <port_id> on "
11855                "encrypt on|off replay-protect on|off",
11856        .tokens = {
11857                (void *)&cmd_macsec_offload_on_set,
11858                (void *)&cmd_macsec_offload_on_macsec,
11859                (void *)&cmd_macsec_offload_on_offload,
11860                (void *)&cmd_macsec_offload_on_port_id,
11861                (void *)&cmd_macsec_offload_on_on,
11862                (void *)&cmd_macsec_offload_on_encrypt,
11863                (void *)&cmd_macsec_offload_on_en_on_off,
11864                (void *)&cmd_macsec_offload_on_replay_protect,
11865                (void *)&cmd_macsec_offload_on_rp_on_off,
11866                NULL,
11867        },
11868};
11869
11870/* Common result structure for MACsec offload disable */
11871struct cmd_macsec_offload_off_result {
11872        cmdline_fixed_string_t set;
11873        cmdline_fixed_string_t macsec;
11874        cmdline_fixed_string_t offload;
11875        portid_t port_id;
11876        cmdline_fixed_string_t off;
11877};
11878
11879/* Common CLI fields for MACsec offload disable */
11880cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11881        TOKEN_STRING_INITIALIZER
11882                (struct cmd_macsec_offload_off_result,
11883                 set, "set");
11884cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11885        TOKEN_STRING_INITIALIZER
11886                (struct cmd_macsec_offload_off_result,
11887                 macsec, "macsec");
11888cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11889        TOKEN_STRING_INITIALIZER
11890                (struct cmd_macsec_offload_off_result,
11891                 offload, "offload");
11892cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11893        TOKEN_NUM_INITIALIZER
11894                (struct cmd_macsec_offload_off_result,
11895                 port_id, RTE_UINT16);
11896cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11897        TOKEN_STRING_INITIALIZER
11898                (struct cmd_macsec_offload_off_result,
11899                 off, "off");
11900
11901static void
11902cmd_set_macsec_offload_off_parsed(
11903        void *parsed_result,
11904        __rte_unused struct cmdline *cl,
11905        __rte_unused void *data)
11906{
11907        struct cmd_macsec_offload_off_result *res = parsed_result;
11908        int ret = -ENOTSUP;
11909        struct rte_eth_dev_info dev_info;
11910        portid_t port_id = res->port_id;
11911
11912        if (port_id_is_invalid(port_id, ENABLED_WARN))
11913                return;
11914        if (!port_is_stopped(port_id)) {
11915                fprintf(stderr, "Please stop port %d first\n", port_id);
11916                return;
11917        }
11918
11919        ret = eth_dev_info_get_print_err(port_id, &dev_info);
11920        if (ret != 0)
11921                return;
11922
11923        if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11924#ifdef RTE_NET_IXGBE
11925                ret = rte_pmd_ixgbe_macsec_disable(port_id);
11926#endif
11927        }
11928        switch (ret) {
11929        case 0:
11930                ports[port_id].dev_conf.txmode.offloads &=
11931                                                ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11932                cmd_reconfig_device_queue(port_id, 1, 1);
11933                break;
11934        case -ENODEV:
11935                fprintf(stderr, "invalid port_id %d\n", port_id);
11936                break;
11937        case -ENOTSUP:
11938                fprintf(stderr, "not supported on port %d\n", port_id);
11939                break;
11940        default:
11941                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11942        }
11943}
11944
11945cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11946        .f = cmd_set_macsec_offload_off_parsed,
11947        .data = NULL,
11948        .help_str = "set macsec offload <port_id> off",
11949        .tokens = {
11950                (void *)&cmd_macsec_offload_off_set,
11951                (void *)&cmd_macsec_offload_off_macsec,
11952                (void *)&cmd_macsec_offload_off_offload,
11953                (void *)&cmd_macsec_offload_off_port_id,
11954                (void *)&cmd_macsec_offload_off_off,
11955                NULL,
11956        },
11957};
11958
11959/* Common result structure for MACsec secure connection configure */
11960struct cmd_macsec_sc_result {
11961        cmdline_fixed_string_t set;
11962        cmdline_fixed_string_t macsec;
11963        cmdline_fixed_string_t sc;
11964        cmdline_fixed_string_t tx_rx;
11965        portid_t port_id;
11966        struct rte_ether_addr mac;
11967        uint16_t pi;
11968};
11969
11970/* Common CLI fields for MACsec secure connection configure */
11971cmdline_parse_token_string_t cmd_macsec_sc_set =
11972        TOKEN_STRING_INITIALIZER
11973                (struct cmd_macsec_sc_result,
11974                 set, "set");
11975cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11976        TOKEN_STRING_INITIALIZER
11977                (struct cmd_macsec_sc_result,
11978                 macsec, "macsec");
11979cmdline_parse_token_string_t cmd_macsec_sc_sc =
11980        TOKEN_STRING_INITIALIZER
11981                (struct cmd_macsec_sc_result,
11982                 sc, "sc");
11983cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11984        TOKEN_STRING_INITIALIZER
11985                (struct cmd_macsec_sc_result,
11986                 tx_rx, "tx#rx");
11987cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11988        TOKEN_NUM_INITIALIZER
11989                (struct cmd_macsec_sc_result,
11990                 port_id, RTE_UINT16);
11991cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11992        TOKEN_ETHERADDR_INITIALIZER
11993                (struct cmd_macsec_sc_result,
11994                 mac);
11995cmdline_parse_token_num_t cmd_macsec_sc_pi =
11996        TOKEN_NUM_INITIALIZER
11997                (struct cmd_macsec_sc_result,
11998                 pi, RTE_UINT16);
11999
12000static void
12001cmd_set_macsec_sc_parsed(
12002        void *parsed_result,
12003        __rte_unused struct cmdline *cl,
12004        __rte_unused void *data)
12005{
12006        struct cmd_macsec_sc_result *res = parsed_result;
12007        int ret = -ENOTSUP;
12008        int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12009
12010#ifdef RTE_NET_IXGBE
12011        ret = is_tx ?
12012                rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12013                                res->mac.addr_bytes) :
12014                rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12015                                res->mac.addr_bytes, res->pi);
12016#endif
12017        RTE_SET_USED(is_tx);
12018
12019        switch (ret) {
12020        case 0:
12021                break;
12022        case -ENODEV:
12023                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12024                break;
12025        case -ENOTSUP:
12026                fprintf(stderr, "not supported on port %d\n", res->port_id);
12027                break;
12028        default:
12029                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12030        }
12031}
12032
12033cmdline_parse_inst_t cmd_set_macsec_sc = {
12034        .f = cmd_set_macsec_sc_parsed,
12035        .data = NULL,
12036        .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12037        .tokens = {
12038                (void *)&cmd_macsec_sc_set,
12039                (void *)&cmd_macsec_sc_macsec,
12040                (void *)&cmd_macsec_sc_sc,
12041                (void *)&cmd_macsec_sc_tx_rx,
12042                (void *)&cmd_macsec_sc_port_id,
12043                (void *)&cmd_macsec_sc_mac,
12044                (void *)&cmd_macsec_sc_pi,
12045                NULL,
12046        },
12047};
12048
12049/* Common result structure for MACsec secure connection configure */
12050struct cmd_macsec_sa_result {
12051        cmdline_fixed_string_t set;
12052        cmdline_fixed_string_t macsec;
12053        cmdline_fixed_string_t sa;
12054        cmdline_fixed_string_t tx_rx;
12055        portid_t port_id;
12056        uint8_t idx;
12057        uint8_t an;
12058        uint32_t pn;
12059        cmdline_fixed_string_t key;
12060};
12061
12062/* Common CLI fields for MACsec secure connection configure */
12063cmdline_parse_token_string_t cmd_macsec_sa_set =
12064        TOKEN_STRING_INITIALIZER
12065                (struct cmd_macsec_sa_result,
12066                 set, "set");
12067cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12068        TOKEN_STRING_INITIALIZER
12069                (struct cmd_macsec_sa_result,
12070                 macsec, "macsec");
12071cmdline_parse_token_string_t cmd_macsec_sa_sa =
12072        TOKEN_STRING_INITIALIZER
12073                (struct cmd_macsec_sa_result,
12074                 sa, "sa");
12075cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12076        TOKEN_STRING_INITIALIZER
12077                (struct cmd_macsec_sa_result,
12078                 tx_rx, "tx#rx");
12079cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12080        TOKEN_NUM_INITIALIZER
12081                (struct cmd_macsec_sa_result,
12082                 port_id, RTE_UINT16);
12083cmdline_parse_token_num_t cmd_macsec_sa_idx =
12084        TOKEN_NUM_INITIALIZER
12085                (struct cmd_macsec_sa_result,
12086                 idx, RTE_UINT8);
12087cmdline_parse_token_num_t cmd_macsec_sa_an =
12088        TOKEN_NUM_INITIALIZER
12089                (struct cmd_macsec_sa_result,
12090                 an, RTE_UINT8);
12091cmdline_parse_token_num_t cmd_macsec_sa_pn =
12092        TOKEN_NUM_INITIALIZER
12093                (struct cmd_macsec_sa_result,
12094                 pn, RTE_UINT32);
12095cmdline_parse_token_string_t cmd_macsec_sa_key =
12096        TOKEN_STRING_INITIALIZER
12097                (struct cmd_macsec_sa_result,
12098                 key, NULL);
12099
12100static void
12101cmd_set_macsec_sa_parsed(
12102        void *parsed_result,
12103        __rte_unused struct cmdline *cl,
12104        __rte_unused void *data)
12105{
12106        struct cmd_macsec_sa_result *res = parsed_result;
12107        int ret = -ENOTSUP;
12108        int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12109        uint8_t key[16] = { 0 };
12110        uint8_t xdgt0;
12111        uint8_t xdgt1;
12112        int key_len;
12113        int i;
12114
12115        key_len = strlen(res->key) / 2;
12116        if (key_len > 16)
12117                key_len = 16;
12118
12119        for (i = 0; i < key_len; i++) {
12120                xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12121                if (xdgt0 == 0xFF)
12122                        return;
12123                xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12124                if (xdgt1 == 0xFF)
12125                        return;
12126                key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12127        }
12128
12129#ifdef RTE_NET_IXGBE
12130        ret = is_tx ?
12131                rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12132                        res->idx, res->an, res->pn, key) :
12133                rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12134                        res->idx, res->an, res->pn, key);
12135#endif
12136        RTE_SET_USED(is_tx);
12137        RTE_SET_USED(key);
12138
12139        switch (ret) {
12140        case 0:
12141                break;
12142        case -EINVAL:
12143                fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12144                break;
12145        case -ENODEV:
12146                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12147                break;
12148        case -ENOTSUP:
12149                fprintf(stderr, "not supported on port %d\n", res->port_id);
12150                break;
12151        default:
12152                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12153        }
12154}
12155
12156cmdline_parse_inst_t cmd_set_macsec_sa = {
12157        .f = cmd_set_macsec_sa_parsed,
12158        .data = NULL,
12159        .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12160        .tokens = {
12161                (void *)&cmd_macsec_sa_set,
12162                (void *)&cmd_macsec_sa_macsec,
12163                (void *)&cmd_macsec_sa_sa,
12164                (void *)&cmd_macsec_sa_tx_rx,
12165                (void *)&cmd_macsec_sa_port_id,
12166                (void *)&cmd_macsec_sa_idx,
12167                (void *)&cmd_macsec_sa_an,
12168                (void *)&cmd_macsec_sa_pn,
12169                (void *)&cmd_macsec_sa_key,
12170                NULL,
12171        },
12172};
12173
12174/* VF unicast promiscuous mode configuration */
12175
12176/* Common result structure for VF unicast promiscuous mode */
12177struct cmd_vf_promisc_result {
12178        cmdline_fixed_string_t set;
12179        cmdline_fixed_string_t vf;
12180        cmdline_fixed_string_t promisc;
12181        portid_t port_id;
12182        uint32_t vf_id;
12183        cmdline_fixed_string_t on_off;
12184};
12185
12186/* Common CLI fields for VF unicast promiscuous mode enable disable */
12187cmdline_parse_token_string_t cmd_vf_promisc_set =
12188        TOKEN_STRING_INITIALIZER
12189                (struct cmd_vf_promisc_result,
12190                 set, "set");
12191cmdline_parse_token_string_t cmd_vf_promisc_vf =
12192        TOKEN_STRING_INITIALIZER
12193                (struct cmd_vf_promisc_result,
12194                 vf, "vf");
12195cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12196        TOKEN_STRING_INITIALIZER
12197                (struct cmd_vf_promisc_result,
12198                 promisc, "promisc");
12199cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12200        TOKEN_NUM_INITIALIZER
12201                (struct cmd_vf_promisc_result,
12202                 port_id, RTE_UINT16);
12203cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12204        TOKEN_NUM_INITIALIZER
12205                (struct cmd_vf_promisc_result,
12206                 vf_id, RTE_UINT32);
12207cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12208        TOKEN_STRING_INITIALIZER
12209                (struct cmd_vf_promisc_result,
12210                 on_off, "on#off");
12211
12212static void
12213cmd_set_vf_promisc_parsed(
12214        void *parsed_result,
12215        __rte_unused struct cmdline *cl,
12216        __rte_unused void *data)
12217{
12218        struct cmd_vf_promisc_result *res = parsed_result;
12219        int ret = -ENOTSUP;
12220
12221        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12222
12223        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12224                return;
12225
12226#ifdef RTE_NET_I40E
12227        ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12228                                                  res->vf_id, is_on);
12229#endif
12230
12231        switch (ret) {
12232        case 0:
12233                break;
12234        case -EINVAL:
12235                fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12236                break;
12237        case -ENODEV:
12238                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12239                break;
12240        case -ENOTSUP:
12241                fprintf(stderr, "function not implemented\n");
12242                break;
12243        default:
12244                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12245        }
12246}
12247
12248cmdline_parse_inst_t cmd_set_vf_promisc = {
12249        .f = cmd_set_vf_promisc_parsed,
12250        .data = NULL,
12251        .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12252                "Set unicast promiscuous mode for a VF from the PF",
12253        .tokens = {
12254                (void *)&cmd_vf_promisc_set,
12255                (void *)&cmd_vf_promisc_vf,
12256                (void *)&cmd_vf_promisc_promisc,
12257                (void *)&cmd_vf_promisc_port_id,
12258                (void *)&cmd_vf_promisc_vf_id,
12259                (void *)&cmd_vf_promisc_on_off,
12260                NULL,
12261        },
12262};
12263
12264/* VF multicast promiscuous mode configuration */
12265
12266/* Common result structure for VF multicast promiscuous mode */
12267struct cmd_vf_allmulti_result {
12268        cmdline_fixed_string_t set;
12269        cmdline_fixed_string_t vf;
12270        cmdline_fixed_string_t allmulti;
12271        portid_t port_id;
12272        uint32_t vf_id;
12273        cmdline_fixed_string_t on_off;
12274};
12275
12276/* Common CLI fields for VF multicast promiscuous mode enable disable */
12277cmdline_parse_token_string_t cmd_vf_allmulti_set =
12278        TOKEN_STRING_INITIALIZER
12279                (struct cmd_vf_allmulti_result,
12280                 set, "set");
12281cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12282        TOKEN_STRING_INITIALIZER
12283                (struct cmd_vf_allmulti_result,
12284                 vf, "vf");
12285cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12286        TOKEN_STRING_INITIALIZER
12287                (struct cmd_vf_allmulti_result,
12288                 allmulti, "allmulti");
12289cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12290        TOKEN_NUM_INITIALIZER
12291                (struct cmd_vf_allmulti_result,
12292                 port_id, RTE_UINT16);
12293cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12294        TOKEN_NUM_INITIALIZER
12295                (struct cmd_vf_allmulti_result,
12296                 vf_id, RTE_UINT32);
12297cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12298        TOKEN_STRING_INITIALIZER
12299                (struct cmd_vf_allmulti_result,
12300                 on_off, "on#off");
12301
12302static void
12303cmd_set_vf_allmulti_parsed(
12304        void *parsed_result,
12305        __rte_unused struct cmdline *cl,
12306        __rte_unused void *data)
12307{
12308        struct cmd_vf_allmulti_result *res = parsed_result;
12309        int ret = -ENOTSUP;
12310
12311        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12312
12313        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12314                return;
12315
12316#ifdef RTE_NET_I40E
12317        ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12318                                                    res->vf_id, is_on);
12319#endif
12320
12321        switch (ret) {
12322        case 0:
12323                break;
12324        case -EINVAL:
12325                fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12326                break;
12327        case -ENODEV:
12328                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12329                break;
12330        case -ENOTSUP:
12331                fprintf(stderr, "function not implemented\n");
12332                break;
12333        default:
12334                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12335        }
12336}
12337
12338cmdline_parse_inst_t cmd_set_vf_allmulti = {
12339        .f = cmd_set_vf_allmulti_parsed,
12340        .data = NULL,
12341        .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12342                "Set multicast promiscuous mode for a VF from the PF",
12343        .tokens = {
12344                (void *)&cmd_vf_allmulti_set,
12345                (void *)&cmd_vf_allmulti_vf,
12346                (void *)&cmd_vf_allmulti_allmulti,
12347                (void *)&cmd_vf_allmulti_port_id,
12348                (void *)&cmd_vf_allmulti_vf_id,
12349                (void *)&cmd_vf_allmulti_on_off,
12350                NULL,
12351        },
12352};
12353
12354/* vf broadcast mode configuration */
12355
12356/* Common result structure for vf broadcast */
12357struct cmd_set_vf_broadcast_result {
12358        cmdline_fixed_string_t set;
12359        cmdline_fixed_string_t vf;
12360        cmdline_fixed_string_t broadcast;
12361        portid_t port_id;
12362        uint16_t vf_id;
12363        cmdline_fixed_string_t on_off;
12364};
12365
12366/* Common CLI fields for vf broadcast enable disable */
12367cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12368        TOKEN_STRING_INITIALIZER
12369                (struct cmd_set_vf_broadcast_result,
12370                 set, "set");
12371cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12372        TOKEN_STRING_INITIALIZER
12373                (struct cmd_set_vf_broadcast_result,
12374                 vf, "vf");
12375cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12376        TOKEN_STRING_INITIALIZER
12377                (struct cmd_set_vf_broadcast_result,
12378                 broadcast, "broadcast");
12379cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12380        TOKEN_NUM_INITIALIZER
12381                (struct cmd_set_vf_broadcast_result,
12382                 port_id, RTE_UINT16);
12383cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12384        TOKEN_NUM_INITIALIZER
12385                (struct cmd_set_vf_broadcast_result,
12386                 vf_id, RTE_UINT16);
12387cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12388        TOKEN_STRING_INITIALIZER
12389                (struct cmd_set_vf_broadcast_result,
12390                 on_off, "on#off");
12391
12392static void
12393cmd_set_vf_broadcast_parsed(
12394        void *parsed_result,
12395        __rte_unused struct cmdline *cl,
12396        __rte_unused void *data)
12397{
12398        struct cmd_set_vf_broadcast_result *res = parsed_result;
12399        int ret = -ENOTSUP;
12400
12401        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12402
12403        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12404                return;
12405
12406#ifdef RTE_NET_I40E
12407        ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12408                                            res->vf_id, is_on);
12409#endif
12410
12411        switch (ret) {
12412        case 0:
12413                break;
12414        case -EINVAL:
12415                fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12416                        res->vf_id, is_on);
12417                break;
12418        case -ENODEV:
12419                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12420                break;
12421        case -ENOTSUP:
12422                fprintf(stderr, "function not implemented\n");
12423                break;
12424        default:
12425                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12426        }
12427}
12428
12429cmdline_parse_inst_t cmd_set_vf_broadcast = {
12430        .f = cmd_set_vf_broadcast_parsed,
12431        .data = NULL,
12432        .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12433        .tokens = {
12434                (void *)&cmd_set_vf_broadcast_set,
12435                (void *)&cmd_set_vf_broadcast_vf,
12436                (void *)&cmd_set_vf_broadcast_broadcast,
12437                (void *)&cmd_set_vf_broadcast_port_id,
12438                (void *)&cmd_set_vf_broadcast_vf_id,
12439                (void *)&cmd_set_vf_broadcast_on_off,
12440                NULL,
12441        },
12442};
12443
12444/* vf vlan tag configuration */
12445
12446/* Common result structure for vf vlan tag */
12447struct cmd_set_vf_vlan_tag_result {
12448        cmdline_fixed_string_t set;
12449        cmdline_fixed_string_t vf;
12450        cmdline_fixed_string_t vlan;
12451        cmdline_fixed_string_t tag;
12452        portid_t port_id;
12453        uint16_t vf_id;
12454        cmdline_fixed_string_t on_off;
12455};
12456
12457/* Common CLI fields for vf vlan tag enable disable */
12458cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12459        TOKEN_STRING_INITIALIZER
12460                (struct cmd_set_vf_vlan_tag_result,
12461                 set, "set");
12462cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12463        TOKEN_STRING_INITIALIZER
12464                (struct cmd_set_vf_vlan_tag_result,
12465                 vf, "vf");
12466cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12467        TOKEN_STRING_INITIALIZER
12468                (struct cmd_set_vf_vlan_tag_result,
12469                 vlan, "vlan");
12470cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12471        TOKEN_STRING_INITIALIZER
12472                (struct cmd_set_vf_vlan_tag_result,
12473                 tag, "tag");
12474cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12475        TOKEN_NUM_INITIALIZER
12476                (struct cmd_set_vf_vlan_tag_result,
12477                 port_id, RTE_UINT16);
12478cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12479        TOKEN_NUM_INITIALIZER
12480                (struct cmd_set_vf_vlan_tag_result,
12481                 vf_id, RTE_UINT16);
12482cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12483        TOKEN_STRING_INITIALIZER
12484                (struct cmd_set_vf_vlan_tag_result,
12485                 on_off, "on#off");
12486
12487static void
12488cmd_set_vf_vlan_tag_parsed(
12489        void *parsed_result,
12490        __rte_unused struct cmdline *cl,
12491        __rte_unused void *data)
12492{
12493        struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12494        int ret = -ENOTSUP;
12495
12496        __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12497
12498        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12499                return;
12500
12501#ifdef RTE_NET_I40E
12502        ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12503                                           res->vf_id, is_on);
12504#endif
12505
12506        switch (ret) {
12507        case 0:
12508                break;
12509        case -EINVAL:
12510                fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12511                        res->vf_id, is_on);
12512                break;
12513        case -ENODEV:
12514                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12515                break;
12516        case -ENOTSUP:
12517                fprintf(stderr, "function not implemented\n");
12518                break;
12519        default:
12520                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12521        }
12522}
12523
12524cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12525        .f = cmd_set_vf_vlan_tag_parsed,
12526        .data = NULL,
12527        .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12528        .tokens = {
12529                (void *)&cmd_set_vf_vlan_tag_set,
12530                (void *)&cmd_set_vf_vlan_tag_vf,
12531                (void *)&cmd_set_vf_vlan_tag_vlan,
12532                (void *)&cmd_set_vf_vlan_tag_tag,
12533                (void *)&cmd_set_vf_vlan_tag_port_id,
12534                (void *)&cmd_set_vf_vlan_tag_vf_id,
12535                (void *)&cmd_set_vf_vlan_tag_on_off,
12536                NULL,
12537        },
12538};
12539
12540/* Common definition of VF and TC TX bandwidth configuration */
12541struct cmd_vf_tc_bw_result {
12542        cmdline_fixed_string_t set;
12543        cmdline_fixed_string_t vf;
12544        cmdline_fixed_string_t tc;
12545        cmdline_fixed_string_t tx;
12546        cmdline_fixed_string_t min_bw;
12547        cmdline_fixed_string_t max_bw;
12548        cmdline_fixed_string_t strict_link_prio;
12549        portid_t port_id;
12550        uint16_t vf_id;
12551        uint8_t tc_no;
12552        uint32_t bw;
12553        cmdline_fixed_string_t bw_list;
12554        uint8_t tc_map;
12555};
12556
12557cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12558        TOKEN_STRING_INITIALIZER
12559                (struct cmd_vf_tc_bw_result,
12560                 set, "set");
12561cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12562        TOKEN_STRING_INITIALIZER
12563                (struct cmd_vf_tc_bw_result,
12564                 vf, "vf");
12565cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12566        TOKEN_STRING_INITIALIZER
12567                (struct cmd_vf_tc_bw_result,
12568                 tc, "tc");
12569cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12570        TOKEN_STRING_INITIALIZER
12571                (struct cmd_vf_tc_bw_result,
12572                 tx, "tx");
12573cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12574        TOKEN_STRING_INITIALIZER
12575                (struct cmd_vf_tc_bw_result,
12576                 strict_link_prio, "strict-link-priority");
12577cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12578        TOKEN_STRING_INITIALIZER
12579                (struct cmd_vf_tc_bw_result,
12580                 min_bw, "min-bandwidth");
12581cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12582        TOKEN_STRING_INITIALIZER
12583                (struct cmd_vf_tc_bw_result,
12584                 max_bw, "max-bandwidth");
12585cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12586        TOKEN_NUM_INITIALIZER
12587                (struct cmd_vf_tc_bw_result,
12588                 port_id, RTE_UINT16);
12589cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12590        TOKEN_NUM_INITIALIZER
12591                (struct cmd_vf_tc_bw_result,
12592                 vf_id, RTE_UINT16);
12593cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12594        TOKEN_NUM_INITIALIZER
12595                (struct cmd_vf_tc_bw_result,
12596                 tc_no, RTE_UINT8);
12597cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12598        TOKEN_NUM_INITIALIZER
12599                (struct cmd_vf_tc_bw_result,
12600                 bw, RTE_UINT32);
12601cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12602        TOKEN_STRING_INITIALIZER
12603                (struct cmd_vf_tc_bw_result,
12604                 bw_list, NULL);
12605cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12606        TOKEN_NUM_INITIALIZER
12607                (struct cmd_vf_tc_bw_result,
12608                 tc_map, RTE_UINT8);
12609
12610/* VF max bandwidth setting */
12611static void
12612cmd_vf_max_bw_parsed(
12613        void *parsed_result,
12614        __rte_unused struct cmdline *cl,
12615        __rte_unused void *data)
12616{
12617        struct cmd_vf_tc_bw_result *res = parsed_result;
12618        int ret = -ENOTSUP;
12619
12620        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12621                return;
12622
12623#ifdef RTE_NET_I40E
12624        ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12625                                         res->vf_id, res->bw);
12626#endif
12627
12628        switch (ret) {
12629        case 0:
12630                break;
12631        case -EINVAL:
12632                fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12633                        res->vf_id, res->bw);
12634                break;
12635        case -ENODEV:
12636                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12637                break;
12638        case -ENOTSUP:
12639                fprintf(stderr, "function not implemented\n");
12640                break;
12641        default:
12642                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12643        }
12644}
12645
12646cmdline_parse_inst_t cmd_vf_max_bw = {
12647        .f = cmd_vf_max_bw_parsed,
12648        .data = NULL,
12649        .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12650        .tokens = {
12651                (void *)&cmd_vf_tc_bw_set,
12652                (void *)&cmd_vf_tc_bw_vf,
12653                (void *)&cmd_vf_tc_bw_tx,
12654                (void *)&cmd_vf_tc_bw_max_bw,
12655                (void *)&cmd_vf_tc_bw_port_id,
12656                (void *)&cmd_vf_tc_bw_vf_id,
12657                (void *)&cmd_vf_tc_bw_bw,
12658                NULL,
12659        },
12660};
12661
12662static int
12663vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12664                           uint8_t *tc_num,
12665                           char *str)
12666{
12667        uint32_t size;
12668        const char *p, *p0 = str;
12669        char s[256];
12670        char *end;
12671        char *str_fld[16];
12672        uint16_t i;
12673        int ret;
12674
12675        p = strchr(p0, '(');
12676        if (p == NULL) {
12677                fprintf(stderr,
12678                        "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12679                return -1;
12680        }
12681        p++;
12682        p0 = strchr(p, ')');
12683        if (p0 == NULL) {
12684                fprintf(stderr,
12685                        "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12686                return -1;
12687        }
12688        size = p0 - p;
12689        if (size >= sizeof(s)) {
12690                fprintf(stderr,
12691                        "The string size exceeds the internal buffer size\n");
12692                return -1;
12693        }
12694        snprintf(s, sizeof(s), "%.*s", size, p);
12695        ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12696        if (ret <= 0) {
12697                fprintf(stderr, "Failed to get the bandwidth list.\n");
12698                return -1;
12699        }
12700        *tc_num = ret;
12701        for (i = 0; i < ret; i++)
12702                bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12703
12704        return 0;
12705}
12706
12707/* TC min bandwidth setting */
12708static void
12709cmd_vf_tc_min_bw_parsed(
12710        void *parsed_result,
12711        __rte_unused struct cmdline *cl,
12712        __rte_unused void *data)
12713{
12714        struct cmd_vf_tc_bw_result *res = parsed_result;
12715        uint8_t tc_num;
12716        uint8_t bw[16];
12717        int ret = -ENOTSUP;
12718
12719        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12720                return;
12721
12722        ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12723        if (ret)
12724                return;
12725
12726#ifdef RTE_NET_I40E
12727        ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12728                                              tc_num, bw);
12729#endif
12730
12731        switch (ret) {
12732        case 0:
12733                break;
12734        case -EINVAL:
12735                fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12736                break;
12737        case -ENODEV:
12738                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12739                break;
12740        case -ENOTSUP:
12741                fprintf(stderr, "function not implemented\n");
12742                break;
12743        default:
12744                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12745        }
12746}
12747
12748cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12749        .f = cmd_vf_tc_min_bw_parsed,
12750        .data = NULL,
12751        .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12752                    " <bw1, bw2, ...>",
12753        .tokens = {
12754                (void *)&cmd_vf_tc_bw_set,
12755                (void *)&cmd_vf_tc_bw_vf,
12756                (void *)&cmd_vf_tc_bw_tc,
12757                (void *)&cmd_vf_tc_bw_tx,
12758                (void *)&cmd_vf_tc_bw_min_bw,
12759                (void *)&cmd_vf_tc_bw_port_id,
12760                (void *)&cmd_vf_tc_bw_vf_id,
12761                (void *)&cmd_vf_tc_bw_bw_list,
12762                NULL,
12763        },
12764};
12765
12766static void
12767cmd_tc_min_bw_parsed(
12768        void *parsed_result,
12769        __rte_unused struct cmdline *cl,
12770        __rte_unused void *data)
12771{
12772        struct cmd_vf_tc_bw_result *res = parsed_result;
12773        struct rte_port *port;
12774        uint8_t tc_num;
12775        uint8_t bw[16];
12776        int ret = -ENOTSUP;
12777
12778        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12779                return;
12780
12781        port = &ports[res->port_id];
12782        /** Check if the port is not started **/
12783        if (port->port_status != RTE_PORT_STOPPED) {
12784                fprintf(stderr, "Please stop port %d first\n", res->port_id);
12785                return;
12786        }
12787
12788        ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12789        if (ret)
12790                return;
12791
12792#ifdef RTE_NET_IXGBE
12793        ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12794#endif
12795
12796        switch (ret) {
12797        case 0:
12798                break;
12799        case -EINVAL:
12800                fprintf(stderr, "invalid bandwidth\n");
12801                break;
12802        case -ENODEV:
12803                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12804                break;
12805        case -ENOTSUP:
12806                fprintf(stderr, "function not implemented\n");
12807                break;
12808        default:
12809                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12810        }
12811}
12812
12813cmdline_parse_inst_t cmd_tc_min_bw = {
12814        .f = cmd_tc_min_bw_parsed,
12815        .data = NULL,
12816        .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12817        .tokens = {
12818                (void *)&cmd_vf_tc_bw_set,
12819                (void *)&cmd_vf_tc_bw_tc,
12820                (void *)&cmd_vf_tc_bw_tx,
12821                (void *)&cmd_vf_tc_bw_min_bw,
12822                (void *)&cmd_vf_tc_bw_port_id,
12823                (void *)&cmd_vf_tc_bw_bw_list,
12824                NULL,
12825        },
12826};
12827
12828/* TC max bandwidth setting */
12829static void
12830cmd_vf_tc_max_bw_parsed(
12831        void *parsed_result,
12832        __rte_unused struct cmdline *cl,
12833        __rte_unused void *data)
12834{
12835        struct cmd_vf_tc_bw_result *res = parsed_result;
12836        int ret = -ENOTSUP;
12837
12838        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12839                return;
12840
12841#ifdef RTE_NET_I40E
12842        ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12843                                            res->tc_no, res->bw);
12844#endif
12845
12846        switch (ret) {
12847        case 0:
12848                break;
12849        case -EINVAL:
12850                fprintf(stderr,
12851                        "invalid vf_id %d, tc_no %d or bandwidth %d\n",
12852                        res->vf_id, res->tc_no, res->bw);
12853                break;
12854        case -ENODEV:
12855                fprintf(stderr, "invalid port_id %d\n", res->port_id);
12856                break;
12857        case -ENOTSUP:
12858                fprintf(stderr, "function not implemented\n");
12859                break;
12860        default:
12861                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12862        }
12863}
12864
12865cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12866        .f = cmd_vf_tc_max_bw_parsed,
12867        .data = NULL,
12868        .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12869                    " <bandwidth>",
12870        .tokens = {
12871                (void *)&cmd_vf_tc_bw_set,
12872                (void *)&cmd_vf_tc_bw_vf,
12873                (void *)&cmd_vf_tc_bw_tc,
12874                (void *)&cmd_vf_tc_bw_tx,
12875                (void *)&cmd_vf_tc_bw_max_bw,
12876                (void *)&cmd_vf_tc_bw_port_id,
12877                (void *)&cmd_vf_tc_bw_vf_id,
12878                (void *)&cmd_vf_tc_bw_tc_no,
12879                (void *)&cmd_vf_tc_bw_bw,
12880                NULL,
12881        },
12882};
12883
12884/** Set VXLAN encapsulation details */
12885struct cmd_set_vxlan_result {
12886        cmdline_fixed_string_t set;
12887        cmdline_fixed_string_t vxlan;
12888        cmdline_fixed_string_t pos_token;
12889        cmdline_fixed_string_t ip_version;
12890        uint32_t vlan_present:1;
12891        uint32_t vni;
12892        uint16_t udp_src;
12893        uint16_t udp_dst;
12894        cmdline_ipaddr_t ip_src;
12895        cmdline_ipaddr_t ip_dst;
12896        uint16_t tci;
12897        uint8_t tos;
12898        uint8_t ttl;
12899        struct rte_ether_addr eth_src;
12900        struct rte_ether_addr eth_dst;
12901};
12902
12903cmdline_parse_token_string_t cmd_set_vxlan_set =
12904        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12905cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12906        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12907cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12908        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12909                                 "vxlan-tos-ttl");
12910cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12911        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12912                                 "vxlan-with-vlan");
12913cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12914        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12915                                 "ip-version");
12916cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12917        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12918                                 "ipv4#ipv6");
12919cmdline_parse_token_string_t cmd_set_vxlan_vni =
12920        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12921                                 "vni");
12922cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12923        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12924cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12925        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12926                                 "udp-src");
12927cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12928        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12929cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12930        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12931                                 "udp-dst");
12932cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12933        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12934cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12935        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12936                                 "ip-tos");
12937cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12938        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12939cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12940        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12941                                 "ip-ttl");
12942cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12943        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12944cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12945        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12946                                 "ip-src");
12947cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12948        TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12949cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12950        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12951                                 "ip-dst");
12952cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12953        TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12954cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12955        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12956                                 "vlan-tci");
12957cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12958        TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12959cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12960        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12961                                 "eth-src");
12962cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12963        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12964cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12965        TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12966                                 "eth-dst");
12967cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12968        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12969
12970static void cmd_set_vxlan_parsed(void *parsed_result,
12971        __rte_unused struct cmdline *cl,
12972        __rte_unused void *data)
12973{
12974        struct cmd_set_vxlan_result *res = parsed_result;
12975        union {
12976                uint32_t vxlan_id;
12977                uint8_t vni[4];
12978        } id = {
12979                .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12980        };
12981
12982        vxlan_encap_conf.select_tos_ttl = 0;
12983        if (strcmp(res->vxlan, "vxlan") == 0)
12984                vxlan_encap_conf.select_vlan = 0;
12985        else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12986                vxlan_encap_conf.select_vlan = 1;
12987        else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12988                vxlan_encap_conf.select_vlan = 0;
12989                vxlan_encap_conf.select_tos_ttl = 1;
12990        }
12991        if (strcmp(res->ip_version, "ipv4") == 0)
12992                vxlan_encap_conf.select_ipv4 = 1;
12993        else if (strcmp(res->ip_version, "ipv6") == 0)
12994                vxlan_encap_conf.select_ipv4 = 0;
12995        else
12996                return;
12997        rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12998        vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12999        vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13000        vxlan_encap_conf.ip_tos = res->tos;
13001        vxlan_encap_conf.ip_ttl = res->ttl;
13002        if (vxlan_encap_conf.select_ipv4) {
13003                IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13004                IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13005        } else {
13006                IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13007                IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13008        }
13009        if (vxlan_encap_conf.select_vlan)
13010                vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13011        rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13012                   RTE_ETHER_ADDR_LEN);
13013        rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13014                   RTE_ETHER_ADDR_LEN);
13015}
13016
13017cmdline_parse_inst_t cmd_set_vxlan = {
13018        .f = cmd_set_vxlan_parsed,
13019        .data = NULL,
13020        .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13021                " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13022                " eth-src <eth-src> eth-dst <eth-dst>",
13023        .tokens = {
13024                (void *)&cmd_set_vxlan_set,
13025                (void *)&cmd_set_vxlan_vxlan,
13026                (void *)&cmd_set_vxlan_ip_version,
13027                (void *)&cmd_set_vxlan_ip_version_value,
13028                (void *)&cmd_set_vxlan_vni,
13029                (void *)&cmd_set_vxlan_vni_value,
13030                (void *)&cmd_set_vxlan_udp_src,
13031                (void *)&cmd_set_vxlan_udp_src_value,
13032                (void *)&cmd_set_vxlan_udp_dst,
13033                (void *)&cmd_set_vxlan_udp_dst_value,
13034                (void *)&cmd_set_vxlan_ip_src,
13035                (void *)&cmd_set_vxlan_ip_src_value,
13036                (void *)&cmd_set_vxlan_ip_dst,
13037                (void *)&cmd_set_vxlan_ip_dst_value,
13038                (void *)&cmd_set_vxlan_eth_src,
13039                (void *)&cmd_set_vxlan_eth_src_value,
13040                (void *)&cmd_set_vxlan_eth_dst,
13041                (void *)&cmd_set_vxlan_eth_dst_value,
13042                NULL,
13043        },
13044};
13045
13046cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13047        .f = cmd_set_vxlan_parsed,
13048        .data = NULL,
13049        .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13050                " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13051                " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13052                " eth-dst <eth-dst>",
13053        .tokens = {
13054                (void *)&cmd_set_vxlan_set,
13055                (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13056                (void *)&cmd_set_vxlan_ip_version,
13057                (void *)&cmd_set_vxlan_ip_version_value,
13058                (void *)&cmd_set_vxlan_vni,
13059                (void *)&cmd_set_vxlan_vni_value,
13060                (void *)&cmd_set_vxlan_udp_src,
13061                (void *)&cmd_set_vxlan_udp_src_value,
13062                (void *)&cmd_set_vxlan_udp_dst,
13063                (void *)&cmd_set_vxlan_udp_dst_value,
13064                (void *)&cmd_set_vxlan_ip_tos,
13065                (void *)&cmd_set_vxlan_ip_tos_value,
13066                (void *)&cmd_set_vxlan_ip_ttl,
13067                (void *)&cmd_set_vxlan_ip_ttl_value,
13068                (void *)&cmd_set_vxlan_ip_src,
13069                (void *)&cmd_set_vxlan_ip_src_value,
13070                (void *)&cmd_set_vxlan_ip_dst,
13071                (void *)&cmd_set_vxlan_ip_dst_value,
13072                (void *)&cmd_set_vxlan_eth_src,
13073                (void *)&cmd_set_vxlan_eth_src_value,
13074                (void *)&cmd_set_vxlan_eth_dst,
13075                (void *)&cmd_set_vxlan_eth_dst_value,
13076                NULL,
13077        },
13078};
13079
13080cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13081        .f = cmd_set_vxlan_parsed,
13082        .data = NULL,
13083        .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13084                " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13085                " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13086                " <eth-dst>",
13087        .tokens = {
13088                (void *)&cmd_set_vxlan_set,
13089                (void *)&cmd_set_vxlan_vxlan_with_vlan,
13090                (void *)&cmd_set_vxlan_ip_version,
13091                (void *)&cmd_set_vxlan_ip_version_value,
13092                (void *)&cmd_set_vxlan_vni,
13093                (void *)&cmd_set_vxlan_vni_value,
13094                (void *)&cmd_set_vxlan_udp_src,
13095                (void *)&cmd_set_vxlan_udp_src_value,
13096                (void *)&cmd_set_vxlan_udp_dst,
13097                (void *)&cmd_set_vxlan_udp_dst_value,
13098                (void *)&cmd_set_vxlan_ip_src,
13099                (void *)&cmd_set_vxlan_ip_src_value,
13100                (void *)&cmd_set_vxlan_ip_dst,
13101                (void *)&cmd_set_vxlan_ip_dst_value,
13102                (void *)&cmd_set_vxlan_vlan,
13103                (void *)&cmd_set_vxlan_vlan_value,
13104                (void *)&cmd_set_vxlan_eth_src,
13105                (void *)&cmd_set_vxlan_eth_src_value,
13106                (void *)&cmd_set_vxlan_eth_dst,
13107                (void *)&cmd_set_vxlan_eth_dst_value,
13108                NULL,
13109        },
13110};
13111
13112/** Set NVGRE encapsulation details */
13113struct cmd_set_nvgre_result {
13114        cmdline_fixed_string_t set;
13115        cmdline_fixed_string_t nvgre;
13116        cmdline_fixed_string_t pos_token;
13117        cmdline_fixed_string_t ip_version;
13118        uint32_t tni;
13119        cmdline_ipaddr_t ip_src;
13120        cmdline_ipaddr_t ip_dst;
13121        uint16_t tci;
13122        struct rte_ether_addr eth_src;
13123        struct rte_ether_addr eth_dst;
13124};
13125
13126cmdline_parse_token_string_t cmd_set_nvgre_set =
13127        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13128cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13129        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13130cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13131        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13132                                 "nvgre-with-vlan");
13133cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13134        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13135                                 "ip-version");
13136cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13137        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13138                                 "ipv4#ipv6");
13139cmdline_parse_token_string_t cmd_set_nvgre_tni =
13140        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13141                                 "tni");
13142cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13143        TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13144cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13145        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13146                                 "ip-src");
13147cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13148        TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13149cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13150        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13151                                 "ip-dst");
13152cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13153        TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13154cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13155        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13156                                 "vlan-tci");
13157cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13158        TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13159cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13160        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13161                                 "eth-src");
13162cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13163        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13164cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13165        TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13166                                 "eth-dst");
13167cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13168        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13169
13170static void cmd_set_nvgre_parsed(void *parsed_result,
13171        __rte_unused struct cmdline *cl,
13172        __rte_unused void *data)
13173{
13174        struct cmd_set_nvgre_result *res = parsed_result;
13175        union {
13176                uint32_t nvgre_tni;
13177                uint8_t tni[4];
13178        } id = {
13179                .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13180        };
13181
13182        if (strcmp(res->nvgre, "nvgre") == 0)
13183                nvgre_encap_conf.select_vlan = 0;
13184        else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13185                nvgre_encap_conf.select_vlan = 1;
13186        if (strcmp(res->ip_version, "ipv4") == 0)
13187                nvgre_encap_conf.select_ipv4 = 1;
13188        else if (strcmp(res->ip_version, "ipv6") == 0)
13189                nvgre_encap_conf.select_ipv4 = 0;
13190        else
13191                return;
13192        rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13193        if (nvgre_encap_conf.select_ipv4) {
13194                IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13195                IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13196        } else {
13197                IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13198                IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13199        }
13200        if (nvgre_encap_conf.select_vlan)
13201                nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13202        rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13203                   RTE_ETHER_ADDR_LEN);
13204        rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13205                   RTE_ETHER_ADDR_LEN);
13206}
13207
13208cmdline_parse_inst_t cmd_set_nvgre = {
13209        .f = cmd_set_nvgre_parsed,
13210        .data = NULL,
13211        .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13212                " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13213                " eth-dst <eth-dst>",
13214        .tokens = {
13215                (void *)&cmd_set_nvgre_set,
13216                (void *)&cmd_set_nvgre_nvgre,
13217                (void *)&cmd_set_nvgre_ip_version,
13218                (void *)&cmd_set_nvgre_ip_version_value,
13219                (void *)&cmd_set_nvgre_tni,
13220                (void *)&cmd_set_nvgre_tni_value,
13221                (void *)&cmd_set_nvgre_ip_src,
13222                (void *)&cmd_set_nvgre_ip_src_value,
13223                (void *)&cmd_set_nvgre_ip_dst,
13224                (void *)&cmd_set_nvgre_ip_dst_value,
13225                (void *)&cmd_set_nvgre_eth_src,
13226                (void *)&cmd_set_nvgre_eth_src_value,
13227                (void *)&cmd_set_nvgre_eth_dst,
13228                (void *)&cmd_set_nvgre_eth_dst_value,
13229                NULL,
13230        },
13231};
13232
13233cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13234        .f = cmd_set_nvgre_parsed,
13235        .data = NULL,
13236        .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13237                " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13238                " eth-src <eth-src> eth-dst <eth-dst>",
13239        .tokens = {
13240                (void *)&cmd_set_nvgre_set,
13241                (void *)&cmd_set_nvgre_nvgre_with_vlan,
13242                (void *)&cmd_set_nvgre_ip_version,
13243                (void *)&cmd_set_nvgre_ip_version_value,
13244                (void *)&cmd_set_nvgre_tni,
13245                (void *)&cmd_set_nvgre_tni_value,
13246                (void *)&cmd_set_nvgre_ip_src,
13247                (void *)&cmd_set_nvgre_ip_src_value,
13248                (void *)&cmd_set_nvgre_ip_dst,
13249                (void *)&cmd_set_nvgre_ip_dst_value,
13250                (void *)&cmd_set_nvgre_vlan,
13251                (void *)&cmd_set_nvgre_vlan_value,
13252                (void *)&cmd_set_nvgre_eth_src,
13253                (void *)&cmd_set_nvgre_eth_src_value,
13254                (void *)&cmd_set_nvgre_eth_dst,
13255                (void *)&cmd_set_nvgre_eth_dst_value,
13256                NULL,
13257        },
13258};
13259
13260/** Set L2 encapsulation details */
13261struct cmd_set_l2_encap_result {
13262        cmdline_fixed_string_t set;
13263        cmdline_fixed_string_t l2_encap;
13264        cmdline_fixed_string_t pos_token;
13265        cmdline_fixed_string_t ip_version;
13266        uint32_t vlan_present:1;
13267        uint16_t tci;
13268        struct rte_ether_addr eth_src;
13269        struct rte_ether_addr eth_dst;
13270};
13271
13272cmdline_parse_token_string_t cmd_set_l2_encap_set =
13273        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13274cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13275        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13276cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13277        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13278                                 "l2_encap-with-vlan");
13279cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13280        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13281                                 "ip-version");
13282cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13283        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13284                                 "ipv4#ipv6");
13285cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13286        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13287                                 "vlan-tci");
13288cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13289        TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13290cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13291        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13292                                 "eth-src");
13293cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13294        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13295cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13296        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13297                                 "eth-dst");
13298cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13299        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13300
13301static void cmd_set_l2_encap_parsed(void *parsed_result,
13302        __rte_unused struct cmdline *cl,
13303        __rte_unused void *data)
13304{
13305        struct cmd_set_l2_encap_result *res = parsed_result;
13306
13307        if (strcmp(res->l2_encap, "l2_encap") == 0)
13308                l2_encap_conf.select_vlan = 0;
13309        else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13310                l2_encap_conf.select_vlan = 1;
13311        if (strcmp(res->ip_version, "ipv4") == 0)
13312                l2_encap_conf.select_ipv4 = 1;
13313        else if (strcmp(res->ip_version, "ipv6") == 0)
13314                l2_encap_conf.select_ipv4 = 0;
13315        else
13316                return;
13317        if (l2_encap_conf.select_vlan)
13318                l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13319        rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13320                   RTE_ETHER_ADDR_LEN);
13321        rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13322                   RTE_ETHER_ADDR_LEN);
13323}
13324
13325cmdline_parse_inst_t cmd_set_l2_encap = {
13326        .f = cmd_set_l2_encap_parsed,
13327        .data = NULL,
13328        .help_str = "set l2_encap ip-version ipv4|ipv6"
13329                " eth-src <eth-src> eth-dst <eth-dst>",
13330        .tokens = {
13331                (void *)&cmd_set_l2_encap_set,
13332                (void *)&cmd_set_l2_encap_l2_encap,
13333                (void *)&cmd_set_l2_encap_ip_version,
13334                (void *)&cmd_set_l2_encap_ip_version_value,
13335                (void *)&cmd_set_l2_encap_eth_src,
13336                (void *)&cmd_set_l2_encap_eth_src_value,
13337                (void *)&cmd_set_l2_encap_eth_dst,
13338                (void *)&cmd_set_l2_encap_eth_dst_value,
13339                NULL,
13340        },
13341};
13342
13343cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13344        .f = cmd_set_l2_encap_parsed,
13345        .data = NULL,
13346        .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13347                " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13348        .tokens = {
13349                (void *)&cmd_set_l2_encap_set,
13350                (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13351                (void *)&cmd_set_l2_encap_ip_version,
13352                (void *)&cmd_set_l2_encap_ip_version_value,
13353                (void *)&cmd_set_l2_encap_vlan,
13354                (void *)&cmd_set_l2_encap_vlan_value,
13355                (void *)&cmd_set_l2_encap_eth_src,
13356                (void *)&cmd_set_l2_encap_eth_src_value,
13357                (void *)&cmd_set_l2_encap_eth_dst,
13358                (void *)&cmd_set_l2_encap_eth_dst_value,
13359                NULL,
13360        },
13361};
13362
13363/** Set L2 decapsulation details */
13364struct cmd_set_l2_decap_result {
13365        cmdline_fixed_string_t set;
13366        cmdline_fixed_string_t l2_decap;
13367        cmdline_fixed_string_t pos_token;
13368        uint32_t vlan_present:1;
13369};
13370
13371cmdline_parse_token_string_t cmd_set_l2_decap_set =
13372        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13373cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13374        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13375                                 "l2_decap");
13376cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13377        TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13378                                 "l2_decap-with-vlan");
13379
13380static void cmd_set_l2_decap_parsed(void *parsed_result,
13381        __rte_unused struct cmdline *cl,
13382        __rte_unused void *data)
13383{
13384        struct cmd_set_l2_decap_result *res = parsed_result;
13385
13386        if (strcmp(res->l2_decap, "l2_decap") == 0)
13387                l2_decap_conf.select_vlan = 0;
13388        else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13389                l2_decap_conf.select_vlan = 1;
13390}
13391
13392cmdline_parse_inst_t cmd_set_l2_decap = {
13393        .f = cmd_set_l2_decap_parsed,
13394        .data = NULL,
13395        .help_str = "set l2_decap",
13396        .tokens = {
13397                (void *)&cmd_set_l2_decap_set,
13398                (void *)&cmd_set_l2_decap_l2_decap,
13399                NULL,
13400        },
13401};
13402
13403cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13404        .f = cmd_set_l2_decap_parsed,
13405        .data = NULL,
13406        .help_str = "set l2_decap-with-vlan",
13407        .tokens = {
13408                (void *)&cmd_set_l2_decap_set,
13409                (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13410                NULL,
13411        },
13412};
13413
13414/** Set MPLSoGRE encapsulation details */
13415struct cmd_set_mplsogre_encap_result {
13416        cmdline_fixed_string_t set;
13417        cmdline_fixed_string_t mplsogre;
13418        cmdline_fixed_string_t pos_token;
13419        cmdline_fixed_string_t ip_version;
13420        uint32_t vlan_present:1;
13421        uint32_t label;
13422        cmdline_ipaddr_t ip_src;
13423        cmdline_ipaddr_t ip_dst;
13424        uint16_t tci;
13425        struct rte_ether_addr eth_src;
13426        struct rte_ether_addr eth_dst;
13427};
13428
13429cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13430        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13431                                 "set");
13432cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13433        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13434                                 "mplsogre_encap");
13435cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13436        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13437                                 mplsogre, "mplsogre_encap-with-vlan");
13438cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13439        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13440                                 pos_token, "ip-version");
13441cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13442        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13443                                 ip_version, "ipv4#ipv6");
13444cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13445        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13446                                 pos_token, "label");
13447cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13448        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13449                              RTE_UINT32);
13450cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13451        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13452                                 pos_token, "ip-src");
13453cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13454        TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13455cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13456        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13457                                 pos_token, "ip-dst");
13458cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13459        TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13460cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13461        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13462                                 pos_token, "vlan-tci");
13463cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13464        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13465                              RTE_UINT16);
13466cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13467        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13468                                 pos_token, "eth-src");
13469cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13470        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13471                                    eth_src);
13472cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13473        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13474                                 pos_token, "eth-dst");
13475cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13476        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13477                                    eth_dst);
13478
13479static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13480        __rte_unused struct cmdline *cl,
13481        __rte_unused void *data)
13482{
13483        struct cmd_set_mplsogre_encap_result *res = parsed_result;
13484        union {
13485                uint32_t mplsogre_label;
13486                uint8_t label[4];
13487        } id = {
13488                .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13489        };
13490
13491        if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13492                mplsogre_encap_conf.select_vlan = 0;
13493        else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13494                mplsogre_encap_conf.select_vlan = 1;
13495        if (strcmp(res->ip_version, "ipv4") == 0)
13496                mplsogre_encap_conf.select_ipv4 = 1;
13497        else if (strcmp(res->ip_version, "ipv6") == 0)
13498                mplsogre_encap_conf.select_ipv4 = 0;
13499        else
13500                return;
13501        rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13502        if (mplsogre_encap_conf.select_ipv4) {
13503                IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13504                IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13505        } else {
13506                IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13507                IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13508        }
13509        if (mplsogre_encap_conf.select_vlan)
13510                mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13511        rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13512                   RTE_ETHER_ADDR_LEN);
13513        rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13514                   RTE_ETHER_ADDR_LEN);
13515}
13516
13517cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13518        .f = cmd_set_mplsogre_encap_parsed,
13519        .data = NULL,
13520        .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13521                " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13522                " eth-dst <eth-dst>",
13523        .tokens = {
13524                (void *)&cmd_set_mplsogre_encap_set,
13525                (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13526                (void *)&cmd_set_mplsogre_encap_ip_version,
13527                (void *)&cmd_set_mplsogre_encap_ip_version_value,
13528                (void *)&cmd_set_mplsogre_encap_label,
13529                (void *)&cmd_set_mplsogre_encap_label_value,
13530                (void *)&cmd_set_mplsogre_encap_ip_src,
13531                (void *)&cmd_set_mplsogre_encap_ip_src_value,
13532                (void *)&cmd_set_mplsogre_encap_ip_dst,
13533                (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13534                (void *)&cmd_set_mplsogre_encap_eth_src,
13535                (void *)&cmd_set_mplsogre_encap_eth_src_value,
13536                (void *)&cmd_set_mplsogre_encap_eth_dst,
13537                (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13538                NULL,
13539        },
13540};
13541
13542cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13543        .f = cmd_set_mplsogre_encap_parsed,
13544        .data = NULL,
13545        .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13546                " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13547                " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13548        .tokens = {
13549                (void *)&cmd_set_mplsogre_encap_set,
13550                (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13551                (void *)&cmd_set_mplsogre_encap_ip_version,
13552                (void *)&cmd_set_mplsogre_encap_ip_version_value,
13553                (void *)&cmd_set_mplsogre_encap_label,
13554                (void *)&cmd_set_mplsogre_encap_label_value,
13555                (void *)&cmd_set_mplsogre_encap_ip_src,
13556                (void *)&cmd_set_mplsogre_encap_ip_src_value,
13557                (void *)&cmd_set_mplsogre_encap_ip_dst,
13558                (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13559                (void *)&cmd_set_mplsogre_encap_vlan,
13560                (void *)&cmd_set_mplsogre_encap_vlan_value,
13561                (void *)&cmd_set_mplsogre_encap_eth_src,
13562                (void *)&cmd_set_mplsogre_encap_eth_src_value,
13563                (void *)&cmd_set_mplsogre_encap_eth_dst,
13564                (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13565                NULL,
13566        },
13567};
13568
13569/** Set MPLSoGRE decapsulation details */
13570struct cmd_set_mplsogre_decap_result {
13571        cmdline_fixed_string_t set;
13572        cmdline_fixed_string_t mplsogre;
13573        cmdline_fixed_string_t pos_token;
13574        cmdline_fixed_string_t ip_version;
13575        uint32_t vlan_present:1;
13576};
13577
13578cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13579        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13580                                 "set");
13581cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13582        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13583                                 "mplsogre_decap");
13584cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13585        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13586                                 mplsogre, "mplsogre_decap-with-vlan");
13587cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13588        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13589                                 pos_token, "ip-version");
13590cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13591        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13592                                 ip_version, "ipv4#ipv6");
13593
13594static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13595        __rte_unused struct cmdline *cl,
13596        __rte_unused void *data)
13597{
13598        struct cmd_set_mplsogre_decap_result *res = parsed_result;
13599
13600        if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13601                mplsogre_decap_conf.select_vlan = 0;
13602        else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13603                mplsogre_decap_conf.select_vlan = 1;
13604        if (strcmp(res->ip_version, "ipv4") == 0)
13605                mplsogre_decap_conf.select_ipv4 = 1;
13606        else if (strcmp(res->ip_version, "ipv6") == 0)
13607                mplsogre_decap_conf.select_ipv4 = 0;
13608}
13609
13610cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13611        .f = cmd_set_mplsogre_decap_parsed,
13612        .data = NULL,
13613        .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13614        .tokens = {
13615                (void *)&cmd_set_mplsogre_decap_set,
13616                (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13617                (void *)&cmd_set_mplsogre_decap_ip_version,
13618                (void *)&cmd_set_mplsogre_decap_ip_version_value,
13619                NULL,
13620        },
13621};
13622
13623cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13624        .f = cmd_set_mplsogre_decap_parsed,
13625        .data = NULL,
13626        .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13627        .tokens = {
13628                (void *)&cmd_set_mplsogre_decap_set,
13629                (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13630                (void *)&cmd_set_mplsogre_decap_ip_version,
13631                (void *)&cmd_set_mplsogre_decap_ip_version_value,
13632                NULL,
13633        },
13634};
13635
13636/** Set MPLSoUDP encapsulation details */
13637struct cmd_set_mplsoudp_encap_result {
13638        cmdline_fixed_string_t set;
13639        cmdline_fixed_string_t mplsoudp;
13640        cmdline_fixed_string_t pos_token;
13641        cmdline_fixed_string_t ip_version;
13642        uint32_t vlan_present:1;
13643        uint32_t label;
13644        uint16_t udp_src;
13645        uint16_t udp_dst;
13646        cmdline_ipaddr_t ip_src;
13647        cmdline_ipaddr_t ip_dst;
13648        uint16_t tci;
13649        struct rte_ether_addr eth_src;
13650        struct rte_ether_addr eth_dst;
13651};
13652
13653cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13654        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13655                                 "set");
13656cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13657        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13658                                 "mplsoudp_encap");
13659cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13660        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13661                                 mplsoudp, "mplsoudp_encap-with-vlan");
13662cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13663        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13664                                 pos_token, "ip-version");
13665cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13666        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13667                                 ip_version, "ipv4#ipv6");
13668cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13669        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13670                                 pos_token, "label");
13671cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13672        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13673                              RTE_UINT32);
13674cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13675        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13676                                 pos_token, "udp-src");
13677cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13678        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13679                              RTE_UINT16);
13680cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13681        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13682                                 pos_token, "udp-dst");
13683cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13684        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13685                              RTE_UINT16);
13686cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13687        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13688                                 pos_token, "ip-src");
13689cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13690        TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13691cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13692        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13693                                 pos_token, "ip-dst");
13694cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13695        TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13696cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13697        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13698                                 pos_token, "vlan-tci");
13699cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13700        TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13701                              RTE_UINT16);
13702cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13703        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13704                                 pos_token, "eth-src");
13705cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13706        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13707                                    eth_src);
13708cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13709        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13710                                 pos_token, "eth-dst");
13711cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13712        TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13713                                    eth_dst);
13714
13715static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13716        __rte_unused struct cmdline *cl,
13717        __rte_unused void *data)
13718{
13719        struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13720        union {
13721                uint32_t mplsoudp_label;
13722                uint8_t label[4];
13723        } id = {
13724                .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13725        };
13726
13727        if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13728                mplsoudp_encap_conf.select_vlan = 0;
13729        else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13730                mplsoudp_encap_conf.select_vlan = 1;
13731        if (strcmp(res->ip_version, "ipv4") == 0)
13732                mplsoudp_encap_conf.select_ipv4 = 1;
13733        else if (strcmp(res->ip_version, "ipv6") == 0)
13734                mplsoudp_encap_conf.select_ipv4 = 0;
13735        else
13736                return;
13737        rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13738        mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13739        mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13740        if (mplsoudp_encap_conf.select_ipv4) {
13741                IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13742                IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13743        } else {
13744                IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13745                IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13746        }
13747        if (mplsoudp_encap_conf.select_vlan)
13748                mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13749        rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13750                   RTE_ETHER_ADDR_LEN);
13751        rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13752                   RTE_ETHER_ADDR_LEN);
13753}
13754
13755cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13756        .f = cmd_set_mplsoudp_encap_parsed,
13757        .data = NULL,
13758        .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13759                " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13760                " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13761        .tokens = {
13762                (void *)&cmd_set_mplsoudp_encap_set,
13763                (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13764                (void *)&cmd_set_mplsoudp_encap_ip_version,
13765                (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13766                (void *)&cmd_set_mplsoudp_encap_label,
13767                (void *)&cmd_set_mplsoudp_encap_label_value,
13768                (void *)&cmd_set_mplsoudp_encap_udp_src,
13769                (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13770                (void *)&cmd_set_mplsoudp_encap_udp_dst,
13771                (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13772                (void *)&cmd_set_mplsoudp_encap_ip_src,
13773                (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13774                (void *)&cmd_set_mplsoudp_encap_ip_dst,
13775                (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13776                (void *)&cmd_set_mplsoudp_encap_eth_src,
13777                (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13778                (void *)&cmd_set_mplsoudp_encap_eth_dst,
13779                (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13780                NULL,
13781        },
13782};
13783
13784cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13785        .f = cmd_set_mplsoudp_encap_parsed,
13786        .data = NULL,
13787        .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13788                " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13789                " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13790                " eth-src <eth-src> eth-dst <eth-dst>",
13791        .tokens = {
13792                (void *)&cmd_set_mplsoudp_encap_set,
13793                (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13794                (void *)&cmd_set_mplsoudp_encap_ip_version,
13795                (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13796                (void *)&cmd_set_mplsoudp_encap_label,
13797                (void *)&cmd_set_mplsoudp_encap_label_value,
13798                (void *)&cmd_set_mplsoudp_encap_udp_src,
13799                (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13800                (void *)&cmd_set_mplsoudp_encap_udp_dst,
13801                (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13802                (void *)&cmd_set_mplsoudp_encap_ip_src,
13803                (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13804                (void *)&cmd_set_mplsoudp_encap_ip_dst,
13805                (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13806                (void *)&cmd_set_mplsoudp_encap_vlan,
13807                (void *)&cmd_set_mplsoudp_encap_vlan_value,
13808                (void *)&cmd_set_mplsoudp_encap_eth_src,
13809                (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13810                (void *)&cmd_set_mplsoudp_encap_eth_dst,
13811                (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13812                NULL,
13813        },
13814};
13815
13816/** Set MPLSoUDP decapsulation details */
13817struct cmd_set_mplsoudp_decap_result {
13818        cmdline_fixed_string_t set;
13819        cmdline_fixed_string_t mplsoudp;
13820        cmdline_fixed_string_t pos_token;
13821        cmdline_fixed_string_t ip_version;
13822        uint32_t vlan_present:1;
13823};
13824
13825cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13826        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13827                                 "set");
13828cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13829        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13830                                 "mplsoudp_decap");
13831cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13832        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13833                                 mplsoudp, "mplsoudp_decap-with-vlan");
13834cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13835        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13836                                 pos_token, "ip-version");
13837cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13838        TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13839                                 ip_version, "ipv4#ipv6");
13840
13841static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13842        __rte_unused struct cmdline *cl,
13843        __rte_unused void *data)
13844{
13845        struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13846
13847        if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13848                mplsoudp_decap_conf.select_vlan = 0;
13849        else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13850                mplsoudp_decap_conf.select_vlan = 1;
13851        if (strcmp(res->ip_version, "ipv4") == 0)
13852                mplsoudp_decap_conf.select_ipv4 = 1;
13853        else if (strcmp(res->ip_version, "ipv6") == 0)
13854                mplsoudp_decap_conf.select_ipv4 = 0;
13855}
13856
13857cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13858        .f = cmd_set_mplsoudp_decap_parsed,
13859        .data = NULL,
13860        .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13861        .tokens = {
13862                (void *)&cmd_set_mplsoudp_decap_set,
13863                (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13864                (void *)&cmd_set_mplsoudp_decap_ip_version,
13865                (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13866                NULL,
13867        },
13868};
13869
13870cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13871        .f = cmd_set_mplsoudp_decap_parsed,
13872        .data = NULL,
13873        .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13874        .tokens = {
13875                (void *)&cmd_set_mplsoudp_decap_set,
13876                (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13877                (void *)&cmd_set_mplsoudp_decap_ip_version,
13878                (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13879                NULL,
13880        },
13881};
13882
13883/** Set connection tracking object common details */
13884struct cmd_set_conntrack_common_result {
13885        cmdline_fixed_string_t set;
13886        cmdline_fixed_string_t conntrack;
13887        cmdline_fixed_string_t common;
13888        cmdline_fixed_string_t peer;
13889        cmdline_fixed_string_t is_orig;
13890        cmdline_fixed_string_t enable;
13891        cmdline_fixed_string_t live;
13892        cmdline_fixed_string_t sack;
13893        cmdline_fixed_string_t cack;
13894        cmdline_fixed_string_t last_dir;
13895        cmdline_fixed_string_t liberal;
13896        cmdline_fixed_string_t state;
13897        cmdline_fixed_string_t max_ack_win;
13898        cmdline_fixed_string_t retrans;
13899        cmdline_fixed_string_t last_win;
13900        cmdline_fixed_string_t last_seq;
13901        cmdline_fixed_string_t last_ack;
13902        cmdline_fixed_string_t last_end;
13903        cmdline_fixed_string_t last_index;
13904        uint8_t stat;
13905        uint8_t factor;
13906        uint16_t peer_port;
13907        uint32_t is_original;
13908        uint32_t en;
13909        uint32_t is_live;
13910        uint32_t s_ack;
13911        uint32_t c_ack;
13912        uint32_t ld;
13913        uint32_t lb;
13914        uint8_t re_num;
13915        uint8_t li;
13916        uint16_t lw;
13917        uint32_t ls;
13918        uint32_t la;
13919        uint32_t le;
13920};
13921
13922cmdline_parse_token_string_t cmd_set_conntrack_set =
13923        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13924                                 set, "set");
13925cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13926        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13927                                 conntrack, "conntrack");
13928cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13929        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13930                                 common, "com");
13931cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13932        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13933                                 peer, "peer");
13934cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13935        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13936                              peer_port, RTE_UINT16);
13937cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13938        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13939                                 is_orig, "is_orig");
13940cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13941        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13942                              is_original, RTE_UINT32);
13943cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13944        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13945                                 enable, "enable");
13946cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13947        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13948                              en, RTE_UINT32);
13949cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13950        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13951                                 live, "live");
13952cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13953        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13954                              is_live, RTE_UINT32);
13955cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13956        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13957                                 sack, "sack");
13958cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13959        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13960                              s_ack, RTE_UINT32);
13961cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
13962        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13963                                 cack, "cack");
13964cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
13965        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13966                              c_ack, RTE_UINT32);
13967cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
13968        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13969                                 last_dir, "last_dir");
13970cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
13971        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13972                              ld, RTE_UINT32);
13973cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
13974        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13975                                 liberal, "liberal");
13976cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
13977        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13978                              lb, RTE_UINT32);
13979cmdline_parse_token_string_t cmd_set_conntrack_common_state =
13980        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13981                                 state, "state");
13982cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
13983        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13984                              stat, RTE_UINT8);
13985cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
13986        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13987                                 max_ack_win, "max_ack_win");
13988cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
13989        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13990                              factor, RTE_UINT8);
13991cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
13992        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13993                                 retrans, "r_lim");
13994cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
13995        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13996                              re_num, RTE_UINT8);
13997cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
13998        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13999                                 last_win, "last_win");
14000cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14001        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14002                              lw, RTE_UINT16);
14003cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14004        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14005                                 last_seq, "last_seq");
14006cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14007        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14008                              ls, RTE_UINT32);
14009cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14010        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14011                                 last_ack, "last_ack");
14012cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14013        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14014                              la, RTE_UINT32);
14015cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14016        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14017                                 last_end, "last_end");
14018cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14019        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14020                              le, RTE_UINT32);
14021cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14022        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14023                                 last_index, "last_index");
14024cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14025        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14026                              li, RTE_UINT8);
14027
14028static void cmd_set_conntrack_common_parsed(void *parsed_result,
14029        __rte_unused struct cmdline *cl,
14030        __rte_unused void *data)
14031{
14032        struct cmd_set_conntrack_common_result *res = parsed_result;
14033
14034        /* No need to swap to big endian. */
14035        conntrack_context.peer_port = res->peer_port;
14036        conntrack_context.is_original_dir = res->is_original;
14037        conntrack_context.enable = res->en;
14038        conntrack_context.live_connection = res->is_live;
14039        conntrack_context.selective_ack = res->s_ack;
14040        conntrack_context.challenge_ack_passed = res->c_ack;
14041        conntrack_context.last_direction = res->ld;
14042        conntrack_context.liberal_mode = res->lb;
14043        conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14044        conntrack_context.max_ack_window = res->factor;
14045        conntrack_context.retransmission_limit = res->re_num;
14046        conntrack_context.last_window = res->lw;
14047        conntrack_context.last_index =
14048                (enum rte_flow_conntrack_tcp_last_index)res->li;
14049        conntrack_context.last_seq = res->ls;
14050        conntrack_context.last_ack = res->la;
14051        conntrack_context.last_end = res->le;
14052}
14053
14054cmdline_parse_inst_t cmd_set_conntrack_common = {
14055        .f = cmd_set_conntrack_common_parsed,
14056        .data = NULL,
14057        .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14058                " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14059                " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14060                " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14061                " last_index <flag>",
14062        .tokens = {
14063                (void *)&cmd_set_conntrack_set,
14064                (void *)&cmd_set_conntrack_conntrack,
14065                (void *)&cmd_set_conntrack_common_com,
14066                (void *)&cmd_set_conntrack_common_peer,
14067                (void *)&cmd_set_conntrack_common_peer_value,
14068                (void *)&cmd_set_conntrack_common_is_orig,
14069                (void *)&cmd_set_conntrack_common_is_orig_value,
14070                (void *)&cmd_set_conntrack_common_enable,
14071                (void *)&cmd_set_conntrack_common_enable_value,
14072                (void *)&cmd_set_conntrack_common_live,
14073                (void *)&cmd_set_conntrack_common_live_value,
14074                (void *)&cmd_set_conntrack_common_sack,
14075                (void *)&cmd_set_conntrack_common_sack_value,
14076                (void *)&cmd_set_conntrack_common_cack,
14077                (void *)&cmd_set_conntrack_common_cack_value,
14078                (void *)&cmd_set_conntrack_common_last_dir,
14079                (void *)&cmd_set_conntrack_common_last_dir_value,
14080                (void *)&cmd_set_conntrack_common_liberal,
14081                (void *)&cmd_set_conntrack_common_liberal_value,
14082                (void *)&cmd_set_conntrack_common_state,
14083                (void *)&cmd_set_conntrack_common_state_value,
14084                (void *)&cmd_set_conntrack_common_max_ackwin,
14085                (void *)&cmd_set_conntrack_common_max_ackwin_value,
14086                (void *)&cmd_set_conntrack_common_retrans,
14087                (void *)&cmd_set_conntrack_common_retrans_value,
14088                (void *)&cmd_set_conntrack_common_last_win,
14089                (void *)&cmd_set_conntrack_common_last_win_value,
14090                (void *)&cmd_set_conntrack_common_last_seq,
14091                (void *)&cmd_set_conntrack_common_last_seq_value,
14092                (void *)&cmd_set_conntrack_common_last_ack,
14093                (void *)&cmd_set_conntrack_common_last_ack_value,
14094                (void *)&cmd_set_conntrack_common_last_end,
14095                (void *)&cmd_set_conntrack_common_last_end_value,
14096                (void *)&cmd_set_conntrack_common_last_index,
14097                (void *)&cmd_set_conntrack_common_last_index_value,
14098                NULL,
14099        },
14100};
14101
14102/** Set connection tracking object both directions' details */
14103struct cmd_set_conntrack_dir_result {
14104        cmdline_fixed_string_t set;
14105        cmdline_fixed_string_t conntrack;
14106        cmdline_fixed_string_t dir;
14107        cmdline_fixed_string_t scale;
14108        cmdline_fixed_string_t fin;
14109        cmdline_fixed_string_t ack_seen;
14110        cmdline_fixed_string_t unack;
14111        cmdline_fixed_string_t sent_end;
14112        cmdline_fixed_string_t reply_end;
14113        cmdline_fixed_string_t max_win;
14114        cmdline_fixed_string_t max_ack;
14115        uint32_t factor;
14116        uint32_t f;
14117        uint32_t as;
14118        uint32_t un;
14119        uint32_t se;
14120        uint32_t re;
14121        uint32_t mw;
14122        uint32_t ma;
14123};
14124
14125cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14126        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14127                                 set, "set");
14128cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14129        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14130                                 conntrack, "conntrack");
14131cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14132        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14133                                 dir, "orig#rply");
14134cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14135        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14136                                 scale, "scale");
14137cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14138        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14139                              factor, RTE_UINT32);
14140cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14141        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14142                                 fin, "fin");
14143cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14144        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14145                              f, RTE_UINT32);
14146cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14147        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14148                                 ack_seen, "acked");
14149cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14150        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14151                              as, RTE_UINT32);
14152cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14153        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14154                                 unack, "unack_data");
14155cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14156        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14157                              un, RTE_UINT32);
14158cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14159        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14160                                 sent_end, "sent_end");
14161cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14162        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14163                              se, RTE_UINT32);
14164cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14165        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14166                                 reply_end, "reply_end");
14167cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14168        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14169                              re, RTE_UINT32);
14170cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14171        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14172                                 max_win, "max_win");
14173cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14174        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14175                              mw, RTE_UINT32);
14176cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14177        TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14178                                 max_ack, "max_ack");
14179cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14180        TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14181                              ma, RTE_UINT32);
14182
14183static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14184        __rte_unused struct cmdline *cl,
14185        __rte_unused void *data)
14186{
14187        struct cmd_set_conntrack_dir_result *res = parsed_result;
14188        struct rte_flow_tcp_dir_param *dir = NULL;
14189
14190        if (strcmp(res->dir, "orig") == 0)
14191                dir = &conntrack_context.original_dir;
14192        else if (strcmp(res->dir, "rply") == 0)
14193                dir = &conntrack_context.reply_dir;
14194        else
14195                return;
14196        dir->scale = res->factor;
14197        dir->close_initiated = res->f;
14198        dir->last_ack_seen = res->as;
14199        dir->data_unacked = res->un;
14200        dir->sent_end = res->se;
14201        dir->reply_end = res->re;
14202        dir->max_ack = res->ma;
14203        dir->max_win = res->mw;
14204}
14205
14206cmdline_parse_inst_t cmd_set_conntrack_dir = {
14207        .f = cmd_set_conntrack_dir_parsed,
14208        .data = NULL,
14209        .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14210                    " acked <seen> unack_data <unack> sent_end <sent>"
14211                    " reply_end <reply> max_win <win> max_ack <ack>",
14212        .tokens = {
14213                (void *)&cmd_set_conntrack_set,
14214                (void *)&cmd_set_conntrack_conntrack,
14215                (void *)&cmd_set_conntrack_dir_dir,
14216                (void *)&cmd_set_conntrack_dir_scale,
14217                (void *)&cmd_set_conntrack_dir_scale_value,
14218                (void *)&cmd_set_conntrack_dir_fin,
14219                (void *)&cmd_set_conntrack_dir_fin_value,
14220                (void *)&cmd_set_conntrack_dir_ack,
14221                (void *)&cmd_set_conntrack_dir_ack_value,
14222                (void *)&cmd_set_conntrack_dir_unack_data,
14223                (void *)&cmd_set_conntrack_dir_unack_data_value,
14224                (void *)&cmd_set_conntrack_dir_sent_end,
14225                (void *)&cmd_set_conntrack_dir_sent_end_value,
14226                (void *)&cmd_set_conntrack_dir_reply_end,
14227                (void *)&cmd_set_conntrack_dir_reply_end_value,
14228                (void *)&cmd_set_conntrack_dir_max_win,
14229                (void *)&cmd_set_conntrack_dir_max_win_value,
14230                (void *)&cmd_set_conntrack_dir_max_ack,
14231                (void *)&cmd_set_conntrack_dir_max_ack_value,
14232                NULL,
14233        },
14234};
14235
14236/* Strict link priority scheduling mode setting */
14237static void
14238cmd_strict_link_prio_parsed(
14239        void *parsed_result,
14240        __rte_unused struct cmdline *cl,
14241        __rte_unused void *data)
14242{
14243        struct cmd_vf_tc_bw_result *res = parsed_result;
14244        int ret = -ENOTSUP;
14245
14246        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14247                return;
14248
14249#ifdef RTE_NET_I40E
14250        ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14251#endif
14252
14253        switch (ret) {
14254        case 0:
14255                break;
14256        case -EINVAL:
14257                fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14258                break;
14259        case -ENODEV:
14260                fprintf(stderr, "invalid port_id %d\n", res->port_id);
14261                break;
14262        case -ENOTSUP:
14263                fprintf(stderr, "function not implemented\n");
14264                break;
14265        default:
14266                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14267        }
14268}
14269
14270cmdline_parse_inst_t cmd_strict_link_prio = {
14271        .f = cmd_strict_link_prio_parsed,
14272        .data = NULL,
14273        .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14274        .tokens = {
14275                (void *)&cmd_vf_tc_bw_set,
14276                (void *)&cmd_vf_tc_bw_tx,
14277                (void *)&cmd_vf_tc_bw_strict_link_prio,
14278                (void *)&cmd_vf_tc_bw_port_id,
14279                (void *)&cmd_vf_tc_bw_tc_map,
14280                NULL,
14281        },
14282};
14283
14284/* Load dynamic device personalization*/
14285struct cmd_ddp_add_result {
14286        cmdline_fixed_string_t ddp;
14287        cmdline_fixed_string_t add;
14288        portid_t port_id;
14289        char filepath[];
14290};
14291
14292cmdline_parse_token_string_t cmd_ddp_add_ddp =
14293        TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14294cmdline_parse_token_string_t cmd_ddp_add_add =
14295        TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14296cmdline_parse_token_num_t cmd_ddp_add_port_id =
14297        TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14298                RTE_UINT16);
14299cmdline_parse_token_string_t cmd_ddp_add_filepath =
14300        TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14301
14302static void
14303cmd_ddp_add_parsed(
14304        void *parsed_result,
14305        __rte_unused struct cmdline *cl,
14306        __rte_unused void *data)
14307{
14308        struct cmd_ddp_add_result *res = parsed_result;
14309        uint8_t *buff;
14310        uint32_t size;
14311        char *filepath;
14312        char *file_fld[2];
14313        int file_num;
14314        int ret = -ENOTSUP;
14315
14316        if (!all_ports_stopped()) {
14317                fprintf(stderr, "Please stop all ports first\n");
14318                return;
14319        }
14320
14321        filepath = strdup(res->filepath);
14322        if (filepath == NULL) {
14323                fprintf(stderr, "Failed to allocate memory\n");
14324                return;
14325        }
14326        file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14327
14328        buff = open_file(file_fld[0], &size);
14329        if (!buff) {
14330                free((void *)filepath);
14331                return;
14332        }
14333
14334#ifdef RTE_NET_I40E
14335        if (ret == -ENOTSUP)
14336                ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14337                                               buff, size,
14338                                               RTE_PMD_I40E_PKG_OP_WR_ADD);
14339#endif
14340
14341        if (ret == -EEXIST)
14342                fprintf(stderr, "Profile has already existed.\n");
14343        else if (ret < 0)
14344                fprintf(stderr, "Failed to load profile.\n");
14345        else if (file_num == 2)
14346                save_file(file_fld[1], buff, size);
14347
14348        close_file(buff);
14349        free((void *)filepath);
14350}
14351
14352cmdline_parse_inst_t cmd_ddp_add = {
14353        .f = cmd_ddp_add_parsed,
14354        .data = NULL,
14355        .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14356        .tokens = {
14357                (void *)&cmd_ddp_add_ddp,
14358                (void *)&cmd_ddp_add_add,
14359                (void *)&cmd_ddp_add_port_id,
14360                (void *)&cmd_ddp_add_filepath,
14361                NULL,
14362        },
14363};
14364
14365/* Delete dynamic device personalization*/
14366struct cmd_ddp_del_result {
14367        cmdline_fixed_string_t ddp;
14368        cmdline_fixed_string_t del;
14369        portid_t port_id;
14370        char filepath[];
14371};
14372
14373cmdline_parse_token_string_t cmd_ddp_del_ddp =
14374        TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14375cmdline_parse_token_string_t cmd_ddp_del_del =
14376        TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14377cmdline_parse_token_num_t cmd_ddp_del_port_id =
14378        TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14379cmdline_parse_token_string_t cmd_ddp_del_filepath =
14380        TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14381
14382static void
14383cmd_ddp_del_parsed(
14384        void *parsed_result,
14385        __rte_unused struct cmdline *cl,
14386        __rte_unused void *data)
14387{
14388        struct cmd_ddp_del_result *res = parsed_result;
14389        uint8_t *buff;
14390        uint32_t size;
14391        int ret = -ENOTSUP;
14392
14393        if (!all_ports_stopped()) {
14394                fprintf(stderr, "Please stop all ports first\n");
14395                return;
14396        }
14397
14398        buff = open_file(res->filepath, &size);
14399        if (!buff)
14400                return;
14401
14402#ifdef RTE_NET_I40E
14403        if (ret == -ENOTSUP)
14404                ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14405                                               buff, size,
14406                                               RTE_PMD_I40E_PKG_OP_WR_DEL);
14407#endif
14408
14409        if (ret == -EACCES)
14410                fprintf(stderr, "Profile does not exist.\n");
14411        else if (ret < 0)
14412                fprintf(stderr, "Failed to delete profile.\n");
14413
14414        close_file(buff);
14415}
14416
14417cmdline_parse_inst_t cmd_ddp_del = {
14418        .f = cmd_ddp_del_parsed,
14419        .data = NULL,
14420        .help_str = "ddp del <port_id> <backup_profile_path>",
14421        .tokens = {
14422                (void *)&cmd_ddp_del_ddp,
14423                (void *)&cmd_ddp_del_del,
14424                (void *)&cmd_ddp_del_port_id,
14425                (void *)&cmd_ddp_del_filepath,
14426                NULL,
14427        },
14428};
14429
14430/* Get dynamic device personalization profile info */
14431struct cmd_ddp_info_result {
14432        cmdline_fixed_string_t ddp;
14433        cmdline_fixed_string_t get;
14434        cmdline_fixed_string_t info;
14435        char filepath[];
14436};
14437
14438cmdline_parse_token_string_t cmd_ddp_info_ddp =
14439        TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14440cmdline_parse_token_string_t cmd_ddp_info_get =
14441        TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14442cmdline_parse_token_string_t cmd_ddp_info_info =
14443        TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14444cmdline_parse_token_string_t cmd_ddp_info_filepath =
14445        TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14446
14447static void
14448cmd_ddp_info_parsed(
14449        void *parsed_result,
14450        __rte_unused struct cmdline *cl,
14451        __rte_unused void *data)
14452{
14453        struct cmd_ddp_info_result *res = parsed_result;
14454        uint8_t *pkg;
14455        uint32_t pkg_size;
14456        int ret = -ENOTSUP;
14457#ifdef RTE_NET_I40E
14458        uint32_t i, j, n;
14459        uint8_t *buff;
14460        uint32_t buff_size = 0;
14461        struct rte_pmd_i40e_profile_info info;
14462        uint32_t dev_num = 0;
14463        struct rte_pmd_i40e_ddp_device_id *devs;
14464        uint32_t proto_num = 0;
14465        struct rte_pmd_i40e_proto_info *proto = NULL;
14466        uint32_t pctype_num = 0;
14467        struct rte_pmd_i40e_ptype_info *pctype;
14468        uint32_t ptype_num = 0;
14469        struct rte_pmd_i40e_ptype_info *ptype;
14470        uint8_t proto_id;
14471
14472#endif
14473
14474        pkg = open_file(res->filepath, &pkg_size);
14475        if (!pkg)
14476                return;
14477
14478#ifdef RTE_NET_I40E
14479        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14480                                (uint8_t *)&info, sizeof(info),
14481                                RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14482        if (!ret) {
14483                printf("Global Track id:       0x%x\n", info.track_id);
14484                printf("Global Version:        %d.%d.%d.%d\n",
14485                        info.version.major,
14486                        info.version.minor,
14487                        info.version.update,
14488                        info.version.draft);
14489                printf("Global Package name:   %s\n\n", info.name);
14490        }
14491
14492        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14493                                (uint8_t *)&info, sizeof(info),
14494                                RTE_PMD_I40E_PKG_INFO_HEADER);
14495        if (!ret) {
14496                printf("i40e Profile Track id: 0x%x\n", info.track_id);
14497                printf("i40e Profile Version:  %d.%d.%d.%d\n",
14498                        info.version.major,
14499                        info.version.minor,
14500                        info.version.update,
14501                        info.version.draft);
14502                printf("i40e Profile name:     %s\n\n", info.name);
14503        }
14504
14505        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14506                                (uint8_t *)&buff_size, sizeof(buff_size),
14507                                RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14508        if (!ret && buff_size) {
14509                buff = (uint8_t *)malloc(buff_size);
14510                if (buff) {
14511                        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14512                                                buff, buff_size,
14513                                                RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14514                        if (!ret)
14515                                printf("Package Notes:\n%s\n\n", buff);
14516                        free(buff);
14517                }
14518        }
14519
14520        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14521                                (uint8_t *)&dev_num, sizeof(dev_num),
14522                                RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14523        if (!ret && dev_num) {
14524                buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14525                devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14526                if (devs) {
14527                        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14528                                                (uint8_t *)devs, buff_size,
14529                                                RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14530                        if (!ret) {
14531                                printf("List of supported devices:\n");
14532                                for (i = 0; i < dev_num; i++) {
14533                                        printf("  %04X:%04X %04X:%04X\n",
14534                                                devs[i].vendor_dev_id >> 16,
14535                                                devs[i].vendor_dev_id & 0xFFFF,
14536                                                devs[i].sub_vendor_dev_id >> 16,
14537                                                devs[i].sub_vendor_dev_id & 0xFFFF);
14538                                }
14539                                printf("\n");
14540                        }
14541                        free(devs);
14542                }
14543        }
14544
14545        /* get information about protocols and packet types */
14546        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14547                (uint8_t *)&proto_num, sizeof(proto_num),
14548                RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14549        if (ret || !proto_num)
14550                goto no_print_return;
14551
14552        buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14553        proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14554        if (!proto)
14555                goto no_print_return;
14556
14557        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14558                                        buff_size,
14559                                        RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14560        if (!ret) {
14561                printf("List of used protocols:\n");
14562                for (i = 0; i < proto_num; i++)
14563                        printf("  %2u: %s\n", proto[i].proto_id,
14564                               proto[i].name);
14565                printf("\n");
14566        }
14567        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14568                (uint8_t *)&pctype_num, sizeof(pctype_num),
14569                RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14570        if (ret || !pctype_num)
14571                goto no_print_pctypes;
14572
14573        buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14574        pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14575        if (!pctype)
14576                goto no_print_pctypes;
14577
14578        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14579                                        buff_size,
14580                                        RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14581        if (ret) {
14582                free(pctype);
14583                goto no_print_pctypes;
14584        }
14585
14586        printf("List of defined packet classification types:\n");
14587        for (i = 0; i < pctype_num; i++) {
14588                printf("  %2u:", pctype[i].ptype_id);
14589                for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14590                        proto_id = pctype[i].protocols[j];
14591                        if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14592                                for (n = 0; n < proto_num; n++) {
14593                                        if (proto[n].proto_id == proto_id) {
14594                                                printf(" %s", proto[n].name);
14595                                                break;
14596                                        }
14597                                }
14598                        }
14599                }
14600                printf("\n");
14601        }
14602        printf("\n");
14603        free(pctype);
14604
14605no_print_pctypes:
14606
14607        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14608                                        sizeof(ptype_num),
14609                                        RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14610        if (ret || !ptype_num)
14611                goto no_print_return;
14612
14613        buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14614        ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14615        if (!ptype)
14616                goto no_print_return;
14617
14618        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14619                                        buff_size,
14620                                        RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14621        if (ret) {
14622                free(ptype);
14623                goto no_print_return;
14624        }
14625        printf("List of defined packet types:\n");
14626        for (i = 0; i < ptype_num; i++) {
14627                printf("  %2u:", ptype[i].ptype_id);
14628                for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14629                        proto_id = ptype[i].protocols[j];
14630                        if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14631                                for (n = 0; n < proto_num; n++) {
14632                                        if (proto[n].proto_id == proto_id) {
14633                                                printf(" %s", proto[n].name);
14634                                                break;
14635                                        }
14636                                }
14637                        }
14638                }
14639                printf("\n");
14640        }
14641        free(ptype);
14642        printf("\n");
14643
14644        ret = 0;
14645no_print_return:
14646        if (proto)
14647                free(proto);
14648#endif
14649        if (ret == -ENOTSUP)
14650                fprintf(stderr, "Function not supported in PMD driver\n");
14651        close_file(pkg);
14652}
14653
14654cmdline_parse_inst_t cmd_ddp_get_info = {
14655        .f = cmd_ddp_info_parsed,
14656        .data = NULL,
14657        .help_str = "ddp get info <profile_path>",
14658        .tokens = {
14659                (void *)&cmd_ddp_info_ddp,
14660                (void *)&cmd_ddp_info_get,
14661                (void *)&cmd_ddp_info_info,
14662                (void *)&cmd_ddp_info_filepath,
14663                NULL,
14664        },
14665};
14666
14667/* Get dynamic device personalization profile info list*/
14668#define PROFILE_INFO_SIZE 48
14669#define MAX_PROFILE_NUM 16
14670
14671struct cmd_ddp_get_list_result {
14672        cmdline_fixed_string_t ddp;
14673        cmdline_fixed_string_t get;
14674        cmdline_fixed_string_t list;
14675        portid_t port_id;
14676};
14677
14678cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14679        TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14680cmdline_parse_token_string_t cmd_ddp_get_list_get =
14681        TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14682cmdline_parse_token_string_t cmd_ddp_get_list_list =
14683        TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14684cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14685        TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14686                RTE_UINT16);
14687
14688static void
14689cmd_ddp_get_list_parsed(
14690        __rte_unused void *parsed_result,
14691        __rte_unused struct cmdline *cl,
14692        __rte_unused void *data)
14693{
14694#ifdef RTE_NET_I40E
14695        struct cmd_ddp_get_list_result *res = parsed_result;
14696        struct rte_pmd_i40e_profile_list *p_list;
14697        struct rte_pmd_i40e_profile_info *p_info;
14698        uint32_t p_num;
14699        uint32_t size;
14700        uint32_t i;
14701#endif
14702        int ret = -ENOTSUP;
14703
14704#ifdef RTE_NET_I40E
14705        size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14706        p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14707        if (!p_list) {
14708                fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14709                return;
14710        }
14711
14712        if (ret == -ENOTSUP)
14713                ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14714                                                (uint8_t *)p_list, size);
14715
14716        if (!ret) {
14717                p_num = p_list->p_count;
14718                printf("Profile number is: %d\n\n", p_num);
14719
14720                for (i = 0; i < p_num; i++) {
14721                        p_info = &p_list->p_info[i];
14722                        printf("Profile %d:\n", i);
14723                        printf("Track id:     0x%x\n", p_info->track_id);
14724                        printf("Version:      %d.%d.%d.%d\n",
14725                               p_info->version.major,
14726                               p_info->version.minor,
14727                               p_info->version.update,
14728                               p_info->version.draft);
14729                        printf("Profile name: %s\n\n", p_info->name);
14730                }
14731        }
14732
14733        free(p_list);
14734#endif
14735
14736        if (ret < 0)
14737                fprintf(stderr, "Failed to get ddp list\n");
14738}
14739
14740cmdline_parse_inst_t cmd_ddp_get_list = {
14741        .f = cmd_ddp_get_list_parsed,
14742        .data = NULL,
14743        .help_str = "ddp get list <port_id>",
14744        .tokens = {
14745                (void *)&cmd_ddp_get_list_ddp,
14746                (void *)&cmd_ddp_get_list_get,
14747                (void *)&cmd_ddp_get_list_list,
14748                (void *)&cmd_ddp_get_list_port_id,
14749                NULL,
14750        },
14751};
14752
14753/* Configure input set */
14754struct cmd_cfg_input_set_result {
14755        cmdline_fixed_string_t port;
14756        cmdline_fixed_string_t cfg;
14757        portid_t port_id;
14758        cmdline_fixed_string_t pctype;
14759        uint8_t pctype_id;
14760        cmdline_fixed_string_t inset_type;
14761        cmdline_fixed_string_t opt;
14762        cmdline_fixed_string_t field;
14763        uint8_t field_idx;
14764};
14765
14766static void
14767cmd_cfg_input_set_parsed(
14768        __rte_unused void *parsed_result,
14769        __rte_unused struct cmdline *cl,
14770        __rte_unused void *data)
14771{
14772#ifdef RTE_NET_I40E
14773        struct cmd_cfg_input_set_result *res = parsed_result;
14774        enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14775        struct rte_pmd_i40e_inset inset;
14776#endif
14777        int ret = -ENOTSUP;
14778
14779        if (!all_ports_stopped()) {
14780                fprintf(stderr, "Please stop all ports first\n");
14781                return;
14782        }
14783
14784#ifdef RTE_NET_I40E
14785        if (!strcmp(res->inset_type, "hash_inset"))
14786                inset_type = INSET_HASH;
14787        else if (!strcmp(res->inset_type, "fdir_inset"))
14788                inset_type = INSET_FDIR;
14789        else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14790                inset_type = INSET_FDIR_FLX;
14791        ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14792                                     &inset, inset_type);
14793        if (ret) {
14794                fprintf(stderr, "Failed to get input set.\n");
14795                return;
14796        }
14797
14798        if (!strcmp(res->opt, "get")) {
14799                ret = rte_pmd_i40e_inset_field_get(inset.inset,
14800                                                   res->field_idx);
14801                if (ret)
14802                        printf("Field index %d is enabled.\n", res->field_idx);
14803                else
14804                        printf("Field index %d is disabled.\n", res->field_idx);
14805                return;
14806        } else if (!strcmp(res->opt, "set"))
14807                ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14808                                                   res->field_idx);
14809        else if (!strcmp(res->opt, "clear"))
14810                ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14811                                                     res->field_idx);
14812        if (ret) {
14813                fprintf(stderr, "Failed to configure input set field.\n");
14814                return;
14815        }
14816
14817        ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14818                                     &inset, inset_type);
14819        if (ret) {
14820                fprintf(stderr, "Failed to set input set.\n");
14821                return;
14822        }
14823#endif
14824
14825        if (ret == -ENOTSUP)
14826                fprintf(stderr, "Function not supported\n");
14827}
14828
14829cmdline_parse_token_string_t cmd_cfg_input_set_port =
14830        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14831                                 port, "port");
14832cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14833        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14834                                 cfg, "config");
14835cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14836        TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14837                              port_id, RTE_UINT16);
14838cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14839        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14840                                 pctype, "pctype");
14841cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14842        TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14843                              pctype_id, RTE_UINT8);
14844cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14845        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14846                                 inset_type,
14847                                 "hash_inset#fdir_inset#fdir_flx_inset");
14848cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14849        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14850                                 opt, "get#set#clear");
14851cmdline_parse_token_string_t cmd_cfg_input_set_field =
14852        TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14853                                 field, "field");
14854cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14855        TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14856                              field_idx, RTE_UINT8);
14857
14858cmdline_parse_inst_t cmd_cfg_input_set = {
14859        .f = cmd_cfg_input_set_parsed,
14860        .data = NULL,
14861        .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14862                    "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14863        .tokens = {
14864                (void *)&cmd_cfg_input_set_port,
14865                (void *)&cmd_cfg_input_set_cfg,
14866                (void *)&cmd_cfg_input_set_port_id,
14867                (void *)&cmd_cfg_input_set_pctype,
14868                (void *)&cmd_cfg_input_set_pctype_id,
14869                (void *)&cmd_cfg_input_set_inset_type,
14870                (void *)&cmd_cfg_input_set_opt,
14871                (void *)&cmd_cfg_input_set_field,
14872                (void *)&cmd_cfg_input_set_field_idx,
14873                NULL,
14874        },
14875};
14876
14877/* Clear input set */
14878struct cmd_clear_input_set_result {
14879        cmdline_fixed_string_t port;
14880        cmdline_fixed_string_t cfg;
14881        portid_t port_id;
14882        cmdline_fixed_string_t pctype;
14883        uint8_t pctype_id;
14884        cmdline_fixed_string_t inset_type;
14885        cmdline_fixed_string_t clear;
14886        cmdline_fixed_string_t all;
14887};
14888
14889static void
14890cmd_clear_input_set_parsed(
14891        __rte_unused void *parsed_result,
14892        __rte_unused struct cmdline *cl,
14893        __rte_unused void *data)
14894{
14895#ifdef RTE_NET_I40E
14896        struct cmd_clear_input_set_result *res = parsed_result;
14897        enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14898        struct rte_pmd_i40e_inset inset;
14899#endif
14900        int ret = -ENOTSUP;
14901
14902        if (!all_ports_stopped()) {
14903                fprintf(stderr, "Please stop all ports first\n");
14904                return;
14905        }
14906
14907#ifdef RTE_NET_I40E
14908        if (!strcmp(res->inset_type, "hash_inset"))
14909                inset_type = INSET_HASH;
14910        else if (!strcmp(res->inset_type, "fdir_inset"))
14911                inset_type = INSET_FDIR;
14912        else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14913                inset_type = INSET_FDIR_FLX;
14914
14915        memset(&inset, 0, sizeof(inset));
14916
14917        ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14918                                     &inset, inset_type);
14919        if (ret) {
14920                fprintf(stderr, "Failed to clear input set.\n");
14921                return;
14922        }
14923
14924#endif
14925
14926        if (ret == -ENOTSUP)
14927                fprintf(stderr, "Function not supported\n");
14928}
14929
14930cmdline_parse_token_string_t cmd_clear_input_set_port =
14931        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14932                                 port, "port");
14933cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14934        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14935                                 cfg, "config");
14936cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14937        TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14938                              port_id, RTE_UINT16);
14939cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14940        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14941                                 pctype, "pctype");
14942cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14943        TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14944                              pctype_id, RTE_UINT8);
14945cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14946        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14947                                 inset_type,
14948                                 "hash_inset#fdir_inset#fdir_flx_inset");
14949cmdline_parse_token_string_t cmd_clear_input_set_clear =
14950        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14951                                 clear, "clear");
14952cmdline_parse_token_string_t cmd_clear_input_set_all =
14953        TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14954                                 all, "all");
14955
14956cmdline_parse_inst_t cmd_clear_input_set = {
14957        .f = cmd_clear_input_set_parsed,
14958        .data = NULL,
14959        .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14960                    "fdir_inset|fdir_flx_inset clear all",
14961        .tokens = {
14962                (void *)&cmd_clear_input_set_port,
14963                (void *)&cmd_clear_input_set_cfg,
14964                (void *)&cmd_clear_input_set_port_id,
14965                (void *)&cmd_clear_input_set_pctype,
14966                (void *)&cmd_clear_input_set_pctype_id,
14967                (void *)&cmd_clear_input_set_inset_type,
14968                (void *)&cmd_clear_input_set_clear,
14969                (void *)&cmd_clear_input_set_all,
14970                NULL,
14971        },
14972};
14973
14974/* show vf stats */
14975
14976/* Common result structure for show vf stats */
14977struct cmd_show_vf_stats_result {
14978        cmdline_fixed_string_t show;
14979        cmdline_fixed_string_t vf;
14980        cmdline_fixed_string_t stats;
14981        portid_t port_id;
14982        uint16_t vf_id;
14983};
14984
14985/* Common CLI fields show vf stats*/
14986cmdline_parse_token_string_t cmd_show_vf_stats_show =
14987        TOKEN_STRING_INITIALIZER
14988                (struct cmd_show_vf_stats_result,
14989                 show, "show");
14990cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14991        TOKEN_STRING_INITIALIZER
14992                (struct cmd_show_vf_stats_result,
14993                 vf, "vf");
14994cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14995        TOKEN_STRING_INITIALIZER
14996                (struct cmd_show_vf_stats_result,
14997                 stats, "stats");
14998cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14999        TOKEN_NUM_INITIALIZER
15000                (struct cmd_show_vf_stats_result,
15001                 port_id, RTE_UINT16);
15002cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15003        TOKEN_NUM_INITIALIZER
15004                (struct cmd_show_vf_stats_result,
15005                 vf_id, RTE_UINT16);
15006
15007static void
15008cmd_show_vf_stats_parsed(
15009        void *parsed_result,
15010        __rte_unused struct cmdline *cl,
15011        __rte_unused void *data)
15012{
15013        struct cmd_show_vf_stats_result *res = parsed_result;
15014        struct rte_eth_stats stats;
15015        int ret = -ENOTSUP;
15016        static const char *nic_stats_border = "########################";
15017
15018        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15019                return;
15020
15021        memset(&stats, 0, sizeof(stats));
15022
15023#ifdef RTE_NET_I40E
15024        if (ret == -ENOTSUP)
15025                ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15026                                                res->vf_id,
15027                                                &stats);
15028#endif
15029#ifdef RTE_NET_BNXT
15030        if (ret == -ENOTSUP)
15031                ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15032                                                res->vf_id,
15033                                                &stats);
15034#endif
15035
15036        switch (ret) {
15037        case 0:
15038                break;
15039        case -EINVAL:
15040                fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15041                break;
15042        case -ENODEV:
15043                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15044                break;
15045        case -ENOTSUP:
15046                fprintf(stderr, "function not implemented\n");
15047                break;
15048        default:
15049                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15050        }
15051
15052        printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15053                nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15054
15055        printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15056               "%-"PRIu64"\n",
15057               stats.ipackets, stats.imissed, stats.ibytes);
15058        printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15059        printf("  RX-nombuf:  %-10"PRIu64"\n",
15060               stats.rx_nombuf);
15061        printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15062               "%-"PRIu64"\n",
15063               stats.opackets, stats.oerrors, stats.obytes);
15064
15065        printf("  %s############################%s\n",
15066                               nic_stats_border, nic_stats_border);
15067}
15068
15069cmdline_parse_inst_t cmd_show_vf_stats = {
15070        .f = cmd_show_vf_stats_parsed,
15071        .data = NULL,
15072        .help_str = "show vf stats <port_id> <vf_id>",
15073        .tokens = {
15074                (void *)&cmd_show_vf_stats_show,
15075                (void *)&cmd_show_vf_stats_vf,
15076                (void *)&cmd_show_vf_stats_stats,
15077                (void *)&cmd_show_vf_stats_port_id,
15078                (void *)&cmd_show_vf_stats_vf_id,
15079                NULL,
15080        },
15081};
15082
15083/* clear vf stats */
15084
15085/* Common result structure for clear vf stats */
15086struct cmd_clear_vf_stats_result {
15087        cmdline_fixed_string_t clear;
15088        cmdline_fixed_string_t vf;
15089        cmdline_fixed_string_t stats;
15090        portid_t port_id;
15091        uint16_t vf_id;
15092};
15093
15094/* Common CLI fields clear vf stats*/
15095cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15096        TOKEN_STRING_INITIALIZER
15097                (struct cmd_clear_vf_stats_result,
15098                 clear, "clear");
15099cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15100        TOKEN_STRING_INITIALIZER
15101                (struct cmd_clear_vf_stats_result,
15102                 vf, "vf");
15103cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15104        TOKEN_STRING_INITIALIZER
15105                (struct cmd_clear_vf_stats_result,
15106                 stats, "stats");
15107cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15108        TOKEN_NUM_INITIALIZER
15109                (struct cmd_clear_vf_stats_result,
15110                 port_id, RTE_UINT16);
15111cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15112        TOKEN_NUM_INITIALIZER
15113                (struct cmd_clear_vf_stats_result,
15114                 vf_id, RTE_UINT16);
15115
15116static void
15117cmd_clear_vf_stats_parsed(
15118        void *parsed_result,
15119        __rte_unused struct cmdline *cl,
15120        __rte_unused void *data)
15121{
15122        struct cmd_clear_vf_stats_result *res = parsed_result;
15123        int ret = -ENOTSUP;
15124
15125        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15126                return;
15127
15128#ifdef RTE_NET_I40E
15129        if (ret == -ENOTSUP)
15130                ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15131                                                  res->vf_id);
15132#endif
15133#ifdef RTE_NET_BNXT
15134        if (ret == -ENOTSUP)
15135                ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15136                                                  res->vf_id);
15137#endif
15138
15139        switch (ret) {
15140        case 0:
15141                break;
15142        case -EINVAL:
15143                fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15144                break;
15145        case -ENODEV:
15146                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15147                break;
15148        case -ENOTSUP:
15149                fprintf(stderr, "function not implemented\n");
15150                break;
15151        default:
15152                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15153        }
15154}
15155
15156cmdline_parse_inst_t cmd_clear_vf_stats = {
15157        .f = cmd_clear_vf_stats_parsed,
15158        .data = NULL,
15159        .help_str = "clear vf stats <port_id> <vf_id>",
15160        .tokens = {
15161                (void *)&cmd_clear_vf_stats_clear,
15162                (void *)&cmd_clear_vf_stats_vf,
15163                (void *)&cmd_clear_vf_stats_stats,
15164                (void *)&cmd_clear_vf_stats_port_id,
15165                (void *)&cmd_clear_vf_stats_vf_id,
15166                NULL,
15167        },
15168};
15169
15170/* port config pctype mapping reset */
15171
15172/* Common result structure for port config pctype mapping reset */
15173struct cmd_pctype_mapping_reset_result {
15174        cmdline_fixed_string_t port;
15175        cmdline_fixed_string_t config;
15176        portid_t port_id;
15177        cmdline_fixed_string_t pctype;
15178        cmdline_fixed_string_t mapping;
15179        cmdline_fixed_string_t reset;
15180};
15181
15182/* Common CLI fields for port config pctype mapping reset*/
15183cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15184        TOKEN_STRING_INITIALIZER
15185                (struct cmd_pctype_mapping_reset_result,
15186                 port, "port");
15187cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15188        TOKEN_STRING_INITIALIZER
15189                (struct cmd_pctype_mapping_reset_result,
15190                 config, "config");
15191cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15192        TOKEN_NUM_INITIALIZER
15193                (struct cmd_pctype_mapping_reset_result,
15194                 port_id, RTE_UINT16);
15195cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15196        TOKEN_STRING_INITIALIZER
15197                (struct cmd_pctype_mapping_reset_result,
15198                 pctype, "pctype");
15199cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15200        TOKEN_STRING_INITIALIZER
15201                (struct cmd_pctype_mapping_reset_result,
15202                 mapping, "mapping");
15203cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15204        TOKEN_STRING_INITIALIZER
15205                (struct cmd_pctype_mapping_reset_result,
15206                 reset, "reset");
15207
15208static void
15209cmd_pctype_mapping_reset_parsed(
15210        void *parsed_result,
15211        __rte_unused struct cmdline *cl,
15212        __rte_unused void *data)
15213{
15214        struct cmd_pctype_mapping_reset_result *res = parsed_result;
15215        int ret = -ENOTSUP;
15216
15217        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15218                return;
15219
15220#ifdef RTE_NET_I40E
15221        ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15222#endif
15223
15224        switch (ret) {
15225        case 0:
15226                break;
15227        case -ENODEV:
15228                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15229                break;
15230        case -ENOTSUP:
15231                fprintf(stderr, "function not implemented\n");
15232                break;
15233        default:
15234                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15235        }
15236}
15237
15238cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15239        .f = cmd_pctype_mapping_reset_parsed,
15240        .data = NULL,
15241        .help_str = "port config <port_id> pctype mapping reset",
15242        .tokens = {
15243                (void *)&cmd_pctype_mapping_reset_port,
15244                (void *)&cmd_pctype_mapping_reset_config,
15245                (void *)&cmd_pctype_mapping_reset_port_id,
15246                (void *)&cmd_pctype_mapping_reset_pctype,
15247                (void *)&cmd_pctype_mapping_reset_mapping,
15248                (void *)&cmd_pctype_mapping_reset_reset,
15249                NULL,
15250        },
15251};
15252
15253/* show port pctype mapping */
15254
15255/* Common result structure for show port pctype mapping */
15256struct cmd_pctype_mapping_get_result {
15257        cmdline_fixed_string_t show;
15258        cmdline_fixed_string_t port;
15259        portid_t port_id;
15260        cmdline_fixed_string_t pctype;
15261        cmdline_fixed_string_t mapping;
15262};
15263
15264/* Common CLI fields for pctype mapping get */
15265cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15266        TOKEN_STRING_INITIALIZER
15267                (struct cmd_pctype_mapping_get_result,
15268                 show, "show");
15269cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15270        TOKEN_STRING_INITIALIZER
15271                (struct cmd_pctype_mapping_get_result,
15272                 port, "port");
15273cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15274        TOKEN_NUM_INITIALIZER
15275                (struct cmd_pctype_mapping_get_result,
15276                 port_id, RTE_UINT16);
15277cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15278        TOKEN_STRING_INITIALIZER
15279                (struct cmd_pctype_mapping_get_result,
15280                 pctype, "pctype");
15281cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15282        TOKEN_STRING_INITIALIZER
15283                (struct cmd_pctype_mapping_get_result,
15284                 mapping, "mapping");
15285
15286static void
15287cmd_pctype_mapping_get_parsed(
15288        void *parsed_result,
15289        __rte_unused struct cmdline *cl,
15290        __rte_unused void *data)
15291{
15292        struct cmd_pctype_mapping_get_result *res = parsed_result;
15293        int ret = -ENOTSUP;
15294#ifdef RTE_NET_I40E
15295        struct rte_pmd_i40e_flow_type_mapping
15296                                mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15297        int i, j, first_pctype;
15298#endif
15299
15300        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15301                return;
15302
15303#ifdef RTE_NET_I40E
15304        ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15305#endif
15306
15307        switch (ret) {
15308        case 0:
15309                break;
15310        case -ENODEV:
15311                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15312                return;
15313        case -ENOTSUP:
15314                fprintf(stderr, "function not implemented\n");
15315                return;
15316        default:
15317                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15318                return;
15319        }
15320
15321#ifdef RTE_NET_I40E
15322        for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15323                if (mapping[i].pctype != 0ULL) {
15324                        first_pctype = 1;
15325
15326                        printf("pctype: ");
15327                        for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15328                                if (mapping[i].pctype & (1ULL << j)) {
15329                                        printf(first_pctype ?
15330                                               "%02d" : ",%02d", j);
15331                                        first_pctype = 0;
15332                                }
15333                        }
15334                        printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15335                }
15336        }
15337#endif
15338}
15339
15340cmdline_parse_inst_t cmd_pctype_mapping_get = {
15341        .f = cmd_pctype_mapping_get_parsed,
15342        .data = NULL,
15343        .help_str = "show port <port_id> pctype mapping",
15344        .tokens = {
15345                (void *)&cmd_pctype_mapping_get_show,
15346                (void *)&cmd_pctype_mapping_get_port,
15347                (void *)&cmd_pctype_mapping_get_port_id,
15348                (void *)&cmd_pctype_mapping_get_pctype,
15349                (void *)&cmd_pctype_mapping_get_mapping,
15350                NULL,
15351        },
15352};
15353
15354/* port config pctype mapping update */
15355
15356/* Common result structure for port config pctype mapping update */
15357struct cmd_pctype_mapping_update_result {
15358        cmdline_fixed_string_t port;
15359        cmdline_fixed_string_t config;
15360        portid_t port_id;
15361        cmdline_fixed_string_t pctype;
15362        cmdline_fixed_string_t mapping;
15363        cmdline_fixed_string_t update;
15364        cmdline_fixed_string_t pctype_list;
15365        uint16_t flow_type;
15366};
15367
15368/* Common CLI fields for pctype mapping update*/
15369cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15370        TOKEN_STRING_INITIALIZER
15371                (struct cmd_pctype_mapping_update_result,
15372                 port, "port");
15373cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15374        TOKEN_STRING_INITIALIZER
15375                (struct cmd_pctype_mapping_update_result,
15376                 config, "config");
15377cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15378        TOKEN_NUM_INITIALIZER
15379                (struct cmd_pctype_mapping_update_result,
15380                 port_id, RTE_UINT16);
15381cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15382        TOKEN_STRING_INITIALIZER
15383                (struct cmd_pctype_mapping_update_result,
15384                 pctype, "pctype");
15385cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15386        TOKEN_STRING_INITIALIZER
15387                (struct cmd_pctype_mapping_update_result,
15388                 mapping, "mapping");
15389cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15390        TOKEN_STRING_INITIALIZER
15391                (struct cmd_pctype_mapping_update_result,
15392                 update, "update");
15393cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15394        TOKEN_STRING_INITIALIZER
15395                (struct cmd_pctype_mapping_update_result,
15396                 pctype_list, NULL);
15397cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15398        TOKEN_NUM_INITIALIZER
15399                (struct cmd_pctype_mapping_update_result,
15400                 flow_type, RTE_UINT16);
15401
15402static void
15403cmd_pctype_mapping_update_parsed(
15404        void *parsed_result,
15405        __rte_unused struct cmdline *cl,
15406        __rte_unused void *data)
15407{
15408        struct cmd_pctype_mapping_update_result *res = parsed_result;
15409        int ret = -ENOTSUP;
15410#ifdef RTE_NET_I40E
15411        struct rte_pmd_i40e_flow_type_mapping mapping;
15412        unsigned int i;
15413        unsigned int nb_item;
15414        unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15415#endif
15416
15417        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15418                return;
15419
15420#ifdef RTE_NET_I40E
15421        nb_item = parse_item_list(res->pctype_list, "pctypes",
15422                                  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15423        mapping.flow_type = res->flow_type;
15424        for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15425                mapping.pctype |= (1ULL << pctype_list[i]);
15426        ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15427                                                &mapping,
15428                                                1,
15429                                                0);
15430#endif
15431
15432        switch (ret) {
15433        case 0:
15434                break;
15435        case -EINVAL:
15436                fprintf(stderr, "invalid pctype or flow type\n");
15437                break;
15438        case -ENODEV:
15439                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15440                break;
15441        case -ENOTSUP:
15442                fprintf(stderr, "function not implemented\n");
15443                break;
15444        default:
15445                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15446        }
15447}
15448
15449cmdline_parse_inst_t cmd_pctype_mapping_update = {
15450        .f = cmd_pctype_mapping_update_parsed,
15451        .data = NULL,
15452        .help_str = "port config <port_id> pctype mapping update"
15453        " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15454        .tokens = {
15455                (void *)&cmd_pctype_mapping_update_port,
15456                (void *)&cmd_pctype_mapping_update_config,
15457                (void *)&cmd_pctype_mapping_update_port_id,
15458                (void *)&cmd_pctype_mapping_update_pctype,
15459                (void *)&cmd_pctype_mapping_update_mapping,
15460                (void *)&cmd_pctype_mapping_update_update,
15461                (void *)&cmd_pctype_mapping_update_pc_type,
15462                (void *)&cmd_pctype_mapping_update_flow_type,
15463                NULL,
15464        },
15465};
15466
15467/* ptype mapping get */
15468
15469/* Common result structure for ptype mapping get */
15470struct cmd_ptype_mapping_get_result {
15471        cmdline_fixed_string_t ptype;
15472        cmdline_fixed_string_t mapping;
15473        cmdline_fixed_string_t get;
15474        portid_t port_id;
15475        uint8_t valid_only;
15476};
15477
15478/* Common CLI fields for ptype mapping get */
15479cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15480        TOKEN_STRING_INITIALIZER
15481                (struct cmd_ptype_mapping_get_result,
15482                 ptype, "ptype");
15483cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15484        TOKEN_STRING_INITIALIZER
15485                (struct cmd_ptype_mapping_get_result,
15486                 mapping, "mapping");
15487cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15488        TOKEN_STRING_INITIALIZER
15489                (struct cmd_ptype_mapping_get_result,
15490                 get, "get");
15491cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15492        TOKEN_NUM_INITIALIZER
15493                (struct cmd_ptype_mapping_get_result,
15494                 port_id, RTE_UINT16);
15495cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15496        TOKEN_NUM_INITIALIZER
15497                (struct cmd_ptype_mapping_get_result,
15498                 valid_only, RTE_UINT8);
15499
15500static void
15501cmd_ptype_mapping_get_parsed(
15502        void *parsed_result,
15503        __rte_unused struct cmdline *cl,
15504        __rte_unused void *data)
15505{
15506        struct cmd_ptype_mapping_get_result *res = parsed_result;
15507        int ret = -ENOTSUP;
15508#ifdef RTE_NET_I40E
15509        int max_ptype_num = 256;
15510        struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15511        uint16_t count;
15512        int i;
15513#endif
15514
15515        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15516                return;
15517
15518#ifdef RTE_NET_I40E
15519        ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15520                                        mapping,
15521                                        max_ptype_num,
15522                                        &count,
15523                                        res->valid_only);
15524#endif
15525
15526        switch (ret) {
15527        case 0:
15528                break;
15529        case -ENODEV:
15530                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15531                break;
15532        case -ENOTSUP:
15533                fprintf(stderr, "function not implemented\n");
15534                break;
15535        default:
15536                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15537        }
15538
15539#ifdef RTE_NET_I40E
15540        if (!ret) {
15541                for (i = 0; i < count; i++)
15542                        printf("%3d\t0x%08x\n",
15543                                mapping[i].hw_ptype, mapping[i].sw_ptype);
15544        }
15545#endif
15546}
15547
15548cmdline_parse_inst_t cmd_ptype_mapping_get = {
15549        .f = cmd_ptype_mapping_get_parsed,
15550        .data = NULL,
15551        .help_str = "ptype mapping get <port_id> <valid_only>",
15552        .tokens = {
15553                (void *)&cmd_ptype_mapping_get_ptype,
15554                (void *)&cmd_ptype_mapping_get_mapping,
15555                (void *)&cmd_ptype_mapping_get_get,
15556                (void *)&cmd_ptype_mapping_get_port_id,
15557                (void *)&cmd_ptype_mapping_get_valid_only,
15558                NULL,
15559        },
15560};
15561
15562/* ptype mapping replace */
15563
15564/* Common result structure for ptype mapping replace */
15565struct cmd_ptype_mapping_replace_result {
15566        cmdline_fixed_string_t ptype;
15567        cmdline_fixed_string_t mapping;
15568        cmdline_fixed_string_t replace;
15569        portid_t port_id;
15570        uint32_t target;
15571        uint8_t mask;
15572        uint32_t pkt_type;
15573};
15574
15575/* Common CLI fields for ptype mapping replace */
15576cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15577        TOKEN_STRING_INITIALIZER
15578                (struct cmd_ptype_mapping_replace_result,
15579                 ptype, "ptype");
15580cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15581        TOKEN_STRING_INITIALIZER
15582                (struct cmd_ptype_mapping_replace_result,
15583                 mapping, "mapping");
15584cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15585        TOKEN_STRING_INITIALIZER
15586                (struct cmd_ptype_mapping_replace_result,
15587                 replace, "replace");
15588cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15589        TOKEN_NUM_INITIALIZER
15590                (struct cmd_ptype_mapping_replace_result,
15591                 port_id, RTE_UINT16);
15592cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15593        TOKEN_NUM_INITIALIZER
15594                (struct cmd_ptype_mapping_replace_result,
15595                 target, RTE_UINT32);
15596cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15597        TOKEN_NUM_INITIALIZER
15598                (struct cmd_ptype_mapping_replace_result,
15599                 mask, RTE_UINT8);
15600cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15601        TOKEN_NUM_INITIALIZER
15602                (struct cmd_ptype_mapping_replace_result,
15603                 pkt_type, RTE_UINT32);
15604
15605static void
15606cmd_ptype_mapping_replace_parsed(
15607        void *parsed_result,
15608        __rte_unused struct cmdline *cl,
15609        __rte_unused void *data)
15610{
15611        struct cmd_ptype_mapping_replace_result *res = parsed_result;
15612        int ret = -ENOTSUP;
15613
15614        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15615                return;
15616
15617#ifdef RTE_NET_I40E
15618        ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15619                                        res->target,
15620                                        res->mask,
15621                                        res->pkt_type);
15622#endif
15623
15624        switch (ret) {
15625        case 0:
15626                break;
15627        case -EINVAL:
15628                fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15629                        res->target, res->pkt_type);
15630                break;
15631        case -ENODEV:
15632                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15633                break;
15634        case -ENOTSUP:
15635                fprintf(stderr, "function not implemented\n");
15636                break;
15637        default:
15638                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15639        }
15640}
15641
15642cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15643        .f = cmd_ptype_mapping_replace_parsed,
15644        .data = NULL,
15645        .help_str =
15646                "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15647        .tokens = {
15648                (void *)&cmd_ptype_mapping_replace_ptype,
15649                (void *)&cmd_ptype_mapping_replace_mapping,
15650                (void *)&cmd_ptype_mapping_replace_replace,
15651                (void *)&cmd_ptype_mapping_replace_port_id,
15652                (void *)&cmd_ptype_mapping_replace_target,
15653                (void *)&cmd_ptype_mapping_replace_mask,
15654                (void *)&cmd_ptype_mapping_replace_pkt_type,
15655                NULL,
15656        },
15657};
15658
15659/* ptype mapping reset */
15660
15661/* Common result structure for ptype mapping reset */
15662struct cmd_ptype_mapping_reset_result {
15663        cmdline_fixed_string_t ptype;
15664        cmdline_fixed_string_t mapping;
15665        cmdline_fixed_string_t reset;
15666        portid_t port_id;
15667};
15668
15669/* Common CLI fields for ptype mapping reset*/
15670cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15671        TOKEN_STRING_INITIALIZER
15672                (struct cmd_ptype_mapping_reset_result,
15673                 ptype, "ptype");
15674cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15675        TOKEN_STRING_INITIALIZER
15676                (struct cmd_ptype_mapping_reset_result,
15677                 mapping, "mapping");
15678cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15679        TOKEN_STRING_INITIALIZER
15680                (struct cmd_ptype_mapping_reset_result,
15681                 reset, "reset");
15682cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15683        TOKEN_NUM_INITIALIZER
15684                (struct cmd_ptype_mapping_reset_result,
15685                 port_id, RTE_UINT16);
15686
15687static void
15688cmd_ptype_mapping_reset_parsed(
15689        void *parsed_result,
15690        __rte_unused struct cmdline *cl,
15691        __rte_unused void *data)
15692{
15693        struct cmd_ptype_mapping_reset_result *res = parsed_result;
15694        int ret = -ENOTSUP;
15695
15696        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15697                return;
15698
15699#ifdef RTE_NET_I40E
15700        ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15701#endif
15702
15703        switch (ret) {
15704        case 0:
15705                break;
15706        case -ENODEV:
15707                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15708                break;
15709        case -ENOTSUP:
15710                fprintf(stderr, "function not implemented\n");
15711                break;
15712        default:
15713                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15714        }
15715}
15716
15717cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15718        .f = cmd_ptype_mapping_reset_parsed,
15719        .data = NULL,
15720        .help_str = "ptype mapping reset <port_id>",
15721        .tokens = {
15722                (void *)&cmd_ptype_mapping_reset_ptype,
15723                (void *)&cmd_ptype_mapping_reset_mapping,
15724                (void *)&cmd_ptype_mapping_reset_reset,
15725                (void *)&cmd_ptype_mapping_reset_port_id,
15726                NULL,
15727        },
15728};
15729
15730/* ptype mapping update */
15731
15732/* Common result structure for ptype mapping update */
15733struct cmd_ptype_mapping_update_result {
15734        cmdline_fixed_string_t ptype;
15735        cmdline_fixed_string_t mapping;
15736        cmdline_fixed_string_t reset;
15737        portid_t port_id;
15738        uint8_t hw_ptype;
15739        uint32_t sw_ptype;
15740};
15741
15742/* Common CLI fields for ptype mapping update*/
15743cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15744        TOKEN_STRING_INITIALIZER
15745                (struct cmd_ptype_mapping_update_result,
15746                 ptype, "ptype");
15747cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15748        TOKEN_STRING_INITIALIZER
15749                (struct cmd_ptype_mapping_update_result,
15750                 mapping, "mapping");
15751cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15752        TOKEN_STRING_INITIALIZER
15753                (struct cmd_ptype_mapping_update_result,
15754                 reset, "update");
15755cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15756        TOKEN_NUM_INITIALIZER
15757                (struct cmd_ptype_mapping_update_result,
15758                 port_id, RTE_UINT16);
15759cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15760        TOKEN_NUM_INITIALIZER
15761                (struct cmd_ptype_mapping_update_result,
15762                 hw_ptype, RTE_UINT8);
15763cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15764        TOKEN_NUM_INITIALIZER
15765                (struct cmd_ptype_mapping_update_result,
15766                 sw_ptype, RTE_UINT32);
15767
15768static void
15769cmd_ptype_mapping_update_parsed(
15770        void *parsed_result,
15771        __rte_unused struct cmdline *cl,
15772        __rte_unused void *data)
15773{
15774        struct cmd_ptype_mapping_update_result *res = parsed_result;
15775        int ret = -ENOTSUP;
15776#ifdef RTE_NET_I40E
15777        struct rte_pmd_i40e_ptype_mapping mapping;
15778#endif
15779        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15780                return;
15781
15782#ifdef RTE_NET_I40E
15783        mapping.hw_ptype = res->hw_ptype;
15784        mapping.sw_ptype = res->sw_ptype;
15785        ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15786                                                &mapping,
15787                                                1,
15788                                                0);
15789#endif
15790
15791        switch (ret) {
15792        case 0:
15793                break;
15794        case -EINVAL:
15795                fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15796                break;
15797        case -ENODEV:
15798                fprintf(stderr, "invalid port_id %d\n", res->port_id);
15799                break;
15800        case -ENOTSUP:
15801                fprintf(stderr, "function not implemented\n");
15802                break;
15803        default:
15804                fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15805        }
15806}
15807
15808cmdline_parse_inst_t cmd_ptype_mapping_update = {
15809        .f = cmd_ptype_mapping_update_parsed,
15810        .data = NULL,
15811        .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15812        .tokens = {
15813                (void *)&cmd_ptype_mapping_update_ptype,
15814                (void *)&cmd_ptype_mapping_update_mapping,
15815                (void *)&cmd_ptype_mapping_update_update,
15816                (void *)&cmd_ptype_mapping_update_port_id,
15817                (void *)&cmd_ptype_mapping_update_hw_ptype,
15818                (void *)&cmd_ptype_mapping_update_sw_ptype,
15819                NULL,
15820        },
15821};
15822
15823/* Common result structure for file commands */
15824struct cmd_cmdfile_result {
15825        cmdline_fixed_string_t load;
15826        cmdline_fixed_string_t filename;
15827};
15828
15829/* Common CLI fields for file commands */
15830cmdline_parse_token_string_t cmd_load_cmdfile =
15831        TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15832cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15833        TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15834
15835static void
15836cmd_load_from_file_parsed(
15837        void *parsed_result,
15838        __rte_unused struct cmdline *cl,
15839        __rte_unused void *data)
15840{
15841        struct cmd_cmdfile_result *res = parsed_result;
15842
15843        cmdline_read_from_file(res->filename);
15844}
15845
15846cmdline_parse_inst_t cmd_load_from_file = {
15847        .f = cmd_load_from_file_parsed,
15848        .data = NULL,
15849        .help_str = "load <filename>",
15850        .tokens = {
15851                (void *)&cmd_load_cmdfile,
15852                (void *)&cmd_load_cmdfile_filename,
15853                NULL,
15854        },
15855};
15856
15857/* Get Rx offloads capabilities */
15858struct cmd_rx_offload_get_capa_result {
15859        cmdline_fixed_string_t show;
15860        cmdline_fixed_string_t port;
15861        portid_t port_id;
15862        cmdline_fixed_string_t rx_offload;
15863        cmdline_fixed_string_t capabilities;
15864};
15865
15866cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15867        TOKEN_STRING_INITIALIZER
15868                (struct cmd_rx_offload_get_capa_result,
15869                 show, "show");
15870cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15871        TOKEN_STRING_INITIALIZER
15872                (struct cmd_rx_offload_get_capa_result,
15873                 port, "port");
15874cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15875        TOKEN_NUM_INITIALIZER
15876                (struct cmd_rx_offload_get_capa_result,
15877                 port_id, RTE_UINT16);
15878cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15879        TOKEN_STRING_INITIALIZER
15880                (struct cmd_rx_offload_get_capa_result,
15881                 rx_offload, "rx_offload");
15882cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15883        TOKEN_STRING_INITIALIZER
15884                (struct cmd_rx_offload_get_capa_result,
15885                 capabilities, "capabilities");
15886
15887static void
15888print_rx_offloads(uint64_t offloads)
15889{
15890        uint64_t single_offload;
15891        int begin;
15892        int end;
15893        int bit;
15894
15895        if (offloads == 0)
15896                return;
15897
15898        begin = __builtin_ctzll(offloads);
15899        end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15900
15901        single_offload = 1ULL << begin;
15902        for (bit = begin; bit < end; bit++) {
15903                if (offloads & single_offload)
15904                        printf(" %s",
15905                               rte_eth_dev_rx_offload_name(single_offload));
15906                single_offload <<= 1;
15907        }
15908}
15909
15910static void
15911cmd_rx_offload_get_capa_parsed(
15912        void *parsed_result,
15913        __rte_unused struct cmdline *cl,
15914        __rte_unused void *data)
15915{
15916        struct cmd_rx_offload_get_capa_result *res = parsed_result;
15917        struct rte_eth_dev_info dev_info;
15918        portid_t port_id = res->port_id;
15919        uint64_t queue_offloads;
15920        uint64_t port_offloads;
15921        int ret;
15922
15923        ret = eth_dev_info_get_print_err(port_id, &dev_info);
15924        if (ret != 0)
15925                return;
15926
15927        queue_offloads = dev_info.rx_queue_offload_capa;
15928        port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15929
15930        printf("Rx Offloading Capabilities of port %d :\n", port_id);
15931        printf("  Per Queue :");
15932        print_rx_offloads(queue_offloads);
15933
15934        printf("\n");
15935        printf("  Per Port  :");
15936        print_rx_offloads(port_offloads);
15937        printf("\n\n");
15938}
15939
15940cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15941        .f = cmd_rx_offload_get_capa_parsed,
15942        .data = NULL,
15943        .help_str = "show port <port_id> rx_offload capabilities",
15944        .tokens = {
15945                (void *)&cmd_rx_offload_get_capa_show,
15946                (void *)&cmd_rx_offload_get_capa_port,
15947                (void *)&cmd_rx_offload_get_capa_port_id,
15948                (void *)&cmd_rx_offload_get_capa_rx_offload,
15949                (void *)&cmd_rx_offload_get_capa_capabilities,
15950                NULL,
15951        }
15952};
15953
15954/* Get Rx offloads configuration */
15955struct cmd_rx_offload_get_configuration_result {
15956        cmdline_fixed_string_t show;
15957        cmdline_fixed_string_t port;
15958        portid_t port_id;
15959        cmdline_fixed_string_t rx_offload;
15960        cmdline_fixed_string_t configuration;
15961};
15962
15963cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15964        TOKEN_STRING_INITIALIZER
15965                (struct cmd_rx_offload_get_configuration_result,
15966                 show, "show");
15967cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15968        TOKEN_STRING_INITIALIZER
15969                (struct cmd_rx_offload_get_configuration_result,
15970                 port, "port");
15971cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15972        TOKEN_NUM_INITIALIZER
15973                (struct cmd_rx_offload_get_configuration_result,
15974                 port_id, RTE_UINT16);
15975cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15976        TOKEN_STRING_INITIALIZER
15977                (struct cmd_rx_offload_get_configuration_result,
15978                 rx_offload, "rx_offload");
15979cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15980        TOKEN_STRING_INITIALIZER
15981                (struct cmd_rx_offload_get_configuration_result,
15982                 configuration, "configuration");
15983
15984static void
15985cmd_rx_offload_get_configuration_parsed(
15986        void *parsed_result,
15987        __rte_unused struct cmdline *cl,
15988        __rte_unused void *data)
15989{
15990        struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15991        struct rte_eth_dev_info dev_info;
15992        portid_t port_id = res->port_id;
15993        struct rte_port *port = &ports[port_id];
15994        uint64_t port_offloads;
15995        uint64_t queue_offloads;
15996        uint16_t nb_rx_queues;
15997        int q;
15998        int ret;
15999
16000        printf("Rx Offloading Configuration of port %d :\n", port_id);
16001
16002        port_offloads = port->dev_conf.rxmode.offloads;
16003        printf("  Port :");
16004        print_rx_offloads(port_offloads);
16005        printf("\n");
16006
16007        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16008        if (ret != 0)
16009                return;
16010
16011        nb_rx_queues = dev_info.nb_rx_queues;
16012        for (q = 0; q < nb_rx_queues; q++) {
16013                queue_offloads = port->rx_conf[q].offloads;
16014                printf("  Queue[%2d] :", q);
16015                print_rx_offloads(queue_offloads);
16016                printf("\n");
16017        }
16018        printf("\n");
16019}
16020
16021cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16022        .f = cmd_rx_offload_get_configuration_parsed,
16023        .data = NULL,
16024        .help_str = "show port <port_id> rx_offload configuration",
16025        .tokens = {
16026                (void *)&cmd_rx_offload_get_configuration_show,
16027                (void *)&cmd_rx_offload_get_configuration_port,
16028                (void *)&cmd_rx_offload_get_configuration_port_id,
16029                (void *)&cmd_rx_offload_get_configuration_rx_offload,
16030                (void *)&cmd_rx_offload_get_configuration_configuration,
16031                NULL,
16032        }
16033};
16034
16035/* Enable/Disable a per port offloading */
16036struct cmd_config_per_port_rx_offload_result {
16037        cmdline_fixed_string_t port;
16038        cmdline_fixed_string_t config;
16039        portid_t port_id;
16040        cmdline_fixed_string_t rx_offload;
16041        cmdline_fixed_string_t offload;
16042        cmdline_fixed_string_t on_off;
16043};
16044
16045cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16046        TOKEN_STRING_INITIALIZER
16047                (struct cmd_config_per_port_rx_offload_result,
16048                 port, "port");
16049cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16050        TOKEN_STRING_INITIALIZER
16051                (struct cmd_config_per_port_rx_offload_result,
16052                 config, "config");
16053cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16054        TOKEN_NUM_INITIALIZER
16055                (struct cmd_config_per_port_rx_offload_result,
16056                 port_id, RTE_UINT16);
16057cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16058        TOKEN_STRING_INITIALIZER
16059                (struct cmd_config_per_port_rx_offload_result,
16060                 rx_offload, "rx_offload");
16061cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16062        TOKEN_STRING_INITIALIZER
16063                (struct cmd_config_per_port_rx_offload_result,
16064                 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16065                           "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16066                           "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16067                           "scatter#buffer_split#timestamp#security#"
16068                           "keep_crc#rss_hash");
16069cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16070        TOKEN_STRING_INITIALIZER
16071                (struct cmd_config_per_port_rx_offload_result,
16072                 on_off, "on#off");
16073
16074static uint64_t
16075search_rx_offload(const char *name)
16076{
16077        uint64_t single_offload;
16078        const char *single_name;
16079        int found = 0;
16080        unsigned int bit;
16081
16082        single_offload = 1;
16083        for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16084                single_name = rte_eth_dev_rx_offload_name(single_offload);
16085                if (!strcasecmp(single_name, name)) {
16086                        found = 1;
16087                        break;
16088                }
16089                single_offload <<= 1;
16090        }
16091
16092        if (found)
16093                return single_offload;
16094
16095        return 0;
16096}
16097
16098static void
16099cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16100                                __rte_unused struct cmdline *cl,
16101                                __rte_unused void *data)
16102{
16103        struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16104        portid_t port_id = res->port_id;
16105        struct rte_eth_dev_info dev_info;
16106        struct rte_port *port = &ports[port_id];
16107        uint64_t single_offload;
16108        uint16_t nb_rx_queues;
16109        int q;
16110        int ret;
16111
16112        if (port->port_status != RTE_PORT_STOPPED) {
16113                fprintf(stderr,
16114                        "Error: Can't config offload when Port %d is not stopped\n",
16115                        port_id);
16116                return;
16117        }
16118
16119        single_offload = search_rx_offload(res->offload);
16120        if (single_offload == 0) {
16121                fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16122                return;
16123        }
16124
16125        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16126        if (ret != 0)
16127                return;
16128
16129        nb_rx_queues = dev_info.nb_rx_queues;
16130        if (!strcmp(res->on_off, "on")) {
16131                port->dev_conf.rxmode.offloads |= single_offload;
16132                for (q = 0; q < nb_rx_queues; q++)
16133                        port->rx_conf[q].offloads |= single_offload;
16134        } else {
16135                port->dev_conf.rxmode.offloads &= ~single_offload;
16136                for (q = 0; q < nb_rx_queues; q++)
16137                        port->rx_conf[q].offloads &= ~single_offload;
16138        }
16139
16140        cmd_reconfig_device_queue(port_id, 1, 1);
16141}
16142
16143cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16144        .f = cmd_config_per_port_rx_offload_parsed,
16145        .data = NULL,
16146        .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16147                    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16148                    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16149                    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16150                    "keep_crc|rss_hash on|off",
16151        .tokens = {
16152                (void *)&cmd_config_per_port_rx_offload_result_port,
16153                (void *)&cmd_config_per_port_rx_offload_result_config,
16154                (void *)&cmd_config_per_port_rx_offload_result_port_id,
16155                (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16156                (void *)&cmd_config_per_port_rx_offload_result_offload,
16157                (void *)&cmd_config_per_port_rx_offload_result_on_off,
16158                NULL,
16159        }
16160};
16161
16162/* Enable/Disable a per queue offloading */
16163struct cmd_config_per_queue_rx_offload_result {
16164        cmdline_fixed_string_t port;
16165        portid_t port_id;
16166        cmdline_fixed_string_t rxq;
16167        uint16_t queue_id;
16168        cmdline_fixed_string_t rx_offload;
16169        cmdline_fixed_string_t offload;
16170        cmdline_fixed_string_t on_off;
16171};
16172
16173cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16174        TOKEN_STRING_INITIALIZER
16175                (struct cmd_config_per_queue_rx_offload_result,
16176                 port, "port");
16177cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16178        TOKEN_NUM_INITIALIZER
16179                (struct cmd_config_per_queue_rx_offload_result,
16180                 port_id, RTE_UINT16);
16181cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16182        TOKEN_STRING_INITIALIZER
16183                (struct cmd_config_per_queue_rx_offload_result,
16184                 rxq, "rxq");
16185cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16186        TOKEN_NUM_INITIALIZER
16187                (struct cmd_config_per_queue_rx_offload_result,
16188                 queue_id, RTE_UINT16);
16189cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16190        TOKEN_STRING_INITIALIZER
16191                (struct cmd_config_per_queue_rx_offload_result,
16192                 rx_offload, "rx_offload");
16193cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16194        TOKEN_STRING_INITIALIZER
16195                (struct cmd_config_per_queue_rx_offload_result,
16196                 offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16197                           "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16198                           "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16199                           "scatter#buffer_split#timestamp#security#keep_crc");
16200cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16201        TOKEN_STRING_INITIALIZER
16202                (struct cmd_config_per_queue_rx_offload_result,
16203                 on_off, "on#off");
16204
16205static void
16206cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16207                                __rte_unused struct cmdline *cl,
16208                                __rte_unused void *data)
16209{
16210        struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16211        struct rte_eth_dev_info dev_info;
16212        portid_t port_id = res->port_id;
16213        uint16_t queue_id = res->queue_id;
16214        struct rte_port *port = &ports[port_id];
16215        uint64_t single_offload;
16216        int ret;
16217
16218        if (port->port_status != RTE_PORT_STOPPED) {
16219                fprintf(stderr,
16220                        "Error: Can't config offload when Port %d is not stopped\n",
16221                        port_id);
16222                return;
16223        }
16224
16225        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16226        if (ret != 0)
16227                return;
16228
16229        if (queue_id >= dev_info.nb_rx_queues) {
16230                fprintf(stderr,
16231                        "Error: input queue_id should be 0 ... %d\n",
16232                        dev_info.nb_rx_queues - 1);
16233                return;
16234        }
16235
16236        single_offload = search_rx_offload(res->offload);
16237        if (single_offload == 0) {
16238                fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16239                return;
16240        }
16241
16242        if (!strcmp(res->on_off, "on"))
16243                port->rx_conf[queue_id].offloads |= single_offload;
16244        else
16245                port->rx_conf[queue_id].offloads &= ~single_offload;
16246
16247        cmd_reconfig_device_queue(port_id, 1, 1);
16248}
16249
16250cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16251        .f = cmd_config_per_queue_rx_offload_parsed,
16252        .data = NULL,
16253        .help_str = "port <port_id> rxq <queue_id> rx_offload "
16254                    "vlan_strip|ipv4_cksum|"
16255                    "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16256                    "macsec_strip|header_split|vlan_filter|vlan_extend|"
16257                    "jumbo_frame|scatter|buffer_split|timestamp|security|"
16258                    "keep_crc on|off",
16259        .tokens = {
16260                (void *)&cmd_config_per_queue_rx_offload_result_port,
16261                (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16262                (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16263                (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16264                (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16265                (void *)&cmd_config_per_queue_rx_offload_result_offload,
16266                (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16267                NULL,
16268        }
16269};
16270
16271/* Get Tx offloads capabilities */
16272struct cmd_tx_offload_get_capa_result {
16273        cmdline_fixed_string_t show;
16274        cmdline_fixed_string_t port;
16275        portid_t port_id;
16276        cmdline_fixed_string_t tx_offload;
16277        cmdline_fixed_string_t capabilities;
16278};
16279
16280cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16281        TOKEN_STRING_INITIALIZER
16282                (struct cmd_tx_offload_get_capa_result,
16283                 show, "show");
16284cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16285        TOKEN_STRING_INITIALIZER
16286                (struct cmd_tx_offload_get_capa_result,
16287                 port, "port");
16288cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16289        TOKEN_NUM_INITIALIZER
16290                (struct cmd_tx_offload_get_capa_result,
16291                 port_id, RTE_UINT16);
16292cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16293        TOKEN_STRING_INITIALIZER
16294                (struct cmd_tx_offload_get_capa_result,
16295                 tx_offload, "tx_offload");
16296cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16297        TOKEN_STRING_INITIALIZER
16298                (struct cmd_tx_offload_get_capa_result,
16299                 capabilities, "capabilities");
16300
16301static void
16302print_tx_offloads(uint64_t offloads)
16303{
16304        uint64_t single_offload;
16305        int begin;
16306        int end;
16307        int bit;
16308
16309        if (offloads == 0)
16310                return;
16311
16312        begin = __builtin_ctzll(offloads);
16313        end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16314
16315        single_offload = 1ULL << begin;
16316        for (bit = begin; bit < end; bit++) {
16317                if (offloads & single_offload)
16318                        printf(" %s",
16319                               rte_eth_dev_tx_offload_name(single_offload));
16320                single_offload <<= 1;
16321        }
16322}
16323
16324static void
16325cmd_tx_offload_get_capa_parsed(
16326        void *parsed_result,
16327        __rte_unused struct cmdline *cl,
16328        __rte_unused void *data)
16329{
16330        struct cmd_tx_offload_get_capa_result *res = parsed_result;
16331        struct rte_eth_dev_info dev_info;
16332        portid_t port_id = res->port_id;
16333        uint64_t queue_offloads;
16334        uint64_t port_offloads;
16335        int ret;
16336
16337        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16338        if (ret != 0)
16339                return;
16340
16341        queue_offloads = dev_info.tx_queue_offload_capa;
16342        port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16343
16344        printf("Tx Offloading Capabilities of port %d :\n", port_id);
16345        printf("  Per Queue :");
16346        print_tx_offloads(queue_offloads);
16347
16348        printf("\n");
16349        printf("  Per Port  :");
16350        print_tx_offloads(port_offloads);
16351        printf("\n\n");
16352}
16353
16354cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16355        .f = cmd_tx_offload_get_capa_parsed,
16356        .data = NULL,
16357        .help_str = "show port <port_id> tx_offload capabilities",
16358        .tokens = {
16359                (void *)&cmd_tx_offload_get_capa_show,
16360                (void *)&cmd_tx_offload_get_capa_port,
16361                (void *)&cmd_tx_offload_get_capa_port_id,
16362                (void *)&cmd_tx_offload_get_capa_tx_offload,
16363                (void *)&cmd_tx_offload_get_capa_capabilities,
16364                NULL,
16365        }
16366};
16367
16368/* Get Tx offloads configuration */
16369struct cmd_tx_offload_get_configuration_result {
16370        cmdline_fixed_string_t show;
16371        cmdline_fixed_string_t port;
16372        portid_t port_id;
16373        cmdline_fixed_string_t tx_offload;
16374        cmdline_fixed_string_t configuration;
16375};
16376
16377cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16378        TOKEN_STRING_INITIALIZER
16379                (struct cmd_tx_offload_get_configuration_result,
16380                 show, "show");
16381cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16382        TOKEN_STRING_INITIALIZER
16383                (struct cmd_tx_offload_get_configuration_result,
16384                 port, "port");
16385cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16386        TOKEN_NUM_INITIALIZER
16387                (struct cmd_tx_offload_get_configuration_result,
16388                 port_id, RTE_UINT16);
16389cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16390        TOKEN_STRING_INITIALIZER
16391                (struct cmd_tx_offload_get_configuration_result,
16392                 tx_offload, "tx_offload");
16393cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16394        TOKEN_STRING_INITIALIZER
16395                (struct cmd_tx_offload_get_configuration_result,
16396                 configuration, "configuration");
16397
16398static void
16399cmd_tx_offload_get_configuration_parsed(
16400        void *parsed_result,
16401        __rte_unused struct cmdline *cl,
16402        __rte_unused void *data)
16403{
16404        struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16405        struct rte_eth_dev_info dev_info;
16406        portid_t port_id = res->port_id;
16407        struct rte_port *port = &ports[port_id];
16408        uint64_t port_offloads;
16409        uint64_t queue_offloads;
16410        uint16_t nb_tx_queues;
16411        int q;
16412        int ret;
16413
16414        printf("Tx Offloading Configuration of port %d :\n", port_id);
16415
16416        port_offloads = port->dev_conf.txmode.offloads;
16417        printf("  Port :");
16418        print_tx_offloads(port_offloads);
16419        printf("\n");
16420
16421        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16422        if (ret != 0)
16423                return;
16424
16425        nb_tx_queues = dev_info.nb_tx_queues;
16426        for (q = 0; q < nb_tx_queues; q++) {
16427                queue_offloads = port->tx_conf[q].offloads;
16428                printf("  Queue[%2d] :", q);
16429                print_tx_offloads(queue_offloads);
16430                printf("\n");
16431        }
16432        printf("\n");
16433}
16434
16435cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16436        .f = cmd_tx_offload_get_configuration_parsed,
16437        .data = NULL,
16438        .help_str = "show port <port_id> tx_offload configuration",
16439        .tokens = {
16440                (void *)&cmd_tx_offload_get_configuration_show,
16441                (void *)&cmd_tx_offload_get_configuration_port,
16442                (void *)&cmd_tx_offload_get_configuration_port_id,
16443                (void *)&cmd_tx_offload_get_configuration_tx_offload,
16444                (void *)&cmd_tx_offload_get_configuration_configuration,
16445                NULL,
16446        }
16447};
16448
16449/* Enable/Disable a per port offloading */
16450struct cmd_config_per_port_tx_offload_result {
16451        cmdline_fixed_string_t port;
16452        cmdline_fixed_string_t config;
16453        portid_t port_id;
16454        cmdline_fixed_string_t tx_offload;
16455        cmdline_fixed_string_t offload;
16456        cmdline_fixed_string_t on_off;
16457};
16458
16459cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16460        TOKEN_STRING_INITIALIZER
16461                (struct cmd_config_per_port_tx_offload_result,
16462                 port, "port");
16463cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16464        TOKEN_STRING_INITIALIZER
16465                (struct cmd_config_per_port_tx_offload_result,
16466                 config, "config");
16467cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16468        TOKEN_NUM_INITIALIZER
16469                (struct cmd_config_per_port_tx_offload_result,
16470                 port_id, RTE_UINT16);
16471cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16472        TOKEN_STRING_INITIALIZER
16473                (struct cmd_config_per_port_tx_offload_result,
16474                 tx_offload, "tx_offload");
16475cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16476        TOKEN_STRING_INITIALIZER
16477                (struct cmd_config_per_port_tx_offload_result,
16478                 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16479                          "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16480                          "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16481                          "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16482                          "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16483                          "send_on_timestamp");
16484cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16485        TOKEN_STRING_INITIALIZER
16486                (struct cmd_config_per_port_tx_offload_result,
16487                 on_off, "on#off");
16488
16489static uint64_t
16490search_tx_offload(const char *name)
16491{
16492        uint64_t single_offload;
16493        const char *single_name;
16494        int found = 0;
16495        unsigned int bit;
16496
16497        single_offload = 1;
16498        for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16499                single_name = rte_eth_dev_tx_offload_name(single_offload);
16500                if (single_name == NULL)
16501                        break;
16502                if (!strcasecmp(single_name, name)) {
16503                        found = 1;
16504                        break;
16505                } else if (!strcasecmp(single_name, "UNKNOWN"))
16506                        break;
16507                single_offload <<= 1;
16508        }
16509
16510        if (found)
16511                return single_offload;
16512
16513        return 0;
16514}
16515
16516static void
16517cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16518                                __rte_unused struct cmdline *cl,
16519                                __rte_unused void *data)
16520{
16521        struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16522        portid_t port_id = res->port_id;
16523        struct rte_eth_dev_info dev_info;
16524        struct rte_port *port = &ports[port_id];
16525        uint64_t single_offload;
16526        uint16_t nb_tx_queues;
16527        int q;
16528        int ret;
16529
16530        if (port->port_status != RTE_PORT_STOPPED) {
16531                fprintf(stderr,
16532                        "Error: Can't config offload when Port %d is not stopped\n",
16533                        port_id);
16534                return;
16535        }
16536
16537        single_offload = search_tx_offload(res->offload);
16538        if (single_offload == 0) {
16539                fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16540                return;
16541        }
16542
16543        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16544        if (ret != 0)
16545                return;
16546
16547        nb_tx_queues = dev_info.nb_tx_queues;
16548        if (!strcmp(res->on_off, "on")) {
16549                port->dev_conf.txmode.offloads |= single_offload;
16550                for (q = 0; q < nb_tx_queues; q++)
16551                        port->tx_conf[q].offloads |= single_offload;
16552        } else {
16553                port->dev_conf.txmode.offloads &= ~single_offload;
16554                for (q = 0; q < nb_tx_queues; q++)
16555                        port->tx_conf[q].offloads &= ~single_offload;
16556        }
16557
16558        cmd_reconfig_device_queue(port_id, 1, 1);
16559}
16560
16561cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16562        .f = cmd_config_per_port_tx_offload_parsed,
16563        .data = NULL,
16564        .help_str = "port config <port_id> tx_offload "
16565                    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16566                    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16567                    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16568                    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16569                    "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16570                    "send_on_timestamp on|off",
16571        .tokens = {
16572                (void *)&cmd_config_per_port_tx_offload_result_port,
16573                (void *)&cmd_config_per_port_tx_offload_result_config,
16574                (void *)&cmd_config_per_port_tx_offload_result_port_id,
16575                (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16576                (void *)&cmd_config_per_port_tx_offload_result_offload,
16577                (void *)&cmd_config_per_port_tx_offload_result_on_off,
16578                NULL,
16579        }
16580};
16581
16582/* Enable/Disable a per queue offloading */
16583struct cmd_config_per_queue_tx_offload_result {
16584        cmdline_fixed_string_t port;
16585        portid_t port_id;
16586        cmdline_fixed_string_t txq;
16587        uint16_t queue_id;
16588        cmdline_fixed_string_t tx_offload;
16589        cmdline_fixed_string_t offload;
16590        cmdline_fixed_string_t on_off;
16591};
16592
16593cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16594        TOKEN_STRING_INITIALIZER
16595                (struct cmd_config_per_queue_tx_offload_result,
16596                 port, "port");
16597cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16598        TOKEN_NUM_INITIALIZER
16599                (struct cmd_config_per_queue_tx_offload_result,
16600                 port_id, RTE_UINT16);
16601cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16602        TOKEN_STRING_INITIALIZER
16603                (struct cmd_config_per_queue_tx_offload_result,
16604                 txq, "txq");
16605cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16606        TOKEN_NUM_INITIALIZER
16607                (struct cmd_config_per_queue_tx_offload_result,
16608                 queue_id, RTE_UINT16);
16609cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16610        TOKEN_STRING_INITIALIZER
16611                (struct cmd_config_per_queue_tx_offload_result,
16612                 tx_offload, "tx_offload");
16613cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16614        TOKEN_STRING_INITIALIZER
16615                (struct cmd_config_per_queue_tx_offload_result,
16616                 offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16617                          "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16618                          "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16619                          "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16620                          "mt_lockfree#multi_segs#mbuf_fast_free#security");
16621cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16622        TOKEN_STRING_INITIALIZER
16623                (struct cmd_config_per_queue_tx_offload_result,
16624                 on_off, "on#off");
16625
16626static void
16627cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16628                                __rte_unused struct cmdline *cl,
16629                                __rte_unused void *data)
16630{
16631        struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16632        struct rte_eth_dev_info dev_info;
16633        portid_t port_id = res->port_id;
16634        uint16_t queue_id = res->queue_id;
16635        struct rte_port *port = &ports[port_id];
16636        uint64_t single_offload;
16637        int ret;
16638
16639        if (port->port_status != RTE_PORT_STOPPED) {
16640                fprintf(stderr,
16641                        "Error: Can't config offload when Port %d is not stopped\n",
16642                        port_id);
16643                return;
16644        }
16645
16646        ret = eth_dev_info_get_print_err(port_id, &dev_info);
16647        if (ret != 0)
16648                return;
16649
16650        if (queue_id >= dev_info.nb_tx_queues) {
16651                fprintf(stderr,
16652                        "Error: input queue_id should be 0 ... %d\n",
16653                        dev_info.nb_tx_queues - 1);
16654                return;
16655        }
16656
16657        single_offload = search_tx_offload(res->offload);
16658        if (single_offload == 0) {
16659                fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16660                return;
16661        }
16662
16663        if (!strcmp(res->on_off, "on"))
16664                port->tx_conf[queue_id].offloads |= single_offload;
16665        else
16666                port->tx_conf[queue_id].offloads &= ~single_offload;
16667
16668        cmd_reconfig_device_queue(port_id, 1, 1);
16669}
16670
16671cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16672        .f = cmd_config_per_queue_tx_offload_parsed,
16673        .data = NULL,
16674        .help_str = "port <port_id> txq <queue_id> tx_offload "
16675                    "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16676                    "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16677                    "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16678                    "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16679                    "mt_lockfree|multi_segs|mbuf_fast_free|security "
16680                    "on|off",
16681        .tokens = {
16682                (void *)&cmd_config_per_queue_tx_offload_result_port,
16683                (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16684                (void *)&cmd_config_per_queue_tx_offload_result_txq,
16685                (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16686                (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16687                (void *)&cmd_config_per_queue_tx_offload_result_offload,
16688                (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16689                NULL,
16690        }
16691};
16692
16693/* *** configure tx_metadata for specific port *** */
16694struct cmd_config_tx_metadata_specific_result {
16695        cmdline_fixed_string_t port;
16696        cmdline_fixed_string_t keyword;
16697        uint16_t port_id;
16698        cmdline_fixed_string_t item;
16699        uint32_t value;
16700};
16701
16702static void
16703cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16704                                __rte_unused struct cmdline *cl,
16705                                __rte_unused void *data)
16706{
16707        struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16708
16709        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16710                return;
16711        ports[res->port_id].tx_metadata = res->value;
16712        /* Add/remove callback to insert valid metadata in every Tx packet. */
16713        if (ports[res->port_id].tx_metadata)
16714                add_tx_md_callback(res->port_id);
16715        else
16716                remove_tx_md_callback(res->port_id);
16717        rte_flow_dynf_metadata_register();
16718}
16719
16720cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16721        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16722                        port, "port");
16723cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16724        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16725                        keyword, "config");
16726cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16727        TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16728                        port_id, RTE_UINT16);
16729cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16730        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16731                        item, "tx_metadata");
16732cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16733        TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16734                        value, RTE_UINT32);
16735
16736cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16737        .f = cmd_config_tx_metadata_specific_parsed,
16738        .data = NULL,
16739        .help_str = "port config <port_id> tx_metadata <value>",
16740        .tokens = {
16741                (void *)&cmd_config_tx_metadata_specific_port,
16742                (void *)&cmd_config_tx_metadata_specific_keyword,
16743                (void *)&cmd_config_tx_metadata_specific_id,
16744                (void *)&cmd_config_tx_metadata_specific_item,
16745                (void *)&cmd_config_tx_metadata_specific_value,
16746                NULL,
16747        },
16748};
16749
16750/* *** set dynf *** */
16751struct cmd_config_tx_dynf_specific_result {
16752        cmdline_fixed_string_t port;
16753        cmdline_fixed_string_t keyword;
16754        uint16_t port_id;
16755        cmdline_fixed_string_t item;
16756        cmdline_fixed_string_t name;
16757        cmdline_fixed_string_t value;
16758};
16759
16760static void
16761cmd_config_dynf_specific_parsed(void *parsed_result,
16762                                __rte_unused struct cmdline *cl,
16763                                __rte_unused void *data)
16764{
16765        struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16766        struct rte_mbuf_dynflag desc_flag;
16767        int flag;
16768        uint64_t old_port_flags;
16769
16770        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16771                return;
16772        flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16773        if (flag <= 0) {
16774                if (strlcpy(desc_flag.name, res->name,
16775                            RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16776                        fprintf(stderr, "Flag name too long\n");
16777                        return;
16778                }
16779                desc_flag.flags = 0;
16780                flag = rte_mbuf_dynflag_register(&desc_flag);
16781                if (flag < 0) {
16782                        fprintf(stderr, "Can't register flag\n");
16783                        return;
16784                }
16785                strcpy(dynf_names[flag], desc_flag.name);
16786        }
16787        old_port_flags = ports[res->port_id].mbuf_dynf;
16788        if (!strcmp(res->value, "set")) {
16789                ports[res->port_id].mbuf_dynf |= 1UL << flag;
16790                if (old_port_flags == 0)
16791                        add_tx_dynf_callback(res->port_id);
16792        } else {
16793                ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16794                if (ports[res->port_id].mbuf_dynf == 0)
16795                        remove_tx_dynf_callback(res->port_id);
16796        }
16797}
16798
16799cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16800        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16801                        keyword, "port");
16802cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16803        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16804                        keyword, "config");
16805cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16806        TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16807                        port_id, RTE_UINT16);
16808cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16809        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16810                        item, "dynf");
16811cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16812        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16813                        name, NULL);
16814cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16815        TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16816                        value, "set#clear");
16817
16818cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16819        .f = cmd_config_dynf_specific_parsed,
16820        .data = NULL,
16821        .help_str = "port config <port id> dynf <name> set|clear",
16822        .tokens = {
16823                (void *)&cmd_config_tx_dynf_specific_port,
16824                (void *)&cmd_config_tx_dynf_specific_keyword,
16825                (void *)&cmd_config_tx_dynf_specific_port_id,
16826                (void *)&cmd_config_tx_dynf_specific_item,
16827                (void *)&cmd_config_tx_dynf_specific_name,
16828                (void *)&cmd_config_tx_dynf_specific_value,
16829                NULL,
16830        },
16831};
16832
16833/* *** display tx_metadata per port configuration *** */
16834struct cmd_show_tx_metadata_result {
16835        cmdline_fixed_string_t cmd_show;
16836        cmdline_fixed_string_t cmd_port;
16837        cmdline_fixed_string_t cmd_keyword;
16838        portid_t cmd_pid;
16839};
16840
16841static void
16842cmd_show_tx_metadata_parsed(void *parsed_result,
16843                __rte_unused struct cmdline *cl,
16844                __rte_unused void *data)
16845{
16846        struct cmd_show_tx_metadata_result *res = parsed_result;
16847
16848        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16849                fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
16850                return;
16851        }
16852        if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16853                printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16854                       ports[res->cmd_pid].tx_metadata);
16855        }
16856}
16857
16858cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16859        TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16860                        cmd_show, "show");
16861cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16862        TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16863                        cmd_port, "port");
16864cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16865        TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16866                        cmd_pid, RTE_UINT16);
16867cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16868        TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16869                        cmd_keyword, "tx_metadata");
16870
16871cmdline_parse_inst_t cmd_show_tx_metadata = {
16872        .f = cmd_show_tx_metadata_parsed,
16873        .data = NULL,
16874        .help_str = "show port <port_id> tx_metadata",
16875        .tokens = {
16876                (void *)&cmd_show_tx_metadata_show,
16877                (void *)&cmd_show_tx_metadata_port,
16878                (void *)&cmd_show_tx_metadata_pid,
16879                (void *)&cmd_show_tx_metadata_keyword,
16880                NULL,
16881        },
16882};
16883
16884/* *** show fec capability per port configuration *** */
16885struct cmd_show_fec_capability_result {
16886        cmdline_fixed_string_t cmd_show;
16887        cmdline_fixed_string_t cmd_port;
16888        cmdline_fixed_string_t cmd_fec;
16889        cmdline_fixed_string_t cmd_keyword;
16890        portid_t cmd_pid;
16891};
16892
16893static void
16894cmd_show_fec_capability_parsed(void *parsed_result,
16895                __rte_unused struct cmdline *cl,
16896                __rte_unused void *data)
16897{
16898        struct cmd_show_fec_capability_result *res = parsed_result;
16899        struct rte_eth_fec_capa *speed_fec_capa;
16900        unsigned int num;
16901        int ret;
16902
16903        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16904                fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16905                return;
16906        }
16907
16908        ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16909        if (ret == -ENOTSUP) {
16910                fprintf(stderr, "Function not implemented\n");
16911                return;
16912        } else if (ret < 0) {
16913                fprintf(stderr, "Get FEC capability failed: %d\n", ret);
16914                return;
16915        }
16916
16917        num = (unsigned int)ret;
16918        speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16919        if (speed_fec_capa == NULL) {
16920                fprintf(stderr, "Failed to alloc FEC capability buffer\n");
16921                return;
16922        }
16923
16924        ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16925        if (ret < 0) {
16926                fprintf(stderr, "Error getting FEC capability: %d\n", ret);
16927                goto out;
16928        }
16929
16930        show_fec_capability(num, speed_fec_capa);
16931out:
16932        free(speed_fec_capa);
16933}
16934
16935cmdline_parse_token_string_t cmd_show_fec_capability_show =
16936        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16937                        cmd_show, "show");
16938cmdline_parse_token_string_t cmd_show_fec_capability_port =
16939        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16940                        cmd_port, "port");
16941cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16942        TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16943                        cmd_pid, RTE_UINT16);
16944cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16945        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16946                        cmd_fec, "fec");
16947cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16948        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16949                        cmd_keyword, "capabilities");
16950
16951cmdline_parse_inst_t cmd_show_capability = {
16952        .f = cmd_show_fec_capability_parsed,
16953        .data = NULL,
16954        .help_str = "show port <port_id> fec capabilities",
16955        .tokens = {
16956                (void *)&cmd_show_fec_capability_show,
16957                (void *)&cmd_show_fec_capability_port,
16958                (void *)&cmd_show_fec_capability_pid,
16959                (void *)&cmd_show_fec_capability_fec,
16960                (void *)&cmd_show_fec_capability_keyword,
16961                NULL,
16962        },
16963};
16964
16965/* *** show fec mode per port configuration *** */
16966struct cmd_show_fec_metadata_result {
16967        cmdline_fixed_string_t cmd_show;
16968        cmdline_fixed_string_t cmd_port;
16969        cmdline_fixed_string_t cmd_keyword;
16970        portid_t cmd_pid;
16971};
16972
16973static void
16974cmd_show_fec_mode_parsed(void *parsed_result,
16975                __rte_unused struct cmdline *cl,
16976                __rte_unused void *data)
16977{
16978#define FEC_NAME_SIZE 16
16979        struct cmd_show_fec_metadata_result *res = parsed_result;
16980        uint32_t mode;
16981        char buf[FEC_NAME_SIZE];
16982        int ret;
16983
16984        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16985                fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16986                return;
16987        }
16988        ret = rte_eth_fec_get(res->cmd_pid, &mode);
16989        if (ret == -ENOTSUP) {
16990                fprintf(stderr, "Function not implemented\n");
16991                return;
16992        } else if (ret < 0) {
16993                fprintf(stderr, "Get FEC mode failed\n");
16994                return;
16995        }
16996
16997        switch (mode) {
16998        case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16999                strlcpy(buf, "off", sizeof(buf));
17000                break;
17001        case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17002                strlcpy(buf, "auto", sizeof(buf));
17003                break;
17004        case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17005                strlcpy(buf, "baser", sizeof(buf));
17006                break;
17007        case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17008                strlcpy(buf, "rs", sizeof(buf));
17009                break;
17010        default:
17011                return;
17012        }
17013
17014        printf("%s\n", buf);
17015}
17016
17017cmdline_parse_token_string_t cmd_show_fec_mode_show =
17018        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17019                        cmd_show, "show");
17020cmdline_parse_token_string_t cmd_show_fec_mode_port =
17021        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17022                        cmd_port, "port");
17023cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17024        TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17025                        cmd_pid, RTE_UINT16);
17026cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17027        TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17028                        cmd_keyword, "fec_mode");
17029
17030cmdline_parse_inst_t cmd_show_fec_mode = {
17031        .f = cmd_show_fec_mode_parsed,
17032        .data = NULL,
17033        .help_str = "show port <port_id> fec_mode",
17034        .tokens = {
17035                (void *)&cmd_show_fec_mode_show,
17036                (void *)&cmd_show_fec_mode_port,
17037                (void *)&cmd_show_fec_mode_pid,
17038                (void *)&cmd_show_fec_mode_keyword,
17039                NULL,
17040        },
17041};
17042
17043/* *** set fec mode per port configuration *** */
17044struct cmd_set_port_fec_mode {
17045        cmdline_fixed_string_t set;
17046        cmdline_fixed_string_t port;
17047        portid_t port_id;
17048        cmdline_fixed_string_t fec_mode;
17049        cmdline_fixed_string_t fec_value;
17050};
17051
17052/* Common CLI fields for set fec mode */
17053cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17054        TOKEN_STRING_INITIALIZER
17055                (struct cmd_set_port_fec_mode,
17056                 set, "set");
17057cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17058        TOKEN_STRING_INITIALIZER
17059                (struct cmd_set_port_fec_mode,
17060                 port, "port");
17061cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17062        TOKEN_NUM_INITIALIZER
17063                (struct cmd_set_port_fec_mode,
17064                 port_id, RTE_UINT16);
17065cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17066        TOKEN_STRING_INITIALIZER
17067                (struct cmd_set_port_fec_mode,
17068                 fec_mode, "fec_mode");
17069cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17070        TOKEN_STRING_INITIALIZER
17071                (struct cmd_set_port_fec_mode,
17072                 fec_value, NULL);
17073
17074static void
17075cmd_set_port_fec_mode_parsed(
17076        void *parsed_result,
17077        __rte_unused struct cmdline *cl,
17078        __rte_unused void *data)
17079{
17080        struct cmd_set_port_fec_mode *res = parsed_result;
17081        uint16_t port_id = res->port_id;
17082        uint32_t fec_capa;
17083        int ret;
17084
17085        ret = parse_fec_mode(res->fec_value, &fec_capa);
17086        if (ret < 0) {
17087                fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17088                                res->fec_value, port_id);
17089                return;
17090        }
17091
17092        ret = rte_eth_fec_set(port_id, fec_capa);
17093        if (ret == -ENOTSUP) {
17094                fprintf(stderr, "Function not implemented\n");
17095                return;
17096        } else if (ret < 0) {
17097                fprintf(stderr, "Set FEC mode failed\n");
17098                return;
17099        }
17100}
17101
17102cmdline_parse_inst_t cmd_set_fec_mode = {
17103        .f = cmd_set_port_fec_mode_parsed,
17104        .data = NULL,
17105        .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17106        .tokens = {
17107                (void *)&cmd_set_port_fec_mode_set,
17108                (void *)&cmd_set_port_fec_mode_port,
17109                (void *)&cmd_set_port_fec_mode_port_id,
17110                (void *)&cmd_set_port_fec_mode_str,
17111                (void *)&cmd_set_port_fec_mode_value,
17112                NULL,
17113        },
17114};
17115
17116/* show port supported ptypes */
17117
17118/* Common result structure for show port ptypes */
17119struct cmd_show_port_supported_ptypes_result {
17120        cmdline_fixed_string_t show;
17121        cmdline_fixed_string_t port;
17122        portid_t port_id;
17123        cmdline_fixed_string_t ptypes;
17124};
17125
17126/* Common CLI fields for show port ptypes */
17127cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17128        TOKEN_STRING_INITIALIZER
17129                (struct cmd_show_port_supported_ptypes_result,
17130                 show, "show");
17131cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17132        TOKEN_STRING_INITIALIZER
17133                (struct cmd_show_port_supported_ptypes_result,
17134                 port, "port");
17135cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17136        TOKEN_NUM_INITIALIZER
17137                (struct cmd_show_port_supported_ptypes_result,
17138                 port_id, RTE_UINT16);
17139cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17140        TOKEN_STRING_INITIALIZER
17141                (struct cmd_show_port_supported_ptypes_result,
17142                 ptypes, "ptypes");
17143
17144static void
17145cmd_show_port_supported_ptypes_parsed(
17146        void *parsed_result,
17147        __rte_unused struct cmdline *cl,
17148        __rte_unused void *data)
17149{
17150#define RSVD_PTYPE_MASK       0xf0000000
17151#define MAX_PTYPES_PER_LAYER  16
17152#define LTYPE_NAMESIZE        32
17153#define PTYPE_NAMESIZE        256
17154        struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17155        char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17156        uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17157        uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17158        uint16_t port_id = res->port_id;
17159        int ret, i;
17160
17161        ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17162        if (ret < 0)
17163                return;
17164
17165        while (ptype_mask != RSVD_PTYPE_MASK) {
17166
17167                switch (ptype_mask) {
17168                case RTE_PTYPE_L2_MASK:
17169                        strlcpy(ltype, "L2", sizeof(ltype));
17170                        break;
17171                case RTE_PTYPE_L3_MASK:
17172                        strlcpy(ltype, "L3", sizeof(ltype));
17173                        break;
17174                case RTE_PTYPE_L4_MASK:
17175                        strlcpy(ltype, "L4", sizeof(ltype));
17176                        break;
17177                case RTE_PTYPE_TUNNEL_MASK:
17178                        strlcpy(ltype, "Tunnel", sizeof(ltype));
17179                        break;
17180                case RTE_PTYPE_INNER_L2_MASK:
17181                        strlcpy(ltype, "Inner L2", sizeof(ltype));
17182                        break;
17183                case RTE_PTYPE_INNER_L3_MASK:
17184                        strlcpy(ltype, "Inner L3", sizeof(ltype));
17185                        break;
17186                case RTE_PTYPE_INNER_L4_MASK:
17187                        strlcpy(ltype, "Inner L4", sizeof(ltype));
17188                        break;
17189                default:
17190                        return;
17191                }
17192
17193                ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17194                                                       ptype_mask, ptypes,
17195                                                       MAX_PTYPES_PER_LAYER);
17196
17197                if (ret > 0)
17198                        printf("Supported %s ptypes:\n", ltype);
17199                else
17200                        printf("%s ptypes unsupported\n", ltype);
17201
17202                for (i = 0; i < ret; ++i) {
17203                        rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17204                        printf("%s\n", buf);
17205                }
17206
17207                ptype_mask <<= 4;
17208        }
17209}
17210
17211cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17212        .f = cmd_show_port_supported_ptypes_parsed,
17213        .data = NULL,
17214        .help_str = "show port <port_id> ptypes",
17215        .tokens = {
17216                (void *)&cmd_show_port_supported_ptypes_show,
17217                (void *)&cmd_show_port_supported_ptypes_port,
17218                (void *)&cmd_show_port_supported_ptypes_port_id,
17219                (void *)&cmd_show_port_supported_ptypes_ptypes,
17220                NULL,
17221        },
17222};
17223
17224/* *** display rx/tx descriptor status *** */
17225struct cmd_show_rx_tx_desc_status_result {
17226        cmdline_fixed_string_t cmd_show;
17227        cmdline_fixed_string_t cmd_port;
17228        cmdline_fixed_string_t cmd_keyword;
17229        cmdline_fixed_string_t cmd_desc;
17230        cmdline_fixed_string_t cmd_status;
17231        portid_t cmd_pid;
17232        portid_t cmd_qid;
17233        portid_t cmd_did;
17234};
17235
17236static void
17237cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17238                __rte_unused struct cmdline *cl,
17239                __rte_unused void *data)
17240{
17241        struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17242        int rc;
17243
17244        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17245                fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17246                return;
17247        }
17248
17249        if (!strcmp(res->cmd_keyword, "rxq")) {
17250                rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17251                                             res->cmd_did);
17252                if (rc < 0) {
17253                        fprintf(stderr,
17254                                "Invalid input: queue id = %d, desc id = %d\n",
17255                                res->cmd_qid, res->cmd_did);
17256                        return;
17257                }
17258                if (rc == RTE_ETH_RX_DESC_AVAIL)
17259                        printf("Desc status = AVAILABLE\n");
17260                else if (rc == RTE_ETH_RX_DESC_DONE)
17261                        printf("Desc status = DONE\n");
17262                else
17263                        printf("Desc status = UNAVAILABLE\n");
17264        } else if (!strcmp(res->cmd_keyword, "txq")) {
17265                rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17266                                             res->cmd_did);
17267                if (rc < 0) {
17268                        fprintf(stderr,
17269                                "Invalid input: queue id = %d, desc id = %d\n",
17270                                res->cmd_qid, res->cmd_did);
17271                        return;
17272                }
17273                if (rc == RTE_ETH_TX_DESC_FULL)
17274                        printf("Desc status = FULL\n");
17275                else if (rc == RTE_ETH_TX_DESC_DONE)
17276                        printf("Desc status = DONE\n");
17277                else
17278                        printf("Desc status = UNAVAILABLE\n");
17279        }
17280}
17281
17282cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17283        TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17284                        cmd_show, "show");
17285cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17286        TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17287                        cmd_port, "port");
17288cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17289        TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17290                        cmd_pid, RTE_UINT16);
17291cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17292        TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17293                        cmd_keyword, "rxq#txq");
17294cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17295        TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17296                        cmd_qid, RTE_UINT16);
17297cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17298        TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17299                        cmd_desc, "desc");
17300cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17301        TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17302                        cmd_did, RTE_UINT16);
17303cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17304        TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17305                        cmd_status, "status");
17306cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17307        .f = cmd_show_rx_tx_desc_status_parsed,
17308        .data = NULL,
17309        .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17310                "status",
17311        .tokens = {
17312                (void *)&cmd_show_rx_tx_desc_status_show,
17313                (void *)&cmd_show_rx_tx_desc_status_port,
17314                (void *)&cmd_show_rx_tx_desc_status_pid,
17315                (void *)&cmd_show_rx_tx_desc_status_keyword,
17316                (void *)&cmd_show_rx_tx_desc_status_qid,
17317                (void *)&cmd_show_rx_tx_desc_status_desc,
17318                (void *)&cmd_show_rx_tx_desc_status_did,
17319                (void *)&cmd_show_rx_tx_desc_status_status,
17320                NULL,
17321        },
17322};
17323
17324/* *** display rx queue desc used count *** */
17325struct cmd_show_rx_queue_desc_used_count_result {
17326        cmdline_fixed_string_t cmd_show;
17327        cmdline_fixed_string_t cmd_port;
17328        cmdline_fixed_string_t cmd_rxq;
17329        cmdline_fixed_string_t cmd_desc;
17330        cmdline_fixed_string_t cmd_used;
17331        cmdline_fixed_string_t cmd_count;
17332        portid_t cmd_pid;
17333        portid_t cmd_qid;
17334};
17335
17336static void
17337cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17338                __rte_unused struct cmdline *cl,
17339                __rte_unused void *data)
17340{
17341        struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17342        int rc;
17343
17344        if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17345                fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17346                return;
17347        }
17348
17349        rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17350        if (rc < 0) {
17351                fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17352                return;
17353        }
17354        printf("Used desc count = %d\n", rc);
17355}
17356
17357cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17358        TOKEN_STRING_INITIALIZER
17359                (struct cmd_show_rx_queue_desc_used_count_result,
17360                 cmd_show, "show");
17361cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17362        TOKEN_STRING_INITIALIZER
17363                (struct cmd_show_rx_queue_desc_used_count_result,
17364                 cmd_port, "port");
17365cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17366        TOKEN_NUM_INITIALIZER
17367                (struct cmd_show_rx_queue_desc_used_count_result,
17368                 cmd_pid, RTE_UINT16);
17369cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17370        TOKEN_STRING_INITIALIZER
17371                (struct cmd_show_rx_queue_desc_used_count_result,
17372                 cmd_rxq, "rxq");
17373cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17374        TOKEN_NUM_INITIALIZER
17375                (struct cmd_show_rx_queue_desc_used_count_result,
17376                 cmd_qid, RTE_UINT16);
17377cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17378        TOKEN_STRING_INITIALIZER
17379                (struct cmd_show_rx_queue_desc_used_count_result,
17380                 cmd_count, "desc");
17381cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17382        TOKEN_STRING_INITIALIZER
17383                (struct cmd_show_rx_queue_desc_used_count_result,
17384                 cmd_count, "used");
17385cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17386        TOKEN_STRING_INITIALIZER
17387                (struct cmd_show_rx_queue_desc_used_count_result,
17388                 cmd_count, "count");
17389cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17390        .f = cmd_show_rx_queue_desc_used_count_parsed,
17391        .data = NULL,
17392        .help_str = "show port <port_id> rxq <queue_id> desc used count",
17393        .tokens = {
17394                (void *)&cmd_show_rx_queue_desc_used_count_show,
17395                (void *)&cmd_show_rx_queue_desc_used_count_port,
17396                (void *)&cmd_show_rx_queue_desc_used_count_pid,
17397                (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17398                (void *)&cmd_show_rx_queue_desc_used_count_qid,
17399                (void *)&cmd_show_rx_queue_desc_used_count_desc,
17400                (void *)&cmd_show_rx_queue_desc_used_count_used,
17401                (void *)&cmd_show_rx_queue_desc_used_count_count,
17402                NULL,
17403        },
17404};
17405
17406/* Common result structure for set port ptypes */
17407struct cmd_set_port_ptypes_result {
17408        cmdline_fixed_string_t set;
17409        cmdline_fixed_string_t port;
17410        portid_t port_id;
17411        cmdline_fixed_string_t ptype_mask;
17412        uint32_t mask;
17413};
17414
17415/* Common CLI fields for set port ptypes */
17416cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17417        TOKEN_STRING_INITIALIZER
17418                (struct cmd_set_port_ptypes_result,
17419                 set, "set");
17420cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17421        TOKEN_STRING_INITIALIZER
17422                (struct cmd_set_port_ptypes_result,
17423                 port, "port");
17424cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17425        TOKEN_NUM_INITIALIZER
17426                (struct cmd_set_port_ptypes_result,
17427                 port_id, RTE_UINT16);
17428cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17429        TOKEN_STRING_INITIALIZER
17430                (struct cmd_set_port_ptypes_result,
17431                 ptype_mask, "ptype_mask");
17432cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17433        TOKEN_NUM_INITIALIZER
17434                (struct cmd_set_port_ptypes_result,
17435                 mask, RTE_UINT32);
17436
17437static void
17438cmd_set_port_ptypes_parsed(
17439        void *parsed_result,
17440        __rte_unused struct cmdline *cl,
17441        __rte_unused void *data)
17442{
17443        struct cmd_set_port_ptypes_result *res = parsed_result;
17444#define PTYPE_NAMESIZE        256
17445        char ptype_name[PTYPE_NAMESIZE];
17446        uint16_t port_id = res->port_id;
17447        uint32_t ptype_mask = res->mask;
17448        int ret, i;
17449
17450        ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17451                                               NULL, 0);
17452        if (ret <= 0) {
17453                fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17454                        port_id);
17455                return;
17456        }
17457
17458        uint32_t ptypes[ret];
17459
17460        ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17461        if (ret < 0) {
17462                fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17463                        port_id);
17464                return;
17465        }
17466
17467        printf("Successfully set following ptypes for Port %d\n", port_id);
17468        for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17469                rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17470                printf("%s\n", ptype_name);
17471        }
17472
17473        clear_ptypes = false;
17474}
17475
17476cmdline_parse_inst_t cmd_set_port_ptypes = {
17477        .f = cmd_set_port_ptypes_parsed,
17478        .data = NULL,
17479        .help_str = "set port <port_id> ptype_mask <mask>",
17480        .tokens = {
17481                (void *)&cmd_set_port_ptypes_set,
17482                (void *)&cmd_set_port_ptypes_port,
17483                (void *)&cmd_set_port_ptypes_port_id,
17484                (void *)&cmd_set_port_ptypes_mask_str,
17485                (void *)&cmd_set_port_ptypes_mask_u32,
17486                NULL,
17487        },
17488};
17489
17490/* *** display mac addresses added to a port *** */
17491struct cmd_showport_macs_result {
17492        cmdline_fixed_string_t cmd_show;
17493        cmdline_fixed_string_t cmd_port;
17494        cmdline_fixed_string_t cmd_keyword;
17495        portid_t cmd_pid;
17496};
17497
17498static void
17499cmd_showport_macs_parsed(void *parsed_result,
17500                __rte_unused struct cmdline *cl,
17501                __rte_unused void *data)
17502{
17503        struct cmd_showport_macs_result *res = parsed_result;
17504
17505        if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17506                return;
17507
17508        if (!strcmp(res->cmd_keyword, "macs"))
17509                show_macs(res->cmd_pid);
17510        else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17511                show_mcast_macs(res->cmd_pid);
17512}
17513
17514cmdline_parse_token_string_t cmd_showport_macs_show =
17515        TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17516                        cmd_show, "show");
17517cmdline_parse_token_string_t cmd_showport_macs_port =
17518        TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17519                        cmd_port, "port");
17520cmdline_parse_token_num_t cmd_showport_macs_pid =
17521        TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17522                        cmd_pid, RTE_UINT16);
17523cmdline_parse_token_string_t cmd_showport_macs_keyword =
17524        TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17525                        cmd_keyword, "macs#mcast_macs");
17526
17527cmdline_parse_inst_t cmd_showport_macs = {
17528        .f = cmd_showport_macs_parsed,
17529        .data = NULL,
17530        .help_str = "show port <port_id> macs|mcast_macs",
17531        .tokens = {
17532                (void *)&cmd_showport_macs_show,
17533                (void *)&cmd_showport_macs_port,
17534                (void *)&cmd_showport_macs_pid,
17535                (void *)&cmd_showport_macs_keyword,
17536                NULL,
17537        },
17538};
17539
17540/* ******************************************************************************** */
17541
17542/* list of instructions */
17543cmdline_parse_ctx_t main_ctx[] = {
17544        (cmdline_parse_inst_t *)&cmd_help_brief,
17545        (cmdline_parse_inst_t *)&cmd_help_long,
17546        (cmdline_parse_inst_t *)&cmd_quit,
17547        (cmdline_parse_inst_t *)&cmd_load_from_file,
17548        (cmdline_parse_inst_t *)&cmd_showport,
17549        (cmdline_parse_inst_t *)&cmd_showqueue,
17550        (cmdline_parse_inst_t *)&cmd_showeeprom,
17551        (cmdline_parse_inst_t *)&cmd_showportall,
17552        (cmdline_parse_inst_t *)&cmd_showdevice,
17553        (cmdline_parse_inst_t *)&cmd_showcfg,
17554        (cmdline_parse_inst_t *)&cmd_showfwdall,
17555        (cmdline_parse_inst_t *)&cmd_start,
17556        (cmdline_parse_inst_t *)&cmd_start_tx_first,
17557        (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17558        (cmdline_parse_inst_t *)&cmd_set_link_up,
17559        (cmdline_parse_inst_t *)&cmd_set_link_down,
17560        (cmdline_parse_inst_t *)&cmd_reset,
17561        (cmdline_parse_inst_t *)&cmd_set_numbers,
17562        (cmdline_parse_inst_t *)&cmd_set_log,
17563        (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17564        (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17565        (cmdline_parse_inst_t *)&cmd_set_txpkts,
17566        (cmdline_parse_inst_t *)&cmd_set_txsplit,
17567        (cmdline_parse_inst_t *)&cmd_set_txtimes,
17568        (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17569        (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17570        (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17571        (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17572        (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17573        (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17574        (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17575        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17576        (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17577        (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17578        (cmdline_parse_inst_t *)&cmd_set_link_check,
17579        (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17580        (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17581        (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17582        (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17583#ifdef RTE_NET_BOND
17584        (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17585        (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17586        (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17587        (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17588        (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17589        (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17590        (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17591        (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17592        (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17593        (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17594        (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17595#endif
17596        (cmdline_parse_inst_t *)&cmd_vlan_offload,
17597        (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17598        (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17599        (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17600        (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17601        (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17602        (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17603        (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17604        (cmdline_parse_inst_t *)&cmd_csum_set,
17605        (cmdline_parse_inst_t *)&cmd_csum_show,
17606        (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17607        (cmdline_parse_inst_t *)&cmd_tso_set,
17608        (cmdline_parse_inst_t *)&cmd_tso_show,
17609        (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17610        (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17611        (cmdline_parse_inst_t *)&cmd_gro_enable,
17612        (cmdline_parse_inst_t *)&cmd_gro_flush,
17613        (cmdline_parse_inst_t *)&cmd_gro_show,
17614        (cmdline_parse_inst_t *)&cmd_gso_enable,
17615        (cmdline_parse_inst_t *)&cmd_gso_size,
17616        (cmdline_parse_inst_t *)&cmd_gso_show,
17617        (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17618        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17619        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17620        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17621        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17622        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17623        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17624        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17625        (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17626        (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17627        (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17628        (cmdline_parse_inst_t *)&cmd_config_dcb,
17629        (cmdline_parse_inst_t *)&cmd_read_reg,
17630        (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17631        (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17632        (cmdline_parse_inst_t *)&cmd_write_reg,
17633        (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17634        (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17635        (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17636        (cmdline_parse_inst_t *)&cmd_stop,
17637        (cmdline_parse_inst_t *)&cmd_mac_addr,
17638        (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17639        (cmdline_parse_inst_t *)&cmd_set_qmap,
17640        (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17641        (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17642        (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17643        (cmdline_parse_inst_t *)&cmd_operate_port,
17644        (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17645        (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17646        (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17647        (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17648        (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17649        (cmdline_parse_inst_t *)&cmd_config_speed_all,
17650        (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17651        (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17652        (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17653        (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17654        (cmdline_parse_inst_t *)&cmd_config_mtu,
17655        (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17656        (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17657        (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17658        (cmdline_parse_inst_t *)&cmd_config_rss,
17659        (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17660        (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17661        (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17662        (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17663        (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17664        (cmdline_parse_inst_t *)&cmd_showport_reta,
17665        (cmdline_parse_inst_t *)&cmd_showport_macs,
17666        (cmdline_parse_inst_t *)&cmd_config_burst,
17667        (cmdline_parse_inst_t *)&cmd_config_thresh,
17668        (cmdline_parse_inst_t *)&cmd_config_threshold,
17669        (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17670        (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17671        (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17672        (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17673        (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17674        (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17675        (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17676        (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17677        (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17678        (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17679        (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17680        (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17681        (cmdline_parse_inst_t *)&cmd_dump,
17682        (cmdline_parse_inst_t *)&cmd_dump_one,
17683#ifdef RTE_NET_I40E
17684        (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17685#endif
17686        (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17687        (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17688        (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17689        (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17690        (cmdline_parse_inst_t *)&cmd_flow,
17691        (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17692        (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17693        (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17694        (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17695        (cmdline_parse_inst_t *)&cmd_create_port_meter,
17696        (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17697        (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17698        (cmdline_parse_inst_t *)&cmd_del_port_meter,
17699        (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17700        (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17701        (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17702        (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17703        (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17704        (cmdline_parse_inst_t *)&cmd_mcast_addr,
17705        (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17706        (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17707        (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17708        (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17709        (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17710        (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17711        (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17712        (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17713        (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17714        (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17715        (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17716        (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17717        (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17718        (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17719        (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17720        (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17721        (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17722        (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17723        (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17724        (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17725        (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17726        (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17727        (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17728        (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17729        (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17730        (cmdline_parse_inst_t *)&cmd_set_vxlan,
17731        (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17732        (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17733        (cmdline_parse_inst_t *)&cmd_set_nvgre,
17734        (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17735        (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17736        (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17737        (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17738        (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17739        (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17740        (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17741        (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17742        (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17743        (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17744        (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17745        (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17746        (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17747        (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17748        (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17749        (cmdline_parse_inst_t *)&cmd_ddp_add,
17750        (cmdline_parse_inst_t *)&cmd_ddp_del,
17751        (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17752        (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17753        (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17754        (cmdline_parse_inst_t *)&cmd_clear_input_set,
17755        (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17756        (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17757        (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17758        (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17759        (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17760        (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17761        (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17762        (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17763
17764        (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17765        (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17766        (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17767        (cmdline_parse_inst_t *)&cmd_queue_region,
17768        (cmdline_parse_inst_t *)&cmd_region_flowtype,
17769        (cmdline_parse_inst_t *)&cmd_user_priority_region,
17770        (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17771        (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17772        (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17773        (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17774        (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17775        (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17776        (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17777        (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17778        (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17779        (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17780        (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17781        (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17782        (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17783        (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17784        (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17785        (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17786        (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17787        (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17788        (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17789        (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17790        (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17791        (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17792        (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17793        (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17794        (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17795        (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17796        (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17797        (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17798        (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17799        (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17800        (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17801        (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17802        (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17803        (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17804#ifdef RTE_LIB_BPF
17805        (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17806        (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17807#endif
17808        (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17809        (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17810        (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17811        (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17812        (cmdline_parse_inst_t *)&cmd_set_raw,
17813        (cmdline_parse_inst_t *)&cmd_show_set_raw,
17814        (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17815        (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17816        (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17817        (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17818        (cmdline_parse_inst_t *)&cmd_show_capability,
17819        NULL,
17820};
17821
17822/* read cmdline commands from file */
17823void
17824cmdline_read_from_file(const char *filename)
17825{
17826        struct cmdline *cl;
17827
17828        cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17829        if (cl == NULL) {
17830                fprintf(stderr,
17831                        "Failed to create file based cmdline context: %s\n",
17832                        filename);
17833                return;
17834        }
17835
17836        cmdline_interact(cl);
17837        cmdline_quit(cl);
17838
17839        cmdline_free(cl);
17840
17841        printf("Read CLI commands from %s\n", filename);
17842}
17843
17844/* prompt function, called from main on MAIN lcore */
17845void
17846prompt(void)
17847{
17848        int ret;
17849        /* initialize non-constant commands */
17850        cmd_set_fwd_mode_init();
17851        cmd_set_fwd_retry_mode_init();
17852
17853        testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17854        if (testpmd_cl == NULL)
17855                return;
17856
17857        ret = atexit(prompt_exit);
17858        if (ret != 0)
17859                fprintf(stderr, "Cannot set exit function for cmdline\n");
17860
17861        cmdline_interact(testpmd_cl);
17862        if (ret != 0)
17863                cmdline_stdin_exit(testpmd_cl);
17864}
17865
17866void
17867prompt_exit(void)
17868{
17869        if (testpmd_cl != NULL) {
17870                cmdline_quit(testpmd_cl);
17871                cmdline_stdin_exit(testpmd_cl);
17872        }
17873}
17874
17875static void
17876cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17877{
17878        if (id == (portid_t)RTE_PORT_ALL) {
17879                portid_t pid;
17880
17881                RTE_ETH_FOREACH_DEV(pid) {
17882                        /* check if need_reconfig has been set to 1 */
17883                        if (ports[pid].need_reconfig == 0)
17884                                ports[pid].need_reconfig = dev;
17885                        /* check if need_reconfig_queues has been set to 1 */
17886                        if (ports[pid].need_reconfig_queues == 0)
17887                                ports[pid].need_reconfig_queues = queue;
17888                }
17889        } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17890                /* check if need_reconfig has been set to 1 */
17891                if (ports[id].need_reconfig == 0)
17892                        ports[id].need_reconfig = dev;
17893                /* check if need_reconfig_queues has been set to 1 */
17894                if (ports[id].need_reconfig_queues == 0)
17895                        ports[id].need_reconfig_queues = queue;
17896        }
17897}
17898