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