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 <stdarg.h> 40 #include <string.h> 41 #include <termios.h> 42 #include <unistd.h> 43 #include <inttypes.h> 44 #ifndef __linux__ 45 #ifndef __FreeBSD__ 46 #include <net/socket.h> 47 #else 48 #include <sys/socket.h> 49 #endif 50 #endif 51 #include <netinet/in.h> 52 53 #include <sys/queue.h> 54 55 #include <rte_common.h> 56 #include <rte_byteorder.h> 57 #include <rte_log.h> 58 #include <rte_debug.h> 59 #include <rte_cycles.h> 60 #include <rte_memory.h> 61 #include <rte_memzone.h> 62 #include <rte_malloc.h> 63 #include <rte_launch.h> 64 #include <rte_eal.h> 65 #include <rte_per_lcore.h> 66 #include <rte_lcore.h> 67 #include <rte_atomic.h> 68 #include <rte_branch_prediction.h> 69 #include <rte_ring.h> 70 #include <rte_mempool.h> 71 #include <rte_interrupts.h> 72 #include <rte_pci.h> 73 #include <rte_ether.h> 74 #include <rte_ethdev.h> 75 #include <rte_string_fns.h> 76 #include <rte_devargs.h> 77 #include <rte_eth_ctrl.h> 78 #include <rte_flow.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 #endif 91 #ifdef RTE_LIBRTE_IXGBE_PMD 92 #include <rte_pmd_ixgbe.h> 93 #endif 94 #ifdef RTE_LIBRTE_I40E_PMD 95 #include <rte_pmd_i40e.h> 96 #endif 97 #include "testpmd.h" 98 99 static struct cmdline *testpmd_cl; 100 101 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 102 103 /* *** Help command with introduction. *** */ 104 struct cmd_help_brief_result { 105 cmdline_fixed_string_t help; 106 }; 107 108 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 109 struct cmdline *cl, 110 __attribute__((unused)) void *data) 111 { 112 cmdline_printf( 113 cl, 114 "\n" 115 "Help is available for the following sections:\n\n" 116 " help control : Start and stop forwarding.\n" 117 " help display : Displaying port, stats and config " 118 "information.\n" 119 " help config : Configuration information.\n" 120 " help ports : Configuring ports.\n" 121 " help registers : Reading and setting port registers.\n" 122 " help filters : Filters configuration help.\n" 123 " help all : All of the above sections.\n\n" 124 ); 125 126 } 127 128 cmdline_parse_token_string_t cmd_help_brief_help = 129 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 130 131 cmdline_parse_inst_t cmd_help_brief = { 132 .f = cmd_help_brief_parsed, 133 .data = NULL, 134 .help_str = "help: Show help", 135 .tokens = { 136 (void *)&cmd_help_brief_help, 137 NULL, 138 }, 139 }; 140 141 /* *** Help command with help sections. *** */ 142 struct cmd_help_long_result { 143 cmdline_fixed_string_t help; 144 cmdline_fixed_string_t section; 145 }; 146 147 static void cmd_help_long_parsed(void *parsed_result, 148 struct cmdline *cl, 149 __attribute__((unused)) void *data) 150 { 151 int show_all = 0; 152 struct cmd_help_long_result *res = parsed_result; 153 154 if (!strcmp(res->section, "all")) 155 show_all = 1; 156 157 if (show_all || !strcmp(res->section, "control")) { 158 159 cmdline_printf( 160 cl, 161 "\n" 162 "Control forwarding:\n" 163 "-------------------\n\n" 164 165 "start\n" 166 " Start packet forwarding with current configuration.\n\n" 167 168 "start tx_first\n" 169 " Start packet forwarding with current config" 170 " after sending one burst of packets.\n\n" 171 172 "stop\n" 173 " Stop packet forwarding, and display accumulated" 174 " statistics.\n\n" 175 176 "quit\n" 177 " Quit to prompt.\n\n" 178 ); 179 } 180 181 if (show_all || !strcmp(res->section, "display")) { 182 183 cmdline_printf( 184 cl, 185 "\n" 186 "Display:\n" 187 "--------\n\n" 188 189 "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc) (port_id|all)\n" 190 " Display information for port_id, or all.\n\n" 191 192 "show port X rss reta (size) (mask0,mask1,...)\n" 193 " Display the rss redirection table entry indicated" 194 " by masks on port X. size is used to indicate the" 195 " hardware supported reta size\n\n" 196 197 "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|" 198 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 199 "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n" 200 " Display the RSS hash functions and RSS hash key" 201 " of port X\n\n" 202 203 "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n" 204 " Clear information for port_id, or all.\n\n" 205 206 "show (rxq|txq) info (port_id) (queue_id)\n" 207 " Display information for configured RX/TX queue.\n\n" 208 209 "show config (rxtx|cores|fwd|txpkts)\n" 210 " Display the given configuration.\n\n" 211 212 "read rxd (port_id) (queue_id) (rxd_id)\n" 213 " Display an RX descriptor of a port RX queue.\n\n" 214 215 "read txd (port_id) (queue_id) (txd_id)\n" 216 " Display a TX descriptor of a port TX queue.\n\n" 217 ); 218 } 219 220 if (show_all || !strcmp(res->section, "config")) { 221 cmdline_printf( 222 cl, 223 "\n" 224 "Configuration:\n" 225 "--------------\n" 226 "Configuration changes only become active when" 227 " forwarding is started/restarted.\n\n" 228 229 "set default\n" 230 " Reset forwarding to the default configuration.\n\n" 231 232 "set verbose (level)\n" 233 " Set the debug verbosity level X.\n\n" 234 235 "set nbport (num)\n" 236 " Set number of ports.\n\n" 237 238 "set nbcore (num)\n" 239 " Set number of cores.\n\n" 240 241 "set coremask (mask)\n" 242 " Set the forwarding cores hexadecimal mask.\n\n" 243 244 "set portmask (mask)\n" 245 " Set the forwarding ports hexadecimal mask.\n\n" 246 247 "set burst (num)\n" 248 " Set number of packets per burst.\n\n" 249 250 "set burst tx delay (microseconds) retry (num)\n" 251 " Set the transmit delay time and number of retries," 252 " effective when retry is enabled.\n\n" 253 254 "set txpkts (x[,y]*)\n" 255 " Set the length of each segment of TXONLY" 256 " and optionally CSUM packets.\n\n" 257 258 "set txsplit (off|on|rand)\n" 259 " Set the split policy for the TX packets." 260 " Right now only applicable for CSUM and TXONLY" 261 " modes\n\n" 262 263 "set corelist (x[,y]*)\n" 264 " Set the list of forwarding cores.\n\n" 265 266 "set portlist (x[,y]*)\n" 267 " Set the list of forwarding ports.\n\n" 268 269 "set tx loopback (port_id) (on|off)\n" 270 " Enable or disable tx loopback.\n\n" 271 272 #ifdef RTE_LIBRTE_IXGBE_PMD 273 "set all queues drop (port_id) (on|off)\n" 274 " Set drop enable bit for all queues.\n\n" 275 276 "set vf split drop (port_id) (vf_id) (on|off)\n" 277 " Set split drop enable bit for a VF from the PF.\n\n" 278 #endif 279 280 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 281 " Set MAC antispoof for a VF from the PF.\n\n" 282 283 #ifdef RTE_LIBRTE_IXGBE_PMD 284 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 285 " Enable MACsec offload.\n\n" 286 287 "set macsec offload (port_id) off\n" 288 " Disable MACsec offload.\n\n" 289 290 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 291 " Configure MACsec secure connection (SC).\n\n" 292 293 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 294 " Configure MACsec secure association (SA).\n\n" 295 #endif 296 297 "set vf broadcast (port_id) (vf_id) (on|off)\n" 298 " Set VF broadcast for a VF from the PF.\n\n" 299 300 "vlan set strip (on|off) (port_id)\n" 301 " Set the VLAN strip on a port.\n\n" 302 303 "vlan set stripq (on|off) (port_id,queue_id)\n" 304 " Set the VLAN strip for a queue on a port.\n\n" 305 306 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 307 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 308 309 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 310 " Set VLAN insert for a VF from the PF.\n\n" 311 312 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 313 " Set VLAN antispoof for a VF from the PF.\n\n" 314 315 "set vf vlan tag (port_id) (vf_id) (on|off)\n" 316 " Set VLAN tag for a VF from the PF.\n\n" 317 318 "vlan set filter (on|off) (port_id)\n" 319 " Set the VLAN filter on a port.\n\n" 320 321 "vlan set qinq (on|off) (port_id)\n" 322 " Set the VLAN QinQ (extended queue in queue)" 323 " on a port.\n\n" 324 325 "vlan set (inner|outer) tpid (value) (port_id)\n" 326 " Set the VLAN TPID for Packet Filtering on" 327 " a port\n\n" 328 329 "rx_vlan add (vlan_id|all) (port_id)\n" 330 " Add a vlan_id, or all identifiers, to the set" 331 " of VLAN identifiers filtered by port_id.\n\n" 332 333 "rx_vlan rm (vlan_id|all) (port_id)\n" 334 " Remove a vlan_id, or all identifiers, from the set" 335 " of VLAN identifiers filtered by port_id.\n\n" 336 337 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 338 " Add a vlan_id, to the set of VLAN identifiers" 339 "filtered for VF(s) from port_id.\n\n" 340 341 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 342 " Remove a vlan_id, to the set of VLAN identifiers" 343 "filtered for VF(s) from port_id.\n\n" 344 345 "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) " 346 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 347 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 348 " add a tunnel filter of a port.\n\n" 349 350 "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) " 351 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 352 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 353 " remove a tunnel filter of a port.\n\n" 354 355 "rx_vxlan_port add (udp_port) (port_id)\n" 356 " Add an UDP port for VXLAN packet filter on a port\n\n" 357 358 "rx_vxlan_port rm (udp_port) (port_id)\n" 359 " Remove an UDP port for VXLAN packet filter on a port\n\n" 360 361 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 362 " Set hardware insertion of VLAN IDs (single or double VLAN " 363 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 364 365 "tx_vlan set pvid port_id vlan_id (on|off)\n" 366 " Set port based TX VLAN insertion.\n\n" 367 368 "tx_vlan reset (port_id)\n" 369 " Disable hardware insertion of a VLAN header in" 370 " packets sent on a port.\n\n" 371 372 "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n" 373 " Select hardware or software calculation of the" 374 " checksum when transmitting a packet using the" 375 " csum forward engine.\n" 376 " ip|udp|tcp|sctp always concern the inner layer.\n" 377 " outer-ip concerns the outer IP layer in" 378 " case the packet is recognized as a tunnel packet by" 379 " the forward engine (vxlan, gre and ipip are supported)\n" 380 " Please check the NIC datasheet for HW limits.\n\n" 381 382 "csum parse-tunnel (on|off) (tx_port_id)\n" 383 " If disabled, treat tunnel packets as non-tunneled" 384 " packets (treat inner headers as payload). The port\n" 385 " argument is the port used for TX in csum forward" 386 " engine.\n\n" 387 388 "csum show (port_id)\n" 389 " Display tx checksum offload configuration\n\n" 390 391 "tso set (segsize) (portid)\n" 392 " Enable TCP Segmentation Offload in csum forward" 393 " engine.\n" 394 " Please check the NIC datasheet for HW limits.\n\n" 395 396 "tso show (portid)" 397 " Display the status of TCP Segmentation Offload.\n\n" 398 399 "set fwd (%s)\n" 400 " Set packet forwarding mode.\n\n" 401 402 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 403 " Add a MAC address on port_id.\n\n" 404 405 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 406 " Remove a MAC address from port_id.\n\n" 407 408 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 409 " Add a MAC address for a VF on the port.\n\n" 410 411 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 412 " Set the MAC address for a VF from the PF.\n\n" 413 414 "set port (port_id) uta (mac_address|all) (on|off)\n" 415 " Add/Remove a or all unicast hash filter(s)" 416 "from port X.\n\n" 417 418 "set promisc (port_id|all) (on|off)\n" 419 " Set the promiscuous mode on port_id, or all.\n\n" 420 421 "set allmulti (port_id|all) (on|off)\n" 422 " Set the allmulti mode on port_id, or all.\n\n" 423 424 "set vf promisc (port_id) (vf_id) (on|off)\n" 425 " Set unicast promiscuous mode for a VF from the PF.\n\n" 426 427 "set vf allmulti (port_id) (vf_id) (on|off)\n" 428 " Set multicast promiscuous mode for a VF from the PF.\n\n" 429 430 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 431 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 432 " (on|off) autoneg (on|off) (port_id)\n" 433 "set flow_ctrl rx (on|off) (portid)\n" 434 "set flow_ctrl tx (on|off) (portid)\n" 435 "set flow_ctrl high_water (high_water) (portid)\n" 436 "set flow_ctrl low_water (low_water) (portid)\n" 437 "set flow_ctrl pause_time (pause_time) (portid)\n" 438 "set flow_ctrl send_xon (send_xon) (portid)\n" 439 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 440 "set flow_ctrl autoneg (on|off) (port_id)\n" 441 " Set the link flow control parameter on a port.\n\n" 442 443 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 444 " (low_water) (pause_time) (priority) (port_id)\n" 445 " Set the priority flow control parameter on a" 446 " port.\n\n" 447 448 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 449 " Set statistics mapping (qmapping 0..15) for RX/TX" 450 " queue on port.\n" 451 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 452 " on port 0 to mapping 5.\n\n" 453 454 "set port (port_id) vf (vf_id) rx|tx on|off\n" 455 " Enable/Disable a VF receive/tranmit from a port\n\n" 456 457 "set port (port_id) vf (vf_id) (mac_addr)" 458 " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n" 459 " Add/Remove unicast or multicast MAC addr filter" 460 " for a VF.\n\n" 461 462 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 463 "|MPE) (on|off)\n" 464 " AUPE:accepts untagged VLAN;" 465 "ROPE:accept unicast hash\n\n" 466 " BAM:accepts broadcast packets;" 467 "MPE:accepts all multicast packets\n\n" 468 " Enable/Disable a VF receive mode of a port\n\n" 469 470 "set port (port_id) queue (queue_id) rate (rate_num)\n" 471 " Set rate limit for a queue of a port\n\n" 472 473 "set port (port_id) vf (vf_id) rate (rate_num) " 474 "queue_mask (queue_mask_value)\n" 475 " Set rate limit for queues in VF of a port\n\n" 476 477 "set port (port_id) mirror-rule (rule_id)" 478 " (pool-mirror-up|pool-mirror-down|vlan-mirror)" 479 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 480 " Set pool or vlan type mirror rule on a port.\n" 481 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 482 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 483 " to pool 0.\n\n" 484 485 "set port (port_id) mirror-rule (rule_id)" 486 " (uplink-mirror|downlink-mirror) dst-pool" 487 " (pool_id) (on|off)\n" 488 " Set uplink or downlink type mirror rule on a port.\n" 489 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 490 " 0 on' enable mirror income traffic to pool 0.\n\n" 491 492 "reset port (port_id) mirror-rule (rule_id)\n" 493 " Reset a mirror rule.\n\n" 494 495 "set flush_rx (on|off)\n" 496 " Flush (default) or don't flush RX streams before" 497 " forwarding. Mainly used with PCAP drivers.\n\n" 498 499 #ifdef RTE_NIC_BYPASS 500 "set bypass mode (normal|bypass|isolate) (port_id)\n" 501 " Set the bypass mode for the lowest port on bypass enabled" 502 " NIC.\n\n" 503 504 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 505 "mode (normal|bypass|isolate) (port_id)\n" 506 " Set the event required to initiate specified bypass mode for" 507 " the lowest port on a bypass enabled NIC where:\n" 508 " timeout = enable bypass after watchdog timeout.\n" 509 " os_on = enable bypass when OS/board is powered on.\n" 510 " os_off = enable bypass when OS/board is powered off.\n" 511 " power_on = enable bypass when power supply is turned on.\n" 512 " power_off = enable bypass when power supply is turned off." 513 "\n\n" 514 515 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 516 " Set the bypass watchdog timeout to 'n' seconds" 517 " where 0 = instant.\n\n" 518 519 "show bypass config (port_id)\n" 520 " Show the bypass configuration for a bypass enabled NIC" 521 " using the lowest port on the NIC.\n\n" 522 #endif 523 #ifdef RTE_LIBRTE_PMD_BOND 524 "create bonded device (mode) (socket)\n" 525 " Create a new bonded device with specific bonding mode and socket.\n\n" 526 527 "add bonding slave (slave_id) (port_id)\n" 528 " Add a slave device to a bonded device.\n\n" 529 530 "remove bonding slave (slave_id) (port_id)\n" 531 " Remove a slave device from a bonded device.\n\n" 532 533 "set bonding mode (value) (port_id)\n" 534 " Set the bonding mode on a bonded device.\n\n" 535 536 "set bonding primary (slave_id) (port_id)\n" 537 " Set the primary slave for a bonded device.\n\n" 538 539 "show bonding config (port_id)\n" 540 " Show the bonding config for port_id.\n\n" 541 542 "set bonding mac_addr (port_id) (address)\n" 543 " Set the MAC address of a bonded device.\n\n" 544 545 "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n" 546 " Set the transmit balance policy for bonded device running in balance mode.\n\n" 547 548 "set bonding mon_period (port_id) (value)\n" 549 " Set the bonding link status monitoring polling period in ms.\n\n" 550 #endif 551 "set link-up port (port_id)\n" 552 " Set link up for a port.\n\n" 553 554 "set link-down port (port_id)\n" 555 " Set link down for a port.\n\n" 556 557 "E-tag set insertion on port-tag-id (value)" 558 " port (port_id) vf (vf_id)\n" 559 " Enable E-tag insertion for a VF on a port\n\n" 560 561 "E-tag set insertion off port (port_id) vf (vf_id)\n" 562 " Disable E-tag insertion for a VF on a port\n\n" 563 564 "E-tag set stripping (on|off) port (port_id)\n" 565 " Enable/disable E-tag stripping on a port\n\n" 566 567 "E-tag set forwarding (on|off) port (port_id)\n" 568 " Enable/disable E-tag based forwarding" 569 " on a port\n\n" 570 571 "E-tag set filter add e-tag-id (value) dst-pool" 572 " (pool_id) port (port_id)\n" 573 " Add an E-tag forwarding filter on a port\n\n" 574 575 "E-tag set filter del e-tag-id (value) port (port_id)\n" 576 " Delete an E-tag forwarding filter on a port\n\n" 577 578 , list_pkt_forwarding_modes() 579 ); 580 } 581 582 if (show_all || !strcmp(res->section, "ports")) { 583 584 cmdline_printf( 585 cl, 586 "\n" 587 "Port Operations:\n" 588 "----------------\n\n" 589 590 "port start (port_id|all)\n" 591 " Start all ports or port_id.\n\n" 592 593 "port stop (port_id|all)\n" 594 " Stop all ports or port_id.\n\n" 595 596 "port close (port_id|all)\n" 597 " Close all ports or port_id.\n\n" 598 599 "port attach (ident)\n" 600 " Attach physical or virtual dev by pci address or virtual device name\n\n" 601 602 "port detach (port_id)\n" 603 " Detach physical or virtual dev by port_id\n\n" 604 605 "port config (port_id|all)" 606 " speed (10|100|1000|10000|25000|40000|50000|100000|auto)" 607 " duplex (half|full|auto)\n" 608 " Set speed and duplex for all ports or port_id\n\n" 609 610 "port config all (rxq|txq|rxd|txd) (value)\n" 611 " Set number for rxq/txq/rxd/txd.\n\n" 612 613 "port config all max-pkt-len (value)\n" 614 " Set the max packet length.\n\n" 615 616 "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|" 617 "hw-vlan-strip|hw-vlan-extend|drop-en)" 618 " (on|off)\n" 619 " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" 620 " for ports.\n\n" 621 622 "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n" 623 " Set the RSS mode.\n\n" 624 625 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 626 " Set the RSS redirection table.\n\n" 627 628 "port config (port_id) dcb vt (on|off) (traffic_class)" 629 " pfc (on|off)\n" 630 " Set the DCB mode.\n\n" 631 632 "port config all burst (value)\n" 633 " Set the number of packets per burst.\n\n" 634 635 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 636 " (value)\n" 637 " Set the ring prefetch/host/writeback threshold" 638 " for tx/rx queue.\n\n" 639 640 "port config all (txfreet|txrst|rxfreet) (value)\n" 641 " Set free threshold for rx/tx, or set" 642 " tx rs bit threshold.\n\n" 643 "port config mtu X value\n" 644 " Set the MTU of port X to a given value\n\n" 645 646 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 647 " Start/stop a rx/tx queue of port X. Only take effect" 648 " when port X is started\n\n" 649 650 "port config (port_id|all) l2-tunnel E-tag ether-type" 651 " (value)\n" 652 " Set the value of E-tag ether-type.\n\n" 653 654 "port config (port_id|all) l2-tunnel E-tag" 655 " (enable|disable)\n" 656 " Enable/disable the E-tag support.\n\n" 657 ); 658 } 659 660 if (show_all || !strcmp(res->section, "registers")) { 661 662 cmdline_printf( 663 cl, 664 "\n" 665 "Registers:\n" 666 "----------\n\n" 667 668 "read reg (port_id) (address)\n" 669 " Display value of a port register.\n\n" 670 671 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 672 " Display a port register bit field.\n\n" 673 674 "read regbit (port_id) (address) (bit_x)\n" 675 " Display a single port register bit.\n\n" 676 677 "write reg (port_id) (address) (value)\n" 678 " Set value of a port register.\n\n" 679 680 "write regfield (port_id) (address) (bit_x) (bit_y)" 681 " (value)\n" 682 " Set bit field of a port register.\n\n" 683 684 "write regbit (port_id) (address) (bit_x) (value)\n" 685 " Set single bit value of a port register.\n\n" 686 ); 687 } 688 if (show_all || !strcmp(res->section, "filters")) { 689 690 cmdline_printf( 691 cl, 692 "\n" 693 "filters:\n" 694 "--------\n\n" 695 696 "ethertype_filter (port_id) (add|del)" 697 " (mac_addr|mac_ignr) (mac_address) ethertype" 698 " (ether_type) (drop|fwd) queue (queue_id)\n" 699 " Add/Del an ethertype filter.\n\n" 700 701 "2tuple_filter (port_id) (add|del)" 702 " dst_port (dst_port_value) protocol (protocol_value)" 703 " mask (mask_value) tcp_flags (tcp_flags_value)" 704 " priority (prio_value) queue (queue_id)\n" 705 " Add/Del a 2tuple filter.\n\n" 706 707 "5tuple_filter (port_id) (add|del)" 708 " dst_ip (dst_address) src_ip (src_address)" 709 " dst_port (dst_port_value) src_port (src_port_value)" 710 " protocol (protocol_value)" 711 " mask (mask_value) tcp_flags (tcp_flags_value)" 712 " priority (prio_value) queue (queue_id)\n" 713 " Add/Del a 5tuple filter.\n\n" 714 715 "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" 716 " Add/Del syn filter.\n\n" 717 718 "flex_filter (port_id) (add|del) len (len_value)" 719 " bytes (bytes_value) mask (mask_value)" 720 " priority (prio_value) queue (queue_id)\n" 721 " Add/Del a flex filter.\n\n" 722 723 "flow_director_filter (port_id) mode IP (add|del|update)" 724 " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)" 725 " src (src_ip_address) dst (dst_ip_address)" 726 " tos (tos_value) proto (proto_value) ttl (ttl_value)" 727 " vlan (vlan_value) flexbytes (flexbytes_value)" 728 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 729 " fd_id (fd_id_value)\n" 730 " Add/Del an IP type flow director filter.\n\n" 731 732 "flow_director_filter (port_id) mode IP (add|del|update)" 733 " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)" 734 " src (src_ip_address) (src_port)" 735 " dst (dst_ip_address) (dst_port)" 736 " tos (tos_value) ttl (ttl_value)" 737 " vlan (vlan_value) flexbytes (flexbytes_value)" 738 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 739 " fd_id (fd_id_value)\n" 740 " Add/Del an UDP/TCP type flow director filter.\n\n" 741 742 "flow_director_filter (port_id) mode IP (add|del|update)" 743 " flow (ipv4-sctp|ipv6-sctp)" 744 " src (src_ip_address) (src_port)" 745 " dst (dst_ip_address) (dst_port)" 746 " tag (verification_tag) " 747 " tos (tos_value) ttl (ttl_value)" 748 " vlan (vlan_value)" 749 " flexbytes (flexbytes_value) (drop|fwd)" 750 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 751 " Add/Del a SCTP type flow director filter.\n\n" 752 753 "flow_director_filter (port_id) mode IP (add|del|update)" 754 " flow l2_payload ether (ethertype)" 755 " flexbytes (flexbytes_value) (drop|fwd)" 756 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 757 " Add/Del a l2 payload type flow director filter.\n\n" 758 759 "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)" 760 " mac (mac_address) vlan (vlan_value)" 761 " flexbytes (flexbytes_value) (drop|fwd)" 762 " queue (queue_id) fd_id (fd_id_value)\n" 763 " Add/Del a MAC-VLAN flow director filter.\n\n" 764 765 "flow_director_filter (port_id) mode Tunnel (add|del|update)" 766 " mac (mac_address) vlan (vlan_value)" 767 " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)" 768 " flexbytes (flexbytes_value) (drop|fwd)" 769 " queue (queue_id) fd_id (fd_id_value)\n" 770 " Add/Del a Tunnel flow director filter.\n\n" 771 772 "flush_flow_director (port_id)\n" 773 " Flush all flow director entries of a device.\n\n" 774 775 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 776 " src_mask (ipv4_src) (ipv6_src) (src_port)" 777 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 778 " Set flow director IP mask.\n\n" 779 780 "flow_director_mask (port_id) mode MAC-VLAN" 781 " vlan (vlan_value)\n" 782 " Set flow director MAC-VLAN mask.\n\n" 783 784 "flow_director_mask (port_id) mode Tunnel" 785 " vlan (vlan_value) mac (mac_value)" 786 " tunnel-type (tunnel_type_value)" 787 " tunnel-id (tunnel_id_value)\n" 788 " Set flow director Tunnel mask.\n\n" 789 790 "flow_director_flex_mask (port_id)" 791 " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 792 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)" 793 " (mask)\n" 794 " Configure mask of flex payload.\n\n" 795 796 "flow_director_flex_payload (port_id)" 797 " (raw|l2|l3|l4) (config)\n" 798 " Configure flex payload selection.\n\n" 799 800 "get_sym_hash_ena_per_port (port_id)\n" 801 " get symmetric hash enable configuration per port.\n\n" 802 803 "set_sym_hash_ena_per_port (port_id) (enable|disable)\n" 804 " set symmetric hash enable configuration per port" 805 " to enable or disable.\n\n" 806 807 "get_hash_global_config (port_id)\n" 808 " Get the global configurations of hash filters.\n\n" 809 810 "set_hash_global_config (port_id) (toeplitz|simple_xor|default)" 811 " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 812 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)" 813 " (enable|disable)\n" 814 " Set the global configurations of hash filters.\n\n" 815 816 "set_hash_input_set (port_id) (ipv4|ipv4-frag|" 817 "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 818 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 819 "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|" 820 "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" 821 "ipv6-next-header|udp-src-port|udp-dst-port|" 822 "tcp-src-port|tcp-dst-port|sctp-src-port|" 823 "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" 824 "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|" 825 "fld-8th|none) (select|add)\n" 826 " Set the input set for hash.\n\n" 827 828 "set_fdir_input_set (port_id) " 829 "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 830 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 831 "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|" 832 "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|" 833 "ipv6-next-header|ipv6-hop-limits|udp-src-port|" 834 "udp-dst-port|tcp-src-port|tcp-dst-port|" 835 "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)" 836 " (select|add)\n" 837 " Set the input set for FDir.\n\n" 838 839 "flow validate {port_id}" 840 " [group {group_id}] [priority {level}]" 841 " [ingress] [egress]" 842 " pattern {item} [/ {item} [...]] / end" 843 " actions {action} [/ {action} [...]] / end\n" 844 " Check whether a flow rule can be created.\n\n" 845 846 "flow create {port_id}" 847 " [group {group_id}] [priority {level}]" 848 " [ingress] [egress]" 849 " pattern {item} [/ {item} [...]] / end" 850 " actions {action} [/ {action} [...]] / end\n" 851 " Create a flow rule.\n\n" 852 853 "flow destroy {port_id} rule {rule_id} [...]\n" 854 " Destroy specific flow rules.\n\n" 855 856 "flow flush {port_id}\n" 857 " Destroy all flow rules.\n\n" 858 859 "flow query {port_id} {rule_id} {action}\n" 860 " Query an existing flow rule.\n\n" 861 862 "flow list {port_id} [group {group_id}] [...]\n" 863 " List existing flow rules sorted by priority," 864 " filtered by group identifiers.\n\n" 865 ); 866 } 867 } 868 869 cmdline_parse_token_string_t cmd_help_long_help = 870 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 871 872 cmdline_parse_token_string_t cmd_help_long_section = 873 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 874 "all#control#display#config#" 875 "ports#registers#filters"); 876 877 cmdline_parse_inst_t cmd_help_long = { 878 .f = cmd_help_long_parsed, 879 .data = NULL, 880 .help_str = "help all|control|display|config|ports|register|filters: " 881 "Show help", 882 .tokens = { 883 (void *)&cmd_help_long_help, 884 (void *)&cmd_help_long_section, 885 NULL, 886 }, 887 }; 888 889 890 /* *** start/stop/close all ports *** */ 891 struct cmd_operate_port_result { 892 cmdline_fixed_string_t keyword; 893 cmdline_fixed_string_t name; 894 cmdline_fixed_string_t value; 895 }; 896 897 static void cmd_operate_port_parsed(void *parsed_result, 898 __attribute__((unused)) struct cmdline *cl, 899 __attribute__((unused)) void *data) 900 { 901 struct cmd_operate_port_result *res = parsed_result; 902 903 if (!strcmp(res->name, "start")) 904 start_port(RTE_PORT_ALL); 905 else if (!strcmp(res->name, "stop")) 906 stop_port(RTE_PORT_ALL); 907 else if (!strcmp(res->name, "close")) 908 close_port(RTE_PORT_ALL); 909 else 910 printf("Unknown parameter\n"); 911 } 912 913 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 914 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 915 "port"); 916 cmdline_parse_token_string_t cmd_operate_port_all_port = 917 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 918 "start#stop#close"); 919 cmdline_parse_token_string_t cmd_operate_port_all_all = 920 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 921 922 cmdline_parse_inst_t cmd_operate_port = { 923 .f = cmd_operate_port_parsed, 924 .data = NULL, 925 .help_str = "port start|stop|close all: Start/Stop/Close all ports", 926 .tokens = { 927 (void *)&cmd_operate_port_all_cmd, 928 (void *)&cmd_operate_port_all_port, 929 (void *)&cmd_operate_port_all_all, 930 NULL, 931 }, 932 }; 933 934 /* *** start/stop/close specific port *** */ 935 struct cmd_operate_specific_port_result { 936 cmdline_fixed_string_t keyword; 937 cmdline_fixed_string_t name; 938 uint8_t value; 939 }; 940 941 static void cmd_operate_specific_port_parsed(void *parsed_result, 942 __attribute__((unused)) struct cmdline *cl, 943 __attribute__((unused)) void *data) 944 { 945 struct cmd_operate_specific_port_result *res = parsed_result; 946 947 if (!strcmp(res->name, "start")) 948 start_port(res->value); 949 else if (!strcmp(res->name, "stop")) 950 stop_port(res->value); 951 else if (!strcmp(res->name, "close")) 952 close_port(res->value); 953 else 954 printf("Unknown parameter\n"); 955 } 956 957 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 958 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 959 keyword, "port"); 960 cmdline_parse_token_string_t cmd_operate_specific_port_port = 961 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 962 name, "start#stop#close"); 963 cmdline_parse_token_num_t cmd_operate_specific_port_id = 964 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 965 value, UINT8); 966 967 cmdline_parse_inst_t cmd_operate_specific_port = { 968 .f = cmd_operate_specific_port_parsed, 969 .data = NULL, 970 .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id", 971 .tokens = { 972 (void *)&cmd_operate_specific_port_cmd, 973 (void *)&cmd_operate_specific_port_port, 974 (void *)&cmd_operate_specific_port_id, 975 NULL, 976 }, 977 }; 978 979 /* *** attach a specified port *** */ 980 struct cmd_operate_attach_port_result { 981 cmdline_fixed_string_t port; 982 cmdline_fixed_string_t keyword; 983 cmdline_fixed_string_t identifier; 984 }; 985 986 static void cmd_operate_attach_port_parsed(void *parsed_result, 987 __attribute__((unused)) struct cmdline *cl, 988 __attribute__((unused)) void *data) 989 { 990 struct cmd_operate_attach_port_result *res = parsed_result; 991 992 if (!strcmp(res->keyword, "attach")) 993 attach_port(res->identifier); 994 else 995 printf("Unknown parameter\n"); 996 } 997 998 cmdline_parse_token_string_t cmd_operate_attach_port_port = 999 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1000 port, "port"); 1001 cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1002 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1003 keyword, "attach"); 1004 cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1005 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1006 identifier, NULL); 1007 1008 cmdline_parse_inst_t cmd_operate_attach_port = { 1009 .f = cmd_operate_attach_port_parsed, 1010 .data = NULL, 1011 .help_str = "port attach <identifier>: " 1012 "(identifier: pci address or virtual dev name)", 1013 .tokens = { 1014 (void *)&cmd_operate_attach_port_port, 1015 (void *)&cmd_operate_attach_port_keyword, 1016 (void *)&cmd_operate_attach_port_identifier, 1017 NULL, 1018 }, 1019 }; 1020 1021 /* *** detach a specified port *** */ 1022 struct cmd_operate_detach_port_result { 1023 cmdline_fixed_string_t port; 1024 cmdline_fixed_string_t keyword; 1025 uint8_t port_id; 1026 }; 1027 1028 static void cmd_operate_detach_port_parsed(void *parsed_result, 1029 __attribute__((unused)) struct cmdline *cl, 1030 __attribute__((unused)) void *data) 1031 { 1032 struct cmd_operate_detach_port_result *res = parsed_result; 1033 1034 if (!strcmp(res->keyword, "detach")) 1035 detach_port(res->port_id); 1036 else 1037 printf("Unknown parameter\n"); 1038 } 1039 1040 cmdline_parse_token_string_t cmd_operate_detach_port_port = 1041 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1042 port, "port"); 1043 cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1044 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1045 keyword, "detach"); 1046 cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1047 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1048 port_id, UINT8); 1049 1050 cmdline_parse_inst_t cmd_operate_detach_port = { 1051 .f = cmd_operate_detach_port_parsed, 1052 .data = NULL, 1053 .help_str = "port detach <port_id>", 1054 .tokens = { 1055 (void *)&cmd_operate_detach_port_port, 1056 (void *)&cmd_operate_detach_port_keyword, 1057 (void *)&cmd_operate_detach_port_port_id, 1058 NULL, 1059 }, 1060 }; 1061 1062 /* *** configure speed for all ports *** */ 1063 struct cmd_config_speed_all { 1064 cmdline_fixed_string_t port; 1065 cmdline_fixed_string_t keyword; 1066 cmdline_fixed_string_t all; 1067 cmdline_fixed_string_t item1; 1068 cmdline_fixed_string_t item2; 1069 cmdline_fixed_string_t value1; 1070 cmdline_fixed_string_t value2; 1071 }; 1072 1073 static int 1074 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1075 { 1076 1077 int duplex; 1078 1079 if (!strcmp(duplexstr, "half")) { 1080 duplex = ETH_LINK_HALF_DUPLEX; 1081 } else if (!strcmp(duplexstr, "full")) { 1082 duplex = ETH_LINK_FULL_DUPLEX; 1083 } else if (!strcmp(duplexstr, "auto")) { 1084 duplex = ETH_LINK_FULL_DUPLEX; 1085 } else { 1086 printf("Unknown duplex parameter\n"); 1087 return -1; 1088 } 1089 1090 if (!strcmp(speedstr, "10")) { 1091 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1092 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M; 1093 } else if (!strcmp(speedstr, "100")) { 1094 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1095 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M; 1096 } else { 1097 if (duplex != ETH_LINK_FULL_DUPLEX) { 1098 printf("Invalid speed/duplex parameters\n"); 1099 return -1; 1100 } 1101 if (!strcmp(speedstr, "1000")) { 1102 *speed = ETH_LINK_SPEED_1G; 1103 } else if (!strcmp(speedstr, "10000")) { 1104 *speed = ETH_LINK_SPEED_10G; 1105 } else if (!strcmp(speedstr, "25000")) { 1106 *speed = ETH_LINK_SPEED_25G; 1107 } else if (!strcmp(speedstr, "40000")) { 1108 *speed = ETH_LINK_SPEED_40G; 1109 } else if (!strcmp(speedstr, "50000")) { 1110 *speed = ETH_LINK_SPEED_50G; 1111 } else if (!strcmp(speedstr, "100000")) { 1112 *speed = ETH_LINK_SPEED_100G; 1113 } else if (!strcmp(speedstr, "auto")) { 1114 *speed = ETH_LINK_SPEED_AUTONEG; 1115 } else { 1116 printf("Unknown speed parameter\n"); 1117 return -1; 1118 } 1119 } 1120 1121 return 0; 1122 } 1123 1124 static void 1125 cmd_config_speed_all_parsed(void *parsed_result, 1126 __attribute__((unused)) struct cmdline *cl, 1127 __attribute__((unused)) void *data) 1128 { 1129 struct cmd_config_speed_all *res = parsed_result; 1130 uint32_t link_speed; 1131 portid_t pid; 1132 1133 if (!all_ports_stopped()) { 1134 printf("Please stop all ports first\n"); 1135 return; 1136 } 1137 1138 if (parse_and_check_speed_duplex(res->value1, res->value2, 1139 &link_speed) < 0) 1140 return; 1141 1142 FOREACH_PORT(pid, ports) { 1143 ports[pid].dev_conf.link_speeds = link_speed; 1144 } 1145 1146 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1147 } 1148 1149 cmdline_parse_token_string_t cmd_config_speed_all_port = 1150 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1151 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1152 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1153 "config"); 1154 cmdline_parse_token_string_t cmd_config_speed_all_all = 1155 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1156 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1157 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1158 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1159 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1160 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1161 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1162 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1163 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1164 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1165 "half#full#auto"); 1166 1167 cmdline_parse_inst_t cmd_config_speed_all = { 1168 .f = cmd_config_speed_all_parsed, 1169 .data = NULL, 1170 .help_str = "port config all speed " 1171 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1172 "half|full|auto", 1173 .tokens = { 1174 (void *)&cmd_config_speed_all_port, 1175 (void *)&cmd_config_speed_all_keyword, 1176 (void *)&cmd_config_speed_all_all, 1177 (void *)&cmd_config_speed_all_item1, 1178 (void *)&cmd_config_speed_all_value1, 1179 (void *)&cmd_config_speed_all_item2, 1180 (void *)&cmd_config_speed_all_value2, 1181 NULL, 1182 }, 1183 }; 1184 1185 /* *** configure speed for specific port *** */ 1186 struct cmd_config_speed_specific { 1187 cmdline_fixed_string_t port; 1188 cmdline_fixed_string_t keyword; 1189 uint8_t id; 1190 cmdline_fixed_string_t item1; 1191 cmdline_fixed_string_t item2; 1192 cmdline_fixed_string_t value1; 1193 cmdline_fixed_string_t value2; 1194 }; 1195 1196 static void 1197 cmd_config_speed_specific_parsed(void *parsed_result, 1198 __attribute__((unused)) struct cmdline *cl, 1199 __attribute__((unused)) void *data) 1200 { 1201 struct cmd_config_speed_specific *res = parsed_result; 1202 uint32_t link_speed; 1203 1204 if (!all_ports_stopped()) { 1205 printf("Please stop all ports first\n"); 1206 return; 1207 } 1208 1209 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1210 return; 1211 1212 if (parse_and_check_speed_duplex(res->value1, res->value2, 1213 &link_speed) < 0) 1214 return; 1215 1216 ports[res->id].dev_conf.link_speeds = link_speed; 1217 1218 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1219 } 1220 1221 1222 cmdline_parse_token_string_t cmd_config_speed_specific_port = 1223 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1224 "port"); 1225 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1226 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1227 "config"); 1228 cmdline_parse_token_num_t cmd_config_speed_specific_id = 1229 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 1230 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1231 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1232 "speed"); 1233 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1234 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1235 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1236 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1237 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1238 "duplex"); 1239 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1240 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1241 "half#full#auto"); 1242 1243 cmdline_parse_inst_t cmd_config_speed_specific = { 1244 .f = cmd_config_speed_specific_parsed, 1245 .data = NULL, 1246 .help_str = "port config <port_id> speed " 1247 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1248 "half|full|auto", 1249 .tokens = { 1250 (void *)&cmd_config_speed_specific_port, 1251 (void *)&cmd_config_speed_specific_keyword, 1252 (void *)&cmd_config_speed_specific_id, 1253 (void *)&cmd_config_speed_specific_item1, 1254 (void *)&cmd_config_speed_specific_value1, 1255 (void *)&cmd_config_speed_specific_item2, 1256 (void *)&cmd_config_speed_specific_value2, 1257 NULL, 1258 }, 1259 }; 1260 1261 /* *** configure txq/rxq, txd/rxd *** */ 1262 struct cmd_config_rx_tx { 1263 cmdline_fixed_string_t port; 1264 cmdline_fixed_string_t keyword; 1265 cmdline_fixed_string_t all; 1266 cmdline_fixed_string_t name; 1267 uint16_t value; 1268 }; 1269 1270 static void 1271 cmd_config_rx_tx_parsed(void *parsed_result, 1272 __attribute__((unused)) struct cmdline *cl, 1273 __attribute__((unused)) void *data) 1274 { 1275 struct cmd_config_rx_tx *res = parsed_result; 1276 1277 if (!all_ports_stopped()) { 1278 printf("Please stop all ports first\n"); 1279 return; 1280 } 1281 if (!strcmp(res->name, "rxq")) { 1282 if (!res->value && !nb_txq) { 1283 printf("Warning: Either rx or tx queues should be non zero\n"); 1284 return; 1285 } 1286 nb_rxq = res->value; 1287 } 1288 else if (!strcmp(res->name, "txq")) { 1289 if (!res->value && !nb_rxq) { 1290 printf("Warning: Either rx or tx queues should be non zero\n"); 1291 return; 1292 } 1293 nb_txq = res->value; 1294 } 1295 else if (!strcmp(res->name, "rxd")) { 1296 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 1297 printf("rxd %d invalid - must be > 0 && <= %d\n", 1298 res->value, RTE_TEST_RX_DESC_MAX); 1299 return; 1300 } 1301 nb_rxd = res->value; 1302 } else if (!strcmp(res->name, "txd")) { 1303 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 1304 printf("txd %d invalid - must be > 0 && <= %d\n", 1305 res->value, RTE_TEST_TX_DESC_MAX); 1306 return; 1307 } 1308 nb_txd = res->value; 1309 } else { 1310 printf("Unknown parameter\n"); 1311 return; 1312 } 1313 1314 fwd_config_setup(); 1315 1316 init_port_config(); 1317 1318 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1319 } 1320 1321 cmdline_parse_token_string_t cmd_config_rx_tx_port = 1322 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1323 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1324 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1325 cmdline_parse_token_string_t cmd_config_rx_tx_all = 1326 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1327 cmdline_parse_token_string_t cmd_config_rx_tx_name = 1328 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1329 "rxq#txq#rxd#txd"); 1330 cmdline_parse_token_num_t cmd_config_rx_tx_value = 1331 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 1332 1333 cmdline_parse_inst_t cmd_config_rx_tx = { 1334 .f = cmd_config_rx_tx_parsed, 1335 .data = NULL, 1336 .help_str = "port config all rxq|txq|rxd|txd <value>", 1337 .tokens = { 1338 (void *)&cmd_config_rx_tx_port, 1339 (void *)&cmd_config_rx_tx_keyword, 1340 (void *)&cmd_config_rx_tx_all, 1341 (void *)&cmd_config_rx_tx_name, 1342 (void *)&cmd_config_rx_tx_value, 1343 NULL, 1344 }, 1345 }; 1346 1347 /* *** config max packet length *** */ 1348 struct cmd_config_max_pkt_len_result { 1349 cmdline_fixed_string_t port; 1350 cmdline_fixed_string_t keyword; 1351 cmdline_fixed_string_t all; 1352 cmdline_fixed_string_t name; 1353 uint32_t value; 1354 }; 1355 1356 static void 1357 cmd_config_max_pkt_len_parsed(void *parsed_result, 1358 __attribute__((unused)) struct cmdline *cl, 1359 __attribute__((unused)) void *data) 1360 { 1361 struct cmd_config_max_pkt_len_result *res = parsed_result; 1362 1363 if (!all_ports_stopped()) { 1364 printf("Please stop all ports first\n"); 1365 return; 1366 } 1367 1368 if (!strcmp(res->name, "max-pkt-len")) { 1369 if (res->value < ETHER_MIN_LEN) { 1370 printf("max-pkt-len can not be less than %d\n", 1371 ETHER_MIN_LEN); 1372 return; 1373 } 1374 if (res->value == rx_mode.max_rx_pkt_len) 1375 return; 1376 1377 rx_mode.max_rx_pkt_len = res->value; 1378 if (res->value > ETHER_MAX_LEN) 1379 rx_mode.jumbo_frame = 1; 1380 else 1381 rx_mode.jumbo_frame = 0; 1382 } else { 1383 printf("Unknown parameter\n"); 1384 return; 1385 } 1386 1387 init_port_config(); 1388 1389 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1390 } 1391 1392 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1393 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1394 "port"); 1395 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1396 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1397 "config"); 1398 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1399 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1400 "all"); 1401 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1402 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1403 "max-pkt-len"); 1404 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1405 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1406 UINT32); 1407 1408 cmdline_parse_inst_t cmd_config_max_pkt_len = { 1409 .f = cmd_config_max_pkt_len_parsed, 1410 .data = NULL, 1411 .help_str = "port config all max-pkt-len <value>", 1412 .tokens = { 1413 (void *)&cmd_config_max_pkt_len_port, 1414 (void *)&cmd_config_max_pkt_len_keyword, 1415 (void *)&cmd_config_max_pkt_len_all, 1416 (void *)&cmd_config_max_pkt_len_name, 1417 (void *)&cmd_config_max_pkt_len_value, 1418 NULL, 1419 }, 1420 }; 1421 1422 /* *** configure port MTU *** */ 1423 struct cmd_config_mtu_result { 1424 cmdline_fixed_string_t port; 1425 cmdline_fixed_string_t keyword; 1426 cmdline_fixed_string_t mtu; 1427 uint8_t port_id; 1428 uint16_t value; 1429 }; 1430 1431 static void 1432 cmd_config_mtu_parsed(void *parsed_result, 1433 __attribute__((unused)) struct cmdline *cl, 1434 __attribute__((unused)) void *data) 1435 { 1436 struct cmd_config_mtu_result *res = parsed_result; 1437 1438 if (res->value < ETHER_MIN_LEN) { 1439 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN); 1440 return; 1441 } 1442 port_mtu_set(res->port_id, res->value); 1443 } 1444 1445 cmdline_parse_token_string_t cmd_config_mtu_port = 1446 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1447 "port"); 1448 cmdline_parse_token_string_t cmd_config_mtu_keyword = 1449 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1450 "config"); 1451 cmdline_parse_token_string_t cmd_config_mtu_mtu = 1452 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1453 "mtu"); 1454 cmdline_parse_token_num_t cmd_config_mtu_port_id = 1455 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8); 1456 cmdline_parse_token_num_t cmd_config_mtu_value = 1457 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); 1458 1459 cmdline_parse_inst_t cmd_config_mtu = { 1460 .f = cmd_config_mtu_parsed, 1461 .data = NULL, 1462 .help_str = "port config mtu <port_id> <value>", 1463 .tokens = { 1464 (void *)&cmd_config_mtu_port, 1465 (void *)&cmd_config_mtu_keyword, 1466 (void *)&cmd_config_mtu_mtu, 1467 (void *)&cmd_config_mtu_port_id, 1468 (void *)&cmd_config_mtu_value, 1469 NULL, 1470 }, 1471 }; 1472 1473 /* *** configure rx mode *** */ 1474 struct cmd_config_rx_mode_flag { 1475 cmdline_fixed_string_t port; 1476 cmdline_fixed_string_t keyword; 1477 cmdline_fixed_string_t all; 1478 cmdline_fixed_string_t name; 1479 cmdline_fixed_string_t value; 1480 }; 1481 1482 static void 1483 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1484 __attribute__((unused)) struct cmdline *cl, 1485 __attribute__((unused)) void *data) 1486 { 1487 struct cmd_config_rx_mode_flag *res = parsed_result; 1488 1489 if (!all_ports_stopped()) { 1490 printf("Please stop all ports first\n"); 1491 return; 1492 } 1493 1494 if (!strcmp(res->name, "crc-strip")) { 1495 if (!strcmp(res->value, "on")) 1496 rx_mode.hw_strip_crc = 1; 1497 else if (!strcmp(res->value, "off")) 1498 rx_mode.hw_strip_crc = 0; 1499 else { 1500 printf("Unknown parameter\n"); 1501 return; 1502 } 1503 } else if (!strcmp(res->name, "scatter")) { 1504 if (!strcmp(res->value, "on")) 1505 rx_mode.enable_scatter = 1; 1506 else if (!strcmp(res->value, "off")) 1507 rx_mode.enable_scatter = 0; 1508 else { 1509 printf("Unknown parameter\n"); 1510 return; 1511 } 1512 } else if (!strcmp(res->name, "rx-cksum")) { 1513 if (!strcmp(res->value, "on")) 1514 rx_mode.hw_ip_checksum = 1; 1515 else if (!strcmp(res->value, "off")) 1516 rx_mode.hw_ip_checksum = 0; 1517 else { 1518 printf("Unknown parameter\n"); 1519 return; 1520 } 1521 } else if (!strcmp(res->name, "hw-vlan")) { 1522 if (!strcmp(res->value, "on")) { 1523 rx_mode.hw_vlan_filter = 1; 1524 rx_mode.hw_vlan_strip = 1; 1525 } 1526 else if (!strcmp(res->value, "off")) { 1527 rx_mode.hw_vlan_filter = 0; 1528 rx_mode.hw_vlan_strip = 0; 1529 } 1530 else { 1531 printf("Unknown parameter\n"); 1532 return; 1533 } 1534 } else if (!strcmp(res->name, "hw-vlan-filter")) { 1535 if (!strcmp(res->value, "on")) 1536 rx_mode.hw_vlan_filter = 1; 1537 else if (!strcmp(res->value, "off")) 1538 rx_mode.hw_vlan_filter = 0; 1539 else { 1540 printf("Unknown parameter\n"); 1541 return; 1542 } 1543 } else if (!strcmp(res->name, "hw-vlan-strip")) { 1544 if (!strcmp(res->value, "on")) 1545 rx_mode.hw_vlan_strip = 1; 1546 else if (!strcmp(res->value, "off")) 1547 rx_mode.hw_vlan_strip = 0; 1548 else { 1549 printf("Unknown parameter\n"); 1550 return; 1551 } 1552 } else if (!strcmp(res->name, "hw-vlan-extend")) { 1553 if (!strcmp(res->value, "on")) 1554 rx_mode.hw_vlan_extend = 1; 1555 else if (!strcmp(res->value, "off")) 1556 rx_mode.hw_vlan_extend = 0; 1557 else { 1558 printf("Unknown parameter\n"); 1559 return; 1560 } 1561 } else if (!strcmp(res->name, "drop-en")) { 1562 if (!strcmp(res->value, "on")) 1563 rx_drop_en = 1; 1564 else if (!strcmp(res->value, "off")) 1565 rx_drop_en = 0; 1566 else { 1567 printf("Unknown parameter\n"); 1568 return; 1569 } 1570 } else { 1571 printf("Unknown parameter\n"); 1572 return; 1573 } 1574 1575 init_port_config(); 1576 1577 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1578 } 1579 1580 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1581 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1582 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1583 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1584 "config"); 1585 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1586 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1587 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1588 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1589 "crc-strip#scatter#rx-cksum#hw-vlan#" 1590 "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); 1591 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1592 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1593 "on#off"); 1594 1595 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1596 .f = cmd_config_rx_mode_flag_parsed, 1597 .data = NULL, 1598 .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|" 1599 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", 1600 .tokens = { 1601 (void *)&cmd_config_rx_mode_flag_port, 1602 (void *)&cmd_config_rx_mode_flag_keyword, 1603 (void *)&cmd_config_rx_mode_flag_all, 1604 (void *)&cmd_config_rx_mode_flag_name, 1605 (void *)&cmd_config_rx_mode_flag_value, 1606 NULL, 1607 }, 1608 }; 1609 1610 /* *** configure rss *** */ 1611 struct cmd_config_rss { 1612 cmdline_fixed_string_t port; 1613 cmdline_fixed_string_t keyword; 1614 cmdline_fixed_string_t all; 1615 cmdline_fixed_string_t name; 1616 cmdline_fixed_string_t value; 1617 }; 1618 1619 static void 1620 cmd_config_rss_parsed(void *parsed_result, 1621 __attribute__((unused)) struct cmdline *cl, 1622 __attribute__((unused)) void *data) 1623 { 1624 struct cmd_config_rss *res = parsed_result; 1625 struct rte_eth_rss_conf rss_conf; 1626 int diag; 1627 uint8_t i; 1628 1629 if (!strcmp(res->value, "all")) 1630 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | 1631 ETH_RSS_UDP | ETH_RSS_SCTP | 1632 ETH_RSS_L2_PAYLOAD; 1633 else if (!strcmp(res->value, "ip")) 1634 rss_conf.rss_hf = ETH_RSS_IP; 1635 else if (!strcmp(res->value, "udp")) 1636 rss_conf.rss_hf = ETH_RSS_UDP; 1637 else if (!strcmp(res->value, "tcp")) 1638 rss_conf.rss_hf = ETH_RSS_TCP; 1639 else if (!strcmp(res->value, "sctp")) 1640 rss_conf.rss_hf = ETH_RSS_SCTP; 1641 else if (!strcmp(res->value, "ether")) 1642 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD; 1643 else if (!strcmp(res->value, "port")) 1644 rss_conf.rss_hf = ETH_RSS_PORT; 1645 else if (!strcmp(res->value, "vxlan")) 1646 rss_conf.rss_hf = ETH_RSS_VXLAN; 1647 else if (!strcmp(res->value, "geneve")) 1648 rss_conf.rss_hf = ETH_RSS_GENEVE; 1649 else if (!strcmp(res->value, "nvgre")) 1650 rss_conf.rss_hf = ETH_RSS_NVGRE; 1651 else if (!strcmp(res->value, "none")) 1652 rss_conf.rss_hf = 0; 1653 else { 1654 printf("Unknown parameter\n"); 1655 return; 1656 } 1657 rss_conf.rss_key = NULL; 1658 for (i = 0; i < rte_eth_dev_count(); i++) { 1659 diag = rte_eth_dev_rss_hash_update(i, &rss_conf); 1660 if (diag < 0) 1661 printf("Configuration of RSS hash at ethernet port %d " 1662 "failed with error (%d): %s.\n", 1663 i, -diag, strerror(-diag)); 1664 } 1665 } 1666 1667 cmdline_parse_token_string_t cmd_config_rss_port = 1668 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1669 cmdline_parse_token_string_t cmd_config_rss_keyword = 1670 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1671 cmdline_parse_token_string_t cmd_config_rss_all = 1672 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1673 cmdline_parse_token_string_t cmd_config_rss_name = 1674 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1675 cmdline_parse_token_string_t cmd_config_rss_value = 1676 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, 1677 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none"); 1678 1679 cmdline_parse_inst_t cmd_config_rss = { 1680 .f = cmd_config_rss_parsed, 1681 .data = NULL, 1682 .help_str = "port config all rss " 1683 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none", 1684 .tokens = { 1685 (void *)&cmd_config_rss_port, 1686 (void *)&cmd_config_rss_keyword, 1687 (void *)&cmd_config_rss_all, 1688 (void *)&cmd_config_rss_name, 1689 (void *)&cmd_config_rss_value, 1690 NULL, 1691 }, 1692 }; 1693 1694 /* *** configure rss hash key *** */ 1695 struct cmd_config_rss_hash_key { 1696 cmdline_fixed_string_t port; 1697 cmdline_fixed_string_t config; 1698 uint8_t port_id; 1699 cmdline_fixed_string_t rss_hash_key; 1700 cmdline_fixed_string_t rss_type; 1701 cmdline_fixed_string_t key; 1702 }; 1703 1704 static uint8_t 1705 hexa_digit_to_value(char hexa_digit) 1706 { 1707 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 1708 return (uint8_t) (hexa_digit - '0'); 1709 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 1710 return (uint8_t) ((hexa_digit - 'a') + 10); 1711 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 1712 return (uint8_t) ((hexa_digit - 'A') + 10); 1713 /* Invalid hexa digit */ 1714 return 0xFF; 1715 } 1716 1717 static uint8_t 1718 parse_and_check_key_hexa_digit(char *key, int idx) 1719 { 1720 uint8_t hexa_v; 1721 1722 hexa_v = hexa_digit_to_value(key[idx]); 1723 if (hexa_v == 0xFF) 1724 printf("invalid key: character %c at position %d is not a " 1725 "valid hexa digit\n", key[idx], idx); 1726 return hexa_v; 1727 } 1728 1729 static void 1730 cmd_config_rss_hash_key_parsed(void *parsed_result, 1731 __attribute__((unused)) struct cmdline *cl, 1732 __attribute__((unused)) void *data) 1733 { 1734 struct cmd_config_rss_hash_key *res = parsed_result; 1735 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 1736 uint8_t xdgt0; 1737 uint8_t xdgt1; 1738 int i; 1739 struct rte_eth_dev_info dev_info; 1740 uint8_t hash_key_size; 1741 uint32_t key_len; 1742 1743 memset(&dev_info, 0, sizeof(dev_info)); 1744 rte_eth_dev_info_get(res->port_id, &dev_info); 1745 if (dev_info.hash_key_size > 0 && 1746 dev_info.hash_key_size <= sizeof(hash_key)) 1747 hash_key_size = dev_info.hash_key_size; 1748 else { 1749 printf("dev_info did not provide a valid hash key size\n"); 1750 return; 1751 } 1752 /* Check the length of the RSS hash key */ 1753 key_len = strlen(res->key); 1754 if (key_len != (hash_key_size * 2)) { 1755 printf("key length: %d invalid - key must be a string of %d" 1756 " hexa-decimal numbers\n", 1757 (int) key_len, hash_key_size * 2); 1758 return; 1759 } 1760 /* Translate RSS hash key into binary representation */ 1761 for (i = 0; i < hash_key_size; i++) { 1762 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 1763 if (xdgt0 == 0xFF) 1764 return; 1765 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 1766 if (xdgt1 == 0xFF) 1767 return; 1768 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 1769 } 1770 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 1771 hash_key_size); 1772 } 1773 1774 cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 1775 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 1776 cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 1777 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 1778 "config"); 1779 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 1780 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); 1781 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 1782 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 1783 rss_hash_key, "rss-hash-key"); 1784 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 1785 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 1786 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 1787 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 1788 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 1789 "ipv6-tcp-ex#ipv6-udp-ex"); 1790 cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 1791 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 1792 1793 cmdline_parse_inst_t cmd_config_rss_hash_key = { 1794 .f = cmd_config_rss_hash_key_parsed, 1795 .data = NULL, 1796 .help_str = "port config <port_id> rss-hash-key " 1797 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 1798 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1799 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex " 1800 "<string of hex digits (variable length, NIC dependent)>", 1801 .tokens = { 1802 (void *)&cmd_config_rss_hash_key_port, 1803 (void *)&cmd_config_rss_hash_key_config, 1804 (void *)&cmd_config_rss_hash_key_port_id, 1805 (void *)&cmd_config_rss_hash_key_rss_hash_key, 1806 (void *)&cmd_config_rss_hash_key_rss_type, 1807 (void *)&cmd_config_rss_hash_key_value, 1808 NULL, 1809 }, 1810 }; 1811 1812 /* *** configure port rxq/txq start/stop *** */ 1813 struct cmd_config_rxtx_queue { 1814 cmdline_fixed_string_t port; 1815 uint8_t portid; 1816 cmdline_fixed_string_t rxtxq; 1817 uint16_t qid; 1818 cmdline_fixed_string_t opname; 1819 }; 1820 1821 static void 1822 cmd_config_rxtx_queue_parsed(void *parsed_result, 1823 __attribute__((unused)) struct cmdline *cl, 1824 __attribute__((unused)) void *data) 1825 { 1826 struct cmd_config_rxtx_queue *res = parsed_result; 1827 uint8_t isrx; 1828 uint8_t isstart; 1829 int ret = 0; 1830 1831 if (test_done == 0) { 1832 printf("Please stop forwarding first\n"); 1833 return; 1834 } 1835 1836 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 1837 return; 1838 1839 if (port_is_started(res->portid) != 1) { 1840 printf("Please start port %u first\n", res->portid); 1841 return; 1842 } 1843 1844 if (!strcmp(res->rxtxq, "rxq")) 1845 isrx = 1; 1846 else if (!strcmp(res->rxtxq, "txq")) 1847 isrx = 0; 1848 else { 1849 printf("Unknown parameter\n"); 1850 return; 1851 } 1852 1853 if (isrx && rx_queue_id_is_invalid(res->qid)) 1854 return; 1855 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 1856 return; 1857 1858 if (!strcmp(res->opname, "start")) 1859 isstart = 1; 1860 else if (!strcmp(res->opname, "stop")) 1861 isstart = 0; 1862 else { 1863 printf("Unknown parameter\n"); 1864 return; 1865 } 1866 1867 if (isstart && isrx) 1868 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 1869 else if (!isstart && isrx) 1870 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 1871 else if (isstart && !isrx) 1872 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 1873 else 1874 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 1875 1876 if (ret == -ENOTSUP) 1877 printf("Function not supported in PMD driver\n"); 1878 } 1879 1880 cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 1881 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 1882 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 1883 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8); 1884 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 1885 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 1886 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 1887 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16); 1888 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 1889 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 1890 "start#stop"); 1891 1892 cmdline_parse_inst_t cmd_config_rxtx_queue = { 1893 .f = cmd_config_rxtx_queue_parsed, 1894 .data = NULL, 1895 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 1896 .tokens = { 1897 (void *)&cmd_config_speed_all_port, 1898 (void *)&cmd_config_rxtx_queue_portid, 1899 (void *)&cmd_config_rxtx_queue_rxtxq, 1900 (void *)&cmd_config_rxtx_queue_qid, 1901 (void *)&cmd_config_rxtx_queue_opname, 1902 NULL, 1903 }, 1904 }; 1905 1906 /* *** Configure RSS RETA *** */ 1907 struct cmd_config_rss_reta { 1908 cmdline_fixed_string_t port; 1909 cmdline_fixed_string_t keyword; 1910 uint8_t port_id; 1911 cmdline_fixed_string_t name; 1912 cmdline_fixed_string_t list_name; 1913 cmdline_fixed_string_t list_of_items; 1914 }; 1915 1916 static int 1917 parse_reta_config(const char *str, 1918 struct rte_eth_rss_reta_entry64 *reta_conf, 1919 uint16_t nb_entries) 1920 { 1921 int i; 1922 unsigned size; 1923 uint16_t hash_index, idx, shift; 1924 uint16_t nb_queue; 1925 char s[256]; 1926 const char *p, *p0 = str; 1927 char *end; 1928 enum fieldnames { 1929 FLD_HASH_INDEX = 0, 1930 FLD_QUEUE, 1931 _NUM_FLD 1932 }; 1933 unsigned long int_fld[_NUM_FLD]; 1934 char *str_fld[_NUM_FLD]; 1935 1936 while ((p = strchr(p0,'(')) != NULL) { 1937 ++p; 1938 if((p0 = strchr(p,')')) == NULL) 1939 return -1; 1940 1941 size = p0 - p; 1942 if(size >= sizeof(s)) 1943 return -1; 1944 1945 snprintf(s, sizeof(s), "%.*s", size, p); 1946 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 1947 return -1; 1948 for (i = 0; i < _NUM_FLD; i++) { 1949 errno = 0; 1950 int_fld[i] = strtoul(str_fld[i], &end, 0); 1951 if (errno != 0 || end == str_fld[i] || 1952 int_fld[i] > 65535) 1953 return -1; 1954 } 1955 1956 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 1957 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 1958 1959 if (hash_index >= nb_entries) { 1960 printf("Invalid RETA hash index=%d\n", hash_index); 1961 return -1; 1962 } 1963 1964 idx = hash_index / RTE_RETA_GROUP_SIZE; 1965 shift = hash_index % RTE_RETA_GROUP_SIZE; 1966 reta_conf[idx].mask |= (1ULL << shift); 1967 reta_conf[idx].reta[shift] = nb_queue; 1968 } 1969 1970 return 0; 1971 } 1972 1973 static void 1974 cmd_set_rss_reta_parsed(void *parsed_result, 1975 __attribute__((unused)) struct cmdline *cl, 1976 __attribute__((unused)) void *data) 1977 { 1978 int ret; 1979 struct rte_eth_dev_info dev_info; 1980 struct rte_eth_rss_reta_entry64 reta_conf[8]; 1981 struct cmd_config_rss_reta *res = parsed_result; 1982 1983 memset(&dev_info, 0, sizeof(dev_info)); 1984 rte_eth_dev_info_get(res->port_id, &dev_info); 1985 if (dev_info.reta_size == 0) { 1986 printf("Redirection table size is 0 which is " 1987 "invalid for RSS\n"); 1988 return; 1989 } else 1990 printf("The reta size of port %d is %u\n", 1991 res->port_id, dev_info.reta_size); 1992 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) { 1993 printf("Currently do not support more than %u entries of " 1994 "redirection table\n", ETH_RSS_RETA_SIZE_512); 1995 return; 1996 } 1997 1998 memset(reta_conf, 0, sizeof(reta_conf)); 1999 if (!strcmp(res->list_name, "reta")) { 2000 if (parse_reta_config(res->list_of_items, reta_conf, 2001 dev_info.reta_size)) { 2002 printf("Invalid RSS Redirection Table " 2003 "config entered\n"); 2004 return; 2005 } 2006 ret = rte_eth_dev_rss_reta_update(res->port_id, 2007 reta_conf, dev_info.reta_size); 2008 if (ret != 0) 2009 printf("Bad redirection table parameter, " 2010 "return code = %d \n", ret); 2011 } 2012 } 2013 2014 cmdline_parse_token_string_t cmd_config_rss_reta_port = 2015 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2016 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2017 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2018 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2019 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); 2020 cmdline_parse_token_string_t cmd_config_rss_reta_name = 2021 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2022 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2023 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2024 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2025 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2026 NULL); 2027 cmdline_parse_inst_t cmd_config_rss_reta = { 2028 .f = cmd_set_rss_reta_parsed, 2029 .data = NULL, 2030 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2031 .tokens = { 2032 (void *)&cmd_config_rss_reta_port, 2033 (void *)&cmd_config_rss_reta_keyword, 2034 (void *)&cmd_config_rss_reta_port_id, 2035 (void *)&cmd_config_rss_reta_name, 2036 (void *)&cmd_config_rss_reta_list_name, 2037 (void *)&cmd_config_rss_reta_list_of_items, 2038 NULL, 2039 }, 2040 }; 2041 2042 /* *** SHOW PORT RETA INFO *** */ 2043 struct cmd_showport_reta { 2044 cmdline_fixed_string_t show; 2045 cmdline_fixed_string_t port; 2046 uint8_t port_id; 2047 cmdline_fixed_string_t rss; 2048 cmdline_fixed_string_t reta; 2049 uint16_t size; 2050 cmdline_fixed_string_t list_of_items; 2051 }; 2052 2053 static int 2054 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2055 uint16_t nb_entries, 2056 char *str) 2057 { 2058 uint32_t size; 2059 const char *p, *p0 = str; 2060 char s[256]; 2061 char *end; 2062 char *str_fld[8]; 2063 uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE; 2064 int ret; 2065 2066 p = strchr(p0, '('); 2067 if (p == NULL) 2068 return -1; 2069 p++; 2070 p0 = strchr(p, ')'); 2071 if (p0 == NULL) 2072 return -1; 2073 size = p0 - p; 2074 if (size >= sizeof(s)) { 2075 printf("The string size exceeds the internal buffer size\n"); 2076 return -1; 2077 } 2078 snprintf(s, sizeof(s), "%.*s", size, p); 2079 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 2080 if (ret <= 0 || ret != num) { 2081 printf("The bits of masks do not match the number of " 2082 "reta entries: %u\n", num); 2083 return -1; 2084 } 2085 for (i = 0; i < ret; i++) 2086 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0); 2087 2088 return 0; 2089 } 2090 2091 static void 2092 cmd_showport_reta_parsed(void *parsed_result, 2093 __attribute__((unused)) struct cmdline *cl, 2094 __attribute__((unused)) void *data) 2095 { 2096 struct cmd_showport_reta *res = parsed_result; 2097 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2098 struct rte_eth_dev_info dev_info; 2099 2100 memset(&dev_info, 0, sizeof(dev_info)); 2101 rte_eth_dev_info_get(res->port_id, &dev_info); 2102 if (dev_info.reta_size == 0 || res->size != dev_info.reta_size || 2103 res->size > ETH_RSS_RETA_SIZE_512) { 2104 printf("Invalid redirection table size: %u\n", res->size); 2105 return; 2106 } 2107 2108 memset(reta_conf, 0, sizeof(reta_conf)); 2109 if (showport_parse_reta_config(reta_conf, res->size, 2110 res->list_of_items) < 0) { 2111 printf("Invalid string: %s for reta masks\n", 2112 res->list_of_items); 2113 return; 2114 } 2115 port_rss_reta_info(res->port_id, reta_conf, res->size); 2116 } 2117 2118 cmdline_parse_token_string_t cmd_showport_reta_show = 2119 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 2120 cmdline_parse_token_string_t cmd_showport_reta_port = 2121 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 2122 cmdline_parse_token_num_t cmd_showport_reta_port_id = 2123 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); 2124 cmdline_parse_token_string_t cmd_showport_reta_rss = 2125 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 2126 cmdline_parse_token_string_t cmd_showport_reta_reta = 2127 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 2128 cmdline_parse_token_num_t cmd_showport_reta_size = 2129 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16); 2130 cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 2131 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 2132 list_of_items, NULL); 2133 2134 cmdline_parse_inst_t cmd_showport_reta = { 2135 .f = cmd_showport_reta_parsed, 2136 .data = NULL, 2137 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 2138 .tokens = { 2139 (void *)&cmd_showport_reta_show, 2140 (void *)&cmd_showport_reta_port, 2141 (void *)&cmd_showport_reta_port_id, 2142 (void *)&cmd_showport_reta_rss, 2143 (void *)&cmd_showport_reta_reta, 2144 (void *)&cmd_showport_reta_size, 2145 (void *)&cmd_showport_reta_list_of_items, 2146 NULL, 2147 }, 2148 }; 2149 2150 /* *** Show RSS hash configuration *** */ 2151 struct cmd_showport_rss_hash { 2152 cmdline_fixed_string_t show; 2153 cmdline_fixed_string_t port; 2154 uint8_t port_id; 2155 cmdline_fixed_string_t rss_hash; 2156 cmdline_fixed_string_t rss_type; 2157 cmdline_fixed_string_t key; /* optional argument */ 2158 }; 2159 2160 static void cmd_showport_rss_hash_parsed(void *parsed_result, 2161 __attribute__((unused)) struct cmdline *cl, 2162 void *show_rss_key) 2163 { 2164 struct cmd_showport_rss_hash *res = parsed_result; 2165 2166 port_rss_hash_conf_show(res->port_id, res->rss_type, 2167 show_rss_key != NULL); 2168 } 2169 2170 cmdline_parse_token_string_t cmd_showport_rss_hash_show = 2171 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 2172 cmdline_parse_token_string_t cmd_showport_rss_hash_port = 2173 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 2174 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 2175 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8); 2176 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 2177 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 2178 "rss-hash"); 2179 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info = 2180 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type, 2181 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2182 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2183 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2184 "ipv6-tcp-ex#ipv6-udp-ex"); 2185 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 2186 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 2187 2188 cmdline_parse_inst_t cmd_showport_rss_hash = { 2189 .f = cmd_showport_rss_hash_parsed, 2190 .data = NULL, 2191 .help_str = "show port <port_id> rss-hash " 2192 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2193 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2194 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex", 2195 .tokens = { 2196 (void *)&cmd_showport_rss_hash_show, 2197 (void *)&cmd_showport_rss_hash_port, 2198 (void *)&cmd_showport_rss_hash_port_id, 2199 (void *)&cmd_showport_rss_hash_rss_hash, 2200 (void *)&cmd_showport_rss_hash_rss_hash_info, 2201 NULL, 2202 }, 2203 }; 2204 2205 cmdline_parse_inst_t cmd_showport_rss_hash_key = { 2206 .f = cmd_showport_rss_hash_parsed, 2207 .data = (void *)1, 2208 .help_str = "show port <port_id> rss-hash " 2209 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2210 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2211 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key", 2212 .tokens = { 2213 (void *)&cmd_showport_rss_hash_show, 2214 (void *)&cmd_showport_rss_hash_port, 2215 (void *)&cmd_showport_rss_hash_port_id, 2216 (void *)&cmd_showport_rss_hash_rss_hash, 2217 (void *)&cmd_showport_rss_hash_rss_hash_info, 2218 (void *)&cmd_showport_rss_hash_rss_key, 2219 NULL, 2220 }, 2221 }; 2222 2223 /* *** Configure DCB *** */ 2224 struct cmd_config_dcb { 2225 cmdline_fixed_string_t port; 2226 cmdline_fixed_string_t config; 2227 uint8_t port_id; 2228 cmdline_fixed_string_t dcb; 2229 cmdline_fixed_string_t vt; 2230 cmdline_fixed_string_t vt_en; 2231 uint8_t num_tcs; 2232 cmdline_fixed_string_t pfc; 2233 cmdline_fixed_string_t pfc_en; 2234 }; 2235 2236 static void 2237 cmd_config_dcb_parsed(void *parsed_result, 2238 __attribute__((unused)) struct cmdline *cl, 2239 __attribute__((unused)) void *data) 2240 { 2241 struct cmd_config_dcb *res = parsed_result; 2242 portid_t port_id = res->port_id; 2243 struct rte_port *port; 2244 uint8_t pfc_en; 2245 int ret; 2246 2247 port = &ports[port_id]; 2248 /** Check if the port is not started **/ 2249 if (port->port_status != RTE_PORT_STOPPED) { 2250 printf("Please stop port %d first\n", port_id); 2251 return; 2252 } 2253 2254 if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) { 2255 printf("The invalid number of traffic class," 2256 " only 4 or 8 allowed.\n"); 2257 return; 2258 } 2259 2260 if (nb_fwd_lcores < res->num_tcs) { 2261 printf("nb_cores shouldn't be less than number of TCs.\n"); 2262 return; 2263 } 2264 if (!strncmp(res->pfc_en, "on", 2)) 2265 pfc_en = 1; 2266 else 2267 pfc_en = 0; 2268 2269 /* DCB in VT mode */ 2270 if (!strncmp(res->vt_en, "on", 2)) 2271 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 2272 (enum rte_eth_nb_tcs)res->num_tcs, 2273 pfc_en); 2274 else 2275 ret = init_port_dcb_config(port_id, DCB_ENABLED, 2276 (enum rte_eth_nb_tcs)res->num_tcs, 2277 pfc_en); 2278 2279 2280 if (ret != 0) { 2281 printf("Cannot initialize network ports.\n"); 2282 return; 2283 } 2284 2285 cmd_reconfig_device_queue(port_id, 1, 1); 2286 } 2287 2288 cmdline_parse_token_string_t cmd_config_dcb_port = 2289 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 2290 cmdline_parse_token_string_t cmd_config_dcb_config = 2291 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 2292 cmdline_parse_token_num_t cmd_config_dcb_port_id = 2293 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); 2294 cmdline_parse_token_string_t cmd_config_dcb_dcb = 2295 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 2296 cmdline_parse_token_string_t cmd_config_dcb_vt = 2297 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 2298 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 2299 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 2300 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 2301 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 2302 cmdline_parse_token_string_t cmd_config_dcb_pfc= 2303 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 2304 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 2305 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 2306 2307 cmdline_parse_inst_t cmd_config_dcb = { 2308 .f = cmd_config_dcb_parsed, 2309 .data = NULL, 2310 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 2311 .tokens = { 2312 (void *)&cmd_config_dcb_port, 2313 (void *)&cmd_config_dcb_config, 2314 (void *)&cmd_config_dcb_port_id, 2315 (void *)&cmd_config_dcb_dcb, 2316 (void *)&cmd_config_dcb_vt, 2317 (void *)&cmd_config_dcb_vt_en, 2318 (void *)&cmd_config_dcb_num_tcs, 2319 (void *)&cmd_config_dcb_pfc, 2320 (void *)&cmd_config_dcb_pfc_en, 2321 NULL, 2322 }, 2323 }; 2324 2325 /* *** configure number of packets per burst *** */ 2326 struct cmd_config_burst { 2327 cmdline_fixed_string_t port; 2328 cmdline_fixed_string_t keyword; 2329 cmdline_fixed_string_t all; 2330 cmdline_fixed_string_t name; 2331 uint16_t value; 2332 }; 2333 2334 static void 2335 cmd_config_burst_parsed(void *parsed_result, 2336 __attribute__((unused)) struct cmdline *cl, 2337 __attribute__((unused)) void *data) 2338 { 2339 struct cmd_config_burst *res = parsed_result; 2340 2341 if (!all_ports_stopped()) { 2342 printf("Please stop all ports first\n"); 2343 return; 2344 } 2345 2346 if (!strcmp(res->name, "burst")) { 2347 if (res->value < 1 || res->value > MAX_PKT_BURST) { 2348 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 2349 return; 2350 } 2351 nb_pkt_per_burst = res->value; 2352 } else { 2353 printf("Unknown parameter\n"); 2354 return; 2355 } 2356 2357 init_port_config(); 2358 2359 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2360 } 2361 2362 cmdline_parse_token_string_t cmd_config_burst_port = 2363 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 2364 cmdline_parse_token_string_t cmd_config_burst_keyword = 2365 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 2366 cmdline_parse_token_string_t cmd_config_burst_all = 2367 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 2368 cmdline_parse_token_string_t cmd_config_burst_name = 2369 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 2370 cmdline_parse_token_num_t cmd_config_burst_value = 2371 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 2372 2373 cmdline_parse_inst_t cmd_config_burst = { 2374 .f = cmd_config_burst_parsed, 2375 .data = NULL, 2376 .help_str = "port config all burst <value>", 2377 .tokens = { 2378 (void *)&cmd_config_burst_port, 2379 (void *)&cmd_config_burst_keyword, 2380 (void *)&cmd_config_burst_all, 2381 (void *)&cmd_config_burst_name, 2382 (void *)&cmd_config_burst_value, 2383 NULL, 2384 }, 2385 }; 2386 2387 /* *** configure rx/tx queues *** */ 2388 struct cmd_config_thresh { 2389 cmdline_fixed_string_t port; 2390 cmdline_fixed_string_t keyword; 2391 cmdline_fixed_string_t all; 2392 cmdline_fixed_string_t name; 2393 uint8_t value; 2394 }; 2395 2396 static void 2397 cmd_config_thresh_parsed(void *parsed_result, 2398 __attribute__((unused)) struct cmdline *cl, 2399 __attribute__((unused)) void *data) 2400 { 2401 struct cmd_config_thresh *res = parsed_result; 2402 2403 if (!all_ports_stopped()) { 2404 printf("Please stop all ports first\n"); 2405 return; 2406 } 2407 2408 if (!strcmp(res->name, "txpt")) 2409 tx_pthresh = res->value; 2410 else if(!strcmp(res->name, "txht")) 2411 tx_hthresh = res->value; 2412 else if(!strcmp(res->name, "txwt")) 2413 tx_wthresh = res->value; 2414 else if(!strcmp(res->name, "rxpt")) 2415 rx_pthresh = res->value; 2416 else if(!strcmp(res->name, "rxht")) 2417 rx_hthresh = res->value; 2418 else if(!strcmp(res->name, "rxwt")) 2419 rx_wthresh = 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_thresh_port = 2431 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 2432 cmdline_parse_token_string_t cmd_config_thresh_keyword = 2433 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 2434 cmdline_parse_token_string_t cmd_config_thresh_all = 2435 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 2436 cmdline_parse_token_string_t cmd_config_thresh_name = 2437 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 2438 "txpt#txht#txwt#rxpt#rxht#rxwt"); 2439 cmdline_parse_token_num_t cmd_config_thresh_value = 2440 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 2441 2442 cmdline_parse_inst_t cmd_config_thresh = { 2443 .f = cmd_config_thresh_parsed, 2444 .data = NULL, 2445 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 2446 .tokens = { 2447 (void *)&cmd_config_thresh_port, 2448 (void *)&cmd_config_thresh_keyword, 2449 (void *)&cmd_config_thresh_all, 2450 (void *)&cmd_config_thresh_name, 2451 (void *)&cmd_config_thresh_value, 2452 NULL, 2453 }, 2454 }; 2455 2456 /* *** configure free/rs threshold *** */ 2457 struct cmd_config_threshold { 2458 cmdline_fixed_string_t port; 2459 cmdline_fixed_string_t keyword; 2460 cmdline_fixed_string_t all; 2461 cmdline_fixed_string_t name; 2462 uint16_t value; 2463 }; 2464 2465 static void 2466 cmd_config_threshold_parsed(void *parsed_result, 2467 __attribute__((unused)) struct cmdline *cl, 2468 __attribute__((unused)) void *data) 2469 { 2470 struct cmd_config_threshold *res = parsed_result; 2471 2472 if (!all_ports_stopped()) { 2473 printf("Please stop all ports first\n"); 2474 return; 2475 } 2476 2477 if (!strcmp(res->name, "txfreet")) 2478 tx_free_thresh = res->value; 2479 else if (!strcmp(res->name, "txrst")) 2480 tx_rs_thresh = res->value; 2481 else if (!strcmp(res->name, "rxfreet")) 2482 rx_free_thresh = res->value; 2483 else { 2484 printf("Unknown parameter\n"); 2485 return; 2486 } 2487 2488 init_port_config(); 2489 2490 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2491 } 2492 2493 cmdline_parse_token_string_t cmd_config_threshold_port = 2494 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 2495 cmdline_parse_token_string_t cmd_config_threshold_keyword = 2496 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 2497 "config"); 2498 cmdline_parse_token_string_t cmd_config_threshold_all = 2499 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 2500 cmdline_parse_token_string_t cmd_config_threshold_name = 2501 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 2502 "txfreet#txrst#rxfreet"); 2503 cmdline_parse_token_num_t cmd_config_threshold_value = 2504 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 2505 2506 cmdline_parse_inst_t cmd_config_threshold = { 2507 .f = cmd_config_threshold_parsed, 2508 .data = NULL, 2509 .help_str = "port config all txfreet|txrst|rxfreet <value>", 2510 .tokens = { 2511 (void *)&cmd_config_threshold_port, 2512 (void *)&cmd_config_threshold_keyword, 2513 (void *)&cmd_config_threshold_all, 2514 (void *)&cmd_config_threshold_name, 2515 (void *)&cmd_config_threshold_value, 2516 NULL, 2517 }, 2518 }; 2519 2520 /* *** stop *** */ 2521 struct cmd_stop_result { 2522 cmdline_fixed_string_t stop; 2523 }; 2524 2525 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 2526 __attribute__((unused)) struct cmdline *cl, 2527 __attribute__((unused)) void *data) 2528 { 2529 stop_packet_forwarding(); 2530 } 2531 2532 cmdline_parse_token_string_t cmd_stop_stop = 2533 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 2534 2535 cmdline_parse_inst_t cmd_stop = { 2536 .f = cmd_stop_parsed, 2537 .data = NULL, 2538 .help_str = "stop: Stop packet forwarding", 2539 .tokens = { 2540 (void *)&cmd_stop_stop, 2541 NULL, 2542 }, 2543 }; 2544 2545 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 2546 2547 unsigned int 2548 parse_item_list(char* str, const char* item_name, unsigned int max_items, 2549 unsigned int *parsed_items, int check_unique_values) 2550 { 2551 unsigned int nb_item; 2552 unsigned int value; 2553 unsigned int i; 2554 unsigned int j; 2555 int value_ok; 2556 char c; 2557 2558 /* 2559 * First parse all items in the list and store their value. 2560 */ 2561 value = 0; 2562 nb_item = 0; 2563 value_ok = 0; 2564 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 2565 c = str[i]; 2566 if ((c >= '0') && (c <= '9')) { 2567 value = (unsigned int) (value * 10 + (c - '0')); 2568 value_ok = 1; 2569 continue; 2570 } 2571 if (c != ',') { 2572 printf("character %c is not a decimal digit\n", c); 2573 return 0; 2574 } 2575 if (! value_ok) { 2576 printf("No valid value before comma\n"); 2577 return 0; 2578 } 2579 if (nb_item < max_items) { 2580 parsed_items[nb_item] = value; 2581 value_ok = 0; 2582 value = 0; 2583 } 2584 nb_item++; 2585 } 2586 if (nb_item >= max_items) { 2587 printf("Number of %s = %u > %u (maximum items)\n", 2588 item_name, nb_item + 1, max_items); 2589 return 0; 2590 } 2591 parsed_items[nb_item++] = value; 2592 if (! check_unique_values) 2593 return nb_item; 2594 2595 /* 2596 * Then, check that all values in the list are differents. 2597 * No optimization here... 2598 */ 2599 for (i = 0; i < nb_item; i++) { 2600 for (j = i + 1; j < nb_item; j++) { 2601 if (parsed_items[j] == parsed_items[i]) { 2602 printf("duplicated %s %u at index %u and %u\n", 2603 item_name, parsed_items[i], i, j); 2604 return 0; 2605 } 2606 } 2607 } 2608 return nb_item; 2609 } 2610 2611 struct cmd_set_list_result { 2612 cmdline_fixed_string_t cmd_keyword; 2613 cmdline_fixed_string_t list_name; 2614 cmdline_fixed_string_t list_of_items; 2615 }; 2616 2617 static void cmd_set_list_parsed(void *parsed_result, 2618 __attribute__((unused)) struct cmdline *cl, 2619 __attribute__((unused)) void *data) 2620 { 2621 struct cmd_set_list_result *res; 2622 union { 2623 unsigned int lcorelist[RTE_MAX_LCORE]; 2624 unsigned int portlist[RTE_MAX_ETHPORTS]; 2625 } parsed_items; 2626 unsigned int nb_item; 2627 2628 if (test_done == 0) { 2629 printf("Please stop forwarding first\n"); 2630 return; 2631 } 2632 2633 res = parsed_result; 2634 if (!strcmp(res->list_name, "corelist")) { 2635 nb_item = parse_item_list(res->list_of_items, "core", 2636 RTE_MAX_LCORE, 2637 parsed_items.lcorelist, 1); 2638 if (nb_item > 0) { 2639 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 2640 fwd_config_setup(); 2641 } 2642 return; 2643 } 2644 if (!strcmp(res->list_name, "portlist")) { 2645 nb_item = parse_item_list(res->list_of_items, "port", 2646 RTE_MAX_ETHPORTS, 2647 parsed_items.portlist, 1); 2648 if (nb_item > 0) { 2649 set_fwd_ports_list(parsed_items.portlist, nb_item); 2650 fwd_config_setup(); 2651 } 2652 } 2653 } 2654 2655 cmdline_parse_token_string_t cmd_set_list_keyword = 2656 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 2657 "set"); 2658 cmdline_parse_token_string_t cmd_set_list_name = 2659 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 2660 "corelist#portlist"); 2661 cmdline_parse_token_string_t cmd_set_list_of_items = 2662 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 2663 NULL); 2664 2665 cmdline_parse_inst_t cmd_set_fwd_list = { 2666 .f = cmd_set_list_parsed, 2667 .data = NULL, 2668 .help_str = "set corelist|portlist <list0[,list1]*>", 2669 .tokens = { 2670 (void *)&cmd_set_list_keyword, 2671 (void *)&cmd_set_list_name, 2672 (void *)&cmd_set_list_of_items, 2673 NULL, 2674 }, 2675 }; 2676 2677 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 2678 2679 struct cmd_setmask_result { 2680 cmdline_fixed_string_t set; 2681 cmdline_fixed_string_t mask; 2682 uint64_t hexavalue; 2683 }; 2684 2685 static void cmd_set_mask_parsed(void *parsed_result, 2686 __attribute__((unused)) struct cmdline *cl, 2687 __attribute__((unused)) void *data) 2688 { 2689 struct cmd_setmask_result *res = parsed_result; 2690 2691 if (test_done == 0) { 2692 printf("Please stop forwarding first\n"); 2693 return; 2694 } 2695 if (!strcmp(res->mask, "coremask")) { 2696 set_fwd_lcores_mask(res->hexavalue); 2697 fwd_config_setup(); 2698 } else if (!strcmp(res->mask, "portmask")) { 2699 set_fwd_ports_mask(res->hexavalue); 2700 fwd_config_setup(); 2701 } 2702 } 2703 2704 cmdline_parse_token_string_t cmd_setmask_set = 2705 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 2706 cmdline_parse_token_string_t cmd_setmask_mask = 2707 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 2708 "coremask#portmask"); 2709 cmdline_parse_token_num_t cmd_setmask_value = 2710 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 2711 2712 cmdline_parse_inst_t cmd_set_fwd_mask = { 2713 .f = cmd_set_mask_parsed, 2714 .data = NULL, 2715 .help_str = "set coremask|portmask <hexadecimal value>", 2716 .tokens = { 2717 (void *)&cmd_setmask_set, 2718 (void *)&cmd_setmask_mask, 2719 (void *)&cmd_setmask_value, 2720 NULL, 2721 }, 2722 }; 2723 2724 /* 2725 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 2726 */ 2727 struct cmd_set_result { 2728 cmdline_fixed_string_t set; 2729 cmdline_fixed_string_t what; 2730 uint16_t value; 2731 }; 2732 2733 static void cmd_set_parsed(void *parsed_result, 2734 __attribute__((unused)) struct cmdline *cl, 2735 __attribute__((unused)) void *data) 2736 { 2737 struct cmd_set_result *res = parsed_result; 2738 if (!strcmp(res->what, "nbport")) { 2739 set_fwd_ports_number(res->value); 2740 fwd_config_setup(); 2741 } else if (!strcmp(res->what, "nbcore")) { 2742 set_fwd_lcores_number(res->value); 2743 fwd_config_setup(); 2744 } else if (!strcmp(res->what, "burst")) 2745 set_nb_pkt_per_burst(res->value); 2746 else if (!strcmp(res->what, "verbose")) 2747 set_verbose_level(res->value); 2748 } 2749 2750 cmdline_parse_token_string_t cmd_set_set = 2751 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 2752 cmdline_parse_token_string_t cmd_set_what = 2753 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 2754 "nbport#nbcore#burst#verbose"); 2755 cmdline_parse_token_num_t cmd_set_value = 2756 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 2757 2758 cmdline_parse_inst_t cmd_set_numbers = { 2759 .f = cmd_set_parsed, 2760 .data = NULL, 2761 .help_str = "set nbport|nbcore|burst|verbose <value>", 2762 .tokens = { 2763 (void *)&cmd_set_set, 2764 (void *)&cmd_set_what, 2765 (void *)&cmd_set_value, 2766 NULL, 2767 }, 2768 }; 2769 2770 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 2771 2772 struct cmd_set_txpkts_result { 2773 cmdline_fixed_string_t cmd_keyword; 2774 cmdline_fixed_string_t txpkts; 2775 cmdline_fixed_string_t seg_lengths; 2776 }; 2777 2778 static void 2779 cmd_set_txpkts_parsed(void *parsed_result, 2780 __attribute__((unused)) struct cmdline *cl, 2781 __attribute__((unused)) void *data) 2782 { 2783 struct cmd_set_txpkts_result *res; 2784 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 2785 unsigned int nb_segs; 2786 2787 res = parsed_result; 2788 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 2789 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 2790 if (nb_segs > 0) 2791 set_tx_pkt_segments(seg_lengths, nb_segs); 2792 } 2793 2794 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 2795 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2796 cmd_keyword, "set"); 2797 cmdline_parse_token_string_t cmd_set_txpkts_name = 2798 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2799 txpkts, "txpkts"); 2800 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 2801 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2802 seg_lengths, NULL); 2803 2804 cmdline_parse_inst_t cmd_set_txpkts = { 2805 .f = cmd_set_txpkts_parsed, 2806 .data = NULL, 2807 .help_str = "set txpkts <len0[,len1]*>", 2808 .tokens = { 2809 (void *)&cmd_set_txpkts_keyword, 2810 (void *)&cmd_set_txpkts_name, 2811 (void *)&cmd_set_txpkts_lengths, 2812 NULL, 2813 }, 2814 }; 2815 2816 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 2817 2818 struct cmd_set_txsplit_result { 2819 cmdline_fixed_string_t cmd_keyword; 2820 cmdline_fixed_string_t txsplit; 2821 cmdline_fixed_string_t mode; 2822 }; 2823 2824 static void 2825 cmd_set_txsplit_parsed(void *parsed_result, 2826 __attribute__((unused)) struct cmdline *cl, 2827 __attribute__((unused)) void *data) 2828 { 2829 struct cmd_set_txsplit_result *res; 2830 2831 res = parsed_result; 2832 set_tx_pkt_split(res->mode); 2833 } 2834 2835 cmdline_parse_token_string_t cmd_set_txsplit_keyword = 2836 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2837 cmd_keyword, "set"); 2838 cmdline_parse_token_string_t cmd_set_txsplit_name = 2839 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2840 txsplit, "txsplit"); 2841 cmdline_parse_token_string_t cmd_set_txsplit_mode = 2842 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2843 mode, NULL); 2844 2845 cmdline_parse_inst_t cmd_set_txsplit = { 2846 .f = cmd_set_txsplit_parsed, 2847 .data = NULL, 2848 .help_str = "set txsplit on|off|rand", 2849 .tokens = { 2850 (void *)&cmd_set_txsplit_keyword, 2851 (void *)&cmd_set_txsplit_name, 2852 (void *)&cmd_set_txsplit_mode, 2853 NULL, 2854 }, 2855 }; 2856 2857 /* *** CONFIG TX QUEUE FLAGS *** */ 2858 2859 struct cmd_config_txqflags_result { 2860 cmdline_fixed_string_t port; 2861 cmdline_fixed_string_t config; 2862 cmdline_fixed_string_t all; 2863 cmdline_fixed_string_t what; 2864 int32_t hexvalue; 2865 }; 2866 2867 static void cmd_config_txqflags_parsed(void *parsed_result, 2868 __attribute__((unused)) struct cmdline *cl, 2869 __attribute__((unused)) void *data) 2870 { 2871 struct cmd_config_txqflags_result *res = parsed_result; 2872 2873 if (!all_ports_stopped()) { 2874 printf("Please stop all ports first\n"); 2875 return; 2876 } 2877 2878 if (strcmp(res->what, "txqflags")) { 2879 printf("Unknown parameter\n"); 2880 return; 2881 } 2882 2883 if (res->hexvalue >= 0) { 2884 txq_flags = res->hexvalue; 2885 } else { 2886 printf("txqflags must be >= 0\n"); 2887 return; 2888 } 2889 2890 init_port_config(); 2891 2892 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2893 } 2894 2895 cmdline_parse_token_string_t cmd_config_txqflags_port = 2896 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port, 2897 "port"); 2898 cmdline_parse_token_string_t cmd_config_txqflags_config = 2899 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config, 2900 "config"); 2901 cmdline_parse_token_string_t cmd_config_txqflags_all = 2902 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all, 2903 "all"); 2904 cmdline_parse_token_string_t cmd_config_txqflags_what = 2905 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what, 2906 "txqflags"); 2907 cmdline_parse_token_num_t cmd_config_txqflags_value = 2908 TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result, 2909 hexvalue, INT32); 2910 2911 cmdline_parse_inst_t cmd_config_txqflags = { 2912 .f = cmd_config_txqflags_parsed, 2913 .data = NULL, 2914 .help_str = "port config all txqflags <value>", 2915 .tokens = { 2916 (void *)&cmd_config_txqflags_port, 2917 (void *)&cmd_config_txqflags_config, 2918 (void *)&cmd_config_txqflags_all, 2919 (void *)&cmd_config_txqflags_what, 2920 (void *)&cmd_config_txqflags_value, 2921 NULL, 2922 }, 2923 }; 2924 2925 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 2926 struct cmd_rx_vlan_filter_all_result { 2927 cmdline_fixed_string_t rx_vlan; 2928 cmdline_fixed_string_t what; 2929 cmdline_fixed_string_t all; 2930 uint8_t port_id; 2931 }; 2932 2933 static void 2934 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 2935 __attribute__((unused)) struct cmdline *cl, 2936 __attribute__((unused)) void *data) 2937 { 2938 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 2939 2940 if (!strcmp(res->what, "add")) 2941 rx_vlan_all_filter_set(res->port_id, 1); 2942 else 2943 rx_vlan_all_filter_set(res->port_id, 0); 2944 } 2945 2946 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 2947 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2948 rx_vlan, "rx_vlan"); 2949 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 2950 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2951 what, "add#rm"); 2952 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 2953 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2954 all, "all"); 2955 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 2956 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2957 port_id, UINT8); 2958 2959 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 2960 .f = cmd_rx_vlan_filter_all_parsed, 2961 .data = NULL, 2962 .help_str = "rx_vlan add|rm all <port_id>: " 2963 "Add/Remove all identifiers to/from the set of VLAN " 2964 "identifiers filtered by a port", 2965 .tokens = { 2966 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 2967 (void *)&cmd_rx_vlan_filter_all_what, 2968 (void *)&cmd_rx_vlan_filter_all_all, 2969 (void *)&cmd_rx_vlan_filter_all_portid, 2970 NULL, 2971 }, 2972 }; 2973 2974 /* *** VLAN OFFLOAD SET ON A PORT *** */ 2975 struct cmd_vlan_offload_result { 2976 cmdline_fixed_string_t vlan; 2977 cmdline_fixed_string_t set; 2978 cmdline_fixed_string_t vlan_type; 2979 cmdline_fixed_string_t what; 2980 cmdline_fixed_string_t on; 2981 cmdline_fixed_string_t port_id; 2982 }; 2983 2984 static void 2985 cmd_vlan_offload_parsed(void *parsed_result, 2986 __attribute__((unused)) struct cmdline *cl, 2987 __attribute__((unused)) void *data) 2988 { 2989 int on; 2990 struct cmd_vlan_offload_result *res = parsed_result; 2991 char *str; 2992 int i, len = 0; 2993 portid_t port_id = 0; 2994 unsigned int tmp; 2995 2996 str = res->port_id; 2997 len = strnlen(str, STR_TOKEN_SIZE); 2998 i = 0; 2999 /* Get port_id first */ 3000 while(i < len){ 3001 if(str[i] == ',') 3002 break; 3003 3004 i++; 3005 } 3006 str[i]='\0'; 3007 tmp = strtoul(str, NULL, 0); 3008 /* If port_id greater that what portid_t can represent, return */ 3009 if(tmp >= RTE_MAX_ETHPORTS) 3010 return; 3011 port_id = (portid_t)tmp; 3012 3013 if (!strcmp(res->on, "on")) 3014 on = 1; 3015 else 3016 on = 0; 3017 3018 if (!strcmp(res->what, "strip")) 3019 rx_vlan_strip_set(port_id, on); 3020 else if(!strcmp(res->what, "stripq")){ 3021 uint16_t queue_id = 0; 3022 3023 /* No queue_id, return */ 3024 if(i + 1 >= len) { 3025 printf("must specify (port,queue_id)\n"); 3026 return; 3027 } 3028 tmp = strtoul(str + i + 1, NULL, 0); 3029 /* If queue_id greater that what 16-bits can represent, return */ 3030 if(tmp > 0xffff) 3031 return; 3032 3033 queue_id = (uint16_t)tmp; 3034 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 3035 } 3036 else if (!strcmp(res->what, "filter")) 3037 rx_vlan_filter_set(port_id, on); 3038 else 3039 vlan_extend_set(port_id, on); 3040 3041 return; 3042 } 3043 3044 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 3045 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3046 vlan, "vlan"); 3047 cmdline_parse_token_string_t cmd_vlan_offload_set = 3048 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3049 set, "set"); 3050 cmdline_parse_token_string_t cmd_vlan_offload_what = 3051 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3052 what, "strip#filter#qinq#stripq"); 3053 cmdline_parse_token_string_t cmd_vlan_offload_on = 3054 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3055 on, "on#off"); 3056 cmdline_parse_token_string_t cmd_vlan_offload_portid = 3057 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3058 port_id, NULL); 3059 3060 cmdline_parse_inst_t cmd_vlan_offload = { 3061 .f = cmd_vlan_offload_parsed, 3062 .data = NULL, 3063 .help_str = "vlan set strip|filter|qinq|stripq on|off " 3064 "<port_id[,queue_id]>: " 3065 "Filter/Strip for rx side qinq(extended) for both rx/tx sides", 3066 .tokens = { 3067 (void *)&cmd_vlan_offload_vlan, 3068 (void *)&cmd_vlan_offload_set, 3069 (void *)&cmd_vlan_offload_what, 3070 (void *)&cmd_vlan_offload_on, 3071 (void *)&cmd_vlan_offload_portid, 3072 NULL, 3073 }, 3074 }; 3075 3076 /* *** VLAN TPID SET ON A PORT *** */ 3077 struct cmd_vlan_tpid_result { 3078 cmdline_fixed_string_t vlan; 3079 cmdline_fixed_string_t set; 3080 cmdline_fixed_string_t vlan_type; 3081 cmdline_fixed_string_t what; 3082 uint16_t tp_id; 3083 uint8_t port_id; 3084 }; 3085 3086 static void 3087 cmd_vlan_tpid_parsed(void *parsed_result, 3088 __attribute__((unused)) struct cmdline *cl, 3089 __attribute__((unused)) void *data) 3090 { 3091 struct cmd_vlan_tpid_result *res = parsed_result; 3092 enum rte_vlan_type vlan_type; 3093 3094 if (!strcmp(res->vlan_type, "inner")) 3095 vlan_type = ETH_VLAN_TYPE_INNER; 3096 else if (!strcmp(res->vlan_type, "outer")) 3097 vlan_type = ETH_VLAN_TYPE_OUTER; 3098 else { 3099 printf("Unknown vlan type\n"); 3100 return; 3101 } 3102 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 3103 } 3104 3105 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 3106 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3107 vlan, "vlan"); 3108 cmdline_parse_token_string_t cmd_vlan_tpid_set = 3109 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3110 set, "set"); 3111 cmdline_parse_token_string_t cmd_vlan_type = 3112 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3113 vlan_type, "inner#outer"); 3114 cmdline_parse_token_string_t cmd_vlan_tpid_what = 3115 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3116 what, "tpid"); 3117 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 3118 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3119 tp_id, UINT16); 3120 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 3121 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3122 port_id, UINT8); 3123 3124 cmdline_parse_inst_t cmd_vlan_tpid = { 3125 .f = cmd_vlan_tpid_parsed, 3126 .data = NULL, 3127 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 3128 "Set the VLAN Ether type", 3129 .tokens = { 3130 (void *)&cmd_vlan_tpid_vlan, 3131 (void *)&cmd_vlan_tpid_set, 3132 (void *)&cmd_vlan_type, 3133 (void *)&cmd_vlan_tpid_what, 3134 (void *)&cmd_vlan_tpid_tpid, 3135 (void *)&cmd_vlan_tpid_portid, 3136 NULL, 3137 }, 3138 }; 3139 3140 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 3141 struct cmd_rx_vlan_filter_result { 3142 cmdline_fixed_string_t rx_vlan; 3143 cmdline_fixed_string_t what; 3144 uint16_t vlan_id; 3145 uint8_t port_id; 3146 }; 3147 3148 static void 3149 cmd_rx_vlan_filter_parsed(void *parsed_result, 3150 __attribute__((unused)) struct cmdline *cl, 3151 __attribute__((unused)) void *data) 3152 { 3153 struct cmd_rx_vlan_filter_result *res = parsed_result; 3154 3155 if (!strcmp(res->what, "add")) 3156 rx_vft_set(res->port_id, res->vlan_id, 1); 3157 else 3158 rx_vft_set(res->port_id, res->vlan_id, 0); 3159 } 3160 3161 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 3162 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3163 rx_vlan, "rx_vlan"); 3164 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 3165 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3166 what, "add#rm"); 3167 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 3168 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3169 vlan_id, UINT16); 3170 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 3171 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3172 port_id, UINT8); 3173 3174 cmdline_parse_inst_t cmd_rx_vlan_filter = { 3175 .f = cmd_rx_vlan_filter_parsed, 3176 .data = NULL, 3177 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 3178 "Add/Remove a VLAN identifier to/from the set of VLAN " 3179 "identifiers filtered by a port", 3180 .tokens = { 3181 (void *)&cmd_rx_vlan_filter_rx_vlan, 3182 (void *)&cmd_rx_vlan_filter_what, 3183 (void *)&cmd_rx_vlan_filter_vlanid, 3184 (void *)&cmd_rx_vlan_filter_portid, 3185 NULL, 3186 }, 3187 }; 3188 3189 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3190 struct cmd_tx_vlan_set_result { 3191 cmdline_fixed_string_t tx_vlan; 3192 cmdline_fixed_string_t set; 3193 uint8_t port_id; 3194 uint16_t vlan_id; 3195 }; 3196 3197 static void 3198 cmd_tx_vlan_set_parsed(void *parsed_result, 3199 __attribute__((unused)) struct cmdline *cl, 3200 __attribute__((unused)) void *data) 3201 { 3202 struct cmd_tx_vlan_set_result *res = parsed_result; 3203 3204 tx_vlan_set(res->port_id, res->vlan_id); 3205 } 3206 3207 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 3208 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3209 tx_vlan, "tx_vlan"); 3210 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 3211 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3212 set, "set"); 3213 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 3214 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3215 port_id, UINT8); 3216 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 3217 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3218 vlan_id, UINT16); 3219 3220 cmdline_parse_inst_t cmd_tx_vlan_set = { 3221 .f = cmd_tx_vlan_set_parsed, 3222 .data = NULL, 3223 .help_str = "tx_vlan set <port_id> <vlan_id>: " 3224 "Enable hardware insertion of a single VLAN header " 3225 "with a given TAG Identifier in packets sent on a port", 3226 .tokens = { 3227 (void *)&cmd_tx_vlan_set_tx_vlan, 3228 (void *)&cmd_tx_vlan_set_set, 3229 (void *)&cmd_tx_vlan_set_portid, 3230 (void *)&cmd_tx_vlan_set_vlanid, 3231 NULL, 3232 }, 3233 }; 3234 3235 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 3236 struct cmd_tx_vlan_set_qinq_result { 3237 cmdline_fixed_string_t tx_vlan; 3238 cmdline_fixed_string_t set; 3239 uint8_t port_id; 3240 uint16_t vlan_id; 3241 uint16_t vlan_id_outer; 3242 }; 3243 3244 static void 3245 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 3246 __attribute__((unused)) struct cmdline *cl, 3247 __attribute__((unused)) void *data) 3248 { 3249 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 3250 3251 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 3252 } 3253 3254 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 3255 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3256 tx_vlan, "tx_vlan"); 3257 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 3258 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3259 set, "set"); 3260 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 3261 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3262 port_id, UINT8); 3263 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 3264 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3265 vlan_id, UINT16); 3266 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 3267 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3268 vlan_id_outer, UINT16); 3269 3270 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 3271 .f = cmd_tx_vlan_set_qinq_parsed, 3272 .data = NULL, 3273 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 3274 "Enable hardware insertion of double VLAN header " 3275 "with given TAG Identifiers in packets sent on a port", 3276 .tokens = { 3277 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 3278 (void *)&cmd_tx_vlan_set_qinq_set, 3279 (void *)&cmd_tx_vlan_set_qinq_portid, 3280 (void *)&cmd_tx_vlan_set_qinq_vlanid, 3281 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 3282 NULL, 3283 }, 3284 }; 3285 3286 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 3287 struct cmd_tx_vlan_set_pvid_result { 3288 cmdline_fixed_string_t tx_vlan; 3289 cmdline_fixed_string_t set; 3290 cmdline_fixed_string_t pvid; 3291 uint8_t port_id; 3292 uint16_t vlan_id; 3293 cmdline_fixed_string_t mode; 3294 }; 3295 3296 static void 3297 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 3298 __attribute__((unused)) struct cmdline *cl, 3299 __attribute__((unused)) void *data) 3300 { 3301 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 3302 3303 if (strcmp(res->mode, "on") == 0) 3304 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 3305 else 3306 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 3307 } 3308 3309 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 3310 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3311 tx_vlan, "tx_vlan"); 3312 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 3313 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3314 set, "set"); 3315 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 3316 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3317 pvid, "pvid"); 3318 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 3319 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3320 port_id, UINT8); 3321 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 3322 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3323 vlan_id, UINT16); 3324 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 3325 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3326 mode, "on#off"); 3327 3328 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 3329 .f = cmd_tx_vlan_set_pvid_parsed, 3330 .data = NULL, 3331 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 3332 .tokens = { 3333 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 3334 (void *)&cmd_tx_vlan_set_pvid_set, 3335 (void *)&cmd_tx_vlan_set_pvid_pvid, 3336 (void *)&cmd_tx_vlan_set_pvid_port_id, 3337 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 3338 (void *)&cmd_tx_vlan_set_pvid_mode, 3339 NULL, 3340 }, 3341 }; 3342 3343 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3344 struct cmd_tx_vlan_reset_result { 3345 cmdline_fixed_string_t tx_vlan; 3346 cmdline_fixed_string_t reset; 3347 uint8_t port_id; 3348 }; 3349 3350 static void 3351 cmd_tx_vlan_reset_parsed(void *parsed_result, 3352 __attribute__((unused)) struct cmdline *cl, 3353 __attribute__((unused)) void *data) 3354 { 3355 struct cmd_tx_vlan_reset_result *res = parsed_result; 3356 3357 tx_vlan_reset(res->port_id); 3358 } 3359 3360 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 3361 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3362 tx_vlan, "tx_vlan"); 3363 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 3364 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3365 reset, "reset"); 3366 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 3367 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 3368 port_id, UINT8); 3369 3370 cmdline_parse_inst_t cmd_tx_vlan_reset = { 3371 .f = cmd_tx_vlan_reset_parsed, 3372 .data = NULL, 3373 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 3374 "VLAN header in packets sent on a port", 3375 .tokens = { 3376 (void *)&cmd_tx_vlan_reset_tx_vlan, 3377 (void *)&cmd_tx_vlan_reset_reset, 3378 (void *)&cmd_tx_vlan_reset_portid, 3379 NULL, 3380 }, 3381 }; 3382 3383 3384 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 3385 struct cmd_csum_result { 3386 cmdline_fixed_string_t csum; 3387 cmdline_fixed_string_t mode; 3388 cmdline_fixed_string_t proto; 3389 cmdline_fixed_string_t hwsw; 3390 uint8_t port_id; 3391 }; 3392 3393 static void 3394 csum_show(int port_id) 3395 { 3396 struct rte_eth_dev_info dev_info; 3397 uint16_t ol_flags; 3398 3399 ol_flags = ports[port_id].tx_ol_flags; 3400 printf("Parse tunnel is %s\n", 3401 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off"); 3402 printf("IP checksum offload is %s\n", 3403 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw"); 3404 printf("UDP checksum offload is %s\n", 3405 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 3406 printf("TCP checksum offload is %s\n", 3407 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 3408 printf("SCTP checksum offload is %s\n", 3409 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 3410 printf("Outer-Ip checksum offload is %s\n", 3411 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw"); 3412 3413 /* display warnings if configuration is not supported by the NIC */ 3414 rte_eth_dev_info_get(port_id, &dev_info); 3415 if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) && 3416 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) { 3417 printf("Warning: hardware IP checksum enabled but not " 3418 "supported by port %d\n", port_id); 3419 } 3420 if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) && 3421 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) { 3422 printf("Warning: hardware UDP checksum enabled but not " 3423 "supported by port %d\n", port_id); 3424 } 3425 if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) && 3426 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) { 3427 printf("Warning: hardware TCP checksum enabled but not " 3428 "supported by port %d\n", port_id); 3429 } 3430 if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) && 3431 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) { 3432 printf("Warning: hardware SCTP checksum enabled but not " 3433 "supported by port %d\n", port_id); 3434 } 3435 if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) && 3436 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 3437 printf("Warning: hardware outer IP checksum enabled but not " 3438 "supported by port %d\n", port_id); 3439 } 3440 } 3441 3442 static void 3443 cmd_csum_parsed(void *parsed_result, 3444 __attribute__((unused)) struct cmdline *cl, 3445 __attribute__((unused)) void *data) 3446 { 3447 struct cmd_csum_result *res = parsed_result; 3448 int hw = 0; 3449 uint16_t mask = 0; 3450 3451 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 3452 printf("invalid port %d\n", res->port_id); 3453 return; 3454 } 3455 3456 if (!strcmp(res->mode, "set")) { 3457 3458 if (!strcmp(res->hwsw, "hw")) 3459 hw = 1; 3460 3461 if (!strcmp(res->proto, "ip")) { 3462 mask = TESTPMD_TX_OFFLOAD_IP_CKSUM; 3463 } else if (!strcmp(res->proto, "udp")) { 3464 mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM; 3465 } else if (!strcmp(res->proto, "tcp")) { 3466 mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM; 3467 } else if (!strcmp(res->proto, "sctp")) { 3468 mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM; 3469 } else if (!strcmp(res->proto, "outer-ip")) { 3470 mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM; 3471 } 3472 3473 if (hw) 3474 ports[res->port_id].tx_ol_flags |= mask; 3475 else 3476 ports[res->port_id].tx_ol_flags &= (~mask); 3477 } 3478 csum_show(res->port_id); 3479 } 3480 3481 cmdline_parse_token_string_t cmd_csum_csum = 3482 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3483 csum, "csum"); 3484 cmdline_parse_token_string_t cmd_csum_mode = 3485 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3486 mode, "set"); 3487 cmdline_parse_token_string_t cmd_csum_proto = 3488 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3489 proto, "ip#tcp#udp#sctp#outer-ip"); 3490 cmdline_parse_token_string_t cmd_csum_hwsw = 3491 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3492 hwsw, "hw#sw"); 3493 cmdline_parse_token_num_t cmd_csum_portid = 3494 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 3495 port_id, UINT8); 3496 3497 cmdline_parse_inst_t cmd_csum_set = { 3498 .f = cmd_csum_parsed, 3499 .data = NULL, 3500 .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: " 3501 "Enable/Disable hardware calculation of L3/L4 checksum when " 3502 "using csum forward engine", 3503 .tokens = { 3504 (void *)&cmd_csum_csum, 3505 (void *)&cmd_csum_mode, 3506 (void *)&cmd_csum_proto, 3507 (void *)&cmd_csum_hwsw, 3508 (void *)&cmd_csum_portid, 3509 NULL, 3510 }, 3511 }; 3512 3513 cmdline_parse_token_string_t cmd_csum_mode_show = 3514 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3515 mode, "show"); 3516 3517 cmdline_parse_inst_t cmd_csum_show = { 3518 .f = cmd_csum_parsed, 3519 .data = NULL, 3520 .help_str = "csum show <port_id>: Show checksum offload configuration", 3521 .tokens = { 3522 (void *)&cmd_csum_csum, 3523 (void *)&cmd_csum_mode_show, 3524 (void *)&cmd_csum_portid, 3525 NULL, 3526 }, 3527 }; 3528 3529 /* Enable/disable tunnel parsing */ 3530 struct cmd_csum_tunnel_result { 3531 cmdline_fixed_string_t csum; 3532 cmdline_fixed_string_t parse; 3533 cmdline_fixed_string_t onoff; 3534 uint8_t port_id; 3535 }; 3536 3537 static void 3538 cmd_csum_tunnel_parsed(void *parsed_result, 3539 __attribute__((unused)) struct cmdline *cl, 3540 __attribute__((unused)) void *data) 3541 { 3542 struct cmd_csum_tunnel_result *res = parsed_result; 3543 3544 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3545 return; 3546 3547 if (!strcmp(res->onoff, "on")) 3548 ports[res->port_id].tx_ol_flags |= 3549 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL; 3550 else 3551 ports[res->port_id].tx_ol_flags &= 3552 (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL); 3553 3554 csum_show(res->port_id); 3555 } 3556 3557 cmdline_parse_token_string_t cmd_csum_tunnel_csum = 3558 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3559 csum, "csum"); 3560 cmdline_parse_token_string_t cmd_csum_tunnel_parse = 3561 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3562 parse, "parse_tunnel"); 3563 cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 3564 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3565 onoff, "on#off"); 3566 cmdline_parse_token_num_t cmd_csum_tunnel_portid = 3567 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 3568 port_id, UINT8); 3569 3570 cmdline_parse_inst_t cmd_csum_tunnel = { 3571 .f = cmd_csum_tunnel_parsed, 3572 .data = NULL, 3573 .help_str = "csum parse_tunnel on|off <port_id>: " 3574 "Enable/Disable parsing of tunnels for csum engine", 3575 .tokens = { 3576 (void *)&cmd_csum_tunnel_csum, 3577 (void *)&cmd_csum_tunnel_parse, 3578 (void *)&cmd_csum_tunnel_onoff, 3579 (void *)&cmd_csum_tunnel_portid, 3580 NULL, 3581 }, 3582 }; 3583 3584 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 3585 struct cmd_tso_set_result { 3586 cmdline_fixed_string_t tso; 3587 cmdline_fixed_string_t mode; 3588 uint16_t tso_segsz; 3589 uint8_t port_id; 3590 }; 3591 3592 static void 3593 cmd_tso_set_parsed(void *parsed_result, 3594 __attribute__((unused)) struct cmdline *cl, 3595 __attribute__((unused)) void *data) 3596 { 3597 struct cmd_tso_set_result *res = parsed_result; 3598 struct rte_eth_dev_info dev_info; 3599 3600 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3601 return; 3602 3603 if (!strcmp(res->mode, "set")) 3604 ports[res->port_id].tso_segsz = res->tso_segsz; 3605 3606 if (ports[res->port_id].tso_segsz == 0) 3607 printf("TSO for non-tunneled packets is disabled\n"); 3608 else 3609 printf("TSO segment size for non-tunneled packets is %d\n", 3610 ports[res->port_id].tso_segsz); 3611 3612 /* display warnings if configuration is not supported by the NIC */ 3613 rte_eth_dev_info_get(res->port_id, &dev_info); 3614 if ((ports[res->port_id].tso_segsz != 0) && 3615 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3616 printf("Warning: TSO enabled but not " 3617 "supported by port %d\n", res->port_id); 3618 } 3619 } 3620 3621 cmdline_parse_token_string_t cmd_tso_set_tso = 3622 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3623 tso, "tso"); 3624 cmdline_parse_token_string_t cmd_tso_set_mode = 3625 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3626 mode, "set"); 3627 cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 3628 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3629 tso_segsz, UINT16); 3630 cmdline_parse_token_num_t cmd_tso_set_portid = 3631 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3632 port_id, UINT8); 3633 3634 cmdline_parse_inst_t cmd_tso_set = { 3635 .f = cmd_tso_set_parsed, 3636 .data = NULL, 3637 .help_str = "tso set <tso_segsz> <port_id>: " 3638 "Set TSO segment size of non-tunneled packets for csum engine " 3639 "(0 to disable)", 3640 .tokens = { 3641 (void *)&cmd_tso_set_tso, 3642 (void *)&cmd_tso_set_mode, 3643 (void *)&cmd_tso_set_tso_segsz, 3644 (void *)&cmd_tso_set_portid, 3645 NULL, 3646 }, 3647 }; 3648 3649 cmdline_parse_token_string_t cmd_tso_show_mode = 3650 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3651 mode, "show"); 3652 3653 3654 cmdline_parse_inst_t cmd_tso_show = { 3655 .f = cmd_tso_set_parsed, 3656 .data = NULL, 3657 .help_str = "tso show <port_id>: " 3658 "Show TSO segment size of non-tunneled packets for csum engine", 3659 .tokens = { 3660 (void *)&cmd_tso_set_tso, 3661 (void *)&cmd_tso_show_mode, 3662 (void *)&cmd_tso_set_portid, 3663 NULL, 3664 }, 3665 }; 3666 3667 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 3668 struct cmd_tunnel_tso_set_result { 3669 cmdline_fixed_string_t tso; 3670 cmdline_fixed_string_t mode; 3671 uint16_t tso_segsz; 3672 uint8_t port_id; 3673 }; 3674 3675 static void 3676 check_tunnel_tso_nic_support(uint8_t port_id) 3677 { 3678 struct rte_eth_dev_info dev_info; 3679 3680 rte_eth_dev_info_get(port_id, &dev_info); 3681 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) 3682 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not " 3683 "supported by port %d\n", port_id); 3684 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO)) 3685 printf("Warning: TSO enabled but GRE TUNNEL TSO not " 3686 "supported by port %d\n", port_id); 3687 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO)) 3688 printf("Warning: TSO enabled but IPIP TUNNEL TSO not " 3689 "supported by port %d\n", port_id); 3690 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) 3691 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not " 3692 "supported by port %d\n", port_id); 3693 } 3694 3695 static void 3696 cmd_tunnel_tso_set_parsed(void *parsed_result, 3697 __attribute__((unused)) struct cmdline *cl, 3698 __attribute__((unused)) void *data) 3699 { 3700 struct cmd_tunnel_tso_set_result *res = parsed_result; 3701 3702 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3703 return; 3704 3705 if (!strcmp(res->mode, "set")) 3706 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 3707 3708 if (ports[res->port_id].tunnel_tso_segsz == 0) 3709 printf("TSO for tunneled packets is disabled\n"); 3710 else { 3711 printf("TSO segment size for tunneled packets is %d\n", 3712 ports[res->port_id].tunnel_tso_segsz); 3713 3714 /* Below conditions are needed to make it work: 3715 * (1) tunnel TSO is supported by the NIC; 3716 * (2) "csum parse_tunnel" must be set so that tunneled pkts 3717 * are recognized; 3718 * (3) for tunneled pkts with outer L3 of IPv4, 3719 * "csum set outer-ip" must be set to hw, because after tso, 3720 * total_len of outer IP header is changed, and the checksum 3721 * of outer IP header calculated by sw should be wrong; that 3722 * is not necessary for IPv6 tunneled pkts because there's no 3723 * checksum in IP header anymore. 3724 */ 3725 check_tunnel_tso_nic_support(res->port_id); 3726 3727 if (!(ports[res->port_id].tx_ol_flags & 3728 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL)) 3729 printf("Warning: csum parse_tunnel must be set " 3730 "so that tunneled packets are recognized\n"); 3731 if (!(ports[res->port_id].tx_ol_flags & 3732 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)) 3733 printf("Warning: csum set outer-ip must be set to hw " 3734 "if outer L3 is IPv4; not necessary for IPv6\n"); 3735 } 3736 } 3737 3738 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 3739 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3740 tso, "tunnel_tso"); 3741 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 3742 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3743 mode, "set"); 3744 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 3745 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3746 tso_segsz, UINT16); 3747 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 3748 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3749 port_id, UINT8); 3750 3751 cmdline_parse_inst_t cmd_tunnel_tso_set = { 3752 .f = cmd_tunnel_tso_set_parsed, 3753 .data = NULL, 3754 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 3755 "Set TSO segment size of tunneled packets for csum engine " 3756 "(0 to disable)", 3757 .tokens = { 3758 (void *)&cmd_tunnel_tso_set_tso, 3759 (void *)&cmd_tunnel_tso_set_mode, 3760 (void *)&cmd_tunnel_tso_set_tso_segsz, 3761 (void *)&cmd_tunnel_tso_set_portid, 3762 NULL, 3763 }, 3764 }; 3765 3766 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 3767 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3768 mode, "show"); 3769 3770 3771 cmdline_parse_inst_t cmd_tunnel_tso_show = { 3772 .f = cmd_tunnel_tso_set_parsed, 3773 .data = NULL, 3774 .help_str = "tunnel_tso show <port_id> " 3775 "Show TSO segment size of tunneled packets for csum engine", 3776 .tokens = { 3777 (void *)&cmd_tunnel_tso_set_tso, 3778 (void *)&cmd_tunnel_tso_show_mode, 3779 (void *)&cmd_tunnel_tso_set_portid, 3780 NULL, 3781 }, 3782 }; 3783 3784 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 3785 struct cmd_set_flush_rx { 3786 cmdline_fixed_string_t set; 3787 cmdline_fixed_string_t flush_rx; 3788 cmdline_fixed_string_t mode; 3789 }; 3790 3791 static void 3792 cmd_set_flush_rx_parsed(void *parsed_result, 3793 __attribute__((unused)) struct cmdline *cl, 3794 __attribute__((unused)) void *data) 3795 { 3796 struct cmd_set_flush_rx *res = parsed_result; 3797 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 3798 } 3799 3800 cmdline_parse_token_string_t cmd_setflushrx_set = 3801 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3802 set, "set"); 3803 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 3804 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3805 flush_rx, "flush_rx"); 3806 cmdline_parse_token_string_t cmd_setflushrx_mode = 3807 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3808 mode, "on#off"); 3809 3810 3811 cmdline_parse_inst_t cmd_set_flush_rx = { 3812 .f = cmd_set_flush_rx_parsed, 3813 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 3814 .data = NULL, 3815 .tokens = { 3816 (void *)&cmd_setflushrx_set, 3817 (void *)&cmd_setflushrx_flush_rx, 3818 (void *)&cmd_setflushrx_mode, 3819 NULL, 3820 }, 3821 }; 3822 3823 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 3824 struct cmd_set_link_check { 3825 cmdline_fixed_string_t set; 3826 cmdline_fixed_string_t link_check; 3827 cmdline_fixed_string_t mode; 3828 }; 3829 3830 static void 3831 cmd_set_link_check_parsed(void *parsed_result, 3832 __attribute__((unused)) struct cmdline *cl, 3833 __attribute__((unused)) void *data) 3834 { 3835 struct cmd_set_link_check *res = parsed_result; 3836 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 3837 } 3838 3839 cmdline_parse_token_string_t cmd_setlinkcheck_set = 3840 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3841 set, "set"); 3842 cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 3843 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3844 link_check, "link_check"); 3845 cmdline_parse_token_string_t cmd_setlinkcheck_mode = 3846 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3847 mode, "on#off"); 3848 3849 3850 cmdline_parse_inst_t cmd_set_link_check = { 3851 .f = cmd_set_link_check_parsed, 3852 .help_str = "set link_check on|off: Enable/Disable link status check " 3853 "when starting/stopping a port", 3854 .data = NULL, 3855 .tokens = { 3856 (void *)&cmd_setlinkcheck_set, 3857 (void *)&cmd_setlinkcheck_link_check, 3858 (void *)&cmd_setlinkcheck_mode, 3859 NULL, 3860 }, 3861 }; 3862 3863 #ifdef RTE_NIC_BYPASS 3864 /* *** SET NIC BYPASS MODE *** */ 3865 struct cmd_set_bypass_mode_result { 3866 cmdline_fixed_string_t set; 3867 cmdline_fixed_string_t bypass; 3868 cmdline_fixed_string_t mode; 3869 cmdline_fixed_string_t value; 3870 uint8_t port_id; 3871 }; 3872 3873 static void 3874 cmd_set_bypass_mode_parsed(void *parsed_result, 3875 __attribute__((unused)) struct cmdline *cl, 3876 __attribute__((unused)) void *data) 3877 { 3878 struct cmd_set_bypass_mode_result *res = parsed_result; 3879 portid_t port_id = res->port_id; 3880 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 3881 3882 if (!strcmp(res->value, "bypass")) 3883 bypass_mode = RTE_BYPASS_MODE_BYPASS; 3884 else if (!strcmp(res->value, "isolate")) 3885 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 3886 else 3887 bypass_mode = RTE_BYPASS_MODE_NORMAL; 3888 3889 /* Set the bypass mode for the relevant port. */ 3890 if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) { 3891 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 3892 } 3893 } 3894 3895 cmdline_parse_token_string_t cmd_setbypass_mode_set = 3896 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3897 set, "set"); 3898 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 3899 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3900 bypass, "bypass"); 3901 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 3902 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3903 mode, "mode"); 3904 cmdline_parse_token_string_t cmd_setbypass_mode_value = 3905 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3906 value, "normal#bypass#isolate"); 3907 cmdline_parse_token_num_t cmd_setbypass_mode_port = 3908 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 3909 port_id, UINT8); 3910 3911 cmdline_parse_inst_t cmd_set_bypass_mode = { 3912 .f = cmd_set_bypass_mode_parsed, 3913 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 3914 "Set the NIC bypass mode for port_id", 3915 .data = NULL, 3916 .tokens = { 3917 (void *)&cmd_setbypass_mode_set, 3918 (void *)&cmd_setbypass_mode_bypass, 3919 (void *)&cmd_setbypass_mode_mode, 3920 (void *)&cmd_setbypass_mode_value, 3921 (void *)&cmd_setbypass_mode_port, 3922 NULL, 3923 }, 3924 }; 3925 3926 /* *** SET NIC BYPASS EVENT *** */ 3927 struct cmd_set_bypass_event_result { 3928 cmdline_fixed_string_t set; 3929 cmdline_fixed_string_t bypass; 3930 cmdline_fixed_string_t event; 3931 cmdline_fixed_string_t event_value; 3932 cmdline_fixed_string_t mode; 3933 cmdline_fixed_string_t mode_value; 3934 uint8_t port_id; 3935 }; 3936 3937 static void 3938 cmd_set_bypass_event_parsed(void *parsed_result, 3939 __attribute__((unused)) struct cmdline *cl, 3940 __attribute__((unused)) void *data) 3941 { 3942 int32_t rc; 3943 struct cmd_set_bypass_event_result *res = parsed_result; 3944 portid_t port_id = res->port_id; 3945 uint32_t bypass_event = RTE_BYPASS_EVENT_NONE; 3946 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 3947 3948 if (!strcmp(res->event_value, "timeout")) 3949 bypass_event = RTE_BYPASS_EVENT_TIMEOUT; 3950 else if (!strcmp(res->event_value, "os_on")) 3951 bypass_event = RTE_BYPASS_EVENT_OS_ON; 3952 else if (!strcmp(res->event_value, "os_off")) 3953 bypass_event = RTE_BYPASS_EVENT_OS_OFF; 3954 else if (!strcmp(res->event_value, "power_on")) 3955 bypass_event = RTE_BYPASS_EVENT_POWER_ON; 3956 else if (!strcmp(res->event_value, "power_off")) 3957 bypass_event = RTE_BYPASS_EVENT_POWER_OFF; 3958 else 3959 bypass_event = RTE_BYPASS_EVENT_NONE; 3960 3961 if (!strcmp(res->mode_value, "bypass")) 3962 bypass_mode = RTE_BYPASS_MODE_BYPASS; 3963 else if (!strcmp(res->mode_value, "isolate")) 3964 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 3965 else 3966 bypass_mode = RTE_BYPASS_MODE_NORMAL; 3967 3968 /* Set the watchdog timeout. */ 3969 if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) { 3970 3971 rc = -EINVAL; 3972 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) || 3973 (rc = rte_eth_dev_wd_timeout_store(port_id, 3974 bypass_timeout)) != 0) { 3975 printf("Failed to set timeout value %u " 3976 "for port %d, errto code: %d.\n", 3977 bypass_timeout, port_id, rc); 3978 } 3979 } 3980 3981 /* Set the bypass event to transition to bypass mode. */ 3982 if (0 != rte_eth_dev_bypass_event_store(port_id, 3983 bypass_event, bypass_mode)) { 3984 printf("\t Failed to set bypass event for port = %d.\n", port_id); 3985 } 3986 3987 } 3988 3989 cmdline_parse_token_string_t cmd_setbypass_event_set = 3990 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 3991 set, "set"); 3992 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 3993 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 3994 bypass, "bypass"); 3995 cmdline_parse_token_string_t cmd_setbypass_event_event = 3996 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 3997 event, "event"); 3998 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 3999 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4000 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 4001 cmdline_parse_token_string_t cmd_setbypass_event_mode = 4002 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4003 mode, "mode"); 4004 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 4005 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4006 mode_value, "normal#bypass#isolate"); 4007 cmdline_parse_token_num_t cmd_setbypass_event_port = 4008 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 4009 port_id, UINT8); 4010 4011 cmdline_parse_inst_t cmd_set_bypass_event = { 4012 .f = cmd_set_bypass_event_parsed, 4013 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 4014 "power_off mode normal|bypass|isolate <port_id>: " 4015 "Set the NIC bypass event mode for port_id", 4016 .data = NULL, 4017 .tokens = { 4018 (void *)&cmd_setbypass_event_set, 4019 (void *)&cmd_setbypass_event_bypass, 4020 (void *)&cmd_setbypass_event_event, 4021 (void *)&cmd_setbypass_event_event_value, 4022 (void *)&cmd_setbypass_event_mode, 4023 (void *)&cmd_setbypass_event_mode_value, 4024 (void *)&cmd_setbypass_event_port, 4025 NULL, 4026 }, 4027 }; 4028 4029 4030 /* *** SET NIC BYPASS TIMEOUT *** */ 4031 struct cmd_set_bypass_timeout_result { 4032 cmdline_fixed_string_t set; 4033 cmdline_fixed_string_t bypass; 4034 cmdline_fixed_string_t timeout; 4035 cmdline_fixed_string_t value; 4036 }; 4037 4038 static void 4039 cmd_set_bypass_timeout_parsed(void *parsed_result, 4040 __attribute__((unused)) struct cmdline *cl, 4041 __attribute__((unused)) void *data) 4042 { 4043 struct cmd_set_bypass_timeout_result *res = parsed_result; 4044 4045 if (!strcmp(res->value, "1.5")) 4046 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC; 4047 else if (!strcmp(res->value, "2")) 4048 bypass_timeout = RTE_BYPASS_TMT_2_SEC; 4049 else if (!strcmp(res->value, "3")) 4050 bypass_timeout = RTE_BYPASS_TMT_3_SEC; 4051 else if (!strcmp(res->value, "4")) 4052 bypass_timeout = RTE_BYPASS_TMT_4_SEC; 4053 else if (!strcmp(res->value, "8")) 4054 bypass_timeout = RTE_BYPASS_TMT_8_SEC; 4055 else if (!strcmp(res->value, "16")) 4056 bypass_timeout = RTE_BYPASS_TMT_16_SEC; 4057 else if (!strcmp(res->value, "32")) 4058 bypass_timeout = RTE_BYPASS_TMT_32_SEC; 4059 else 4060 bypass_timeout = RTE_BYPASS_TMT_OFF; 4061 } 4062 4063 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 4064 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4065 set, "set"); 4066 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 4067 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4068 bypass, "bypass"); 4069 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 4070 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4071 timeout, "timeout"); 4072 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 4073 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4074 value, "0#1.5#2#3#4#8#16#32"); 4075 4076 cmdline_parse_inst_t cmd_set_bypass_timeout = { 4077 .f = cmd_set_bypass_timeout_parsed, 4078 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 4079 "Set the NIC bypass watchdog timeout in seconds", 4080 .data = NULL, 4081 .tokens = { 4082 (void *)&cmd_setbypass_timeout_set, 4083 (void *)&cmd_setbypass_timeout_bypass, 4084 (void *)&cmd_setbypass_timeout_timeout, 4085 (void *)&cmd_setbypass_timeout_value, 4086 NULL, 4087 }, 4088 }; 4089 4090 /* *** SHOW NIC BYPASS MODE *** */ 4091 struct cmd_show_bypass_config_result { 4092 cmdline_fixed_string_t show; 4093 cmdline_fixed_string_t bypass; 4094 cmdline_fixed_string_t config; 4095 uint8_t port_id; 4096 }; 4097 4098 static void 4099 cmd_show_bypass_config_parsed(void *parsed_result, 4100 __attribute__((unused)) struct cmdline *cl, 4101 __attribute__((unused)) void *data) 4102 { 4103 struct cmd_show_bypass_config_result *res = parsed_result; 4104 uint32_t event_mode; 4105 uint32_t bypass_mode; 4106 portid_t port_id = res->port_id; 4107 uint32_t timeout = bypass_timeout; 4108 int i; 4109 4110 static const char * const timeouts[RTE_BYPASS_TMT_NUM] = 4111 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 4112 static const char * const modes[RTE_BYPASS_MODE_NUM] = 4113 {"UNKNOWN", "normal", "bypass", "isolate"}; 4114 static const char * const events[RTE_BYPASS_EVENT_NUM] = { 4115 "NONE", 4116 "OS/board on", 4117 "power supply on", 4118 "OS/board off", 4119 "power supply off", 4120 "timeout"}; 4121 int num_events = (sizeof events) / (sizeof events[0]); 4122 4123 /* Display the bypass mode.*/ 4124 if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) { 4125 printf("\tFailed to get bypass mode for port = %d\n", port_id); 4126 return; 4127 } 4128 else { 4129 if (!RTE_BYPASS_MODE_VALID(bypass_mode)) 4130 bypass_mode = RTE_BYPASS_MODE_NONE; 4131 4132 printf("\tbypass mode = %s\n", modes[bypass_mode]); 4133 } 4134 4135 /* Display the bypass timeout.*/ 4136 if (!RTE_BYPASS_TMT_VALID(timeout)) 4137 timeout = RTE_BYPASS_TMT_OFF; 4138 4139 printf("\tbypass timeout = %s\n", timeouts[timeout]); 4140 4141 /* Display the bypass events and associated modes. */ 4142 for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) { 4143 4144 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) { 4145 printf("\tFailed to get bypass mode for event = %s\n", 4146 events[i]); 4147 } else { 4148 if (!RTE_BYPASS_MODE_VALID(event_mode)) 4149 event_mode = RTE_BYPASS_MODE_NONE; 4150 4151 printf("\tbypass event: %-16s = %s\n", events[i], 4152 modes[event_mode]); 4153 } 4154 } 4155 } 4156 4157 cmdline_parse_token_string_t cmd_showbypass_config_show = 4158 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4159 show, "show"); 4160 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 4161 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4162 bypass, "bypass"); 4163 cmdline_parse_token_string_t cmd_showbypass_config_config = 4164 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4165 config, "config"); 4166 cmdline_parse_token_num_t cmd_showbypass_config_port = 4167 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 4168 port_id, UINT8); 4169 4170 cmdline_parse_inst_t cmd_show_bypass_config = { 4171 .f = cmd_show_bypass_config_parsed, 4172 .help_str = "show bypass config <port_id>: " 4173 "Show the NIC bypass config for port_id", 4174 .data = NULL, 4175 .tokens = { 4176 (void *)&cmd_showbypass_config_show, 4177 (void *)&cmd_showbypass_config_bypass, 4178 (void *)&cmd_showbypass_config_config, 4179 (void *)&cmd_showbypass_config_port, 4180 NULL, 4181 }, 4182 }; 4183 #endif 4184 4185 #ifdef RTE_LIBRTE_PMD_BOND 4186 /* *** SET BONDING MODE *** */ 4187 struct cmd_set_bonding_mode_result { 4188 cmdline_fixed_string_t set; 4189 cmdline_fixed_string_t bonding; 4190 cmdline_fixed_string_t mode; 4191 uint8_t value; 4192 uint8_t port_id; 4193 }; 4194 4195 static void cmd_set_bonding_mode_parsed(void *parsed_result, 4196 __attribute__((unused)) struct cmdline *cl, 4197 __attribute__((unused)) void *data) 4198 { 4199 struct cmd_set_bonding_mode_result *res = parsed_result; 4200 portid_t port_id = res->port_id; 4201 4202 /* Set the bonding mode for the relevant port. */ 4203 if (0 != rte_eth_bond_mode_set(port_id, res->value)) 4204 printf("\t Failed to set bonding mode for port = %d.\n", port_id); 4205 } 4206 4207 cmdline_parse_token_string_t cmd_setbonding_mode_set = 4208 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4209 set, "set"); 4210 cmdline_parse_token_string_t cmd_setbonding_mode_bonding = 4211 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4212 bonding, "bonding"); 4213 cmdline_parse_token_string_t cmd_setbonding_mode_mode = 4214 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4215 mode, "mode"); 4216 cmdline_parse_token_num_t cmd_setbonding_mode_value = 4217 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4218 value, UINT8); 4219 cmdline_parse_token_num_t cmd_setbonding_mode_port = 4220 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4221 port_id, UINT8); 4222 4223 cmdline_parse_inst_t cmd_set_bonding_mode = { 4224 .f = cmd_set_bonding_mode_parsed, 4225 .help_str = "set bonding mode <mode_value> <port_id>: " 4226 "Set the bonding mode for port_id", 4227 .data = NULL, 4228 .tokens = { 4229 (void *) &cmd_setbonding_mode_set, 4230 (void *) &cmd_setbonding_mode_bonding, 4231 (void *) &cmd_setbonding_mode_mode, 4232 (void *) &cmd_setbonding_mode_value, 4233 (void *) &cmd_setbonding_mode_port, 4234 NULL 4235 } 4236 }; 4237 4238 /* *** SET BALANCE XMIT POLICY *** */ 4239 struct cmd_set_bonding_balance_xmit_policy_result { 4240 cmdline_fixed_string_t set; 4241 cmdline_fixed_string_t bonding; 4242 cmdline_fixed_string_t balance_xmit_policy; 4243 uint8_t port_id; 4244 cmdline_fixed_string_t policy; 4245 }; 4246 4247 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, 4248 __attribute__((unused)) struct cmdline *cl, 4249 __attribute__((unused)) void *data) 4250 { 4251 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; 4252 portid_t port_id = res->port_id; 4253 uint8_t policy; 4254 4255 if (!strcmp(res->policy, "l2")) { 4256 policy = BALANCE_XMIT_POLICY_LAYER2; 4257 } else if (!strcmp(res->policy, "l23")) { 4258 policy = BALANCE_XMIT_POLICY_LAYER23; 4259 } else if (!strcmp(res->policy, "l34")) { 4260 policy = BALANCE_XMIT_POLICY_LAYER34; 4261 } else { 4262 printf("\t Invalid xmit policy selection"); 4263 return; 4264 } 4265 4266 /* Set the bonding mode for the relevant port. */ 4267 if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { 4268 printf("\t Failed to set bonding balance xmit policy for port = %d.\n", 4269 port_id); 4270 } 4271 } 4272 4273 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = 4274 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4275 set, "set"); 4276 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = 4277 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4278 bonding, "bonding"); 4279 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = 4280 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4281 balance_xmit_policy, "balance_xmit_policy"); 4282 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = 4283 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4284 port_id, UINT8); 4285 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = 4286 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4287 policy, "l2#l23#l34"); 4288 4289 cmdline_parse_inst_t cmd_set_balance_xmit_policy = { 4290 .f = cmd_set_bonding_balance_xmit_policy_parsed, 4291 .help_str = "set bonding balance_xmit_policy <port_id> " 4292 "l2|l23|l34: " 4293 "Set the bonding balance_xmit_policy for port_id", 4294 .data = NULL, 4295 .tokens = { 4296 (void *)&cmd_setbonding_balance_xmit_policy_set, 4297 (void *)&cmd_setbonding_balance_xmit_policy_bonding, 4298 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, 4299 (void *)&cmd_setbonding_balance_xmit_policy_port, 4300 (void *)&cmd_setbonding_balance_xmit_policy_policy, 4301 NULL 4302 } 4303 }; 4304 4305 /* *** SHOW NIC BONDING CONFIGURATION *** */ 4306 struct cmd_show_bonding_config_result { 4307 cmdline_fixed_string_t show; 4308 cmdline_fixed_string_t bonding; 4309 cmdline_fixed_string_t config; 4310 uint8_t port_id; 4311 }; 4312 4313 static void cmd_show_bonding_config_parsed(void *parsed_result, 4314 __attribute__((unused)) struct cmdline *cl, 4315 __attribute__((unused)) void *data) 4316 { 4317 struct cmd_show_bonding_config_result *res = parsed_result; 4318 int bonding_mode; 4319 uint8_t slaves[RTE_MAX_ETHPORTS]; 4320 int num_slaves, num_active_slaves; 4321 int primary_id; 4322 int i; 4323 portid_t port_id = res->port_id; 4324 4325 /* Display the bonding mode.*/ 4326 bonding_mode = rte_eth_bond_mode_get(port_id); 4327 if (bonding_mode < 0) { 4328 printf("\tFailed to get bonding mode for port = %d\n", port_id); 4329 return; 4330 } else 4331 printf("\tBonding mode: %d\n", bonding_mode); 4332 4333 if (bonding_mode == BONDING_MODE_BALANCE) { 4334 int balance_xmit_policy; 4335 4336 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); 4337 if (balance_xmit_policy < 0) { 4338 printf("\tFailed to get balance xmit policy for port = %d\n", 4339 port_id); 4340 return; 4341 } else { 4342 printf("\tBalance Xmit Policy: "); 4343 4344 switch (balance_xmit_policy) { 4345 case BALANCE_XMIT_POLICY_LAYER2: 4346 printf("BALANCE_XMIT_POLICY_LAYER2"); 4347 break; 4348 case BALANCE_XMIT_POLICY_LAYER23: 4349 printf("BALANCE_XMIT_POLICY_LAYER23"); 4350 break; 4351 case BALANCE_XMIT_POLICY_LAYER34: 4352 printf("BALANCE_XMIT_POLICY_LAYER34"); 4353 break; 4354 } 4355 printf("\n"); 4356 } 4357 } 4358 4359 num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); 4360 4361 if (num_slaves < 0) { 4362 printf("\tFailed to get slave list for port = %d\n", port_id); 4363 return; 4364 } 4365 if (num_slaves > 0) { 4366 printf("\tSlaves (%d): [", num_slaves); 4367 for (i = 0; i < num_slaves - 1; i++) 4368 printf("%d ", slaves[i]); 4369 4370 printf("%d]\n", slaves[num_slaves - 1]); 4371 } else { 4372 printf("\tSlaves: []\n"); 4373 4374 } 4375 4376 num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, 4377 RTE_MAX_ETHPORTS); 4378 4379 if (num_active_slaves < 0) { 4380 printf("\tFailed to get active slave list for port = %d\n", port_id); 4381 return; 4382 } 4383 if (num_active_slaves > 0) { 4384 printf("\tActive Slaves (%d): [", num_active_slaves); 4385 for (i = 0; i < num_active_slaves - 1; i++) 4386 printf("%d ", slaves[i]); 4387 4388 printf("%d]\n", slaves[num_active_slaves - 1]); 4389 4390 } else { 4391 printf("\tActive Slaves: []\n"); 4392 4393 } 4394 4395 primary_id = rte_eth_bond_primary_get(port_id); 4396 if (primary_id < 0) { 4397 printf("\tFailed to get primary slave for port = %d\n", port_id); 4398 return; 4399 } else 4400 printf("\tPrimary: [%d]\n", primary_id); 4401 4402 } 4403 4404 cmdline_parse_token_string_t cmd_showbonding_config_show = 4405 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4406 show, "show"); 4407 cmdline_parse_token_string_t cmd_showbonding_config_bonding = 4408 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4409 bonding, "bonding"); 4410 cmdline_parse_token_string_t cmd_showbonding_config_config = 4411 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4412 config, "config"); 4413 cmdline_parse_token_num_t cmd_showbonding_config_port = 4414 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, 4415 port_id, UINT8); 4416 4417 cmdline_parse_inst_t cmd_show_bonding_config = { 4418 .f = cmd_show_bonding_config_parsed, 4419 .help_str = "show bonding config <port_id>: " 4420 "Show the bonding config for port_id", 4421 .data = NULL, 4422 .tokens = { 4423 (void *)&cmd_showbonding_config_show, 4424 (void *)&cmd_showbonding_config_bonding, 4425 (void *)&cmd_showbonding_config_config, 4426 (void *)&cmd_showbonding_config_port, 4427 NULL 4428 } 4429 }; 4430 4431 /* *** SET BONDING PRIMARY *** */ 4432 struct cmd_set_bonding_primary_result { 4433 cmdline_fixed_string_t set; 4434 cmdline_fixed_string_t bonding; 4435 cmdline_fixed_string_t primary; 4436 uint8_t slave_id; 4437 uint8_t port_id; 4438 }; 4439 4440 static void cmd_set_bonding_primary_parsed(void *parsed_result, 4441 __attribute__((unused)) struct cmdline *cl, 4442 __attribute__((unused)) void *data) 4443 { 4444 struct cmd_set_bonding_primary_result *res = parsed_result; 4445 portid_t master_port_id = res->port_id; 4446 portid_t slave_port_id = res->slave_id; 4447 4448 /* Set the primary slave for a bonded device. */ 4449 if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { 4450 printf("\t Failed to set primary slave for port = %d.\n", 4451 master_port_id); 4452 return; 4453 } 4454 init_port_config(); 4455 } 4456 4457 cmdline_parse_token_string_t cmd_setbonding_primary_set = 4458 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4459 set, "set"); 4460 cmdline_parse_token_string_t cmd_setbonding_primary_bonding = 4461 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4462 bonding, "bonding"); 4463 cmdline_parse_token_string_t cmd_setbonding_primary_primary = 4464 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4465 primary, "primary"); 4466 cmdline_parse_token_num_t cmd_setbonding_primary_slave = 4467 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4468 slave_id, UINT8); 4469 cmdline_parse_token_num_t cmd_setbonding_primary_port = 4470 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4471 port_id, UINT8); 4472 4473 cmdline_parse_inst_t cmd_set_bonding_primary = { 4474 .f = cmd_set_bonding_primary_parsed, 4475 .help_str = "set bonding primary <slave_id> <port_id>: " 4476 "Set the primary slave for port_id", 4477 .data = NULL, 4478 .tokens = { 4479 (void *)&cmd_setbonding_primary_set, 4480 (void *)&cmd_setbonding_primary_bonding, 4481 (void *)&cmd_setbonding_primary_primary, 4482 (void *)&cmd_setbonding_primary_slave, 4483 (void *)&cmd_setbonding_primary_port, 4484 NULL 4485 } 4486 }; 4487 4488 /* *** ADD SLAVE *** */ 4489 struct cmd_add_bonding_slave_result { 4490 cmdline_fixed_string_t add; 4491 cmdline_fixed_string_t bonding; 4492 cmdline_fixed_string_t slave; 4493 uint8_t slave_id; 4494 uint8_t port_id; 4495 }; 4496 4497 static void cmd_add_bonding_slave_parsed(void *parsed_result, 4498 __attribute__((unused)) struct cmdline *cl, 4499 __attribute__((unused)) void *data) 4500 { 4501 struct cmd_add_bonding_slave_result *res = parsed_result; 4502 portid_t master_port_id = res->port_id; 4503 portid_t slave_port_id = res->slave_id; 4504 4505 /* Set the primary slave for a bonded device. */ 4506 if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { 4507 printf("\t Failed to add slave %d to master port = %d.\n", 4508 slave_port_id, master_port_id); 4509 return; 4510 } 4511 init_port_config(); 4512 set_port_slave_flag(slave_port_id); 4513 } 4514 4515 cmdline_parse_token_string_t cmd_addbonding_slave_add = 4516 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4517 add, "add"); 4518 cmdline_parse_token_string_t cmd_addbonding_slave_bonding = 4519 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4520 bonding, "bonding"); 4521 cmdline_parse_token_string_t cmd_addbonding_slave_slave = 4522 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4523 slave, "slave"); 4524 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = 4525 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4526 slave_id, UINT8); 4527 cmdline_parse_token_num_t cmd_addbonding_slave_port = 4528 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4529 port_id, UINT8); 4530 4531 cmdline_parse_inst_t cmd_add_bonding_slave = { 4532 .f = cmd_add_bonding_slave_parsed, 4533 .help_str = "add bonding slave <slave_id> <port_id>: " 4534 "Add a slave device to a bonded device", 4535 .data = NULL, 4536 .tokens = { 4537 (void *)&cmd_addbonding_slave_add, 4538 (void *)&cmd_addbonding_slave_bonding, 4539 (void *)&cmd_addbonding_slave_slave, 4540 (void *)&cmd_addbonding_slave_slaveid, 4541 (void *)&cmd_addbonding_slave_port, 4542 NULL 4543 } 4544 }; 4545 4546 /* *** REMOVE SLAVE *** */ 4547 struct cmd_remove_bonding_slave_result { 4548 cmdline_fixed_string_t remove; 4549 cmdline_fixed_string_t bonding; 4550 cmdline_fixed_string_t slave; 4551 uint8_t slave_id; 4552 uint8_t port_id; 4553 }; 4554 4555 static void cmd_remove_bonding_slave_parsed(void *parsed_result, 4556 __attribute__((unused)) struct cmdline *cl, 4557 __attribute__((unused)) void *data) 4558 { 4559 struct cmd_remove_bonding_slave_result *res = parsed_result; 4560 portid_t master_port_id = res->port_id; 4561 portid_t slave_port_id = res->slave_id; 4562 4563 /* Set the primary slave for a bonded device. */ 4564 if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { 4565 printf("\t Failed to remove slave %d from master port = %d.\n", 4566 slave_port_id, master_port_id); 4567 return; 4568 } 4569 init_port_config(); 4570 clear_port_slave_flag(slave_port_id); 4571 } 4572 4573 cmdline_parse_token_string_t cmd_removebonding_slave_remove = 4574 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4575 remove, "remove"); 4576 cmdline_parse_token_string_t cmd_removebonding_slave_bonding = 4577 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4578 bonding, "bonding"); 4579 cmdline_parse_token_string_t cmd_removebonding_slave_slave = 4580 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4581 slave, "slave"); 4582 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = 4583 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4584 slave_id, UINT8); 4585 cmdline_parse_token_num_t cmd_removebonding_slave_port = 4586 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4587 port_id, UINT8); 4588 4589 cmdline_parse_inst_t cmd_remove_bonding_slave = { 4590 .f = cmd_remove_bonding_slave_parsed, 4591 .help_str = "remove bonding slave <slave_id> <port_id>: " 4592 "Remove a slave device from a bonded device", 4593 .data = NULL, 4594 .tokens = { 4595 (void *)&cmd_removebonding_slave_remove, 4596 (void *)&cmd_removebonding_slave_bonding, 4597 (void *)&cmd_removebonding_slave_slave, 4598 (void *)&cmd_removebonding_slave_slaveid, 4599 (void *)&cmd_removebonding_slave_port, 4600 NULL 4601 } 4602 }; 4603 4604 /* *** CREATE BONDED DEVICE *** */ 4605 struct cmd_create_bonded_device_result { 4606 cmdline_fixed_string_t create; 4607 cmdline_fixed_string_t bonded; 4608 cmdline_fixed_string_t device; 4609 uint8_t mode; 4610 uint8_t socket; 4611 }; 4612 4613 static int bond_dev_num = 0; 4614 4615 static void cmd_create_bonded_device_parsed(void *parsed_result, 4616 __attribute__((unused)) struct cmdline *cl, 4617 __attribute__((unused)) void *data) 4618 { 4619 struct cmd_create_bonded_device_result *res = parsed_result; 4620 char ethdev_name[RTE_ETH_NAME_MAX_LEN]; 4621 int port_id; 4622 4623 if (test_done == 0) { 4624 printf("Please stop forwarding first\n"); 4625 return; 4626 } 4627 4628 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d", 4629 bond_dev_num++); 4630 4631 /* Create a new bonded device. */ 4632 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); 4633 if (port_id < 0) { 4634 printf("\t Failed to create bonded device.\n"); 4635 return; 4636 } else { 4637 printf("Created new bonded device %s on (port %d).\n", ethdev_name, 4638 port_id); 4639 4640 /* Update number of ports */ 4641 nb_ports = rte_eth_dev_count(); 4642 reconfig(port_id, res->socket); 4643 rte_eth_promiscuous_enable(port_id); 4644 ports[port_id].enabled = 1; 4645 } 4646 4647 } 4648 4649 cmdline_parse_token_string_t cmd_createbonded_device_create = 4650 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4651 create, "create"); 4652 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 4653 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4654 bonded, "bonded"); 4655 cmdline_parse_token_string_t cmd_createbonded_device_device = 4656 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4657 device, "device"); 4658 cmdline_parse_token_num_t cmd_createbonded_device_mode = 4659 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4660 mode, UINT8); 4661 cmdline_parse_token_num_t cmd_createbonded_device_socket = 4662 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4663 socket, UINT8); 4664 4665 cmdline_parse_inst_t cmd_create_bonded_device = { 4666 .f = cmd_create_bonded_device_parsed, 4667 .help_str = "create bonded device <mode> <socket>: " 4668 "Create a new bonded device with specific bonding mode and socket", 4669 .data = NULL, 4670 .tokens = { 4671 (void *)&cmd_createbonded_device_create, 4672 (void *)&cmd_createbonded_device_bonded, 4673 (void *)&cmd_createbonded_device_device, 4674 (void *)&cmd_createbonded_device_mode, 4675 (void *)&cmd_createbonded_device_socket, 4676 NULL 4677 } 4678 }; 4679 4680 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 4681 struct cmd_set_bond_mac_addr_result { 4682 cmdline_fixed_string_t set; 4683 cmdline_fixed_string_t bonding; 4684 cmdline_fixed_string_t mac_addr; 4685 uint8_t port_num; 4686 struct ether_addr address; 4687 }; 4688 4689 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 4690 __attribute__((unused)) struct cmdline *cl, 4691 __attribute__((unused)) void *data) 4692 { 4693 struct cmd_set_bond_mac_addr_result *res = parsed_result; 4694 int ret; 4695 4696 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 4697 return; 4698 4699 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 4700 4701 /* check the return value and print it if is < 0 */ 4702 if (ret < 0) 4703 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4704 } 4705 4706 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 4707 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 4708 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 4709 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 4710 "bonding"); 4711 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 4712 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 4713 "mac_addr"); 4714 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 4715 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); 4716 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 4717 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 4718 4719 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 4720 .f = cmd_set_bond_mac_addr_parsed, 4721 .data = (void *) 0, 4722 .help_str = "set bonding mac_addr <port_id> <mac_addr>", 4723 .tokens = { 4724 (void *)&cmd_set_bond_mac_addr_set, 4725 (void *)&cmd_set_bond_mac_addr_bonding, 4726 (void *)&cmd_set_bond_mac_addr_mac, 4727 (void *)&cmd_set_bond_mac_addr_portnum, 4728 (void *)&cmd_set_bond_mac_addr_addr, 4729 NULL 4730 } 4731 }; 4732 4733 4734 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 4735 struct cmd_set_bond_mon_period_result { 4736 cmdline_fixed_string_t set; 4737 cmdline_fixed_string_t bonding; 4738 cmdline_fixed_string_t mon_period; 4739 uint8_t port_num; 4740 uint32_t period_ms; 4741 }; 4742 4743 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 4744 __attribute__((unused)) struct cmdline *cl, 4745 __attribute__((unused)) void *data) 4746 { 4747 struct cmd_set_bond_mon_period_result *res = parsed_result; 4748 int ret; 4749 4750 if (res->port_num >= nb_ports) { 4751 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 4752 return; 4753 } 4754 4755 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 4756 4757 /* check the return value and print it if is < 0 */ 4758 if (ret < 0) 4759 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4760 } 4761 4762 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 4763 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4764 set, "set"); 4765 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 4766 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4767 bonding, "bonding"); 4768 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 4769 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4770 mon_period, "mon_period"); 4771 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 4772 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4773 port_num, UINT8); 4774 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 4775 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4776 period_ms, UINT32); 4777 4778 cmdline_parse_inst_t cmd_set_bond_mon_period = { 4779 .f = cmd_set_bond_mon_period_parsed, 4780 .data = (void *) 0, 4781 .help_str = "set bonding mon_period <port_id> <period_ms>", 4782 .tokens = { 4783 (void *)&cmd_set_bond_mon_period_set, 4784 (void *)&cmd_set_bond_mon_period_bonding, 4785 (void *)&cmd_set_bond_mon_period_mon_period, 4786 (void *)&cmd_set_bond_mon_period_portnum, 4787 (void *)&cmd_set_bond_mon_period_period_ms, 4788 NULL 4789 } 4790 }; 4791 4792 #endif /* RTE_LIBRTE_PMD_BOND */ 4793 4794 /* *** SET FORWARDING MODE *** */ 4795 struct cmd_set_fwd_mode_result { 4796 cmdline_fixed_string_t set; 4797 cmdline_fixed_string_t fwd; 4798 cmdline_fixed_string_t mode; 4799 }; 4800 4801 static void cmd_set_fwd_mode_parsed(void *parsed_result, 4802 __attribute__((unused)) struct cmdline *cl, 4803 __attribute__((unused)) void *data) 4804 { 4805 struct cmd_set_fwd_mode_result *res = parsed_result; 4806 4807 retry_enabled = 0; 4808 set_pkt_forwarding_mode(res->mode); 4809 } 4810 4811 cmdline_parse_token_string_t cmd_setfwd_set = 4812 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 4813 cmdline_parse_token_string_t cmd_setfwd_fwd = 4814 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 4815 cmdline_parse_token_string_t cmd_setfwd_mode = 4816 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 4817 "" /* defined at init */); 4818 4819 cmdline_parse_inst_t cmd_set_fwd_mode = { 4820 .f = cmd_set_fwd_mode_parsed, 4821 .data = NULL, 4822 .help_str = NULL, /* defined at init */ 4823 .tokens = { 4824 (void *)&cmd_setfwd_set, 4825 (void *)&cmd_setfwd_fwd, 4826 (void *)&cmd_setfwd_mode, 4827 NULL, 4828 }, 4829 }; 4830 4831 static void cmd_set_fwd_mode_init(void) 4832 { 4833 char *modes, *c; 4834 static char token[128]; 4835 static char help[256]; 4836 cmdline_parse_token_string_t *token_struct; 4837 4838 modes = list_pkt_forwarding_modes(); 4839 snprintf(help, sizeof(help), "set fwd %s: " 4840 "Set packet forwarding mode", modes); 4841 cmd_set_fwd_mode.help_str = help; 4842 4843 /* string token separator is # */ 4844 for (c = token; *modes != '\0'; modes++) 4845 if (*modes == '|') 4846 *c++ = '#'; 4847 else 4848 *c++ = *modes; 4849 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 4850 token_struct->string_data.str = token; 4851 } 4852 4853 /* *** SET RETRY FORWARDING MODE *** */ 4854 struct cmd_set_fwd_retry_mode_result { 4855 cmdline_fixed_string_t set; 4856 cmdline_fixed_string_t fwd; 4857 cmdline_fixed_string_t mode; 4858 cmdline_fixed_string_t retry; 4859 }; 4860 4861 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 4862 __attribute__((unused)) struct cmdline *cl, 4863 __attribute__((unused)) void *data) 4864 { 4865 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 4866 4867 retry_enabled = 1; 4868 set_pkt_forwarding_mode(res->mode); 4869 } 4870 4871 cmdline_parse_token_string_t cmd_setfwd_retry_set = 4872 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4873 set, "set"); 4874 cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 4875 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4876 fwd, "fwd"); 4877 cmdline_parse_token_string_t cmd_setfwd_retry_mode = 4878 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4879 mode, 4880 "" /* defined at init */); 4881 cmdline_parse_token_string_t cmd_setfwd_retry_retry = 4882 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4883 retry, "retry"); 4884 4885 cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 4886 .f = cmd_set_fwd_retry_mode_parsed, 4887 .data = NULL, 4888 .help_str = NULL, /* defined at init */ 4889 .tokens = { 4890 (void *)&cmd_setfwd_retry_set, 4891 (void *)&cmd_setfwd_retry_fwd, 4892 (void *)&cmd_setfwd_retry_mode, 4893 (void *)&cmd_setfwd_retry_retry, 4894 NULL, 4895 }, 4896 }; 4897 4898 static void cmd_set_fwd_retry_mode_init(void) 4899 { 4900 char *modes, *c; 4901 static char token[128]; 4902 static char help[256]; 4903 cmdline_parse_token_string_t *token_struct; 4904 4905 modes = list_pkt_forwarding_retry_modes(); 4906 snprintf(help, sizeof(help), "set fwd %s retry: " 4907 "Set packet forwarding mode with retry", modes); 4908 cmd_set_fwd_retry_mode.help_str = help; 4909 4910 /* string token separator is # */ 4911 for (c = token; *modes != '\0'; modes++) 4912 if (*modes == '|') 4913 *c++ = '#'; 4914 else 4915 *c++ = *modes; 4916 token_struct = (cmdline_parse_token_string_t *) 4917 cmd_set_fwd_retry_mode.tokens[2]; 4918 token_struct->string_data.str = token; 4919 } 4920 4921 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 4922 struct cmd_set_burst_tx_retry_result { 4923 cmdline_fixed_string_t set; 4924 cmdline_fixed_string_t burst; 4925 cmdline_fixed_string_t tx; 4926 cmdline_fixed_string_t delay; 4927 uint32_t time; 4928 cmdline_fixed_string_t retry; 4929 uint32_t retry_num; 4930 }; 4931 4932 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 4933 __attribute__((unused)) struct cmdline *cl, 4934 __attribute__((unused)) void *data) 4935 { 4936 struct cmd_set_burst_tx_retry_result *res = parsed_result; 4937 4938 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 4939 && !strcmp(res->tx, "tx")) { 4940 if (!strcmp(res->delay, "delay")) 4941 burst_tx_delay_time = res->time; 4942 if (!strcmp(res->retry, "retry")) 4943 burst_tx_retry_num = res->retry_num; 4944 } 4945 4946 } 4947 4948 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 4949 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 4950 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 4951 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 4952 "burst"); 4953 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 4954 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 4955 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 4956 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 4957 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 4958 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 4959 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 4960 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 4961 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 4962 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 4963 4964 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 4965 .f = cmd_set_burst_tx_retry_parsed, 4966 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 4967 .tokens = { 4968 (void *)&cmd_set_burst_tx_retry_set, 4969 (void *)&cmd_set_burst_tx_retry_burst, 4970 (void *)&cmd_set_burst_tx_retry_tx, 4971 (void *)&cmd_set_burst_tx_retry_delay, 4972 (void *)&cmd_set_burst_tx_retry_time, 4973 (void *)&cmd_set_burst_tx_retry_retry, 4974 (void *)&cmd_set_burst_tx_retry_retry_num, 4975 NULL, 4976 }, 4977 }; 4978 4979 /* *** SET PROMISC MODE *** */ 4980 struct cmd_set_promisc_mode_result { 4981 cmdline_fixed_string_t set; 4982 cmdline_fixed_string_t promisc; 4983 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 4984 uint8_t port_num; /* valid if "allports" argument == 0 */ 4985 cmdline_fixed_string_t mode; 4986 }; 4987 4988 static void cmd_set_promisc_mode_parsed(void *parsed_result, 4989 __attribute__((unused)) struct cmdline *cl, 4990 void *allports) 4991 { 4992 struct cmd_set_promisc_mode_result *res = parsed_result; 4993 int enable; 4994 portid_t i; 4995 4996 if (!strcmp(res->mode, "on")) 4997 enable = 1; 4998 else 4999 enable = 0; 5000 5001 /* all ports */ 5002 if (allports) { 5003 FOREACH_PORT(i, ports) { 5004 if (enable) 5005 rte_eth_promiscuous_enable(i); 5006 else 5007 rte_eth_promiscuous_disable(i); 5008 } 5009 } 5010 else { 5011 if (enable) 5012 rte_eth_promiscuous_enable(res->port_num); 5013 else 5014 rte_eth_promiscuous_disable(res->port_num); 5015 } 5016 } 5017 5018 cmdline_parse_token_string_t cmd_setpromisc_set = 5019 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 5020 cmdline_parse_token_string_t cmd_setpromisc_promisc = 5021 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 5022 "promisc"); 5023 cmdline_parse_token_string_t cmd_setpromisc_portall = 5024 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 5025 "all"); 5026 cmdline_parse_token_num_t cmd_setpromisc_portnum = 5027 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 5028 UINT8); 5029 cmdline_parse_token_string_t cmd_setpromisc_mode = 5030 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 5031 "on#off"); 5032 5033 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 5034 .f = cmd_set_promisc_mode_parsed, 5035 .data = (void *)1, 5036 .help_str = "set promisc all on|off: Set promisc mode for all ports", 5037 .tokens = { 5038 (void *)&cmd_setpromisc_set, 5039 (void *)&cmd_setpromisc_promisc, 5040 (void *)&cmd_setpromisc_portall, 5041 (void *)&cmd_setpromisc_mode, 5042 NULL, 5043 }, 5044 }; 5045 5046 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 5047 .f = cmd_set_promisc_mode_parsed, 5048 .data = (void *)0, 5049 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 5050 .tokens = { 5051 (void *)&cmd_setpromisc_set, 5052 (void *)&cmd_setpromisc_promisc, 5053 (void *)&cmd_setpromisc_portnum, 5054 (void *)&cmd_setpromisc_mode, 5055 NULL, 5056 }, 5057 }; 5058 5059 /* *** SET ALLMULTI MODE *** */ 5060 struct cmd_set_allmulti_mode_result { 5061 cmdline_fixed_string_t set; 5062 cmdline_fixed_string_t allmulti; 5063 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5064 uint8_t port_num; /* valid if "allports" argument == 0 */ 5065 cmdline_fixed_string_t mode; 5066 }; 5067 5068 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 5069 __attribute__((unused)) struct cmdline *cl, 5070 void *allports) 5071 { 5072 struct cmd_set_allmulti_mode_result *res = parsed_result; 5073 int enable; 5074 portid_t i; 5075 5076 if (!strcmp(res->mode, "on")) 5077 enable = 1; 5078 else 5079 enable = 0; 5080 5081 /* all ports */ 5082 if (allports) { 5083 FOREACH_PORT(i, ports) { 5084 if (enable) 5085 rte_eth_allmulticast_enable(i); 5086 else 5087 rte_eth_allmulticast_disable(i); 5088 } 5089 } 5090 else { 5091 if (enable) 5092 rte_eth_allmulticast_enable(res->port_num); 5093 else 5094 rte_eth_allmulticast_disable(res->port_num); 5095 } 5096 } 5097 5098 cmdline_parse_token_string_t cmd_setallmulti_set = 5099 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 5100 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 5101 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 5102 "allmulti"); 5103 cmdline_parse_token_string_t cmd_setallmulti_portall = 5104 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 5105 "all"); 5106 cmdline_parse_token_num_t cmd_setallmulti_portnum = 5107 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 5108 UINT8); 5109 cmdline_parse_token_string_t cmd_setallmulti_mode = 5110 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 5111 "on#off"); 5112 5113 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 5114 .f = cmd_set_allmulti_mode_parsed, 5115 .data = (void *)1, 5116 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 5117 .tokens = { 5118 (void *)&cmd_setallmulti_set, 5119 (void *)&cmd_setallmulti_allmulti, 5120 (void *)&cmd_setallmulti_portall, 5121 (void *)&cmd_setallmulti_mode, 5122 NULL, 5123 }, 5124 }; 5125 5126 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 5127 .f = cmd_set_allmulti_mode_parsed, 5128 .data = (void *)0, 5129 .help_str = "set allmulti <port_id> on|off: " 5130 "Set allmulti mode on port_id", 5131 .tokens = { 5132 (void *)&cmd_setallmulti_set, 5133 (void *)&cmd_setallmulti_allmulti, 5134 (void *)&cmd_setallmulti_portnum, 5135 (void *)&cmd_setallmulti_mode, 5136 NULL, 5137 }, 5138 }; 5139 5140 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 5141 struct cmd_link_flow_ctrl_set_result { 5142 cmdline_fixed_string_t set; 5143 cmdline_fixed_string_t flow_ctrl; 5144 cmdline_fixed_string_t rx; 5145 cmdline_fixed_string_t rx_lfc_mode; 5146 cmdline_fixed_string_t tx; 5147 cmdline_fixed_string_t tx_lfc_mode; 5148 cmdline_fixed_string_t mac_ctrl_frame_fwd; 5149 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 5150 cmdline_fixed_string_t autoneg_str; 5151 cmdline_fixed_string_t autoneg; 5152 cmdline_fixed_string_t hw_str; 5153 uint32_t high_water; 5154 cmdline_fixed_string_t lw_str; 5155 uint32_t low_water; 5156 cmdline_fixed_string_t pt_str; 5157 uint16_t pause_time; 5158 cmdline_fixed_string_t xon_str; 5159 uint16_t send_xon; 5160 uint8_t port_id; 5161 }; 5162 5163 cmdline_parse_token_string_t cmd_lfc_set_set = 5164 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5165 set, "set"); 5166 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 5167 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5168 flow_ctrl, "flow_ctrl"); 5169 cmdline_parse_token_string_t cmd_lfc_set_rx = 5170 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5171 rx, "rx"); 5172 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 5173 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5174 rx_lfc_mode, "on#off"); 5175 cmdline_parse_token_string_t cmd_lfc_set_tx = 5176 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5177 tx, "tx"); 5178 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 5179 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5180 tx_lfc_mode, "on#off"); 5181 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 5182 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5183 hw_str, "high_water"); 5184 cmdline_parse_token_num_t cmd_lfc_set_high_water = 5185 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5186 high_water, UINT32); 5187 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 5188 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5189 lw_str, "low_water"); 5190 cmdline_parse_token_num_t cmd_lfc_set_low_water = 5191 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5192 low_water, UINT32); 5193 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 5194 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5195 pt_str, "pause_time"); 5196 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 5197 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5198 pause_time, UINT16); 5199 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 5200 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5201 xon_str, "send_xon"); 5202 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 5203 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5204 send_xon, UINT16); 5205 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 5206 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5207 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 5208 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 5209 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5210 mac_ctrl_frame_fwd_mode, "on#off"); 5211 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 5212 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5213 autoneg_str, "autoneg"); 5214 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 5215 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5216 autoneg, "on#off"); 5217 cmdline_parse_token_num_t cmd_lfc_set_portid = 5218 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5219 port_id, UINT8); 5220 5221 /* forward declaration */ 5222 static void 5223 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 5224 void *data); 5225 5226 cmdline_parse_inst_t cmd_link_flow_control_set = { 5227 .f = cmd_link_flow_ctrl_set_parsed, 5228 .data = NULL, 5229 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 5230 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 5231 "autoneg on|off <port_id>: Configure the Ethernet flow control", 5232 .tokens = { 5233 (void *)&cmd_lfc_set_set, 5234 (void *)&cmd_lfc_set_flow_ctrl, 5235 (void *)&cmd_lfc_set_rx, 5236 (void *)&cmd_lfc_set_rx_mode, 5237 (void *)&cmd_lfc_set_tx, 5238 (void *)&cmd_lfc_set_tx_mode, 5239 (void *)&cmd_lfc_set_high_water, 5240 (void *)&cmd_lfc_set_low_water, 5241 (void *)&cmd_lfc_set_pause_time, 5242 (void *)&cmd_lfc_set_send_xon, 5243 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5244 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5245 (void *)&cmd_lfc_set_autoneg_str, 5246 (void *)&cmd_lfc_set_autoneg, 5247 (void *)&cmd_lfc_set_portid, 5248 NULL, 5249 }, 5250 }; 5251 5252 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 5253 .f = cmd_link_flow_ctrl_set_parsed, 5254 .data = (void *)&cmd_link_flow_control_set_rx, 5255 .help_str = "set flow_ctrl rx on|off <port_id>: " 5256 "Change rx flow control parameter", 5257 .tokens = { 5258 (void *)&cmd_lfc_set_set, 5259 (void *)&cmd_lfc_set_flow_ctrl, 5260 (void *)&cmd_lfc_set_rx, 5261 (void *)&cmd_lfc_set_rx_mode, 5262 (void *)&cmd_lfc_set_portid, 5263 NULL, 5264 }, 5265 }; 5266 5267 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 5268 .f = cmd_link_flow_ctrl_set_parsed, 5269 .data = (void *)&cmd_link_flow_control_set_tx, 5270 .help_str = "set flow_ctrl tx on|off <port_id>: " 5271 "Change tx flow control parameter", 5272 .tokens = { 5273 (void *)&cmd_lfc_set_set, 5274 (void *)&cmd_lfc_set_flow_ctrl, 5275 (void *)&cmd_lfc_set_tx, 5276 (void *)&cmd_lfc_set_tx_mode, 5277 (void *)&cmd_lfc_set_portid, 5278 NULL, 5279 }, 5280 }; 5281 5282 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 5283 .f = cmd_link_flow_ctrl_set_parsed, 5284 .data = (void *)&cmd_link_flow_control_set_hw, 5285 .help_str = "set flow_ctrl high_water <value> <port_id>: " 5286 "Change high water flow control parameter", 5287 .tokens = { 5288 (void *)&cmd_lfc_set_set, 5289 (void *)&cmd_lfc_set_flow_ctrl, 5290 (void *)&cmd_lfc_set_high_water_str, 5291 (void *)&cmd_lfc_set_high_water, 5292 (void *)&cmd_lfc_set_portid, 5293 NULL, 5294 }, 5295 }; 5296 5297 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 5298 .f = cmd_link_flow_ctrl_set_parsed, 5299 .data = (void *)&cmd_link_flow_control_set_lw, 5300 .help_str = "set flow_ctrl low_water <value> <port_id>: " 5301 "Change low water flow control parameter", 5302 .tokens = { 5303 (void *)&cmd_lfc_set_set, 5304 (void *)&cmd_lfc_set_flow_ctrl, 5305 (void *)&cmd_lfc_set_low_water_str, 5306 (void *)&cmd_lfc_set_low_water, 5307 (void *)&cmd_lfc_set_portid, 5308 NULL, 5309 }, 5310 }; 5311 5312 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 5313 .f = cmd_link_flow_ctrl_set_parsed, 5314 .data = (void *)&cmd_link_flow_control_set_pt, 5315 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 5316 "Change pause time flow control parameter", 5317 .tokens = { 5318 (void *)&cmd_lfc_set_set, 5319 (void *)&cmd_lfc_set_flow_ctrl, 5320 (void *)&cmd_lfc_set_pause_time_str, 5321 (void *)&cmd_lfc_set_pause_time, 5322 (void *)&cmd_lfc_set_portid, 5323 NULL, 5324 }, 5325 }; 5326 5327 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 5328 .f = cmd_link_flow_ctrl_set_parsed, 5329 .data = (void *)&cmd_link_flow_control_set_xon, 5330 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 5331 "Change send_xon flow control parameter", 5332 .tokens = { 5333 (void *)&cmd_lfc_set_set, 5334 (void *)&cmd_lfc_set_flow_ctrl, 5335 (void *)&cmd_lfc_set_send_xon_str, 5336 (void *)&cmd_lfc_set_send_xon, 5337 (void *)&cmd_lfc_set_portid, 5338 NULL, 5339 }, 5340 }; 5341 5342 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 5343 .f = cmd_link_flow_ctrl_set_parsed, 5344 .data = (void *)&cmd_link_flow_control_set_macfwd, 5345 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 5346 "Change mac ctrl fwd flow control parameter", 5347 .tokens = { 5348 (void *)&cmd_lfc_set_set, 5349 (void *)&cmd_lfc_set_flow_ctrl, 5350 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5351 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5352 (void *)&cmd_lfc_set_portid, 5353 NULL, 5354 }, 5355 }; 5356 5357 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 5358 .f = cmd_link_flow_ctrl_set_parsed, 5359 .data = (void *)&cmd_link_flow_control_set_autoneg, 5360 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 5361 "Change autoneg flow control parameter", 5362 .tokens = { 5363 (void *)&cmd_lfc_set_set, 5364 (void *)&cmd_lfc_set_flow_ctrl, 5365 (void *)&cmd_lfc_set_autoneg_str, 5366 (void *)&cmd_lfc_set_autoneg, 5367 (void *)&cmd_lfc_set_portid, 5368 NULL, 5369 }, 5370 }; 5371 5372 static void 5373 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 5374 __attribute__((unused)) struct cmdline *cl, 5375 void *data) 5376 { 5377 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 5378 cmdline_parse_inst_t *cmd = data; 5379 struct rte_eth_fc_conf fc_conf; 5380 int rx_fc_en = 0; 5381 int tx_fc_en = 0; 5382 int ret; 5383 5384 /* 5385 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5386 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5387 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5388 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5389 */ 5390 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 5391 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 5392 }; 5393 5394 /* Partial command line, retrieve current configuration */ 5395 if (cmd) { 5396 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 5397 if (ret != 0) { 5398 printf("cannot get current flow ctrl parameters, return" 5399 "code = %d\n", ret); 5400 return; 5401 } 5402 5403 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 5404 (fc_conf.mode == RTE_FC_FULL)) 5405 rx_fc_en = 1; 5406 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 5407 (fc_conf.mode == RTE_FC_FULL)) 5408 tx_fc_en = 1; 5409 } 5410 5411 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 5412 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 5413 5414 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 5415 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 5416 5417 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 5418 5419 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 5420 fc_conf.high_water = res->high_water; 5421 5422 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 5423 fc_conf.low_water = res->low_water; 5424 5425 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 5426 fc_conf.pause_time = res->pause_time; 5427 5428 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 5429 fc_conf.send_xon = res->send_xon; 5430 5431 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 5432 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 5433 fc_conf.mac_ctrl_frame_fwd = 1; 5434 else 5435 fc_conf.mac_ctrl_frame_fwd = 0; 5436 } 5437 5438 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 5439 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 5440 5441 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 5442 if (ret != 0) 5443 printf("bad flow contrl parameter, return code = %d \n", ret); 5444 } 5445 5446 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */ 5447 struct cmd_priority_flow_ctrl_set_result { 5448 cmdline_fixed_string_t set; 5449 cmdline_fixed_string_t pfc_ctrl; 5450 cmdline_fixed_string_t rx; 5451 cmdline_fixed_string_t rx_pfc_mode; 5452 cmdline_fixed_string_t tx; 5453 cmdline_fixed_string_t tx_pfc_mode; 5454 uint32_t high_water; 5455 uint32_t low_water; 5456 uint16_t pause_time; 5457 uint8_t priority; 5458 uint8_t port_id; 5459 }; 5460 5461 static void 5462 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 5463 __attribute__((unused)) struct cmdline *cl, 5464 __attribute__((unused)) void *data) 5465 { 5466 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 5467 struct rte_eth_pfc_conf pfc_conf; 5468 int rx_fc_enable, tx_fc_enable; 5469 int ret; 5470 5471 /* 5472 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5473 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5474 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5475 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5476 */ 5477 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 5478 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 5479 }; 5480 5481 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 5482 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 5483 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 5484 pfc_conf.fc.high_water = res->high_water; 5485 pfc_conf.fc.low_water = res->low_water; 5486 pfc_conf.fc.pause_time = res->pause_time; 5487 pfc_conf.priority = res->priority; 5488 5489 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 5490 if (ret != 0) 5491 printf("bad priority flow contrl parameter, return code = %d \n", ret); 5492 } 5493 5494 cmdline_parse_token_string_t cmd_pfc_set_set = 5495 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5496 set, "set"); 5497 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 5498 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5499 pfc_ctrl, "pfc_ctrl"); 5500 cmdline_parse_token_string_t cmd_pfc_set_rx = 5501 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5502 rx, "rx"); 5503 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 5504 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5505 rx_pfc_mode, "on#off"); 5506 cmdline_parse_token_string_t cmd_pfc_set_tx = 5507 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5508 tx, "tx"); 5509 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 5510 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5511 tx_pfc_mode, "on#off"); 5512 cmdline_parse_token_num_t cmd_pfc_set_high_water = 5513 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5514 high_water, UINT32); 5515 cmdline_parse_token_num_t cmd_pfc_set_low_water = 5516 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5517 low_water, UINT32); 5518 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 5519 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5520 pause_time, UINT16); 5521 cmdline_parse_token_num_t cmd_pfc_set_priority = 5522 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5523 priority, UINT8); 5524 cmdline_parse_token_num_t cmd_pfc_set_portid = 5525 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5526 port_id, UINT8); 5527 5528 cmdline_parse_inst_t cmd_priority_flow_control_set = { 5529 .f = cmd_priority_flow_ctrl_set_parsed, 5530 .data = NULL, 5531 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 5532 "<pause_time> <priority> <port_id>: " 5533 "Configure the Ethernet priority flow control", 5534 .tokens = { 5535 (void *)&cmd_pfc_set_set, 5536 (void *)&cmd_pfc_set_flow_ctrl, 5537 (void *)&cmd_pfc_set_rx, 5538 (void *)&cmd_pfc_set_rx_mode, 5539 (void *)&cmd_pfc_set_tx, 5540 (void *)&cmd_pfc_set_tx_mode, 5541 (void *)&cmd_pfc_set_high_water, 5542 (void *)&cmd_pfc_set_low_water, 5543 (void *)&cmd_pfc_set_pause_time, 5544 (void *)&cmd_pfc_set_priority, 5545 (void *)&cmd_pfc_set_portid, 5546 NULL, 5547 }, 5548 }; 5549 5550 /* *** RESET CONFIGURATION *** */ 5551 struct cmd_reset_result { 5552 cmdline_fixed_string_t reset; 5553 cmdline_fixed_string_t def; 5554 }; 5555 5556 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 5557 struct cmdline *cl, 5558 __attribute__((unused)) void *data) 5559 { 5560 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 5561 set_def_fwd_config(); 5562 } 5563 5564 cmdline_parse_token_string_t cmd_reset_set = 5565 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 5566 cmdline_parse_token_string_t cmd_reset_def = 5567 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 5568 "default"); 5569 5570 cmdline_parse_inst_t cmd_reset = { 5571 .f = cmd_reset_parsed, 5572 .data = NULL, 5573 .help_str = "set default: Reset default forwarding configuration", 5574 .tokens = { 5575 (void *)&cmd_reset_set, 5576 (void *)&cmd_reset_def, 5577 NULL, 5578 }, 5579 }; 5580 5581 /* *** START FORWARDING *** */ 5582 struct cmd_start_result { 5583 cmdline_fixed_string_t start; 5584 }; 5585 5586 cmdline_parse_token_string_t cmd_start_start = 5587 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 5588 5589 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 5590 __attribute__((unused)) struct cmdline *cl, 5591 __attribute__((unused)) void *data) 5592 { 5593 start_packet_forwarding(0); 5594 } 5595 5596 cmdline_parse_inst_t cmd_start = { 5597 .f = cmd_start_parsed, 5598 .data = NULL, 5599 .help_str = "start: Start packet forwarding", 5600 .tokens = { 5601 (void *)&cmd_start_start, 5602 NULL, 5603 }, 5604 }; 5605 5606 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 5607 struct cmd_start_tx_first_result { 5608 cmdline_fixed_string_t start; 5609 cmdline_fixed_string_t tx_first; 5610 }; 5611 5612 static void 5613 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 5614 __attribute__((unused)) struct cmdline *cl, 5615 __attribute__((unused)) void *data) 5616 { 5617 start_packet_forwarding(1); 5618 } 5619 5620 cmdline_parse_token_string_t cmd_start_tx_first_start = 5621 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 5622 "start"); 5623 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 5624 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 5625 tx_first, "tx_first"); 5626 5627 cmdline_parse_inst_t cmd_start_tx_first = { 5628 .f = cmd_start_tx_first_parsed, 5629 .data = NULL, 5630 .help_str = "start tx_first: Start packet forwarding, " 5631 "after sending 1 burst of packets", 5632 .tokens = { 5633 (void *)&cmd_start_tx_first_start, 5634 (void *)&cmd_start_tx_first_tx_first, 5635 NULL, 5636 }, 5637 }; 5638 5639 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 5640 struct cmd_start_tx_first_n_result { 5641 cmdline_fixed_string_t start; 5642 cmdline_fixed_string_t tx_first; 5643 uint32_t tx_num; 5644 }; 5645 5646 static void 5647 cmd_start_tx_first_n_parsed(void *parsed_result, 5648 __attribute__((unused)) struct cmdline *cl, 5649 __attribute__((unused)) void *data) 5650 { 5651 struct cmd_start_tx_first_n_result *res = parsed_result; 5652 5653 start_packet_forwarding(res->tx_num); 5654 } 5655 5656 cmdline_parse_token_string_t cmd_start_tx_first_n_start = 5657 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 5658 start, "start"); 5659 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 5660 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 5661 tx_first, "tx_first"); 5662 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 5663 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 5664 tx_num, UINT32); 5665 5666 cmdline_parse_inst_t cmd_start_tx_first_n = { 5667 .f = cmd_start_tx_first_n_parsed, 5668 .data = NULL, 5669 .help_str = "start tx_first <num>: " 5670 "packet forwarding, after sending <num> bursts of packets", 5671 .tokens = { 5672 (void *)&cmd_start_tx_first_n_start, 5673 (void *)&cmd_start_tx_first_n_tx_first, 5674 (void *)&cmd_start_tx_first_n_tx_num, 5675 NULL, 5676 }, 5677 }; 5678 5679 /* *** SET LINK UP *** */ 5680 struct cmd_set_link_up_result { 5681 cmdline_fixed_string_t set; 5682 cmdline_fixed_string_t link_up; 5683 cmdline_fixed_string_t port; 5684 uint8_t port_id; 5685 }; 5686 5687 cmdline_parse_token_string_t cmd_set_link_up_set = 5688 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 5689 cmdline_parse_token_string_t cmd_set_link_up_link_up = 5690 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 5691 "link-up"); 5692 cmdline_parse_token_string_t cmd_set_link_up_port = 5693 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 5694 cmdline_parse_token_num_t cmd_set_link_up_port_id = 5695 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); 5696 5697 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 5698 __attribute__((unused)) struct cmdline *cl, 5699 __attribute__((unused)) void *data) 5700 { 5701 struct cmd_set_link_up_result *res = parsed_result; 5702 dev_set_link_up(res->port_id); 5703 } 5704 5705 cmdline_parse_inst_t cmd_set_link_up = { 5706 .f = cmd_set_link_up_parsed, 5707 .data = NULL, 5708 .help_str = "set link-up port <port id>", 5709 .tokens = { 5710 (void *)&cmd_set_link_up_set, 5711 (void *)&cmd_set_link_up_link_up, 5712 (void *)&cmd_set_link_up_port, 5713 (void *)&cmd_set_link_up_port_id, 5714 NULL, 5715 }, 5716 }; 5717 5718 /* *** SET LINK DOWN *** */ 5719 struct cmd_set_link_down_result { 5720 cmdline_fixed_string_t set; 5721 cmdline_fixed_string_t link_down; 5722 cmdline_fixed_string_t port; 5723 uint8_t port_id; 5724 }; 5725 5726 cmdline_parse_token_string_t cmd_set_link_down_set = 5727 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 5728 cmdline_parse_token_string_t cmd_set_link_down_link_down = 5729 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 5730 "link-down"); 5731 cmdline_parse_token_string_t cmd_set_link_down_port = 5732 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 5733 cmdline_parse_token_num_t cmd_set_link_down_port_id = 5734 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); 5735 5736 static void cmd_set_link_down_parsed( 5737 __attribute__((unused)) void *parsed_result, 5738 __attribute__((unused)) struct cmdline *cl, 5739 __attribute__((unused)) void *data) 5740 { 5741 struct cmd_set_link_down_result *res = parsed_result; 5742 dev_set_link_down(res->port_id); 5743 } 5744 5745 cmdline_parse_inst_t cmd_set_link_down = { 5746 .f = cmd_set_link_down_parsed, 5747 .data = NULL, 5748 .help_str = "set link-down port <port id>", 5749 .tokens = { 5750 (void *)&cmd_set_link_down_set, 5751 (void *)&cmd_set_link_down_link_down, 5752 (void *)&cmd_set_link_down_port, 5753 (void *)&cmd_set_link_down_port_id, 5754 NULL, 5755 }, 5756 }; 5757 5758 /* *** SHOW CFG *** */ 5759 struct cmd_showcfg_result { 5760 cmdline_fixed_string_t show; 5761 cmdline_fixed_string_t cfg; 5762 cmdline_fixed_string_t what; 5763 }; 5764 5765 static void cmd_showcfg_parsed(void *parsed_result, 5766 __attribute__((unused)) struct cmdline *cl, 5767 __attribute__((unused)) void *data) 5768 { 5769 struct cmd_showcfg_result *res = parsed_result; 5770 if (!strcmp(res->what, "rxtx")) 5771 rxtx_config_display(); 5772 else if (!strcmp(res->what, "cores")) 5773 fwd_lcores_config_display(); 5774 else if (!strcmp(res->what, "fwd")) 5775 pkt_fwd_config_display(&cur_fwd_config); 5776 else if (!strcmp(res->what, "txpkts")) 5777 show_tx_pkt_segments(); 5778 } 5779 5780 cmdline_parse_token_string_t cmd_showcfg_show = 5781 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 5782 cmdline_parse_token_string_t cmd_showcfg_port = 5783 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 5784 cmdline_parse_token_string_t cmd_showcfg_what = 5785 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 5786 "rxtx#cores#fwd#txpkts"); 5787 5788 cmdline_parse_inst_t cmd_showcfg = { 5789 .f = cmd_showcfg_parsed, 5790 .data = NULL, 5791 .help_str = "show config rxtx|cores|fwd|txpkts", 5792 .tokens = { 5793 (void *)&cmd_showcfg_show, 5794 (void *)&cmd_showcfg_port, 5795 (void *)&cmd_showcfg_what, 5796 NULL, 5797 }, 5798 }; 5799 5800 /* *** SHOW ALL PORT INFO *** */ 5801 struct cmd_showportall_result { 5802 cmdline_fixed_string_t show; 5803 cmdline_fixed_string_t port; 5804 cmdline_fixed_string_t what; 5805 cmdline_fixed_string_t all; 5806 }; 5807 5808 static void cmd_showportall_parsed(void *parsed_result, 5809 __attribute__((unused)) struct cmdline *cl, 5810 __attribute__((unused)) void *data) 5811 { 5812 portid_t i; 5813 5814 struct cmd_showportall_result *res = parsed_result; 5815 if (!strcmp(res->show, "clear")) { 5816 if (!strcmp(res->what, "stats")) 5817 FOREACH_PORT(i, ports) 5818 nic_stats_clear(i); 5819 else if (!strcmp(res->what, "xstats")) 5820 FOREACH_PORT(i, ports) 5821 nic_xstats_clear(i); 5822 } else if (!strcmp(res->what, "info")) 5823 FOREACH_PORT(i, ports) 5824 port_infos_display(i); 5825 else if (!strcmp(res->what, "stats")) 5826 FOREACH_PORT(i, ports) 5827 nic_stats_display(i); 5828 else if (!strcmp(res->what, "xstats")) 5829 FOREACH_PORT(i, ports) 5830 nic_xstats_display(i); 5831 else if (!strcmp(res->what, "fdir")) 5832 FOREACH_PORT(i, ports) 5833 fdir_get_infos(i); 5834 else if (!strcmp(res->what, "stat_qmap")) 5835 FOREACH_PORT(i, ports) 5836 nic_stats_mapping_display(i); 5837 else if (!strcmp(res->what, "dcb_tc")) 5838 FOREACH_PORT(i, ports) 5839 port_dcb_info_display(i); 5840 } 5841 5842 cmdline_parse_token_string_t cmd_showportall_show = 5843 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 5844 "show#clear"); 5845 cmdline_parse_token_string_t cmd_showportall_port = 5846 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 5847 cmdline_parse_token_string_t cmd_showportall_what = 5848 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 5849 "info#stats#xstats#fdir#stat_qmap#dcb_tc"); 5850 cmdline_parse_token_string_t cmd_showportall_all = 5851 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 5852 cmdline_parse_inst_t cmd_showportall = { 5853 .f = cmd_showportall_parsed, 5854 .data = NULL, 5855 .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all", 5856 .tokens = { 5857 (void *)&cmd_showportall_show, 5858 (void *)&cmd_showportall_port, 5859 (void *)&cmd_showportall_what, 5860 (void *)&cmd_showportall_all, 5861 NULL, 5862 }, 5863 }; 5864 5865 /* *** SHOW PORT INFO *** */ 5866 struct cmd_showport_result { 5867 cmdline_fixed_string_t show; 5868 cmdline_fixed_string_t port; 5869 cmdline_fixed_string_t what; 5870 uint8_t portnum; 5871 }; 5872 5873 static void cmd_showport_parsed(void *parsed_result, 5874 __attribute__((unused)) struct cmdline *cl, 5875 __attribute__((unused)) void *data) 5876 { 5877 struct cmd_showport_result *res = parsed_result; 5878 if (!strcmp(res->show, "clear")) { 5879 if (!strcmp(res->what, "stats")) 5880 nic_stats_clear(res->portnum); 5881 else if (!strcmp(res->what, "xstats")) 5882 nic_xstats_clear(res->portnum); 5883 } else if (!strcmp(res->what, "info")) 5884 port_infos_display(res->portnum); 5885 else if (!strcmp(res->what, "stats")) 5886 nic_stats_display(res->portnum); 5887 else if (!strcmp(res->what, "xstats")) 5888 nic_xstats_display(res->portnum); 5889 else if (!strcmp(res->what, "fdir")) 5890 fdir_get_infos(res->portnum); 5891 else if (!strcmp(res->what, "stat_qmap")) 5892 nic_stats_mapping_display(res->portnum); 5893 else if (!strcmp(res->what, "dcb_tc")) 5894 port_dcb_info_display(res->portnum); 5895 } 5896 5897 cmdline_parse_token_string_t cmd_showport_show = 5898 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 5899 "show#clear"); 5900 cmdline_parse_token_string_t cmd_showport_port = 5901 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 5902 cmdline_parse_token_string_t cmd_showport_what = 5903 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 5904 "info#stats#xstats#fdir#stat_qmap#dcb_tc"); 5905 cmdline_parse_token_num_t cmd_showport_portnum = 5906 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); 5907 5908 cmdline_parse_inst_t cmd_showport = { 5909 .f = cmd_showport_parsed, 5910 .data = NULL, 5911 .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc " 5912 "<port_id>", 5913 .tokens = { 5914 (void *)&cmd_showport_show, 5915 (void *)&cmd_showport_port, 5916 (void *)&cmd_showport_what, 5917 (void *)&cmd_showport_portnum, 5918 NULL, 5919 }, 5920 }; 5921 5922 /* *** SHOW QUEUE INFO *** */ 5923 struct cmd_showqueue_result { 5924 cmdline_fixed_string_t show; 5925 cmdline_fixed_string_t type; 5926 cmdline_fixed_string_t what; 5927 uint8_t portnum; 5928 uint16_t queuenum; 5929 }; 5930 5931 static void 5932 cmd_showqueue_parsed(void *parsed_result, 5933 __attribute__((unused)) struct cmdline *cl, 5934 __attribute__((unused)) void *data) 5935 { 5936 struct cmd_showqueue_result *res = parsed_result; 5937 5938 if (!strcmp(res->type, "rxq")) 5939 rx_queue_infos_display(res->portnum, res->queuenum); 5940 else if (!strcmp(res->type, "txq")) 5941 tx_queue_infos_display(res->portnum, res->queuenum); 5942 } 5943 5944 cmdline_parse_token_string_t cmd_showqueue_show = 5945 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 5946 cmdline_parse_token_string_t cmd_showqueue_type = 5947 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 5948 cmdline_parse_token_string_t cmd_showqueue_what = 5949 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 5950 cmdline_parse_token_num_t cmd_showqueue_portnum = 5951 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8); 5952 cmdline_parse_token_num_t cmd_showqueue_queuenum = 5953 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); 5954 5955 cmdline_parse_inst_t cmd_showqueue = { 5956 .f = cmd_showqueue_parsed, 5957 .data = NULL, 5958 .help_str = "show rxq|txq info <port_id> <queue_id>", 5959 .tokens = { 5960 (void *)&cmd_showqueue_show, 5961 (void *)&cmd_showqueue_type, 5962 (void *)&cmd_showqueue_what, 5963 (void *)&cmd_showqueue_portnum, 5964 (void *)&cmd_showqueue_queuenum, 5965 NULL, 5966 }, 5967 }; 5968 5969 /* *** READ PORT REGISTER *** */ 5970 struct cmd_read_reg_result { 5971 cmdline_fixed_string_t read; 5972 cmdline_fixed_string_t reg; 5973 uint8_t port_id; 5974 uint32_t reg_off; 5975 }; 5976 5977 static void 5978 cmd_read_reg_parsed(void *parsed_result, 5979 __attribute__((unused)) struct cmdline *cl, 5980 __attribute__((unused)) void *data) 5981 { 5982 struct cmd_read_reg_result *res = parsed_result; 5983 port_reg_display(res->port_id, res->reg_off); 5984 } 5985 5986 cmdline_parse_token_string_t cmd_read_reg_read = 5987 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 5988 cmdline_parse_token_string_t cmd_read_reg_reg = 5989 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 5990 cmdline_parse_token_num_t cmd_read_reg_port_id = 5991 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 5992 cmdline_parse_token_num_t cmd_read_reg_reg_off = 5993 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 5994 5995 cmdline_parse_inst_t cmd_read_reg = { 5996 .f = cmd_read_reg_parsed, 5997 .data = NULL, 5998 .help_str = "read reg <port_id> <reg_off>", 5999 .tokens = { 6000 (void *)&cmd_read_reg_read, 6001 (void *)&cmd_read_reg_reg, 6002 (void *)&cmd_read_reg_port_id, 6003 (void *)&cmd_read_reg_reg_off, 6004 NULL, 6005 }, 6006 }; 6007 6008 /* *** READ PORT REGISTER BIT FIELD *** */ 6009 struct cmd_read_reg_bit_field_result { 6010 cmdline_fixed_string_t read; 6011 cmdline_fixed_string_t regfield; 6012 uint8_t port_id; 6013 uint32_t reg_off; 6014 uint8_t bit1_pos; 6015 uint8_t bit2_pos; 6016 }; 6017 6018 static void 6019 cmd_read_reg_bit_field_parsed(void *parsed_result, 6020 __attribute__((unused)) struct cmdline *cl, 6021 __attribute__((unused)) void *data) 6022 { 6023 struct cmd_read_reg_bit_field_result *res = parsed_result; 6024 port_reg_bit_field_display(res->port_id, res->reg_off, 6025 res->bit1_pos, res->bit2_pos); 6026 } 6027 6028 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 6029 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 6030 "read"); 6031 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 6032 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 6033 regfield, "regfield"); 6034 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 6035 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 6036 UINT8); 6037 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 6038 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 6039 UINT32); 6040 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 6041 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 6042 UINT8); 6043 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 6044 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 6045 UINT8); 6046 6047 cmdline_parse_inst_t cmd_read_reg_bit_field = { 6048 .f = cmd_read_reg_bit_field_parsed, 6049 .data = NULL, 6050 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 6051 "Read register bit field between bit_x and bit_y included", 6052 .tokens = { 6053 (void *)&cmd_read_reg_bit_field_read, 6054 (void *)&cmd_read_reg_bit_field_regfield, 6055 (void *)&cmd_read_reg_bit_field_port_id, 6056 (void *)&cmd_read_reg_bit_field_reg_off, 6057 (void *)&cmd_read_reg_bit_field_bit1_pos, 6058 (void *)&cmd_read_reg_bit_field_bit2_pos, 6059 NULL, 6060 }, 6061 }; 6062 6063 /* *** READ PORT REGISTER BIT *** */ 6064 struct cmd_read_reg_bit_result { 6065 cmdline_fixed_string_t read; 6066 cmdline_fixed_string_t regbit; 6067 uint8_t port_id; 6068 uint32_t reg_off; 6069 uint8_t bit_pos; 6070 }; 6071 6072 static void 6073 cmd_read_reg_bit_parsed(void *parsed_result, 6074 __attribute__((unused)) struct cmdline *cl, 6075 __attribute__((unused)) void *data) 6076 { 6077 struct cmd_read_reg_bit_result *res = parsed_result; 6078 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 6079 } 6080 6081 cmdline_parse_token_string_t cmd_read_reg_bit_read = 6082 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 6083 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 6084 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 6085 regbit, "regbit"); 6086 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 6087 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 6088 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 6089 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 6090 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 6091 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 6092 6093 cmdline_parse_inst_t cmd_read_reg_bit = { 6094 .f = cmd_read_reg_bit_parsed, 6095 .data = NULL, 6096 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 6097 .tokens = { 6098 (void *)&cmd_read_reg_bit_read, 6099 (void *)&cmd_read_reg_bit_regbit, 6100 (void *)&cmd_read_reg_bit_port_id, 6101 (void *)&cmd_read_reg_bit_reg_off, 6102 (void *)&cmd_read_reg_bit_bit_pos, 6103 NULL, 6104 }, 6105 }; 6106 6107 /* *** WRITE PORT REGISTER *** */ 6108 struct cmd_write_reg_result { 6109 cmdline_fixed_string_t write; 6110 cmdline_fixed_string_t reg; 6111 uint8_t port_id; 6112 uint32_t reg_off; 6113 uint32_t value; 6114 }; 6115 6116 static void 6117 cmd_write_reg_parsed(void *parsed_result, 6118 __attribute__((unused)) struct cmdline *cl, 6119 __attribute__((unused)) void *data) 6120 { 6121 struct cmd_write_reg_result *res = parsed_result; 6122 port_reg_set(res->port_id, res->reg_off, res->value); 6123 } 6124 6125 cmdline_parse_token_string_t cmd_write_reg_write = 6126 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 6127 cmdline_parse_token_string_t cmd_write_reg_reg = 6128 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 6129 cmdline_parse_token_num_t cmd_write_reg_port_id = 6130 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 6131 cmdline_parse_token_num_t cmd_write_reg_reg_off = 6132 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 6133 cmdline_parse_token_num_t cmd_write_reg_value = 6134 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 6135 6136 cmdline_parse_inst_t cmd_write_reg = { 6137 .f = cmd_write_reg_parsed, 6138 .data = NULL, 6139 .help_str = "write reg <port_id> <reg_off> <reg_value>", 6140 .tokens = { 6141 (void *)&cmd_write_reg_write, 6142 (void *)&cmd_write_reg_reg, 6143 (void *)&cmd_write_reg_port_id, 6144 (void *)&cmd_write_reg_reg_off, 6145 (void *)&cmd_write_reg_value, 6146 NULL, 6147 }, 6148 }; 6149 6150 /* *** WRITE PORT REGISTER BIT FIELD *** */ 6151 struct cmd_write_reg_bit_field_result { 6152 cmdline_fixed_string_t write; 6153 cmdline_fixed_string_t regfield; 6154 uint8_t port_id; 6155 uint32_t reg_off; 6156 uint8_t bit1_pos; 6157 uint8_t bit2_pos; 6158 uint32_t value; 6159 }; 6160 6161 static void 6162 cmd_write_reg_bit_field_parsed(void *parsed_result, 6163 __attribute__((unused)) struct cmdline *cl, 6164 __attribute__((unused)) void *data) 6165 { 6166 struct cmd_write_reg_bit_field_result *res = parsed_result; 6167 port_reg_bit_field_set(res->port_id, res->reg_off, 6168 res->bit1_pos, res->bit2_pos, res->value); 6169 } 6170 6171 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 6172 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 6173 "write"); 6174 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 6175 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 6176 regfield, "regfield"); 6177 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 6178 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 6179 UINT8); 6180 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 6181 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 6182 UINT32); 6183 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 6184 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 6185 UINT8); 6186 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 6187 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 6188 UINT8); 6189 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 6190 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 6191 UINT32); 6192 6193 cmdline_parse_inst_t cmd_write_reg_bit_field = { 6194 .f = cmd_write_reg_bit_field_parsed, 6195 .data = NULL, 6196 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 6197 "<reg_value>: " 6198 "Set register bit field between bit_x and bit_y included", 6199 .tokens = { 6200 (void *)&cmd_write_reg_bit_field_write, 6201 (void *)&cmd_write_reg_bit_field_regfield, 6202 (void *)&cmd_write_reg_bit_field_port_id, 6203 (void *)&cmd_write_reg_bit_field_reg_off, 6204 (void *)&cmd_write_reg_bit_field_bit1_pos, 6205 (void *)&cmd_write_reg_bit_field_bit2_pos, 6206 (void *)&cmd_write_reg_bit_field_value, 6207 NULL, 6208 }, 6209 }; 6210 6211 /* *** WRITE PORT REGISTER BIT *** */ 6212 struct cmd_write_reg_bit_result { 6213 cmdline_fixed_string_t write; 6214 cmdline_fixed_string_t regbit; 6215 uint8_t port_id; 6216 uint32_t reg_off; 6217 uint8_t bit_pos; 6218 uint8_t value; 6219 }; 6220 6221 static void 6222 cmd_write_reg_bit_parsed(void *parsed_result, 6223 __attribute__((unused)) struct cmdline *cl, 6224 __attribute__((unused)) void *data) 6225 { 6226 struct cmd_write_reg_bit_result *res = parsed_result; 6227 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 6228 } 6229 6230 cmdline_parse_token_string_t cmd_write_reg_bit_write = 6231 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 6232 "write"); 6233 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 6234 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 6235 regbit, "regbit"); 6236 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 6237 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 6238 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 6239 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 6240 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 6241 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 6242 cmdline_parse_token_num_t cmd_write_reg_bit_value = 6243 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 6244 6245 cmdline_parse_inst_t cmd_write_reg_bit = { 6246 .f = cmd_write_reg_bit_parsed, 6247 .data = NULL, 6248 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 6249 "0 <= bit_x <= 31", 6250 .tokens = { 6251 (void *)&cmd_write_reg_bit_write, 6252 (void *)&cmd_write_reg_bit_regbit, 6253 (void *)&cmd_write_reg_bit_port_id, 6254 (void *)&cmd_write_reg_bit_reg_off, 6255 (void *)&cmd_write_reg_bit_bit_pos, 6256 (void *)&cmd_write_reg_bit_value, 6257 NULL, 6258 }, 6259 }; 6260 6261 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 6262 struct cmd_read_rxd_txd_result { 6263 cmdline_fixed_string_t read; 6264 cmdline_fixed_string_t rxd_txd; 6265 uint8_t port_id; 6266 uint16_t queue_id; 6267 uint16_t desc_id; 6268 }; 6269 6270 static void 6271 cmd_read_rxd_txd_parsed(void *parsed_result, 6272 __attribute__((unused)) struct cmdline *cl, 6273 __attribute__((unused)) void *data) 6274 { 6275 struct cmd_read_rxd_txd_result *res = parsed_result; 6276 6277 if (!strcmp(res->rxd_txd, "rxd")) 6278 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6279 else if (!strcmp(res->rxd_txd, "txd")) 6280 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6281 } 6282 6283 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 6284 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 6285 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 6286 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 6287 "rxd#txd"); 6288 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 6289 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 6290 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 6291 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 6292 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 6293 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 6294 6295 cmdline_parse_inst_t cmd_read_rxd_txd = { 6296 .f = cmd_read_rxd_txd_parsed, 6297 .data = NULL, 6298 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 6299 .tokens = { 6300 (void *)&cmd_read_rxd_txd_read, 6301 (void *)&cmd_read_rxd_txd_rxd_txd, 6302 (void *)&cmd_read_rxd_txd_port_id, 6303 (void *)&cmd_read_rxd_txd_queue_id, 6304 (void *)&cmd_read_rxd_txd_desc_id, 6305 NULL, 6306 }, 6307 }; 6308 6309 /* *** QUIT *** */ 6310 struct cmd_quit_result { 6311 cmdline_fixed_string_t quit; 6312 }; 6313 6314 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 6315 struct cmdline *cl, 6316 __attribute__((unused)) void *data) 6317 { 6318 pmd_test_exit(); 6319 cmdline_quit(cl); 6320 } 6321 6322 cmdline_parse_token_string_t cmd_quit_quit = 6323 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 6324 6325 cmdline_parse_inst_t cmd_quit = { 6326 .f = cmd_quit_parsed, 6327 .data = NULL, 6328 .help_str = "quit: Exit application", 6329 .tokens = { 6330 (void *)&cmd_quit_quit, 6331 NULL, 6332 }, 6333 }; 6334 6335 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 6336 struct cmd_mac_addr_result { 6337 cmdline_fixed_string_t mac_addr_cmd; 6338 cmdline_fixed_string_t what; 6339 uint8_t port_num; 6340 struct ether_addr address; 6341 }; 6342 6343 static void cmd_mac_addr_parsed(void *parsed_result, 6344 __attribute__((unused)) struct cmdline *cl, 6345 __attribute__((unused)) void *data) 6346 { 6347 struct cmd_mac_addr_result *res = parsed_result; 6348 int ret; 6349 6350 if (strcmp(res->what, "add") == 0) 6351 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 6352 else 6353 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 6354 6355 /* check the return value and print it if is < 0 */ 6356 if(ret < 0) 6357 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 6358 6359 } 6360 6361 cmdline_parse_token_string_t cmd_mac_addr_cmd = 6362 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 6363 "mac_addr"); 6364 cmdline_parse_token_string_t cmd_mac_addr_what = 6365 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 6366 "add#remove"); 6367 cmdline_parse_token_num_t cmd_mac_addr_portnum = 6368 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 6369 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 6370 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 6371 6372 cmdline_parse_inst_t cmd_mac_addr = { 6373 .f = cmd_mac_addr_parsed, 6374 .data = (void *)0, 6375 .help_str = "mac_addr add|remove <port_id> <mac_addr>: " 6376 "Add/Remove MAC address on port_id", 6377 .tokens = { 6378 (void *)&cmd_mac_addr_cmd, 6379 (void *)&cmd_mac_addr_what, 6380 (void *)&cmd_mac_addr_portnum, 6381 (void *)&cmd_mac_addr_addr, 6382 NULL, 6383 }, 6384 }; 6385 6386 6387 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 6388 struct cmd_set_qmap_result { 6389 cmdline_fixed_string_t set; 6390 cmdline_fixed_string_t qmap; 6391 cmdline_fixed_string_t what; 6392 uint8_t port_id; 6393 uint16_t queue_id; 6394 uint8_t map_value; 6395 }; 6396 6397 static void 6398 cmd_set_qmap_parsed(void *parsed_result, 6399 __attribute__((unused)) struct cmdline *cl, 6400 __attribute__((unused)) void *data) 6401 { 6402 struct cmd_set_qmap_result *res = parsed_result; 6403 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 6404 6405 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 6406 } 6407 6408 cmdline_parse_token_string_t cmd_setqmap_set = 6409 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6410 set, "set"); 6411 cmdline_parse_token_string_t cmd_setqmap_qmap = 6412 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6413 qmap, "stat_qmap"); 6414 cmdline_parse_token_string_t cmd_setqmap_what = 6415 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6416 what, "tx#rx"); 6417 cmdline_parse_token_num_t cmd_setqmap_portid = 6418 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6419 port_id, UINT8); 6420 cmdline_parse_token_num_t cmd_setqmap_queueid = 6421 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6422 queue_id, UINT16); 6423 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 6424 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6425 map_value, UINT8); 6426 6427 cmdline_parse_inst_t cmd_set_qmap = { 6428 .f = cmd_set_qmap_parsed, 6429 .data = NULL, 6430 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 6431 "Set statistics mapping value on tx|rx queue_id of port_id", 6432 .tokens = { 6433 (void *)&cmd_setqmap_set, 6434 (void *)&cmd_setqmap_qmap, 6435 (void *)&cmd_setqmap_what, 6436 (void *)&cmd_setqmap_portid, 6437 (void *)&cmd_setqmap_queueid, 6438 (void *)&cmd_setqmap_mapvalue, 6439 NULL, 6440 }, 6441 }; 6442 6443 /* *** CONFIGURE UNICAST HASH TABLE *** */ 6444 struct cmd_set_uc_hash_table { 6445 cmdline_fixed_string_t set; 6446 cmdline_fixed_string_t port; 6447 uint8_t port_id; 6448 cmdline_fixed_string_t what; 6449 struct ether_addr address; 6450 cmdline_fixed_string_t mode; 6451 }; 6452 6453 static void 6454 cmd_set_uc_hash_parsed(void *parsed_result, 6455 __attribute__((unused)) struct cmdline *cl, 6456 __attribute__((unused)) void *data) 6457 { 6458 int ret=0; 6459 struct cmd_set_uc_hash_table *res = parsed_result; 6460 6461 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6462 6463 if (strcmp(res->what, "uta") == 0) 6464 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 6465 &res->address,(uint8_t)is_on); 6466 if (ret < 0) 6467 printf("bad unicast hash table parameter, return code = %d \n", ret); 6468 6469 } 6470 6471 cmdline_parse_token_string_t cmd_set_uc_hash_set = 6472 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6473 set, "set"); 6474 cmdline_parse_token_string_t cmd_set_uc_hash_port = 6475 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6476 port, "port"); 6477 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 6478 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 6479 port_id, UINT8); 6480 cmdline_parse_token_string_t cmd_set_uc_hash_what = 6481 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6482 what, "uta"); 6483 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 6484 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 6485 address); 6486 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 6487 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6488 mode, "on#off"); 6489 6490 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 6491 .f = cmd_set_uc_hash_parsed, 6492 .data = NULL, 6493 .help_str = "set port <port_id> uta <mac_addr> on|off)", 6494 .tokens = { 6495 (void *)&cmd_set_uc_hash_set, 6496 (void *)&cmd_set_uc_hash_port, 6497 (void *)&cmd_set_uc_hash_portid, 6498 (void *)&cmd_set_uc_hash_what, 6499 (void *)&cmd_set_uc_hash_mac, 6500 (void *)&cmd_set_uc_hash_mode, 6501 NULL, 6502 }, 6503 }; 6504 6505 struct cmd_set_uc_all_hash_table { 6506 cmdline_fixed_string_t set; 6507 cmdline_fixed_string_t port; 6508 uint8_t port_id; 6509 cmdline_fixed_string_t what; 6510 cmdline_fixed_string_t value; 6511 cmdline_fixed_string_t mode; 6512 }; 6513 6514 static void 6515 cmd_set_uc_all_hash_parsed(void *parsed_result, 6516 __attribute__((unused)) struct cmdline *cl, 6517 __attribute__((unused)) void *data) 6518 { 6519 int ret=0; 6520 struct cmd_set_uc_all_hash_table *res = parsed_result; 6521 6522 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6523 6524 if ((strcmp(res->what, "uta") == 0) && 6525 (strcmp(res->value, "all") == 0)) 6526 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 6527 if (ret < 0) 6528 printf("bad unicast hash table parameter," 6529 "return code = %d \n", ret); 6530 } 6531 6532 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 6533 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6534 set, "set"); 6535 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 6536 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6537 port, "port"); 6538 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 6539 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 6540 port_id, UINT8); 6541 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 6542 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6543 what, "uta"); 6544 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 6545 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6546 value,"all"); 6547 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 6548 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6549 mode, "on#off"); 6550 6551 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 6552 .f = cmd_set_uc_all_hash_parsed, 6553 .data = NULL, 6554 .help_str = "set port <port_id> uta all on|off", 6555 .tokens = { 6556 (void *)&cmd_set_uc_all_hash_set, 6557 (void *)&cmd_set_uc_all_hash_port, 6558 (void *)&cmd_set_uc_all_hash_portid, 6559 (void *)&cmd_set_uc_all_hash_what, 6560 (void *)&cmd_set_uc_all_hash_value, 6561 (void *)&cmd_set_uc_all_hash_mode, 6562 NULL, 6563 }, 6564 }; 6565 6566 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 6567 struct cmd_set_vf_macvlan_filter { 6568 cmdline_fixed_string_t set; 6569 cmdline_fixed_string_t port; 6570 uint8_t port_id; 6571 cmdline_fixed_string_t vf; 6572 uint8_t vf_id; 6573 struct ether_addr address; 6574 cmdline_fixed_string_t filter_type; 6575 cmdline_fixed_string_t mode; 6576 }; 6577 6578 static void 6579 cmd_set_vf_macvlan_parsed(void *parsed_result, 6580 __attribute__((unused)) struct cmdline *cl, 6581 __attribute__((unused)) void *data) 6582 { 6583 int is_on, ret = 0; 6584 struct cmd_set_vf_macvlan_filter *res = parsed_result; 6585 struct rte_eth_mac_filter filter; 6586 6587 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 6588 6589 (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 6590 6591 /* set VF MAC filter */ 6592 filter.is_vf = 1; 6593 6594 /* set VF ID */ 6595 filter.dst_id = res->vf_id; 6596 6597 if (!strcmp(res->filter_type, "exact-mac")) 6598 filter.filter_type = RTE_MAC_PERFECT_MATCH; 6599 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 6600 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 6601 else if (!strcmp(res->filter_type, "hashmac")) 6602 filter.filter_type = RTE_MAC_HASH_MATCH; 6603 else if (!strcmp(res->filter_type, "hashmac-vlan")) 6604 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 6605 6606 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6607 6608 if (is_on) 6609 ret = rte_eth_dev_filter_ctrl(res->port_id, 6610 RTE_ETH_FILTER_MACVLAN, 6611 RTE_ETH_FILTER_ADD, 6612 &filter); 6613 else 6614 ret = rte_eth_dev_filter_ctrl(res->port_id, 6615 RTE_ETH_FILTER_MACVLAN, 6616 RTE_ETH_FILTER_DELETE, 6617 &filter); 6618 6619 if (ret < 0) 6620 printf("bad set MAC hash parameter, return code = %d\n", ret); 6621 6622 } 6623 6624 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 6625 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6626 set, "set"); 6627 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 6628 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6629 port, "port"); 6630 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 6631 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6632 port_id, UINT8); 6633 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 6634 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6635 vf, "vf"); 6636 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 6637 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6638 vf_id, UINT8); 6639 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 6640 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6641 address); 6642 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 6643 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6644 filter_type, "exact-mac#exact-mac-vlan" 6645 "#hashmac#hashmac-vlan"); 6646 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 6647 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6648 mode, "on#off"); 6649 6650 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 6651 .f = cmd_set_vf_macvlan_parsed, 6652 .data = NULL, 6653 .help_str = "set port <port_id> vf <vf_id> <mac_addr> " 6654 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: " 6655 "Exact match rule: exact match of MAC or MAC and VLAN; " 6656 "hash match rule: hash match of MAC and exact match of VLAN", 6657 .tokens = { 6658 (void *)&cmd_set_vf_macvlan_set, 6659 (void *)&cmd_set_vf_macvlan_port, 6660 (void *)&cmd_set_vf_macvlan_portid, 6661 (void *)&cmd_set_vf_macvlan_vf, 6662 (void *)&cmd_set_vf_macvlan_vf_id, 6663 (void *)&cmd_set_vf_macvlan_mac, 6664 (void *)&cmd_set_vf_macvlan_filter_type, 6665 (void *)&cmd_set_vf_macvlan_mode, 6666 NULL, 6667 }, 6668 }; 6669 6670 #ifdef RTE_LIBRTE_IXGBE_PMD 6671 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 6672 struct cmd_set_vf_traffic { 6673 cmdline_fixed_string_t set; 6674 cmdline_fixed_string_t port; 6675 uint8_t port_id; 6676 cmdline_fixed_string_t vf; 6677 uint8_t vf_id; 6678 cmdline_fixed_string_t what; 6679 cmdline_fixed_string_t mode; 6680 }; 6681 6682 static void 6683 cmd_set_vf_traffic_parsed(void *parsed_result, 6684 __attribute__((unused)) struct cmdline *cl, 6685 __attribute__((unused)) void *data) 6686 { 6687 struct cmd_set_vf_traffic *res = parsed_result; 6688 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 6689 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6690 6691 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 6692 } 6693 6694 cmdline_parse_token_string_t cmd_setvf_traffic_set = 6695 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6696 set, "set"); 6697 cmdline_parse_token_string_t cmd_setvf_traffic_port = 6698 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6699 port, "port"); 6700 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 6701 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 6702 port_id, UINT8); 6703 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 6704 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6705 vf, "vf"); 6706 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 6707 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 6708 vf_id, UINT8); 6709 cmdline_parse_token_string_t cmd_setvf_traffic_what = 6710 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6711 what, "tx#rx"); 6712 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 6713 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6714 mode, "on#off"); 6715 6716 cmdline_parse_inst_t cmd_set_vf_traffic = { 6717 .f = cmd_set_vf_traffic_parsed, 6718 .data = NULL, 6719 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 6720 .tokens = { 6721 (void *)&cmd_setvf_traffic_set, 6722 (void *)&cmd_setvf_traffic_port, 6723 (void *)&cmd_setvf_traffic_portid, 6724 (void *)&cmd_setvf_traffic_vf, 6725 (void *)&cmd_setvf_traffic_vfid, 6726 (void *)&cmd_setvf_traffic_what, 6727 (void *)&cmd_setvf_traffic_mode, 6728 NULL, 6729 }, 6730 }; 6731 6732 /* *** CONFIGURE VF RECEIVE MODE *** */ 6733 struct cmd_set_vf_rxmode { 6734 cmdline_fixed_string_t set; 6735 cmdline_fixed_string_t port; 6736 uint8_t port_id; 6737 cmdline_fixed_string_t vf; 6738 uint8_t vf_id; 6739 cmdline_fixed_string_t what; 6740 cmdline_fixed_string_t mode; 6741 cmdline_fixed_string_t on; 6742 }; 6743 6744 static void 6745 cmd_set_vf_rxmode_parsed(void *parsed_result, 6746 __attribute__((unused)) struct cmdline *cl, 6747 __attribute__((unused)) void *data) 6748 { 6749 int ret; 6750 uint16_t rx_mode = 0; 6751 struct cmd_set_vf_rxmode *res = parsed_result; 6752 6753 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 6754 if (!strcmp(res->what,"rxmode")) { 6755 if (!strcmp(res->mode, "AUPE")) 6756 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 6757 else if (!strcmp(res->mode, "ROPE")) 6758 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 6759 else if (!strcmp(res->mode, "BAM")) 6760 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 6761 else if (!strncmp(res->mode, "MPE",3)) 6762 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 6763 } 6764 6765 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on); 6766 if (ret < 0) 6767 printf("bad VF receive mode parameter, return code = %d \n", 6768 ret); 6769 } 6770 6771 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 6772 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6773 set, "set"); 6774 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 6775 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6776 port, "port"); 6777 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 6778 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6779 port_id, UINT8); 6780 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 6781 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6782 vf, "vf"); 6783 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 6784 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6785 vf_id, UINT8); 6786 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 6787 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6788 what, "rxmode"); 6789 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 6790 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6791 mode, "AUPE#ROPE#BAM#MPE"); 6792 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 6793 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6794 on, "on#off"); 6795 6796 cmdline_parse_inst_t cmd_set_vf_rxmode = { 6797 .f = cmd_set_vf_rxmode_parsed, 6798 .data = NULL, 6799 .help_str = "set port <port_id> vf <vf_id> rxmode " 6800 "AUPE|ROPE|BAM|MPE on|off", 6801 .tokens = { 6802 (void *)&cmd_set_vf_rxmode_set, 6803 (void *)&cmd_set_vf_rxmode_port, 6804 (void *)&cmd_set_vf_rxmode_portid, 6805 (void *)&cmd_set_vf_rxmode_vf, 6806 (void *)&cmd_set_vf_rxmode_vfid, 6807 (void *)&cmd_set_vf_rxmode_what, 6808 (void *)&cmd_set_vf_rxmode_mode, 6809 (void *)&cmd_set_vf_rxmode_on, 6810 NULL, 6811 }, 6812 }; 6813 #endif 6814 6815 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 6816 struct cmd_vf_mac_addr_result { 6817 cmdline_fixed_string_t mac_addr_cmd; 6818 cmdline_fixed_string_t what; 6819 cmdline_fixed_string_t port; 6820 uint8_t port_num; 6821 cmdline_fixed_string_t vf; 6822 uint8_t vf_num; 6823 struct ether_addr address; 6824 }; 6825 6826 static void cmd_vf_mac_addr_parsed(void *parsed_result, 6827 __attribute__((unused)) struct cmdline *cl, 6828 __attribute__((unused)) void *data) 6829 { 6830 struct cmd_vf_mac_addr_result *res = parsed_result; 6831 int ret = 0; 6832 6833 if (strcmp(res->what, "add") == 0) 6834 ret = rte_eth_dev_mac_addr_add(res->port_num, 6835 &res->address, res->vf_num); 6836 if(ret < 0) 6837 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 6838 6839 } 6840 6841 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 6842 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6843 mac_addr_cmd,"mac_addr"); 6844 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 6845 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6846 what,"add"); 6847 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 6848 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6849 port,"port"); 6850 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 6851 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6852 port_num, UINT8); 6853 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 6854 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6855 vf,"vf"); 6856 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 6857 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6858 vf_num, UINT8); 6859 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 6860 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 6861 address); 6862 6863 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 6864 .f = cmd_vf_mac_addr_parsed, 6865 .data = (void *)0, 6866 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 6867 "Add MAC address filtering for a VF on port_id", 6868 .tokens = { 6869 (void *)&cmd_vf_mac_addr_cmd, 6870 (void *)&cmd_vf_mac_addr_what, 6871 (void *)&cmd_vf_mac_addr_port, 6872 (void *)&cmd_vf_mac_addr_portnum, 6873 (void *)&cmd_vf_mac_addr_vf, 6874 (void *)&cmd_vf_mac_addr_vfnum, 6875 (void *)&cmd_vf_mac_addr_addr, 6876 NULL, 6877 }, 6878 }; 6879 6880 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 6881 struct cmd_vf_rx_vlan_filter { 6882 cmdline_fixed_string_t rx_vlan; 6883 cmdline_fixed_string_t what; 6884 uint16_t vlan_id; 6885 cmdline_fixed_string_t port; 6886 uint8_t port_id; 6887 cmdline_fixed_string_t vf; 6888 uint64_t vf_mask; 6889 }; 6890 6891 static void 6892 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 6893 __attribute__((unused)) struct cmdline *cl, 6894 __attribute__((unused)) void *data) 6895 { 6896 struct cmd_vf_rx_vlan_filter *res = parsed_result; 6897 int ret = -ENOTSUP; 6898 6899 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 6900 6901 #ifdef RTE_LIBRTE_IXGBE_PMD 6902 if (ret == -ENOTSUP) 6903 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 6904 res->vlan_id, res->vf_mask, is_add); 6905 #endif 6906 #ifdef RTE_LIBRTE_I40E_PMD 6907 if (ret == -ENOTSUP) 6908 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 6909 res->vlan_id, res->vf_mask, is_add); 6910 #endif 6911 6912 switch (ret) { 6913 case 0: 6914 break; 6915 case -EINVAL: 6916 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n", 6917 res->vlan_id, res->vf_mask); 6918 break; 6919 case -ENODEV: 6920 printf("invalid port_id %d\n", res->port_id); 6921 break; 6922 case -ENOTSUP: 6923 printf("function not implemented or supported\n"); 6924 break; 6925 default: 6926 printf("programming error: (%s)\n", strerror(-ret)); 6927 } 6928 } 6929 6930 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 6931 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6932 rx_vlan, "rx_vlan"); 6933 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 6934 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6935 what, "add#rm"); 6936 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 6937 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6938 vlan_id, UINT16); 6939 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 6940 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6941 port, "port"); 6942 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 6943 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6944 port_id, UINT8); 6945 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 6946 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6947 vf, "vf"); 6948 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 6949 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6950 vf_mask, UINT64); 6951 6952 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 6953 .f = cmd_vf_rx_vlan_filter_parsed, 6954 .data = NULL, 6955 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 6956 "(vf_mask = hexadecimal VF mask)", 6957 .tokens = { 6958 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 6959 (void *)&cmd_vf_rx_vlan_filter_what, 6960 (void *)&cmd_vf_rx_vlan_filter_vlanid, 6961 (void *)&cmd_vf_rx_vlan_filter_port, 6962 (void *)&cmd_vf_rx_vlan_filter_portid, 6963 (void *)&cmd_vf_rx_vlan_filter_vf, 6964 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 6965 NULL, 6966 }, 6967 }; 6968 6969 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 6970 struct cmd_queue_rate_limit_result { 6971 cmdline_fixed_string_t set; 6972 cmdline_fixed_string_t port; 6973 uint8_t port_num; 6974 cmdline_fixed_string_t queue; 6975 uint8_t queue_num; 6976 cmdline_fixed_string_t rate; 6977 uint16_t rate_num; 6978 }; 6979 6980 static void cmd_queue_rate_limit_parsed(void *parsed_result, 6981 __attribute__((unused)) struct cmdline *cl, 6982 __attribute__((unused)) void *data) 6983 { 6984 struct cmd_queue_rate_limit_result *res = parsed_result; 6985 int ret = 0; 6986 6987 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 6988 && (strcmp(res->queue, "queue") == 0) 6989 && (strcmp(res->rate, "rate") == 0)) 6990 ret = set_queue_rate_limit(res->port_num, res->queue_num, 6991 res->rate_num); 6992 if (ret < 0) 6993 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 6994 6995 } 6996 6997 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 6998 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 6999 set, "set"); 7000 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 7001 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7002 port, "port"); 7003 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 7004 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7005 port_num, UINT8); 7006 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 7007 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7008 queue, "queue"); 7009 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 7010 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7011 queue_num, UINT8); 7012 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 7013 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7014 rate, "rate"); 7015 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 7016 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7017 rate_num, UINT16); 7018 7019 cmdline_parse_inst_t cmd_queue_rate_limit = { 7020 .f = cmd_queue_rate_limit_parsed, 7021 .data = (void *)0, 7022 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 7023 "Set rate limit for a queue on port_id", 7024 .tokens = { 7025 (void *)&cmd_queue_rate_limit_set, 7026 (void *)&cmd_queue_rate_limit_port, 7027 (void *)&cmd_queue_rate_limit_portnum, 7028 (void *)&cmd_queue_rate_limit_queue, 7029 (void *)&cmd_queue_rate_limit_queuenum, 7030 (void *)&cmd_queue_rate_limit_rate, 7031 (void *)&cmd_queue_rate_limit_ratenum, 7032 NULL, 7033 }, 7034 }; 7035 7036 #ifdef RTE_LIBRTE_IXGBE_PMD 7037 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 7038 struct cmd_vf_rate_limit_result { 7039 cmdline_fixed_string_t set; 7040 cmdline_fixed_string_t port; 7041 uint8_t port_num; 7042 cmdline_fixed_string_t vf; 7043 uint8_t vf_num; 7044 cmdline_fixed_string_t rate; 7045 uint16_t rate_num; 7046 cmdline_fixed_string_t q_msk; 7047 uint64_t q_msk_val; 7048 }; 7049 7050 static void cmd_vf_rate_limit_parsed(void *parsed_result, 7051 __attribute__((unused)) struct cmdline *cl, 7052 __attribute__((unused)) void *data) 7053 { 7054 struct cmd_vf_rate_limit_result *res = parsed_result; 7055 int ret = 0; 7056 7057 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7058 && (strcmp(res->vf, "vf") == 0) 7059 && (strcmp(res->rate, "rate") == 0) 7060 && (strcmp(res->q_msk, "queue_mask") == 0)) 7061 ret = set_vf_rate_limit(res->port_num, res->vf_num, 7062 res->rate_num, res->q_msk_val); 7063 if (ret < 0) 7064 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7065 7066 } 7067 7068 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 7069 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7070 set, "set"); 7071 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 7072 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7073 port, "port"); 7074 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 7075 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7076 port_num, UINT8); 7077 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 7078 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7079 vf, "vf"); 7080 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 7081 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7082 vf_num, UINT8); 7083 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 7084 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7085 rate, "rate"); 7086 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 7087 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7088 rate_num, UINT16); 7089 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 7090 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7091 q_msk, "queue_mask"); 7092 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 7093 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7094 q_msk_val, UINT64); 7095 7096 cmdline_parse_inst_t cmd_vf_rate_limit = { 7097 .f = cmd_vf_rate_limit_parsed, 7098 .data = (void *)0, 7099 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 7100 "queue_mask <queue_mask_value>: " 7101 "Set rate limit for queues of VF on port_id", 7102 .tokens = { 7103 (void *)&cmd_vf_rate_limit_set, 7104 (void *)&cmd_vf_rate_limit_port, 7105 (void *)&cmd_vf_rate_limit_portnum, 7106 (void *)&cmd_vf_rate_limit_vf, 7107 (void *)&cmd_vf_rate_limit_vfnum, 7108 (void *)&cmd_vf_rate_limit_rate, 7109 (void *)&cmd_vf_rate_limit_ratenum, 7110 (void *)&cmd_vf_rate_limit_q_msk, 7111 (void *)&cmd_vf_rate_limit_q_msk_val, 7112 NULL, 7113 }, 7114 }; 7115 #endif 7116 7117 /* *** ADD TUNNEL FILTER OF A PORT *** */ 7118 struct cmd_tunnel_filter_result { 7119 cmdline_fixed_string_t cmd; 7120 cmdline_fixed_string_t what; 7121 uint8_t port_id; 7122 struct ether_addr outer_mac; 7123 struct ether_addr inner_mac; 7124 cmdline_ipaddr_t ip_value; 7125 uint16_t inner_vlan; 7126 cmdline_fixed_string_t tunnel_type; 7127 cmdline_fixed_string_t filter_type; 7128 uint32_t tenant_id; 7129 uint16_t queue_num; 7130 }; 7131 7132 static void 7133 cmd_tunnel_filter_parsed(void *parsed_result, 7134 __attribute__((unused)) struct cmdline *cl, 7135 __attribute__((unused)) void *data) 7136 { 7137 struct cmd_tunnel_filter_result *res = parsed_result; 7138 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 7139 int ret = 0; 7140 7141 memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf)); 7142 7143 ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac); 7144 ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac); 7145 tunnel_filter_conf.inner_vlan = res->inner_vlan; 7146 7147 if (res->ip_value.family == AF_INET) { 7148 tunnel_filter_conf.ip_addr.ipv4_addr = 7149 res->ip_value.addr.ipv4.s_addr; 7150 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 7151 } else { 7152 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 7153 &(res->ip_value.addr.ipv6), 7154 sizeof(struct in6_addr)); 7155 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 7156 } 7157 7158 if (!strcmp(res->filter_type, "imac-ivlan")) 7159 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 7160 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 7161 tunnel_filter_conf.filter_type = 7162 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 7163 else if (!strcmp(res->filter_type, "imac-tenid")) 7164 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 7165 else if (!strcmp(res->filter_type, "imac")) 7166 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 7167 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 7168 tunnel_filter_conf.filter_type = 7169 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 7170 else if (!strcmp(res->filter_type, "oip")) 7171 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP; 7172 else if (!strcmp(res->filter_type, "iip")) 7173 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP; 7174 else { 7175 printf("The filter type is not supported"); 7176 return; 7177 } 7178 7179 if (!strcmp(res->tunnel_type, "vxlan")) 7180 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 7181 else if (!strcmp(res->tunnel_type, "nvgre")) 7182 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 7183 else if (!strcmp(res->tunnel_type, "ipingre")) 7184 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE; 7185 else { 7186 printf("The tunnel type %s not supported.\n", res->tunnel_type); 7187 return; 7188 } 7189 7190 tunnel_filter_conf.tenant_id = res->tenant_id; 7191 tunnel_filter_conf.queue_id = res->queue_num; 7192 if (!strcmp(res->what, "add")) 7193 ret = rte_eth_dev_filter_ctrl(res->port_id, 7194 RTE_ETH_FILTER_TUNNEL, 7195 RTE_ETH_FILTER_ADD, 7196 &tunnel_filter_conf); 7197 else 7198 ret = rte_eth_dev_filter_ctrl(res->port_id, 7199 RTE_ETH_FILTER_TUNNEL, 7200 RTE_ETH_FILTER_DELETE, 7201 &tunnel_filter_conf); 7202 if (ret < 0) 7203 printf("cmd_tunnel_filter_parsed error: (%s)\n", 7204 strerror(-ret)); 7205 7206 } 7207 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 7208 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7209 cmd, "tunnel_filter"); 7210 cmdline_parse_token_string_t cmd_tunnel_filter_what = 7211 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7212 what, "add#rm"); 7213 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 7214 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7215 port_id, UINT8); 7216 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 7217 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7218 outer_mac); 7219 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 7220 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7221 inner_mac); 7222 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 7223 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7224 inner_vlan, UINT16); 7225 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 7226 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7227 ip_value); 7228 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 7229 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7230 tunnel_type, "vxlan#nvgre#ipingre"); 7231 7232 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 7233 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7234 filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#" 7235 "imac#omac-imac-tenid"); 7236 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 7237 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7238 tenant_id, UINT32); 7239 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 7240 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7241 queue_num, UINT16); 7242 7243 cmdline_parse_inst_t cmd_tunnel_filter = { 7244 .f = cmd_tunnel_filter_parsed, 7245 .data = (void *)0, 7246 .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> " 7247 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|" 7248 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> " 7249 "<queue_id>: Add/Rm tunnel filter of a port", 7250 .tokens = { 7251 (void *)&cmd_tunnel_filter_cmd, 7252 (void *)&cmd_tunnel_filter_what, 7253 (void *)&cmd_tunnel_filter_port_id, 7254 (void *)&cmd_tunnel_filter_outer_mac, 7255 (void *)&cmd_tunnel_filter_inner_mac, 7256 (void *)&cmd_tunnel_filter_ip_value, 7257 (void *)&cmd_tunnel_filter_innner_vlan, 7258 (void *)&cmd_tunnel_filter_tunnel_type, 7259 (void *)&cmd_tunnel_filter_filter_type, 7260 (void *)&cmd_tunnel_filter_tenant_id, 7261 (void *)&cmd_tunnel_filter_queue_num, 7262 NULL, 7263 }, 7264 }; 7265 7266 /* *** CONFIGURE TUNNEL UDP PORT *** */ 7267 struct cmd_tunnel_udp_config { 7268 cmdline_fixed_string_t cmd; 7269 cmdline_fixed_string_t what; 7270 uint16_t udp_port; 7271 uint8_t port_id; 7272 }; 7273 7274 static void 7275 cmd_tunnel_udp_config_parsed(void *parsed_result, 7276 __attribute__((unused)) struct cmdline *cl, 7277 __attribute__((unused)) void *data) 7278 { 7279 struct cmd_tunnel_udp_config *res = parsed_result; 7280 struct rte_eth_udp_tunnel tunnel_udp; 7281 int ret; 7282 7283 tunnel_udp.udp_port = res->udp_port; 7284 7285 if (!strcmp(res->cmd, "rx_vxlan_port")) 7286 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 7287 7288 if (!strcmp(res->what, "add")) 7289 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 7290 &tunnel_udp); 7291 else 7292 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 7293 &tunnel_udp); 7294 7295 if (ret < 0) 7296 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 7297 } 7298 7299 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 7300 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7301 cmd, "rx_vxlan_port"); 7302 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 7303 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7304 what, "add#rm"); 7305 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 7306 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7307 udp_port, UINT16); 7308 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 7309 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7310 port_id, UINT8); 7311 7312 cmdline_parse_inst_t cmd_tunnel_udp_config = { 7313 .f = cmd_tunnel_udp_config_parsed, 7314 .data = (void *)0, 7315 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 7316 "Add/Remove a tunneling UDP port filter", 7317 .tokens = { 7318 (void *)&cmd_tunnel_udp_config_cmd, 7319 (void *)&cmd_tunnel_udp_config_what, 7320 (void *)&cmd_tunnel_udp_config_udp_port, 7321 (void *)&cmd_tunnel_udp_config_port_id, 7322 NULL, 7323 }, 7324 }; 7325 7326 /* *** GLOBAL CONFIG *** */ 7327 struct cmd_global_config_result { 7328 cmdline_fixed_string_t cmd; 7329 uint8_t port_id; 7330 cmdline_fixed_string_t cfg_type; 7331 uint8_t len; 7332 }; 7333 7334 static void 7335 cmd_global_config_parsed(void *parsed_result, 7336 __attribute__((unused)) struct cmdline *cl, 7337 __attribute__((unused)) void *data) 7338 { 7339 struct cmd_global_config_result *res = parsed_result; 7340 struct rte_eth_global_cfg conf; 7341 int ret; 7342 7343 memset(&conf, 0, sizeof(conf)); 7344 conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN; 7345 conf.cfg.gre_key_len = res->len; 7346 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE, 7347 RTE_ETH_FILTER_SET, &conf); 7348 if (ret != 0) 7349 printf("Global config error\n"); 7350 } 7351 7352 cmdline_parse_token_string_t cmd_global_config_cmd = 7353 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, 7354 "global_config"); 7355 cmdline_parse_token_num_t cmd_global_config_port_id = 7356 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8); 7357 cmdline_parse_token_string_t cmd_global_config_type = 7358 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, 7359 cfg_type, "gre-key-len"); 7360 cmdline_parse_token_num_t cmd_global_config_gre_key_len = 7361 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, 7362 len, UINT8); 7363 7364 cmdline_parse_inst_t cmd_global_config = { 7365 .f = cmd_global_config_parsed, 7366 .data = (void *)NULL, 7367 .help_str = "global_config <port_id> gre-key-len <key_len>", 7368 .tokens = { 7369 (void *)&cmd_global_config_cmd, 7370 (void *)&cmd_global_config_port_id, 7371 (void *)&cmd_global_config_type, 7372 (void *)&cmd_global_config_gre_key_len, 7373 NULL, 7374 }, 7375 }; 7376 7377 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 7378 struct cmd_set_mirror_mask_result { 7379 cmdline_fixed_string_t set; 7380 cmdline_fixed_string_t port; 7381 uint8_t port_id; 7382 cmdline_fixed_string_t mirror; 7383 uint8_t rule_id; 7384 cmdline_fixed_string_t what; 7385 cmdline_fixed_string_t value; 7386 cmdline_fixed_string_t dstpool; 7387 uint8_t dstpool_id; 7388 cmdline_fixed_string_t on; 7389 }; 7390 7391 cmdline_parse_token_string_t cmd_mirror_mask_set = 7392 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7393 set, "set"); 7394 cmdline_parse_token_string_t cmd_mirror_mask_port = 7395 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7396 port, "port"); 7397 cmdline_parse_token_num_t cmd_mirror_mask_portid = 7398 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7399 port_id, UINT8); 7400 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 7401 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7402 mirror, "mirror-rule"); 7403 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 7404 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7405 rule_id, UINT8); 7406 cmdline_parse_token_string_t cmd_mirror_mask_what = 7407 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7408 what, "pool-mirror-up#pool-mirror-down" 7409 "#vlan-mirror"); 7410 cmdline_parse_token_string_t cmd_mirror_mask_value = 7411 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7412 value, NULL); 7413 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 7414 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7415 dstpool, "dst-pool"); 7416 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 7417 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7418 dstpool_id, UINT8); 7419 cmdline_parse_token_string_t cmd_mirror_mask_on = 7420 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7421 on, "on#off"); 7422 7423 static void 7424 cmd_set_mirror_mask_parsed(void *parsed_result, 7425 __attribute__((unused)) struct cmdline *cl, 7426 __attribute__((unused)) void *data) 7427 { 7428 int ret,nb_item,i; 7429 struct cmd_set_mirror_mask_result *res = parsed_result; 7430 struct rte_eth_mirror_conf mr_conf; 7431 7432 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7433 7434 unsigned int vlan_list[ETH_MIRROR_MAX_VLANS]; 7435 7436 mr_conf.dst_pool = res->dstpool_id; 7437 7438 if (!strcmp(res->what, "pool-mirror-up")) { 7439 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7440 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP; 7441 } else if (!strcmp(res->what, "pool-mirror-down")) { 7442 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7443 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN; 7444 } else if (!strcmp(res->what, "vlan-mirror")) { 7445 mr_conf.rule_type = ETH_MIRROR_VLAN; 7446 nb_item = parse_item_list(res->value, "vlan", 7447 ETH_MIRROR_MAX_VLANS, vlan_list, 1); 7448 if (nb_item <= 0) 7449 return; 7450 7451 for (i = 0; i < nb_item; i++) { 7452 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 7453 printf("Invalid vlan_id: must be < 4096\n"); 7454 return; 7455 } 7456 7457 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 7458 mr_conf.vlan.vlan_mask |= 1ULL << i; 7459 } 7460 } 7461 7462 if (!strcmp(res->on, "on")) 7463 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7464 res->rule_id, 1); 7465 else 7466 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7467 res->rule_id, 0); 7468 if (ret < 0) 7469 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7470 } 7471 7472 cmdline_parse_inst_t cmd_set_mirror_mask = { 7473 .f = cmd_set_mirror_mask_parsed, 7474 .data = NULL, 7475 .help_str = "set port <port_id> mirror-rule <rule_id> " 7476 "pool-mirror-up|pool-mirror-down|vlan-mirror " 7477 "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off", 7478 .tokens = { 7479 (void *)&cmd_mirror_mask_set, 7480 (void *)&cmd_mirror_mask_port, 7481 (void *)&cmd_mirror_mask_portid, 7482 (void *)&cmd_mirror_mask_mirror, 7483 (void *)&cmd_mirror_mask_ruleid, 7484 (void *)&cmd_mirror_mask_what, 7485 (void *)&cmd_mirror_mask_value, 7486 (void *)&cmd_mirror_mask_dstpool, 7487 (void *)&cmd_mirror_mask_poolid, 7488 (void *)&cmd_mirror_mask_on, 7489 NULL, 7490 }, 7491 }; 7492 7493 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */ 7494 struct cmd_set_mirror_link_result { 7495 cmdline_fixed_string_t set; 7496 cmdline_fixed_string_t port; 7497 uint8_t port_id; 7498 cmdline_fixed_string_t mirror; 7499 uint8_t rule_id; 7500 cmdline_fixed_string_t what; 7501 cmdline_fixed_string_t dstpool; 7502 uint8_t dstpool_id; 7503 cmdline_fixed_string_t on; 7504 }; 7505 7506 cmdline_parse_token_string_t cmd_mirror_link_set = 7507 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7508 set, "set"); 7509 cmdline_parse_token_string_t cmd_mirror_link_port = 7510 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7511 port, "port"); 7512 cmdline_parse_token_num_t cmd_mirror_link_portid = 7513 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7514 port_id, UINT8); 7515 cmdline_parse_token_string_t cmd_mirror_link_mirror = 7516 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7517 mirror, "mirror-rule"); 7518 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 7519 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7520 rule_id, UINT8); 7521 cmdline_parse_token_string_t cmd_mirror_link_what = 7522 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7523 what, "uplink-mirror#downlink-mirror"); 7524 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 7525 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7526 dstpool, "dst-pool"); 7527 cmdline_parse_token_num_t cmd_mirror_link_poolid = 7528 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7529 dstpool_id, UINT8); 7530 cmdline_parse_token_string_t cmd_mirror_link_on = 7531 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7532 on, "on#off"); 7533 7534 static void 7535 cmd_set_mirror_link_parsed(void *parsed_result, 7536 __attribute__((unused)) struct cmdline *cl, 7537 __attribute__((unused)) void *data) 7538 { 7539 int ret; 7540 struct cmd_set_mirror_link_result *res = parsed_result; 7541 struct rte_eth_mirror_conf mr_conf; 7542 7543 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7544 if (!strcmp(res->what, "uplink-mirror")) 7545 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT; 7546 else 7547 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT; 7548 7549 mr_conf.dst_pool = res->dstpool_id; 7550 7551 if (!strcmp(res->on, "on")) 7552 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7553 res->rule_id, 1); 7554 else 7555 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7556 res->rule_id, 0); 7557 7558 /* check the return value and print it if is < 0 */ 7559 if (ret < 0) 7560 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7561 7562 } 7563 7564 cmdline_parse_inst_t cmd_set_mirror_link = { 7565 .f = cmd_set_mirror_link_parsed, 7566 .data = NULL, 7567 .help_str = "set port <port_id> mirror-rule <rule_id> " 7568 "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off", 7569 .tokens = { 7570 (void *)&cmd_mirror_link_set, 7571 (void *)&cmd_mirror_link_port, 7572 (void *)&cmd_mirror_link_portid, 7573 (void *)&cmd_mirror_link_mirror, 7574 (void *)&cmd_mirror_link_ruleid, 7575 (void *)&cmd_mirror_link_what, 7576 (void *)&cmd_mirror_link_dstpool, 7577 (void *)&cmd_mirror_link_poolid, 7578 (void *)&cmd_mirror_link_on, 7579 NULL, 7580 }, 7581 }; 7582 7583 /* *** RESET VM MIRROR RULE *** */ 7584 struct cmd_rm_mirror_rule_result { 7585 cmdline_fixed_string_t reset; 7586 cmdline_fixed_string_t port; 7587 uint8_t port_id; 7588 cmdline_fixed_string_t mirror; 7589 uint8_t rule_id; 7590 }; 7591 7592 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 7593 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7594 reset, "reset"); 7595 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 7596 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7597 port, "port"); 7598 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 7599 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7600 port_id, UINT8); 7601 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 7602 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7603 mirror, "mirror-rule"); 7604 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 7605 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7606 rule_id, UINT8); 7607 7608 static void 7609 cmd_reset_mirror_rule_parsed(void *parsed_result, 7610 __attribute__((unused)) struct cmdline *cl, 7611 __attribute__((unused)) void *data) 7612 { 7613 int ret; 7614 struct cmd_set_mirror_link_result *res = parsed_result; 7615 /* check rule_id */ 7616 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 7617 if(ret < 0) 7618 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 7619 } 7620 7621 cmdline_parse_inst_t cmd_reset_mirror_rule = { 7622 .f = cmd_reset_mirror_rule_parsed, 7623 .data = NULL, 7624 .help_str = "reset port <port_id> mirror-rule <rule_id>", 7625 .tokens = { 7626 (void *)&cmd_rm_mirror_rule_reset, 7627 (void *)&cmd_rm_mirror_rule_port, 7628 (void *)&cmd_rm_mirror_rule_portid, 7629 (void *)&cmd_rm_mirror_rule_mirror, 7630 (void *)&cmd_rm_mirror_rule_ruleid, 7631 NULL, 7632 }, 7633 }; 7634 7635 /* ******************************************************************************** */ 7636 7637 struct cmd_dump_result { 7638 cmdline_fixed_string_t dump; 7639 }; 7640 7641 static void 7642 dump_struct_sizes(void) 7643 { 7644 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 7645 DUMP_SIZE(struct rte_mbuf); 7646 DUMP_SIZE(struct rte_mempool); 7647 DUMP_SIZE(struct rte_ring); 7648 #undef DUMP_SIZE 7649 } 7650 7651 static void cmd_dump_parsed(void *parsed_result, 7652 __attribute__((unused)) struct cmdline *cl, 7653 __attribute__((unused)) void *data) 7654 { 7655 struct cmd_dump_result *res = parsed_result; 7656 7657 if (!strcmp(res->dump, "dump_physmem")) 7658 rte_dump_physmem_layout(stdout); 7659 else if (!strcmp(res->dump, "dump_memzone")) 7660 rte_memzone_dump(stdout); 7661 else if (!strcmp(res->dump, "dump_struct_sizes")) 7662 dump_struct_sizes(); 7663 else if (!strcmp(res->dump, "dump_ring")) 7664 rte_ring_list_dump(stdout); 7665 else if (!strcmp(res->dump, "dump_mempool")) 7666 rte_mempool_list_dump(stdout); 7667 else if (!strcmp(res->dump, "dump_devargs")) 7668 rte_eal_devargs_dump(stdout); 7669 } 7670 7671 cmdline_parse_token_string_t cmd_dump_dump = 7672 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 7673 "dump_physmem#" 7674 "dump_memzone#" 7675 "dump_struct_sizes#" 7676 "dump_ring#" 7677 "dump_mempool#" 7678 "dump_devargs"); 7679 7680 cmdline_parse_inst_t cmd_dump = { 7681 .f = cmd_dump_parsed, /* function to call */ 7682 .data = NULL, /* 2nd arg of func */ 7683 .help_str = "Dump status", 7684 .tokens = { /* token list, NULL terminated */ 7685 (void *)&cmd_dump_dump, 7686 NULL, 7687 }, 7688 }; 7689 7690 /* ******************************************************************************** */ 7691 7692 struct cmd_dump_one_result { 7693 cmdline_fixed_string_t dump; 7694 cmdline_fixed_string_t name; 7695 }; 7696 7697 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 7698 __attribute__((unused)) void *data) 7699 { 7700 struct cmd_dump_one_result *res = parsed_result; 7701 7702 if (!strcmp(res->dump, "dump_ring")) { 7703 struct rte_ring *r; 7704 r = rte_ring_lookup(res->name); 7705 if (r == NULL) { 7706 cmdline_printf(cl, "Cannot find ring\n"); 7707 return; 7708 } 7709 rte_ring_dump(stdout, r); 7710 } else if (!strcmp(res->dump, "dump_mempool")) { 7711 struct rte_mempool *mp; 7712 mp = rte_mempool_lookup(res->name); 7713 if (mp == NULL) { 7714 cmdline_printf(cl, "Cannot find mempool\n"); 7715 return; 7716 } 7717 rte_mempool_dump(stdout, mp); 7718 } 7719 } 7720 7721 cmdline_parse_token_string_t cmd_dump_one_dump = 7722 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 7723 "dump_ring#dump_mempool"); 7724 7725 cmdline_parse_token_string_t cmd_dump_one_name = 7726 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 7727 7728 cmdline_parse_inst_t cmd_dump_one = { 7729 .f = cmd_dump_one_parsed, /* function to call */ 7730 .data = NULL, /* 2nd arg of func */ 7731 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 7732 .tokens = { /* token list, NULL terminated */ 7733 (void *)&cmd_dump_one_dump, 7734 (void *)&cmd_dump_one_name, 7735 NULL, 7736 }, 7737 }; 7738 7739 /* *** Add/Del syn filter *** */ 7740 struct cmd_syn_filter_result { 7741 cmdline_fixed_string_t filter; 7742 uint8_t port_id; 7743 cmdline_fixed_string_t ops; 7744 cmdline_fixed_string_t priority; 7745 cmdline_fixed_string_t high; 7746 cmdline_fixed_string_t queue; 7747 uint16_t queue_id; 7748 }; 7749 7750 static void 7751 cmd_syn_filter_parsed(void *parsed_result, 7752 __attribute__((unused)) struct cmdline *cl, 7753 __attribute__((unused)) void *data) 7754 { 7755 struct cmd_syn_filter_result *res = parsed_result; 7756 struct rte_eth_syn_filter syn_filter; 7757 int ret = 0; 7758 7759 ret = rte_eth_dev_filter_supported(res->port_id, 7760 RTE_ETH_FILTER_SYN); 7761 if (ret < 0) { 7762 printf("syn filter is not supported on port %u.\n", 7763 res->port_id); 7764 return; 7765 } 7766 7767 memset(&syn_filter, 0, sizeof(syn_filter)); 7768 7769 if (!strcmp(res->ops, "add")) { 7770 if (!strcmp(res->high, "high")) 7771 syn_filter.hig_pri = 1; 7772 else 7773 syn_filter.hig_pri = 0; 7774 7775 syn_filter.queue = res->queue_id; 7776 ret = rte_eth_dev_filter_ctrl(res->port_id, 7777 RTE_ETH_FILTER_SYN, 7778 RTE_ETH_FILTER_ADD, 7779 &syn_filter); 7780 } else 7781 ret = rte_eth_dev_filter_ctrl(res->port_id, 7782 RTE_ETH_FILTER_SYN, 7783 RTE_ETH_FILTER_DELETE, 7784 &syn_filter); 7785 7786 if (ret < 0) 7787 printf("syn filter programming error: (%s)\n", 7788 strerror(-ret)); 7789 } 7790 7791 cmdline_parse_token_string_t cmd_syn_filter_filter = 7792 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7793 filter, "syn_filter"); 7794 cmdline_parse_token_num_t cmd_syn_filter_port_id = 7795 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 7796 port_id, UINT8); 7797 cmdline_parse_token_string_t cmd_syn_filter_ops = 7798 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7799 ops, "add#del"); 7800 cmdline_parse_token_string_t cmd_syn_filter_priority = 7801 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7802 priority, "priority"); 7803 cmdline_parse_token_string_t cmd_syn_filter_high = 7804 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7805 high, "high#low"); 7806 cmdline_parse_token_string_t cmd_syn_filter_queue = 7807 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7808 queue, "queue"); 7809 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 7810 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 7811 queue_id, UINT16); 7812 7813 cmdline_parse_inst_t cmd_syn_filter = { 7814 .f = cmd_syn_filter_parsed, 7815 .data = NULL, 7816 .help_str = "syn_filter <port_id> add|del priority high|low queue " 7817 "<queue_id>: Add/Delete syn filter", 7818 .tokens = { 7819 (void *)&cmd_syn_filter_filter, 7820 (void *)&cmd_syn_filter_port_id, 7821 (void *)&cmd_syn_filter_ops, 7822 (void *)&cmd_syn_filter_priority, 7823 (void *)&cmd_syn_filter_high, 7824 (void *)&cmd_syn_filter_queue, 7825 (void *)&cmd_syn_filter_queue_id, 7826 NULL, 7827 }, 7828 }; 7829 7830 /* *** ADD/REMOVE A 2tuple FILTER *** */ 7831 struct cmd_2tuple_filter_result { 7832 cmdline_fixed_string_t filter; 7833 uint8_t port_id; 7834 cmdline_fixed_string_t ops; 7835 cmdline_fixed_string_t dst_port; 7836 uint16_t dst_port_value; 7837 cmdline_fixed_string_t protocol; 7838 uint8_t protocol_value; 7839 cmdline_fixed_string_t mask; 7840 uint8_t mask_value; 7841 cmdline_fixed_string_t tcp_flags; 7842 uint8_t tcp_flags_value; 7843 cmdline_fixed_string_t priority; 7844 uint8_t priority_value; 7845 cmdline_fixed_string_t queue; 7846 uint16_t queue_id; 7847 }; 7848 7849 static void 7850 cmd_2tuple_filter_parsed(void *parsed_result, 7851 __attribute__((unused)) struct cmdline *cl, 7852 __attribute__((unused)) void *data) 7853 { 7854 struct rte_eth_ntuple_filter filter; 7855 struct cmd_2tuple_filter_result *res = parsed_result; 7856 int ret = 0; 7857 7858 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 7859 if (ret < 0) { 7860 printf("ntuple filter is not supported on port %u.\n", 7861 res->port_id); 7862 return; 7863 } 7864 7865 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 7866 7867 filter.flags = RTE_2TUPLE_FLAGS; 7868 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 7869 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 7870 filter.proto = res->protocol_value; 7871 filter.priority = res->priority_value; 7872 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 7873 printf("nonzero tcp_flags is only meaningful" 7874 " when protocol is TCP.\n"); 7875 return; 7876 } 7877 if (res->tcp_flags_value > TCP_FLAG_ALL) { 7878 printf("invalid TCP flags.\n"); 7879 return; 7880 } 7881 7882 if (res->tcp_flags_value != 0) { 7883 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 7884 filter.tcp_flags = res->tcp_flags_value; 7885 } 7886 7887 /* need convert to big endian. */ 7888 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 7889 filter.queue = res->queue_id; 7890 7891 if (!strcmp(res->ops, "add")) 7892 ret = rte_eth_dev_filter_ctrl(res->port_id, 7893 RTE_ETH_FILTER_NTUPLE, 7894 RTE_ETH_FILTER_ADD, 7895 &filter); 7896 else 7897 ret = rte_eth_dev_filter_ctrl(res->port_id, 7898 RTE_ETH_FILTER_NTUPLE, 7899 RTE_ETH_FILTER_DELETE, 7900 &filter); 7901 if (ret < 0) 7902 printf("2tuple filter programming error: (%s)\n", 7903 strerror(-ret)); 7904 7905 } 7906 7907 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 7908 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7909 filter, "2tuple_filter"); 7910 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 7911 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7912 port_id, UINT8); 7913 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 7914 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7915 ops, "add#del"); 7916 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 7917 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7918 dst_port, "dst_port"); 7919 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 7920 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7921 dst_port_value, UINT16); 7922 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 7923 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7924 protocol, "protocol"); 7925 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 7926 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7927 protocol_value, UINT8); 7928 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 7929 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7930 mask, "mask"); 7931 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 7932 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7933 mask_value, INT8); 7934 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 7935 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7936 tcp_flags, "tcp_flags"); 7937 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 7938 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7939 tcp_flags_value, UINT8); 7940 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 7941 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7942 priority, "priority"); 7943 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 7944 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7945 priority_value, UINT8); 7946 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 7947 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7948 queue, "queue"); 7949 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 7950 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7951 queue_id, UINT16); 7952 7953 cmdline_parse_inst_t cmd_2tuple_filter = { 7954 .f = cmd_2tuple_filter_parsed, 7955 .data = NULL, 7956 .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol " 7957 "<value> mask <value> tcp_flags <value> priority <value> queue " 7958 "<queue_id>: Add a 2tuple filter", 7959 .tokens = { 7960 (void *)&cmd_2tuple_filter_filter, 7961 (void *)&cmd_2tuple_filter_port_id, 7962 (void *)&cmd_2tuple_filter_ops, 7963 (void *)&cmd_2tuple_filter_dst_port, 7964 (void *)&cmd_2tuple_filter_dst_port_value, 7965 (void *)&cmd_2tuple_filter_protocol, 7966 (void *)&cmd_2tuple_filter_protocol_value, 7967 (void *)&cmd_2tuple_filter_mask, 7968 (void *)&cmd_2tuple_filter_mask_value, 7969 (void *)&cmd_2tuple_filter_tcp_flags, 7970 (void *)&cmd_2tuple_filter_tcp_flags_value, 7971 (void *)&cmd_2tuple_filter_priority, 7972 (void *)&cmd_2tuple_filter_priority_value, 7973 (void *)&cmd_2tuple_filter_queue, 7974 (void *)&cmd_2tuple_filter_queue_id, 7975 NULL, 7976 }, 7977 }; 7978 7979 /* *** ADD/REMOVE A 5tuple FILTER *** */ 7980 struct cmd_5tuple_filter_result { 7981 cmdline_fixed_string_t filter; 7982 uint8_t port_id; 7983 cmdline_fixed_string_t ops; 7984 cmdline_fixed_string_t dst_ip; 7985 cmdline_ipaddr_t dst_ip_value; 7986 cmdline_fixed_string_t src_ip; 7987 cmdline_ipaddr_t src_ip_value; 7988 cmdline_fixed_string_t dst_port; 7989 uint16_t dst_port_value; 7990 cmdline_fixed_string_t src_port; 7991 uint16_t src_port_value; 7992 cmdline_fixed_string_t protocol; 7993 uint8_t protocol_value; 7994 cmdline_fixed_string_t mask; 7995 uint8_t mask_value; 7996 cmdline_fixed_string_t tcp_flags; 7997 uint8_t tcp_flags_value; 7998 cmdline_fixed_string_t priority; 7999 uint8_t priority_value; 8000 cmdline_fixed_string_t queue; 8001 uint16_t queue_id; 8002 }; 8003 8004 static void 8005 cmd_5tuple_filter_parsed(void *parsed_result, 8006 __attribute__((unused)) struct cmdline *cl, 8007 __attribute__((unused)) void *data) 8008 { 8009 struct rte_eth_ntuple_filter filter; 8010 struct cmd_5tuple_filter_result *res = parsed_result; 8011 int ret = 0; 8012 8013 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 8014 if (ret < 0) { 8015 printf("ntuple filter is not supported on port %u.\n", 8016 res->port_id); 8017 return; 8018 } 8019 8020 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 8021 8022 filter.flags = RTE_5TUPLE_FLAGS; 8023 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 8024 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 8025 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 8026 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 8027 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 8028 filter.proto = res->protocol_value; 8029 filter.priority = res->priority_value; 8030 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 8031 printf("nonzero tcp_flags is only meaningful" 8032 " when protocol is TCP.\n"); 8033 return; 8034 } 8035 if (res->tcp_flags_value > TCP_FLAG_ALL) { 8036 printf("invalid TCP flags.\n"); 8037 return; 8038 } 8039 8040 if (res->tcp_flags_value != 0) { 8041 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 8042 filter.tcp_flags = res->tcp_flags_value; 8043 } 8044 8045 if (res->dst_ip_value.family == AF_INET) 8046 /* no need to convert, already big endian. */ 8047 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 8048 else { 8049 if (filter.dst_ip_mask == 0) { 8050 printf("can not support ipv6 involved compare.\n"); 8051 return; 8052 } 8053 filter.dst_ip = 0; 8054 } 8055 8056 if (res->src_ip_value.family == AF_INET) 8057 /* no need to convert, already big endian. */ 8058 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 8059 else { 8060 if (filter.src_ip_mask == 0) { 8061 printf("can not support ipv6 involved compare.\n"); 8062 return; 8063 } 8064 filter.src_ip = 0; 8065 } 8066 /* need convert to big endian. */ 8067 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 8068 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 8069 filter.queue = res->queue_id; 8070 8071 if (!strcmp(res->ops, "add")) 8072 ret = rte_eth_dev_filter_ctrl(res->port_id, 8073 RTE_ETH_FILTER_NTUPLE, 8074 RTE_ETH_FILTER_ADD, 8075 &filter); 8076 else 8077 ret = rte_eth_dev_filter_ctrl(res->port_id, 8078 RTE_ETH_FILTER_NTUPLE, 8079 RTE_ETH_FILTER_DELETE, 8080 &filter); 8081 if (ret < 0) 8082 printf("5tuple filter programming error: (%s)\n", 8083 strerror(-ret)); 8084 } 8085 8086 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 8087 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8088 filter, "5tuple_filter"); 8089 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 8090 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8091 port_id, UINT8); 8092 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 8093 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8094 ops, "add#del"); 8095 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 8096 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8097 dst_ip, "dst_ip"); 8098 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 8099 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8100 dst_ip_value); 8101 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 8102 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8103 src_ip, "src_ip"); 8104 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 8105 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8106 src_ip_value); 8107 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 8108 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8109 dst_port, "dst_port"); 8110 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 8111 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8112 dst_port_value, UINT16); 8113 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 8114 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8115 src_port, "src_port"); 8116 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 8117 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8118 src_port_value, UINT16); 8119 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 8120 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8121 protocol, "protocol"); 8122 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 8123 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8124 protocol_value, UINT8); 8125 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 8126 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8127 mask, "mask"); 8128 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 8129 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8130 mask_value, INT8); 8131 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 8132 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8133 tcp_flags, "tcp_flags"); 8134 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 8135 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8136 tcp_flags_value, UINT8); 8137 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 8138 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8139 priority, "priority"); 8140 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 8141 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8142 priority_value, UINT8); 8143 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 8144 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8145 queue, "queue"); 8146 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 8147 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8148 queue_id, UINT16); 8149 8150 cmdline_parse_inst_t cmd_5tuple_filter = { 8151 .f = cmd_5tuple_filter_parsed, 8152 .data = NULL, 8153 .help_str = "5tuple_filter <port_id> add|del dst_ip <value> " 8154 "src_ip <value> dst_port <value> src_port <value> " 8155 "protocol <value> mask <value> tcp_flags <value> " 8156 "priority <value> queue <queue_id>: Add/Del a 5tuple filter", 8157 .tokens = { 8158 (void *)&cmd_5tuple_filter_filter, 8159 (void *)&cmd_5tuple_filter_port_id, 8160 (void *)&cmd_5tuple_filter_ops, 8161 (void *)&cmd_5tuple_filter_dst_ip, 8162 (void *)&cmd_5tuple_filter_dst_ip_value, 8163 (void *)&cmd_5tuple_filter_src_ip, 8164 (void *)&cmd_5tuple_filter_src_ip_value, 8165 (void *)&cmd_5tuple_filter_dst_port, 8166 (void *)&cmd_5tuple_filter_dst_port_value, 8167 (void *)&cmd_5tuple_filter_src_port, 8168 (void *)&cmd_5tuple_filter_src_port_value, 8169 (void *)&cmd_5tuple_filter_protocol, 8170 (void *)&cmd_5tuple_filter_protocol_value, 8171 (void *)&cmd_5tuple_filter_mask, 8172 (void *)&cmd_5tuple_filter_mask_value, 8173 (void *)&cmd_5tuple_filter_tcp_flags, 8174 (void *)&cmd_5tuple_filter_tcp_flags_value, 8175 (void *)&cmd_5tuple_filter_priority, 8176 (void *)&cmd_5tuple_filter_priority_value, 8177 (void *)&cmd_5tuple_filter_queue, 8178 (void *)&cmd_5tuple_filter_queue_id, 8179 NULL, 8180 }, 8181 }; 8182 8183 /* *** ADD/REMOVE A flex FILTER *** */ 8184 struct cmd_flex_filter_result { 8185 cmdline_fixed_string_t filter; 8186 cmdline_fixed_string_t ops; 8187 uint8_t port_id; 8188 cmdline_fixed_string_t len; 8189 uint8_t len_value; 8190 cmdline_fixed_string_t bytes; 8191 cmdline_fixed_string_t bytes_value; 8192 cmdline_fixed_string_t mask; 8193 cmdline_fixed_string_t mask_value; 8194 cmdline_fixed_string_t priority; 8195 uint8_t priority_value; 8196 cmdline_fixed_string_t queue; 8197 uint16_t queue_id; 8198 }; 8199 8200 static int xdigit2val(unsigned char c) 8201 { 8202 int val; 8203 if (isdigit(c)) 8204 val = c - '0'; 8205 else if (isupper(c)) 8206 val = c - 'A' + 10; 8207 else 8208 val = c - 'a' + 10; 8209 return val; 8210 } 8211 8212 static void 8213 cmd_flex_filter_parsed(void *parsed_result, 8214 __attribute__((unused)) struct cmdline *cl, 8215 __attribute__((unused)) void *data) 8216 { 8217 int ret = 0; 8218 struct rte_eth_flex_filter filter; 8219 struct cmd_flex_filter_result *res = parsed_result; 8220 char *bytes_ptr, *mask_ptr; 8221 uint16_t len, i, j = 0; 8222 char c; 8223 int val; 8224 uint8_t byte = 0; 8225 8226 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 8227 printf("the len exceed the max length 128\n"); 8228 return; 8229 } 8230 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 8231 filter.len = res->len_value; 8232 filter.priority = res->priority_value; 8233 filter.queue = res->queue_id; 8234 bytes_ptr = res->bytes_value; 8235 mask_ptr = res->mask_value; 8236 8237 /* translate bytes string to array. */ 8238 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 8239 (bytes_ptr[1] == 'X'))) 8240 bytes_ptr += 2; 8241 len = strnlen(bytes_ptr, res->len_value * 2); 8242 if (len == 0 || (len % 8 != 0)) { 8243 printf("please check len and bytes input\n"); 8244 return; 8245 } 8246 for (i = 0; i < len; i++) { 8247 c = bytes_ptr[i]; 8248 if (isxdigit(c) == 0) { 8249 /* invalid characters. */ 8250 printf("invalid input\n"); 8251 return; 8252 } 8253 val = xdigit2val(c); 8254 if (i % 2) { 8255 byte |= val; 8256 filter.bytes[j] = byte; 8257 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 8258 j++; 8259 byte = 0; 8260 } else 8261 byte |= val << 4; 8262 } 8263 printf("\n"); 8264 /* translate mask string to uint8_t array. */ 8265 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 8266 (mask_ptr[1] == 'X'))) 8267 mask_ptr += 2; 8268 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 8269 if (len == 0) { 8270 printf("invalid input\n"); 8271 return; 8272 } 8273 j = 0; 8274 byte = 0; 8275 for (i = 0; i < len; i++) { 8276 c = mask_ptr[i]; 8277 if (isxdigit(c) == 0) { 8278 /* invalid characters. */ 8279 printf("invalid input\n"); 8280 return; 8281 } 8282 val = xdigit2val(c); 8283 if (i % 2) { 8284 byte |= val; 8285 filter.mask[j] = byte; 8286 printf("mask[%d]:%02x ", j, filter.mask[j]); 8287 j++; 8288 byte = 0; 8289 } else 8290 byte |= val << 4; 8291 } 8292 printf("\n"); 8293 8294 if (!strcmp(res->ops, "add")) 8295 ret = rte_eth_dev_filter_ctrl(res->port_id, 8296 RTE_ETH_FILTER_FLEXIBLE, 8297 RTE_ETH_FILTER_ADD, 8298 &filter); 8299 else 8300 ret = rte_eth_dev_filter_ctrl(res->port_id, 8301 RTE_ETH_FILTER_FLEXIBLE, 8302 RTE_ETH_FILTER_DELETE, 8303 &filter); 8304 8305 if (ret < 0) 8306 printf("flex filter setting error: (%s)\n", strerror(-ret)); 8307 } 8308 8309 cmdline_parse_token_string_t cmd_flex_filter_filter = 8310 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8311 filter, "flex_filter"); 8312 cmdline_parse_token_num_t cmd_flex_filter_port_id = 8313 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8314 port_id, UINT8); 8315 cmdline_parse_token_string_t cmd_flex_filter_ops = 8316 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8317 ops, "add#del"); 8318 cmdline_parse_token_string_t cmd_flex_filter_len = 8319 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8320 len, "len"); 8321 cmdline_parse_token_num_t cmd_flex_filter_len_value = 8322 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8323 len_value, UINT8); 8324 cmdline_parse_token_string_t cmd_flex_filter_bytes = 8325 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8326 bytes, "bytes"); 8327 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 8328 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8329 bytes_value, NULL); 8330 cmdline_parse_token_string_t cmd_flex_filter_mask = 8331 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8332 mask, "mask"); 8333 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 8334 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8335 mask_value, NULL); 8336 cmdline_parse_token_string_t cmd_flex_filter_priority = 8337 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8338 priority, "priority"); 8339 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 8340 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8341 priority_value, UINT8); 8342 cmdline_parse_token_string_t cmd_flex_filter_queue = 8343 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8344 queue, "queue"); 8345 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 8346 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8347 queue_id, UINT16); 8348 cmdline_parse_inst_t cmd_flex_filter = { 8349 .f = cmd_flex_filter_parsed, 8350 .data = NULL, 8351 .help_str = "flex_filter <port_id> add|del len <value> bytes " 8352 "<value> mask <value> priority <value> queue <queue_id>: " 8353 "Add/Del a flex filter", 8354 .tokens = { 8355 (void *)&cmd_flex_filter_filter, 8356 (void *)&cmd_flex_filter_port_id, 8357 (void *)&cmd_flex_filter_ops, 8358 (void *)&cmd_flex_filter_len, 8359 (void *)&cmd_flex_filter_len_value, 8360 (void *)&cmd_flex_filter_bytes, 8361 (void *)&cmd_flex_filter_bytes_value, 8362 (void *)&cmd_flex_filter_mask, 8363 (void *)&cmd_flex_filter_mask_value, 8364 (void *)&cmd_flex_filter_priority, 8365 (void *)&cmd_flex_filter_priority_value, 8366 (void *)&cmd_flex_filter_queue, 8367 (void *)&cmd_flex_filter_queue_id, 8368 NULL, 8369 }, 8370 }; 8371 8372 /* *** Filters Control *** */ 8373 8374 /* *** deal with ethertype filter *** */ 8375 struct cmd_ethertype_filter_result { 8376 cmdline_fixed_string_t filter; 8377 uint8_t port_id; 8378 cmdline_fixed_string_t ops; 8379 cmdline_fixed_string_t mac; 8380 struct ether_addr mac_addr; 8381 cmdline_fixed_string_t ethertype; 8382 uint16_t ethertype_value; 8383 cmdline_fixed_string_t drop; 8384 cmdline_fixed_string_t queue; 8385 uint16_t queue_id; 8386 }; 8387 8388 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 8389 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8390 filter, "ethertype_filter"); 8391 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 8392 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8393 port_id, UINT8); 8394 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 8395 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8396 ops, "add#del"); 8397 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 8398 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8399 mac, "mac_addr#mac_ignr"); 8400 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 8401 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 8402 mac_addr); 8403 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 8404 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8405 ethertype, "ethertype"); 8406 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 8407 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8408 ethertype_value, UINT16); 8409 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 8410 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8411 drop, "drop#fwd"); 8412 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 8413 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8414 queue, "queue"); 8415 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 8416 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8417 queue_id, UINT16); 8418 8419 static void 8420 cmd_ethertype_filter_parsed(void *parsed_result, 8421 __attribute__((unused)) struct cmdline *cl, 8422 __attribute__((unused)) void *data) 8423 { 8424 struct cmd_ethertype_filter_result *res = parsed_result; 8425 struct rte_eth_ethertype_filter filter; 8426 int ret = 0; 8427 8428 ret = rte_eth_dev_filter_supported(res->port_id, 8429 RTE_ETH_FILTER_ETHERTYPE); 8430 if (ret < 0) { 8431 printf("ethertype filter is not supported on port %u.\n", 8432 res->port_id); 8433 return; 8434 } 8435 8436 memset(&filter, 0, sizeof(filter)); 8437 if (!strcmp(res->mac, "mac_addr")) { 8438 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 8439 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr, 8440 sizeof(struct ether_addr)); 8441 } 8442 if (!strcmp(res->drop, "drop")) 8443 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 8444 filter.ether_type = res->ethertype_value; 8445 filter.queue = res->queue_id; 8446 8447 if (!strcmp(res->ops, "add")) 8448 ret = rte_eth_dev_filter_ctrl(res->port_id, 8449 RTE_ETH_FILTER_ETHERTYPE, 8450 RTE_ETH_FILTER_ADD, 8451 &filter); 8452 else 8453 ret = rte_eth_dev_filter_ctrl(res->port_id, 8454 RTE_ETH_FILTER_ETHERTYPE, 8455 RTE_ETH_FILTER_DELETE, 8456 &filter); 8457 if (ret < 0) 8458 printf("ethertype filter programming error: (%s)\n", 8459 strerror(-ret)); 8460 } 8461 8462 cmdline_parse_inst_t cmd_ethertype_filter = { 8463 .f = cmd_ethertype_filter_parsed, 8464 .data = NULL, 8465 .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr " 8466 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: " 8467 "Add or delete an ethertype filter entry", 8468 .tokens = { 8469 (void *)&cmd_ethertype_filter_filter, 8470 (void *)&cmd_ethertype_filter_port_id, 8471 (void *)&cmd_ethertype_filter_ops, 8472 (void *)&cmd_ethertype_filter_mac, 8473 (void *)&cmd_ethertype_filter_mac_addr, 8474 (void *)&cmd_ethertype_filter_ethertype, 8475 (void *)&cmd_ethertype_filter_ethertype_value, 8476 (void *)&cmd_ethertype_filter_drop, 8477 (void *)&cmd_ethertype_filter_queue, 8478 (void *)&cmd_ethertype_filter_queue_id, 8479 NULL, 8480 }, 8481 }; 8482 8483 /* *** deal with flow director filter *** */ 8484 struct cmd_flow_director_result { 8485 cmdline_fixed_string_t flow_director_filter; 8486 uint8_t port_id; 8487 cmdline_fixed_string_t mode; 8488 cmdline_fixed_string_t mode_value; 8489 cmdline_fixed_string_t ops; 8490 cmdline_fixed_string_t flow; 8491 cmdline_fixed_string_t flow_type; 8492 cmdline_fixed_string_t ether; 8493 uint16_t ether_type; 8494 cmdline_fixed_string_t src; 8495 cmdline_ipaddr_t ip_src; 8496 uint16_t port_src; 8497 cmdline_fixed_string_t dst; 8498 cmdline_ipaddr_t ip_dst; 8499 uint16_t port_dst; 8500 cmdline_fixed_string_t verify_tag; 8501 uint32_t verify_tag_value; 8502 cmdline_ipaddr_t tos; 8503 uint8_t tos_value; 8504 cmdline_ipaddr_t proto; 8505 uint8_t proto_value; 8506 cmdline_ipaddr_t ttl; 8507 uint8_t ttl_value; 8508 cmdline_fixed_string_t vlan; 8509 uint16_t vlan_value; 8510 cmdline_fixed_string_t flexbytes; 8511 cmdline_fixed_string_t flexbytes_value; 8512 cmdline_fixed_string_t pf_vf; 8513 cmdline_fixed_string_t drop; 8514 cmdline_fixed_string_t queue; 8515 uint16_t queue_id; 8516 cmdline_fixed_string_t fd_id; 8517 uint32_t fd_id_value; 8518 cmdline_fixed_string_t mac; 8519 struct ether_addr mac_addr; 8520 cmdline_fixed_string_t tunnel; 8521 cmdline_fixed_string_t tunnel_type; 8522 cmdline_fixed_string_t tunnel_id; 8523 uint32_t tunnel_id_value; 8524 }; 8525 8526 static inline int 8527 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 8528 { 8529 char s[256]; 8530 const char *p, *p0 = q_arg; 8531 char *end; 8532 unsigned long int_fld; 8533 char *str_fld[max_num]; 8534 int i; 8535 unsigned size; 8536 int ret = -1; 8537 8538 p = strchr(p0, '('); 8539 if (p == NULL) 8540 return -1; 8541 ++p; 8542 p0 = strchr(p, ')'); 8543 if (p0 == NULL) 8544 return -1; 8545 8546 size = p0 - p; 8547 if (size >= sizeof(s)) 8548 return -1; 8549 8550 snprintf(s, sizeof(s), "%.*s", size, p); 8551 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 8552 if (ret < 0 || ret > max_num) 8553 return -1; 8554 for (i = 0; i < ret; i++) { 8555 errno = 0; 8556 int_fld = strtoul(str_fld[i], &end, 0); 8557 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 8558 return -1; 8559 flexbytes[i] = (uint8_t)int_fld; 8560 } 8561 return ret; 8562 } 8563 8564 static uint16_t 8565 str2flowtype(char *string) 8566 { 8567 uint8_t i = 0; 8568 static const struct { 8569 char str[32]; 8570 uint16_t type; 8571 } flowtype_str[] = { 8572 {"raw", RTE_ETH_FLOW_RAW}, 8573 {"ipv4", RTE_ETH_FLOW_IPV4}, 8574 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 8575 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 8576 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 8577 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 8578 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 8579 {"ipv6", RTE_ETH_FLOW_IPV6}, 8580 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 8581 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 8582 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 8583 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 8584 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 8585 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 8586 }; 8587 8588 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 8589 if (!strcmp(flowtype_str[i].str, string)) 8590 return flowtype_str[i].type; 8591 } 8592 return RTE_ETH_FLOW_UNKNOWN; 8593 } 8594 8595 static enum rte_eth_fdir_tunnel_type 8596 str2fdir_tunneltype(char *string) 8597 { 8598 uint8_t i = 0; 8599 8600 static const struct { 8601 char str[32]; 8602 enum rte_eth_fdir_tunnel_type type; 8603 } tunneltype_str[] = { 8604 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE}, 8605 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN}, 8606 }; 8607 8608 for (i = 0; i < RTE_DIM(tunneltype_str); i++) { 8609 if (!strcmp(tunneltype_str[i].str, string)) 8610 return tunneltype_str[i].type; 8611 } 8612 return RTE_FDIR_TUNNEL_TYPE_UNKNOWN; 8613 } 8614 8615 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 8616 do { \ 8617 if ((ip_addr).family == AF_INET) \ 8618 (ip) = (ip_addr).addr.ipv4.s_addr; \ 8619 else { \ 8620 printf("invalid parameter.\n"); \ 8621 return; \ 8622 } \ 8623 } while (0) 8624 8625 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 8626 do { \ 8627 if ((ip_addr).family == AF_INET6) \ 8628 (void)rte_memcpy(&(ip), \ 8629 &((ip_addr).addr.ipv6), \ 8630 sizeof(struct in6_addr)); \ 8631 else { \ 8632 printf("invalid parameter.\n"); \ 8633 return; \ 8634 } \ 8635 } while (0) 8636 8637 static void 8638 cmd_flow_director_filter_parsed(void *parsed_result, 8639 __attribute__((unused)) struct cmdline *cl, 8640 __attribute__((unused)) void *data) 8641 { 8642 struct cmd_flow_director_result *res = parsed_result; 8643 struct rte_eth_fdir_filter entry; 8644 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 8645 char *end; 8646 unsigned long vf_id; 8647 int ret = 0; 8648 8649 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 8650 if (ret < 0) { 8651 printf("flow director is not supported on port %u.\n", 8652 res->port_id); 8653 return; 8654 } 8655 memset(flexbytes, 0, sizeof(flexbytes)); 8656 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 8657 8658 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 8659 if (strcmp(res->mode_value, "MAC-VLAN")) { 8660 printf("Please set mode to MAC-VLAN.\n"); 8661 return; 8662 } 8663 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 8664 if (strcmp(res->mode_value, "Tunnel")) { 8665 printf("Please set mode to Tunnel.\n"); 8666 return; 8667 } 8668 } else { 8669 if (strcmp(res->mode_value, "IP")) { 8670 printf("Please set mode to IP.\n"); 8671 return; 8672 } 8673 entry.input.flow_type = str2flowtype(res->flow_type); 8674 } 8675 8676 ret = parse_flexbytes(res->flexbytes_value, 8677 flexbytes, 8678 RTE_ETH_FDIR_MAX_FLEXLEN); 8679 if (ret < 0) { 8680 printf("error: Cannot parse flexbytes input.\n"); 8681 return; 8682 } 8683 8684 switch (entry.input.flow_type) { 8685 case RTE_ETH_FLOW_FRAG_IPV4: 8686 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 8687 entry.input.flow.ip4_flow.proto = res->proto_value; 8688 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 8689 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 8690 IPV4_ADDR_TO_UINT(res->ip_dst, 8691 entry.input.flow.ip4_flow.dst_ip); 8692 IPV4_ADDR_TO_UINT(res->ip_src, 8693 entry.input.flow.ip4_flow.src_ip); 8694 entry.input.flow.ip4_flow.tos = res->tos_value; 8695 entry.input.flow.ip4_flow.ttl = res->ttl_value; 8696 /* need convert to big endian. */ 8697 entry.input.flow.udp4_flow.dst_port = 8698 rte_cpu_to_be_16(res->port_dst); 8699 entry.input.flow.udp4_flow.src_port = 8700 rte_cpu_to_be_16(res->port_src); 8701 break; 8702 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 8703 IPV4_ADDR_TO_UINT(res->ip_dst, 8704 entry.input.flow.sctp4_flow.ip.dst_ip); 8705 IPV4_ADDR_TO_UINT(res->ip_src, 8706 entry.input.flow.sctp4_flow.ip.src_ip); 8707 entry.input.flow.ip4_flow.tos = res->tos_value; 8708 entry.input.flow.ip4_flow.ttl = res->ttl_value; 8709 /* need convert to big endian. */ 8710 entry.input.flow.sctp4_flow.dst_port = 8711 rte_cpu_to_be_16(res->port_dst); 8712 entry.input.flow.sctp4_flow.src_port = 8713 rte_cpu_to_be_16(res->port_src); 8714 entry.input.flow.sctp4_flow.verify_tag = 8715 rte_cpu_to_be_32(res->verify_tag_value); 8716 break; 8717 case RTE_ETH_FLOW_FRAG_IPV6: 8718 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 8719 entry.input.flow.ipv6_flow.proto = res->proto_value; 8720 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 8721 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 8722 IPV6_ADDR_TO_ARRAY(res->ip_dst, 8723 entry.input.flow.ipv6_flow.dst_ip); 8724 IPV6_ADDR_TO_ARRAY(res->ip_src, 8725 entry.input.flow.ipv6_flow.src_ip); 8726 entry.input.flow.ipv6_flow.tc = res->tos_value; 8727 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 8728 /* need convert to big endian. */ 8729 entry.input.flow.udp6_flow.dst_port = 8730 rte_cpu_to_be_16(res->port_dst); 8731 entry.input.flow.udp6_flow.src_port = 8732 rte_cpu_to_be_16(res->port_src); 8733 break; 8734 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 8735 IPV6_ADDR_TO_ARRAY(res->ip_dst, 8736 entry.input.flow.sctp6_flow.ip.dst_ip); 8737 IPV6_ADDR_TO_ARRAY(res->ip_src, 8738 entry.input.flow.sctp6_flow.ip.src_ip); 8739 entry.input.flow.ipv6_flow.tc = res->tos_value; 8740 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 8741 /* need convert to big endian. */ 8742 entry.input.flow.sctp6_flow.dst_port = 8743 rte_cpu_to_be_16(res->port_dst); 8744 entry.input.flow.sctp6_flow.src_port = 8745 rte_cpu_to_be_16(res->port_src); 8746 entry.input.flow.sctp6_flow.verify_tag = 8747 rte_cpu_to_be_32(res->verify_tag_value); 8748 break; 8749 case RTE_ETH_FLOW_L2_PAYLOAD: 8750 entry.input.flow.l2_flow.ether_type = 8751 rte_cpu_to_be_16(res->ether_type); 8752 break; 8753 default: 8754 break; 8755 } 8756 8757 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 8758 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, 8759 &res->mac_addr, 8760 sizeof(struct ether_addr)); 8761 8762 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 8763 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, 8764 &res->mac_addr, 8765 sizeof(struct ether_addr)); 8766 entry.input.flow.tunnel_flow.tunnel_type = 8767 str2fdir_tunneltype(res->tunnel_type); 8768 entry.input.flow.tunnel_flow.tunnel_id = 8769 rte_cpu_to_be_32(res->tunnel_id_value); 8770 } 8771 8772 (void)rte_memcpy(entry.input.flow_ext.flexbytes, 8773 flexbytes, 8774 RTE_ETH_FDIR_MAX_FLEXLEN); 8775 8776 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 8777 8778 entry.action.flex_off = 0; /*use 0 by default */ 8779 if (!strcmp(res->drop, "drop")) 8780 entry.action.behavior = RTE_ETH_FDIR_REJECT; 8781 else 8782 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 8783 8784 if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN && 8785 fdir_conf.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 8786 if (!strcmp(res->pf_vf, "pf")) 8787 entry.input.flow_ext.is_vf = 0; 8788 else if (!strncmp(res->pf_vf, "vf", 2)) { 8789 struct rte_eth_dev_info dev_info; 8790 8791 memset(&dev_info, 0, sizeof(dev_info)); 8792 rte_eth_dev_info_get(res->port_id, &dev_info); 8793 errno = 0; 8794 vf_id = strtoul(res->pf_vf + 2, &end, 10); 8795 if (errno != 0 || *end != '\0' || 8796 vf_id >= dev_info.max_vfs) { 8797 printf("invalid parameter %s.\n", res->pf_vf); 8798 return; 8799 } 8800 entry.input.flow_ext.is_vf = 1; 8801 entry.input.flow_ext.dst_id = (uint16_t)vf_id; 8802 } else { 8803 printf("invalid parameter %s.\n", res->pf_vf); 8804 return; 8805 } 8806 } 8807 8808 /* set to report FD ID by default */ 8809 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 8810 entry.action.rx_queue = res->queue_id; 8811 entry.soft_id = res->fd_id_value; 8812 if (!strcmp(res->ops, "add")) 8813 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8814 RTE_ETH_FILTER_ADD, &entry); 8815 else if (!strcmp(res->ops, "del")) 8816 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8817 RTE_ETH_FILTER_DELETE, &entry); 8818 else 8819 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8820 RTE_ETH_FILTER_UPDATE, &entry); 8821 if (ret < 0) 8822 printf("flow director programming error: (%s)\n", 8823 strerror(-ret)); 8824 } 8825 8826 cmdline_parse_token_string_t cmd_flow_director_filter = 8827 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8828 flow_director_filter, "flow_director_filter"); 8829 cmdline_parse_token_num_t cmd_flow_director_port_id = 8830 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8831 port_id, UINT8); 8832 cmdline_parse_token_string_t cmd_flow_director_ops = 8833 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8834 ops, "add#del#update"); 8835 cmdline_parse_token_string_t cmd_flow_director_flow = 8836 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8837 flow, "flow"); 8838 cmdline_parse_token_string_t cmd_flow_director_flow_type = 8839 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8840 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 8841 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload"); 8842 cmdline_parse_token_string_t cmd_flow_director_ether = 8843 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8844 ether, "ether"); 8845 cmdline_parse_token_num_t cmd_flow_director_ether_type = 8846 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8847 ether_type, UINT16); 8848 cmdline_parse_token_string_t cmd_flow_director_src = 8849 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8850 src, "src"); 8851 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 8852 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 8853 ip_src); 8854 cmdline_parse_token_num_t cmd_flow_director_port_src = 8855 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8856 port_src, UINT16); 8857 cmdline_parse_token_string_t cmd_flow_director_dst = 8858 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8859 dst, "dst"); 8860 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 8861 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 8862 ip_dst); 8863 cmdline_parse_token_num_t cmd_flow_director_port_dst = 8864 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8865 port_dst, UINT16); 8866 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 8867 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8868 verify_tag, "verify_tag"); 8869 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 8870 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8871 verify_tag_value, UINT32); 8872 cmdline_parse_token_string_t cmd_flow_director_tos = 8873 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8874 tos, "tos"); 8875 cmdline_parse_token_num_t cmd_flow_director_tos_value = 8876 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8877 tos_value, UINT8); 8878 cmdline_parse_token_string_t cmd_flow_director_proto = 8879 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8880 proto, "proto"); 8881 cmdline_parse_token_num_t cmd_flow_director_proto_value = 8882 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8883 proto_value, UINT8); 8884 cmdline_parse_token_string_t cmd_flow_director_ttl = 8885 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8886 ttl, "ttl"); 8887 cmdline_parse_token_num_t cmd_flow_director_ttl_value = 8888 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8889 ttl_value, UINT8); 8890 cmdline_parse_token_string_t cmd_flow_director_vlan = 8891 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8892 vlan, "vlan"); 8893 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 8894 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8895 vlan_value, UINT16); 8896 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 8897 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8898 flexbytes, "flexbytes"); 8899 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 8900 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8901 flexbytes_value, NULL); 8902 cmdline_parse_token_string_t cmd_flow_director_drop = 8903 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8904 drop, "drop#fwd"); 8905 cmdline_parse_token_string_t cmd_flow_director_pf_vf = 8906 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8907 pf_vf, NULL); 8908 cmdline_parse_token_string_t cmd_flow_director_queue = 8909 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8910 queue, "queue"); 8911 cmdline_parse_token_num_t cmd_flow_director_queue_id = 8912 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8913 queue_id, UINT16); 8914 cmdline_parse_token_string_t cmd_flow_director_fd_id = 8915 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8916 fd_id, "fd_id"); 8917 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 8918 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8919 fd_id_value, UINT32); 8920 8921 cmdline_parse_token_string_t cmd_flow_director_mode = 8922 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8923 mode, "mode"); 8924 cmdline_parse_token_string_t cmd_flow_director_mode_ip = 8925 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8926 mode_value, "IP"); 8927 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan = 8928 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8929 mode_value, "MAC-VLAN"); 8930 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel = 8931 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8932 mode_value, "Tunnel"); 8933 cmdline_parse_token_string_t cmd_flow_director_mac = 8934 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8935 mac, "mac"); 8936 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr = 8937 TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result, 8938 mac_addr); 8939 cmdline_parse_token_string_t cmd_flow_director_tunnel = 8940 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8941 tunnel, "tunnel"); 8942 cmdline_parse_token_string_t cmd_flow_director_tunnel_type = 8943 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8944 tunnel_type, "NVGRE#VxLAN"); 8945 cmdline_parse_token_string_t cmd_flow_director_tunnel_id = 8946 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8947 tunnel_id, "tunnel-id"); 8948 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value = 8949 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8950 tunnel_id_value, UINT32); 8951 8952 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 8953 .f = cmd_flow_director_filter_parsed, 8954 .data = NULL, 8955 .help_str = "flow_director_filter <port_id> mode IP add|del|update flow" 8956 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 8957 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 8958 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " 8959 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " 8960 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> " 8961 "fd_id <fd_id_value>: " 8962 "Add or delete an ip flow director entry on NIC", 8963 .tokens = { 8964 (void *)&cmd_flow_director_filter, 8965 (void *)&cmd_flow_director_port_id, 8966 (void *)&cmd_flow_director_mode, 8967 (void *)&cmd_flow_director_mode_ip, 8968 (void *)&cmd_flow_director_ops, 8969 (void *)&cmd_flow_director_flow, 8970 (void *)&cmd_flow_director_flow_type, 8971 (void *)&cmd_flow_director_src, 8972 (void *)&cmd_flow_director_ip_src, 8973 (void *)&cmd_flow_director_dst, 8974 (void *)&cmd_flow_director_ip_dst, 8975 (void *)&cmd_flow_director_tos, 8976 (void *)&cmd_flow_director_tos_value, 8977 (void *)&cmd_flow_director_proto, 8978 (void *)&cmd_flow_director_proto_value, 8979 (void *)&cmd_flow_director_ttl, 8980 (void *)&cmd_flow_director_ttl_value, 8981 (void *)&cmd_flow_director_vlan, 8982 (void *)&cmd_flow_director_vlan_value, 8983 (void *)&cmd_flow_director_flexbytes, 8984 (void *)&cmd_flow_director_flexbytes_value, 8985 (void *)&cmd_flow_director_drop, 8986 (void *)&cmd_flow_director_pf_vf, 8987 (void *)&cmd_flow_director_queue, 8988 (void *)&cmd_flow_director_queue_id, 8989 (void *)&cmd_flow_director_fd_id, 8990 (void *)&cmd_flow_director_fd_id_value, 8991 NULL, 8992 }, 8993 }; 8994 8995 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 8996 .f = cmd_flow_director_filter_parsed, 8997 .data = NULL, 8998 .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow " 8999 "director entry on NIC", 9000 .tokens = { 9001 (void *)&cmd_flow_director_filter, 9002 (void *)&cmd_flow_director_port_id, 9003 (void *)&cmd_flow_director_mode, 9004 (void *)&cmd_flow_director_mode_ip, 9005 (void *)&cmd_flow_director_ops, 9006 (void *)&cmd_flow_director_flow, 9007 (void *)&cmd_flow_director_flow_type, 9008 (void *)&cmd_flow_director_src, 9009 (void *)&cmd_flow_director_ip_src, 9010 (void *)&cmd_flow_director_port_src, 9011 (void *)&cmd_flow_director_dst, 9012 (void *)&cmd_flow_director_ip_dst, 9013 (void *)&cmd_flow_director_port_dst, 9014 (void *)&cmd_flow_director_tos, 9015 (void *)&cmd_flow_director_tos_value, 9016 (void *)&cmd_flow_director_ttl, 9017 (void *)&cmd_flow_director_ttl_value, 9018 (void *)&cmd_flow_director_vlan, 9019 (void *)&cmd_flow_director_vlan_value, 9020 (void *)&cmd_flow_director_flexbytes, 9021 (void *)&cmd_flow_director_flexbytes_value, 9022 (void *)&cmd_flow_director_drop, 9023 (void *)&cmd_flow_director_pf_vf, 9024 (void *)&cmd_flow_director_queue, 9025 (void *)&cmd_flow_director_queue_id, 9026 (void *)&cmd_flow_director_fd_id, 9027 (void *)&cmd_flow_director_fd_id_value, 9028 NULL, 9029 }, 9030 }; 9031 9032 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 9033 .f = cmd_flow_director_filter_parsed, 9034 .data = NULL, 9035 .help_str = "flow_director_filter ... : Add or delete a sctp flow " 9036 "director entry on NIC", 9037 .tokens = { 9038 (void *)&cmd_flow_director_filter, 9039 (void *)&cmd_flow_director_port_id, 9040 (void *)&cmd_flow_director_mode, 9041 (void *)&cmd_flow_director_mode_ip, 9042 (void *)&cmd_flow_director_ops, 9043 (void *)&cmd_flow_director_flow, 9044 (void *)&cmd_flow_director_flow_type, 9045 (void *)&cmd_flow_director_src, 9046 (void *)&cmd_flow_director_ip_src, 9047 (void *)&cmd_flow_director_port_dst, 9048 (void *)&cmd_flow_director_dst, 9049 (void *)&cmd_flow_director_ip_dst, 9050 (void *)&cmd_flow_director_port_dst, 9051 (void *)&cmd_flow_director_verify_tag, 9052 (void *)&cmd_flow_director_verify_tag_value, 9053 (void *)&cmd_flow_director_tos, 9054 (void *)&cmd_flow_director_tos_value, 9055 (void *)&cmd_flow_director_ttl, 9056 (void *)&cmd_flow_director_ttl_value, 9057 (void *)&cmd_flow_director_vlan, 9058 (void *)&cmd_flow_director_vlan_value, 9059 (void *)&cmd_flow_director_flexbytes, 9060 (void *)&cmd_flow_director_flexbytes_value, 9061 (void *)&cmd_flow_director_drop, 9062 (void *)&cmd_flow_director_pf_vf, 9063 (void *)&cmd_flow_director_queue, 9064 (void *)&cmd_flow_director_queue_id, 9065 (void *)&cmd_flow_director_fd_id, 9066 (void *)&cmd_flow_director_fd_id_value, 9067 NULL, 9068 }, 9069 }; 9070 9071 cmdline_parse_inst_t cmd_add_del_l2_flow_director = { 9072 .f = cmd_flow_director_filter_parsed, 9073 .data = NULL, 9074 .help_str = "flow_director_filter ... : Add or delete a L2 flow " 9075 "director entry on NIC", 9076 .tokens = { 9077 (void *)&cmd_flow_director_filter, 9078 (void *)&cmd_flow_director_port_id, 9079 (void *)&cmd_flow_director_mode, 9080 (void *)&cmd_flow_director_mode_ip, 9081 (void *)&cmd_flow_director_ops, 9082 (void *)&cmd_flow_director_flow, 9083 (void *)&cmd_flow_director_flow_type, 9084 (void *)&cmd_flow_director_ether, 9085 (void *)&cmd_flow_director_ether_type, 9086 (void *)&cmd_flow_director_flexbytes, 9087 (void *)&cmd_flow_director_flexbytes_value, 9088 (void *)&cmd_flow_director_drop, 9089 (void *)&cmd_flow_director_pf_vf, 9090 (void *)&cmd_flow_director_queue, 9091 (void *)&cmd_flow_director_queue_id, 9092 (void *)&cmd_flow_director_fd_id, 9093 (void *)&cmd_flow_director_fd_id_value, 9094 NULL, 9095 }, 9096 }; 9097 9098 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = { 9099 .f = cmd_flow_director_filter_parsed, 9100 .data = NULL, 9101 .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow " 9102 "director entry on NIC", 9103 .tokens = { 9104 (void *)&cmd_flow_director_filter, 9105 (void *)&cmd_flow_director_port_id, 9106 (void *)&cmd_flow_director_mode, 9107 (void *)&cmd_flow_director_mode_mac_vlan, 9108 (void *)&cmd_flow_director_ops, 9109 (void *)&cmd_flow_director_mac, 9110 (void *)&cmd_flow_director_mac_addr, 9111 (void *)&cmd_flow_director_vlan, 9112 (void *)&cmd_flow_director_vlan_value, 9113 (void *)&cmd_flow_director_flexbytes, 9114 (void *)&cmd_flow_director_flexbytes_value, 9115 (void *)&cmd_flow_director_drop, 9116 (void *)&cmd_flow_director_queue, 9117 (void *)&cmd_flow_director_queue_id, 9118 (void *)&cmd_flow_director_fd_id, 9119 (void *)&cmd_flow_director_fd_id_value, 9120 NULL, 9121 }, 9122 }; 9123 9124 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { 9125 .f = cmd_flow_director_filter_parsed, 9126 .data = NULL, 9127 .help_str = "flow_director_filter ... : Add or delete a tunnel flow " 9128 "director entry on NIC", 9129 .tokens = { 9130 (void *)&cmd_flow_director_filter, 9131 (void *)&cmd_flow_director_port_id, 9132 (void *)&cmd_flow_director_mode, 9133 (void *)&cmd_flow_director_mode_tunnel, 9134 (void *)&cmd_flow_director_ops, 9135 (void *)&cmd_flow_director_mac, 9136 (void *)&cmd_flow_director_mac_addr, 9137 (void *)&cmd_flow_director_vlan, 9138 (void *)&cmd_flow_director_vlan_value, 9139 (void *)&cmd_flow_director_tunnel, 9140 (void *)&cmd_flow_director_tunnel_type, 9141 (void *)&cmd_flow_director_tunnel_id, 9142 (void *)&cmd_flow_director_tunnel_id_value, 9143 (void *)&cmd_flow_director_flexbytes, 9144 (void *)&cmd_flow_director_flexbytes_value, 9145 (void *)&cmd_flow_director_drop, 9146 (void *)&cmd_flow_director_queue, 9147 (void *)&cmd_flow_director_queue_id, 9148 (void *)&cmd_flow_director_fd_id, 9149 (void *)&cmd_flow_director_fd_id_value, 9150 NULL, 9151 }, 9152 }; 9153 9154 struct cmd_flush_flow_director_result { 9155 cmdline_fixed_string_t flush_flow_director; 9156 uint8_t port_id; 9157 }; 9158 9159 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 9160 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 9161 flush_flow_director, "flush_flow_director"); 9162 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 9163 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 9164 port_id, UINT8); 9165 9166 static void 9167 cmd_flush_flow_director_parsed(void *parsed_result, 9168 __attribute__((unused)) struct cmdline *cl, 9169 __attribute__((unused)) void *data) 9170 { 9171 struct cmd_flow_director_result *res = parsed_result; 9172 int ret = 0; 9173 9174 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 9175 if (ret < 0) { 9176 printf("flow director is not supported on port %u.\n", 9177 res->port_id); 9178 return; 9179 } 9180 9181 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9182 RTE_ETH_FILTER_FLUSH, NULL); 9183 if (ret < 0) 9184 printf("flow director table flushing error: (%s)\n", 9185 strerror(-ret)); 9186 } 9187 9188 cmdline_parse_inst_t cmd_flush_flow_director = { 9189 .f = cmd_flush_flow_director_parsed, 9190 .data = NULL, 9191 .help_str = "flush_flow_director <port_id>: " 9192 "Flush all flow director entries of a device on NIC", 9193 .tokens = { 9194 (void *)&cmd_flush_flow_director_flush, 9195 (void *)&cmd_flush_flow_director_port_id, 9196 NULL, 9197 }, 9198 }; 9199 9200 /* *** deal with flow director mask *** */ 9201 struct cmd_flow_director_mask_result { 9202 cmdline_fixed_string_t flow_director_mask; 9203 uint8_t port_id; 9204 cmdline_fixed_string_t mode; 9205 cmdline_fixed_string_t mode_value; 9206 cmdline_fixed_string_t vlan; 9207 uint16_t vlan_mask; 9208 cmdline_fixed_string_t src_mask; 9209 cmdline_ipaddr_t ipv4_src; 9210 cmdline_ipaddr_t ipv6_src; 9211 uint16_t port_src; 9212 cmdline_fixed_string_t dst_mask; 9213 cmdline_ipaddr_t ipv4_dst; 9214 cmdline_ipaddr_t ipv6_dst; 9215 uint16_t port_dst; 9216 cmdline_fixed_string_t mac; 9217 uint8_t mac_addr_byte_mask; 9218 cmdline_fixed_string_t tunnel_id; 9219 uint32_t tunnel_id_mask; 9220 cmdline_fixed_string_t tunnel_type; 9221 uint8_t tunnel_type_mask; 9222 }; 9223 9224 static void 9225 cmd_flow_director_mask_parsed(void *parsed_result, 9226 __attribute__((unused)) struct cmdline *cl, 9227 __attribute__((unused)) void *data) 9228 { 9229 struct cmd_flow_director_mask_result *res = parsed_result; 9230 struct rte_eth_fdir_masks *mask; 9231 struct rte_port *port; 9232 9233 if (res->port_id > nb_ports) { 9234 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9235 return; 9236 } 9237 9238 port = &ports[res->port_id]; 9239 /** Check if the port is not started **/ 9240 if (port->port_status != RTE_PORT_STOPPED) { 9241 printf("Please stop port %d first\n", res->port_id); 9242 return; 9243 } 9244 9245 mask = &port->dev_conf.fdir_conf.mask; 9246 9247 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9248 if (strcmp(res->mode_value, "MAC-VLAN")) { 9249 printf("Please set mode to MAC-VLAN.\n"); 9250 return; 9251 } 9252 9253 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9254 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9255 if (strcmp(res->mode_value, "Tunnel")) { 9256 printf("Please set mode to Tunnel.\n"); 9257 return; 9258 } 9259 9260 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9261 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 9262 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 9263 mask->tunnel_type_mask = res->tunnel_type_mask; 9264 } else { 9265 if (strcmp(res->mode_value, "IP")) { 9266 printf("Please set mode to IP.\n"); 9267 return; 9268 } 9269 9270 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9271 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 9272 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 9273 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 9274 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 9275 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 9276 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 9277 } 9278 9279 cmd_reconfig_device_queue(res->port_id, 1, 1); 9280 } 9281 9282 cmdline_parse_token_string_t cmd_flow_director_mask = 9283 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9284 flow_director_mask, "flow_director_mask"); 9285 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 9286 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9287 port_id, UINT8); 9288 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 9289 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9290 vlan, "vlan"); 9291 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 9292 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9293 vlan_mask, UINT16); 9294 cmdline_parse_token_string_t cmd_flow_director_mask_src = 9295 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9296 src_mask, "src_mask"); 9297 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 9298 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9299 ipv4_src); 9300 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 9301 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9302 ipv6_src); 9303 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 9304 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9305 port_src, UINT16); 9306 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 9307 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9308 dst_mask, "dst_mask"); 9309 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 9310 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9311 ipv4_dst); 9312 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 9313 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9314 ipv6_dst); 9315 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 9316 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9317 port_dst, UINT16); 9318 9319 cmdline_parse_token_string_t cmd_flow_director_mask_mode = 9320 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9321 mode, "mode"); 9322 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 9323 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9324 mode_value, "IP"); 9325 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 9326 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9327 mode_value, "MAC-VLAN"); 9328 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 9329 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9330 mode_value, "Tunnel"); 9331 cmdline_parse_token_string_t cmd_flow_director_mask_mac = 9332 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9333 mac, "mac"); 9334 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 9335 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9336 mac_addr_byte_mask, UINT8); 9337 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 9338 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9339 tunnel_type, "tunnel-type"); 9340 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 9341 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9342 tunnel_type_mask, UINT8); 9343 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 9344 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9345 tunnel_id, "tunnel-id"); 9346 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 9347 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9348 tunnel_id_mask, UINT32); 9349 9350 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 9351 .f = cmd_flow_director_mask_parsed, 9352 .data = NULL, 9353 .help_str = "flow_director_mask ... : " 9354 "Set IP mode flow director's mask on NIC", 9355 .tokens = { 9356 (void *)&cmd_flow_director_mask, 9357 (void *)&cmd_flow_director_mask_port_id, 9358 (void *)&cmd_flow_director_mask_mode, 9359 (void *)&cmd_flow_director_mask_mode_ip, 9360 (void *)&cmd_flow_director_mask_vlan, 9361 (void *)&cmd_flow_director_mask_vlan_value, 9362 (void *)&cmd_flow_director_mask_src, 9363 (void *)&cmd_flow_director_mask_ipv4_src, 9364 (void *)&cmd_flow_director_mask_ipv6_src, 9365 (void *)&cmd_flow_director_mask_port_src, 9366 (void *)&cmd_flow_director_mask_dst, 9367 (void *)&cmd_flow_director_mask_ipv4_dst, 9368 (void *)&cmd_flow_director_mask_ipv6_dst, 9369 (void *)&cmd_flow_director_mask_port_dst, 9370 NULL, 9371 }, 9372 }; 9373 9374 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 9375 .f = cmd_flow_director_mask_parsed, 9376 .data = NULL, 9377 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 9378 "flow director's mask on NIC", 9379 .tokens = { 9380 (void *)&cmd_flow_director_mask, 9381 (void *)&cmd_flow_director_mask_port_id, 9382 (void *)&cmd_flow_director_mask_mode, 9383 (void *)&cmd_flow_director_mask_mode_mac_vlan, 9384 (void *)&cmd_flow_director_mask_vlan, 9385 (void *)&cmd_flow_director_mask_vlan_value, 9386 NULL, 9387 }, 9388 }; 9389 9390 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 9391 .f = cmd_flow_director_mask_parsed, 9392 .data = NULL, 9393 .help_str = "flow_director_mask ... : Set tunnel mode " 9394 "flow director's mask on NIC", 9395 .tokens = { 9396 (void *)&cmd_flow_director_mask, 9397 (void *)&cmd_flow_director_mask_port_id, 9398 (void *)&cmd_flow_director_mask_mode, 9399 (void *)&cmd_flow_director_mask_mode_tunnel, 9400 (void *)&cmd_flow_director_mask_vlan, 9401 (void *)&cmd_flow_director_mask_vlan_value, 9402 (void *)&cmd_flow_director_mask_mac, 9403 (void *)&cmd_flow_director_mask_mac_value, 9404 (void *)&cmd_flow_director_mask_tunnel_type, 9405 (void *)&cmd_flow_director_mask_tunnel_type_value, 9406 (void *)&cmd_flow_director_mask_tunnel_id, 9407 (void *)&cmd_flow_director_mask_tunnel_id_value, 9408 NULL, 9409 }, 9410 }; 9411 9412 /* *** deal with flow director mask on flexible payload *** */ 9413 struct cmd_flow_director_flex_mask_result { 9414 cmdline_fixed_string_t flow_director_flexmask; 9415 uint8_t port_id; 9416 cmdline_fixed_string_t flow; 9417 cmdline_fixed_string_t flow_type; 9418 cmdline_fixed_string_t mask; 9419 }; 9420 9421 static void 9422 cmd_flow_director_flex_mask_parsed(void *parsed_result, 9423 __attribute__((unused)) struct cmdline *cl, 9424 __attribute__((unused)) void *data) 9425 { 9426 struct cmd_flow_director_flex_mask_result *res = parsed_result; 9427 struct rte_eth_fdir_info fdir_info; 9428 struct rte_eth_fdir_flex_mask flex_mask; 9429 struct rte_port *port; 9430 uint32_t flow_type_mask; 9431 uint16_t i; 9432 int ret; 9433 9434 if (res->port_id > nb_ports) { 9435 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9436 return; 9437 } 9438 9439 port = &ports[res->port_id]; 9440 /** Check if the port is not started **/ 9441 if (port->port_status != RTE_PORT_STOPPED) { 9442 printf("Please stop port %d first\n", res->port_id); 9443 return; 9444 } 9445 9446 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 9447 ret = parse_flexbytes(res->mask, 9448 flex_mask.mask, 9449 RTE_ETH_FDIR_MAX_FLEXLEN); 9450 if (ret < 0) { 9451 printf("error: Cannot parse mask input.\n"); 9452 return; 9453 } 9454 9455 memset(&fdir_info, 0, sizeof(fdir_info)); 9456 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9457 RTE_ETH_FILTER_INFO, &fdir_info); 9458 if (ret < 0) { 9459 printf("Cannot get FDir filter info\n"); 9460 return; 9461 } 9462 9463 if (!strcmp(res->flow_type, "none")) { 9464 /* means don't specify the flow type */ 9465 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN; 9466 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) 9467 memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 9468 0, sizeof(struct rte_eth_fdir_flex_mask)); 9469 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; 9470 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], 9471 &flex_mask, 9472 sizeof(struct rte_eth_fdir_flex_mask)); 9473 cmd_reconfig_device_queue(res->port_id, 1, 1); 9474 return; 9475 } 9476 flow_type_mask = fdir_info.flow_types_mask[0]; 9477 if (!strcmp(res->flow_type, "all")) { 9478 if (!flow_type_mask) { 9479 printf("No flow type supported\n"); 9480 return; 9481 } 9482 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 9483 if (flow_type_mask & (1 << i)) { 9484 flex_mask.flow_type = i; 9485 fdir_set_flex_mask(res->port_id, &flex_mask); 9486 } 9487 } 9488 cmd_reconfig_device_queue(res->port_id, 1, 1); 9489 return; 9490 } 9491 flex_mask.flow_type = str2flowtype(res->flow_type); 9492 if (!(flow_type_mask & (1 << flex_mask.flow_type))) { 9493 printf("Flow type %s not supported on port %d\n", 9494 res->flow_type, res->port_id); 9495 return; 9496 } 9497 fdir_set_flex_mask(res->port_id, &flex_mask); 9498 cmd_reconfig_device_queue(res->port_id, 1, 1); 9499 } 9500 9501 cmdline_parse_token_string_t cmd_flow_director_flexmask = 9502 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9503 flow_director_flexmask, 9504 "flow_director_flex_mask"); 9505 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 9506 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9507 port_id, UINT8); 9508 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 9509 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9510 flow, "flow"); 9511 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 9512 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9513 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 9514 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all"); 9515 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 9516 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9517 mask, NULL); 9518 9519 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 9520 .f = cmd_flow_director_flex_mask_parsed, 9521 .data = NULL, 9522 .help_str = "flow_director_flex_mask ... : " 9523 "Set flow director's flex mask on NIC", 9524 .tokens = { 9525 (void *)&cmd_flow_director_flexmask, 9526 (void *)&cmd_flow_director_flexmask_port_id, 9527 (void *)&cmd_flow_director_flexmask_flow, 9528 (void *)&cmd_flow_director_flexmask_flow_type, 9529 (void *)&cmd_flow_director_flexmask_mask, 9530 NULL, 9531 }, 9532 }; 9533 9534 /* *** deal with flow director flexible payload configuration *** */ 9535 struct cmd_flow_director_flexpayload_result { 9536 cmdline_fixed_string_t flow_director_flexpayload; 9537 uint8_t port_id; 9538 cmdline_fixed_string_t payload_layer; 9539 cmdline_fixed_string_t payload_cfg; 9540 }; 9541 9542 static inline int 9543 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 9544 { 9545 char s[256]; 9546 const char *p, *p0 = q_arg; 9547 char *end; 9548 unsigned long int_fld; 9549 char *str_fld[max_num]; 9550 int i; 9551 unsigned size; 9552 int ret = -1; 9553 9554 p = strchr(p0, '('); 9555 if (p == NULL) 9556 return -1; 9557 ++p; 9558 p0 = strchr(p, ')'); 9559 if (p0 == NULL) 9560 return -1; 9561 9562 size = p0 - p; 9563 if (size >= sizeof(s)) 9564 return -1; 9565 9566 snprintf(s, sizeof(s), "%.*s", size, p); 9567 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9568 if (ret < 0 || ret > max_num) 9569 return -1; 9570 for (i = 0; i < ret; i++) { 9571 errno = 0; 9572 int_fld = strtoul(str_fld[i], &end, 0); 9573 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 9574 return -1; 9575 offsets[i] = (uint16_t)int_fld; 9576 } 9577 return ret; 9578 } 9579 9580 static void 9581 cmd_flow_director_flxpld_parsed(void *parsed_result, 9582 __attribute__((unused)) struct cmdline *cl, 9583 __attribute__((unused)) void *data) 9584 { 9585 struct cmd_flow_director_flexpayload_result *res = parsed_result; 9586 struct rte_eth_flex_payload_cfg flex_cfg; 9587 struct rte_port *port; 9588 int ret = 0; 9589 9590 if (res->port_id > nb_ports) { 9591 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9592 return; 9593 } 9594 9595 port = &ports[res->port_id]; 9596 /** Check if the port is not started **/ 9597 if (port->port_status != RTE_PORT_STOPPED) { 9598 printf("Please stop port %d first\n", res->port_id); 9599 return; 9600 } 9601 9602 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 9603 9604 if (!strcmp(res->payload_layer, "raw")) 9605 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 9606 else if (!strcmp(res->payload_layer, "l2")) 9607 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 9608 else if (!strcmp(res->payload_layer, "l3")) 9609 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 9610 else if (!strcmp(res->payload_layer, "l4")) 9611 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 9612 9613 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 9614 RTE_ETH_FDIR_MAX_FLEXLEN); 9615 if (ret < 0) { 9616 printf("error: Cannot parse flex payload input.\n"); 9617 return; 9618 } 9619 9620 fdir_set_flex_payload(res->port_id, &flex_cfg); 9621 cmd_reconfig_device_queue(res->port_id, 1, 1); 9622 } 9623 9624 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 9625 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9626 flow_director_flexpayload, 9627 "flow_director_flex_payload"); 9628 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 9629 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9630 port_id, UINT8); 9631 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 9632 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9633 payload_layer, "raw#l2#l3#l4"); 9634 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 9635 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9636 payload_cfg, NULL); 9637 9638 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 9639 .f = cmd_flow_director_flxpld_parsed, 9640 .data = NULL, 9641 .help_str = "flow_director_flexpayload ... : " 9642 "Set flow director's flex payload on NIC", 9643 .tokens = { 9644 (void *)&cmd_flow_director_flexpayload, 9645 (void *)&cmd_flow_director_flexpayload_port_id, 9646 (void *)&cmd_flow_director_flexpayload_payload_layer, 9647 (void *)&cmd_flow_director_flexpayload_payload_cfg, 9648 NULL, 9649 }, 9650 }; 9651 9652 /* Generic flow interface command. */ 9653 extern cmdline_parse_inst_t cmd_flow; 9654 9655 /* *** Classification Filters Control *** */ 9656 /* *** Get symmetric hash enable per port *** */ 9657 struct cmd_get_sym_hash_ena_per_port_result { 9658 cmdline_fixed_string_t get_sym_hash_ena_per_port; 9659 uint8_t port_id; 9660 }; 9661 9662 static void 9663 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 9664 __rte_unused struct cmdline *cl, 9665 __rte_unused void *data) 9666 { 9667 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 9668 struct rte_eth_hash_filter_info info; 9669 int ret; 9670 9671 if (rte_eth_dev_filter_supported(res->port_id, 9672 RTE_ETH_FILTER_HASH) < 0) { 9673 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 9674 res->port_id); 9675 return; 9676 } 9677 9678 memset(&info, 0, sizeof(info)); 9679 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 9680 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9681 RTE_ETH_FILTER_GET, &info); 9682 9683 if (ret < 0) { 9684 printf("Cannot get symmetric hash enable per port " 9685 "on port %u\n", res->port_id); 9686 return; 9687 } 9688 9689 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 9690 "enabled" : "disabled", res->port_id); 9691 } 9692 9693 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 9694 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 9695 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 9696 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 9697 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 9698 port_id, UINT8); 9699 9700 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 9701 .f = cmd_get_sym_hash_per_port_parsed, 9702 .data = NULL, 9703 .help_str = "get_sym_hash_ena_per_port <port_id>", 9704 .tokens = { 9705 (void *)&cmd_get_sym_hash_ena_per_port_all, 9706 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 9707 NULL, 9708 }, 9709 }; 9710 9711 /* *** Set symmetric hash enable per port *** */ 9712 struct cmd_set_sym_hash_ena_per_port_result { 9713 cmdline_fixed_string_t set_sym_hash_ena_per_port; 9714 cmdline_fixed_string_t enable; 9715 uint8_t port_id; 9716 }; 9717 9718 static void 9719 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 9720 __rte_unused struct cmdline *cl, 9721 __rte_unused void *data) 9722 { 9723 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 9724 struct rte_eth_hash_filter_info info; 9725 int ret; 9726 9727 if (rte_eth_dev_filter_supported(res->port_id, 9728 RTE_ETH_FILTER_HASH) < 0) { 9729 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 9730 res->port_id); 9731 return; 9732 } 9733 9734 memset(&info, 0, sizeof(info)); 9735 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 9736 if (!strcmp(res->enable, "enable")) 9737 info.info.enable = 1; 9738 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9739 RTE_ETH_FILTER_SET, &info); 9740 if (ret < 0) { 9741 printf("Cannot set symmetric hash enable per port on " 9742 "port %u\n", res->port_id); 9743 return; 9744 } 9745 printf("Symmetric hash has been set to %s on port %u\n", 9746 res->enable, res->port_id); 9747 } 9748 9749 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 9750 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9751 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 9752 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 9753 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9754 port_id, UINT8); 9755 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 9756 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9757 enable, "enable#disable"); 9758 9759 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 9760 .f = cmd_set_sym_hash_per_port_parsed, 9761 .data = NULL, 9762 .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable", 9763 .tokens = { 9764 (void *)&cmd_set_sym_hash_ena_per_port_all, 9765 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 9766 (void *)&cmd_set_sym_hash_ena_per_port_enable, 9767 NULL, 9768 }, 9769 }; 9770 9771 /* Get global config of hash function */ 9772 struct cmd_get_hash_global_config_result { 9773 cmdline_fixed_string_t get_hash_global_config; 9774 uint8_t port_id; 9775 }; 9776 9777 static char * 9778 flowtype_to_str(uint16_t ftype) 9779 { 9780 uint16_t i; 9781 static struct { 9782 char str[16]; 9783 uint16_t ftype; 9784 } ftype_table[] = { 9785 {"ipv4", RTE_ETH_FLOW_IPV4}, 9786 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 9787 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 9788 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 9789 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 9790 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 9791 {"ipv6", RTE_ETH_FLOW_IPV6}, 9792 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 9793 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 9794 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 9795 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 9796 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 9797 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 9798 {"port", RTE_ETH_FLOW_PORT}, 9799 {"vxlan", RTE_ETH_FLOW_VXLAN}, 9800 {"geneve", RTE_ETH_FLOW_GENEVE}, 9801 {"nvgre", RTE_ETH_FLOW_NVGRE}, 9802 }; 9803 9804 for (i = 0; i < RTE_DIM(ftype_table); i++) { 9805 if (ftype_table[i].ftype == ftype) 9806 return ftype_table[i].str; 9807 } 9808 9809 return NULL; 9810 } 9811 9812 static void 9813 cmd_get_hash_global_config_parsed(void *parsed_result, 9814 __rte_unused struct cmdline *cl, 9815 __rte_unused void *data) 9816 { 9817 struct cmd_get_hash_global_config_result *res = parsed_result; 9818 struct rte_eth_hash_filter_info info; 9819 uint32_t idx, offset; 9820 uint16_t i; 9821 char *str; 9822 int ret; 9823 9824 if (rte_eth_dev_filter_supported(res->port_id, 9825 RTE_ETH_FILTER_HASH) < 0) { 9826 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 9827 res->port_id); 9828 return; 9829 } 9830 9831 memset(&info, 0, sizeof(info)); 9832 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 9833 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9834 RTE_ETH_FILTER_GET, &info); 9835 if (ret < 0) { 9836 printf("Cannot get hash global configurations by port %d\n", 9837 res->port_id); 9838 return; 9839 } 9840 9841 switch (info.info.global_conf.hash_func) { 9842 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 9843 printf("Hash function is Toeplitz\n"); 9844 break; 9845 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 9846 printf("Hash function is Simple XOR\n"); 9847 break; 9848 default: 9849 printf("Unknown hash function\n"); 9850 break; 9851 } 9852 9853 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 9854 idx = i / UINT32_BIT; 9855 offset = i % UINT32_BIT; 9856 if (!(info.info.global_conf.valid_bit_mask[idx] & 9857 (1UL << offset))) 9858 continue; 9859 str = flowtype_to_str(i); 9860 if (!str) 9861 continue; 9862 printf("Symmetric hash is %s globally for flow type %s " 9863 "by port %d\n", 9864 ((info.info.global_conf.sym_hash_enable_mask[idx] & 9865 (1UL << offset)) ? "enabled" : "disabled"), str, 9866 res->port_id); 9867 } 9868 } 9869 9870 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 9871 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 9872 get_hash_global_config, "get_hash_global_config"); 9873 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 9874 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 9875 port_id, UINT8); 9876 9877 cmdline_parse_inst_t cmd_get_hash_global_config = { 9878 .f = cmd_get_hash_global_config_parsed, 9879 .data = NULL, 9880 .help_str = "get_hash_global_config <port_id>", 9881 .tokens = { 9882 (void *)&cmd_get_hash_global_config_all, 9883 (void *)&cmd_get_hash_global_config_port_id, 9884 NULL, 9885 }, 9886 }; 9887 9888 /* Set global config of hash function */ 9889 struct cmd_set_hash_global_config_result { 9890 cmdline_fixed_string_t set_hash_global_config; 9891 uint8_t port_id; 9892 cmdline_fixed_string_t hash_func; 9893 cmdline_fixed_string_t flow_type; 9894 cmdline_fixed_string_t enable; 9895 }; 9896 9897 static void 9898 cmd_set_hash_global_config_parsed(void *parsed_result, 9899 __rte_unused struct cmdline *cl, 9900 __rte_unused void *data) 9901 { 9902 struct cmd_set_hash_global_config_result *res = parsed_result; 9903 struct rte_eth_hash_filter_info info; 9904 uint32_t ftype, idx, offset; 9905 int ret; 9906 9907 if (rte_eth_dev_filter_supported(res->port_id, 9908 RTE_ETH_FILTER_HASH) < 0) { 9909 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 9910 res->port_id); 9911 return; 9912 } 9913 memset(&info, 0, sizeof(info)); 9914 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 9915 if (!strcmp(res->hash_func, "toeplitz")) 9916 info.info.global_conf.hash_func = 9917 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 9918 else if (!strcmp(res->hash_func, "simple_xor")) 9919 info.info.global_conf.hash_func = 9920 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 9921 else if (!strcmp(res->hash_func, "default")) 9922 info.info.global_conf.hash_func = 9923 RTE_ETH_HASH_FUNCTION_DEFAULT; 9924 9925 ftype = str2flowtype(res->flow_type); 9926 idx = ftype / (CHAR_BIT * sizeof(uint32_t)); 9927 offset = ftype % (CHAR_BIT * sizeof(uint32_t)); 9928 info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset); 9929 if (!strcmp(res->enable, "enable")) 9930 info.info.global_conf.sym_hash_enable_mask[idx] |= 9931 (1UL << offset); 9932 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9933 RTE_ETH_FILTER_SET, &info); 9934 if (ret < 0) 9935 printf("Cannot set global hash configurations by port %d\n", 9936 res->port_id); 9937 else 9938 printf("Global hash configurations have been set " 9939 "succcessfully by port %d\n", res->port_id); 9940 } 9941 9942 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 9943 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9944 set_hash_global_config, "set_hash_global_config"); 9945 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 9946 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 9947 port_id, UINT8); 9948 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 9949 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9950 hash_func, "toeplitz#simple_xor#default"); 9951 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 9952 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9953 flow_type, 9954 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 9955 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 9956 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 9957 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9958 enable, "enable#disable"); 9959 9960 cmdline_parse_inst_t cmd_set_hash_global_config = { 9961 .f = cmd_set_hash_global_config_parsed, 9962 .data = NULL, 9963 .help_str = "set_hash_global_config <port_id> " 9964 "toeplitz|simple_xor|default " 9965 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 9966 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 9967 "l2_payload enable|disable", 9968 .tokens = { 9969 (void *)&cmd_set_hash_global_config_all, 9970 (void *)&cmd_set_hash_global_config_port_id, 9971 (void *)&cmd_set_hash_global_config_hash_func, 9972 (void *)&cmd_set_hash_global_config_flow_type, 9973 (void *)&cmd_set_hash_global_config_enable, 9974 NULL, 9975 }, 9976 }; 9977 9978 /* Set hash input set */ 9979 struct cmd_set_hash_input_set_result { 9980 cmdline_fixed_string_t set_hash_input_set; 9981 uint8_t port_id; 9982 cmdline_fixed_string_t flow_type; 9983 cmdline_fixed_string_t inset_field; 9984 cmdline_fixed_string_t select; 9985 }; 9986 9987 static enum rte_eth_input_set_field 9988 str2inset(char *string) 9989 { 9990 uint16_t i; 9991 9992 static const struct { 9993 char str[32]; 9994 enum rte_eth_input_set_field inset; 9995 } inset_table[] = { 9996 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE}, 9997 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN}, 9998 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN}, 9999 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4}, 10000 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4}, 10001 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS}, 10002 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO}, 10003 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL}, 10004 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6}, 10005 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6}, 10006 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC}, 10007 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER}, 10008 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS}, 10009 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT}, 10010 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT}, 10011 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT}, 10012 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT}, 10013 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT}, 10014 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT}, 10015 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG}, 10016 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY}, 10017 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY}, 10018 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD}, 10019 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD}, 10020 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD}, 10021 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD}, 10022 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD}, 10023 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD}, 10024 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD}, 10025 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD}, 10026 {"none", RTE_ETH_INPUT_SET_NONE}, 10027 }; 10028 10029 for (i = 0; i < RTE_DIM(inset_table); i++) { 10030 if (!strcmp(string, inset_table[i].str)) 10031 return inset_table[i].inset; 10032 } 10033 10034 return RTE_ETH_INPUT_SET_UNKNOWN; 10035 } 10036 10037 static void 10038 cmd_set_hash_input_set_parsed(void *parsed_result, 10039 __rte_unused struct cmdline *cl, 10040 __rte_unused void *data) 10041 { 10042 struct cmd_set_hash_input_set_result *res = parsed_result; 10043 struct rte_eth_hash_filter_info info; 10044 10045 memset(&info, 0, sizeof(info)); 10046 info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; 10047 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10048 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10049 info.info.input_set_conf.inset_size = 1; 10050 if (!strcmp(res->select, "select")) 10051 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10052 else if (!strcmp(res->select, "add")) 10053 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10054 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10055 RTE_ETH_FILTER_SET, &info); 10056 } 10057 10058 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = 10059 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10060 set_hash_input_set, "set_hash_input_set"); 10061 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = 10062 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, 10063 port_id, UINT8); 10064 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = 10065 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10066 flow_type, 10067 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10068 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10069 cmdline_parse_token_string_t cmd_set_hash_input_set_field = 10070 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10071 inset_field, 10072 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10073 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#" 10074 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#" 10075 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#" 10076 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#" 10077 "fld-8th#none"); 10078 cmdline_parse_token_string_t cmd_set_hash_input_set_select = 10079 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10080 select, "select#add"); 10081 10082 cmdline_parse_inst_t cmd_set_hash_input_set = { 10083 .f = cmd_set_hash_input_set_parsed, 10084 .data = NULL, 10085 .help_str = "set_hash_input_set <port_id> " 10086 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10087 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10088 "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" 10089 "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" 10090 "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" 10091 "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|" 10092 "fld-7th|fld-8th|none select|add", 10093 .tokens = { 10094 (void *)&cmd_set_hash_input_set_cmd, 10095 (void *)&cmd_set_hash_input_set_port_id, 10096 (void *)&cmd_set_hash_input_set_flow_type, 10097 (void *)&cmd_set_hash_input_set_field, 10098 (void *)&cmd_set_hash_input_set_select, 10099 NULL, 10100 }, 10101 }; 10102 10103 /* Set flow director input set */ 10104 struct cmd_set_fdir_input_set_result { 10105 cmdline_fixed_string_t set_fdir_input_set; 10106 uint8_t port_id; 10107 cmdline_fixed_string_t flow_type; 10108 cmdline_fixed_string_t inset_field; 10109 cmdline_fixed_string_t select; 10110 }; 10111 10112 static void 10113 cmd_set_fdir_input_set_parsed(void *parsed_result, 10114 __rte_unused struct cmdline *cl, 10115 __rte_unused void *data) 10116 { 10117 struct cmd_set_fdir_input_set_result *res = parsed_result; 10118 struct rte_eth_fdir_filter_info info; 10119 10120 memset(&info, 0, sizeof(info)); 10121 info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT; 10122 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10123 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10124 info.info.input_set_conf.inset_size = 1; 10125 if (!strcmp(res->select, "select")) 10126 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10127 else if (!strcmp(res->select, "add")) 10128 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10129 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10130 RTE_ETH_FILTER_SET, &info); 10131 } 10132 10133 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = 10134 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10135 set_fdir_input_set, "set_fdir_input_set"); 10136 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = 10137 TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, 10138 port_id, UINT8); 10139 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = 10140 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10141 flow_type, 10142 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10143 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10144 cmdline_parse_token_string_t cmd_set_fdir_input_set_field = 10145 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10146 inset_field, 10147 "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10148 "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#" 10149 "ipv6-hop-limits#udp-src-port#udp-dst-port#" 10150 "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#" 10151 "sctp-veri-tag#none"); 10152 cmdline_parse_token_string_t cmd_set_fdir_input_set_select = 10153 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10154 select, "select#add"); 10155 10156 cmdline_parse_inst_t cmd_set_fdir_input_set = { 10157 .f = cmd_set_fdir_input_set_parsed, 10158 .data = NULL, 10159 .help_str = "set_fdir_input_set <port_id> " 10160 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10161 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10162 "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|" 10163 "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|" 10164 "ipv6-hop-limits|udp-src-port|udp-dst-port|" 10165 "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|" 10166 "sctp-veri-tag|none select|add", 10167 .tokens = { 10168 (void *)&cmd_set_fdir_input_set_cmd, 10169 (void *)&cmd_set_fdir_input_set_port_id, 10170 (void *)&cmd_set_fdir_input_set_flow_type, 10171 (void *)&cmd_set_fdir_input_set_field, 10172 (void *)&cmd_set_fdir_input_set_select, 10173 NULL, 10174 }, 10175 }; 10176 10177 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 10178 struct cmd_mcast_addr_result { 10179 cmdline_fixed_string_t mcast_addr_cmd; 10180 cmdline_fixed_string_t what; 10181 uint8_t port_num; 10182 struct ether_addr mc_addr; 10183 }; 10184 10185 static void cmd_mcast_addr_parsed(void *parsed_result, 10186 __attribute__((unused)) struct cmdline *cl, 10187 __attribute__((unused)) void *data) 10188 { 10189 struct cmd_mcast_addr_result *res = parsed_result; 10190 10191 if (!is_multicast_ether_addr(&res->mc_addr)) { 10192 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n", 10193 res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1], 10194 res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3], 10195 res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]); 10196 return; 10197 } 10198 if (strcmp(res->what, "add") == 0) 10199 mcast_addr_add(res->port_num, &res->mc_addr); 10200 else 10201 mcast_addr_remove(res->port_num, &res->mc_addr); 10202 } 10203 10204 cmdline_parse_token_string_t cmd_mcast_addr_cmd = 10205 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 10206 mcast_addr_cmd, "mcast_addr"); 10207 cmdline_parse_token_string_t cmd_mcast_addr_what = 10208 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 10209 "add#remove"); 10210 cmdline_parse_token_num_t cmd_mcast_addr_portnum = 10211 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8); 10212 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 10213 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 10214 10215 cmdline_parse_inst_t cmd_mcast_addr = { 10216 .f = cmd_mcast_addr_parsed, 10217 .data = (void *)0, 10218 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 10219 "Add/Remove multicast MAC address on port_id", 10220 .tokens = { 10221 (void *)&cmd_mcast_addr_cmd, 10222 (void *)&cmd_mcast_addr_what, 10223 (void *)&cmd_mcast_addr_portnum, 10224 (void *)&cmd_mcast_addr_addr, 10225 NULL, 10226 }, 10227 }; 10228 10229 /* l2 tunnel config 10230 * only support E-tag now. 10231 */ 10232 10233 /* Ether type config */ 10234 struct cmd_config_l2_tunnel_eth_type_result { 10235 cmdline_fixed_string_t port; 10236 cmdline_fixed_string_t config; 10237 cmdline_fixed_string_t all; 10238 uint8_t id; 10239 cmdline_fixed_string_t l2_tunnel; 10240 cmdline_fixed_string_t l2_tunnel_type; 10241 cmdline_fixed_string_t eth_type; 10242 uint16_t eth_type_val; 10243 }; 10244 10245 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port = 10246 TOKEN_STRING_INITIALIZER 10247 (struct cmd_config_l2_tunnel_eth_type_result, 10248 port, "port"); 10249 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config = 10250 TOKEN_STRING_INITIALIZER 10251 (struct cmd_config_l2_tunnel_eth_type_result, 10252 config, "config"); 10253 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str = 10254 TOKEN_STRING_INITIALIZER 10255 (struct cmd_config_l2_tunnel_eth_type_result, 10256 all, "all"); 10257 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id = 10258 TOKEN_NUM_INITIALIZER 10259 (struct cmd_config_l2_tunnel_eth_type_result, 10260 id, UINT8); 10261 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel = 10262 TOKEN_STRING_INITIALIZER 10263 (struct cmd_config_l2_tunnel_eth_type_result, 10264 l2_tunnel, "l2-tunnel"); 10265 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type = 10266 TOKEN_STRING_INITIALIZER 10267 (struct cmd_config_l2_tunnel_eth_type_result, 10268 l2_tunnel_type, "E-tag"); 10269 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type = 10270 TOKEN_STRING_INITIALIZER 10271 (struct cmd_config_l2_tunnel_eth_type_result, 10272 eth_type, "ether-type"); 10273 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val = 10274 TOKEN_NUM_INITIALIZER 10275 (struct cmd_config_l2_tunnel_eth_type_result, 10276 eth_type_val, UINT16); 10277 10278 static enum rte_eth_tunnel_type 10279 str2fdir_l2_tunnel_type(char *string) 10280 { 10281 uint32_t i = 0; 10282 10283 static const struct { 10284 char str[32]; 10285 enum rte_eth_tunnel_type type; 10286 } l2_tunnel_type_str[] = { 10287 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG}, 10288 }; 10289 10290 for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) { 10291 if (!strcmp(l2_tunnel_type_str[i].str, string)) 10292 return l2_tunnel_type_str[i].type; 10293 } 10294 return RTE_TUNNEL_TYPE_NONE; 10295 } 10296 10297 /* ether type config for all ports */ 10298 static void 10299 cmd_config_l2_tunnel_eth_type_all_parsed 10300 (void *parsed_result, 10301 __attribute__((unused)) struct cmdline *cl, 10302 __attribute__((unused)) void *data) 10303 { 10304 struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result; 10305 struct rte_eth_l2_tunnel_conf entry; 10306 portid_t pid; 10307 10308 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10309 entry.ether_type = res->eth_type_val; 10310 10311 FOREACH_PORT(pid, ports) { 10312 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry); 10313 } 10314 } 10315 10316 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = { 10317 .f = cmd_config_l2_tunnel_eth_type_all_parsed, 10318 .data = NULL, 10319 .help_str = "port config all l2-tunnel E-tag ether-type <value>", 10320 .tokens = { 10321 (void *)&cmd_config_l2_tunnel_eth_type_port, 10322 (void *)&cmd_config_l2_tunnel_eth_type_config, 10323 (void *)&cmd_config_l2_tunnel_eth_type_all_str, 10324 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10325 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10326 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10327 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10328 NULL, 10329 }, 10330 }; 10331 10332 /* ether type config for a specific port */ 10333 static void 10334 cmd_config_l2_tunnel_eth_type_specific_parsed( 10335 void *parsed_result, 10336 __attribute__((unused)) struct cmdline *cl, 10337 __attribute__((unused)) void *data) 10338 { 10339 struct cmd_config_l2_tunnel_eth_type_result *res = 10340 parsed_result; 10341 struct rte_eth_l2_tunnel_conf entry; 10342 10343 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10344 return; 10345 10346 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10347 entry.ether_type = res->eth_type_val; 10348 10349 rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry); 10350 } 10351 10352 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = { 10353 .f = cmd_config_l2_tunnel_eth_type_specific_parsed, 10354 .data = NULL, 10355 .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>", 10356 .tokens = { 10357 (void *)&cmd_config_l2_tunnel_eth_type_port, 10358 (void *)&cmd_config_l2_tunnel_eth_type_config, 10359 (void *)&cmd_config_l2_tunnel_eth_type_id, 10360 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10361 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10362 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10363 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10364 NULL, 10365 }, 10366 }; 10367 10368 /* Enable/disable l2 tunnel */ 10369 struct cmd_config_l2_tunnel_en_dis_result { 10370 cmdline_fixed_string_t port; 10371 cmdline_fixed_string_t config; 10372 cmdline_fixed_string_t all; 10373 uint8_t id; 10374 cmdline_fixed_string_t l2_tunnel; 10375 cmdline_fixed_string_t l2_tunnel_type; 10376 cmdline_fixed_string_t en_dis; 10377 }; 10378 10379 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port = 10380 TOKEN_STRING_INITIALIZER 10381 (struct cmd_config_l2_tunnel_en_dis_result, 10382 port, "port"); 10383 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config = 10384 TOKEN_STRING_INITIALIZER 10385 (struct cmd_config_l2_tunnel_en_dis_result, 10386 config, "config"); 10387 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str = 10388 TOKEN_STRING_INITIALIZER 10389 (struct cmd_config_l2_tunnel_en_dis_result, 10390 all, "all"); 10391 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id = 10392 TOKEN_NUM_INITIALIZER 10393 (struct cmd_config_l2_tunnel_en_dis_result, 10394 id, UINT8); 10395 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel = 10396 TOKEN_STRING_INITIALIZER 10397 (struct cmd_config_l2_tunnel_en_dis_result, 10398 l2_tunnel, "l2-tunnel"); 10399 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type = 10400 TOKEN_STRING_INITIALIZER 10401 (struct cmd_config_l2_tunnel_en_dis_result, 10402 l2_tunnel_type, "E-tag"); 10403 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis = 10404 TOKEN_STRING_INITIALIZER 10405 (struct cmd_config_l2_tunnel_en_dis_result, 10406 en_dis, "enable#disable"); 10407 10408 /* enable/disable l2 tunnel for all ports */ 10409 static void 10410 cmd_config_l2_tunnel_en_dis_all_parsed( 10411 void *parsed_result, 10412 __attribute__((unused)) struct cmdline *cl, 10413 __attribute__((unused)) void *data) 10414 { 10415 struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result; 10416 struct rte_eth_l2_tunnel_conf entry; 10417 portid_t pid; 10418 uint8_t en; 10419 10420 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10421 10422 if (!strcmp("enable", res->en_dis)) 10423 en = 1; 10424 else 10425 en = 0; 10426 10427 FOREACH_PORT(pid, ports) { 10428 rte_eth_dev_l2_tunnel_offload_set(pid, 10429 &entry, 10430 ETH_L2_TUNNEL_ENABLE_MASK, 10431 en); 10432 } 10433 } 10434 10435 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = { 10436 .f = cmd_config_l2_tunnel_en_dis_all_parsed, 10437 .data = NULL, 10438 .help_str = "port config all l2-tunnel E-tag enable|disable", 10439 .tokens = { 10440 (void *)&cmd_config_l2_tunnel_en_dis_port, 10441 (void *)&cmd_config_l2_tunnel_en_dis_config, 10442 (void *)&cmd_config_l2_tunnel_en_dis_all_str, 10443 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10444 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10445 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10446 NULL, 10447 }, 10448 }; 10449 10450 /* enable/disable l2 tunnel for a port */ 10451 static void 10452 cmd_config_l2_tunnel_en_dis_specific_parsed( 10453 void *parsed_result, 10454 __attribute__((unused)) struct cmdline *cl, 10455 __attribute__((unused)) void *data) 10456 { 10457 struct cmd_config_l2_tunnel_en_dis_result *res = 10458 parsed_result; 10459 struct rte_eth_l2_tunnel_conf entry; 10460 10461 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10462 return; 10463 10464 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10465 10466 if (!strcmp("enable", res->en_dis)) 10467 rte_eth_dev_l2_tunnel_offload_set(res->id, 10468 &entry, 10469 ETH_L2_TUNNEL_ENABLE_MASK, 10470 1); 10471 else 10472 rte_eth_dev_l2_tunnel_offload_set(res->id, 10473 &entry, 10474 ETH_L2_TUNNEL_ENABLE_MASK, 10475 0); 10476 } 10477 10478 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = { 10479 .f = cmd_config_l2_tunnel_en_dis_specific_parsed, 10480 .data = NULL, 10481 .help_str = "port config <port_id> l2-tunnel E-tag enable|disable", 10482 .tokens = { 10483 (void *)&cmd_config_l2_tunnel_en_dis_port, 10484 (void *)&cmd_config_l2_tunnel_en_dis_config, 10485 (void *)&cmd_config_l2_tunnel_en_dis_id, 10486 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10487 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10488 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10489 NULL, 10490 }, 10491 }; 10492 10493 /* E-tag configuration */ 10494 10495 /* Common result structure for all E-tag configuration */ 10496 struct cmd_config_e_tag_result { 10497 cmdline_fixed_string_t e_tag; 10498 cmdline_fixed_string_t set; 10499 cmdline_fixed_string_t insertion; 10500 cmdline_fixed_string_t stripping; 10501 cmdline_fixed_string_t forwarding; 10502 cmdline_fixed_string_t filter; 10503 cmdline_fixed_string_t add; 10504 cmdline_fixed_string_t del; 10505 cmdline_fixed_string_t on; 10506 cmdline_fixed_string_t off; 10507 cmdline_fixed_string_t on_off; 10508 cmdline_fixed_string_t port_tag_id; 10509 uint32_t port_tag_id_val; 10510 cmdline_fixed_string_t e_tag_id; 10511 uint16_t e_tag_id_val; 10512 cmdline_fixed_string_t dst_pool; 10513 uint8_t dst_pool_val; 10514 cmdline_fixed_string_t port; 10515 uint8_t port_id; 10516 cmdline_fixed_string_t vf; 10517 uint8_t vf_id; 10518 }; 10519 10520 /* Common CLI fields for all E-tag configuration */ 10521 cmdline_parse_token_string_t cmd_config_e_tag_e_tag = 10522 TOKEN_STRING_INITIALIZER 10523 (struct cmd_config_e_tag_result, 10524 e_tag, "E-tag"); 10525 cmdline_parse_token_string_t cmd_config_e_tag_set = 10526 TOKEN_STRING_INITIALIZER 10527 (struct cmd_config_e_tag_result, 10528 set, "set"); 10529 cmdline_parse_token_string_t cmd_config_e_tag_insertion = 10530 TOKEN_STRING_INITIALIZER 10531 (struct cmd_config_e_tag_result, 10532 insertion, "insertion"); 10533 cmdline_parse_token_string_t cmd_config_e_tag_stripping = 10534 TOKEN_STRING_INITIALIZER 10535 (struct cmd_config_e_tag_result, 10536 stripping, "stripping"); 10537 cmdline_parse_token_string_t cmd_config_e_tag_forwarding = 10538 TOKEN_STRING_INITIALIZER 10539 (struct cmd_config_e_tag_result, 10540 forwarding, "forwarding"); 10541 cmdline_parse_token_string_t cmd_config_e_tag_filter = 10542 TOKEN_STRING_INITIALIZER 10543 (struct cmd_config_e_tag_result, 10544 filter, "filter"); 10545 cmdline_parse_token_string_t cmd_config_e_tag_add = 10546 TOKEN_STRING_INITIALIZER 10547 (struct cmd_config_e_tag_result, 10548 add, "add"); 10549 cmdline_parse_token_string_t cmd_config_e_tag_del = 10550 TOKEN_STRING_INITIALIZER 10551 (struct cmd_config_e_tag_result, 10552 del, "del"); 10553 cmdline_parse_token_string_t cmd_config_e_tag_on = 10554 TOKEN_STRING_INITIALIZER 10555 (struct cmd_config_e_tag_result, 10556 on, "on"); 10557 cmdline_parse_token_string_t cmd_config_e_tag_off = 10558 TOKEN_STRING_INITIALIZER 10559 (struct cmd_config_e_tag_result, 10560 off, "off"); 10561 cmdline_parse_token_string_t cmd_config_e_tag_on_off = 10562 TOKEN_STRING_INITIALIZER 10563 (struct cmd_config_e_tag_result, 10564 on_off, "on#off"); 10565 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id = 10566 TOKEN_STRING_INITIALIZER 10567 (struct cmd_config_e_tag_result, 10568 port_tag_id, "port-tag-id"); 10569 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val = 10570 TOKEN_NUM_INITIALIZER 10571 (struct cmd_config_e_tag_result, 10572 port_tag_id_val, UINT32); 10573 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id = 10574 TOKEN_STRING_INITIALIZER 10575 (struct cmd_config_e_tag_result, 10576 e_tag_id, "e-tag-id"); 10577 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val = 10578 TOKEN_NUM_INITIALIZER 10579 (struct cmd_config_e_tag_result, 10580 e_tag_id_val, UINT16); 10581 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool = 10582 TOKEN_STRING_INITIALIZER 10583 (struct cmd_config_e_tag_result, 10584 dst_pool, "dst-pool"); 10585 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val = 10586 TOKEN_NUM_INITIALIZER 10587 (struct cmd_config_e_tag_result, 10588 dst_pool_val, UINT8); 10589 cmdline_parse_token_string_t cmd_config_e_tag_port = 10590 TOKEN_STRING_INITIALIZER 10591 (struct cmd_config_e_tag_result, 10592 port, "port"); 10593 cmdline_parse_token_num_t cmd_config_e_tag_port_id = 10594 TOKEN_NUM_INITIALIZER 10595 (struct cmd_config_e_tag_result, 10596 port_id, UINT8); 10597 cmdline_parse_token_string_t cmd_config_e_tag_vf = 10598 TOKEN_STRING_INITIALIZER 10599 (struct cmd_config_e_tag_result, 10600 vf, "vf"); 10601 cmdline_parse_token_num_t cmd_config_e_tag_vf_id = 10602 TOKEN_NUM_INITIALIZER 10603 (struct cmd_config_e_tag_result, 10604 vf_id, UINT8); 10605 10606 /* E-tag insertion configuration */ 10607 static void 10608 cmd_config_e_tag_insertion_en_parsed( 10609 void *parsed_result, 10610 __attribute__((unused)) struct cmdline *cl, 10611 __attribute__((unused)) void *data) 10612 { 10613 struct cmd_config_e_tag_result *res = 10614 parsed_result; 10615 struct rte_eth_l2_tunnel_conf entry; 10616 10617 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10618 return; 10619 10620 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10621 entry.tunnel_id = res->port_tag_id_val; 10622 entry.vf_id = res->vf_id; 10623 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 10624 &entry, 10625 ETH_L2_TUNNEL_INSERTION_MASK, 10626 1); 10627 } 10628 10629 static void 10630 cmd_config_e_tag_insertion_dis_parsed( 10631 void *parsed_result, 10632 __attribute__((unused)) struct cmdline *cl, 10633 __attribute__((unused)) void *data) 10634 { 10635 struct cmd_config_e_tag_result *res = 10636 parsed_result; 10637 struct rte_eth_l2_tunnel_conf entry; 10638 10639 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10640 return; 10641 10642 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10643 entry.vf_id = res->vf_id; 10644 10645 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 10646 &entry, 10647 ETH_L2_TUNNEL_INSERTION_MASK, 10648 0); 10649 } 10650 10651 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = { 10652 .f = cmd_config_e_tag_insertion_en_parsed, 10653 .data = NULL, 10654 .help_str = "E-tag ... : E-tag insertion enable", 10655 .tokens = { 10656 (void *)&cmd_config_e_tag_e_tag, 10657 (void *)&cmd_config_e_tag_set, 10658 (void *)&cmd_config_e_tag_insertion, 10659 (void *)&cmd_config_e_tag_on, 10660 (void *)&cmd_config_e_tag_port_tag_id, 10661 (void *)&cmd_config_e_tag_port_tag_id_val, 10662 (void *)&cmd_config_e_tag_port, 10663 (void *)&cmd_config_e_tag_port_id, 10664 (void *)&cmd_config_e_tag_vf, 10665 (void *)&cmd_config_e_tag_vf_id, 10666 NULL, 10667 }, 10668 }; 10669 10670 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = { 10671 .f = cmd_config_e_tag_insertion_dis_parsed, 10672 .data = NULL, 10673 .help_str = "E-tag ... : E-tag insertion disable", 10674 .tokens = { 10675 (void *)&cmd_config_e_tag_e_tag, 10676 (void *)&cmd_config_e_tag_set, 10677 (void *)&cmd_config_e_tag_insertion, 10678 (void *)&cmd_config_e_tag_off, 10679 (void *)&cmd_config_e_tag_port, 10680 (void *)&cmd_config_e_tag_port_id, 10681 (void *)&cmd_config_e_tag_vf, 10682 (void *)&cmd_config_e_tag_vf_id, 10683 NULL, 10684 }, 10685 }; 10686 10687 /* E-tag stripping configuration */ 10688 static void 10689 cmd_config_e_tag_stripping_parsed( 10690 void *parsed_result, 10691 __attribute__((unused)) struct cmdline *cl, 10692 __attribute__((unused)) void *data) 10693 { 10694 struct cmd_config_e_tag_result *res = 10695 parsed_result; 10696 struct rte_eth_l2_tunnel_conf entry; 10697 10698 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10699 return; 10700 10701 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10702 10703 if (!strcmp(res->on_off, "on")) 10704 rte_eth_dev_l2_tunnel_offload_set 10705 (res->port_id, 10706 &entry, 10707 ETH_L2_TUNNEL_STRIPPING_MASK, 10708 1); 10709 else 10710 rte_eth_dev_l2_tunnel_offload_set 10711 (res->port_id, 10712 &entry, 10713 ETH_L2_TUNNEL_STRIPPING_MASK, 10714 0); 10715 } 10716 10717 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = { 10718 .f = cmd_config_e_tag_stripping_parsed, 10719 .data = NULL, 10720 .help_str = "E-tag ... : E-tag stripping enable/disable", 10721 .tokens = { 10722 (void *)&cmd_config_e_tag_e_tag, 10723 (void *)&cmd_config_e_tag_set, 10724 (void *)&cmd_config_e_tag_stripping, 10725 (void *)&cmd_config_e_tag_on_off, 10726 (void *)&cmd_config_e_tag_port, 10727 (void *)&cmd_config_e_tag_port_id, 10728 NULL, 10729 }, 10730 }; 10731 10732 /* E-tag forwarding configuration */ 10733 static void 10734 cmd_config_e_tag_forwarding_parsed( 10735 void *parsed_result, 10736 __attribute__((unused)) struct cmdline *cl, 10737 __attribute__((unused)) void *data) 10738 { 10739 struct cmd_config_e_tag_result *res = parsed_result; 10740 struct rte_eth_l2_tunnel_conf entry; 10741 10742 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10743 return; 10744 10745 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10746 10747 if (!strcmp(res->on_off, "on")) 10748 rte_eth_dev_l2_tunnel_offload_set 10749 (res->port_id, 10750 &entry, 10751 ETH_L2_TUNNEL_FORWARDING_MASK, 10752 1); 10753 else 10754 rte_eth_dev_l2_tunnel_offload_set 10755 (res->port_id, 10756 &entry, 10757 ETH_L2_TUNNEL_FORWARDING_MASK, 10758 0); 10759 } 10760 10761 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = { 10762 .f = cmd_config_e_tag_forwarding_parsed, 10763 .data = NULL, 10764 .help_str = "E-tag ... : E-tag forwarding enable/disable", 10765 .tokens = { 10766 (void *)&cmd_config_e_tag_e_tag, 10767 (void *)&cmd_config_e_tag_set, 10768 (void *)&cmd_config_e_tag_forwarding, 10769 (void *)&cmd_config_e_tag_on_off, 10770 (void *)&cmd_config_e_tag_port, 10771 (void *)&cmd_config_e_tag_port_id, 10772 NULL, 10773 }, 10774 }; 10775 10776 /* E-tag filter configuration */ 10777 static void 10778 cmd_config_e_tag_filter_add_parsed( 10779 void *parsed_result, 10780 __attribute__((unused)) struct cmdline *cl, 10781 __attribute__((unused)) void *data) 10782 { 10783 struct cmd_config_e_tag_result *res = parsed_result; 10784 struct rte_eth_l2_tunnel_conf entry; 10785 int ret = 0; 10786 10787 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10788 return; 10789 10790 if (res->e_tag_id_val > 0x3fff) { 10791 printf("e-tag-id must be equal or less than 0x3fff.\n"); 10792 return; 10793 } 10794 10795 ret = rte_eth_dev_filter_supported(res->port_id, 10796 RTE_ETH_FILTER_L2_TUNNEL); 10797 if (ret < 0) { 10798 printf("E-tag filter is not supported on port %u.\n", 10799 res->port_id); 10800 return; 10801 } 10802 10803 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10804 entry.tunnel_id = res->e_tag_id_val; 10805 entry.pool = res->dst_pool_val; 10806 10807 ret = rte_eth_dev_filter_ctrl(res->port_id, 10808 RTE_ETH_FILTER_L2_TUNNEL, 10809 RTE_ETH_FILTER_ADD, 10810 &entry); 10811 if (ret < 0) 10812 printf("E-tag filter programming error: (%s)\n", 10813 strerror(-ret)); 10814 } 10815 10816 cmdline_parse_inst_t cmd_config_e_tag_filter_add = { 10817 .f = cmd_config_e_tag_filter_add_parsed, 10818 .data = NULL, 10819 .help_str = "E-tag ... : E-tag filter add", 10820 .tokens = { 10821 (void *)&cmd_config_e_tag_e_tag, 10822 (void *)&cmd_config_e_tag_set, 10823 (void *)&cmd_config_e_tag_filter, 10824 (void *)&cmd_config_e_tag_add, 10825 (void *)&cmd_config_e_tag_e_tag_id, 10826 (void *)&cmd_config_e_tag_e_tag_id_val, 10827 (void *)&cmd_config_e_tag_dst_pool, 10828 (void *)&cmd_config_e_tag_dst_pool_val, 10829 (void *)&cmd_config_e_tag_port, 10830 (void *)&cmd_config_e_tag_port_id, 10831 NULL, 10832 }, 10833 }; 10834 10835 static void 10836 cmd_config_e_tag_filter_del_parsed( 10837 void *parsed_result, 10838 __attribute__((unused)) struct cmdline *cl, 10839 __attribute__((unused)) void *data) 10840 { 10841 struct cmd_config_e_tag_result *res = parsed_result; 10842 struct rte_eth_l2_tunnel_conf entry; 10843 int ret = 0; 10844 10845 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10846 return; 10847 10848 if (res->e_tag_id_val > 0x3fff) { 10849 printf("e-tag-id must be less than 0x3fff.\n"); 10850 return; 10851 } 10852 10853 ret = rte_eth_dev_filter_supported(res->port_id, 10854 RTE_ETH_FILTER_L2_TUNNEL); 10855 if (ret < 0) { 10856 printf("E-tag filter is not supported on port %u.\n", 10857 res->port_id); 10858 return; 10859 } 10860 10861 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10862 entry.tunnel_id = res->e_tag_id_val; 10863 10864 ret = rte_eth_dev_filter_ctrl(res->port_id, 10865 RTE_ETH_FILTER_L2_TUNNEL, 10866 RTE_ETH_FILTER_DELETE, 10867 &entry); 10868 if (ret < 0) 10869 printf("E-tag filter programming error: (%s)\n", 10870 strerror(-ret)); 10871 } 10872 10873 cmdline_parse_inst_t cmd_config_e_tag_filter_del = { 10874 .f = cmd_config_e_tag_filter_del_parsed, 10875 .data = NULL, 10876 .help_str = "E-tag ... : E-tag filter delete", 10877 .tokens = { 10878 (void *)&cmd_config_e_tag_e_tag, 10879 (void *)&cmd_config_e_tag_set, 10880 (void *)&cmd_config_e_tag_filter, 10881 (void *)&cmd_config_e_tag_del, 10882 (void *)&cmd_config_e_tag_e_tag_id, 10883 (void *)&cmd_config_e_tag_e_tag_id_val, 10884 (void *)&cmd_config_e_tag_port, 10885 (void *)&cmd_config_e_tag_port_id, 10886 NULL, 10887 }, 10888 }; 10889 10890 /* vf vlan anti spoof configuration */ 10891 10892 /* Common result structure for vf vlan anti spoof */ 10893 struct cmd_vf_vlan_anti_spoof_result { 10894 cmdline_fixed_string_t set; 10895 cmdline_fixed_string_t vf; 10896 cmdline_fixed_string_t vlan; 10897 cmdline_fixed_string_t antispoof; 10898 uint8_t port_id; 10899 uint32_t vf_id; 10900 cmdline_fixed_string_t on_off; 10901 }; 10902 10903 /* Common CLI fields for vf vlan anti spoof enable disable */ 10904 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 10905 TOKEN_STRING_INITIALIZER 10906 (struct cmd_vf_vlan_anti_spoof_result, 10907 set, "set"); 10908 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 10909 TOKEN_STRING_INITIALIZER 10910 (struct cmd_vf_vlan_anti_spoof_result, 10911 vf, "vf"); 10912 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 10913 TOKEN_STRING_INITIALIZER 10914 (struct cmd_vf_vlan_anti_spoof_result, 10915 vlan, "vlan"); 10916 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 10917 TOKEN_STRING_INITIALIZER 10918 (struct cmd_vf_vlan_anti_spoof_result, 10919 antispoof, "antispoof"); 10920 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 10921 TOKEN_NUM_INITIALIZER 10922 (struct cmd_vf_vlan_anti_spoof_result, 10923 port_id, UINT8); 10924 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 10925 TOKEN_NUM_INITIALIZER 10926 (struct cmd_vf_vlan_anti_spoof_result, 10927 vf_id, UINT32); 10928 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 10929 TOKEN_STRING_INITIALIZER 10930 (struct cmd_vf_vlan_anti_spoof_result, 10931 on_off, "on#off"); 10932 10933 static void 10934 cmd_set_vf_vlan_anti_spoof_parsed( 10935 void *parsed_result, 10936 __attribute__((unused)) struct cmdline *cl, 10937 __attribute__((unused)) void *data) 10938 { 10939 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 10940 int ret = -ENOTSUP; 10941 10942 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 10943 10944 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10945 return; 10946 10947 #ifdef RTE_LIBRTE_IXGBE_PMD 10948 if (ret == -ENOTSUP) 10949 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 10950 res->vf_id, is_on); 10951 #endif 10952 #ifdef RTE_LIBRTE_I40E_PMD 10953 if (ret == -ENOTSUP) 10954 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 10955 res->vf_id, is_on); 10956 #endif 10957 10958 switch (ret) { 10959 case 0: 10960 break; 10961 case -EINVAL: 10962 printf("invalid vf_id %d\n", res->vf_id); 10963 break; 10964 case -ENODEV: 10965 printf("invalid port_id %d\n", res->port_id); 10966 break; 10967 case -ENOTSUP: 10968 printf("function not implemented\n"); 10969 break; 10970 default: 10971 printf("programming error: (%s)\n", strerror(-ret)); 10972 } 10973 } 10974 10975 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 10976 .f = cmd_set_vf_vlan_anti_spoof_parsed, 10977 .data = NULL, 10978 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 10979 .tokens = { 10980 (void *)&cmd_vf_vlan_anti_spoof_set, 10981 (void *)&cmd_vf_vlan_anti_spoof_vf, 10982 (void *)&cmd_vf_vlan_anti_spoof_vlan, 10983 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 10984 (void *)&cmd_vf_vlan_anti_spoof_port_id, 10985 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 10986 (void *)&cmd_vf_vlan_anti_spoof_on_off, 10987 NULL, 10988 }, 10989 }; 10990 10991 /* vf mac anti spoof configuration */ 10992 10993 /* Common result structure for vf mac anti spoof */ 10994 struct cmd_vf_mac_anti_spoof_result { 10995 cmdline_fixed_string_t set; 10996 cmdline_fixed_string_t vf; 10997 cmdline_fixed_string_t mac; 10998 cmdline_fixed_string_t antispoof; 10999 uint8_t port_id; 11000 uint32_t vf_id; 11001 cmdline_fixed_string_t on_off; 11002 }; 11003 11004 /* Common CLI fields for vf mac anti spoof enable disable */ 11005 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 11006 TOKEN_STRING_INITIALIZER 11007 (struct cmd_vf_mac_anti_spoof_result, 11008 set, "set"); 11009 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 11010 TOKEN_STRING_INITIALIZER 11011 (struct cmd_vf_mac_anti_spoof_result, 11012 vf, "vf"); 11013 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 11014 TOKEN_STRING_INITIALIZER 11015 (struct cmd_vf_mac_anti_spoof_result, 11016 mac, "mac"); 11017 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 11018 TOKEN_STRING_INITIALIZER 11019 (struct cmd_vf_mac_anti_spoof_result, 11020 antispoof, "antispoof"); 11021 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 11022 TOKEN_NUM_INITIALIZER 11023 (struct cmd_vf_mac_anti_spoof_result, 11024 port_id, UINT8); 11025 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 11026 TOKEN_NUM_INITIALIZER 11027 (struct cmd_vf_mac_anti_spoof_result, 11028 vf_id, UINT32); 11029 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 11030 TOKEN_STRING_INITIALIZER 11031 (struct cmd_vf_mac_anti_spoof_result, 11032 on_off, "on#off"); 11033 11034 static void 11035 cmd_set_vf_mac_anti_spoof_parsed( 11036 void *parsed_result, 11037 __attribute__((unused)) struct cmdline *cl, 11038 __attribute__((unused)) void *data) 11039 { 11040 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 11041 int ret = -ENOTSUP; 11042 11043 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11044 11045 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11046 return; 11047 11048 #ifdef RTE_LIBRTE_IXGBE_PMD 11049 if (ret == -ENOTSUP) 11050 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 11051 res->vf_id, is_on); 11052 #endif 11053 #ifdef RTE_LIBRTE_I40E_PMD 11054 if (ret == -ENOTSUP) 11055 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 11056 res->vf_id, is_on); 11057 #endif 11058 11059 switch (ret) { 11060 case 0: 11061 break; 11062 case -EINVAL: 11063 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11064 break; 11065 case -ENODEV: 11066 printf("invalid port_id %d\n", res->port_id); 11067 break; 11068 case -ENOTSUP: 11069 printf("function not implemented\n"); 11070 break; 11071 default: 11072 printf("programming error: (%s)\n", strerror(-ret)); 11073 } 11074 } 11075 11076 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 11077 .f = cmd_set_vf_mac_anti_spoof_parsed, 11078 .data = NULL, 11079 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 11080 .tokens = { 11081 (void *)&cmd_vf_mac_anti_spoof_set, 11082 (void *)&cmd_vf_mac_anti_spoof_vf, 11083 (void *)&cmd_vf_mac_anti_spoof_mac, 11084 (void *)&cmd_vf_mac_anti_spoof_antispoof, 11085 (void *)&cmd_vf_mac_anti_spoof_port_id, 11086 (void *)&cmd_vf_mac_anti_spoof_vf_id, 11087 (void *)&cmd_vf_mac_anti_spoof_on_off, 11088 NULL, 11089 }, 11090 }; 11091 11092 /* vf vlan strip queue configuration */ 11093 11094 /* Common result structure for vf mac anti spoof */ 11095 struct cmd_vf_vlan_stripq_result { 11096 cmdline_fixed_string_t set; 11097 cmdline_fixed_string_t vf; 11098 cmdline_fixed_string_t vlan; 11099 cmdline_fixed_string_t stripq; 11100 uint8_t port_id; 11101 uint16_t vf_id; 11102 cmdline_fixed_string_t on_off; 11103 }; 11104 11105 /* Common CLI fields for vf vlan strip enable disable */ 11106 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 11107 TOKEN_STRING_INITIALIZER 11108 (struct cmd_vf_vlan_stripq_result, 11109 set, "set"); 11110 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 11111 TOKEN_STRING_INITIALIZER 11112 (struct cmd_vf_vlan_stripq_result, 11113 vf, "vf"); 11114 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 11115 TOKEN_STRING_INITIALIZER 11116 (struct cmd_vf_vlan_stripq_result, 11117 vlan, "vlan"); 11118 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 11119 TOKEN_STRING_INITIALIZER 11120 (struct cmd_vf_vlan_stripq_result, 11121 stripq, "stripq"); 11122 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 11123 TOKEN_NUM_INITIALIZER 11124 (struct cmd_vf_vlan_stripq_result, 11125 port_id, UINT8); 11126 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 11127 TOKEN_NUM_INITIALIZER 11128 (struct cmd_vf_vlan_stripq_result, 11129 vf_id, UINT16); 11130 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 11131 TOKEN_STRING_INITIALIZER 11132 (struct cmd_vf_vlan_stripq_result, 11133 on_off, "on#off"); 11134 11135 static void 11136 cmd_set_vf_vlan_stripq_parsed( 11137 void *parsed_result, 11138 __attribute__((unused)) struct cmdline *cl, 11139 __attribute__((unused)) void *data) 11140 { 11141 struct cmd_vf_vlan_stripq_result *res = parsed_result; 11142 int ret = -ENOTSUP; 11143 11144 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11145 11146 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11147 return; 11148 11149 #ifdef RTE_LIBRTE_IXGBE_PMD 11150 if (ret == -ENOTSUP) 11151 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 11152 res->vf_id, is_on); 11153 #endif 11154 #ifdef RTE_LIBRTE_I40E_PMD 11155 if (ret == -ENOTSUP) 11156 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 11157 res->vf_id, is_on); 11158 #endif 11159 11160 switch (ret) { 11161 case 0: 11162 break; 11163 case -EINVAL: 11164 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11165 break; 11166 case -ENODEV: 11167 printf("invalid port_id %d\n", res->port_id); 11168 break; 11169 case -ENOTSUP: 11170 printf("function not implemented\n"); 11171 break; 11172 default: 11173 printf("programming error: (%s)\n", strerror(-ret)); 11174 } 11175 } 11176 11177 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 11178 .f = cmd_set_vf_vlan_stripq_parsed, 11179 .data = NULL, 11180 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 11181 .tokens = { 11182 (void *)&cmd_vf_vlan_stripq_set, 11183 (void *)&cmd_vf_vlan_stripq_vf, 11184 (void *)&cmd_vf_vlan_stripq_vlan, 11185 (void *)&cmd_vf_vlan_stripq_stripq, 11186 (void *)&cmd_vf_vlan_stripq_port_id, 11187 (void *)&cmd_vf_vlan_stripq_vf_id, 11188 (void *)&cmd_vf_vlan_stripq_on_off, 11189 NULL, 11190 }, 11191 }; 11192 11193 /* vf vlan insert configuration */ 11194 11195 /* Common result structure for vf vlan insert */ 11196 struct cmd_vf_vlan_insert_result { 11197 cmdline_fixed_string_t set; 11198 cmdline_fixed_string_t vf; 11199 cmdline_fixed_string_t vlan; 11200 cmdline_fixed_string_t insert; 11201 uint8_t port_id; 11202 uint16_t vf_id; 11203 uint16_t vlan_id; 11204 }; 11205 11206 /* Common CLI fields for vf vlan insert enable disable */ 11207 cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 11208 TOKEN_STRING_INITIALIZER 11209 (struct cmd_vf_vlan_insert_result, 11210 set, "set"); 11211 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 11212 TOKEN_STRING_INITIALIZER 11213 (struct cmd_vf_vlan_insert_result, 11214 vf, "vf"); 11215 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 11216 TOKEN_STRING_INITIALIZER 11217 (struct cmd_vf_vlan_insert_result, 11218 vlan, "vlan"); 11219 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 11220 TOKEN_STRING_INITIALIZER 11221 (struct cmd_vf_vlan_insert_result, 11222 insert, "insert"); 11223 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 11224 TOKEN_NUM_INITIALIZER 11225 (struct cmd_vf_vlan_insert_result, 11226 port_id, UINT8); 11227 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 11228 TOKEN_NUM_INITIALIZER 11229 (struct cmd_vf_vlan_insert_result, 11230 vf_id, UINT16); 11231 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 11232 TOKEN_NUM_INITIALIZER 11233 (struct cmd_vf_vlan_insert_result, 11234 vlan_id, UINT16); 11235 11236 static void 11237 cmd_set_vf_vlan_insert_parsed( 11238 void *parsed_result, 11239 __attribute__((unused)) struct cmdline *cl, 11240 __attribute__((unused)) void *data) 11241 { 11242 struct cmd_vf_vlan_insert_result *res = parsed_result; 11243 int ret = -ENOTSUP; 11244 11245 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11246 return; 11247 11248 #ifdef RTE_LIBRTE_IXGBE_PMD 11249 if (ret == -ENOTSUP) 11250 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 11251 res->vlan_id); 11252 #endif 11253 #ifdef RTE_LIBRTE_I40E_PMD 11254 if (ret == -ENOTSUP) 11255 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 11256 res->vlan_id); 11257 #endif 11258 11259 switch (ret) { 11260 case 0: 11261 break; 11262 case -EINVAL: 11263 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id); 11264 break; 11265 case -ENODEV: 11266 printf("invalid port_id %d\n", res->port_id); 11267 break; 11268 case -ENOTSUP: 11269 printf("function not implemented\n"); 11270 break; 11271 default: 11272 printf("programming error: (%s)\n", strerror(-ret)); 11273 } 11274 } 11275 11276 cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 11277 .f = cmd_set_vf_vlan_insert_parsed, 11278 .data = NULL, 11279 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 11280 .tokens = { 11281 (void *)&cmd_vf_vlan_insert_set, 11282 (void *)&cmd_vf_vlan_insert_vf, 11283 (void *)&cmd_vf_vlan_insert_vlan, 11284 (void *)&cmd_vf_vlan_insert_insert, 11285 (void *)&cmd_vf_vlan_insert_port_id, 11286 (void *)&cmd_vf_vlan_insert_vf_id, 11287 (void *)&cmd_vf_vlan_insert_vlan_id, 11288 NULL, 11289 }, 11290 }; 11291 11292 /* tx loopback configuration */ 11293 11294 /* Common result structure for tx loopback */ 11295 struct cmd_tx_loopback_result { 11296 cmdline_fixed_string_t set; 11297 cmdline_fixed_string_t tx; 11298 cmdline_fixed_string_t loopback; 11299 uint8_t port_id; 11300 cmdline_fixed_string_t on_off; 11301 }; 11302 11303 /* Common CLI fields for tx loopback enable disable */ 11304 cmdline_parse_token_string_t cmd_tx_loopback_set = 11305 TOKEN_STRING_INITIALIZER 11306 (struct cmd_tx_loopback_result, 11307 set, "set"); 11308 cmdline_parse_token_string_t cmd_tx_loopback_tx = 11309 TOKEN_STRING_INITIALIZER 11310 (struct cmd_tx_loopback_result, 11311 tx, "tx"); 11312 cmdline_parse_token_string_t cmd_tx_loopback_loopback = 11313 TOKEN_STRING_INITIALIZER 11314 (struct cmd_tx_loopback_result, 11315 loopback, "loopback"); 11316 cmdline_parse_token_num_t cmd_tx_loopback_port_id = 11317 TOKEN_NUM_INITIALIZER 11318 (struct cmd_tx_loopback_result, 11319 port_id, UINT8); 11320 cmdline_parse_token_string_t cmd_tx_loopback_on_off = 11321 TOKEN_STRING_INITIALIZER 11322 (struct cmd_tx_loopback_result, 11323 on_off, "on#off"); 11324 11325 static void 11326 cmd_set_tx_loopback_parsed( 11327 void *parsed_result, 11328 __attribute__((unused)) struct cmdline *cl, 11329 __attribute__((unused)) void *data) 11330 { 11331 struct cmd_tx_loopback_result *res = parsed_result; 11332 int ret = -ENOTSUP; 11333 11334 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11335 11336 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11337 return; 11338 11339 #ifdef RTE_LIBRTE_IXGBE_PMD 11340 if (ret == -ENOTSUP) 11341 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 11342 #endif 11343 #ifdef RTE_LIBRTE_I40E_PMD 11344 if (ret == -ENOTSUP) 11345 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 11346 #endif 11347 11348 switch (ret) { 11349 case 0: 11350 break; 11351 case -EINVAL: 11352 printf("invalid is_on %d\n", is_on); 11353 break; 11354 case -ENODEV: 11355 printf("invalid port_id %d\n", res->port_id); 11356 break; 11357 case -ENOTSUP: 11358 printf("function not implemented\n"); 11359 break; 11360 default: 11361 printf("programming error: (%s)\n", strerror(-ret)); 11362 } 11363 } 11364 11365 cmdline_parse_inst_t cmd_set_tx_loopback = { 11366 .f = cmd_set_tx_loopback_parsed, 11367 .data = NULL, 11368 .help_str = "set tx loopback <port_id> on|off", 11369 .tokens = { 11370 (void *)&cmd_tx_loopback_set, 11371 (void *)&cmd_tx_loopback_tx, 11372 (void *)&cmd_tx_loopback_loopback, 11373 (void *)&cmd_tx_loopback_port_id, 11374 (void *)&cmd_tx_loopback_on_off, 11375 NULL, 11376 }, 11377 }; 11378 11379 #ifdef RTE_LIBRTE_IXGBE_PMD 11380 /* all queues drop enable configuration */ 11381 11382 /* Common result structure for all queues drop enable */ 11383 struct cmd_all_queues_drop_en_result { 11384 cmdline_fixed_string_t set; 11385 cmdline_fixed_string_t all; 11386 cmdline_fixed_string_t queues; 11387 cmdline_fixed_string_t drop; 11388 uint8_t port_id; 11389 cmdline_fixed_string_t on_off; 11390 }; 11391 11392 /* Common CLI fields for tx loopback enable disable */ 11393 cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 11394 TOKEN_STRING_INITIALIZER 11395 (struct cmd_all_queues_drop_en_result, 11396 set, "set"); 11397 cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 11398 TOKEN_STRING_INITIALIZER 11399 (struct cmd_all_queues_drop_en_result, 11400 all, "all"); 11401 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 11402 TOKEN_STRING_INITIALIZER 11403 (struct cmd_all_queues_drop_en_result, 11404 queues, "queues"); 11405 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 11406 TOKEN_STRING_INITIALIZER 11407 (struct cmd_all_queues_drop_en_result, 11408 drop, "drop"); 11409 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 11410 TOKEN_NUM_INITIALIZER 11411 (struct cmd_all_queues_drop_en_result, 11412 port_id, UINT8); 11413 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 11414 TOKEN_STRING_INITIALIZER 11415 (struct cmd_all_queues_drop_en_result, 11416 on_off, "on#off"); 11417 11418 static void 11419 cmd_set_all_queues_drop_en_parsed( 11420 void *parsed_result, 11421 __attribute__((unused)) struct cmdline *cl, 11422 __attribute__((unused)) void *data) 11423 { 11424 struct cmd_all_queues_drop_en_result *res = parsed_result; 11425 int ret = 0; 11426 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11427 11428 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11429 return; 11430 11431 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 11432 switch (ret) { 11433 case 0: 11434 break; 11435 case -EINVAL: 11436 printf("invalid is_on %d\n", is_on); 11437 break; 11438 case -ENODEV: 11439 printf("invalid port_id %d\n", res->port_id); 11440 break; 11441 case -ENOTSUP: 11442 printf("function not implemented\n"); 11443 break; 11444 default: 11445 printf("programming error: (%s)\n", strerror(-ret)); 11446 } 11447 } 11448 11449 cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 11450 .f = cmd_set_all_queues_drop_en_parsed, 11451 .data = NULL, 11452 .help_str = "set all queues drop <port_id> on|off", 11453 .tokens = { 11454 (void *)&cmd_all_queues_drop_en_set, 11455 (void *)&cmd_all_queues_drop_en_all, 11456 (void *)&cmd_all_queues_drop_en_queues, 11457 (void *)&cmd_all_queues_drop_en_drop, 11458 (void *)&cmd_all_queues_drop_en_port_id, 11459 (void *)&cmd_all_queues_drop_en_on_off, 11460 NULL, 11461 }, 11462 }; 11463 11464 /* vf split drop enable configuration */ 11465 11466 /* Common result structure for vf split drop enable */ 11467 struct cmd_vf_split_drop_en_result { 11468 cmdline_fixed_string_t set; 11469 cmdline_fixed_string_t vf; 11470 cmdline_fixed_string_t split; 11471 cmdline_fixed_string_t drop; 11472 uint8_t port_id; 11473 uint16_t vf_id; 11474 cmdline_fixed_string_t on_off; 11475 }; 11476 11477 /* Common CLI fields for vf split drop enable disable */ 11478 cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 11479 TOKEN_STRING_INITIALIZER 11480 (struct cmd_vf_split_drop_en_result, 11481 set, "set"); 11482 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 11483 TOKEN_STRING_INITIALIZER 11484 (struct cmd_vf_split_drop_en_result, 11485 vf, "vf"); 11486 cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 11487 TOKEN_STRING_INITIALIZER 11488 (struct cmd_vf_split_drop_en_result, 11489 split, "split"); 11490 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 11491 TOKEN_STRING_INITIALIZER 11492 (struct cmd_vf_split_drop_en_result, 11493 drop, "drop"); 11494 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 11495 TOKEN_NUM_INITIALIZER 11496 (struct cmd_vf_split_drop_en_result, 11497 port_id, UINT8); 11498 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 11499 TOKEN_NUM_INITIALIZER 11500 (struct cmd_vf_split_drop_en_result, 11501 vf_id, UINT16); 11502 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 11503 TOKEN_STRING_INITIALIZER 11504 (struct cmd_vf_split_drop_en_result, 11505 on_off, "on#off"); 11506 11507 static void 11508 cmd_set_vf_split_drop_en_parsed( 11509 void *parsed_result, 11510 __attribute__((unused)) struct cmdline *cl, 11511 __attribute__((unused)) void *data) 11512 { 11513 struct cmd_vf_split_drop_en_result *res = parsed_result; 11514 int ret; 11515 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11516 11517 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11518 return; 11519 11520 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 11521 is_on); 11522 switch (ret) { 11523 case 0: 11524 break; 11525 case -EINVAL: 11526 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11527 break; 11528 case -ENODEV: 11529 printf("invalid port_id %d\n", res->port_id); 11530 break; 11531 default: 11532 printf("programming error: (%s)\n", strerror(-ret)); 11533 } 11534 } 11535 11536 cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 11537 .f = cmd_set_vf_split_drop_en_parsed, 11538 .data = NULL, 11539 .help_str = "set vf split drop <port_id> <vf_id> on|off", 11540 .tokens = { 11541 (void *)&cmd_vf_split_drop_en_set, 11542 (void *)&cmd_vf_split_drop_en_vf, 11543 (void *)&cmd_vf_split_drop_en_split, 11544 (void *)&cmd_vf_split_drop_en_drop, 11545 (void *)&cmd_vf_split_drop_en_port_id, 11546 (void *)&cmd_vf_split_drop_en_vf_id, 11547 (void *)&cmd_vf_split_drop_en_on_off, 11548 NULL, 11549 }, 11550 }; 11551 #endif 11552 11553 /* vf mac address configuration */ 11554 11555 /* Common result structure for vf mac address */ 11556 struct cmd_set_vf_mac_addr_result { 11557 cmdline_fixed_string_t set; 11558 cmdline_fixed_string_t vf; 11559 cmdline_fixed_string_t mac; 11560 cmdline_fixed_string_t addr; 11561 uint8_t port_id; 11562 uint16_t vf_id; 11563 struct ether_addr mac_addr; 11564 11565 }; 11566 11567 /* Common CLI fields for vf split drop enable disable */ 11568 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 11569 TOKEN_STRING_INITIALIZER 11570 (struct cmd_set_vf_mac_addr_result, 11571 set, "set"); 11572 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 11573 TOKEN_STRING_INITIALIZER 11574 (struct cmd_set_vf_mac_addr_result, 11575 vf, "vf"); 11576 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 11577 TOKEN_STRING_INITIALIZER 11578 (struct cmd_set_vf_mac_addr_result, 11579 mac, "mac"); 11580 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 11581 TOKEN_STRING_INITIALIZER 11582 (struct cmd_set_vf_mac_addr_result, 11583 addr, "addr"); 11584 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 11585 TOKEN_NUM_INITIALIZER 11586 (struct cmd_set_vf_mac_addr_result, 11587 port_id, UINT8); 11588 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 11589 TOKEN_NUM_INITIALIZER 11590 (struct cmd_set_vf_mac_addr_result, 11591 vf_id, UINT16); 11592 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 11593 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 11594 mac_addr); 11595 11596 static void 11597 cmd_set_vf_mac_addr_parsed( 11598 void *parsed_result, 11599 __attribute__((unused)) struct cmdline *cl, 11600 __attribute__((unused)) void *data) 11601 { 11602 struct cmd_set_vf_mac_addr_result *res = parsed_result; 11603 int ret = -ENOTSUP; 11604 11605 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11606 return; 11607 11608 #ifdef RTE_LIBRTE_IXGBE_PMD 11609 if (ret == -ENOTSUP) 11610 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 11611 &res->mac_addr); 11612 #endif 11613 #ifdef RTE_LIBRTE_I40E_PMD 11614 if (ret == -ENOTSUP) 11615 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 11616 &res->mac_addr); 11617 #endif 11618 11619 switch (ret) { 11620 case 0: 11621 break; 11622 case -EINVAL: 11623 printf("invalid vf_id %d or mac_addr\n", res->vf_id); 11624 break; 11625 case -ENODEV: 11626 printf("invalid port_id %d\n", res->port_id); 11627 break; 11628 case -ENOTSUP: 11629 printf("function not implemented\n"); 11630 break; 11631 default: 11632 printf("programming error: (%s)\n", strerror(-ret)); 11633 } 11634 } 11635 11636 cmdline_parse_inst_t cmd_set_vf_mac_addr = { 11637 .f = cmd_set_vf_mac_addr_parsed, 11638 .data = NULL, 11639 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 11640 .tokens = { 11641 (void *)&cmd_set_vf_mac_addr_set, 11642 (void *)&cmd_set_vf_mac_addr_vf, 11643 (void *)&cmd_set_vf_mac_addr_mac, 11644 (void *)&cmd_set_vf_mac_addr_addr, 11645 (void *)&cmd_set_vf_mac_addr_port_id, 11646 (void *)&cmd_set_vf_mac_addr_vf_id, 11647 (void *)&cmd_set_vf_mac_addr_mac_addr, 11648 NULL, 11649 }, 11650 }; 11651 11652 #ifdef RTE_LIBRTE_IXGBE_PMD 11653 /* MACsec configuration */ 11654 11655 /* Common result structure for MACsec offload enable */ 11656 struct cmd_macsec_offload_on_result { 11657 cmdline_fixed_string_t set; 11658 cmdline_fixed_string_t macsec; 11659 cmdline_fixed_string_t offload; 11660 uint8_t port_id; 11661 cmdline_fixed_string_t on; 11662 cmdline_fixed_string_t encrypt; 11663 cmdline_fixed_string_t en_on_off; 11664 cmdline_fixed_string_t replay_protect; 11665 cmdline_fixed_string_t rp_on_off; 11666 }; 11667 11668 /* Common CLI fields for MACsec offload disable */ 11669 cmdline_parse_token_string_t cmd_macsec_offload_on_set = 11670 TOKEN_STRING_INITIALIZER 11671 (struct cmd_macsec_offload_on_result, 11672 set, "set"); 11673 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 11674 TOKEN_STRING_INITIALIZER 11675 (struct cmd_macsec_offload_on_result, 11676 macsec, "macsec"); 11677 cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 11678 TOKEN_STRING_INITIALIZER 11679 (struct cmd_macsec_offload_on_result, 11680 offload, "offload"); 11681 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 11682 TOKEN_NUM_INITIALIZER 11683 (struct cmd_macsec_offload_on_result, 11684 port_id, UINT8); 11685 cmdline_parse_token_string_t cmd_macsec_offload_on_on = 11686 TOKEN_STRING_INITIALIZER 11687 (struct cmd_macsec_offload_on_result, 11688 on, "on"); 11689 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 11690 TOKEN_STRING_INITIALIZER 11691 (struct cmd_macsec_offload_on_result, 11692 encrypt, "encrypt"); 11693 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 11694 TOKEN_STRING_INITIALIZER 11695 (struct cmd_macsec_offload_on_result, 11696 en_on_off, "on#off"); 11697 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 11698 TOKEN_STRING_INITIALIZER 11699 (struct cmd_macsec_offload_on_result, 11700 replay_protect, "replay-protect"); 11701 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 11702 TOKEN_STRING_INITIALIZER 11703 (struct cmd_macsec_offload_on_result, 11704 rp_on_off, "on#off"); 11705 11706 static void 11707 cmd_set_macsec_offload_on_parsed( 11708 void *parsed_result, 11709 __attribute__((unused)) struct cmdline *cl, 11710 __attribute__((unused)) void *data) 11711 { 11712 struct cmd_macsec_offload_on_result *res = parsed_result; 11713 int ret; 11714 portid_t port_id = res->port_id; 11715 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 11716 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 11717 11718 if (port_id_is_invalid(port_id, ENABLED_WARN)) 11719 return; 11720 11721 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC; 11722 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 11723 11724 switch (ret) { 11725 case 0: 11726 break; 11727 case -ENODEV: 11728 printf("invalid port_id %d\n", port_id); 11729 break; 11730 default: 11731 printf("programming error: (%s)\n", strerror(-ret)); 11732 } 11733 } 11734 11735 cmdline_parse_inst_t cmd_set_macsec_offload_on = { 11736 .f = cmd_set_macsec_offload_on_parsed, 11737 .data = NULL, 11738 .help_str = "set macsec offload <port_id> on " 11739 "encrypt on|off replay-protect on|off", 11740 .tokens = { 11741 (void *)&cmd_macsec_offload_on_set, 11742 (void *)&cmd_macsec_offload_on_macsec, 11743 (void *)&cmd_macsec_offload_on_offload, 11744 (void *)&cmd_macsec_offload_on_port_id, 11745 (void *)&cmd_macsec_offload_on_on, 11746 (void *)&cmd_macsec_offload_on_encrypt, 11747 (void *)&cmd_macsec_offload_on_en_on_off, 11748 (void *)&cmd_macsec_offload_on_replay_protect, 11749 (void *)&cmd_macsec_offload_on_rp_on_off, 11750 NULL, 11751 }, 11752 }; 11753 11754 /* Common result structure for MACsec offload disable */ 11755 struct cmd_macsec_offload_off_result { 11756 cmdline_fixed_string_t set; 11757 cmdline_fixed_string_t macsec; 11758 cmdline_fixed_string_t offload; 11759 uint8_t port_id; 11760 cmdline_fixed_string_t off; 11761 }; 11762 11763 /* Common CLI fields for MACsec offload disable */ 11764 cmdline_parse_token_string_t cmd_macsec_offload_off_set = 11765 TOKEN_STRING_INITIALIZER 11766 (struct cmd_macsec_offload_off_result, 11767 set, "set"); 11768 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 11769 TOKEN_STRING_INITIALIZER 11770 (struct cmd_macsec_offload_off_result, 11771 macsec, "macsec"); 11772 cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 11773 TOKEN_STRING_INITIALIZER 11774 (struct cmd_macsec_offload_off_result, 11775 offload, "offload"); 11776 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 11777 TOKEN_NUM_INITIALIZER 11778 (struct cmd_macsec_offload_off_result, 11779 port_id, UINT8); 11780 cmdline_parse_token_string_t cmd_macsec_offload_off_off = 11781 TOKEN_STRING_INITIALIZER 11782 (struct cmd_macsec_offload_off_result, 11783 off, "off"); 11784 11785 static void 11786 cmd_set_macsec_offload_off_parsed( 11787 void *parsed_result, 11788 __attribute__((unused)) struct cmdline *cl, 11789 __attribute__((unused)) void *data) 11790 { 11791 struct cmd_macsec_offload_off_result *res = parsed_result; 11792 int ret; 11793 portid_t port_id = res->port_id; 11794 11795 if (port_id_is_invalid(port_id, ENABLED_WARN)) 11796 return; 11797 11798 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC; 11799 ret = rte_pmd_ixgbe_macsec_disable(port_id); 11800 11801 switch (ret) { 11802 case 0: 11803 break; 11804 case -ENODEV: 11805 printf("invalid port_id %d\n", port_id); 11806 break; 11807 default: 11808 printf("programming error: (%s)\n", strerror(-ret)); 11809 } 11810 } 11811 11812 cmdline_parse_inst_t cmd_set_macsec_offload_off = { 11813 .f = cmd_set_macsec_offload_off_parsed, 11814 .data = NULL, 11815 .help_str = "set macsec offload <port_id> off", 11816 .tokens = { 11817 (void *)&cmd_macsec_offload_off_set, 11818 (void *)&cmd_macsec_offload_off_macsec, 11819 (void *)&cmd_macsec_offload_off_offload, 11820 (void *)&cmd_macsec_offload_off_port_id, 11821 (void *)&cmd_macsec_offload_off_off, 11822 NULL, 11823 }, 11824 }; 11825 11826 /* Common result structure for MACsec secure connection configure */ 11827 struct cmd_macsec_sc_result { 11828 cmdline_fixed_string_t set; 11829 cmdline_fixed_string_t macsec; 11830 cmdline_fixed_string_t sc; 11831 cmdline_fixed_string_t tx_rx; 11832 uint8_t port_id; 11833 struct ether_addr mac; 11834 uint16_t pi; 11835 }; 11836 11837 /* Common CLI fields for MACsec secure connection configure */ 11838 cmdline_parse_token_string_t cmd_macsec_sc_set = 11839 TOKEN_STRING_INITIALIZER 11840 (struct cmd_macsec_sc_result, 11841 set, "set"); 11842 cmdline_parse_token_string_t cmd_macsec_sc_macsec = 11843 TOKEN_STRING_INITIALIZER 11844 (struct cmd_macsec_sc_result, 11845 macsec, "macsec"); 11846 cmdline_parse_token_string_t cmd_macsec_sc_sc = 11847 TOKEN_STRING_INITIALIZER 11848 (struct cmd_macsec_sc_result, 11849 sc, "sc"); 11850 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 11851 TOKEN_STRING_INITIALIZER 11852 (struct cmd_macsec_sc_result, 11853 tx_rx, "tx#rx"); 11854 cmdline_parse_token_num_t cmd_macsec_sc_port_id = 11855 TOKEN_NUM_INITIALIZER 11856 (struct cmd_macsec_sc_result, 11857 port_id, UINT8); 11858 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 11859 TOKEN_ETHERADDR_INITIALIZER 11860 (struct cmd_macsec_sc_result, 11861 mac); 11862 cmdline_parse_token_num_t cmd_macsec_sc_pi = 11863 TOKEN_NUM_INITIALIZER 11864 (struct cmd_macsec_sc_result, 11865 pi, UINT16); 11866 11867 static void 11868 cmd_set_macsec_sc_parsed( 11869 void *parsed_result, 11870 __attribute__((unused)) struct cmdline *cl, 11871 __attribute__((unused)) void *data) 11872 { 11873 struct cmd_macsec_sc_result *res = parsed_result; 11874 int ret; 11875 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 11876 11877 ret = is_tx ? 11878 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 11879 res->mac.addr_bytes) : 11880 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 11881 res->mac.addr_bytes, res->pi); 11882 switch (ret) { 11883 case 0: 11884 break; 11885 case -ENODEV: 11886 printf("invalid port_id %d\n", res->port_id); 11887 break; 11888 default: 11889 printf("programming error: (%s)\n", strerror(-ret)); 11890 } 11891 } 11892 11893 cmdline_parse_inst_t cmd_set_macsec_sc = { 11894 .f = cmd_set_macsec_sc_parsed, 11895 .data = NULL, 11896 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 11897 .tokens = { 11898 (void *)&cmd_macsec_sc_set, 11899 (void *)&cmd_macsec_sc_macsec, 11900 (void *)&cmd_macsec_sc_sc, 11901 (void *)&cmd_macsec_sc_tx_rx, 11902 (void *)&cmd_macsec_sc_port_id, 11903 (void *)&cmd_macsec_sc_mac, 11904 (void *)&cmd_macsec_sc_pi, 11905 NULL, 11906 }, 11907 }; 11908 11909 /* Common result structure for MACsec secure connection configure */ 11910 struct cmd_macsec_sa_result { 11911 cmdline_fixed_string_t set; 11912 cmdline_fixed_string_t macsec; 11913 cmdline_fixed_string_t sa; 11914 cmdline_fixed_string_t tx_rx; 11915 uint8_t port_id; 11916 uint8_t idx; 11917 uint8_t an; 11918 uint32_t pn; 11919 cmdline_fixed_string_t key; 11920 }; 11921 11922 /* Common CLI fields for MACsec secure connection configure */ 11923 cmdline_parse_token_string_t cmd_macsec_sa_set = 11924 TOKEN_STRING_INITIALIZER 11925 (struct cmd_macsec_sa_result, 11926 set, "set"); 11927 cmdline_parse_token_string_t cmd_macsec_sa_macsec = 11928 TOKEN_STRING_INITIALIZER 11929 (struct cmd_macsec_sa_result, 11930 macsec, "macsec"); 11931 cmdline_parse_token_string_t cmd_macsec_sa_sa = 11932 TOKEN_STRING_INITIALIZER 11933 (struct cmd_macsec_sa_result, 11934 sa, "sa"); 11935 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 11936 TOKEN_STRING_INITIALIZER 11937 (struct cmd_macsec_sa_result, 11938 tx_rx, "tx#rx"); 11939 cmdline_parse_token_num_t cmd_macsec_sa_port_id = 11940 TOKEN_NUM_INITIALIZER 11941 (struct cmd_macsec_sa_result, 11942 port_id, UINT8); 11943 cmdline_parse_token_num_t cmd_macsec_sa_idx = 11944 TOKEN_NUM_INITIALIZER 11945 (struct cmd_macsec_sa_result, 11946 idx, UINT8); 11947 cmdline_parse_token_num_t cmd_macsec_sa_an = 11948 TOKEN_NUM_INITIALIZER 11949 (struct cmd_macsec_sa_result, 11950 an, UINT8); 11951 cmdline_parse_token_num_t cmd_macsec_sa_pn = 11952 TOKEN_NUM_INITIALIZER 11953 (struct cmd_macsec_sa_result, 11954 pn, UINT32); 11955 cmdline_parse_token_string_t cmd_macsec_sa_key = 11956 TOKEN_STRING_INITIALIZER 11957 (struct cmd_macsec_sa_result, 11958 key, NULL); 11959 11960 static void 11961 cmd_set_macsec_sa_parsed( 11962 void *parsed_result, 11963 __attribute__((unused)) struct cmdline *cl, 11964 __attribute__((unused)) void *data) 11965 { 11966 struct cmd_macsec_sa_result *res = parsed_result; 11967 int ret; 11968 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 11969 uint8_t key[16] = { 0 }; 11970 uint8_t xdgt0; 11971 uint8_t xdgt1; 11972 int key_len; 11973 int i; 11974 11975 key_len = strlen(res->key) / 2; 11976 if (key_len > 16) 11977 key_len = 16; 11978 11979 for (i = 0; i < key_len; i++) { 11980 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 11981 if (xdgt0 == 0xFF) 11982 return; 11983 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 11984 if (xdgt1 == 0xFF) 11985 return; 11986 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 11987 } 11988 11989 ret = is_tx ? 11990 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 11991 res->idx, res->an, res->pn, key) : 11992 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 11993 res->idx, res->an, res->pn, key); 11994 switch (ret) { 11995 case 0: 11996 break; 11997 case -EINVAL: 11998 printf("invalid idx %d or an %d\n", res->idx, res->an); 11999 break; 12000 case -ENODEV: 12001 printf("invalid port_id %d\n", res->port_id); 12002 break; 12003 default: 12004 printf("programming error: (%s)\n", strerror(-ret)); 12005 } 12006 } 12007 12008 cmdline_parse_inst_t cmd_set_macsec_sa = { 12009 .f = cmd_set_macsec_sa_parsed, 12010 .data = NULL, 12011 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 12012 .tokens = { 12013 (void *)&cmd_macsec_sa_set, 12014 (void *)&cmd_macsec_sa_macsec, 12015 (void *)&cmd_macsec_sa_sa, 12016 (void *)&cmd_macsec_sa_tx_rx, 12017 (void *)&cmd_macsec_sa_port_id, 12018 (void *)&cmd_macsec_sa_idx, 12019 (void *)&cmd_macsec_sa_an, 12020 (void *)&cmd_macsec_sa_pn, 12021 (void *)&cmd_macsec_sa_key, 12022 NULL, 12023 }, 12024 }; 12025 #endif 12026 12027 /* VF unicast promiscuous mode configuration */ 12028 12029 /* Common result structure for VF unicast promiscuous mode */ 12030 struct cmd_vf_promisc_result { 12031 cmdline_fixed_string_t set; 12032 cmdline_fixed_string_t vf; 12033 cmdline_fixed_string_t promisc; 12034 uint8_t port_id; 12035 uint32_t vf_id; 12036 cmdline_fixed_string_t on_off; 12037 }; 12038 12039 /* Common CLI fields for VF unicast promiscuous mode enable disable */ 12040 cmdline_parse_token_string_t cmd_vf_promisc_set = 12041 TOKEN_STRING_INITIALIZER 12042 (struct cmd_vf_promisc_result, 12043 set, "set"); 12044 cmdline_parse_token_string_t cmd_vf_promisc_vf = 12045 TOKEN_STRING_INITIALIZER 12046 (struct cmd_vf_promisc_result, 12047 vf, "vf"); 12048 cmdline_parse_token_string_t cmd_vf_promisc_promisc = 12049 TOKEN_STRING_INITIALIZER 12050 (struct cmd_vf_promisc_result, 12051 promisc, "promisc"); 12052 cmdline_parse_token_num_t cmd_vf_promisc_port_id = 12053 TOKEN_NUM_INITIALIZER 12054 (struct cmd_vf_promisc_result, 12055 port_id, UINT8); 12056 cmdline_parse_token_num_t cmd_vf_promisc_vf_id = 12057 TOKEN_NUM_INITIALIZER 12058 (struct cmd_vf_promisc_result, 12059 vf_id, UINT32); 12060 cmdline_parse_token_string_t cmd_vf_promisc_on_off = 12061 TOKEN_STRING_INITIALIZER 12062 (struct cmd_vf_promisc_result, 12063 on_off, "on#off"); 12064 12065 static void 12066 cmd_set_vf_promisc_parsed( 12067 void *parsed_result, 12068 __attribute__((unused)) struct cmdline *cl, 12069 __attribute__((unused)) void *data) 12070 { 12071 struct cmd_vf_promisc_result *res = parsed_result; 12072 int ret = -ENOTSUP; 12073 12074 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12075 12076 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12077 return; 12078 12079 #ifdef RTE_LIBRTE_I40E_PMD 12080 ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id, 12081 res->vf_id, is_on); 12082 #endif 12083 12084 switch (ret) { 12085 case 0: 12086 break; 12087 case -EINVAL: 12088 printf("invalid vf_id %d\n", res->vf_id); 12089 break; 12090 case -ENODEV: 12091 printf("invalid port_id %d\n", res->port_id); 12092 break; 12093 case -ENOTSUP: 12094 printf("function not implemented\n"); 12095 break; 12096 default: 12097 printf("programming error: (%s)\n", strerror(-ret)); 12098 } 12099 } 12100 12101 cmdline_parse_inst_t cmd_set_vf_promisc = { 12102 .f = cmd_set_vf_promisc_parsed, 12103 .data = NULL, 12104 .help_str = "set vf promisc <port_id> <vf_id> on|off: " 12105 "Set unicast promiscuous mode for a VF from the PF", 12106 .tokens = { 12107 (void *)&cmd_vf_promisc_set, 12108 (void *)&cmd_vf_promisc_vf, 12109 (void *)&cmd_vf_promisc_promisc, 12110 (void *)&cmd_vf_promisc_port_id, 12111 (void *)&cmd_vf_promisc_vf_id, 12112 (void *)&cmd_vf_promisc_on_off, 12113 NULL, 12114 }, 12115 }; 12116 12117 /* VF multicast promiscuous mode configuration */ 12118 12119 /* Common result structure for VF multicast promiscuous mode */ 12120 struct cmd_vf_allmulti_result { 12121 cmdline_fixed_string_t set; 12122 cmdline_fixed_string_t vf; 12123 cmdline_fixed_string_t allmulti; 12124 uint8_t port_id; 12125 uint32_t vf_id; 12126 cmdline_fixed_string_t on_off; 12127 }; 12128 12129 /* Common CLI fields for VF multicast promiscuous mode enable disable */ 12130 cmdline_parse_token_string_t cmd_vf_allmulti_set = 12131 TOKEN_STRING_INITIALIZER 12132 (struct cmd_vf_allmulti_result, 12133 set, "set"); 12134 cmdline_parse_token_string_t cmd_vf_allmulti_vf = 12135 TOKEN_STRING_INITIALIZER 12136 (struct cmd_vf_allmulti_result, 12137 vf, "vf"); 12138 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = 12139 TOKEN_STRING_INITIALIZER 12140 (struct cmd_vf_allmulti_result, 12141 allmulti, "allmulti"); 12142 cmdline_parse_token_num_t cmd_vf_allmulti_port_id = 12143 TOKEN_NUM_INITIALIZER 12144 (struct cmd_vf_allmulti_result, 12145 port_id, UINT8); 12146 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = 12147 TOKEN_NUM_INITIALIZER 12148 (struct cmd_vf_allmulti_result, 12149 vf_id, UINT32); 12150 cmdline_parse_token_string_t cmd_vf_allmulti_on_off = 12151 TOKEN_STRING_INITIALIZER 12152 (struct cmd_vf_allmulti_result, 12153 on_off, "on#off"); 12154 12155 static void 12156 cmd_set_vf_allmulti_parsed( 12157 void *parsed_result, 12158 __attribute__((unused)) struct cmdline *cl, 12159 __attribute__((unused)) void *data) 12160 { 12161 struct cmd_vf_allmulti_result *res = parsed_result; 12162 int ret = -ENOTSUP; 12163 12164 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12165 12166 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12167 return; 12168 12169 #ifdef RTE_LIBRTE_I40E_PMD 12170 ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id, 12171 res->vf_id, is_on); 12172 #endif 12173 12174 switch (ret) { 12175 case 0: 12176 break; 12177 case -EINVAL: 12178 printf("invalid vf_id %d\n", res->vf_id); 12179 break; 12180 case -ENODEV: 12181 printf("invalid port_id %d\n", res->port_id); 12182 break; 12183 case -ENOTSUP: 12184 printf("function not implemented\n"); 12185 break; 12186 default: 12187 printf("programming error: (%s)\n", strerror(-ret)); 12188 } 12189 } 12190 12191 cmdline_parse_inst_t cmd_set_vf_allmulti = { 12192 .f = cmd_set_vf_allmulti_parsed, 12193 .data = NULL, 12194 .help_str = "set vf allmulti <port_id> <vf_id> on|off: " 12195 "Set multicast promiscuous mode for a VF from the PF", 12196 .tokens = { 12197 (void *)&cmd_vf_allmulti_set, 12198 (void *)&cmd_vf_allmulti_vf, 12199 (void *)&cmd_vf_allmulti_allmulti, 12200 (void *)&cmd_vf_allmulti_port_id, 12201 (void *)&cmd_vf_allmulti_vf_id, 12202 (void *)&cmd_vf_allmulti_on_off, 12203 NULL, 12204 }, 12205 }; 12206 12207 /* vf broadcast mode configuration */ 12208 12209 /* Common result structure for vf broadcast */ 12210 struct cmd_set_vf_broadcast_result { 12211 cmdline_fixed_string_t set; 12212 cmdline_fixed_string_t vf; 12213 cmdline_fixed_string_t broadcast; 12214 uint8_t port_id; 12215 uint16_t vf_id; 12216 cmdline_fixed_string_t on_off; 12217 }; 12218 12219 /* Common CLI fields for vf broadcast enable disable */ 12220 cmdline_parse_token_string_t cmd_set_vf_broadcast_set = 12221 TOKEN_STRING_INITIALIZER 12222 (struct cmd_set_vf_broadcast_result, 12223 set, "set"); 12224 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf = 12225 TOKEN_STRING_INITIALIZER 12226 (struct cmd_set_vf_broadcast_result, 12227 vf, "vf"); 12228 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = 12229 TOKEN_STRING_INITIALIZER 12230 (struct cmd_set_vf_broadcast_result, 12231 broadcast, "broadcast"); 12232 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = 12233 TOKEN_NUM_INITIALIZER 12234 (struct cmd_set_vf_broadcast_result, 12235 port_id, UINT8); 12236 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = 12237 TOKEN_NUM_INITIALIZER 12238 (struct cmd_set_vf_broadcast_result, 12239 vf_id, UINT16); 12240 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off = 12241 TOKEN_STRING_INITIALIZER 12242 (struct cmd_set_vf_broadcast_result, 12243 on_off, "on#off"); 12244 12245 static void 12246 cmd_set_vf_broadcast_parsed( 12247 void *parsed_result, 12248 __attribute__((unused)) struct cmdline *cl, 12249 __attribute__((unused)) void *data) 12250 { 12251 struct cmd_set_vf_broadcast_result *res = parsed_result; 12252 int ret = -ENOTSUP; 12253 12254 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12255 12256 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12257 return; 12258 12259 #ifdef RTE_LIBRTE_I40E_PMD 12260 ret = rte_pmd_i40e_set_vf_broadcast(res->port_id, 12261 res->vf_id, is_on); 12262 #endif 12263 12264 switch (ret) { 12265 case 0: 12266 break; 12267 case -EINVAL: 12268 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12269 break; 12270 case -ENODEV: 12271 printf("invalid port_id %d\n", res->port_id); 12272 break; 12273 case -ENOTSUP: 12274 printf("function not implemented\n"); 12275 break; 12276 default: 12277 printf("programming error: (%s)\n", strerror(-ret)); 12278 } 12279 } 12280 12281 cmdline_parse_inst_t cmd_set_vf_broadcast = { 12282 .f = cmd_set_vf_broadcast_parsed, 12283 .data = NULL, 12284 .help_str = "set vf broadcast <port_id> <vf_id> on|off", 12285 .tokens = { 12286 (void *)&cmd_set_vf_broadcast_set, 12287 (void *)&cmd_set_vf_broadcast_vf, 12288 (void *)&cmd_set_vf_broadcast_broadcast, 12289 (void *)&cmd_set_vf_broadcast_port_id, 12290 (void *)&cmd_set_vf_broadcast_vf_id, 12291 (void *)&cmd_set_vf_broadcast_on_off, 12292 NULL, 12293 }, 12294 }; 12295 12296 /* vf vlan tag configuration */ 12297 12298 /* Common result structure for vf vlan tag */ 12299 struct cmd_set_vf_vlan_tag_result { 12300 cmdline_fixed_string_t set; 12301 cmdline_fixed_string_t vf; 12302 cmdline_fixed_string_t vlan; 12303 cmdline_fixed_string_t tag; 12304 uint8_t port_id; 12305 uint16_t vf_id; 12306 cmdline_fixed_string_t on_off; 12307 }; 12308 12309 /* Common CLI fields for vf vlan tag enable disable */ 12310 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set = 12311 TOKEN_STRING_INITIALIZER 12312 (struct cmd_set_vf_vlan_tag_result, 12313 set, "set"); 12314 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf = 12315 TOKEN_STRING_INITIALIZER 12316 (struct cmd_set_vf_vlan_tag_result, 12317 vf, "vf"); 12318 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan = 12319 TOKEN_STRING_INITIALIZER 12320 (struct cmd_set_vf_vlan_tag_result, 12321 vlan, "vlan"); 12322 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = 12323 TOKEN_STRING_INITIALIZER 12324 (struct cmd_set_vf_vlan_tag_result, 12325 tag, "tag"); 12326 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = 12327 TOKEN_NUM_INITIALIZER 12328 (struct cmd_set_vf_vlan_tag_result, 12329 port_id, UINT8); 12330 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = 12331 TOKEN_NUM_INITIALIZER 12332 (struct cmd_set_vf_vlan_tag_result, 12333 vf_id, UINT16); 12334 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off = 12335 TOKEN_STRING_INITIALIZER 12336 (struct cmd_set_vf_vlan_tag_result, 12337 on_off, "on#off"); 12338 12339 static void 12340 cmd_set_vf_vlan_tag_parsed( 12341 void *parsed_result, 12342 __attribute__((unused)) struct cmdline *cl, 12343 __attribute__((unused)) void *data) 12344 { 12345 struct cmd_set_vf_vlan_tag_result *res = parsed_result; 12346 int ret = -ENOTSUP; 12347 12348 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12349 12350 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12351 return; 12352 12353 #ifdef RTE_LIBRTE_I40E_PMD 12354 ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id, 12355 res->vf_id, is_on); 12356 #endif 12357 12358 switch (ret) { 12359 case 0: 12360 break; 12361 case -EINVAL: 12362 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12363 break; 12364 case -ENODEV: 12365 printf("invalid port_id %d\n", res->port_id); 12366 break; 12367 case -ENOTSUP: 12368 printf("function not implemented\n"); 12369 break; 12370 default: 12371 printf("programming error: (%s)\n", strerror(-ret)); 12372 } 12373 } 12374 12375 cmdline_parse_inst_t cmd_set_vf_vlan_tag = { 12376 .f = cmd_set_vf_vlan_tag_parsed, 12377 .data = NULL, 12378 .help_str = "set vf vlan tag <port_id> <vf_id> on|off", 12379 .tokens = { 12380 (void *)&cmd_set_vf_vlan_tag_set, 12381 (void *)&cmd_set_vf_vlan_tag_vf, 12382 (void *)&cmd_set_vf_vlan_tag_vlan, 12383 (void *)&cmd_set_vf_vlan_tag_tag, 12384 (void *)&cmd_set_vf_vlan_tag_port_id, 12385 (void *)&cmd_set_vf_vlan_tag_vf_id, 12386 (void *)&cmd_set_vf_vlan_tag_on_off, 12387 NULL, 12388 }, 12389 }; 12390 12391 /* ******************************************************************************** */ 12392 12393 /* list of instructions */ 12394 cmdline_parse_ctx_t main_ctx[] = { 12395 (cmdline_parse_inst_t *)&cmd_help_brief, 12396 (cmdline_parse_inst_t *)&cmd_help_long, 12397 (cmdline_parse_inst_t *)&cmd_quit, 12398 (cmdline_parse_inst_t *)&cmd_showport, 12399 (cmdline_parse_inst_t *)&cmd_showqueue, 12400 (cmdline_parse_inst_t *)&cmd_showportall, 12401 (cmdline_parse_inst_t *)&cmd_showcfg, 12402 (cmdline_parse_inst_t *)&cmd_start, 12403 (cmdline_parse_inst_t *)&cmd_start_tx_first, 12404 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 12405 (cmdline_parse_inst_t *)&cmd_set_link_up, 12406 (cmdline_parse_inst_t *)&cmd_set_link_down, 12407 (cmdline_parse_inst_t *)&cmd_reset, 12408 (cmdline_parse_inst_t *)&cmd_set_numbers, 12409 (cmdline_parse_inst_t *)&cmd_set_txpkts, 12410 (cmdline_parse_inst_t *)&cmd_set_txsplit, 12411 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 12412 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 12413 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 12414 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 12415 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 12416 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 12417 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 12418 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 12419 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 12420 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 12421 (cmdline_parse_inst_t *)&cmd_set_link_check, 12422 #ifdef RTE_NIC_BYPASS 12423 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 12424 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 12425 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 12426 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 12427 #endif 12428 #ifdef RTE_LIBRTE_PMD_BOND 12429 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 12430 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 12431 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 12432 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 12433 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 12434 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 12435 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 12436 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 12437 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 12438 #endif 12439 (cmdline_parse_inst_t *)&cmd_vlan_offload, 12440 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 12441 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 12442 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 12443 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 12444 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 12445 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 12446 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 12447 (cmdline_parse_inst_t *)&cmd_csum_set, 12448 (cmdline_parse_inst_t *)&cmd_csum_show, 12449 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 12450 (cmdline_parse_inst_t *)&cmd_tso_set, 12451 (cmdline_parse_inst_t *)&cmd_tso_show, 12452 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 12453 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 12454 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 12455 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 12456 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 12457 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 12458 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 12459 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 12460 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 12461 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 12462 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 12463 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 12464 (cmdline_parse_inst_t *)&cmd_config_dcb, 12465 (cmdline_parse_inst_t *)&cmd_read_reg, 12466 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 12467 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 12468 (cmdline_parse_inst_t *)&cmd_write_reg, 12469 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 12470 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 12471 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 12472 (cmdline_parse_inst_t *)&cmd_stop, 12473 (cmdline_parse_inst_t *)&cmd_mac_addr, 12474 (cmdline_parse_inst_t *)&cmd_set_qmap, 12475 (cmdline_parse_inst_t *)&cmd_operate_port, 12476 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 12477 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 12478 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 12479 (cmdline_parse_inst_t *)&cmd_config_speed_all, 12480 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 12481 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 12482 (cmdline_parse_inst_t *)&cmd_config_mtu, 12483 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 12484 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 12485 (cmdline_parse_inst_t *)&cmd_config_rss, 12486 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 12487 (cmdline_parse_inst_t *)&cmd_config_txqflags, 12488 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 12489 (cmdline_parse_inst_t *)&cmd_showport_reta, 12490 (cmdline_parse_inst_t *)&cmd_config_burst, 12491 (cmdline_parse_inst_t *)&cmd_config_thresh, 12492 (cmdline_parse_inst_t *)&cmd_config_threshold, 12493 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 12494 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 12495 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 12496 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 12497 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 12498 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 12499 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 12500 (cmdline_parse_inst_t *)&cmd_global_config, 12501 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 12502 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 12503 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 12504 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 12505 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 12506 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 12507 (cmdline_parse_inst_t *)&cmd_dump, 12508 (cmdline_parse_inst_t *)&cmd_dump_one, 12509 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 12510 (cmdline_parse_inst_t *)&cmd_syn_filter, 12511 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 12512 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 12513 (cmdline_parse_inst_t *)&cmd_flex_filter, 12514 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 12515 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 12516 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 12517 (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director, 12518 (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director, 12519 (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director, 12520 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 12521 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 12522 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 12523 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 12524 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 12525 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 12526 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 12527 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 12528 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 12529 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 12530 (cmdline_parse_inst_t *)&cmd_set_hash_input_set, 12531 (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, 12532 (cmdline_parse_inst_t *)&cmd_flow, 12533 (cmdline_parse_inst_t *)&cmd_mcast_addr, 12534 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, 12535 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, 12536 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all, 12537 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific, 12538 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en, 12539 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis, 12540 (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis, 12541 (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis, 12542 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add, 12543 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del, 12544 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 12545 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 12546 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 12547 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 12548 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 12549 #ifdef RTE_LIBRTE_IXGBE_PMD 12550 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 12551 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 12552 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 12553 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 12554 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 12555 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 12556 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 12557 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 12558 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 12559 #endif 12560 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 12561 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 12562 (cmdline_parse_inst_t *)&cmd_set_vf_promisc, 12563 (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, 12564 (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, 12565 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, 12566 NULL, 12567 }; 12568 12569 /* prompt function, called from main on MASTER lcore */ 12570 void 12571 prompt(void) 12572 { 12573 /* initialize non-constant commands */ 12574 cmd_set_fwd_mode_init(); 12575 cmd_set_fwd_retry_mode_init(); 12576 12577 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 12578 if (testpmd_cl == NULL) 12579 return; 12580 cmdline_interact(testpmd_cl); 12581 cmdline_stdin_exit(testpmd_cl); 12582 } 12583 12584 void 12585 prompt_exit(void) 12586 { 12587 if (testpmd_cl != NULL) 12588 cmdline_quit(testpmd_cl); 12589 } 12590 12591 static void 12592 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 12593 { 12594 if (id == (portid_t)RTE_PORT_ALL) { 12595 portid_t pid; 12596 12597 FOREACH_PORT(pid, ports) { 12598 /* check if need_reconfig has been set to 1 */ 12599 if (ports[pid].need_reconfig == 0) 12600 ports[pid].need_reconfig = dev; 12601 /* check if need_reconfig_queues has been set to 1 */ 12602 if (ports[pid].need_reconfig_queues == 0) 12603 ports[pid].need_reconfig_queues = queue; 12604 } 12605 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 12606 /* check if need_reconfig has been set to 1 */ 12607 if (ports[id].need_reconfig == 0) 12608 ports[id].need_reconfig = dev; 12609 /* check if need_reconfig_queues has been set to 1 */ 12610 if (ports[id].need_reconfig_queues == 0) 12611 ports[id].need_reconfig_queues = queue; 12612 } 12613 } 12614