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