1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. 5 * Copyright(c) 2014 6WIND S.A. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include <stdarg.h> 36 #include <errno.h> 37 #include <stdio.h> 38 #include <stdint.h> 39 #include <string.h> 40 #include <termios.h> 41 #include <unistd.h> 42 #include <inttypes.h> 43 #ifndef __linux__ 44 #ifndef __FreeBSD__ 45 #include <net/socket.h> 46 #else 47 #include <sys/socket.h> 48 #endif 49 #endif 50 #include <netinet/in.h> 51 52 #include <sys/queue.h> 53 54 #include <rte_common.h> 55 #include <rte_byteorder.h> 56 #include <rte_log.h> 57 #include <rte_debug.h> 58 #include <rte_cycles.h> 59 #include <rte_memory.h> 60 #include <rte_memzone.h> 61 #include <rte_malloc.h> 62 #include <rte_launch.h> 63 #include <rte_eal.h> 64 #include <rte_per_lcore.h> 65 #include <rte_lcore.h> 66 #include <rte_atomic.h> 67 #include <rte_branch_prediction.h> 68 #include <rte_ring.h> 69 #include <rte_mempool.h> 70 #include <rte_interrupts.h> 71 #include <rte_pci.h> 72 #include <rte_ether.h> 73 #include <rte_ethdev.h> 74 #include <rte_string_fns.h> 75 #include <rte_devargs.h> 76 #include <rte_eth_ctrl.h> 77 #include <rte_flow.h> 78 #include <rte_gro.h> 79 80 #include <cmdline_rdline.h> 81 #include <cmdline_parse.h> 82 #include <cmdline_parse_num.h> 83 #include <cmdline_parse_string.h> 84 #include <cmdline_parse_ipaddr.h> 85 #include <cmdline_parse_etheraddr.h> 86 #include <cmdline_socket.h> 87 #include <cmdline.h> 88 #ifdef RTE_LIBRTE_PMD_BOND 89 #include <rte_eth_bond.h> 90 #include <rte_eth_bond_8023ad.h> 91 #endif 92 #ifdef RTE_LIBRTE_IXGBE_PMD 93 #include <rte_pmd_ixgbe.h> 94 #endif 95 #ifdef RTE_LIBRTE_I40E_PMD 96 #include <rte_pmd_i40e.h> 97 #endif 98 #ifdef RTE_LIBRTE_BNXT_PMD 99 #include <rte_pmd_bnxt.h> 100 #endif 101 #include "testpmd.h" 102 103 static struct cmdline *testpmd_cl; 104 105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 106 107 /* *** Help command with introduction. *** */ 108 struct cmd_help_brief_result { 109 cmdline_fixed_string_t help; 110 }; 111 112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 113 struct cmdline *cl, 114 __attribute__((unused)) void *data) 115 { 116 cmdline_printf( 117 cl, 118 "\n" 119 "Help is available for the following sections:\n\n" 120 " help control : Start and stop forwarding.\n" 121 " help display : Displaying port, stats and config " 122 "information.\n" 123 " help config : Configuration information.\n" 124 " help ports : Configuring ports.\n" 125 " help registers : Reading and setting port registers.\n" 126 " help filters : Filters configuration help.\n" 127 " help all : All of the above sections.\n\n" 128 ); 129 130 } 131 132 cmdline_parse_token_string_t cmd_help_brief_help = 133 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 134 135 cmdline_parse_inst_t cmd_help_brief = { 136 .f = cmd_help_brief_parsed, 137 .data = NULL, 138 .help_str = "help: Show help", 139 .tokens = { 140 (void *)&cmd_help_brief_help, 141 NULL, 142 }, 143 }; 144 145 /* *** Help command with help sections. *** */ 146 struct cmd_help_long_result { 147 cmdline_fixed_string_t help; 148 cmdline_fixed_string_t section; 149 }; 150 151 static void cmd_help_long_parsed(void *parsed_result, 152 struct cmdline *cl, 153 __attribute__((unused)) void *data) 154 { 155 int show_all = 0; 156 struct cmd_help_long_result *res = parsed_result; 157 158 if (!strcmp(res->section, "all")) 159 show_all = 1; 160 161 if (show_all || !strcmp(res->section, "control")) { 162 163 cmdline_printf( 164 cl, 165 "\n" 166 "Control forwarding:\n" 167 "-------------------\n\n" 168 169 "start\n" 170 " Start packet forwarding with current configuration.\n\n" 171 172 "start tx_first\n" 173 " Start packet forwarding with current config" 174 " after sending one burst of packets.\n\n" 175 176 "stop\n" 177 " Stop packet forwarding, and display accumulated" 178 " statistics.\n\n" 179 180 "quit\n" 181 " Quit to prompt.\n\n" 182 ); 183 } 184 185 if (show_all || !strcmp(res->section, "display")) { 186 187 cmdline_printf( 188 cl, 189 "\n" 190 "Display:\n" 191 "--------\n\n" 192 193 "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n" 194 " Display information for port_id, or all.\n\n" 195 196 "show port X rss reta (size) (mask0,mask1,...)\n" 197 " Display the rss redirection table entry indicated" 198 " by masks on port X. size is used to indicate the" 199 " hardware supported reta size\n\n" 200 201 "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|" 202 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 203 "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n" 204 " Display the RSS hash functions and RSS hash key" 205 " of port X\n\n" 206 207 "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n" 208 " Clear information for port_id, or all.\n\n" 209 210 "show (rxq|txq) info (port_id) (queue_id)\n" 211 " Display information for configured RX/TX queue.\n\n" 212 213 "show config (rxtx|cores|fwd|txpkts)\n" 214 " Display the given configuration.\n\n" 215 216 "read rxd (port_id) (queue_id) (rxd_id)\n" 217 " Display an RX descriptor of a port RX queue.\n\n" 218 219 "read txd (port_id) (queue_id) (txd_id)\n" 220 " Display a TX descriptor of a port TX queue.\n\n" 221 222 "ddp get list (port_id)\n" 223 " Get ddp profile info list\n\n" 224 225 "ddp get info (profile_path)\n" 226 " Get ddp profile information.\n\n" 227 228 "show vf stats (port_id) (vf_id)\n" 229 " Display a VF's statistics.\n\n" 230 231 "clear vf stats (port_id) (vf_id)\n" 232 " Reset a VF's statistics.\n\n" 233 ); 234 } 235 236 if (show_all || !strcmp(res->section, "config")) { 237 cmdline_printf( 238 cl, 239 "\n" 240 "Configuration:\n" 241 "--------------\n" 242 "Configuration changes only become active when" 243 " forwarding is started/restarted.\n\n" 244 245 "set default\n" 246 " Reset forwarding to the default configuration.\n\n" 247 248 "set verbose (level)\n" 249 " Set the debug verbosity level X.\n\n" 250 251 "set nbport (num)\n" 252 " Set number of ports.\n\n" 253 254 "set nbcore (num)\n" 255 " Set number of cores.\n\n" 256 257 "set coremask (mask)\n" 258 " Set the forwarding cores hexadecimal mask.\n\n" 259 260 "set portmask (mask)\n" 261 " Set the forwarding ports hexadecimal mask.\n\n" 262 263 "set burst (num)\n" 264 " Set number of packets per burst.\n\n" 265 266 "set burst tx delay (microseconds) retry (num)\n" 267 " Set the transmit delay time and number of retries," 268 " effective when retry is enabled.\n\n" 269 270 "set txpkts (x[,y]*)\n" 271 " Set the length of each segment of TXONLY" 272 " and optionally CSUM packets.\n\n" 273 274 "set txsplit (off|on|rand)\n" 275 " Set the split policy for the TX packets." 276 " Right now only applicable for CSUM and TXONLY" 277 " modes\n\n" 278 279 "set corelist (x[,y]*)\n" 280 " Set the list of forwarding cores.\n\n" 281 282 "set portlist (x[,y]*)\n" 283 " Set the list of forwarding ports.\n\n" 284 285 "set tx loopback (port_id) (on|off)\n" 286 " Enable or disable tx loopback.\n\n" 287 288 "set all queues drop (port_id) (on|off)\n" 289 " Set drop enable bit for all queues.\n\n" 290 291 "set vf split drop (port_id) (vf_id) (on|off)\n" 292 " Set split drop enable bit for a VF from the PF.\n\n" 293 294 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 295 " Set MAC antispoof for a VF from the PF.\n\n" 296 297 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 298 " Enable MACsec offload.\n\n" 299 300 "set macsec offload (port_id) off\n" 301 " Disable MACsec offload.\n\n" 302 303 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 304 " Configure MACsec secure connection (SC).\n\n" 305 306 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 307 " Configure MACsec secure association (SA).\n\n" 308 309 "set vf broadcast (port_id) (vf_id) (on|off)\n" 310 " Set VF broadcast for a VF from the PF.\n\n" 311 312 "vlan set strip (on|off) (port_id)\n" 313 " Set the VLAN strip on a port.\n\n" 314 315 "vlan set stripq (on|off) (port_id,queue_id)\n" 316 " Set the VLAN strip for a queue on a port.\n\n" 317 318 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 319 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 320 321 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 322 " Set VLAN insert for a VF from the PF.\n\n" 323 324 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 325 " Set VLAN antispoof for a VF from the PF.\n\n" 326 327 "set vf vlan tag (port_id) (vf_id) (on|off)\n" 328 " Set VLAN tag for a VF from the PF.\n\n" 329 330 "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n" 331 " Set a VF's max bandwidth(Mbps).\n\n" 332 333 "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n" 334 " Set all TCs' min bandwidth(%%) on a VF.\n\n" 335 336 "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n" 337 " Set a TC's max bandwidth(Mbps) on a VF.\n\n" 338 339 "set tx strict-link-priority (port_id) (tc_bitmap)\n" 340 " Set some TCs' strict link priority mode on a physical port.\n\n" 341 342 "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" 343 " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" 344 345 "vlan set filter (on|off) (port_id)\n" 346 " Set the VLAN filter on a port.\n\n" 347 348 "vlan set qinq (on|off) (port_id)\n" 349 " Set the VLAN QinQ (extended queue in queue)" 350 " on a port.\n\n" 351 352 "vlan set (inner|outer) tpid (value) (port_id)\n" 353 " Set the VLAN TPID for Packet Filtering on" 354 " a port\n\n" 355 356 "rx_vlan add (vlan_id|all) (port_id)\n" 357 " Add a vlan_id, or all identifiers, to the set" 358 " of VLAN identifiers filtered by port_id.\n\n" 359 360 "rx_vlan rm (vlan_id|all) (port_id)\n" 361 " Remove a vlan_id, or all identifiers, from the set" 362 " of VLAN identifiers filtered by port_id.\n\n" 363 364 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 365 " Add a vlan_id, to the set of VLAN identifiers" 366 "filtered for VF(s) from port_id.\n\n" 367 368 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 369 " Remove a vlan_id, to the set of VLAN identifiers" 370 "filtered for VF(s) from port_id.\n\n" 371 372 "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) " 373 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 374 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 375 " add a tunnel filter of a port.\n\n" 376 377 "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) " 378 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 379 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 380 " remove a tunnel filter of a port.\n\n" 381 382 "rx_vxlan_port add (udp_port) (port_id)\n" 383 " Add an UDP port for VXLAN packet filter on a port\n\n" 384 385 "rx_vxlan_port rm (udp_port) (port_id)\n" 386 " Remove an UDP port for VXLAN packet filter on a port\n\n" 387 388 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 389 " Set hardware insertion of VLAN IDs (single or double VLAN " 390 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 391 392 "tx_vlan set pvid port_id vlan_id (on|off)\n" 393 " Set port based TX VLAN insertion.\n\n" 394 395 "tx_vlan reset (port_id)\n" 396 " Disable hardware insertion of a VLAN header in" 397 " packets sent on a port.\n\n" 398 399 "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n" 400 " Select hardware or software calculation of the" 401 " checksum when transmitting a packet using the" 402 " csum forward engine.\n" 403 " ip|udp|tcp|sctp always concern the inner layer.\n" 404 " outer-ip concerns the outer IP layer in" 405 " case the packet is recognized as a tunnel packet by" 406 " the forward engine (vxlan, gre and ipip are supported)\n" 407 " Please check the NIC datasheet for HW limits.\n\n" 408 409 "csum parse-tunnel (on|off) (tx_port_id)\n" 410 " If disabled, treat tunnel packets as non-tunneled" 411 " packets (treat inner headers as payload). The port\n" 412 " argument is the port used for TX in csum forward" 413 " engine.\n\n" 414 415 "csum show (port_id)\n" 416 " Display tx checksum offload configuration\n\n" 417 418 "tso set (segsize) (portid)\n" 419 " Enable TCP Segmentation Offload in csum forward" 420 " engine.\n" 421 " Please check the NIC datasheet for HW limits.\n\n" 422 423 "tso show (portid)" 424 " Display the status of TCP Segmentation Offload.\n\n" 425 426 "gro (on|off) (port_id)" 427 " Enable or disable Generic Receive Offload in io" 428 " forward engine.\n\n" 429 430 "gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n" 431 " Set max flow number and max packet number per-flow" 432 " for GRO.\n\n" 433 434 "set fwd (%s)\n" 435 " Set packet forwarding mode.\n\n" 436 437 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 438 " Add a MAC address on port_id.\n\n" 439 440 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 441 " Remove a MAC address from port_id.\n\n" 442 443 "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n" 444 " Set the default MAC address for port_id.\n\n" 445 446 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 447 " Add a MAC address for a VF on the port.\n\n" 448 449 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 450 " Set the MAC address for a VF from the PF.\n\n" 451 452 "set port (port_id) uta (mac_address|all) (on|off)\n" 453 " Add/Remove a or all unicast hash filter(s)" 454 "from port X.\n\n" 455 456 "set promisc (port_id|all) (on|off)\n" 457 " Set the promiscuous mode on port_id, or all.\n\n" 458 459 "set allmulti (port_id|all) (on|off)\n" 460 " Set the allmulti mode on port_id, or all.\n\n" 461 462 "set vf promisc (port_id) (vf_id) (on|off)\n" 463 " Set unicast promiscuous mode for a VF from the PF.\n\n" 464 465 "set vf allmulti (port_id) (vf_id) (on|off)\n" 466 " Set multicast promiscuous mode for a VF from the PF.\n\n" 467 468 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 469 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 470 " (on|off) autoneg (on|off) (port_id)\n" 471 "set flow_ctrl rx (on|off) (portid)\n" 472 "set flow_ctrl tx (on|off) (portid)\n" 473 "set flow_ctrl high_water (high_water) (portid)\n" 474 "set flow_ctrl low_water (low_water) (portid)\n" 475 "set flow_ctrl pause_time (pause_time) (portid)\n" 476 "set flow_ctrl send_xon (send_xon) (portid)\n" 477 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 478 "set flow_ctrl autoneg (on|off) (port_id)\n" 479 " Set the link flow control parameter on a port.\n\n" 480 481 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 482 " (low_water) (pause_time) (priority) (port_id)\n" 483 " Set the priority flow control parameter on a" 484 " port.\n\n" 485 486 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 487 " Set statistics mapping (qmapping 0..15) for RX/TX" 488 " queue on port.\n" 489 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 490 " on port 0 to mapping 5.\n\n" 491 492 "set port (port_id) vf (vf_id) rx|tx on|off\n" 493 " Enable/Disable a VF receive/tranmit from a port\n\n" 494 495 "set port (port_id) vf (vf_id) (mac_addr)" 496 " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n" 497 " Add/Remove unicast or multicast MAC addr filter" 498 " for a VF.\n\n" 499 500 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 501 "|MPE) (on|off)\n" 502 " AUPE:accepts untagged VLAN;" 503 "ROPE:accept unicast hash\n\n" 504 " BAM:accepts broadcast packets;" 505 "MPE:accepts all multicast packets\n\n" 506 " Enable/Disable a VF receive mode of a port\n\n" 507 508 "set port (port_id) queue (queue_id) rate (rate_num)\n" 509 " Set rate limit for a queue of a port\n\n" 510 511 "set port (port_id) vf (vf_id) rate (rate_num) " 512 "queue_mask (queue_mask_value)\n" 513 " Set rate limit for queues in VF of a port\n\n" 514 515 "set port (port_id) mirror-rule (rule_id)" 516 " (pool-mirror-up|pool-mirror-down|vlan-mirror)" 517 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 518 " Set pool or vlan type mirror rule on a port.\n" 519 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 520 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 521 " to pool 0.\n\n" 522 523 "set port (port_id) mirror-rule (rule_id)" 524 " (uplink-mirror|downlink-mirror) dst-pool" 525 " (pool_id) (on|off)\n" 526 " Set uplink or downlink type mirror rule on a port.\n" 527 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 528 " 0 on' enable mirror income traffic to pool 0.\n\n" 529 530 "reset port (port_id) mirror-rule (rule_id)\n" 531 " Reset a mirror rule.\n\n" 532 533 "set flush_rx (on|off)\n" 534 " Flush (default) or don't flush RX streams before" 535 " forwarding. Mainly used with PCAP drivers.\n\n" 536 537 "set bypass mode (normal|bypass|isolate) (port_id)\n" 538 " Set the bypass mode for the lowest port on bypass enabled" 539 " NIC.\n\n" 540 541 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 542 "mode (normal|bypass|isolate) (port_id)\n" 543 " Set the event required to initiate specified bypass mode for" 544 " the lowest port on a bypass enabled NIC where:\n" 545 " timeout = enable bypass after watchdog timeout.\n" 546 " os_on = enable bypass when OS/board is powered on.\n" 547 " os_off = enable bypass when OS/board is powered off.\n" 548 " power_on = enable bypass when power supply is turned on.\n" 549 " power_off = enable bypass when power supply is turned off." 550 "\n\n" 551 552 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 553 " Set the bypass watchdog timeout to 'n' seconds" 554 " where 0 = instant.\n\n" 555 556 "show bypass config (port_id)\n" 557 " Show the bypass configuration for a bypass enabled NIC" 558 " using the lowest port on the NIC.\n\n" 559 560 #ifdef RTE_LIBRTE_PMD_BOND 561 "create bonded device (mode) (socket)\n" 562 " Create a new bonded device with specific bonding mode and socket.\n\n" 563 564 "add bonding slave (slave_id) (port_id)\n" 565 " Add a slave device to a bonded device.\n\n" 566 567 "remove bonding slave (slave_id) (port_id)\n" 568 " Remove a slave device from a bonded device.\n\n" 569 570 "set bonding mode (value) (port_id)\n" 571 " Set the bonding mode on a bonded device.\n\n" 572 573 "set bonding primary (slave_id) (port_id)\n" 574 " Set the primary slave for a bonded device.\n\n" 575 576 "show bonding config (port_id)\n" 577 " Show the bonding config for port_id.\n\n" 578 579 "set bonding mac_addr (port_id) (address)\n" 580 " Set the MAC address of a bonded device.\n\n" 581 582 "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)" 583 " Set Aggregation mode for IEEE802.3AD (mode 4)" 584 585 "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n" 586 " Set the transmit balance policy for bonded device running in balance mode.\n\n" 587 588 "set bonding mon_period (port_id) (value)\n" 589 " Set the bonding link status monitoring polling period in ms.\n\n" 590 591 "set bonding lacp dedicated_queues <port_id> (enable|disable)\n" 592 " Enable/disable dedicated queues for LACP control traffic.\n\n" 593 594 #endif 595 "set link-up port (port_id)\n" 596 " Set link up for a port.\n\n" 597 598 "set link-down port (port_id)\n" 599 " Set link down for a port.\n\n" 600 601 "E-tag set insertion on port-tag-id (value)" 602 " port (port_id) vf (vf_id)\n" 603 " Enable E-tag insertion for a VF on a port\n\n" 604 605 "E-tag set insertion off port (port_id) vf (vf_id)\n" 606 " Disable E-tag insertion for a VF on a port\n\n" 607 608 "E-tag set stripping (on|off) port (port_id)\n" 609 " Enable/disable E-tag stripping on a port\n\n" 610 611 "E-tag set forwarding (on|off) port (port_id)\n" 612 " Enable/disable E-tag based forwarding" 613 " on a port\n\n" 614 615 "E-tag set filter add e-tag-id (value) dst-pool" 616 " (pool_id) port (port_id)\n" 617 " Add an E-tag forwarding filter on a port\n\n" 618 619 "E-tag set filter del e-tag-id (value) port (port_id)\n" 620 " Delete an E-tag forwarding filter on a port\n\n" 621 622 "ddp add (port_id) (profile_path[,output_path])\n" 623 " Load a profile package on a port\n\n" 624 625 "ddp del (port_id) (profile_path)\n" 626 " Delete a profile package from a port\n\n" 627 628 "ptype mapping get (port_id) (valid_only)\n" 629 " Get ptype mapping on a port\n\n" 630 631 "ptype mapping replace (port_id) (target) (mask) (pky_type)\n" 632 " Replace target with the pkt_type in ptype mapping\n\n" 633 634 "ptype mapping reset (port_id)\n" 635 " Reset ptype mapping on a port\n\n" 636 637 "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n" 638 " Update a ptype mapping item on a port\n\n" 639 640 , list_pkt_forwarding_modes() 641 ); 642 } 643 644 if (show_all || !strcmp(res->section, "ports")) { 645 646 cmdline_printf( 647 cl, 648 "\n" 649 "Port Operations:\n" 650 "----------------\n\n" 651 652 "port start (port_id|all)\n" 653 " Start all ports or port_id.\n\n" 654 655 "port stop (port_id|all)\n" 656 " Stop all ports or port_id.\n\n" 657 658 "port close (port_id|all)\n" 659 " Close all ports or port_id.\n\n" 660 661 "port attach (ident)\n" 662 " Attach physical or virtual dev by pci address or virtual device name\n\n" 663 664 "port detach (port_id)\n" 665 " Detach physical or virtual dev by port_id\n\n" 666 667 "port config (port_id|all)" 668 " speed (10|100|1000|10000|25000|40000|50000|100000|auto)" 669 " duplex (half|full|auto)\n" 670 " Set speed and duplex for all ports or port_id\n\n" 671 672 "port config all (rxq|txq|rxd|txd) (value)\n" 673 " Set number for rxq/txq/rxd/txd.\n\n" 674 675 "port config all max-pkt-len (value)\n" 676 " Set the max packet length.\n\n" 677 678 "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|" 679 "hw-vlan-strip|hw-vlan-extend|drop-en)" 680 " (on|off)\n" 681 " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" 682 " for ports.\n\n" 683 684 "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n" 685 " Set the RSS mode.\n\n" 686 687 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 688 " Set the RSS redirection table.\n\n" 689 690 "port config (port_id) dcb vt (on|off) (traffic_class)" 691 " pfc (on|off)\n" 692 " Set the DCB mode.\n\n" 693 694 "port config all burst (value)\n" 695 " Set the number of packets per burst.\n\n" 696 697 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 698 " (value)\n" 699 " Set the ring prefetch/host/writeback threshold" 700 " for tx/rx queue.\n\n" 701 702 "port config all (txfreet|txrst|rxfreet) (value)\n" 703 " Set free threshold for rx/tx, or set" 704 " tx rs bit threshold.\n\n" 705 "port config mtu X value\n" 706 " Set the MTU of port X to a given value\n\n" 707 708 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 709 " Start/stop a rx/tx queue of port X. Only take effect" 710 " when port X is started\n\n" 711 712 "port config (port_id|all) l2-tunnel E-tag ether-type" 713 " (value)\n" 714 " Set the value of E-tag ether-type.\n\n" 715 716 "port config (port_id|all) l2-tunnel E-tag" 717 " (enable|disable)\n" 718 " Enable/disable the E-tag support.\n\n" 719 ); 720 } 721 722 if (show_all || !strcmp(res->section, "registers")) { 723 724 cmdline_printf( 725 cl, 726 "\n" 727 "Registers:\n" 728 "----------\n\n" 729 730 "read reg (port_id) (address)\n" 731 " Display value of a port register.\n\n" 732 733 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 734 " Display a port register bit field.\n\n" 735 736 "read regbit (port_id) (address) (bit_x)\n" 737 " Display a single port register bit.\n\n" 738 739 "write reg (port_id) (address) (value)\n" 740 " Set value of a port register.\n\n" 741 742 "write regfield (port_id) (address) (bit_x) (bit_y)" 743 " (value)\n" 744 " Set bit field of a port register.\n\n" 745 746 "write regbit (port_id) (address) (bit_x) (value)\n" 747 " Set single bit value of a port register.\n\n" 748 ); 749 } 750 if (show_all || !strcmp(res->section, "filters")) { 751 752 cmdline_printf( 753 cl, 754 "\n" 755 "filters:\n" 756 "--------\n\n" 757 758 "ethertype_filter (port_id) (add|del)" 759 " (mac_addr|mac_ignr) (mac_address) ethertype" 760 " (ether_type) (drop|fwd) queue (queue_id)\n" 761 " Add/Del an ethertype filter.\n\n" 762 763 "2tuple_filter (port_id) (add|del)" 764 " dst_port (dst_port_value) protocol (protocol_value)" 765 " mask (mask_value) tcp_flags (tcp_flags_value)" 766 " priority (prio_value) queue (queue_id)\n" 767 " Add/Del a 2tuple filter.\n\n" 768 769 "5tuple_filter (port_id) (add|del)" 770 " dst_ip (dst_address) src_ip (src_address)" 771 " dst_port (dst_port_value) src_port (src_port_value)" 772 " protocol (protocol_value)" 773 " mask (mask_value) tcp_flags (tcp_flags_value)" 774 " priority (prio_value) queue (queue_id)\n" 775 " Add/Del a 5tuple filter.\n\n" 776 777 "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" 778 " Add/Del syn filter.\n\n" 779 780 "flex_filter (port_id) (add|del) len (len_value)" 781 " bytes (bytes_value) mask (mask_value)" 782 " priority (prio_value) queue (queue_id)\n" 783 " Add/Del a flex filter.\n\n" 784 785 "flow_director_filter (port_id) mode IP (add|del|update)" 786 " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)" 787 " src (src_ip_address) dst (dst_ip_address)" 788 " tos (tos_value) proto (proto_value) ttl (ttl_value)" 789 " vlan (vlan_value) flexbytes (flexbytes_value)" 790 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 791 " fd_id (fd_id_value)\n" 792 " Add/Del an IP type flow director filter.\n\n" 793 794 "flow_director_filter (port_id) mode IP (add|del|update)" 795 " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)" 796 " src (src_ip_address) (src_port)" 797 " dst (dst_ip_address) (dst_port)" 798 " tos (tos_value) ttl (ttl_value)" 799 " vlan (vlan_value) flexbytes (flexbytes_value)" 800 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 801 " fd_id (fd_id_value)\n" 802 " Add/Del an UDP/TCP type flow director filter.\n\n" 803 804 "flow_director_filter (port_id) mode IP (add|del|update)" 805 " flow (ipv4-sctp|ipv6-sctp)" 806 " src (src_ip_address) (src_port)" 807 " dst (dst_ip_address) (dst_port)" 808 " tag (verification_tag) " 809 " tos (tos_value) ttl (ttl_value)" 810 " vlan (vlan_value)" 811 " flexbytes (flexbytes_value) (drop|fwd)" 812 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 813 " Add/Del a SCTP type flow director filter.\n\n" 814 815 "flow_director_filter (port_id) mode IP (add|del|update)" 816 " flow l2_payload ether (ethertype)" 817 " flexbytes (flexbytes_value) (drop|fwd)" 818 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 819 " Add/Del a l2 payload type flow director filter.\n\n" 820 821 "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)" 822 " mac (mac_address) vlan (vlan_value)" 823 " flexbytes (flexbytes_value) (drop|fwd)" 824 " queue (queue_id) fd_id (fd_id_value)\n" 825 " Add/Del a MAC-VLAN flow director filter.\n\n" 826 827 "flow_director_filter (port_id) mode Tunnel (add|del|update)" 828 " mac (mac_address) vlan (vlan_value)" 829 " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)" 830 " flexbytes (flexbytes_value) (drop|fwd)" 831 " queue (queue_id) fd_id (fd_id_value)\n" 832 " Add/Del a Tunnel flow director filter.\n\n" 833 834 "flush_flow_director (port_id)\n" 835 " Flush all flow director entries of a device.\n\n" 836 837 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 838 " src_mask (ipv4_src) (ipv6_src) (src_port)" 839 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 840 " Set flow director IP mask.\n\n" 841 842 "flow_director_mask (port_id) mode MAC-VLAN" 843 " vlan (vlan_value)\n" 844 " Set flow director MAC-VLAN mask.\n\n" 845 846 "flow_director_mask (port_id) mode Tunnel" 847 " vlan (vlan_value) mac (mac_value)" 848 " tunnel-type (tunnel_type_value)" 849 " tunnel-id (tunnel_id_value)\n" 850 " Set flow director Tunnel mask.\n\n" 851 852 "flow_director_flex_mask (port_id)" 853 " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 854 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)" 855 " (mask)\n" 856 " Configure mask of flex payload.\n\n" 857 858 "flow_director_flex_payload (port_id)" 859 " (raw|l2|l3|l4) (config)\n" 860 " Configure flex payload selection.\n\n" 861 862 "get_sym_hash_ena_per_port (port_id)\n" 863 " get symmetric hash enable configuration per port.\n\n" 864 865 "set_sym_hash_ena_per_port (port_id) (enable|disable)\n" 866 " set symmetric hash enable configuration per port" 867 " to enable or disable.\n\n" 868 869 "get_hash_global_config (port_id)\n" 870 " Get the global configurations of hash filters.\n\n" 871 872 "set_hash_global_config (port_id) (toeplitz|simple_xor|default)" 873 " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 874 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)" 875 " (enable|disable)\n" 876 " Set the global configurations of hash filters.\n\n" 877 878 "set_hash_input_set (port_id) (ipv4|ipv4-frag|" 879 "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 880 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 881 "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|" 882 "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" 883 "ipv6-next-header|udp-src-port|udp-dst-port|" 884 "tcp-src-port|tcp-dst-port|sctp-src-port|" 885 "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" 886 "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|" 887 "fld-8th|none) (select|add)\n" 888 " Set the input set for hash.\n\n" 889 890 "set_fdir_input_set (port_id) " 891 "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 892 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 893 "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|" 894 "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|" 895 "ipv6-next-header|ipv6-hop-limits|udp-src-port|" 896 "udp-dst-port|tcp-src-port|tcp-dst-port|" 897 "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)" 898 " (select|add)\n" 899 " Set the input set for FDir.\n\n" 900 901 "flow validate {port_id}" 902 " [group {group_id}] [priority {level}]" 903 " [ingress] [egress]" 904 " pattern {item} [/ {item} [...]] / end" 905 " actions {action} [/ {action} [...]] / end\n" 906 " Check whether a flow rule can be created.\n\n" 907 908 "flow create {port_id}" 909 " [group {group_id}] [priority {level}]" 910 " [ingress] [egress]" 911 " pattern {item} [/ {item} [...]] / end" 912 " actions {action} [/ {action} [...]] / end\n" 913 " Create a flow rule.\n\n" 914 915 "flow destroy {port_id} rule {rule_id} [...]\n" 916 " Destroy specific flow rules.\n\n" 917 918 "flow flush {port_id}\n" 919 " Destroy all flow rules.\n\n" 920 921 "flow query {port_id} {rule_id} {action}\n" 922 " Query an existing flow rule.\n\n" 923 924 "flow list {port_id} [group {group_id}] [...]\n" 925 " List existing flow rules sorted by priority," 926 " filtered by group identifiers.\n\n" 927 928 "flow isolate {port_id} {boolean}\n" 929 " Restrict ingress traffic to the defined" 930 " flow rules\n\n" 931 ); 932 } 933 } 934 935 cmdline_parse_token_string_t cmd_help_long_help = 936 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 937 938 cmdline_parse_token_string_t cmd_help_long_section = 939 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 940 "all#control#display#config#" 941 "ports#registers#filters"); 942 943 cmdline_parse_inst_t cmd_help_long = { 944 .f = cmd_help_long_parsed, 945 .data = NULL, 946 .help_str = "help all|control|display|config|ports|register|filters: " 947 "Show help", 948 .tokens = { 949 (void *)&cmd_help_long_help, 950 (void *)&cmd_help_long_section, 951 NULL, 952 }, 953 }; 954 955 956 /* *** start/stop/close all ports *** */ 957 struct cmd_operate_port_result { 958 cmdline_fixed_string_t keyword; 959 cmdline_fixed_string_t name; 960 cmdline_fixed_string_t value; 961 }; 962 963 static void cmd_operate_port_parsed(void *parsed_result, 964 __attribute__((unused)) struct cmdline *cl, 965 __attribute__((unused)) void *data) 966 { 967 struct cmd_operate_port_result *res = parsed_result; 968 969 if (!strcmp(res->name, "start")) 970 start_port(RTE_PORT_ALL); 971 else if (!strcmp(res->name, "stop")) 972 stop_port(RTE_PORT_ALL); 973 else if (!strcmp(res->name, "close")) 974 close_port(RTE_PORT_ALL); 975 else 976 printf("Unknown parameter\n"); 977 } 978 979 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 980 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 981 "port"); 982 cmdline_parse_token_string_t cmd_operate_port_all_port = 983 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 984 "start#stop#close"); 985 cmdline_parse_token_string_t cmd_operate_port_all_all = 986 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 987 988 cmdline_parse_inst_t cmd_operate_port = { 989 .f = cmd_operate_port_parsed, 990 .data = NULL, 991 .help_str = "port start|stop|close all: Start/Stop/Close all ports", 992 .tokens = { 993 (void *)&cmd_operate_port_all_cmd, 994 (void *)&cmd_operate_port_all_port, 995 (void *)&cmd_operate_port_all_all, 996 NULL, 997 }, 998 }; 999 1000 /* *** start/stop/close specific port *** */ 1001 struct cmd_operate_specific_port_result { 1002 cmdline_fixed_string_t keyword; 1003 cmdline_fixed_string_t name; 1004 uint8_t value; 1005 }; 1006 1007 static void cmd_operate_specific_port_parsed(void *parsed_result, 1008 __attribute__((unused)) struct cmdline *cl, 1009 __attribute__((unused)) void *data) 1010 { 1011 struct cmd_operate_specific_port_result *res = parsed_result; 1012 1013 if (!strcmp(res->name, "start")) 1014 start_port(res->value); 1015 else if (!strcmp(res->name, "stop")) 1016 stop_port(res->value); 1017 else if (!strcmp(res->name, "close")) 1018 close_port(res->value); 1019 else 1020 printf("Unknown parameter\n"); 1021 } 1022 1023 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 1024 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1025 keyword, "port"); 1026 cmdline_parse_token_string_t cmd_operate_specific_port_port = 1027 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1028 name, "start#stop#close"); 1029 cmdline_parse_token_num_t cmd_operate_specific_port_id = 1030 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 1031 value, UINT8); 1032 1033 cmdline_parse_inst_t cmd_operate_specific_port = { 1034 .f = cmd_operate_specific_port_parsed, 1035 .data = NULL, 1036 .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id", 1037 .tokens = { 1038 (void *)&cmd_operate_specific_port_cmd, 1039 (void *)&cmd_operate_specific_port_port, 1040 (void *)&cmd_operate_specific_port_id, 1041 NULL, 1042 }, 1043 }; 1044 1045 /* *** attach a specified port *** */ 1046 struct cmd_operate_attach_port_result { 1047 cmdline_fixed_string_t port; 1048 cmdline_fixed_string_t keyword; 1049 cmdline_fixed_string_t identifier; 1050 }; 1051 1052 static void cmd_operate_attach_port_parsed(void *parsed_result, 1053 __attribute__((unused)) struct cmdline *cl, 1054 __attribute__((unused)) void *data) 1055 { 1056 struct cmd_operate_attach_port_result *res = parsed_result; 1057 1058 if (!strcmp(res->keyword, "attach")) 1059 attach_port(res->identifier); 1060 else 1061 printf("Unknown parameter\n"); 1062 } 1063 1064 cmdline_parse_token_string_t cmd_operate_attach_port_port = 1065 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1066 port, "port"); 1067 cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1068 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1069 keyword, "attach"); 1070 cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1071 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1072 identifier, NULL); 1073 1074 cmdline_parse_inst_t cmd_operate_attach_port = { 1075 .f = cmd_operate_attach_port_parsed, 1076 .data = NULL, 1077 .help_str = "port attach <identifier>: " 1078 "(identifier: pci address or virtual dev name)", 1079 .tokens = { 1080 (void *)&cmd_operate_attach_port_port, 1081 (void *)&cmd_operate_attach_port_keyword, 1082 (void *)&cmd_operate_attach_port_identifier, 1083 NULL, 1084 }, 1085 }; 1086 1087 /* *** detach a specified port *** */ 1088 struct cmd_operate_detach_port_result { 1089 cmdline_fixed_string_t port; 1090 cmdline_fixed_string_t keyword; 1091 uint8_t port_id; 1092 }; 1093 1094 static void cmd_operate_detach_port_parsed(void *parsed_result, 1095 __attribute__((unused)) struct cmdline *cl, 1096 __attribute__((unused)) void *data) 1097 { 1098 struct cmd_operate_detach_port_result *res = parsed_result; 1099 1100 if (!strcmp(res->keyword, "detach")) 1101 detach_port(res->port_id); 1102 else 1103 printf("Unknown parameter\n"); 1104 } 1105 1106 cmdline_parse_token_string_t cmd_operate_detach_port_port = 1107 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1108 port, "port"); 1109 cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1110 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1111 keyword, "detach"); 1112 cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1113 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1114 port_id, UINT8); 1115 1116 cmdline_parse_inst_t cmd_operate_detach_port = { 1117 .f = cmd_operate_detach_port_parsed, 1118 .data = NULL, 1119 .help_str = "port detach <port_id>", 1120 .tokens = { 1121 (void *)&cmd_operate_detach_port_port, 1122 (void *)&cmd_operate_detach_port_keyword, 1123 (void *)&cmd_operate_detach_port_port_id, 1124 NULL, 1125 }, 1126 }; 1127 1128 /* *** configure speed for all ports *** */ 1129 struct cmd_config_speed_all { 1130 cmdline_fixed_string_t port; 1131 cmdline_fixed_string_t keyword; 1132 cmdline_fixed_string_t all; 1133 cmdline_fixed_string_t item1; 1134 cmdline_fixed_string_t item2; 1135 cmdline_fixed_string_t value1; 1136 cmdline_fixed_string_t value2; 1137 }; 1138 1139 static int 1140 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1141 { 1142 1143 int duplex; 1144 1145 if (!strcmp(duplexstr, "half")) { 1146 duplex = ETH_LINK_HALF_DUPLEX; 1147 } else if (!strcmp(duplexstr, "full")) { 1148 duplex = ETH_LINK_FULL_DUPLEX; 1149 } else if (!strcmp(duplexstr, "auto")) { 1150 duplex = ETH_LINK_FULL_DUPLEX; 1151 } else { 1152 printf("Unknown duplex parameter\n"); 1153 return -1; 1154 } 1155 1156 if (!strcmp(speedstr, "10")) { 1157 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1158 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M; 1159 } else if (!strcmp(speedstr, "100")) { 1160 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1161 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M; 1162 } else { 1163 if (duplex != ETH_LINK_FULL_DUPLEX) { 1164 printf("Invalid speed/duplex parameters\n"); 1165 return -1; 1166 } 1167 if (!strcmp(speedstr, "1000")) { 1168 *speed = ETH_LINK_SPEED_1G; 1169 } else if (!strcmp(speedstr, "10000")) { 1170 *speed = ETH_LINK_SPEED_10G; 1171 } else if (!strcmp(speedstr, "25000")) { 1172 *speed = ETH_LINK_SPEED_25G; 1173 } else if (!strcmp(speedstr, "40000")) { 1174 *speed = ETH_LINK_SPEED_40G; 1175 } else if (!strcmp(speedstr, "50000")) { 1176 *speed = ETH_LINK_SPEED_50G; 1177 } else if (!strcmp(speedstr, "100000")) { 1178 *speed = ETH_LINK_SPEED_100G; 1179 } else if (!strcmp(speedstr, "auto")) { 1180 *speed = ETH_LINK_SPEED_AUTONEG; 1181 } else { 1182 printf("Unknown speed parameter\n"); 1183 return -1; 1184 } 1185 } 1186 1187 return 0; 1188 } 1189 1190 static void 1191 cmd_config_speed_all_parsed(void *parsed_result, 1192 __attribute__((unused)) struct cmdline *cl, 1193 __attribute__((unused)) void *data) 1194 { 1195 struct cmd_config_speed_all *res = parsed_result; 1196 uint32_t link_speed; 1197 portid_t pid; 1198 1199 if (!all_ports_stopped()) { 1200 printf("Please stop all ports first\n"); 1201 return; 1202 } 1203 1204 if (parse_and_check_speed_duplex(res->value1, res->value2, 1205 &link_speed) < 0) 1206 return; 1207 1208 RTE_ETH_FOREACH_DEV(pid) { 1209 ports[pid].dev_conf.link_speeds = link_speed; 1210 } 1211 1212 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1213 } 1214 1215 cmdline_parse_token_string_t cmd_config_speed_all_port = 1216 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1217 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1218 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1219 "config"); 1220 cmdline_parse_token_string_t cmd_config_speed_all_all = 1221 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1222 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1223 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1224 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1225 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1226 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1227 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1228 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1229 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1230 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1231 "half#full#auto"); 1232 1233 cmdline_parse_inst_t cmd_config_speed_all = { 1234 .f = cmd_config_speed_all_parsed, 1235 .data = NULL, 1236 .help_str = "port config all speed " 1237 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1238 "half|full|auto", 1239 .tokens = { 1240 (void *)&cmd_config_speed_all_port, 1241 (void *)&cmd_config_speed_all_keyword, 1242 (void *)&cmd_config_speed_all_all, 1243 (void *)&cmd_config_speed_all_item1, 1244 (void *)&cmd_config_speed_all_value1, 1245 (void *)&cmd_config_speed_all_item2, 1246 (void *)&cmd_config_speed_all_value2, 1247 NULL, 1248 }, 1249 }; 1250 1251 /* *** configure speed for specific port *** */ 1252 struct cmd_config_speed_specific { 1253 cmdline_fixed_string_t port; 1254 cmdline_fixed_string_t keyword; 1255 uint8_t id; 1256 cmdline_fixed_string_t item1; 1257 cmdline_fixed_string_t item2; 1258 cmdline_fixed_string_t value1; 1259 cmdline_fixed_string_t value2; 1260 }; 1261 1262 static void 1263 cmd_config_speed_specific_parsed(void *parsed_result, 1264 __attribute__((unused)) struct cmdline *cl, 1265 __attribute__((unused)) void *data) 1266 { 1267 struct cmd_config_speed_specific *res = parsed_result; 1268 uint32_t link_speed; 1269 1270 if (!all_ports_stopped()) { 1271 printf("Please stop all ports first\n"); 1272 return; 1273 } 1274 1275 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1276 return; 1277 1278 if (parse_and_check_speed_duplex(res->value1, res->value2, 1279 &link_speed) < 0) 1280 return; 1281 1282 ports[res->id].dev_conf.link_speeds = link_speed; 1283 1284 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1285 } 1286 1287 1288 cmdline_parse_token_string_t cmd_config_speed_specific_port = 1289 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1290 "port"); 1291 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1292 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1293 "config"); 1294 cmdline_parse_token_num_t cmd_config_speed_specific_id = 1295 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 1296 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1297 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1298 "speed"); 1299 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1300 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1301 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1302 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1303 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1304 "duplex"); 1305 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1306 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1307 "half#full#auto"); 1308 1309 cmdline_parse_inst_t cmd_config_speed_specific = { 1310 .f = cmd_config_speed_specific_parsed, 1311 .data = NULL, 1312 .help_str = "port config <port_id> speed " 1313 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1314 "half|full|auto", 1315 .tokens = { 1316 (void *)&cmd_config_speed_specific_port, 1317 (void *)&cmd_config_speed_specific_keyword, 1318 (void *)&cmd_config_speed_specific_id, 1319 (void *)&cmd_config_speed_specific_item1, 1320 (void *)&cmd_config_speed_specific_value1, 1321 (void *)&cmd_config_speed_specific_item2, 1322 (void *)&cmd_config_speed_specific_value2, 1323 NULL, 1324 }, 1325 }; 1326 1327 /* *** configure txq/rxq, txd/rxd *** */ 1328 struct cmd_config_rx_tx { 1329 cmdline_fixed_string_t port; 1330 cmdline_fixed_string_t keyword; 1331 cmdline_fixed_string_t all; 1332 cmdline_fixed_string_t name; 1333 uint16_t value; 1334 }; 1335 1336 static void 1337 cmd_config_rx_tx_parsed(void *parsed_result, 1338 __attribute__((unused)) struct cmdline *cl, 1339 __attribute__((unused)) void *data) 1340 { 1341 struct cmd_config_rx_tx *res = parsed_result; 1342 1343 if (!all_ports_stopped()) { 1344 printf("Please stop all ports first\n"); 1345 return; 1346 } 1347 if (!strcmp(res->name, "rxq")) { 1348 if (!res->value && !nb_txq) { 1349 printf("Warning: Either rx or tx queues should be non zero\n"); 1350 return; 1351 } 1352 nb_rxq = res->value; 1353 } 1354 else if (!strcmp(res->name, "txq")) { 1355 if (!res->value && !nb_rxq) { 1356 printf("Warning: Either rx or tx queues should be non zero\n"); 1357 return; 1358 } 1359 nb_txq = res->value; 1360 } 1361 else if (!strcmp(res->name, "rxd")) { 1362 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 1363 printf("rxd %d invalid - must be > 0 && <= %d\n", 1364 res->value, RTE_TEST_RX_DESC_MAX); 1365 return; 1366 } 1367 nb_rxd = res->value; 1368 } else if (!strcmp(res->name, "txd")) { 1369 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 1370 printf("txd %d invalid - must be > 0 && <= %d\n", 1371 res->value, RTE_TEST_TX_DESC_MAX); 1372 return; 1373 } 1374 nb_txd = res->value; 1375 } else { 1376 printf("Unknown parameter\n"); 1377 return; 1378 } 1379 1380 fwd_config_setup(); 1381 1382 init_port_config(); 1383 1384 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1385 } 1386 1387 cmdline_parse_token_string_t cmd_config_rx_tx_port = 1388 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1389 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1390 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1391 cmdline_parse_token_string_t cmd_config_rx_tx_all = 1392 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1393 cmdline_parse_token_string_t cmd_config_rx_tx_name = 1394 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1395 "rxq#txq#rxd#txd"); 1396 cmdline_parse_token_num_t cmd_config_rx_tx_value = 1397 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 1398 1399 cmdline_parse_inst_t cmd_config_rx_tx = { 1400 .f = cmd_config_rx_tx_parsed, 1401 .data = NULL, 1402 .help_str = "port config all rxq|txq|rxd|txd <value>", 1403 .tokens = { 1404 (void *)&cmd_config_rx_tx_port, 1405 (void *)&cmd_config_rx_tx_keyword, 1406 (void *)&cmd_config_rx_tx_all, 1407 (void *)&cmd_config_rx_tx_name, 1408 (void *)&cmd_config_rx_tx_value, 1409 NULL, 1410 }, 1411 }; 1412 1413 /* *** config max packet length *** */ 1414 struct cmd_config_max_pkt_len_result { 1415 cmdline_fixed_string_t port; 1416 cmdline_fixed_string_t keyword; 1417 cmdline_fixed_string_t all; 1418 cmdline_fixed_string_t name; 1419 uint32_t value; 1420 }; 1421 1422 static void 1423 cmd_config_max_pkt_len_parsed(void *parsed_result, 1424 __attribute__((unused)) struct cmdline *cl, 1425 __attribute__((unused)) void *data) 1426 { 1427 struct cmd_config_max_pkt_len_result *res = parsed_result; 1428 1429 if (!all_ports_stopped()) { 1430 printf("Please stop all ports first\n"); 1431 return; 1432 } 1433 1434 if (!strcmp(res->name, "max-pkt-len")) { 1435 if (res->value < ETHER_MIN_LEN) { 1436 printf("max-pkt-len can not be less than %d\n", 1437 ETHER_MIN_LEN); 1438 return; 1439 } 1440 if (res->value == rx_mode.max_rx_pkt_len) 1441 return; 1442 1443 rx_mode.max_rx_pkt_len = res->value; 1444 if (res->value > ETHER_MAX_LEN) 1445 rx_mode.jumbo_frame = 1; 1446 else 1447 rx_mode.jumbo_frame = 0; 1448 } else { 1449 printf("Unknown parameter\n"); 1450 return; 1451 } 1452 1453 init_port_config(); 1454 1455 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1456 } 1457 1458 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1459 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1460 "port"); 1461 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1462 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1463 "config"); 1464 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1465 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1466 "all"); 1467 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1468 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1469 "max-pkt-len"); 1470 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1471 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1472 UINT32); 1473 1474 cmdline_parse_inst_t cmd_config_max_pkt_len = { 1475 .f = cmd_config_max_pkt_len_parsed, 1476 .data = NULL, 1477 .help_str = "port config all max-pkt-len <value>", 1478 .tokens = { 1479 (void *)&cmd_config_max_pkt_len_port, 1480 (void *)&cmd_config_max_pkt_len_keyword, 1481 (void *)&cmd_config_max_pkt_len_all, 1482 (void *)&cmd_config_max_pkt_len_name, 1483 (void *)&cmd_config_max_pkt_len_value, 1484 NULL, 1485 }, 1486 }; 1487 1488 /* *** configure port MTU *** */ 1489 struct cmd_config_mtu_result { 1490 cmdline_fixed_string_t port; 1491 cmdline_fixed_string_t keyword; 1492 cmdline_fixed_string_t mtu; 1493 uint8_t port_id; 1494 uint16_t value; 1495 }; 1496 1497 static void 1498 cmd_config_mtu_parsed(void *parsed_result, 1499 __attribute__((unused)) struct cmdline *cl, 1500 __attribute__((unused)) void *data) 1501 { 1502 struct cmd_config_mtu_result *res = parsed_result; 1503 1504 if (res->value < ETHER_MIN_LEN) { 1505 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN); 1506 return; 1507 } 1508 port_mtu_set(res->port_id, res->value); 1509 } 1510 1511 cmdline_parse_token_string_t cmd_config_mtu_port = 1512 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1513 "port"); 1514 cmdline_parse_token_string_t cmd_config_mtu_keyword = 1515 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1516 "config"); 1517 cmdline_parse_token_string_t cmd_config_mtu_mtu = 1518 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1519 "mtu"); 1520 cmdline_parse_token_num_t cmd_config_mtu_port_id = 1521 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8); 1522 cmdline_parse_token_num_t cmd_config_mtu_value = 1523 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); 1524 1525 cmdline_parse_inst_t cmd_config_mtu = { 1526 .f = cmd_config_mtu_parsed, 1527 .data = NULL, 1528 .help_str = "port config mtu <port_id> <value>", 1529 .tokens = { 1530 (void *)&cmd_config_mtu_port, 1531 (void *)&cmd_config_mtu_keyword, 1532 (void *)&cmd_config_mtu_mtu, 1533 (void *)&cmd_config_mtu_port_id, 1534 (void *)&cmd_config_mtu_value, 1535 NULL, 1536 }, 1537 }; 1538 1539 /* *** configure rx mode *** */ 1540 struct cmd_config_rx_mode_flag { 1541 cmdline_fixed_string_t port; 1542 cmdline_fixed_string_t keyword; 1543 cmdline_fixed_string_t all; 1544 cmdline_fixed_string_t name; 1545 cmdline_fixed_string_t value; 1546 }; 1547 1548 static void 1549 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1550 __attribute__((unused)) struct cmdline *cl, 1551 __attribute__((unused)) void *data) 1552 { 1553 struct cmd_config_rx_mode_flag *res = parsed_result; 1554 1555 if (!all_ports_stopped()) { 1556 printf("Please stop all ports first\n"); 1557 return; 1558 } 1559 1560 if (!strcmp(res->name, "crc-strip")) { 1561 if (!strcmp(res->value, "on")) 1562 rx_mode.hw_strip_crc = 1; 1563 else if (!strcmp(res->value, "off")) 1564 rx_mode.hw_strip_crc = 0; 1565 else { 1566 printf("Unknown parameter\n"); 1567 return; 1568 } 1569 } else if (!strcmp(res->name, "scatter")) { 1570 if (!strcmp(res->value, "on")) 1571 rx_mode.enable_scatter = 1; 1572 else if (!strcmp(res->value, "off")) 1573 rx_mode.enable_scatter = 0; 1574 else { 1575 printf("Unknown parameter\n"); 1576 return; 1577 } 1578 } else if (!strcmp(res->name, "rx-cksum")) { 1579 if (!strcmp(res->value, "on")) 1580 rx_mode.hw_ip_checksum = 1; 1581 else if (!strcmp(res->value, "off")) 1582 rx_mode.hw_ip_checksum = 0; 1583 else { 1584 printf("Unknown parameter\n"); 1585 return; 1586 } 1587 } else if (!strcmp(res->name, "hw-vlan")) { 1588 if (!strcmp(res->value, "on")) { 1589 rx_mode.hw_vlan_filter = 1; 1590 rx_mode.hw_vlan_strip = 1; 1591 } 1592 else if (!strcmp(res->value, "off")) { 1593 rx_mode.hw_vlan_filter = 0; 1594 rx_mode.hw_vlan_strip = 0; 1595 } 1596 else { 1597 printf("Unknown parameter\n"); 1598 return; 1599 } 1600 } else if (!strcmp(res->name, "hw-vlan-filter")) { 1601 if (!strcmp(res->value, "on")) 1602 rx_mode.hw_vlan_filter = 1; 1603 else if (!strcmp(res->value, "off")) 1604 rx_mode.hw_vlan_filter = 0; 1605 else { 1606 printf("Unknown parameter\n"); 1607 return; 1608 } 1609 } else if (!strcmp(res->name, "hw-vlan-strip")) { 1610 if (!strcmp(res->value, "on")) 1611 rx_mode.hw_vlan_strip = 1; 1612 else if (!strcmp(res->value, "off")) 1613 rx_mode.hw_vlan_strip = 0; 1614 else { 1615 printf("Unknown parameter\n"); 1616 return; 1617 } 1618 } else if (!strcmp(res->name, "hw-vlan-extend")) { 1619 if (!strcmp(res->value, "on")) 1620 rx_mode.hw_vlan_extend = 1; 1621 else if (!strcmp(res->value, "off")) 1622 rx_mode.hw_vlan_extend = 0; 1623 else { 1624 printf("Unknown parameter\n"); 1625 return; 1626 } 1627 } else if (!strcmp(res->name, "drop-en")) { 1628 if (!strcmp(res->value, "on")) 1629 rx_drop_en = 1; 1630 else if (!strcmp(res->value, "off")) 1631 rx_drop_en = 0; 1632 else { 1633 printf("Unknown parameter\n"); 1634 return; 1635 } 1636 } else { 1637 printf("Unknown parameter\n"); 1638 return; 1639 } 1640 1641 init_port_config(); 1642 1643 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1644 } 1645 1646 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1647 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1648 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1649 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1650 "config"); 1651 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1652 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1653 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1654 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1655 "crc-strip#scatter#rx-cksum#hw-vlan#" 1656 "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); 1657 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1658 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1659 "on#off"); 1660 1661 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1662 .f = cmd_config_rx_mode_flag_parsed, 1663 .data = NULL, 1664 .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|" 1665 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", 1666 .tokens = { 1667 (void *)&cmd_config_rx_mode_flag_port, 1668 (void *)&cmd_config_rx_mode_flag_keyword, 1669 (void *)&cmd_config_rx_mode_flag_all, 1670 (void *)&cmd_config_rx_mode_flag_name, 1671 (void *)&cmd_config_rx_mode_flag_value, 1672 NULL, 1673 }, 1674 }; 1675 1676 /* *** configure rss *** */ 1677 struct cmd_config_rss { 1678 cmdline_fixed_string_t port; 1679 cmdline_fixed_string_t keyword; 1680 cmdline_fixed_string_t all; 1681 cmdline_fixed_string_t name; 1682 cmdline_fixed_string_t value; 1683 }; 1684 1685 static void 1686 cmd_config_rss_parsed(void *parsed_result, 1687 __attribute__((unused)) struct cmdline *cl, 1688 __attribute__((unused)) void *data) 1689 { 1690 struct cmd_config_rss *res = parsed_result; 1691 struct rte_eth_rss_conf rss_conf; 1692 int diag; 1693 uint8_t i; 1694 1695 if (!strcmp(res->value, "all")) 1696 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | 1697 ETH_RSS_UDP | ETH_RSS_SCTP | 1698 ETH_RSS_L2_PAYLOAD; 1699 else if (!strcmp(res->value, "ip")) 1700 rss_conf.rss_hf = ETH_RSS_IP; 1701 else if (!strcmp(res->value, "udp")) 1702 rss_conf.rss_hf = ETH_RSS_UDP; 1703 else if (!strcmp(res->value, "tcp")) 1704 rss_conf.rss_hf = ETH_RSS_TCP; 1705 else if (!strcmp(res->value, "sctp")) 1706 rss_conf.rss_hf = ETH_RSS_SCTP; 1707 else if (!strcmp(res->value, "ether")) 1708 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD; 1709 else if (!strcmp(res->value, "port")) 1710 rss_conf.rss_hf = ETH_RSS_PORT; 1711 else if (!strcmp(res->value, "vxlan")) 1712 rss_conf.rss_hf = ETH_RSS_VXLAN; 1713 else if (!strcmp(res->value, "geneve")) 1714 rss_conf.rss_hf = ETH_RSS_GENEVE; 1715 else if (!strcmp(res->value, "nvgre")) 1716 rss_conf.rss_hf = ETH_RSS_NVGRE; 1717 else if (!strcmp(res->value, "none")) 1718 rss_conf.rss_hf = 0; 1719 else { 1720 printf("Unknown parameter\n"); 1721 return; 1722 } 1723 rss_conf.rss_key = NULL; 1724 for (i = 0; i < rte_eth_dev_count(); i++) { 1725 diag = rte_eth_dev_rss_hash_update(i, &rss_conf); 1726 if (diag < 0) 1727 printf("Configuration of RSS hash at ethernet port %d " 1728 "failed with error (%d): %s.\n", 1729 i, -diag, strerror(-diag)); 1730 } 1731 } 1732 1733 cmdline_parse_token_string_t cmd_config_rss_port = 1734 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1735 cmdline_parse_token_string_t cmd_config_rss_keyword = 1736 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1737 cmdline_parse_token_string_t cmd_config_rss_all = 1738 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1739 cmdline_parse_token_string_t cmd_config_rss_name = 1740 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1741 cmdline_parse_token_string_t cmd_config_rss_value = 1742 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, 1743 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none"); 1744 1745 cmdline_parse_inst_t cmd_config_rss = { 1746 .f = cmd_config_rss_parsed, 1747 .data = NULL, 1748 .help_str = "port config all rss " 1749 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none", 1750 .tokens = { 1751 (void *)&cmd_config_rss_port, 1752 (void *)&cmd_config_rss_keyword, 1753 (void *)&cmd_config_rss_all, 1754 (void *)&cmd_config_rss_name, 1755 (void *)&cmd_config_rss_value, 1756 NULL, 1757 }, 1758 }; 1759 1760 /* *** configure rss hash key *** */ 1761 struct cmd_config_rss_hash_key { 1762 cmdline_fixed_string_t port; 1763 cmdline_fixed_string_t config; 1764 uint8_t port_id; 1765 cmdline_fixed_string_t rss_hash_key; 1766 cmdline_fixed_string_t rss_type; 1767 cmdline_fixed_string_t key; 1768 }; 1769 1770 static uint8_t 1771 hexa_digit_to_value(char hexa_digit) 1772 { 1773 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 1774 return (uint8_t) (hexa_digit - '0'); 1775 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 1776 return (uint8_t) ((hexa_digit - 'a') + 10); 1777 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 1778 return (uint8_t) ((hexa_digit - 'A') + 10); 1779 /* Invalid hexa digit */ 1780 return 0xFF; 1781 } 1782 1783 static uint8_t 1784 parse_and_check_key_hexa_digit(char *key, int idx) 1785 { 1786 uint8_t hexa_v; 1787 1788 hexa_v = hexa_digit_to_value(key[idx]); 1789 if (hexa_v == 0xFF) 1790 printf("invalid key: character %c at position %d is not a " 1791 "valid hexa digit\n", key[idx], idx); 1792 return hexa_v; 1793 } 1794 1795 static void 1796 cmd_config_rss_hash_key_parsed(void *parsed_result, 1797 __attribute__((unused)) struct cmdline *cl, 1798 __attribute__((unused)) void *data) 1799 { 1800 struct cmd_config_rss_hash_key *res = parsed_result; 1801 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 1802 uint8_t xdgt0; 1803 uint8_t xdgt1; 1804 int i; 1805 struct rte_eth_dev_info dev_info; 1806 uint8_t hash_key_size; 1807 uint32_t key_len; 1808 1809 memset(&dev_info, 0, sizeof(dev_info)); 1810 rte_eth_dev_info_get(res->port_id, &dev_info); 1811 if (dev_info.hash_key_size > 0 && 1812 dev_info.hash_key_size <= sizeof(hash_key)) 1813 hash_key_size = dev_info.hash_key_size; 1814 else { 1815 printf("dev_info did not provide a valid hash key size\n"); 1816 return; 1817 } 1818 /* Check the length of the RSS hash key */ 1819 key_len = strlen(res->key); 1820 if (key_len != (hash_key_size * 2)) { 1821 printf("key length: %d invalid - key must be a string of %d" 1822 " hexa-decimal numbers\n", 1823 (int) key_len, hash_key_size * 2); 1824 return; 1825 } 1826 /* Translate RSS hash key into binary representation */ 1827 for (i = 0; i < hash_key_size; i++) { 1828 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 1829 if (xdgt0 == 0xFF) 1830 return; 1831 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 1832 if (xdgt1 == 0xFF) 1833 return; 1834 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 1835 } 1836 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 1837 hash_key_size); 1838 } 1839 1840 cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 1841 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 1842 cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 1843 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 1844 "config"); 1845 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 1846 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); 1847 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 1848 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 1849 rss_hash_key, "rss-hash-key"); 1850 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 1851 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 1852 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 1853 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 1854 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 1855 "ipv6-tcp-ex#ipv6-udp-ex"); 1856 cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 1857 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 1858 1859 cmdline_parse_inst_t cmd_config_rss_hash_key = { 1860 .f = cmd_config_rss_hash_key_parsed, 1861 .data = NULL, 1862 .help_str = "port config <port_id> rss-hash-key " 1863 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 1864 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1865 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex " 1866 "<string of hex digits (variable length, NIC dependent)>", 1867 .tokens = { 1868 (void *)&cmd_config_rss_hash_key_port, 1869 (void *)&cmd_config_rss_hash_key_config, 1870 (void *)&cmd_config_rss_hash_key_port_id, 1871 (void *)&cmd_config_rss_hash_key_rss_hash_key, 1872 (void *)&cmd_config_rss_hash_key_rss_type, 1873 (void *)&cmd_config_rss_hash_key_value, 1874 NULL, 1875 }, 1876 }; 1877 1878 /* *** configure port rxq/txq start/stop *** */ 1879 struct cmd_config_rxtx_queue { 1880 cmdline_fixed_string_t port; 1881 uint8_t portid; 1882 cmdline_fixed_string_t rxtxq; 1883 uint16_t qid; 1884 cmdline_fixed_string_t opname; 1885 }; 1886 1887 static void 1888 cmd_config_rxtx_queue_parsed(void *parsed_result, 1889 __attribute__((unused)) struct cmdline *cl, 1890 __attribute__((unused)) void *data) 1891 { 1892 struct cmd_config_rxtx_queue *res = parsed_result; 1893 uint8_t isrx; 1894 uint8_t isstart; 1895 int ret = 0; 1896 1897 if (test_done == 0) { 1898 printf("Please stop forwarding first\n"); 1899 return; 1900 } 1901 1902 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 1903 return; 1904 1905 if (port_is_started(res->portid) != 1) { 1906 printf("Please start port %u first\n", res->portid); 1907 return; 1908 } 1909 1910 if (!strcmp(res->rxtxq, "rxq")) 1911 isrx = 1; 1912 else if (!strcmp(res->rxtxq, "txq")) 1913 isrx = 0; 1914 else { 1915 printf("Unknown parameter\n"); 1916 return; 1917 } 1918 1919 if (isrx && rx_queue_id_is_invalid(res->qid)) 1920 return; 1921 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 1922 return; 1923 1924 if (!strcmp(res->opname, "start")) 1925 isstart = 1; 1926 else if (!strcmp(res->opname, "stop")) 1927 isstart = 0; 1928 else { 1929 printf("Unknown parameter\n"); 1930 return; 1931 } 1932 1933 if (isstart && isrx) 1934 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 1935 else if (!isstart && isrx) 1936 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 1937 else if (isstart && !isrx) 1938 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 1939 else 1940 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 1941 1942 if (ret == -ENOTSUP) 1943 printf("Function not supported in PMD driver\n"); 1944 } 1945 1946 cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 1947 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 1948 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 1949 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8); 1950 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 1951 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 1952 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 1953 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16); 1954 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 1955 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 1956 "start#stop"); 1957 1958 cmdline_parse_inst_t cmd_config_rxtx_queue = { 1959 .f = cmd_config_rxtx_queue_parsed, 1960 .data = NULL, 1961 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 1962 .tokens = { 1963 (void *)&cmd_config_speed_all_port, 1964 (void *)&cmd_config_rxtx_queue_portid, 1965 (void *)&cmd_config_rxtx_queue_rxtxq, 1966 (void *)&cmd_config_rxtx_queue_qid, 1967 (void *)&cmd_config_rxtx_queue_opname, 1968 NULL, 1969 }, 1970 }; 1971 1972 /* *** Configure RSS RETA *** */ 1973 struct cmd_config_rss_reta { 1974 cmdline_fixed_string_t port; 1975 cmdline_fixed_string_t keyword; 1976 uint8_t port_id; 1977 cmdline_fixed_string_t name; 1978 cmdline_fixed_string_t list_name; 1979 cmdline_fixed_string_t list_of_items; 1980 }; 1981 1982 static int 1983 parse_reta_config(const char *str, 1984 struct rte_eth_rss_reta_entry64 *reta_conf, 1985 uint16_t nb_entries) 1986 { 1987 int i; 1988 unsigned size; 1989 uint16_t hash_index, idx, shift; 1990 uint16_t nb_queue; 1991 char s[256]; 1992 const char *p, *p0 = str; 1993 char *end; 1994 enum fieldnames { 1995 FLD_HASH_INDEX = 0, 1996 FLD_QUEUE, 1997 _NUM_FLD 1998 }; 1999 unsigned long int_fld[_NUM_FLD]; 2000 char *str_fld[_NUM_FLD]; 2001 2002 while ((p = strchr(p0,'(')) != NULL) { 2003 ++p; 2004 if((p0 = strchr(p,')')) == NULL) 2005 return -1; 2006 2007 size = p0 - p; 2008 if(size >= sizeof(s)) 2009 return -1; 2010 2011 snprintf(s, sizeof(s), "%.*s", size, p); 2012 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 2013 return -1; 2014 for (i = 0; i < _NUM_FLD; i++) { 2015 errno = 0; 2016 int_fld[i] = strtoul(str_fld[i], &end, 0); 2017 if (errno != 0 || end == str_fld[i] || 2018 int_fld[i] > 65535) 2019 return -1; 2020 } 2021 2022 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 2023 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 2024 2025 if (hash_index >= nb_entries) { 2026 printf("Invalid RETA hash index=%d\n", hash_index); 2027 return -1; 2028 } 2029 2030 idx = hash_index / RTE_RETA_GROUP_SIZE; 2031 shift = hash_index % RTE_RETA_GROUP_SIZE; 2032 reta_conf[idx].mask |= (1ULL << shift); 2033 reta_conf[idx].reta[shift] = nb_queue; 2034 } 2035 2036 return 0; 2037 } 2038 2039 static void 2040 cmd_set_rss_reta_parsed(void *parsed_result, 2041 __attribute__((unused)) struct cmdline *cl, 2042 __attribute__((unused)) void *data) 2043 { 2044 int ret; 2045 struct rte_eth_dev_info dev_info; 2046 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2047 struct cmd_config_rss_reta *res = parsed_result; 2048 2049 memset(&dev_info, 0, sizeof(dev_info)); 2050 rte_eth_dev_info_get(res->port_id, &dev_info); 2051 if (dev_info.reta_size == 0) { 2052 printf("Redirection table size is 0 which is " 2053 "invalid for RSS\n"); 2054 return; 2055 } else 2056 printf("The reta size of port %d is %u\n", 2057 res->port_id, dev_info.reta_size); 2058 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) { 2059 printf("Currently do not support more than %u entries of " 2060 "redirection table\n", ETH_RSS_RETA_SIZE_512); 2061 return; 2062 } 2063 2064 memset(reta_conf, 0, sizeof(reta_conf)); 2065 if (!strcmp(res->list_name, "reta")) { 2066 if (parse_reta_config(res->list_of_items, reta_conf, 2067 dev_info.reta_size)) { 2068 printf("Invalid RSS Redirection Table " 2069 "config entered\n"); 2070 return; 2071 } 2072 ret = rte_eth_dev_rss_reta_update(res->port_id, 2073 reta_conf, dev_info.reta_size); 2074 if (ret != 0) 2075 printf("Bad redirection table parameter, " 2076 "return code = %d \n", ret); 2077 } 2078 } 2079 2080 cmdline_parse_token_string_t cmd_config_rss_reta_port = 2081 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2082 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2083 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2084 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2085 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); 2086 cmdline_parse_token_string_t cmd_config_rss_reta_name = 2087 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2088 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2089 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2090 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2091 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2092 NULL); 2093 cmdline_parse_inst_t cmd_config_rss_reta = { 2094 .f = cmd_set_rss_reta_parsed, 2095 .data = NULL, 2096 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2097 .tokens = { 2098 (void *)&cmd_config_rss_reta_port, 2099 (void *)&cmd_config_rss_reta_keyword, 2100 (void *)&cmd_config_rss_reta_port_id, 2101 (void *)&cmd_config_rss_reta_name, 2102 (void *)&cmd_config_rss_reta_list_name, 2103 (void *)&cmd_config_rss_reta_list_of_items, 2104 NULL, 2105 }, 2106 }; 2107 2108 /* *** SHOW PORT RETA INFO *** */ 2109 struct cmd_showport_reta { 2110 cmdline_fixed_string_t show; 2111 cmdline_fixed_string_t port; 2112 uint8_t port_id; 2113 cmdline_fixed_string_t rss; 2114 cmdline_fixed_string_t reta; 2115 uint16_t size; 2116 cmdline_fixed_string_t list_of_items; 2117 }; 2118 2119 static int 2120 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2121 uint16_t nb_entries, 2122 char *str) 2123 { 2124 uint32_t size; 2125 const char *p, *p0 = str; 2126 char s[256]; 2127 char *end; 2128 char *str_fld[8]; 2129 uint16_t i; 2130 uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) / 2131 RTE_RETA_GROUP_SIZE; 2132 int ret; 2133 2134 p = strchr(p0, '('); 2135 if (p == NULL) 2136 return -1; 2137 p++; 2138 p0 = strchr(p, ')'); 2139 if (p0 == NULL) 2140 return -1; 2141 size = p0 - p; 2142 if (size >= sizeof(s)) { 2143 printf("The string size exceeds the internal buffer size\n"); 2144 return -1; 2145 } 2146 snprintf(s, sizeof(s), "%.*s", size, p); 2147 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 2148 if (ret <= 0 || ret != num) { 2149 printf("The bits of masks do not match the number of " 2150 "reta entries: %u\n", num); 2151 return -1; 2152 } 2153 for (i = 0; i < ret; i++) 2154 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0); 2155 2156 return 0; 2157 } 2158 2159 static void 2160 cmd_showport_reta_parsed(void *parsed_result, 2161 __attribute__((unused)) struct cmdline *cl, 2162 __attribute__((unused)) void *data) 2163 { 2164 struct cmd_showport_reta *res = parsed_result; 2165 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2166 struct rte_eth_dev_info dev_info; 2167 2168 memset(&dev_info, 0, sizeof(dev_info)); 2169 rte_eth_dev_info_get(res->port_id, &dev_info); 2170 if (dev_info.reta_size == 0 || res->size != dev_info.reta_size || 2171 res->size > ETH_RSS_RETA_SIZE_512) { 2172 printf("Invalid redirection table size: %u\n", res->size); 2173 return; 2174 } 2175 2176 memset(reta_conf, 0, sizeof(reta_conf)); 2177 if (showport_parse_reta_config(reta_conf, res->size, 2178 res->list_of_items) < 0) { 2179 printf("Invalid string: %s for reta masks\n", 2180 res->list_of_items); 2181 return; 2182 } 2183 port_rss_reta_info(res->port_id, reta_conf, res->size); 2184 } 2185 2186 cmdline_parse_token_string_t cmd_showport_reta_show = 2187 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 2188 cmdline_parse_token_string_t cmd_showport_reta_port = 2189 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 2190 cmdline_parse_token_num_t cmd_showport_reta_port_id = 2191 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); 2192 cmdline_parse_token_string_t cmd_showport_reta_rss = 2193 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 2194 cmdline_parse_token_string_t cmd_showport_reta_reta = 2195 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 2196 cmdline_parse_token_num_t cmd_showport_reta_size = 2197 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16); 2198 cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 2199 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 2200 list_of_items, NULL); 2201 2202 cmdline_parse_inst_t cmd_showport_reta = { 2203 .f = cmd_showport_reta_parsed, 2204 .data = NULL, 2205 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 2206 .tokens = { 2207 (void *)&cmd_showport_reta_show, 2208 (void *)&cmd_showport_reta_port, 2209 (void *)&cmd_showport_reta_port_id, 2210 (void *)&cmd_showport_reta_rss, 2211 (void *)&cmd_showport_reta_reta, 2212 (void *)&cmd_showport_reta_size, 2213 (void *)&cmd_showport_reta_list_of_items, 2214 NULL, 2215 }, 2216 }; 2217 2218 /* *** Show RSS hash configuration *** */ 2219 struct cmd_showport_rss_hash { 2220 cmdline_fixed_string_t show; 2221 cmdline_fixed_string_t port; 2222 uint8_t port_id; 2223 cmdline_fixed_string_t rss_hash; 2224 cmdline_fixed_string_t rss_type; 2225 cmdline_fixed_string_t key; /* optional argument */ 2226 }; 2227 2228 static void cmd_showport_rss_hash_parsed(void *parsed_result, 2229 __attribute__((unused)) struct cmdline *cl, 2230 void *show_rss_key) 2231 { 2232 struct cmd_showport_rss_hash *res = parsed_result; 2233 2234 port_rss_hash_conf_show(res->port_id, res->rss_type, 2235 show_rss_key != NULL); 2236 } 2237 2238 cmdline_parse_token_string_t cmd_showport_rss_hash_show = 2239 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 2240 cmdline_parse_token_string_t cmd_showport_rss_hash_port = 2241 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 2242 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 2243 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8); 2244 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 2245 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 2246 "rss-hash"); 2247 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info = 2248 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type, 2249 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2250 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2251 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2252 "ipv6-tcp-ex#ipv6-udp-ex"); 2253 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 2254 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 2255 2256 cmdline_parse_inst_t cmd_showport_rss_hash = { 2257 .f = cmd_showport_rss_hash_parsed, 2258 .data = NULL, 2259 .help_str = "show port <port_id> rss-hash " 2260 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2261 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2262 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex", 2263 .tokens = { 2264 (void *)&cmd_showport_rss_hash_show, 2265 (void *)&cmd_showport_rss_hash_port, 2266 (void *)&cmd_showport_rss_hash_port_id, 2267 (void *)&cmd_showport_rss_hash_rss_hash, 2268 (void *)&cmd_showport_rss_hash_rss_hash_info, 2269 NULL, 2270 }, 2271 }; 2272 2273 cmdline_parse_inst_t cmd_showport_rss_hash_key = { 2274 .f = cmd_showport_rss_hash_parsed, 2275 .data = (void *)1, 2276 .help_str = "show port <port_id> rss-hash " 2277 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2278 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2279 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key", 2280 .tokens = { 2281 (void *)&cmd_showport_rss_hash_show, 2282 (void *)&cmd_showport_rss_hash_port, 2283 (void *)&cmd_showport_rss_hash_port_id, 2284 (void *)&cmd_showport_rss_hash_rss_hash, 2285 (void *)&cmd_showport_rss_hash_rss_hash_info, 2286 (void *)&cmd_showport_rss_hash_rss_key, 2287 NULL, 2288 }, 2289 }; 2290 2291 /* *** Configure DCB *** */ 2292 struct cmd_config_dcb { 2293 cmdline_fixed_string_t port; 2294 cmdline_fixed_string_t config; 2295 uint8_t port_id; 2296 cmdline_fixed_string_t dcb; 2297 cmdline_fixed_string_t vt; 2298 cmdline_fixed_string_t vt_en; 2299 uint8_t num_tcs; 2300 cmdline_fixed_string_t pfc; 2301 cmdline_fixed_string_t pfc_en; 2302 }; 2303 2304 static void 2305 cmd_config_dcb_parsed(void *parsed_result, 2306 __attribute__((unused)) struct cmdline *cl, 2307 __attribute__((unused)) void *data) 2308 { 2309 struct cmd_config_dcb *res = parsed_result; 2310 portid_t port_id = res->port_id; 2311 struct rte_port *port; 2312 uint8_t pfc_en; 2313 int ret; 2314 2315 port = &ports[port_id]; 2316 /** Check if the port is not started **/ 2317 if (port->port_status != RTE_PORT_STOPPED) { 2318 printf("Please stop port %d first\n", port_id); 2319 return; 2320 } 2321 2322 if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) { 2323 printf("The invalid number of traffic class," 2324 " only 4 or 8 allowed.\n"); 2325 return; 2326 } 2327 2328 if (nb_fwd_lcores < res->num_tcs) { 2329 printf("nb_cores shouldn't be less than number of TCs.\n"); 2330 return; 2331 } 2332 if (!strncmp(res->pfc_en, "on", 2)) 2333 pfc_en = 1; 2334 else 2335 pfc_en = 0; 2336 2337 /* DCB in VT mode */ 2338 if (!strncmp(res->vt_en, "on", 2)) 2339 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 2340 (enum rte_eth_nb_tcs)res->num_tcs, 2341 pfc_en); 2342 else 2343 ret = init_port_dcb_config(port_id, DCB_ENABLED, 2344 (enum rte_eth_nb_tcs)res->num_tcs, 2345 pfc_en); 2346 2347 2348 if (ret != 0) { 2349 printf("Cannot initialize network ports.\n"); 2350 return; 2351 } 2352 2353 cmd_reconfig_device_queue(port_id, 1, 1); 2354 } 2355 2356 cmdline_parse_token_string_t cmd_config_dcb_port = 2357 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 2358 cmdline_parse_token_string_t cmd_config_dcb_config = 2359 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 2360 cmdline_parse_token_num_t cmd_config_dcb_port_id = 2361 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); 2362 cmdline_parse_token_string_t cmd_config_dcb_dcb = 2363 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 2364 cmdline_parse_token_string_t cmd_config_dcb_vt = 2365 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 2366 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 2367 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 2368 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 2369 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 2370 cmdline_parse_token_string_t cmd_config_dcb_pfc= 2371 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 2372 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 2373 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 2374 2375 cmdline_parse_inst_t cmd_config_dcb = { 2376 .f = cmd_config_dcb_parsed, 2377 .data = NULL, 2378 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 2379 .tokens = { 2380 (void *)&cmd_config_dcb_port, 2381 (void *)&cmd_config_dcb_config, 2382 (void *)&cmd_config_dcb_port_id, 2383 (void *)&cmd_config_dcb_dcb, 2384 (void *)&cmd_config_dcb_vt, 2385 (void *)&cmd_config_dcb_vt_en, 2386 (void *)&cmd_config_dcb_num_tcs, 2387 (void *)&cmd_config_dcb_pfc, 2388 (void *)&cmd_config_dcb_pfc_en, 2389 NULL, 2390 }, 2391 }; 2392 2393 /* *** configure number of packets per burst *** */ 2394 struct cmd_config_burst { 2395 cmdline_fixed_string_t port; 2396 cmdline_fixed_string_t keyword; 2397 cmdline_fixed_string_t all; 2398 cmdline_fixed_string_t name; 2399 uint16_t value; 2400 }; 2401 2402 static void 2403 cmd_config_burst_parsed(void *parsed_result, 2404 __attribute__((unused)) struct cmdline *cl, 2405 __attribute__((unused)) void *data) 2406 { 2407 struct cmd_config_burst *res = parsed_result; 2408 2409 if (!all_ports_stopped()) { 2410 printf("Please stop all ports first\n"); 2411 return; 2412 } 2413 2414 if (!strcmp(res->name, "burst")) { 2415 if (res->value < 1 || res->value > MAX_PKT_BURST) { 2416 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 2417 return; 2418 } 2419 nb_pkt_per_burst = res->value; 2420 } else { 2421 printf("Unknown parameter\n"); 2422 return; 2423 } 2424 2425 init_port_config(); 2426 2427 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2428 } 2429 2430 cmdline_parse_token_string_t cmd_config_burst_port = 2431 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 2432 cmdline_parse_token_string_t cmd_config_burst_keyword = 2433 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 2434 cmdline_parse_token_string_t cmd_config_burst_all = 2435 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 2436 cmdline_parse_token_string_t cmd_config_burst_name = 2437 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 2438 cmdline_parse_token_num_t cmd_config_burst_value = 2439 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 2440 2441 cmdline_parse_inst_t cmd_config_burst = { 2442 .f = cmd_config_burst_parsed, 2443 .data = NULL, 2444 .help_str = "port config all burst <value>", 2445 .tokens = { 2446 (void *)&cmd_config_burst_port, 2447 (void *)&cmd_config_burst_keyword, 2448 (void *)&cmd_config_burst_all, 2449 (void *)&cmd_config_burst_name, 2450 (void *)&cmd_config_burst_value, 2451 NULL, 2452 }, 2453 }; 2454 2455 /* *** configure rx/tx queues *** */ 2456 struct cmd_config_thresh { 2457 cmdline_fixed_string_t port; 2458 cmdline_fixed_string_t keyword; 2459 cmdline_fixed_string_t all; 2460 cmdline_fixed_string_t name; 2461 uint8_t value; 2462 }; 2463 2464 static void 2465 cmd_config_thresh_parsed(void *parsed_result, 2466 __attribute__((unused)) struct cmdline *cl, 2467 __attribute__((unused)) void *data) 2468 { 2469 struct cmd_config_thresh *res = parsed_result; 2470 2471 if (!all_ports_stopped()) { 2472 printf("Please stop all ports first\n"); 2473 return; 2474 } 2475 2476 if (!strcmp(res->name, "txpt")) 2477 tx_pthresh = res->value; 2478 else if(!strcmp(res->name, "txht")) 2479 tx_hthresh = res->value; 2480 else if(!strcmp(res->name, "txwt")) 2481 tx_wthresh = res->value; 2482 else if(!strcmp(res->name, "rxpt")) 2483 rx_pthresh = res->value; 2484 else if(!strcmp(res->name, "rxht")) 2485 rx_hthresh = res->value; 2486 else if(!strcmp(res->name, "rxwt")) 2487 rx_wthresh = res->value; 2488 else { 2489 printf("Unknown parameter\n"); 2490 return; 2491 } 2492 2493 init_port_config(); 2494 2495 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2496 } 2497 2498 cmdline_parse_token_string_t cmd_config_thresh_port = 2499 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 2500 cmdline_parse_token_string_t cmd_config_thresh_keyword = 2501 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 2502 cmdline_parse_token_string_t cmd_config_thresh_all = 2503 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 2504 cmdline_parse_token_string_t cmd_config_thresh_name = 2505 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 2506 "txpt#txht#txwt#rxpt#rxht#rxwt"); 2507 cmdline_parse_token_num_t cmd_config_thresh_value = 2508 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 2509 2510 cmdline_parse_inst_t cmd_config_thresh = { 2511 .f = cmd_config_thresh_parsed, 2512 .data = NULL, 2513 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 2514 .tokens = { 2515 (void *)&cmd_config_thresh_port, 2516 (void *)&cmd_config_thresh_keyword, 2517 (void *)&cmd_config_thresh_all, 2518 (void *)&cmd_config_thresh_name, 2519 (void *)&cmd_config_thresh_value, 2520 NULL, 2521 }, 2522 }; 2523 2524 /* *** configure free/rs threshold *** */ 2525 struct cmd_config_threshold { 2526 cmdline_fixed_string_t port; 2527 cmdline_fixed_string_t keyword; 2528 cmdline_fixed_string_t all; 2529 cmdline_fixed_string_t name; 2530 uint16_t value; 2531 }; 2532 2533 static void 2534 cmd_config_threshold_parsed(void *parsed_result, 2535 __attribute__((unused)) struct cmdline *cl, 2536 __attribute__((unused)) void *data) 2537 { 2538 struct cmd_config_threshold *res = parsed_result; 2539 2540 if (!all_ports_stopped()) { 2541 printf("Please stop all ports first\n"); 2542 return; 2543 } 2544 2545 if (!strcmp(res->name, "txfreet")) 2546 tx_free_thresh = res->value; 2547 else if (!strcmp(res->name, "txrst")) 2548 tx_rs_thresh = res->value; 2549 else if (!strcmp(res->name, "rxfreet")) 2550 rx_free_thresh = res->value; 2551 else { 2552 printf("Unknown parameter\n"); 2553 return; 2554 } 2555 2556 init_port_config(); 2557 2558 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2559 } 2560 2561 cmdline_parse_token_string_t cmd_config_threshold_port = 2562 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 2563 cmdline_parse_token_string_t cmd_config_threshold_keyword = 2564 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 2565 "config"); 2566 cmdline_parse_token_string_t cmd_config_threshold_all = 2567 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 2568 cmdline_parse_token_string_t cmd_config_threshold_name = 2569 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 2570 "txfreet#txrst#rxfreet"); 2571 cmdline_parse_token_num_t cmd_config_threshold_value = 2572 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 2573 2574 cmdline_parse_inst_t cmd_config_threshold = { 2575 .f = cmd_config_threshold_parsed, 2576 .data = NULL, 2577 .help_str = "port config all txfreet|txrst|rxfreet <value>", 2578 .tokens = { 2579 (void *)&cmd_config_threshold_port, 2580 (void *)&cmd_config_threshold_keyword, 2581 (void *)&cmd_config_threshold_all, 2582 (void *)&cmd_config_threshold_name, 2583 (void *)&cmd_config_threshold_value, 2584 NULL, 2585 }, 2586 }; 2587 2588 /* *** stop *** */ 2589 struct cmd_stop_result { 2590 cmdline_fixed_string_t stop; 2591 }; 2592 2593 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 2594 __attribute__((unused)) struct cmdline *cl, 2595 __attribute__((unused)) void *data) 2596 { 2597 stop_packet_forwarding(); 2598 } 2599 2600 cmdline_parse_token_string_t cmd_stop_stop = 2601 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 2602 2603 cmdline_parse_inst_t cmd_stop = { 2604 .f = cmd_stop_parsed, 2605 .data = NULL, 2606 .help_str = "stop: Stop packet forwarding", 2607 .tokens = { 2608 (void *)&cmd_stop_stop, 2609 NULL, 2610 }, 2611 }; 2612 2613 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 2614 2615 unsigned int 2616 parse_item_list(char* str, const char* item_name, unsigned int max_items, 2617 unsigned int *parsed_items, int check_unique_values) 2618 { 2619 unsigned int nb_item; 2620 unsigned int value; 2621 unsigned int i; 2622 unsigned int j; 2623 int value_ok; 2624 char c; 2625 2626 /* 2627 * First parse all items in the list and store their value. 2628 */ 2629 value = 0; 2630 nb_item = 0; 2631 value_ok = 0; 2632 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 2633 c = str[i]; 2634 if ((c >= '0') && (c <= '9')) { 2635 value = (unsigned int) (value * 10 + (c - '0')); 2636 value_ok = 1; 2637 continue; 2638 } 2639 if (c != ',') { 2640 printf("character %c is not a decimal digit\n", c); 2641 return 0; 2642 } 2643 if (! value_ok) { 2644 printf("No valid value before comma\n"); 2645 return 0; 2646 } 2647 if (nb_item < max_items) { 2648 parsed_items[nb_item] = value; 2649 value_ok = 0; 2650 value = 0; 2651 } 2652 nb_item++; 2653 } 2654 if (nb_item >= max_items) { 2655 printf("Number of %s = %u > %u (maximum items)\n", 2656 item_name, nb_item + 1, max_items); 2657 return 0; 2658 } 2659 parsed_items[nb_item++] = value; 2660 if (! check_unique_values) 2661 return nb_item; 2662 2663 /* 2664 * Then, check that all values in the list are differents. 2665 * No optimization here... 2666 */ 2667 for (i = 0; i < nb_item; i++) { 2668 for (j = i + 1; j < nb_item; j++) { 2669 if (parsed_items[j] == parsed_items[i]) { 2670 printf("duplicated %s %u at index %u and %u\n", 2671 item_name, parsed_items[i], i, j); 2672 return 0; 2673 } 2674 } 2675 } 2676 return nb_item; 2677 } 2678 2679 struct cmd_set_list_result { 2680 cmdline_fixed_string_t cmd_keyword; 2681 cmdline_fixed_string_t list_name; 2682 cmdline_fixed_string_t list_of_items; 2683 }; 2684 2685 static void cmd_set_list_parsed(void *parsed_result, 2686 __attribute__((unused)) struct cmdline *cl, 2687 __attribute__((unused)) void *data) 2688 { 2689 struct cmd_set_list_result *res; 2690 union { 2691 unsigned int lcorelist[RTE_MAX_LCORE]; 2692 unsigned int portlist[RTE_MAX_ETHPORTS]; 2693 } parsed_items; 2694 unsigned int nb_item; 2695 2696 if (test_done == 0) { 2697 printf("Please stop forwarding first\n"); 2698 return; 2699 } 2700 2701 res = parsed_result; 2702 if (!strcmp(res->list_name, "corelist")) { 2703 nb_item = parse_item_list(res->list_of_items, "core", 2704 RTE_MAX_LCORE, 2705 parsed_items.lcorelist, 1); 2706 if (nb_item > 0) { 2707 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 2708 fwd_config_setup(); 2709 } 2710 return; 2711 } 2712 if (!strcmp(res->list_name, "portlist")) { 2713 nb_item = parse_item_list(res->list_of_items, "port", 2714 RTE_MAX_ETHPORTS, 2715 parsed_items.portlist, 1); 2716 if (nb_item > 0) { 2717 set_fwd_ports_list(parsed_items.portlist, nb_item); 2718 fwd_config_setup(); 2719 } 2720 } 2721 } 2722 2723 cmdline_parse_token_string_t cmd_set_list_keyword = 2724 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 2725 "set"); 2726 cmdline_parse_token_string_t cmd_set_list_name = 2727 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 2728 "corelist#portlist"); 2729 cmdline_parse_token_string_t cmd_set_list_of_items = 2730 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 2731 NULL); 2732 2733 cmdline_parse_inst_t cmd_set_fwd_list = { 2734 .f = cmd_set_list_parsed, 2735 .data = NULL, 2736 .help_str = "set corelist|portlist <list0[,list1]*>", 2737 .tokens = { 2738 (void *)&cmd_set_list_keyword, 2739 (void *)&cmd_set_list_name, 2740 (void *)&cmd_set_list_of_items, 2741 NULL, 2742 }, 2743 }; 2744 2745 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 2746 2747 struct cmd_setmask_result { 2748 cmdline_fixed_string_t set; 2749 cmdline_fixed_string_t mask; 2750 uint64_t hexavalue; 2751 }; 2752 2753 static void cmd_set_mask_parsed(void *parsed_result, 2754 __attribute__((unused)) struct cmdline *cl, 2755 __attribute__((unused)) void *data) 2756 { 2757 struct cmd_setmask_result *res = parsed_result; 2758 2759 if (test_done == 0) { 2760 printf("Please stop forwarding first\n"); 2761 return; 2762 } 2763 if (!strcmp(res->mask, "coremask")) { 2764 set_fwd_lcores_mask(res->hexavalue); 2765 fwd_config_setup(); 2766 } else if (!strcmp(res->mask, "portmask")) { 2767 set_fwd_ports_mask(res->hexavalue); 2768 fwd_config_setup(); 2769 } 2770 } 2771 2772 cmdline_parse_token_string_t cmd_setmask_set = 2773 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 2774 cmdline_parse_token_string_t cmd_setmask_mask = 2775 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 2776 "coremask#portmask"); 2777 cmdline_parse_token_num_t cmd_setmask_value = 2778 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 2779 2780 cmdline_parse_inst_t cmd_set_fwd_mask = { 2781 .f = cmd_set_mask_parsed, 2782 .data = NULL, 2783 .help_str = "set coremask|portmask <hexadecimal value>", 2784 .tokens = { 2785 (void *)&cmd_setmask_set, 2786 (void *)&cmd_setmask_mask, 2787 (void *)&cmd_setmask_value, 2788 NULL, 2789 }, 2790 }; 2791 2792 /* 2793 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 2794 */ 2795 struct cmd_set_result { 2796 cmdline_fixed_string_t set; 2797 cmdline_fixed_string_t what; 2798 uint16_t value; 2799 }; 2800 2801 static void cmd_set_parsed(void *parsed_result, 2802 __attribute__((unused)) struct cmdline *cl, 2803 __attribute__((unused)) void *data) 2804 { 2805 struct cmd_set_result *res = parsed_result; 2806 if (!strcmp(res->what, "nbport")) { 2807 set_fwd_ports_number(res->value); 2808 fwd_config_setup(); 2809 } else if (!strcmp(res->what, "nbcore")) { 2810 set_fwd_lcores_number(res->value); 2811 fwd_config_setup(); 2812 } else if (!strcmp(res->what, "burst")) 2813 set_nb_pkt_per_burst(res->value); 2814 else if (!strcmp(res->what, "verbose")) 2815 set_verbose_level(res->value); 2816 } 2817 2818 cmdline_parse_token_string_t cmd_set_set = 2819 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 2820 cmdline_parse_token_string_t cmd_set_what = 2821 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 2822 "nbport#nbcore#burst#verbose"); 2823 cmdline_parse_token_num_t cmd_set_value = 2824 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 2825 2826 cmdline_parse_inst_t cmd_set_numbers = { 2827 .f = cmd_set_parsed, 2828 .data = NULL, 2829 .help_str = "set nbport|nbcore|burst|verbose <value>", 2830 .tokens = { 2831 (void *)&cmd_set_set, 2832 (void *)&cmd_set_what, 2833 (void *)&cmd_set_value, 2834 NULL, 2835 }, 2836 }; 2837 2838 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 2839 2840 struct cmd_set_txpkts_result { 2841 cmdline_fixed_string_t cmd_keyword; 2842 cmdline_fixed_string_t txpkts; 2843 cmdline_fixed_string_t seg_lengths; 2844 }; 2845 2846 static void 2847 cmd_set_txpkts_parsed(void *parsed_result, 2848 __attribute__((unused)) struct cmdline *cl, 2849 __attribute__((unused)) void *data) 2850 { 2851 struct cmd_set_txpkts_result *res; 2852 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 2853 unsigned int nb_segs; 2854 2855 res = parsed_result; 2856 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 2857 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 2858 if (nb_segs > 0) 2859 set_tx_pkt_segments(seg_lengths, nb_segs); 2860 } 2861 2862 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 2863 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2864 cmd_keyword, "set"); 2865 cmdline_parse_token_string_t cmd_set_txpkts_name = 2866 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2867 txpkts, "txpkts"); 2868 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 2869 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2870 seg_lengths, NULL); 2871 2872 cmdline_parse_inst_t cmd_set_txpkts = { 2873 .f = cmd_set_txpkts_parsed, 2874 .data = NULL, 2875 .help_str = "set txpkts <len0[,len1]*>", 2876 .tokens = { 2877 (void *)&cmd_set_txpkts_keyword, 2878 (void *)&cmd_set_txpkts_name, 2879 (void *)&cmd_set_txpkts_lengths, 2880 NULL, 2881 }, 2882 }; 2883 2884 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 2885 2886 struct cmd_set_txsplit_result { 2887 cmdline_fixed_string_t cmd_keyword; 2888 cmdline_fixed_string_t txsplit; 2889 cmdline_fixed_string_t mode; 2890 }; 2891 2892 static void 2893 cmd_set_txsplit_parsed(void *parsed_result, 2894 __attribute__((unused)) struct cmdline *cl, 2895 __attribute__((unused)) void *data) 2896 { 2897 struct cmd_set_txsplit_result *res; 2898 2899 res = parsed_result; 2900 set_tx_pkt_split(res->mode); 2901 } 2902 2903 cmdline_parse_token_string_t cmd_set_txsplit_keyword = 2904 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2905 cmd_keyword, "set"); 2906 cmdline_parse_token_string_t cmd_set_txsplit_name = 2907 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2908 txsplit, "txsplit"); 2909 cmdline_parse_token_string_t cmd_set_txsplit_mode = 2910 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2911 mode, NULL); 2912 2913 cmdline_parse_inst_t cmd_set_txsplit = { 2914 .f = cmd_set_txsplit_parsed, 2915 .data = NULL, 2916 .help_str = "set txsplit on|off|rand", 2917 .tokens = { 2918 (void *)&cmd_set_txsplit_keyword, 2919 (void *)&cmd_set_txsplit_name, 2920 (void *)&cmd_set_txsplit_mode, 2921 NULL, 2922 }, 2923 }; 2924 2925 /* *** CONFIG TX QUEUE FLAGS *** */ 2926 2927 struct cmd_config_txqflags_result { 2928 cmdline_fixed_string_t port; 2929 cmdline_fixed_string_t config; 2930 cmdline_fixed_string_t all; 2931 cmdline_fixed_string_t what; 2932 int32_t hexvalue; 2933 }; 2934 2935 static void cmd_config_txqflags_parsed(void *parsed_result, 2936 __attribute__((unused)) struct cmdline *cl, 2937 __attribute__((unused)) void *data) 2938 { 2939 struct cmd_config_txqflags_result *res = parsed_result; 2940 2941 if (!all_ports_stopped()) { 2942 printf("Please stop all ports first\n"); 2943 return; 2944 } 2945 2946 if (strcmp(res->what, "txqflags")) { 2947 printf("Unknown parameter\n"); 2948 return; 2949 } 2950 2951 if (res->hexvalue >= 0) { 2952 txq_flags = res->hexvalue; 2953 } else { 2954 printf("txqflags must be >= 0\n"); 2955 return; 2956 } 2957 2958 init_port_config(); 2959 2960 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2961 } 2962 2963 cmdline_parse_token_string_t cmd_config_txqflags_port = 2964 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port, 2965 "port"); 2966 cmdline_parse_token_string_t cmd_config_txqflags_config = 2967 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config, 2968 "config"); 2969 cmdline_parse_token_string_t cmd_config_txqflags_all = 2970 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all, 2971 "all"); 2972 cmdline_parse_token_string_t cmd_config_txqflags_what = 2973 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what, 2974 "txqflags"); 2975 cmdline_parse_token_num_t cmd_config_txqflags_value = 2976 TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result, 2977 hexvalue, INT32); 2978 2979 cmdline_parse_inst_t cmd_config_txqflags = { 2980 .f = cmd_config_txqflags_parsed, 2981 .data = NULL, 2982 .help_str = "port config all txqflags <value>", 2983 .tokens = { 2984 (void *)&cmd_config_txqflags_port, 2985 (void *)&cmd_config_txqflags_config, 2986 (void *)&cmd_config_txqflags_all, 2987 (void *)&cmd_config_txqflags_what, 2988 (void *)&cmd_config_txqflags_value, 2989 NULL, 2990 }, 2991 }; 2992 2993 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 2994 struct cmd_rx_vlan_filter_all_result { 2995 cmdline_fixed_string_t rx_vlan; 2996 cmdline_fixed_string_t what; 2997 cmdline_fixed_string_t all; 2998 uint8_t port_id; 2999 }; 3000 3001 static void 3002 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 3003 __attribute__((unused)) struct cmdline *cl, 3004 __attribute__((unused)) void *data) 3005 { 3006 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 3007 3008 if (!strcmp(res->what, "add")) 3009 rx_vlan_all_filter_set(res->port_id, 1); 3010 else 3011 rx_vlan_all_filter_set(res->port_id, 0); 3012 } 3013 3014 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 3015 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3016 rx_vlan, "rx_vlan"); 3017 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 3018 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3019 what, "add#rm"); 3020 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 3021 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3022 all, "all"); 3023 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 3024 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3025 port_id, UINT8); 3026 3027 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 3028 .f = cmd_rx_vlan_filter_all_parsed, 3029 .data = NULL, 3030 .help_str = "rx_vlan add|rm all <port_id>: " 3031 "Add/Remove all identifiers to/from the set of VLAN " 3032 "identifiers filtered by a port", 3033 .tokens = { 3034 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 3035 (void *)&cmd_rx_vlan_filter_all_what, 3036 (void *)&cmd_rx_vlan_filter_all_all, 3037 (void *)&cmd_rx_vlan_filter_all_portid, 3038 NULL, 3039 }, 3040 }; 3041 3042 /* *** VLAN OFFLOAD SET ON A PORT *** */ 3043 struct cmd_vlan_offload_result { 3044 cmdline_fixed_string_t vlan; 3045 cmdline_fixed_string_t set; 3046 cmdline_fixed_string_t vlan_type; 3047 cmdline_fixed_string_t what; 3048 cmdline_fixed_string_t on; 3049 cmdline_fixed_string_t port_id; 3050 }; 3051 3052 static void 3053 cmd_vlan_offload_parsed(void *parsed_result, 3054 __attribute__((unused)) struct cmdline *cl, 3055 __attribute__((unused)) void *data) 3056 { 3057 int on; 3058 struct cmd_vlan_offload_result *res = parsed_result; 3059 char *str; 3060 int i, len = 0; 3061 portid_t port_id = 0; 3062 unsigned int tmp; 3063 3064 str = res->port_id; 3065 len = strnlen(str, STR_TOKEN_SIZE); 3066 i = 0; 3067 /* Get port_id first */ 3068 while(i < len){ 3069 if(str[i] == ',') 3070 break; 3071 3072 i++; 3073 } 3074 str[i]='\0'; 3075 tmp = strtoul(str, NULL, 0); 3076 /* If port_id greater that what portid_t can represent, return */ 3077 if(tmp >= RTE_MAX_ETHPORTS) 3078 return; 3079 port_id = (portid_t)tmp; 3080 3081 if (!strcmp(res->on, "on")) 3082 on = 1; 3083 else 3084 on = 0; 3085 3086 if (!strcmp(res->what, "strip")) 3087 rx_vlan_strip_set(port_id, on); 3088 else if(!strcmp(res->what, "stripq")){ 3089 uint16_t queue_id = 0; 3090 3091 /* No queue_id, return */ 3092 if(i + 1 >= len) { 3093 printf("must specify (port,queue_id)\n"); 3094 return; 3095 } 3096 tmp = strtoul(str + i + 1, NULL, 0); 3097 /* If queue_id greater that what 16-bits can represent, return */ 3098 if(tmp > 0xffff) 3099 return; 3100 3101 queue_id = (uint16_t)tmp; 3102 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 3103 } 3104 else if (!strcmp(res->what, "filter")) 3105 rx_vlan_filter_set(port_id, on); 3106 else 3107 vlan_extend_set(port_id, on); 3108 3109 return; 3110 } 3111 3112 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 3113 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3114 vlan, "vlan"); 3115 cmdline_parse_token_string_t cmd_vlan_offload_set = 3116 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3117 set, "set"); 3118 cmdline_parse_token_string_t cmd_vlan_offload_what = 3119 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3120 what, "strip#filter#qinq#stripq"); 3121 cmdline_parse_token_string_t cmd_vlan_offload_on = 3122 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3123 on, "on#off"); 3124 cmdline_parse_token_string_t cmd_vlan_offload_portid = 3125 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3126 port_id, NULL); 3127 3128 cmdline_parse_inst_t cmd_vlan_offload = { 3129 .f = cmd_vlan_offload_parsed, 3130 .data = NULL, 3131 .help_str = "vlan set strip|filter|qinq|stripq on|off " 3132 "<port_id[,queue_id]>: " 3133 "Filter/Strip for rx side qinq(extended) for both rx/tx sides", 3134 .tokens = { 3135 (void *)&cmd_vlan_offload_vlan, 3136 (void *)&cmd_vlan_offload_set, 3137 (void *)&cmd_vlan_offload_what, 3138 (void *)&cmd_vlan_offload_on, 3139 (void *)&cmd_vlan_offload_portid, 3140 NULL, 3141 }, 3142 }; 3143 3144 /* *** VLAN TPID SET ON A PORT *** */ 3145 struct cmd_vlan_tpid_result { 3146 cmdline_fixed_string_t vlan; 3147 cmdline_fixed_string_t set; 3148 cmdline_fixed_string_t vlan_type; 3149 cmdline_fixed_string_t what; 3150 uint16_t tp_id; 3151 uint8_t port_id; 3152 }; 3153 3154 static void 3155 cmd_vlan_tpid_parsed(void *parsed_result, 3156 __attribute__((unused)) struct cmdline *cl, 3157 __attribute__((unused)) void *data) 3158 { 3159 struct cmd_vlan_tpid_result *res = parsed_result; 3160 enum rte_vlan_type vlan_type; 3161 3162 if (!strcmp(res->vlan_type, "inner")) 3163 vlan_type = ETH_VLAN_TYPE_INNER; 3164 else if (!strcmp(res->vlan_type, "outer")) 3165 vlan_type = ETH_VLAN_TYPE_OUTER; 3166 else { 3167 printf("Unknown vlan type\n"); 3168 return; 3169 } 3170 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 3171 } 3172 3173 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 3174 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3175 vlan, "vlan"); 3176 cmdline_parse_token_string_t cmd_vlan_tpid_set = 3177 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3178 set, "set"); 3179 cmdline_parse_token_string_t cmd_vlan_type = 3180 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3181 vlan_type, "inner#outer"); 3182 cmdline_parse_token_string_t cmd_vlan_tpid_what = 3183 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3184 what, "tpid"); 3185 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 3186 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3187 tp_id, UINT16); 3188 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 3189 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3190 port_id, UINT8); 3191 3192 cmdline_parse_inst_t cmd_vlan_tpid = { 3193 .f = cmd_vlan_tpid_parsed, 3194 .data = NULL, 3195 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 3196 "Set the VLAN Ether type", 3197 .tokens = { 3198 (void *)&cmd_vlan_tpid_vlan, 3199 (void *)&cmd_vlan_tpid_set, 3200 (void *)&cmd_vlan_type, 3201 (void *)&cmd_vlan_tpid_what, 3202 (void *)&cmd_vlan_tpid_tpid, 3203 (void *)&cmd_vlan_tpid_portid, 3204 NULL, 3205 }, 3206 }; 3207 3208 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 3209 struct cmd_rx_vlan_filter_result { 3210 cmdline_fixed_string_t rx_vlan; 3211 cmdline_fixed_string_t what; 3212 uint16_t vlan_id; 3213 uint8_t port_id; 3214 }; 3215 3216 static void 3217 cmd_rx_vlan_filter_parsed(void *parsed_result, 3218 __attribute__((unused)) struct cmdline *cl, 3219 __attribute__((unused)) void *data) 3220 { 3221 struct cmd_rx_vlan_filter_result *res = parsed_result; 3222 3223 if (!strcmp(res->what, "add")) 3224 rx_vft_set(res->port_id, res->vlan_id, 1); 3225 else 3226 rx_vft_set(res->port_id, res->vlan_id, 0); 3227 } 3228 3229 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 3230 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3231 rx_vlan, "rx_vlan"); 3232 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 3233 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3234 what, "add#rm"); 3235 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 3236 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3237 vlan_id, UINT16); 3238 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 3239 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3240 port_id, UINT8); 3241 3242 cmdline_parse_inst_t cmd_rx_vlan_filter = { 3243 .f = cmd_rx_vlan_filter_parsed, 3244 .data = NULL, 3245 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 3246 "Add/Remove a VLAN identifier to/from the set of VLAN " 3247 "identifiers filtered by a port", 3248 .tokens = { 3249 (void *)&cmd_rx_vlan_filter_rx_vlan, 3250 (void *)&cmd_rx_vlan_filter_what, 3251 (void *)&cmd_rx_vlan_filter_vlanid, 3252 (void *)&cmd_rx_vlan_filter_portid, 3253 NULL, 3254 }, 3255 }; 3256 3257 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3258 struct cmd_tx_vlan_set_result { 3259 cmdline_fixed_string_t tx_vlan; 3260 cmdline_fixed_string_t set; 3261 uint8_t port_id; 3262 uint16_t vlan_id; 3263 }; 3264 3265 static void 3266 cmd_tx_vlan_set_parsed(void *parsed_result, 3267 __attribute__((unused)) struct cmdline *cl, 3268 __attribute__((unused)) void *data) 3269 { 3270 struct cmd_tx_vlan_set_result *res = parsed_result; 3271 3272 tx_vlan_set(res->port_id, res->vlan_id); 3273 } 3274 3275 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 3276 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3277 tx_vlan, "tx_vlan"); 3278 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 3279 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3280 set, "set"); 3281 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 3282 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3283 port_id, UINT8); 3284 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 3285 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3286 vlan_id, UINT16); 3287 3288 cmdline_parse_inst_t cmd_tx_vlan_set = { 3289 .f = cmd_tx_vlan_set_parsed, 3290 .data = NULL, 3291 .help_str = "tx_vlan set <port_id> <vlan_id>: " 3292 "Enable hardware insertion of a single VLAN header " 3293 "with a given TAG Identifier in packets sent on a port", 3294 .tokens = { 3295 (void *)&cmd_tx_vlan_set_tx_vlan, 3296 (void *)&cmd_tx_vlan_set_set, 3297 (void *)&cmd_tx_vlan_set_portid, 3298 (void *)&cmd_tx_vlan_set_vlanid, 3299 NULL, 3300 }, 3301 }; 3302 3303 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 3304 struct cmd_tx_vlan_set_qinq_result { 3305 cmdline_fixed_string_t tx_vlan; 3306 cmdline_fixed_string_t set; 3307 uint8_t port_id; 3308 uint16_t vlan_id; 3309 uint16_t vlan_id_outer; 3310 }; 3311 3312 static void 3313 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 3314 __attribute__((unused)) struct cmdline *cl, 3315 __attribute__((unused)) void *data) 3316 { 3317 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 3318 3319 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 3320 } 3321 3322 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 3323 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3324 tx_vlan, "tx_vlan"); 3325 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 3326 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3327 set, "set"); 3328 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 3329 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3330 port_id, UINT8); 3331 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 3332 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3333 vlan_id, UINT16); 3334 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 3335 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3336 vlan_id_outer, UINT16); 3337 3338 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 3339 .f = cmd_tx_vlan_set_qinq_parsed, 3340 .data = NULL, 3341 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 3342 "Enable hardware insertion of double VLAN header " 3343 "with given TAG Identifiers in packets sent on a port", 3344 .tokens = { 3345 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 3346 (void *)&cmd_tx_vlan_set_qinq_set, 3347 (void *)&cmd_tx_vlan_set_qinq_portid, 3348 (void *)&cmd_tx_vlan_set_qinq_vlanid, 3349 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 3350 NULL, 3351 }, 3352 }; 3353 3354 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 3355 struct cmd_tx_vlan_set_pvid_result { 3356 cmdline_fixed_string_t tx_vlan; 3357 cmdline_fixed_string_t set; 3358 cmdline_fixed_string_t pvid; 3359 uint8_t port_id; 3360 uint16_t vlan_id; 3361 cmdline_fixed_string_t mode; 3362 }; 3363 3364 static void 3365 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 3366 __attribute__((unused)) struct cmdline *cl, 3367 __attribute__((unused)) void *data) 3368 { 3369 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 3370 3371 if (strcmp(res->mode, "on") == 0) 3372 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 3373 else 3374 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 3375 } 3376 3377 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 3378 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3379 tx_vlan, "tx_vlan"); 3380 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 3381 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3382 set, "set"); 3383 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 3384 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3385 pvid, "pvid"); 3386 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 3387 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3388 port_id, UINT8); 3389 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 3390 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3391 vlan_id, UINT16); 3392 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 3393 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3394 mode, "on#off"); 3395 3396 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 3397 .f = cmd_tx_vlan_set_pvid_parsed, 3398 .data = NULL, 3399 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 3400 .tokens = { 3401 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 3402 (void *)&cmd_tx_vlan_set_pvid_set, 3403 (void *)&cmd_tx_vlan_set_pvid_pvid, 3404 (void *)&cmd_tx_vlan_set_pvid_port_id, 3405 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 3406 (void *)&cmd_tx_vlan_set_pvid_mode, 3407 NULL, 3408 }, 3409 }; 3410 3411 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3412 struct cmd_tx_vlan_reset_result { 3413 cmdline_fixed_string_t tx_vlan; 3414 cmdline_fixed_string_t reset; 3415 uint8_t port_id; 3416 }; 3417 3418 static void 3419 cmd_tx_vlan_reset_parsed(void *parsed_result, 3420 __attribute__((unused)) struct cmdline *cl, 3421 __attribute__((unused)) void *data) 3422 { 3423 struct cmd_tx_vlan_reset_result *res = parsed_result; 3424 3425 tx_vlan_reset(res->port_id); 3426 } 3427 3428 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 3429 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3430 tx_vlan, "tx_vlan"); 3431 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 3432 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3433 reset, "reset"); 3434 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 3435 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 3436 port_id, UINT8); 3437 3438 cmdline_parse_inst_t cmd_tx_vlan_reset = { 3439 .f = cmd_tx_vlan_reset_parsed, 3440 .data = NULL, 3441 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 3442 "VLAN header in packets sent on a port", 3443 .tokens = { 3444 (void *)&cmd_tx_vlan_reset_tx_vlan, 3445 (void *)&cmd_tx_vlan_reset_reset, 3446 (void *)&cmd_tx_vlan_reset_portid, 3447 NULL, 3448 }, 3449 }; 3450 3451 3452 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 3453 struct cmd_csum_result { 3454 cmdline_fixed_string_t csum; 3455 cmdline_fixed_string_t mode; 3456 cmdline_fixed_string_t proto; 3457 cmdline_fixed_string_t hwsw; 3458 uint8_t port_id; 3459 }; 3460 3461 static void 3462 csum_show(int port_id) 3463 { 3464 struct rte_eth_dev_info dev_info; 3465 uint16_t ol_flags; 3466 3467 ol_flags = ports[port_id].tx_ol_flags; 3468 printf("Parse tunnel is %s\n", 3469 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off"); 3470 printf("IP checksum offload is %s\n", 3471 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw"); 3472 printf("UDP checksum offload is %s\n", 3473 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 3474 printf("TCP checksum offload is %s\n", 3475 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 3476 printf("SCTP checksum offload is %s\n", 3477 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 3478 printf("Outer-Ip checksum offload is %s\n", 3479 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw"); 3480 3481 /* display warnings if configuration is not supported by the NIC */ 3482 rte_eth_dev_info_get(port_id, &dev_info); 3483 if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) && 3484 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) { 3485 printf("Warning: hardware IP checksum enabled but not " 3486 "supported by port %d\n", port_id); 3487 } 3488 if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) && 3489 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) { 3490 printf("Warning: hardware UDP checksum enabled but not " 3491 "supported by port %d\n", port_id); 3492 } 3493 if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) && 3494 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) { 3495 printf("Warning: hardware TCP checksum enabled but not " 3496 "supported by port %d\n", port_id); 3497 } 3498 if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) && 3499 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) { 3500 printf("Warning: hardware SCTP checksum enabled but not " 3501 "supported by port %d\n", port_id); 3502 } 3503 if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) && 3504 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 3505 printf("Warning: hardware outer IP checksum enabled but not " 3506 "supported by port %d\n", port_id); 3507 } 3508 } 3509 3510 static void 3511 cmd_csum_parsed(void *parsed_result, 3512 __attribute__((unused)) struct cmdline *cl, 3513 __attribute__((unused)) void *data) 3514 { 3515 struct cmd_csum_result *res = parsed_result; 3516 int hw = 0; 3517 uint16_t mask = 0; 3518 3519 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 3520 printf("invalid port %d\n", res->port_id); 3521 return; 3522 } 3523 3524 if (!strcmp(res->mode, "set")) { 3525 3526 if (!strcmp(res->hwsw, "hw")) 3527 hw = 1; 3528 3529 if (!strcmp(res->proto, "ip")) { 3530 mask = TESTPMD_TX_OFFLOAD_IP_CKSUM; 3531 } else if (!strcmp(res->proto, "udp")) { 3532 mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM; 3533 } else if (!strcmp(res->proto, "tcp")) { 3534 mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM; 3535 } else if (!strcmp(res->proto, "sctp")) { 3536 mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM; 3537 } else if (!strcmp(res->proto, "outer-ip")) { 3538 mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM; 3539 } 3540 3541 if (hw) 3542 ports[res->port_id].tx_ol_flags |= mask; 3543 else 3544 ports[res->port_id].tx_ol_flags &= (~mask); 3545 } 3546 csum_show(res->port_id); 3547 } 3548 3549 cmdline_parse_token_string_t cmd_csum_csum = 3550 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3551 csum, "csum"); 3552 cmdline_parse_token_string_t cmd_csum_mode = 3553 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3554 mode, "set"); 3555 cmdline_parse_token_string_t cmd_csum_proto = 3556 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3557 proto, "ip#tcp#udp#sctp#outer-ip"); 3558 cmdline_parse_token_string_t cmd_csum_hwsw = 3559 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3560 hwsw, "hw#sw"); 3561 cmdline_parse_token_num_t cmd_csum_portid = 3562 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 3563 port_id, UINT8); 3564 3565 cmdline_parse_inst_t cmd_csum_set = { 3566 .f = cmd_csum_parsed, 3567 .data = NULL, 3568 .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: " 3569 "Enable/Disable hardware calculation of L3/L4 checksum when " 3570 "using csum forward engine", 3571 .tokens = { 3572 (void *)&cmd_csum_csum, 3573 (void *)&cmd_csum_mode, 3574 (void *)&cmd_csum_proto, 3575 (void *)&cmd_csum_hwsw, 3576 (void *)&cmd_csum_portid, 3577 NULL, 3578 }, 3579 }; 3580 3581 cmdline_parse_token_string_t cmd_csum_mode_show = 3582 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3583 mode, "show"); 3584 3585 cmdline_parse_inst_t cmd_csum_show = { 3586 .f = cmd_csum_parsed, 3587 .data = NULL, 3588 .help_str = "csum show <port_id>: Show checksum offload configuration", 3589 .tokens = { 3590 (void *)&cmd_csum_csum, 3591 (void *)&cmd_csum_mode_show, 3592 (void *)&cmd_csum_portid, 3593 NULL, 3594 }, 3595 }; 3596 3597 /* Enable/disable tunnel parsing */ 3598 struct cmd_csum_tunnel_result { 3599 cmdline_fixed_string_t csum; 3600 cmdline_fixed_string_t parse; 3601 cmdline_fixed_string_t onoff; 3602 uint8_t port_id; 3603 }; 3604 3605 static void 3606 cmd_csum_tunnel_parsed(void *parsed_result, 3607 __attribute__((unused)) struct cmdline *cl, 3608 __attribute__((unused)) void *data) 3609 { 3610 struct cmd_csum_tunnel_result *res = parsed_result; 3611 3612 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3613 return; 3614 3615 if (!strcmp(res->onoff, "on")) 3616 ports[res->port_id].tx_ol_flags |= 3617 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL; 3618 else 3619 ports[res->port_id].tx_ol_flags &= 3620 (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL); 3621 3622 csum_show(res->port_id); 3623 } 3624 3625 cmdline_parse_token_string_t cmd_csum_tunnel_csum = 3626 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3627 csum, "csum"); 3628 cmdline_parse_token_string_t cmd_csum_tunnel_parse = 3629 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3630 parse, "parse_tunnel"); 3631 cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 3632 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3633 onoff, "on#off"); 3634 cmdline_parse_token_num_t cmd_csum_tunnel_portid = 3635 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 3636 port_id, UINT8); 3637 3638 cmdline_parse_inst_t cmd_csum_tunnel = { 3639 .f = cmd_csum_tunnel_parsed, 3640 .data = NULL, 3641 .help_str = "csum parse_tunnel on|off <port_id>: " 3642 "Enable/Disable parsing of tunnels for csum engine", 3643 .tokens = { 3644 (void *)&cmd_csum_tunnel_csum, 3645 (void *)&cmd_csum_tunnel_parse, 3646 (void *)&cmd_csum_tunnel_onoff, 3647 (void *)&cmd_csum_tunnel_portid, 3648 NULL, 3649 }, 3650 }; 3651 3652 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 3653 struct cmd_tso_set_result { 3654 cmdline_fixed_string_t tso; 3655 cmdline_fixed_string_t mode; 3656 uint16_t tso_segsz; 3657 uint8_t port_id; 3658 }; 3659 3660 static void 3661 cmd_tso_set_parsed(void *parsed_result, 3662 __attribute__((unused)) struct cmdline *cl, 3663 __attribute__((unused)) void *data) 3664 { 3665 struct cmd_tso_set_result *res = parsed_result; 3666 struct rte_eth_dev_info dev_info; 3667 3668 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3669 return; 3670 3671 if (!strcmp(res->mode, "set")) 3672 ports[res->port_id].tso_segsz = res->tso_segsz; 3673 3674 if (ports[res->port_id].tso_segsz == 0) 3675 printf("TSO for non-tunneled packets is disabled\n"); 3676 else 3677 printf("TSO segment size for non-tunneled packets is %d\n", 3678 ports[res->port_id].tso_segsz); 3679 3680 /* display warnings if configuration is not supported by the NIC */ 3681 rte_eth_dev_info_get(res->port_id, &dev_info); 3682 if ((ports[res->port_id].tso_segsz != 0) && 3683 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3684 printf("Warning: TSO enabled but not " 3685 "supported by port %d\n", res->port_id); 3686 } 3687 } 3688 3689 cmdline_parse_token_string_t cmd_tso_set_tso = 3690 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3691 tso, "tso"); 3692 cmdline_parse_token_string_t cmd_tso_set_mode = 3693 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3694 mode, "set"); 3695 cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 3696 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3697 tso_segsz, UINT16); 3698 cmdline_parse_token_num_t cmd_tso_set_portid = 3699 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3700 port_id, UINT8); 3701 3702 cmdline_parse_inst_t cmd_tso_set = { 3703 .f = cmd_tso_set_parsed, 3704 .data = NULL, 3705 .help_str = "tso set <tso_segsz> <port_id>: " 3706 "Set TSO segment size of non-tunneled packets for csum engine " 3707 "(0 to disable)", 3708 .tokens = { 3709 (void *)&cmd_tso_set_tso, 3710 (void *)&cmd_tso_set_mode, 3711 (void *)&cmd_tso_set_tso_segsz, 3712 (void *)&cmd_tso_set_portid, 3713 NULL, 3714 }, 3715 }; 3716 3717 cmdline_parse_token_string_t cmd_tso_show_mode = 3718 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3719 mode, "show"); 3720 3721 3722 cmdline_parse_inst_t cmd_tso_show = { 3723 .f = cmd_tso_set_parsed, 3724 .data = NULL, 3725 .help_str = "tso show <port_id>: " 3726 "Show TSO segment size of non-tunneled packets for csum engine", 3727 .tokens = { 3728 (void *)&cmd_tso_set_tso, 3729 (void *)&cmd_tso_show_mode, 3730 (void *)&cmd_tso_set_portid, 3731 NULL, 3732 }, 3733 }; 3734 3735 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 3736 struct cmd_tunnel_tso_set_result { 3737 cmdline_fixed_string_t tso; 3738 cmdline_fixed_string_t mode; 3739 uint16_t tso_segsz; 3740 uint8_t port_id; 3741 }; 3742 3743 static void 3744 check_tunnel_tso_nic_support(uint8_t port_id) 3745 { 3746 struct rte_eth_dev_info dev_info; 3747 3748 rte_eth_dev_info_get(port_id, &dev_info); 3749 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) 3750 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not " 3751 "supported by port %d\n", port_id); 3752 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO)) 3753 printf("Warning: TSO enabled but GRE TUNNEL TSO not " 3754 "supported by port %d\n", port_id); 3755 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO)) 3756 printf("Warning: TSO enabled but IPIP TUNNEL TSO not " 3757 "supported by port %d\n", port_id); 3758 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) 3759 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not " 3760 "supported by port %d\n", port_id); 3761 } 3762 3763 static void 3764 cmd_tunnel_tso_set_parsed(void *parsed_result, 3765 __attribute__((unused)) struct cmdline *cl, 3766 __attribute__((unused)) void *data) 3767 { 3768 struct cmd_tunnel_tso_set_result *res = parsed_result; 3769 3770 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3771 return; 3772 3773 if (!strcmp(res->mode, "set")) 3774 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 3775 3776 if (ports[res->port_id].tunnel_tso_segsz == 0) 3777 printf("TSO for tunneled packets is disabled\n"); 3778 else { 3779 printf("TSO segment size for tunneled packets is %d\n", 3780 ports[res->port_id].tunnel_tso_segsz); 3781 3782 /* Below conditions are needed to make it work: 3783 * (1) tunnel TSO is supported by the NIC; 3784 * (2) "csum parse_tunnel" must be set so that tunneled pkts 3785 * are recognized; 3786 * (3) for tunneled pkts with outer L3 of IPv4, 3787 * "csum set outer-ip" must be set to hw, because after tso, 3788 * total_len of outer IP header is changed, and the checksum 3789 * of outer IP header calculated by sw should be wrong; that 3790 * is not necessary for IPv6 tunneled pkts because there's no 3791 * checksum in IP header anymore. 3792 */ 3793 check_tunnel_tso_nic_support(res->port_id); 3794 3795 if (!(ports[res->port_id].tx_ol_flags & 3796 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL)) 3797 printf("Warning: csum parse_tunnel must be set " 3798 "so that tunneled packets are recognized\n"); 3799 if (!(ports[res->port_id].tx_ol_flags & 3800 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)) 3801 printf("Warning: csum set outer-ip must be set to hw " 3802 "if outer L3 is IPv4; not necessary for IPv6\n"); 3803 } 3804 } 3805 3806 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 3807 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3808 tso, "tunnel_tso"); 3809 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 3810 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3811 mode, "set"); 3812 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 3813 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3814 tso_segsz, UINT16); 3815 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 3816 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3817 port_id, UINT8); 3818 3819 cmdline_parse_inst_t cmd_tunnel_tso_set = { 3820 .f = cmd_tunnel_tso_set_parsed, 3821 .data = NULL, 3822 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 3823 "Set TSO segment size of tunneled packets for csum engine " 3824 "(0 to disable)", 3825 .tokens = { 3826 (void *)&cmd_tunnel_tso_set_tso, 3827 (void *)&cmd_tunnel_tso_set_mode, 3828 (void *)&cmd_tunnel_tso_set_tso_segsz, 3829 (void *)&cmd_tunnel_tso_set_portid, 3830 NULL, 3831 }, 3832 }; 3833 3834 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 3835 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3836 mode, "show"); 3837 3838 3839 cmdline_parse_inst_t cmd_tunnel_tso_show = { 3840 .f = cmd_tunnel_tso_set_parsed, 3841 .data = NULL, 3842 .help_str = "tunnel_tso show <port_id> " 3843 "Show TSO segment size of tunneled packets for csum engine", 3844 .tokens = { 3845 (void *)&cmd_tunnel_tso_set_tso, 3846 (void *)&cmd_tunnel_tso_show_mode, 3847 (void *)&cmd_tunnel_tso_set_portid, 3848 NULL, 3849 }, 3850 }; 3851 3852 /* *** SET GRO FOR A PORT *** */ 3853 struct cmd_gro_result { 3854 cmdline_fixed_string_t cmd_keyword; 3855 cmdline_fixed_string_t mode; 3856 uint8_t port_id; 3857 }; 3858 3859 static void 3860 cmd_enable_gro_parsed(void *parsed_result, 3861 __attribute__((unused)) struct cmdline *cl, 3862 __attribute__((unused)) void *data) 3863 { 3864 struct cmd_gro_result *res; 3865 3866 res = parsed_result; 3867 setup_gro(res->mode, res->port_id); 3868 } 3869 3870 cmdline_parse_token_string_t cmd_gro_keyword = 3871 TOKEN_STRING_INITIALIZER(struct cmd_gro_result, 3872 cmd_keyword, "gro"); 3873 cmdline_parse_token_string_t cmd_gro_mode = 3874 TOKEN_STRING_INITIALIZER(struct cmd_gro_result, 3875 mode, "on#off"); 3876 cmdline_parse_token_num_t cmd_gro_pid = 3877 TOKEN_NUM_INITIALIZER(struct cmd_gro_result, 3878 port_id, UINT8); 3879 3880 cmdline_parse_inst_t cmd_enable_gro = { 3881 .f = cmd_enable_gro_parsed, 3882 .data = NULL, 3883 .help_str = "gro (on|off) (port_id)", 3884 .tokens = { 3885 (void *)&cmd_gro_keyword, 3886 (void *)&cmd_gro_mode, 3887 (void *)&cmd_gro_pid, 3888 NULL, 3889 }, 3890 }; 3891 3892 /* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */ 3893 struct cmd_gro_set_result { 3894 cmdline_fixed_string_t gro; 3895 cmdline_fixed_string_t mode; 3896 uint16_t flow_num; 3897 uint16_t item_num_per_flow; 3898 uint8_t port_id; 3899 }; 3900 3901 static void 3902 cmd_gro_set_parsed(void *parsed_result, 3903 __attribute__((unused)) struct cmdline *cl, 3904 __attribute__((unused)) void *data) 3905 { 3906 struct cmd_gro_set_result *res = parsed_result; 3907 3908 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3909 return; 3910 if (test_done == 0) { 3911 printf("Before set GRO flow_num and item_num_per_flow," 3912 " please stop forwarding first\n"); 3913 return; 3914 } 3915 3916 if (!strcmp(res->mode, "set")) { 3917 if (res->flow_num == 0) 3918 printf("Invalid flow number. Revert to default value:" 3919 " %u.\n", GRO_DEFAULT_FLOW_NUM); 3920 else 3921 gro_ports[res->port_id].param.max_flow_num = 3922 res->flow_num; 3923 3924 if (res->item_num_per_flow == 0) 3925 printf("Invalid item number per-flow. Revert" 3926 " to default value:%u.\n", 3927 GRO_DEFAULT_ITEM_NUM_PER_FLOW); 3928 else 3929 gro_ports[res->port_id].param.max_item_per_flow = 3930 res->item_num_per_flow; 3931 } 3932 } 3933 3934 cmdline_parse_token_string_t cmd_gro_set_gro = 3935 TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result, 3936 gro, "gro"); 3937 cmdline_parse_token_string_t cmd_gro_set_mode = 3938 TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result, 3939 mode, "set"); 3940 cmdline_parse_token_num_t cmd_gro_set_flow_num = 3941 TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, 3942 flow_num, UINT16); 3943 cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow = 3944 TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, 3945 item_num_per_flow, UINT16); 3946 cmdline_parse_token_num_t cmd_gro_set_portid = 3947 TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, 3948 port_id, UINT8); 3949 3950 cmdline_parse_inst_t cmd_gro_set = { 3951 .f = cmd_gro_set_parsed, 3952 .data = NULL, 3953 .help_str = "gro set <max_flow_num> <max_item_num_per_flow> " 3954 "<port_id>: set max flow number and max packet number per-flow " 3955 "for GRO", 3956 .tokens = { 3957 (void *)&cmd_gro_set_gro, 3958 (void *)&cmd_gro_set_mode, 3959 (void *)&cmd_gro_set_flow_num, 3960 (void *)&cmd_gro_set_item_num_per_flow, 3961 (void *)&cmd_gro_set_portid, 3962 NULL, 3963 }, 3964 }; 3965 3966 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 3967 struct cmd_set_flush_rx { 3968 cmdline_fixed_string_t set; 3969 cmdline_fixed_string_t flush_rx; 3970 cmdline_fixed_string_t mode; 3971 }; 3972 3973 static void 3974 cmd_set_flush_rx_parsed(void *parsed_result, 3975 __attribute__((unused)) struct cmdline *cl, 3976 __attribute__((unused)) void *data) 3977 { 3978 struct cmd_set_flush_rx *res = parsed_result; 3979 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 3980 } 3981 3982 cmdline_parse_token_string_t cmd_setflushrx_set = 3983 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3984 set, "set"); 3985 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 3986 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3987 flush_rx, "flush_rx"); 3988 cmdline_parse_token_string_t cmd_setflushrx_mode = 3989 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3990 mode, "on#off"); 3991 3992 3993 cmdline_parse_inst_t cmd_set_flush_rx = { 3994 .f = cmd_set_flush_rx_parsed, 3995 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 3996 .data = NULL, 3997 .tokens = { 3998 (void *)&cmd_setflushrx_set, 3999 (void *)&cmd_setflushrx_flush_rx, 4000 (void *)&cmd_setflushrx_mode, 4001 NULL, 4002 }, 4003 }; 4004 4005 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 4006 struct cmd_set_link_check { 4007 cmdline_fixed_string_t set; 4008 cmdline_fixed_string_t link_check; 4009 cmdline_fixed_string_t mode; 4010 }; 4011 4012 static void 4013 cmd_set_link_check_parsed(void *parsed_result, 4014 __attribute__((unused)) struct cmdline *cl, 4015 __attribute__((unused)) void *data) 4016 { 4017 struct cmd_set_link_check *res = parsed_result; 4018 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 4019 } 4020 4021 cmdline_parse_token_string_t cmd_setlinkcheck_set = 4022 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4023 set, "set"); 4024 cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 4025 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4026 link_check, "link_check"); 4027 cmdline_parse_token_string_t cmd_setlinkcheck_mode = 4028 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4029 mode, "on#off"); 4030 4031 4032 cmdline_parse_inst_t cmd_set_link_check = { 4033 .f = cmd_set_link_check_parsed, 4034 .help_str = "set link_check on|off: Enable/Disable link status check " 4035 "when starting/stopping a port", 4036 .data = NULL, 4037 .tokens = { 4038 (void *)&cmd_setlinkcheck_set, 4039 (void *)&cmd_setlinkcheck_link_check, 4040 (void *)&cmd_setlinkcheck_mode, 4041 NULL, 4042 }, 4043 }; 4044 4045 /* *** SET NIC BYPASS MODE *** */ 4046 struct cmd_set_bypass_mode_result { 4047 cmdline_fixed_string_t set; 4048 cmdline_fixed_string_t bypass; 4049 cmdline_fixed_string_t mode; 4050 cmdline_fixed_string_t value; 4051 uint8_t port_id; 4052 }; 4053 4054 static void 4055 cmd_set_bypass_mode_parsed(void *parsed_result, 4056 __attribute__((unused)) struct cmdline *cl, 4057 __attribute__((unused)) void *data) 4058 { 4059 struct cmd_set_bypass_mode_result *res = parsed_result; 4060 portid_t port_id = res->port_id; 4061 int32_t rc = -EINVAL; 4062 4063 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4064 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4065 4066 if (!strcmp(res->value, "bypass")) 4067 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4068 else if (!strcmp(res->value, "isolate")) 4069 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4070 else 4071 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4072 4073 /* Set the bypass mode for the relevant port. */ 4074 rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); 4075 #endif 4076 if (rc != 0) 4077 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 4078 } 4079 4080 cmdline_parse_token_string_t cmd_setbypass_mode_set = 4081 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4082 set, "set"); 4083 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 4084 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4085 bypass, "bypass"); 4086 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 4087 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4088 mode, "mode"); 4089 cmdline_parse_token_string_t cmd_setbypass_mode_value = 4090 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4091 value, "normal#bypass#isolate"); 4092 cmdline_parse_token_num_t cmd_setbypass_mode_port = 4093 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 4094 port_id, UINT8); 4095 4096 cmdline_parse_inst_t cmd_set_bypass_mode = { 4097 .f = cmd_set_bypass_mode_parsed, 4098 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 4099 "Set the NIC bypass mode for port_id", 4100 .data = NULL, 4101 .tokens = { 4102 (void *)&cmd_setbypass_mode_set, 4103 (void *)&cmd_setbypass_mode_bypass, 4104 (void *)&cmd_setbypass_mode_mode, 4105 (void *)&cmd_setbypass_mode_value, 4106 (void *)&cmd_setbypass_mode_port, 4107 NULL, 4108 }, 4109 }; 4110 4111 /* *** SET NIC BYPASS EVENT *** */ 4112 struct cmd_set_bypass_event_result { 4113 cmdline_fixed_string_t set; 4114 cmdline_fixed_string_t bypass; 4115 cmdline_fixed_string_t event; 4116 cmdline_fixed_string_t event_value; 4117 cmdline_fixed_string_t mode; 4118 cmdline_fixed_string_t mode_value; 4119 uint8_t port_id; 4120 }; 4121 4122 static void 4123 cmd_set_bypass_event_parsed(void *parsed_result, 4124 __attribute__((unused)) struct cmdline *cl, 4125 __attribute__((unused)) void *data) 4126 { 4127 int32_t rc = -EINVAL; 4128 struct cmd_set_bypass_event_result *res = parsed_result; 4129 portid_t port_id = res->port_id; 4130 4131 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4132 uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4133 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4134 4135 if (!strcmp(res->event_value, "timeout")) 4136 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; 4137 else if (!strcmp(res->event_value, "os_on")) 4138 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; 4139 else if (!strcmp(res->event_value, "os_off")) 4140 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; 4141 else if (!strcmp(res->event_value, "power_on")) 4142 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; 4143 else if (!strcmp(res->event_value, "power_off")) 4144 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; 4145 else 4146 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4147 4148 if (!strcmp(res->mode_value, "bypass")) 4149 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4150 else if (!strcmp(res->mode_value, "isolate")) 4151 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4152 else 4153 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4154 4155 /* Set the watchdog timeout. */ 4156 if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { 4157 4158 rc = -EINVAL; 4159 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { 4160 rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, 4161 bypass_timeout); 4162 } 4163 if (rc != 0) { 4164 printf("Failed to set timeout value %u " 4165 "for port %d, errto code: %d.\n", 4166 bypass_timeout, port_id, rc); 4167 } 4168 } 4169 4170 /* Set the bypass event to transition to bypass mode. */ 4171 rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, 4172 bypass_mode); 4173 #endif 4174 4175 if (rc != 0) 4176 printf("\t Failed to set bypass event for port = %d.\n", 4177 port_id); 4178 } 4179 4180 cmdline_parse_token_string_t cmd_setbypass_event_set = 4181 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4182 set, "set"); 4183 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 4184 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4185 bypass, "bypass"); 4186 cmdline_parse_token_string_t cmd_setbypass_event_event = 4187 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4188 event, "event"); 4189 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 4190 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4191 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 4192 cmdline_parse_token_string_t cmd_setbypass_event_mode = 4193 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4194 mode, "mode"); 4195 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 4196 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4197 mode_value, "normal#bypass#isolate"); 4198 cmdline_parse_token_num_t cmd_setbypass_event_port = 4199 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 4200 port_id, UINT8); 4201 4202 cmdline_parse_inst_t cmd_set_bypass_event = { 4203 .f = cmd_set_bypass_event_parsed, 4204 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 4205 "power_off mode normal|bypass|isolate <port_id>: " 4206 "Set the NIC bypass event mode for port_id", 4207 .data = NULL, 4208 .tokens = { 4209 (void *)&cmd_setbypass_event_set, 4210 (void *)&cmd_setbypass_event_bypass, 4211 (void *)&cmd_setbypass_event_event, 4212 (void *)&cmd_setbypass_event_event_value, 4213 (void *)&cmd_setbypass_event_mode, 4214 (void *)&cmd_setbypass_event_mode_value, 4215 (void *)&cmd_setbypass_event_port, 4216 NULL, 4217 }, 4218 }; 4219 4220 4221 /* *** SET NIC BYPASS TIMEOUT *** */ 4222 struct cmd_set_bypass_timeout_result { 4223 cmdline_fixed_string_t set; 4224 cmdline_fixed_string_t bypass; 4225 cmdline_fixed_string_t timeout; 4226 cmdline_fixed_string_t value; 4227 }; 4228 4229 static void 4230 cmd_set_bypass_timeout_parsed(void *parsed_result, 4231 __attribute__((unused)) struct cmdline *cl, 4232 __attribute__((unused)) void *data) 4233 { 4234 __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result; 4235 4236 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4237 if (!strcmp(res->value, "1.5")) 4238 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; 4239 else if (!strcmp(res->value, "2")) 4240 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; 4241 else if (!strcmp(res->value, "3")) 4242 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; 4243 else if (!strcmp(res->value, "4")) 4244 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; 4245 else if (!strcmp(res->value, "8")) 4246 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; 4247 else if (!strcmp(res->value, "16")) 4248 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; 4249 else if (!strcmp(res->value, "32")) 4250 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; 4251 else 4252 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4253 #endif 4254 } 4255 4256 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 4257 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4258 set, "set"); 4259 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 4260 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4261 bypass, "bypass"); 4262 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 4263 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4264 timeout, "timeout"); 4265 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 4266 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4267 value, "0#1.5#2#3#4#8#16#32"); 4268 4269 cmdline_parse_inst_t cmd_set_bypass_timeout = { 4270 .f = cmd_set_bypass_timeout_parsed, 4271 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 4272 "Set the NIC bypass watchdog timeout in seconds", 4273 .data = NULL, 4274 .tokens = { 4275 (void *)&cmd_setbypass_timeout_set, 4276 (void *)&cmd_setbypass_timeout_bypass, 4277 (void *)&cmd_setbypass_timeout_timeout, 4278 (void *)&cmd_setbypass_timeout_value, 4279 NULL, 4280 }, 4281 }; 4282 4283 /* *** SHOW NIC BYPASS MODE *** */ 4284 struct cmd_show_bypass_config_result { 4285 cmdline_fixed_string_t show; 4286 cmdline_fixed_string_t bypass; 4287 cmdline_fixed_string_t config; 4288 uint8_t port_id; 4289 }; 4290 4291 static void 4292 cmd_show_bypass_config_parsed(void *parsed_result, 4293 __attribute__((unused)) struct cmdline *cl, 4294 __attribute__((unused)) void *data) 4295 { 4296 struct cmd_show_bypass_config_result *res = parsed_result; 4297 portid_t port_id = res->port_id; 4298 int rc = -EINVAL; 4299 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4300 uint32_t event_mode; 4301 uint32_t bypass_mode; 4302 uint32_t timeout = bypass_timeout; 4303 int i; 4304 4305 static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = 4306 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 4307 static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = 4308 {"UNKNOWN", "normal", "bypass", "isolate"}; 4309 static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { 4310 "NONE", 4311 "OS/board on", 4312 "power supply on", 4313 "OS/board off", 4314 "power supply off", 4315 "timeout"}; 4316 int num_events = (sizeof events) / (sizeof events[0]); 4317 4318 /* Display the bypass mode.*/ 4319 if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { 4320 printf("\tFailed to get bypass mode for port = %d\n", port_id); 4321 return; 4322 } 4323 else { 4324 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) 4325 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4326 4327 printf("\tbypass mode = %s\n", modes[bypass_mode]); 4328 } 4329 4330 /* Display the bypass timeout.*/ 4331 if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) 4332 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4333 4334 printf("\tbypass timeout = %s\n", timeouts[timeout]); 4335 4336 /* Display the bypass events and associated modes. */ 4337 for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) { 4338 4339 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { 4340 printf("\tFailed to get bypass mode for event = %s\n", 4341 events[i]); 4342 } else { 4343 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) 4344 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4345 4346 printf("\tbypass event: %-16s = %s\n", events[i], 4347 modes[event_mode]); 4348 } 4349 } 4350 #endif 4351 if (rc != 0) 4352 printf("\tFailed to get bypass configuration for port = %d\n", 4353 port_id); 4354 } 4355 4356 cmdline_parse_token_string_t cmd_showbypass_config_show = 4357 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4358 show, "show"); 4359 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 4360 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4361 bypass, "bypass"); 4362 cmdline_parse_token_string_t cmd_showbypass_config_config = 4363 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4364 config, "config"); 4365 cmdline_parse_token_num_t cmd_showbypass_config_port = 4366 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 4367 port_id, UINT8); 4368 4369 cmdline_parse_inst_t cmd_show_bypass_config = { 4370 .f = cmd_show_bypass_config_parsed, 4371 .help_str = "show bypass config <port_id>: " 4372 "Show the NIC bypass config for port_id", 4373 .data = NULL, 4374 .tokens = { 4375 (void *)&cmd_showbypass_config_show, 4376 (void *)&cmd_showbypass_config_bypass, 4377 (void *)&cmd_showbypass_config_config, 4378 (void *)&cmd_showbypass_config_port, 4379 NULL, 4380 }, 4381 }; 4382 4383 #ifdef RTE_LIBRTE_PMD_BOND 4384 /* *** SET BONDING MODE *** */ 4385 struct cmd_set_bonding_mode_result { 4386 cmdline_fixed_string_t set; 4387 cmdline_fixed_string_t bonding; 4388 cmdline_fixed_string_t mode; 4389 uint8_t value; 4390 uint8_t port_id; 4391 }; 4392 4393 static void cmd_set_bonding_mode_parsed(void *parsed_result, 4394 __attribute__((unused)) struct cmdline *cl, 4395 __attribute__((unused)) void *data) 4396 { 4397 struct cmd_set_bonding_mode_result *res = parsed_result; 4398 portid_t port_id = res->port_id; 4399 4400 /* Set the bonding mode for the relevant port. */ 4401 if (0 != rte_eth_bond_mode_set(port_id, res->value)) 4402 printf("\t Failed to set bonding mode for port = %d.\n", port_id); 4403 } 4404 4405 cmdline_parse_token_string_t cmd_setbonding_mode_set = 4406 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4407 set, "set"); 4408 cmdline_parse_token_string_t cmd_setbonding_mode_bonding = 4409 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4410 bonding, "bonding"); 4411 cmdline_parse_token_string_t cmd_setbonding_mode_mode = 4412 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4413 mode, "mode"); 4414 cmdline_parse_token_num_t cmd_setbonding_mode_value = 4415 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4416 value, UINT8); 4417 cmdline_parse_token_num_t cmd_setbonding_mode_port = 4418 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4419 port_id, UINT8); 4420 4421 cmdline_parse_inst_t cmd_set_bonding_mode = { 4422 .f = cmd_set_bonding_mode_parsed, 4423 .help_str = "set bonding mode <mode_value> <port_id>: " 4424 "Set the bonding mode for port_id", 4425 .data = NULL, 4426 .tokens = { 4427 (void *) &cmd_setbonding_mode_set, 4428 (void *) &cmd_setbonding_mode_bonding, 4429 (void *) &cmd_setbonding_mode_mode, 4430 (void *) &cmd_setbonding_mode_value, 4431 (void *) &cmd_setbonding_mode_port, 4432 NULL 4433 } 4434 }; 4435 4436 /* *** SET BONDING SLOW_QUEUE SW/HW *** */ 4437 struct cmd_set_bonding_lacp_dedicated_queues_result { 4438 cmdline_fixed_string_t set; 4439 cmdline_fixed_string_t bonding; 4440 cmdline_fixed_string_t lacp; 4441 cmdline_fixed_string_t dedicated_queues; 4442 uint8_t port_id; 4443 cmdline_fixed_string_t mode; 4444 }; 4445 4446 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result, 4447 __attribute__((unused)) struct cmdline *cl, 4448 __attribute__((unused)) void *data) 4449 { 4450 struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result; 4451 portid_t port_id = res->port_id; 4452 struct rte_port *port; 4453 4454 port = &ports[port_id]; 4455 4456 /** Check if the port is not started **/ 4457 if (port->port_status != RTE_PORT_STOPPED) { 4458 printf("Please stop port %d first\n", port_id); 4459 return; 4460 } 4461 4462 if (!strcmp(res->mode, "enable")) { 4463 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0) 4464 printf("Dedicate queues for LACP control packets" 4465 " enabled\n"); 4466 else 4467 printf("Enabling dedicate queues for LACP control " 4468 "packets on port %d failed\n", port_id); 4469 } else if (!strcmp(res->mode, "disable")) { 4470 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0) 4471 printf("Dedicated queues for LACP control packets " 4472 "disabled\n"); 4473 else 4474 printf("Disabling dedicated queues for LACP control " 4475 "traffic on port %d failed\n", port_id); 4476 } 4477 } 4478 4479 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set = 4480 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4481 set, "set"); 4482 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding = 4483 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4484 bonding, "bonding"); 4485 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp = 4486 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4487 lacp, "lacp"); 4488 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues = 4489 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4490 dedicated_queues, "dedicated_queues"); 4491 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = 4492 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4493 port_id, UINT8); 4494 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = 4495 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4496 mode, "enable#disable"); 4497 4498 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = { 4499 .f = cmd_set_bonding_lacp_dedicated_queues_parsed, 4500 .help_str = "set bonding lacp dedicated_queues <port_id> " 4501 "enable|disable: " 4502 "Enable/disable dedicated queues for LACP control traffic for port_id", 4503 .data = NULL, 4504 .tokens = { 4505 (void *)&cmd_setbonding_lacp_dedicated_queues_set, 4506 (void *)&cmd_setbonding_lacp_dedicated_queues_bonding, 4507 (void *)&cmd_setbonding_lacp_dedicated_queues_lacp, 4508 (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues, 4509 (void *)&cmd_setbonding_lacp_dedicated_queues_port_id, 4510 (void *)&cmd_setbonding_lacp_dedicated_queues_mode, 4511 NULL 4512 } 4513 }; 4514 4515 /* *** SET BALANCE XMIT POLICY *** */ 4516 struct cmd_set_bonding_balance_xmit_policy_result { 4517 cmdline_fixed_string_t set; 4518 cmdline_fixed_string_t bonding; 4519 cmdline_fixed_string_t balance_xmit_policy; 4520 uint8_t port_id; 4521 cmdline_fixed_string_t policy; 4522 }; 4523 4524 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, 4525 __attribute__((unused)) struct cmdline *cl, 4526 __attribute__((unused)) void *data) 4527 { 4528 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; 4529 portid_t port_id = res->port_id; 4530 uint8_t policy; 4531 4532 if (!strcmp(res->policy, "l2")) { 4533 policy = BALANCE_XMIT_POLICY_LAYER2; 4534 } else if (!strcmp(res->policy, "l23")) { 4535 policy = BALANCE_XMIT_POLICY_LAYER23; 4536 } else if (!strcmp(res->policy, "l34")) { 4537 policy = BALANCE_XMIT_POLICY_LAYER34; 4538 } else { 4539 printf("\t Invalid xmit policy selection"); 4540 return; 4541 } 4542 4543 /* Set the bonding mode for the relevant port. */ 4544 if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { 4545 printf("\t Failed to set bonding balance xmit policy for port = %d.\n", 4546 port_id); 4547 } 4548 } 4549 4550 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = 4551 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4552 set, "set"); 4553 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = 4554 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4555 bonding, "bonding"); 4556 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = 4557 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4558 balance_xmit_policy, "balance_xmit_policy"); 4559 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = 4560 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4561 port_id, UINT8); 4562 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = 4563 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4564 policy, "l2#l23#l34"); 4565 4566 cmdline_parse_inst_t cmd_set_balance_xmit_policy = { 4567 .f = cmd_set_bonding_balance_xmit_policy_parsed, 4568 .help_str = "set bonding balance_xmit_policy <port_id> " 4569 "l2|l23|l34: " 4570 "Set the bonding balance_xmit_policy for port_id", 4571 .data = NULL, 4572 .tokens = { 4573 (void *)&cmd_setbonding_balance_xmit_policy_set, 4574 (void *)&cmd_setbonding_balance_xmit_policy_bonding, 4575 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, 4576 (void *)&cmd_setbonding_balance_xmit_policy_port, 4577 (void *)&cmd_setbonding_balance_xmit_policy_policy, 4578 NULL 4579 } 4580 }; 4581 4582 /* *** SHOW NIC BONDING CONFIGURATION *** */ 4583 struct cmd_show_bonding_config_result { 4584 cmdline_fixed_string_t show; 4585 cmdline_fixed_string_t bonding; 4586 cmdline_fixed_string_t config; 4587 uint8_t port_id; 4588 }; 4589 4590 static void cmd_show_bonding_config_parsed(void *parsed_result, 4591 __attribute__((unused)) struct cmdline *cl, 4592 __attribute__((unused)) void *data) 4593 { 4594 struct cmd_show_bonding_config_result *res = parsed_result; 4595 int bonding_mode, agg_mode; 4596 uint8_t slaves[RTE_MAX_ETHPORTS]; 4597 int num_slaves, num_active_slaves; 4598 int primary_id; 4599 int i; 4600 portid_t port_id = res->port_id; 4601 4602 /* Display the bonding mode.*/ 4603 bonding_mode = rte_eth_bond_mode_get(port_id); 4604 if (bonding_mode < 0) { 4605 printf("\tFailed to get bonding mode for port = %d\n", port_id); 4606 return; 4607 } else 4608 printf("\tBonding mode: %d\n", bonding_mode); 4609 4610 if (bonding_mode == BONDING_MODE_BALANCE) { 4611 int balance_xmit_policy; 4612 4613 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); 4614 if (balance_xmit_policy < 0) { 4615 printf("\tFailed to get balance xmit policy for port = %d\n", 4616 port_id); 4617 return; 4618 } else { 4619 printf("\tBalance Xmit Policy: "); 4620 4621 switch (balance_xmit_policy) { 4622 case BALANCE_XMIT_POLICY_LAYER2: 4623 printf("BALANCE_XMIT_POLICY_LAYER2"); 4624 break; 4625 case BALANCE_XMIT_POLICY_LAYER23: 4626 printf("BALANCE_XMIT_POLICY_LAYER23"); 4627 break; 4628 case BALANCE_XMIT_POLICY_LAYER34: 4629 printf("BALANCE_XMIT_POLICY_LAYER34"); 4630 break; 4631 } 4632 printf("\n"); 4633 } 4634 } 4635 4636 if (bonding_mode == BONDING_MODE_8023AD) { 4637 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id); 4638 printf("\tIEEE802.3AD Aggregator Mode: "); 4639 switch (agg_mode) { 4640 case AGG_BANDWIDTH: 4641 printf("bandwidth"); 4642 break; 4643 case AGG_STABLE: 4644 printf("stable"); 4645 break; 4646 case AGG_COUNT: 4647 printf("count"); 4648 break; 4649 } 4650 printf("\n"); 4651 } 4652 4653 num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); 4654 4655 if (num_slaves < 0) { 4656 printf("\tFailed to get slave list for port = %d\n", port_id); 4657 return; 4658 } 4659 if (num_slaves > 0) { 4660 printf("\tSlaves (%d): [", num_slaves); 4661 for (i = 0; i < num_slaves - 1; i++) 4662 printf("%d ", slaves[i]); 4663 4664 printf("%d]\n", slaves[num_slaves - 1]); 4665 } else { 4666 printf("\tSlaves: []\n"); 4667 4668 } 4669 4670 num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, 4671 RTE_MAX_ETHPORTS); 4672 4673 if (num_active_slaves < 0) { 4674 printf("\tFailed to get active slave list for port = %d\n", port_id); 4675 return; 4676 } 4677 if (num_active_slaves > 0) { 4678 printf("\tActive Slaves (%d): [", num_active_slaves); 4679 for (i = 0; i < num_active_slaves - 1; i++) 4680 printf("%d ", slaves[i]); 4681 4682 printf("%d]\n", slaves[num_active_slaves - 1]); 4683 4684 } else { 4685 printf("\tActive Slaves: []\n"); 4686 4687 } 4688 4689 primary_id = rte_eth_bond_primary_get(port_id); 4690 if (primary_id < 0) { 4691 printf("\tFailed to get primary slave for port = %d\n", port_id); 4692 return; 4693 } else 4694 printf("\tPrimary: [%d]\n", primary_id); 4695 4696 } 4697 4698 cmdline_parse_token_string_t cmd_showbonding_config_show = 4699 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4700 show, "show"); 4701 cmdline_parse_token_string_t cmd_showbonding_config_bonding = 4702 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4703 bonding, "bonding"); 4704 cmdline_parse_token_string_t cmd_showbonding_config_config = 4705 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4706 config, "config"); 4707 cmdline_parse_token_num_t cmd_showbonding_config_port = 4708 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, 4709 port_id, UINT8); 4710 4711 cmdline_parse_inst_t cmd_show_bonding_config = { 4712 .f = cmd_show_bonding_config_parsed, 4713 .help_str = "show bonding config <port_id>: " 4714 "Show the bonding config for port_id", 4715 .data = NULL, 4716 .tokens = { 4717 (void *)&cmd_showbonding_config_show, 4718 (void *)&cmd_showbonding_config_bonding, 4719 (void *)&cmd_showbonding_config_config, 4720 (void *)&cmd_showbonding_config_port, 4721 NULL 4722 } 4723 }; 4724 4725 /* *** SET BONDING PRIMARY *** */ 4726 struct cmd_set_bonding_primary_result { 4727 cmdline_fixed_string_t set; 4728 cmdline_fixed_string_t bonding; 4729 cmdline_fixed_string_t primary; 4730 uint8_t slave_id; 4731 uint8_t port_id; 4732 }; 4733 4734 static void cmd_set_bonding_primary_parsed(void *parsed_result, 4735 __attribute__((unused)) struct cmdline *cl, 4736 __attribute__((unused)) void *data) 4737 { 4738 struct cmd_set_bonding_primary_result *res = parsed_result; 4739 portid_t master_port_id = res->port_id; 4740 portid_t slave_port_id = res->slave_id; 4741 4742 /* Set the primary slave for a bonded device. */ 4743 if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { 4744 printf("\t Failed to set primary slave for port = %d.\n", 4745 master_port_id); 4746 return; 4747 } 4748 init_port_config(); 4749 } 4750 4751 cmdline_parse_token_string_t cmd_setbonding_primary_set = 4752 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4753 set, "set"); 4754 cmdline_parse_token_string_t cmd_setbonding_primary_bonding = 4755 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4756 bonding, "bonding"); 4757 cmdline_parse_token_string_t cmd_setbonding_primary_primary = 4758 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4759 primary, "primary"); 4760 cmdline_parse_token_num_t cmd_setbonding_primary_slave = 4761 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4762 slave_id, UINT8); 4763 cmdline_parse_token_num_t cmd_setbonding_primary_port = 4764 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4765 port_id, UINT8); 4766 4767 cmdline_parse_inst_t cmd_set_bonding_primary = { 4768 .f = cmd_set_bonding_primary_parsed, 4769 .help_str = "set bonding primary <slave_id> <port_id>: " 4770 "Set the primary slave for port_id", 4771 .data = NULL, 4772 .tokens = { 4773 (void *)&cmd_setbonding_primary_set, 4774 (void *)&cmd_setbonding_primary_bonding, 4775 (void *)&cmd_setbonding_primary_primary, 4776 (void *)&cmd_setbonding_primary_slave, 4777 (void *)&cmd_setbonding_primary_port, 4778 NULL 4779 } 4780 }; 4781 4782 /* *** ADD SLAVE *** */ 4783 struct cmd_add_bonding_slave_result { 4784 cmdline_fixed_string_t add; 4785 cmdline_fixed_string_t bonding; 4786 cmdline_fixed_string_t slave; 4787 uint8_t slave_id; 4788 uint8_t port_id; 4789 }; 4790 4791 static void cmd_add_bonding_slave_parsed(void *parsed_result, 4792 __attribute__((unused)) struct cmdline *cl, 4793 __attribute__((unused)) void *data) 4794 { 4795 struct cmd_add_bonding_slave_result *res = parsed_result; 4796 portid_t master_port_id = res->port_id; 4797 portid_t slave_port_id = res->slave_id; 4798 4799 /* add the slave for a bonded device. */ 4800 if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { 4801 printf("\t Failed to add slave %d to master port = %d.\n", 4802 slave_port_id, master_port_id); 4803 return; 4804 } 4805 init_port_config(); 4806 set_port_slave_flag(slave_port_id); 4807 } 4808 4809 cmdline_parse_token_string_t cmd_addbonding_slave_add = 4810 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4811 add, "add"); 4812 cmdline_parse_token_string_t cmd_addbonding_slave_bonding = 4813 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4814 bonding, "bonding"); 4815 cmdline_parse_token_string_t cmd_addbonding_slave_slave = 4816 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4817 slave, "slave"); 4818 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = 4819 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4820 slave_id, UINT8); 4821 cmdline_parse_token_num_t cmd_addbonding_slave_port = 4822 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4823 port_id, UINT8); 4824 4825 cmdline_parse_inst_t cmd_add_bonding_slave = { 4826 .f = cmd_add_bonding_slave_parsed, 4827 .help_str = "add bonding slave <slave_id> <port_id>: " 4828 "Add a slave device to a bonded device", 4829 .data = NULL, 4830 .tokens = { 4831 (void *)&cmd_addbonding_slave_add, 4832 (void *)&cmd_addbonding_slave_bonding, 4833 (void *)&cmd_addbonding_slave_slave, 4834 (void *)&cmd_addbonding_slave_slaveid, 4835 (void *)&cmd_addbonding_slave_port, 4836 NULL 4837 } 4838 }; 4839 4840 /* *** REMOVE SLAVE *** */ 4841 struct cmd_remove_bonding_slave_result { 4842 cmdline_fixed_string_t remove; 4843 cmdline_fixed_string_t bonding; 4844 cmdline_fixed_string_t slave; 4845 uint8_t slave_id; 4846 uint8_t port_id; 4847 }; 4848 4849 static void cmd_remove_bonding_slave_parsed(void *parsed_result, 4850 __attribute__((unused)) struct cmdline *cl, 4851 __attribute__((unused)) void *data) 4852 { 4853 struct cmd_remove_bonding_slave_result *res = parsed_result; 4854 portid_t master_port_id = res->port_id; 4855 portid_t slave_port_id = res->slave_id; 4856 4857 /* remove the slave from a bonded device. */ 4858 if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { 4859 printf("\t Failed to remove slave %d from master port = %d.\n", 4860 slave_port_id, master_port_id); 4861 return; 4862 } 4863 init_port_config(); 4864 clear_port_slave_flag(slave_port_id); 4865 } 4866 4867 cmdline_parse_token_string_t cmd_removebonding_slave_remove = 4868 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4869 remove, "remove"); 4870 cmdline_parse_token_string_t cmd_removebonding_slave_bonding = 4871 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4872 bonding, "bonding"); 4873 cmdline_parse_token_string_t cmd_removebonding_slave_slave = 4874 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4875 slave, "slave"); 4876 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = 4877 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4878 slave_id, UINT8); 4879 cmdline_parse_token_num_t cmd_removebonding_slave_port = 4880 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4881 port_id, UINT8); 4882 4883 cmdline_parse_inst_t cmd_remove_bonding_slave = { 4884 .f = cmd_remove_bonding_slave_parsed, 4885 .help_str = "remove bonding slave <slave_id> <port_id>: " 4886 "Remove a slave device from a bonded device", 4887 .data = NULL, 4888 .tokens = { 4889 (void *)&cmd_removebonding_slave_remove, 4890 (void *)&cmd_removebonding_slave_bonding, 4891 (void *)&cmd_removebonding_slave_slave, 4892 (void *)&cmd_removebonding_slave_slaveid, 4893 (void *)&cmd_removebonding_slave_port, 4894 NULL 4895 } 4896 }; 4897 4898 /* *** CREATE BONDED DEVICE *** */ 4899 struct cmd_create_bonded_device_result { 4900 cmdline_fixed_string_t create; 4901 cmdline_fixed_string_t bonded; 4902 cmdline_fixed_string_t device; 4903 uint8_t mode; 4904 uint8_t socket; 4905 }; 4906 4907 static int bond_dev_num = 0; 4908 4909 static void cmd_create_bonded_device_parsed(void *parsed_result, 4910 __attribute__((unused)) struct cmdline *cl, 4911 __attribute__((unused)) void *data) 4912 { 4913 struct cmd_create_bonded_device_result *res = parsed_result; 4914 char ethdev_name[RTE_ETH_NAME_MAX_LEN]; 4915 int port_id; 4916 4917 if (test_done == 0) { 4918 printf("Please stop forwarding first\n"); 4919 return; 4920 } 4921 4922 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d", 4923 bond_dev_num++); 4924 4925 /* Create a new bonded device. */ 4926 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); 4927 if (port_id < 0) { 4928 printf("\t Failed to create bonded device.\n"); 4929 return; 4930 } else { 4931 printf("Created new bonded device %s on (port %d).\n", ethdev_name, 4932 port_id); 4933 4934 /* Update number of ports */ 4935 nb_ports = rte_eth_dev_count(); 4936 reconfig(port_id, res->socket); 4937 rte_eth_promiscuous_enable(port_id); 4938 } 4939 4940 } 4941 4942 cmdline_parse_token_string_t cmd_createbonded_device_create = 4943 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4944 create, "create"); 4945 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 4946 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4947 bonded, "bonded"); 4948 cmdline_parse_token_string_t cmd_createbonded_device_device = 4949 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4950 device, "device"); 4951 cmdline_parse_token_num_t cmd_createbonded_device_mode = 4952 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4953 mode, UINT8); 4954 cmdline_parse_token_num_t cmd_createbonded_device_socket = 4955 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4956 socket, UINT8); 4957 4958 cmdline_parse_inst_t cmd_create_bonded_device = { 4959 .f = cmd_create_bonded_device_parsed, 4960 .help_str = "create bonded device <mode> <socket>: " 4961 "Create a new bonded device with specific bonding mode and socket", 4962 .data = NULL, 4963 .tokens = { 4964 (void *)&cmd_createbonded_device_create, 4965 (void *)&cmd_createbonded_device_bonded, 4966 (void *)&cmd_createbonded_device_device, 4967 (void *)&cmd_createbonded_device_mode, 4968 (void *)&cmd_createbonded_device_socket, 4969 NULL 4970 } 4971 }; 4972 4973 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 4974 struct cmd_set_bond_mac_addr_result { 4975 cmdline_fixed_string_t set; 4976 cmdline_fixed_string_t bonding; 4977 cmdline_fixed_string_t mac_addr; 4978 uint8_t port_num; 4979 struct ether_addr address; 4980 }; 4981 4982 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 4983 __attribute__((unused)) struct cmdline *cl, 4984 __attribute__((unused)) void *data) 4985 { 4986 struct cmd_set_bond_mac_addr_result *res = parsed_result; 4987 int ret; 4988 4989 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 4990 return; 4991 4992 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 4993 4994 /* check the return value and print it if is < 0 */ 4995 if (ret < 0) 4996 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4997 } 4998 4999 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 5000 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 5001 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 5002 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 5003 "bonding"); 5004 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 5005 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 5006 "mac_addr"); 5007 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 5008 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); 5009 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 5010 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 5011 5012 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 5013 .f = cmd_set_bond_mac_addr_parsed, 5014 .data = (void *) 0, 5015 .help_str = "set bonding mac_addr <port_id> <mac_addr>", 5016 .tokens = { 5017 (void *)&cmd_set_bond_mac_addr_set, 5018 (void *)&cmd_set_bond_mac_addr_bonding, 5019 (void *)&cmd_set_bond_mac_addr_mac, 5020 (void *)&cmd_set_bond_mac_addr_portnum, 5021 (void *)&cmd_set_bond_mac_addr_addr, 5022 NULL 5023 } 5024 }; 5025 5026 5027 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 5028 struct cmd_set_bond_mon_period_result { 5029 cmdline_fixed_string_t set; 5030 cmdline_fixed_string_t bonding; 5031 cmdline_fixed_string_t mon_period; 5032 uint8_t port_num; 5033 uint32_t period_ms; 5034 }; 5035 5036 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 5037 __attribute__((unused)) struct cmdline *cl, 5038 __attribute__((unused)) void *data) 5039 { 5040 struct cmd_set_bond_mon_period_result *res = parsed_result; 5041 int ret; 5042 5043 if (res->port_num >= nb_ports) { 5044 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 5045 return; 5046 } 5047 5048 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 5049 5050 /* check the return value and print it if is < 0 */ 5051 if (ret < 0) 5052 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 5053 } 5054 5055 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 5056 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5057 set, "set"); 5058 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 5059 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5060 bonding, "bonding"); 5061 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 5062 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5063 mon_period, "mon_period"); 5064 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 5065 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5066 port_num, UINT8); 5067 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 5068 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5069 period_ms, UINT32); 5070 5071 cmdline_parse_inst_t cmd_set_bond_mon_period = { 5072 .f = cmd_set_bond_mon_period_parsed, 5073 .data = (void *) 0, 5074 .help_str = "set bonding mon_period <port_id> <period_ms>", 5075 .tokens = { 5076 (void *)&cmd_set_bond_mon_period_set, 5077 (void *)&cmd_set_bond_mon_period_bonding, 5078 (void *)&cmd_set_bond_mon_period_mon_period, 5079 (void *)&cmd_set_bond_mon_period_portnum, 5080 (void *)&cmd_set_bond_mon_period_period_ms, 5081 NULL 5082 } 5083 }; 5084 5085 5086 5087 struct cmd_set_bonding_agg_mode_policy_result { 5088 cmdline_fixed_string_t set; 5089 cmdline_fixed_string_t bonding; 5090 cmdline_fixed_string_t agg_mode; 5091 uint8_t port_num; 5092 cmdline_fixed_string_t policy; 5093 }; 5094 5095 5096 static void 5097 cmd_set_bonding_agg_mode(void *parsed_result, 5098 __attribute__((unused)) struct cmdline *cl, 5099 __attribute__((unused)) void *data) 5100 { 5101 struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result; 5102 uint8_t policy = AGG_BANDWIDTH; 5103 5104 if (res->port_num >= nb_ports) { 5105 printf("Port id %d must be less than %d\n", 5106 res->port_num, nb_ports); 5107 return; 5108 } 5109 5110 if (!strcmp(res->policy, "bandwidth")) 5111 policy = AGG_BANDWIDTH; 5112 else if (!strcmp(res->policy, "stable")) 5113 policy = AGG_STABLE; 5114 else if (!strcmp(res->policy, "count")) 5115 policy = AGG_COUNT; 5116 5117 rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy); 5118 } 5119 5120 5121 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set = 5122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5123 set, "set"); 5124 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding = 5125 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5126 bonding, "bonding"); 5127 5128 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = 5129 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5130 agg_mode, "agg_mode"); 5131 5132 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = 5133 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5134 port_num, UINT8); 5135 5136 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = 5137 TOKEN_STRING_INITIALIZER( 5138 struct cmd_set_bonding_balance_xmit_policy_result, 5139 policy, "stable#bandwidth#count"); 5140 5141 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = { 5142 .f = cmd_set_bonding_agg_mode, 5143 .data = (void *) 0, 5144 .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>", 5145 .tokens = { 5146 (void *)&cmd_set_bonding_agg_mode_set, 5147 (void *)&cmd_set_bonding_agg_mode_bonding, 5148 (void *)&cmd_set_bonding_agg_mode_agg_mode, 5149 (void *)&cmd_set_bonding_agg_mode_portnum, 5150 (void *)&cmd_set_bonding_agg_mode_policy_string, 5151 NULL 5152 } 5153 }; 5154 5155 5156 #endif /* RTE_LIBRTE_PMD_BOND */ 5157 5158 /* *** SET FORWARDING MODE *** */ 5159 struct cmd_set_fwd_mode_result { 5160 cmdline_fixed_string_t set; 5161 cmdline_fixed_string_t fwd; 5162 cmdline_fixed_string_t mode; 5163 }; 5164 5165 static void cmd_set_fwd_mode_parsed(void *parsed_result, 5166 __attribute__((unused)) struct cmdline *cl, 5167 __attribute__((unused)) void *data) 5168 { 5169 struct cmd_set_fwd_mode_result *res = parsed_result; 5170 5171 retry_enabled = 0; 5172 set_pkt_forwarding_mode(res->mode); 5173 } 5174 5175 cmdline_parse_token_string_t cmd_setfwd_set = 5176 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 5177 cmdline_parse_token_string_t cmd_setfwd_fwd = 5178 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 5179 cmdline_parse_token_string_t cmd_setfwd_mode = 5180 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 5181 "" /* defined at init */); 5182 5183 cmdline_parse_inst_t cmd_set_fwd_mode = { 5184 .f = cmd_set_fwd_mode_parsed, 5185 .data = NULL, 5186 .help_str = NULL, /* defined at init */ 5187 .tokens = { 5188 (void *)&cmd_setfwd_set, 5189 (void *)&cmd_setfwd_fwd, 5190 (void *)&cmd_setfwd_mode, 5191 NULL, 5192 }, 5193 }; 5194 5195 static void cmd_set_fwd_mode_init(void) 5196 { 5197 char *modes, *c; 5198 static char token[128]; 5199 static char help[256]; 5200 cmdline_parse_token_string_t *token_struct; 5201 5202 modes = list_pkt_forwarding_modes(); 5203 snprintf(help, sizeof(help), "set fwd %s: " 5204 "Set packet forwarding mode", modes); 5205 cmd_set_fwd_mode.help_str = help; 5206 5207 /* string token separator is # */ 5208 for (c = token; *modes != '\0'; modes++) 5209 if (*modes == '|') 5210 *c++ = '#'; 5211 else 5212 *c++ = *modes; 5213 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 5214 token_struct->string_data.str = token; 5215 } 5216 5217 /* *** SET RETRY FORWARDING MODE *** */ 5218 struct cmd_set_fwd_retry_mode_result { 5219 cmdline_fixed_string_t set; 5220 cmdline_fixed_string_t fwd; 5221 cmdline_fixed_string_t mode; 5222 cmdline_fixed_string_t retry; 5223 }; 5224 5225 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 5226 __attribute__((unused)) struct cmdline *cl, 5227 __attribute__((unused)) void *data) 5228 { 5229 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 5230 5231 retry_enabled = 1; 5232 set_pkt_forwarding_mode(res->mode); 5233 } 5234 5235 cmdline_parse_token_string_t cmd_setfwd_retry_set = 5236 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5237 set, "set"); 5238 cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 5239 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5240 fwd, "fwd"); 5241 cmdline_parse_token_string_t cmd_setfwd_retry_mode = 5242 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5243 mode, 5244 "" /* defined at init */); 5245 cmdline_parse_token_string_t cmd_setfwd_retry_retry = 5246 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5247 retry, "retry"); 5248 5249 cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 5250 .f = cmd_set_fwd_retry_mode_parsed, 5251 .data = NULL, 5252 .help_str = NULL, /* defined at init */ 5253 .tokens = { 5254 (void *)&cmd_setfwd_retry_set, 5255 (void *)&cmd_setfwd_retry_fwd, 5256 (void *)&cmd_setfwd_retry_mode, 5257 (void *)&cmd_setfwd_retry_retry, 5258 NULL, 5259 }, 5260 }; 5261 5262 static void cmd_set_fwd_retry_mode_init(void) 5263 { 5264 char *modes, *c; 5265 static char token[128]; 5266 static char help[256]; 5267 cmdline_parse_token_string_t *token_struct; 5268 5269 modes = list_pkt_forwarding_retry_modes(); 5270 snprintf(help, sizeof(help), "set fwd %s retry: " 5271 "Set packet forwarding mode with retry", modes); 5272 cmd_set_fwd_retry_mode.help_str = help; 5273 5274 /* string token separator is # */ 5275 for (c = token; *modes != '\0'; modes++) 5276 if (*modes == '|') 5277 *c++ = '#'; 5278 else 5279 *c++ = *modes; 5280 token_struct = (cmdline_parse_token_string_t *) 5281 cmd_set_fwd_retry_mode.tokens[2]; 5282 token_struct->string_data.str = token; 5283 } 5284 5285 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 5286 struct cmd_set_burst_tx_retry_result { 5287 cmdline_fixed_string_t set; 5288 cmdline_fixed_string_t burst; 5289 cmdline_fixed_string_t tx; 5290 cmdline_fixed_string_t delay; 5291 uint32_t time; 5292 cmdline_fixed_string_t retry; 5293 uint32_t retry_num; 5294 }; 5295 5296 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 5297 __attribute__((unused)) struct cmdline *cl, 5298 __attribute__((unused)) void *data) 5299 { 5300 struct cmd_set_burst_tx_retry_result *res = parsed_result; 5301 5302 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 5303 && !strcmp(res->tx, "tx")) { 5304 if (!strcmp(res->delay, "delay")) 5305 burst_tx_delay_time = res->time; 5306 if (!strcmp(res->retry, "retry")) 5307 burst_tx_retry_num = res->retry_num; 5308 } 5309 5310 } 5311 5312 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 5313 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 5314 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 5315 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 5316 "burst"); 5317 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 5318 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 5319 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 5320 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 5321 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 5322 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 5323 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 5324 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 5325 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 5326 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 5327 5328 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 5329 .f = cmd_set_burst_tx_retry_parsed, 5330 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 5331 .tokens = { 5332 (void *)&cmd_set_burst_tx_retry_set, 5333 (void *)&cmd_set_burst_tx_retry_burst, 5334 (void *)&cmd_set_burst_tx_retry_tx, 5335 (void *)&cmd_set_burst_tx_retry_delay, 5336 (void *)&cmd_set_burst_tx_retry_time, 5337 (void *)&cmd_set_burst_tx_retry_retry, 5338 (void *)&cmd_set_burst_tx_retry_retry_num, 5339 NULL, 5340 }, 5341 }; 5342 5343 /* *** SET PROMISC MODE *** */ 5344 struct cmd_set_promisc_mode_result { 5345 cmdline_fixed_string_t set; 5346 cmdline_fixed_string_t promisc; 5347 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5348 uint8_t port_num; /* valid if "allports" argument == 0 */ 5349 cmdline_fixed_string_t mode; 5350 }; 5351 5352 static void cmd_set_promisc_mode_parsed(void *parsed_result, 5353 __attribute__((unused)) struct cmdline *cl, 5354 void *allports) 5355 { 5356 struct cmd_set_promisc_mode_result *res = parsed_result; 5357 int enable; 5358 portid_t i; 5359 5360 if (!strcmp(res->mode, "on")) 5361 enable = 1; 5362 else 5363 enable = 0; 5364 5365 /* all ports */ 5366 if (allports) { 5367 RTE_ETH_FOREACH_DEV(i) { 5368 if (enable) 5369 rte_eth_promiscuous_enable(i); 5370 else 5371 rte_eth_promiscuous_disable(i); 5372 } 5373 } 5374 else { 5375 if (enable) 5376 rte_eth_promiscuous_enable(res->port_num); 5377 else 5378 rte_eth_promiscuous_disable(res->port_num); 5379 } 5380 } 5381 5382 cmdline_parse_token_string_t cmd_setpromisc_set = 5383 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 5384 cmdline_parse_token_string_t cmd_setpromisc_promisc = 5385 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 5386 "promisc"); 5387 cmdline_parse_token_string_t cmd_setpromisc_portall = 5388 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 5389 "all"); 5390 cmdline_parse_token_num_t cmd_setpromisc_portnum = 5391 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 5392 UINT8); 5393 cmdline_parse_token_string_t cmd_setpromisc_mode = 5394 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 5395 "on#off"); 5396 5397 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 5398 .f = cmd_set_promisc_mode_parsed, 5399 .data = (void *)1, 5400 .help_str = "set promisc all on|off: Set promisc mode for all ports", 5401 .tokens = { 5402 (void *)&cmd_setpromisc_set, 5403 (void *)&cmd_setpromisc_promisc, 5404 (void *)&cmd_setpromisc_portall, 5405 (void *)&cmd_setpromisc_mode, 5406 NULL, 5407 }, 5408 }; 5409 5410 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 5411 .f = cmd_set_promisc_mode_parsed, 5412 .data = (void *)0, 5413 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 5414 .tokens = { 5415 (void *)&cmd_setpromisc_set, 5416 (void *)&cmd_setpromisc_promisc, 5417 (void *)&cmd_setpromisc_portnum, 5418 (void *)&cmd_setpromisc_mode, 5419 NULL, 5420 }, 5421 }; 5422 5423 /* *** SET ALLMULTI MODE *** */ 5424 struct cmd_set_allmulti_mode_result { 5425 cmdline_fixed_string_t set; 5426 cmdline_fixed_string_t allmulti; 5427 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5428 uint8_t port_num; /* valid if "allports" argument == 0 */ 5429 cmdline_fixed_string_t mode; 5430 }; 5431 5432 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 5433 __attribute__((unused)) struct cmdline *cl, 5434 void *allports) 5435 { 5436 struct cmd_set_allmulti_mode_result *res = parsed_result; 5437 int enable; 5438 portid_t i; 5439 5440 if (!strcmp(res->mode, "on")) 5441 enable = 1; 5442 else 5443 enable = 0; 5444 5445 /* all ports */ 5446 if (allports) { 5447 RTE_ETH_FOREACH_DEV(i) { 5448 if (enable) 5449 rte_eth_allmulticast_enable(i); 5450 else 5451 rte_eth_allmulticast_disable(i); 5452 } 5453 } 5454 else { 5455 if (enable) 5456 rte_eth_allmulticast_enable(res->port_num); 5457 else 5458 rte_eth_allmulticast_disable(res->port_num); 5459 } 5460 } 5461 5462 cmdline_parse_token_string_t cmd_setallmulti_set = 5463 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 5464 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 5465 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 5466 "allmulti"); 5467 cmdline_parse_token_string_t cmd_setallmulti_portall = 5468 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 5469 "all"); 5470 cmdline_parse_token_num_t cmd_setallmulti_portnum = 5471 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 5472 UINT8); 5473 cmdline_parse_token_string_t cmd_setallmulti_mode = 5474 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 5475 "on#off"); 5476 5477 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 5478 .f = cmd_set_allmulti_mode_parsed, 5479 .data = (void *)1, 5480 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 5481 .tokens = { 5482 (void *)&cmd_setallmulti_set, 5483 (void *)&cmd_setallmulti_allmulti, 5484 (void *)&cmd_setallmulti_portall, 5485 (void *)&cmd_setallmulti_mode, 5486 NULL, 5487 }, 5488 }; 5489 5490 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 5491 .f = cmd_set_allmulti_mode_parsed, 5492 .data = (void *)0, 5493 .help_str = "set allmulti <port_id> on|off: " 5494 "Set allmulti mode on port_id", 5495 .tokens = { 5496 (void *)&cmd_setallmulti_set, 5497 (void *)&cmd_setallmulti_allmulti, 5498 (void *)&cmd_setallmulti_portnum, 5499 (void *)&cmd_setallmulti_mode, 5500 NULL, 5501 }, 5502 }; 5503 5504 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 5505 struct cmd_link_flow_ctrl_set_result { 5506 cmdline_fixed_string_t set; 5507 cmdline_fixed_string_t flow_ctrl; 5508 cmdline_fixed_string_t rx; 5509 cmdline_fixed_string_t rx_lfc_mode; 5510 cmdline_fixed_string_t tx; 5511 cmdline_fixed_string_t tx_lfc_mode; 5512 cmdline_fixed_string_t mac_ctrl_frame_fwd; 5513 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 5514 cmdline_fixed_string_t autoneg_str; 5515 cmdline_fixed_string_t autoneg; 5516 cmdline_fixed_string_t hw_str; 5517 uint32_t high_water; 5518 cmdline_fixed_string_t lw_str; 5519 uint32_t low_water; 5520 cmdline_fixed_string_t pt_str; 5521 uint16_t pause_time; 5522 cmdline_fixed_string_t xon_str; 5523 uint16_t send_xon; 5524 uint8_t port_id; 5525 }; 5526 5527 cmdline_parse_token_string_t cmd_lfc_set_set = 5528 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5529 set, "set"); 5530 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 5531 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5532 flow_ctrl, "flow_ctrl"); 5533 cmdline_parse_token_string_t cmd_lfc_set_rx = 5534 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5535 rx, "rx"); 5536 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 5537 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5538 rx_lfc_mode, "on#off"); 5539 cmdline_parse_token_string_t cmd_lfc_set_tx = 5540 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5541 tx, "tx"); 5542 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 5543 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5544 tx_lfc_mode, "on#off"); 5545 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 5546 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5547 hw_str, "high_water"); 5548 cmdline_parse_token_num_t cmd_lfc_set_high_water = 5549 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5550 high_water, UINT32); 5551 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 5552 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5553 lw_str, "low_water"); 5554 cmdline_parse_token_num_t cmd_lfc_set_low_water = 5555 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5556 low_water, UINT32); 5557 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 5558 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5559 pt_str, "pause_time"); 5560 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 5561 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5562 pause_time, UINT16); 5563 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 5564 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5565 xon_str, "send_xon"); 5566 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 5567 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5568 send_xon, UINT16); 5569 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 5570 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5571 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 5572 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 5573 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5574 mac_ctrl_frame_fwd_mode, "on#off"); 5575 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 5576 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5577 autoneg_str, "autoneg"); 5578 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 5579 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5580 autoneg, "on#off"); 5581 cmdline_parse_token_num_t cmd_lfc_set_portid = 5582 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5583 port_id, UINT8); 5584 5585 /* forward declaration */ 5586 static void 5587 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 5588 void *data); 5589 5590 cmdline_parse_inst_t cmd_link_flow_control_set = { 5591 .f = cmd_link_flow_ctrl_set_parsed, 5592 .data = NULL, 5593 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 5594 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 5595 "autoneg on|off <port_id>: Configure the Ethernet flow control", 5596 .tokens = { 5597 (void *)&cmd_lfc_set_set, 5598 (void *)&cmd_lfc_set_flow_ctrl, 5599 (void *)&cmd_lfc_set_rx, 5600 (void *)&cmd_lfc_set_rx_mode, 5601 (void *)&cmd_lfc_set_tx, 5602 (void *)&cmd_lfc_set_tx_mode, 5603 (void *)&cmd_lfc_set_high_water, 5604 (void *)&cmd_lfc_set_low_water, 5605 (void *)&cmd_lfc_set_pause_time, 5606 (void *)&cmd_lfc_set_send_xon, 5607 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5608 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5609 (void *)&cmd_lfc_set_autoneg_str, 5610 (void *)&cmd_lfc_set_autoneg, 5611 (void *)&cmd_lfc_set_portid, 5612 NULL, 5613 }, 5614 }; 5615 5616 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 5617 .f = cmd_link_flow_ctrl_set_parsed, 5618 .data = (void *)&cmd_link_flow_control_set_rx, 5619 .help_str = "set flow_ctrl rx on|off <port_id>: " 5620 "Change rx flow control parameter", 5621 .tokens = { 5622 (void *)&cmd_lfc_set_set, 5623 (void *)&cmd_lfc_set_flow_ctrl, 5624 (void *)&cmd_lfc_set_rx, 5625 (void *)&cmd_lfc_set_rx_mode, 5626 (void *)&cmd_lfc_set_portid, 5627 NULL, 5628 }, 5629 }; 5630 5631 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 5632 .f = cmd_link_flow_ctrl_set_parsed, 5633 .data = (void *)&cmd_link_flow_control_set_tx, 5634 .help_str = "set flow_ctrl tx on|off <port_id>: " 5635 "Change tx flow control parameter", 5636 .tokens = { 5637 (void *)&cmd_lfc_set_set, 5638 (void *)&cmd_lfc_set_flow_ctrl, 5639 (void *)&cmd_lfc_set_tx, 5640 (void *)&cmd_lfc_set_tx_mode, 5641 (void *)&cmd_lfc_set_portid, 5642 NULL, 5643 }, 5644 }; 5645 5646 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 5647 .f = cmd_link_flow_ctrl_set_parsed, 5648 .data = (void *)&cmd_link_flow_control_set_hw, 5649 .help_str = "set flow_ctrl high_water <value> <port_id>: " 5650 "Change high water flow control parameter", 5651 .tokens = { 5652 (void *)&cmd_lfc_set_set, 5653 (void *)&cmd_lfc_set_flow_ctrl, 5654 (void *)&cmd_lfc_set_high_water_str, 5655 (void *)&cmd_lfc_set_high_water, 5656 (void *)&cmd_lfc_set_portid, 5657 NULL, 5658 }, 5659 }; 5660 5661 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 5662 .f = cmd_link_flow_ctrl_set_parsed, 5663 .data = (void *)&cmd_link_flow_control_set_lw, 5664 .help_str = "set flow_ctrl low_water <value> <port_id>: " 5665 "Change low water flow control parameter", 5666 .tokens = { 5667 (void *)&cmd_lfc_set_set, 5668 (void *)&cmd_lfc_set_flow_ctrl, 5669 (void *)&cmd_lfc_set_low_water_str, 5670 (void *)&cmd_lfc_set_low_water, 5671 (void *)&cmd_lfc_set_portid, 5672 NULL, 5673 }, 5674 }; 5675 5676 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 5677 .f = cmd_link_flow_ctrl_set_parsed, 5678 .data = (void *)&cmd_link_flow_control_set_pt, 5679 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 5680 "Change pause time flow control parameter", 5681 .tokens = { 5682 (void *)&cmd_lfc_set_set, 5683 (void *)&cmd_lfc_set_flow_ctrl, 5684 (void *)&cmd_lfc_set_pause_time_str, 5685 (void *)&cmd_lfc_set_pause_time, 5686 (void *)&cmd_lfc_set_portid, 5687 NULL, 5688 }, 5689 }; 5690 5691 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 5692 .f = cmd_link_flow_ctrl_set_parsed, 5693 .data = (void *)&cmd_link_flow_control_set_xon, 5694 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 5695 "Change send_xon flow control parameter", 5696 .tokens = { 5697 (void *)&cmd_lfc_set_set, 5698 (void *)&cmd_lfc_set_flow_ctrl, 5699 (void *)&cmd_lfc_set_send_xon_str, 5700 (void *)&cmd_lfc_set_send_xon, 5701 (void *)&cmd_lfc_set_portid, 5702 NULL, 5703 }, 5704 }; 5705 5706 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 5707 .f = cmd_link_flow_ctrl_set_parsed, 5708 .data = (void *)&cmd_link_flow_control_set_macfwd, 5709 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 5710 "Change mac ctrl fwd flow control parameter", 5711 .tokens = { 5712 (void *)&cmd_lfc_set_set, 5713 (void *)&cmd_lfc_set_flow_ctrl, 5714 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5715 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5716 (void *)&cmd_lfc_set_portid, 5717 NULL, 5718 }, 5719 }; 5720 5721 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 5722 .f = cmd_link_flow_ctrl_set_parsed, 5723 .data = (void *)&cmd_link_flow_control_set_autoneg, 5724 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 5725 "Change autoneg flow control parameter", 5726 .tokens = { 5727 (void *)&cmd_lfc_set_set, 5728 (void *)&cmd_lfc_set_flow_ctrl, 5729 (void *)&cmd_lfc_set_autoneg_str, 5730 (void *)&cmd_lfc_set_autoneg, 5731 (void *)&cmd_lfc_set_portid, 5732 NULL, 5733 }, 5734 }; 5735 5736 static void 5737 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 5738 __attribute__((unused)) struct cmdline *cl, 5739 void *data) 5740 { 5741 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 5742 cmdline_parse_inst_t *cmd = data; 5743 struct rte_eth_fc_conf fc_conf; 5744 int rx_fc_en = 0; 5745 int tx_fc_en = 0; 5746 int ret; 5747 5748 /* 5749 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5750 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5751 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5752 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5753 */ 5754 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 5755 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 5756 }; 5757 5758 /* Partial command line, retrieve current configuration */ 5759 if (cmd) { 5760 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 5761 if (ret != 0) { 5762 printf("cannot get current flow ctrl parameters, return" 5763 "code = %d\n", ret); 5764 return; 5765 } 5766 5767 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 5768 (fc_conf.mode == RTE_FC_FULL)) 5769 rx_fc_en = 1; 5770 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 5771 (fc_conf.mode == RTE_FC_FULL)) 5772 tx_fc_en = 1; 5773 } 5774 5775 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 5776 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 5777 5778 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 5779 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 5780 5781 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 5782 5783 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 5784 fc_conf.high_water = res->high_water; 5785 5786 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 5787 fc_conf.low_water = res->low_water; 5788 5789 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 5790 fc_conf.pause_time = res->pause_time; 5791 5792 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 5793 fc_conf.send_xon = res->send_xon; 5794 5795 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 5796 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 5797 fc_conf.mac_ctrl_frame_fwd = 1; 5798 else 5799 fc_conf.mac_ctrl_frame_fwd = 0; 5800 } 5801 5802 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 5803 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 5804 5805 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 5806 if (ret != 0) 5807 printf("bad flow contrl parameter, return code = %d \n", ret); 5808 } 5809 5810 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */ 5811 struct cmd_priority_flow_ctrl_set_result { 5812 cmdline_fixed_string_t set; 5813 cmdline_fixed_string_t pfc_ctrl; 5814 cmdline_fixed_string_t rx; 5815 cmdline_fixed_string_t rx_pfc_mode; 5816 cmdline_fixed_string_t tx; 5817 cmdline_fixed_string_t tx_pfc_mode; 5818 uint32_t high_water; 5819 uint32_t low_water; 5820 uint16_t pause_time; 5821 uint8_t priority; 5822 uint8_t port_id; 5823 }; 5824 5825 static void 5826 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 5827 __attribute__((unused)) struct cmdline *cl, 5828 __attribute__((unused)) void *data) 5829 { 5830 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 5831 struct rte_eth_pfc_conf pfc_conf; 5832 int rx_fc_enable, tx_fc_enable; 5833 int ret; 5834 5835 /* 5836 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5837 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5838 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5839 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5840 */ 5841 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 5842 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 5843 }; 5844 5845 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 5846 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 5847 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 5848 pfc_conf.fc.high_water = res->high_water; 5849 pfc_conf.fc.low_water = res->low_water; 5850 pfc_conf.fc.pause_time = res->pause_time; 5851 pfc_conf.priority = res->priority; 5852 5853 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 5854 if (ret != 0) 5855 printf("bad priority flow contrl parameter, return code = %d \n", ret); 5856 } 5857 5858 cmdline_parse_token_string_t cmd_pfc_set_set = 5859 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5860 set, "set"); 5861 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 5862 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5863 pfc_ctrl, "pfc_ctrl"); 5864 cmdline_parse_token_string_t cmd_pfc_set_rx = 5865 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5866 rx, "rx"); 5867 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 5868 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5869 rx_pfc_mode, "on#off"); 5870 cmdline_parse_token_string_t cmd_pfc_set_tx = 5871 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5872 tx, "tx"); 5873 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 5874 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5875 tx_pfc_mode, "on#off"); 5876 cmdline_parse_token_num_t cmd_pfc_set_high_water = 5877 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5878 high_water, UINT32); 5879 cmdline_parse_token_num_t cmd_pfc_set_low_water = 5880 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5881 low_water, UINT32); 5882 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 5883 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5884 pause_time, UINT16); 5885 cmdline_parse_token_num_t cmd_pfc_set_priority = 5886 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5887 priority, UINT8); 5888 cmdline_parse_token_num_t cmd_pfc_set_portid = 5889 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5890 port_id, UINT8); 5891 5892 cmdline_parse_inst_t cmd_priority_flow_control_set = { 5893 .f = cmd_priority_flow_ctrl_set_parsed, 5894 .data = NULL, 5895 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 5896 "<pause_time> <priority> <port_id>: " 5897 "Configure the Ethernet priority flow control", 5898 .tokens = { 5899 (void *)&cmd_pfc_set_set, 5900 (void *)&cmd_pfc_set_flow_ctrl, 5901 (void *)&cmd_pfc_set_rx, 5902 (void *)&cmd_pfc_set_rx_mode, 5903 (void *)&cmd_pfc_set_tx, 5904 (void *)&cmd_pfc_set_tx_mode, 5905 (void *)&cmd_pfc_set_high_water, 5906 (void *)&cmd_pfc_set_low_water, 5907 (void *)&cmd_pfc_set_pause_time, 5908 (void *)&cmd_pfc_set_priority, 5909 (void *)&cmd_pfc_set_portid, 5910 NULL, 5911 }, 5912 }; 5913 5914 /* *** RESET CONFIGURATION *** */ 5915 struct cmd_reset_result { 5916 cmdline_fixed_string_t reset; 5917 cmdline_fixed_string_t def; 5918 }; 5919 5920 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 5921 struct cmdline *cl, 5922 __attribute__((unused)) void *data) 5923 { 5924 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 5925 set_def_fwd_config(); 5926 } 5927 5928 cmdline_parse_token_string_t cmd_reset_set = 5929 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 5930 cmdline_parse_token_string_t cmd_reset_def = 5931 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 5932 "default"); 5933 5934 cmdline_parse_inst_t cmd_reset = { 5935 .f = cmd_reset_parsed, 5936 .data = NULL, 5937 .help_str = "set default: Reset default forwarding configuration", 5938 .tokens = { 5939 (void *)&cmd_reset_set, 5940 (void *)&cmd_reset_def, 5941 NULL, 5942 }, 5943 }; 5944 5945 /* *** START FORWARDING *** */ 5946 struct cmd_start_result { 5947 cmdline_fixed_string_t start; 5948 }; 5949 5950 cmdline_parse_token_string_t cmd_start_start = 5951 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 5952 5953 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 5954 __attribute__((unused)) struct cmdline *cl, 5955 __attribute__((unused)) void *data) 5956 { 5957 start_packet_forwarding(0); 5958 } 5959 5960 cmdline_parse_inst_t cmd_start = { 5961 .f = cmd_start_parsed, 5962 .data = NULL, 5963 .help_str = "start: Start packet forwarding", 5964 .tokens = { 5965 (void *)&cmd_start_start, 5966 NULL, 5967 }, 5968 }; 5969 5970 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 5971 struct cmd_start_tx_first_result { 5972 cmdline_fixed_string_t start; 5973 cmdline_fixed_string_t tx_first; 5974 }; 5975 5976 static void 5977 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 5978 __attribute__((unused)) struct cmdline *cl, 5979 __attribute__((unused)) void *data) 5980 { 5981 start_packet_forwarding(1); 5982 } 5983 5984 cmdline_parse_token_string_t cmd_start_tx_first_start = 5985 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 5986 "start"); 5987 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 5988 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 5989 tx_first, "tx_first"); 5990 5991 cmdline_parse_inst_t cmd_start_tx_first = { 5992 .f = cmd_start_tx_first_parsed, 5993 .data = NULL, 5994 .help_str = "start tx_first: Start packet forwarding, " 5995 "after sending 1 burst of packets", 5996 .tokens = { 5997 (void *)&cmd_start_tx_first_start, 5998 (void *)&cmd_start_tx_first_tx_first, 5999 NULL, 6000 }, 6001 }; 6002 6003 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 6004 struct cmd_start_tx_first_n_result { 6005 cmdline_fixed_string_t start; 6006 cmdline_fixed_string_t tx_first; 6007 uint32_t tx_num; 6008 }; 6009 6010 static void 6011 cmd_start_tx_first_n_parsed(void *parsed_result, 6012 __attribute__((unused)) struct cmdline *cl, 6013 __attribute__((unused)) void *data) 6014 { 6015 struct cmd_start_tx_first_n_result *res = parsed_result; 6016 6017 start_packet_forwarding(res->tx_num); 6018 } 6019 6020 cmdline_parse_token_string_t cmd_start_tx_first_n_start = 6021 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6022 start, "start"); 6023 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 6024 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6025 tx_first, "tx_first"); 6026 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 6027 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 6028 tx_num, UINT32); 6029 6030 cmdline_parse_inst_t cmd_start_tx_first_n = { 6031 .f = cmd_start_tx_first_n_parsed, 6032 .data = NULL, 6033 .help_str = "start tx_first <num>: " 6034 "packet forwarding, after sending <num> bursts of packets", 6035 .tokens = { 6036 (void *)&cmd_start_tx_first_n_start, 6037 (void *)&cmd_start_tx_first_n_tx_first, 6038 (void *)&cmd_start_tx_first_n_tx_num, 6039 NULL, 6040 }, 6041 }; 6042 6043 /* *** SET LINK UP *** */ 6044 struct cmd_set_link_up_result { 6045 cmdline_fixed_string_t set; 6046 cmdline_fixed_string_t link_up; 6047 cmdline_fixed_string_t port; 6048 uint8_t port_id; 6049 }; 6050 6051 cmdline_parse_token_string_t cmd_set_link_up_set = 6052 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 6053 cmdline_parse_token_string_t cmd_set_link_up_link_up = 6054 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 6055 "link-up"); 6056 cmdline_parse_token_string_t cmd_set_link_up_port = 6057 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 6058 cmdline_parse_token_num_t cmd_set_link_up_port_id = 6059 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); 6060 6061 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 6062 __attribute__((unused)) struct cmdline *cl, 6063 __attribute__((unused)) void *data) 6064 { 6065 struct cmd_set_link_up_result *res = parsed_result; 6066 dev_set_link_up(res->port_id); 6067 } 6068 6069 cmdline_parse_inst_t cmd_set_link_up = { 6070 .f = cmd_set_link_up_parsed, 6071 .data = NULL, 6072 .help_str = "set link-up port <port id>", 6073 .tokens = { 6074 (void *)&cmd_set_link_up_set, 6075 (void *)&cmd_set_link_up_link_up, 6076 (void *)&cmd_set_link_up_port, 6077 (void *)&cmd_set_link_up_port_id, 6078 NULL, 6079 }, 6080 }; 6081 6082 /* *** SET LINK DOWN *** */ 6083 struct cmd_set_link_down_result { 6084 cmdline_fixed_string_t set; 6085 cmdline_fixed_string_t link_down; 6086 cmdline_fixed_string_t port; 6087 uint8_t port_id; 6088 }; 6089 6090 cmdline_parse_token_string_t cmd_set_link_down_set = 6091 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 6092 cmdline_parse_token_string_t cmd_set_link_down_link_down = 6093 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 6094 "link-down"); 6095 cmdline_parse_token_string_t cmd_set_link_down_port = 6096 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 6097 cmdline_parse_token_num_t cmd_set_link_down_port_id = 6098 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); 6099 6100 static void cmd_set_link_down_parsed( 6101 __attribute__((unused)) void *parsed_result, 6102 __attribute__((unused)) struct cmdline *cl, 6103 __attribute__((unused)) void *data) 6104 { 6105 struct cmd_set_link_down_result *res = parsed_result; 6106 dev_set_link_down(res->port_id); 6107 } 6108 6109 cmdline_parse_inst_t cmd_set_link_down = { 6110 .f = cmd_set_link_down_parsed, 6111 .data = NULL, 6112 .help_str = "set link-down port <port id>", 6113 .tokens = { 6114 (void *)&cmd_set_link_down_set, 6115 (void *)&cmd_set_link_down_link_down, 6116 (void *)&cmd_set_link_down_port, 6117 (void *)&cmd_set_link_down_port_id, 6118 NULL, 6119 }, 6120 }; 6121 6122 /* *** SHOW CFG *** */ 6123 struct cmd_showcfg_result { 6124 cmdline_fixed_string_t show; 6125 cmdline_fixed_string_t cfg; 6126 cmdline_fixed_string_t what; 6127 }; 6128 6129 static void cmd_showcfg_parsed(void *parsed_result, 6130 __attribute__((unused)) struct cmdline *cl, 6131 __attribute__((unused)) void *data) 6132 { 6133 struct cmd_showcfg_result *res = parsed_result; 6134 if (!strcmp(res->what, "rxtx")) 6135 rxtx_config_display(); 6136 else if (!strcmp(res->what, "cores")) 6137 fwd_lcores_config_display(); 6138 else if (!strcmp(res->what, "fwd")) 6139 pkt_fwd_config_display(&cur_fwd_config); 6140 else if (!strcmp(res->what, "txpkts")) 6141 show_tx_pkt_segments(); 6142 } 6143 6144 cmdline_parse_token_string_t cmd_showcfg_show = 6145 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 6146 cmdline_parse_token_string_t cmd_showcfg_port = 6147 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 6148 cmdline_parse_token_string_t cmd_showcfg_what = 6149 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 6150 "rxtx#cores#fwd#txpkts"); 6151 6152 cmdline_parse_inst_t cmd_showcfg = { 6153 .f = cmd_showcfg_parsed, 6154 .data = NULL, 6155 .help_str = "show config rxtx|cores|fwd|txpkts", 6156 .tokens = { 6157 (void *)&cmd_showcfg_show, 6158 (void *)&cmd_showcfg_port, 6159 (void *)&cmd_showcfg_what, 6160 NULL, 6161 }, 6162 }; 6163 6164 /* *** SHOW ALL PORT INFO *** */ 6165 struct cmd_showportall_result { 6166 cmdline_fixed_string_t show; 6167 cmdline_fixed_string_t port; 6168 cmdline_fixed_string_t what; 6169 cmdline_fixed_string_t all; 6170 }; 6171 6172 static void cmd_showportall_parsed(void *parsed_result, 6173 __attribute__((unused)) struct cmdline *cl, 6174 __attribute__((unused)) void *data) 6175 { 6176 portid_t i; 6177 6178 struct cmd_showportall_result *res = parsed_result; 6179 if (!strcmp(res->show, "clear")) { 6180 if (!strcmp(res->what, "stats")) 6181 RTE_ETH_FOREACH_DEV(i) 6182 nic_stats_clear(i); 6183 else if (!strcmp(res->what, "xstats")) 6184 RTE_ETH_FOREACH_DEV(i) 6185 nic_xstats_clear(i); 6186 } else if (!strcmp(res->what, "info")) 6187 RTE_ETH_FOREACH_DEV(i) 6188 port_infos_display(i); 6189 else if (!strcmp(res->what, "stats")) 6190 RTE_ETH_FOREACH_DEV(i) 6191 nic_stats_display(i); 6192 else if (!strcmp(res->what, "xstats")) 6193 RTE_ETH_FOREACH_DEV(i) 6194 nic_xstats_display(i); 6195 else if (!strcmp(res->what, "fdir")) 6196 RTE_ETH_FOREACH_DEV(i) 6197 fdir_get_infos(i); 6198 else if (!strcmp(res->what, "stat_qmap")) 6199 RTE_ETH_FOREACH_DEV(i) 6200 nic_stats_mapping_display(i); 6201 else if (!strcmp(res->what, "dcb_tc")) 6202 RTE_ETH_FOREACH_DEV(i) 6203 port_dcb_info_display(i); 6204 else if (!strcmp(res->what, "cap")) 6205 RTE_ETH_FOREACH_DEV(i) 6206 port_offload_cap_display(i); 6207 } 6208 6209 cmdline_parse_token_string_t cmd_showportall_show = 6210 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 6211 "show#clear"); 6212 cmdline_parse_token_string_t cmd_showportall_port = 6213 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 6214 cmdline_parse_token_string_t cmd_showportall_what = 6215 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 6216 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6217 cmdline_parse_token_string_t cmd_showportall_all = 6218 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 6219 cmdline_parse_inst_t cmd_showportall = { 6220 .f = cmd_showportall_parsed, 6221 .data = NULL, 6222 .help_str = "show|clear port " 6223 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all", 6224 .tokens = { 6225 (void *)&cmd_showportall_show, 6226 (void *)&cmd_showportall_port, 6227 (void *)&cmd_showportall_what, 6228 (void *)&cmd_showportall_all, 6229 NULL, 6230 }, 6231 }; 6232 6233 /* *** SHOW PORT INFO *** */ 6234 struct cmd_showport_result { 6235 cmdline_fixed_string_t show; 6236 cmdline_fixed_string_t port; 6237 cmdline_fixed_string_t what; 6238 uint8_t portnum; 6239 }; 6240 6241 static void cmd_showport_parsed(void *parsed_result, 6242 __attribute__((unused)) struct cmdline *cl, 6243 __attribute__((unused)) void *data) 6244 { 6245 struct cmd_showport_result *res = parsed_result; 6246 if (!strcmp(res->show, "clear")) { 6247 if (!strcmp(res->what, "stats")) 6248 nic_stats_clear(res->portnum); 6249 else if (!strcmp(res->what, "xstats")) 6250 nic_xstats_clear(res->portnum); 6251 } else if (!strcmp(res->what, "info")) 6252 port_infos_display(res->portnum); 6253 else if (!strcmp(res->what, "stats")) 6254 nic_stats_display(res->portnum); 6255 else if (!strcmp(res->what, "xstats")) 6256 nic_xstats_display(res->portnum); 6257 else if (!strcmp(res->what, "fdir")) 6258 fdir_get_infos(res->portnum); 6259 else if (!strcmp(res->what, "stat_qmap")) 6260 nic_stats_mapping_display(res->portnum); 6261 else if (!strcmp(res->what, "dcb_tc")) 6262 port_dcb_info_display(res->portnum); 6263 else if (!strcmp(res->what, "cap")) 6264 port_offload_cap_display(res->portnum); 6265 } 6266 6267 cmdline_parse_token_string_t cmd_showport_show = 6268 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 6269 "show#clear"); 6270 cmdline_parse_token_string_t cmd_showport_port = 6271 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 6272 cmdline_parse_token_string_t cmd_showport_what = 6273 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 6274 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6275 cmdline_parse_token_num_t cmd_showport_portnum = 6276 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); 6277 6278 cmdline_parse_inst_t cmd_showport = { 6279 .f = cmd_showport_parsed, 6280 .data = NULL, 6281 .help_str = "show|clear port " 6282 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap " 6283 "<port_id>", 6284 .tokens = { 6285 (void *)&cmd_showport_show, 6286 (void *)&cmd_showport_port, 6287 (void *)&cmd_showport_what, 6288 (void *)&cmd_showport_portnum, 6289 NULL, 6290 }, 6291 }; 6292 6293 /* *** SHOW QUEUE INFO *** */ 6294 struct cmd_showqueue_result { 6295 cmdline_fixed_string_t show; 6296 cmdline_fixed_string_t type; 6297 cmdline_fixed_string_t what; 6298 uint8_t portnum; 6299 uint16_t queuenum; 6300 }; 6301 6302 static void 6303 cmd_showqueue_parsed(void *parsed_result, 6304 __attribute__((unused)) struct cmdline *cl, 6305 __attribute__((unused)) void *data) 6306 { 6307 struct cmd_showqueue_result *res = parsed_result; 6308 6309 if (!strcmp(res->type, "rxq")) 6310 rx_queue_infos_display(res->portnum, res->queuenum); 6311 else if (!strcmp(res->type, "txq")) 6312 tx_queue_infos_display(res->portnum, res->queuenum); 6313 } 6314 6315 cmdline_parse_token_string_t cmd_showqueue_show = 6316 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 6317 cmdline_parse_token_string_t cmd_showqueue_type = 6318 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 6319 cmdline_parse_token_string_t cmd_showqueue_what = 6320 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 6321 cmdline_parse_token_num_t cmd_showqueue_portnum = 6322 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8); 6323 cmdline_parse_token_num_t cmd_showqueue_queuenum = 6324 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); 6325 6326 cmdline_parse_inst_t cmd_showqueue = { 6327 .f = cmd_showqueue_parsed, 6328 .data = NULL, 6329 .help_str = "show rxq|txq info <port_id> <queue_id>", 6330 .tokens = { 6331 (void *)&cmd_showqueue_show, 6332 (void *)&cmd_showqueue_type, 6333 (void *)&cmd_showqueue_what, 6334 (void *)&cmd_showqueue_portnum, 6335 (void *)&cmd_showqueue_queuenum, 6336 NULL, 6337 }, 6338 }; 6339 6340 /* *** READ PORT REGISTER *** */ 6341 struct cmd_read_reg_result { 6342 cmdline_fixed_string_t read; 6343 cmdline_fixed_string_t reg; 6344 uint8_t port_id; 6345 uint32_t reg_off; 6346 }; 6347 6348 static void 6349 cmd_read_reg_parsed(void *parsed_result, 6350 __attribute__((unused)) struct cmdline *cl, 6351 __attribute__((unused)) void *data) 6352 { 6353 struct cmd_read_reg_result *res = parsed_result; 6354 port_reg_display(res->port_id, res->reg_off); 6355 } 6356 6357 cmdline_parse_token_string_t cmd_read_reg_read = 6358 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 6359 cmdline_parse_token_string_t cmd_read_reg_reg = 6360 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 6361 cmdline_parse_token_num_t cmd_read_reg_port_id = 6362 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 6363 cmdline_parse_token_num_t cmd_read_reg_reg_off = 6364 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 6365 6366 cmdline_parse_inst_t cmd_read_reg = { 6367 .f = cmd_read_reg_parsed, 6368 .data = NULL, 6369 .help_str = "read reg <port_id> <reg_off>", 6370 .tokens = { 6371 (void *)&cmd_read_reg_read, 6372 (void *)&cmd_read_reg_reg, 6373 (void *)&cmd_read_reg_port_id, 6374 (void *)&cmd_read_reg_reg_off, 6375 NULL, 6376 }, 6377 }; 6378 6379 /* *** READ PORT REGISTER BIT FIELD *** */ 6380 struct cmd_read_reg_bit_field_result { 6381 cmdline_fixed_string_t read; 6382 cmdline_fixed_string_t regfield; 6383 uint8_t port_id; 6384 uint32_t reg_off; 6385 uint8_t bit1_pos; 6386 uint8_t bit2_pos; 6387 }; 6388 6389 static void 6390 cmd_read_reg_bit_field_parsed(void *parsed_result, 6391 __attribute__((unused)) struct cmdline *cl, 6392 __attribute__((unused)) void *data) 6393 { 6394 struct cmd_read_reg_bit_field_result *res = parsed_result; 6395 port_reg_bit_field_display(res->port_id, res->reg_off, 6396 res->bit1_pos, res->bit2_pos); 6397 } 6398 6399 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 6400 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 6401 "read"); 6402 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 6403 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 6404 regfield, "regfield"); 6405 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 6406 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 6407 UINT8); 6408 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 6409 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 6410 UINT32); 6411 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 6412 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 6413 UINT8); 6414 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 6415 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 6416 UINT8); 6417 6418 cmdline_parse_inst_t cmd_read_reg_bit_field = { 6419 .f = cmd_read_reg_bit_field_parsed, 6420 .data = NULL, 6421 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 6422 "Read register bit field between bit_x and bit_y included", 6423 .tokens = { 6424 (void *)&cmd_read_reg_bit_field_read, 6425 (void *)&cmd_read_reg_bit_field_regfield, 6426 (void *)&cmd_read_reg_bit_field_port_id, 6427 (void *)&cmd_read_reg_bit_field_reg_off, 6428 (void *)&cmd_read_reg_bit_field_bit1_pos, 6429 (void *)&cmd_read_reg_bit_field_bit2_pos, 6430 NULL, 6431 }, 6432 }; 6433 6434 /* *** READ PORT REGISTER BIT *** */ 6435 struct cmd_read_reg_bit_result { 6436 cmdline_fixed_string_t read; 6437 cmdline_fixed_string_t regbit; 6438 uint8_t port_id; 6439 uint32_t reg_off; 6440 uint8_t bit_pos; 6441 }; 6442 6443 static void 6444 cmd_read_reg_bit_parsed(void *parsed_result, 6445 __attribute__((unused)) struct cmdline *cl, 6446 __attribute__((unused)) void *data) 6447 { 6448 struct cmd_read_reg_bit_result *res = parsed_result; 6449 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 6450 } 6451 6452 cmdline_parse_token_string_t cmd_read_reg_bit_read = 6453 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 6454 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 6455 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 6456 regbit, "regbit"); 6457 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 6458 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 6459 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 6460 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 6461 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 6462 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 6463 6464 cmdline_parse_inst_t cmd_read_reg_bit = { 6465 .f = cmd_read_reg_bit_parsed, 6466 .data = NULL, 6467 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 6468 .tokens = { 6469 (void *)&cmd_read_reg_bit_read, 6470 (void *)&cmd_read_reg_bit_regbit, 6471 (void *)&cmd_read_reg_bit_port_id, 6472 (void *)&cmd_read_reg_bit_reg_off, 6473 (void *)&cmd_read_reg_bit_bit_pos, 6474 NULL, 6475 }, 6476 }; 6477 6478 /* *** WRITE PORT REGISTER *** */ 6479 struct cmd_write_reg_result { 6480 cmdline_fixed_string_t write; 6481 cmdline_fixed_string_t reg; 6482 uint8_t port_id; 6483 uint32_t reg_off; 6484 uint32_t value; 6485 }; 6486 6487 static void 6488 cmd_write_reg_parsed(void *parsed_result, 6489 __attribute__((unused)) struct cmdline *cl, 6490 __attribute__((unused)) void *data) 6491 { 6492 struct cmd_write_reg_result *res = parsed_result; 6493 port_reg_set(res->port_id, res->reg_off, res->value); 6494 } 6495 6496 cmdline_parse_token_string_t cmd_write_reg_write = 6497 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 6498 cmdline_parse_token_string_t cmd_write_reg_reg = 6499 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 6500 cmdline_parse_token_num_t cmd_write_reg_port_id = 6501 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 6502 cmdline_parse_token_num_t cmd_write_reg_reg_off = 6503 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 6504 cmdline_parse_token_num_t cmd_write_reg_value = 6505 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 6506 6507 cmdline_parse_inst_t cmd_write_reg = { 6508 .f = cmd_write_reg_parsed, 6509 .data = NULL, 6510 .help_str = "write reg <port_id> <reg_off> <reg_value>", 6511 .tokens = { 6512 (void *)&cmd_write_reg_write, 6513 (void *)&cmd_write_reg_reg, 6514 (void *)&cmd_write_reg_port_id, 6515 (void *)&cmd_write_reg_reg_off, 6516 (void *)&cmd_write_reg_value, 6517 NULL, 6518 }, 6519 }; 6520 6521 /* *** WRITE PORT REGISTER BIT FIELD *** */ 6522 struct cmd_write_reg_bit_field_result { 6523 cmdline_fixed_string_t write; 6524 cmdline_fixed_string_t regfield; 6525 uint8_t port_id; 6526 uint32_t reg_off; 6527 uint8_t bit1_pos; 6528 uint8_t bit2_pos; 6529 uint32_t value; 6530 }; 6531 6532 static void 6533 cmd_write_reg_bit_field_parsed(void *parsed_result, 6534 __attribute__((unused)) struct cmdline *cl, 6535 __attribute__((unused)) void *data) 6536 { 6537 struct cmd_write_reg_bit_field_result *res = parsed_result; 6538 port_reg_bit_field_set(res->port_id, res->reg_off, 6539 res->bit1_pos, res->bit2_pos, res->value); 6540 } 6541 6542 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 6543 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 6544 "write"); 6545 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 6546 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 6547 regfield, "regfield"); 6548 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 6549 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 6550 UINT8); 6551 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 6552 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 6553 UINT32); 6554 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 6555 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 6556 UINT8); 6557 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 6558 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 6559 UINT8); 6560 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 6561 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 6562 UINT32); 6563 6564 cmdline_parse_inst_t cmd_write_reg_bit_field = { 6565 .f = cmd_write_reg_bit_field_parsed, 6566 .data = NULL, 6567 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 6568 "<reg_value>: " 6569 "Set register bit field between bit_x and bit_y included", 6570 .tokens = { 6571 (void *)&cmd_write_reg_bit_field_write, 6572 (void *)&cmd_write_reg_bit_field_regfield, 6573 (void *)&cmd_write_reg_bit_field_port_id, 6574 (void *)&cmd_write_reg_bit_field_reg_off, 6575 (void *)&cmd_write_reg_bit_field_bit1_pos, 6576 (void *)&cmd_write_reg_bit_field_bit2_pos, 6577 (void *)&cmd_write_reg_bit_field_value, 6578 NULL, 6579 }, 6580 }; 6581 6582 /* *** WRITE PORT REGISTER BIT *** */ 6583 struct cmd_write_reg_bit_result { 6584 cmdline_fixed_string_t write; 6585 cmdline_fixed_string_t regbit; 6586 uint8_t port_id; 6587 uint32_t reg_off; 6588 uint8_t bit_pos; 6589 uint8_t value; 6590 }; 6591 6592 static void 6593 cmd_write_reg_bit_parsed(void *parsed_result, 6594 __attribute__((unused)) struct cmdline *cl, 6595 __attribute__((unused)) void *data) 6596 { 6597 struct cmd_write_reg_bit_result *res = parsed_result; 6598 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 6599 } 6600 6601 cmdline_parse_token_string_t cmd_write_reg_bit_write = 6602 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 6603 "write"); 6604 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 6605 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 6606 regbit, "regbit"); 6607 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 6608 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 6609 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 6610 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 6611 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 6612 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 6613 cmdline_parse_token_num_t cmd_write_reg_bit_value = 6614 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 6615 6616 cmdline_parse_inst_t cmd_write_reg_bit = { 6617 .f = cmd_write_reg_bit_parsed, 6618 .data = NULL, 6619 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 6620 "0 <= bit_x <= 31", 6621 .tokens = { 6622 (void *)&cmd_write_reg_bit_write, 6623 (void *)&cmd_write_reg_bit_regbit, 6624 (void *)&cmd_write_reg_bit_port_id, 6625 (void *)&cmd_write_reg_bit_reg_off, 6626 (void *)&cmd_write_reg_bit_bit_pos, 6627 (void *)&cmd_write_reg_bit_value, 6628 NULL, 6629 }, 6630 }; 6631 6632 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 6633 struct cmd_read_rxd_txd_result { 6634 cmdline_fixed_string_t read; 6635 cmdline_fixed_string_t rxd_txd; 6636 uint8_t port_id; 6637 uint16_t queue_id; 6638 uint16_t desc_id; 6639 }; 6640 6641 static void 6642 cmd_read_rxd_txd_parsed(void *parsed_result, 6643 __attribute__((unused)) struct cmdline *cl, 6644 __attribute__((unused)) void *data) 6645 { 6646 struct cmd_read_rxd_txd_result *res = parsed_result; 6647 6648 if (!strcmp(res->rxd_txd, "rxd")) 6649 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6650 else if (!strcmp(res->rxd_txd, "txd")) 6651 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6652 } 6653 6654 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 6655 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 6656 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 6657 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 6658 "rxd#txd"); 6659 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 6660 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 6661 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 6662 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 6663 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 6664 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 6665 6666 cmdline_parse_inst_t cmd_read_rxd_txd = { 6667 .f = cmd_read_rxd_txd_parsed, 6668 .data = NULL, 6669 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 6670 .tokens = { 6671 (void *)&cmd_read_rxd_txd_read, 6672 (void *)&cmd_read_rxd_txd_rxd_txd, 6673 (void *)&cmd_read_rxd_txd_port_id, 6674 (void *)&cmd_read_rxd_txd_queue_id, 6675 (void *)&cmd_read_rxd_txd_desc_id, 6676 NULL, 6677 }, 6678 }; 6679 6680 /* *** QUIT *** */ 6681 struct cmd_quit_result { 6682 cmdline_fixed_string_t quit; 6683 }; 6684 6685 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 6686 struct cmdline *cl, 6687 __attribute__((unused)) void *data) 6688 { 6689 pmd_test_exit(); 6690 cmdline_quit(cl); 6691 } 6692 6693 cmdline_parse_token_string_t cmd_quit_quit = 6694 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 6695 6696 cmdline_parse_inst_t cmd_quit = { 6697 .f = cmd_quit_parsed, 6698 .data = NULL, 6699 .help_str = "quit: Exit application", 6700 .tokens = { 6701 (void *)&cmd_quit_quit, 6702 NULL, 6703 }, 6704 }; 6705 6706 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 6707 struct cmd_mac_addr_result { 6708 cmdline_fixed_string_t mac_addr_cmd; 6709 cmdline_fixed_string_t what; 6710 uint8_t port_num; 6711 struct ether_addr address; 6712 }; 6713 6714 static void cmd_mac_addr_parsed(void *parsed_result, 6715 __attribute__((unused)) struct cmdline *cl, 6716 __attribute__((unused)) void *data) 6717 { 6718 struct cmd_mac_addr_result *res = parsed_result; 6719 int ret; 6720 6721 if (strcmp(res->what, "add") == 0) 6722 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 6723 else if (strcmp(res->what, "set") == 0) 6724 ret = rte_eth_dev_default_mac_addr_set(res->port_num, 6725 &res->address); 6726 else 6727 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 6728 6729 /* check the return value and print it if is < 0 */ 6730 if(ret < 0) 6731 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 6732 6733 } 6734 6735 cmdline_parse_token_string_t cmd_mac_addr_cmd = 6736 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 6737 "mac_addr"); 6738 cmdline_parse_token_string_t cmd_mac_addr_what = 6739 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 6740 "add#remove#set"); 6741 cmdline_parse_token_num_t cmd_mac_addr_portnum = 6742 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 6743 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 6744 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 6745 6746 cmdline_parse_inst_t cmd_mac_addr = { 6747 .f = cmd_mac_addr_parsed, 6748 .data = (void *)0, 6749 .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: " 6750 "Add/Remove/Set MAC address on port_id", 6751 .tokens = { 6752 (void *)&cmd_mac_addr_cmd, 6753 (void *)&cmd_mac_addr_what, 6754 (void *)&cmd_mac_addr_portnum, 6755 (void *)&cmd_mac_addr_addr, 6756 NULL, 6757 }, 6758 }; 6759 6760 6761 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 6762 struct cmd_set_qmap_result { 6763 cmdline_fixed_string_t set; 6764 cmdline_fixed_string_t qmap; 6765 cmdline_fixed_string_t what; 6766 uint8_t port_id; 6767 uint16_t queue_id; 6768 uint8_t map_value; 6769 }; 6770 6771 static void 6772 cmd_set_qmap_parsed(void *parsed_result, 6773 __attribute__((unused)) struct cmdline *cl, 6774 __attribute__((unused)) void *data) 6775 { 6776 struct cmd_set_qmap_result *res = parsed_result; 6777 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 6778 6779 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 6780 } 6781 6782 cmdline_parse_token_string_t cmd_setqmap_set = 6783 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6784 set, "set"); 6785 cmdline_parse_token_string_t cmd_setqmap_qmap = 6786 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6787 qmap, "stat_qmap"); 6788 cmdline_parse_token_string_t cmd_setqmap_what = 6789 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6790 what, "tx#rx"); 6791 cmdline_parse_token_num_t cmd_setqmap_portid = 6792 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6793 port_id, UINT8); 6794 cmdline_parse_token_num_t cmd_setqmap_queueid = 6795 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6796 queue_id, UINT16); 6797 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 6798 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6799 map_value, UINT8); 6800 6801 cmdline_parse_inst_t cmd_set_qmap = { 6802 .f = cmd_set_qmap_parsed, 6803 .data = NULL, 6804 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 6805 "Set statistics mapping value on tx|rx queue_id of port_id", 6806 .tokens = { 6807 (void *)&cmd_setqmap_set, 6808 (void *)&cmd_setqmap_qmap, 6809 (void *)&cmd_setqmap_what, 6810 (void *)&cmd_setqmap_portid, 6811 (void *)&cmd_setqmap_queueid, 6812 (void *)&cmd_setqmap_mapvalue, 6813 NULL, 6814 }, 6815 }; 6816 6817 /* *** CONFIGURE UNICAST HASH TABLE *** */ 6818 struct cmd_set_uc_hash_table { 6819 cmdline_fixed_string_t set; 6820 cmdline_fixed_string_t port; 6821 uint8_t port_id; 6822 cmdline_fixed_string_t what; 6823 struct ether_addr address; 6824 cmdline_fixed_string_t mode; 6825 }; 6826 6827 static void 6828 cmd_set_uc_hash_parsed(void *parsed_result, 6829 __attribute__((unused)) struct cmdline *cl, 6830 __attribute__((unused)) void *data) 6831 { 6832 int ret=0; 6833 struct cmd_set_uc_hash_table *res = parsed_result; 6834 6835 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6836 6837 if (strcmp(res->what, "uta") == 0) 6838 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 6839 &res->address,(uint8_t)is_on); 6840 if (ret < 0) 6841 printf("bad unicast hash table parameter, return code = %d \n", ret); 6842 6843 } 6844 6845 cmdline_parse_token_string_t cmd_set_uc_hash_set = 6846 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6847 set, "set"); 6848 cmdline_parse_token_string_t cmd_set_uc_hash_port = 6849 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6850 port, "port"); 6851 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 6852 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 6853 port_id, UINT8); 6854 cmdline_parse_token_string_t cmd_set_uc_hash_what = 6855 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6856 what, "uta"); 6857 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 6858 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 6859 address); 6860 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 6861 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6862 mode, "on#off"); 6863 6864 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 6865 .f = cmd_set_uc_hash_parsed, 6866 .data = NULL, 6867 .help_str = "set port <port_id> uta <mac_addr> on|off)", 6868 .tokens = { 6869 (void *)&cmd_set_uc_hash_set, 6870 (void *)&cmd_set_uc_hash_port, 6871 (void *)&cmd_set_uc_hash_portid, 6872 (void *)&cmd_set_uc_hash_what, 6873 (void *)&cmd_set_uc_hash_mac, 6874 (void *)&cmd_set_uc_hash_mode, 6875 NULL, 6876 }, 6877 }; 6878 6879 struct cmd_set_uc_all_hash_table { 6880 cmdline_fixed_string_t set; 6881 cmdline_fixed_string_t port; 6882 uint8_t port_id; 6883 cmdline_fixed_string_t what; 6884 cmdline_fixed_string_t value; 6885 cmdline_fixed_string_t mode; 6886 }; 6887 6888 static void 6889 cmd_set_uc_all_hash_parsed(void *parsed_result, 6890 __attribute__((unused)) struct cmdline *cl, 6891 __attribute__((unused)) void *data) 6892 { 6893 int ret=0; 6894 struct cmd_set_uc_all_hash_table *res = parsed_result; 6895 6896 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6897 6898 if ((strcmp(res->what, "uta") == 0) && 6899 (strcmp(res->value, "all") == 0)) 6900 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 6901 if (ret < 0) 6902 printf("bad unicast hash table parameter," 6903 "return code = %d \n", ret); 6904 } 6905 6906 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 6907 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6908 set, "set"); 6909 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 6910 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6911 port, "port"); 6912 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 6913 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 6914 port_id, UINT8); 6915 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 6916 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6917 what, "uta"); 6918 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 6919 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6920 value,"all"); 6921 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 6922 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6923 mode, "on#off"); 6924 6925 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 6926 .f = cmd_set_uc_all_hash_parsed, 6927 .data = NULL, 6928 .help_str = "set port <port_id> uta all on|off", 6929 .tokens = { 6930 (void *)&cmd_set_uc_all_hash_set, 6931 (void *)&cmd_set_uc_all_hash_port, 6932 (void *)&cmd_set_uc_all_hash_portid, 6933 (void *)&cmd_set_uc_all_hash_what, 6934 (void *)&cmd_set_uc_all_hash_value, 6935 (void *)&cmd_set_uc_all_hash_mode, 6936 NULL, 6937 }, 6938 }; 6939 6940 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 6941 struct cmd_set_vf_macvlan_filter { 6942 cmdline_fixed_string_t set; 6943 cmdline_fixed_string_t port; 6944 uint8_t port_id; 6945 cmdline_fixed_string_t vf; 6946 uint8_t vf_id; 6947 struct ether_addr address; 6948 cmdline_fixed_string_t filter_type; 6949 cmdline_fixed_string_t mode; 6950 }; 6951 6952 static void 6953 cmd_set_vf_macvlan_parsed(void *parsed_result, 6954 __attribute__((unused)) struct cmdline *cl, 6955 __attribute__((unused)) void *data) 6956 { 6957 int is_on, ret = 0; 6958 struct cmd_set_vf_macvlan_filter *res = parsed_result; 6959 struct rte_eth_mac_filter filter; 6960 6961 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 6962 6963 (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 6964 6965 /* set VF MAC filter */ 6966 filter.is_vf = 1; 6967 6968 /* set VF ID */ 6969 filter.dst_id = res->vf_id; 6970 6971 if (!strcmp(res->filter_type, "exact-mac")) 6972 filter.filter_type = RTE_MAC_PERFECT_MATCH; 6973 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 6974 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 6975 else if (!strcmp(res->filter_type, "hashmac")) 6976 filter.filter_type = RTE_MAC_HASH_MATCH; 6977 else if (!strcmp(res->filter_type, "hashmac-vlan")) 6978 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 6979 6980 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6981 6982 if (is_on) 6983 ret = rte_eth_dev_filter_ctrl(res->port_id, 6984 RTE_ETH_FILTER_MACVLAN, 6985 RTE_ETH_FILTER_ADD, 6986 &filter); 6987 else 6988 ret = rte_eth_dev_filter_ctrl(res->port_id, 6989 RTE_ETH_FILTER_MACVLAN, 6990 RTE_ETH_FILTER_DELETE, 6991 &filter); 6992 6993 if (ret < 0) 6994 printf("bad set MAC hash parameter, return code = %d\n", ret); 6995 6996 } 6997 6998 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 6999 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7000 set, "set"); 7001 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 7002 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7003 port, "port"); 7004 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 7005 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7006 port_id, UINT8); 7007 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 7008 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7009 vf, "vf"); 7010 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 7011 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7012 vf_id, UINT8); 7013 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 7014 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7015 address); 7016 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 7017 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7018 filter_type, "exact-mac#exact-mac-vlan" 7019 "#hashmac#hashmac-vlan"); 7020 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 7021 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7022 mode, "on#off"); 7023 7024 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 7025 .f = cmd_set_vf_macvlan_parsed, 7026 .data = NULL, 7027 .help_str = "set port <port_id> vf <vf_id> <mac_addr> " 7028 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: " 7029 "Exact match rule: exact match of MAC or MAC and VLAN; " 7030 "hash match rule: hash match of MAC and exact match of VLAN", 7031 .tokens = { 7032 (void *)&cmd_set_vf_macvlan_set, 7033 (void *)&cmd_set_vf_macvlan_port, 7034 (void *)&cmd_set_vf_macvlan_portid, 7035 (void *)&cmd_set_vf_macvlan_vf, 7036 (void *)&cmd_set_vf_macvlan_vf_id, 7037 (void *)&cmd_set_vf_macvlan_mac, 7038 (void *)&cmd_set_vf_macvlan_filter_type, 7039 (void *)&cmd_set_vf_macvlan_mode, 7040 NULL, 7041 }, 7042 }; 7043 7044 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 7045 struct cmd_set_vf_traffic { 7046 cmdline_fixed_string_t set; 7047 cmdline_fixed_string_t port; 7048 uint8_t port_id; 7049 cmdline_fixed_string_t vf; 7050 uint8_t vf_id; 7051 cmdline_fixed_string_t what; 7052 cmdline_fixed_string_t mode; 7053 }; 7054 7055 static void 7056 cmd_set_vf_traffic_parsed(void *parsed_result, 7057 __attribute__((unused)) struct cmdline *cl, 7058 __attribute__((unused)) void *data) 7059 { 7060 struct cmd_set_vf_traffic *res = parsed_result; 7061 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 7062 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7063 7064 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 7065 } 7066 7067 cmdline_parse_token_string_t cmd_setvf_traffic_set = 7068 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7069 set, "set"); 7070 cmdline_parse_token_string_t cmd_setvf_traffic_port = 7071 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7072 port, "port"); 7073 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 7074 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7075 port_id, UINT8); 7076 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 7077 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7078 vf, "vf"); 7079 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 7080 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7081 vf_id, UINT8); 7082 cmdline_parse_token_string_t cmd_setvf_traffic_what = 7083 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7084 what, "tx#rx"); 7085 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 7086 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7087 mode, "on#off"); 7088 7089 cmdline_parse_inst_t cmd_set_vf_traffic = { 7090 .f = cmd_set_vf_traffic_parsed, 7091 .data = NULL, 7092 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 7093 .tokens = { 7094 (void *)&cmd_setvf_traffic_set, 7095 (void *)&cmd_setvf_traffic_port, 7096 (void *)&cmd_setvf_traffic_portid, 7097 (void *)&cmd_setvf_traffic_vf, 7098 (void *)&cmd_setvf_traffic_vfid, 7099 (void *)&cmd_setvf_traffic_what, 7100 (void *)&cmd_setvf_traffic_mode, 7101 NULL, 7102 }, 7103 }; 7104 7105 /* *** CONFIGURE VF RECEIVE MODE *** */ 7106 struct cmd_set_vf_rxmode { 7107 cmdline_fixed_string_t set; 7108 cmdline_fixed_string_t port; 7109 uint8_t port_id; 7110 cmdline_fixed_string_t vf; 7111 uint8_t vf_id; 7112 cmdline_fixed_string_t what; 7113 cmdline_fixed_string_t mode; 7114 cmdline_fixed_string_t on; 7115 }; 7116 7117 static void 7118 cmd_set_vf_rxmode_parsed(void *parsed_result, 7119 __attribute__((unused)) struct cmdline *cl, 7120 __attribute__((unused)) void *data) 7121 { 7122 int ret = -ENOTSUP; 7123 uint16_t rx_mode = 0; 7124 struct cmd_set_vf_rxmode *res = parsed_result; 7125 7126 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 7127 if (!strcmp(res->what,"rxmode")) { 7128 if (!strcmp(res->mode, "AUPE")) 7129 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 7130 else if (!strcmp(res->mode, "ROPE")) 7131 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 7132 else if (!strcmp(res->mode, "BAM")) 7133 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 7134 else if (!strncmp(res->mode, "MPE",3)) 7135 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 7136 } 7137 7138 #ifdef RTE_LIBRTE_IXGBE_PMD 7139 if (ret == -ENOTSUP) 7140 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, 7141 rx_mode, (uint8_t)is_on); 7142 #endif 7143 #ifdef RTE_LIBRTE_BNXT_PMD 7144 if (ret == -ENOTSUP) 7145 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id, 7146 rx_mode, (uint8_t)is_on); 7147 #endif 7148 if (ret < 0) 7149 printf("bad VF receive mode parameter, return code = %d \n", 7150 ret); 7151 } 7152 7153 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 7154 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7155 set, "set"); 7156 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 7157 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7158 port, "port"); 7159 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 7160 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7161 port_id, UINT8); 7162 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 7163 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7164 vf, "vf"); 7165 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 7166 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7167 vf_id, UINT8); 7168 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 7169 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7170 what, "rxmode"); 7171 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 7172 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7173 mode, "AUPE#ROPE#BAM#MPE"); 7174 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 7175 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7176 on, "on#off"); 7177 7178 cmdline_parse_inst_t cmd_set_vf_rxmode = { 7179 .f = cmd_set_vf_rxmode_parsed, 7180 .data = NULL, 7181 .help_str = "set port <port_id> vf <vf_id> rxmode " 7182 "AUPE|ROPE|BAM|MPE on|off", 7183 .tokens = { 7184 (void *)&cmd_set_vf_rxmode_set, 7185 (void *)&cmd_set_vf_rxmode_port, 7186 (void *)&cmd_set_vf_rxmode_portid, 7187 (void *)&cmd_set_vf_rxmode_vf, 7188 (void *)&cmd_set_vf_rxmode_vfid, 7189 (void *)&cmd_set_vf_rxmode_what, 7190 (void *)&cmd_set_vf_rxmode_mode, 7191 (void *)&cmd_set_vf_rxmode_on, 7192 NULL, 7193 }, 7194 }; 7195 7196 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 7197 struct cmd_vf_mac_addr_result { 7198 cmdline_fixed_string_t mac_addr_cmd; 7199 cmdline_fixed_string_t what; 7200 cmdline_fixed_string_t port; 7201 uint8_t port_num; 7202 cmdline_fixed_string_t vf; 7203 uint8_t vf_num; 7204 struct ether_addr address; 7205 }; 7206 7207 static void cmd_vf_mac_addr_parsed(void *parsed_result, 7208 __attribute__((unused)) struct cmdline *cl, 7209 __attribute__((unused)) void *data) 7210 { 7211 struct cmd_vf_mac_addr_result *res = parsed_result; 7212 int ret = 0; 7213 7214 if (strcmp(res->what, "add") == 0) 7215 ret = rte_eth_dev_mac_addr_add(res->port_num, 7216 &res->address, res->vf_num); 7217 if(ret < 0) 7218 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 7219 7220 } 7221 7222 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 7223 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7224 mac_addr_cmd,"mac_addr"); 7225 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 7226 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7227 what,"add"); 7228 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 7229 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7230 port,"port"); 7231 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 7232 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7233 port_num, UINT8); 7234 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 7235 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7236 vf,"vf"); 7237 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 7238 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7239 vf_num, UINT8); 7240 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 7241 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 7242 address); 7243 7244 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 7245 .f = cmd_vf_mac_addr_parsed, 7246 .data = (void *)0, 7247 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 7248 "Add MAC address filtering for a VF on port_id", 7249 .tokens = { 7250 (void *)&cmd_vf_mac_addr_cmd, 7251 (void *)&cmd_vf_mac_addr_what, 7252 (void *)&cmd_vf_mac_addr_port, 7253 (void *)&cmd_vf_mac_addr_portnum, 7254 (void *)&cmd_vf_mac_addr_vf, 7255 (void *)&cmd_vf_mac_addr_vfnum, 7256 (void *)&cmd_vf_mac_addr_addr, 7257 NULL, 7258 }, 7259 }; 7260 7261 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 7262 struct cmd_vf_rx_vlan_filter { 7263 cmdline_fixed_string_t rx_vlan; 7264 cmdline_fixed_string_t what; 7265 uint16_t vlan_id; 7266 cmdline_fixed_string_t port; 7267 uint8_t port_id; 7268 cmdline_fixed_string_t vf; 7269 uint64_t vf_mask; 7270 }; 7271 7272 static void 7273 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 7274 __attribute__((unused)) struct cmdline *cl, 7275 __attribute__((unused)) void *data) 7276 { 7277 struct cmd_vf_rx_vlan_filter *res = parsed_result; 7278 int ret = -ENOTSUP; 7279 7280 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 7281 7282 #ifdef RTE_LIBRTE_IXGBE_PMD 7283 if (ret == -ENOTSUP) 7284 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 7285 res->vlan_id, res->vf_mask, is_add); 7286 #endif 7287 #ifdef RTE_LIBRTE_I40E_PMD 7288 if (ret == -ENOTSUP) 7289 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 7290 res->vlan_id, res->vf_mask, is_add); 7291 #endif 7292 #ifdef RTE_LIBRTE_BNXT_PMD 7293 if (ret == -ENOTSUP) 7294 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id, 7295 res->vlan_id, res->vf_mask, is_add); 7296 #endif 7297 7298 switch (ret) { 7299 case 0: 7300 break; 7301 case -EINVAL: 7302 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n", 7303 res->vlan_id, res->vf_mask); 7304 break; 7305 case -ENODEV: 7306 printf("invalid port_id %d\n", res->port_id); 7307 break; 7308 case -ENOTSUP: 7309 printf("function not implemented or supported\n"); 7310 break; 7311 default: 7312 printf("programming error: (%s)\n", strerror(-ret)); 7313 } 7314 } 7315 7316 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 7317 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7318 rx_vlan, "rx_vlan"); 7319 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 7320 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7321 what, "add#rm"); 7322 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 7323 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7324 vlan_id, UINT16); 7325 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 7326 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7327 port, "port"); 7328 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 7329 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7330 port_id, UINT8); 7331 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 7332 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7333 vf, "vf"); 7334 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 7335 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7336 vf_mask, UINT64); 7337 7338 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 7339 .f = cmd_vf_rx_vlan_filter_parsed, 7340 .data = NULL, 7341 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 7342 "(vf_mask = hexadecimal VF mask)", 7343 .tokens = { 7344 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 7345 (void *)&cmd_vf_rx_vlan_filter_what, 7346 (void *)&cmd_vf_rx_vlan_filter_vlanid, 7347 (void *)&cmd_vf_rx_vlan_filter_port, 7348 (void *)&cmd_vf_rx_vlan_filter_portid, 7349 (void *)&cmd_vf_rx_vlan_filter_vf, 7350 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 7351 NULL, 7352 }, 7353 }; 7354 7355 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 7356 struct cmd_queue_rate_limit_result { 7357 cmdline_fixed_string_t set; 7358 cmdline_fixed_string_t port; 7359 uint8_t port_num; 7360 cmdline_fixed_string_t queue; 7361 uint8_t queue_num; 7362 cmdline_fixed_string_t rate; 7363 uint16_t rate_num; 7364 }; 7365 7366 static void cmd_queue_rate_limit_parsed(void *parsed_result, 7367 __attribute__((unused)) struct cmdline *cl, 7368 __attribute__((unused)) void *data) 7369 { 7370 struct cmd_queue_rate_limit_result *res = parsed_result; 7371 int ret = 0; 7372 7373 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7374 && (strcmp(res->queue, "queue") == 0) 7375 && (strcmp(res->rate, "rate") == 0)) 7376 ret = set_queue_rate_limit(res->port_num, res->queue_num, 7377 res->rate_num); 7378 if (ret < 0) 7379 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7380 7381 } 7382 7383 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 7384 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7385 set, "set"); 7386 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 7387 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7388 port, "port"); 7389 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 7390 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7391 port_num, UINT8); 7392 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 7393 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7394 queue, "queue"); 7395 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 7396 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7397 queue_num, UINT8); 7398 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 7399 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7400 rate, "rate"); 7401 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 7402 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7403 rate_num, UINT16); 7404 7405 cmdline_parse_inst_t cmd_queue_rate_limit = { 7406 .f = cmd_queue_rate_limit_parsed, 7407 .data = (void *)0, 7408 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 7409 "Set rate limit for a queue on port_id", 7410 .tokens = { 7411 (void *)&cmd_queue_rate_limit_set, 7412 (void *)&cmd_queue_rate_limit_port, 7413 (void *)&cmd_queue_rate_limit_portnum, 7414 (void *)&cmd_queue_rate_limit_queue, 7415 (void *)&cmd_queue_rate_limit_queuenum, 7416 (void *)&cmd_queue_rate_limit_rate, 7417 (void *)&cmd_queue_rate_limit_ratenum, 7418 NULL, 7419 }, 7420 }; 7421 7422 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 7423 struct cmd_vf_rate_limit_result { 7424 cmdline_fixed_string_t set; 7425 cmdline_fixed_string_t port; 7426 uint8_t port_num; 7427 cmdline_fixed_string_t vf; 7428 uint8_t vf_num; 7429 cmdline_fixed_string_t rate; 7430 uint16_t rate_num; 7431 cmdline_fixed_string_t q_msk; 7432 uint64_t q_msk_val; 7433 }; 7434 7435 static void cmd_vf_rate_limit_parsed(void *parsed_result, 7436 __attribute__((unused)) struct cmdline *cl, 7437 __attribute__((unused)) void *data) 7438 { 7439 struct cmd_vf_rate_limit_result *res = parsed_result; 7440 int ret = 0; 7441 7442 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7443 && (strcmp(res->vf, "vf") == 0) 7444 && (strcmp(res->rate, "rate") == 0) 7445 && (strcmp(res->q_msk, "queue_mask") == 0)) 7446 ret = set_vf_rate_limit(res->port_num, res->vf_num, 7447 res->rate_num, res->q_msk_val); 7448 if (ret < 0) 7449 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7450 7451 } 7452 7453 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 7454 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7455 set, "set"); 7456 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 7457 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7458 port, "port"); 7459 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 7460 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7461 port_num, UINT8); 7462 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 7463 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7464 vf, "vf"); 7465 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 7466 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7467 vf_num, UINT8); 7468 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 7469 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7470 rate, "rate"); 7471 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 7472 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7473 rate_num, UINT16); 7474 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 7475 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7476 q_msk, "queue_mask"); 7477 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 7478 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7479 q_msk_val, UINT64); 7480 7481 cmdline_parse_inst_t cmd_vf_rate_limit = { 7482 .f = cmd_vf_rate_limit_parsed, 7483 .data = (void *)0, 7484 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 7485 "queue_mask <queue_mask_value>: " 7486 "Set rate limit for queues of VF on port_id", 7487 .tokens = { 7488 (void *)&cmd_vf_rate_limit_set, 7489 (void *)&cmd_vf_rate_limit_port, 7490 (void *)&cmd_vf_rate_limit_portnum, 7491 (void *)&cmd_vf_rate_limit_vf, 7492 (void *)&cmd_vf_rate_limit_vfnum, 7493 (void *)&cmd_vf_rate_limit_rate, 7494 (void *)&cmd_vf_rate_limit_ratenum, 7495 (void *)&cmd_vf_rate_limit_q_msk, 7496 (void *)&cmd_vf_rate_limit_q_msk_val, 7497 NULL, 7498 }, 7499 }; 7500 7501 /* *** ADD TUNNEL FILTER OF A PORT *** */ 7502 struct cmd_tunnel_filter_result { 7503 cmdline_fixed_string_t cmd; 7504 cmdline_fixed_string_t what; 7505 uint8_t port_id; 7506 struct ether_addr outer_mac; 7507 struct ether_addr inner_mac; 7508 cmdline_ipaddr_t ip_value; 7509 uint16_t inner_vlan; 7510 cmdline_fixed_string_t tunnel_type; 7511 cmdline_fixed_string_t filter_type; 7512 uint32_t tenant_id; 7513 uint16_t queue_num; 7514 }; 7515 7516 static void 7517 cmd_tunnel_filter_parsed(void *parsed_result, 7518 __attribute__((unused)) struct cmdline *cl, 7519 __attribute__((unused)) void *data) 7520 { 7521 struct cmd_tunnel_filter_result *res = parsed_result; 7522 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 7523 int ret = 0; 7524 7525 memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf)); 7526 7527 ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac); 7528 ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac); 7529 tunnel_filter_conf.inner_vlan = res->inner_vlan; 7530 7531 if (res->ip_value.family == AF_INET) { 7532 tunnel_filter_conf.ip_addr.ipv4_addr = 7533 res->ip_value.addr.ipv4.s_addr; 7534 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 7535 } else { 7536 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 7537 &(res->ip_value.addr.ipv6), 7538 sizeof(struct in6_addr)); 7539 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 7540 } 7541 7542 if (!strcmp(res->filter_type, "imac-ivlan")) 7543 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 7544 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 7545 tunnel_filter_conf.filter_type = 7546 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 7547 else if (!strcmp(res->filter_type, "imac-tenid")) 7548 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 7549 else if (!strcmp(res->filter_type, "imac")) 7550 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 7551 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 7552 tunnel_filter_conf.filter_type = 7553 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 7554 else if (!strcmp(res->filter_type, "oip")) 7555 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP; 7556 else if (!strcmp(res->filter_type, "iip")) 7557 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP; 7558 else { 7559 printf("The filter type is not supported"); 7560 return; 7561 } 7562 7563 if (!strcmp(res->tunnel_type, "vxlan")) 7564 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 7565 else if (!strcmp(res->tunnel_type, "nvgre")) 7566 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 7567 else if (!strcmp(res->tunnel_type, "ipingre")) 7568 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE; 7569 else { 7570 printf("The tunnel type %s not supported.\n", res->tunnel_type); 7571 return; 7572 } 7573 7574 tunnel_filter_conf.tenant_id = res->tenant_id; 7575 tunnel_filter_conf.queue_id = res->queue_num; 7576 if (!strcmp(res->what, "add")) 7577 ret = rte_eth_dev_filter_ctrl(res->port_id, 7578 RTE_ETH_FILTER_TUNNEL, 7579 RTE_ETH_FILTER_ADD, 7580 &tunnel_filter_conf); 7581 else 7582 ret = rte_eth_dev_filter_ctrl(res->port_id, 7583 RTE_ETH_FILTER_TUNNEL, 7584 RTE_ETH_FILTER_DELETE, 7585 &tunnel_filter_conf); 7586 if (ret < 0) 7587 printf("cmd_tunnel_filter_parsed error: (%s)\n", 7588 strerror(-ret)); 7589 7590 } 7591 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 7592 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7593 cmd, "tunnel_filter"); 7594 cmdline_parse_token_string_t cmd_tunnel_filter_what = 7595 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7596 what, "add#rm"); 7597 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 7598 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7599 port_id, UINT8); 7600 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 7601 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7602 outer_mac); 7603 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 7604 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7605 inner_mac); 7606 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 7607 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7608 inner_vlan, UINT16); 7609 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 7610 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7611 ip_value); 7612 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 7613 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7614 tunnel_type, "vxlan#nvgre#ipingre"); 7615 7616 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 7617 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7618 filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#" 7619 "imac#omac-imac-tenid"); 7620 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 7621 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7622 tenant_id, UINT32); 7623 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 7624 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7625 queue_num, UINT16); 7626 7627 cmdline_parse_inst_t cmd_tunnel_filter = { 7628 .f = cmd_tunnel_filter_parsed, 7629 .data = (void *)0, 7630 .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> " 7631 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|" 7632 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> " 7633 "<queue_id>: Add/Rm tunnel filter of a port", 7634 .tokens = { 7635 (void *)&cmd_tunnel_filter_cmd, 7636 (void *)&cmd_tunnel_filter_what, 7637 (void *)&cmd_tunnel_filter_port_id, 7638 (void *)&cmd_tunnel_filter_outer_mac, 7639 (void *)&cmd_tunnel_filter_inner_mac, 7640 (void *)&cmd_tunnel_filter_ip_value, 7641 (void *)&cmd_tunnel_filter_innner_vlan, 7642 (void *)&cmd_tunnel_filter_tunnel_type, 7643 (void *)&cmd_tunnel_filter_filter_type, 7644 (void *)&cmd_tunnel_filter_tenant_id, 7645 (void *)&cmd_tunnel_filter_queue_num, 7646 NULL, 7647 }, 7648 }; 7649 7650 /* *** CONFIGURE TUNNEL UDP PORT *** */ 7651 struct cmd_tunnel_udp_config { 7652 cmdline_fixed_string_t cmd; 7653 cmdline_fixed_string_t what; 7654 uint16_t udp_port; 7655 uint8_t port_id; 7656 }; 7657 7658 static void 7659 cmd_tunnel_udp_config_parsed(void *parsed_result, 7660 __attribute__((unused)) struct cmdline *cl, 7661 __attribute__((unused)) void *data) 7662 { 7663 struct cmd_tunnel_udp_config *res = parsed_result; 7664 struct rte_eth_udp_tunnel tunnel_udp; 7665 int ret; 7666 7667 tunnel_udp.udp_port = res->udp_port; 7668 7669 if (!strcmp(res->cmd, "rx_vxlan_port")) 7670 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 7671 7672 if (!strcmp(res->what, "add")) 7673 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 7674 &tunnel_udp); 7675 else 7676 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 7677 &tunnel_udp); 7678 7679 if (ret < 0) 7680 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 7681 } 7682 7683 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 7684 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7685 cmd, "rx_vxlan_port"); 7686 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 7687 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7688 what, "add#rm"); 7689 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 7690 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7691 udp_port, UINT16); 7692 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 7693 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7694 port_id, UINT8); 7695 7696 cmdline_parse_inst_t cmd_tunnel_udp_config = { 7697 .f = cmd_tunnel_udp_config_parsed, 7698 .data = (void *)0, 7699 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 7700 "Add/Remove a tunneling UDP port filter", 7701 .tokens = { 7702 (void *)&cmd_tunnel_udp_config_cmd, 7703 (void *)&cmd_tunnel_udp_config_what, 7704 (void *)&cmd_tunnel_udp_config_udp_port, 7705 (void *)&cmd_tunnel_udp_config_port_id, 7706 NULL, 7707 }, 7708 }; 7709 7710 /* *** GLOBAL CONFIG *** */ 7711 struct cmd_global_config_result { 7712 cmdline_fixed_string_t cmd; 7713 uint8_t port_id; 7714 cmdline_fixed_string_t cfg_type; 7715 uint8_t len; 7716 }; 7717 7718 static void 7719 cmd_global_config_parsed(void *parsed_result, 7720 __attribute__((unused)) struct cmdline *cl, 7721 __attribute__((unused)) void *data) 7722 { 7723 struct cmd_global_config_result *res = parsed_result; 7724 struct rte_eth_global_cfg conf; 7725 int ret; 7726 7727 memset(&conf, 0, sizeof(conf)); 7728 conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN; 7729 conf.cfg.gre_key_len = res->len; 7730 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE, 7731 RTE_ETH_FILTER_SET, &conf); 7732 if (ret != 0) 7733 printf("Global config error\n"); 7734 } 7735 7736 cmdline_parse_token_string_t cmd_global_config_cmd = 7737 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, 7738 "global_config"); 7739 cmdline_parse_token_num_t cmd_global_config_port_id = 7740 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8); 7741 cmdline_parse_token_string_t cmd_global_config_type = 7742 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, 7743 cfg_type, "gre-key-len"); 7744 cmdline_parse_token_num_t cmd_global_config_gre_key_len = 7745 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, 7746 len, UINT8); 7747 7748 cmdline_parse_inst_t cmd_global_config = { 7749 .f = cmd_global_config_parsed, 7750 .data = (void *)NULL, 7751 .help_str = "global_config <port_id> gre-key-len <key_len>", 7752 .tokens = { 7753 (void *)&cmd_global_config_cmd, 7754 (void *)&cmd_global_config_port_id, 7755 (void *)&cmd_global_config_type, 7756 (void *)&cmd_global_config_gre_key_len, 7757 NULL, 7758 }, 7759 }; 7760 7761 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 7762 struct cmd_set_mirror_mask_result { 7763 cmdline_fixed_string_t set; 7764 cmdline_fixed_string_t port; 7765 uint8_t port_id; 7766 cmdline_fixed_string_t mirror; 7767 uint8_t rule_id; 7768 cmdline_fixed_string_t what; 7769 cmdline_fixed_string_t value; 7770 cmdline_fixed_string_t dstpool; 7771 uint8_t dstpool_id; 7772 cmdline_fixed_string_t on; 7773 }; 7774 7775 cmdline_parse_token_string_t cmd_mirror_mask_set = 7776 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7777 set, "set"); 7778 cmdline_parse_token_string_t cmd_mirror_mask_port = 7779 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7780 port, "port"); 7781 cmdline_parse_token_num_t cmd_mirror_mask_portid = 7782 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7783 port_id, UINT8); 7784 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 7785 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7786 mirror, "mirror-rule"); 7787 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 7788 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7789 rule_id, UINT8); 7790 cmdline_parse_token_string_t cmd_mirror_mask_what = 7791 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7792 what, "pool-mirror-up#pool-mirror-down" 7793 "#vlan-mirror"); 7794 cmdline_parse_token_string_t cmd_mirror_mask_value = 7795 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7796 value, NULL); 7797 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 7798 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7799 dstpool, "dst-pool"); 7800 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 7801 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7802 dstpool_id, UINT8); 7803 cmdline_parse_token_string_t cmd_mirror_mask_on = 7804 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7805 on, "on#off"); 7806 7807 static void 7808 cmd_set_mirror_mask_parsed(void *parsed_result, 7809 __attribute__((unused)) struct cmdline *cl, 7810 __attribute__((unused)) void *data) 7811 { 7812 int ret,nb_item,i; 7813 struct cmd_set_mirror_mask_result *res = parsed_result; 7814 struct rte_eth_mirror_conf mr_conf; 7815 7816 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7817 7818 unsigned int vlan_list[ETH_MIRROR_MAX_VLANS]; 7819 7820 mr_conf.dst_pool = res->dstpool_id; 7821 7822 if (!strcmp(res->what, "pool-mirror-up")) { 7823 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7824 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP; 7825 } else if (!strcmp(res->what, "pool-mirror-down")) { 7826 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7827 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN; 7828 } else if (!strcmp(res->what, "vlan-mirror")) { 7829 mr_conf.rule_type = ETH_MIRROR_VLAN; 7830 nb_item = parse_item_list(res->value, "vlan", 7831 ETH_MIRROR_MAX_VLANS, vlan_list, 1); 7832 if (nb_item <= 0) 7833 return; 7834 7835 for (i = 0; i < nb_item; i++) { 7836 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 7837 printf("Invalid vlan_id: must be < 4096\n"); 7838 return; 7839 } 7840 7841 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 7842 mr_conf.vlan.vlan_mask |= 1ULL << i; 7843 } 7844 } 7845 7846 if (!strcmp(res->on, "on")) 7847 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7848 res->rule_id, 1); 7849 else 7850 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7851 res->rule_id, 0); 7852 if (ret < 0) 7853 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7854 } 7855 7856 cmdline_parse_inst_t cmd_set_mirror_mask = { 7857 .f = cmd_set_mirror_mask_parsed, 7858 .data = NULL, 7859 .help_str = "set port <port_id> mirror-rule <rule_id> " 7860 "pool-mirror-up|pool-mirror-down|vlan-mirror " 7861 "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off", 7862 .tokens = { 7863 (void *)&cmd_mirror_mask_set, 7864 (void *)&cmd_mirror_mask_port, 7865 (void *)&cmd_mirror_mask_portid, 7866 (void *)&cmd_mirror_mask_mirror, 7867 (void *)&cmd_mirror_mask_ruleid, 7868 (void *)&cmd_mirror_mask_what, 7869 (void *)&cmd_mirror_mask_value, 7870 (void *)&cmd_mirror_mask_dstpool, 7871 (void *)&cmd_mirror_mask_poolid, 7872 (void *)&cmd_mirror_mask_on, 7873 NULL, 7874 }, 7875 }; 7876 7877 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */ 7878 struct cmd_set_mirror_link_result { 7879 cmdline_fixed_string_t set; 7880 cmdline_fixed_string_t port; 7881 uint8_t port_id; 7882 cmdline_fixed_string_t mirror; 7883 uint8_t rule_id; 7884 cmdline_fixed_string_t what; 7885 cmdline_fixed_string_t dstpool; 7886 uint8_t dstpool_id; 7887 cmdline_fixed_string_t on; 7888 }; 7889 7890 cmdline_parse_token_string_t cmd_mirror_link_set = 7891 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7892 set, "set"); 7893 cmdline_parse_token_string_t cmd_mirror_link_port = 7894 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7895 port, "port"); 7896 cmdline_parse_token_num_t cmd_mirror_link_portid = 7897 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7898 port_id, UINT8); 7899 cmdline_parse_token_string_t cmd_mirror_link_mirror = 7900 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7901 mirror, "mirror-rule"); 7902 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 7903 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7904 rule_id, UINT8); 7905 cmdline_parse_token_string_t cmd_mirror_link_what = 7906 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7907 what, "uplink-mirror#downlink-mirror"); 7908 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 7909 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7910 dstpool, "dst-pool"); 7911 cmdline_parse_token_num_t cmd_mirror_link_poolid = 7912 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7913 dstpool_id, UINT8); 7914 cmdline_parse_token_string_t cmd_mirror_link_on = 7915 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7916 on, "on#off"); 7917 7918 static void 7919 cmd_set_mirror_link_parsed(void *parsed_result, 7920 __attribute__((unused)) struct cmdline *cl, 7921 __attribute__((unused)) void *data) 7922 { 7923 int ret; 7924 struct cmd_set_mirror_link_result *res = parsed_result; 7925 struct rte_eth_mirror_conf mr_conf; 7926 7927 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7928 if (!strcmp(res->what, "uplink-mirror")) 7929 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT; 7930 else 7931 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT; 7932 7933 mr_conf.dst_pool = res->dstpool_id; 7934 7935 if (!strcmp(res->on, "on")) 7936 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7937 res->rule_id, 1); 7938 else 7939 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7940 res->rule_id, 0); 7941 7942 /* check the return value and print it if is < 0 */ 7943 if (ret < 0) 7944 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7945 7946 } 7947 7948 cmdline_parse_inst_t cmd_set_mirror_link = { 7949 .f = cmd_set_mirror_link_parsed, 7950 .data = NULL, 7951 .help_str = "set port <port_id> mirror-rule <rule_id> " 7952 "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off", 7953 .tokens = { 7954 (void *)&cmd_mirror_link_set, 7955 (void *)&cmd_mirror_link_port, 7956 (void *)&cmd_mirror_link_portid, 7957 (void *)&cmd_mirror_link_mirror, 7958 (void *)&cmd_mirror_link_ruleid, 7959 (void *)&cmd_mirror_link_what, 7960 (void *)&cmd_mirror_link_dstpool, 7961 (void *)&cmd_mirror_link_poolid, 7962 (void *)&cmd_mirror_link_on, 7963 NULL, 7964 }, 7965 }; 7966 7967 /* *** RESET VM MIRROR RULE *** */ 7968 struct cmd_rm_mirror_rule_result { 7969 cmdline_fixed_string_t reset; 7970 cmdline_fixed_string_t port; 7971 uint8_t port_id; 7972 cmdline_fixed_string_t mirror; 7973 uint8_t rule_id; 7974 }; 7975 7976 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 7977 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7978 reset, "reset"); 7979 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 7980 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7981 port, "port"); 7982 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 7983 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7984 port_id, UINT8); 7985 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 7986 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7987 mirror, "mirror-rule"); 7988 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 7989 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7990 rule_id, UINT8); 7991 7992 static void 7993 cmd_reset_mirror_rule_parsed(void *parsed_result, 7994 __attribute__((unused)) struct cmdline *cl, 7995 __attribute__((unused)) void *data) 7996 { 7997 int ret; 7998 struct cmd_set_mirror_link_result *res = parsed_result; 7999 /* check rule_id */ 8000 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 8001 if(ret < 0) 8002 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 8003 } 8004 8005 cmdline_parse_inst_t cmd_reset_mirror_rule = { 8006 .f = cmd_reset_mirror_rule_parsed, 8007 .data = NULL, 8008 .help_str = "reset port <port_id> mirror-rule <rule_id>", 8009 .tokens = { 8010 (void *)&cmd_rm_mirror_rule_reset, 8011 (void *)&cmd_rm_mirror_rule_port, 8012 (void *)&cmd_rm_mirror_rule_portid, 8013 (void *)&cmd_rm_mirror_rule_mirror, 8014 (void *)&cmd_rm_mirror_rule_ruleid, 8015 NULL, 8016 }, 8017 }; 8018 8019 /* ******************************************************************************** */ 8020 8021 struct cmd_dump_result { 8022 cmdline_fixed_string_t dump; 8023 }; 8024 8025 static void 8026 dump_struct_sizes(void) 8027 { 8028 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 8029 DUMP_SIZE(struct rte_mbuf); 8030 DUMP_SIZE(struct rte_mempool); 8031 DUMP_SIZE(struct rte_ring); 8032 #undef DUMP_SIZE 8033 } 8034 8035 static void cmd_dump_parsed(void *parsed_result, 8036 __attribute__((unused)) struct cmdline *cl, 8037 __attribute__((unused)) void *data) 8038 { 8039 struct cmd_dump_result *res = parsed_result; 8040 8041 if (!strcmp(res->dump, "dump_physmem")) 8042 rte_dump_physmem_layout(stdout); 8043 else if (!strcmp(res->dump, "dump_memzone")) 8044 rte_memzone_dump(stdout); 8045 else if (!strcmp(res->dump, "dump_struct_sizes")) 8046 dump_struct_sizes(); 8047 else if (!strcmp(res->dump, "dump_ring")) 8048 rte_ring_list_dump(stdout); 8049 else if (!strcmp(res->dump, "dump_mempool")) 8050 rte_mempool_list_dump(stdout); 8051 else if (!strcmp(res->dump, "dump_devargs")) 8052 rte_eal_devargs_dump(stdout); 8053 else if (!strcmp(res->dump, "dump_log_types")) 8054 rte_log_dump(stdout); 8055 } 8056 8057 cmdline_parse_token_string_t cmd_dump_dump = 8058 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 8059 "dump_physmem#" 8060 "dump_memzone#" 8061 "dump_struct_sizes#" 8062 "dump_ring#" 8063 "dump_mempool#" 8064 "dump_devargs#" 8065 "dump_log_types"); 8066 8067 cmdline_parse_inst_t cmd_dump = { 8068 .f = cmd_dump_parsed, /* function to call */ 8069 .data = NULL, /* 2nd arg of func */ 8070 .help_str = "Dump status", 8071 .tokens = { /* token list, NULL terminated */ 8072 (void *)&cmd_dump_dump, 8073 NULL, 8074 }, 8075 }; 8076 8077 /* ******************************************************************************** */ 8078 8079 struct cmd_dump_one_result { 8080 cmdline_fixed_string_t dump; 8081 cmdline_fixed_string_t name; 8082 }; 8083 8084 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 8085 __attribute__((unused)) void *data) 8086 { 8087 struct cmd_dump_one_result *res = parsed_result; 8088 8089 if (!strcmp(res->dump, "dump_ring")) { 8090 struct rte_ring *r; 8091 r = rte_ring_lookup(res->name); 8092 if (r == NULL) { 8093 cmdline_printf(cl, "Cannot find ring\n"); 8094 return; 8095 } 8096 rte_ring_dump(stdout, r); 8097 } else if (!strcmp(res->dump, "dump_mempool")) { 8098 struct rte_mempool *mp; 8099 mp = rte_mempool_lookup(res->name); 8100 if (mp == NULL) { 8101 cmdline_printf(cl, "Cannot find mempool\n"); 8102 return; 8103 } 8104 rte_mempool_dump(stdout, mp); 8105 } 8106 } 8107 8108 cmdline_parse_token_string_t cmd_dump_one_dump = 8109 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 8110 "dump_ring#dump_mempool"); 8111 8112 cmdline_parse_token_string_t cmd_dump_one_name = 8113 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 8114 8115 cmdline_parse_inst_t cmd_dump_one = { 8116 .f = cmd_dump_one_parsed, /* function to call */ 8117 .data = NULL, /* 2nd arg of func */ 8118 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 8119 .tokens = { /* token list, NULL terminated */ 8120 (void *)&cmd_dump_one_dump, 8121 (void *)&cmd_dump_one_name, 8122 NULL, 8123 }, 8124 }; 8125 8126 /* *** Add/Del syn filter *** */ 8127 struct cmd_syn_filter_result { 8128 cmdline_fixed_string_t filter; 8129 uint8_t port_id; 8130 cmdline_fixed_string_t ops; 8131 cmdline_fixed_string_t priority; 8132 cmdline_fixed_string_t high; 8133 cmdline_fixed_string_t queue; 8134 uint16_t queue_id; 8135 }; 8136 8137 static void 8138 cmd_syn_filter_parsed(void *parsed_result, 8139 __attribute__((unused)) struct cmdline *cl, 8140 __attribute__((unused)) void *data) 8141 { 8142 struct cmd_syn_filter_result *res = parsed_result; 8143 struct rte_eth_syn_filter syn_filter; 8144 int ret = 0; 8145 8146 ret = rte_eth_dev_filter_supported(res->port_id, 8147 RTE_ETH_FILTER_SYN); 8148 if (ret < 0) { 8149 printf("syn filter is not supported on port %u.\n", 8150 res->port_id); 8151 return; 8152 } 8153 8154 memset(&syn_filter, 0, sizeof(syn_filter)); 8155 8156 if (!strcmp(res->ops, "add")) { 8157 if (!strcmp(res->high, "high")) 8158 syn_filter.hig_pri = 1; 8159 else 8160 syn_filter.hig_pri = 0; 8161 8162 syn_filter.queue = res->queue_id; 8163 ret = rte_eth_dev_filter_ctrl(res->port_id, 8164 RTE_ETH_FILTER_SYN, 8165 RTE_ETH_FILTER_ADD, 8166 &syn_filter); 8167 } else 8168 ret = rte_eth_dev_filter_ctrl(res->port_id, 8169 RTE_ETH_FILTER_SYN, 8170 RTE_ETH_FILTER_DELETE, 8171 &syn_filter); 8172 8173 if (ret < 0) 8174 printf("syn filter programming error: (%s)\n", 8175 strerror(-ret)); 8176 } 8177 8178 cmdline_parse_token_string_t cmd_syn_filter_filter = 8179 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8180 filter, "syn_filter"); 8181 cmdline_parse_token_num_t cmd_syn_filter_port_id = 8182 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8183 port_id, UINT8); 8184 cmdline_parse_token_string_t cmd_syn_filter_ops = 8185 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8186 ops, "add#del"); 8187 cmdline_parse_token_string_t cmd_syn_filter_priority = 8188 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8189 priority, "priority"); 8190 cmdline_parse_token_string_t cmd_syn_filter_high = 8191 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8192 high, "high#low"); 8193 cmdline_parse_token_string_t cmd_syn_filter_queue = 8194 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8195 queue, "queue"); 8196 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 8197 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8198 queue_id, UINT16); 8199 8200 cmdline_parse_inst_t cmd_syn_filter = { 8201 .f = cmd_syn_filter_parsed, 8202 .data = NULL, 8203 .help_str = "syn_filter <port_id> add|del priority high|low queue " 8204 "<queue_id>: Add/Delete syn filter", 8205 .tokens = { 8206 (void *)&cmd_syn_filter_filter, 8207 (void *)&cmd_syn_filter_port_id, 8208 (void *)&cmd_syn_filter_ops, 8209 (void *)&cmd_syn_filter_priority, 8210 (void *)&cmd_syn_filter_high, 8211 (void *)&cmd_syn_filter_queue, 8212 (void *)&cmd_syn_filter_queue_id, 8213 NULL, 8214 }, 8215 }; 8216 8217 /* *** ADD/REMOVE A 2tuple FILTER *** */ 8218 struct cmd_2tuple_filter_result { 8219 cmdline_fixed_string_t filter; 8220 uint8_t port_id; 8221 cmdline_fixed_string_t ops; 8222 cmdline_fixed_string_t dst_port; 8223 uint16_t dst_port_value; 8224 cmdline_fixed_string_t protocol; 8225 uint8_t protocol_value; 8226 cmdline_fixed_string_t mask; 8227 uint8_t mask_value; 8228 cmdline_fixed_string_t tcp_flags; 8229 uint8_t tcp_flags_value; 8230 cmdline_fixed_string_t priority; 8231 uint8_t priority_value; 8232 cmdline_fixed_string_t queue; 8233 uint16_t queue_id; 8234 }; 8235 8236 static void 8237 cmd_2tuple_filter_parsed(void *parsed_result, 8238 __attribute__((unused)) struct cmdline *cl, 8239 __attribute__((unused)) void *data) 8240 { 8241 struct rte_eth_ntuple_filter filter; 8242 struct cmd_2tuple_filter_result *res = parsed_result; 8243 int ret = 0; 8244 8245 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 8246 if (ret < 0) { 8247 printf("ntuple filter is not supported on port %u.\n", 8248 res->port_id); 8249 return; 8250 } 8251 8252 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 8253 8254 filter.flags = RTE_2TUPLE_FLAGS; 8255 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 8256 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 8257 filter.proto = res->protocol_value; 8258 filter.priority = res->priority_value; 8259 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 8260 printf("nonzero tcp_flags is only meaningful" 8261 " when protocol is TCP.\n"); 8262 return; 8263 } 8264 if (res->tcp_flags_value > TCP_FLAG_ALL) { 8265 printf("invalid TCP flags.\n"); 8266 return; 8267 } 8268 8269 if (res->tcp_flags_value != 0) { 8270 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 8271 filter.tcp_flags = res->tcp_flags_value; 8272 } 8273 8274 /* need convert to big endian. */ 8275 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 8276 filter.queue = res->queue_id; 8277 8278 if (!strcmp(res->ops, "add")) 8279 ret = rte_eth_dev_filter_ctrl(res->port_id, 8280 RTE_ETH_FILTER_NTUPLE, 8281 RTE_ETH_FILTER_ADD, 8282 &filter); 8283 else 8284 ret = rte_eth_dev_filter_ctrl(res->port_id, 8285 RTE_ETH_FILTER_NTUPLE, 8286 RTE_ETH_FILTER_DELETE, 8287 &filter); 8288 if (ret < 0) 8289 printf("2tuple filter programming error: (%s)\n", 8290 strerror(-ret)); 8291 8292 } 8293 8294 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 8295 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8296 filter, "2tuple_filter"); 8297 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 8298 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8299 port_id, UINT8); 8300 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 8301 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8302 ops, "add#del"); 8303 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 8304 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8305 dst_port, "dst_port"); 8306 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 8307 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8308 dst_port_value, UINT16); 8309 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 8310 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8311 protocol, "protocol"); 8312 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 8313 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8314 protocol_value, UINT8); 8315 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 8316 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8317 mask, "mask"); 8318 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 8319 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8320 mask_value, INT8); 8321 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 8322 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8323 tcp_flags, "tcp_flags"); 8324 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 8325 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8326 tcp_flags_value, UINT8); 8327 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 8328 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8329 priority, "priority"); 8330 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 8331 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8332 priority_value, UINT8); 8333 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 8334 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 8335 queue, "queue"); 8336 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 8337 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 8338 queue_id, UINT16); 8339 8340 cmdline_parse_inst_t cmd_2tuple_filter = { 8341 .f = cmd_2tuple_filter_parsed, 8342 .data = NULL, 8343 .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol " 8344 "<value> mask <value> tcp_flags <value> priority <value> queue " 8345 "<queue_id>: Add a 2tuple filter", 8346 .tokens = { 8347 (void *)&cmd_2tuple_filter_filter, 8348 (void *)&cmd_2tuple_filter_port_id, 8349 (void *)&cmd_2tuple_filter_ops, 8350 (void *)&cmd_2tuple_filter_dst_port, 8351 (void *)&cmd_2tuple_filter_dst_port_value, 8352 (void *)&cmd_2tuple_filter_protocol, 8353 (void *)&cmd_2tuple_filter_protocol_value, 8354 (void *)&cmd_2tuple_filter_mask, 8355 (void *)&cmd_2tuple_filter_mask_value, 8356 (void *)&cmd_2tuple_filter_tcp_flags, 8357 (void *)&cmd_2tuple_filter_tcp_flags_value, 8358 (void *)&cmd_2tuple_filter_priority, 8359 (void *)&cmd_2tuple_filter_priority_value, 8360 (void *)&cmd_2tuple_filter_queue, 8361 (void *)&cmd_2tuple_filter_queue_id, 8362 NULL, 8363 }, 8364 }; 8365 8366 /* *** ADD/REMOVE A 5tuple FILTER *** */ 8367 struct cmd_5tuple_filter_result { 8368 cmdline_fixed_string_t filter; 8369 uint8_t port_id; 8370 cmdline_fixed_string_t ops; 8371 cmdline_fixed_string_t dst_ip; 8372 cmdline_ipaddr_t dst_ip_value; 8373 cmdline_fixed_string_t src_ip; 8374 cmdline_ipaddr_t src_ip_value; 8375 cmdline_fixed_string_t dst_port; 8376 uint16_t dst_port_value; 8377 cmdline_fixed_string_t src_port; 8378 uint16_t src_port_value; 8379 cmdline_fixed_string_t protocol; 8380 uint8_t protocol_value; 8381 cmdline_fixed_string_t mask; 8382 uint8_t mask_value; 8383 cmdline_fixed_string_t tcp_flags; 8384 uint8_t tcp_flags_value; 8385 cmdline_fixed_string_t priority; 8386 uint8_t priority_value; 8387 cmdline_fixed_string_t queue; 8388 uint16_t queue_id; 8389 }; 8390 8391 static void 8392 cmd_5tuple_filter_parsed(void *parsed_result, 8393 __attribute__((unused)) struct cmdline *cl, 8394 __attribute__((unused)) void *data) 8395 { 8396 struct rte_eth_ntuple_filter filter; 8397 struct cmd_5tuple_filter_result *res = parsed_result; 8398 int ret = 0; 8399 8400 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 8401 if (ret < 0) { 8402 printf("ntuple filter is not supported on port %u.\n", 8403 res->port_id); 8404 return; 8405 } 8406 8407 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 8408 8409 filter.flags = RTE_5TUPLE_FLAGS; 8410 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 8411 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 8412 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 8413 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 8414 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 8415 filter.proto = res->protocol_value; 8416 filter.priority = res->priority_value; 8417 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 8418 printf("nonzero tcp_flags is only meaningful" 8419 " when protocol is TCP.\n"); 8420 return; 8421 } 8422 if (res->tcp_flags_value > TCP_FLAG_ALL) { 8423 printf("invalid TCP flags.\n"); 8424 return; 8425 } 8426 8427 if (res->tcp_flags_value != 0) { 8428 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 8429 filter.tcp_flags = res->tcp_flags_value; 8430 } 8431 8432 if (res->dst_ip_value.family == AF_INET) 8433 /* no need to convert, already big endian. */ 8434 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 8435 else { 8436 if (filter.dst_ip_mask == 0) { 8437 printf("can not support ipv6 involved compare.\n"); 8438 return; 8439 } 8440 filter.dst_ip = 0; 8441 } 8442 8443 if (res->src_ip_value.family == AF_INET) 8444 /* no need to convert, already big endian. */ 8445 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 8446 else { 8447 if (filter.src_ip_mask == 0) { 8448 printf("can not support ipv6 involved compare.\n"); 8449 return; 8450 } 8451 filter.src_ip = 0; 8452 } 8453 /* need convert to big endian. */ 8454 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 8455 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 8456 filter.queue = res->queue_id; 8457 8458 if (!strcmp(res->ops, "add")) 8459 ret = rte_eth_dev_filter_ctrl(res->port_id, 8460 RTE_ETH_FILTER_NTUPLE, 8461 RTE_ETH_FILTER_ADD, 8462 &filter); 8463 else 8464 ret = rte_eth_dev_filter_ctrl(res->port_id, 8465 RTE_ETH_FILTER_NTUPLE, 8466 RTE_ETH_FILTER_DELETE, 8467 &filter); 8468 if (ret < 0) 8469 printf("5tuple filter programming error: (%s)\n", 8470 strerror(-ret)); 8471 } 8472 8473 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 8474 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8475 filter, "5tuple_filter"); 8476 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 8477 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8478 port_id, UINT8); 8479 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 8480 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8481 ops, "add#del"); 8482 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 8483 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8484 dst_ip, "dst_ip"); 8485 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 8486 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8487 dst_ip_value); 8488 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 8489 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8490 src_ip, "src_ip"); 8491 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 8492 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8493 src_ip_value); 8494 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 8495 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8496 dst_port, "dst_port"); 8497 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 8498 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8499 dst_port_value, UINT16); 8500 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 8501 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8502 src_port, "src_port"); 8503 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 8504 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8505 src_port_value, UINT16); 8506 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 8507 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8508 protocol, "protocol"); 8509 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 8510 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8511 protocol_value, UINT8); 8512 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 8513 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8514 mask, "mask"); 8515 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 8516 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8517 mask_value, INT8); 8518 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 8519 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8520 tcp_flags, "tcp_flags"); 8521 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 8522 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8523 tcp_flags_value, UINT8); 8524 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 8525 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8526 priority, "priority"); 8527 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 8528 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8529 priority_value, UINT8); 8530 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 8531 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8532 queue, "queue"); 8533 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 8534 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8535 queue_id, UINT16); 8536 8537 cmdline_parse_inst_t cmd_5tuple_filter = { 8538 .f = cmd_5tuple_filter_parsed, 8539 .data = NULL, 8540 .help_str = "5tuple_filter <port_id> add|del dst_ip <value> " 8541 "src_ip <value> dst_port <value> src_port <value> " 8542 "protocol <value> mask <value> tcp_flags <value> " 8543 "priority <value> queue <queue_id>: Add/Del a 5tuple filter", 8544 .tokens = { 8545 (void *)&cmd_5tuple_filter_filter, 8546 (void *)&cmd_5tuple_filter_port_id, 8547 (void *)&cmd_5tuple_filter_ops, 8548 (void *)&cmd_5tuple_filter_dst_ip, 8549 (void *)&cmd_5tuple_filter_dst_ip_value, 8550 (void *)&cmd_5tuple_filter_src_ip, 8551 (void *)&cmd_5tuple_filter_src_ip_value, 8552 (void *)&cmd_5tuple_filter_dst_port, 8553 (void *)&cmd_5tuple_filter_dst_port_value, 8554 (void *)&cmd_5tuple_filter_src_port, 8555 (void *)&cmd_5tuple_filter_src_port_value, 8556 (void *)&cmd_5tuple_filter_protocol, 8557 (void *)&cmd_5tuple_filter_protocol_value, 8558 (void *)&cmd_5tuple_filter_mask, 8559 (void *)&cmd_5tuple_filter_mask_value, 8560 (void *)&cmd_5tuple_filter_tcp_flags, 8561 (void *)&cmd_5tuple_filter_tcp_flags_value, 8562 (void *)&cmd_5tuple_filter_priority, 8563 (void *)&cmd_5tuple_filter_priority_value, 8564 (void *)&cmd_5tuple_filter_queue, 8565 (void *)&cmd_5tuple_filter_queue_id, 8566 NULL, 8567 }, 8568 }; 8569 8570 /* *** ADD/REMOVE A flex FILTER *** */ 8571 struct cmd_flex_filter_result { 8572 cmdline_fixed_string_t filter; 8573 cmdline_fixed_string_t ops; 8574 uint8_t port_id; 8575 cmdline_fixed_string_t len; 8576 uint8_t len_value; 8577 cmdline_fixed_string_t bytes; 8578 cmdline_fixed_string_t bytes_value; 8579 cmdline_fixed_string_t mask; 8580 cmdline_fixed_string_t mask_value; 8581 cmdline_fixed_string_t priority; 8582 uint8_t priority_value; 8583 cmdline_fixed_string_t queue; 8584 uint16_t queue_id; 8585 }; 8586 8587 static int xdigit2val(unsigned char c) 8588 { 8589 int val; 8590 if (isdigit(c)) 8591 val = c - '0'; 8592 else if (isupper(c)) 8593 val = c - 'A' + 10; 8594 else 8595 val = c - 'a' + 10; 8596 return val; 8597 } 8598 8599 static void 8600 cmd_flex_filter_parsed(void *parsed_result, 8601 __attribute__((unused)) struct cmdline *cl, 8602 __attribute__((unused)) void *data) 8603 { 8604 int ret = 0; 8605 struct rte_eth_flex_filter filter; 8606 struct cmd_flex_filter_result *res = parsed_result; 8607 char *bytes_ptr, *mask_ptr; 8608 uint16_t len, i, j = 0; 8609 char c; 8610 int val; 8611 uint8_t byte = 0; 8612 8613 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 8614 printf("the len exceed the max length 128\n"); 8615 return; 8616 } 8617 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 8618 filter.len = res->len_value; 8619 filter.priority = res->priority_value; 8620 filter.queue = res->queue_id; 8621 bytes_ptr = res->bytes_value; 8622 mask_ptr = res->mask_value; 8623 8624 /* translate bytes string to array. */ 8625 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 8626 (bytes_ptr[1] == 'X'))) 8627 bytes_ptr += 2; 8628 len = strnlen(bytes_ptr, res->len_value * 2); 8629 if (len == 0 || (len % 8 != 0)) { 8630 printf("please check len and bytes input\n"); 8631 return; 8632 } 8633 for (i = 0; i < len; i++) { 8634 c = bytes_ptr[i]; 8635 if (isxdigit(c) == 0) { 8636 /* invalid characters. */ 8637 printf("invalid input\n"); 8638 return; 8639 } 8640 val = xdigit2val(c); 8641 if (i % 2) { 8642 byte |= val; 8643 filter.bytes[j] = byte; 8644 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 8645 j++; 8646 byte = 0; 8647 } else 8648 byte |= val << 4; 8649 } 8650 printf("\n"); 8651 /* translate mask string to uint8_t array. */ 8652 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 8653 (mask_ptr[1] == 'X'))) 8654 mask_ptr += 2; 8655 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 8656 if (len == 0) { 8657 printf("invalid input\n"); 8658 return; 8659 } 8660 j = 0; 8661 byte = 0; 8662 for (i = 0; i < len; i++) { 8663 c = mask_ptr[i]; 8664 if (isxdigit(c) == 0) { 8665 /* invalid characters. */ 8666 printf("invalid input\n"); 8667 return; 8668 } 8669 val = xdigit2val(c); 8670 if (i % 2) { 8671 byte |= val; 8672 filter.mask[j] = byte; 8673 printf("mask[%d]:%02x ", j, filter.mask[j]); 8674 j++; 8675 byte = 0; 8676 } else 8677 byte |= val << 4; 8678 } 8679 printf("\n"); 8680 8681 if (!strcmp(res->ops, "add")) 8682 ret = rte_eth_dev_filter_ctrl(res->port_id, 8683 RTE_ETH_FILTER_FLEXIBLE, 8684 RTE_ETH_FILTER_ADD, 8685 &filter); 8686 else 8687 ret = rte_eth_dev_filter_ctrl(res->port_id, 8688 RTE_ETH_FILTER_FLEXIBLE, 8689 RTE_ETH_FILTER_DELETE, 8690 &filter); 8691 8692 if (ret < 0) 8693 printf("flex filter setting error: (%s)\n", strerror(-ret)); 8694 } 8695 8696 cmdline_parse_token_string_t cmd_flex_filter_filter = 8697 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8698 filter, "flex_filter"); 8699 cmdline_parse_token_num_t cmd_flex_filter_port_id = 8700 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8701 port_id, UINT8); 8702 cmdline_parse_token_string_t cmd_flex_filter_ops = 8703 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8704 ops, "add#del"); 8705 cmdline_parse_token_string_t cmd_flex_filter_len = 8706 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8707 len, "len"); 8708 cmdline_parse_token_num_t cmd_flex_filter_len_value = 8709 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8710 len_value, UINT8); 8711 cmdline_parse_token_string_t cmd_flex_filter_bytes = 8712 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8713 bytes, "bytes"); 8714 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 8715 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8716 bytes_value, NULL); 8717 cmdline_parse_token_string_t cmd_flex_filter_mask = 8718 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8719 mask, "mask"); 8720 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 8721 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8722 mask_value, NULL); 8723 cmdline_parse_token_string_t cmd_flex_filter_priority = 8724 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8725 priority, "priority"); 8726 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 8727 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8728 priority_value, UINT8); 8729 cmdline_parse_token_string_t cmd_flex_filter_queue = 8730 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8731 queue, "queue"); 8732 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 8733 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8734 queue_id, UINT16); 8735 cmdline_parse_inst_t cmd_flex_filter = { 8736 .f = cmd_flex_filter_parsed, 8737 .data = NULL, 8738 .help_str = "flex_filter <port_id> add|del len <value> bytes " 8739 "<value> mask <value> priority <value> queue <queue_id>: " 8740 "Add/Del a flex filter", 8741 .tokens = { 8742 (void *)&cmd_flex_filter_filter, 8743 (void *)&cmd_flex_filter_port_id, 8744 (void *)&cmd_flex_filter_ops, 8745 (void *)&cmd_flex_filter_len, 8746 (void *)&cmd_flex_filter_len_value, 8747 (void *)&cmd_flex_filter_bytes, 8748 (void *)&cmd_flex_filter_bytes_value, 8749 (void *)&cmd_flex_filter_mask, 8750 (void *)&cmd_flex_filter_mask_value, 8751 (void *)&cmd_flex_filter_priority, 8752 (void *)&cmd_flex_filter_priority_value, 8753 (void *)&cmd_flex_filter_queue, 8754 (void *)&cmd_flex_filter_queue_id, 8755 NULL, 8756 }, 8757 }; 8758 8759 /* *** Filters Control *** */ 8760 8761 /* *** deal with ethertype filter *** */ 8762 struct cmd_ethertype_filter_result { 8763 cmdline_fixed_string_t filter; 8764 uint8_t port_id; 8765 cmdline_fixed_string_t ops; 8766 cmdline_fixed_string_t mac; 8767 struct ether_addr mac_addr; 8768 cmdline_fixed_string_t ethertype; 8769 uint16_t ethertype_value; 8770 cmdline_fixed_string_t drop; 8771 cmdline_fixed_string_t queue; 8772 uint16_t queue_id; 8773 }; 8774 8775 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 8776 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8777 filter, "ethertype_filter"); 8778 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 8779 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8780 port_id, UINT8); 8781 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 8782 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8783 ops, "add#del"); 8784 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 8785 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8786 mac, "mac_addr#mac_ignr"); 8787 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 8788 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 8789 mac_addr); 8790 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 8791 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8792 ethertype, "ethertype"); 8793 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 8794 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8795 ethertype_value, UINT16); 8796 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 8797 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8798 drop, "drop#fwd"); 8799 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 8800 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8801 queue, "queue"); 8802 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 8803 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8804 queue_id, UINT16); 8805 8806 static void 8807 cmd_ethertype_filter_parsed(void *parsed_result, 8808 __attribute__((unused)) struct cmdline *cl, 8809 __attribute__((unused)) void *data) 8810 { 8811 struct cmd_ethertype_filter_result *res = parsed_result; 8812 struct rte_eth_ethertype_filter filter; 8813 int ret = 0; 8814 8815 ret = rte_eth_dev_filter_supported(res->port_id, 8816 RTE_ETH_FILTER_ETHERTYPE); 8817 if (ret < 0) { 8818 printf("ethertype filter is not supported on port %u.\n", 8819 res->port_id); 8820 return; 8821 } 8822 8823 memset(&filter, 0, sizeof(filter)); 8824 if (!strcmp(res->mac, "mac_addr")) { 8825 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 8826 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr, 8827 sizeof(struct ether_addr)); 8828 } 8829 if (!strcmp(res->drop, "drop")) 8830 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 8831 filter.ether_type = res->ethertype_value; 8832 filter.queue = res->queue_id; 8833 8834 if (!strcmp(res->ops, "add")) 8835 ret = rte_eth_dev_filter_ctrl(res->port_id, 8836 RTE_ETH_FILTER_ETHERTYPE, 8837 RTE_ETH_FILTER_ADD, 8838 &filter); 8839 else 8840 ret = rte_eth_dev_filter_ctrl(res->port_id, 8841 RTE_ETH_FILTER_ETHERTYPE, 8842 RTE_ETH_FILTER_DELETE, 8843 &filter); 8844 if (ret < 0) 8845 printf("ethertype filter programming error: (%s)\n", 8846 strerror(-ret)); 8847 } 8848 8849 cmdline_parse_inst_t cmd_ethertype_filter = { 8850 .f = cmd_ethertype_filter_parsed, 8851 .data = NULL, 8852 .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr " 8853 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: " 8854 "Add or delete an ethertype filter entry", 8855 .tokens = { 8856 (void *)&cmd_ethertype_filter_filter, 8857 (void *)&cmd_ethertype_filter_port_id, 8858 (void *)&cmd_ethertype_filter_ops, 8859 (void *)&cmd_ethertype_filter_mac, 8860 (void *)&cmd_ethertype_filter_mac_addr, 8861 (void *)&cmd_ethertype_filter_ethertype, 8862 (void *)&cmd_ethertype_filter_ethertype_value, 8863 (void *)&cmd_ethertype_filter_drop, 8864 (void *)&cmd_ethertype_filter_queue, 8865 (void *)&cmd_ethertype_filter_queue_id, 8866 NULL, 8867 }, 8868 }; 8869 8870 /* *** deal with flow director filter *** */ 8871 struct cmd_flow_director_result { 8872 cmdline_fixed_string_t flow_director_filter; 8873 uint8_t port_id; 8874 cmdline_fixed_string_t mode; 8875 cmdline_fixed_string_t mode_value; 8876 cmdline_fixed_string_t ops; 8877 cmdline_fixed_string_t flow; 8878 cmdline_fixed_string_t flow_type; 8879 cmdline_fixed_string_t ether; 8880 uint16_t ether_type; 8881 cmdline_fixed_string_t src; 8882 cmdline_ipaddr_t ip_src; 8883 uint16_t port_src; 8884 cmdline_fixed_string_t dst; 8885 cmdline_ipaddr_t ip_dst; 8886 uint16_t port_dst; 8887 cmdline_fixed_string_t verify_tag; 8888 uint32_t verify_tag_value; 8889 cmdline_ipaddr_t tos; 8890 uint8_t tos_value; 8891 cmdline_ipaddr_t proto; 8892 uint8_t proto_value; 8893 cmdline_ipaddr_t ttl; 8894 uint8_t ttl_value; 8895 cmdline_fixed_string_t vlan; 8896 uint16_t vlan_value; 8897 cmdline_fixed_string_t flexbytes; 8898 cmdline_fixed_string_t flexbytes_value; 8899 cmdline_fixed_string_t pf_vf; 8900 cmdline_fixed_string_t drop; 8901 cmdline_fixed_string_t queue; 8902 uint16_t queue_id; 8903 cmdline_fixed_string_t fd_id; 8904 uint32_t fd_id_value; 8905 cmdline_fixed_string_t mac; 8906 struct ether_addr mac_addr; 8907 cmdline_fixed_string_t tunnel; 8908 cmdline_fixed_string_t tunnel_type; 8909 cmdline_fixed_string_t tunnel_id; 8910 uint32_t tunnel_id_value; 8911 }; 8912 8913 static inline int 8914 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 8915 { 8916 char s[256]; 8917 const char *p, *p0 = q_arg; 8918 char *end; 8919 unsigned long int_fld; 8920 char *str_fld[max_num]; 8921 int i; 8922 unsigned size; 8923 int ret = -1; 8924 8925 p = strchr(p0, '('); 8926 if (p == NULL) 8927 return -1; 8928 ++p; 8929 p0 = strchr(p, ')'); 8930 if (p0 == NULL) 8931 return -1; 8932 8933 size = p0 - p; 8934 if (size >= sizeof(s)) 8935 return -1; 8936 8937 snprintf(s, sizeof(s), "%.*s", size, p); 8938 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 8939 if (ret < 0 || ret > max_num) 8940 return -1; 8941 for (i = 0; i < ret; i++) { 8942 errno = 0; 8943 int_fld = strtoul(str_fld[i], &end, 0); 8944 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 8945 return -1; 8946 flexbytes[i] = (uint8_t)int_fld; 8947 } 8948 return ret; 8949 } 8950 8951 static uint16_t 8952 str2flowtype(char *string) 8953 { 8954 uint8_t i = 0; 8955 static const struct { 8956 char str[32]; 8957 uint16_t type; 8958 } flowtype_str[] = { 8959 {"raw", RTE_ETH_FLOW_RAW}, 8960 {"ipv4", RTE_ETH_FLOW_IPV4}, 8961 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 8962 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 8963 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 8964 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 8965 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 8966 {"ipv6", RTE_ETH_FLOW_IPV6}, 8967 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 8968 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 8969 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 8970 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 8971 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 8972 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 8973 }; 8974 8975 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 8976 if (!strcmp(flowtype_str[i].str, string)) 8977 return flowtype_str[i].type; 8978 } 8979 return RTE_ETH_FLOW_UNKNOWN; 8980 } 8981 8982 static enum rte_eth_fdir_tunnel_type 8983 str2fdir_tunneltype(char *string) 8984 { 8985 uint8_t i = 0; 8986 8987 static const struct { 8988 char str[32]; 8989 enum rte_eth_fdir_tunnel_type type; 8990 } tunneltype_str[] = { 8991 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE}, 8992 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN}, 8993 }; 8994 8995 for (i = 0; i < RTE_DIM(tunneltype_str); i++) { 8996 if (!strcmp(tunneltype_str[i].str, string)) 8997 return tunneltype_str[i].type; 8998 } 8999 return RTE_FDIR_TUNNEL_TYPE_UNKNOWN; 9000 } 9001 9002 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 9003 do { \ 9004 if ((ip_addr).family == AF_INET) \ 9005 (ip) = (ip_addr).addr.ipv4.s_addr; \ 9006 else { \ 9007 printf("invalid parameter.\n"); \ 9008 return; \ 9009 } \ 9010 } while (0) 9011 9012 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 9013 do { \ 9014 if ((ip_addr).family == AF_INET6) \ 9015 (void)rte_memcpy(&(ip), \ 9016 &((ip_addr).addr.ipv6), \ 9017 sizeof(struct in6_addr)); \ 9018 else { \ 9019 printf("invalid parameter.\n"); \ 9020 return; \ 9021 } \ 9022 } while (0) 9023 9024 static void 9025 cmd_flow_director_filter_parsed(void *parsed_result, 9026 __attribute__((unused)) struct cmdline *cl, 9027 __attribute__((unused)) void *data) 9028 { 9029 struct cmd_flow_director_result *res = parsed_result; 9030 struct rte_eth_fdir_filter entry; 9031 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 9032 char *end; 9033 unsigned long vf_id; 9034 int ret = 0; 9035 9036 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 9037 if (ret < 0) { 9038 printf("flow director is not supported on port %u.\n", 9039 res->port_id); 9040 return; 9041 } 9042 memset(flexbytes, 0, sizeof(flexbytes)); 9043 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 9044 9045 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9046 if (strcmp(res->mode_value, "MAC-VLAN")) { 9047 printf("Please set mode to MAC-VLAN.\n"); 9048 return; 9049 } 9050 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9051 if (strcmp(res->mode_value, "Tunnel")) { 9052 printf("Please set mode to Tunnel.\n"); 9053 return; 9054 } 9055 } else { 9056 if (strcmp(res->mode_value, "IP")) { 9057 printf("Please set mode to IP.\n"); 9058 return; 9059 } 9060 entry.input.flow_type = str2flowtype(res->flow_type); 9061 } 9062 9063 ret = parse_flexbytes(res->flexbytes_value, 9064 flexbytes, 9065 RTE_ETH_FDIR_MAX_FLEXLEN); 9066 if (ret < 0) { 9067 printf("error: Cannot parse flexbytes input.\n"); 9068 return; 9069 } 9070 9071 switch (entry.input.flow_type) { 9072 case RTE_ETH_FLOW_FRAG_IPV4: 9073 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 9074 entry.input.flow.ip4_flow.proto = res->proto_value; 9075 /* fall-through */ 9076 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 9077 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 9078 IPV4_ADDR_TO_UINT(res->ip_dst, 9079 entry.input.flow.ip4_flow.dst_ip); 9080 IPV4_ADDR_TO_UINT(res->ip_src, 9081 entry.input.flow.ip4_flow.src_ip); 9082 entry.input.flow.ip4_flow.tos = res->tos_value; 9083 entry.input.flow.ip4_flow.ttl = res->ttl_value; 9084 /* need convert to big endian. */ 9085 entry.input.flow.udp4_flow.dst_port = 9086 rte_cpu_to_be_16(res->port_dst); 9087 entry.input.flow.udp4_flow.src_port = 9088 rte_cpu_to_be_16(res->port_src); 9089 break; 9090 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 9091 IPV4_ADDR_TO_UINT(res->ip_dst, 9092 entry.input.flow.sctp4_flow.ip.dst_ip); 9093 IPV4_ADDR_TO_UINT(res->ip_src, 9094 entry.input.flow.sctp4_flow.ip.src_ip); 9095 entry.input.flow.ip4_flow.tos = res->tos_value; 9096 entry.input.flow.ip4_flow.ttl = res->ttl_value; 9097 /* need convert to big endian. */ 9098 entry.input.flow.sctp4_flow.dst_port = 9099 rte_cpu_to_be_16(res->port_dst); 9100 entry.input.flow.sctp4_flow.src_port = 9101 rte_cpu_to_be_16(res->port_src); 9102 entry.input.flow.sctp4_flow.verify_tag = 9103 rte_cpu_to_be_32(res->verify_tag_value); 9104 break; 9105 case RTE_ETH_FLOW_FRAG_IPV6: 9106 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 9107 entry.input.flow.ipv6_flow.proto = res->proto_value; 9108 /* fall-through */ 9109 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 9110 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 9111 IPV6_ADDR_TO_ARRAY(res->ip_dst, 9112 entry.input.flow.ipv6_flow.dst_ip); 9113 IPV6_ADDR_TO_ARRAY(res->ip_src, 9114 entry.input.flow.ipv6_flow.src_ip); 9115 entry.input.flow.ipv6_flow.tc = res->tos_value; 9116 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 9117 /* need convert to big endian. */ 9118 entry.input.flow.udp6_flow.dst_port = 9119 rte_cpu_to_be_16(res->port_dst); 9120 entry.input.flow.udp6_flow.src_port = 9121 rte_cpu_to_be_16(res->port_src); 9122 break; 9123 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 9124 IPV6_ADDR_TO_ARRAY(res->ip_dst, 9125 entry.input.flow.sctp6_flow.ip.dst_ip); 9126 IPV6_ADDR_TO_ARRAY(res->ip_src, 9127 entry.input.flow.sctp6_flow.ip.src_ip); 9128 entry.input.flow.ipv6_flow.tc = res->tos_value; 9129 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 9130 /* need convert to big endian. */ 9131 entry.input.flow.sctp6_flow.dst_port = 9132 rte_cpu_to_be_16(res->port_dst); 9133 entry.input.flow.sctp6_flow.src_port = 9134 rte_cpu_to_be_16(res->port_src); 9135 entry.input.flow.sctp6_flow.verify_tag = 9136 rte_cpu_to_be_32(res->verify_tag_value); 9137 break; 9138 case RTE_ETH_FLOW_L2_PAYLOAD: 9139 entry.input.flow.l2_flow.ether_type = 9140 rte_cpu_to_be_16(res->ether_type); 9141 break; 9142 default: 9143 break; 9144 } 9145 9146 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 9147 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, 9148 &res->mac_addr, 9149 sizeof(struct ether_addr)); 9150 9151 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9152 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, 9153 &res->mac_addr, 9154 sizeof(struct ether_addr)); 9155 entry.input.flow.tunnel_flow.tunnel_type = 9156 str2fdir_tunneltype(res->tunnel_type); 9157 entry.input.flow.tunnel_flow.tunnel_id = 9158 rte_cpu_to_be_32(res->tunnel_id_value); 9159 } 9160 9161 (void)rte_memcpy(entry.input.flow_ext.flexbytes, 9162 flexbytes, 9163 RTE_ETH_FDIR_MAX_FLEXLEN); 9164 9165 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 9166 9167 entry.action.flex_off = 0; /*use 0 by default */ 9168 if (!strcmp(res->drop, "drop")) 9169 entry.action.behavior = RTE_ETH_FDIR_REJECT; 9170 else 9171 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 9172 9173 if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN && 9174 fdir_conf.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 9175 if (!strcmp(res->pf_vf, "pf")) 9176 entry.input.flow_ext.is_vf = 0; 9177 else if (!strncmp(res->pf_vf, "vf", 2)) { 9178 struct rte_eth_dev_info dev_info; 9179 9180 memset(&dev_info, 0, sizeof(dev_info)); 9181 rte_eth_dev_info_get(res->port_id, &dev_info); 9182 errno = 0; 9183 vf_id = strtoul(res->pf_vf + 2, &end, 10); 9184 if (errno != 0 || *end != '\0' || 9185 vf_id >= dev_info.max_vfs) { 9186 printf("invalid parameter %s.\n", res->pf_vf); 9187 return; 9188 } 9189 entry.input.flow_ext.is_vf = 1; 9190 entry.input.flow_ext.dst_id = (uint16_t)vf_id; 9191 } else { 9192 printf("invalid parameter %s.\n", res->pf_vf); 9193 return; 9194 } 9195 } 9196 9197 /* set to report FD ID by default */ 9198 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 9199 entry.action.rx_queue = res->queue_id; 9200 entry.soft_id = res->fd_id_value; 9201 if (!strcmp(res->ops, "add")) 9202 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9203 RTE_ETH_FILTER_ADD, &entry); 9204 else if (!strcmp(res->ops, "del")) 9205 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9206 RTE_ETH_FILTER_DELETE, &entry); 9207 else 9208 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9209 RTE_ETH_FILTER_UPDATE, &entry); 9210 if (ret < 0) 9211 printf("flow director programming error: (%s)\n", 9212 strerror(-ret)); 9213 } 9214 9215 cmdline_parse_token_string_t cmd_flow_director_filter = 9216 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9217 flow_director_filter, "flow_director_filter"); 9218 cmdline_parse_token_num_t cmd_flow_director_port_id = 9219 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9220 port_id, UINT8); 9221 cmdline_parse_token_string_t cmd_flow_director_ops = 9222 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9223 ops, "add#del#update"); 9224 cmdline_parse_token_string_t cmd_flow_director_flow = 9225 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9226 flow, "flow"); 9227 cmdline_parse_token_string_t cmd_flow_director_flow_type = 9228 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9229 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 9230 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload"); 9231 cmdline_parse_token_string_t cmd_flow_director_ether = 9232 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9233 ether, "ether"); 9234 cmdline_parse_token_num_t cmd_flow_director_ether_type = 9235 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9236 ether_type, UINT16); 9237 cmdline_parse_token_string_t cmd_flow_director_src = 9238 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9239 src, "src"); 9240 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 9241 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 9242 ip_src); 9243 cmdline_parse_token_num_t cmd_flow_director_port_src = 9244 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9245 port_src, UINT16); 9246 cmdline_parse_token_string_t cmd_flow_director_dst = 9247 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9248 dst, "dst"); 9249 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 9250 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 9251 ip_dst); 9252 cmdline_parse_token_num_t cmd_flow_director_port_dst = 9253 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9254 port_dst, UINT16); 9255 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 9256 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9257 verify_tag, "verify_tag"); 9258 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 9259 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9260 verify_tag_value, UINT32); 9261 cmdline_parse_token_string_t cmd_flow_director_tos = 9262 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9263 tos, "tos"); 9264 cmdline_parse_token_num_t cmd_flow_director_tos_value = 9265 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9266 tos_value, UINT8); 9267 cmdline_parse_token_string_t cmd_flow_director_proto = 9268 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9269 proto, "proto"); 9270 cmdline_parse_token_num_t cmd_flow_director_proto_value = 9271 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9272 proto_value, UINT8); 9273 cmdline_parse_token_string_t cmd_flow_director_ttl = 9274 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9275 ttl, "ttl"); 9276 cmdline_parse_token_num_t cmd_flow_director_ttl_value = 9277 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9278 ttl_value, UINT8); 9279 cmdline_parse_token_string_t cmd_flow_director_vlan = 9280 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9281 vlan, "vlan"); 9282 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 9283 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9284 vlan_value, UINT16); 9285 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 9286 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9287 flexbytes, "flexbytes"); 9288 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 9289 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9290 flexbytes_value, NULL); 9291 cmdline_parse_token_string_t cmd_flow_director_drop = 9292 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9293 drop, "drop#fwd"); 9294 cmdline_parse_token_string_t cmd_flow_director_pf_vf = 9295 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9296 pf_vf, NULL); 9297 cmdline_parse_token_string_t cmd_flow_director_queue = 9298 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9299 queue, "queue"); 9300 cmdline_parse_token_num_t cmd_flow_director_queue_id = 9301 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9302 queue_id, UINT16); 9303 cmdline_parse_token_string_t cmd_flow_director_fd_id = 9304 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9305 fd_id, "fd_id"); 9306 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 9307 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9308 fd_id_value, UINT32); 9309 9310 cmdline_parse_token_string_t cmd_flow_director_mode = 9311 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9312 mode, "mode"); 9313 cmdline_parse_token_string_t cmd_flow_director_mode_ip = 9314 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9315 mode_value, "IP"); 9316 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan = 9317 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9318 mode_value, "MAC-VLAN"); 9319 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel = 9320 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9321 mode_value, "Tunnel"); 9322 cmdline_parse_token_string_t cmd_flow_director_mac = 9323 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9324 mac, "mac"); 9325 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr = 9326 TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result, 9327 mac_addr); 9328 cmdline_parse_token_string_t cmd_flow_director_tunnel = 9329 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9330 tunnel, "tunnel"); 9331 cmdline_parse_token_string_t cmd_flow_director_tunnel_type = 9332 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9333 tunnel_type, "NVGRE#VxLAN"); 9334 cmdline_parse_token_string_t cmd_flow_director_tunnel_id = 9335 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9336 tunnel_id, "tunnel-id"); 9337 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value = 9338 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9339 tunnel_id_value, UINT32); 9340 9341 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 9342 .f = cmd_flow_director_filter_parsed, 9343 .data = NULL, 9344 .help_str = "flow_director_filter <port_id> mode IP add|del|update flow" 9345 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 9346 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 9347 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " 9348 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " 9349 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> " 9350 "fd_id <fd_id_value>: " 9351 "Add or delete an ip flow director entry on NIC", 9352 .tokens = { 9353 (void *)&cmd_flow_director_filter, 9354 (void *)&cmd_flow_director_port_id, 9355 (void *)&cmd_flow_director_mode, 9356 (void *)&cmd_flow_director_mode_ip, 9357 (void *)&cmd_flow_director_ops, 9358 (void *)&cmd_flow_director_flow, 9359 (void *)&cmd_flow_director_flow_type, 9360 (void *)&cmd_flow_director_src, 9361 (void *)&cmd_flow_director_ip_src, 9362 (void *)&cmd_flow_director_dst, 9363 (void *)&cmd_flow_director_ip_dst, 9364 (void *)&cmd_flow_director_tos, 9365 (void *)&cmd_flow_director_tos_value, 9366 (void *)&cmd_flow_director_proto, 9367 (void *)&cmd_flow_director_proto_value, 9368 (void *)&cmd_flow_director_ttl, 9369 (void *)&cmd_flow_director_ttl_value, 9370 (void *)&cmd_flow_director_vlan, 9371 (void *)&cmd_flow_director_vlan_value, 9372 (void *)&cmd_flow_director_flexbytes, 9373 (void *)&cmd_flow_director_flexbytes_value, 9374 (void *)&cmd_flow_director_drop, 9375 (void *)&cmd_flow_director_pf_vf, 9376 (void *)&cmd_flow_director_queue, 9377 (void *)&cmd_flow_director_queue_id, 9378 (void *)&cmd_flow_director_fd_id, 9379 (void *)&cmd_flow_director_fd_id_value, 9380 NULL, 9381 }, 9382 }; 9383 9384 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 9385 .f = cmd_flow_director_filter_parsed, 9386 .data = NULL, 9387 .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow " 9388 "director entry on NIC", 9389 .tokens = { 9390 (void *)&cmd_flow_director_filter, 9391 (void *)&cmd_flow_director_port_id, 9392 (void *)&cmd_flow_director_mode, 9393 (void *)&cmd_flow_director_mode_ip, 9394 (void *)&cmd_flow_director_ops, 9395 (void *)&cmd_flow_director_flow, 9396 (void *)&cmd_flow_director_flow_type, 9397 (void *)&cmd_flow_director_src, 9398 (void *)&cmd_flow_director_ip_src, 9399 (void *)&cmd_flow_director_port_src, 9400 (void *)&cmd_flow_director_dst, 9401 (void *)&cmd_flow_director_ip_dst, 9402 (void *)&cmd_flow_director_port_dst, 9403 (void *)&cmd_flow_director_tos, 9404 (void *)&cmd_flow_director_tos_value, 9405 (void *)&cmd_flow_director_ttl, 9406 (void *)&cmd_flow_director_ttl_value, 9407 (void *)&cmd_flow_director_vlan, 9408 (void *)&cmd_flow_director_vlan_value, 9409 (void *)&cmd_flow_director_flexbytes, 9410 (void *)&cmd_flow_director_flexbytes_value, 9411 (void *)&cmd_flow_director_drop, 9412 (void *)&cmd_flow_director_pf_vf, 9413 (void *)&cmd_flow_director_queue, 9414 (void *)&cmd_flow_director_queue_id, 9415 (void *)&cmd_flow_director_fd_id, 9416 (void *)&cmd_flow_director_fd_id_value, 9417 NULL, 9418 }, 9419 }; 9420 9421 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 9422 .f = cmd_flow_director_filter_parsed, 9423 .data = NULL, 9424 .help_str = "flow_director_filter ... : Add or delete a sctp flow " 9425 "director entry on NIC", 9426 .tokens = { 9427 (void *)&cmd_flow_director_filter, 9428 (void *)&cmd_flow_director_port_id, 9429 (void *)&cmd_flow_director_mode, 9430 (void *)&cmd_flow_director_mode_ip, 9431 (void *)&cmd_flow_director_ops, 9432 (void *)&cmd_flow_director_flow, 9433 (void *)&cmd_flow_director_flow_type, 9434 (void *)&cmd_flow_director_src, 9435 (void *)&cmd_flow_director_ip_src, 9436 (void *)&cmd_flow_director_port_dst, 9437 (void *)&cmd_flow_director_dst, 9438 (void *)&cmd_flow_director_ip_dst, 9439 (void *)&cmd_flow_director_port_dst, 9440 (void *)&cmd_flow_director_verify_tag, 9441 (void *)&cmd_flow_director_verify_tag_value, 9442 (void *)&cmd_flow_director_tos, 9443 (void *)&cmd_flow_director_tos_value, 9444 (void *)&cmd_flow_director_ttl, 9445 (void *)&cmd_flow_director_ttl_value, 9446 (void *)&cmd_flow_director_vlan, 9447 (void *)&cmd_flow_director_vlan_value, 9448 (void *)&cmd_flow_director_flexbytes, 9449 (void *)&cmd_flow_director_flexbytes_value, 9450 (void *)&cmd_flow_director_drop, 9451 (void *)&cmd_flow_director_pf_vf, 9452 (void *)&cmd_flow_director_queue, 9453 (void *)&cmd_flow_director_queue_id, 9454 (void *)&cmd_flow_director_fd_id, 9455 (void *)&cmd_flow_director_fd_id_value, 9456 NULL, 9457 }, 9458 }; 9459 9460 cmdline_parse_inst_t cmd_add_del_l2_flow_director = { 9461 .f = cmd_flow_director_filter_parsed, 9462 .data = NULL, 9463 .help_str = "flow_director_filter ... : Add or delete a L2 flow " 9464 "director entry on NIC", 9465 .tokens = { 9466 (void *)&cmd_flow_director_filter, 9467 (void *)&cmd_flow_director_port_id, 9468 (void *)&cmd_flow_director_mode, 9469 (void *)&cmd_flow_director_mode_ip, 9470 (void *)&cmd_flow_director_ops, 9471 (void *)&cmd_flow_director_flow, 9472 (void *)&cmd_flow_director_flow_type, 9473 (void *)&cmd_flow_director_ether, 9474 (void *)&cmd_flow_director_ether_type, 9475 (void *)&cmd_flow_director_flexbytes, 9476 (void *)&cmd_flow_director_flexbytes_value, 9477 (void *)&cmd_flow_director_drop, 9478 (void *)&cmd_flow_director_pf_vf, 9479 (void *)&cmd_flow_director_queue, 9480 (void *)&cmd_flow_director_queue_id, 9481 (void *)&cmd_flow_director_fd_id, 9482 (void *)&cmd_flow_director_fd_id_value, 9483 NULL, 9484 }, 9485 }; 9486 9487 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = { 9488 .f = cmd_flow_director_filter_parsed, 9489 .data = NULL, 9490 .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow " 9491 "director entry on NIC", 9492 .tokens = { 9493 (void *)&cmd_flow_director_filter, 9494 (void *)&cmd_flow_director_port_id, 9495 (void *)&cmd_flow_director_mode, 9496 (void *)&cmd_flow_director_mode_mac_vlan, 9497 (void *)&cmd_flow_director_ops, 9498 (void *)&cmd_flow_director_mac, 9499 (void *)&cmd_flow_director_mac_addr, 9500 (void *)&cmd_flow_director_vlan, 9501 (void *)&cmd_flow_director_vlan_value, 9502 (void *)&cmd_flow_director_flexbytes, 9503 (void *)&cmd_flow_director_flexbytes_value, 9504 (void *)&cmd_flow_director_drop, 9505 (void *)&cmd_flow_director_queue, 9506 (void *)&cmd_flow_director_queue_id, 9507 (void *)&cmd_flow_director_fd_id, 9508 (void *)&cmd_flow_director_fd_id_value, 9509 NULL, 9510 }, 9511 }; 9512 9513 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { 9514 .f = cmd_flow_director_filter_parsed, 9515 .data = NULL, 9516 .help_str = "flow_director_filter ... : Add or delete a tunnel flow " 9517 "director entry on NIC", 9518 .tokens = { 9519 (void *)&cmd_flow_director_filter, 9520 (void *)&cmd_flow_director_port_id, 9521 (void *)&cmd_flow_director_mode, 9522 (void *)&cmd_flow_director_mode_tunnel, 9523 (void *)&cmd_flow_director_ops, 9524 (void *)&cmd_flow_director_mac, 9525 (void *)&cmd_flow_director_mac_addr, 9526 (void *)&cmd_flow_director_vlan, 9527 (void *)&cmd_flow_director_vlan_value, 9528 (void *)&cmd_flow_director_tunnel, 9529 (void *)&cmd_flow_director_tunnel_type, 9530 (void *)&cmd_flow_director_tunnel_id, 9531 (void *)&cmd_flow_director_tunnel_id_value, 9532 (void *)&cmd_flow_director_flexbytes, 9533 (void *)&cmd_flow_director_flexbytes_value, 9534 (void *)&cmd_flow_director_drop, 9535 (void *)&cmd_flow_director_queue, 9536 (void *)&cmd_flow_director_queue_id, 9537 (void *)&cmd_flow_director_fd_id, 9538 (void *)&cmd_flow_director_fd_id_value, 9539 NULL, 9540 }, 9541 }; 9542 9543 struct cmd_flush_flow_director_result { 9544 cmdline_fixed_string_t flush_flow_director; 9545 uint8_t port_id; 9546 }; 9547 9548 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 9549 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 9550 flush_flow_director, "flush_flow_director"); 9551 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 9552 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 9553 port_id, UINT8); 9554 9555 static void 9556 cmd_flush_flow_director_parsed(void *parsed_result, 9557 __attribute__((unused)) struct cmdline *cl, 9558 __attribute__((unused)) void *data) 9559 { 9560 struct cmd_flow_director_result *res = parsed_result; 9561 int ret = 0; 9562 9563 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 9564 if (ret < 0) { 9565 printf("flow director is not supported on port %u.\n", 9566 res->port_id); 9567 return; 9568 } 9569 9570 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9571 RTE_ETH_FILTER_FLUSH, NULL); 9572 if (ret < 0) 9573 printf("flow director table flushing error: (%s)\n", 9574 strerror(-ret)); 9575 } 9576 9577 cmdline_parse_inst_t cmd_flush_flow_director = { 9578 .f = cmd_flush_flow_director_parsed, 9579 .data = NULL, 9580 .help_str = "flush_flow_director <port_id>: " 9581 "Flush all flow director entries of a device on NIC", 9582 .tokens = { 9583 (void *)&cmd_flush_flow_director_flush, 9584 (void *)&cmd_flush_flow_director_port_id, 9585 NULL, 9586 }, 9587 }; 9588 9589 /* *** deal with flow director mask *** */ 9590 struct cmd_flow_director_mask_result { 9591 cmdline_fixed_string_t flow_director_mask; 9592 uint8_t port_id; 9593 cmdline_fixed_string_t mode; 9594 cmdline_fixed_string_t mode_value; 9595 cmdline_fixed_string_t vlan; 9596 uint16_t vlan_mask; 9597 cmdline_fixed_string_t src_mask; 9598 cmdline_ipaddr_t ipv4_src; 9599 cmdline_ipaddr_t ipv6_src; 9600 uint16_t port_src; 9601 cmdline_fixed_string_t dst_mask; 9602 cmdline_ipaddr_t ipv4_dst; 9603 cmdline_ipaddr_t ipv6_dst; 9604 uint16_t port_dst; 9605 cmdline_fixed_string_t mac; 9606 uint8_t mac_addr_byte_mask; 9607 cmdline_fixed_string_t tunnel_id; 9608 uint32_t tunnel_id_mask; 9609 cmdline_fixed_string_t tunnel_type; 9610 uint8_t tunnel_type_mask; 9611 }; 9612 9613 static void 9614 cmd_flow_director_mask_parsed(void *parsed_result, 9615 __attribute__((unused)) struct cmdline *cl, 9616 __attribute__((unused)) void *data) 9617 { 9618 struct cmd_flow_director_mask_result *res = parsed_result; 9619 struct rte_eth_fdir_masks *mask; 9620 struct rte_port *port; 9621 9622 if (res->port_id > nb_ports) { 9623 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9624 return; 9625 } 9626 9627 port = &ports[res->port_id]; 9628 /** Check if the port is not started **/ 9629 if (port->port_status != RTE_PORT_STOPPED) { 9630 printf("Please stop port %d first\n", res->port_id); 9631 return; 9632 } 9633 9634 mask = &port->dev_conf.fdir_conf.mask; 9635 9636 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9637 if (strcmp(res->mode_value, "MAC-VLAN")) { 9638 printf("Please set mode to MAC-VLAN.\n"); 9639 return; 9640 } 9641 9642 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9643 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9644 if (strcmp(res->mode_value, "Tunnel")) { 9645 printf("Please set mode to Tunnel.\n"); 9646 return; 9647 } 9648 9649 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9650 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 9651 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 9652 mask->tunnel_type_mask = res->tunnel_type_mask; 9653 } else { 9654 if (strcmp(res->mode_value, "IP")) { 9655 printf("Please set mode to IP.\n"); 9656 return; 9657 } 9658 9659 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9660 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 9661 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 9662 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 9663 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 9664 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 9665 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 9666 } 9667 9668 cmd_reconfig_device_queue(res->port_id, 1, 1); 9669 } 9670 9671 cmdline_parse_token_string_t cmd_flow_director_mask = 9672 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9673 flow_director_mask, "flow_director_mask"); 9674 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 9675 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9676 port_id, UINT8); 9677 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 9678 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9679 vlan, "vlan"); 9680 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 9681 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9682 vlan_mask, UINT16); 9683 cmdline_parse_token_string_t cmd_flow_director_mask_src = 9684 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9685 src_mask, "src_mask"); 9686 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 9687 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9688 ipv4_src); 9689 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 9690 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9691 ipv6_src); 9692 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 9693 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9694 port_src, UINT16); 9695 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 9696 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9697 dst_mask, "dst_mask"); 9698 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 9699 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9700 ipv4_dst); 9701 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 9702 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9703 ipv6_dst); 9704 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 9705 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9706 port_dst, UINT16); 9707 9708 cmdline_parse_token_string_t cmd_flow_director_mask_mode = 9709 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9710 mode, "mode"); 9711 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 9712 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9713 mode_value, "IP"); 9714 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 9715 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9716 mode_value, "MAC-VLAN"); 9717 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 9718 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9719 mode_value, "Tunnel"); 9720 cmdline_parse_token_string_t cmd_flow_director_mask_mac = 9721 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9722 mac, "mac"); 9723 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 9724 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9725 mac_addr_byte_mask, UINT8); 9726 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 9727 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9728 tunnel_type, "tunnel-type"); 9729 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 9730 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9731 tunnel_type_mask, UINT8); 9732 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 9733 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9734 tunnel_id, "tunnel-id"); 9735 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 9736 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9737 tunnel_id_mask, UINT32); 9738 9739 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 9740 .f = cmd_flow_director_mask_parsed, 9741 .data = NULL, 9742 .help_str = "flow_director_mask ... : " 9743 "Set IP mode flow director's mask on NIC", 9744 .tokens = { 9745 (void *)&cmd_flow_director_mask, 9746 (void *)&cmd_flow_director_mask_port_id, 9747 (void *)&cmd_flow_director_mask_mode, 9748 (void *)&cmd_flow_director_mask_mode_ip, 9749 (void *)&cmd_flow_director_mask_vlan, 9750 (void *)&cmd_flow_director_mask_vlan_value, 9751 (void *)&cmd_flow_director_mask_src, 9752 (void *)&cmd_flow_director_mask_ipv4_src, 9753 (void *)&cmd_flow_director_mask_ipv6_src, 9754 (void *)&cmd_flow_director_mask_port_src, 9755 (void *)&cmd_flow_director_mask_dst, 9756 (void *)&cmd_flow_director_mask_ipv4_dst, 9757 (void *)&cmd_flow_director_mask_ipv6_dst, 9758 (void *)&cmd_flow_director_mask_port_dst, 9759 NULL, 9760 }, 9761 }; 9762 9763 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 9764 .f = cmd_flow_director_mask_parsed, 9765 .data = NULL, 9766 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 9767 "flow director's mask on NIC", 9768 .tokens = { 9769 (void *)&cmd_flow_director_mask, 9770 (void *)&cmd_flow_director_mask_port_id, 9771 (void *)&cmd_flow_director_mask_mode, 9772 (void *)&cmd_flow_director_mask_mode_mac_vlan, 9773 (void *)&cmd_flow_director_mask_vlan, 9774 (void *)&cmd_flow_director_mask_vlan_value, 9775 NULL, 9776 }, 9777 }; 9778 9779 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 9780 .f = cmd_flow_director_mask_parsed, 9781 .data = NULL, 9782 .help_str = "flow_director_mask ... : Set tunnel mode " 9783 "flow director's mask on NIC", 9784 .tokens = { 9785 (void *)&cmd_flow_director_mask, 9786 (void *)&cmd_flow_director_mask_port_id, 9787 (void *)&cmd_flow_director_mask_mode, 9788 (void *)&cmd_flow_director_mask_mode_tunnel, 9789 (void *)&cmd_flow_director_mask_vlan, 9790 (void *)&cmd_flow_director_mask_vlan_value, 9791 (void *)&cmd_flow_director_mask_mac, 9792 (void *)&cmd_flow_director_mask_mac_value, 9793 (void *)&cmd_flow_director_mask_tunnel_type, 9794 (void *)&cmd_flow_director_mask_tunnel_type_value, 9795 (void *)&cmd_flow_director_mask_tunnel_id, 9796 (void *)&cmd_flow_director_mask_tunnel_id_value, 9797 NULL, 9798 }, 9799 }; 9800 9801 /* *** deal with flow director mask on flexible payload *** */ 9802 struct cmd_flow_director_flex_mask_result { 9803 cmdline_fixed_string_t flow_director_flexmask; 9804 uint8_t port_id; 9805 cmdline_fixed_string_t flow; 9806 cmdline_fixed_string_t flow_type; 9807 cmdline_fixed_string_t mask; 9808 }; 9809 9810 static void 9811 cmd_flow_director_flex_mask_parsed(void *parsed_result, 9812 __attribute__((unused)) struct cmdline *cl, 9813 __attribute__((unused)) void *data) 9814 { 9815 struct cmd_flow_director_flex_mask_result *res = parsed_result; 9816 struct rte_eth_fdir_info fdir_info; 9817 struct rte_eth_fdir_flex_mask flex_mask; 9818 struct rte_port *port; 9819 uint32_t flow_type_mask; 9820 uint16_t i; 9821 int ret; 9822 9823 if (res->port_id > nb_ports) { 9824 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9825 return; 9826 } 9827 9828 port = &ports[res->port_id]; 9829 /** Check if the port is not started **/ 9830 if (port->port_status != RTE_PORT_STOPPED) { 9831 printf("Please stop port %d first\n", res->port_id); 9832 return; 9833 } 9834 9835 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 9836 ret = parse_flexbytes(res->mask, 9837 flex_mask.mask, 9838 RTE_ETH_FDIR_MAX_FLEXLEN); 9839 if (ret < 0) { 9840 printf("error: Cannot parse mask input.\n"); 9841 return; 9842 } 9843 9844 memset(&fdir_info, 0, sizeof(fdir_info)); 9845 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9846 RTE_ETH_FILTER_INFO, &fdir_info); 9847 if (ret < 0) { 9848 printf("Cannot get FDir filter info\n"); 9849 return; 9850 } 9851 9852 if (!strcmp(res->flow_type, "none")) { 9853 /* means don't specify the flow type */ 9854 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN; 9855 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) 9856 memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 9857 0, sizeof(struct rte_eth_fdir_flex_mask)); 9858 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; 9859 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], 9860 &flex_mask, 9861 sizeof(struct rte_eth_fdir_flex_mask)); 9862 cmd_reconfig_device_queue(res->port_id, 1, 1); 9863 return; 9864 } 9865 flow_type_mask = fdir_info.flow_types_mask[0]; 9866 if (!strcmp(res->flow_type, "all")) { 9867 if (!flow_type_mask) { 9868 printf("No flow type supported\n"); 9869 return; 9870 } 9871 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 9872 if (flow_type_mask & (1 << i)) { 9873 flex_mask.flow_type = i; 9874 fdir_set_flex_mask(res->port_id, &flex_mask); 9875 } 9876 } 9877 cmd_reconfig_device_queue(res->port_id, 1, 1); 9878 return; 9879 } 9880 flex_mask.flow_type = str2flowtype(res->flow_type); 9881 if (!(flow_type_mask & (1 << flex_mask.flow_type))) { 9882 printf("Flow type %s not supported on port %d\n", 9883 res->flow_type, res->port_id); 9884 return; 9885 } 9886 fdir_set_flex_mask(res->port_id, &flex_mask); 9887 cmd_reconfig_device_queue(res->port_id, 1, 1); 9888 } 9889 9890 cmdline_parse_token_string_t cmd_flow_director_flexmask = 9891 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9892 flow_director_flexmask, 9893 "flow_director_flex_mask"); 9894 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 9895 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9896 port_id, UINT8); 9897 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 9898 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9899 flow, "flow"); 9900 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 9901 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9902 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 9903 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all"); 9904 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 9905 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9906 mask, NULL); 9907 9908 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 9909 .f = cmd_flow_director_flex_mask_parsed, 9910 .data = NULL, 9911 .help_str = "flow_director_flex_mask ... : " 9912 "Set flow director's flex mask on NIC", 9913 .tokens = { 9914 (void *)&cmd_flow_director_flexmask, 9915 (void *)&cmd_flow_director_flexmask_port_id, 9916 (void *)&cmd_flow_director_flexmask_flow, 9917 (void *)&cmd_flow_director_flexmask_flow_type, 9918 (void *)&cmd_flow_director_flexmask_mask, 9919 NULL, 9920 }, 9921 }; 9922 9923 /* *** deal with flow director flexible payload configuration *** */ 9924 struct cmd_flow_director_flexpayload_result { 9925 cmdline_fixed_string_t flow_director_flexpayload; 9926 uint8_t port_id; 9927 cmdline_fixed_string_t payload_layer; 9928 cmdline_fixed_string_t payload_cfg; 9929 }; 9930 9931 static inline int 9932 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 9933 { 9934 char s[256]; 9935 const char *p, *p0 = q_arg; 9936 char *end; 9937 unsigned long int_fld; 9938 char *str_fld[max_num]; 9939 int i; 9940 unsigned size; 9941 int ret = -1; 9942 9943 p = strchr(p0, '('); 9944 if (p == NULL) 9945 return -1; 9946 ++p; 9947 p0 = strchr(p, ')'); 9948 if (p0 == NULL) 9949 return -1; 9950 9951 size = p0 - p; 9952 if (size >= sizeof(s)) 9953 return -1; 9954 9955 snprintf(s, sizeof(s), "%.*s", size, p); 9956 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9957 if (ret < 0 || ret > max_num) 9958 return -1; 9959 for (i = 0; i < ret; i++) { 9960 errno = 0; 9961 int_fld = strtoul(str_fld[i], &end, 0); 9962 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 9963 return -1; 9964 offsets[i] = (uint16_t)int_fld; 9965 } 9966 return ret; 9967 } 9968 9969 static void 9970 cmd_flow_director_flxpld_parsed(void *parsed_result, 9971 __attribute__((unused)) struct cmdline *cl, 9972 __attribute__((unused)) void *data) 9973 { 9974 struct cmd_flow_director_flexpayload_result *res = parsed_result; 9975 struct rte_eth_flex_payload_cfg flex_cfg; 9976 struct rte_port *port; 9977 int ret = 0; 9978 9979 if (res->port_id > nb_ports) { 9980 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9981 return; 9982 } 9983 9984 port = &ports[res->port_id]; 9985 /** Check if the port is not started **/ 9986 if (port->port_status != RTE_PORT_STOPPED) { 9987 printf("Please stop port %d first\n", res->port_id); 9988 return; 9989 } 9990 9991 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 9992 9993 if (!strcmp(res->payload_layer, "raw")) 9994 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 9995 else if (!strcmp(res->payload_layer, "l2")) 9996 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 9997 else if (!strcmp(res->payload_layer, "l3")) 9998 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 9999 else if (!strcmp(res->payload_layer, "l4")) 10000 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 10001 10002 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 10003 RTE_ETH_FDIR_MAX_FLEXLEN); 10004 if (ret < 0) { 10005 printf("error: Cannot parse flex payload input.\n"); 10006 return; 10007 } 10008 10009 fdir_set_flex_payload(res->port_id, &flex_cfg); 10010 cmd_reconfig_device_queue(res->port_id, 1, 1); 10011 } 10012 10013 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 10014 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10015 flow_director_flexpayload, 10016 "flow_director_flex_payload"); 10017 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 10018 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10019 port_id, UINT8); 10020 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 10021 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10022 payload_layer, "raw#l2#l3#l4"); 10023 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 10024 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10025 payload_cfg, NULL); 10026 10027 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 10028 .f = cmd_flow_director_flxpld_parsed, 10029 .data = NULL, 10030 .help_str = "flow_director_flexpayload ... : " 10031 "Set flow director's flex payload on NIC", 10032 .tokens = { 10033 (void *)&cmd_flow_director_flexpayload, 10034 (void *)&cmd_flow_director_flexpayload_port_id, 10035 (void *)&cmd_flow_director_flexpayload_payload_layer, 10036 (void *)&cmd_flow_director_flexpayload_payload_cfg, 10037 NULL, 10038 }, 10039 }; 10040 10041 /* Generic flow interface command. */ 10042 extern cmdline_parse_inst_t cmd_flow; 10043 10044 /* *** Classification Filters Control *** */ 10045 /* *** Get symmetric hash enable per port *** */ 10046 struct cmd_get_sym_hash_ena_per_port_result { 10047 cmdline_fixed_string_t get_sym_hash_ena_per_port; 10048 uint8_t port_id; 10049 }; 10050 10051 static void 10052 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 10053 __rte_unused struct cmdline *cl, 10054 __rte_unused void *data) 10055 { 10056 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 10057 struct rte_eth_hash_filter_info info; 10058 int ret; 10059 10060 if (rte_eth_dev_filter_supported(res->port_id, 10061 RTE_ETH_FILTER_HASH) < 0) { 10062 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 10063 res->port_id); 10064 return; 10065 } 10066 10067 memset(&info, 0, sizeof(info)); 10068 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 10069 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10070 RTE_ETH_FILTER_GET, &info); 10071 10072 if (ret < 0) { 10073 printf("Cannot get symmetric hash enable per port " 10074 "on port %u\n", res->port_id); 10075 return; 10076 } 10077 10078 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 10079 "enabled" : "disabled", res->port_id); 10080 } 10081 10082 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 10083 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 10084 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 10085 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 10086 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 10087 port_id, UINT8); 10088 10089 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 10090 .f = cmd_get_sym_hash_per_port_parsed, 10091 .data = NULL, 10092 .help_str = "get_sym_hash_ena_per_port <port_id>", 10093 .tokens = { 10094 (void *)&cmd_get_sym_hash_ena_per_port_all, 10095 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 10096 NULL, 10097 }, 10098 }; 10099 10100 /* *** Set symmetric hash enable per port *** */ 10101 struct cmd_set_sym_hash_ena_per_port_result { 10102 cmdline_fixed_string_t set_sym_hash_ena_per_port; 10103 cmdline_fixed_string_t enable; 10104 uint8_t port_id; 10105 }; 10106 10107 static void 10108 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 10109 __rte_unused struct cmdline *cl, 10110 __rte_unused void *data) 10111 { 10112 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 10113 struct rte_eth_hash_filter_info info; 10114 int ret; 10115 10116 if (rte_eth_dev_filter_supported(res->port_id, 10117 RTE_ETH_FILTER_HASH) < 0) { 10118 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 10119 res->port_id); 10120 return; 10121 } 10122 10123 memset(&info, 0, sizeof(info)); 10124 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 10125 if (!strcmp(res->enable, "enable")) 10126 info.info.enable = 1; 10127 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10128 RTE_ETH_FILTER_SET, &info); 10129 if (ret < 0) { 10130 printf("Cannot set symmetric hash enable per port on " 10131 "port %u\n", res->port_id); 10132 return; 10133 } 10134 printf("Symmetric hash has been set to %s on port %u\n", 10135 res->enable, res->port_id); 10136 } 10137 10138 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 10139 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10140 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 10141 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 10142 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10143 port_id, UINT8); 10144 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 10145 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10146 enable, "enable#disable"); 10147 10148 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 10149 .f = cmd_set_sym_hash_per_port_parsed, 10150 .data = NULL, 10151 .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable", 10152 .tokens = { 10153 (void *)&cmd_set_sym_hash_ena_per_port_all, 10154 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 10155 (void *)&cmd_set_sym_hash_ena_per_port_enable, 10156 NULL, 10157 }, 10158 }; 10159 10160 /* Get global config of hash function */ 10161 struct cmd_get_hash_global_config_result { 10162 cmdline_fixed_string_t get_hash_global_config; 10163 uint8_t port_id; 10164 }; 10165 10166 static char * 10167 flowtype_to_str(uint16_t ftype) 10168 { 10169 uint16_t i; 10170 static struct { 10171 char str[16]; 10172 uint16_t ftype; 10173 } ftype_table[] = { 10174 {"ipv4", RTE_ETH_FLOW_IPV4}, 10175 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 10176 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 10177 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 10178 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 10179 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 10180 {"ipv6", RTE_ETH_FLOW_IPV6}, 10181 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 10182 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 10183 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 10184 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 10185 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 10186 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 10187 {"port", RTE_ETH_FLOW_PORT}, 10188 {"vxlan", RTE_ETH_FLOW_VXLAN}, 10189 {"geneve", RTE_ETH_FLOW_GENEVE}, 10190 {"nvgre", RTE_ETH_FLOW_NVGRE}, 10191 }; 10192 10193 for (i = 0; i < RTE_DIM(ftype_table); i++) { 10194 if (ftype_table[i].ftype == ftype) 10195 return ftype_table[i].str; 10196 } 10197 10198 return NULL; 10199 } 10200 10201 static void 10202 cmd_get_hash_global_config_parsed(void *parsed_result, 10203 __rte_unused struct cmdline *cl, 10204 __rte_unused void *data) 10205 { 10206 struct cmd_get_hash_global_config_result *res = parsed_result; 10207 struct rte_eth_hash_filter_info info; 10208 uint32_t idx, offset; 10209 uint16_t i; 10210 char *str; 10211 int ret; 10212 10213 if (rte_eth_dev_filter_supported(res->port_id, 10214 RTE_ETH_FILTER_HASH) < 0) { 10215 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 10216 res->port_id); 10217 return; 10218 } 10219 10220 memset(&info, 0, sizeof(info)); 10221 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 10222 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10223 RTE_ETH_FILTER_GET, &info); 10224 if (ret < 0) { 10225 printf("Cannot get hash global configurations by port %d\n", 10226 res->port_id); 10227 return; 10228 } 10229 10230 switch (info.info.global_conf.hash_func) { 10231 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 10232 printf("Hash function is Toeplitz\n"); 10233 break; 10234 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 10235 printf("Hash function is Simple XOR\n"); 10236 break; 10237 default: 10238 printf("Unknown hash function\n"); 10239 break; 10240 } 10241 10242 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 10243 idx = i / UINT32_BIT; 10244 offset = i % UINT32_BIT; 10245 if (!(info.info.global_conf.valid_bit_mask[idx] & 10246 (1UL << offset))) 10247 continue; 10248 str = flowtype_to_str(i); 10249 if (!str) 10250 continue; 10251 printf("Symmetric hash is %s globally for flow type %s " 10252 "by port %d\n", 10253 ((info.info.global_conf.sym_hash_enable_mask[idx] & 10254 (1UL << offset)) ? "enabled" : "disabled"), str, 10255 res->port_id); 10256 } 10257 } 10258 10259 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 10260 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 10261 get_hash_global_config, "get_hash_global_config"); 10262 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 10263 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 10264 port_id, UINT8); 10265 10266 cmdline_parse_inst_t cmd_get_hash_global_config = { 10267 .f = cmd_get_hash_global_config_parsed, 10268 .data = NULL, 10269 .help_str = "get_hash_global_config <port_id>", 10270 .tokens = { 10271 (void *)&cmd_get_hash_global_config_all, 10272 (void *)&cmd_get_hash_global_config_port_id, 10273 NULL, 10274 }, 10275 }; 10276 10277 /* Set global config of hash function */ 10278 struct cmd_set_hash_global_config_result { 10279 cmdline_fixed_string_t set_hash_global_config; 10280 uint8_t port_id; 10281 cmdline_fixed_string_t hash_func; 10282 cmdline_fixed_string_t flow_type; 10283 cmdline_fixed_string_t enable; 10284 }; 10285 10286 static void 10287 cmd_set_hash_global_config_parsed(void *parsed_result, 10288 __rte_unused struct cmdline *cl, 10289 __rte_unused void *data) 10290 { 10291 struct cmd_set_hash_global_config_result *res = parsed_result; 10292 struct rte_eth_hash_filter_info info; 10293 uint32_t ftype, idx, offset; 10294 int ret; 10295 10296 if (rte_eth_dev_filter_supported(res->port_id, 10297 RTE_ETH_FILTER_HASH) < 0) { 10298 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 10299 res->port_id); 10300 return; 10301 } 10302 memset(&info, 0, sizeof(info)); 10303 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 10304 if (!strcmp(res->hash_func, "toeplitz")) 10305 info.info.global_conf.hash_func = 10306 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 10307 else if (!strcmp(res->hash_func, "simple_xor")) 10308 info.info.global_conf.hash_func = 10309 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 10310 else if (!strcmp(res->hash_func, "default")) 10311 info.info.global_conf.hash_func = 10312 RTE_ETH_HASH_FUNCTION_DEFAULT; 10313 10314 ftype = str2flowtype(res->flow_type); 10315 idx = ftype / (CHAR_BIT * sizeof(uint32_t)); 10316 offset = ftype % (CHAR_BIT * sizeof(uint32_t)); 10317 info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset); 10318 if (!strcmp(res->enable, "enable")) 10319 info.info.global_conf.sym_hash_enable_mask[idx] |= 10320 (1UL << offset); 10321 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10322 RTE_ETH_FILTER_SET, &info); 10323 if (ret < 0) 10324 printf("Cannot set global hash configurations by port %d\n", 10325 res->port_id); 10326 else 10327 printf("Global hash configurations have been set " 10328 "succcessfully by port %d\n", res->port_id); 10329 } 10330 10331 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 10332 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 10333 set_hash_global_config, "set_hash_global_config"); 10334 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 10335 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 10336 port_id, UINT8); 10337 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 10338 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 10339 hash_func, "toeplitz#simple_xor#default"); 10340 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 10341 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 10342 flow_type, 10343 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 10344 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10345 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 10346 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 10347 enable, "enable#disable"); 10348 10349 cmdline_parse_inst_t cmd_set_hash_global_config = { 10350 .f = cmd_set_hash_global_config_parsed, 10351 .data = NULL, 10352 .help_str = "set_hash_global_config <port_id> " 10353 "toeplitz|simple_xor|default " 10354 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10355 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 10356 "l2_payload enable|disable", 10357 .tokens = { 10358 (void *)&cmd_set_hash_global_config_all, 10359 (void *)&cmd_set_hash_global_config_port_id, 10360 (void *)&cmd_set_hash_global_config_hash_func, 10361 (void *)&cmd_set_hash_global_config_flow_type, 10362 (void *)&cmd_set_hash_global_config_enable, 10363 NULL, 10364 }, 10365 }; 10366 10367 /* Set hash input set */ 10368 struct cmd_set_hash_input_set_result { 10369 cmdline_fixed_string_t set_hash_input_set; 10370 uint8_t port_id; 10371 cmdline_fixed_string_t flow_type; 10372 cmdline_fixed_string_t inset_field; 10373 cmdline_fixed_string_t select; 10374 }; 10375 10376 static enum rte_eth_input_set_field 10377 str2inset(char *string) 10378 { 10379 uint16_t i; 10380 10381 static const struct { 10382 char str[32]; 10383 enum rte_eth_input_set_field inset; 10384 } inset_table[] = { 10385 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE}, 10386 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN}, 10387 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN}, 10388 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4}, 10389 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4}, 10390 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS}, 10391 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO}, 10392 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL}, 10393 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6}, 10394 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6}, 10395 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC}, 10396 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER}, 10397 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS}, 10398 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT}, 10399 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT}, 10400 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT}, 10401 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT}, 10402 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT}, 10403 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT}, 10404 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG}, 10405 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY}, 10406 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY}, 10407 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD}, 10408 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD}, 10409 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD}, 10410 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD}, 10411 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD}, 10412 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD}, 10413 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD}, 10414 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD}, 10415 {"none", RTE_ETH_INPUT_SET_NONE}, 10416 }; 10417 10418 for (i = 0; i < RTE_DIM(inset_table); i++) { 10419 if (!strcmp(string, inset_table[i].str)) 10420 return inset_table[i].inset; 10421 } 10422 10423 return RTE_ETH_INPUT_SET_UNKNOWN; 10424 } 10425 10426 static void 10427 cmd_set_hash_input_set_parsed(void *parsed_result, 10428 __rte_unused struct cmdline *cl, 10429 __rte_unused void *data) 10430 { 10431 struct cmd_set_hash_input_set_result *res = parsed_result; 10432 struct rte_eth_hash_filter_info info; 10433 10434 memset(&info, 0, sizeof(info)); 10435 info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; 10436 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10437 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10438 info.info.input_set_conf.inset_size = 1; 10439 if (!strcmp(res->select, "select")) 10440 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10441 else if (!strcmp(res->select, "add")) 10442 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10443 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10444 RTE_ETH_FILTER_SET, &info); 10445 } 10446 10447 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = 10448 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10449 set_hash_input_set, "set_hash_input_set"); 10450 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = 10451 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, 10452 port_id, UINT8); 10453 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = 10454 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10455 flow_type, 10456 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10457 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10458 cmdline_parse_token_string_t cmd_set_hash_input_set_field = 10459 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10460 inset_field, 10461 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10462 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#" 10463 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#" 10464 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#" 10465 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#" 10466 "fld-8th#none"); 10467 cmdline_parse_token_string_t cmd_set_hash_input_set_select = 10468 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10469 select, "select#add"); 10470 10471 cmdline_parse_inst_t cmd_set_hash_input_set = { 10472 .f = cmd_set_hash_input_set_parsed, 10473 .data = NULL, 10474 .help_str = "set_hash_input_set <port_id> " 10475 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10476 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10477 "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" 10478 "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" 10479 "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" 10480 "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|" 10481 "fld-7th|fld-8th|none select|add", 10482 .tokens = { 10483 (void *)&cmd_set_hash_input_set_cmd, 10484 (void *)&cmd_set_hash_input_set_port_id, 10485 (void *)&cmd_set_hash_input_set_flow_type, 10486 (void *)&cmd_set_hash_input_set_field, 10487 (void *)&cmd_set_hash_input_set_select, 10488 NULL, 10489 }, 10490 }; 10491 10492 /* Set flow director input set */ 10493 struct cmd_set_fdir_input_set_result { 10494 cmdline_fixed_string_t set_fdir_input_set; 10495 uint8_t port_id; 10496 cmdline_fixed_string_t flow_type; 10497 cmdline_fixed_string_t inset_field; 10498 cmdline_fixed_string_t select; 10499 }; 10500 10501 static void 10502 cmd_set_fdir_input_set_parsed(void *parsed_result, 10503 __rte_unused struct cmdline *cl, 10504 __rte_unused void *data) 10505 { 10506 struct cmd_set_fdir_input_set_result *res = parsed_result; 10507 struct rte_eth_fdir_filter_info info; 10508 10509 memset(&info, 0, sizeof(info)); 10510 info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT; 10511 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10512 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10513 info.info.input_set_conf.inset_size = 1; 10514 if (!strcmp(res->select, "select")) 10515 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10516 else if (!strcmp(res->select, "add")) 10517 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10518 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10519 RTE_ETH_FILTER_SET, &info); 10520 } 10521 10522 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = 10523 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10524 set_fdir_input_set, "set_fdir_input_set"); 10525 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = 10526 TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, 10527 port_id, UINT8); 10528 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = 10529 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10530 flow_type, 10531 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10532 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10533 cmdline_parse_token_string_t cmd_set_fdir_input_set_field = 10534 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10535 inset_field, 10536 "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10537 "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#" 10538 "ipv6-hop-limits#udp-src-port#udp-dst-port#" 10539 "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#" 10540 "sctp-veri-tag#none"); 10541 cmdline_parse_token_string_t cmd_set_fdir_input_set_select = 10542 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10543 select, "select#add"); 10544 10545 cmdline_parse_inst_t cmd_set_fdir_input_set = { 10546 .f = cmd_set_fdir_input_set_parsed, 10547 .data = NULL, 10548 .help_str = "set_fdir_input_set <port_id> " 10549 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10550 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10551 "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|" 10552 "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|" 10553 "ipv6-hop-limits|udp-src-port|udp-dst-port|" 10554 "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|" 10555 "sctp-veri-tag|none select|add", 10556 .tokens = { 10557 (void *)&cmd_set_fdir_input_set_cmd, 10558 (void *)&cmd_set_fdir_input_set_port_id, 10559 (void *)&cmd_set_fdir_input_set_flow_type, 10560 (void *)&cmd_set_fdir_input_set_field, 10561 (void *)&cmd_set_fdir_input_set_select, 10562 NULL, 10563 }, 10564 }; 10565 10566 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 10567 struct cmd_mcast_addr_result { 10568 cmdline_fixed_string_t mcast_addr_cmd; 10569 cmdline_fixed_string_t what; 10570 uint8_t port_num; 10571 struct ether_addr mc_addr; 10572 }; 10573 10574 static void cmd_mcast_addr_parsed(void *parsed_result, 10575 __attribute__((unused)) struct cmdline *cl, 10576 __attribute__((unused)) void *data) 10577 { 10578 struct cmd_mcast_addr_result *res = parsed_result; 10579 10580 if (!is_multicast_ether_addr(&res->mc_addr)) { 10581 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n", 10582 res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1], 10583 res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3], 10584 res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]); 10585 return; 10586 } 10587 if (strcmp(res->what, "add") == 0) 10588 mcast_addr_add(res->port_num, &res->mc_addr); 10589 else 10590 mcast_addr_remove(res->port_num, &res->mc_addr); 10591 } 10592 10593 cmdline_parse_token_string_t cmd_mcast_addr_cmd = 10594 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 10595 mcast_addr_cmd, "mcast_addr"); 10596 cmdline_parse_token_string_t cmd_mcast_addr_what = 10597 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 10598 "add#remove"); 10599 cmdline_parse_token_num_t cmd_mcast_addr_portnum = 10600 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8); 10601 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 10602 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 10603 10604 cmdline_parse_inst_t cmd_mcast_addr = { 10605 .f = cmd_mcast_addr_parsed, 10606 .data = (void *)0, 10607 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 10608 "Add/Remove multicast MAC address on port_id", 10609 .tokens = { 10610 (void *)&cmd_mcast_addr_cmd, 10611 (void *)&cmd_mcast_addr_what, 10612 (void *)&cmd_mcast_addr_portnum, 10613 (void *)&cmd_mcast_addr_addr, 10614 NULL, 10615 }, 10616 }; 10617 10618 /* l2 tunnel config 10619 * only support E-tag now. 10620 */ 10621 10622 /* Ether type config */ 10623 struct cmd_config_l2_tunnel_eth_type_result { 10624 cmdline_fixed_string_t port; 10625 cmdline_fixed_string_t config; 10626 cmdline_fixed_string_t all; 10627 uint8_t id; 10628 cmdline_fixed_string_t l2_tunnel; 10629 cmdline_fixed_string_t l2_tunnel_type; 10630 cmdline_fixed_string_t eth_type; 10631 uint16_t eth_type_val; 10632 }; 10633 10634 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port = 10635 TOKEN_STRING_INITIALIZER 10636 (struct cmd_config_l2_tunnel_eth_type_result, 10637 port, "port"); 10638 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config = 10639 TOKEN_STRING_INITIALIZER 10640 (struct cmd_config_l2_tunnel_eth_type_result, 10641 config, "config"); 10642 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str = 10643 TOKEN_STRING_INITIALIZER 10644 (struct cmd_config_l2_tunnel_eth_type_result, 10645 all, "all"); 10646 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id = 10647 TOKEN_NUM_INITIALIZER 10648 (struct cmd_config_l2_tunnel_eth_type_result, 10649 id, UINT8); 10650 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel = 10651 TOKEN_STRING_INITIALIZER 10652 (struct cmd_config_l2_tunnel_eth_type_result, 10653 l2_tunnel, "l2-tunnel"); 10654 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type = 10655 TOKEN_STRING_INITIALIZER 10656 (struct cmd_config_l2_tunnel_eth_type_result, 10657 l2_tunnel_type, "E-tag"); 10658 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type = 10659 TOKEN_STRING_INITIALIZER 10660 (struct cmd_config_l2_tunnel_eth_type_result, 10661 eth_type, "ether-type"); 10662 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val = 10663 TOKEN_NUM_INITIALIZER 10664 (struct cmd_config_l2_tunnel_eth_type_result, 10665 eth_type_val, UINT16); 10666 10667 static enum rte_eth_tunnel_type 10668 str2fdir_l2_tunnel_type(char *string) 10669 { 10670 uint32_t i = 0; 10671 10672 static const struct { 10673 char str[32]; 10674 enum rte_eth_tunnel_type type; 10675 } l2_tunnel_type_str[] = { 10676 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG}, 10677 }; 10678 10679 for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) { 10680 if (!strcmp(l2_tunnel_type_str[i].str, string)) 10681 return l2_tunnel_type_str[i].type; 10682 } 10683 return RTE_TUNNEL_TYPE_NONE; 10684 } 10685 10686 /* ether type config for all ports */ 10687 static void 10688 cmd_config_l2_tunnel_eth_type_all_parsed 10689 (void *parsed_result, 10690 __attribute__((unused)) struct cmdline *cl, 10691 __attribute__((unused)) void *data) 10692 { 10693 struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result; 10694 struct rte_eth_l2_tunnel_conf entry; 10695 portid_t pid; 10696 10697 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10698 entry.ether_type = res->eth_type_val; 10699 10700 RTE_ETH_FOREACH_DEV(pid) { 10701 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry); 10702 } 10703 } 10704 10705 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = { 10706 .f = cmd_config_l2_tunnel_eth_type_all_parsed, 10707 .data = NULL, 10708 .help_str = "port config all l2-tunnel E-tag ether-type <value>", 10709 .tokens = { 10710 (void *)&cmd_config_l2_tunnel_eth_type_port, 10711 (void *)&cmd_config_l2_tunnel_eth_type_config, 10712 (void *)&cmd_config_l2_tunnel_eth_type_all_str, 10713 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10714 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10715 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10716 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10717 NULL, 10718 }, 10719 }; 10720 10721 /* ether type config for a specific port */ 10722 static void 10723 cmd_config_l2_tunnel_eth_type_specific_parsed( 10724 void *parsed_result, 10725 __attribute__((unused)) struct cmdline *cl, 10726 __attribute__((unused)) void *data) 10727 { 10728 struct cmd_config_l2_tunnel_eth_type_result *res = 10729 parsed_result; 10730 struct rte_eth_l2_tunnel_conf entry; 10731 10732 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10733 return; 10734 10735 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10736 entry.ether_type = res->eth_type_val; 10737 10738 rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry); 10739 } 10740 10741 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = { 10742 .f = cmd_config_l2_tunnel_eth_type_specific_parsed, 10743 .data = NULL, 10744 .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>", 10745 .tokens = { 10746 (void *)&cmd_config_l2_tunnel_eth_type_port, 10747 (void *)&cmd_config_l2_tunnel_eth_type_config, 10748 (void *)&cmd_config_l2_tunnel_eth_type_id, 10749 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10750 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10751 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10752 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10753 NULL, 10754 }, 10755 }; 10756 10757 /* Enable/disable l2 tunnel */ 10758 struct cmd_config_l2_tunnel_en_dis_result { 10759 cmdline_fixed_string_t port; 10760 cmdline_fixed_string_t config; 10761 cmdline_fixed_string_t all; 10762 uint8_t id; 10763 cmdline_fixed_string_t l2_tunnel; 10764 cmdline_fixed_string_t l2_tunnel_type; 10765 cmdline_fixed_string_t en_dis; 10766 }; 10767 10768 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port = 10769 TOKEN_STRING_INITIALIZER 10770 (struct cmd_config_l2_tunnel_en_dis_result, 10771 port, "port"); 10772 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config = 10773 TOKEN_STRING_INITIALIZER 10774 (struct cmd_config_l2_tunnel_en_dis_result, 10775 config, "config"); 10776 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str = 10777 TOKEN_STRING_INITIALIZER 10778 (struct cmd_config_l2_tunnel_en_dis_result, 10779 all, "all"); 10780 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id = 10781 TOKEN_NUM_INITIALIZER 10782 (struct cmd_config_l2_tunnel_en_dis_result, 10783 id, UINT8); 10784 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel = 10785 TOKEN_STRING_INITIALIZER 10786 (struct cmd_config_l2_tunnel_en_dis_result, 10787 l2_tunnel, "l2-tunnel"); 10788 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type = 10789 TOKEN_STRING_INITIALIZER 10790 (struct cmd_config_l2_tunnel_en_dis_result, 10791 l2_tunnel_type, "E-tag"); 10792 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis = 10793 TOKEN_STRING_INITIALIZER 10794 (struct cmd_config_l2_tunnel_en_dis_result, 10795 en_dis, "enable#disable"); 10796 10797 /* enable/disable l2 tunnel for all ports */ 10798 static void 10799 cmd_config_l2_tunnel_en_dis_all_parsed( 10800 void *parsed_result, 10801 __attribute__((unused)) struct cmdline *cl, 10802 __attribute__((unused)) void *data) 10803 { 10804 struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result; 10805 struct rte_eth_l2_tunnel_conf entry; 10806 portid_t pid; 10807 uint8_t en; 10808 10809 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10810 10811 if (!strcmp("enable", res->en_dis)) 10812 en = 1; 10813 else 10814 en = 0; 10815 10816 RTE_ETH_FOREACH_DEV(pid) { 10817 rte_eth_dev_l2_tunnel_offload_set(pid, 10818 &entry, 10819 ETH_L2_TUNNEL_ENABLE_MASK, 10820 en); 10821 } 10822 } 10823 10824 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = { 10825 .f = cmd_config_l2_tunnel_en_dis_all_parsed, 10826 .data = NULL, 10827 .help_str = "port config all l2-tunnel E-tag enable|disable", 10828 .tokens = { 10829 (void *)&cmd_config_l2_tunnel_en_dis_port, 10830 (void *)&cmd_config_l2_tunnel_en_dis_config, 10831 (void *)&cmd_config_l2_tunnel_en_dis_all_str, 10832 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10833 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10834 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10835 NULL, 10836 }, 10837 }; 10838 10839 /* enable/disable l2 tunnel for a port */ 10840 static void 10841 cmd_config_l2_tunnel_en_dis_specific_parsed( 10842 void *parsed_result, 10843 __attribute__((unused)) struct cmdline *cl, 10844 __attribute__((unused)) void *data) 10845 { 10846 struct cmd_config_l2_tunnel_en_dis_result *res = 10847 parsed_result; 10848 struct rte_eth_l2_tunnel_conf entry; 10849 10850 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10851 return; 10852 10853 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10854 10855 if (!strcmp("enable", res->en_dis)) 10856 rte_eth_dev_l2_tunnel_offload_set(res->id, 10857 &entry, 10858 ETH_L2_TUNNEL_ENABLE_MASK, 10859 1); 10860 else 10861 rte_eth_dev_l2_tunnel_offload_set(res->id, 10862 &entry, 10863 ETH_L2_TUNNEL_ENABLE_MASK, 10864 0); 10865 } 10866 10867 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = { 10868 .f = cmd_config_l2_tunnel_en_dis_specific_parsed, 10869 .data = NULL, 10870 .help_str = "port config <port_id> l2-tunnel E-tag enable|disable", 10871 .tokens = { 10872 (void *)&cmd_config_l2_tunnel_en_dis_port, 10873 (void *)&cmd_config_l2_tunnel_en_dis_config, 10874 (void *)&cmd_config_l2_tunnel_en_dis_id, 10875 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10876 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10877 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10878 NULL, 10879 }, 10880 }; 10881 10882 /* E-tag configuration */ 10883 10884 /* Common result structure for all E-tag configuration */ 10885 struct cmd_config_e_tag_result { 10886 cmdline_fixed_string_t e_tag; 10887 cmdline_fixed_string_t set; 10888 cmdline_fixed_string_t insertion; 10889 cmdline_fixed_string_t stripping; 10890 cmdline_fixed_string_t forwarding; 10891 cmdline_fixed_string_t filter; 10892 cmdline_fixed_string_t add; 10893 cmdline_fixed_string_t del; 10894 cmdline_fixed_string_t on; 10895 cmdline_fixed_string_t off; 10896 cmdline_fixed_string_t on_off; 10897 cmdline_fixed_string_t port_tag_id; 10898 uint32_t port_tag_id_val; 10899 cmdline_fixed_string_t e_tag_id; 10900 uint16_t e_tag_id_val; 10901 cmdline_fixed_string_t dst_pool; 10902 uint8_t dst_pool_val; 10903 cmdline_fixed_string_t port; 10904 uint8_t port_id; 10905 cmdline_fixed_string_t vf; 10906 uint8_t vf_id; 10907 }; 10908 10909 /* Common CLI fields for all E-tag configuration */ 10910 cmdline_parse_token_string_t cmd_config_e_tag_e_tag = 10911 TOKEN_STRING_INITIALIZER 10912 (struct cmd_config_e_tag_result, 10913 e_tag, "E-tag"); 10914 cmdline_parse_token_string_t cmd_config_e_tag_set = 10915 TOKEN_STRING_INITIALIZER 10916 (struct cmd_config_e_tag_result, 10917 set, "set"); 10918 cmdline_parse_token_string_t cmd_config_e_tag_insertion = 10919 TOKEN_STRING_INITIALIZER 10920 (struct cmd_config_e_tag_result, 10921 insertion, "insertion"); 10922 cmdline_parse_token_string_t cmd_config_e_tag_stripping = 10923 TOKEN_STRING_INITIALIZER 10924 (struct cmd_config_e_tag_result, 10925 stripping, "stripping"); 10926 cmdline_parse_token_string_t cmd_config_e_tag_forwarding = 10927 TOKEN_STRING_INITIALIZER 10928 (struct cmd_config_e_tag_result, 10929 forwarding, "forwarding"); 10930 cmdline_parse_token_string_t cmd_config_e_tag_filter = 10931 TOKEN_STRING_INITIALIZER 10932 (struct cmd_config_e_tag_result, 10933 filter, "filter"); 10934 cmdline_parse_token_string_t cmd_config_e_tag_add = 10935 TOKEN_STRING_INITIALIZER 10936 (struct cmd_config_e_tag_result, 10937 add, "add"); 10938 cmdline_parse_token_string_t cmd_config_e_tag_del = 10939 TOKEN_STRING_INITIALIZER 10940 (struct cmd_config_e_tag_result, 10941 del, "del"); 10942 cmdline_parse_token_string_t cmd_config_e_tag_on = 10943 TOKEN_STRING_INITIALIZER 10944 (struct cmd_config_e_tag_result, 10945 on, "on"); 10946 cmdline_parse_token_string_t cmd_config_e_tag_off = 10947 TOKEN_STRING_INITIALIZER 10948 (struct cmd_config_e_tag_result, 10949 off, "off"); 10950 cmdline_parse_token_string_t cmd_config_e_tag_on_off = 10951 TOKEN_STRING_INITIALIZER 10952 (struct cmd_config_e_tag_result, 10953 on_off, "on#off"); 10954 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id = 10955 TOKEN_STRING_INITIALIZER 10956 (struct cmd_config_e_tag_result, 10957 port_tag_id, "port-tag-id"); 10958 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val = 10959 TOKEN_NUM_INITIALIZER 10960 (struct cmd_config_e_tag_result, 10961 port_tag_id_val, UINT32); 10962 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id = 10963 TOKEN_STRING_INITIALIZER 10964 (struct cmd_config_e_tag_result, 10965 e_tag_id, "e-tag-id"); 10966 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val = 10967 TOKEN_NUM_INITIALIZER 10968 (struct cmd_config_e_tag_result, 10969 e_tag_id_val, UINT16); 10970 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool = 10971 TOKEN_STRING_INITIALIZER 10972 (struct cmd_config_e_tag_result, 10973 dst_pool, "dst-pool"); 10974 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val = 10975 TOKEN_NUM_INITIALIZER 10976 (struct cmd_config_e_tag_result, 10977 dst_pool_val, UINT8); 10978 cmdline_parse_token_string_t cmd_config_e_tag_port = 10979 TOKEN_STRING_INITIALIZER 10980 (struct cmd_config_e_tag_result, 10981 port, "port"); 10982 cmdline_parse_token_num_t cmd_config_e_tag_port_id = 10983 TOKEN_NUM_INITIALIZER 10984 (struct cmd_config_e_tag_result, 10985 port_id, UINT8); 10986 cmdline_parse_token_string_t cmd_config_e_tag_vf = 10987 TOKEN_STRING_INITIALIZER 10988 (struct cmd_config_e_tag_result, 10989 vf, "vf"); 10990 cmdline_parse_token_num_t cmd_config_e_tag_vf_id = 10991 TOKEN_NUM_INITIALIZER 10992 (struct cmd_config_e_tag_result, 10993 vf_id, UINT8); 10994 10995 /* E-tag insertion configuration */ 10996 static void 10997 cmd_config_e_tag_insertion_en_parsed( 10998 void *parsed_result, 10999 __attribute__((unused)) struct cmdline *cl, 11000 __attribute__((unused)) void *data) 11001 { 11002 struct cmd_config_e_tag_result *res = 11003 parsed_result; 11004 struct rte_eth_l2_tunnel_conf entry; 11005 11006 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11007 return; 11008 11009 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11010 entry.tunnel_id = res->port_tag_id_val; 11011 entry.vf_id = res->vf_id; 11012 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 11013 &entry, 11014 ETH_L2_TUNNEL_INSERTION_MASK, 11015 1); 11016 } 11017 11018 static void 11019 cmd_config_e_tag_insertion_dis_parsed( 11020 void *parsed_result, 11021 __attribute__((unused)) struct cmdline *cl, 11022 __attribute__((unused)) void *data) 11023 { 11024 struct cmd_config_e_tag_result *res = 11025 parsed_result; 11026 struct rte_eth_l2_tunnel_conf entry; 11027 11028 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11029 return; 11030 11031 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11032 entry.vf_id = res->vf_id; 11033 11034 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 11035 &entry, 11036 ETH_L2_TUNNEL_INSERTION_MASK, 11037 0); 11038 } 11039 11040 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = { 11041 .f = cmd_config_e_tag_insertion_en_parsed, 11042 .data = NULL, 11043 .help_str = "E-tag ... : E-tag insertion enable", 11044 .tokens = { 11045 (void *)&cmd_config_e_tag_e_tag, 11046 (void *)&cmd_config_e_tag_set, 11047 (void *)&cmd_config_e_tag_insertion, 11048 (void *)&cmd_config_e_tag_on, 11049 (void *)&cmd_config_e_tag_port_tag_id, 11050 (void *)&cmd_config_e_tag_port_tag_id_val, 11051 (void *)&cmd_config_e_tag_port, 11052 (void *)&cmd_config_e_tag_port_id, 11053 (void *)&cmd_config_e_tag_vf, 11054 (void *)&cmd_config_e_tag_vf_id, 11055 NULL, 11056 }, 11057 }; 11058 11059 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = { 11060 .f = cmd_config_e_tag_insertion_dis_parsed, 11061 .data = NULL, 11062 .help_str = "E-tag ... : E-tag insertion disable", 11063 .tokens = { 11064 (void *)&cmd_config_e_tag_e_tag, 11065 (void *)&cmd_config_e_tag_set, 11066 (void *)&cmd_config_e_tag_insertion, 11067 (void *)&cmd_config_e_tag_off, 11068 (void *)&cmd_config_e_tag_port, 11069 (void *)&cmd_config_e_tag_port_id, 11070 (void *)&cmd_config_e_tag_vf, 11071 (void *)&cmd_config_e_tag_vf_id, 11072 NULL, 11073 }, 11074 }; 11075 11076 /* E-tag stripping configuration */ 11077 static void 11078 cmd_config_e_tag_stripping_parsed( 11079 void *parsed_result, 11080 __attribute__((unused)) struct cmdline *cl, 11081 __attribute__((unused)) void *data) 11082 { 11083 struct cmd_config_e_tag_result *res = 11084 parsed_result; 11085 struct rte_eth_l2_tunnel_conf entry; 11086 11087 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11088 return; 11089 11090 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11091 11092 if (!strcmp(res->on_off, "on")) 11093 rte_eth_dev_l2_tunnel_offload_set 11094 (res->port_id, 11095 &entry, 11096 ETH_L2_TUNNEL_STRIPPING_MASK, 11097 1); 11098 else 11099 rte_eth_dev_l2_tunnel_offload_set 11100 (res->port_id, 11101 &entry, 11102 ETH_L2_TUNNEL_STRIPPING_MASK, 11103 0); 11104 } 11105 11106 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = { 11107 .f = cmd_config_e_tag_stripping_parsed, 11108 .data = NULL, 11109 .help_str = "E-tag ... : E-tag stripping enable/disable", 11110 .tokens = { 11111 (void *)&cmd_config_e_tag_e_tag, 11112 (void *)&cmd_config_e_tag_set, 11113 (void *)&cmd_config_e_tag_stripping, 11114 (void *)&cmd_config_e_tag_on_off, 11115 (void *)&cmd_config_e_tag_port, 11116 (void *)&cmd_config_e_tag_port_id, 11117 NULL, 11118 }, 11119 }; 11120 11121 /* E-tag forwarding configuration */ 11122 static void 11123 cmd_config_e_tag_forwarding_parsed( 11124 void *parsed_result, 11125 __attribute__((unused)) struct cmdline *cl, 11126 __attribute__((unused)) void *data) 11127 { 11128 struct cmd_config_e_tag_result *res = parsed_result; 11129 struct rte_eth_l2_tunnel_conf entry; 11130 11131 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11132 return; 11133 11134 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11135 11136 if (!strcmp(res->on_off, "on")) 11137 rte_eth_dev_l2_tunnel_offload_set 11138 (res->port_id, 11139 &entry, 11140 ETH_L2_TUNNEL_FORWARDING_MASK, 11141 1); 11142 else 11143 rte_eth_dev_l2_tunnel_offload_set 11144 (res->port_id, 11145 &entry, 11146 ETH_L2_TUNNEL_FORWARDING_MASK, 11147 0); 11148 } 11149 11150 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = { 11151 .f = cmd_config_e_tag_forwarding_parsed, 11152 .data = NULL, 11153 .help_str = "E-tag ... : E-tag forwarding enable/disable", 11154 .tokens = { 11155 (void *)&cmd_config_e_tag_e_tag, 11156 (void *)&cmd_config_e_tag_set, 11157 (void *)&cmd_config_e_tag_forwarding, 11158 (void *)&cmd_config_e_tag_on_off, 11159 (void *)&cmd_config_e_tag_port, 11160 (void *)&cmd_config_e_tag_port_id, 11161 NULL, 11162 }, 11163 }; 11164 11165 /* E-tag filter configuration */ 11166 static void 11167 cmd_config_e_tag_filter_add_parsed( 11168 void *parsed_result, 11169 __attribute__((unused)) struct cmdline *cl, 11170 __attribute__((unused)) void *data) 11171 { 11172 struct cmd_config_e_tag_result *res = parsed_result; 11173 struct rte_eth_l2_tunnel_conf entry; 11174 int ret = 0; 11175 11176 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11177 return; 11178 11179 if (res->e_tag_id_val > 0x3fff) { 11180 printf("e-tag-id must be equal or less than 0x3fff.\n"); 11181 return; 11182 } 11183 11184 ret = rte_eth_dev_filter_supported(res->port_id, 11185 RTE_ETH_FILTER_L2_TUNNEL); 11186 if (ret < 0) { 11187 printf("E-tag filter is not supported on port %u.\n", 11188 res->port_id); 11189 return; 11190 } 11191 11192 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11193 entry.tunnel_id = res->e_tag_id_val; 11194 entry.pool = res->dst_pool_val; 11195 11196 ret = rte_eth_dev_filter_ctrl(res->port_id, 11197 RTE_ETH_FILTER_L2_TUNNEL, 11198 RTE_ETH_FILTER_ADD, 11199 &entry); 11200 if (ret < 0) 11201 printf("E-tag filter programming error: (%s)\n", 11202 strerror(-ret)); 11203 } 11204 11205 cmdline_parse_inst_t cmd_config_e_tag_filter_add = { 11206 .f = cmd_config_e_tag_filter_add_parsed, 11207 .data = NULL, 11208 .help_str = "E-tag ... : E-tag filter add", 11209 .tokens = { 11210 (void *)&cmd_config_e_tag_e_tag, 11211 (void *)&cmd_config_e_tag_set, 11212 (void *)&cmd_config_e_tag_filter, 11213 (void *)&cmd_config_e_tag_add, 11214 (void *)&cmd_config_e_tag_e_tag_id, 11215 (void *)&cmd_config_e_tag_e_tag_id_val, 11216 (void *)&cmd_config_e_tag_dst_pool, 11217 (void *)&cmd_config_e_tag_dst_pool_val, 11218 (void *)&cmd_config_e_tag_port, 11219 (void *)&cmd_config_e_tag_port_id, 11220 NULL, 11221 }, 11222 }; 11223 11224 static void 11225 cmd_config_e_tag_filter_del_parsed( 11226 void *parsed_result, 11227 __attribute__((unused)) struct cmdline *cl, 11228 __attribute__((unused)) void *data) 11229 { 11230 struct cmd_config_e_tag_result *res = parsed_result; 11231 struct rte_eth_l2_tunnel_conf entry; 11232 int ret = 0; 11233 11234 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11235 return; 11236 11237 if (res->e_tag_id_val > 0x3fff) { 11238 printf("e-tag-id must be less than 0x3fff.\n"); 11239 return; 11240 } 11241 11242 ret = rte_eth_dev_filter_supported(res->port_id, 11243 RTE_ETH_FILTER_L2_TUNNEL); 11244 if (ret < 0) { 11245 printf("E-tag filter is not supported on port %u.\n", 11246 res->port_id); 11247 return; 11248 } 11249 11250 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11251 entry.tunnel_id = res->e_tag_id_val; 11252 11253 ret = rte_eth_dev_filter_ctrl(res->port_id, 11254 RTE_ETH_FILTER_L2_TUNNEL, 11255 RTE_ETH_FILTER_DELETE, 11256 &entry); 11257 if (ret < 0) 11258 printf("E-tag filter programming error: (%s)\n", 11259 strerror(-ret)); 11260 } 11261 11262 cmdline_parse_inst_t cmd_config_e_tag_filter_del = { 11263 .f = cmd_config_e_tag_filter_del_parsed, 11264 .data = NULL, 11265 .help_str = "E-tag ... : E-tag filter delete", 11266 .tokens = { 11267 (void *)&cmd_config_e_tag_e_tag, 11268 (void *)&cmd_config_e_tag_set, 11269 (void *)&cmd_config_e_tag_filter, 11270 (void *)&cmd_config_e_tag_del, 11271 (void *)&cmd_config_e_tag_e_tag_id, 11272 (void *)&cmd_config_e_tag_e_tag_id_val, 11273 (void *)&cmd_config_e_tag_port, 11274 (void *)&cmd_config_e_tag_port_id, 11275 NULL, 11276 }, 11277 }; 11278 11279 /* vf vlan anti spoof configuration */ 11280 11281 /* Common result structure for vf vlan anti spoof */ 11282 struct cmd_vf_vlan_anti_spoof_result { 11283 cmdline_fixed_string_t set; 11284 cmdline_fixed_string_t vf; 11285 cmdline_fixed_string_t vlan; 11286 cmdline_fixed_string_t antispoof; 11287 uint8_t port_id; 11288 uint32_t vf_id; 11289 cmdline_fixed_string_t on_off; 11290 }; 11291 11292 /* Common CLI fields for vf vlan anti spoof enable disable */ 11293 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 11294 TOKEN_STRING_INITIALIZER 11295 (struct cmd_vf_vlan_anti_spoof_result, 11296 set, "set"); 11297 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 11298 TOKEN_STRING_INITIALIZER 11299 (struct cmd_vf_vlan_anti_spoof_result, 11300 vf, "vf"); 11301 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 11302 TOKEN_STRING_INITIALIZER 11303 (struct cmd_vf_vlan_anti_spoof_result, 11304 vlan, "vlan"); 11305 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 11306 TOKEN_STRING_INITIALIZER 11307 (struct cmd_vf_vlan_anti_spoof_result, 11308 antispoof, "antispoof"); 11309 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 11310 TOKEN_NUM_INITIALIZER 11311 (struct cmd_vf_vlan_anti_spoof_result, 11312 port_id, UINT8); 11313 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 11314 TOKEN_NUM_INITIALIZER 11315 (struct cmd_vf_vlan_anti_spoof_result, 11316 vf_id, UINT32); 11317 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 11318 TOKEN_STRING_INITIALIZER 11319 (struct cmd_vf_vlan_anti_spoof_result, 11320 on_off, "on#off"); 11321 11322 static void 11323 cmd_set_vf_vlan_anti_spoof_parsed( 11324 void *parsed_result, 11325 __attribute__((unused)) struct cmdline *cl, 11326 __attribute__((unused)) void *data) 11327 { 11328 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 11329 int ret = -ENOTSUP; 11330 11331 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11332 11333 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11334 return; 11335 11336 #ifdef RTE_LIBRTE_IXGBE_PMD 11337 if (ret == -ENOTSUP) 11338 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 11339 res->vf_id, is_on); 11340 #endif 11341 #ifdef RTE_LIBRTE_I40E_PMD 11342 if (ret == -ENOTSUP) 11343 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 11344 res->vf_id, is_on); 11345 #endif 11346 #ifdef RTE_LIBRTE_BNXT_PMD 11347 if (ret == -ENOTSUP) 11348 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id, 11349 res->vf_id, is_on); 11350 #endif 11351 11352 switch (ret) { 11353 case 0: 11354 break; 11355 case -EINVAL: 11356 printf("invalid vf_id %d\n", res->vf_id); 11357 break; 11358 case -ENODEV: 11359 printf("invalid port_id %d\n", res->port_id); 11360 break; 11361 case -ENOTSUP: 11362 printf("function not implemented\n"); 11363 break; 11364 default: 11365 printf("programming error: (%s)\n", strerror(-ret)); 11366 } 11367 } 11368 11369 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 11370 .f = cmd_set_vf_vlan_anti_spoof_parsed, 11371 .data = NULL, 11372 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 11373 .tokens = { 11374 (void *)&cmd_vf_vlan_anti_spoof_set, 11375 (void *)&cmd_vf_vlan_anti_spoof_vf, 11376 (void *)&cmd_vf_vlan_anti_spoof_vlan, 11377 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 11378 (void *)&cmd_vf_vlan_anti_spoof_port_id, 11379 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 11380 (void *)&cmd_vf_vlan_anti_spoof_on_off, 11381 NULL, 11382 }, 11383 }; 11384 11385 /* vf mac anti spoof configuration */ 11386 11387 /* Common result structure for vf mac anti spoof */ 11388 struct cmd_vf_mac_anti_spoof_result { 11389 cmdline_fixed_string_t set; 11390 cmdline_fixed_string_t vf; 11391 cmdline_fixed_string_t mac; 11392 cmdline_fixed_string_t antispoof; 11393 uint8_t port_id; 11394 uint32_t vf_id; 11395 cmdline_fixed_string_t on_off; 11396 }; 11397 11398 /* Common CLI fields for vf mac anti spoof enable disable */ 11399 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 11400 TOKEN_STRING_INITIALIZER 11401 (struct cmd_vf_mac_anti_spoof_result, 11402 set, "set"); 11403 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 11404 TOKEN_STRING_INITIALIZER 11405 (struct cmd_vf_mac_anti_spoof_result, 11406 vf, "vf"); 11407 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 11408 TOKEN_STRING_INITIALIZER 11409 (struct cmd_vf_mac_anti_spoof_result, 11410 mac, "mac"); 11411 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 11412 TOKEN_STRING_INITIALIZER 11413 (struct cmd_vf_mac_anti_spoof_result, 11414 antispoof, "antispoof"); 11415 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 11416 TOKEN_NUM_INITIALIZER 11417 (struct cmd_vf_mac_anti_spoof_result, 11418 port_id, UINT8); 11419 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 11420 TOKEN_NUM_INITIALIZER 11421 (struct cmd_vf_mac_anti_spoof_result, 11422 vf_id, UINT32); 11423 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 11424 TOKEN_STRING_INITIALIZER 11425 (struct cmd_vf_mac_anti_spoof_result, 11426 on_off, "on#off"); 11427 11428 static void 11429 cmd_set_vf_mac_anti_spoof_parsed( 11430 void *parsed_result, 11431 __attribute__((unused)) struct cmdline *cl, 11432 __attribute__((unused)) void *data) 11433 { 11434 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 11435 int ret = -ENOTSUP; 11436 11437 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11438 11439 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11440 return; 11441 11442 #ifdef RTE_LIBRTE_IXGBE_PMD 11443 if (ret == -ENOTSUP) 11444 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 11445 res->vf_id, is_on); 11446 #endif 11447 #ifdef RTE_LIBRTE_I40E_PMD 11448 if (ret == -ENOTSUP) 11449 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 11450 res->vf_id, is_on); 11451 #endif 11452 #ifdef RTE_LIBRTE_BNXT_PMD 11453 if (ret == -ENOTSUP) 11454 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id, 11455 res->vf_id, is_on); 11456 #endif 11457 11458 switch (ret) { 11459 case 0: 11460 break; 11461 case -EINVAL: 11462 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11463 break; 11464 case -ENODEV: 11465 printf("invalid port_id %d\n", res->port_id); 11466 break; 11467 case -ENOTSUP: 11468 printf("function not implemented\n"); 11469 break; 11470 default: 11471 printf("programming error: (%s)\n", strerror(-ret)); 11472 } 11473 } 11474 11475 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 11476 .f = cmd_set_vf_mac_anti_spoof_parsed, 11477 .data = NULL, 11478 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 11479 .tokens = { 11480 (void *)&cmd_vf_mac_anti_spoof_set, 11481 (void *)&cmd_vf_mac_anti_spoof_vf, 11482 (void *)&cmd_vf_mac_anti_spoof_mac, 11483 (void *)&cmd_vf_mac_anti_spoof_antispoof, 11484 (void *)&cmd_vf_mac_anti_spoof_port_id, 11485 (void *)&cmd_vf_mac_anti_spoof_vf_id, 11486 (void *)&cmd_vf_mac_anti_spoof_on_off, 11487 NULL, 11488 }, 11489 }; 11490 11491 /* vf vlan strip queue configuration */ 11492 11493 /* Common result structure for vf mac anti spoof */ 11494 struct cmd_vf_vlan_stripq_result { 11495 cmdline_fixed_string_t set; 11496 cmdline_fixed_string_t vf; 11497 cmdline_fixed_string_t vlan; 11498 cmdline_fixed_string_t stripq; 11499 uint8_t port_id; 11500 uint16_t vf_id; 11501 cmdline_fixed_string_t on_off; 11502 }; 11503 11504 /* Common CLI fields for vf vlan strip enable disable */ 11505 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 11506 TOKEN_STRING_INITIALIZER 11507 (struct cmd_vf_vlan_stripq_result, 11508 set, "set"); 11509 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 11510 TOKEN_STRING_INITIALIZER 11511 (struct cmd_vf_vlan_stripq_result, 11512 vf, "vf"); 11513 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 11514 TOKEN_STRING_INITIALIZER 11515 (struct cmd_vf_vlan_stripq_result, 11516 vlan, "vlan"); 11517 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 11518 TOKEN_STRING_INITIALIZER 11519 (struct cmd_vf_vlan_stripq_result, 11520 stripq, "stripq"); 11521 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 11522 TOKEN_NUM_INITIALIZER 11523 (struct cmd_vf_vlan_stripq_result, 11524 port_id, UINT8); 11525 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 11526 TOKEN_NUM_INITIALIZER 11527 (struct cmd_vf_vlan_stripq_result, 11528 vf_id, UINT16); 11529 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 11530 TOKEN_STRING_INITIALIZER 11531 (struct cmd_vf_vlan_stripq_result, 11532 on_off, "on#off"); 11533 11534 static void 11535 cmd_set_vf_vlan_stripq_parsed( 11536 void *parsed_result, 11537 __attribute__((unused)) struct cmdline *cl, 11538 __attribute__((unused)) void *data) 11539 { 11540 struct cmd_vf_vlan_stripq_result *res = parsed_result; 11541 int ret = -ENOTSUP; 11542 11543 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11544 11545 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11546 return; 11547 11548 #ifdef RTE_LIBRTE_IXGBE_PMD 11549 if (ret == -ENOTSUP) 11550 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 11551 res->vf_id, is_on); 11552 #endif 11553 #ifdef RTE_LIBRTE_I40E_PMD 11554 if (ret == -ENOTSUP) 11555 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 11556 res->vf_id, is_on); 11557 #endif 11558 #ifdef RTE_LIBRTE_BNXT_PMD 11559 if (ret == -ENOTSUP) 11560 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id, 11561 res->vf_id, is_on); 11562 #endif 11563 11564 switch (ret) { 11565 case 0: 11566 break; 11567 case -EINVAL: 11568 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11569 break; 11570 case -ENODEV: 11571 printf("invalid port_id %d\n", res->port_id); 11572 break; 11573 case -ENOTSUP: 11574 printf("function not implemented\n"); 11575 break; 11576 default: 11577 printf("programming error: (%s)\n", strerror(-ret)); 11578 } 11579 } 11580 11581 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 11582 .f = cmd_set_vf_vlan_stripq_parsed, 11583 .data = NULL, 11584 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 11585 .tokens = { 11586 (void *)&cmd_vf_vlan_stripq_set, 11587 (void *)&cmd_vf_vlan_stripq_vf, 11588 (void *)&cmd_vf_vlan_stripq_vlan, 11589 (void *)&cmd_vf_vlan_stripq_stripq, 11590 (void *)&cmd_vf_vlan_stripq_port_id, 11591 (void *)&cmd_vf_vlan_stripq_vf_id, 11592 (void *)&cmd_vf_vlan_stripq_on_off, 11593 NULL, 11594 }, 11595 }; 11596 11597 /* vf vlan insert configuration */ 11598 11599 /* Common result structure for vf vlan insert */ 11600 struct cmd_vf_vlan_insert_result { 11601 cmdline_fixed_string_t set; 11602 cmdline_fixed_string_t vf; 11603 cmdline_fixed_string_t vlan; 11604 cmdline_fixed_string_t insert; 11605 uint8_t port_id; 11606 uint16_t vf_id; 11607 uint16_t vlan_id; 11608 }; 11609 11610 /* Common CLI fields for vf vlan insert enable disable */ 11611 cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 11612 TOKEN_STRING_INITIALIZER 11613 (struct cmd_vf_vlan_insert_result, 11614 set, "set"); 11615 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 11616 TOKEN_STRING_INITIALIZER 11617 (struct cmd_vf_vlan_insert_result, 11618 vf, "vf"); 11619 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 11620 TOKEN_STRING_INITIALIZER 11621 (struct cmd_vf_vlan_insert_result, 11622 vlan, "vlan"); 11623 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 11624 TOKEN_STRING_INITIALIZER 11625 (struct cmd_vf_vlan_insert_result, 11626 insert, "insert"); 11627 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 11628 TOKEN_NUM_INITIALIZER 11629 (struct cmd_vf_vlan_insert_result, 11630 port_id, UINT8); 11631 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 11632 TOKEN_NUM_INITIALIZER 11633 (struct cmd_vf_vlan_insert_result, 11634 vf_id, UINT16); 11635 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 11636 TOKEN_NUM_INITIALIZER 11637 (struct cmd_vf_vlan_insert_result, 11638 vlan_id, UINT16); 11639 11640 static void 11641 cmd_set_vf_vlan_insert_parsed( 11642 void *parsed_result, 11643 __attribute__((unused)) struct cmdline *cl, 11644 __attribute__((unused)) void *data) 11645 { 11646 struct cmd_vf_vlan_insert_result *res = parsed_result; 11647 int ret = -ENOTSUP; 11648 11649 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11650 return; 11651 11652 #ifdef RTE_LIBRTE_IXGBE_PMD 11653 if (ret == -ENOTSUP) 11654 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 11655 res->vlan_id); 11656 #endif 11657 #ifdef RTE_LIBRTE_I40E_PMD 11658 if (ret == -ENOTSUP) 11659 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 11660 res->vlan_id); 11661 #endif 11662 #ifdef RTE_LIBRTE_BNXT_PMD 11663 if (ret == -ENOTSUP) 11664 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id, 11665 res->vlan_id); 11666 #endif 11667 11668 switch (ret) { 11669 case 0: 11670 break; 11671 case -EINVAL: 11672 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id); 11673 break; 11674 case -ENODEV: 11675 printf("invalid port_id %d\n", res->port_id); 11676 break; 11677 case -ENOTSUP: 11678 printf("function not implemented\n"); 11679 break; 11680 default: 11681 printf("programming error: (%s)\n", strerror(-ret)); 11682 } 11683 } 11684 11685 cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 11686 .f = cmd_set_vf_vlan_insert_parsed, 11687 .data = NULL, 11688 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 11689 .tokens = { 11690 (void *)&cmd_vf_vlan_insert_set, 11691 (void *)&cmd_vf_vlan_insert_vf, 11692 (void *)&cmd_vf_vlan_insert_vlan, 11693 (void *)&cmd_vf_vlan_insert_insert, 11694 (void *)&cmd_vf_vlan_insert_port_id, 11695 (void *)&cmd_vf_vlan_insert_vf_id, 11696 (void *)&cmd_vf_vlan_insert_vlan_id, 11697 NULL, 11698 }, 11699 }; 11700 11701 /* tx loopback configuration */ 11702 11703 /* Common result structure for tx loopback */ 11704 struct cmd_tx_loopback_result { 11705 cmdline_fixed_string_t set; 11706 cmdline_fixed_string_t tx; 11707 cmdline_fixed_string_t loopback; 11708 uint8_t port_id; 11709 cmdline_fixed_string_t on_off; 11710 }; 11711 11712 /* Common CLI fields for tx loopback enable disable */ 11713 cmdline_parse_token_string_t cmd_tx_loopback_set = 11714 TOKEN_STRING_INITIALIZER 11715 (struct cmd_tx_loopback_result, 11716 set, "set"); 11717 cmdline_parse_token_string_t cmd_tx_loopback_tx = 11718 TOKEN_STRING_INITIALIZER 11719 (struct cmd_tx_loopback_result, 11720 tx, "tx"); 11721 cmdline_parse_token_string_t cmd_tx_loopback_loopback = 11722 TOKEN_STRING_INITIALIZER 11723 (struct cmd_tx_loopback_result, 11724 loopback, "loopback"); 11725 cmdline_parse_token_num_t cmd_tx_loopback_port_id = 11726 TOKEN_NUM_INITIALIZER 11727 (struct cmd_tx_loopback_result, 11728 port_id, UINT8); 11729 cmdline_parse_token_string_t cmd_tx_loopback_on_off = 11730 TOKEN_STRING_INITIALIZER 11731 (struct cmd_tx_loopback_result, 11732 on_off, "on#off"); 11733 11734 static void 11735 cmd_set_tx_loopback_parsed( 11736 void *parsed_result, 11737 __attribute__((unused)) struct cmdline *cl, 11738 __attribute__((unused)) void *data) 11739 { 11740 struct cmd_tx_loopback_result *res = parsed_result; 11741 int ret = -ENOTSUP; 11742 11743 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11744 11745 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11746 return; 11747 11748 #ifdef RTE_LIBRTE_IXGBE_PMD 11749 if (ret == -ENOTSUP) 11750 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 11751 #endif 11752 #ifdef RTE_LIBRTE_I40E_PMD 11753 if (ret == -ENOTSUP) 11754 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 11755 #endif 11756 #ifdef RTE_LIBRTE_BNXT_PMD 11757 if (ret == -ENOTSUP) 11758 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on); 11759 #endif 11760 11761 switch (ret) { 11762 case 0: 11763 break; 11764 case -EINVAL: 11765 printf("invalid is_on %d\n", is_on); 11766 break; 11767 case -ENODEV: 11768 printf("invalid port_id %d\n", res->port_id); 11769 break; 11770 case -ENOTSUP: 11771 printf("function not implemented\n"); 11772 break; 11773 default: 11774 printf("programming error: (%s)\n", strerror(-ret)); 11775 } 11776 } 11777 11778 cmdline_parse_inst_t cmd_set_tx_loopback = { 11779 .f = cmd_set_tx_loopback_parsed, 11780 .data = NULL, 11781 .help_str = "set tx loopback <port_id> on|off", 11782 .tokens = { 11783 (void *)&cmd_tx_loopback_set, 11784 (void *)&cmd_tx_loopback_tx, 11785 (void *)&cmd_tx_loopback_loopback, 11786 (void *)&cmd_tx_loopback_port_id, 11787 (void *)&cmd_tx_loopback_on_off, 11788 NULL, 11789 }, 11790 }; 11791 11792 /* all queues drop enable configuration */ 11793 11794 /* Common result structure for all queues drop enable */ 11795 struct cmd_all_queues_drop_en_result { 11796 cmdline_fixed_string_t set; 11797 cmdline_fixed_string_t all; 11798 cmdline_fixed_string_t queues; 11799 cmdline_fixed_string_t drop; 11800 uint8_t port_id; 11801 cmdline_fixed_string_t on_off; 11802 }; 11803 11804 /* Common CLI fields for tx loopback enable disable */ 11805 cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 11806 TOKEN_STRING_INITIALIZER 11807 (struct cmd_all_queues_drop_en_result, 11808 set, "set"); 11809 cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 11810 TOKEN_STRING_INITIALIZER 11811 (struct cmd_all_queues_drop_en_result, 11812 all, "all"); 11813 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 11814 TOKEN_STRING_INITIALIZER 11815 (struct cmd_all_queues_drop_en_result, 11816 queues, "queues"); 11817 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 11818 TOKEN_STRING_INITIALIZER 11819 (struct cmd_all_queues_drop_en_result, 11820 drop, "drop"); 11821 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 11822 TOKEN_NUM_INITIALIZER 11823 (struct cmd_all_queues_drop_en_result, 11824 port_id, UINT8); 11825 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 11826 TOKEN_STRING_INITIALIZER 11827 (struct cmd_all_queues_drop_en_result, 11828 on_off, "on#off"); 11829 11830 static void 11831 cmd_set_all_queues_drop_en_parsed( 11832 void *parsed_result, 11833 __attribute__((unused)) struct cmdline *cl, 11834 __attribute__((unused)) void *data) 11835 { 11836 struct cmd_all_queues_drop_en_result *res = parsed_result; 11837 int ret = -ENOTSUP; 11838 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11839 11840 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11841 return; 11842 11843 #ifdef RTE_LIBRTE_IXGBE_PMD 11844 if (ret == -ENOTSUP) 11845 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 11846 #endif 11847 #ifdef RTE_LIBRTE_BNXT_PMD 11848 if (ret == -ENOTSUP) 11849 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on); 11850 #endif 11851 switch (ret) { 11852 case 0: 11853 break; 11854 case -EINVAL: 11855 printf("invalid is_on %d\n", is_on); 11856 break; 11857 case -ENODEV: 11858 printf("invalid port_id %d\n", res->port_id); 11859 break; 11860 case -ENOTSUP: 11861 printf("function not implemented\n"); 11862 break; 11863 default: 11864 printf("programming error: (%s)\n", strerror(-ret)); 11865 } 11866 } 11867 11868 cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 11869 .f = cmd_set_all_queues_drop_en_parsed, 11870 .data = NULL, 11871 .help_str = "set all queues drop <port_id> on|off", 11872 .tokens = { 11873 (void *)&cmd_all_queues_drop_en_set, 11874 (void *)&cmd_all_queues_drop_en_all, 11875 (void *)&cmd_all_queues_drop_en_queues, 11876 (void *)&cmd_all_queues_drop_en_drop, 11877 (void *)&cmd_all_queues_drop_en_port_id, 11878 (void *)&cmd_all_queues_drop_en_on_off, 11879 NULL, 11880 }, 11881 }; 11882 11883 /* vf split drop enable configuration */ 11884 11885 /* Common result structure for vf split drop enable */ 11886 struct cmd_vf_split_drop_en_result { 11887 cmdline_fixed_string_t set; 11888 cmdline_fixed_string_t vf; 11889 cmdline_fixed_string_t split; 11890 cmdline_fixed_string_t drop; 11891 uint8_t port_id; 11892 uint16_t vf_id; 11893 cmdline_fixed_string_t on_off; 11894 }; 11895 11896 /* Common CLI fields for vf split drop enable disable */ 11897 cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 11898 TOKEN_STRING_INITIALIZER 11899 (struct cmd_vf_split_drop_en_result, 11900 set, "set"); 11901 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 11902 TOKEN_STRING_INITIALIZER 11903 (struct cmd_vf_split_drop_en_result, 11904 vf, "vf"); 11905 cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 11906 TOKEN_STRING_INITIALIZER 11907 (struct cmd_vf_split_drop_en_result, 11908 split, "split"); 11909 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 11910 TOKEN_STRING_INITIALIZER 11911 (struct cmd_vf_split_drop_en_result, 11912 drop, "drop"); 11913 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 11914 TOKEN_NUM_INITIALIZER 11915 (struct cmd_vf_split_drop_en_result, 11916 port_id, UINT8); 11917 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 11918 TOKEN_NUM_INITIALIZER 11919 (struct cmd_vf_split_drop_en_result, 11920 vf_id, UINT16); 11921 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 11922 TOKEN_STRING_INITIALIZER 11923 (struct cmd_vf_split_drop_en_result, 11924 on_off, "on#off"); 11925 11926 static void 11927 cmd_set_vf_split_drop_en_parsed( 11928 void *parsed_result, 11929 __attribute__((unused)) struct cmdline *cl, 11930 __attribute__((unused)) void *data) 11931 { 11932 struct cmd_vf_split_drop_en_result *res = parsed_result; 11933 int ret = -ENOTSUP; 11934 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11935 11936 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11937 return; 11938 11939 #ifdef RTE_LIBRTE_IXGBE_PMD 11940 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 11941 is_on); 11942 #endif 11943 switch (ret) { 11944 case 0: 11945 break; 11946 case -EINVAL: 11947 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11948 break; 11949 case -ENODEV: 11950 printf("invalid port_id %d\n", res->port_id); 11951 break; 11952 case -ENOTSUP: 11953 printf("not supported on port %d\n", res->port_id); 11954 break; 11955 default: 11956 printf("programming error: (%s)\n", strerror(-ret)); 11957 } 11958 } 11959 11960 cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 11961 .f = cmd_set_vf_split_drop_en_parsed, 11962 .data = NULL, 11963 .help_str = "set vf split drop <port_id> <vf_id> on|off", 11964 .tokens = { 11965 (void *)&cmd_vf_split_drop_en_set, 11966 (void *)&cmd_vf_split_drop_en_vf, 11967 (void *)&cmd_vf_split_drop_en_split, 11968 (void *)&cmd_vf_split_drop_en_drop, 11969 (void *)&cmd_vf_split_drop_en_port_id, 11970 (void *)&cmd_vf_split_drop_en_vf_id, 11971 (void *)&cmd_vf_split_drop_en_on_off, 11972 NULL, 11973 }, 11974 }; 11975 11976 /* vf mac address configuration */ 11977 11978 /* Common result structure for vf mac address */ 11979 struct cmd_set_vf_mac_addr_result { 11980 cmdline_fixed_string_t set; 11981 cmdline_fixed_string_t vf; 11982 cmdline_fixed_string_t mac; 11983 cmdline_fixed_string_t addr; 11984 uint8_t port_id; 11985 uint16_t vf_id; 11986 struct ether_addr mac_addr; 11987 11988 }; 11989 11990 /* Common CLI fields for vf split drop enable disable */ 11991 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 11992 TOKEN_STRING_INITIALIZER 11993 (struct cmd_set_vf_mac_addr_result, 11994 set, "set"); 11995 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 11996 TOKEN_STRING_INITIALIZER 11997 (struct cmd_set_vf_mac_addr_result, 11998 vf, "vf"); 11999 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 12000 TOKEN_STRING_INITIALIZER 12001 (struct cmd_set_vf_mac_addr_result, 12002 mac, "mac"); 12003 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 12004 TOKEN_STRING_INITIALIZER 12005 (struct cmd_set_vf_mac_addr_result, 12006 addr, "addr"); 12007 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 12008 TOKEN_NUM_INITIALIZER 12009 (struct cmd_set_vf_mac_addr_result, 12010 port_id, UINT8); 12011 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 12012 TOKEN_NUM_INITIALIZER 12013 (struct cmd_set_vf_mac_addr_result, 12014 vf_id, UINT16); 12015 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 12016 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 12017 mac_addr); 12018 12019 static void 12020 cmd_set_vf_mac_addr_parsed( 12021 void *parsed_result, 12022 __attribute__((unused)) struct cmdline *cl, 12023 __attribute__((unused)) void *data) 12024 { 12025 struct cmd_set_vf_mac_addr_result *res = parsed_result; 12026 int ret = -ENOTSUP; 12027 12028 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12029 return; 12030 12031 #ifdef RTE_LIBRTE_IXGBE_PMD 12032 if (ret == -ENOTSUP) 12033 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 12034 &res->mac_addr); 12035 #endif 12036 #ifdef RTE_LIBRTE_I40E_PMD 12037 if (ret == -ENOTSUP) 12038 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 12039 &res->mac_addr); 12040 #endif 12041 #ifdef RTE_LIBRTE_BNXT_PMD 12042 if (ret == -ENOTSUP) 12043 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id, 12044 &res->mac_addr); 12045 #endif 12046 12047 switch (ret) { 12048 case 0: 12049 break; 12050 case -EINVAL: 12051 printf("invalid vf_id %d or mac_addr\n", res->vf_id); 12052 break; 12053 case -ENODEV: 12054 printf("invalid port_id %d\n", res->port_id); 12055 break; 12056 case -ENOTSUP: 12057 printf("function not implemented\n"); 12058 break; 12059 default: 12060 printf("programming error: (%s)\n", strerror(-ret)); 12061 } 12062 } 12063 12064 cmdline_parse_inst_t cmd_set_vf_mac_addr = { 12065 .f = cmd_set_vf_mac_addr_parsed, 12066 .data = NULL, 12067 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 12068 .tokens = { 12069 (void *)&cmd_set_vf_mac_addr_set, 12070 (void *)&cmd_set_vf_mac_addr_vf, 12071 (void *)&cmd_set_vf_mac_addr_mac, 12072 (void *)&cmd_set_vf_mac_addr_addr, 12073 (void *)&cmd_set_vf_mac_addr_port_id, 12074 (void *)&cmd_set_vf_mac_addr_vf_id, 12075 (void *)&cmd_set_vf_mac_addr_mac_addr, 12076 NULL, 12077 }, 12078 }; 12079 12080 /* MACsec configuration */ 12081 12082 /* Common result structure for MACsec offload enable */ 12083 struct cmd_macsec_offload_on_result { 12084 cmdline_fixed_string_t set; 12085 cmdline_fixed_string_t macsec; 12086 cmdline_fixed_string_t offload; 12087 uint8_t port_id; 12088 cmdline_fixed_string_t on; 12089 cmdline_fixed_string_t encrypt; 12090 cmdline_fixed_string_t en_on_off; 12091 cmdline_fixed_string_t replay_protect; 12092 cmdline_fixed_string_t rp_on_off; 12093 }; 12094 12095 /* Common CLI fields for MACsec offload disable */ 12096 cmdline_parse_token_string_t cmd_macsec_offload_on_set = 12097 TOKEN_STRING_INITIALIZER 12098 (struct cmd_macsec_offload_on_result, 12099 set, "set"); 12100 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 12101 TOKEN_STRING_INITIALIZER 12102 (struct cmd_macsec_offload_on_result, 12103 macsec, "macsec"); 12104 cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 12105 TOKEN_STRING_INITIALIZER 12106 (struct cmd_macsec_offload_on_result, 12107 offload, "offload"); 12108 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 12109 TOKEN_NUM_INITIALIZER 12110 (struct cmd_macsec_offload_on_result, 12111 port_id, UINT8); 12112 cmdline_parse_token_string_t cmd_macsec_offload_on_on = 12113 TOKEN_STRING_INITIALIZER 12114 (struct cmd_macsec_offload_on_result, 12115 on, "on"); 12116 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 12117 TOKEN_STRING_INITIALIZER 12118 (struct cmd_macsec_offload_on_result, 12119 encrypt, "encrypt"); 12120 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 12121 TOKEN_STRING_INITIALIZER 12122 (struct cmd_macsec_offload_on_result, 12123 en_on_off, "on#off"); 12124 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 12125 TOKEN_STRING_INITIALIZER 12126 (struct cmd_macsec_offload_on_result, 12127 replay_protect, "replay-protect"); 12128 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 12129 TOKEN_STRING_INITIALIZER 12130 (struct cmd_macsec_offload_on_result, 12131 rp_on_off, "on#off"); 12132 12133 static void 12134 cmd_set_macsec_offload_on_parsed( 12135 void *parsed_result, 12136 __attribute__((unused)) struct cmdline *cl, 12137 __attribute__((unused)) void *data) 12138 { 12139 struct cmd_macsec_offload_on_result *res = parsed_result; 12140 int ret = -ENOTSUP; 12141 portid_t port_id = res->port_id; 12142 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 12143 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 12144 12145 if (port_id_is_invalid(port_id, ENABLED_WARN)) 12146 return; 12147 12148 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC; 12149 #ifdef RTE_LIBRTE_IXGBE_PMD 12150 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 12151 #endif 12152 RTE_SET_USED(en); 12153 RTE_SET_USED(rp); 12154 12155 switch (ret) { 12156 case 0: 12157 break; 12158 case -ENODEV: 12159 printf("invalid port_id %d\n", port_id); 12160 break; 12161 case -ENOTSUP: 12162 printf("not supported on port %d\n", port_id); 12163 break; 12164 default: 12165 printf("programming error: (%s)\n", strerror(-ret)); 12166 } 12167 } 12168 12169 cmdline_parse_inst_t cmd_set_macsec_offload_on = { 12170 .f = cmd_set_macsec_offload_on_parsed, 12171 .data = NULL, 12172 .help_str = "set macsec offload <port_id> on " 12173 "encrypt on|off replay-protect on|off", 12174 .tokens = { 12175 (void *)&cmd_macsec_offload_on_set, 12176 (void *)&cmd_macsec_offload_on_macsec, 12177 (void *)&cmd_macsec_offload_on_offload, 12178 (void *)&cmd_macsec_offload_on_port_id, 12179 (void *)&cmd_macsec_offload_on_on, 12180 (void *)&cmd_macsec_offload_on_encrypt, 12181 (void *)&cmd_macsec_offload_on_en_on_off, 12182 (void *)&cmd_macsec_offload_on_replay_protect, 12183 (void *)&cmd_macsec_offload_on_rp_on_off, 12184 NULL, 12185 }, 12186 }; 12187 12188 /* Common result structure for MACsec offload disable */ 12189 struct cmd_macsec_offload_off_result { 12190 cmdline_fixed_string_t set; 12191 cmdline_fixed_string_t macsec; 12192 cmdline_fixed_string_t offload; 12193 uint8_t port_id; 12194 cmdline_fixed_string_t off; 12195 }; 12196 12197 /* Common CLI fields for MACsec offload disable */ 12198 cmdline_parse_token_string_t cmd_macsec_offload_off_set = 12199 TOKEN_STRING_INITIALIZER 12200 (struct cmd_macsec_offload_off_result, 12201 set, "set"); 12202 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 12203 TOKEN_STRING_INITIALIZER 12204 (struct cmd_macsec_offload_off_result, 12205 macsec, "macsec"); 12206 cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 12207 TOKEN_STRING_INITIALIZER 12208 (struct cmd_macsec_offload_off_result, 12209 offload, "offload"); 12210 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 12211 TOKEN_NUM_INITIALIZER 12212 (struct cmd_macsec_offload_off_result, 12213 port_id, UINT8); 12214 cmdline_parse_token_string_t cmd_macsec_offload_off_off = 12215 TOKEN_STRING_INITIALIZER 12216 (struct cmd_macsec_offload_off_result, 12217 off, "off"); 12218 12219 static void 12220 cmd_set_macsec_offload_off_parsed( 12221 void *parsed_result, 12222 __attribute__((unused)) struct cmdline *cl, 12223 __attribute__((unused)) void *data) 12224 { 12225 struct cmd_macsec_offload_off_result *res = parsed_result; 12226 int ret = -ENOTSUP; 12227 portid_t port_id = res->port_id; 12228 12229 if (port_id_is_invalid(port_id, ENABLED_WARN)) 12230 return; 12231 12232 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC; 12233 #ifdef RTE_LIBRTE_IXGBE_PMD 12234 ret = rte_pmd_ixgbe_macsec_disable(port_id); 12235 #endif 12236 12237 switch (ret) { 12238 case 0: 12239 break; 12240 case -ENODEV: 12241 printf("invalid port_id %d\n", port_id); 12242 break; 12243 case -ENOTSUP: 12244 printf("not supported on port %d\n", port_id); 12245 break; 12246 default: 12247 printf("programming error: (%s)\n", strerror(-ret)); 12248 } 12249 } 12250 12251 cmdline_parse_inst_t cmd_set_macsec_offload_off = { 12252 .f = cmd_set_macsec_offload_off_parsed, 12253 .data = NULL, 12254 .help_str = "set macsec offload <port_id> off", 12255 .tokens = { 12256 (void *)&cmd_macsec_offload_off_set, 12257 (void *)&cmd_macsec_offload_off_macsec, 12258 (void *)&cmd_macsec_offload_off_offload, 12259 (void *)&cmd_macsec_offload_off_port_id, 12260 (void *)&cmd_macsec_offload_off_off, 12261 NULL, 12262 }, 12263 }; 12264 12265 /* Common result structure for MACsec secure connection configure */ 12266 struct cmd_macsec_sc_result { 12267 cmdline_fixed_string_t set; 12268 cmdline_fixed_string_t macsec; 12269 cmdline_fixed_string_t sc; 12270 cmdline_fixed_string_t tx_rx; 12271 uint8_t port_id; 12272 struct ether_addr mac; 12273 uint16_t pi; 12274 }; 12275 12276 /* Common CLI fields for MACsec secure connection configure */ 12277 cmdline_parse_token_string_t cmd_macsec_sc_set = 12278 TOKEN_STRING_INITIALIZER 12279 (struct cmd_macsec_sc_result, 12280 set, "set"); 12281 cmdline_parse_token_string_t cmd_macsec_sc_macsec = 12282 TOKEN_STRING_INITIALIZER 12283 (struct cmd_macsec_sc_result, 12284 macsec, "macsec"); 12285 cmdline_parse_token_string_t cmd_macsec_sc_sc = 12286 TOKEN_STRING_INITIALIZER 12287 (struct cmd_macsec_sc_result, 12288 sc, "sc"); 12289 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 12290 TOKEN_STRING_INITIALIZER 12291 (struct cmd_macsec_sc_result, 12292 tx_rx, "tx#rx"); 12293 cmdline_parse_token_num_t cmd_macsec_sc_port_id = 12294 TOKEN_NUM_INITIALIZER 12295 (struct cmd_macsec_sc_result, 12296 port_id, UINT8); 12297 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 12298 TOKEN_ETHERADDR_INITIALIZER 12299 (struct cmd_macsec_sc_result, 12300 mac); 12301 cmdline_parse_token_num_t cmd_macsec_sc_pi = 12302 TOKEN_NUM_INITIALIZER 12303 (struct cmd_macsec_sc_result, 12304 pi, UINT16); 12305 12306 static void 12307 cmd_set_macsec_sc_parsed( 12308 void *parsed_result, 12309 __attribute__((unused)) struct cmdline *cl, 12310 __attribute__((unused)) void *data) 12311 { 12312 struct cmd_macsec_sc_result *res = parsed_result; 12313 int ret = -ENOTSUP; 12314 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 12315 12316 #ifdef RTE_LIBRTE_IXGBE_PMD 12317 ret = is_tx ? 12318 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 12319 res->mac.addr_bytes) : 12320 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 12321 res->mac.addr_bytes, res->pi); 12322 #endif 12323 RTE_SET_USED(is_tx); 12324 12325 switch (ret) { 12326 case 0: 12327 break; 12328 case -ENODEV: 12329 printf("invalid port_id %d\n", res->port_id); 12330 break; 12331 case -ENOTSUP: 12332 printf("not supported on port %d\n", res->port_id); 12333 break; 12334 default: 12335 printf("programming error: (%s)\n", strerror(-ret)); 12336 } 12337 } 12338 12339 cmdline_parse_inst_t cmd_set_macsec_sc = { 12340 .f = cmd_set_macsec_sc_parsed, 12341 .data = NULL, 12342 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 12343 .tokens = { 12344 (void *)&cmd_macsec_sc_set, 12345 (void *)&cmd_macsec_sc_macsec, 12346 (void *)&cmd_macsec_sc_sc, 12347 (void *)&cmd_macsec_sc_tx_rx, 12348 (void *)&cmd_macsec_sc_port_id, 12349 (void *)&cmd_macsec_sc_mac, 12350 (void *)&cmd_macsec_sc_pi, 12351 NULL, 12352 }, 12353 }; 12354 12355 /* Common result structure for MACsec secure connection configure */ 12356 struct cmd_macsec_sa_result { 12357 cmdline_fixed_string_t set; 12358 cmdline_fixed_string_t macsec; 12359 cmdline_fixed_string_t sa; 12360 cmdline_fixed_string_t tx_rx; 12361 uint8_t port_id; 12362 uint8_t idx; 12363 uint8_t an; 12364 uint32_t pn; 12365 cmdline_fixed_string_t key; 12366 }; 12367 12368 /* Common CLI fields for MACsec secure connection configure */ 12369 cmdline_parse_token_string_t cmd_macsec_sa_set = 12370 TOKEN_STRING_INITIALIZER 12371 (struct cmd_macsec_sa_result, 12372 set, "set"); 12373 cmdline_parse_token_string_t cmd_macsec_sa_macsec = 12374 TOKEN_STRING_INITIALIZER 12375 (struct cmd_macsec_sa_result, 12376 macsec, "macsec"); 12377 cmdline_parse_token_string_t cmd_macsec_sa_sa = 12378 TOKEN_STRING_INITIALIZER 12379 (struct cmd_macsec_sa_result, 12380 sa, "sa"); 12381 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 12382 TOKEN_STRING_INITIALIZER 12383 (struct cmd_macsec_sa_result, 12384 tx_rx, "tx#rx"); 12385 cmdline_parse_token_num_t cmd_macsec_sa_port_id = 12386 TOKEN_NUM_INITIALIZER 12387 (struct cmd_macsec_sa_result, 12388 port_id, UINT8); 12389 cmdline_parse_token_num_t cmd_macsec_sa_idx = 12390 TOKEN_NUM_INITIALIZER 12391 (struct cmd_macsec_sa_result, 12392 idx, UINT8); 12393 cmdline_parse_token_num_t cmd_macsec_sa_an = 12394 TOKEN_NUM_INITIALIZER 12395 (struct cmd_macsec_sa_result, 12396 an, UINT8); 12397 cmdline_parse_token_num_t cmd_macsec_sa_pn = 12398 TOKEN_NUM_INITIALIZER 12399 (struct cmd_macsec_sa_result, 12400 pn, UINT32); 12401 cmdline_parse_token_string_t cmd_macsec_sa_key = 12402 TOKEN_STRING_INITIALIZER 12403 (struct cmd_macsec_sa_result, 12404 key, NULL); 12405 12406 static void 12407 cmd_set_macsec_sa_parsed( 12408 void *parsed_result, 12409 __attribute__((unused)) struct cmdline *cl, 12410 __attribute__((unused)) void *data) 12411 { 12412 struct cmd_macsec_sa_result *res = parsed_result; 12413 int ret = -ENOTSUP; 12414 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 12415 uint8_t key[16] = { 0 }; 12416 uint8_t xdgt0; 12417 uint8_t xdgt1; 12418 int key_len; 12419 int i; 12420 12421 key_len = strlen(res->key) / 2; 12422 if (key_len > 16) 12423 key_len = 16; 12424 12425 for (i = 0; i < key_len; i++) { 12426 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 12427 if (xdgt0 == 0xFF) 12428 return; 12429 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 12430 if (xdgt1 == 0xFF) 12431 return; 12432 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 12433 } 12434 12435 #ifdef RTE_LIBRTE_IXGBE_PMD 12436 ret = is_tx ? 12437 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 12438 res->idx, res->an, res->pn, key) : 12439 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 12440 res->idx, res->an, res->pn, key); 12441 #endif 12442 RTE_SET_USED(is_tx); 12443 RTE_SET_USED(key); 12444 12445 switch (ret) { 12446 case 0: 12447 break; 12448 case -EINVAL: 12449 printf("invalid idx %d or an %d\n", res->idx, res->an); 12450 break; 12451 case -ENODEV: 12452 printf("invalid port_id %d\n", res->port_id); 12453 break; 12454 case -ENOTSUP: 12455 printf("not supported on port %d\n", res->port_id); 12456 break; 12457 default: 12458 printf("programming error: (%s)\n", strerror(-ret)); 12459 } 12460 } 12461 12462 cmdline_parse_inst_t cmd_set_macsec_sa = { 12463 .f = cmd_set_macsec_sa_parsed, 12464 .data = NULL, 12465 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 12466 .tokens = { 12467 (void *)&cmd_macsec_sa_set, 12468 (void *)&cmd_macsec_sa_macsec, 12469 (void *)&cmd_macsec_sa_sa, 12470 (void *)&cmd_macsec_sa_tx_rx, 12471 (void *)&cmd_macsec_sa_port_id, 12472 (void *)&cmd_macsec_sa_idx, 12473 (void *)&cmd_macsec_sa_an, 12474 (void *)&cmd_macsec_sa_pn, 12475 (void *)&cmd_macsec_sa_key, 12476 NULL, 12477 }, 12478 }; 12479 12480 /* VF unicast promiscuous mode configuration */ 12481 12482 /* Common result structure for VF unicast promiscuous mode */ 12483 struct cmd_vf_promisc_result { 12484 cmdline_fixed_string_t set; 12485 cmdline_fixed_string_t vf; 12486 cmdline_fixed_string_t promisc; 12487 uint8_t port_id; 12488 uint32_t vf_id; 12489 cmdline_fixed_string_t on_off; 12490 }; 12491 12492 /* Common CLI fields for VF unicast promiscuous mode enable disable */ 12493 cmdline_parse_token_string_t cmd_vf_promisc_set = 12494 TOKEN_STRING_INITIALIZER 12495 (struct cmd_vf_promisc_result, 12496 set, "set"); 12497 cmdline_parse_token_string_t cmd_vf_promisc_vf = 12498 TOKEN_STRING_INITIALIZER 12499 (struct cmd_vf_promisc_result, 12500 vf, "vf"); 12501 cmdline_parse_token_string_t cmd_vf_promisc_promisc = 12502 TOKEN_STRING_INITIALIZER 12503 (struct cmd_vf_promisc_result, 12504 promisc, "promisc"); 12505 cmdline_parse_token_num_t cmd_vf_promisc_port_id = 12506 TOKEN_NUM_INITIALIZER 12507 (struct cmd_vf_promisc_result, 12508 port_id, UINT8); 12509 cmdline_parse_token_num_t cmd_vf_promisc_vf_id = 12510 TOKEN_NUM_INITIALIZER 12511 (struct cmd_vf_promisc_result, 12512 vf_id, UINT32); 12513 cmdline_parse_token_string_t cmd_vf_promisc_on_off = 12514 TOKEN_STRING_INITIALIZER 12515 (struct cmd_vf_promisc_result, 12516 on_off, "on#off"); 12517 12518 static void 12519 cmd_set_vf_promisc_parsed( 12520 void *parsed_result, 12521 __attribute__((unused)) struct cmdline *cl, 12522 __attribute__((unused)) void *data) 12523 { 12524 struct cmd_vf_promisc_result *res = parsed_result; 12525 int ret = -ENOTSUP; 12526 12527 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12528 12529 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12530 return; 12531 12532 #ifdef RTE_LIBRTE_I40E_PMD 12533 ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id, 12534 res->vf_id, is_on); 12535 #endif 12536 12537 switch (ret) { 12538 case 0: 12539 break; 12540 case -EINVAL: 12541 printf("invalid vf_id %d\n", res->vf_id); 12542 break; 12543 case -ENODEV: 12544 printf("invalid port_id %d\n", res->port_id); 12545 break; 12546 case -ENOTSUP: 12547 printf("function not implemented\n"); 12548 break; 12549 default: 12550 printf("programming error: (%s)\n", strerror(-ret)); 12551 } 12552 } 12553 12554 cmdline_parse_inst_t cmd_set_vf_promisc = { 12555 .f = cmd_set_vf_promisc_parsed, 12556 .data = NULL, 12557 .help_str = "set vf promisc <port_id> <vf_id> on|off: " 12558 "Set unicast promiscuous mode for a VF from the PF", 12559 .tokens = { 12560 (void *)&cmd_vf_promisc_set, 12561 (void *)&cmd_vf_promisc_vf, 12562 (void *)&cmd_vf_promisc_promisc, 12563 (void *)&cmd_vf_promisc_port_id, 12564 (void *)&cmd_vf_promisc_vf_id, 12565 (void *)&cmd_vf_promisc_on_off, 12566 NULL, 12567 }, 12568 }; 12569 12570 /* VF multicast promiscuous mode configuration */ 12571 12572 /* Common result structure for VF multicast promiscuous mode */ 12573 struct cmd_vf_allmulti_result { 12574 cmdline_fixed_string_t set; 12575 cmdline_fixed_string_t vf; 12576 cmdline_fixed_string_t allmulti; 12577 uint8_t port_id; 12578 uint32_t vf_id; 12579 cmdline_fixed_string_t on_off; 12580 }; 12581 12582 /* Common CLI fields for VF multicast promiscuous mode enable disable */ 12583 cmdline_parse_token_string_t cmd_vf_allmulti_set = 12584 TOKEN_STRING_INITIALIZER 12585 (struct cmd_vf_allmulti_result, 12586 set, "set"); 12587 cmdline_parse_token_string_t cmd_vf_allmulti_vf = 12588 TOKEN_STRING_INITIALIZER 12589 (struct cmd_vf_allmulti_result, 12590 vf, "vf"); 12591 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = 12592 TOKEN_STRING_INITIALIZER 12593 (struct cmd_vf_allmulti_result, 12594 allmulti, "allmulti"); 12595 cmdline_parse_token_num_t cmd_vf_allmulti_port_id = 12596 TOKEN_NUM_INITIALIZER 12597 (struct cmd_vf_allmulti_result, 12598 port_id, UINT8); 12599 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = 12600 TOKEN_NUM_INITIALIZER 12601 (struct cmd_vf_allmulti_result, 12602 vf_id, UINT32); 12603 cmdline_parse_token_string_t cmd_vf_allmulti_on_off = 12604 TOKEN_STRING_INITIALIZER 12605 (struct cmd_vf_allmulti_result, 12606 on_off, "on#off"); 12607 12608 static void 12609 cmd_set_vf_allmulti_parsed( 12610 void *parsed_result, 12611 __attribute__((unused)) struct cmdline *cl, 12612 __attribute__((unused)) void *data) 12613 { 12614 struct cmd_vf_allmulti_result *res = parsed_result; 12615 int ret = -ENOTSUP; 12616 12617 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12618 12619 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12620 return; 12621 12622 #ifdef RTE_LIBRTE_I40E_PMD 12623 ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id, 12624 res->vf_id, is_on); 12625 #endif 12626 12627 switch (ret) { 12628 case 0: 12629 break; 12630 case -EINVAL: 12631 printf("invalid vf_id %d\n", res->vf_id); 12632 break; 12633 case -ENODEV: 12634 printf("invalid port_id %d\n", res->port_id); 12635 break; 12636 case -ENOTSUP: 12637 printf("function not implemented\n"); 12638 break; 12639 default: 12640 printf("programming error: (%s)\n", strerror(-ret)); 12641 } 12642 } 12643 12644 cmdline_parse_inst_t cmd_set_vf_allmulti = { 12645 .f = cmd_set_vf_allmulti_parsed, 12646 .data = NULL, 12647 .help_str = "set vf allmulti <port_id> <vf_id> on|off: " 12648 "Set multicast promiscuous mode for a VF from the PF", 12649 .tokens = { 12650 (void *)&cmd_vf_allmulti_set, 12651 (void *)&cmd_vf_allmulti_vf, 12652 (void *)&cmd_vf_allmulti_allmulti, 12653 (void *)&cmd_vf_allmulti_port_id, 12654 (void *)&cmd_vf_allmulti_vf_id, 12655 (void *)&cmd_vf_allmulti_on_off, 12656 NULL, 12657 }, 12658 }; 12659 12660 /* vf broadcast mode configuration */ 12661 12662 /* Common result structure for vf broadcast */ 12663 struct cmd_set_vf_broadcast_result { 12664 cmdline_fixed_string_t set; 12665 cmdline_fixed_string_t vf; 12666 cmdline_fixed_string_t broadcast; 12667 uint8_t port_id; 12668 uint16_t vf_id; 12669 cmdline_fixed_string_t on_off; 12670 }; 12671 12672 /* Common CLI fields for vf broadcast enable disable */ 12673 cmdline_parse_token_string_t cmd_set_vf_broadcast_set = 12674 TOKEN_STRING_INITIALIZER 12675 (struct cmd_set_vf_broadcast_result, 12676 set, "set"); 12677 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf = 12678 TOKEN_STRING_INITIALIZER 12679 (struct cmd_set_vf_broadcast_result, 12680 vf, "vf"); 12681 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = 12682 TOKEN_STRING_INITIALIZER 12683 (struct cmd_set_vf_broadcast_result, 12684 broadcast, "broadcast"); 12685 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = 12686 TOKEN_NUM_INITIALIZER 12687 (struct cmd_set_vf_broadcast_result, 12688 port_id, UINT8); 12689 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = 12690 TOKEN_NUM_INITIALIZER 12691 (struct cmd_set_vf_broadcast_result, 12692 vf_id, UINT16); 12693 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off = 12694 TOKEN_STRING_INITIALIZER 12695 (struct cmd_set_vf_broadcast_result, 12696 on_off, "on#off"); 12697 12698 static void 12699 cmd_set_vf_broadcast_parsed( 12700 void *parsed_result, 12701 __attribute__((unused)) struct cmdline *cl, 12702 __attribute__((unused)) void *data) 12703 { 12704 struct cmd_set_vf_broadcast_result *res = parsed_result; 12705 int ret = -ENOTSUP; 12706 12707 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12708 12709 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12710 return; 12711 12712 #ifdef RTE_LIBRTE_I40E_PMD 12713 ret = rte_pmd_i40e_set_vf_broadcast(res->port_id, 12714 res->vf_id, is_on); 12715 #endif 12716 12717 switch (ret) { 12718 case 0: 12719 break; 12720 case -EINVAL: 12721 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12722 break; 12723 case -ENODEV: 12724 printf("invalid port_id %d\n", res->port_id); 12725 break; 12726 case -ENOTSUP: 12727 printf("function not implemented\n"); 12728 break; 12729 default: 12730 printf("programming error: (%s)\n", strerror(-ret)); 12731 } 12732 } 12733 12734 cmdline_parse_inst_t cmd_set_vf_broadcast = { 12735 .f = cmd_set_vf_broadcast_parsed, 12736 .data = NULL, 12737 .help_str = "set vf broadcast <port_id> <vf_id> on|off", 12738 .tokens = { 12739 (void *)&cmd_set_vf_broadcast_set, 12740 (void *)&cmd_set_vf_broadcast_vf, 12741 (void *)&cmd_set_vf_broadcast_broadcast, 12742 (void *)&cmd_set_vf_broadcast_port_id, 12743 (void *)&cmd_set_vf_broadcast_vf_id, 12744 (void *)&cmd_set_vf_broadcast_on_off, 12745 NULL, 12746 }, 12747 }; 12748 12749 /* vf vlan tag configuration */ 12750 12751 /* Common result structure for vf vlan tag */ 12752 struct cmd_set_vf_vlan_tag_result { 12753 cmdline_fixed_string_t set; 12754 cmdline_fixed_string_t vf; 12755 cmdline_fixed_string_t vlan; 12756 cmdline_fixed_string_t tag; 12757 uint8_t port_id; 12758 uint16_t vf_id; 12759 cmdline_fixed_string_t on_off; 12760 }; 12761 12762 /* Common CLI fields for vf vlan tag enable disable */ 12763 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set = 12764 TOKEN_STRING_INITIALIZER 12765 (struct cmd_set_vf_vlan_tag_result, 12766 set, "set"); 12767 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf = 12768 TOKEN_STRING_INITIALIZER 12769 (struct cmd_set_vf_vlan_tag_result, 12770 vf, "vf"); 12771 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan = 12772 TOKEN_STRING_INITIALIZER 12773 (struct cmd_set_vf_vlan_tag_result, 12774 vlan, "vlan"); 12775 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = 12776 TOKEN_STRING_INITIALIZER 12777 (struct cmd_set_vf_vlan_tag_result, 12778 tag, "tag"); 12779 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = 12780 TOKEN_NUM_INITIALIZER 12781 (struct cmd_set_vf_vlan_tag_result, 12782 port_id, UINT8); 12783 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = 12784 TOKEN_NUM_INITIALIZER 12785 (struct cmd_set_vf_vlan_tag_result, 12786 vf_id, UINT16); 12787 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off = 12788 TOKEN_STRING_INITIALIZER 12789 (struct cmd_set_vf_vlan_tag_result, 12790 on_off, "on#off"); 12791 12792 static void 12793 cmd_set_vf_vlan_tag_parsed( 12794 void *parsed_result, 12795 __attribute__((unused)) struct cmdline *cl, 12796 __attribute__((unused)) void *data) 12797 { 12798 struct cmd_set_vf_vlan_tag_result *res = parsed_result; 12799 int ret = -ENOTSUP; 12800 12801 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12802 12803 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12804 return; 12805 12806 #ifdef RTE_LIBRTE_I40E_PMD 12807 ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id, 12808 res->vf_id, is_on); 12809 #endif 12810 12811 switch (ret) { 12812 case 0: 12813 break; 12814 case -EINVAL: 12815 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12816 break; 12817 case -ENODEV: 12818 printf("invalid port_id %d\n", res->port_id); 12819 break; 12820 case -ENOTSUP: 12821 printf("function not implemented\n"); 12822 break; 12823 default: 12824 printf("programming error: (%s)\n", strerror(-ret)); 12825 } 12826 } 12827 12828 cmdline_parse_inst_t cmd_set_vf_vlan_tag = { 12829 .f = cmd_set_vf_vlan_tag_parsed, 12830 .data = NULL, 12831 .help_str = "set vf vlan tag <port_id> <vf_id> on|off", 12832 .tokens = { 12833 (void *)&cmd_set_vf_vlan_tag_set, 12834 (void *)&cmd_set_vf_vlan_tag_vf, 12835 (void *)&cmd_set_vf_vlan_tag_vlan, 12836 (void *)&cmd_set_vf_vlan_tag_tag, 12837 (void *)&cmd_set_vf_vlan_tag_port_id, 12838 (void *)&cmd_set_vf_vlan_tag_vf_id, 12839 (void *)&cmd_set_vf_vlan_tag_on_off, 12840 NULL, 12841 }, 12842 }; 12843 12844 /* Common definition of VF and TC TX bandwidth configuration */ 12845 struct cmd_vf_tc_bw_result { 12846 cmdline_fixed_string_t set; 12847 cmdline_fixed_string_t vf; 12848 cmdline_fixed_string_t tc; 12849 cmdline_fixed_string_t tx; 12850 cmdline_fixed_string_t min_bw; 12851 cmdline_fixed_string_t max_bw; 12852 cmdline_fixed_string_t strict_link_prio; 12853 uint8_t port_id; 12854 uint16_t vf_id; 12855 uint8_t tc_no; 12856 uint32_t bw; 12857 cmdline_fixed_string_t bw_list; 12858 uint8_t tc_map; 12859 }; 12860 12861 cmdline_parse_token_string_t cmd_vf_tc_bw_set = 12862 TOKEN_STRING_INITIALIZER 12863 (struct cmd_vf_tc_bw_result, 12864 set, "set"); 12865 cmdline_parse_token_string_t cmd_vf_tc_bw_vf = 12866 TOKEN_STRING_INITIALIZER 12867 (struct cmd_vf_tc_bw_result, 12868 vf, "vf"); 12869 cmdline_parse_token_string_t cmd_vf_tc_bw_tc = 12870 TOKEN_STRING_INITIALIZER 12871 (struct cmd_vf_tc_bw_result, 12872 tc, "tc"); 12873 cmdline_parse_token_string_t cmd_vf_tc_bw_tx = 12874 TOKEN_STRING_INITIALIZER 12875 (struct cmd_vf_tc_bw_result, 12876 tx, "tx"); 12877 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio = 12878 TOKEN_STRING_INITIALIZER 12879 (struct cmd_vf_tc_bw_result, 12880 strict_link_prio, "strict-link-priority"); 12881 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = 12882 TOKEN_STRING_INITIALIZER 12883 (struct cmd_vf_tc_bw_result, 12884 min_bw, "min-bandwidth"); 12885 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw = 12886 TOKEN_STRING_INITIALIZER 12887 (struct cmd_vf_tc_bw_result, 12888 max_bw, "max-bandwidth"); 12889 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = 12890 TOKEN_NUM_INITIALIZER 12891 (struct cmd_vf_tc_bw_result, 12892 port_id, UINT8); 12893 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id = 12894 TOKEN_NUM_INITIALIZER 12895 (struct cmd_vf_tc_bw_result, 12896 vf_id, UINT16); 12897 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no = 12898 TOKEN_NUM_INITIALIZER 12899 (struct cmd_vf_tc_bw_result, 12900 tc_no, UINT8); 12901 cmdline_parse_token_num_t cmd_vf_tc_bw_bw = 12902 TOKEN_NUM_INITIALIZER 12903 (struct cmd_vf_tc_bw_result, 12904 bw, UINT32); 12905 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = 12906 TOKEN_STRING_INITIALIZER 12907 (struct cmd_vf_tc_bw_result, 12908 bw_list, NULL); 12909 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map = 12910 TOKEN_NUM_INITIALIZER 12911 (struct cmd_vf_tc_bw_result, 12912 tc_map, UINT8); 12913 12914 /* VF max bandwidth setting */ 12915 static void 12916 cmd_vf_max_bw_parsed( 12917 void *parsed_result, 12918 __attribute__((unused)) struct cmdline *cl, 12919 __attribute__((unused)) void *data) 12920 { 12921 struct cmd_vf_tc_bw_result *res = parsed_result; 12922 int ret = -ENOTSUP; 12923 12924 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12925 return; 12926 12927 #ifdef RTE_LIBRTE_I40E_PMD 12928 ret = rte_pmd_i40e_set_vf_max_bw(res->port_id, 12929 res->vf_id, res->bw); 12930 #endif 12931 12932 switch (ret) { 12933 case 0: 12934 break; 12935 case -EINVAL: 12936 printf("invalid vf_id %d or bandwidth %d\n", 12937 res->vf_id, res->bw); 12938 break; 12939 case -ENODEV: 12940 printf("invalid port_id %d\n", res->port_id); 12941 break; 12942 case -ENOTSUP: 12943 printf("function not implemented\n"); 12944 break; 12945 default: 12946 printf("programming error: (%s)\n", strerror(-ret)); 12947 } 12948 } 12949 12950 cmdline_parse_inst_t cmd_vf_max_bw = { 12951 .f = cmd_vf_max_bw_parsed, 12952 .data = NULL, 12953 .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>", 12954 .tokens = { 12955 (void *)&cmd_vf_tc_bw_set, 12956 (void *)&cmd_vf_tc_bw_vf, 12957 (void *)&cmd_vf_tc_bw_tx, 12958 (void *)&cmd_vf_tc_bw_max_bw, 12959 (void *)&cmd_vf_tc_bw_port_id, 12960 (void *)&cmd_vf_tc_bw_vf_id, 12961 (void *)&cmd_vf_tc_bw_bw, 12962 NULL, 12963 }, 12964 }; 12965 12966 static int 12967 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, 12968 uint8_t *tc_num, 12969 char *str) 12970 { 12971 uint32_t size; 12972 const char *p, *p0 = str; 12973 char s[256]; 12974 char *end; 12975 char *str_fld[16]; 12976 uint16_t i; 12977 int ret; 12978 12979 p = strchr(p0, '('); 12980 if (p == NULL) { 12981 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 12982 return -1; 12983 } 12984 p++; 12985 p0 = strchr(p, ')'); 12986 if (p0 == NULL) { 12987 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 12988 return -1; 12989 } 12990 size = p0 - p; 12991 if (size >= sizeof(s)) { 12992 printf("The string size exceeds the internal buffer size\n"); 12993 return -1; 12994 } 12995 snprintf(s, sizeof(s), "%.*s", size, p); 12996 ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); 12997 if (ret <= 0) { 12998 printf("Failed to get the bandwidth list. "); 12999 return -1; 13000 } 13001 *tc_num = ret; 13002 for (i = 0; i < ret; i++) 13003 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); 13004 13005 return 0; 13006 } 13007 13008 /* TC min bandwidth setting */ 13009 static void 13010 cmd_vf_tc_min_bw_parsed( 13011 void *parsed_result, 13012 __attribute__((unused)) struct cmdline *cl, 13013 __attribute__((unused)) void *data) 13014 { 13015 struct cmd_vf_tc_bw_result *res = parsed_result; 13016 uint8_t tc_num; 13017 uint8_t bw[16]; 13018 int ret = -ENOTSUP; 13019 13020 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13021 return; 13022 13023 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 13024 if (ret) 13025 return; 13026 13027 #ifdef RTE_LIBRTE_I40E_PMD 13028 ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id, 13029 tc_num, bw); 13030 #endif 13031 13032 switch (ret) { 13033 case 0: 13034 break; 13035 case -EINVAL: 13036 printf("invalid vf_id %d or bandwidth\n", res->vf_id); 13037 break; 13038 case -ENODEV: 13039 printf("invalid port_id %d\n", res->port_id); 13040 break; 13041 case -ENOTSUP: 13042 printf("function not implemented\n"); 13043 break; 13044 default: 13045 printf("programming error: (%s)\n", strerror(-ret)); 13046 } 13047 } 13048 13049 cmdline_parse_inst_t cmd_vf_tc_min_bw = { 13050 .f = cmd_vf_tc_min_bw_parsed, 13051 .data = NULL, 13052 .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>" 13053 " <bw1, bw2, ...>", 13054 .tokens = { 13055 (void *)&cmd_vf_tc_bw_set, 13056 (void *)&cmd_vf_tc_bw_vf, 13057 (void *)&cmd_vf_tc_bw_tc, 13058 (void *)&cmd_vf_tc_bw_tx, 13059 (void *)&cmd_vf_tc_bw_min_bw, 13060 (void *)&cmd_vf_tc_bw_port_id, 13061 (void *)&cmd_vf_tc_bw_vf_id, 13062 (void *)&cmd_vf_tc_bw_bw_list, 13063 NULL, 13064 }, 13065 }; 13066 13067 static void 13068 cmd_tc_min_bw_parsed( 13069 void *parsed_result, 13070 __attribute__((unused)) struct cmdline *cl, 13071 __attribute__((unused)) void *data) 13072 { 13073 struct cmd_vf_tc_bw_result *res = parsed_result; 13074 struct rte_port *port; 13075 uint8_t tc_num; 13076 uint8_t bw[16]; 13077 int ret = -ENOTSUP; 13078 13079 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13080 return; 13081 13082 port = &ports[res->port_id]; 13083 /** Check if the port is not started **/ 13084 if (port->port_status != RTE_PORT_STOPPED) { 13085 printf("Please stop port %d first\n", res->port_id); 13086 return; 13087 } 13088 13089 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 13090 if (ret) 13091 return; 13092 13093 #ifdef RTE_LIBRTE_IXGBE_PMD 13094 ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); 13095 #endif 13096 13097 switch (ret) { 13098 case 0: 13099 break; 13100 case -EINVAL: 13101 printf("invalid bandwidth\n"); 13102 break; 13103 case -ENODEV: 13104 printf("invalid port_id %d\n", res->port_id); 13105 break; 13106 case -ENOTSUP: 13107 printf("function not implemented\n"); 13108 break; 13109 default: 13110 printf("programming error: (%s)\n", strerror(-ret)); 13111 } 13112 } 13113 13114 cmdline_parse_inst_t cmd_tc_min_bw = { 13115 .f = cmd_tc_min_bw_parsed, 13116 .data = NULL, 13117 .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>", 13118 .tokens = { 13119 (void *)&cmd_vf_tc_bw_set, 13120 (void *)&cmd_vf_tc_bw_tc, 13121 (void *)&cmd_vf_tc_bw_tx, 13122 (void *)&cmd_vf_tc_bw_min_bw, 13123 (void *)&cmd_vf_tc_bw_port_id, 13124 (void *)&cmd_vf_tc_bw_bw_list, 13125 NULL, 13126 }, 13127 }; 13128 13129 /* TC max bandwidth setting */ 13130 static void 13131 cmd_vf_tc_max_bw_parsed( 13132 void *parsed_result, 13133 __attribute__((unused)) struct cmdline *cl, 13134 __attribute__((unused)) void *data) 13135 { 13136 struct cmd_vf_tc_bw_result *res = parsed_result; 13137 int ret = -ENOTSUP; 13138 13139 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13140 return; 13141 13142 #ifdef RTE_LIBRTE_I40E_PMD 13143 ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id, 13144 res->tc_no, res->bw); 13145 #endif 13146 13147 switch (ret) { 13148 case 0: 13149 break; 13150 case -EINVAL: 13151 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n", 13152 res->vf_id, res->tc_no, res->bw); 13153 break; 13154 case -ENODEV: 13155 printf("invalid port_id %d\n", res->port_id); 13156 break; 13157 case -ENOTSUP: 13158 printf("function not implemented\n"); 13159 break; 13160 default: 13161 printf("programming error: (%s)\n", strerror(-ret)); 13162 } 13163 } 13164 13165 cmdline_parse_inst_t cmd_vf_tc_max_bw = { 13166 .f = cmd_vf_tc_max_bw_parsed, 13167 .data = NULL, 13168 .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>" 13169 " <bandwidth>", 13170 .tokens = { 13171 (void *)&cmd_vf_tc_bw_set, 13172 (void *)&cmd_vf_tc_bw_vf, 13173 (void *)&cmd_vf_tc_bw_tc, 13174 (void *)&cmd_vf_tc_bw_tx, 13175 (void *)&cmd_vf_tc_bw_max_bw, 13176 (void *)&cmd_vf_tc_bw_port_id, 13177 (void *)&cmd_vf_tc_bw_vf_id, 13178 (void *)&cmd_vf_tc_bw_tc_no, 13179 (void *)&cmd_vf_tc_bw_bw, 13180 NULL, 13181 }, 13182 }; 13183 13184 /* Strict link priority scheduling mode setting */ 13185 static void 13186 cmd_strict_link_prio_parsed( 13187 void *parsed_result, 13188 __attribute__((unused)) struct cmdline *cl, 13189 __attribute__((unused)) void *data) 13190 { 13191 struct cmd_vf_tc_bw_result *res = parsed_result; 13192 int ret = -ENOTSUP; 13193 13194 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13195 return; 13196 13197 #ifdef RTE_LIBRTE_I40E_PMD 13198 ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map); 13199 #endif 13200 13201 switch (ret) { 13202 case 0: 13203 break; 13204 case -EINVAL: 13205 printf("invalid tc_bitmap 0x%x\n", res->tc_map); 13206 break; 13207 case -ENODEV: 13208 printf("invalid port_id %d\n", res->port_id); 13209 break; 13210 case -ENOTSUP: 13211 printf("function not implemented\n"); 13212 break; 13213 default: 13214 printf("programming error: (%s)\n", strerror(-ret)); 13215 } 13216 } 13217 13218 cmdline_parse_inst_t cmd_strict_link_prio = { 13219 .f = cmd_strict_link_prio_parsed, 13220 .data = NULL, 13221 .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>", 13222 .tokens = { 13223 (void *)&cmd_vf_tc_bw_set, 13224 (void *)&cmd_vf_tc_bw_tx, 13225 (void *)&cmd_vf_tc_bw_strict_link_prio, 13226 (void *)&cmd_vf_tc_bw_port_id, 13227 (void *)&cmd_vf_tc_bw_tc_map, 13228 NULL, 13229 }, 13230 }; 13231 13232 /* Load dynamic device personalization*/ 13233 struct cmd_ddp_add_result { 13234 cmdline_fixed_string_t ddp; 13235 cmdline_fixed_string_t add; 13236 uint8_t port_id; 13237 char filepath[]; 13238 }; 13239 13240 cmdline_parse_token_string_t cmd_ddp_add_ddp = 13241 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp"); 13242 cmdline_parse_token_string_t cmd_ddp_add_add = 13243 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add"); 13244 cmdline_parse_token_num_t cmd_ddp_add_port_id = 13245 TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8); 13246 cmdline_parse_token_string_t cmd_ddp_add_filepath = 13247 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL); 13248 13249 static void 13250 cmd_ddp_add_parsed( 13251 void *parsed_result, 13252 __attribute__((unused)) struct cmdline *cl, 13253 __attribute__((unused)) void *data) 13254 { 13255 struct cmd_ddp_add_result *res = parsed_result; 13256 uint8_t *buff; 13257 uint32_t size; 13258 char *filepath; 13259 char *file_fld[2]; 13260 int file_num; 13261 int ret = -ENOTSUP; 13262 13263 if (res->port_id > nb_ports) { 13264 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 13265 return; 13266 } 13267 13268 if (!all_ports_stopped()) { 13269 printf("Please stop all ports first\n"); 13270 return; 13271 } 13272 13273 filepath = strdup(res->filepath); 13274 if (filepath == NULL) { 13275 printf("Failed to allocate memory\n"); 13276 return; 13277 } 13278 file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ','); 13279 13280 buff = open_ddp_package_file(file_fld[0], &size); 13281 if (!buff) { 13282 free((void *)filepath); 13283 return; 13284 } 13285 13286 #ifdef RTE_LIBRTE_I40E_PMD 13287 if (ret == -ENOTSUP) 13288 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 13289 buff, size, 13290 RTE_PMD_I40E_PKG_OP_WR_ADD); 13291 #endif 13292 13293 if (ret == -EEXIST) 13294 printf("Profile has already existed.\n"); 13295 else if (ret < 0) 13296 printf("Failed to load profile.\n"); 13297 else if (file_num == 2) 13298 save_ddp_package_file(file_fld[1], buff, size); 13299 13300 close_ddp_package_file(buff); 13301 free((void *)filepath); 13302 } 13303 13304 cmdline_parse_inst_t cmd_ddp_add = { 13305 .f = cmd_ddp_add_parsed, 13306 .data = NULL, 13307 .help_str = "ddp add <port_id> <profile_path[,output_path]>", 13308 .tokens = { 13309 (void *)&cmd_ddp_add_ddp, 13310 (void *)&cmd_ddp_add_add, 13311 (void *)&cmd_ddp_add_port_id, 13312 (void *)&cmd_ddp_add_filepath, 13313 NULL, 13314 }, 13315 }; 13316 13317 /* Delete dynamic device personalization*/ 13318 struct cmd_ddp_del_result { 13319 cmdline_fixed_string_t ddp; 13320 cmdline_fixed_string_t del; 13321 uint8_t port_id; 13322 char filepath[]; 13323 }; 13324 13325 cmdline_parse_token_string_t cmd_ddp_del_ddp = 13326 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp"); 13327 cmdline_parse_token_string_t cmd_ddp_del_del = 13328 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del"); 13329 cmdline_parse_token_num_t cmd_ddp_del_port_id = 13330 TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8); 13331 cmdline_parse_token_string_t cmd_ddp_del_filepath = 13332 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL); 13333 13334 static void 13335 cmd_ddp_del_parsed( 13336 void *parsed_result, 13337 __attribute__((unused)) struct cmdline *cl, 13338 __attribute__((unused)) void *data) 13339 { 13340 struct cmd_ddp_del_result *res = parsed_result; 13341 uint8_t *buff; 13342 uint32_t size; 13343 int ret = -ENOTSUP; 13344 13345 if (res->port_id > nb_ports) { 13346 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 13347 return; 13348 } 13349 13350 if (!all_ports_stopped()) { 13351 printf("Please stop all ports first\n"); 13352 return; 13353 } 13354 13355 buff = open_ddp_package_file(res->filepath, &size); 13356 if (!buff) 13357 return; 13358 13359 #ifdef RTE_LIBRTE_I40E_PMD 13360 if (ret == -ENOTSUP) 13361 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 13362 buff, size, 13363 RTE_PMD_I40E_PKG_OP_WR_DEL); 13364 #endif 13365 13366 if (ret == -EACCES) 13367 printf("Profile does not exist.\n"); 13368 else if (ret < 0) 13369 printf("Failed to delete profile.\n"); 13370 13371 close_ddp_package_file(buff); 13372 } 13373 13374 cmdline_parse_inst_t cmd_ddp_del = { 13375 .f = cmd_ddp_del_parsed, 13376 .data = NULL, 13377 .help_str = "ddp del <port_id> <profile_path>", 13378 .tokens = { 13379 (void *)&cmd_ddp_del_ddp, 13380 (void *)&cmd_ddp_del_del, 13381 (void *)&cmd_ddp_del_port_id, 13382 (void *)&cmd_ddp_del_filepath, 13383 NULL, 13384 }, 13385 }; 13386 13387 /* Get dynamic device personalization profile info */ 13388 struct cmd_ddp_info_result { 13389 cmdline_fixed_string_t ddp; 13390 cmdline_fixed_string_t get; 13391 cmdline_fixed_string_t info; 13392 char filepath[]; 13393 }; 13394 13395 cmdline_parse_token_string_t cmd_ddp_info_ddp = 13396 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp"); 13397 cmdline_parse_token_string_t cmd_ddp_info_get = 13398 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get"); 13399 cmdline_parse_token_string_t cmd_ddp_info_info = 13400 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info"); 13401 cmdline_parse_token_string_t cmd_ddp_info_filepath = 13402 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL); 13403 13404 static void 13405 cmd_ddp_info_parsed( 13406 void *parsed_result, 13407 __attribute__((unused)) struct cmdline *cl, 13408 __attribute__((unused)) void *data) 13409 { 13410 struct cmd_ddp_info_result *res = parsed_result; 13411 uint8_t *pkg; 13412 uint32_t pkg_size; 13413 int ret = -ENOTSUP; 13414 #ifdef RTE_LIBRTE_I40E_PMD 13415 uint32_t i; 13416 uint8_t *buff; 13417 uint32_t buff_size; 13418 struct rte_pmd_i40e_profile_info info; 13419 uint32_t dev_num; 13420 struct rte_pmd_i40e_ddp_device_id *devs; 13421 #endif 13422 13423 pkg = open_ddp_package_file(res->filepath, &pkg_size); 13424 if (!pkg) 13425 return; 13426 13427 #ifdef RTE_LIBRTE_I40E_PMD 13428 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13429 (uint8_t *)&info, sizeof(info), 13430 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER); 13431 if (!ret) { 13432 printf("Global Track id: 0x%x\n", info.track_id); 13433 printf("Global Version: %d.%d.%d.%d\n", 13434 info.version.major, 13435 info.version.minor, 13436 info.version.update, 13437 info.version.draft); 13438 printf("Global Package name: %s\n\n", info.name); 13439 } 13440 13441 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13442 (uint8_t *)&info, sizeof(info), 13443 RTE_PMD_I40E_PKG_INFO_HEADER); 13444 if (!ret) { 13445 printf("i40e Profile Track id: 0x%x\n", info.track_id); 13446 printf("i40e Profile Version: %d.%d.%d.%d\n", 13447 info.version.major, 13448 info.version.minor, 13449 info.version.update, 13450 info.version.draft); 13451 printf("i40e Profile name: %s\n\n", info.name); 13452 } 13453 13454 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13455 (uint8_t *)&buff_size, sizeof(buff_size), 13456 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE); 13457 if (!ret && buff_size) { 13458 buff = (uint8_t *)malloc(buff_size); 13459 if (buff) { 13460 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13461 buff, buff_size, 13462 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES); 13463 if (!ret) 13464 printf("Package Notes:\n%s\n\n", buff); 13465 free(buff); 13466 } 13467 } 13468 13469 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13470 (uint8_t *)&dev_num, sizeof(dev_num), 13471 RTE_PMD_I40E_PKG_INFO_DEVID_NUM); 13472 if (!ret && dev_num) { 13473 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(dev_num * 13474 sizeof(struct rte_pmd_i40e_ddp_device_id)); 13475 if (devs) { 13476 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 13477 (uint8_t *)devs, dev_num * 13478 sizeof(struct rte_pmd_i40e_ddp_device_id), 13479 RTE_PMD_I40E_PKG_INFO_DEVID_LIST); 13480 if (!ret) { 13481 printf("List of supported devices:\n"); 13482 for (i = 0; i < dev_num; i++) { 13483 printf(" %04X:%04X %04X:%04X\n", 13484 devs[i].vendor_dev_id >> 16, 13485 devs[i].vendor_dev_id & 0xFFFF, 13486 devs[i].sub_vendor_dev_id >> 16, 13487 devs[i].sub_vendor_dev_id & 0xFFFF); 13488 } 13489 printf("\n"); 13490 } 13491 free(devs); 13492 } 13493 } 13494 ret = 0; 13495 #endif 13496 if (ret == -ENOTSUP) 13497 printf("Function not supported in PMD driver\n"); 13498 close_ddp_package_file(pkg); 13499 } 13500 13501 cmdline_parse_inst_t cmd_ddp_get_info = { 13502 .f = cmd_ddp_info_parsed, 13503 .data = NULL, 13504 .help_str = "ddp get info <profile_path>", 13505 .tokens = { 13506 (void *)&cmd_ddp_info_ddp, 13507 (void *)&cmd_ddp_info_get, 13508 (void *)&cmd_ddp_info_info, 13509 (void *)&cmd_ddp_info_filepath, 13510 NULL, 13511 }, 13512 }; 13513 13514 /* Get dynamic device personalization profile info list*/ 13515 #define PROFILE_INFO_SIZE 48 13516 #define MAX_PROFILE_NUM 16 13517 13518 struct cmd_ddp_get_list_result { 13519 cmdline_fixed_string_t ddp; 13520 cmdline_fixed_string_t get; 13521 cmdline_fixed_string_t list; 13522 uint8_t port_id; 13523 }; 13524 13525 cmdline_parse_token_string_t cmd_ddp_get_list_ddp = 13526 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp"); 13527 cmdline_parse_token_string_t cmd_ddp_get_list_get = 13528 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get"); 13529 cmdline_parse_token_string_t cmd_ddp_get_list_list = 13530 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list"); 13531 cmdline_parse_token_num_t cmd_ddp_get_list_port_id = 13532 TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8); 13533 13534 static void 13535 cmd_ddp_get_list_parsed( 13536 void *parsed_result, 13537 __attribute__((unused)) struct cmdline *cl, 13538 __attribute__((unused)) void *data) 13539 { 13540 struct cmd_ddp_get_list_result *res = parsed_result; 13541 #ifdef RTE_LIBRTE_I40E_PMD 13542 struct rte_pmd_i40e_profile_list *p_list; 13543 struct rte_pmd_i40e_profile_info *p_info; 13544 uint32_t p_num; 13545 uint32_t size; 13546 uint32_t i; 13547 #endif 13548 int ret = -ENOTSUP; 13549 13550 if (res->port_id > nb_ports) { 13551 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 13552 return; 13553 } 13554 13555 #ifdef RTE_LIBRTE_I40E_PMD 13556 size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4; 13557 p_list = (struct rte_pmd_i40e_profile_list *)malloc(size); 13558 if (!p_list) 13559 printf("%s: Failed to malloc buffer\n", __func__); 13560 13561 if (ret == -ENOTSUP) 13562 ret = rte_pmd_i40e_get_ddp_list(res->port_id, 13563 (uint8_t *)p_list, size); 13564 13565 if (!ret) { 13566 p_num = p_list->p_count; 13567 printf("Profile number is: %d\n\n", p_num); 13568 13569 for (i = 0; i < p_num; i++) { 13570 p_info = &p_list->p_info[i]; 13571 printf("Profile %d:\n", i); 13572 printf("Track id: 0x%x\n", p_info->track_id); 13573 printf("Version: %d.%d.%d.%d\n", 13574 p_info->version.major, 13575 p_info->version.minor, 13576 p_info->version.update, 13577 p_info->version.draft); 13578 printf("Profile name: %s\n\n", p_info->name); 13579 } 13580 } 13581 13582 free(p_list); 13583 #endif 13584 13585 if (ret < 0) 13586 printf("Failed to get ddp list\n"); 13587 } 13588 13589 cmdline_parse_inst_t cmd_ddp_get_list = { 13590 .f = cmd_ddp_get_list_parsed, 13591 .data = NULL, 13592 .help_str = "ddp get list <port_id>", 13593 .tokens = { 13594 (void *)&cmd_ddp_get_list_ddp, 13595 (void *)&cmd_ddp_get_list_get, 13596 (void *)&cmd_ddp_get_list_list, 13597 (void *)&cmd_ddp_get_list_port_id, 13598 NULL, 13599 }, 13600 }; 13601 13602 /* show vf stats */ 13603 13604 /* Common result structure for show vf stats */ 13605 struct cmd_show_vf_stats_result { 13606 cmdline_fixed_string_t show; 13607 cmdline_fixed_string_t vf; 13608 cmdline_fixed_string_t stats; 13609 uint8_t port_id; 13610 uint16_t vf_id; 13611 }; 13612 13613 /* Common CLI fields show vf stats*/ 13614 cmdline_parse_token_string_t cmd_show_vf_stats_show = 13615 TOKEN_STRING_INITIALIZER 13616 (struct cmd_show_vf_stats_result, 13617 show, "show"); 13618 cmdline_parse_token_string_t cmd_show_vf_stats_vf = 13619 TOKEN_STRING_INITIALIZER 13620 (struct cmd_show_vf_stats_result, 13621 vf, "vf"); 13622 cmdline_parse_token_string_t cmd_show_vf_stats_stats = 13623 TOKEN_STRING_INITIALIZER 13624 (struct cmd_show_vf_stats_result, 13625 stats, "stats"); 13626 cmdline_parse_token_num_t cmd_show_vf_stats_port_id = 13627 TOKEN_NUM_INITIALIZER 13628 (struct cmd_show_vf_stats_result, 13629 port_id, UINT8); 13630 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id = 13631 TOKEN_NUM_INITIALIZER 13632 (struct cmd_show_vf_stats_result, 13633 vf_id, UINT16); 13634 13635 static void 13636 cmd_show_vf_stats_parsed( 13637 void *parsed_result, 13638 __attribute__((unused)) struct cmdline *cl, 13639 __attribute__((unused)) void *data) 13640 { 13641 struct cmd_show_vf_stats_result *res = parsed_result; 13642 struct rte_eth_stats stats; 13643 int ret = -ENOTSUP; 13644 static const char *nic_stats_border = "########################"; 13645 13646 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13647 return; 13648 13649 memset(&stats, 0, sizeof(stats)); 13650 13651 #ifdef RTE_LIBRTE_I40E_PMD 13652 if (ret == -ENOTSUP) 13653 ret = rte_pmd_i40e_get_vf_stats(res->port_id, 13654 res->vf_id, 13655 &stats); 13656 #endif 13657 #ifdef RTE_LIBRTE_BNXT_PMD 13658 if (ret == -ENOTSUP) 13659 ret = rte_pmd_bnxt_get_vf_stats(res->port_id, 13660 res->vf_id, 13661 &stats); 13662 #endif 13663 13664 switch (ret) { 13665 case 0: 13666 break; 13667 case -EINVAL: 13668 printf("invalid vf_id %d\n", res->vf_id); 13669 break; 13670 case -ENODEV: 13671 printf("invalid port_id %d\n", res->port_id); 13672 break; 13673 case -ENOTSUP: 13674 printf("function not implemented\n"); 13675 break; 13676 default: 13677 printf("programming error: (%s)\n", strerror(-ret)); 13678 } 13679 13680 printf("\n %s NIC statistics for port %-2d vf %-2d %s\n", 13681 nic_stats_border, res->port_id, res->vf_id, nic_stats_border); 13682 13683 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 13684 "%-"PRIu64"\n", 13685 stats.ipackets, stats.imissed, stats.ibytes); 13686 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 13687 printf(" RX-nombuf: %-10"PRIu64"\n", 13688 stats.rx_nombuf); 13689 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 13690 "%-"PRIu64"\n", 13691 stats.opackets, stats.oerrors, stats.obytes); 13692 13693 printf(" %s############################%s\n", 13694 nic_stats_border, nic_stats_border); 13695 } 13696 13697 cmdline_parse_inst_t cmd_show_vf_stats = { 13698 .f = cmd_show_vf_stats_parsed, 13699 .data = NULL, 13700 .help_str = "show vf stats <port_id> <vf_id>", 13701 .tokens = { 13702 (void *)&cmd_show_vf_stats_show, 13703 (void *)&cmd_show_vf_stats_vf, 13704 (void *)&cmd_show_vf_stats_stats, 13705 (void *)&cmd_show_vf_stats_port_id, 13706 (void *)&cmd_show_vf_stats_vf_id, 13707 NULL, 13708 }, 13709 }; 13710 13711 /* clear vf stats */ 13712 13713 /* Common result structure for clear vf stats */ 13714 struct cmd_clear_vf_stats_result { 13715 cmdline_fixed_string_t clear; 13716 cmdline_fixed_string_t vf; 13717 cmdline_fixed_string_t stats; 13718 uint8_t port_id; 13719 uint16_t vf_id; 13720 }; 13721 13722 /* Common CLI fields clear vf stats*/ 13723 cmdline_parse_token_string_t cmd_clear_vf_stats_clear = 13724 TOKEN_STRING_INITIALIZER 13725 (struct cmd_clear_vf_stats_result, 13726 clear, "clear"); 13727 cmdline_parse_token_string_t cmd_clear_vf_stats_vf = 13728 TOKEN_STRING_INITIALIZER 13729 (struct cmd_clear_vf_stats_result, 13730 vf, "vf"); 13731 cmdline_parse_token_string_t cmd_clear_vf_stats_stats = 13732 TOKEN_STRING_INITIALIZER 13733 (struct cmd_clear_vf_stats_result, 13734 stats, "stats"); 13735 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id = 13736 TOKEN_NUM_INITIALIZER 13737 (struct cmd_clear_vf_stats_result, 13738 port_id, UINT8); 13739 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id = 13740 TOKEN_NUM_INITIALIZER 13741 (struct cmd_clear_vf_stats_result, 13742 vf_id, UINT16); 13743 13744 static void 13745 cmd_clear_vf_stats_parsed( 13746 void *parsed_result, 13747 __attribute__((unused)) struct cmdline *cl, 13748 __attribute__((unused)) void *data) 13749 { 13750 struct cmd_clear_vf_stats_result *res = parsed_result; 13751 int ret = -ENOTSUP; 13752 13753 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13754 return; 13755 13756 #ifdef RTE_LIBRTE_I40E_PMD 13757 if (ret == -ENOTSUP) 13758 ret = rte_pmd_i40e_reset_vf_stats(res->port_id, 13759 res->vf_id); 13760 #endif 13761 #ifdef RTE_LIBRTE_BNXT_PMD 13762 if (ret == -ENOTSUP) 13763 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id, 13764 res->vf_id); 13765 #endif 13766 13767 switch (ret) { 13768 case 0: 13769 break; 13770 case -EINVAL: 13771 printf("invalid vf_id %d\n", res->vf_id); 13772 break; 13773 case -ENODEV: 13774 printf("invalid port_id %d\n", res->port_id); 13775 break; 13776 case -ENOTSUP: 13777 printf("function not implemented\n"); 13778 break; 13779 default: 13780 printf("programming error: (%s)\n", strerror(-ret)); 13781 } 13782 } 13783 13784 cmdline_parse_inst_t cmd_clear_vf_stats = { 13785 .f = cmd_clear_vf_stats_parsed, 13786 .data = NULL, 13787 .help_str = "clear vf stats <port_id> <vf_id>", 13788 .tokens = { 13789 (void *)&cmd_clear_vf_stats_clear, 13790 (void *)&cmd_clear_vf_stats_vf, 13791 (void *)&cmd_clear_vf_stats_stats, 13792 (void *)&cmd_clear_vf_stats_port_id, 13793 (void *)&cmd_clear_vf_stats_vf_id, 13794 NULL, 13795 }, 13796 }; 13797 13798 /* ptype mapping get */ 13799 13800 /* Common result structure for ptype mapping get */ 13801 struct cmd_ptype_mapping_get_result { 13802 cmdline_fixed_string_t ptype; 13803 cmdline_fixed_string_t mapping; 13804 cmdline_fixed_string_t get; 13805 uint8_t port_id; 13806 uint8_t valid_only; 13807 }; 13808 13809 /* Common CLI fields for ptype mapping get */ 13810 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype = 13811 TOKEN_STRING_INITIALIZER 13812 (struct cmd_ptype_mapping_get_result, 13813 ptype, "ptype"); 13814 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping = 13815 TOKEN_STRING_INITIALIZER 13816 (struct cmd_ptype_mapping_get_result, 13817 mapping, "mapping"); 13818 cmdline_parse_token_string_t cmd_ptype_mapping_get_get = 13819 TOKEN_STRING_INITIALIZER 13820 (struct cmd_ptype_mapping_get_result, 13821 get, "get"); 13822 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id = 13823 TOKEN_NUM_INITIALIZER 13824 (struct cmd_ptype_mapping_get_result, 13825 port_id, UINT8); 13826 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only = 13827 TOKEN_NUM_INITIALIZER 13828 (struct cmd_ptype_mapping_get_result, 13829 valid_only, UINT8); 13830 13831 static void 13832 cmd_ptype_mapping_get_parsed( 13833 void *parsed_result, 13834 __attribute__((unused)) struct cmdline *cl, 13835 __attribute__((unused)) void *data) 13836 { 13837 struct cmd_ptype_mapping_get_result *res = parsed_result; 13838 int ret = -ENOTSUP; 13839 #ifdef RTE_LIBRTE_I40E_PMD 13840 int max_ptype_num = 256; 13841 struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num]; 13842 uint16_t count; 13843 int i; 13844 #endif 13845 13846 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13847 return; 13848 13849 #ifdef RTE_LIBRTE_I40E_PMD 13850 ret = rte_pmd_i40e_ptype_mapping_get(res->port_id, 13851 mapping, 13852 max_ptype_num, 13853 &count, 13854 res->valid_only); 13855 #endif 13856 13857 switch (ret) { 13858 case 0: 13859 break; 13860 case -ENODEV: 13861 printf("invalid port_id %d\n", res->port_id); 13862 break; 13863 case -ENOTSUP: 13864 printf("function not implemented\n"); 13865 break; 13866 default: 13867 printf("programming error: (%s)\n", strerror(-ret)); 13868 } 13869 13870 #ifdef RTE_LIBRTE_I40E_PMD 13871 if (!ret) { 13872 for (i = 0; i < count; i++) 13873 printf("%3d\t0x%08x\n", 13874 mapping[i].hw_ptype, mapping[i].sw_ptype); 13875 } 13876 #endif 13877 } 13878 13879 cmdline_parse_inst_t cmd_ptype_mapping_get = { 13880 .f = cmd_ptype_mapping_get_parsed, 13881 .data = NULL, 13882 .help_str = "ptype mapping get <port_id> <valid_only>", 13883 .tokens = { 13884 (void *)&cmd_ptype_mapping_get_ptype, 13885 (void *)&cmd_ptype_mapping_get_mapping, 13886 (void *)&cmd_ptype_mapping_get_get, 13887 (void *)&cmd_ptype_mapping_get_port_id, 13888 (void *)&cmd_ptype_mapping_get_valid_only, 13889 NULL, 13890 }, 13891 }; 13892 13893 /* ptype mapping replace */ 13894 13895 /* Common result structure for ptype mapping replace */ 13896 struct cmd_ptype_mapping_replace_result { 13897 cmdline_fixed_string_t ptype; 13898 cmdline_fixed_string_t mapping; 13899 cmdline_fixed_string_t replace; 13900 uint8_t port_id; 13901 uint32_t target; 13902 uint8_t mask; 13903 uint32_t pkt_type; 13904 }; 13905 13906 /* Common CLI fields for ptype mapping replace */ 13907 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype = 13908 TOKEN_STRING_INITIALIZER 13909 (struct cmd_ptype_mapping_replace_result, 13910 ptype, "ptype"); 13911 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping = 13912 TOKEN_STRING_INITIALIZER 13913 (struct cmd_ptype_mapping_replace_result, 13914 mapping, "mapping"); 13915 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace = 13916 TOKEN_STRING_INITIALIZER 13917 (struct cmd_ptype_mapping_replace_result, 13918 replace, "replace"); 13919 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id = 13920 TOKEN_NUM_INITIALIZER 13921 (struct cmd_ptype_mapping_replace_result, 13922 port_id, UINT8); 13923 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target = 13924 TOKEN_NUM_INITIALIZER 13925 (struct cmd_ptype_mapping_replace_result, 13926 target, UINT32); 13927 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask = 13928 TOKEN_NUM_INITIALIZER 13929 (struct cmd_ptype_mapping_replace_result, 13930 mask, UINT8); 13931 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type = 13932 TOKEN_NUM_INITIALIZER 13933 (struct cmd_ptype_mapping_replace_result, 13934 pkt_type, UINT32); 13935 13936 static void 13937 cmd_ptype_mapping_replace_parsed( 13938 void *parsed_result, 13939 __attribute__((unused)) struct cmdline *cl, 13940 __attribute__((unused)) void *data) 13941 { 13942 struct cmd_ptype_mapping_replace_result *res = parsed_result; 13943 int ret = -ENOTSUP; 13944 13945 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13946 return; 13947 13948 #ifdef RTE_LIBRTE_I40E_PMD 13949 ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id, 13950 res->target, 13951 res->mask, 13952 res->pkt_type); 13953 #endif 13954 13955 switch (ret) { 13956 case 0: 13957 break; 13958 case -EINVAL: 13959 printf("invalid ptype 0x%8x or 0x%8x\n", 13960 res->target, res->pkt_type); 13961 break; 13962 case -ENODEV: 13963 printf("invalid port_id %d\n", res->port_id); 13964 break; 13965 case -ENOTSUP: 13966 printf("function not implemented\n"); 13967 break; 13968 default: 13969 printf("programming error: (%s)\n", strerror(-ret)); 13970 } 13971 } 13972 13973 cmdline_parse_inst_t cmd_ptype_mapping_replace = { 13974 .f = cmd_ptype_mapping_replace_parsed, 13975 .data = NULL, 13976 .help_str = 13977 "ptype mapping replace <port_id> <target> <mask> <pkt_type>", 13978 .tokens = { 13979 (void *)&cmd_ptype_mapping_replace_ptype, 13980 (void *)&cmd_ptype_mapping_replace_mapping, 13981 (void *)&cmd_ptype_mapping_replace_replace, 13982 (void *)&cmd_ptype_mapping_replace_port_id, 13983 (void *)&cmd_ptype_mapping_replace_target, 13984 (void *)&cmd_ptype_mapping_replace_mask, 13985 (void *)&cmd_ptype_mapping_replace_pkt_type, 13986 NULL, 13987 }, 13988 }; 13989 13990 /* ptype mapping reset */ 13991 13992 /* Common result structure for ptype mapping reset */ 13993 struct cmd_ptype_mapping_reset_result { 13994 cmdline_fixed_string_t ptype; 13995 cmdline_fixed_string_t mapping; 13996 cmdline_fixed_string_t reset; 13997 uint8_t port_id; 13998 }; 13999 14000 /* Common CLI fields for ptype mapping reset*/ 14001 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype = 14002 TOKEN_STRING_INITIALIZER 14003 (struct cmd_ptype_mapping_reset_result, 14004 ptype, "ptype"); 14005 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping = 14006 TOKEN_STRING_INITIALIZER 14007 (struct cmd_ptype_mapping_reset_result, 14008 mapping, "mapping"); 14009 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset = 14010 TOKEN_STRING_INITIALIZER 14011 (struct cmd_ptype_mapping_reset_result, 14012 reset, "reset"); 14013 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id = 14014 TOKEN_NUM_INITIALIZER 14015 (struct cmd_ptype_mapping_reset_result, 14016 port_id, UINT8); 14017 14018 static void 14019 cmd_ptype_mapping_reset_parsed( 14020 void *parsed_result, 14021 __attribute__((unused)) struct cmdline *cl, 14022 __attribute__((unused)) void *data) 14023 { 14024 struct cmd_ptype_mapping_reset_result *res = parsed_result; 14025 int ret = -ENOTSUP; 14026 14027 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14028 return; 14029 14030 #ifdef RTE_LIBRTE_I40E_PMD 14031 ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id); 14032 #endif 14033 14034 switch (ret) { 14035 case 0: 14036 break; 14037 case -ENODEV: 14038 printf("invalid port_id %d\n", res->port_id); 14039 break; 14040 case -ENOTSUP: 14041 printf("function not implemented\n"); 14042 break; 14043 default: 14044 printf("programming error: (%s)\n", strerror(-ret)); 14045 } 14046 } 14047 14048 cmdline_parse_inst_t cmd_ptype_mapping_reset = { 14049 .f = cmd_ptype_mapping_reset_parsed, 14050 .data = NULL, 14051 .help_str = "ptype mapping reset <port_id>", 14052 .tokens = { 14053 (void *)&cmd_ptype_mapping_reset_ptype, 14054 (void *)&cmd_ptype_mapping_reset_mapping, 14055 (void *)&cmd_ptype_mapping_reset_reset, 14056 (void *)&cmd_ptype_mapping_reset_port_id, 14057 NULL, 14058 }, 14059 }; 14060 14061 /* ptype mapping update */ 14062 14063 /* Common result structure for ptype mapping update */ 14064 struct cmd_ptype_mapping_update_result { 14065 cmdline_fixed_string_t ptype; 14066 cmdline_fixed_string_t mapping; 14067 cmdline_fixed_string_t reset; 14068 uint8_t port_id; 14069 uint8_t hw_ptype; 14070 uint32_t sw_ptype; 14071 }; 14072 14073 /* Common CLI fields for ptype mapping update*/ 14074 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype = 14075 TOKEN_STRING_INITIALIZER 14076 (struct cmd_ptype_mapping_update_result, 14077 ptype, "ptype"); 14078 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping = 14079 TOKEN_STRING_INITIALIZER 14080 (struct cmd_ptype_mapping_update_result, 14081 mapping, "mapping"); 14082 cmdline_parse_token_string_t cmd_ptype_mapping_update_update = 14083 TOKEN_STRING_INITIALIZER 14084 (struct cmd_ptype_mapping_update_result, 14085 reset, "update"); 14086 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id = 14087 TOKEN_NUM_INITIALIZER 14088 (struct cmd_ptype_mapping_update_result, 14089 port_id, UINT8); 14090 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype = 14091 TOKEN_NUM_INITIALIZER 14092 (struct cmd_ptype_mapping_update_result, 14093 hw_ptype, UINT8); 14094 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype = 14095 TOKEN_NUM_INITIALIZER 14096 (struct cmd_ptype_mapping_update_result, 14097 sw_ptype, UINT32); 14098 14099 static void 14100 cmd_ptype_mapping_update_parsed( 14101 void *parsed_result, 14102 __attribute__((unused)) struct cmdline *cl, 14103 __attribute__((unused)) void *data) 14104 { 14105 struct cmd_ptype_mapping_update_result *res = parsed_result; 14106 int ret = -ENOTSUP; 14107 #ifdef RTE_LIBRTE_I40E_PMD 14108 struct rte_pmd_i40e_ptype_mapping mapping; 14109 #endif 14110 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14111 return; 14112 14113 #ifdef RTE_LIBRTE_I40E_PMD 14114 mapping.hw_ptype = res->hw_ptype; 14115 mapping.sw_ptype = res->sw_ptype; 14116 ret = rte_pmd_i40e_ptype_mapping_update(res->port_id, 14117 &mapping, 14118 1, 14119 0); 14120 #endif 14121 14122 switch (ret) { 14123 case 0: 14124 break; 14125 case -EINVAL: 14126 printf("invalid ptype 0x%8x\n", res->sw_ptype); 14127 break; 14128 case -ENODEV: 14129 printf("invalid port_id %d\n", res->port_id); 14130 break; 14131 case -ENOTSUP: 14132 printf("function not implemented\n"); 14133 break; 14134 default: 14135 printf("programming error: (%s)\n", strerror(-ret)); 14136 } 14137 } 14138 14139 cmdline_parse_inst_t cmd_ptype_mapping_update = { 14140 .f = cmd_ptype_mapping_update_parsed, 14141 .data = NULL, 14142 .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>", 14143 .tokens = { 14144 (void *)&cmd_ptype_mapping_update_ptype, 14145 (void *)&cmd_ptype_mapping_update_mapping, 14146 (void *)&cmd_ptype_mapping_update_update, 14147 (void *)&cmd_ptype_mapping_update_port_id, 14148 (void *)&cmd_ptype_mapping_update_hw_ptype, 14149 (void *)&cmd_ptype_mapping_update_sw_ptype, 14150 NULL, 14151 }, 14152 }; 14153 14154 /* Common result structure for file commands */ 14155 struct cmd_cmdfile_result { 14156 cmdline_fixed_string_t load; 14157 cmdline_fixed_string_t filename; 14158 }; 14159 14160 /* Common CLI fields for file commands */ 14161 cmdline_parse_token_string_t cmd_load_cmdfile = 14162 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load"); 14163 cmdline_parse_token_string_t cmd_load_cmdfile_filename = 14164 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL); 14165 14166 static void 14167 cmd_load_from_file_parsed( 14168 void *parsed_result, 14169 __attribute__((unused)) struct cmdline *cl, 14170 __attribute__((unused)) void *data) 14171 { 14172 struct cmd_cmdfile_result *res = parsed_result; 14173 14174 cmdline_read_from_file(res->filename); 14175 } 14176 14177 cmdline_parse_inst_t cmd_load_from_file = { 14178 .f = cmd_load_from_file_parsed, 14179 .data = NULL, 14180 .help_str = "load <filename>", 14181 .tokens = { 14182 (void *)&cmd_load_cmdfile, 14183 (void *)&cmd_load_cmdfile_filename, 14184 NULL, 14185 }, 14186 }; 14187 14188 /* ******************************************************************************** */ 14189 14190 /* list of instructions */ 14191 cmdline_parse_ctx_t main_ctx[] = { 14192 (cmdline_parse_inst_t *)&cmd_help_brief, 14193 (cmdline_parse_inst_t *)&cmd_help_long, 14194 (cmdline_parse_inst_t *)&cmd_quit, 14195 (cmdline_parse_inst_t *)&cmd_load_from_file, 14196 (cmdline_parse_inst_t *)&cmd_showport, 14197 (cmdline_parse_inst_t *)&cmd_showqueue, 14198 (cmdline_parse_inst_t *)&cmd_showportall, 14199 (cmdline_parse_inst_t *)&cmd_showcfg, 14200 (cmdline_parse_inst_t *)&cmd_start, 14201 (cmdline_parse_inst_t *)&cmd_start_tx_first, 14202 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 14203 (cmdline_parse_inst_t *)&cmd_set_link_up, 14204 (cmdline_parse_inst_t *)&cmd_set_link_down, 14205 (cmdline_parse_inst_t *)&cmd_reset, 14206 (cmdline_parse_inst_t *)&cmd_set_numbers, 14207 (cmdline_parse_inst_t *)&cmd_set_txpkts, 14208 (cmdline_parse_inst_t *)&cmd_set_txsplit, 14209 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 14210 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 14211 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 14212 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 14213 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 14214 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 14215 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 14216 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 14217 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 14218 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 14219 (cmdline_parse_inst_t *)&cmd_set_link_check, 14220 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 14221 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 14222 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 14223 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 14224 #ifdef RTE_LIBRTE_PMD_BOND 14225 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 14226 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 14227 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 14228 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 14229 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 14230 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 14231 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 14232 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 14233 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 14234 (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues, 14235 (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy, 14236 #endif 14237 (cmdline_parse_inst_t *)&cmd_vlan_offload, 14238 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 14239 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 14240 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 14241 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 14242 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 14243 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 14244 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 14245 (cmdline_parse_inst_t *)&cmd_csum_set, 14246 (cmdline_parse_inst_t *)&cmd_csum_show, 14247 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 14248 (cmdline_parse_inst_t *)&cmd_tso_set, 14249 (cmdline_parse_inst_t *)&cmd_tso_show, 14250 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 14251 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 14252 (cmdline_parse_inst_t *)&cmd_enable_gro, 14253 (cmdline_parse_inst_t *)&cmd_gro_set, 14254 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 14255 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 14256 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 14257 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 14258 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 14259 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 14260 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 14261 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 14262 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 14263 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 14264 (cmdline_parse_inst_t *)&cmd_config_dcb, 14265 (cmdline_parse_inst_t *)&cmd_read_reg, 14266 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 14267 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 14268 (cmdline_parse_inst_t *)&cmd_write_reg, 14269 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 14270 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 14271 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 14272 (cmdline_parse_inst_t *)&cmd_stop, 14273 (cmdline_parse_inst_t *)&cmd_mac_addr, 14274 (cmdline_parse_inst_t *)&cmd_set_qmap, 14275 (cmdline_parse_inst_t *)&cmd_operate_port, 14276 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 14277 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 14278 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 14279 (cmdline_parse_inst_t *)&cmd_config_speed_all, 14280 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 14281 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 14282 (cmdline_parse_inst_t *)&cmd_config_mtu, 14283 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 14284 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 14285 (cmdline_parse_inst_t *)&cmd_config_rss, 14286 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 14287 (cmdline_parse_inst_t *)&cmd_config_txqflags, 14288 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 14289 (cmdline_parse_inst_t *)&cmd_showport_reta, 14290 (cmdline_parse_inst_t *)&cmd_config_burst, 14291 (cmdline_parse_inst_t *)&cmd_config_thresh, 14292 (cmdline_parse_inst_t *)&cmd_config_threshold, 14293 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 14294 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 14295 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 14296 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 14297 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 14298 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 14299 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 14300 (cmdline_parse_inst_t *)&cmd_global_config, 14301 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 14302 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 14303 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 14304 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 14305 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 14306 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 14307 (cmdline_parse_inst_t *)&cmd_dump, 14308 (cmdline_parse_inst_t *)&cmd_dump_one, 14309 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 14310 (cmdline_parse_inst_t *)&cmd_syn_filter, 14311 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 14312 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 14313 (cmdline_parse_inst_t *)&cmd_flex_filter, 14314 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 14315 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 14316 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 14317 (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director, 14318 (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director, 14319 (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director, 14320 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 14321 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 14322 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 14323 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 14324 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 14325 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 14326 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 14327 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 14328 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 14329 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 14330 (cmdline_parse_inst_t *)&cmd_set_hash_input_set, 14331 (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, 14332 (cmdline_parse_inst_t *)&cmd_flow, 14333 (cmdline_parse_inst_t *)&cmd_mcast_addr, 14334 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, 14335 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, 14336 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all, 14337 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific, 14338 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en, 14339 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis, 14340 (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis, 14341 (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis, 14342 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add, 14343 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del, 14344 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 14345 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 14346 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 14347 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 14348 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 14349 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 14350 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 14351 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 14352 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 14353 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 14354 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 14355 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 14356 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 14357 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 14358 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 14359 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 14360 (cmdline_parse_inst_t *)&cmd_set_vf_promisc, 14361 (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, 14362 (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, 14363 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, 14364 (cmdline_parse_inst_t *)&cmd_vf_max_bw, 14365 (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw, 14366 (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, 14367 (cmdline_parse_inst_t *)&cmd_strict_link_prio, 14368 (cmdline_parse_inst_t *)&cmd_tc_min_bw, 14369 (cmdline_parse_inst_t *)&cmd_ddp_add, 14370 (cmdline_parse_inst_t *)&cmd_ddp_del, 14371 (cmdline_parse_inst_t *)&cmd_ddp_get_list, 14372 (cmdline_parse_inst_t *)&cmd_ddp_get_info, 14373 (cmdline_parse_inst_t *)&cmd_show_vf_stats, 14374 (cmdline_parse_inst_t *)&cmd_clear_vf_stats, 14375 (cmdline_parse_inst_t *)&cmd_ptype_mapping_get, 14376 (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace, 14377 (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset, 14378 (cmdline_parse_inst_t *)&cmd_ptype_mapping_update, 14379 NULL, 14380 }; 14381 14382 /* read cmdline commands from file */ 14383 void 14384 cmdline_read_from_file(const char *filename) 14385 { 14386 struct cmdline *cl; 14387 14388 cl = cmdline_file_new(main_ctx, "testpmd> ", filename); 14389 if (cl == NULL) { 14390 printf("Failed to create file based cmdline context: %s\n", 14391 filename); 14392 return; 14393 } 14394 14395 cmdline_interact(cl); 14396 cmdline_quit(cl); 14397 14398 cmdline_free(cl); 14399 14400 printf("Read CLI commands from %s\n", filename); 14401 } 14402 14403 /* prompt function, called from main on MASTER lcore */ 14404 void 14405 prompt(void) 14406 { 14407 /* initialize non-constant commands */ 14408 cmd_set_fwd_mode_init(); 14409 cmd_set_fwd_retry_mode_init(); 14410 14411 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 14412 if (testpmd_cl == NULL) 14413 return; 14414 cmdline_interact(testpmd_cl); 14415 cmdline_stdin_exit(testpmd_cl); 14416 } 14417 14418 void 14419 prompt_exit(void) 14420 { 14421 if (testpmd_cl != NULL) 14422 cmdline_quit(testpmd_cl); 14423 } 14424 14425 static void 14426 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 14427 { 14428 if (id == (portid_t)RTE_PORT_ALL) { 14429 portid_t pid; 14430 14431 RTE_ETH_FOREACH_DEV(pid) { 14432 /* check if need_reconfig has been set to 1 */ 14433 if (ports[pid].need_reconfig == 0) 14434 ports[pid].need_reconfig = dev; 14435 /* check if need_reconfig_queues has been set to 1 */ 14436 if (ports[pid].need_reconfig_queues == 0) 14437 ports[pid].need_reconfig_queues = queue; 14438 } 14439 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 14440 /* check if need_reconfig has been set to 1 */ 14441 if (ports[id].need_reconfig == 0) 14442 ports[id].need_reconfig = dev; 14443 /* check if need_reconfig_queues has been set to 1 */ 14444 if (ports[id].need_reconfig_queues == 0) 14445 ports[id].need_reconfig_queues = queue; 14446 } 14447 } 14448