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