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 } 4054 4055 } 4056 4057 cmdline_parse_token_string_t cmd_createbonded_device_create = 4058 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4059 create, "create"); 4060 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 4061 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4062 bonded, "bonded"); 4063 cmdline_parse_token_string_t cmd_createbonded_device_device = 4064 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4065 device, "device"); 4066 cmdline_parse_token_num_t cmd_createbonded_device_mode = 4067 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4068 mode, UINT8); 4069 cmdline_parse_token_num_t cmd_createbonded_device_socket = 4070 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4071 socket, UINT8); 4072 4073 cmdline_parse_inst_t cmd_create_bonded_device = { 4074 .f = cmd_create_bonded_device_parsed, 4075 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket", 4076 .data = NULL, 4077 .tokens = { 4078 (void *)&cmd_createbonded_device_create, 4079 (void *)&cmd_createbonded_device_bonded, 4080 (void *)&cmd_createbonded_device_device, 4081 (void *)&cmd_createbonded_device_mode, 4082 (void *)&cmd_createbonded_device_socket, 4083 NULL 4084 } 4085 }; 4086 4087 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 4088 struct cmd_set_bond_mac_addr_result { 4089 cmdline_fixed_string_t set; 4090 cmdline_fixed_string_t bonding; 4091 cmdline_fixed_string_t mac_addr; 4092 uint8_t port_num; 4093 struct ether_addr address; 4094 }; 4095 4096 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 4097 __attribute__((unused)) struct cmdline *cl, 4098 __attribute__((unused)) void *data) 4099 { 4100 struct cmd_set_bond_mac_addr_result *res = parsed_result; 4101 int ret; 4102 4103 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 4104 return; 4105 4106 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 4107 4108 /* check the return value and print it if is < 0 */ 4109 if (ret < 0) 4110 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4111 } 4112 4113 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 4114 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 4115 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 4116 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 4117 "bonding"); 4118 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 4119 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 4120 "mac_addr"); 4121 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 4122 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); 4123 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 4124 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 4125 4126 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 4127 .f = cmd_set_bond_mac_addr_parsed, 4128 .data = (void *) 0, 4129 .help_str = "set bonding mac_addr (port_id) (address): ", 4130 .tokens = { 4131 (void *)&cmd_set_bond_mac_addr_set, 4132 (void *)&cmd_set_bond_mac_addr_bonding, 4133 (void *)&cmd_set_bond_mac_addr_mac, 4134 (void *)&cmd_set_bond_mac_addr_portnum, 4135 (void *)&cmd_set_bond_mac_addr_addr, 4136 NULL 4137 } 4138 }; 4139 4140 4141 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 4142 struct cmd_set_bond_mon_period_result { 4143 cmdline_fixed_string_t set; 4144 cmdline_fixed_string_t bonding; 4145 cmdline_fixed_string_t mon_period; 4146 uint8_t port_num; 4147 uint32_t period_ms; 4148 }; 4149 4150 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 4151 __attribute__((unused)) struct cmdline *cl, 4152 __attribute__((unused)) void *data) 4153 { 4154 struct cmd_set_bond_mon_period_result *res = parsed_result; 4155 int ret; 4156 4157 if (res->port_num >= nb_ports) { 4158 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 4159 return; 4160 } 4161 4162 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 4163 4164 /* check the return value and print it if is < 0 */ 4165 if (ret < 0) 4166 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4167 } 4168 4169 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 4170 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4171 set, "set"); 4172 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 4173 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4174 bonding, "bonding"); 4175 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 4176 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4177 mon_period, "mon_period"); 4178 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 4179 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4180 port_num, UINT8); 4181 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 4182 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4183 period_ms, UINT32); 4184 4185 cmdline_parse_inst_t cmd_set_bond_mon_period = { 4186 .f = cmd_set_bond_mon_period_parsed, 4187 .data = (void *) 0, 4188 .help_str = "set bonding mon_period (port_id) (period_ms): ", 4189 .tokens = { 4190 (void *)&cmd_set_bond_mon_period_set, 4191 (void *)&cmd_set_bond_mon_period_bonding, 4192 (void *)&cmd_set_bond_mon_period_mon_period, 4193 (void *)&cmd_set_bond_mon_period_portnum, 4194 (void *)&cmd_set_bond_mon_period_period_ms, 4195 NULL 4196 } 4197 }; 4198 4199 #endif /* RTE_LIBRTE_PMD_BOND */ 4200 4201 /* *** SET FORWARDING MODE *** */ 4202 struct cmd_set_fwd_mode_result { 4203 cmdline_fixed_string_t set; 4204 cmdline_fixed_string_t fwd; 4205 cmdline_fixed_string_t mode; 4206 }; 4207 4208 static void cmd_set_fwd_mode_parsed(void *parsed_result, 4209 __attribute__((unused)) struct cmdline *cl, 4210 __attribute__((unused)) void *data) 4211 { 4212 struct cmd_set_fwd_mode_result *res = parsed_result; 4213 4214 set_pkt_forwarding_mode(res->mode); 4215 } 4216 4217 cmdline_parse_token_string_t cmd_setfwd_set = 4218 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 4219 cmdline_parse_token_string_t cmd_setfwd_fwd = 4220 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 4221 cmdline_parse_token_string_t cmd_setfwd_mode = 4222 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 4223 "" /* defined at init */); 4224 4225 cmdline_parse_inst_t cmd_set_fwd_mode = { 4226 .f = cmd_set_fwd_mode_parsed, 4227 .data = NULL, 4228 .help_str = NULL, /* defined at init */ 4229 .tokens = { 4230 (void *)&cmd_setfwd_set, 4231 (void *)&cmd_setfwd_fwd, 4232 (void *)&cmd_setfwd_mode, 4233 NULL, 4234 }, 4235 }; 4236 4237 static void cmd_set_fwd_mode_init(void) 4238 { 4239 char *modes, *c; 4240 static char token[128]; 4241 static char help[256]; 4242 cmdline_parse_token_string_t *token_struct; 4243 4244 modes = list_pkt_forwarding_modes(); 4245 snprintf(help, sizeof help, "set fwd %s - " 4246 "set packet forwarding mode", modes); 4247 cmd_set_fwd_mode.help_str = help; 4248 4249 /* string token separator is # */ 4250 for (c = token; *modes != '\0'; modes++) 4251 if (*modes == '|') 4252 *c++ = '#'; 4253 else 4254 *c++ = *modes; 4255 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 4256 token_struct->string_data.str = token; 4257 } 4258 4259 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 4260 struct cmd_set_burst_tx_retry_result { 4261 cmdline_fixed_string_t set; 4262 cmdline_fixed_string_t burst; 4263 cmdline_fixed_string_t tx; 4264 cmdline_fixed_string_t delay; 4265 uint32_t time; 4266 cmdline_fixed_string_t retry; 4267 uint32_t retry_num; 4268 }; 4269 4270 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 4271 __attribute__((unused)) struct cmdline *cl, 4272 __attribute__((unused)) void *data) 4273 { 4274 struct cmd_set_burst_tx_retry_result *res = parsed_result; 4275 4276 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 4277 && !strcmp(res->tx, "tx")) { 4278 if (!strcmp(res->delay, "delay")) 4279 burst_tx_delay_time = res->time; 4280 if (!strcmp(res->retry, "retry")) 4281 burst_tx_retry_num = res->retry_num; 4282 } 4283 4284 } 4285 4286 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 4287 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 4288 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 4289 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 4290 "burst"); 4291 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 4292 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 4293 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 4294 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 4295 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 4296 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 4297 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 4298 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 4299 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 4300 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 4301 4302 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 4303 .f = cmd_set_burst_tx_retry_parsed, 4304 .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)", 4305 .tokens = { 4306 (void *)&cmd_set_burst_tx_retry_set, 4307 (void *)&cmd_set_burst_tx_retry_burst, 4308 (void *)&cmd_set_burst_tx_retry_tx, 4309 (void *)&cmd_set_burst_tx_retry_delay, 4310 (void *)&cmd_set_burst_tx_retry_time, 4311 (void *)&cmd_set_burst_tx_retry_retry, 4312 (void *)&cmd_set_burst_tx_retry_retry_num, 4313 NULL, 4314 }, 4315 }; 4316 4317 /* *** SET PROMISC MODE *** */ 4318 struct cmd_set_promisc_mode_result { 4319 cmdline_fixed_string_t set; 4320 cmdline_fixed_string_t promisc; 4321 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 4322 uint8_t port_num; /* valid if "allports" argument == 0 */ 4323 cmdline_fixed_string_t mode; 4324 }; 4325 4326 static void cmd_set_promisc_mode_parsed(void *parsed_result, 4327 __attribute__((unused)) struct cmdline *cl, 4328 void *allports) 4329 { 4330 struct cmd_set_promisc_mode_result *res = parsed_result; 4331 int enable; 4332 portid_t i; 4333 4334 if (!strcmp(res->mode, "on")) 4335 enable = 1; 4336 else 4337 enable = 0; 4338 4339 /* all ports */ 4340 if (allports) { 4341 FOREACH_PORT(i, ports) { 4342 if (enable) 4343 rte_eth_promiscuous_enable(i); 4344 else 4345 rte_eth_promiscuous_disable(i); 4346 } 4347 } 4348 else { 4349 if (enable) 4350 rte_eth_promiscuous_enable(res->port_num); 4351 else 4352 rte_eth_promiscuous_disable(res->port_num); 4353 } 4354 } 4355 4356 cmdline_parse_token_string_t cmd_setpromisc_set = 4357 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 4358 cmdline_parse_token_string_t cmd_setpromisc_promisc = 4359 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 4360 "promisc"); 4361 cmdline_parse_token_string_t cmd_setpromisc_portall = 4362 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 4363 "all"); 4364 cmdline_parse_token_num_t cmd_setpromisc_portnum = 4365 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 4366 UINT8); 4367 cmdline_parse_token_string_t cmd_setpromisc_mode = 4368 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 4369 "on#off"); 4370 4371 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 4372 .f = cmd_set_promisc_mode_parsed, 4373 .data = (void *)1, 4374 .help_str = "set promisc all on|off: set promisc mode for all ports", 4375 .tokens = { 4376 (void *)&cmd_setpromisc_set, 4377 (void *)&cmd_setpromisc_promisc, 4378 (void *)&cmd_setpromisc_portall, 4379 (void *)&cmd_setpromisc_mode, 4380 NULL, 4381 }, 4382 }; 4383 4384 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 4385 .f = cmd_set_promisc_mode_parsed, 4386 .data = (void *)0, 4387 .help_str = "set promisc X on|off: set promisc mode on port X", 4388 .tokens = { 4389 (void *)&cmd_setpromisc_set, 4390 (void *)&cmd_setpromisc_promisc, 4391 (void *)&cmd_setpromisc_portnum, 4392 (void *)&cmd_setpromisc_mode, 4393 NULL, 4394 }, 4395 }; 4396 4397 /* *** SET ALLMULTI MODE *** */ 4398 struct cmd_set_allmulti_mode_result { 4399 cmdline_fixed_string_t set; 4400 cmdline_fixed_string_t allmulti; 4401 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 4402 uint8_t port_num; /* valid if "allports" argument == 0 */ 4403 cmdline_fixed_string_t mode; 4404 }; 4405 4406 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 4407 __attribute__((unused)) struct cmdline *cl, 4408 void *allports) 4409 { 4410 struct cmd_set_allmulti_mode_result *res = parsed_result; 4411 int enable; 4412 portid_t i; 4413 4414 if (!strcmp(res->mode, "on")) 4415 enable = 1; 4416 else 4417 enable = 0; 4418 4419 /* all ports */ 4420 if (allports) { 4421 FOREACH_PORT(i, ports) { 4422 if (enable) 4423 rte_eth_allmulticast_enable(i); 4424 else 4425 rte_eth_allmulticast_disable(i); 4426 } 4427 } 4428 else { 4429 if (enable) 4430 rte_eth_allmulticast_enable(res->port_num); 4431 else 4432 rte_eth_allmulticast_disable(res->port_num); 4433 } 4434 } 4435 4436 cmdline_parse_token_string_t cmd_setallmulti_set = 4437 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 4438 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 4439 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 4440 "allmulti"); 4441 cmdline_parse_token_string_t cmd_setallmulti_portall = 4442 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 4443 "all"); 4444 cmdline_parse_token_num_t cmd_setallmulti_portnum = 4445 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 4446 UINT8); 4447 cmdline_parse_token_string_t cmd_setallmulti_mode = 4448 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 4449 "on#off"); 4450 4451 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 4452 .f = cmd_set_allmulti_mode_parsed, 4453 .data = (void *)1, 4454 .help_str = "set allmulti all on|off: set allmulti mode for all ports", 4455 .tokens = { 4456 (void *)&cmd_setallmulti_set, 4457 (void *)&cmd_setallmulti_allmulti, 4458 (void *)&cmd_setallmulti_portall, 4459 (void *)&cmd_setallmulti_mode, 4460 NULL, 4461 }, 4462 }; 4463 4464 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 4465 .f = cmd_set_allmulti_mode_parsed, 4466 .data = (void *)0, 4467 .help_str = "set allmulti X on|off: set allmulti mode on port X", 4468 .tokens = { 4469 (void *)&cmd_setallmulti_set, 4470 (void *)&cmd_setallmulti_allmulti, 4471 (void *)&cmd_setallmulti_portnum, 4472 (void *)&cmd_setallmulti_mode, 4473 NULL, 4474 }, 4475 }; 4476 4477 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 4478 struct cmd_link_flow_ctrl_set_result { 4479 cmdline_fixed_string_t set; 4480 cmdline_fixed_string_t flow_ctrl; 4481 cmdline_fixed_string_t rx; 4482 cmdline_fixed_string_t rx_lfc_mode; 4483 cmdline_fixed_string_t tx; 4484 cmdline_fixed_string_t tx_lfc_mode; 4485 cmdline_fixed_string_t mac_ctrl_frame_fwd; 4486 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 4487 cmdline_fixed_string_t autoneg_str; 4488 cmdline_fixed_string_t autoneg; 4489 cmdline_fixed_string_t hw_str; 4490 uint32_t high_water; 4491 cmdline_fixed_string_t lw_str; 4492 uint32_t low_water; 4493 cmdline_fixed_string_t pt_str; 4494 uint16_t pause_time; 4495 cmdline_fixed_string_t xon_str; 4496 uint16_t send_xon; 4497 uint8_t port_id; 4498 }; 4499 4500 cmdline_parse_token_string_t cmd_lfc_set_set = 4501 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4502 set, "set"); 4503 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 4504 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4505 flow_ctrl, "flow_ctrl"); 4506 cmdline_parse_token_string_t cmd_lfc_set_rx = 4507 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4508 rx, "rx"); 4509 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 4510 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4511 rx_lfc_mode, "on#off"); 4512 cmdline_parse_token_string_t cmd_lfc_set_tx = 4513 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4514 tx, "tx"); 4515 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 4516 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4517 tx_lfc_mode, "on#off"); 4518 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 4519 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4520 hw_str, "high_water"); 4521 cmdline_parse_token_num_t cmd_lfc_set_high_water = 4522 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4523 high_water, UINT32); 4524 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 4525 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4526 lw_str, "low_water"); 4527 cmdline_parse_token_num_t cmd_lfc_set_low_water = 4528 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4529 low_water, UINT32); 4530 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 4531 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4532 pt_str, "pause_time"); 4533 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 4534 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4535 pause_time, UINT16); 4536 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 4537 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4538 xon_str, "send_xon"); 4539 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 4540 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4541 send_xon, UINT16); 4542 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 4543 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4544 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 4545 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 4546 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4547 mac_ctrl_frame_fwd_mode, "on#off"); 4548 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 4549 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4550 autoneg_str, "autoneg"); 4551 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 4552 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4553 autoneg, "on#off"); 4554 cmdline_parse_token_num_t cmd_lfc_set_portid = 4555 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 4556 port_id, UINT8); 4557 4558 /* forward declaration */ 4559 static void 4560 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 4561 void *data); 4562 4563 cmdline_parse_inst_t cmd_link_flow_control_set = { 4564 .f = cmd_link_flow_ctrl_set_parsed, 4565 .data = NULL, 4566 .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \ 4567 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \ 4568 autoneg on|off port_id", 4569 .tokens = { 4570 (void *)&cmd_lfc_set_set, 4571 (void *)&cmd_lfc_set_flow_ctrl, 4572 (void *)&cmd_lfc_set_rx, 4573 (void *)&cmd_lfc_set_rx_mode, 4574 (void *)&cmd_lfc_set_tx, 4575 (void *)&cmd_lfc_set_tx_mode, 4576 (void *)&cmd_lfc_set_high_water, 4577 (void *)&cmd_lfc_set_low_water, 4578 (void *)&cmd_lfc_set_pause_time, 4579 (void *)&cmd_lfc_set_send_xon, 4580 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 4581 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 4582 (void *)&cmd_lfc_set_autoneg_str, 4583 (void *)&cmd_lfc_set_autoneg, 4584 (void *)&cmd_lfc_set_portid, 4585 NULL, 4586 }, 4587 }; 4588 4589 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 4590 .f = cmd_link_flow_ctrl_set_parsed, 4591 .data = (void *)&cmd_link_flow_control_set_rx, 4592 .help_str = "Change rx flow control parameter: set flow_ctrl " 4593 "rx on|off port_id", 4594 .tokens = { 4595 (void *)&cmd_lfc_set_set, 4596 (void *)&cmd_lfc_set_flow_ctrl, 4597 (void *)&cmd_lfc_set_rx, 4598 (void *)&cmd_lfc_set_rx_mode, 4599 (void *)&cmd_lfc_set_portid, 4600 NULL, 4601 }, 4602 }; 4603 4604 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 4605 .f = cmd_link_flow_ctrl_set_parsed, 4606 .data = (void *)&cmd_link_flow_control_set_tx, 4607 .help_str = "Change tx flow control parameter: set flow_ctrl " 4608 "tx on|off port_id", 4609 .tokens = { 4610 (void *)&cmd_lfc_set_set, 4611 (void *)&cmd_lfc_set_flow_ctrl, 4612 (void *)&cmd_lfc_set_tx, 4613 (void *)&cmd_lfc_set_tx_mode, 4614 (void *)&cmd_lfc_set_portid, 4615 NULL, 4616 }, 4617 }; 4618 4619 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 4620 .f = cmd_link_flow_ctrl_set_parsed, 4621 .data = (void *)&cmd_link_flow_control_set_hw, 4622 .help_str = "Change high water flow control parameter: set flow_ctrl " 4623 "high_water value port_id", 4624 .tokens = { 4625 (void *)&cmd_lfc_set_set, 4626 (void *)&cmd_lfc_set_flow_ctrl, 4627 (void *)&cmd_lfc_set_high_water_str, 4628 (void *)&cmd_lfc_set_high_water, 4629 (void *)&cmd_lfc_set_portid, 4630 NULL, 4631 }, 4632 }; 4633 4634 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 4635 .f = cmd_link_flow_ctrl_set_parsed, 4636 .data = (void *)&cmd_link_flow_control_set_lw, 4637 .help_str = "Change low water flow control parameter: set flow_ctrl " 4638 "low_water value port_id", 4639 .tokens = { 4640 (void *)&cmd_lfc_set_set, 4641 (void *)&cmd_lfc_set_flow_ctrl, 4642 (void *)&cmd_lfc_set_low_water_str, 4643 (void *)&cmd_lfc_set_low_water, 4644 (void *)&cmd_lfc_set_portid, 4645 NULL, 4646 }, 4647 }; 4648 4649 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 4650 .f = cmd_link_flow_ctrl_set_parsed, 4651 .data = (void *)&cmd_link_flow_control_set_pt, 4652 .help_str = "Change pause time flow control parameter: set flow_ctrl " 4653 "pause_time value port_id", 4654 .tokens = { 4655 (void *)&cmd_lfc_set_set, 4656 (void *)&cmd_lfc_set_flow_ctrl, 4657 (void *)&cmd_lfc_set_pause_time_str, 4658 (void *)&cmd_lfc_set_pause_time, 4659 (void *)&cmd_lfc_set_portid, 4660 NULL, 4661 }, 4662 }; 4663 4664 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 4665 .f = cmd_link_flow_ctrl_set_parsed, 4666 .data = (void *)&cmd_link_flow_control_set_xon, 4667 .help_str = "Change send_xon flow control parameter: set flow_ctrl " 4668 "send_xon value port_id", 4669 .tokens = { 4670 (void *)&cmd_lfc_set_set, 4671 (void *)&cmd_lfc_set_flow_ctrl, 4672 (void *)&cmd_lfc_set_send_xon_str, 4673 (void *)&cmd_lfc_set_send_xon, 4674 (void *)&cmd_lfc_set_portid, 4675 NULL, 4676 }, 4677 }; 4678 4679 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 4680 .f = cmd_link_flow_ctrl_set_parsed, 4681 .data = (void *)&cmd_link_flow_control_set_macfwd, 4682 .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl " 4683 "mac_ctrl_frame_fwd on|off port_id", 4684 .tokens = { 4685 (void *)&cmd_lfc_set_set, 4686 (void *)&cmd_lfc_set_flow_ctrl, 4687 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 4688 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 4689 (void *)&cmd_lfc_set_portid, 4690 NULL, 4691 }, 4692 }; 4693 4694 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 4695 .f = cmd_link_flow_ctrl_set_parsed, 4696 .data = (void *)&cmd_link_flow_control_set_autoneg, 4697 .help_str = "Change autoneg flow control parameter: set flow_ctrl " 4698 "autoneg on|off port_id", 4699 .tokens = { 4700 (void *)&cmd_lfc_set_set, 4701 (void *)&cmd_lfc_set_flow_ctrl, 4702 (void *)&cmd_lfc_set_autoneg_str, 4703 (void *)&cmd_lfc_set_autoneg, 4704 (void *)&cmd_lfc_set_portid, 4705 NULL, 4706 }, 4707 }; 4708 4709 static void 4710 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 4711 __attribute__((unused)) struct cmdline *cl, 4712 void *data) 4713 { 4714 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 4715 cmdline_parse_inst_t *cmd = data; 4716 struct rte_eth_fc_conf fc_conf; 4717 int rx_fc_en, tx_fc_en = 0; 4718 int ret; 4719 4720 /* 4721 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 4722 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 4723 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 4724 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 4725 */ 4726 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 4727 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 4728 }; 4729 4730 /* Partial command line, retrieve current configuration */ 4731 if (cmd) { 4732 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 4733 if (ret != 0) { 4734 printf("cannot get current flow ctrl parameters, return" 4735 "code = %d\n", ret); 4736 return; 4737 } 4738 4739 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 4740 (fc_conf.mode == RTE_FC_FULL)) 4741 rx_fc_en = 1; 4742 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 4743 (fc_conf.mode == RTE_FC_FULL)) 4744 tx_fc_en = 1; 4745 } 4746 4747 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 4748 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 4749 4750 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 4751 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 4752 4753 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 4754 4755 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 4756 fc_conf.high_water = res->high_water; 4757 4758 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 4759 fc_conf.low_water = res->low_water; 4760 4761 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 4762 fc_conf.pause_time = res->pause_time; 4763 4764 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 4765 fc_conf.send_xon = res->send_xon; 4766 4767 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 4768 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 4769 fc_conf.mac_ctrl_frame_fwd = 1; 4770 else 4771 fc_conf.mac_ctrl_frame_fwd = 0; 4772 } 4773 4774 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 4775 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 4776 4777 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 4778 if (ret != 0) 4779 printf("bad flow contrl parameter, return code = %d \n", ret); 4780 } 4781 4782 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */ 4783 struct cmd_priority_flow_ctrl_set_result { 4784 cmdline_fixed_string_t set; 4785 cmdline_fixed_string_t pfc_ctrl; 4786 cmdline_fixed_string_t rx; 4787 cmdline_fixed_string_t rx_pfc_mode; 4788 cmdline_fixed_string_t tx; 4789 cmdline_fixed_string_t tx_pfc_mode; 4790 uint32_t high_water; 4791 uint32_t low_water; 4792 uint16_t pause_time; 4793 uint8_t priority; 4794 uint8_t port_id; 4795 }; 4796 4797 static void 4798 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 4799 __attribute__((unused)) struct cmdline *cl, 4800 __attribute__((unused)) void *data) 4801 { 4802 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 4803 struct rte_eth_pfc_conf pfc_conf; 4804 int rx_fc_enable, tx_fc_enable; 4805 int ret; 4806 4807 /* 4808 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 4809 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 4810 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 4811 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 4812 */ 4813 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 4814 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 4815 }; 4816 4817 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 4818 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 4819 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 4820 pfc_conf.fc.high_water = res->high_water; 4821 pfc_conf.fc.low_water = res->low_water; 4822 pfc_conf.fc.pause_time = res->pause_time; 4823 pfc_conf.priority = res->priority; 4824 4825 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 4826 if (ret != 0) 4827 printf("bad priority flow contrl parameter, return code = %d \n", ret); 4828 } 4829 4830 cmdline_parse_token_string_t cmd_pfc_set_set = 4831 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4832 set, "set"); 4833 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 4834 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4835 pfc_ctrl, "pfc_ctrl"); 4836 cmdline_parse_token_string_t cmd_pfc_set_rx = 4837 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4838 rx, "rx"); 4839 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 4840 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4841 rx_pfc_mode, "on#off"); 4842 cmdline_parse_token_string_t cmd_pfc_set_tx = 4843 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4844 tx, "tx"); 4845 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 4846 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4847 tx_pfc_mode, "on#off"); 4848 cmdline_parse_token_num_t cmd_pfc_set_high_water = 4849 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4850 high_water, UINT32); 4851 cmdline_parse_token_num_t cmd_pfc_set_low_water = 4852 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4853 low_water, UINT32); 4854 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 4855 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4856 pause_time, UINT16); 4857 cmdline_parse_token_num_t cmd_pfc_set_priority = 4858 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4859 priority, UINT8); 4860 cmdline_parse_token_num_t cmd_pfc_set_portid = 4861 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 4862 port_id, UINT8); 4863 4864 cmdline_parse_inst_t cmd_priority_flow_control_set = { 4865 .f = cmd_priority_flow_ctrl_set_parsed, 4866 .data = NULL, 4867 .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\ 4868 tx on|off high_water low_water pause_time priority port_id", 4869 .tokens = { 4870 (void *)&cmd_pfc_set_set, 4871 (void *)&cmd_pfc_set_flow_ctrl, 4872 (void *)&cmd_pfc_set_rx, 4873 (void *)&cmd_pfc_set_rx_mode, 4874 (void *)&cmd_pfc_set_tx, 4875 (void *)&cmd_pfc_set_tx_mode, 4876 (void *)&cmd_pfc_set_high_water, 4877 (void *)&cmd_pfc_set_low_water, 4878 (void *)&cmd_pfc_set_pause_time, 4879 (void *)&cmd_pfc_set_priority, 4880 (void *)&cmd_pfc_set_portid, 4881 NULL, 4882 }, 4883 }; 4884 4885 /* *** RESET CONFIGURATION *** */ 4886 struct cmd_reset_result { 4887 cmdline_fixed_string_t reset; 4888 cmdline_fixed_string_t def; 4889 }; 4890 4891 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 4892 struct cmdline *cl, 4893 __attribute__((unused)) void *data) 4894 { 4895 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 4896 set_def_fwd_config(); 4897 } 4898 4899 cmdline_parse_token_string_t cmd_reset_set = 4900 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 4901 cmdline_parse_token_string_t cmd_reset_def = 4902 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 4903 "default"); 4904 4905 cmdline_parse_inst_t cmd_reset = { 4906 .f = cmd_reset_parsed, 4907 .data = NULL, 4908 .help_str = "set default: reset default forwarding configuration", 4909 .tokens = { 4910 (void *)&cmd_reset_set, 4911 (void *)&cmd_reset_def, 4912 NULL, 4913 }, 4914 }; 4915 4916 /* *** START FORWARDING *** */ 4917 struct cmd_start_result { 4918 cmdline_fixed_string_t start; 4919 }; 4920 4921 cmdline_parse_token_string_t cmd_start_start = 4922 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 4923 4924 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 4925 __attribute__((unused)) struct cmdline *cl, 4926 __attribute__((unused)) void *data) 4927 { 4928 start_packet_forwarding(0); 4929 } 4930 4931 cmdline_parse_inst_t cmd_start = { 4932 .f = cmd_start_parsed, 4933 .data = NULL, 4934 .help_str = "start packet forwarding", 4935 .tokens = { 4936 (void *)&cmd_start_start, 4937 NULL, 4938 }, 4939 }; 4940 4941 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 4942 struct cmd_start_tx_first_result { 4943 cmdline_fixed_string_t start; 4944 cmdline_fixed_string_t tx_first; 4945 }; 4946 4947 static void 4948 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 4949 __attribute__((unused)) struct cmdline *cl, 4950 __attribute__((unused)) void *data) 4951 { 4952 start_packet_forwarding(1); 4953 } 4954 4955 cmdline_parse_token_string_t cmd_start_tx_first_start = 4956 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 4957 "start"); 4958 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 4959 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 4960 tx_first, "tx_first"); 4961 4962 cmdline_parse_inst_t cmd_start_tx_first = { 4963 .f = cmd_start_tx_first_parsed, 4964 .data = NULL, 4965 .help_str = "start packet forwarding, after sending 1 burst of packets", 4966 .tokens = { 4967 (void *)&cmd_start_tx_first_start, 4968 (void *)&cmd_start_tx_first_tx_first, 4969 NULL, 4970 }, 4971 }; 4972 4973 /* *** SET LINK UP *** */ 4974 struct cmd_set_link_up_result { 4975 cmdline_fixed_string_t set; 4976 cmdline_fixed_string_t link_up; 4977 cmdline_fixed_string_t port; 4978 uint8_t port_id; 4979 }; 4980 4981 cmdline_parse_token_string_t cmd_set_link_up_set = 4982 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 4983 cmdline_parse_token_string_t cmd_set_link_up_link_up = 4984 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 4985 "link-up"); 4986 cmdline_parse_token_string_t cmd_set_link_up_port = 4987 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 4988 cmdline_parse_token_num_t cmd_set_link_up_port_id = 4989 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); 4990 4991 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 4992 __attribute__((unused)) struct cmdline *cl, 4993 __attribute__((unused)) void *data) 4994 { 4995 struct cmd_set_link_up_result *res = parsed_result; 4996 dev_set_link_up(res->port_id); 4997 } 4998 4999 cmdline_parse_inst_t cmd_set_link_up = { 5000 .f = cmd_set_link_up_parsed, 5001 .data = NULL, 5002 .help_str = "set link-up port (port id)", 5003 .tokens = { 5004 (void *)&cmd_set_link_up_set, 5005 (void *)&cmd_set_link_up_link_up, 5006 (void *)&cmd_set_link_up_port, 5007 (void *)&cmd_set_link_up_port_id, 5008 NULL, 5009 }, 5010 }; 5011 5012 /* *** SET LINK DOWN *** */ 5013 struct cmd_set_link_down_result { 5014 cmdline_fixed_string_t set; 5015 cmdline_fixed_string_t link_down; 5016 cmdline_fixed_string_t port; 5017 uint8_t port_id; 5018 }; 5019 5020 cmdline_parse_token_string_t cmd_set_link_down_set = 5021 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 5022 cmdline_parse_token_string_t cmd_set_link_down_link_down = 5023 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 5024 "link-down"); 5025 cmdline_parse_token_string_t cmd_set_link_down_port = 5026 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 5027 cmdline_parse_token_num_t cmd_set_link_down_port_id = 5028 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); 5029 5030 static void cmd_set_link_down_parsed( 5031 __attribute__((unused)) void *parsed_result, 5032 __attribute__((unused)) struct cmdline *cl, 5033 __attribute__((unused)) void *data) 5034 { 5035 struct cmd_set_link_down_result *res = parsed_result; 5036 dev_set_link_down(res->port_id); 5037 } 5038 5039 cmdline_parse_inst_t cmd_set_link_down = { 5040 .f = cmd_set_link_down_parsed, 5041 .data = NULL, 5042 .help_str = "set link-down port (port id)", 5043 .tokens = { 5044 (void *)&cmd_set_link_down_set, 5045 (void *)&cmd_set_link_down_link_down, 5046 (void *)&cmd_set_link_down_port, 5047 (void *)&cmd_set_link_down_port_id, 5048 NULL, 5049 }, 5050 }; 5051 5052 /* *** SHOW CFG *** */ 5053 struct cmd_showcfg_result { 5054 cmdline_fixed_string_t show; 5055 cmdline_fixed_string_t cfg; 5056 cmdline_fixed_string_t what; 5057 }; 5058 5059 static void cmd_showcfg_parsed(void *parsed_result, 5060 __attribute__((unused)) struct cmdline *cl, 5061 __attribute__((unused)) void *data) 5062 { 5063 struct cmd_showcfg_result *res = parsed_result; 5064 if (!strcmp(res->what, "rxtx")) 5065 rxtx_config_display(); 5066 else if (!strcmp(res->what, "cores")) 5067 fwd_lcores_config_display(); 5068 else if (!strcmp(res->what, "fwd")) 5069 fwd_config_display(); 5070 } 5071 5072 cmdline_parse_token_string_t cmd_showcfg_show = 5073 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 5074 cmdline_parse_token_string_t cmd_showcfg_port = 5075 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 5076 cmdline_parse_token_string_t cmd_showcfg_what = 5077 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 5078 "rxtx#cores#fwd"); 5079 5080 cmdline_parse_inst_t cmd_showcfg = { 5081 .f = cmd_showcfg_parsed, 5082 .data = NULL, 5083 .help_str = "show config rxtx|cores|fwd", 5084 .tokens = { 5085 (void *)&cmd_showcfg_show, 5086 (void *)&cmd_showcfg_port, 5087 (void *)&cmd_showcfg_what, 5088 NULL, 5089 }, 5090 }; 5091 5092 /* *** SHOW ALL PORT INFO *** */ 5093 struct cmd_showportall_result { 5094 cmdline_fixed_string_t show; 5095 cmdline_fixed_string_t port; 5096 cmdline_fixed_string_t what; 5097 cmdline_fixed_string_t all; 5098 }; 5099 5100 static void cmd_showportall_parsed(void *parsed_result, 5101 __attribute__((unused)) struct cmdline *cl, 5102 __attribute__((unused)) void *data) 5103 { 5104 portid_t i; 5105 5106 struct cmd_showportall_result *res = parsed_result; 5107 if (!strcmp(res->show, "clear")) { 5108 if (!strcmp(res->what, "stats")) 5109 FOREACH_PORT(i, ports) 5110 nic_stats_clear(i); 5111 else if (!strcmp(res->what, "xstats")) 5112 FOREACH_PORT(i, ports) 5113 nic_xstats_clear(i); 5114 } else if (!strcmp(res->what, "info")) 5115 FOREACH_PORT(i, ports) 5116 port_infos_display(i); 5117 else if (!strcmp(res->what, "stats")) 5118 FOREACH_PORT(i, ports) 5119 nic_stats_display(i); 5120 else if (!strcmp(res->what, "xstats")) 5121 FOREACH_PORT(i, ports) 5122 nic_xstats_display(i); 5123 else if (!strcmp(res->what, "fdir")) 5124 FOREACH_PORT(i, ports) 5125 fdir_get_infos(i); 5126 else if (!strcmp(res->what, "stat_qmap")) 5127 FOREACH_PORT(i, ports) 5128 nic_stats_mapping_display(i); 5129 } 5130 5131 cmdline_parse_token_string_t cmd_showportall_show = 5132 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 5133 "show#clear"); 5134 cmdline_parse_token_string_t cmd_showportall_port = 5135 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 5136 cmdline_parse_token_string_t cmd_showportall_what = 5137 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 5138 "info#stats#xstats#fdir#stat_qmap"); 5139 cmdline_parse_token_string_t cmd_showportall_all = 5140 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 5141 cmdline_parse_inst_t cmd_showportall = { 5142 .f = cmd_showportall_parsed, 5143 .data = NULL, 5144 .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap all", 5145 .tokens = { 5146 (void *)&cmd_showportall_show, 5147 (void *)&cmd_showportall_port, 5148 (void *)&cmd_showportall_what, 5149 (void *)&cmd_showportall_all, 5150 NULL, 5151 }, 5152 }; 5153 5154 /* *** SHOW PORT INFO *** */ 5155 struct cmd_showport_result { 5156 cmdline_fixed_string_t show; 5157 cmdline_fixed_string_t port; 5158 cmdline_fixed_string_t what; 5159 uint8_t portnum; 5160 }; 5161 5162 static void cmd_showport_parsed(void *parsed_result, 5163 __attribute__((unused)) struct cmdline *cl, 5164 __attribute__((unused)) void *data) 5165 { 5166 struct cmd_showport_result *res = parsed_result; 5167 if (!strcmp(res->show, "clear")) { 5168 if (!strcmp(res->what, "stats")) 5169 nic_stats_clear(res->portnum); 5170 else if (!strcmp(res->what, "xstats")) 5171 nic_xstats_clear(res->portnum); 5172 } else if (!strcmp(res->what, "info")) 5173 port_infos_display(res->portnum); 5174 else if (!strcmp(res->what, "stats")) 5175 nic_stats_display(res->portnum); 5176 else if (!strcmp(res->what, "xstats")) 5177 nic_xstats_display(res->portnum); 5178 else if (!strcmp(res->what, "fdir")) 5179 fdir_get_infos(res->portnum); 5180 else if (!strcmp(res->what, "stat_qmap")) 5181 nic_stats_mapping_display(res->portnum); 5182 } 5183 5184 cmdline_parse_token_string_t cmd_showport_show = 5185 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 5186 "show#clear"); 5187 cmdline_parse_token_string_t cmd_showport_port = 5188 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 5189 cmdline_parse_token_string_t cmd_showport_what = 5190 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 5191 "info#stats#xstats#fdir#stat_qmap"); 5192 cmdline_parse_token_num_t cmd_showport_portnum = 5193 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); 5194 5195 cmdline_parse_inst_t cmd_showport = { 5196 .f = cmd_showport_parsed, 5197 .data = NULL, 5198 .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap X (X = port number)", 5199 .tokens = { 5200 (void *)&cmd_showport_show, 5201 (void *)&cmd_showport_port, 5202 (void *)&cmd_showport_what, 5203 (void *)&cmd_showport_portnum, 5204 NULL, 5205 }, 5206 }; 5207 5208 /* *** READ PORT REGISTER *** */ 5209 struct cmd_read_reg_result { 5210 cmdline_fixed_string_t read; 5211 cmdline_fixed_string_t reg; 5212 uint8_t port_id; 5213 uint32_t reg_off; 5214 }; 5215 5216 static void 5217 cmd_read_reg_parsed(void *parsed_result, 5218 __attribute__((unused)) struct cmdline *cl, 5219 __attribute__((unused)) void *data) 5220 { 5221 struct cmd_read_reg_result *res = parsed_result; 5222 port_reg_display(res->port_id, res->reg_off); 5223 } 5224 5225 cmdline_parse_token_string_t cmd_read_reg_read = 5226 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 5227 cmdline_parse_token_string_t cmd_read_reg_reg = 5228 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 5229 cmdline_parse_token_num_t cmd_read_reg_port_id = 5230 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 5231 cmdline_parse_token_num_t cmd_read_reg_reg_off = 5232 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 5233 5234 cmdline_parse_inst_t cmd_read_reg = { 5235 .f = cmd_read_reg_parsed, 5236 .data = NULL, 5237 .help_str = "read reg port_id reg_off", 5238 .tokens = { 5239 (void *)&cmd_read_reg_read, 5240 (void *)&cmd_read_reg_reg, 5241 (void *)&cmd_read_reg_port_id, 5242 (void *)&cmd_read_reg_reg_off, 5243 NULL, 5244 }, 5245 }; 5246 5247 /* *** READ PORT REGISTER BIT FIELD *** */ 5248 struct cmd_read_reg_bit_field_result { 5249 cmdline_fixed_string_t read; 5250 cmdline_fixed_string_t regfield; 5251 uint8_t port_id; 5252 uint32_t reg_off; 5253 uint8_t bit1_pos; 5254 uint8_t bit2_pos; 5255 }; 5256 5257 static void 5258 cmd_read_reg_bit_field_parsed(void *parsed_result, 5259 __attribute__((unused)) struct cmdline *cl, 5260 __attribute__((unused)) void *data) 5261 { 5262 struct cmd_read_reg_bit_field_result *res = parsed_result; 5263 port_reg_bit_field_display(res->port_id, res->reg_off, 5264 res->bit1_pos, res->bit2_pos); 5265 } 5266 5267 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 5268 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 5269 "read"); 5270 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 5271 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 5272 regfield, "regfield"); 5273 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 5274 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 5275 UINT8); 5276 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 5277 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 5278 UINT32); 5279 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 5280 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 5281 UINT8); 5282 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 5283 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 5284 UINT8); 5285 5286 cmdline_parse_inst_t cmd_read_reg_bit_field = { 5287 .f = cmd_read_reg_bit_field_parsed, 5288 .data = NULL, 5289 .help_str = "read regfield port_id reg_off bit_x bit_y " 5290 "(read register bit field between bit_x and bit_y included)", 5291 .tokens = { 5292 (void *)&cmd_read_reg_bit_field_read, 5293 (void *)&cmd_read_reg_bit_field_regfield, 5294 (void *)&cmd_read_reg_bit_field_port_id, 5295 (void *)&cmd_read_reg_bit_field_reg_off, 5296 (void *)&cmd_read_reg_bit_field_bit1_pos, 5297 (void *)&cmd_read_reg_bit_field_bit2_pos, 5298 NULL, 5299 }, 5300 }; 5301 5302 /* *** READ PORT REGISTER BIT *** */ 5303 struct cmd_read_reg_bit_result { 5304 cmdline_fixed_string_t read; 5305 cmdline_fixed_string_t regbit; 5306 uint8_t port_id; 5307 uint32_t reg_off; 5308 uint8_t bit_pos; 5309 }; 5310 5311 static void 5312 cmd_read_reg_bit_parsed(void *parsed_result, 5313 __attribute__((unused)) struct cmdline *cl, 5314 __attribute__((unused)) void *data) 5315 { 5316 struct cmd_read_reg_bit_result *res = parsed_result; 5317 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 5318 } 5319 5320 cmdline_parse_token_string_t cmd_read_reg_bit_read = 5321 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 5322 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 5323 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 5324 regbit, "regbit"); 5325 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 5326 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 5327 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 5328 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 5329 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 5330 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 5331 5332 cmdline_parse_inst_t cmd_read_reg_bit = { 5333 .f = cmd_read_reg_bit_parsed, 5334 .data = NULL, 5335 .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)", 5336 .tokens = { 5337 (void *)&cmd_read_reg_bit_read, 5338 (void *)&cmd_read_reg_bit_regbit, 5339 (void *)&cmd_read_reg_bit_port_id, 5340 (void *)&cmd_read_reg_bit_reg_off, 5341 (void *)&cmd_read_reg_bit_bit_pos, 5342 NULL, 5343 }, 5344 }; 5345 5346 /* *** WRITE PORT REGISTER *** */ 5347 struct cmd_write_reg_result { 5348 cmdline_fixed_string_t write; 5349 cmdline_fixed_string_t reg; 5350 uint8_t port_id; 5351 uint32_t reg_off; 5352 uint32_t value; 5353 }; 5354 5355 static void 5356 cmd_write_reg_parsed(void *parsed_result, 5357 __attribute__((unused)) struct cmdline *cl, 5358 __attribute__((unused)) void *data) 5359 { 5360 struct cmd_write_reg_result *res = parsed_result; 5361 port_reg_set(res->port_id, res->reg_off, res->value); 5362 } 5363 5364 cmdline_parse_token_string_t cmd_write_reg_write = 5365 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 5366 cmdline_parse_token_string_t cmd_write_reg_reg = 5367 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 5368 cmdline_parse_token_num_t cmd_write_reg_port_id = 5369 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 5370 cmdline_parse_token_num_t cmd_write_reg_reg_off = 5371 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 5372 cmdline_parse_token_num_t cmd_write_reg_value = 5373 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 5374 5375 cmdline_parse_inst_t cmd_write_reg = { 5376 .f = cmd_write_reg_parsed, 5377 .data = NULL, 5378 .help_str = "write reg port_id reg_off reg_value", 5379 .tokens = { 5380 (void *)&cmd_write_reg_write, 5381 (void *)&cmd_write_reg_reg, 5382 (void *)&cmd_write_reg_port_id, 5383 (void *)&cmd_write_reg_reg_off, 5384 (void *)&cmd_write_reg_value, 5385 NULL, 5386 }, 5387 }; 5388 5389 /* *** WRITE PORT REGISTER BIT FIELD *** */ 5390 struct cmd_write_reg_bit_field_result { 5391 cmdline_fixed_string_t write; 5392 cmdline_fixed_string_t regfield; 5393 uint8_t port_id; 5394 uint32_t reg_off; 5395 uint8_t bit1_pos; 5396 uint8_t bit2_pos; 5397 uint32_t value; 5398 }; 5399 5400 static void 5401 cmd_write_reg_bit_field_parsed(void *parsed_result, 5402 __attribute__((unused)) struct cmdline *cl, 5403 __attribute__((unused)) void *data) 5404 { 5405 struct cmd_write_reg_bit_field_result *res = parsed_result; 5406 port_reg_bit_field_set(res->port_id, res->reg_off, 5407 res->bit1_pos, res->bit2_pos, res->value); 5408 } 5409 5410 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 5411 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 5412 "write"); 5413 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 5414 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 5415 regfield, "regfield"); 5416 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 5417 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 5418 UINT8); 5419 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 5420 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 5421 UINT32); 5422 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 5423 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 5424 UINT8); 5425 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 5426 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 5427 UINT8); 5428 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 5429 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 5430 UINT32); 5431 5432 cmdline_parse_inst_t cmd_write_reg_bit_field = { 5433 .f = cmd_write_reg_bit_field_parsed, 5434 .data = NULL, 5435 .help_str = "write regfield port_id reg_off bit_x bit_y reg_value" 5436 "(set register bit field between bit_x and bit_y included)", 5437 .tokens = { 5438 (void *)&cmd_write_reg_bit_field_write, 5439 (void *)&cmd_write_reg_bit_field_regfield, 5440 (void *)&cmd_write_reg_bit_field_port_id, 5441 (void *)&cmd_write_reg_bit_field_reg_off, 5442 (void *)&cmd_write_reg_bit_field_bit1_pos, 5443 (void *)&cmd_write_reg_bit_field_bit2_pos, 5444 (void *)&cmd_write_reg_bit_field_value, 5445 NULL, 5446 }, 5447 }; 5448 5449 /* *** WRITE PORT REGISTER BIT *** */ 5450 struct cmd_write_reg_bit_result { 5451 cmdline_fixed_string_t write; 5452 cmdline_fixed_string_t regbit; 5453 uint8_t port_id; 5454 uint32_t reg_off; 5455 uint8_t bit_pos; 5456 uint8_t value; 5457 }; 5458 5459 static void 5460 cmd_write_reg_bit_parsed(void *parsed_result, 5461 __attribute__((unused)) struct cmdline *cl, 5462 __attribute__((unused)) void *data) 5463 { 5464 struct cmd_write_reg_bit_result *res = parsed_result; 5465 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 5466 } 5467 5468 cmdline_parse_token_string_t cmd_write_reg_bit_write = 5469 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 5470 "write"); 5471 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 5472 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 5473 regbit, "regbit"); 5474 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 5475 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 5476 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 5477 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 5478 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 5479 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 5480 cmdline_parse_token_num_t cmd_write_reg_bit_value = 5481 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 5482 5483 cmdline_parse_inst_t cmd_write_reg_bit = { 5484 .f = cmd_write_reg_bit_parsed, 5485 .data = NULL, 5486 .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)", 5487 .tokens = { 5488 (void *)&cmd_write_reg_bit_write, 5489 (void *)&cmd_write_reg_bit_regbit, 5490 (void *)&cmd_write_reg_bit_port_id, 5491 (void *)&cmd_write_reg_bit_reg_off, 5492 (void *)&cmd_write_reg_bit_bit_pos, 5493 (void *)&cmd_write_reg_bit_value, 5494 NULL, 5495 }, 5496 }; 5497 5498 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 5499 struct cmd_read_rxd_txd_result { 5500 cmdline_fixed_string_t read; 5501 cmdline_fixed_string_t rxd_txd; 5502 uint8_t port_id; 5503 uint16_t queue_id; 5504 uint16_t desc_id; 5505 }; 5506 5507 static void 5508 cmd_read_rxd_txd_parsed(void *parsed_result, 5509 __attribute__((unused)) struct cmdline *cl, 5510 __attribute__((unused)) void *data) 5511 { 5512 struct cmd_read_rxd_txd_result *res = parsed_result; 5513 5514 if (!strcmp(res->rxd_txd, "rxd")) 5515 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 5516 else if (!strcmp(res->rxd_txd, "txd")) 5517 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 5518 } 5519 5520 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 5521 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 5522 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 5523 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 5524 "rxd#txd"); 5525 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 5526 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 5527 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 5528 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 5529 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 5530 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 5531 5532 cmdline_parse_inst_t cmd_read_rxd_txd = { 5533 .f = cmd_read_rxd_txd_parsed, 5534 .data = NULL, 5535 .help_str = "read rxd|txd port_id queue_id rxd_id", 5536 .tokens = { 5537 (void *)&cmd_read_rxd_txd_read, 5538 (void *)&cmd_read_rxd_txd_rxd_txd, 5539 (void *)&cmd_read_rxd_txd_port_id, 5540 (void *)&cmd_read_rxd_txd_queue_id, 5541 (void *)&cmd_read_rxd_txd_desc_id, 5542 NULL, 5543 }, 5544 }; 5545 5546 /* *** QUIT *** */ 5547 struct cmd_quit_result { 5548 cmdline_fixed_string_t quit; 5549 }; 5550 5551 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 5552 struct cmdline *cl, 5553 __attribute__((unused)) void *data) 5554 { 5555 pmd_test_exit(); 5556 cmdline_quit(cl); 5557 } 5558 5559 cmdline_parse_token_string_t cmd_quit_quit = 5560 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 5561 5562 cmdline_parse_inst_t cmd_quit = { 5563 .f = cmd_quit_parsed, 5564 .data = NULL, 5565 .help_str = "exit application", 5566 .tokens = { 5567 (void *)&cmd_quit_quit, 5568 NULL, 5569 }, 5570 }; 5571 5572 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 5573 struct cmd_mac_addr_result { 5574 cmdline_fixed_string_t mac_addr_cmd; 5575 cmdline_fixed_string_t what; 5576 uint8_t port_num; 5577 struct ether_addr address; 5578 }; 5579 5580 static void cmd_mac_addr_parsed(void *parsed_result, 5581 __attribute__((unused)) struct cmdline *cl, 5582 __attribute__((unused)) void *data) 5583 { 5584 struct cmd_mac_addr_result *res = parsed_result; 5585 int ret; 5586 5587 if (strcmp(res->what, "add") == 0) 5588 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 5589 else 5590 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 5591 5592 /* check the return value and print it if is < 0 */ 5593 if(ret < 0) 5594 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 5595 5596 } 5597 5598 cmdline_parse_token_string_t cmd_mac_addr_cmd = 5599 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 5600 "mac_addr"); 5601 cmdline_parse_token_string_t cmd_mac_addr_what = 5602 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 5603 "add#remove"); 5604 cmdline_parse_token_num_t cmd_mac_addr_portnum = 5605 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 5606 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 5607 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 5608 5609 cmdline_parse_inst_t cmd_mac_addr = { 5610 .f = cmd_mac_addr_parsed, 5611 .data = (void *)0, 5612 .help_str = "mac_addr add|remove X <address>: " 5613 "add/remove MAC address on port X", 5614 .tokens = { 5615 (void *)&cmd_mac_addr_cmd, 5616 (void *)&cmd_mac_addr_what, 5617 (void *)&cmd_mac_addr_portnum, 5618 (void *)&cmd_mac_addr_addr, 5619 NULL, 5620 }, 5621 }; 5622 5623 5624 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 5625 struct cmd_set_qmap_result { 5626 cmdline_fixed_string_t set; 5627 cmdline_fixed_string_t qmap; 5628 cmdline_fixed_string_t what; 5629 uint8_t port_id; 5630 uint16_t queue_id; 5631 uint8_t map_value; 5632 }; 5633 5634 static void 5635 cmd_set_qmap_parsed(void *parsed_result, 5636 __attribute__((unused)) struct cmdline *cl, 5637 __attribute__((unused)) void *data) 5638 { 5639 struct cmd_set_qmap_result *res = parsed_result; 5640 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 5641 5642 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 5643 } 5644 5645 cmdline_parse_token_string_t cmd_setqmap_set = 5646 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 5647 set, "set"); 5648 cmdline_parse_token_string_t cmd_setqmap_qmap = 5649 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 5650 qmap, "stat_qmap"); 5651 cmdline_parse_token_string_t cmd_setqmap_what = 5652 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 5653 what, "tx#rx"); 5654 cmdline_parse_token_num_t cmd_setqmap_portid = 5655 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 5656 port_id, UINT8); 5657 cmdline_parse_token_num_t cmd_setqmap_queueid = 5658 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 5659 queue_id, UINT16); 5660 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 5661 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 5662 map_value, UINT8); 5663 5664 cmdline_parse_inst_t cmd_set_qmap = { 5665 .f = cmd_set_qmap_parsed, 5666 .data = NULL, 5667 .help_str = "Set statistics mapping value on tx|rx queue_id of port_id", 5668 .tokens = { 5669 (void *)&cmd_setqmap_set, 5670 (void *)&cmd_setqmap_qmap, 5671 (void *)&cmd_setqmap_what, 5672 (void *)&cmd_setqmap_portid, 5673 (void *)&cmd_setqmap_queueid, 5674 (void *)&cmd_setqmap_mapvalue, 5675 NULL, 5676 }, 5677 }; 5678 5679 /* *** CONFIGURE UNICAST HASH TABLE *** */ 5680 struct cmd_set_uc_hash_table { 5681 cmdline_fixed_string_t set; 5682 cmdline_fixed_string_t port; 5683 uint8_t port_id; 5684 cmdline_fixed_string_t what; 5685 struct ether_addr address; 5686 cmdline_fixed_string_t mode; 5687 }; 5688 5689 static void 5690 cmd_set_uc_hash_parsed(void *parsed_result, 5691 __attribute__((unused)) struct cmdline *cl, 5692 __attribute__((unused)) void *data) 5693 { 5694 int ret=0; 5695 struct cmd_set_uc_hash_table *res = parsed_result; 5696 5697 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 5698 5699 if (strcmp(res->what, "uta") == 0) 5700 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 5701 &res->address,(uint8_t)is_on); 5702 if (ret < 0) 5703 printf("bad unicast hash table parameter, return code = %d \n", ret); 5704 5705 } 5706 5707 cmdline_parse_token_string_t cmd_set_uc_hash_set = 5708 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 5709 set, "set"); 5710 cmdline_parse_token_string_t cmd_set_uc_hash_port = 5711 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 5712 port, "port"); 5713 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 5714 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 5715 port_id, UINT8); 5716 cmdline_parse_token_string_t cmd_set_uc_hash_what = 5717 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 5718 what, "uta"); 5719 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 5720 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 5721 address); 5722 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 5723 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 5724 mode, "on#off"); 5725 5726 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 5727 .f = cmd_set_uc_hash_parsed, 5728 .data = NULL, 5729 .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)", 5730 .tokens = { 5731 (void *)&cmd_set_uc_hash_set, 5732 (void *)&cmd_set_uc_hash_port, 5733 (void *)&cmd_set_uc_hash_portid, 5734 (void *)&cmd_set_uc_hash_what, 5735 (void *)&cmd_set_uc_hash_mac, 5736 (void *)&cmd_set_uc_hash_mode, 5737 NULL, 5738 }, 5739 }; 5740 5741 struct cmd_set_uc_all_hash_table { 5742 cmdline_fixed_string_t set; 5743 cmdline_fixed_string_t port; 5744 uint8_t port_id; 5745 cmdline_fixed_string_t what; 5746 cmdline_fixed_string_t value; 5747 cmdline_fixed_string_t mode; 5748 }; 5749 5750 static void 5751 cmd_set_uc_all_hash_parsed(void *parsed_result, 5752 __attribute__((unused)) struct cmdline *cl, 5753 __attribute__((unused)) void *data) 5754 { 5755 int ret=0; 5756 struct cmd_set_uc_all_hash_table *res = parsed_result; 5757 5758 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 5759 5760 if ((strcmp(res->what, "uta") == 0) && 5761 (strcmp(res->value, "all") == 0)) 5762 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 5763 if (ret < 0) 5764 printf("bad unicast hash table parameter," 5765 "return code = %d \n", ret); 5766 } 5767 5768 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 5769 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 5770 set, "set"); 5771 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 5772 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 5773 port, "port"); 5774 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 5775 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 5776 port_id, UINT8); 5777 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 5778 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 5779 what, "uta"); 5780 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 5781 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 5782 value,"all"); 5783 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 5784 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 5785 mode, "on#off"); 5786 5787 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 5788 .f = cmd_set_uc_all_hash_parsed, 5789 .data = NULL, 5790 .help_str = "set port X uta all on|off (X = port number)", 5791 .tokens = { 5792 (void *)&cmd_set_uc_all_hash_set, 5793 (void *)&cmd_set_uc_all_hash_port, 5794 (void *)&cmd_set_uc_all_hash_portid, 5795 (void *)&cmd_set_uc_all_hash_what, 5796 (void *)&cmd_set_uc_all_hash_value, 5797 (void *)&cmd_set_uc_all_hash_mode, 5798 NULL, 5799 }, 5800 }; 5801 5802 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 5803 struct cmd_set_vf_macvlan_filter { 5804 cmdline_fixed_string_t set; 5805 cmdline_fixed_string_t port; 5806 uint8_t port_id; 5807 cmdline_fixed_string_t vf; 5808 uint8_t vf_id; 5809 struct ether_addr address; 5810 cmdline_fixed_string_t filter_type; 5811 cmdline_fixed_string_t mode; 5812 }; 5813 5814 static void 5815 cmd_set_vf_macvlan_parsed(void *parsed_result, 5816 __attribute__((unused)) struct cmdline *cl, 5817 __attribute__((unused)) void *data) 5818 { 5819 int is_on, ret = 0; 5820 struct cmd_set_vf_macvlan_filter *res = parsed_result; 5821 struct rte_eth_mac_filter filter; 5822 5823 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 5824 5825 (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 5826 5827 /* set VF MAC filter */ 5828 filter.is_vf = 1; 5829 5830 /* set VF ID */ 5831 filter.dst_id = res->vf_id; 5832 5833 if (!strcmp(res->filter_type, "exact-mac")) 5834 filter.filter_type = RTE_MAC_PERFECT_MATCH; 5835 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 5836 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 5837 else if (!strcmp(res->filter_type, "hashmac")) 5838 filter.filter_type = RTE_MAC_HASH_MATCH; 5839 else if (!strcmp(res->filter_type, "hashmac-vlan")) 5840 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 5841 5842 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 5843 5844 if (is_on) 5845 ret = rte_eth_dev_filter_ctrl(res->port_id, 5846 RTE_ETH_FILTER_MACVLAN, 5847 RTE_ETH_FILTER_ADD, 5848 &filter); 5849 else 5850 ret = rte_eth_dev_filter_ctrl(res->port_id, 5851 RTE_ETH_FILTER_MACVLAN, 5852 RTE_ETH_FILTER_DELETE, 5853 &filter); 5854 5855 if (ret < 0) 5856 printf("bad set MAC hash parameter, return code = %d\n", ret); 5857 5858 } 5859 5860 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 5861 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5862 set, "set"); 5863 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 5864 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5865 port, "port"); 5866 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 5867 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5868 port_id, UINT8); 5869 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 5870 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5871 vf, "vf"); 5872 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 5873 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5874 vf_id, UINT8); 5875 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 5876 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5877 address); 5878 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 5879 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5880 filter_type, "exact-mac#exact-mac-vlan" 5881 "#hashmac#hashmac-vlan"); 5882 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 5883 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 5884 mode, "on#off"); 5885 5886 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 5887 .f = cmd_set_vf_macvlan_parsed, 5888 .data = NULL, 5889 .help_str = "set port (portid) vf (vfid) (mac-addr) " 5890 "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) " 5891 "on|off\n" 5892 "exact match rule:exact match of MAC or MAC and VLAN; " 5893 "hash match rule: hash match of MAC and exact match " 5894 "of VLAN", 5895 .tokens = { 5896 (void *)&cmd_set_vf_macvlan_set, 5897 (void *)&cmd_set_vf_macvlan_port, 5898 (void *)&cmd_set_vf_macvlan_portid, 5899 (void *)&cmd_set_vf_macvlan_vf, 5900 (void *)&cmd_set_vf_macvlan_vf_id, 5901 (void *)&cmd_set_vf_macvlan_mac, 5902 (void *)&cmd_set_vf_macvlan_filter_type, 5903 (void *)&cmd_set_vf_macvlan_mode, 5904 NULL, 5905 }, 5906 }; 5907 5908 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 5909 struct cmd_set_vf_traffic { 5910 cmdline_fixed_string_t set; 5911 cmdline_fixed_string_t port; 5912 uint8_t port_id; 5913 cmdline_fixed_string_t vf; 5914 uint8_t vf_id; 5915 cmdline_fixed_string_t what; 5916 cmdline_fixed_string_t mode; 5917 }; 5918 5919 static void 5920 cmd_set_vf_traffic_parsed(void *parsed_result, 5921 __attribute__((unused)) struct cmdline *cl, 5922 __attribute__((unused)) void *data) 5923 { 5924 struct cmd_set_vf_traffic *res = parsed_result; 5925 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 5926 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 5927 5928 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 5929 } 5930 5931 cmdline_parse_token_string_t cmd_setvf_traffic_set = 5932 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 5933 set, "set"); 5934 cmdline_parse_token_string_t cmd_setvf_traffic_port = 5935 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 5936 port, "port"); 5937 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 5938 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 5939 port_id, UINT8); 5940 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 5941 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 5942 vf, "vf"); 5943 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 5944 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 5945 vf_id, UINT8); 5946 cmdline_parse_token_string_t cmd_setvf_traffic_what = 5947 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 5948 what, "tx#rx"); 5949 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 5950 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 5951 mode, "on#off"); 5952 5953 cmdline_parse_inst_t cmd_set_vf_traffic = { 5954 .f = cmd_set_vf_traffic_parsed, 5955 .data = NULL, 5956 .help_str = "set port X vf Y rx|tx on|off" 5957 "(X = port number,Y = vf id)", 5958 .tokens = { 5959 (void *)&cmd_setvf_traffic_set, 5960 (void *)&cmd_setvf_traffic_port, 5961 (void *)&cmd_setvf_traffic_portid, 5962 (void *)&cmd_setvf_traffic_vf, 5963 (void *)&cmd_setvf_traffic_vfid, 5964 (void *)&cmd_setvf_traffic_what, 5965 (void *)&cmd_setvf_traffic_mode, 5966 NULL, 5967 }, 5968 }; 5969 5970 /* *** CONFIGURE VF RECEIVE MODE *** */ 5971 struct cmd_set_vf_rxmode { 5972 cmdline_fixed_string_t set; 5973 cmdline_fixed_string_t port; 5974 uint8_t port_id; 5975 cmdline_fixed_string_t vf; 5976 uint8_t vf_id; 5977 cmdline_fixed_string_t what; 5978 cmdline_fixed_string_t mode; 5979 cmdline_fixed_string_t on; 5980 }; 5981 5982 static void 5983 cmd_set_vf_rxmode_parsed(void *parsed_result, 5984 __attribute__((unused)) struct cmdline *cl, 5985 __attribute__((unused)) void *data) 5986 { 5987 int ret; 5988 uint16_t rx_mode = 0; 5989 struct cmd_set_vf_rxmode *res = parsed_result; 5990 5991 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 5992 if (!strcmp(res->what,"rxmode")) { 5993 if (!strcmp(res->mode, "AUPE")) 5994 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 5995 else if (!strcmp(res->mode, "ROPE")) 5996 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 5997 else if (!strcmp(res->mode, "BAM")) 5998 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 5999 else if (!strncmp(res->mode, "MPE",3)) 6000 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 6001 } 6002 6003 ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on); 6004 if (ret < 0) 6005 printf("bad VF receive mode parameter, return code = %d \n", 6006 ret); 6007 } 6008 6009 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 6010 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6011 set, "set"); 6012 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 6013 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6014 port, "port"); 6015 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 6016 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6017 port_id, UINT8); 6018 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 6019 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6020 vf, "vf"); 6021 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 6022 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6023 vf_id, UINT8); 6024 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 6025 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6026 what, "rxmode"); 6027 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 6028 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6029 mode, "AUPE#ROPE#BAM#MPE"); 6030 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 6031 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6032 on, "on#off"); 6033 6034 cmdline_parse_inst_t cmd_set_vf_rxmode = { 6035 .f = cmd_set_vf_rxmode_parsed, 6036 .data = NULL, 6037 .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off", 6038 .tokens = { 6039 (void *)&cmd_set_vf_rxmode_set, 6040 (void *)&cmd_set_vf_rxmode_port, 6041 (void *)&cmd_set_vf_rxmode_portid, 6042 (void *)&cmd_set_vf_rxmode_vf, 6043 (void *)&cmd_set_vf_rxmode_vfid, 6044 (void *)&cmd_set_vf_rxmode_what, 6045 (void *)&cmd_set_vf_rxmode_mode, 6046 (void *)&cmd_set_vf_rxmode_on, 6047 NULL, 6048 }, 6049 }; 6050 6051 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 6052 struct cmd_vf_mac_addr_result { 6053 cmdline_fixed_string_t mac_addr_cmd; 6054 cmdline_fixed_string_t what; 6055 cmdline_fixed_string_t port; 6056 uint8_t port_num; 6057 cmdline_fixed_string_t vf; 6058 uint8_t vf_num; 6059 struct ether_addr address; 6060 }; 6061 6062 static void cmd_vf_mac_addr_parsed(void *parsed_result, 6063 __attribute__((unused)) struct cmdline *cl, 6064 __attribute__((unused)) void *data) 6065 { 6066 struct cmd_vf_mac_addr_result *res = parsed_result; 6067 int ret = 0; 6068 6069 if (strcmp(res->what, "add") == 0) 6070 ret = rte_eth_dev_mac_addr_add(res->port_num, 6071 &res->address, res->vf_num); 6072 if(ret < 0) 6073 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 6074 6075 } 6076 6077 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 6078 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6079 mac_addr_cmd,"mac_addr"); 6080 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 6081 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6082 what,"add"); 6083 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 6084 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6085 port,"port"); 6086 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 6087 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6088 port_num, UINT8); 6089 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 6090 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6091 vf,"vf"); 6092 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 6093 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6094 vf_num, UINT8); 6095 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 6096 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 6097 address); 6098 6099 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 6100 .f = cmd_vf_mac_addr_parsed, 6101 .data = (void *)0, 6102 .help_str = "mac_addr add port X vf Y ethaddr:(X = port number," 6103 "Y = VF number)add MAC address filtering for a VF on port X", 6104 .tokens = { 6105 (void *)&cmd_vf_mac_addr_cmd, 6106 (void *)&cmd_vf_mac_addr_what, 6107 (void *)&cmd_vf_mac_addr_port, 6108 (void *)&cmd_vf_mac_addr_portnum, 6109 (void *)&cmd_vf_mac_addr_vf, 6110 (void *)&cmd_vf_mac_addr_vfnum, 6111 (void *)&cmd_vf_mac_addr_addr, 6112 NULL, 6113 }, 6114 }; 6115 6116 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 6117 struct cmd_vf_rx_vlan_filter { 6118 cmdline_fixed_string_t rx_vlan; 6119 cmdline_fixed_string_t what; 6120 uint16_t vlan_id; 6121 cmdline_fixed_string_t port; 6122 uint8_t port_id; 6123 cmdline_fixed_string_t vf; 6124 uint64_t vf_mask; 6125 }; 6126 6127 static void 6128 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 6129 __attribute__((unused)) struct cmdline *cl, 6130 __attribute__((unused)) void *data) 6131 { 6132 struct cmd_vf_rx_vlan_filter *res = parsed_result; 6133 6134 if (!strcmp(res->what, "add")) 6135 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1); 6136 else 6137 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0); 6138 } 6139 6140 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 6141 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6142 rx_vlan, "rx_vlan"); 6143 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 6144 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6145 what, "add#rm"); 6146 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 6147 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6148 vlan_id, UINT16); 6149 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 6150 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6151 port, "port"); 6152 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 6153 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6154 port_id, UINT8); 6155 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 6156 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6157 vf, "vf"); 6158 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 6159 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6160 vf_mask, UINT64); 6161 6162 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 6163 .f = cmd_vf_rx_vlan_filter_parsed, 6164 .data = NULL, 6165 .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID," 6166 "Y = port number,Z = hexadecimal VF mask)", 6167 .tokens = { 6168 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 6169 (void *)&cmd_vf_rx_vlan_filter_what, 6170 (void *)&cmd_vf_rx_vlan_filter_vlanid, 6171 (void *)&cmd_vf_rx_vlan_filter_port, 6172 (void *)&cmd_vf_rx_vlan_filter_portid, 6173 (void *)&cmd_vf_rx_vlan_filter_vf, 6174 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 6175 NULL, 6176 }, 6177 }; 6178 6179 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 6180 struct cmd_queue_rate_limit_result { 6181 cmdline_fixed_string_t set; 6182 cmdline_fixed_string_t port; 6183 uint8_t port_num; 6184 cmdline_fixed_string_t queue; 6185 uint8_t queue_num; 6186 cmdline_fixed_string_t rate; 6187 uint16_t rate_num; 6188 }; 6189 6190 static void cmd_queue_rate_limit_parsed(void *parsed_result, 6191 __attribute__((unused)) struct cmdline *cl, 6192 __attribute__((unused)) void *data) 6193 { 6194 struct cmd_queue_rate_limit_result *res = parsed_result; 6195 int ret = 0; 6196 6197 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 6198 && (strcmp(res->queue, "queue") == 0) 6199 && (strcmp(res->rate, "rate") == 0)) 6200 ret = set_queue_rate_limit(res->port_num, res->queue_num, 6201 res->rate_num); 6202 if (ret < 0) 6203 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 6204 6205 } 6206 6207 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 6208 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 6209 set, "set"); 6210 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 6211 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 6212 port, "port"); 6213 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 6214 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 6215 port_num, UINT8); 6216 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 6217 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 6218 queue, "queue"); 6219 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 6220 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 6221 queue_num, UINT8); 6222 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 6223 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 6224 rate, "rate"); 6225 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 6226 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 6227 rate_num, UINT16); 6228 6229 cmdline_parse_inst_t cmd_queue_rate_limit = { 6230 .f = cmd_queue_rate_limit_parsed, 6231 .data = (void *)0, 6232 .help_str = "set port X queue Y rate Z:(X = port number," 6233 "Y = queue number,Z = rate number)set rate limit for a queue on port X", 6234 .tokens = { 6235 (void *)&cmd_queue_rate_limit_set, 6236 (void *)&cmd_queue_rate_limit_port, 6237 (void *)&cmd_queue_rate_limit_portnum, 6238 (void *)&cmd_queue_rate_limit_queue, 6239 (void *)&cmd_queue_rate_limit_queuenum, 6240 (void *)&cmd_queue_rate_limit_rate, 6241 (void *)&cmd_queue_rate_limit_ratenum, 6242 NULL, 6243 }, 6244 }; 6245 6246 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 6247 struct cmd_vf_rate_limit_result { 6248 cmdline_fixed_string_t set; 6249 cmdline_fixed_string_t port; 6250 uint8_t port_num; 6251 cmdline_fixed_string_t vf; 6252 uint8_t vf_num; 6253 cmdline_fixed_string_t rate; 6254 uint16_t rate_num; 6255 cmdline_fixed_string_t q_msk; 6256 uint64_t q_msk_val; 6257 }; 6258 6259 static void cmd_vf_rate_limit_parsed(void *parsed_result, 6260 __attribute__((unused)) struct cmdline *cl, 6261 __attribute__((unused)) void *data) 6262 { 6263 struct cmd_vf_rate_limit_result *res = parsed_result; 6264 int ret = 0; 6265 6266 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 6267 && (strcmp(res->vf, "vf") == 0) 6268 && (strcmp(res->rate, "rate") == 0) 6269 && (strcmp(res->q_msk, "queue_mask") == 0)) 6270 ret = set_vf_rate_limit(res->port_num, res->vf_num, 6271 res->rate_num, res->q_msk_val); 6272 if (ret < 0) 6273 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 6274 6275 } 6276 6277 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 6278 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 6279 set, "set"); 6280 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 6281 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 6282 port, "port"); 6283 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 6284 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 6285 port_num, UINT8); 6286 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 6287 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 6288 vf, "vf"); 6289 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 6290 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 6291 vf_num, UINT8); 6292 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 6293 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 6294 rate, "rate"); 6295 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 6296 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 6297 rate_num, UINT16); 6298 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 6299 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 6300 q_msk, "queue_mask"); 6301 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 6302 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 6303 q_msk_val, UINT64); 6304 6305 cmdline_parse_inst_t cmd_vf_rate_limit = { 6306 .f = cmd_vf_rate_limit_parsed, 6307 .data = (void *)0, 6308 .help_str = "set port X vf Y rate Z queue_mask V:(X = port number," 6309 "Y = VF number,Z = rate number, V = queue mask value)set rate limit " 6310 "for queues of VF on port X", 6311 .tokens = { 6312 (void *)&cmd_vf_rate_limit_set, 6313 (void *)&cmd_vf_rate_limit_port, 6314 (void *)&cmd_vf_rate_limit_portnum, 6315 (void *)&cmd_vf_rate_limit_vf, 6316 (void *)&cmd_vf_rate_limit_vfnum, 6317 (void *)&cmd_vf_rate_limit_rate, 6318 (void *)&cmd_vf_rate_limit_ratenum, 6319 (void *)&cmd_vf_rate_limit_q_msk, 6320 (void *)&cmd_vf_rate_limit_q_msk_val, 6321 NULL, 6322 }, 6323 }; 6324 6325 /* *** ADD TUNNEL FILTER OF A PORT *** */ 6326 struct cmd_tunnel_filter_result { 6327 cmdline_fixed_string_t cmd; 6328 cmdline_fixed_string_t what; 6329 uint8_t port_id; 6330 struct ether_addr outer_mac; 6331 struct ether_addr inner_mac; 6332 cmdline_ipaddr_t ip_value; 6333 uint16_t inner_vlan; 6334 cmdline_fixed_string_t tunnel_type; 6335 cmdline_fixed_string_t filter_type; 6336 uint32_t tenant_id; 6337 uint16_t queue_num; 6338 }; 6339 6340 static void 6341 cmd_tunnel_filter_parsed(void *parsed_result, 6342 __attribute__((unused)) struct cmdline *cl, 6343 __attribute__((unused)) void *data) 6344 { 6345 struct cmd_tunnel_filter_result *res = parsed_result; 6346 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 6347 int ret = 0; 6348 6349 tunnel_filter_conf.outer_mac = &res->outer_mac; 6350 tunnel_filter_conf.inner_mac = &res->inner_mac; 6351 tunnel_filter_conf.inner_vlan = res->inner_vlan; 6352 6353 if (res->ip_value.family == AF_INET) { 6354 tunnel_filter_conf.ip_addr.ipv4_addr = 6355 res->ip_value.addr.ipv4.s_addr; 6356 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 6357 } else { 6358 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 6359 &(res->ip_value.addr.ipv6), 6360 sizeof(struct in6_addr)); 6361 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 6362 } 6363 6364 if (!strcmp(res->filter_type, "imac-ivlan")) 6365 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 6366 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 6367 tunnel_filter_conf.filter_type = 6368 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 6369 else if (!strcmp(res->filter_type, "imac-tenid")) 6370 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 6371 else if (!strcmp(res->filter_type, "imac")) 6372 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 6373 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 6374 tunnel_filter_conf.filter_type = 6375 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 6376 else { 6377 printf("The filter type is not supported"); 6378 return; 6379 } 6380 6381 if (!strcmp(res->tunnel_type, "vxlan")) 6382 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 6383 else if (!strcmp(res->tunnel_type, "nvgre")) 6384 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 6385 else { 6386 printf("The tunnel type %s not supported.\n", res->tunnel_type); 6387 return; 6388 } 6389 6390 tunnel_filter_conf.tenant_id = res->tenant_id; 6391 tunnel_filter_conf.queue_id = res->queue_num; 6392 if (!strcmp(res->what, "add")) 6393 ret = rte_eth_dev_filter_ctrl(res->port_id, 6394 RTE_ETH_FILTER_TUNNEL, 6395 RTE_ETH_FILTER_ADD, 6396 &tunnel_filter_conf); 6397 else 6398 ret = rte_eth_dev_filter_ctrl(res->port_id, 6399 RTE_ETH_FILTER_TUNNEL, 6400 RTE_ETH_FILTER_DELETE, 6401 &tunnel_filter_conf); 6402 if (ret < 0) 6403 printf("cmd_tunnel_filter_parsed error: (%s)\n", 6404 strerror(-ret)); 6405 6406 } 6407 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 6408 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 6409 cmd, "tunnel_filter"); 6410 cmdline_parse_token_string_t cmd_tunnel_filter_what = 6411 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 6412 what, "add#rm"); 6413 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 6414 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 6415 port_id, UINT8); 6416 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 6417 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 6418 outer_mac); 6419 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 6420 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 6421 inner_mac); 6422 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 6423 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 6424 inner_vlan, UINT16); 6425 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 6426 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 6427 ip_value); 6428 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 6429 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 6430 tunnel_type, "vxlan#nvgre"); 6431 6432 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 6433 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 6434 filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#" 6435 "imac#omac-imac-tenid"); 6436 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 6437 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 6438 tenant_id, UINT32); 6439 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 6440 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 6441 queue_num, UINT16); 6442 6443 cmdline_parse_inst_t cmd_tunnel_filter = { 6444 .f = cmd_tunnel_filter_parsed, 6445 .data = (void *)0, 6446 .help_str = "add/rm tunnel filter of a port: " 6447 "tunnel_filter add port_id outer_mac inner_mac ip " 6448 "inner_vlan tunnel_type(vxlan|nvgre) filter_type " 6449 "(imac-ivlan|imac-ivlan-tenid|imac-tenid|" 6450 "imac|omac-imac-tenid) " 6451 "tenant_id queue_num", 6452 .tokens = { 6453 (void *)&cmd_tunnel_filter_cmd, 6454 (void *)&cmd_tunnel_filter_what, 6455 (void *)&cmd_tunnel_filter_port_id, 6456 (void *)&cmd_tunnel_filter_outer_mac, 6457 (void *)&cmd_tunnel_filter_inner_mac, 6458 (void *)&cmd_tunnel_filter_ip_value, 6459 (void *)&cmd_tunnel_filter_innner_vlan, 6460 (void *)&cmd_tunnel_filter_tunnel_type, 6461 (void *)&cmd_tunnel_filter_filter_type, 6462 (void *)&cmd_tunnel_filter_tenant_id, 6463 (void *)&cmd_tunnel_filter_queue_num, 6464 NULL, 6465 }, 6466 }; 6467 6468 /* *** CONFIGURE TUNNEL UDP PORT *** */ 6469 struct cmd_tunnel_udp_config { 6470 cmdline_fixed_string_t cmd; 6471 cmdline_fixed_string_t what; 6472 uint16_t udp_port; 6473 uint8_t port_id; 6474 }; 6475 6476 static void 6477 cmd_tunnel_udp_config_parsed(void *parsed_result, 6478 __attribute__((unused)) struct cmdline *cl, 6479 __attribute__((unused)) void *data) 6480 { 6481 struct cmd_tunnel_udp_config *res = parsed_result; 6482 struct rte_eth_udp_tunnel tunnel_udp; 6483 int ret; 6484 6485 tunnel_udp.udp_port = res->udp_port; 6486 6487 if (!strcmp(res->cmd, "rx_vxlan_port")) 6488 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 6489 6490 if (!strcmp(res->what, "add")) 6491 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp); 6492 else 6493 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp); 6494 6495 if (ret < 0) 6496 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 6497 } 6498 6499 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 6500 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 6501 cmd, "rx_vxlan_port"); 6502 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 6503 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 6504 what, "add#rm"); 6505 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 6506 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 6507 udp_port, UINT16); 6508 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 6509 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 6510 port_id, UINT8); 6511 6512 cmdline_parse_inst_t cmd_tunnel_udp_config = { 6513 .f = cmd_tunnel_udp_config_parsed, 6514 .data = (void *)0, 6515 .help_str = "add/rm an tunneling UDP port filter: " 6516 "rx_vxlan_port add udp_port port_id", 6517 .tokens = { 6518 (void *)&cmd_tunnel_udp_config_cmd, 6519 (void *)&cmd_tunnel_udp_config_what, 6520 (void *)&cmd_tunnel_udp_config_udp_port, 6521 (void *)&cmd_tunnel_udp_config_port_id, 6522 NULL, 6523 }, 6524 }; 6525 6526 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 6527 struct cmd_set_mirror_mask_result { 6528 cmdline_fixed_string_t set; 6529 cmdline_fixed_string_t port; 6530 uint8_t port_id; 6531 cmdline_fixed_string_t mirror; 6532 uint8_t rule_id; 6533 cmdline_fixed_string_t what; 6534 cmdline_fixed_string_t value; 6535 cmdline_fixed_string_t dstpool; 6536 uint8_t dstpool_id; 6537 cmdline_fixed_string_t on; 6538 }; 6539 6540 cmdline_parse_token_string_t cmd_mirror_mask_set = 6541 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6542 set, "set"); 6543 cmdline_parse_token_string_t cmd_mirror_mask_port = 6544 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6545 port, "port"); 6546 cmdline_parse_token_num_t cmd_mirror_mask_portid = 6547 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 6548 port_id, UINT8); 6549 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 6550 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6551 mirror, "mirror-rule"); 6552 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 6553 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 6554 rule_id, UINT8); 6555 cmdline_parse_token_string_t cmd_mirror_mask_what = 6556 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6557 what, "pool-mirror#vlan-mirror"); 6558 cmdline_parse_token_string_t cmd_mirror_mask_value = 6559 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6560 value, NULL); 6561 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 6562 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6563 dstpool, "dst-pool"); 6564 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 6565 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 6566 dstpool_id, UINT8); 6567 cmdline_parse_token_string_t cmd_mirror_mask_on = 6568 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 6569 on, "on#off"); 6570 6571 static void 6572 cmd_set_mirror_mask_parsed(void *parsed_result, 6573 __attribute__((unused)) struct cmdline *cl, 6574 __attribute__((unused)) void *data) 6575 { 6576 int ret,nb_item,i; 6577 struct cmd_set_mirror_mask_result *res = parsed_result; 6578 struct rte_eth_vmdq_mirror_conf mr_conf; 6579 6580 memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf)); 6581 6582 unsigned int vlan_list[ETH_VMDQ_MAX_VLAN_FILTERS]; 6583 6584 mr_conf.dst_pool = res->dstpool_id; 6585 6586 if (!strcmp(res->what, "pool-mirror")) { 6587 mr_conf.pool_mask = strtoull(res->value,NULL,16); 6588 mr_conf.rule_type_mask = ETH_VMDQ_POOL_MIRROR; 6589 } else if(!strcmp(res->what, "vlan-mirror")) { 6590 mr_conf.rule_type_mask = ETH_VMDQ_VLAN_MIRROR; 6591 nb_item = parse_item_list(res->value, "core", 6592 ETH_VMDQ_MAX_VLAN_FILTERS,vlan_list,1); 6593 if (nb_item <= 0) 6594 return; 6595 6596 for(i=0; i < nb_item; i++) { 6597 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 6598 printf("Invalid vlan_id: must be < 4096\n"); 6599 return; 6600 } 6601 6602 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 6603 mr_conf.vlan.vlan_mask |= 1ULL << i; 6604 } 6605 } 6606 6607 if(!strcmp(res->on, "on")) 6608 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 6609 res->rule_id, 1); 6610 else 6611 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 6612 res->rule_id, 0); 6613 if(ret < 0) 6614 printf("mirror rule add error: (%s)\n", strerror(-ret)); 6615 } 6616 6617 cmdline_parse_inst_t cmd_set_mirror_mask = { 6618 .f = cmd_set_mirror_mask_parsed, 6619 .data = NULL, 6620 .help_str = "set port X mirror-rule Y pool-mirror|vlan-mirror " 6621 "pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off", 6622 .tokens = { 6623 (void *)&cmd_mirror_mask_set, 6624 (void *)&cmd_mirror_mask_port, 6625 (void *)&cmd_mirror_mask_portid, 6626 (void *)&cmd_mirror_mask_mirror, 6627 (void *)&cmd_mirror_mask_ruleid, 6628 (void *)&cmd_mirror_mask_what, 6629 (void *)&cmd_mirror_mask_value, 6630 (void *)&cmd_mirror_mask_dstpool, 6631 (void *)&cmd_mirror_mask_poolid, 6632 (void *)&cmd_mirror_mask_on, 6633 NULL, 6634 }, 6635 }; 6636 6637 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */ 6638 struct cmd_set_mirror_link_result { 6639 cmdline_fixed_string_t set; 6640 cmdline_fixed_string_t port; 6641 uint8_t port_id; 6642 cmdline_fixed_string_t mirror; 6643 uint8_t rule_id; 6644 cmdline_fixed_string_t what; 6645 cmdline_fixed_string_t dstpool; 6646 uint8_t dstpool_id; 6647 cmdline_fixed_string_t on; 6648 }; 6649 6650 cmdline_parse_token_string_t cmd_mirror_link_set = 6651 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6652 set, "set"); 6653 cmdline_parse_token_string_t cmd_mirror_link_port = 6654 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6655 port, "port"); 6656 cmdline_parse_token_num_t cmd_mirror_link_portid = 6657 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 6658 port_id, UINT8); 6659 cmdline_parse_token_string_t cmd_mirror_link_mirror = 6660 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6661 mirror, "mirror-rule"); 6662 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 6663 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 6664 rule_id, UINT8); 6665 cmdline_parse_token_string_t cmd_mirror_link_what = 6666 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6667 what, "uplink-mirror#downlink-mirror"); 6668 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 6669 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6670 dstpool, "dst-pool"); 6671 cmdline_parse_token_num_t cmd_mirror_link_poolid = 6672 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 6673 dstpool_id, UINT8); 6674 cmdline_parse_token_string_t cmd_mirror_link_on = 6675 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 6676 on, "on#off"); 6677 6678 static void 6679 cmd_set_mirror_link_parsed(void *parsed_result, 6680 __attribute__((unused)) struct cmdline *cl, 6681 __attribute__((unused)) void *data) 6682 { 6683 int ret; 6684 struct cmd_set_mirror_link_result *res = parsed_result; 6685 struct rte_eth_vmdq_mirror_conf mr_conf; 6686 6687 memset(&mr_conf,0,sizeof(struct rte_eth_vmdq_mirror_conf)); 6688 if(!strcmp(res->what, "uplink-mirror")) { 6689 mr_conf.rule_type_mask = ETH_VMDQ_UPLINK_MIRROR; 6690 }else if(!strcmp(res->what, "downlink-mirror")) 6691 mr_conf.rule_type_mask = ETH_VMDQ_DOWNLIN_MIRROR; 6692 6693 mr_conf.dst_pool = res->dstpool_id; 6694 6695 if(!strcmp(res->on, "on")) 6696 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 6697 res->rule_id, 1); 6698 else 6699 ret = rte_eth_mirror_rule_set(res->port_id,&mr_conf, 6700 res->rule_id, 0); 6701 6702 /* check the return value and print it if is < 0 */ 6703 if(ret < 0) 6704 printf("mirror rule add error: (%s)\n", strerror(-ret)); 6705 6706 } 6707 6708 cmdline_parse_inst_t cmd_set_mirror_link = { 6709 .f = cmd_set_mirror_link_parsed, 6710 .data = NULL, 6711 .help_str = "set port X mirror-rule Y uplink-mirror|" 6712 "downlink-mirror dst-pool Z on|off", 6713 .tokens = { 6714 (void *)&cmd_mirror_link_set, 6715 (void *)&cmd_mirror_link_port, 6716 (void *)&cmd_mirror_link_portid, 6717 (void *)&cmd_mirror_link_mirror, 6718 (void *)&cmd_mirror_link_ruleid, 6719 (void *)&cmd_mirror_link_what, 6720 (void *)&cmd_mirror_link_dstpool, 6721 (void *)&cmd_mirror_link_poolid, 6722 (void *)&cmd_mirror_link_on, 6723 NULL, 6724 }, 6725 }; 6726 6727 /* *** RESET VM MIRROR RULE *** */ 6728 struct cmd_rm_mirror_rule_result { 6729 cmdline_fixed_string_t reset; 6730 cmdline_fixed_string_t port; 6731 uint8_t port_id; 6732 cmdline_fixed_string_t mirror; 6733 uint8_t rule_id; 6734 }; 6735 6736 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 6737 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 6738 reset, "reset"); 6739 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 6740 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 6741 port, "port"); 6742 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 6743 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 6744 port_id, UINT8); 6745 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 6746 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 6747 mirror, "mirror-rule"); 6748 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 6749 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 6750 rule_id, UINT8); 6751 6752 static void 6753 cmd_reset_mirror_rule_parsed(void *parsed_result, 6754 __attribute__((unused)) struct cmdline *cl, 6755 __attribute__((unused)) void *data) 6756 { 6757 int ret; 6758 struct cmd_set_mirror_link_result *res = parsed_result; 6759 /* check rule_id */ 6760 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 6761 if(ret < 0) 6762 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 6763 } 6764 6765 cmdline_parse_inst_t cmd_reset_mirror_rule = { 6766 .f = cmd_reset_mirror_rule_parsed, 6767 .data = NULL, 6768 .help_str = "reset port X mirror-rule Y", 6769 .tokens = { 6770 (void *)&cmd_rm_mirror_rule_reset, 6771 (void *)&cmd_rm_mirror_rule_port, 6772 (void *)&cmd_rm_mirror_rule_portid, 6773 (void *)&cmd_rm_mirror_rule_mirror, 6774 (void *)&cmd_rm_mirror_rule_ruleid, 6775 NULL, 6776 }, 6777 }; 6778 6779 /* ******************************************************************************** */ 6780 6781 struct cmd_dump_result { 6782 cmdline_fixed_string_t dump; 6783 }; 6784 6785 static void 6786 dump_struct_sizes(void) 6787 { 6788 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 6789 DUMP_SIZE(struct rte_mbuf); 6790 DUMP_SIZE(struct rte_mempool); 6791 DUMP_SIZE(struct rte_ring); 6792 #undef DUMP_SIZE 6793 } 6794 6795 static void cmd_dump_parsed(void *parsed_result, 6796 __attribute__((unused)) struct cmdline *cl, 6797 __attribute__((unused)) void *data) 6798 { 6799 struct cmd_dump_result *res = parsed_result; 6800 6801 if (!strcmp(res->dump, "dump_physmem")) 6802 rte_dump_physmem_layout(stdout); 6803 else if (!strcmp(res->dump, "dump_memzone")) 6804 rte_memzone_dump(stdout); 6805 else if (!strcmp(res->dump, "dump_log_history")) 6806 rte_log_dump_history(stdout); 6807 else if (!strcmp(res->dump, "dump_struct_sizes")) 6808 dump_struct_sizes(); 6809 else if (!strcmp(res->dump, "dump_ring")) 6810 rte_ring_list_dump(stdout); 6811 else if (!strcmp(res->dump, "dump_mempool")) 6812 rte_mempool_list_dump(stdout); 6813 else if (!strcmp(res->dump, "dump_devargs")) 6814 rte_eal_devargs_dump(stdout); 6815 } 6816 6817 cmdline_parse_token_string_t cmd_dump_dump = 6818 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 6819 "dump_physmem#" 6820 "dump_memzone#" 6821 "dump_log_history#" 6822 "dump_struct_sizes#" 6823 "dump_ring#" 6824 "dump_mempool#" 6825 "dump_devargs"); 6826 6827 cmdline_parse_inst_t cmd_dump = { 6828 .f = cmd_dump_parsed, /* function to call */ 6829 .data = NULL, /* 2nd arg of func */ 6830 .help_str = "dump status", 6831 .tokens = { /* token list, NULL terminated */ 6832 (void *)&cmd_dump_dump, 6833 NULL, 6834 }, 6835 }; 6836 6837 /* ******************************************************************************** */ 6838 6839 struct cmd_dump_one_result { 6840 cmdline_fixed_string_t dump; 6841 cmdline_fixed_string_t name; 6842 }; 6843 6844 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 6845 __attribute__((unused)) void *data) 6846 { 6847 struct cmd_dump_one_result *res = parsed_result; 6848 6849 if (!strcmp(res->dump, "dump_ring")) { 6850 struct rte_ring *r; 6851 r = rte_ring_lookup(res->name); 6852 if (r == NULL) { 6853 cmdline_printf(cl, "Cannot find ring\n"); 6854 return; 6855 } 6856 rte_ring_dump(stdout, r); 6857 } else if (!strcmp(res->dump, "dump_mempool")) { 6858 struct rte_mempool *mp; 6859 mp = rte_mempool_lookup(res->name); 6860 if (mp == NULL) { 6861 cmdline_printf(cl, "Cannot find mempool\n"); 6862 return; 6863 } 6864 rte_mempool_dump(stdout, mp); 6865 } 6866 } 6867 6868 cmdline_parse_token_string_t cmd_dump_one_dump = 6869 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 6870 "dump_ring#dump_mempool"); 6871 6872 cmdline_parse_token_string_t cmd_dump_one_name = 6873 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 6874 6875 cmdline_parse_inst_t cmd_dump_one = { 6876 .f = cmd_dump_one_parsed, /* function to call */ 6877 .data = NULL, /* 2nd arg of func */ 6878 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>", 6879 .tokens = { /* token list, NULL terminated */ 6880 (void *)&cmd_dump_one_dump, 6881 (void *)&cmd_dump_one_name, 6882 NULL, 6883 }, 6884 }; 6885 6886 /* *** Add/Del syn filter *** */ 6887 struct cmd_syn_filter_result { 6888 cmdline_fixed_string_t filter; 6889 uint8_t port_id; 6890 cmdline_fixed_string_t ops; 6891 cmdline_fixed_string_t priority; 6892 cmdline_fixed_string_t high; 6893 cmdline_fixed_string_t queue; 6894 uint16_t queue_id; 6895 }; 6896 6897 static void 6898 cmd_syn_filter_parsed(void *parsed_result, 6899 __attribute__((unused)) struct cmdline *cl, 6900 __attribute__((unused)) void *data) 6901 { 6902 struct cmd_syn_filter_result *res = parsed_result; 6903 struct rte_eth_syn_filter syn_filter; 6904 int ret = 0; 6905 6906 ret = rte_eth_dev_filter_supported(res->port_id, 6907 RTE_ETH_FILTER_SYN); 6908 if (ret < 0) { 6909 printf("syn filter is not supported on port %u.\n", 6910 res->port_id); 6911 return; 6912 } 6913 6914 memset(&syn_filter, 0, sizeof(syn_filter)); 6915 6916 if (!strcmp(res->ops, "add")) { 6917 if (!strcmp(res->high, "high")) 6918 syn_filter.hig_pri = 1; 6919 else 6920 syn_filter.hig_pri = 0; 6921 6922 syn_filter.queue = res->queue_id; 6923 ret = rte_eth_dev_filter_ctrl(res->port_id, 6924 RTE_ETH_FILTER_SYN, 6925 RTE_ETH_FILTER_ADD, 6926 &syn_filter); 6927 } else 6928 ret = rte_eth_dev_filter_ctrl(res->port_id, 6929 RTE_ETH_FILTER_SYN, 6930 RTE_ETH_FILTER_DELETE, 6931 &syn_filter); 6932 6933 if (ret < 0) 6934 printf("syn filter programming error: (%s)\n", 6935 strerror(-ret)); 6936 } 6937 6938 cmdline_parse_token_string_t cmd_syn_filter_filter = 6939 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 6940 filter, "syn_filter"); 6941 cmdline_parse_token_num_t cmd_syn_filter_port_id = 6942 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 6943 port_id, UINT8); 6944 cmdline_parse_token_string_t cmd_syn_filter_ops = 6945 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 6946 ops, "add#del"); 6947 cmdline_parse_token_string_t cmd_syn_filter_priority = 6948 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 6949 priority, "priority"); 6950 cmdline_parse_token_string_t cmd_syn_filter_high = 6951 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 6952 high, "high#low"); 6953 cmdline_parse_token_string_t cmd_syn_filter_queue = 6954 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 6955 queue, "queue"); 6956 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 6957 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 6958 queue_id, UINT16); 6959 6960 cmdline_parse_inst_t cmd_syn_filter = { 6961 .f = cmd_syn_filter_parsed, 6962 .data = NULL, 6963 .help_str = "add/delete syn filter", 6964 .tokens = { 6965 (void *)&cmd_syn_filter_filter, 6966 (void *)&cmd_syn_filter_port_id, 6967 (void *)&cmd_syn_filter_ops, 6968 (void *)&cmd_syn_filter_priority, 6969 (void *)&cmd_syn_filter_high, 6970 (void *)&cmd_syn_filter_queue, 6971 (void *)&cmd_syn_filter_queue_id, 6972 NULL, 6973 }, 6974 }; 6975 6976 /* *** ADD/REMOVE A 2tuple FILTER *** */ 6977 struct cmd_2tuple_filter_result { 6978 cmdline_fixed_string_t filter; 6979 uint8_t port_id; 6980 cmdline_fixed_string_t ops; 6981 cmdline_fixed_string_t dst_port; 6982 uint16_t dst_port_value; 6983 cmdline_fixed_string_t protocol; 6984 uint8_t protocol_value; 6985 cmdline_fixed_string_t mask; 6986 uint8_t mask_value; 6987 cmdline_fixed_string_t tcp_flags; 6988 uint8_t tcp_flags_value; 6989 cmdline_fixed_string_t priority; 6990 uint8_t priority_value; 6991 cmdline_fixed_string_t queue; 6992 uint16_t queue_id; 6993 }; 6994 6995 static void 6996 cmd_2tuple_filter_parsed(void *parsed_result, 6997 __attribute__((unused)) struct cmdline *cl, 6998 __attribute__((unused)) void *data) 6999 { 7000 struct rte_eth_ntuple_filter filter; 7001 struct cmd_2tuple_filter_result *res = parsed_result; 7002 int ret = 0; 7003 7004 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 7005 if (ret < 0) { 7006 printf("ntuple filter is not supported on port %u.\n", 7007 res->port_id); 7008 return; 7009 } 7010 7011 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 7012 7013 filter.flags = RTE_2TUPLE_FLAGS; 7014 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 7015 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 7016 filter.proto = res->protocol_value; 7017 filter.priority = res->priority_value; 7018 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 7019 printf("nonzero tcp_flags is only meaningful" 7020 " when protocol is TCP.\n"); 7021 return; 7022 } 7023 if (res->tcp_flags_value > TCP_FLAG_ALL) { 7024 printf("invalid TCP flags.\n"); 7025 return; 7026 } 7027 7028 if (res->tcp_flags_value != 0) { 7029 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 7030 filter.tcp_flags = res->tcp_flags_value; 7031 } 7032 7033 /* need convert to big endian. */ 7034 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 7035 filter.queue = res->queue_id; 7036 7037 if (!strcmp(res->ops, "add")) 7038 ret = rte_eth_dev_filter_ctrl(res->port_id, 7039 RTE_ETH_FILTER_NTUPLE, 7040 RTE_ETH_FILTER_ADD, 7041 &filter); 7042 else 7043 ret = rte_eth_dev_filter_ctrl(res->port_id, 7044 RTE_ETH_FILTER_NTUPLE, 7045 RTE_ETH_FILTER_DELETE, 7046 &filter); 7047 if (ret < 0) 7048 printf("2tuple filter programming error: (%s)\n", 7049 strerror(-ret)); 7050 7051 } 7052 7053 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 7054 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7055 filter, "2tuple_filter"); 7056 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 7057 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7058 port_id, UINT8); 7059 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 7060 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7061 ops, "add#del"); 7062 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 7063 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7064 dst_port, "dst_port"); 7065 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 7066 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7067 dst_port_value, UINT16); 7068 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 7069 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7070 protocol, "protocol"); 7071 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 7072 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7073 protocol_value, UINT8); 7074 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 7075 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7076 mask, "mask"); 7077 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 7078 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7079 mask_value, INT8); 7080 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 7081 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7082 tcp_flags, "tcp_flags"); 7083 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 7084 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7085 tcp_flags_value, UINT8); 7086 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 7087 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7088 priority, "priority"); 7089 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 7090 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7091 priority_value, UINT8); 7092 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 7093 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7094 queue, "queue"); 7095 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 7096 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7097 queue_id, UINT16); 7098 7099 cmdline_parse_inst_t cmd_2tuple_filter = { 7100 .f = cmd_2tuple_filter_parsed, 7101 .data = NULL, 7102 .help_str = "add a 2tuple filter", 7103 .tokens = { 7104 (void *)&cmd_2tuple_filter_filter, 7105 (void *)&cmd_2tuple_filter_port_id, 7106 (void *)&cmd_2tuple_filter_ops, 7107 (void *)&cmd_2tuple_filter_dst_port, 7108 (void *)&cmd_2tuple_filter_dst_port_value, 7109 (void *)&cmd_2tuple_filter_protocol, 7110 (void *)&cmd_2tuple_filter_protocol_value, 7111 (void *)&cmd_2tuple_filter_mask, 7112 (void *)&cmd_2tuple_filter_mask_value, 7113 (void *)&cmd_2tuple_filter_tcp_flags, 7114 (void *)&cmd_2tuple_filter_tcp_flags_value, 7115 (void *)&cmd_2tuple_filter_priority, 7116 (void *)&cmd_2tuple_filter_priority_value, 7117 (void *)&cmd_2tuple_filter_queue, 7118 (void *)&cmd_2tuple_filter_queue_id, 7119 NULL, 7120 }, 7121 }; 7122 7123 /* *** ADD/REMOVE A 5tuple FILTER *** */ 7124 struct cmd_5tuple_filter_result { 7125 cmdline_fixed_string_t filter; 7126 uint8_t port_id; 7127 cmdline_fixed_string_t ops; 7128 cmdline_fixed_string_t dst_ip; 7129 cmdline_ipaddr_t dst_ip_value; 7130 cmdline_fixed_string_t src_ip; 7131 cmdline_ipaddr_t src_ip_value; 7132 cmdline_fixed_string_t dst_port; 7133 uint16_t dst_port_value; 7134 cmdline_fixed_string_t src_port; 7135 uint16_t src_port_value; 7136 cmdline_fixed_string_t protocol; 7137 uint8_t protocol_value; 7138 cmdline_fixed_string_t mask; 7139 uint8_t mask_value; 7140 cmdline_fixed_string_t tcp_flags; 7141 uint8_t tcp_flags_value; 7142 cmdline_fixed_string_t priority; 7143 uint8_t priority_value; 7144 cmdline_fixed_string_t queue; 7145 uint16_t queue_id; 7146 }; 7147 7148 static void 7149 cmd_5tuple_filter_parsed(void *parsed_result, 7150 __attribute__((unused)) struct cmdline *cl, 7151 __attribute__((unused)) void *data) 7152 { 7153 struct rte_eth_ntuple_filter filter; 7154 struct cmd_5tuple_filter_result *res = parsed_result; 7155 int ret = 0; 7156 7157 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 7158 if (ret < 0) { 7159 printf("ntuple filter is not supported on port %u.\n", 7160 res->port_id); 7161 return; 7162 } 7163 7164 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 7165 7166 filter.flags = RTE_5TUPLE_FLAGS; 7167 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 7168 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 7169 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 7170 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 7171 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 7172 filter.proto = res->protocol_value; 7173 filter.priority = res->priority_value; 7174 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 7175 printf("nonzero tcp_flags is only meaningful" 7176 " when protocol is TCP.\n"); 7177 return; 7178 } 7179 if (res->tcp_flags_value > TCP_FLAG_ALL) { 7180 printf("invalid TCP flags.\n"); 7181 return; 7182 } 7183 7184 if (res->tcp_flags_value != 0) { 7185 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 7186 filter.tcp_flags = res->tcp_flags_value; 7187 } 7188 7189 if (res->dst_ip_value.family == AF_INET) 7190 /* no need to convert, already big endian. */ 7191 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 7192 else { 7193 if (filter.dst_ip_mask == 0) { 7194 printf("can not support ipv6 involved compare.\n"); 7195 return; 7196 } 7197 filter.dst_ip = 0; 7198 } 7199 7200 if (res->src_ip_value.family == AF_INET) 7201 /* no need to convert, already big endian. */ 7202 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 7203 else { 7204 if (filter.src_ip_mask == 0) { 7205 printf("can not support ipv6 involved compare.\n"); 7206 return; 7207 } 7208 filter.src_ip = 0; 7209 } 7210 /* need convert to big endian. */ 7211 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 7212 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 7213 filter.queue = res->queue_id; 7214 7215 if (!strcmp(res->ops, "add")) 7216 ret = rte_eth_dev_filter_ctrl(res->port_id, 7217 RTE_ETH_FILTER_NTUPLE, 7218 RTE_ETH_FILTER_ADD, 7219 &filter); 7220 else 7221 ret = rte_eth_dev_filter_ctrl(res->port_id, 7222 RTE_ETH_FILTER_NTUPLE, 7223 RTE_ETH_FILTER_DELETE, 7224 &filter); 7225 if (ret < 0) 7226 printf("5tuple filter programming error: (%s)\n", 7227 strerror(-ret)); 7228 } 7229 7230 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 7231 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7232 filter, "5tuple_filter"); 7233 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 7234 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7235 port_id, UINT8); 7236 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 7237 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7238 ops, "add#del"); 7239 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 7240 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7241 dst_ip, "dst_ip"); 7242 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 7243 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 7244 dst_ip_value); 7245 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 7246 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7247 src_ip, "src_ip"); 7248 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 7249 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 7250 src_ip_value); 7251 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 7252 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7253 dst_port, "dst_port"); 7254 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 7255 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7256 dst_port_value, UINT16); 7257 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 7258 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7259 src_port, "src_port"); 7260 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 7261 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7262 src_port_value, UINT16); 7263 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 7264 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7265 protocol, "protocol"); 7266 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 7267 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7268 protocol_value, UINT8); 7269 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 7270 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7271 mask, "mask"); 7272 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 7273 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7274 mask_value, INT8); 7275 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 7276 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7277 tcp_flags, "tcp_flags"); 7278 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 7279 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7280 tcp_flags_value, UINT8); 7281 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 7282 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7283 priority, "priority"); 7284 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 7285 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7286 priority_value, UINT8); 7287 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 7288 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 7289 queue, "queue"); 7290 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 7291 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 7292 queue_id, UINT16); 7293 7294 cmdline_parse_inst_t cmd_5tuple_filter = { 7295 .f = cmd_5tuple_filter_parsed, 7296 .data = NULL, 7297 .help_str = "add/del a 5tuple filter", 7298 .tokens = { 7299 (void *)&cmd_5tuple_filter_filter, 7300 (void *)&cmd_5tuple_filter_port_id, 7301 (void *)&cmd_5tuple_filter_ops, 7302 (void *)&cmd_5tuple_filter_dst_ip, 7303 (void *)&cmd_5tuple_filter_dst_ip_value, 7304 (void *)&cmd_5tuple_filter_src_ip, 7305 (void *)&cmd_5tuple_filter_src_ip_value, 7306 (void *)&cmd_5tuple_filter_dst_port, 7307 (void *)&cmd_5tuple_filter_dst_port_value, 7308 (void *)&cmd_5tuple_filter_src_port, 7309 (void *)&cmd_5tuple_filter_src_port_value, 7310 (void *)&cmd_5tuple_filter_protocol, 7311 (void *)&cmd_5tuple_filter_protocol_value, 7312 (void *)&cmd_5tuple_filter_mask, 7313 (void *)&cmd_5tuple_filter_mask_value, 7314 (void *)&cmd_5tuple_filter_tcp_flags, 7315 (void *)&cmd_5tuple_filter_tcp_flags_value, 7316 (void *)&cmd_5tuple_filter_priority, 7317 (void *)&cmd_5tuple_filter_priority_value, 7318 (void *)&cmd_5tuple_filter_queue, 7319 (void *)&cmd_5tuple_filter_queue_id, 7320 NULL, 7321 }, 7322 }; 7323 7324 /* *** ADD/REMOVE A flex FILTER *** */ 7325 struct cmd_flex_filter_result { 7326 cmdline_fixed_string_t filter; 7327 cmdline_fixed_string_t ops; 7328 uint8_t port_id; 7329 cmdline_fixed_string_t len; 7330 uint8_t len_value; 7331 cmdline_fixed_string_t bytes; 7332 cmdline_fixed_string_t bytes_value; 7333 cmdline_fixed_string_t mask; 7334 cmdline_fixed_string_t mask_value; 7335 cmdline_fixed_string_t priority; 7336 uint8_t priority_value; 7337 cmdline_fixed_string_t queue; 7338 uint16_t queue_id; 7339 }; 7340 7341 static int xdigit2val(unsigned char c) 7342 { 7343 int val; 7344 if (isdigit(c)) 7345 val = c - '0'; 7346 else if (isupper(c)) 7347 val = c - 'A' + 10; 7348 else 7349 val = c - 'a' + 10; 7350 return val; 7351 } 7352 7353 static void 7354 cmd_flex_filter_parsed(void *parsed_result, 7355 __attribute__((unused)) struct cmdline *cl, 7356 __attribute__((unused)) void *data) 7357 { 7358 int ret = 0; 7359 struct rte_eth_flex_filter filter; 7360 struct cmd_flex_filter_result *res = parsed_result; 7361 char *bytes_ptr, *mask_ptr; 7362 uint16_t len, i, j = 0; 7363 char c; 7364 int val; 7365 uint8_t byte = 0; 7366 7367 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 7368 printf("the len exceed the max length 128\n"); 7369 return; 7370 } 7371 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 7372 filter.len = res->len_value; 7373 filter.priority = res->priority_value; 7374 filter.queue = res->queue_id; 7375 bytes_ptr = res->bytes_value; 7376 mask_ptr = res->mask_value; 7377 7378 /* translate bytes string to array. */ 7379 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 7380 (bytes_ptr[1] == 'X'))) 7381 bytes_ptr += 2; 7382 len = strnlen(bytes_ptr, res->len_value * 2); 7383 if (len == 0 || (len % 8 != 0)) { 7384 printf("please check len and bytes input\n"); 7385 return; 7386 } 7387 for (i = 0; i < len; i++) { 7388 c = bytes_ptr[i]; 7389 if (isxdigit(c) == 0) { 7390 /* invalid characters. */ 7391 printf("invalid input\n"); 7392 return; 7393 } 7394 val = xdigit2val(c); 7395 if (i % 2) { 7396 byte |= val; 7397 filter.bytes[j] = byte; 7398 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 7399 j++; 7400 byte = 0; 7401 } else 7402 byte |= val << 4; 7403 } 7404 printf("\n"); 7405 /* translate mask string to uint8_t array. */ 7406 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 7407 (mask_ptr[1] == 'X'))) 7408 mask_ptr += 2; 7409 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 7410 if (len == 0) { 7411 printf("invalid input\n"); 7412 return; 7413 } 7414 j = 0; 7415 byte = 0; 7416 for (i = 0; i < len; i++) { 7417 c = mask_ptr[i]; 7418 if (isxdigit(c) == 0) { 7419 /* invalid characters. */ 7420 printf("invalid input\n"); 7421 return; 7422 } 7423 val = xdigit2val(c); 7424 if (i % 2) { 7425 byte |= val; 7426 filter.mask[j] = byte; 7427 printf("mask[%d]:%02x ", j, filter.mask[j]); 7428 j++; 7429 byte = 0; 7430 } else 7431 byte |= val << 4; 7432 } 7433 printf("\n"); 7434 7435 if (!strcmp(res->ops, "add")) 7436 ret = rte_eth_dev_filter_ctrl(res->port_id, 7437 RTE_ETH_FILTER_FLEXIBLE, 7438 RTE_ETH_FILTER_ADD, 7439 &filter); 7440 else 7441 ret = rte_eth_dev_filter_ctrl(res->port_id, 7442 RTE_ETH_FILTER_FLEXIBLE, 7443 RTE_ETH_FILTER_DELETE, 7444 &filter); 7445 7446 if (ret < 0) 7447 printf("flex filter setting error: (%s)\n", strerror(-ret)); 7448 } 7449 7450 cmdline_parse_token_string_t cmd_flex_filter_filter = 7451 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7452 filter, "flex_filter"); 7453 cmdline_parse_token_num_t cmd_flex_filter_port_id = 7454 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 7455 port_id, UINT8); 7456 cmdline_parse_token_string_t cmd_flex_filter_ops = 7457 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7458 ops, "add#del"); 7459 cmdline_parse_token_string_t cmd_flex_filter_len = 7460 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7461 len, "len"); 7462 cmdline_parse_token_num_t cmd_flex_filter_len_value = 7463 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 7464 len_value, UINT8); 7465 cmdline_parse_token_string_t cmd_flex_filter_bytes = 7466 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7467 bytes, "bytes"); 7468 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 7469 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7470 bytes_value, NULL); 7471 cmdline_parse_token_string_t cmd_flex_filter_mask = 7472 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7473 mask, "mask"); 7474 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 7475 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7476 mask_value, NULL); 7477 cmdline_parse_token_string_t cmd_flex_filter_priority = 7478 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7479 priority, "priority"); 7480 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 7481 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 7482 priority_value, UINT8); 7483 cmdline_parse_token_string_t cmd_flex_filter_queue = 7484 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 7485 queue, "queue"); 7486 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 7487 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 7488 queue_id, UINT16); 7489 cmdline_parse_inst_t cmd_flex_filter = { 7490 .f = cmd_flex_filter_parsed, 7491 .data = NULL, 7492 .help_str = "add/del a flex filter", 7493 .tokens = { 7494 (void *)&cmd_flex_filter_filter, 7495 (void *)&cmd_flex_filter_port_id, 7496 (void *)&cmd_flex_filter_ops, 7497 (void *)&cmd_flex_filter_len, 7498 (void *)&cmd_flex_filter_len_value, 7499 (void *)&cmd_flex_filter_bytes, 7500 (void *)&cmd_flex_filter_bytes_value, 7501 (void *)&cmd_flex_filter_mask, 7502 (void *)&cmd_flex_filter_mask_value, 7503 (void *)&cmd_flex_filter_priority, 7504 (void *)&cmd_flex_filter_priority_value, 7505 (void *)&cmd_flex_filter_queue, 7506 (void *)&cmd_flex_filter_queue_id, 7507 NULL, 7508 }, 7509 }; 7510 7511 /* *** Filters Control *** */ 7512 7513 /* *** deal with ethertype filter *** */ 7514 struct cmd_ethertype_filter_result { 7515 cmdline_fixed_string_t filter; 7516 uint8_t port_id; 7517 cmdline_fixed_string_t ops; 7518 cmdline_fixed_string_t mac; 7519 struct ether_addr mac_addr; 7520 cmdline_fixed_string_t ethertype; 7521 uint16_t ethertype_value; 7522 cmdline_fixed_string_t drop; 7523 cmdline_fixed_string_t queue; 7524 uint16_t queue_id; 7525 }; 7526 7527 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 7528 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7529 filter, "ethertype_filter"); 7530 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 7531 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 7532 port_id, UINT8); 7533 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 7534 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7535 ops, "add#del"); 7536 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 7537 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7538 mac, "mac_addr#mac_ignr"); 7539 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 7540 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 7541 mac_addr); 7542 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 7543 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7544 ethertype, "ethertype"); 7545 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 7546 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 7547 ethertype_value, UINT16); 7548 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 7549 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7550 drop, "drop#fwd"); 7551 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 7552 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 7553 queue, "queue"); 7554 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 7555 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 7556 queue_id, UINT16); 7557 7558 static void 7559 cmd_ethertype_filter_parsed(void *parsed_result, 7560 __attribute__((unused)) struct cmdline *cl, 7561 __attribute__((unused)) void *data) 7562 { 7563 struct cmd_ethertype_filter_result *res = parsed_result; 7564 struct rte_eth_ethertype_filter filter; 7565 int ret = 0; 7566 7567 ret = rte_eth_dev_filter_supported(res->port_id, 7568 RTE_ETH_FILTER_ETHERTYPE); 7569 if (ret < 0) { 7570 printf("ethertype filter is not supported on port %u.\n", 7571 res->port_id); 7572 return; 7573 } 7574 7575 memset(&filter, 0, sizeof(filter)); 7576 if (!strcmp(res->mac, "mac_addr")) { 7577 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 7578 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr, 7579 sizeof(struct ether_addr)); 7580 } 7581 if (!strcmp(res->drop, "drop")) 7582 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 7583 filter.ether_type = res->ethertype_value; 7584 filter.queue = res->queue_id; 7585 7586 if (!strcmp(res->ops, "add")) 7587 ret = rte_eth_dev_filter_ctrl(res->port_id, 7588 RTE_ETH_FILTER_ETHERTYPE, 7589 RTE_ETH_FILTER_ADD, 7590 &filter); 7591 else 7592 ret = rte_eth_dev_filter_ctrl(res->port_id, 7593 RTE_ETH_FILTER_ETHERTYPE, 7594 RTE_ETH_FILTER_DELETE, 7595 &filter); 7596 if (ret < 0) 7597 printf("ethertype filter programming error: (%s)\n", 7598 strerror(-ret)); 7599 } 7600 7601 cmdline_parse_inst_t cmd_ethertype_filter = { 7602 .f = cmd_ethertype_filter_parsed, 7603 .data = NULL, 7604 .help_str = "add or delete an ethertype filter entry", 7605 .tokens = { 7606 (void *)&cmd_ethertype_filter_filter, 7607 (void *)&cmd_ethertype_filter_port_id, 7608 (void *)&cmd_ethertype_filter_ops, 7609 (void *)&cmd_ethertype_filter_mac, 7610 (void *)&cmd_ethertype_filter_mac_addr, 7611 (void *)&cmd_ethertype_filter_ethertype, 7612 (void *)&cmd_ethertype_filter_ethertype_value, 7613 (void *)&cmd_ethertype_filter_drop, 7614 (void *)&cmd_ethertype_filter_queue, 7615 (void *)&cmd_ethertype_filter_queue_id, 7616 NULL, 7617 }, 7618 }; 7619 7620 /* *** deal with flow director filter *** */ 7621 struct cmd_flow_director_result { 7622 cmdline_fixed_string_t flow_director_filter; 7623 uint8_t port_id; 7624 cmdline_fixed_string_t ops; 7625 cmdline_fixed_string_t flow; 7626 cmdline_fixed_string_t flow_type; 7627 cmdline_fixed_string_t src; 7628 cmdline_ipaddr_t ip_src; 7629 uint16_t port_src; 7630 cmdline_fixed_string_t dst; 7631 cmdline_ipaddr_t ip_dst; 7632 uint16_t port_dst; 7633 cmdline_fixed_string_t verify_tag; 7634 uint32_t verify_tag_value; 7635 cmdline_fixed_string_t vlan; 7636 uint16_t vlan_value; 7637 cmdline_fixed_string_t flexbytes; 7638 cmdline_fixed_string_t flexbytes_value; 7639 cmdline_fixed_string_t drop; 7640 cmdline_fixed_string_t queue; 7641 uint16_t queue_id; 7642 cmdline_fixed_string_t fd_id; 7643 uint32_t fd_id_value; 7644 }; 7645 7646 static inline int 7647 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 7648 { 7649 char s[256]; 7650 const char *p, *p0 = q_arg; 7651 char *end; 7652 unsigned long int_fld; 7653 char *str_fld[max_num]; 7654 int i; 7655 unsigned size; 7656 int ret = -1; 7657 7658 p = strchr(p0, '('); 7659 if (p == NULL) 7660 return -1; 7661 ++p; 7662 p0 = strchr(p, ')'); 7663 if (p0 == NULL) 7664 return -1; 7665 7666 size = p0 - p; 7667 if (size >= sizeof(s)) 7668 return -1; 7669 7670 snprintf(s, sizeof(s), "%.*s", size, p); 7671 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 7672 if (ret < 0 || ret > max_num) 7673 return -1; 7674 for (i = 0; i < ret; i++) { 7675 errno = 0; 7676 int_fld = strtoul(str_fld[i], &end, 0); 7677 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 7678 return -1; 7679 flexbytes[i] = (uint8_t)int_fld; 7680 } 7681 return ret; 7682 } 7683 7684 static uint16_t 7685 str2flowtype(char *string) 7686 { 7687 uint8_t i = 0; 7688 static const struct { 7689 char str[32]; 7690 uint16_t type; 7691 } flowtype_str[] = { 7692 {"raw", RTE_ETH_FLOW_RAW}, 7693 {"ipv4", RTE_ETH_FLOW_IPV4}, 7694 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 7695 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 7696 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 7697 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 7698 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 7699 {"ipv6", RTE_ETH_FLOW_IPV6}, 7700 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 7701 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 7702 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 7703 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 7704 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 7705 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 7706 }; 7707 7708 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 7709 if (!strcmp(flowtype_str[i].str, string)) 7710 return flowtype_str[i].type; 7711 } 7712 return RTE_ETH_FLOW_UNKNOWN; 7713 } 7714 7715 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 7716 do { \ 7717 if ((ip_addr).family == AF_INET) \ 7718 (ip) = (ip_addr).addr.ipv4.s_addr; \ 7719 else { \ 7720 printf("invalid parameter.\n"); \ 7721 return; \ 7722 } \ 7723 } while (0) 7724 7725 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 7726 do { \ 7727 if ((ip_addr).family == AF_INET6) \ 7728 (void)rte_memcpy(&(ip), \ 7729 &((ip_addr).addr.ipv6), \ 7730 sizeof(struct in6_addr)); \ 7731 else { \ 7732 printf("invalid parameter.\n"); \ 7733 return; \ 7734 } \ 7735 } while (0) 7736 7737 static void 7738 cmd_flow_director_filter_parsed(void *parsed_result, 7739 __attribute__((unused)) struct cmdline *cl, 7740 __attribute__((unused)) void *data) 7741 { 7742 struct cmd_flow_director_result *res = parsed_result; 7743 struct rte_eth_fdir_filter entry; 7744 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 7745 int ret = 0; 7746 7747 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 7748 if (ret < 0) { 7749 printf("flow director is not supported on port %u.\n", 7750 res->port_id); 7751 return; 7752 } 7753 memset(flexbytes, 0, sizeof(flexbytes)); 7754 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 7755 ret = parse_flexbytes(res->flexbytes_value, 7756 flexbytes, 7757 RTE_ETH_FDIR_MAX_FLEXLEN); 7758 if (ret < 0) { 7759 printf("error: Cannot parse flexbytes input.\n"); 7760 return; 7761 } 7762 7763 entry.input.flow_type = str2flowtype(res->flow_type); 7764 switch (entry.input.flow_type) { 7765 case RTE_ETH_FLOW_FRAG_IPV4: 7766 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 7767 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 7768 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 7769 IPV4_ADDR_TO_UINT(res->ip_dst, 7770 entry.input.flow.ip4_flow.dst_ip); 7771 IPV4_ADDR_TO_UINT(res->ip_src, 7772 entry.input.flow.ip4_flow.src_ip); 7773 /* need convert to big endian. */ 7774 entry.input.flow.udp4_flow.dst_port = 7775 rte_cpu_to_be_16(res->port_dst); 7776 entry.input.flow.udp4_flow.src_port = 7777 rte_cpu_to_be_16(res->port_src); 7778 break; 7779 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 7780 IPV4_ADDR_TO_UINT(res->ip_dst, 7781 entry.input.flow.sctp4_flow.ip.dst_ip); 7782 IPV4_ADDR_TO_UINT(res->ip_src, 7783 entry.input.flow.sctp4_flow.ip.src_ip); 7784 /* need convert to big endian. */ 7785 entry.input.flow.sctp4_flow.verify_tag = 7786 rte_cpu_to_be_32(res->verify_tag_value); 7787 break; 7788 case RTE_ETH_FLOW_FRAG_IPV6: 7789 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 7790 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 7791 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 7792 IPV6_ADDR_TO_ARRAY(res->ip_dst, 7793 entry.input.flow.ipv6_flow.dst_ip); 7794 IPV6_ADDR_TO_ARRAY(res->ip_src, 7795 entry.input.flow.ipv6_flow.src_ip); 7796 /* need convert to big endian. */ 7797 entry.input.flow.udp6_flow.dst_port = 7798 rte_cpu_to_be_16(res->port_dst); 7799 entry.input.flow.udp6_flow.src_port = 7800 rte_cpu_to_be_16(res->port_src); 7801 break; 7802 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 7803 IPV6_ADDR_TO_ARRAY(res->ip_dst, 7804 entry.input.flow.sctp6_flow.ip.dst_ip); 7805 IPV6_ADDR_TO_ARRAY(res->ip_src, 7806 entry.input.flow.sctp6_flow.ip.src_ip); 7807 /* need convert to big endian. */ 7808 entry.input.flow.sctp6_flow.verify_tag = 7809 rte_cpu_to_be_32(res->verify_tag_value); 7810 break; 7811 default: 7812 printf("invalid parameter.\n"); 7813 return; 7814 } 7815 (void)rte_memcpy(entry.input.flow_ext.flexbytes, 7816 flexbytes, 7817 RTE_ETH_FDIR_MAX_FLEXLEN); 7818 7819 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 7820 7821 entry.action.flex_off = 0; /*use 0 by default */ 7822 if (!strcmp(res->drop, "drop")) 7823 entry.action.behavior = RTE_ETH_FDIR_REJECT; 7824 else 7825 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 7826 /* set to report FD ID by default */ 7827 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 7828 entry.action.rx_queue = res->queue_id; 7829 entry.soft_id = res->fd_id_value; 7830 if (!strcmp(res->ops, "add")) 7831 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 7832 RTE_ETH_FILTER_ADD, &entry); 7833 else if (!strcmp(res->ops, "del")) 7834 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 7835 RTE_ETH_FILTER_DELETE, &entry); 7836 else 7837 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 7838 RTE_ETH_FILTER_UPDATE, &entry); 7839 if (ret < 0) 7840 printf("flow director programming error: (%s)\n", 7841 strerror(-ret)); 7842 } 7843 7844 cmdline_parse_token_string_t cmd_flow_director_filter = 7845 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7846 flow_director_filter, "flow_director_filter"); 7847 cmdline_parse_token_num_t cmd_flow_director_port_id = 7848 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7849 port_id, UINT8); 7850 cmdline_parse_token_string_t cmd_flow_director_ops = 7851 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7852 ops, "add#del#update"); 7853 cmdline_parse_token_string_t cmd_flow_director_flow = 7854 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7855 flow, "flow"); 7856 cmdline_parse_token_string_t cmd_flow_director_flow_type = 7857 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7858 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 7859 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp"); 7860 cmdline_parse_token_string_t cmd_flow_director_src = 7861 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7862 src, "src"); 7863 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 7864 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 7865 ip_src); 7866 cmdline_parse_token_num_t cmd_flow_director_port_src = 7867 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7868 port_src, UINT16); 7869 cmdline_parse_token_string_t cmd_flow_director_dst = 7870 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7871 dst, "dst"); 7872 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 7873 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 7874 ip_dst); 7875 cmdline_parse_token_num_t cmd_flow_director_port_dst = 7876 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7877 port_dst, UINT16); 7878 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 7879 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7880 verify_tag, "verify_tag"); 7881 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 7882 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7883 verify_tag_value, UINT32); 7884 cmdline_parse_token_string_t cmd_flow_director_vlan = 7885 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7886 vlan, "vlan"); 7887 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 7888 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7889 vlan_value, UINT16); 7890 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 7891 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7892 flexbytes, "flexbytes"); 7893 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 7894 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7895 flexbytes_value, NULL); 7896 cmdline_parse_token_string_t cmd_flow_director_drop = 7897 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7898 drop, "drop#fwd"); 7899 cmdline_parse_token_string_t cmd_flow_director_queue = 7900 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7901 queue, "queue"); 7902 cmdline_parse_token_num_t cmd_flow_director_queue_id = 7903 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7904 queue_id, UINT16); 7905 cmdline_parse_token_string_t cmd_flow_director_fd_id = 7906 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 7907 fd_id, "fd_id"); 7908 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 7909 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 7910 fd_id_value, UINT32); 7911 7912 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 7913 .f = cmd_flow_director_filter_parsed, 7914 .data = NULL, 7915 .help_str = "add or delete an ip flow director entry on NIC", 7916 .tokens = { 7917 (void *)&cmd_flow_director_filter, 7918 (void *)&cmd_flow_director_port_id, 7919 (void *)&cmd_flow_director_ops, 7920 (void *)&cmd_flow_director_flow, 7921 (void *)&cmd_flow_director_flow_type, 7922 (void *)&cmd_flow_director_src, 7923 (void *)&cmd_flow_director_ip_src, 7924 (void *)&cmd_flow_director_dst, 7925 (void *)&cmd_flow_director_ip_dst, 7926 (void *)&cmd_flow_director_vlan, 7927 (void *)&cmd_flow_director_vlan_value, 7928 (void *)&cmd_flow_director_flexbytes, 7929 (void *)&cmd_flow_director_flexbytes_value, 7930 (void *)&cmd_flow_director_drop, 7931 (void *)&cmd_flow_director_queue, 7932 (void *)&cmd_flow_director_queue_id, 7933 (void *)&cmd_flow_director_fd_id, 7934 (void *)&cmd_flow_director_fd_id_value, 7935 NULL, 7936 }, 7937 }; 7938 7939 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 7940 .f = cmd_flow_director_filter_parsed, 7941 .data = NULL, 7942 .help_str = "add or delete an udp/tcp flow director entry on NIC", 7943 .tokens = { 7944 (void *)&cmd_flow_director_filter, 7945 (void *)&cmd_flow_director_port_id, 7946 (void *)&cmd_flow_director_ops, 7947 (void *)&cmd_flow_director_flow, 7948 (void *)&cmd_flow_director_flow_type, 7949 (void *)&cmd_flow_director_src, 7950 (void *)&cmd_flow_director_ip_src, 7951 (void *)&cmd_flow_director_port_src, 7952 (void *)&cmd_flow_director_dst, 7953 (void *)&cmd_flow_director_ip_dst, 7954 (void *)&cmd_flow_director_port_dst, 7955 (void *)&cmd_flow_director_vlan, 7956 (void *)&cmd_flow_director_vlan_value, 7957 (void *)&cmd_flow_director_flexbytes, 7958 (void *)&cmd_flow_director_flexbytes_value, 7959 (void *)&cmd_flow_director_drop, 7960 (void *)&cmd_flow_director_queue, 7961 (void *)&cmd_flow_director_queue_id, 7962 (void *)&cmd_flow_director_fd_id, 7963 (void *)&cmd_flow_director_fd_id_value, 7964 NULL, 7965 }, 7966 }; 7967 7968 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 7969 .f = cmd_flow_director_filter_parsed, 7970 .data = NULL, 7971 .help_str = "add or delete a sctp flow director entry on NIC", 7972 .tokens = { 7973 (void *)&cmd_flow_director_filter, 7974 (void *)&cmd_flow_director_port_id, 7975 (void *)&cmd_flow_director_ops, 7976 (void *)&cmd_flow_director_flow, 7977 (void *)&cmd_flow_director_flow_type, 7978 (void *)&cmd_flow_director_src, 7979 (void *)&cmd_flow_director_ip_src, 7980 (void *)&cmd_flow_director_port_dst, 7981 (void *)&cmd_flow_director_dst, 7982 (void *)&cmd_flow_director_ip_dst, 7983 (void *)&cmd_flow_director_port_dst, 7984 (void *)&cmd_flow_director_verify_tag, 7985 (void *)&cmd_flow_director_verify_tag_value, 7986 (void *)&cmd_flow_director_vlan, 7987 (void *)&cmd_flow_director_vlan_value, 7988 (void *)&cmd_flow_director_flexbytes, 7989 (void *)&cmd_flow_director_flexbytes_value, 7990 (void *)&cmd_flow_director_drop, 7991 (void *)&cmd_flow_director_queue, 7992 (void *)&cmd_flow_director_queue_id, 7993 (void *)&cmd_flow_director_fd_id, 7994 (void *)&cmd_flow_director_fd_id_value, 7995 NULL, 7996 }, 7997 }; 7998 7999 struct cmd_flush_flow_director_result { 8000 cmdline_fixed_string_t flush_flow_director; 8001 uint8_t port_id; 8002 }; 8003 8004 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 8005 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 8006 flush_flow_director, "flush_flow_director"); 8007 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 8008 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 8009 port_id, UINT8); 8010 8011 static void 8012 cmd_flush_flow_director_parsed(void *parsed_result, 8013 __attribute__((unused)) struct cmdline *cl, 8014 __attribute__((unused)) void *data) 8015 { 8016 struct cmd_flow_director_result *res = parsed_result; 8017 int ret = 0; 8018 8019 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 8020 if (ret < 0) { 8021 printf("flow director is not supported on port %u.\n", 8022 res->port_id); 8023 return; 8024 } 8025 8026 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8027 RTE_ETH_FILTER_FLUSH, NULL); 8028 if (ret < 0) 8029 printf("flow director table flushing error: (%s)\n", 8030 strerror(-ret)); 8031 } 8032 8033 cmdline_parse_inst_t cmd_flush_flow_director = { 8034 .f = cmd_flush_flow_director_parsed, 8035 .data = NULL, 8036 .help_str = "flush all flow director entries of a device on NIC", 8037 .tokens = { 8038 (void *)&cmd_flush_flow_director_flush, 8039 (void *)&cmd_flush_flow_director_port_id, 8040 NULL, 8041 }, 8042 }; 8043 8044 /* *** deal with flow director mask *** */ 8045 struct cmd_flow_director_mask_result { 8046 cmdline_fixed_string_t flow_director_mask; 8047 uint8_t port_id; 8048 cmdline_fixed_string_t vlan; 8049 uint16_t vlan_value; 8050 cmdline_fixed_string_t src_mask; 8051 cmdline_ipaddr_t ipv4_src; 8052 cmdline_ipaddr_t ipv6_src; 8053 uint16_t port_src; 8054 cmdline_fixed_string_t dst_mask; 8055 cmdline_ipaddr_t ipv4_dst; 8056 cmdline_ipaddr_t ipv6_dst; 8057 uint16_t port_dst; 8058 }; 8059 8060 static void 8061 cmd_flow_director_mask_parsed(void *parsed_result, 8062 __attribute__((unused)) struct cmdline *cl, 8063 __attribute__((unused)) void *data) 8064 { 8065 struct cmd_flow_director_mask_result *res = parsed_result; 8066 struct rte_eth_fdir_masks *mask; 8067 struct rte_port *port; 8068 8069 if (res->port_id > nb_ports) { 8070 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 8071 return; 8072 } 8073 8074 port = &ports[res->port_id]; 8075 /** Check if the port is not started **/ 8076 if (port->port_status != RTE_PORT_STOPPED) { 8077 printf("Please stop port %d first\n", res->port_id); 8078 return; 8079 } 8080 mask = &port->dev_conf.fdir_conf.mask; 8081 8082 mask->vlan_tci_mask = res->vlan_value; 8083 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 8084 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 8085 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 8086 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 8087 mask->src_port_mask = res->port_src; 8088 mask->dst_port_mask = res->port_dst; 8089 8090 cmd_reconfig_device_queue(res->port_id, 1, 1); 8091 } 8092 8093 cmdline_parse_token_string_t cmd_flow_director_mask = 8094 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 8095 flow_director_mask, "flow_director_mask"); 8096 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 8097 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 8098 port_id, UINT8); 8099 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 8100 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 8101 vlan, "vlan"); 8102 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 8103 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 8104 vlan_value, UINT16); 8105 cmdline_parse_token_string_t cmd_flow_director_mask_src = 8106 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 8107 src_mask, "src_mask"); 8108 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 8109 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 8110 ipv4_src); 8111 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 8112 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 8113 ipv6_src); 8114 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 8115 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 8116 port_src, UINT16); 8117 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 8118 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 8119 dst_mask, "dst_mask"); 8120 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 8121 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 8122 ipv4_dst); 8123 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 8124 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 8125 ipv6_dst); 8126 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 8127 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 8128 port_dst, UINT16); 8129 cmdline_parse_inst_t cmd_set_flow_director_mask = { 8130 .f = cmd_flow_director_mask_parsed, 8131 .data = NULL, 8132 .help_str = "set flow director's mask on NIC", 8133 .tokens = { 8134 (void *)&cmd_flow_director_mask, 8135 (void *)&cmd_flow_director_mask_port_id, 8136 (void *)&cmd_flow_director_mask_vlan, 8137 (void *)&cmd_flow_director_mask_vlan_value, 8138 (void *)&cmd_flow_director_mask_src, 8139 (void *)&cmd_flow_director_mask_ipv4_src, 8140 (void *)&cmd_flow_director_mask_ipv6_src, 8141 (void *)&cmd_flow_director_mask_port_src, 8142 (void *)&cmd_flow_director_mask_dst, 8143 (void *)&cmd_flow_director_mask_ipv4_dst, 8144 (void *)&cmd_flow_director_mask_ipv6_dst, 8145 (void *)&cmd_flow_director_mask_port_dst, 8146 NULL, 8147 }, 8148 }; 8149 8150 /* *** deal with flow director mask on flexible payload *** */ 8151 struct cmd_flow_director_flex_mask_result { 8152 cmdline_fixed_string_t flow_director_flexmask; 8153 uint8_t port_id; 8154 cmdline_fixed_string_t flow; 8155 cmdline_fixed_string_t flow_type; 8156 cmdline_fixed_string_t mask; 8157 }; 8158 8159 static void 8160 cmd_flow_director_flex_mask_parsed(void *parsed_result, 8161 __attribute__((unused)) struct cmdline *cl, 8162 __attribute__((unused)) void *data) 8163 { 8164 struct cmd_flow_director_flex_mask_result *res = parsed_result; 8165 struct rte_eth_fdir_info fdir_info; 8166 struct rte_eth_fdir_flex_mask flex_mask; 8167 struct rte_port *port; 8168 uint32_t flow_type_mask; 8169 uint16_t i; 8170 int ret; 8171 8172 if (res->port_id > nb_ports) { 8173 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 8174 return; 8175 } 8176 8177 port = &ports[res->port_id]; 8178 /** Check if the port is not started **/ 8179 if (port->port_status != RTE_PORT_STOPPED) { 8180 printf("Please stop port %d first\n", res->port_id); 8181 return; 8182 } 8183 8184 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 8185 ret = parse_flexbytes(res->mask, 8186 flex_mask.mask, 8187 RTE_ETH_FDIR_MAX_FLEXLEN); 8188 if (ret < 0) { 8189 printf("error: Cannot parse mask input.\n"); 8190 return; 8191 } 8192 8193 memset(&fdir_info, 0, sizeof(fdir_info)); 8194 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8195 RTE_ETH_FILTER_INFO, &fdir_info); 8196 if (ret < 0) { 8197 printf("Cannot get FDir filter info\n"); 8198 return; 8199 } 8200 8201 flow_type_mask = fdir_info.flow_types_mask[0]; 8202 if (!strcmp(res->flow_type, "all")) { 8203 if (!flow_type_mask) { 8204 printf("No flow type supported\n"); 8205 return; 8206 } 8207 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 8208 if (flow_type_mask & (1 << i)) { 8209 flex_mask.flow_type = i; 8210 fdir_set_flex_mask(res->port_id, &flex_mask); 8211 } 8212 } 8213 cmd_reconfig_device_queue(res->port_id, 1, 1); 8214 return; 8215 } 8216 flex_mask.flow_type = str2flowtype(res->flow_type); 8217 if (!(flow_type_mask & (1 << flex_mask.flow_type))) { 8218 printf("Flow type %s not supported on port %d\n", 8219 res->flow_type, res->port_id); 8220 return; 8221 } 8222 fdir_set_flex_mask(res->port_id, &flex_mask); 8223 cmd_reconfig_device_queue(res->port_id, 1, 1); 8224 } 8225 8226 cmdline_parse_token_string_t cmd_flow_director_flexmask = 8227 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 8228 flow_director_flexmask, 8229 "flow_director_flex_mask"); 8230 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 8231 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 8232 port_id, UINT8); 8233 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 8234 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 8235 flow, "flow"); 8236 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 8237 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 8238 flow_type, "raw#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 8239 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#all"); 8240 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 8241 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 8242 mask, NULL); 8243 8244 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 8245 .f = cmd_flow_director_flex_mask_parsed, 8246 .data = NULL, 8247 .help_str = "set flow director's flex mask on NIC", 8248 .tokens = { 8249 (void *)&cmd_flow_director_flexmask, 8250 (void *)&cmd_flow_director_flexmask_port_id, 8251 (void *)&cmd_flow_director_flexmask_flow, 8252 (void *)&cmd_flow_director_flexmask_flow_type, 8253 (void *)&cmd_flow_director_flexmask_mask, 8254 NULL, 8255 }, 8256 }; 8257 8258 /* *** deal with flow director flexible payload configuration *** */ 8259 struct cmd_flow_director_flexpayload_result { 8260 cmdline_fixed_string_t flow_director_flexpayload; 8261 uint8_t port_id; 8262 cmdline_fixed_string_t payload_layer; 8263 cmdline_fixed_string_t payload_cfg; 8264 }; 8265 8266 static inline int 8267 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 8268 { 8269 char s[256]; 8270 const char *p, *p0 = q_arg; 8271 char *end; 8272 unsigned long int_fld; 8273 char *str_fld[max_num]; 8274 int i; 8275 unsigned size; 8276 int ret = -1; 8277 8278 p = strchr(p0, '('); 8279 if (p == NULL) 8280 return -1; 8281 ++p; 8282 p0 = strchr(p, ')'); 8283 if (p0 == NULL) 8284 return -1; 8285 8286 size = p0 - p; 8287 if (size >= sizeof(s)) 8288 return -1; 8289 8290 snprintf(s, sizeof(s), "%.*s", size, p); 8291 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 8292 if (ret < 0 || ret > max_num) 8293 return -1; 8294 for (i = 0; i < ret; i++) { 8295 errno = 0; 8296 int_fld = strtoul(str_fld[i], &end, 0); 8297 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 8298 return -1; 8299 offsets[i] = (uint16_t)int_fld; 8300 } 8301 return ret; 8302 } 8303 8304 static void 8305 cmd_flow_director_flxpld_parsed(void *parsed_result, 8306 __attribute__((unused)) struct cmdline *cl, 8307 __attribute__((unused)) void *data) 8308 { 8309 struct cmd_flow_director_flexpayload_result *res = parsed_result; 8310 struct rte_eth_flex_payload_cfg flex_cfg; 8311 struct rte_port *port; 8312 int ret = 0; 8313 8314 if (res->port_id > nb_ports) { 8315 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 8316 return; 8317 } 8318 8319 port = &ports[res->port_id]; 8320 /** Check if the port is not started **/ 8321 if (port->port_status != RTE_PORT_STOPPED) { 8322 printf("Please stop port %d first\n", res->port_id); 8323 return; 8324 } 8325 8326 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 8327 8328 if (!strcmp(res->payload_layer, "raw")) 8329 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 8330 else if (!strcmp(res->payload_layer, "l2")) 8331 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 8332 else if (!strcmp(res->payload_layer, "l3")) 8333 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 8334 else if (!strcmp(res->payload_layer, "l4")) 8335 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 8336 8337 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 8338 RTE_ETH_FDIR_MAX_FLEXLEN); 8339 if (ret < 0) { 8340 printf("error: Cannot parse flex payload input.\n"); 8341 return; 8342 } 8343 8344 fdir_set_flex_payload(res->port_id, &flex_cfg); 8345 cmd_reconfig_device_queue(res->port_id, 1, 1); 8346 } 8347 8348 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 8349 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 8350 flow_director_flexpayload, 8351 "flow_director_flex_payload"); 8352 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 8353 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 8354 port_id, UINT8); 8355 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 8356 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 8357 payload_layer, "raw#l2#l3#l4"); 8358 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 8359 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 8360 payload_cfg, NULL); 8361 8362 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 8363 .f = cmd_flow_director_flxpld_parsed, 8364 .data = NULL, 8365 .help_str = "set flow director's flex payload on NIC", 8366 .tokens = { 8367 (void *)&cmd_flow_director_flexpayload, 8368 (void *)&cmd_flow_director_flexpayload_port_id, 8369 (void *)&cmd_flow_director_flexpayload_payload_layer, 8370 (void *)&cmd_flow_director_flexpayload_payload_cfg, 8371 NULL, 8372 }, 8373 }; 8374 8375 /* *** Classification Filters Control *** */ 8376 /* *** Get symmetric hash enable per port *** */ 8377 struct cmd_get_sym_hash_ena_per_port_result { 8378 cmdline_fixed_string_t get_sym_hash_ena_per_port; 8379 uint8_t port_id; 8380 }; 8381 8382 static void 8383 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 8384 __rte_unused struct cmdline *cl, 8385 __rte_unused void *data) 8386 { 8387 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 8388 struct rte_eth_hash_filter_info info; 8389 int ret; 8390 8391 if (rte_eth_dev_filter_supported(res->port_id, 8392 RTE_ETH_FILTER_HASH) < 0) { 8393 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 8394 res->port_id); 8395 return; 8396 } 8397 8398 memset(&info, 0, sizeof(info)); 8399 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 8400 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 8401 RTE_ETH_FILTER_GET, &info); 8402 8403 if (ret < 0) { 8404 printf("Cannot get symmetric hash enable per port " 8405 "on port %u\n", res->port_id); 8406 return; 8407 } 8408 8409 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 8410 "enabled" : "disabled", res->port_id); 8411 } 8412 8413 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 8414 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 8415 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 8416 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 8417 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 8418 port_id, UINT8); 8419 8420 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 8421 .f = cmd_get_sym_hash_per_port_parsed, 8422 .data = NULL, 8423 .help_str = "get_sym_hash_ena_per_port port_id", 8424 .tokens = { 8425 (void *)&cmd_get_sym_hash_ena_per_port_all, 8426 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 8427 NULL, 8428 }, 8429 }; 8430 8431 /* *** Set symmetric hash enable per port *** */ 8432 struct cmd_set_sym_hash_ena_per_port_result { 8433 cmdline_fixed_string_t set_sym_hash_ena_per_port; 8434 cmdline_fixed_string_t enable; 8435 uint8_t port_id; 8436 }; 8437 8438 static void 8439 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 8440 __rte_unused struct cmdline *cl, 8441 __rte_unused void *data) 8442 { 8443 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 8444 struct rte_eth_hash_filter_info info; 8445 int ret; 8446 8447 if (rte_eth_dev_filter_supported(res->port_id, 8448 RTE_ETH_FILTER_HASH) < 0) { 8449 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 8450 res->port_id); 8451 return; 8452 } 8453 8454 memset(&info, 0, sizeof(info)); 8455 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 8456 if (!strcmp(res->enable, "enable")) 8457 info.info.enable = 1; 8458 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 8459 RTE_ETH_FILTER_SET, &info); 8460 if (ret < 0) { 8461 printf("Cannot set symmetric hash enable per port on " 8462 "port %u\n", res->port_id); 8463 return; 8464 } 8465 printf("Symmetric hash has been set to %s on port %u\n", 8466 res->enable, res->port_id); 8467 } 8468 8469 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 8470 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 8471 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 8472 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 8473 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 8474 port_id, UINT8); 8475 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 8476 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 8477 enable, "enable#disable"); 8478 8479 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 8480 .f = cmd_set_sym_hash_per_port_parsed, 8481 .data = NULL, 8482 .help_str = "set_sym_hash_ena_per_port port_id enable|disable", 8483 .tokens = { 8484 (void *)&cmd_set_sym_hash_ena_per_port_all, 8485 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 8486 (void *)&cmd_set_sym_hash_ena_per_port_enable, 8487 NULL, 8488 }, 8489 }; 8490 8491 /* Get global config of hash function */ 8492 struct cmd_get_hash_global_config_result { 8493 cmdline_fixed_string_t get_hash_global_config; 8494 uint8_t port_id; 8495 }; 8496 8497 static char * 8498 flowtype_to_str(uint16_t ftype) 8499 { 8500 uint16_t i; 8501 static struct { 8502 char str[16]; 8503 uint16_t ftype; 8504 } ftype_table[] = { 8505 {"ipv4", RTE_ETH_FLOW_IPV4}, 8506 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 8507 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 8508 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 8509 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 8510 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 8511 {"ipv6", RTE_ETH_FLOW_IPV6}, 8512 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 8513 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 8514 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 8515 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 8516 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 8517 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 8518 }; 8519 8520 for (i = 0; i < RTE_DIM(ftype_table); i++) { 8521 if (ftype_table[i].ftype == ftype) 8522 return ftype_table[i].str; 8523 } 8524 8525 return NULL; 8526 } 8527 8528 static void 8529 cmd_get_hash_global_config_parsed(void *parsed_result, 8530 __rte_unused struct cmdline *cl, 8531 __rte_unused void *data) 8532 { 8533 struct cmd_get_hash_global_config_result *res = parsed_result; 8534 struct rte_eth_hash_filter_info info; 8535 uint32_t idx, offset; 8536 uint16_t i; 8537 char *str; 8538 int ret; 8539 8540 if (rte_eth_dev_filter_supported(res->port_id, 8541 RTE_ETH_FILTER_HASH) < 0) { 8542 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 8543 res->port_id); 8544 return; 8545 } 8546 8547 memset(&info, 0, sizeof(info)); 8548 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 8549 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 8550 RTE_ETH_FILTER_GET, &info); 8551 if (ret < 0) { 8552 printf("Cannot get hash global configurations by port %d\n", 8553 res->port_id); 8554 return; 8555 } 8556 8557 switch (info.info.global_conf.hash_func) { 8558 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 8559 printf("Hash function is Toeplitz\n"); 8560 break; 8561 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 8562 printf("Hash function is Simple XOR\n"); 8563 break; 8564 default: 8565 printf("Unknown hash function\n"); 8566 break; 8567 } 8568 8569 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 8570 idx = i / UINT32_BIT; 8571 offset = i % UINT32_BIT; 8572 if (!(info.info.global_conf.valid_bit_mask[idx] & 8573 (1UL << offset))) 8574 continue; 8575 str = flowtype_to_str(i); 8576 if (!str) 8577 continue; 8578 printf("Symmetric hash is %s globally for flow type %s " 8579 "by port %d\n", 8580 ((info.info.global_conf.sym_hash_enable_mask[idx] & 8581 (1UL << offset)) ? "enabled" : "disabled"), str, 8582 res->port_id); 8583 } 8584 } 8585 8586 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 8587 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 8588 get_hash_global_config, "get_hash_global_config"); 8589 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 8590 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 8591 port_id, UINT8); 8592 8593 cmdline_parse_inst_t cmd_get_hash_global_config = { 8594 .f = cmd_get_hash_global_config_parsed, 8595 .data = NULL, 8596 .help_str = "get_hash_global_config port_id", 8597 .tokens = { 8598 (void *)&cmd_get_hash_global_config_all, 8599 (void *)&cmd_get_hash_global_config_port_id, 8600 NULL, 8601 }, 8602 }; 8603 8604 /* Set global config of hash function */ 8605 struct cmd_set_hash_global_config_result { 8606 cmdline_fixed_string_t set_hash_global_config; 8607 uint8_t port_id; 8608 cmdline_fixed_string_t hash_func; 8609 cmdline_fixed_string_t flow_type; 8610 cmdline_fixed_string_t enable; 8611 }; 8612 8613 static void 8614 cmd_set_hash_global_config_parsed(void *parsed_result, 8615 __rte_unused struct cmdline *cl, 8616 __rte_unused void *data) 8617 { 8618 struct cmd_set_hash_global_config_result *res = parsed_result; 8619 struct rte_eth_hash_filter_info info; 8620 uint32_t ftype, idx, offset; 8621 int ret; 8622 8623 if (rte_eth_dev_filter_supported(res->port_id, 8624 RTE_ETH_FILTER_HASH) < 0) { 8625 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 8626 res->port_id); 8627 return; 8628 } 8629 memset(&info, 0, sizeof(info)); 8630 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 8631 if (!strcmp(res->hash_func, "toeplitz")) 8632 info.info.global_conf.hash_func = 8633 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 8634 else if (!strcmp(res->hash_func, "simple_xor")) 8635 info.info.global_conf.hash_func = 8636 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 8637 else if (!strcmp(res->hash_func, "default")) 8638 info.info.global_conf.hash_func = 8639 RTE_ETH_HASH_FUNCTION_DEFAULT; 8640 8641 ftype = str2flowtype(res->flow_type); 8642 idx = ftype / (CHAR_BIT * sizeof(uint32_t)); 8643 offset = ftype % (CHAR_BIT * sizeof(uint32_t)); 8644 info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset); 8645 if (!strcmp(res->enable, "enable")) 8646 info.info.global_conf.sym_hash_enable_mask[idx] |= 8647 (1UL << offset); 8648 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 8649 RTE_ETH_FILTER_SET, &info); 8650 if (ret < 0) 8651 printf("Cannot set global hash configurations by port %d\n", 8652 res->port_id); 8653 else 8654 printf("Global hash configurations have been set " 8655 "succcessfully by port %d\n", res->port_id); 8656 } 8657 8658 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 8659 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 8660 set_hash_global_config, "set_hash_global_config"); 8661 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 8662 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 8663 port_id, UINT8); 8664 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 8665 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 8666 hash_func, "toeplitz#simple_xor#default"); 8667 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 8668 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 8669 flow_type, 8670 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 8671 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 8672 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 8673 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 8674 enable, "enable#disable"); 8675 8676 cmdline_parse_inst_t cmd_set_hash_global_config = { 8677 .f = cmd_set_hash_global_config_parsed, 8678 .data = NULL, 8679 .help_str = "set_hash_global_config port_id " 8680 "toeplitz|simple_xor|default " 8681 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 8682 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 8683 "enable|disable", 8684 .tokens = { 8685 (void *)&cmd_set_hash_global_config_all, 8686 (void *)&cmd_set_hash_global_config_port_id, 8687 (void *)&cmd_set_hash_global_config_hash_func, 8688 (void *)&cmd_set_hash_global_config_flow_type, 8689 (void *)&cmd_set_hash_global_config_enable, 8690 NULL, 8691 }, 8692 }; 8693 8694 /* ******************************************************************************** */ 8695 8696 /* list of instructions */ 8697 cmdline_parse_ctx_t main_ctx[] = { 8698 (cmdline_parse_inst_t *)&cmd_help_brief, 8699 (cmdline_parse_inst_t *)&cmd_help_long, 8700 (cmdline_parse_inst_t *)&cmd_quit, 8701 (cmdline_parse_inst_t *)&cmd_showport, 8702 (cmdline_parse_inst_t *)&cmd_showportall, 8703 (cmdline_parse_inst_t *)&cmd_showcfg, 8704 (cmdline_parse_inst_t *)&cmd_start, 8705 (cmdline_parse_inst_t *)&cmd_start_tx_first, 8706 (cmdline_parse_inst_t *)&cmd_set_link_up, 8707 (cmdline_parse_inst_t *)&cmd_set_link_down, 8708 (cmdline_parse_inst_t *)&cmd_reset, 8709 (cmdline_parse_inst_t *)&cmd_set_numbers, 8710 (cmdline_parse_inst_t *)&cmd_set_txpkts, 8711 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 8712 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 8713 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 8714 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 8715 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 8716 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 8717 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 8718 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 8719 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 8720 (cmdline_parse_inst_t *)&cmd_set_link_check, 8721 #ifdef RTE_NIC_BYPASS 8722 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 8723 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 8724 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 8725 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 8726 #endif 8727 #ifdef RTE_LIBRTE_PMD_BOND 8728 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 8729 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 8730 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 8731 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 8732 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 8733 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 8734 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 8735 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 8736 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 8737 #endif 8738 (cmdline_parse_inst_t *)&cmd_vlan_offload, 8739 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 8740 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 8741 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 8742 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 8743 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 8744 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 8745 (cmdline_parse_inst_t *)&cmd_csum_set, 8746 (cmdline_parse_inst_t *)&cmd_csum_show, 8747 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 8748 (cmdline_parse_inst_t *)&cmd_tso_set, 8749 (cmdline_parse_inst_t *)&cmd_tso_show, 8750 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 8751 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 8752 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 8753 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 8754 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 8755 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 8756 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 8757 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 8758 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 8759 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 8760 (cmdline_parse_inst_t *)&cmd_config_dcb, 8761 (cmdline_parse_inst_t *)&cmd_read_reg, 8762 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 8763 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 8764 (cmdline_parse_inst_t *)&cmd_write_reg, 8765 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 8766 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 8767 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 8768 (cmdline_parse_inst_t *)&cmd_stop, 8769 (cmdline_parse_inst_t *)&cmd_mac_addr, 8770 (cmdline_parse_inst_t *)&cmd_set_qmap, 8771 (cmdline_parse_inst_t *)&cmd_operate_port, 8772 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 8773 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 8774 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 8775 (cmdline_parse_inst_t *)&cmd_config_speed_all, 8776 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 8777 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 8778 (cmdline_parse_inst_t *)&cmd_config_mtu, 8779 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 8780 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 8781 (cmdline_parse_inst_t *)&cmd_config_rss, 8782 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 8783 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 8784 (cmdline_parse_inst_t *)&cmd_showport_reta, 8785 (cmdline_parse_inst_t *)&cmd_config_burst, 8786 (cmdline_parse_inst_t *)&cmd_config_thresh, 8787 (cmdline_parse_inst_t *)&cmd_config_threshold, 8788 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 8789 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 8790 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 8791 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 8792 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 8793 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 8794 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 8795 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 8796 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 8797 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 8798 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 8799 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 8800 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 8801 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 8802 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 8803 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 8804 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 8805 (cmdline_parse_inst_t *)&cmd_dump, 8806 (cmdline_parse_inst_t *)&cmd_dump_one, 8807 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 8808 (cmdline_parse_inst_t *)&cmd_syn_filter, 8809 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 8810 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 8811 (cmdline_parse_inst_t *)&cmd_flex_filter, 8812 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 8813 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 8814 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 8815 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 8816 (cmdline_parse_inst_t *)&cmd_set_flow_director_mask, 8817 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 8818 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 8819 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 8820 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 8821 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 8822 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 8823 NULL, 8824 }; 8825 8826 /* prompt function, called from main on MASTER lcore */ 8827 void 8828 prompt(void) 8829 { 8830 struct cmdline *cl; 8831 8832 /* initialize non-constant commands */ 8833 cmd_set_fwd_mode_init(); 8834 8835 cl = cmdline_stdin_new(main_ctx, "testpmd> "); 8836 if (cl == NULL) { 8837 return; 8838 } 8839 cmdline_interact(cl); 8840 cmdline_stdin_exit(cl); 8841 } 8842 8843 static void 8844 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 8845 { 8846 if (!port_id_is_invalid(id, DISABLED_WARN)) { 8847 /* check if need_reconfig has been set to 1 */ 8848 if (ports[id].need_reconfig == 0) 8849 ports[id].need_reconfig = dev; 8850 /* check if need_reconfig_queues has been set to 1 */ 8851 if (ports[id].need_reconfig_queues == 0) 8852 ports[id].need_reconfig_queues = queue; 8853 } else { 8854 portid_t pid; 8855 8856 FOREACH_PORT(pid, ports) { 8857 /* check if need_reconfig has been set to 1 */ 8858 if (ports[pid].need_reconfig == 0) 8859 ports[pid].need_reconfig = dev; 8860 /* check if need_reconfig_queues has been set to 1 */ 8861 if (ports[pid].need_reconfig_queues == 0) 8862 ports[pid].need_reconfig_queues = queue; 8863 } 8864 } 8865 } 8866 8867 #ifdef RTE_NIC_BYPASS 8868 uint8_t 8869 bypass_is_supported(portid_t port_id) 8870 { 8871 struct rte_port *port; 8872 struct rte_pci_id *pci_id; 8873 8874 if (port_id_is_invalid(port_id, ENABLED_WARN)) 8875 return 0; 8876 8877 /* Get the device id. */ 8878 port = &ports[port_id]; 8879 pci_id = &port->dev_info.pci_dev->id; 8880 8881 /* Check if NIC supports bypass. */ 8882 if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) { 8883 return 1; 8884 } 8885 else { 8886 printf("\tBypass not supported for port_id = %d.\n", port_id); 8887 return 0; 8888 } 8889 } 8890 #endif 8891