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 #include <rte_flow.h> 79 80 #include <cmdline_rdline.h> 81 #include <cmdline_parse.h> 82 #include <cmdline_parse_num.h> 83 #include <cmdline_parse_string.h> 84 #include <cmdline_parse_ipaddr.h> 85 #include <cmdline_parse_etheraddr.h> 86 #include <cmdline_socket.h> 87 #include <cmdline.h> 88 #ifdef RTE_LIBRTE_PMD_BOND 89 #include <rte_eth_bond.h> 90 #endif 91 #ifdef RTE_LIBRTE_IXGBE_PMD 92 #include <rte_pmd_ixgbe.h> 93 #endif 94 #ifdef RTE_LIBRTE_I40E_PMD 95 #include <rte_pmd_i40e.h> 96 #endif 97 #include "testpmd.h" 98 99 static struct cmdline *testpmd_cl; 100 101 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 102 103 /* *** Help command with introduction. *** */ 104 struct cmd_help_brief_result { 105 cmdline_fixed_string_t help; 106 }; 107 108 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 109 struct cmdline *cl, 110 __attribute__((unused)) void *data) 111 { 112 cmdline_printf( 113 cl, 114 "\n" 115 "Help is available for the following sections:\n\n" 116 " help control : Start and stop forwarding.\n" 117 " help display : Displaying port, stats and config " 118 "information.\n" 119 " help config : Configuration information.\n" 120 " help ports : Configuring ports.\n" 121 " help registers : Reading and setting port registers.\n" 122 " help filters : Filters configuration help.\n" 123 " help all : All of the above sections.\n\n" 124 ); 125 126 } 127 128 cmdline_parse_token_string_t cmd_help_brief_help = 129 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 130 131 cmdline_parse_inst_t cmd_help_brief = { 132 .f = cmd_help_brief_parsed, 133 .data = NULL, 134 .help_str = "help: Show help", 135 .tokens = { 136 (void *)&cmd_help_brief_help, 137 NULL, 138 }, 139 }; 140 141 /* *** Help command with help sections. *** */ 142 struct cmd_help_long_result { 143 cmdline_fixed_string_t help; 144 cmdline_fixed_string_t section; 145 }; 146 147 static void cmd_help_long_parsed(void *parsed_result, 148 struct cmdline *cl, 149 __attribute__((unused)) void *data) 150 { 151 int show_all = 0; 152 struct cmd_help_long_result *res = parsed_result; 153 154 if (!strcmp(res->section, "all")) 155 show_all = 1; 156 157 if (show_all || !strcmp(res->section, "control")) { 158 159 cmdline_printf( 160 cl, 161 "\n" 162 "Control forwarding:\n" 163 "-------------------\n\n" 164 165 "start\n" 166 " Start packet forwarding with current configuration.\n\n" 167 168 "start tx_first\n" 169 " Start packet forwarding with current config" 170 " after sending one burst of packets.\n\n" 171 172 "stop\n" 173 " Stop packet forwarding, and display accumulated" 174 " statistics.\n\n" 175 176 "quit\n" 177 " Quit to prompt.\n\n" 178 ); 179 } 180 181 if (show_all || !strcmp(res->section, "display")) { 182 183 cmdline_printf( 184 cl, 185 "\n" 186 "Display:\n" 187 "--------\n\n" 188 189 "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n" 190 " Display information for port_id, or all.\n\n" 191 192 "show port X rss reta (size) (mask0,mask1,...)\n" 193 " Display the rss redirection table entry indicated" 194 " by masks on port X. size is used to indicate the" 195 " hardware supported reta size\n\n" 196 197 "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|" 198 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 199 "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n" 200 " Display the RSS hash functions and RSS hash key" 201 " of port X\n\n" 202 203 "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n" 204 " Clear information for port_id, or all.\n\n" 205 206 "show (rxq|txq) info (port_id) (queue_id)\n" 207 " Display information for configured RX/TX queue.\n\n" 208 209 "show config (rxtx|cores|fwd|txpkts)\n" 210 " Display the given configuration.\n\n" 211 212 "read rxd (port_id) (queue_id) (rxd_id)\n" 213 " Display an RX descriptor of a port RX queue.\n\n" 214 215 "read txd (port_id) (queue_id) (txd_id)\n" 216 " Display a TX descriptor of a port TX queue.\n\n" 217 218 "ddp get list (port_id)\n" 219 " Get ddp profile info list\n\n" 220 ); 221 } 222 223 if (show_all || !strcmp(res->section, "config")) { 224 cmdline_printf( 225 cl, 226 "\n" 227 "Configuration:\n" 228 "--------------\n" 229 "Configuration changes only become active when" 230 " forwarding is started/restarted.\n\n" 231 232 "set default\n" 233 " Reset forwarding to the default configuration.\n\n" 234 235 "set verbose (level)\n" 236 " Set the debug verbosity level X.\n\n" 237 238 "set nbport (num)\n" 239 " Set number of ports.\n\n" 240 241 "set nbcore (num)\n" 242 " Set number of cores.\n\n" 243 244 "set coremask (mask)\n" 245 " Set the forwarding cores hexadecimal mask.\n\n" 246 247 "set portmask (mask)\n" 248 " Set the forwarding ports hexadecimal mask.\n\n" 249 250 "set burst (num)\n" 251 " Set number of packets per burst.\n\n" 252 253 "set burst tx delay (microseconds) retry (num)\n" 254 " Set the transmit delay time and number of retries," 255 " effective when retry is enabled.\n\n" 256 257 "set txpkts (x[,y]*)\n" 258 " Set the length of each segment of TXONLY" 259 " and optionally CSUM packets.\n\n" 260 261 "set txsplit (off|on|rand)\n" 262 " Set the split policy for the TX packets." 263 " Right now only applicable for CSUM and TXONLY" 264 " modes\n\n" 265 266 "set corelist (x[,y]*)\n" 267 " Set the list of forwarding cores.\n\n" 268 269 "set portlist (x[,y]*)\n" 270 " Set the list of forwarding ports.\n\n" 271 272 "set tx loopback (port_id) (on|off)\n" 273 " Enable or disable tx loopback.\n\n" 274 275 #ifdef RTE_LIBRTE_IXGBE_PMD 276 "set all queues drop (port_id) (on|off)\n" 277 " Set drop enable bit for all queues.\n\n" 278 279 "set vf split drop (port_id) (vf_id) (on|off)\n" 280 " Set split drop enable bit for a VF from the PF.\n\n" 281 #endif 282 283 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 284 " Set MAC antispoof for a VF from the PF.\n\n" 285 286 #ifdef RTE_LIBRTE_IXGBE_PMD 287 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 288 " Enable MACsec offload.\n\n" 289 290 "set macsec offload (port_id) off\n" 291 " Disable MACsec offload.\n\n" 292 293 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 294 " Configure MACsec secure connection (SC).\n\n" 295 296 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 297 " Configure MACsec secure association (SA).\n\n" 298 #endif 299 300 "set vf broadcast (port_id) (vf_id) (on|off)\n" 301 " Set VF broadcast for a VF from the PF.\n\n" 302 303 "vlan set strip (on|off) (port_id)\n" 304 " Set the VLAN strip on a port.\n\n" 305 306 "vlan set stripq (on|off) (port_id,queue_id)\n" 307 " Set the VLAN strip for a queue on a port.\n\n" 308 309 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 310 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 311 312 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 313 " Set VLAN insert for a VF from the PF.\n\n" 314 315 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 316 " Set VLAN antispoof for a VF from the PF.\n\n" 317 318 "set vf vlan tag (port_id) (vf_id) (on|off)\n" 319 " Set VLAN tag for a VF from the PF.\n\n" 320 321 "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n" 322 " Set a VF's max bandwidth(Mbps).\n\n" 323 324 "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n" 325 " Set all TCs' min bandwidth(%%) on a VF.\n\n" 326 327 "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n" 328 " Set a TC's max bandwidth(Mbps) on a VF.\n\n" 329 330 "set tx strict-link-priority (port_id) (tc_bitmap)\n" 331 " Set some TCs' strict link priority mode on a physical port.\n\n" 332 333 "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" 334 " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" 335 336 "vlan set filter (on|off) (port_id)\n" 337 " Set the VLAN filter on a port.\n\n" 338 339 "vlan set qinq (on|off) (port_id)\n" 340 " Set the VLAN QinQ (extended queue in queue)" 341 " on a port.\n\n" 342 343 "vlan set (inner|outer) tpid (value) (port_id)\n" 344 " Set the VLAN TPID for Packet Filtering on" 345 " a port\n\n" 346 347 "rx_vlan add (vlan_id|all) (port_id)\n" 348 " Add a vlan_id, or all identifiers, to the set" 349 " of VLAN identifiers filtered by port_id.\n\n" 350 351 "rx_vlan rm (vlan_id|all) (port_id)\n" 352 " Remove a vlan_id, or all identifiers, from the set" 353 " of VLAN identifiers filtered by port_id.\n\n" 354 355 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 356 " Add a vlan_id, to the set of VLAN identifiers" 357 "filtered for VF(s) from port_id.\n\n" 358 359 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 360 " Remove a vlan_id, to the set of VLAN identifiers" 361 "filtered for VF(s) from port_id.\n\n" 362 363 "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) " 364 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 365 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 366 " add a tunnel filter of a port.\n\n" 367 368 "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) " 369 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 370 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 371 " remove a tunnel filter of a port.\n\n" 372 373 "rx_vxlan_port add (udp_port) (port_id)\n" 374 " Add an UDP port for VXLAN packet filter on a port\n\n" 375 376 "rx_vxlan_port rm (udp_port) (port_id)\n" 377 " Remove an UDP port for VXLAN packet filter on a port\n\n" 378 379 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 380 " Set hardware insertion of VLAN IDs (single or double VLAN " 381 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 382 383 "tx_vlan set pvid port_id vlan_id (on|off)\n" 384 " Set port based TX VLAN insertion.\n\n" 385 386 "tx_vlan reset (port_id)\n" 387 " Disable hardware insertion of a VLAN header in" 388 " packets sent on a port.\n\n" 389 390 "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n" 391 " Select hardware or software calculation of the" 392 " checksum when transmitting a packet using the" 393 " csum forward engine.\n" 394 " ip|udp|tcp|sctp always concern the inner layer.\n" 395 " outer-ip concerns the outer IP layer in" 396 " case the packet is recognized as a tunnel packet by" 397 " the forward engine (vxlan, gre and ipip are supported)\n" 398 " Please check the NIC datasheet for HW limits.\n\n" 399 400 "csum parse-tunnel (on|off) (tx_port_id)\n" 401 " If disabled, treat tunnel packets as non-tunneled" 402 " packets (treat inner headers as payload). The port\n" 403 " argument is the port used for TX in csum forward" 404 " engine.\n\n" 405 406 "csum show (port_id)\n" 407 " Display tx checksum offload configuration\n\n" 408 409 "tso set (segsize) (portid)\n" 410 " Enable TCP Segmentation Offload in csum forward" 411 " engine.\n" 412 " Please check the NIC datasheet for HW limits.\n\n" 413 414 "tso show (portid)" 415 " Display the status of TCP Segmentation Offload.\n\n" 416 417 "set fwd (%s)\n" 418 " Set packet forwarding mode.\n\n" 419 420 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 421 " Add a MAC address on port_id.\n\n" 422 423 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 424 " Remove a MAC address from port_id.\n\n" 425 426 "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n" 427 " Set the default MAC address for port_id.\n\n" 428 429 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 430 " Add a MAC address for a VF on the port.\n\n" 431 432 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 433 " Set the MAC address for a VF from the PF.\n\n" 434 435 "set port (port_id) uta (mac_address|all) (on|off)\n" 436 " Add/Remove a or all unicast hash filter(s)" 437 "from port X.\n\n" 438 439 "set promisc (port_id|all) (on|off)\n" 440 " Set the promiscuous mode on port_id, or all.\n\n" 441 442 "set allmulti (port_id|all) (on|off)\n" 443 " Set the allmulti mode on port_id, or all.\n\n" 444 445 "set vf promisc (port_id) (vf_id) (on|off)\n" 446 " Set unicast promiscuous mode for a VF from the PF.\n\n" 447 448 "set vf allmulti (port_id) (vf_id) (on|off)\n" 449 " Set multicast promiscuous mode for a VF from the PF.\n\n" 450 451 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 452 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 453 " (on|off) autoneg (on|off) (port_id)\n" 454 "set flow_ctrl rx (on|off) (portid)\n" 455 "set flow_ctrl tx (on|off) (portid)\n" 456 "set flow_ctrl high_water (high_water) (portid)\n" 457 "set flow_ctrl low_water (low_water) (portid)\n" 458 "set flow_ctrl pause_time (pause_time) (portid)\n" 459 "set flow_ctrl send_xon (send_xon) (portid)\n" 460 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 461 "set flow_ctrl autoneg (on|off) (port_id)\n" 462 " Set the link flow control parameter on a port.\n\n" 463 464 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 465 " (low_water) (pause_time) (priority) (port_id)\n" 466 " Set the priority flow control parameter on a" 467 " port.\n\n" 468 469 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 470 " Set statistics mapping (qmapping 0..15) for RX/TX" 471 " queue on port.\n" 472 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 473 " on port 0 to mapping 5.\n\n" 474 475 "set port (port_id) vf (vf_id) rx|tx on|off\n" 476 " Enable/Disable a VF receive/tranmit from a port\n\n" 477 478 "set port (port_id) vf (vf_id) (mac_addr)" 479 " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n" 480 " Add/Remove unicast or multicast MAC addr filter" 481 " for a VF.\n\n" 482 483 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 484 "|MPE) (on|off)\n" 485 " AUPE:accepts untagged VLAN;" 486 "ROPE:accept unicast hash\n\n" 487 " BAM:accepts broadcast packets;" 488 "MPE:accepts all multicast packets\n\n" 489 " Enable/Disable a VF receive mode of a port\n\n" 490 491 "set port (port_id) queue (queue_id) rate (rate_num)\n" 492 " Set rate limit for a queue of a port\n\n" 493 494 "set port (port_id) vf (vf_id) rate (rate_num) " 495 "queue_mask (queue_mask_value)\n" 496 " Set rate limit for queues in VF of a port\n\n" 497 498 "set port (port_id) mirror-rule (rule_id)" 499 " (pool-mirror-up|pool-mirror-down|vlan-mirror)" 500 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 501 " Set pool or vlan type mirror rule on a port.\n" 502 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 503 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 504 " to pool 0.\n\n" 505 506 "set port (port_id) mirror-rule (rule_id)" 507 " (uplink-mirror|downlink-mirror) dst-pool" 508 " (pool_id) (on|off)\n" 509 " Set uplink or downlink type mirror rule on a port.\n" 510 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 511 " 0 on' enable mirror income traffic to pool 0.\n\n" 512 513 "reset port (port_id) mirror-rule (rule_id)\n" 514 " Reset a mirror rule.\n\n" 515 516 "set flush_rx (on|off)\n" 517 " Flush (default) or don't flush RX streams before" 518 " forwarding. Mainly used with PCAP drivers.\n\n" 519 520 #ifdef RTE_NIC_BYPASS 521 "set bypass mode (normal|bypass|isolate) (port_id)\n" 522 " Set the bypass mode for the lowest port on bypass enabled" 523 " NIC.\n\n" 524 525 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 526 "mode (normal|bypass|isolate) (port_id)\n" 527 " Set the event required to initiate specified bypass mode for" 528 " the lowest port on a bypass enabled NIC where:\n" 529 " timeout = enable bypass after watchdog timeout.\n" 530 " os_on = enable bypass when OS/board is powered on.\n" 531 " os_off = enable bypass when OS/board is powered off.\n" 532 " power_on = enable bypass when power supply is turned on.\n" 533 " power_off = enable bypass when power supply is turned off." 534 "\n\n" 535 536 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 537 " Set the bypass watchdog timeout to 'n' seconds" 538 " where 0 = instant.\n\n" 539 540 "show bypass config (port_id)\n" 541 " Show the bypass configuration for a bypass enabled NIC" 542 " using the lowest port on the NIC.\n\n" 543 #endif 544 #ifdef RTE_LIBRTE_PMD_BOND 545 "create bonded device (mode) (socket)\n" 546 " Create a new bonded device with specific bonding mode and socket.\n\n" 547 548 "add bonding slave (slave_id) (port_id)\n" 549 " Add a slave device to a bonded device.\n\n" 550 551 "remove bonding slave (slave_id) (port_id)\n" 552 " Remove a slave device from a bonded device.\n\n" 553 554 "set bonding mode (value) (port_id)\n" 555 " Set the bonding mode on a bonded device.\n\n" 556 557 "set bonding primary (slave_id) (port_id)\n" 558 " Set the primary slave for a bonded device.\n\n" 559 560 "show bonding config (port_id)\n" 561 " Show the bonding config for port_id.\n\n" 562 563 "set bonding mac_addr (port_id) (address)\n" 564 " Set the MAC address of a bonded device.\n\n" 565 566 "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n" 567 " Set the transmit balance policy for bonded device running in balance mode.\n\n" 568 569 "set bonding mon_period (port_id) (value)\n" 570 " Set the bonding link status monitoring polling period in ms.\n\n" 571 #endif 572 "set link-up port (port_id)\n" 573 " Set link up for a port.\n\n" 574 575 "set link-down port (port_id)\n" 576 " Set link down for a port.\n\n" 577 578 "E-tag set insertion on port-tag-id (value)" 579 " port (port_id) vf (vf_id)\n" 580 " Enable E-tag insertion for a VF on a port\n\n" 581 582 "E-tag set insertion off port (port_id) vf (vf_id)\n" 583 " Disable E-tag insertion for a VF on a port\n\n" 584 585 "E-tag set stripping (on|off) port (port_id)\n" 586 " Enable/disable E-tag stripping on a port\n\n" 587 588 "E-tag set forwarding (on|off) port (port_id)\n" 589 " Enable/disable E-tag based forwarding" 590 " on a port\n\n" 591 592 "E-tag set filter add e-tag-id (value) dst-pool" 593 " (pool_id) port (port_id)\n" 594 " Add an E-tag forwarding filter on a port\n\n" 595 596 "E-tag set filter del e-tag-id (value) port (port_id)\n" 597 " Delete an E-tag forwarding filter on a port\n\n" 598 599 "ddp add (port_id) (profile_path)\n" 600 " Load a profile package on a port\n\n" 601 602 , list_pkt_forwarding_modes() 603 ); 604 } 605 606 if (show_all || !strcmp(res->section, "ports")) { 607 608 cmdline_printf( 609 cl, 610 "\n" 611 "Port Operations:\n" 612 "----------------\n\n" 613 614 "port start (port_id|all)\n" 615 " Start all ports or port_id.\n\n" 616 617 "port stop (port_id|all)\n" 618 " Stop all ports or port_id.\n\n" 619 620 "port close (port_id|all)\n" 621 " Close all ports or port_id.\n\n" 622 623 "port attach (ident)\n" 624 " Attach physical or virtual dev by pci address or virtual device name\n\n" 625 626 "port detach (port_id)\n" 627 " Detach physical or virtual dev by port_id\n\n" 628 629 "port config (port_id|all)" 630 " speed (10|100|1000|10000|25000|40000|50000|100000|auto)" 631 " duplex (half|full|auto)\n" 632 " Set speed and duplex for all ports or port_id\n\n" 633 634 "port config all (rxq|txq|rxd|txd) (value)\n" 635 " Set number for rxq/txq/rxd/txd.\n\n" 636 637 "port config all max-pkt-len (value)\n" 638 " Set the max packet length.\n\n" 639 640 "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|" 641 "hw-vlan-strip|hw-vlan-extend|drop-en)" 642 " (on|off)\n" 643 " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" 644 " for ports.\n\n" 645 646 "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n" 647 " Set the RSS mode.\n\n" 648 649 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 650 " Set the RSS redirection table.\n\n" 651 652 "port config (port_id) dcb vt (on|off) (traffic_class)" 653 " pfc (on|off)\n" 654 " Set the DCB mode.\n\n" 655 656 "port config all burst (value)\n" 657 " Set the number of packets per burst.\n\n" 658 659 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 660 " (value)\n" 661 " Set the ring prefetch/host/writeback threshold" 662 " for tx/rx queue.\n\n" 663 664 "port config all (txfreet|txrst|rxfreet) (value)\n" 665 " Set free threshold for rx/tx, or set" 666 " tx rs bit threshold.\n\n" 667 "port config mtu X value\n" 668 " Set the MTU of port X to a given value\n\n" 669 670 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 671 " Start/stop a rx/tx queue of port X. Only take effect" 672 " when port X is started\n\n" 673 674 "port config (port_id|all) l2-tunnel E-tag ether-type" 675 " (value)\n" 676 " Set the value of E-tag ether-type.\n\n" 677 678 "port config (port_id|all) l2-tunnel E-tag" 679 " (enable|disable)\n" 680 " Enable/disable the E-tag support.\n\n" 681 ); 682 } 683 684 if (show_all || !strcmp(res->section, "registers")) { 685 686 cmdline_printf( 687 cl, 688 "\n" 689 "Registers:\n" 690 "----------\n\n" 691 692 "read reg (port_id) (address)\n" 693 " Display value of a port register.\n\n" 694 695 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 696 " Display a port register bit field.\n\n" 697 698 "read regbit (port_id) (address) (bit_x)\n" 699 " Display a single port register bit.\n\n" 700 701 "write reg (port_id) (address) (value)\n" 702 " Set value of a port register.\n\n" 703 704 "write regfield (port_id) (address) (bit_x) (bit_y)" 705 " (value)\n" 706 " Set bit field of a port register.\n\n" 707 708 "write regbit (port_id) (address) (bit_x) (value)\n" 709 " Set single bit value of a port register.\n\n" 710 ); 711 } 712 if (show_all || !strcmp(res->section, "filters")) { 713 714 cmdline_printf( 715 cl, 716 "\n" 717 "filters:\n" 718 "--------\n\n" 719 720 "ethertype_filter (port_id) (add|del)" 721 " (mac_addr|mac_ignr) (mac_address) ethertype" 722 " (ether_type) (drop|fwd) queue (queue_id)\n" 723 " Add/Del an ethertype filter.\n\n" 724 725 "2tuple_filter (port_id) (add|del)" 726 " dst_port (dst_port_value) protocol (protocol_value)" 727 " mask (mask_value) tcp_flags (tcp_flags_value)" 728 " priority (prio_value) queue (queue_id)\n" 729 " Add/Del a 2tuple filter.\n\n" 730 731 "5tuple_filter (port_id) (add|del)" 732 " dst_ip (dst_address) src_ip (src_address)" 733 " dst_port (dst_port_value) src_port (src_port_value)" 734 " protocol (protocol_value)" 735 " mask (mask_value) tcp_flags (tcp_flags_value)" 736 " priority (prio_value) queue (queue_id)\n" 737 " Add/Del a 5tuple filter.\n\n" 738 739 "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" 740 " Add/Del syn filter.\n\n" 741 742 "flex_filter (port_id) (add|del) len (len_value)" 743 " bytes (bytes_value) mask (mask_value)" 744 " priority (prio_value) queue (queue_id)\n" 745 " Add/Del a flex filter.\n\n" 746 747 "flow_director_filter (port_id) mode IP (add|del|update)" 748 " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)" 749 " src (src_ip_address) dst (dst_ip_address)" 750 " tos (tos_value) proto (proto_value) ttl (ttl_value)" 751 " vlan (vlan_value) flexbytes (flexbytes_value)" 752 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 753 " fd_id (fd_id_value)\n" 754 " Add/Del an IP type flow director filter.\n\n" 755 756 "flow_director_filter (port_id) mode IP (add|del|update)" 757 " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)" 758 " src (src_ip_address) (src_port)" 759 " dst (dst_ip_address) (dst_port)" 760 " tos (tos_value) ttl (ttl_value)" 761 " vlan (vlan_value) flexbytes (flexbytes_value)" 762 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 763 " fd_id (fd_id_value)\n" 764 " Add/Del an UDP/TCP type flow director filter.\n\n" 765 766 "flow_director_filter (port_id) mode IP (add|del|update)" 767 " flow (ipv4-sctp|ipv6-sctp)" 768 " src (src_ip_address) (src_port)" 769 " dst (dst_ip_address) (dst_port)" 770 " tag (verification_tag) " 771 " tos (tos_value) ttl (ttl_value)" 772 " vlan (vlan_value)" 773 " flexbytes (flexbytes_value) (drop|fwd)" 774 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 775 " Add/Del a SCTP type flow director filter.\n\n" 776 777 "flow_director_filter (port_id) mode IP (add|del|update)" 778 " flow l2_payload ether (ethertype)" 779 " flexbytes (flexbytes_value) (drop|fwd)" 780 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 781 " Add/Del a l2 payload type flow director filter.\n\n" 782 783 "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)" 784 " mac (mac_address) vlan (vlan_value)" 785 " flexbytes (flexbytes_value) (drop|fwd)" 786 " queue (queue_id) fd_id (fd_id_value)\n" 787 " Add/Del a MAC-VLAN flow director filter.\n\n" 788 789 "flow_director_filter (port_id) mode Tunnel (add|del|update)" 790 " mac (mac_address) vlan (vlan_value)" 791 " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)" 792 " flexbytes (flexbytes_value) (drop|fwd)" 793 " queue (queue_id) fd_id (fd_id_value)\n" 794 " Add/Del a Tunnel flow director filter.\n\n" 795 796 "flush_flow_director (port_id)\n" 797 " Flush all flow director entries of a device.\n\n" 798 799 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 800 " src_mask (ipv4_src) (ipv6_src) (src_port)" 801 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 802 " Set flow director IP mask.\n\n" 803 804 "flow_director_mask (port_id) mode MAC-VLAN" 805 " vlan (vlan_value)\n" 806 " Set flow director MAC-VLAN mask.\n\n" 807 808 "flow_director_mask (port_id) mode Tunnel" 809 " vlan (vlan_value) mac (mac_value)" 810 " tunnel-type (tunnel_type_value)" 811 " tunnel-id (tunnel_id_value)\n" 812 " Set flow director Tunnel mask.\n\n" 813 814 "flow_director_flex_mask (port_id)" 815 " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 816 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)" 817 " (mask)\n" 818 " Configure mask of flex payload.\n\n" 819 820 "flow_director_flex_payload (port_id)" 821 " (raw|l2|l3|l4) (config)\n" 822 " Configure flex payload selection.\n\n" 823 824 "get_sym_hash_ena_per_port (port_id)\n" 825 " get symmetric hash enable configuration per port.\n\n" 826 827 "set_sym_hash_ena_per_port (port_id) (enable|disable)\n" 828 " set symmetric hash enable configuration per port" 829 " to enable or disable.\n\n" 830 831 "get_hash_global_config (port_id)\n" 832 " Get the global configurations of hash filters.\n\n" 833 834 "set_hash_global_config (port_id) (toeplitz|simple_xor|default)" 835 " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 836 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)" 837 " (enable|disable)\n" 838 " Set the global configurations of hash filters.\n\n" 839 840 "set_hash_input_set (port_id) (ipv4|ipv4-frag|" 841 "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 842 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 843 "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|" 844 "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" 845 "ipv6-next-header|udp-src-port|udp-dst-port|" 846 "tcp-src-port|tcp-dst-port|sctp-src-port|" 847 "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" 848 "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|" 849 "fld-8th|none) (select|add)\n" 850 " Set the input set for hash.\n\n" 851 852 "set_fdir_input_set (port_id) " 853 "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 854 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 855 "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|" 856 "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|" 857 "ipv6-next-header|ipv6-hop-limits|udp-src-port|" 858 "udp-dst-port|tcp-src-port|tcp-dst-port|" 859 "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)" 860 " (select|add)\n" 861 " Set the input set for FDir.\n\n" 862 863 "flow validate {port_id}" 864 " [group {group_id}] [priority {level}]" 865 " [ingress] [egress]" 866 " pattern {item} [/ {item} [...]] / end" 867 " actions {action} [/ {action} [...]] / end\n" 868 " Check whether a flow rule can be created.\n\n" 869 870 "flow create {port_id}" 871 " [group {group_id}] [priority {level}]" 872 " [ingress] [egress]" 873 " pattern {item} [/ {item} [...]] / end" 874 " actions {action} [/ {action} [...]] / end\n" 875 " Create a flow rule.\n\n" 876 877 "flow destroy {port_id} rule {rule_id} [...]\n" 878 " Destroy specific flow rules.\n\n" 879 880 "flow flush {port_id}\n" 881 " Destroy all flow rules.\n\n" 882 883 "flow query {port_id} {rule_id} {action}\n" 884 " Query an existing flow rule.\n\n" 885 886 "flow list {port_id} [group {group_id}] [...]\n" 887 " List existing flow rules sorted by priority," 888 " filtered by group identifiers.\n\n" 889 ); 890 } 891 } 892 893 cmdline_parse_token_string_t cmd_help_long_help = 894 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 895 896 cmdline_parse_token_string_t cmd_help_long_section = 897 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 898 "all#control#display#config#" 899 "ports#registers#filters"); 900 901 cmdline_parse_inst_t cmd_help_long = { 902 .f = cmd_help_long_parsed, 903 .data = NULL, 904 .help_str = "help all|control|display|config|ports|register|filters: " 905 "Show help", 906 .tokens = { 907 (void *)&cmd_help_long_help, 908 (void *)&cmd_help_long_section, 909 NULL, 910 }, 911 }; 912 913 914 /* *** start/stop/close all ports *** */ 915 struct cmd_operate_port_result { 916 cmdline_fixed_string_t keyword; 917 cmdline_fixed_string_t name; 918 cmdline_fixed_string_t value; 919 }; 920 921 static void cmd_operate_port_parsed(void *parsed_result, 922 __attribute__((unused)) struct cmdline *cl, 923 __attribute__((unused)) void *data) 924 { 925 struct cmd_operate_port_result *res = parsed_result; 926 927 if (!strcmp(res->name, "start")) 928 start_port(RTE_PORT_ALL); 929 else if (!strcmp(res->name, "stop")) 930 stop_port(RTE_PORT_ALL); 931 else if (!strcmp(res->name, "close")) 932 close_port(RTE_PORT_ALL); 933 else 934 printf("Unknown parameter\n"); 935 } 936 937 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 938 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 939 "port"); 940 cmdline_parse_token_string_t cmd_operate_port_all_port = 941 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 942 "start#stop#close"); 943 cmdline_parse_token_string_t cmd_operate_port_all_all = 944 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 945 946 cmdline_parse_inst_t cmd_operate_port = { 947 .f = cmd_operate_port_parsed, 948 .data = NULL, 949 .help_str = "port start|stop|close all: Start/Stop/Close all ports", 950 .tokens = { 951 (void *)&cmd_operate_port_all_cmd, 952 (void *)&cmd_operate_port_all_port, 953 (void *)&cmd_operate_port_all_all, 954 NULL, 955 }, 956 }; 957 958 /* *** start/stop/close specific port *** */ 959 struct cmd_operate_specific_port_result { 960 cmdline_fixed_string_t keyword; 961 cmdline_fixed_string_t name; 962 uint8_t value; 963 }; 964 965 static void cmd_operate_specific_port_parsed(void *parsed_result, 966 __attribute__((unused)) struct cmdline *cl, 967 __attribute__((unused)) void *data) 968 { 969 struct cmd_operate_specific_port_result *res = parsed_result; 970 971 if (!strcmp(res->name, "start")) 972 start_port(res->value); 973 else if (!strcmp(res->name, "stop")) 974 stop_port(res->value); 975 else if (!strcmp(res->name, "close")) 976 close_port(res->value); 977 else 978 printf("Unknown parameter\n"); 979 } 980 981 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 982 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 983 keyword, "port"); 984 cmdline_parse_token_string_t cmd_operate_specific_port_port = 985 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 986 name, "start#stop#close"); 987 cmdline_parse_token_num_t cmd_operate_specific_port_id = 988 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 989 value, UINT8); 990 991 cmdline_parse_inst_t cmd_operate_specific_port = { 992 .f = cmd_operate_specific_port_parsed, 993 .data = NULL, 994 .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id", 995 .tokens = { 996 (void *)&cmd_operate_specific_port_cmd, 997 (void *)&cmd_operate_specific_port_port, 998 (void *)&cmd_operate_specific_port_id, 999 NULL, 1000 }, 1001 }; 1002 1003 /* *** attach a specified port *** */ 1004 struct cmd_operate_attach_port_result { 1005 cmdline_fixed_string_t port; 1006 cmdline_fixed_string_t keyword; 1007 cmdline_fixed_string_t identifier; 1008 }; 1009 1010 static void cmd_operate_attach_port_parsed(void *parsed_result, 1011 __attribute__((unused)) struct cmdline *cl, 1012 __attribute__((unused)) void *data) 1013 { 1014 struct cmd_operate_attach_port_result *res = parsed_result; 1015 1016 if (!strcmp(res->keyword, "attach")) 1017 attach_port(res->identifier); 1018 else 1019 printf("Unknown parameter\n"); 1020 } 1021 1022 cmdline_parse_token_string_t cmd_operate_attach_port_port = 1023 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1024 port, "port"); 1025 cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1026 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1027 keyword, "attach"); 1028 cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1029 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1030 identifier, NULL); 1031 1032 cmdline_parse_inst_t cmd_operate_attach_port = { 1033 .f = cmd_operate_attach_port_parsed, 1034 .data = NULL, 1035 .help_str = "port attach <identifier>: " 1036 "(identifier: pci address or virtual dev name)", 1037 .tokens = { 1038 (void *)&cmd_operate_attach_port_port, 1039 (void *)&cmd_operate_attach_port_keyword, 1040 (void *)&cmd_operate_attach_port_identifier, 1041 NULL, 1042 }, 1043 }; 1044 1045 /* *** detach a specified port *** */ 1046 struct cmd_operate_detach_port_result { 1047 cmdline_fixed_string_t port; 1048 cmdline_fixed_string_t keyword; 1049 uint8_t port_id; 1050 }; 1051 1052 static void cmd_operate_detach_port_parsed(void *parsed_result, 1053 __attribute__((unused)) struct cmdline *cl, 1054 __attribute__((unused)) void *data) 1055 { 1056 struct cmd_operate_detach_port_result *res = parsed_result; 1057 1058 if (!strcmp(res->keyword, "detach")) 1059 detach_port(res->port_id); 1060 else 1061 printf("Unknown parameter\n"); 1062 } 1063 1064 cmdline_parse_token_string_t cmd_operate_detach_port_port = 1065 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1066 port, "port"); 1067 cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1068 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1069 keyword, "detach"); 1070 cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1071 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1072 port_id, UINT8); 1073 1074 cmdline_parse_inst_t cmd_operate_detach_port = { 1075 .f = cmd_operate_detach_port_parsed, 1076 .data = NULL, 1077 .help_str = "port detach <port_id>", 1078 .tokens = { 1079 (void *)&cmd_operate_detach_port_port, 1080 (void *)&cmd_operate_detach_port_keyword, 1081 (void *)&cmd_operate_detach_port_port_id, 1082 NULL, 1083 }, 1084 }; 1085 1086 /* *** configure speed for all ports *** */ 1087 struct cmd_config_speed_all { 1088 cmdline_fixed_string_t port; 1089 cmdline_fixed_string_t keyword; 1090 cmdline_fixed_string_t all; 1091 cmdline_fixed_string_t item1; 1092 cmdline_fixed_string_t item2; 1093 cmdline_fixed_string_t value1; 1094 cmdline_fixed_string_t value2; 1095 }; 1096 1097 static int 1098 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1099 { 1100 1101 int duplex; 1102 1103 if (!strcmp(duplexstr, "half")) { 1104 duplex = ETH_LINK_HALF_DUPLEX; 1105 } else if (!strcmp(duplexstr, "full")) { 1106 duplex = ETH_LINK_FULL_DUPLEX; 1107 } else if (!strcmp(duplexstr, "auto")) { 1108 duplex = ETH_LINK_FULL_DUPLEX; 1109 } else { 1110 printf("Unknown duplex parameter\n"); 1111 return -1; 1112 } 1113 1114 if (!strcmp(speedstr, "10")) { 1115 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1116 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M; 1117 } else if (!strcmp(speedstr, "100")) { 1118 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1119 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M; 1120 } else { 1121 if (duplex != ETH_LINK_FULL_DUPLEX) { 1122 printf("Invalid speed/duplex parameters\n"); 1123 return -1; 1124 } 1125 if (!strcmp(speedstr, "1000")) { 1126 *speed = ETH_LINK_SPEED_1G; 1127 } else if (!strcmp(speedstr, "10000")) { 1128 *speed = ETH_LINK_SPEED_10G; 1129 } else if (!strcmp(speedstr, "25000")) { 1130 *speed = ETH_LINK_SPEED_25G; 1131 } else if (!strcmp(speedstr, "40000")) { 1132 *speed = ETH_LINK_SPEED_40G; 1133 } else if (!strcmp(speedstr, "50000")) { 1134 *speed = ETH_LINK_SPEED_50G; 1135 } else if (!strcmp(speedstr, "100000")) { 1136 *speed = ETH_LINK_SPEED_100G; 1137 } else if (!strcmp(speedstr, "auto")) { 1138 *speed = ETH_LINK_SPEED_AUTONEG; 1139 } else { 1140 printf("Unknown speed parameter\n"); 1141 return -1; 1142 } 1143 } 1144 1145 return 0; 1146 } 1147 1148 static void 1149 cmd_config_speed_all_parsed(void *parsed_result, 1150 __attribute__((unused)) struct cmdline *cl, 1151 __attribute__((unused)) void *data) 1152 { 1153 struct cmd_config_speed_all *res = parsed_result; 1154 uint32_t link_speed; 1155 portid_t pid; 1156 1157 if (!all_ports_stopped()) { 1158 printf("Please stop all ports first\n"); 1159 return; 1160 } 1161 1162 if (parse_and_check_speed_duplex(res->value1, res->value2, 1163 &link_speed) < 0) 1164 return; 1165 1166 FOREACH_PORT(pid, ports) { 1167 ports[pid].dev_conf.link_speeds = link_speed; 1168 } 1169 1170 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1171 } 1172 1173 cmdline_parse_token_string_t cmd_config_speed_all_port = 1174 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1175 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1176 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1177 "config"); 1178 cmdline_parse_token_string_t cmd_config_speed_all_all = 1179 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1180 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1181 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1182 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1183 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1184 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1185 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1186 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1187 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1188 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1189 "half#full#auto"); 1190 1191 cmdline_parse_inst_t cmd_config_speed_all = { 1192 .f = cmd_config_speed_all_parsed, 1193 .data = NULL, 1194 .help_str = "port config all speed " 1195 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1196 "half|full|auto", 1197 .tokens = { 1198 (void *)&cmd_config_speed_all_port, 1199 (void *)&cmd_config_speed_all_keyword, 1200 (void *)&cmd_config_speed_all_all, 1201 (void *)&cmd_config_speed_all_item1, 1202 (void *)&cmd_config_speed_all_value1, 1203 (void *)&cmd_config_speed_all_item2, 1204 (void *)&cmd_config_speed_all_value2, 1205 NULL, 1206 }, 1207 }; 1208 1209 /* *** configure speed for specific port *** */ 1210 struct cmd_config_speed_specific { 1211 cmdline_fixed_string_t port; 1212 cmdline_fixed_string_t keyword; 1213 uint8_t id; 1214 cmdline_fixed_string_t item1; 1215 cmdline_fixed_string_t item2; 1216 cmdline_fixed_string_t value1; 1217 cmdline_fixed_string_t value2; 1218 }; 1219 1220 static void 1221 cmd_config_speed_specific_parsed(void *parsed_result, 1222 __attribute__((unused)) struct cmdline *cl, 1223 __attribute__((unused)) void *data) 1224 { 1225 struct cmd_config_speed_specific *res = parsed_result; 1226 uint32_t link_speed; 1227 1228 if (!all_ports_stopped()) { 1229 printf("Please stop all ports first\n"); 1230 return; 1231 } 1232 1233 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1234 return; 1235 1236 if (parse_and_check_speed_duplex(res->value1, res->value2, 1237 &link_speed) < 0) 1238 return; 1239 1240 ports[res->id].dev_conf.link_speeds = link_speed; 1241 1242 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1243 } 1244 1245 1246 cmdline_parse_token_string_t cmd_config_speed_specific_port = 1247 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1248 "port"); 1249 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1250 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1251 "config"); 1252 cmdline_parse_token_num_t cmd_config_speed_specific_id = 1253 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 1254 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1255 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1256 "speed"); 1257 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1258 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1259 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1260 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1261 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1262 "duplex"); 1263 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1264 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1265 "half#full#auto"); 1266 1267 cmdline_parse_inst_t cmd_config_speed_specific = { 1268 .f = cmd_config_speed_specific_parsed, 1269 .data = NULL, 1270 .help_str = "port config <port_id> speed " 1271 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1272 "half|full|auto", 1273 .tokens = { 1274 (void *)&cmd_config_speed_specific_port, 1275 (void *)&cmd_config_speed_specific_keyword, 1276 (void *)&cmd_config_speed_specific_id, 1277 (void *)&cmd_config_speed_specific_item1, 1278 (void *)&cmd_config_speed_specific_value1, 1279 (void *)&cmd_config_speed_specific_item2, 1280 (void *)&cmd_config_speed_specific_value2, 1281 NULL, 1282 }, 1283 }; 1284 1285 /* *** configure txq/rxq, txd/rxd *** */ 1286 struct cmd_config_rx_tx { 1287 cmdline_fixed_string_t port; 1288 cmdline_fixed_string_t keyword; 1289 cmdline_fixed_string_t all; 1290 cmdline_fixed_string_t name; 1291 uint16_t value; 1292 }; 1293 1294 static void 1295 cmd_config_rx_tx_parsed(void *parsed_result, 1296 __attribute__((unused)) struct cmdline *cl, 1297 __attribute__((unused)) void *data) 1298 { 1299 struct cmd_config_rx_tx *res = parsed_result; 1300 1301 if (!all_ports_stopped()) { 1302 printf("Please stop all ports first\n"); 1303 return; 1304 } 1305 if (!strcmp(res->name, "rxq")) { 1306 if (!res->value && !nb_txq) { 1307 printf("Warning: Either rx or tx queues should be non zero\n"); 1308 return; 1309 } 1310 nb_rxq = res->value; 1311 } 1312 else if (!strcmp(res->name, "txq")) { 1313 if (!res->value && !nb_rxq) { 1314 printf("Warning: Either rx or tx queues should be non zero\n"); 1315 return; 1316 } 1317 nb_txq = res->value; 1318 } 1319 else if (!strcmp(res->name, "rxd")) { 1320 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 1321 printf("rxd %d invalid - must be > 0 && <= %d\n", 1322 res->value, RTE_TEST_RX_DESC_MAX); 1323 return; 1324 } 1325 nb_rxd = res->value; 1326 } else if (!strcmp(res->name, "txd")) { 1327 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 1328 printf("txd %d invalid - must be > 0 && <= %d\n", 1329 res->value, RTE_TEST_TX_DESC_MAX); 1330 return; 1331 } 1332 nb_txd = res->value; 1333 } else { 1334 printf("Unknown parameter\n"); 1335 return; 1336 } 1337 1338 fwd_config_setup(); 1339 1340 init_port_config(); 1341 1342 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1343 } 1344 1345 cmdline_parse_token_string_t cmd_config_rx_tx_port = 1346 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1347 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1348 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1349 cmdline_parse_token_string_t cmd_config_rx_tx_all = 1350 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1351 cmdline_parse_token_string_t cmd_config_rx_tx_name = 1352 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1353 "rxq#txq#rxd#txd"); 1354 cmdline_parse_token_num_t cmd_config_rx_tx_value = 1355 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 1356 1357 cmdline_parse_inst_t cmd_config_rx_tx = { 1358 .f = cmd_config_rx_tx_parsed, 1359 .data = NULL, 1360 .help_str = "port config all rxq|txq|rxd|txd <value>", 1361 .tokens = { 1362 (void *)&cmd_config_rx_tx_port, 1363 (void *)&cmd_config_rx_tx_keyword, 1364 (void *)&cmd_config_rx_tx_all, 1365 (void *)&cmd_config_rx_tx_name, 1366 (void *)&cmd_config_rx_tx_value, 1367 NULL, 1368 }, 1369 }; 1370 1371 /* *** config max packet length *** */ 1372 struct cmd_config_max_pkt_len_result { 1373 cmdline_fixed_string_t port; 1374 cmdline_fixed_string_t keyword; 1375 cmdline_fixed_string_t all; 1376 cmdline_fixed_string_t name; 1377 uint32_t value; 1378 }; 1379 1380 static void 1381 cmd_config_max_pkt_len_parsed(void *parsed_result, 1382 __attribute__((unused)) struct cmdline *cl, 1383 __attribute__((unused)) void *data) 1384 { 1385 struct cmd_config_max_pkt_len_result *res = parsed_result; 1386 1387 if (!all_ports_stopped()) { 1388 printf("Please stop all ports first\n"); 1389 return; 1390 } 1391 1392 if (!strcmp(res->name, "max-pkt-len")) { 1393 if (res->value < ETHER_MIN_LEN) { 1394 printf("max-pkt-len can not be less than %d\n", 1395 ETHER_MIN_LEN); 1396 return; 1397 } 1398 if (res->value == rx_mode.max_rx_pkt_len) 1399 return; 1400 1401 rx_mode.max_rx_pkt_len = res->value; 1402 if (res->value > ETHER_MAX_LEN) 1403 rx_mode.jumbo_frame = 1; 1404 else 1405 rx_mode.jumbo_frame = 0; 1406 } else { 1407 printf("Unknown parameter\n"); 1408 return; 1409 } 1410 1411 init_port_config(); 1412 1413 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1414 } 1415 1416 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1417 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1418 "port"); 1419 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1420 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1421 "config"); 1422 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1423 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1424 "all"); 1425 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1426 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1427 "max-pkt-len"); 1428 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1429 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1430 UINT32); 1431 1432 cmdline_parse_inst_t cmd_config_max_pkt_len = { 1433 .f = cmd_config_max_pkt_len_parsed, 1434 .data = NULL, 1435 .help_str = "port config all max-pkt-len <value>", 1436 .tokens = { 1437 (void *)&cmd_config_max_pkt_len_port, 1438 (void *)&cmd_config_max_pkt_len_keyword, 1439 (void *)&cmd_config_max_pkt_len_all, 1440 (void *)&cmd_config_max_pkt_len_name, 1441 (void *)&cmd_config_max_pkt_len_value, 1442 NULL, 1443 }, 1444 }; 1445 1446 /* *** configure port MTU *** */ 1447 struct cmd_config_mtu_result { 1448 cmdline_fixed_string_t port; 1449 cmdline_fixed_string_t keyword; 1450 cmdline_fixed_string_t mtu; 1451 uint8_t port_id; 1452 uint16_t value; 1453 }; 1454 1455 static void 1456 cmd_config_mtu_parsed(void *parsed_result, 1457 __attribute__((unused)) struct cmdline *cl, 1458 __attribute__((unused)) void *data) 1459 { 1460 struct cmd_config_mtu_result *res = parsed_result; 1461 1462 if (res->value < ETHER_MIN_LEN) { 1463 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN); 1464 return; 1465 } 1466 port_mtu_set(res->port_id, res->value); 1467 } 1468 1469 cmdline_parse_token_string_t cmd_config_mtu_port = 1470 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1471 "port"); 1472 cmdline_parse_token_string_t cmd_config_mtu_keyword = 1473 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1474 "config"); 1475 cmdline_parse_token_string_t cmd_config_mtu_mtu = 1476 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1477 "mtu"); 1478 cmdline_parse_token_num_t cmd_config_mtu_port_id = 1479 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8); 1480 cmdline_parse_token_num_t cmd_config_mtu_value = 1481 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); 1482 1483 cmdline_parse_inst_t cmd_config_mtu = { 1484 .f = cmd_config_mtu_parsed, 1485 .data = NULL, 1486 .help_str = "port config mtu <port_id> <value>", 1487 .tokens = { 1488 (void *)&cmd_config_mtu_port, 1489 (void *)&cmd_config_mtu_keyword, 1490 (void *)&cmd_config_mtu_mtu, 1491 (void *)&cmd_config_mtu_port_id, 1492 (void *)&cmd_config_mtu_value, 1493 NULL, 1494 }, 1495 }; 1496 1497 /* *** configure rx mode *** */ 1498 struct cmd_config_rx_mode_flag { 1499 cmdline_fixed_string_t port; 1500 cmdline_fixed_string_t keyword; 1501 cmdline_fixed_string_t all; 1502 cmdline_fixed_string_t name; 1503 cmdline_fixed_string_t value; 1504 }; 1505 1506 static void 1507 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1508 __attribute__((unused)) struct cmdline *cl, 1509 __attribute__((unused)) void *data) 1510 { 1511 struct cmd_config_rx_mode_flag *res = parsed_result; 1512 1513 if (!all_ports_stopped()) { 1514 printf("Please stop all ports first\n"); 1515 return; 1516 } 1517 1518 if (!strcmp(res->name, "crc-strip")) { 1519 if (!strcmp(res->value, "on")) 1520 rx_mode.hw_strip_crc = 1; 1521 else if (!strcmp(res->value, "off")) 1522 rx_mode.hw_strip_crc = 0; 1523 else { 1524 printf("Unknown parameter\n"); 1525 return; 1526 } 1527 } else if (!strcmp(res->name, "scatter")) { 1528 if (!strcmp(res->value, "on")) 1529 rx_mode.enable_scatter = 1; 1530 else if (!strcmp(res->value, "off")) 1531 rx_mode.enable_scatter = 0; 1532 else { 1533 printf("Unknown parameter\n"); 1534 return; 1535 } 1536 } else if (!strcmp(res->name, "rx-cksum")) { 1537 if (!strcmp(res->value, "on")) 1538 rx_mode.hw_ip_checksum = 1; 1539 else if (!strcmp(res->value, "off")) 1540 rx_mode.hw_ip_checksum = 0; 1541 else { 1542 printf("Unknown parameter\n"); 1543 return; 1544 } 1545 } else if (!strcmp(res->name, "hw-vlan")) { 1546 if (!strcmp(res->value, "on")) { 1547 rx_mode.hw_vlan_filter = 1; 1548 rx_mode.hw_vlan_strip = 1; 1549 } 1550 else if (!strcmp(res->value, "off")) { 1551 rx_mode.hw_vlan_filter = 0; 1552 rx_mode.hw_vlan_strip = 0; 1553 } 1554 else { 1555 printf("Unknown parameter\n"); 1556 return; 1557 } 1558 } else if (!strcmp(res->name, "hw-vlan-filter")) { 1559 if (!strcmp(res->value, "on")) 1560 rx_mode.hw_vlan_filter = 1; 1561 else if (!strcmp(res->value, "off")) 1562 rx_mode.hw_vlan_filter = 0; 1563 else { 1564 printf("Unknown parameter\n"); 1565 return; 1566 } 1567 } else if (!strcmp(res->name, "hw-vlan-strip")) { 1568 if (!strcmp(res->value, "on")) 1569 rx_mode.hw_vlan_strip = 1; 1570 else if (!strcmp(res->value, "off")) 1571 rx_mode.hw_vlan_strip = 0; 1572 else { 1573 printf("Unknown parameter\n"); 1574 return; 1575 } 1576 } else if (!strcmp(res->name, "hw-vlan-extend")) { 1577 if (!strcmp(res->value, "on")) 1578 rx_mode.hw_vlan_extend = 1; 1579 else if (!strcmp(res->value, "off")) 1580 rx_mode.hw_vlan_extend = 0; 1581 else { 1582 printf("Unknown parameter\n"); 1583 return; 1584 } 1585 } else if (!strcmp(res->name, "drop-en")) { 1586 if (!strcmp(res->value, "on")) 1587 rx_drop_en = 1; 1588 else if (!strcmp(res->value, "off")) 1589 rx_drop_en = 0; 1590 else { 1591 printf("Unknown parameter\n"); 1592 return; 1593 } 1594 } else { 1595 printf("Unknown parameter\n"); 1596 return; 1597 } 1598 1599 init_port_config(); 1600 1601 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1602 } 1603 1604 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1605 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1606 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1607 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1608 "config"); 1609 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1610 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1611 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1612 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1613 "crc-strip#scatter#rx-cksum#hw-vlan#" 1614 "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); 1615 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1616 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1617 "on#off"); 1618 1619 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1620 .f = cmd_config_rx_mode_flag_parsed, 1621 .data = NULL, 1622 .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|" 1623 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", 1624 .tokens = { 1625 (void *)&cmd_config_rx_mode_flag_port, 1626 (void *)&cmd_config_rx_mode_flag_keyword, 1627 (void *)&cmd_config_rx_mode_flag_all, 1628 (void *)&cmd_config_rx_mode_flag_name, 1629 (void *)&cmd_config_rx_mode_flag_value, 1630 NULL, 1631 }, 1632 }; 1633 1634 /* *** configure rss *** */ 1635 struct cmd_config_rss { 1636 cmdline_fixed_string_t port; 1637 cmdline_fixed_string_t keyword; 1638 cmdline_fixed_string_t all; 1639 cmdline_fixed_string_t name; 1640 cmdline_fixed_string_t value; 1641 }; 1642 1643 static void 1644 cmd_config_rss_parsed(void *parsed_result, 1645 __attribute__((unused)) struct cmdline *cl, 1646 __attribute__((unused)) void *data) 1647 { 1648 struct cmd_config_rss *res = parsed_result; 1649 struct rte_eth_rss_conf rss_conf; 1650 int diag; 1651 uint8_t i; 1652 1653 if (!strcmp(res->value, "all")) 1654 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | 1655 ETH_RSS_UDP | ETH_RSS_SCTP | 1656 ETH_RSS_L2_PAYLOAD; 1657 else if (!strcmp(res->value, "ip")) 1658 rss_conf.rss_hf = ETH_RSS_IP; 1659 else if (!strcmp(res->value, "udp")) 1660 rss_conf.rss_hf = ETH_RSS_UDP; 1661 else if (!strcmp(res->value, "tcp")) 1662 rss_conf.rss_hf = ETH_RSS_TCP; 1663 else if (!strcmp(res->value, "sctp")) 1664 rss_conf.rss_hf = ETH_RSS_SCTP; 1665 else if (!strcmp(res->value, "ether")) 1666 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD; 1667 else if (!strcmp(res->value, "port")) 1668 rss_conf.rss_hf = ETH_RSS_PORT; 1669 else if (!strcmp(res->value, "vxlan")) 1670 rss_conf.rss_hf = ETH_RSS_VXLAN; 1671 else if (!strcmp(res->value, "geneve")) 1672 rss_conf.rss_hf = ETH_RSS_GENEVE; 1673 else if (!strcmp(res->value, "nvgre")) 1674 rss_conf.rss_hf = ETH_RSS_NVGRE; 1675 else if (!strcmp(res->value, "none")) 1676 rss_conf.rss_hf = 0; 1677 else { 1678 printf("Unknown parameter\n"); 1679 return; 1680 } 1681 rss_conf.rss_key = NULL; 1682 for (i = 0; i < rte_eth_dev_count(); i++) { 1683 diag = rte_eth_dev_rss_hash_update(i, &rss_conf); 1684 if (diag < 0) 1685 printf("Configuration of RSS hash at ethernet port %d " 1686 "failed with error (%d): %s.\n", 1687 i, -diag, strerror(-diag)); 1688 } 1689 } 1690 1691 cmdline_parse_token_string_t cmd_config_rss_port = 1692 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1693 cmdline_parse_token_string_t cmd_config_rss_keyword = 1694 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1695 cmdline_parse_token_string_t cmd_config_rss_all = 1696 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1697 cmdline_parse_token_string_t cmd_config_rss_name = 1698 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1699 cmdline_parse_token_string_t cmd_config_rss_value = 1700 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, 1701 "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none"); 1702 1703 cmdline_parse_inst_t cmd_config_rss = { 1704 .f = cmd_config_rss_parsed, 1705 .data = NULL, 1706 .help_str = "port config all rss " 1707 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none", 1708 .tokens = { 1709 (void *)&cmd_config_rss_port, 1710 (void *)&cmd_config_rss_keyword, 1711 (void *)&cmd_config_rss_all, 1712 (void *)&cmd_config_rss_name, 1713 (void *)&cmd_config_rss_value, 1714 NULL, 1715 }, 1716 }; 1717 1718 /* *** configure rss hash key *** */ 1719 struct cmd_config_rss_hash_key { 1720 cmdline_fixed_string_t port; 1721 cmdline_fixed_string_t config; 1722 uint8_t port_id; 1723 cmdline_fixed_string_t rss_hash_key; 1724 cmdline_fixed_string_t rss_type; 1725 cmdline_fixed_string_t key; 1726 }; 1727 1728 static uint8_t 1729 hexa_digit_to_value(char hexa_digit) 1730 { 1731 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 1732 return (uint8_t) (hexa_digit - '0'); 1733 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 1734 return (uint8_t) ((hexa_digit - 'a') + 10); 1735 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 1736 return (uint8_t) ((hexa_digit - 'A') + 10); 1737 /* Invalid hexa digit */ 1738 return 0xFF; 1739 } 1740 1741 static uint8_t 1742 parse_and_check_key_hexa_digit(char *key, int idx) 1743 { 1744 uint8_t hexa_v; 1745 1746 hexa_v = hexa_digit_to_value(key[idx]); 1747 if (hexa_v == 0xFF) 1748 printf("invalid key: character %c at position %d is not a " 1749 "valid hexa digit\n", key[idx], idx); 1750 return hexa_v; 1751 } 1752 1753 static void 1754 cmd_config_rss_hash_key_parsed(void *parsed_result, 1755 __attribute__((unused)) struct cmdline *cl, 1756 __attribute__((unused)) void *data) 1757 { 1758 struct cmd_config_rss_hash_key *res = parsed_result; 1759 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 1760 uint8_t xdgt0; 1761 uint8_t xdgt1; 1762 int i; 1763 struct rte_eth_dev_info dev_info; 1764 uint8_t hash_key_size; 1765 uint32_t key_len; 1766 1767 memset(&dev_info, 0, sizeof(dev_info)); 1768 rte_eth_dev_info_get(res->port_id, &dev_info); 1769 if (dev_info.hash_key_size > 0 && 1770 dev_info.hash_key_size <= sizeof(hash_key)) 1771 hash_key_size = dev_info.hash_key_size; 1772 else { 1773 printf("dev_info did not provide a valid hash key size\n"); 1774 return; 1775 } 1776 /* Check the length of the RSS hash key */ 1777 key_len = strlen(res->key); 1778 if (key_len != (hash_key_size * 2)) { 1779 printf("key length: %d invalid - key must be a string of %d" 1780 " hexa-decimal numbers\n", 1781 (int) key_len, hash_key_size * 2); 1782 return; 1783 } 1784 /* Translate RSS hash key into binary representation */ 1785 for (i = 0; i < hash_key_size; i++) { 1786 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 1787 if (xdgt0 == 0xFF) 1788 return; 1789 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 1790 if (xdgt1 == 0xFF) 1791 return; 1792 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 1793 } 1794 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 1795 hash_key_size); 1796 } 1797 1798 cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 1799 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 1800 cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 1801 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 1802 "config"); 1803 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 1804 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); 1805 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 1806 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 1807 rss_hash_key, "rss-hash-key"); 1808 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 1809 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 1810 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 1811 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 1812 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 1813 "ipv6-tcp-ex#ipv6-udp-ex"); 1814 cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 1815 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 1816 1817 cmdline_parse_inst_t cmd_config_rss_hash_key = { 1818 .f = cmd_config_rss_hash_key_parsed, 1819 .data = NULL, 1820 .help_str = "port config <port_id> rss-hash-key " 1821 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 1822 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1823 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex " 1824 "<string of hex digits (variable length, NIC dependent)>", 1825 .tokens = { 1826 (void *)&cmd_config_rss_hash_key_port, 1827 (void *)&cmd_config_rss_hash_key_config, 1828 (void *)&cmd_config_rss_hash_key_port_id, 1829 (void *)&cmd_config_rss_hash_key_rss_hash_key, 1830 (void *)&cmd_config_rss_hash_key_rss_type, 1831 (void *)&cmd_config_rss_hash_key_value, 1832 NULL, 1833 }, 1834 }; 1835 1836 /* *** configure port rxq/txq start/stop *** */ 1837 struct cmd_config_rxtx_queue { 1838 cmdline_fixed_string_t port; 1839 uint8_t portid; 1840 cmdline_fixed_string_t rxtxq; 1841 uint16_t qid; 1842 cmdline_fixed_string_t opname; 1843 }; 1844 1845 static void 1846 cmd_config_rxtx_queue_parsed(void *parsed_result, 1847 __attribute__((unused)) struct cmdline *cl, 1848 __attribute__((unused)) void *data) 1849 { 1850 struct cmd_config_rxtx_queue *res = parsed_result; 1851 uint8_t isrx; 1852 uint8_t isstart; 1853 int ret = 0; 1854 1855 if (test_done == 0) { 1856 printf("Please stop forwarding first\n"); 1857 return; 1858 } 1859 1860 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 1861 return; 1862 1863 if (port_is_started(res->portid) != 1) { 1864 printf("Please start port %u first\n", res->portid); 1865 return; 1866 } 1867 1868 if (!strcmp(res->rxtxq, "rxq")) 1869 isrx = 1; 1870 else if (!strcmp(res->rxtxq, "txq")) 1871 isrx = 0; 1872 else { 1873 printf("Unknown parameter\n"); 1874 return; 1875 } 1876 1877 if (isrx && rx_queue_id_is_invalid(res->qid)) 1878 return; 1879 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 1880 return; 1881 1882 if (!strcmp(res->opname, "start")) 1883 isstart = 1; 1884 else if (!strcmp(res->opname, "stop")) 1885 isstart = 0; 1886 else { 1887 printf("Unknown parameter\n"); 1888 return; 1889 } 1890 1891 if (isstart && isrx) 1892 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 1893 else if (!isstart && isrx) 1894 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 1895 else if (isstart && !isrx) 1896 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 1897 else 1898 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 1899 1900 if (ret == -ENOTSUP) 1901 printf("Function not supported in PMD driver\n"); 1902 } 1903 1904 cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 1905 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 1906 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 1907 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8); 1908 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 1909 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 1910 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 1911 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16); 1912 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 1913 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 1914 "start#stop"); 1915 1916 cmdline_parse_inst_t cmd_config_rxtx_queue = { 1917 .f = cmd_config_rxtx_queue_parsed, 1918 .data = NULL, 1919 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 1920 .tokens = { 1921 (void *)&cmd_config_speed_all_port, 1922 (void *)&cmd_config_rxtx_queue_portid, 1923 (void *)&cmd_config_rxtx_queue_rxtxq, 1924 (void *)&cmd_config_rxtx_queue_qid, 1925 (void *)&cmd_config_rxtx_queue_opname, 1926 NULL, 1927 }, 1928 }; 1929 1930 /* *** Configure RSS RETA *** */ 1931 struct cmd_config_rss_reta { 1932 cmdline_fixed_string_t port; 1933 cmdline_fixed_string_t keyword; 1934 uint8_t port_id; 1935 cmdline_fixed_string_t name; 1936 cmdline_fixed_string_t list_name; 1937 cmdline_fixed_string_t list_of_items; 1938 }; 1939 1940 static int 1941 parse_reta_config(const char *str, 1942 struct rte_eth_rss_reta_entry64 *reta_conf, 1943 uint16_t nb_entries) 1944 { 1945 int i; 1946 unsigned size; 1947 uint16_t hash_index, idx, shift; 1948 uint16_t nb_queue; 1949 char s[256]; 1950 const char *p, *p0 = str; 1951 char *end; 1952 enum fieldnames { 1953 FLD_HASH_INDEX = 0, 1954 FLD_QUEUE, 1955 _NUM_FLD 1956 }; 1957 unsigned long int_fld[_NUM_FLD]; 1958 char *str_fld[_NUM_FLD]; 1959 1960 while ((p = strchr(p0,'(')) != NULL) { 1961 ++p; 1962 if((p0 = strchr(p,')')) == NULL) 1963 return -1; 1964 1965 size = p0 - p; 1966 if(size >= sizeof(s)) 1967 return -1; 1968 1969 snprintf(s, sizeof(s), "%.*s", size, p); 1970 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 1971 return -1; 1972 for (i = 0; i < _NUM_FLD; i++) { 1973 errno = 0; 1974 int_fld[i] = strtoul(str_fld[i], &end, 0); 1975 if (errno != 0 || end == str_fld[i] || 1976 int_fld[i] > 65535) 1977 return -1; 1978 } 1979 1980 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 1981 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 1982 1983 if (hash_index >= nb_entries) { 1984 printf("Invalid RETA hash index=%d\n", hash_index); 1985 return -1; 1986 } 1987 1988 idx = hash_index / RTE_RETA_GROUP_SIZE; 1989 shift = hash_index % RTE_RETA_GROUP_SIZE; 1990 reta_conf[idx].mask |= (1ULL << shift); 1991 reta_conf[idx].reta[shift] = nb_queue; 1992 } 1993 1994 return 0; 1995 } 1996 1997 static void 1998 cmd_set_rss_reta_parsed(void *parsed_result, 1999 __attribute__((unused)) struct cmdline *cl, 2000 __attribute__((unused)) void *data) 2001 { 2002 int ret; 2003 struct rte_eth_dev_info dev_info; 2004 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2005 struct cmd_config_rss_reta *res = parsed_result; 2006 2007 memset(&dev_info, 0, sizeof(dev_info)); 2008 rte_eth_dev_info_get(res->port_id, &dev_info); 2009 if (dev_info.reta_size == 0) { 2010 printf("Redirection table size is 0 which is " 2011 "invalid for RSS\n"); 2012 return; 2013 } else 2014 printf("The reta size of port %d is %u\n", 2015 res->port_id, dev_info.reta_size); 2016 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) { 2017 printf("Currently do not support more than %u entries of " 2018 "redirection table\n", ETH_RSS_RETA_SIZE_512); 2019 return; 2020 } 2021 2022 memset(reta_conf, 0, sizeof(reta_conf)); 2023 if (!strcmp(res->list_name, "reta")) { 2024 if (parse_reta_config(res->list_of_items, reta_conf, 2025 dev_info.reta_size)) { 2026 printf("Invalid RSS Redirection Table " 2027 "config entered\n"); 2028 return; 2029 } 2030 ret = rte_eth_dev_rss_reta_update(res->port_id, 2031 reta_conf, dev_info.reta_size); 2032 if (ret != 0) 2033 printf("Bad redirection table parameter, " 2034 "return code = %d \n", ret); 2035 } 2036 } 2037 2038 cmdline_parse_token_string_t cmd_config_rss_reta_port = 2039 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2040 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2041 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2042 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2043 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); 2044 cmdline_parse_token_string_t cmd_config_rss_reta_name = 2045 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2046 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2047 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2048 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2049 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2050 NULL); 2051 cmdline_parse_inst_t cmd_config_rss_reta = { 2052 .f = cmd_set_rss_reta_parsed, 2053 .data = NULL, 2054 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2055 .tokens = { 2056 (void *)&cmd_config_rss_reta_port, 2057 (void *)&cmd_config_rss_reta_keyword, 2058 (void *)&cmd_config_rss_reta_port_id, 2059 (void *)&cmd_config_rss_reta_name, 2060 (void *)&cmd_config_rss_reta_list_name, 2061 (void *)&cmd_config_rss_reta_list_of_items, 2062 NULL, 2063 }, 2064 }; 2065 2066 /* *** SHOW PORT RETA INFO *** */ 2067 struct cmd_showport_reta { 2068 cmdline_fixed_string_t show; 2069 cmdline_fixed_string_t port; 2070 uint8_t port_id; 2071 cmdline_fixed_string_t rss; 2072 cmdline_fixed_string_t reta; 2073 uint16_t size; 2074 cmdline_fixed_string_t list_of_items; 2075 }; 2076 2077 static int 2078 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2079 uint16_t nb_entries, 2080 char *str) 2081 { 2082 uint32_t size; 2083 const char *p, *p0 = str; 2084 char s[256]; 2085 char *end; 2086 char *str_fld[8]; 2087 uint16_t i; 2088 uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) / 2089 RTE_RETA_GROUP_SIZE; 2090 int ret; 2091 2092 p = strchr(p0, '('); 2093 if (p == NULL) 2094 return -1; 2095 p++; 2096 p0 = strchr(p, ')'); 2097 if (p0 == NULL) 2098 return -1; 2099 size = p0 - p; 2100 if (size >= sizeof(s)) { 2101 printf("The string size exceeds the internal buffer size\n"); 2102 return -1; 2103 } 2104 snprintf(s, sizeof(s), "%.*s", size, p); 2105 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 2106 if (ret <= 0 || ret != num) { 2107 printf("The bits of masks do not match the number of " 2108 "reta entries: %u\n", num); 2109 return -1; 2110 } 2111 for (i = 0; i < ret; i++) 2112 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0); 2113 2114 return 0; 2115 } 2116 2117 static void 2118 cmd_showport_reta_parsed(void *parsed_result, 2119 __attribute__((unused)) struct cmdline *cl, 2120 __attribute__((unused)) void *data) 2121 { 2122 struct cmd_showport_reta *res = parsed_result; 2123 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2124 struct rte_eth_dev_info dev_info; 2125 2126 memset(&dev_info, 0, sizeof(dev_info)); 2127 rte_eth_dev_info_get(res->port_id, &dev_info); 2128 if (dev_info.reta_size == 0 || res->size != dev_info.reta_size || 2129 res->size > ETH_RSS_RETA_SIZE_512) { 2130 printf("Invalid redirection table size: %u\n", res->size); 2131 return; 2132 } 2133 2134 memset(reta_conf, 0, sizeof(reta_conf)); 2135 if (showport_parse_reta_config(reta_conf, res->size, 2136 res->list_of_items) < 0) { 2137 printf("Invalid string: %s for reta masks\n", 2138 res->list_of_items); 2139 return; 2140 } 2141 port_rss_reta_info(res->port_id, reta_conf, res->size); 2142 } 2143 2144 cmdline_parse_token_string_t cmd_showport_reta_show = 2145 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 2146 cmdline_parse_token_string_t cmd_showport_reta_port = 2147 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 2148 cmdline_parse_token_num_t cmd_showport_reta_port_id = 2149 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); 2150 cmdline_parse_token_string_t cmd_showport_reta_rss = 2151 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 2152 cmdline_parse_token_string_t cmd_showport_reta_reta = 2153 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 2154 cmdline_parse_token_num_t cmd_showport_reta_size = 2155 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16); 2156 cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 2157 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 2158 list_of_items, NULL); 2159 2160 cmdline_parse_inst_t cmd_showport_reta = { 2161 .f = cmd_showport_reta_parsed, 2162 .data = NULL, 2163 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 2164 .tokens = { 2165 (void *)&cmd_showport_reta_show, 2166 (void *)&cmd_showport_reta_port, 2167 (void *)&cmd_showport_reta_port_id, 2168 (void *)&cmd_showport_reta_rss, 2169 (void *)&cmd_showport_reta_reta, 2170 (void *)&cmd_showport_reta_size, 2171 (void *)&cmd_showport_reta_list_of_items, 2172 NULL, 2173 }, 2174 }; 2175 2176 /* *** Show RSS hash configuration *** */ 2177 struct cmd_showport_rss_hash { 2178 cmdline_fixed_string_t show; 2179 cmdline_fixed_string_t port; 2180 uint8_t port_id; 2181 cmdline_fixed_string_t rss_hash; 2182 cmdline_fixed_string_t rss_type; 2183 cmdline_fixed_string_t key; /* optional argument */ 2184 }; 2185 2186 static void cmd_showport_rss_hash_parsed(void *parsed_result, 2187 __attribute__((unused)) struct cmdline *cl, 2188 void *show_rss_key) 2189 { 2190 struct cmd_showport_rss_hash *res = parsed_result; 2191 2192 port_rss_hash_conf_show(res->port_id, res->rss_type, 2193 show_rss_key != NULL); 2194 } 2195 2196 cmdline_parse_token_string_t cmd_showport_rss_hash_show = 2197 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 2198 cmdline_parse_token_string_t cmd_showport_rss_hash_port = 2199 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 2200 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 2201 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8); 2202 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 2203 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 2204 "rss-hash"); 2205 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info = 2206 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type, 2207 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2208 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2209 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2210 "ipv6-tcp-ex#ipv6-udp-ex"); 2211 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 2212 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 2213 2214 cmdline_parse_inst_t cmd_showport_rss_hash = { 2215 .f = cmd_showport_rss_hash_parsed, 2216 .data = NULL, 2217 .help_str = "show port <port_id> rss-hash " 2218 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2219 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2220 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex", 2221 .tokens = { 2222 (void *)&cmd_showport_rss_hash_show, 2223 (void *)&cmd_showport_rss_hash_port, 2224 (void *)&cmd_showport_rss_hash_port_id, 2225 (void *)&cmd_showport_rss_hash_rss_hash, 2226 (void *)&cmd_showport_rss_hash_rss_hash_info, 2227 NULL, 2228 }, 2229 }; 2230 2231 cmdline_parse_inst_t cmd_showport_rss_hash_key = { 2232 .f = cmd_showport_rss_hash_parsed, 2233 .data = (void *)1, 2234 .help_str = "show port <port_id> rss-hash " 2235 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2236 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2237 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key", 2238 .tokens = { 2239 (void *)&cmd_showport_rss_hash_show, 2240 (void *)&cmd_showport_rss_hash_port, 2241 (void *)&cmd_showport_rss_hash_port_id, 2242 (void *)&cmd_showport_rss_hash_rss_hash, 2243 (void *)&cmd_showport_rss_hash_rss_hash_info, 2244 (void *)&cmd_showport_rss_hash_rss_key, 2245 NULL, 2246 }, 2247 }; 2248 2249 /* *** Configure DCB *** */ 2250 struct cmd_config_dcb { 2251 cmdline_fixed_string_t port; 2252 cmdline_fixed_string_t config; 2253 uint8_t port_id; 2254 cmdline_fixed_string_t dcb; 2255 cmdline_fixed_string_t vt; 2256 cmdline_fixed_string_t vt_en; 2257 uint8_t num_tcs; 2258 cmdline_fixed_string_t pfc; 2259 cmdline_fixed_string_t pfc_en; 2260 }; 2261 2262 static void 2263 cmd_config_dcb_parsed(void *parsed_result, 2264 __attribute__((unused)) struct cmdline *cl, 2265 __attribute__((unused)) void *data) 2266 { 2267 struct cmd_config_dcb *res = parsed_result; 2268 portid_t port_id = res->port_id; 2269 struct rte_port *port; 2270 uint8_t pfc_en; 2271 int ret; 2272 2273 port = &ports[port_id]; 2274 /** Check if the port is not started **/ 2275 if (port->port_status != RTE_PORT_STOPPED) { 2276 printf("Please stop port %d first\n", port_id); 2277 return; 2278 } 2279 2280 if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) { 2281 printf("The invalid number of traffic class," 2282 " only 4 or 8 allowed.\n"); 2283 return; 2284 } 2285 2286 if (nb_fwd_lcores < res->num_tcs) { 2287 printf("nb_cores shouldn't be less than number of TCs.\n"); 2288 return; 2289 } 2290 if (!strncmp(res->pfc_en, "on", 2)) 2291 pfc_en = 1; 2292 else 2293 pfc_en = 0; 2294 2295 /* DCB in VT mode */ 2296 if (!strncmp(res->vt_en, "on", 2)) 2297 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 2298 (enum rte_eth_nb_tcs)res->num_tcs, 2299 pfc_en); 2300 else 2301 ret = init_port_dcb_config(port_id, DCB_ENABLED, 2302 (enum rte_eth_nb_tcs)res->num_tcs, 2303 pfc_en); 2304 2305 2306 if (ret != 0) { 2307 printf("Cannot initialize network ports.\n"); 2308 return; 2309 } 2310 2311 cmd_reconfig_device_queue(port_id, 1, 1); 2312 } 2313 2314 cmdline_parse_token_string_t cmd_config_dcb_port = 2315 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 2316 cmdline_parse_token_string_t cmd_config_dcb_config = 2317 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 2318 cmdline_parse_token_num_t cmd_config_dcb_port_id = 2319 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); 2320 cmdline_parse_token_string_t cmd_config_dcb_dcb = 2321 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 2322 cmdline_parse_token_string_t cmd_config_dcb_vt = 2323 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 2324 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 2325 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 2326 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 2327 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 2328 cmdline_parse_token_string_t cmd_config_dcb_pfc= 2329 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 2330 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 2331 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 2332 2333 cmdline_parse_inst_t cmd_config_dcb = { 2334 .f = cmd_config_dcb_parsed, 2335 .data = NULL, 2336 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 2337 .tokens = { 2338 (void *)&cmd_config_dcb_port, 2339 (void *)&cmd_config_dcb_config, 2340 (void *)&cmd_config_dcb_port_id, 2341 (void *)&cmd_config_dcb_dcb, 2342 (void *)&cmd_config_dcb_vt, 2343 (void *)&cmd_config_dcb_vt_en, 2344 (void *)&cmd_config_dcb_num_tcs, 2345 (void *)&cmd_config_dcb_pfc, 2346 (void *)&cmd_config_dcb_pfc_en, 2347 NULL, 2348 }, 2349 }; 2350 2351 /* *** configure number of packets per burst *** */ 2352 struct cmd_config_burst { 2353 cmdline_fixed_string_t port; 2354 cmdline_fixed_string_t keyword; 2355 cmdline_fixed_string_t all; 2356 cmdline_fixed_string_t name; 2357 uint16_t value; 2358 }; 2359 2360 static void 2361 cmd_config_burst_parsed(void *parsed_result, 2362 __attribute__((unused)) struct cmdline *cl, 2363 __attribute__((unused)) void *data) 2364 { 2365 struct cmd_config_burst *res = parsed_result; 2366 2367 if (!all_ports_stopped()) { 2368 printf("Please stop all ports first\n"); 2369 return; 2370 } 2371 2372 if (!strcmp(res->name, "burst")) { 2373 if (res->value < 1 || res->value > MAX_PKT_BURST) { 2374 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 2375 return; 2376 } 2377 nb_pkt_per_burst = res->value; 2378 } else { 2379 printf("Unknown parameter\n"); 2380 return; 2381 } 2382 2383 init_port_config(); 2384 2385 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2386 } 2387 2388 cmdline_parse_token_string_t cmd_config_burst_port = 2389 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 2390 cmdline_parse_token_string_t cmd_config_burst_keyword = 2391 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 2392 cmdline_parse_token_string_t cmd_config_burst_all = 2393 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 2394 cmdline_parse_token_string_t cmd_config_burst_name = 2395 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 2396 cmdline_parse_token_num_t cmd_config_burst_value = 2397 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 2398 2399 cmdline_parse_inst_t cmd_config_burst = { 2400 .f = cmd_config_burst_parsed, 2401 .data = NULL, 2402 .help_str = "port config all burst <value>", 2403 .tokens = { 2404 (void *)&cmd_config_burst_port, 2405 (void *)&cmd_config_burst_keyword, 2406 (void *)&cmd_config_burst_all, 2407 (void *)&cmd_config_burst_name, 2408 (void *)&cmd_config_burst_value, 2409 NULL, 2410 }, 2411 }; 2412 2413 /* *** configure rx/tx queues *** */ 2414 struct cmd_config_thresh { 2415 cmdline_fixed_string_t port; 2416 cmdline_fixed_string_t keyword; 2417 cmdline_fixed_string_t all; 2418 cmdline_fixed_string_t name; 2419 uint8_t value; 2420 }; 2421 2422 static void 2423 cmd_config_thresh_parsed(void *parsed_result, 2424 __attribute__((unused)) struct cmdline *cl, 2425 __attribute__((unused)) void *data) 2426 { 2427 struct cmd_config_thresh *res = parsed_result; 2428 2429 if (!all_ports_stopped()) { 2430 printf("Please stop all ports first\n"); 2431 return; 2432 } 2433 2434 if (!strcmp(res->name, "txpt")) 2435 tx_pthresh = res->value; 2436 else if(!strcmp(res->name, "txht")) 2437 tx_hthresh = res->value; 2438 else if(!strcmp(res->name, "txwt")) 2439 tx_wthresh = res->value; 2440 else if(!strcmp(res->name, "rxpt")) 2441 rx_pthresh = res->value; 2442 else if(!strcmp(res->name, "rxht")) 2443 rx_hthresh = res->value; 2444 else if(!strcmp(res->name, "rxwt")) 2445 rx_wthresh = res->value; 2446 else { 2447 printf("Unknown parameter\n"); 2448 return; 2449 } 2450 2451 init_port_config(); 2452 2453 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2454 } 2455 2456 cmdline_parse_token_string_t cmd_config_thresh_port = 2457 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 2458 cmdline_parse_token_string_t cmd_config_thresh_keyword = 2459 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 2460 cmdline_parse_token_string_t cmd_config_thresh_all = 2461 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 2462 cmdline_parse_token_string_t cmd_config_thresh_name = 2463 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 2464 "txpt#txht#txwt#rxpt#rxht#rxwt"); 2465 cmdline_parse_token_num_t cmd_config_thresh_value = 2466 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 2467 2468 cmdline_parse_inst_t cmd_config_thresh = { 2469 .f = cmd_config_thresh_parsed, 2470 .data = NULL, 2471 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 2472 .tokens = { 2473 (void *)&cmd_config_thresh_port, 2474 (void *)&cmd_config_thresh_keyword, 2475 (void *)&cmd_config_thresh_all, 2476 (void *)&cmd_config_thresh_name, 2477 (void *)&cmd_config_thresh_value, 2478 NULL, 2479 }, 2480 }; 2481 2482 /* *** configure free/rs threshold *** */ 2483 struct cmd_config_threshold { 2484 cmdline_fixed_string_t port; 2485 cmdline_fixed_string_t keyword; 2486 cmdline_fixed_string_t all; 2487 cmdline_fixed_string_t name; 2488 uint16_t value; 2489 }; 2490 2491 static void 2492 cmd_config_threshold_parsed(void *parsed_result, 2493 __attribute__((unused)) struct cmdline *cl, 2494 __attribute__((unused)) void *data) 2495 { 2496 struct cmd_config_threshold *res = parsed_result; 2497 2498 if (!all_ports_stopped()) { 2499 printf("Please stop all ports first\n"); 2500 return; 2501 } 2502 2503 if (!strcmp(res->name, "txfreet")) 2504 tx_free_thresh = res->value; 2505 else if (!strcmp(res->name, "txrst")) 2506 tx_rs_thresh = res->value; 2507 else if (!strcmp(res->name, "rxfreet")) 2508 rx_free_thresh = res->value; 2509 else { 2510 printf("Unknown parameter\n"); 2511 return; 2512 } 2513 2514 init_port_config(); 2515 2516 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2517 } 2518 2519 cmdline_parse_token_string_t cmd_config_threshold_port = 2520 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 2521 cmdline_parse_token_string_t cmd_config_threshold_keyword = 2522 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 2523 "config"); 2524 cmdline_parse_token_string_t cmd_config_threshold_all = 2525 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 2526 cmdline_parse_token_string_t cmd_config_threshold_name = 2527 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 2528 "txfreet#txrst#rxfreet"); 2529 cmdline_parse_token_num_t cmd_config_threshold_value = 2530 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 2531 2532 cmdline_parse_inst_t cmd_config_threshold = { 2533 .f = cmd_config_threshold_parsed, 2534 .data = NULL, 2535 .help_str = "port config all txfreet|txrst|rxfreet <value>", 2536 .tokens = { 2537 (void *)&cmd_config_threshold_port, 2538 (void *)&cmd_config_threshold_keyword, 2539 (void *)&cmd_config_threshold_all, 2540 (void *)&cmd_config_threshold_name, 2541 (void *)&cmd_config_threshold_value, 2542 NULL, 2543 }, 2544 }; 2545 2546 /* *** stop *** */ 2547 struct cmd_stop_result { 2548 cmdline_fixed_string_t stop; 2549 }; 2550 2551 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 2552 __attribute__((unused)) struct cmdline *cl, 2553 __attribute__((unused)) void *data) 2554 { 2555 stop_packet_forwarding(); 2556 } 2557 2558 cmdline_parse_token_string_t cmd_stop_stop = 2559 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 2560 2561 cmdline_parse_inst_t cmd_stop = { 2562 .f = cmd_stop_parsed, 2563 .data = NULL, 2564 .help_str = "stop: Stop packet forwarding", 2565 .tokens = { 2566 (void *)&cmd_stop_stop, 2567 NULL, 2568 }, 2569 }; 2570 2571 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 2572 2573 unsigned int 2574 parse_item_list(char* str, const char* item_name, unsigned int max_items, 2575 unsigned int *parsed_items, int check_unique_values) 2576 { 2577 unsigned int nb_item; 2578 unsigned int value; 2579 unsigned int i; 2580 unsigned int j; 2581 int value_ok; 2582 char c; 2583 2584 /* 2585 * First parse all items in the list and store their value. 2586 */ 2587 value = 0; 2588 nb_item = 0; 2589 value_ok = 0; 2590 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 2591 c = str[i]; 2592 if ((c >= '0') && (c <= '9')) { 2593 value = (unsigned int) (value * 10 + (c - '0')); 2594 value_ok = 1; 2595 continue; 2596 } 2597 if (c != ',') { 2598 printf("character %c is not a decimal digit\n", c); 2599 return 0; 2600 } 2601 if (! value_ok) { 2602 printf("No valid value before comma\n"); 2603 return 0; 2604 } 2605 if (nb_item < max_items) { 2606 parsed_items[nb_item] = value; 2607 value_ok = 0; 2608 value = 0; 2609 } 2610 nb_item++; 2611 } 2612 if (nb_item >= max_items) { 2613 printf("Number of %s = %u > %u (maximum items)\n", 2614 item_name, nb_item + 1, max_items); 2615 return 0; 2616 } 2617 parsed_items[nb_item++] = value; 2618 if (! check_unique_values) 2619 return nb_item; 2620 2621 /* 2622 * Then, check that all values in the list are differents. 2623 * No optimization here... 2624 */ 2625 for (i = 0; i < nb_item; i++) { 2626 for (j = i + 1; j < nb_item; j++) { 2627 if (parsed_items[j] == parsed_items[i]) { 2628 printf("duplicated %s %u at index %u and %u\n", 2629 item_name, parsed_items[i], i, j); 2630 return 0; 2631 } 2632 } 2633 } 2634 return nb_item; 2635 } 2636 2637 struct cmd_set_list_result { 2638 cmdline_fixed_string_t cmd_keyword; 2639 cmdline_fixed_string_t list_name; 2640 cmdline_fixed_string_t list_of_items; 2641 }; 2642 2643 static void cmd_set_list_parsed(void *parsed_result, 2644 __attribute__((unused)) struct cmdline *cl, 2645 __attribute__((unused)) void *data) 2646 { 2647 struct cmd_set_list_result *res; 2648 union { 2649 unsigned int lcorelist[RTE_MAX_LCORE]; 2650 unsigned int portlist[RTE_MAX_ETHPORTS]; 2651 } parsed_items; 2652 unsigned int nb_item; 2653 2654 if (test_done == 0) { 2655 printf("Please stop forwarding first\n"); 2656 return; 2657 } 2658 2659 res = parsed_result; 2660 if (!strcmp(res->list_name, "corelist")) { 2661 nb_item = parse_item_list(res->list_of_items, "core", 2662 RTE_MAX_LCORE, 2663 parsed_items.lcorelist, 1); 2664 if (nb_item > 0) { 2665 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 2666 fwd_config_setup(); 2667 } 2668 return; 2669 } 2670 if (!strcmp(res->list_name, "portlist")) { 2671 nb_item = parse_item_list(res->list_of_items, "port", 2672 RTE_MAX_ETHPORTS, 2673 parsed_items.portlist, 1); 2674 if (nb_item > 0) { 2675 set_fwd_ports_list(parsed_items.portlist, nb_item); 2676 fwd_config_setup(); 2677 } 2678 } 2679 } 2680 2681 cmdline_parse_token_string_t cmd_set_list_keyword = 2682 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 2683 "set"); 2684 cmdline_parse_token_string_t cmd_set_list_name = 2685 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 2686 "corelist#portlist"); 2687 cmdline_parse_token_string_t cmd_set_list_of_items = 2688 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 2689 NULL); 2690 2691 cmdline_parse_inst_t cmd_set_fwd_list = { 2692 .f = cmd_set_list_parsed, 2693 .data = NULL, 2694 .help_str = "set corelist|portlist <list0[,list1]*>", 2695 .tokens = { 2696 (void *)&cmd_set_list_keyword, 2697 (void *)&cmd_set_list_name, 2698 (void *)&cmd_set_list_of_items, 2699 NULL, 2700 }, 2701 }; 2702 2703 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 2704 2705 struct cmd_setmask_result { 2706 cmdline_fixed_string_t set; 2707 cmdline_fixed_string_t mask; 2708 uint64_t hexavalue; 2709 }; 2710 2711 static void cmd_set_mask_parsed(void *parsed_result, 2712 __attribute__((unused)) struct cmdline *cl, 2713 __attribute__((unused)) void *data) 2714 { 2715 struct cmd_setmask_result *res = parsed_result; 2716 2717 if (test_done == 0) { 2718 printf("Please stop forwarding first\n"); 2719 return; 2720 } 2721 if (!strcmp(res->mask, "coremask")) { 2722 set_fwd_lcores_mask(res->hexavalue); 2723 fwd_config_setup(); 2724 } else if (!strcmp(res->mask, "portmask")) { 2725 set_fwd_ports_mask(res->hexavalue); 2726 fwd_config_setup(); 2727 } 2728 } 2729 2730 cmdline_parse_token_string_t cmd_setmask_set = 2731 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 2732 cmdline_parse_token_string_t cmd_setmask_mask = 2733 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 2734 "coremask#portmask"); 2735 cmdline_parse_token_num_t cmd_setmask_value = 2736 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 2737 2738 cmdline_parse_inst_t cmd_set_fwd_mask = { 2739 .f = cmd_set_mask_parsed, 2740 .data = NULL, 2741 .help_str = "set coremask|portmask <hexadecimal value>", 2742 .tokens = { 2743 (void *)&cmd_setmask_set, 2744 (void *)&cmd_setmask_mask, 2745 (void *)&cmd_setmask_value, 2746 NULL, 2747 }, 2748 }; 2749 2750 /* 2751 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 2752 */ 2753 struct cmd_set_result { 2754 cmdline_fixed_string_t set; 2755 cmdline_fixed_string_t what; 2756 uint16_t value; 2757 }; 2758 2759 static void cmd_set_parsed(void *parsed_result, 2760 __attribute__((unused)) struct cmdline *cl, 2761 __attribute__((unused)) void *data) 2762 { 2763 struct cmd_set_result *res = parsed_result; 2764 if (!strcmp(res->what, "nbport")) { 2765 set_fwd_ports_number(res->value); 2766 fwd_config_setup(); 2767 } else if (!strcmp(res->what, "nbcore")) { 2768 set_fwd_lcores_number(res->value); 2769 fwd_config_setup(); 2770 } else if (!strcmp(res->what, "burst")) 2771 set_nb_pkt_per_burst(res->value); 2772 else if (!strcmp(res->what, "verbose")) 2773 set_verbose_level(res->value); 2774 } 2775 2776 cmdline_parse_token_string_t cmd_set_set = 2777 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 2778 cmdline_parse_token_string_t cmd_set_what = 2779 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 2780 "nbport#nbcore#burst#verbose"); 2781 cmdline_parse_token_num_t cmd_set_value = 2782 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 2783 2784 cmdline_parse_inst_t cmd_set_numbers = { 2785 .f = cmd_set_parsed, 2786 .data = NULL, 2787 .help_str = "set nbport|nbcore|burst|verbose <value>", 2788 .tokens = { 2789 (void *)&cmd_set_set, 2790 (void *)&cmd_set_what, 2791 (void *)&cmd_set_value, 2792 NULL, 2793 }, 2794 }; 2795 2796 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 2797 2798 struct cmd_set_txpkts_result { 2799 cmdline_fixed_string_t cmd_keyword; 2800 cmdline_fixed_string_t txpkts; 2801 cmdline_fixed_string_t seg_lengths; 2802 }; 2803 2804 static void 2805 cmd_set_txpkts_parsed(void *parsed_result, 2806 __attribute__((unused)) struct cmdline *cl, 2807 __attribute__((unused)) void *data) 2808 { 2809 struct cmd_set_txpkts_result *res; 2810 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 2811 unsigned int nb_segs; 2812 2813 res = parsed_result; 2814 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 2815 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 2816 if (nb_segs > 0) 2817 set_tx_pkt_segments(seg_lengths, nb_segs); 2818 } 2819 2820 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 2821 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2822 cmd_keyword, "set"); 2823 cmdline_parse_token_string_t cmd_set_txpkts_name = 2824 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2825 txpkts, "txpkts"); 2826 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 2827 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2828 seg_lengths, NULL); 2829 2830 cmdline_parse_inst_t cmd_set_txpkts = { 2831 .f = cmd_set_txpkts_parsed, 2832 .data = NULL, 2833 .help_str = "set txpkts <len0[,len1]*>", 2834 .tokens = { 2835 (void *)&cmd_set_txpkts_keyword, 2836 (void *)&cmd_set_txpkts_name, 2837 (void *)&cmd_set_txpkts_lengths, 2838 NULL, 2839 }, 2840 }; 2841 2842 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 2843 2844 struct cmd_set_txsplit_result { 2845 cmdline_fixed_string_t cmd_keyword; 2846 cmdline_fixed_string_t txsplit; 2847 cmdline_fixed_string_t mode; 2848 }; 2849 2850 static void 2851 cmd_set_txsplit_parsed(void *parsed_result, 2852 __attribute__((unused)) struct cmdline *cl, 2853 __attribute__((unused)) void *data) 2854 { 2855 struct cmd_set_txsplit_result *res; 2856 2857 res = parsed_result; 2858 set_tx_pkt_split(res->mode); 2859 } 2860 2861 cmdline_parse_token_string_t cmd_set_txsplit_keyword = 2862 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2863 cmd_keyword, "set"); 2864 cmdline_parse_token_string_t cmd_set_txsplit_name = 2865 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2866 txsplit, "txsplit"); 2867 cmdline_parse_token_string_t cmd_set_txsplit_mode = 2868 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2869 mode, NULL); 2870 2871 cmdline_parse_inst_t cmd_set_txsplit = { 2872 .f = cmd_set_txsplit_parsed, 2873 .data = NULL, 2874 .help_str = "set txsplit on|off|rand", 2875 .tokens = { 2876 (void *)&cmd_set_txsplit_keyword, 2877 (void *)&cmd_set_txsplit_name, 2878 (void *)&cmd_set_txsplit_mode, 2879 NULL, 2880 }, 2881 }; 2882 2883 /* *** CONFIG TX QUEUE FLAGS *** */ 2884 2885 struct cmd_config_txqflags_result { 2886 cmdline_fixed_string_t port; 2887 cmdline_fixed_string_t config; 2888 cmdline_fixed_string_t all; 2889 cmdline_fixed_string_t what; 2890 int32_t hexvalue; 2891 }; 2892 2893 static void cmd_config_txqflags_parsed(void *parsed_result, 2894 __attribute__((unused)) struct cmdline *cl, 2895 __attribute__((unused)) void *data) 2896 { 2897 struct cmd_config_txqflags_result *res = parsed_result; 2898 2899 if (!all_ports_stopped()) { 2900 printf("Please stop all ports first\n"); 2901 return; 2902 } 2903 2904 if (strcmp(res->what, "txqflags")) { 2905 printf("Unknown parameter\n"); 2906 return; 2907 } 2908 2909 if (res->hexvalue >= 0) { 2910 txq_flags = res->hexvalue; 2911 } else { 2912 printf("txqflags must be >= 0\n"); 2913 return; 2914 } 2915 2916 init_port_config(); 2917 2918 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2919 } 2920 2921 cmdline_parse_token_string_t cmd_config_txqflags_port = 2922 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port, 2923 "port"); 2924 cmdline_parse_token_string_t cmd_config_txqflags_config = 2925 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config, 2926 "config"); 2927 cmdline_parse_token_string_t cmd_config_txqflags_all = 2928 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all, 2929 "all"); 2930 cmdline_parse_token_string_t cmd_config_txqflags_what = 2931 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what, 2932 "txqflags"); 2933 cmdline_parse_token_num_t cmd_config_txqflags_value = 2934 TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result, 2935 hexvalue, INT32); 2936 2937 cmdline_parse_inst_t cmd_config_txqflags = { 2938 .f = cmd_config_txqflags_parsed, 2939 .data = NULL, 2940 .help_str = "port config all txqflags <value>", 2941 .tokens = { 2942 (void *)&cmd_config_txqflags_port, 2943 (void *)&cmd_config_txqflags_config, 2944 (void *)&cmd_config_txqflags_all, 2945 (void *)&cmd_config_txqflags_what, 2946 (void *)&cmd_config_txqflags_value, 2947 NULL, 2948 }, 2949 }; 2950 2951 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 2952 struct cmd_rx_vlan_filter_all_result { 2953 cmdline_fixed_string_t rx_vlan; 2954 cmdline_fixed_string_t what; 2955 cmdline_fixed_string_t all; 2956 uint8_t port_id; 2957 }; 2958 2959 static void 2960 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 2961 __attribute__((unused)) struct cmdline *cl, 2962 __attribute__((unused)) void *data) 2963 { 2964 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 2965 2966 if (!strcmp(res->what, "add")) 2967 rx_vlan_all_filter_set(res->port_id, 1); 2968 else 2969 rx_vlan_all_filter_set(res->port_id, 0); 2970 } 2971 2972 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 2973 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2974 rx_vlan, "rx_vlan"); 2975 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 2976 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2977 what, "add#rm"); 2978 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 2979 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2980 all, "all"); 2981 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 2982 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 2983 port_id, UINT8); 2984 2985 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 2986 .f = cmd_rx_vlan_filter_all_parsed, 2987 .data = NULL, 2988 .help_str = "rx_vlan add|rm all <port_id>: " 2989 "Add/Remove all identifiers to/from the set of VLAN " 2990 "identifiers filtered by a port", 2991 .tokens = { 2992 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 2993 (void *)&cmd_rx_vlan_filter_all_what, 2994 (void *)&cmd_rx_vlan_filter_all_all, 2995 (void *)&cmd_rx_vlan_filter_all_portid, 2996 NULL, 2997 }, 2998 }; 2999 3000 /* *** VLAN OFFLOAD SET ON A PORT *** */ 3001 struct cmd_vlan_offload_result { 3002 cmdline_fixed_string_t vlan; 3003 cmdline_fixed_string_t set; 3004 cmdline_fixed_string_t vlan_type; 3005 cmdline_fixed_string_t what; 3006 cmdline_fixed_string_t on; 3007 cmdline_fixed_string_t port_id; 3008 }; 3009 3010 static void 3011 cmd_vlan_offload_parsed(void *parsed_result, 3012 __attribute__((unused)) struct cmdline *cl, 3013 __attribute__((unused)) void *data) 3014 { 3015 int on; 3016 struct cmd_vlan_offload_result *res = parsed_result; 3017 char *str; 3018 int i, len = 0; 3019 portid_t port_id = 0; 3020 unsigned int tmp; 3021 3022 str = res->port_id; 3023 len = strnlen(str, STR_TOKEN_SIZE); 3024 i = 0; 3025 /* Get port_id first */ 3026 while(i < len){ 3027 if(str[i] == ',') 3028 break; 3029 3030 i++; 3031 } 3032 str[i]='\0'; 3033 tmp = strtoul(str, NULL, 0); 3034 /* If port_id greater that what portid_t can represent, return */ 3035 if(tmp >= RTE_MAX_ETHPORTS) 3036 return; 3037 port_id = (portid_t)tmp; 3038 3039 if (!strcmp(res->on, "on")) 3040 on = 1; 3041 else 3042 on = 0; 3043 3044 if (!strcmp(res->what, "strip")) 3045 rx_vlan_strip_set(port_id, on); 3046 else if(!strcmp(res->what, "stripq")){ 3047 uint16_t queue_id = 0; 3048 3049 /* No queue_id, return */ 3050 if(i + 1 >= len) { 3051 printf("must specify (port,queue_id)\n"); 3052 return; 3053 } 3054 tmp = strtoul(str + i + 1, NULL, 0); 3055 /* If queue_id greater that what 16-bits can represent, return */ 3056 if(tmp > 0xffff) 3057 return; 3058 3059 queue_id = (uint16_t)tmp; 3060 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 3061 } 3062 else if (!strcmp(res->what, "filter")) 3063 rx_vlan_filter_set(port_id, on); 3064 else 3065 vlan_extend_set(port_id, on); 3066 3067 return; 3068 } 3069 3070 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 3071 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3072 vlan, "vlan"); 3073 cmdline_parse_token_string_t cmd_vlan_offload_set = 3074 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3075 set, "set"); 3076 cmdline_parse_token_string_t cmd_vlan_offload_what = 3077 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3078 what, "strip#filter#qinq#stripq"); 3079 cmdline_parse_token_string_t cmd_vlan_offload_on = 3080 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3081 on, "on#off"); 3082 cmdline_parse_token_string_t cmd_vlan_offload_portid = 3083 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3084 port_id, NULL); 3085 3086 cmdline_parse_inst_t cmd_vlan_offload = { 3087 .f = cmd_vlan_offload_parsed, 3088 .data = NULL, 3089 .help_str = "vlan set strip|filter|qinq|stripq on|off " 3090 "<port_id[,queue_id]>: " 3091 "Filter/Strip for rx side qinq(extended) for both rx/tx sides", 3092 .tokens = { 3093 (void *)&cmd_vlan_offload_vlan, 3094 (void *)&cmd_vlan_offload_set, 3095 (void *)&cmd_vlan_offload_what, 3096 (void *)&cmd_vlan_offload_on, 3097 (void *)&cmd_vlan_offload_portid, 3098 NULL, 3099 }, 3100 }; 3101 3102 /* *** VLAN TPID SET ON A PORT *** */ 3103 struct cmd_vlan_tpid_result { 3104 cmdline_fixed_string_t vlan; 3105 cmdline_fixed_string_t set; 3106 cmdline_fixed_string_t vlan_type; 3107 cmdline_fixed_string_t what; 3108 uint16_t tp_id; 3109 uint8_t port_id; 3110 }; 3111 3112 static void 3113 cmd_vlan_tpid_parsed(void *parsed_result, 3114 __attribute__((unused)) struct cmdline *cl, 3115 __attribute__((unused)) void *data) 3116 { 3117 struct cmd_vlan_tpid_result *res = parsed_result; 3118 enum rte_vlan_type vlan_type; 3119 3120 if (!strcmp(res->vlan_type, "inner")) 3121 vlan_type = ETH_VLAN_TYPE_INNER; 3122 else if (!strcmp(res->vlan_type, "outer")) 3123 vlan_type = ETH_VLAN_TYPE_OUTER; 3124 else { 3125 printf("Unknown vlan type\n"); 3126 return; 3127 } 3128 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 3129 } 3130 3131 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 3132 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3133 vlan, "vlan"); 3134 cmdline_parse_token_string_t cmd_vlan_tpid_set = 3135 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3136 set, "set"); 3137 cmdline_parse_token_string_t cmd_vlan_type = 3138 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3139 vlan_type, "inner#outer"); 3140 cmdline_parse_token_string_t cmd_vlan_tpid_what = 3141 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3142 what, "tpid"); 3143 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 3144 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3145 tp_id, UINT16); 3146 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 3147 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3148 port_id, UINT8); 3149 3150 cmdline_parse_inst_t cmd_vlan_tpid = { 3151 .f = cmd_vlan_tpid_parsed, 3152 .data = NULL, 3153 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 3154 "Set the VLAN Ether type", 3155 .tokens = { 3156 (void *)&cmd_vlan_tpid_vlan, 3157 (void *)&cmd_vlan_tpid_set, 3158 (void *)&cmd_vlan_type, 3159 (void *)&cmd_vlan_tpid_what, 3160 (void *)&cmd_vlan_tpid_tpid, 3161 (void *)&cmd_vlan_tpid_portid, 3162 NULL, 3163 }, 3164 }; 3165 3166 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 3167 struct cmd_rx_vlan_filter_result { 3168 cmdline_fixed_string_t rx_vlan; 3169 cmdline_fixed_string_t what; 3170 uint16_t vlan_id; 3171 uint8_t port_id; 3172 }; 3173 3174 static void 3175 cmd_rx_vlan_filter_parsed(void *parsed_result, 3176 __attribute__((unused)) struct cmdline *cl, 3177 __attribute__((unused)) void *data) 3178 { 3179 struct cmd_rx_vlan_filter_result *res = parsed_result; 3180 3181 if (!strcmp(res->what, "add")) 3182 rx_vft_set(res->port_id, res->vlan_id, 1); 3183 else 3184 rx_vft_set(res->port_id, res->vlan_id, 0); 3185 } 3186 3187 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 3188 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3189 rx_vlan, "rx_vlan"); 3190 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 3191 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3192 what, "add#rm"); 3193 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 3194 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3195 vlan_id, UINT16); 3196 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 3197 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3198 port_id, UINT8); 3199 3200 cmdline_parse_inst_t cmd_rx_vlan_filter = { 3201 .f = cmd_rx_vlan_filter_parsed, 3202 .data = NULL, 3203 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 3204 "Add/Remove a VLAN identifier to/from the set of VLAN " 3205 "identifiers filtered by a port", 3206 .tokens = { 3207 (void *)&cmd_rx_vlan_filter_rx_vlan, 3208 (void *)&cmd_rx_vlan_filter_what, 3209 (void *)&cmd_rx_vlan_filter_vlanid, 3210 (void *)&cmd_rx_vlan_filter_portid, 3211 NULL, 3212 }, 3213 }; 3214 3215 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3216 struct cmd_tx_vlan_set_result { 3217 cmdline_fixed_string_t tx_vlan; 3218 cmdline_fixed_string_t set; 3219 uint8_t port_id; 3220 uint16_t vlan_id; 3221 }; 3222 3223 static void 3224 cmd_tx_vlan_set_parsed(void *parsed_result, 3225 __attribute__((unused)) struct cmdline *cl, 3226 __attribute__((unused)) void *data) 3227 { 3228 struct cmd_tx_vlan_set_result *res = parsed_result; 3229 3230 tx_vlan_set(res->port_id, res->vlan_id); 3231 } 3232 3233 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 3234 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3235 tx_vlan, "tx_vlan"); 3236 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 3237 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3238 set, "set"); 3239 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 3240 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3241 port_id, UINT8); 3242 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 3243 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3244 vlan_id, UINT16); 3245 3246 cmdline_parse_inst_t cmd_tx_vlan_set = { 3247 .f = cmd_tx_vlan_set_parsed, 3248 .data = NULL, 3249 .help_str = "tx_vlan set <port_id> <vlan_id>: " 3250 "Enable hardware insertion of a single VLAN header " 3251 "with a given TAG Identifier in packets sent on a port", 3252 .tokens = { 3253 (void *)&cmd_tx_vlan_set_tx_vlan, 3254 (void *)&cmd_tx_vlan_set_set, 3255 (void *)&cmd_tx_vlan_set_portid, 3256 (void *)&cmd_tx_vlan_set_vlanid, 3257 NULL, 3258 }, 3259 }; 3260 3261 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 3262 struct cmd_tx_vlan_set_qinq_result { 3263 cmdline_fixed_string_t tx_vlan; 3264 cmdline_fixed_string_t set; 3265 uint8_t port_id; 3266 uint16_t vlan_id; 3267 uint16_t vlan_id_outer; 3268 }; 3269 3270 static void 3271 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 3272 __attribute__((unused)) struct cmdline *cl, 3273 __attribute__((unused)) void *data) 3274 { 3275 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 3276 3277 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 3278 } 3279 3280 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 3281 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3282 tx_vlan, "tx_vlan"); 3283 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 3284 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3285 set, "set"); 3286 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 3287 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3288 port_id, UINT8); 3289 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 3290 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3291 vlan_id, UINT16); 3292 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 3293 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3294 vlan_id_outer, UINT16); 3295 3296 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 3297 .f = cmd_tx_vlan_set_qinq_parsed, 3298 .data = NULL, 3299 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 3300 "Enable hardware insertion of double VLAN header " 3301 "with given TAG Identifiers in packets sent on a port", 3302 .tokens = { 3303 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 3304 (void *)&cmd_tx_vlan_set_qinq_set, 3305 (void *)&cmd_tx_vlan_set_qinq_portid, 3306 (void *)&cmd_tx_vlan_set_qinq_vlanid, 3307 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 3308 NULL, 3309 }, 3310 }; 3311 3312 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 3313 struct cmd_tx_vlan_set_pvid_result { 3314 cmdline_fixed_string_t tx_vlan; 3315 cmdline_fixed_string_t set; 3316 cmdline_fixed_string_t pvid; 3317 uint8_t port_id; 3318 uint16_t vlan_id; 3319 cmdline_fixed_string_t mode; 3320 }; 3321 3322 static void 3323 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 3324 __attribute__((unused)) struct cmdline *cl, 3325 __attribute__((unused)) void *data) 3326 { 3327 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 3328 3329 if (strcmp(res->mode, "on") == 0) 3330 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 3331 else 3332 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 3333 } 3334 3335 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 3336 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3337 tx_vlan, "tx_vlan"); 3338 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 3339 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3340 set, "set"); 3341 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 3342 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3343 pvid, "pvid"); 3344 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 3345 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3346 port_id, UINT8); 3347 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 3348 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3349 vlan_id, UINT16); 3350 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 3351 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3352 mode, "on#off"); 3353 3354 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 3355 .f = cmd_tx_vlan_set_pvid_parsed, 3356 .data = NULL, 3357 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 3358 .tokens = { 3359 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 3360 (void *)&cmd_tx_vlan_set_pvid_set, 3361 (void *)&cmd_tx_vlan_set_pvid_pvid, 3362 (void *)&cmd_tx_vlan_set_pvid_port_id, 3363 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 3364 (void *)&cmd_tx_vlan_set_pvid_mode, 3365 NULL, 3366 }, 3367 }; 3368 3369 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3370 struct cmd_tx_vlan_reset_result { 3371 cmdline_fixed_string_t tx_vlan; 3372 cmdline_fixed_string_t reset; 3373 uint8_t port_id; 3374 }; 3375 3376 static void 3377 cmd_tx_vlan_reset_parsed(void *parsed_result, 3378 __attribute__((unused)) struct cmdline *cl, 3379 __attribute__((unused)) void *data) 3380 { 3381 struct cmd_tx_vlan_reset_result *res = parsed_result; 3382 3383 tx_vlan_reset(res->port_id); 3384 } 3385 3386 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 3387 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3388 tx_vlan, "tx_vlan"); 3389 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 3390 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3391 reset, "reset"); 3392 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 3393 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 3394 port_id, UINT8); 3395 3396 cmdline_parse_inst_t cmd_tx_vlan_reset = { 3397 .f = cmd_tx_vlan_reset_parsed, 3398 .data = NULL, 3399 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 3400 "VLAN header in packets sent on a port", 3401 .tokens = { 3402 (void *)&cmd_tx_vlan_reset_tx_vlan, 3403 (void *)&cmd_tx_vlan_reset_reset, 3404 (void *)&cmd_tx_vlan_reset_portid, 3405 NULL, 3406 }, 3407 }; 3408 3409 3410 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 3411 struct cmd_csum_result { 3412 cmdline_fixed_string_t csum; 3413 cmdline_fixed_string_t mode; 3414 cmdline_fixed_string_t proto; 3415 cmdline_fixed_string_t hwsw; 3416 uint8_t port_id; 3417 }; 3418 3419 static void 3420 csum_show(int port_id) 3421 { 3422 struct rte_eth_dev_info dev_info; 3423 uint16_t ol_flags; 3424 3425 ol_flags = ports[port_id].tx_ol_flags; 3426 printf("Parse tunnel is %s\n", 3427 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off"); 3428 printf("IP checksum offload is %s\n", 3429 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw"); 3430 printf("UDP checksum offload is %s\n", 3431 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 3432 printf("TCP checksum offload is %s\n", 3433 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 3434 printf("SCTP checksum offload is %s\n", 3435 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 3436 printf("Outer-Ip checksum offload is %s\n", 3437 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw"); 3438 3439 /* display warnings if configuration is not supported by the NIC */ 3440 rte_eth_dev_info_get(port_id, &dev_info); 3441 if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) && 3442 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) { 3443 printf("Warning: hardware IP checksum enabled but not " 3444 "supported by port %d\n", port_id); 3445 } 3446 if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) && 3447 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) { 3448 printf("Warning: hardware UDP checksum enabled but not " 3449 "supported by port %d\n", port_id); 3450 } 3451 if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) && 3452 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) { 3453 printf("Warning: hardware TCP checksum enabled but not " 3454 "supported by port %d\n", port_id); 3455 } 3456 if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) && 3457 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) { 3458 printf("Warning: hardware SCTP checksum enabled but not " 3459 "supported by port %d\n", port_id); 3460 } 3461 if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) && 3462 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 3463 printf("Warning: hardware outer IP checksum enabled but not " 3464 "supported by port %d\n", port_id); 3465 } 3466 } 3467 3468 static void 3469 cmd_csum_parsed(void *parsed_result, 3470 __attribute__((unused)) struct cmdline *cl, 3471 __attribute__((unused)) void *data) 3472 { 3473 struct cmd_csum_result *res = parsed_result; 3474 int hw = 0; 3475 uint16_t mask = 0; 3476 3477 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 3478 printf("invalid port %d\n", res->port_id); 3479 return; 3480 } 3481 3482 if (!strcmp(res->mode, "set")) { 3483 3484 if (!strcmp(res->hwsw, "hw")) 3485 hw = 1; 3486 3487 if (!strcmp(res->proto, "ip")) { 3488 mask = TESTPMD_TX_OFFLOAD_IP_CKSUM; 3489 } else if (!strcmp(res->proto, "udp")) { 3490 mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM; 3491 } else if (!strcmp(res->proto, "tcp")) { 3492 mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM; 3493 } else if (!strcmp(res->proto, "sctp")) { 3494 mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM; 3495 } else if (!strcmp(res->proto, "outer-ip")) { 3496 mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM; 3497 } 3498 3499 if (hw) 3500 ports[res->port_id].tx_ol_flags |= mask; 3501 else 3502 ports[res->port_id].tx_ol_flags &= (~mask); 3503 } 3504 csum_show(res->port_id); 3505 } 3506 3507 cmdline_parse_token_string_t cmd_csum_csum = 3508 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3509 csum, "csum"); 3510 cmdline_parse_token_string_t cmd_csum_mode = 3511 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3512 mode, "set"); 3513 cmdline_parse_token_string_t cmd_csum_proto = 3514 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3515 proto, "ip#tcp#udp#sctp#outer-ip"); 3516 cmdline_parse_token_string_t cmd_csum_hwsw = 3517 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3518 hwsw, "hw#sw"); 3519 cmdline_parse_token_num_t cmd_csum_portid = 3520 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 3521 port_id, UINT8); 3522 3523 cmdline_parse_inst_t cmd_csum_set = { 3524 .f = cmd_csum_parsed, 3525 .data = NULL, 3526 .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: " 3527 "Enable/Disable hardware calculation of L3/L4 checksum when " 3528 "using csum forward engine", 3529 .tokens = { 3530 (void *)&cmd_csum_csum, 3531 (void *)&cmd_csum_mode, 3532 (void *)&cmd_csum_proto, 3533 (void *)&cmd_csum_hwsw, 3534 (void *)&cmd_csum_portid, 3535 NULL, 3536 }, 3537 }; 3538 3539 cmdline_parse_token_string_t cmd_csum_mode_show = 3540 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3541 mode, "show"); 3542 3543 cmdline_parse_inst_t cmd_csum_show = { 3544 .f = cmd_csum_parsed, 3545 .data = NULL, 3546 .help_str = "csum show <port_id>: Show checksum offload configuration", 3547 .tokens = { 3548 (void *)&cmd_csum_csum, 3549 (void *)&cmd_csum_mode_show, 3550 (void *)&cmd_csum_portid, 3551 NULL, 3552 }, 3553 }; 3554 3555 /* Enable/disable tunnel parsing */ 3556 struct cmd_csum_tunnel_result { 3557 cmdline_fixed_string_t csum; 3558 cmdline_fixed_string_t parse; 3559 cmdline_fixed_string_t onoff; 3560 uint8_t port_id; 3561 }; 3562 3563 static void 3564 cmd_csum_tunnel_parsed(void *parsed_result, 3565 __attribute__((unused)) struct cmdline *cl, 3566 __attribute__((unused)) void *data) 3567 { 3568 struct cmd_csum_tunnel_result *res = parsed_result; 3569 3570 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3571 return; 3572 3573 if (!strcmp(res->onoff, "on")) 3574 ports[res->port_id].tx_ol_flags |= 3575 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL; 3576 else 3577 ports[res->port_id].tx_ol_flags &= 3578 (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL); 3579 3580 csum_show(res->port_id); 3581 } 3582 3583 cmdline_parse_token_string_t cmd_csum_tunnel_csum = 3584 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3585 csum, "csum"); 3586 cmdline_parse_token_string_t cmd_csum_tunnel_parse = 3587 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3588 parse, "parse_tunnel"); 3589 cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 3590 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3591 onoff, "on#off"); 3592 cmdline_parse_token_num_t cmd_csum_tunnel_portid = 3593 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 3594 port_id, UINT8); 3595 3596 cmdline_parse_inst_t cmd_csum_tunnel = { 3597 .f = cmd_csum_tunnel_parsed, 3598 .data = NULL, 3599 .help_str = "csum parse_tunnel on|off <port_id>: " 3600 "Enable/Disable parsing of tunnels for csum engine", 3601 .tokens = { 3602 (void *)&cmd_csum_tunnel_csum, 3603 (void *)&cmd_csum_tunnel_parse, 3604 (void *)&cmd_csum_tunnel_onoff, 3605 (void *)&cmd_csum_tunnel_portid, 3606 NULL, 3607 }, 3608 }; 3609 3610 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 3611 struct cmd_tso_set_result { 3612 cmdline_fixed_string_t tso; 3613 cmdline_fixed_string_t mode; 3614 uint16_t tso_segsz; 3615 uint8_t port_id; 3616 }; 3617 3618 static void 3619 cmd_tso_set_parsed(void *parsed_result, 3620 __attribute__((unused)) struct cmdline *cl, 3621 __attribute__((unused)) void *data) 3622 { 3623 struct cmd_tso_set_result *res = parsed_result; 3624 struct rte_eth_dev_info dev_info; 3625 3626 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3627 return; 3628 3629 if (!strcmp(res->mode, "set")) 3630 ports[res->port_id].tso_segsz = res->tso_segsz; 3631 3632 if (ports[res->port_id].tso_segsz == 0) 3633 printf("TSO for non-tunneled packets is disabled\n"); 3634 else 3635 printf("TSO segment size for non-tunneled packets is %d\n", 3636 ports[res->port_id].tso_segsz); 3637 3638 /* display warnings if configuration is not supported by the NIC */ 3639 rte_eth_dev_info_get(res->port_id, &dev_info); 3640 if ((ports[res->port_id].tso_segsz != 0) && 3641 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3642 printf("Warning: TSO enabled but not " 3643 "supported by port %d\n", res->port_id); 3644 } 3645 } 3646 3647 cmdline_parse_token_string_t cmd_tso_set_tso = 3648 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3649 tso, "tso"); 3650 cmdline_parse_token_string_t cmd_tso_set_mode = 3651 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3652 mode, "set"); 3653 cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 3654 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3655 tso_segsz, UINT16); 3656 cmdline_parse_token_num_t cmd_tso_set_portid = 3657 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3658 port_id, UINT8); 3659 3660 cmdline_parse_inst_t cmd_tso_set = { 3661 .f = cmd_tso_set_parsed, 3662 .data = NULL, 3663 .help_str = "tso set <tso_segsz> <port_id>: " 3664 "Set TSO segment size of non-tunneled packets for csum engine " 3665 "(0 to disable)", 3666 .tokens = { 3667 (void *)&cmd_tso_set_tso, 3668 (void *)&cmd_tso_set_mode, 3669 (void *)&cmd_tso_set_tso_segsz, 3670 (void *)&cmd_tso_set_portid, 3671 NULL, 3672 }, 3673 }; 3674 3675 cmdline_parse_token_string_t cmd_tso_show_mode = 3676 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3677 mode, "show"); 3678 3679 3680 cmdline_parse_inst_t cmd_tso_show = { 3681 .f = cmd_tso_set_parsed, 3682 .data = NULL, 3683 .help_str = "tso show <port_id>: " 3684 "Show TSO segment size of non-tunneled packets for csum engine", 3685 .tokens = { 3686 (void *)&cmd_tso_set_tso, 3687 (void *)&cmd_tso_show_mode, 3688 (void *)&cmd_tso_set_portid, 3689 NULL, 3690 }, 3691 }; 3692 3693 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 3694 struct cmd_tunnel_tso_set_result { 3695 cmdline_fixed_string_t tso; 3696 cmdline_fixed_string_t mode; 3697 uint16_t tso_segsz; 3698 uint8_t port_id; 3699 }; 3700 3701 static void 3702 check_tunnel_tso_nic_support(uint8_t port_id) 3703 { 3704 struct rte_eth_dev_info dev_info; 3705 3706 rte_eth_dev_info_get(port_id, &dev_info); 3707 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) 3708 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not " 3709 "supported by port %d\n", port_id); 3710 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO)) 3711 printf("Warning: TSO enabled but GRE TUNNEL TSO not " 3712 "supported by port %d\n", port_id); 3713 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO)) 3714 printf("Warning: TSO enabled but IPIP TUNNEL TSO not " 3715 "supported by port %d\n", port_id); 3716 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) 3717 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not " 3718 "supported by port %d\n", port_id); 3719 } 3720 3721 static void 3722 cmd_tunnel_tso_set_parsed(void *parsed_result, 3723 __attribute__((unused)) struct cmdline *cl, 3724 __attribute__((unused)) void *data) 3725 { 3726 struct cmd_tunnel_tso_set_result *res = parsed_result; 3727 3728 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3729 return; 3730 3731 if (!strcmp(res->mode, "set")) 3732 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 3733 3734 if (ports[res->port_id].tunnel_tso_segsz == 0) 3735 printf("TSO for tunneled packets is disabled\n"); 3736 else { 3737 printf("TSO segment size for tunneled packets is %d\n", 3738 ports[res->port_id].tunnel_tso_segsz); 3739 3740 /* Below conditions are needed to make it work: 3741 * (1) tunnel TSO is supported by the NIC; 3742 * (2) "csum parse_tunnel" must be set so that tunneled pkts 3743 * are recognized; 3744 * (3) for tunneled pkts with outer L3 of IPv4, 3745 * "csum set outer-ip" must be set to hw, because after tso, 3746 * total_len of outer IP header is changed, and the checksum 3747 * of outer IP header calculated by sw should be wrong; that 3748 * is not necessary for IPv6 tunneled pkts because there's no 3749 * checksum in IP header anymore. 3750 */ 3751 check_tunnel_tso_nic_support(res->port_id); 3752 3753 if (!(ports[res->port_id].tx_ol_flags & 3754 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL)) 3755 printf("Warning: csum parse_tunnel must be set " 3756 "so that tunneled packets are recognized\n"); 3757 if (!(ports[res->port_id].tx_ol_flags & 3758 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)) 3759 printf("Warning: csum set outer-ip must be set to hw " 3760 "if outer L3 is IPv4; not necessary for IPv6\n"); 3761 } 3762 } 3763 3764 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 3765 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3766 tso, "tunnel_tso"); 3767 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 3768 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3769 mode, "set"); 3770 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 3771 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3772 tso_segsz, UINT16); 3773 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 3774 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3775 port_id, UINT8); 3776 3777 cmdline_parse_inst_t cmd_tunnel_tso_set = { 3778 .f = cmd_tunnel_tso_set_parsed, 3779 .data = NULL, 3780 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 3781 "Set TSO segment size of tunneled packets for csum engine " 3782 "(0 to disable)", 3783 .tokens = { 3784 (void *)&cmd_tunnel_tso_set_tso, 3785 (void *)&cmd_tunnel_tso_set_mode, 3786 (void *)&cmd_tunnel_tso_set_tso_segsz, 3787 (void *)&cmd_tunnel_tso_set_portid, 3788 NULL, 3789 }, 3790 }; 3791 3792 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 3793 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3794 mode, "show"); 3795 3796 3797 cmdline_parse_inst_t cmd_tunnel_tso_show = { 3798 .f = cmd_tunnel_tso_set_parsed, 3799 .data = NULL, 3800 .help_str = "tunnel_tso show <port_id> " 3801 "Show TSO segment size of tunneled packets for csum engine", 3802 .tokens = { 3803 (void *)&cmd_tunnel_tso_set_tso, 3804 (void *)&cmd_tunnel_tso_show_mode, 3805 (void *)&cmd_tunnel_tso_set_portid, 3806 NULL, 3807 }, 3808 }; 3809 3810 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 3811 struct cmd_set_flush_rx { 3812 cmdline_fixed_string_t set; 3813 cmdline_fixed_string_t flush_rx; 3814 cmdline_fixed_string_t mode; 3815 }; 3816 3817 static void 3818 cmd_set_flush_rx_parsed(void *parsed_result, 3819 __attribute__((unused)) struct cmdline *cl, 3820 __attribute__((unused)) void *data) 3821 { 3822 struct cmd_set_flush_rx *res = parsed_result; 3823 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 3824 } 3825 3826 cmdline_parse_token_string_t cmd_setflushrx_set = 3827 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3828 set, "set"); 3829 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 3830 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3831 flush_rx, "flush_rx"); 3832 cmdline_parse_token_string_t cmd_setflushrx_mode = 3833 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 3834 mode, "on#off"); 3835 3836 3837 cmdline_parse_inst_t cmd_set_flush_rx = { 3838 .f = cmd_set_flush_rx_parsed, 3839 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 3840 .data = NULL, 3841 .tokens = { 3842 (void *)&cmd_setflushrx_set, 3843 (void *)&cmd_setflushrx_flush_rx, 3844 (void *)&cmd_setflushrx_mode, 3845 NULL, 3846 }, 3847 }; 3848 3849 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 3850 struct cmd_set_link_check { 3851 cmdline_fixed_string_t set; 3852 cmdline_fixed_string_t link_check; 3853 cmdline_fixed_string_t mode; 3854 }; 3855 3856 static void 3857 cmd_set_link_check_parsed(void *parsed_result, 3858 __attribute__((unused)) struct cmdline *cl, 3859 __attribute__((unused)) void *data) 3860 { 3861 struct cmd_set_link_check *res = parsed_result; 3862 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 3863 } 3864 3865 cmdline_parse_token_string_t cmd_setlinkcheck_set = 3866 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3867 set, "set"); 3868 cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 3869 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3870 link_check, "link_check"); 3871 cmdline_parse_token_string_t cmd_setlinkcheck_mode = 3872 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 3873 mode, "on#off"); 3874 3875 3876 cmdline_parse_inst_t cmd_set_link_check = { 3877 .f = cmd_set_link_check_parsed, 3878 .help_str = "set link_check on|off: Enable/Disable link status check " 3879 "when starting/stopping a port", 3880 .data = NULL, 3881 .tokens = { 3882 (void *)&cmd_setlinkcheck_set, 3883 (void *)&cmd_setlinkcheck_link_check, 3884 (void *)&cmd_setlinkcheck_mode, 3885 NULL, 3886 }, 3887 }; 3888 3889 #ifdef RTE_NIC_BYPASS 3890 /* *** SET NIC BYPASS MODE *** */ 3891 struct cmd_set_bypass_mode_result { 3892 cmdline_fixed_string_t set; 3893 cmdline_fixed_string_t bypass; 3894 cmdline_fixed_string_t mode; 3895 cmdline_fixed_string_t value; 3896 uint8_t port_id; 3897 }; 3898 3899 static void 3900 cmd_set_bypass_mode_parsed(void *parsed_result, 3901 __attribute__((unused)) struct cmdline *cl, 3902 __attribute__((unused)) void *data) 3903 { 3904 struct cmd_set_bypass_mode_result *res = parsed_result; 3905 portid_t port_id = res->port_id; 3906 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 3907 3908 if (!strcmp(res->value, "bypass")) 3909 bypass_mode = RTE_BYPASS_MODE_BYPASS; 3910 else if (!strcmp(res->value, "isolate")) 3911 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 3912 else 3913 bypass_mode = RTE_BYPASS_MODE_NORMAL; 3914 3915 /* Set the bypass mode for the relevant port. */ 3916 if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) { 3917 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 3918 } 3919 } 3920 3921 cmdline_parse_token_string_t cmd_setbypass_mode_set = 3922 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3923 set, "set"); 3924 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 3925 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3926 bypass, "bypass"); 3927 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 3928 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3929 mode, "mode"); 3930 cmdline_parse_token_string_t cmd_setbypass_mode_value = 3931 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 3932 value, "normal#bypass#isolate"); 3933 cmdline_parse_token_num_t cmd_setbypass_mode_port = 3934 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 3935 port_id, UINT8); 3936 3937 cmdline_parse_inst_t cmd_set_bypass_mode = { 3938 .f = cmd_set_bypass_mode_parsed, 3939 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 3940 "Set the NIC bypass mode for port_id", 3941 .data = NULL, 3942 .tokens = { 3943 (void *)&cmd_setbypass_mode_set, 3944 (void *)&cmd_setbypass_mode_bypass, 3945 (void *)&cmd_setbypass_mode_mode, 3946 (void *)&cmd_setbypass_mode_value, 3947 (void *)&cmd_setbypass_mode_port, 3948 NULL, 3949 }, 3950 }; 3951 3952 /* *** SET NIC BYPASS EVENT *** */ 3953 struct cmd_set_bypass_event_result { 3954 cmdline_fixed_string_t set; 3955 cmdline_fixed_string_t bypass; 3956 cmdline_fixed_string_t event; 3957 cmdline_fixed_string_t event_value; 3958 cmdline_fixed_string_t mode; 3959 cmdline_fixed_string_t mode_value; 3960 uint8_t port_id; 3961 }; 3962 3963 static void 3964 cmd_set_bypass_event_parsed(void *parsed_result, 3965 __attribute__((unused)) struct cmdline *cl, 3966 __attribute__((unused)) void *data) 3967 { 3968 int32_t rc; 3969 struct cmd_set_bypass_event_result *res = parsed_result; 3970 portid_t port_id = res->port_id; 3971 uint32_t bypass_event = RTE_BYPASS_EVENT_NONE; 3972 uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL; 3973 3974 if (!strcmp(res->event_value, "timeout")) 3975 bypass_event = RTE_BYPASS_EVENT_TIMEOUT; 3976 else if (!strcmp(res->event_value, "os_on")) 3977 bypass_event = RTE_BYPASS_EVENT_OS_ON; 3978 else if (!strcmp(res->event_value, "os_off")) 3979 bypass_event = RTE_BYPASS_EVENT_OS_OFF; 3980 else if (!strcmp(res->event_value, "power_on")) 3981 bypass_event = RTE_BYPASS_EVENT_POWER_ON; 3982 else if (!strcmp(res->event_value, "power_off")) 3983 bypass_event = RTE_BYPASS_EVENT_POWER_OFF; 3984 else 3985 bypass_event = RTE_BYPASS_EVENT_NONE; 3986 3987 if (!strcmp(res->mode_value, "bypass")) 3988 bypass_mode = RTE_BYPASS_MODE_BYPASS; 3989 else if (!strcmp(res->mode_value, "isolate")) 3990 bypass_mode = RTE_BYPASS_MODE_ISOLATE; 3991 else 3992 bypass_mode = RTE_BYPASS_MODE_NORMAL; 3993 3994 /* Set the watchdog timeout. */ 3995 if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) { 3996 3997 rc = -EINVAL; 3998 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) || 3999 (rc = rte_eth_dev_wd_timeout_store(port_id, 4000 bypass_timeout)) != 0) { 4001 printf("Failed to set timeout value %u " 4002 "for port %d, errto code: %d.\n", 4003 bypass_timeout, port_id, rc); 4004 } 4005 } 4006 4007 /* Set the bypass event to transition to bypass mode. */ 4008 if (0 != rte_eth_dev_bypass_event_store(port_id, 4009 bypass_event, bypass_mode)) { 4010 printf("\t Failed to set bypass event for port = %d.\n", port_id); 4011 } 4012 4013 } 4014 4015 cmdline_parse_token_string_t cmd_setbypass_event_set = 4016 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4017 set, "set"); 4018 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 4019 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4020 bypass, "bypass"); 4021 cmdline_parse_token_string_t cmd_setbypass_event_event = 4022 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4023 event, "event"); 4024 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 4025 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4026 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 4027 cmdline_parse_token_string_t cmd_setbypass_event_mode = 4028 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4029 mode, "mode"); 4030 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 4031 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4032 mode_value, "normal#bypass#isolate"); 4033 cmdline_parse_token_num_t cmd_setbypass_event_port = 4034 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 4035 port_id, UINT8); 4036 4037 cmdline_parse_inst_t cmd_set_bypass_event = { 4038 .f = cmd_set_bypass_event_parsed, 4039 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 4040 "power_off mode normal|bypass|isolate <port_id>: " 4041 "Set the NIC bypass event mode for port_id", 4042 .data = NULL, 4043 .tokens = { 4044 (void *)&cmd_setbypass_event_set, 4045 (void *)&cmd_setbypass_event_bypass, 4046 (void *)&cmd_setbypass_event_event, 4047 (void *)&cmd_setbypass_event_event_value, 4048 (void *)&cmd_setbypass_event_mode, 4049 (void *)&cmd_setbypass_event_mode_value, 4050 (void *)&cmd_setbypass_event_port, 4051 NULL, 4052 }, 4053 }; 4054 4055 4056 /* *** SET NIC BYPASS TIMEOUT *** */ 4057 struct cmd_set_bypass_timeout_result { 4058 cmdline_fixed_string_t set; 4059 cmdline_fixed_string_t bypass; 4060 cmdline_fixed_string_t timeout; 4061 cmdline_fixed_string_t value; 4062 }; 4063 4064 static void 4065 cmd_set_bypass_timeout_parsed(void *parsed_result, 4066 __attribute__((unused)) struct cmdline *cl, 4067 __attribute__((unused)) void *data) 4068 { 4069 struct cmd_set_bypass_timeout_result *res = parsed_result; 4070 4071 if (!strcmp(res->value, "1.5")) 4072 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC; 4073 else if (!strcmp(res->value, "2")) 4074 bypass_timeout = RTE_BYPASS_TMT_2_SEC; 4075 else if (!strcmp(res->value, "3")) 4076 bypass_timeout = RTE_BYPASS_TMT_3_SEC; 4077 else if (!strcmp(res->value, "4")) 4078 bypass_timeout = RTE_BYPASS_TMT_4_SEC; 4079 else if (!strcmp(res->value, "8")) 4080 bypass_timeout = RTE_BYPASS_TMT_8_SEC; 4081 else if (!strcmp(res->value, "16")) 4082 bypass_timeout = RTE_BYPASS_TMT_16_SEC; 4083 else if (!strcmp(res->value, "32")) 4084 bypass_timeout = RTE_BYPASS_TMT_32_SEC; 4085 else 4086 bypass_timeout = RTE_BYPASS_TMT_OFF; 4087 } 4088 4089 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 4090 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4091 set, "set"); 4092 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 4093 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4094 bypass, "bypass"); 4095 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 4096 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4097 timeout, "timeout"); 4098 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 4099 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4100 value, "0#1.5#2#3#4#8#16#32"); 4101 4102 cmdline_parse_inst_t cmd_set_bypass_timeout = { 4103 .f = cmd_set_bypass_timeout_parsed, 4104 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 4105 "Set the NIC bypass watchdog timeout in seconds", 4106 .data = NULL, 4107 .tokens = { 4108 (void *)&cmd_setbypass_timeout_set, 4109 (void *)&cmd_setbypass_timeout_bypass, 4110 (void *)&cmd_setbypass_timeout_timeout, 4111 (void *)&cmd_setbypass_timeout_value, 4112 NULL, 4113 }, 4114 }; 4115 4116 /* *** SHOW NIC BYPASS MODE *** */ 4117 struct cmd_show_bypass_config_result { 4118 cmdline_fixed_string_t show; 4119 cmdline_fixed_string_t bypass; 4120 cmdline_fixed_string_t config; 4121 uint8_t port_id; 4122 }; 4123 4124 static void 4125 cmd_show_bypass_config_parsed(void *parsed_result, 4126 __attribute__((unused)) struct cmdline *cl, 4127 __attribute__((unused)) void *data) 4128 { 4129 struct cmd_show_bypass_config_result *res = parsed_result; 4130 uint32_t event_mode; 4131 uint32_t bypass_mode; 4132 portid_t port_id = res->port_id; 4133 uint32_t timeout = bypass_timeout; 4134 int i; 4135 4136 static const char * const timeouts[RTE_BYPASS_TMT_NUM] = 4137 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 4138 static const char * const modes[RTE_BYPASS_MODE_NUM] = 4139 {"UNKNOWN", "normal", "bypass", "isolate"}; 4140 static const char * const events[RTE_BYPASS_EVENT_NUM] = { 4141 "NONE", 4142 "OS/board on", 4143 "power supply on", 4144 "OS/board off", 4145 "power supply off", 4146 "timeout"}; 4147 int num_events = (sizeof events) / (sizeof events[0]); 4148 4149 /* Display the bypass mode.*/ 4150 if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) { 4151 printf("\tFailed to get bypass mode for port = %d\n", port_id); 4152 return; 4153 } 4154 else { 4155 if (!RTE_BYPASS_MODE_VALID(bypass_mode)) 4156 bypass_mode = RTE_BYPASS_MODE_NONE; 4157 4158 printf("\tbypass mode = %s\n", modes[bypass_mode]); 4159 } 4160 4161 /* Display the bypass timeout.*/ 4162 if (!RTE_BYPASS_TMT_VALID(timeout)) 4163 timeout = RTE_BYPASS_TMT_OFF; 4164 4165 printf("\tbypass timeout = %s\n", timeouts[timeout]); 4166 4167 /* Display the bypass events and associated modes. */ 4168 for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) { 4169 4170 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) { 4171 printf("\tFailed to get bypass mode for event = %s\n", 4172 events[i]); 4173 } else { 4174 if (!RTE_BYPASS_MODE_VALID(event_mode)) 4175 event_mode = RTE_BYPASS_MODE_NONE; 4176 4177 printf("\tbypass event: %-16s = %s\n", events[i], 4178 modes[event_mode]); 4179 } 4180 } 4181 } 4182 4183 cmdline_parse_token_string_t cmd_showbypass_config_show = 4184 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4185 show, "show"); 4186 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 4187 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4188 bypass, "bypass"); 4189 cmdline_parse_token_string_t cmd_showbypass_config_config = 4190 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4191 config, "config"); 4192 cmdline_parse_token_num_t cmd_showbypass_config_port = 4193 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 4194 port_id, UINT8); 4195 4196 cmdline_parse_inst_t cmd_show_bypass_config = { 4197 .f = cmd_show_bypass_config_parsed, 4198 .help_str = "show bypass config <port_id>: " 4199 "Show the NIC bypass config for port_id", 4200 .data = NULL, 4201 .tokens = { 4202 (void *)&cmd_showbypass_config_show, 4203 (void *)&cmd_showbypass_config_bypass, 4204 (void *)&cmd_showbypass_config_config, 4205 (void *)&cmd_showbypass_config_port, 4206 NULL, 4207 }, 4208 }; 4209 #endif 4210 4211 #ifdef RTE_LIBRTE_PMD_BOND 4212 /* *** SET BONDING MODE *** */ 4213 struct cmd_set_bonding_mode_result { 4214 cmdline_fixed_string_t set; 4215 cmdline_fixed_string_t bonding; 4216 cmdline_fixed_string_t mode; 4217 uint8_t value; 4218 uint8_t port_id; 4219 }; 4220 4221 static void cmd_set_bonding_mode_parsed(void *parsed_result, 4222 __attribute__((unused)) struct cmdline *cl, 4223 __attribute__((unused)) void *data) 4224 { 4225 struct cmd_set_bonding_mode_result *res = parsed_result; 4226 portid_t port_id = res->port_id; 4227 4228 /* Set the bonding mode for the relevant port. */ 4229 if (0 != rte_eth_bond_mode_set(port_id, res->value)) 4230 printf("\t Failed to set bonding mode for port = %d.\n", port_id); 4231 } 4232 4233 cmdline_parse_token_string_t cmd_setbonding_mode_set = 4234 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4235 set, "set"); 4236 cmdline_parse_token_string_t cmd_setbonding_mode_bonding = 4237 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4238 bonding, "bonding"); 4239 cmdline_parse_token_string_t cmd_setbonding_mode_mode = 4240 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4241 mode, "mode"); 4242 cmdline_parse_token_num_t cmd_setbonding_mode_value = 4243 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4244 value, UINT8); 4245 cmdline_parse_token_num_t cmd_setbonding_mode_port = 4246 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4247 port_id, UINT8); 4248 4249 cmdline_parse_inst_t cmd_set_bonding_mode = { 4250 .f = cmd_set_bonding_mode_parsed, 4251 .help_str = "set bonding mode <mode_value> <port_id>: " 4252 "Set the bonding mode for port_id", 4253 .data = NULL, 4254 .tokens = { 4255 (void *) &cmd_setbonding_mode_set, 4256 (void *) &cmd_setbonding_mode_bonding, 4257 (void *) &cmd_setbonding_mode_mode, 4258 (void *) &cmd_setbonding_mode_value, 4259 (void *) &cmd_setbonding_mode_port, 4260 NULL 4261 } 4262 }; 4263 4264 /* *** SET BALANCE XMIT POLICY *** */ 4265 struct cmd_set_bonding_balance_xmit_policy_result { 4266 cmdline_fixed_string_t set; 4267 cmdline_fixed_string_t bonding; 4268 cmdline_fixed_string_t balance_xmit_policy; 4269 uint8_t port_id; 4270 cmdline_fixed_string_t policy; 4271 }; 4272 4273 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, 4274 __attribute__((unused)) struct cmdline *cl, 4275 __attribute__((unused)) void *data) 4276 { 4277 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; 4278 portid_t port_id = res->port_id; 4279 uint8_t policy; 4280 4281 if (!strcmp(res->policy, "l2")) { 4282 policy = BALANCE_XMIT_POLICY_LAYER2; 4283 } else if (!strcmp(res->policy, "l23")) { 4284 policy = BALANCE_XMIT_POLICY_LAYER23; 4285 } else if (!strcmp(res->policy, "l34")) { 4286 policy = BALANCE_XMIT_POLICY_LAYER34; 4287 } else { 4288 printf("\t Invalid xmit policy selection"); 4289 return; 4290 } 4291 4292 /* Set the bonding mode for the relevant port. */ 4293 if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { 4294 printf("\t Failed to set bonding balance xmit policy for port = %d.\n", 4295 port_id); 4296 } 4297 } 4298 4299 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = 4300 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4301 set, "set"); 4302 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = 4303 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4304 bonding, "bonding"); 4305 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = 4306 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4307 balance_xmit_policy, "balance_xmit_policy"); 4308 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = 4309 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4310 port_id, UINT8); 4311 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = 4312 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4313 policy, "l2#l23#l34"); 4314 4315 cmdline_parse_inst_t cmd_set_balance_xmit_policy = { 4316 .f = cmd_set_bonding_balance_xmit_policy_parsed, 4317 .help_str = "set bonding balance_xmit_policy <port_id> " 4318 "l2|l23|l34: " 4319 "Set the bonding balance_xmit_policy for port_id", 4320 .data = NULL, 4321 .tokens = { 4322 (void *)&cmd_setbonding_balance_xmit_policy_set, 4323 (void *)&cmd_setbonding_balance_xmit_policy_bonding, 4324 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, 4325 (void *)&cmd_setbonding_balance_xmit_policy_port, 4326 (void *)&cmd_setbonding_balance_xmit_policy_policy, 4327 NULL 4328 } 4329 }; 4330 4331 /* *** SHOW NIC BONDING CONFIGURATION *** */ 4332 struct cmd_show_bonding_config_result { 4333 cmdline_fixed_string_t show; 4334 cmdline_fixed_string_t bonding; 4335 cmdline_fixed_string_t config; 4336 uint8_t port_id; 4337 }; 4338 4339 static void cmd_show_bonding_config_parsed(void *parsed_result, 4340 __attribute__((unused)) struct cmdline *cl, 4341 __attribute__((unused)) void *data) 4342 { 4343 struct cmd_show_bonding_config_result *res = parsed_result; 4344 int bonding_mode; 4345 uint8_t slaves[RTE_MAX_ETHPORTS]; 4346 int num_slaves, num_active_slaves; 4347 int primary_id; 4348 int i; 4349 portid_t port_id = res->port_id; 4350 4351 /* Display the bonding mode.*/ 4352 bonding_mode = rte_eth_bond_mode_get(port_id); 4353 if (bonding_mode < 0) { 4354 printf("\tFailed to get bonding mode for port = %d\n", port_id); 4355 return; 4356 } else 4357 printf("\tBonding mode: %d\n", bonding_mode); 4358 4359 if (bonding_mode == BONDING_MODE_BALANCE) { 4360 int balance_xmit_policy; 4361 4362 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); 4363 if (balance_xmit_policy < 0) { 4364 printf("\tFailed to get balance xmit policy for port = %d\n", 4365 port_id); 4366 return; 4367 } else { 4368 printf("\tBalance Xmit Policy: "); 4369 4370 switch (balance_xmit_policy) { 4371 case BALANCE_XMIT_POLICY_LAYER2: 4372 printf("BALANCE_XMIT_POLICY_LAYER2"); 4373 break; 4374 case BALANCE_XMIT_POLICY_LAYER23: 4375 printf("BALANCE_XMIT_POLICY_LAYER23"); 4376 break; 4377 case BALANCE_XMIT_POLICY_LAYER34: 4378 printf("BALANCE_XMIT_POLICY_LAYER34"); 4379 break; 4380 } 4381 printf("\n"); 4382 } 4383 } 4384 4385 num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); 4386 4387 if (num_slaves < 0) { 4388 printf("\tFailed to get slave list for port = %d\n", port_id); 4389 return; 4390 } 4391 if (num_slaves > 0) { 4392 printf("\tSlaves (%d): [", num_slaves); 4393 for (i = 0; i < num_slaves - 1; i++) 4394 printf("%d ", slaves[i]); 4395 4396 printf("%d]\n", slaves[num_slaves - 1]); 4397 } else { 4398 printf("\tSlaves: []\n"); 4399 4400 } 4401 4402 num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, 4403 RTE_MAX_ETHPORTS); 4404 4405 if (num_active_slaves < 0) { 4406 printf("\tFailed to get active slave list for port = %d\n", port_id); 4407 return; 4408 } 4409 if (num_active_slaves > 0) { 4410 printf("\tActive Slaves (%d): [", num_active_slaves); 4411 for (i = 0; i < num_active_slaves - 1; i++) 4412 printf("%d ", slaves[i]); 4413 4414 printf("%d]\n", slaves[num_active_slaves - 1]); 4415 4416 } else { 4417 printf("\tActive Slaves: []\n"); 4418 4419 } 4420 4421 primary_id = rte_eth_bond_primary_get(port_id); 4422 if (primary_id < 0) { 4423 printf("\tFailed to get primary slave for port = %d\n", port_id); 4424 return; 4425 } else 4426 printf("\tPrimary: [%d]\n", primary_id); 4427 4428 } 4429 4430 cmdline_parse_token_string_t cmd_showbonding_config_show = 4431 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4432 show, "show"); 4433 cmdline_parse_token_string_t cmd_showbonding_config_bonding = 4434 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4435 bonding, "bonding"); 4436 cmdline_parse_token_string_t cmd_showbonding_config_config = 4437 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4438 config, "config"); 4439 cmdline_parse_token_num_t cmd_showbonding_config_port = 4440 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, 4441 port_id, UINT8); 4442 4443 cmdline_parse_inst_t cmd_show_bonding_config = { 4444 .f = cmd_show_bonding_config_parsed, 4445 .help_str = "show bonding config <port_id>: " 4446 "Show the bonding config for port_id", 4447 .data = NULL, 4448 .tokens = { 4449 (void *)&cmd_showbonding_config_show, 4450 (void *)&cmd_showbonding_config_bonding, 4451 (void *)&cmd_showbonding_config_config, 4452 (void *)&cmd_showbonding_config_port, 4453 NULL 4454 } 4455 }; 4456 4457 /* *** SET BONDING PRIMARY *** */ 4458 struct cmd_set_bonding_primary_result { 4459 cmdline_fixed_string_t set; 4460 cmdline_fixed_string_t bonding; 4461 cmdline_fixed_string_t primary; 4462 uint8_t slave_id; 4463 uint8_t port_id; 4464 }; 4465 4466 static void cmd_set_bonding_primary_parsed(void *parsed_result, 4467 __attribute__((unused)) struct cmdline *cl, 4468 __attribute__((unused)) void *data) 4469 { 4470 struct cmd_set_bonding_primary_result *res = parsed_result; 4471 portid_t master_port_id = res->port_id; 4472 portid_t slave_port_id = res->slave_id; 4473 4474 /* Set the primary slave for a bonded device. */ 4475 if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { 4476 printf("\t Failed to set primary slave for port = %d.\n", 4477 master_port_id); 4478 return; 4479 } 4480 init_port_config(); 4481 } 4482 4483 cmdline_parse_token_string_t cmd_setbonding_primary_set = 4484 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4485 set, "set"); 4486 cmdline_parse_token_string_t cmd_setbonding_primary_bonding = 4487 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4488 bonding, "bonding"); 4489 cmdline_parse_token_string_t cmd_setbonding_primary_primary = 4490 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 4491 primary, "primary"); 4492 cmdline_parse_token_num_t cmd_setbonding_primary_slave = 4493 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4494 slave_id, UINT8); 4495 cmdline_parse_token_num_t cmd_setbonding_primary_port = 4496 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 4497 port_id, UINT8); 4498 4499 cmdline_parse_inst_t cmd_set_bonding_primary = { 4500 .f = cmd_set_bonding_primary_parsed, 4501 .help_str = "set bonding primary <slave_id> <port_id>: " 4502 "Set the primary slave for port_id", 4503 .data = NULL, 4504 .tokens = { 4505 (void *)&cmd_setbonding_primary_set, 4506 (void *)&cmd_setbonding_primary_bonding, 4507 (void *)&cmd_setbonding_primary_primary, 4508 (void *)&cmd_setbonding_primary_slave, 4509 (void *)&cmd_setbonding_primary_port, 4510 NULL 4511 } 4512 }; 4513 4514 /* *** ADD SLAVE *** */ 4515 struct cmd_add_bonding_slave_result { 4516 cmdline_fixed_string_t add; 4517 cmdline_fixed_string_t bonding; 4518 cmdline_fixed_string_t slave; 4519 uint8_t slave_id; 4520 uint8_t port_id; 4521 }; 4522 4523 static void cmd_add_bonding_slave_parsed(void *parsed_result, 4524 __attribute__((unused)) struct cmdline *cl, 4525 __attribute__((unused)) void *data) 4526 { 4527 struct cmd_add_bonding_slave_result *res = parsed_result; 4528 portid_t master_port_id = res->port_id; 4529 portid_t slave_port_id = res->slave_id; 4530 4531 /* Set the primary slave for a bonded device. */ 4532 if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { 4533 printf("\t Failed to add slave %d to master port = %d.\n", 4534 slave_port_id, master_port_id); 4535 return; 4536 } 4537 init_port_config(); 4538 set_port_slave_flag(slave_port_id); 4539 } 4540 4541 cmdline_parse_token_string_t cmd_addbonding_slave_add = 4542 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4543 add, "add"); 4544 cmdline_parse_token_string_t cmd_addbonding_slave_bonding = 4545 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4546 bonding, "bonding"); 4547 cmdline_parse_token_string_t cmd_addbonding_slave_slave = 4548 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 4549 slave, "slave"); 4550 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = 4551 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4552 slave_id, UINT8); 4553 cmdline_parse_token_num_t cmd_addbonding_slave_port = 4554 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 4555 port_id, UINT8); 4556 4557 cmdline_parse_inst_t cmd_add_bonding_slave = { 4558 .f = cmd_add_bonding_slave_parsed, 4559 .help_str = "add bonding slave <slave_id> <port_id>: " 4560 "Add a slave device to a bonded device", 4561 .data = NULL, 4562 .tokens = { 4563 (void *)&cmd_addbonding_slave_add, 4564 (void *)&cmd_addbonding_slave_bonding, 4565 (void *)&cmd_addbonding_slave_slave, 4566 (void *)&cmd_addbonding_slave_slaveid, 4567 (void *)&cmd_addbonding_slave_port, 4568 NULL 4569 } 4570 }; 4571 4572 /* *** REMOVE SLAVE *** */ 4573 struct cmd_remove_bonding_slave_result { 4574 cmdline_fixed_string_t remove; 4575 cmdline_fixed_string_t bonding; 4576 cmdline_fixed_string_t slave; 4577 uint8_t slave_id; 4578 uint8_t port_id; 4579 }; 4580 4581 static void cmd_remove_bonding_slave_parsed(void *parsed_result, 4582 __attribute__((unused)) struct cmdline *cl, 4583 __attribute__((unused)) void *data) 4584 { 4585 struct cmd_remove_bonding_slave_result *res = parsed_result; 4586 portid_t master_port_id = res->port_id; 4587 portid_t slave_port_id = res->slave_id; 4588 4589 /* Set the primary slave for a bonded device. */ 4590 if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { 4591 printf("\t Failed to remove slave %d from master port = %d.\n", 4592 slave_port_id, master_port_id); 4593 return; 4594 } 4595 init_port_config(); 4596 clear_port_slave_flag(slave_port_id); 4597 } 4598 4599 cmdline_parse_token_string_t cmd_removebonding_slave_remove = 4600 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4601 remove, "remove"); 4602 cmdline_parse_token_string_t cmd_removebonding_slave_bonding = 4603 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4604 bonding, "bonding"); 4605 cmdline_parse_token_string_t cmd_removebonding_slave_slave = 4606 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 4607 slave, "slave"); 4608 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = 4609 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4610 slave_id, UINT8); 4611 cmdline_parse_token_num_t cmd_removebonding_slave_port = 4612 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 4613 port_id, UINT8); 4614 4615 cmdline_parse_inst_t cmd_remove_bonding_slave = { 4616 .f = cmd_remove_bonding_slave_parsed, 4617 .help_str = "remove bonding slave <slave_id> <port_id>: " 4618 "Remove a slave device from a bonded device", 4619 .data = NULL, 4620 .tokens = { 4621 (void *)&cmd_removebonding_slave_remove, 4622 (void *)&cmd_removebonding_slave_bonding, 4623 (void *)&cmd_removebonding_slave_slave, 4624 (void *)&cmd_removebonding_slave_slaveid, 4625 (void *)&cmd_removebonding_slave_port, 4626 NULL 4627 } 4628 }; 4629 4630 /* *** CREATE BONDED DEVICE *** */ 4631 struct cmd_create_bonded_device_result { 4632 cmdline_fixed_string_t create; 4633 cmdline_fixed_string_t bonded; 4634 cmdline_fixed_string_t device; 4635 uint8_t mode; 4636 uint8_t socket; 4637 }; 4638 4639 static int bond_dev_num = 0; 4640 4641 static void cmd_create_bonded_device_parsed(void *parsed_result, 4642 __attribute__((unused)) struct cmdline *cl, 4643 __attribute__((unused)) void *data) 4644 { 4645 struct cmd_create_bonded_device_result *res = parsed_result; 4646 char ethdev_name[RTE_ETH_NAME_MAX_LEN]; 4647 int port_id; 4648 4649 if (test_done == 0) { 4650 printf("Please stop forwarding first\n"); 4651 return; 4652 } 4653 4654 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bond_testpmd_%d", 4655 bond_dev_num++); 4656 4657 /* Create a new bonded device. */ 4658 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); 4659 if (port_id < 0) { 4660 printf("\t Failed to create bonded device.\n"); 4661 return; 4662 } else { 4663 printf("Created new bonded device %s on (port %d).\n", ethdev_name, 4664 port_id); 4665 4666 /* Update number of ports */ 4667 nb_ports = rte_eth_dev_count(); 4668 reconfig(port_id, res->socket); 4669 rte_eth_promiscuous_enable(port_id); 4670 ports[port_id].enabled = 1; 4671 } 4672 4673 } 4674 4675 cmdline_parse_token_string_t cmd_createbonded_device_create = 4676 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4677 create, "create"); 4678 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 4679 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4680 bonded, "bonded"); 4681 cmdline_parse_token_string_t cmd_createbonded_device_device = 4682 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 4683 device, "device"); 4684 cmdline_parse_token_num_t cmd_createbonded_device_mode = 4685 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4686 mode, UINT8); 4687 cmdline_parse_token_num_t cmd_createbonded_device_socket = 4688 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 4689 socket, UINT8); 4690 4691 cmdline_parse_inst_t cmd_create_bonded_device = { 4692 .f = cmd_create_bonded_device_parsed, 4693 .help_str = "create bonded device <mode> <socket>: " 4694 "Create a new bonded device with specific bonding mode and socket", 4695 .data = NULL, 4696 .tokens = { 4697 (void *)&cmd_createbonded_device_create, 4698 (void *)&cmd_createbonded_device_bonded, 4699 (void *)&cmd_createbonded_device_device, 4700 (void *)&cmd_createbonded_device_mode, 4701 (void *)&cmd_createbonded_device_socket, 4702 NULL 4703 } 4704 }; 4705 4706 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 4707 struct cmd_set_bond_mac_addr_result { 4708 cmdline_fixed_string_t set; 4709 cmdline_fixed_string_t bonding; 4710 cmdline_fixed_string_t mac_addr; 4711 uint8_t port_num; 4712 struct ether_addr address; 4713 }; 4714 4715 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 4716 __attribute__((unused)) struct cmdline *cl, 4717 __attribute__((unused)) void *data) 4718 { 4719 struct cmd_set_bond_mac_addr_result *res = parsed_result; 4720 int ret; 4721 4722 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 4723 return; 4724 4725 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 4726 4727 /* check the return value and print it if is < 0 */ 4728 if (ret < 0) 4729 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4730 } 4731 4732 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 4733 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 4734 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 4735 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 4736 "bonding"); 4737 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 4738 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 4739 "mac_addr"); 4740 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 4741 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); 4742 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 4743 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 4744 4745 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 4746 .f = cmd_set_bond_mac_addr_parsed, 4747 .data = (void *) 0, 4748 .help_str = "set bonding mac_addr <port_id> <mac_addr>", 4749 .tokens = { 4750 (void *)&cmd_set_bond_mac_addr_set, 4751 (void *)&cmd_set_bond_mac_addr_bonding, 4752 (void *)&cmd_set_bond_mac_addr_mac, 4753 (void *)&cmd_set_bond_mac_addr_portnum, 4754 (void *)&cmd_set_bond_mac_addr_addr, 4755 NULL 4756 } 4757 }; 4758 4759 4760 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 4761 struct cmd_set_bond_mon_period_result { 4762 cmdline_fixed_string_t set; 4763 cmdline_fixed_string_t bonding; 4764 cmdline_fixed_string_t mon_period; 4765 uint8_t port_num; 4766 uint32_t period_ms; 4767 }; 4768 4769 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 4770 __attribute__((unused)) struct cmdline *cl, 4771 __attribute__((unused)) void *data) 4772 { 4773 struct cmd_set_bond_mon_period_result *res = parsed_result; 4774 int ret; 4775 4776 if (res->port_num >= nb_ports) { 4777 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 4778 return; 4779 } 4780 4781 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 4782 4783 /* check the return value and print it if is < 0 */ 4784 if (ret < 0) 4785 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 4786 } 4787 4788 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 4789 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4790 set, "set"); 4791 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 4792 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4793 bonding, "bonding"); 4794 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 4795 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 4796 mon_period, "mon_period"); 4797 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 4798 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4799 port_num, UINT8); 4800 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 4801 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 4802 period_ms, UINT32); 4803 4804 cmdline_parse_inst_t cmd_set_bond_mon_period = { 4805 .f = cmd_set_bond_mon_period_parsed, 4806 .data = (void *) 0, 4807 .help_str = "set bonding mon_period <port_id> <period_ms>", 4808 .tokens = { 4809 (void *)&cmd_set_bond_mon_period_set, 4810 (void *)&cmd_set_bond_mon_period_bonding, 4811 (void *)&cmd_set_bond_mon_period_mon_period, 4812 (void *)&cmd_set_bond_mon_period_portnum, 4813 (void *)&cmd_set_bond_mon_period_period_ms, 4814 NULL 4815 } 4816 }; 4817 4818 #endif /* RTE_LIBRTE_PMD_BOND */ 4819 4820 /* *** SET FORWARDING MODE *** */ 4821 struct cmd_set_fwd_mode_result { 4822 cmdline_fixed_string_t set; 4823 cmdline_fixed_string_t fwd; 4824 cmdline_fixed_string_t mode; 4825 }; 4826 4827 static void cmd_set_fwd_mode_parsed(void *parsed_result, 4828 __attribute__((unused)) struct cmdline *cl, 4829 __attribute__((unused)) void *data) 4830 { 4831 struct cmd_set_fwd_mode_result *res = parsed_result; 4832 4833 retry_enabled = 0; 4834 set_pkt_forwarding_mode(res->mode); 4835 } 4836 4837 cmdline_parse_token_string_t cmd_setfwd_set = 4838 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 4839 cmdline_parse_token_string_t cmd_setfwd_fwd = 4840 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 4841 cmdline_parse_token_string_t cmd_setfwd_mode = 4842 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 4843 "" /* defined at init */); 4844 4845 cmdline_parse_inst_t cmd_set_fwd_mode = { 4846 .f = cmd_set_fwd_mode_parsed, 4847 .data = NULL, 4848 .help_str = NULL, /* defined at init */ 4849 .tokens = { 4850 (void *)&cmd_setfwd_set, 4851 (void *)&cmd_setfwd_fwd, 4852 (void *)&cmd_setfwd_mode, 4853 NULL, 4854 }, 4855 }; 4856 4857 static void cmd_set_fwd_mode_init(void) 4858 { 4859 char *modes, *c; 4860 static char token[128]; 4861 static char help[256]; 4862 cmdline_parse_token_string_t *token_struct; 4863 4864 modes = list_pkt_forwarding_modes(); 4865 snprintf(help, sizeof(help), "set fwd %s: " 4866 "Set packet forwarding mode", modes); 4867 cmd_set_fwd_mode.help_str = help; 4868 4869 /* string token separator is # */ 4870 for (c = token; *modes != '\0'; modes++) 4871 if (*modes == '|') 4872 *c++ = '#'; 4873 else 4874 *c++ = *modes; 4875 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 4876 token_struct->string_data.str = token; 4877 } 4878 4879 /* *** SET RETRY FORWARDING MODE *** */ 4880 struct cmd_set_fwd_retry_mode_result { 4881 cmdline_fixed_string_t set; 4882 cmdline_fixed_string_t fwd; 4883 cmdline_fixed_string_t mode; 4884 cmdline_fixed_string_t retry; 4885 }; 4886 4887 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 4888 __attribute__((unused)) struct cmdline *cl, 4889 __attribute__((unused)) void *data) 4890 { 4891 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 4892 4893 retry_enabled = 1; 4894 set_pkt_forwarding_mode(res->mode); 4895 } 4896 4897 cmdline_parse_token_string_t cmd_setfwd_retry_set = 4898 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4899 set, "set"); 4900 cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 4901 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4902 fwd, "fwd"); 4903 cmdline_parse_token_string_t cmd_setfwd_retry_mode = 4904 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4905 mode, 4906 "" /* defined at init */); 4907 cmdline_parse_token_string_t cmd_setfwd_retry_retry = 4908 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 4909 retry, "retry"); 4910 4911 cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 4912 .f = cmd_set_fwd_retry_mode_parsed, 4913 .data = NULL, 4914 .help_str = NULL, /* defined at init */ 4915 .tokens = { 4916 (void *)&cmd_setfwd_retry_set, 4917 (void *)&cmd_setfwd_retry_fwd, 4918 (void *)&cmd_setfwd_retry_mode, 4919 (void *)&cmd_setfwd_retry_retry, 4920 NULL, 4921 }, 4922 }; 4923 4924 static void cmd_set_fwd_retry_mode_init(void) 4925 { 4926 char *modes, *c; 4927 static char token[128]; 4928 static char help[256]; 4929 cmdline_parse_token_string_t *token_struct; 4930 4931 modes = list_pkt_forwarding_retry_modes(); 4932 snprintf(help, sizeof(help), "set fwd %s retry: " 4933 "Set packet forwarding mode with retry", modes); 4934 cmd_set_fwd_retry_mode.help_str = help; 4935 4936 /* string token separator is # */ 4937 for (c = token; *modes != '\0'; modes++) 4938 if (*modes == '|') 4939 *c++ = '#'; 4940 else 4941 *c++ = *modes; 4942 token_struct = (cmdline_parse_token_string_t *) 4943 cmd_set_fwd_retry_mode.tokens[2]; 4944 token_struct->string_data.str = token; 4945 } 4946 4947 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 4948 struct cmd_set_burst_tx_retry_result { 4949 cmdline_fixed_string_t set; 4950 cmdline_fixed_string_t burst; 4951 cmdline_fixed_string_t tx; 4952 cmdline_fixed_string_t delay; 4953 uint32_t time; 4954 cmdline_fixed_string_t retry; 4955 uint32_t retry_num; 4956 }; 4957 4958 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 4959 __attribute__((unused)) struct cmdline *cl, 4960 __attribute__((unused)) void *data) 4961 { 4962 struct cmd_set_burst_tx_retry_result *res = parsed_result; 4963 4964 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 4965 && !strcmp(res->tx, "tx")) { 4966 if (!strcmp(res->delay, "delay")) 4967 burst_tx_delay_time = res->time; 4968 if (!strcmp(res->retry, "retry")) 4969 burst_tx_retry_num = res->retry_num; 4970 } 4971 4972 } 4973 4974 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 4975 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 4976 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 4977 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 4978 "burst"); 4979 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 4980 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 4981 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 4982 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 4983 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 4984 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 4985 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 4986 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 4987 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 4988 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 4989 4990 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 4991 .f = cmd_set_burst_tx_retry_parsed, 4992 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 4993 .tokens = { 4994 (void *)&cmd_set_burst_tx_retry_set, 4995 (void *)&cmd_set_burst_tx_retry_burst, 4996 (void *)&cmd_set_burst_tx_retry_tx, 4997 (void *)&cmd_set_burst_tx_retry_delay, 4998 (void *)&cmd_set_burst_tx_retry_time, 4999 (void *)&cmd_set_burst_tx_retry_retry, 5000 (void *)&cmd_set_burst_tx_retry_retry_num, 5001 NULL, 5002 }, 5003 }; 5004 5005 /* *** SET PROMISC MODE *** */ 5006 struct cmd_set_promisc_mode_result { 5007 cmdline_fixed_string_t set; 5008 cmdline_fixed_string_t promisc; 5009 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5010 uint8_t port_num; /* valid if "allports" argument == 0 */ 5011 cmdline_fixed_string_t mode; 5012 }; 5013 5014 static void cmd_set_promisc_mode_parsed(void *parsed_result, 5015 __attribute__((unused)) struct cmdline *cl, 5016 void *allports) 5017 { 5018 struct cmd_set_promisc_mode_result *res = parsed_result; 5019 int enable; 5020 portid_t i; 5021 5022 if (!strcmp(res->mode, "on")) 5023 enable = 1; 5024 else 5025 enable = 0; 5026 5027 /* all ports */ 5028 if (allports) { 5029 FOREACH_PORT(i, ports) { 5030 if (enable) 5031 rte_eth_promiscuous_enable(i); 5032 else 5033 rte_eth_promiscuous_disable(i); 5034 } 5035 } 5036 else { 5037 if (enable) 5038 rte_eth_promiscuous_enable(res->port_num); 5039 else 5040 rte_eth_promiscuous_disable(res->port_num); 5041 } 5042 } 5043 5044 cmdline_parse_token_string_t cmd_setpromisc_set = 5045 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 5046 cmdline_parse_token_string_t cmd_setpromisc_promisc = 5047 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 5048 "promisc"); 5049 cmdline_parse_token_string_t cmd_setpromisc_portall = 5050 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 5051 "all"); 5052 cmdline_parse_token_num_t cmd_setpromisc_portnum = 5053 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 5054 UINT8); 5055 cmdline_parse_token_string_t cmd_setpromisc_mode = 5056 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 5057 "on#off"); 5058 5059 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 5060 .f = cmd_set_promisc_mode_parsed, 5061 .data = (void *)1, 5062 .help_str = "set promisc all on|off: Set promisc mode for all ports", 5063 .tokens = { 5064 (void *)&cmd_setpromisc_set, 5065 (void *)&cmd_setpromisc_promisc, 5066 (void *)&cmd_setpromisc_portall, 5067 (void *)&cmd_setpromisc_mode, 5068 NULL, 5069 }, 5070 }; 5071 5072 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 5073 .f = cmd_set_promisc_mode_parsed, 5074 .data = (void *)0, 5075 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 5076 .tokens = { 5077 (void *)&cmd_setpromisc_set, 5078 (void *)&cmd_setpromisc_promisc, 5079 (void *)&cmd_setpromisc_portnum, 5080 (void *)&cmd_setpromisc_mode, 5081 NULL, 5082 }, 5083 }; 5084 5085 /* *** SET ALLMULTI MODE *** */ 5086 struct cmd_set_allmulti_mode_result { 5087 cmdline_fixed_string_t set; 5088 cmdline_fixed_string_t allmulti; 5089 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5090 uint8_t port_num; /* valid if "allports" argument == 0 */ 5091 cmdline_fixed_string_t mode; 5092 }; 5093 5094 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 5095 __attribute__((unused)) struct cmdline *cl, 5096 void *allports) 5097 { 5098 struct cmd_set_allmulti_mode_result *res = parsed_result; 5099 int enable; 5100 portid_t i; 5101 5102 if (!strcmp(res->mode, "on")) 5103 enable = 1; 5104 else 5105 enable = 0; 5106 5107 /* all ports */ 5108 if (allports) { 5109 FOREACH_PORT(i, ports) { 5110 if (enable) 5111 rte_eth_allmulticast_enable(i); 5112 else 5113 rte_eth_allmulticast_disable(i); 5114 } 5115 } 5116 else { 5117 if (enable) 5118 rte_eth_allmulticast_enable(res->port_num); 5119 else 5120 rte_eth_allmulticast_disable(res->port_num); 5121 } 5122 } 5123 5124 cmdline_parse_token_string_t cmd_setallmulti_set = 5125 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 5126 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 5127 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 5128 "allmulti"); 5129 cmdline_parse_token_string_t cmd_setallmulti_portall = 5130 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 5131 "all"); 5132 cmdline_parse_token_num_t cmd_setallmulti_portnum = 5133 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 5134 UINT8); 5135 cmdline_parse_token_string_t cmd_setallmulti_mode = 5136 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 5137 "on#off"); 5138 5139 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 5140 .f = cmd_set_allmulti_mode_parsed, 5141 .data = (void *)1, 5142 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 5143 .tokens = { 5144 (void *)&cmd_setallmulti_set, 5145 (void *)&cmd_setallmulti_allmulti, 5146 (void *)&cmd_setallmulti_portall, 5147 (void *)&cmd_setallmulti_mode, 5148 NULL, 5149 }, 5150 }; 5151 5152 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 5153 .f = cmd_set_allmulti_mode_parsed, 5154 .data = (void *)0, 5155 .help_str = "set allmulti <port_id> on|off: " 5156 "Set allmulti mode on port_id", 5157 .tokens = { 5158 (void *)&cmd_setallmulti_set, 5159 (void *)&cmd_setallmulti_allmulti, 5160 (void *)&cmd_setallmulti_portnum, 5161 (void *)&cmd_setallmulti_mode, 5162 NULL, 5163 }, 5164 }; 5165 5166 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 5167 struct cmd_link_flow_ctrl_set_result { 5168 cmdline_fixed_string_t set; 5169 cmdline_fixed_string_t flow_ctrl; 5170 cmdline_fixed_string_t rx; 5171 cmdline_fixed_string_t rx_lfc_mode; 5172 cmdline_fixed_string_t tx; 5173 cmdline_fixed_string_t tx_lfc_mode; 5174 cmdline_fixed_string_t mac_ctrl_frame_fwd; 5175 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 5176 cmdline_fixed_string_t autoneg_str; 5177 cmdline_fixed_string_t autoneg; 5178 cmdline_fixed_string_t hw_str; 5179 uint32_t high_water; 5180 cmdline_fixed_string_t lw_str; 5181 uint32_t low_water; 5182 cmdline_fixed_string_t pt_str; 5183 uint16_t pause_time; 5184 cmdline_fixed_string_t xon_str; 5185 uint16_t send_xon; 5186 uint8_t port_id; 5187 }; 5188 5189 cmdline_parse_token_string_t cmd_lfc_set_set = 5190 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5191 set, "set"); 5192 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 5193 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5194 flow_ctrl, "flow_ctrl"); 5195 cmdline_parse_token_string_t cmd_lfc_set_rx = 5196 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5197 rx, "rx"); 5198 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 5199 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5200 rx_lfc_mode, "on#off"); 5201 cmdline_parse_token_string_t cmd_lfc_set_tx = 5202 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5203 tx, "tx"); 5204 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 5205 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5206 tx_lfc_mode, "on#off"); 5207 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 5208 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5209 hw_str, "high_water"); 5210 cmdline_parse_token_num_t cmd_lfc_set_high_water = 5211 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5212 high_water, UINT32); 5213 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 5214 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5215 lw_str, "low_water"); 5216 cmdline_parse_token_num_t cmd_lfc_set_low_water = 5217 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5218 low_water, UINT32); 5219 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 5220 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5221 pt_str, "pause_time"); 5222 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 5223 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5224 pause_time, UINT16); 5225 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 5226 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5227 xon_str, "send_xon"); 5228 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 5229 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5230 send_xon, UINT16); 5231 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 5232 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5233 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 5234 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 5235 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5236 mac_ctrl_frame_fwd_mode, "on#off"); 5237 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 5238 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5239 autoneg_str, "autoneg"); 5240 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 5241 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5242 autoneg, "on#off"); 5243 cmdline_parse_token_num_t cmd_lfc_set_portid = 5244 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5245 port_id, UINT8); 5246 5247 /* forward declaration */ 5248 static void 5249 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 5250 void *data); 5251 5252 cmdline_parse_inst_t cmd_link_flow_control_set = { 5253 .f = cmd_link_flow_ctrl_set_parsed, 5254 .data = NULL, 5255 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 5256 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 5257 "autoneg on|off <port_id>: Configure the Ethernet flow control", 5258 .tokens = { 5259 (void *)&cmd_lfc_set_set, 5260 (void *)&cmd_lfc_set_flow_ctrl, 5261 (void *)&cmd_lfc_set_rx, 5262 (void *)&cmd_lfc_set_rx_mode, 5263 (void *)&cmd_lfc_set_tx, 5264 (void *)&cmd_lfc_set_tx_mode, 5265 (void *)&cmd_lfc_set_high_water, 5266 (void *)&cmd_lfc_set_low_water, 5267 (void *)&cmd_lfc_set_pause_time, 5268 (void *)&cmd_lfc_set_send_xon, 5269 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5270 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5271 (void *)&cmd_lfc_set_autoneg_str, 5272 (void *)&cmd_lfc_set_autoneg, 5273 (void *)&cmd_lfc_set_portid, 5274 NULL, 5275 }, 5276 }; 5277 5278 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 5279 .f = cmd_link_flow_ctrl_set_parsed, 5280 .data = (void *)&cmd_link_flow_control_set_rx, 5281 .help_str = "set flow_ctrl rx on|off <port_id>: " 5282 "Change rx flow control parameter", 5283 .tokens = { 5284 (void *)&cmd_lfc_set_set, 5285 (void *)&cmd_lfc_set_flow_ctrl, 5286 (void *)&cmd_lfc_set_rx, 5287 (void *)&cmd_lfc_set_rx_mode, 5288 (void *)&cmd_lfc_set_portid, 5289 NULL, 5290 }, 5291 }; 5292 5293 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 5294 .f = cmd_link_flow_ctrl_set_parsed, 5295 .data = (void *)&cmd_link_flow_control_set_tx, 5296 .help_str = "set flow_ctrl tx on|off <port_id>: " 5297 "Change tx flow control parameter", 5298 .tokens = { 5299 (void *)&cmd_lfc_set_set, 5300 (void *)&cmd_lfc_set_flow_ctrl, 5301 (void *)&cmd_lfc_set_tx, 5302 (void *)&cmd_lfc_set_tx_mode, 5303 (void *)&cmd_lfc_set_portid, 5304 NULL, 5305 }, 5306 }; 5307 5308 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 5309 .f = cmd_link_flow_ctrl_set_parsed, 5310 .data = (void *)&cmd_link_flow_control_set_hw, 5311 .help_str = "set flow_ctrl high_water <value> <port_id>: " 5312 "Change high water flow control parameter", 5313 .tokens = { 5314 (void *)&cmd_lfc_set_set, 5315 (void *)&cmd_lfc_set_flow_ctrl, 5316 (void *)&cmd_lfc_set_high_water_str, 5317 (void *)&cmd_lfc_set_high_water, 5318 (void *)&cmd_lfc_set_portid, 5319 NULL, 5320 }, 5321 }; 5322 5323 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 5324 .f = cmd_link_flow_ctrl_set_parsed, 5325 .data = (void *)&cmd_link_flow_control_set_lw, 5326 .help_str = "set flow_ctrl low_water <value> <port_id>: " 5327 "Change low water flow control parameter", 5328 .tokens = { 5329 (void *)&cmd_lfc_set_set, 5330 (void *)&cmd_lfc_set_flow_ctrl, 5331 (void *)&cmd_lfc_set_low_water_str, 5332 (void *)&cmd_lfc_set_low_water, 5333 (void *)&cmd_lfc_set_portid, 5334 NULL, 5335 }, 5336 }; 5337 5338 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 5339 .f = cmd_link_flow_ctrl_set_parsed, 5340 .data = (void *)&cmd_link_flow_control_set_pt, 5341 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 5342 "Change pause time flow control parameter", 5343 .tokens = { 5344 (void *)&cmd_lfc_set_set, 5345 (void *)&cmd_lfc_set_flow_ctrl, 5346 (void *)&cmd_lfc_set_pause_time_str, 5347 (void *)&cmd_lfc_set_pause_time, 5348 (void *)&cmd_lfc_set_portid, 5349 NULL, 5350 }, 5351 }; 5352 5353 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 5354 .f = cmd_link_flow_ctrl_set_parsed, 5355 .data = (void *)&cmd_link_flow_control_set_xon, 5356 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 5357 "Change send_xon flow control parameter", 5358 .tokens = { 5359 (void *)&cmd_lfc_set_set, 5360 (void *)&cmd_lfc_set_flow_ctrl, 5361 (void *)&cmd_lfc_set_send_xon_str, 5362 (void *)&cmd_lfc_set_send_xon, 5363 (void *)&cmd_lfc_set_portid, 5364 NULL, 5365 }, 5366 }; 5367 5368 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 5369 .f = cmd_link_flow_ctrl_set_parsed, 5370 .data = (void *)&cmd_link_flow_control_set_macfwd, 5371 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 5372 "Change mac ctrl fwd flow control parameter", 5373 .tokens = { 5374 (void *)&cmd_lfc_set_set, 5375 (void *)&cmd_lfc_set_flow_ctrl, 5376 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5377 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5378 (void *)&cmd_lfc_set_portid, 5379 NULL, 5380 }, 5381 }; 5382 5383 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 5384 .f = cmd_link_flow_ctrl_set_parsed, 5385 .data = (void *)&cmd_link_flow_control_set_autoneg, 5386 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 5387 "Change autoneg flow control parameter", 5388 .tokens = { 5389 (void *)&cmd_lfc_set_set, 5390 (void *)&cmd_lfc_set_flow_ctrl, 5391 (void *)&cmd_lfc_set_autoneg_str, 5392 (void *)&cmd_lfc_set_autoneg, 5393 (void *)&cmd_lfc_set_portid, 5394 NULL, 5395 }, 5396 }; 5397 5398 static void 5399 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 5400 __attribute__((unused)) struct cmdline *cl, 5401 void *data) 5402 { 5403 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 5404 cmdline_parse_inst_t *cmd = data; 5405 struct rte_eth_fc_conf fc_conf; 5406 int rx_fc_en = 0; 5407 int tx_fc_en = 0; 5408 int ret; 5409 5410 /* 5411 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5412 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5413 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5414 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5415 */ 5416 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 5417 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 5418 }; 5419 5420 /* Partial command line, retrieve current configuration */ 5421 if (cmd) { 5422 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 5423 if (ret != 0) { 5424 printf("cannot get current flow ctrl parameters, return" 5425 "code = %d\n", ret); 5426 return; 5427 } 5428 5429 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 5430 (fc_conf.mode == RTE_FC_FULL)) 5431 rx_fc_en = 1; 5432 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 5433 (fc_conf.mode == RTE_FC_FULL)) 5434 tx_fc_en = 1; 5435 } 5436 5437 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 5438 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 5439 5440 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 5441 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 5442 5443 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 5444 5445 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 5446 fc_conf.high_water = res->high_water; 5447 5448 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 5449 fc_conf.low_water = res->low_water; 5450 5451 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 5452 fc_conf.pause_time = res->pause_time; 5453 5454 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 5455 fc_conf.send_xon = res->send_xon; 5456 5457 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 5458 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 5459 fc_conf.mac_ctrl_frame_fwd = 1; 5460 else 5461 fc_conf.mac_ctrl_frame_fwd = 0; 5462 } 5463 5464 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 5465 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 5466 5467 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 5468 if (ret != 0) 5469 printf("bad flow contrl parameter, return code = %d \n", ret); 5470 } 5471 5472 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */ 5473 struct cmd_priority_flow_ctrl_set_result { 5474 cmdline_fixed_string_t set; 5475 cmdline_fixed_string_t pfc_ctrl; 5476 cmdline_fixed_string_t rx; 5477 cmdline_fixed_string_t rx_pfc_mode; 5478 cmdline_fixed_string_t tx; 5479 cmdline_fixed_string_t tx_pfc_mode; 5480 uint32_t high_water; 5481 uint32_t low_water; 5482 uint16_t pause_time; 5483 uint8_t priority; 5484 uint8_t port_id; 5485 }; 5486 5487 static void 5488 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 5489 __attribute__((unused)) struct cmdline *cl, 5490 __attribute__((unused)) void *data) 5491 { 5492 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 5493 struct rte_eth_pfc_conf pfc_conf; 5494 int rx_fc_enable, tx_fc_enable; 5495 int ret; 5496 5497 /* 5498 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 5499 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 5500 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 5501 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 5502 */ 5503 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 5504 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 5505 }; 5506 5507 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 5508 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 5509 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 5510 pfc_conf.fc.high_water = res->high_water; 5511 pfc_conf.fc.low_water = res->low_water; 5512 pfc_conf.fc.pause_time = res->pause_time; 5513 pfc_conf.priority = res->priority; 5514 5515 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 5516 if (ret != 0) 5517 printf("bad priority flow contrl parameter, return code = %d \n", ret); 5518 } 5519 5520 cmdline_parse_token_string_t cmd_pfc_set_set = 5521 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5522 set, "set"); 5523 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 5524 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5525 pfc_ctrl, "pfc_ctrl"); 5526 cmdline_parse_token_string_t cmd_pfc_set_rx = 5527 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5528 rx, "rx"); 5529 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 5530 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5531 rx_pfc_mode, "on#off"); 5532 cmdline_parse_token_string_t cmd_pfc_set_tx = 5533 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5534 tx, "tx"); 5535 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 5536 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5537 tx_pfc_mode, "on#off"); 5538 cmdline_parse_token_num_t cmd_pfc_set_high_water = 5539 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5540 high_water, UINT32); 5541 cmdline_parse_token_num_t cmd_pfc_set_low_water = 5542 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5543 low_water, UINT32); 5544 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 5545 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5546 pause_time, UINT16); 5547 cmdline_parse_token_num_t cmd_pfc_set_priority = 5548 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5549 priority, UINT8); 5550 cmdline_parse_token_num_t cmd_pfc_set_portid = 5551 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 5552 port_id, UINT8); 5553 5554 cmdline_parse_inst_t cmd_priority_flow_control_set = { 5555 .f = cmd_priority_flow_ctrl_set_parsed, 5556 .data = NULL, 5557 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 5558 "<pause_time> <priority> <port_id>: " 5559 "Configure the Ethernet priority flow control", 5560 .tokens = { 5561 (void *)&cmd_pfc_set_set, 5562 (void *)&cmd_pfc_set_flow_ctrl, 5563 (void *)&cmd_pfc_set_rx, 5564 (void *)&cmd_pfc_set_rx_mode, 5565 (void *)&cmd_pfc_set_tx, 5566 (void *)&cmd_pfc_set_tx_mode, 5567 (void *)&cmd_pfc_set_high_water, 5568 (void *)&cmd_pfc_set_low_water, 5569 (void *)&cmd_pfc_set_pause_time, 5570 (void *)&cmd_pfc_set_priority, 5571 (void *)&cmd_pfc_set_portid, 5572 NULL, 5573 }, 5574 }; 5575 5576 /* *** RESET CONFIGURATION *** */ 5577 struct cmd_reset_result { 5578 cmdline_fixed_string_t reset; 5579 cmdline_fixed_string_t def; 5580 }; 5581 5582 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 5583 struct cmdline *cl, 5584 __attribute__((unused)) void *data) 5585 { 5586 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 5587 set_def_fwd_config(); 5588 } 5589 5590 cmdline_parse_token_string_t cmd_reset_set = 5591 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 5592 cmdline_parse_token_string_t cmd_reset_def = 5593 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 5594 "default"); 5595 5596 cmdline_parse_inst_t cmd_reset = { 5597 .f = cmd_reset_parsed, 5598 .data = NULL, 5599 .help_str = "set default: Reset default forwarding configuration", 5600 .tokens = { 5601 (void *)&cmd_reset_set, 5602 (void *)&cmd_reset_def, 5603 NULL, 5604 }, 5605 }; 5606 5607 /* *** START FORWARDING *** */ 5608 struct cmd_start_result { 5609 cmdline_fixed_string_t start; 5610 }; 5611 5612 cmdline_parse_token_string_t cmd_start_start = 5613 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 5614 5615 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 5616 __attribute__((unused)) struct cmdline *cl, 5617 __attribute__((unused)) void *data) 5618 { 5619 start_packet_forwarding(0); 5620 } 5621 5622 cmdline_parse_inst_t cmd_start = { 5623 .f = cmd_start_parsed, 5624 .data = NULL, 5625 .help_str = "start: Start packet forwarding", 5626 .tokens = { 5627 (void *)&cmd_start_start, 5628 NULL, 5629 }, 5630 }; 5631 5632 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 5633 struct cmd_start_tx_first_result { 5634 cmdline_fixed_string_t start; 5635 cmdline_fixed_string_t tx_first; 5636 }; 5637 5638 static void 5639 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 5640 __attribute__((unused)) struct cmdline *cl, 5641 __attribute__((unused)) void *data) 5642 { 5643 start_packet_forwarding(1); 5644 } 5645 5646 cmdline_parse_token_string_t cmd_start_tx_first_start = 5647 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 5648 "start"); 5649 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 5650 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 5651 tx_first, "tx_first"); 5652 5653 cmdline_parse_inst_t cmd_start_tx_first = { 5654 .f = cmd_start_tx_first_parsed, 5655 .data = NULL, 5656 .help_str = "start tx_first: Start packet forwarding, " 5657 "after sending 1 burst of packets", 5658 .tokens = { 5659 (void *)&cmd_start_tx_first_start, 5660 (void *)&cmd_start_tx_first_tx_first, 5661 NULL, 5662 }, 5663 }; 5664 5665 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 5666 struct cmd_start_tx_first_n_result { 5667 cmdline_fixed_string_t start; 5668 cmdline_fixed_string_t tx_first; 5669 uint32_t tx_num; 5670 }; 5671 5672 static void 5673 cmd_start_tx_first_n_parsed(void *parsed_result, 5674 __attribute__((unused)) struct cmdline *cl, 5675 __attribute__((unused)) void *data) 5676 { 5677 struct cmd_start_tx_first_n_result *res = parsed_result; 5678 5679 start_packet_forwarding(res->tx_num); 5680 } 5681 5682 cmdline_parse_token_string_t cmd_start_tx_first_n_start = 5683 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 5684 start, "start"); 5685 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 5686 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 5687 tx_first, "tx_first"); 5688 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 5689 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 5690 tx_num, UINT32); 5691 5692 cmdline_parse_inst_t cmd_start_tx_first_n = { 5693 .f = cmd_start_tx_first_n_parsed, 5694 .data = NULL, 5695 .help_str = "start tx_first <num>: " 5696 "packet forwarding, after sending <num> bursts of packets", 5697 .tokens = { 5698 (void *)&cmd_start_tx_first_n_start, 5699 (void *)&cmd_start_tx_first_n_tx_first, 5700 (void *)&cmd_start_tx_first_n_tx_num, 5701 NULL, 5702 }, 5703 }; 5704 5705 /* *** SET LINK UP *** */ 5706 struct cmd_set_link_up_result { 5707 cmdline_fixed_string_t set; 5708 cmdline_fixed_string_t link_up; 5709 cmdline_fixed_string_t port; 5710 uint8_t port_id; 5711 }; 5712 5713 cmdline_parse_token_string_t cmd_set_link_up_set = 5714 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 5715 cmdline_parse_token_string_t cmd_set_link_up_link_up = 5716 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 5717 "link-up"); 5718 cmdline_parse_token_string_t cmd_set_link_up_port = 5719 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 5720 cmdline_parse_token_num_t cmd_set_link_up_port_id = 5721 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); 5722 5723 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 5724 __attribute__((unused)) struct cmdline *cl, 5725 __attribute__((unused)) void *data) 5726 { 5727 struct cmd_set_link_up_result *res = parsed_result; 5728 dev_set_link_up(res->port_id); 5729 } 5730 5731 cmdline_parse_inst_t cmd_set_link_up = { 5732 .f = cmd_set_link_up_parsed, 5733 .data = NULL, 5734 .help_str = "set link-up port <port id>", 5735 .tokens = { 5736 (void *)&cmd_set_link_up_set, 5737 (void *)&cmd_set_link_up_link_up, 5738 (void *)&cmd_set_link_up_port, 5739 (void *)&cmd_set_link_up_port_id, 5740 NULL, 5741 }, 5742 }; 5743 5744 /* *** SET LINK DOWN *** */ 5745 struct cmd_set_link_down_result { 5746 cmdline_fixed_string_t set; 5747 cmdline_fixed_string_t link_down; 5748 cmdline_fixed_string_t port; 5749 uint8_t port_id; 5750 }; 5751 5752 cmdline_parse_token_string_t cmd_set_link_down_set = 5753 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 5754 cmdline_parse_token_string_t cmd_set_link_down_link_down = 5755 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 5756 "link-down"); 5757 cmdline_parse_token_string_t cmd_set_link_down_port = 5758 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 5759 cmdline_parse_token_num_t cmd_set_link_down_port_id = 5760 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); 5761 5762 static void cmd_set_link_down_parsed( 5763 __attribute__((unused)) void *parsed_result, 5764 __attribute__((unused)) struct cmdline *cl, 5765 __attribute__((unused)) void *data) 5766 { 5767 struct cmd_set_link_down_result *res = parsed_result; 5768 dev_set_link_down(res->port_id); 5769 } 5770 5771 cmdline_parse_inst_t cmd_set_link_down = { 5772 .f = cmd_set_link_down_parsed, 5773 .data = NULL, 5774 .help_str = "set link-down port <port id>", 5775 .tokens = { 5776 (void *)&cmd_set_link_down_set, 5777 (void *)&cmd_set_link_down_link_down, 5778 (void *)&cmd_set_link_down_port, 5779 (void *)&cmd_set_link_down_port_id, 5780 NULL, 5781 }, 5782 }; 5783 5784 /* *** SHOW CFG *** */ 5785 struct cmd_showcfg_result { 5786 cmdline_fixed_string_t show; 5787 cmdline_fixed_string_t cfg; 5788 cmdline_fixed_string_t what; 5789 }; 5790 5791 static void cmd_showcfg_parsed(void *parsed_result, 5792 __attribute__((unused)) struct cmdline *cl, 5793 __attribute__((unused)) void *data) 5794 { 5795 struct cmd_showcfg_result *res = parsed_result; 5796 if (!strcmp(res->what, "rxtx")) 5797 rxtx_config_display(); 5798 else if (!strcmp(res->what, "cores")) 5799 fwd_lcores_config_display(); 5800 else if (!strcmp(res->what, "fwd")) 5801 pkt_fwd_config_display(&cur_fwd_config); 5802 else if (!strcmp(res->what, "txpkts")) 5803 show_tx_pkt_segments(); 5804 } 5805 5806 cmdline_parse_token_string_t cmd_showcfg_show = 5807 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 5808 cmdline_parse_token_string_t cmd_showcfg_port = 5809 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 5810 cmdline_parse_token_string_t cmd_showcfg_what = 5811 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 5812 "rxtx#cores#fwd#txpkts"); 5813 5814 cmdline_parse_inst_t cmd_showcfg = { 5815 .f = cmd_showcfg_parsed, 5816 .data = NULL, 5817 .help_str = "show config rxtx|cores|fwd|txpkts", 5818 .tokens = { 5819 (void *)&cmd_showcfg_show, 5820 (void *)&cmd_showcfg_port, 5821 (void *)&cmd_showcfg_what, 5822 NULL, 5823 }, 5824 }; 5825 5826 /* *** SHOW ALL PORT INFO *** */ 5827 struct cmd_showportall_result { 5828 cmdline_fixed_string_t show; 5829 cmdline_fixed_string_t port; 5830 cmdline_fixed_string_t what; 5831 cmdline_fixed_string_t all; 5832 }; 5833 5834 static void cmd_showportall_parsed(void *parsed_result, 5835 __attribute__((unused)) struct cmdline *cl, 5836 __attribute__((unused)) void *data) 5837 { 5838 portid_t i; 5839 5840 struct cmd_showportall_result *res = parsed_result; 5841 if (!strcmp(res->show, "clear")) { 5842 if (!strcmp(res->what, "stats")) 5843 FOREACH_PORT(i, ports) 5844 nic_stats_clear(i); 5845 else if (!strcmp(res->what, "xstats")) 5846 FOREACH_PORT(i, ports) 5847 nic_xstats_clear(i); 5848 } else if (!strcmp(res->what, "info")) 5849 FOREACH_PORT(i, ports) 5850 port_infos_display(i); 5851 else if (!strcmp(res->what, "stats")) 5852 FOREACH_PORT(i, ports) 5853 nic_stats_display(i); 5854 else if (!strcmp(res->what, "xstats")) 5855 FOREACH_PORT(i, ports) 5856 nic_xstats_display(i); 5857 else if (!strcmp(res->what, "fdir")) 5858 FOREACH_PORT(i, ports) 5859 fdir_get_infos(i); 5860 else if (!strcmp(res->what, "stat_qmap")) 5861 FOREACH_PORT(i, ports) 5862 nic_stats_mapping_display(i); 5863 else if (!strcmp(res->what, "dcb_tc")) 5864 FOREACH_PORT(i, ports) 5865 port_dcb_info_display(i); 5866 else if (!strcmp(res->what, "cap")) 5867 FOREACH_PORT(i, ports) 5868 port_offload_cap_display(i); 5869 } 5870 5871 cmdline_parse_token_string_t cmd_showportall_show = 5872 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 5873 "show#clear"); 5874 cmdline_parse_token_string_t cmd_showportall_port = 5875 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 5876 cmdline_parse_token_string_t cmd_showportall_what = 5877 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 5878 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 5879 cmdline_parse_token_string_t cmd_showportall_all = 5880 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 5881 cmdline_parse_inst_t cmd_showportall = { 5882 .f = cmd_showportall_parsed, 5883 .data = NULL, 5884 .help_str = "show|clear port " 5885 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all", 5886 .tokens = { 5887 (void *)&cmd_showportall_show, 5888 (void *)&cmd_showportall_port, 5889 (void *)&cmd_showportall_what, 5890 (void *)&cmd_showportall_all, 5891 NULL, 5892 }, 5893 }; 5894 5895 /* *** SHOW PORT INFO *** */ 5896 struct cmd_showport_result { 5897 cmdline_fixed_string_t show; 5898 cmdline_fixed_string_t port; 5899 cmdline_fixed_string_t what; 5900 uint8_t portnum; 5901 }; 5902 5903 static void cmd_showport_parsed(void *parsed_result, 5904 __attribute__((unused)) struct cmdline *cl, 5905 __attribute__((unused)) void *data) 5906 { 5907 struct cmd_showport_result *res = parsed_result; 5908 if (!strcmp(res->show, "clear")) { 5909 if (!strcmp(res->what, "stats")) 5910 nic_stats_clear(res->portnum); 5911 else if (!strcmp(res->what, "xstats")) 5912 nic_xstats_clear(res->portnum); 5913 } else if (!strcmp(res->what, "info")) 5914 port_infos_display(res->portnum); 5915 else if (!strcmp(res->what, "stats")) 5916 nic_stats_display(res->portnum); 5917 else if (!strcmp(res->what, "xstats")) 5918 nic_xstats_display(res->portnum); 5919 else if (!strcmp(res->what, "fdir")) 5920 fdir_get_infos(res->portnum); 5921 else if (!strcmp(res->what, "stat_qmap")) 5922 nic_stats_mapping_display(res->portnum); 5923 else if (!strcmp(res->what, "dcb_tc")) 5924 port_dcb_info_display(res->portnum); 5925 else if (!strcmp(res->what, "cap")) 5926 port_offload_cap_display(res->portnum); 5927 } 5928 5929 cmdline_parse_token_string_t cmd_showport_show = 5930 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 5931 "show#clear"); 5932 cmdline_parse_token_string_t cmd_showport_port = 5933 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 5934 cmdline_parse_token_string_t cmd_showport_what = 5935 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 5936 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 5937 cmdline_parse_token_num_t cmd_showport_portnum = 5938 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); 5939 5940 cmdline_parse_inst_t cmd_showport = { 5941 .f = cmd_showport_parsed, 5942 .data = NULL, 5943 .help_str = "show|clear port " 5944 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap " 5945 "<port_id>", 5946 .tokens = { 5947 (void *)&cmd_showport_show, 5948 (void *)&cmd_showport_port, 5949 (void *)&cmd_showport_what, 5950 (void *)&cmd_showport_portnum, 5951 NULL, 5952 }, 5953 }; 5954 5955 /* *** SHOW QUEUE INFO *** */ 5956 struct cmd_showqueue_result { 5957 cmdline_fixed_string_t show; 5958 cmdline_fixed_string_t type; 5959 cmdline_fixed_string_t what; 5960 uint8_t portnum; 5961 uint16_t queuenum; 5962 }; 5963 5964 static void 5965 cmd_showqueue_parsed(void *parsed_result, 5966 __attribute__((unused)) struct cmdline *cl, 5967 __attribute__((unused)) void *data) 5968 { 5969 struct cmd_showqueue_result *res = parsed_result; 5970 5971 if (!strcmp(res->type, "rxq")) 5972 rx_queue_infos_display(res->portnum, res->queuenum); 5973 else if (!strcmp(res->type, "txq")) 5974 tx_queue_infos_display(res->portnum, res->queuenum); 5975 } 5976 5977 cmdline_parse_token_string_t cmd_showqueue_show = 5978 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 5979 cmdline_parse_token_string_t cmd_showqueue_type = 5980 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 5981 cmdline_parse_token_string_t cmd_showqueue_what = 5982 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 5983 cmdline_parse_token_num_t cmd_showqueue_portnum = 5984 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8); 5985 cmdline_parse_token_num_t cmd_showqueue_queuenum = 5986 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); 5987 5988 cmdline_parse_inst_t cmd_showqueue = { 5989 .f = cmd_showqueue_parsed, 5990 .data = NULL, 5991 .help_str = "show rxq|txq info <port_id> <queue_id>", 5992 .tokens = { 5993 (void *)&cmd_showqueue_show, 5994 (void *)&cmd_showqueue_type, 5995 (void *)&cmd_showqueue_what, 5996 (void *)&cmd_showqueue_portnum, 5997 (void *)&cmd_showqueue_queuenum, 5998 NULL, 5999 }, 6000 }; 6001 6002 /* *** READ PORT REGISTER *** */ 6003 struct cmd_read_reg_result { 6004 cmdline_fixed_string_t read; 6005 cmdline_fixed_string_t reg; 6006 uint8_t port_id; 6007 uint32_t reg_off; 6008 }; 6009 6010 static void 6011 cmd_read_reg_parsed(void *parsed_result, 6012 __attribute__((unused)) struct cmdline *cl, 6013 __attribute__((unused)) void *data) 6014 { 6015 struct cmd_read_reg_result *res = parsed_result; 6016 port_reg_display(res->port_id, res->reg_off); 6017 } 6018 6019 cmdline_parse_token_string_t cmd_read_reg_read = 6020 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 6021 cmdline_parse_token_string_t cmd_read_reg_reg = 6022 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 6023 cmdline_parse_token_num_t cmd_read_reg_port_id = 6024 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 6025 cmdline_parse_token_num_t cmd_read_reg_reg_off = 6026 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 6027 6028 cmdline_parse_inst_t cmd_read_reg = { 6029 .f = cmd_read_reg_parsed, 6030 .data = NULL, 6031 .help_str = "read reg <port_id> <reg_off>", 6032 .tokens = { 6033 (void *)&cmd_read_reg_read, 6034 (void *)&cmd_read_reg_reg, 6035 (void *)&cmd_read_reg_port_id, 6036 (void *)&cmd_read_reg_reg_off, 6037 NULL, 6038 }, 6039 }; 6040 6041 /* *** READ PORT REGISTER BIT FIELD *** */ 6042 struct cmd_read_reg_bit_field_result { 6043 cmdline_fixed_string_t read; 6044 cmdline_fixed_string_t regfield; 6045 uint8_t port_id; 6046 uint32_t reg_off; 6047 uint8_t bit1_pos; 6048 uint8_t bit2_pos; 6049 }; 6050 6051 static void 6052 cmd_read_reg_bit_field_parsed(void *parsed_result, 6053 __attribute__((unused)) struct cmdline *cl, 6054 __attribute__((unused)) void *data) 6055 { 6056 struct cmd_read_reg_bit_field_result *res = parsed_result; 6057 port_reg_bit_field_display(res->port_id, res->reg_off, 6058 res->bit1_pos, res->bit2_pos); 6059 } 6060 6061 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 6062 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 6063 "read"); 6064 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 6065 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 6066 regfield, "regfield"); 6067 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 6068 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 6069 UINT8); 6070 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 6071 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 6072 UINT32); 6073 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 6074 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 6075 UINT8); 6076 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 6077 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 6078 UINT8); 6079 6080 cmdline_parse_inst_t cmd_read_reg_bit_field = { 6081 .f = cmd_read_reg_bit_field_parsed, 6082 .data = NULL, 6083 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 6084 "Read register bit field between bit_x and bit_y included", 6085 .tokens = { 6086 (void *)&cmd_read_reg_bit_field_read, 6087 (void *)&cmd_read_reg_bit_field_regfield, 6088 (void *)&cmd_read_reg_bit_field_port_id, 6089 (void *)&cmd_read_reg_bit_field_reg_off, 6090 (void *)&cmd_read_reg_bit_field_bit1_pos, 6091 (void *)&cmd_read_reg_bit_field_bit2_pos, 6092 NULL, 6093 }, 6094 }; 6095 6096 /* *** READ PORT REGISTER BIT *** */ 6097 struct cmd_read_reg_bit_result { 6098 cmdline_fixed_string_t read; 6099 cmdline_fixed_string_t regbit; 6100 uint8_t port_id; 6101 uint32_t reg_off; 6102 uint8_t bit_pos; 6103 }; 6104 6105 static void 6106 cmd_read_reg_bit_parsed(void *parsed_result, 6107 __attribute__((unused)) struct cmdline *cl, 6108 __attribute__((unused)) void *data) 6109 { 6110 struct cmd_read_reg_bit_result *res = parsed_result; 6111 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 6112 } 6113 6114 cmdline_parse_token_string_t cmd_read_reg_bit_read = 6115 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 6116 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 6117 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 6118 regbit, "regbit"); 6119 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 6120 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 6121 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 6122 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 6123 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 6124 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 6125 6126 cmdline_parse_inst_t cmd_read_reg_bit = { 6127 .f = cmd_read_reg_bit_parsed, 6128 .data = NULL, 6129 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 6130 .tokens = { 6131 (void *)&cmd_read_reg_bit_read, 6132 (void *)&cmd_read_reg_bit_regbit, 6133 (void *)&cmd_read_reg_bit_port_id, 6134 (void *)&cmd_read_reg_bit_reg_off, 6135 (void *)&cmd_read_reg_bit_bit_pos, 6136 NULL, 6137 }, 6138 }; 6139 6140 /* *** WRITE PORT REGISTER *** */ 6141 struct cmd_write_reg_result { 6142 cmdline_fixed_string_t write; 6143 cmdline_fixed_string_t reg; 6144 uint8_t port_id; 6145 uint32_t reg_off; 6146 uint32_t value; 6147 }; 6148 6149 static void 6150 cmd_write_reg_parsed(void *parsed_result, 6151 __attribute__((unused)) struct cmdline *cl, 6152 __attribute__((unused)) void *data) 6153 { 6154 struct cmd_write_reg_result *res = parsed_result; 6155 port_reg_set(res->port_id, res->reg_off, res->value); 6156 } 6157 6158 cmdline_parse_token_string_t cmd_write_reg_write = 6159 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 6160 cmdline_parse_token_string_t cmd_write_reg_reg = 6161 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 6162 cmdline_parse_token_num_t cmd_write_reg_port_id = 6163 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 6164 cmdline_parse_token_num_t cmd_write_reg_reg_off = 6165 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 6166 cmdline_parse_token_num_t cmd_write_reg_value = 6167 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 6168 6169 cmdline_parse_inst_t cmd_write_reg = { 6170 .f = cmd_write_reg_parsed, 6171 .data = NULL, 6172 .help_str = "write reg <port_id> <reg_off> <reg_value>", 6173 .tokens = { 6174 (void *)&cmd_write_reg_write, 6175 (void *)&cmd_write_reg_reg, 6176 (void *)&cmd_write_reg_port_id, 6177 (void *)&cmd_write_reg_reg_off, 6178 (void *)&cmd_write_reg_value, 6179 NULL, 6180 }, 6181 }; 6182 6183 /* *** WRITE PORT REGISTER BIT FIELD *** */ 6184 struct cmd_write_reg_bit_field_result { 6185 cmdline_fixed_string_t write; 6186 cmdline_fixed_string_t regfield; 6187 uint8_t port_id; 6188 uint32_t reg_off; 6189 uint8_t bit1_pos; 6190 uint8_t bit2_pos; 6191 uint32_t value; 6192 }; 6193 6194 static void 6195 cmd_write_reg_bit_field_parsed(void *parsed_result, 6196 __attribute__((unused)) struct cmdline *cl, 6197 __attribute__((unused)) void *data) 6198 { 6199 struct cmd_write_reg_bit_field_result *res = parsed_result; 6200 port_reg_bit_field_set(res->port_id, res->reg_off, 6201 res->bit1_pos, res->bit2_pos, res->value); 6202 } 6203 6204 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 6205 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 6206 "write"); 6207 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 6208 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 6209 regfield, "regfield"); 6210 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 6211 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 6212 UINT8); 6213 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 6214 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 6215 UINT32); 6216 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 6217 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 6218 UINT8); 6219 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 6220 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 6221 UINT8); 6222 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 6223 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 6224 UINT32); 6225 6226 cmdline_parse_inst_t cmd_write_reg_bit_field = { 6227 .f = cmd_write_reg_bit_field_parsed, 6228 .data = NULL, 6229 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 6230 "<reg_value>: " 6231 "Set register bit field between bit_x and bit_y included", 6232 .tokens = { 6233 (void *)&cmd_write_reg_bit_field_write, 6234 (void *)&cmd_write_reg_bit_field_regfield, 6235 (void *)&cmd_write_reg_bit_field_port_id, 6236 (void *)&cmd_write_reg_bit_field_reg_off, 6237 (void *)&cmd_write_reg_bit_field_bit1_pos, 6238 (void *)&cmd_write_reg_bit_field_bit2_pos, 6239 (void *)&cmd_write_reg_bit_field_value, 6240 NULL, 6241 }, 6242 }; 6243 6244 /* *** WRITE PORT REGISTER BIT *** */ 6245 struct cmd_write_reg_bit_result { 6246 cmdline_fixed_string_t write; 6247 cmdline_fixed_string_t regbit; 6248 uint8_t port_id; 6249 uint32_t reg_off; 6250 uint8_t bit_pos; 6251 uint8_t value; 6252 }; 6253 6254 static void 6255 cmd_write_reg_bit_parsed(void *parsed_result, 6256 __attribute__((unused)) struct cmdline *cl, 6257 __attribute__((unused)) void *data) 6258 { 6259 struct cmd_write_reg_bit_result *res = parsed_result; 6260 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 6261 } 6262 6263 cmdline_parse_token_string_t cmd_write_reg_bit_write = 6264 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 6265 "write"); 6266 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 6267 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 6268 regbit, "regbit"); 6269 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 6270 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 6271 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 6272 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 6273 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 6274 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 6275 cmdline_parse_token_num_t cmd_write_reg_bit_value = 6276 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 6277 6278 cmdline_parse_inst_t cmd_write_reg_bit = { 6279 .f = cmd_write_reg_bit_parsed, 6280 .data = NULL, 6281 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 6282 "0 <= bit_x <= 31", 6283 .tokens = { 6284 (void *)&cmd_write_reg_bit_write, 6285 (void *)&cmd_write_reg_bit_regbit, 6286 (void *)&cmd_write_reg_bit_port_id, 6287 (void *)&cmd_write_reg_bit_reg_off, 6288 (void *)&cmd_write_reg_bit_bit_pos, 6289 (void *)&cmd_write_reg_bit_value, 6290 NULL, 6291 }, 6292 }; 6293 6294 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 6295 struct cmd_read_rxd_txd_result { 6296 cmdline_fixed_string_t read; 6297 cmdline_fixed_string_t rxd_txd; 6298 uint8_t port_id; 6299 uint16_t queue_id; 6300 uint16_t desc_id; 6301 }; 6302 6303 static void 6304 cmd_read_rxd_txd_parsed(void *parsed_result, 6305 __attribute__((unused)) struct cmdline *cl, 6306 __attribute__((unused)) void *data) 6307 { 6308 struct cmd_read_rxd_txd_result *res = parsed_result; 6309 6310 if (!strcmp(res->rxd_txd, "rxd")) 6311 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6312 else if (!strcmp(res->rxd_txd, "txd")) 6313 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6314 } 6315 6316 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 6317 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 6318 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 6319 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 6320 "rxd#txd"); 6321 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 6322 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 6323 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 6324 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 6325 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 6326 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 6327 6328 cmdline_parse_inst_t cmd_read_rxd_txd = { 6329 .f = cmd_read_rxd_txd_parsed, 6330 .data = NULL, 6331 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 6332 .tokens = { 6333 (void *)&cmd_read_rxd_txd_read, 6334 (void *)&cmd_read_rxd_txd_rxd_txd, 6335 (void *)&cmd_read_rxd_txd_port_id, 6336 (void *)&cmd_read_rxd_txd_queue_id, 6337 (void *)&cmd_read_rxd_txd_desc_id, 6338 NULL, 6339 }, 6340 }; 6341 6342 /* *** QUIT *** */ 6343 struct cmd_quit_result { 6344 cmdline_fixed_string_t quit; 6345 }; 6346 6347 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 6348 struct cmdline *cl, 6349 __attribute__((unused)) void *data) 6350 { 6351 pmd_test_exit(); 6352 cmdline_quit(cl); 6353 } 6354 6355 cmdline_parse_token_string_t cmd_quit_quit = 6356 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 6357 6358 cmdline_parse_inst_t cmd_quit = { 6359 .f = cmd_quit_parsed, 6360 .data = NULL, 6361 .help_str = "quit: Exit application", 6362 .tokens = { 6363 (void *)&cmd_quit_quit, 6364 NULL, 6365 }, 6366 }; 6367 6368 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 6369 struct cmd_mac_addr_result { 6370 cmdline_fixed_string_t mac_addr_cmd; 6371 cmdline_fixed_string_t what; 6372 uint8_t port_num; 6373 struct ether_addr address; 6374 }; 6375 6376 static void cmd_mac_addr_parsed(void *parsed_result, 6377 __attribute__((unused)) struct cmdline *cl, 6378 __attribute__((unused)) void *data) 6379 { 6380 struct cmd_mac_addr_result *res = parsed_result; 6381 int ret; 6382 6383 if (strcmp(res->what, "add") == 0) 6384 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 6385 else if (strcmp(res->what, "set") == 0) 6386 ret = rte_eth_dev_default_mac_addr_set(res->port_num, 6387 &res->address); 6388 else 6389 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 6390 6391 /* check the return value and print it if is < 0 */ 6392 if(ret < 0) 6393 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 6394 6395 } 6396 6397 cmdline_parse_token_string_t cmd_mac_addr_cmd = 6398 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 6399 "mac_addr"); 6400 cmdline_parse_token_string_t cmd_mac_addr_what = 6401 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 6402 "add#remove#set"); 6403 cmdline_parse_token_num_t cmd_mac_addr_portnum = 6404 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 6405 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 6406 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 6407 6408 cmdline_parse_inst_t cmd_mac_addr = { 6409 .f = cmd_mac_addr_parsed, 6410 .data = (void *)0, 6411 .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: " 6412 "Add/Remove/Set MAC address on port_id", 6413 .tokens = { 6414 (void *)&cmd_mac_addr_cmd, 6415 (void *)&cmd_mac_addr_what, 6416 (void *)&cmd_mac_addr_portnum, 6417 (void *)&cmd_mac_addr_addr, 6418 NULL, 6419 }, 6420 }; 6421 6422 6423 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 6424 struct cmd_set_qmap_result { 6425 cmdline_fixed_string_t set; 6426 cmdline_fixed_string_t qmap; 6427 cmdline_fixed_string_t what; 6428 uint8_t port_id; 6429 uint16_t queue_id; 6430 uint8_t map_value; 6431 }; 6432 6433 static void 6434 cmd_set_qmap_parsed(void *parsed_result, 6435 __attribute__((unused)) struct cmdline *cl, 6436 __attribute__((unused)) void *data) 6437 { 6438 struct cmd_set_qmap_result *res = parsed_result; 6439 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 6440 6441 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 6442 } 6443 6444 cmdline_parse_token_string_t cmd_setqmap_set = 6445 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6446 set, "set"); 6447 cmdline_parse_token_string_t cmd_setqmap_qmap = 6448 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6449 qmap, "stat_qmap"); 6450 cmdline_parse_token_string_t cmd_setqmap_what = 6451 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 6452 what, "tx#rx"); 6453 cmdline_parse_token_num_t cmd_setqmap_portid = 6454 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6455 port_id, UINT8); 6456 cmdline_parse_token_num_t cmd_setqmap_queueid = 6457 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6458 queue_id, UINT16); 6459 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 6460 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 6461 map_value, UINT8); 6462 6463 cmdline_parse_inst_t cmd_set_qmap = { 6464 .f = cmd_set_qmap_parsed, 6465 .data = NULL, 6466 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 6467 "Set statistics mapping value on tx|rx queue_id of port_id", 6468 .tokens = { 6469 (void *)&cmd_setqmap_set, 6470 (void *)&cmd_setqmap_qmap, 6471 (void *)&cmd_setqmap_what, 6472 (void *)&cmd_setqmap_portid, 6473 (void *)&cmd_setqmap_queueid, 6474 (void *)&cmd_setqmap_mapvalue, 6475 NULL, 6476 }, 6477 }; 6478 6479 /* *** CONFIGURE UNICAST HASH TABLE *** */ 6480 struct cmd_set_uc_hash_table { 6481 cmdline_fixed_string_t set; 6482 cmdline_fixed_string_t port; 6483 uint8_t port_id; 6484 cmdline_fixed_string_t what; 6485 struct ether_addr address; 6486 cmdline_fixed_string_t mode; 6487 }; 6488 6489 static void 6490 cmd_set_uc_hash_parsed(void *parsed_result, 6491 __attribute__((unused)) struct cmdline *cl, 6492 __attribute__((unused)) void *data) 6493 { 6494 int ret=0; 6495 struct cmd_set_uc_hash_table *res = parsed_result; 6496 6497 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6498 6499 if (strcmp(res->what, "uta") == 0) 6500 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 6501 &res->address,(uint8_t)is_on); 6502 if (ret < 0) 6503 printf("bad unicast hash table parameter, return code = %d \n", ret); 6504 6505 } 6506 6507 cmdline_parse_token_string_t cmd_set_uc_hash_set = 6508 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6509 set, "set"); 6510 cmdline_parse_token_string_t cmd_set_uc_hash_port = 6511 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6512 port, "port"); 6513 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 6514 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 6515 port_id, UINT8); 6516 cmdline_parse_token_string_t cmd_set_uc_hash_what = 6517 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6518 what, "uta"); 6519 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 6520 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 6521 address); 6522 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 6523 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 6524 mode, "on#off"); 6525 6526 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 6527 .f = cmd_set_uc_hash_parsed, 6528 .data = NULL, 6529 .help_str = "set port <port_id> uta <mac_addr> on|off)", 6530 .tokens = { 6531 (void *)&cmd_set_uc_hash_set, 6532 (void *)&cmd_set_uc_hash_port, 6533 (void *)&cmd_set_uc_hash_portid, 6534 (void *)&cmd_set_uc_hash_what, 6535 (void *)&cmd_set_uc_hash_mac, 6536 (void *)&cmd_set_uc_hash_mode, 6537 NULL, 6538 }, 6539 }; 6540 6541 struct cmd_set_uc_all_hash_table { 6542 cmdline_fixed_string_t set; 6543 cmdline_fixed_string_t port; 6544 uint8_t port_id; 6545 cmdline_fixed_string_t what; 6546 cmdline_fixed_string_t value; 6547 cmdline_fixed_string_t mode; 6548 }; 6549 6550 static void 6551 cmd_set_uc_all_hash_parsed(void *parsed_result, 6552 __attribute__((unused)) struct cmdline *cl, 6553 __attribute__((unused)) void *data) 6554 { 6555 int ret=0; 6556 struct cmd_set_uc_all_hash_table *res = parsed_result; 6557 6558 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6559 6560 if ((strcmp(res->what, "uta") == 0) && 6561 (strcmp(res->value, "all") == 0)) 6562 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 6563 if (ret < 0) 6564 printf("bad unicast hash table parameter," 6565 "return code = %d \n", ret); 6566 } 6567 6568 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 6569 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6570 set, "set"); 6571 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 6572 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6573 port, "port"); 6574 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 6575 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 6576 port_id, UINT8); 6577 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 6578 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6579 what, "uta"); 6580 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 6581 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6582 value,"all"); 6583 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 6584 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 6585 mode, "on#off"); 6586 6587 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 6588 .f = cmd_set_uc_all_hash_parsed, 6589 .data = NULL, 6590 .help_str = "set port <port_id> uta all on|off", 6591 .tokens = { 6592 (void *)&cmd_set_uc_all_hash_set, 6593 (void *)&cmd_set_uc_all_hash_port, 6594 (void *)&cmd_set_uc_all_hash_portid, 6595 (void *)&cmd_set_uc_all_hash_what, 6596 (void *)&cmd_set_uc_all_hash_value, 6597 (void *)&cmd_set_uc_all_hash_mode, 6598 NULL, 6599 }, 6600 }; 6601 6602 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 6603 struct cmd_set_vf_macvlan_filter { 6604 cmdline_fixed_string_t set; 6605 cmdline_fixed_string_t port; 6606 uint8_t port_id; 6607 cmdline_fixed_string_t vf; 6608 uint8_t vf_id; 6609 struct ether_addr address; 6610 cmdline_fixed_string_t filter_type; 6611 cmdline_fixed_string_t mode; 6612 }; 6613 6614 static void 6615 cmd_set_vf_macvlan_parsed(void *parsed_result, 6616 __attribute__((unused)) struct cmdline *cl, 6617 __attribute__((unused)) void *data) 6618 { 6619 int is_on, ret = 0; 6620 struct cmd_set_vf_macvlan_filter *res = parsed_result; 6621 struct rte_eth_mac_filter filter; 6622 6623 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 6624 6625 (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 6626 6627 /* set VF MAC filter */ 6628 filter.is_vf = 1; 6629 6630 /* set VF ID */ 6631 filter.dst_id = res->vf_id; 6632 6633 if (!strcmp(res->filter_type, "exact-mac")) 6634 filter.filter_type = RTE_MAC_PERFECT_MATCH; 6635 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 6636 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 6637 else if (!strcmp(res->filter_type, "hashmac")) 6638 filter.filter_type = RTE_MAC_HASH_MATCH; 6639 else if (!strcmp(res->filter_type, "hashmac-vlan")) 6640 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 6641 6642 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6643 6644 if (is_on) 6645 ret = rte_eth_dev_filter_ctrl(res->port_id, 6646 RTE_ETH_FILTER_MACVLAN, 6647 RTE_ETH_FILTER_ADD, 6648 &filter); 6649 else 6650 ret = rte_eth_dev_filter_ctrl(res->port_id, 6651 RTE_ETH_FILTER_MACVLAN, 6652 RTE_ETH_FILTER_DELETE, 6653 &filter); 6654 6655 if (ret < 0) 6656 printf("bad set MAC hash parameter, return code = %d\n", ret); 6657 6658 } 6659 6660 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 6661 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6662 set, "set"); 6663 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 6664 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6665 port, "port"); 6666 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 6667 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6668 port_id, UINT8); 6669 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 6670 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6671 vf, "vf"); 6672 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 6673 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6674 vf_id, UINT8); 6675 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 6676 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6677 address); 6678 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 6679 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6680 filter_type, "exact-mac#exact-mac-vlan" 6681 "#hashmac#hashmac-vlan"); 6682 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 6683 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 6684 mode, "on#off"); 6685 6686 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 6687 .f = cmd_set_vf_macvlan_parsed, 6688 .data = NULL, 6689 .help_str = "set port <port_id> vf <vf_id> <mac_addr> " 6690 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: " 6691 "Exact match rule: exact match of MAC or MAC and VLAN; " 6692 "hash match rule: hash match of MAC and exact match of VLAN", 6693 .tokens = { 6694 (void *)&cmd_set_vf_macvlan_set, 6695 (void *)&cmd_set_vf_macvlan_port, 6696 (void *)&cmd_set_vf_macvlan_portid, 6697 (void *)&cmd_set_vf_macvlan_vf, 6698 (void *)&cmd_set_vf_macvlan_vf_id, 6699 (void *)&cmd_set_vf_macvlan_mac, 6700 (void *)&cmd_set_vf_macvlan_filter_type, 6701 (void *)&cmd_set_vf_macvlan_mode, 6702 NULL, 6703 }, 6704 }; 6705 6706 #ifdef RTE_LIBRTE_IXGBE_PMD 6707 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 6708 struct cmd_set_vf_traffic { 6709 cmdline_fixed_string_t set; 6710 cmdline_fixed_string_t port; 6711 uint8_t port_id; 6712 cmdline_fixed_string_t vf; 6713 uint8_t vf_id; 6714 cmdline_fixed_string_t what; 6715 cmdline_fixed_string_t mode; 6716 }; 6717 6718 static void 6719 cmd_set_vf_traffic_parsed(void *parsed_result, 6720 __attribute__((unused)) struct cmdline *cl, 6721 __attribute__((unused)) void *data) 6722 { 6723 struct cmd_set_vf_traffic *res = parsed_result; 6724 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 6725 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 6726 6727 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 6728 } 6729 6730 cmdline_parse_token_string_t cmd_setvf_traffic_set = 6731 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6732 set, "set"); 6733 cmdline_parse_token_string_t cmd_setvf_traffic_port = 6734 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6735 port, "port"); 6736 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 6737 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 6738 port_id, UINT8); 6739 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 6740 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6741 vf, "vf"); 6742 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 6743 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 6744 vf_id, UINT8); 6745 cmdline_parse_token_string_t cmd_setvf_traffic_what = 6746 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6747 what, "tx#rx"); 6748 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 6749 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 6750 mode, "on#off"); 6751 6752 cmdline_parse_inst_t cmd_set_vf_traffic = { 6753 .f = cmd_set_vf_traffic_parsed, 6754 .data = NULL, 6755 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 6756 .tokens = { 6757 (void *)&cmd_setvf_traffic_set, 6758 (void *)&cmd_setvf_traffic_port, 6759 (void *)&cmd_setvf_traffic_portid, 6760 (void *)&cmd_setvf_traffic_vf, 6761 (void *)&cmd_setvf_traffic_vfid, 6762 (void *)&cmd_setvf_traffic_what, 6763 (void *)&cmd_setvf_traffic_mode, 6764 NULL, 6765 }, 6766 }; 6767 6768 /* *** CONFIGURE VF RECEIVE MODE *** */ 6769 struct cmd_set_vf_rxmode { 6770 cmdline_fixed_string_t set; 6771 cmdline_fixed_string_t port; 6772 uint8_t port_id; 6773 cmdline_fixed_string_t vf; 6774 uint8_t vf_id; 6775 cmdline_fixed_string_t what; 6776 cmdline_fixed_string_t mode; 6777 cmdline_fixed_string_t on; 6778 }; 6779 6780 static void 6781 cmd_set_vf_rxmode_parsed(void *parsed_result, 6782 __attribute__((unused)) struct cmdline *cl, 6783 __attribute__((unused)) void *data) 6784 { 6785 int ret; 6786 uint16_t rx_mode = 0; 6787 struct cmd_set_vf_rxmode *res = parsed_result; 6788 6789 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 6790 if (!strcmp(res->what,"rxmode")) { 6791 if (!strcmp(res->mode, "AUPE")) 6792 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 6793 else if (!strcmp(res->mode, "ROPE")) 6794 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 6795 else if (!strcmp(res->mode, "BAM")) 6796 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 6797 else if (!strncmp(res->mode, "MPE",3)) 6798 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 6799 } 6800 6801 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, rx_mode, (uint8_t)is_on); 6802 if (ret < 0) 6803 printf("bad VF receive mode parameter, return code = %d \n", 6804 ret); 6805 } 6806 6807 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 6808 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6809 set, "set"); 6810 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 6811 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6812 port, "port"); 6813 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 6814 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6815 port_id, UINT8); 6816 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 6817 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6818 vf, "vf"); 6819 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 6820 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 6821 vf_id, UINT8); 6822 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 6823 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6824 what, "rxmode"); 6825 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 6826 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6827 mode, "AUPE#ROPE#BAM#MPE"); 6828 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 6829 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 6830 on, "on#off"); 6831 6832 cmdline_parse_inst_t cmd_set_vf_rxmode = { 6833 .f = cmd_set_vf_rxmode_parsed, 6834 .data = NULL, 6835 .help_str = "set port <port_id> vf <vf_id> rxmode " 6836 "AUPE|ROPE|BAM|MPE on|off", 6837 .tokens = { 6838 (void *)&cmd_set_vf_rxmode_set, 6839 (void *)&cmd_set_vf_rxmode_port, 6840 (void *)&cmd_set_vf_rxmode_portid, 6841 (void *)&cmd_set_vf_rxmode_vf, 6842 (void *)&cmd_set_vf_rxmode_vfid, 6843 (void *)&cmd_set_vf_rxmode_what, 6844 (void *)&cmd_set_vf_rxmode_mode, 6845 (void *)&cmd_set_vf_rxmode_on, 6846 NULL, 6847 }, 6848 }; 6849 #endif 6850 6851 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 6852 struct cmd_vf_mac_addr_result { 6853 cmdline_fixed_string_t mac_addr_cmd; 6854 cmdline_fixed_string_t what; 6855 cmdline_fixed_string_t port; 6856 uint8_t port_num; 6857 cmdline_fixed_string_t vf; 6858 uint8_t vf_num; 6859 struct ether_addr address; 6860 }; 6861 6862 static void cmd_vf_mac_addr_parsed(void *parsed_result, 6863 __attribute__((unused)) struct cmdline *cl, 6864 __attribute__((unused)) void *data) 6865 { 6866 struct cmd_vf_mac_addr_result *res = parsed_result; 6867 int ret = 0; 6868 6869 if (strcmp(res->what, "add") == 0) 6870 ret = rte_eth_dev_mac_addr_add(res->port_num, 6871 &res->address, res->vf_num); 6872 if(ret < 0) 6873 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 6874 6875 } 6876 6877 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 6878 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6879 mac_addr_cmd,"mac_addr"); 6880 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 6881 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6882 what,"add"); 6883 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 6884 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6885 port,"port"); 6886 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 6887 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6888 port_num, UINT8); 6889 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 6890 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 6891 vf,"vf"); 6892 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 6893 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 6894 vf_num, UINT8); 6895 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 6896 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 6897 address); 6898 6899 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 6900 .f = cmd_vf_mac_addr_parsed, 6901 .data = (void *)0, 6902 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 6903 "Add MAC address filtering for a VF on port_id", 6904 .tokens = { 6905 (void *)&cmd_vf_mac_addr_cmd, 6906 (void *)&cmd_vf_mac_addr_what, 6907 (void *)&cmd_vf_mac_addr_port, 6908 (void *)&cmd_vf_mac_addr_portnum, 6909 (void *)&cmd_vf_mac_addr_vf, 6910 (void *)&cmd_vf_mac_addr_vfnum, 6911 (void *)&cmd_vf_mac_addr_addr, 6912 NULL, 6913 }, 6914 }; 6915 6916 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 6917 struct cmd_vf_rx_vlan_filter { 6918 cmdline_fixed_string_t rx_vlan; 6919 cmdline_fixed_string_t what; 6920 uint16_t vlan_id; 6921 cmdline_fixed_string_t port; 6922 uint8_t port_id; 6923 cmdline_fixed_string_t vf; 6924 uint64_t vf_mask; 6925 }; 6926 6927 static void 6928 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 6929 __attribute__((unused)) struct cmdline *cl, 6930 __attribute__((unused)) void *data) 6931 { 6932 struct cmd_vf_rx_vlan_filter *res = parsed_result; 6933 int ret = -ENOTSUP; 6934 6935 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 6936 6937 #ifdef RTE_LIBRTE_IXGBE_PMD 6938 if (ret == -ENOTSUP) 6939 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 6940 res->vlan_id, res->vf_mask, is_add); 6941 #endif 6942 #ifdef RTE_LIBRTE_I40E_PMD 6943 if (ret == -ENOTSUP) 6944 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 6945 res->vlan_id, res->vf_mask, is_add); 6946 #endif 6947 6948 switch (ret) { 6949 case 0: 6950 break; 6951 case -EINVAL: 6952 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n", 6953 res->vlan_id, res->vf_mask); 6954 break; 6955 case -ENODEV: 6956 printf("invalid port_id %d\n", res->port_id); 6957 break; 6958 case -ENOTSUP: 6959 printf("function not implemented or supported\n"); 6960 break; 6961 default: 6962 printf("programming error: (%s)\n", strerror(-ret)); 6963 } 6964 } 6965 6966 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 6967 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6968 rx_vlan, "rx_vlan"); 6969 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 6970 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6971 what, "add#rm"); 6972 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 6973 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6974 vlan_id, UINT16); 6975 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 6976 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6977 port, "port"); 6978 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 6979 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6980 port_id, UINT8); 6981 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 6982 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6983 vf, "vf"); 6984 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 6985 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 6986 vf_mask, UINT64); 6987 6988 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 6989 .f = cmd_vf_rx_vlan_filter_parsed, 6990 .data = NULL, 6991 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 6992 "(vf_mask = hexadecimal VF mask)", 6993 .tokens = { 6994 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 6995 (void *)&cmd_vf_rx_vlan_filter_what, 6996 (void *)&cmd_vf_rx_vlan_filter_vlanid, 6997 (void *)&cmd_vf_rx_vlan_filter_port, 6998 (void *)&cmd_vf_rx_vlan_filter_portid, 6999 (void *)&cmd_vf_rx_vlan_filter_vf, 7000 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 7001 NULL, 7002 }, 7003 }; 7004 7005 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 7006 struct cmd_queue_rate_limit_result { 7007 cmdline_fixed_string_t set; 7008 cmdline_fixed_string_t port; 7009 uint8_t port_num; 7010 cmdline_fixed_string_t queue; 7011 uint8_t queue_num; 7012 cmdline_fixed_string_t rate; 7013 uint16_t rate_num; 7014 }; 7015 7016 static void cmd_queue_rate_limit_parsed(void *parsed_result, 7017 __attribute__((unused)) struct cmdline *cl, 7018 __attribute__((unused)) void *data) 7019 { 7020 struct cmd_queue_rate_limit_result *res = parsed_result; 7021 int ret = 0; 7022 7023 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7024 && (strcmp(res->queue, "queue") == 0) 7025 && (strcmp(res->rate, "rate") == 0)) 7026 ret = set_queue_rate_limit(res->port_num, res->queue_num, 7027 res->rate_num); 7028 if (ret < 0) 7029 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7030 7031 } 7032 7033 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 7034 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7035 set, "set"); 7036 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 7037 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7038 port, "port"); 7039 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 7040 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7041 port_num, UINT8); 7042 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 7043 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7044 queue, "queue"); 7045 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 7046 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7047 queue_num, UINT8); 7048 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 7049 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7050 rate, "rate"); 7051 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 7052 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7053 rate_num, UINT16); 7054 7055 cmdline_parse_inst_t cmd_queue_rate_limit = { 7056 .f = cmd_queue_rate_limit_parsed, 7057 .data = (void *)0, 7058 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 7059 "Set rate limit for a queue on port_id", 7060 .tokens = { 7061 (void *)&cmd_queue_rate_limit_set, 7062 (void *)&cmd_queue_rate_limit_port, 7063 (void *)&cmd_queue_rate_limit_portnum, 7064 (void *)&cmd_queue_rate_limit_queue, 7065 (void *)&cmd_queue_rate_limit_queuenum, 7066 (void *)&cmd_queue_rate_limit_rate, 7067 (void *)&cmd_queue_rate_limit_ratenum, 7068 NULL, 7069 }, 7070 }; 7071 7072 #ifdef RTE_LIBRTE_IXGBE_PMD 7073 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 7074 struct cmd_vf_rate_limit_result { 7075 cmdline_fixed_string_t set; 7076 cmdline_fixed_string_t port; 7077 uint8_t port_num; 7078 cmdline_fixed_string_t vf; 7079 uint8_t vf_num; 7080 cmdline_fixed_string_t rate; 7081 uint16_t rate_num; 7082 cmdline_fixed_string_t q_msk; 7083 uint64_t q_msk_val; 7084 }; 7085 7086 static void cmd_vf_rate_limit_parsed(void *parsed_result, 7087 __attribute__((unused)) struct cmdline *cl, 7088 __attribute__((unused)) void *data) 7089 { 7090 struct cmd_vf_rate_limit_result *res = parsed_result; 7091 int ret = 0; 7092 7093 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7094 && (strcmp(res->vf, "vf") == 0) 7095 && (strcmp(res->rate, "rate") == 0) 7096 && (strcmp(res->q_msk, "queue_mask") == 0)) 7097 ret = set_vf_rate_limit(res->port_num, res->vf_num, 7098 res->rate_num, res->q_msk_val); 7099 if (ret < 0) 7100 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7101 7102 } 7103 7104 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 7105 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7106 set, "set"); 7107 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 7108 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7109 port, "port"); 7110 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 7111 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7112 port_num, UINT8); 7113 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 7114 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7115 vf, "vf"); 7116 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 7117 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7118 vf_num, UINT8); 7119 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 7120 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7121 rate, "rate"); 7122 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 7123 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7124 rate_num, UINT16); 7125 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 7126 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7127 q_msk, "queue_mask"); 7128 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 7129 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7130 q_msk_val, UINT64); 7131 7132 cmdline_parse_inst_t cmd_vf_rate_limit = { 7133 .f = cmd_vf_rate_limit_parsed, 7134 .data = (void *)0, 7135 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 7136 "queue_mask <queue_mask_value>: " 7137 "Set rate limit for queues of VF on port_id", 7138 .tokens = { 7139 (void *)&cmd_vf_rate_limit_set, 7140 (void *)&cmd_vf_rate_limit_port, 7141 (void *)&cmd_vf_rate_limit_portnum, 7142 (void *)&cmd_vf_rate_limit_vf, 7143 (void *)&cmd_vf_rate_limit_vfnum, 7144 (void *)&cmd_vf_rate_limit_rate, 7145 (void *)&cmd_vf_rate_limit_ratenum, 7146 (void *)&cmd_vf_rate_limit_q_msk, 7147 (void *)&cmd_vf_rate_limit_q_msk_val, 7148 NULL, 7149 }, 7150 }; 7151 #endif 7152 7153 /* *** ADD TUNNEL FILTER OF A PORT *** */ 7154 struct cmd_tunnel_filter_result { 7155 cmdline_fixed_string_t cmd; 7156 cmdline_fixed_string_t what; 7157 uint8_t port_id; 7158 struct ether_addr outer_mac; 7159 struct ether_addr inner_mac; 7160 cmdline_ipaddr_t ip_value; 7161 uint16_t inner_vlan; 7162 cmdline_fixed_string_t tunnel_type; 7163 cmdline_fixed_string_t filter_type; 7164 uint32_t tenant_id; 7165 uint16_t queue_num; 7166 }; 7167 7168 static void 7169 cmd_tunnel_filter_parsed(void *parsed_result, 7170 __attribute__((unused)) struct cmdline *cl, 7171 __attribute__((unused)) void *data) 7172 { 7173 struct cmd_tunnel_filter_result *res = parsed_result; 7174 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 7175 int ret = 0; 7176 7177 memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf)); 7178 7179 ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac); 7180 ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac); 7181 tunnel_filter_conf.inner_vlan = res->inner_vlan; 7182 7183 if (res->ip_value.family == AF_INET) { 7184 tunnel_filter_conf.ip_addr.ipv4_addr = 7185 res->ip_value.addr.ipv4.s_addr; 7186 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 7187 } else { 7188 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 7189 &(res->ip_value.addr.ipv6), 7190 sizeof(struct in6_addr)); 7191 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 7192 } 7193 7194 if (!strcmp(res->filter_type, "imac-ivlan")) 7195 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 7196 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 7197 tunnel_filter_conf.filter_type = 7198 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 7199 else if (!strcmp(res->filter_type, "imac-tenid")) 7200 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 7201 else if (!strcmp(res->filter_type, "imac")) 7202 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 7203 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 7204 tunnel_filter_conf.filter_type = 7205 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 7206 else if (!strcmp(res->filter_type, "oip")) 7207 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP; 7208 else if (!strcmp(res->filter_type, "iip")) 7209 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP; 7210 else { 7211 printf("The filter type is not supported"); 7212 return; 7213 } 7214 7215 if (!strcmp(res->tunnel_type, "vxlan")) 7216 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 7217 else if (!strcmp(res->tunnel_type, "nvgre")) 7218 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 7219 else if (!strcmp(res->tunnel_type, "ipingre")) 7220 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE; 7221 else { 7222 printf("The tunnel type %s not supported.\n", res->tunnel_type); 7223 return; 7224 } 7225 7226 tunnel_filter_conf.tenant_id = res->tenant_id; 7227 tunnel_filter_conf.queue_id = res->queue_num; 7228 if (!strcmp(res->what, "add")) 7229 ret = rte_eth_dev_filter_ctrl(res->port_id, 7230 RTE_ETH_FILTER_TUNNEL, 7231 RTE_ETH_FILTER_ADD, 7232 &tunnel_filter_conf); 7233 else 7234 ret = rte_eth_dev_filter_ctrl(res->port_id, 7235 RTE_ETH_FILTER_TUNNEL, 7236 RTE_ETH_FILTER_DELETE, 7237 &tunnel_filter_conf); 7238 if (ret < 0) 7239 printf("cmd_tunnel_filter_parsed error: (%s)\n", 7240 strerror(-ret)); 7241 7242 } 7243 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 7244 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7245 cmd, "tunnel_filter"); 7246 cmdline_parse_token_string_t cmd_tunnel_filter_what = 7247 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7248 what, "add#rm"); 7249 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 7250 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7251 port_id, UINT8); 7252 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 7253 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7254 outer_mac); 7255 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 7256 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7257 inner_mac); 7258 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 7259 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7260 inner_vlan, UINT16); 7261 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 7262 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7263 ip_value); 7264 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 7265 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7266 tunnel_type, "vxlan#nvgre#ipingre"); 7267 7268 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 7269 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7270 filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#" 7271 "imac#omac-imac-tenid"); 7272 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 7273 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7274 tenant_id, UINT32); 7275 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 7276 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7277 queue_num, UINT16); 7278 7279 cmdline_parse_inst_t cmd_tunnel_filter = { 7280 .f = cmd_tunnel_filter_parsed, 7281 .data = (void *)0, 7282 .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> " 7283 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|" 7284 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> " 7285 "<queue_id>: Add/Rm tunnel filter of a port", 7286 .tokens = { 7287 (void *)&cmd_tunnel_filter_cmd, 7288 (void *)&cmd_tunnel_filter_what, 7289 (void *)&cmd_tunnel_filter_port_id, 7290 (void *)&cmd_tunnel_filter_outer_mac, 7291 (void *)&cmd_tunnel_filter_inner_mac, 7292 (void *)&cmd_tunnel_filter_ip_value, 7293 (void *)&cmd_tunnel_filter_innner_vlan, 7294 (void *)&cmd_tunnel_filter_tunnel_type, 7295 (void *)&cmd_tunnel_filter_filter_type, 7296 (void *)&cmd_tunnel_filter_tenant_id, 7297 (void *)&cmd_tunnel_filter_queue_num, 7298 NULL, 7299 }, 7300 }; 7301 7302 /* *** CONFIGURE TUNNEL UDP PORT *** */ 7303 struct cmd_tunnel_udp_config { 7304 cmdline_fixed_string_t cmd; 7305 cmdline_fixed_string_t what; 7306 uint16_t udp_port; 7307 uint8_t port_id; 7308 }; 7309 7310 static void 7311 cmd_tunnel_udp_config_parsed(void *parsed_result, 7312 __attribute__((unused)) struct cmdline *cl, 7313 __attribute__((unused)) void *data) 7314 { 7315 struct cmd_tunnel_udp_config *res = parsed_result; 7316 struct rte_eth_udp_tunnel tunnel_udp; 7317 int ret; 7318 7319 tunnel_udp.udp_port = res->udp_port; 7320 7321 if (!strcmp(res->cmd, "rx_vxlan_port")) 7322 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 7323 7324 if (!strcmp(res->what, "add")) 7325 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 7326 &tunnel_udp); 7327 else 7328 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 7329 &tunnel_udp); 7330 7331 if (ret < 0) 7332 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 7333 } 7334 7335 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 7336 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7337 cmd, "rx_vxlan_port"); 7338 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 7339 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7340 what, "add#rm"); 7341 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 7342 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7343 udp_port, UINT16); 7344 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 7345 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7346 port_id, UINT8); 7347 7348 cmdline_parse_inst_t cmd_tunnel_udp_config = { 7349 .f = cmd_tunnel_udp_config_parsed, 7350 .data = (void *)0, 7351 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 7352 "Add/Remove a tunneling UDP port filter", 7353 .tokens = { 7354 (void *)&cmd_tunnel_udp_config_cmd, 7355 (void *)&cmd_tunnel_udp_config_what, 7356 (void *)&cmd_tunnel_udp_config_udp_port, 7357 (void *)&cmd_tunnel_udp_config_port_id, 7358 NULL, 7359 }, 7360 }; 7361 7362 /* *** GLOBAL CONFIG *** */ 7363 struct cmd_global_config_result { 7364 cmdline_fixed_string_t cmd; 7365 uint8_t port_id; 7366 cmdline_fixed_string_t cfg_type; 7367 uint8_t len; 7368 }; 7369 7370 static void 7371 cmd_global_config_parsed(void *parsed_result, 7372 __attribute__((unused)) struct cmdline *cl, 7373 __attribute__((unused)) void *data) 7374 { 7375 struct cmd_global_config_result *res = parsed_result; 7376 struct rte_eth_global_cfg conf; 7377 int ret; 7378 7379 memset(&conf, 0, sizeof(conf)); 7380 conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN; 7381 conf.cfg.gre_key_len = res->len; 7382 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE, 7383 RTE_ETH_FILTER_SET, &conf); 7384 if (ret != 0) 7385 printf("Global config error\n"); 7386 } 7387 7388 cmdline_parse_token_string_t cmd_global_config_cmd = 7389 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, 7390 "global_config"); 7391 cmdline_parse_token_num_t cmd_global_config_port_id = 7392 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8); 7393 cmdline_parse_token_string_t cmd_global_config_type = 7394 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, 7395 cfg_type, "gre-key-len"); 7396 cmdline_parse_token_num_t cmd_global_config_gre_key_len = 7397 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, 7398 len, UINT8); 7399 7400 cmdline_parse_inst_t cmd_global_config = { 7401 .f = cmd_global_config_parsed, 7402 .data = (void *)NULL, 7403 .help_str = "global_config <port_id> gre-key-len <key_len>", 7404 .tokens = { 7405 (void *)&cmd_global_config_cmd, 7406 (void *)&cmd_global_config_port_id, 7407 (void *)&cmd_global_config_type, 7408 (void *)&cmd_global_config_gre_key_len, 7409 NULL, 7410 }, 7411 }; 7412 7413 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 7414 struct cmd_set_mirror_mask_result { 7415 cmdline_fixed_string_t set; 7416 cmdline_fixed_string_t port; 7417 uint8_t port_id; 7418 cmdline_fixed_string_t mirror; 7419 uint8_t rule_id; 7420 cmdline_fixed_string_t what; 7421 cmdline_fixed_string_t value; 7422 cmdline_fixed_string_t dstpool; 7423 uint8_t dstpool_id; 7424 cmdline_fixed_string_t on; 7425 }; 7426 7427 cmdline_parse_token_string_t cmd_mirror_mask_set = 7428 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7429 set, "set"); 7430 cmdline_parse_token_string_t cmd_mirror_mask_port = 7431 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7432 port, "port"); 7433 cmdline_parse_token_num_t cmd_mirror_mask_portid = 7434 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7435 port_id, UINT8); 7436 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 7437 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7438 mirror, "mirror-rule"); 7439 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 7440 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7441 rule_id, UINT8); 7442 cmdline_parse_token_string_t cmd_mirror_mask_what = 7443 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7444 what, "pool-mirror-up#pool-mirror-down" 7445 "#vlan-mirror"); 7446 cmdline_parse_token_string_t cmd_mirror_mask_value = 7447 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7448 value, NULL); 7449 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 7450 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7451 dstpool, "dst-pool"); 7452 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 7453 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 7454 dstpool_id, UINT8); 7455 cmdline_parse_token_string_t cmd_mirror_mask_on = 7456 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 7457 on, "on#off"); 7458 7459 static void 7460 cmd_set_mirror_mask_parsed(void *parsed_result, 7461 __attribute__((unused)) struct cmdline *cl, 7462 __attribute__((unused)) void *data) 7463 { 7464 int ret,nb_item,i; 7465 struct cmd_set_mirror_mask_result *res = parsed_result; 7466 struct rte_eth_mirror_conf mr_conf; 7467 7468 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7469 7470 unsigned int vlan_list[ETH_MIRROR_MAX_VLANS]; 7471 7472 mr_conf.dst_pool = res->dstpool_id; 7473 7474 if (!strcmp(res->what, "pool-mirror-up")) { 7475 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7476 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP; 7477 } else if (!strcmp(res->what, "pool-mirror-down")) { 7478 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 7479 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN; 7480 } else if (!strcmp(res->what, "vlan-mirror")) { 7481 mr_conf.rule_type = ETH_MIRROR_VLAN; 7482 nb_item = parse_item_list(res->value, "vlan", 7483 ETH_MIRROR_MAX_VLANS, vlan_list, 1); 7484 if (nb_item <= 0) 7485 return; 7486 7487 for (i = 0; i < nb_item; i++) { 7488 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 7489 printf("Invalid vlan_id: must be < 4096\n"); 7490 return; 7491 } 7492 7493 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 7494 mr_conf.vlan.vlan_mask |= 1ULL << i; 7495 } 7496 } 7497 7498 if (!strcmp(res->on, "on")) 7499 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7500 res->rule_id, 1); 7501 else 7502 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7503 res->rule_id, 0); 7504 if (ret < 0) 7505 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7506 } 7507 7508 cmdline_parse_inst_t cmd_set_mirror_mask = { 7509 .f = cmd_set_mirror_mask_parsed, 7510 .data = NULL, 7511 .help_str = "set port <port_id> mirror-rule <rule_id> " 7512 "pool-mirror-up|pool-mirror-down|vlan-mirror " 7513 "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off", 7514 .tokens = { 7515 (void *)&cmd_mirror_mask_set, 7516 (void *)&cmd_mirror_mask_port, 7517 (void *)&cmd_mirror_mask_portid, 7518 (void *)&cmd_mirror_mask_mirror, 7519 (void *)&cmd_mirror_mask_ruleid, 7520 (void *)&cmd_mirror_mask_what, 7521 (void *)&cmd_mirror_mask_value, 7522 (void *)&cmd_mirror_mask_dstpool, 7523 (void *)&cmd_mirror_mask_poolid, 7524 (void *)&cmd_mirror_mask_on, 7525 NULL, 7526 }, 7527 }; 7528 7529 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */ 7530 struct cmd_set_mirror_link_result { 7531 cmdline_fixed_string_t set; 7532 cmdline_fixed_string_t port; 7533 uint8_t port_id; 7534 cmdline_fixed_string_t mirror; 7535 uint8_t rule_id; 7536 cmdline_fixed_string_t what; 7537 cmdline_fixed_string_t dstpool; 7538 uint8_t dstpool_id; 7539 cmdline_fixed_string_t on; 7540 }; 7541 7542 cmdline_parse_token_string_t cmd_mirror_link_set = 7543 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7544 set, "set"); 7545 cmdline_parse_token_string_t cmd_mirror_link_port = 7546 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7547 port, "port"); 7548 cmdline_parse_token_num_t cmd_mirror_link_portid = 7549 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7550 port_id, UINT8); 7551 cmdline_parse_token_string_t cmd_mirror_link_mirror = 7552 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7553 mirror, "mirror-rule"); 7554 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 7555 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7556 rule_id, UINT8); 7557 cmdline_parse_token_string_t cmd_mirror_link_what = 7558 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7559 what, "uplink-mirror#downlink-mirror"); 7560 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 7561 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7562 dstpool, "dst-pool"); 7563 cmdline_parse_token_num_t cmd_mirror_link_poolid = 7564 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 7565 dstpool_id, UINT8); 7566 cmdline_parse_token_string_t cmd_mirror_link_on = 7567 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 7568 on, "on#off"); 7569 7570 static void 7571 cmd_set_mirror_link_parsed(void *parsed_result, 7572 __attribute__((unused)) struct cmdline *cl, 7573 __attribute__((unused)) void *data) 7574 { 7575 int ret; 7576 struct cmd_set_mirror_link_result *res = parsed_result; 7577 struct rte_eth_mirror_conf mr_conf; 7578 7579 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 7580 if (!strcmp(res->what, "uplink-mirror")) 7581 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT; 7582 else 7583 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT; 7584 7585 mr_conf.dst_pool = res->dstpool_id; 7586 7587 if (!strcmp(res->on, "on")) 7588 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7589 res->rule_id, 1); 7590 else 7591 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 7592 res->rule_id, 0); 7593 7594 /* check the return value and print it if is < 0 */ 7595 if (ret < 0) 7596 printf("mirror rule add error: (%s)\n", strerror(-ret)); 7597 7598 } 7599 7600 cmdline_parse_inst_t cmd_set_mirror_link = { 7601 .f = cmd_set_mirror_link_parsed, 7602 .data = NULL, 7603 .help_str = "set port <port_id> mirror-rule <rule_id> " 7604 "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off", 7605 .tokens = { 7606 (void *)&cmd_mirror_link_set, 7607 (void *)&cmd_mirror_link_port, 7608 (void *)&cmd_mirror_link_portid, 7609 (void *)&cmd_mirror_link_mirror, 7610 (void *)&cmd_mirror_link_ruleid, 7611 (void *)&cmd_mirror_link_what, 7612 (void *)&cmd_mirror_link_dstpool, 7613 (void *)&cmd_mirror_link_poolid, 7614 (void *)&cmd_mirror_link_on, 7615 NULL, 7616 }, 7617 }; 7618 7619 /* *** RESET VM MIRROR RULE *** */ 7620 struct cmd_rm_mirror_rule_result { 7621 cmdline_fixed_string_t reset; 7622 cmdline_fixed_string_t port; 7623 uint8_t port_id; 7624 cmdline_fixed_string_t mirror; 7625 uint8_t rule_id; 7626 }; 7627 7628 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 7629 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7630 reset, "reset"); 7631 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 7632 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7633 port, "port"); 7634 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 7635 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7636 port_id, UINT8); 7637 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 7638 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 7639 mirror, "mirror-rule"); 7640 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 7641 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 7642 rule_id, UINT8); 7643 7644 static void 7645 cmd_reset_mirror_rule_parsed(void *parsed_result, 7646 __attribute__((unused)) struct cmdline *cl, 7647 __attribute__((unused)) void *data) 7648 { 7649 int ret; 7650 struct cmd_set_mirror_link_result *res = parsed_result; 7651 /* check rule_id */ 7652 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 7653 if(ret < 0) 7654 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 7655 } 7656 7657 cmdline_parse_inst_t cmd_reset_mirror_rule = { 7658 .f = cmd_reset_mirror_rule_parsed, 7659 .data = NULL, 7660 .help_str = "reset port <port_id> mirror-rule <rule_id>", 7661 .tokens = { 7662 (void *)&cmd_rm_mirror_rule_reset, 7663 (void *)&cmd_rm_mirror_rule_port, 7664 (void *)&cmd_rm_mirror_rule_portid, 7665 (void *)&cmd_rm_mirror_rule_mirror, 7666 (void *)&cmd_rm_mirror_rule_ruleid, 7667 NULL, 7668 }, 7669 }; 7670 7671 /* ******************************************************************************** */ 7672 7673 struct cmd_dump_result { 7674 cmdline_fixed_string_t dump; 7675 }; 7676 7677 static void 7678 dump_struct_sizes(void) 7679 { 7680 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 7681 DUMP_SIZE(struct rte_mbuf); 7682 DUMP_SIZE(struct rte_mempool); 7683 DUMP_SIZE(struct rte_ring); 7684 #undef DUMP_SIZE 7685 } 7686 7687 static void cmd_dump_parsed(void *parsed_result, 7688 __attribute__((unused)) struct cmdline *cl, 7689 __attribute__((unused)) void *data) 7690 { 7691 struct cmd_dump_result *res = parsed_result; 7692 7693 if (!strcmp(res->dump, "dump_physmem")) 7694 rte_dump_physmem_layout(stdout); 7695 else if (!strcmp(res->dump, "dump_memzone")) 7696 rte_memzone_dump(stdout); 7697 else if (!strcmp(res->dump, "dump_struct_sizes")) 7698 dump_struct_sizes(); 7699 else if (!strcmp(res->dump, "dump_ring")) 7700 rte_ring_list_dump(stdout); 7701 else if (!strcmp(res->dump, "dump_mempool")) 7702 rte_mempool_list_dump(stdout); 7703 else if (!strcmp(res->dump, "dump_devargs")) 7704 rte_eal_devargs_dump(stdout); 7705 } 7706 7707 cmdline_parse_token_string_t cmd_dump_dump = 7708 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 7709 "dump_physmem#" 7710 "dump_memzone#" 7711 "dump_struct_sizes#" 7712 "dump_ring#" 7713 "dump_mempool#" 7714 "dump_devargs"); 7715 7716 cmdline_parse_inst_t cmd_dump = { 7717 .f = cmd_dump_parsed, /* function to call */ 7718 .data = NULL, /* 2nd arg of func */ 7719 .help_str = "Dump status", 7720 .tokens = { /* token list, NULL terminated */ 7721 (void *)&cmd_dump_dump, 7722 NULL, 7723 }, 7724 }; 7725 7726 /* ******************************************************************************** */ 7727 7728 struct cmd_dump_one_result { 7729 cmdline_fixed_string_t dump; 7730 cmdline_fixed_string_t name; 7731 }; 7732 7733 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 7734 __attribute__((unused)) void *data) 7735 { 7736 struct cmd_dump_one_result *res = parsed_result; 7737 7738 if (!strcmp(res->dump, "dump_ring")) { 7739 struct rte_ring *r; 7740 r = rte_ring_lookup(res->name); 7741 if (r == NULL) { 7742 cmdline_printf(cl, "Cannot find ring\n"); 7743 return; 7744 } 7745 rte_ring_dump(stdout, r); 7746 } else if (!strcmp(res->dump, "dump_mempool")) { 7747 struct rte_mempool *mp; 7748 mp = rte_mempool_lookup(res->name); 7749 if (mp == NULL) { 7750 cmdline_printf(cl, "Cannot find mempool\n"); 7751 return; 7752 } 7753 rte_mempool_dump(stdout, mp); 7754 } 7755 } 7756 7757 cmdline_parse_token_string_t cmd_dump_one_dump = 7758 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 7759 "dump_ring#dump_mempool"); 7760 7761 cmdline_parse_token_string_t cmd_dump_one_name = 7762 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 7763 7764 cmdline_parse_inst_t cmd_dump_one = { 7765 .f = cmd_dump_one_parsed, /* function to call */ 7766 .data = NULL, /* 2nd arg of func */ 7767 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 7768 .tokens = { /* token list, NULL terminated */ 7769 (void *)&cmd_dump_one_dump, 7770 (void *)&cmd_dump_one_name, 7771 NULL, 7772 }, 7773 }; 7774 7775 /* *** Add/Del syn filter *** */ 7776 struct cmd_syn_filter_result { 7777 cmdline_fixed_string_t filter; 7778 uint8_t port_id; 7779 cmdline_fixed_string_t ops; 7780 cmdline_fixed_string_t priority; 7781 cmdline_fixed_string_t high; 7782 cmdline_fixed_string_t queue; 7783 uint16_t queue_id; 7784 }; 7785 7786 static void 7787 cmd_syn_filter_parsed(void *parsed_result, 7788 __attribute__((unused)) struct cmdline *cl, 7789 __attribute__((unused)) void *data) 7790 { 7791 struct cmd_syn_filter_result *res = parsed_result; 7792 struct rte_eth_syn_filter syn_filter; 7793 int ret = 0; 7794 7795 ret = rte_eth_dev_filter_supported(res->port_id, 7796 RTE_ETH_FILTER_SYN); 7797 if (ret < 0) { 7798 printf("syn filter is not supported on port %u.\n", 7799 res->port_id); 7800 return; 7801 } 7802 7803 memset(&syn_filter, 0, sizeof(syn_filter)); 7804 7805 if (!strcmp(res->ops, "add")) { 7806 if (!strcmp(res->high, "high")) 7807 syn_filter.hig_pri = 1; 7808 else 7809 syn_filter.hig_pri = 0; 7810 7811 syn_filter.queue = res->queue_id; 7812 ret = rte_eth_dev_filter_ctrl(res->port_id, 7813 RTE_ETH_FILTER_SYN, 7814 RTE_ETH_FILTER_ADD, 7815 &syn_filter); 7816 } else 7817 ret = rte_eth_dev_filter_ctrl(res->port_id, 7818 RTE_ETH_FILTER_SYN, 7819 RTE_ETH_FILTER_DELETE, 7820 &syn_filter); 7821 7822 if (ret < 0) 7823 printf("syn filter programming error: (%s)\n", 7824 strerror(-ret)); 7825 } 7826 7827 cmdline_parse_token_string_t cmd_syn_filter_filter = 7828 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7829 filter, "syn_filter"); 7830 cmdline_parse_token_num_t cmd_syn_filter_port_id = 7831 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 7832 port_id, UINT8); 7833 cmdline_parse_token_string_t cmd_syn_filter_ops = 7834 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7835 ops, "add#del"); 7836 cmdline_parse_token_string_t cmd_syn_filter_priority = 7837 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7838 priority, "priority"); 7839 cmdline_parse_token_string_t cmd_syn_filter_high = 7840 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7841 high, "high#low"); 7842 cmdline_parse_token_string_t cmd_syn_filter_queue = 7843 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 7844 queue, "queue"); 7845 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 7846 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 7847 queue_id, UINT16); 7848 7849 cmdline_parse_inst_t cmd_syn_filter = { 7850 .f = cmd_syn_filter_parsed, 7851 .data = NULL, 7852 .help_str = "syn_filter <port_id> add|del priority high|low queue " 7853 "<queue_id>: Add/Delete syn filter", 7854 .tokens = { 7855 (void *)&cmd_syn_filter_filter, 7856 (void *)&cmd_syn_filter_port_id, 7857 (void *)&cmd_syn_filter_ops, 7858 (void *)&cmd_syn_filter_priority, 7859 (void *)&cmd_syn_filter_high, 7860 (void *)&cmd_syn_filter_queue, 7861 (void *)&cmd_syn_filter_queue_id, 7862 NULL, 7863 }, 7864 }; 7865 7866 /* *** ADD/REMOVE A 2tuple FILTER *** */ 7867 struct cmd_2tuple_filter_result { 7868 cmdline_fixed_string_t filter; 7869 uint8_t port_id; 7870 cmdline_fixed_string_t ops; 7871 cmdline_fixed_string_t dst_port; 7872 uint16_t dst_port_value; 7873 cmdline_fixed_string_t protocol; 7874 uint8_t protocol_value; 7875 cmdline_fixed_string_t mask; 7876 uint8_t mask_value; 7877 cmdline_fixed_string_t tcp_flags; 7878 uint8_t tcp_flags_value; 7879 cmdline_fixed_string_t priority; 7880 uint8_t priority_value; 7881 cmdline_fixed_string_t queue; 7882 uint16_t queue_id; 7883 }; 7884 7885 static void 7886 cmd_2tuple_filter_parsed(void *parsed_result, 7887 __attribute__((unused)) struct cmdline *cl, 7888 __attribute__((unused)) void *data) 7889 { 7890 struct rte_eth_ntuple_filter filter; 7891 struct cmd_2tuple_filter_result *res = parsed_result; 7892 int ret = 0; 7893 7894 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 7895 if (ret < 0) { 7896 printf("ntuple filter is not supported on port %u.\n", 7897 res->port_id); 7898 return; 7899 } 7900 7901 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 7902 7903 filter.flags = RTE_2TUPLE_FLAGS; 7904 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 7905 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 7906 filter.proto = res->protocol_value; 7907 filter.priority = res->priority_value; 7908 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 7909 printf("nonzero tcp_flags is only meaningful" 7910 " when protocol is TCP.\n"); 7911 return; 7912 } 7913 if (res->tcp_flags_value > TCP_FLAG_ALL) { 7914 printf("invalid TCP flags.\n"); 7915 return; 7916 } 7917 7918 if (res->tcp_flags_value != 0) { 7919 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 7920 filter.tcp_flags = res->tcp_flags_value; 7921 } 7922 7923 /* need convert to big endian. */ 7924 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 7925 filter.queue = res->queue_id; 7926 7927 if (!strcmp(res->ops, "add")) 7928 ret = rte_eth_dev_filter_ctrl(res->port_id, 7929 RTE_ETH_FILTER_NTUPLE, 7930 RTE_ETH_FILTER_ADD, 7931 &filter); 7932 else 7933 ret = rte_eth_dev_filter_ctrl(res->port_id, 7934 RTE_ETH_FILTER_NTUPLE, 7935 RTE_ETH_FILTER_DELETE, 7936 &filter); 7937 if (ret < 0) 7938 printf("2tuple filter programming error: (%s)\n", 7939 strerror(-ret)); 7940 7941 } 7942 7943 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 7944 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7945 filter, "2tuple_filter"); 7946 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 7947 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7948 port_id, UINT8); 7949 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 7950 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7951 ops, "add#del"); 7952 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 7953 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7954 dst_port, "dst_port"); 7955 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 7956 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7957 dst_port_value, UINT16); 7958 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 7959 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7960 protocol, "protocol"); 7961 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 7962 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7963 protocol_value, UINT8); 7964 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 7965 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7966 mask, "mask"); 7967 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 7968 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7969 mask_value, INT8); 7970 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 7971 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7972 tcp_flags, "tcp_flags"); 7973 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 7974 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7975 tcp_flags_value, UINT8); 7976 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 7977 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7978 priority, "priority"); 7979 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 7980 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7981 priority_value, UINT8); 7982 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 7983 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 7984 queue, "queue"); 7985 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 7986 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 7987 queue_id, UINT16); 7988 7989 cmdline_parse_inst_t cmd_2tuple_filter = { 7990 .f = cmd_2tuple_filter_parsed, 7991 .data = NULL, 7992 .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol " 7993 "<value> mask <value> tcp_flags <value> priority <value> queue " 7994 "<queue_id>: Add a 2tuple filter", 7995 .tokens = { 7996 (void *)&cmd_2tuple_filter_filter, 7997 (void *)&cmd_2tuple_filter_port_id, 7998 (void *)&cmd_2tuple_filter_ops, 7999 (void *)&cmd_2tuple_filter_dst_port, 8000 (void *)&cmd_2tuple_filter_dst_port_value, 8001 (void *)&cmd_2tuple_filter_protocol, 8002 (void *)&cmd_2tuple_filter_protocol_value, 8003 (void *)&cmd_2tuple_filter_mask, 8004 (void *)&cmd_2tuple_filter_mask_value, 8005 (void *)&cmd_2tuple_filter_tcp_flags, 8006 (void *)&cmd_2tuple_filter_tcp_flags_value, 8007 (void *)&cmd_2tuple_filter_priority, 8008 (void *)&cmd_2tuple_filter_priority_value, 8009 (void *)&cmd_2tuple_filter_queue, 8010 (void *)&cmd_2tuple_filter_queue_id, 8011 NULL, 8012 }, 8013 }; 8014 8015 /* *** ADD/REMOVE A 5tuple FILTER *** */ 8016 struct cmd_5tuple_filter_result { 8017 cmdline_fixed_string_t filter; 8018 uint8_t port_id; 8019 cmdline_fixed_string_t ops; 8020 cmdline_fixed_string_t dst_ip; 8021 cmdline_ipaddr_t dst_ip_value; 8022 cmdline_fixed_string_t src_ip; 8023 cmdline_ipaddr_t src_ip_value; 8024 cmdline_fixed_string_t dst_port; 8025 uint16_t dst_port_value; 8026 cmdline_fixed_string_t src_port; 8027 uint16_t src_port_value; 8028 cmdline_fixed_string_t protocol; 8029 uint8_t protocol_value; 8030 cmdline_fixed_string_t mask; 8031 uint8_t mask_value; 8032 cmdline_fixed_string_t tcp_flags; 8033 uint8_t tcp_flags_value; 8034 cmdline_fixed_string_t priority; 8035 uint8_t priority_value; 8036 cmdline_fixed_string_t queue; 8037 uint16_t queue_id; 8038 }; 8039 8040 static void 8041 cmd_5tuple_filter_parsed(void *parsed_result, 8042 __attribute__((unused)) struct cmdline *cl, 8043 __attribute__((unused)) void *data) 8044 { 8045 struct rte_eth_ntuple_filter filter; 8046 struct cmd_5tuple_filter_result *res = parsed_result; 8047 int ret = 0; 8048 8049 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 8050 if (ret < 0) { 8051 printf("ntuple filter is not supported on port %u.\n", 8052 res->port_id); 8053 return; 8054 } 8055 8056 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 8057 8058 filter.flags = RTE_5TUPLE_FLAGS; 8059 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 8060 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 8061 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 8062 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 8063 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 8064 filter.proto = res->protocol_value; 8065 filter.priority = res->priority_value; 8066 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 8067 printf("nonzero tcp_flags is only meaningful" 8068 " when protocol is TCP.\n"); 8069 return; 8070 } 8071 if (res->tcp_flags_value > TCP_FLAG_ALL) { 8072 printf("invalid TCP flags.\n"); 8073 return; 8074 } 8075 8076 if (res->tcp_flags_value != 0) { 8077 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 8078 filter.tcp_flags = res->tcp_flags_value; 8079 } 8080 8081 if (res->dst_ip_value.family == AF_INET) 8082 /* no need to convert, already big endian. */ 8083 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 8084 else { 8085 if (filter.dst_ip_mask == 0) { 8086 printf("can not support ipv6 involved compare.\n"); 8087 return; 8088 } 8089 filter.dst_ip = 0; 8090 } 8091 8092 if (res->src_ip_value.family == AF_INET) 8093 /* no need to convert, already big endian. */ 8094 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 8095 else { 8096 if (filter.src_ip_mask == 0) { 8097 printf("can not support ipv6 involved compare.\n"); 8098 return; 8099 } 8100 filter.src_ip = 0; 8101 } 8102 /* need convert to big endian. */ 8103 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 8104 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 8105 filter.queue = res->queue_id; 8106 8107 if (!strcmp(res->ops, "add")) 8108 ret = rte_eth_dev_filter_ctrl(res->port_id, 8109 RTE_ETH_FILTER_NTUPLE, 8110 RTE_ETH_FILTER_ADD, 8111 &filter); 8112 else 8113 ret = rte_eth_dev_filter_ctrl(res->port_id, 8114 RTE_ETH_FILTER_NTUPLE, 8115 RTE_ETH_FILTER_DELETE, 8116 &filter); 8117 if (ret < 0) 8118 printf("5tuple filter programming error: (%s)\n", 8119 strerror(-ret)); 8120 } 8121 8122 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 8123 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8124 filter, "5tuple_filter"); 8125 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 8126 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8127 port_id, UINT8); 8128 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 8129 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8130 ops, "add#del"); 8131 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 8132 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8133 dst_ip, "dst_ip"); 8134 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 8135 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8136 dst_ip_value); 8137 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 8138 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8139 src_ip, "src_ip"); 8140 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 8141 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 8142 src_ip_value); 8143 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 8144 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8145 dst_port, "dst_port"); 8146 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 8147 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8148 dst_port_value, UINT16); 8149 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 8150 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8151 src_port, "src_port"); 8152 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 8153 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8154 src_port_value, UINT16); 8155 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 8156 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8157 protocol, "protocol"); 8158 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 8159 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8160 protocol_value, UINT8); 8161 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 8162 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8163 mask, "mask"); 8164 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 8165 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8166 mask_value, INT8); 8167 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 8168 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8169 tcp_flags, "tcp_flags"); 8170 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 8171 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8172 tcp_flags_value, UINT8); 8173 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 8174 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8175 priority, "priority"); 8176 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 8177 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8178 priority_value, UINT8); 8179 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 8180 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 8181 queue, "queue"); 8182 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 8183 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 8184 queue_id, UINT16); 8185 8186 cmdline_parse_inst_t cmd_5tuple_filter = { 8187 .f = cmd_5tuple_filter_parsed, 8188 .data = NULL, 8189 .help_str = "5tuple_filter <port_id> add|del dst_ip <value> " 8190 "src_ip <value> dst_port <value> src_port <value> " 8191 "protocol <value> mask <value> tcp_flags <value> " 8192 "priority <value> queue <queue_id>: Add/Del a 5tuple filter", 8193 .tokens = { 8194 (void *)&cmd_5tuple_filter_filter, 8195 (void *)&cmd_5tuple_filter_port_id, 8196 (void *)&cmd_5tuple_filter_ops, 8197 (void *)&cmd_5tuple_filter_dst_ip, 8198 (void *)&cmd_5tuple_filter_dst_ip_value, 8199 (void *)&cmd_5tuple_filter_src_ip, 8200 (void *)&cmd_5tuple_filter_src_ip_value, 8201 (void *)&cmd_5tuple_filter_dst_port, 8202 (void *)&cmd_5tuple_filter_dst_port_value, 8203 (void *)&cmd_5tuple_filter_src_port, 8204 (void *)&cmd_5tuple_filter_src_port_value, 8205 (void *)&cmd_5tuple_filter_protocol, 8206 (void *)&cmd_5tuple_filter_protocol_value, 8207 (void *)&cmd_5tuple_filter_mask, 8208 (void *)&cmd_5tuple_filter_mask_value, 8209 (void *)&cmd_5tuple_filter_tcp_flags, 8210 (void *)&cmd_5tuple_filter_tcp_flags_value, 8211 (void *)&cmd_5tuple_filter_priority, 8212 (void *)&cmd_5tuple_filter_priority_value, 8213 (void *)&cmd_5tuple_filter_queue, 8214 (void *)&cmd_5tuple_filter_queue_id, 8215 NULL, 8216 }, 8217 }; 8218 8219 /* *** ADD/REMOVE A flex FILTER *** */ 8220 struct cmd_flex_filter_result { 8221 cmdline_fixed_string_t filter; 8222 cmdline_fixed_string_t ops; 8223 uint8_t port_id; 8224 cmdline_fixed_string_t len; 8225 uint8_t len_value; 8226 cmdline_fixed_string_t bytes; 8227 cmdline_fixed_string_t bytes_value; 8228 cmdline_fixed_string_t mask; 8229 cmdline_fixed_string_t mask_value; 8230 cmdline_fixed_string_t priority; 8231 uint8_t priority_value; 8232 cmdline_fixed_string_t queue; 8233 uint16_t queue_id; 8234 }; 8235 8236 static int xdigit2val(unsigned char c) 8237 { 8238 int val; 8239 if (isdigit(c)) 8240 val = c - '0'; 8241 else if (isupper(c)) 8242 val = c - 'A' + 10; 8243 else 8244 val = c - 'a' + 10; 8245 return val; 8246 } 8247 8248 static void 8249 cmd_flex_filter_parsed(void *parsed_result, 8250 __attribute__((unused)) struct cmdline *cl, 8251 __attribute__((unused)) void *data) 8252 { 8253 int ret = 0; 8254 struct rte_eth_flex_filter filter; 8255 struct cmd_flex_filter_result *res = parsed_result; 8256 char *bytes_ptr, *mask_ptr; 8257 uint16_t len, i, j = 0; 8258 char c; 8259 int val; 8260 uint8_t byte = 0; 8261 8262 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 8263 printf("the len exceed the max length 128\n"); 8264 return; 8265 } 8266 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 8267 filter.len = res->len_value; 8268 filter.priority = res->priority_value; 8269 filter.queue = res->queue_id; 8270 bytes_ptr = res->bytes_value; 8271 mask_ptr = res->mask_value; 8272 8273 /* translate bytes string to array. */ 8274 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 8275 (bytes_ptr[1] == 'X'))) 8276 bytes_ptr += 2; 8277 len = strnlen(bytes_ptr, res->len_value * 2); 8278 if (len == 0 || (len % 8 != 0)) { 8279 printf("please check len and bytes input\n"); 8280 return; 8281 } 8282 for (i = 0; i < len; i++) { 8283 c = bytes_ptr[i]; 8284 if (isxdigit(c) == 0) { 8285 /* invalid characters. */ 8286 printf("invalid input\n"); 8287 return; 8288 } 8289 val = xdigit2val(c); 8290 if (i % 2) { 8291 byte |= val; 8292 filter.bytes[j] = byte; 8293 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 8294 j++; 8295 byte = 0; 8296 } else 8297 byte |= val << 4; 8298 } 8299 printf("\n"); 8300 /* translate mask string to uint8_t array. */ 8301 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 8302 (mask_ptr[1] == 'X'))) 8303 mask_ptr += 2; 8304 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 8305 if (len == 0) { 8306 printf("invalid input\n"); 8307 return; 8308 } 8309 j = 0; 8310 byte = 0; 8311 for (i = 0; i < len; i++) { 8312 c = mask_ptr[i]; 8313 if (isxdigit(c) == 0) { 8314 /* invalid characters. */ 8315 printf("invalid input\n"); 8316 return; 8317 } 8318 val = xdigit2val(c); 8319 if (i % 2) { 8320 byte |= val; 8321 filter.mask[j] = byte; 8322 printf("mask[%d]:%02x ", j, filter.mask[j]); 8323 j++; 8324 byte = 0; 8325 } else 8326 byte |= val << 4; 8327 } 8328 printf("\n"); 8329 8330 if (!strcmp(res->ops, "add")) 8331 ret = rte_eth_dev_filter_ctrl(res->port_id, 8332 RTE_ETH_FILTER_FLEXIBLE, 8333 RTE_ETH_FILTER_ADD, 8334 &filter); 8335 else 8336 ret = rte_eth_dev_filter_ctrl(res->port_id, 8337 RTE_ETH_FILTER_FLEXIBLE, 8338 RTE_ETH_FILTER_DELETE, 8339 &filter); 8340 8341 if (ret < 0) 8342 printf("flex filter setting error: (%s)\n", strerror(-ret)); 8343 } 8344 8345 cmdline_parse_token_string_t cmd_flex_filter_filter = 8346 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8347 filter, "flex_filter"); 8348 cmdline_parse_token_num_t cmd_flex_filter_port_id = 8349 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8350 port_id, UINT8); 8351 cmdline_parse_token_string_t cmd_flex_filter_ops = 8352 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8353 ops, "add#del"); 8354 cmdline_parse_token_string_t cmd_flex_filter_len = 8355 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8356 len, "len"); 8357 cmdline_parse_token_num_t cmd_flex_filter_len_value = 8358 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8359 len_value, UINT8); 8360 cmdline_parse_token_string_t cmd_flex_filter_bytes = 8361 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8362 bytes, "bytes"); 8363 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 8364 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8365 bytes_value, NULL); 8366 cmdline_parse_token_string_t cmd_flex_filter_mask = 8367 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8368 mask, "mask"); 8369 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 8370 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8371 mask_value, NULL); 8372 cmdline_parse_token_string_t cmd_flex_filter_priority = 8373 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8374 priority, "priority"); 8375 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 8376 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8377 priority_value, UINT8); 8378 cmdline_parse_token_string_t cmd_flex_filter_queue = 8379 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 8380 queue, "queue"); 8381 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 8382 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 8383 queue_id, UINT16); 8384 cmdline_parse_inst_t cmd_flex_filter = { 8385 .f = cmd_flex_filter_parsed, 8386 .data = NULL, 8387 .help_str = "flex_filter <port_id> add|del len <value> bytes " 8388 "<value> mask <value> priority <value> queue <queue_id>: " 8389 "Add/Del a flex filter", 8390 .tokens = { 8391 (void *)&cmd_flex_filter_filter, 8392 (void *)&cmd_flex_filter_port_id, 8393 (void *)&cmd_flex_filter_ops, 8394 (void *)&cmd_flex_filter_len, 8395 (void *)&cmd_flex_filter_len_value, 8396 (void *)&cmd_flex_filter_bytes, 8397 (void *)&cmd_flex_filter_bytes_value, 8398 (void *)&cmd_flex_filter_mask, 8399 (void *)&cmd_flex_filter_mask_value, 8400 (void *)&cmd_flex_filter_priority, 8401 (void *)&cmd_flex_filter_priority_value, 8402 (void *)&cmd_flex_filter_queue, 8403 (void *)&cmd_flex_filter_queue_id, 8404 NULL, 8405 }, 8406 }; 8407 8408 /* *** Filters Control *** */ 8409 8410 /* *** deal with ethertype filter *** */ 8411 struct cmd_ethertype_filter_result { 8412 cmdline_fixed_string_t filter; 8413 uint8_t port_id; 8414 cmdline_fixed_string_t ops; 8415 cmdline_fixed_string_t mac; 8416 struct ether_addr mac_addr; 8417 cmdline_fixed_string_t ethertype; 8418 uint16_t ethertype_value; 8419 cmdline_fixed_string_t drop; 8420 cmdline_fixed_string_t queue; 8421 uint16_t queue_id; 8422 }; 8423 8424 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 8425 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8426 filter, "ethertype_filter"); 8427 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 8428 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8429 port_id, UINT8); 8430 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 8431 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8432 ops, "add#del"); 8433 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 8434 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8435 mac, "mac_addr#mac_ignr"); 8436 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 8437 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 8438 mac_addr); 8439 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 8440 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8441 ethertype, "ethertype"); 8442 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 8443 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8444 ethertype_value, UINT16); 8445 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 8446 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8447 drop, "drop#fwd"); 8448 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 8449 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 8450 queue, "queue"); 8451 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 8452 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 8453 queue_id, UINT16); 8454 8455 static void 8456 cmd_ethertype_filter_parsed(void *parsed_result, 8457 __attribute__((unused)) struct cmdline *cl, 8458 __attribute__((unused)) void *data) 8459 { 8460 struct cmd_ethertype_filter_result *res = parsed_result; 8461 struct rte_eth_ethertype_filter filter; 8462 int ret = 0; 8463 8464 ret = rte_eth_dev_filter_supported(res->port_id, 8465 RTE_ETH_FILTER_ETHERTYPE); 8466 if (ret < 0) { 8467 printf("ethertype filter is not supported on port %u.\n", 8468 res->port_id); 8469 return; 8470 } 8471 8472 memset(&filter, 0, sizeof(filter)); 8473 if (!strcmp(res->mac, "mac_addr")) { 8474 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 8475 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr, 8476 sizeof(struct ether_addr)); 8477 } 8478 if (!strcmp(res->drop, "drop")) 8479 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 8480 filter.ether_type = res->ethertype_value; 8481 filter.queue = res->queue_id; 8482 8483 if (!strcmp(res->ops, "add")) 8484 ret = rte_eth_dev_filter_ctrl(res->port_id, 8485 RTE_ETH_FILTER_ETHERTYPE, 8486 RTE_ETH_FILTER_ADD, 8487 &filter); 8488 else 8489 ret = rte_eth_dev_filter_ctrl(res->port_id, 8490 RTE_ETH_FILTER_ETHERTYPE, 8491 RTE_ETH_FILTER_DELETE, 8492 &filter); 8493 if (ret < 0) 8494 printf("ethertype filter programming error: (%s)\n", 8495 strerror(-ret)); 8496 } 8497 8498 cmdline_parse_inst_t cmd_ethertype_filter = { 8499 .f = cmd_ethertype_filter_parsed, 8500 .data = NULL, 8501 .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr " 8502 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: " 8503 "Add or delete an ethertype filter entry", 8504 .tokens = { 8505 (void *)&cmd_ethertype_filter_filter, 8506 (void *)&cmd_ethertype_filter_port_id, 8507 (void *)&cmd_ethertype_filter_ops, 8508 (void *)&cmd_ethertype_filter_mac, 8509 (void *)&cmd_ethertype_filter_mac_addr, 8510 (void *)&cmd_ethertype_filter_ethertype, 8511 (void *)&cmd_ethertype_filter_ethertype_value, 8512 (void *)&cmd_ethertype_filter_drop, 8513 (void *)&cmd_ethertype_filter_queue, 8514 (void *)&cmd_ethertype_filter_queue_id, 8515 NULL, 8516 }, 8517 }; 8518 8519 /* *** deal with flow director filter *** */ 8520 struct cmd_flow_director_result { 8521 cmdline_fixed_string_t flow_director_filter; 8522 uint8_t port_id; 8523 cmdline_fixed_string_t mode; 8524 cmdline_fixed_string_t mode_value; 8525 cmdline_fixed_string_t ops; 8526 cmdline_fixed_string_t flow; 8527 cmdline_fixed_string_t flow_type; 8528 cmdline_fixed_string_t ether; 8529 uint16_t ether_type; 8530 cmdline_fixed_string_t src; 8531 cmdline_ipaddr_t ip_src; 8532 uint16_t port_src; 8533 cmdline_fixed_string_t dst; 8534 cmdline_ipaddr_t ip_dst; 8535 uint16_t port_dst; 8536 cmdline_fixed_string_t verify_tag; 8537 uint32_t verify_tag_value; 8538 cmdline_ipaddr_t tos; 8539 uint8_t tos_value; 8540 cmdline_ipaddr_t proto; 8541 uint8_t proto_value; 8542 cmdline_ipaddr_t ttl; 8543 uint8_t ttl_value; 8544 cmdline_fixed_string_t vlan; 8545 uint16_t vlan_value; 8546 cmdline_fixed_string_t flexbytes; 8547 cmdline_fixed_string_t flexbytes_value; 8548 cmdline_fixed_string_t pf_vf; 8549 cmdline_fixed_string_t drop; 8550 cmdline_fixed_string_t queue; 8551 uint16_t queue_id; 8552 cmdline_fixed_string_t fd_id; 8553 uint32_t fd_id_value; 8554 cmdline_fixed_string_t mac; 8555 struct ether_addr mac_addr; 8556 cmdline_fixed_string_t tunnel; 8557 cmdline_fixed_string_t tunnel_type; 8558 cmdline_fixed_string_t tunnel_id; 8559 uint32_t tunnel_id_value; 8560 }; 8561 8562 static inline int 8563 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 8564 { 8565 char s[256]; 8566 const char *p, *p0 = q_arg; 8567 char *end; 8568 unsigned long int_fld; 8569 char *str_fld[max_num]; 8570 int i; 8571 unsigned size; 8572 int ret = -1; 8573 8574 p = strchr(p0, '('); 8575 if (p == NULL) 8576 return -1; 8577 ++p; 8578 p0 = strchr(p, ')'); 8579 if (p0 == NULL) 8580 return -1; 8581 8582 size = p0 - p; 8583 if (size >= sizeof(s)) 8584 return -1; 8585 8586 snprintf(s, sizeof(s), "%.*s", size, p); 8587 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 8588 if (ret < 0 || ret > max_num) 8589 return -1; 8590 for (i = 0; i < ret; i++) { 8591 errno = 0; 8592 int_fld = strtoul(str_fld[i], &end, 0); 8593 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 8594 return -1; 8595 flexbytes[i] = (uint8_t)int_fld; 8596 } 8597 return ret; 8598 } 8599 8600 static uint16_t 8601 str2flowtype(char *string) 8602 { 8603 uint8_t i = 0; 8604 static const struct { 8605 char str[32]; 8606 uint16_t type; 8607 } flowtype_str[] = { 8608 {"raw", RTE_ETH_FLOW_RAW}, 8609 {"ipv4", RTE_ETH_FLOW_IPV4}, 8610 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 8611 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 8612 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 8613 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 8614 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 8615 {"ipv6", RTE_ETH_FLOW_IPV6}, 8616 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 8617 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 8618 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 8619 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 8620 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 8621 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 8622 }; 8623 8624 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 8625 if (!strcmp(flowtype_str[i].str, string)) 8626 return flowtype_str[i].type; 8627 } 8628 return RTE_ETH_FLOW_UNKNOWN; 8629 } 8630 8631 static enum rte_eth_fdir_tunnel_type 8632 str2fdir_tunneltype(char *string) 8633 { 8634 uint8_t i = 0; 8635 8636 static const struct { 8637 char str[32]; 8638 enum rte_eth_fdir_tunnel_type type; 8639 } tunneltype_str[] = { 8640 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE}, 8641 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN}, 8642 }; 8643 8644 for (i = 0; i < RTE_DIM(tunneltype_str); i++) { 8645 if (!strcmp(tunneltype_str[i].str, string)) 8646 return tunneltype_str[i].type; 8647 } 8648 return RTE_FDIR_TUNNEL_TYPE_UNKNOWN; 8649 } 8650 8651 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 8652 do { \ 8653 if ((ip_addr).family == AF_INET) \ 8654 (ip) = (ip_addr).addr.ipv4.s_addr; \ 8655 else { \ 8656 printf("invalid parameter.\n"); \ 8657 return; \ 8658 } \ 8659 } while (0) 8660 8661 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 8662 do { \ 8663 if ((ip_addr).family == AF_INET6) \ 8664 (void)rte_memcpy(&(ip), \ 8665 &((ip_addr).addr.ipv6), \ 8666 sizeof(struct in6_addr)); \ 8667 else { \ 8668 printf("invalid parameter.\n"); \ 8669 return; \ 8670 } \ 8671 } while (0) 8672 8673 static void 8674 cmd_flow_director_filter_parsed(void *parsed_result, 8675 __attribute__((unused)) struct cmdline *cl, 8676 __attribute__((unused)) void *data) 8677 { 8678 struct cmd_flow_director_result *res = parsed_result; 8679 struct rte_eth_fdir_filter entry; 8680 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 8681 char *end; 8682 unsigned long vf_id; 8683 int ret = 0; 8684 8685 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 8686 if (ret < 0) { 8687 printf("flow director is not supported on port %u.\n", 8688 res->port_id); 8689 return; 8690 } 8691 memset(flexbytes, 0, sizeof(flexbytes)); 8692 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 8693 8694 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 8695 if (strcmp(res->mode_value, "MAC-VLAN")) { 8696 printf("Please set mode to MAC-VLAN.\n"); 8697 return; 8698 } 8699 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 8700 if (strcmp(res->mode_value, "Tunnel")) { 8701 printf("Please set mode to Tunnel.\n"); 8702 return; 8703 } 8704 } else { 8705 if (strcmp(res->mode_value, "IP")) { 8706 printf("Please set mode to IP.\n"); 8707 return; 8708 } 8709 entry.input.flow_type = str2flowtype(res->flow_type); 8710 } 8711 8712 ret = parse_flexbytes(res->flexbytes_value, 8713 flexbytes, 8714 RTE_ETH_FDIR_MAX_FLEXLEN); 8715 if (ret < 0) { 8716 printf("error: Cannot parse flexbytes input.\n"); 8717 return; 8718 } 8719 8720 switch (entry.input.flow_type) { 8721 case RTE_ETH_FLOW_FRAG_IPV4: 8722 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 8723 entry.input.flow.ip4_flow.proto = res->proto_value; 8724 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 8725 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 8726 IPV4_ADDR_TO_UINT(res->ip_dst, 8727 entry.input.flow.ip4_flow.dst_ip); 8728 IPV4_ADDR_TO_UINT(res->ip_src, 8729 entry.input.flow.ip4_flow.src_ip); 8730 entry.input.flow.ip4_flow.tos = res->tos_value; 8731 entry.input.flow.ip4_flow.ttl = res->ttl_value; 8732 /* need convert to big endian. */ 8733 entry.input.flow.udp4_flow.dst_port = 8734 rte_cpu_to_be_16(res->port_dst); 8735 entry.input.flow.udp4_flow.src_port = 8736 rte_cpu_to_be_16(res->port_src); 8737 break; 8738 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 8739 IPV4_ADDR_TO_UINT(res->ip_dst, 8740 entry.input.flow.sctp4_flow.ip.dst_ip); 8741 IPV4_ADDR_TO_UINT(res->ip_src, 8742 entry.input.flow.sctp4_flow.ip.src_ip); 8743 entry.input.flow.ip4_flow.tos = res->tos_value; 8744 entry.input.flow.ip4_flow.ttl = res->ttl_value; 8745 /* need convert to big endian. */ 8746 entry.input.flow.sctp4_flow.dst_port = 8747 rte_cpu_to_be_16(res->port_dst); 8748 entry.input.flow.sctp4_flow.src_port = 8749 rte_cpu_to_be_16(res->port_src); 8750 entry.input.flow.sctp4_flow.verify_tag = 8751 rte_cpu_to_be_32(res->verify_tag_value); 8752 break; 8753 case RTE_ETH_FLOW_FRAG_IPV6: 8754 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 8755 entry.input.flow.ipv6_flow.proto = res->proto_value; 8756 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 8757 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 8758 IPV6_ADDR_TO_ARRAY(res->ip_dst, 8759 entry.input.flow.ipv6_flow.dst_ip); 8760 IPV6_ADDR_TO_ARRAY(res->ip_src, 8761 entry.input.flow.ipv6_flow.src_ip); 8762 entry.input.flow.ipv6_flow.tc = res->tos_value; 8763 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 8764 /* need convert to big endian. */ 8765 entry.input.flow.udp6_flow.dst_port = 8766 rte_cpu_to_be_16(res->port_dst); 8767 entry.input.flow.udp6_flow.src_port = 8768 rte_cpu_to_be_16(res->port_src); 8769 break; 8770 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 8771 IPV6_ADDR_TO_ARRAY(res->ip_dst, 8772 entry.input.flow.sctp6_flow.ip.dst_ip); 8773 IPV6_ADDR_TO_ARRAY(res->ip_src, 8774 entry.input.flow.sctp6_flow.ip.src_ip); 8775 entry.input.flow.ipv6_flow.tc = res->tos_value; 8776 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 8777 /* need convert to big endian. */ 8778 entry.input.flow.sctp6_flow.dst_port = 8779 rte_cpu_to_be_16(res->port_dst); 8780 entry.input.flow.sctp6_flow.src_port = 8781 rte_cpu_to_be_16(res->port_src); 8782 entry.input.flow.sctp6_flow.verify_tag = 8783 rte_cpu_to_be_32(res->verify_tag_value); 8784 break; 8785 case RTE_ETH_FLOW_L2_PAYLOAD: 8786 entry.input.flow.l2_flow.ether_type = 8787 rte_cpu_to_be_16(res->ether_type); 8788 break; 8789 default: 8790 break; 8791 } 8792 8793 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 8794 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, 8795 &res->mac_addr, 8796 sizeof(struct ether_addr)); 8797 8798 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 8799 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, 8800 &res->mac_addr, 8801 sizeof(struct ether_addr)); 8802 entry.input.flow.tunnel_flow.tunnel_type = 8803 str2fdir_tunneltype(res->tunnel_type); 8804 entry.input.flow.tunnel_flow.tunnel_id = 8805 rte_cpu_to_be_32(res->tunnel_id_value); 8806 } 8807 8808 (void)rte_memcpy(entry.input.flow_ext.flexbytes, 8809 flexbytes, 8810 RTE_ETH_FDIR_MAX_FLEXLEN); 8811 8812 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 8813 8814 entry.action.flex_off = 0; /*use 0 by default */ 8815 if (!strcmp(res->drop, "drop")) 8816 entry.action.behavior = RTE_ETH_FDIR_REJECT; 8817 else 8818 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 8819 8820 if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN && 8821 fdir_conf.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 8822 if (!strcmp(res->pf_vf, "pf")) 8823 entry.input.flow_ext.is_vf = 0; 8824 else if (!strncmp(res->pf_vf, "vf", 2)) { 8825 struct rte_eth_dev_info dev_info; 8826 8827 memset(&dev_info, 0, sizeof(dev_info)); 8828 rte_eth_dev_info_get(res->port_id, &dev_info); 8829 errno = 0; 8830 vf_id = strtoul(res->pf_vf + 2, &end, 10); 8831 if (errno != 0 || *end != '\0' || 8832 vf_id >= dev_info.max_vfs) { 8833 printf("invalid parameter %s.\n", res->pf_vf); 8834 return; 8835 } 8836 entry.input.flow_ext.is_vf = 1; 8837 entry.input.flow_ext.dst_id = (uint16_t)vf_id; 8838 } else { 8839 printf("invalid parameter %s.\n", res->pf_vf); 8840 return; 8841 } 8842 } 8843 8844 /* set to report FD ID by default */ 8845 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 8846 entry.action.rx_queue = res->queue_id; 8847 entry.soft_id = res->fd_id_value; 8848 if (!strcmp(res->ops, "add")) 8849 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8850 RTE_ETH_FILTER_ADD, &entry); 8851 else if (!strcmp(res->ops, "del")) 8852 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8853 RTE_ETH_FILTER_DELETE, &entry); 8854 else 8855 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 8856 RTE_ETH_FILTER_UPDATE, &entry); 8857 if (ret < 0) 8858 printf("flow director programming error: (%s)\n", 8859 strerror(-ret)); 8860 } 8861 8862 cmdline_parse_token_string_t cmd_flow_director_filter = 8863 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8864 flow_director_filter, "flow_director_filter"); 8865 cmdline_parse_token_num_t cmd_flow_director_port_id = 8866 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8867 port_id, UINT8); 8868 cmdline_parse_token_string_t cmd_flow_director_ops = 8869 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8870 ops, "add#del#update"); 8871 cmdline_parse_token_string_t cmd_flow_director_flow = 8872 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8873 flow, "flow"); 8874 cmdline_parse_token_string_t cmd_flow_director_flow_type = 8875 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8876 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 8877 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload"); 8878 cmdline_parse_token_string_t cmd_flow_director_ether = 8879 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8880 ether, "ether"); 8881 cmdline_parse_token_num_t cmd_flow_director_ether_type = 8882 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8883 ether_type, UINT16); 8884 cmdline_parse_token_string_t cmd_flow_director_src = 8885 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8886 src, "src"); 8887 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 8888 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 8889 ip_src); 8890 cmdline_parse_token_num_t cmd_flow_director_port_src = 8891 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8892 port_src, UINT16); 8893 cmdline_parse_token_string_t cmd_flow_director_dst = 8894 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8895 dst, "dst"); 8896 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 8897 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 8898 ip_dst); 8899 cmdline_parse_token_num_t cmd_flow_director_port_dst = 8900 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8901 port_dst, UINT16); 8902 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 8903 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8904 verify_tag, "verify_tag"); 8905 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 8906 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8907 verify_tag_value, UINT32); 8908 cmdline_parse_token_string_t cmd_flow_director_tos = 8909 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8910 tos, "tos"); 8911 cmdline_parse_token_num_t cmd_flow_director_tos_value = 8912 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8913 tos_value, UINT8); 8914 cmdline_parse_token_string_t cmd_flow_director_proto = 8915 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8916 proto, "proto"); 8917 cmdline_parse_token_num_t cmd_flow_director_proto_value = 8918 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8919 proto_value, UINT8); 8920 cmdline_parse_token_string_t cmd_flow_director_ttl = 8921 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8922 ttl, "ttl"); 8923 cmdline_parse_token_num_t cmd_flow_director_ttl_value = 8924 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8925 ttl_value, UINT8); 8926 cmdline_parse_token_string_t cmd_flow_director_vlan = 8927 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8928 vlan, "vlan"); 8929 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 8930 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8931 vlan_value, UINT16); 8932 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 8933 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8934 flexbytes, "flexbytes"); 8935 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 8936 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8937 flexbytes_value, NULL); 8938 cmdline_parse_token_string_t cmd_flow_director_drop = 8939 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8940 drop, "drop#fwd"); 8941 cmdline_parse_token_string_t cmd_flow_director_pf_vf = 8942 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8943 pf_vf, NULL); 8944 cmdline_parse_token_string_t cmd_flow_director_queue = 8945 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8946 queue, "queue"); 8947 cmdline_parse_token_num_t cmd_flow_director_queue_id = 8948 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8949 queue_id, UINT16); 8950 cmdline_parse_token_string_t cmd_flow_director_fd_id = 8951 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8952 fd_id, "fd_id"); 8953 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 8954 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8955 fd_id_value, UINT32); 8956 8957 cmdline_parse_token_string_t cmd_flow_director_mode = 8958 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8959 mode, "mode"); 8960 cmdline_parse_token_string_t cmd_flow_director_mode_ip = 8961 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8962 mode_value, "IP"); 8963 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan = 8964 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8965 mode_value, "MAC-VLAN"); 8966 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel = 8967 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8968 mode_value, "Tunnel"); 8969 cmdline_parse_token_string_t cmd_flow_director_mac = 8970 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8971 mac, "mac"); 8972 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr = 8973 TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result, 8974 mac_addr); 8975 cmdline_parse_token_string_t cmd_flow_director_tunnel = 8976 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8977 tunnel, "tunnel"); 8978 cmdline_parse_token_string_t cmd_flow_director_tunnel_type = 8979 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8980 tunnel_type, "NVGRE#VxLAN"); 8981 cmdline_parse_token_string_t cmd_flow_director_tunnel_id = 8982 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 8983 tunnel_id, "tunnel-id"); 8984 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value = 8985 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 8986 tunnel_id_value, UINT32); 8987 8988 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 8989 .f = cmd_flow_director_filter_parsed, 8990 .data = NULL, 8991 .help_str = "flow_director_filter <port_id> mode IP add|del|update flow" 8992 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 8993 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 8994 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " 8995 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " 8996 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> " 8997 "fd_id <fd_id_value>: " 8998 "Add or delete an ip flow director entry on NIC", 8999 .tokens = { 9000 (void *)&cmd_flow_director_filter, 9001 (void *)&cmd_flow_director_port_id, 9002 (void *)&cmd_flow_director_mode, 9003 (void *)&cmd_flow_director_mode_ip, 9004 (void *)&cmd_flow_director_ops, 9005 (void *)&cmd_flow_director_flow, 9006 (void *)&cmd_flow_director_flow_type, 9007 (void *)&cmd_flow_director_src, 9008 (void *)&cmd_flow_director_ip_src, 9009 (void *)&cmd_flow_director_dst, 9010 (void *)&cmd_flow_director_ip_dst, 9011 (void *)&cmd_flow_director_tos, 9012 (void *)&cmd_flow_director_tos_value, 9013 (void *)&cmd_flow_director_proto, 9014 (void *)&cmd_flow_director_proto_value, 9015 (void *)&cmd_flow_director_ttl, 9016 (void *)&cmd_flow_director_ttl_value, 9017 (void *)&cmd_flow_director_vlan, 9018 (void *)&cmd_flow_director_vlan_value, 9019 (void *)&cmd_flow_director_flexbytes, 9020 (void *)&cmd_flow_director_flexbytes_value, 9021 (void *)&cmd_flow_director_drop, 9022 (void *)&cmd_flow_director_pf_vf, 9023 (void *)&cmd_flow_director_queue, 9024 (void *)&cmd_flow_director_queue_id, 9025 (void *)&cmd_flow_director_fd_id, 9026 (void *)&cmd_flow_director_fd_id_value, 9027 NULL, 9028 }, 9029 }; 9030 9031 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 9032 .f = cmd_flow_director_filter_parsed, 9033 .data = NULL, 9034 .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow " 9035 "director entry on NIC", 9036 .tokens = { 9037 (void *)&cmd_flow_director_filter, 9038 (void *)&cmd_flow_director_port_id, 9039 (void *)&cmd_flow_director_mode, 9040 (void *)&cmd_flow_director_mode_ip, 9041 (void *)&cmd_flow_director_ops, 9042 (void *)&cmd_flow_director_flow, 9043 (void *)&cmd_flow_director_flow_type, 9044 (void *)&cmd_flow_director_src, 9045 (void *)&cmd_flow_director_ip_src, 9046 (void *)&cmd_flow_director_port_src, 9047 (void *)&cmd_flow_director_dst, 9048 (void *)&cmd_flow_director_ip_dst, 9049 (void *)&cmd_flow_director_port_dst, 9050 (void *)&cmd_flow_director_tos, 9051 (void *)&cmd_flow_director_tos_value, 9052 (void *)&cmd_flow_director_ttl, 9053 (void *)&cmd_flow_director_ttl_value, 9054 (void *)&cmd_flow_director_vlan, 9055 (void *)&cmd_flow_director_vlan_value, 9056 (void *)&cmd_flow_director_flexbytes, 9057 (void *)&cmd_flow_director_flexbytes_value, 9058 (void *)&cmd_flow_director_drop, 9059 (void *)&cmd_flow_director_pf_vf, 9060 (void *)&cmd_flow_director_queue, 9061 (void *)&cmd_flow_director_queue_id, 9062 (void *)&cmd_flow_director_fd_id, 9063 (void *)&cmd_flow_director_fd_id_value, 9064 NULL, 9065 }, 9066 }; 9067 9068 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 9069 .f = cmd_flow_director_filter_parsed, 9070 .data = NULL, 9071 .help_str = "flow_director_filter ... : Add or delete a sctp flow " 9072 "director entry on NIC", 9073 .tokens = { 9074 (void *)&cmd_flow_director_filter, 9075 (void *)&cmd_flow_director_port_id, 9076 (void *)&cmd_flow_director_mode, 9077 (void *)&cmd_flow_director_mode_ip, 9078 (void *)&cmd_flow_director_ops, 9079 (void *)&cmd_flow_director_flow, 9080 (void *)&cmd_flow_director_flow_type, 9081 (void *)&cmd_flow_director_src, 9082 (void *)&cmd_flow_director_ip_src, 9083 (void *)&cmd_flow_director_port_dst, 9084 (void *)&cmd_flow_director_dst, 9085 (void *)&cmd_flow_director_ip_dst, 9086 (void *)&cmd_flow_director_port_dst, 9087 (void *)&cmd_flow_director_verify_tag, 9088 (void *)&cmd_flow_director_verify_tag_value, 9089 (void *)&cmd_flow_director_tos, 9090 (void *)&cmd_flow_director_tos_value, 9091 (void *)&cmd_flow_director_ttl, 9092 (void *)&cmd_flow_director_ttl_value, 9093 (void *)&cmd_flow_director_vlan, 9094 (void *)&cmd_flow_director_vlan_value, 9095 (void *)&cmd_flow_director_flexbytes, 9096 (void *)&cmd_flow_director_flexbytes_value, 9097 (void *)&cmd_flow_director_drop, 9098 (void *)&cmd_flow_director_pf_vf, 9099 (void *)&cmd_flow_director_queue, 9100 (void *)&cmd_flow_director_queue_id, 9101 (void *)&cmd_flow_director_fd_id, 9102 (void *)&cmd_flow_director_fd_id_value, 9103 NULL, 9104 }, 9105 }; 9106 9107 cmdline_parse_inst_t cmd_add_del_l2_flow_director = { 9108 .f = cmd_flow_director_filter_parsed, 9109 .data = NULL, 9110 .help_str = "flow_director_filter ... : Add or delete a L2 flow " 9111 "director entry on NIC", 9112 .tokens = { 9113 (void *)&cmd_flow_director_filter, 9114 (void *)&cmd_flow_director_port_id, 9115 (void *)&cmd_flow_director_mode, 9116 (void *)&cmd_flow_director_mode_ip, 9117 (void *)&cmd_flow_director_ops, 9118 (void *)&cmd_flow_director_flow, 9119 (void *)&cmd_flow_director_flow_type, 9120 (void *)&cmd_flow_director_ether, 9121 (void *)&cmd_flow_director_ether_type, 9122 (void *)&cmd_flow_director_flexbytes, 9123 (void *)&cmd_flow_director_flexbytes_value, 9124 (void *)&cmd_flow_director_drop, 9125 (void *)&cmd_flow_director_pf_vf, 9126 (void *)&cmd_flow_director_queue, 9127 (void *)&cmd_flow_director_queue_id, 9128 (void *)&cmd_flow_director_fd_id, 9129 (void *)&cmd_flow_director_fd_id_value, 9130 NULL, 9131 }, 9132 }; 9133 9134 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = { 9135 .f = cmd_flow_director_filter_parsed, 9136 .data = NULL, 9137 .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow " 9138 "director entry on NIC", 9139 .tokens = { 9140 (void *)&cmd_flow_director_filter, 9141 (void *)&cmd_flow_director_port_id, 9142 (void *)&cmd_flow_director_mode, 9143 (void *)&cmd_flow_director_mode_mac_vlan, 9144 (void *)&cmd_flow_director_ops, 9145 (void *)&cmd_flow_director_mac, 9146 (void *)&cmd_flow_director_mac_addr, 9147 (void *)&cmd_flow_director_vlan, 9148 (void *)&cmd_flow_director_vlan_value, 9149 (void *)&cmd_flow_director_flexbytes, 9150 (void *)&cmd_flow_director_flexbytes_value, 9151 (void *)&cmd_flow_director_drop, 9152 (void *)&cmd_flow_director_queue, 9153 (void *)&cmd_flow_director_queue_id, 9154 (void *)&cmd_flow_director_fd_id, 9155 (void *)&cmd_flow_director_fd_id_value, 9156 NULL, 9157 }, 9158 }; 9159 9160 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { 9161 .f = cmd_flow_director_filter_parsed, 9162 .data = NULL, 9163 .help_str = "flow_director_filter ... : Add or delete a tunnel flow " 9164 "director entry on NIC", 9165 .tokens = { 9166 (void *)&cmd_flow_director_filter, 9167 (void *)&cmd_flow_director_port_id, 9168 (void *)&cmd_flow_director_mode, 9169 (void *)&cmd_flow_director_mode_tunnel, 9170 (void *)&cmd_flow_director_ops, 9171 (void *)&cmd_flow_director_mac, 9172 (void *)&cmd_flow_director_mac_addr, 9173 (void *)&cmd_flow_director_vlan, 9174 (void *)&cmd_flow_director_vlan_value, 9175 (void *)&cmd_flow_director_tunnel, 9176 (void *)&cmd_flow_director_tunnel_type, 9177 (void *)&cmd_flow_director_tunnel_id, 9178 (void *)&cmd_flow_director_tunnel_id_value, 9179 (void *)&cmd_flow_director_flexbytes, 9180 (void *)&cmd_flow_director_flexbytes_value, 9181 (void *)&cmd_flow_director_drop, 9182 (void *)&cmd_flow_director_queue, 9183 (void *)&cmd_flow_director_queue_id, 9184 (void *)&cmd_flow_director_fd_id, 9185 (void *)&cmd_flow_director_fd_id_value, 9186 NULL, 9187 }, 9188 }; 9189 9190 struct cmd_flush_flow_director_result { 9191 cmdline_fixed_string_t flush_flow_director; 9192 uint8_t port_id; 9193 }; 9194 9195 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 9196 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 9197 flush_flow_director, "flush_flow_director"); 9198 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 9199 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 9200 port_id, UINT8); 9201 9202 static void 9203 cmd_flush_flow_director_parsed(void *parsed_result, 9204 __attribute__((unused)) struct cmdline *cl, 9205 __attribute__((unused)) void *data) 9206 { 9207 struct cmd_flow_director_result *res = parsed_result; 9208 int ret = 0; 9209 9210 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 9211 if (ret < 0) { 9212 printf("flow director is not supported on port %u.\n", 9213 res->port_id); 9214 return; 9215 } 9216 9217 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9218 RTE_ETH_FILTER_FLUSH, NULL); 9219 if (ret < 0) 9220 printf("flow director table flushing error: (%s)\n", 9221 strerror(-ret)); 9222 } 9223 9224 cmdline_parse_inst_t cmd_flush_flow_director = { 9225 .f = cmd_flush_flow_director_parsed, 9226 .data = NULL, 9227 .help_str = "flush_flow_director <port_id>: " 9228 "Flush all flow director entries of a device on NIC", 9229 .tokens = { 9230 (void *)&cmd_flush_flow_director_flush, 9231 (void *)&cmd_flush_flow_director_port_id, 9232 NULL, 9233 }, 9234 }; 9235 9236 /* *** deal with flow director mask *** */ 9237 struct cmd_flow_director_mask_result { 9238 cmdline_fixed_string_t flow_director_mask; 9239 uint8_t port_id; 9240 cmdline_fixed_string_t mode; 9241 cmdline_fixed_string_t mode_value; 9242 cmdline_fixed_string_t vlan; 9243 uint16_t vlan_mask; 9244 cmdline_fixed_string_t src_mask; 9245 cmdline_ipaddr_t ipv4_src; 9246 cmdline_ipaddr_t ipv6_src; 9247 uint16_t port_src; 9248 cmdline_fixed_string_t dst_mask; 9249 cmdline_ipaddr_t ipv4_dst; 9250 cmdline_ipaddr_t ipv6_dst; 9251 uint16_t port_dst; 9252 cmdline_fixed_string_t mac; 9253 uint8_t mac_addr_byte_mask; 9254 cmdline_fixed_string_t tunnel_id; 9255 uint32_t tunnel_id_mask; 9256 cmdline_fixed_string_t tunnel_type; 9257 uint8_t tunnel_type_mask; 9258 }; 9259 9260 static void 9261 cmd_flow_director_mask_parsed(void *parsed_result, 9262 __attribute__((unused)) struct cmdline *cl, 9263 __attribute__((unused)) void *data) 9264 { 9265 struct cmd_flow_director_mask_result *res = parsed_result; 9266 struct rte_eth_fdir_masks *mask; 9267 struct rte_port *port; 9268 9269 if (res->port_id > nb_ports) { 9270 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9271 return; 9272 } 9273 9274 port = &ports[res->port_id]; 9275 /** Check if the port is not started **/ 9276 if (port->port_status != RTE_PORT_STOPPED) { 9277 printf("Please stop port %d first\n", res->port_id); 9278 return; 9279 } 9280 9281 mask = &port->dev_conf.fdir_conf.mask; 9282 9283 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9284 if (strcmp(res->mode_value, "MAC-VLAN")) { 9285 printf("Please set mode to MAC-VLAN.\n"); 9286 return; 9287 } 9288 9289 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9290 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9291 if (strcmp(res->mode_value, "Tunnel")) { 9292 printf("Please set mode to Tunnel.\n"); 9293 return; 9294 } 9295 9296 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9297 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 9298 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 9299 mask->tunnel_type_mask = res->tunnel_type_mask; 9300 } else { 9301 if (strcmp(res->mode_value, "IP")) { 9302 printf("Please set mode to IP.\n"); 9303 return; 9304 } 9305 9306 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 9307 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 9308 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 9309 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 9310 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 9311 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 9312 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 9313 } 9314 9315 cmd_reconfig_device_queue(res->port_id, 1, 1); 9316 } 9317 9318 cmdline_parse_token_string_t cmd_flow_director_mask = 9319 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9320 flow_director_mask, "flow_director_mask"); 9321 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 9322 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9323 port_id, UINT8); 9324 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 9325 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9326 vlan, "vlan"); 9327 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 9328 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9329 vlan_mask, UINT16); 9330 cmdline_parse_token_string_t cmd_flow_director_mask_src = 9331 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9332 src_mask, "src_mask"); 9333 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 9334 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9335 ipv4_src); 9336 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 9337 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9338 ipv6_src); 9339 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 9340 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9341 port_src, UINT16); 9342 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 9343 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9344 dst_mask, "dst_mask"); 9345 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 9346 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9347 ipv4_dst); 9348 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 9349 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 9350 ipv6_dst); 9351 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 9352 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9353 port_dst, UINT16); 9354 9355 cmdline_parse_token_string_t cmd_flow_director_mask_mode = 9356 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9357 mode, "mode"); 9358 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 9359 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9360 mode_value, "IP"); 9361 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 9362 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9363 mode_value, "MAC-VLAN"); 9364 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 9365 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9366 mode_value, "Tunnel"); 9367 cmdline_parse_token_string_t cmd_flow_director_mask_mac = 9368 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9369 mac, "mac"); 9370 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 9371 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9372 mac_addr_byte_mask, UINT8); 9373 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 9374 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9375 tunnel_type, "tunnel-type"); 9376 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 9377 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9378 tunnel_type_mask, UINT8); 9379 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 9380 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 9381 tunnel_id, "tunnel-id"); 9382 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 9383 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 9384 tunnel_id_mask, UINT32); 9385 9386 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 9387 .f = cmd_flow_director_mask_parsed, 9388 .data = NULL, 9389 .help_str = "flow_director_mask ... : " 9390 "Set IP mode flow director's mask on NIC", 9391 .tokens = { 9392 (void *)&cmd_flow_director_mask, 9393 (void *)&cmd_flow_director_mask_port_id, 9394 (void *)&cmd_flow_director_mask_mode, 9395 (void *)&cmd_flow_director_mask_mode_ip, 9396 (void *)&cmd_flow_director_mask_vlan, 9397 (void *)&cmd_flow_director_mask_vlan_value, 9398 (void *)&cmd_flow_director_mask_src, 9399 (void *)&cmd_flow_director_mask_ipv4_src, 9400 (void *)&cmd_flow_director_mask_ipv6_src, 9401 (void *)&cmd_flow_director_mask_port_src, 9402 (void *)&cmd_flow_director_mask_dst, 9403 (void *)&cmd_flow_director_mask_ipv4_dst, 9404 (void *)&cmd_flow_director_mask_ipv6_dst, 9405 (void *)&cmd_flow_director_mask_port_dst, 9406 NULL, 9407 }, 9408 }; 9409 9410 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 9411 .f = cmd_flow_director_mask_parsed, 9412 .data = NULL, 9413 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 9414 "flow director's mask on NIC", 9415 .tokens = { 9416 (void *)&cmd_flow_director_mask, 9417 (void *)&cmd_flow_director_mask_port_id, 9418 (void *)&cmd_flow_director_mask_mode, 9419 (void *)&cmd_flow_director_mask_mode_mac_vlan, 9420 (void *)&cmd_flow_director_mask_vlan, 9421 (void *)&cmd_flow_director_mask_vlan_value, 9422 NULL, 9423 }, 9424 }; 9425 9426 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 9427 .f = cmd_flow_director_mask_parsed, 9428 .data = NULL, 9429 .help_str = "flow_director_mask ... : Set tunnel mode " 9430 "flow director's mask on NIC", 9431 .tokens = { 9432 (void *)&cmd_flow_director_mask, 9433 (void *)&cmd_flow_director_mask_port_id, 9434 (void *)&cmd_flow_director_mask_mode, 9435 (void *)&cmd_flow_director_mask_mode_tunnel, 9436 (void *)&cmd_flow_director_mask_vlan, 9437 (void *)&cmd_flow_director_mask_vlan_value, 9438 (void *)&cmd_flow_director_mask_mac, 9439 (void *)&cmd_flow_director_mask_mac_value, 9440 (void *)&cmd_flow_director_mask_tunnel_type, 9441 (void *)&cmd_flow_director_mask_tunnel_type_value, 9442 (void *)&cmd_flow_director_mask_tunnel_id, 9443 (void *)&cmd_flow_director_mask_tunnel_id_value, 9444 NULL, 9445 }, 9446 }; 9447 9448 /* *** deal with flow director mask on flexible payload *** */ 9449 struct cmd_flow_director_flex_mask_result { 9450 cmdline_fixed_string_t flow_director_flexmask; 9451 uint8_t port_id; 9452 cmdline_fixed_string_t flow; 9453 cmdline_fixed_string_t flow_type; 9454 cmdline_fixed_string_t mask; 9455 }; 9456 9457 static void 9458 cmd_flow_director_flex_mask_parsed(void *parsed_result, 9459 __attribute__((unused)) struct cmdline *cl, 9460 __attribute__((unused)) void *data) 9461 { 9462 struct cmd_flow_director_flex_mask_result *res = parsed_result; 9463 struct rte_eth_fdir_info fdir_info; 9464 struct rte_eth_fdir_flex_mask flex_mask; 9465 struct rte_port *port; 9466 uint32_t flow_type_mask; 9467 uint16_t i; 9468 int ret; 9469 9470 if (res->port_id > nb_ports) { 9471 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9472 return; 9473 } 9474 9475 port = &ports[res->port_id]; 9476 /** Check if the port is not started **/ 9477 if (port->port_status != RTE_PORT_STOPPED) { 9478 printf("Please stop port %d first\n", res->port_id); 9479 return; 9480 } 9481 9482 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 9483 ret = parse_flexbytes(res->mask, 9484 flex_mask.mask, 9485 RTE_ETH_FDIR_MAX_FLEXLEN); 9486 if (ret < 0) { 9487 printf("error: Cannot parse mask input.\n"); 9488 return; 9489 } 9490 9491 memset(&fdir_info, 0, sizeof(fdir_info)); 9492 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9493 RTE_ETH_FILTER_INFO, &fdir_info); 9494 if (ret < 0) { 9495 printf("Cannot get FDir filter info\n"); 9496 return; 9497 } 9498 9499 if (!strcmp(res->flow_type, "none")) { 9500 /* means don't specify the flow type */ 9501 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN; 9502 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) 9503 memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 9504 0, sizeof(struct rte_eth_fdir_flex_mask)); 9505 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; 9506 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], 9507 &flex_mask, 9508 sizeof(struct rte_eth_fdir_flex_mask)); 9509 cmd_reconfig_device_queue(res->port_id, 1, 1); 9510 return; 9511 } 9512 flow_type_mask = fdir_info.flow_types_mask[0]; 9513 if (!strcmp(res->flow_type, "all")) { 9514 if (!flow_type_mask) { 9515 printf("No flow type supported\n"); 9516 return; 9517 } 9518 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 9519 if (flow_type_mask & (1 << i)) { 9520 flex_mask.flow_type = i; 9521 fdir_set_flex_mask(res->port_id, &flex_mask); 9522 } 9523 } 9524 cmd_reconfig_device_queue(res->port_id, 1, 1); 9525 return; 9526 } 9527 flex_mask.flow_type = str2flowtype(res->flow_type); 9528 if (!(flow_type_mask & (1 << flex_mask.flow_type))) { 9529 printf("Flow type %s not supported on port %d\n", 9530 res->flow_type, res->port_id); 9531 return; 9532 } 9533 fdir_set_flex_mask(res->port_id, &flex_mask); 9534 cmd_reconfig_device_queue(res->port_id, 1, 1); 9535 } 9536 9537 cmdline_parse_token_string_t cmd_flow_director_flexmask = 9538 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9539 flow_director_flexmask, 9540 "flow_director_flex_mask"); 9541 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 9542 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9543 port_id, UINT8); 9544 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 9545 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9546 flow, "flow"); 9547 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 9548 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9549 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 9550 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all"); 9551 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 9552 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 9553 mask, NULL); 9554 9555 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 9556 .f = cmd_flow_director_flex_mask_parsed, 9557 .data = NULL, 9558 .help_str = "flow_director_flex_mask ... : " 9559 "Set flow director's flex mask on NIC", 9560 .tokens = { 9561 (void *)&cmd_flow_director_flexmask, 9562 (void *)&cmd_flow_director_flexmask_port_id, 9563 (void *)&cmd_flow_director_flexmask_flow, 9564 (void *)&cmd_flow_director_flexmask_flow_type, 9565 (void *)&cmd_flow_director_flexmask_mask, 9566 NULL, 9567 }, 9568 }; 9569 9570 /* *** deal with flow director flexible payload configuration *** */ 9571 struct cmd_flow_director_flexpayload_result { 9572 cmdline_fixed_string_t flow_director_flexpayload; 9573 uint8_t port_id; 9574 cmdline_fixed_string_t payload_layer; 9575 cmdline_fixed_string_t payload_cfg; 9576 }; 9577 9578 static inline int 9579 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 9580 { 9581 char s[256]; 9582 const char *p, *p0 = q_arg; 9583 char *end; 9584 unsigned long int_fld; 9585 char *str_fld[max_num]; 9586 int i; 9587 unsigned size; 9588 int ret = -1; 9589 9590 p = strchr(p0, '('); 9591 if (p == NULL) 9592 return -1; 9593 ++p; 9594 p0 = strchr(p, ')'); 9595 if (p0 == NULL) 9596 return -1; 9597 9598 size = p0 - p; 9599 if (size >= sizeof(s)) 9600 return -1; 9601 9602 snprintf(s, sizeof(s), "%.*s", size, p); 9603 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9604 if (ret < 0 || ret > max_num) 9605 return -1; 9606 for (i = 0; i < ret; i++) { 9607 errno = 0; 9608 int_fld = strtoul(str_fld[i], &end, 0); 9609 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 9610 return -1; 9611 offsets[i] = (uint16_t)int_fld; 9612 } 9613 return ret; 9614 } 9615 9616 static void 9617 cmd_flow_director_flxpld_parsed(void *parsed_result, 9618 __attribute__((unused)) struct cmdline *cl, 9619 __attribute__((unused)) void *data) 9620 { 9621 struct cmd_flow_director_flexpayload_result *res = parsed_result; 9622 struct rte_eth_flex_payload_cfg flex_cfg; 9623 struct rte_port *port; 9624 int ret = 0; 9625 9626 if (res->port_id > nb_ports) { 9627 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 9628 return; 9629 } 9630 9631 port = &ports[res->port_id]; 9632 /** Check if the port is not started **/ 9633 if (port->port_status != RTE_PORT_STOPPED) { 9634 printf("Please stop port %d first\n", res->port_id); 9635 return; 9636 } 9637 9638 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 9639 9640 if (!strcmp(res->payload_layer, "raw")) 9641 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 9642 else if (!strcmp(res->payload_layer, "l2")) 9643 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 9644 else if (!strcmp(res->payload_layer, "l3")) 9645 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 9646 else if (!strcmp(res->payload_layer, "l4")) 9647 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 9648 9649 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 9650 RTE_ETH_FDIR_MAX_FLEXLEN); 9651 if (ret < 0) { 9652 printf("error: Cannot parse flex payload input.\n"); 9653 return; 9654 } 9655 9656 fdir_set_flex_payload(res->port_id, &flex_cfg); 9657 cmd_reconfig_device_queue(res->port_id, 1, 1); 9658 } 9659 9660 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 9661 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9662 flow_director_flexpayload, 9663 "flow_director_flex_payload"); 9664 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 9665 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9666 port_id, UINT8); 9667 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 9668 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9669 payload_layer, "raw#l2#l3#l4"); 9670 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 9671 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 9672 payload_cfg, NULL); 9673 9674 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 9675 .f = cmd_flow_director_flxpld_parsed, 9676 .data = NULL, 9677 .help_str = "flow_director_flexpayload ... : " 9678 "Set flow director's flex payload on NIC", 9679 .tokens = { 9680 (void *)&cmd_flow_director_flexpayload, 9681 (void *)&cmd_flow_director_flexpayload_port_id, 9682 (void *)&cmd_flow_director_flexpayload_payload_layer, 9683 (void *)&cmd_flow_director_flexpayload_payload_cfg, 9684 NULL, 9685 }, 9686 }; 9687 9688 /* Generic flow interface command. */ 9689 extern cmdline_parse_inst_t cmd_flow; 9690 9691 /* *** Classification Filters Control *** */ 9692 /* *** Get symmetric hash enable per port *** */ 9693 struct cmd_get_sym_hash_ena_per_port_result { 9694 cmdline_fixed_string_t get_sym_hash_ena_per_port; 9695 uint8_t port_id; 9696 }; 9697 9698 static void 9699 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 9700 __rte_unused struct cmdline *cl, 9701 __rte_unused void *data) 9702 { 9703 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 9704 struct rte_eth_hash_filter_info info; 9705 int ret; 9706 9707 if (rte_eth_dev_filter_supported(res->port_id, 9708 RTE_ETH_FILTER_HASH) < 0) { 9709 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 9710 res->port_id); 9711 return; 9712 } 9713 9714 memset(&info, 0, sizeof(info)); 9715 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 9716 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9717 RTE_ETH_FILTER_GET, &info); 9718 9719 if (ret < 0) { 9720 printf("Cannot get symmetric hash enable per port " 9721 "on port %u\n", res->port_id); 9722 return; 9723 } 9724 9725 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 9726 "enabled" : "disabled", res->port_id); 9727 } 9728 9729 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 9730 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 9731 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 9732 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 9733 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 9734 port_id, UINT8); 9735 9736 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 9737 .f = cmd_get_sym_hash_per_port_parsed, 9738 .data = NULL, 9739 .help_str = "get_sym_hash_ena_per_port <port_id>", 9740 .tokens = { 9741 (void *)&cmd_get_sym_hash_ena_per_port_all, 9742 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 9743 NULL, 9744 }, 9745 }; 9746 9747 /* *** Set symmetric hash enable per port *** */ 9748 struct cmd_set_sym_hash_ena_per_port_result { 9749 cmdline_fixed_string_t set_sym_hash_ena_per_port; 9750 cmdline_fixed_string_t enable; 9751 uint8_t port_id; 9752 }; 9753 9754 static void 9755 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 9756 __rte_unused struct cmdline *cl, 9757 __rte_unused void *data) 9758 { 9759 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 9760 struct rte_eth_hash_filter_info info; 9761 int ret; 9762 9763 if (rte_eth_dev_filter_supported(res->port_id, 9764 RTE_ETH_FILTER_HASH) < 0) { 9765 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 9766 res->port_id); 9767 return; 9768 } 9769 9770 memset(&info, 0, sizeof(info)); 9771 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 9772 if (!strcmp(res->enable, "enable")) 9773 info.info.enable = 1; 9774 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9775 RTE_ETH_FILTER_SET, &info); 9776 if (ret < 0) { 9777 printf("Cannot set symmetric hash enable per port on " 9778 "port %u\n", res->port_id); 9779 return; 9780 } 9781 printf("Symmetric hash has been set to %s on port %u\n", 9782 res->enable, res->port_id); 9783 } 9784 9785 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 9786 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9787 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 9788 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 9789 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9790 port_id, UINT8); 9791 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 9792 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 9793 enable, "enable#disable"); 9794 9795 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 9796 .f = cmd_set_sym_hash_per_port_parsed, 9797 .data = NULL, 9798 .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable", 9799 .tokens = { 9800 (void *)&cmd_set_sym_hash_ena_per_port_all, 9801 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 9802 (void *)&cmd_set_sym_hash_ena_per_port_enable, 9803 NULL, 9804 }, 9805 }; 9806 9807 /* Get global config of hash function */ 9808 struct cmd_get_hash_global_config_result { 9809 cmdline_fixed_string_t get_hash_global_config; 9810 uint8_t port_id; 9811 }; 9812 9813 static char * 9814 flowtype_to_str(uint16_t ftype) 9815 { 9816 uint16_t i; 9817 static struct { 9818 char str[16]; 9819 uint16_t ftype; 9820 } ftype_table[] = { 9821 {"ipv4", RTE_ETH_FLOW_IPV4}, 9822 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 9823 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 9824 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 9825 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 9826 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 9827 {"ipv6", RTE_ETH_FLOW_IPV6}, 9828 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 9829 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 9830 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 9831 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 9832 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 9833 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 9834 {"port", RTE_ETH_FLOW_PORT}, 9835 {"vxlan", RTE_ETH_FLOW_VXLAN}, 9836 {"geneve", RTE_ETH_FLOW_GENEVE}, 9837 {"nvgre", RTE_ETH_FLOW_NVGRE}, 9838 }; 9839 9840 for (i = 0; i < RTE_DIM(ftype_table); i++) { 9841 if (ftype_table[i].ftype == ftype) 9842 return ftype_table[i].str; 9843 } 9844 9845 return NULL; 9846 } 9847 9848 static void 9849 cmd_get_hash_global_config_parsed(void *parsed_result, 9850 __rte_unused struct cmdline *cl, 9851 __rte_unused void *data) 9852 { 9853 struct cmd_get_hash_global_config_result *res = parsed_result; 9854 struct rte_eth_hash_filter_info info; 9855 uint32_t idx, offset; 9856 uint16_t i; 9857 char *str; 9858 int ret; 9859 9860 if (rte_eth_dev_filter_supported(res->port_id, 9861 RTE_ETH_FILTER_HASH) < 0) { 9862 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 9863 res->port_id); 9864 return; 9865 } 9866 9867 memset(&info, 0, sizeof(info)); 9868 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 9869 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9870 RTE_ETH_FILTER_GET, &info); 9871 if (ret < 0) { 9872 printf("Cannot get hash global configurations by port %d\n", 9873 res->port_id); 9874 return; 9875 } 9876 9877 switch (info.info.global_conf.hash_func) { 9878 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 9879 printf("Hash function is Toeplitz\n"); 9880 break; 9881 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 9882 printf("Hash function is Simple XOR\n"); 9883 break; 9884 default: 9885 printf("Unknown hash function\n"); 9886 break; 9887 } 9888 9889 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 9890 idx = i / UINT32_BIT; 9891 offset = i % UINT32_BIT; 9892 if (!(info.info.global_conf.valid_bit_mask[idx] & 9893 (1UL << offset))) 9894 continue; 9895 str = flowtype_to_str(i); 9896 if (!str) 9897 continue; 9898 printf("Symmetric hash is %s globally for flow type %s " 9899 "by port %d\n", 9900 ((info.info.global_conf.sym_hash_enable_mask[idx] & 9901 (1UL << offset)) ? "enabled" : "disabled"), str, 9902 res->port_id); 9903 } 9904 } 9905 9906 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 9907 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 9908 get_hash_global_config, "get_hash_global_config"); 9909 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 9910 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 9911 port_id, UINT8); 9912 9913 cmdline_parse_inst_t cmd_get_hash_global_config = { 9914 .f = cmd_get_hash_global_config_parsed, 9915 .data = NULL, 9916 .help_str = "get_hash_global_config <port_id>", 9917 .tokens = { 9918 (void *)&cmd_get_hash_global_config_all, 9919 (void *)&cmd_get_hash_global_config_port_id, 9920 NULL, 9921 }, 9922 }; 9923 9924 /* Set global config of hash function */ 9925 struct cmd_set_hash_global_config_result { 9926 cmdline_fixed_string_t set_hash_global_config; 9927 uint8_t port_id; 9928 cmdline_fixed_string_t hash_func; 9929 cmdline_fixed_string_t flow_type; 9930 cmdline_fixed_string_t enable; 9931 }; 9932 9933 static void 9934 cmd_set_hash_global_config_parsed(void *parsed_result, 9935 __rte_unused struct cmdline *cl, 9936 __rte_unused void *data) 9937 { 9938 struct cmd_set_hash_global_config_result *res = parsed_result; 9939 struct rte_eth_hash_filter_info info; 9940 uint32_t ftype, idx, offset; 9941 int ret; 9942 9943 if (rte_eth_dev_filter_supported(res->port_id, 9944 RTE_ETH_FILTER_HASH) < 0) { 9945 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 9946 res->port_id); 9947 return; 9948 } 9949 memset(&info, 0, sizeof(info)); 9950 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 9951 if (!strcmp(res->hash_func, "toeplitz")) 9952 info.info.global_conf.hash_func = 9953 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 9954 else if (!strcmp(res->hash_func, "simple_xor")) 9955 info.info.global_conf.hash_func = 9956 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 9957 else if (!strcmp(res->hash_func, "default")) 9958 info.info.global_conf.hash_func = 9959 RTE_ETH_HASH_FUNCTION_DEFAULT; 9960 9961 ftype = str2flowtype(res->flow_type); 9962 idx = ftype / (CHAR_BIT * sizeof(uint32_t)); 9963 offset = ftype % (CHAR_BIT * sizeof(uint32_t)); 9964 info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset); 9965 if (!strcmp(res->enable, "enable")) 9966 info.info.global_conf.sym_hash_enable_mask[idx] |= 9967 (1UL << offset); 9968 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 9969 RTE_ETH_FILTER_SET, &info); 9970 if (ret < 0) 9971 printf("Cannot set global hash configurations by port %d\n", 9972 res->port_id); 9973 else 9974 printf("Global hash configurations have been set " 9975 "succcessfully by port %d\n", res->port_id); 9976 } 9977 9978 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 9979 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9980 set_hash_global_config, "set_hash_global_config"); 9981 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 9982 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 9983 port_id, UINT8); 9984 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 9985 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9986 hash_func, "toeplitz#simple_xor#default"); 9987 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 9988 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9989 flow_type, 9990 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 9991 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 9992 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 9993 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 9994 enable, "enable#disable"); 9995 9996 cmdline_parse_inst_t cmd_set_hash_global_config = { 9997 .f = cmd_set_hash_global_config_parsed, 9998 .data = NULL, 9999 .help_str = "set_hash_global_config <port_id> " 10000 "toeplitz|simple_xor|default " 10001 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10002 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 10003 "l2_payload enable|disable", 10004 .tokens = { 10005 (void *)&cmd_set_hash_global_config_all, 10006 (void *)&cmd_set_hash_global_config_port_id, 10007 (void *)&cmd_set_hash_global_config_hash_func, 10008 (void *)&cmd_set_hash_global_config_flow_type, 10009 (void *)&cmd_set_hash_global_config_enable, 10010 NULL, 10011 }, 10012 }; 10013 10014 /* Set hash input set */ 10015 struct cmd_set_hash_input_set_result { 10016 cmdline_fixed_string_t set_hash_input_set; 10017 uint8_t port_id; 10018 cmdline_fixed_string_t flow_type; 10019 cmdline_fixed_string_t inset_field; 10020 cmdline_fixed_string_t select; 10021 }; 10022 10023 static enum rte_eth_input_set_field 10024 str2inset(char *string) 10025 { 10026 uint16_t i; 10027 10028 static const struct { 10029 char str[32]; 10030 enum rte_eth_input_set_field inset; 10031 } inset_table[] = { 10032 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE}, 10033 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN}, 10034 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN}, 10035 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4}, 10036 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4}, 10037 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS}, 10038 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO}, 10039 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL}, 10040 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6}, 10041 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6}, 10042 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC}, 10043 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER}, 10044 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS}, 10045 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT}, 10046 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT}, 10047 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT}, 10048 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT}, 10049 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT}, 10050 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT}, 10051 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG}, 10052 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY}, 10053 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY}, 10054 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD}, 10055 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD}, 10056 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD}, 10057 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD}, 10058 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD}, 10059 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD}, 10060 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD}, 10061 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD}, 10062 {"none", RTE_ETH_INPUT_SET_NONE}, 10063 }; 10064 10065 for (i = 0; i < RTE_DIM(inset_table); i++) { 10066 if (!strcmp(string, inset_table[i].str)) 10067 return inset_table[i].inset; 10068 } 10069 10070 return RTE_ETH_INPUT_SET_UNKNOWN; 10071 } 10072 10073 static void 10074 cmd_set_hash_input_set_parsed(void *parsed_result, 10075 __rte_unused struct cmdline *cl, 10076 __rte_unused void *data) 10077 { 10078 struct cmd_set_hash_input_set_result *res = parsed_result; 10079 struct rte_eth_hash_filter_info info; 10080 10081 memset(&info, 0, sizeof(info)); 10082 info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; 10083 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10084 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10085 info.info.input_set_conf.inset_size = 1; 10086 if (!strcmp(res->select, "select")) 10087 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10088 else if (!strcmp(res->select, "add")) 10089 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10090 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10091 RTE_ETH_FILTER_SET, &info); 10092 } 10093 10094 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = 10095 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10096 set_hash_input_set, "set_hash_input_set"); 10097 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = 10098 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, 10099 port_id, UINT8); 10100 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = 10101 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10102 flow_type, 10103 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10104 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10105 cmdline_parse_token_string_t cmd_set_hash_input_set_field = 10106 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10107 inset_field, 10108 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10109 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#" 10110 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#" 10111 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#" 10112 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#" 10113 "fld-8th#none"); 10114 cmdline_parse_token_string_t cmd_set_hash_input_set_select = 10115 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 10116 select, "select#add"); 10117 10118 cmdline_parse_inst_t cmd_set_hash_input_set = { 10119 .f = cmd_set_hash_input_set_parsed, 10120 .data = NULL, 10121 .help_str = "set_hash_input_set <port_id> " 10122 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10123 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10124 "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" 10125 "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" 10126 "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" 10127 "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|" 10128 "fld-7th|fld-8th|none select|add", 10129 .tokens = { 10130 (void *)&cmd_set_hash_input_set_cmd, 10131 (void *)&cmd_set_hash_input_set_port_id, 10132 (void *)&cmd_set_hash_input_set_flow_type, 10133 (void *)&cmd_set_hash_input_set_field, 10134 (void *)&cmd_set_hash_input_set_select, 10135 NULL, 10136 }, 10137 }; 10138 10139 /* Set flow director input set */ 10140 struct cmd_set_fdir_input_set_result { 10141 cmdline_fixed_string_t set_fdir_input_set; 10142 uint8_t port_id; 10143 cmdline_fixed_string_t flow_type; 10144 cmdline_fixed_string_t inset_field; 10145 cmdline_fixed_string_t select; 10146 }; 10147 10148 static void 10149 cmd_set_fdir_input_set_parsed(void *parsed_result, 10150 __rte_unused struct cmdline *cl, 10151 __rte_unused void *data) 10152 { 10153 struct cmd_set_fdir_input_set_result *res = parsed_result; 10154 struct rte_eth_fdir_filter_info info; 10155 10156 memset(&info, 0, sizeof(info)); 10157 info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT; 10158 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 10159 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 10160 info.info.input_set_conf.inset_size = 1; 10161 if (!strcmp(res->select, "select")) 10162 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 10163 else if (!strcmp(res->select, "add")) 10164 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 10165 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10166 RTE_ETH_FILTER_SET, &info); 10167 } 10168 10169 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = 10170 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10171 set_fdir_input_set, "set_fdir_input_set"); 10172 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = 10173 TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, 10174 port_id, UINT8); 10175 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = 10176 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10177 flow_type, 10178 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 10179 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 10180 cmdline_parse_token_string_t cmd_set_fdir_input_set_field = 10181 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10182 inset_field, 10183 "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 10184 "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#" 10185 "ipv6-hop-limits#udp-src-port#udp-dst-port#" 10186 "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#" 10187 "sctp-veri-tag#none"); 10188 cmdline_parse_token_string_t cmd_set_fdir_input_set_select = 10189 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 10190 select, "select#add"); 10191 10192 cmdline_parse_inst_t cmd_set_fdir_input_set = { 10193 .f = cmd_set_fdir_input_set_parsed, 10194 .data = NULL, 10195 .help_str = "set_fdir_input_set <port_id> " 10196 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 10197 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 10198 "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|" 10199 "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|" 10200 "ipv6-hop-limits|udp-src-port|udp-dst-port|" 10201 "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|" 10202 "sctp-veri-tag|none select|add", 10203 .tokens = { 10204 (void *)&cmd_set_fdir_input_set_cmd, 10205 (void *)&cmd_set_fdir_input_set_port_id, 10206 (void *)&cmd_set_fdir_input_set_flow_type, 10207 (void *)&cmd_set_fdir_input_set_field, 10208 (void *)&cmd_set_fdir_input_set_select, 10209 NULL, 10210 }, 10211 }; 10212 10213 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 10214 struct cmd_mcast_addr_result { 10215 cmdline_fixed_string_t mcast_addr_cmd; 10216 cmdline_fixed_string_t what; 10217 uint8_t port_num; 10218 struct ether_addr mc_addr; 10219 }; 10220 10221 static void cmd_mcast_addr_parsed(void *parsed_result, 10222 __attribute__((unused)) struct cmdline *cl, 10223 __attribute__((unused)) void *data) 10224 { 10225 struct cmd_mcast_addr_result *res = parsed_result; 10226 10227 if (!is_multicast_ether_addr(&res->mc_addr)) { 10228 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n", 10229 res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1], 10230 res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3], 10231 res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]); 10232 return; 10233 } 10234 if (strcmp(res->what, "add") == 0) 10235 mcast_addr_add(res->port_num, &res->mc_addr); 10236 else 10237 mcast_addr_remove(res->port_num, &res->mc_addr); 10238 } 10239 10240 cmdline_parse_token_string_t cmd_mcast_addr_cmd = 10241 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 10242 mcast_addr_cmd, "mcast_addr"); 10243 cmdline_parse_token_string_t cmd_mcast_addr_what = 10244 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 10245 "add#remove"); 10246 cmdline_parse_token_num_t cmd_mcast_addr_portnum = 10247 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8); 10248 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 10249 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 10250 10251 cmdline_parse_inst_t cmd_mcast_addr = { 10252 .f = cmd_mcast_addr_parsed, 10253 .data = (void *)0, 10254 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 10255 "Add/Remove multicast MAC address on port_id", 10256 .tokens = { 10257 (void *)&cmd_mcast_addr_cmd, 10258 (void *)&cmd_mcast_addr_what, 10259 (void *)&cmd_mcast_addr_portnum, 10260 (void *)&cmd_mcast_addr_addr, 10261 NULL, 10262 }, 10263 }; 10264 10265 /* l2 tunnel config 10266 * only support E-tag now. 10267 */ 10268 10269 /* Ether type config */ 10270 struct cmd_config_l2_tunnel_eth_type_result { 10271 cmdline_fixed_string_t port; 10272 cmdline_fixed_string_t config; 10273 cmdline_fixed_string_t all; 10274 uint8_t id; 10275 cmdline_fixed_string_t l2_tunnel; 10276 cmdline_fixed_string_t l2_tunnel_type; 10277 cmdline_fixed_string_t eth_type; 10278 uint16_t eth_type_val; 10279 }; 10280 10281 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port = 10282 TOKEN_STRING_INITIALIZER 10283 (struct cmd_config_l2_tunnel_eth_type_result, 10284 port, "port"); 10285 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config = 10286 TOKEN_STRING_INITIALIZER 10287 (struct cmd_config_l2_tunnel_eth_type_result, 10288 config, "config"); 10289 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str = 10290 TOKEN_STRING_INITIALIZER 10291 (struct cmd_config_l2_tunnel_eth_type_result, 10292 all, "all"); 10293 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id = 10294 TOKEN_NUM_INITIALIZER 10295 (struct cmd_config_l2_tunnel_eth_type_result, 10296 id, UINT8); 10297 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel = 10298 TOKEN_STRING_INITIALIZER 10299 (struct cmd_config_l2_tunnel_eth_type_result, 10300 l2_tunnel, "l2-tunnel"); 10301 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type = 10302 TOKEN_STRING_INITIALIZER 10303 (struct cmd_config_l2_tunnel_eth_type_result, 10304 l2_tunnel_type, "E-tag"); 10305 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type = 10306 TOKEN_STRING_INITIALIZER 10307 (struct cmd_config_l2_tunnel_eth_type_result, 10308 eth_type, "ether-type"); 10309 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val = 10310 TOKEN_NUM_INITIALIZER 10311 (struct cmd_config_l2_tunnel_eth_type_result, 10312 eth_type_val, UINT16); 10313 10314 static enum rte_eth_tunnel_type 10315 str2fdir_l2_tunnel_type(char *string) 10316 { 10317 uint32_t i = 0; 10318 10319 static const struct { 10320 char str[32]; 10321 enum rte_eth_tunnel_type type; 10322 } l2_tunnel_type_str[] = { 10323 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG}, 10324 }; 10325 10326 for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) { 10327 if (!strcmp(l2_tunnel_type_str[i].str, string)) 10328 return l2_tunnel_type_str[i].type; 10329 } 10330 return RTE_TUNNEL_TYPE_NONE; 10331 } 10332 10333 /* ether type config for all ports */ 10334 static void 10335 cmd_config_l2_tunnel_eth_type_all_parsed 10336 (void *parsed_result, 10337 __attribute__((unused)) struct cmdline *cl, 10338 __attribute__((unused)) void *data) 10339 { 10340 struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result; 10341 struct rte_eth_l2_tunnel_conf entry; 10342 portid_t pid; 10343 10344 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10345 entry.ether_type = res->eth_type_val; 10346 10347 FOREACH_PORT(pid, ports) { 10348 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry); 10349 } 10350 } 10351 10352 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = { 10353 .f = cmd_config_l2_tunnel_eth_type_all_parsed, 10354 .data = NULL, 10355 .help_str = "port config all l2-tunnel E-tag ether-type <value>", 10356 .tokens = { 10357 (void *)&cmd_config_l2_tunnel_eth_type_port, 10358 (void *)&cmd_config_l2_tunnel_eth_type_config, 10359 (void *)&cmd_config_l2_tunnel_eth_type_all_str, 10360 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10361 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10362 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10363 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10364 NULL, 10365 }, 10366 }; 10367 10368 /* ether type config for a specific port */ 10369 static void 10370 cmd_config_l2_tunnel_eth_type_specific_parsed( 10371 void *parsed_result, 10372 __attribute__((unused)) struct cmdline *cl, 10373 __attribute__((unused)) void *data) 10374 { 10375 struct cmd_config_l2_tunnel_eth_type_result *res = 10376 parsed_result; 10377 struct rte_eth_l2_tunnel_conf entry; 10378 10379 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10380 return; 10381 10382 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10383 entry.ether_type = res->eth_type_val; 10384 10385 rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry); 10386 } 10387 10388 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = { 10389 .f = cmd_config_l2_tunnel_eth_type_specific_parsed, 10390 .data = NULL, 10391 .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>", 10392 .tokens = { 10393 (void *)&cmd_config_l2_tunnel_eth_type_port, 10394 (void *)&cmd_config_l2_tunnel_eth_type_config, 10395 (void *)&cmd_config_l2_tunnel_eth_type_id, 10396 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 10397 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 10398 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 10399 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 10400 NULL, 10401 }, 10402 }; 10403 10404 /* Enable/disable l2 tunnel */ 10405 struct cmd_config_l2_tunnel_en_dis_result { 10406 cmdline_fixed_string_t port; 10407 cmdline_fixed_string_t config; 10408 cmdline_fixed_string_t all; 10409 uint8_t id; 10410 cmdline_fixed_string_t l2_tunnel; 10411 cmdline_fixed_string_t l2_tunnel_type; 10412 cmdline_fixed_string_t en_dis; 10413 }; 10414 10415 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port = 10416 TOKEN_STRING_INITIALIZER 10417 (struct cmd_config_l2_tunnel_en_dis_result, 10418 port, "port"); 10419 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config = 10420 TOKEN_STRING_INITIALIZER 10421 (struct cmd_config_l2_tunnel_en_dis_result, 10422 config, "config"); 10423 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str = 10424 TOKEN_STRING_INITIALIZER 10425 (struct cmd_config_l2_tunnel_en_dis_result, 10426 all, "all"); 10427 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id = 10428 TOKEN_NUM_INITIALIZER 10429 (struct cmd_config_l2_tunnel_en_dis_result, 10430 id, UINT8); 10431 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel = 10432 TOKEN_STRING_INITIALIZER 10433 (struct cmd_config_l2_tunnel_en_dis_result, 10434 l2_tunnel, "l2-tunnel"); 10435 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type = 10436 TOKEN_STRING_INITIALIZER 10437 (struct cmd_config_l2_tunnel_en_dis_result, 10438 l2_tunnel_type, "E-tag"); 10439 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis = 10440 TOKEN_STRING_INITIALIZER 10441 (struct cmd_config_l2_tunnel_en_dis_result, 10442 en_dis, "enable#disable"); 10443 10444 /* enable/disable l2 tunnel for all ports */ 10445 static void 10446 cmd_config_l2_tunnel_en_dis_all_parsed( 10447 void *parsed_result, 10448 __attribute__((unused)) struct cmdline *cl, 10449 __attribute__((unused)) void *data) 10450 { 10451 struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result; 10452 struct rte_eth_l2_tunnel_conf entry; 10453 portid_t pid; 10454 uint8_t en; 10455 10456 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10457 10458 if (!strcmp("enable", res->en_dis)) 10459 en = 1; 10460 else 10461 en = 0; 10462 10463 FOREACH_PORT(pid, ports) { 10464 rte_eth_dev_l2_tunnel_offload_set(pid, 10465 &entry, 10466 ETH_L2_TUNNEL_ENABLE_MASK, 10467 en); 10468 } 10469 } 10470 10471 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = { 10472 .f = cmd_config_l2_tunnel_en_dis_all_parsed, 10473 .data = NULL, 10474 .help_str = "port config all l2-tunnel E-tag enable|disable", 10475 .tokens = { 10476 (void *)&cmd_config_l2_tunnel_en_dis_port, 10477 (void *)&cmd_config_l2_tunnel_en_dis_config, 10478 (void *)&cmd_config_l2_tunnel_en_dis_all_str, 10479 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10480 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10481 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10482 NULL, 10483 }, 10484 }; 10485 10486 /* enable/disable l2 tunnel for a port */ 10487 static void 10488 cmd_config_l2_tunnel_en_dis_specific_parsed( 10489 void *parsed_result, 10490 __attribute__((unused)) struct cmdline *cl, 10491 __attribute__((unused)) void *data) 10492 { 10493 struct cmd_config_l2_tunnel_en_dis_result *res = 10494 parsed_result; 10495 struct rte_eth_l2_tunnel_conf entry; 10496 10497 if (port_id_is_invalid(res->id, ENABLED_WARN)) 10498 return; 10499 10500 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 10501 10502 if (!strcmp("enable", res->en_dis)) 10503 rte_eth_dev_l2_tunnel_offload_set(res->id, 10504 &entry, 10505 ETH_L2_TUNNEL_ENABLE_MASK, 10506 1); 10507 else 10508 rte_eth_dev_l2_tunnel_offload_set(res->id, 10509 &entry, 10510 ETH_L2_TUNNEL_ENABLE_MASK, 10511 0); 10512 } 10513 10514 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = { 10515 .f = cmd_config_l2_tunnel_en_dis_specific_parsed, 10516 .data = NULL, 10517 .help_str = "port config <port_id> l2-tunnel E-tag enable|disable", 10518 .tokens = { 10519 (void *)&cmd_config_l2_tunnel_en_dis_port, 10520 (void *)&cmd_config_l2_tunnel_en_dis_config, 10521 (void *)&cmd_config_l2_tunnel_en_dis_id, 10522 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 10523 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 10524 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 10525 NULL, 10526 }, 10527 }; 10528 10529 /* E-tag configuration */ 10530 10531 /* Common result structure for all E-tag configuration */ 10532 struct cmd_config_e_tag_result { 10533 cmdline_fixed_string_t e_tag; 10534 cmdline_fixed_string_t set; 10535 cmdline_fixed_string_t insertion; 10536 cmdline_fixed_string_t stripping; 10537 cmdline_fixed_string_t forwarding; 10538 cmdline_fixed_string_t filter; 10539 cmdline_fixed_string_t add; 10540 cmdline_fixed_string_t del; 10541 cmdline_fixed_string_t on; 10542 cmdline_fixed_string_t off; 10543 cmdline_fixed_string_t on_off; 10544 cmdline_fixed_string_t port_tag_id; 10545 uint32_t port_tag_id_val; 10546 cmdline_fixed_string_t e_tag_id; 10547 uint16_t e_tag_id_val; 10548 cmdline_fixed_string_t dst_pool; 10549 uint8_t dst_pool_val; 10550 cmdline_fixed_string_t port; 10551 uint8_t port_id; 10552 cmdline_fixed_string_t vf; 10553 uint8_t vf_id; 10554 }; 10555 10556 /* Common CLI fields for all E-tag configuration */ 10557 cmdline_parse_token_string_t cmd_config_e_tag_e_tag = 10558 TOKEN_STRING_INITIALIZER 10559 (struct cmd_config_e_tag_result, 10560 e_tag, "E-tag"); 10561 cmdline_parse_token_string_t cmd_config_e_tag_set = 10562 TOKEN_STRING_INITIALIZER 10563 (struct cmd_config_e_tag_result, 10564 set, "set"); 10565 cmdline_parse_token_string_t cmd_config_e_tag_insertion = 10566 TOKEN_STRING_INITIALIZER 10567 (struct cmd_config_e_tag_result, 10568 insertion, "insertion"); 10569 cmdline_parse_token_string_t cmd_config_e_tag_stripping = 10570 TOKEN_STRING_INITIALIZER 10571 (struct cmd_config_e_tag_result, 10572 stripping, "stripping"); 10573 cmdline_parse_token_string_t cmd_config_e_tag_forwarding = 10574 TOKEN_STRING_INITIALIZER 10575 (struct cmd_config_e_tag_result, 10576 forwarding, "forwarding"); 10577 cmdline_parse_token_string_t cmd_config_e_tag_filter = 10578 TOKEN_STRING_INITIALIZER 10579 (struct cmd_config_e_tag_result, 10580 filter, "filter"); 10581 cmdline_parse_token_string_t cmd_config_e_tag_add = 10582 TOKEN_STRING_INITIALIZER 10583 (struct cmd_config_e_tag_result, 10584 add, "add"); 10585 cmdline_parse_token_string_t cmd_config_e_tag_del = 10586 TOKEN_STRING_INITIALIZER 10587 (struct cmd_config_e_tag_result, 10588 del, "del"); 10589 cmdline_parse_token_string_t cmd_config_e_tag_on = 10590 TOKEN_STRING_INITIALIZER 10591 (struct cmd_config_e_tag_result, 10592 on, "on"); 10593 cmdline_parse_token_string_t cmd_config_e_tag_off = 10594 TOKEN_STRING_INITIALIZER 10595 (struct cmd_config_e_tag_result, 10596 off, "off"); 10597 cmdline_parse_token_string_t cmd_config_e_tag_on_off = 10598 TOKEN_STRING_INITIALIZER 10599 (struct cmd_config_e_tag_result, 10600 on_off, "on#off"); 10601 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id = 10602 TOKEN_STRING_INITIALIZER 10603 (struct cmd_config_e_tag_result, 10604 port_tag_id, "port-tag-id"); 10605 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val = 10606 TOKEN_NUM_INITIALIZER 10607 (struct cmd_config_e_tag_result, 10608 port_tag_id_val, UINT32); 10609 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id = 10610 TOKEN_STRING_INITIALIZER 10611 (struct cmd_config_e_tag_result, 10612 e_tag_id, "e-tag-id"); 10613 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val = 10614 TOKEN_NUM_INITIALIZER 10615 (struct cmd_config_e_tag_result, 10616 e_tag_id_val, UINT16); 10617 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool = 10618 TOKEN_STRING_INITIALIZER 10619 (struct cmd_config_e_tag_result, 10620 dst_pool, "dst-pool"); 10621 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val = 10622 TOKEN_NUM_INITIALIZER 10623 (struct cmd_config_e_tag_result, 10624 dst_pool_val, UINT8); 10625 cmdline_parse_token_string_t cmd_config_e_tag_port = 10626 TOKEN_STRING_INITIALIZER 10627 (struct cmd_config_e_tag_result, 10628 port, "port"); 10629 cmdline_parse_token_num_t cmd_config_e_tag_port_id = 10630 TOKEN_NUM_INITIALIZER 10631 (struct cmd_config_e_tag_result, 10632 port_id, UINT8); 10633 cmdline_parse_token_string_t cmd_config_e_tag_vf = 10634 TOKEN_STRING_INITIALIZER 10635 (struct cmd_config_e_tag_result, 10636 vf, "vf"); 10637 cmdline_parse_token_num_t cmd_config_e_tag_vf_id = 10638 TOKEN_NUM_INITIALIZER 10639 (struct cmd_config_e_tag_result, 10640 vf_id, UINT8); 10641 10642 /* E-tag insertion configuration */ 10643 static void 10644 cmd_config_e_tag_insertion_en_parsed( 10645 void *parsed_result, 10646 __attribute__((unused)) struct cmdline *cl, 10647 __attribute__((unused)) void *data) 10648 { 10649 struct cmd_config_e_tag_result *res = 10650 parsed_result; 10651 struct rte_eth_l2_tunnel_conf entry; 10652 10653 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10654 return; 10655 10656 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10657 entry.tunnel_id = res->port_tag_id_val; 10658 entry.vf_id = res->vf_id; 10659 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 10660 &entry, 10661 ETH_L2_TUNNEL_INSERTION_MASK, 10662 1); 10663 } 10664 10665 static void 10666 cmd_config_e_tag_insertion_dis_parsed( 10667 void *parsed_result, 10668 __attribute__((unused)) struct cmdline *cl, 10669 __attribute__((unused)) void *data) 10670 { 10671 struct cmd_config_e_tag_result *res = 10672 parsed_result; 10673 struct rte_eth_l2_tunnel_conf entry; 10674 10675 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10676 return; 10677 10678 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10679 entry.vf_id = res->vf_id; 10680 10681 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 10682 &entry, 10683 ETH_L2_TUNNEL_INSERTION_MASK, 10684 0); 10685 } 10686 10687 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = { 10688 .f = cmd_config_e_tag_insertion_en_parsed, 10689 .data = NULL, 10690 .help_str = "E-tag ... : E-tag insertion enable", 10691 .tokens = { 10692 (void *)&cmd_config_e_tag_e_tag, 10693 (void *)&cmd_config_e_tag_set, 10694 (void *)&cmd_config_e_tag_insertion, 10695 (void *)&cmd_config_e_tag_on, 10696 (void *)&cmd_config_e_tag_port_tag_id, 10697 (void *)&cmd_config_e_tag_port_tag_id_val, 10698 (void *)&cmd_config_e_tag_port, 10699 (void *)&cmd_config_e_tag_port_id, 10700 (void *)&cmd_config_e_tag_vf, 10701 (void *)&cmd_config_e_tag_vf_id, 10702 NULL, 10703 }, 10704 }; 10705 10706 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = { 10707 .f = cmd_config_e_tag_insertion_dis_parsed, 10708 .data = NULL, 10709 .help_str = "E-tag ... : E-tag insertion disable", 10710 .tokens = { 10711 (void *)&cmd_config_e_tag_e_tag, 10712 (void *)&cmd_config_e_tag_set, 10713 (void *)&cmd_config_e_tag_insertion, 10714 (void *)&cmd_config_e_tag_off, 10715 (void *)&cmd_config_e_tag_port, 10716 (void *)&cmd_config_e_tag_port_id, 10717 (void *)&cmd_config_e_tag_vf, 10718 (void *)&cmd_config_e_tag_vf_id, 10719 NULL, 10720 }, 10721 }; 10722 10723 /* E-tag stripping configuration */ 10724 static void 10725 cmd_config_e_tag_stripping_parsed( 10726 void *parsed_result, 10727 __attribute__((unused)) struct cmdline *cl, 10728 __attribute__((unused)) void *data) 10729 { 10730 struct cmd_config_e_tag_result *res = 10731 parsed_result; 10732 struct rte_eth_l2_tunnel_conf entry; 10733 10734 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10735 return; 10736 10737 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10738 10739 if (!strcmp(res->on_off, "on")) 10740 rte_eth_dev_l2_tunnel_offload_set 10741 (res->port_id, 10742 &entry, 10743 ETH_L2_TUNNEL_STRIPPING_MASK, 10744 1); 10745 else 10746 rte_eth_dev_l2_tunnel_offload_set 10747 (res->port_id, 10748 &entry, 10749 ETH_L2_TUNNEL_STRIPPING_MASK, 10750 0); 10751 } 10752 10753 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = { 10754 .f = cmd_config_e_tag_stripping_parsed, 10755 .data = NULL, 10756 .help_str = "E-tag ... : E-tag stripping enable/disable", 10757 .tokens = { 10758 (void *)&cmd_config_e_tag_e_tag, 10759 (void *)&cmd_config_e_tag_set, 10760 (void *)&cmd_config_e_tag_stripping, 10761 (void *)&cmd_config_e_tag_on_off, 10762 (void *)&cmd_config_e_tag_port, 10763 (void *)&cmd_config_e_tag_port_id, 10764 NULL, 10765 }, 10766 }; 10767 10768 /* E-tag forwarding configuration */ 10769 static void 10770 cmd_config_e_tag_forwarding_parsed( 10771 void *parsed_result, 10772 __attribute__((unused)) struct cmdline *cl, 10773 __attribute__((unused)) void *data) 10774 { 10775 struct cmd_config_e_tag_result *res = parsed_result; 10776 struct rte_eth_l2_tunnel_conf entry; 10777 10778 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10779 return; 10780 10781 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10782 10783 if (!strcmp(res->on_off, "on")) 10784 rte_eth_dev_l2_tunnel_offload_set 10785 (res->port_id, 10786 &entry, 10787 ETH_L2_TUNNEL_FORWARDING_MASK, 10788 1); 10789 else 10790 rte_eth_dev_l2_tunnel_offload_set 10791 (res->port_id, 10792 &entry, 10793 ETH_L2_TUNNEL_FORWARDING_MASK, 10794 0); 10795 } 10796 10797 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = { 10798 .f = cmd_config_e_tag_forwarding_parsed, 10799 .data = NULL, 10800 .help_str = "E-tag ... : E-tag forwarding enable/disable", 10801 .tokens = { 10802 (void *)&cmd_config_e_tag_e_tag, 10803 (void *)&cmd_config_e_tag_set, 10804 (void *)&cmd_config_e_tag_forwarding, 10805 (void *)&cmd_config_e_tag_on_off, 10806 (void *)&cmd_config_e_tag_port, 10807 (void *)&cmd_config_e_tag_port_id, 10808 NULL, 10809 }, 10810 }; 10811 10812 /* E-tag filter configuration */ 10813 static void 10814 cmd_config_e_tag_filter_add_parsed( 10815 void *parsed_result, 10816 __attribute__((unused)) struct cmdline *cl, 10817 __attribute__((unused)) void *data) 10818 { 10819 struct cmd_config_e_tag_result *res = parsed_result; 10820 struct rte_eth_l2_tunnel_conf entry; 10821 int ret = 0; 10822 10823 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10824 return; 10825 10826 if (res->e_tag_id_val > 0x3fff) { 10827 printf("e-tag-id must be equal or less than 0x3fff.\n"); 10828 return; 10829 } 10830 10831 ret = rte_eth_dev_filter_supported(res->port_id, 10832 RTE_ETH_FILTER_L2_TUNNEL); 10833 if (ret < 0) { 10834 printf("E-tag filter is not supported on port %u.\n", 10835 res->port_id); 10836 return; 10837 } 10838 10839 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10840 entry.tunnel_id = res->e_tag_id_val; 10841 entry.pool = res->dst_pool_val; 10842 10843 ret = rte_eth_dev_filter_ctrl(res->port_id, 10844 RTE_ETH_FILTER_L2_TUNNEL, 10845 RTE_ETH_FILTER_ADD, 10846 &entry); 10847 if (ret < 0) 10848 printf("E-tag filter programming error: (%s)\n", 10849 strerror(-ret)); 10850 } 10851 10852 cmdline_parse_inst_t cmd_config_e_tag_filter_add = { 10853 .f = cmd_config_e_tag_filter_add_parsed, 10854 .data = NULL, 10855 .help_str = "E-tag ... : E-tag filter add", 10856 .tokens = { 10857 (void *)&cmd_config_e_tag_e_tag, 10858 (void *)&cmd_config_e_tag_set, 10859 (void *)&cmd_config_e_tag_filter, 10860 (void *)&cmd_config_e_tag_add, 10861 (void *)&cmd_config_e_tag_e_tag_id, 10862 (void *)&cmd_config_e_tag_e_tag_id_val, 10863 (void *)&cmd_config_e_tag_dst_pool, 10864 (void *)&cmd_config_e_tag_dst_pool_val, 10865 (void *)&cmd_config_e_tag_port, 10866 (void *)&cmd_config_e_tag_port_id, 10867 NULL, 10868 }, 10869 }; 10870 10871 static void 10872 cmd_config_e_tag_filter_del_parsed( 10873 void *parsed_result, 10874 __attribute__((unused)) struct cmdline *cl, 10875 __attribute__((unused)) void *data) 10876 { 10877 struct cmd_config_e_tag_result *res = parsed_result; 10878 struct rte_eth_l2_tunnel_conf entry; 10879 int ret = 0; 10880 10881 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10882 return; 10883 10884 if (res->e_tag_id_val > 0x3fff) { 10885 printf("e-tag-id must be less than 0x3fff.\n"); 10886 return; 10887 } 10888 10889 ret = rte_eth_dev_filter_supported(res->port_id, 10890 RTE_ETH_FILTER_L2_TUNNEL); 10891 if (ret < 0) { 10892 printf("E-tag filter is not supported on port %u.\n", 10893 res->port_id); 10894 return; 10895 } 10896 10897 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 10898 entry.tunnel_id = res->e_tag_id_val; 10899 10900 ret = rte_eth_dev_filter_ctrl(res->port_id, 10901 RTE_ETH_FILTER_L2_TUNNEL, 10902 RTE_ETH_FILTER_DELETE, 10903 &entry); 10904 if (ret < 0) 10905 printf("E-tag filter programming error: (%s)\n", 10906 strerror(-ret)); 10907 } 10908 10909 cmdline_parse_inst_t cmd_config_e_tag_filter_del = { 10910 .f = cmd_config_e_tag_filter_del_parsed, 10911 .data = NULL, 10912 .help_str = "E-tag ... : E-tag filter delete", 10913 .tokens = { 10914 (void *)&cmd_config_e_tag_e_tag, 10915 (void *)&cmd_config_e_tag_set, 10916 (void *)&cmd_config_e_tag_filter, 10917 (void *)&cmd_config_e_tag_del, 10918 (void *)&cmd_config_e_tag_e_tag_id, 10919 (void *)&cmd_config_e_tag_e_tag_id_val, 10920 (void *)&cmd_config_e_tag_port, 10921 (void *)&cmd_config_e_tag_port_id, 10922 NULL, 10923 }, 10924 }; 10925 10926 /* vf vlan anti spoof configuration */ 10927 10928 /* Common result structure for vf vlan anti spoof */ 10929 struct cmd_vf_vlan_anti_spoof_result { 10930 cmdline_fixed_string_t set; 10931 cmdline_fixed_string_t vf; 10932 cmdline_fixed_string_t vlan; 10933 cmdline_fixed_string_t antispoof; 10934 uint8_t port_id; 10935 uint32_t vf_id; 10936 cmdline_fixed_string_t on_off; 10937 }; 10938 10939 /* Common CLI fields for vf vlan anti spoof enable disable */ 10940 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 10941 TOKEN_STRING_INITIALIZER 10942 (struct cmd_vf_vlan_anti_spoof_result, 10943 set, "set"); 10944 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 10945 TOKEN_STRING_INITIALIZER 10946 (struct cmd_vf_vlan_anti_spoof_result, 10947 vf, "vf"); 10948 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 10949 TOKEN_STRING_INITIALIZER 10950 (struct cmd_vf_vlan_anti_spoof_result, 10951 vlan, "vlan"); 10952 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 10953 TOKEN_STRING_INITIALIZER 10954 (struct cmd_vf_vlan_anti_spoof_result, 10955 antispoof, "antispoof"); 10956 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 10957 TOKEN_NUM_INITIALIZER 10958 (struct cmd_vf_vlan_anti_spoof_result, 10959 port_id, UINT8); 10960 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 10961 TOKEN_NUM_INITIALIZER 10962 (struct cmd_vf_vlan_anti_spoof_result, 10963 vf_id, UINT32); 10964 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 10965 TOKEN_STRING_INITIALIZER 10966 (struct cmd_vf_vlan_anti_spoof_result, 10967 on_off, "on#off"); 10968 10969 static void 10970 cmd_set_vf_vlan_anti_spoof_parsed( 10971 void *parsed_result, 10972 __attribute__((unused)) struct cmdline *cl, 10973 __attribute__((unused)) void *data) 10974 { 10975 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 10976 int ret = -ENOTSUP; 10977 10978 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 10979 10980 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 10981 return; 10982 10983 #ifdef RTE_LIBRTE_IXGBE_PMD 10984 if (ret == -ENOTSUP) 10985 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 10986 res->vf_id, is_on); 10987 #endif 10988 #ifdef RTE_LIBRTE_I40E_PMD 10989 if (ret == -ENOTSUP) 10990 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 10991 res->vf_id, is_on); 10992 #endif 10993 10994 switch (ret) { 10995 case 0: 10996 break; 10997 case -EINVAL: 10998 printf("invalid vf_id %d\n", res->vf_id); 10999 break; 11000 case -ENODEV: 11001 printf("invalid port_id %d\n", res->port_id); 11002 break; 11003 case -ENOTSUP: 11004 printf("function not implemented\n"); 11005 break; 11006 default: 11007 printf("programming error: (%s)\n", strerror(-ret)); 11008 } 11009 } 11010 11011 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 11012 .f = cmd_set_vf_vlan_anti_spoof_parsed, 11013 .data = NULL, 11014 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 11015 .tokens = { 11016 (void *)&cmd_vf_vlan_anti_spoof_set, 11017 (void *)&cmd_vf_vlan_anti_spoof_vf, 11018 (void *)&cmd_vf_vlan_anti_spoof_vlan, 11019 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 11020 (void *)&cmd_vf_vlan_anti_spoof_port_id, 11021 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 11022 (void *)&cmd_vf_vlan_anti_spoof_on_off, 11023 NULL, 11024 }, 11025 }; 11026 11027 /* vf mac anti spoof configuration */ 11028 11029 /* Common result structure for vf mac anti spoof */ 11030 struct cmd_vf_mac_anti_spoof_result { 11031 cmdline_fixed_string_t set; 11032 cmdline_fixed_string_t vf; 11033 cmdline_fixed_string_t mac; 11034 cmdline_fixed_string_t antispoof; 11035 uint8_t port_id; 11036 uint32_t vf_id; 11037 cmdline_fixed_string_t on_off; 11038 }; 11039 11040 /* Common CLI fields for vf mac anti spoof enable disable */ 11041 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 11042 TOKEN_STRING_INITIALIZER 11043 (struct cmd_vf_mac_anti_spoof_result, 11044 set, "set"); 11045 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 11046 TOKEN_STRING_INITIALIZER 11047 (struct cmd_vf_mac_anti_spoof_result, 11048 vf, "vf"); 11049 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 11050 TOKEN_STRING_INITIALIZER 11051 (struct cmd_vf_mac_anti_spoof_result, 11052 mac, "mac"); 11053 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 11054 TOKEN_STRING_INITIALIZER 11055 (struct cmd_vf_mac_anti_spoof_result, 11056 antispoof, "antispoof"); 11057 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 11058 TOKEN_NUM_INITIALIZER 11059 (struct cmd_vf_mac_anti_spoof_result, 11060 port_id, UINT8); 11061 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 11062 TOKEN_NUM_INITIALIZER 11063 (struct cmd_vf_mac_anti_spoof_result, 11064 vf_id, UINT32); 11065 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 11066 TOKEN_STRING_INITIALIZER 11067 (struct cmd_vf_mac_anti_spoof_result, 11068 on_off, "on#off"); 11069 11070 static void 11071 cmd_set_vf_mac_anti_spoof_parsed( 11072 void *parsed_result, 11073 __attribute__((unused)) struct cmdline *cl, 11074 __attribute__((unused)) void *data) 11075 { 11076 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 11077 int ret = -ENOTSUP; 11078 11079 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11080 11081 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11082 return; 11083 11084 #ifdef RTE_LIBRTE_IXGBE_PMD 11085 if (ret == -ENOTSUP) 11086 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 11087 res->vf_id, is_on); 11088 #endif 11089 #ifdef RTE_LIBRTE_I40E_PMD 11090 if (ret == -ENOTSUP) 11091 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 11092 res->vf_id, is_on); 11093 #endif 11094 11095 switch (ret) { 11096 case 0: 11097 break; 11098 case -EINVAL: 11099 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11100 break; 11101 case -ENODEV: 11102 printf("invalid port_id %d\n", res->port_id); 11103 break; 11104 case -ENOTSUP: 11105 printf("function not implemented\n"); 11106 break; 11107 default: 11108 printf("programming error: (%s)\n", strerror(-ret)); 11109 } 11110 } 11111 11112 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 11113 .f = cmd_set_vf_mac_anti_spoof_parsed, 11114 .data = NULL, 11115 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 11116 .tokens = { 11117 (void *)&cmd_vf_mac_anti_spoof_set, 11118 (void *)&cmd_vf_mac_anti_spoof_vf, 11119 (void *)&cmd_vf_mac_anti_spoof_mac, 11120 (void *)&cmd_vf_mac_anti_spoof_antispoof, 11121 (void *)&cmd_vf_mac_anti_spoof_port_id, 11122 (void *)&cmd_vf_mac_anti_spoof_vf_id, 11123 (void *)&cmd_vf_mac_anti_spoof_on_off, 11124 NULL, 11125 }, 11126 }; 11127 11128 /* vf vlan strip queue configuration */ 11129 11130 /* Common result structure for vf mac anti spoof */ 11131 struct cmd_vf_vlan_stripq_result { 11132 cmdline_fixed_string_t set; 11133 cmdline_fixed_string_t vf; 11134 cmdline_fixed_string_t vlan; 11135 cmdline_fixed_string_t stripq; 11136 uint8_t port_id; 11137 uint16_t vf_id; 11138 cmdline_fixed_string_t on_off; 11139 }; 11140 11141 /* Common CLI fields for vf vlan strip enable disable */ 11142 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 11143 TOKEN_STRING_INITIALIZER 11144 (struct cmd_vf_vlan_stripq_result, 11145 set, "set"); 11146 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 11147 TOKEN_STRING_INITIALIZER 11148 (struct cmd_vf_vlan_stripq_result, 11149 vf, "vf"); 11150 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 11151 TOKEN_STRING_INITIALIZER 11152 (struct cmd_vf_vlan_stripq_result, 11153 vlan, "vlan"); 11154 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 11155 TOKEN_STRING_INITIALIZER 11156 (struct cmd_vf_vlan_stripq_result, 11157 stripq, "stripq"); 11158 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 11159 TOKEN_NUM_INITIALIZER 11160 (struct cmd_vf_vlan_stripq_result, 11161 port_id, UINT8); 11162 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 11163 TOKEN_NUM_INITIALIZER 11164 (struct cmd_vf_vlan_stripq_result, 11165 vf_id, UINT16); 11166 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 11167 TOKEN_STRING_INITIALIZER 11168 (struct cmd_vf_vlan_stripq_result, 11169 on_off, "on#off"); 11170 11171 static void 11172 cmd_set_vf_vlan_stripq_parsed( 11173 void *parsed_result, 11174 __attribute__((unused)) struct cmdline *cl, 11175 __attribute__((unused)) void *data) 11176 { 11177 struct cmd_vf_vlan_stripq_result *res = parsed_result; 11178 int ret = -ENOTSUP; 11179 11180 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11181 11182 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11183 return; 11184 11185 #ifdef RTE_LIBRTE_IXGBE_PMD 11186 if (ret == -ENOTSUP) 11187 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 11188 res->vf_id, is_on); 11189 #endif 11190 #ifdef RTE_LIBRTE_I40E_PMD 11191 if (ret == -ENOTSUP) 11192 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 11193 res->vf_id, is_on); 11194 #endif 11195 11196 switch (ret) { 11197 case 0: 11198 break; 11199 case -EINVAL: 11200 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11201 break; 11202 case -ENODEV: 11203 printf("invalid port_id %d\n", res->port_id); 11204 break; 11205 case -ENOTSUP: 11206 printf("function not implemented\n"); 11207 break; 11208 default: 11209 printf("programming error: (%s)\n", strerror(-ret)); 11210 } 11211 } 11212 11213 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 11214 .f = cmd_set_vf_vlan_stripq_parsed, 11215 .data = NULL, 11216 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 11217 .tokens = { 11218 (void *)&cmd_vf_vlan_stripq_set, 11219 (void *)&cmd_vf_vlan_stripq_vf, 11220 (void *)&cmd_vf_vlan_stripq_vlan, 11221 (void *)&cmd_vf_vlan_stripq_stripq, 11222 (void *)&cmd_vf_vlan_stripq_port_id, 11223 (void *)&cmd_vf_vlan_stripq_vf_id, 11224 (void *)&cmd_vf_vlan_stripq_on_off, 11225 NULL, 11226 }, 11227 }; 11228 11229 /* vf vlan insert configuration */ 11230 11231 /* Common result structure for vf vlan insert */ 11232 struct cmd_vf_vlan_insert_result { 11233 cmdline_fixed_string_t set; 11234 cmdline_fixed_string_t vf; 11235 cmdline_fixed_string_t vlan; 11236 cmdline_fixed_string_t insert; 11237 uint8_t port_id; 11238 uint16_t vf_id; 11239 uint16_t vlan_id; 11240 }; 11241 11242 /* Common CLI fields for vf vlan insert enable disable */ 11243 cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 11244 TOKEN_STRING_INITIALIZER 11245 (struct cmd_vf_vlan_insert_result, 11246 set, "set"); 11247 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 11248 TOKEN_STRING_INITIALIZER 11249 (struct cmd_vf_vlan_insert_result, 11250 vf, "vf"); 11251 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 11252 TOKEN_STRING_INITIALIZER 11253 (struct cmd_vf_vlan_insert_result, 11254 vlan, "vlan"); 11255 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 11256 TOKEN_STRING_INITIALIZER 11257 (struct cmd_vf_vlan_insert_result, 11258 insert, "insert"); 11259 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 11260 TOKEN_NUM_INITIALIZER 11261 (struct cmd_vf_vlan_insert_result, 11262 port_id, UINT8); 11263 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 11264 TOKEN_NUM_INITIALIZER 11265 (struct cmd_vf_vlan_insert_result, 11266 vf_id, UINT16); 11267 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 11268 TOKEN_NUM_INITIALIZER 11269 (struct cmd_vf_vlan_insert_result, 11270 vlan_id, UINT16); 11271 11272 static void 11273 cmd_set_vf_vlan_insert_parsed( 11274 void *parsed_result, 11275 __attribute__((unused)) struct cmdline *cl, 11276 __attribute__((unused)) void *data) 11277 { 11278 struct cmd_vf_vlan_insert_result *res = parsed_result; 11279 int ret = -ENOTSUP; 11280 11281 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11282 return; 11283 11284 #ifdef RTE_LIBRTE_IXGBE_PMD 11285 if (ret == -ENOTSUP) 11286 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 11287 res->vlan_id); 11288 #endif 11289 #ifdef RTE_LIBRTE_I40E_PMD 11290 if (ret == -ENOTSUP) 11291 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 11292 res->vlan_id); 11293 #endif 11294 11295 switch (ret) { 11296 case 0: 11297 break; 11298 case -EINVAL: 11299 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id); 11300 break; 11301 case -ENODEV: 11302 printf("invalid port_id %d\n", res->port_id); 11303 break; 11304 case -ENOTSUP: 11305 printf("function not implemented\n"); 11306 break; 11307 default: 11308 printf("programming error: (%s)\n", strerror(-ret)); 11309 } 11310 } 11311 11312 cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 11313 .f = cmd_set_vf_vlan_insert_parsed, 11314 .data = NULL, 11315 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 11316 .tokens = { 11317 (void *)&cmd_vf_vlan_insert_set, 11318 (void *)&cmd_vf_vlan_insert_vf, 11319 (void *)&cmd_vf_vlan_insert_vlan, 11320 (void *)&cmd_vf_vlan_insert_insert, 11321 (void *)&cmd_vf_vlan_insert_port_id, 11322 (void *)&cmd_vf_vlan_insert_vf_id, 11323 (void *)&cmd_vf_vlan_insert_vlan_id, 11324 NULL, 11325 }, 11326 }; 11327 11328 /* tx loopback configuration */ 11329 11330 /* Common result structure for tx loopback */ 11331 struct cmd_tx_loopback_result { 11332 cmdline_fixed_string_t set; 11333 cmdline_fixed_string_t tx; 11334 cmdline_fixed_string_t loopback; 11335 uint8_t port_id; 11336 cmdline_fixed_string_t on_off; 11337 }; 11338 11339 /* Common CLI fields for tx loopback enable disable */ 11340 cmdline_parse_token_string_t cmd_tx_loopback_set = 11341 TOKEN_STRING_INITIALIZER 11342 (struct cmd_tx_loopback_result, 11343 set, "set"); 11344 cmdline_parse_token_string_t cmd_tx_loopback_tx = 11345 TOKEN_STRING_INITIALIZER 11346 (struct cmd_tx_loopback_result, 11347 tx, "tx"); 11348 cmdline_parse_token_string_t cmd_tx_loopback_loopback = 11349 TOKEN_STRING_INITIALIZER 11350 (struct cmd_tx_loopback_result, 11351 loopback, "loopback"); 11352 cmdline_parse_token_num_t cmd_tx_loopback_port_id = 11353 TOKEN_NUM_INITIALIZER 11354 (struct cmd_tx_loopback_result, 11355 port_id, UINT8); 11356 cmdline_parse_token_string_t cmd_tx_loopback_on_off = 11357 TOKEN_STRING_INITIALIZER 11358 (struct cmd_tx_loopback_result, 11359 on_off, "on#off"); 11360 11361 static void 11362 cmd_set_tx_loopback_parsed( 11363 void *parsed_result, 11364 __attribute__((unused)) struct cmdline *cl, 11365 __attribute__((unused)) void *data) 11366 { 11367 struct cmd_tx_loopback_result *res = parsed_result; 11368 int ret = -ENOTSUP; 11369 11370 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11371 11372 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11373 return; 11374 11375 #ifdef RTE_LIBRTE_IXGBE_PMD 11376 if (ret == -ENOTSUP) 11377 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 11378 #endif 11379 #ifdef RTE_LIBRTE_I40E_PMD 11380 if (ret == -ENOTSUP) 11381 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 11382 #endif 11383 11384 switch (ret) { 11385 case 0: 11386 break; 11387 case -EINVAL: 11388 printf("invalid is_on %d\n", is_on); 11389 break; 11390 case -ENODEV: 11391 printf("invalid port_id %d\n", res->port_id); 11392 break; 11393 case -ENOTSUP: 11394 printf("function not implemented\n"); 11395 break; 11396 default: 11397 printf("programming error: (%s)\n", strerror(-ret)); 11398 } 11399 } 11400 11401 cmdline_parse_inst_t cmd_set_tx_loopback = { 11402 .f = cmd_set_tx_loopback_parsed, 11403 .data = NULL, 11404 .help_str = "set tx loopback <port_id> on|off", 11405 .tokens = { 11406 (void *)&cmd_tx_loopback_set, 11407 (void *)&cmd_tx_loopback_tx, 11408 (void *)&cmd_tx_loopback_loopback, 11409 (void *)&cmd_tx_loopback_port_id, 11410 (void *)&cmd_tx_loopback_on_off, 11411 NULL, 11412 }, 11413 }; 11414 11415 #ifdef RTE_LIBRTE_IXGBE_PMD 11416 /* all queues drop enable configuration */ 11417 11418 /* Common result structure for all queues drop enable */ 11419 struct cmd_all_queues_drop_en_result { 11420 cmdline_fixed_string_t set; 11421 cmdline_fixed_string_t all; 11422 cmdline_fixed_string_t queues; 11423 cmdline_fixed_string_t drop; 11424 uint8_t port_id; 11425 cmdline_fixed_string_t on_off; 11426 }; 11427 11428 /* Common CLI fields for tx loopback enable disable */ 11429 cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 11430 TOKEN_STRING_INITIALIZER 11431 (struct cmd_all_queues_drop_en_result, 11432 set, "set"); 11433 cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 11434 TOKEN_STRING_INITIALIZER 11435 (struct cmd_all_queues_drop_en_result, 11436 all, "all"); 11437 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 11438 TOKEN_STRING_INITIALIZER 11439 (struct cmd_all_queues_drop_en_result, 11440 queues, "queues"); 11441 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 11442 TOKEN_STRING_INITIALIZER 11443 (struct cmd_all_queues_drop_en_result, 11444 drop, "drop"); 11445 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 11446 TOKEN_NUM_INITIALIZER 11447 (struct cmd_all_queues_drop_en_result, 11448 port_id, UINT8); 11449 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 11450 TOKEN_STRING_INITIALIZER 11451 (struct cmd_all_queues_drop_en_result, 11452 on_off, "on#off"); 11453 11454 static void 11455 cmd_set_all_queues_drop_en_parsed( 11456 void *parsed_result, 11457 __attribute__((unused)) struct cmdline *cl, 11458 __attribute__((unused)) void *data) 11459 { 11460 struct cmd_all_queues_drop_en_result *res = parsed_result; 11461 int ret = 0; 11462 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11463 11464 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11465 return; 11466 11467 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 11468 switch (ret) { 11469 case 0: 11470 break; 11471 case -EINVAL: 11472 printf("invalid is_on %d\n", is_on); 11473 break; 11474 case -ENODEV: 11475 printf("invalid port_id %d\n", res->port_id); 11476 break; 11477 case -ENOTSUP: 11478 printf("function not implemented\n"); 11479 break; 11480 default: 11481 printf("programming error: (%s)\n", strerror(-ret)); 11482 } 11483 } 11484 11485 cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 11486 .f = cmd_set_all_queues_drop_en_parsed, 11487 .data = NULL, 11488 .help_str = "set all queues drop <port_id> on|off", 11489 .tokens = { 11490 (void *)&cmd_all_queues_drop_en_set, 11491 (void *)&cmd_all_queues_drop_en_all, 11492 (void *)&cmd_all_queues_drop_en_queues, 11493 (void *)&cmd_all_queues_drop_en_drop, 11494 (void *)&cmd_all_queues_drop_en_port_id, 11495 (void *)&cmd_all_queues_drop_en_on_off, 11496 NULL, 11497 }, 11498 }; 11499 11500 /* vf split drop enable configuration */ 11501 11502 /* Common result structure for vf split drop enable */ 11503 struct cmd_vf_split_drop_en_result { 11504 cmdline_fixed_string_t set; 11505 cmdline_fixed_string_t vf; 11506 cmdline_fixed_string_t split; 11507 cmdline_fixed_string_t drop; 11508 uint8_t port_id; 11509 uint16_t vf_id; 11510 cmdline_fixed_string_t on_off; 11511 }; 11512 11513 /* Common CLI fields for vf split drop enable disable */ 11514 cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 11515 TOKEN_STRING_INITIALIZER 11516 (struct cmd_vf_split_drop_en_result, 11517 set, "set"); 11518 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 11519 TOKEN_STRING_INITIALIZER 11520 (struct cmd_vf_split_drop_en_result, 11521 vf, "vf"); 11522 cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 11523 TOKEN_STRING_INITIALIZER 11524 (struct cmd_vf_split_drop_en_result, 11525 split, "split"); 11526 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 11527 TOKEN_STRING_INITIALIZER 11528 (struct cmd_vf_split_drop_en_result, 11529 drop, "drop"); 11530 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 11531 TOKEN_NUM_INITIALIZER 11532 (struct cmd_vf_split_drop_en_result, 11533 port_id, UINT8); 11534 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 11535 TOKEN_NUM_INITIALIZER 11536 (struct cmd_vf_split_drop_en_result, 11537 vf_id, UINT16); 11538 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 11539 TOKEN_STRING_INITIALIZER 11540 (struct cmd_vf_split_drop_en_result, 11541 on_off, "on#off"); 11542 11543 static void 11544 cmd_set_vf_split_drop_en_parsed( 11545 void *parsed_result, 11546 __attribute__((unused)) struct cmdline *cl, 11547 __attribute__((unused)) void *data) 11548 { 11549 struct cmd_vf_split_drop_en_result *res = parsed_result; 11550 int ret; 11551 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 11552 11553 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11554 return; 11555 11556 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 11557 is_on); 11558 switch (ret) { 11559 case 0: 11560 break; 11561 case -EINVAL: 11562 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 11563 break; 11564 case -ENODEV: 11565 printf("invalid port_id %d\n", res->port_id); 11566 break; 11567 default: 11568 printf("programming error: (%s)\n", strerror(-ret)); 11569 } 11570 } 11571 11572 cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 11573 .f = cmd_set_vf_split_drop_en_parsed, 11574 .data = NULL, 11575 .help_str = "set vf split drop <port_id> <vf_id> on|off", 11576 .tokens = { 11577 (void *)&cmd_vf_split_drop_en_set, 11578 (void *)&cmd_vf_split_drop_en_vf, 11579 (void *)&cmd_vf_split_drop_en_split, 11580 (void *)&cmd_vf_split_drop_en_drop, 11581 (void *)&cmd_vf_split_drop_en_port_id, 11582 (void *)&cmd_vf_split_drop_en_vf_id, 11583 (void *)&cmd_vf_split_drop_en_on_off, 11584 NULL, 11585 }, 11586 }; 11587 #endif 11588 11589 /* vf mac address configuration */ 11590 11591 /* Common result structure for vf mac address */ 11592 struct cmd_set_vf_mac_addr_result { 11593 cmdline_fixed_string_t set; 11594 cmdline_fixed_string_t vf; 11595 cmdline_fixed_string_t mac; 11596 cmdline_fixed_string_t addr; 11597 uint8_t port_id; 11598 uint16_t vf_id; 11599 struct ether_addr mac_addr; 11600 11601 }; 11602 11603 /* Common CLI fields for vf split drop enable disable */ 11604 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 11605 TOKEN_STRING_INITIALIZER 11606 (struct cmd_set_vf_mac_addr_result, 11607 set, "set"); 11608 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 11609 TOKEN_STRING_INITIALIZER 11610 (struct cmd_set_vf_mac_addr_result, 11611 vf, "vf"); 11612 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 11613 TOKEN_STRING_INITIALIZER 11614 (struct cmd_set_vf_mac_addr_result, 11615 mac, "mac"); 11616 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 11617 TOKEN_STRING_INITIALIZER 11618 (struct cmd_set_vf_mac_addr_result, 11619 addr, "addr"); 11620 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 11621 TOKEN_NUM_INITIALIZER 11622 (struct cmd_set_vf_mac_addr_result, 11623 port_id, UINT8); 11624 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 11625 TOKEN_NUM_INITIALIZER 11626 (struct cmd_set_vf_mac_addr_result, 11627 vf_id, UINT16); 11628 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 11629 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 11630 mac_addr); 11631 11632 static void 11633 cmd_set_vf_mac_addr_parsed( 11634 void *parsed_result, 11635 __attribute__((unused)) struct cmdline *cl, 11636 __attribute__((unused)) void *data) 11637 { 11638 struct cmd_set_vf_mac_addr_result *res = parsed_result; 11639 int ret = -ENOTSUP; 11640 11641 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11642 return; 11643 11644 #ifdef RTE_LIBRTE_IXGBE_PMD 11645 if (ret == -ENOTSUP) 11646 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 11647 &res->mac_addr); 11648 #endif 11649 #ifdef RTE_LIBRTE_I40E_PMD 11650 if (ret == -ENOTSUP) 11651 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 11652 &res->mac_addr); 11653 #endif 11654 11655 switch (ret) { 11656 case 0: 11657 break; 11658 case -EINVAL: 11659 printf("invalid vf_id %d or mac_addr\n", res->vf_id); 11660 break; 11661 case -ENODEV: 11662 printf("invalid port_id %d\n", res->port_id); 11663 break; 11664 case -ENOTSUP: 11665 printf("function not implemented\n"); 11666 break; 11667 default: 11668 printf("programming error: (%s)\n", strerror(-ret)); 11669 } 11670 } 11671 11672 cmdline_parse_inst_t cmd_set_vf_mac_addr = { 11673 .f = cmd_set_vf_mac_addr_parsed, 11674 .data = NULL, 11675 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 11676 .tokens = { 11677 (void *)&cmd_set_vf_mac_addr_set, 11678 (void *)&cmd_set_vf_mac_addr_vf, 11679 (void *)&cmd_set_vf_mac_addr_mac, 11680 (void *)&cmd_set_vf_mac_addr_addr, 11681 (void *)&cmd_set_vf_mac_addr_port_id, 11682 (void *)&cmd_set_vf_mac_addr_vf_id, 11683 (void *)&cmd_set_vf_mac_addr_mac_addr, 11684 NULL, 11685 }, 11686 }; 11687 11688 #ifdef RTE_LIBRTE_IXGBE_PMD 11689 /* MACsec configuration */ 11690 11691 /* Common result structure for MACsec offload enable */ 11692 struct cmd_macsec_offload_on_result { 11693 cmdline_fixed_string_t set; 11694 cmdline_fixed_string_t macsec; 11695 cmdline_fixed_string_t offload; 11696 uint8_t port_id; 11697 cmdline_fixed_string_t on; 11698 cmdline_fixed_string_t encrypt; 11699 cmdline_fixed_string_t en_on_off; 11700 cmdline_fixed_string_t replay_protect; 11701 cmdline_fixed_string_t rp_on_off; 11702 }; 11703 11704 /* Common CLI fields for MACsec offload disable */ 11705 cmdline_parse_token_string_t cmd_macsec_offload_on_set = 11706 TOKEN_STRING_INITIALIZER 11707 (struct cmd_macsec_offload_on_result, 11708 set, "set"); 11709 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 11710 TOKEN_STRING_INITIALIZER 11711 (struct cmd_macsec_offload_on_result, 11712 macsec, "macsec"); 11713 cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 11714 TOKEN_STRING_INITIALIZER 11715 (struct cmd_macsec_offload_on_result, 11716 offload, "offload"); 11717 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 11718 TOKEN_NUM_INITIALIZER 11719 (struct cmd_macsec_offload_on_result, 11720 port_id, UINT8); 11721 cmdline_parse_token_string_t cmd_macsec_offload_on_on = 11722 TOKEN_STRING_INITIALIZER 11723 (struct cmd_macsec_offload_on_result, 11724 on, "on"); 11725 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 11726 TOKEN_STRING_INITIALIZER 11727 (struct cmd_macsec_offload_on_result, 11728 encrypt, "encrypt"); 11729 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 11730 TOKEN_STRING_INITIALIZER 11731 (struct cmd_macsec_offload_on_result, 11732 en_on_off, "on#off"); 11733 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 11734 TOKEN_STRING_INITIALIZER 11735 (struct cmd_macsec_offload_on_result, 11736 replay_protect, "replay-protect"); 11737 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 11738 TOKEN_STRING_INITIALIZER 11739 (struct cmd_macsec_offload_on_result, 11740 rp_on_off, "on#off"); 11741 11742 static void 11743 cmd_set_macsec_offload_on_parsed( 11744 void *parsed_result, 11745 __attribute__((unused)) struct cmdline *cl, 11746 __attribute__((unused)) void *data) 11747 { 11748 struct cmd_macsec_offload_on_result *res = parsed_result; 11749 int ret; 11750 portid_t port_id = res->port_id; 11751 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 11752 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 11753 11754 if (port_id_is_invalid(port_id, ENABLED_WARN)) 11755 return; 11756 11757 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC; 11758 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 11759 11760 switch (ret) { 11761 case 0: 11762 break; 11763 case -ENODEV: 11764 printf("invalid port_id %d\n", port_id); 11765 break; 11766 default: 11767 printf("programming error: (%s)\n", strerror(-ret)); 11768 } 11769 } 11770 11771 cmdline_parse_inst_t cmd_set_macsec_offload_on = { 11772 .f = cmd_set_macsec_offload_on_parsed, 11773 .data = NULL, 11774 .help_str = "set macsec offload <port_id> on " 11775 "encrypt on|off replay-protect on|off", 11776 .tokens = { 11777 (void *)&cmd_macsec_offload_on_set, 11778 (void *)&cmd_macsec_offload_on_macsec, 11779 (void *)&cmd_macsec_offload_on_offload, 11780 (void *)&cmd_macsec_offload_on_port_id, 11781 (void *)&cmd_macsec_offload_on_on, 11782 (void *)&cmd_macsec_offload_on_encrypt, 11783 (void *)&cmd_macsec_offload_on_en_on_off, 11784 (void *)&cmd_macsec_offload_on_replay_protect, 11785 (void *)&cmd_macsec_offload_on_rp_on_off, 11786 NULL, 11787 }, 11788 }; 11789 11790 /* Common result structure for MACsec offload disable */ 11791 struct cmd_macsec_offload_off_result { 11792 cmdline_fixed_string_t set; 11793 cmdline_fixed_string_t macsec; 11794 cmdline_fixed_string_t offload; 11795 uint8_t port_id; 11796 cmdline_fixed_string_t off; 11797 }; 11798 11799 /* Common CLI fields for MACsec offload disable */ 11800 cmdline_parse_token_string_t cmd_macsec_offload_off_set = 11801 TOKEN_STRING_INITIALIZER 11802 (struct cmd_macsec_offload_off_result, 11803 set, "set"); 11804 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 11805 TOKEN_STRING_INITIALIZER 11806 (struct cmd_macsec_offload_off_result, 11807 macsec, "macsec"); 11808 cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 11809 TOKEN_STRING_INITIALIZER 11810 (struct cmd_macsec_offload_off_result, 11811 offload, "offload"); 11812 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 11813 TOKEN_NUM_INITIALIZER 11814 (struct cmd_macsec_offload_off_result, 11815 port_id, UINT8); 11816 cmdline_parse_token_string_t cmd_macsec_offload_off_off = 11817 TOKEN_STRING_INITIALIZER 11818 (struct cmd_macsec_offload_off_result, 11819 off, "off"); 11820 11821 static void 11822 cmd_set_macsec_offload_off_parsed( 11823 void *parsed_result, 11824 __attribute__((unused)) struct cmdline *cl, 11825 __attribute__((unused)) void *data) 11826 { 11827 struct cmd_macsec_offload_off_result *res = parsed_result; 11828 int ret; 11829 portid_t port_id = res->port_id; 11830 11831 if (port_id_is_invalid(port_id, ENABLED_WARN)) 11832 return; 11833 11834 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC; 11835 ret = rte_pmd_ixgbe_macsec_disable(port_id); 11836 11837 switch (ret) { 11838 case 0: 11839 break; 11840 case -ENODEV: 11841 printf("invalid port_id %d\n", port_id); 11842 break; 11843 default: 11844 printf("programming error: (%s)\n", strerror(-ret)); 11845 } 11846 } 11847 11848 cmdline_parse_inst_t cmd_set_macsec_offload_off = { 11849 .f = cmd_set_macsec_offload_off_parsed, 11850 .data = NULL, 11851 .help_str = "set macsec offload <port_id> off", 11852 .tokens = { 11853 (void *)&cmd_macsec_offload_off_set, 11854 (void *)&cmd_macsec_offload_off_macsec, 11855 (void *)&cmd_macsec_offload_off_offload, 11856 (void *)&cmd_macsec_offload_off_port_id, 11857 (void *)&cmd_macsec_offload_off_off, 11858 NULL, 11859 }, 11860 }; 11861 11862 /* Common result structure for MACsec secure connection configure */ 11863 struct cmd_macsec_sc_result { 11864 cmdline_fixed_string_t set; 11865 cmdline_fixed_string_t macsec; 11866 cmdline_fixed_string_t sc; 11867 cmdline_fixed_string_t tx_rx; 11868 uint8_t port_id; 11869 struct ether_addr mac; 11870 uint16_t pi; 11871 }; 11872 11873 /* Common CLI fields for MACsec secure connection configure */ 11874 cmdline_parse_token_string_t cmd_macsec_sc_set = 11875 TOKEN_STRING_INITIALIZER 11876 (struct cmd_macsec_sc_result, 11877 set, "set"); 11878 cmdline_parse_token_string_t cmd_macsec_sc_macsec = 11879 TOKEN_STRING_INITIALIZER 11880 (struct cmd_macsec_sc_result, 11881 macsec, "macsec"); 11882 cmdline_parse_token_string_t cmd_macsec_sc_sc = 11883 TOKEN_STRING_INITIALIZER 11884 (struct cmd_macsec_sc_result, 11885 sc, "sc"); 11886 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 11887 TOKEN_STRING_INITIALIZER 11888 (struct cmd_macsec_sc_result, 11889 tx_rx, "tx#rx"); 11890 cmdline_parse_token_num_t cmd_macsec_sc_port_id = 11891 TOKEN_NUM_INITIALIZER 11892 (struct cmd_macsec_sc_result, 11893 port_id, UINT8); 11894 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 11895 TOKEN_ETHERADDR_INITIALIZER 11896 (struct cmd_macsec_sc_result, 11897 mac); 11898 cmdline_parse_token_num_t cmd_macsec_sc_pi = 11899 TOKEN_NUM_INITIALIZER 11900 (struct cmd_macsec_sc_result, 11901 pi, UINT16); 11902 11903 static void 11904 cmd_set_macsec_sc_parsed( 11905 void *parsed_result, 11906 __attribute__((unused)) struct cmdline *cl, 11907 __attribute__((unused)) void *data) 11908 { 11909 struct cmd_macsec_sc_result *res = parsed_result; 11910 int ret; 11911 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 11912 11913 ret = is_tx ? 11914 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 11915 res->mac.addr_bytes) : 11916 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 11917 res->mac.addr_bytes, res->pi); 11918 switch (ret) { 11919 case 0: 11920 break; 11921 case -ENODEV: 11922 printf("invalid port_id %d\n", res->port_id); 11923 break; 11924 default: 11925 printf("programming error: (%s)\n", strerror(-ret)); 11926 } 11927 } 11928 11929 cmdline_parse_inst_t cmd_set_macsec_sc = { 11930 .f = cmd_set_macsec_sc_parsed, 11931 .data = NULL, 11932 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 11933 .tokens = { 11934 (void *)&cmd_macsec_sc_set, 11935 (void *)&cmd_macsec_sc_macsec, 11936 (void *)&cmd_macsec_sc_sc, 11937 (void *)&cmd_macsec_sc_tx_rx, 11938 (void *)&cmd_macsec_sc_port_id, 11939 (void *)&cmd_macsec_sc_mac, 11940 (void *)&cmd_macsec_sc_pi, 11941 NULL, 11942 }, 11943 }; 11944 11945 /* Common result structure for MACsec secure connection configure */ 11946 struct cmd_macsec_sa_result { 11947 cmdline_fixed_string_t set; 11948 cmdline_fixed_string_t macsec; 11949 cmdline_fixed_string_t sa; 11950 cmdline_fixed_string_t tx_rx; 11951 uint8_t port_id; 11952 uint8_t idx; 11953 uint8_t an; 11954 uint32_t pn; 11955 cmdline_fixed_string_t key; 11956 }; 11957 11958 /* Common CLI fields for MACsec secure connection configure */ 11959 cmdline_parse_token_string_t cmd_macsec_sa_set = 11960 TOKEN_STRING_INITIALIZER 11961 (struct cmd_macsec_sa_result, 11962 set, "set"); 11963 cmdline_parse_token_string_t cmd_macsec_sa_macsec = 11964 TOKEN_STRING_INITIALIZER 11965 (struct cmd_macsec_sa_result, 11966 macsec, "macsec"); 11967 cmdline_parse_token_string_t cmd_macsec_sa_sa = 11968 TOKEN_STRING_INITIALIZER 11969 (struct cmd_macsec_sa_result, 11970 sa, "sa"); 11971 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 11972 TOKEN_STRING_INITIALIZER 11973 (struct cmd_macsec_sa_result, 11974 tx_rx, "tx#rx"); 11975 cmdline_parse_token_num_t cmd_macsec_sa_port_id = 11976 TOKEN_NUM_INITIALIZER 11977 (struct cmd_macsec_sa_result, 11978 port_id, UINT8); 11979 cmdline_parse_token_num_t cmd_macsec_sa_idx = 11980 TOKEN_NUM_INITIALIZER 11981 (struct cmd_macsec_sa_result, 11982 idx, UINT8); 11983 cmdline_parse_token_num_t cmd_macsec_sa_an = 11984 TOKEN_NUM_INITIALIZER 11985 (struct cmd_macsec_sa_result, 11986 an, UINT8); 11987 cmdline_parse_token_num_t cmd_macsec_sa_pn = 11988 TOKEN_NUM_INITIALIZER 11989 (struct cmd_macsec_sa_result, 11990 pn, UINT32); 11991 cmdline_parse_token_string_t cmd_macsec_sa_key = 11992 TOKEN_STRING_INITIALIZER 11993 (struct cmd_macsec_sa_result, 11994 key, NULL); 11995 11996 static void 11997 cmd_set_macsec_sa_parsed( 11998 void *parsed_result, 11999 __attribute__((unused)) struct cmdline *cl, 12000 __attribute__((unused)) void *data) 12001 { 12002 struct cmd_macsec_sa_result *res = parsed_result; 12003 int ret; 12004 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 12005 uint8_t key[16] = { 0 }; 12006 uint8_t xdgt0; 12007 uint8_t xdgt1; 12008 int key_len; 12009 int i; 12010 12011 key_len = strlen(res->key) / 2; 12012 if (key_len > 16) 12013 key_len = 16; 12014 12015 for (i = 0; i < key_len; i++) { 12016 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 12017 if (xdgt0 == 0xFF) 12018 return; 12019 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 12020 if (xdgt1 == 0xFF) 12021 return; 12022 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 12023 } 12024 12025 ret = is_tx ? 12026 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 12027 res->idx, res->an, res->pn, key) : 12028 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 12029 res->idx, res->an, res->pn, key); 12030 switch (ret) { 12031 case 0: 12032 break; 12033 case -EINVAL: 12034 printf("invalid idx %d or an %d\n", res->idx, res->an); 12035 break; 12036 case -ENODEV: 12037 printf("invalid port_id %d\n", res->port_id); 12038 break; 12039 default: 12040 printf("programming error: (%s)\n", strerror(-ret)); 12041 } 12042 } 12043 12044 cmdline_parse_inst_t cmd_set_macsec_sa = { 12045 .f = cmd_set_macsec_sa_parsed, 12046 .data = NULL, 12047 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 12048 .tokens = { 12049 (void *)&cmd_macsec_sa_set, 12050 (void *)&cmd_macsec_sa_macsec, 12051 (void *)&cmd_macsec_sa_sa, 12052 (void *)&cmd_macsec_sa_tx_rx, 12053 (void *)&cmd_macsec_sa_port_id, 12054 (void *)&cmd_macsec_sa_idx, 12055 (void *)&cmd_macsec_sa_an, 12056 (void *)&cmd_macsec_sa_pn, 12057 (void *)&cmd_macsec_sa_key, 12058 NULL, 12059 }, 12060 }; 12061 #endif 12062 12063 /* VF unicast promiscuous mode configuration */ 12064 12065 /* Common result structure for VF unicast promiscuous mode */ 12066 struct cmd_vf_promisc_result { 12067 cmdline_fixed_string_t set; 12068 cmdline_fixed_string_t vf; 12069 cmdline_fixed_string_t promisc; 12070 uint8_t port_id; 12071 uint32_t vf_id; 12072 cmdline_fixed_string_t on_off; 12073 }; 12074 12075 /* Common CLI fields for VF unicast promiscuous mode enable disable */ 12076 cmdline_parse_token_string_t cmd_vf_promisc_set = 12077 TOKEN_STRING_INITIALIZER 12078 (struct cmd_vf_promisc_result, 12079 set, "set"); 12080 cmdline_parse_token_string_t cmd_vf_promisc_vf = 12081 TOKEN_STRING_INITIALIZER 12082 (struct cmd_vf_promisc_result, 12083 vf, "vf"); 12084 cmdline_parse_token_string_t cmd_vf_promisc_promisc = 12085 TOKEN_STRING_INITIALIZER 12086 (struct cmd_vf_promisc_result, 12087 promisc, "promisc"); 12088 cmdline_parse_token_num_t cmd_vf_promisc_port_id = 12089 TOKEN_NUM_INITIALIZER 12090 (struct cmd_vf_promisc_result, 12091 port_id, UINT8); 12092 cmdline_parse_token_num_t cmd_vf_promisc_vf_id = 12093 TOKEN_NUM_INITIALIZER 12094 (struct cmd_vf_promisc_result, 12095 vf_id, UINT32); 12096 cmdline_parse_token_string_t cmd_vf_promisc_on_off = 12097 TOKEN_STRING_INITIALIZER 12098 (struct cmd_vf_promisc_result, 12099 on_off, "on#off"); 12100 12101 static void 12102 cmd_set_vf_promisc_parsed( 12103 void *parsed_result, 12104 __attribute__((unused)) struct cmdline *cl, 12105 __attribute__((unused)) void *data) 12106 { 12107 struct cmd_vf_promisc_result *res = parsed_result; 12108 int ret = -ENOTSUP; 12109 12110 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12111 12112 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12113 return; 12114 12115 #ifdef RTE_LIBRTE_I40E_PMD 12116 ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id, 12117 res->vf_id, is_on); 12118 #endif 12119 12120 switch (ret) { 12121 case 0: 12122 break; 12123 case -EINVAL: 12124 printf("invalid vf_id %d\n", res->vf_id); 12125 break; 12126 case -ENODEV: 12127 printf("invalid port_id %d\n", res->port_id); 12128 break; 12129 case -ENOTSUP: 12130 printf("function not implemented\n"); 12131 break; 12132 default: 12133 printf("programming error: (%s)\n", strerror(-ret)); 12134 } 12135 } 12136 12137 cmdline_parse_inst_t cmd_set_vf_promisc = { 12138 .f = cmd_set_vf_promisc_parsed, 12139 .data = NULL, 12140 .help_str = "set vf promisc <port_id> <vf_id> on|off: " 12141 "Set unicast promiscuous mode for a VF from the PF", 12142 .tokens = { 12143 (void *)&cmd_vf_promisc_set, 12144 (void *)&cmd_vf_promisc_vf, 12145 (void *)&cmd_vf_promisc_promisc, 12146 (void *)&cmd_vf_promisc_port_id, 12147 (void *)&cmd_vf_promisc_vf_id, 12148 (void *)&cmd_vf_promisc_on_off, 12149 NULL, 12150 }, 12151 }; 12152 12153 /* VF multicast promiscuous mode configuration */ 12154 12155 /* Common result structure for VF multicast promiscuous mode */ 12156 struct cmd_vf_allmulti_result { 12157 cmdline_fixed_string_t set; 12158 cmdline_fixed_string_t vf; 12159 cmdline_fixed_string_t allmulti; 12160 uint8_t port_id; 12161 uint32_t vf_id; 12162 cmdline_fixed_string_t on_off; 12163 }; 12164 12165 /* Common CLI fields for VF multicast promiscuous mode enable disable */ 12166 cmdline_parse_token_string_t cmd_vf_allmulti_set = 12167 TOKEN_STRING_INITIALIZER 12168 (struct cmd_vf_allmulti_result, 12169 set, "set"); 12170 cmdline_parse_token_string_t cmd_vf_allmulti_vf = 12171 TOKEN_STRING_INITIALIZER 12172 (struct cmd_vf_allmulti_result, 12173 vf, "vf"); 12174 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = 12175 TOKEN_STRING_INITIALIZER 12176 (struct cmd_vf_allmulti_result, 12177 allmulti, "allmulti"); 12178 cmdline_parse_token_num_t cmd_vf_allmulti_port_id = 12179 TOKEN_NUM_INITIALIZER 12180 (struct cmd_vf_allmulti_result, 12181 port_id, UINT8); 12182 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = 12183 TOKEN_NUM_INITIALIZER 12184 (struct cmd_vf_allmulti_result, 12185 vf_id, UINT32); 12186 cmdline_parse_token_string_t cmd_vf_allmulti_on_off = 12187 TOKEN_STRING_INITIALIZER 12188 (struct cmd_vf_allmulti_result, 12189 on_off, "on#off"); 12190 12191 static void 12192 cmd_set_vf_allmulti_parsed( 12193 void *parsed_result, 12194 __attribute__((unused)) struct cmdline *cl, 12195 __attribute__((unused)) void *data) 12196 { 12197 struct cmd_vf_allmulti_result *res = parsed_result; 12198 int ret = -ENOTSUP; 12199 12200 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12201 12202 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12203 return; 12204 12205 #ifdef RTE_LIBRTE_I40E_PMD 12206 ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id, 12207 res->vf_id, is_on); 12208 #endif 12209 12210 switch (ret) { 12211 case 0: 12212 break; 12213 case -EINVAL: 12214 printf("invalid vf_id %d\n", res->vf_id); 12215 break; 12216 case -ENODEV: 12217 printf("invalid port_id %d\n", res->port_id); 12218 break; 12219 case -ENOTSUP: 12220 printf("function not implemented\n"); 12221 break; 12222 default: 12223 printf("programming error: (%s)\n", strerror(-ret)); 12224 } 12225 } 12226 12227 cmdline_parse_inst_t cmd_set_vf_allmulti = { 12228 .f = cmd_set_vf_allmulti_parsed, 12229 .data = NULL, 12230 .help_str = "set vf allmulti <port_id> <vf_id> on|off: " 12231 "Set multicast promiscuous mode for a VF from the PF", 12232 .tokens = { 12233 (void *)&cmd_vf_allmulti_set, 12234 (void *)&cmd_vf_allmulti_vf, 12235 (void *)&cmd_vf_allmulti_allmulti, 12236 (void *)&cmd_vf_allmulti_port_id, 12237 (void *)&cmd_vf_allmulti_vf_id, 12238 (void *)&cmd_vf_allmulti_on_off, 12239 NULL, 12240 }, 12241 }; 12242 12243 /* vf broadcast mode configuration */ 12244 12245 /* Common result structure for vf broadcast */ 12246 struct cmd_set_vf_broadcast_result { 12247 cmdline_fixed_string_t set; 12248 cmdline_fixed_string_t vf; 12249 cmdline_fixed_string_t broadcast; 12250 uint8_t port_id; 12251 uint16_t vf_id; 12252 cmdline_fixed_string_t on_off; 12253 }; 12254 12255 /* Common CLI fields for vf broadcast enable disable */ 12256 cmdline_parse_token_string_t cmd_set_vf_broadcast_set = 12257 TOKEN_STRING_INITIALIZER 12258 (struct cmd_set_vf_broadcast_result, 12259 set, "set"); 12260 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf = 12261 TOKEN_STRING_INITIALIZER 12262 (struct cmd_set_vf_broadcast_result, 12263 vf, "vf"); 12264 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = 12265 TOKEN_STRING_INITIALIZER 12266 (struct cmd_set_vf_broadcast_result, 12267 broadcast, "broadcast"); 12268 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = 12269 TOKEN_NUM_INITIALIZER 12270 (struct cmd_set_vf_broadcast_result, 12271 port_id, UINT8); 12272 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = 12273 TOKEN_NUM_INITIALIZER 12274 (struct cmd_set_vf_broadcast_result, 12275 vf_id, UINT16); 12276 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off = 12277 TOKEN_STRING_INITIALIZER 12278 (struct cmd_set_vf_broadcast_result, 12279 on_off, "on#off"); 12280 12281 static void 12282 cmd_set_vf_broadcast_parsed( 12283 void *parsed_result, 12284 __attribute__((unused)) struct cmdline *cl, 12285 __attribute__((unused)) void *data) 12286 { 12287 struct cmd_set_vf_broadcast_result *res = parsed_result; 12288 int ret = -ENOTSUP; 12289 12290 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12291 12292 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12293 return; 12294 12295 #ifdef RTE_LIBRTE_I40E_PMD 12296 ret = rte_pmd_i40e_set_vf_broadcast(res->port_id, 12297 res->vf_id, is_on); 12298 #endif 12299 12300 switch (ret) { 12301 case 0: 12302 break; 12303 case -EINVAL: 12304 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12305 break; 12306 case -ENODEV: 12307 printf("invalid port_id %d\n", res->port_id); 12308 break; 12309 case -ENOTSUP: 12310 printf("function not implemented\n"); 12311 break; 12312 default: 12313 printf("programming error: (%s)\n", strerror(-ret)); 12314 } 12315 } 12316 12317 cmdline_parse_inst_t cmd_set_vf_broadcast = { 12318 .f = cmd_set_vf_broadcast_parsed, 12319 .data = NULL, 12320 .help_str = "set vf broadcast <port_id> <vf_id> on|off", 12321 .tokens = { 12322 (void *)&cmd_set_vf_broadcast_set, 12323 (void *)&cmd_set_vf_broadcast_vf, 12324 (void *)&cmd_set_vf_broadcast_broadcast, 12325 (void *)&cmd_set_vf_broadcast_port_id, 12326 (void *)&cmd_set_vf_broadcast_vf_id, 12327 (void *)&cmd_set_vf_broadcast_on_off, 12328 NULL, 12329 }, 12330 }; 12331 12332 /* vf vlan tag configuration */ 12333 12334 /* Common result structure for vf vlan tag */ 12335 struct cmd_set_vf_vlan_tag_result { 12336 cmdline_fixed_string_t set; 12337 cmdline_fixed_string_t vf; 12338 cmdline_fixed_string_t vlan; 12339 cmdline_fixed_string_t tag; 12340 uint8_t port_id; 12341 uint16_t vf_id; 12342 cmdline_fixed_string_t on_off; 12343 }; 12344 12345 /* Common CLI fields for vf vlan tag enable disable */ 12346 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set = 12347 TOKEN_STRING_INITIALIZER 12348 (struct cmd_set_vf_vlan_tag_result, 12349 set, "set"); 12350 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf = 12351 TOKEN_STRING_INITIALIZER 12352 (struct cmd_set_vf_vlan_tag_result, 12353 vf, "vf"); 12354 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan = 12355 TOKEN_STRING_INITIALIZER 12356 (struct cmd_set_vf_vlan_tag_result, 12357 vlan, "vlan"); 12358 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = 12359 TOKEN_STRING_INITIALIZER 12360 (struct cmd_set_vf_vlan_tag_result, 12361 tag, "tag"); 12362 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = 12363 TOKEN_NUM_INITIALIZER 12364 (struct cmd_set_vf_vlan_tag_result, 12365 port_id, UINT8); 12366 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = 12367 TOKEN_NUM_INITIALIZER 12368 (struct cmd_set_vf_vlan_tag_result, 12369 vf_id, UINT16); 12370 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off = 12371 TOKEN_STRING_INITIALIZER 12372 (struct cmd_set_vf_vlan_tag_result, 12373 on_off, "on#off"); 12374 12375 static void 12376 cmd_set_vf_vlan_tag_parsed( 12377 void *parsed_result, 12378 __attribute__((unused)) struct cmdline *cl, 12379 __attribute__((unused)) void *data) 12380 { 12381 struct cmd_set_vf_vlan_tag_result *res = parsed_result; 12382 int ret = -ENOTSUP; 12383 12384 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12385 12386 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12387 return; 12388 12389 #ifdef RTE_LIBRTE_I40E_PMD 12390 ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id, 12391 res->vf_id, is_on); 12392 #endif 12393 12394 switch (ret) { 12395 case 0: 12396 break; 12397 case -EINVAL: 12398 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12399 break; 12400 case -ENODEV: 12401 printf("invalid port_id %d\n", res->port_id); 12402 break; 12403 case -ENOTSUP: 12404 printf("function not implemented\n"); 12405 break; 12406 default: 12407 printf("programming error: (%s)\n", strerror(-ret)); 12408 } 12409 } 12410 12411 cmdline_parse_inst_t cmd_set_vf_vlan_tag = { 12412 .f = cmd_set_vf_vlan_tag_parsed, 12413 .data = NULL, 12414 .help_str = "set vf vlan tag <port_id> <vf_id> on|off", 12415 .tokens = { 12416 (void *)&cmd_set_vf_vlan_tag_set, 12417 (void *)&cmd_set_vf_vlan_tag_vf, 12418 (void *)&cmd_set_vf_vlan_tag_vlan, 12419 (void *)&cmd_set_vf_vlan_tag_tag, 12420 (void *)&cmd_set_vf_vlan_tag_port_id, 12421 (void *)&cmd_set_vf_vlan_tag_vf_id, 12422 (void *)&cmd_set_vf_vlan_tag_on_off, 12423 NULL, 12424 }, 12425 }; 12426 12427 /* Common definition of VF and TC TX bandwidth configuration */ 12428 struct cmd_vf_tc_bw_result { 12429 cmdline_fixed_string_t set; 12430 cmdline_fixed_string_t vf; 12431 cmdline_fixed_string_t tc; 12432 cmdline_fixed_string_t tx; 12433 cmdline_fixed_string_t min_bw; 12434 cmdline_fixed_string_t max_bw; 12435 cmdline_fixed_string_t strict_link_prio; 12436 uint8_t port_id; 12437 uint16_t vf_id; 12438 uint8_t tc_no; 12439 uint32_t bw; 12440 cmdline_fixed_string_t bw_list; 12441 uint8_t tc_map; 12442 }; 12443 12444 cmdline_parse_token_string_t cmd_vf_tc_bw_set = 12445 TOKEN_STRING_INITIALIZER 12446 (struct cmd_vf_tc_bw_result, 12447 set, "set"); 12448 cmdline_parse_token_string_t cmd_vf_tc_bw_vf = 12449 TOKEN_STRING_INITIALIZER 12450 (struct cmd_vf_tc_bw_result, 12451 vf, "vf"); 12452 cmdline_parse_token_string_t cmd_vf_tc_bw_tc = 12453 TOKEN_STRING_INITIALIZER 12454 (struct cmd_vf_tc_bw_result, 12455 tc, "tc"); 12456 cmdline_parse_token_string_t cmd_vf_tc_bw_tx = 12457 TOKEN_STRING_INITIALIZER 12458 (struct cmd_vf_tc_bw_result, 12459 tx, "tx"); 12460 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio = 12461 TOKEN_STRING_INITIALIZER 12462 (struct cmd_vf_tc_bw_result, 12463 strict_link_prio, "strict-link-priority"); 12464 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = 12465 TOKEN_STRING_INITIALIZER 12466 (struct cmd_vf_tc_bw_result, 12467 min_bw, "min-bandwidth"); 12468 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw = 12469 TOKEN_STRING_INITIALIZER 12470 (struct cmd_vf_tc_bw_result, 12471 max_bw, "max-bandwidth"); 12472 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = 12473 TOKEN_NUM_INITIALIZER 12474 (struct cmd_vf_tc_bw_result, 12475 port_id, UINT8); 12476 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id = 12477 TOKEN_NUM_INITIALIZER 12478 (struct cmd_vf_tc_bw_result, 12479 vf_id, UINT16); 12480 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no = 12481 TOKEN_NUM_INITIALIZER 12482 (struct cmd_vf_tc_bw_result, 12483 tc_no, UINT8); 12484 cmdline_parse_token_num_t cmd_vf_tc_bw_bw = 12485 TOKEN_NUM_INITIALIZER 12486 (struct cmd_vf_tc_bw_result, 12487 bw, UINT32); 12488 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = 12489 TOKEN_STRING_INITIALIZER 12490 (struct cmd_vf_tc_bw_result, 12491 bw_list, NULL); 12492 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map = 12493 TOKEN_NUM_INITIALIZER 12494 (struct cmd_vf_tc_bw_result, 12495 tc_map, UINT8); 12496 12497 /* VF max bandwidth setting */ 12498 static void 12499 cmd_vf_max_bw_parsed( 12500 void *parsed_result, 12501 __attribute__((unused)) struct cmdline *cl, 12502 __attribute__((unused)) void *data) 12503 { 12504 struct cmd_vf_tc_bw_result *res = parsed_result; 12505 int ret = -ENOTSUP; 12506 12507 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12508 return; 12509 12510 #ifdef RTE_LIBRTE_I40E_PMD 12511 ret = rte_pmd_i40e_set_vf_max_bw(res->port_id, 12512 res->vf_id, res->bw); 12513 #endif 12514 12515 switch (ret) { 12516 case 0: 12517 break; 12518 case -EINVAL: 12519 printf("invalid vf_id %d or bandwidth %d\n", 12520 res->vf_id, res->bw); 12521 break; 12522 case -ENODEV: 12523 printf("invalid port_id %d\n", res->port_id); 12524 break; 12525 case -ENOTSUP: 12526 printf("function not implemented\n"); 12527 break; 12528 default: 12529 printf("programming error: (%s)\n", strerror(-ret)); 12530 } 12531 } 12532 12533 cmdline_parse_inst_t cmd_vf_max_bw = { 12534 .f = cmd_vf_max_bw_parsed, 12535 .data = NULL, 12536 .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>", 12537 .tokens = { 12538 (void *)&cmd_vf_tc_bw_set, 12539 (void *)&cmd_vf_tc_bw_vf, 12540 (void *)&cmd_vf_tc_bw_tx, 12541 (void *)&cmd_vf_tc_bw_max_bw, 12542 (void *)&cmd_vf_tc_bw_port_id, 12543 (void *)&cmd_vf_tc_bw_vf_id, 12544 (void *)&cmd_vf_tc_bw_bw, 12545 NULL, 12546 }, 12547 }; 12548 12549 static int 12550 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, 12551 uint8_t *tc_num, 12552 char *str) 12553 { 12554 uint32_t size; 12555 const char *p, *p0 = str; 12556 char s[256]; 12557 char *end; 12558 char *str_fld[16]; 12559 uint16_t i; 12560 int ret; 12561 12562 p = strchr(p0, '('); 12563 if (p == NULL) { 12564 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 12565 return -1; 12566 } 12567 p++; 12568 p0 = strchr(p, ')'); 12569 if (p0 == NULL) { 12570 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 12571 return -1; 12572 } 12573 size = p0 - p; 12574 if (size >= sizeof(s)) { 12575 printf("The string size exceeds the internal buffer size\n"); 12576 return -1; 12577 } 12578 snprintf(s, sizeof(s), "%.*s", size, p); 12579 ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); 12580 if (ret <= 0) { 12581 printf("Failed to get the bandwidth list. "); 12582 return -1; 12583 } 12584 *tc_num = ret; 12585 for (i = 0; i < ret; i++) 12586 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); 12587 12588 return 0; 12589 } 12590 12591 /* TC min bandwidth setting */ 12592 static void 12593 cmd_vf_tc_min_bw_parsed( 12594 void *parsed_result, 12595 __attribute__((unused)) struct cmdline *cl, 12596 __attribute__((unused)) void *data) 12597 { 12598 struct cmd_vf_tc_bw_result *res = parsed_result; 12599 uint8_t tc_num; 12600 uint8_t bw[16]; 12601 int ret = -ENOTSUP; 12602 12603 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12604 return; 12605 12606 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 12607 if (ret) 12608 return; 12609 12610 #ifdef RTE_LIBRTE_I40E_PMD 12611 ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id, 12612 tc_num, bw); 12613 #endif 12614 12615 switch (ret) { 12616 case 0: 12617 break; 12618 case -EINVAL: 12619 printf("invalid vf_id %d or bandwidth\n", res->vf_id); 12620 break; 12621 case -ENODEV: 12622 printf("invalid port_id %d\n", res->port_id); 12623 break; 12624 case -ENOTSUP: 12625 printf("function not implemented\n"); 12626 break; 12627 default: 12628 printf("programming error: (%s)\n", strerror(-ret)); 12629 } 12630 } 12631 12632 cmdline_parse_inst_t cmd_vf_tc_min_bw = { 12633 .f = cmd_vf_tc_min_bw_parsed, 12634 .data = NULL, 12635 .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>" 12636 " <bw1, bw2, ...>", 12637 .tokens = { 12638 (void *)&cmd_vf_tc_bw_set, 12639 (void *)&cmd_vf_tc_bw_vf, 12640 (void *)&cmd_vf_tc_bw_tc, 12641 (void *)&cmd_vf_tc_bw_tx, 12642 (void *)&cmd_vf_tc_bw_min_bw, 12643 (void *)&cmd_vf_tc_bw_port_id, 12644 (void *)&cmd_vf_tc_bw_vf_id, 12645 (void *)&cmd_vf_tc_bw_bw_list, 12646 NULL, 12647 }, 12648 }; 12649 12650 static void 12651 cmd_tc_min_bw_parsed( 12652 void *parsed_result, 12653 __attribute__((unused)) struct cmdline *cl, 12654 __attribute__((unused)) void *data) 12655 { 12656 struct cmd_vf_tc_bw_result *res = parsed_result; 12657 struct rte_port *port; 12658 uint8_t tc_num; 12659 uint8_t bw[16]; 12660 int ret = -ENOTSUP; 12661 12662 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12663 return; 12664 12665 port = &ports[res->port_id]; 12666 /** Check if the port is not started **/ 12667 if (port->port_status != RTE_PORT_STOPPED) { 12668 printf("Please stop port %d first\n", res->port_id); 12669 return; 12670 } 12671 12672 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 12673 if (ret) 12674 return; 12675 12676 #ifdef RTE_LIBRTE_IXGBE_PMD 12677 ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); 12678 #endif 12679 12680 switch (ret) { 12681 case 0: 12682 break; 12683 case -EINVAL: 12684 printf("invalid bandwidth\n"); 12685 break; 12686 case -ENODEV: 12687 printf("invalid port_id %d\n", res->port_id); 12688 break; 12689 case -ENOTSUP: 12690 printf("function not implemented\n"); 12691 break; 12692 default: 12693 printf("programming error: (%s)\n", strerror(-ret)); 12694 } 12695 } 12696 12697 cmdline_parse_inst_t cmd_tc_min_bw = { 12698 .f = cmd_tc_min_bw_parsed, 12699 .data = NULL, 12700 .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>", 12701 .tokens = { 12702 (void *)&cmd_vf_tc_bw_set, 12703 (void *)&cmd_vf_tc_bw_tc, 12704 (void *)&cmd_vf_tc_bw_tx, 12705 (void *)&cmd_vf_tc_bw_min_bw, 12706 (void *)&cmd_vf_tc_bw_port_id, 12707 (void *)&cmd_vf_tc_bw_bw_list, 12708 NULL, 12709 }, 12710 }; 12711 12712 /* TC max bandwidth setting */ 12713 static void 12714 cmd_vf_tc_max_bw_parsed( 12715 void *parsed_result, 12716 __attribute__((unused)) struct cmdline *cl, 12717 __attribute__((unused)) void *data) 12718 { 12719 struct cmd_vf_tc_bw_result *res = parsed_result; 12720 int ret = -ENOTSUP; 12721 12722 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12723 return; 12724 12725 #ifdef RTE_LIBRTE_I40E_PMD 12726 ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id, 12727 res->tc_no, res->bw); 12728 #endif 12729 12730 switch (ret) { 12731 case 0: 12732 break; 12733 case -EINVAL: 12734 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n", 12735 res->vf_id, res->tc_no, res->bw); 12736 break; 12737 case -ENODEV: 12738 printf("invalid port_id %d\n", res->port_id); 12739 break; 12740 case -ENOTSUP: 12741 printf("function not implemented\n"); 12742 break; 12743 default: 12744 printf("programming error: (%s)\n", strerror(-ret)); 12745 } 12746 } 12747 12748 cmdline_parse_inst_t cmd_vf_tc_max_bw = { 12749 .f = cmd_vf_tc_max_bw_parsed, 12750 .data = NULL, 12751 .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>" 12752 " <bandwidth>", 12753 .tokens = { 12754 (void *)&cmd_vf_tc_bw_set, 12755 (void *)&cmd_vf_tc_bw_vf, 12756 (void *)&cmd_vf_tc_bw_tc, 12757 (void *)&cmd_vf_tc_bw_tx, 12758 (void *)&cmd_vf_tc_bw_max_bw, 12759 (void *)&cmd_vf_tc_bw_port_id, 12760 (void *)&cmd_vf_tc_bw_vf_id, 12761 (void *)&cmd_vf_tc_bw_tc_no, 12762 (void *)&cmd_vf_tc_bw_bw, 12763 NULL, 12764 }, 12765 }; 12766 12767 /* Strict link priority scheduling mode setting */ 12768 static void 12769 cmd_strict_link_prio_parsed( 12770 void *parsed_result, 12771 __attribute__((unused)) struct cmdline *cl, 12772 __attribute__((unused)) void *data) 12773 { 12774 struct cmd_vf_tc_bw_result *res = parsed_result; 12775 int ret = -ENOTSUP; 12776 12777 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12778 return; 12779 12780 #ifdef RTE_LIBRTE_I40E_PMD 12781 ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map); 12782 #endif 12783 12784 switch (ret) { 12785 case 0: 12786 break; 12787 case -EINVAL: 12788 printf("invalid tc_bitmap 0x%x\n", res->tc_map); 12789 break; 12790 case -ENODEV: 12791 printf("invalid port_id %d\n", res->port_id); 12792 break; 12793 case -ENOTSUP: 12794 printf("function not implemented\n"); 12795 break; 12796 default: 12797 printf("programming error: (%s)\n", strerror(-ret)); 12798 } 12799 } 12800 12801 cmdline_parse_inst_t cmd_strict_link_prio = { 12802 .f = cmd_strict_link_prio_parsed, 12803 .data = NULL, 12804 .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>", 12805 .tokens = { 12806 (void *)&cmd_vf_tc_bw_set, 12807 (void *)&cmd_vf_tc_bw_tx, 12808 (void *)&cmd_vf_tc_bw_strict_link_prio, 12809 (void *)&cmd_vf_tc_bw_port_id, 12810 (void *)&cmd_vf_tc_bw_tc_map, 12811 NULL, 12812 }, 12813 }; 12814 12815 /* Load dynamic device personalization*/ 12816 struct cmd_ddp_add_result { 12817 cmdline_fixed_string_t ddp; 12818 cmdline_fixed_string_t add; 12819 uint8_t port_id; 12820 char filepath[]; 12821 }; 12822 12823 cmdline_parse_token_string_t cmd_ddp_add_ddp = 12824 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp"); 12825 cmdline_parse_token_string_t cmd_ddp_add_add = 12826 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add"); 12827 cmdline_parse_token_num_t cmd_ddp_add_port_id = 12828 TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8); 12829 cmdline_parse_token_string_t cmd_ddp_add_filepath = 12830 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL); 12831 12832 static void 12833 cmd_ddp_add_parsed( 12834 void *parsed_result, 12835 __attribute__((unused)) struct cmdline *cl, 12836 __attribute__((unused)) void *data) 12837 { 12838 struct cmd_ddp_add_result *res = parsed_result; 12839 uint8_t *buff; 12840 uint32_t size; 12841 int ret = -ENOTSUP; 12842 12843 if (res->port_id > nb_ports) { 12844 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 12845 return; 12846 } 12847 12848 if (!all_ports_stopped()) { 12849 printf("Please stop all ports first\n"); 12850 return; 12851 } 12852 12853 buff = open_ddp_package_file(res->filepath, &size); 12854 if (!buff) 12855 return; 12856 12857 #ifdef RTE_LIBRTE_I40E_PMD 12858 if (ret == -ENOTSUP) 12859 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 12860 buff, size, 12861 RTE_PMD_I40E_PKG_OP_WR_ADD); 12862 #endif 12863 12864 if (ret < 0) 12865 printf("Failed to load profile.\n"); 12866 else if (ret > 0) 12867 printf("Profile has already existed.\n"); 12868 12869 close_ddp_package_file(buff); 12870 } 12871 12872 cmdline_parse_inst_t cmd_ddp_add = { 12873 .f = cmd_ddp_add_parsed, 12874 .data = NULL, 12875 .help_str = "ddp add <port_id> <profile_path>", 12876 .tokens = { 12877 (void *)&cmd_ddp_add_ddp, 12878 (void *)&cmd_ddp_add_add, 12879 (void *)&cmd_ddp_add_port_id, 12880 (void *)&cmd_ddp_add_filepath, 12881 NULL, 12882 }, 12883 }; 12884 12885 /* Get dynamic device personalization profile info list*/ 12886 #define PROFILE_INFO_SIZE 48 12887 #define MAX_PROFILE_NUM 16 12888 12889 struct cmd_ddp_get_list_result { 12890 cmdline_fixed_string_t ddp; 12891 cmdline_fixed_string_t get; 12892 cmdline_fixed_string_t list; 12893 uint8_t port_id; 12894 }; 12895 12896 cmdline_parse_token_string_t cmd_ddp_get_list_ddp = 12897 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp"); 12898 cmdline_parse_token_string_t cmd_ddp_get_list_get = 12899 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get"); 12900 cmdline_parse_token_string_t cmd_ddp_get_list_list = 12901 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list"); 12902 cmdline_parse_token_num_t cmd_ddp_get_list_port_id = 12903 TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8); 12904 12905 static void 12906 cmd_ddp_get_list_parsed( 12907 void *parsed_result, 12908 __attribute__((unused)) struct cmdline *cl, 12909 __attribute__((unused)) void *data) 12910 { 12911 struct cmd_ddp_get_list_result *res = parsed_result; 12912 #ifdef RTE_LIBRTE_I40E_PMD 12913 struct rte_pmd_i40e_profile_list *p_list; 12914 struct rte_pmd_i40e_profile_info *p_info; 12915 uint32_t p_num; 12916 uint32_t size; 12917 uint32_t i; 12918 #endif 12919 int ret = -ENOTSUP; 12920 12921 if (res->port_id > nb_ports) { 12922 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 12923 return; 12924 } 12925 12926 #ifdef RTE_LIBRTE_I40E_PMD 12927 size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4; 12928 p_list = (struct rte_pmd_i40e_profile_list *)malloc(size); 12929 if (!p_list) 12930 printf("%s: Failed to malloc buffer\n", __func__); 12931 12932 if (ret == -ENOTSUP) 12933 ret = rte_pmd_i40e_get_ddp_list(res->port_id, 12934 (uint8_t *)p_list, size); 12935 12936 if (!ret) { 12937 p_num = p_list->p_count; 12938 printf("Profile number is: %d\n\n", p_num); 12939 12940 for (i = 0; i < p_num; i++) { 12941 p_info = &p_list->p_info[i]; 12942 printf("Profile %d:\n", i); 12943 printf("Track id: 0x%x\n", p_info->track_id); 12944 printf("Version: %d.%d.%d.%d\n", 12945 p_info->version.major, 12946 p_info->version.minor, 12947 p_info->version.update, 12948 p_info->version.draft); 12949 printf("Profile name: %s\n\n", p_info->name); 12950 } 12951 } 12952 12953 free(p_list); 12954 #endif 12955 12956 if (ret < 0) 12957 printf("Failed to get ddp list\n"); 12958 } 12959 12960 cmdline_parse_inst_t cmd_ddp_get_list = { 12961 .f = cmd_ddp_get_list_parsed, 12962 .data = NULL, 12963 .help_str = "ddp get list <port_id>", 12964 .tokens = { 12965 (void *)&cmd_ddp_get_list_ddp, 12966 (void *)&cmd_ddp_get_list_get, 12967 (void *)&cmd_ddp_get_list_list, 12968 (void *)&cmd_ddp_get_list_port_id, 12969 NULL, 12970 }, 12971 }; 12972 /* ******************************************************************************** */ 12973 12974 /* list of instructions */ 12975 cmdline_parse_ctx_t main_ctx[] = { 12976 (cmdline_parse_inst_t *)&cmd_help_brief, 12977 (cmdline_parse_inst_t *)&cmd_help_long, 12978 (cmdline_parse_inst_t *)&cmd_quit, 12979 (cmdline_parse_inst_t *)&cmd_showport, 12980 (cmdline_parse_inst_t *)&cmd_showqueue, 12981 (cmdline_parse_inst_t *)&cmd_showportall, 12982 (cmdline_parse_inst_t *)&cmd_showcfg, 12983 (cmdline_parse_inst_t *)&cmd_start, 12984 (cmdline_parse_inst_t *)&cmd_start_tx_first, 12985 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 12986 (cmdline_parse_inst_t *)&cmd_set_link_up, 12987 (cmdline_parse_inst_t *)&cmd_set_link_down, 12988 (cmdline_parse_inst_t *)&cmd_reset, 12989 (cmdline_parse_inst_t *)&cmd_set_numbers, 12990 (cmdline_parse_inst_t *)&cmd_set_txpkts, 12991 (cmdline_parse_inst_t *)&cmd_set_txsplit, 12992 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 12993 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 12994 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 12995 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 12996 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 12997 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 12998 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 12999 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 13000 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 13001 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 13002 (cmdline_parse_inst_t *)&cmd_set_link_check, 13003 #ifdef RTE_NIC_BYPASS 13004 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 13005 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 13006 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 13007 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 13008 #endif 13009 #ifdef RTE_LIBRTE_PMD_BOND 13010 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 13011 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 13012 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 13013 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 13014 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 13015 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 13016 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 13017 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 13018 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 13019 #endif 13020 (cmdline_parse_inst_t *)&cmd_vlan_offload, 13021 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 13022 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 13023 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 13024 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 13025 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 13026 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 13027 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 13028 (cmdline_parse_inst_t *)&cmd_csum_set, 13029 (cmdline_parse_inst_t *)&cmd_csum_show, 13030 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 13031 (cmdline_parse_inst_t *)&cmd_tso_set, 13032 (cmdline_parse_inst_t *)&cmd_tso_show, 13033 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 13034 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 13035 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 13036 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 13037 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 13038 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 13039 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 13040 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 13041 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 13042 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 13043 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 13044 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 13045 (cmdline_parse_inst_t *)&cmd_config_dcb, 13046 (cmdline_parse_inst_t *)&cmd_read_reg, 13047 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 13048 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 13049 (cmdline_parse_inst_t *)&cmd_write_reg, 13050 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 13051 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 13052 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 13053 (cmdline_parse_inst_t *)&cmd_stop, 13054 (cmdline_parse_inst_t *)&cmd_mac_addr, 13055 (cmdline_parse_inst_t *)&cmd_set_qmap, 13056 (cmdline_parse_inst_t *)&cmd_operate_port, 13057 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 13058 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 13059 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 13060 (cmdline_parse_inst_t *)&cmd_config_speed_all, 13061 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 13062 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 13063 (cmdline_parse_inst_t *)&cmd_config_mtu, 13064 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 13065 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 13066 (cmdline_parse_inst_t *)&cmd_config_rss, 13067 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 13068 (cmdline_parse_inst_t *)&cmd_config_txqflags, 13069 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 13070 (cmdline_parse_inst_t *)&cmd_showport_reta, 13071 (cmdline_parse_inst_t *)&cmd_config_burst, 13072 (cmdline_parse_inst_t *)&cmd_config_thresh, 13073 (cmdline_parse_inst_t *)&cmd_config_threshold, 13074 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 13075 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 13076 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 13077 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 13078 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 13079 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 13080 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 13081 (cmdline_parse_inst_t *)&cmd_global_config, 13082 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 13083 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 13084 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 13085 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 13086 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 13087 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 13088 (cmdline_parse_inst_t *)&cmd_dump, 13089 (cmdline_parse_inst_t *)&cmd_dump_one, 13090 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 13091 (cmdline_parse_inst_t *)&cmd_syn_filter, 13092 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 13093 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 13094 (cmdline_parse_inst_t *)&cmd_flex_filter, 13095 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 13096 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 13097 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 13098 (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director, 13099 (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director, 13100 (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director, 13101 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 13102 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 13103 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 13104 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 13105 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 13106 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 13107 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 13108 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 13109 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 13110 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 13111 (cmdline_parse_inst_t *)&cmd_set_hash_input_set, 13112 (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, 13113 (cmdline_parse_inst_t *)&cmd_flow, 13114 (cmdline_parse_inst_t *)&cmd_mcast_addr, 13115 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, 13116 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, 13117 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all, 13118 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific, 13119 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en, 13120 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis, 13121 (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis, 13122 (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis, 13123 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add, 13124 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del, 13125 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 13126 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 13127 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 13128 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 13129 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 13130 #ifdef RTE_LIBRTE_IXGBE_PMD 13131 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 13132 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 13133 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 13134 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 13135 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 13136 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 13137 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 13138 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 13139 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 13140 #endif 13141 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 13142 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 13143 (cmdline_parse_inst_t *)&cmd_set_vf_promisc, 13144 (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, 13145 (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, 13146 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, 13147 (cmdline_parse_inst_t *)&cmd_vf_max_bw, 13148 (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw, 13149 (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, 13150 (cmdline_parse_inst_t *)&cmd_strict_link_prio, 13151 (cmdline_parse_inst_t *)&cmd_tc_min_bw, 13152 (cmdline_parse_inst_t *)&cmd_ddp_add, 13153 (cmdline_parse_inst_t *)&cmd_ddp_get_list, 13154 NULL, 13155 }; 13156 13157 /* prompt function, called from main on MASTER lcore */ 13158 void 13159 prompt(void) 13160 { 13161 /* initialize non-constant commands */ 13162 cmd_set_fwd_mode_init(); 13163 cmd_set_fwd_retry_mode_init(); 13164 13165 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 13166 if (testpmd_cl == NULL) 13167 return; 13168 cmdline_interact(testpmd_cl); 13169 cmdline_stdin_exit(testpmd_cl); 13170 } 13171 13172 void 13173 prompt_exit(void) 13174 { 13175 if (testpmd_cl != NULL) 13176 cmdline_quit(testpmd_cl); 13177 } 13178 13179 static void 13180 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 13181 { 13182 if (id == (portid_t)RTE_PORT_ALL) { 13183 portid_t pid; 13184 13185 FOREACH_PORT(pid, ports) { 13186 /* check if need_reconfig has been set to 1 */ 13187 if (ports[pid].need_reconfig == 0) 13188 ports[pid].need_reconfig = dev; 13189 /* check if need_reconfig_queues has been set to 1 */ 13190 if (ports[pid].need_reconfig_queues == 0) 13191 ports[pid].need_reconfig_queues = queue; 13192 } 13193 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 13194 /* check if need_reconfig has been set to 1 */ 13195 if (ports[id].need_reconfig == 0) 13196 ports[id].need_reconfig = dev; 13197 /* check if need_reconfig_queues has been set to 1 */ 13198 if (ports[id].need_reconfig_queues == 0) 13199 ports[id].need_reconfig_queues = queue; 13200 } 13201 } 13202