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 <string.h> 40 #include <termios.h> 41 #include <unistd.h> 42 #include <inttypes.h> 43 #ifndef __linux__ 44 #ifndef __FreeBSD__ 45 #include <net/socket.h> 46 #else 47 #include <sys/socket.h> 48 #endif 49 #endif 50 #include <netinet/in.h> 51 52 #include <sys/queue.h> 53 54 #include <rte_common.h> 55 #include <rte_byteorder.h> 56 #include <rte_log.h> 57 #include <rte_debug.h> 58 #include <rte_cycles.h> 59 #include <rte_memory.h> 60 #include <rte_memzone.h> 61 #include <rte_malloc.h> 62 #include <rte_launch.h> 63 #include <rte_eal.h> 64 #include <rte_per_lcore.h> 65 #include <rte_lcore.h> 66 #include <rte_atomic.h> 67 #include <rte_branch_prediction.h> 68 #include <rte_ring.h> 69 #include <rte_mempool.h> 70 #include <rte_interrupts.h> 71 #include <rte_pci.h> 72 #include <rte_ether.h> 73 #include <rte_ethdev.h> 74 #include <rte_string_fns.h> 75 #include <rte_devargs.h> 76 #include <rte_eth_ctrl.h> 77 #include <rte_flow.h> 78 #include <rte_gro.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 #include <rte_eth_bond_8023ad.h> 91 #endif 92 #ifdef RTE_LIBRTE_IXGBE_PMD 93 #include <rte_pmd_ixgbe.h> 94 #endif 95 #ifdef RTE_LIBRTE_I40E_PMD 96 #include <rte_pmd_i40e.h> 97 #endif 98 #ifdef RTE_LIBRTE_BNXT_PMD 99 #include <rte_pmd_bnxt.h> 100 #endif 101 #include "testpmd.h" 102 103 static struct cmdline *testpmd_cl; 104 105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 106 107 /* *** Help command with introduction. *** */ 108 struct cmd_help_brief_result { 109 cmdline_fixed_string_t help; 110 }; 111 112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 113 struct cmdline *cl, 114 __attribute__((unused)) void *data) 115 { 116 cmdline_printf( 117 cl, 118 "\n" 119 "Help is available for the following sections:\n\n" 120 " help control : Start and stop forwarding.\n" 121 " help display : Displaying port, stats and config " 122 "information.\n" 123 " help config : Configuration information.\n" 124 " help ports : Configuring ports.\n" 125 " help registers : Reading and setting port registers.\n" 126 " help filters : Filters configuration help.\n" 127 " help all : All of the above sections.\n\n" 128 ); 129 130 } 131 132 cmdline_parse_token_string_t cmd_help_brief_help = 133 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 134 135 cmdline_parse_inst_t cmd_help_brief = { 136 .f = cmd_help_brief_parsed, 137 .data = NULL, 138 .help_str = "help: Show help", 139 .tokens = { 140 (void *)&cmd_help_brief_help, 141 NULL, 142 }, 143 }; 144 145 /* *** Help command with help sections. *** */ 146 struct cmd_help_long_result { 147 cmdline_fixed_string_t help; 148 cmdline_fixed_string_t section; 149 }; 150 151 static void cmd_help_long_parsed(void *parsed_result, 152 struct cmdline *cl, 153 __attribute__((unused)) void *data) 154 { 155 int show_all = 0; 156 struct cmd_help_long_result *res = parsed_result; 157 158 if (!strcmp(res->section, "all")) 159 show_all = 1; 160 161 if (show_all || !strcmp(res->section, "control")) { 162 163 cmdline_printf( 164 cl, 165 "\n" 166 "Control forwarding:\n" 167 "-------------------\n\n" 168 169 "start\n" 170 " Start packet forwarding with current configuration.\n\n" 171 172 "start tx_first\n" 173 " Start packet forwarding with current config" 174 " after sending one burst of packets.\n\n" 175 176 "stop\n" 177 " Stop packet forwarding, and display accumulated" 178 " statistics.\n\n" 179 180 "quit\n" 181 " Quit to prompt.\n\n" 182 ); 183 } 184 185 if (show_all || !strcmp(res->section, "display")) { 186 187 cmdline_printf( 188 cl, 189 "\n" 190 "Display:\n" 191 "--------\n\n" 192 193 "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n" 194 " Display information for port_id, or all.\n\n" 195 196 "show port X rss reta (size) (mask0,mask1,...)\n" 197 " Display the rss redirection table entry indicated" 198 " by masks on port X. size is used to indicate the" 199 " hardware supported reta size\n\n" 200 201 "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|" 202 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 203 "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n" 204 " Display the RSS hash functions and RSS hash key" 205 " of port X\n\n" 206 207 "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n" 208 " Clear information for port_id, or all.\n\n" 209 210 "show (rxq|txq) info (port_id) (queue_id)\n" 211 " Display information for configured RX/TX queue.\n\n" 212 213 "show config (rxtx|cores|fwd|txpkts)\n" 214 " Display the given configuration.\n\n" 215 216 "read rxd (port_id) (queue_id) (rxd_id)\n" 217 " Display an RX descriptor of a port RX queue.\n\n" 218 219 "read txd (port_id) (queue_id) (txd_id)\n" 220 " Display a TX descriptor of a port TX queue.\n\n" 221 222 "ddp get list (port_id)\n" 223 " Get ddp profile info list\n\n" 224 225 "ddp get info (profile_path)\n" 226 " Get ddp profile information.\n\n" 227 228 "show vf stats (port_id) (vf_id)\n" 229 " Display a VF's statistics.\n\n" 230 231 "clear vf stats (port_id) (vf_id)\n" 232 " Reset a VF's statistics.\n\n" 233 234 "show port (port_id) pctype mapping\n" 235 " Get flow ptype to pctype mapping on a port\n\n" 236 237 ); 238 } 239 240 if (show_all || !strcmp(res->section, "config")) { 241 cmdline_printf( 242 cl, 243 "\n" 244 "Configuration:\n" 245 "--------------\n" 246 "Configuration changes only become active when" 247 " forwarding is started/restarted.\n\n" 248 249 "set default\n" 250 " Reset forwarding to the default configuration.\n\n" 251 252 "set verbose (level)\n" 253 " Set the debug verbosity level X.\n\n" 254 255 "set nbport (num)\n" 256 " Set number of ports.\n\n" 257 258 "set nbcore (num)\n" 259 " Set number of cores.\n\n" 260 261 "set coremask (mask)\n" 262 " Set the forwarding cores hexadecimal mask.\n\n" 263 264 "set portmask (mask)\n" 265 " Set the forwarding ports hexadecimal mask.\n\n" 266 267 "set burst (num)\n" 268 " Set number of packets per burst.\n\n" 269 270 "set burst tx delay (microseconds) retry (num)\n" 271 " Set the transmit delay time and number of retries," 272 " effective when retry is enabled.\n\n" 273 274 "set txpkts (x[,y]*)\n" 275 " Set the length of each segment of TXONLY" 276 " and optionally CSUM packets.\n\n" 277 278 "set txsplit (off|on|rand)\n" 279 " Set the split policy for the TX packets." 280 " Right now only applicable for CSUM and TXONLY" 281 " modes\n\n" 282 283 "set corelist (x[,y]*)\n" 284 " Set the list of forwarding cores.\n\n" 285 286 "set portlist (x[,y]*)\n" 287 " Set the list of forwarding ports.\n\n" 288 289 "set tx loopback (port_id) (on|off)\n" 290 " Enable or disable tx loopback.\n\n" 291 292 "set all queues drop (port_id) (on|off)\n" 293 " Set drop enable bit for all queues.\n\n" 294 295 "set vf split drop (port_id) (vf_id) (on|off)\n" 296 " Set split drop enable bit for a VF from the PF.\n\n" 297 298 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 299 " Set MAC antispoof for a VF from the PF.\n\n" 300 301 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 302 " Enable MACsec offload.\n\n" 303 304 "set macsec offload (port_id) off\n" 305 " Disable MACsec offload.\n\n" 306 307 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 308 " Configure MACsec secure connection (SC).\n\n" 309 310 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 311 " Configure MACsec secure association (SA).\n\n" 312 313 "set vf broadcast (port_id) (vf_id) (on|off)\n" 314 " Set VF broadcast for a VF from the PF.\n\n" 315 316 "vlan set strip (on|off) (port_id)\n" 317 " Set the VLAN strip on a port.\n\n" 318 319 "vlan set stripq (on|off) (port_id,queue_id)\n" 320 " Set the VLAN strip for a queue on a port.\n\n" 321 322 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 323 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 324 325 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 326 " Set VLAN insert for a VF from the PF.\n\n" 327 328 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 329 " Set VLAN antispoof for a VF from the PF.\n\n" 330 331 "set vf vlan tag (port_id) (vf_id) (on|off)\n" 332 " Set VLAN tag for a VF from the PF.\n\n" 333 334 "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n" 335 " Set a VF's max bandwidth(Mbps).\n\n" 336 337 "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n" 338 " Set all TCs' min bandwidth(%%) on a VF.\n\n" 339 340 "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n" 341 " Set a TC's max bandwidth(Mbps) on a VF.\n\n" 342 343 "set tx strict-link-priority (port_id) (tc_bitmap)\n" 344 " Set some TCs' strict link priority mode on a physical port.\n\n" 345 346 "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" 347 " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" 348 349 "vlan set filter (on|off) (port_id)\n" 350 " Set the VLAN filter on a port.\n\n" 351 352 "vlan set qinq (on|off) (port_id)\n" 353 " Set the VLAN QinQ (extended queue in queue)" 354 " on a port.\n\n" 355 356 "vlan set (inner|outer) tpid (value) (port_id)\n" 357 " Set the VLAN TPID for Packet Filtering on" 358 " a port\n\n" 359 360 "rx_vlan add (vlan_id|all) (port_id)\n" 361 " Add a vlan_id, or all identifiers, to the set" 362 " of VLAN identifiers filtered by port_id.\n\n" 363 364 "rx_vlan rm (vlan_id|all) (port_id)\n" 365 " Remove a vlan_id, or all identifiers, from the set" 366 " of VLAN identifiers filtered by port_id.\n\n" 367 368 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 369 " Add a vlan_id, to the set of VLAN identifiers" 370 "filtered for VF(s) from port_id.\n\n" 371 372 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 373 " Remove a vlan_id, to the set of VLAN identifiers" 374 "filtered for VF(s) from port_id.\n\n" 375 376 "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) " 377 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 378 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 379 " add a tunnel filter of a port.\n\n" 380 381 "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) " 382 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 383 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 384 " remove a tunnel filter of a port.\n\n" 385 386 "rx_vxlan_port add (udp_port) (port_id)\n" 387 " Add an UDP port for VXLAN packet filter on a port\n\n" 388 389 "rx_vxlan_port rm (udp_port) (port_id)\n" 390 " Remove an UDP port for VXLAN packet filter on a port\n\n" 391 392 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 393 " Set hardware insertion of VLAN IDs (single or double VLAN " 394 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 395 396 "tx_vlan set pvid port_id vlan_id (on|off)\n" 397 " Set port based TX VLAN insertion.\n\n" 398 399 "tx_vlan reset (port_id)\n" 400 " Disable hardware insertion of a VLAN header in" 401 " packets sent on a port.\n\n" 402 403 "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n" 404 " Select hardware or software calculation of the" 405 " checksum when transmitting a packet using the" 406 " csum forward engine.\n" 407 " ip|udp|tcp|sctp always concern the inner layer.\n" 408 " outer-ip concerns the outer IP layer in" 409 " case the packet is recognized as a tunnel packet by" 410 " the forward engine (vxlan, gre and ipip are supported)\n" 411 " Please check the NIC datasheet for HW limits.\n\n" 412 413 "csum parse-tunnel (on|off) (tx_port_id)\n" 414 " If disabled, treat tunnel packets as non-tunneled" 415 " packets (treat inner headers as payload). The port\n" 416 " argument is the port used for TX in csum forward" 417 " engine.\n\n" 418 419 "csum show (port_id)\n" 420 " Display tx checksum offload configuration\n\n" 421 422 "tso set (segsize) (portid)\n" 423 " Enable TCP Segmentation Offload in csum forward" 424 " engine.\n" 425 " Please check the NIC datasheet for HW limits.\n\n" 426 427 "tso show (portid)" 428 " Display the status of TCP Segmentation Offload.\n\n" 429 430 "set port (port_id) gro on|off\n" 431 " Enable or disable Generic Receive Offload in" 432 " csum forwarding engine.\n\n" 433 434 "show port (port_id) gro\n" 435 " Display GRO configuration.\n\n" 436 437 "set gro flush (cycles)\n" 438 " Set the cycle to flush GROed packets from" 439 " reassembly tables.\n\n" 440 441 "set port (port_id) gso (on|off)" 442 " Enable or disable Generic Segmentation Offload in" 443 " csum forwarding engine.\n\n" 444 445 "set gso segsz (length)\n" 446 " Set max packet length for output GSO segments," 447 " including packet header and payload.\n\n" 448 449 "show port (port_id) gso\n" 450 " Show GSO configuration.\n\n" 451 452 "set fwd (%s)\n" 453 " Set packet forwarding mode.\n\n" 454 455 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 456 " Add a MAC address on port_id.\n\n" 457 458 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 459 " Remove a MAC address from port_id.\n\n" 460 461 "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n" 462 " Set the default MAC address for port_id.\n\n" 463 464 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 465 " Add a MAC address for a VF on the port.\n\n" 466 467 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 468 " Set the MAC address for a VF from the PF.\n\n" 469 470 "set port (port_id) uta (mac_address|all) (on|off)\n" 471 " Add/Remove a or all unicast hash filter(s)" 472 "from port X.\n\n" 473 474 "set promisc (port_id|all) (on|off)\n" 475 " Set the promiscuous mode on port_id, or all.\n\n" 476 477 "set allmulti (port_id|all) (on|off)\n" 478 " Set the allmulti mode on port_id, or all.\n\n" 479 480 "set vf promisc (port_id) (vf_id) (on|off)\n" 481 " Set unicast promiscuous mode for a VF from the PF.\n\n" 482 483 "set vf allmulti (port_id) (vf_id) (on|off)\n" 484 " Set multicast promiscuous mode for a VF from the PF.\n\n" 485 486 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 487 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 488 " (on|off) autoneg (on|off) (port_id)\n" 489 "set flow_ctrl rx (on|off) (portid)\n" 490 "set flow_ctrl tx (on|off) (portid)\n" 491 "set flow_ctrl high_water (high_water) (portid)\n" 492 "set flow_ctrl low_water (low_water) (portid)\n" 493 "set flow_ctrl pause_time (pause_time) (portid)\n" 494 "set flow_ctrl send_xon (send_xon) (portid)\n" 495 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 496 "set flow_ctrl autoneg (on|off) (port_id)\n" 497 " Set the link flow control parameter on a port.\n\n" 498 499 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 500 " (low_water) (pause_time) (priority) (port_id)\n" 501 " Set the priority flow control parameter on a" 502 " port.\n\n" 503 504 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 505 " Set statistics mapping (qmapping 0..15) for RX/TX" 506 " queue on port.\n" 507 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 508 " on port 0 to mapping 5.\n\n" 509 510 "set port (port_id) vf (vf_id) rx|tx on|off\n" 511 " Enable/Disable a VF receive/tranmit from a port\n\n" 512 513 "set port (port_id) vf (vf_id) (mac_addr)" 514 " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n" 515 " Add/Remove unicast or multicast MAC addr filter" 516 " for a VF.\n\n" 517 518 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 519 "|MPE) (on|off)\n" 520 " AUPE:accepts untagged VLAN;" 521 "ROPE:accept unicast hash\n\n" 522 " BAM:accepts broadcast packets;" 523 "MPE:accepts all multicast packets\n\n" 524 " Enable/Disable a VF receive mode of a port\n\n" 525 526 "set port (port_id) queue (queue_id) rate (rate_num)\n" 527 " Set rate limit for a queue of a port\n\n" 528 529 "set port (port_id) vf (vf_id) rate (rate_num) " 530 "queue_mask (queue_mask_value)\n" 531 " Set rate limit for queues in VF of a port\n\n" 532 533 "set port (port_id) mirror-rule (rule_id)" 534 " (pool-mirror-up|pool-mirror-down|vlan-mirror)" 535 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 536 " Set pool or vlan type mirror rule on a port.\n" 537 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 538 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 539 " to pool 0.\n\n" 540 541 "set port (port_id) mirror-rule (rule_id)" 542 " (uplink-mirror|downlink-mirror) dst-pool" 543 " (pool_id) (on|off)\n" 544 " Set uplink or downlink type mirror rule on a port.\n" 545 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 546 " 0 on' enable mirror income traffic to pool 0.\n\n" 547 548 "reset port (port_id) mirror-rule (rule_id)\n" 549 " Reset a mirror rule.\n\n" 550 551 "set flush_rx (on|off)\n" 552 " Flush (default) or don't flush RX streams before" 553 " forwarding. Mainly used with PCAP drivers.\n\n" 554 555 "set bypass mode (normal|bypass|isolate) (port_id)\n" 556 " Set the bypass mode for the lowest port on bypass enabled" 557 " NIC.\n\n" 558 559 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 560 "mode (normal|bypass|isolate) (port_id)\n" 561 " Set the event required to initiate specified bypass mode for" 562 " the lowest port on a bypass enabled NIC where:\n" 563 " timeout = enable bypass after watchdog timeout.\n" 564 " os_on = enable bypass when OS/board is powered on.\n" 565 " os_off = enable bypass when OS/board is powered off.\n" 566 " power_on = enable bypass when power supply is turned on.\n" 567 " power_off = enable bypass when power supply is turned off." 568 "\n\n" 569 570 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 571 " Set the bypass watchdog timeout to 'n' seconds" 572 " where 0 = instant.\n\n" 573 574 "show bypass config (port_id)\n" 575 " Show the bypass configuration for a bypass enabled NIC" 576 " using the lowest port on the NIC.\n\n" 577 578 #ifdef RTE_LIBRTE_PMD_BOND 579 "create bonded device (mode) (socket)\n" 580 " Create a new bonded device with specific bonding mode and socket.\n\n" 581 582 "add bonding slave (slave_id) (port_id)\n" 583 " Add a slave device to a bonded device.\n\n" 584 585 "remove bonding slave (slave_id) (port_id)\n" 586 " Remove a slave device from a bonded device.\n\n" 587 588 "set bonding mode (value) (port_id)\n" 589 " Set the bonding mode on a bonded device.\n\n" 590 591 "set bonding primary (slave_id) (port_id)\n" 592 " Set the primary slave for a bonded device.\n\n" 593 594 "show bonding config (port_id)\n" 595 " Show the bonding config for port_id.\n\n" 596 597 "set bonding mac_addr (port_id) (address)\n" 598 " Set the MAC address of a bonded device.\n\n" 599 600 "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)" 601 " Set Aggregation mode for IEEE802.3AD (mode 4)" 602 603 "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n" 604 " Set the transmit balance policy for bonded device running in balance mode.\n\n" 605 606 "set bonding mon_period (port_id) (value)\n" 607 " Set the bonding link status monitoring polling period in ms.\n\n" 608 609 "set bonding lacp dedicated_queues <port_id> (enable|disable)\n" 610 " Enable/disable dedicated queues for LACP control traffic.\n\n" 611 612 #endif 613 "set link-up port (port_id)\n" 614 " Set link up for a port.\n\n" 615 616 "set link-down port (port_id)\n" 617 " Set link down for a port.\n\n" 618 619 "E-tag set insertion on port-tag-id (value)" 620 " port (port_id) vf (vf_id)\n" 621 " Enable E-tag insertion for a VF on a port\n\n" 622 623 "E-tag set insertion off port (port_id) vf (vf_id)\n" 624 " Disable E-tag insertion for a VF on a port\n\n" 625 626 "E-tag set stripping (on|off) port (port_id)\n" 627 " Enable/disable E-tag stripping on a port\n\n" 628 629 "E-tag set forwarding (on|off) port (port_id)\n" 630 " Enable/disable E-tag based forwarding" 631 " on a port\n\n" 632 633 "E-tag set filter add e-tag-id (value) dst-pool" 634 " (pool_id) port (port_id)\n" 635 " Add an E-tag forwarding filter on a port\n\n" 636 637 "E-tag set filter del e-tag-id (value) port (port_id)\n" 638 " Delete an E-tag forwarding filter on a port\n\n" 639 640 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 641 "set port tm hierarchy default (port_id)\n" 642 " Set default traffic Management hierarchy on a port\n\n" 643 644 #endif 645 "ddp add (port_id) (profile_path[,output_path])\n" 646 " Load a profile package on a port\n\n" 647 648 "ddp del (port_id) (profile_path)\n" 649 " Delete a profile package from a port\n\n" 650 651 "ptype mapping get (port_id) (valid_only)\n" 652 " Get ptype mapping on a port\n\n" 653 654 "ptype mapping replace (port_id) (target) (mask) (pky_type)\n" 655 " Replace target with the pkt_type in ptype mapping\n\n" 656 657 "ptype mapping reset (port_id)\n" 658 " Reset ptype mapping on a port\n\n" 659 660 "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n" 661 " Update a ptype mapping item on a port\n\n" 662 663 "set port (port_id) queue-region region_id (value) " 664 "queue_start_index (value) queue_num (value)\n" 665 " Set a queue region on a port\n\n" 666 667 "set port (port_id) queue-region region_id (value) " 668 "flowtype (value)\n" 669 " Set a flowtype region index on a port\n\n" 670 671 "set port (port_id) queue-region UP (value) region_id (value)\n" 672 " Set the mapping of User Priority to " 673 "queue region on a port\n\n" 674 675 "set port (port_id) queue-region flush (on|off)\n" 676 " flush all queue region related configuration\n\n" 677 678 "show port (port_id) queue-region\n" 679 " show all queue region related configuration info\n\n" 680 681 , list_pkt_forwarding_modes() 682 ); 683 } 684 685 if (show_all || !strcmp(res->section, "ports")) { 686 687 cmdline_printf( 688 cl, 689 "\n" 690 "Port Operations:\n" 691 "----------------\n\n" 692 693 "port start (port_id|all)\n" 694 " Start all ports or port_id.\n\n" 695 696 "port stop (port_id|all)\n" 697 " Stop all ports or port_id.\n\n" 698 699 "port close (port_id|all)\n" 700 " Close all ports or port_id.\n\n" 701 702 "port attach (ident)\n" 703 " Attach physical or virtual dev by pci address or virtual device name\n\n" 704 705 "port detach (port_id)\n" 706 " Detach physical or virtual dev by port_id\n\n" 707 708 "port config (port_id|all)" 709 " speed (10|100|1000|10000|25000|40000|50000|100000|auto)" 710 " duplex (half|full|auto)\n" 711 " Set speed and duplex for all ports or port_id\n\n" 712 713 "port config all (rxq|txq|rxd|txd) (value)\n" 714 " Set number for rxq/txq/rxd/txd.\n\n" 715 716 "port config all max-pkt-len (value)\n" 717 " Set the max packet length.\n\n" 718 719 "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|" 720 "hw-vlan-strip|hw-vlan-extend|drop-en)" 721 " (on|off)\n" 722 " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" 723 " for ports.\n\n" 724 725 "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|" 726 "geneve|nvgre|none|<flowtype_id>)\n" 727 " Set the RSS mode.\n\n" 728 729 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 730 " Set the RSS redirection table.\n\n" 731 732 "port config (port_id) dcb vt (on|off) (traffic_class)" 733 " pfc (on|off)\n" 734 " Set the DCB mode.\n\n" 735 736 "port config all burst (value)\n" 737 " Set the number of packets per burst.\n\n" 738 739 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 740 " (value)\n" 741 " Set the ring prefetch/host/writeback threshold" 742 " for tx/rx queue.\n\n" 743 744 "port config all (txfreet|txrst|rxfreet) (value)\n" 745 " Set free threshold for rx/tx, or set" 746 " tx rs bit threshold.\n\n" 747 "port config mtu X value\n" 748 " Set the MTU of port X to a given value\n\n" 749 750 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 751 " Start/stop a rx/tx queue of port X. Only take effect" 752 " when port X is started\n\n" 753 754 "port config (port_id|all) l2-tunnel E-tag ether-type" 755 " (value)\n" 756 " Set the value of E-tag ether-type.\n\n" 757 758 "port config (port_id|all) l2-tunnel E-tag" 759 " (enable|disable)\n" 760 " Enable/disable the E-tag support.\n\n" 761 762 "port config (port_id) pctype mapping reset\n" 763 " Reset flow type to pctype mapping on a port\n\n" 764 765 "port config (port_id) pctype mapping update" 766 " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n" 767 " Update a flow type to pctype mapping item on a port\n\n" 768 ); 769 } 770 771 if (show_all || !strcmp(res->section, "registers")) { 772 773 cmdline_printf( 774 cl, 775 "\n" 776 "Registers:\n" 777 "----------\n\n" 778 779 "read reg (port_id) (address)\n" 780 " Display value of a port register.\n\n" 781 782 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 783 " Display a port register bit field.\n\n" 784 785 "read regbit (port_id) (address) (bit_x)\n" 786 " Display a single port register bit.\n\n" 787 788 "write reg (port_id) (address) (value)\n" 789 " Set value of a port register.\n\n" 790 791 "write regfield (port_id) (address) (bit_x) (bit_y)" 792 " (value)\n" 793 " Set bit field of a port register.\n\n" 794 795 "write regbit (port_id) (address) (bit_x) (value)\n" 796 " Set single bit value of a port register.\n\n" 797 ); 798 } 799 if (show_all || !strcmp(res->section, "filters")) { 800 801 cmdline_printf( 802 cl, 803 "\n" 804 "filters:\n" 805 "--------\n\n" 806 807 "ethertype_filter (port_id) (add|del)" 808 " (mac_addr|mac_ignr) (mac_address) ethertype" 809 " (ether_type) (drop|fwd) queue (queue_id)\n" 810 " Add/Del an ethertype filter.\n\n" 811 812 "2tuple_filter (port_id) (add|del)" 813 " dst_port (dst_port_value) protocol (protocol_value)" 814 " mask (mask_value) tcp_flags (tcp_flags_value)" 815 " priority (prio_value) queue (queue_id)\n" 816 " Add/Del a 2tuple filter.\n\n" 817 818 "5tuple_filter (port_id) (add|del)" 819 " dst_ip (dst_address) src_ip (src_address)" 820 " dst_port (dst_port_value) src_port (src_port_value)" 821 " protocol (protocol_value)" 822 " mask (mask_value) tcp_flags (tcp_flags_value)" 823 " priority (prio_value) queue (queue_id)\n" 824 " Add/Del a 5tuple filter.\n\n" 825 826 "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" 827 " Add/Del syn filter.\n\n" 828 829 "flex_filter (port_id) (add|del) len (len_value)" 830 " bytes (bytes_value) mask (mask_value)" 831 " priority (prio_value) queue (queue_id)\n" 832 " Add/Del a flex filter.\n\n" 833 834 "flow_director_filter (port_id) mode IP (add|del|update)" 835 " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)" 836 " src (src_ip_address) dst (dst_ip_address)" 837 " tos (tos_value) proto (proto_value) ttl (ttl_value)" 838 " vlan (vlan_value) flexbytes (flexbytes_value)" 839 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 840 " fd_id (fd_id_value)\n" 841 " Add/Del an IP type flow director filter.\n\n" 842 843 "flow_director_filter (port_id) mode IP (add|del|update)" 844 " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)" 845 " src (src_ip_address) (src_port)" 846 " dst (dst_ip_address) (dst_port)" 847 " tos (tos_value) ttl (ttl_value)" 848 " vlan (vlan_value) flexbytes (flexbytes_value)" 849 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 850 " fd_id (fd_id_value)\n" 851 " Add/Del an UDP/TCP type flow director filter.\n\n" 852 853 "flow_director_filter (port_id) mode IP (add|del|update)" 854 " flow (ipv4-sctp|ipv6-sctp)" 855 " src (src_ip_address) (src_port)" 856 " dst (dst_ip_address) (dst_port)" 857 " tag (verification_tag) " 858 " tos (tos_value) ttl (ttl_value)" 859 " vlan (vlan_value)" 860 " flexbytes (flexbytes_value) (drop|fwd)" 861 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 862 " Add/Del a SCTP type flow director filter.\n\n" 863 864 "flow_director_filter (port_id) mode IP (add|del|update)" 865 " flow l2_payload ether (ethertype)" 866 " flexbytes (flexbytes_value) (drop|fwd)" 867 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 868 " Add/Del a l2 payload type flow director filter.\n\n" 869 870 "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)" 871 " mac (mac_address) vlan (vlan_value)" 872 " flexbytes (flexbytes_value) (drop|fwd)" 873 " queue (queue_id) fd_id (fd_id_value)\n" 874 " Add/Del a MAC-VLAN flow director filter.\n\n" 875 876 "flow_director_filter (port_id) mode Tunnel (add|del|update)" 877 " mac (mac_address) vlan (vlan_value)" 878 " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)" 879 " flexbytes (flexbytes_value) (drop|fwd)" 880 " queue (queue_id) fd_id (fd_id_value)\n" 881 " Add/Del a Tunnel flow director filter.\n\n" 882 883 "flush_flow_director (port_id)\n" 884 " Flush all flow director entries of a device.\n\n" 885 886 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 887 " src_mask (ipv4_src) (ipv6_src) (src_port)" 888 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 889 " Set flow director IP mask.\n\n" 890 891 "flow_director_mask (port_id) mode MAC-VLAN" 892 " vlan (vlan_value)\n" 893 " Set flow director MAC-VLAN mask.\n\n" 894 895 "flow_director_mask (port_id) mode Tunnel" 896 " vlan (vlan_value) mac (mac_value)" 897 " tunnel-type (tunnel_type_value)" 898 " tunnel-id (tunnel_id_value)\n" 899 " Set flow director Tunnel mask.\n\n" 900 901 "flow_director_flex_mask (port_id)" 902 " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 903 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)" 904 " (mask)\n" 905 " Configure mask of flex payload.\n\n" 906 907 "flow_director_flex_payload (port_id)" 908 " (raw|l2|l3|l4) (config)\n" 909 " Configure flex payload selection.\n\n" 910 911 "get_sym_hash_ena_per_port (port_id)\n" 912 " get symmetric hash enable configuration per port.\n\n" 913 914 "set_sym_hash_ena_per_port (port_id) (enable|disable)\n" 915 " set symmetric hash enable configuration per port" 916 " to enable or disable.\n\n" 917 918 "get_hash_global_config (port_id)\n" 919 " Get the global configurations of hash filters.\n\n" 920 921 "set_hash_global_config (port_id) (toeplitz|simple_xor|default)" 922 " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 923 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)" 924 " (enable|disable)\n" 925 " Set the global configurations of hash filters.\n\n" 926 927 "set_hash_input_set (port_id) (ipv4|ipv4-frag|" 928 "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 929 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 930 "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|" 931 "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" 932 "ipv6-next-header|udp-src-port|udp-dst-port|" 933 "tcp-src-port|tcp-dst-port|sctp-src-port|" 934 "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" 935 "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|" 936 "fld-8th|none) (select|add)\n" 937 " Set the input set for hash.\n\n" 938 939 "set_fdir_input_set (port_id) " 940 "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 941 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 942 "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|" 943 "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|" 944 "ipv6-next-header|ipv6-hop-limits|udp-src-port|" 945 "udp-dst-port|tcp-src-port|tcp-dst-port|" 946 "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)" 947 " (select|add)\n" 948 " Set the input set for FDir.\n\n" 949 950 "flow validate {port_id}" 951 " [group {group_id}] [priority {level}]" 952 " [ingress] [egress]" 953 " pattern {item} [/ {item} [...]] / end" 954 " actions {action} [/ {action} [...]] / end\n" 955 " Check whether a flow rule can be created.\n\n" 956 957 "flow create {port_id}" 958 " [group {group_id}] [priority {level}]" 959 " [ingress] [egress]" 960 " pattern {item} [/ {item} [...]] / end" 961 " actions {action} [/ {action} [...]] / end\n" 962 " Create a flow rule.\n\n" 963 964 "flow destroy {port_id} rule {rule_id} [...]\n" 965 " Destroy specific flow rules.\n\n" 966 967 "flow flush {port_id}\n" 968 " Destroy all flow rules.\n\n" 969 970 "flow query {port_id} {rule_id} {action}\n" 971 " Query an existing flow rule.\n\n" 972 973 "flow list {port_id} [group {group_id}] [...]\n" 974 " List existing flow rules sorted by priority," 975 " filtered by group identifiers.\n\n" 976 977 "flow isolate {port_id} {boolean}\n" 978 " Restrict ingress traffic to the defined" 979 " flow rules\n\n" 980 ); 981 } 982 } 983 984 cmdline_parse_token_string_t cmd_help_long_help = 985 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 986 987 cmdline_parse_token_string_t cmd_help_long_section = 988 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 989 "all#control#display#config#" 990 "ports#registers#filters"); 991 992 cmdline_parse_inst_t cmd_help_long = { 993 .f = cmd_help_long_parsed, 994 .data = NULL, 995 .help_str = "help all|control|display|config|ports|register|filters: " 996 "Show help", 997 .tokens = { 998 (void *)&cmd_help_long_help, 999 (void *)&cmd_help_long_section, 1000 NULL, 1001 }, 1002 }; 1003 1004 1005 /* *** start/stop/close all ports *** */ 1006 struct cmd_operate_port_result { 1007 cmdline_fixed_string_t keyword; 1008 cmdline_fixed_string_t name; 1009 cmdline_fixed_string_t value; 1010 }; 1011 1012 static void cmd_operate_port_parsed(void *parsed_result, 1013 __attribute__((unused)) struct cmdline *cl, 1014 __attribute__((unused)) void *data) 1015 { 1016 struct cmd_operate_port_result *res = parsed_result; 1017 1018 if (!strcmp(res->name, "start")) 1019 start_port(RTE_PORT_ALL); 1020 else if (!strcmp(res->name, "stop")) 1021 stop_port(RTE_PORT_ALL); 1022 else if (!strcmp(res->name, "close")) 1023 close_port(RTE_PORT_ALL); 1024 else if (!strcmp(res->name, "reset")) 1025 reset_port(RTE_PORT_ALL); 1026 else 1027 printf("Unknown parameter\n"); 1028 } 1029 1030 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 1031 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 1032 "port"); 1033 cmdline_parse_token_string_t cmd_operate_port_all_port = 1034 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 1035 "start#stop#close#reset"); 1036 cmdline_parse_token_string_t cmd_operate_port_all_all = 1037 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 1038 1039 cmdline_parse_inst_t cmd_operate_port = { 1040 .f = cmd_operate_port_parsed, 1041 .data = NULL, 1042 .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports", 1043 .tokens = { 1044 (void *)&cmd_operate_port_all_cmd, 1045 (void *)&cmd_operate_port_all_port, 1046 (void *)&cmd_operate_port_all_all, 1047 NULL, 1048 }, 1049 }; 1050 1051 /* *** start/stop/close specific port *** */ 1052 struct cmd_operate_specific_port_result { 1053 cmdline_fixed_string_t keyword; 1054 cmdline_fixed_string_t name; 1055 uint8_t value; 1056 }; 1057 1058 static void cmd_operate_specific_port_parsed(void *parsed_result, 1059 __attribute__((unused)) struct cmdline *cl, 1060 __attribute__((unused)) void *data) 1061 { 1062 struct cmd_operate_specific_port_result *res = parsed_result; 1063 1064 if (!strcmp(res->name, "start")) 1065 start_port(res->value); 1066 else if (!strcmp(res->name, "stop")) 1067 stop_port(res->value); 1068 else if (!strcmp(res->name, "close")) 1069 close_port(res->value); 1070 else if (!strcmp(res->name, "reset")) 1071 reset_port(res->value); 1072 else 1073 printf("Unknown parameter\n"); 1074 } 1075 1076 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 1077 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1078 keyword, "port"); 1079 cmdline_parse_token_string_t cmd_operate_specific_port_port = 1080 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1081 name, "start#stop#close#reset"); 1082 cmdline_parse_token_num_t cmd_operate_specific_port_id = 1083 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 1084 value, UINT8); 1085 1086 cmdline_parse_inst_t cmd_operate_specific_port = { 1087 .f = cmd_operate_specific_port_parsed, 1088 .data = NULL, 1089 .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id", 1090 .tokens = { 1091 (void *)&cmd_operate_specific_port_cmd, 1092 (void *)&cmd_operate_specific_port_port, 1093 (void *)&cmd_operate_specific_port_id, 1094 NULL, 1095 }, 1096 }; 1097 1098 /* *** attach a specified port *** */ 1099 struct cmd_operate_attach_port_result { 1100 cmdline_fixed_string_t port; 1101 cmdline_fixed_string_t keyword; 1102 cmdline_fixed_string_t identifier; 1103 }; 1104 1105 static void cmd_operate_attach_port_parsed(void *parsed_result, 1106 __attribute__((unused)) struct cmdline *cl, 1107 __attribute__((unused)) void *data) 1108 { 1109 struct cmd_operate_attach_port_result *res = parsed_result; 1110 1111 if (!strcmp(res->keyword, "attach")) 1112 attach_port(res->identifier); 1113 else 1114 printf("Unknown parameter\n"); 1115 } 1116 1117 cmdline_parse_token_string_t cmd_operate_attach_port_port = 1118 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1119 port, "port"); 1120 cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1121 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1122 keyword, "attach"); 1123 cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1124 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1125 identifier, NULL); 1126 1127 cmdline_parse_inst_t cmd_operate_attach_port = { 1128 .f = cmd_operate_attach_port_parsed, 1129 .data = NULL, 1130 .help_str = "port attach <identifier>: " 1131 "(identifier: pci address or virtual dev name)", 1132 .tokens = { 1133 (void *)&cmd_operate_attach_port_port, 1134 (void *)&cmd_operate_attach_port_keyword, 1135 (void *)&cmd_operate_attach_port_identifier, 1136 NULL, 1137 }, 1138 }; 1139 1140 /* *** detach a specified port *** */ 1141 struct cmd_operate_detach_port_result { 1142 cmdline_fixed_string_t port; 1143 cmdline_fixed_string_t keyword; 1144 uint8_t port_id; 1145 }; 1146 1147 static void cmd_operate_detach_port_parsed(void *parsed_result, 1148 __attribute__((unused)) struct cmdline *cl, 1149 __attribute__((unused)) void *data) 1150 { 1151 struct cmd_operate_detach_port_result *res = parsed_result; 1152 1153 if (!strcmp(res->keyword, "detach")) 1154 detach_port(res->port_id); 1155 else 1156 printf("Unknown parameter\n"); 1157 } 1158 1159 cmdline_parse_token_string_t cmd_operate_detach_port_port = 1160 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1161 port, "port"); 1162 cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1163 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1164 keyword, "detach"); 1165 cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1166 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1167 port_id, UINT8); 1168 1169 cmdline_parse_inst_t cmd_operate_detach_port = { 1170 .f = cmd_operate_detach_port_parsed, 1171 .data = NULL, 1172 .help_str = "port detach <port_id>", 1173 .tokens = { 1174 (void *)&cmd_operate_detach_port_port, 1175 (void *)&cmd_operate_detach_port_keyword, 1176 (void *)&cmd_operate_detach_port_port_id, 1177 NULL, 1178 }, 1179 }; 1180 1181 /* *** configure speed for all ports *** */ 1182 struct cmd_config_speed_all { 1183 cmdline_fixed_string_t port; 1184 cmdline_fixed_string_t keyword; 1185 cmdline_fixed_string_t all; 1186 cmdline_fixed_string_t item1; 1187 cmdline_fixed_string_t item2; 1188 cmdline_fixed_string_t value1; 1189 cmdline_fixed_string_t value2; 1190 }; 1191 1192 static int 1193 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1194 { 1195 1196 int duplex; 1197 1198 if (!strcmp(duplexstr, "half")) { 1199 duplex = ETH_LINK_HALF_DUPLEX; 1200 } else if (!strcmp(duplexstr, "full")) { 1201 duplex = ETH_LINK_FULL_DUPLEX; 1202 } else if (!strcmp(duplexstr, "auto")) { 1203 duplex = ETH_LINK_FULL_DUPLEX; 1204 } else { 1205 printf("Unknown duplex parameter\n"); 1206 return -1; 1207 } 1208 1209 if (!strcmp(speedstr, "10")) { 1210 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1211 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M; 1212 } else if (!strcmp(speedstr, "100")) { 1213 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1214 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M; 1215 } else { 1216 if (duplex != ETH_LINK_FULL_DUPLEX) { 1217 printf("Invalid speed/duplex parameters\n"); 1218 return -1; 1219 } 1220 if (!strcmp(speedstr, "1000")) { 1221 *speed = ETH_LINK_SPEED_1G; 1222 } else if (!strcmp(speedstr, "10000")) { 1223 *speed = ETH_LINK_SPEED_10G; 1224 } else if (!strcmp(speedstr, "25000")) { 1225 *speed = ETH_LINK_SPEED_25G; 1226 } else if (!strcmp(speedstr, "40000")) { 1227 *speed = ETH_LINK_SPEED_40G; 1228 } else if (!strcmp(speedstr, "50000")) { 1229 *speed = ETH_LINK_SPEED_50G; 1230 } else if (!strcmp(speedstr, "100000")) { 1231 *speed = ETH_LINK_SPEED_100G; 1232 } else if (!strcmp(speedstr, "auto")) { 1233 *speed = ETH_LINK_SPEED_AUTONEG; 1234 } else { 1235 printf("Unknown speed parameter\n"); 1236 return -1; 1237 } 1238 } 1239 1240 return 0; 1241 } 1242 1243 static void 1244 cmd_config_speed_all_parsed(void *parsed_result, 1245 __attribute__((unused)) struct cmdline *cl, 1246 __attribute__((unused)) void *data) 1247 { 1248 struct cmd_config_speed_all *res = parsed_result; 1249 uint32_t link_speed; 1250 portid_t pid; 1251 1252 if (!all_ports_stopped()) { 1253 printf("Please stop all ports first\n"); 1254 return; 1255 } 1256 1257 if (parse_and_check_speed_duplex(res->value1, res->value2, 1258 &link_speed) < 0) 1259 return; 1260 1261 RTE_ETH_FOREACH_DEV(pid) { 1262 ports[pid].dev_conf.link_speeds = link_speed; 1263 } 1264 1265 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1266 } 1267 1268 cmdline_parse_token_string_t cmd_config_speed_all_port = 1269 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1270 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1271 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1272 "config"); 1273 cmdline_parse_token_string_t cmd_config_speed_all_all = 1274 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1275 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1276 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1277 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1278 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1279 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1280 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1281 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1282 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1283 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1284 "half#full#auto"); 1285 1286 cmdline_parse_inst_t cmd_config_speed_all = { 1287 .f = cmd_config_speed_all_parsed, 1288 .data = NULL, 1289 .help_str = "port config all speed " 1290 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1291 "half|full|auto", 1292 .tokens = { 1293 (void *)&cmd_config_speed_all_port, 1294 (void *)&cmd_config_speed_all_keyword, 1295 (void *)&cmd_config_speed_all_all, 1296 (void *)&cmd_config_speed_all_item1, 1297 (void *)&cmd_config_speed_all_value1, 1298 (void *)&cmd_config_speed_all_item2, 1299 (void *)&cmd_config_speed_all_value2, 1300 NULL, 1301 }, 1302 }; 1303 1304 /* *** configure speed for specific port *** */ 1305 struct cmd_config_speed_specific { 1306 cmdline_fixed_string_t port; 1307 cmdline_fixed_string_t keyword; 1308 uint8_t id; 1309 cmdline_fixed_string_t item1; 1310 cmdline_fixed_string_t item2; 1311 cmdline_fixed_string_t value1; 1312 cmdline_fixed_string_t value2; 1313 }; 1314 1315 static void 1316 cmd_config_speed_specific_parsed(void *parsed_result, 1317 __attribute__((unused)) struct cmdline *cl, 1318 __attribute__((unused)) void *data) 1319 { 1320 struct cmd_config_speed_specific *res = parsed_result; 1321 uint32_t link_speed; 1322 1323 if (!all_ports_stopped()) { 1324 printf("Please stop all ports first\n"); 1325 return; 1326 } 1327 1328 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1329 return; 1330 1331 if (parse_and_check_speed_duplex(res->value1, res->value2, 1332 &link_speed) < 0) 1333 return; 1334 1335 ports[res->id].dev_conf.link_speeds = link_speed; 1336 1337 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1338 } 1339 1340 1341 cmdline_parse_token_string_t cmd_config_speed_specific_port = 1342 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1343 "port"); 1344 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1345 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1346 "config"); 1347 cmdline_parse_token_num_t cmd_config_speed_specific_id = 1348 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 1349 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1350 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1351 "speed"); 1352 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1353 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1354 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1355 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1356 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1357 "duplex"); 1358 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1359 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1360 "half#full#auto"); 1361 1362 cmdline_parse_inst_t cmd_config_speed_specific = { 1363 .f = cmd_config_speed_specific_parsed, 1364 .data = NULL, 1365 .help_str = "port config <port_id> speed " 1366 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1367 "half|full|auto", 1368 .tokens = { 1369 (void *)&cmd_config_speed_specific_port, 1370 (void *)&cmd_config_speed_specific_keyword, 1371 (void *)&cmd_config_speed_specific_id, 1372 (void *)&cmd_config_speed_specific_item1, 1373 (void *)&cmd_config_speed_specific_value1, 1374 (void *)&cmd_config_speed_specific_item2, 1375 (void *)&cmd_config_speed_specific_value2, 1376 NULL, 1377 }, 1378 }; 1379 1380 /* *** configure txq/rxq, txd/rxd *** */ 1381 struct cmd_config_rx_tx { 1382 cmdline_fixed_string_t port; 1383 cmdline_fixed_string_t keyword; 1384 cmdline_fixed_string_t all; 1385 cmdline_fixed_string_t name; 1386 uint16_t value; 1387 }; 1388 1389 static void 1390 cmd_config_rx_tx_parsed(void *parsed_result, 1391 __attribute__((unused)) struct cmdline *cl, 1392 __attribute__((unused)) void *data) 1393 { 1394 struct cmd_config_rx_tx *res = parsed_result; 1395 1396 if (!all_ports_stopped()) { 1397 printf("Please stop all ports first\n"); 1398 return; 1399 } 1400 if (!strcmp(res->name, "rxq")) { 1401 if (!res->value && !nb_txq) { 1402 printf("Warning: Either rx or tx queues should be non zero\n"); 1403 return; 1404 } 1405 nb_rxq = res->value; 1406 } 1407 else if (!strcmp(res->name, "txq")) { 1408 if (!res->value && !nb_rxq) { 1409 printf("Warning: Either rx or tx queues should be non zero\n"); 1410 return; 1411 } 1412 nb_txq = res->value; 1413 } 1414 else if (!strcmp(res->name, "rxd")) { 1415 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 1416 printf("rxd %d invalid - must be > 0 && <= %d\n", 1417 res->value, RTE_TEST_RX_DESC_MAX); 1418 return; 1419 } 1420 nb_rxd = res->value; 1421 } else if (!strcmp(res->name, "txd")) { 1422 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 1423 printf("txd %d invalid - must be > 0 && <= %d\n", 1424 res->value, RTE_TEST_TX_DESC_MAX); 1425 return; 1426 } 1427 nb_txd = res->value; 1428 } else { 1429 printf("Unknown parameter\n"); 1430 return; 1431 } 1432 1433 fwd_config_setup(); 1434 1435 init_port_config(); 1436 1437 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1438 } 1439 1440 cmdline_parse_token_string_t cmd_config_rx_tx_port = 1441 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1442 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1443 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1444 cmdline_parse_token_string_t cmd_config_rx_tx_all = 1445 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1446 cmdline_parse_token_string_t cmd_config_rx_tx_name = 1447 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1448 "rxq#txq#rxd#txd"); 1449 cmdline_parse_token_num_t cmd_config_rx_tx_value = 1450 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 1451 1452 cmdline_parse_inst_t cmd_config_rx_tx = { 1453 .f = cmd_config_rx_tx_parsed, 1454 .data = NULL, 1455 .help_str = "port config all rxq|txq|rxd|txd <value>", 1456 .tokens = { 1457 (void *)&cmd_config_rx_tx_port, 1458 (void *)&cmd_config_rx_tx_keyword, 1459 (void *)&cmd_config_rx_tx_all, 1460 (void *)&cmd_config_rx_tx_name, 1461 (void *)&cmd_config_rx_tx_value, 1462 NULL, 1463 }, 1464 }; 1465 1466 /* *** config max packet length *** */ 1467 struct cmd_config_max_pkt_len_result { 1468 cmdline_fixed_string_t port; 1469 cmdline_fixed_string_t keyword; 1470 cmdline_fixed_string_t all; 1471 cmdline_fixed_string_t name; 1472 uint32_t value; 1473 }; 1474 1475 static void 1476 cmd_config_max_pkt_len_parsed(void *parsed_result, 1477 __attribute__((unused)) struct cmdline *cl, 1478 __attribute__((unused)) void *data) 1479 { 1480 struct cmd_config_max_pkt_len_result *res = parsed_result; 1481 1482 if (!all_ports_stopped()) { 1483 printf("Please stop all ports first\n"); 1484 return; 1485 } 1486 1487 if (!strcmp(res->name, "max-pkt-len")) { 1488 if (res->value < ETHER_MIN_LEN) { 1489 printf("max-pkt-len can not be less than %d\n", 1490 ETHER_MIN_LEN); 1491 return; 1492 } 1493 if (res->value == rx_mode.max_rx_pkt_len) 1494 return; 1495 1496 rx_mode.max_rx_pkt_len = res->value; 1497 if (res->value > ETHER_MAX_LEN) 1498 rx_mode.jumbo_frame = 1; 1499 else 1500 rx_mode.jumbo_frame = 0; 1501 } else { 1502 printf("Unknown parameter\n"); 1503 return; 1504 } 1505 1506 init_port_config(); 1507 1508 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1509 } 1510 1511 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1512 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1513 "port"); 1514 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1515 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1516 "config"); 1517 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1518 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1519 "all"); 1520 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1521 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1522 "max-pkt-len"); 1523 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1524 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1525 UINT32); 1526 1527 cmdline_parse_inst_t cmd_config_max_pkt_len = { 1528 .f = cmd_config_max_pkt_len_parsed, 1529 .data = NULL, 1530 .help_str = "port config all max-pkt-len <value>", 1531 .tokens = { 1532 (void *)&cmd_config_max_pkt_len_port, 1533 (void *)&cmd_config_max_pkt_len_keyword, 1534 (void *)&cmd_config_max_pkt_len_all, 1535 (void *)&cmd_config_max_pkt_len_name, 1536 (void *)&cmd_config_max_pkt_len_value, 1537 NULL, 1538 }, 1539 }; 1540 1541 /* *** configure port MTU *** */ 1542 struct cmd_config_mtu_result { 1543 cmdline_fixed_string_t port; 1544 cmdline_fixed_string_t keyword; 1545 cmdline_fixed_string_t mtu; 1546 uint8_t port_id; 1547 uint16_t value; 1548 }; 1549 1550 static void 1551 cmd_config_mtu_parsed(void *parsed_result, 1552 __attribute__((unused)) struct cmdline *cl, 1553 __attribute__((unused)) void *data) 1554 { 1555 struct cmd_config_mtu_result *res = parsed_result; 1556 1557 if (res->value < ETHER_MIN_LEN) { 1558 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN); 1559 return; 1560 } 1561 port_mtu_set(res->port_id, res->value); 1562 } 1563 1564 cmdline_parse_token_string_t cmd_config_mtu_port = 1565 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1566 "port"); 1567 cmdline_parse_token_string_t cmd_config_mtu_keyword = 1568 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1569 "config"); 1570 cmdline_parse_token_string_t cmd_config_mtu_mtu = 1571 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1572 "mtu"); 1573 cmdline_parse_token_num_t cmd_config_mtu_port_id = 1574 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8); 1575 cmdline_parse_token_num_t cmd_config_mtu_value = 1576 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); 1577 1578 cmdline_parse_inst_t cmd_config_mtu = { 1579 .f = cmd_config_mtu_parsed, 1580 .data = NULL, 1581 .help_str = "port config mtu <port_id> <value>", 1582 .tokens = { 1583 (void *)&cmd_config_mtu_port, 1584 (void *)&cmd_config_mtu_keyword, 1585 (void *)&cmd_config_mtu_mtu, 1586 (void *)&cmd_config_mtu_port_id, 1587 (void *)&cmd_config_mtu_value, 1588 NULL, 1589 }, 1590 }; 1591 1592 /* *** configure rx mode *** */ 1593 struct cmd_config_rx_mode_flag { 1594 cmdline_fixed_string_t port; 1595 cmdline_fixed_string_t keyword; 1596 cmdline_fixed_string_t all; 1597 cmdline_fixed_string_t name; 1598 cmdline_fixed_string_t value; 1599 }; 1600 1601 static void 1602 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1603 __attribute__((unused)) struct cmdline *cl, 1604 __attribute__((unused)) void *data) 1605 { 1606 struct cmd_config_rx_mode_flag *res = parsed_result; 1607 1608 if (!all_ports_stopped()) { 1609 printf("Please stop all ports first\n"); 1610 return; 1611 } 1612 1613 if (!strcmp(res->name, "crc-strip")) { 1614 if (!strcmp(res->value, "on")) 1615 rx_mode.hw_strip_crc = 1; 1616 else if (!strcmp(res->value, "off")) 1617 rx_mode.hw_strip_crc = 0; 1618 else { 1619 printf("Unknown parameter\n"); 1620 return; 1621 } 1622 } else if (!strcmp(res->name, "scatter")) { 1623 if (!strcmp(res->value, "on")) 1624 rx_mode.enable_scatter = 1; 1625 else if (!strcmp(res->value, "off")) 1626 rx_mode.enable_scatter = 0; 1627 else { 1628 printf("Unknown parameter\n"); 1629 return; 1630 } 1631 } else if (!strcmp(res->name, "rx-cksum")) { 1632 if (!strcmp(res->value, "on")) 1633 rx_mode.hw_ip_checksum = 1; 1634 else if (!strcmp(res->value, "off")) 1635 rx_mode.hw_ip_checksum = 0; 1636 else { 1637 printf("Unknown parameter\n"); 1638 return; 1639 } 1640 } else if (!strcmp(res->name, "rx-timestamp")) { 1641 if (!strcmp(res->value, "on")) 1642 rx_mode.hw_timestamp = 1; 1643 else if (!strcmp(res->value, "off")) 1644 rx_mode.hw_timestamp = 0; 1645 else { 1646 printf("Unknown parameter\n"); 1647 return; 1648 } 1649 } else if (!strcmp(res->name, "hw-vlan")) { 1650 if (!strcmp(res->value, "on")) { 1651 rx_mode.hw_vlan_filter = 1; 1652 rx_mode.hw_vlan_strip = 1; 1653 } 1654 else if (!strcmp(res->value, "off")) { 1655 rx_mode.hw_vlan_filter = 0; 1656 rx_mode.hw_vlan_strip = 0; 1657 } 1658 else { 1659 printf("Unknown parameter\n"); 1660 return; 1661 } 1662 } else if (!strcmp(res->name, "hw-vlan-filter")) { 1663 if (!strcmp(res->value, "on")) 1664 rx_mode.hw_vlan_filter = 1; 1665 else if (!strcmp(res->value, "off")) 1666 rx_mode.hw_vlan_filter = 0; 1667 else { 1668 printf("Unknown parameter\n"); 1669 return; 1670 } 1671 } else if (!strcmp(res->name, "hw-vlan-strip")) { 1672 if (!strcmp(res->value, "on")) 1673 rx_mode.hw_vlan_strip = 1; 1674 else if (!strcmp(res->value, "off")) 1675 rx_mode.hw_vlan_strip = 0; 1676 else { 1677 printf("Unknown parameter\n"); 1678 return; 1679 } 1680 } else if (!strcmp(res->name, "hw-vlan-extend")) { 1681 if (!strcmp(res->value, "on")) 1682 rx_mode.hw_vlan_extend = 1; 1683 else if (!strcmp(res->value, "off")) 1684 rx_mode.hw_vlan_extend = 0; 1685 else { 1686 printf("Unknown parameter\n"); 1687 return; 1688 } 1689 } else if (!strcmp(res->name, "drop-en")) { 1690 if (!strcmp(res->value, "on")) 1691 rx_drop_en = 1; 1692 else if (!strcmp(res->value, "off")) 1693 rx_drop_en = 0; 1694 else { 1695 printf("Unknown parameter\n"); 1696 return; 1697 } 1698 } else { 1699 printf("Unknown parameter\n"); 1700 return; 1701 } 1702 1703 init_port_config(); 1704 1705 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1706 } 1707 1708 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1709 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1710 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1711 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1712 "config"); 1713 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1714 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1715 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1716 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1717 "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#" 1718 "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); 1719 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1720 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1721 "on#off"); 1722 1723 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1724 .f = cmd_config_rx_mode_flag_parsed, 1725 .data = NULL, 1726 .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|" 1727 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", 1728 .tokens = { 1729 (void *)&cmd_config_rx_mode_flag_port, 1730 (void *)&cmd_config_rx_mode_flag_keyword, 1731 (void *)&cmd_config_rx_mode_flag_all, 1732 (void *)&cmd_config_rx_mode_flag_name, 1733 (void *)&cmd_config_rx_mode_flag_value, 1734 NULL, 1735 }, 1736 }; 1737 1738 /* *** configure rss *** */ 1739 struct cmd_config_rss { 1740 cmdline_fixed_string_t port; 1741 cmdline_fixed_string_t keyword; 1742 cmdline_fixed_string_t all; 1743 cmdline_fixed_string_t name; 1744 cmdline_fixed_string_t value; 1745 }; 1746 1747 static void 1748 cmd_config_rss_parsed(void *parsed_result, 1749 __attribute__((unused)) struct cmdline *cl, 1750 __attribute__((unused)) void *data) 1751 { 1752 struct cmd_config_rss *res = parsed_result; 1753 struct rte_eth_rss_conf rss_conf; 1754 int diag; 1755 uint8_t i; 1756 1757 if (!strcmp(res->value, "all")) 1758 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | 1759 ETH_RSS_UDP | ETH_RSS_SCTP | 1760 ETH_RSS_L2_PAYLOAD; 1761 else if (!strcmp(res->value, "ip")) 1762 rss_conf.rss_hf = ETH_RSS_IP; 1763 else if (!strcmp(res->value, "udp")) 1764 rss_conf.rss_hf = ETH_RSS_UDP; 1765 else if (!strcmp(res->value, "tcp")) 1766 rss_conf.rss_hf = ETH_RSS_TCP; 1767 else if (!strcmp(res->value, "sctp")) 1768 rss_conf.rss_hf = ETH_RSS_SCTP; 1769 else if (!strcmp(res->value, "ether")) 1770 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD; 1771 else if (!strcmp(res->value, "port")) 1772 rss_conf.rss_hf = ETH_RSS_PORT; 1773 else if (!strcmp(res->value, "vxlan")) 1774 rss_conf.rss_hf = ETH_RSS_VXLAN; 1775 else if (!strcmp(res->value, "geneve")) 1776 rss_conf.rss_hf = ETH_RSS_GENEVE; 1777 else if (!strcmp(res->value, "nvgre")) 1778 rss_conf.rss_hf = ETH_RSS_NVGRE; 1779 else if (!strcmp(res->value, "none")) 1780 rss_conf.rss_hf = 0; 1781 else if (isdigit(res->value[0]) && atoi(res->value) > 0 && 1782 atoi(res->value) < 64) 1783 rss_conf.rss_hf = 1ULL << atoi(res->value); 1784 else { 1785 printf("Unknown parameter\n"); 1786 return; 1787 } 1788 rss_conf.rss_key = NULL; 1789 for (i = 0; i < rte_eth_dev_count(); i++) { 1790 diag = rte_eth_dev_rss_hash_update(i, &rss_conf); 1791 if (diag < 0) 1792 printf("Configuration of RSS hash at ethernet port %d " 1793 "failed with error (%d): %s.\n", 1794 i, -diag, strerror(-diag)); 1795 } 1796 } 1797 1798 cmdline_parse_token_string_t cmd_config_rss_port = 1799 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1800 cmdline_parse_token_string_t cmd_config_rss_keyword = 1801 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1802 cmdline_parse_token_string_t cmd_config_rss_all = 1803 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1804 cmdline_parse_token_string_t cmd_config_rss_name = 1805 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1806 cmdline_parse_token_string_t cmd_config_rss_value = 1807 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL); 1808 1809 cmdline_parse_inst_t cmd_config_rss = { 1810 .f = cmd_config_rss_parsed, 1811 .data = NULL, 1812 .help_str = "port config all rss " 1813 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>", 1814 .tokens = { 1815 (void *)&cmd_config_rss_port, 1816 (void *)&cmd_config_rss_keyword, 1817 (void *)&cmd_config_rss_all, 1818 (void *)&cmd_config_rss_name, 1819 (void *)&cmd_config_rss_value, 1820 NULL, 1821 }, 1822 }; 1823 1824 /* *** configure rss hash key *** */ 1825 struct cmd_config_rss_hash_key { 1826 cmdline_fixed_string_t port; 1827 cmdline_fixed_string_t config; 1828 uint8_t port_id; 1829 cmdline_fixed_string_t rss_hash_key; 1830 cmdline_fixed_string_t rss_type; 1831 cmdline_fixed_string_t key; 1832 }; 1833 1834 static uint8_t 1835 hexa_digit_to_value(char hexa_digit) 1836 { 1837 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 1838 return (uint8_t) (hexa_digit - '0'); 1839 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 1840 return (uint8_t) ((hexa_digit - 'a') + 10); 1841 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 1842 return (uint8_t) ((hexa_digit - 'A') + 10); 1843 /* Invalid hexa digit */ 1844 return 0xFF; 1845 } 1846 1847 static uint8_t 1848 parse_and_check_key_hexa_digit(char *key, int idx) 1849 { 1850 uint8_t hexa_v; 1851 1852 hexa_v = hexa_digit_to_value(key[idx]); 1853 if (hexa_v == 0xFF) 1854 printf("invalid key: character %c at position %d is not a " 1855 "valid hexa digit\n", key[idx], idx); 1856 return hexa_v; 1857 } 1858 1859 static void 1860 cmd_config_rss_hash_key_parsed(void *parsed_result, 1861 __attribute__((unused)) struct cmdline *cl, 1862 __attribute__((unused)) void *data) 1863 { 1864 struct cmd_config_rss_hash_key *res = parsed_result; 1865 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 1866 uint8_t xdgt0; 1867 uint8_t xdgt1; 1868 int i; 1869 struct rte_eth_dev_info dev_info; 1870 uint8_t hash_key_size; 1871 uint32_t key_len; 1872 1873 memset(&dev_info, 0, sizeof(dev_info)); 1874 rte_eth_dev_info_get(res->port_id, &dev_info); 1875 if (dev_info.hash_key_size > 0 && 1876 dev_info.hash_key_size <= sizeof(hash_key)) 1877 hash_key_size = dev_info.hash_key_size; 1878 else { 1879 printf("dev_info did not provide a valid hash key size\n"); 1880 return; 1881 } 1882 /* Check the length of the RSS hash key */ 1883 key_len = strlen(res->key); 1884 if (key_len != (hash_key_size * 2)) { 1885 printf("key length: %d invalid - key must be a string of %d" 1886 " hexa-decimal numbers\n", 1887 (int) key_len, hash_key_size * 2); 1888 return; 1889 } 1890 /* Translate RSS hash key into binary representation */ 1891 for (i = 0; i < hash_key_size; i++) { 1892 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 1893 if (xdgt0 == 0xFF) 1894 return; 1895 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 1896 if (xdgt1 == 0xFF) 1897 return; 1898 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 1899 } 1900 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 1901 hash_key_size); 1902 } 1903 1904 cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 1905 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 1906 cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 1907 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 1908 "config"); 1909 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 1910 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); 1911 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 1912 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 1913 rss_hash_key, "rss-hash-key"); 1914 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 1915 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 1916 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 1917 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 1918 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 1919 "ipv6-tcp-ex#ipv6-udp-ex"); 1920 cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 1921 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 1922 1923 cmdline_parse_inst_t cmd_config_rss_hash_key = { 1924 .f = cmd_config_rss_hash_key_parsed, 1925 .data = NULL, 1926 .help_str = "port config <port_id> rss-hash-key " 1927 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 1928 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1929 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex " 1930 "<string of hex digits (variable length, NIC dependent)>", 1931 .tokens = { 1932 (void *)&cmd_config_rss_hash_key_port, 1933 (void *)&cmd_config_rss_hash_key_config, 1934 (void *)&cmd_config_rss_hash_key_port_id, 1935 (void *)&cmd_config_rss_hash_key_rss_hash_key, 1936 (void *)&cmd_config_rss_hash_key_rss_type, 1937 (void *)&cmd_config_rss_hash_key_value, 1938 NULL, 1939 }, 1940 }; 1941 1942 /* *** configure port rxq/txq start/stop *** */ 1943 struct cmd_config_rxtx_queue { 1944 cmdline_fixed_string_t port; 1945 uint8_t portid; 1946 cmdline_fixed_string_t rxtxq; 1947 uint16_t qid; 1948 cmdline_fixed_string_t opname; 1949 }; 1950 1951 static void 1952 cmd_config_rxtx_queue_parsed(void *parsed_result, 1953 __attribute__((unused)) struct cmdline *cl, 1954 __attribute__((unused)) void *data) 1955 { 1956 struct cmd_config_rxtx_queue *res = parsed_result; 1957 uint8_t isrx; 1958 uint8_t isstart; 1959 int ret = 0; 1960 1961 if (test_done == 0) { 1962 printf("Please stop forwarding first\n"); 1963 return; 1964 } 1965 1966 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 1967 return; 1968 1969 if (port_is_started(res->portid) != 1) { 1970 printf("Please start port %u first\n", res->portid); 1971 return; 1972 } 1973 1974 if (!strcmp(res->rxtxq, "rxq")) 1975 isrx = 1; 1976 else if (!strcmp(res->rxtxq, "txq")) 1977 isrx = 0; 1978 else { 1979 printf("Unknown parameter\n"); 1980 return; 1981 } 1982 1983 if (isrx && rx_queue_id_is_invalid(res->qid)) 1984 return; 1985 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 1986 return; 1987 1988 if (!strcmp(res->opname, "start")) 1989 isstart = 1; 1990 else if (!strcmp(res->opname, "stop")) 1991 isstart = 0; 1992 else { 1993 printf("Unknown parameter\n"); 1994 return; 1995 } 1996 1997 if (isstart && isrx) 1998 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 1999 else if (!isstart && isrx) 2000 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 2001 else if (isstart && !isrx) 2002 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 2003 else 2004 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 2005 2006 if (ret == -ENOTSUP) 2007 printf("Function not supported in PMD driver\n"); 2008 } 2009 2010 cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 2011 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 2012 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 2013 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8); 2014 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 2015 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 2016 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 2017 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16); 2018 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 2019 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 2020 "start#stop"); 2021 2022 cmdline_parse_inst_t cmd_config_rxtx_queue = { 2023 .f = cmd_config_rxtx_queue_parsed, 2024 .data = NULL, 2025 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 2026 .tokens = { 2027 (void *)&cmd_config_speed_all_port, 2028 (void *)&cmd_config_rxtx_queue_portid, 2029 (void *)&cmd_config_rxtx_queue_rxtxq, 2030 (void *)&cmd_config_rxtx_queue_qid, 2031 (void *)&cmd_config_rxtx_queue_opname, 2032 NULL, 2033 }, 2034 }; 2035 2036 /* *** Configure RSS RETA *** */ 2037 struct cmd_config_rss_reta { 2038 cmdline_fixed_string_t port; 2039 cmdline_fixed_string_t keyword; 2040 uint8_t port_id; 2041 cmdline_fixed_string_t name; 2042 cmdline_fixed_string_t list_name; 2043 cmdline_fixed_string_t list_of_items; 2044 }; 2045 2046 static int 2047 parse_reta_config(const char *str, 2048 struct rte_eth_rss_reta_entry64 *reta_conf, 2049 uint16_t nb_entries) 2050 { 2051 int i; 2052 unsigned size; 2053 uint16_t hash_index, idx, shift; 2054 uint16_t nb_queue; 2055 char s[256]; 2056 const char *p, *p0 = str; 2057 char *end; 2058 enum fieldnames { 2059 FLD_HASH_INDEX = 0, 2060 FLD_QUEUE, 2061 _NUM_FLD 2062 }; 2063 unsigned long int_fld[_NUM_FLD]; 2064 char *str_fld[_NUM_FLD]; 2065 2066 while ((p = strchr(p0,'(')) != NULL) { 2067 ++p; 2068 if((p0 = strchr(p,')')) == NULL) 2069 return -1; 2070 2071 size = p0 - p; 2072 if(size >= sizeof(s)) 2073 return -1; 2074 2075 snprintf(s, sizeof(s), "%.*s", size, p); 2076 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 2077 return -1; 2078 for (i = 0; i < _NUM_FLD; i++) { 2079 errno = 0; 2080 int_fld[i] = strtoul(str_fld[i], &end, 0); 2081 if (errno != 0 || end == str_fld[i] || 2082 int_fld[i] > 65535) 2083 return -1; 2084 } 2085 2086 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 2087 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 2088 2089 if (hash_index >= nb_entries) { 2090 printf("Invalid RETA hash index=%d\n", hash_index); 2091 return -1; 2092 } 2093 2094 idx = hash_index / RTE_RETA_GROUP_SIZE; 2095 shift = hash_index % RTE_RETA_GROUP_SIZE; 2096 reta_conf[idx].mask |= (1ULL << shift); 2097 reta_conf[idx].reta[shift] = nb_queue; 2098 } 2099 2100 return 0; 2101 } 2102 2103 static void 2104 cmd_set_rss_reta_parsed(void *parsed_result, 2105 __attribute__((unused)) struct cmdline *cl, 2106 __attribute__((unused)) void *data) 2107 { 2108 int ret; 2109 struct rte_eth_dev_info dev_info; 2110 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2111 struct cmd_config_rss_reta *res = parsed_result; 2112 2113 memset(&dev_info, 0, sizeof(dev_info)); 2114 rte_eth_dev_info_get(res->port_id, &dev_info); 2115 if (dev_info.reta_size == 0) { 2116 printf("Redirection table size is 0 which is " 2117 "invalid for RSS\n"); 2118 return; 2119 } else 2120 printf("The reta size of port %d is %u\n", 2121 res->port_id, dev_info.reta_size); 2122 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) { 2123 printf("Currently do not support more than %u entries of " 2124 "redirection table\n", ETH_RSS_RETA_SIZE_512); 2125 return; 2126 } 2127 2128 memset(reta_conf, 0, sizeof(reta_conf)); 2129 if (!strcmp(res->list_name, "reta")) { 2130 if (parse_reta_config(res->list_of_items, reta_conf, 2131 dev_info.reta_size)) { 2132 printf("Invalid RSS Redirection Table " 2133 "config entered\n"); 2134 return; 2135 } 2136 ret = rte_eth_dev_rss_reta_update(res->port_id, 2137 reta_conf, dev_info.reta_size); 2138 if (ret != 0) 2139 printf("Bad redirection table parameter, " 2140 "return code = %d \n", ret); 2141 } 2142 } 2143 2144 cmdline_parse_token_string_t cmd_config_rss_reta_port = 2145 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2146 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2147 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2148 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2149 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); 2150 cmdline_parse_token_string_t cmd_config_rss_reta_name = 2151 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2152 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2153 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2154 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2155 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2156 NULL); 2157 cmdline_parse_inst_t cmd_config_rss_reta = { 2158 .f = cmd_set_rss_reta_parsed, 2159 .data = NULL, 2160 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2161 .tokens = { 2162 (void *)&cmd_config_rss_reta_port, 2163 (void *)&cmd_config_rss_reta_keyword, 2164 (void *)&cmd_config_rss_reta_port_id, 2165 (void *)&cmd_config_rss_reta_name, 2166 (void *)&cmd_config_rss_reta_list_name, 2167 (void *)&cmd_config_rss_reta_list_of_items, 2168 NULL, 2169 }, 2170 }; 2171 2172 /* *** SHOW PORT RETA INFO *** */ 2173 struct cmd_showport_reta { 2174 cmdline_fixed_string_t show; 2175 cmdline_fixed_string_t port; 2176 uint8_t port_id; 2177 cmdline_fixed_string_t rss; 2178 cmdline_fixed_string_t reta; 2179 uint16_t size; 2180 cmdline_fixed_string_t list_of_items; 2181 }; 2182 2183 static int 2184 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2185 uint16_t nb_entries, 2186 char *str) 2187 { 2188 uint32_t size; 2189 const char *p, *p0 = str; 2190 char s[256]; 2191 char *end; 2192 char *str_fld[8]; 2193 uint16_t i; 2194 uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) / 2195 RTE_RETA_GROUP_SIZE; 2196 int ret; 2197 2198 p = strchr(p0, '('); 2199 if (p == NULL) 2200 return -1; 2201 p++; 2202 p0 = strchr(p, ')'); 2203 if (p0 == NULL) 2204 return -1; 2205 size = p0 - p; 2206 if (size >= sizeof(s)) { 2207 printf("The string size exceeds the internal buffer size\n"); 2208 return -1; 2209 } 2210 snprintf(s, sizeof(s), "%.*s", size, p); 2211 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 2212 if (ret <= 0 || ret != num) { 2213 printf("The bits of masks do not match the number of " 2214 "reta entries: %u\n", num); 2215 return -1; 2216 } 2217 for (i = 0; i < ret; i++) 2218 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0); 2219 2220 return 0; 2221 } 2222 2223 static void 2224 cmd_showport_reta_parsed(void *parsed_result, 2225 __attribute__((unused)) struct cmdline *cl, 2226 __attribute__((unused)) void *data) 2227 { 2228 struct cmd_showport_reta *res = parsed_result; 2229 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2230 struct rte_eth_dev_info dev_info; 2231 uint16_t max_reta_size; 2232 2233 memset(&dev_info, 0, sizeof(dev_info)); 2234 rte_eth_dev_info_get(res->port_id, &dev_info); 2235 max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512); 2236 if (res->size == 0 || res->size > max_reta_size) { 2237 printf("Invalid redirection table size: %u (1-%u)\n", 2238 res->size, max_reta_size); 2239 return; 2240 } 2241 2242 memset(reta_conf, 0, sizeof(reta_conf)); 2243 if (showport_parse_reta_config(reta_conf, res->size, 2244 res->list_of_items) < 0) { 2245 printf("Invalid string: %s for reta masks\n", 2246 res->list_of_items); 2247 return; 2248 } 2249 port_rss_reta_info(res->port_id, reta_conf, res->size); 2250 } 2251 2252 cmdline_parse_token_string_t cmd_showport_reta_show = 2253 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 2254 cmdline_parse_token_string_t cmd_showport_reta_port = 2255 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 2256 cmdline_parse_token_num_t cmd_showport_reta_port_id = 2257 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); 2258 cmdline_parse_token_string_t cmd_showport_reta_rss = 2259 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 2260 cmdline_parse_token_string_t cmd_showport_reta_reta = 2261 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 2262 cmdline_parse_token_num_t cmd_showport_reta_size = 2263 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16); 2264 cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 2265 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 2266 list_of_items, NULL); 2267 2268 cmdline_parse_inst_t cmd_showport_reta = { 2269 .f = cmd_showport_reta_parsed, 2270 .data = NULL, 2271 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 2272 .tokens = { 2273 (void *)&cmd_showport_reta_show, 2274 (void *)&cmd_showport_reta_port, 2275 (void *)&cmd_showport_reta_port_id, 2276 (void *)&cmd_showport_reta_rss, 2277 (void *)&cmd_showport_reta_reta, 2278 (void *)&cmd_showport_reta_size, 2279 (void *)&cmd_showport_reta_list_of_items, 2280 NULL, 2281 }, 2282 }; 2283 2284 /* *** Show RSS hash configuration *** */ 2285 struct cmd_showport_rss_hash { 2286 cmdline_fixed_string_t show; 2287 cmdline_fixed_string_t port; 2288 uint8_t port_id; 2289 cmdline_fixed_string_t rss_hash; 2290 cmdline_fixed_string_t rss_type; 2291 cmdline_fixed_string_t key; /* optional argument */ 2292 }; 2293 2294 static void cmd_showport_rss_hash_parsed(void *parsed_result, 2295 __attribute__((unused)) struct cmdline *cl, 2296 void *show_rss_key) 2297 { 2298 struct cmd_showport_rss_hash *res = parsed_result; 2299 2300 port_rss_hash_conf_show(res->port_id, res->rss_type, 2301 show_rss_key != NULL); 2302 } 2303 2304 cmdline_parse_token_string_t cmd_showport_rss_hash_show = 2305 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 2306 cmdline_parse_token_string_t cmd_showport_rss_hash_port = 2307 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 2308 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 2309 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8); 2310 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 2311 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 2312 "rss-hash"); 2313 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info = 2314 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type, 2315 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2316 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2317 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2318 "ipv6-tcp-ex#ipv6-udp-ex"); 2319 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 2320 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 2321 2322 cmdline_parse_inst_t cmd_showport_rss_hash = { 2323 .f = cmd_showport_rss_hash_parsed, 2324 .data = NULL, 2325 .help_str = "show port <port_id> rss-hash " 2326 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2327 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2328 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex", 2329 .tokens = { 2330 (void *)&cmd_showport_rss_hash_show, 2331 (void *)&cmd_showport_rss_hash_port, 2332 (void *)&cmd_showport_rss_hash_port_id, 2333 (void *)&cmd_showport_rss_hash_rss_hash, 2334 (void *)&cmd_showport_rss_hash_rss_hash_info, 2335 NULL, 2336 }, 2337 }; 2338 2339 cmdline_parse_inst_t cmd_showport_rss_hash_key = { 2340 .f = cmd_showport_rss_hash_parsed, 2341 .data = (void *)1, 2342 .help_str = "show port <port_id> rss-hash " 2343 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2344 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2345 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key", 2346 .tokens = { 2347 (void *)&cmd_showport_rss_hash_show, 2348 (void *)&cmd_showport_rss_hash_port, 2349 (void *)&cmd_showport_rss_hash_port_id, 2350 (void *)&cmd_showport_rss_hash_rss_hash, 2351 (void *)&cmd_showport_rss_hash_rss_hash_info, 2352 (void *)&cmd_showport_rss_hash_rss_key, 2353 NULL, 2354 }, 2355 }; 2356 2357 /* *** Configure DCB *** */ 2358 struct cmd_config_dcb { 2359 cmdline_fixed_string_t port; 2360 cmdline_fixed_string_t config; 2361 uint8_t port_id; 2362 cmdline_fixed_string_t dcb; 2363 cmdline_fixed_string_t vt; 2364 cmdline_fixed_string_t vt_en; 2365 uint8_t num_tcs; 2366 cmdline_fixed_string_t pfc; 2367 cmdline_fixed_string_t pfc_en; 2368 }; 2369 2370 static void 2371 cmd_config_dcb_parsed(void *parsed_result, 2372 __attribute__((unused)) struct cmdline *cl, 2373 __attribute__((unused)) void *data) 2374 { 2375 struct cmd_config_dcb *res = parsed_result; 2376 portid_t port_id = res->port_id; 2377 struct rte_port *port; 2378 uint8_t pfc_en; 2379 int ret; 2380 2381 port = &ports[port_id]; 2382 /** Check if the port is not started **/ 2383 if (port->port_status != RTE_PORT_STOPPED) { 2384 printf("Please stop port %d first\n", port_id); 2385 return; 2386 } 2387 2388 if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) { 2389 printf("The invalid number of traffic class," 2390 " only 4 or 8 allowed.\n"); 2391 return; 2392 } 2393 2394 if (nb_fwd_lcores < res->num_tcs) { 2395 printf("nb_cores shouldn't be less than number of TCs.\n"); 2396 return; 2397 } 2398 if (!strncmp(res->pfc_en, "on", 2)) 2399 pfc_en = 1; 2400 else 2401 pfc_en = 0; 2402 2403 /* DCB in VT mode */ 2404 if (!strncmp(res->vt_en, "on", 2)) 2405 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 2406 (enum rte_eth_nb_tcs)res->num_tcs, 2407 pfc_en); 2408 else 2409 ret = init_port_dcb_config(port_id, DCB_ENABLED, 2410 (enum rte_eth_nb_tcs)res->num_tcs, 2411 pfc_en); 2412 2413 2414 if (ret != 0) { 2415 printf("Cannot initialize network ports.\n"); 2416 return; 2417 } 2418 2419 cmd_reconfig_device_queue(port_id, 1, 1); 2420 } 2421 2422 cmdline_parse_token_string_t cmd_config_dcb_port = 2423 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 2424 cmdline_parse_token_string_t cmd_config_dcb_config = 2425 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 2426 cmdline_parse_token_num_t cmd_config_dcb_port_id = 2427 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); 2428 cmdline_parse_token_string_t cmd_config_dcb_dcb = 2429 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 2430 cmdline_parse_token_string_t cmd_config_dcb_vt = 2431 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 2432 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 2433 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 2434 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 2435 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 2436 cmdline_parse_token_string_t cmd_config_dcb_pfc= 2437 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 2438 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 2439 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 2440 2441 cmdline_parse_inst_t cmd_config_dcb = { 2442 .f = cmd_config_dcb_parsed, 2443 .data = NULL, 2444 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 2445 .tokens = { 2446 (void *)&cmd_config_dcb_port, 2447 (void *)&cmd_config_dcb_config, 2448 (void *)&cmd_config_dcb_port_id, 2449 (void *)&cmd_config_dcb_dcb, 2450 (void *)&cmd_config_dcb_vt, 2451 (void *)&cmd_config_dcb_vt_en, 2452 (void *)&cmd_config_dcb_num_tcs, 2453 (void *)&cmd_config_dcb_pfc, 2454 (void *)&cmd_config_dcb_pfc_en, 2455 NULL, 2456 }, 2457 }; 2458 2459 /* *** configure number of packets per burst *** */ 2460 struct cmd_config_burst { 2461 cmdline_fixed_string_t port; 2462 cmdline_fixed_string_t keyword; 2463 cmdline_fixed_string_t all; 2464 cmdline_fixed_string_t name; 2465 uint16_t value; 2466 }; 2467 2468 static void 2469 cmd_config_burst_parsed(void *parsed_result, 2470 __attribute__((unused)) struct cmdline *cl, 2471 __attribute__((unused)) void *data) 2472 { 2473 struct cmd_config_burst *res = parsed_result; 2474 2475 if (!all_ports_stopped()) { 2476 printf("Please stop all ports first\n"); 2477 return; 2478 } 2479 2480 if (!strcmp(res->name, "burst")) { 2481 if (res->value < 1 || res->value > MAX_PKT_BURST) { 2482 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 2483 return; 2484 } 2485 nb_pkt_per_burst = res->value; 2486 } else { 2487 printf("Unknown parameter\n"); 2488 return; 2489 } 2490 2491 init_port_config(); 2492 2493 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2494 } 2495 2496 cmdline_parse_token_string_t cmd_config_burst_port = 2497 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 2498 cmdline_parse_token_string_t cmd_config_burst_keyword = 2499 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 2500 cmdline_parse_token_string_t cmd_config_burst_all = 2501 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 2502 cmdline_parse_token_string_t cmd_config_burst_name = 2503 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 2504 cmdline_parse_token_num_t cmd_config_burst_value = 2505 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 2506 2507 cmdline_parse_inst_t cmd_config_burst = { 2508 .f = cmd_config_burst_parsed, 2509 .data = NULL, 2510 .help_str = "port config all burst <value>", 2511 .tokens = { 2512 (void *)&cmd_config_burst_port, 2513 (void *)&cmd_config_burst_keyword, 2514 (void *)&cmd_config_burst_all, 2515 (void *)&cmd_config_burst_name, 2516 (void *)&cmd_config_burst_value, 2517 NULL, 2518 }, 2519 }; 2520 2521 /* *** configure rx/tx queues *** */ 2522 struct cmd_config_thresh { 2523 cmdline_fixed_string_t port; 2524 cmdline_fixed_string_t keyword; 2525 cmdline_fixed_string_t all; 2526 cmdline_fixed_string_t name; 2527 uint8_t value; 2528 }; 2529 2530 static void 2531 cmd_config_thresh_parsed(void *parsed_result, 2532 __attribute__((unused)) struct cmdline *cl, 2533 __attribute__((unused)) void *data) 2534 { 2535 struct cmd_config_thresh *res = parsed_result; 2536 2537 if (!all_ports_stopped()) { 2538 printf("Please stop all ports first\n"); 2539 return; 2540 } 2541 2542 if (!strcmp(res->name, "txpt")) 2543 tx_pthresh = res->value; 2544 else if(!strcmp(res->name, "txht")) 2545 tx_hthresh = res->value; 2546 else if(!strcmp(res->name, "txwt")) 2547 tx_wthresh = res->value; 2548 else if(!strcmp(res->name, "rxpt")) 2549 rx_pthresh = res->value; 2550 else if(!strcmp(res->name, "rxht")) 2551 rx_hthresh = res->value; 2552 else if(!strcmp(res->name, "rxwt")) 2553 rx_wthresh = res->value; 2554 else { 2555 printf("Unknown parameter\n"); 2556 return; 2557 } 2558 2559 init_port_config(); 2560 2561 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2562 } 2563 2564 cmdline_parse_token_string_t cmd_config_thresh_port = 2565 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 2566 cmdline_parse_token_string_t cmd_config_thresh_keyword = 2567 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 2568 cmdline_parse_token_string_t cmd_config_thresh_all = 2569 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 2570 cmdline_parse_token_string_t cmd_config_thresh_name = 2571 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 2572 "txpt#txht#txwt#rxpt#rxht#rxwt"); 2573 cmdline_parse_token_num_t cmd_config_thresh_value = 2574 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 2575 2576 cmdline_parse_inst_t cmd_config_thresh = { 2577 .f = cmd_config_thresh_parsed, 2578 .data = NULL, 2579 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 2580 .tokens = { 2581 (void *)&cmd_config_thresh_port, 2582 (void *)&cmd_config_thresh_keyword, 2583 (void *)&cmd_config_thresh_all, 2584 (void *)&cmd_config_thresh_name, 2585 (void *)&cmd_config_thresh_value, 2586 NULL, 2587 }, 2588 }; 2589 2590 /* *** configure free/rs threshold *** */ 2591 struct cmd_config_threshold { 2592 cmdline_fixed_string_t port; 2593 cmdline_fixed_string_t keyword; 2594 cmdline_fixed_string_t all; 2595 cmdline_fixed_string_t name; 2596 uint16_t value; 2597 }; 2598 2599 static void 2600 cmd_config_threshold_parsed(void *parsed_result, 2601 __attribute__((unused)) struct cmdline *cl, 2602 __attribute__((unused)) void *data) 2603 { 2604 struct cmd_config_threshold *res = parsed_result; 2605 2606 if (!all_ports_stopped()) { 2607 printf("Please stop all ports first\n"); 2608 return; 2609 } 2610 2611 if (!strcmp(res->name, "txfreet")) 2612 tx_free_thresh = res->value; 2613 else if (!strcmp(res->name, "txrst")) 2614 tx_rs_thresh = res->value; 2615 else if (!strcmp(res->name, "rxfreet")) 2616 rx_free_thresh = res->value; 2617 else { 2618 printf("Unknown parameter\n"); 2619 return; 2620 } 2621 2622 init_port_config(); 2623 2624 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2625 } 2626 2627 cmdline_parse_token_string_t cmd_config_threshold_port = 2628 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 2629 cmdline_parse_token_string_t cmd_config_threshold_keyword = 2630 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 2631 "config"); 2632 cmdline_parse_token_string_t cmd_config_threshold_all = 2633 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 2634 cmdline_parse_token_string_t cmd_config_threshold_name = 2635 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 2636 "txfreet#txrst#rxfreet"); 2637 cmdline_parse_token_num_t cmd_config_threshold_value = 2638 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 2639 2640 cmdline_parse_inst_t cmd_config_threshold = { 2641 .f = cmd_config_threshold_parsed, 2642 .data = NULL, 2643 .help_str = "port config all txfreet|txrst|rxfreet <value>", 2644 .tokens = { 2645 (void *)&cmd_config_threshold_port, 2646 (void *)&cmd_config_threshold_keyword, 2647 (void *)&cmd_config_threshold_all, 2648 (void *)&cmd_config_threshold_name, 2649 (void *)&cmd_config_threshold_value, 2650 NULL, 2651 }, 2652 }; 2653 2654 /* *** stop *** */ 2655 struct cmd_stop_result { 2656 cmdline_fixed_string_t stop; 2657 }; 2658 2659 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 2660 __attribute__((unused)) struct cmdline *cl, 2661 __attribute__((unused)) void *data) 2662 { 2663 stop_packet_forwarding(); 2664 } 2665 2666 cmdline_parse_token_string_t cmd_stop_stop = 2667 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 2668 2669 cmdline_parse_inst_t cmd_stop = { 2670 .f = cmd_stop_parsed, 2671 .data = NULL, 2672 .help_str = "stop: Stop packet forwarding", 2673 .tokens = { 2674 (void *)&cmd_stop_stop, 2675 NULL, 2676 }, 2677 }; 2678 2679 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 2680 2681 unsigned int 2682 parse_item_list(char* str, const char* item_name, unsigned int max_items, 2683 unsigned int *parsed_items, int check_unique_values) 2684 { 2685 unsigned int nb_item; 2686 unsigned int value; 2687 unsigned int i; 2688 unsigned int j; 2689 int value_ok; 2690 char c; 2691 2692 /* 2693 * First parse all items in the list and store their value. 2694 */ 2695 value = 0; 2696 nb_item = 0; 2697 value_ok = 0; 2698 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 2699 c = str[i]; 2700 if ((c >= '0') && (c <= '9')) { 2701 value = (unsigned int) (value * 10 + (c - '0')); 2702 value_ok = 1; 2703 continue; 2704 } 2705 if (c != ',') { 2706 printf("character %c is not a decimal digit\n", c); 2707 return 0; 2708 } 2709 if (! value_ok) { 2710 printf("No valid value before comma\n"); 2711 return 0; 2712 } 2713 if (nb_item < max_items) { 2714 parsed_items[nb_item] = value; 2715 value_ok = 0; 2716 value = 0; 2717 } 2718 nb_item++; 2719 } 2720 if (nb_item >= max_items) { 2721 printf("Number of %s = %u > %u (maximum items)\n", 2722 item_name, nb_item + 1, max_items); 2723 return 0; 2724 } 2725 parsed_items[nb_item++] = value; 2726 if (! check_unique_values) 2727 return nb_item; 2728 2729 /* 2730 * Then, check that all values in the list are differents. 2731 * No optimization here... 2732 */ 2733 for (i = 0; i < nb_item; i++) { 2734 for (j = i + 1; j < nb_item; j++) { 2735 if (parsed_items[j] == parsed_items[i]) { 2736 printf("duplicated %s %u at index %u and %u\n", 2737 item_name, parsed_items[i], i, j); 2738 return 0; 2739 } 2740 } 2741 } 2742 return nb_item; 2743 } 2744 2745 struct cmd_set_list_result { 2746 cmdline_fixed_string_t cmd_keyword; 2747 cmdline_fixed_string_t list_name; 2748 cmdline_fixed_string_t list_of_items; 2749 }; 2750 2751 static void cmd_set_list_parsed(void *parsed_result, 2752 __attribute__((unused)) struct cmdline *cl, 2753 __attribute__((unused)) void *data) 2754 { 2755 struct cmd_set_list_result *res; 2756 union { 2757 unsigned int lcorelist[RTE_MAX_LCORE]; 2758 unsigned int portlist[RTE_MAX_ETHPORTS]; 2759 } parsed_items; 2760 unsigned int nb_item; 2761 2762 if (test_done == 0) { 2763 printf("Please stop forwarding first\n"); 2764 return; 2765 } 2766 2767 res = parsed_result; 2768 if (!strcmp(res->list_name, "corelist")) { 2769 nb_item = parse_item_list(res->list_of_items, "core", 2770 RTE_MAX_LCORE, 2771 parsed_items.lcorelist, 1); 2772 if (nb_item > 0) { 2773 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 2774 fwd_config_setup(); 2775 } 2776 return; 2777 } 2778 if (!strcmp(res->list_name, "portlist")) { 2779 nb_item = parse_item_list(res->list_of_items, "port", 2780 RTE_MAX_ETHPORTS, 2781 parsed_items.portlist, 1); 2782 if (nb_item > 0) { 2783 set_fwd_ports_list(parsed_items.portlist, nb_item); 2784 fwd_config_setup(); 2785 } 2786 } 2787 } 2788 2789 cmdline_parse_token_string_t cmd_set_list_keyword = 2790 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 2791 "set"); 2792 cmdline_parse_token_string_t cmd_set_list_name = 2793 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 2794 "corelist#portlist"); 2795 cmdline_parse_token_string_t cmd_set_list_of_items = 2796 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 2797 NULL); 2798 2799 cmdline_parse_inst_t cmd_set_fwd_list = { 2800 .f = cmd_set_list_parsed, 2801 .data = NULL, 2802 .help_str = "set corelist|portlist <list0[,list1]*>", 2803 .tokens = { 2804 (void *)&cmd_set_list_keyword, 2805 (void *)&cmd_set_list_name, 2806 (void *)&cmd_set_list_of_items, 2807 NULL, 2808 }, 2809 }; 2810 2811 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 2812 2813 struct cmd_setmask_result { 2814 cmdline_fixed_string_t set; 2815 cmdline_fixed_string_t mask; 2816 uint64_t hexavalue; 2817 }; 2818 2819 static void cmd_set_mask_parsed(void *parsed_result, 2820 __attribute__((unused)) struct cmdline *cl, 2821 __attribute__((unused)) void *data) 2822 { 2823 struct cmd_setmask_result *res = parsed_result; 2824 2825 if (test_done == 0) { 2826 printf("Please stop forwarding first\n"); 2827 return; 2828 } 2829 if (!strcmp(res->mask, "coremask")) { 2830 set_fwd_lcores_mask(res->hexavalue); 2831 fwd_config_setup(); 2832 } else if (!strcmp(res->mask, "portmask")) { 2833 set_fwd_ports_mask(res->hexavalue); 2834 fwd_config_setup(); 2835 } 2836 } 2837 2838 cmdline_parse_token_string_t cmd_setmask_set = 2839 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 2840 cmdline_parse_token_string_t cmd_setmask_mask = 2841 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 2842 "coremask#portmask"); 2843 cmdline_parse_token_num_t cmd_setmask_value = 2844 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 2845 2846 cmdline_parse_inst_t cmd_set_fwd_mask = { 2847 .f = cmd_set_mask_parsed, 2848 .data = NULL, 2849 .help_str = "set coremask|portmask <hexadecimal value>", 2850 .tokens = { 2851 (void *)&cmd_setmask_set, 2852 (void *)&cmd_setmask_mask, 2853 (void *)&cmd_setmask_value, 2854 NULL, 2855 }, 2856 }; 2857 2858 /* 2859 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 2860 */ 2861 struct cmd_set_result { 2862 cmdline_fixed_string_t set; 2863 cmdline_fixed_string_t what; 2864 uint16_t value; 2865 }; 2866 2867 static void cmd_set_parsed(void *parsed_result, 2868 __attribute__((unused)) struct cmdline *cl, 2869 __attribute__((unused)) void *data) 2870 { 2871 struct cmd_set_result *res = parsed_result; 2872 if (!strcmp(res->what, "nbport")) { 2873 set_fwd_ports_number(res->value); 2874 fwd_config_setup(); 2875 } else if (!strcmp(res->what, "nbcore")) { 2876 set_fwd_lcores_number(res->value); 2877 fwd_config_setup(); 2878 } else if (!strcmp(res->what, "burst")) 2879 set_nb_pkt_per_burst(res->value); 2880 else if (!strcmp(res->what, "verbose")) 2881 set_verbose_level(res->value); 2882 } 2883 2884 cmdline_parse_token_string_t cmd_set_set = 2885 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 2886 cmdline_parse_token_string_t cmd_set_what = 2887 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 2888 "nbport#nbcore#burst#verbose"); 2889 cmdline_parse_token_num_t cmd_set_value = 2890 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 2891 2892 cmdline_parse_inst_t cmd_set_numbers = { 2893 .f = cmd_set_parsed, 2894 .data = NULL, 2895 .help_str = "set nbport|nbcore|burst|verbose <value>", 2896 .tokens = { 2897 (void *)&cmd_set_set, 2898 (void *)&cmd_set_what, 2899 (void *)&cmd_set_value, 2900 NULL, 2901 }, 2902 }; 2903 2904 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 2905 2906 struct cmd_set_txpkts_result { 2907 cmdline_fixed_string_t cmd_keyword; 2908 cmdline_fixed_string_t txpkts; 2909 cmdline_fixed_string_t seg_lengths; 2910 }; 2911 2912 static void 2913 cmd_set_txpkts_parsed(void *parsed_result, 2914 __attribute__((unused)) struct cmdline *cl, 2915 __attribute__((unused)) void *data) 2916 { 2917 struct cmd_set_txpkts_result *res; 2918 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 2919 unsigned int nb_segs; 2920 2921 res = parsed_result; 2922 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 2923 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 2924 if (nb_segs > 0) 2925 set_tx_pkt_segments(seg_lengths, nb_segs); 2926 } 2927 2928 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 2929 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2930 cmd_keyword, "set"); 2931 cmdline_parse_token_string_t cmd_set_txpkts_name = 2932 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2933 txpkts, "txpkts"); 2934 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 2935 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 2936 seg_lengths, NULL); 2937 2938 cmdline_parse_inst_t cmd_set_txpkts = { 2939 .f = cmd_set_txpkts_parsed, 2940 .data = NULL, 2941 .help_str = "set txpkts <len0[,len1]*>", 2942 .tokens = { 2943 (void *)&cmd_set_txpkts_keyword, 2944 (void *)&cmd_set_txpkts_name, 2945 (void *)&cmd_set_txpkts_lengths, 2946 NULL, 2947 }, 2948 }; 2949 2950 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 2951 2952 struct cmd_set_txsplit_result { 2953 cmdline_fixed_string_t cmd_keyword; 2954 cmdline_fixed_string_t txsplit; 2955 cmdline_fixed_string_t mode; 2956 }; 2957 2958 static void 2959 cmd_set_txsplit_parsed(void *parsed_result, 2960 __attribute__((unused)) struct cmdline *cl, 2961 __attribute__((unused)) void *data) 2962 { 2963 struct cmd_set_txsplit_result *res; 2964 2965 res = parsed_result; 2966 set_tx_pkt_split(res->mode); 2967 } 2968 2969 cmdline_parse_token_string_t cmd_set_txsplit_keyword = 2970 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2971 cmd_keyword, "set"); 2972 cmdline_parse_token_string_t cmd_set_txsplit_name = 2973 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2974 txsplit, "txsplit"); 2975 cmdline_parse_token_string_t cmd_set_txsplit_mode = 2976 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 2977 mode, NULL); 2978 2979 cmdline_parse_inst_t cmd_set_txsplit = { 2980 .f = cmd_set_txsplit_parsed, 2981 .data = NULL, 2982 .help_str = "set txsplit on|off|rand", 2983 .tokens = { 2984 (void *)&cmd_set_txsplit_keyword, 2985 (void *)&cmd_set_txsplit_name, 2986 (void *)&cmd_set_txsplit_mode, 2987 NULL, 2988 }, 2989 }; 2990 2991 /* *** CONFIG TX QUEUE FLAGS *** */ 2992 2993 struct cmd_config_txqflags_result { 2994 cmdline_fixed_string_t port; 2995 cmdline_fixed_string_t config; 2996 cmdline_fixed_string_t all; 2997 cmdline_fixed_string_t what; 2998 int32_t hexvalue; 2999 }; 3000 3001 static void cmd_config_txqflags_parsed(void *parsed_result, 3002 __attribute__((unused)) struct cmdline *cl, 3003 __attribute__((unused)) void *data) 3004 { 3005 struct cmd_config_txqflags_result *res = parsed_result; 3006 3007 if (!all_ports_stopped()) { 3008 printf("Please stop all ports first\n"); 3009 return; 3010 } 3011 3012 if (strcmp(res->what, "txqflags")) { 3013 printf("Unknown parameter\n"); 3014 return; 3015 } 3016 3017 if (res->hexvalue >= 0) { 3018 txq_flags = res->hexvalue; 3019 } else { 3020 printf("txqflags must be >= 0\n"); 3021 return; 3022 } 3023 3024 init_port_config(); 3025 3026 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 3027 } 3028 3029 cmdline_parse_token_string_t cmd_config_txqflags_port = 3030 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port, 3031 "port"); 3032 cmdline_parse_token_string_t cmd_config_txqflags_config = 3033 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config, 3034 "config"); 3035 cmdline_parse_token_string_t cmd_config_txqflags_all = 3036 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all, 3037 "all"); 3038 cmdline_parse_token_string_t cmd_config_txqflags_what = 3039 TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what, 3040 "txqflags"); 3041 cmdline_parse_token_num_t cmd_config_txqflags_value = 3042 TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result, 3043 hexvalue, INT32); 3044 3045 cmdline_parse_inst_t cmd_config_txqflags = { 3046 .f = cmd_config_txqflags_parsed, 3047 .data = NULL, 3048 .help_str = "port config all txqflags <value>", 3049 .tokens = { 3050 (void *)&cmd_config_txqflags_port, 3051 (void *)&cmd_config_txqflags_config, 3052 (void *)&cmd_config_txqflags_all, 3053 (void *)&cmd_config_txqflags_what, 3054 (void *)&cmd_config_txqflags_value, 3055 NULL, 3056 }, 3057 }; 3058 3059 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 3060 struct cmd_rx_vlan_filter_all_result { 3061 cmdline_fixed_string_t rx_vlan; 3062 cmdline_fixed_string_t what; 3063 cmdline_fixed_string_t all; 3064 uint8_t port_id; 3065 }; 3066 3067 static void 3068 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 3069 __attribute__((unused)) struct cmdline *cl, 3070 __attribute__((unused)) void *data) 3071 { 3072 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 3073 3074 if (!strcmp(res->what, "add")) 3075 rx_vlan_all_filter_set(res->port_id, 1); 3076 else 3077 rx_vlan_all_filter_set(res->port_id, 0); 3078 } 3079 3080 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 3081 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3082 rx_vlan, "rx_vlan"); 3083 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 3084 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3085 what, "add#rm"); 3086 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 3087 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3088 all, "all"); 3089 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 3090 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3091 port_id, UINT8); 3092 3093 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 3094 .f = cmd_rx_vlan_filter_all_parsed, 3095 .data = NULL, 3096 .help_str = "rx_vlan add|rm all <port_id>: " 3097 "Add/Remove all identifiers to/from the set of VLAN " 3098 "identifiers filtered by a port", 3099 .tokens = { 3100 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 3101 (void *)&cmd_rx_vlan_filter_all_what, 3102 (void *)&cmd_rx_vlan_filter_all_all, 3103 (void *)&cmd_rx_vlan_filter_all_portid, 3104 NULL, 3105 }, 3106 }; 3107 3108 /* *** VLAN OFFLOAD SET ON A PORT *** */ 3109 struct cmd_vlan_offload_result { 3110 cmdline_fixed_string_t vlan; 3111 cmdline_fixed_string_t set; 3112 cmdline_fixed_string_t vlan_type; 3113 cmdline_fixed_string_t what; 3114 cmdline_fixed_string_t on; 3115 cmdline_fixed_string_t port_id; 3116 }; 3117 3118 static void 3119 cmd_vlan_offload_parsed(void *parsed_result, 3120 __attribute__((unused)) struct cmdline *cl, 3121 __attribute__((unused)) void *data) 3122 { 3123 int on; 3124 struct cmd_vlan_offload_result *res = parsed_result; 3125 char *str; 3126 int i, len = 0; 3127 portid_t port_id = 0; 3128 unsigned int tmp; 3129 3130 str = res->port_id; 3131 len = strnlen(str, STR_TOKEN_SIZE); 3132 i = 0; 3133 /* Get port_id first */ 3134 while(i < len){ 3135 if(str[i] == ',') 3136 break; 3137 3138 i++; 3139 } 3140 str[i]='\0'; 3141 tmp = strtoul(str, NULL, 0); 3142 /* If port_id greater that what portid_t can represent, return */ 3143 if(tmp >= RTE_MAX_ETHPORTS) 3144 return; 3145 port_id = (portid_t)tmp; 3146 3147 if (!strcmp(res->on, "on")) 3148 on = 1; 3149 else 3150 on = 0; 3151 3152 if (!strcmp(res->what, "strip")) 3153 rx_vlan_strip_set(port_id, on); 3154 else if(!strcmp(res->what, "stripq")){ 3155 uint16_t queue_id = 0; 3156 3157 /* No queue_id, return */ 3158 if(i + 1 >= len) { 3159 printf("must specify (port,queue_id)\n"); 3160 return; 3161 } 3162 tmp = strtoul(str + i + 1, NULL, 0); 3163 /* If queue_id greater that what 16-bits can represent, return */ 3164 if(tmp > 0xffff) 3165 return; 3166 3167 queue_id = (uint16_t)tmp; 3168 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 3169 } 3170 else if (!strcmp(res->what, "filter")) 3171 rx_vlan_filter_set(port_id, on); 3172 else 3173 vlan_extend_set(port_id, on); 3174 3175 return; 3176 } 3177 3178 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 3179 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3180 vlan, "vlan"); 3181 cmdline_parse_token_string_t cmd_vlan_offload_set = 3182 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3183 set, "set"); 3184 cmdline_parse_token_string_t cmd_vlan_offload_what = 3185 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3186 what, "strip#filter#qinq#stripq"); 3187 cmdline_parse_token_string_t cmd_vlan_offload_on = 3188 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3189 on, "on#off"); 3190 cmdline_parse_token_string_t cmd_vlan_offload_portid = 3191 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3192 port_id, NULL); 3193 3194 cmdline_parse_inst_t cmd_vlan_offload = { 3195 .f = cmd_vlan_offload_parsed, 3196 .data = NULL, 3197 .help_str = "vlan set strip|filter|qinq|stripq on|off " 3198 "<port_id[,queue_id]>: " 3199 "Filter/Strip for rx side qinq(extended) for both rx/tx sides", 3200 .tokens = { 3201 (void *)&cmd_vlan_offload_vlan, 3202 (void *)&cmd_vlan_offload_set, 3203 (void *)&cmd_vlan_offload_what, 3204 (void *)&cmd_vlan_offload_on, 3205 (void *)&cmd_vlan_offload_portid, 3206 NULL, 3207 }, 3208 }; 3209 3210 /* *** VLAN TPID SET ON A PORT *** */ 3211 struct cmd_vlan_tpid_result { 3212 cmdline_fixed_string_t vlan; 3213 cmdline_fixed_string_t set; 3214 cmdline_fixed_string_t vlan_type; 3215 cmdline_fixed_string_t what; 3216 uint16_t tp_id; 3217 uint8_t port_id; 3218 }; 3219 3220 static void 3221 cmd_vlan_tpid_parsed(void *parsed_result, 3222 __attribute__((unused)) struct cmdline *cl, 3223 __attribute__((unused)) void *data) 3224 { 3225 struct cmd_vlan_tpid_result *res = parsed_result; 3226 enum rte_vlan_type vlan_type; 3227 3228 if (!strcmp(res->vlan_type, "inner")) 3229 vlan_type = ETH_VLAN_TYPE_INNER; 3230 else if (!strcmp(res->vlan_type, "outer")) 3231 vlan_type = ETH_VLAN_TYPE_OUTER; 3232 else { 3233 printf("Unknown vlan type\n"); 3234 return; 3235 } 3236 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 3237 } 3238 3239 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 3240 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3241 vlan, "vlan"); 3242 cmdline_parse_token_string_t cmd_vlan_tpid_set = 3243 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3244 set, "set"); 3245 cmdline_parse_token_string_t cmd_vlan_type = 3246 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3247 vlan_type, "inner#outer"); 3248 cmdline_parse_token_string_t cmd_vlan_tpid_what = 3249 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3250 what, "tpid"); 3251 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 3252 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3253 tp_id, UINT16); 3254 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 3255 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3256 port_id, UINT8); 3257 3258 cmdline_parse_inst_t cmd_vlan_tpid = { 3259 .f = cmd_vlan_tpid_parsed, 3260 .data = NULL, 3261 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 3262 "Set the VLAN Ether type", 3263 .tokens = { 3264 (void *)&cmd_vlan_tpid_vlan, 3265 (void *)&cmd_vlan_tpid_set, 3266 (void *)&cmd_vlan_type, 3267 (void *)&cmd_vlan_tpid_what, 3268 (void *)&cmd_vlan_tpid_tpid, 3269 (void *)&cmd_vlan_tpid_portid, 3270 NULL, 3271 }, 3272 }; 3273 3274 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 3275 struct cmd_rx_vlan_filter_result { 3276 cmdline_fixed_string_t rx_vlan; 3277 cmdline_fixed_string_t what; 3278 uint16_t vlan_id; 3279 uint8_t port_id; 3280 }; 3281 3282 static void 3283 cmd_rx_vlan_filter_parsed(void *parsed_result, 3284 __attribute__((unused)) struct cmdline *cl, 3285 __attribute__((unused)) void *data) 3286 { 3287 struct cmd_rx_vlan_filter_result *res = parsed_result; 3288 3289 if (!strcmp(res->what, "add")) 3290 rx_vft_set(res->port_id, res->vlan_id, 1); 3291 else 3292 rx_vft_set(res->port_id, res->vlan_id, 0); 3293 } 3294 3295 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 3296 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3297 rx_vlan, "rx_vlan"); 3298 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 3299 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3300 what, "add#rm"); 3301 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 3302 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3303 vlan_id, UINT16); 3304 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 3305 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3306 port_id, UINT8); 3307 3308 cmdline_parse_inst_t cmd_rx_vlan_filter = { 3309 .f = cmd_rx_vlan_filter_parsed, 3310 .data = NULL, 3311 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 3312 "Add/Remove a VLAN identifier to/from the set of VLAN " 3313 "identifiers filtered by a port", 3314 .tokens = { 3315 (void *)&cmd_rx_vlan_filter_rx_vlan, 3316 (void *)&cmd_rx_vlan_filter_what, 3317 (void *)&cmd_rx_vlan_filter_vlanid, 3318 (void *)&cmd_rx_vlan_filter_portid, 3319 NULL, 3320 }, 3321 }; 3322 3323 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3324 struct cmd_tx_vlan_set_result { 3325 cmdline_fixed_string_t tx_vlan; 3326 cmdline_fixed_string_t set; 3327 uint8_t port_id; 3328 uint16_t vlan_id; 3329 }; 3330 3331 static void 3332 cmd_tx_vlan_set_parsed(void *parsed_result, 3333 __attribute__((unused)) struct cmdline *cl, 3334 __attribute__((unused)) void *data) 3335 { 3336 struct cmd_tx_vlan_set_result *res = parsed_result; 3337 3338 tx_vlan_set(res->port_id, res->vlan_id); 3339 } 3340 3341 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 3342 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3343 tx_vlan, "tx_vlan"); 3344 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 3345 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3346 set, "set"); 3347 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 3348 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3349 port_id, UINT8); 3350 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 3351 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3352 vlan_id, UINT16); 3353 3354 cmdline_parse_inst_t cmd_tx_vlan_set = { 3355 .f = cmd_tx_vlan_set_parsed, 3356 .data = NULL, 3357 .help_str = "tx_vlan set <port_id> <vlan_id>: " 3358 "Enable hardware insertion of a single VLAN header " 3359 "with a given TAG Identifier in packets sent on a port", 3360 .tokens = { 3361 (void *)&cmd_tx_vlan_set_tx_vlan, 3362 (void *)&cmd_tx_vlan_set_set, 3363 (void *)&cmd_tx_vlan_set_portid, 3364 (void *)&cmd_tx_vlan_set_vlanid, 3365 NULL, 3366 }, 3367 }; 3368 3369 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 3370 struct cmd_tx_vlan_set_qinq_result { 3371 cmdline_fixed_string_t tx_vlan; 3372 cmdline_fixed_string_t set; 3373 uint8_t port_id; 3374 uint16_t vlan_id; 3375 uint16_t vlan_id_outer; 3376 }; 3377 3378 static void 3379 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 3380 __attribute__((unused)) struct cmdline *cl, 3381 __attribute__((unused)) void *data) 3382 { 3383 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 3384 3385 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 3386 } 3387 3388 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 3389 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3390 tx_vlan, "tx_vlan"); 3391 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 3392 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3393 set, "set"); 3394 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 3395 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3396 port_id, UINT8); 3397 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 3398 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3399 vlan_id, UINT16); 3400 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 3401 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3402 vlan_id_outer, UINT16); 3403 3404 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 3405 .f = cmd_tx_vlan_set_qinq_parsed, 3406 .data = NULL, 3407 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 3408 "Enable hardware insertion of double VLAN header " 3409 "with given TAG Identifiers in packets sent on a port", 3410 .tokens = { 3411 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 3412 (void *)&cmd_tx_vlan_set_qinq_set, 3413 (void *)&cmd_tx_vlan_set_qinq_portid, 3414 (void *)&cmd_tx_vlan_set_qinq_vlanid, 3415 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 3416 NULL, 3417 }, 3418 }; 3419 3420 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 3421 struct cmd_tx_vlan_set_pvid_result { 3422 cmdline_fixed_string_t tx_vlan; 3423 cmdline_fixed_string_t set; 3424 cmdline_fixed_string_t pvid; 3425 uint8_t port_id; 3426 uint16_t vlan_id; 3427 cmdline_fixed_string_t mode; 3428 }; 3429 3430 static void 3431 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 3432 __attribute__((unused)) struct cmdline *cl, 3433 __attribute__((unused)) void *data) 3434 { 3435 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 3436 3437 if (strcmp(res->mode, "on") == 0) 3438 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 3439 else 3440 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 3441 } 3442 3443 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 3444 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3445 tx_vlan, "tx_vlan"); 3446 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 3447 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3448 set, "set"); 3449 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 3450 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3451 pvid, "pvid"); 3452 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 3453 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3454 port_id, UINT8); 3455 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 3456 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3457 vlan_id, UINT16); 3458 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 3459 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3460 mode, "on#off"); 3461 3462 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 3463 .f = cmd_tx_vlan_set_pvid_parsed, 3464 .data = NULL, 3465 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 3466 .tokens = { 3467 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 3468 (void *)&cmd_tx_vlan_set_pvid_set, 3469 (void *)&cmd_tx_vlan_set_pvid_pvid, 3470 (void *)&cmd_tx_vlan_set_pvid_port_id, 3471 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 3472 (void *)&cmd_tx_vlan_set_pvid_mode, 3473 NULL, 3474 }, 3475 }; 3476 3477 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3478 struct cmd_tx_vlan_reset_result { 3479 cmdline_fixed_string_t tx_vlan; 3480 cmdline_fixed_string_t reset; 3481 uint8_t port_id; 3482 }; 3483 3484 static void 3485 cmd_tx_vlan_reset_parsed(void *parsed_result, 3486 __attribute__((unused)) struct cmdline *cl, 3487 __attribute__((unused)) void *data) 3488 { 3489 struct cmd_tx_vlan_reset_result *res = parsed_result; 3490 3491 tx_vlan_reset(res->port_id); 3492 } 3493 3494 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 3495 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3496 tx_vlan, "tx_vlan"); 3497 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 3498 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3499 reset, "reset"); 3500 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 3501 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 3502 port_id, UINT8); 3503 3504 cmdline_parse_inst_t cmd_tx_vlan_reset = { 3505 .f = cmd_tx_vlan_reset_parsed, 3506 .data = NULL, 3507 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 3508 "VLAN header in packets sent on a port", 3509 .tokens = { 3510 (void *)&cmd_tx_vlan_reset_tx_vlan, 3511 (void *)&cmd_tx_vlan_reset_reset, 3512 (void *)&cmd_tx_vlan_reset_portid, 3513 NULL, 3514 }, 3515 }; 3516 3517 3518 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 3519 struct cmd_csum_result { 3520 cmdline_fixed_string_t csum; 3521 cmdline_fixed_string_t mode; 3522 cmdline_fixed_string_t proto; 3523 cmdline_fixed_string_t hwsw; 3524 uint8_t port_id; 3525 }; 3526 3527 static void 3528 csum_show(int port_id) 3529 { 3530 struct rte_eth_dev_info dev_info; 3531 uint16_t ol_flags; 3532 3533 ol_flags = ports[port_id].tx_ol_flags; 3534 printf("Parse tunnel is %s\n", 3535 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off"); 3536 printf("IP checksum offload is %s\n", 3537 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw"); 3538 printf("UDP checksum offload is %s\n", 3539 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 3540 printf("TCP checksum offload is %s\n", 3541 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 3542 printf("SCTP checksum offload is %s\n", 3543 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 3544 printf("Outer-Ip checksum offload is %s\n", 3545 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw"); 3546 3547 /* display warnings if configuration is not supported by the NIC */ 3548 rte_eth_dev_info_get(port_id, &dev_info); 3549 if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) && 3550 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) { 3551 printf("Warning: hardware IP checksum enabled but not " 3552 "supported by port %d\n", port_id); 3553 } 3554 if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) && 3555 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) { 3556 printf("Warning: hardware UDP checksum enabled but not " 3557 "supported by port %d\n", port_id); 3558 } 3559 if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) && 3560 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) { 3561 printf("Warning: hardware TCP checksum enabled but not " 3562 "supported by port %d\n", port_id); 3563 } 3564 if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) && 3565 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) { 3566 printf("Warning: hardware SCTP checksum enabled but not " 3567 "supported by port %d\n", port_id); 3568 } 3569 if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) && 3570 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 3571 printf("Warning: hardware outer IP checksum enabled but not " 3572 "supported by port %d\n", port_id); 3573 } 3574 } 3575 3576 static void 3577 cmd_csum_parsed(void *parsed_result, 3578 __attribute__((unused)) struct cmdline *cl, 3579 __attribute__((unused)) void *data) 3580 { 3581 struct cmd_csum_result *res = parsed_result; 3582 int hw = 0; 3583 uint16_t mask = 0; 3584 3585 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 3586 printf("invalid port %d\n", res->port_id); 3587 return; 3588 } 3589 3590 if (!strcmp(res->mode, "set")) { 3591 3592 if (!strcmp(res->hwsw, "hw")) 3593 hw = 1; 3594 3595 if (!strcmp(res->proto, "ip")) { 3596 mask = TESTPMD_TX_OFFLOAD_IP_CKSUM; 3597 } else if (!strcmp(res->proto, "udp")) { 3598 mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM; 3599 } else if (!strcmp(res->proto, "tcp")) { 3600 mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM; 3601 } else if (!strcmp(res->proto, "sctp")) { 3602 mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM; 3603 } else if (!strcmp(res->proto, "outer-ip")) { 3604 mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM; 3605 } 3606 3607 if (hw) 3608 ports[res->port_id].tx_ol_flags |= mask; 3609 else 3610 ports[res->port_id].tx_ol_flags &= (~mask); 3611 } 3612 csum_show(res->port_id); 3613 } 3614 3615 cmdline_parse_token_string_t cmd_csum_csum = 3616 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3617 csum, "csum"); 3618 cmdline_parse_token_string_t cmd_csum_mode = 3619 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3620 mode, "set"); 3621 cmdline_parse_token_string_t cmd_csum_proto = 3622 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3623 proto, "ip#tcp#udp#sctp#outer-ip"); 3624 cmdline_parse_token_string_t cmd_csum_hwsw = 3625 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3626 hwsw, "hw#sw"); 3627 cmdline_parse_token_num_t cmd_csum_portid = 3628 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 3629 port_id, UINT8); 3630 3631 cmdline_parse_inst_t cmd_csum_set = { 3632 .f = cmd_csum_parsed, 3633 .data = NULL, 3634 .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: " 3635 "Enable/Disable hardware calculation of L3/L4 checksum when " 3636 "using csum forward engine", 3637 .tokens = { 3638 (void *)&cmd_csum_csum, 3639 (void *)&cmd_csum_mode, 3640 (void *)&cmd_csum_proto, 3641 (void *)&cmd_csum_hwsw, 3642 (void *)&cmd_csum_portid, 3643 NULL, 3644 }, 3645 }; 3646 3647 cmdline_parse_token_string_t cmd_csum_mode_show = 3648 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3649 mode, "show"); 3650 3651 cmdline_parse_inst_t cmd_csum_show = { 3652 .f = cmd_csum_parsed, 3653 .data = NULL, 3654 .help_str = "csum show <port_id>: Show checksum offload configuration", 3655 .tokens = { 3656 (void *)&cmd_csum_csum, 3657 (void *)&cmd_csum_mode_show, 3658 (void *)&cmd_csum_portid, 3659 NULL, 3660 }, 3661 }; 3662 3663 /* Enable/disable tunnel parsing */ 3664 struct cmd_csum_tunnel_result { 3665 cmdline_fixed_string_t csum; 3666 cmdline_fixed_string_t parse; 3667 cmdline_fixed_string_t onoff; 3668 uint8_t port_id; 3669 }; 3670 3671 static void 3672 cmd_csum_tunnel_parsed(void *parsed_result, 3673 __attribute__((unused)) struct cmdline *cl, 3674 __attribute__((unused)) void *data) 3675 { 3676 struct cmd_csum_tunnel_result *res = parsed_result; 3677 3678 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3679 return; 3680 3681 if (!strcmp(res->onoff, "on")) 3682 ports[res->port_id].tx_ol_flags |= 3683 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL; 3684 else 3685 ports[res->port_id].tx_ol_flags &= 3686 (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL); 3687 3688 csum_show(res->port_id); 3689 } 3690 3691 cmdline_parse_token_string_t cmd_csum_tunnel_csum = 3692 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3693 csum, "csum"); 3694 cmdline_parse_token_string_t cmd_csum_tunnel_parse = 3695 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3696 parse, "parse_tunnel"); 3697 cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 3698 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3699 onoff, "on#off"); 3700 cmdline_parse_token_num_t cmd_csum_tunnel_portid = 3701 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 3702 port_id, UINT8); 3703 3704 cmdline_parse_inst_t cmd_csum_tunnel = { 3705 .f = cmd_csum_tunnel_parsed, 3706 .data = NULL, 3707 .help_str = "csum parse_tunnel on|off <port_id>: " 3708 "Enable/Disable parsing of tunnels for csum engine", 3709 .tokens = { 3710 (void *)&cmd_csum_tunnel_csum, 3711 (void *)&cmd_csum_tunnel_parse, 3712 (void *)&cmd_csum_tunnel_onoff, 3713 (void *)&cmd_csum_tunnel_portid, 3714 NULL, 3715 }, 3716 }; 3717 3718 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 3719 struct cmd_tso_set_result { 3720 cmdline_fixed_string_t tso; 3721 cmdline_fixed_string_t mode; 3722 uint16_t tso_segsz; 3723 uint8_t port_id; 3724 }; 3725 3726 static void 3727 cmd_tso_set_parsed(void *parsed_result, 3728 __attribute__((unused)) struct cmdline *cl, 3729 __attribute__((unused)) void *data) 3730 { 3731 struct cmd_tso_set_result *res = parsed_result; 3732 struct rte_eth_dev_info dev_info; 3733 3734 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3735 return; 3736 3737 if (!strcmp(res->mode, "set")) 3738 ports[res->port_id].tso_segsz = res->tso_segsz; 3739 3740 if (ports[res->port_id].tso_segsz == 0) 3741 printf("TSO for non-tunneled packets is disabled\n"); 3742 else 3743 printf("TSO segment size for non-tunneled packets is %d\n", 3744 ports[res->port_id].tso_segsz); 3745 3746 /* display warnings if configuration is not supported by the NIC */ 3747 rte_eth_dev_info_get(res->port_id, &dev_info); 3748 if ((ports[res->port_id].tso_segsz != 0) && 3749 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3750 printf("Warning: TSO enabled but not " 3751 "supported by port %d\n", res->port_id); 3752 } 3753 } 3754 3755 cmdline_parse_token_string_t cmd_tso_set_tso = 3756 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3757 tso, "tso"); 3758 cmdline_parse_token_string_t cmd_tso_set_mode = 3759 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3760 mode, "set"); 3761 cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 3762 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3763 tso_segsz, UINT16); 3764 cmdline_parse_token_num_t cmd_tso_set_portid = 3765 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3766 port_id, UINT8); 3767 3768 cmdline_parse_inst_t cmd_tso_set = { 3769 .f = cmd_tso_set_parsed, 3770 .data = NULL, 3771 .help_str = "tso set <tso_segsz> <port_id>: " 3772 "Set TSO segment size of non-tunneled packets for csum engine " 3773 "(0 to disable)", 3774 .tokens = { 3775 (void *)&cmd_tso_set_tso, 3776 (void *)&cmd_tso_set_mode, 3777 (void *)&cmd_tso_set_tso_segsz, 3778 (void *)&cmd_tso_set_portid, 3779 NULL, 3780 }, 3781 }; 3782 3783 cmdline_parse_token_string_t cmd_tso_show_mode = 3784 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3785 mode, "show"); 3786 3787 3788 cmdline_parse_inst_t cmd_tso_show = { 3789 .f = cmd_tso_set_parsed, 3790 .data = NULL, 3791 .help_str = "tso show <port_id>: " 3792 "Show TSO segment size of non-tunneled packets for csum engine", 3793 .tokens = { 3794 (void *)&cmd_tso_set_tso, 3795 (void *)&cmd_tso_show_mode, 3796 (void *)&cmd_tso_set_portid, 3797 NULL, 3798 }, 3799 }; 3800 3801 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 3802 struct cmd_tunnel_tso_set_result { 3803 cmdline_fixed_string_t tso; 3804 cmdline_fixed_string_t mode; 3805 uint16_t tso_segsz; 3806 uint8_t port_id; 3807 }; 3808 3809 static void 3810 check_tunnel_tso_nic_support(uint8_t port_id) 3811 { 3812 struct rte_eth_dev_info dev_info; 3813 3814 rte_eth_dev_info_get(port_id, &dev_info); 3815 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) 3816 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not " 3817 "supported by port %d\n", port_id); 3818 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO)) 3819 printf("Warning: TSO enabled but GRE TUNNEL TSO not " 3820 "supported by port %d\n", port_id); 3821 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO)) 3822 printf("Warning: TSO enabled but IPIP TUNNEL TSO not " 3823 "supported by port %d\n", port_id); 3824 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) 3825 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not " 3826 "supported by port %d\n", port_id); 3827 } 3828 3829 static void 3830 cmd_tunnel_tso_set_parsed(void *parsed_result, 3831 __attribute__((unused)) struct cmdline *cl, 3832 __attribute__((unused)) void *data) 3833 { 3834 struct cmd_tunnel_tso_set_result *res = parsed_result; 3835 3836 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3837 return; 3838 3839 if (!strcmp(res->mode, "set")) 3840 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 3841 3842 if (ports[res->port_id].tunnel_tso_segsz == 0) 3843 printf("TSO for tunneled packets is disabled\n"); 3844 else { 3845 printf("TSO segment size for tunneled packets is %d\n", 3846 ports[res->port_id].tunnel_tso_segsz); 3847 3848 /* Below conditions are needed to make it work: 3849 * (1) tunnel TSO is supported by the NIC; 3850 * (2) "csum parse_tunnel" must be set so that tunneled pkts 3851 * are recognized; 3852 * (3) for tunneled pkts with outer L3 of IPv4, 3853 * "csum set outer-ip" must be set to hw, because after tso, 3854 * total_len of outer IP header is changed, and the checksum 3855 * of outer IP header calculated by sw should be wrong; that 3856 * is not necessary for IPv6 tunneled pkts because there's no 3857 * checksum in IP header anymore. 3858 */ 3859 check_tunnel_tso_nic_support(res->port_id); 3860 3861 if (!(ports[res->port_id].tx_ol_flags & 3862 TESTPMD_TX_OFFLOAD_PARSE_TUNNEL)) 3863 printf("Warning: csum parse_tunnel must be set " 3864 "so that tunneled packets are recognized\n"); 3865 if (!(ports[res->port_id].tx_ol_flags & 3866 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)) 3867 printf("Warning: csum set outer-ip must be set to hw " 3868 "if outer L3 is IPv4; not necessary for IPv6\n"); 3869 } 3870 } 3871 3872 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 3873 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3874 tso, "tunnel_tso"); 3875 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 3876 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3877 mode, "set"); 3878 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 3879 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3880 tso_segsz, UINT16); 3881 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 3882 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 3883 port_id, UINT8); 3884 3885 cmdline_parse_inst_t cmd_tunnel_tso_set = { 3886 .f = cmd_tunnel_tso_set_parsed, 3887 .data = NULL, 3888 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 3889 "Set TSO segment size of tunneled packets for csum engine " 3890 "(0 to disable)", 3891 .tokens = { 3892 (void *)&cmd_tunnel_tso_set_tso, 3893 (void *)&cmd_tunnel_tso_set_mode, 3894 (void *)&cmd_tunnel_tso_set_tso_segsz, 3895 (void *)&cmd_tunnel_tso_set_portid, 3896 NULL, 3897 }, 3898 }; 3899 3900 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 3901 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 3902 mode, "show"); 3903 3904 3905 cmdline_parse_inst_t cmd_tunnel_tso_show = { 3906 .f = cmd_tunnel_tso_set_parsed, 3907 .data = NULL, 3908 .help_str = "tunnel_tso show <port_id> " 3909 "Show TSO segment size of tunneled packets for csum engine", 3910 .tokens = { 3911 (void *)&cmd_tunnel_tso_set_tso, 3912 (void *)&cmd_tunnel_tso_show_mode, 3913 (void *)&cmd_tunnel_tso_set_portid, 3914 NULL, 3915 }, 3916 }; 3917 3918 /* *** SET GRO FOR A PORT *** */ 3919 struct cmd_gro_enable_result { 3920 cmdline_fixed_string_t cmd_set; 3921 cmdline_fixed_string_t cmd_port; 3922 cmdline_fixed_string_t cmd_keyword; 3923 cmdline_fixed_string_t cmd_onoff; 3924 portid_t cmd_pid; 3925 }; 3926 3927 static void 3928 cmd_gro_enable_parsed(void *parsed_result, 3929 __attribute__((unused)) struct cmdline *cl, 3930 __attribute__((unused)) void *data) 3931 { 3932 struct cmd_gro_enable_result *res; 3933 3934 res = parsed_result; 3935 if (!strcmp(res->cmd_keyword, "gro")) 3936 setup_gro(res->cmd_onoff, res->cmd_pid); 3937 } 3938 3939 cmdline_parse_token_string_t cmd_gro_enable_set = 3940 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 3941 cmd_set, "set"); 3942 cmdline_parse_token_string_t cmd_gro_enable_port = 3943 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 3944 cmd_keyword, "port"); 3945 cmdline_parse_token_num_t cmd_gro_enable_pid = 3946 TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result, 3947 cmd_pid, UINT16); 3948 cmdline_parse_token_string_t cmd_gro_enable_keyword = 3949 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 3950 cmd_keyword, "gro"); 3951 cmdline_parse_token_string_t cmd_gro_enable_onoff = 3952 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 3953 cmd_onoff, "on#off"); 3954 3955 cmdline_parse_inst_t cmd_gro_enable = { 3956 .f = cmd_gro_enable_parsed, 3957 .data = NULL, 3958 .help_str = "set port <port_id> gro on|off", 3959 .tokens = { 3960 (void *)&cmd_gro_enable_set, 3961 (void *)&cmd_gro_enable_port, 3962 (void *)&cmd_gro_enable_pid, 3963 (void *)&cmd_gro_enable_keyword, 3964 (void *)&cmd_gro_enable_onoff, 3965 NULL, 3966 }, 3967 }; 3968 3969 /* *** DISPLAY GRO CONFIGURATION *** */ 3970 struct cmd_gro_show_result { 3971 cmdline_fixed_string_t cmd_show; 3972 cmdline_fixed_string_t cmd_port; 3973 cmdline_fixed_string_t cmd_keyword; 3974 portid_t cmd_pid; 3975 }; 3976 3977 static void 3978 cmd_gro_show_parsed(void *parsed_result, 3979 __attribute__((unused)) struct cmdline *cl, 3980 __attribute__((unused)) void *data) 3981 { 3982 struct cmd_gro_show_result *res; 3983 3984 res = parsed_result; 3985 if (!strcmp(res->cmd_keyword, "gro")) 3986 show_gro(res->cmd_pid); 3987 } 3988 3989 cmdline_parse_token_string_t cmd_gro_show_show = 3990 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 3991 cmd_show, "show"); 3992 cmdline_parse_token_string_t cmd_gro_show_port = 3993 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 3994 cmd_port, "port"); 3995 cmdline_parse_token_num_t cmd_gro_show_pid = 3996 TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result, 3997 cmd_pid, UINT16); 3998 cmdline_parse_token_string_t cmd_gro_show_keyword = 3999 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 4000 cmd_keyword, "gro"); 4001 4002 cmdline_parse_inst_t cmd_gro_show = { 4003 .f = cmd_gro_show_parsed, 4004 .data = NULL, 4005 .help_str = "show port <port_id> gro", 4006 .tokens = { 4007 (void *)&cmd_gro_show_show, 4008 (void *)&cmd_gro_show_port, 4009 (void *)&cmd_gro_show_pid, 4010 (void *)&cmd_gro_show_keyword, 4011 NULL, 4012 }, 4013 }; 4014 4015 /* *** SET FLUSH CYCLES FOR GRO *** */ 4016 struct cmd_gro_flush_result { 4017 cmdline_fixed_string_t cmd_set; 4018 cmdline_fixed_string_t cmd_keyword; 4019 cmdline_fixed_string_t cmd_flush; 4020 uint8_t cmd_cycles; 4021 }; 4022 4023 static void 4024 cmd_gro_flush_parsed(void *parsed_result, 4025 __attribute__((unused)) struct cmdline *cl, 4026 __attribute__((unused)) void *data) 4027 { 4028 struct cmd_gro_flush_result *res; 4029 4030 res = parsed_result; 4031 if ((!strcmp(res->cmd_keyword, "gro")) && 4032 (!strcmp(res->cmd_flush, "flush"))) 4033 setup_gro_flush_cycles(res->cmd_cycles); 4034 } 4035 4036 cmdline_parse_token_string_t cmd_gro_flush_set = 4037 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4038 cmd_set, "set"); 4039 cmdline_parse_token_string_t cmd_gro_flush_keyword = 4040 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4041 cmd_keyword, "gro"); 4042 cmdline_parse_token_string_t cmd_gro_flush_flush = 4043 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4044 cmd_flush, "flush"); 4045 cmdline_parse_token_num_t cmd_gro_flush_cycles = 4046 TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result, 4047 cmd_cycles, UINT8); 4048 4049 cmdline_parse_inst_t cmd_gro_flush = { 4050 .f = cmd_gro_flush_parsed, 4051 .data = NULL, 4052 .help_str = "set gro flush <cycles>", 4053 .tokens = { 4054 (void *)&cmd_gro_flush_set, 4055 (void *)&cmd_gro_flush_keyword, 4056 (void *)&cmd_gro_flush_flush, 4057 (void *)&cmd_gro_flush_cycles, 4058 NULL, 4059 }, 4060 }; 4061 4062 /* *** ENABLE/DISABLE GSO *** */ 4063 struct cmd_gso_enable_result { 4064 cmdline_fixed_string_t cmd_set; 4065 cmdline_fixed_string_t cmd_port; 4066 cmdline_fixed_string_t cmd_keyword; 4067 cmdline_fixed_string_t cmd_mode; 4068 portid_t cmd_pid; 4069 }; 4070 4071 static void 4072 cmd_gso_enable_parsed(void *parsed_result, 4073 __attribute__((unused)) struct cmdline *cl, 4074 __attribute__((unused)) void *data) 4075 { 4076 struct cmd_gso_enable_result *res; 4077 4078 res = parsed_result; 4079 if (!strcmp(res->cmd_keyword, "gso")) 4080 setup_gso(res->cmd_mode, res->cmd_pid); 4081 } 4082 4083 cmdline_parse_token_string_t cmd_gso_enable_set = 4084 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4085 cmd_set, "set"); 4086 cmdline_parse_token_string_t cmd_gso_enable_port = 4087 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4088 cmd_port, "port"); 4089 cmdline_parse_token_string_t cmd_gso_enable_keyword = 4090 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4091 cmd_keyword, "gso"); 4092 cmdline_parse_token_string_t cmd_gso_enable_mode = 4093 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4094 cmd_mode, "on#off"); 4095 cmdline_parse_token_num_t cmd_gso_enable_pid = 4096 TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result, 4097 cmd_pid, UINT16); 4098 4099 cmdline_parse_inst_t cmd_gso_enable = { 4100 .f = cmd_gso_enable_parsed, 4101 .data = NULL, 4102 .help_str = "set port <port_id> gso on|off", 4103 .tokens = { 4104 (void *)&cmd_gso_enable_set, 4105 (void *)&cmd_gso_enable_port, 4106 (void *)&cmd_gso_enable_pid, 4107 (void *)&cmd_gso_enable_keyword, 4108 (void *)&cmd_gso_enable_mode, 4109 NULL, 4110 }, 4111 }; 4112 4113 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */ 4114 struct cmd_gso_size_result { 4115 cmdline_fixed_string_t cmd_set; 4116 cmdline_fixed_string_t cmd_keyword; 4117 cmdline_fixed_string_t cmd_segsz; 4118 uint16_t cmd_size; 4119 }; 4120 4121 static void 4122 cmd_gso_size_parsed(void *parsed_result, 4123 __attribute__((unused)) struct cmdline *cl, 4124 __attribute__((unused)) void *data) 4125 { 4126 struct cmd_gso_size_result *res = parsed_result; 4127 4128 if (test_done == 0) { 4129 printf("Before setting GSO segsz, please first" 4130 " stop fowarding\n"); 4131 return; 4132 } 4133 4134 if (!strcmp(res->cmd_keyword, "gso") && 4135 !strcmp(res->cmd_segsz, "segsz")) { 4136 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN) 4137 printf("gso_size should be larger than %zu." 4138 " Please input a legal value\n", 4139 RTE_GSO_SEG_SIZE_MIN); 4140 else 4141 gso_max_segment_size = res->cmd_size; 4142 } 4143 } 4144 4145 cmdline_parse_token_string_t cmd_gso_size_set = 4146 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4147 cmd_set, "set"); 4148 cmdline_parse_token_string_t cmd_gso_size_keyword = 4149 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4150 cmd_keyword, "gso"); 4151 cmdline_parse_token_string_t cmd_gso_size_segsz = 4152 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4153 cmd_segsz, "segsz"); 4154 cmdline_parse_token_num_t cmd_gso_size_size = 4155 TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result, 4156 cmd_size, UINT16); 4157 4158 cmdline_parse_inst_t cmd_gso_size = { 4159 .f = cmd_gso_size_parsed, 4160 .data = NULL, 4161 .help_str = "set gso segsz <length>", 4162 .tokens = { 4163 (void *)&cmd_gso_size_set, 4164 (void *)&cmd_gso_size_keyword, 4165 (void *)&cmd_gso_size_segsz, 4166 (void *)&cmd_gso_size_size, 4167 NULL, 4168 }, 4169 }; 4170 4171 /* *** SHOW GSO CONFIGURATION *** */ 4172 struct cmd_gso_show_result { 4173 cmdline_fixed_string_t cmd_show; 4174 cmdline_fixed_string_t cmd_port; 4175 cmdline_fixed_string_t cmd_keyword; 4176 portid_t cmd_pid; 4177 }; 4178 4179 static void 4180 cmd_gso_show_parsed(void *parsed_result, 4181 __attribute__((unused)) struct cmdline *cl, 4182 __attribute__((unused)) void *data) 4183 { 4184 struct cmd_gso_show_result *res = parsed_result; 4185 4186 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 4187 printf("invalid port id %u\n", res->cmd_pid); 4188 return; 4189 } 4190 if (!strcmp(res->cmd_keyword, "gso")) { 4191 if (gso_ports[res->cmd_pid].enable) { 4192 printf("Max GSO'd packet size: %uB\n" 4193 "Supported GSO types: TCP/IPv4, " 4194 "VxLAN with inner TCP/IPv4 packet, " 4195 "GRE with inner TCP/IPv4 packet\n", 4196 gso_max_segment_size); 4197 } else 4198 printf("GSO is not enabled on Port %u\n", res->cmd_pid); 4199 } 4200 } 4201 4202 cmdline_parse_token_string_t cmd_gso_show_show = 4203 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4204 cmd_show, "show"); 4205 cmdline_parse_token_string_t cmd_gso_show_port = 4206 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4207 cmd_port, "port"); 4208 cmdline_parse_token_string_t cmd_gso_show_keyword = 4209 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4210 cmd_keyword, "gso"); 4211 cmdline_parse_token_num_t cmd_gso_show_pid = 4212 TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result, 4213 cmd_pid, UINT16); 4214 4215 cmdline_parse_inst_t cmd_gso_show = { 4216 .f = cmd_gso_show_parsed, 4217 .data = NULL, 4218 .help_str = "show port <port_id> gso", 4219 .tokens = { 4220 (void *)&cmd_gso_show_show, 4221 (void *)&cmd_gso_show_port, 4222 (void *)&cmd_gso_show_pid, 4223 (void *)&cmd_gso_show_keyword, 4224 NULL, 4225 }, 4226 }; 4227 4228 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 4229 struct cmd_set_flush_rx { 4230 cmdline_fixed_string_t set; 4231 cmdline_fixed_string_t flush_rx; 4232 cmdline_fixed_string_t mode; 4233 }; 4234 4235 static void 4236 cmd_set_flush_rx_parsed(void *parsed_result, 4237 __attribute__((unused)) struct cmdline *cl, 4238 __attribute__((unused)) void *data) 4239 { 4240 struct cmd_set_flush_rx *res = parsed_result; 4241 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 4242 } 4243 4244 cmdline_parse_token_string_t cmd_setflushrx_set = 4245 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4246 set, "set"); 4247 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 4248 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4249 flush_rx, "flush_rx"); 4250 cmdline_parse_token_string_t cmd_setflushrx_mode = 4251 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4252 mode, "on#off"); 4253 4254 4255 cmdline_parse_inst_t cmd_set_flush_rx = { 4256 .f = cmd_set_flush_rx_parsed, 4257 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 4258 .data = NULL, 4259 .tokens = { 4260 (void *)&cmd_setflushrx_set, 4261 (void *)&cmd_setflushrx_flush_rx, 4262 (void *)&cmd_setflushrx_mode, 4263 NULL, 4264 }, 4265 }; 4266 4267 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 4268 struct cmd_set_link_check { 4269 cmdline_fixed_string_t set; 4270 cmdline_fixed_string_t link_check; 4271 cmdline_fixed_string_t mode; 4272 }; 4273 4274 static void 4275 cmd_set_link_check_parsed(void *parsed_result, 4276 __attribute__((unused)) struct cmdline *cl, 4277 __attribute__((unused)) void *data) 4278 { 4279 struct cmd_set_link_check *res = parsed_result; 4280 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 4281 } 4282 4283 cmdline_parse_token_string_t cmd_setlinkcheck_set = 4284 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4285 set, "set"); 4286 cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 4287 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4288 link_check, "link_check"); 4289 cmdline_parse_token_string_t cmd_setlinkcheck_mode = 4290 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4291 mode, "on#off"); 4292 4293 4294 cmdline_parse_inst_t cmd_set_link_check = { 4295 .f = cmd_set_link_check_parsed, 4296 .help_str = "set link_check on|off: Enable/Disable link status check " 4297 "when starting/stopping a port", 4298 .data = NULL, 4299 .tokens = { 4300 (void *)&cmd_setlinkcheck_set, 4301 (void *)&cmd_setlinkcheck_link_check, 4302 (void *)&cmd_setlinkcheck_mode, 4303 NULL, 4304 }, 4305 }; 4306 4307 /* *** SET NIC BYPASS MODE *** */ 4308 struct cmd_set_bypass_mode_result { 4309 cmdline_fixed_string_t set; 4310 cmdline_fixed_string_t bypass; 4311 cmdline_fixed_string_t mode; 4312 cmdline_fixed_string_t value; 4313 uint8_t port_id; 4314 }; 4315 4316 static void 4317 cmd_set_bypass_mode_parsed(void *parsed_result, 4318 __attribute__((unused)) struct cmdline *cl, 4319 __attribute__((unused)) void *data) 4320 { 4321 struct cmd_set_bypass_mode_result *res = parsed_result; 4322 portid_t port_id = res->port_id; 4323 int32_t rc = -EINVAL; 4324 4325 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4326 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4327 4328 if (!strcmp(res->value, "bypass")) 4329 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4330 else if (!strcmp(res->value, "isolate")) 4331 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4332 else 4333 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4334 4335 /* Set the bypass mode for the relevant port. */ 4336 rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); 4337 #endif 4338 if (rc != 0) 4339 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 4340 } 4341 4342 cmdline_parse_token_string_t cmd_setbypass_mode_set = 4343 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4344 set, "set"); 4345 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 4346 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4347 bypass, "bypass"); 4348 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 4349 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4350 mode, "mode"); 4351 cmdline_parse_token_string_t cmd_setbypass_mode_value = 4352 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4353 value, "normal#bypass#isolate"); 4354 cmdline_parse_token_num_t cmd_setbypass_mode_port = 4355 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 4356 port_id, UINT8); 4357 4358 cmdline_parse_inst_t cmd_set_bypass_mode = { 4359 .f = cmd_set_bypass_mode_parsed, 4360 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 4361 "Set the NIC bypass mode for port_id", 4362 .data = NULL, 4363 .tokens = { 4364 (void *)&cmd_setbypass_mode_set, 4365 (void *)&cmd_setbypass_mode_bypass, 4366 (void *)&cmd_setbypass_mode_mode, 4367 (void *)&cmd_setbypass_mode_value, 4368 (void *)&cmd_setbypass_mode_port, 4369 NULL, 4370 }, 4371 }; 4372 4373 /* *** SET NIC BYPASS EVENT *** */ 4374 struct cmd_set_bypass_event_result { 4375 cmdline_fixed_string_t set; 4376 cmdline_fixed_string_t bypass; 4377 cmdline_fixed_string_t event; 4378 cmdline_fixed_string_t event_value; 4379 cmdline_fixed_string_t mode; 4380 cmdline_fixed_string_t mode_value; 4381 uint8_t port_id; 4382 }; 4383 4384 static void 4385 cmd_set_bypass_event_parsed(void *parsed_result, 4386 __attribute__((unused)) struct cmdline *cl, 4387 __attribute__((unused)) void *data) 4388 { 4389 int32_t rc = -EINVAL; 4390 struct cmd_set_bypass_event_result *res = parsed_result; 4391 portid_t port_id = res->port_id; 4392 4393 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4394 uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4395 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4396 4397 if (!strcmp(res->event_value, "timeout")) 4398 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; 4399 else if (!strcmp(res->event_value, "os_on")) 4400 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; 4401 else if (!strcmp(res->event_value, "os_off")) 4402 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; 4403 else if (!strcmp(res->event_value, "power_on")) 4404 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; 4405 else if (!strcmp(res->event_value, "power_off")) 4406 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; 4407 else 4408 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4409 4410 if (!strcmp(res->mode_value, "bypass")) 4411 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4412 else if (!strcmp(res->mode_value, "isolate")) 4413 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4414 else 4415 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4416 4417 /* Set the watchdog timeout. */ 4418 if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { 4419 4420 rc = -EINVAL; 4421 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { 4422 rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, 4423 bypass_timeout); 4424 } 4425 if (rc != 0) { 4426 printf("Failed to set timeout value %u " 4427 "for port %d, errto code: %d.\n", 4428 bypass_timeout, port_id, rc); 4429 } 4430 } 4431 4432 /* Set the bypass event to transition to bypass mode. */ 4433 rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, 4434 bypass_mode); 4435 #endif 4436 4437 if (rc != 0) 4438 printf("\t Failed to set bypass event for port = %d.\n", 4439 port_id); 4440 } 4441 4442 cmdline_parse_token_string_t cmd_setbypass_event_set = 4443 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4444 set, "set"); 4445 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 4446 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4447 bypass, "bypass"); 4448 cmdline_parse_token_string_t cmd_setbypass_event_event = 4449 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4450 event, "event"); 4451 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 4452 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4453 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 4454 cmdline_parse_token_string_t cmd_setbypass_event_mode = 4455 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4456 mode, "mode"); 4457 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 4458 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4459 mode_value, "normal#bypass#isolate"); 4460 cmdline_parse_token_num_t cmd_setbypass_event_port = 4461 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 4462 port_id, UINT8); 4463 4464 cmdline_parse_inst_t cmd_set_bypass_event = { 4465 .f = cmd_set_bypass_event_parsed, 4466 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 4467 "power_off mode normal|bypass|isolate <port_id>: " 4468 "Set the NIC bypass event mode for port_id", 4469 .data = NULL, 4470 .tokens = { 4471 (void *)&cmd_setbypass_event_set, 4472 (void *)&cmd_setbypass_event_bypass, 4473 (void *)&cmd_setbypass_event_event, 4474 (void *)&cmd_setbypass_event_event_value, 4475 (void *)&cmd_setbypass_event_mode, 4476 (void *)&cmd_setbypass_event_mode_value, 4477 (void *)&cmd_setbypass_event_port, 4478 NULL, 4479 }, 4480 }; 4481 4482 4483 /* *** SET NIC BYPASS TIMEOUT *** */ 4484 struct cmd_set_bypass_timeout_result { 4485 cmdline_fixed_string_t set; 4486 cmdline_fixed_string_t bypass; 4487 cmdline_fixed_string_t timeout; 4488 cmdline_fixed_string_t value; 4489 }; 4490 4491 static void 4492 cmd_set_bypass_timeout_parsed(void *parsed_result, 4493 __attribute__((unused)) struct cmdline *cl, 4494 __attribute__((unused)) void *data) 4495 { 4496 __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result; 4497 4498 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4499 if (!strcmp(res->value, "1.5")) 4500 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; 4501 else if (!strcmp(res->value, "2")) 4502 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; 4503 else if (!strcmp(res->value, "3")) 4504 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; 4505 else if (!strcmp(res->value, "4")) 4506 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; 4507 else if (!strcmp(res->value, "8")) 4508 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; 4509 else if (!strcmp(res->value, "16")) 4510 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; 4511 else if (!strcmp(res->value, "32")) 4512 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; 4513 else 4514 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4515 #endif 4516 } 4517 4518 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 4519 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4520 set, "set"); 4521 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 4522 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4523 bypass, "bypass"); 4524 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 4525 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4526 timeout, "timeout"); 4527 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 4528 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4529 value, "0#1.5#2#3#4#8#16#32"); 4530 4531 cmdline_parse_inst_t cmd_set_bypass_timeout = { 4532 .f = cmd_set_bypass_timeout_parsed, 4533 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 4534 "Set the NIC bypass watchdog timeout in seconds", 4535 .data = NULL, 4536 .tokens = { 4537 (void *)&cmd_setbypass_timeout_set, 4538 (void *)&cmd_setbypass_timeout_bypass, 4539 (void *)&cmd_setbypass_timeout_timeout, 4540 (void *)&cmd_setbypass_timeout_value, 4541 NULL, 4542 }, 4543 }; 4544 4545 /* *** SHOW NIC BYPASS MODE *** */ 4546 struct cmd_show_bypass_config_result { 4547 cmdline_fixed_string_t show; 4548 cmdline_fixed_string_t bypass; 4549 cmdline_fixed_string_t config; 4550 uint8_t port_id; 4551 }; 4552 4553 static void 4554 cmd_show_bypass_config_parsed(void *parsed_result, 4555 __attribute__((unused)) struct cmdline *cl, 4556 __attribute__((unused)) void *data) 4557 { 4558 struct cmd_show_bypass_config_result *res = parsed_result; 4559 portid_t port_id = res->port_id; 4560 int rc = -EINVAL; 4561 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4562 uint32_t event_mode; 4563 uint32_t bypass_mode; 4564 uint32_t timeout = bypass_timeout; 4565 int i; 4566 4567 static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = 4568 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 4569 static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = 4570 {"UNKNOWN", "normal", "bypass", "isolate"}; 4571 static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { 4572 "NONE", 4573 "OS/board on", 4574 "power supply on", 4575 "OS/board off", 4576 "power supply off", 4577 "timeout"}; 4578 int num_events = (sizeof events) / (sizeof events[0]); 4579 4580 /* Display the bypass mode.*/ 4581 if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { 4582 printf("\tFailed to get bypass mode for port = %d\n", port_id); 4583 return; 4584 } 4585 else { 4586 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) 4587 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4588 4589 printf("\tbypass mode = %s\n", modes[bypass_mode]); 4590 } 4591 4592 /* Display the bypass timeout.*/ 4593 if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) 4594 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4595 4596 printf("\tbypass timeout = %s\n", timeouts[timeout]); 4597 4598 /* Display the bypass events and associated modes. */ 4599 for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) { 4600 4601 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { 4602 printf("\tFailed to get bypass mode for event = %s\n", 4603 events[i]); 4604 } else { 4605 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) 4606 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4607 4608 printf("\tbypass event: %-16s = %s\n", events[i], 4609 modes[event_mode]); 4610 } 4611 } 4612 #endif 4613 if (rc != 0) 4614 printf("\tFailed to get bypass configuration for port = %d\n", 4615 port_id); 4616 } 4617 4618 cmdline_parse_token_string_t cmd_showbypass_config_show = 4619 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4620 show, "show"); 4621 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 4622 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4623 bypass, "bypass"); 4624 cmdline_parse_token_string_t cmd_showbypass_config_config = 4625 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4626 config, "config"); 4627 cmdline_parse_token_num_t cmd_showbypass_config_port = 4628 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 4629 port_id, UINT8); 4630 4631 cmdline_parse_inst_t cmd_show_bypass_config = { 4632 .f = cmd_show_bypass_config_parsed, 4633 .help_str = "show bypass config <port_id>: " 4634 "Show the NIC bypass config for port_id", 4635 .data = NULL, 4636 .tokens = { 4637 (void *)&cmd_showbypass_config_show, 4638 (void *)&cmd_showbypass_config_bypass, 4639 (void *)&cmd_showbypass_config_config, 4640 (void *)&cmd_showbypass_config_port, 4641 NULL, 4642 }, 4643 }; 4644 4645 #ifdef RTE_LIBRTE_PMD_BOND 4646 /* *** SET BONDING MODE *** */ 4647 struct cmd_set_bonding_mode_result { 4648 cmdline_fixed_string_t set; 4649 cmdline_fixed_string_t bonding; 4650 cmdline_fixed_string_t mode; 4651 uint8_t value; 4652 uint8_t port_id; 4653 }; 4654 4655 static void cmd_set_bonding_mode_parsed(void *parsed_result, 4656 __attribute__((unused)) struct cmdline *cl, 4657 __attribute__((unused)) void *data) 4658 { 4659 struct cmd_set_bonding_mode_result *res = parsed_result; 4660 portid_t port_id = res->port_id; 4661 4662 /* Set the bonding mode for the relevant port. */ 4663 if (0 != rte_eth_bond_mode_set(port_id, res->value)) 4664 printf("\t Failed to set bonding mode for port = %d.\n", port_id); 4665 } 4666 4667 cmdline_parse_token_string_t cmd_setbonding_mode_set = 4668 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4669 set, "set"); 4670 cmdline_parse_token_string_t cmd_setbonding_mode_bonding = 4671 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4672 bonding, "bonding"); 4673 cmdline_parse_token_string_t cmd_setbonding_mode_mode = 4674 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4675 mode, "mode"); 4676 cmdline_parse_token_num_t cmd_setbonding_mode_value = 4677 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4678 value, UINT8); 4679 cmdline_parse_token_num_t cmd_setbonding_mode_port = 4680 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4681 port_id, UINT8); 4682 4683 cmdline_parse_inst_t cmd_set_bonding_mode = { 4684 .f = cmd_set_bonding_mode_parsed, 4685 .help_str = "set bonding mode <mode_value> <port_id>: " 4686 "Set the bonding mode for port_id", 4687 .data = NULL, 4688 .tokens = { 4689 (void *) &cmd_setbonding_mode_set, 4690 (void *) &cmd_setbonding_mode_bonding, 4691 (void *) &cmd_setbonding_mode_mode, 4692 (void *) &cmd_setbonding_mode_value, 4693 (void *) &cmd_setbonding_mode_port, 4694 NULL 4695 } 4696 }; 4697 4698 /* *** SET BONDING SLOW_QUEUE SW/HW *** */ 4699 struct cmd_set_bonding_lacp_dedicated_queues_result { 4700 cmdline_fixed_string_t set; 4701 cmdline_fixed_string_t bonding; 4702 cmdline_fixed_string_t lacp; 4703 cmdline_fixed_string_t dedicated_queues; 4704 uint8_t port_id; 4705 cmdline_fixed_string_t mode; 4706 }; 4707 4708 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result, 4709 __attribute__((unused)) struct cmdline *cl, 4710 __attribute__((unused)) void *data) 4711 { 4712 struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result; 4713 portid_t port_id = res->port_id; 4714 struct rte_port *port; 4715 4716 port = &ports[port_id]; 4717 4718 /** Check if the port is not started **/ 4719 if (port->port_status != RTE_PORT_STOPPED) { 4720 printf("Please stop port %d first\n", port_id); 4721 return; 4722 } 4723 4724 if (!strcmp(res->mode, "enable")) { 4725 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0) 4726 printf("Dedicate queues for LACP control packets" 4727 " enabled\n"); 4728 else 4729 printf("Enabling dedicate queues for LACP control " 4730 "packets on port %d failed\n", port_id); 4731 } else if (!strcmp(res->mode, "disable")) { 4732 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0) 4733 printf("Dedicated queues for LACP control packets " 4734 "disabled\n"); 4735 else 4736 printf("Disabling dedicated queues for LACP control " 4737 "traffic on port %d failed\n", port_id); 4738 } 4739 } 4740 4741 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set = 4742 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4743 set, "set"); 4744 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding = 4745 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4746 bonding, "bonding"); 4747 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp = 4748 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4749 lacp, "lacp"); 4750 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues = 4751 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4752 dedicated_queues, "dedicated_queues"); 4753 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = 4754 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4755 port_id, UINT8); 4756 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = 4757 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4758 mode, "enable#disable"); 4759 4760 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = { 4761 .f = cmd_set_bonding_lacp_dedicated_queues_parsed, 4762 .help_str = "set bonding lacp dedicated_queues <port_id> " 4763 "enable|disable: " 4764 "Enable/disable dedicated queues for LACP control traffic for port_id", 4765 .data = NULL, 4766 .tokens = { 4767 (void *)&cmd_setbonding_lacp_dedicated_queues_set, 4768 (void *)&cmd_setbonding_lacp_dedicated_queues_bonding, 4769 (void *)&cmd_setbonding_lacp_dedicated_queues_lacp, 4770 (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues, 4771 (void *)&cmd_setbonding_lacp_dedicated_queues_port_id, 4772 (void *)&cmd_setbonding_lacp_dedicated_queues_mode, 4773 NULL 4774 } 4775 }; 4776 4777 /* *** SET BALANCE XMIT POLICY *** */ 4778 struct cmd_set_bonding_balance_xmit_policy_result { 4779 cmdline_fixed_string_t set; 4780 cmdline_fixed_string_t bonding; 4781 cmdline_fixed_string_t balance_xmit_policy; 4782 uint8_t port_id; 4783 cmdline_fixed_string_t policy; 4784 }; 4785 4786 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, 4787 __attribute__((unused)) struct cmdline *cl, 4788 __attribute__((unused)) void *data) 4789 { 4790 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; 4791 portid_t port_id = res->port_id; 4792 uint8_t policy; 4793 4794 if (!strcmp(res->policy, "l2")) { 4795 policy = BALANCE_XMIT_POLICY_LAYER2; 4796 } else if (!strcmp(res->policy, "l23")) { 4797 policy = BALANCE_XMIT_POLICY_LAYER23; 4798 } else if (!strcmp(res->policy, "l34")) { 4799 policy = BALANCE_XMIT_POLICY_LAYER34; 4800 } else { 4801 printf("\t Invalid xmit policy selection"); 4802 return; 4803 } 4804 4805 /* Set the bonding mode for the relevant port. */ 4806 if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { 4807 printf("\t Failed to set bonding balance xmit policy for port = %d.\n", 4808 port_id); 4809 } 4810 } 4811 4812 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = 4813 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4814 set, "set"); 4815 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = 4816 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4817 bonding, "bonding"); 4818 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = 4819 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4820 balance_xmit_policy, "balance_xmit_policy"); 4821 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = 4822 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4823 port_id, UINT8); 4824 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = 4825 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 4826 policy, "l2#l23#l34"); 4827 4828 cmdline_parse_inst_t cmd_set_balance_xmit_policy = { 4829 .f = cmd_set_bonding_balance_xmit_policy_parsed, 4830 .help_str = "set bonding balance_xmit_policy <port_id> " 4831 "l2|l23|l34: " 4832 "Set the bonding balance_xmit_policy for port_id", 4833 .data = NULL, 4834 .tokens = { 4835 (void *)&cmd_setbonding_balance_xmit_policy_set, 4836 (void *)&cmd_setbonding_balance_xmit_policy_bonding, 4837 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, 4838 (void *)&cmd_setbonding_balance_xmit_policy_port, 4839 (void *)&cmd_setbonding_balance_xmit_policy_policy, 4840 NULL 4841 } 4842 }; 4843 4844 /* *** SHOW NIC BONDING CONFIGURATION *** */ 4845 struct cmd_show_bonding_config_result { 4846 cmdline_fixed_string_t show; 4847 cmdline_fixed_string_t bonding; 4848 cmdline_fixed_string_t config; 4849 portid_t port_id; 4850 }; 4851 4852 static void cmd_show_bonding_config_parsed(void *parsed_result, 4853 __attribute__((unused)) struct cmdline *cl, 4854 __attribute__((unused)) void *data) 4855 { 4856 struct cmd_show_bonding_config_result *res = parsed_result; 4857 int bonding_mode, agg_mode; 4858 portid_t slaves[RTE_MAX_ETHPORTS]; 4859 int num_slaves, num_active_slaves; 4860 int primary_id; 4861 int i; 4862 portid_t port_id = res->port_id; 4863 4864 /* Display the bonding mode.*/ 4865 bonding_mode = rte_eth_bond_mode_get(port_id); 4866 if (bonding_mode < 0) { 4867 printf("\tFailed to get bonding mode for port = %d\n", port_id); 4868 return; 4869 } else 4870 printf("\tBonding mode: %d\n", bonding_mode); 4871 4872 if (bonding_mode == BONDING_MODE_BALANCE) { 4873 int balance_xmit_policy; 4874 4875 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); 4876 if (balance_xmit_policy < 0) { 4877 printf("\tFailed to get balance xmit policy for port = %d\n", 4878 port_id); 4879 return; 4880 } else { 4881 printf("\tBalance Xmit Policy: "); 4882 4883 switch (balance_xmit_policy) { 4884 case BALANCE_XMIT_POLICY_LAYER2: 4885 printf("BALANCE_XMIT_POLICY_LAYER2"); 4886 break; 4887 case BALANCE_XMIT_POLICY_LAYER23: 4888 printf("BALANCE_XMIT_POLICY_LAYER23"); 4889 break; 4890 case BALANCE_XMIT_POLICY_LAYER34: 4891 printf("BALANCE_XMIT_POLICY_LAYER34"); 4892 break; 4893 } 4894 printf("\n"); 4895 } 4896 } 4897 4898 if (bonding_mode == BONDING_MODE_8023AD) { 4899 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id); 4900 printf("\tIEEE802.3AD Aggregator Mode: "); 4901 switch (agg_mode) { 4902 case AGG_BANDWIDTH: 4903 printf("bandwidth"); 4904 break; 4905 case AGG_STABLE: 4906 printf("stable"); 4907 break; 4908 case AGG_COUNT: 4909 printf("count"); 4910 break; 4911 } 4912 printf("\n"); 4913 } 4914 4915 num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); 4916 4917 if (num_slaves < 0) { 4918 printf("\tFailed to get slave list for port = %d\n", port_id); 4919 return; 4920 } 4921 if (num_slaves > 0) { 4922 printf("\tSlaves (%d): [", num_slaves); 4923 for (i = 0; i < num_slaves - 1; i++) 4924 printf("%d ", slaves[i]); 4925 4926 printf("%d]\n", slaves[num_slaves - 1]); 4927 } else { 4928 printf("\tSlaves: []\n"); 4929 4930 } 4931 4932 num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, 4933 RTE_MAX_ETHPORTS); 4934 4935 if (num_active_slaves < 0) { 4936 printf("\tFailed to get active slave list for port = %d\n", port_id); 4937 return; 4938 } 4939 if (num_active_slaves > 0) { 4940 printf("\tActive Slaves (%d): [", num_active_slaves); 4941 for (i = 0; i < num_active_slaves - 1; i++) 4942 printf("%d ", slaves[i]); 4943 4944 printf("%d]\n", slaves[num_active_slaves - 1]); 4945 4946 } else { 4947 printf("\tActive Slaves: []\n"); 4948 4949 } 4950 4951 primary_id = rte_eth_bond_primary_get(port_id); 4952 if (primary_id < 0) { 4953 printf("\tFailed to get primary slave for port = %d\n", port_id); 4954 return; 4955 } else 4956 printf("\tPrimary: [%d]\n", primary_id); 4957 4958 } 4959 4960 cmdline_parse_token_string_t cmd_showbonding_config_show = 4961 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4962 show, "show"); 4963 cmdline_parse_token_string_t cmd_showbonding_config_bonding = 4964 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4965 bonding, "bonding"); 4966 cmdline_parse_token_string_t cmd_showbonding_config_config = 4967 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 4968 config, "config"); 4969 cmdline_parse_token_num_t cmd_showbonding_config_port = 4970 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, 4971 port_id, UINT8); 4972 4973 cmdline_parse_inst_t cmd_show_bonding_config = { 4974 .f = cmd_show_bonding_config_parsed, 4975 .help_str = "show bonding config <port_id>: " 4976 "Show the bonding config for port_id", 4977 .data = NULL, 4978 .tokens = { 4979 (void *)&cmd_showbonding_config_show, 4980 (void *)&cmd_showbonding_config_bonding, 4981 (void *)&cmd_showbonding_config_config, 4982 (void *)&cmd_showbonding_config_port, 4983 NULL 4984 } 4985 }; 4986 4987 /* *** SET BONDING PRIMARY *** */ 4988 struct cmd_set_bonding_primary_result { 4989 cmdline_fixed_string_t set; 4990 cmdline_fixed_string_t bonding; 4991 cmdline_fixed_string_t primary; 4992 uint8_t slave_id; 4993 uint8_t port_id; 4994 }; 4995 4996 static void cmd_set_bonding_primary_parsed(void *parsed_result, 4997 __attribute__((unused)) struct cmdline *cl, 4998 __attribute__((unused)) void *data) 4999 { 5000 struct cmd_set_bonding_primary_result *res = parsed_result; 5001 portid_t master_port_id = res->port_id; 5002 portid_t slave_port_id = res->slave_id; 5003 5004 /* Set the primary slave for a bonded device. */ 5005 if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { 5006 printf("\t Failed to set primary slave for port = %d.\n", 5007 master_port_id); 5008 return; 5009 } 5010 init_port_config(); 5011 } 5012 5013 cmdline_parse_token_string_t cmd_setbonding_primary_set = 5014 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5015 set, "set"); 5016 cmdline_parse_token_string_t cmd_setbonding_primary_bonding = 5017 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5018 bonding, "bonding"); 5019 cmdline_parse_token_string_t cmd_setbonding_primary_primary = 5020 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5021 primary, "primary"); 5022 cmdline_parse_token_num_t cmd_setbonding_primary_slave = 5023 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 5024 slave_id, UINT8); 5025 cmdline_parse_token_num_t cmd_setbonding_primary_port = 5026 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 5027 port_id, UINT8); 5028 5029 cmdline_parse_inst_t cmd_set_bonding_primary = { 5030 .f = cmd_set_bonding_primary_parsed, 5031 .help_str = "set bonding primary <slave_id> <port_id>: " 5032 "Set the primary slave for port_id", 5033 .data = NULL, 5034 .tokens = { 5035 (void *)&cmd_setbonding_primary_set, 5036 (void *)&cmd_setbonding_primary_bonding, 5037 (void *)&cmd_setbonding_primary_primary, 5038 (void *)&cmd_setbonding_primary_slave, 5039 (void *)&cmd_setbonding_primary_port, 5040 NULL 5041 } 5042 }; 5043 5044 /* *** ADD SLAVE *** */ 5045 struct cmd_add_bonding_slave_result { 5046 cmdline_fixed_string_t add; 5047 cmdline_fixed_string_t bonding; 5048 cmdline_fixed_string_t slave; 5049 uint8_t slave_id; 5050 uint8_t port_id; 5051 }; 5052 5053 static void cmd_add_bonding_slave_parsed(void *parsed_result, 5054 __attribute__((unused)) struct cmdline *cl, 5055 __attribute__((unused)) void *data) 5056 { 5057 struct cmd_add_bonding_slave_result *res = parsed_result; 5058 portid_t master_port_id = res->port_id; 5059 portid_t slave_port_id = res->slave_id; 5060 5061 /* add the slave for a bonded device. */ 5062 if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { 5063 printf("\t Failed to add slave %d to master port = %d.\n", 5064 slave_port_id, master_port_id); 5065 return; 5066 } 5067 init_port_config(); 5068 set_port_slave_flag(slave_port_id); 5069 } 5070 5071 cmdline_parse_token_string_t cmd_addbonding_slave_add = 5072 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5073 add, "add"); 5074 cmdline_parse_token_string_t cmd_addbonding_slave_bonding = 5075 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5076 bonding, "bonding"); 5077 cmdline_parse_token_string_t cmd_addbonding_slave_slave = 5078 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5079 slave, "slave"); 5080 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = 5081 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 5082 slave_id, UINT8); 5083 cmdline_parse_token_num_t cmd_addbonding_slave_port = 5084 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 5085 port_id, UINT8); 5086 5087 cmdline_parse_inst_t cmd_add_bonding_slave = { 5088 .f = cmd_add_bonding_slave_parsed, 5089 .help_str = "add bonding slave <slave_id> <port_id>: " 5090 "Add a slave device to a bonded device", 5091 .data = NULL, 5092 .tokens = { 5093 (void *)&cmd_addbonding_slave_add, 5094 (void *)&cmd_addbonding_slave_bonding, 5095 (void *)&cmd_addbonding_slave_slave, 5096 (void *)&cmd_addbonding_slave_slaveid, 5097 (void *)&cmd_addbonding_slave_port, 5098 NULL 5099 } 5100 }; 5101 5102 /* *** REMOVE SLAVE *** */ 5103 struct cmd_remove_bonding_slave_result { 5104 cmdline_fixed_string_t remove; 5105 cmdline_fixed_string_t bonding; 5106 cmdline_fixed_string_t slave; 5107 uint8_t slave_id; 5108 uint8_t port_id; 5109 }; 5110 5111 static void cmd_remove_bonding_slave_parsed(void *parsed_result, 5112 __attribute__((unused)) struct cmdline *cl, 5113 __attribute__((unused)) void *data) 5114 { 5115 struct cmd_remove_bonding_slave_result *res = parsed_result; 5116 portid_t master_port_id = res->port_id; 5117 portid_t slave_port_id = res->slave_id; 5118 5119 /* remove the slave from a bonded device. */ 5120 if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { 5121 printf("\t Failed to remove slave %d from master port = %d.\n", 5122 slave_port_id, master_port_id); 5123 return; 5124 } 5125 init_port_config(); 5126 clear_port_slave_flag(slave_port_id); 5127 } 5128 5129 cmdline_parse_token_string_t cmd_removebonding_slave_remove = 5130 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5131 remove, "remove"); 5132 cmdline_parse_token_string_t cmd_removebonding_slave_bonding = 5133 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5134 bonding, "bonding"); 5135 cmdline_parse_token_string_t cmd_removebonding_slave_slave = 5136 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5137 slave, "slave"); 5138 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = 5139 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 5140 slave_id, UINT8); 5141 cmdline_parse_token_num_t cmd_removebonding_slave_port = 5142 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 5143 port_id, UINT8); 5144 5145 cmdline_parse_inst_t cmd_remove_bonding_slave = { 5146 .f = cmd_remove_bonding_slave_parsed, 5147 .help_str = "remove bonding slave <slave_id> <port_id>: " 5148 "Remove a slave device from a bonded device", 5149 .data = NULL, 5150 .tokens = { 5151 (void *)&cmd_removebonding_slave_remove, 5152 (void *)&cmd_removebonding_slave_bonding, 5153 (void *)&cmd_removebonding_slave_slave, 5154 (void *)&cmd_removebonding_slave_slaveid, 5155 (void *)&cmd_removebonding_slave_port, 5156 NULL 5157 } 5158 }; 5159 5160 /* *** CREATE BONDED DEVICE *** */ 5161 struct cmd_create_bonded_device_result { 5162 cmdline_fixed_string_t create; 5163 cmdline_fixed_string_t bonded; 5164 cmdline_fixed_string_t device; 5165 uint8_t mode; 5166 uint8_t socket; 5167 }; 5168 5169 static int bond_dev_num = 0; 5170 5171 static void cmd_create_bonded_device_parsed(void *parsed_result, 5172 __attribute__((unused)) struct cmdline *cl, 5173 __attribute__((unused)) void *data) 5174 { 5175 struct cmd_create_bonded_device_result *res = parsed_result; 5176 char ethdev_name[RTE_ETH_NAME_MAX_LEN]; 5177 int port_id; 5178 5179 if (test_done == 0) { 5180 printf("Please stop forwarding first\n"); 5181 return; 5182 } 5183 5184 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d", 5185 bond_dev_num++); 5186 5187 /* Create a new bonded device. */ 5188 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); 5189 if (port_id < 0) { 5190 printf("\t Failed to create bonded device.\n"); 5191 return; 5192 } else { 5193 printf("Created new bonded device %s on (port %d).\n", ethdev_name, 5194 port_id); 5195 5196 /* Update number of ports */ 5197 nb_ports = rte_eth_dev_count(); 5198 reconfig(port_id, res->socket); 5199 rte_eth_promiscuous_enable(port_id); 5200 } 5201 5202 } 5203 5204 cmdline_parse_token_string_t cmd_createbonded_device_create = 5205 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5206 create, "create"); 5207 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 5208 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5209 bonded, "bonded"); 5210 cmdline_parse_token_string_t cmd_createbonded_device_device = 5211 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5212 device, "device"); 5213 cmdline_parse_token_num_t cmd_createbonded_device_mode = 5214 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 5215 mode, UINT8); 5216 cmdline_parse_token_num_t cmd_createbonded_device_socket = 5217 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 5218 socket, UINT8); 5219 5220 cmdline_parse_inst_t cmd_create_bonded_device = { 5221 .f = cmd_create_bonded_device_parsed, 5222 .help_str = "create bonded device <mode> <socket>: " 5223 "Create a new bonded device with specific bonding mode and socket", 5224 .data = NULL, 5225 .tokens = { 5226 (void *)&cmd_createbonded_device_create, 5227 (void *)&cmd_createbonded_device_bonded, 5228 (void *)&cmd_createbonded_device_device, 5229 (void *)&cmd_createbonded_device_mode, 5230 (void *)&cmd_createbonded_device_socket, 5231 NULL 5232 } 5233 }; 5234 5235 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 5236 struct cmd_set_bond_mac_addr_result { 5237 cmdline_fixed_string_t set; 5238 cmdline_fixed_string_t bonding; 5239 cmdline_fixed_string_t mac_addr; 5240 uint8_t port_num; 5241 struct ether_addr address; 5242 }; 5243 5244 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 5245 __attribute__((unused)) struct cmdline *cl, 5246 __attribute__((unused)) void *data) 5247 { 5248 struct cmd_set_bond_mac_addr_result *res = parsed_result; 5249 int ret; 5250 5251 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 5252 return; 5253 5254 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 5255 5256 /* check the return value and print it if is < 0 */ 5257 if (ret < 0) 5258 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 5259 } 5260 5261 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 5262 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 5263 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 5264 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 5265 "bonding"); 5266 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 5267 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 5268 "mac_addr"); 5269 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 5270 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); 5271 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 5272 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 5273 5274 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 5275 .f = cmd_set_bond_mac_addr_parsed, 5276 .data = (void *) 0, 5277 .help_str = "set bonding mac_addr <port_id> <mac_addr>", 5278 .tokens = { 5279 (void *)&cmd_set_bond_mac_addr_set, 5280 (void *)&cmd_set_bond_mac_addr_bonding, 5281 (void *)&cmd_set_bond_mac_addr_mac, 5282 (void *)&cmd_set_bond_mac_addr_portnum, 5283 (void *)&cmd_set_bond_mac_addr_addr, 5284 NULL 5285 } 5286 }; 5287 5288 5289 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 5290 struct cmd_set_bond_mon_period_result { 5291 cmdline_fixed_string_t set; 5292 cmdline_fixed_string_t bonding; 5293 cmdline_fixed_string_t mon_period; 5294 uint8_t port_num; 5295 uint32_t period_ms; 5296 }; 5297 5298 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 5299 __attribute__((unused)) struct cmdline *cl, 5300 __attribute__((unused)) void *data) 5301 { 5302 struct cmd_set_bond_mon_period_result *res = parsed_result; 5303 int ret; 5304 5305 if (res->port_num >= nb_ports) { 5306 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 5307 return; 5308 } 5309 5310 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 5311 5312 /* check the return value and print it if is < 0 */ 5313 if (ret < 0) 5314 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 5315 } 5316 5317 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 5318 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5319 set, "set"); 5320 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 5321 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5322 bonding, "bonding"); 5323 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 5324 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5325 mon_period, "mon_period"); 5326 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 5327 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5328 port_num, UINT8); 5329 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 5330 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5331 period_ms, UINT32); 5332 5333 cmdline_parse_inst_t cmd_set_bond_mon_period = { 5334 .f = cmd_set_bond_mon_period_parsed, 5335 .data = (void *) 0, 5336 .help_str = "set bonding mon_period <port_id> <period_ms>", 5337 .tokens = { 5338 (void *)&cmd_set_bond_mon_period_set, 5339 (void *)&cmd_set_bond_mon_period_bonding, 5340 (void *)&cmd_set_bond_mon_period_mon_period, 5341 (void *)&cmd_set_bond_mon_period_portnum, 5342 (void *)&cmd_set_bond_mon_period_period_ms, 5343 NULL 5344 } 5345 }; 5346 5347 5348 5349 struct cmd_set_bonding_agg_mode_policy_result { 5350 cmdline_fixed_string_t set; 5351 cmdline_fixed_string_t bonding; 5352 cmdline_fixed_string_t agg_mode; 5353 uint8_t port_num; 5354 cmdline_fixed_string_t policy; 5355 }; 5356 5357 5358 static void 5359 cmd_set_bonding_agg_mode(void *parsed_result, 5360 __attribute__((unused)) struct cmdline *cl, 5361 __attribute__((unused)) void *data) 5362 { 5363 struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result; 5364 uint8_t policy = AGG_BANDWIDTH; 5365 5366 if (res->port_num >= nb_ports) { 5367 printf("Port id %d must be less than %d\n", 5368 res->port_num, nb_ports); 5369 return; 5370 } 5371 5372 if (!strcmp(res->policy, "bandwidth")) 5373 policy = AGG_BANDWIDTH; 5374 else if (!strcmp(res->policy, "stable")) 5375 policy = AGG_STABLE; 5376 else if (!strcmp(res->policy, "count")) 5377 policy = AGG_COUNT; 5378 5379 rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy); 5380 } 5381 5382 5383 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set = 5384 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5385 set, "set"); 5386 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding = 5387 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5388 bonding, "bonding"); 5389 5390 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = 5391 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5392 agg_mode, "agg_mode"); 5393 5394 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = 5395 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5396 port_num, UINT8); 5397 5398 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = 5399 TOKEN_STRING_INITIALIZER( 5400 struct cmd_set_bonding_balance_xmit_policy_result, 5401 policy, "stable#bandwidth#count"); 5402 5403 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = { 5404 .f = cmd_set_bonding_agg_mode, 5405 .data = (void *) 0, 5406 .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>", 5407 .tokens = { 5408 (void *)&cmd_set_bonding_agg_mode_set, 5409 (void *)&cmd_set_bonding_agg_mode_bonding, 5410 (void *)&cmd_set_bonding_agg_mode_agg_mode, 5411 (void *)&cmd_set_bonding_agg_mode_portnum, 5412 (void *)&cmd_set_bonding_agg_mode_policy_string, 5413 NULL 5414 } 5415 }; 5416 5417 5418 #endif /* RTE_LIBRTE_PMD_BOND */ 5419 5420 /* *** SET FORWARDING MODE *** */ 5421 struct cmd_set_fwd_mode_result { 5422 cmdline_fixed_string_t set; 5423 cmdline_fixed_string_t fwd; 5424 cmdline_fixed_string_t mode; 5425 }; 5426 5427 static void cmd_set_fwd_mode_parsed(void *parsed_result, 5428 __attribute__((unused)) struct cmdline *cl, 5429 __attribute__((unused)) void *data) 5430 { 5431 struct cmd_set_fwd_mode_result *res = parsed_result; 5432 5433 retry_enabled = 0; 5434 set_pkt_forwarding_mode(res->mode); 5435 } 5436 5437 cmdline_parse_token_string_t cmd_setfwd_set = 5438 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 5439 cmdline_parse_token_string_t cmd_setfwd_fwd = 5440 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 5441 cmdline_parse_token_string_t cmd_setfwd_mode = 5442 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 5443 "" /* defined at init */); 5444 5445 cmdline_parse_inst_t cmd_set_fwd_mode = { 5446 .f = cmd_set_fwd_mode_parsed, 5447 .data = NULL, 5448 .help_str = NULL, /* defined at init */ 5449 .tokens = { 5450 (void *)&cmd_setfwd_set, 5451 (void *)&cmd_setfwd_fwd, 5452 (void *)&cmd_setfwd_mode, 5453 NULL, 5454 }, 5455 }; 5456 5457 static void cmd_set_fwd_mode_init(void) 5458 { 5459 char *modes, *c; 5460 static char token[128]; 5461 static char help[256]; 5462 cmdline_parse_token_string_t *token_struct; 5463 5464 modes = list_pkt_forwarding_modes(); 5465 snprintf(help, sizeof(help), "set fwd %s: " 5466 "Set packet forwarding mode", modes); 5467 cmd_set_fwd_mode.help_str = help; 5468 5469 /* string token separator is # */ 5470 for (c = token; *modes != '\0'; modes++) 5471 if (*modes == '|') 5472 *c++ = '#'; 5473 else 5474 *c++ = *modes; 5475 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 5476 token_struct->string_data.str = token; 5477 } 5478 5479 /* *** SET RETRY FORWARDING MODE *** */ 5480 struct cmd_set_fwd_retry_mode_result { 5481 cmdline_fixed_string_t set; 5482 cmdline_fixed_string_t fwd; 5483 cmdline_fixed_string_t mode; 5484 cmdline_fixed_string_t retry; 5485 }; 5486 5487 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 5488 __attribute__((unused)) struct cmdline *cl, 5489 __attribute__((unused)) void *data) 5490 { 5491 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 5492 5493 retry_enabled = 1; 5494 set_pkt_forwarding_mode(res->mode); 5495 } 5496 5497 cmdline_parse_token_string_t cmd_setfwd_retry_set = 5498 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5499 set, "set"); 5500 cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 5501 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5502 fwd, "fwd"); 5503 cmdline_parse_token_string_t cmd_setfwd_retry_mode = 5504 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5505 mode, 5506 "" /* defined at init */); 5507 cmdline_parse_token_string_t cmd_setfwd_retry_retry = 5508 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5509 retry, "retry"); 5510 5511 cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 5512 .f = cmd_set_fwd_retry_mode_parsed, 5513 .data = NULL, 5514 .help_str = NULL, /* defined at init */ 5515 .tokens = { 5516 (void *)&cmd_setfwd_retry_set, 5517 (void *)&cmd_setfwd_retry_fwd, 5518 (void *)&cmd_setfwd_retry_mode, 5519 (void *)&cmd_setfwd_retry_retry, 5520 NULL, 5521 }, 5522 }; 5523 5524 static void cmd_set_fwd_retry_mode_init(void) 5525 { 5526 char *modes, *c; 5527 static char token[128]; 5528 static char help[256]; 5529 cmdline_parse_token_string_t *token_struct; 5530 5531 modes = list_pkt_forwarding_retry_modes(); 5532 snprintf(help, sizeof(help), "set fwd %s retry: " 5533 "Set packet forwarding mode with retry", modes); 5534 cmd_set_fwd_retry_mode.help_str = help; 5535 5536 /* string token separator is # */ 5537 for (c = token; *modes != '\0'; modes++) 5538 if (*modes == '|') 5539 *c++ = '#'; 5540 else 5541 *c++ = *modes; 5542 token_struct = (cmdline_parse_token_string_t *) 5543 cmd_set_fwd_retry_mode.tokens[2]; 5544 token_struct->string_data.str = token; 5545 } 5546 5547 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 5548 struct cmd_set_burst_tx_retry_result { 5549 cmdline_fixed_string_t set; 5550 cmdline_fixed_string_t burst; 5551 cmdline_fixed_string_t tx; 5552 cmdline_fixed_string_t delay; 5553 uint32_t time; 5554 cmdline_fixed_string_t retry; 5555 uint32_t retry_num; 5556 }; 5557 5558 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 5559 __attribute__((unused)) struct cmdline *cl, 5560 __attribute__((unused)) void *data) 5561 { 5562 struct cmd_set_burst_tx_retry_result *res = parsed_result; 5563 5564 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 5565 && !strcmp(res->tx, "tx")) { 5566 if (!strcmp(res->delay, "delay")) 5567 burst_tx_delay_time = res->time; 5568 if (!strcmp(res->retry, "retry")) 5569 burst_tx_retry_num = res->retry_num; 5570 } 5571 5572 } 5573 5574 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 5575 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 5576 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 5577 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 5578 "burst"); 5579 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 5580 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 5581 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 5582 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 5583 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 5584 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 5585 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 5586 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 5587 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 5588 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 5589 5590 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 5591 .f = cmd_set_burst_tx_retry_parsed, 5592 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 5593 .tokens = { 5594 (void *)&cmd_set_burst_tx_retry_set, 5595 (void *)&cmd_set_burst_tx_retry_burst, 5596 (void *)&cmd_set_burst_tx_retry_tx, 5597 (void *)&cmd_set_burst_tx_retry_delay, 5598 (void *)&cmd_set_burst_tx_retry_time, 5599 (void *)&cmd_set_burst_tx_retry_retry, 5600 (void *)&cmd_set_burst_tx_retry_retry_num, 5601 NULL, 5602 }, 5603 }; 5604 5605 /* *** SET PROMISC MODE *** */ 5606 struct cmd_set_promisc_mode_result { 5607 cmdline_fixed_string_t set; 5608 cmdline_fixed_string_t promisc; 5609 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5610 uint8_t port_num; /* valid if "allports" argument == 0 */ 5611 cmdline_fixed_string_t mode; 5612 }; 5613 5614 static void cmd_set_promisc_mode_parsed(void *parsed_result, 5615 __attribute__((unused)) struct cmdline *cl, 5616 void *allports) 5617 { 5618 struct cmd_set_promisc_mode_result *res = parsed_result; 5619 int enable; 5620 portid_t i; 5621 5622 if (!strcmp(res->mode, "on")) 5623 enable = 1; 5624 else 5625 enable = 0; 5626 5627 /* all ports */ 5628 if (allports) { 5629 RTE_ETH_FOREACH_DEV(i) { 5630 if (enable) 5631 rte_eth_promiscuous_enable(i); 5632 else 5633 rte_eth_promiscuous_disable(i); 5634 } 5635 } 5636 else { 5637 if (enable) 5638 rte_eth_promiscuous_enable(res->port_num); 5639 else 5640 rte_eth_promiscuous_disable(res->port_num); 5641 } 5642 } 5643 5644 cmdline_parse_token_string_t cmd_setpromisc_set = 5645 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 5646 cmdline_parse_token_string_t cmd_setpromisc_promisc = 5647 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 5648 "promisc"); 5649 cmdline_parse_token_string_t cmd_setpromisc_portall = 5650 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 5651 "all"); 5652 cmdline_parse_token_num_t cmd_setpromisc_portnum = 5653 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 5654 UINT8); 5655 cmdline_parse_token_string_t cmd_setpromisc_mode = 5656 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 5657 "on#off"); 5658 5659 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 5660 .f = cmd_set_promisc_mode_parsed, 5661 .data = (void *)1, 5662 .help_str = "set promisc all on|off: Set promisc mode for all ports", 5663 .tokens = { 5664 (void *)&cmd_setpromisc_set, 5665 (void *)&cmd_setpromisc_promisc, 5666 (void *)&cmd_setpromisc_portall, 5667 (void *)&cmd_setpromisc_mode, 5668 NULL, 5669 }, 5670 }; 5671 5672 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 5673 .f = cmd_set_promisc_mode_parsed, 5674 .data = (void *)0, 5675 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 5676 .tokens = { 5677 (void *)&cmd_setpromisc_set, 5678 (void *)&cmd_setpromisc_promisc, 5679 (void *)&cmd_setpromisc_portnum, 5680 (void *)&cmd_setpromisc_mode, 5681 NULL, 5682 }, 5683 }; 5684 5685 /* *** SET ALLMULTI MODE *** */ 5686 struct cmd_set_allmulti_mode_result { 5687 cmdline_fixed_string_t set; 5688 cmdline_fixed_string_t allmulti; 5689 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5690 uint8_t port_num; /* valid if "allports" argument == 0 */ 5691 cmdline_fixed_string_t mode; 5692 }; 5693 5694 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 5695 __attribute__((unused)) struct cmdline *cl, 5696 void *allports) 5697 { 5698 struct cmd_set_allmulti_mode_result *res = parsed_result; 5699 int enable; 5700 portid_t i; 5701 5702 if (!strcmp(res->mode, "on")) 5703 enable = 1; 5704 else 5705 enable = 0; 5706 5707 /* all ports */ 5708 if (allports) { 5709 RTE_ETH_FOREACH_DEV(i) { 5710 if (enable) 5711 rte_eth_allmulticast_enable(i); 5712 else 5713 rte_eth_allmulticast_disable(i); 5714 } 5715 } 5716 else { 5717 if (enable) 5718 rte_eth_allmulticast_enable(res->port_num); 5719 else 5720 rte_eth_allmulticast_disable(res->port_num); 5721 } 5722 } 5723 5724 cmdline_parse_token_string_t cmd_setallmulti_set = 5725 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 5726 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 5727 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 5728 "allmulti"); 5729 cmdline_parse_token_string_t cmd_setallmulti_portall = 5730 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 5731 "all"); 5732 cmdline_parse_token_num_t cmd_setallmulti_portnum = 5733 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 5734 UINT8); 5735 cmdline_parse_token_string_t cmd_setallmulti_mode = 5736 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 5737 "on#off"); 5738 5739 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 5740 .f = cmd_set_allmulti_mode_parsed, 5741 .data = (void *)1, 5742 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 5743 .tokens = { 5744 (void *)&cmd_setallmulti_set, 5745 (void *)&cmd_setallmulti_allmulti, 5746 (void *)&cmd_setallmulti_portall, 5747 (void *)&cmd_setallmulti_mode, 5748 NULL, 5749 }, 5750 }; 5751 5752 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 5753 .f = cmd_set_allmulti_mode_parsed, 5754 .data = (void *)0, 5755 .help_str = "set allmulti <port_id> on|off: " 5756 "Set allmulti mode on port_id", 5757 .tokens = { 5758 (void *)&cmd_setallmulti_set, 5759 (void *)&cmd_setallmulti_allmulti, 5760 (void *)&cmd_setallmulti_portnum, 5761 (void *)&cmd_setallmulti_mode, 5762 NULL, 5763 }, 5764 }; 5765 5766 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 5767 struct cmd_link_flow_ctrl_set_result { 5768 cmdline_fixed_string_t set; 5769 cmdline_fixed_string_t flow_ctrl; 5770 cmdline_fixed_string_t rx; 5771 cmdline_fixed_string_t rx_lfc_mode; 5772 cmdline_fixed_string_t tx; 5773 cmdline_fixed_string_t tx_lfc_mode; 5774 cmdline_fixed_string_t mac_ctrl_frame_fwd; 5775 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 5776 cmdline_fixed_string_t autoneg_str; 5777 cmdline_fixed_string_t autoneg; 5778 cmdline_fixed_string_t hw_str; 5779 uint32_t high_water; 5780 cmdline_fixed_string_t lw_str; 5781 uint32_t low_water; 5782 cmdline_fixed_string_t pt_str; 5783 uint16_t pause_time; 5784 cmdline_fixed_string_t xon_str; 5785 uint16_t send_xon; 5786 uint8_t port_id; 5787 }; 5788 5789 cmdline_parse_token_string_t cmd_lfc_set_set = 5790 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5791 set, "set"); 5792 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 5793 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5794 flow_ctrl, "flow_ctrl"); 5795 cmdline_parse_token_string_t cmd_lfc_set_rx = 5796 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5797 rx, "rx"); 5798 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 5799 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5800 rx_lfc_mode, "on#off"); 5801 cmdline_parse_token_string_t cmd_lfc_set_tx = 5802 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5803 tx, "tx"); 5804 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 5805 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5806 tx_lfc_mode, "on#off"); 5807 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 5808 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5809 hw_str, "high_water"); 5810 cmdline_parse_token_num_t cmd_lfc_set_high_water = 5811 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5812 high_water, UINT32); 5813 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 5814 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5815 lw_str, "low_water"); 5816 cmdline_parse_token_num_t cmd_lfc_set_low_water = 5817 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5818 low_water, UINT32); 5819 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 5820 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5821 pt_str, "pause_time"); 5822 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 5823 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5824 pause_time, UINT16); 5825 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 5826 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5827 xon_str, "send_xon"); 5828 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 5829 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5830 send_xon, UINT16); 5831 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 5832 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5833 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 5834 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 5835 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5836 mac_ctrl_frame_fwd_mode, "on#off"); 5837 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 5838 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5839 autoneg_str, "autoneg"); 5840 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 5841 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5842 autoneg, "on#off"); 5843 cmdline_parse_token_num_t cmd_lfc_set_portid = 5844 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 5845 port_id, UINT8); 5846 5847 /* forward declaration */ 5848 static void 5849 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 5850 void *data); 5851 5852 cmdline_parse_inst_t cmd_link_flow_control_set = { 5853 .f = cmd_link_flow_ctrl_set_parsed, 5854 .data = NULL, 5855 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 5856 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 5857 "autoneg on|off <port_id>: Configure the Ethernet flow control", 5858 .tokens = { 5859 (void *)&cmd_lfc_set_set, 5860 (void *)&cmd_lfc_set_flow_ctrl, 5861 (void *)&cmd_lfc_set_rx, 5862 (void *)&cmd_lfc_set_rx_mode, 5863 (void *)&cmd_lfc_set_tx, 5864 (void *)&cmd_lfc_set_tx_mode, 5865 (void *)&cmd_lfc_set_high_water, 5866 (void *)&cmd_lfc_set_low_water, 5867 (void *)&cmd_lfc_set_pause_time, 5868 (void *)&cmd_lfc_set_send_xon, 5869 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5870 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5871 (void *)&cmd_lfc_set_autoneg_str, 5872 (void *)&cmd_lfc_set_autoneg, 5873 (void *)&cmd_lfc_set_portid, 5874 NULL, 5875 }, 5876 }; 5877 5878 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 5879 .f = cmd_link_flow_ctrl_set_parsed, 5880 .data = (void *)&cmd_link_flow_control_set_rx, 5881 .help_str = "set flow_ctrl rx on|off <port_id>: " 5882 "Change rx flow control parameter", 5883 .tokens = { 5884 (void *)&cmd_lfc_set_set, 5885 (void *)&cmd_lfc_set_flow_ctrl, 5886 (void *)&cmd_lfc_set_rx, 5887 (void *)&cmd_lfc_set_rx_mode, 5888 (void *)&cmd_lfc_set_portid, 5889 NULL, 5890 }, 5891 }; 5892 5893 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 5894 .f = cmd_link_flow_ctrl_set_parsed, 5895 .data = (void *)&cmd_link_flow_control_set_tx, 5896 .help_str = "set flow_ctrl tx on|off <port_id>: " 5897 "Change tx flow control parameter", 5898 .tokens = { 5899 (void *)&cmd_lfc_set_set, 5900 (void *)&cmd_lfc_set_flow_ctrl, 5901 (void *)&cmd_lfc_set_tx, 5902 (void *)&cmd_lfc_set_tx_mode, 5903 (void *)&cmd_lfc_set_portid, 5904 NULL, 5905 }, 5906 }; 5907 5908 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 5909 .f = cmd_link_flow_ctrl_set_parsed, 5910 .data = (void *)&cmd_link_flow_control_set_hw, 5911 .help_str = "set flow_ctrl high_water <value> <port_id>: " 5912 "Change high water flow control parameter", 5913 .tokens = { 5914 (void *)&cmd_lfc_set_set, 5915 (void *)&cmd_lfc_set_flow_ctrl, 5916 (void *)&cmd_lfc_set_high_water_str, 5917 (void *)&cmd_lfc_set_high_water, 5918 (void *)&cmd_lfc_set_portid, 5919 NULL, 5920 }, 5921 }; 5922 5923 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 5924 .f = cmd_link_flow_ctrl_set_parsed, 5925 .data = (void *)&cmd_link_flow_control_set_lw, 5926 .help_str = "set flow_ctrl low_water <value> <port_id>: " 5927 "Change low water flow control parameter", 5928 .tokens = { 5929 (void *)&cmd_lfc_set_set, 5930 (void *)&cmd_lfc_set_flow_ctrl, 5931 (void *)&cmd_lfc_set_low_water_str, 5932 (void *)&cmd_lfc_set_low_water, 5933 (void *)&cmd_lfc_set_portid, 5934 NULL, 5935 }, 5936 }; 5937 5938 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 5939 .f = cmd_link_flow_ctrl_set_parsed, 5940 .data = (void *)&cmd_link_flow_control_set_pt, 5941 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 5942 "Change pause time flow control parameter", 5943 .tokens = { 5944 (void *)&cmd_lfc_set_set, 5945 (void *)&cmd_lfc_set_flow_ctrl, 5946 (void *)&cmd_lfc_set_pause_time_str, 5947 (void *)&cmd_lfc_set_pause_time, 5948 (void *)&cmd_lfc_set_portid, 5949 NULL, 5950 }, 5951 }; 5952 5953 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 5954 .f = cmd_link_flow_ctrl_set_parsed, 5955 .data = (void *)&cmd_link_flow_control_set_xon, 5956 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 5957 "Change send_xon flow control parameter", 5958 .tokens = { 5959 (void *)&cmd_lfc_set_set, 5960 (void *)&cmd_lfc_set_flow_ctrl, 5961 (void *)&cmd_lfc_set_send_xon_str, 5962 (void *)&cmd_lfc_set_send_xon, 5963 (void *)&cmd_lfc_set_portid, 5964 NULL, 5965 }, 5966 }; 5967 5968 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 5969 .f = cmd_link_flow_ctrl_set_parsed, 5970 .data = (void *)&cmd_link_flow_control_set_macfwd, 5971 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 5972 "Change mac ctrl fwd flow control parameter", 5973 .tokens = { 5974 (void *)&cmd_lfc_set_set, 5975 (void *)&cmd_lfc_set_flow_ctrl, 5976 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 5977 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 5978 (void *)&cmd_lfc_set_portid, 5979 NULL, 5980 }, 5981 }; 5982 5983 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 5984 .f = cmd_link_flow_ctrl_set_parsed, 5985 .data = (void *)&cmd_link_flow_control_set_autoneg, 5986 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 5987 "Change autoneg flow control parameter", 5988 .tokens = { 5989 (void *)&cmd_lfc_set_set, 5990 (void *)&cmd_lfc_set_flow_ctrl, 5991 (void *)&cmd_lfc_set_autoneg_str, 5992 (void *)&cmd_lfc_set_autoneg, 5993 (void *)&cmd_lfc_set_portid, 5994 NULL, 5995 }, 5996 }; 5997 5998 static void 5999 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 6000 __attribute__((unused)) struct cmdline *cl, 6001 void *data) 6002 { 6003 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 6004 cmdline_parse_inst_t *cmd = data; 6005 struct rte_eth_fc_conf fc_conf; 6006 int rx_fc_en = 0; 6007 int tx_fc_en = 0; 6008 int ret; 6009 6010 /* 6011 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6012 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6013 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6014 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6015 */ 6016 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 6017 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 6018 }; 6019 6020 /* Partial command line, retrieve current configuration */ 6021 if (cmd) { 6022 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 6023 if (ret != 0) { 6024 printf("cannot get current flow ctrl parameters, return" 6025 "code = %d\n", ret); 6026 return; 6027 } 6028 6029 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 6030 (fc_conf.mode == RTE_FC_FULL)) 6031 rx_fc_en = 1; 6032 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 6033 (fc_conf.mode == RTE_FC_FULL)) 6034 tx_fc_en = 1; 6035 } 6036 6037 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 6038 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 6039 6040 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 6041 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 6042 6043 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 6044 6045 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 6046 fc_conf.high_water = res->high_water; 6047 6048 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 6049 fc_conf.low_water = res->low_water; 6050 6051 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 6052 fc_conf.pause_time = res->pause_time; 6053 6054 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 6055 fc_conf.send_xon = res->send_xon; 6056 6057 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 6058 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 6059 fc_conf.mac_ctrl_frame_fwd = 1; 6060 else 6061 fc_conf.mac_ctrl_frame_fwd = 0; 6062 } 6063 6064 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 6065 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 6066 6067 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 6068 if (ret != 0) 6069 printf("bad flow contrl parameter, return code = %d \n", ret); 6070 } 6071 6072 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */ 6073 struct cmd_priority_flow_ctrl_set_result { 6074 cmdline_fixed_string_t set; 6075 cmdline_fixed_string_t pfc_ctrl; 6076 cmdline_fixed_string_t rx; 6077 cmdline_fixed_string_t rx_pfc_mode; 6078 cmdline_fixed_string_t tx; 6079 cmdline_fixed_string_t tx_pfc_mode; 6080 uint32_t high_water; 6081 uint32_t low_water; 6082 uint16_t pause_time; 6083 uint8_t priority; 6084 uint8_t port_id; 6085 }; 6086 6087 static void 6088 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 6089 __attribute__((unused)) struct cmdline *cl, 6090 __attribute__((unused)) void *data) 6091 { 6092 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 6093 struct rte_eth_pfc_conf pfc_conf; 6094 int rx_fc_enable, tx_fc_enable; 6095 int ret; 6096 6097 /* 6098 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6099 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6100 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6101 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6102 */ 6103 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 6104 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 6105 }; 6106 6107 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 6108 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 6109 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 6110 pfc_conf.fc.high_water = res->high_water; 6111 pfc_conf.fc.low_water = res->low_water; 6112 pfc_conf.fc.pause_time = res->pause_time; 6113 pfc_conf.priority = res->priority; 6114 6115 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 6116 if (ret != 0) 6117 printf("bad priority flow contrl parameter, return code = %d \n", ret); 6118 } 6119 6120 cmdline_parse_token_string_t cmd_pfc_set_set = 6121 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6122 set, "set"); 6123 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 6124 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6125 pfc_ctrl, "pfc_ctrl"); 6126 cmdline_parse_token_string_t cmd_pfc_set_rx = 6127 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6128 rx, "rx"); 6129 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 6130 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6131 rx_pfc_mode, "on#off"); 6132 cmdline_parse_token_string_t cmd_pfc_set_tx = 6133 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6134 tx, "tx"); 6135 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 6136 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6137 tx_pfc_mode, "on#off"); 6138 cmdline_parse_token_num_t cmd_pfc_set_high_water = 6139 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6140 high_water, UINT32); 6141 cmdline_parse_token_num_t cmd_pfc_set_low_water = 6142 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6143 low_water, UINT32); 6144 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 6145 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6146 pause_time, UINT16); 6147 cmdline_parse_token_num_t cmd_pfc_set_priority = 6148 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6149 priority, UINT8); 6150 cmdline_parse_token_num_t cmd_pfc_set_portid = 6151 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6152 port_id, UINT8); 6153 6154 cmdline_parse_inst_t cmd_priority_flow_control_set = { 6155 .f = cmd_priority_flow_ctrl_set_parsed, 6156 .data = NULL, 6157 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 6158 "<pause_time> <priority> <port_id>: " 6159 "Configure the Ethernet priority flow control", 6160 .tokens = { 6161 (void *)&cmd_pfc_set_set, 6162 (void *)&cmd_pfc_set_flow_ctrl, 6163 (void *)&cmd_pfc_set_rx, 6164 (void *)&cmd_pfc_set_rx_mode, 6165 (void *)&cmd_pfc_set_tx, 6166 (void *)&cmd_pfc_set_tx_mode, 6167 (void *)&cmd_pfc_set_high_water, 6168 (void *)&cmd_pfc_set_low_water, 6169 (void *)&cmd_pfc_set_pause_time, 6170 (void *)&cmd_pfc_set_priority, 6171 (void *)&cmd_pfc_set_portid, 6172 NULL, 6173 }, 6174 }; 6175 6176 /* *** RESET CONFIGURATION *** */ 6177 struct cmd_reset_result { 6178 cmdline_fixed_string_t reset; 6179 cmdline_fixed_string_t def; 6180 }; 6181 6182 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 6183 struct cmdline *cl, 6184 __attribute__((unused)) void *data) 6185 { 6186 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 6187 set_def_fwd_config(); 6188 } 6189 6190 cmdline_parse_token_string_t cmd_reset_set = 6191 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 6192 cmdline_parse_token_string_t cmd_reset_def = 6193 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 6194 "default"); 6195 6196 cmdline_parse_inst_t cmd_reset = { 6197 .f = cmd_reset_parsed, 6198 .data = NULL, 6199 .help_str = "set default: Reset default forwarding configuration", 6200 .tokens = { 6201 (void *)&cmd_reset_set, 6202 (void *)&cmd_reset_def, 6203 NULL, 6204 }, 6205 }; 6206 6207 /* *** START FORWARDING *** */ 6208 struct cmd_start_result { 6209 cmdline_fixed_string_t start; 6210 }; 6211 6212 cmdline_parse_token_string_t cmd_start_start = 6213 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 6214 6215 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 6216 __attribute__((unused)) struct cmdline *cl, 6217 __attribute__((unused)) void *data) 6218 { 6219 start_packet_forwarding(0); 6220 } 6221 6222 cmdline_parse_inst_t cmd_start = { 6223 .f = cmd_start_parsed, 6224 .data = NULL, 6225 .help_str = "start: Start packet forwarding", 6226 .tokens = { 6227 (void *)&cmd_start_start, 6228 NULL, 6229 }, 6230 }; 6231 6232 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 6233 struct cmd_start_tx_first_result { 6234 cmdline_fixed_string_t start; 6235 cmdline_fixed_string_t tx_first; 6236 }; 6237 6238 static void 6239 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 6240 __attribute__((unused)) struct cmdline *cl, 6241 __attribute__((unused)) void *data) 6242 { 6243 start_packet_forwarding(1); 6244 } 6245 6246 cmdline_parse_token_string_t cmd_start_tx_first_start = 6247 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 6248 "start"); 6249 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 6250 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 6251 tx_first, "tx_first"); 6252 6253 cmdline_parse_inst_t cmd_start_tx_first = { 6254 .f = cmd_start_tx_first_parsed, 6255 .data = NULL, 6256 .help_str = "start tx_first: Start packet forwarding, " 6257 "after sending 1 burst of packets", 6258 .tokens = { 6259 (void *)&cmd_start_tx_first_start, 6260 (void *)&cmd_start_tx_first_tx_first, 6261 NULL, 6262 }, 6263 }; 6264 6265 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 6266 struct cmd_start_tx_first_n_result { 6267 cmdline_fixed_string_t start; 6268 cmdline_fixed_string_t tx_first; 6269 uint32_t tx_num; 6270 }; 6271 6272 static void 6273 cmd_start_tx_first_n_parsed(void *parsed_result, 6274 __attribute__((unused)) struct cmdline *cl, 6275 __attribute__((unused)) void *data) 6276 { 6277 struct cmd_start_tx_first_n_result *res = parsed_result; 6278 6279 start_packet_forwarding(res->tx_num); 6280 } 6281 6282 cmdline_parse_token_string_t cmd_start_tx_first_n_start = 6283 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6284 start, "start"); 6285 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 6286 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6287 tx_first, "tx_first"); 6288 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 6289 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 6290 tx_num, UINT32); 6291 6292 cmdline_parse_inst_t cmd_start_tx_first_n = { 6293 .f = cmd_start_tx_first_n_parsed, 6294 .data = NULL, 6295 .help_str = "start tx_first <num>: " 6296 "packet forwarding, after sending <num> bursts of packets", 6297 .tokens = { 6298 (void *)&cmd_start_tx_first_n_start, 6299 (void *)&cmd_start_tx_first_n_tx_first, 6300 (void *)&cmd_start_tx_first_n_tx_num, 6301 NULL, 6302 }, 6303 }; 6304 6305 /* *** SET LINK UP *** */ 6306 struct cmd_set_link_up_result { 6307 cmdline_fixed_string_t set; 6308 cmdline_fixed_string_t link_up; 6309 cmdline_fixed_string_t port; 6310 uint8_t port_id; 6311 }; 6312 6313 cmdline_parse_token_string_t cmd_set_link_up_set = 6314 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 6315 cmdline_parse_token_string_t cmd_set_link_up_link_up = 6316 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 6317 "link-up"); 6318 cmdline_parse_token_string_t cmd_set_link_up_port = 6319 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 6320 cmdline_parse_token_num_t cmd_set_link_up_port_id = 6321 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); 6322 6323 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 6324 __attribute__((unused)) struct cmdline *cl, 6325 __attribute__((unused)) void *data) 6326 { 6327 struct cmd_set_link_up_result *res = parsed_result; 6328 dev_set_link_up(res->port_id); 6329 } 6330 6331 cmdline_parse_inst_t cmd_set_link_up = { 6332 .f = cmd_set_link_up_parsed, 6333 .data = NULL, 6334 .help_str = "set link-up port <port id>", 6335 .tokens = { 6336 (void *)&cmd_set_link_up_set, 6337 (void *)&cmd_set_link_up_link_up, 6338 (void *)&cmd_set_link_up_port, 6339 (void *)&cmd_set_link_up_port_id, 6340 NULL, 6341 }, 6342 }; 6343 6344 /* *** SET LINK DOWN *** */ 6345 struct cmd_set_link_down_result { 6346 cmdline_fixed_string_t set; 6347 cmdline_fixed_string_t link_down; 6348 cmdline_fixed_string_t port; 6349 uint8_t port_id; 6350 }; 6351 6352 cmdline_parse_token_string_t cmd_set_link_down_set = 6353 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 6354 cmdline_parse_token_string_t cmd_set_link_down_link_down = 6355 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 6356 "link-down"); 6357 cmdline_parse_token_string_t cmd_set_link_down_port = 6358 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 6359 cmdline_parse_token_num_t cmd_set_link_down_port_id = 6360 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); 6361 6362 static void cmd_set_link_down_parsed( 6363 __attribute__((unused)) void *parsed_result, 6364 __attribute__((unused)) struct cmdline *cl, 6365 __attribute__((unused)) void *data) 6366 { 6367 struct cmd_set_link_down_result *res = parsed_result; 6368 dev_set_link_down(res->port_id); 6369 } 6370 6371 cmdline_parse_inst_t cmd_set_link_down = { 6372 .f = cmd_set_link_down_parsed, 6373 .data = NULL, 6374 .help_str = "set link-down port <port id>", 6375 .tokens = { 6376 (void *)&cmd_set_link_down_set, 6377 (void *)&cmd_set_link_down_link_down, 6378 (void *)&cmd_set_link_down_port, 6379 (void *)&cmd_set_link_down_port_id, 6380 NULL, 6381 }, 6382 }; 6383 6384 /* *** SHOW CFG *** */ 6385 struct cmd_showcfg_result { 6386 cmdline_fixed_string_t show; 6387 cmdline_fixed_string_t cfg; 6388 cmdline_fixed_string_t what; 6389 }; 6390 6391 static void cmd_showcfg_parsed(void *parsed_result, 6392 __attribute__((unused)) struct cmdline *cl, 6393 __attribute__((unused)) void *data) 6394 { 6395 struct cmd_showcfg_result *res = parsed_result; 6396 if (!strcmp(res->what, "rxtx")) 6397 rxtx_config_display(); 6398 else if (!strcmp(res->what, "cores")) 6399 fwd_lcores_config_display(); 6400 else if (!strcmp(res->what, "fwd")) 6401 pkt_fwd_config_display(&cur_fwd_config); 6402 else if (!strcmp(res->what, "txpkts")) 6403 show_tx_pkt_segments(); 6404 } 6405 6406 cmdline_parse_token_string_t cmd_showcfg_show = 6407 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 6408 cmdline_parse_token_string_t cmd_showcfg_port = 6409 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 6410 cmdline_parse_token_string_t cmd_showcfg_what = 6411 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 6412 "rxtx#cores#fwd#txpkts"); 6413 6414 cmdline_parse_inst_t cmd_showcfg = { 6415 .f = cmd_showcfg_parsed, 6416 .data = NULL, 6417 .help_str = "show config rxtx|cores|fwd|txpkts", 6418 .tokens = { 6419 (void *)&cmd_showcfg_show, 6420 (void *)&cmd_showcfg_port, 6421 (void *)&cmd_showcfg_what, 6422 NULL, 6423 }, 6424 }; 6425 6426 /* *** SHOW ALL PORT INFO *** */ 6427 struct cmd_showportall_result { 6428 cmdline_fixed_string_t show; 6429 cmdline_fixed_string_t port; 6430 cmdline_fixed_string_t what; 6431 cmdline_fixed_string_t all; 6432 }; 6433 6434 static void cmd_showportall_parsed(void *parsed_result, 6435 __attribute__((unused)) struct cmdline *cl, 6436 __attribute__((unused)) void *data) 6437 { 6438 portid_t i; 6439 6440 struct cmd_showportall_result *res = parsed_result; 6441 if (!strcmp(res->show, "clear")) { 6442 if (!strcmp(res->what, "stats")) 6443 RTE_ETH_FOREACH_DEV(i) 6444 nic_stats_clear(i); 6445 else if (!strcmp(res->what, "xstats")) 6446 RTE_ETH_FOREACH_DEV(i) 6447 nic_xstats_clear(i); 6448 } else if (!strcmp(res->what, "info")) 6449 RTE_ETH_FOREACH_DEV(i) 6450 port_infos_display(i); 6451 else if (!strcmp(res->what, "stats")) 6452 RTE_ETH_FOREACH_DEV(i) 6453 nic_stats_display(i); 6454 else if (!strcmp(res->what, "xstats")) 6455 RTE_ETH_FOREACH_DEV(i) 6456 nic_xstats_display(i); 6457 else if (!strcmp(res->what, "fdir")) 6458 RTE_ETH_FOREACH_DEV(i) 6459 fdir_get_infos(i); 6460 else if (!strcmp(res->what, "stat_qmap")) 6461 RTE_ETH_FOREACH_DEV(i) 6462 nic_stats_mapping_display(i); 6463 else if (!strcmp(res->what, "dcb_tc")) 6464 RTE_ETH_FOREACH_DEV(i) 6465 port_dcb_info_display(i); 6466 else if (!strcmp(res->what, "cap")) 6467 RTE_ETH_FOREACH_DEV(i) 6468 port_offload_cap_display(i); 6469 } 6470 6471 cmdline_parse_token_string_t cmd_showportall_show = 6472 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 6473 "show#clear"); 6474 cmdline_parse_token_string_t cmd_showportall_port = 6475 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 6476 cmdline_parse_token_string_t cmd_showportall_what = 6477 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 6478 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6479 cmdline_parse_token_string_t cmd_showportall_all = 6480 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 6481 cmdline_parse_inst_t cmd_showportall = { 6482 .f = cmd_showportall_parsed, 6483 .data = NULL, 6484 .help_str = "show|clear port " 6485 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all", 6486 .tokens = { 6487 (void *)&cmd_showportall_show, 6488 (void *)&cmd_showportall_port, 6489 (void *)&cmd_showportall_what, 6490 (void *)&cmd_showportall_all, 6491 NULL, 6492 }, 6493 }; 6494 6495 /* *** SHOW PORT INFO *** */ 6496 struct cmd_showport_result { 6497 cmdline_fixed_string_t show; 6498 cmdline_fixed_string_t port; 6499 cmdline_fixed_string_t what; 6500 uint8_t portnum; 6501 }; 6502 6503 static void cmd_showport_parsed(void *parsed_result, 6504 __attribute__((unused)) struct cmdline *cl, 6505 __attribute__((unused)) void *data) 6506 { 6507 struct cmd_showport_result *res = parsed_result; 6508 if (!strcmp(res->show, "clear")) { 6509 if (!strcmp(res->what, "stats")) 6510 nic_stats_clear(res->portnum); 6511 else if (!strcmp(res->what, "xstats")) 6512 nic_xstats_clear(res->portnum); 6513 } else if (!strcmp(res->what, "info")) 6514 port_infos_display(res->portnum); 6515 else if (!strcmp(res->what, "stats")) 6516 nic_stats_display(res->portnum); 6517 else if (!strcmp(res->what, "xstats")) 6518 nic_xstats_display(res->portnum); 6519 else if (!strcmp(res->what, "fdir")) 6520 fdir_get_infos(res->portnum); 6521 else if (!strcmp(res->what, "stat_qmap")) 6522 nic_stats_mapping_display(res->portnum); 6523 else if (!strcmp(res->what, "dcb_tc")) 6524 port_dcb_info_display(res->portnum); 6525 else if (!strcmp(res->what, "cap")) 6526 port_offload_cap_display(res->portnum); 6527 } 6528 6529 cmdline_parse_token_string_t cmd_showport_show = 6530 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 6531 "show#clear"); 6532 cmdline_parse_token_string_t cmd_showport_port = 6533 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 6534 cmdline_parse_token_string_t cmd_showport_what = 6535 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 6536 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6537 cmdline_parse_token_num_t cmd_showport_portnum = 6538 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); 6539 6540 cmdline_parse_inst_t cmd_showport = { 6541 .f = cmd_showport_parsed, 6542 .data = NULL, 6543 .help_str = "show|clear port " 6544 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap " 6545 "<port_id>", 6546 .tokens = { 6547 (void *)&cmd_showport_show, 6548 (void *)&cmd_showport_port, 6549 (void *)&cmd_showport_what, 6550 (void *)&cmd_showport_portnum, 6551 NULL, 6552 }, 6553 }; 6554 6555 /* *** SHOW QUEUE INFO *** */ 6556 struct cmd_showqueue_result { 6557 cmdline_fixed_string_t show; 6558 cmdline_fixed_string_t type; 6559 cmdline_fixed_string_t what; 6560 uint8_t portnum; 6561 uint16_t queuenum; 6562 }; 6563 6564 static void 6565 cmd_showqueue_parsed(void *parsed_result, 6566 __attribute__((unused)) struct cmdline *cl, 6567 __attribute__((unused)) void *data) 6568 { 6569 struct cmd_showqueue_result *res = parsed_result; 6570 6571 if (!strcmp(res->type, "rxq")) 6572 rx_queue_infos_display(res->portnum, res->queuenum); 6573 else if (!strcmp(res->type, "txq")) 6574 tx_queue_infos_display(res->portnum, res->queuenum); 6575 } 6576 6577 cmdline_parse_token_string_t cmd_showqueue_show = 6578 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 6579 cmdline_parse_token_string_t cmd_showqueue_type = 6580 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 6581 cmdline_parse_token_string_t cmd_showqueue_what = 6582 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 6583 cmdline_parse_token_num_t cmd_showqueue_portnum = 6584 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8); 6585 cmdline_parse_token_num_t cmd_showqueue_queuenum = 6586 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); 6587 6588 cmdline_parse_inst_t cmd_showqueue = { 6589 .f = cmd_showqueue_parsed, 6590 .data = NULL, 6591 .help_str = "show rxq|txq info <port_id> <queue_id>", 6592 .tokens = { 6593 (void *)&cmd_showqueue_show, 6594 (void *)&cmd_showqueue_type, 6595 (void *)&cmd_showqueue_what, 6596 (void *)&cmd_showqueue_portnum, 6597 (void *)&cmd_showqueue_queuenum, 6598 NULL, 6599 }, 6600 }; 6601 6602 /* *** READ PORT REGISTER *** */ 6603 struct cmd_read_reg_result { 6604 cmdline_fixed_string_t read; 6605 cmdline_fixed_string_t reg; 6606 uint8_t port_id; 6607 uint32_t reg_off; 6608 }; 6609 6610 static void 6611 cmd_read_reg_parsed(void *parsed_result, 6612 __attribute__((unused)) struct cmdline *cl, 6613 __attribute__((unused)) void *data) 6614 { 6615 struct cmd_read_reg_result *res = parsed_result; 6616 port_reg_display(res->port_id, res->reg_off); 6617 } 6618 6619 cmdline_parse_token_string_t cmd_read_reg_read = 6620 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 6621 cmdline_parse_token_string_t cmd_read_reg_reg = 6622 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 6623 cmdline_parse_token_num_t cmd_read_reg_port_id = 6624 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); 6625 cmdline_parse_token_num_t cmd_read_reg_reg_off = 6626 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 6627 6628 cmdline_parse_inst_t cmd_read_reg = { 6629 .f = cmd_read_reg_parsed, 6630 .data = NULL, 6631 .help_str = "read reg <port_id> <reg_off>", 6632 .tokens = { 6633 (void *)&cmd_read_reg_read, 6634 (void *)&cmd_read_reg_reg, 6635 (void *)&cmd_read_reg_port_id, 6636 (void *)&cmd_read_reg_reg_off, 6637 NULL, 6638 }, 6639 }; 6640 6641 /* *** READ PORT REGISTER BIT FIELD *** */ 6642 struct cmd_read_reg_bit_field_result { 6643 cmdline_fixed_string_t read; 6644 cmdline_fixed_string_t regfield; 6645 uint8_t port_id; 6646 uint32_t reg_off; 6647 uint8_t bit1_pos; 6648 uint8_t bit2_pos; 6649 }; 6650 6651 static void 6652 cmd_read_reg_bit_field_parsed(void *parsed_result, 6653 __attribute__((unused)) struct cmdline *cl, 6654 __attribute__((unused)) void *data) 6655 { 6656 struct cmd_read_reg_bit_field_result *res = parsed_result; 6657 port_reg_bit_field_display(res->port_id, res->reg_off, 6658 res->bit1_pos, res->bit2_pos); 6659 } 6660 6661 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 6662 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 6663 "read"); 6664 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 6665 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 6666 regfield, "regfield"); 6667 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 6668 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 6669 UINT8); 6670 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 6671 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 6672 UINT32); 6673 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 6674 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 6675 UINT8); 6676 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 6677 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 6678 UINT8); 6679 6680 cmdline_parse_inst_t cmd_read_reg_bit_field = { 6681 .f = cmd_read_reg_bit_field_parsed, 6682 .data = NULL, 6683 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 6684 "Read register bit field between bit_x and bit_y included", 6685 .tokens = { 6686 (void *)&cmd_read_reg_bit_field_read, 6687 (void *)&cmd_read_reg_bit_field_regfield, 6688 (void *)&cmd_read_reg_bit_field_port_id, 6689 (void *)&cmd_read_reg_bit_field_reg_off, 6690 (void *)&cmd_read_reg_bit_field_bit1_pos, 6691 (void *)&cmd_read_reg_bit_field_bit2_pos, 6692 NULL, 6693 }, 6694 }; 6695 6696 /* *** READ PORT REGISTER BIT *** */ 6697 struct cmd_read_reg_bit_result { 6698 cmdline_fixed_string_t read; 6699 cmdline_fixed_string_t regbit; 6700 uint8_t port_id; 6701 uint32_t reg_off; 6702 uint8_t bit_pos; 6703 }; 6704 6705 static void 6706 cmd_read_reg_bit_parsed(void *parsed_result, 6707 __attribute__((unused)) struct cmdline *cl, 6708 __attribute__((unused)) void *data) 6709 { 6710 struct cmd_read_reg_bit_result *res = parsed_result; 6711 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 6712 } 6713 6714 cmdline_parse_token_string_t cmd_read_reg_bit_read = 6715 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 6716 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 6717 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 6718 regbit, "regbit"); 6719 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 6720 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); 6721 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 6722 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 6723 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 6724 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 6725 6726 cmdline_parse_inst_t cmd_read_reg_bit = { 6727 .f = cmd_read_reg_bit_parsed, 6728 .data = NULL, 6729 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 6730 .tokens = { 6731 (void *)&cmd_read_reg_bit_read, 6732 (void *)&cmd_read_reg_bit_regbit, 6733 (void *)&cmd_read_reg_bit_port_id, 6734 (void *)&cmd_read_reg_bit_reg_off, 6735 (void *)&cmd_read_reg_bit_bit_pos, 6736 NULL, 6737 }, 6738 }; 6739 6740 /* *** WRITE PORT REGISTER *** */ 6741 struct cmd_write_reg_result { 6742 cmdline_fixed_string_t write; 6743 cmdline_fixed_string_t reg; 6744 uint8_t port_id; 6745 uint32_t reg_off; 6746 uint32_t value; 6747 }; 6748 6749 static void 6750 cmd_write_reg_parsed(void *parsed_result, 6751 __attribute__((unused)) struct cmdline *cl, 6752 __attribute__((unused)) void *data) 6753 { 6754 struct cmd_write_reg_result *res = parsed_result; 6755 port_reg_set(res->port_id, res->reg_off, res->value); 6756 } 6757 6758 cmdline_parse_token_string_t cmd_write_reg_write = 6759 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 6760 cmdline_parse_token_string_t cmd_write_reg_reg = 6761 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 6762 cmdline_parse_token_num_t cmd_write_reg_port_id = 6763 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); 6764 cmdline_parse_token_num_t cmd_write_reg_reg_off = 6765 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 6766 cmdline_parse_token_num_t cmd_write_reg_value = 6767 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 6768 6769 cmdline_parse_inst_t cmd_write_reg = { 6770 .f = cmd_write_reg_parsed, 6771 .data = NULL, 6772 .help_str = "write reg <port_id> <reg_off> <reg_value>", 6773 .tokens = { 6774 (void *)&cmd_write_reg_write, 6775 (void *)&cmd_write_reg_reg, 6776 (void *)&cmd_write_reg_port_id, 6777 (void *)&cmd_write_reg_reg_off, 6778 (void *)&cmd_write_reg_value, 6779 NULL, 6780 }, 6781 }; 6782 6783 /* *** WRITE PORT REGISTER BIT FIELD *** */ 6784 struct cmd_write_reg_bit_field_result { 6785 cmdline_fixed_string_t write; 6786 cmdline_fixed_string_t regfield; 6787 uint8_t port_id; 6788 uint32_t reg_off; 6789 uint8_t bit1_pos; 6790 uint8_t bit2_pos; 6791 uint32_t value; 6792 }; 6793 6794 static void 6795 cmd_write_reg_bit_field_parsed(void *parsed_result, 6796 __attribute__((unused)) struct cmdline *cl, 6797 __attribute__((unused)) void *data) 6798 { 6799 struct cmd_write_reg_bit_field_result *res = parsed_result; 6800 port_reg_bit_field_set(res->port_id, res->reg_off, 6801 res->bit1_pos, res->bit2_pos, res->value); 6802 } 6803 6804 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 6805 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 6806 "write"); 6807 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 6808 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 6809 regfield, "regfield"); 6810 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 6811 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 6812 UINT8); 6813 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 6814 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 6815 UINT32); 6816 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 6817 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 6818 UINT8); 6819 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 6820 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 6821 UINT8); 6822 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 6823 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 6824 UINT32); 6825 6826 cmdline_parse_inst_t cmd_write_reg_bit_field = { 6827 .f = cmd_write_reg_bit_field_parsed, 6828 .data = NULL, 6829 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 6830 "<reg_value>: " 6831 "Set register bit field between bit_x and bit_y included", 6832 .tokens = { 6833 (void *)&cmd_write_reg_bit_field_write, 6834 (void *)&cmd_write_reg_bit_field_regfield, 6835 (void *)&cmd_write_reg_bit_field_port_id, 6836 (void *)&cmd_write_reg_bit_field_reg_off, 6837 (void *)&cmd_write_reg_bit_field_bit1_pos, 6838 (void *)&cmd_write_reg_bit_field_bit2_pos, 6839 (void *)&cmd_write_reg_bit_field_value, 6840 NULL, 6841 }, 6842 }; 6843 6844 /* *** WRITE PORT REGISTER BIT *** */ 6845 struct cmd_write_reg_bit_result { 6846 cmdline_fixed_string_t write; 6847 cmdline_fixed_string_t regbit; 6848 uint8_t port_id; 6849 uint32_t reg_off; 6850 uint8_t bit_pos; 6851 uint8_t value; 6852 }; 6853 6854 static void 6855 cmd_write_reg_bit_parsed(void *parsed_result, 6856 __attribute__((unused)) struct cmdline *cl, 6857 __attribute__((unused)) void *data) 6858 { 6859 struct cmd_write_reg_bit_result *res = parsed_result; 6860 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 6861 } 6862 6863 cmdline_parse_token_string_t cmd_write_reg_bit_write = 6864 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 6865 "write"); 6866 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 6867 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 6868 regbit, "regbit"); 6869 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 6870 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); 6871 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 6872 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 6873 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 6874 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 6875 cmdline_parse_token_num_t cmd_write_reg_bit_value = 6876 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 6877 6878 cmdline_parse_inst_t cmd_write_reg_bit = { 6879 .f = cmd_write_reg_bit_parsed, 6880 .data = NULL, 6881 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 6882 "0 <= bit_x <= 31", 6883 .tokens = { 6884 (void *)&cmd_write_reg_bit_write, 6885 (void *)&cmd_write_reg_bit_regbit, 6886 (void *)&cmd_write_reg_bit_port_id, 6887 (void *)&cmd_write_reg_bit_reg_off, 6888 (void *)&cmd_write_reg_bit_bit_pos, 6889 (void *)&cmd_write_reg_bit_value, 6890 NULL, 6891 }, 6892 }; 6893 6894 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 6895 struct cmd_read_rxd_txd_result { 6896 cmdline_fixed_string_t read; 6897 cmdline_fixed_string_t rxd_txd; 6898 uint8_t port_id; 6899 uint16_t queue_id; 6900 uint16_t desc_id; 6901 }; 6902 6903 static void 6904 cmd_read_rxd_txd_parsed(void *parsed_result, 6905 __attribute__((unused)) struct cmdline *cl, 6906 __attribute__((unused)) void *data) 6907 { 6908 struct cmd_read_rxd_txd_result *res = parsed_result; 6909 6910 if (!strcmp(res->rxd_txd, "rxd")) 6911 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6912 else if (!strcmp(res->rxd_txd, "txd")) 6913 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 6914 } 6915 6916 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 6917 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 6918 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 6919 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 6920 "rxd#txd"); 6921 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 6922 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); 6923 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 6924 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 6925 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 6926 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 6927 6928 cmdline_parse_inst_t cmd_read_rxd_txd = { 6929 .f = cmd_read_rxd_txd_parsed, 6930 .data = NULL, 6931 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 6932 .tokens = { 6933 (void *)&cmd_read_rxd_txd_read, 6934 (void *)&cmd_read_rxd_txd_rxd_txd, 6935 (void *)&cmd_read_rxd_txd_port_id, 6936 (void *)&cmd_read_rxd_txd_queue_id, 6937 (void *)&cmd_read_rxd_txd_desc_id, 6938 NULL, 6939 }, 6940 }; 6941 6942 /* *** QUIT *** */ 6943 struct cmd_quit_result { 6944 cmdline_fixed_string_t quit; 6945 }; 6946 6947 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 6948 struct cmdline *cl, 6949 __attribute__((unused)) void *data) 6950 { 6951 pmd_test_exit(); 6952 cmdline_quit(cl); 6953 } 6954 6955 cmdline_parse_token_string_t cmd_quit_quit = 6956 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 6957 6958 cmdline_parse_inst_t cmd_quit = { 6959 .f = cmd_quit_parsed, 6960 .data = NULL, 6961 .help_str = "quit: Exit application", 6962 .tokens = { 6963 (void *)&cmd_quit_quit, 6964 NULL, 6965 }, 6966 }; 6967 6968 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 6969 struct cmd_mac_addr_result { 6970 cmdline_fixed_string_t mac_addr_cmd; 6971 cmdline_fixed_string_t what; 6972 uint8_t port_num; 6973 struct ether_addr address; 6974 }; 6975 6976 static void cmd_mac_addr_parsed(void *parsed_result, 6977 __attribute__((unused)) struct cmdline *cl, 6978 __attribute__((unused)) void *data) 6979 { 6980 struct cmd_mac_addr_result *res = parsed_result; 6981 int ret; 6982 6983 if (strcmp(res->what, "add") == 0) 6984 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 6985 else if (strcmp(res->what, "set") == 0) 6986 ret = rte_eth_dev_default_mac_addr_set(res->port_num, 6987 &res->address); 6988 else 6989 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 6990 6991 /* check the return value and print it if is < 0 */ 6992 if(ret < 0) 6993 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 6994 6995 } 6996 6997 cmdline_parse_token_string_t cmd_mac_addr_cmd = 6998 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 6999 "mac_addr"); 7000 cmdline_parse_token_string_t cmd_mac_addr_what = 7001 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 7002 "add#remove#set"); 7003 cmdline_parse_token_num_t cmd_mac_addr_portnum = 7004 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); 7005 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 7006 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 7007 7008 cmdline_parse_inst_t cmd_mac_addr = { 7009 .f = cmd_mac_addr_parsed, 7010 .data = (void *)0, 7011 .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: " 7012 "Add/Remove/Set MAC address on port_id", 7013 .tokens = { 7014 (void *)&cmd_mac_addr_cmd, 7015 (void *)&cmd_mac_addr_what, 7016 (void *)&cmd_mac_addr_portnum, 7017 (void *)&cmd_mac_addr_addr, 7018 NULL, 7019 }, 7020 }; 7021 7022 7023 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 7024 struct cmd_set_qmap_result { 7025 cmdline_fixed_string_t set; 7026 cmdline_fixed_string_t qmap; 7027 cmdline_fixed_string_t what; 7028 uint8_t port_id; 7029 uint16_t queue_id; 7030 uint8_t map_value; 7031 }; 7032 7033 static void 7034 cmd_set_qmap_parsed(void *parsed_result, 7035 __attribute__((unused)) struct cmdline *cl, 7036 __attribute__((unused)) void *data) 7037 { 7038 struct cmd_set_qmap_result *res = parsed_result; 7039 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 7040 7041 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 7042 } 7043 7044 cmdline_parse_token_string_t cmd_setqmap_set = 7045 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7046 set, "set"); 7047 cmdline_parse_token_string_t cmd_setqmap_qmap = 7048 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7049 qmap, "stat_qmap"); 7050 cmdline_parse_token_string_t cmd_setqmap_what = 7051 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7052 what, "tx#rx"); 7053 cmdline_parse_token_num_t cmd_setqmap_portid = 7054 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7055 port_id, UINT8); 7056 cmdline_parse_token_num_t cmd_setqmap_queueid = 7057 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7058 queue_id, UINT16); 7059 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 7060 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7061 map_value, UINT8); 7062 7063 cmdline_parse_inst_t cmd_set_qmap = { 7064 .f = cmd_set_qmap_parsed, 7065 .data = NULL, 7066 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 7067 "Set statistics mapping value on tx|rx queue_id of port_id", 7068 .tokens = { 7069 (void *)&cmd_setqmap_set, 7070 (void *)&cmd_setqmap_qmap, 7071 (void *)&cmd_setqmap_what, 7072 (void *)&cmd_setqmap_portid, 7073 (void *)&cmd_setqmap_queueid, 7074 (void *)&cmd_setqmap_mapvalue, 7075 NULL, 7076 }, 7077 }; 7078 7079 /* *** CONFIGURE UNICAST HASH TABLE *** */ 7080 struct cmd_set_uc_hash_table { 7081 cmdline_fixed_string_t set; 7082 cmdline_fixed_string_t port; 7083 uint8_t port_id; 7084 cmdline_fixed_string_t what; 7085 struct ether_addr address; 7086 cmdline_fixed_string_t mode; 7087 }; 7088 7089 static void 7090 cmd_set_uc_hash_parsed(void *parsed_result, 7091 __attribute__((unused)) struct cmdline *cl, 7092 __attribute__((unused)) void *data) 7093 { 7094 int ret=0; 7095 struct cmd_set_uc_hash_table *res = parsed_result; 7096 7097 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7098 7099 if (strcmp(res->what, "uta") == 0) 7100 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 7101 &res->address,(uint8_t)is_on); 7102 if (ret < 0) 7103 printf("bad unicast hash table parameter, return code = %d \n", ret); 7104 7105 } 7106 7107 cmdline_parse_token_string_t cmd_set_uc_hash_set = 7108 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7109 set, "set"); 7110 cmdline_parse_token_string_t cmd_set_uc_hash_port = 7111 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7112 port, "port"); 7113 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 7114 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 7115 port_id, UINT8); 7116 cmdline_parse_token_string_t cmd_set_uc_hash_what = 7117 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7118 what, "uta"); 7119 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 7120 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 7121 address); 7122 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 7123 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7124 mode, "on#off"); 7125 7126 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 7127 .f = cmd_set_uc_hash_parsed, 7128 .data = NULL, 7129 .help_str = "set port <port_id> uta <mac_addr> on|off)", 7130 .tokens = { 7131 (void *)&cmd_set_uc_hash_set, 7132 (void *)&cmd_set_uc_hash_port, 7133 (void *)&cmd_set_uc_hash_portid, 7134 (void *)&cmd_set_uc_hash_what, 7135 (void *)&cmd_set_uc_hash_mac, 7136 (void *)&cmd_set_uc_hash_mode, 7137 NULL, 7138 }, 7139 }; 7140 7141 struct cmd_set_uc_all_hash_table { 7142 cmdline_fixed_string_t set; 7143 cmdline_fixed_string_t port; 7144 uint8_t port_id; 7145 cmdline_fixed_string_t what; 7146 cmdline_fixed_string_t value; 7147 cmdline_fixed_string_t mode; 7148 }; 7149 7150 static void 7151 cmd_set_uc_all_hash_parsed(void *parsed_result, 7152 __attribute__((unused)) struct cmdline *cl, 7153 __attribute__((unused)) void *data) 7154 { 7155 int ret=0; 7156 struct cmd_set_uc_all_hash_table *res = parsed_result; 7157 7158 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7159 7160 if ((strcmp(res->what, "uta") == 0) && 7161 (strcmp(res->value, "all") == 0)) 7162 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 7163 if (ret < 0) 7164 printf("bad unicast hash table parameter," 7165 "return code = %d \n", ret); 7166 } 7167 7168 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 7169 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7170 set, "set"); 7171 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 7172 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7173 port, "port"); 7174 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 7175 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 7176 port_id, UINT8); 7177 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 7178 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7179 what, "uta"); 7180 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 7181 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7182 value,"all"); 7183 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 7184 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7185 mode, "on#off"); 7186 7187 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 7188 .f = cmd_set_uc_all_hash_parsed, 7189 .data = NULL, 7190 .help_str = "set port <port_id> uta all on|off", 7191 .tokens = { 7192 (void *)&cmd_set_uc_all_hash_set, 7193 (void *)&cmd_set_uc_all_hash_port, 7194 (void *)&cmd_set_uc_all_hash_portid, 7195 (void *)&cmd_set_uc_all_hash_what, 7196 (void *)&cmd_set_uc_all_hash_value, 7197 (void *)&cmd_set_uc_all_hash_mode, 7198 NULL, 7199 }, 7200 }; 7201 7202 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 7203 struct cmd_set_vf_macvlan_filter { 7204 cmdline_fixed_string_t set; 7205 cmdline_fixed_string_t port; 7206 uint8_t port_id; 7207 cmdline_fixed_string_t vf; 7208 uint8_t vf_id; 7209 struct ether_addr address; 7210 cmdline_fixed_string_t filter_type; 7211 cmdline_fixed_string_t mode; 7212 }; 7213 7214 static void 7215 cmd_set_vf_macvlan_parsed(void *parsed_result, 7216 __attribute__((unused)) struct cmdline *cl, 7217 __attribute__((unused)) void *data) 7218 { 7219 int is_on, ret = 0; 7220 struct cmd_set_vf_macvlan_filter *res = parsed_result; 7221 struct rte_eth_mac_filter filter; 7222 7223 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 7224 7225 rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 7226 7227 /* set VF MAC filter */ 7228 filter.is_vf = 1; 7229 7230 /* set VF ID */ 7231 filter.dst_id = res->vf_id; 7232 7233 if (!strcmp(res->filter_type, "exact-mac")) 7234 filter.filter_type = RTE_MAC_PERFECT_MATCH; 7235 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 7236 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 7237 else if (!strcmp(res->filter_type, "hashmac")) 7238 filter.filter_type = RTE_MAC_HASH_MATCH; 7239 else if (!strcmp(res->filter_type, "hashmac-vlan")) 7240 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 7241 7242 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7243 7244 if (is_on) 7245 ret = rte_eth_dev_filter_ctrl(res->port_id, 7246 RTE_ETH_FILTER_MACVLAN, 7247 RTE_ETH_FILTER_ADD, 7248 &filter); 7249 else 7250 ret = rte_eth_dev_filter_ctrl(res->port_id, 7251 RTE_ETH_FILTER_MACVLAN, 7252 RTE_ETH_FILTER_DELETE, 7253 &filter); 7254 7255 if (ret < 0) 7256 printf("bad set MAC hash parameter, return code = %d\n", ret); 7257 7258 } 7259 7260 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 7261 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7262 set, "set"); 7263 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 7264 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7265 port, "port"); 7266 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 7267 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7268 port_id, UINT8); 7269 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 7270 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7271 vf, "vf"); 7272 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 7273 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7274 vf_id, UINT8); 7275 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 7276 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7277 address); 7278 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 7279 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7280 filter_type, "exact-mac#exact-mac-vlan" 7281 "#hashmac#hashmac-vlan"); 7282 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 7283 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7284 mode, "on#off"); 7285 7286 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 7287 .f = cmd_set_vf_macvlan_parsed, 7288 .data = NULL, 7289 .help_str = "set port <port_id> vf <vf_id> <mac_addr> " 7290 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: " 7291 "Exact match rule: exact match of MAC or MAC and VLAN; " 7292 "hash match rule: hash match of MAC and exact match of VLAN", 7293 .tokens = { 7294 (void *)&cmd_set_vf_macvlan_set, 7295 (void *)&cmd_set_vf_macvlan_port, 7296 (void *)&cmd_set_vf_macvlan_portid, 7297 (void *)&cmd_set_vf_macvlan_vf, 7298 (void *)&cmd_set_vf_macvlan_vf_id, 7299 (void *)&cmd_set_vf_macvlan_mac, 7300 (void *)&cmd_set_vf_macvlan_filter_type, 7301 (void *)&cmd_set_vf_macvlan_mode, 7302 NULL, 7303 }, 7304 }; 7305 7306 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 7307 struct cmd_set_vf_traffic { 7308 cmdline_fixed_string_t set; 7309 cmdline_fixed_string_t port; 7310 uint8_t port_id; 7311 cmdline_fixed_string_t vf; 7312 uint8_t vf_id; 7313 cmdline_fixed_string_t what; 7314 cmdline_fixed_string_t mode; 7315 }; 7316 7317 static void 7318 cmd_set_vf_traffic_parsed(void *parsed_result, 7319 __attribute__((unused)) struct cmdline *cl, 7320 __attribute__((unused)) void *data) 7321 { 7322 struct cmd_set_vf_traffic *res = parsed_result; 7323 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 7324 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7325 7326 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 7327 } 7328 7329 cmdline_parse_token_string_t cmd_setvf_traffic_set = 7330 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7331 set, "set"); 7332 cmdline_parse_token_string_t cmd_setvf_traffic_port = 7333 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7334 port, "port"); 7335 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 7336 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7337 port_id, UINT8); 7338 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 7339 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7340 vf, "vf"); 7341 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 7342 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7343 vf_id, UINT8); 7344 cmdline_parse_token_string_t cmd_setvf_traffic_what = 7345 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7346 what, "tx#rx"); 7347 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 7348 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7349 mode, "on#off"); 7350 7351 cmdline_parse_inst_t cmd_set_vf_traffic = { 7352 .f = cmd_set_vf_traffic_parsed, 7353 .data = NULL, 7354 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 7355 .tokens = { 7356 (void *)&cmd_setvf_traffic_set, 7357 (void *)&cmd_setvf_traffic_port, 7358 (void *)&cmd_setvf_traffic_portid, 7359 (void *)&cmd_setvf_traffic_vf, 7360 (void *)&cmd_setvf_traffic_vfid, 7361 (void *)&cmd_setvf_traffic_what, 7362 (void *)&cmd_setvf_traffic_mode, 7363 NULL, 7364 }, 7365 }; 7366 7367 /* *** CONFIGURE VF RECEIVE MODE *** */ 7368 struct cmd_set_vf_rxmode { 7369 cmdline_fixed_string_t set; 7370 cmdline_fixed_string_t port; 7371 uint8_t port_id; 7372 cmdline_fixed_string_t vf; 7373 uint8_t vf_id; 7374 cmdline_fixed_string_t what; 7375 cmdline_fixed_string_t mode; 7376 cmdline_fixed_string_t on; 7377 }; 7378 7379 static void 7380 cmd_set_vf_rxmode_parsed(void *parsed_result, 7381 __attribute__((unused)) struct cmdline *cl, 7382 __attribute__((unused)) void *data) 7383 { 7384 int ret = -ENOTSUP; 7385 uint16_t rx_mode = 0; 7386 struct cmd_set_vf_rxmode *res = parsed_result; 7387 7388 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 7389 if (!strcmp(res->what,"rxmode")) { 7390 if (!strcmp(res->mode, "AUPE")) 7391 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 7392 else if (!strcmp(res->mode, "ROPE")) 7393 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 7394 else if (!strcmp(res->mode, "BAM")) 7395 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 7396 else if (!strncmp(res->mode, "MPE",3)) 7397 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 7398 } 7399 7400 #ifdef RTE_LIBRTE_IXGBE_PMD 7401 if (ret == -ENOTSUP) 7402 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, 7403 rx_mode, (uint8_t)is_on); 7404 #endif 7405 #ifdef RTE_LIBRTE_BNXT_PMD 7406 if (ret == -ENOTSUP) 7407 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id, 7408 rx_mode, (uint8_t)is_on); 7409 #endif 7410 if (ret < 0) 7411 printf("bad VF receive mode parameter, return code = %d \n", 7412 ret); 7413 } 7414 7415 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 7416 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7417 set, "set"); 7418 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 7419 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7420 port, "port"); 7421 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 7422 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7423 port_id, UINT8); 7424 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 7425 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7426 vf, "vf"); 7427 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 7428 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7429 vf_id, UINT8); 7430 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 7431 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7432 what, "rxmode"); 7433 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 7434 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7435 mode, "AUPE#ROPE#BAM#MPE"); 7436 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 7437 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7438 on, "on#off"); 7439 7440 cmdline_parse_inst_t cmd_set_vf_rxmode = { 7441 .f = cmd_set_vf_rxmode_parsed, 7442 .data = NULL, 7443 .help_str = "set port <port_id> vf <vf_id> rxmode " 7444 "AUPE|ROPE|BAM|MPE on|off", 7445 .tokens = { 7446 (void *)&cmd_set_vf_rxmode_set, 7447 (void *)&cmd_set_vf_rxmode_port, 7448 (void *)&cmd_set_vf_rxmode_portid, 7449 (void *)&cmd_set_vf_rxmode_vf, 7450 (void *)&cmd_set_vf_rxmode_vfid, 7451 (void *)&cmd_set_vf_rxmode_what, 7452 (void *)&cmd_set_vf_rxmode_mode, 7453 (void *)&cmd_set_vf_rxmode_on, 7454 NULL, 7455 }, 7456 }; 7457 7458 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 7459 struct cmd_vf_mac_addr_result { 7460 cmdline_fixed_string_t mac_addr_cmd; 7461 cmdline_fixed_string_t what; 7462 cmdline_fixed_string_t port; 7463 uint8_t port_num; 7464 cmdline_fixed_string_t vf; 7465 uint8_t vf_num; 7466 struct ether_addr address; 7467 }; 7468 7469 static void cmd_vf_mac_addr_parsed(void *parsed_result, 7470 __attribute__((unused)) struct cmdline *cl, 7471 __attribute__((unused)) void *data) 7472 { 7473 struct cmd_vf_mac_addr_result *res = parsed_result; 7474 int ret = -ENOTSUP; 7475 7476 if (strcmp(res->what, "add") != 0) 7477 return; 7478 7479 #ifdef RTE_LIBRTE_I40E_PMD 7480 if (ret == -ENOTSUP) 7481 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num, 7482 &res->address); 7483 #endif 7484 #ifdef RTE_LIBRTE_BNXT_PMD 7485 if (ret == -ENOTSUP) 7486 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address, 7487 res->vf_num); 7488 #endif 7489 7490 if(ret < 0) 7491 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 7492 7493 } 7494 7495 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 7496 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7497 mac_addr_cmd,"mac_addr"); 7498 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 7499 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7500 what,"add"); 7501 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 7502 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7503 port,"port"); 7504 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 7505 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7506 port_num, UINT8); 7507 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 7508 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7509 vf,"vf"); 7510 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 7511 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7512 vf_num, UINT8); 7513 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 7514 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 7515 address); 7516 7517 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 7518 .f = cmd_vf_mac_addr_parsed, 7519 .data = (void *)0, 7520 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 7521 "Add MAC address filtering for a VF on port_id", 7522 .tokens = { 7523 (void *)&cmd_vf_mac_addr_cmd, 7524 (void *)&cmd_vf_mac_addr_what, 7525 (void *)&cmd_vf_mac_addr_port, 7526 (void *)&cmd_vf_mac_addr_portnum, 7527 (void *)&cmd_vf_mac_addr_vf, 7528 (void *)&cmd_vf_mac_addr_vfnum, 7529 (void *)&cmd_vf_mac_addr_addr, 7530 NULL, 7531 }, 7532 }; 7533 7534 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 7535 struct cmd_vf_rx_vlan_filter { 7536 cmdline_fixed_string_t rx_vlan; 7537 cmdline_fixed_string_t what; 7538 uint16_t vlan_id; 7539 cmdline_fixed_string_t port; 7540 uint8_t port_id; 7541 cmdline_fixed_string_t vf; 7542 uint64_t vf_mask; 7543 }; 7544 7545 static void 7546 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 7547 __attribute__((unused)) struct cmdline *cl, 7548 __attribute__((unused)) void *data) 7549 { 7550 struct cmd_vf_rx_vlan_filter *res = parsed_result; 7551 int ret = -ENOTSUP; 7552 7553 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 7554 7555 #ifdef RTE_LIBRTE_IXGBE_PMD 7556 if (ret == -ENOTSUP) 7557 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 7558 res->vlan_id, res->vf_mask, is_add); 7559 #endif 7560 #ifdef RTE_LIBRTE_I40E_PMD 7561 if (ret == -ENOTSUP) 7562 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 7563 res->vlan_id, res->vf_mask, is_add); 7564 #endif 7565 #ifdef RTE_LIBRTE_BNXT_PMD 7566 if (ret == -ENOTSUP) 7567 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id, 7568 res->vlan_id, res->vf_mask, is_add); 7569 #endif 7570 7571 switch (ret) { 7572 case 0: 7573 break; 7574 case -EINVAL: 7575 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n", 7576 res->vlan_id, res->vf_mask); 7577 break; 7578 case -ENODEV: 7579 printf("invalid port_id %d\n", res->port_id); 7580 break; 7581 case -ENOTSUP: 7582 printf("function not implemented or supported\n"); 7583 break; 7584 default: 7585 printf("programming error: (%s)\n", strerror(-ret)); 7586 } 7587 } 7588 7589 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 7590 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7591 rx_vlan, "rx_vlan"); 7592 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 7593 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7594 what, "add#rm"); 7595 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 7596 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7597 vlan_id, UINT16); 7598 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 7599 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7600 port, "port"); 7601 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 7602 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7603 port_id, UINT8); 7604 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 7605 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7606 vf, "vf"); 7607 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 7608 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7609 vf_mask, UINT64); 7610 7611 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 7612 .f = cmd_vf_rx_vlan_filter_parsed, 7613 .data = NULL, 7614 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 7615 "(vf_mask = hexadecimal VF mask)", 7616 .tokens = { 7617 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 7618 (void *)&cmd_vf_rx_vlan_filter_what, 7619 (void *)&cmd_vf_rx_vlan_filter_vlanid, 7620 (void *)&cmd_vf_rx_vlan_filter_port, 7621 (void *)&cmd_vf_rx_vlan_filter_portid, 7622 (void *)&cmd_vf_rx_vlan_filter_vf, 7623 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 7624 NULL, 7625 }, 7626 }; 7627 7628 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 7629 struct cmd_queue_rate_limit_result { 7630 cmdline_fixed_string_t set; 7631 cmdline_fixed_string_t port; 7632 uint8_t port_num; 7633 cmdline_fixed_string_t queue; 7634 uint8_t queue_num; 7635 cmdline_fixed_string_t rate; 7636 uint16_t rate_num; 7637 }; 7638 7639 static void cmd_queue_rate_limit_parsed(void *parsed_result, 7640 __attribute__((unused)) struct cmdline *cl, 7641 __attribute__((unused)) void *data) 7642 { 7643 struct cmd_queue_rate_limit_result *res = parsed_result; 7644 int ret = 0; 7645 7646 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7647 && (strcmp(res->queue, "queue") == 0) 7648 && (strcmp(res->rate, "rate") == 0)) 7649 ret = set_queue_rate_limit(res->port_num, res->queue_num, 7650 res->rate_num); 7651 if (ret < 0) 7652 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7653 7654 } 7655 7656 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 7657 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7658 set, "set"); 7659 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 7660 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7661 port, "port"); 7662 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 7663 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7664 port_num, UINT8); 7665 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 7666 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7667 queue, "queue"); 7668 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 7669 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7670 queue_num, UINT8); 7671 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 7672 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7673 rate, "rate"); 7674 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 7675 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7676 rate_num, UINT16); 7677 7678 cmdline_parse_inst_t cmd_queue_rate_limit = { 7679 .f = cmd_queue_rate_limit_parsed, 7680 .data = (void *)0, 7681 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 7682 "Set rate limit for a queue on port_id", 7683 .tokens = { 7684 (void *)&cmd_queue_rate_limit_set, 7685 (void *)&cmd_queue_rate_limit_port, 7686 (void *)&cmd_queue_rate_limit_portnum, 7687 (void *)&cmd_queue_rate_limit_queue, 7688 (void *)&cmd_queue_rate_limit_queuenum, 7689 (void *)&cmd_queue_rate_limit_rate, 7690 (void *)&cmd_queue_rate_limit_ratenum, 7691 NULL, 7692 }, 7693 }; 7694 7695 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 7696 struct cmd_vf_rate_limit_result { 7697 cmdline_fixed_string_t set; 7698 cmdline_fixed_string_t port; 7699 uint8_t port_num; 7700 cmdline_fixed_string_t vf; 7701 uint8_t vf_num; 7702 cmdline_fixed_string_t rate; 7703 uint16_t rate_num; 7704 cmdline_fixed_string_t q_msk; 7705 uint64_t q_msk_val; 7706 }; 7707 7708 static void cmd_vf_rate_limit_parsed(void *parsed_result, 7709 __attribute__((unused)) struct cmdline *cl, 7710 __attribute__((unused)) void *data) 7711 { 7712 struct cmd_vf_rate_limit_result *res = parsed_result; 7713 int ret = 0; 7714 7715 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7716 && (strcmp(res->vf, "vf") == 0) 7717 && (strcmp(res->rate, "rate") == 0) 7718 && (strcmp(res->q_msk, "queue_mask") == 0)) 7719 ret = set_vf_rate_limit(res->port_num, res->vf_num, 7720 res->rate_num, res->q_msk_val); 7721 if (ret < 0) 7722 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7723 7724 } 7725 7726 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 7727 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7728 set, "set"); 7729 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 7730 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7731 port, "port"); 7732 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 7733 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7734 port_num, UINT8); 7735 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 7736 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7737 vf, "vf"); 7738 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 7739 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7740 vf_num, UINT8); 7741 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 7742 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7743 rate, "rate"); 7744 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 7745 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7746 rate_num, UINT16); 7747 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 7748 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 7749 q_msk, "queue_mask"); 7750 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 7751 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 7752 q_msk_val, UINT64); 7753 7754 cmdline_parse_inst_t cmd_vf_rate_limit = { 7755 .f = cmd_vf_rate_limit_parsed, 7756 .data = (void *)0, 7757 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 7758 "queue_mask <queue_mask_value>: " 7759 "Set rate limit for queues of VF on port_id", 7760 .tokens = { 7761 (void *)&cmd_vf_rate_limit_set, 7762 (void *)&cmd_vf_rate_limit_port, 7763 (void *)&cmd_vf_rate_limit_portnum, 7764 (void *)&cmd_vf_rate_limit_vf, 7765 (void *)&cmd_vf_rate_limit_vfnum, 7766 (void *)&cmd_vf_rate_limit_rate, 7767 (void *)&cmd_vf_rate_limit_ratenum, 7768 (void *)&cmd_vf_rate_limit_q_msk, 7769 (void *)&cmd_vf_rate_limit_q_msk_val, 7770 NULL, 7771 }, 7772 }; 7773 7774 /* *** ADD TUNNEL FILTER OF A PORT *** */ 7775 struct cmd_tunnel_filter_result { 7776 cmdline_fixed_string_t cmd; 7777 cmdline_fixed_string_t what; 7778 uint8_t port_id; 7779 struct ether_addr outer_mac; 7780 struct ether_addr inner_mac; 7781 cmdline_ipaddr_t ip_value; 7782 uint16_t inner_vlan; 7783 cmdline_fixed_string_t tunnel_type; 7784 cmdline_fixed_string_t filter_type; 7785 uint32_t tenant_id; 7786 uint16_t queue_num; 7787 }; 7788 7789 static void 7790 cmd_tunnel_filter_parsed(void *parsed_result, 7791 __attribute__((unused)) struct cmdline *cl, 7792 __attribute__((unused)) void *data) 7793 { 7794 struct cmd_tunnel_filter_result *res = parsed_result; 7795 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 7796 int ret = 0; 7797 7798 memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf)); 7799 7800 ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac); 7801 ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac); 7802 tunnel_filter_conf.inner_vlan = res->inner_vlan; 7803 7804 if (res->ip_value.family == AF_INET) { 7805 tunnel_filter_conf.ip_addr.ipv4_addr = 7806 res->ip_value.addr.ipv4.s_addr; 7807 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 7808 } else { 7809 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 7810 &(res->ip_value.addr.ipv6), 7811 sizeof(struct in6_addr)); 7812 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 7813 } 7814 7815 if (!strcmp(res->filter_type, "imac-ivlan")) 7816 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 7817 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 7818 tunnel_filter_conf.filter_type = 7819 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 7820 else if (!strcmp(res->filter_type, "imac-tenid")) 7821 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 7822 else if (!strcmp(res->filter_type, "imac")) 7823 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 7824 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 7825 tunnel_filter_conf.filter_type = 7826 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 7827 else if (!strcmp(res->filter_type, "oip")) 7828 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP; 7829 else if (!strcmp(res->filter_type, "iip")) 7830 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP; 7831 else { 7832 printf("The filter type is not supported"); 7833 return; 7834 } 7835 7836 if (!strcmp(res->tunnel_type, "vxlan")) 7837 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 7838 else if (!strcmp(res->tunnel_type, "nvgre")) 7839 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 7840 else if (!strcmp(res->tunnel_type, "ipingre")) 7841 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE; 7842 else { 7843 printf("The tunnel type %s not supported.\n", res->tunnel_type); 7844 return; 7845 } 7846 7847 tunnel_filter_conf.tenant_id = res->tenant_id; 7848 tunnel_filter_conf.queue_id = res->queue_num; 7849 if (!strcmp(res->what, "add")) 7850 ret = rte_eth_dev_filter_ctrl(res->port_id, 7851 RTE_ETH_FILTER_TUNNEL, 7852 RTE_ETH_FILTER_ADD, 7853 &tunnel_filter_conf); 7854 else 7855 ret = rte_eth_dev_filter_ctrl(res->port_id, 7856 RTE_ETH_FILTER_TUNNEL, 7857 RTE_ETH_FILTER_DELETE, 7858 &tunnel_filter_conf); 7859 if (ret < 0) 7860 printf("cmd_tunnel_filter_parsed error: (%s)\n", 7861 strerror(-ret)); 7862 7863 } 7864 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 7865 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7866 cmd, "tunnel_filter"); 7867 cmdline_parse_token_string_t cmd_tunnel_filter_what = 7868 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7869 what, "add#rm"); 7870 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 7871 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7872 port_id, UINT8); 7873 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 7874 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7875 outer_mac); 7876 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 7877 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7878 inner_mac); 7879 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 7880 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7881 inner_vlan, UINT16); 7882 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 7883 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 7884 ip_value); 7885 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 7886 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7887 tunnel_type, "vxlan#nvgre#ipingre"); 7888 7889 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 7890 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 7891 filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#" 7892 "imac#omac-imac-tenid"); 7893 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 7894 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7895 tenant_id, UINT32); 7896 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 7897 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 7898 queue_num, UINT16); 7899 7900 cmdline_parse_inst_t cmd_tunnel_filter = { 7901 .f = cmd_tunnel_filter_parsed, 7902 .data = (void *)0, 7903 .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> " 7904 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|" 7905 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> " 7906 "<queue_id>: Add/Rm tunnel filter of a port", 7907 .tokens = { 7908 (void *)&cmd_tunnel_filter_cmd, 7909 (void *)&cmd_tunnel_filter_what, 7910 (void *)&cmd_tunnel_filter_port_id, 7911 (void *)&cmd_tunnel_filter_outer_mac, 7912 (void *)&cmd_tunnel_filter_inner_mac, 7913 (void *)&cmd_tunnel_filter_ip_value, 7914 (void *)&cmd_tunnel_filter_innner_vlan, 7915 (void *)&cmd_tunnel_filter_tunnel_type, 7916 (void *)&cmd_tunnel_filter_filter_type, 7917 (void *)&cmd_tunnel_filter_tenant_id, 7918 (void *)&cmd_tunnel_filter_queue_num, 7919 NULL, 7920 }, 7921 }; 7922 7923 /* *** CONFIGURE TUNNEL UDP PORT *** */ 7924 struct cmd_tunnel_udp_config { 7925 cmdline_fixed_string_t cmd; 7926 cmdline_fixed_string_t what; 7927 uint16_t udp_port; 7928 uint8_t port_id; 7929 }; 7930 7931 static void 7932 cmd_tunnel_udp_config_parsed(void *parsed_result, 7933 __attribute__((unused)) struct cmdline *cl, 7934 __attribute__((unused)) void *data) 7935 { 7936 struct cmd_tunnel_udp_config *res = parsed_result; 7937 struct rte_eth_udp_tunnel tunnel_udp; 7938 int ret; 7939 7940 tunnel_udp.udp_port = res->udp_port; 7941 7942 if (!strcmp(res->cmd, "rx_vxlan_port")) 7943 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 7944 7945 if (!strcmp(res->what, "add")) 7946 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 7947 &tunnel_udp); 7948 else 7949 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 7950 &tunnel_udp); 7951 7952 if (ret < 0) 7953 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 7954 } 7955 7956 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 7957 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7958 cmd, "rx_vxlan_port"); 7959 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 7960 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 7961 what, "add#rm"); 7962 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 7963 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7964 udp_port, UINT16); 7965 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 7966 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 7967 port_id, UINT8); 7968 7969 cmdline_parse_inst_t cmd_tunnel_udp_config = { 7970 .f = cmd_tunnel_udp_config_parsed, 7971 .data = (void *)0, 7972 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 7973 "Add/Remove a tunneling UDP port filter", 7974 .tokens = { 7975 (void *)&cmd_tunnel_udp_config_cmd, 7976 (void *)&cmd_tunnel_udp_config_what, 7977 (void *)&cmd_tunnel_udp_config_udp_port, 7978 (void *)&cmd_tunnel_udp_config_port_id, 7979 NULL, 7980 }, 7981 }; 7982 7983 /* *** GLOBAL CONFIG *** */ 7984 struct cmd_global_config_result { 7985 cmdline_fixed_string_t cmd; 7986 uint8_t port_id; 7987 cmdline_fixed_string_t cfg_type; 7988 uint8_t len; 7989 }; 7990 7991 static void 7992 cmd_global_config_parsed(void *parsed_result, 7993 __attribute__((unused)) struct cmdline *cl, 7994 __attribute__((unused)) void *data) 7995 { 7996 struct cmd_global_config_result *res = parsed_result; 7997 struct rte_eth_global_cfg conf; 7998 int ret; 7999 8000 memset(&conf, 0, sizeof(conf)); 8001 conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN; 8002 conf.cfg.gre_key_len = res->len; 8003 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE, 8004 RTE_ETH_FILTER_SET, &conf); 8005 if (ret != 0) 8006 printf("Global config error\n"); 8007 } 8008 8009 cmdline_parse_token_string_t cmd_global_config_cmd = 8010 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, 8011 "global_config"); 8012 cmdline_parse_token_num_t cmd_global_config_port_id = 8013 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8); 8014 cmdline_parse_token_string_t cmd_global_config_type = 8015 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, 8016 cfg_type, "gre-key-len"); 8017 cmdline_parse_token_num_t cmd_global_config_gre_key_len = 8018 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, 8019 len, UINT8); 8020 8021 cmdline_parse_inst_t cmd_global_config = { 8022 .f = cmd_global_config_parsed, 8023 .data = (void *)NULL, 8024 .help_str = "global_config <port_id> gre-key-len <key_len>", 8025 .tokens = { 8026 (void *)&cmd_global_config_cmd, 8027 (void *)&cmd_global_config_port_id, 8028 (void *)&cmd_global_config_type, 8029 (void *)&cmd_global_config_gre_key_len, 8030 NULL, 8031 }, 8032 }; 8033 8034 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 8035 struct cmd_set_mirror_mask_result { 8036 cmdline_fixed_string_t set; 8037 cmdline_fixed_string_t port; 8038 uint8_t port_id; 8039 cmdline_fixed_string_t mirror; 8040 uint8_t rule_id; 8041 cmdline_fixed_string_t what; 8042 cmdline_fixed_string_t value; 8043 cmdline_fixed_string_t dstpool; 8044 uint8_t dstpool_id; 8045 cmdline_fixed_string_t on; 8046 }; 8047 8048 cmdline_parse_token_string_t cmd_mirror_mask_set = 8049 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8050 set, "set"); 8051 cmdline_parse_token_string_t cmd_mirror_mask_port = 8052 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8053 port, "port"); 8054 cmdline_parse_token_num_t cmd_mirror_mask_portid = 8055 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8056 port_id, UINT8); 8057 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 8058 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8059 mirror, "mirror-rule"); 8060 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 8061 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8062 rule_id, UINT8); 8063 cmdline_parse_token_string_t cmd_mirror_mask_what = 8064 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8065 what, "pool-mirror-up#pool-mirror-down" 8066 "#vlan-mirror"); 8067 cmdline_parse_token_string_t cmd_mirror_mask_value = 8068 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8069 value, NULL); 8070 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 8071 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8072 dstpool, "dst-pool"); 8073 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 8074 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8075 dstpool_id, UINT8); 8076 cmdline_parse_token_string_t cmd_mirror_mask_on = 8077 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8078 on, "on#off"); 8079 8080 static void 8081 cmd_set_mirror_mask_parsed(void *parsed_result, 8082 __attribute__((unused)) struct cmdline *cl, 8083 __attribute__((unused)) void *data) 8084 { 8085 int ret,nb_item,i; 8086 struct cmd_set_mirror_mask_result *res = parsed_result; 8087 struct rte_eth_mirror_conf mr_conf; 8088 8089 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 8090 8091 unsigned int vlan_list[ETH_MIRROR_MAX_VLANS]; 8092 8093 mr_conf.dst_pool = res->dstpool_id; 8094 8095 if (!strcmp(res->what, "pool-mirror-up")) { 8096 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 8097 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP; 8098 } else if (!strcmp(res->what, "pool-mirror-down")) { 8099 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 8100 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN; 8101 } else if (!strcmp(res->what, "vlan-mirror")) { 8102 mr_conf.rule_type = ETH_MIRROR_VLAN; 8103 nb_item = parse_item_list(res->value, "vlan", 8104 ETH_MIRROR_MAX_VLANS, vlan_list, 1); 8105 if (nb_item <= 0) 8106 return; 8107 8108 for (i = 0; i < nb_item; i++) { 8109 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 8110 printf("Invalid vlan_id: must be < 4096\n"); 8111 return; 8112 } 8113 8114 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 8115 mr_conf.vlan.vlan_mask |= 1ULL << i; 8116 } 8117 } 8118 8119 if (!strcmp(res->on, "on")) 8120 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8121 res->rule_id, 1); 8122 else 8123 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8124 res->rule_id, 0); 8125 if (ret < 0) 8126 printf("mirror rule add error: (%s)\n", strerror(-ret)); 8127 } 8128 8129 cmdline_parse_inst_t cmd_set_mirror_mask = { 8130 .f = cmd_set_mirror_mask_parsed, 8131 .data = NULL, 8132 .help_str = "set port <port_id> mirror-rule <rule_id> " 8133 "pool-mirror-up|pool-mirror-down|vlan-mirror " 8134 "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off", 8135 .tokens = { 8136 (void *)&cmd_mirror_mask_set, 8137 (void *)&cmd_mirror_mask_port, 8138 (void *)&cmd_mirror_mask_portid, 8139 (void *)&cmd_mirror_mask_mirror, 8140 (void *)&cmd_mirror_mask_ruleid, 8141 (void *)&cmd_mirror_mask_what, 8142 (void *)&cmd_mirror_mask_value, 8143 (void *)&cmd_mirror_mask_dstpool, 8144 (void *)&cmd_mirror_mask_poolid, 8145 (void *)&cmd_mirror_mask_on, 8146 NULL, 8147 }, 8148 }; 8149 8150 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */ 8151 struct cmd_set_mirror_link_result { 8152 cmdline_fixed_string_t set; 8153 cmdline_fixed_string_t port; 8154 uint8_t port_id; 8155 cmdline_fixed_string_t mirror; 8156 uint8_t rule_id; 8157 cmdline_fixed_string_t what; 8158 cmdline_fixed_string_t dstpool; 8159 uint8_t dstpool_id; 8160 cmdline_fixed_string_t on; 8161 }; 8162 8163 cmdline_parse_token_string_t cmd_mirror_link_set = 8164 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8165 set, "set"); 8166 cmdline_parse_token_string_t cmd_mirror_link_port = 8167 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8168 port, "port"); 8169 cmdline_parse_token_num_t cmd_mirror_link_portid = 8170 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8171 port_id, UINT8); 8172 cmdline_parse_token_string_t cmd_mirror_link_mirror = 8173 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8174 mirror, "mirror-rule"); 8175 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 8176 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8177 rule_id, UINT8); 8178 cmdline_parse_token_string_t cmd_mirror_link_what = 8179 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8180 what, "uplink-mirror#downlink-mirror"); 8181 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 8182 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8183 dstpool, "dst-pool"); 8184 cmdline_parse_token_num_t cmd_mirror_link_poolid = 8185 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8186 dstpool_id, UINT8); 8187 cmdline_parse_token_string_t cmd_mirror_link_on = 8188 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8189 on, "on#off"); 8190 8191 static void 8192 cmd_set_mirror_link_parsed(void *parsed_result, 8193 __attribute__((unused)) struct cmdline *cl, 8194 __attribute__((unused)) void *data) 8195 { 8196 int ret; 8197 struct cmd_set_mirror_link_result *res = parsed_result; 8198 struct rte_eth_mirror_conf mr_conf; 8199 8200 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 8201 if (!strcmp(res->what, "uplink-mirror")) 8202 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT; 8203 else 8204 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT; 8205 8206 mr_conf.dst_pool = res->dstpool_id; 8207 8208 if (!strcmp(res->on, "on")) 8209 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8210 res->rule_id, 1); 8211 else 8212 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8213 res->rule_id, 0); 8214 8215 /* check the return value and print it if is < 0 */ 8216 if (ret < 0) 8217 printf("mirror rule add error: (%s)\n", strerror(-ret)); 8218 8219 } 8220 8221 cmdline_parse_inst_t cmd_set_mirror_link = { 8222 .f = cmd_set_mirror_link_parsed, 8223 .data = NULL, 8224 .help_str = "set port <port_id> mirror-rule <rule_id> " 8225 "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off", 8226 .tokens = { 8227 (void *)&cmd_mirror_link_set, 8228 (void *)&cmd_mirror_link_port, 8229 (void *)&cmd_mirror_link_portid, 8230 (void *)&cmd_mirror_link_mirror, 8231 (void *)&cmd_mirror_link_ruleid, 8232 (void *)&cmd_mirror_link_what, 8233 (void *)&cmd_mirror_link_dstpool, 8234 (void *)&cmd_mirror_link_poolid, 8235 (void *)&cmd_mirror_link_on, 8236 NULL, 8237 }, 8238 }; 8239 8240 /* *** RESET VM MIRROR RULE *** */ 8241 struct cmd_rm_mirror_rule_result { 8242 cmdline_fixed_string_t reset; 8243 cmdline_fixed_string_t port; 8244 uint8_t port_id; 8245 cmdline_fixed_string_t mirror; 8246 uint8_t rule_id; 8247 }; 8248 8249 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 8250 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8251 reset, "reset"); 8252 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 8253 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8254 port, "port"); 8255 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 8256 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 8257 port_id, UINT8); 8258 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 8259 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8260 mirror, "mirror-rule"); 8261 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 8262 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 8263 rule_id, UINT8); 8264 8265 static void 8266 cmd_reset_mirror_rule_parsed(void *parsed_result, 8267 __attribute__((unused)) struct cmdline *cl, 8268 __attribute__((unused)) void *data) 8269 { 8270 int ret; 8271 struct cmd_set_mirror_link_result *res = parsed_result; 8272 /* check rule_id */ 8273 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 8274 if(ret < 0) 8275 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 8276 } 8277 8278 cmdline_parse_inst_t cmd_reset_mirror_rule = { 8279 .f = cmd_reset_mirror_rule_parsed, 8280 .data = NULL, 8281 .help_str = "reset port <port_id> mirror-rule <rule_id>", 8282 .tokens = { 8283 (void *)&cmd_rm_mirror_rule_reset, 8284 (void *)&cmd_rm_mirror_rule_port, 8285 (void *)&cmd_rm_mirror_rule_portid, 8286 (void *)&cmd_rm_mirror_rule_mirror, 8287 (void *)&cmd_rm_mirror_rule_ruleid, 8288 NULL, 8289 }, 8290 }; 8291 8292 /* ******************************************************************************** */ 8293 8294 struct cmd_dump_result { 8295 cmdline_fixed_string_t dump; 8296 }; 8297 8298 static void 8299 dump_struct_sizes(void) 8300 { 8301 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 8302 DUMP_SIZE(struct rte_mbuf); 8303 DUMP_SIZE(struct rte_mempool); 8304 DUMP_SIZE(struct rte_ring); 8305 #undef DUMP_SIZE 8306 } 8307 8308 static void cmd_dump_parsed(void *parsed_result, 8309 __attribute__((unused)) struct cmdline *cl, 8310 __attribute__((unused)) void *data) 8311 { 8312 struct cmd_dump_result *res = parsed_result; 8313 8314 if (!strcmp(res->dump, "dump_physmem")) 8315 rte_dump_physmem_layout(stdout); 8316 else if (!strcmp(res->dump, "dump_memzone")) 8317 rte_memzone_dump(stdout); 8318 else if (!strcmp(res->dump, "dump_struct_sizes")) 8319 dump_struct_sizes(); 8320 else if (!strcmp(res->dump, "dump_ring")) 8321 rte_ring_list_dump(stdout); 8322 else if (!strcmp(res->dump, "dump_mempool")) 8323 rte_mempool_list_dump(stdout); 8324 else if (!strcmp(res->dump, "dump_devargs")) 8325 rte_eal_devargs_dump(stdout); 8326 else if (!strcmp(res->dump, "dump_log_types")) 8327 rte_log_dump(stdout); 8328 } 8329 8330 cmdline_parse_token_string_t cmd_dump_dump = 8331 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 8332 "dump_physmem#" 8333 "dump_memzone#" 8334 "dump_struct_sizes#" 8335 "dump_ring#" 8336 "dump_mempool#" 8337 "dump_devargs#" 8338 "dump_log_types"); 8339 8340 cmdline_parse_inst_t cmd_dump = { 8341 .f = cmd_dump_parsed, /* function to call */ 8342 .data = NULL, /* 2nd arg of func */ 8343 .help_str = "Dump status", 8344 .tokens = { /* token list, NULL terminated */ 8345 (void *)&cmd_dump_dump, 8346 NULL, 8347 }, 8348 }; 8349 8350 /* ******************************************************************************** */ 8351 8352 struct cmd_dump_one_result { 8353 cmdline_fixed_string_t dump; 8354 cmdline_fixed_string_t name; 8355 }; 8356 8357 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 8358 __attribute__((unused)) void *data) 8359 { 8360 struct cmd_dump_one_result *res = parsed_result; 8361 8362 if (!strcmp(res->dump, "dump_ring")) { 8363 struct rte_ring *r; 8364 r = rte_ring_lookup(res->name); 8365 if (r == NULL) { 8366 cmdline_printf(cl, "Cannot find ring\n"); 8367 return; 8368 } 8369 rte_ring_dump(stdout, r); 8370 } else if (!strcmp(res->dump, "dump_mempool")) { 8371 struct rte_mempool *mp; 8372 mp = rte_mempool_lookup(res->name); 8373 if (mp == NULL) { 8374 cmdline_printf(cl, "Cannot find mempool\n"); 8375 return; 8376 } 8377 rte_mempool_dump(stdout, mp); 8378 } 8379 } 8380 8381 cmdline_parse_token_string_t cmd_dump_one_dump = 8382 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 8383 "dump_ring#dump_mempool"); 8384 8385 cmdline_parse_token_string_t cmd_dump_one_name = 8386 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 8387 8388 cmdline_parse_inst_t cmd_dump_one = { 8389 .f = cmd_dump_one_parsed, /* function to call */ 8390 .data = NULL, /* 2nd arg of func */ 8391 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 8392 .tokens = { /* token list, NULL terminated */ 8393 (void *)&cmd_dump_one_dump, 8394 (void *)&cmd_dump_one_name, 8395 NULL, 8396 }, 8397 }; 8398 8399 /* *** Add/Del syn filter *** */ 8400 struct cmd_syn_filter_result { 8401 cmdline_fixed_string_t filter; 8402 uint8_t port_id; 8403 cmdline_fixed_string_t ops; 8404 cmdline_fixed_string_t priority; 8405 cmdline_fixed_string_t high; 8406 cmdline_fixed_string_t queue; 8407 uint16_t queue_id; 8408 }; 8409 8410 static void 8411 cmd_syn_filter_parsed(void *parsed_result, 8412 __attribute__((unused)) struct cmdline *cl, 8413 __attribute__((unused)) void *data) 8414 { 8415 struct cmd_syn_filter_result *res = parsed_result; 8416 struct rte_eth_syn_filter syn_filter; 8417 int ret = 0; 8418 8419 ret = rte_eth_dev_filter_supported(res->port_id, 8420 RTE_ETH_FILTER_SYN); 8421 if (ret < 0) { 8422 printf("syn filter is not supported on port %u.\n", 8423 res->port_id); 8424 return; 8425 } 8426 8427 memset(&syn_filter, 0, sizeof(syn_filter)); 8428 8429 if (!strcmp(res->ops, "add")) { 8430 if (!strcmp(res->high, "high")) 8431 syn_filter.hig_pri = 1; 8432 else 8433 syn_filter.hig_pri = 0; 8434 8435 syn_filter.queue = res->queue_id; 8436 ret = rte_eth_dev_filter_ctrl(res->port_id, 8437 RTE_ETH_FILTER_SYN, 8438 RTE_ETH_FILTER_ADD, 8439 &syn_filter); 8440 } else 8441 ret = rte_eth_dev_filter_ctrl(res->port_id, 8442 RTE_ETH_FILTER_SYN, 8443 RTE_ETH_FILTER_DELETE, 8444 &syn_filter); 8445 8446 if (ret < 0) 8447 printf("syn filter programming error: (%s)\n", 8448 strerror(-ret)); 8449 } 8450 8451 cmdline_parse_token_string_t cmd_syn_filter_filter = 8452 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8453 filter, "syn_filter"); 8454 cmdline_parse_token_num_t cmd_syn_filter_port_id = 8455 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8456 port_id, UINT8); 8457 cmdline_parse_token_string_t cmd_syn_filter_ops = 8458 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8459 ops, "add#del"); 8460 cmdline_parse_token_string_t cmd_syn_filter_priority = 8461 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8462 priority, "priority"); 8463 cmdline_parse_token_string_t cmd_syn_filter_high = 8464 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8465 high, "high#low"); 8466 cmdline_parse_token_string_t cmd_syn_filter_queue = 8467 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8468 queue, "queue"); 8469 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 8470 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8471 queue_id, UINT16); 8472 8473 cmdline_parse_inst_t cmd_syn_filter = { 8474 .f = cmd_syn_filter_parsed, 8475 .data = NULL, 8476 .help_str = "syn_filter <port_id> add|del priority high|low queue " 8477 "<queue_id>: Add/Delete syn filter", 8478 .tokens = { 8479 (void *)&cmd_syn_filter_filter, 8480 (void *)&cmd_syn_filter_port_id, 8481 (void *)&cmd_syn_filter_ops, 8482 (void *)&cmd_syn_filter_priority, 8483 (void *)&cmd_syn_filter_high, 8484 (void *)&cmd_syn_filter_queue, 8485 (void *)&cmd_syn_filter_queue_id, 8486 NULL, 8487 }, 8488 }; 8489 8490 /* *** queue region set *** */ 8491 struct cmd_queue_region_result { 8492 cmdline_fixed_string_t set; 8493 cmdline_fixed_string_t port; 8494 uint8_t port_id; 8495 cmdline_fixed_string_t cmd; 8496 cmdline_fixed_string_t region; 8497 uint8_t region_id; 8498 cmdline_fixed_string_t queue_start_index; 8499 uint8_t queue_id; 8500 cmdline_fixed_string_t queue_num; 8501 uint8_t queue_num_value; 8502 }; 8503 8504 static void 8505 cmd_queue_region_parsed(void *parsed_result, 8506 __attribute__((unused)) struct cmdline *cl, 8507 __attribute__((unused)) void *data) 8508 { 8509 struct cmd_queue_region_result *res = parsed_result; 8510 int ret = -ENOTSUP; 8511 #ifdef RTE_LIBRTE_I40E_PMD 8512 struct rte_pmd_i40e_queue_region_conf region_conf; 8513 enum rte_pmd_i40e_queue_region_op op_type; 8514 #endif 8515 8516 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8517 return; 8518 8519 #ifdef RTE_LIBRTE_I40E_PMD 8520 memset(®ion_conf, 0, sizeof(region_conf)); 8521 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET; 8522 region_conf.region_id = res->region_id; 8523 region_conf.queue_num = res->queue_num_value; 8524 region_conf.queue_start_index = res->queue_id; 8525 8526 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8527 op_type, ®ion_conf); 8528 #endif 8529 8530 switch (ret) { 8531 case 0: 8532 break; 8533 case -ENOTSUP: 8534 printf("function not implemented or supported\n"); 8535 break; 8536 default: 8537 printf("queue region config error: (%s)\n", strerror(-ret)); 8538 } 8539 } 8540 8541 cmdline_parse_token_string_t cmd_queue_region_set = 8542 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8543 set, "set"); 8544 cmdline_parse_token_string_t cmd_queue_region_port = 8545 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port"); 8546 cmdline_parse_token_num_t cmd_queue_region_port_id = 8547 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8548 port_id, UINT8); 8549 cmdline_parse_token_string_t cmd_queue_region_cmd = 8550 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8551 cmd, "queue-region"); 8552 cmdline_parse_token_string_t cmd_queue_region_id = 8553 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8554 region, "region_id"); 8555 cmdline_parse_token_num_t cmd_queue_region_index = 8556 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8557 region_id, UINT8); 8558 cmdline_parse_token_string_t cmd_queue_region_queue_start_index = 8559 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8560 queue_start_index, "queue_start_index"); 8561 cmdline_parse_token_num_t cmd_queue_region_queue_id = 8562 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8563 queue_id, UINT8); 8564 cmdline_parse_token_string_t cmd_queue_region_queue_num = 8565 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8566 queue_num, "queue_num"); 8567 cmdline_parse_token_num_t cmd_queue_region_queue_num_value = 8568 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8569 queue_num_value, UINT8); 8570 8571 cmdline_parse_inst_t cmd_queue_region = { 8572 .f = cmd_queue_region_parsed, 8573 .data = NULL, 8574 .help_str = "set port <port_id> queue-region region_id <value> " 8575 "queue_start_index <value> queue_num <value>: Set a queue region", 8576 .tokens = { 8577 (void *)&cmd_queue_region_set, 8578 (void *)&cmd_queue_region_port, 8579 (void *)&cmd_queue_region_port_id, 8580 (void *)&cmd_queue_region_cmd, 8581 (void *)&cmd_queue_region_id, 8582 (void *)&cmd_queue_region_index, 8583 (void *)&cmd_queue_region_queue_start_index, 8584 (void *)&cmd_queue_region_queue_id, 8585 (void *)&cmd_queue_region_queue_num, 8586 (void *)&cmd_queue_region_queue_num_value, 8587 NULL, 8588 }, 8589 }; 8590 8591 /* *** queue region and flowtype set *** */ 8592 struct cmd_region_flowtype_result { 8593 cmdline_fixed_string_t set; 8594 cmdline_fixed_string_t port; 8595 uint8_t port_id; 8596 cmdline_fixed_string_t cmd; 8597 cmdline_fixed_string_t region; 8598 uint8_t region_id; 8599 cmdline_fixed_string_t flowtype; 8600 uint8_t flowtype_id; 8601 }; 8602 8603 static void 8604 cmd_region_flowtype_parsed(void *parsed_result, 8605 __attribute__((unused)) struct cmdline *cl, 8606 __attribute__((unused)) void *data) 8607 { 8608 struct cmd_region_flowtype_result *res = parsed_result; 8609 int ret = -ENOTSUP; 8610 #ifdef RTE_LIBRTE_I40E_PMD 8611 struct rte_pmd_i40e_queue_region_conf region_conf; 8612 enum rte_pmd_i40e_queue_region_op op_type; 8613 #endif 8614 8615 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8616 return; 8617 8618 #ifdef RTE_LIBRTE_I40E_PMD 8619 memset(®ion_conf, 0, sizeof(region_conf)); 8620 8621 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET; 8622 region_conf.region_id = res->region_id; 8623 region_conf.hw_flowtype = res->flowtype_id; 8624 8625 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8626 op_type, ®ion_conf); 8627 #endif 8628 8629 switch (ret) { 8630 case 0: 8631 break; 8632 case -ENOTSUP: 8633 printf("function not implemented or supported\n"); 8634 break; 8635 default: 8636 printf("region flowtype config error: (%s)\n", strerror(-ret)); 8637 } 8638 } 8639 8640 cmdline_parse_token_string_t cmd_region_flowtype_set = 8641 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8642 set, "set"); 8643 cmdline_parse_token_string_t cmd_region_flowtype_port = 8644 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8645 port, "port"); 8646 cmdline_parse_token_num_t cmd_region_flowtype_port_index = 8647 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8648 port_id, UINT8); 8649 cmdline_parse_token_string_t cmd_region_flowtype_cmd = 8650 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8651 cmd, "queue-region"); 8652 cmdline_parse_token_string_t cmd_region_flowtype_index = 8653 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8654 region, "region_id"); 8655 cmdline_parse_token_num_t cmd_region_flowtype_id = 8656 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8657 region_id, UINT8); 8658 cmdline_parse_token_string_t cmd_region_flowtype_flow_index = 8659 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8660 flowtype, "flowtype"); 8661 cmdline_parse_token_num_t cmd_region_flowtype_flow_id = 8662 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8663 flowtype_id, UINT8); 8664 cmdline_parse_inst_t cmd_region_flowtype = { 8665 .f = cmd_region_flowtype_parsed, 8666 .data = NULL, 8667 .help_str = "set port <port_id> queue-region region_id <value> " 8668 "flowtype <value>: Set a flowtype region index", 8669 .tokens = { 8670 (void *)&cmd_region_flowtype_set, 8671 (void *)&cmd_region_flowtype_port, 8672 (void *)&cmd_region_flowtype_port_index, 8673 (void *)&cmd_region_flowtype_cmd, 8674 (void *)&cmd_region_flowtype_index, 8675 (void *)&cmd_region_flowtype_id, 8676 (void *)&cmd_region_flowtype_flow_index, 8677 (void *)&cmd_region_flowtype_flow_id, 8678 NULL, 8679 }, 8680 }; 8681 8682 /* *** User Priority (UP) to queue region (region_id) set *** */ 8683 struct cmd_user_priority_region_result { 8684 cmdline_fixed_string_t set; 8685 cmdline_fixed_string_t port; 8686 uint8_t port_id; 8687 cmdline_fixed_string_t cmd; 8688 cmdline_fixed_string_t user_priority; 8689 uint8_t user_priority_id; 8690 cmdline_fixed_string_t region; 8691 uint8_t region_id; 8692 }; 8693 8694 static void 8695 cmd_user_priority_region_parsed(void *parsed_result, 8696 __attribute__((unused)) struct cmdline *cl, 8697 __attribute__((unused)) void *data) 8698 { 8699 struct cmd_user_priority_region_result *res = parsed_result; 8700 int ret = -ENOTSUP; 8701 #ifdef RTE_LIBRTE_I40E_PMD 8702 struct rte_pmd_i40e_queue_region_conf region_conf; 8703 enum rte_pmd_i40e_queue_region_op op_type; 8704 #endif 8705 8706 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8707 return; 8708 8709 #ifdef RTE_LIBRTE_I40E_PMD 8710 memset(®ion_conf, 0, sizeof(region_conf)); 8711 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET; 8712 region_conf.user_priority = res->user_priority_id; 8713 region_conf.region_id = res->region_id; 8714 8715 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8716 op_type, ®ion_conf); 8717 #endif 8718 8719 switch (ret) { 8720 case 0: 8721 break; 8722 case -ENOTSUP: 8723 printf("function not implemented or supported\n"); 8724 break; 8725 default: 8726 printf("user_priority region config error: (%s)\n", 8727 strerror(-ret)); 8728 } 8729 } 8730 8731 cmdline_parse_token_string_t cmd_user_priority_region_set = 8732 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 8733 set, "set"); 8734 cmdline_parse_token_string_t cmd_user_priority_region_port = 8735 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 8736 port, "port"); 8737 cmdline_parse_token_num_t cmd_user_priority_region_port_index = 8738 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 8739 port_id, UINT8); 8740 cmdline_parse_token_string_t cmd_user_priority_region_cmd = 8741 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 8742 cmd, "queue-region"); 8743 cmdline_parse_token_string_t cmd_user_priority_region_UP = 8744 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 8745 user_priority, "UP"); 8746 cmdline_parse_token_num_t cmd_user_priority_region_UP_id = 8747 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 8748 user_priority_id, UINT8); 8749 cmdline_parse_token_string_t cmd_user_priority_region_region = 8750 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 8751 region, "region_id"); 8752 cmdline_parse_token_num_t cmd_user_priority_region_region_id = 8753 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 8754 region_id, UINT8); 8755 8756 cmdline_parse_inst_t cmd_user_priority_region = { 8757 .f = cmd_user_priority_region_parsed, 8758 .data = NULL, 8759 .help_str = "set port <port_id> queue-region UP <value> " 8760 "region_id <value>: Set the mapping of User Priority (UP) " 8761 "to queue region (region_id) ", 8762 .tokens = { 8763 (void *)&cmd_user_priority_region_set, 8764 (void *)&cmd_user_priority_region_port, 8765 (void *)&cmd_user_priority_region_port_index, 8766 (void *)&cmd_user_priority_region_cmd, 8767 (void *)&cmd_user_priority_region_UP, 8768 (void *)&cmd_user_priority_region_UP_id, 8769 (void *)&cmd_user_priority_region_region, 8770 (void *)&cmd_user_priority_region_region_id, 8771 NULL, 8772 }, 8773 }; 8774 8775 /* *** flush all queue region related configuration *** */ 8776 struct cmd_flush_queue_region_result { 8777 cmdline_fixed_string_t set; 8778 cmdline_fixed_string_t port; 8779 uint8_t port_id; 8780 cmdline_fixed_string_t cmd; 8781 cmdline_fixed_string_t flush; 8782 cmdline_fixed_string_t what; 8783 }; 8784 8785 static void 8786 cmd_flush_queue_region_parsed(void *parsed_result, 8787 __attribute__((unused)) struct cmdline *cl, 8788 __attribute__((unused)) void *data) 8789 { 8790 struct cmd_flush_queue_region_result *res = parsed_result; 8791 int ret = -ENOTSUP; 8792 #ifdef RTE_LIBRTE_I40E_PMD 8793 struct rte_pmd_i40e_queue_region_conf region_conf; 8794 enum rte_pmd_i40e_queue_region_op op_type; 8795 #endif 8796 8797 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8798 return; 8799 8800 #ifdef RTE_LIBRTE_I40E_PMD 8801 memset(®ion_conf, 0, sizeof(region_conf)); 8802 8803 if (strcmp(res->what, "on") == 0) 8804 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON; 8805 else 8806 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF; 8807 8808 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8809 op_type, ®ion_conf); 8810 #endif 8811 8812 switch (ret) { 8813 case 0: 8814 break; 8815 case -ENOTSUP: 8816 printf("function not implemented or supported\n"); 8817 break; 8818 default: 8819 printf("queue region config flush error: (%s)\n", 8820 strerror(-ret)); 8821 } 8822 } 8823 8824 cmdline_parse_token_string_t cmd_flush_queue_region_set = 8825 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 8826 set, "set"); 8827 cmdline_parse_token_string_t cmd_flush_queue_region_port = 8828 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 8829 port, "port"); 8830 cmdline_parse_token_num_t cmd_flush_queue_region_port_index = 8831 TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result, 8832 port_id, UINT8); 8833 cmdline_parse_token_string_t cmd_flush_queue_region_cmd = 8834 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 8835 cmd, "queue-region"); 8836 cmdline_parse_token_string_t cmd_flush_queue_region_flush = 8837 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 8838 flush, "flush"); 8839 cmdline_parse_token_string_t cmd_flush_queue_region_what = 8840 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 8841 what, "on#off"); 8842 8843 cmdline_parse_inst_t cmd_flush_queue_region = { 8844 .f = cmd_flush_queue_region_parsed, 8845 .data = NULL, 8846 .help_str = "set port <port_id> queue-region flush on|off" 8847 ": flush all queue region related configuration", 8848 .tokens = { 8849 (void *)&cmd_flush_queue_region_set, 8850 (void *)&cmd_flush_queue_region_port, 8851 (void *)&cmd_flush_queue_region_port_index, 8852 (void *)&cmd_flush_queue_region_cmd, 8853 (void *)&cmd_flush_queue_region_flush, 8854 (void *)&cmd_flush_queue_region_what, 8855 NULL, 8856 }, 8857 }; 8858 8859 /* *** get all queue region related configuration info *** */ 8860 struct cmd_show_queue_region_info { 8861 cmdline_fixed_string_t show; 8862 cmdline_fixed_string_t port; 8863 uint8_t port_id; 8864 cmdline_fixed_string_t cmd; 8865 }; 8866 8867 static void 8868 cmd_show_queue_region_info_parsed(void *parsed_result, 8869 __attribute__((unused)) struct cmdline *cl, 8870 __attribute__((unused)) void *data) 8871 { 8872 struct cmd_show_queue_region_info *res = parsed_result; 8873 int ret = -ENOTSUP; 8874 #ifdef RTE_LIBRTE_I40E_PMD 8875 struct rte_pmd_i40e_queue_regions rte_pmd_regions; 8876 enum rte_pmd_i40e_queue_region_op op_type; 8877 #endif 8878 8879 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8880 return; 8881 8882 #ifdef RTE_LIBRTE_I40E_PMD 8883 memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions)); 8884 8885 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET; 8886 8887 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8888 op_type, &rte_pmd_regions); 8889 8890 port_queue_region_info_display(res->port_id, &rte_pmd_regions); 8891 #endif 8892 8893 switch (ret) { 8894 case 0: 8895 break; 8896 case -ENOTSUP: 8897 printf("function not implemented or supported\n"); 8898 break; 8899 default: 8900 printf("queue region config info show error: (%s)\n", 8901 strerror(-ret)); 8902 } 8903 } 8904 8905 cmdline_parse_token_string_t cmd_show_queue_region_info_get = 8906 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 8907 show, "show"); 8908 cmdline_parse_token_string_t cmd_show_queue_region_info_port = 8909 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 8910 port, "port"); 8911 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index = 8912 TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info, 8913 port_id, UINT8); 8914 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd = 8915 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 8916 cmd, "queue-region"); 8917 8918 cmdline_parse_inst_t cmd_show_queue_region_info_all = { 8919 .f = cmd_show_queue_region_info_parsed, 8920 .data = NULL, 8921 .help_str = "show port <port_id> queue-region" 8922 ": show all queue region related configuration info", 8923 .tokens = { 8924 (void *)&cmd_show_queue_region_info_get, 8925 (void *)&cmd_show_queue_region_info_port, 8926 (void *)&cmd_show_queue_region_info_port_index, 8927 (void *)&cmd_show_queue_region_info_cmd, 8928 NULL, 8929 }, 8930 }; 8931 8932 /* *** ADD/REMOVE A 2tuple FILTER *** */ 8933 struct cmd_2tuple_filter_result { 8934 cmdline_fixed_string_t filter; 8935 uint8_t port_id; 8936 cmdline_fixed_string_t ops; 8937 cmdline_fixed_string_t dst_port; 8938 uint16_t dst_port_value; 8939 cmdline_fixed_string_t protocol; 8940 uint8_t protocol_value; 8941 cmdline_fixed_string_t mask; 8942 uint8_t mask_value; 8943 cmdline_fixed_string_t tcp_flags; 8944 uint8_t tcp_flags_value; 8945 cmdline_fixed_string_t priority; 8946 uint8_t priority_value; 8947 cmdline_fixed_string_t queue; 8948 uint16_t queue_id; 8949 }; 8950 8951 static void 8952 cmd_2tuple_filter_parsed(void *parsed_result, 8953 __attribute__((unused)) struct cmdline *cl, 8954 __attribute__((unused)) void *data) 8955 { 8956 struct rte_eth_ntuple_filter filter; 8957 struct cmd_2tuple_filter_result *res = parsed_result; 8958 int ret = 0; 8959 8960 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 8961 if (ret < 0) { 8962 printf("ntuple filter is not supported on port %u.\n", 8963 res->port_id); 8964 return; 8965 } 8966 8967 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 8968 8969 filter.flags = RTE_2TUPLE_FLAGS; 8970 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 8971 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 8972 filter.proto = res->protocol_value; 8973 filter.priority = res->priority_value; 8974 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 8975 printf("nonzero tcp_flags is only meaningful" 8976 " when protocol is TCP.\n"); 8977 return; 8978 } 8979 if (res->tcp_flags_value > TCP_FLAG_ALL) { 8980 printf("invalid TCP flags.\n"); 8981 return; 8982 } 8983 8984 if (res->tcp_flags_value != 0) { 8985 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 8986 filter.tcp_flags = res->tcp_flags_value; 8987 } 8988 8989 /* need convert to big endian. */ 8990 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 8991 filter.queue = res->queue_id; 8992 8993 if (!strcmp(res->ops, "add")) 8994 ret = rte_eth_dev_filter_ctrl(res->port_id, 8995 RTE_ETH_FILTER_NTUPLE, 8996 RTE_ETH_FILTER_ADD, 8997 &filter); 8998 else 8999 ret = rte_eth_dev_filter_ctrl(res->port_id, 9000 RTE_ETH_FILTER_NTUPLE, 9001 RTE_ETH_FILTER_DELETE, 9002 &filter); 9003 if (ret < 0) 9004 printf("2tuple filter programming error: (%s)\n", 9005 strerror(-ret)); 9006 9007 } 9008 9009 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 9010 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9011 filter, "2tuple_filter"); 9012 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 9013 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9014 port_id, UINT8); 9015 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 9016 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9017 ops, "add#del"); 9018 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 9019 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9020 dst_port, "dst_port"); 9021 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 9022 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9023 dst_port_value, UINT16); 9024 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 9025 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9026 protocol, "protocol"); 9027 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 9028 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9029 protocol_value, UINT8); 9030 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 9031 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9032 mask, "mask"); 9033 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 9034 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9035 mask_value, INT8); 9036 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 9037 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9038 tcp_flags, "tcp_flags"); 9039 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 9040 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9041 tcp_flags_value, UINT8); 9042 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 9043 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9044 priority, "priority"); 9045 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 9046 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9047 priority_value, UINT8); 9048 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 9049 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9050 queue, "queue"); 9051 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 9052 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9053 queue_id, UINT16); 9054 9055 cmdline_parse_inst_t cmd_2tuple_filter = { 9056 .f = cmd_2tuple_filter_parsed, 9057 .data = NULL, 9058 .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol " 9059 "<value> mask <value> tcp_flags <value> priority <value> queue " 9060 "<queue_id>: Add a 2tuple filter", 9061 .tokens = { 9062 (void *)&cmd_2tuple_filter_filter, 9063 (void *)&cmd_2tuple_filter_port_id, 9064 (void *)&cmd_2tuple_filter_ops, 9065 (void *)&cmd_2tuple_filter_dst_port, 9066 (void *)&cmd_2tuple_filter_dst_port_value, 9067 (void *)&cmd_2tuple_filter_protocol, 9068 (void *)&cmd_2tuple_filter_protocol_value, 9069 (void *)&cmd_2tuple_filter_mask, 9070 (void *)&cmd_2tuple_filter_mask_value, 9071 (void *)&cmd_2tuple_filter_tcp_flags, 9072 (void *)&cmd_2tuple_filter_tcp_flags_value, 9073 (void *)&cmd_2tuple_filter_priority, 9074 (void *)&cmd_2tuple_filter_priority_value, 9075 (void *)&cmd_2tuple_filter_queue, 9076 (void *)&cmd_2tuple_filter_queue_id, 9077 NULL, 9078 }, 9079 }; 9080 9081 /* *** ADD/REMOVE A 5tuple FILTER *** */ 9082 struct cmd_5tuple_filter_result { 9083 cmdline_fixed_string_t filter; 9084 uint8_t port_id; 9085 cmdline_fixed_string_t ops; 9086 cmdline_fixed_string_t dst_ip; 9087 cmdline_ipaddr_t dst_ip_value; 9088 cmdline_fixed_string_t src_ip; 9089 cmdline_ipaddr_t src_ip_value; 9090 cmdline_fixed_string_t dst_port; 9091 uint16_t dst_port_value; 9092 cmdline_fixed_string_t src_port; 9093 uint16_t src_port_value; 9094 cmdline_fixed_string_t protocol; 9095 uint8_t protocol_value; 9096 cmdline_fixed_string_t mask; 9097 uint8_t mask_value; 9098 cmdline_fixed_string_t tcp_flags; 9099 uint8_t tcp_flags_value; 9100 cmdline_fixed_string_t priority; 9101 uint8_t priority_value; 9102 cmdline_fixed_string_t queue; 9103 uint16_t queue_id; 9104 }; 9105 9106 static void 9107 cmd_5tuple_filter_parsed(void *parsed_result, 9108 __attribute__((unused)) struct cmdline *cl, 9109 __attribute__((unused)) void *data) 9110 { 9111 struct rte_eth_ntuple_filter filter; 9112 struct cmd_5tuple_filter_result *res = parsed_result; 9113 int ret = 0; 9114 9115 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 9116 if (ret < 0) { 9117 printf("ntuple filter is not supported on port %u.\n", 9118 res->port_id); 9119 return; 9120 } 9121 9122 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 9123 9124 filter.flags = RTE_5TUPLE_FLAGS; 9125 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 9126 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 9127 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 9128 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 9129 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 9130 filter.proto = res->protocol_value; 9131 filter.priority = res->priority_value; 9132 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 9133 printf("nonzero tcp_flags is only meaningful" 9134 " when protocol is TCP.\n"); 9135 return; 9136 } 9137 if (res->tcp_flags_value > TCP_FLAG_ALL) { 9138 printf("invalid TCP flags.\n"); 9139 return; 9140 } 9141 9142 if (res->tcp_flags_value != 0) { 9143 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 9144 filter.tcp_flags = res->tcp_flags_value; 9145 } 9146 9147 if (res->dst_ip_value.family == AF_INET) 9148 /* no need to convert, already big endian. */ 9149 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 9150 else { 9151 if (filter.dst_ip_mask == 0) { 9152 printf("can not support ipv6 involved compare.\n"); 9153 return; 9154 } 9155 filter.dst_ip = 0; 9156 } 9157 9158 if (res->src_ip_value.family == AF_INET) 9159 /* no need to convert, already big endian. */ 9160 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 9161 else { 9162 if (filter.src_ip_mask == 0) { 9163 printf("can not support ipv6 involved compare.\n"); 9164 return; 9165 } 9166 filter.src_ip = 0; 9167 } 9168 /* need convert to big endian. */ 9169 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 9170 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 9171 filter.queue = res->queue_id; 9172 9173 if (!strcmp(res->ops, "add")) 9174 ret = rte_eth_dev_filter_ctrl(res->port_id, 9175 RTE_ETH_FILTER_NTUPLE, 9176 RTE_ETH_FILTER_ADD, 9177 &filter); 9178 else 9179 ret = rte_eth_dev_filter_ctrl(res->port_id, 9180 RTE_ETH_FILTER_NTUPLE, 9181 RTE_ETH_FILTER_DELETE, 9182 &filter); 9183 if (ret < 0) 9184 printf("5tuple filter programming error: (%s)\n", 9185 strerror(-ret)); 9186 } 9187 9188 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 9189 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9190 filter, "5tuple_filter"); 9191 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 9192 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9193 port_id, UINT8); 9194 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 9195 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9196 ops, "add#del"); 9197 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 9198 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9199 dst_ip, "dst_ip"); 9200 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 9201 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 9202 dst_ip_value); 9203 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 9204 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9205 src_ip, "src_ip"); 9206 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 9207 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 9208 src_ip_value); 9209 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 9210 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9211 dst_port, "dst_port"); 9212 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 9213 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9214 dst_port_value, UINT16); 9215 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 9216 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9217 src_port, "src_port"); 9218 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 9219 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9220 src_port_value, UINT16); 9221 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 9222 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9223 protocol, "protocol"); 9224 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 9225 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9226 protocol_value, UINT8); 9227 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 9228 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9229 mask, "mask"); 9230 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 9231 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9232 mask_value, INT8); 9233 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 9234 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9235 tcp_flags, "tcp_flags"); 9236 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 9237 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9238 tcp_flags_value, UINT8); 9239 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 9240 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9241 priority, "priority"); 9242 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 9243 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9244 priority_value, UINT8); 9245 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 9246 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9247 queue, "queue"); 9248 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 9249 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9250 queue_id, UINT16); 9251 9252 cmdline_parse_inst_t cmd_5tuple_filter = { 9253 .f = cmd_5tuple_filter_parsed, 9254 .data = NULL, 9255 .help_str = "5tuple_filter <port_id> add|del dst_ip <value> " 9256 "src_ip <value> dst_port <value> src_port <value> " 9257 "protocol <value> mask <value> tcp_flags <value> " 9258 "priority <value> queue <queue_id>: Add/Del a 5tuple filter", 9259 .tokens = { 9260 (void *)&cmd_5tuple_filter_filter, 9261 (void *)&cmd_5tuple_filter_port_id, 9262 (void *)&cmd_5tuple_filter_ops, 9263 (void *)&cmd_5tuple_filter_dst_ip, 9264 (void *)&cmd_5tuple_filter_dst_ip_value, 9265 (void *)&cmd_5tuple_filter_src_ip, 9266 (void *)&cmd_5tuple_filter_src_ip_value, 9267 (void *)&cmd_5tuple_filter_dst_port, 9268 (void *)&cmd_5tuple_filter_dst_port_value, 9269 (void *)&cmd_5tuple_filter_src_port, 9270 (void *)&cmd_5tuple_filter_src_port_value, 9271 (void *)&cmd_5tuple_filter_protocol, 9272 (void *)&cmd_5tuple_filter_protocol_value, 9273 (void *)&cmd_5tuple_filter_mask, 9274 (void *)&cmd_5tuple_filter_mask_value, 9275 (void *)&cmd_5tuple_filter_tcp_flags, 9276 (void *)&cmd_5tuple_filter_tcp_flags_value, 9277 (void *)&cmd_5tuple_filter_priority, 9278 (void *)&cmd_5tuple_filter_priority_value, 9279 (void *)&cmd_5tuple_filter_queue, 9280 (void *)&cmd_5tuple_filter_queue_id, 9281 NULL, 9282 }, 9283 }; 9284 9285 /* *** ADD/REMOVE A flex FILTER *** */ 9286 struct cmd_flex_filter_result { 9287 cmdline_fixed_string_t filter; 9288 cmdline_fixed_string_t ops; 9289 uint8_t port_id; 9290 cmdline_fixed_string_t len; 9291 uint8_t len_value; 9292 cmdline_fixed_string_t bytes; 9293 cmdline_fixed_string_t bytes_value; 9294 cmdline_fixed_string_t mask; 9295 cmdline_fixed_string_t mask_value; 9296 cmdline_fixed_string_t priority; 9297 uint8_t priority_value; 9298 cmdline_fixed_string_t queue; 9299 uint16_t queue_id; 9300 }; 9301 9302 static int xdigit2val(unsigned char c) 9303 { 9304 int val; 9305 if (isdigit(c)) 9306 val = c - '0'; 9307 else if (isupper(c)) 9308 val = c - 'A' + 10; 9309 else 9310 val = c - 'a' + 10; 9311 return val; 9312 } 9313 9314 static void 9315 cmd_flex_filter_parsed(void *parsed_result, 9316 __attribute__((unused)) struct cmdline *cl, 9317 __attribute__((unused)) void *data) 9318 { 9319 int ret = 0; 9320 struct rte_eth_flex_filter filter; 9321 struct cmd_flex_filter_result *res = parsed_result; 9322 char *bytes_ptr, *mask_ptr; 9323 uint16_t len, i, j = 0; 9324 char c; 9325 int val; 9326 uint8_t byte = 0; 9327 9328 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 9329 printf("the len exceed the max length 128\n"); 9330 return; 9331 } 9332 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 9333 filter.len = res->len_value; 9334 filter.priority = res->priority_value; 9335 filter.queue = res->queue_id; 9336 bytes_ptr = res->bytes_value; 9337 mask_ptr = res->mask_value; 9338 9339 /* translate bytes string to array. */ 9340 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 9341 (bytes_ptr[1] == 'X'))) 9342 bytes_ptr += 2; 9343 len = strnlen(bytes_ptr, res->len_value * 2); 9344 if (len == 0 || (len % 8 != 0)) { 9345 printf("please check len and bytes input\n"); 9346 return; 9347 } 9348 for (i = 0; i < len; i++) { 9349 c = bytes_ptr[i]; 9350 if (isxdigit(c) == 0) { 9351 /* invalid characters. */ 9352 printf("invalid input\n"); 9353 return; 9354 } 9355 val = xdigit2val(c); 9356 if (i % 2) { 9357 byte |= val; 9358 filter.bytes[j] = byte; 9359 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 9360 j++; 9361 byte = 0; 9362 } else 9363 byte |= val << 4; 9364 } 9365 printf("\n"); 9366 /* translate mask string to uint8_t array. */ 9367 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 9368 (mask_ptr[1] == 'X'))) 9369 mask_ptr += 2; 9370 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 9371 if (len == 0) { 9372 printf("invalid input\n"); 9373 return; 9374 } 9375 j = 0; 9376 byte = 0; 9377 for (i = 0; i < len; i++) { 9378 c = mask_ptr[i]; 9379 if (isxdigit(c) == 0) { 9380 /* invalid characters. */ 9381 printf("invalid input\n"); 9382 return; 9383 } 9384 val = xdigit2val(c); 9385 if (i % 2) { 9386 byte |= val; 9387 filter.mask[j] = byte; 9388 printf("mask[%d]:%02x ", j, filter.mask[j]); 9389 j++; 9390 byte = 0; 9391 } else 9392 byte |= val << 4; 9393 } 9394 printf("\n"); 9395 9396 if (!strcmp(res->ops, "add")) 9397 ret = rte_eth_dev_filter_ctrl(res->port_id, 9398 RTE_ETH_FILTER_FLEXIBLE, 9399 RTE_ETH_FILTER_ADD, 9400 &filter); 9401 else 9402 ret = rte_eth_dev_filter_ctrl(res->port_id, 9403 RTE_ETH_FILTER_FLEXIBLE, 9404 RTE_ETH_FILTER_DELETE, 9405 &filter); 9406 9407 if (ret < 0) 9408 printf("flex filter setting error: (%s)\n", strerror(-ret)); 9409 } 9410 9411 cmdline_parse_token_string_t cmd_flex_filter_filter = 9412 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9413 filter, "flex_filter"); 9414 cmdline_parse_token_num_t cmd_flex_filter_port_id = 9415 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9416 port_id, UINT8); 9417 cmdline_parse_token_string_t cmd_flex_filter_ops = 9418 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9419 ops, "add#del"); 9420 cmdline_parse_token_string_t cmd_flex_filter_len = 9421 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9422 len, "len"); 9423 cmdline_parse_token_num_t cmd_flex_filter_len_value = 9424 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9425 len_value, UINT8); 9426 cmdline_parse_token_string_t cmd_flex_filter_bytes = 9427 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9428 bytes, "bytes"); 9429 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 9430 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9431 bytes_value, NULL); 9432 cmdline_parse_token_string_t cmd_flex_filter_mask = 9433 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9434 mask, "mask"); 9435 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 9436 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9437 mask_value, NULL); 9438 cmdline_parse_token_string_t cmd_flex_filter_priority = 9439 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9440 priority, "priority"); 9441 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 9442 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9443 priority_value, UINT8); 9444 cmdline_parse_token_string_t cmd_flex_filter_queue = 9445 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9446 queue, "queue"); 9447 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 9448 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9449 queue_id, UINT16); 9450 cmdline_parse_inst_t cmd_flex_filter = { 9451 .f = cmd_flex_filter_parsed, 9452 .data = NULL, 9453 .help_str = "flex_filter <port_id> add|del len <value> bytes " 9454 "<value> mask <value> priority <value> queue <queue_id>: " 9455 "Add/Del a flex filter", 9456 .tokens = { 9457 (void *)&cmd_flex_filter_filter, 9458 (void *)&cmd_flex_filter_port_id, 9459 (void *)&cmd_flex_filter_ops, 9460 (void *)&cmd_flex_filter_len, 9461 (void *)&cmd_flex_filter_len_value, 9462 (void *)&cmd_flex_filter_bytes, 9463 (void *)&cmd_flex_filter_bytes_value, 9464 (void *)&cmd_flex_filter_mask, 9465 (void *)&cmd_flex_filter_mask_value, 9466 (void *)&cmd_flex_filter_priority, 9467 (void *)&cmd_flex_filter_priority_value, 9468 (void *)&cmd_flex_filter_queue, 9469 (void *)&cmd_flex_filter_queue_id, 9470 NULL, 9471 }, 9472 }; 9473 9474 /* *** Filters Control *** */ 9475 9476 /* *** deal with ethertype filter *** */ 9477 struct cmd_ethertype_filter_result { 9478 cmdline_fixed_string_t filter; 9479 uint8_t port_id; 9480 cmdline_fixed_string_t ops; 9481 cmdline_fixed_string_t mac; 9482 struct ether_addr mac_addr; 9483 cmdline_fixed_string_t ethertype; 9484 uint16_t ethertype_value; 9485 cmdline_fixed_string_t drop; 9486 cmdline_fixed_string_t queue; 9487 uint16_t queue_id; 9488 }; 9489 9490 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 9491 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9492 filter, "ethertype_filter"); 9493 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 9494 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9495 port_id, UINT8); 9496 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 9497 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9498 ops, "add#del"); 9499 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 9500 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9501 mac, "mac_addr#mac_ignr"); 9502 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 9503 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 9504 mac_addr); 9505 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 9506 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9507 ethertype, "ethertype"); 9508 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 9509 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9510 ethertype_value, UINT16); 9511 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 9512 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9513 drop, "drop#fwd"); 9514 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 9515 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9516 queue, "queue"); 9517 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 9518 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9519 queue_id, UINT16); 9520 9521 static void 9522 cmd_ethertype_filter_parsed(void *parsed_result, 9523 __attribute__((unused)) struct cmdline *cl, 9524 __attribute__((unused)) void *data) 9525 { 9526 struct cmd_ethertype_filter_result *res = parsed_result; 9527 struct rte_eth_ethertype_filter filter; 9528 int ret = 0; 9529 9530 ret = rte_eth_dev_filter_supported(res->port_id, 9531 RTE_ETH_FILTER_ETHERTYPE); 9532 if (ret < 0) { 9533 printf("ethertype filter is not supported on port %u.\n", 9534 res->port_id); 9535 return; 9536 } 9537 9538 memset(&filter, 0, sizeof(filter)); 9539 if (!strcmp(res->mac, "mac_addr")) { 9540 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 9541 rte_memcpy(&filter.mac_addr, &res->mac_addr, 9542 sizeof(struct ether_addr)); 9543 } 9544 if (!strcmp(res->drop, "drop")) 9545 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 9546 filter.ether_type = res->ethertype_value; 9547 filter.queue = res->queue_id; 9548 9549 if (!strcmp(res->ops, "add")) 9550 ret = rte_eth_dev_filter_ctrl(res->port_id, 9551 RTE_ETH_FILTER_ETHERTYPE, 9552 RTE_ETH_FILTER_ADD, 9553 &filter); 9554 else 9555 ret = rte_eth_dev_filter_ctrl(res->port_id, 9556 RTE_ETH_FILTER_ETHERTYPE, 9557 RTE_ETH_FILTER_DELETE, 9558 &filter); 9559 if (ret < 0) 9560 printf("ethertype filter programming error: (%s)\n", 9561 strerror(-ret)); 9562 } 9563 9564 cmdline_parse_inst_t cmd_ethertype_filter = { 9565 .f = cmd_ethertype_filter_parsed, 9566 .data = NULL, 9567 .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr " 9568 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: " 9569 "Add or delete an ethertype filter entry", 9570 .tokens = { 9571 (void *)&cmd_ethertype_filter_filter, 9572 (void *)&cmd_ethertype_filter_port_id, 9573 (void *)&cmd_ethertype_filter_ops, 9574 (void *)&cmd_ethertype_filter_mac, 9575 (void *)&cmd_ethertype_filter_mac_addr, 9576 (void *)&cmd_ethertype_filter_ethertype, 9577 (void *)&cmd_ethertype_filter_ethertype_value, 9578 (void *)&cmd_ethertype_filter_drop, 9579 (void *)&cmd_ethertype_filter_queue, 9580 (void *)&cmd_ethertype_filter_queue_id, 9581 NULL, 9582 }, 9583 }; 9584 9585 /* *** deal with flow director filter *** */ 9586 struct cmd_flow_director_result { 9587 cmdline_fixed_string_t flow_director_filter; 9588 uint8_t port_id; 9589 cmdline_fixed_string_t mode; 9590 cmdline_fixed_string_t mode_value; 9591 cmdline_fixed_string_t ops; 9592 cmdline_fixed_string_t flow; 9593 cmdline_fixed_string_t flow_type; 9594 cmdline_fixed_string_t ether; 9595 uint16_t ether_type; 9596 cmdline_fixed_string_t src; 9597 cmdline_ipaddr_t ip_src; 9598 uint16_t port_src; 9599 cmdline_fixed_string_t dst; 9600 cmdline_ipaddr_t ip_dst; 9601 uint16_t port_dst; 9602 cmdline_fixed_string_t verify_tag; 9603 uint32_t verify_tag_value; 9604 cmdline_ipaddr_t tos; 9605 uint8_t tos_value; 9606 cmdline_ipaddr_t proto; 9607 uint8_t proto_value; 9608 cmdline_ipaddr_t ttl; 9609 uint8_t ttl_value; 9610 cmdline_fixed_string_t vlan; 9611 uint16_t vlan_value; 9612 cmdline_fixed_string_t flexbytes; 9613 cmdline_fixed_string_t flexbytes_value; 9614 cmdline_fixed_string_t pf_vf; 9615 cmdline_fixed_string_t drop; 9616 cmdline_fixed_string_t queue; 9617 uint16_t queue_id; 9618 cmdline_fixed_string_t fd_id; 9619 uint32_t fd_id_value; 9620 cmdline_fixed_string_t mac; 9621 struct ether_addr mac_addr; 9622 cmdline_fixed_string_t tunnel; 9623 cmdline_fixed_string_t tunnel_type; 9624 cmdline_fixed_string_t tunnel_id; 9625 uint32_t tunnel_id_value; 9626 }; 9627 9628 static inline int 9629 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 9630 { 9631 char s[256]; 9632 const char *p, *p0 = q_arg; 9633 char *end; 9634 unsigned long int_fld; 9635 char *str_fld[max_num]; 9636 int i; 9637 unsigned size; 9638 int ret = -1; 9639 9640 p = strchr(p0, '('); 9641 if (p == NULL) 9642 return -1; 9643 ++p; 9644 p0 = strchr(p, ')'); 9645 if (p0 == NULL) 9646 return -1; 9647 9648 size = p0 - p; 9649 if (size >= sizeof(s)) 9650 return -1; 9651 9652 snprintf(s, sizeof(s), "%.*s", size, p); 9653 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9654 if (ret < 0 || ret > max_num) 9655 return -1; 9656 for (i = 0; i < ret; i++) { 9657 errno = 0; 9658 int_fld = strtoul(str_fld[i], &end, 0); 9659 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 9660 return -1; 9661 flexbytes[i] = (uint8_t)int_fld; 9662 } 9663 return ret; 9664 } 9665 9666 static uint16_t 9667 str2flowtype(char *string) 9668 { 9669 uint8_t i = 0; 9670 static const struct { 9671 char str[32]; 9672 uint16_t type; 9673 } flowtype_str[] = { 9674 {"raw", RTE_ETH_FLOW_RAW}, 9675 {"ipv4", RTE_ETH_FLOW_IPV4}, 9676 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 9677 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 9678 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 9679 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 9680 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 9681 {"ipv6", RTE_ETH_FLOW_IPV6}, 9682 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 9683 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 9684 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 9685 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 9686 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 9687 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 9688 }; 9689 9690 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 9691 if (!strcmp(flowtype_str[i].str, string)) 9692 return flowtype_str[i].type; 9693 } 9694 9695 if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64) 9696 return (uint16_t)atoi(string); 9697 9698 return RTE_ETH_FLOW_UNKNOWN; 9699 } 9700 9701 static enum rte_eth_fdir_tunnel_type 9702 str2fdir_tunneltype(char *string) 9703 { 9704 uint8_t i = 0; 9705 9706 static const struct { 9707 char str[32]; 9708 enum rte_eth_fdir_tunnel_type type; 9709 } tunneltype_str[] = { 9710 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE}, 9711 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN}, 9712 }; 9713 9714 for (i = 0; i < RTE_DIM(tunneltype_str); i++) { 9715 if (!strcmp(tunneltype_str[i].str, string)) 9716 return tunneltype_str[i].type; 9717 } 9718 return RTE_FDIR_TUNNEL_TYPE_UNKNOWN; 9719 } 9720 9721 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 9722 do { \ 9723 if ((ip_addr).family == AF_INET) \ 9724 (ip) = (ip_addr).addr.ipv4.s_addr; \ 9725 else { \ 9726 printf("invalid parameter.\n"); \ 9727 return; \ 9728 } \ 9729 } while (0) 9730 9731 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 9732 do { \ 9733 if ((ip_addr).family == AF_INET6) \ 9734 rte_memcpy(&(ip), \ 9735 &((ip_addr).addr.ipv6), \ 9736 sizeof(struct in6_addr)); \ 9737 else { \ 9738 printf("invalid parameter.\n"); \ 9739 return; \ 9740 } \ 9741 } while (0) 9742 9743 static void 9744 cmd_flow_director_filter_parsed(void *parsed_result, 9745 __attribute__((unused)) struct cmdline *cl, 9746 __attribute__((unused)) void *data) 9747 { 9748 struct cmd_flow_director_result *res = parsed_result; 9749 struct rte_eth_fdir_filter entry; 9750 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 9751 char *end; 9752 unsigned long vf_id; 9753 int ret = 0; 9754 9755 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 9756 if (ret < 0) { 9757 printf("flow director is not supported on port %u.\n", 9758 res->port_id); 9759 return; 9760 } 9761 memset(flexbytes, 0, sizeof(flexbytes)); 9762 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 9763 9764 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 9765 if (strcmp(res->mode_value, "MAC-VLAN")) { 9766 printf("Please set mode to MAC-VLAN.\n"); 9767 return; 9768 } 9769 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9770 if (strcmp(res->mode_value, "Tunnel")) { 9771 printf("Please set mode to Tunnel.\n"); 9772 return; 9773 } 9774 } else { 9775 if (strcmp(res->mode_value, "IP")) { 9776 printf("Please set mode to IP.\n"); 9777 return; 9778 } 9779 entry.input.flow_type = str2flowtype(res->flow_type); 9780 } 9781 9782 ret = parse_flexbytes(res->flexbytes_value, 9783 flexbytes, 9784 RTE_ETH_FDIR_MAX_FLEXLEN); 9785 if (ret < 0) { 9786 printf("error: Cannot parse flexbytes input.\n"); 9787 return; 9788 } 9789 9790 switch (entry.input.flow_type) { 9791 case RTE_ETH_FLOW_FRAG_IPV4: 9792 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 9793 entry.input.flow.ip4_flow.proto = res->proto_value; 9794 /* fall-through */ 9795 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 9796 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 9797 IPV4_ADDR_TO_UINT(res->ip_dst, 9798 entry.input.flow.ip4_flow.dst_ip); 9799 IPV4_ADDR_TO_UINT(res->ip_src, 9800 entry.input.flow.ip4_flow.src_ip); 9801 entry.input.flow.ip4_flow.tos = res->tos_value; 9802 entry.input.flow.ip4_flow.ttl = res->ttl_value; 9803 /* need convert to big endian. */ 9804 entry.input.flow.udp4_flow.dst_port = 9805 rte_cpu_to_be_16(res->port_dst); 9806 entry.input.flow.udp4_flow.src_port = 9807 rte_cpu_to_be_16(res->port_src); 9808 break; 9809 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 9810 IPV4_ADDR_TO_UINT(res->ip_dst, 9811 entry.input.flow.sctp4_flow.ip.dst_ip); 9812 IPV4_ADDR_TO_UINT(res->ip_src, 9813 entry.input.flow.sctp4_flow.ip.src_ip); 9814 entry.input.flow.ip4_flow.tos = res->tos_value; 9815 entry.input.flow.ip4_flow.ttl = res->ttl_value; 9816 /* need convert to big endian. */ 9817 entry.input.flow.sctp4_flow.dst_port = 9818 rte_cpu_to_be_16(res->port_dst); 9819 entry.input.flow.sctp4_flow.src_port = 9820 rte_cpu_to_be_16(res->port_src); 9821 entry.input.flow.sctp4_flow.verify_tag = 9822 rte_cpu_to_be_32(res->verify_tag_value); 9823 break; 9824 case RTE_ETH_FLOW_FRAG_IPV6: 9825 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 9826 entry.input.flow.ipv6_flow.proto = res->proto_value; 9827 /* fall-through */ 9828 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 9829 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 9830 IPV6_ADDR_TO_ARRAY(res->ip_dst, 9831 entry.input.flow.ipv6_flow.dst_ip); 9832 IPV6_ADDR_TO_ARRAY(res->ip_src, 9833 entry.input.flow.ipv6_flow.src_ip); 9834 entry.input.flow.ipv6_flow.tc = res->tos_value; 9835 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 9836 /* need convert to big endian. */ 9837 entry.input.flow.udp6_flow.dst_port = 9838 rte_cpu_to_be_16(res->port_dst); 9839 entry.input.flow.udp6_flow.src_port = 9840 rte_cpu_to_be_16(res->port_src); 9841 break; 9842 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 9843 IPV6_ADDR_TO_ARRAY(res->ip_dst, 9844 entry.input.flow.sctp6_flow.ip.dst_ip); 9845 IPV6_ADDR_TO_ARRAY(res->ip_src, 9846 entry.input.flow.sctp6_flow.ip.src_ip); 9847 entry.input.flow.ipv6_flow.tc = res->tos_value; 9848 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 9849 /* need convert to big endian. */ 9850 entry.input.flow.sctp6_flow.dst_port = 9851 rte_cpu_to_be_16(res->port_dst); 9852 entry.input.flow.sctp6_flow.src_port = 9853 rte_cpu_to_be_16(res->port_src); 9854 entry.input.flow.sctp6_flow.verify_tag = 9855 rte_cpu_to_be_32(res->verify_tag_value); 9856 break; 9857 case RTE_ETH_FLOW_L2_PAYLOAD: 9858 entry.input.flow.l2_flow.ether_type = 9859 rte_cpu_to_be_16(res->ether_type); 9860 break; 9861 default: 9862 break; 9863 } 9864 9865 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 9866 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, 9867 &res->mac_addr, 9868 sizeof(struct ether_addr)); 9869 9870 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 9871 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, 9872 &res->mac_addr, 9873 sizeof(struct ether_addr)); 9874 entry.input.flow.tunnel_flow.tunnel_type = 9875 str2fdir_tunneltype(res->tunnel_type); 9876 entry.input.flow.tunnel_flow.tunnel_id = 9877 rte_cpu_to_be_32(res->tunnel_id_value); 9878 } 9879 9880 rte_memcpy(entry.input.flow_ext.flexbytes, 9881 flexbytes, 9882 RTE_ETH_FDIR_MAX_FLEXLEN); 9883 9884 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 9885 9886 entry.action.flex_off = 0; /*use 0 by default */ 9887 if (!strcmp(res->drop, "drop")) 9888 entry.action.behavior = RTE_ETH_FDIR_REJECT; 9889 else 9890 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 9891 9892 if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN && 9893 fdir_conf.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 9894 if (!strcmp(res->pf_vf, "pf")) 9895 entry.input.flow_ext.is_vf = 0; 9896 else if (!strncmp(res->pf_vf, "vf", 2)) { 9897 struct rte_eth_dev_info dev_info; 9898 9899 memset(&dev_info, 0, sizeof(dev_info)); 9900 rte_eth_dev_info_get(res->port_id, &dev_info); 9901 errno = 0; 9902 vf_id = strtoul(res->pf_vf + 2, &end, 10); 9903 if (errno != 0 || *end != '\0' || 9904 vf_id >= dev_info.max_vfs) { 9905 printf("invalid parameter %s.\n", res->pf_vf); 9906 return; 9907 } 9908 entry.input.flow_ext.is_vf = 1; 9909 entry.input.flow_ext.dst_id = (uint16_t)vf_id; 9910 } else { 9911 printf("invalid parameter %s.\n", res->pf_vf); 9912 return; 9913 } 9914 } 9915 9916 /* set to report FD ID by default */ 9917 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 9918 entry.action.rx_queue = res->queue_id; 9919 entry.soft_id = res->fd_id_value; 9920 if (!strcmp(res->ops, "add")) 9921 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9922 RTE_ETH_FILTER_ADD, &entry); 9923 else if (!strcmp(res->ops, "del")) 9924 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9925 RTE_ETH_FILTER_DELETE, &entry); 9926 else 9927 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 9928 RTE_ETH_FILTER_UPDATE, &entry); 9929 if (ret < 0) 9930 printf("flow director programming error: (%s)\n", 9931 strerror(-ret)); 9932 } 9933 9934 cmdline_parse_token_string_t cmd_flow_director_filter = 9935 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9936 flow_director_filter, "flow_director_filter"); 9937 cmdline_parse_token_num_t cmd_flow_director_port_id = 9938 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9939 port_id, UINT8); 9940 cmdline_parse_token_string_t cmd_flow_director_ops = 9941 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9942 ops, "add#del#update"); 9943 cmdline_parse_token_string_t cmd_flow_director_flow = 9944 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9945 flow, "flow"); 9946 cmdline_parse_token_string_t cmd_flow_director_flow_type = 9947 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9948 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 9949 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload"); 9950 cmdline_parse_token_string_t cmd_flow_director_ether = 9951 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9952 ether, "ether"); 9953 cmdline_parse_token_num_t cmd_flow_director_ether_type = 9954 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9955 ether_type, UINT16); 9956 cmdline_parse_token_string_t cmd_flow_director_src = 9957 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9958 src, "src"); 9959 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 9960 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 9961 ip_src); 9962 cmdline_parse_token_num_t cmd_flow_director_port_src = 9963 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9964 port_src, UINT16); 9965 cmdline_parse_token_string_t cmd_flow_director_dst = 9966 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9967 dst, "dst"); 9968 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 9969 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 9970 ip_dst); 9971 cmdline_parse_token_num_t cmd_flow_director_port_dst = 9972 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9973 port_dst, UINT16); 9974 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 9975 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9976 verify_tag, "verify_tag"); 9977 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 9978 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9979 verify_tag_value, UINT32); 9980 cmdline_parse_token_string_t cmd_flow_director_tos = 9981 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9982 tos, "tos"); 9983 cmdline_parse_token_num_t cmd_flow_director_tos_value = 9984 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9985 tos_value, UINT8); 9986 cmdline_parse_token_string_t cmd_flow_director_proto = 9987 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9988 proto, "proto"); 9989 cmdline_parse_token_num_t cmd_flow_director_proto_value = 9990 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9991 proto_value, UINT8); 9992 cmdline_parse_token_string_t cmd_flow_director_ttl = 9993 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 9994 ttl, "ttl"); 9995 cmdline_parse_token_num_t cmd_flow_director_ttl_value = 9996 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 9997 ttl_value, UINT8); 9998 cmdline_parse_token_string_t cmd_flow_director_vlan = 9999 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10000 vlan, "vlan"); 10001 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 10002 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10003 vlan_value, UINT16); 10004 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 10005 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10006 flexbytes, "flexbytes"); 10007 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 10008 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10009 flexbytes_value, NULL); 10010 cmdline_parse_token_string_t cmd_flow_director_drop = 10011 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10012 drop, "drop#fwd"); 10013 cmdline_parse_token_string_t cmd_flow_director_pf_vf = 10014 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10015 pf_vf, NULL); 10016 cmdline_parse_token_string_t cmd_flow_director_queue = 10017 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10018 queue, "queue"); 10019 cmdline_parse_token_num_t cmd_flow_director_queue_id = 10020 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10021 queue_id, UINT16); 10022 cmdline_parse_token_string_t cmd_flow_director_fd_id = 10023 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10024 fd_id, "fd_id"); 10025 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 10026 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10027 fd_id_value, UINT32); 10028 10029 cmdline_parse_token_string_t cmd_flow_director_mode = 10030 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10031 mode, "mode"); 10032 cmdline_parse_token_string_t cmd_flow_director_mode_ip = 10033 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10034 mode_value, "IP"); 10035 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan = 10036 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10037 mode_value, "MAC-VLAN"); 10038 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel = 10039 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10040 mode_value, "Tunnel"); 10041 cmdline_parse_token_string_t cmd_flow_director_mac = 10042 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10043 mac, "mac"); 10044 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr = 10045 TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result, 10046 mac_addr); 10047 cmdline_parse_token_string_t cmd_flow_director_tunnel = 10048 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10049 tunnel, "tunnel"); 10050 cmdline_parse_token_string_t cmd_flow_director_tunnel_type = 10051 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10052 tunnel_type, "NVGRE#VxLAN"); 10053 cmdline_parse_token_string_t cmd_flow_director_tunnel_id = 10054 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10055 tunnel_id, "tunnel-id"); 10056 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value = 10057 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10058 tunnel_id_value, UINT32); 10059 10060 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 10061 .f = cmd_flow_director_filter_parsed, 10062 .data = NULL, 10063 .help_str = "flow_director_filter <port_id> mode IP add|del|update flow" 10064 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 10065 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 10066 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " 10067 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " 10068 "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> " 10069 "fd_id <fd_id_value>: " 10070 "Add or delete an ip flow director entry on NIC", 10071 .tokens = { 10072 (void *)&cmd_flow_director_filter, 10073 (void *)&cmd_flow_director_port_id, 10074 (void *)&cmd_flow_director_mode, 10075 (void *)&cmd_flow_director_mode_ip, 10076 (void *)&cmd_flow_director_ops, 10077 (void *)&cmd_flow_director_flow, 10078 (void *)&cmd_flow_director_flow_type, 10079 (void *)&cmd_flow_director_src, 10080 (void *)&cmd_flow_director_ip_src, 10081 (void *)&cmd_flow_director_dst, 10082 (void *)&cmd_flow_director_ip_dst, 10083 (void *)&cmd_flow_director_tos, 10084 (void *)&cmd_flow_director_tos_value, 10085 (void *)&cmd_flow_director_proto, 10086 (void *)&cmd_flow_director_proto_value, 10087 (void *)&cmd_flow_director_ttl, 10088 (void *)&cmd_flow_director_ttl_value, 10089 (void *)&cmd_flow_director_vlan, 10090 (void *)&cmd_flow_director_vlan_value, 10091 (void *)&cmd_flow_director_flexbytes, 10092 (void *)&cmd_flow_director_flexbytes_value, 10093 (void *)&cmd_flow_director_drop, 10094 (void *)&cmd_flow_director_pf_vf, 10095 (void *)&cmd_flow_director_queue, 10096 (void *)&cmd_flow_director_queue_id, 10097 (void *)&cmd_flow_director_fd_id, 10098 (void *)&cmd_flow_director_fd_id_value, 10099 NULL, 10100 }, 10101 }; 10102 10103 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 10104 .f = cmd_flow_director_filter_parsed, 10105 .data = NULL, 10106 .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow " 10107 "director entry on NIC", 10108 .tokens = { 10109 (void *)&cmd_flow_director_filter, 10110 (void *)&cmd_flow_director_port_id, 10111 (void *)&cmd_flow_director_mode, 10112 (void *)&cmd_flow_director_mode_ip, 10113 (void *)&cmd_flow_director_ops, 10114 (void *)&cmd_flow_director_flow, 10115 (void *)&cmd_flow_director_flow_type, 10116 (void *)&cmd_flow_director_src, 10117 (void *)&cmd_flow_director_ip_src, 10118 (void *)&cmd_flow_director_port_src, 10119 (void *)&cmd_flow_director_dst, 10120 (void *)&cmd_flow_director_ip_dst, 10121 (void *)&cmd_flow_director_port_dst, 10122 (void *)&cmd_flow_director_tos, 10123 (void *)&cmd_flow_director_tos_value, 10124 (void *)&cmd_flow_director_ttl, 10125 (void *)&cmd_flow_director_ttl_value, 10126 (void *)&cmd_flow_director_vlan, 10127 (void *)&cmd_flow_director_vlan_value, 10128 (void *)&cmd_flow_director_flexbytes, 10129 (void *)&cmd_flow_director_flexbytes_value, 10130 (void *)&cmd_flow_director_drop, 10131 (void *)&cmd_flow_director_pf_vf, 10132 (void *)&cmd_flow_director_queue, 10133 (void *)&cmd_flow_director_queue_id, 10134 (void *)&cmd_flow_director_fd_id, 10135 (void *)&cmd_flow_director_fd_id_value, 10136 NULL, 10137 }, 10138 }; 10139 10140 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 10141 .f = cmd_flow_director_filter_parsed, 10142 .data = NULL, 10143 .help_str = "flow_director_filter ... : Add or delete a sctp flow " 10144 "director entry on NIC", 10145 .tokens = { 10146 (void *)&cmd_flow_director_filter, 10147 (void *)&cmd_flow_director_port_id, 10148 (void *)&cmd_flow_director_mode, 10149 (void *)&cmd_flow_director_mode_ip, 10150 (void *)&cmd_flow_director_ops, 10151 (void *)&cmd_flow_director_flow, 10152 (void *)&cmd_flow_director_flow_type, 10153 (void *)&cmd_flow_director_src, 10154 (void *)&cmd_flow_director_ip_src, 10155 (void *)&cmd_flow_director_port_dst, 10156 (void *)&cmd_flow_director_dst, 10157 (void *)&cmd_flow_director_ip_dst, 10158 (void *)&cmd_flow_director_port_dst, 10159 (void *)&cmd_flow_director_verify_tag, 10160 (void *)&cmd_flow_director_verify_tag_value, 10161 (void *)&cmd_flow_director_tos, 10162 (void *)&cmd_flow_director_tos_value, 10163 (void *)&cmd_flow_director_ttl, 10164 (void *)&cmd_flow_director_ttl_value, 10165 (void *)&cmd_flow_director_vlan, 10166 (void *)&cmd_flow_director_vlan_value, 10167 (void *)&cmd_flow_director_flexbytes, 10168 (void *)&cmd_flow_director_flexbytes_value, 10169 (void *)&cmd_flow_director_drop, 10170 (void *)&cmd_flow_director_pf_vf, 10171 (void *)&cmd_flow_director_queue, 10172 (void *)&cmd_flow_director_queue_id, 10173 (void *)&cmd_flow_director_fd_id, 10174 (void *)&cmd_flow_director_fd_id_value, 10175 NULL, 10176 }, 10177 }; 10178 10179 cmdline_parse_inst_t cmd_add_del_l2_flow_director = { 10180 .f = cmd_flow_director_filter_parsed, 10181 .data = NULL, 10182 .help_str = "flow_director_filter ... : Add or delete a L2 flow " 10183 "director entry on NIC", 10184 .tokens = { 10185 (void *)&cmd_flow_director_filter, 10186 (void *)&cmd_flow_director_port_id, 10187 (void *)&cmd_flow_director_mode, 10188 (void *)&cmd_flow_director_mode_ip, 10189 (void *)&cmd_flow_director_ops, 10190 (void *)&cmd_flow_director_flow, 10191 (void *)&cmd_flow_director_flow_type, 10192 (void *)&cmd_flow_director_ether, 10193 (void *)&cmd_flow_director_ether_type, 10194 (void *)&cmd_flow_director_flexbytes, 10195 (void *)&cmd_flow_director_flexbytes_value, 10196 (void *)&cmd_flow_director_drop, 10197 (void *)&cmd_flow_director_pf_vf, 10198 (void *)&cmd_flow_director_queue, 10199 (void *)&cmd_flow_director_queue_id, 10200 (void *)&cmd_flow_director_fd_id, 10201 (void *)&cmd_flow_director_fd_id_value, 10202 NULL, 10203 }, 10204 }; 10205 10206 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = { 10207 .f = cmd_flow_director_filter_parsed, 10208 .data = NULL, 10209 .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow " 10210 "director entry on NIC", 10211 .tokens = { 10212 (void *)&cmd_flow_director_filter, 10213 (void *)&cmd_flow_director_port_id, 10214 (void *)&cmd_flow_director_mode, 10215 (void *)&cmd_flow_director_mode_mac_vlan, 10216 (void *)&cmd_flow_director_ops, 10217 (void *)&cmd_flow_director_mac, 10218 (void *)&cmd_flow_director_mac_addr, 10219 (void *)&cmd_flow_director_vlan, 10220 (void *)&cmd_flow_director_vlan_value, 10221 (void *)&cmd_flow_director_flexbytes, 10222 (void *)&cmd_flow_director_flexbytes_value, 10223 (void *)&cmd_flow_director_drop, 10224 (void *)&cmd_flow_director_queue, 10225 (void *)&cmd_flow_director_queue_id, 10226 (void *)&cmd_flow_director_fd_id, 10227 (void *)&cmd_flow_director_fd_id_value, 10228 NULL, 10229 }, 10230 }; 10231 10232 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { 10233 .f = cmd_flow_director_filter_parsed, 10234 .data = NULL, 10235 .help_str = "flow_director_filter ... : Add or delete a tunnel flow " 10236 "director entry on NIC", 10237 .tokens = { 10238 (void *)&cmd_flow_director_filter, 10239 (void *)&cmd_flow_director_port_id, 10240 (void *)&cmd_flow_director_mode, 10241 (void *)&cmd_flow_director_mode_tunnel, 10242 (void *)&cmd_flow_director_ops, 10243 (void *)&cmd_flow_director_mac, 10244 (void *)&cmd_flow_director_mac_addr, 10245 (void *)&cmd_flow_director_vlan, 10246 (void *)&cmd_flow_director_vlan_value, 10247 (void *)&cmd_flow_director_tunnel, 10248 (void *)&cmd_flow_director_tunnel_type, 10249 (void *)&cmd_flow_director_tunnel_id, 10250 (void *)&cmd_flow_director_tunnel_id_value, 10251 (void *)&cmd_flow_director_flexbytes, 10252 (void *)&cmd_flow_director_flexbytes_value, 10253 (void *)&cmd_flow_director_drop, 10254 (void *)&cmd_flow_director_queue, 10255 (void *)&cmd_flow_director_queue_id, 10256 (void *)&cmd_flow_director_fd_id, 10257 (void *)&cmd_flow_director_fd_id_value, 10258 NULL, 10259 }, 10260 }; 10261 10262 struct cmd_flush_flow_director_result { 10263 cmdline_fixed_string_t flush_flow_director; 10264 uint8_t port_id; 10265 }; 10266 10267 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 10268 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 10269 flush_flow_director, "flush_flow_director"); 10270 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 10271 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 10272 port_id, UINT8); 10273 10274 static void 10275 cmd_flush_flow_director_parsed(void *parsed_result, 10276 __attribute__((unused)) struct cmdline *cl, 10277 __attribute__((unused)) void *data) 10278 { 10279 struct cmd_flow_director_result *res = parsed_result; 10280 int ret = 0; 10281 10282 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 10283 if (ret < 0) { 10284 printf("flow director is not supported on port %u.\n", 10285 res->port_id); 10286 return; 10287 } 10288 10289 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10290 RTE_ETH_FILTER_FLUSH, NULL); 10291 if (ret < 0) 10292 printf("flow director table flushing error: (%s)\n", 10293 strerror(-ret)); 10294 } 10295 10296 cmdline_parse_inst_t cmd_flush_flow_director = { 10297 .f = cmd_flush_flow_director_parsed, 10298 .data = NULL, 10299 .help_str = "flush_flow_director <port_id>: " 10300 "Flush all flow director entries of a device on NIC", 10301 .tokens = { 10302 (void *)&cmd_flush_flow_director_flush, 10303 (void *)&cmd_flush_flow_director_port_id, 10304 NULL, 10305 }, 10306 }; 10307 10308 /* *** deal with flow director mask *** */ 10309 struct cmd_flow_director_mask_result { 10310 cmdline_fixed_string_t flow_director_mask; 10311 uint8_t port_id; 10312 cmdline_fixed_string_t mode; 10313 cmdline_fixed_string_t mode_value; 10314 cmdline_fixed_string_t vlan; 10315 uint16_t vlan_mask; 10316 cmdline_fixed_string_t src_mask; 10317 cmdline_ipaddr_t ipv4_src; 10318 cmdline_ipaddr_t ipv6_src; 10319 uint16_t port_src; 10320 cmdline_fixed_string_t dst_mask; 10321 cmdline_ipaddr_t ipv4_dst; 10322 cmdline_ipaddr_t ipv6_dst; 10323 uint16_t port_dst; 10324 cmdline_fixed_string_t mac; 10325 uint8_t mac_addr_byte_mask; 10326 cmdline_fixed_string_t tunnel_id; 10327 uint32_t tunnel_id_mask; 10328 cmdline_fixed_string_t tunnel_type; 10329 uint8_t tunnel_type_mask; 10330 }; 10331 10332 static void 10333 cmd_flow_director_mask_parsed(void *parsed_result, 10334 __attribute__((unused)) struct cmdline *cl, 10335 __attribute__((unused)) void *data) 10336 { 10337 struct cmd_flow_director_mask_result *res = parsed_result; 10338 struct rte_eth_fdir_masks *mask; 10339 struct rte_port *port; 10340 10341 if (res->port_id > nb_ports) { 10342 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 10343 return; 10344 } 10345 10346 port = &ports[res->port_id]; 10347 /** Check if the port is not started **/ 10348 if (port->port_status != RTE_PORT_STOPPED) { 10349 printf("Please stop port %d first\n", res->port_id); 10350 return; 10351 } 10352 10353 mask = &port->dev_conf.fdir_conf.mask; 10354 10355 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 10356 if (strcmp(res->mode_value, "MAC-VLAN")) { 10357 printf("Please set mode to MAC-VLAN.\n"); 10358 return; 10359 } 10360 10361 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10362 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 10363 if (strcmp(res->mode_value, "Tunnel")) { 10364 printf("Please set mode to Tunnel.\n"); 10365 return; 10366 } 10367 10368 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10369 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 10370 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 10371 mask->tunnel_type_mask = res->tunnel_type_mask; 10372 } else { 10373 if (strcmp(res->mode_value, "IP")) { 10374 printf("Please set mode to IP.\n"); 10375 return; 10376 } 10377 10378 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10379 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 10380 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 10381 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 10382 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 10383 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 10384 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 10385 } 10386 10387 cmd_reconfig_device_queue(res->port_id, 1, 1); 10388 } 10389 10390 cmdline_parse_token_string_t cmd_flow_director_mask = 10391 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10392 flow_director_mask, "flow_director_mask"); 10393 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 10394 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10395 port_id, UINT8); 10396 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 10397 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10398 vlan, "vlan"); 10399 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 10400 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10401 vlan_mask, UINT16); 10402 cmdline_parse_token_string_t cmd_flow_director_mask_src = 10403 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10404 src_mask, "src_mask"); 10405 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 10406 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10407 ipv4_src); 10408 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 10409 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10410 ipv6_src); 10411 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 10412 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10413 port_src, UINT16); 10414 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 10415 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10416 dst_mask, "dst_mask"); 10417 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 10418 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10419 ipv4_dst); 10420 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 10421 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10422 ipv6_dst); 10423 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 10424 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10425 port_dst, UINT16); 10426 10427 cmdline_parse_token_string_t cmd_flow_director_mask_mode = 10428 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10429 mode, "mode"); 10430 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 10431 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10432 mode_value, "IP"); 10433 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 10434 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10435 mode_value, "MAC-VLAN"); 10436 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 10437 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10438 mode_value, "Tunnel"); 10439 cmdline_parse_token_string_t cmd_flow_director_mask_mac = 10440 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10441 mac, "mac"); 10442 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 10443 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10444 mac_addr_byte_mask, UINT8); 10445 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 10446 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10447 tunnel_type, "tunnel-type"); 10448 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 10449 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10450 tunnel_type_mask, UINT8); 10451 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 10452 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10453 tunnel_id, "tunnel-id"); 10454 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 10455 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10456 tunnel_id_mask, UINT32); 10457 10458 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 10459 .f = cmd_flow_director_mask_parsed, 10460 .data = NULL, 10461 .help_str = "flow_director_mask ... : " 10462 "Set IP mode flow director's mask on NIC", 10463 .tokens = { 10464 (void *)&cmd_flow_director_mask, 10465 (void *)&cmd_flow_director_mask_port_id, 10466 (void *)&cmd_flow_director_mask_mode, 10467 (void *)&cmd_flow_director_mask_mode_ip, 10468 (void *)&cmd_flow_director_mask_vlan, 10469 (void *)&cmd_flow_director_mask_vlan_value, 10470 (void *)&cmd_flow_director_mask_src, 10471 (void *)&cmd_flow_director_mask_ipv4_src, 10472 (void *)&cmd_flow_director_mask_ipv6_src, 10473 (void *)&cmd_flow_director_mask_port_src, 10474 (void *)&cmd_flow_director_mask_dst, 10475 (void *)&cmd_flow_director_mask_ipv4_dst, 10476 (void *)&cmd_flow_director_mask_ipv6_dst, 10477 (void *)&cmd_flow_director_mask_port_dst, 10478 NULL, 10479 }, 10480 }; 10481 10482 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 10483 .f = cmd_flow_director_mask_parsed, 10484 .data = NULL, 10485 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 10486 "flow director's mask on NIC", 10487 .tokens = { 10488 (void *)&cmd_flow_director_mask, 10489 (void *)&cmd_flow_director_mask_port_id, 10490 (void *)&cmd_flow_director_mask_mode, 10491 (void *)&cmd_flow_director_mask_mode_mac_vlan, 10492 (void *)&cmd_flow_director_mask_vlan, 10493 (void *)&cmd_flow_director_mask_vlan_value, 10494 NULL, 10495 }, 10496 }; 10497 10498 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 10499 .f = cmd_flow_director_mask_parsed, 10500 .data = NULL, 10501 .help_str = "flow_director_mask ... : Set tunnel mode " 10502 "flow director's mask on NIC", 10503 .tokens = { 10504 (void *)&cmd_flow_director_mask, 10505 (void *)&cmd_flow_director_mask_port_id, 10506 (void *)&cmd_flow_director_mask_mode, 10507 (void *)&cmd_flow_director_mask_mode_tunnel, 10508 (void *)&cmd_flow_director_mask_vlan, 10509 (void *)&cmd_flow_director_mask_vlan_value, 10510 (void *)&cmd_flow_director_mask_mac, 10511 (void *)&cmd_flow_director_mask_mac_value, 10512 (void *)&cmd_flow_director_mask_tunnel_type, 10513 (void *)&cmd_flow_director_mask_tunnel_type_value, 10514 (void *)&cmd_flow_director_mask_tunnel_id, 10515 (void *)&cmd_flow_director_mask_tunnel_id_value, 10516 NULL, 10517 }, 10518 }; 10519 10520 /* *** deal with flow director mask on flexible payload *** */ 10521 struct cmd_flow_director_flex_mask_result { 10522 cmdline_fixed_string_t flow_director_flexmask; 10523 uint8_t port_id; 10524 cmdline_fixed_string_t flow; 10525 cmdline_fixed_string_t flow_type; 10526 cmdline_fixed_string_t mask; 10527 }; 10528 10529 static void 10530 cmd_flow_director_flex_mask_parsed(void *parsed_result, 10531 __attribute__((unused)) struct cmdline *cl, 10532 __attribute__((unused)) void *data) 10533 { 10534 struct cmd_flow_director_flex_mask_result *res = parsed_result; 10535 struct rte_eth_fdir_info fdir_info; 10536 struct rte_eth_fdir_flex_mask flex_mask; 10537 struct rte_port *port; 10538 uint32_t flow_type_mask; 10539 uint16_t i; 10540 int ret; 10541 10542 if (res->port_id > nb_ports) { 10543 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 10544 return; 10545 } 10546 10547 port = &ports[res->port_id]; 10548 /** Check if the port is not started **/ 10549 if (port->port_status != RTE_PORT_STOPPED) { 10550 printf("Please stop port %d first\n", res->port_id); 10551 return; 10552 } 10553 10554 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 10555 ret = parse_flexbytes(res->mask, 10556 flex_mask.mask, 10557 RTE_ETH_FDIR_MAX_FLEXLEN); 10558 if (ret < 0) { 10559 printf("error: Cannot parse mask input.\n"); 10560 return; 10561 } 10562 10563 memset(&fdir_info, 0, sizeof(fdir_info)); 10564 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10565 RTE_ETH_FILTER_INFO, &fdir_info); 10566 if (ret < 0) { 10567 printf("Cannot get FDir filter info\n"); 10568 return; 10569 } 10570 10571 if (!strcmp(res->flow_type, "none")) { 10572 /* means don't specify the flow type */ 10573 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN; 10574 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) 10575 memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 10576 0, sizeof(struct rte_eth_fdir_flex_mask)); 10577 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; 10578 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], 10579 &flex_mask, 10580 sizeof(struct rte_eth_fdir_flex_mask)); 10581 cmd_reconfig_device_queue(res->port_id, 1, 1); 10582 return; 10583 } 10584 flow_type_mask = fdir_info.flow_types_mask[0]; 10585 if (!strcmp(res->flow_type, "all")) { 10586 if (!flow_type_mask) { 10587 printf("No flow type supported\n"); 10588 return; 10589 } 10590 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 10591 if (flow_type_mask & (1 << i)) { 10592 flex_mask.flow_type = i; 10593 fdir_set_flex_mask(res->port_id, &flex_mask); 10594 } 10595 } 10596 cmd_reconfig_device_queue(res->port_id, 1, 1); 10597 return; 10598 } 10599 flex_mask.flow_type = str2flowtype(res->flow_type); 10600 if (!(flow_type_mask & (1 << flex_mask.flow_type))) { 10601 printf("Flow type %s not supported on port %d\n", 10602 res->flow_type, res->port_id); 10603 return; 10604 } 10605 fdir_set_flex_mask(res->port_id, &flex_mask); 10606 cmd_reconfig_device_queue(res->port_id, 1, 1); 10607 } 10608 10609 cmdline_parse_token_string_t cmd_flow_director_flexmask = 10610 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10611 flow_director_flexmask, 10612 "flow_director_flex_mask"); 10613 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 10614 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10615 port_id, UINT8); 10616 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 10617 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10618 flow, "flow"); 10619 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 10620 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10621 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 10622 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all"); 10623 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 10624 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10625 mask, NULL); 10626 10627 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 10628 .f = cmd_flow_director_flex_mask_parsed, 10629 .data = NULL, 10630 .help_str = "flow_director_flex_mask ... : " 10631 "Set flow director's flex mask on NIC", 10632 .tokens = { 10633 (void *)&cmd_flow_director_flexmask, 10634 (void *)&cmd_flow_director_flexmask_port_id, 10635 (void *)&cmd_flow_director_flexmask_flow, 10636 (void *)&cmd_flow_director_flexmask_flow_type, 10637 (void *)&cmd_flow_director_flexmask_mask, 10638 NULL, 10639 }, 10640 }; 10641 10642 /* *** deal with flow director flexible payload configuration *** */ 10643 struct cmd_flow_director_flexpayload_result { 10644 cmdline_fixed_string_t flow_director_flexpayload; 10645 uint8_t port_id; 10646 cmdline_fixed_string_t payload_layer; 10647 cmdline_fixed_string_t payload_cfg; 10648 }; 10649 10650 static inline int 10651 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 10652 { 10653 char s[256]; 10654 const char *p, *p0 = q_arg; 10655 char *end; 10656 unsigned long int_fld; 10657 char *str_fld[max_num]; 10658 int i; 10659 unsigned size; 10660 int ret = -1; 10661 10662 p = strchr(p0, '('); 10663 if (p == NULL) 10664 return -1; 10665 ++p; 10666 p0 = strchr(p, ')'); 10667 if (p0 == NULL) 10668 return -1; 10669 10670 size = p0 - p; 10671 if (size >= sizeof(s)) 10672 return -1; 10673 10674 snprintf(s, sizeof(s), "%.*s", size, p); 10675 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 10676 if (ret < 0 || ret > max_num) 10677 return -1; 10678 for (i = 0; i < ret; i++) { 10679 errno = 0; 10680 int_fld = strtoul(str_fld[i], &end, 0); 10681 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 10682 return -1; 10683 offsets[i] = (uint16_t)int_fld; 10684 } 10685 return ret; 10686 } 10687 10688 static void 10689 cmd_flow_director_flxpld_parsed(void *parsed_result, 10690 __attribute__((unused)) struct cmdline *cl, 10691 __attribute__((unused)) void *data) 10692 { 10693 struct cmd_flow_director_flexpayload_result *res = parsed_result; 10694 struct rte_eth_flex_payload_cfg flex_cfg; 10695 struct rte_port *port; 10696 int ret = 0; 10697 10698 if (res->port_id > nb_ports) { 10699 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 10700 return; 10701 } 10702 10703 port = &ports[res->port_id]; 10704 /** Check if the port is not started **/ 10705 if (port->port_status != RTE_PORT_STOPPED) { 10706 printf("Please stop port %d first\n", res->port_id); 10707 return; 10708 } 10709 10710 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 10711 10712 if (!strcmp(res->payload_layer, "raw")) 10713 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 10714 else if (!strcmp(res->payload_layer, "l2")) 10715 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 10716 else if (!strcmp(res->payload_layer, "l3")) 10717 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 10718 else if (!strcmp(res->payload_layer, "l4")) 10719 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 10720 10721 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 10722 RTE_ETH_FDIR_MAX_FLEXLEN); 10723 if (ret < 0) { 10724 printf("error: Cannot parse flex payload input.\n"); 10725 return; 10726 } 10727 10728 fdir_set_flex_payload(res->port_id, &flex_cfg); 10729 cmd_reconfig_device_queue(res->port_id, 1, 1); 10730 } 10731 10732 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 10733 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10734 flow_director_flexpayload, 10735 "flow_director_flex_payload"); 10736 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 10737 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10738 port_id, UINT8); 10739 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 10740 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10741 payload_layer, "raw#l2#l3#l4"); 10742 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 10743 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 10744 payload_cfg, NULL); 10745 10746 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 10747 .f = cmd_flow_director_flxpld_parsed, 10748 .data = NULL, 10749 .help_str = "flow_director_flexpayload ... : " 10750 "Set flow director's flex payload on NIC", 10751 .tokens = { 10752 (void *)&cmd_flow_director_flexpayload, 10753 (void *)&cmd_flow_director_flexpayload_port_id, 10754 (void *)&cmd_flow_director_flexpayload_payload_layer, 10755 (void *)&cmd_flow_director_flexpayload_payload_cfg, 10756 NULL, 10757 }, 10758 }; 10759 10760 /* Generic flow interface command. */ 10761 extern cmdline_parse_inst_t cmd_flow; 10762 10763 /* *** Classification Filters Control *** */ 10764 /* *** Get symmetric hash enable per port *** */ 10765 struct cmd_get_sym_hash_ena_per_port_result { 10766 cmdline_fixed_string_t get_sym_hash_ena_per_port; 10767 uint8_t port_id; 10768 }; 10769 10770 static void 10771 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 10772 __rte_unused struct cmdline *cl, 10773 __rte_unused void *data) 10774 { 10775 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 10776 struct rte_eth_hash_filter_info info; 10777 int ret; 10778 10779 if (rte_eth_dev_filter_supported(res->port_id, 10780 RTE_ETH_FILTER_HASH) < 0) { 10781 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 10782 res->port_id); 10783 return; 10784 } 10785 10786 memset(&info, 0, sizeof(info)); 10787 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 10788 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10789 RTE_ETH_FILTER_GET, &info); 10790 10791 if (ret < 0) { 10792 printf("Cannot get symmetric hash enable per port " 10793 "on port %u\n", res->port_id); 10794 return; 10795 } 10796 10797 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 10798 "enabled" : "disabled", res->port_id); 10799 } 10800 10801 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 10802 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 10803 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 10804 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 10805 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 10806 port_id, UINT8); 10807 10808 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 10809 .f = cmd_get_sym_hash_per_port_parsed, 10810 .data = NULL, 10811 .help_str = "get_sym_hash_ena_per_port <port_id>", 10812 .tokens = { 10813 (void *)&cmd_get_sym_hash_ena_per_port_all, 10814 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 10815 NULL, 10816 }, 10817 }; 10818 10819 /* *** Set symmetric hash enable per port *** */ 10820 struct cmd_set_sym_hash_ena_per_port_result { 10821 cmdline_fixed_string_t set_sym_hash_ena_per_port; 10822 cmdline_fixed_string_t enable; 10823 uint8_t port_id; 10824 }; 10825 10826 static void 10827 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 10828 __rte_unused struct cmdline *cl, 10829 __rte_unused void *data) 10830 { 10831 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 10832 struct rte_eth_hash_filter_info info; 10833 int ret; 10834 10835 if (rte_eth_dev_filter_supported(res->port_id, 10836 RTE_ETH_FILTER_HASH) < 0) { 10837 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 10838 res->port_id); 10839 return; 10840 } 10841 10842 memset(&info, 0, sizeof(info)); 10843 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 10844 if (!strcmp(res->enable, "enable")) 10845 info.info.enable = 1; 10846 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10847 RTE_ETH_FILTER_SET, &info); 10848 if (ret < 0) { 10849 printf("Cannot set symmetric hash enable per port on " 10850 "port %u\n", res->port_id); 10851 return; 10852 } 10853 printf("Symmetric hash has been set to %s on port %u\n", 10854 res->enable, res->port_id); 10855 } 10856 10857 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 10858 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10859 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 10860 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 10861 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10862 port_id, UINT8); 10863 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 10864 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 10865 enable, "enable#disable"); 10866 10867 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 10868 .f = cmd_set_sym_hash_per_port_parsed, 10869 .data = NULL, 10870 .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable", 10871 .tokens = { 10872 (void *)&cmd_set_sym_hash_ena_per_port_all, 10873 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 10874 (void *)&cmd_set_sym_hash_ena_per_port_enable, 10875 NULL, 10876 }, 10877 }; 10878 10879 /* Get global config of hash function */ 10880 struct cmd_get_hash_global_config_result { 10881 cmdline_fixed_string_t get_hash_global_config; 10882 uint8_t port_id; 10883 }; 10884 10885 static char * 10886 flowtype_to_str(uint16_t ftype) 10887 { 10888 uint16_t i; 10889 static struct { 10890 char str[16]; 10891 uint16_t ftype; 10892 } ftype_table[] = { 10893 {"ipv4", RTE_ETH_FLOW_IPV4}, 10894 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 10895 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 10896 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 10897 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 10898 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 10899 {"ipv6", RTE_ETH_FLOW_IPV6}, 10900 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 10901 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 10902 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 10903 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 10904 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 10905 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 10906 {"port", RTE_ETH_FLOW_PORT}, 10907 {"vxlan", RTE_ETH_FLOW_VXLAN}, 10908 {"geneve", RTE_ETH_FLOW_GENEVE}, 10909 {"nvgre", RTE_ETH_FLOW_NVGRE}, 10910 }; 10911 10912 for (i = 0; i < RTE_DIM(ftype_table); i++) { 10913 if (ftype_table[i].ftype == ftype) 10914 return ftype_table[i].str; 10915 } 10916 10917 return NULL; 10918 } 10919 10920 static void 10921 cmd_get_hash_global_config_parsed(void *parsed_result, 10922 __rte_unused struct cmdline *cl, 10923 __rte_unused void *data) 10924 { 10925 struct cmd_get_hash_global_config_result *res = parsed_result; 10926 struct rte_eth_hash_filter_info info; 10927 uint32_t idx, offset; 10928 uint16_t i; 10929 char *str; 10930 int ret; 10931 10932 if (rte_eth_dev_filter_supported(res->port_id, 10933 RTE_ETH_FILTER_HASH) < 0) { 10934 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 10935 res->port_id); 10936 return; 10937 } 10938 10939 memset(&info, 0, sizeof(info)); 10940 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 10941 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 10942 RTE_ETH_FILTER_GET, &info); 10943 if (ret < 0) { 10944 printf("Cannot get hash global configurations by port %d\n", 10945 res->port_id); 10946 return; 10947 } 10948 10949 switch (info.info.global_conf.hash_func) { 10950 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 10951 printf("Hash function is Toeplitz\n"); 10952 break; 10953 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 10954 printf("Hash function is Simple XOR\n"); 10955 break; 10956 default: 10957 printf("Unknown hash function\n"); 10958 break; 10959 } 10960 10961 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 10962 idx = i / UINT32_BIT; 10963 offset = i % UINT32_BIT; 10964 if (!(info.info.global_conf.valid_bit_mask[idx] & 10965 (1UL << offset))) 10966 continue; 10967 str = flowtype_to_str(i); 10968 if (!str) 10969 continue; 10970 printf("Symmetric hash is %s globally for flow type %s " 10971 "by port %d\n", 10972 ((info.info.global_conf.sym_hash_enable_mask[idx] & 10973 (1UL << offset)) ? "enabled" : "disabled"), str, 10974 res->port_id); 10975 } 10976 } 10977 10978 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 10979 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 10980 get_hash_global_config, "get_hash_global_config"); 10981 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 10982 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 10983 port_id, UINT8); 10984 10985 cmdline_parse_inst_t cmd_get_hash_global_config = { 10986 .f = cmd_get_hash_global_config_parsed, 10987 .data = NULL, 10988 .help_str = "get_hash_global_config <port_id>", 10989 .tokens = { 10990 (void *)&cmd_get_hash_global_config_all, 10991 (void *)&cmd_get_hash_global_config_port_id, 10992 NULL, 10993 }, 10994 }; 10995 10996 /* Set global config of hash function */ 10997 struct cmd_set_hash_global_config_result { 10998 cmdline_fixed_string_t set_hash_global_config; 10999 uint8_t port_id; 11000 cmdline_fixed_string_t hash_func; 11001 cmdline_fixed_string_t flow_type; 11002 cmdline_fixed_string_t enable; 11003 }; 11004 11005 static void 11006 cmd_set_hash_global_config_parsed(void *parsed_result, 11007 __rte_unused struct cmdline *cl, 11008 __rte_unused void *data) 11009 { 11010 struct cmd_set_hash_global_config_result *res = parsed_result; 11011 struct rte_eth_hash_filter_info info; 11012 uint32_t ftype, idx, offset; 11013 int ret; 11014 11015 if (rte_eth_dev_filter_supported(res->port_id, 11016 RTE_ETH_FILTER_HASH) < 0) { 11017 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 11018 res->port_id); 11019 return; 11020 } 11021 memset(&info, 0, sizeof(info)); 11022 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 11023 if (!strcmp(res->hash_func, "toeplitz")) 11024 info.info.global_conf.hash_func = 11025 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 11026 else if (!strcmp(res->hash_func, "simple_xor")) 11027 info.info.global_conf.hash_func = 11028 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 11029 else if (!strcmp(res->hash_func, "default")) 11030 info.info.global_conf.hash_func = 11031 RTE_ETH_HASH_FUNCTION_DEFAULT; 11032 11033 ftype = str2flowtype(res->flow_type); 11034 idx = ftype / (CHAR_BIT * sizeof(uint32_t)); 11035 offset = ftype % (CHAR_BIT * sizeof(uint32_t)); 11036 info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset); 11037 if (!strcmp(res->enable, "enable")) 11038 info.info.global_conf.sym_hash_enable_mask[idx] |= 11039 (1UL << offset); 11040 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11041 RTE_ETH_FILTER_SET, &info); 11042 if (ret < 0) 11043 printf("Cannot set global hash configurations by port %d\n", 11044 res->port_id); 11045 else 11046 printf("Global hash configurations have been set " 11047 "succcessfully by port %d\n", res->port_id); 11048 } 11049 11050 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 11051 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11052 set_hash_global_config, "set_hash_global_config"); 11053 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 11054 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 11055 port_id, UINT8); 11056 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 11057 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11058 hash_func, "toeplitz#simple_xor#default"); 11059 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 11060 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11061 flow_type, 11062 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 11063 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 11064 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 11065 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11066 enable, "enable#disable"); 11067 11068 cmdline_parse_inst_t cmd_set_hash_global_config = { 11069 .f = cmd_set_hash_global_config_parsed, 11070 .data = NULL, 11071 .help_str = "set_hash_global_config <port_id> " 11072 "toeplitz|simple_xor|default " 11073 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11074 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 11075 "l2_payload enable|disable", 11076 .tokens = { 11077 (void *)&cmd_set_hash_global_config_all, 11078 (void *)&cmd_set_hash_global_config_port_id, 11079 (void *)&cmd_set_hash_global_config_hash_func, 11080 (void *)&cmd_set_hash_global_config_flow_type, 11081 (void *)&cmd_set_hash_global_config_enable, 11082 NULL, 11083 }, 11084 }; 11085 11086 /* Set hash input set */ 11087 struct cmd_set_hash_input_set_result { 11088 cmdline_fixed_string_t set_hash_input_set; 11089 uint8_t port_id; 11090 cmdline_fixed_string_t flow_type; 11091 cmdline_fixed_string_t inset_field; 11092 cmdline_fixed_string_t select; 11093 }; 11094 11095 static enum rte_eth_input_set_field 11096 str2inset(char *string) 11097 { 11098 uint16_t i; 11099 11100 static const struct { 11101 char str[32]; 11102 enum rte_eth_input_set_field inset; 11103 } inset_table[] = { 11104 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE}, 11105 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN}, 11106 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN}, 11107 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4}, 11108 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4}, 11109 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS}, 11110 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO}, 11111 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL}, 11112 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6}, 11113 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6}, 11114 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC}, 11115 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER}, 11116 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS}, 11117 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT}, 11118 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT}, 11119 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT}, 11120 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT}, 11121 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT}, 11122 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT}, 11123 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG}, 11124 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY}, 11125 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY}, 11126 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD}, 11127 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD}, 11128 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD}, 11129 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD}, 11130 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD}, 11131 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD}, 11132 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD}, 11133 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD}, 11134 {"none", RTE_ETH_INPUT_SET_NONE}, 11135 }; 11136 11137 for (i = 0; i < RTE_DIM(inset_table); i++) { 11138 if (!strcmp(string, inset_table[i].str)) 11139 return inset_table[i].inset; 11140 } 11141 11142 return RTE_ETH_INPUT_SET_UNKNOWN; 11143 } 11144 11145 static void 11146 cmd_set_hash_input_set_parsed(void *parsed_result, 11147 __rte_unused struct cmdline *cl, 11148 __rte_unused void *data) 11149 { 11150 struct cmd_set_hash_input_set_result *res = parsed_result; 11151 struct rte_eth_hash_filter_info info; 11152 11153 memset(&info, 0, sizeof(info)); 11154 info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; 11155 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 11156 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 11157 info.info.input_set_conf.inset_size = 1; 11158 if (!strcmp(res->select, "select")) 11159 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 11160 else if (!strcmp(res->select, "add")) 11161 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 11162 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11163 RTE_ETH_FILTER_SET, &info); 11164 } 11165 11166 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = 11167 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11168 set_hash_input_set, "set_hash_input_set"); 11169 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = 11170 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, 11171 port_id, UINT8); 11172 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = 11173 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11174 flow_type, NULL); 11175 cmdline_parse_token_string_t cmd_set_hash_input_set_field = 11176 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11177 inset_field, 11178 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 11179 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#" 11180 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#" 11181 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#" 11182 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#" 11183 "fld-8th#none"); 11184 cmdline_parse_token_string_t cmd_set_hash_input_set_select = 11185 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11186 select, "select#add"); 11187 11188 cmdline_parse_inst_t cmd_set_hash_input_set = { 11189 .f = cmd_set_hash_input_set_parsed, 11190 .data = NULL, 11191 .help_str = "set_hash_input_set <port_id> " 11192 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11193 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> " 11194 "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" 11195 "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" 11196 "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" 11197 "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|" 11198 "fld-7th|fld-8th|none select|add", 11199 .tokens = { 11200 (void *)&cmd_set_hash_input_set_cmd, 11201 (void *)&cmd_set_hash_input_set_port_id, 11202 (void *)&cmd_set_hash_input_set_flow_type, 11203 (void *)&cmd_set_hash_input_set_field, 11204 (void *)&cmd_set_hash_input_set_select, 11205 NULL, 11206 }, 11207 }; 11208 11209 /* Set flow director input set */ 11210 struct cmd_set_fdir_input_set_result { 11211 cmdline_fixed_string_t set_fdir_input_set; 11212 uint8_t port_id; 11213 cmdline_fixed_string_t flow_type; 11214 cmdline_fixed_string_t inset_field; 11215 cmdline_fixed_string_t select; 11216 }; 11217 11218 static void 11219 cmd_set_fdir_input_set_parsed(void *parsed_result, 11220 __rte_unused struct cmdline *cl, 11221 __rte_unused void *data) 11222 { 11223 struct cmd_set_fdir_input_set_result *res = parsed_result; 11224 struct rte_eth_fdir_filter_info info; 11225 11226 memset(&info, 0, sizeof(info)); 11227 info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT; 11228 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 11229 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 11230 info.info.input_set_conf.inset_size = 1; 11231 if (!strcmp(res->select, "select")) 11232 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 11233 else if (!strcmp(res->select, "add")) 11234 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 11235 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 11236 RTE_ETH_FILTER_SET, &info); 11237 } 11238 11239 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = 11240 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11241 set_fdir_input_set, "set_fdir_input_set"); 11242 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = 11243 TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, 11244 port_id, UINT8); 11245 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = 11246 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11247 flow_type, 11248 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 11249 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 11250 cmdline_parse_token_string_t cmd_set_fdir_input_set_field = 11251 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11252 inset_field, 11253 "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 11254 "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#" 11255 "ipv6-hop-limits#udp-src-port#udp-dst-port#" 11256 "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#" 11257 "sctp-veri-tag#none"); 11258 cmdline_parse_token_string_t cmd_set_fdir_input_set_select = 11259 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11260 select, "select#add"); 11261 11262 cmdline_parse_inst_t cmd_set_fdir_input_set = { 11263 .f = cmd_set_fdir_input_set_parsed, 11264 .data = NULL, 11265 .help_str = "set_fdir_input_set <port_id> " 11266 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11267 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 11268 "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|" 11269 "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|" 11270 "ipv6-hop-limits|udp-src-port|udp-dst-port|" 11271 "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|" 11272 "sctp-veri-tag|none select|add", 11273 .tokens = { 11274 (void *)&cmd_set_fdir_input_set_cmd, 11275 (void *)&cmd_set_fdir_input_set_port_id, 11276 (void *)&cmd_set_fdir_input_set_flow_type, 11277 (void *)&cmd_set_fdir_input_set_field, 11278 (void *)&cmd_set_fdir_input_set_select, 11279 NULL, 11280 }, 11281 }; 11282 11283 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 11284 struct cmd_mcast_addr_result { 11285 cmdline_fixed_string_t mcast_addr_cmd; 11286 cmdline_fixed_string_t what; 11287 uint8_t port_num; 11288 struct ether_addr mc_addr; 11289 }; 11290 11291 static void cmd_mcast_addr_parsed(void *parsed_result, 11292 __attribute__((unused)) struct cmdline *cl, 11293 __attribute__((unused)) void *data) 11294 { 11295 struct cmd_mcast_addr_result *res = parsed_result; 11296 11297 if (!is_multicast_ether_addr(&res->mc_addr)) { 11298 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n", 11299 res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1], 11300 res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3], 11301 res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]); 11302 return; 11303 } 11304 if (strcmp(res->what, "add") == 0) 11305 mcast_addr_add(res->port_num, &res->mc_addr); 11306 else 11307 mcast_addr_remove(res->port_num, &res->mc_addr); 11308 } 11309 11310 cmdline_parse_token_string_t cmd_mcast_addr_cmd = 11311 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 11312 mcast_addr_cmd, "mcast_addr"); 11313 cmdline_parse_token_string_t cmd_mcast_addr_what = 11314 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 11315 "add#remove"); 11316 cmdline_parse_token_num_t cmd_mcast_addr_portnum = 11317 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8); 11318 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 11319 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 11320 11321 cmdline_parse_inst_t cmd_mcast_addr = { 11322 .f = cmd_mcast_addr_parsed, 11323 .data = (void *)0, 11324 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 11325 "Add/Remove multicast MAC address on port_id", 11326 .tokens = { 11327 (void *)&cmd_mcast_addr_cmd, 11328 (void *)&cmd_mcast_addr_what, 11329 (void *)&cmd_mcast_addr_portnum, 11330 (void *)&cmd_mcast_addr_addr, 11331 NULL, 11332 }, 11333 }; 11334 11335 /* l2 tunnel config 11336 * only support E-tag now. 11337 */ 11338 11339 /* Ether type config */ 11340 struct cmd_config_l2_tunnel_eth_type_result { 11341 cmdline_fixed_string_t port; 11342 cmdline_fixed_string_t config; 11343 cmdline_fixed_string_t all; 11344 uint8_t id; 11345 cmdline_fixed_string_t l2_tunnel; 11346 cmdline_fixed_string_t l2_tunnel_type; 11347 cmdline_fixed_string_t eth_type; 11348 uint16_t eth_type_val; 11349 }; 11350 11351 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port = 11352 TOKEN_STRING_INITIALIZER 11353 (struct cmd_config_l2_tunnel_eth_type_result, 11354 port, "port"); 11355 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config = 11356 TOKEN_STRING_INITIALIZER 11357 (struct cmd_config_l2_tunnel_eth_type_result, 11358 config, "config"); 11359 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str = 11360 TOKEN_STRING_INITIALIZER 11361 (struct cmd_config_l2_tunnel_eth_type_result, 11362 all, "all"); 11363 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id = 11364 TOKEN_NUM_INITIALIZER 11365 (struct cmd_config_l2_tunnel_eth_type_result, 11366 id, UINT8); 11367 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel = 11368 TOKEN_STRING_INITIALIZER 11369 (struct cmd_config_l2_tunnel_eth_type_result, 11370 l2_tunnel, "l2-tunnel"); 11371 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type = 11372 TOKEN_STRING_INITIALIZER 11373 (struct cmd_config_l2_tunnel_eth_type_result, 11374 l2_tunnel_type, "E-tag"); 11375 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type = 11376 TOKEN_STRING_INITIALIZER 11377 (struct cmd_config_l2_tunnel_eth_type_result, 11378 eth_type, "ether-type"); 11379 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val = 11380 TOKEN_NUM_INITIALIZER 11381 (struct cmd_config_l2_tunnel_eth_type_result, 11382 eth_type_val, UINT16); 11383 11384 static enum rte_eth_tunnel_type 11385 str2fdir_l2_tunnel_type(char *string) 11386 { 11387 uint32_t i = 0; 11388 11389 static const struct { 11390 char str[32]; 11391 enum rte_eth_tunnel_type type; 11392 } l2_tunnel_type_str[] = { 11393 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG}, 11394 }; 11395 11396 for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) { 11397 if (!strcmp(l2_tunnel_type_str[i].str, string)) 11398 return l2_tunnel_type_str[i].type; 11399 } 11400 return RTE_TUNNEL_TYPE_NONE; 11401 } 11402 11403 /* ether type config for all ports */ 11404 static void 11405 cmd_config_l2_tunnel_eth_type_all_parsed 11406 (void *parsed_result, 11407 __attribute__((unused)) struct cmdline *cl, 11408 __attribute__((unused)) void *data) 11409 { 11410 struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result; 11411 struct rte_eth_l2_tunnel_conf entry; 11412 portid_t pid; 11413 11414 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11415 entry.ether_type = res->eth_type_val; 11416 11417 RTE_ETH_FOREACH_DEV(pid) { 11418 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry); 11419 } 11420 } 11421 11422 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = { 11423 .f = cmd_config_l2_tunnel_eth_type_all_parsed, 11424 .data = NULL, 11425 .help_str = "port config all l2-tunnel E-tag ether-type <value>", 11426 .tokens = { 11427 (void *)&cmd_config_l2_tunnel_eth_type_port, 11428 (void *)&cmd_config_l2_tunnel_eth_type_config, 11429 (void *)&cmd_config_l2_tunnel_eth_type_all_str, 11430 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 11431 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 11432 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 11433 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 11434 NULL, 11435 }, 11436 }; 11437 11438 /* ether type config for a specific port */ 11439 static void 11440 cmd_config_l2_tunnel_eth_type_specific_parsed( 11441 void *parsed_result, 11442 __attribute__((unused)) struct cmdline *cl, 11443 __attribute__((unused)) void *data) 11444 { 11445 struct cmd_config_l2_tunnel_eth_type_result *res = 11446 parsed_result; 11447 struct rte_eth_l2_tunnel_conf entry; 11448 11449 if (port_id_is_invalid(res->id, ENABLED_WARN)) 11450 return; 11451 11452 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11453 entry.ether_type = res->eth_type_val; 11454 11455 rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry); 11456 } 11457 11458 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = { 11459 .f = cmd_config_l2_tunnel_eth_type_specific_parsed, 11460 .data = NULL, 11461 .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>", 11462 .tokens = { 11463 (void *)&cmd_config_l2_tunnel_eth_type_port, 11464 (void *)&cmd_config_l2_tunnel_eth_type_config, 11465 (void *)&cmd_config_l2_tunnel_eth_type_id, 11466 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 11467 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 11468 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 11469 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 11470 NULL, 11471 }, 11472 }; 11473 11474 /* Enable/disable l2 tunnel */ 11475 struct cmd_config_l2_tunnel_en_dis_result { 11476 cmdline_fixed_string_t port; 11477 cmdline_fixed_string_t config; 11478 cmdline_fixed_string_t all; 11479 uint8_t id; 11480 cmdline_fixed_string_t l2_tunnel; 11481 cmdline_fixed_string_t l2_tunnel_type; 11482 cmdline_fixed_string_t en_dis; 11483 }; 11484 11485 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port = 11486 TOKEN_STRING_INITIALIZER 11487 (struct cmd_config_l2_tunnel_en_dis_result, 11488 port, "port"); 11489 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config = 11490 TOKEN_STRING_INITIALIZER 11491 (struct cmd_config_l2_tunnel_en_dis_result, 11492 config, "config"); 11493 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str = 11494 TOKEN_STRING_INITIALIZER 11495 (struct cmd_config_l2_tunnel_en_dis_result, 11496 all, "all"); 11497 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id = 11498 TOKEN_NUM_INITIALIZER 11499 (struct cmd_config_l2_tunnel_en_dis_result, 11500 id, UINT8); 11501 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel = 11502 TOKEN_STRING_INITIALIZER 11503 (struct cmd_config_l2_tunnel_en_dis_result, 11504 l2_tunnel, "l2-tunnel"); 11505 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type = 11506 TOKEN_STRING_INITIALIZER 11507 (struct cmd_config_l2_tunnel_en_dis_result, 11508 l2_tunnel_type, "E-tag"); 11509 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis = 11510 TOKEN_STRING_INITIALIZER 11511 (struct cmd_config_l2_tunnel_en_dis_result, 11512 en_dis, "enable#disable"); 11513 11514 /* enable/disable l2 tunnel for all ports */ 11515 static void 11516 cmd_config_l2_tunnel_en_dis_all_parsed( 11517 void *parsed_result, 11518 __attribute__((unused)) struct cmdline *cl, 11519 __attribute__((unused)) void *data) 11520 { 11521 struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result; 11522 struct rte_eth_l2_tunnel_conf entry; 11523 portid_t pid; 11524 uint8_t en; 11525 11526 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11527 11528 if (!strcmp("enable", res->en_dis)) 11529 en = 1; 11530 else 11531 en = 0; 11532 11533 RTE_ETH_FOREACH_DEV(pid) { 11534 rte_eth_dev_l2_tunnel_offload_set(pid, 11535 &entry, 11536 ETH_L2_TUNNEL_ENABLE_MASK, 11537 en); 11538 } 11539 } 11540 11541 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = { 11542 .f = cmd_config_l2_tunnel_en_dis_all_parsed, 11543 .data = NULL, 11544 .help_str = "port config all l2-tunnel E-tag enable|disable", 11545 .tokens = { 11546 (void *)&cmd_config_l2_tunnel_en_dis_port, 11547 (void *)&cmd_config_l2_tunnel_en_dis_config, 11548 (void *)&cmd_config_l2_tunnel_en_dis_all_str, 11549 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 11550 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 11551 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 11552 NULL, 11553 }, 11554 }; 11555 11556 /* enable/disable l2 tunnel for a port */ 11557 static void 11558 cmd_config_l2_tunnel_en_dis_specific_parsed( 11559 void *parsed_result, 11560 __attribute__((unused)) struct cmdline *cl, 11561 __attribute__((unused)) void *data) 11562 { 11563 struct cmd_config_l2_tunnel_en_dis_result *res = 11564 parsed_result; 11565 struct rte_eth_l2_tunnel_conf entry; 11566 11567 if (port_id_is_invalid(res->id, ENABLED_WARN)) 11568 return; 11569 11570 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11571 11572 if (!strcmp("enable", res->en_dis)) 11573 rte_eth_dev_l2_tunnel_offload_set(res->id, 11574 &entry, 11575 ETH_L2_TUNNEL_ENABLE_MASK, 11576 1); 11577 else 11578 rte_eth_dev_l2_tunnel_offload_set(res->id, 11579 &entry, 11580 ETH_L2_TUNNEL_ENABLE_MASK, 11581 0); 11582 } 11583 11584 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = { 11585 .f = cmd_config_l2_tunnel_en_dis_specific_parsed, 11586 .data = NULL, 11587 .help_str = "port config <port_id> l2-tunnel E-tag enable|disable", 11588 .tokens = { 11589 (void *)&cmd_config_l2_tunnel_en_dis_port, 11590 (void *)&cmd_config_l2_tunnel_en_dis_config, 11591 (void *)&cmd_config_l2_tunnel_en_dis_id, 11592 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 11593 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 11594 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 11595 NULL, 11596 }, 11597 }; 11598 11599 /* E-tag configuration */ 11600 11601 /* Common result structure for all E-tag configuration */ 11602 struct cmd_config_e_tag_result { 11603 cmdline_fixed_string_t e_tag; 11604 cmdline_fixed_string_t set; 11605 cmdline_fixed_string_t insertion; 11606 cmdline_fixed_string_t stripping; 11607 cmdline_fixed_string_t forwarding; 11608 cmdline_fixed_string_t filter; 11609 cmdline_fixed_string_t add; 11610 cmdline_fixed_string_t del; 11611 cmdline_fixed_string_t on; 11612 cmdline_fixed_string_t off; 11613 cmdline_fixed_string_t on_off; 11614 cmdline_fixed_string_t port_tag_id; 11615 uint32_t port_tag_id_val; 11616 cmdline_fixed_string_t e_tag_id; 11617 uint16_t e_tag_id_val; 11618 cmdline_fixed_string_t dst_pool; 11619 uint8_t dst_pool_val; 11620 cmdline_fixed_string_t port; 11621 uint8_t port_id; 11622 cmdline_fixed_string_t vf; 11623 uint8_t vf_id; 11624 }; 11625 11626 /* Common CLI fields for all E-tag configuration */ 11627 cmdline_parse_token_string_t cmd_config_e_tag_e_tag = 11628 TOKEN_STRING_INITIALIZER 11629 (struct cmd_config_e_tag_result, 11630 e_tag, "E-tag"); 11631 cmdline_parse_token_string_t cmd_config_e_tag_set = 11632 TOKEN_STRING_INITIALIZER 11633 (struct cmd_config_e_tag_result, 11634 set, "set"); 11635 cmdline_parse_token_string_t cmd_config_e_tag_insertion = 11636 TOKEN_STRING_INITIALIZER 11637 (struct cmd_config_e_tag_result, 11638 insertion, "insertion"); 11639 cmdline_parse_token_string_t cmd_config_e_tag_stripping = 11640 TOKEN_STRING_INITIALIZER 11641 (struct cmd_config_e_tag_result, 11642 stripping, "stripping"); 11643 cmdline_parse_token_string_t cmd_config_e_tag_forwarding = 11644 TOKEN_STRING_INITIALIZER 11645 (struct cmd_config_e_tag_result, 11646 forwarding, "forwarding"); 11647 cmdline_parse_token_string_t cmd_config_e_tag_filter = 11648 TOKEN_STRING_INITIALIZER 11649 (struct cmd_config_e_tag_result, 11650 filter, "filter"); 11651 cmdline_parse_token_string_t cmd_config_e_tag_add = 11652 TOKEN_STRING_INITIALIZER 11653 (struct cmd_config_e_tag_result, 11654 add, "add"); 11655 cmdline_parse_token_string_t cmd_config_e_tag_del = 11656 TOKEN_STRING_INITIALIZER 11657 (struct cmd_config_e_tag_result, 11658 del, "del"); 11659 cmdline_parse_token_string_t cmd_config_e_tag_on = 11660 TOKEN_STRING_INITIALIZER 11661 (struct cmd_config_e_tag_result, 11662 on, "on"); 11663 cmdline_parse_token_string_t cmd_config_e_tag_off = 11664 TOKEN_STRING_INITIALIZER 11665 (struct cmd_config_e_tag_result, 11666 off, "off"); 11667 cmdline_parse_token_string_t cmd_config_e_tag_on_off = 11668 TOKEN_STRING_INITIALIZER 11669 (struct cmd_config_e_tag_result, 11670 on_off, "on#off"); 11671 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id = 11672 TOKEN_STRING_INITIALIZER 11673 (struct cmd_config_e_tag_result, 11674 port_tag_id, "port-tag-id"); 11675 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val = 11676 TOKEN_NUM_INITIALIZER 11677 (struct cmd_config_e_tag_result, 11678 port_tag_id_val, UINT32); 11679 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id = 11680 TOKEN_STRING_INITIALIZER 11681 (struct cmd_config_e_tag_result, 11682 e_tag_id, "e-tag-id"); 11683 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val = 11684 TOKEN_NUM_INITIALIZER 11685 (struct cmd_config_e_tag_result, 11686 e_tag_id_val, UINT16); 11687 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool = 11688 TOKEN_STRING_INITIALIZER 11689 (struct cmd_config_e_tag_result, 11690 dst_pool, "dst-pool"); 11691 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val = 11692 TOKEN_NUM_INITIALIZER 11693 (struct cmd_config_e_tag_result, 11694 dst_pool_val, UINT8); 11695 cmdline_parse_token_string_t cmd_config_e_tag_port = 11696 TOKEN_STRING_INITIALIZER 11697 (struct cmd_config_e_tag_result, 11698 port, "port"); 11699 cmdline_parse_token_num_t cmd_config_e_tag_port_id = 11700 TOKEN_NUM_INITIALIZER 11701 (struct cmd_config_e_tag_result, 11702 port_id, UINT8); 11703 cmdline_parse_token_string_t cmd_config_e_tag_vf = 11704 TOKEN_STRING_INITIALIZER 11705 (struct cmd_config_e_tag_result, 11706 vf, "vf"); 11707 cmdline_parse_token_num_t cmd_config_e_tag_vf_id = 11708 TOKEN_NUM_INITIALIZER 11709 (struct cmd_config_e_tag_result, 11710 vf_id, UINT8); 11711 11712 /* E-tag insertion configuration */ 11713 static void 11714 cmd_config_e_tag_insertion_en_parsed( 11715 void *parsed_result, 11716 __attribute__((unused)) struct cmdline *cl, 11717 __attribute__((unused)) void *data) 11718 { 11719 struct cmd_config_e_tag_result *res = 11720 parsed_result; 11721 struct rte_eth_l2_tunnel_conf entry; 11722 11723 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11724 return; 11725 11726 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11727 entry.tunnel_id = res->port_tag_id_val; 11728 entry.vf_id = res->vf_id; 11729 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 11730 &entry, 11731 ETH_L2_TUNNEL_INSERTION_MASK, 11732 1); 11733 } 11734 11735 static void 11736 cmd_config_e_tag_insertion_dis_parsed( 11737 void *parsed_result, 11738 __attribute__((unused)) struct cmdline *cl, 11739 __attribute__((unused)) void *data) 11740 { 11741 struct cmd_config_e_tag_result *res = 11742 parsed_result; 11743 struct rte_eth_l2_tunnel_conf entry; 11744 11745 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11746 return; 11747 11748 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11749 entry.vf_id = res->vf_id; 11750 11751 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 11752 &entry, 11753 ETH_L2_TUNNEL_INSERTION_MASK, 11754 0); 11755 } 11756 11757 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = { 11758 .f = cmd_config_e_tag_insertion_en_parsed, 11759 .data = NULL, 11760 .help_str = "E-tag ... : E-tag insertion enable", 11761 .tokens = { 11762 (void *)&cmd_config_e_tag_e_tag, 11763 (void *)&cmd_config_e_tag_set, 11764 (void *)&cmd_config_e_tag_insertion, 11765 (void *)&cmd_config_e_tag_on, 11766 (void *)&cmd_config_e_tag_port_tag_id, 11767 (void *)&cmd_config_e_tag_port_tag_id_val, 11768 (void *)&cmd_config_e_tag_port, 11769 (void *)&cmd_config_e_tag_port_id, 11770 (void *)&cmd_config_e_tag_vf, 11771 (void *)&cmd_config_e_tag_vf_id, 11772 NULL, 11773 }, 11774 }; 11775 11776 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = { 11777 .f = cmd_config_e_tag_insertion_dis_parsed, 11778 .data = NULL, 11779 .help_str = "E-tag ... : E-tag insertion disable", 11780 .tokens = { 11781 (void *)&cmd_config_e_tag_e_tag, 11782 (void *)&cmd_config_e_tag_set, 11783 (void *)&cmd_config_e_tag_insertion, 11784 (void *)&cmd_config_e_tag_off, 11785 (void *)&cmd_config_e_tag_port, 11786 (void *)&cmd_config_e_tag_port_id, 11787 (void *)&cmd_config_e_tag_vf, 11788 (void *)&cmd_config_e_tag_vf_id, 11789 NULL, 11790 }, 11791 }; 11792 11793 /* E-tag stripping configuration */ 11794 static void 11795 cmd_config_e_tag_stripping_parsed( 11796 void *parsed_result, 11797 __attribute__((unused)) struct cmdline *cl, 11798 __attribute__((unused)) void *data) 11799 { 11800 struct cmd_config_e_tag_result *res = 11801 parsed_result; 11802 struct rte_eth_l2_tunnel_conf entry; 11803 11804 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11805 return; 11806 11807 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11808 11809 if (!strcmp(res->on_off, "on")) 11810 rte_eth_dev_l2_tunnel_offload_set 11811 (res->port_id, 11812 &entry, 11813 ETH_L2_TUNNEL_STRIPPING_MASK, 11814 1); 11815 else 11816 rte_eth_dev_l2_tunnel_offload_set 11817 (res->port_id, 11818 &entry, 11819 ETH_L2_TUNNEL_STRIPPING_MASK, 11820 0); 11821 } 11822 11823 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = { 11824 .f = cmd_config_e_tag_stripping_parsed, 11825 .data = NULL, 11826 .help_str = "E-tag ... : E-tag stripping enable/disable", 11827 .tokens = { 11828 (void *)&cmd_config_e_tag_e_tag, 11829 (void *)&cmd_config_e_tag_set, 11830 (void *)&cmd_config_e_tag_stripping, 11831 (void *)&cmd_config_e_tag_on_off, 11832 (void *)&cmd_config_e_tag_port, 11833 (void *)&cmd_config_e_tag_port_id, 11834 NULL, 11835 }, 11836 }; 11837 11838 /* E-tag forwarding configuration */ 11839 static void 11840 cmd_config_e_tag_forwarding_parsed( 11841 void *parsed_result, 11842 __attribute__((unused)) struct cmdline *cl, 11843 __attribute__((unused)) void *data) 11844 { 11845 struct cmd_config_e_tag_result *res = parsed_result; 11846 struct rte_eth_l2_tunnel_conf entry; 11847 11848 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11849 return; 11850 11851 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11852 11853 if (!strcmp(res->on_off, "on")) 11854 rte_eth_dev_l2_tunnel_offload_set 11855 (res->port_id, 11856 &entry, 11857 ETH_L2_TUNNEL_FORWARDING_MASK, 11858 1); 11859 else 11860 rte_eth_dev_l2_tunnel_offload_set 11861 (res->port_id, 11862 &entry, 11863 ETH_L2_TUNNEL_FORWARDING_MASK, 11864 0); 11865 } 11866 11867 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = { 11868 .f = cmd_config_e_tag_forwarding_parsed, 11869 .data = NULL, 11870 .help_str = "E-tag ... : E-tag forwarding enable/disable", 11871 .tokens = { 11872 (void *)&cmd_config_e_tag_e_tag, 11873 (void *)&cmd_config_e_tag_set, 11874 (void *)&cmd_config_e_tag_forwarding, 11875 (void *)&cmd_config_e_tag_on_off, 11876 (void *)&cmd_config_e_tag_port, 11877 (void *)&cmd_config_e_tag_port_id, 11878 NULL, 11879 }, 11880 }; 11881 11882 /* E-tag filter configuration */ 11883 static void 11884 cmd_config_e_tag_filter_add_parsed( 11885 void *parsed_result, 11886 __attribute__((unused)) struct cmdline *cl, 11887 __attribute__((unused)) void *data) 11888 { 11889 struct cmd_config_e_tag_result *res = parsed_result; 11890 struct rte_eth_l2_tunnel_conf entry; 11891 int ret = 0; 11892 11893 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11894 return; 11895 11896 if (res->e_tag_id_val > 0x3fff) { 11897 printf("e-tag-id must be equal or less than 0x3fff.\n"); 11898 return; 11899 } 11900 11901 ret = rte_eth_dev_filter_supported(res->port_id, 11902 RTE_ETH_FILTER_L2_TUNNEL); 11903 if (ret < 0) { 11904 printf("E-tag filter is not supported on port %u.\n", 11905 res->port_id); 11906 return; 11907 } 11908 11909 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11910 entry.tunnel_id = res->e_tag_id_val; 11911 entry.pool = res->dst_pool_val; 11912 11913 ret = rte_eth_dev_filter_ctrl(res->port_id, 11914 RTE_ETH_FILTER_L2_TUNNEL, 11915 RTE_ETH_FILTER_ADD, 11916 &entry); 11917 if (ret < 0) 11918 printf("E-tag filter programming error: (%s)\n", 11919 strerror(-ret)); 11920 } 11921 11922 cmdline_parse_inst_t cmd_config_e_tag_filter_add = { 11923 .f = cmd_config_e_tag_filter_add_parsed, 11924 .data = NULL, 11925 .help_str = "E-tag ... : E-tag filter add", 11926 .tokens = { 11927 (void *)&cmd_config_e_tag_e_tag, 11928 (void *)&cmd_config_e_tag_set, 11929 (void *)&cmd_config_e_tag_filter, 11930 (void *)&cmd_config_e_tag_add, 11931 (void *)&cmd_config_e_tag_e_tag_id, 11932 (void *)&cmd_config_e_tag_e_tag_id_val, 11933 (void *)&cmd_config_e_tag_dst_pool, 11934 (void *)&cmd_config_e_tag_dst_pool_val, 11935 (void *)&cmd_config_e_tag_port, 11936 (void *)&cmd_config_e_tag_port_id, 11937 NULL, 11938 }, 11939 }; 11940 11941 static void 11942 cmd_config_e_tag_filter_del_parsed( 11943 void *parsed_result, 11944 __attribute__((unused)) struct cmdline *cl, 11945 __attribute__((unused)) void *data) 11946 { 11947 struct cmd_config_e_tag_result *res = parsed_result; 11948 struct rte_eth_l2_tunnel_conf entry; 11949 int ret = 0; 11950 11951 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 11952 return; 11953 11954 if (res->e_tag_id_val > 0x3fff) { 11955 printf("e-tag-id must be less than 0x3fff.\n"); 11956 return; 11957 } 11958 11959 ret = rte_eth_dev_filter_supported(res->port_id, 11960 RTE_ETH_FILTER_L2_TUNNEL); 11961 if (ret < 0) { 11962 printf("E-tag filter is not supported on port %u.\n", 11963 res->port_id); 11964 return; 11965 } 11966 11967 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 11968 entry.tunnel_id = res->e_tag_id_val; 11969 11970 ret = rte_eth_dev_filter_ctrl(res->port_id, 11971 RTE_ETH_FILTER_L2_TUNNEL, 11972 RTE_ETH_FILTER_DELETE, 11973 &entry); 11974 if (ret < 0) 11975 printf("E-tag filter programming error: (%s)\n", 11976 strerror(-ret)); 11977 } 11978 11979 cmdline_parse_inst_t cmd_config_e_tag_filter_del = { 11980 .f = cmd_config_e_tag_filter_del_parsed, 11981 .data = NULL, 11982 .help_str = "E-tag ... : E-tag filter delete", 11983 .tokens = { 11984 (void *)&cmd_config_e_tag_e_tag, 11985 (void *)&cmd_config_e_tag_set, 11986 (void *)&cmd_config_e_tag_filter, 11987 (void *)&cmd_config_e_tag_del, 11988 (void *)&cmd_config_e_tag_e_tag_id, 11989 (void *)&cmd_config_e_tag_e_tag_id_val, 11990 (void *)&cmd_config_e_tag_port, 11991 (void *)&cmd_config_e_tag_port_id, 11992 NULL, 11993 }, 11994 }; 11995 11996 /* vf vlan anti spoof configuration */ 11997 11998 /* Common result structure for vf vlan anti spoof */ 11999 struct cmd_vf_vlan_anti_spoof_result { 12000 cmdline_fixed_string_t set; 12001 cmdline_fixed_string_t vf; 12002 cmdline_fixed_string_t vlan; 12003 cmdline_fixed_string_t antispoof; 12004 uint8_t port_id; 12005 uint32_t vf_id; 12006 cmdline_fixed_string_t on_off; 12007 }; 12008 12009 /* Common CLI fields for vf vlan anti spoof enable disable */ 12010 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 12011 TOKEN_STRING_INITIALIZER 12012 (struct cmd_vf_vlan_anti_spoof_result, 12013 set, "set"); 12014 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 12015 TOKEN_STRING_INITIALIZER 12016 (struct cmd_vf_vlan_anti_spoof_result, 12017 vf, "vf"); 12018 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 12019 TOKEN_STRING_INITIALIZER 12020 (struct cmd_vf_vlan_anti_spoof_result, 12021 vlan, "vlan"); 12022 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 12023 TOKEN_STRING_INITIALIZER 12024 (struct cmd_vf_vlan_anti_spoof_result, 12025 antispoof, "antispoof"); 12026 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 12027 TOKEN_NUM_INITIALIZER 12028 (struct cmd_vf_vlan_anti_spoof_result, 12029 port_id, UINT8); 12030 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 12031 TOKEN_NUM_INITIALIZER 12032 (struct cmd_vf_vlan_anti_spoof_result, 12033 vf_id, UINT32); 12034 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 12035 TOKEN_STRING_INITIALIZER 12036 (struct cmd_vf_vlan_anti_spoof_result, 12037 on_off, "on#off"); 12038 12039 static void 12040 cmd_set_vf_vlan_anti_spoof_parsed( 12041 void *parsed_result, 12042 __attribute__((unused)) struct cmdline *cl, 12043 __attribute__((unused)) void *data) 12044 { 12045 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 12046 int ret = -ENOTSUP; 12047 12048 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12049 12050 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12051 return; 12052 12053 #ifdef RTE_LIBRTE_IXGBE_PMD 12054 if (ret == -ENOTSUP) 12055 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 12056 res->vf_id, is_on); 12057 #endif 12058 #ifdef RTE_LIBRTE_I40E_PMD 12059 if (ret == -ENOTSUP) 12060 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 12061 res->vf_id, is_on); 12062 #endif 12063 #ifdef RTE_LIBRTE_BNXT_PMD 12064 if (ret == -ENOTSUP) 12065 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id, 12066 res->vf_id, is_on); 12067 #endif 12068 12069 switch (ret) { 12070 case 0: 12071 break; 12072 case -EINVAL: 12073 printf("invalid vf_id %d\n", res->vf_id); 12074 break; 12075 case -ENODEV: 12076 printf("invalid port_id %d\n", res->port_id); 12077 break; 12078 case -ENOTSUP: 12079 printf("function not implemented\n"); 12080 break; 12081 default: 12082 printf("programming error: (%s)\n", strerror(-ret)); 12083 } 12084 } 12085 12086 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 12087 .f = cmd_set_vf_vlan_anti_spoof_parsed, 12088 .data = NULL, 12089 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 12090 .tokens = { 12091 (void *)&cmd_vf_vlan_anti_spoof_set, 12092 (void *)&cmd_vf_vlan_anti_spoof_vf, 12093 (void *)&cmd_vf_vlan_anti_spoof_vlan, 12094 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 12095 (void *)&cmd_vf_vlan_anti_spoof_port_id, 12096 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 12097 (void *)&cmd_vf_vlan_anti_spoof_on_off, 12098 NULL, 12099 }, 12100 }; 12101 12102 /* vf mac anti spoof configuration */ 12103 12104 /* Common result structure for vf mac anti spoof */ 12105 struct cmd_vf_mac_anti_spoof_result { 12106 cmdline_fixed_string_t set; 12107 cmdline_fixed_string_t vf; 12108 cmdline_fixed_string_t mac; 12109 cmdline_fixed_string_t antispoof; 12110 uint8_t port_id; 12111 uint32_t vf_id; 12112 cmdline_fixed_string_t on_off; 12113 }; 12114 12115 /* Common CLI fields for vf mac anti spoof enable disable */ 12116 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 12117 TOKEN_STRING_INITIALIZER 12118 (struct cmd_vf_mac_anti_spoof_result, 12119 set, "set"); 12120 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 12121 TOKEN_STRING_INITIALIZER 12122 (struct cmd_vf_mac_anti_spoof_result, 12123 vf, "vf"); 12124 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 12125 TOKEN_STRING_INITIALIZER 12126 (struct cmd_vf_mac_anti_spoof_result, 12127 mac, "mac"); 12128 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 12129 TOKEN_STRING_INITIALIZER 12130 (struct cmd_vf_mac_anti_spoof_result, 12131 antispoof, "antispoof"); 12132 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 12133 TOKEN_NUM_INITIALIZER 12134 (struct cmd_vf_mac_anti_spoof_result, 12135 port_id, UINT8); 12136 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 12137 TOKEN_NUM_INITIALIZER 12138 (struct cmd_vf_mac_anti_spoof_result, 12139 vf_id, UINT32); 12140 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 12141 TOKEN_STRING_INITIALIZER 12142 (struct cmd_vf_mac_anti_spoof_result, 12143 on_off, "on#off"); 12144 12145 static void 12146 cmd_set_vf_mac_anti_spoof_parsed( 12147 void *parsed_result, 12148 __attribute__((unused)) struct cmdline *cl, 12149 __attribute__((unused)) void *data) 12150 { 12151 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 12152 int ret = -ENOTSUP; 12153 12154 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12155 12156 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12157 return; 12158 12159 #ifdef RTE_LIBRTE_IXGBE_PMD 12160 if (ret == -ENOTSUP) 12161 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 12162 res->vf_id, is_on); 12163 #endif 12164 #ifdef RTE_LIBRTE_I40E_PMD 12165 if (ret == -ENOTSUP) 12166 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 12167 res->vf_id, is_on); 12168 #endif 12169 #ifdef RTE_LIBRTE_BNXT_PMD 12170 if (ret == -ENOTSUP) 12171 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id, 12172 res->vf_id, is_on); 12173 #endif 12174 12175 switch (ret) { 12176 case 0: 12177 break; 12178 case -EINVAL: 12179 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12180 break; 12181 case -ENODEV: 12182 printf("invalid port_id %d\n", res->port_id); 12183 break; 12184 case -ENOTSUP: 12185 printf("function not implemented\n"); 12186 break; 12187 default: 12188 printf("programming error: (%s)\n", strerror(-ret)); 12189 } 12190 } 12191 12192 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 12193 .f = cmd_set_vf_mac_anti_spoof_parsed, 12194 .data = NULL, 12195 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 12196 .tokens = { 12197 (void *)&cmd_vf_mac_anti_spoof_set, 12198 (void *)&cmd_vf_mac_anti_spoof_vf, 12199 (void *)&cmd_vf_mac_anti_spoof_mac, 12200 (void *)&cmd_vf_mac_anti_spoof_antispoof, 12201 (void *)&cmd_vf_mac_anti_spoof_port_id, 12202 (void *)&cmd_vf_mac_anti_spoof_vf_id, 12203 (void *)&cmd_vf_mac_anti_spoof_on_off, 12204 NULL, 12205 }, 12206 }; 12207 12208 /* vf vlan strip queue configuration */ 12209 12210 /* Common result structure for vf mac anti spoof */ 12211 struct cmd_vf_vlan_stripq_result { 12212 cmdline_fixed_string_t set; 12213 cmdline_fixed_string_t vf; 12214 cmdline_fixed_string_t vlan; 12215 cmdline_fixed_string_t stripq; 12216 portid_t port_id; 12217 uint16_t vf_id; 12218 cmdline_fixed_string_t on_off; 12219 }; 12220 12221 /* Common CLI fields for vf vlan strip enable disable */ 12222 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 12223 TOKEN_STRING_INITIALIZER 12224 (struct cmd_vf_vlan_stripq_result, 12225 set, "set"); 12226 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 12227 TOKEN_STRING_INITIALIZER 12228 (struct cmd_vf_vlan_stripq_result, 12229 vf, "vf"); 12230 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 12231 TOKEN_STRING_INITIALIZER 12232 (struct cmd_vf_vlan_stripq_result, 12233 vlan, "vlan"); 12234 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 12235 TOKEN_STRING_INITIALIZER 12236 (struct cmd_vf_vlan_stripq_result, 12237 stripq, "stripq"); 12238 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 12239 TOKEN_NUM_INITIALIZER 12240 (struct cmd_vf_vlan_stripq_result, 12241 port_id, UINT8); 12242 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 12243 TOKEN_NUM_INITIALIZER 12244 (struct cmd_vf_vlan_stripq_result, 12245 vf_id, UINT16); 12246 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 12247 TOKEN_STRING_INITIALIZER 12248 (struct cmd_vf_vlan_stripq_result, 12249 on_off, "on#off"); 12250 12251 static void 12252 cmd_set_vf_vlan_stripq_parsed( 12253 void *parsed_result, 12254 __attribute__((unused)) struct cmdline *cl, 12255 __attribute__((unused)) void *data) 12256 { 12257 struct cmd_vf_vlan_stripq_result *res = parsed_result; 12258 int ret = -ENOTSUP; 12259 12260 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12261 12262 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12263 return; 12264 12265 #ifdef RTE_LIBRTE_IXGBE_PMD 12266 if (ret == -ENOTSUP) 12267 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 12268 res->vf_id, is_on); 12269 #endif 12270 #ifdef RTE_LIBRTE_I40E_PMD 12271 if (ret == -ENOTSUP) 12272 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 12273 res->vf_id, is_on); 12274 #endif 12275 #ifdef RTE_LIBRTE_BNXT_PMD 12276 if (ret == -ENOTSUP) 12277 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id, 12278 res->vf_id, is_on); 12279 #endif 12280 12281 switch (ret) { 12282 case 0: 12283 break; 12284 case -EINVAL: 12285 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12286 break; 12287 case -ENODEV: 12288 printf("invalid port_id %d\n", res->port_id); 12289 break; 12290 case -ENOTSUP: 12291 printf("function not implemented\n"); 12292 break; 12293 default: 12294 printf("programming error: (%s)\n", strerror(-ret)); 12295 } 12296 } 12297 12298 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 12299 .f = cmd_set_vf_vlan_stripq_parsed, 12300 .data = NULL, 12301 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 12302 .tokens = { 12303 (void *)&cmd_vf_vlan_stripq_set, 12304 (void *)&cmd_vf_vlan_stripq_vf, 12305 (void *)&cmd_vf_vlan_stripq_vlan, 12306 (void *)&cmd_vf_vlan_stripq_stripq, 12307 (void *)&cmd_vf_vlan_stripq_port_id, 12308 (void *)&cmd_vf_vlan_stripq_vf_id, 12309 (void *)&cmd_vf_vlan_stripq_on_off, 12310 NULL, 12311 }, 12312 }; 12313 12314 /* vf vlan insert configuration */ 12315 12316 /* Common result structure for vf vlan insert */ 12317 struct cmd_vf_vlan_insert_result { 12318 cmdline_fixed_string_t set; 12319 cmdline_fixed_string_t vf; 12320 cmdline_fixed_string_t vlan; 12321 cmdline_fixed_string_t insert; 12322 uint8_t port_id; 12323 uint16_t vf_id; 12324 uint16_t vlan_id; 12325 }; 12326 12327 /* Common CLI fields for vf vlan insert enable disable */ 12328 cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 12329 TOKEN_STRING_INITIALIZER 12330 (struct cmd_vf_vlan_insert_result, 12331 set, "set"); 12332 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 12333 TOKEN_STRING_INITIALIZER 12334 (struct cmd_vf_vlan_insert_result, 12335 vf, "vf"); 12336 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 12337 TOKEN_STRING_INITIALIZER 12338 (struct cmd_vf_vlan_insert_result, 12339 vlan, "vlan"); 12340 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 12341 TOKEN_STRING_INITIALIZER 12342 (struct cmd_vf_vlan_insert_result, 12343 insert, "insert"); 12344 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 12345 TOKEN_NUM_INITIALIZER 12346 (struct cmd_vf_vlan_insert_result, 12347 port_id, UINT8); 12348 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 12349 TOKEN_NUM_INITIALIZER 12350 (struct cmd_vf_vlan_insert_result, 12351 vf_id, UINT16); 12352 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 12353 TOKEN_NUM_INITIALIZER 12354 (struct cmd_vf_vlan_insert_result, 12355 vlan_id, UINT16); 12356 12357 static void 12358 cmd_set_vf_vlan_insert_parsed( 12359 void *parsed_result, 12360 __attribute__((unused)) struct cmdline *cl, 12361 __attribute__((unused)) void *data) 12362 { 12363 struct cmd_vf_vlan_insert_result *res = parsed_result; 12364 int ret = -ENOTSUP; 12365 12366 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12367 return; 12368 12369 #ifdef RTE_LIBRTE_IXGBE_PMD 12370 if (ret == -ENOTSUP) 12371 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 12372 res->vlan_id); 12373 #endif 12374 #ifdef RTE_LIBRTE_I40E_PMD 12375 if (ret == -ENOTSUP) 12376 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 12377 res->vlan_id); 12378 #endif 12379 #ifdef RTE_LIBRTE_BNXT_PMD 12380 if (ret == -ENOTSUP) 12381 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id, 12382 res->vlan_id); 12383 #endif 12384 12385 switch (ret) { 12386 case 0: 12387 break; 12388 case -EINVAL: 12389 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id); 12390 break; 12391 case -ENODEV: 12392 printf("invalid port_id %d\n", res->port_id); 12393 break; 12394 case -ENOTSUP: 12395 printf("function not implemented\n"); 12396 break; 12397 default: 12398 printf("programming error: (%s)\n", strerror(-ret)); 12399 } 12400 } 12401 12402 cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 12403 .f = cmd_set_vf_vlan_insert_parsed, 12404 .data = NULL, 12405 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 12406 .tokens = { 12407 (void *)&cmd_vf_vlan_insert_set, 12408 (void *)&cmd_vf_vlan_insert_vf, 12409 (void *)&cmd_vf_vlan_insert_vlan, 12410 (void *)&cmd_vf_vlan_insert_insert, 12411 (void *)&cmd_vf_vlan_insert_port_id, 12412 (void *)&cmd_vf_vlan_insert_vf_id, 12413 (void *)&cmd_vf_vlan_insert_vlan_id, 12414 NULL, 12415 }, 12416 }; 12417 12418 /* tx loopback configuration */ 12419 12420 /* Common result structure for tx loopback */ 12421 struct cmd_tx_loopback_result { 12422 cmdline_fixed_string_t set; 12423 cmdline_fixed_string_t tx; 12424 cmdline_fixed_string_t loopback; 12425 uint8_t port_id; 12426 cmdline_fixed_string_t on_off; 12427 }; 12428 12429 /* Common CLI fields for tx loopback enable disable */ 12430 cmdline_parse_token_string_t cmd_tx_loopback_set = 12431 TOKEN_STRING_INITIALIZER 12432 (struct cmd_tx_loopback_result, 12433 set, "set"); 12434 cmdline_parse_token_string_t cmd_tx_loopback_tx = 12435 TOKEN_STRING_INITIALIZER 12436 (struct cmd_tx_loopback_result, 12437 tx, "tx"); 12438 cmdline_parse_token_string_t cmd_tx_loopback_loopback = 12439 TOKEN_STRING_INITIALIZER 12440 (struct cmd_tx_loopback_result, 12441 loopback, "loopback"); 12442 cmdline_parse_token_num_t cmd_tx_loopback_port_id = 12443 TOKEN_NUM_INITIALIZER 12444 (struct cmd_tx_loopback_result, 12445 port_id, UINT8); 12446 cmdline_parse_token_string_t cmd_tx_loopback_on_off = 12447 TOKEN_STRING_INITIALIZER 12448 (struct cmd_tx_loopback_result, 12449 on_off, "on#off"); 12450 12451 static void 12452 cmd_set_tx_loopback_parsed( 12453 void *parsed_result, 12454 __attribute__((unused)) struct cmdline *cl, 12455 __attribute__((unused)) void *data) 12456 { 12457 struct cmd_tx_loopback_result *res = parsed_result; 12458 int ret = -ENOTSUP; 12459 12460 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12461 12462 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12463 return; 12464 12465 #ifdef RTE_LIBRTE_IXGBE_PMD 12466 if (ret == -ENOTSUP) 12467 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 12468 #endif 12469 #ifdef RTE_LIBRTE_I40E_PMD 12470 if (ret == -ENOTSUP) 12471 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 12472 #endif 12473 #ifdef RTE_LIBRTE_BNXT_PMD 12474 if (ret == -ENOTSUP) 12475 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on); 12476 #endif 12477 12478 switch (ret) { 12479 case 0: 12480 break; 12481 case -EINVAL: 12482 printf("invalid is_on %d\n", is_on); 12483 break; 12484 case -ENODEV: 12485 printf("invalid port_id %d\n", res->port_id); 12486 break; 12487 case -ENOTSUP: 12488 printf("function not implemented\n"); 12489 break; 12490 default: 12491 printf("programming error: (%s)\n", strerror(-ret)); 12492 } 12493 } 12494 12495 cmdline_parse_inst_t cmd_set_tx_loopback = { 12496 .f = cmd_set_tx_loopback_parsed, 12497 .data = NULL, 12498 .help_str = "set tx loopback <port_id> on|off", 12499 .tokens = { 12500 (void *)&cmd_tx_loopback_set, 12501 (void *)&cmd_tx_loopback_tx, 12502 (void *)&cmd_tx_loopback_loopback, 12503 (void *)&cmd_tx_loopback_port_id, 12504 (void *)&cmd_tx_loopback_on_off, 12505 NULL, 12506 }, 12507 }; 12508 12509 /* all queues drop enable configuration */ 12510 12511 /* Common result structure for all queues drop enable */ 12512 struct cmd_all_queues_drop_en_result { 12513 cmdline_fixed_string_t set; 12514 cmdline_fixed_string_t all; 12515 cmdline_fixed_string_t queues; 12516 cmdline_fixed_string_t drop; 12517 uint8_t port_id; 12518 cmdline_fixed_string_t on_off; 12519 }; 12520 12521 /* Common CLI fields for tx loopback enable disable */ 12522 cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 12523 TOKEN_STRING_INITIALIZER 12524 (struct cmd_all_queues_drop_en_result, 12525 set, "set"); 12526 cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 12527 TOKEN_STRING_INITIALIZER 12528 (struct cmd_all_queues_drop_en_result, 12529 all, "all"); 12530 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 12531 TOKEN_STRING_INITIALIZER 12532 (struct cmd_all_queues_drop_en_result, 12533 queues, "queues"); 12534 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 12535 TOKEN_STRING_INITIALIZER 12536 (struct cmd_all_queues_drop_en_result, 12537 drop, "drop"); 12538 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 12539 TOKEN_NUM_INITIALIZER 12540 (struct cmd_all_queues_drop_en_result, 12541 port_id, UINT8); 12542 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 12543 TOKEN_STRING_INITIALIZER 12544 (struct cmd_all_queues_drop_en_result, 12545 on_off, "on#off"); 12546 12547 static void 12548 cmd_set_all_queues_drop_en_parsed( 12549 void *parsed_result, 12550 __attribute__((unused)) struct cmdline *cl, 12551 __attribute__((unused)) void *data) 12552 { 12553 struct cmd_all_queues_drop_en_result *res = parsed_result; 12554 int ret = -ENOTSUP; 12555 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12556 12557 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12558 return; 12559 12560 #ifdef RTE_LIBRTE_IXGBE_PMD 12561 if (ret == -ENOTSUP) 12562 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 12563 #endif 12564 #ifdef RTE_LIBRTE_BNXT_PMD 12565 if (ret == -ENOTSUP) 12566 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on); 12567 #endif 12568 switch (ret) { 12569 case 0: 12570 break; 12571 case -EINVAL: 12572 printf("invalid is_on %d\n", is_on); 12573 break; 12574 case -ENODEV: 12575 printf("invalid port_id %d\n", res->port_id); 12576 break; 12577 case -ENOTSUP: 12578 printf("function not implemented\n"); 12579 break; 12580 default: 12581 printf("programming error: (%s)\n", strerror(-ret)); 12582 } 12583 } 12584 12585 cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 12586 .f = cmd_set_all_queues_drop_en_parsed, 12587 .data = NULL, 12588 .help_str = "set all queues drop <port_id> on|off", 12589 .tokens = { 12590 (void *)&cmd_all_queues_drop_en_set, 12591 (void *)&cmd_all_queues_drop_en_all, 12592 (void *)&cmd_all_queues_drop_en_queues, 12593 (void *)&cmd_all_queues_drop_en_drop, 12594 (void *)&cmd_all_queues_drop_en_port_id, 12595 (void *)&cmd_all_queues_drop_en_on_off, 12596 NULL, 12597 }, 12598 }; 12599 12600 /* vf split drop enable configuration */ 12601 12602 /* Common result structure for vf split drop enable */ 12603 struct cmd_vf_split_drop_en_result { 12604 cmdline_fixed_string_t set; 12605 cmdline_fixed_string_t vf; 12606 cmdline_fixed_string_t split; 12607 cmdline_fixed_string_t drop; 12608 uint8_t port_id; 12609 uint16_t vf_id; 12610 cmdline_fixed_string_t on_off; 12611 }; 12612 12613 /* Common CLI fields for vf split drop enable disable */ 12614 cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 12615 TOKEN_STRING_INITIALIZER 12616 (struct cmd_vf_split_drop_en_result, 12617 set, "set"); 12618 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 12619 TOKEN_STRING_INITIALIZER 12620 (struct cmd_vf_split_drop_en_result, 12621 vf, "vf"); 12622 cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 12623 TOKEN_STRING_INITIALIZER 12624 (struct cmd_vf_split_drop_en_result, 12625 split, "split"); 12626 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 12627 TOKEN_STRING_INITIALIZER 12628 (struct cmd_vf_split_drop_en_result, 12629 drop, "drop"); 12630 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 12631 TOKEN_NUM_INITIALIZER 12632 (struct cmd_vf_split_drop_en_result, 12633 port_id, UINT8); 12634 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 12635 TOKEN_NUM_INITIALIZER 12636 (struct cmd_vf_split_drop_en_result, 12637 vf_id, UINT16); 12638 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 12639 TOKEN_STRING_INITIALIZER 12640 (struct cmd_vf_split_drop_en_result, 12641 on_off, "on#off"); 12642 12643 static void 12644 cmd_set_vf_split_drop_en_parsed( 12645 void *parsed_result, 12646 __attribute__((unused)) struct cmdline *cl, 12647 __attribute__((unused)) void *data) 12648 { 12649 struct cmd_vf_split_drop_en_result *res = parsed_result; 12650 int ret = -ENOTSUP; 12651 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12652 12653 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12654 return; 12655 12656 #ifdef RTE_LIBRTE_IXGBE_PMD 12657 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 12658 is_on); 12659 #endif 12660 switch (ret) { 12661 case 0: 12662 break; 12663 case -EINVAL: 12664 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12665 break; 12666 case -ENODEV: 12667 printf("invalid port_id %d\n", res->port_id); 12668 break; 12669 case -ENOTSUP: 12670 printf("not supported on port %d\n", res->port_id); 12671 break; 12672 default: 12673 printf("programming error: (%s)\n", strerror(-ret)); 12674 } 12675 } 12676 12677 cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 12678 .f = cmd_set_vf_split_drop_en_parsed, 12679 .data = NULL, 12680 .help_str = "set vf split drop <port_id> <vf_id> on|off", 12681 .tokens = { 12682 (void *)&cmd_vf_split_drop_en_set, 12683 (void *)&cmd_vf_split_drop_en_vf, 12684 (void *)&cmd_vf_split_drop_en_split, 12685 (void *)&cmd_vf_split_drop_en_drop, 12686 (void *)&cmd_vf_split_drop_en_port_id, 12687 (void *)&cmd_vf_split_drop_en_vf_id, 12688 (void *)&cmd_vf_split_drop_en_on_off, 12689 NULL, 12690 }, 12691 }; 12692 12693 /* vf mac address configuration */ 12694 12695 /* Common result structure for vf mac address */ 12696 struct cmd_set_vf_mac_addr_result { 12697 cmdline_fixed_string_t set; 12698 cmdline_fixed_string_t vf; 12699 cmdline_fixed_string_t mac; 12700 cmdline_fixed_string_t addr; 12701 uint8_t port_id; 12702 uint16_t vf_id; 12703 struct ether_addr mac_addr; 12704 12705 }; 12706 12707 /* Common CLI fields for vf split drop enable disable */ 12708 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 12709 TOKEN_STRING_INITIALIZER 12710 (struct cmd_set_vf_mac_addr_result, 12711 set, "set"); 12712 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 12713 TOKEN_STRING_INITIALIZER 12714 (struct cmd_set_vf_mac_addr_result, 12715 vf, "vf"); 12716 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 12717 TOKEN_STRING_INITIALIZER 12718 (struct cmd_set_vf_mac_addr_result, 12719 mac, "mac"); 12720 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 12721 TOKEN_STRING_INITIALIZER 12722 (struct cmd_set_vf_mac_addr_result, 12723 addr, "addr"); 12724 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 12725 TOKEN_NUM_INITIALIZER 12726 (struct cmd_set_vf_mac_addr_result, 12727 port_id, UINT8); 12728 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 12729 TOKEN_NUM_INITIALIZER 12730 (struct cmd_set_vf_mac_addr_result, 12731 vf_id, UINT16); 12732 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 12733 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 12734 mac_addr); 12735 12736 static void 12737 cmd_set_vf_mac_addr_parsed( 12738 void *parsed_result, 12739 __attribute__((unused)) struct cmdline *cl, 12740 __attribute__((unused)) void *data) 12741 { 12742 struct cmd_set_vf_mac_addr_result *res = parsed_result; 12743 int ret = -ENOTSUP; 12744 12745 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12746 return; 12747 12748 #ifdef RTE_LIBRTE_IXGBE_PMD 12749 if (ret == -ENOTSUP) 12750 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 12751 &res->mac_addr); 12752 #endif 12753 #ifdef RTE_LIBRTE_I40E_PMD 12754 if (ret == -ENOTSUP) 12755 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 12756 &res->mac_addr); 12757 #endif 12758 #ifdef RTE_LIBRTE_BNXT_PMD 12759 if (ret == -ENOTSUP) 12760 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id, 12761 &res->mac_addr); 12762 #endif 12763 12764 switch (ret) { 12765 case 0: 12766 break; 12767 case -EINVAL: 12768 printf("invalid vf_id %d or mac_addr\n", res->vf_id); 12769 break; 12770 case -ENODEV: 12771 printf("invalid port_id %d\n", res->port_id); 12772 break; 12773 case -ENOTSUP: 12774 printf("function not implemented\n"); 12775 break; 12776 default: 12777 printf("programming error: (%s)\n", strerror(-ret)); 12778 } 12779 } 12780 12781 cmdline_parse_inst_t cmd_set_vf_mac_addr = { 12782 .f = cmd_set_vf_mac_addr_parsed, 12783 .data = NULL, 12784 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 12785 .tokens = { 12786 (void *)&cmd_set_vf_mac_addr_set, 12787 (void *)&cmd_set_vf_mac_addr_vf, 12788 (void *)&cmd_set_vf_mac_addr_mac, 12789 (void *)&cmd_set_vf_mac_addr_addr, 12790 (void *)&cmd_set_vf_mac_addr_port_id, 12791 (void *)&cmd_set_vf_mac_addr_vf_id, 12792 (void *)&cmd_set_vf_mac_addr_mac_addr, 12793 NULL, 12794 }, 12795 }; 12796 12797 /* MACsec configuration */ 12798 12799 /* Common result structure for MACsec offload enable */ 12800 struct cmd_macsec_offload_on_result { 12801 cmdline_fixed_string_t set; 12802 cmdline_fixed_string_t macsec; 12803 cmdline_fixed_string_t offload; 12804 uint8_t port_id; 12805 cmdline_fixed_string_t on; 12806 cmdline_fixed_string_t encrypt; 12807 cmdline_fixed_string_t en_on_off; 12808 cmdline_fixed_string_t replay_protect; 12809 cmdline_fixed_string_t rp_on_off; 12810 }; 12811 12812 /* Common CLI fields for MACsec offload disable */ 12813 cmdline_parse_token_string_t cmd_macsec_offload_on_set = 12814 TOKEN_STRING_INITIALIZER 12815 (struct cmd_macsec_offload_on_result, 12816 set, "set"); 12817 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 12818 TOKEN_STRING_INITIALIZER 12819 (struct cmd_macsec_offload_on_result, 12820 macsec, "macsec"); 12821 cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 12822 TOKEN_STRING_INITIALIZER 12823 (struct cmd_macsec_offload_on_result, 12824 offload, "offload"); 12825 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 12826 TOKEN_NUM_INITIALIZER 12827 (struct cmd_macsec_offload_on_result, 12828 port_id, UINT8); 12829 cmdline_parse_token_string_t cmd_macsec_offload_on_on = 12830 TOKEN_STRING_INITIALIZER 12831 (struct cmd_macsec_offload_on_result, 12832 on, "on"); 12833 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 12834 TOKEN_STRING_INITIALIZER 12835 (struct cmd_macsec_offload_on_result, 12836 encrypt, "encrypt"); 12837 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 12838 TOKEN_STRING_INITIALIZER 12839 (struct cmd_macsec_offload_on_result, 12840 en_on_off, "on#off"); 12841 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 12842 TOKEN_STRING_INITIALIZER 12843 (struct cmd_macsec_offload_on_result, 12844 replay_protect, "replay-protect"); 12845 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 12846 TOKEN_STRING_INITIALIZER 12847 (struct cmd_macsec_offload_on_result, 12848 rp_on_off, "on#off"); 12849 12850 static void 12851 cmd_set_macsec_offload_on_parsed( 12852 void *parsed_result, 12853 __attribute__((unused)) struct cmdline *cl, 12854 __attribute__((unused)) void *data) 12855 { 12856 struct cmd_macsec_offload_on_result *res = parsed_result; 12857 int ret = -ENOTSUP; 12858 portid_t port_id = res->port_id; 12859 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 12860 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 12861 12862 if (port_id_is_invalid(port_id, ENABLED_WARN)) 12863 return; 12864 12865 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC; 12866 #ifdef RTE_LIBRTE_IXGBE_PMD 12867 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 12868 #endif 12869 RTE_SET_USED(en); 12870 RTE_SET_USED(rp); 12871 12872 switch (ret) { 12873 case 0: 12874 break; 12875 case -ENODEV: 12876 printf("invalid port_id %d\n", port_id); 12877 break; 12878 case -ENOTSUP: 12879 printf("not supported on port %d\n", port_id); 12880 break; 12881 default: 12882 printf("programming error: (%s)\n", strerror(-ret)); 12883 } 12884 } 12885 12886 cmdline_parse_inst_t cmd_set_macsec_offload_on = { 12887 .f = cmd_set_macsec_offload_on_parsed, 12888 .data = NULL, 12889 .help_str = "set macsec offload <port_id> on " 12890 "encrypt on|off replay-protect on|off", 12891 .tokens = { 12892 (void *)&cmd_macsec_offload_on_set, 12893 (void *)&cmd_macsec_offload_on_macsec, 12894 (void *)&cmd_macsec_offload_on_offload, 12895 (void *)&cmd_macsec_offload_on_port_id, 12896 (void *)&cmd_macsec_offload_on_on, 12897 (void *)&cmd_macsec_offload_on_encrypt, 12898 (void *)&cmd_macsec_offload_on_en_on_off, 12899 (void *)&cmd_macsec_offload_on_replay_protect, 12900 (void *)&cmd_macsec_offload_on_rp_on_off, 12901 NULL, 12902 }, 12903 }; 12904 12905 /* Common result structure for MACsec offload disable */ 12906 struct cmd_macsec_offload_off_result { 12907 cmdline_fixed_string_t set; 12908 cmdline_fixed_string_t macsec; 12909 cmdline_fixed_string_t offload; 12910 uint8_t port_id; 12911 cmdline_fixed_string_t off; 12912 }; 12913 12914 /* Common CLI fields for MACsec offload disable */ 12915 cmdline_parse_token_string_t cmd_macsec_offload_off_set = 12916 TOKEN_STRING_INITIALIZER 12917 (struct cmd_macsec_offload_off_result, 12918 set, "set"); 12919 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 12920 TOKEN_STRING_INITIALIZER 12921 (struct cmd_macsec_offload_off_result, 12922 macsec, "macsec"); 12923 cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 12924 TOKEN_STRING_INITIALIZER 12925 (struct cmd_macsec_offload_off_result, 12926 offload, "offload"); 12927 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 12928 TOKEN_NUM_INITIALIZER 12929 (struct cmd_macsec_offload_off_result, 12930 port_id, UINT8); 12931 cmdline_parse_token_string_t cmd_macsec_offload_off_off = 12932 TOKEN_STRING_INITIALIZER 12933 (struct cmd_macsec_offload_off_result, 12934 off, "off"); 12935 12936 static void 12937 cmd_set_macsec_offload_off_parsed( 12938 void *parsed_result, 12939 __attribute__((unused)) struct cmdline *cl, 12940 __attribute__((unused)) void *data) 12941 { 12942 struct cmd_macsec_offload_off_result *res = parsed_result; 12943 int ret = -ENOTSUP; 12944 portid_t port_id = res->port_id; 12945 12946 if (port_id_is_invalid(port_id, ENABLED_WARN)) 12947 return; 12948 12949 ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC; 12950 #ifdef RTE_LIBRTE_IXGBE_PMD 12951 ret = rte_pmd_ixgbe_macsec_disable(port_id); 12952 #endif 12953 12954 switch (ret) { 12955 case 0: 12956 break; 12957 case -ENODEV: 12958 printf("invalid port_id %d\n", port_id); 12959 break; 12960 case -ENOTSUP: 12961 printf("not supported on port %d\n", port_id); 12962 break; 12963 default: 12964 printf("programming error: (%s)\n", strerror(-ret)); 12965 } 12966 } 12967 12968 cmdline_parse_inst_t cmd_set_macsec_offload_off = { 12969 .f = cmd_set_macsec_offload_off_parsed, 12970 .data = NULL, 12971 .help_str = "set macsec offload <port_id> off", 12972 .tokens = { 12973 (void *)&cmd_macsec_offload_off_set, 12974 (void *)&cmd_macsec_offload_off_macsec, 12975 (void *)&cmd_macsec_offload_off_offload, 12976 (void *)&cmd_macsec_offload_off_port_id, 12977 (void *)&cmd_macsec_offload_off_off, 12978 NULL, 12979 }, 12980 }; 12981 12982 /* Common result structure for MACsec secure connection configure */ 12983 struct cmd_macsec_sc_result { 12984 cmdline_fixed_string_t set; 12985 cmdline_fixed_string_t macsec; 12986 cmdline_fixed_string_t sc; 12987 cmdline_fixed_string_t tx_rx; 12988 uint8_t port_id; 12989 struct ether_addr mac; 12990 uint16_t pi; 12991 }; 12992 12993 /* Common CLI fields for MACsec secure connection configure */ 12994 cmdline_parse_token_string_t cmd_macsec_sc_set = 12995 TOKEN_STRING_INITIALIZER 12996 (struct cmd_macsec_sc_result, 12997 set, "set"); 12998 cmdline_parse_token_string_t cmd_macsec_sc_macsec = 12999 TOKEN_STRING_INITIALIZER 13000 (struct cmd_macsec_sc_result, 13001 macsec, "macsec"); 13002 cmdline_parse_token_string_t cmd_macsec_sc_sc = 13003 TOKEN_STRING_INITIALIZER 13004 (struct cmd_macsec_sc_result, 13005 sc, "sc"); 13006 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 13007 TOKEN_STRING_INITIALIZER 13008 (struct cmd_macsec_sc_result, 13009 tx_rx, "tx#rx"); 13010 cmdline_parse_token_num_t cmd_macsec_sc_port_id = 13011 TOKEN_NUM_INITIALIZER 13012 (struct cmd_macsec_sc_result, 13013 port_id, UINT8); 13014 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 13015 TOKEN_ETHERADDR_INITIALIZER 13016 (struct cmd_macsec_sc_result, 13017 mac); 13018 cmdline_parse_token_num_t cmd_macsec_sc_pi = 13019 TOKEN_NUM_INITIALIZER 13020 (struct cmd_macsec_sc_result, 13021 pi, UINT16); 13022 13023 static void 13024 cmd_set_macsec_sc_parsed( 13025 void *parsed_result, 13026 __attribute__((unused)) struct cmdline *cl, 13027 __attribute__((unused)) void *data) 13028 { 13029 struct cmd_macsec_sc_result *res = parsed_result; 13030 int ret = -ENOTSUP; 13031 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 13032 13033 #ifdef RTE_LIBRTE_IXGBE_PMD 13034 ret = is_tx ? 13035 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 13036 res->mac.addr_bytes) : 13037 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 13038 res->mac.addr_bytes, res->pi); 13039 #endif 13040 RTE_SET_USED(is_tx); 13041 13042 switch (ret) { 13043 case 0: 13044 break; 13045 case -ENODEV: 13046 printf("invalid port_id %d\n", res->port_id); 13047 break; 13048 case -ENOTSUP: 13049 printf("not supported on port %d\n", res->port_id); 13050 break; 13051 default: 13052 printf("programming error: (%s)\n", strerror(-ret)); 13053 } 13054 } 13055 13056 cmdline_parse_inst_t cmd_set_macsec_sc = { 13057 .f = cmd_set_macsec_sc_parsed, 13058 .data = NULL, 13059 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 13060 .tokens = { 13061 (void *)&cmd_macsec_sc_set, 13062 (void *)&cmd_macsec_sc_macsec, 13063 (void *)&cmd_macsec_sc_sc, 13064 (void *)&cmd_macsec_sc_tx_rx, 13065 (void *)&cmd_macsec_sc_port_id, 13066 (void *)&cmd_macsec_sc_mac, 13067 (void *)&cmd_macsec_sc_pi, 13068 NULL, 13069 }, 13070 }; 13071 13072 /* Common result structure for MACsec secure connection configure */ 13073 struct cmd_macsec_sa_result { 13074 cmdline_fixed_string_t set; 13075 cmdline_fixed_string_t macsec; 13076 cmdline_fixed_string_t sa; 13077 cmdline_fixed_string_t tx_rx; 13078 uint8_t port_id; 13079 uint8_t idx; 13080 uint8_t an; 13081 uint32_t pn; 13082 cmdline_fixed_string_t key; 13083 }; 13084 13085 /* Common CLI fields for MACsec secure connection configure */ 13086 cmdline_parse_token_string_t cmd_macsec_sa_set = 13087 TOKEN_STRING_INITIALIZER 13088 (struct cmd_macsec_sa_result, 13089 set, "set"); 13090 cmdline_parse_token_string_t cmd_macsec_sa_macsec = 13091 TOKEN_STRING_INITIALIZER 13092 (struct cmd_macsec_sa_result, 13093 macsec, "macsec"); 13094 cmdline_parse_token_string_t cmd_macsec_sa_sa = 13095 TOKEN_STRING_INITIALIZER 13096 (struct cmd_macsec_sa_result, 13097 sa, "sa"); 13098 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 13099 TOKEN_STRING_INITIALIZER 13100 (struct cmd_macsec_sa_result, 13101 tx_rx, "tx#rx"); 13102 cmdline_parse_token_num_t cmd_macsec_sa_port_id = 13103 TOKEN_NUM_INITIALIZER 13104 (struct cmd_macsec_sa_result, 13105 port_id, UINT8); 13106 cmdline_parse_token_num_t cmd_macsec_sa_idx = 13107 TOKEN_NUM_INITIALIZER 13108 (struct cmd_macsec_sa_result, 13109 idx, UINT8); 13110 cmdline_parse_token_num_t cmd_macsec_sa_an = 13111 TOKEN_NUM_INITIALIZER 13112 (struct cmd_macsec_sa_result, 13113 an, UINT8); 13114 cmdline_parse_token_num_t cmd_macsec_sa_pn = 13115 TOKEN_NUM_INITIALIZER 13116 (struct cmd_macsec_sa_result, 13117 pn, UINT32); 13118 cmdline_parse_token_string_t cmd_macsec_sa_key = 13119 TOKEN_STRING_INITIALIZER 13120 (struct cmd_macsec_sa_result, 13121 key, NULL); 13122 13123 static void 13124 cmd_set_macsec_sa_parsed( 13125 void *parsed_result, 13126 __attribute__((unused)) struct cmdline *cl, 13127 __attribute__((unused)) void *data) 13128 { 13129 struct cmd_macsec_sa_result *res = parsed_result; 13130 int ret = -ENOTSUP; 13131 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 13132 uint8_t key[16] = { 0 }; 13133 uint8_t xdgt0; 13134 uint8_t xdgt1; 13135 int key_len; 13136 int i; 13137 13138 key_len = strlen(res->key) / 2; 13139 if (key_len > 16) 13140 key_len = 16; 13141 13142 for (i = 0; i < key_len; i++) { 13143 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 13144 if (xdgt0 == 0xFF) 13145 return; 13146 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 13147 if (xdgt1 == 0xFF) 13148 return; 13149 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 13150 } 13151 13152 #ifdef RTE_LIBRTE_IXGBE_PMD 13153 ret = is_tx ? 13154 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 13155 res->idx, res->an, res->pn, key) : 13156 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 13157 res->idx, res->an, res->pn, key); 13158 #endif 13159 RTE_SET_USED(is_tx); 13160 RTE_SET_USED(key); 13161 13162 switch (ret) { 13163 case 0: 13164 break; 13165 case -EINVAL: 13166 printf("invalid idx %d or an %d\n", res->idx, res->an); 13167 break; 13168 case -ENODEV: 13169 printf("invalid port_id %d\n", res->port_id); 13170 break; 13171 case -ENOTSUP: 13172 printf("not supported on port %d\n", res->port_id); 13173 break; 13174 default: 13175 printf("programming error: (%s)\n", strerror(-ret)); 13176 } 13177 } 13178 13179 cmdline_parse_inst_t cmd_set_macsec_sa = { 13180 .f = cmd_set_macsec_sa_parsed, 13181 .data = NULL, 13182 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 13183 .tokens = { 13184 (void *)&cmd_macsec_sa_set, 13185 (void *)&cmd_macsec_sa_macsec, 13186 (void *)&cmd_macsec_sa_sa, 13187 (void *)&cmd_macsec_sa_tx_rx, 13188 (void *)&cmd_macsec_sa_port_id, 13189 (void *)&cmd_macsec_sa_idx, 13190 (void *)&cmd_macsec_sa_an, 13191 (void *)&cmd_macsec_sa_pn, 13192 (void *)&cmd_macsec_sa_key, 13193 NULL, 13194 }, 13195 }; 13196 13197 /* VF unicast promiscuous mode configuration */ 13198 13199 /* Common result structure for VF unicast promiscuous mode */ 13200 struct cmd_vf_promisc_result { 13201 cmdline_fixed_string_t set; 13202 cmdline_fixed_string_t vf; 13203 cmdline_fixed_string_t promisc; 13204 uint8_t port_id; 13205 uint32_t vf_id; 13206 cmdline_fixed_string_t on_off; 13207 }; 13208 13209 /* Common CLI fields for VF unicast promiscuous mode enable disable */ 13210 cmdline_parse_token_string_t cmd_vf_promisc_set = 13211 TOKEN_STRING_INITIALIZER 13212 (struct cmd_vf_promisc_result, 13213 set, "set"); 13214 cmdline_parse_token_string_t cmd_vf_promisc_vf = 13215 TOKEN_STRING_INITIALIZER 13216 (struct cmd_vf_promisc_result, 13217 vf, "vf"); 13218 cmdline_parse_token_string_t cmd_vf_promisc_promisc = 13219 TOKEN_STRING_INITIALIZER 13220 (struct cmd_vf_promisc_result, 13221 promisc, "promisc"); 13222 cmdline_parse_token_num_t cmd_vf_promisc_port_id = 13223 TOKEN_NUM_INITIALIZER 13224 (struct cmd_vf_promisc_result, 13225 port_id, UINT8); 13226 cmdline_parse_token_num_t cmd_vf_promisc_vf_id = 13227 TOKEN_NUM_INITIALIZER 13228 (struct cmd_vf_promisc_result, 13229 vf_id, UINT32); 13230 cmdline_parse_token_string_t cmd_vf_promisc_on_off = 13231 TOKEN_STRING_INITIALIZER 13232 (struct cmd_vf_promisc_result, 13233 on_off, "on#off"); 13234 13235 static void 13236 cmd_set_vf_promisc_parsed( 13237 void *parsed_result, 13238 __attribute__((unused)) struct cmdline *cl, 13239 __attribute__((unused)) void *data) 13240 { 13241 struct cmd_vf_promisc_result *res = parsed_result; 13242 int ret = -ENOTSUP; 13243 13244 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13245 13246 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13247 return; 13248 13249 #ifdef RTE_LIBRTE_I40E_PMD 13250 ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id, 13251 res->vf_id, is_on); 13252 #endif 13253 13254 switch (ret) { 13255 case 0: 13256 break; 13257 case -EINVAL: 13258 printf("invalid vf_id %d\n", res->vf_id); 13259 break; 13260 case -ENODEV: 13261 printf("invalid port_id %d\n", res->port_id); 13262 break; 13263 case -ENOTSUP: 13264 printf("function not implemented\n"); 13265 break; 13266 default: 13267 printf("programming error: (%s)\n", strerror(-ret)); 13268 } 13269 } 13270 13271 cmdline_parse_inst_t cmd_set_vf_promisc = { 13272 .f = cmd_set_vf_promisc_parsed, 13273 .data = NULL, 13274 .help_str = "set vf promisc <port_id> <vf_id> on|off: " 13275 "Set unicast promiscuous mode for a VF from the PF", 13276 .tokens = { 13277 (void *)&cmd_vf_promisc_set, 13278 (void *)&cmd_vf_promisc_vf, 13279 (void *)&cmd_vf_promisc_promisc, 13280 (void *)&cmd_vf_promisc_port_id, 13281 (void *)&cmd_vf_promisc_vf_id, 13282 (void *)&cmd_vf_promisc_on_off, 13283 NULL, 13284 }, 13285 }; 13286 13287 /* VF multicast promiscuous mode configuration */ 13288 13289 /* Common result structure for VF multicast promiscuous mode */ 13290 struct cmd_vf_allmulti_result { 13291 cmdline_fixed_string_t set; 13292 cmdline_fixed_string_t vf; 13293 cmdline_fixed_string_t allmulti; 13294 uint8_t port_id; 13295 uint32_t vf_id; 13296 cmdline_fixed_string_t on_off; 13297 }; 13298 13299 /* Common CLI fields for VF multicast promiscuous mode enable disable */ 13300 cmdline_parse_token_string_t cmd_vf_allmulti_set = 13301 TOKEN_STRING_INITIALIZER 13302 (struct cmd_vf_allmulti_result, 13303 set, "set"); 13304 cmdline_parse_token_string_t cmd_vf_allmulti_vf = 13305 TOKEN_STRING_INITIALIZER 13306 (struct cmd_vf_allmulti_result, 13307 vf, "vf"); 13308 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = 13309 TOKEN_STRING_INITIALIZER 13310 (struct cmd_vf_allmulti_result, 13311 allmulti, "allmulti"); 13312 cmdline_parse_token_num_t cmd_vf_allmulti_port_id = 13313 TOKEN_NUM_INITIALIZER 13314 (struct cmd_vf_allmulti_result, 13315 port_id, UINT8); 13316 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = 13317 TOKEN_NUM_INITIALIZER 13318 (struct cmd_vf_allmulti_result, 13319 vf_id, UINT32); 13320 cmdline_parse_token_string_t cmd_vf_allmulti_on_off = 13321 TOKEN_STRING_INITIALIZER 13322 (struct cmd_vf_allmulti_result, 13323 on_off, "on#off"); 13324 13325 static void 13326 cmd_set_vf_allmulti_parsed( 13327 void *parsed_result, 13328 __attribute__((unused)) struct cmdline *cl, 13329 __attribute__((unused)) void *data) 13330 { 13331 struct cmd_vf_allmulti_result *res = parsed_result; 13332 int ret = -ENOTSUP; 13333 13334 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13335 13336 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13337 return; 13338 13339 #ifdef RTE_LIBRTE_I40E_PMD 13340 ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id, 13341 res->vf_id, is_on); 13342 #endif 13343 13344 switch (ret) { 13345 case 0: 13346 break; 13347 case -EINVAL: 13348 printf("invalid vf_id %d\n", res->vf_id); 13349 break; 13350 case -ENODEV: 13351 printf("invalid port_id %d\n", res->port_id); 13352 break; 13353 case -ENOTSUP: 13354 printf("function not implemented\n"); 13355 break; 13356 default: 13357 printf("programming error: (%s)\n", strerror(-ret)); 13358 } 13359 } 13360 13361 cmdline_parse_inst_t cmd_set_vf_allmulti = { 13362 .f = cmd_set_vf_allmulti_parsed, 13363 .data = NULL, 13364 .help_str = "set vf allmulti <port_id> <vf_id> on|off: " 13365 "Set multicast promiscuous mode for a VF from the PF", 13366 .tokens = { 13367 (void *)&cmd_vf_allmulti_set, 13368 (void *)&cmd_vf_allmulti_vf, 13369 (void *)&cmd_vf_allmulti_allmulti, 13370 (void *)&cmd_vf_allmulti_port_id, 13371 (void *)&cmd_vf_allmulti_vf_id, 13372 (void *)&cmd_vf_allmulti_on_off, 13373 NULL, 13374 }, 13375 }; 13376 13377 /* vf broadcast mode configuration */ 13378 13379 /* Common result structure for vf broadcast */ 13380 struct cmd_set_vf_broadcast_result { 13381 cmdline_fixed_string_t set; 13382 cmdline_fixed_string_t vf; 13383 cmdline_fixed_string_t broadcast; 13384 uint8_t port_id; 13385 uint16_t vf_id; 13386 cmdline_fixed_string_t on_off; 13387 }; 13388 13389 /* Common CLI fields for vf broadcast enable disable */ 13390 cmdline_parse_token_string_t cmd_set_vf_broadcast_set = 13391 TOKEN_STRING_INITIALIZER 13392 (struct cmd_set_vf_broadcast_result, 13393 set, "set"); 13394 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf = 13395 TOKEN_STRING_INITIALIZER 13396 (struct cmd_set_vf_broadcast_result, 13397 vf, "vf"); 13398 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = 13399 TOKEN_STRING_INITIALIZER 13400 (struct cmd_set_vf_broadcast_result, 13401 broadcast, "broadcast"); 13402 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = 13403 TOKEN_NUM_INITIALIZER 13404 (struct cmd_set_vf_broadcast_result, 13405 port_id, UINT8); 13406 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = 13407 TOKEN_NUM_INITIALIZER 13408 (struct cmd_set_vf_broadcast_result, 13409 vf_id, UINT16); 13410 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off = 13411 TOKEN_STRING_INITIALIZER 13412 (struct cmd_set_vf_broadcast_result, 13413 on_off, "on#off"); 13414 13415 static void 13416 cmd_set_vf_broadcast_parsed( 13417 void *parsed_result, 13418 __attribute__((unused)) struct cmdline *cl, 13419 __attribute__((unused)) void *data) 13420 { 13421 struct cmd_set_vf_broadcast_result *res = parsed_result; 13422 int ret = -ENOTSUP; 13423 13424 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13425 13426 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13427 return; 13428 13429 #ifdef RTE_LIBRTE_I40E_PMD 13430 ret = rte_pmd_i40e_set_vf_broadcast(res->port_id, 13431 res->vf_id, is_on); 13432 #endif 13433 13434 switch (ret) { 13435 case 0: 13436 break; 13437 case -EINVAL: 13438 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 13439 break; 13440 case -ENODEV: 13441 printf("invalid port_id %d\n", res->port_id); 13442 break; 13443 case -ENOTSUP: 13444 printf("function not implemented\n"); 13445 break; 13446 default: 13447 printf("programming error: (%s)\n", strerror(-ret)); 13448 } 13449 } 13450 13451 cmdline_parse_inst_t cmd_set_vf_broadcast = { 13452 .f = cmd_set_vf_broadcast_parsed, 13453 .data = NULL, 13454 .help_str = "set vf broadcast <port_id> <vf_id> on|off", 13455 .tokens = { 13456 (void *)&cmd_set_vf_broadcast_set, 13457 (void *)&cmd_set_vf_broadcast_vf, 13458 (void *)&cmd_set_vf_broadcast_broadcast, 13459 (void *)&cmd_set_vf_broadcast_port_id, 13460 (void *)&cmd_set_vf_broadcast_vf_id, 13461 (void *)&cmd_set_vf_broadcast_on_off, 13462 NULL, 13463 }, 13464 }; 13465 13466 /* vf vlan tag configuration */ 13467 13468 /* Common result structure for vf vlan tag */ 13469 struct cmd_set_vf_vlan_tag_result { 13470 cmdline_fixed_string_t set; 13471 cmdline_fixed_string_t vf; 13472 cmdline_fixed_string_t vlan; 13473 cmdline_fixed_string_t tag; 13474 uint8_t port_id; 13475 uint16_t vf_id; 13476 cmdline_fixed_string_t on_off; 13477 }; 13478 13479 /* Common CLI fields for vf vlan tag enable disable */ 13480 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set = 13481 TOKEN_STRING_INITIALIZER 13482 (struct cmd_set_vf_vlan_tag_result, 13483 set, "set"); 13484 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf = 13485 TOKEN_STRING_INITIALIZER 13486 (struct cmd_set_vf_vlan_tag_result, 13487 vf, "vf"); 13488 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan = 13489 TOKEN_STRING_INITIALIZER 13490 (struct cmd_set_vf_vlan_tag_result, 13491 vlan, "vlan"); 13492 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = 13493 TOKEN_STRING_INITIALIZER 13494 (struct cmd_set_vf_vlan_tag_result, 13495 tag, "tag"); 13496 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = 13497 TOKEN_NUM_INITIALIZER 13498 (struct cmd_set_vf_vlan_tag_result, 13499 port_id, UINT8); 13500 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = 13501 TOKEN_NUM_INITIALIZER 13502 (struct cmd_set_vf_vlan_tag_result, 13503 vf_id, UINT16); 13504 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off = 13505 TOKEN_STRING_INITIALIZER 13506 (struct cmd_set_vf_vlan_tag_result, 13507 on_off, "on#off"); 13508 13509 static void 13510 cmd_set_vf_vlan_tag_parsed( 13511 void *parsed_result, 13512 __attribute__((unused)) struct cmdline *cl, 13513 __attribute__((unused)) void *data) 13514 { 13515 struct cmd_set_vf_vlan_tag_result *res = parsed_result; 13516 int ret = -ENOTSUP; 13517 13518 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13519 13520 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13521 return; 13522 13523 #ifdef RTE_LIBRTE_I40E_PMD 13524 ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id, 13525 res->vf_id, is_on); 13526 #endif 13527 13528 switch (ret) { 13529 case 0: 13530 break; 13531 case -EINVAL: 13532 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 13533 break; 13534 case -ENODEV: 13535 printf("invalid port_id %d\n", res->port_id); 13536 break; 13537 case -ENOTSUP: 13538 printf("function not implemented\n"); 13539 break; 13540 default: 13541 printf("programming error: (%s)\n", strerror(-ret)); 13542 } 13543 } 13544 13545 cmdline_parse_inst_t cmd_set_vf_vlan_tag = { 13546 .f = cmd_set_vf_vlan_tag_parsed, 13547 .data = NULL, 13548 .help_str = "set vf vlan tag <port_id> <vf_id> on|off", 13549 .tokens = { 13550 (void *)&cmd_set_vf_vlan_tag_set, 13551 (void *)&cmd_set_vf_vlan_tag_vf, 13552 (void *)&cmd_set_vf_vlan_tag_vlan, 13553 (void *)&cmd_set_vf_vlan_tag_tag, 13554 (void *)&cmd_set_vf_vlan_tag_port_id, 13555 (void *)&cmd_set_vf_vlan_tag_vf_id, 13556 (void *)&cmd_set_vf_vlan_tag_on_off, 13557 NULL, 13558 }, 13559 }; 13560 13561 /* Common definition of VF and TC TX bandwidth configuration */ 13562 struct cmd_vf_tc_bw_result { 13563 cmdline_fixed_string_t set; 13564 cmdline_fixed_string_t vf; 13565 cmdline_fixed_string_t tc; 13566 cmdline_fixed_string_t tx; 13567 cmdline_fixed_string_t min_bw; 13568 cmdline_fixed_string_t max_bw; 13569 cmdline_fixed_string_t strict_link_prio; 13570 uint8_t port_id; 13571 uint16_t vf_id; 13572 uint8_t tc_no; 13573 uint32_t bw; 13574 cmdline_fixed_string_t bw_list; 13575 uint8_t tc_map; 13576 }; 13577 13578 cmdline_parse_token_string_t cmd_vf_tc_bw_set = 13579 TOKEN_STRING_INITIALIZER 13580 (struct cmd_vf_tc_bw_result, 13581 set, "set"); 13582 cmdline_parse_token_string_t cmd_vf_tc_bw_vf = 13583 TOKEN_STRING_INITIALIZER 13584 (struct cmd_vf_tc_bw_result, 13585 vf, "vf"); 13586 cmdline_parse_token_string_t cmd_vf_tc_bw_tc = 13587 TOKEN_STRING_INITIALIZER 13588 (struct cmd_vf_tc_bw_result, 13589 tc, "tc"); 13590 cmdline_parse_token_string_t cmd_vf_tc_bw_tx = 13591 TOKEN_STRING_INITIALIZER 13592 (struct cmd_vf_tc_bw_result, 13593 tx, "tx"); 13594 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio = 13595 TOKEN_STRING_INITIALIZER 13596 (struct cmd_vf_tc_bw_result, 13597 strict_link_prio, "strict-link-priority"); 13598 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = 13599 TOKEN_STRING_INITIALIZER 13600 (struct cmd_vf_tc_bw_result, 13601 min_bw, "min-bandwidth"); 13602 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw = 13603 TOKEN_STRING_INITIALIZER 13604 (struct cmd_vf_tc_bw_result, 13605 max_bw, "max-bandwidth"); 13606 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = 13607 TOKEN_NUM_INITIALIZER 13608 (struct cmd_vf_tc_bw_result, 13609 port_id, UINT8); 13610 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id = 13611 TOKEN_NUM_INITIALIZER 13612 (struct cmd_vf_tc_bw_result, 13613 vf_id, UINT16); 13614 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no = 13615 TOKEN_NUM_INITIALIZER 13616 (struct cmd_vf_tc_bw_result, 13617 tc_no, UINT8); 13618 cmdline_parse_token_num_t cmd_vf_tc_bw_bw = 13619 TOKEN_NUM_INITIALIZER 13620 (struct cmd_vf_tc_bw_result, 13621 bw, UINT32); 13622 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = 13623 TOKEN_STRING_INITIALIZER 13624 (struct cmd_vf_tc_bw_result, 13625 bw_list, NULL); 13626 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map = 13627 TOKEN_NUM_INITIALIZER 13628 (struct cmd_vf_tc_bw_result, 13629 tc_map, UINT8); 13630 13631 /* VF max bandwidth setting */ 13632 static void 13633 cmd_vf_max_bw_parsed( 13634 void *parsed_result, 13635 __attribute__((unused)) struct cmdline *cl, 13636 __attribute__((unused)) void *data) 13637 { 13638 struct cmd_vf_tc_bw_result *res = parsed_result; 13639 int ret = -ENOTSUP; 13640 13641 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13642 return; 13643 13644 #ifdef RTE_LIBRTE_I40E_PMD 13645 ret = rte_pmd_i40e_set_vf_max_bw(res->port_id, 13646 res->vf_id, res->bw); 13647 #endif 13648 13649 switch (ret) { 13650 case 0: 13651 break; 13652 case -EINVAL: 13653 printf("invalid vf_id %d or bandwidth %d\n", 13654 res->vf_id, res->bw); 13655 break; 13656 case -ENODEV: 13657 printf("invalid port_id %d\n", res->port_id); 13658 break; 13659 case -ENOTSUP: 13660 printf("function not implemented\n"); 13661 break; 13662 default: 13663 printf("programming error: (%s)\n", strerror(-ret)); 13664 } 13665 } 13666 13667 cmdline_parse_inst_t cmd_vf_max_bw = { 13668 .f = cmd_vf_max_bw_parsed, 13669 .data = NULL, 13670 .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>", 13671 .tokens = { 13672 (void *)&cmd_vf_tc_bw_set, 13673 (void *)&cmd_vf_tc_bw_vf, 13674 (void *)&cmd_vf_tc_bw_tx, 13675 (void *)&cmd_vf_tc_bw_max_bw, 13676 (void *)&cmd_vf_tc_bw_port_id, 13677 (void *)&cmd_vf_tc_bw_vf_id, 13678 (void *)&cmd_vf_tc_bw_bw, 13679 NULL, 13680 }, 13681 }; 13682 13683 static int 13684 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, 13685 uint8_t *tc_num, 13686 char *str) 13687 { 13688 uint32_t size; 13689 const char *p, *p0 = str; 13690 char s[256]; 13691 char *end; 13692 char *str_fld[16]; 13693 uint16_t i; 13694 int ret; 13695 13696 p = strchr(p0, '('); 13697 if (p == NULL) { 13698 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 13699 return -1; 13700 } 13701 p++; 13702 p0 = strchr(p, ')'); 13703 if (p0 == NULL) { 13704 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 13705 return -1; 13706 } 13707 size = p0 - p; 13708 if (size >= sizeof(s)) { 13709 printf("The string size exceeds the internal buffer size\n"); 13710 return -1; 13711 } 13712 snprintf(s, sizeof(s), "%.*s", size, p); 13713 ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); 13714 if (ret <= 0) { 13715 printf("Failed to get the bandwidth list. "); 13716 return -1; 13717 } 13718 *tc_num = ret; 13719 for (i = 0; i < ret; i++) 13720 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); 13721 13722 return 0; 13723 } 13724 13725 /* TC min bandwidth setting */ 13726 static void 13727 cmd_vf_tc_min_bw_parsed( 13728 void *parsed_result, 13729 __attribute__((unused)) struct cmdline *cl, 13730 __attribute__((unused)) void *data) 13731 { 13732 struct cmd_vf_tc_bw_result *res = parsed_result; 13733 uint8_t tc_num; 13734 uint8_t bw[16]; 13735 int ret = -ENOTSUP; 13736 13737 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13738 return; 13739 13740 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 13741 if (ret) 13742 return; 13743 13744 #ifdef RTE_LIBRTE_I40E_PMD 13745 ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id, 13746 tc_num, bw); 13747 #endif 13748 13749 switch (ret) { 13750 case 0: 13751 break; 13752 case -EINVAL: 13753 printf("invalid vf_id %d or bandwidth\n", res->vf_id); 13754 break; 13755 case -ENODEV: 13756 printf("invalid port_id %d\n", res->port_id); 13757 break; 13758 case -ENOTSUP: 13759 printf("function not implemented\n"); 13760 break; 13761 default: 13762 printf("programming error: (%s)\n", strerror(-ret)); 13763 } 13764 } 13765 13766 cmdline_parse_inst_t cmd_vf_tc_min_bw = { 13767 .f = cmd_vf_tc_min_bw_parsed, 13768 .data = NULL, 13769 .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>" 13770 " <bw1, bw2, ...>", 13771 .tokens = { 13772 (void *)&cmd_vf_tc_bw_set, 13773 (void *)&cmd_vf_tc_bw_vf, 13774 (void *)&cmd_vf_tc_bw_tc, 13775 (void *)&cmd_vf_tc_bw_tx, 13776 (void *)&cmd_vf_tc_bw_min_bw, 13777 (void *)&cmd_vf_tc_bw_port_id, 13778 (void *)&cmd_vf_tc_bw_vf_id, 13779 (void *)&cmd_vf_tc_bw_bw_list, 13780 NULL, 13781 }, 13782 }; 13783 13784 static void 13785 cmd_tc_min_bw_parsed( 13786 void *parsed_result, 13787 __attribute__((unused)) struct cmdline *cl, 13788 __attribute__((unused)) void *data) 13789 { 13790 struct cmd_vf_tc_bw_result *res = parsed_result; 13791 struct rte_port *port; 13792 uint8_t tc_num; 13793 uint8_t bw[16]; 13794 int ret = -ENOTSUP; 13795 13796 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13797 return; 13798 13799 port = &ports[res->port_id]; 13800 /** Check if the port is not started **/ 13801 if (port->port_status != RTE_PORT_STOPPED) { 13802 printf("Please stop port %d first\n", res->port_id); 13803 return; 13804 } 13805 13806 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 13807 if (ret) 13808 return; 13809 13810 #ifdef RTE_LIBRTE_IXGBE_PMD 13811 ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); 13812 #endif 13813 13814 switch (ret) { 13815 case 0: 13816 break; 13817 case -EINVAL: 13818 printf("invalid bandwidth\n"); 13819 break; 13820 case -ENODEV: 13821 printf("invalid port_id %d\n", res->port_id); 13822 break; 13823 case -ENOTSUP: 13824 printf("function not implemented\n"); 13825 break; 13826 default: 13827 printf("programming error: (%s)\n", strerror(-ret)); 13828 } 13829 } 13830 13831 cmdline_parse_inst_t cmd_tc_min_bw = { 13832 .f = cmd_tc_min_bw_parsed, 13833 .data = NULL, 13834 .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>", 13835 .tokens = { 13836 (void *)&cmd_vf_tc_bw_set, 13837 (void *)&cmd_vf_tc_bw_tc, 13838 (void *)&cmd_vf_tc_bw_tx, 13839 (void *)&cmd_vf_tc_bw_min_bw, 13840 (void *)&cmd_vf_tc_bw_port_id, 13841 (void *)&cmd_vf_tc_bw_bw_list, 13842 NULL, 13843 }, 13844 }; 13845 13846 /* TC max bandwidth setting */ 13847 static void 13848 cmd_vf_tc_max_bw_parsed( 13849 void *parsed_result, 13850 __attribute__((unused)) struct cmdline *cl, 13851 __attribute__((unused)) void *data) 13852 { 13853 struct cmd_vf_tc_bw_result *res = parsed_result; 13854 int ret = -ENOTSUP; 13855 13856 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13857 return; 13858 13859 #ifdef RTE_LIBRTE_I40E_PMD 13860 ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id, 13861 res->tc_no, res->bw); 13862 #endif 13863 13864 switch (ret) { 13865 case 0: 13866 break; 13867 case -EINVAL: 13868 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n", 13869 res->vf_id, res->tc_no, res->bw); 13870 break; 13871 case -ENODEV: 13872 printf("invalid port_id %d\n", res->port_id); 13873 break; 13874 case -ENOTSUP: 13875 printf("function not implemented\n"); 13876 break; 13877 default: 13878 printf("programming error: (%s)\n", strerror(-ret)); 13879 } 13880 } 13881 13882 cmdline_parse_inst_t cmd_vf_tc_max_bw = { 13883 .f = cmd_vf_tc_max_bw_parsed, 13884 .data = NULL, 13885 .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>" 13886 " <bandwidth>", 13887 .tokens = { 13888 (void *)&cmd_vf_tc_bw_set, 13889 (void *)&cmd_vf_tc_bw_vf, 13890 (void *)&cmd_vf_tc_bw_tc, 13891 (void *)&cmd_vf_tc_bw_tx, 13892 (void *)&cmd_vf_tc_bw_max_bw, 13893 (void *)&cmd_vf_tc_bw_port_id, 13894 (void *)&cmd_vf_tc_bw_vf_id, 13895 (void *)&cmd_vf_tc_bw_tc_no, 13896 (void *)&cmd_vf_tc_bw_bw, 13897 NULL, 13898 }, 13899 }; 13900 13901 13902 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 13903 13904 /* *** Set Port default Traffic Management Hierarchy *** */ 13905 struct cmd_set_port_tm_hierarchy_default_result { 13906 cmdline_fixed_string_t set; 13907 cmdline_fixed_string_t port; 13908 cmdline_fixed_string_t tm; 13909 cmdline_fixed_string_t hierarchy; 13910 cmdline_fixed_string_t def; 13911 uint16_t port_id; 13912 }; 13913 13914 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set = 13915 TOKEN_STRING_INITIALIZER( 13916 struct cmd_set_port_tm_hierarchy_default_result, set, "set"); 13917 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port = 13918 TOKEN_STRING_INITIALIZER( 13919 struct cmd_set_port_tm_hierarchy_default_result, port, "port"); 13920 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm = 13921 TOKEN_STRING_INITIALIZER( 13922 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm"); 13923 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy = 13924 TOKEN_STRING_INITIALIZER( 13925 struct cmd_set_port_tm_hierarchy_default_result, 13926 hierarchy, "hierarchy"); 13927 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default = 13928 TOKEN_STRING_INITIALIZER( 13929 struct cmd_set_port_tm_hierarchy_default_result, 13930 def, "default"); 13931 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id = 13932 TOKEN_NUM_INITIALIZER( 13933 struct cmd_set_port_tm_hierarchy_default_result, 13934 port_id, UINT8); 13935 13936 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result, 13937 __attribute__((unused)) struct cmdline *cl, 13938 __attribute__((unused)) void *data) 13939 { 13940 struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result; 13941 struct rte_port *p; 13942 uint16_t port_id = res->port_id; 13943 13944 if (port_id_is_invalid(port_id, ENABLED_WARN)) 13945 return; 13946 13947 p = &ports[port_id]; 13948 13949 /* Port tm flag */ 13950 if (p->softport.tm_flag == 0) { 13951 printf(" tm not enabled on port %u (error)\n", port_id); 13952 return; 13953 } 13954 13955 /* Forward mode: tm */ 13956 if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) { 13957 printf(" tm mode not enabled(error)\n"); 13958 return; 13959 } 13960 13961 /* Set the default tm hierarchy */ 13962 p->softport.tm.default_hierarchy_enable = 1; 13963 } 13964 13965 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = { 13966 .f = cmd_set_port_tm_hierarchy_default_parsed, 13967 .data = NULL, 13968 .help_str = "set port tm hierarchy default <port_id>", 13969 .tokens = { 13970 (void *)&cmd_set_port_tm_hierarchy_default_set, 13971 (void *)&cmd_set_port_tm_hierarchy_default_port, 13972 (void *)&cmd_set_port_tm_hierarchy_default_tm, 13973 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy, 13974 (void *)&cmd_set_port_tm_hierarchy_default_default, 13975 (void *)&cmd_set_port_tm_hierarchy_default_port_id, 13976 NULL, 13977 }, 13978 }; 13979 #endif 13980 13981 /* Strict link priority scheduling mode setting */ 13982 static void 13983 cmd_strict_link_prio_parsed( 13984 void *parsed_result, 13985 __attribute__((unused)) struct cmdline *cl, 13986 __attribute__((unused)) void *data) 13987 { 13988 struct cmd_vf_tc_bw_result *res = parsed_result; 13989 int ret = -ENOTSUP; 13990 13991 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13992 return; 13993 13994 #ifdef RTE_LIBRTE_I40E_PMD 13995 ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map); 13996 #endif 13997 13998 switch (ret) { 13999 case 0: 14000 break; 14001 case -EINVAL: 14002 printf("invalid tc_bitmap 0x%x\n", res->tc_map); 14003 break; 14004 case -ENODEV: 14005 printf("invalid port_id %d\n", res->port_id); 14006 break; 14007 case -ENOTSUP: 14008 printf("function not implemented\n"); 14009 break; 14010 default: 14011 printf("programming error: (%s)\n", strerror(-ret)); 14012 } 14013 } 14014 14015 cmdline_parse_inst_t cmd_strict_link_prio = { 14016 .f = cmd_strict_link_prio_parsed, 14017 .data = NULL, 14018 .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>", 14019 .tokens = { 14020 (void *)&cmd_vf_tc_bw_set, 14021 (void *)&cmd_vf_tc_bw_tx, 14022 (void *)&cmd_vf_tc_bw_strict_link_prio, 14023 (void *)&cmd_vf_tc_bw_port_id, 14024 (void *)&cmd_vf_tc_bw_tc_map, 14025 NULL, 14026 }, 14027 }; 14028 14029 /* Load dynamic device personalization*/ 14030 struct cmd_ddp_add_result { 14031 cmdline_fixed_string_t ddp; 14032 cmdline_fixed_string_t add; 14033 uint8_t port_id; 14034 char filepath[]; 14035 }; 14036 14037 cmdline_parse_token_string_t cmd_ddp_add_ddp = 14038 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp"); 14039 cmdline_parse_token_string_t cmd_ddp_add_add = 14040 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add"); 14041 cmdline_parse_token_num_t cmd_ddp_add_port_id = 14042 TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8); 14043 cmdline_parse_token_string_t cmd_ddp_add_filepath = 14044 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL); 14045 14046 static void 14047 cmd_ddp_add_parsed( 14048 void *parsed_result, 14049 __attribute__((unused)) struct cmdline *cl, 14050 __attribute__((unused)) void *data) 14051 { 14052 struct cmd_ddp_add_result *res = parsed_result; 14053 uint8_t *buff; 14054 uint32_t size; 14055 char *filepath; 14056 char *file_fld[2]; 14057 int file_num; 14058 int ret = -ENOTSUP; 14059 14060 if (res->port_id > nb_ports) { 14061 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14062 return; 14063 } 14064 14065 if (!all_ports_stopped()) { 14066 printf("Please stop all ports first\n"); 14067 return; 14068 } 14069 14070 filepath = strdup(res->filepath); 14071 if (filepath == NULL) { 14072 printf("Failed to allocate memory\n"); 14073 return; 14074 } 14075 file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ','); 14076 14077 buff = open_ddp_package_file(file_fld[0], &size); 14078 if (!buff) { 14079 free((void *)filepath); 14080 return; 14081 } 14082 14083 #ifdef RTE_LIBRTE_I40E_PMD 14084 if (ret == -ENOTSUP) 14085 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 14086 buff, size, 14087 RTE_PMD_I40E_PKG_OP_WR_ADD); 14088 #endif 14089 14090 if (ret == -EEXIST) 14091 printf("Profile has already existed.\n"); 14092 else if (ret < 0) 14093 printf("Failed to load profile.\n"); 14094 else if (file_num == 2) 14095 save_ddp_package_file(file_fld[1], buff, size); 14096 14097 close_ddp_package_file(buff); 14098 free((void *)filepath); 14099 } 14100 14101 cmdline_parse_inst_t cmd_ddp_add = { 14102 .f = cmd_ddp_add_parsed, 14103 .data = NULL, 14104 .help_str = "ddp add <port_id> <profile_path[,output_path]>", 14105 .tokens = { 14106 (void *)&cmd_ddp_add_ddp, 14107 (void *)&cmd_ddp_add_add, 14108 (void *)&cmd_ddp_add_port_id, 14109 (void *)&cmd_ddp_add_filepath, 14110 NULL, 14111 }, 14112 }; 14113 14114 /* Delete dynamic device personalization*/ 14115 struct cmd_ddp_del_result { 14116 cmdline_fixed_string_t ddp; 14117 cmdline_fixed_string_t del; 14118 uint8_t port_id; 14119 char filepath[]; 14120 }; 14121 14122 cmdline_parse_token_string_t cmd_ddp_del_ddp = 14123 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp"); 14124 cmdline_parse_token_string_t cmd_ddp_del_del = 14125 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del"); 14126 cmdline_parse_token_num_t cmd_ddp_del_port_id = 14127 TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8); 14128 cmdline_parse_token_string_t cmd_ddp_del_filepath = 14129 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL); 14130 14131 static void 14132 cmd_ddp_del_parsed( 14133 void *parsed_result, 14134 __attribute__((unused)) struct cmdline *cl, 14135 __attribute__((unused)) void *data) 14136 { 14137 struct cmd_ddp_del_result *res = parsed_result; 14138 uint8_t *buff; 14139 uint32_t size; 14140 int ret = -ENOTSUP; 14141 14142 if (res->port_id > nb_ports) { 14143 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14144 return; 14145 } 14146 14147 if (!all_ports_stopped()) { 14148 printf("Please stop all ports first\n"); 14149 return; 14150 } 14151 14152 buff = open_ddp_package_file(res->filepath, &size); 14153 if (!buff) 14154 return; 14155 14156 #ifdef RTE_LIBRTE_I40E_PMD 14157 if (ret == -ENOTSUP) 14158 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 14159 buff, size, 14160 RTE_PMD_I40E_PKG_OP_WR_DEL); 14161 #endif 14162 14163 if (ret == -EACCES) 14164 printf("Profile does not exist.\n"); 14165 else if (ret < 0) 14166 printf("Failed to delete profile.\n"); 14167 14168 close_ddp_package_file(buff); 14169 } 14170 14171 cmdline_parse_inst_t cmd_ddp_del = { 14172 .f = cmd_ddp_del_parsed, 14173 .data = NULL, 14174 .help_str = "ddp del <port_id> <profile_path>", 14175 .tokens = { 14176 (void *)&cmd_ddp_del_ddp, 14177 (void *)&cmd_ddp_del_del, 14178 (void *)&cmd_ddp_del_port_id, 14179 (void *)&cmd_ddp_del_filepath, 14180 NULL, 14181 }, 14182 }; 14183 14184 /* Get dynamic device personalization profile info */ 14185 struct cmd_ddp_info_result { 14186 cmdline_fixed_string_t ddp; 14187 cmdline_fixed_string_t get; 14188 cmdline_fixed_string_t info; 14189 char filepath[]; 14190 }; 14191 14192 cmdline_parse_token_string_t cmd_ddp_info_ddp = 14193 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp"); 14194 cmdline_parse_token_string_t cmd_ddp_info_get = 14195 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get"); 14196 cmdline_parse_token_string_t cmd_ddp_info_info = 14197 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info"); 14198 cmdline_parse_token_string_t cmd_ddp_info_filepath = 14199 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL); 14200 14201 static void 14202 cmd_ddp_info_parsed( 14203 void *parsed_result, 14204 __attribute__((unused)) struct cmdline *cl, 14205 __attribute__((unused)) void *data) 14206 { 14207 struct cmd_ddp_info_result *res = parsed_result; 14208 uint8_t *pkg; 14209 uint32_t pkg_size; 14210 int ret = -ENOTSUP; 14211 #ifdef RTE_LIBRTE_I40E_PMD 14212 uint32_t i, j, n; 14213 uint8_t *buff; 14214 uint32_t buff_size = 0; 14215 struct rte_pmd_i40e_profile_info info; 14216 uint32_t dev_num = 0; 14217 struct rte_pmd_i40e_ddp_device_id *devs; 14218 uint32_t proto_num = 0; 14219 struct rte_pmd_i40e_proto_info *proto; 14220 uint32_t pctype_num = 0; 14221 struct rte_pmd_i40e_ptype_info *pctype; 14222 uint32_t ptype_num = 0; 14223 struct rte_pmd_i40e_ptype_info *ptype; 14224 uint8_t proto_id; 14225 14226 #endif 14227 14228 pkg = open_ddp_package_file(res->filepath, &pkg_size); 14229 if (!pkg) 14230 return; 14231 14232 #ifdef RTE_LIBRTE_I40E_PMD 14233 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14234 (uint8_t *)&info, sizeof(info), 14235 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER); 14236 if (!ret) { 14237 printf("Global Track id: 0x%x\n", info.track_id); 14238 printf("Global Version: %d.%d.%d.%d\n", 14239 info.version.major, 14240 info.version.minor, 14241 info.version.update, 14242 info.version.draft); 14243 printf("Global Package name: %s\n\n", info.name); 14244 } 14245 14246 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14247 (uint8_t *)&info, sizeof(info), 14248 RTE_PMD_I40E_PKG_INFO_HEADER); 14249 if (!ret) { 14250 printf("i40e Profile Track id: 0x%x\n", info.track_id); 14251 printf("i40e Profile Version: %d.%d.%d.%d\n", 14252 info.version.major, 14253 info.version.minor, 14254 info.version.update, 14255 info.version.draft); 14256 printf("i40e Profile name: %s\n\n", info.name); 14257 } 14258 14259 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14260 (uint8_t *)&buff_size, sizeof(buff_size), 14261 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE); 14262 if (!ret && buff_size) { 14263 buff = (uint8_t *)malloc(buff_size); 14264 if (buff) { 14265 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14266 buff, buff_size, 14267 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES); 14268 if (!ret) 14269 printf("Package Notes:\n%s\n\n", buff); 14270 free(buff); 14271 } 14272 } 14273 14274 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14275 (uint8_t *)&dev_num, sizeof(dev_num), 14276 RTE_PMD_I40E_PKG_INFO_DEVID_NUM); 14277 if (!ret && dev_num) { 14278 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id); 14279 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size); 14280 if (devs) { 14281 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14282 (uint8_t *)devs, buff_size, 14283 RTE_PMD_I40E_PKG_INFO_DEVID_LIST); 14284 if (!ret) { 14285 printf("List of supported devices:\n"); 14286 for (i = 0; i < dev_num; i++) { 14287 printf(" %04X:%04X %04X:%04X\n", 14288 devs[i].vendor_dev_id >> 16, 14289 devs[i].vendor_dev_id & 0xFFFF, 14290 devs[i].sub_vendor_dev_id >> 16, 14291 devs[i].sub_vendor_dev_id & 0xFFFF); 14292 } 14293 printf("\n"); 14294 } 14295 free(devs); 14296 } 14297 } 14298 14299 /* get information about protocols and packet types */ 14300 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14301 (uint8_t *)&proto_num, sizeof(proto_num), 14302 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM); 14303 if (ret || !proto_num) 14304 goto no_print_return; 14305 14306 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info); 14307 proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size); 14308 if (!proto) 14309 goto no_print_return; 14310 14311 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto, 14312 buff_size, 14313 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST); 14314 if (!ret) { 14315 printf("List of used protocols:\n"); 14316 for (i = 0; i < proto_num; i++) 14317 printf(" %2u: %s\n", proto[i].proto_id, 14318 proto[i].name); 14319 printf("\n"); 14320 } 14321 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14322 (uint8_t *)&pctype_num, sizeof(pctype_num), 14323 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM); 14324 if (ret || !pctype_num) 14325 goto no_print_pctypes; 14326 14327 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info); 14328 pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); 14329 if (!pctype) 14330 goto no_print_pctypes; 14331 14332 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype, 14333 buff_size, 14334 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST); 14335 if (ret) { 14336 free(pctype); 14337 goto no_print_pctypes; 14338 } 14339 14340 printf("List of defined packet classification types:\n"); 14341 for (i = 0; i < pctype_num; i++) { 14342 printf(" %2u:", pctype[i].ptype_id); 14343 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { 14344 proto_id = pctype[i].protocols[j]; 14345 if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { 14346 for (n = 0; n < proto_num; n++) { 14347 if (proto[n].proto_id == proto_id) { 14348 printf(" %s", proto[n].name); 14349 break; 14350 } 14351 } 14352 } 14353 } 14354 printf("\n"); 14355 } 14356 printf("\n"); 14357 free(pctype); 14358 14359 no_print_pctypes: 14360 14361 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num, 14362 sizeof(ptype_num), 14363 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM); 14364 if (ret || !ptype_num) 14365 goto no_print_return; 14366 14367 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info); 14368 ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); 14369 if (!ptype) 14370 goto no_print_return; 14371 14372 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype, 14373 buff_size, 14374 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST); 14375 if (ret) { 14376 free(ptype); 14377 goto no_print_return; 14378 } 14379 printf("List of defined packet types:\n"); 14380 for (i = 0; i < ptype_num; i++) { 14381 printf(" %2u:", ptype[i].ptype_id); 14382 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { 14383 proto_id = ptype[i].protocols[j]; 14384 if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { 14385 for (n = 0; n < proto_num; n++) { 14386 if (proto[n].proto_id == proto_id) { 14387 printf(" %s", proto[n].name); 14388 break; 14389 } 14390 } 14391 } 14392 } 14393 printf("\n"); 14394 } 14395 free(ptype); 14396 printf("\n"); 14397 14398 free(proto); 14399 ret = 0; 14400 no_print_return: 14401 #endif 14402 if (ret == -ENOTSUP) 14403 printf("Function not supported in PMD driver\n"); 14404 close_ddp_package_file(pkg); 14405 } 14406 14407 cmdline_parse_inst_t cmd_ddp_get_info = { 14408 .f = cmd_ddp_info_parsed, 14409 .data = NULL, 14410 .help_str = "ddp get info <profile_path>", 14411 .tokens = { 14412 (void *)&cmd_ddp_info_ddp, 14413 (void *)&cmd_ddp_info_get, 14414 (void *)&cmd_ddp_info_info, 14415 (void *)&cmd_ddp_info_filepath, 14416 NULL, 14417 }, 14418 }; 14419 14420 /* Get dynamic device personalization profile info list*/ 14421 #define PROFILE_INFO_SIZE 48 14422 #define MAX_PROFILE_NUM 16 14423 14424 struct cmd_ddp_get_list_result { 14425 cmdline_fixed_string_t ddp; 14426 cmdline_fixed_string_t get; 14427 cmdline_fixed_string_t list; 14428 uint8_t port_id; 14429 }; 14430 14431 cmdline_parse_token_string_t cmd_ddp_get_list_ddp = 14432 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp"); 14433 cmdline_parse_token_string_t cmd_ddp_get_list_get = 14434 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get"); 14435 cmdline_parse_token_string_t cmd_ddp_get_list_list = 14436 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list"); 14437 cmdline_parse_token_num_t cmd_ddp_get_list_port_id = 14438 TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8); 14439 14440 static void 14441 cmd_ddp_get_list_parsed( 14442 void *parsed_result, 14443 __attribute__((unused)) struct cmdline *cl, 14444 __attribute__((unused)) void *data) 14445 { 14446 struct cmd_ddp_get_list_result *res = parsed_result; 14447 #ifdef RTE_LIBRTE_I40E_PMD 14448 struct rte_pmd_i40e_profile_list *p_list; 14449 struct rte_pmd_i40e_profile_info *p_info; 14450 uint32_t p_num; 14451 uint32_t size; 14452 uint32_t i; 14453 #endif 14454 int ret = -ENOTSUP; 14455 14456 if (res->port_id > nb_ports) { 14457 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14458 return; 14459 } 14460 14461 #ifdef RTE_LIBRTE_I40E_PMD 14462 size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4; 14463 p_list = (struct rte_pmd_i40e_profile_list *)malloc(size); 14464 if (!p_list) 14465 printf("%s: Failed to malloc buffer\n", __func__); 14466 14467 if (ret == -ENOTSUP) 14468 ret = rte_pmd_i40e_get_ddp_list(res->port_id, 14469 (uint8_t *)p_list, size); 14470 14471 if (!ret) { 14472 p_num = p_list->p_count; 14473 printf("Profile number is: %d\n\n", p_num); 14474 14475 for (i = 0; i < p_num; i++) { 14476 p_info = &p_list->p_info[i]; 14477 printf("Profile %d:\n", i); 14478 printf("Track id: 0x%x\n", p_info->track_id); 14479 printf("Version: %d.%d.%d.%d\n", 14480 p_info->version.major, 14481 p_info->version.minor, 14482 p_info->version.update, 14483 p_info->version.draft); 14484 printf("Profile name: %s\n\n", p_info->name); 14485 } 14486 } 14487 14488 free(p_list); 14489 #endif 14490 14491 if (ret < 0) 14492 printf("Failed to get ddp list\n"); 14493 } 14494 14495 cmdline_parse_inst_t cmd_ddp_get_list = { 14496 .f = cmd_ddp_get_list_parsed, 14497 .data = NULL, 14498 .help_str = "ddp get list <port_id>", 14499 .tokens = { 14500 (void *)&cmd_ddp_get_list_ddp, 14501 (void *)&cmd_ddp_get_list_get, 14502 (void *)&cmd_ddp_get_list_list, 14503 (void *)&cmd_ddp_get_list_port_id, 14504 NULL, 14505 }, 14506 }; 14507 14508 /* show vf stats */ 14509 14510 /* Common result structure for show vf stats */ 14511 struct cmd_show_vf_stats_result { 14512 cmdline_fixed_string_t show; 14513 cmdline_fixed_string_t vf; 14514 cmdline_fixed_string_t stats; 14515 uint8_t port_id; 14516 uint16_t vf_id; 14517 }; 14518 14519 /* Common CLI fields show vf stats*/ 14520 cmdline_parse_token_string_t cmd_show_vf_stats_show = 14521 TOKEN_STRING_INITIALIZER 14522 (struct cmd_show_vf_stats_result, 14523 show, "show"); 14524 cmdline_parse_token_string_t cmd_show_vf_stats_vf = 14525 TOKEN_STRING_INITIALIZER 14526 (struct cmd_show_vf_stats_result, 14527 vf, "vf"); 14528 cmdline_parse_token_string_t cmd_show_vf_stats_stats = 14529 TOKEN_STRING_INITIALIZER 14530 (struct cmd_show_vf_stats_result, 14531 stats, "stats"); 14532 cmdline_parse_token_num_t cmd_show_vf_stats_port_id = 14533 TOKEN_NUM_INITIALIZER 14534 (struct cmd_show_vf_stats_result, 14535 port_id, UINT8); 14536 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id = 14537 TOKEN_NUM_INITIALIZER 14538 (struct cmd_show_vf_stats_result, 14539 vf_id, UINT16); 14540 14541 static void 14542 cmd_show_vf_stats_parsed( 14543 void *parsed_result, 14544 __attribute__((unused)) struct cmdline *cl, 14545 __attribute__((unused)) void *data) 14546 { 14547 struct cmd_show_vf_stats_result *res = parsed_result; 14548 struct rte_eth_stats stats; 14549 int ret = -ENOTSUP; 14550 static const char *nic_stats_border = "########################"; 14551 14552 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14553 return; 14554 14555 memset(&stats, 0, sizeof(stats)); 14556 14557 #ifdef RTE_LIBRTE_I40E_PMD 14558 if (ret == -ENOTSUP) 14559 ret = rte_pmd_i40e_get_vf_stats(res->port_id, 14560 res->vf_id, 14561 &stats); 14562 #endif 14563 #ifdef RTE_LIBRTE_BNXT_PMD 14564 if (ret == -ENOTSUP) 14565 ret = rte_pmd_bnxt_get_vf_stats(res->port_id, 14566 res->vf_id, 14567 &stats); 14568 #endif 14569 14570 switch (ret) { 14571 case 0: 14572 break; 14573 case -EINVAL: 14574 printf("invalid vf_id %d\n", res->vf_id); 14575 break; 14576 case -ENODEV: 14577 printf("invalid port_id %d\n", res->port_id); 14578 break; 14579 case -ENOTSUP: 14580 printf("function not implemented\n"); 14581 break; 14582 default: 14583 printf("programming error: (%s)\n", strerror(-ret)); 14584 } 14585 14586 printf("\n %s NIC statistics for port %-2d vf %-2d %s\n", 14587 nic_stats_border, res->port_id, res->vf_id, nic_stats_border); 14588 14589 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 14590 "%-"PRIu64"\n", 14591 stats.ipackets, stats.imissed, stats.ibytes); 14592 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 14593 printf(" RX-nombuf: %-10"PRIu64"\n", 14594 stats.rx_nombuf); 14595 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 14596 "%-"PRIu64"\n", 14597 stats.opackets, stats.oerrors, stats.obytes); 14598 14599 printf(" %s############################%s\n", 14600 nic_stats_border, nic_stats_border); 14601 } 14602 14603 cmdline_parse_inst_t cmd_show_vf_stats = { 14604 .f = cmd_show_vf_stats_parsed, 14605 .data = NULL, 14606 .help_str = "show vf stats <port_id> <vf_id>", 14607 .tokens = { 14608 (void *)&cmd_show_vf_stats_show, 14609 (void *)&cmd_show_vf_stats_vf, 14610 (void *)&cmd_show_vf_stats_stats, 14611 (void *)&cmd_show_vf_stats_port_id, 14612 (void *)&cmd_show_vf_stats_vf_id, 14613 NULL, 14614 }, 14615 }; 14616 14617 /* clear vf stats */ 14618 14619 /* Common result structure for clear vf stats */ 14620 struct cmd_clear_vf_stats_result { 14621 cmdline_fixed_string_t clear; 14622 cmdline_fixed_string_t vf; 14623 cmdline_fixed_string_t stats; 14624 uint8_t port_id; 14625 uint16_t vf_id; 14626 }; 14627 14628 /* Common CLI fields clear vf stats*/ 14629 cmdline_parse_token_string_t cmd_clear_vf_stats_clear = 14630 TOKEN_STRING_INITIALIZER 14631 (struct cmd_clear_vf_stats_result, 14632 clear, "clear"); 14633 cmdline_parse_token_string_t cmd_clear_vf_stats_vf = 14634 TOKEN_STRING_INITIALIZER 14635 (struct cmd_clear_vf_stats_result, 14636 vf, "vf"); 14637 cmdline_parse_token_string_t cmd_clear_vf_stats_stats = 14638 TOKEN_STRING_INITIALIZER 14639 (struct cmd_clear_vf_stats_result, 14640 stats, "stats"); 14641 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id = 14642 TOKEN_NUM_INITIALIZER 14643 (struct cmd_clear_vf_stats_result, 14644 port_id, UINT8); 14645 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id = 14646 TOKEN_NUM_INITIALIZER 14647 (struct cmd_clear_vf_stats_result, 14648 vf_id, UINT16); 14649 14650 static void 14651 cmd_clear_vf_stats_parsed( 14652 void *parsed_result, 14653 __attribute__((unused)) struct cmdline *cl, 14654 __attribute__((unused)) void *data) 14655 { 14656 struct cmd_clear_vf_stats_result *res = parsed_result; 14657 int ret = -ENOTSUP; 14658 14659 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14660 return; 14661 14662 #ifdef RTE_LIBRTE_I40E_PMD 14663 if (ret == -ENOTSUP) 14664 ret = rte_pmd_i40e_reset_vf_stats(res->port_id, 14665 res->vf_id); 14666 #endif 14667 #ifdef RTE_LIBRTE_BNXT_PMD 14668 if (ret == -ENOTSUP) 14669 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id, 14670 res->vf_id); 14671 #endif 14672 14673 switch (ret) { 14674 case 0: 14675 break; 14676 case -EINVAL: 14677 printf("invalid vf_id %d\n", res->vf_id); 14678 break; 14679 case -ENODEV: 14680 printf("invalid port_id %d\n", res->port_id); 14681 break; 14682 case -ENOTSUP: 14683 printf("function not implemented\n"); 14684 break; 14685 default: 14686 printf("programming error: (%s)\n", strerror(-ret)); 14687 } 14688 } 14689 14690 cmdline_parse_inst_t cmd_clear_vf_stats = { 14691 .f = cmd_clear_vf_stats_parsed, 14692 .data = NULL, 14693 .help_str = "clear vf stats <port_id> <vf_id>", 14694 .tokens = { 14695 (void *)&cmd_clear_vf_stats_clear, 14696 (void *)&cmd_clear_vf_stats_vf, 14697 (void *)&cmd_clear_vf_stats_stats, 14698 (void *)&cmd_clear_vf_stats_port_id, 14699 (void *)&cmd_clear_vf_stats_vf_id, 14700 NULL, 14701 }, 14702 }; 14703 14704 /* port config pctype mapping reset */ 14705 14706 /* Common result structure for port config pctype mapping reset */ 14707 struct cmd_pctype_mapping_reset_result { 14708 cmdline_fixed_string_t port; 14709 cmdline_fixed_string_t config; 14710 uint8_t port_id; 14711 cmdline_fixed_string_t pctype; 14712 cmdline_fixed_string_t mapping; 14713 cmdline_fixed_string_t reset; 14714 }; 14715 14716 /* Common CLI fields for port config pctype mapping reset*/ 14717 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port = 14718 TOKEN_STRING_INITIALIZER 14719 (struct cmd_pctype_mapping_reset_result, 14720 port, "port"); 14721 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config = 14722 TOKEN_STRING_INITIALIZER 14723 (struct cmd_pctype_mapping_reset_result, 14724 config, "config"); 14725 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id = 14726 TOKEN_NUM_INITIALIZER 14727 (struct cmd_pctype_mapping_reset_result, 14728 port_id, UINT8); 14729 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype = 14730 TOKEN_STRING_INITIALIZER 14731 (struct cmd_pctype_mapping_reset_result, 14732 pctype, "pctype"); 14733 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping = 14734 TOKEN_STRING_INITIALIZER 14735 (struct cmd_pctype_mapping_reset_result, 14736 mapping, "mapping"); 14737 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset = 14738 TOKEN_STRING_INITIALIZER 14739 (struct cmd_pctype_mapping_reset_result, 14740 reset, "reset"); 14741 14742 static void 14743 cmd_pctype_mapping_reset_parsed( 14744 void *parsed_result, 14745 __attribute__((unused)) struct cmdline *cl, 14746 __attribute__((unused)) void *data) 14747 { 14748 struct cmd_pctype_mapping_reset_result *res = parsed_result; 14749 int ret = -ENOTSUP; 14750 14751 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14752 return; 14753 14754 #ifdef RTE_LIBRTE_I40E_PMD 14755 ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id); 14756 #endif 14757 14758 switch (ret) { 14759 case 0: 14760 break; 14761 case -ENODEV: 14762 printf("invalid port_id %d\n", res->port_id); 14763 break; 14764 case -ENOTSUP: 14765 printf("function not implemented\n"); 14766 break; 14767 default: 14768 printf("programming error: (%s)\n", strerror(-ret)); 14769 } 14770 } 14771 14772 cmdline_parse_inst_t cmd_pctype_mapping_reset = { 14773 .f = cmd_pctype_mapping_reset_parsed, 14774 .data = NULL, 14775 .help_str = "port config <port_id> pctype mapping reset", 14776 .tokens = { 14777 (void *)&cmd_pctype_mapping_reset_port, 14778 (void *)&cmd_pctype_mapping_reset_config, 14779 (void *)&cmd_pctype_mapping_reset_port_id, 14780 (void *)&cmd_pctype_mapping_reset_pctype, 14781 (void *)&cmd_pctype_mapping_reset_mapping, 14782 (void *)&cmd_pctype_mapping_reset_reset, 14783 NULL, 14784 }, 14785 }; 14786 14787 /* show port pctype mapping */ 14788 14789 /* Common result structure for show port pctype mapping */ 14790 struct cmd_pctype_mapping_get_result { 14791 cmdline_fixed_string_t show; 14792 cmdline_fixed_string_t port; 14793 uint8_t port_id; 14794 cmdline_fixed_string_t pctype; 14795 cmdline_fixed_string_t mapping; 14796 }; 14797 14798 /* Common CLI fields for pctype mapping get */ 14799 cmdline_parse_token_string_t cmd_pctype_mapping_get_show = 14800 TOKEN_STRING_INITIALIZER 14801 (struct cmd_pctype_mapping_get_result, 14802 show, "show"); 14803 cmdline_parse_token_string_t cmd_pctype_mapping_get_port = 14804 TOKEN_STRING_INITIALIZER 14805 (struct cmd_pctype_mapping_get_result, 14806 port, "port"); 14807 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id = 14808 TOKEN_NUM_INITIALIZER 14809 (struct cmd_pctype_mapping_get_result, 14810 port_id, UINT8); 14811 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype = 14812 TOKEN_STRING_INITIALIZER 14813 (struct cmd_pctype_mapping_get_result, 14814 pctype, "pctype"); 14815 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping = 14816 TOKEN_STRING_INITIALIZER 14817 (struct cmd_pctype_mapping_get_result, 14818 mapping, "mapping"); 14819 14820 static void 14821 cmd_pctype_mapping_get_parsed( 14822 void *parsed_result, 14823 __attribute__((unused)) struct cmdline *cl, 14824 __attribute__((unused)) void *data) 14825 { 14826 struct cmd_pctype_mapping_get_result *res = parsed_result; 14827 int ret = -ENOTSUP; 14828 #ifdef RTE_LIBRTE_I40E_PMD 14829 struct rte_pmd_i40e_flow_type_mapping 14830 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; 14831 int i, j, first_pctype; 14832 #endif 14833 14834 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14835 return; 14836 14837 #ifdef RTE_LIBRTE_I40E_PMD 14838 ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping); 14839 #endif 14840 14841 switch (ret) { 14842 case 0: 14843 break; 14844 case -ENODEV: 14845 printf("invalid port_id %d\n", res->port_id); 14846 return; 14847 case -ENOTSUP: 14848 printf("function not implemented\n"); 14849 return; 14850 default: 14851 printf("programming error: (%s)\n", strerror(-ret)); 14852 return; 14853 } 14854 14855 #ifdef RTE_LIBRTE_I40E_PMD 14856 for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) { 14857 if (mapping[i].pctype != 0ULL) { 14858 first_pctype = 1; 14859 14860 printf("pctype: "); 14861 for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) { 14862 if (mapping[i].pctype & (1ULL << j)) { 14863 printf(first_pctype ? 14864 "%02d" : ",%02d", j); 14865 first_pctype = 0; 14866 } 14867 } 14868 printf(" -> flowtype: %02d\n", mapping[i].flow_type); 14869 } 14870 } 14871 #endif 14872 } 14873 14874 cmdline_parse_inst_t cmd_pctype_mapping_get = { 14875 .f = cmd_pctype_mapping_get_parsed, 14876 .data = NULL, 14877 .help_str = "show port <port_id> pctype mapping", 14878 .tokens = { 14879 (void *)&cmd_pctype_mapping_get_show, 14880 (void *)&cmd_pctype_mapping_get_port, 14881 (void *)&cmd_pctype_mapping_get_port_id, 14882 (void *)&cmd_pctype_mapping_get_pctype, 14883 (void *)&cmd_pctype_mapping_get_mapping, 14884 NULL, 14885 }, 14886 }; 14887 14888 /* port config pctype mapping update */ 14889 14890 /* Common result structure for port config pctype mapping update */ 14891 struct cmd_pctype_mapping_update_result { 14892 cmdline_fixed_string_t port; 14893 cmdline_fixed_string_t config; 14894 uint8_t port_id; 14895 cmdline_fixed_string_t pctype; 14896 cmdline_fixed_string_t mapping; 14897 cmdline_fixed_string_t update; 14898 cmdline_fixed_string_t pctype_list; 14899 uint16_t flow_type; 14900 }; 14901 14902 /* Common CLI fields for pctype mapping update*/ 14903 cmdline_parse_token_string_t cmd_pctype_mapping_update_port = 14904 TOKEN_STRING_INITIALIZER 14905 (struct cmd_pctype_mapping_update_result, 14906 port, "port"); 14907 cmdline_parse_token_string_t cmd_pctype_mapping_update_config = 14908 TOKEN_STRING_INITIALIZER 14909 (struct cmd_pctype_mapping_update_result, 14910 config, "config"); 14911 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id = 14912 TOKEN_NUM_INITIALIZER 14913 (struct cmd_pctype_mapping_update_result, 14914 port_id, UINT8); 14915 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype = 14916 TOKEN_STRING_INITIALIZER 14917 (struct cmd_pctype_mapping_update_result, 14918 pctype, "pctype"); 14919 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping = 14920 TOKEN_STRING_INITIALIZER 14921 (struct cmd_pctype_mapping_update_result, 14922 mapping, "mapping"); 14923 cmdline_parse_token_string_t cmd_pctype_mapping_update_update = 14924 TOKEN_STRING_INITIALIZER 14925 (struct cmd_pctype_mapping_update_result, 14926 update, "update"); 14927 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type = 14928 TOKEN_STRING_INITIALIZER 14929 (struct cmd_pctype_mapping_update_result, 14930 pctype_list, NULL); 14931 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type = 14932 TOKEN_NUM_INITIALIZER 14933 (struct cmd_pctype_mapping_update_result, 14934 flow_type, UINT16); 14935 14936 static void 14937 cmd_pctype_mapping_update_parsed( 14938 void *parsed_result, 14939 __attribute__((unused)) struct cmdline *cl, 14940 __attribute__((unused)) void *data) 14941 { 14942 struct cmd_pctype_mapping_update_result *res = parsed_result; 14943 int ret = -ENOTSUP; 14944 #ifdef RTE_LIBRTE_I40E_PMD 14945 struct rte_pmd_i40e_flow_type_mapping mapping; 14946 unsigned int i; 14947 unsigned int nb_item; 14948 unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX]; 14949 #endif 14950 14951 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14952 return; 14953 14954 #ifdef RTE_LIBRTE_I40E_PMD 14955 nb_item = parse_item_list(res->pctype_list, "pctypes", 14956 RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1); 14957 mapping.flow_type = res->flow_type; 14958 for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++) 14959 mapping.pctype |= (1ULL << pctype_list[i]); 14960 ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id, 14961 &mapping, 14962 1, 14963 0); 14964 #endif 14965 14966 switch (ret) { 14967 case 0: 14968 break; 14969 case -EINVAL: 14970 printf("invalid pctype or flow type\n"); 14971 break; 14972 case -ENODEV: 14973 printf("invalid port_id %d\n", res->port_id); 14974 break; 14975 case -ENOTSUP: 14976 printf("function not implemented\n"); 14977 break; 14978 default: 14979 printf("programming error: (%s)\n", strerror(-ret)); 14980 } 14981 } 14982 14983 cmdline_parse_inst_t cmd_pctype_mapping_update = { 14984 .f = cmd_pctype_mapping_update_parsed, 14985 .data = NULL, 14986 .help_str = "port config <port_id> pctype mapping update" 14987 " <pctype_id_0,[pctype_id_1]*> <flowtype_id>", 14988 .tokens = { 14989 (void *)&cmd_pctype_mapping_update_port, 14990 (void *)&cmd_pctype_mapping_update_config, 14991 (void *)&cmd_pctype_mapping_update_port_id, 14992 (void *)&cmd_pctype_mapping_update_pctype, 14993 (void *)&cmd_pctype_mapping_update_mapping, 14994 (void *)&cmd_pctype_mapping_update_update, 14995 (void *)&cmd_pctype_mapping_update_pc_type, 14996 (void *)&cmd_pctype_mapping_update_flow_type, 14997 NULL, 14998 }, 14999 }; 15000 15001 /* ptype mapping get */ 15002 15003 /* Common result structure for ptype mapping get */ 15004 struct cmd_ptype_mapping_get_result { 15005 cmdline_fixed_string_t ptype; 15006 cmdline_fixed_string_t mapping; 15007 cmdline_fixed_string_t get; 15008 uint8_t port_id; 15009 uint8_t valid_only; 15010 }; 15011 15012 /* Common CLI fields for ptype mapping get */ 15013 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype = 15014 TOKEN_STRING_INITIALIZER 15015 (struct cmd_ptype_mapping_get_result, 15016 ptype, "ptype"); 15017 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping = 15018 TOKEN_STRING_INITIALIZER 15019 (struct cmd_ptype_mapping_get_result, 15020 mapping, "mapping"); 15021 cmdline_parse_token_string_t cmd_ptype_mapping_get_get = 15022 TOKEN_STRING_INITIALIZER 15023 (struct cmd_ptype_mapping_get_result, 15024 get, "get"); 15025 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id = 15026 TOKEN_NUM_INITIALIZER 15027 (struct cmd_ptype_mapping_get_result, 15028 port_id, UINT8); 15029 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only = 15030 TOKEN_NUM_INITIALIZER 15031 (struct cmd_ptype_mapping_get_result, 15032 valid_only, UINT8); 15033 15034 static void 15035 cmd_ptype_mapping_get_parsed( 15036 void *parsed_result, 15037 __attribute__((unused)) struct cmdline *cl, 15038 __attribute__((unused)) void *data) 15039 { 15040 struct cmd_ptype_mapping_get_result *res = parsed_result; 15041 int ret = -ENOTSUP; 15042 #ifdef RTE_LIBRTE_I40E_PMD 15043 int max_ptype_num = 256; 15044 struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num]; 15045 uint16_t count; 15046 int i; 15047 #endif 15048 15049 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15050 return; 15051 15052 #ifdef RTE_LIBRTE_I40E_PMD 15053 ret = rte_pmd_i40e_ptype_mapping_get(res->port_id, 15054 mapping, 15055 max_ptype_num, 15056 &count, 15057 res->valid_only); 15058 #endif 15059 15060 switch (ret) { 15061 case 0: 15062 break; 15063 case -ENODEV: 15064 printf("invalid port_id %d\n", res->port_id); 15065 break; 15066 case -ENOTSUP: 15067 printf("function not implemented\n"); 15068 break; 15069 default: 15070 printf("programming error: (%s)\n", strerror(-ret)); 15071 } 15072 15073 #ifdef RTE_LIBRTE_I40E_PMD 15074 if (!ret) { 15075 for (i = 0; i < count; i++) 15076 printf("%3d\t0x%08x\n", 15077 mapping[i].hw_ptype, mapping[i].sw_ptype); 15078 } 15079 #endif 15080 } 15081 15082 cmdline_parse_inst_t cmd_ptype_mapping_get = { 15083 .f = cmd_ptype_mapping_get_parsed, 15084 .data = NULL, 15085 .help_str = "ptype mapping get <port_id> <valid_only>", 15086 .tokens = { 15087 (void *)&cmd_ptype_mapping_get_ptype, 15088 (void *)&cmd_ptype_mapping_get_mapping, 15089 (void *)&cmd_ptype_mapping_get_get, 15090 (void *)&cmd_ptype_mapping_get_port_id, 15091 (void *)&cmd_ptype_mapping_get_valid_only, 15092 NULL, 15093 }, 15094 }; 15095 15096 /* ptype mapping replace */ 15097 15098 /* Common result structure for ptype mapping replace */ 15099 struct cmd_ptype_mapping_replace_result { 15100 cmdline_fixed_string_t ptype; 15101 cmdline_fixed_string_t mapping; 15102 cmdline_fixed_string_t replace; 15103 uint8_t port_id; 15104 uint32_t target; 15105 uint8_t mask; 15106 uint32_t pkt_type; 15107 }; 15108 15109 /* Common CLI fields for ptype mapping replace */ 15110 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype = 15111 TOKEN_STRING_INITIALIZER 15112 (struct cmd_ptype_mapping_replace_result, 15113 ptype, "ptype"); 15114 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping = 15115 TOKEN_STRING_INITIALIZER 15116 (struct cmd_ptype_mapping_replace_result, 15117 mapping, "mapping"); 15118 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace = 15119 TOKEN_STRING_INITIALIZER 15120 (struct cmd_ptype_mapping_replace_result, 15121 replace, "replace"); 15122 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id = 15123 TOKEN_NUM_INITIALIZER 15124 (struct cmd_ptype_mapping_replace_result, 15125 port_id, UINT8); 15126 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target = 15127 TOKEN_NUM_INITIALIZER 15128 (struct cmd_ptype_mapping_replace_result, 15129 target, UINT32); 15130 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask = 15131 TOKEN_NUM_INITIALIZER 15132 (struct cmd_ptype_mapping_replace_result, 15133 mask, UINT8); 15134 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type = 15135 TOKEN_NUM_INITIALIZER 15136 (struct cmd_ptype_mapping_replace_result, 15137 pkt_type, UINT32); 15138 15139 static void 15140 cmd_ptype_mapping_replace_parsed( 15141 void *parsed_result, 15142 __attribute__((unused)) struct cmdline *cl, 15143 __attribute__((unused)) void *data) 15144 { 15145 struct cmd_ptype_mapping_replace_result *res = parsed_result; 15146 int ret = -ENOTSUP; 15147 15148 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15149 return; 15150 15151 #ifdef RTE_LIBRTE_I40E_PMD 15152 ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id, 15153 res->target, 15154 res->mask, 15155 res->pkt_type); 15156 #endif 15157 15158 switch (ret) { 15159 case 0: 15160 break; 15161 case -EINVAL: 15162 printf("invalid ptype 0x%8x or 0x%8x\n", 15163 res->target, res->pkt_type); 15164 break; 15165 case -ENODEV: 15166 printf("invalid port_id %d\n", res->port_id); 15167 break; 15168 case -ENOTSUP: 15169 printf("function not implemented\n"); 15170 break; 15171 default: 15172 printf("programming error: (%s)\n", strerror(-ret)); 15173 } 15174 } 15175 15176 cmdline_parse_inst_t cmd_ptype_mapping_replace = { 15177 .f = cmd_ptype_mapping_replace_parsed, 15178 .data = NULL, 15179 .help_str = 15180 "ptype mapping replace <port_id> <target> <mask> <pkt_type>", 15181 .tokens = { 15182 (void *)&cmd_ptype_mapping_replace_ptype, 15183 (void *)&cmd_ptype_mapping_replace_mapping, 15184 (void *)&cmd_ptype_mapping_replace_replace, 15185 (void *)&cmd_ptype_mapping_replace_port_id, 15186 (void *)&cmd_ptype_mapping_replace_target, 15187 (void *)&cmd_ptype_mapping_replace_mask, 15188 (void *)&cmd_ptype_mapping_replace_pkt_type, 15189 NULL, 15190 }, 15191 }; 15192 15193 /* ptype mapping reset */ 15194 15195 /* Common result structure for ptype mapping reset */ 15196 struct cmd_ptype_mapping_reset_result { 15197 cmdline_fixed_string_t ptype; 15198 cmdline_fixed_string_t mapping; 15199 cmdline_fixed_string_t reset; 15200 uint8_t port_id; 15201 }; 15202 15203 /* Common CLI fields for ptype mapping reset*/ 15204 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype = 15205 TOKEN_STRING_INITIALIZER 15206 (struct cmd_ptype_mapping_reset_result, 15207 ptype, "ptype"); 15208 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping = 15209 TOKEN_STRING_INITIALIZER 15210 (struct cmd_ptype_mapping_reset_result, 15211 mapping, "mapping"); 15212 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset = 15213 TOKEN_STRING_INITIALIZER 15214 (struct cmd_ptype_mapping_reset_result, 15215 reset, "reset"); 15216 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id = 15217 TOKEN_NUM_INITIALIZER 15218 (struct cmd_ptype_mapping_reset_result, 15219 port_id, UINT8); 15220 15221 static void 15222 cmd_ptype_mapping_reset_parsed( 15223 void *parsed_result, 15224 __attribute__((unused)) struct cmdline *cl, 15225 __attribute__((unused)) void *data) 15226 { 15227 struct cmd_ptype_mapping_reset_result *res = parsed_result; 15228 int ret = -ENOTSUP; 15229 15230 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15231 return; 15232 15233 #ifdef RTE_LIBRTE_I40E_PMD 15234 ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id); 15235 #endif 15236 15237 switch (ret) { 15238 case 0: 15239 break; 15240 case -ENODEV: 15241 printf("invalid port_id %d\n", res->port_id); 15242 break; 15243 case -ENOTSUP: 15244 printf("function not implemented\n"); 15245 break; 15246 default: 15247 printf("programming error: (%s)\n", strerror(-ret)); 15248 } 15249 } 15250 15251 cmdline_parse_inst_t cmd_ptype_mapping_reset = { 15252 .f = cmd_ptype_mapping_reset_parsed, 15253 .data = NULL, 15254 .help_str = "ptype mapping reset <port_id>", 15255 .tokens = { 15256 (void *)&cmd_ptype_mapping_reset_ptype, 15257 (void *)&cmd_ptype_mapping_reset_mapping, 15258 (void *)&cmd_ptype_mapping_reset_reset, 15259 (void *)&cmd_ptype_mapping_reset_port_id, 15260 NULL, 15261 }, 15262 }; 15263 15264 /* ptype mapping update */ 15265 15266 /* Common result structure for ptype mapping update */ 15267 struct cmd_ptype_mapping_update_result { 15268 cmdline_fixed_string_t ptype; 15269 cmdline_fixed_string_t mapping; 15270 cmdline_fixed_string_t reset; 15271 uint8_t port_id; 15272 uint8_t hw_ptype; 15273 uint32_t sw_ptype; 15274 }; 15275 15276 /* Common CLI fields for ptype mapping update*/ 15277 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype = 15278 TOKEN_STRING_INITIALIZER 15279 (struct cmd_ptype_mapping_update_result, 15280 ptype, "ptype"); 15281 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping = 15282 TOKEN_STRING_INITIALIZER 15283 (struct cmd_ptype_mapping_update_result, 15284 mapping, "mapping"); 15285 cmdline_parse_token_string_t cmd_ptype_mapping_update_update = 15286 TOKEN_STRING_INITIALIZER 15287 (struct cmd_ptype_mapping_update_result, 15288 reset, "update"); 15289 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id = 15290 TOKEN_NUM_INITIALIZER 15291 (struct cmd_ptype_mapping_update_result, 15292 port_id, UINT8); 15293 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype = 15294 TOKEN_NUM_INITIALIZER 15295 (struct cmd_ptype_mapping_update_result, 15296 hw_ptype, UINT8); 15297 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype = 15298 TOKEN_NUM_INITIALIZER 15299 (struct cmd_ptype_mapping_update_result, 15300 sw_ptype, UINT32); 15301 15302 static void 15303 cmd_ptype_mapping_update_parsed( 15304 void *parsed_result, 15305 __attribute__((unused)) struct cmdline *cl, 15306 __attribute__((unused)) void *data) 15307 { 15308 struct cmd_ptype_mapping_update_result *res = parsed_result; 15309 int ret = -ENOTSUP; 15310 #ifdef RTE_LIBRTE_I40E_PMD 15311 struct rte_pmd_i40e_ptype_mapping mapping; 15312 #endif 15313 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15314 return; 15315 15316 #ifdef RTE_LIBRTE_I40E_PMD 15317 mapping.hw_ptype = res->hw_ptype; 15318 mapping.sw_ptype = res->sw_ptype; 15319 ret = rte_pmd_i40e_ptype_mapping_update(res->port_id, 15320 &mapping, 15321 1, 15322 0); 15323 #endif 15324 15325 switch (ret) { 15326 case 0: 15327 break; 15328 case -EINVAL: 15329 printf("invalid ptype 0x%8x\n", res->sw_ptype); 15330 break; 15331 case -ENODEV: 15332 printf("invalid port_id %d\n", res->port_id); 15333 break; 15334 case -ENOTSUP: 15335 printf("function not implemented\n"); 15336 break; 15337 default: 15338 printf("programming error: (%s)\n", strerror(-ret)); 15339 } 15340 } 15341 15342 cmdline_parse_inst_t cmd_ptype_mapping_update = { 15343 .f = cmd_ptype_mapping_update_parsed, 15344 .data = NULL, 15345 .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>", 15346 .tokens = { 15347 (void *)&cmd_ptype_mapping_update_ptype, 15348 (void *)&cmd_ptype_mapping_update_mapping, 15349 (void *)&cmd_ptype_mapping_update_update, 15350 (void *)&cmd_ptype_mapping_update_port_id, 15351 (void *)&cmd_ptype_mapping_update_hw_ptype, 15352 (void *)&cmd_ptype_mapping_update_sw_ptype, 15353 NULL, 15354 }, 15355 }; 15356 15357 /* Common result structure for file commands */ 15358 struct cmd_cmdfile_result { 15359 cmdline_fixed_string_t load; 15360 cmdline_fixed_string_t filename; 15361 }; 15362 15363 /* Common CLI fields for file commands */ 15364 cmdline_parse_token_string_t cmd_load_cmdfile = 15365 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load"); 15366 cmdline_parse_token_string_t cmd_load_cmdfile_filename = 15367 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL); 15368 15369 static void 15370 cmd_load_from_file_parsed( 15371 void *parsed_result, 15372 __attribute__((unused)) struct cmdline *cl, 15373 __attribute__((unused)) void *data) 15374 { 15375 struct cmd_cmdfile_result *res = parsed_result; 15376 15377 cmdline_read_from_file(res->filename); 15378 } 15379 15380 cmdline_parse_inst_t cmd_load_from_file = { 15381 .f = cmd_load_from_file_parsed, 15382 .data = NULL, 15383 .help_str = "load <filename>", 15384 .tokens = { 15385 (void *)&cmd_load_cmdfile, 15386 (void *)&cmd_load_cmdfile_filename, 15387 NULL, 15388 }, 15389 }; 15390 15391 /* ******************************************************************************** */ 15392 15393 /* list of instructions */ 15394 cmdline_parse_ctx_t main_ctx[] = { 15395 (cmdline_parse_inst_t *)&cmd_help_brief, 15396 (cmdline_parse_inst_t *)&cmd_help_long, 15397 (cmdline_parse_inst_t *)&cmd_quit, 15398 (cmdline_parse_inst_t *)&cmd_load_from_file, 15399 (cmdline_parse_inst_t *)&cmd_showport, 15400 (cmdline_parse_inst_t *)&cmd_showqueue, 15401 (cmdline_parse_inst_t *)&cmd_showportall, 15402 (cmdline_parse_inst_t *)&cmd_showcfg, 15403 (cmdline_parse_inst_t *)&cmd_start, 15404 (cmdline_parse_inst_t *)&cmd_start_tx_first, 15405 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 15406 (cmdline_parse_inst_t *)&cmd_set_link_up, 15407 (cmdline_parse_inst_t *)&cmd_set_link_down, 15408 (cmdline_parse_inst_t *)&cmd_reset, 15409 (cmdline_parse_inst_t *)&cmd_set_numbers, 15410 (cmdline_parse_inst_t *)&cmd_set_txpkts, 15411 (cmdline_parse_inst_t *)&cmd_set_txsplit, 15412 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 15413 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 15414 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 15415 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 15416 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 15417 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 15418 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 15419 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 15420 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 15421 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 15422 (cmdline_parse_inst_t *)&cmd_set_link_check, 15423 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 15424 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 15425 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 15426 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 15427 #ifdef RTE_LIBRTE_PMD_BOND 15428 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 15429 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 15430 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 15431 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 15432 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 15433 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 15434 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 15435 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 15436 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 15437 (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues, 15438 (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy, 15439 #endif 15440 (cmdline_parse_inst_t *)&cmd_vlan_offload, 15441 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 15442 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 15443 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 15444 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 15445 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 15446 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 15447 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 15448 (cmdline_parse_inst_t *)&cmd_csum_set, 15449 (cmdline_parse_inst_t *)&cmd_csum_show, 15450 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 15451 (cmdline_parse_inst_t *)&cmd_tso_set, 15452 (cmdline_parse_inst_t *)&cmd_tso_show, 15453 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 15454 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 15455 (cmdline_parse_inst_t *)&cmd_gro_enable, 15456 (cmdline_parse_inst_t *)&cmd_gro_flush, 15457 (cmdline_parse_inst_t *)&cmd_gro_show, 15458 (cmdline_parse_inst_t *)&cmd_gso_enable, 15459 (cmdline_parse_inst_t *)&cmd_gso_size, 15460 (cmdline_parse_inst_t *)&cmd_gso_show, 15461 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 15462 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 15463 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 15464 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 15465 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 15466 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 15467 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 15468 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 15469 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 15470 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 15471 (cmdline_parse_inst_t *)&cmd_config_dcb, 15472 (cmdline_parse_inst_t *)&cmd_read_reg, 15473 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 15474 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 15475 (cmdline_parse_inst_t *)&cmd_write_reg, 15476 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 15477 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 15478 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 15479 (cmdline_parse_inst_t *)&cmd_stop, 15480 (cmdline_parse_inst_t *)&cmd_mac_addr, 15481 (cmdline_parse_inst_t *)&cmd_set_qmap, 15482 (cmdline_parse_inst_t *)&cmd_operate_port, 15483 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 15484 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 15485 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 15486 (cmdline_parse_inst_t *)&cmd_config_speed_all, 15487 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 15488 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 15489 (cmdline_parse_inst_t *)&cmd_config_mtu, 15490 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 15491 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 15492 (cmdline_parse_inst_t *)&cmd_config_rss, 15493 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 15494 (cmdline_parse_inst_t *)&cmd_config_txqflags, 15495 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 15496 (cmdline_parse_inst_t *)&cmd_showport_reta, 15497 (cmdline_parse_inst_t *)&cmd_config_burst, 15498 (cmdline_parse_inst_t *)&cmd_config_thresh, 15499 (cmdline_parse_inst_t *)&cmd_config_threshold, 15500 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 15501 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 15502 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 15503 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 15504 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 15505 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 15506 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 15507 (cmdline_parse_inst_t *)&cmd_global_config, 15508 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 15509 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 15510 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 15511 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 15512 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 15513 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 15514 (cmdline_parse_inst_t *)&cmd_dump, 15515 (cmdline_parse_inst_t *)&cmd_dump_one, 15516 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 15517 (cmdline_parse_inst_t *)&cmd_syn_filter, 15518 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 15519 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 15520 (cmdline_parse_inst_t *)&cmd_flex_filter, 15521 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 15522 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 15523 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 15524 (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director, 15525 (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director, 15526 (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director, 15527 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 15528 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 15529 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 15530 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 15531 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 15532 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 15533 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 15534 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 15535 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 15536 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 15537 (cmdline_parse_inst_t *)&cmd_set_hash_input_set, 15538 (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, 15539 (cmdline_parse_inst_t *)&cmd_flow, 15540 (cmdline_parse_inst_t *)&cmd_mcast_addr, 15541 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, 15542 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, 15543 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all, 15544 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific, 15545 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en, 15546 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis, 15547 (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis, 15548 (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis, 15549 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add, 15550 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del, 15551 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 15552 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 15553 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 15554 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 15555 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 15556 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 15557 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 15558 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 15559 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 15560 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 15561 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 15562 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 15563 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 15564 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 15565 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 15566 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 15567 (cmdline_parse_inst_t *)&cmd_set_vf_promisc, 15568 (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, 15569 (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, 15570 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, 15571 (cmdline_parse_inst_t *)&cmd_vf_max_bw, 15572 (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw, 15573 (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, 15574 (cmdline_parse_inst_t *)&cmd_strict_link_prio, 15575 (cmdline_parse_inst_t *)&cmd_tc_min_bw, 15576 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 15577 (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default, 15578 #endif 15579 (cmdline_parse_inst_t *)&cmd_ddp_add, 15580 (cmdline_parse_inst_t *)&cmd_ddp_del, 15581 (cmdline_parse_inst_t *)&cmd_ddp_get_list, 15582 (cmdline_parse_inst_t *)&cmd_ddp_get_info, 15583 (cmdline_parse_inst_t *)&cmd_show_vf_stats, 15584 (cmdline_parse_inst_t *)&cmd_clear_vf_stats, 15585 (cmdline_parse_inst_t *)&cmd_ptype_mapping_get, 15586 (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace, 15587 (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset, 15588 (cmdline_parse_inst_t *)&cmd_ptype_mapping_update, 15589 15590 (cmdline_parse_inst_t *)&cmd_pctype_mapping_get, 15591 (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset, 15592 (cmdline_parse_inst_t *)&cmd_pctype_mapping_update, 15593 (cmdline_parse_inst_t *)&cmd_queue_region, 15594 (cmdline_parse_inst_t *)&cmd_region_flowtype, 15595 (cmdline_parse_inst_t *)&cmd_user_priority_region, 15596 (cmdline_parse_inst_t *)&cmd_flush_queue_region, 15597 (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all, 15598 NULL, 15599 }; 15600 15601 /* read cmdline commands from file */ 15602 void 15603 cmdline_read_from_file(const char *filename) 15604 { 15605 struct cmdline *cl; 15606 15607 cl = cmdline_file_new(main_ctx, "testpmd> ", filename); 15608 if (cl == NULL) { 15609 printf("Failed to create file based cmdline context: %s\n", 15610 filename); 15611 return; 15612 } 15613 15614 cmdline_interact(cl); 15615 cmdline_quit(cl); 15616 15617 cmdline_free(cl); 15618 15619 printf("Read CLI commands from %s\n", filename); 15620 } 15621 15622 /* prompt function, called from main on MASTER lcore */ 15623 void 15624 prompt(void) 15625 { 15626 /* initialize non-constant commands */ 15627 cmd_set_fwd_mode_init(); 15628 cmd_set_fwd_retry_mode_init(); 15629 15630 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 15631 if (testpmd_cl == NULL) 15632 return; 15633 cmdline_interact(testpmd_cl); 15634 cmdline_stdin_exit(testpmd_cl); 15635 } 15636 15637 void 15638 prompt_exit(void) 15639 { 15640 if (testpmd_cl != NULL) 15641 cmdline_quit(testpmd_cl); 15642 } 15643 15644 static void 15645 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 15646 { 15647 if (id == (portid_t)RTE_PORT_ALL) { 15648 portid_t pid; 15649 15650 RTE_ETH_FOREACH_DEV(pid) { 15651 /* check if need_reconfig has been set to 1 */ 15652 if (ports[pid].need_reconfig == 0) 15653 ports[pid].need_reconfig = dev; 15654 /* check if need_reconfig_queues has been set to 1 */ 15655 if (ports[pid].need_reconfig_queues == 0) 15656 ports[pid].need_reconfig_queues = queue; 15657 } 15658 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 15659 /* check if need_reconfig has been set to 1 */ 15660 if (ports[id].need_reconfig == 0) 15661 ports[id].need_reconfig = dev; 15662 /* check if need_reconfig_queues has been set to 1 */ 15663 if (ports[id].need_reconfig_queues == 0) 15664 ports[id].need_reconfig_queues = queue; 15665 } 15666 } 15667