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