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