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