1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation. 3 * Copyright(c) 2014 6WIND S.A. 4 */ 5 6 #include <stdarg.h> 7 #include <errno.h> 8 #include <stdio.h> 9 #include <stdint.h> 10 #include <string.h> 11 #include <termios.h> 12 #include <unistd.h> 13 #include <inttypes.h> 14 #ifndef __linux__ 15 #ifndef __FreeBSD__ 16 #include <net/socket.h> 17 #else 18 #include <sys/socket.h> 19 #endif 20 #endif 21 #include <netinet/in.h> 22 23 #include <sys/queue.h> 24 25 #include <rte_common.h> 26 #include <rte_byteorder.h> 27 #include <rte_log.h> 28 #include <rte_debug.h> 29 #include <rte_cycles.h> 30 #include <rte_memory.h> 31 #include <rte_memzone.h> 32 #include <rte_malloc.h> 33 #include <rte_launch.h> 34 #include <rte_eal.h> 35 #include <rte_per_lcore.h> 36 #include <rte_lcore.h> 37 #include <rte_atomic.h> 38 #include <rte_branch_prediction.h> 39 #include <rte_ring.h> 40 #include <rte_mempool.h> 41 #include <rte_interrupts.h> 42 #include <rte_pci.h> 43 #include <rte_ether.h> 44 #include <rte_ethdev.h> 45 #include <rte_string_fns.h> 46 #include <rte_devargs.h> 47 #include <rte_eth_ctrl.h> 48 #include <rte_flow.h> 49 #include <rte_gro.h> 50 51 #include <cmdline_rdline.h> 52 #include <cmdline_parse.h> 53 #include <cmdline_parse_num.h> 54 #include <cmdline_parse_string.h> 55 #include <cmdline_parse_ipaddr.h> 56 #include <cmdline_parse_etheraddr.h> 57 #include <cmdline_socket.h> 58 #include <cmdline.h> 59 #ifdef RTE_LIBRTE_PMD_BOND 60 #include <rte_eth_bond.h> 61 #include <rte_eth_bond_8023ad.h> 62 #endif 63 #ifdef RTE_LIBRTE_DPAA_PMD 64 #include <rte_pmd_dpaa.h> 65 #endif 66 #ifdef RTE_LIBRTE_IXGBE_PMD 67 #include <rte_pmd_ixgbe.h> 68 #endif 69 #ifdef RTE_LIBRTE_I40E_PMD 70 #include <rte_pmd_i40e.h> 71 #endif 72 #ifdef RTE_LIBRTE_BNXT_PMD 73 #include <rte_pmd_bnxt.h> 74 #endif 75 #include "testpmd.h" 76 #include "cmdline_mtr.h" 77 #include "cmdline_tm.h" 78 79 static struct cmdline *testpmd_cl; 80 81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); 82 83 /* *** Help command with introduction. *** */ 84 struct cmd_help_brief_result { 85 cmdline_fixed_string_t help; 86 }; 87 88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result, 89 struct cmdline *cl, 90 __attribute__((unused)) void *data) 91 { 92 cmdline_printf( 93 cl, 94 "\n" 95 "Help is available for the following sections:\n\n" 96 " help control : Start and stop forwarding.\n" 97 " help display : Displaying port, stats and config " 98 "information.\n" 99 " help config : Configuration information.\n" 100 " help ports : Configuring ports.\n" 101 " help registers : Reading and setting port registers.\n" 102 " help filters : Filters configuration help.\n" 103 " help all : All of the above sections.\n\n" 104 ); 105 106 } 107 108 cmdline_parse_token_string_t cmd_help_brief_help = 109 TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help"); 110 111 cmdline_parse_inst_t cmd_help_brief = { 112 .f = cmd_help_brief_parsed, 113 .data = NULL, 114 .help_str = "help: Show help", 115 .tokens = { 116 (void *)&cmd_help_brief_help, 117 NULL, 118 }, 119 }; 120 121 /* *** Help command with help sections. *** */ 122 struct cmd_help_long_result { 123 cmdline_fixed_string_t help; 124 cmdline_fixed_string_t section; 125 }; 126 127 static void cmd_help_long_parsed(void *parsed_result, 128 struct cmdline *cl, 129 __attribute__((unused)) void *data) 130 { 131 int show_all = 0; 132 struct cmd_help_long_result *res = parsed_result; 133 134 if (!strcmp(res->section, "all")) 135 show_all = 1; 136 137 if (show_all || !strcmp(res->section, "control")) { 138 139 cmdline_printf( 140 cl, 141 "\n" 142 "Control forwarding:\n" 143 "-------------------\n\n" 144 145 "start\n" 146 " Start packet forwarding with current configuration.\n\n" 147 148 "start tx_first\n" 149 " Start packet forwarding with current config" 150 " after sending one burst of packets.\n\n" 151 152 "stop\n" 153 " Stop packet forwarding, and display accumulated" 154 " statistics.\n\n" 155 156 "quit\n" 157 " Quit to prompt.\n\n" 158 ); 159 } 160 161 if (show_all || !strcmp(res->section, "display")) { 162 163 cmdline_printf( 164 cl, 165 "\n" 166 "Display:\n" 167 "--------\n\n" 168 169 "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n" 170 " Display information for port_id, or all.\n\n" 171 172 "show port X rss reta (size) (mask0,mask1,...)\n" 173 " Display the rss redirection table entry indicated" 174 " by masks on port X. size is used to indicate the" 175 " hardware supported reta size\n\n" 176 177 "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|" 178 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 179 "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n" 180 " Display the RSS hash functions and RSS hash key" 181 " of port X\n\n" 182 183 "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n" 184 " Clear information for port_id, or all.\n\n" 185 186 "show (rxq|txq) info (port_id) (queue_id)\n" 187 " Display information for configured RX/TX queue.\n\n" 188 189 "show config (rxtx|cores|fwd|txpkts)\n" 190 " Display the given configuration.\n\n" 191 192 "read rxd (port_id) (queue_id) (rxd_id)\n" 193 " Display an RX descriptor of a port RX queue.\n\n" 194 195 "read txd (port_id) (queue_id) (txd_id)\n" 196 " Display a TX descriptor of a port TX queue.\n\n" 197 198 "ddp get list (port_id)\n" 199 " Get ddp profile info list\n\n" 200 201 "ddp get info (profile_path)\n" 202 " Get ddp profile information.\n\n" 203 204 "show vf stats (port_id) (vf_id)\n" 205 " Display a VF's statistics.\n\n" 206 207 "clear vf stats (port_id) (vf_id)\n" 208 " Reset a VF's statistics.\n\n" 209 210 "show port (port_id) pctype mapping\n" 211 " Get flow ptype to pctype mapping on a port\n\n" 212 213 "show port meter stats (port_id) (meter_id) (clear)\n" 214 " Get meter stats on a port\n\n" 215 "show port tm cap (port_id)\n" 216 " Display the port TM capability.\n\n" 217 218 "show port tm level cap (port_id) (level_id)\n" 219 " Display the port TM hierarchical level capability.\n\n" 220 221 "show port tm node cap (port_id) (node_id)\n" 222 " Display the port TM node capability.\n\n" 223 224 "show port tm node type (port_id) (node_id)\n" 225 " Display the port TM node type.\n\n" 226 227 "show port tm node stats (port_id) (node_id) (clear)\n" 228 " Display the port TM node stats.\n\n" 229 230 ); 231 } 232 233 if (show_all || !strcmp(res->section, "config")) { 234 cmdline_printf( 235 cl, 236 "\n" 237 "Configuration:\n" 238 "--------------\n" 239 "Configuration changes only become active when" 240 " forwarding is started/restarted.\n\n" 241 242 "set default\n" 243 " Reset forwarding to the default configuration.\n\n" 244 245 "set verbose (level)\n" 246 " Set the debug verbosity level X.\n\n" 247 248 "set log global|(type) (level)\n" 249 " Set the log level.\n\n" 250 251 "set nbport (num)\n" 252 " Set number of ports.\n\n" 253 254 "set nbcore (num)\n" 255 " Set number of cores.\n\n" 256 257 "set coremask (mask)\n" 258 " Set the forwarding cores hexadecimal mask.\n\n" 259 260 "set portmask (mask)\n" 261 " Set the forwarding ports hexadecimal mask.\n\n" 262 263 "set burst (num)\n" 264 " Set number of packets per burst.\n\n" 265 266 "set burst tx delay (microseconds) retry (num)\n" 267 " Set the transmit delay time and number of retries," 268 " effective when retry is enabled.\n\n" 269 270 "set txpkts (x[,y]*)\n" 271 " Set the length of each segment of TXONLY" 272 " and optionally CSUM packets.\n\n" 273 274 "set txsplit (off|on|rand)\n" 275 " Set the split policy for the TX packets." 276 " Right now only applicable for CSUM and TXONLY" 277 " modes\n\n" 278 279 "set corelist (x[,y]*)\n" 280 " Set the list of forwarding cores.\n\n" 281 282 "set portlist (x[,y]*)\n" 283 " Set the list of forwarding ports.\n\n" 284 285 "set tx loopback (port_id) (on|off)\n" 286 " Enable or disable tx loopback.\n\n" 287 288 "set all queues drop (port_id) (on|off)\n" 289 " Set drop enable bit for all queues.\n\n" 290 291 "set vf split drop (port_id) (vf_id) (on|off)\n" 292 " Set split drop enable bit for a VF from the PF.\n\n" 293 294 "set vf mac antispoof (port_id) (vf_id) (on|off).\n" 295 " Set MAC antispoof for a VF from the PF.\n\n" 296 297 "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" 298 " Enable MACsec offload.\n\n" 299 300 "set macsec offload (port_id) off\n" 301 " Disable MACsec offload.\n\n" 302 303 "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" 304 " Configure MACsec secure connection (SC).\n\n" 305 306 "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" 307 " Configure MACsec secure association (SA).\n\n" 308 309 "set vf broadcast (port_id) (vf_id) (on|off)\n" 310 " Set VF broadcast for a VF from the PF.\n\n" 311 312 "vlan set strip (on|off) (port_id)\n" 313 " Set the VLAN strip on a port.\n\n" 314 315 "vlan set stripq (on|off) (port_id,queue_id)\n" 316 " Set the VLAN strip for a queue on a port.\n\n" 317 318 "set vf vlan stripq (port_id) (vf_id) (on|off)\n" 319 " Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n" 320 321 "set vf vlan insert (port_id) (vf_id) (vlan_id)\n" 322 " Set VLAN insert for a VF from the PF.\n\n" 323 324 "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" 325 " Set VLAN antispoof for a VF from the PF.\n\n" 326 327 "set vf vlan tag (port_id) (vf_id) (on|off)\n" 328 " Set VLAN tag for a VF from the PF.\n\n" 329 330 "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n" 331 " Set a VF's max bandwidth(Mbps).\n\n" 332 333 "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n" 334 " Set all TCs' min bandwidth(%%) on a VF.\n\n" 335 336 "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n" 337 " Set a TC's max bandwidth(Mbps) on a VF.\n\n" 338 339 "set tx strict-link-priority (port_id) (tc_bitmap)\n" 340 " Set some TCs' strict link priority mode on a physical port.\n\n" 341 342 "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" 343 " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" 344 345 "vlan set filter (on|off) (port_id)\n" 346 " Set the VLAN filter on a port.\n\n" 347 348 "vlan set qinq (on|off) (port_id)\n" 349 " Set the VLAN QinQ (extended queue in queue)" 350 " on a port.\n\n" 351 352 "vlan set (inner|outer) tpid (value) (port_id)\n" 353 " Set the VLAN TPID for Packet Filtering on" 354 " a port\n\n" 355 356 "rx_vlan add (vlan_id|all) (port_id)\n" 357 " Add a vlan_id, or all identifiers, to the set" 358 " of VLAN identifiers filtered by port_id.\n\n" 359 360 "rx_vlan rm (vlan_id|all) (port_id)\n" 361 " Remove a vlan_id, or all identifiers, from the set" 362 " of VLAN identifiers filtered by port_id.\n\n" 363 364 "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n" 365 " Add a vlan_id, to the set of VLAN identifiers" 366 "filtered for VF(s) from port_id.\n\n" 367 368 "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n" 369 " Remove a vlan_id, to the set of VLAN identifiers" 370 "filtered for VF(s) from port_id.\n\n" 371 372 "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) " 373 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 374 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 375 " add a tunnel filter of a port.\n\n" 376 377 "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) " 378 "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|" 379 "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n" 380 " remove a tunnel filter of a port.\n\n" 381 382 "rx_vxlan_port add (udp_port) (port_id)\n" 383 " Add an UDP port for VXLAN packet filter on a port\n\n" 384 385 "rx_vxlan_port rm (udp_port) (port_id)\n" 386 " Remove an UDP port for VXLAN packet filter on a port\n\n" 387 388 "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n" 389 " Set hardware insertion of VLAN IDs (single or double VLAN " 390 "depends on the number of VLAN IDs) in packets sent on a port.\n\n" 391 392 "tx_vlan set pvid port_id vlan_id (on|off)\n" 393 " Set port based TX VLAN insertion.\n\n" 394 395 "tx_vlan reset (port_id)\n" 396 " Disable hardware insertion of a VLAN header in" 397 " packets sent on a port.\n\n" 398 399 "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n" 400 " Select hardware or software calculation of the" 401 " checksum when transmitting a packet using the" 402 " csum forward engine.\n" 403 " ip|udp|tcp|sctp always concern the inner layer.\n" 404 " outer-ip concerns the outer IP layer in" 405 " case the packet is recognized as a tunnel packet by" 406 " the forward engine (vxlan, gre and ipip are supported)\n" 407 " Please check the NIC datasheet for HW limits.\n\n" 408 409 "csum parse-tunnel (on|off) (tx_port_id)\n" 410 " If disabled, treat tunnel packets as non-tunneled" 411 " packets (treat inner headers as payload). The port\n" 412 " argument is the port used for TX in csum forward" 413 " engine.\n\n" 414 415 "csum show (port_id)\n" 416 " Display tx checksum offload configuration\n\n" 417 418 "tso set (segsize) (portid)\n" 419 " Enable TCP Segmentation Offload in csum forward" 420 " engine.\n" 421 " Please check the NIC datasheet for HW limits.\n\n" 422 423 "tso show (portid)" 424 " Display the status of TCP Segmentation Offload.\n\n" 425 426 "set port (port_id) gro on|off\n" 427 " Enable or disable Generic Receive Offload in" 428 " csum forwarding engine.\n\n" 429 430 "show port (port_id) gro\n" 431 " Display GRO configuration.\n\n" 432 433 "set gro flush (cycles)\n" 434 " Set the cycle to flush GROed packets from" 435 " reassembly tables.\n\n" 436 437 "set port (port_id) gso (on|off)" 438 " Enable or disable Generic Segmentation Offload in" 439 " csum forwarding engine.\n\n" 440 441 "set gso segsz (length)\n" 442 " Set max packet length for output GSO segments," 443 " including packet header and payload.\n\n" 444 445 "show port (port_id) gso\n" 446 " Show GSO configuration.\n\n" 447 448 "set fwd (%s)\n" 449 " Set packet forwarding mode.\n\n" 450 451 "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n" 452 " Add a MAC address on port_id.\n\n" 453 454 "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n" 455 " Remove a MAC address from port_id.\n\n" 456 457 "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n" 458 " Set the default MAC address for port_id.\n\n" 459 460 "mac_addr add port (port_id) vf (vf_id) (mac_address)\n" 461 " Add a MAC address for a VF on the port.\n\n" 462 463 "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n" 464 " Set the MAC address for a VF from the PF.\n\n" 465 466 "set eth-peer (port_id) (peer_addr)\n" 467 " set the peer address for certain port.\n\n" 468 469 "set port (port_id) uta (mac_address|all) (on|off)\n" 470 " Add/Remove a or all unicast hash filter(s)" 471 "from port X.\n\n" 472 473 "set promisc (port_id|all) (on|off)\n" 474 " Set the promiscuous mode on port_id, or all.\n\n" 475 476 "set allmulti (port_id|all) (on|off)\n" 477 " Set the allmulti mode on port_id, or all.\n\n" 478 479 "set vf promisc (port_id) (vf_id) (on|off)\n" 480 " Set unicast promiscuous mode for a VF from the PF.\n\n" 481 482 "set vf allmulti (port_id) (vf_id) (on|off)\n" 483 " Set multicast promiscuous mode for a VF from the PF.\n\n" 484 485 "set flow_ctrl rx (on|off) tx (on|off) (high_water)" 486 " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd" 487 " (on|off) autoneg (on|off) (port_id)\n" 488 "set flow_ctrl rx (on|off) (portid)\n" 489 "set flow_ctrl tx (on|off) (portid)\n" 490 "set flow_ctrl high_water (high_water) (portid)\n" 491 "set flow_ctrl low_water (low_water) (portid)\n" 492 "set flow_ctrl pause_time (pause_time) (portid)\n" 493 "set flow_ctrl send_xon (send_xon) (portid)\n" 494 "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n" 495 "set flow_ctrl autoneg (on|off) (port_id)\n" 496 " Set the link flow control parameter on a port.\n\n" 497 498 "set pfc_ctrl rx (on|off) tx (on|off) (high_water)" 499 " (low_water) (pause_time) (priority) (port_id)\n" 500 " Set the priority flow control parameter on a" 501 " port.\n\n" 502 503 "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n" 504 " Set statistics mapping (qmapping 0..15) for RX/TX" 505 " queue on port.\n" 506 " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" 507 " on port 0 to mapping 5.\n\n" 508 509 "set xstats-hide-zero on|off\n" 510 " Set the option to hide the zero values" 511 " for xstats display.\n" 512 513 "set port (port_id) vf (vf_id) rx|tx on|off\n" 514 " Enable/Disable a VF receive/tranmit from a port\n\n" 515 516 "set port (port_id) vf (vf_id) (mac_addr)" 517 " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n" 518 " Add/Remove unicast or multicast MAC addr filter" 519 " for a VF.\n\n" 520 521 "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM" 522 "|MPE) (on|off)\n" 523 " AUPE:accepts untagged VLAN;" 524 "ROPE:accept unicast hash\n\n" 525 " BAM:accepts broadcast packets;" 526 "MPE:accepts all multicast packets\n\n" 527 " Enable/Disable a VF receive mode of a port\n\n" 528 529 "set port (port_id) queue (queue_id) rate (rate_num)\n" 530 " Set rate limit for a queue of a port\n\n" 531 532 "set port (port_id) vf (vf_id) rate (rate_num) " 533 "queue_mask (queue_mask_value)\n" 534 " Set rate limit for queues in VF of a port\n\n" 535 536 "set port (port_id) mirror-rule (rule_id)" 537 " (pool-mirror-up|pool-mirror-down|vlan-mirror)" 538 " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n" 539 " Set pool or vlan type mirror rule on a port.\n" 540 " e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1" 541 " dst-pool 0 on' enable mirror traffic with vlan 0,1" 542 " to pool 0.\n\n" 543 544 "set port (port_id) mirror-rule (rule_id)" 545 " (uplink-mirror|downlink-mirror) dst-pool" 546 " (pool_id) (on|off)\n" 547 " Set uplink or downlink type mirror rule on a port.\n" 548 " e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool" 549 " 0 on' enable mirror income traffic to pool 0.\n\n" 550 551 "reset port (port_id) mirror-rule (rule_id)\n" 552 " Reset a mirror rule.\n\n" 553 554 "set flush_rx (on|off)\n" 555 " Flush (default) or don't flush RX streams before" 556 " forwarding. Mainly used with PCAP drivers.\n\n" 557 558 "set bypass mode (normal|bypass|isolate) (port_id)\n" 559 " Set the bypass mode for the lowest port on bypass enabled" 560 " NIC.\n\n" 561 562 "set bypass event (timeout|os_on|os_off|power_on|power_off) " 563 "mode (normal|bypass|isolate) (port_id)\n" 564 " Set the event required to initiate specified bypass mode for" 565 " the lowest port on a bypass enabled NIC where:\n" 566 " timeout = enable bypass after watchdog timeout.\n" 567 " os_on = enable bypass when OS/board is powered on.\n" 568 " os_off = enable bypass when OS/board is powered off.\n" 569 " power_on = enable bypass when power supply is turned on.\n" 570 " power_off = enable bypass when power supply is turned off." 571 "\n\n" 572 573 "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" 574 " Set the bypass watchdog timeout to 'n' seconds" 575 " where 0 = instant.\n\n" 576 577 "show bypass config (port_id)\n" 578 " Show the bypass configuration for a bypass enabled NIC" 579 " using the lowest port on the NIC.\n\n" 580 581 #ifdef RTE_LIBRTE_PMD_BOND 582 "create bonded device (mode) (socket)\n" 583 " Create a new bonded device with specific bonding mode and socket.\n\n" 584 585 "add bonding slave (slave_id) (port_id)\n" 586 " Add a slave device to a bonded device.\n\n" 587 588 "remove bonding slave (slave_id) (port_id)\n" 589 " Remove a slave device from a bonded device.\n\n" 590 591 "set bonding mode (value) (port_id)\n" 592 " Set the bonding mode on a bonded device.\n\n" 593 594 "set bonding primary (slave_id) (port_id)\n" 595 " Set the primary slave for a bonded device.\n\n" 596 597 "show bonding config (port_id)\n" 598 " Show the bonding config for port_id.\n\n" 599 600 "set bonding mac_addr (port_id) (address)\n" 601 " Set the MAC address of a bonded device.\n\n" 602 603 "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)" 604 " Set Aggregation mode for IEEE802.3AD (mode 4)" 605 606 "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n" 607 " Set the transmit balance policy for bonded device running in balance mode.\n\n" 608 609 "set bonding mon_period (port_id) (value)\n" 610 " Set the bonding link status monitoring polling period in ms.\n\n" 611 612 "set bonding lacp dedicated_queues <port_id> (enable|disable)\n" 613 " Enable/disable dedicated queues for LACP control traffic.\n\n" 614 615 #endif 616 "set link-up port (port_id)\n" 617 " Set link up for a port.\n\n" 618 619 "set link-down port (port_id)\n" 620 " Set link down for a port.\n\n" 621 622 "E-tag set insertion on port-tag-id (value)" 623 " port (port_id) vf (vf_id)\n" 624 " Enable E-tag insertion for a VF on a port\n\n" 625 626 "E-tag set insertion off port (port_id) vf (vf_id)\n" 627 " Disable E-tag insertion for a VF on a port\n\n" 628 629 "E-tag set stripping (on|off) port (port_id)\n" 630 " Enable/disable E-tag stripping on a port\n\n" 631 632 "E-tag set forwarding (on|off) port (port_id)\n" 633 " Enable/disable E-tag based forwarding" 634 " on a port\n\n" 635 636 "E-tag set filter add e-tag-id (value) dst-pool" 637 " (pool_id) port (port_id)\n" 638 " Add an E-tag forwarding filter on a port\n\n" 639 640 "E-tag set filter del e-tag-id (value) port (port_id)\n" 641 " Delete an E-tag forwarding filter on a port\n\n" 642 643 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 644 "set port tm hierarchy default (port_id)\n" 645 " Set default traffic Management hierarchy on a port\n\n" 646 647 #endif 648 "ddp add (port_id) (profile_path[,backup_profile_path])\n" 649 " Load a profile package on a port\n\n" 650 651 "ddp del (port_id) (backup_profile_path)\n" 652 " Delete a profile package from a port\n\n" 653 654 "ptype mapping get (port_id) (valid_only)\n" 655 " Get ptype mapping on a port\n\n" 656 657 "ptype mapping replace (port_id) (target) (mask) (pky_type)\n" 658 " Replace target with the pkt_type in ptype mapping\n\n" 659 660 "ptype mapping reset (port_id)\n" 661 " Reset ptype mapping on a port\n\n" 662 663 "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n" 664 " Update a ptype mapping item on a port\n\n" 665 666 "set port (port_id) queue-region region_id (value) " 667 "queue_start_index (value) queue_num (value)\n" 668 " Set a queue region on a port\n\n" 669 670 "set port (port_id) queue-region region_id (value) " 671 "flowtype (value)\n" 672 " Set a flowtype region index on a port\n\n" 673 674 "set port (port_id) queue-region UP (value) region_id (value)\n" 675 " Set the mapping of User Priority to " 676 "queue region on a port\n\n" 677 678 "set port (port_id) queue-region flush (on|off)\n" 679 " flush all queue region related configuration\n\n" 680 681 "show port meter cap (port_id)\n" 682 " Show port meter capability information\n\n" 683 684 "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n" 685 " meter profile add - srtcm rfc 2697\n\n" 686 687 "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n" 688 " meter profile add - trtcm rfc 2698\n\n" 689 690 "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n" 691 " meter profile add - trtcm rfc 4115\n\n" 692 693 "del port meter profile (port_id) (profile_id)\n" 694 " meter profile delete\n\n" 695 696 "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n" 697 "(g_action) (y_action) (r_action) (stats_mask) (shared)\n" 698 "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n" 699 "(dscp_tbl_entry63)]\n" 700 " meter create\n\n" 701 702 "enable port meter (port_id) (mtr_id)\n" 703 " meter enable\n\n" 704 705 "disable port meter (port_id) (mtr_id)\n" 706 " meter disable\n\n" 707 708 "del port meter (port_id) (mtr_id)\n" 709 " meter delete\n\n" 710 711 "set port meter profile (port_id) (mtr_id) (profile_id)\n" 712 " meter update meter profile\n\n" 713 714 "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n" 715 "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n" 716 " update meter dscp table entries\n\n" 717 718 "set port meter policer action (port_id) (mtr_id) (action_mask)\n" 719 "(action0) [(action1) (action2)]\n" 720 " meter update policer action\n\n" 721 722 "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n" 723 " meter update stats\n\n" 724 725 "show port (port_id) queue-region\n" 726 " show all queue region related configuration info\n\n" 727 728 "add port tm node shaper profile (port_id) (shaper_profile_id)" 729 " (tb_rate) (tb_size) (packet_length_adjust)\n" 730 " Add port tm node private shaper profile.\n\n" 731 732 "del port tm node shaper profile (port_id) (shaper_profile_id)\n" 733 " Delete port tm node private shaper profile.\n\n" 734 735 "add port tm node shared shaper (port_id) (shared_shaper_id)" 736 " (shaper_profile_id)\n" 737 " Add/update port tm node shared shaper.\n\n" 738 739 "del port tm node shared shaper (port_id) (shared_shaper_id)\n" 740 " Delete port tm node shared shaper.\n\n" 741 742 "set port tm node shaper profile (port_id) (node_id)" 743 " (shaper_profile_id)\n" 744 " Set port tm node shaper profile.\n\n" 745 746 "add port tm node wred profile (port_id) (wred_profile_id)" 747 " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)" 748 " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)" 749 " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n" 750 " Add port tm node wred profile.\n\n" 751 752 "del port tm node wred profile (port_id) (wred_profile_id)\n" 753 " Delete port tm node wred profile.\n\n" 754 755 "add port tm nonleaf node (port_id) (node_id) (parent_node_id)" 756 " (priority) (weight) (level_id) (shaper_profile_id)" 757 " (n_sp_priorities) (stats_mask) (n_shared_shapers)" 758 " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" 759 " Add port tm nonleaf node.\n\n" 760 761 "add port tm leaf node (port_id) (node_id) (parent_node_id)" 762 " (priority) (weight) (level_id) (shaper_profile_id)" 763 " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)" 764 " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" 765 " Add port tm leaf node.\n\n" 766 767 "del port tm node (port_id) (node_id)\n" 768 " Delete port tm node.\n\n" 769 770 "set port tm node parent (port_id) (node_id) (parent_node_id)" 771 " (priority) (weight)\n" 772 " Set port tm node parent.\n\n" 773 774 "port tm hierarchy commit (port_id) (clean_on_fail)\n" 775 " Commit tm hierarchy.\n\n" 776 777 , list_pkt_forwarding_modes() 778 ); 779 } 780 781 if (show_all || !strcmp(res->section, "ports")) { 782 783 cmdline_printf( 784 cl, 785 "\n" 786 "Port Operations:\n" 787 "----------------\n\n" 788 789 "port start (port_id|all)\n" 790 " Start all ports or port_id.\n\n" 791 792 "port stop (port_id|all)\n" 793 " Stop all ports or port_id.\n\n" 794 795 "port close (port_id|all)\n" 796 " Close all ports or port_id.\n\n" 797 798 "port attach (ident)\n" 799 " Attach physical or virtual dev by pci address or virtual device name\n\n" 800 801 "port detach (port_id)\n" 802 " Detach physical or virtual dev by port_id\n\n" 803 804 "port config (port_id|all)" 805 " speed (10|100|1000|10000|25000|40000|50000|100000|auto)" 806 " duplex (half|full|auto)\n" 807 " Set speed and duplex for all ports or port_id\n\n" 808 809 "port config all (rxq|txq|rxd|txd) (value)\n" 810 " Set number for rxq/txq/rxd/txd.\n\n" 811 812 "port config all max-pkt-len (value)\n" 813 " Set the max packet length.\n\n" 814 815 "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|" 816 "hw-vlan-strip|hw-vlan-extend|drop-en)" 817 " (on|off)\n" 818 " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" 819 " for ports.\n\n" 820 821 "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|" 822 "geneve|nvgre|none|<flowtype_id>)\n" 823 " Set the RSS mode.\n\n" 824 825 "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" 826 " Set the RSS redirection table.\n\n" 827 828 "port config (port_id) dcb vt (on|off) (traffic_class)" 829 " pfc (on|off)\n" 830 " Set the DCB mode.\n\n" 831 832 "port config all burst (value)\n" 833 " Set the number of packets per burst.\n\n" 834 835 "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)" 836 " (value)\n" 837 " Set the ring prefetch/host/writeback threshold" 838 " for tx/rx queue.\n\n" 839 840 "port config all (txfreet|txrst|rxfreet) (value)\n" 841 " Set free threshold for rx/tx, or set" 842 " tx rs bit threshold.\n\n" 843 "port config mtu X value\n" 844 " Set the MTU of port X to a given value\n\n" 845 846 "port (port_id) (rxq|txq) (queue_id) (start|stop)\n" 847 " Start/stop a rx/tx queue of port X. Only take effect" 848 " when port X is started\n\n" 849 850 "port config (port_id|all) l2-tunnel E-tag ether-type" 851 " (value)\n" 852 " Set the value of E-tag ether-type.\n\n" 853 854 "port config (port_id|all) l2-tunnel E-tag" 855 " (enable|disable)\n" 856 " Enable/disable the E-tag support.\n\n" 857 858 "port config (port_id) pctype mapping reset\n" 859 " Reset flow type to pctype mapping on a port\n\n" 860 861 "port config (port_id) pctype mapping update" 862 " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n" 863 " Update a flow type to pctype mapping item on a port\n\n" 864 865 "port config (port_id) pctype (pctype_id) hash_inset|" 866 "fdir_inset|fdir_flx_inset get|set|clear field\n" 867 " (field_idx)\n" 868 " Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n" 869 870 "port config (port_id) pctype (pctype_id) hash_inset|" 871 "fdir_inset|fdir_flx_inset clear all" 872 " Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n" 873 ); 874 } 875 876 if (show_all || !strcmp(res->section, "registers")) { 877 878 cmdline_printf( 879 cl, 880 "\n" 881 "Registers:\n" 882 "----------\n\n" 883 884 "read reg (port_id) (address)\n" 885 " Display value of a port register.\n\n" 886 887 "read regfield (port_id) (address) (bit_x) (bit_y)\n" 888 " Display a port register bit field.\n\n" 889 890 "read regbit (port_id) (address) (bit_x)\n" 891 " Display a single port register bit.\n\n" 892 893 "write reg (port_id) (address) (value)\n" 894 " Set value of a port register.\n\n" 895 896 "write regfield (port_id) (address) (bit_x) (bit_y)" 897 " (value)\n" 898 " Set bit field of a port register.\n\n" 899 900 "write regbit (port_id) (address) (bit_x) (value)\n" 901 " Set single bit value of a port register.\n\n" 902 ); 903 } 904 if (show_all || !strcmp(res->section, "filters")) { 905 906 cmdline_printf( 907 cl, 908 "\n" 909 "filters:\n" 910 "--------\n\n" 911 912 "ethertype_filter (port_id) (add|del)" 913 " (mac_addr|mac_ignr) (mac_address) ethertype" 914 " (ether_type) (drop|fwd) queue (queue_id)\n" 915 " Add/Del an ethertype filter.\n\n" 916 917 "2tuple_filter (port_id) (add|del)" 918 " dst_port (dst_port_value) protocol (protocol_value)" 919 " mask (mask_value) tcp_flags (tcp_flags_value)" 920 " priority (prio_value) queue (queue_id)\n" 921 " Add/Del a 2tuple filter.\n\n" 922 923 "5tuple_filter (port_id) (add|del)" 924 " dst_ip (dst_address) src_ip (src_address)" 925 " dst_port (dst_port_value) src_port (src_port_value)" 926 " protocol (protocol_value)" 927 " mask (mask_value) tcp_flags (tcp_flags_value)" 928 " priority (prio_value) queue (queue_id)\n" 929 " Add/Del a 5tuple filter.\n\n" 930 931 "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)" 932 " Add/Del syn filter.\n\n" 933 934 "flex_filter (port_id) (add|del) len (len_value)" 935 " bytes (bytes_value) mask (mask_value)" 936 " priority (prio_value) queue (queue_id)\n" 937 " Add/Del a flex filter.\n\n" 938 939 "flow_director_filter (port_id) mode IP (add|del|update)" 940 " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)" 941 " src (src_ip_address) dst (dst_ip_address)" 942 " tos (tos_value) proto (proto_value) ttl (ttl_value)" 943 " vlan (vlan_value) flexbytes (flexbytes_value)" 944 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 945 " fd_id (fd_id_value)\n" 946 " Add/Del an IP type flow director filter.\n\n" 947 948 "flow_director_filter (port_id) mode IP (add|del|update)" 949 " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)" 950 " src (src_ip_address) (src_port)" 951 " dst (dst_ip_address) (dst_port)" 952 " tos (tos_value) ttl (ttl_value)" 953 " vlan (vlan_value) flexbytes (flexbytes_value)" 954 " (drop|fwd) pf|vf(vf_id) queue (queue_id)" 955 " fd_id (fd_id_value)\n" 956 " Add/Del an UDP/TCP type flow director filter.\n\n" 957 958 "flow_director_filter (port_id) mode IP (add|del|update)" 959 " flow (ipv4-sctp|ipv6-sctp)" 960 " src (src_ip_address) (src_port)" 961 " dst (dst_ip_address) (dst_port)" 962 " tag (verification_tag) " 963 " tos (tos_value) ttl (ttl_value)" 964 " vlan (vlan_value)" 965 " flexbytes (flexbytes_value) (drop|fwd)" 966 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 967 " Add/Del a SCTP type flow director filter.\n\n" 968 969 "flow_director_filter (port_id) mode IP (add|del|update)" 970 " flow l2_payload ether (ethertype)" 971 " flexbytes (flexbytes_value) (drop|fwd)" 972 " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n" 973 " Add/Del a l2 payload type flow director filter.\n\n" 974 975 "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)" 976 " mac (mac_address) vlan (vlan_value)" 977 " flexbytes (flexbytes_value) (drop|fwd)" 978 " queue (queue_id) fd_id (fd_id_value)\n" 979 " Add/Del a MAC-VLAN flow director filter.\n\n" 980 981 "flow_director_filter (port_id) mode Tunnel (add|del|update)" 982 " mac (mac_address) vlan (vlan_value)" 983 " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)" 984 " flexbytes (flexbytes_value) (drop|fwd)" 985 " queue (queue_id) fd_id (fd_id_value)\n" 986 " Add/Del a Tunnel flow director filter.\n\n" 987 988 "flow_director_filter (port_id) mode raw (add|del|update)" 989 " flow (flow_id) (drop|fwd) queue (queue_id)" 990 " fd_id (fd_id_value) packet (packet file name)\n" 991 " Add/Del a raw type flow director filter.\n\n" 992 993 "flush_flow_director (port_id)\n" 994 " Flush all flow director entries of a device.\n\n" 995 996 "flow_director_mask (port_id) mode IP vlan (vlan_value)" 997 " src_mask (ipv4_src) (ipv6_src) (src_port)" 998 " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" 999 " Set flow director IP mask.\n\n" 1000 1001 "flow_director_mask (port_id) mode MAC-VLAN" 1002 " vlan (vlan_value)\n" 1003 " Set flow director MAC-VLAN mask.\n\n" 1004 1005 "flow_director_mask (port_id) mode Tunnel" 1006 " vlan (vlan_value) mac (mac_value)" 1007 " tunnel-type (tunnel_type_value)" 1008 " tunnel-id (tunnel_id_value)\n" 1009 " Set flow director Tunnel mask.\n\n" 1010 1011 "flow_director_flex_mask (port_id)" 1012 " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 1013 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)" 1014 " (mask)\n" 1015 " Configure mask of flex payload.\n\n" 1016 1017 "flow_director_flex_payload (port_id)" 1018 " (raw|l2|l3|l4) (config)\n" 1019 " Configure flex payload selection.\n\n" 1020 1021 "get_sym_hash_ena_per_port (port_id)\n" 1022 " get symmetric hash enable configuration per port.\n\n" 1023 1024 "set_sym_hash_ena_per_port (port_id) (enable|disable)\n" 1025 " set symmetric hash enable configuration per port" 1026 " to enable or disable.\n\n" 1027 1028 "get_hash_global_config (port_id)\n" 1029 " Get the global configurations of hash filters.\n\n" 1030 1031 "set_hash_global_config (port_id) (toeplitz|simple_xor|default)" 1032 " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 1033 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)" 1034 " (enable|disable)\n" 1035 " Set the global configurations of hash filters.\n\n" 1036 1037 "set_hash_input_set (port_id) (ipv4|ipv4-frag|" 1038 "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" 1039 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1040 "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|" 1041 "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" 1042 "ipv6-next-header|udp-src-port|udp-dst-port|" 1043 "tcp-src-port|tcp-dst-port|sctp-src-port|" 1044 "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" 1045 "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|" 1046 "fld-8th|none) (select|add)\n" 1047 " Set the input set for hash.\n\n" 1048 1049 "set_fdir_input_set (port_id) " 1050 "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 1051 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 1052 "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|" 1053 "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|" 1054 "ipv6-next-header|ipv6-hop-limits|udp-src-port|" 1055 "udp-dst-port|tcp-src-port|tcp-dst-port|" 1056 "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)" 1057 " (select|add)\n" 1058 " Set the input set for FDir.\n\n" 1059 1060 "flow validate {port_id}" 1061 " [group {group_id}] [priority {level}]" 1062 " [ingress] [egress]" 1063 " pattern {item} [/ {item} [...]] / end" 1064 " actions {action} [/ {action} [...]] / end\n" 1065 " Check whether a flow rule can be created.\n\n" 1066 1067 "flow create {port_id}" 1068 " [group {group_id}] [priority {level}]" 1069 " [ingress] [egress]" 1070 " pattern {item} [/ {item} [...]] / end" 1071 " actions {action} [/ {action} [...]] / end\n" 1072 " Create a flow rule.\n\n" 1073 1074 "flow destroy {port_id} rule {rule_id} [...]\n" 1075 " Destroy specific flow rules.\n\n" 1076 1077 "flow flush {port_id}\n" 1078 " Destroy all flow rules.\n\n" 1079 1080 "flow query {port_id} {rule_id} {action}\n" 1081 " Query an existing flow rule.\n\n" 1082 1083 "flow list {port_id} [group {group_id}] [...]\n" 1084 " List existing flow rules sorted by priority," 1085 " filtered by group identifiers.\n\n" 1086 1087 "flow isolate {port_id} {boolean}\n" 1088 " Restrict ingress traffic to the defined" 1089 " flow rules\n\n" 1090 ); 1091 } 1092 } 1093 1094 cmdline_parse_token_string_t cmd_help_long_help = 1095 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help"); 1096 1097 cmdline_parse_token_string_t cmd_help_long_section = 1098 TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, 1099 "all#control#display#config#" 1100 "ports#registers#filters"); 1101 1102 cmdline_parse_inst_t cmd_help_long = { 1103 .f = cmd_help_long_parsed, 1104 .data = NULL, 1105 .help_str = "help all|control|display|config|ports|register|filters: " 1106 "Show help", 1107 .tokens = { 1108 (void *)&cmd_help_long_help, 1109 (void *)&cmd_help_long_section, 1110 NULL, 1111 }, 1112 }; 1113 1114 1115 /* *** start/stop/close all ports *** */ 1116 struct cmd_operate_port_result { 1117 cmdline_fixed_string_t keyword; 1118 cmdline_fixed_string_t name; 1119 cmdline_fixed_string_t value; 1120 }; 1121 1122 static void cmd_operate_port_parsed(void *parsed_result, 1123 __attribute__((unused)) struct cmdline *cl, 1124 __attribute__((unused)) void *data) 1125 { 1126 struct cmd_operate_port_result *res = parsed_result; 1127 1128 if (!strcmp(res->name, "start")) 1129 start_port(RTE_PORT_ALL); 1130 else if (!strcmp(res->name, "stop")) 1131 stop_port(RTE_PORT_ALL); 1132 else if (!strcmp(res->name, "close")) 1133 close_port(RTE_PORT_ALL); 1134 else if (!strcmp(res->name, "reset")) 1135 reset_port(RTE_PORT_ALL); 1136 else 1137 printf("Unknown parameter\n"); 1138 } 1139 1140 cmdline_parse_token_string_t cmd_operate_port_all_cmd = 1141 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword, 1142 "port"); 1143 cmdline_parse_token_string_t cmd_operate_port_all_port = 1144 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, 1145 "start#stop#close#reset"); 1146 cmdline_parse_token_string_t cmd_operate_port_all_all = 1147 TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); 1148 1149 cmdline_parse_inst_t cmd_operate_port = { 1150 .f = cmd_operate_port_parsed, 1151 .data = NULL, 1152 .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports", 1153 .tokens = { 1154 (void *)&cmd_operate_port_all_cmd, 1155 (void *)&cmd_operate_port_all_port, 1156 (void *)&cmd_operate_port_all_all, 1157 NULL, 1158 }, 1159 }; 1160 1161 /* *** start/stop/close specific port *** */ 1162 struct cmd_operate_specific_port_result { 1163 cmdline_fixed_string_t keyword; 1164 cmdline_fixed_string_t name; 1165 uint8_t value; 1166 }; 1167 1168 static void cmd_operate_specific_port_parsed(void *parsed_result, 1169 __attribute__((unused)) struct cmdline *cl, 1170 __attribute__((unused)) void *data) 1171 { 1172 struct cmd_operate_specific_port_result *res = parsed_result; 1173 1174 if (!strcmp(res->name, "start")) 1175 start_port(res->value); 1176 else if (!strcmp(res->name, "stop")) 1177 stop_port(res->value); 1178 else if (!strcmp(res->name, "close")) 1179 close_port(res->value); 1180 else if (!strcmp(res->name, "reset")) 1181 reset_port(res->value); 1182 else 1183 printf("Unknown parameter\n"); 1184 } 1185 1186 cmdline_parse_token_string_t cmd_operate_specific_port_cmd = 1187 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1188 keyword, "port"); 1189 cmdline_parse_token_string_t cmd_operate_specific_port_port = 1190 TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, 1191 name, "start#stop#close#reset"); 1192 cmdline_parse_token_num_t cmd_operate_specific_port_id = 1193 TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, 1194 value, UINT8); 1195 1196 cmdline_parse_inst_t cmd_operate_specific_port = { 1197 .f = cmd_operate_specific_port_parsed, 1198 .data = NULL, 1199 .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id", 1200 .tokens = { 1201 (void *)&cmd_operate_specific_port_cmd, 1202 (void *)&cmd_operate_specific_port_port, 1203 (void *)&cmd_operate_specific_port_id, 1204 NULL, 1205 }, 1206 }; 1207 1208 /* *** attach a specified port *** */ 1209 struct cmd_operate_attach_port_result { 1210 cmdline_fixed_string_t port; 1211 cmdline_fixed_string_t keyword; 1212 cmdline_fixed_string_t identifier; 1213 }; 1214 1215 static void cmd_operate_attach_port_parsed(void *parsed_result, 1216 __attribute__((unused)) struct cmdline *cl, 1217 __attribute__((unused)) void *data) 1218 { 1219 struct cmd_operate_attach_port_result *res = parsed_result; 1220 1221 if (!strcmp(res->keyword, "attach")) 1222 attach_port(res->identifier); 1223 else 1224 printf("Unknown parameter\n"); 1225 } 1226 1227 cmdline_parse_token_string_t cmd_operate_attach_port_port = 1228 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1229 port, "port"); 1230 cmdline_parse_token_string_t cmd_operate_attach_port_keyword = 1231 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1232 keyword, "attach"); 1233 cmdline_parse_token_string_t cmd_operate_attach_port_identifier = 1234 TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result, 1235 identifier, NULL); 1236 1237 cmdline_parse_inst_t cmd_operate_attach_port = { 1238 .f = cmd_operate_attach_port_parsed, 1239 .data = NULL, 1240 .help_str = "port attach <identifier>: " 1241 "(identifier: pci address or virtual dev name)", 1242 .tokens = { 1243 (void *)&cmd_operate_attach_port_port, 1244 (void *)&cmd_operate_attach_port_keyword, 1245 (void *)&cmd_operate_attach_port_identifier, 1246 NULL, 1247 }, 1248 }; 1249 1250 /* *** detach a specified port *** */ 1251 struct cmd_operate_detach_port_result { 1252 cmdline_fixed_string_t port; 1253 cmdline_fixed_string_t keyword; 1254 portid_t port_id; 1255 }; 1256 1257 static void cmd_operate_detach_port_parsed(void *parsed_result, 1258 __attribute__((unused)) struct cmdline *cl, 1259 __attribute__((unused)) void *data) 1260 { 1261 struct cmd_operate_detach_port_result *res = parsed_result; 1262 1263 if (!strcmp(res->keyword, "detach")) 1264 detach_port(res->port_id); 1265 else 1266 printf("Unknown parameter\n"); 1267 } 1268 1269 cmdline_parse_token_string_t cmd_operate_detach_port_port = 1270 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1271 port, "port"); 1272 cmdline_parse_token_string_t cmd_operate_detach_port_keyword = 1273 TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result, 1274 keyword, "detach"); 1275 cmdline_parse_token_num_t cmd_operate_detach_port_port_id = 1276 TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, 1277 port_id, UINT16); 1278 1279 cmdline_parse_inst_t cmd_operate_detach_port = { 1280 .f = cmd_operate_detach_port_parsed, 1281 .data = NULL, 1282 .help_str = "port detach <port_id>", 1283 .tokens = { 1284 (void *)&cmd_operate_detach_port_port, 1285 (void *)&cmd_operate_detach_port_keyword, 1286 (void *)&cmd_operate_detach_port_port_id, 1287 NULL, 1288 }, 1289 }; 1290 1291 /* *** configure speed for all ports *** */ 1292 struct cmd_config_speed_all { 1293 cmdline_fixed_string_t port; 1294 cmdline_fixed_string_t keyword; 1295 cmdline_fixed_string_t all; 1296 cmdline_fixed_string_t item1; 1297 cmdline_fixed_string_t item2; 1298 cmdline_fixed_string_t value1; 1299 cmdline_fixed_string_t value2; 1300 }; 1301 1302 static int 1303 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed) 1304 { 1305 1306 int duplex; 1307 1308 if (!strcmp(duplexstr, "half")) { 1309 duplex = ETH_LINK_HALF_DUPLEX; 1310 } else if (!strcmp(duplexstr, "full")) { 1311 duplex = ETH_LINK_FULL_DUPLEX; 1312 } else if (!strcmp(duplexstr, "auto")) { 1313 duplex = ETH_LINK_FULL_DUPLEX; 1314 } else { 1315 printf("Unknown duplex parameter\n"); 1316 return -1; 1317 } 1318 1319 if (!strcmp(speedstr, "10")) { 1320 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1321 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M; 1322 } else if (!strcmp(speedstr, "100")) { 1323 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ? 1324 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M; 1325 } else { 1326 if (duplex != ETH_LINK_FULL_DUPLEX) { 1327 printf("Invalid speed/duplex parameters\n"); 1328 return -1; 1329 } 1330 if (!strcmp(speedstr, "1000")) { 1331 *speed = ETH_LINK_SPEED_1G; 1332 } else if (!strcmp(speedstr, "10000")) { 1333 *speed = ETH_LINK_SPEED_10G; 1334 } else if (!strcmp(speedstr, "25000")) { 1335 *speed = ETH_LINK_SPEED_25G; 1336 } else if (!strcmp(speedstr, "40000")) { 1337 *speed = ETH_LINK_SPEED_40G; 1338 } else if (!strcmp(speedstr, "50000")) { 1339 *speed = ETH_LINK_SPEED_50G; 1340 } else if (!strcmp(speedstr, "100000")) { 1341 *speed = ETH_LINK_SPEED_100G; 1342 } else if (!strcmp(speedstr, "auto")) { 1343 *speed = ETH_LINK_SPEED_AUTONEG; 1344 } else { 1345 printf("Unknown speed parameter\n"); 1346 return -1; 1347 } 1348 } 1349 1350 return 0; 1351 } 1352 1353 static void 1354 cmd_config_speed_all_parsed(void *parsed_result, 1355 __attribute__((unused)) struct cmdline *cl, 1356 __attribute__((unused)) void *data) 1357 { 1358 struct cmd_config_speed_all *res = parsed_result; 1359 uint32_t link_speed; 1360 portid_t pid; 1361 1362 if (!all_ports_stopped()) { 1363 printf("Please stop all ports first\n"); 1364 return; 1365 } 1366 1367 if (parse_and_check_speed_duplex(res->value1, res->value2, 1368 &link_speed) < 0) 1369 return; 1370 1371 RTE_ETH_FOREACH_DEV(pid) { 1372 ports[pid].dev_conf.link_speeds = link_speed; 1373 } 1374 1375 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1376 } 1377 1378 cmdline_parse_token_string_t cmd_config_speed_all_port = 1379 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port"); 1380 cmdline_parse_token_string_t cmd_config_speed_all_keyword = 1381 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword, 1382 "config"); 1383 cmdline_parse_token_string_t cmd_config_speed_all_all = 1384 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all"); 1385 cmdline_parse_token_string_t cmd_config_speed_all_item1 = 1386 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed"); 1387 cmdline_parse_token_string_t cmd_config_speed_all_value1 = 1388 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1, 1389 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1390 cmdline_parse_token_string_t cmd_config_speed_all_item2 = 1391 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex"); 1392 cmdline_parse_token_string_t cmd_config_speed_all_value2 = 1393 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2, 1394 "half#full#auto"); 1395 1396 cmdline_parse_inst_t cmd_config_speed_all = { 1397 .f = cmd_config_speed_all_parsed, 1398 .data = NULL, 1399 .help_str = "port config all speed " 1400 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1401 "half|full|auto", 1402 .tokens = { 1403 (void *)&cmd_config_speed_all_port, 1404 (void *)&cmd_config_speed_all_keyword, 1405 (void *)&cmd_config_speed_all_all, 1406 (void *)&cmd_config_speed_all_item1, 1407 (void *)&cmd_config_speed_all_value1, 1408 (void *)&cmd_config_speed_all_item2, 1409 (void *)&cmd_config_speed_all_value2, 1410 NULL, 1411 }, 1412 }; 1413 1414 /* *** configure speed for specific port *** */ 1415 struct cmd_config_speed_specific { 1416 cmdline_fixed_string_t port; 1417 cmdline_fixed_string_t keyword; 1418 uint8_t id; 1419 cmdline_fixed_string_t item1; 1420 cmdline_fixed_string_t item2; 1421 cmdline_fixed_string_t value1; 1422 cmdline_fixed_string_t value2; 1423 }; 1424 1425 static void 1426 cmd_config_speed_specific_parsed(void *parsed_result, 1427 __attribute__((unused)) struct cmdline *cl, 1428 __attribute__((unused)) void *data) 1429 { 1430 struct cmd_config_speed_specific *res = parsed_result; 1431 uint32_t link_speed; 1432 1433 if (!all_ports_stopped()) { 1434 printf("Please stop all ports first\n"); 1435 return; 1436 } 1437 1438 if (port_id_is_invalid(res->id, ENABLED_WARN)) 1439 return; 1440 1441 if (parse_and_check_speed_duplex(res->value1, res->value2, 1442 &link_speed) < 0) 1443 return; 1444 1445 ports[res->id].dev_conf.link_speeds = link_speed; 1446 1447 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1448 } 1449 1450 1451 cmdline_parse_token_string_t cmd_config_speed_specific_port = 1452 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port, 1453 "port"); 1454 cmdline_parse_token_string_t cmd_config_speed_specific_keyword = 1455 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword, 1456 "config"); 1457 cmdline_parse_token_num_t cmd_config_speed_specific_id = 1458 TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8); 1459 cmdline_parse_token_string_t cmd_config_speed_specific_item1 = 1460 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1, 1461 "speed"); 1462 cmdline_parse_token_string_t cmd_config_speed_specific_value1 = 1463 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1, 1464 "10#100#1000#10000#25000#40000#50000#100000#auto"); 1465 cmdline_parse_token_string_t cmd_config_speed_specific_item2 = 1466 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2, 1467 "duplex"); 1468 cmdline_parse_token_string_t cmd_config_speed_specific_value2 = 1469 TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2, 1470 "half#full#auto"); 1471 1472 cmdline_parse_inst_t cmd_config_speed_specific = { 1473 .f = cmd_config_speed_specific_parsed, 1474 .data = NULL, 1475 .help_str = "port config <port_id> speed " 1476 "10|100|1000|10000|25000|40000|50000|100000|auto duplex " 1477 "half|full|auto", 1478 .tokens = { 1479 (void *)&cmd_config_speed_specific_port, 1480 (void *)&cmd_config_speed_specific_keyword, 1481 (void *)&cmd_config_speed_specific_id, 1482 (void *)&cmd_config_speed_specific_item1, 1483 (void *)&cmd_config_speed_specific_value1, 1484 (void *)&cmd_config_speed_specific_item2, 1485 (void *)&cmd_config_speed_specific_value2, 1486 NULL, 1487 }, 1488 }; 1489 1490 /* *** configure txq/rxq, txd/rxd *** */ 1491 struct cmd_config_rx_tx { 1492 cmdline_fixed_string_t port; 1493 cmdline_fixed_string_t keyword; 1494 cmdline_fixed_string_t all; 1495 cmdline_fixed_string_t name; 1496 uint16_t value; 1497 }; 1498 1499 static void 1500 cmd_config_rx_tx_parsed(void *parsed_result, 1501 __attribute__((unused)) struct cmdline *cl, 1502 __attribute__((unused)) void *data) 1503 { 1504 struct cmd_config_rx_tx *res = parsed_result; 1505 1506 if (!all_ports_stopped()) { 1507 printf("Please stop all ports first\n"); 1508 return; 1509 } 1510 if (!strcmp(res->name, "rxq")) { 1511 if (!res->value && !nb_txq) { 1512 printf("Warning: Either rx or tx queues should be non zero\n"); 1513 return; 1514 } 1515 if (check_nb_rxq(res->value) != 0) 1516 return; 1517 nb_rxq = res->value; 1518 } 1519 else if (!strcmp(res->name, "txq")) { 1520 if (!res->value && !nb_rxq) { 1521 printf("Warning: Either rx or tx queues should be non zero\n"); 1522 return; 1523 } 1524 if (check_nb_txq(res->value) != 0) 1525 return; 1526 nb_txq = res->value; 1527 } 1528 else if (!strcmp(res->name, "rxd")) { 1529 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) { 1530 printf("rxd %d invalid - must be > 0 && <= %d\n", 1531 res->value, RTE_TEST_RX_DESC_MAX); 1532 return; 1533 } 1534 nb_rxd = res->value; 1535 } else if (!strcmp(res->name, "txd")) { 1536 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) { 1537 printf("txd %d invalid - must be > 0 && <= %d\n", 1538 res->value, RTE_TEST_TX_DESC_MAX); 1539 return; 1540 } 1541 nb_txd = res->value; 1542 } else { 1543 printf("Unknown parameter\n"); 1544 return; 1545 } 1546 1547 fwd_config_setup(); 1548 1549 init_port_config(); 1550 1551 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1552 } 1553 1554 cmdline_parse_token_string_t cmd_config_rx_tx_port = 1555 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port"); 1556 cmdline_parse_token_string_t cmd_config_rx_tx_keyword = 1557 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config"); 1558 cmdline_parse_token_string_t cmd_config_rx_tx_all = 1559 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all"); 1560 cmdline_parse_token_string_t cmd_config_rx_tx_name = 1561 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name, 1562 "rxq#txq#rxd#txd"); 1563 cmdline_parse_token_num_t cmd_config_rx_tx_value = 1564 TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16); 1565 1566 cmdline_parse_inst_t cmd_config_rx_tx = { 1567 .f = cmd_config_rx_tx_parsed, 1568 .data = NULL, 1569 .help_str = "port config all rxq|txq|rxd|txd <value>", 1570 .tokens = { 1571 (void *)&cmd_config_rx_tx_port, 1572 (void *)&cmd_config_rx_tx_keyword, 1573 (void *)&cmd_config_rx_tx_all, 1574 (void *)&cmd_config_rx_tx_name, 1575 (void *)&cmd_config_rx_tx_value, 1576 NULL, 1577 }, 1578 }; 1579 1580 /* *** config max packet length *** */ 1581 struct cmd_config_max_pkt_len_result { 1582 cmdline_fixed_string_t port; 1583 cmdline_fixed_string_t keyword; 1584 cmdline_fixed_string_t all; 1585 cmdline_fixed_string_t name; 1586 uint32_t value; 1587 }; 1588 1589 static void 1590 cmd_config_max_pkt_len_parsed(void *parsed_result, 1591 __attribute__((unused)) struct cmdline *cl, 1592 __attribute__((unused)) void *data) 1593 { 1594 struct cmd_config_max_pkt_len_result *res = parsed_result; 1595 portid_t pid; 1596 1597 if (!all_ports_stopped()) { 1598 printf("Please stop all ports first\n"); 1599 return; 1600 } 1601 1602 RTE_ETH_FOREACH_DEV(pid) { 1603 struct rte_port *port = &ports[pid]; 1604 uint64_t rx_offloads = port->dev_conf.rxmode.offloads; 1605 1606 if (!strcmp(res->name, "max-pkt-len")) { 1607 if (res->value < ETHER_MIN_LEN) { 1608 printf("max-pkt-len can not be less than %d\n", 1609 ETHER_MIN_LEN); 1610 return; 1611 } 1612 if (res->value == port->dev_conf.rxmode.max_rx_pkt_len) 1613 return; 1614 1615 port->dev_conf.rxmode.max_rx_pkt_len = res->value; 1616 if (res->value > ETHER_MAX_LEN) 1617 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME; 1618 else 1619 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME; 1620 port->dev_conf.rxmode.offloads = rx_offloads; 1621 } else { 1622 printf("Unknown parameter\n"); 1623 return; 1624 } 1625 } 1626 1627 init_port_config(); 1628 1629 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1630 } 1631 1632 cmdline_parse_token_string_t cmd_config_max_pkt_len_port = 1633 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port, 1634 "port"); 1635 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword = 1636 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword, 1637 "config"); 1638 cmdline_parse_token_string_t cmd_config_max_pkt_len_all = 1639 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all, 1640 "all"); 1641 cmdline_parse_token_string_t cmd_config_max_pkt_len_name = 1642 TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name, 1643 "max-pkt-len"); 1644 cmdline_parse_token_num_t cmd_config_max_pkt_len_value = 1645 TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value, 1646 UINT32); 1647 1648 cmdline_parse_inst_t cmd_config_max_pkt_len = { 1649 .f = cmd_config_max_pkt_len_parsed, 1650 .data = NULL, 1651 .help_str = "port config all max-pkt-len <value>", 1652 .tokens = { 1653 (void *)&cmd_config_max_pkt_len_port, 1654 (void *)&cmd_config_max_pkt_len_keyword, 1655 (void *)&cmd_config_max_pkt_len_all, 1656 (void *)&cmd_config_max_pkt_len_name, 1657 (void *)&cmd_config_max_pkt_len_value, 1658 NULL, 1659 }, 1660 }; 1661 1662 /* *** configure port MTU *** */ 1663 struct cmd_config_mtu_result { 1664 cmdline_fixed_string_t port; 1665 cmdline_fixed_string_t keyword; 1666 cmdline_fixed_string_t mtu; 1667 portid_t port_id; 1668 uint16_t value; 1669 }; 1670 1671 static void 1672 cmd_config_mtu_parsed(void *parsed_result, 1673 __attribute__((unused)) struct cmdline *cl, 1674 __attribute__((unused)) void *data) 1675 { 1676 struct cmd_config_mtu_result *res = parsed_result; 1677 1678 if (res->value < ETHER_MIN_LEN) { 1679 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN); 1680 return; 1681 } 1682 port_mtu_set(res->port_id, res->value); 1683 } 1684 1685 cmdline_parse_token_string_t cmd_config_mtu_port = 1686 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port, 1687 "port"); 1688 cmdline_parse_token_string_t cmd_config_mtu_keyword = 1689 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1690 "config"); 1691 cmdline_parse_token_string_t cmd_config_mtu_mtu = 1692 TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, 1693 "mtu"); 1694 cmdline_parse_token_num_t cmd_config_mtu_port_id = 1695 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16); 1696 cmdline_parse_token_num_t cmd_config_mtu_value = 1697 TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); 1698 1699 cmdline_parse_inst_t cmd_config_mtu = { 1700 .f = cmd_config_mtu_parsed, 1701 .data = NULL, 1702 .help_str = "port config mtu <port_id> <value>", 1703 .tokens = { 1704 (void *)&cmd_config_mtu_port, 1705 (void *)&cmd_config_mtu_keyword, 1706 (void *)&cmd_config_mtu_mtu, 1707 (void *)&cmd_config_mtu_port_id, 1708 (void *)&cmd_config_mtu_value, 1709 NULL, 1710 }, 1711 }; 1712 1713 /* *** configure rx mode *** */ 1714 struct cmd_config_rx_mode_flag { 1715 cmdline_fixed_string_t port; 1716 cmdline_fixed_string_t keyword; 1717 cmdline_fixed_string_t all; 1718 cmdline_fixed_string_t name; 1719 cmdline_fixed_string_t value; 1720 }; 1721 1722 static void 1723 cmd_config_rx_mode_flag_parsed(void *parsed_result, 1724 __attribute__((unused)) struct cmdline *cl, 1725 __attribute__((unused)) void *data) 1726 { 1727 struct cmd_config_rx_mode_flag *res = parsed_result; 1728 portid_t pid; 1729 1730 if (!all_ports_stopped()) { 1731 printf("Please stop all ports first\n"); 1732 return; 1733 } 1734 1735 RTE_ETH_FOREACH_DEV(pid) { 1736 struct rte_port *port; 1737 uint64_t rx_offloads; 1738 1739 port = &ports[pid]; 1740 rx_offloads = port->dev_conf.rxmode.offloads; 1741 if (!strcmp(res->name, "crc-strip")) { 1742 if (!strcmp(res->value, "on")) 1743 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP; 1744 else if (!strcmp(res->value, "off")) 1745 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP; 1746 else { 1747 printf("Unknown parameter\n"); 1748 return; 1749 } 1750 } else if (!strcmp(res->name, "scatter")) { 1751 if (!strcmp(res->value, "on")) { 1752 rx_offloads |= DEV_RX_OFFLOAD_SCATTER; 1753 } else if (!strcmp(res->value, "off")) { 1754 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER; 1755 } else { 1756 printf("Unknown parameter\n"); 1757 return; 1758 } 1759 } else if (!strcmp(res->name, "rx-cksum")) { 1760 if (!strcmp(res->value, "on")) 1761 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM; 1762 else if (!strcmp(res->value, "off")) 1763 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM; 1764 else { 1765 printf("Unknown parameter\n"); 1766 return; 1767 } 1768 } else if (!strcmp(res->name, "rx-timestamp")) { 1769 if (!strcmp(res->value, "on")) 1770 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP; 1771 else if (!strcmp(res->value, "off")) 1772 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP; 1773 else { 1774 printf("Unknown parameter\n"); 1775 return; 1776 } 1777 } else if (!strcmp(res->name, "hw-vlan")) { 1778 if (!strcmp(res->value, "on")) { 1779 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER | 1780 DEV_RX_OFFLOAD_VLAN_STRIP); 1781 } else if (!strcmp(res->value, "off")) { 1782 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER | 1783 DEV_RX_OFFLOAD_VLAN_STRIP); 1784 } else { 1785 printf("Unknown parameter\n"); 1786 return; 1787 } 1788 } else if (!strcmp(res->name, "hw-vlan-filter")) { 1789 if (!strcmp(res->value, "on")) 1790 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER; 1791 else if (!strcmp(res->value, "off")) 1792 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER; 1793 else { 1794 printf("Unknown parameter\n"); 1795 return; 1796 } 1797 } else if (!strcmp(res->name, "hw-vlan-strip")) { 1798 if (!strcmp(res->value, "on")) 1799 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; 1800 else if (!strcmp(res->value, "off")) 1801 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; 1802 else { 1803 printf("Unknown parameter\n"); 1804 return; 1805 } 1806 } else if (!strcmp(res->name, "hw-vlan-extend")) { 1807 if (!strcmp(res->value, "on")) 1808 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND; 1809 else if (!strcmp(res->value, "off")) 1810 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND; 1811 else { 1812 printf("Unknown parameter\n"); 1813 return; 1814 } 1815 } else if (!strcmp(res->name, "drop-en")) { 1816 if (!strcmp(res->value, "on")) 1817 rx_drop_en = 1; 1818 else if (!strcmp(res->value, "off")) 1819 rx_drop_en = 0; 1820 else { 1821 printf("Unknown parameter\n"); 1822 return; 1823 } 1824 } else { 1825 printf("Unknown parameter\n"); 1826 return; 1827 } 1828 port->dev_conf.rxmode.offloads = rx_offloads; 1829 } 1830 1831 init_port_config(); 1832 1833 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 1834 } 1835 1836 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port = 1837 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port"); 1838 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword = 1839 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword, 1840 "config"); 1841 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = 1842 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); 1843 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = 1844 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, 1845 "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#" 1846 "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); 1847 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = 1848 TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, 1849 "on#off"); 1850 1851 cmdline_parse_inst_t cmd_config_rx_mode_flag = { 1852 .f = cmd_config_rx_mode_flag_parsed, 1853 .data = NULL, 1854 .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|" 1855 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", 1856 .tokens = { 1857 (void *)&cmd_config_rx_mode_flag_port, 1858 (void *)&cmd_config_rx_mode_flag_keyword, 1859 (void *)&cmd_config_rx_mode_flag_all, 1860 (void *)&cmd_config_rx_mode_flag_name, 1861 (void *)&cmd_config_rx_mode_flag_value, 1862 NULL, 1863 }, 1864 }; 1865 1866 /* *** configure rss *** */ 1867 struct cmd_config_rss { 1868 cmdline_fixed_string_t port; 1869 cmdline_fixed_string_t keyword; 1870 cmdline_fixed_string_t all; 1871 cmdline_fixed_string_t name; 1872 cmdline_fixed_string_t value; 1873 }; 1874 1875 static void 1876 cmd_config_rss_parsed(void *parsed_result, 1877 __attribute__((unused)) struct cmdline *cl, 1878 __attribute__((unused)) void *data) 1879 { 1880 struct cmd_config_rss *res = parsed_result; 1881 struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, }; 1882 int diag; 1883 uint8_t i; 1884 1885 if (!strcmp(res->value, "all")) 1886 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | 1887 ETH_RSS_UDP | ETH_RSS_SCTP | 1888 ETH_RSS_L2_PAYLOAD; 1889 else if (!strcmp(res->value, "ip")) 1890 rss_conf.rss_hf = ETH_RSS_IP; 1891 else if (!strcmp(res->value, "udp")) 1892 rss_conf.rss_hf = ETH_RSS_UDP; 1893 else if (!strcmp(res->value, "tcp")) 1894 rss_conf.rss_hf = ETH_RSS_TCP; 1895 else if (!strcmp(res->value, "sctp")) 1896 rss_conf.rss_hf = ETH_RSS_SCTP; 1897 else if (!strcmp(res->value, "ether")) 1898 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD; 1899 else if (!strcmp(res->value, "port")) 1900 rss_conf.rss_hf = ETH_RSS_PORT; 1901 else if (!strcmp(res->value, "vxlan")) 1902 rss_conf.rss_hf = ETH_RSS_VXLAN; 1903 else if (!strcmp(res->value, "geneve")) 1904 rss_conf.rss_hf = ETH_RSS_GENEVE; 1905 else if (!strcmp(res->value, "nvgre")) 1906 rss_conf.rss_hf = ETH_RSS_NVGRE; 1907 else if (!strcmp(res->value, "none")) 1908 rss_conf.rss_hf = 0; 1909 else if (isdigit(res->value[0]) && atoi(res->value) > 0 && 1910 atoi(res->value) < 64) 1911 rss_conf.rss_hf = 1ULL << atoi(res->value); 1912 else { 1913 printf("Unknown parameter\n"); 1914 return; 1915 } 1916 rss_conf.rss_key = NULL; 1917 for (i = 0; i < rte_eth_dev_count(); i++) { 1918 diag = rte_eth_dev_rss_hash_update(i, &rss_conf); 1919 if (diag < 0) 1920 printf("Configuration of RSS hash at ethernet port %d " 1921 "failed with error (%d): %s.\n", 1922 i, -diag, strerror(-diag)); 1923 } 1924 } 1925 1926 cmdline_parse_token_string_t cmd_config_rss_port = 1927 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port"); 1928 cmdline_parse_token_string_t cmd_config_rss_keyword = 1929 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config"); 1930 cmdline_parse_token_string_t cmd_config_rss_all = 1931 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all"); 1932 cmdline_parse_token_string_t cmd_config_rss_name = 1933 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); 1934 cmdline_parse_token_string_t cmd_config_rss_value = 1935 TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL); 1936 1937 cmdline_parse_inst_t cmd_config_rss = { 1938 .f = cmd_config_rss_parsed, 1939 .data = NULL, 1940 .help_str = "port config all rss " 1941 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>", 1942 .tokens = { 1943 (void *)&cmd_config_rss_port, 1944 (void *)&cmd_config_rss_keyword, 1945 (void *)&cmd_config_rss_all, 1946 (void *)&cmd_config_rss_name, 1947 (void *)&cmd_config_rss_value, 1948 NULL, 1949 }, 1950 }; 1951 1952 /* *** configure rss hash key *** */ 1953 struct cmd_config_rss_hash_key { 1954 cmdline_fixed_string_t port; 1955 cmdline_fixed_string_t config; 1956 portid_t port_id; 1957 cmdline_fixed_string_t rss_hash_key; 1958 cmdline_fixed_string_t rss_type; 1959 cmdline_fixed_string_t key; 1960 }; 1961 1962 static uint8_t 1963 hexa_digit_to_value(char hexa_digit) 1964 { 1965 if ((hexa_digit >= '0') && (hexa_digit <= '9')) 1966 return (uint8_t) (hexa_digit - '0'); 1967 if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) 1968 return (uint8_t) ((hexa_digit - 'a') + 10); 1969 if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) 1970 return (uint8_t) ((hexa_digit - 'A') + 10); 1971 /* Invalid hexa digit */ 1972 return 0xFF; 1973 } 1974 1975 static uint8_t 1976 parse_and_check_key_hexa_digit(char *key, int idx) 1977 { 1978 uint8_t hexa_v; 1979 1980 hexa_v = hexa_digit_to_value(key[idx]); 1981 if (hexa_v == 0xFF) 1982 printf("invalid key: character %c at position %d is not a " 1983 "valid hexa digit\n", key[idx], idx); 1984 return hexa_v; 1985 } 1986 1987 static void 1988 cmd_config_rss_hash_key_parsed(void *parsed_result, 1989 __attribute__((unused)) struct cmdline *cl, 1990 __attribute__((unused)) void *data) 1991 { 1992 struct cmd_config_rss_hash_key *res = parsed_result; 1993 uint8_t hash_key[RSS_HASH_KEY_LENGTH]; 1994 uint8_t xdgt0; 1995 uint8_t xdgt1; 1996 int i; 1997 struct rte_eth_dev_info dev_info; 1998 uint8_t hash_key_size; 1999 uint32_t key_len; 2000 2001 memset(&dev_info, 0, sizeof(dev_info)); 2002 rte_eth_dev_info_get(res->port_id, &dev_info); 2003 if (dev_info.hash_key_size > 0 && 2004 dev_info.hash_key_size <= sizeof(hash_key)) 2005 hash_key_size = dev_info.hash_key_size; 2006 else { 2007 printf("dev_info did not provide a valid hash key size\n"); 2008 return; 2009 } 2010 /* Check the length of the RSS hash key */ 2011 key_len = strlen(res->key); 2012 if (key_len != (hash_key_size * 2)) { 2013 printf("key length: %d invalid - key must be a string of %d" 2014 " hexa-decimal numbers\n", 2015 (int) key_len, hash_key_size * 2); 2016 return; 2017 } 2018 /* Translate RSS hash key into binary representation */ 2019 for (i = 0; i < hash_key_size; i++) { 2020 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 2021 if (xdgt0 == 0xFF) 2022 return; 2023 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 2024 if (xdgt1 == 0xFF) 2025 return; 2026 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 2027 } 2028 port_rss_hash_key_update(res->port_id, res->rss_type, hash_key, 2029 hash_key_size); 2030 } 2031 2032 cmdline_parse_token_string_t cmd_config_rss_hash_key_port = 2033 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); 2034 cmdline_parse_token_string_t cmd_config_rss_hash_key_config = 2035 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, 2036 "config"); 2037 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = 2038 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16); 2039 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = 2040 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, 2041 rss_hash_key, "rss-hash-key"); 2042 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type = 2043 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type, 2044 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2045 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2046 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2047 "ipv6-tcp-ex#ipv6-udp-ex"); 2048 cmdline_parse_token_string_t cmd_config_rss_hash_key_value = 2049 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); 2050 2051 cmdline_parse_inst_t cmd_config_rss_hash_key = { 2052 .f = cmd_config_rss_hash_key_parsed, 2053 .data = NULL, 2054 .help_str = "port config <port_id> rss-hash-key " 2055 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2056 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2057 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex " 2058 "<string of hex digits (variable length, NIC dependent)>", 2059 .tokens = { 2060 (void *)&cmd_config_rss_hash_key_port, 2061 (void *)&cmd_config_rss_hash_key_config, 2062 (void *)&cmd_config_rss_hash_key_port_id, 2063 (void *)&cmd_config_rss_hash_key_rss_hash_key, 2064 (void *)&cmd_config_rss_hash_key_rss_type, 2065 (void *)&cmd_config_rss_hash_key_value, 2066 NULL, 2067 }, 2068 }; 2069 2070 /* *** configure port rxq/txq start/stop *** */ 2071 struct cmd_config_rxtx_queue { 2072 cmdline_fixed_string_t port; 2073 portid_t portid; 2074 cmdline_fixed_string_t rxtxq; 2075 uint16_t qid; 2076 cmdline_fixed_string_t opname; 2077 }; 2078 2079 static void 2080 cmd_config_rxtx_queue_parsed(void *parsed_result, 2081 __attribute__((unused)) struct cmdline *cl, 2082 __attribute__((unused)) void *data) 2083 { 2084 struct cmd_config_rxtx_queue *res = parsed_result; 2085 uint8_t isrx; 2086 uint8_t isstart; 2087 int ret = 0; 2088 2089 if (test_done == 0) { 2090 printf("Please stop forwarding first\n"); 2091 return; 2092 } 2093 2094 if (port_id_is_invalid(res->portid, ENABLED_WARN)) 2095 return; 2096 2097 if (port_is_started(res->portid) != 1) { 2098 printf("Please start port %u first\n", res->portid); 2099 return; 2100 } 2101 2102 if (!strcmp(res->rxtxq, "rxq")) 2103 isrx = 1; 2104 else if (!strcmp(res->rxtxq, "txq")) 2105 isrx = 0; 2106 else { 2107 printf("Unknown parameter\n"); 2108 return; 2109 } 2110 2111 if (isrx && rx_queue_id_is_invalid(res->qid)) 2112 return; 2113 else if (!isrx && tx_queue_id_is_invalid(res->qid)) 2114 return; 2115 2116 if (!strcmp(res->opname, "start")) 2117 isstart = 1; 2118 else if (!strcmp(res->opname, "stop")) 2119 isstart = 0; 2120 else { 2121 printf("Unknown parameter\n"); 2122 return; 2123 } 2124 2125 if (isstart && isrx) 2126 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid); 2127 else if (!isstart && isrx) 2128 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid); 2129 else if (isstart && !isrx) 2130 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid); 2131 else 2132 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid); 2133 2134 if (ret == -ENOTSUP) 2135 printf("Function not supported in PMD driver\n"); 2136 } 2137 2138 cmdline_parse_token_string_t cmd_config_rxtx_queue_port = 2139 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); 2140 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = 2141 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16); 2142 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = 2143 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); 2144 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = 2145 TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16); 2146 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname = 2147 TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname, 2148 "start#stop"); 2149 2150 cmdline_parse_inst_t cmd_config_rxtx_queue = { 2151 .f = cmd_config_rxtx_queue_parsed, 2152 .data = NULL, 2153 .help_str = "port <port_id> rxq|txq <queue_id> start|stop", 2154 .tokens = { 2155 (void *)&cmd_config_speed_all_port, 2156 (void *)&cmd_config_rxtx_queue_portid, 2157 (void *)&cmd_config_rxtx_queue_rxtxq, 2158 (void *)&cmd_config_rxtx_queue_qid, 2159 (void *)&cmd_config_rxtx_queue_opname, 2160 NULL, 2161 }, 2162 }; 2163 2164 /* *** Configure RSS RETA *** */ 2165 struct cmd_config_rss_reta { 2166 cmdline_fixed_string_t port; 2167 cmdline_fixed_string_t keyword; 2168 portid_t port_id; 2169 cmdline_fixed_string_t name; 2170 cmdline_fixed_string_t list_name; 2171 cmdline_fixed_string_t list_of_items; 2172 }; 2173 2174 static int 2175 parse_reta_config(const char *str, 2176 struct rte_eth_rss_reta_entry64 *reta_conf, 2177 uint16_t nb_entries) 2178 { 2179 int i; 2180 unsigned size; 2181 uint16_t hash_index, idx, shift; 2182 uint16_t nb_queue; 2183 char s[256]; 2184 const char *p, *p0 = str; 2185 char *end; 2186 enum fieldnames { 2187 FLD_HASH_INDEX = 0, 2188 FLD_QUEUE, 2189 _NUM_FLD 2190 }; 2191 unsigned long int_fld[_NUM_FLD]; 2192 char *str_fld[_NUM_FLD]; 2193 2194 while ((p = strchr(p0,'(')) != NULL) { 2195 ++p; 2196 if((p0 = strchr(p,')')) == NULL) 2197 return -1; 2198 2199 size = p0 - p; 2200 if(size >= sizeof(s)) 2201 return -1; 2202 2203 snprintf(s, sizeof(s), "%.*s", size, p); 2204 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) 2205 return -1; 2206 for (i = 0; i < _NUM_FLD; i++) { 2207 errno = 0; 2208 int_fld[i] = strtoul(str_fld[i], &end, 0); 2209 if (errno != 0 || end == str_fld[i] || 2210 int_fld[i] > 65535) 2211 return -1; 2212 } 2213 2214 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX]; 2215 nb_queue = (uint16_t)int_fld[FLD_QUEUE]; 2216 2217 if (hash_index >= nb_entries) { 2218 printf("Invalid RETA hash index=%d\n", hash_index); 2219 return -1; 2220 } 2221 2222 idx = hash_index / RTE_RETA_GROUP_SIZE; 2223 shift = hash_index % RTE_RETA_GROUP_SIZE; 2224 reta_conf[idx].mask |= (1ULL << shift); 2225 reta_conf[idx].reta[shift] = nb_queue; 2226 } 2227 2228 return 0; 2229 } 2230 2231 static void 2232 cmd_set_rss_reta_parsed(void *parsed_result, 2233 __attribute__((unused)) struct cmdline *cl, 2234 __attribute__((unused)) void *data) 2235 { 2236 int ret; 2237 struct rte_eth_dev_info dev_info; 2238 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2239 struct cmd_config_rss_reta *res = parsed_result; 2240 2241 memset(&dev_info, 0, sizeof(dev_info)); 2242 rte_eth_dev_info_get(res->port_id, &dev_info); 2243 if (dev_info.reta_size == 0) { 2244 printf("Redirection table size is 0 which is " 2245 "invalid for RSS\n"); 2246 return; 2247 } else 2248 printf("The reta size of port %d is %u\n", 2249 res->port_id, dev_info.reta_size); 2250 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) { 2251 printf("Currently do not support more than %u entries of " 2252 "redirection table\n", ETH_RSS_RETA_SIZE_512); 2253 return; 2254 } 2255 2256 memset(reta_conf, 0, sizeof(reta_conf)); 2257 if (!strcmp(res->list_name, "reta")) { 2258 if (parse_reta_config(res->list_of_items, reta_conf, 2259 dev_info.reta_size)) { 2260 printf("Invalid RSS Redirection Table " 2261 "config entered\n"); 2262 return; 2263 } 2264 ret = rte_eth_dev_rss_reta_update(res->port_id, 2265 reta_conf, dev_info.reta_size); 2266 if (ret != 0) 2267 printf("Bad redirection table parameter, " 2268 "return code = %d \n", ret); 2269 } 2270 } 2271 2272 cmdline_parse_token_string_t cmd_config_rss_reta_port = 2273 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port"); 2274 cmdline_parse_token_string_t cmd_config_rss_reta_keyword = 2275 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); 2276 cmdline_parse_token_num_t cmd_config_rss_reta_port_id = 2277 TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16); 2278 cmdline_parse_token_string_t cmd_config_rss_reta_name = 2279 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); 2280 cmdline_parse_token_string_t cmd_config_rss_reta_list_name = 2281 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta"); 2282 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items = 2283 TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items, 2284 NULL); 2285 cmdline_parse_inst_t cmd_config_rss_reta = { 2286 .f = cmd_set_rss_reta_parsed, 2287 .data = NULL, 2288 .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>", 2289 .tokens = { 2290 (void *)&cmd_config_rss_reta_port, 2291 (void *)&cmd_config_rss_reta_keyword, 2292 (void *)&cmd_config_rss_reta_port_id, 2293 (void *)&cmd_config_rss_reta_name, 2294 (void *)&cmd_config_rss_reta_list_name, 2295 (void *)&cmd_config_rss_reta_list_of_items, 2296 NULL, 2297 }, 2298 }; 2299 2300 /* *** SHOW PORT RETA INFO *** */ 2301 struct cmd_showport_reta { 2302 cmdline_fixed_string_t show; 2303 cmdline_fixed_string_t port; 2304 portid_t port_id; 2305 cmdline_fixed_string_t rss; 2306 cmdline_fixed_string_t reta; 2307 uint16_t size; 2308 cmdline_fixed_string_t list_of_items; 2309 }; 2310 2311 static int 2312 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf, 2313 uint16_t nb_entries, 2314 char *str) 2315 { 2316 uint32_t size; 2317 const char *p, *p0 = str; 2318 char s[256]; 2319 char *end; 2320 char *str_fld[8]; 2321 uint16_t i; 2322 uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) / 2323 RTE_RETA_GROUP_SIZE; 2324 int ret; 2325 2326 p = strchr(p0, '('); 2327 if (p == NULL) 2328 return -1; 2329 p++; 2330 p0 = strchr(p, ')'); 2331 if (p0 == NULL) 2332 return -1; 2333 size = p0 - p; 2334 if (size >= sizeof(s)) { 2335 printf("The string size exceeds the internal buffer size\n"); 2336 return -1; 2337 } 2338 snprintf(s, sizeof(s), "%.*s", size, p); 2339 ret = rte_strsplit(s, sizeof(s), str_fld, num, ','); 2340 if (ret <= 0 || ret != num) { 2341 printf("The bits of masks do not match the number of " 2342 "reta entries: %u\n", num); 2343 return -1; 2344 } 2345 for (i = 0; i < ret; i++) 2346 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0); 2347 2348 return 0; 2349 } 2350 2351 static void 2352 cmd_showport_reta_parsed(void *parsed_result, 2353 __attribute__((unused)) struct cmdline *cl, 2354 __attribute__((unused)) void *data) 2355 { 2356 struct cmd_showport_reta *res = parsed_result; 2357 struct rte_eth_rss_reta_entry64 reta_conf[8]; 2358 struct rte_eth_dev_info dev_info; 2359 uint16_t max_reta_size; 2360 2361 memset(&dev_info, 0, sizeof(dev_info)); 2362 rte_eth_dev_info_get(res->port_id, &dev_info); 2363 max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512); 2364 if (res->size == 0 || res->size > max_reta_size) { 2365 printf("Invalid redirection table size: %u (1-%u)\n", 2366 res->size, max_reta_size); 2367 return; 2368 } 2369 2370 memset(reta_conf, 0, sizeof(reta_conf)); 2371 if (showport_parse_reta_config(reta_conf, res->size, 2372 res->list_of_items) < 0) { 2373 printf("Invalid string: %s for reta masks\n", 2374 res->list_of_items); 2375 return; 2376 } 2377 port_rss_reta_info(res->port_id, reta_conf, res->size); 2378 } 2379 2380 cmdline_parse_token_string_t cmd_showport_reta_show = 2381 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, show, "show"); 2382 cmdline_parse_token_string_t cmd_showport_reta_port = 2383 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); 2384 cmdline_parse_token_num_t cmd_showport_reta_port_id = 2385 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16); 2386 cmdline_parse_token_string_t cmd_showport_reta_rss = 2387 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); 2388 cmdline_parse_token_string_t cmd_showport_reta_reta = 2389 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta"); 2390 cmdline_parse_token_num_t cmd_showport_reta_size = 2391 TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16); 2392 cmdline_parse_token_string_t cmd_showport_reta_list_of_items = 2393 TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, 2394 list_of_items, NULL); 2395 2396 cmdline_parse_inst_t cmd_showport_reta = { 2397 .f = cmd_showport_reta_parsed, 2398 .data = NULL, 2399 .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>", 2400 .tokens = { 2401 (void *)&cmd_showport_reta_show, 2402 (void *)&cmd_showport_reta_port, 2403 (void *)&cmd_showport_reta_port_id, 2404 (void *)&cmd_showport_reta_rss, 2405 (void *)&cmd_showport_reta_reta, 2406 (void *)&cmd_showport_reta_size, 2407 (void *)&cmd_showport_reta_list_of_items, 2408 NULL, 2409 }, 2410 }; 2411 2412 /* *** Show RSS hash configuration *** */ 2413 struct cmd_showport_rss_hash { 2414 cmdline_fixed_string_t show; 2415 cmdline_fixed_string_t port; 2416 portid_t port_id; 2417 cmdline_fixed_string_t rss_hash; 2418 cmdline_fixed_string_t rss_type; 2419 cmdline_fixed_string_t key; /* optional argument */ 2420 }; 2421 2422 static void cmd_showport_rss_hash_parsed(void *parsed_result, 2423 __attribute__((unused)) struct cmdline *cl, 2424 void *show_rss_key) 2425 { 2426 struct cmd_showport_rss_hash *res = parsed_result; 2427 2428 port_rss_hash_conf_show(res->port_id, res->rss_type, 2429 show_rss_key != NULL); 2430 } 2431 2432 cmdline_parse_token_string_t cmd_showport_rss_hash_show = 2433 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show"); 2434 cmdline_parse_token_string_t cmd_showport_rss_hash_port = 2435 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); 2436 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = 2437 TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16); 2438 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = 2439 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, 2440 "rss-hash"); 2441 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info = 2442 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type, 2443 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 2444 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#" 2445 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#" 2446 "ipv6-tcp-ex#ipv6-udp-ex"); 2447 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key = 2448 TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key"); 2449 2450 cmdline_parse_inst_t cmd_showport_rss_hash = { 2451 .f = cmd_showport_rss_hash_parsed, 2452 .data = NULL, 2453 .help_str = "show port <port_id> rss-hash " 2454 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2455 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2456 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex", 2457 .tokens = { 2458 (void *)&cmd_showport_rss_hash_show, 2459 (void *)&cmd_showport_rss_hash_port, 2460 (void *)&cmd_showport_rss_hash_port_id, 2461 (void *)&cmd_showport_rss_hash_rss_hash, 2462 (void *)&cmd_showport_rss_hash_rss_hash_info, 2463 NULL, 2464 }, 2465 }; 2466 2467 cmdline_parse_inst_t cmd_showport_rss_hash_key = { 2468 .f = cmd_showport_rss_hash_parsed, 2469 .data = (void *)1, 2470 .help_str = "show port <port_id> rss-hash " 2471 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 2472 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 2473 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key", 2474 .tokens = { 2475 (void *)&cmd_showport_rss_hash_show, 2476 (void *)&cmd_showport_rss_hash_port, 2477 (void *)&cmd_showport_rss_hash_port_id, 2478 (void *)&cmd_showport_rss_hash_rss_hash, 2479 (void *)&cmd_showport_rss_hash_rss_hash_info, 2480 (void *)&cmd_showport_rss_hash_rss_key, 2481 NULL, 2482 }, 2483 }; 2484 2485 /* *** Configure DCB *** */ 2486 struct cmd_config_dcb { 2487 cmdline_fixed_string_t port; 2488 cmdline_fixed_string_t config; 2489 portid_t port_id; 2490 cmdline_fixed_string_t dcb; 2491 cmdline_fixed_string_t vt; 2492 cmdline_fixed_string_t vt_en; 2493 uint8_t num_tcs; 2494 cmdline_fixed_string_t pfc; 2495 cmdline_fixed_string_t pfc_en; 2496 }; 2497 2498 static void 2499 cmd_config_dcb_parsed(void *parsed_result, 2500 __attribute__((unused)) struct cmdline *cl, 2501 __attribute__((unused)) void *data) 2502 { 2503 struct cmd_config_dcb *res = parsed_result; 2504 portid_t port_id = res->port_id; 2505 struct rte_port *port; 2506 uint8_t pfc_en; 2507 int ret; 2508 2509 port = &ports[port_id]; 2510 /** Check if the port is not started **/ 2511 if (port->port_status != RTE_PORT_STOPPED) { 2512 printf("Please stop port %d first\n", port_id); 2513 return; 2514 } 2515 2516 if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) { 2517 printf("The invalid number of traffic class," 2518 " only 4 or 8 allowed.\n"); 2519 return; 2520 } 2521 2522 if (nb_fwd_lcores < res->num_tcs) { 2523 printf("nb_cores shouldn't be less than number of TCs.\n"); 2524 return; 2525 } 2526 if (!strncmp(res->pfc_en, "on", 2)) 2527 pfc_en = 1; 2528 else 2529 pfc_en = 0; 2530 2531 /* DCB in VT mode */ 2532 if (!strncmp(res->vt_en, "on", 2)) 2533 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED, 2534 (enum rte_eth_nb_tcs)res->num_tcs, 2535 pfc_en); 2536 else 2537 ret = init_port_dcb_config(port_id, DCB_ENABLED, 2538 (enum rte_eth_nb_tcs)res->num_tcs, 2539 pfc_en); 2540 2541 2542 if (ret != 0) { 2543 printf("Cannot initialize network ports.\n"); 2544 return; 2545 } 2546 2547 cmd_reconfig_device_queue(port_id, 1, 1); 2548 } 2549 2550 cmdline_parse_token_string_t cmd_config_dcb_port = 2551 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port"); 2552 cmdline_parse_token_string_t cmd_config_dcb_config = 2553 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); 2554 cmdline_parse_token_num_t cmd_config_dcb_port_id = 2555 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16); 2556 cmdline_parse_token_string_t cmd_config_dcb_dcb = 2557 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); 2558 cmdline_parse_token_string_t cmd_config_dcb_vt = 2559 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt"); 2560 cmdline_parse_token_string_t cmd_config_dcb_vt_en = 2561 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off"); 2562 cmdline_parse_token_num_t cmd_config_dcb_num_tcs = 2563 TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8); 2564 cmdline_parse_token_string_t cmd_config_dcb_pfc= 2565 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc"); 2566 cmdline_parse_token_string_t cmd_config_dcb_pfc_en = 2567 TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off"); 2568 2569 cmdline_parse_inst_t cmd_config_dcb = { 2570 .f = cmd_config_dcb_parsed, 2571 .data = NULL, 2572 .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off", 2573 .tokens = { 2574 (void *)&cmd_config_dcb_port, 2575 (void *)&cmd_config_dcb_config, 2576 (void *)&cmd_config_dcb_port_id, 2577 (void *)&cmd_config_dcb_dcb, 2578 (void *)&cmd_config_dcb_vt, 2579 (void *)&cmd_config_dcb_vt_en, 2580 (void *)&cmd_config_dcb_num_tcs, 2581 (void *)&cmd_config_dcb_pfc, 2582 (void *)&cmd_config_dcb_pfc_en, 2583 NULL, 2584 }, 2585 }; 2586 2587 /* *** configure number of packets per burst *** */ 2588 struct cmd_config_burst { 2589 cmdline_fixed_string_t port; 2590 cmdline_fixed_string_t keyword; 2591 cmdline_fixed_string_t all; 2592 cmdline_fixed_string_t name; 2593 uint16_t value; 2594 }; 2595 2596 static void 2597 cmd_config_burst_parsed(void *parsed_result, 2598 __attribute__((unused)) struct cmdline *cl, 2599 __attribute__((unused)) void *data) 2600 { 2601 struct cmd_config_burst *res = parsed_result; 2602 2603 if (!all_ports_stopped()) { 2604 printf("Please stop all ports first\n"); 2605 return; 2606 } 2607 2608 if (!strcmp(res->name, "burst")) { 2609 if (res->value < 1 || res->value > MAX_PKT_BURST) { 2610 printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST); 2611 return; 2612 } 2613 nb_pkt_per_burst = res->value; 2614 } else { 2615 printf("Unknown parameter\n"); 2616 return; 2617 } 2618 2619 init_port_config(); 2620 2621 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2622 } 2623 2624 cmdline_parse_token_string_t cmd_config_burst_port = 2625 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port"); 2626 cmdline_parse_token_string_t cmd_config_burst_keyword = 2627 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config"); 2628 cmdline_parse_token_string_t cmd_config_burst_all = 2629 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all"); 2630 cmdline_parse_token_string_t cmd_config_burst_name = 2631 TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst"); 2632 cmdline_parse_token_num_t cmd_config_burst_value = 2633 TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16); 2634 2635 cmdline_parse_inst_t cmd_config_burst = { 2636 .f = cmd_config_burst_parsed, 2637 .data = NULL, 2638 .help_str = "port config all burst <value>", 2639 .tokens = { 2640 (void *)&cmd_config_burst_port, 2641 (void *)&cmd_config_burst_keyword, 2642 (void *)&cmd_config_burst_all, 2643 (void *)&cmd_config_burst_name, 2644 (void *)&cmd_config_burst_value, 2645 NULL, 2646 }, 2647 }; 2648 2649 /* *** configure rx/tx queues *** */ 2650 struct cmd_config_thresh { 2651 cmdline_fixed_string_t port; 2652 cmdline_fixed_string_t keyword; 2653 cmdline_fixed_string_t all; 2654 cmdline_fixed_string_t name; 2655 uint8_t value; 2656 }; 2657 2658 static void 2659 cmd_config_thresh_parsed(void *parsed_result, 2660 __attribute__((unused)) struct cmdline *cl, 2661 __attribute__((unused)) void *data) 2662 { 2663 struct cmd_config_thresh *res = parsed_result; 2664 2665 if (!all_ports_stopped()) { 2666 printf("Please stop all ports first\n"); 2667 return; 2668 } 2669 2670 if (!strcmp(res->name, "txpt")) 2671 tx_pthresh = res->value; 2672 else if(!strcmp(res->name, "txht")) 2673 tx_hthresh = res->value; 2674 else if(!strcmp(res->name, "txwt")) 2675 tx_wthresh = res->value; 2676 else if(!strcmp(res->name, "rxpt")) 2677 rx_pthresh = res->value; 2678 else if(!strcmp(res->name, "rxht")) 2679 rx_hthresh = res->value; 2680 else if(!strcmp(res->name, "rxwt")) 2681 rx_wthresh = res->value; 2682 else { 2683 printf("Unknown parameter\n"); 2684 return; 2685 } 2686 2687 init_port_config(); 2688 2689 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2690 } 2691 2692 cmdline_parse_token_string_t cmd_config_thresh_port = 2693 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port"); 2694 cmdline_parse_token_string_t cmd_config_thresh_keyword = 2695 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config"); 2696 cmdline_parse_token_string_t cmd_config_thresh_all = 2697 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all"); 2698 cmdline_parse_token_string_t cmd_config_thresh_name = 2699 TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name, 2700 "txpt#txht#txwt#rxpt#rxht#rxwt"); 2701 cmdline_parse_token_num_t cmd_config_thresh_value = 2702 TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8); 2703 2704 cmdline_parse_inst_t cmd_config_thresh = { 2705 .f = cmd_config_thresh_parsed, 2706 .data = NULL, 2707 .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>", 2708 .tokens = { 2709 (void *)&cmd_config_thresh_port, 2710 (void *)&cmd_config_thresh_keyword, 2711 (void *)&cmd_config_thresh_all, 2712 (void *)&cmd_config_thresh_name, 2713 (void *)&cmd_config_thresh_value, 2714 NULL, 2715 }, 2716 }; 2717 2718 /* *** configure free/rs threshold *** */ 2719 struct cmd_config_threshold { 2720 cmdline_fixed_string_t port; 2721 cmdline_fixed_string_t keyword; 2722 cmdline_fixed_string_t all; 2723 cmdline_fixed_string_t name; 2724 uint16_t value; 2725 }; 2726 2727 static void 2728 cmd_config_threshold_parsed(void *parsed_result, 2729 __attribute__((unused)) struct cmdline *cl, 2730 __attribute__((unused)) void *data) 2731 { 2732 struct cmd_config_threshold *res = parsed_result; 2733 2734 if (!all_ports_stopped()) { 2735 printf("Please stop all ports first\n"); 2736 return; 2737 } 2738 2739 if (!strcmp(res->name, "txfreet")) 2740 tx_free_thresh = res->value; 2741 else if (!strcmp(res->name, "txrst")) 2742 tx_rs_thresh = res->value; 2743 else if (!strcmp(res->name, "rxfreet")) 2744 rx_free_thresh = res->value; 2745 else { 2746 printf("Unknown parameter\n"); 2747 return; 2748 } 2749 2750 init_port_config(); 2751 2752 cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); 2753 } 2754 2755 cmdline_parse_token_string_t cmd_config_threshold_port = 2756 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port"); 2757 cmdline_parse_token_string_t cmd_config_threshold_keyword = 2758 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword, 2759 "config"); 2760 cmdline_parse_token_string_t cmd_config_threshold_all = 2761 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all"); 2762 cmdline_parse_token_string_t cmd_config_threshold_name = 2763 TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name, 2764 "txfreet#txrst#rxfreet"); 2765 cmdline_parse_token_num_t cmd_config_threshold_value = 2766 TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16); 2767 2768 cmdline_parse_inst_t cmd_config_threshold = { 2769 .f = cmd_config_threshold_parsed, 2770 .data = NULL, 2771 .help_str = "port config all txfreet|txrst|rxfreet <value>", 2772 .tokens = { 2773 (void *)&cmd_config_threshold_port, 2774 (void *)&cmd_config_threshold_keyword, 2775 (void *)&cmd_config_threshold_all, 2776 (void *)&cmd_config_threshold_name, 2777 (void *)&cmd_config_threshold_value, 2778 NULL, 2779 }, 2780 }; 2781 2782 /* *** stop *** */ 2783 struct cmd_stop_result { 2784 cmdline_fixed_string_t stop; 2785 }; 2786 2787 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result, 2788 __attribute__((unused)) struct cmdline *cl, 2789 __attribute__((unused)) void *data) 2790 { 2791 stop_packet_forwarding(); 2792 } 2793 2794 cmdline_parse_token_string_t cmd_stop_stop = 2795 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); 2796 2797 cmdline_parse_inst_t cmd_stop = { 2798 .f = cmd_stop_parsed, 2799 .data = NULL, 2800 .help_str = "stop: Stop packet forwarding", 2801 .tokens = { 2802 (void *)&cmd_stop_stop, 2803 NULL, 2804 }, 2805 }; 2806 2807 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */ 2808 2809 unsigned int 2810 parse_item_list(char* str, const char* item_name, unsigned int max_items, 2811 unsigned int *parsed_items, int check_unique_values) 2812 { 2813 unsigned int nb_item; 2814 unsigned int value; 2815 unsigned int i; 2816 unsigned int j; 2817 int value_ok; 2818 char c; 2819 2820 /* 2821 * First parse all items in the list and store their value. 2822 */ 2823 value = 0; 2824 nb_item = 0; 2825 value_ok = 0; 2826 for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) { 2827 c = str[i]; 2828 if ((c >= '0') && (c <= '9')) { 2829 value = (unsigned int) (value * 10 + (c - '0')); 2830 value_ok = 1; 2831 continue; 2832 } 2833 if (c != ',') { 2834 printf("character %c is not a decimal digit\n", c); 2835 return 0; 2836 } 2837 if (! value_ok) { 2838 printf("No valid value before comma\n"); 2839 return 0; 2840 } 2841 if (nb_item < max_items) { 2842 parsed_items[nb_item] = value; 2843 value_ok = 0; 2844 value = 0; 2845 } 2846 nb_item++; 2847 } 2848 if (nb_item >= max_items) { 2849 printf("Number of %s = %u > %u (maximum items)\n", 2850 item_name, nb_item + 1, max_items); 2851 return 0; 2852 } 2853 parsed_items[nb_item++] = value; 2854 if (! check_unique_values) 2855 return nb_item; 2856 2857 /* 2858 * Then, check that all values in the list are differents. 2859 * No optimization here... 2860 */ 2861 for (i = 0; i < nb_item; i++) { 2862 for (j = i + 1; j < nb_item; j++) { 2863 if (parsed_items[j] == parsed_items[i]) { 2864 printf("duplicated %s %u at index %u and %u\n", 2865 item_name, parsed_items[i], i, j); 2866 return 0; 2867 } 2868 } 2869 } 2870 return nb_item; 2871 } 2872 2873 struct cmd_set_list_result { 2874 cmdline_fixed_string_t cmd_keyword; 2875 cmdline_fixed_string_t list_name; 2876 cmdline_fixed_string_t list_of_items; 2877 }; 2878 2879 static void cmd_set_list_parsed(void *parsed_result, 2880 __attribute__((unused)) struct cmdline *cl, 2881 __attribute__((unused)) void *data) 2882 { 2883 struct cmd_set_list_result *res; 2884 union { 2885 unsigned int lcorelist[RTE_MAX_LCORE]; 2886 unsigned int portlist[RTE_MAX_ETHPORTS]; 2887 } parsed_items; 2888 unsigned int nb_item; 2889 2890 if (test_done == 0) { 2891 printf("Please stop forwarding first\n"); 2892 return; 2893 } 2894 2895 res = parsed_result; 2896 if (!strcmp(res->list_name, "corelist")) { 2897 nb_item = parse_item_list(res->list_of_items, "core", 2898 RTE_MAX_LCORE, 2899 parsed_items.lcorelist, 1); 2900 if (nb_item > 0) { 2901 set_fwd_lcores_list(parsed_items.lcorelist, nb_item); 2902 fwd_config_setup(); 2903 } 2904 return; 2905 } 2906 if (!strcmp(res->list_name, "portlist")) { 2907 nb_item = parse_item_list(res->list_of_items, "port", 2908 RTE_MAX_ETHPORTS, 2909 parsed_items.portlist, 1); 2910 if (nb_item > 0) { 2911 set_fwd_ports_list(parsed_items.portlist, nb_item); 2912 fwd_config_setup(); 2913 } 2914 } 2915 } 2916 2917 cmdline_parse_token_string_t cmd_set_list_keyword = 2918 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword, 2919 "set"); 2920 cmdline_parse_token_string_t cmd_set_list_name = 2921 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name, 2922 "corelist#portlist"); 2923 cmdline_parse_token_string_t cmd_set_list_of_items = 2924 TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items, 2925 NULL); 2926 2927 cmdline_parse_inst_t cmd_set_fwd_list = { 2928 .f = cmd_set_list_parsed, 2929 .data = NULL, 2930 .help_str = "set corelist|portlist <list0[,list1]*>", 2931 .tokens = { 2932 (void *)&cmd_set_list_keyword, 2933 (void *)&cmd_set_list_name, 2934 (void *)&cmd_set_list_of_items, 2935 NULL, 2936 }, 2937 }; 2938 2939 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */ 2940 2941 struct cmd_setmask_result { 2942 cmdline_fixed_string_t set; 2943 cmdline_fixed_string_t mask; 2944 uint64_t hexavalue; 2945 }; 2946 2947 static void cmd_set_mask_parsed(void *parsed_result, 2948 __attribute__((unused)) struct cmdline *cl, 2949 __attribute__((unused)) void *data) 2950 { 2951 struct cmd_setmask_result *res = parsed_result; 2952 2953 if (test_done == 0) { 2954 printf("Please stop forwarding first\n"); 2955 return; 2956 } 2957 if (!strcmp(res->mask, "coremask")) { 2958 set_fwd_lcores_mask(res->hexavalue); 2959 fwd_config_setup(); 2960 } else if (!strcmp(res->mask, "portmask")) { 2961 set_fwd_ports_mask(res->hexavalue); 2962 fwd_config_setup(); 2963 } 2964 } 2965 2966 cmdline_parse_token_string_t cmd_setmask_set = 2967 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set"); 2968 cmdline_parse_token_string_t cmd_setmask_mask = 2969 TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask, 2970 "coremask#portmask"); 2971 cmdline_parse_token_num_t cmd_setmask_value = 2972 TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64); 2973 2974 cmdline_parse_inst_t cmd_set_fwd_mask = { 2975 .f = cmd_set_mask_parsed, 2976 .data = NULL, 2977 .help_str = "set coremask|portmask <hexadecimal value>", 2978 .tokens = { 2979 (void *)&cmd_setmask_set, 2980 (void *)&cmd_setmask_mask, 2981 (void *)&cmd_setmask_value, 2982 NULL, 2983 }, 2984 }; 2985 2986 /* 2987 * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION 2988 */ 2989 struct cmd_set_result { 2990 cmdline_fixed_string_t set; 2991 cmdline_fixed_string_t what; 2992 uint16_t value; 2993 }; 2994 2995 static void cmd_set_parsed(void *parsed_result, 2996 __attribute__((unused)) struct cmdline *cl, 2997 __attribute__((unused)) void *data) 2998 { 2999 struct cmd_set_result *res = parsed_result; 3000 if (!strcmp(res->what, "nbport")) { 3001 set_fwd_ports_number(res->value); 3002 fwd_config_setup(); 3003 } else if (!strcmp(res->what, "nbcore")) { 3004 set_fwd_lcores_number(res->value); 3005 fwd_config_setup(); 3006 } else if (!strcmp(res->what, "burst")) 3007 set_nb_pkt_per_burst(res->value); 3008 else if (!strcmp(res->what, "verbose")) 3009 set_verbose_level(res->value); 3010 } 3011 3012 cmdline_parse_token_string_t cmd_set_set = 3013 TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set"); 3014 cmdline_parse_token_string_t cmd_set_what = 3015 TOKEN_STRING_INITIALIZER(struct cmd_set_result, what, 3016 "nbport#nbcore#burst#verbose"); 3017 cmdline_parse_token_num_t cmd_set_value = 3018 TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16); 3019 3020 cmdline_parse_inst_t cmd_set_numbers = { 3021 .f = cmd_set_parsed, 3022 .data = NULL, 3023 .help_str = "set nbport|nbcore|burst|verbose <value>", 3024 .tokens = { 3025 (void *)&cmd_set_set, 3026 (void *)&cmd_set_what, 3027 (void *)&cmd_set_value, 3028 NULL, 3029 }, 3030 }; 3031 3032 /* *** SET LOG LEVEL CONFIGURATION *** */ 3033 3034 struct cmd_set_log_result { 3035 cmdline_fixed_string_t set; 3036 cmdline_fixed_string_t log; 3037 cmdline_fixed_string_t type; 3038 uint32_t level; 3039 }; 3040 3041 static void 3042 cmd_set_log_parsed(void *parsed_result, 3043 __attribute__((unused)) struct cmdline *cl, 3044 __attribute__((unused)) void *data) 3045 { 3046 struct cmd_set_log_result *res; 3047 int ret; 3048 3049 res = parsed_result; 3050 if (!strcmp(res->type, "global")) 3051 rte_log_set_global_level(res->level); 3052 else { 3053 ret = rte_log_set_level_regexp(res->type, res->level); 3054 if (ret < 0) 3055 printf("Unable to set log level\n"); 3056 } 3057 } 3058 3059 cmdline_parse_token_string_t cmd_set_log_set = 3060 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set"); 3061 cmdline_parse_token_string_t cmd_set_log_log = 3062 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log"); 3063 cmdline_parse_token_string_t cmd_set_log_type = 3064 TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL); 3065 cmdline_parse_token_num_t cmd_set_log_level = 3066 TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32); 3067 3068 cmdline_parse_inst_t cmd_set_log = { 3069 .f = cmd_set_log_parsed, 3070 .data = NULL, 3071 .help_str = "set log global|<type> <level>", 3072 .tokens = { 3073 (void *)&cmd_set_log_set, 3074 (void *)&cmd_set_log_log, 3075 (void *)&cmd_set_log_type, 3076 (void *)&cmd_set_log_level, 3077 NULL, 3078 }, 3079 }; 3080 3081 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ 3082 3083 struct cmd_set_txpkts_result { 3084 cmdline_fixed_string_t cmd_keyword; 3085 cmdline_fixed_string_t txpkts; 3086 cmdline_fixed_string_t seg_lengths; 3087 }; 3088 3089 static void 3090 cmd_set_txpkts_parsed(void *parsed_result, 3091 __attribute__((unused)) struct cmdline *cl, 3092 __attribute__((unused)) void *data) 3093 { 3094 struct cmd_set_txpkts_result *res; 3095 unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; 3096 unsigned int nb_segs; 3097 3098 res = parsed_result; 3099 nb_segs = parse_item_list(res->seg_lengths, "segment lengths", 3100 RTE_MAX_SEGS_PER_PKT, seg_lengths, 0); 3101 if (nb_segs > 0) 3102 set_tx_pkt_segments(seg_lengths, nb_segs); 3103 } 3104 3105 cmdline_parse_token_string_t cmd_set_txpkts_keyword = 3106 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3107 cmd_keyword, "set"); 3108 cmdline_parse_token_string_t cmd_set_txpkts_name = 3109 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3110 txpkts, "txpkts"); 3111 cmdline_parse_token_string_t cmd_set_txpkts_lengths = 3112 TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result, 3113 seg_lengths, NULL); 3114 3115 cmdline_parse_inst_t cmd_set_txpkts = { 3116 .f = cmd_set_txpkts_parsed, 3117 .data = NULL, 3118 .help_str = "set txpkts <len0[,len1]*>", 3119 .tokens = { 3120 (void *)&cmd_set_txpkts_keyword, 3121 (void *)&cmd_set_txpkts_name, 3122 (void *)&cmd_set_txpkts_lengths, 3123 NULL, 3124 }, 3125 }; 3126 3127 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */ 3128 3129 struct cmd_set_txsplit_result { 3130 cmdline_fixed_string_t cmd_keyword; 3131 cmdline_fixed_string_t txsplit; 3132 cmdline_fixed_string_t mode; 3133 }; 3134 3135 static void 3136 cmd_set_txsplit_parsed(void *parsed_result, 3137 __attribute__((unused)) struct cmdline *cl, 3138 __attribute__((unused)) void *data) 3139 { 3140 struct cmd_set_txsplit_result *res; 3141 3142 res = parsed_result; 3143 set_tx_pkt_split(res->mode); 3144 } 3145 3146 cmdline_parse_token_string_t cmd_set_txsplit_keyword = 3147 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3148 cmd_keyword, "set"); 3149 cmdline_parse_token_string_t cmd_set_txsplit_name = 3150 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3151 txsplit, "txsplit"); 3152 cmdline_parse_token_string_t cmd_set_txsplit_mode = 3153 TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result, 3154 mode, NULL); 3155 3156 cmdline_parse_inst_t cmd_set_txsplit = { 3157 .f = cmd_set_txsplit_parsed, 3158 .data = NULL, 3159 .help_str = "set txsplit on|off|rand", 3160 .tokens = { 3161 (void *)&cmd_set_txsplit_keyword, 3162 (void *)&cmd_set_txsplit_name, 3163 (void *)&cmd_set_txsplit_mode, 3164 NULL, 3165 }, 3166 }; 3167 3168 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */ 3169 struct cmd_rx_vlan_filter_all_result { 3170 cmdline_fixed_string_t rx_vlan; 3171 cmdline_fixed_string_t what; 3172 cmdline_fixed_string_t all; 3173 portid_t port_id; 3174 }; 3175 3176 static void 3177 cmd_rx_vlan_filter_all_parsed(void *parsed_result, 3178 __attribute__((unused)) struct cmdline *cl, 3179 __attribute__((unused)) void *data) 3180 { 3181 struct cmd_rx_vlan_filter_all_result *res = parsed_result; 3182 3183 if (!strcmp(res->what, "add")) 3184 rx_vlan_all_filter_set(res->port_id, 1); 3185 else 3186 rx_vlan_all_filter_set(res->port_id, 0); 3187 } 3188 3189 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan = 3190 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3191 rx_vlan, "rx_vlan"); 3192 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what = 3193 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3194 what, "add#rm"); 3195 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = 3196 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3197 all, "all"); 3198 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = 3199 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, 3200 port_id, UINT16); 3201 3202 cmdline_parse_inst_t cmd_rx_vlan_filter_all = { 3203 .f = cmd_rx_vlan_filter_all_parsed, 3204 .data = NULL, 3205 .help_str = "rx_vlan add|rm all <port_id>: " 3206 "Add/Remove all identifiers to/from the set of VLAN " 3207 "identifiers filtered by a port", 3208 .tokens = { 3209 (void *)&cmd_rx_vlan_filter_all_rx_vlan, 3210 (void *)&cmd_rx_vlan_filter_all_what, 3211 (void *)&cmd_rx_vlan_filter_all_all, 3212 (void *)&cmd_rx_vlan_filter_all_portid, 3213 NULL, 3214 }, 3215 }; 3216 3217 /* *** VLAN OFFLOAD SET ON A PORT *** */ 3218 struct cmd_vlan_offload_result { 3219 cmdline_fixed_string_t vlan; 3220 cmdline_fixed_string_t set; 3221 cmdline_fixed_string_t vlan_type; 3222 cmdline_fixed_string_t what; 3223 cmdline_fixed_string_t on; 3224 cmdline_fixed_string_t port_id; 3225 }; 3226 3227 static void 3228 cmd_vlan_offload_parsed(void *parsed_result, 3229 __attribute__((unused)) struct cmdline *cl, 3230 __attribute__((unused)) void *data) 3231 { 3232 int on; 3233 struct cmd_vlan_offload_result *res = parsed_result; 3234 char *str; 3235 int i, len = 0; 3236 portid_t port_id = 0; 3237 unsigned int tmp; 3238 3239 str = res->port_id; 3240 len = strnlen(str, STR_TOKEN_SIZE); 3241 i = 0; 3242 /* Get port_id first */ 3243 while(i < len){ 3244 if(str[i] == ',') 3245 break; 3246 3247 i++; 3248 } 3249 str[i]='\0'; 3250 tmp = strtoul(str, NULL, 0); 3251 /* If port_id greater that what portid_t can represent, return */ 3252 if(tmp >= RTE_MAX_ETHPORTS) 3253 return; 3254 port_id = (portid_t)tmp; 3255 3256 if (!strcmp(res->on, "on")) 3257 on = 1; 3258 else 3259 on = 0; 3260 3261 if (!strcmp(res->what, "strip")) 3262 rx_vlan_strip_set(port_id, on); 3263 else if(!strcmp(res->what, "stripq")){ 3264 uint16_t queue_id = 0; 3265 3266 /* No queue_id, return */ 3267 if(i + 1 >= len) { 3268 printf("must specify (port,queue_id)\n"); 3269 return; 3270 } 3271 tmp = strtoul(str + i + 1, NULL, 0); 3272 /* If queue_id greater that what 16-bits can represent, return */ 3273 if(tmp > 0xffff) 3274 return; 3275 3276 queue_id = (uint16_t)tmp; 3277 rx_vlan_strip_set_on_queue(port_id, queue_id, on); 3278 } 3279 else if (!strcmp(res->what, "filter")) 3280 rx_vlan_filter_set(port_id, on); 3281 else 3282 vlan_extend_set(port_id, on); 3283 3284 return; 3285 } 3286 3287 cmdline_parse_token_string_t cmd_vlan_offload_vlan = 3288 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3289 vlan, "vlan"); 3290 cmdline_parse_token_string_t cmd_vlan_offload_set = 3291 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3292 set, "set"); 3293 cmdline_parse_token_string_t cmd_vlan_offload_what = 3294 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3295 what, "strip#filter#qinq#stripq"); 3296 cmdline_parse_token_string_t cmd_vlan_offload_on = 3297 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3298 on, "on#off"); 3299 cmdline_parse_token_string_t cmd_vlan_offload_portid = 3300 TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result, 3301 port_id, NULL); 3302 3303 cmdline_parse_inst_t cmd_vlan_offload = { 3304 .f = cmd_vlan_offload_parsed, 3305 .data = NULL, 3306 .help_str = "vlan set strip|filter|qinq|stripq on|off " 3307 "<port_id[,queue_id]>: " 3308 "Filter/Strip for rx side qinq(extended) for both rx/tx sides", 3309 .tokens = { 3310 (void *)&cmd_vlan_offload_vlan, 3311 (void *)&cmd_vlan_offload_set, 3312 (void *)&cmd_vlan_offload_what, 3313 (void *)&cmd_vlan_offload_on, 3314 (void *)&cmd_vlan_offload_portid, 3315 NULL, 3316 }, 3317 }; 3318 3319 /* *** VLAN TPID SET ON A PORT *** */ 3320 struct cmd_vlan_tpid_result { 3321 cmdline_fixed_string_t vlan; 3322 cmdline_fixed_string_t set; 3323 cmdline_fixed_string_t vlan_type; 3324 cmdline_fixed_string_t what; 3325 uint16_t tp_id; 3326 portid_t port_id; 3327 }; 3328 3329 static void 3330 cmd_vlan_tpid_parsed(void *parsed_result, 3331 __attribute__((unused)) struct cmdline *cl, 3332 __attribute__((unused)) void *data) 3333 { 3334 struct cmd_vlan_tpid_result *res = parsed_result; 3335 enum rte_vlan_type vlan_type; 3336 3337 if (!strcmp(res->vlan_type, "inner")) 3338 vlan_type = ETH_VLAN_TYPE_INNER; 3339 else if (!strcmp(res->vlan_type, "outer")) 3340 vlan_type = ETH_VLAN_TYPE_OUTER; 3341 else { 3342 printf("Unknown vlan type\n"); 3343 return; 3344 } 3345 vlan_tpid_set(res->port_id, vlan_type, res->tp_id); 3346 } 3347 3348 cmdline_parse_token_string_t cmd_vlan_tpid_vlan = 3349 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3350 vlan, "vlan"); 3351 cmdline_parse_token_string_t cmd_vlan_tpid_set = 3352 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3353 set, "set"); 3354 cmdline_parse_token_string_t cmd_vlan_type = 3355 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3356 vlan_type, "inner#outer"); 3357 cmdline_parse_token_string_t cmd_vlan_tpid_what = 3358 TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result, 3359 what, "tpid"); 3360 cmdline_parse_token_num_t cmd_vlan_tpid_tpid = 3361 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3362 tp_id, UINT16); 3363 cmdline_parse_token_num_t cmd_vlan_tpid_portid = 3364 TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result, 3365 port_id, UINT16); 3366 3367 cmdline_parse_inst_t cmd_vlan_tpid = { 3368 .f = cmd_vlan_tpid_parsed, 3369 .data = NULL, 3370 .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: " 3371 "Set the VLAN Ether type", 3372 .tokens = { 3373 (void *)&cmd_vlan_tpid_vlan, 3374 (void *)&cmd_vlan_tpid_set, 3375 (void *)&cmd_vlan_type, 3376 (void *)&cmd_vlan_tpid_what, 3377 (void *)&cmd_vlan_tpid_tpid, 3378 (void *)&cmd_vlan_tpid_portid, 3379 NULL, 3380 }, 3381 }; 3382 3383 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 3384 struct cmd_rx_vlan_filter_result { 3385 cmdline_fixed_string_t rx_vlan; 3386 cmdline_fixed_string_t what; 3387 uint16_t vlan_id; 3388 portid_t port_id; 3389 }; 3390 3391 static void 3392 cmd_rx_vlan_filter_parsed(void *parsed_result, 3393 __attribute__((unused)) struct cmdline *cl, 3394 __attribute__((unused)) void *data) 3395 { 3396 struct cmd_rx_vlan_filter_result *res = parsed_result; 3397 3398 if (!strcmp(res->what, "add")) 3399 rx_vft_set(res->port_id, res->vlan_id, 1); 3400 else 3401 rx_vft_set(res->port_id, res->vlan_id, 0); 3402 } 3403 3404 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan = 3405 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3406 rx_vlan, "rx_vlan"); 3407 cmdline_parse_token_string_t cmd_rx_vlan_filter_what = 3408 TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result, 3409 what, "add#rm"); 3410 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = 3411 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3412 vlan_id, UINT16); 3413 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = 3414 TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, 3415 port_id, UINT16); 3416 3417 cmdline_parse_inst_t cmd_rx_vlan_filter = { 3418 .f = cmd_rx_vlan_filter_parsed, 3419 .data = NULL, 3420 .help_str = "rx_vlan add|rm <vlan_id> <port_id>: " 3421 "Add/Remove a VLAN identifier to/from the set of VLAN " 3422 "identifiers filtered by a port", 3423 .tokens = { 3424 (void *)&cmd_rx_vlan_filter_rx_vlan, 3425 (void *)&cmd_rx_vlan_filter_what, 3426 (void *)&cmd_rx_vlan_filter_vlanid, 3427 (void *)&cmd_rx_vlan_filter_portid, 3428 NULL, 3429 }, 3430 }; 3431 3432 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3433 struct cmd_tx_vlan_set_result { 3434 cmdline_fixed_string_t tx_vlan; 3435 cmdline_fixed_string_t set; 3436 portid_t port_id; 3437 uint16_t vlan_id; 3438 }; 3439 3440 static void 3441 cmd_tx_vlan_set_parsed(void *parsed_result, 3442 __attribute__((unused)) struct cmdline *cl, 3443 __attribute__((unused)) void *data) 3444 { 3445 struct cmd_tx_vlan_set_result *res = parsed_result; 3446 3447 if (!port_is_stopped(res->port_id)) { 3448 printf("Please stop port %d first\n", res->port_id); 3449 return; 3450 } 3451 3452 tx_vlan_set(res->port_id, res->vlan_id); 3453 3454 cmd_reconfig_device_queue(res->port_id, 1, 1); 3455 } 3456 3457 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan = 3458 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3459 tx_vlan, "tx_vlan"); 3460 cmdline_parse_token_string_t cmd_tx_vlan_set_set = 3461 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result, 3462 set, "set"); 3463 cmdline_parse_token_num_t cmd_tx_vlan_set_portid = 3464 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3465 port_id, UINT16); 3466 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = 3467 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, 3468 vlan_id, UINT16); 3469 3470 cmdline_parse_inst_t cmd_tx_vlan_set = { 3471 .f = cmd_tx_vlan_set_parsed, 3472 .data = NULL, 3473 .help_str = "tx_vlan set <port_id> <vlan_id>: " 3474 "Enable hardware insertion of a single VLAN header " 3475 "with a given TAG Identifier in packets sent on a port", 3476 .tokens = { 3477 (void *)&cmd_tx_vlan_set_tx_vlan, 3478 (void *)&cmd_tx_vlan_set_set, 3479 (void *)&cmd_tx_vlan_set_portid, 3480 (void *)&cmd_tx_vlan_set_vlanid, 3481 NULL, 3482 }, 3483 }; 3484 3485 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */ 3486 struct cmd_tx_vlan_set_qinq_result { 3487 cmdline_fixed_string_t tx_vlan; 3488 cmdline_fixed_string_t set; 3489 portid_t port_id; 3490 uint16_t vlan_id; 3491 uint16_t vlan_id_outer; 3492 }; 3493 3494 static void 3495 cmd_tx_vlan_set_qinq_parsed(void *parsed_result, 3496 __attribute__((unused)) struct cmdline *cl, 3497 __attribute__((unused)) void *data) 3498 { 3499 struct cmd_tx_vlan_set_qinq_result *res = parsed_result; 3500 3501 if (!port_is_stopped(res->port_id)) { 3502 printf("Please stop port %d first\n", res->port_id); 3503 return; 3504 } 3505 3506 tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer); 3507 3508 cmd_reconfig_device_queue(res->port_id, 1, 1); 3509 } 3510 3511 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan = 3512 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3513 tx_vlan, "tx_vlan"); 3514 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = 3515 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3516 set, "set"); 3517 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = 3518 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3519 port_id, UINT16); 3520 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = 3521 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3522 vlan_id, UINT16); 3523 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer = 3524 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, 3525 vlan_id_outer, UINT16); 3526 3527 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = { 3528 .f = cmd_tx_vlan_set_qinq_parsed, 3529 .data = NULL, 3530 .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: " 3531 "Enable hardware insertion of double VLAN header " 3532 "with given TAG Identifiers in packets sent on a port", 3533 .tokens = { 3534 (void *)&cmd_tx_vlan_set_qinq_tx_vlan, 3535 (void *)&cmd_tx_vlan_set_qinq_set, 3536 (void *)&cmd_tx_vlan_set_qinq_portid, 3537 (void *)&cmd_tx_vlan_set_qinq_vlanid, 3538 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer, 3539 NULL, 3540 }, 3541 }; 3542 3543 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */ 3544 struct cmd_tx_vlan_set_pvid_result { 3545 cmdline_fixed_string_t tx_vlan; 3546 cmdline_fixed_string_t set; 3547 cmdline_fixed_string_t pvid; 3548 portid_t port_id; 3549 uint16_t vlan_id; 3550 cmdline_fixed_string_t mode; 3551 }; 3552 3553 static void 3554 cmd_tx_vlan_set_pvid_parsed(void *parsed_result, 3555 __attribute__((unused)) struct cmdline *cl, 3556 __attribute__((unused)) void *data) 3557 { 3558 struct cmd_tx_vlan_set_pvid_result *res = parsed_result; 3559 3560 if (strcmp(res->mode, "on") == 0) 3561 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1); 3562 else 3563 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0); 3564 } 3565 3566 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan = 3567 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3568 tx_vlan, "tx_vlan"); 3569 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set = 3570 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3571 set, "set"); 3572 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = 3573 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3574 pvid, "pvid"); 3575 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = 3576 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3577 port_id, UINT16); 3578 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = 3579 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3580 vlan_id, UINT16); 3581 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode = 3582 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, 3583 mode, "on#off"); 3584 3585 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { 3586 .f = cmd_tx_vlan_set_pvid_parsed, 3587 .data = NULL, 3588 .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off", 3589 .tokens = { 3590 (void *)&cmd_tx_vlan_set_pvid_tx_vlan, 3591 (void *)&cmd_tx_vlan_set_pvid_set, 3592 (void *)&cmd_tx_vlan_set_pvid_pvid, 3593 (void *)&cmd_tx_vlan_set_pvid_port_id, 3594 (void *)&cmd_tx_vlan_set_pvid_vlan_id, 3595 (void *)&cmd_tx_vlan_set_pvid_mode, 3596 NULL, 3597 }, 3598 }; 3599 3600 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */ 3601 struct cmd_tx_vlan_reset_result { 3602 cmdline_fixed_string_t tx_vlan; 3603 cmdline_fixed_string_t reset; 3604 portid_t port_id; 3605 }; 3606 3607 static void 3608 cmd_tx_vlan_reset_parsed(void *parsed_result, 3609 __attribute__((unused)) struct cmdline *cl, 3610 __attribute__((unused)) void *data) 3611 { 3612 struct cmd_tx_vlan_reset_result *res = parsed_result; 3613 3614 if (!port_is_stopped(res->port_id)) { 3615 printf("Please stop port %d first\n", res->port_id); 3616 return; 3617 } 3618 3619 tx_vlan_reset(res->port_id); 3620 3621 cmd_reconfig_device_queue(res->port_id, 1, 1); 3622 } 3623 3624 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan = 3625 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3626 tx_vlan, "tx_vlan"); 3627 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = 3628 TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result, 3629 reset, "reset"); 3630 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = 3631 TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, 3632 port_id, UINT16); 3633 3634 cmdline_parse_inst_t cmd_tx_vlan_reset = { 3635 .f = cmd_tx_vlan_reset_parsed, 3636 .data = NULL, 3637 .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a " 3638 "VLAN header in packets sent on a port", 3639 .tokens = { 3640 (void *)&cmd_tx_vlan_reset_tx_vlan, 3641 (void *)&cmd_tx_vlan_reset_reset, 3642 (void *)&cmd_tx_vlan_reset_portid, 3643 NULL, 3644 }, 3645 }; 3646 3647 3648 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */ 3649 struct cmd_csum_result { 3650 cmdline_fixed_string_t csum; 3651 cmdline_fixed_string_t mode; 3652 cmdline_fixed_string_t proto; 3653 cmdline_fixed_string_t hwsw; 3654 portid_t port_id; 3655 }; 3656 3657 static void 3658 csum_show(int port_id) 3659 { 3660 struct rte_eth_dev_info dev_info; 3661 uint64_t tx_offloads; 3662 3663 tx_offloads = ports[port_id].dev_conf.txmode.offloads; 3664 printf("Parse tunnel is %s\n", 3665 (ports[port_id].parse_tunnel) ? "on" : "off"); 3666 printf("IP checksum offload is %s\n", 3667 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw"); 3668 printf("UDP checksum offload is %s\n", 3669 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw"); 3670 printf("TCP checksum offload is %s\n", 3671 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw"); 3672 printf("SCTP checksum offload is %s\n", 3673 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw"); 3674 printf("Outer-Ip checksum offload is %s\n", 3675 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw"); 3676 3677 /* display warnings if configuration is not supported by the NIC */ 3678 rte_eth_dev_info_get(port_id, &dev_info); 3679 if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) && 3680 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) { 3681 printf("Warning: hardware IP checksum enabled but not " 3682 "supported by port %d\n", port_id); 3683 } 3684 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) && 3685 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) { 3686 printf("Warning: hardware UDP checksum enabled but not " 3687 "supported by port %d\n", port_id); 3688 } 3689 if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) && 3690 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) { 3691 printf("Warning: hardware TCP checksum enabled but not " 3692 "supported by port %d\n", port_id); 3693 } 3694 if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) && 3695 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) { 3696 printf("Warning: hardware SCTP checksum enabled but not " 3697 "supported by port %d\n", port_id); 3698 } 3699 if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) && 3700 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) { 3701 printf("Warning: hardware outer IP checksum enabled but not " 3702 "supported by port %d\n", port_id); 3703 } 3704 } 3705 3706 static void 3707 cmd_csum_parsed(void *parsed_result, 3708 __attribute__((unused)) struct cmdline *cl, 3709 __attribute__((unused)) void *data) 3710 { 3711 struct cmd_csum_result *res = parsed_result; 3712 int hw = 0; 3713 uint64_t csum_offloads = 0; 3714 struct rte_eth_dev_info dev_info; 3715 3716 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) { 3717 printf("invalid port %d\n", res->port_id); 3718 return; 3719 } 3720 if (!port_is_stopped(res->port_id)) { 3721 printf("Please stop port %d first\n", res->port_id); 3722 return; 3723 } 3724 3725 rte_eth_dev_info_get(res->port_id, &dev_info); 3726 if (!strcmp(res->mode, "set")) { 3727 3728 if (!strcmp(res->hwsw, "hw")) 3729 hw = 1; 3730 3731 if (!strcmp(res->proto, "ip")) { 3732 if (hw == 0 || (dev_info.tx_offload_capa & 3733 DEV_TX_OFFLOAD_IPV4_CKSUM)) { 3734 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM; 3735 } else { 3736 printf("IP checksum offload is not supported " 3737 "by port %u\n", res->port_id); 3738 } 3739 } else if (!strcmp(res->proto, "udp")) { 3740 if (hw == 0 || (dev_info.tx_offload_capa & 3741 DEV_TX_OFFLOAD_UDP_CKSUM)) { 3742 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM; 3743 } else { 3744 printf("UDP checksum offload is not supported " 3745 "by port %u\n", res->port_id); 3746 } 3747 } else if (!strcmp(res->proto, "tcp")) { 3748 if (hw == 0 || (dev_info.tx_offload_capa & 3749 DEV_TX_OFFLOAD_TCP_CKSUM)) { 3750 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM; 3751 } else { 3752 printf("TCP checksum offload is not supported " 3753 "by port %u\n", res->port_id); 3754 } 3755 } else if (!strcmp(res->proto, "sctp")) { 3756 if (hw == 0 || (dev_info.tx_offload_capa & 3757 DEV_TX_OFFLOAD_SCTP_CKSUM)) { 3758 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM; 3759 } else { 3760 printf("SCTP checksum offload is not supported " 3761 "by port %u\n", res->port_id); 3762 } 3763 } else if (!strcmp(res->proto, "outer-ip")) { 3764 if (hw == 0 || (dev_info.tx_offload_capa & 3765 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) { 3766 csum_offloads |= 3767 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM; 3768 } else { 3769 printf("Outer IP checksum offload is not " 3770 "supported by port %u\n", res->port_id); 3771 } 3772 } 3773 3774 if (hw) { 3775 ports[res->port_id].dev_conf.txmode.offloads |= 3776 csum_offloads; 3777 } else { 3778 ports[res->port_id].dev_conf.txmode.offloads &= 3779 (~csum_offloads); 3780 } 3781 } 3782 csum_show(res->port_id); 3783 3784 cmd_reconfig_device_queue(res->port_id, 1, 1); 3785 } 3786 3787 cmdline_parse_token_string_t cmd_csum_csum = 3788 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3789 csum, "csum"); 3790 cmdline_parse_token_string_t cmd_csum_mode = 3791 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3792 mode, "set"); 3793 cmdline_parse_token_string_t cmd_csum_proto = 3794 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3795 proto, "ip#tcp#udp#sctp#outer-ip"); 3796 cmdline_parse_token_string_t cmd_csum_hwsw = 3797 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3798 hwsw, "hw#sw"); 3799 cmdline_parse_token_num_t cmd_csum_portid = 3800 TOKEN_NUM_INITIALIZER(struct cmd_csum_result, 3801 port_id, UINT16); 3802 3803 cmdline_parse_inst_t cmd_csum_set = { 3804 .f = cmd_csum_parsed, 3805 .data = NULL, 3806 .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: " 3807 "Enable/Disable hardware calculation of L3/L4 checksum when " 3808 "using csum forward engine", 3809 .tokens = { 3810 (void *)&cmd_csum_csum, 3811 (void *)&cmd_csum_mode, 3812 (void *)&cmd_csum_proto, 3813 (void *)&cmd_csum_hwsw, 3814 (void *)&cmd_csum_portid, 3815 NULL, 3816 }, 3817 }; 3818 3819 cmdline_parse_token_string_t cmd_csum_mode_show = 3820 TOKEN_STRING_INITIALIZER(struct cmd_csum_result, 3821 mode, "show"); 3822 3823 cmdline_parse_inst_t cmd_csum_show = { 3824 .f = cmd_csum_parsed, 3825 .data = NULL, 3826 .help_str = "csum show <port_id>: Show checksum offload configuration", 3827 .tokens = { 3828 (void *)&cmd_csum_csum, 3829 (void *)&cmd_csum_mode_show, 3830 (void *)&cmd_csum_portid, 3831 NULL, 3832 }, 3833 }; 3834 3835 /* Enable/disable tunnel parsing */ 3836 struct cmd_csum_tunnel_result { 3837 cmdline_fixed_string_t csum; 3838 cmdline_fixed_string_t parse; 3839 cmdline_fixed_string_t onoff; 3840 portid_t port_id; 3841 }; 3842 3843 static void 3844 cmd_csum_tunnel_parsed(void *parsed_result, 3845 __attribute__((unused)) struct cmdline *cl, 3846 __attribute__((unused)) void *data) 3847 { 3848 struct cmd_csum_tunnel_result *res = parsed_result; 3849 3850 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3851 return; 3852 3853 if (!strcmp(res->onoff, "on")) 3854 ports[res->port_id].parse_tunnel = 1; 3855 else 3856 ports[res->port_id].parse_tunnel = 0; 3857 3858 csum_show(res->port_id); 3859 } 3860 3861 cmdline_parse_token_string_t cmd_csum_tunnel_csum = 3862 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3863 csum, "csum"); 3864 cmdline_parse_token_string_t cmd_csum_tunnel_parse = 3865 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3866 parse, "parse_tunnel"); 3867 cmdline_parse_token_string_t cmd_csum_tunnel_onoff = 3868 TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result, 3869 onoff, "on#off"); 3870 cmdline_parse_token_num_t cmd_csum_tunnel_portid = 3871 TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, 3872 port_id, UINT16); 3873 3874 cmdline_parse_inst_t cmd_csum_tunnel = { 3875 .f = cmd_csum_tunnel_parsed, 3876 .data = NULL, 3877 .help_str = "csum parse_tunnel on|off <port_id>: " 3878 "Enable/Disable parsing of tunnels for csum engine", 3879 .tokens = { 3880 (void *)&cmd_csum_tunnel_csum, 3881 (void *)&cmd_csum_tunnel_parse, 3882 (void *)&cmd_csum_tunnel_onoff, 3883 (void *)&cmd_csum_tunnel_portid, 3884 NULL, 3885 }, 3886 }; 3887 3888 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */ 3889 struct cmd_tso_set_result { 3890 cmdline_fixed_string_t tso; 3891 cmdline_fixed_string_t mode; 3892 uint16_t tso_segsz; 3893 portid_t port_id; 3894 }; 3895 3896 static void 3897 cmd_tso_set_parsed(void *parsed_result, 3898 __attribute__((unused)) struct cmdline *cl, 3899 __attribute__((unused)) void *data) 3900 { 3901 struct cmd_tso_set_result *res = parsed_result; 3902 struct rte_eth_dev_info dev_info; 3903 3904 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 3905 return; 3906 if (!port_is_stopped(res->port_id)) { 3907 printf("Please stop port %d first\n", res->port_id); 3908 return; 3909 } 3910 3911 if (!strcmp(res->mode, "set")) 3912 ports[res->port_id].tso_segsz = res->tso_segsz; 3913 3914 rte_eth_dev_info_get(res->port_id, &dev_info); 3915 if ((ports[res->port_id].tso_segsz != 0) && 3916 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3917 printf("Error: TSO is not supported by port %d\n", 3918 res->port_id); 3919 return; 3920 } 3921 3922 if (ports[res->port_id].tso_segsz == 0) { 3923 ports[res->port_id].dev_conf.txmode.offloads &= 3924 ~DEV_TX_OFFLOAD_TCP_TSO; 3925 printf("TSO for non-tunneled packets is disabled\n"); 3926 } else { 3927 ports[res->port_id].dev_conf.txmode.offloads |= 3928 DEV_TX_OFFLOAD_TCP_TSO; 3929 printf("TSO segment size for non-tunneled packets is %d\n", 3930 ports[res->port_id].tso_segsz); 3931 } 3932 3933 /* display warnings if configuration is not supported by the NIC */ 3934 rte_eth_dev_info_get(res->port_id, &dev_info); 3935 if ((ports[res->port_id].tso_segsz != 0) && 3936 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) { 3937 printf("Warning: TSO enabled but not " 3938 "supported by port %d\n", res->port_id); 3939 } 3940 3941 cmd_reconfig_device_queue(res->port_id, 1, 1); 3942 } 3943 3944 cmdline_parse_token_string_t cmd_tso_set_tso = 3945 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3946 tso, "tso"); 3947 cmdline_parse_token_string_t cmd_tso_set_mode = 3948 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3949 mode, "set"); 3950 cmdline_parse_token_num_t cmd_tso_set_tso_segsz = 3951 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3952 tso_segsz, UINT16); 3953 cmdline_parse_token_num_t cmd_tso_set_portid = 3954 TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, 3955 port_id, UINT16); 3956 3957 cmdline_parse_inst_t cmd_tso_set = { 3958 .f = cmd_tso_set_parsed, 3959 .data = NULL, 3960 .help_str = "tso set <tso_segsz> <port_id>: " 3961 "Set TSO segment size of non-tunneled packets for csum engine " 3962 "(0 to disable)", 3963 .tokens = { 3964 (void *)&cmd_tso_set_tso, 3965 (void *)&cmd_tso_set_mode, 3966 (void *)&cmd_tso_set_tso_segsz, 3967 (void *)&cmd_tso_set_portid, 3968 NULL, 3969 }, 3970 }; 3971 3972 cmdline_parse_token_string_t cmd_tso_show_mode = 3973 TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, 3974 mode, "show"); 3975 3976 3977 cmdline_parse_inst_t cmd_tso_show = { 3978 .f = cmd_tso_set_parsed, 3979 .data = NULL, 3980 .help_str = "tso show <port_id>: " 3981 "Show TSO segment size of non-tunneled packets for csum engine", 3982 .tokens = { 3983 (void *)&cmd_tso_set_tso, 3984 (void *)&cmd_tso_show_mode, 3985 (void *)&cmd_tso_set_portid, 3986 NULL, 3987 }, 3988 }; 3989 3990 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */ 3991 struct cmd_tunnel_tso_set_result { 3992 cmdline_fixed_string_t tso; 3993 cmdline_fixed_string_t mode; 3994 uint16_t tso_segsz; 3995 portid_t port_id; 3996 }; 3997 3998 static struct rte_eth_dev_info 3999 check_tunnel_tso_nic_support(portid_t port_id) 4000 { 4001 struct rte_eth_dev_info dev_info; 4002 4003 rte_eth_dev_info_get(port_id, &dev_info); 4004 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) 4005 printf("Warning: VXLAN TUNNEL TSO not supported therefore " 4006 "not enabled for port %d\n", port_id); 4007 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO)) 4008 printf("Warning: GRE TUNNEL TSO not supported therefore " 4009 "not enabled for port %d\n", port_id); 4010 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO)) 4011 printf("Warning: IPIP TUNNEL TSO not supported therefore " 4012 "not enabled for port %d\n", port_id); 4013 if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO)) 4014 printf("Warning: GENEVE TUNNEL TSO not supported therefore " 4015 "not enabled for port %d\n", port_id); 4016 return dev_info; 4017 } 4018 4019 static void 4020 cmd_tunnel_tso_set_parsed(void *parsed_result, 4021 __attribute__((unused)) struct cmdline *cl, 4022 __attribute__((unused)) void *data) 4023 { 4024 struct cmd_tunnel_tso_set_result *res = parsed_result; 4025 struct rte_eth_dev_info dev_info; 4026 4027 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 4028 return; 4029 if (!port_is_stopped(res->port_id)) { 4030 printf("Please stop port %d first\n", res->port_id); 4031 return; 4032 } 4033 4034 if (!strcmp(res->mode, "set")) 4035 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz; 4036 4037 dev_info = check_tunnel_tso_nic_support(res->port_id); 4038 if (ports[res->port_id].tunnel_tso_segsz == 0) { 4039 ports[res->port_id].dev_conf.txmode.offloads &= 4040 ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO | 4041 DEV_TX_OFFLOAD_GRE_TNL_TSO | 4042 DEV_TX_OFFLOAD_IPIP_TNL_TSO | 4043 DEV_TX_OFFLOAD_GENEVE_TNL_TSO); 4044 printf("TSO for tunneled packets is disabled\n"); 4045 } else { 4046 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO | 4047 DEV_TX_OFFLOAD_GRE_TNL_TSO | 4048 DEV_TX_OFFLOAD_IPIP_TNL_TSO | 4049 DEV_TX_OFFLOAD_GENEVE_TNL_TSO); 4050 4051 ports[res->port_id].dev_conf.txmode.offloads |= 4052 (tso_offloads & dev_info.tx_offload_capa); 4053 printf("TSO segment size for tunneled packets is %d\n", 4054 ports[res->port_id].tunnel_tso_segsz); 4055 4056 /* Below conditions are needed to make it work: 4057 * (1) tunnel TSO is supported by the NIC; 4058 * (2) "csum parse_tunnel" must be set so that tunneled pkts 4059 * are recognized; 4060 * (3) for tunneled pkts with outer L3 of IPv4, 4061 * "csum set outer-ip" must be set to hw, because after tso, 4062 * total_len of outer IP header is changed, and the checksum 4063 * of outer IP header calculated by sw should be wrong; that 4064 * is not necessary for IPv6 tunneled pkts because there's no 4065 * checksum in IP header anymore. 4066 */ 4067 4068 if (!ports[res->port_id].parse_tunnel) 4069 printf("Warning: csum parse_tunnel must be set " 4070 "so that tunneled packets are recognized\n"); 4071 if (!(ports[res->port_id].dev_conf.txmode.offloads & 4072 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) 4073 printf("Warning: csum set outer-ip must be set to hw " 4074 "if outer L3 is IPv4; not necessary for IPv6\n"); 4075 } 4076 4077 cmd_reconfig_device_queue(res->port_id, 1, 1); 4078 } 4079 4080 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso = 4081 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 4082 tso, "tunnel_tso"); 4083 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode = 4084 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 4085 mode, "set"); 4086 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = 4087 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 4088 tso_segsz, UINT16); 4089 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = 4090 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, 4091 port_id, UINT16); 4092 4093 cmdline_parse_inst_t cmd_tunnel_tso_set = { 4094 .f = cmd_tunnel_tso_set_parsed, 4095 .data = NULL, 4096 .help_str = "tunnel_tso set <tso_segsz> <port_id>: " 4097 "Set TSO segment size of tunneled packets for csum engine " 4098 "(0 to disable)", 4099 .tokens = { 4100 (void *)&cmd_tunnel_tso_set_tso, 4101 (void *)&cmd_tunnel_tso_set_mode, 4102 (void *)&cmd_tunnel_tso_set_tso_segsz, 4103 (void *)&cmd_tunnel_tso_set_portid, 4104 NULL, 4105 }, 4106 }; 4107 4108 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode = 4109 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result, 4110 mode, "show"); 4111 4112 4113 cmdline_parse_inst_t cmd_tunnel_tso_show = { 4114 .f = cmd_tunnel_tso_set_parsed, 4115 .data = NULL, 4116 .help_str = "tunnel_tso show <port_id> " 4117 "Show TSO segment size of tunneled packets for csum engine", 4118 .tokens = { 4119 (void *)&cmd_tunnel_tso_set_tso, 4120 (void *)&cmd_tunnel_tso_show_mode, 4121 (void *)&cmd_tunnel_tso_set_portid, 4122 NULL, 4123 }, 4124 }; 4125 4126 /* *** SET GRO FOR A PORT *** */ 4127 struct cmd_gro_enable_result { 4128 cmdline_fixed_string_t cmd_set; 4129 cmdline_fixed_string_t cmd_port; 4130 cmdline_fixed_string_t cmd_keyword; 4131 cmdline_fixed_string_t cmd_onoff; 4132 portid_t cmd_pid; 4133 }; 4134 4135 static void 4136 cmd_gro_enable_parsed(void *parsed_result, 4137 __attribute__((unused)) struct cmdline *cl, 4138 __attribute__((unused)) void *data) 4139 { 4140 struct cmd_gro_enable_result *res; 4141 4142 res = parsed_result; 4143 if (!strcmp(res->cmd_keyword, "gro")) 4144 setup_gro(res->cmd_onoff, res->cmd_pid); 4145 } 4146 4147 cmdline_parse_token_string_t cmd_gro_enable_set = 4148 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 4149 cmd_set, "set"); 4150 cmdline_parse_token_string_t cmd_gro_enable_port = 4151 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 4152 cmd_keyword, "port"); 4153 cmdline_parse_token_num_t cmd_gro_enable_pid = 4154 TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result, 4155 cmd_pid, UINT16); 4156 cmdline_parse_token_string_t cmd_gro_enable_keyword = 4157 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 4158 cmd_keyword, "gro"); 4159 cmdline_parse_token_string_t cmd_gro_enable_onoff = 4160 TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, 4161 cmd_onoff, "on#off"); 4162 4163 cmdline_parse_inst_t cmd_gro_enable = { 4164 .f = cmd_gro_enable_parsed, 4165 .data = NULL, 4166 .help_str = "set port <port_id> gro on|off", 4167 .tokens = { 4168 (void *)&cmd_gro_enable_set, 4169 (void *)&cmd_gro_enable_port, 4170 (void *)&cmd_gro_enable_pid, 4171 (void *)&cmd_gro_enable_keyword, 4172 (void *)&cmd_gro_enable_onoff, 4173 NULL, 4174 }, 4175 }; 4176 4177 /* *** DISPLAY GRO CONFIGURATION *** */ 4178 struct cmd_gro_show_result { 4179 cmdline_fixed_string_t cmd_show; 4180 cmdline_fixed_string_t cmd_port; 4181 cmdline_fixed_string_t cmd_keyword; 4182 portid_t cmd_pid; 4183 }; 4184 4185 static void 4186 cmd_gro_show_parsed(void *parsed_result, 4187 __attribute__((unused)) struct cmdline *cl, 4188 __attribute__((unused)) void *data) 4189 { 4190 struct cmd_gro_show_result *res; 4191 4192 res = parsed_result; 4193 if (!strcmp(res->cmd_keyword, "gro")) 4194 show_gro(res->cmd_pid); 4195 } 4196 4197 cmdline_parse_token_string_t cmd_gro_show_show = 4198 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 4199 cmd_show, "show"); 4200 cmdline_parse_token_string_t cmd_gro_show_port = 4201 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 4202 cmd_port, "port"); 4203 cmdline_parse_token_num_t cmd_gro_show_pid = 4204 TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result, 4205 cmd_pid, UINT16); 4206 cmdline_parse_token_string_t cmd_gro_show_keyword = 4207 TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, 4208 cmd_keyword, "gro"); 4209 4210 cmdline_parse_inst_t cmd_gro_show = { 4211 .f = cmd_gro_show_parsed, 4212 .data = NULL, 4213 .help_str = "show port <port_id> gro", 4214 .tokens = { 4215 (void *)&cmd_gro_show_show, 4216 (void *)&cmd_gro_show_port, 4217 (void *)&cmd_gro_show_pid, 4218 (void *)&cmd_gro_show_keyword, 4219 NULL, 4220 }, 4221 }; 4222 4223 /* *** SET FLUSH CYCLES FOR GRO *** */ 4224 struct cmd_gro_flush_result { 4225 cmdline_fixed_string_t cmd_set; 4226 cmdline_fixed_string_t cmd_keyword; 4227 cmdline_fixed_string_t cmd_flush; 4228 uint8_t cmd_cycles; 4229 }; 4230 4231 static void 4232 cmd_gro_flush_parsed(void *parsed_result, 4233 __attribute__((unused)) struct cmdline *cl, 4234 __attribute__((unused)) void *data) 4235 { 4236 struct cmd_gro_flush_result *res; 4237 4238 res = parsed_result; 4239 if ((!strcmp(res->cmd_keyword, "gro")) && 4240 (!strcmp(res->cmd_flush, "flush"))) 4241 setup_gro_flush_cycles(res->cmd_cycles); 4242 } 4243 4244 cmdline_parse_token_string_t cmd_gro_flush_set = 4245 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4246 cmd_set, "set"); 4247 cmdline_parse_token_string_t cmd_gro_flush_keyword = 4248 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4249 cmd_keyword, "gro"); 4250 cmdline_parse_token_string_t cmd_gro_flush_flush = 4251 TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, 4252 cmd_flush, "flush"); 4253 cmdline_parse_token_num_t cmd_gro_flush_cycles = 4254 TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result, 4255 cmd_cycles, UINT8); 4256 4257 cmdline_parse_inst_t cmd_gro_flush = { 4258 .f = cmd_gro_flush_parsed, 4259 .data = NULL, 4260 .help_str = "set gro flush <cycles>", 4261 .tokens = { 4262 (void *)&cmd_gro_flush_set, 4263 (void *)&cmd_gro_flush_keyword, 4264 (void *)&cmd_gro_flush_flush, 4265 (void *)&cmd_gro_flush_cycles, 4266 NULL, 4267 }, 4268 }; 4269 4270 /* *** ENABLE/DISABLE GSO *** */ 4271 struct cmd_gso_enable_result { 4272 cmdline_fixed_string_t cmd_set; 4273 cmdline_fixed_string_t cmd_port; 4274 cmdline_fixed_string_t cmd_keyword; 4275 cmdline_fixed_string_t cmd_mode; 4276 portid_t cmd_pid; 4277 }; 4278 4279 static void 4280 cmd_gso_enable_parsed(void *parsed_result, 4281 __attribute__((unused)) struct cmdline *cl, 4282 __attribute__((unused)) void *data) 4283 { 4284 struct cmd_gso_enable_result *res; 4285 4286 res = parsed_result; 4287 if (!strcmp(res->cmd_keyword, "gso")) 4288 setup_gso(res->cmd_mode, res->cmd_pid); 4289 } 4290 4291 cmdline_parse_token_string_t cmd_gso_enable_set = 4292 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4293 cmd_set, "set"); 4294 cmdline_parse_token_string_t cmd_gso_enable_port = 4295 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4296 cmd_port, "port"); 4297 cmdline_parse_token_string_t cmd_gso_enable_keyword = 4298 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4299 cmd_keyword, "gso"); 4300 cmdline_parse_token_string_t cmd_gso_enable_mode = 4301 TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, 4302 cmd_mode, "on#off"); 4303 cmdline_parse_token_num_t cmd_gso_enable_pid = 4304 TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result, 4305 cmd_pid, UINT16); 4306 4307 cmdline_parse_inst_t cmd_gso_enable = { 4308 .f = cmd_gso_enable_parsed, 4309 .data = NULL, 4310 .help_str = "set port <port_id> gso on|off", 4311 .tokens = { 4312 (void *)&cmd_gso_enable_set, 4313 (void *)&cmd_gso_enable_port, 4314 (void *)&cmd_gso_enable_pid, 4315 (void *)&cmd_gso_enable_keyword, 4316 (void *)&cmd_gso_enable_mode, 4317 NULL, 4318 }, 4319 }; 4320 4321 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */ 4322 struct cmd_gso_size_result { 4323 cmdline_fixed_string_t cmd_set; 4324 cmdline_fixed_string_t cmd_keyword; 4325 cmdline_fixed_string_t cmd_segsz; 4326 uint16_t cmd_size; 4327 }; 4328 4329 static void 4330 cmd_gso_size_parsed(void *parsed_result, 4331 __attribute__((unused)) struct cmdline *cl, 4332 __attribute__((unused)) void *data) 4333 { 4334 struct cmd_gso_size_result *res = parsed_result; 4335 4336 if (test_done == 0) { 4337 printf("Before setting GSO segsz, please first" 4338 " stop fowarding\n"); 4339 return; 4340 } 4341 4342 if (!strcmp(res->cmd_keyword, "gso") && 4343 !strcmp(res->cmd_segsz, "segsz")) { 4344 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN) 4345 printf("gso_size should be larger than %zu." 4346 " Please input a legal value\n", 4347 RTE_GSO_SEG_SIZE_MIN); 4348 else 4349 gso_max_segment_size = res->cmd_size; 4350 } 4351 } 4352 4353 cmdline_parse_token_string_t cmd_gso_size_set = 4354 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4355 cmd_set, "set"); 4356 cmdline_parse_token_string_t cmd_gso_size_keyword = 4357 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4358 cmd_keyword, "gso"); 4359 cmdline_parse_token_string_t cmd_gso_size_segsz = 4360 TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, 4361 cmd_segsz, "segsz"); 4362 cmdline_parse_token_num_t cmd_gso_size_size = 4363 TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result, 4364 cmd_size, UINT16); 4365 4366 cmdline_parse_inst_t cmd_gso_size = { 4367 .f = cmd_gso_size_parsed, 4368 .data = NULL, 4369 .help_str = "set gso segsz <length>", 4370 .tokens = { 4371 (void *)&cmd_gso_size_set, 4372 (void *)&cmd_gso_size_keyword, 4373 (void *)&cmd_gso_size_segsz, 4374 (void *)&cmd_gso_size_size, 4375 NULL, 4376 }, 4377 }; 4378 4379 /* *** SHOW GSO CONFIGURATION *** */ 4380 struct cmd_gso_show_result { 4381 cmdline_fixed_string_t cmd_show; 4382 cmdline_fixed_string_t cmd_port; 4383 cmdline_fixed_string_t cmd_keyword; 4384 portid_t cmd_pid; 4385 }; 4386 4387 static void 4388 cmd_gso_show_parsed(void *parsed_result, 4389 __attribute__((unused)) struct cmdline *cl, 4390 __attribute__((unused)) void *data) 4391 { 4392 struct cmd_gso_show_result *res = parsed_result; 4393 4394 if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { 4395 printf("invalid port id %u\n", res->cmd_pid); 4396 return; 4397 } 4398 if (!strcmp(res->cmd_keyword, "gso")) { 4399 if (gso_ports[res->cmd_pid].enable) { 4400 printf("Max GSO'd packet size: %uB\n" 4401 "Supported GSO types: TCP/IPv4, " 4402 "VxLAN with inner TCP/IPv4 packet, " 4403 "GRE with inner TCP/IPv4 packet\n", 4404 gso_max_segment_size); 4405 } else 4406 printf("GSO is not enabled on Port %u\n", res->cmd_pid); 4407 } 4408 } 4409 4410 cmdline_parse_token_string_t cmd_gso_show_show = 4411 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4412 cmd_show, "show"); 4413 cmdline_parse_token_string_t cmd_gso_show_port = 4414 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4415 cmd_port, "port"); 4416 cmdline_parse_token_string_t cmd_gso_show_keyword = 4417 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, 4418 cmd_keyword, "gso"); 4419 cmdline_parse_token_num_t cmd_gso_show_pid = 4420 TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result, 4421 cmd_pid, UINT16); 4422 4423 cmdline_parse_inst_t cmd_gso_show = { 4424 .f = cmd_gso_show_parsed, 4425 .data = NULL, 4426 .help_str = "show port <port_id> gso", 4427 .tokens = { 4428 (void *)&cmd_gso_show_show, 4429 (void *)&cmd_gso_show_port, 4430 (void *)&cmd_gso_show_pid, 4431 (void *)&cmd_gso_show_keyword, 4432 NULL, 4433 }, 4434 }; 4435 4436 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ 4437 struct cmd_set_flush_rx { 4438 cmdline_fixed_string_t set; 4439 cmdline_fixed_string_t flush_rx; 4440 cmdline_fixed_string_t mode; 4441 }; 4442 4443 static void 4444 cmd_set_flush_rx_parsed(void *parsed_result, 4445 __attribute__((unused)) struct cmdline *cl, 4446 __attribute__((unused)) void *data) 4447 { 4448 struct cmd_set_flush_rx *res = parsed_result; 4449 no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 4450 } 4451 4452 cmdline_parse_token_string_t cmd_setflushrx_set = 4453 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4454 set, "set"); 4455 cmdline_parse_token_string_t cmd_setflushrx_flush_rx = 4456 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4457 flush_rx, "flush_rx"); 4458 cmdline_parse_token_string_t cmd_setflushrx_mode = 4459 TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx, 4460 mode, "on#off"); 4461 4462 4463 cmdline_parse_inst_t cmd_set_flush_rx = { 4464 .f = cmd_set_flush_rx_parsed, 4465 .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams", 4466 .data = NULL, 4467 .tokens = { 4468 (void *)&cmd_setflushrx_set, 4469 (void *)&cmd_setflushrx_flush_rx, 4470 (void *)&cmd_setflushrx_mode, 4471 NULL, 4472 }, 4473 }; 4474 4475 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */ 4476 struct cmd_set_link_check { 4477 cmdline_fixed_string_t set; 4478 cmdline_fixed_string_t link_check; 4479 cmdline_fixed_string_t mode; 4480 }; 4481 4482 static void 4483 cmd_set_link_check_parsed(void *parsed_result, 4484 __attribute__((unused)) struct cmdline *cl, 4485 __attribute__((unused)) void *data) 4486 { 4487 struct cmd_set_link_check *res = parsed_result; 4488 no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1); 4489 } 4490 4491 cmdline_parse_token_string_t cmd_setlinkcheck_set = 4492 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4493 set, "set"); 4494 cmdline_parse_token_string_t cmd_setlinkcheck_link_check = 4495 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4496 link_check, "link_check"); 4497 cmdline_parse_token_string_t cmd_setlinkcheck_mode = 4498 TOKEN_STRING_INITIALIZER(struct cmd_set_link_check, 4499 mode, "on#off"); 4500 4501 4502 cmdline_parse_inst_t cmd_set_link_check = { 4503 .f = cmd_set_link_check_parsed, 4504 .help_str = "set link_check on|off: Enable/Disable link status check " 4505 "when starting/stopping a port", 4506 .data = NULL, 4507 .tokens = { 4508 (void *)&cmd_setlinkcheck_set, 4509 (void *)&cmd_setlinkcheck_link_check, 4510 (void *)&cmd_setlinkcheck_mode, 4511 NULL, 4512 }, 4513 }; 4514 4515 /* *** SET NIC BYPASS MODE *** */ 4516 struct cmd_set_bypass_mode_result { 4517 cmdline_fixed_string_t set; 4518 cmdline_fixed_string_t bypass; 4519 cmdline_fixed_string_t mode; 4520 cmdline_fixed_string_t value; 4521 portid_t port_id; 4522 }; 4523 4524 static void 4525 cmd_set_bypass_mode_parsed(void *parsed_result, 4526 __attribute__((unused)) struct cmdline *cl, 4527 __attribute__((unused)) void *data) 4528 { 4529 struct cmd_set_bypass_mode_result *res = parsed_result; 4530 portid_t port_id = res->port_id; 4531 int32_t rc = -EINVAL; 4532 4533 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4534 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4535 4536 if (!strcmp(res->value, "bypass")) 4537 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4538 else if (!strcmp(res->value, "isolate")) 4539 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4540 else 4541 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4542 4543 /* Set the bypass mode for the relevant port. */ 4544 rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); 4545 #endif 4546 if (rc != 0) 4547 printf("\t Failed to set bypass mode for port = %d.\n", port_id); 4548 } 4549 4550 cmdline_parse_token_string_t cmd_setbypass_mode_set = 4551 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4552 set, "set"); 4553 cmdline_parse_token_string_t cmd_setbypass_mode_bypass = 4554 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4555 bypass, "bypass"); 4556 cmdline_parse_token_string_t cmd_setbypass_mode_mode = 4557 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4558 mode, "mode"); 4559 cmdline_parse_token_string_t cmd_setbypass_mode_value = 4560 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, 4561 value, "normal#bypass#isolate"); 4562 cmdline_parse_token_num_t cmd_setbypass_mode_port = 4563 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, 4564 port_id, UINT16); 4565 4566 cmdline_parse_inst_t cmd_set_bypass_mode = { 4567 .f = cmd_set_bypass_mode_parsed, 4568 .help_str = "set bypass mode normal|bypass|isolate <port_id>: " 4569 "Set the NIC bypass mode for port_id", 4570 .data = NULL, 4571 .tokens = { 4572 (void *)&cmd_setbypass_mode_set, 4573 (void *)&cmd_setbypass_mode_bypass, 4574 (void *)&cmd_setbypass_mode_mode, 4575 (void *)&cmd_setbypass_mode_value, 4576 (void *)&cmd_setbypass_mode_port, 4577 NULL, 4578 }, 4579 }; 4580 4581 /* *** SET NIC BYPASS EVENT *** */ 4582 struct cmd_set_bypass_event_result { 4583 cmdline_fixed_string_t set; 4584 cmdline_fixed_string_t bypass; 4585 cmdline_fixed_string_t event; 4586 cmdline_fixed_string_t event_value; 4587 cmdline_fixed_string_t mode; 4588 cmdline_fixed_string_t mode_value; 4589 portid_t port_id; 4590 }; 4591 4592 static void 4593 cmd_set_bypass_event_parsed(void *parsed_result, 4594 __attribute__((unused)) struct cmdline *cl, 4595 __attribute__((unused)) void *data) 4596 { 4597 int32_t rc = -EINVAL; 4598 struct cmd_set_bypass_event_result *res = parsed_result; 4599 portid_t port_id = res->port_id; 4600 4601 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4602 uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4603 uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4604 4605 if (!strcmp(res->event_value, "timeout")) 4606 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; 4607 else if (!strcmp(res->event_value, "os_on")) 4608 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; 4609 else if (!strcmp(res->event_value, "os_off")) 4610 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; 4611 else if (!strcmp(res->event_value, "power_on")) 4612 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; 4613 else if (!strcmp(res->event_value, "power_off")) 4614 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; 4615 else 4616 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; 4617 4618 if (!strcmp(res->mode_value, "bypass")) 4619 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; 4620 else if (!strcmp(res->mode_value, "isolate")) 4621 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; 4622 else 4623 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; 4624 4625 /* Set the watchdog timeout. */ 4626 if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { 4627 4628 rc = -EINVAL; 4629 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { 4630 rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, 4631 bypass_timeout); 4632 } 4633 if (rc != 0) { 4634 printf("Failed to set timeout value %u " 4635 "for port %d, errto code: %d.\n", 4636 bypass_timeout, port_id, rc); 4637 } 4638 } 4639 4640 /* Set the bypass event to transition to bypass mode. */ 4641 rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, 4642 bypass_mode); 4643 #endif 4644 4645 if (rc != 0) 4646 printf("\t Failed to set bypass event for port = %d.\n", 4647 port_id); 4648 } 4649 4650 cmdline_parse_token_string_t cmd_setbypass_event_set = 4651 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4652 set, "set"); 4653 cmdline_parse_token_string_t cmd_setbypass_event_bypass = 4654 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4655 bypass, "bypass"); 4656 cmdline_parse_token_string_t cmd_setbypass_event_event = 4657 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4658 event, "event"); 4659 cmdline_parse_token_string_t cmd_setbypass_event_event_value = 4660 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4661 event_value, "none#timeout#os_off#os_on#power_on#power_off"); 4662 cmdline_parse_token_string_t cmd_setbypass_event_mode = 4663 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4664 mode, "mode"); 4665 cmdline_parse_token_string_t cmd_setbypass_event_mode_value = 4666 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, 4667 mode_value, "normal#bypass#isolate"); 4668 cmdline_parse_token_num_t cmd_setbypass_event_port = 4669 TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, 4670 port_id, UINT16); 4671 4672 cmdline_parse_inst_t cmd_set_bypass_event = { 4673 .f = cmd_set_bypass_event_parsed, 4674 .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" 4675 "power_off mode normal|bypass|isolate <port_id>: " 4676 "Set the NIC bypass event mode for port_id", 4677 .data = NULL, 4678 .tokens = { 4679 (void *)&cmd_setbypass_event_set, 4680 (void *)&cmd_setbypass_event_bypass, 4681 (void *)&cmd_setbypass_event_event, 4682 (void *)&cmd_setbypass_event_event_value, 4683 (void *)&cmd_setbypass_event_mode, 4684 (void *)&cmd_setbypass_event_mode_value, 4685 (void *)&cmd_setbypass_event_port, 4686 NULL, 4687 }, 4688 }; 4689 4690 4691 /* *** SET NIC BYPASS TIMEOUT *** */ 4692 struct cmd_set_bypass_timeout_result { 4693 cmdline_fixed_string_t set; 4694 cmdline_fixed_string_t bypass; 4695 cmdline_fixed_string_t timeout; 4696 cmdline_fixed_string_t value; 4697 }; 4698 4699 static void 4700 cmd_set_bypass_timeout_parsed(void *parsed_result, 4701 __attribute__((unused)) struct cmdline *cl, 4702 __attribute__((unused)) void *data) 4703 { 4704 __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result; 4705 4706 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4707 if (!strcmp(res->value, "1.5")) 4708 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; 4709 else if (!strcmp(res->value, "2")) 4710 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; 4711 else if (!strcmp(res->value, "3")) 4712 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; 4713 else if (!strcmp(res->value, "4")) 4714 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; 4715 else if (!strcmp(res->value, "8")) 4716 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; 4717 else if (!strcmp(res->value, "16")) 4718 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; 4719 else if (!strcmp(res->value, "32")) 4720 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; 4721 else 4722 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4723 #endif 4724 } 4725 4726 cmdline_parse_token_string_t cmd_setbypass_timeout_set = 4727 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4728 set, "set"); 4729 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = 4730 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4731 bypass, "bypass"); 4732 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = 4733 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4734 timeout, "timeout"); 4735 cmdline_parse_token_string_t cmd_setbypass_timeout_value = 4736 TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, 4737 value, "0#1.5#2#3#4#8#16#32"); 4738 4739 cmdline_parse_inst_t cmd_set_bypass_timeout = { 4740 .f = cmd_set_bypass_timeout_parsed, 4741 .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " 4742 "Set the NIC bypass watchdog timeout in seconds", 4743 .data = NULL, 4744 .tokens = { 4745 (void *)&cmd_setbypass_timeout_set, 4746 (void *)&cmd_setbypass_timeout_bypass, 4747 (void *)&cmd_setbypass_timeout_timeout, 4748 (void *)&cmd_setbypass_timeout_value, 4749 NULL, 4750 }, 4751 }; 4752 4753 /* *** SHOW NIC BYPASS MODE *** */ 4754 struct cmd_show_bypass_config_result { 4755 cmdline_fixed_string_t show; 4756 cmdline_fixed_string_t bypass; 4757 cmdline_fixed_string_t config; 4758 portid_t port_id; 4759 }; 4760 4761 static void 4762 cmd_show_bypass_config_parsed(void *parsed_result, 4763 __attribute__((unused)) struct cmdline *cl, 4764 __attribute__((unused)) void *data) 4765 { 4766 struct cmd_show_bypass_config_result *res = parsed_result; 4767 portid_t port_id = res->port_id; 4768 int rc = -EINVAL; 4769 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS 4770 uint32_t event_mode; 4771 uint32_t bypass_mode; 4772 uint32_t timeout = bypass_timeout; 4773 int i; 4774 4775 static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = 4776 {"off", "1.5", "2", "3", "4", "8", "16", "32"}; 4777 static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = 4778 {"UNKNOWN", "normal", "bypass", "isolate"}; 4779 static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { 4780 "NONE", 4781 "OS/board on", 4782 "power supply on", 4783 "OS/board off", 4784 "power supply off", 4785 "timeout"}; 4786 int num_events = (sizeof events) / (sizeof events[0]); 4787 4788 /* Display the bypass mode.*/ 4789 if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { 4790 printf("\tFailed to get bypass mode for port = %d\n", port_id); 4791 return; 4792 } 4793 else { 4794 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) 4795 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4796 4797 printf("\tbypass mode = %s\n", modes[bypass_mode]); 4798 } 4799 4800 /* Display the bypass timeout.*/ 4801 if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) 4802 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; 4803 4804 printf("\tbypass timeout = %s\n", timeouts[timeout]); 4805 4806 /* Display the bypass events and associated modes. */ 4807 for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) { 4808 4809 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { 4810 printf("\tFailed to get bypass mode for event = %s\n", 4811 events[i]); 4812 } else { 4813 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) 4814 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; 4815 4816 printf("\tbypass event: %-16s = %s\n", events[i], 4817 modes[event_mode]); 4818 } 4819 } 4820 #endif 4821 if (rc != 0) 4822 printf("\tFailed to get bypass configuration for port = %d\n", 4823 port_id); 4824 } 4825 4826 cmdline_parse_token_string_t cmd_showbypass_config_show = 4827 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4828 show, "show"); 4829 cmdline_parse_token_string_t cmd_showbypass_config_bypass = 4830 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4831 bypass, "bypass"); 4832 cmdline_parse_token_string_t cmd_showbypass_config_config = 4833 TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, 4834 config, "config"); 4835 cmdline_parse_token_num_t cmd_showbypass_config_port = 4836 TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, 4837 port_id, UINT16); 4838 4839 cmdline_parse_inst_t cmd_show_bypass_config = { 4840 .f = cmd_show_bypass_config_parsed, 4841 .help_str = "show bypass config <port_id>: " 4842 "Show the NIC bypass config for port_id", 4843 .data = NULL, 4844 .tokens = { 4845 (void *)&cmd_showbypass_config_show, 4846 (void *)&cmd_showbypass_config_bypass, 4847 (void *)&cmd_showbypass_config_config, 4848 (void *)&cmd_showbypass_config_port, 4849 NULL, 4850 }, 4851 }; 4852 4853 #ifdef RTE_LIBRTE_PMD_BOND 4854 /* *** SET BONDING MODE *** */ 4855 struct cmd_set_bonding_mode_result { 4856 cmdline_fixed_string_t set; 4857 cmdline_fixed_string_t bonding; 4858 cmdline_fixed_string_t mode; 4859 uint8_t value; 4860 portid_t port_id; 4861 }; 4862 4863 static void cmd_set_bonding_mode_parsed(void *parsed_result, 4864 __attribute__((unused)) struct cmdline *cl, 4865 __attribute__((unused)) void *data) 4866 { 4867 struct cmd_set_bonding_mode_result *res = parsed_result; 4868 portid_t port_id = res->port_id; 4869 4870 /* Set the bonding mode for the relevant port. */ 4871 if (0 != rte_eth_bond_mode_set(port_id, res->value)) 4872 printf("\t Failed to set bonding mode for port = %d.\n", port_id); 4873 } 4874 4875 cmdline_parse_token_string_t cmd_setbonding_mode_set = 4876 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4877 set, "set"); 4878 cmdline_parse_token_string_t cmd_setbonding_mode_bonding = 4879 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4880 bonding, "bonding"); 4881 cmdline_parse_token_string_t cmd_setbonding_mode_mode = 4882 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, 4883 mode, "mode"); 4884 cmdline_parse_token_num_t cmd_setbonding_mode_value = 4885 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4886 value, UINT8); 4887 cmdline_parse_token_num_t cmd_setbonding_mode_port = 4888 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, 4889 port_id, UINT16); 4890 4891 cmdline_parse_inst_t cmd_set_bonding_mode = { 4892 .f = cmd_set_bonding_mode_parsed, 4893 .help_str = "set bonding mode <mode_value> <port_id>: " 4894 "Set the bonding mode for port_id", 4895 .data = NULL, 4896 .tokens = { 4897 (void *) &cmd_setbonding_mode_set, 4898 (void *) &cmd_setbonding_mode_bonding, 4899 (void *) &cmd_setbonding_mode_mode, 4900 (void *) &cmd_setbonding_mode_value, 4901 (void *) &cmd_setbonding_mode_port, 4902 NULL 4903 } 4904 }; 4905 4906 /* *** SET BONDING SLOW_QUEUE SW/HW *** */ 4907 struct cmd_set_bonding_lacp_dedicated_queues_result { 4908 cmdline_fixed_string_t set; 4909 cmdline_fixed_string_t bonding; 4910 cmdline_fixed_string_t lacp; 4911 cmdline_fixed_string_t dedicated_queues; 4912 portid_t port_id; 4913 cmdline_fixed_string_t mode; 4914 }; 4915 4916 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result, 4917 __attribute__((unused)) struct cmdline *cl, 4918 __attribute__((unused)) void *data) 4919 { 4920 struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result; 4921 portid_t port_id = res->port_id; 4922 struct rte_port *port; 4923 4924 port = &ports[port_id]; 4925 4926 /** Check if the port is not started **/ 4927 if (port->port_status != RTE_PORT_STOPPED) { 4928 printf("Please stop port %d first\n", port_id); 4929 return; 4930 } 4931 4932 if (!strcmp(res->mode, "enable")) { 4933 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0) 4934 printf("Dedicate queues for LACP control packets" 4935 " enabled\n"); 4936 else 4937 printf("Enabling dedicate queues for LACP control " 4938 "packets on port %d failed\n", port_id); 4939 } else if (!strcmp(res->mode, "disable")) { 4940 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0) 4941 printf("Dedicated queues for LACP control packets " 4942 "disabled\n"); 4943 else 4944 printf("Disabling dedicated queues for LACP control " 4945 "traffic on port %d failed\n", port_id); 4946 } 4947 } 4948 4949 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set = 4950 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4951 set, "set"); 4952 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding = 4953 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4954 bonding, "bonding"); 4955 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp = 4956 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4957 lacp, "lacp"); 4958 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues = 4959 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4960 dedicated_queues, "dedicated_queues"); 4961 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = 4962 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4963 port_id, UINT16); 4964 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = 4965 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, 4966 mode, "enable#disable"); 4967 4968 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = { 4969 .f = cmd_set_bonding_lacp_dedicated_queues_parsed, 4970 .help_str = "set bonding lacp dedicated_queues <port_id> " 4971 "enable|disable: " 4972 "Enable/disable dedicated queues for LACP control traffic for port_id", 4973 .data = NULL, 4974 .tokens = { 4975 (void *)&cmd_setbonding_lacp_dedicated_queues_set, 4976 (void *)&cmd_setbonding_lacp_dedicated_queues_bonding, 4977 (void *)&cmd_setbonding_lacp_dedicated_queues_lacp, 4978 (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues, 4979 (void *)&cmd_setbonding_lacp_dedicated_queues_port_id, 4980 (void *)&cmd_setbonding_lacp_dedicated_queues_mode, 4981 NULL 4982 } 4983 }; 4984 4985 /* *** SET BALANCE XMIT POLICY *** */ 4986 struct cmd_set_bonding_balance_xmit_policy_result { 4987 cmdline_fixed_string_t set; 4988 cmdline_fixed_string_t bonding; 4989 cmdline_fixed_string_t balance_xmit_policy; 4990 portid_t port_id; 4991 cmdline_fixed_string_t policy; 4992 }; 4993 4994 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, 4995 __attribute__((unused)) struct cmdline *cl, 4996 __attribute__((unused)) void *data) 4997 { 4998 struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; 4999 portid_t port_id = res->port_id; 5000 uint8_t policy; 5001 5002 if (!strcmp(res->policy, "l2")) { 5003 policy = BALANCE_XMIT_POLICY_LAYER2; 5004 } else if (!strcmp(res->policy, "l23")) { 5005 policy = BALANCE_XMIT_POLICY_LAYER23; 5006 } else if (!strcmp(res->policy, "l34")) { 5007 policy = BALANCE_XMIT_POLICY_LAYER34; 5008 } else { 5009 printf("\t Invalid xmit policy selection"); 5010 return; 5011 } 5012 5013 /* Set the bonding mode for the relevant port. */ 5014 if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { 5015 printf("\t Failed to set bonding balance xmit policy for port = %d.\n", 5016 port_id); 5017 } 5018 } 5019 5020 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = 5021 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 5022 set, "set"); 5023 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = 5024 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 5025 bonding, "bonding"); 5026 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = 5027 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 5028 balance_xmit_policy, "balance_xmit_policy"); 5029 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = 5030 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 5031 port_id, UINT16); 5032 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = 5033 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, 5034 policy, "l2#l23#l34"); 5035 5036 cmdline_parse_inst_t cmd_set_balance_xmit_policy = { 5037 .f = cmd_set_bonding_balance_xmit_policy_parsed, 5038 .help_str = "set bonding balance_xmit_policy <port_id> " 5039 "l2|l23|l34: " 5040 "Set the bonding balance_xmit_policy for port_id", 5041 .data = NULL, 5042 .tokens = { 5043 (void *)&cmd_setbonding_balance_xmit_policy_set, 5044 (void *)&cmd_setbonding_balance_xmit_policy_bonding, 5045 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, 5046 (void *)&cmd_setbonding_balance_xmit_policy_port, 5047 (void *)&cmd_setbonding_balance_xmit_policy_policy, 5048 NULL 5049 } 5050 }; 5051 5052 /* *** SHOW NIC BONDING CONFIGURATION *** */ 5053 struct cmd_show_bonding_config_result { 5054 cmdline_fixed_string_t show; 5055 cmdline_fixed_string_t bonding; 5056 cmdline_fixed_string_t config; 5057 portid_t port_id; 5058 }; 5059 5060 static void cmd_show_bonding_config_parsed(void *parsed_result, 5061 __attribute__((unused)) struct cmdline *cl, 5062 __attribute__((unused)) void *data) 5063 { 5064 struct cmd_show_bonding_config_result *res = parsed_result; 5065 int bonding_mode, agg_mode; 5066 portid_t slaves[RTE_MAX_ETHPORTS]; 5067 int num_slaves, num_active_slaves; 5068 int primary_id; 5069 int i; 5070 portid_t port_id = res->port_id; 5071 5072 /* Display the bonding mode.*/ 5073 bonding_mode = rte_eth_bond_mode_get(port_id); 5074 if (bonding_mode < 0) { 5075 printf("\tFailed to get bonding mode for port = %d\n", port_id); 5076 return; 5077 } else 5078 printf("\tBonding mode: %d\n", bonding_mode); 5079 5080 if (bonding_mode == BONDING_MODE_BALANCE) { 5081 int balance_xmit_policy; 5082 5083 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); 5084 if (balance_xmit_policy < 0) { 5085 printf("\tFailed to get balance xmit policy for port = %d\n", 5086 port_id); 5087 return; 5088 } else { 5089 printf("\tBalance Xmit Policy: "); 5090 5091 switch (balance_xmit_policy) { 5092 case BALANCE_XMIT_POLICY_LAYER2: 5093 printf("BALANCE_XMIT_POLICY_LAYER2"); 5094 break; 5095 case BALANCE_XMIT_POLICY_LAYER23: 5096 printf("BALANCE_XMIT_POLICY_LAYER23"); 5097 break; 5098 case BALANCE_XMIT_POLICY_LAYER34: 5099 printf("BALANCE_XMIT_POLICY_LAYER34"); 5100 break; 5101 } 5102 printf("\n"); 5103 } 5104 } 5105 5106 if (bonding_mode == BONDING_MODE_8023AD) { 5107 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id); 5108 printf("\tIEEE802.3AD Aggregator Mode: "); 5109 switch (agg_mode) { 5110 case AGG_BANDWIDTH: 5111 printf("bandwidth"); 5112 break; 5113 case AGG_STABLE: 5114 printf("stable"); 5115 break; 5116 case AGG_COUNT: 5117 printf("count"); 5118 break; 5119 } 5120 printf("\n"); 5121 } 5122 5123 num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); 5124 5125 if (num_slaves < 0) { 5126 printf("\tFailed to get slave list for port = %d\n", port_id); 5127 return; 5128 } 5129 if (num_slaves > 0) { 5130 printf("\tSlaves (%d): [", num_slaves); 5131 for (i = 0; i < num_slaves - 1; i++) 5132 printf("%d ", slaves[i]); 5133 5134 printf("%d]\n", slaves[num_slaves - 1]); 5135 } else { 5136 printf("\tSlaves: []\n"); 5137 5138 } 5139 5140 num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, 5141 RTE_MAX_ETHPORTS); 5142 5143 if (num_active_slaves < 0) { 5144 printf("\tFailed to get active slave list for port = %d\n", port_id); 5145 return; 5146 } 5147 if (num_active_slaves > 0) { 5148 printf("\tActive Slaves (%d): [", num_active_slaves); 5149 for (i = 0; i < num_active_slaves - 1; i++) 5150 printf("%d ", slaves[i]); 5151 5152 printf("%d]\n", slaves[num_active_slaves - 1]); 5153 5154 } else { 5155 printf("\tActive Slaves: []\n"); 5156 5157 } 5158 5159 primary_id = rte_eth_bond_primary_get(port_id); 5160 if (primary_id < 0) { 5161 printf("\tFailed to get primary slave for port = %d\n", port_id); 5162 return; 5163 } else 5164 printf("\tPrimary: [%d]\n", primary_id); 5165 5166 } 5167 5168 cmdline_parse_token_string_t cmd_showbonding_config_show = 5169 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 5170 show, "show"); 5171 cmdline_parse_token_string_t cmd_showbonding_config_bonding = 5172 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 5173 bonding, "bonding"); 5174 cmdline_parse_token_string_t cmd_showbonding_config_config = 5175 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, 5176 config, "config"); 5177 cmdline_parse_token_num_t cmd_showbonding_config_port = 5178 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, 5179 port_id, UINT16); 5180 5181 cmdline_parse_inst_t cmd_show_bonding_config = { 5182 .f = cmd_show_bonding_config_parsed, 5183 .help_str = "show bonding config <port_id>: " 5184 "Show the bonding config for port_id", 5185 .data = NULL, 5186 .tokens = { 5187 (void *)&cmd_showbonding_config_show, 5188 (void *)&cmd_showbonding_config_bonding, 5189 (void *)&cmd_showbonding_config_config, 5190 (void *)&cmd_showbonding_config_port, 5191 NULL 5192 } 5193 }; 5194 5195 /* *** SET BONDING PRIMARY *** */ 5196 struct cmd_set_bonding_primary_result { 5197 cmdline_fixed_string_t set; 5198 cmdline_fixed_string_t bonding; 5199 cmdline_fixed_string_t primary; 5200 portid_t slave_id; 5201 portid_t port_id; 5202 }; 5203 5204 static void cmd_set_bonding_primary_parsed(void *parsed_result, 5205 __attribute__((unused)) struct cmdline *cl, 5206 __attribute__((unused)) void *data) 5207 { 5208 struct cmd_set_bonding_primary_result *res = parsed_result; 5209 portid_t master_port_id = res->port_id; 5210 portid_t slave_port_id = res->slave_id; 5211 5212 /* Set the primary slave for a bonded device. */ 5213 if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { 5214 printf("\t Failed to set primary slave for port = %d.\n", 5215 master_port_id); 5216 return; 5217 } 5218 init_port_config(); 5219 } 5220 5221 cmdline_parse_token_string_t cmd_setbonding_primary_set = 5222 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5223 set, "set"); 5224 cmdline_parse_token_string_t cmd_setbonding_primary_bonding = 5225 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5226 bonding, "bonding"); 5227 cmdline_parse_token_string_t cmd_setbonding_primary_primary = 5228 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, 5229 primary, "primary"); 5230 cmdline_parse_token_num_t cmd_setbonding_primary_slave = 5231 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 5232 slave_id, UINT16); 5233 cmdline_parse_token_num_t cmd_setbonding_primary_port = 5234 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, 5235 port_id, UINT16); 5236 5237 cmdline_parse_inst_t cmd_set_bonding_primary = { 5238 .f = cmd_set_bonding_primary_parsed, 5239 .help_str = "set bonding primary <slave_id> <port_id>: " 5240 "Set the primary slave for port_id", 5241 .data = NULL, 5242 .tokens = { 5243 (void *)&cmd_setbonding_primary_set, 5244 (void *)&cmd_setbonding_primary_bonding, 5245 (void *)&cmd_setbonding_primary_primary, 5246 (void *)&cmd_setbonding_primary_slave, 5247 (void *)&cmd_setbonding_primary_port, 5248 NULL 5249 } 5250 }; 5251 5252 /* *** ADD SLAVE *** */ 5253 struct cmd_add_bonding_slave_result { 5254 cmdline_fixed_string_t add; 5255 cmdline_fixed_string_t bonding; 5256 cmdline_fixed_string_t slave; 5257 portid_t slave_id; 5258 portid_t port_id; 5259 }; 5260 5261 static void cmd_add_bonding_slave_parsed(void *parsed_result, 5262 __attribute__((unused)) struct cmdline *cl, 5263 __attribute__((unused)) void *data) 5264 { 5265 struct cmd_add_bonding_slave_result *res = parsed_result; 5266 portid_t master_port_id = res->port_id; 5267 portid_t slave_port_id = res->slave_id; 5268 5269 /* add the slave for a bonded device. */ 5270 if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { 5271 printf("\t Failed to add slave %d to master port = %d.\n", 5272 slave_port_id, master_port_id); 5273 return; 5274 } 5275 init_port_config(); 5276 set_port_slave_flag(slave_port_id); 5277 } 5278 5279 cmdline_parse_token_string_t cmd_addbonding_slave_add = 5280 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5281 add, "add"); 5282 cmdline_parse_token_string_t cmd_addbonding_slave_bonding = 5283 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5284 bonding, "bonding"); 5285 cmdline_parse_token_string_t cmd_addbonding_slave_slave = 5286 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, 5287 slave, "slave"); 5288 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = 5289 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 5290 slave_id, UINT16); 5291 cmdline_parse_token_num_t cmd_addbonding_slave_port = 5292 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, 5293 port_id, UINT16); 5294 5295 cmdline_parse_inst_t cmd_add_bonding_slave = { 5296 .f = cmd_add_bonding_slave_parsed, 5297 .help_str = "add bonding slave <slave_id> <port_id>: " 5298 "Add a slave device to a bonded device", 5299 .data = NULL, 5300 .tokens = { 5301 (void *)&cmd_addbonding_slave_add, 5302 (void *)&cmd_addbonding_slave_bonding, 5303 (void *)&cmd_addbonding_slave_slave, 5304 (void *)&cmd_addbonding_slave_slaveid, 5305 (void *)&cmd_addbonding_slave_port, 5306 NULL 5307 } 5308 }; 5309 5310 /* *** REMOVE SLAVE *** */ 5311 struct cmd_remove_bonding_slave_result { 5312 cmdline_fixed_string_t remove; 5313 cmdline_fixed_string_t bonding; 5314 cmdline_fixed_string_t slave; 5315 portid_t slave_id; 5316 portid_t port_id; 5317 }; 5318 5319 static void cmd_remove_bonding_slave_parsed(void *parsed_result, 5320 __attribute__((unused)) struct cmdline *cl, 5321 __attribute__((unused)) void *data) 5322 { 5323 struct cmd_remove_bonding_slave_result *res = parsed_result; 5324 portid_t master_port_id = res->port_id; 5325 portid_t slave_port_id = res->slave_id; 5326 5327 /* remove the slave from a bonded device. */ 5328 if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { 5329 printf("\t Failed to remove slave %d from master port = %d.\n", 5330 slave_port_id, master_port_id); 5331 return; 5332 } 5333 init_port_config(); 5334 clear_port_slave_flag(slave_port_id); 5335 } 5336 5337 cmdline_parse_token_string_t cmd_removebonding_slave_remove = 5338 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5339 remove, "remove"); 5340 cmdline_parse_token_string_t cmd_removebonding_slave_bonding = 5341 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5342 bonding, "bonding"); 5343 cmdline_parse_token_string_t cmd_removebonding_slave_slave = 5344 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, 5345 slave, "slave"); 5346 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = 5347 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 5348 slave_id, UINT16); 5349 cmdline_parse_token_num_t cmd_removebonding_slave_port = 5350 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, 5351 port_id, UINT16); 5352 5353 cmdline_parse_inst_t cmd_remove_bonding_slave = { 5354 .f = cmd_remove_bonding_slave_parsed, 5355 .help_str = "remove bonding slave <slave_id> <port_id>: " 5356 "Remove a slave device from a bonded device", 5357 .data = NULL, 5358 .tokens = { 5359 (void *)&cmd_removebonding_slave_remove, 5360 (void *)&cmd_removebonding_slave_bonding, 5361 (void *)&cmd_removebonding_slave_slave, 5362 (void *)&cmd_removebonding_slave_slaveid, 5363 (void *)&cmd_removebonding_slave_port, 5364 NULL 5365 } 5366 }; 5367 5368 /* *** CREATE BONDED DEVICE *** */ 5369 struct cmd_create_bonded_device_result { 5370 cmdline_fixed_string_t create; 5371 cmdline_fixed_string_t bonded; 5372 cmdline_fixed_string_t device; 5373 uint8_t mode; 5374 uint8_t socket; 5375 }; 5376 5377 static int bond_dev_num = 0; 5378 5379 static void cmd_create_bonded_device_parsed(void *parsed_result, 5380 __attribute__((unused)) struct cmdline *cl, 5381 __attribute__((unused)) void *data) 5382 { 5383 struct cmd_create_bonded_device_result *res = parsed_result; 5384 char ethdev_name[RTE_ETH_NAME_MAX_LEN]; 5385 int port_id; 5386 5387 if (test_done == 0) { 5388 printf("Please stop forwarding first\n"); 5389 return; 5390 } 5391 5392 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d", 5393 bond_dev_num++); 5394 5395 /* Create a new bonded device. */ 5396 port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); 5397 if (port_id < 0) { 5398 printf("\t Failed to create bonded device.\n"); 5399 return; 5400 } else { 5401 printf("Created new bonded device %s on (port %d).\n", ethdev_name, 5402 port_id); 5403 5404 /* Update number of ports */ 5405 nb_ports = rte_eth_dev_count(); 5406 reconfig(port_id, res->socket); 5407 rte_eth_promiscuous_enable(port_id); 5408 } 5409 5410 } 5411 5412 cmdline_parse_token_string_t cmd_createbonded_device_create = 5413 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5414 create, "create"); 5415 cmdline_parse_token_string_t cmd_createbonded_device_bonded = 5416 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5417 bonded, "bonded"); 5418 cmdline_parse_token_string_t cmd_createbonded_device_device = 5419 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, 5420 device, "device"); 5421 cmdline_parse_token_num_t cmd_createbonded_device_mode = 5422 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 5423 mode, UINT8); 5424 cmdline_parse_token_num_t cmd_createbonded_device_socket = 5425 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, 5426 socket, UINT8); 5427 5428 cmdline_parse_inst_t cmd_create_bonded_device = { 5429 .f = cmd_create_bonded_device_parsed, 5430 .help_str = "create bonded device <mode> <socket>: " 5431 "Create a new bonded device with specific bonding mode and socket", 5432 .data = NULL, 5433 .tokens = { 5434 (void *)&cmd_createbonded_device_create, 5435 (void *)&cmd_createbonded_device_bonded, 5436 (void *)&cmd_createbonded_device_device, 5437 (void *)&cmd_createbonded_device_mode, 5438 (void *)&cmd_createbonded_device_socket, 5439 NULL 5440 } 5441 }; 5442 5443 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */ 5444 struct cmd_set_bond_mac_addr_result { 5445 cmdline_fixed_string_t set; 5446 cmdline_fixed_string_t bonding; 5447 cmdline_fixed_string_t mac_addr; 5448 uint16_t port_num; 5449 struct ether_addr address; 5450 }; 5451 5452 static void cmd_set_bond_mac_addr_parsed(void *parsed_result, 5453 __attribute__((unused)) struct cmdline *cl, 5454 __attribute__((unused)) void *data) 5455 { 5456 struct cmd_set_bond_mac_addr_result *res = parsed_result; 5457 int ret; 5458 5459 if (port_id_is_invalid(res->port_num, ENABLED_WARN)) 5460 return; 5461 5462 ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); 5463 5464 /* check the return value and print it if is < 0 */ 5465 if (ret < 0) 5466 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 5467 } 5468 5469 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = 5470 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); 5471 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = 5472 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, 5473 "bonding"); 5474 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = 5475 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, 5476 "mac_addr"); 5477 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = 5478 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, 5479 port_num, UINT16); 5480 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = 5481 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); 5482 5483 cmdline_parse_inst_t cmd_set_bond_mac_addr = { 5484 .f = cmd_set_bond_mac_addr_parsed, 5485 .data = (void *) 0, 5486 .help_str = "set bonding mac_addr <port_id> <mac_addr>", 5487 .tokens = { 5488 (void *)&cmd_set_bond_mac_addr_set, 5489 (void *)&cmd_set_bond_mac_addr_bonding, 5490 (void *)&cmd_set_bond_mac_addr_mac, 5491 (void *)&cmd_set_bond_mac_addr_portnum, 5492 (void *)&cmd_set_bond_mac_addr_addr, 5493 NULL 5494 } 5495 }; 5496 5497 5498 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ 5499 struct cmd_set_bond_mon_period_result { 5500 cmdline_fixed_string_t set; 5501 cmdline_fixed_string_t bonding; 5502 cmdline_fixed_string_t mon_period; 5503 uint16_t port_num; 5504 uint32_t period_ms; 5505 }; 5506 5507 static void cmd_set_bond_mon_period_parsed(void *parsed_result, 5508 __attribute__((unused)) struct cmdline *cl, 5509 __attribute__((unused)) void *data) 5510 { 5511 struct cmd_set_bond_mon_period_result *res = parsed_result; 5512 int ret; 5513 5514 if (res->port_num >= nb_ports) { 5515 printf("Port id %d must be less than %d\n", res->port_num, nb_ports); 5516 return; 5517 } 5518 5519 ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); 5520 5521 /* check the return value and print it if is < 0 */ 5522 if (ret < 0) 5523 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret)); 5524 } 5525 5526 cmdline_parse_token_string_t cmd_set_bond_mon_period_set = 5527 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5528 set, "set"); 5529 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = 5530 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5531 bonding, "bonding"); 5532 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = 5533 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, 5534 mon_period, "mon_period"); 5535 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = 5536 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5537 port_num, UINT16); 5538 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = 5539 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, 5540 period_ms, UINT32); 5541 5542 cmdline_parse_inst_t cmd_set_bond_mon_period = { 5543 .f = cmd_set_bond_mon_period_parsed, 5544 .data = (void *) 0, 5545 .help_str = "set bonding mon_period <port_id> <period_ms>", 5546 .tokens = { 5547 (void *)&cmd_set_bond_mon_period_set, 5548 (void *)&cmd_set_bond_mon_period_bonding, 5549 (void *)&cmd_set_bond_mon_period_mon_period, 5550 (void *)&cmd_set_bond_mon_period_portnum, 5551 (void *)&cmd_set_bond_mon_period_period_ms, 5552 NULL 5553 } 5554 }; 5555 5556 5557 5558 struct cmd_set_bonding_agg_mode_policy_result { 5559 cmdline_fixed_string_t set; 5560 cmdline_fixed_string_t bonding; 5561 cmdline_fixed_string_t agg_mode; 5562 uint16_t port_num; 5563 cmdline_fixed_string_t policy; 5564 }; 5565 5566 5567 static void 5568 cmd_set_bonding_agg_mode(void *parsed_result, 5569 __attribute__((unused)) struct cmdline *cl, 5570 __attribute__((unused)) void *data) 5571 { 5572 struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result; 5573 uint8_t policy = AGG_BANDWIDTH; 5574 5575 if (res->port_num >= nb_ports) { 5576 printf("Port id %d must be less than %d\n", 5577 res->port_num, nb_ports); 5578 return; 5579 } 5580 5581 if (!strcmp(res->policy, "bandwidth")) 5582 policy = AGG_BANDWIDTH; 5583 else if (!strcmp(res->policy, "stable")) 5584 policy = AGG_STABLE; 5585 else if (!strcmp(res->policy, "count")) 5586 policy = AGG_COUNT; 5587 5588 rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy); 5589 } 5590 5591 5592 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set = 5593 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5594 set, "set"); 5595 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding = 5596 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5597 bonding, "bonding"); 5598 5599 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = 5600 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5601 agg_mode, "agg_mode"); 5602 5603 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = 5604 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, 5605 port_num, UINT16); 5606 5607 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = 5608 TOKEN_STRING_INITIALIZER( 5609 struct cmd_set_bonding_balance_xmit_policy_result, 5610 policy, "stable#bandwidth#count"); 5611 5612 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = { 5613 .f = cmd_set_bonding_agg_mode, 5614 .data = (void *) 0, 5615 .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>", 5616 .tokens = { 5617 (void *)&cmd_set_bonding_agg_mode_set, 5618 (void *)&cmd_set_bonding_agg_mode_bonding, 5619 (void *)&cmd_set_bonding_agg_mode_agg_mode, 5620 (void *)&cmd_set_bonding_agg_mode_portnum, 5621 (void *)&cmd_set_bonding_agg_mode_policy_string, 5622 NULL 5623 } 5624 }; 5625 5626 5627 #endif /* RTE_LIBRTE_PMD_BOND */ 5628 5629 /* *** SET FORWARDING MODE *** */ 5630 struct cmd_set_fwd_mode_result { 5631 cmdline_fixed_string_t set; 5632 cmdline_fixed_string_t fwd; 5633 cmdline_fixed_string_t mode; 5634 }; 5635 5636 static void cmd_set_fwd_mode_parsed(void *parsed_result, 5637 __attribute__((unused)) struct cmdline *cl, 5638 __attribute__((unused)) void *data) 5639 { 5640 struct cmd_set_fwd_mode_result *res = parsed_result; 5641 5642 retry_enabled = 0; 5643 set_pkt_forwarding_mode(res->mode); 5644 } 5645 5646 cmdline_parse_token_string_t cmd_setfwd_set = 5647 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); 5648 cmdline_parse_token_string_t cmd_setfwd_fwd = 5649 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); 5650 cmdline_parse_token_string_t cmd_setfwd_mode = 5651 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, 5652 "" /* defined at init */); 5653 5654 cmdline_parse_inst_t cmd_set_fwd_mode = { 5655 .f = cmd_set_fwd_mode_parsed, 5656 .data = NULL, 5657 .help_str = NULL, /* defined at init */ 5658 .tokens = { 5659 (void *)&cmd_setfwd_set, 5660 (void *)&cmd_setfwd_fwd, 5661 (void *)&cmd_setfwd_mode, 5662 NULL, 5663 }, 5664 }; 5665 5666 static void cmd_set_fwd_mode_init(void) 5667 { 5668 char *modes, *c; 5669 static char token[128]; 5670 static char help[256]; 5671 cmdline_parse_token_string_t *token_struct; 5672 5673 modes = list_pkt_forwarding_modes(); 5674 snprintf(help, sizeof(help), "set fwd %s: " 5675 "Set packet forwarding mode", modes); 5676 cmd_set_fwd_mode.help_str = help; 5677 5678 /* string token separator is # */ 5679 for (c = token; *modes != '\0'; modes++) 5680 if (*modes == '|') 5681 *c++ = '#'; 5682 else 5683 *c++ = *modes; 5684 token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2]; 5685 token_struct->string_data.str = token; 5686 } 5687 5688 /* *** SET RETRY FORWARDING MODE *** */ 5689 struct cmd_set_fwd_retry_mode_result { 5690 cmdline_fixed_string_t set; 5691 cmdline_fixed_string_t fwd; 5692 cmdline_fixed_string_t mode; 5693 cmdline_fixed_string_t retry; 5694 }; 5695 5696 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result, 5697 __attribute__((unused)) struct cmdline *cl, 5698 __attribute__((unused)) void *data) 5699 { 5700 struct cmd_set_fwd_retry_mode_result *res = parsed_result; 5701 5702 retry_enabled = 1; 5703 set_pkt_forwarding_mode(res->mode); 5704 } 5705 5706 cmdline_parse_token_string_t cmd_setfwd_retry_set = 5707 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5708 set, "set"); 5709 cmdline_parse_token_string_t cmd_setfwd_retry_fwd = 5710 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5711 fwd, "fwd"); 5712 cmdline_parse_token_string_t cmd_setfwd_retry_mode = 5713 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5714 mode, 5715 "" /* defined at init */); 5716 cmdline_parse_token_string_t cmd_setfwd_retry_retry = 5717 TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result, 5718 retry, "retry"); 5719 5720 cmdline_parse_inst_t cmd_set_fwd_retry_mode = { 5721 .f = cmd_set_fwd_retry_mode_parsed, 5722 .data = NULL, 5723 .help_str = NULL, /* defined at init */ 5724 .tokens = { 5725 (void *)&cmd_setfwd_retry_set, 5726 (void *)&cmd_setfwd_retry_fwd, 5727 (void *)&cmd_setfwd_retry_mode, 5728 (void *)&cmd_setfwd_retry_retry, 5729 NULL, 5730 }, 5731 }; 5732 5733 static void cmd_set_fwd_retry_mode_init(void) 5734 { 5735 char *modes, *c; 5736 static char token[128]; 5737 static char help[256]; 5738 cmdline_parse_token_string_t *token_struct; 5739 5740 modes = list_pkt_forwarding_retry_modes(); 5741 snprintf(help, sizeof(help), "set fwd %s retry: " 5742 "Set packet forwarding mode with retry", modes); 5743 cmd_set_fwd_retry_mode.help_str = help; 5744 5745 /* string token separator is # */ 5746 for (c = token; *modes != '\0'; modes++) 5747 if (*modes == '|') 5748 *c++ = '#'; 5749 else 5750 *c++ = *modes; 5751 token_struct = (cmdline_parse_token_string_t *) 5752 cmd_set_fwd_retry_mode.tokens[2]; 5753 token_struct->string_data.str = token; 5754 } 5755 5756 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */ 5757 struct cmd_set_burst_tx_retry_result { 5758 cmdline_fixed_string_t set; 5759 cmdline_fixed_string_t burst; 5760 cmdline_fixed_string_t tx; 5761 cmdline_fixed_string_t delay; 5762 uint32_t time; 5763 cmdline_fixed_string_t retry; 5764 uint32_t retry_num; 5765 }; 5766 5767 static void cmd_set_burst_tx_retry_parsed(void *parsed_result, 5768 __attribute__((unused)) struct cmdline *cl, 5769 __attribute__((unused)) void *data) 5770 { 5771 struct cmd_set_burst_tx_retry_result *res = parsed_result; 5772 5773 if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst") 5774 && !strcmp(res->tx, "tx")) { 5775 if (!strcmp(res->delay, "delay")) 5776 burst_tx_delay_time = res->time; 5777 if (!strcmp(res->retry, "retry")) 5778 burst_tx_retry_num = res->retry_num; 5779 } 5780 5781 } 5782 5783 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set = 5784 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set"); 5785 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst = 5786 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst, 5787 "burst"); 5788 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx = 5789 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx"); 5790 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay = 5791 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay"); 5792 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time = 5793 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32); 5794 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry = 5795 TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry"); 5796 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num = 5797 TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32); 5798 5799 cmdline_parse_inst_t cmd_set_burst_tx_retry = { 5800 .f = cmd_set_burst_tx_retry_parsed, 5801 .help_str = "set burst tx delay <delay_usec> retry <num_retry>", 5802 .tokens = { 5803 (void *)&cmd_set_burst_tx_retry_set, 5804 (void *)&cmd_set_burst_tx_retry_burst, 5805 (void *)&cmd_set_burst_tx_retry_tx, 5806 (void *)&cmd_set_burst_tx_retry_delay, 5807 (void *)&cmd_set_burst_tx_retry_time, 5808 (void *)&cmd_set_burst_tx_retry_retry, 5809 (void *)&cmd_set_burst_tx_retry_retry_num, 5810 NULL, 5811 }, 5812 }; 5813 5814 /* *** SET PROMISC MODE *** */ 5815 struct cmd_set_promisc_mode_result { 5816 cmdline_fixed_string_t set; 5817 cmdline_fixed_string_t promisc; 5818 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5819 uint16_t port_num; /* valid if "allports" argument == 0 */ 5820 cmdline_fixed_string_t mode; 5821 }; 5822 5823 static void cmd_set_promisc_mode_parsed(void *parsed_result, 5824 __attribute__((unused)) struct cmdline *cl, 5825 void *allports) 5826 { 5827 struct cmd_set_promisc_mode_result *res = parsed_result; 5828 int enable; 5829 portid_t i; 5830 5831 if (!strcmp(res->mode, "on")) 5832 enable = 1; 5833 else 5834 enable = 0; 5835 5836 /* all ports */ 5837 if (allports) { 5838 RTE_ETH_FOREACH_DEV(i) { 5839 if (enable) 5840 rte_eth_promiscuous_enable(i); 5841 else 5842 rte_eth_promiscuous_disable(i); 5843 } 5844 } 5845 else { 5846 if (enable) 5847 rte_eth_promiscuous_enable(res->port_num); 5848 else 5849 rte_eth_promiscuous_disable(res->port_num); 5850 } 5851 } 5852 5853 cmdline_parse_token_string_t cmd_setpromisc_set = 5854 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); 5855 cmdline_parse_token_string_t cmd_setpromisc_promisc = 5856 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, 5857 "promisc"); 5858 cmdline_parse_token_string_t cmd_setpromisc_portall = 5859 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, 5860 "all"); 5861 cmdline_parse_token_num_t cmd_setpromisc_portnum = 5862 TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, 5863 UINT16); 5864 cmdline_parse_token_string_t cmd_setpromisc_mode = 5865 TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, 5866 "on#off"); 5867 5868 cmdline_parse_inst_t cmd_set_promisc_mode_all = { 5869 .f = cmd_set_promisc_mode_parsed, 5870 .data = (void *)1, 5871 .help_str = "set promisc all on|off: Set promisc mode for all ports", 5872 .tokens = { 5873 (void *)&cmd_setpromisc_set, 5874 (void *)&cmd_setpromisc_promisc, 5875 (void *)&cmd_setpromisc_portall, 5876 (void *)&cmd_setpromisc_mode, 5877 NULL, 5878 }, 5879 }; 5880 5881 cmdline_parse_inst_t cmd_set_promisc_mode_one = { 5882 .f = cmd_set_promisc_mode_parsed, 5883 .data = (void *)0, 5884 .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id", 5885 .tokens = { 5886 (void *)&cmd_setpromisc_set, 5887 (void *)&cmd_setpromisc_promisc, 5888 (void *)&cmd_setpromisc_portnum, 5889 (void *)&cmd_setpromisc_mode, 5890 NULL, 5891 }, 5892 }; 5893 5894 /* *** SET ALLMULTI MODE *** */ 5895 struct cmd_set_allmulti_mode_result { 5896 cmdline_fixed_string_t set; 5897 cmdline_fixed_string_t allmulti; 5898 cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ 5899 uint16_t port_num; /* valid if "allports" argument == 0 */ 5900 cmdline_fixed_string_t mode; 5901 }; 5902 5903 static void cmd_set_allmulti_mode_parsed(void *parsed_result, 5904 __attribute__((unused)) struct cmdline *cl, 5905 void *allports) 5906 { 5907 struct cmd_set_allmulti_mode_result *res = parsed_result; 5908 int enable; 5909 portid_t i; 5910 5911 if (!strcmp(res->mode, "on")) 5912 enable = 1; 5913 else 5914 enable = 0; 5915 5916 /* all ports */ 5917 if (allports) { 5918 RTE_ETH_FOREACH_DEV(i) { 5919 if (enable) 5920 rte_eth_allmulticast_enable(i); 5921 else 5922 rte_eth_allmulticast_disable(i); 5923 } 5924 } 5925 else { 5926 if (enable) 5927 rte_eth_allmulticast_enable(res->port_num); 5928 else 5929 rte_eth_allmulticast_disable(res->port_num); 5930 } 5931 } 5932 5933 cmdline_parse_token_string_t cmd_setallmulti_set = 5934 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set"); 5935 cmdline_parse_token_string_t cmd_setallmulti_allmulti = 5936 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti, 5937 "allmulti"); 5938 cmdline_parse_token_string_t cmd_setallmulti_portall = 5939 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all, 5940 "all"); 5941 cmdline_parse_token_num_t cmd_setallmulti_portnum = 5942 TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, 5943 UINT16); 5944 cmdline_parse_token_string_t cmd_setallmulti_mode = 5945 TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, 5946 "on#off"); 5947 5948 cmdline_parse_inst_t cmd_set_allmulti_mode_all = { 5949 .f = cmd_set_allmulti_mode_parsed, 5950 .data = (void *)1, 5951 .help_str = "set allmulti all on|off: Set allmulti mode for all ports", 5952 .tokens = { 5953 (void *)&cmd_setallmulti_set, 5954 (void *)&cmd_setallmulti_allmulti, 5955 (void *)&cmd_setallmulti_portall, 5956 (void *)&cmd_setallmulti_mode, 5957 NULL, 5958 }, 5959 }; 5960 5961 cmdline_parse_inst_t cmd_set_allmulti_mode_one = { 5962 .f = cmd_set_allmulti_mode_parsed, 5963 .data = (void *)0, 5964 .help_str = "set allmulti <port_id> on|off: " 5965 "Set allmulti mode on port_id", 5966 .tokens = { 5967 (void *)&cmd_setallmulti_set, 5968 (void *)&cmd_setallmulti_allmulti, 5969 (void *)&cmd_setallmulti_portnum, 5970 (void *)&cmd_setallmulti_mode, 5971 NULL, 5972 }, 5973 }; 5974 5975 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */ 5976 struct cmd_link_flow_ctrl_set_result { 5977 cmdline_fixed_string_t set; 5978 cmdline_fixed_string_t flow_ctrl; 5979 cmdline_fixed_string_t rx; 5980 cmdline_fixed_string_t rx_lfc_mode; 5981 cmdline_fixed_string_t tx; 5982 cmdline_fixed_string_t tx_lfc_mode; 5983 cmdline_fixed_string_t mac_ctrl_frame_fwd; 5984 cmdline_fixed_string_t mac_ctrl_frame_fwd_mode; 5985 cmdline_fixed_string_t autoneg_str; 5986 cmdline_fixed_string_t autoneg; 5987 cmdline_fixed_string_t hw_str; 5988 uint32_t high_water; 5989 cmdline_fixed_string_t lw_str; 5990 uint32_t low_water; 5991 cmdline_fixed_string_t pt_str; 5992 uint16_t pause_time; 5993 cmdline_fixed_string_t xon_str; 5994 uint16_t send_xon; 5995 portid_t port_id; 5996 }; 5997 5998 cmdline_parse_token_string_t cmd_lfc_set_set = 5999 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6000 set, "set"); 6001 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl = 6002 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6003 flow_ctrl, "flow_ctrl"); 6004 cmdline_parse_token_string_t cmd_lfc_set_rx = 6005 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6006 rx, "rx"); 6007 cmdline_parse_token_string_t cmd_lfc_set_rx_mode = 6008 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6009 rx_lfc_mode, "on#off"); 6010 cmdline_parse_token_string_t cmd_lfc_set_tx = 6011 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6012 tx, "tx"); 6013 cmdline_parse_token_string_t cmd_lfc_set_tx_mode = 6014 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6015 tx_lfc_mode, "on#off"); 6016 cmdline_parse_token_string_t cmd_lfc_set_high_water_str = 6017 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6018 hw_str, "high_water"); 6019 cmdline_parse_token_num_t cmd_lfc_set_high_water = 6020 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6021 high_water, UINT32); 6022 cmdline_parse_token_string_t cmd_lfc_set_low_water_str = 6023 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6024 lw_str, "low_water"); 6025 cmdline_parse_token_num_t cmd_lfc_set_low_water = 6026 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6027 low_water, UINT32); 6028 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str = 6029 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6030 pt_str, "pause_time"); 6031 cmdline_parse_token_num_t cmd_lfc_set_pause_time = 6032 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6033 pause_time, UINT16); 6034 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str = 6035 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6036 xon_str, "send_xon"); 6037 cmdline_parse_token_num_t cmd_lfc_set_send_xon = 6038 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6039 send_xon, UINT16); 6040 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode = 6041 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6042 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd"); 6043 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd = 6044 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6045 mac_ctrl_frame_fwd_mode, "on#off"); 6046 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str = 6047 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6048 autoneg_str, "autoneg"); 6049 cmdline_parse_token_string_t cmd_lfc_set_autoneg = 6050 TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6051 autoneg, "on#off"); 6052 cmdline_parse_token_num_t cmd_lfc_set_portid = 6053 TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, 6054 port_id, UINT16); 6055 6056 /* forward declaration */ 6057 static void 6058 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl, 6059 void *data); 6060 6061 cmdline_parse_inst_t cmd_link_flow_control_set = { 6062 .f = cmd_link_flow_ctrl_set_parsed, 6063 .data = NULL, 6064 .help_str = "set flow_ctrl rx on|off tx on|off <high_water> " 6065 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off " 6066 "autoneg on|off <port_id>: Configure the Ethernet flow control", 6067 .tokens = { 6068 (void *)&cmd_lfc_set_set, 6069 (void *)&cmd_lfc_set_flow_ctrl, 6070 (void *)&cmd_lfc_set_rx, 6071 (void *)&cmd_lfc_set_rx_mode, 6072 (void *)&cmd_lfc_set_tx, 6073 (void *)&cmd_lfc_set_tx_mode, 6074 (void *)&cmd_lfc_set_high_water, 6075 (void *)&cmd_lfc_set_low_water, 6076 (void *)&cmd_lfc_set_pause_time, 6077 (void *)&cmd_lfc_set_send_xon, 6078 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 6079 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 6080 (void *)&cmd_lfc_set_autoneg_str, 6081 (void *)&cmd_lfc_set_autoneg, 6082 (void *)&cmd_lfc_set_portid, 6083 NULL, 6084 }, 6085 }; 6086 6087 cmdline_parse_inst_t cmd_link_flow_control_set_rx = { 6088 .f = cmd_link_flow_ctrl_set_parsed, 6089 .data = (void *)&cmd_link_flow_control_set_rx, 6090 .help_str = "set flow_ctrl rx on|off <port_id>: " 6091 "Change rx flow control parameter", 6092 .tokens = { 6093 (void *)&cmd_lfc_set_set, 6094 (void *)&cmd_lfc_set_flow_ctrl, 6095 (void *)&cmd_lfc_set_rx, 6096 (void *)&cmd_lfc_set_rx_mode, 6097 (void *)&cmd_lfc_set_portid, 6098 NULL, 6099 }, 6100 }; 6101 6102 cmdline_parse_inst_t cmd_link_flow_control_set_tx = { 6103 .f = cmd_link_flow_ctrl_set_parsed, 6104 .data = (void *)&cmd_link_flow_control_set_tx, 6105 .help_str = "set flow_ctrl tx on|off <port_id>: " 6106 "Change tx flow control parameter", 6107 .tokens = { 6108 (void *)&cmd_lfc_set_set, 6109 (void *)&cmd_lfc_set_flow_ctrl, 6110 (void *)&cmd_lfc_set_tx, 6111 (void *)&cmd_lfc_set_tx_mode, 6112 (void *)&cmd_lfc_set_portid, 6113 NULL, 6114 }, 6115 }; 6116 6117 cmdline_parse_inst_t cmd_link_flow_control_set_hw = { 6118 .f = cmd_link_flow_ctrl_set_parsed, 6119 .data = (void *)&cmd_link_flow_control_set_hw, 6120 .help_str = "set flow_ctrl high_water <value> <port_id>: " 6121 "Change high water flow control parameter", 6122 .tokens = { 6123 (void *)&cmd_lfc_set_set, 6124 (void *)&cmd_lfc_set_flow_ctrl, 6125 (void *)&cmd_lfc_set_high_water_str, 6126 (void *)&cmd_lfc_set_high_water, 6127 (void *)&cmd_lfc_set_portid, 6128 NULL, 6129 }, 6130 }; 6131 6132 cmdline_parse_inst_t cmd_link_flow_control_set_lw = { 6133 .f = cmd_link_flow_ctrl_set_parsed, 6134 .data = (void *)&cmd_link_flow_control_set_lw, 6135 .help_str = "set flow_ctrl low_water <value> <port_id>: " 6136 "Change low water flow control parameter", 6137 .tokens = { 6138 (void *)&cmd_lfc_set_set, 6139 (void *)&cmd_lfc_set_flow_ctrl, 6140 (void *)&cmd_lfc_set_low_water_str, 6141 (void *)&cmd_lfc_set_low_water, 6142 (void *)&cmd_lfc_set_portid, 6143 NULL, 6144 }, 6145 }; 6146 6147 cmdline_parse_inst_t cmd_link_flow_control_set_pt = { 6148 .f = cmd_link_flow_ctrl_set_parsed, 6149 .data = (void *)&cmd_link_flow_control_set_pt, 6150 .help_str = "set flow_ctrl pause_time <value> <port_id>: " 6151 "Change pause time flow control parameter", 6152 .tokens = { 6153 (void *)&cmd_lfc_set_set, 6154 (void *)&cmd_lfc_set_flow_ctrl, 6155 (void *)&cmd_lfc_set_pause_time_str, 6156 (void *)&cmd_lfc_set_pause_time, 6157 (void *)&cmd_lfc_set_portid, 6158 NULL, 6159 }, 6160 }; 6161 6162 cmdline_parse_inst_t cmd_link_flow_control_set_xon = { 6163 .f = cmd_link_flow_ctrl_set_parsed, 6164 .data = (void *)&cmd_link_flow_control_set_xon, 6165 .help_str = "set flow_ctrl send_xon <value> <port_id>: " 6166 "Change send_xon flow control parameter", 6167 .tokens = { 6168 (void *)&cmd_lfc_set_set, 6169 (void *)&cmd_lfc_set_flow_ctrl, 6170 (void *)&cmd_lfc_set_send_xon_str, 6171 (void *)&cmd_lfc_set_send_xon, 6172 (void *)&cmd_lfc_set_portid, 6173 NULL, 6174 }, 6175 }; 6176 6177 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = { 6178 .f = cmd_link_flow_ctrl_set_parsed, 6179 .data = (void *)&cmd_link_flow_control_set_macfwd, 6180 .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: " 6181 "Change mac ctrl fwd flow control parameter", 6182 .tokens = { 6183 (void *)&cmd_lfc_set_set, 6184 (void *)&cmd_lfc_set_flow_ctrl, 6185 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode, 6186 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd, 6187 (void *)&cmd_lfc_set_portid, 6188 NULL, 6189 }, 6190 }; 6191 6192 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = { 6193 .f = cmd_link_flow_ctrl_set_parsed, 6194 .data = (void *)&cmd_link_flow_control_set_autoneg, 6195 .help_str = "set flow_ctrl autoneg on|off <port_id>: " 6196 "Change autoneg flow control parameter", 6197 .tokens = { 6198 (void *)&cmd_lfc_set_set, 6199 (void *)&cmd_lfc_set_flow_ctrl, 6200 (void *)&cmd_lfc_set_autoneg_str, 6201 (void *)&cmd_lfc_set_autoneg, 6202 (void *)&cmd_lfc_set_portid, 6203 NULL, 6204 }, 6205 }; 6206 6207 static void 6208 cmd_link_flow_ctrl_set_parsed(void *parsed_result, 6209 __attribute__((unused)) struct cmdline *cl, 6210 void *data) 6211 { 6212 struct cmd_link_flow_ctrl_set_result *res = parsed_result; 6213 cmdline_parse_inst_t *cmd = data; 6214 struct rte_eth_fc_conf fc_conf; 6215 int rx_fc_en = 0; 6216 int tx_fc_en = 0; 6217 int ret; 6218 6219 /* 6220 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6221 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6222 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6223 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6224 */ 6225 static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = { 6226 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL} 6227 }; 6228 6229 /* Partial command line, retrieve current configuration */ 6230 if (cmd) { 6231 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf); 6232 if (ret != 0) { 6233 printf("cannot get current flow ctrl parameters, return" 6234 "code = %d\n", ret); 6235 return; 6236 } 6237 6238 if ((fc_conf.mode == RTE_FC_RX_PAUSE) || 6239 (fc_conf.mode == RTE_FC_FULL)) 6240 rx_fc_en = 1; 6241 if ((fc_conf.mode == RTE_FC_TX_PAUSE) || 6242 (fc_conf.mode == RTE_FC_FULL)) 6243 tx_fc_en = 1; 6244 } 6245 6246 if (!cmd || cmd == &cmd_link_flow_control_set_rx) 6247 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0; 6248 6249 if (!cmd || cmd == &cmd_link_flow_control_set_tx) 6250 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0; 6251 6252 fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en]; 6253 6254 if (!cmd || cmd == &cmd_link_flow_control_set_hw) 6255 fc_conf.high_water = res->high_water; 6256 6257 if (!cmd || cmd == &cmd_link_flow_control_set_lw) 6258 fc_conf.low_water = res->low_water; 6259 6260 if (!cmd || cmd == &cmd_link_flow_control_set_pt) 6261 fc_conf.pause_time = res->pause_time; 6262 6263 if (!cmd || cmd == &cmd_link_flow_control_set_xon) 6264 fc_conf.send_xon = res->send_xon; 6265 6266 if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) { 6267 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on")) 6268 fc_conf.mac_ctrl_frame_fwd = 1; 6269 else 6270 fc_conf.mac_ctrl_frame_fwd = 0; 6271 } 6272 6273 if (!cmd || cmd == &cmd_link_flow_control_set_autoneg) 6274 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0; 6275 6276 ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf); 6277 if (ret != 0) 6278 printf("bad flow contrl parameter, return code = %d \n", ret); 6279 } 6280 6281 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */ 6282 struct cmd_priority_flow_ctrl_set_result { 6283 cmdline_fixed_string_t set; 6284 cmdline_fixed_string_t pfc_ctrl; 6285 cmdline_fixed_string_t rx; 6286 cmdline_fixed_string_t rx_pfc_mode; 6287 cmdline_fixed_string_t tx; 6288 cmdline_fixed_string_t tx_pfc_mode; 6289 uint32_t high_water; 6290 uint32_t low_water; 6291 uint16_t pause_time; 6292 uint8_t priority; 6293 portid_t port_id; 6294 }; 6295 6296 static void 6297 cmd_priority_flow_ctrl_set_parsed(void *parsed_result, 6298 __attribute__((unused)) struct cmdline *cl, 6299 __attribute__((unused)) void *data) 6300 { 6301 struct cmd_priority_flow_ctrl_set_result *res = parsed_result; 6302 struct rte_eth_pfc_conf pfc_conf; 6303 int rx_fc_enable, tx_fc_enable; 6304 int ret; 6305 6306 /* 6307 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate 6308 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side. 6309 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate 6310 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side. 6311 */ 6312 static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = { 6313 {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL} 6314 }; 6315 6316 rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0; 6317 tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0; 6318 pfc_conf.fc.mode = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable]; 6319 pfc_conf.fc.high_water = res->high_water; 6320 pfc_conf.fc.low_water = res->low_water; 6321 pfc_conf.fc.pause_time = res->pause_time; 6322 pfc_conf.priority = res->priority; 6323 6324 ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf); 6325 if (ret != 0) 6326 printf("bad priority flow contrl parameter, return code = %d \n", ret); 6327 } 6328 6329 cmdline_parse_token_string_t cmd_pfc_set_set = 6330 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6331 set, "set"); 6332 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl = 6333 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6334 pfc_ctrl, "pfc_ctrl"); 6335 cmdline_parse_token_string_t cmd_pfc_set_rx = 6336 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6337 rx, "rx"); 6338 cmdline_parse_token_string_t cmd_pfc_set_rx_mode = 6339 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6340 rx_pfc_mode, "on#off"); 6341 cmdline_parse_token_string_t cmd_pfc_set_tx = 6342 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6343 tx, "tx"); 6344 cmdline_parse_token_string_t cmd_pfc_set_tx_mode = 6345 TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6346 tx_pfc_mode, "on#off"); 6347 cmdline_parse_token_num_t cmd_pfc_set_high_water = 6348 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6349 high_water, UINT32); 6350 cmdline_parse_token_num_t cmd_pfc_set_low_water = 6351 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6352 low_water, UINT32); 6353 cmdline_parse_token_num_t cmd_pfc_set_pause_time = 6354 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6355 pause_time, UINT16); 6356 cmdline_parse_token_num_t cmd_pfc_set_priority = 6357 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6358 priority, UINT8); 6359 cmdline_parse_token_num_t cmd_pfc_set_portid = 6360 TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, 6361 port_id, UINT16); 6362 6363 cmdline_parse_inst_t cmd_priority_flow_control_set = { 6364 .f = cmd_priority_flow_ctrl_set_parsed, 6365 .data = NULL, 6366 .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> " 6367 "<pause_time> <priority> <port_id>: " 6368 "Configure the Ethernet priority flow control", 6369 .tokens = { 6370 (void *)&cmd_pfc_set_set, 6371 (void *)&cmd_pfc_set_flow_ctrl, 6372 (void *)&cmd_pfc_set_rx, 6373 (void *)&cmd_pfc_set_rx_mode, 6374 (void *)&cmd_pfc_set_tx, 6375 (void *)&cmd_pfc_set_tx_mode, 6376 (void *)&cmd_pfc_set_high_water, 6377 (void *)&cmd_pfc_set_low_water, 6378 (void *)&cmd_pfc_set_pause_time, 6379 (void *)&cmd_pfc_set_priority, 6380 (void *)&cmd_pfc_set_portid, 6381 NULL, 6382 }, 6383 }; 6384 6385 /* *** RESET CONFIGURATION *** */ 6386 struct cmd_reset_result { 6387 cmdline_fixed_string_t reset; 6388 cmdline_fixed_string_t def; 6389 }; 6390 6391 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result, 6392 struct cmdline *cl, 6393 __attribute__((unused)) void *data) 6394 { 6395 cmdline_printf(cl, "Reset to default forwarding configuration...\n"); 6396 set_def_fwd_config(); 6397 } 6398 6399 cmdline_parse_token_string_t cmd_reset_set = 6400 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set"); 6401 cmdline_parse_token_string_t cmd_reset_def = 6402 TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def, 6403 "default"); 6404 6405 cmdline_parse_inst_t cmd_reset = { 6406 .f = cmd_reset_parsed, 6407 .data = NULL, 6408 .help_str = "set default: Reset default forwarding configuration", 6409 .tokens = { 6410 (void *)&cmd_reset_set, 6411 (void *)&cmd_reset_def, 6412 NULL, 6413 }, 6414 }; 6415 6416 /* *** START FORWARDING *** */ 6417 struct cmd_start_result { 6418 cmdline_fixed_string_t start; 6419 }; 6420 6421 cmdline_parse_token_string_t cmd_start_start = 6422 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); 6423 6424 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result, 6425 __attribute__((unused)) struct cmdline *cl, 6426 __attribute__((unused)) void *data) 6427 { 6428 start_packet_forwarding(0); 6429 } 6430 6431 cmdline_parse_inst_t cmd_start = { 6432 .f = cmd_start_parsed, 6433 .data = NULL, 6434 .help_str = "start: Start packet forwarding", 6435 .tokens = { 6436 (void *)&cmd_start_start, 6437 NULL, 6438 }, 6439 }; 6440 6441 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */ 6442 struct cmd_start_tx_first_result { 6443 cmdline_fixed_string_t start; 6444 cmdline_fixed_string_t tx_first; 6445 }; 6446 6447 static void 6448 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result, 6449 __attribute__((unused)) struct cmdline *cl, 6450 __attribute__((unused)) void *data) 6451 { 6452 start_packet_forwarding(1); 6453 } 6454 6455 cmdline_parse_token_string_t cmd_start_tx_first_start = 6456 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start, 6457 "start"); 6458 cmdline_parse_token_string_t cmd_start_tx_first_tx_first = 6459 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, 6460 tx_first, "tx_first"); 6461 6462 cmdline_parse_inst_t cmd_start_tx_first = { 6463 .f = cmd_start_tx_first_parsed, 6464 .data = NULL, 6465 .help_str = "start tx_first: Start packet forwarding, " 6466 "after sending 1 burst of packets", 6467 .tokens = { 6468 (void *)&cmd_start_tx_first_start, 6469 (void *)&cmd_start_tx_first_tx_first, 6470 NULL, 6471 }, 6472 }; 6473 6474 /* *** START FORWARDING WITH N TX BURST FIRST *** */ 6475 struct cmd_start_tx_first_n_result { 6476 cmdline_fixed_string_t start; 6477 cmdline_fixed_string_t tx_first; 6478 uint32_t tx_num; 6479 }; 6480 6481 static void 6482 cmd_start_tx_first_n_parsed(void *parsed_result, 6483 __attribute__((unused)) struct cmdline *cl, 6484 __attribute__((unused)) void *data) 6485 { 6486 struct cmd_start_tx_first_n_result *res = parsed_result; 6487 6488 start_packet_forwarding(res->tx_num); 6489 } 6490 6491 cmdline_parse_token_string_t cmd_start_tx_first_n_start = 6492 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6493 start, "start"); 6494 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first = 6495 TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result, 6496 tx_first, "tx_first"); 6497 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num = 6498 TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result, 6499 tx_num, UINT32); 6500 6501 cmdline_parse_inst_t cmd_start_tx_first_n = { 6502 .f = cmd_start_tx_first_n_parsed, 6503 .data = NULL, 6504 .help_str = "start tx_first <num>: " 6505 "packet forwarding, after sending <num> bursts of packets", 6506 .tokens = { 6507 (void *)&cmd_start_tx_first_n_start, 6508 (void *)&cmd_start_tx_first_n_tx_first, 6509 (void *)&cmd_start_tx_first_n_tx_num, 6510 NULL, 6511 }, 6512 }; 6513 6514 /* *** SET LINK UP *** */ 6515 struct cmd_set_link_up_result { 6516 cmdline_fixed_string_t set; 6517 cmdline_fixed_string_t link_up; 6518 cmdline_fixed_string_t port; 6519 portid_t port_id; 6520 }; 6521 6522 cmdline_parse_token_string_t cmd_set_link_up_set = 6523 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set"); 6524 cmdline_parse_token_string_t cmd_set_link_up_link_up = 6525 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up, 6526 "link-up"); 6527 cmdline_parse_token_string_t cmd_set_link_up_port = 6528 TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); 6529 cmdline_parse_token_num_t cmd_set_link_up_port_id = 6530 TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16); 6531 6532 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, 6533 __attribute__((unused)) struct cmdline *cl, 6534 __attribute__((unused)) void *data) 6535 { 6536 struct cmd_set_link_up_result *res = parsed_result; 6537 dev_set_link_up(res->port_id); 6538 } 6539 6540 cmdline_parse_inst_t cmd_set_link_up = { 6541 .f = cmd_set_link_up_parsed, 6542 .data = NULL, 6543 .help_str = "set link-up port <port id>", 6544 .tokens = { 6545 (void *)&cmd_set_link_up_set, 6546 (void *)&cmd_set_link_up_link_up, 6547 (void *)&cmd_set_link_up_port, 6548 (void *)&cmd_set_link_up_port_id, 6549 NULL, 6550 }, 6551 }; 6552 6553 /* *** SET LINK DOWN *** */ 6554 struct cmd_set_link_down_result { 6555 cmdline_fixed_string_t set; 6556 cmdline_fixed_string_t link_down; 6557 cmdline_fixed_string_t port; 6558 portid_t port_id; 6559 }; 6560 6561 cmdline_parse_token_string_t cmd_set_link_down_set = 6562 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set"); 6563 cmdline_parse_token_string_t cmd_set_link_down_link_down = 6564 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down, 6565 "link-down"); 6566 cmdline_parse_token_string_t cmd_set_link_down_port = 6567 TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); 6568 cmdline_parse_token_num_t cmd_set_link_down_port_id = 6569 TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16); 6570 6571 static void cmd_set_link_down_parsed( 6572 __attribute__((unused)) void *parsed_result, 6573 __attribute__((unused)) struct cmdline *cl, 6574 __attribute__((unused)) void *data) 6575 { 6576 struct cmd_set_link_down_result *res = parsed_result; 6577 dev_set_link_down(res->port_id); 6578 } 6579 6580 cmdline_parse_inst_t cmd_set_link_down = { 6581 .f = cmd_set_link_down_parsed, 6582 .data = NULL, 6583 .help_str = "set link-down port <port id>", 6584 .tokens = { 6585 (void *)&cmd_set_link_down_set, 6586 (void *)&cmd_set_link_down_link_down, 6587 (void *)&cmd_set_link_down_port, 6588 (void *)&cmd_set_link_down_port_id, 6589 NULL, 6590 }, 6591 }; 6592 6593 /* *** SHOW CFG *** */ 6594 struct cmd_showcfg_result { 6595 cmdline_fixed_string_t show; 6596 cmdline_fixed_string_t cfg; 6597 cmdline_fixed_string_t what; 6598 }; 6599 6600 static void cmd_showcfg_parsed(void *parsed_result, 6601 __attribute__((unused)) struct cmdline *cl, 6602 __attribute__((unused)) void *data) 6603 { 6604 struct cmd_showcfg_result *res = parsed_result; 6605 if (!strcmp(res->what, "rxtx")) 6606 rxtx_config_display(); 6607 else if (!strcmp(res->what, "cores")) 6608 fwd_lcores_config_display(); 6609 else if (!strcmp(res->what, "fwd")) 6610 pkt_fwd_config_display(&cur_fwd_config); 6611 else if (!strcmp(res->what, "txpkts")) 6612 show_tx_pkt_segments(); 6613 } 6614 6615 cmdline_parse_token_string_t cmd_showcfg_show = 6616 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show"); 6617 cmdline_parse_token_string_t cmd_showcfg_port = 6618 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config"); 6619 cmdline_parse_token_string_t cmd_showcfg_what = 6620 TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what, 6621 "rxtx#cores#fwd#txpkts"); 6622 6623 cmdline_parse_inst_t cmd_showcfg = { 6624 .f = cmd_showcfg_parsed, 6625 .data = NULL, 6626 .help_str = "show config rxtx|cores|fwd|txpkts", 6627 .tokens = { 6628 (void *)&cmd_showcfg_show, 6629 (void *)&cmd_showcfg_port, 6630 (void *)&cmd_showcfg_what, 6631 NULL, 6632 }, 6633 }; 6634 6635 /* *** SHOW ALL PORT INFO *** */ 6636 struct cmd_showportall_result { 6637 cmdline_fixed_string_t show; 6638 cmdline_fixed_string_t port; 6639 cmdline_fixed_string_t what; 6640 cmdline_fixed_string_t all; 6641 }; 6642 6643 static void cmd_showportall_parsed(void *parsed_result, 6644 __attribute__((unused)) struct cmdline *cl, 6645 __attribute__((unused)) void *data) 6646 { 6647 portid_t i; 6648 6649 struct cmd_showportall_result *res = parsed_result; 6650 if (!strcmp(res->show, "clear")) { 6651 if (!strcmp(res->what, "stats")) 6652 RTE_ETH_FOREACH_DEV(i) 6653 nic_stats_clear(i); 6654 else if (!strcmp(res->what, "xstats")) 6655 RTE_ETH_FOREACH_DEV(i) 6656 nic_xstats_clear(i); 6657 } else if (!strcmp(res->what, "info")) 6658 RTE_ETH_FOREACH_DEV(i) 6659 port_infos_display(i); 6660 else if (!strcmp(res->what, "stats")) 6661 RTE_ETH_FOREACH_DEV(i) 6662 nic_stats_display(i); 6663 else if (!strcmp(res->what, "xstats")) 6664 RTE_ETH_FOREACH_DEV(i) 6665 nic_xstats_display(i); 6666 else if (!strcmp(res->what, "fdir")) 6667 RTE_ETH_FOREACH_DEV(i) 6668 fdir_get_infos(i); 6669 else if (!strcmp(res->what, "stat_qmap")) 6670 RTE_ETH_FOREACH_DEV(i) 6671 nic_stats_mapping_display(i); 6672 else if (!strcmp(res->what, "dcb_tc")) 6673 RTE_ETH_FOREACH_DEV(i) 6674 port_dcb_info_display(i); 6675 else if (!strcmp(res->what, "cap")) 6676 RTE_ETH_FOREACH_DEV(i) 6677 port_offload_cap_display(i); 6678 } 6679 6680 cmdline_parse_token_string_t cmd_showportall_show = 6681 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show, 6682 "show#clear"); 6683 cmdline_parse_token_string_t cmd_showportall_port = 6684 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port"); 6685 cmdline_parse_token_string_t cmd_showportall_what = 6686 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what, 6687 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6688 cmdline_parse_token_string_t cmd_showportall_all = 6689 TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all"); 6690 cmdline_parse_inst_t cmd_showportall = { 6691 .f = cmd_showportall_parsed, 6692 .data = NULL, 6693 .help_str = "show|clear port " 6694 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all", 6695 .tokens = { 6696 (void *)&cmd_showportall_show, 6697 (void *)&cmd_showportall_port, 6698 (void *)&cmd_showportall_what, 6699 (void *)&cmd_showportall_all, 6700 NULL, 6701 }, 6702 }; 6703 6704 /* *** SHOW PORT INFO *** */ 6705 struct cmd_showport_result { 6706 cmdline_fixed_string_t show; 6707 cmdline_fixed_string_t port; 6708 cmdline_fixed_string_t what; 6709 uint16_t portnum; 6710 }; 6711 6712 static void cmd_showport_parsed(void *parsed_result, 6713 __attribute__((unused)) struct cmdline *cl, 6714 __attribute__((unused)) void *data) 6715 { 6716 struct cmd_showport_result *res = parsed_result; 6717 if (!strcmp(res->show, "clear")) { 6718 if (!strcmp(res->what, "stats")) 6719 nic_stats_clear(res->portnum); 6720 else if (!strcmp(res->what, "xstats")) 6721 nic_xstats_clear(res->portnum); 6722 } else if (!strcmp(res->what, "info")) 6723 port_infos_display(res->portnum); 6724 else if (!strcmp(res->what, "stats")) 6725 nic_stats_display(res->portnum); 6726 else if (!strcmp(res->what, "xstats")) 6727 nic_xstats_display(res->portnum); 6728 else if (!strcmp(res->what, "fdir")) 6729 fdir_get_infos(res->portnum); 6730 else if (!strcmp(res->what, "stat_qmap")) 6731 nic_stats_mapping_display(res->portnum); 6732 else if (!strcmp(res->what, "dcb_tc")) 6733 port_dcb_info_display(res->portnum); 6734 else if (!strcmp(res->what, "cap")) 6735 port_offload_cap_display(res->portnum); 6736 } 6737 6738 cmdline_parse_token_string_t cmd_showport_show = 6739 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show, 6740 "show#clear"); 6741 cmdline_parse_token_string_t cmd_showport_port = 6742 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port"); 6743 cmdline_parse_token_string_t cmd_showport_what = 6744 TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, 6745 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); 6746 cmdline_parse_token_num_t cmd_showport_portnum = 6747 TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16); 6748 6749 cmdline_parse_inst_t cmd_showport = { 6750 .f = cmd_showport_parsed, 6751 .data = NULL, 6752 .help_str = "show|clear port " 6753 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap " 6754 "<port_id>", 6755 .tokens = { 6756 (void *)&cmd_showport_show, 6757 (void *)&cmd_showport_port, 6758 (void *)&cmd_showport_what, 6759 (void *)&cmd_showport_portnum, 6760 NULL, 6761 }, 6762 }; 6763 6764 /* *** SHOW QUEUE INFO *** */ 6765 struct cmd_showqueue_result { 6766 cmdline_fixed_string_t show; 6767 cmdline_fixed_string_t type; 6768 cmdline_fixed_string_t what; 6769 uint16_t portnum; 6770 uint16_t queuenum; 6771 }; 6772 6773 static void 6774 cmd_showqueue_parsed(void *parsed_result, 6775 __attribute__((unused)) struct cmdline *cl, 6776 __attribute__((unused)) void *data) 6777 { 6778 struct cmd_showqueue_result *res = parsed_result; 6779 6780 if (!strcmp(res->type, "rxq")) 6781 rx_queue_infos_display(res->portnum, res->queuenum); 6782 else if (!strcmp(res->type, "txq")) 6783 tx_queue_infos_display(res->portnum, res->queuenum); 6784 } 6785 6786 cmdline_parse_token_string_t cmd_showqueue_show = 6787 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show"); 6788 cmdline_parse_token_string_t cmd_showqueue_type = 6789 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq"); 6790 cmdline_parse_token_string_t cmd_showqueue_what = 6791 TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); 6792 cmdline_parse_token_num_t cmd_showqueue_portnum = 6793 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16); 6794 cmdline_parse_token_num_t cmd_showqueue_queuenum = 6795 TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); 6796 6797 cmdline_parse_inst_t cmd_showqueue = { 6798 .f = cmd_showqueue_parsed, 6799 .data = NULL, 6800 .help_str = "show rxq|txq info <port_id> <queue_id>", 6801 .tokens = { 6802 (void *)&cmd_showqueue_show, 6803 (void *)&cmd_showqueue_type, 6804 (void *)&cmd_showqueue_what, 6805 (void *)&cmd_showqueue_portnum, 6806 (void *)&cmd_showqueue_queuenum, 6807 NULL, 6808 }, 6809 }; 6810 6811 /* *** READ PORT REGISTER *** */ 6812 struct cmd_read_reg_result { 6813 cmdline_fixed_string_t read; 6814 cmdline_fixed_string_t reg; 6815 portid_t port_id; 6816 uint32_t reg_off; 6817 }; 6818 6819 static void 6820 cmd_read_reg_parsed(void *parsed_result, 6821 __attribute__((unused)) struct cmdline *cl, 6822 __attribute__((unused)) void *data) 6823 { 6824 struct cmd_read_reg_result *res = parsed_result; 6825 port_reg_display(res->port_id, res->reg_off); 6826 } 6827 6828 cmdline_parse_token_string_t cmd_read_reg_read = 6829 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read"); 6830 cmdline_parse_token_string_t cmd_read_reg_reg = 6831 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); 6832 cmdline_parse_token_num_t cmd_read_reg_port_id = 6833 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16); 6834 cmdline_parse_token_num_t cmd_read_reg_reg_off = 6835 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); 6836 6837 cmdline_parse_inst_t cmd_read_reg = { 6838 .f = cmd_read_reg_parsed, 6839 .data = NULL, 6840 .help_str = "read reg <port_id> <reg_off>", 6841 .tokens = { 6842 (void *)&cmd_read_reg_read, 6843 (void *)&cmd_read_reg_reg, 6844 (void *)&cmd_read_reg_port_id, 6845 (void *)&cmd_read_reg_reg_off, 6846 NULL, 6847 }, 6848 }; 6849 6850 /* *** READ PORT REGISTER BIT FIELD *** */ 6851 struct cmd_read_reg_bit_field_result { 6852 cmdline_fixed_string_t read; 6853 cmdline_fixed_string_t regfield; 6854 portid_t port_id; 6855 uint32_t reg_off; 6856 uint8_t bit1_pos; 6857 uint8_t bit2_pos; 6858 }; 6859 6860 static void 6861 cmd_read_reg_bit_field_parsed(void *parsed_result, 6862 __attribute__((unused)) struct cmdline *cl, 6863 __attribute__((unused)) void *data) 6864 { 6865 struct cmd_read_reg_bit_field_result *res = parsed_result; 6866 port_reg_bit_field_display(res->port_id, res->reg_off, 6867 res->bit1_pos, res->bit2_pos); 6868 } 6869 6870 cmdline_parse_token_string_t cmd_read_reg_bit_field_read = 6871 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read, 6872 "read"); 6873 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = 6874 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, 6875 regfield, "regfield"); 6876 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = 6877 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, 6878 UINT16); 6879 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = 6880 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, 6881 UINT32); 6882 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos = 6883 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos, 6884 UINT8); 6885 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos = 6886 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos, 6887 UINT8); 6888 6889 cmdline_parse_inst_t cmd_read_reg_bit_field = { 6890 .f = cmd_read_reg_bit_field_parsed, 6891 .data = NULL, 6892 .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: " 6893 "Read register bit field between bit_x and bit_y included", 6894 .tokens = { 6895 (void *)&cmd_read_reg_bit_field_read, 6896 (void *)&cmd_read_reg_bit_field_regfield, 6897 (void *)&cmd_read_reg_bit_field_port_id, 6898 (void *)&cmd_read_reg_bit_field_reg_off, 6899 (void *)&cmd_read_reg_bit_field_bit1_pos, 6900 (void *)&cmd_read_reg_bit_field_bit2_pos, 6901 NULL, 6902 }, 6903 }; 6904 6905 /* *** READ PORT REGISTER BIT *** */ 6906 struct cmd_read_reg_bit_result { 6907 cmdline_fixed_string_t read; 6908 cmdline_fixed_string_t regbit; 6909 portid_t port_id; 6910 uint32_t reg_off; 6911 uint8_t bit_pos; 6912 }; 6913 6914 static void 6915 cmd_read_reg_bit_parsed(void *parsed_result, 6916 __attribute__((unused)) struct cmdline *cl, 6917 __attribute__((unused)) void *data) 6918 { 6919 struct cmd_read_reg_bit_result *res = parsed_result; 6920 port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos); 6921 } 6922 6923 cmdline_parse_token_string_t cmd_read_reg_bit_read = 6924 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read"); 6925 cmdline_parse_token_string_t cmd_read_reg_bit_regbit = 6926 TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, 6927 regbit, "regbit"); 6928 cmdline_parse_token_num_t cmd_read_reg_bit_port_id = 6929 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16); 6930 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = 6931 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); 6932 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = 6933 TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8); 6934 6935 cmdline_parse_inst_t cmd_read_reg_bit = { 6936 .f = cmd_read_reg_bit_parsed, 6937 .data = NULL, 6938 .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31", 6939 .tokens = { 6940 (void *)&cmd_read_reg_bit_read, 6941 (void *)&cmd_read_reg_bit_regbit, 6942 (void *)&cmd_read_reg_bit_port_id, 6943 (void *)&cmd_read_reg_bit_reg_off, 6944 (void *)&cmd_read_reg_bit_bit_pos, 6945 NULL, 6946 }, 6947 }; 6948 6949 /* *** WRITE PORT REGISTER *** */ 6950 struct cmd_write_reg_result { 6951 cmdline_fixed_string_t write; 6952 cmdline_fixed_string_t reg; 6953 portid_t port_id; 6954 uint32_t reg_off; 6955 uint32_t value; 6956 }; 6957 6958 static void 6959 cmd_write_reg_parsed(void *parsed_result, 6960 __attribute__((unused)) struct cmdline *cl, 6961 __attribute__((unused)) void *data) 6962 { 6963 struct cmd_write_reg_result *res = parsed_result; 6964 port_reg_set(res->port_id, res->reg_off, res->value); 6965 } 6966 6967 cmdline_parse_token_string_t cmd_write_reg_write = 6968 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write"); 6969 cmdline_parse_token_string_t cmd_write_reg_reg = 6970 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); 6971 cmdline_parse_token_num_t cmd_write_reg_port_id = 6972 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16); 6973 cmdline_parse_token_num_t cmd_write_reg_reg_off = 6974 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); 6975 cmdline_parse_token_num_t cmd_write_reg_value = 6976 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32); 6977 6978 cmdline_parse_inst_t cmd_write_reg = { 6979 .f = cmd_write_reg_parsed, 6980 .data = NULL, 6981 .help_str = "write reg <port_id> <reg_off> <reg_value>", 6982 .tokens = { 6983 (void *)&cmd_write_reg_write, 6984 (void *)&cmd_write_reg_reg, 6985 (void *)&cmd_write_reg_port_id, 6986 (void *)&cmd_write_reg_reg_off, 6987 (void *)&cmd_write_reg_value, 6988 NULL, 6989 }, 6990 }; 6991 6992 /* *** WRITE PORT REGISTER BIT FIELD *** */ 6993 struct cmd_write_reg_bit_field_result { 6994 cmdline_fixed_string_t write; 6995 cmdline_fixed_string_t regfield; 6996 portid_t port_id; 6997 uint32_t reg_off; 6998 uint8_t bit1_pos; 6999 uint8_t bit2_pos; 7000 uint32_t value; 7001 }; 7002 7003 static void 7004 cmd_write_reg_bit_field_parsed(void *parsed_result, 7005 __attribute__((unused)) struct cmdline *cl, 7006 __attribute__((unused)) void *data) 7007 { 7008 struct cmd_write_reg_bit_field_result *res = parsed_result; 7009 port_reg_bit_field_set(res->port_id, res->reg_off, 7010 res->bit1_pos, res->bit2_pos, res->value); 7011 } 7012 7013 cmdline_parse_token_string_t cmd_write_reg_bit_field_write = 7014 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write, 7015 "write"); 7016 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = 7017 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, 7018 regfield, "regfield"); 7019 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = 7020 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, 7021 UINT16); 7022 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = 7023 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, 7024 UINT32); 7025 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos = 7026 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos, 7027 UINT8); 7028 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos = 7029 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos, 7030 UINT8); 7031 cmdline_parse_token_num_t cmd_write_reg_bit_field_value = 7032 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value, 7033 UINT32); 7034 7035 cmdline_parse_inst_t cmd_write_reg_bit_field = { 7036 .f = cmd_write_reg_bit_field_parsed, 7037 .data = NULL, 7038 .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> " 7039 "<reg_value>: " 7040 "Set register bit field between bit_x and bit_y included", 7041 .tokens = { 7042 (void *)&cmd_write_reg_bit_field_write, 7043 (void *)&cmd_write_reg_bit_field_regfield, 7044 (void *)&cmd_write_reg_bit_field_port_id, 7045 (void *)&cmd_write_reg_bit_field_reg_off, 7046 (void *)&cmd_write_reg_bit_field_bit1_pos, 7047 (void *)&cmd_write_reg_bit_field_bit2_pos, 7048 (void *)&cmd_write_reg_bit_field_value, 7049 NULL, 7050 }, 7051 }; 7052 7053 /* *** WRITE PORT REGISTER BIT *** */ 7054 struct cmd_write_reg_bit_result { 7055 cmdline_fixed_string_t write; 7056 cmdline_fixed_string_t regbit; 7057 portid_t port_id; 7058 uint32_t reg_off; 7059 uint8_t bit_pos; 7060 uint8_t value; 7061 }; 7062 7063 static void 7064 cmd_write_reg_bit_parsed(void *parsed_result, 7065 __attribute__((unused)) struct cmdline *cl, 7066 __attribute__((unused)) void *data) 7067 { 7068 struct cmd_write_reg_bit_result *res = parsed_result; 7069 port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value); 7070 } 7071 7072 cmdline_parse_token_string_t cmd_write_reg_bit_write = 7073 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write, 7074 "write"); 7075 cmdline_parse_token_string_t cmd_write_reg_bit_regbit = 7076 TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, 7077 regbit, "regbit"); 7078 cmdline_parse_token_num_t cmd_write_reg_bit_port_id = 7079 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16); 7080 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = 7081 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); 7082 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = 7083 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8); 7084 cmdline_parse_token_num_t cmd_write_reg_bit_value = 7085 TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8); 7086 7087 cmdline_parse_inst_t cmd_write_reg_bit = { 7088 .f = cmd_write_reg_bit_parsed, 7089 .data = NULL, 7090 .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: " 7091 "0 <= bit_x <= 31", 7092 .tokens = { 7093 (void *)&cmd_write_reg_bit_write, 7094 (void *)&cmd_write_reg_bit_regbit, 7095 (void *)&cmd_write_reg_bit_port_id, 7096 (void *)&cmd_write_reg_bit_reg_off, 7097 (void *)&cmd_write_reg_bit_bit_pos, 7098 (void *)&cmd_write_reg_bit_value, 7099 NULL, 7100 }, 7101 }; 7102 7103 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */ 7104 struct cmd_read_rxd_txd_result { 7105 cmdline_fixed_string_t read; 7106 cmdline_fixed_string_t rxd_txd; 7107 portid_t port_id; 7108 uint16_t queue_id; 7109 uint16_t desc_id; 7110 }; 7111 7112 static void 7113 cmd_read_rxd_txd_parsed(void *parsed_result, 7114 __attribute__((unused)) struct cmdline *cl, 7115 __attribute__((unused)) void *data) 7116 { 7117 struct cmd_read_rxd_txd_result *res = parsed_result; 7118 7119 if (!strcmp(res->rxd_txd, "rxd")) 7120 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 7121 else if (!strcmp(res->rxd_txd, "txd")) 7122 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id); 7123 } 7124 7125 cmdline_parse_token_string_t cmd_read_rxd_txd_read = 7126 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read"); 7127 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = 7128 TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, 7129 "rxd#txd"); 7130 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = 7131 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16); 7132 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = 7133 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); 7134 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = 7135 TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16); 7136 7137 cmdline_parse_inst_t cmd_read_rxd_txd = { 7138 .f = cmd_read_rxd_txd_parsed, 7139 .data = NULL, 7140 .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>", 7141 .tokens = { 7142 (void *)&cmd_read_rxd_txd_read, 7143 (void *)&cmd_read_rxd_txd_rxd_txd, 7144 (void *)&cmd_read_rxd_txd_port_id, 7145 (void *)&cmd_read_rxd_txd_queue_id, 7146 (void *)&cmd_read_rxd_txd_desc_id, 7147 NULL, 7148 }, 7149 }; 7150 7151 /* *** QUIT *** */ 7152 struct cmd_quit_result { 7153 cmdline_fixed_string_t quit; 7154 }; 7155 7156 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 7157 struct cmdline *cl, 7158 __attribute__((unused)) void *data) 7159 { 7160 pmd_test_exit(); 7161 cmdline_quit(cl); 7162 } 7163 7164 cmdline_parse_token_string_t cmd_quit_quit = 7165 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 7166 7167 cmdline_parse_inst_t cmd_quit = { 7168 .f = cmd_quit_parsed, 7169 .data = NULL, 7170 .help_str = "quit: Exit application", 7171 .tokens = { 7172 (void *)&cmd_quit_quit, 7173 NULL, 7174 }, 7175 }; 7176 7177 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */ 7178 struct cmd_mac_addr_result { 7179 cmdline_fixed_string_t mac_addr_cmd; 7180 cmdline_fixed_string_t what; 7181 uint16_t port_num; 7182 struct ether_addr address; 7183 }; 7184 7185 static void cmd_mac_addr_parsed(void *parsed_result, 7186 __attribute__((unused)) struct cmdline *cl, 7187 __attribute__((unused)) void *data) 7188 { 7189 struct cmd_mac_addr_result *res = parsed_result; 7190 int ret; 7191 7192 if (strcmp(res->what, "add") == 0) 7193 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0); 7194 else if (strcmp(res->what, "set") == 0) 7195 ret = rte_eth_dev_default_mac_addr_set(res->port_num, 7196 &res->address); 7197 else 7198 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address); 7199 7200 /* check the return value and print it if is < 0 */ 7201 if(ret < 0) 7202 printf("mac_addr_cmd error: (%s)\n", strerror(-ret)); 7203 7204 } 7205 7206 cmdline_parse_token_string_t cmd_mac_addr_cmd = 7207 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd, 7208 "mac_addr"); 7209 cmdline_parse_token_string_t cmd_mac_addr_what = 7210 TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, 7211 "add#remove#set"); 7212 cmdline_parse_token_num_t cmd_mac_addr_portnum = 7213 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, 7214 UINT16); 7215 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = 7216 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 7217 7218 cmdline_parse_inst_t cmd_mac_addr = { 7219 .f = cmd_mac_addr_parsed, 7220 .data = (void *)0, 7221 .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: " 7222 "Add/Remove/Set MAC address on port_id", 7223 .tokens = { 7224 (void *)&cmd_mac_addr_cmd, 7225 (void *)&cmd_mac_addr_what, 7226 (void *)&cmd_mac_addr_portnum, 7227 (void *)&cmd_mac_addr_addr, 7228 NULL, 7229 }, 7230 }; 7231 7232 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */ 7233 struct cmd_eth_peer_result { 7234 cmdline_fixed_string_t set; 7235 cmdline_fixed_string_t eth_peer; 7236 portid_t port_id; 7237 cmdline_fixed_string_t peer_addr; 7238 }; 7239 7240 static void cmd_set_eth_peer_parsed(void *parsed_result, 7241 __attribute__((unused)) struct cmdline *cl, 7242 __attribute__((unused)) void *data) 7243 { 7244 struct cmd_eth_peer_result *res = parsed_result; 7245 7246 if (test_done == 0) { 7247 printf("Please stop forwarding first\n"); 7248 return; 7249 } 7250 if (!strcmp(res->eth_peer, "eth-peer")) { 7251 set_fwd_eth_peer(res->port_id, res->peer_addr); 7252 fwd_config_setup(); 7253 } 7254 } 7255 cmdline_parse_token_string_t cmd_eth_peer_set = 7256 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set"); 7257 cmdline_parse_token_string_t cmd_eth_peer = 7258 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer"); 7259 cmdline_parse_token_num_t cmd_eth_peer_port_id = 7260 TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16); 7261 cmdline_parse_token_string_t cmd_eth_peer_addr = 7262 TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL); 7263 7264 cmdline_parse_inst_t cmd_set_fwd_eth_peer = { 7265 .f = cmd_set_eth_peer_parsed, 7266 .data = NULL, 7267 .help_str = "set eth-peer <port_id> <peer_mac>", 7268 .tokens = { 7269 (void *)&cmd_eth_peer_set, 7270 (void *)&cmd_eth_peer, 7271 (void *)&cmd_eth_peer_port_id, 7272 (void *)&cmd_eth_peer_addr, 7273 NULL, 7274 }, 7275 }; 7276 7277 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */ 7278 struct cmd_set_qmap_result { 7279 cmdline_fixed_string_t set; 7280 cmdline_fixed_string_t qmap; 7281 cmdline_fixed_string_t what; 7282 portid_t port_id; 7283 uint16_t queue_id; 7284 uint8_t map_value; 7285 }; 7286 7287 static void 7288 cmd_set_qmap_parsed(void *parsed_result, 7289 __attribute__((unused)) struct cmdline *cl, 7290 __attribute__((unused)) void *data) 7291 { 7292 struct cmd_set_qmap_result *res = parsed_result; 7293 int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1; 7294 7295 set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value); 7296 } 7297 7298 cmdline_parse_token_string_t cmd_setqmap_set = 7299 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7300 set, "set"); 7301 cmdline_parse_token_string_t cmd_setqmap_qmap = 7302 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7303 qmap, "stat_qmap"); 7304 cmdline_parse_token_string_t cmd_setqmap_what = 7305 TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result, 7306 what, "tx#rx"); 7307 cmdline_parse_token_num_t cmd_setqmap_portid = 7308 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7309 port_id, UINT16); 7310 cmdline_parse_token_num_t cmd_setqmap_queueid = 7311 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7312 queue_id, UINT16); 7313 cmdline_parse_token_num_t cmd_setqmap_mapvalue = 7314 TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, 7315 map_value, UINT8); 7316 7317 cmdline_parse_inst_t cmd_set_qmap = { 7318 .f = cmd_set_qmap_parsed, 7319 .data = NULL, 7320 .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: " 7321 "Set statistics mapping value on tx|rx queue_id of port_id", 7322 .tokens = { 7323 (void *)&cmd_setqmap_set, 7324 (void *)&cmd_setqmap_qmap, 7325 (void *)&cmd_setqmap_what, 7326 (void *)&cmd_setqmap_portid, 7327 (void *)&cmd_setqmap_queueid, 7328 (void *)&cmd_setqmap_mapvalue, 7329 NULL, 7330 }, 7331 }; 7332 7333 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS DISPLAY *** */ 7334 struct cmd_set_xstats_hide_zero_result { 7335 cmdline_fixed_string_t keyword; 7336 cmdline_fixed_string_t name; 7337 cmdline_fixed_string_t on_off; 7338 }; 7339 7340 static void 7341 cmd_set_xstats_hide_zero_parsed(void *parsed_result, 7342 __attribute__((unused)) struct cmdline *cl, 7343 __attribute__((unused)) void *data) 7344 { 7345 struct cmd_set_xstats_hide_zero_result *res; 7346 uint16_t on_off = 0; 7347 7348 res = parsed_result; 7349 on_off = !strcmp(res->on_off, "on") ? 1 : 0; 7350 set_xstats_hide_zero(on_off); 7351 } 7352 7353 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword = 7354 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 7355 keyword, "set"); 7356 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name = 7357 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 7358 name, "xstats-hide-zero"); 7359 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off = 7360 TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, 7361 on_off, "on#off"); 7362 7363 cmdline_parse_inst_t cmd_set_xstats_hide_zero = { 7364 .f = cmd_set_xstats_hide_zero_parsed, 7365 .data = NULL, 7366 .help_str = "set xstats-hide-zero on|off", 7367 .tokens = { 7368 (void *)&cmd_set_xstats_hide_zero_keyword, 7369 (void *)&cmd_set_xstats_hide_zero_name, 7370 (void *)&cmd_set_xstats_hide_zero_on_off, 7371 NULL, 7372 }, 7373 }; 7374 7375 /* *** CONFIGURE UNICAST HASH TABLE *** */ 7376 struct cmd_set_uc_hash_table { 7377 cmdline_fixed_string_t set; 7378 cmdline_fixed_string_t port; 7379 portid_t port_id; 7380 cmdline_fixed_string_t what; 7381 struct ether_addr address; 7382 cmdline_fixed_string_t mode; 7383 }; 7384 7385 static void 7386 cmd_set_uc_hash_parsed(void *parsed_result, 7387 __attribute__((unused)) struct cmdline *cl, 7388 __attribute__((unused)) void *data) 7389 { 7390 int ret=0; 7391 struct cmd_set_uc_hash_table *res = parsed_result; 7392 7393 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7394 7395 if (strcmp(res->what, "uta") == 0) 7396 ret = rte_eth_dev_uc_hash_table_set(res->port_id, 7397 &res->address,(uint8_t)is_on); 7398 if (ret < 0) 7399 printf("bad unicast hash table parameter, return code = %d \n", ret); 7400 7401 } 7402 7403 cmdline_parse_token_string_t cmd_set_uc_hash_set = 7404 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7405 set, "set"); 7406 cmdline_parse_token_string_t cmd_set_uc_hash_port = 7407 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7408 port, "port"); 7409 cmdline_parse_token_num_t cmd_set_uc_hash_portid = 7410 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, 7411 port_id, UINT16); 7412 cmdline_parse_token_string_t cmd_set_uc_hash_what = 7413 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7414 what, "uta"); 7415 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac = 7416 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table, 7417 address); 7418 cmdline_parse_token_string_t cmd_set_uc_hash_mode = 7419 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, 7420 mode, "on#off"); 7421 7422 cmdline_parse_inst_t cmd_set_uc_hash_filter = { 7423 .f = cmd_set_uc_hash_parsed, 7424 .data = NULL, 7425 .help_str = "set port <port_id> uta <mac_addr> on|off)", 7426 .tokens = { 7427 (void *)&cmd_set_uc_hash_set, 7428 (void *)&cmd_set_uc_hash_port, 7429 (void *)&cmd_set_uc_hash_portid, 7430 (void *)&cmd_set_uc_hash_what, 7431 (void *)&cmd_set_uc_hash_mac, 7432 (void *)&cmd_set_uc_hash_mode, 7433 NULL, 7434 }, 7435 }; 7436 7437 struct cmd_set_uc_all_hash_table { 7438 cmdline_fixed_string_t set; 7439 cmdline_fixed_string_t port; 7440 portid_t port_id; 7441 cmdline_fixed_string_t what; 7442 cmdline_fixed_string_t value; 7443 cmdline_fixed_string_t mode; 7444 }; 7445 7446 static void 7447 cmd_set_uc_all_hash_parsed(void *parsed_result, 7448 __attribute__((unused)) struct cmdline *cl, 7449 __attribute__((unused)) void *data) 7450 { 7451 int ret=0; 7452 struct cmd_set_uc_all_hash_table *res = parsed_result; 7453 7454 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7455 7456 if ((strcmp(res->what, "uta") == 0) && 7457 (strcmp(res->value, "all") == 0)) 7458 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on); 7459 if (ret < 0) 7460 printf("bad unicast hash table parameter," 7461 "return code = %d \n", ret); 7462 } 7463 7464 cmdline_parse_token_string_t cmd_set_uc_all_hash_set = 7465 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7466 set, "set"); 7467 cmdline_parse_token_string_t cmd_set_uc_all_hash_port = 7468 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7469 port, "port"); 7470 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = 7471 TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, 7472 port_id, UINT16); 7473 cmdline_parse_token_string_t cmd_set_uc_all_hash_what = 7474 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7475 what, "uta"); 7476 cmdline_parse_token_string_t cmd_set_uc_all_hash_value = 7477 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7478 value,"all"); 7479 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode = 7480 TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, 7481 mode, "on#off"); 7482 7483 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { 7484 .f = cmd_set_uc_all_hash_parsed, 7485 .data = NULL, 7486 .help_str = "set port <port_id> uta all on|off", 7487 .tokens = { 7488 (void *)&cmd_set_uc_all_hash_set, 7489 (void *)&cmd_set_uc_all_hash_port, 7490 (void *)&cmd_set_uc_all_hash_portid, 7491 (void *)&cmd_set_uc_all_hash_what, 7492 (void *)&cmd_set_uc_all_hash_value, 7493 (void *)&cmd_set_uc_all_hash_mode, 7494 NULL, 7495 }, 7496 }; 7497 7498 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */ 7499 struct cmd_set_vf_macvlan_filter { 7500 cmdline_fixed_string_t set; 7501 cmdline_fixed_string_t port; 7502 portid_t port_id; 7503 cmdline_fixed_string_t vf; 7504 uint8_t vf_id; 7505 struct ether_addr address; 7506 cmdline_fixed_string_t filter_type; 7507 cmdline_fixed_string_t mode; 7508 }; 7509 7510 static void 7511 cmd_set_vf_macvlan_parsed(void *parsed_result, 7512 __attribute__((unused)) struct cmdline *cl, 7513 __attribute__((unused)) void *data) 7514 { 7515 int is_on, ret = 0; 7516 struct cmd_set_vf_macvlan_filter *res = parsed_result; 7517 struct rte_eth_mac_filter filter; 7518 7519 memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); 7520 7521 rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); 7522 7523 /* set VF MAC filter */ 7524 filter.is_vf = 1; 7525 7526 /* set VF ID */ 7527 filter.dst_id = res->vf_id; 7528 7529 if (!strcmp(res->filter_type, "exact-mac")) 7530 filter.filter_type = RTE_MAC_PERFECT_MATCH; 7531 else if (!strcmp(res->filter_type, "exact-mac-vlan")) 7532 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH; 7533 else if (!strcmp(res->filter_type, "hashmac")) 7534 filter.filter_type = RTE_MAC_HASH_MATCH; 7535 else if (!strcmp(res->filter_type, "hashmac-vlan")) 7536 filter.filter_type = RTE_MACVLAN_HASH_MATCH; 7537 7538 is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7539 7540 if (is_on) 7541 ret = rte_eth_dev_filter_ctrl(res->port_id, 7542 RTE_ETH_FILTER_MACVLAN, 7543 RTE_ETH_FILTER_ADD, 7544 &filter); 7545 else 7546 ret = rte_eth_dev_filter_ctrl(res->port_id, 7547 RTE_ETH_FILTER_MACVLAN, 7548 RTE_ETH_FILTER_DELETE, 7549 &filter); 7550 7551 if (ret < 0) 7552 printf("bad set MAC hash parameter, return code = %d\n", ret); 7553 7554 } 7555 7556 cmdline_parse_token_string_t cmd_set_vf_macvlan_set = 7557 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7558 set, "set"); 7559 cmdline_parse_token_string_t cmd_set_vf_macvlan_port = 7560 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7561 port, "port"); 7562 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = 7563 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7564 port_id, UINT16); 7565 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = 7566 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7567 vf, "vf"); 7568 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id = 7569 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7570 vf_id, UINT8); 7571 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac = 7572 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7573 address); 7574 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type = 7575 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7576 filter_type, "exact-mac#exact-mac-vlan" 7577 "#hashmac#hashmac-vlan"); 7578 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode = 7579 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, 7580 mode, "on#off"); 7581 7582 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { 7583 .f = cmd_set_vf_macvlan_parsed, 7584 .data = NULL, 7585 .help_str = "set port <port_id> vf <vf_id> <mac_addr> " 7586 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: " 7587 "Exact match rule: exact match of MAC or MAC and VLAN; " 7588 "hash match rule: hash match of MAC and exact match of VLAN", 7589 .tokens = { 7590 (void *)&cmd_set_vf_macvlan_set, 7591 (void *)&cmd_set_vf_macvlan_port, 7592 (void *)&cmd_set_vf_macvlan_portid, 7593 (void *)&cmd_set_vf_macvlan_vf, 7594 (void *)&cmd_set_vf_macvlan_vf_id, 7595 (void *)&cmd_set_vf_macvlan_mac, 7596 (void *)&cmd_set_vf_macvlan_filter_type, 7597 (void *)&cmd_set_vf_macvlan_mode, 7598 NULL, 7599 }, 7600 }; 7601 7602 /* *** CONFIGURE VF TRAFFIC CONTROL *** */ 7603 struct cmd_set_vf_traffic { 7604 cmdline_fixed_string_t set; 7605 cmdline_fixed_string_t port; 7606 portid_t port_id; 7607 cmdline_fixed_string_t vf; 7608 uint8_t vf_id; 7609 cmdline_fixed_string_t what; 7610 cmdline_fixed_string_t mode; 7611 }; 7612 7613 static void 7614 cmd_set_vf_traffic_parsed(void *parsed_result, 7615 __attribute__((unused)) struct cmdline *cl, 7616 __attribute__((unused)) void *data) 7617 { 7618 struct cmd_set_vf_traffic *res = parsed_result; 7619 int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0; 7620 int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0; 7621 7622 set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on); 7623 } 7624 7625 cmdline_parse_token_string_t cmd_setvf_traffic_set = 7626 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7627 set, "set"); 7628 cmdline_parse_token_string_t cmd_setvf_traffic_port = 7629 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7630 port, "port"); 7631 cmdline_parse_token_num_t cmd_setvf_traffic_portid = 7632 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7633 port_id, UINT16); 7634 cmdline_parse_token_string_t cmd_setvf_traffic_vf = 7635 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7636 vf, "vf"); 7637 cmdline_parse_token_num_t cmd_setvf_traffic_vfid = 7638 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, 7639 vf_id, UINT8); 7640 cmdline_parse_token_string_t cmd_setvf_traffic_what = 7641 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7642 what, "tx#rx"); 7643 cmdline_parse_token_string_t cmd_setvf_traffic_mode = 7644 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, 7645 mode, "on#off"); 7646 7647 cmdline_parse_inst_t cmd_set_vf_traffic = { 7648 .f = cmd_set_vf_traffic_parsed, 7649 .data = NULL, 7650 .help_str = "set port <port_id> vf <vf_id> rx|tx on|off", 7651 .tokens = { 7652 (void *)&cmd_setvf_traffic_set, 7653 (void *)&cmd_setvf_traffic_port, 7654 (void *)&cmd_setvf_traffic_portid, 7655 (void *)&cmd_setvf_traffic_vf, 7656 (void *)&cmd_setvf_traffic_vfid, 7657 (void *)&cmd_setvf_traffic_what, 7658 (void *)&cmd_setvf_traffic_mode, 7659 NULL, 7660 }, 7661 }; 7662 7663 /* *** CONFIGURE VF RECEIVE MODE *** */ 7664 struct cmd_set_vf_rxmode { 7665 cmdline_fixed_string_t set; 7666 cmdline_fixed_string_t port; 7667 portid_t port_id; 7668 cmdline_fixed_string_t vf; 7669 uint8_t vf_id; 7670 cmdline_fixed_string_t what; 7671 cmdline_fixed_string_t mode; 7672 cmdline_fixed_string_t on; 7673 }; 7674 7675 static void 7676 cmd_set_vf_rxmode_parsed(void *parsed_result, 7677 __attribute__((unused)) struct cmdline *cl, 7678 __attribute__((unused)) void *data) 7679 { 7680 int ret = -ENOTSUP; 7681 uint16_t rx_mode = 0; 7682 struct cmd_set_vf_rxmode *res = parsed_result; 7683 7684 int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0; 7685 if (!strcmp(res->what,"rxmode")) { 7686 if (!strcmp(res->mode, "AUPE")) 7687 rx_mode |= ETH_VMDQ_ACCEPT_UNTAG; 7688 else if (!strcmp(res->mode, "ROPE")) 7689 rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC; 7690 else if (!strcmp(res->mode, "BAM")) 7691 rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST; 7692 else if (!strncmp(res->mode, "MPE",3)) 7693 rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; 7694 } 7695 7696 RTE_SET_USED(is_on); 7697 7698 #ifdef RTE_LIBRTE_IXGBE_PMD 7699 if (ret == -ENOTSUP) 7700 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, 7701 rx_mode, (uint8_t)is_on); 7702 #endif 7703 #ifdef RTE_LIBRTE_BNXT_PMD 7704 if (ret == -ENOTSUP) 7705 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id, 7706 rx_mode, (uint8_t)is_on); 7707 #endif 7708 if (ret < 0) 7709 printf("bad VF receive mode parameter, return code = %d \n", 7710 ret); 7711 } 7712 7713 cmdline_parse_token_string_t cmd_set_vf_rxmode_set = 7714 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7715 set, "set"); 7716 cmdline_parse_token_string_t cmd_set_vf_rxmode_port = 7717 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7718 port, "port"); 7719 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = 7720 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7721 port_id, UINT16); 7722 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = 7723 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7724 vf, "vf"); 7725 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid = 7726 TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, 7727 vf_id, UINT8); 7728 cmdline_parse_token_string_t cmd_set_vf_rxmode_what = 7729 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7730 what, "rxmode"); 7731 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode = 7732 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7733 mode, "AUPE#ROPE#BAM#MPE"); 7734 cmdline_parse_token_string_t cmd_set_vf_rxmode_on = 7735 TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, 7736 on, "on#off"); 7737 7738 cmdline_parse_inst_t cmd_set_vf_rxmode = { 7739 .f = cmd_set_vf_rxmode_parsed, 7740 .data = NULL, 7741 .help_str = "set port <port_id> vf <vf_id> rxmode " 7742 "AUPE|ROPE|BAM|MPE on|off", 7743 .tokens = { 7744 (void *)&cmd_set_vf_rxmode_set, 7745 (void *)&cmd_set_vf_rxmode_port, 7746 (void *)&cmd_set_vf_rxmode_portid, 7747 (void *)&cmd_set_vf_rxmode_vf, 7748 (void *)&cmd_set_vf_rxmode_vfid, 7749 (void *)&cmd_set_vf_rxmode_what, 7750 (void *)&cmd_set_vf_rxmode_mode, 7751 (void *)&cmd_set_vf_rxmode_on, 7752 NULL, 7753 }, 7754 }; 7755 7756 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */ 7757 struct cmd_vf_mac_addr_result { 7758 cmdline_fixed_string_t mac_addr_cmd; 7759 cmdline_fixed_string_t what; 7760 cmdline_fixed_string_t port; 7761 uint16_t port_num; 7762 cmdline_fixed_string_t vf; 7763 uint8_t vf_num; 7764 struct ether_addr address; 7765 }; 7766 7767 static void cmd_vf_mac_addr_parsed(void *parsed_result, 7768 __attribute__((unused)) struct cmdline *cl, 7769 __attribute__((unused)) void *data) 7770 { 7771 struct cmd_vf_mac_addr_result *res = parsed_result; 7772 int ret = -ENOTSUP; 7773 7774 if (strcmp(res->what, "add") != 0) 7775 return; 7776 7777 #ifdef RTE_LIBRTE_I40E_PMD 7778 if (ret == -ENOTSUP) 7779 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num, 7780 &res->address); 7781 #endif 7782 #ifdef RTE_LIBRTE_BNXT_PMD 7783 if (ret == -ENOTSUP) 7784 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address, 7785 res->vf_num); 7786 #endif 7787 7788 if(ret < 0) 7789 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); 7790 7791 } 7792 7793 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd = 7794 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7795 mac_addr_cmd,"mac_addr"); 7796 cmdline_parse_token_string_t cmd_vf_mac_addr_what = 7797 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7798 what,"add"); 7799 cmdline_parse_token_string_t cmd_vf_mac_addr_port = 7800 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7801 port,"port"); 7802 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = 7803 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7804 port_num, UINT16); 7805 cmdline_parse_token_string_t cmd_vf_mac_addr_vf = 7806 TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, 7807 vf,"vf"); 7808 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum = 7809 TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, 7810 vf_num, UINT8); 7811 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr = 7812 TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result, 7813 address); 7814 7815 cmdline_parse_inst_t cmd_vf_mac_addr_filter = { 7816 .f = cmd_vf_mac_addr_parsed, 7817 .data = (void *)0, 7818 .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: " 7819 "Add MAC address filtering for a VF on port_id", 7820 .tokens = { 7821 (void *)&cmd_vf_mac_addr_cmd, 7822 (void *)&cmd_vf_mac_addr_what, 7823 (void *)&cmd_vf_mac_addr_port, 7824 (void *)&cmd_vf_mac_addr_portnum, 7825 (void *)&cmd_vf_mac_addr_vf, 7826 (void *)&cmd_vf_mac_addr_vfnum, 7827 (void *)&cmd_vf_mac_addr_addr, 7828 NULL, 7829 }, 7830 }; 7831 7832 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */ 7833 struct cmd_vf_rx_vlan_filter { 7834 cmdline_fixed_string_t rx_vlan; 7835 cmdline_fixed_string_t what; 7836 uint16_t vlan_id; 7837 cmdline_fixed_string_t port; 7838 portid_t port_id; 7839 cmdline_fixed_string_t vf; 7840 uint64_t vf_mask; 7841 }; 7842 7843 static void 7844 cmd_vf_rx_vlan_filter_parsed(void *parsed_result, 7845 __attribute__((unused)) struct cmdline *cl, 7846 __attribute__((unused)) void *data) 7847 { 7848 struct cmd_vf_rx_vlan_filter *res = parsed_result; 7849 int ret = -ENOTSUP; 7850 7851 __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0; 7852 7853 #ifdef RTE_LIBRTE_IXGBE_PMD 7854 if (ret == -ENOTSUP) 7855 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id, 7856 res->vlan_id, res->vf_mask, is_add); 7857 #endif 7858 #ifdef RTE_LIBRTE_I40E_PMD 7859 if (ret == -ENOTSUP) 7860 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id, 7861 res->vlan_id, res->vf_mask, is_add); 7862 #endif 7863 #ifdef RTE_LIBRTE_BNXT_PMD 7864 if (ret == -ENOTSUP) 7865 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id, 7866 res->vlan_id, res->vf_mask, is_add); 7867 #endif 7868 7869 switch (ret) { 7870 case 0: 7871 break; 7872 case -EINVAL: 7873 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n", 7874 res->vlan_id, res->vf_mask); 7875 break; 7876 case -ENODEV: 7877 printf("invalid port_id %d\n", res->port_id); 7878 break; 7879 case -ENOTSUP: 7880 printf("function not implemented or supported\n"); 7881 break; 7882 default: 7883 printf("programming error: (%s)\n", strerror(-ret)); 7884 } 7885 } 7886 7887 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan = 7888 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7889 rx_vlan, "rx_vlan"); 7890 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what = 7891 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7892 what, "add#rm"); 7893 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid = 7894 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7895 vlan_id, UINT16); 7896 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = 7897 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7898 port, "port"); 7899 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = 7900 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7901 port_id, UINT16); 7902 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = 7903 TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7904 vf, "vf"); 7905 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask = 7906 TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, 7907 vf_mask, UINT64); 7908 7909 cmdline_parse_inst_t cmd_vf_rxvlan_filter = { 7910 .f = cmd_vf_rx_vlan_filter_parsed, 7911 .data = NULL, 7912 .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: " 7913 "(vf_mask = hexadecimal VF mask)", 7914 .tokens = { 7915 (void *)&cmd_vf_rx_vlan_filter_rx_vlan, 7916 (void *)&cmd_vf_rx_vlan_filter_what, 7917 (void *)&cmd_vf_rx_vlan_filter_vlanid, 7918 (void *)&cmd_vf_rx_vlan_filter_port, 7919 (void *)&cmd_vf_rx_vlan_filter_portid, 7920 (void *)&cmd_vf_rx_vlan_filter_vf, 7921 (void *)&cmd_vf_rx_vlan_filter_vf_mask, 7922 NULL, 7923 }, 7924 }; 7925 7926 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */ 7927 struct cmd_queue_rate_limit_result { 7928 cmdline_fixed_string_t set; 7929 cmdline_fixed_string_t port; 7930 uint16_t port_num; 7931 cmdline_fixed_string_t queue; 7932 uint8_t queue_num; 7933 cmdline_fixed_string_t rate; 7934 uint16_t rate_num; 7935 }; 7936 7937 static void cmd_queue_rate_limit_parsed(void *parsed_result, 7938 __attribute__((unused)) struct cmdline *cl, 7939 __attribute__((unused)) void *data) 7940 { 7941 struct cmd_queue_rate_limit_result *res = parsed_result; 7942 int ret = 0; 7943 7944 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 7945 && (strcmp(res->queue, "queue") == 0) 7946 && (strcmp(res->rate, "rate") == 0)) 7947 ret = set_queue_rate_limit(res->port_num, res->queue_num, 7948 res->rate_num); 7949 if (ret < 0) 7950 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret)); 7951 7952 } 7953 7954 cmdline_parse_token_string_t cmd_queue_rate_limit_set = 7955 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7956 set, "set"); 7957 cmdline_parse_token_string_t cmd_queue_rate_limit_port = 7958 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7959 port, "port"); 7960 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = 7961 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7962 port_num, UINT16); 7963 cmdline_parse_token_string_t cmd_queue_rate_limit_queue = 7964 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7965 queue, "queue"); 7966 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum = 7967 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7968 queue_num, UINT8); 7969 cmdline_parse_token_string_t cmd_queue_rate_limit_rate = 7970 TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, 7971 rate, "rate"); 7972 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum = 7973 TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, 7974 rate_num, UINT16); 7975 7976 cmdline_parse_inst_t cmd_queue_rate_limit = { 7977 .f = cmd_queue_rate_limit_parsed, 7978 .data = (void *)0, 7979 .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: " 7980 "Set rate limit for a queue on port_id", 7981 .tokens = { 7982 (void *)&cmd_queue_rate_limit_set, 7983 (void *)&cmd_queue_rate_limit_port, 7984 (void *)&cmd_queue_rate_limit_portnum, 7985 (void *)&cmd_queue_rate_limit_queue, 7986 (void *)&cmd_queue_rate_limit_queuenum, 7987 (void *)&cmd_queue_rate_limit_rate, 7988 (void *)&cmd_queue_rate_limit_ratenum, 7989 NULL, 7990 }, 7991 }; 7992 7993 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */ 7994 struct cmd_vf_rate_limit_result { 7995 cmdline_fixed_string_t set; 7996 cmdline_fixed_string_t port; 7997 uint16_t port_num; 7998 cmdline_fixed_string_t vf; 7999 uint8_t vf_num; 8000 cmdline_fixed_string_t rate; 8001 uint16_t rate_num; 8002 cmdline_fixed_string_t q_msk; 8003 uint64_t q_msk_val; 8004 }; 8005 8006 static void cmd_vf_rate_limit_parsed(void *parsed_result, 8007 __attribute__((unused)) struct cmdline *cl, 8008 __attribute__((unused)) void *data) 8009 { 8010 struct cmd_vf_rate_limit_result *res = parsed_result; 8011 int ret = 0; 8012 8013 if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0) 8014 && (strcmp(res->vf, "vf") == 0) 8015 && (strcmp(res->rate, "rate") == 0) 8016 && (strcmp(res->q_msk, "queue_mask") == 0)) 8017 ret = set_vf_rate_limit(res->port_num, res->vf_num, 8018 res->rate_num, res->q_msk_val); 8019 if (ret < 0) 8020 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret)); 8021 8022 } 8023 8024 cmdline_parse_token_string_t cmd_vf_rate_limit_set = 8025 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8026 set, "set"); 8027 cmdline_parse_token_string_t cmd_vf_rate_limit_port = 8028 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8029 port, "port"); 8030 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = 8031 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8032 port_num, UINT16); 8033 cmdline_parse_token_string_t cmd_vf_rate_limit_vf = 8034 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8035 vf, "vf"); 8036 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum = 8037 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8038 vf_num, UINT8); 8039 cmdline_parse_token_string_t cmd_vf_rate_limit_rate = 8040 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8041 rate, "rate"); 8042 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum = 8043 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8044 rate_num, UINT16); 8045 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk = 8046 TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, 8047 q_msk, "queue_mask"); 8048 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val = 8049 TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, 8050 q_msk_val, UINT64); 8051 8052 cmdline_parse_inst_t cmd_vf_rate_limit = { 8053 .f = cmd_vf_rate_limit_parsed, 8054 .data = (void *)0, 8055 .help_str = "set port <port_id> vf <vf_id> rate <rate_value> " 8056 "queue_mask <queue_mask_value>: " 8057 "Set rate limit for queues of VF on port_id", 8058 .tokens = { 8059 (void *)&cmd_vf_rate_limit_set, 8060 (void *)&cmd_vf_rate_limit_port, 8061 (void *)&cmd_vf_rate_limit_portnum, 8062 (void *)&cmd_vf_rate_limit_vf, 8063 (void *)&cmd_vf_rate_limit_vfnum, 8064 (void *)&cmd_vf_rate_limit_rate, 8065 (void *)&cmd_vf_rate_limit_ratenum, 8066 (void *)&cmd_vf_rate_limit_q_msk, 8067 (void *)&cmd_vf_rate_limit_q_msk_val, 8068 NULL, 8069 }, 8070 }; 8071 8072 /* *** ADD TUNNEL FILTER OF A PORT *** */ 8073 struct cmd_tunnel_filter_result { 8074 cmdline_fixed_string_t cmd; 8075 cmdline_fixed_string_t what; 8076 portid_t port_id; 8077 struct ether_addr outer_mac; 8078 struct ether_addr inner_mac; 8079 cmdline_ipaddr_t ip_value; 8080 uint16_t inner_vlan; 8081 cmdline_fixed_string_t tunnel_type; 8082 cmdline_fixed_string_t filter_type; 8083 uint32_t tenant_id; 8084 uint16_t queue_num; 8085 }; 8086 8087 static void 8088 cmd_tunnel_filter_parsed(void *parsed_result, 8089 __attribute__((unused)) struct cmdline *cl, 8090 __attribute__((unused)) void *data) 8091 { 8092 struct cmd_tunnel_filter_result *res = parsed_result; 8093 struct rte_eth_tunnel_filter_conf tunnel_filter_conf; 8094 int ret = 0; 8095 8096 memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf)); 8097 8098 ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac); 8099 ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac); 8100 tunnel_filter_conf.inner_vlan = res->inner_vlan; 8101 8102 if (res->ip_value.family == AF_INET) { 8103 tunnel_filter_conf.ip_addr.ipv4_addr = 8104 res->ip_value.addr.ipv4.s_addr; 8105 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4; 8106 } else { 8107 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr), 8108 &(res->ip_value.addr.ipv6), 8109 sizeof(struct in6_addr)); 8110 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6; 8111 } 8112 8113 if (!strcmp(res->filter_type, "imac-ivlan")) 8114 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN; 8115 else if (!strcmp(res->filter_type, "imac-ivlan-tenid")) 8116 tunnel_filter_conf.filter_type = 8117 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID; 8118 else if (!strcmp(res->filter_type, "imac-tenid")) 8119 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID; 8120 else if (!strcmp(res->filter_type, "imac")) 8121 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC; 8122 else if (!strcmp(res->filter_type, "omac-imac-tenid")) 8123 tunnel_filter_conf.filter_type = 8124 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC; 8125 else if (!strcmp(res->filter_type, "oip")) 8126 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP; 8127 else if (!strcmp(res->filter_type, "iip")) 8128 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP; 8129 else { 8130 printf("The filter type is not supported"); 8131 return; 8132 } 8133 8134 if (!strcmp(res->tunnel_type, "vxlan")) 8135 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; 8136 else if (!strcmp(res->tunnel_type, "nvgre")) 8137 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE; 8138 else if (!strcmp(res->tunnel_type, "ipingre")) 8139 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE; 8140 else { 8141 printf("The tunnel type %s not supported.\n", res->tunnel_type); 8142 return; 8143 } 8144 8145 tunnel_filter_conf.tenant_id = res->tenant_id; 8146 tunnel_filter_conf.queue_id = res->queue_num; 8147 if (!strcmp(res->what, "add")) 8148 ret = rte_eth_dev_filter_ctrl(res->port_id, 8149 RTE_ETH_FILTER_TUNNEL, 8150 RTE_ETH_FILTER_ADD, 8151 &tunnel_filter_conf); 8152 else 8153 ret = rte_eth_dev_filter_ctrl(res->port_id, 8154 RTE_ETH_FILTER_TUNNEL, 8155 RTE_ETH_FILTER_DELETE, 8156 &tunnel_filter_conf); 8157 if (ret < 0) 8158 printf("cmd_tunnel_filter_parsed error: (%s)\n", 8159 strerror(-ret)); 8160 8161 } 8162 cmdline_parse_token_string_t cmd_tunnel_filter_cmd = 8163 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 8164 cmd, "tunnel_filter"); 8165 cmdline_parse_token_string_t cmd_tunnel_filter_what = 8166 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 8167 what, "add#rm"); 8168 cmdline_parse_token_num_t cmd_tunnel_filter_port_id = 8169 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 8170 port_id, UINT16); 8171 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = 8172 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 8173 outer_mac); 8174 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac = 8175 TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, 8176 inner_mac); 8177 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan = 8178 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 8179 inner_vlan, UINT16); 8180 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value = 8181 TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result, 8182 ip_value); 8183 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type = 8184 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 8185 tunnel_type, "vxlan#nvgre#ipingre"); 8186 8187 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type = 8188 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result, 8189 filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#" 8190 "imac#omac-imac-tenid"); 8191 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id = 8192 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 8193 tenant_id, UINT32); 8194 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num = 8195 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, 8196 queue_num, UINT16); 8197 8198 cmdline_parse_inst_t cmd_tunnel_filter = { 8199 .f = cmd_tunnel_filter_parsed, 8200 .data = (void *)0, 8201 .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> " 8202 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|" 8203 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> " 8204 "<queue_id>: Add/Rm tunnel filter of a port", 8205 .tokens = { 8206 (void *)&cmd_tunnel_filter_cmd, 8207 (void *)&cmd_tunnel_filter_what, 8208 (void *)&cmd_tunnel_filter_port_id, 8209 (void *)&cmd_tunnel_filter_outer_mac, 8210 (void *)&cmd_tunnel_filter_inner_mac, 8211 (void *)&cmd_tunnel_filter_ip_value, 8212 (void *)&cmd_tunnel_filter_innner_vlan, 8213 (void *)&cmd_tunnel_filter_tunnel_type, 8214 (void *)&cmd_tunnel_filter_filter_type, 8215 (void *)&cmd_tunnel_filter_tenant_id, 8216 (void *)&cmd_tunnel_filter_queue_num, 8217 NULL, 8218 }, 8219 }; 8220 8221 /* *** CONFIGURE TUNNEL UDP PORT *** */ 8222 struct cmd_tunnel_udp_config { 8223 cmdline_fixed_string_t cmd; 8224 cmdline_fixed_string_t what; 8225 uint16_t udp_port; 8226 portid_t port_id; 8227 }; 8228 8229 static void 8230 cmd_tunnel_udp_config_parsed(void *parsed_result, 8231 __attribute__((unused)) struct cmdline *cl, 8232 __attribute__((unused)) void *data) 8233 { 8234 struct cmd_tunnel_udp_config *res = parsed_result; 8235 struct rte_eth_udp_tunnel tunnel_udp; 8236 int ret; 8237 8238 tunnel_udp.udp_port = res->udp_port; 8239 8240 if (!strcmp(res->cmd, "rx_vxlan_port")) 8241 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; 8242 8243 if (!strcmp(res->what, "add")) 8244 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id, 8245 &tunnel_udp); 8246 else 8247 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id, 8248 &tunnel_udp); 8249 8250 if (ret < 0) 8251 printf("udp tunneling add error: (%s)\n", strerror(-ret)); 8252 } 8253 8254 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = 8255 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 8256 cmd, "rx_vxlan_port"); 8257 cmdline_parse_token_string_t cmd_tunnel_udp_config_what = 8258 TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, 8259 what, "add#rm"); 8260 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = 8261 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 8262 udp_port, UINT16); 8263 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = 8264 TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, 8265 port_id, UINT16); 8266 8267 cmdline_parse_inst_t cmd_tunnel_udp_config = { 8268 .f = cmd_tunnel_udp_config_parsed, 8269 .data = (void *)0, 8270 .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: " 8271 "Add/Remove a tunneling UDP port filter", 8272 .tokens = { 8273 (void *)&cmd_tunnel_udp_config_cmd, 8274 (void *)&cmd_tunnel_udp_config_what, 8275 (void *)&cmd_tunnel_udp_config_udp_port, 8276 (void *)&cmd_tunnel_udp_config_port_id, 8277 NULL, 8278 }, 8279 }; 8280 8281 /* *** GLOBAL CONFIG *** */ 8282 struct cmd_global_config_result { 8283 cmdline_fixed_string_t cmd; 8284 portid_t port_id; 8285 cmdline_fixed_string_t cfg_type; 8286 uint8_t len; 8287 }; 8288 8289 static void 8290 cmd_global_config_parsed(void *parsed_result, 8291 __attribute__((unused)) struct cmdline *cl, 8292 __attribute__((unused)) void *data) 8293 { 8294 struct cmd_global_config_result *res = parsed_result; 8295 struct rte_eth_global_cfg conf; 8296 int ret; 8297 8298 memset(&conf, 0, sizeof(conf)); 8299 conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN; 8300 conf.cfg.gre_key_len = res->len; 8301 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE, 8302 RTE_ETH_FILTER_SET, &conf); 8303 if (ret != 0) 8304 printf("Global config error\n"); 8305 } 8306 8307 cmdline_parse_token_string_t cmd_global_config_cmd = 8308 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, 8309 "global_config"); 8310 cmdline_parse_token_num_t cmd_global_config_port_id = 8311 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, 8312 UINT16); 8313 cmdline_parse_token_string_t cmd_global_config_type = 8314 TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, 8315 cfg_type, "gre-key-len"); 8316 cmdline_parse_token_num_t cmd_global_config_gre_key_len = 8317 TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, 8318 len, UINT8); 8319 8320 cmdline_parse_inst_t cmd_global_config = { 8321 .f = cmd_global_config_parsed, 8322 .data = (void *)NULL, 8323 .help_str = "global_config <port_id> gre-key-len <key_len>", 8324 .tokens = { 8325 (void *)&cmd_global_config_cmd, 8326 (void *)&cmd_global_config_port_id, 8327 (void *)&cmd_global_config_type, 8328 (void *)&cmd_global_config_gre_key_len, 8329 NULL, 8330 }, 8331 }; 8332 8333 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ 8334 struct cmd_set_mirror_mask_result { 8335 cmdline_fixed_string_t set; 8336 cmdline_fixed_string_t port; 8337 portid_t port_id; 8338 cmdline_fixed_string_t mirror; 8339 uint8_t rule_id; 8340 cmdline_fixed_string_t what; 8341 cmdline_fixed_string_t value; 8342 cmdline_fixed_string_t dstpool; 8343 uint8_t dstpool_id; 8344 cmdline_fixed_string_t on; 8345 }; 8346 8347 cmdline_parse_token_string_t cmd_mirror_mask_set = 8348 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8349 set, "set"); 8350 cmdline_parse_token_string_t cmd_mirror_mask_port = 8351 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8352 port, "port"); 8353 cmdline_parse_token_num_t cmd_mirror_mask_portid = 8354 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8355 port_id, UINT16); 8356 cmdline_parse_token_string_t cmd_mirror_mask_mirror = 8357 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8358 mirror, "mirror-rule"); 8359 cmdline_parse_token_num_t cmd_mirror_mask_ruleid = 8360 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8361 rule_id, UINT8); 8362 cmdline_parse_token_string_t cmd_mirror_mask_what = 8363 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8364 what, "pool-mirror-up#pool-mirror-down" 8365 "#vlan-mirror"); 8366 cmdline_parse_token_string_t cmd_mirror_mask_value = 8367 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8368 value, NULL); 8369 cmdline_parse_token_string_t cmd_mirror_mask_dstpool = 8370 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8371 dstpool, "dst-pool"); 8372 cmdline_parse_token_num_t cmd_mirror_mask_poolid = 8373 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, 8374 dstpool_id, UINT8); 8375 cmdline_parse_token_string_t cmd_mirror_mask_on = 8376 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, 8377 on, "on#off"); 8378 8379 static void 8380 cmd_set_mirror_mask_parsed(void *parsed_result, 8381 __attribute__((unused)) struct cmdline *cl, 8382 __attribute__((unused)) void *data) 8383 { 8384 int ret,nb_item,i; 8385 struct cmd_set_mirror_mask_result *res = parsed_result; 8386 struct rte_eth_mirror_conf mr_conf; 8387 8388 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 8389 8390 unsigned int vlan_list[ETH_MIRROR_MAX_VLANS]; 8391 8392 mr_conf.dst_pool = res->dstpool_id; 8393 8394 if (!strcmp(res->what, "pool-mirror-up")) { 8395 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 8396 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP; 8397 } else if (!strcmp(res->what, "pool-mirror-down")) { 8398 mr_conf.pool_mask = strtoull(res->value, NULL, 16); 8399 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN; 8400 } else if (!strcmp(res->what, "vlan-mirror")) { 8401 mr_conf.rule_type = ETH_MIRROR_VLAN; 8402 nb_item = parse_item_list(res->value, "vlan", 8403 ETH_MIRROR_MAX_VLANS, vlan_list, 1); 8404 if (nb_item <= 0) 8405 return; 8406 8407 for (i = 0; i < nb_item; i++) { 8408 if (vlan_list[i] > ETHER_MAX_VLAN_ID) { 8409 printf("Invalid vlan_id: must be < 4096\n"); 8410 return; 8411 } 8412 8413 mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i]; 8414 mr_conf.vlan.vlan_mask |= 1ULL << i; 8415 } 8416 } 8417 8418 if (!strcmp(res->on, "on")) 8419 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8420 res->rule_id, 1); 8421 else 8422 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8423 res->rule_id, 0); 8424 if (ret < 0) 8425 printf("mirror rule add error: (%s)\n", strerror(-ret)); 8426 } 8427 8428 cmdline_parse_inst_t cmd_set_mirror_mask = { 8429 .f = cmd_set_mirror_mask_parsed, 8430 .data = NULL, 8431 .help_str = "set port <port_id> mirror-rule <rule_id> " 8432 "pool-mirror-up|pool-mirror-down|vlan-mirror " 8433 "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off", 8434 .tokens = { 8435 (void *)&cmd_mirror_mask_set, 8436 (void *)&cmd_mirror_mask_port, 8437 (void *)&cmd_mirror_mask_portid, 8438 (void *)&cmd_mirror_mask_mirror, 8439 (void *)&cmd_mirror_mask_ruleid, 8440 (void *)&cmd_mirror_mask_what, 8441 (void *)&cmd_mirror_mask_value, 8442 (void *)&cmd_mirror_mask_dstpool, 8443 (void *)&cmd_mirror_mask_poolid, 8444 (void *)&cmd_mirror_mask_on, 8445 NULL, 8446 }, 8447 }; 8448 8449 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */ 8450 struct cmd_set_mirror_link_result { 8451 cmdline_fixed_string_t set; 8452 cmdline_fixed_string_t port; 8453 portid_t port_id; 8454 cmdline_fixed_string_t mirror; 8455 uint8_t rule_id; 8456 cmdline_fixed_string_t what; 8457 cmdline_fixed_string_t dstpool; 8458 uint8_t dstpool_id; 8459 cmdline_fixed_string_t on; 8460 }; 8461 8462 cmdline_parse_token_string_t cmd_mirror_link_set = 8463 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8464 set, "set"); 8465 cmdline_parse_token_string_t cmd_mirror_link_port = 8466 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8467 port, "port"); 8468 cmdline_parse_token_num_t cmd_mirror_link_portid = 8469 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8470 port_id, UINT16); 8471 cmdline_parse_token_string_t cmd_mirror_link_mirror = 8472 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8473 mirror, "mirror-rule"); 8474 cmdline_parse_token_num_t cmd_mirror_link_ruleid = 8475 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8476 rule_id, UINT8); 8477 cmdline_parse_token_string_t cmd_mirror_link_what = 8478 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8479 what, "uplink-mirror#downlink-mirror"); 8480 cmdline_parse_token_string_t cmd_mirror_link_dstpool = 8481 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8482 dstpool, "dst-pool"); 8483 cmdline_parse_token_num_t cmd_mirror_link_poolid = 8484 TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, 8485 dstpool_id, UINT8); 8486 cmdline_parse_token_string_t cmd_mirror_link_on = 8487 TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, 8488 on, "on#off"); 8489 8490 static void 8491 cmd_set_mirror_link_parsed(void *parsed_result, 8492 __attribute__((unused)) struct cmdline *cl, 8493 __attribute__((unused)) void *data) 8494 { 8495 int ret; 8496 struct cmd_set_mirror_link_result *res = parsed_result; 8497 struct rte_eth_mirror_conf mr_conf; 8498 8499 memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf)); 8500 if (!strcmp(res->what, "uplink-mirror")) 8501 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT; 8502 else 8503 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT; 8504 8505 mr_conf.dst_pool = res->dstpool_id; 8506 8507 if (!strcmp(res->on, "on")) 8508 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8509 res->rule_id, 1); 8510 else 8511 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf, 8512 res->rule_id, 0); 8513 8514 /* check the return value and print it if is < 0 */ 8515 if (ret < 0) 8516 printf("mirror rule add error: (%s)\n", strerror(-ret)); 8517 8518 } 8519 8520 cmdline_parse_inst_t cmd_set_mirror_link = { 8521 .f = cmd_set_mirror_link_parsed, 8522 .data = NULL, 8523 .help_str = "set port <port_id> mirror-rule <rule_id> " 8524 "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off", 8525 .tokens = { 8526 (void *)&cmd_mirror_link_set, 8527 (void *)&cmd_mirror_link_port, 8528 (void *)&cmd_mirror_link_portid, 8529 (void *)&cmd_mirror_link_mirror, 8530 (void *)&cmd_mirror_link_ruleid, 8531 (void *)&cmd_mirror_link_what, 8532 (void *)&cmd_mirror_link_dstpool, 8533 (void *)&cmd_mirror_link_poolid, 8534 (void *)&cmd_mirror_link_on, 8535 NULL, 8536 }, 8537 }; 8538 8539 /* *** RESET VM MIRROR RULE *** */ 8540 struct cmd_rm_mirror_rule_result { 8541 cmdline_fixed_string_t reset; 8542 cmdline_fixed_string_t port; 8543 portid_t port_id; 8544 cmdline_fixed_string_t mirror; 8545 uint8_t rule_id; 8546 }; 8547 8548 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset = 8549 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8550 reset, "reset"); 8551 cmdline_parse_token_string_t cmd_rm_mirror_rule_port = 8552 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8553 port, "port"); 8554 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = 8555 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 8556 port_id, UINT16); 8557 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = 8558 TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, 8559 mirror, "mirror-rule"); 8560 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid = 8561 TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, 8562 rule_id, UINT8); 8563 8564 static void 8565 cmd_reset_mirror_rule_parsed(void *parsed_result, 8566 __attribute__((unused)) struct cmdline *cl, 8567 __attribute__((unused)) void *data) 8568 { 8569 int ret; 8570 struct cmd_set_mirror_link_result *res = parsed_result; 8571 /* check rule_id */ 8572 ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id); 8573 if(ret < 0) 8574 printf("mirror rule remove error: (%s)\n", strerror(-ret)); 8575 } 8576 8577 cmdline_parse_inst_t cmd_reset_mirror_rule = { 8578 .f = cmd_reset_mirror_rule_parsed, 8579 .data = NULL, 8580 .help_str = "reset port <port_id> mirror-rule <rule_id>", 8581 .tokens = { 8582 (void *)&cmd_rm_mirror_rule_reset, 8583 (void *)&cmd_rm_mirror_rule_port, 8584 (void *)&cmd_rm_mirror_rule_portid, 8585 (void *)&cmd_rm_mirror_rule_mirror, 8586 (void *)&cmd_rm_mirror_rule_ruleid, 8587 NULL, 8588 }, 8589 }; 8590 8591 /* ******************************************************************************** */ 8592 8593 struct cmd_dump_result { 8594 cmdline_fixed_string_t dump; 8595 }; 8596 8597 static void 8598 dump_struct_sizes(void) 8599 { 8600 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t)); 8601 DUMP_SIZE(struct rte_mbuf); 8602 DUMP_SIZE(struct rte_mempool); 8603 DUMP_SIZE(struct rte_ring); 8604 #undef DUMP_SIZE 8605 } 8606 8607 static void cmd_dump_parsed(void *parsed_result, 8608 __attribute__((unused)) struct cmdline *cl, 8609 __attribute__((unused)) void *data) 8610 { 8611 struct cmd_dump_result *res = parsed_result; 8612 8613 if (!strcmp(res->dump, "dump_physmem")) 8614 rte_dump_physmem_layout(stdout); 8615 else if (!strcmp(res->dump, "dump_memzone")) 8616 rte_memzone_dump(stdout); 8617 else if (!strcmp(res->dump, "dump_struct_sizes")) 8618 dump_struct_sizes(); 8619 else if (!strcmp(res->dump, "dump_ring")) 8620 rte_ring_list_dump(stdout); 8621 else if (!strcmp(res->dump, "dump_mempool")) 8622 rte_mempool_list_dump(stdout); 8623 else if (!strcmp(res->dump, "dump_devargs")) 8624 rte_eal_devargs_dump(stdout); 8625 else if (!strcmp(res->dump, "dump_log_types")) 8626 rte_log_dump(stdout); 8627 } 8628 8629 cmdline_parse_token_string_t cmd_dump_dump = 8630 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump, 8631 "dump_physmem#" 8632 "dump_memzone#" 8633 "dump_struct_sizes#" 8634 "dump_ring#" 8635 "dump_mempool#" 8636 "dump_devargs#" 8637 "dump_log_types"); 8638 8639 cmdline_parse_inst_t cmd_dump = { 8640 .f = cmd_dump_parsed, /* function to call */ 8641 .data = NULL, /* 2nd arg of func */ 8642 .help_str = "Dump status", 8643 .tokens = { /* token list, NULL terminated */ 8644 (void *)&cmd_dump_dump, 8645 NULL, 8646 }, 8647 }; 8648 8649 /* ******************************************************************************** */ 8650 8651 struct cmd_dump_one_result { 8652 cmdline_fixed_string_t dump; 8653 cmdline_fixed_string_t name; 8654 }; 8655 8656 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, 8657 __attribute__((unused)) void *data) 8658 { 8659 struct cmd_dump_one_result *res = parsed_result; 8660 8661 if (!strcmp(res->dump, "dump_ring")) { 8662 struct rte_ring *r; 8663 r = rte_ring_lookup(res->name); 8664 if (r == NULL) { 8665 cmdline_printf(cl, "Cannot find ring\n"); 8666 return; 8667 } 8668 rte_ring_dump(stdout, r); 8669 } else if (!strcmp(res->dump, "dump_mempool")) { 8670 struct rte_mempool *mp; 8671 mp = rte_mempool_lookup(res->name); 8672 if (mp == NULL) { 8673 cmdline_printf(cl, "Cannot find mempool\n"); 8674 return; 8675 } 8676 rte_mempool_dump(stdout, mp); 8677 } 8678 } 8679 8680 cmdline_parse_token_string_t cmd_dump_one_dump = 8681 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump, 8682 "dump_ring#dump_mempool"); 8683 8684 cmdline_parse_token_string_t cmd_dump_one_name = 8685 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL); 8686 8687 cmdline_parse_inst_t cmd_dump_one = { 8688 .f = cmd_dump_one_parsed, /* function to call */ 8689 .data = NULL, /* 2nd arg of func */ 8690 .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool", 8691 .tokens = { /* token list, NULL terminated */ 8692 (void *)&cmd_dump_one_dump, 8693 (void *)&cmd_dump_one_name, 8694 NULL, 8695 }, 8696 }; 8697 8698 /* *** Add/Del syn filter *** */ 8699 struct cmd_syn_filter_result { 8700 cmdline_fixed_string_t filter; 8701 portid_t port_id; 8702 cmdline_fixed_string_t ops; 8703 cmdline_fixed_string_t priority; 8704 cmdline_fixed_string_t high; 8705 cmdline_fixed_string_t queue; 8706 uint16_t queue_id; 8707 }; 8708 8709 static void 8710 cmd_syn_filter_parsed(void *parsed_result, 8711 __attribute__((unused)) struct cmdline *cl, 8712 __attribute__((unused)) void *data) 8713 { 8714 struct cmd_syn_filter_result *res = parsed_result; 8715 struct rte_eth_syn_filter syn_filter; 8716 int ret = 0; 8717 8718 ret = rte_eth_dev_filter_supported(res->port_id, 8719 RTE_ETH_FILTER_SYN); 8720 if (ret < 0) { 8721 printf("syn filter is not supported on port %u.\n", 8722 res->port_id); 8723 return; 8724 } 8725 8726 memset(&syn_filter, 0, sizeof(syn_filter)); 8727 8728 if (!strcmp(res->ops, "add")) { 8729 if (!strcmp(res->high, "high")) 8730 syn_filter.hig_pri = 1; 8731 else 8732 syn_filter.hig_pri = 0; 8733 8734 syn_filter.queue = res->queue_id; 8735 ret = rte_eth_dev_filter_ctrl(res->port_id, 8736 RTE_ETH_FILTER_SYN, 8737 RTE_ETH_FILTER_ADD, 8738 &syn_filter); 8739 } else 8740 ret = rte_eth_dev_filter_ctrl(res->port_id, 8741 RTE_ETH_FILTER_SYN, 8742 RTE_ETH_FILTER_DELETE, 8743 &syn_filter); 8744 8745 if (ret < 0) 8746 printf("syn filter programming error: (%s)\n", 8747 strerror(-ret)); 8748 } 8749 8750 cmdline_parse_token_string_t cmd_syn_filter_filter = 8751 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8752 filter, "syn_filter"); 8753 cmdline_parse_token_num_t cmd_syn_filter_port_id = 8754 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8755 port_id, UINT16); 8756 cmdline_parse_token_string_t cmd_syn_filter_ops = 8757 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8758 ops, "add#del"); 8759 cmdline_parse_token_string_t cmd_syn_filter_priority = 8760 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8761 priority, "priority"); 8762 cmdline_parse_token_string_t cmd_syn_filter_high = 8763 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8764 high, "high#low"); 8765 cmdline_parse_token_string_t cmd_syn_filter_queue = 8766 TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, 8767 queue, "queue"); 8768 cmdline_parse_token_num_t cmd_syn_filter_queue_id = 8769 TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, 8770 queue_id, UINT16); 8771 8772 cmdline_parse_inst_t cmd_syn_filter = { 8773 .f = cmd_syn_filter_parsed, 8774 .data = NULL, 8775 .help_str = "syn_filter <port_id> add|del priority high|low queue " 8776 "<queue_id>: Add/Delete syn filter", 8777 .tokens = { 8778 (void *)&cmd_syn_filter_filter, 8779 (void *)&cmd_syn_filter_port_id, 8780 (void *)&cmd_syn_filter_ops, 8781 (void *)&cmd_syn_filter_priority, 8782 (void *)&cmd_syn_filter_high, 8783 (void *)&cmd_syn_filter_queue, 8784 (void *)&cmd_syn_filter_queue_id, 8785 NULL, 8786 }, 8787 }; 8788 8789 /* *** queue region set *** */ 8790 struct cmd_queue_region_result { 8791 cmdline_fixed_string_t set; 8792 cmdline_fixed_string_t port; 8793 portid_t port_id; 8794 cmdline_fixed_string_t cmd; 8795 cmdline_fixed_string_t region; 8796 uint8_t region_id; 8797 cmdline_fixed_string_t queue_start_index; 8798 uint8_t queue_id; 8799 cmdline_fixed_string_t queue_num; 8800 uint8_t queue_num_value; 8801 }; 8802 8803 static void 8804 cmd_queue_region_parsed(void *parsed_result, 8805 __attribute__((unused)) struct cmdline *cl, 8806 __attribute__((unused)) void *data) 8807 { 8808 struct cmd_queue_region_result *res = parsed_result; 8809 int ret = -ENOTSUP; 8810 #ifdef RTE_LIBRTE_I40E_PMD 8811 struct rte_pmd_i40e_queue_region_conf region_conf; 8812 enum rte_pmd_i40e_queue_region_op op_type; 8813 #endif 8814 8815 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8816 return; 8817 8818 #ifdef RTE_LIBRTE_I40E_PMD 8819 memset(®ion_conf, 0, sizeof(region_conf)); 8820 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET; 8821 region_conf.region_id = res->region_id; 8822 region_conf.queue_num = res->queue_num_value; 8823 region_conf.queue_start_index = res->queue_id; 8824 8825 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8826 op_type, ®ion_conf); 8827 #endif 8828 8829 switch (ret) { 8830 case 0: 8831 break; 8832 case -ENOTSUP: 8833 printf("function not implemented or supported\n"); 8834 break; 8835 default: 8836 printf("queue region config error: (%s)\n", strerror(-ret)); 8837 } 8838 } 8839 8840 cmdline_parse_token_string_t cmd_queue_region_set = 8841 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8842 set, "set"); 8843 cmdline_parse_token_string_t cmd_queue_region_port = 8844 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port"); 8845 cmdline_parse_token_num_t cmd_queue_region_port_id = 8846 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8847 port_id, UINT16); 8848 cmdline_parse_token_string_t cmd_queue_region_cmd = 8849 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8850 cmd, "queue-region"); 8851 cmdline_parse_token_string_t cmd_queue_region_id = 8852 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8853 region, "region_id"); 8854 cmdline_parse_token_num_t cmd_queue_region_index = 8855 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8856 region_id, UINT8); 8857 cmdline_parse_token_string_t cmd_queue_region_queue_start_index = 8858 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8859 queue_start_index, "queue_start_index"); 8860 cmdline_parse_token_num_t cmd_queue_region_queue_id = 8861 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8862 queue_id, UINT8); 8863 cmdline_parse_token_string_t cmd_queue_region_queue_num = 8864 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, 8865 queue_num, "queue_num"); 8866 cmdline_parse_token_num_t cmd_queue_region_queue_num_value = 8867 TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, 8868 queue_num_value, UINT8); 8869 8870 cmdline_parse_inst_t cmd_queue_region = { 8871 .f = cmd_queue_region_parsed, 8872 .data = NULL, 8873 .help_str = "set port <port_id> queue-region region_id <value> " 8874 "queue_start_index <value> queue_num <value>: Set a queue region", 8875 .tokens = { 8876 (void *)&cmd_queue_region_set, 8877 (void *)&cmd_queue_region_port, 8878 (void *)&cmd_queue_region_port_id, 8879 (void *)&cmd_queue_region_cmd, 8880 (void *)&cmd_queue_region_id, 8881 (void *)&cmd_queue_region_index, 8882 (void *)&cmd_queue_region_queue_start_index, 8883 (void *)&cmd_queue_region_queue_id, 8884 (void *)&cmd_queue_region_queue_num, 8885 (void *)&cmd_queue_region_queue_num_value, 8886 NULL, 8887 }, 8888 }; 8889 8890 /* *** queue region and flowtype set *** */ 8891 struct cmd_region_flowtype_result { 8892 cmdline_fixed_string_t set; 8893 cmdline_fixed_string_t port; 8894 portid_t port_id; 8895 cmdline_fixed_string_t cmd; 8896 cmdline_fixed_string_t region; 8897 uint8_t region_id; 8898 cmdline_fixed_string_t flowtype; 8899 uint8_t flowtype_id; 8900 }; 8901 8902 static void 8903 cmd_region_flowtype_parsed(void *parsed_result, 8904 __attribute__((unused)) struct cmdline *cl, 8905 __attribute__((unused)) void *data) 8906 { 8907 struct cmd_region_flowtype_result *res = parsed_result; 8908 int ret = -ENOTSUP; 8909 #ifdef RTE_LIBRTE_I40E_PMD 8910 struct rte_pmd_i40e_queue_region_conf region_conf; 8911 enum rte_pmd_i40e_queue_region_op op_type; 8912 #endif 8913 8914 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 8915 return; 8916 8917 #ifdef RTE_LIBRTE_I40E_PMD 8918 memset(®ion_conf, 0, sizeof(region_conf)); 8919 8920 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET; 8921 region_conf.region_id = res->region_id; 8922 region_conf.hw_flowtype = res->flowtype_id; 8923 8924 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 8925 op_type, ®ion_conf); 8926 #endif 8927 8928 switch (ret) { 8929 case 0: 8930 break; 8931 case -ENOTSUP: 8932 printf("function not implemented or supported\n"); 8933 break; 8934 default: 8935 printf("region flowtype config error: (%s)\n", strerror(-ret)); 8936 } 8937 } 8938 8939 cmdline_parse_token_string_t cmd_region_flowtype_set = 8940 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8941 set, "set"); 8942 cmdline_parse_token_string_t cmd_region_flowtype_port = 8943 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8944 port, "port"); 8945 cmdline_parse_token_num_t cmd_region_flowtype_port_index = 8946 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8947 port_id, UINT16); 8948 cmdline_parse_token_string_t cmd_region_flowtype_cmd = 8949 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8950 cmd, "queue-region"); 8951 cmdline_parse_token_string_t cmd_region_flowtype_index = 8952 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8953 region, "region_id"); 8954 cmdline_parse_token_num_t cmd_region_flowtype_id = 8955 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8956 region_id, UINT8); 8957 cmdline_parse_token_string_t cmd_region_flowtype_flow_index = 8958 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, 8959 flowtype, "flowtype"); 8960 cmdline_parse_token_num_t cmd_region_flowtype_flow_id = 8961 TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, 8962 flowtype_id, UINT8); 8963 cmdline_parse_inst_t cmd_region_flowtype = { 8964 .f = cmd_region_flowtype_parsed, 8965 .data = NULL, 8966 .help_str = "set port <port_id> queue-region region_id <value> " 8967 "flowtype <value>: Set a flowtype region index", 8968 .tokens = { 8969 (void *)&cmd_region_flowtype_set, 8970 (void *)&cmd_region_flowtype_port, 8971 (void *)&cmd_region_flowtype_port_index, 8972 (void *)&cmd_region_flowtype_cmd, 8973 (void *)&cmd_region_flowtype_index, 8974 (void *)&cmd_region_flowtype_id, 8975 (void *)&cmd_region_flowtype_flow_index, 8976 (void *)&cmd_region_flowtype_flow_id, 8977 NULL, 8978 }, 8979 }; 8980 8981 /* *** User Priority (UP) to queue region (region_id) set *** */ 8982 struct cmd_user_priority_region_result { 8983 cmdline_fixed_string_t set; 8984 cmdline_fixed_string_t port; 8985 portid_t port_id; 8986 cmdline_fixed_string_t cmd; 8987 cmdline_fixed_string_t user_priority; 8988 uint8_t user_priority_id; 8989 cmdline_fixed_string_t region; 8990 uint8_t region_id; 8991 }; 8992 8993 static void 8994 cmd_user_priority_region_parsed(void *parsed_result, 8995 __attribute__((unused)) struct cmdline *cl, 8996 __attribute__((unused)) void *data) 8997 { 8998 struct cmd_user_priority_region_result *res = parsed_result; 8999 int ret = -ENOTSUP; 9000 #ifdef RTE_LIBRTE_I40E_PMD 9001 struct rte_pmd_i40e_queue_region_conf region_conf; 9002 enum rte_pmd_i40e_queue_region_op op_type; 9003 #endif 9004 9005 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9006 return; 9007 9008 #ifdef RTE_LIBRTE_I40E_PMD 9009 memset(®ion_conf, 0, sizeof(region_conf)); 9010 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET; 9011 region_conf.user_priority = res->user_priority_id; 9012 region_conf.region_id = res->region_id; 9013 9014 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 9015 op_type, ®ion_conf); 9016 #endif 9017 9018 switch (ret) { 9019 case 0: 9020 break; 9021 case -ENOTSUP: 9022 printf("function not implemented or supported\n"); 9023 break; 9024 default: 9025 printf("user_priority region config error: (%s)\n", 9026 strerror(-ret)); 9027 } 9028 } 9029 9030 cmdline_parse_token_string_t cmd_user_priority_region_set = 9031 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 9032 set, "set"); 9033 cmdline_parse_token_string_t cmd_user_priority_region_port = 9034 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 9035 port, "port"); 9036 cmdline_parse_token_num_t cmd_user_priority_region_port_index = 9037 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 9038 port_id, UINT16); 9039 cmdline_parse_token_string_t cmd_user_priority_region_cmd = 9040 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 9041 cmd, "queue-region"); 9042 cmdline_parse_token_string_t cmd_user_priority_region_UP = 9043 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 9044 user_priority, "UP"); 9045 cmdline_parse_token_num_t cmd_user_priority_region_UP_id = 9046 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 9047 user_priority_id, UINT8); 9048 cmdline_parse_token_string_t cmd_user_priority_region_region = 9049 TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, 9050 region, "region_id"); 9051 cmdline_parse_token_num_t cmd_user_priority_region_region_id = 9052 TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, 9053 region_id, UINT8); 9054 9055 cmdline_parse_inst_t cmd_user_priority_region = { 9056 .f = cmd_user_priority_region_parsed, 9057 .data = NULL, 9058 .help_str = "set port <port_id> queue-region UP <value> " 9059 "region_id <value>: Set the mapping of User Priority (UP) " 9060 "to queue region (region_id) ", 9061 .tokens = { 9062 (void *)&cmd_user_priority_region_set, 9063 (void *)&cmd_user_priority_region_port, 9064 (void *)&cmd_user_priority_region_port_index, 9065 (void *)&cmd_user_priority_region_cmd, 9066 (void *)&cmd_user_priority_region_UP, 9067 (void *)&cmd_user_priority_region_UP_id, 9068 (void *)&cmd_user_priority_region_region, 9069 (void *)&cmd_user_priority_region_region_id, 9070 NULL, 9071 }, 9072 }; 9073 9074 /* *** flush all queue region related configuration *** */ 9075 struct cmd_flush_queue_region_result { 9076 cmdline_fixed_string_t set; 9077 cmdline_fixed_string_t port; 9078 portid_t port_id; 9079 cmdline_fixed_string_t cmd; 9080 cmdline_fixed_string_t flush; 9081 cmdline_fixed_string_t what; 9082 }; 9083 9084 static void 9085 cmd_flush_queue_region_parsed(void *parsed_result, 9086 __attribute__((unused)) struct cmdline *cl, 9087 __attribute__((unused)) void *data) 9088 { 9089 struct cmd_flush_queue_region_result *res = parsed_result; 9090 int ret = -ENOTSUP; 9091 #ifdef RTE_LIBRTE_I40E_PMD 9092 struct rte_pmd_i40e_queue_region_conf region_conf; 9093 enum rte_pmd_i40e_queue_region_op op_type; 9094 #endif 9095 9096 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9097 return; 9098 9099 #ifdef RTE_LIBRTE_I40E_PMD 9100 memset(®ion_conf, 0, sizeof(region_conf)); 9101 9102 if (strcmp(res->what, "on") == 0) 9103 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON; 9104 else 9105 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF; 9106 9107 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 9108 op_type, ®ion_conf); 9109 #endif 9110 9111 switch (ret) { 9112 case 0: 9113 break; 9114 case -ENOTSUP: 9115 printf("function not implemented or supported\n"); 9116 break; 9117 default: 9118 printf("queue region config flush error: (%s)\n", 9119 strerror(-ret)); 9120 } 9121 } 9122 9123 cmdline_parse_token_string_t cmd_flush_queue_region_set = 9124 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 9125 set, "set"); 9126 cmdline_parse_token_string_t cmd_flush_queue_region_port = 9127 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 9128 port, "port"); 9129 cmdline_parse_token_num_t cmd_flush_queue_region_port_index = 9130 TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result, 9131 port_id, UINT16); 9132 cmdline_parse_token_string_t cmd_flush_queue_region_cmd = 9133 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 9134 cmd, "queue-region"); 9135 cmdline_parse_token_string_t cmd_flush_queue_region_flush = 9136 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 9137 flush, "flush"); 9138 cmdline_parse_token_string_t cmd_flush_queue_region_what = 9139 TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, 9140 what, "on#off"); 9141 9142 cmdline_parse_inst_t cmd_flush_queue_region = { 9143 .f = cmd_flush_queue_region_parsed, 9144 .data = NULL, 9145 .help_str = "set port <port_id> queue-region flush on|off" 9146 ": flush all queue region related configuration", 9147 .tokens = { 9148 (void *)&cmd_flush_queue_region_set, 9149 (void *)&cmd_flush_queue_region_port, 9150 (void *)&cmd_flush_queue_region_port_index, 9151 (void *)&cmd_flush_queue_region_cmd, 9152 (void *)&cmd_flush_queue_region_flush, 9153 (void *)&cmd_flush_queue_region_what, 9154 NULL, 9155 }, 9156 }; 9157 9158 /* *** get all queue region related configuration info *** */ 9159 struct cmd_show_queue_region_info { 9160 cmdline_fixed_string_t show; 9161 cmdline_fixed_string_t port; 9162 portid_t port_id; 9163 cmdline_fixed_string_t cmd; 9164 }; 9165 9166 static void 9167 cmd_show_queue_region_info_parsed(void *parsed_result, 9168 __attribute__((unused)) struct cmdline *cl, 9169 __attribute__((unused)) void *data) 9170 { 9171 struct cmd_show_queue_region_info *res = parsed_result; 9172 int ret = -ENOTSUP; 9173 #ifdef RTE_LIBRTE_I40E_PMD 9174 struct rte_pmd_i40e_queue_regions rte_pmd_regions; 9175 enum rte_pmd_i40e_queue_region_op op_type; 9176 #endif 9177 9178 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 9179 return; 9180 9181 #ifdef RTE_LIBRTE_I40E_PMD 9182 memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions)); 9183 9184 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET; 9185 9186 ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, 9187 op_type, &rte_pmd_regions); 9188 9189 port_queue_region_info_display(res->port_id, &rte_pmd_regions); 9190 #endif 9191 9192 switch (ret) { 9193 case 0: 9194 break; 9195 case -ENOTSUP: 9196 printf("function not implemented or supported\n"); 9197 break; 9198 default: 9199 printf("queue region config info show error: (%s)\n", 9200 strerror(-ret)); 9201 } 9202 } 9203 9204 cmdline_parse_token_string_t cmd_show_queue_region_info_get = 9205 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 9206 show, "show"); 9207 cmdline_parse_token_string_t cmd_show_queue_region_info_port = 9208 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 9209 port, "port"); 9210 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index = 9211 TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info, 9212 port_id, UINT16); 9213 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd = 9214 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, 9215 cmd, "queue-region"); 9216 9217 cmdline_parse_inst_t cmd_show_queue_region_info_all = { 9218 .f = cmd_show_queue_region_info_parsed, 9219 .data = NULL, 9220 .help_str = "show port <port_id> queue-region" 9221 ": show all queue region related configuration info", 9222 .tokens = { 9223 (void *)&cmd_show_queue_region_info_get, 9224 (void *)&cmd_show_queue_region_info_port, 9225 (void *)&cmd_show_queue_region_info_port_index, 9226 (void *)&cmd_show_queue_region_info_cmd, 9227 NULL, 9228 }, 9229 }; 9230 9231 /* *** ADD/REMOVE A 2tuple FILTER *** */ 9232 struct cmd_2tuple_filter_result { 9233 cmdline_fixed_string_t filter; 9234 portid_t port_id; 9235 cmdline_fixed_string_t ops; 9236 cmdline_fixed_string_t dst_port; 9237 uint16_t dst_port_value; 9238 cmdline_fixed_string_t protocol; 9239 uint8_t protocol_value; 9240 cmdline_fixed_string_t mask; 9241 uint8_t mask_value; 9242 cmdline_fixed_string_t tcp_flags; 9243 uint8_t tcp_flags_value; 9244 cmdline_fixed_string_t priority; 9245 uint8_t priority_value; 9246 cmdline_fixed_string_t queue; 9247 uint16_t queue_id; 9248 }; 9249 9250 static void 9251 cmd_2tuple_filter_parsed(void *parsed_result, 9252 __attribute__((unused)) struct cmdline *cl, 9253 __attribute__((unused)) void *data) 9254 { 9255 struct rte_eth_ntuple_filter filter; 9256 struct cmd_2tuple_filter_result *res = parsed_result; 9257 int ret = 0; 9258 9259 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 9260 if (ret < 0) { 9261 printf("ntuple filter is not supported on port %u.\n", 9262 res->port_id); 9263 return; 9264 } 9265 9266 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 9267 9268 filter.flags = RTE_2TUPLE_FLAGS; 9269 filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 9270 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 9271 filter.proto = res->protocol_value; 9272 filter.priority = res->priority_value; 9273 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 9274 printf("nonzero tcp_flags is only meaningful" 9275 " when protocol is TCP.\n"); 9276 return; 9277 } 9278 if (res->tcp_flags_value > TCP_FLAG_ALL) { 9279 printf("invalid TCP flags.\n"); 9280 return; 9281 } 9282 9283 if (res->tcp_flags_value != 0) { 9284 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 9285 filter.tcp_flags = res->tcp_flags_value; 9286 } 9287 9288 /* need convert to big endian. */ 9289 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 9290 filter.queue = res->queue_id; 9291 9292 if (!strcmp(res->ops, "add")) 9293 ret = rte_eth_dev_filter_ctrl(res->port_id, 9294 RTE_ETH_FILTER_NTUPLE, 9295 RTE_ETH_FILTER_ADD, 9296 &filter); 9297 else 9298 ret = rte_eth_dev_filter_ctrl(res->port_id, 9299 RTE_ETH_FILTER_NTUPLE, 9300 RTE_ETH_FILTER_DELETE, 9301 &filter); 9302 if (ret < 0) 9303 printf("2tuple filter programming error: (%s)\n", 9304 strerror(-ret)); 9305 9306 } 9307 9308 cmdline_parse_token_string_t cmd_2tuple_filter_filter = 9309 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9310 filter, "2tuple_filter"); 9311 cmdline_parse_token_num_t cmd_2tuple_filter_port_id = 9312 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9313 port_id, UINT16); 9314 cmdline_parse_token_string_t cmd_2tuple_filter_ops = 9315 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9316 ops, "add#del"); 9317 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port = 9318 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9319 dst_port, "dst_port"); 9320 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value = 9321 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9322 dst_port_value, UINT16); 9323 cmdline_parse_token_string_t cmd_2tuple_filter_protocol = 9324 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9325 protocol, "protocol"); 9326 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value = 9327 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9328 protocol_value, UINT8); 9329 cmdline_parse_token_string_t cmd_2tuple_filter_mask = 9330 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9331 mask, "mask"); 9332 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value = 9333 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9334 mask_value, INT8); 9335 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags = 9336 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9337 tcp_flags, "tcp_flags"); 9338 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value = 9339 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9340 tcp_flags_value, UINT8); 9341 cmdline_parse_token_string_t cmd_2tuple_filter_priority = 9342 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9343 priority, "priority"); 9344 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value = 9345 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9346 priority_value, UINT8); 9347 cmdline_parse_token_string_t cmd_2tuple_filter_queue = 9348 TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, 9349 queue, "queue"); 9350 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id = 9351 TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, 9352 queue_id, UINT16); 9353 9354 cmdline_parse_inst_t cmd_2tuple_filter = { 9355 .f = cmd_2tuple_filter_parsed, 9356 .data = NULL, 9357 .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol " 9358 "<value> mask <value> tcp_flags <value> priority <value> queue " 9359 "<queue_id>: Add a 2tuple filter", 9360 .tokens = { 9361 (void *)&cmd_2tuple_filter_filter, 9362 (void *)&cmd_2tuple_filter_port_id, 9363 (void *)&cmd_2tuple_filter_ops, 9364 (void *)&cmd_2tuple_filter_dst_port, 9365 (void *)&cmd_2tuple_filter_dst_port_value, 9366 (void *)&cmd_2tuple_filter_protocol, 9367 (void *)&cmd_2tuple_filter_protocol_value, 9368 (void *)&cmd_2tuple_filter_mask, 9369 (void *)&cmd_2tuple_filter_mask_value, 9370 (void *)&cmd_2tuple_filter_tcp_flags, 9371 (void *)&cmd_2tuple_filter_tcp_flags_value, 9372 (void *)&cmd_2tuple_filter_priority, 9373 (void *)&cmd_2tuple_filter_priority_value, 9374 (void *)&cmd_2tuple_filter_queue, 9375 (void *)&cmd_2tuple_filter_queue_id, 9376 NULL, 9377 }, 9378 }; 9379 9380 /* *** ADD/REMOVE A 5tuple FILTER *** */ 9381 struct cmd_5tuple_filter_result { 9382 cmdline_fixed_string_t filter; 9383 portid_t port_id; 9384 cmdline_fixed_string_t ops; 9385 cmdline_fixed_string_t dst_ip; 9386 cmdline_ipaddr_t dst_ip_value; 9387 cmdline_fixed_string_t src_ip; 9388 cmdline_ipaddr_t src_ip_value; 9389 cmdline_fixed_string_t dst_port; 9390 uint16_t dst_port_value; 9391 cmdline_fixed_string_t src_port; 9392 uint16_t src_port_value; 9393 cmdline_fixed_string_t protocol; 9394 uint8_t protocol_value; 9395 cmdline_fixed_string_t mask; 9396 uint8_t mask_value; 9397 cmdline_fixed_string_t tcp_flags; 9398 uint8_t tcp_flags_value; 9399 cmdline_fixed_string_t priority; 9400 uint8_t priority_value; 9401 cmdline_fixed_string_t queue; 9402 uint16_t queue_id; 9403 }; 9404 9405 static void 9406 cmd_5tuple_filter_parsed(void *parsed_result, 9407 __attribute__((unused)) struct cmdline *cl, 9408 __attribute__((unused)) void *data) 9409 { 9410 struct rte_eth_ntuple_filter filter; 9411 struct cmd_5tuple_filter_result *res = parsed_result; 9412 int ret = 0; 9413 9414 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE); 9415 if (ret < 0) { 9416 printf("ntuple filter is not supported on port %u.\n", 9417 res->port_id); 9418 return; 9419 } 9420 9421 memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter)); 9422 9423 filter.flags = RTE_5TUPLE_FLAGS; 9424 filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0; 9425 filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0; 9426 filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0; 9427 filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0; 9428 filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0; 9429 filter.proto = res->protocol_value; 9430 filter.priority = res->priority_value; 9431 if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) { 9432 printf("nonzero tcp_flags is only meaningful" 9433 " when protocol is TCP.\n"); 9434 return; 9435 } 9436 if (res->tcp_flags_value > TCP_FLAG_ALL) { 9437 printf("invalid TCP flags.\n"); 9438 return; 9439 } 9440 9441 if (res->tcp_flags_value != 0) { 9442 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG; 9443 filter.tcp_flags = res->tcp_flags_value; 9444 } 9445 9446 if (res->dst_ip_value.family == AF_INET) 9447 /* no need to convert, already big endian. */ 9448 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr; 9449 else { 9450 if (filter.dst_ip_mask == 0) { 9451 printf("can not support ipv6 involved compare.\n"); 9452 return; 9453 } 9454 filter.dst_ip = 0; 9455 } 9456 9457 if (res->src_ip_value.family == AF_INET) 9458 /* no need to convert, already big endian. */ 9459 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr; 9460 else { 9461 if (filter.src_ip_mask == 0) { 9462 printf("can not support ipv6 involved compare.\n"); 9463 return; 9464 } 9465 filter.src_ip = 0; 9466 } 9467 /* need convert to big endian. */ 9468 filter.dst_port = rte_cpu_to_be_16(res->dst_port_value); 9469 filter.src_port = rte_cpu_to_be_16(res->src_port_value); 9470 filter.queue = res->queue_id; 9471 9472 if (!strcmp(res->ops, "add")) 9473 ret = rte_eth_dev_filter_ctrl(res->port_id, 9474 RTE_ETH_FILTER_NTUPLE, 9475 RTE_ETH_FILTER_ADD, 9476 &filter); 9477 else 9478 ret = rte_eth_dev_filter_ctrl(res->port_id, 9479 RTE_ETH_FILTER_NTUPLE, 9480 RTE_ETH_FILTER_DELETE, 9481 &filter); 9482 if (ret < 0) 9483 printf("5tuple filter programming error: (%s)\n", 9484 strerror(-ret)); 9485 } 9486 9487 cmdline_parse_token_string_t cmd_5tuple_filter_filter = 9488 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9489 filter, "5tuple_filter"); 9490 cmdline_parse_token_num_t cmd_5tuple_filter_port_id = 9491 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9492 port_id, UINT16); 9493 cmdline_parse_token_string_t cmd_5tuple_filter_ops = 9494 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9495 ops, "add#del"); 9496 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip = 9497 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9498 dst_ip, "dst_ip"); 9499 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value = 9500 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 9501 dst_ip_value); 9502 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip = 9503 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9504 src_ip, "src_ip"); 9505 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value = 9506 TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result, 9507 src_ip_value); 9508 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port = 9509 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9510 dst_port, "dst_port"); 9511 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value = 9512 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9513 dst_port_value, UINT16); 9514 cmdline_parse_token_string_t cmd_5tuple_filter_src_port = 9515 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9516 src_port, "src_port"); 9517 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value = 9518 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9519 src_port_value, UINT16); 9520 cmdline_parse_token_string_t cmd_5tuple_filter_protocol = 9521 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9522 protocol, "protocol"); 9523 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value = 9524 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9525 protocol_value, UINT8); 9526 cmdline_parse_token_string_t cmd_5tuple_filter_mask = 9527 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9528 mask, "mask"); 9529 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value = 9530 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9531 mask_value, INT8); 9532 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags = 9533 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9534 tcp_flags, "tcp_flags"); 9535 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value = 9536 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9537 tcp_flags_value, UINT8); 9538 cmdline_parse_token_string_t cmd_5tuple_filter_priority = 9539 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9540 priority, "priority"); 9541 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value = 9542 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9543 priority_value, UINT8); 9544 cmdline_parse_token_string_t cmd_5tuple_filter_queue = 9545 TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, 9546 queue, "queue"); 9547 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id = 9548 TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, 9549 queue_id, UINT16); 9550 9551 cmdline_parse_inst_t cmd_5tuple_filter = { 9552 .f = cmd_5tuple_filter_parsed, 9553 .data = NULL, 9554 .help_str = "5tuple_filter <port_id> add|del dst_ip <value> " 9555 "src_ip <value> dst_port <value> src_port <value> " 9556 "protocol <value> mask <value> tcp_flags <value> " 9557 "priority <value> queue <queue_id>: Add/Del a 5tuple filter", 9558 .tokens = { 9559 (void *)&cmd_5tuple_filter_filter, 9560 (void *)&cmd_5tuple_filter_port_id, 9561 (void *)&cmd_5tuple_filter_ops, 9562 (void *)&cmd_5tuple_filter_dst_ip, 9563 (void *)&cmd_5tuple_filter_dst_ip_value, 9564 (void *)&cmd_5tuple_filter_src_ip, 9565 (void *)&cmd_5tuple_filter_src_ip_value, 9566 (void *)&cmd_5tuple_filter_dst_port, 9567 (void *)&cmd_5tuple_filter_dst_port_value, 9568 (void *)&cmd_5tuple_filter_src_port, 9569 (void *)&cmd_5tuple_filter_src_port_value, 9570 (void *)&cmd_5tuple_filter_protocol, 9571 (void *)&cmd_5tuple_filter_protocol_value, 9572 (void *)&cmd_5tuple_filter_mask, 9573 (void *)&cmd_5tuple_filter_mask_value, 9574 (void *)&cmd_5tuple_filter_tcp_flags, 9575 (void *)&cmd_5tuple_filter_tcp_flags_value, 9576 (void *)&cmd_5tuple_filter_priority, 9577 (void *)&cmd_5tuple_filter_priority_value, 9578 (void *)&cmd_5tuple_filter_queue, 9579 (void *)&cmd_5tuple_filter_queue_id, 9580 NULL, 9581 }, 9582 }; 9583 9584 /* *** ADD/REMOVE A flex FILTER *** */ 9585 struct cmd_flex_filter_result { 9586 cmdline_fixed_string_t filter; 9587 cmdline_fixed_string_t ops; 9588 portid_t port_id; 9589 cmdline_fixed_string_t len; 9590 uint8_t len_value; 9591 cmdline_fixed_string_t bytes; 9592 cmdline_fixed_string_t bytes_value; 9593 cmdline_fixed_string_t mask; 9594 cmdline_fixed_string_t mask_value; 9595 cmdline_fixed_string_t priority; 9596 uint8_t priority_value; 9597 cmdline_fixed_string_t queue; 9598 uint16_t queue_id; 9599 }; 9600 9601 static int xdigit2val(unsigned char c) 9602 { 9603 int val; 9604 if (isdigit(c)) 9605 val = c - '0'; 9606 else if (isupper(c)) 9607 val = c - 'A' + 10; 9608 else 9609 val = c - 'a' + 10; 9610 return val; 9611 } 9612 9613 static void 9614 cmd_flex_filter_parsed(void *parsed_result, 9615 __attribute__((unused)) struct cmdline *cl, 9616 __attribute__((unused)) void *data) 9617 { 9618 int ret = 0; 9619 struct rte_eth_flex_filter filter; 9620 struct cmd_flex_filter_result *res = parsed_result; 9621 char *bytes_ptr, *mask_ptr; 9622 uint16_t len, i, j = 0; 9623 char c; 9624 int val; 9625 uint8_t byte = 0; 9626 9627 if (res->len_value > RTE_FLEX_FILTER_MAXLEN) { 9628 printf("the len exceed the max length 128\n"); 9629 return; 9630 } 9631 memset(&filter, 0, sizeof(struct rte_eth_flex_filter)); 9632 filter.len = res->len_value; 9633 filter.priority = res->priority_value; 9634 filter.queue = res->queue_id; 9635 bytes_ptr = res->bytes_value; 9636 mask_ptr = res->mask_value; 9637 9638 /* translate bytes string to array. */ 9639 if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') || 9640 (bytes_ptr[1] == 'X'))) 9641 bytes_ptr += 2; 9642 len = strnlen(bytes_ptr, res->len_value * 2); 9643 if (len == 0 || (len % 8 != 0)) { 9644 printf("please check len and bytes input\n"); 9645 return; 9646 } 9647 for (i = 0; i < len; i++) { 9648 c = bytes_ptr[i]; 9649 if (isxdigit(c) == 0) { 9650 /* invalid characters. */ 9651 printf("invalid input\n"); 9652 return; 9653 } 9654 val = xdigit2val(c); 9655 if (i % 2) { 9656 byte |= val; 9657 filter.bytes[j] = byte; 9658 printf("bytes[%d]:%02x ", j, filter.bytes[j]); 9659 j++; 9660 byte = 0; 9661 } else 9662 byte |= val << 4; 9663 } 9664 printf("\n"); 9665 /* translate mask string to uint8_t array. */ 9666 if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') || 9667 (mask_ptr[1] == 'X'))) 9668 mask_ptr += 2; 9669 len = strnlen(mask_ptr, (res->len_value + 3) / 4); 9670 if (len == 0) { 9671 printf("invalid input\n"); 9672 return; 9673 } 9674 j = 0; 9675 byte = 0; 9676 for (i = 0; i < len; i++) { 9677 c = mask_ptr[i]; 9678 if (isxdigit(c) == 0) { 9679 /* invalid characters. */ 9680 printf("invalid input\n"); 9681 return; 9682 } 9683 val = xdigit2val(c); 9684 if (i % 2) { 9685 byte |= val; 9686 filter.mask[j] = byte; 9687 printf("mask[%d]:%02x ", j, filter.mask[j]); 9688 j++; 9689 byte = 0; 9690 } else 9691 byte |= val << 4; 9692 } 9693 printf("\n"); 9694 9695 if (!strcmp(res->ops, "add")) 9696 ret = rte_eth_dev_filter_ctrl(res->port_id, 9697 RTE_ETH_FILTER_FLEXIBLE, 9698 RTE_ETH_FILTER_ADD, 9699 &filter); 9700 else 9701 ret = rte_eth_dev_filter_ctrl(res->port_id, 9702 RTE_ETH_FILTER_FLEXIBLE, 9703 RTE_ETH_FILTER_DELETE, 9704 &filter); 9705 9706 if (ret < 0) 9707 printf("flex filter setting error: (%s)\n", strerror(-ret)); 9708 } 9709 9710 cmdline_parse_token_string_t cmd_flex_filter_filter = 9711 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9712 filter, "flex_filter"); 9713 cmdline_parse_token_num_t cmd_flex_filter_port_id = 9714 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9715 port_id, UINT16); 9716 cmdline_parse_token_string_t cmd_flex_filter_ops = 9717 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9718 ops, "add#del"); 9719 cmdline_parse_token_string_t cmd_flex_filter_len = 9720 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9721 len, "len"); 9722 cmdline_parse_token_num_t cmd_flex_filter_len_value = 9723 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9724 len_value, UINT8); 9725 cmdline_parse_token_string_t cmd_flex_filter_bytes = 9726 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9727 bytes, "bytes"); 9728 cmdline_parse_token_string_t cmd_flex_filter_bytes_value = 9729 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9730 bytes_value, NULL); 9731 cmdline_parse_token_string_t cmd_flex_filter_mask = 9732 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9733 mask, "mask"); 9734 cmdline_parse_token_string_t cmd_flex_filter_mask_value = 9735 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9736 mask_value, NULL); 9737 cmdline_parse_token_string_t cmd_flex_filter_priority = 9738 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9739 priority, "priority"); 9740 cmdline_parse_token_num_t cmd_flex_filter_priority_value = 9741 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9742 priority_value, UINT8); 9743 cmdline_parse_token_string_t cmd_flex_filter_queue = 9744 TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, 9745 queue, "queue"); 9746 cmdline_parse_token_num_t cmd_flex_filter_queue_id = 9747 TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, 9748 queue_id, UINT16); 9749 cmdline_parse_inst_t cmd_flex_filter = { 9750 .f = cmd_flex_filter_parsed, 9751 .data = NULL, 9752 .help_str = "flex_filter <port_id> add|del len <value> bytes " 9753 "<value> mask <value> priority <value> queue <queue_id>: " 9754 "Add/Del a flex filter", 9755 .tokens = { 9756 (void *)&cmd_flex_filter_filter, 9757 (void *)&cmd_flex_filter_port_id, 9758 (void *)&cmd_flex_filter_ops, 9759 (void *)&cmd_flex_filter_len, 9760 (void *)&cmd_flex_filter_len_value, 9761 (void *)&cmd_flex_filter_bytes, 9762 (void *)&cmd_flex_filter_bytes_value, 9763 (void *)&cmd_flex_filter_mask, 9764 (void *)&cmd_flex_filter_mask_value, 9765 (void *)&cmd_flex_filter_priority, 9766 (void *)&cmd_flex_filter_priority_value, 9767 (void *)&cmd_flex_filter_queue, 9768 (void *)&cmd_flex_filter_queue_id, 9769 NULL, 9770 }, 9771 }; 9772 9773 /* *** Filters Control *** */ 9774 9775 /* *** deal with ethertype filter *** */ 9776 struct cmd_ethertype_filter_result { 9777 cmdline_fixed_string_t filter; 9778 portid_t port_id; 9779 cmdline_fixed_string_t ops; 9780 cmdline_fixed_string_t mac; 9781 struct ether_addr mac_addr; 9782 cmdline_fixed_string_t ethertype; 9783 uint16_t ethertype_value; 9784 cmdline_fixed_string_t drop; 9785 cmdline_fixed_string_t queue; 9786 uint16_t queue_id; 9787 }; 9788 9789 cmdline_parse_token_string_t cmd_ethertype_filter_filter = 9790 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9791 filter, "ethertype_filter"); 9792 cmdline_parse_token_num_t cmd_ethertype_filter_port_id = 9793 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9794 port_id, UINT16); 9795 cmdline_parse_token_string_t cmd_ethertype_filter_ops = 9796 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9797 ops, "add#del"); 9798 cmdline_parse_token_string_t cmd_ethertype_filter_mac = 9799 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9800 mac, "mac_addr#mac_ignr"); 9801 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr = 9802 TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result, 9803 mac_addr); 9804 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype = 9805 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9806 ethertype, "ethertype"); 9807 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value = 9808 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9809 ethertype_value, UINT16); 9810 cmdline_parse_token_string_t cmd_ethertype_filter_drop = 9811 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9812 drop, "drop#fwd"); 9813 cmdline_parse_token_string_t cmd_ethertype_filter_queue = 9814 TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, 9815 queue, "queue"); 9816 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id = 9817 TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, 9818 queue_id, UINT16); 9819 9820 static void 9821 cmd_ethertype_filter_parsed(void *parsed_result, 9822 __attribute__((unused)) struct cmdline *cl, 9823 __attribute__((unused)) void *data) 9824 { 9825 struct cmd_ethertype_filter_result *res = parsed_result; 9826 struct rte_eth_ethertype_filter filter; 9827 int ret = 0; 9828 9829 ret = rte_eth_dev_filter_supported(res->port_id, 9830 RTE_ETH_FILTER_ETHERTYPE); 9831 if (ret < 0) { 9832 printf("ethertype filter is not supported on port %u.\n", 9833 res->port_id); 9834 return; 9835 } 9836 9837 memset(&filter, 0, sizeof(filter)); 9838 if (!strcmp(res->mac, "mac_addr")) { 9839 filter.flags |= RTE_ETHTYPE_FLAGS_MAC; 9840 rte_memcpy(&filter.mac_addr, &res->mac_addr, 9841 sizeof(struct ether_addr)); 9842 } 9843 if (!strcmp(res->drop, "drop")) 9844 filter.flags |= RTE_ETHTYPE_FLAGS_DROP; 9845 filter.ether_type = res->ethertype_value; 9846 filter.queue = res->queue_id; 9847 9848 if (!strcmp(res->ops, "add")) 9849 ret = rte_eth_dev_filter_ctrl(res->port_id, 9850 RTE_ETH_FILTER_ETHERTYPE, 9851 RTE_ETH_FILTER_ADD, 9852 &filter); 9853 else 9854 ret = rte_eth_dev_filter_ctrl(res->port_id, 9855 RTE_ETH_FILTER_ETHERTYPE, 9856 RTE_ETH_FILTER_DELETE, 9857 &filter); 9858 if (ret < 0) 9859 printf("ethertype filter programming error: (%s)\n", 9860 strerror(-ret)); 9861 } 9862 9863 cmdline_parse_inst_t cmd_ethertype_filter = { 9864 .f = cmd_ethertype_filter_parsed, 9865 .data = NULL, 9866 .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr " 9867 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: " 9868 "Add or delete an ethertype filter entry", 9869 .tokens = { 9870 (void *)&cmd_ethertype_filter_filter, 9871 (void *)&cmd_ethertype_filter_port_id, 9872 (void *)&cmd_ethertype_filter_ops, 9873 (void *)&cmd_ethertype_filter_mac, 9874 (void *)&cmd_ethertype_filter_mac_addr, 9875 (void *)&cmd_ethertype_filter_ethertype, 9876 (void *)&cmd_ethertype_filter_ethertype_value, 9877 (void *)&cmd_ethertype_filter_drop, 9878 (void *)&cmd_ethertype_filter_queue, 9879 (void *)&cmd_ethertype_filter_queue_id, 9880 NULL, 9881 }, 9882 }; 9883 9884 /* *** deal with flow director filter *** */ 9885 struct cmd_flow_director_result { 9886 cmdline_fixed_string_t flow_director_filter; 9887 portid_t port_id; 9888 cmdline_fixed_string_t mode; 9889 cmdline_fixed_string_t mode_value; 9890 cmdline_fixed_string_t ops; 9891 cmdline_fixed_string_t flow; 9892 cmdline_fixed_string_t flow_type; 9893 cmdline_fixed_string_t ether; 9894 uint16_t ether_type; 9895 cmdline_fixed_string_t src; 9896 cmdline_ipaddr_t ip_src; 9897 uint16_t port_src; 9898 cmdline_fixed_string_t dst; 9899 cmdline_ipaddr_t ip_dst; 9900 uint16_t port_dst; 9901 cmdline_fixed_string_t verify_tag; 9902 uint32_t verify_tag_value; 9903 cmdline_fixed_string_t tos; 9904 uint8_t tos_value; 9905 cmdline_fixed_string_t proto; 9906 uint8_t proto_value; 9907 cmdline_fixed_string_t ttl; 9908 uint8_t ttl_value; 9909 cmdline_fixed_string_t vlan; 9910 uint16_t vlan_value; 9911 cmdline_fixed_string_t flexbytes; 9912 cmdline_fixed_string_t flexbytes_value; 9913 cmdline_fixed_string_t pf_vf; 9914 cmdline_fixed_string_t drop; 9915 cmdline_fixed_string_t queue; 9916 uint16_t queue_id; 9917 cmdline_fixed_string_t fd_id; 9918 uint32_t fd_id_value; 9919 cmdline_fixed_string_t mac; 9920 struct ether_addr mac_addr; 9921 cmdline_fixed_string_t tunnel; 9922 cmdline_fixed_string_t tunnel_type; 9923 cmdline_fixed_string_t tunnel_id; 9924 uint32_t tunnel_id_value; 9925 cmdline_fixed_string_t packet; 9926 char filepath[]; 9927 }; 9928 9929 static inline int 9930 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num) 9931 { 9932 char s[256]; 9933 const char *p, *p0 = q_arg; 9934 char *end; 9935 unsigned long int_fld; 9936 char *str_fld[max_num]; 9937 int i; 9938 unsigned size; 9939 int ret = -1; 9940 9941 p = strchr(p0, '('); 9942 if (p == NULL) 9943 return -1; 9944 ++p; 9945 p0 = strchr(p, ')'); 9946 if (p0 == NULL) 9947 return -1; 9948 9949 size = p0 - p; 9950 if (size >= sizeof(s)) 9951 return -1; 9952 9953 snprintf(s, sizeof(s), "%.*s", size, p); 9954 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 9955 if (ret < 0 || ret > max_num) 9956 return -1; 9957 for (i = 0; i < ret; i++) { 9958 errno = 0; 9959 int_fld = strtoul(str_fld[i], &end, 0); 9960 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX) 9961 return -1; 9962 flexbytes[i] = (uint8_t)int_fld; 9963 } 9964 return ret; 9965 } 9966 9967 static uint16_t 9968 str2flowtype(char *string) 9969 { 9970 uint8_t i = 0; 9971 static const struct { 9972 char str[32]; 9973 uint16_t type; 9974 } flowtype_str[] = { 9975 {"raw", RTE_ETH_FLOW_RAW}, 9976 {"ipv4", RTE_ETH_FLOW_IPV4}, 9977 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 9978 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 9979 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 9980 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 9981 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 9982 {"ipv6", RTE_ETH_FLOW_IPV6}, 9983 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 9984 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 9985 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 9986 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 9987 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 9988 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 9989 }; 9990 9991 for (i = 0; i < RTE_DIM(flowtype_str); i++) { 9992 if (!strcmp(flowtype_str[i].str, string)) 9993 return flowtype_str[i].type; 9994 } 9995 9996 if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64) 9997 return (uint16_t)atoi(string); 9998 9999 return RTE_ETH_FLOW_UNKNOWN; 10000 } 10001 10002 static enum rte_eth_fdir_tunnel_type 10003 str2fdir_tunneltype(char *string) 10004 { 10005 uint8_t i = 0; 10006 10007 static const struct { 10008 char str[32]; 10009 enum rte_eth_fdir_tunnel_type type; 10010 } tunneltype_str[] = { 10011 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE}, 10012 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN}, 10013 }; 10014 10015 for (i = 0; i < RTE_DIM(tunneltype_str); i++) { 10016 if (!strcmp(tunneltype_str[i].str, string)) 10017 return tunneltype_str[i].type; 10018 } 10019 return RTE_FDIR_TUNNEL_TYPE_UNKNOWN; 10020 } 10021 10022 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ 10023 do { \ 10024 if ((ip_addr).family == AF_INET) \ 10025 (ip) = (ip_addr).addr.ipv4.s_addr; \ 10026 else { \ 10027 printf("invalid parameter.\n"); \ 10028 return; \ 10029 } \ 10030 } while (0) 10031 10032 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ 10033 do { \ 10034 if ((ip_addr).family == AF_INET6) \ 10035 rte_memcpy(&(ip), \ 10036 &((ip_addr).addr.ipv6), \ 10037 sizeof(struct in6_addr)); \ 10038 else { \ 10039 printf("invalid parameter.\n"); \ 10040 return; \ 10041 } \ 10042 } while (0) 10043 10044 static void 10045 cmd_flow_director_filter_parsed(void *parsed_result, 10046 __attribute__((unused)) struct cmdline *cl, 10047 __attribute__((unused)) void *data) 10048 { 10049 struct cmd_flow_director_result *res = parsed_result; 10050 struct rte_eth_fdir_filter entry; 10051 uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN]; 10052 char *end; 10053 unsigned long vf_id; 10054 int ret = 0; 10055 10056 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 10057 if (ret < 0) { 10058 printf("flow director is not supported on port %u.\n", 10059 res->port_id); 10060 return; 10061 } 10062 memset(flexbytes, 0, sizeof(flexbytes)); 10063 memset(&entry, 0, sizeof(struct rte_eth_fdir_filter)); 10064 10065 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 10066 if (strcmp(res->mode_value, "MAC-VLAN")) { 10067 printf("Please set mode to MAC-VLAN.\n"); 10068 return; 10069 } 10070 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 10071 if (strcmp(res->mode_value, "Tunnel")) { 10072 printf("Please set mode to Tunnel.\n"); 10073 return; 10074 } 10075 } else { 10076 if (!strcmp(res->mode_value, "raw")) { 10077 #ifdef RTE_LIBRTE_I40E_PMD 10078 struct rte_pmd_i40e_flow_type_mapping 10079 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; 10080 struct rte_pmd_i40e_pkt_template_conf conf; 10081 uint16_t flow_type = str2flowtype(res->flow_type); 10082 uint16_t i, port = res->port_id; 10083 uint8_t add; 10084 10085 memset(&conf, 0, sizeof(conf)); 10086 10087 if (flow_type == RTE_ETH_FLOW_UNKNOWN) { 10088 printf("Invalid flow type specified.\n"); 10089 return; 10090 } 10091 ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, 10092 mapping); 10093 if (ret) 10094 return; 10095 if (mapping[flow_type].pctype == 0ULL) { 10096 printf("Invalid flow type specified.\n"); 10097 return; 10098 } 10099 for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) { 10100 if (mapping[flow_type].pctype & (1ULL << i)) { 10101 conf.input.pctype = i; 10102 break; 10103 } 10104 } 10105 10106 conf.input.packet = open_file(res->filepath, 10107 &conf.input.length); 10108 if (!conf.input.packet) 10109 return; 10110 if (!strcmp(res->drop, "drop")) 10111 conf.action.behavior = 10112 RTE_PMD_I40E_PKT_TEMPLATE_REJECT; 10113 else 10114 conf.action.behavior = 10115 RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT; 10116 conf.action.report_status = 10117 RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID; 10118 conf.action.rx_queue = res->queue_id; 10119 conf.soft_id = res->fd_id_value; 10120 add = strcmp(res->ops, "del") ? 1 : 0; 10121 ret = rte_pmd_i40e_flow_add_del_packet_template(port, 10122 &conf, 10123 add); 10124 if (ret < 0) 10125 printf("flow director config error: (%s)\n", 10126 strerror(-ret)); 10127 close_file(conf.input.packet); 10128 #endif 10129 return; 10130 } else if (strcmp(res->mode_value, "IP")) { 10131 printf("Please set mode to IP or raw.\n"); 10132 return; 10133 } 10134 entry.input.flow_type = str2flowtype(res->flow_type); 10135 } 10136 10137 ret = parse_flexbytes(res->flexbytes_value, 10138 flexbytes, 10139 RTE_ETH_FDIR_MAX_FLEXLEN); 10140 if (ret < 0) { 10141 printf("error: Cannot parse flexbytes input.\n"); 10142 return; 10143 } 10144 10145 switch (entry.input.flow_type) { 10146 case RTE_ETH_FLOW_FRAG_IPV4: 10147 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: 10148 entry.input.flow.ip4_flow.proto = res->proto_value; 10149 /* fall-through */ 10150 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP: 10151 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP: 10152 IPV4_ADDR_TO_UINT(res->ip_dst, 10153 entry.input.flow.ip4_flow.dst_ip); 10154 IPV4_ADDR_TO_UINT(res->ip_src, 10155 entry.input.flow.ip4_flow.src_ip); 10156 entry.input.flow.ip4_flow.tos = res->tos_value; 10157 entry.input.flow.ip4_flow.ttl = res->ttl_value; 10158 /* need convert to big endian. */ 10159 entry.input.flow.udp4_flow.dst_port = 10160 rte_cpu_to_be_16(res->port_dst); 10161 entry.input.flow.udp4_flow.src_port = 10162 rte_cpu_to_be_16(res->port_src); 10163 break; 10164 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: 10165 IPV4_ADDR_TO_UINT(res->ip_dst, 10166 entry.input.flow.sctp4_flow.ip.dst_ip); 10167 IPV4_ADDR_TO_UINT(res->ip_src, 10168 entry.input.flow.sctp4_flow.ip.src_ip); 10169 entry.input.flow.ip4_flow.tos = res->tos_value; 10170 entry.input.flow.ip4_flow.ttl = res->ttl_value; 10171 /* need convert to big endian. */ 10172 entry.input.flow.sctp4_flow.dst_port = 10173 rte_cpu_to_be_16(res->port_dst); 10174 entry.input.flow.sctp4_flow.src_port = 10175 rte_cpu_to_be_16(res->port_src); 10176 entry.input.flow.sctp4_flow.verify_tag = 10177 rte_cpu_to_be_32(res->verify_tag_value); 10178 break; 10179 case RTE_ETH_FLOW_FRAG_IPV6: 10180 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: 10181 entry.input.flow.ipv6_flow.proto = res->proto_value; 10182 /* fall-through */ 10183 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP: 10184 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP: 10185 IPV6_ADDR_TO_ARRAY(res->ip_dst, 10186 entry.input.flow.ipv6_flow.dst_ip); 10187 IPV6_ADDR_TO_ARRAY(res->ip_src, 10188 entry.input.flow.ipv6_flow.src_ip); 10189 entry.input.flow.ipv6_flow.tc = res->tos_value; 10190 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 10191 /* need convert to big endian. */ 10192 entry.input.flow.udp6_flow.dst_port = 10193 rte_cpu_to_be_16(res->port_dst); 10194 entry.input.flow.udp6_flow.src_port = 10195 rte_cpu_to_be_16(res->port_src); 10196 break; 10197 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: 10198 IPV6_ADDR_TO_ARRAY(res->ip_dst, 10199 entry.input.flow.sctp6_flow.ip.dst_ip); 10200 IPV6_ADDR_TO_ARRAY(res->ip_src, 10201 entry.input.flow.sctp6_flow.ip.src_ip); 10202 entry.input.flow.ipv6_flow.tc = res->tos_value; 10203 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value; 10204 /* need convert to big endian. */ 10205 entry.input.flow.sctp6_flow.dst_port = 10206 rte_cpu_to_be_16(res->port_dst); 10207 entry.input.flow.sctp6_flow.src_port = 10208 rte_cpu_to_be_16(res->port_src); 10209 entry.input.flow.sctp6_flow.verify_tag = 10210 rte_cpu_to_be_32(res->verify_tag_value); 10211 break; 10212 case RTE_ETH_FLOW_L2_PAYLOAD: 10213 entry.input.flow.l2_flow.ether_type = 10214 rte_cpu_to_be_16(res->ether_type); 10215 break; 10216 default: 10217 break; 10218 } 10219 10220 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 10221 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, 10222 &res->mac_addr, 10223 sizeof(struct ether_addr)); 10224 10225 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 10226 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, 10227 &res->mac_addr, 10228 sizeof(struct ether_addr)); 10229 entry.input.flow.tunnel_flow.tunnel_type = 10230 str2fdir_tunneltype(res->tunnel_type); 10231 entry.input.flow.tunnel_flow.tunnel_id = 10232 rte_cpu_to_be_32(res->tunnel_id_value); 10233 } 10234 10235 rte_memcpy(entry.input.flow_ext.flexbytes, 10236 flexbytes, 10237 RTE_ETH_FDIR_MAX_FLEXLEN); 10238 10239 entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value); 10240 10241 entry.action.flex_off = 0; /*use 0 by default */ 10242 if (!strcmp(res->drop, "drop")) 10243 entry.action.behavior = RTE_ETH_FDIR_REJECT; 10244 else 10245 entry.action.behavior = RTE_ETH_FDIR_ACCEPT; 10246 10247 if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN && 10248 fdir_conf.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 10249 if (!strcmp(res->pf_vf, "pf")) 10250 entry.input.flow_ext.is_vf = 0; 10251 else if (!strncmp(res->pf_vf, "vf", 2)) { 10252 struct rte_eth_dev_info dev_info; 10253 10254 memset(&dev_info, 0, sizeof(dev_info)); 10255 rte_eth_dev_info_get(res->port_id, &dev_info); 10256 errno = 0; 10257 vf_id = strtoul(res->pf_vf + 2, &end, 10); 10258 if (errno != 0 || *end != '\0' || 10259 vf_id >= dev_info.max_vfs) { 10260 printf("invalid parameter %s.\n", res->pf_vf); 10261 return; 10262 } 10263 entry.input.flow_ext.is_vf = 1; 10264 entry.input.flow_ext.dst_id = (uint16_t)vf_id; 10265 } else { 10266 printf("invalid parameter %s.\n", res->pf_vf); 10267 return; 10268 } 10269 } 10270 10271 /* set to report FD ID by default */ 10272 entry.action.report_status = RTE_ETH_FDIR_REPORT_ID; 10273 entry.action.rx_queue = res->queue_id; 10274 entry.soft_id = res->fd_id_value; 10275 if (!strcmp(res->ops, "add")) 10276 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10277 RTE_ETH_FILTER_ADD, &entry); 10278 else if (!strcmp(res->ops, "del")) 10279 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10280 RTE_ETH_FILTER_DELETE, &entry); 10281 else 10282 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10283 RTE_ETH_FILTER_UPDATE, &entry); 10284 if (ret < 0) 10285 printf("flow director programming error: (%s)\n", 10286 strerror(-ret)); 10287 } 10288 10289 cmdline_parse_token_string_t cmd_flow_director_filter = 10290 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10291 flow_director_filter, "flow_director_filter"); 10292 cmdline_parse_token_num_t cmd_flow_director_port_id = 10293 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10294 port_id, UINT16); 10295 cmdline_parse_token_string_t cmd_flow_director_ops = 10296 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10297 ops, "add#del#update"); 10298 cmdline_parse_token_string_t cmd_flow_director_flow = 10299 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10300 flow, "flow"); 10301 cmdline_parse_token_string_t cmd_flow_director_flow_type = 10302 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10303 flow_type, NULL); 10304 cmdline_parse_token_string_t cmd_flow_director_ether = 10305 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10306 ether, "ether"); 10307 cmdline_parse_token_num_t cmd_flow_director_ether_type = 10308 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10309 ether_type, UINT16); 10310 cmdline_parse_token_string_t cmd_flow_director_src = 10311 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10312 src, "src"); 10313 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src = 10314 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 10315 ip_src); 10316 cmdline_parse_token_num_t cmd_flow_director_port_src = 10317 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10318 port_src, UINT16); 10319 cmdline_parse_token_string_t cmd_flow_director_dst = 10320 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10321 dst, "dst"); 10322 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst = 10323 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result, 10324 ip_dst); 10325 cmdline_parse_token_num_t cmd_flow_director_port_dst = 10326 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10327 port_dst, UINT16); 10328 cmdline_parse_token_string_t cmd_flow_director_verify_tag = 10329 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10330 verify_tag, "verify_tag"); 10331 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value = 10332 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10333 verify_tag_value, UINT32); 10334 cmdline_parse_token_string_t cmd_flow_director_tos = 10335 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10336 tos, "tos"); 10337 cmdline_parse_token_num_t cmd_flow_director_tos_value = 10338 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10339 tos_value, UINT8); 10340 cmdline_parse_token_string_t cmd_flow_director_proto = 10341 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10342 proto, "proto"); 10343 cmdline_parse_token_num_t cmd_flow_director_proto_value = 10344 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10345 proto_value, UINT8); 10346 cmdline_parse_token_string_t cmd_flow_director_ttl = 10347 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10348 ttl, "ttl"); 10349 cmdline_parse_token_num_t cmd_flow_director_ttl_value = 10350 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10351 ttl_value, UINT8); 10352 cmdline_parse_token_string_t cmd_flow_director_vlan = 10353 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10354 vlan, "vlan"); 10355 cmdline_parse_token_num_t cmd_flow_director_vlan_value = 10356 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10357 vlan_value, UINT16); 10358 cmdline_parse_token_string_t cmd_flow_director_flexbytes = 10359 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10360 flexbytes, "flexbytes"); 10361 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value = 10362 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10363 flexbytes_value, NULL); 10364 cmdline_parse_token_string_t cmd_flow_director_drop = 10365 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10366 drop, "drop#fwd"); 10367 cmdline_parse_token_string_t cmd_flow_director_pf_vf = 10368 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10369 pf_vf, NULL); 10370 cmdline_parse_token_string_t cmd_flow_director_queue = 10371 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10372 queue, "queue"); 10373 cmdline_parse_token_num_t cmd_flow_director_queue_id = 10374 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10375 queue_id, UINT16); 10376 cmdline_parse_token_string_t cmd_flow_director_fd_id = 10377 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10378 fd_id, "fd_id"); 10379 cmdline_parse_token_num_t cmd_flow_director_fd_id_value = 10380 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10381 fd_id_value, UINT32); 10382 10383 cmdline_parse_token_string_t cmd_flow_director_mode = 10384 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10385 mode, "mode"); 10386 cmdline_parse_token_string_t cmd_flow_director_mode_ip = 10387 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10388 mode_value, "IP"); 10389 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan = 10390 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10391 mode_value, "MAC-VLAN"); 10392 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel = 10393 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10394 mode_value, "Tunnel"); 10395 cmdline_parse_token_string_t cmd_flow_director_mode_raw = 10396 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10397 mode_value, "raw"); 10398 cmdline_parse_token_string_t cmd_flow_director_mac = 10399 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10400 mac, "mac"); 10401 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr = 10402 TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result, 10403 mac_addr); 10404 cmdline_parse_token_string_t cmd_flow_director_tunnel = 10405 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10406 tunnel, "tunnel"); 10407 cmdline_parse_token_string_t cmd_flow_director_tunnel_type = 10408 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10409 tunnel_type, "NVGRE#VxLAN"); 10410 cmdline_parse_token_string_t cmd_flow_director_tunnel_id = 10411 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10412 tunnel_id, "tunnel-id"); 10413 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value = 10414 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, 10415 tunnel_id_value, UINT32); 10416 cmdline_parse_token_string_t cmd_flow_director_packet = 10417 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10418 packet, "packet"); 10419 cmdline_parse_token_string_t cmd_flow_director_filepath = 10420 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, 10421 filepath, NULL); 10422 10423 cmdline_parse_inst_t cmd_add_del_ip_flow_director = { 10424 .f = cmd_flow_director_filter_parsed, 10425 .data = NULL, 10426 .help_str = "flow_director_filter <port_id> mode IP add|del|update flow" 10427 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|" 10428 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" 10429 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " 10430 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " 10431 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> " 10432 "fd_id <fd_id_value>: " 10433 "Add or delete an ip flow director entry on NIC", 10434 .tokens = { 10435 (void *)&cmd_flow_director_filter, 10436 (void *)&cmd_flow_director_port_id, 10437 (void *)&cmd_flow_director_mode, 10438 (void *)&cmd_flow_director_mode_ip, 10439 (void *)&cmd_flow_director_ops, 10440 (void *)&cmd_flow_director_flow, 10441 (void *)&cmd_flow_director_flow_type, 10442 (void *)&cmd_flow_director_src, 10443 (void *)&cmd_flow_director_ip_src, 10444 (void *)&cmd_flow_director_dst, 10445 (void *)&cmd_flow_director_ip_dst, 10446 (void *)&cmd_flow_director_tos, 10447 (void *)&cmd_flow_director_tos_value, 10448 (void *)&cmd_flow_director_proto, 10449 (void *)&cmd_flow_director_proto_value, 10450 (void *)&cmd_flow_director_ttl, 10451 (void *)&cmd_flow_director_ttl_value, 10452 (void *)&cmd_flow_director_vlan, 10453 (void *)&cmd_flow_director_vlan_value, 10454 (void *)&cmd_flow_director_flexbytes, 10455 (void *)&cmd_flow_director_flexbytes_value, 10456 (void *)&cmd_flow_director_drop, 10457 (void *)&cmd_flow_director_pf_vf, 10458 (void *)&cmd_flow_director_queue, 10459 (void *)&cmd_flow_director_queue_id, 10460 (void *)&cmd_flow_director_fd_id, 10461 (void *)&cmd_flow_director_fd_id_value, 10462 NULL, 10463 }, 10464 }; 10465 10466 cmdline_parse_inst_t cmd_add_del_udp_flow_director = { 10467 .f = cmd_flow_director_filter_parsed, 10468 .data = NULL, 10469 .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow " 10470 "director entry on NIC", 10471 .tokens = { 10472 (void *)&cmd_flow_director_filter, 10473 (void *)&cmd_flow_director_port_id, 10474 (void *)&cmd_flow_director_mode, 10475 (void *)&cmd_flow_director_mode_ip, 10476 (void *)&cmd_flow_director_ops, 10477 (void *)&cmd_flow_director_flow, 10478 (void *)&cmd_flow_director_flow_type, 10479 (void *)&cmd_flow_director_src, 10480 (void *)&cmd_flow_director_ip_src, 10481 (void *)&cmd_flow_director_port_src, 10482 (void *)&cmd_flow_director_dst, 10483 (void *)&cmd_flow_director_ip_dst, 10484 (void *)&cmd_flow_director_port_dst, 10485 (void *)&cmd_flow_director_tos, 10486 (void *)&cmd_flow_director_tos_value, 10487 (void *)&cmd_flow_director_ttl, 10488 (void *)&cmd_flow_director_ttl_value, 10489 (void *)&cmd_flow_director_vlan, 10490 (void *)&cmd_flow_director_vlan_value, 10491 (void *)&cmd_flow_director_flexbytes, 10492 (void *)&cmd_flow_director_flexbytes_value, 10493 (void *)&cmd_flow_director_drop, 10494 (void *)&cmd_flow_director_pf_vf, 10495 (void *)&cmd_flow_director_queue, 10496 (void *)&cmd_flow_director_queue_id, 10497 (void *)&cmd_flow_director_fd_id, 10498 (void *)&cmd_flow_director_fd_id_value, 10499 NULL, 10500 }, 10501 }; 10502 10503 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = { 10504 .f = cmd_flow_director_filter_parsed, 10505 .data = NULL, 10506 .help_str = "flow_director_filter ... : Add or delete a sctp flow " 10507 "director entry on NIC", 10508 .tokens = { 10509 (void *)&cmd_flow_director_filter, 10510 (void *)&cmd_flow_director_port_id, 10511 (void *)&cmd_flow_director_mode, 10512 (void *)&cmd_flow_director_mode_ip, 10513 (void *)&cmd_flow_director_ops, 10514 (void *)&cmd_flow_director_flow, 10515 (void *)&cmd_flow_director_flow_type, 10516 (void *)&cmd_flow_director_src, 10517 (void *)&cmd_flow_director_ip_src, 10518 (void *)&cmd_flow_director_port_src, 10519 (void *)&cmd_flow_director_dst, 10520 (void *)&cmd_flow_director_ip_dst, 10521 (void *)&cmd_flow_director_port_dst, 10522 (void *)&cmd_flow_director_verify_tag, 10523 (void *)&cmd_flow_director_verify_tag_value, 10524 (void *)&cmd_flow_director_tos, 10525 (void *)&cmd_flow_director_tos_value, 10526 (void *)&cmd_flow_director_ttl, 10527 (void *)&cmd_flow_director_ttl_value, 10528 (void *)&cmd_flow_director_vlan, 10529 (void *)&cmd_flow_director_vlan_value, 10530 (void *)&cmd_flow_director_flexbytes, 10531 (void *)&cmd_flow_director_flexbytes_value, 10532 (void *)&cmd_flow_director_drop, 10533 (void *)&cmd_flow_director_pf_vf, 10534 (void *)&cmd_flow_director_queue, 10535 (void *)&cmd_flow_director_queue_id, 10536 (void *)&cmd_flow_director_fd_id, 10537 (void *)&cmd_flow_director_fd_id_value, 10538 NULL, 10539 }, 10540 }; 10541 10542 cmdline_parse_inst_t cmd_add_del_l2_flow_director = { 10543 .f = cmd_flow_director_filter_parsed, 10544 .data = NULL, 10545 .help_str = "flow_director_filter ... : Add or delete a L2 flow " 10546 "director entry on NIC", 10547 .tokens = { 10548 (void *)&cmd_flow_director_filter, 10549 (void *)&cmd_flow_director_port_id, 10550 (void *)&cmd_flow_director_mode, 10551 (void *)&cmd_flow_director_mode_ip, 10552 (void *)&cmd_flow_director_ops, 10553 (void *)&cmd_flow_director_flow, 10554 (void *)&cmd_flow_director_flow_type, 10555 (void *)&cmd_flow_director_ether, 10556 (void *)&cmd_flow_director_ether_type, 10557 (void *)&cmd_flow_director_flexbytes, 10558 (void *)&cmd_flow_director_flexbytes_value, 10559 (void *)&cmd_flow_director_drop, 10560 (void *)&cmd_flow_director_pf_vf, 10561 (void *)&cmd_flow_director_queue, 10562 (void *)&cmd_flow_director_queue_id, 10563 (void *)&cmd_flow_director_fd_id, 10564 (void *)&cmd_flow_director_fd_id_value, 10565 NULL, 10566 }, 10567 }; 10568 10569 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = { 10570 .f = cmd_flow_director_filter_parsed, 10571 .data = NULL, 10572 .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow " 10573 "director entry on NIC", 10574 .tokens = { 10575 (void *)&cmd_flow_director_filter, 10576 (void *)&cmd_flow_director_port_id, 10577 (void *)&cmd_flow_director_mode, 10578 (void *)&cmd_flow_director_mode_mac_vlan, 10579 (void *)&cmd_flow_director_ops, 10580 (void *)&cmd_flow_director_mac, 10581 (void *)&cmd_flow_director_mac_addr, 10582 (void *)&cmd_flow_director_vlan, 10583 (void *)&cmd_flow_director_vlan_value, 10584 (void *)&cmd_flow_director_flexbytes, 10585 (void *)&cmd_flow_director_flexbytes_value, 10586 (void *)&cmd_flow_director_drop, 10587 (void *)&cmd_flow_director_queue, 10588 (void *)&cmd_flow_director_queue_id, 10589 (void *)&cmd_flow_director_fd_id, 10590 (void *)&cmd_flow_director_fd_id_value, 10591 NULL, 10592 }, 10593 }; 10594 10595 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { 10596 .f = cmd_flow_director_filter_parsed, 10597 .data = NULL, 10598 .help_str = "flow_director_filter ... : Add or delete a tunnel flow " 10599 "director entry on NIC", 10600 .tokens = { 10601 (void *)&cmd_flow_director_filter, 10602 (void *)&cmd_flow_director_port_id, 10603 (void *)&cmd_flow_director_mode, 10604 (void *)&cmd_flow_director_mode_tunnel, 10605 (void *)&cmd_flow_director_ops, 10606 (void *)&cmd_flow_director_mac, 10607 (void *)&cmd_flow_director_mac_addr, 10608 (void *)&cmd_flow_director_vlan, 10609 (void *)&cmd_flow_director_vlan_value, 10610 (void *)&cmd_flow_director_tunnel, 10611 (void *)&cmd_flow_director_tunnel_type, 10612 (void *)&cmd_flow_director_tunnel_id, 10613 (void *)&cmd_flow_director_tunnel_id_value, 10614 (void *)&cmd_flow_director_flexbytes, 10615 (void *)&cmd_flow_director_flexbytes_value, 10616 (void *)&cmd_flow_director_drop, 10617 (void *)&cmd_flow_director_queue, 10618 (void *)&cmd_flow_director_queue_id, 10619 (void *)&cmd_flow_director_fd_id, 10620 (void *)&cmd_flow_director_fd_id_value, 10621 NULL, 10622 }, 10623 }; 10624 10625 cmdline_parse_inst_t cmd_add_del_raw_flow_director = { 10626 .f = cmd_flow_director_filter_parsed, 10627 .data = NULL, 10628 .help_str = "flow_director_filter ... : Add or delete a raw flow " 10629 "director entry on NIC", 10630 .tokens = { 10631 (void *)&cmd_flow_director_filter, 10632 (void *)&cmd_flow_director_port_id, 10633 (void *)&cmd_flow_director_mode, 10634 (void *)&cmd_flow_director_mode_raw, 10635 (void *)&cmd_flow_director_ops, 10636 (void *)&cmd_flow_director_flow, 10637 (void *)&cmd_flow_director_flow_type, 10638 (void *)&cmd_flow_director_drop, 10639 (void *)&cmd_flow_director_queue, 10640 (void *)&cmd_flow_director_queue_id, 10641 (void *)&cmd_flow_director_fd_id, 10642 (void *)&cmd_flow_director_fd_id_value, 10643 (void *)&cmd_flow_director_packet, 10644 (void *)&cmd_flow_director_filepath, 10645 NULL, 10646 }, 10647 }; 10648 10649 struct cmd_flush_flow_director_result { 10650 cmdline_fixed_string_t flush_flow_director; 10651 portid_t port_id; 10652 }; 10653 10654 cmdline_parse_token_string_t cmd_flush_flow_director_flush = 10655 TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result, 10656 flush_flow_director, "flush_flow_director"); 10657 cmdline_parse_token_num_t cmd_flush_flow_director_port_id = 10658 TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, 10659 port_id, UINT16); 10660 10661 static void 10662 cmd_flush_flow_director_parsed(void *parsed_result, 10663 __attribute__((unused)) struct cmdline *cl, 10664 __attribute__((unused)) void *data) 10665 { 10666 struct cmd_flow_director_result *res = parsed_result; 10667 int ret = 0; 10668 10669 ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); 10670 if (ret < 0) { 10671 printf("flow director is not supported on port %u.\n", 10672 res->port_id); 10673 return; 10674 } 10675 10676 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10677 RTE_ETH_FILTER_FLUSH, NULL); 10678 if (ret < 0) 10679 printf("flow director table flushing error: (%s)\n", 10680 strerror(-ret)); 10681 } 10682 10683 cmdline_parse_inst_t cmd_flush_flow_director = { 10684 .f = cmd_flush_flow_director_parsed, 10685 .data = NULL, 10686 .help_str = "flush_flow_director <port_id>: " 10687 "Flush all flow director entries of a device on NIC", 10688 .tokens = { 10689 (void *)&cmd_flush_flow_director_flush, 10690 (void *)&cmd_flush_flow_director_port_id, 10691 NULL, 10692 }, 10693 }; 10694 10695 /* *** deal with flow director mask *** */ 10696 struct cmd_flow_director_mask_result { 10697 cmdline_fixed_string_t flow_director_mask; 10698 portid_t port_id; 10699 cmdline_fixed_string_t mode; 10700 cmdline_fixed_string_t mode_value; 10701 cmdline_fixed_string_t vlan; 10702 uint16_t vlan_mask; 10703 cmdline_fixed_string_t src_mask; 10704 cmdline_ipaddr_t ipv4_src; 10705 cmdline_ipaddr_t ipv6_src; 10706 uint16_t port_src; 10707 cmdline_fixed_string_t dst_mask; 10708 cmdline_ipaddr_t ipv4_dst; 10709 cmdline_ipaddr_t ipv6_dst; 10710 uint16_t port_dst; 10711 cmdline_fixed_string_t mac; 10712 uint8_t mac_addr_byte_mask; 10713 cmdline_fixed_string_t tunnel_id; 10714 uint32_t tunnel_id_mask; 10715 cmdline_fixed_string_t tunnel_type; 10716 uint8_t tunnel_type_mask; 10717 }; 10718 10719 static void 10720 cmd_flow_director_mask_parsed(void *parsed_result, 10721 __attribute__((unused)) struct cmdline *cl, 10722 __attribute__((unused)) void *data) 10723 { 10724 struct cmd_flow_director_mask_result *res = parsed_result; 10725 struct rte_eth_fdir_masks *mask; 10726 struct rte_port *port; 10727 10728 if (res->port_id > nb_ports) { 10729 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 10730 return; 10731 } 10732 10733 port = &ports[res->port_id]; 10734 /** Check if the port is not started **/ 10735 if (port->port_status != RTE_PORT_STOPPED) { 10736 printf("Please stop port %d first\n", res->port_id); 10737 return; 10738 } 10739 10740 mask = &port->dev_conf.fdir_conf.mask; 10741 10742 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 10743 if (strcmp(res->mode_value, "MAC-VLAN")) { 10744 printf("Please set mode to MAC-VLAN.\n"); 10745 return; 10746 } 10747 10748 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10749 } else if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { 10750 if (strcmp(res->mode_value, "Tunnel")) { 10751 printf("Please set mode to Tunnel.\n"); 10752 return; 10753 } 10754 10755 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10756 mask->mac_addr_byte_mask = res->mac_addr_byte_mask; 10757 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask); 10758 mask->tunnel_type_mask = res->tunnel_type_mask; 10759 } else { 10760 if (strcmp(res->mode_value, "IP")) { 10761 printf("Please set mode to IP.\n"); 10762 return; 10763 } 10764 10765 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask); 10766 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip); 10767 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip); 10768 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip); 10769 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip); 10770 mask->src_port_mask = rte_cpu_to_be_16(res->port_src); 10771 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst); 10772 } 10773 10774 cmd_reconfig_device_queue(res->port_id, 1, 1); 10775 } 10776 10777 cmdline_parse_token_string_t cmd_flow_director_mask = 10778 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10779 flow_director_mask, "flow_director_mask"); 10780 cmdline_parse_token_num_t cmd_flow_director_mask_port_id = 10781 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10782 port_id, UINT16); 10783 cmdline_parse_token_string_t cmd_flow_director_mask_vlan = 10784 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10785 vlan, "vlan"); 10786 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value = 10787 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10788 vlan_mask, UINT16); 10789 cmdline_parse_token_string_t cmd_flow_director_mask_src = 10790 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10791 src_mask, "src_mask"); 10792 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src = 10793 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10794 ipv4_src); 10795 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src = 10796 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10797 ipv6_src); 10798 cmdline_parse_token_num_t cmd_flow_director_mask_port_src = 10799 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10800 port_src, UINT16); 10801 cmdline_parse_token_string_t cmd_flow_director_mask_dst = 10802 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10803 dst_mask, "dst_mask"); 10804 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst = 10805 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10806 ipv4_dst); 10807 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst = 10808 TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result, 10809 ipv6_dst); 10810 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst = 10811 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10812 port_dst, UINT16); 10813 10814 cmdline_parse_token_string_t cmd_flow_director_mask_mode = 10815 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10816 mode, "mode"); 10817 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip = 10818 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10819 mode_value, "IP"); 10820 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan = 10821 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10822 mode_value, "MAC-VLAN"); 10823 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel = 10824 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10825 mode_value, "Tunnel"); 10826 cmdline_parse_token_string_t cmd_flow_director_mask_mac = 10827 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10828 mac, "mac"); 10829 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value = 10830 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10831 mac_addr_byte_mask, UINT8); 10832 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type = 10833 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10834 tunnel_type, "tunnel-type"); 10835 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value = 10836 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10837 tunnel_type_mask, UINT8); 10838 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id = 10839 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, 10840 tunnel_id, "tunnel-id"); 10841 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value = 10842 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, 10843 tunnel_id_mask, UINT32); 10844 10845 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = { 10846 .f = cmd_flow_director_mask_parsed, 10847 .data = NULL, 10848 .help_str = "flow_director_mask ... : " 10849 "Set IP mode flow director's mask on NIC", 10850 .tokens = { 10851 (void *)&cmd_flow_director_mask, 10852 (void *)&cmd_flow_director_mask_port_id, 10853 (void *)&cmd_flow_director_mask_mode, 10854 (void *)&cmd_flow_director_mask_mode_ip, 10855 (void *)&cmd_flow_director_mask_vlan, 10856 (void *)&cmd_flow_director_mask_vlan_value, 10857 (void *)&cmd_flow_director_mask_src, 10858 (void *)&cmd_flow_director_mask_ipv4_src, 10859 (void *)&cmd_flow_director_mask_ipv6_src, 10860 (void *)&cmd_flow_director_mask_port_src, 10861 (void *)&cmd_flow_director_mask_dst, 10862 (void *)&cmd_flow_director_mask_ipv4_dst, 10863 (void *)&cmd_flow_director_mask_ipv6_dst, 10864 (void *)&cmd_flow_director_mask_port_dst, 10865 NULL, 10866 }, 10867 }; 10868 10869 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = { 10870 .f = cmd_flow_director_mask_parsed, 10871 .data = NULL, 10872 .help_str = "flow_director_mask ... : Set MAC VLAN mode " 10873 "flow director's mask on NIC", 10874 .tokens = { 10875 (void *)&cmd_flow_director_mask, 10876 (void *)&cmd_flow_director_mask_port_id, 10877 (void *)&cmd_flow_director_mask_mode, 10878 (void *)&cmd_flow_director_mask_mode_mac_vlan, 10879 (void *)&cmd_flow_director_mask_vlan, 10880 (void *)&cmd_flow_director_mask_vlan_value, 10881 NULL, 10882 }, 10883 }; 10884 10885 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { 10886 .f = cmd_flow_director_mask_parsed, 10887 .data = NULL, 10888 .help_str = "flow_director_mask ... : Set tunnel mode " 10889 "flow director's mask on NIC", 10890 .tokens = { 10891 (void *)&cmd_flow_director_mask, 10892 (void *)&cmd_flow_director_mask_port_id, 10893 (void *)&cmd_flow_director_mask_mode, 10894 (void *)&cmd_flow_director_mask_mode_tunnel, 10895 (void *)&cmd_flow_director_mask_vlan, 10896 (void *)&cmd_flow_director_mask_vlan_value, 10897 (void *)&cmd_flow_director_mask_mac, 10898 (void *)&cmd_flow_director_mask_mac_value, 10899 (void *)&cmd_flow_director_mask_tunnel_type, 10900 (void *)&cmd_flow_director_mask_tunnel_type_value, 10901 (void *)&cmd_flow_director_mask_tunnel_id, 10902 (void *)&cmd_flow_director_mask_tunnel_id_value, 10903 NULL, 10904 }, 10905 }; 10906 10907 /* *** deal with flow director mask on flexible payload *** */ 10908 struct cmd_flow_director_flex_mask_result { 10909 cmdline_fixed_string_t flow_director_flexmask; 10910 portid_t port_id; 10911 cmdline_fixed_string_t flow; 10912 cmdline_fixed_string_t flow_type; 10913 cmdline_fixed_string_t mask; 10914 }; 10915 10916 static void 10917 cmd_flow_director_flex_mask_parsed(void *parsed_result, 10918 __attribute__((unused)) struct cmdline *cl, 10919 __attribute__((unused)) void *data) 10920 { 10921 struct cmd_flow_director_flex_mask_result *res = parsed_result; 10922 struct rte_eth_fdir_info fdir_info; 10923 struct rte_eth_fdir_flex_mask flex_mask; 10924 struct rte_port *port; 10925 uint64_t flow_type_mask; 10926 uint16_t i; 10927 int ret; 10928 10929 if (res->port_id > nb_ports) { 10930 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 10931 return; 10932 } 10933 10934 port = &ports[res->port_id]; 10935 /** Check if the port is not started **/ 10936 if (port->port_status != RTE_PORT_STOPPED) { 10937 printf("Please stop port %d first\n", res->port_id); 10938 return; 10939 } 10940 10941 memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); 10942 ret = parse_flexbytes(res->mask, 10943 flex_mask.mask, 10944 RTE_ETH_FDIR_MAX_FLEXLEN); 10945 if (ret < 0) { 10946 printf("error: Cannot parse mask input.\n"); 10947 return; 10948 } 10949 10950 memset(&fdir_info, 0, sizeof(fdir_info)); 10951 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 10952 RTE_ETH_FILTER_INFO, &fdir_info); 10953 if (ret < 0) { 10954 printf("Cannot get FDir filter info\n"); 10955 return; 10956 } 10957 10958 if (!strcmp(res->flow_type, "none")) { 10959 /* means don't specify the flow type */ 10960 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN; 10961 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) 10962 memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 10963 0, sizeof(struct rte_eth_fdir_flex_mask)); 10964 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; 10965 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], 10966 &flex_mask, 10967 sizeof(struct rte_eth_fdir_flex_mask)); 10968 cmd_reconfig_device_queue(res->port_id, 1, 1); 10969 return; 10970 } 10971 flow_type_mask = fdir_info.flow_types_mask[0]; 10972 if (!strcmp(res->flow_type, "all")) { 10973 if (!flow_type_mask) { 10974 printf("No flow type supported\n"); 10975 return; 10976 } 10977 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 10978 if (flow_type_mask & (1ULL << i)) { 10979 flex_mask.flow_type = i; 10980 fdir_set_flex_mask(res->port_id, &flex_mask); 10981 } 10982 } 10983 cmd_reconfig_device_queue(res->port_id, 1, 1); 10984 return; 10985 } 10986 flex_mask.flow_type = str2flowtype(res->flow_type); 10987 if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) { 10988 printf("Flow type %s not supported on port %d\n", 10989 res->flow_type, res->port_id); 10990 return; 10991 } 10992 fdir_set_flex_mask(res->port_id, &flex_mask); 10993 cmd_reconfig_device_queue(res->port_id, 1, 1); 10994 } 10995 10996 cmdline_parse_token_string_t cmd_flow_director_flexmask = 10997 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 10998 flow_director_flexmask, 10999 "flow_director_flex_mask"); 11000 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = 11001 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, 11002 port_id, UINT16); 11003 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = 11004 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 11005 flow, "flow"); 11006 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = 11007 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 11008 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#" 11009 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all"); 11010 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = 11011 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, 11012 mask, NULL); 11013 11014 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { 11015 .f = cmd_flow_director_flex_mask_parsed, 11016 .data = NULL, 11017 .help_str = "flow_director_flex_mask ... : " 11018 "Set flow director's flex mask on NIC", 11019 .tokens = { 11020 (void *)&cmd_flow_director_flexmask, 11021 (void *)&cmd_flow_director_flexmask_port_id, 11022 (void *)&cmd_flow_director_flexmask_flow, 11023 (void *)&cmd_flow_director_flexmask_flow_type, 11024 (void *)&cmd_flow_director_flexmask_mask, 11025 NULL, 11026 }, 11027 }; 11028 11029 /* *** deal with flow director flexible payload configuration *** */ 11030 struct cmd_flow_director_flexpayload_result { 11031 cmdline_fixed_string_t flow_director_flexpayload; 11032 portid_t port_id; 11033 cmdline_fixed_string_t payload_layer; 11034 cmdline_fixed_string_t payload_cfg; 11035 }; 11036 11037 static inline int 11038 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num) 11039 { 11040 char s[256]; 11041 const char *p, *p0 = q_arg; 11042 char *end; 11043 unsigned long int_fld; 11044 char *str_fld[max_num]; 11045 int i; 11046 unsigned size; 11047 int ret = -1; 11048 11049 p = strchr(p0, '('); 11050 if (p == NULL) 11051 return -1; 11052 ++p; 11053 p0 = strchr(p, ')'); 11054 if (p0 == NULL) 11055 return -1; 11056 11057 size = p0 - p; 11058 if (size >= sizeof(s)) 11059 return -1; 11060 11061 snprintf(s, sizeof(s), "%.*s", size, p); 11062 ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ','); 11063 if (ret < 0 || ret > max_num) 11064 return -1; 11065 for (i = 0; i < ret; i++) { 11066 errno = 0; 11067 int_fld = strtoul(str_fld[i], &end, 0); 11068 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX) 11069 return -1; 11070 offsets[i] = (uint16_t)int_fld; 11071 } 11072 return ret; 11073 } 11074 11075 static void 11076 cmd_flow_director_flxpld_parsed(void *parsed_result, 11077 __attribute__((unused)) struct cmdline *cl, 11078 __attribute__((unused)) void *data) 11079 { 11080 struct cmd_flow_director_flexpayload_result *res = parsed_result; 11081 struct rte_eth_flex_payload_cfg flex_cfg; 11082 struct rte_port *port; 11083 int ret = 0; 11084 11085 if (res->port_id > nb_ports) { 11086 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 11087 return; 11088 } 11089 11090 port = &ports[res->port_id]; 11091 /** Check if the port is not started **/ 11092 if (port->port_status != RTE_PORT_STOPPED) { 11093 printf("Please stop port %d first\n", res->port_id); 11094 return; 11095 } 11096 11097 memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg)); 11098 11099 if (!strcmp(res->payload_layer, "raw")) 11100 flex_cfg.type = RTE_ETH_RAW_PAYLOAD; 11101 else if (!strcmp(res->payload_layer, "l2")) 11102 flex_cfg.type = RTE_ETH_L2_PAYLOAD; 11103 else if (!strcmp(res->payload_layer, "l3")) 11104 flex_cfg.type = RTE_ETH_L3_PAYLOAD; 11105 else if (!strcmp(res->payload_layer, "l4")) 11106 flex_cfg.type = RTE_ETH_L4_PAYLOAD; 11107 11108 ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset, 11109 RTE_ETH_FDIR_MAX_FLEXLEN); 11110 if (ret < 0) { 11111 printf("error: Cannot parse flex payload input.\n"); 11112 return; 11113 } 11114 11115 fdir_set_flex_payload(res->port_id, &flex_cfg); 11116 cmd_reconfig_device_queue(res->port_id, 1, 1); 11117 } 11118 11119 cmdline_parse_token_string_t cmd_flow_director_flexpayload = 11120 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 11121 flow_director_flexpayload, 11122 "flow_director_flex_payload"); 11123 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = 11124 TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, 11125 port_id, UINT16); 11126 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = 11127 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 11128 payload_layer, "raw#l2#l3#l4"); 11129 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = 11130 TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, 11131 payload_cfg, NULL); 11132 11133 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { 11134 .f = cmd_flow_director_flxpld_parsed, 11135 .data = NULL, 11136 .help_str = "flow_director_flexpayload ... : " 11137 "Set flow director's flex payload on NIC", 11138 .tokens = { 11139 (void *)&cmd_flow_director_flexpayload, 11140 (void *)&cmd_flow_director_flexpayload_port_id, 11141 (void *)&cmd_flow_director_flexpayload_payload_layer, 11142 (void *)&cmd_flow_director_flexpayload_payload_cfg, 11143 NULL, 11144 }, 11145 }; 11146 11147 /* Generic flow interface command. */ 11148 extern cmdline_parse_inst_t cmd_flow; 11149 11150 /* *** Classification Filters Control *** */ 11151 /* *** Get symmetric hash enable per port *** */ 11152 struct cmd_get_sym_hash_ena_per_port_result { 11153 cmdline_fixed_string_t get_sym_hash_ena_per_port; 11154 portid_t port_id; 11155 }; 11156 11157 static void 11158 cmd_get_sym_hash_per_port_parsed(void *parsed_result, 11159 __rte_unused struct cmdline *cl, 11160 __rte_unused void *data) 11161 { 11162 struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result; 11163 struct rte_eth_hash_filter_info info; 11164 int ret; 11165 11166 if (rte_eth_dev_filter_supported(res->port_id, 11167 RTE_ETH_FILTER_HASH) < 0) { 11168 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 11169 res->port_id); 11170 return; 11171 } 11172 11173 memset(&info, 0, sizeof(info)); 11174 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 11175 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11176 RTE_ETH_FILTER_GET, &info); 11177 11178 if (ret < 0) { 11179 printf("Cannot get symmetric hash enable per port " 11180 "on port %u\n", res->port_id); 11181 return; 11182 } 11183 11184 printf("Symmetric hash is %s on port %u\n", info.info.enable ? 11185 "enabled" : "disabled", res->port_id); 11186 } 11187 11188 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = 11189 TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 11190 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); 11191 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = 11192 TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, 11193 port_id, UINT16); 11194 11195 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { 11196 .f = cmd_get_sym_hash_per_port_parsed, 11197 .data = NULL, 11198 .help_str = "get_sym_hash_ena_per_port <port_id>", 11199 .tokens = { 11200 (void *)&cmd_get_sym_hash_ena_per_port_all, 11201 (void *)&cmd_get_sym_hash_ena_per_port_port_id, 11202 NULL, 11203 }, 11204 }; 11205 11206 /* *** Set symmetric hash enable per port *** */ 11207 struct cmd_set_sym_hash_ena_per_port_result { 11208 cmdline_fixed_string_t set_sym_hash_ena_per_port; 11209 cmdline_fixed_string_t enable; 11210 portid_t port_id; 11211 }; 11212 11213 static void 11214 cmd_set_sym_hash_per_port_parsed(void *parsed_result, 11215 __rte_unused struct cmdline *cl, 11216 __rte_unused void *data) 11217 { 11218 struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result; 11219 struct rte_eth_hash_filter_info info; 11220 int ret; 11221 11222 if (rte_eth_dev_filter_supported(res->port_id, 11223 RTE_ETH_FILTER_HASH) < 0) { 11224 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n", 11225 res->port_id); 11226 return; 11227 } 11228 11229 memset(&info, 0, sizeof(info)); 11230 info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT; 11231 if (!strcmp(res->enable, "enable")) 11232 info.info.enable = 1; 11233 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11234 RTE_ETH_FILTER_SET, &info); 11235 if (ret < 0) { 11236 printf("Cannot set symmetric hash enable per port on " 11237 "port %u\n", res->port_id); 11238 return; 11239 } 11240 printf("Symmetric hash has been set to %s on port %u\n", 11241 res->enable, res->port_id); 11242 } 11243 11244 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = 11245 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 11246 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); 11247 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = 11248 TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 11249 port_id, UINT16); 11250 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = 11251 TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, 11252 enable, "enable#disable"); 11253 11254 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { 11255 .f = cmd_set_sym_hash_per_port_parsed, 11256 .data = NULL, 11257 .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable", 11258 .tokens = { 11259 (void *)&cmd_set_sym_hash_ena_per_port_all, 11260 (void *)&cmd_set_sym_hash_ena_per_port_port_id, 11261 (void *)&cmd_set_sym_hash_ena_per_port_enable, 11262 NULL, 11263 }, 11264 }; 11265 11266 /* Get global config of hash function */ 11267 struct cmd_get_hash_global_config_result { 11268 cmdline_fixed_string_t get_hash_global_config; 11269 portid_t port_id; 11270 }; 11271 11272 static char * 11273 flowtype_to_str(uint16_t ftype) 11274 { 11275 uint16_t i; 11276 static struct { 11277 char str[16]; 11278 uint16_t ftype; 11279 } ftype_table[] = { 11280 {"ipv4", RTE_ETH_FLOW_IPV4}, 11281 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 11282 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 11283 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 11284 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 11285 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 11286 {"ipv6", RTE_ETH_FLOW_IPV6}, 11287 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 11288 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 11289 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 11290 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 11291 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 11292 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 11293 {"port", RTE_ETH_FLOW_PORT}, 11294 {"vxlan", RTE_ETH_FLOW_VXLAN}, 11295 {"geneve", RTE_ETH_FLOW_GENEVE}, 11296 {"nvgre", RTE_ETH_FLOW_NVGRE}, 11297 }; 11298 11299 for (i = 0; i < RTE_DIM(ftype_table); i++) { 11300 if (ftype_table[i].ftype == ftype) 11301 return ftype_table[i].str; 11302 } 11303 11304 return NULL; 11305 } 11306 11307 static void 11308 cmd_get_hash_global_config_parsed(void *parsed_result, 11309 __rte_unused struct cmdline *cl, 11310 __rte_unused void *data) 11311 { 11312 struct cmd_get_hash_global_config_result *res = parsed_result; 11313 struct rte_eth_hash_filter_info info; 11314 uint32_t idx, offset; 11315 uint16_t i; 11316 char *str; 11317 int ret; 11318 11319 if (rte_eth_dev_filter_supported(res->port_id, 11320 RTE_ETH_FILTER_HASH) < 0) { 11321 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 11322 res->port_id); 11323 return; 11324 } 11325 11326 memset(&info, 0, sizeof(info)); 11327 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 11328 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11329 RTE_ETH_FILTER_GET, &info); 11330 if (ret < 0) { 11331 printf("Cannot get hash global configurations by port %d\n", 11332 res->port_id); 11333 return; 11334 } 11335 11336 switch (info.info.global_conf.hash_func) { 11337 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 11338 printf("Hash function is Toeplitz\n"); 11339 break; 11340 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 11341 printf("Hash function is Simple XOR\n"); 11342 break; 11343 default: 11344 printf("Unknown hash function\n"); 11345 break; 11346 } 11347 11348 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 11349 idx = i / UINT64_BIT; 11350 offset = i % UINT64_BIT; 11351 if (!(info.info.global_conf.valid_bit_mask[idx] & 11352 (1ULL << offset))) 11353 continue; 11354 str = flowtype_to_str(i); 11355 if (!str) 11356 continue; 11357 printf("Symmetric hash is %s globally for flow type %s " 11358 "by port %d\n", 11359 ((info.info.global_conf.sym_hash_enable_mask[idx] & 11360 (1ULL << offset)) ? "enabled" : "disabled"), str, 11361 res->port_id); 11362 } 11363 } 11364 11365 cmdline_parse_token_string_t cmd_get_hash_global_config_all = 11366 TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result, 11367 get_hash_global_config, "get_hash_global_config"); 11368 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = 11369 TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, 11370 port_id, UINT16); 11371 11372 cmdline_parse_inst_t cmd_get_hash_global_config = { 11373 .f = cmd_get_hash_global_config_parsed, 11374 .data = NULL, 11375 .help_str = "get_hash_global_config <port_id>", 11376 .tokens = { 11377 (void *)&cmd_get_hash_global_config_all, 11378 (void *)&cmd_get_hash_global_config_port_id, 11379 NULL, 11380 }, 11381 }; 11382 11383 /* Set global config of hash function */ 11384 struct cmd_set_hash_global_config_result { 11385 cmdline_fixed_string_t set_hash_global_config; 11386 portid_t port_id; 11387 cmdline_fixed_string_t hash_func; 11388 cmdline_fixed_string_t flow_type; 11389 cmdline_fixed_string_t enable; 11390 }; 11391 11392 static void 11393 cmd_set_hash_global_config_parsed(void *parsed_result, 11394 __rte_unused struct cmdline *cl, 11395 __rte_unused void *data) 11396 { 11397 struct cmd_set_hash_global_config_result *res = parsed_result; 11398 struct rte_eth_hash_filter_info info; 11399 uint32_t ftype, idx, offset; 11400 int ret; 11401 11402 if (rte_eth_dev_filter_supported(res->port_id, 11403 RTE_ETH_FILTER_HASH) < 0) { 11404 printf("RTE_ETH_FILTER_HASH not supported on port %d\n", 11405 res->port_id); 11406 return; 11407 } 11408 memset(&info, 0, sizeof(info)); 11409 info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG; 11410 if (!strcmp(res->hash_func, "toeplitz")) 11411 info.info.global_conf.hash_func = 11412 RTE_ETH_HASH_FUNCTION_TOEPLITZ; 11413 else if (!strcmp(res->hash_func, "simple_xor")) 11414 info.info.global_conf.hash_func = 11415 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR; 11416 else if (!strcmp(res->hash_func, "default")) 11417 info.info.global_conf.hash_func = 11418 RTE_ETH_HASH_FUNCTION_DEFAULT; 11419 11420 ftype = str2flowtype(res->flow_type); 11421 idx = ftype / UINT64_BIT; 11422 offset = ftype % UINT64_BIT; 11423 info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset); 11424 if (!strcmp(res->enable, "enable")) 11425 info.info.global_conf.sym_hash_enable_mask[idx] |= 11426 (1ULL << offset); 11427 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11428 RTE_ETH_FILTER_SET, &info); 11429 if (ret < 0) 11430 printf("Cannot set global hash configurations by port %d\n", 11431 res->port_id); 11432 else 11433 printf("Global hash configurations have been set " 11434 "succcessfully by port %d\n", res->port_id); 11435 } 11436 11437 cmdline_parse_token_string_t cmd_set_hash_global_config_all = 11438 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11439 set_hash_global_config, "set_hash_global_config"); 11440 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = 11441 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, 11442 port_id, UINT16); 11443 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = 11444 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11445 hash_func, "toeplitz#simple_xor#default"); 11446 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type = 11447 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11448 flow_type, 11449 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#" 11450 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 11451 cmdline_parse_token_string_t cmd_set_hash_global_config_enable = 11452 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, 11453 enable, "enable#disable"); 11454 11455 cmdline_parse_inst_t cmd_set_hash_global_config = { 11456 .f = cmd_set_hash_global_config_parsed, 11457 .data = NULL, 11458 .help_str = "set_hash_global_config <port_id> " 11459 "toeplitz|simple_xor|default " 11460 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11461 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" 11462 "l2_payload enable|disable", 11463 .tokens = { 11464 (void *)&cmd_set_hash_global_config_all, 11465 (void *)&cmd_set_hash_global_config_port_id, 11466 (void *)&cmd_set_hash_global_config_hash_func, 11467 (void *)&cmd_set_hash_global_config_flow_type, 11468 (void *)&cmd_set_hash_global_config_enable, 11469 NULL, 11470 }, 11471 }; 11472 11473 /* Set hash input set */ 11474 struct cmd_set_hash_input_set_result { 11475 cmdline_fixed_string_t set_hash_input_set; 11476 portid_t port_id; 11477 cmdline_fixed_string_t flow_type; 11478 cmdline_fixed_string_t inset_field; 11479 cmdline_fixed_string_t select; 11480 }; 11481 11482 static enum rte_eth_input_set_field 11483 str2inset(char *string) 11484 { 11485 uint16_t i; 11486 11487 static const struct { 11488 char str[32]; 11489 enum rte_eth_input_set_field inset; 11490 } inset_table[] = { 11491 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE}, 11492 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN}, 11493 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN}, 11494 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4}, 11495 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4}, 11496 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS}, 11497 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO}, 11498 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL}, 11499 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6}, 11500 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6}, 11501 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC}, 11502 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER}, 11503 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS}, 11504 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT}, 11505 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT}, 11506 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT}, 11507 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT}, 11508 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT}, 11509 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT}, 11510 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG}, 11511 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY}, 11512 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY}, 11513 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD}, 11514 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD}, 11515 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD}, 11516 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD}, 11517 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD}, 11518 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD}, 11519 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD}, 11520 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD}, 11521 {"none", RTE_ETH_INPUT_SET_NONE}, 11522 }; 11523 11524 for (i = 0; i < RTE_DIM(inset_table); i++) { 11525 if (!strcmp(string, inset_table[i].str)) 11526 return inset_table[i].inset; 11527 } 11528 11529 return RTE_ETH_INPUT_SET_UNKNOWN; 11530 } 11531 11532 static void 11533 cmd_set_hash_input_set_parsed(void *parsed_result, 11534 __rte_unused struct cmdline *cl, 11535 __rte_unused void *data) 11536 { 11537 struct cmd_set_hash_input_set_result *res = parsed_result; 11538 struct rte_eth_hash_filter_info info; 11539 11540 memset(&info, 0, sizeof(info)); 11541 info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT; 11542 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 11543 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 11544 info.info.input_set_conf.inset_size = 1; 11545 if (!strcmp(res->select, "select")) 11546 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 11547 else if (!strcmp(res->select, "add")) 11548 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 11549 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH, 11550 RTE_ETH_FILTER_SET, &info); 11551 } 11552 11553 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = 11554 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11555 set_hash_input_set, "set_hash_input_set"); 11556 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = 11557 TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, 11558 port_id, UINT16); 11559 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = 11560 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11561 flow_type, NULL); 11562 cmdline_parse_token_string_t cmd_set_hash_input_set_field = 11563 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11564 inset_field, 11565 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 11566 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#" 11567 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#" 11568 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#" 11569 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#" 11570 "fld-8th#none"); 11571 cmdline_parse_token_string_t cmd_set_hash_input_set_select = 11572 TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, 11573 select, "select#add"); 11574 11575 cmdline_parse_inst_t cmd_set_hash_input_set = { 11576 .f = cmd_set_hash_input_set_parsed, 11577 .data = NULL, 11578 .help_str = "set_hash_input_set <port_id> " 11579 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11580 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> " 11581 "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" 11582 "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" 11583 "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" 11584 "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|" 11585 "fld-7th|fld-8th|none select|add", 11586 .tokens = { 11587 (void *)&cmd_set_hash_input_set_cmd, 11588 (void *)&cmd_set_hash_input_set_port_id, 11589 (void *)&cmd_set_hash_input_set_flow_type, 11590 (void *)&cmd_set_hash_input_set_field, 11591 (void *)&cmd_set_hash_input_set_select, 11592 NULL, 11593 }, 11594 }; 11595 11596 /* Set flow director input set */ 11597 struct cmd_set_fdir_input_set_result { 11598 cmdline_fixed_string_t set_fdir_input_set; 11599 portid_t port_id; 11600 cmdline_fixed_string_t flow_type; 11601 cmdline_fixed_string_t inset_field; 11602 cmdline_fixed_string_t select; 11603 }; 11604 11605 static void 11606 cmd_set_fdir_input_set_parsed(void *parsed_result, 11607 __rte_unused struct cmdline *cl, 11608 __rte_unused void *data) 11609 { 11610 struct cmd_set_fdir_input_set_result *res = parsed_result; 11611 struct rte_eth_fdir_filter_info info; 11612 11613 memset(&info, 0, sizeof(info)); 11614 info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT; 11615 info.info.input_set_conf.flow_type = str2flowtype(res->flow_type); 11616 info.info.input_set_conf.field[0] = str2inset(res->inset_field); 11617 info.info.input_set_conf.inset_size = 1; 11618 if (!strcmp(res->select, "select")) 11619 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT; 11620 else if (!strcmp(res->select, "add")) 11621 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD; 11622 rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, 11623 RTE_ETH_FILTER_SET, &info); 11624 } 11625 11626 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = 11627 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11628 set_fdir_input_set, "set_fdir_input_set"); 11629 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = 11630 TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, 11631 port_id, UINT16); 11632 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = 11633 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11634 flow_type, 11635 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" 11636 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); 11637 cmdline_parse_token_string_t cmd_set_fdir_input_set_field = 11638 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11639 inset_field, 11640 "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#" 11641 "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#" 11642 "ipv6-hop-limits#udp-src-port#udp-dst-port#" 11643 "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#" 11644 "sctp-veri-tag#none"); 11645 cmdline_parse_token_string_t cmd_set_fdir_input_set_select = 11646 TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, 11647 select, "select#add"); 11648 11649 cmdline_parse_inst_t cmd_set_fdir_input_set = { 11650 .f = cmd_set_fdir_input_set_parsed, 11651 .data = NULL, 11652 .help_str = "set_fdir_input_set <port_id> " 11653 "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" 11654 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " 11655 "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|" 11656 "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|" 11657 "ipv6-hop-limits|udp-src-port|udp-dst-port|" 11658 "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|" 11659 "sctp-veri-tag|none select|add", 11660 .tokens = { 11661 (void *)&cmd_set_fdir_input_set_cmd, 11662 (void *)&cmd_set_fdir_input_set_port_id, 11663 (void *)&cmd_set_fdir_input_set_flow_type, 11664 (void *)&cmd_set_fdir_input_set_field, 11665 (void *)&cmd_set_fdir_input_set_select, 11666 NULL, 11667 }, 11668 }; 11669 11670 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */ 11671 struct cmd_mcast_addr_result { 11672 cmdline_fixed_string_t mcast_addr_cmd; 11673 cmdline_fixed_string_t what; 11674 uint16_t port_num; 11675 struct ether_addr mc_addr; 11676 }; 11677 11678 static void cmd_mcast_addr_parsed(void *parsed_result, 11679 __attribute__((unused)) struct cmdline *cl, 11680 __attribute__((unused)) void *data) 11681 { 11682 struct cmd_mcast_addr_result *res = parsed_result; 11683 11684 if (!is_multicast_ether_addr(&res->mc_addr)) { 11685 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n", 11686 res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1], 11687 res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3], 11688 res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]); 11689 return; 11690 } 11691 if (strcmp(res->what, "add") == 0) 11692 mcast_addr_add(res->port_num, &res->mc_addr); 11693 else 11694 mcast_addr_remove(res->port_num, &res->mc_addr); 11695 } 11696 11697 cmdline_parse_token_string_t cmd_mcast_addr_cmd = 11698 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, 11699 mcast_addr_cmd, "mcast_addr"); 11700 cmdline_parse_token_string_t cmd_mcast_addr_what = 11701 TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, 11702 "add#remove"); 11703 cmdline_parse_token_num_t cmd_mcast_addr_portnum = 11704 TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16); 11705 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = 11706 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); 11707 11708 cmdline_parse_inst_t cmd_mcast_addr = { 11709 .f = cmd_mcast_addr_parsed, 11710 .data = (void *)0, 11711 .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: " 11712 "Add/Remove multicast MAC address on port_id", 11713 .tokens = { 11714 (void *)&cmd_mcast_addr_cmd, 11715 (void *)&cmd_mcast_addr_what, 11716 (void *)&cmd_mcast_addr_portnum, 11717 (void *)&cmd_mcast_addr_addr, 11718 NULL, 11719 }, 11720 }; 11721 11722 /* l2 tunnel config 11723 * only support E-tag now. 11724 */ 11725 11726 /* Ether type config */ 11727 struct cmd_config_l2_tunnel_eth_type_result { 11728 cmdline_fixed_string_t port; 11729 cmdline_fixed_string_t config; 11730 cmdline_fixed_string_t all; 11731 uint8_t id; 11732 cmdline_fixed_string_t l2_tunnel; 11733 cmdline_fixed_string_t l2_tunnel_type; 11734 cmdline_fixed_string_t eth_type; 11735 uint16_t eth_type_val; 11736 }; 11737 11738 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port = 11739 TOKEN_STRING_INITIALIZER 11740 (struct cmd_config_l2_tunnel_eth_type_result, 11741 port, "port"); 11742 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config = 11743 TOKEN_STRING_INITIALIZER 11744 (struct cmd_config_l2_tunnel_eth_type_result, 11745 config, "config"); 11746 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str = 11747 TOKEN_STRING_INITIALIZER 11748 (struct cmd_config_l2_tunnel_eth_type_result, 11749 all, "all"); 11750 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id = 11751 TOKEN_NUM_INITIALIZER 11752 (struct cmd_config_l2_tunnel_eth_type_result, 11753 id, UINT8); 11754 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel = 11755 TOKEN_STRING_INITIALIZER 11756 (struct cmd_config_l2_tunnel_eth_type_result, 11757 l2_tunnel, "l2-tunnel"); 11758 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type = 11759 TOKEN_STRING_INITIALIZER 11760 (struct cmd_config_l2_tunnel_eth_type_result, 11761 l2_tunnel_type, "E-tag"); 11762 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type = 11763 TOKEN_STRING_INITIALIZER 11764 (struct cmd_config_l2_tunnel_eth_type_result, 11765 eth_type, "ether-type"); 11766 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val = 11767 TOKEN_NUM_INITIALIZER 11768 (struct cmd_config_l2_tunnel_eth_type_result, 11769 eth_type_val, UINT16); 11770 11771 static enum rte_eth_tunnel_type 11772 str2fdir_l2_tunnel_type(char *string) 11773 { 11774 uint32_t i = 0; 11775 11776 static const struct { 11777 char str[32]; 11778 enum rte_eth_tunnel_type type; 11779 } l2_tunnel_type_str[] = { 11780 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG}, 11781 }; 11782 11783 for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) { 11784 if (!strcmp(l2_tunnel_type_str[i].str, string)) 11785 return l2_tunnel_type_str[i].type; 11786 } 11787 return RTE_TUNNEL_TYPE_NONE; 11788 } 11789 11790 /* ether type config for all ports */ 11791 static void 11792 cmd_config_l2_tunnel_eth_type_all_parsed 11793 (void *parsed_result, 11794 __attribute__((unused)) struct cmdline *cl, 11795 __attribute__((unused)) void *data) 11796 { 11797 struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result; 11798 struct rte_eth_l2_tunnel_conf entry; 11799 portid_t pid; 11800 11801 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11802 entry.ether_type = res->eth_type_val; 11803 11804 RTE_ETH_FOREACH_DEV(pid) { 11805 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry); 11806 } 11807 } 11808 11809 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = { 11810 .f = cmd_config_l2_tunnel_eth_type_all_parsed, 11811 .data = NULL, 11812 .help_str = "port config all l2-tunnel E-tag ether-type <value>", 11813 .tokens = { 11814 (void *)&cmd_config_l2_tunnel_eth_type_port, 11815 (void *)&cmd_config_l2_tunnel_eth_type_config, 11816 (void *)&cmd_config_l2_tunnel_eth_type_all_str, 11817 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 11818 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 11819 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 11820 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 11821 NULL, 11822 }, 11823 }; 11824 11825 /* ether type config for a specific port */ 11826 static void 11827 cmd_config_l2_tunnel_eth_type_specific_parsed( 11828 void *parsed_result, 11829 __attribute__((unused)) struct cmdline *cl, 11830 __attribute__((unused)) void *data) 11831 { 11832 struct cmd_config_l2_tunnel_eth_type_result *res = 11833 parsed_result; 11834 struct rte_eth_l2_tunnel_conf entry; 11835 11836 if (port_id_is_invalid(res->id, ENABLED_WARN)) 11837 return; 11838 11839 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11840 entry.ether_type = res->eth_type_val; 11841 11842 rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry); 11843 } 11844 11845 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = { 11846 .f = cmd_config_l2_tunnel_eth_type_specific_parsed, 11847 .data = NULL, 11848 .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>", 11849 .tokens = { 11850 (void *)&cmd_config_l2_tunnel_eth_type_port, 11851 (void *)&cmd_config_l2_tunnel_eth_type_config, 11852 (void *)&cmd_config_l2_tunnel_eth_type_id, 11853 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel, 11854 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type, 11855 (void *)&cmd_config_l2_tunnel_eth_type_eth_type, 11856 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val, 11857 NULL, 11858 }, 11859 }; 11860 11861 /* Enable/disable l2 tunnel */ 11862 struct cmd_config_l2_tunnel_en_dis_result { 11863 cmdline_fixed_string_t port; 11864 cmdline_fixed_string_t config; 11865 cmdline_fixed_string_t all; 11866 uint8_t id; 11867 cmdline_fixed_string_t l2_tunnel; 11868 cmdline_fixed_string_t l2_tunnel_type; 11869 cmdline_fixed_string_t en_dis; 11870 }; 11871 11872 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port = 11873 TOKEN_STRING_INITIALIZER 11874 (struct cmd_config_l2_tunnel_en_dis_result, 11875 port, "port"); 11876 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config = 11877 TOKEN_STRING_INITIALIZER 11878 (struct cmd_config_l2_tunnel_en_dis_result, 11879 config, "config"); 11880 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str = 11881 TOKEN_STRING_INITIALIZER 11882 (struct cmd_config_l2_tunnel_en_dis_result, 11883 all, "all"); 11884 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id = 11885 TOKEN_NUM_INITIALIZER 11886 (struct cmd_config_l2_tunnel_en_dis_result, 11887 id, UINT8); 11888 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel = 11889 TOKEN_STRING_INITIALIZER 11890 (struct cmd_config_l2_tunnel_en_dis_result, 11891 l2_tunnel, "l2-tunnel"); 11892 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type = 11893 TOKEN_STRING_INITIALIZER 11894 (struct cmd_config_l2_tunnel_en_dis_result, 11895 l2_tunnel_type, "E-tag"); 11896 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis = 11897 TOKEN_STRING_INITIALIZER 11898 (struct cmd_config_l2_tunnel_en_dis_result, 11899 en_dis, "enable#disable"); 11900 11901 /* enable/disable l2 tunnel for all ports */ 11902 static void 11903 cmd_config_l2_tunnel_en_dis_all_parsed( 11904 void *parsed_result, 11905 __attribute__((unused)) struct cmdline *cl, 11906 __attribute__((unused)) void *data) 11907 { 11908 struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result; 11909 struct rte_eth_l2_tunnel_conf entry; 11910 portid_t pid; 11911 uint8_t en; 11912 11913 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11914 11915 if (!strcmp("enable", res->en_dis)) 11916 en = 1; 11917 else 11918 en = 0; 11919 11920 RTE_ETH_FOREACH_DEV(pid) { 11921 rte_eth_dev_l2_tunnel_offload_set(pid, 11922 &entry, 11923 ETH_L2_TUNNEL_ENABLE_MASK, 11924 en); 11925 } 11926 } 11927 11928 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = { 11929 .f = cmd_config_l2_tunnel_en_dis_all_parsed, 11930 .data = NULL, 11931 .help_str = "port config all l2-tunnel E-tag enable|disable", 11932 .tokens = { 11933 (void *)&cmd_config_l2_tunnel_en_dis_port, 11934 (void *)&cmd_config_l2_tunnel_en_dis_config, 11935 (void *)&cmd_config_l2_tunnel_en_dis_all_str, 11936 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 11937 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 11938 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 11939 NULL, 11940 }, 11941 }; 11942 11943 /* enable/disable l2 tunnel for a port */ 11944 static void 11945 cmd_config_l2_tunnel_en_dis_specific_parsed( 11946 void *parsed_result, 11947 __attribute__((unused)) struct cmdline *cl, 11948 __attribute__((unused)) void *data) 11949 { 11950 struct cmd_config_l2_tunnel_en_dis_result *res = 11951 parsed_result; 11952 struct rte_eth_l2_tunnel_conf entry; 11953 11954 if (port_id_is_invalid(res->id, ENABLED_WARN)) 11955 return; 11956 11957 entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type); 11958 11959 if (!strcmp("enable", res->en_dis)) 11960 rte_eth_dev_l2_tunnel_offload_set(res->id, 11961 &entry, 11962 ETH_L2_TUNNEL_ENABLE_MASK, 11963 1); 11964 else 11965 rte_eth_dev_l2_tunnel_offload_set(res->id, 11966 &entry, 11967 ETH_L2_TUNNEL_ENABLE_MASK, 11968 0); 11969 } 11970 11971 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = { 11972 .f = cmd_config_l2_tunnel_en_dis_specific_parsed, 11973 .data = NULL, 11974 .help_str = "port config <port_id> l2-tunnel E-tag enable|disable", 11975 .tokens = { 11976 (void *)&cmd_config_l2_tunnel_en_dis_port, 11977 (void *)&cmd_config_l2_tunnel_en_dis_config, 11978 (void *)&cmd_config_l2_tunnel_en_dis_id, 11979 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel, 11980 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type, 11981 (void *)&cmd_config_l2_tunnel_en_dis_en_dis, 11982 NULL, 11983 }, 11984 }; 11985 11986 /* E-tag configuration */ 11987 11988 /* Common result structure for all E-tag configuration */ 11989 struct cmd_config_e_tag_result { 11990 cmdline_fixed_string_t e_tag; 11991 cmdline_fixed_string_t set; 11992 cmdline_fixed_string_t insertion; 11993 cmdline_fixed_string_t stripping; 11994 cmdline_fixed_string_t forwarding; 11995 cmdline_fixed_string_t filter; 11996 cmdline_fixed_string_t add; 11997 cmdline_fixed_string_t del; 11998 cmdline_fixed_string_t on; 11999 cmdline_fixed_string_t off; 12000 cmdline_fixed_string_t on_off; 12001 cmdline_fixed_string_t port_tag_id; 12002 uint32_t port_tag_id_val; 12003 cmdline_fixed_string_t e_tag_id; 12004 uint16_t e_tag_id_val; 12005 cmdline_fixed_string_t dst_pool; 12006 uint8_t dst_pool_val; 12007 cmdline_fixed_string_t port; 12008 portid_t port_id; 12009 cmdline_fixed_string_t vf; 12010 uint8_t vf_id; 12011 }; 12012 12013 /* Common CLI fields for all E-tag configuration */ 12014 cmdline_parse_token_string_t cmd_config_e_tag_e_tag = 12015 TOKEN_STRING_INITIALIZER 12016 (struct cmd_config_e_tag_result, 12017 e_tag, "E-tag"); 12018 cmdline_parse_token_string_t cmd_config_e_tag_set = 12019 TOKEN_STRING_INITIALIZER 12020 (struct cmd_config_e_tag_result, 12021 set, "set"); 12022 cmdline_parse_token_string_t cmd_config_e_tag_insertion = 12023 TOKEN_STRING_INITIALIZER 12024 (struct cmd_config_e_tag_result, 12025 insertion, "insertion"); 12026 cmdline_parse_token_string_t cmd_config_e_tag_stripping = 12027 TOKEN_STRING_INITIALIZER 12028 (struct cmd_config_e_tag_result, 12029 stripping, "stripping"); 12030 cmdline_parse_token_string_t cmd_config_e_tag_forwarding = 12031 TOKEN_STRING_INITIALIZER 12032 (struct cmd_config_e_tag_result, 12033 forwarding, "forwarding"); 12034 cmdline_parse_token_string_t cmd_config_e_tag_filter = 12035 TOKEN_STRING_INITIALIZER 12036 (struct cmd_config_e_tag_result, 12037 filter, "filter"); 12038 cmdline_parse_token_string_t cmd_config_e_tag_add = 12039 TOKEN_STRING_INITIALIZER 12040 (struct cmd_config_e_tag_result, 12041 add, "add"); 12042 cmdline_parse_token_string_t cmd_config_e_tag_del = 12043 TOKEN_STRING_INITIALIZER 12044 (struct cmd_config_e_tag_result, 12045 del, "del"); 12046 cmdline_parse_token_string_t cmd_config_e_tag_on = 12047 TOKEN_STRING_INITIALIZER 12048 (struct cmd_config_e_tag_result, 12049 on, "on"); 12050 cmdline_parse_token_string_t cmd_config_e_tag_off = 12051 TOKEN_STRING_INITIALIZER 12052 (struct cmd_config_e_tag_result, 12053 off, "off"); 12054 cmdline_parse_token_string_t cmd_config_e_tag_on_off = 12055 TOKEN_STRING_INITIALIZER 12056 (struct cmd_config_e_tag_result, 12057 on_off, "on#off"); 12058 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id = 12059 TOKEN_STRING_INITIALIZER 12060 (struct cmd_config_e_tag_result, 12061 port_tag_id, "port-tag-id"); 12062 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val = 12063 TOKEN_NUM_INITIALIZER 12064 (struct cmd_config_e_tag_result, 12065 port_tag_id_val, UINT32); 12066 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id = 12067 TOKEN_STRING_INITIALIZER 12068 (struct cmd_config_e_tag_result, 12069 e_tag_id, "e-tag-id"); 12070 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val = 12071 TOKEN_NUM_INITIALIZER 12072 (struct cmd_config_e_tag_result, 12073 e_tag_id_val, UINT16); 12074 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool = 12075 TOKEN_STRING_INITIALIZER 12076 (struct cmd_config_e_tag_result, 12077 dst_pool, "dst-pool"); 12078 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val = 12079 TOKEN_NUM_INITIALIZER 12080 (struct cmd_config_e_tag_result, 12081 dst_pool_val, UINT8); 12082 cmdline_parse_token_string_t cmd_config_e_tag_port = 12083 TOKEN_STRING_INITIALIZER 12084 (struct cmd_config_e_tag_result, 12085 port, "port"); 12086 cmdline_parse_token_num_t cmd_config_e_tag_port_id = 12087 TOKEN_NUM_INITIALIZER 12088 (struct cmd_config_e_tag_result, 12089 port_id, UINT16); 12090 cmdline_parse_token_string_t cmd_config_e_tag_vf = 12091 TOKEN_STRING_INITIALIZER 12092 (struct cmd_config_e_tag_result, 12093 vf, "vf"); 12094 cmdline_parse_token_num_t cmd_config_e_tag_vf_id = 12095 TOKEN_NUM_INITIALIZER 12096 (struct cmd_config_e_tag_result, 12097 vf_id, UINT8); 12098 12099 /* E-tag insertion configuration */ 12100 static void 12101 cmd_config_e_tag_insertion_en_parsed( 12102 void *parsed_result, 12103 __attribute__((unused)) struct cmdline *cl, 12104 __attribute__((unused)) void *data) 12105 { 12106 struct cmd_config_e_tag_result *res = 12107 parsed_result; 12108 struct rte_eth_l2_tunnel_conf entry; 12109 12110 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12111 return; 12112 12113 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12114 entry.tunnel_id = res->port_tag_id_val; 12115 entry.vf_id = res->vf_id; 12116 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 12117 &entry, 12118 ETH_L2_TUNNEL_INSERTION_MASK, 12119 1); 12120 } 12121 12122 static void 12123 cmd_config_e_tag_insertion_dis_parsed( 12124 void *parsed_result, 12125 __attribute__((unused)) struct cmdline *cl, 12126 __attribute__((unused)) void *data) 12127 { 12128 struct cmd_config_e_tag_result *res = 12129 parsed_result; 12130 struct rte_eth_l2_tunnel_conf entry; 12131 12132 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12133 return; 12134 12135 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12136 entry.vf_id = res->vf_id; 12137 12138 rte_eth_dev_l2_tunnel_offload_set(res->port_id, 12139 &entry, 12140 ETH_L2_TUNNEL_INSERTION_MASK, 12141 0); 12142 } 12143 12144 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = { 12145 .f = cmd_config_e_tag_insertion_en_parsed, 12146 .data = NULL, 12147 .help_str = "E-tag ... : E-tag insertion enable", 12148 .tokens = { 12149 (void *)&cmd_config_e_tag_e_tag, 12150 (void *)&cmd_config_e_tag_set, 12151 (void *)&cmd_config_e_tag_insertion, 12152 (void *)&cmd_config_e_tag_on, 12153 (void *)&cmd_config_e_tag_port_tag_id, 12154 (void *)&cmd_config_e_tag_port_tag_id_val, 12155 (void *)&cmd_config_e_tag_port, 12156 (void *)&cmd_config_e_tag_port_id, 12157 (void *)&cmd_config_e_tag_vf, 12158 (void *)&cmd_config_e_tag_vf_id, 12159 NULL, 12160 }, 12161 }; 12162 12163 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = { 12164 .f = cmd_config_e_tag_insertion_dis_parsed, 12165 .data = NULL, 12166 .help_str = "E-tag ... : E-tag insertion disable", 12167 .tokens = { 12168 (void *)&cmd_config_e_tag_e_tag, 12169 (void *)&cmd_config_e_tag_set, 12170 (void *)&cmd_config_e_tag_insertion, 12171 (void *)&cmd_config_e_tag_off, 12172 (void *)&cmd_config_e_tag_port, 12173 (void *)&cmd_config_e_tag_port_id, 12174 (void *)&cmd_config_e_tag_vf, 12175 (void *)&cmd_config_e_tag_vf_id, 12176 NULL, 12177 }, 12178 }; 12179 12180 /* E-tag stripping configuration */ 12181 static void 12182 cmd_config_e_tag_stripping_parsed( 12183 void *parsed_result, 12184 __attribute__((unused)) struct cmdline *cl, 12185 __attribute__((unused)) void *data) 12186 { 12187 struct cmd_config_e_tag_result *res = 12188 parsed_result; 12189 struct rte_eth_l2_tunnel_conf entry; 12190 12191 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12192 return; 12193 12194 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12195 12196 if (!strcmp(res->on_off, "on")) 12197 rte_eth_dev_l2_tunnel_offload_set 12198 (res->port_id, 12199 &entry, 12200 ETH_L2_TUNNEL_STRIPPING_MASK, 12201 1); 12202 else 12203 rte_eth_dev_l2_tunnel_offload_set 12204 (res->port_id, 12205 &entry, 12206 ETH_L2_TUNNEL_STRIPPING_MASK, 12207 0); 12208 } 12209 12210 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = { 12211 .f = cmd_config_e_tag_stripping_parsed, 12212 .data = NULL, 12213 .help_str = "E-tag ... : E-tag stripping enable/disable", 12214 .tokens = { 12215 (void *)&cmd_config_e_tag_e_tag, 12216 (void *)&cmd_config_e_tag_set, 12217 (void *)&cmd_config_e_tag_stripping, 12218 (void *)&cmd_config_e_tag_on_off, 12219 (void *)&cmd_config_e_tag_port, 12220 (void *)&cmd_config_e_tag_port_id, 12221 NULL, 12222 }, 12223 }; 12224 12225 /* E-tag forwarding configuration */ 12226 static void 12227 cmd_config_e_tag_forwarding_parsed( 12228 void *parsed_result, 12229 __attribute__((unused)) struct cmdline *cl, 12230 __attribute__((unused)) void *data) 12231 { 12232 struct cmd_config_e_tag_result *res = parsed_result; 12233 struct rte_eth_l2_tunnel_conf entry; 12234 12235 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12236 return; 12237 12238 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12239 12240 if (!strcmp(res->on_off, "on")) 12241 rte_eth_dev_l2_tunnel_offload_set 12242 (res->port_id, 12243 &entry, 12244 ETH_L2_TUNNEL_FORWARDING_MASK, 12245 1); 12246 else 12247 rte_eth_dev_l2_tunnel_offload_set 12248 (res->port_id, 12249 &entry, 12250 ETH_L2_TUNNEL_FORWARDING_MASK, 12251 0); 12252 } 12253 12254 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = { 12255 .f = cmd_config_e_tag_forwarding_parsed, 12256 .data = NULL, 12257 .help_str = "E-tag ... : E-tag forwarding enable/disable", 12258 .tokens = { 12259 (void *)&cmd_config_e_tag_e_tag, 12260 (void *)&cmd_config_e_tag_set, 12261 (void *)&cmd_config_e_tag_forwarding, 12262 (void *)&cmd_config_e_tag_on_off, 12263 (void *)&cmd_config_e_tag_port, 12264 (void *)&cmd_config_e_tag_port_id, 12265 NULL, 12266 }, 12267 }; 12268 12269 /* E-tag filter configuration */ 12270 static void 12271 cmd_config_e_tag_filter_add_parsed( 12272 void *parsed_result, 12273 __attribute__((unused)) struct cmdline *cl, 12274 __attribute__((unused)) void *data) 12275 { 12276 struct cmd_config_e_tag_result *res = parsed_result; 12277 struct rte_eth_l2_tunnel_conf entry; 12278 int ret = 0; 12279 12280 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12281 return; 12282 12283 if (res->e_tag_id_val > 0x3fff) { 12284 printf("e-tag-id must be equal or less than 0x3fff.\n"); 12285 return; 12286 } 12287 12288 ret = rte_eth_dev_filter_supported(res->port_id, 12289 RTE_ETH_FILTER_L2_TUNNEL); 12290 if (ret < 0) { 12291 printf("E-tag filter is not supported on port %u.\n", 12292 res->port_id); 12293 return; 12294 } 12295 12296 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12297 entry.tunnel_id = res->e_tag_id_val; 12298 entry.pool = res->dst_pool_val; 12299 12300 ret = rte_eth_dev_filter_ctrl(res->port_id, 12301 RTE_ETH_FILTER_L2_TUNNEL, 12302 RTE_ETH_FILTER_ADD, 12303 &entry); 12304 if (ret < 0) 12305 printf("E-tag filter programming error: (%s)\n", 12306 strerror(-ret)); 12307 } 12308 12309 cmdline_parse_inst_t cmd_config_e_tag_filter_add = { 12310 .f = cmd_config_e_tag_filter_add_parsed, 12311 .data = NULL, 12312 .help_str = "E-tag ... : E-tag filter add", 12313 .tokens = { 12314 (void *)&cmd_config_e_tag_e_tag, 12315 (void *)&cmd_config_e_tag_set, 12316 (void *)&cmd_config_e_tag_filter, 12317 (void *)&cmd_config_e_tag_add, 12318 (void *)&cmd_config_e_tag_e_tag_id, 12319 (void *)&cmd_config_e_tag_e_tag_id_val, 12320 (void *)&cmd_config_e_tag_dst_pool, 12321 (void *)&cmd_config_e_tag_dst_pool_val, 12322 (void *)&cmd_config_e_tag_port, 12323 (void *)&cmd_config_e_tag_port_id, 12324 NULL, 12325 }, 12326 }; 12327 12328 static void 12329 cmd_config_e_tag_filter_del_parsed( 12330 void *parsed_result, 12331 __attribute__((unused)) struct cmdline *cl, 12332 __attribute__((unused)) void *data) 12333 { 12334 struct cmd_config_e_tag_result *res = parsed_result; 12335 struct rte_eth_l2_tunnel_conf entry; 12336 int ret = 0; 12337 12338 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12339 return; 12340 12341 if (res->e_tag_id_val > 0x3fff) { 12342 printf("e-tag-id must be less than 0x3fff.\n"); 12343 return; 12344 } 12345 12346 ret = rte_eth_dev_filter_supported(res->port_id, 12347 RTE_ETH_FILTER_L2_TUNNEL); 12348 if (ret < 0) { 12349 printf("E-tag filter is not supported on port %u.\n", 12350 res->port_id); 12351 return; 12352 } 12353 12354 entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG; 12355 entry.tunnel_id = res->e_tag_id_val; 12356 12357 ret = rte_eth_dev_filter_ctrl(res->port_id, 12358 RTE_ETH_FILTER_L2_TUNNEL, 12359 RTE_ETH_FILTER_DELETE, 12360 &entry); 12361 if (ret < 0) 12362 printf("E-tag filter programming error: (%s)\n", 12363 strerror(-ret)); 12364 } 12365 12366 cmdline_parse_inst_t cmd_config_e_tag_filter_del = { 12367 .f = cmd_config_e_tag_filter_del_parsed, 12368 .data = NULL, 12369 .help_str = "E-tag ... : E-tag filter delete", 12370 .tokens = { 12371 (void *)&cmd_config_e_tag_e_tag, 12372 (void *)&cmd_config_e_tag_set, 12373 (void *)&cmd_config_e_tag_filter, 12374 (void *)&cmd_config_e_tag_del, 12375 (void *)&cmd_config_e_tag_e_tag_id, 12376 (void *)&cmd_config_e_tag_e_tag_id_val, 12377 (void *)&cmd_config_e_tag_port, 12378 (void *)&cmd_config_e_tag_port_id, 12379 NULL, 12380 }, 12381 }; 12382 12383 /* vf vlan anti spoof configuration */ 12384 12385 /* Common result structure for vf vlan anti spoof */ 12386 struct cmd_vf_vlan_anti_spoof_result { 12387 cmdline_fixed_string_t set; 12388 cmdline_fixed_string_t vf; 12389 cmdline_fixed_string_t vlan; 12390 cmdline_fixed_string_t antispoof; 12391 portid_t port_id; 12392 uint32_t vf_id; 12393 cmdline_fixed_string_t on_off; 12394 }; 12395 12396 /* Common CLI fields for vf vlan anti spoof enable disable */ 12397 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set = 12398 TOKEN_STRING_INITIALIZER 12399 (struct cmd_vf_vlan_anti_spoof_result, 12400 set, "set"); 12401 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf = 12402 TOKEN_STRING_INITIALIZER 12403 (struct cmd_vf_vlan_anti_spoof_result, 12404 vf, "vf"); 12405 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan = 12406 TOKEN_STRING_INITIALIZER 12407 (struct cmd_vf_vlan_anti_spoof_result, 12408 vlan, "vlan"); 12409 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = 12410 TOKEN_STRING_INITIALIZER 12411 (struct cmd_vf_vlan_anti_spoof_result, 12412 antispoof, "antispoof"); 12413 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = 12414 TOKEN_NUM_INITIALIZER 12415 (struct cmd_vf_vlan_anti_spoof_result, 12416 port_id, UINT16); 12417 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = 12418 TOKEN_NUM_INITIALIZER 12419 (struct cmd_vf_vlan_anti_spoof_result, 12420 vf_id, UINT32); 12421 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off = 12422 TOKEN_STRING_INITIALIZER 12423 (struct cmd_vf_vlan_anti_spoof_result, 12424 on_off, "on#off"); 12425 12426 static void 12427 cmd_set_vf_vlan_anti_spoof_parsed( 12428 void *parsed_result, 12429 __attribute__((unused)) struct cmdline *cl, 12430 __attribute__((unused)) void *data) 12431 { 12432 struct cmd_vf_vlan_anti_spoof_result *res = parsed_result; 12433 int ret = -ENOTSUP; 12434 12435 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12436 12437 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12438 return; 12439 12440 #ifdef RTE_LIBRTE_IXGBE_PMD 12441 if (ret == -ENOTSUP) 12442 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id, 12443 res->vf_id, is_on); 12444 #endif 12445 #ifdef RTE_LIBRTE_I40E_PMD 12446 if (ret == -ENOTSUP) 12447 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id, 12448 res->vf_id, is_on); 12449 #endif 12450 #ifdef RTE_LIBRTE_BNXT_PMD 12451 if (ret == -ENOTSUP) 12452 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id, 12453 res->vf_id, is_on); 12454 #endif 12455 12456 switch (ret) { 12457 case 0: 12458 break; 12459 case -EINVAL: 12460 printf("invalid vf_id %d\n", res->vf_id); 12461 break; 12462 case -ENODEV: 12463 printf("invalid port_id %d\n", res->port_id); 12464 break; 12465 case -ENOTSUP: 12466 printf("function not implemented\n"); 12467 break; 12468 default: 12469 printf("programming error: (%s)\n", strerror(-ret)); 12470 } 12471 } 12472 12473 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = { 12474 .f = cmd_set_vf_vlan_anti_spoof_parsed, 12475 .data = NULL, 12476 .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off", 12477 .tokens = { 12478 (void *)&cmd_vf_vlan_anti_spoof_set, 12479 (void *)&cmd_vf_vlan_anti_spoof_vf, 12480 (void *)&cmd_vf_vlan_anti_spoof_vlan, 12481 (void *)&cmd_vf_vlan_anti_spoof_antispoof, 12482 (void *)&cmd_vf_vlan_anti_spoof_port_id, 12483 (void *)&cmd_vf_vlan_anti_spoof_vf_id, 12484 (void *)&cmd_vf_vlan_anti_spoof_on_off, 12485 NULL, 12486 }, 12487 }; 12488 12489 /* vf mac anti spoof configuration */ 12490 12491 /* Common result structure for vf mac anti spoof */ 12492 struct cmd_vf_mac_anti_spoof_result { 12493 cmdline_fixed_string_t set; 12494 cmdline_fixed_string_t vf; 12495 cmdline_fixed_string_t mac; 12496 cmdline_fixed_string_t antispoof; 12497 portid_t port_id; 12498 uint32_t vf_id; 12499 cmdline_fixed_string_t on_off; 12500 }; 12501 12502 /* Common CLI fields for vf mac anti spoof enable disable */ 12503 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set = 12504 TOKEN_STRING_INITIALIZER 12505 (struct cmd_vf_mac_anti_spoof_result, 12506 set, "set"); 12507 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf = 12508 TOKEN_STRING_INITIALIZER 12509 (struct cmd_vf_mac_anti_spoof_result, 12510 vf, "vf"); 12511 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac = 12512 TOKEN_STRING_INITIALIZER 12513 (struct cmd_vf_mac_anti_spoof_result, 12514 mac, "mac"); 12515 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = 12516 TOKEN_STRING_INITIALIZER 12517 (struct cmd_vf_mac_anti_spoof_result, 12518 antispoof, "antispoof"); 12519 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = 12520 TOKEN_NUM_INITIALIZER 12521 (struct cmd_vf_mac_anti_spoof_result, 12522 port_id, UINT16); 12523 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = 12524 TOKEN_NUM_INITIALIZER 12525 (struct cmd_vf_mac_anti_spoof_result, 12526 vf_id, UINT32); 12527 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off = 12528 TOKEN_STRING_INITIALIZER 12529 (struct cmd_vf_mac_anti_spoof_result, 12530 on_off, "on#off"); 12531 12532 static void 12533 cmd_set_vf_mac_anti_spoof_parsed( 12534 void *parsed_result, 12535 __attribute__((unused)) struct cmdline *cl, 12536 __attribute__((unused)) void *data) 12537 { 12538 struct cmd_vf_mac_anti_spoof_result *res = parsed_result; 12539 int ret = -ENOTSUP; 12540 12541 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12542 12543 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12544 return; 12545 12546 #ifdef RTE_LIBRTE_IXGBE_PMD 12547 if (ret == -ENOTSUP) 12548 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id, 12549 res->vf_id, is_on); 12550 #endif 12551 #ifdef RTE_LIBRTE_I40E_PMD 12552 if (ret == -ENOTSUP) 12553 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id, 12554 res->vf_id, is_on); 12555 #endif 12556 #ifdef RTE_LIBRTE_BNXT_PMD 12557 if (ret == -ENOTSUP) 12558 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id, 12559 res->vf_id, is_on); 12560 #endif 12561 12562 switch (ret) { 12563 case 0: 12564 break; 12565 case -EINVAL: 12566 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12567 break; 12568 case -ENODEV: 12569 printf("invalid port_id %d\n", res->port_id); 12570 break; 12571 case -ENOTSUP: 12572 printf("function not implemented\n"); 12573 break; 12574 default: 12575 printf("programming error: (%s)\n", strerror(-ret)); 12576 } 12577 } 12578 12579 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = { 12580 .f = cmd_set_vf_mac_anti_spoof_parsed, 12581 .data = NULL, 12582 .help_str = "set vf mac antispoof <port_id> <vf_id> on|off", 12583 .tokens = { 12584 (void *)&cmd_vf_mac_anti_spoof_set, 12585 (void *)&cmd_vf_mac_anti_spoof_vf, 12586 (void *)&cmd_vf_mac_anti_spoof_mac, 12587 (void *)&cmd_vf_mac_anti_spoof_antispoof, 12588 (void *)&cmd_vf_mac_anti_spoof_port_id, 12589 (void *)&cmd_vf_mac_anti_spoof_vf_id, 12590 (void *)&cmd_vf_mac_anti_spoof_on_off, 12591 NULL, 12592 }, 12593 }; 12594 12595 /* vf vlan strip queue configuration */ 12596 12597 /* Common result structure for vf mac anti spoof */ 12598 struct cmd_vf_vlan_stripq_result { 12599 cmdline_fixed_string_t set; 12600 cmdline_fixed_string_t vf; 12601 cmdline_fixed_string_t vlan; 12602 cmdline_fixed_string_t stripq; 12603 portid_t port_id; 12604 uint16_t vf_id; 12605 cmdline_fixed_string_t on_off; 12606 }; 12607 12608 /* Common CLI fields for vf vlan strip enable disable */ 12609 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set = 12610 TOKEN_STRING_INITIALIZER 12611 (struct cmd_vf_vlan_stripq_result, 12612 set, "set"); 12613 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf = 12614 TOKEN_STRING_INITIALIZER 12615 (struct cmd_vf_vlan_stripq_result, 12616 vf, "vf"); 12617 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan = 12618 TOKEN_STRING_INITIALIZER 12619 (struct cmd_vf_vlan_stripq_result, 12620 vlan, "vlan"); 12621 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = 12622 TOKEN_STRING_INITIALIZER 12623 (struct cmd_vf_vlan_stripq_result, 12624 stripq, "stripq"); 12625 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = 12626 TOKEN_NUM_INITIALIZER 12627 (struct cmd_vf_vlan_stripq_result, 12628 port_id, UINT16); 12629 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = 12630 TOKEN_NUM_INITIALIZER 12631 (struct cmd_vf_vlan_stripq_result, 12632 vf_id, UINT16); 12633 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off = 12634 TOKEN_STRING_INITIALIZER 12635 (struct cmd_vf_vlan_stripq_result, 12636 on_off, "on#off"); 12637 12638 static void 12639 cmd_set_vf_vlan_stripq_parsed( 12640 void *parsed_result, 12641 __attribute__((unused)) struct cmdline *cl, 12642 __attribute__((unused)) void *data) 12643 { 12644 struct cmd_vf_vlan_stripq_result *res = parsed_result; 12645 int ret = -ENOTSUP; 12646 12647 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12648 12649 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12650 return; 12651 12652 #ifdef RTE_LIBRTE_IXGBE_PMD 12653 if (ret == -ENOTSUP) 12654 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id, 12655 res->vf_id, is_on); 12656 #endif 12657 #ifdef RTE_LIBRTE_I40E_PMD 12658 if (ret == -ENOTSUP) 12659 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id, 12660 res->vf_id, is_on); 12661 #endif 12662 #ifdef RTE_LIBRTE_BNXT_PMD 12663 if (ret == -ENOTSUP) 12664 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id, 12665 res->vf_id, is_on); 12666 #endif 12667 12668 switch (ret) { 12669 case 0: 12670 break; 12671 case -EINVAL: 12672 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 12673 break; 12674 case -ENODEV: 12675 printf("invalid port_id %d\n", res->port_id); 12676 break; 12677 case -ENOTSUP: 12678 printf("function not implemented\n"); 12679 break; 12680 default: 12681 printf("programming error: (%s)\n", strerror(-ret)); 12682 } 12683 } 12684 12685 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = { 12686 .f = cmd_set_vf_vlan_stripq_parsed, 12687 .data = NULL, 12688 .help_str = "set vf vlan stripq <port_id> <vf_id> on|off", 12689 .tokens = { 12690 (void *)&cmd_vf_vlan_stripq_set, 12691 (void *)&cmd_vf_vlan_stripq_vf, 12692 (void *)&cmd_vf_vlan_stripq_vlan, 12693 (void *)&cmd_vf_vlan_stripq_stripq, 12694 (void *)&cmd_vf_vlan_stripq_port_id, 12695 (void *)&cmd_vf_vlan_stripq_vf_id, 12696 (void *)&cmd_vf_vlan_stripq_on_off, 12697 NULL, 12698 }, 12699 }; 12700 12701 /* vf vlan insert configuration */ 12702 12703 /* Common result structure for vf vlan insert */ 12704 struct cmd_vf_vlan_insert_result { 12705 cmdline_fixed_string_t set; 12706 cmdline_fixed_string_t vf; 12707 cmdline_fixed_string_t vlan; 12708 cmdline_fixed_string_t insert; 12709 portid_t port_id; 12710 uint16_t vf_id; 12711 uint16_t vlan_id; 12712 }; 12713 12714 /* Common CLI fields for vf vlan insert enable disable */ 12715 cmdline_parse_token_string_t cmd_vf_vlan_insert_set = 12716 TOKEN_STRING_INITIALIZER 12717 (struct cmd_vf_vlan_insert_result, 12718 set, "set"); 12719 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf = 12720 TOKEN_STRING_INITIALIZER 12721 (struct cmd_vf_vlan_insert_result, 12722 vf, "vf"); 12723 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan = 12724 TOKEN_STRING_INITIALIZER 12725 (struct cmd_vf_vlan_insert_result, 12726 vlan, "vlan"); 12727 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = 12728 TOKEN_STRING_INITIALIZER 12729 (struct cmd_vf_vlan_insert_result, 12730 insert, "insert"); 12731 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = 12732 TOKEN_NUM_INITIALIZER 12733 (struct cmd_vf_vlan_insert_result, 12734 port_id, UINT16); 12735 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = 12736 TOKEN_NUM_INITIALIZER 12737 (struct cmd_vf_vlan_insert_result, 12738 vf_id, UINT16); 12739 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id = 12740 TOKEN_NUM_INITIALIZER 12741 (struct cmd_vf_vlan_insert_result, 12742 vlan_id, UINT16); 12743 12744 static void 12745 cmd_set_vf_vlan_insert_parsed( 12746 void *parsed_result, 12747 __attribute__((unused)) struct cmdline *cl, 12748 __attribute__((unused)) void *data) 12749 { 12750 struct cmd_vf_vlan_insert_result *res = parsed_result; 12751 int ret = -ENOTSUP; 12752 12753 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12754 return; 12755 12756 #ifdef RTE_LIBRTE_IXGBE_PMD 12757 if (ret == -ENOTSUP) 12758 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id, 12759 res->vlan_id); 12760 #endif 12761 #ifdef RTE_LIBRTE_I40E_PMD 12762 if (ret == -ENOTSUP) 12763 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id, 12764 res->vlan_id); 12765 #endif 12766 #ifdef RTE_LIBRTE_BNXT_PMD 12767 if (ret == -ENOTSUP) 12768 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id, 12769 res->vlan_id); 12770 #endif 12771 12772 switch (ret) { 12773 case 0: 12774 break; 12775 case -EINVAL: 12776 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id); 12777 break; 12778 case -ENODEV: 12779 printf("invalid port_id %d\n", res->port_id); 12780 break; 12781 case -ENOTSUP: 12782 printf("function not implemented\n"); 12783 break; 12784 default: 12785 printf("programming error: (%s)\n", strerror(-ret)); 12786 } 12787 } 12788 12789 cmdline_parse_inst_t cmd_set_vf_vlan_insert = { 12790 .f = cmd_set_vf_vlan_insert_parsed, 12791 .data = NULL, 12792 .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>", 12793 .tokens = { 12794 (void *)&cmd_vf_vlan_insert_set, 12795 (void *)&cmd_vf_vlan_insert_vf, 12796 (void *)&cmd_vf_vlan_insert_vlan, 12797 (void *)&cmd_vf_vlan_insert_insert, 12798 (void *)&cmd_vf_vlan_insert_port_id, 12799 (void *)&cmd_vf_vlan_insert_vf_id, 12800 (void *)&cmd_vf_vlan_insert_vlan_id, 12801 NULL, 12802 }, 12803 }; 12804 12805 /* tx loopback configuration */ 12806 12807 /* Common result structure for tx loopback */ 12808 struct cmd_tx_loopback_result { 12809 cmdline_fixed_string_t set; 12810 cmdline_fixed_string_t tx; 12811 cmdline_fixed_string_t loopback; 12812 portid_t port_id; 12813 cmdline_fixed_string_t on_off; 12814 }; 12815 12816 /* Common CLI fields for tx loopback enable disable */ 12817 cmdline_parse_token_string_t cmd_tx_loopback_set = 12818 TOKEN_STRING_INITIALIZER 12819 (struct cmd_tx_loopback_result, 12820 set, "set"); 12821 cmdline_parse_token_string_t cmd_tx_loopback_tx = 12822 TOKEN_STRING_INITIALIZER 12823 (struct cmd_tx_loopback_result, 12824 tx, "tx"); 12825 cmdline_parse_token_string_t cmd_tx_loopback_loopback = 12826 TOKEN_STRING_INITIALIZER 12827 (struct cmd_tx_loopback_result, 12828 loopback, "loopback"); 12829 cmdline_parse_token_num_t cmd_tx_loopback_port_id = 12830 TOKEN_NUM_INITIALIZER 12831 (struct cmd_tx_loopback_result, 12832 port_id, UINT16); 12833 cmdline_parse_token_string_t cmd_tx_loopback_on_off = 12834 TOKEN_STRING_INITIALIZER 12835 (struct cmd_tx_loopback_result, 12836 on_off, "on#off"); 12837 12838 static void 12839 cmd_set_tx_loopback_parsed( 12840 void *parsed_result, 12841 __attribute__((unused)) struct cmdline *cl, 12842 __attribute__((unused)) void *data) 12843 { 12844 struct cmd_tx_loopback_result *res = parsed_result; 12845 int ret = -ENOTSUP; 12846 12847 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12848 12849 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12850 return; 12851 12852 #ifdef RTE_LIBRTE_IXGBE_PMD 12853 if (ret == -ENOTSUP) 12854 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on); 12855 #endif 12856 #ifdef RTE_LIBRTE_I40E_PMD 12857 if (ret == -ENOTSUP) 12858 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on); 12859 #endif 12860 #ifdef RTE_LIBRTE_BNXT_PMD 12861 if (ret == -ENOTSUP) 12862 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on); 12863 #endif 12864 #ifdef RTE_LIBRTE_DPAA_PMD 12865 if (ret == -ENOTSUP) 12866 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on); 12867 #endif 12868 12869 switch (ret) { 12870 case 0: 12871 break; 12872 case -EINVAL: 12873 printf("invalid is_on %d\n", is_on); 12874 break; 12875 case -ENODEV: 12876 printf("invalid port_id %d\n", res->port_id); 12877 break; 12878 case -ENOTSUP: 12879 printf("function not implemented\n"); 12880 break; 12881 default: 12882 printf("programming error: (%s)\n", strerror(-ret)); 12883 } 12884 } 12885 12886 cmdline_parse_inst_t cmd_set_tx_loopback = { 12887 .f = cmd_set_tx_loopback_parsed, 12888 .data = NULL, 12889 .help_str = "set tx loopback <port_id> on|off", 12890 .tokens = { 12891 (void *)&cmd_tx_loopback_set, 12892 (void *)&cmd_tx_loopback_tx, 12893 (void *)&cmd_tx_loopback_loopback, 12894 (void *)&cmd_tx_loopback_port_id, 12895 (void *)&cmd_tx_loopback_on_off, 12896 NULL, 12897 }, 12898 }; 12899 12900 /* all queues drop enable configuration */ 12901 12902 /* Common result structure for all queues drop enable */ 12903 struct cmd_all_queues_drop_en_result { 12904 cmdline_fixed_string_t set; 12905 cmdline_fixed_string_t all; 12906 cmdline_fixed_string_t queues; 12907 cmdline_fixed_string_t drop; 12908 portid_t port_id; 12909 cmdline_fixed_string_t on_off; 12910 }; 12911 12912 /* Common CLI fields for tx loopback enable disable */ 12913 cmdline_parse_token_string_t cmd_all_queues_drop_en_set = 12914 TOKEN_STRING_INITIALIZER 12915 (struct cmd_all_queues_drop_en_result, 12916 set, "set"); 12917 cmdline_parse_token_string_t cmd_all_queues_drop_en_all = 12918 TOKEN_STRING_INITIALIZER 12919 (struct cmd_all_queues_drop_en_result, 12920 all, "all"); 12921 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues = 12922 TOKEN_STRING_INITIALIZER 12923 (struct cmd_all_queues_drop_en_result, 12924 queues, "queues"); 12925 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = 12926 TOKEN_STRING_INITIALIZER 12927 (struct cmd_all_queues_drop_en_result, 12928 drop, "drop"); 12929 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = 12930 TOKEN_NUM_INITIALIZER 12931 (struct cmd_all_queues_drop_en_result, 12932 port_id, UINT16); 12933 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = 12934 TOKEN_STRING_INITIALIZER 12935 (struct cmd_all_queues_drop_en_result, 12936 on_off, "on#off"); 12937 12938 static void 12939 cmd_set_all_queues_drop_en_parsed( 12940 void *parsed_result, 12941 __attribute__((unused)) struct cmdline *cl, 12942 __attribute__((unused)) void *data) 12943 { 12944 struct cmd_all_queues_drop_en_result *res = parsed_result; 12945 int ret = -ENOTSUP; 12946 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 12947 12948 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 12949 return; 12950 12951 #ifdef RTE_LIBRTE_IXGBE_PMD 12952 if (ret == -ENOTSUP) 12953 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on); 12954 #endif 12955 #ifdef RTE_LIBRTE_BNXT_PMD 12956 if (ret == -ENOTSUP) 12957 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on); 12958 #endif 12959 switch (ret) { 12960 case 0: 12961 break; 12962 case -EINVAL: 12963 printf("invalid is_on %d\n", is_on); 12964 break; 12965 case -ENODEV: 12966 printf("invalid port_id %d\n", res->port_id); 12967 break; 12968 case -ENOTSUP: 12969 printf("function not implemented\n"); 12970 break; 12971 default: 12972 printf("programming error: (%s)\n", strerror(-ret)); 12973 } 12974 } 12975 12976 cmdline_parse_inst_t cmd_set_all_queues_drop_en = { 12977 .f = cmd_set_all_queues_drop_en_parsed, 12978 .data = NULL, 12979 .help_str = "set all queues drop <port_id> on|off", 12980 .tokens = { 12981 (void *)&cmd_all_queues_drop_en_set, 12982 (void *)&cmd_all_queues_drop_en_all, 12983 (void *)&cmd_all_queues_drop_en_queues, 12984 (void *)&cmd_all_queues_drop_en_drop, 12985 (void *)&cmd_all_queues_drop_en_port_id, 12986 (void *)&cmd_all_queues_drop_en_on_off, 12987 NULL, 12988 }, 12989 }; 12990 12991 /* vf split drop enable configuration */ 12992 12993 /* Common result structure for vf split drop enable */ 12994 struct cmd_vf_split_drop_en_result { 12995 cmdline_fixed_string_t set; 12996 cmdline_fixed_string_t vf; 12997 cmdline_fixed_string_t split; 12998 cmdline_fixed_string_t drop; 12999 portid_t port_id; 13000 uint16_t vf_id; 13001 cmdline_fixed_string_t on_off; 13002 }; 13003 13004 /* Common CLI fields for vf split drop enable disable */ 13005 cmdline_parse_token_string_t cmd_vf_split_drop_en_set = 13006 TOKEN_STRING_INITIALIZER 13007 (struct cmd_vf_split_drop_en_result, 13008 set, "set"); 13009 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = 13010 TOKEN_STRING_INITIALIZER 13011 (struct cmd_vf_split_drop_en_result, 13012 vf, "vf"); 13013 cmdline_parse_token_string_t cmd_vf_split_drop_en_split = 13014 TOKEN_STRING_INITIALIZER 13015 (struct cmd_vf_split_drop_en_result, 13016 split, "split"); 13017 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = 13018 TOKEN_STRING_INITIALIZER 13019 (struct cmd_vf_split_drop_en_result, 13020 drop, "drop"); 13021 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = 13022 TOKEN_NUM_INITIALIZER 13023 (struct cmd_vf_split_drop_en_result, 13024 port_id, UINT16); 13025 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = 13026 TOKEN_NUM_INITIALIZER 13027 (struct cmd_vf_split_drop_en_result, 13028 vf_id, UINT16); 13029 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = 13030 TOKEN_STRING_INITIALIZER 13031 (struct cmd_vf_split_drop_en_result, 13032 on_off, "on#off"); 13033 13034 static void 13035 cmd_set_vf_split_drop_en_parsed( 13036 void *parsed_result, 13037 __attribute__((unused)) struct cmdline *cl, 13038 __attribute__((unused)) void *data) 13039 { 13040 struct cmd_vf_split_drop_en_result *res = parsed_result; 13041 int ret = -ENOTSUP; 13042 int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13043 13044 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13045 return; 13046 13047 #ifdef RTE_LIBRTE_IXGBE_PMD 13048 ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, 13049 is_on); 13050 #endif 13051 switch (ret) { 13052 case 0: 13053 break; 13054 case -EINVAL: 13055 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 13056 break; 13057 case -ENODEV: 13058 printf("invalid port_id %d\n", res->port_id); 13059 break; 13060 case -ENOTSUP: 13061 printf("not supported on port %d\n", res->port_id); 13062 break; 13063 default: 13064 printf("programming error: (%s)\n", strerror(-ret)); 13065 } 13066 } 13067 13068 cmdline_parse_inst_t cmd_set_vf_split_drop_en = { 13069 .f = cmd_set_vf_split_drop_en_parsed, 13070 .data = NULL, 13071 .help_str = "set vf split drop <port_id> <vf_id> on|off", 13072 .tokens = { 13073 (void *)&cmd_vf_split_drop_en_set, 13074 (void *)&cmd_vf_split_drop_en_vf, 13075 (void *)&cmd_vf_split_drop_en_split, 13076 (void *)&cmd_vf_split_drop_en_drop, 13077 (void *)&cmd_vf_split_drop_en_port_id, 13078 (void *)&cmd_vf_split_drop_en_vf_id, 13079 (void *)&cmd_vf_split_drop_en_on_off, 13080 NULL, 13081 }, 13082 }; 13083 13084 /* vf mac address configuration */ 13085 13086 /* Common result structure for vf mac address */ 13087 struct cmd_set_vf_mac_addr_result { 13088 cmdline_fixed_string_t set; 13089 cmdline_fixed_string_t vf; 13090 cmdline_fixed_string_t mac; 13091 cmdline_fixed_string_t addr; 13092 portid_t port_id; 13093 uint16_t vf_id; 13094 struct ether_addr mac_addr; 13095 13096 }; 13097 13098 /* Common CLI fields for vf split drop enable disable */ 13099 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set = 13100 TOKEN_STRING_INITIALIZER 13101 (struct cmd_set_vf_mac_addr_result, 13102 set, "set"); 13103 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf = 13104 TOKEN_STRING_INITIALIZER 13105 (struct cmd_set_vf_mac_addr_result, 13106 vf, "vf"); 13107 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac = 13108 TOKEN_STRING_INITIALIZER 13109 (struct cmd_set_vf_mac_addr_result, 13110 mac, "mac"); 13111 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = 13112 TOKEN_STRING_INITIALIZER 13113 (struct cmd_set_vf_mac_addr_result, 13114 addr, "addr"); 13115 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = 13116 TOKEN_NUM_INITIALIZER 13117 (struct cmd_set_vf_mac_addr_result, 13118 port_id, UINT16); 13119 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = 13120 TOKEN_NUM_INITIALIZER 13121 (struct cmd_set_vf_mac_addr_result, 13122 vf_id, UINT16); 13123 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr = 13124 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result, 13125 mac_addr); 13126 13127 static void 13128 cmd_set_vf_mac_addr_parsed( 13129 void *parsed_result, 13130 __attribute__((unused)) struct cmdline *cl, 13131 __attribute__((unused)) void *data) 13132 { 13133 struct cmd_set_vf_mac_addr_result *res = parsed_result; 13134 int ret = -ENOTSUP; 13135 13136 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13137 return; 13138 13139 #ifdef RTE_LIBRTE_IXGBE_PMD 13140 if (ret == -ENOTSUP) 13141 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id, 13142 &res->mac_addr); 13143 #endif 13144 #ifdef RTE_LIBRTE_I40E_PMD 13145 if (ret == -ENOTSUP) 13146 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id, 13147 &res->mac_addr); 13148 #endif 13149 #ifdef RTE_LIBRTE_BNXT_PMD 13150 if (ret == -ENOTSUP) 13151 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id, 13152 &res->mac_addr); 13153 #endif 13154 13155 switch (ret) { 13156 case 0: 13157 break; 13158 case -EINVAL: 13159 printf("invalid vf_id %d or mac_addr\n", res->vf_id); 13160 break; 13161 case -ENODEV: 13162 printf("invalid port_id %d\n", res->port_id); 13163 break; 13164 case -ENOTSUP: 13165 printf("function not implemented\n"); 13166 break; 13167 default: 13168 printf("programming error: (%s)\n", strerror(-ret)); 13169 } 13170 } 13171 13172 cmdline_parse_inst_t cmd_set_vf_mac_addr = { 13173 .f = cmd_set_vf_mac_addr_parsed, 13174 .data = NULL, 13175 .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>", 13176 .tokens = { 13177 (void *)&cmd_set_vf_mac_addr_set, 13178 (void *)&cmd_set_vf_mac_addr_vf, 13179 (void *)&cmd_set_vf_mac_addr_mac, 13180 (void *)&cmd_set_vf_mac_addr_addr, 13181 (void *)&cmd_set_vf_mac_addr_port_id, 13182 (void *)&cmd_set_vf_mac_addr_vf_id, 13183 (void *)&cmd_set_vf_mac_addr_mac_addr, 13184 NULL, 13185 }, 13186 }; 13187 13188 /* MACsec configuration */ 13189 13190 /* Common result structure for MACsec offload enable */ 13191 struct cmd_macsec_offload_on_result { 13192 cmdline_fixed_string_t set; 13193 cmdline_fixed_string_t macsec; 13194 cmdline_fixed_string_t offload; 13195 portid_t port_id; 13196 cmdline_fixed_string_t on; 13197 cmdline_fixed_string_t encrypt; 13198 cmdline_fixed_string_t en_on_off; 13199 cmdline_fixed_string_t replay_protect; 13200 cmdline_fixed_string_t rp_on_off; 13201 }; 13202 13203 /* Common CLI fields for MACsec offload disable */ 13204 cmdline_parse_token_string_t cmd_macsec_offload_on_set = 13205 TOKEN_STRING_INITIALIZER 13206 (struct cmd_macsec_offload_on_result, 13207 set, "set"); 13208 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = 13209 TOKEN_STRING_INITIALIZER 13210 (struct cmd_macsec_offload_on_result, 13211 macsec, "macsec"); 13212 cmdline_parse_token_string_t cmd_macsec_offload_on_offload = 13213 TOKEN_STRING_INITIALIZER 13214 (struct cmd_macsec_offload_on_result, 13215 offload, "offload"); 13216 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = 13217 TOKEN_NUM_INITIALIZER 13218 (struct cmd_macsec_offload_on_result, 13219 port_id, UINT16); 13220 cmdline_parse_token_string_t cmd_macsec_offload_on_on = 13221 TOKEN_STRING_INITIALIZER 13222 (struct cmd_macsec_offload_on_result, 13223 on, "on"); 13224 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = 13225 TOKEN_STRING_INITIALIZER 13226 (struct cmd_macsec_offload_on_result, 13227 encrypt, "encrypt"); 13228 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = 13229 TOKEN_STRING_INITIALIZER 13230 (struct cmd_macsec_offload_on_result, 13231 en_on_off, "on#off"); 13232 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = 13233 TOKEN_STRING_INITIALIZER 13234 (struct cmd_macsec_offload_on_result, 13235 replay_protect, "replay-protect"); 13236 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = 13237 TOKEN_STRING_INITIALIZER 13238 (struct cmd_macsec_offload_on_result, 13239 rp_on_off, "on#off"); 13240 13241 static void 13242 cmd_set_macsec_offload_on_parsed( 13243 void *parsed_result, 13244 __attribute__((unused)) struct cmdline *cl, 13245 __attribute__((unused)) void *data) 13246 { 13247 struct cmd_macsec_offload_on_result *res = parsed_result; 13248 int ret = -ENOTSUP; 13249 portid_t port_id = res->port_id; 13250 int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; 13251 int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; 13252 struct rte_eth_dev_info dev_info; 13253 13254 if (port_id_is_invalid(port_id, ENABLED_WARN)) 13255 return; 13256 if (!port_is_stopped(port_id)) { 13257 printf("Please stop port %d first\n", port_id); 13258 return; 13259 } 13260 13261 rte_eth_dev_info_get(port_id, &dev_info); 13262 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) { 13263 #ifdef RTE_LIBRTE_IXGBE_PMD 13264 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); 13265 #endif 13266 } 13267 RTE_SET_USED(en); 13268 RTE_SET_USED(rp); 13269 13270 switch (ret) { 13271 case 0: 13272 ports[port_id].dev_conf.txmode.offloads |= 13273 DEV_TX_OFFLOAD_MACSEC_INSERT; 13274 cmd_reconfig_device_queue(port_id, 1, 1); 13275 break; 13276 case -ENODEV: 13277 printf("invalid port_id %d\n", port_id); 13278 break; 13279 case -ENOTSUP: 13280 printf("not supported on port %d\n", port_id); 13281 break; 13282 default: 13283 printf("programming error: (%s)\n", strerror(-ret)); 13284 } 13285 } 13286 13287 cmdline_parse_inst_t cmd_set_macsec_offload_on = { 13288 .f = cmd_set_macsec_offload_on_parsed, 13289 .data = NULL, 13290 .help_str = "set macsec offload <port_id> on " 13291 "encrypt on|off replay-protect on|off", 13292 .tokens = { 13293 (void *)&cmd_macsec_offload_on_set, 13294 (void *)&cmd_macsec_offload_on_macsec, 13295 (void *)&cmd_macsec_offload_on_offload, 13296 (void *)&cmd_macsec_offload_on_port_id, 13297 (void *)&cmd_macsec_offload_on_on, 13298 (void *)&cmd_macsec_offload_on_encrypt, 13299 (void *)&cmd_macsec_offload_on_en_on_off, 13300 (void *)&cmd_macsec_offload_on_replay_protect, 13301 (void *)&cmd_macsec_offload_on_rp_on_off, 13302 NULL, 13303 }, 13304 }; 13305 13306 /* Common result structure for MACsec offload disable */ 13307 struct cmd_macsec_offload_off_result { 13308 cmdline_fixed_string_t set; 13309 cmdline_fixed_string_t macsec; 13310 cmdline_fixed_string_t offload; 13311 portid_t port_id; 13312 cmdline_fixed_string_t off; 13313 }; 13314 13315 /* Common CLI fields for MACsec offload disable */ 13316 cmdline_parse_token_string_t cmd_macsec_offload_off_set = 13317 TOKEN_STRING_INITIALIZER 13318 (struct cmd_macsec_offload_off_result, 13319 set, "set"); 13320 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = 13321 TOKEN_STRING_INITIALIZER 13322 (struct cmd_macsec_offload_off_result, 13323 macsec, "macsec"); 13324 cmdline_parse_token_string_t cmd_macsec_offload_off_offload = 13325 TOKEN_STRING_INITIALIZER 13326 (struct cmd_macsec_offload_off_result, 13327 offload, "offload"); 13328 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = 13329 TOKEN_NUM_INITIALIZER 13330 (struct cmd_macsec_offload_off_result, 13331 port_id, UINT16); 13332 cmdline_parse_token_string_t cmd_macsec_offload_off_off = 13333 TOKEN_STRING_INITIALIZER 13334 (struct cmd_macsec_offload_off_result, 13335 off, "off"); 13336 13337 static void 13338 cmd_set_macsec_offload_off_parsed( 13339 void *parsed_result, 13340 __attribute__((unused)) struct cmdline *cl, 13341 __attribute__((unused)) void *data) 13342 { 13343 struct cmd_macsec_offload_off_result *res = parsed_result; 13344 int ret = -ENOTSUP; 13345 struct rte_eth_dev_info dev_info; 13346 portid_t port_id = res->port_id; 13347 13348 if (port_id_is_invalid(port_id, ENABLED_WARN)) 13349 return; 13350 if (!port_is_stopped(port_id)) { 13351 printf("Please stop port %d first\n", port_id); 13352 return; 13353 } 13354 13355 rte_eth_dev_info_get(port_id, &dev_info); 13356 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) { 13357 #ifdef RTE_LIBRTE_IXGBE_PMD 13358 ret = rte_pmd_ixgbe_macsec_disable(port_id); 13359 #endif 13360 } 13361 switch (ret) { 13362 case 0: 13363 ports[port_id].dev_conf.txmode.offloads &= 13364 ~DEV_TX_OFFLOAD_MACSEC_INSERT; 13365 cmd_reconfig_device_queue(port_id, 1, 1); 13366 break; 13367 case -ENODEV: 13368 printf("invalid port_id %d\n", port_id); 13369 break; 13370 case -ENOTSUP: 13371 printf("not supported on port %d\n", port_id); 13372 break; 13373 default: 13374 printf("programming error: (%s)\n", strerror(-ret)); 13375 } 13376 } 13377 13378 cmdline_parse_inst_t cmd_set_macsec_offload_off = { 13379 .f = cmd_set_macsec_offload_off_parsed, 13380 .data = NULL, 13381 .help_str = "set macsec offload <port_id> off", 13382 .tokens = { 13383 (void *)&cmd_macsec_offload_off_set, 13384 (void *)&cmd_macsec_offload_off_macsec, 13385 (void *)&cmd_macsec_offload_off_offload, 13386 (void *)&cmd_macsec_offload_off_port_id, 13387 (void *)&cmd_macsec_offload_off_off, 13388 NULL, 13389 }, 13390 }; 13391 13392 /* Common result structure for MACsec secure connection configure */ 13393 struct cmd_macsec_sc_result { 13394 cmdline_fixed_string_t set; 13395 cmdline_fixed_string_t macsec; 13396 cmdline_fixed_string_t sc; 13397 cmdline_fixed_string_t tx_rx; 13398 portid_t port_id; 13399 struct ether_addr mac; 13400 uint16_t pi; 13401 }; 13402 13403 /* Common CLI fields for MACsec secure connection configure */ 13404 cmdline_parse_token_string_t cmd_macsec_sc_set = 13405 TOKEN_STRING_INITIALIZER 13406 (struct cmd_macsec_sc_result, 13407 set, "set"); 13408 cmdline_parse_token_string_t cmd_macsec_sc_macsec = 13409 TOKEN_STRING_INITIALIZER 13410 (struct cmd_macsec_sc_result, 13411 macsec, "macsec"); 13412 cmdline_parse_token_string_t cmd_macsec_sc_sc = 13413 TOKEN_STRING_INITIALIZER 13414 (struct cmd_macsec_sc_result, 13415 sc, "sc"); 13416 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = 13417 TOKEN_STRING_INITIALIZER 13418 (struct cmd_macsec_sc_result, 13419 tx_rx, "tx#rx"); 13420 cmdline_parse_token_num_t cmd_macsec_sc_port_id = 13421 TOKEN_NUM_INITIALIZER 13422 (struct cmd_macsec_sc_result, 13423 port_id, UINT16); 13424 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = 13425 TOKEN_ETHERADDR_INITIALIZER 13426 (struct cmd_macsec_sc_result, 13427 mac); 13428 cmdline_parse_token_num_t cmd_macsec_sc_pi = 13429 TOKEN_NUM_INITIALIZER 13430 (struct cmd_macsec_sc_result, 13431 pi, UINT16); 13432 13433 static void 13434 cmd_set_macsec_sc_parsed( 13435 void *parsed_result, 13436 __attribute__((unused)) struct cmdline *cl, 13437 __attribute__((unused)) void *data) 13438 { 13439 struct cmd_macsec_sc_result *res = parsed_result; 13440 int ret = -ENOTSUP; 13441 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 13442 13443 #ifdef RTE_LIBRTE_IXGBE_PMD 13444 ret = is_tx ? 13445 rte_pmd_ixgbe_macsec_config_txsc(res->port_id, 13446 res->mac.addr_bytes) : 13447 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, 13448 res->mac.addr_bytes, res->pi); 13449 #endif 13450 RTE_SET_USED(is_tx); 13451 13452 switch (ret) { 13453 case 0: 13454 break; 13455 case -ENODEV: 13456 printf("invalid port_id %d\n", res->port_id); 13457 break; 13458 case -ENOTSUP: 13459 printf("not supported on port %d\n", res->port_id); 13460 break; 13461 default: 13462 printf("programming error: (%s)\n", strerror(-ret)); 13463 } 13464 } 13465 13466 cmdline_parse_inst_t cmd_set_macsec_sc = { 13467 .f = cmd_set_macsec_sc_parsed, 13468 .data = NULL, 13469 .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>", 13470 .tokens = { 13471 (void *)&cmd_macsec_sc_set, 13472 (void *)&cmd_macsec_sc_macsec, 13473 (void *)&cmd_macsec_sc_sc, 13474 (void *)&cmd_macsec_sc_tx_rx, 13475 (void *)&cmd_macsec_sc_port_id, 13476 (void *)&cmd_macsec_sc_mac, 13477 (void *)&cmd_macsec_sc_pi, 13478 NULL, 13479 }, 13480 }; 13481 13482 /* Common result structure for MACsec secure connection configure */ 13483 struct cmd_macsec_sa_result { 13484 cmdline_fixed_string_t set; 13485 cmdline_fixed_string_t macsec; 13486 cmdline_fixed_string_t sa; 13487 cmdline_fixed_string_t tx_rx; 13488 portid_t port_id; 13489 uint8_t idx; 13490 uint8_t an; 13491 uint32_t pn; 13492 cmdline_fixed_string_t key; 13493 }; 13494 13495 /* Common CLI fields for MACsec secure connection configure */ 13496 cmdline_parse_token_string_t cmd_macsec_sa_set = 13497 TOKEN_STRING_INITIALIZER 13498 (struct cmd_macsec_sa_result, 13499 set, "set"); 13500 cmdline_parse_token_string_t cmd_macsec_sa_macsec = 13501 TOKEN_STRING_INITIALIZER 13502 (struct cmd_macsec_sa_result, 13503 macsec, "macsec"); 13504 cmdline_parse_token_string_t cmd_macsec_sa_sa = 13505 TOKEN_STRING_INITIALIZER 13506 (struct cmd_macsec_sa_result, 13507 sa, "sa"); 13508 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = 13509 TOKEN_STRING_INITIALIZER 13510 (struct cmd_macsec_sa_result, 13511 tx_rx, "tx#rx"); 13512 cmdline_parse_token_num_t cmd_macsec_sa_port_id = 13513 TOKEN_NUM_INITIALIZER 13514 (struct cmd_macsec_sa_result, 13515 port_id, UINT16); 13516 cmdline_parse_token_num_t cmd_macsec_sa_idx = 13517 TOKEN_NUM_INITIALIZER 13518 (struct cmd_macsec_sa_result, 13519 idx, UINT8); 13520 cmdline_parse_token_num_t cmd_macsec_sa_an = 13521 TOKEN_NUM_INITIALIZER 13522 (struct cmd_macsec_sa_result, 13523 an, UINT8); 13524 cmdline_parse_token_num_t cmd_macsec_sa_pn = 13525 TOKEN_NUM_INITIALIZER 13526 (struct cmd_macsec_sa_result, 13527 pn, UINT32); 13528 cmdline_parse_token_string_t cmd_macsec_sa_key = 13529 TOKEN_STRING_INITIALIZER 13530 (struct cmd_macsec_sa_result, 13531 key, NULL); 13532 13533 static void 13534 cmd_set_macsec_sa_parsed( 13535 void *parsed_result, 13536 __attribute__((unused)) struct cmdline *cl, 13537 __attribute__((unused)) void *data) 13538 { 13539 struct cmd_macsec_sa_result *res = parsed_result; 13540 int ret = -ENOTSUP; 13541 int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; 13542 uint8_t key[16] = { 0 }; 13543 uint8_t xdgt0; 13544 uint8_t xdgt1; 13545 int key_len; 13546 int i; 13547 13548 key_len = strlen(res->key) / 2; 13549 if (key_len > 16) 13550 key_len = 16; 13551 13552 for (i = 0; i < key_len; i++) { 13553 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); 13554 if (xdgt0 == 0xFF) 13555 return; 13556 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); 13557 if (xdgt1 == 0xFF) 13558 return; 13559 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); 13560 } 13561 13562 #ifdef RTE_LIBRTE_IXGBE_PMD 13563 ret = is_tx ? 13564 rte_pmd_ixgbe_macsec_select_txsa(res->port_id, 13565 res->idx, res->an, res->pn, key) : 13566 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, 13567 res->idx, res->an, res->pn, key); 13568 #endif 13569 RTE_SET_USED(is_tx); 13570 RTE_SET_USED(key); 13571 13572 switch (ret) { 13573 case 0: 13574 break; 13575 case -EINVAL: 13576 printf("invalid idx %d or an %d\n", res->idx, res->an); 13577 break; 13578 case -ENODEV: 13579 printf("invalid port_id %d\n", res->port_id); 13580 break; 13581 case -ENOTSUP: 13582 printf("not supported on port %d\n", res->port_id); 13583 break; 13584 default: 13585 printf("programming error: (%s)\n", strerror(-ret)); 13586 } 13587 } 13588 13589 cmdline_parse_inst_t cmd_set_macsec_sa = { 13590 .f = cmd_set_macsec_sa_parsed, 13591 .data = NULL, 13592 .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>", 13593 .tokens = { 13594 (void *)&cmd_macsec_sa_set, 13595 (void *)&cmd_macsec_sa_macsec, 13596 (void *)&cmd_macsec_sa_sa, 13597 (void *)&cmd_macsec_sa_tx_rx, 13598 (void *)&cmd_macsec_sa_port_id, 13599 (void *)&cmd_macsec_sa_idx, 13600 (void *)&cmd_macsec_sa_an, 13601 (void *)&cmd_macsec_sa_pn, 13602 (void *)&cmd_macsec_sa_key, 13603 NULL, 13604 }, 13605 }; 13606 13607 /* VF unicast promiscuous mode configuration */ 13608 13609 /* Common result structure for VF unicast promiscuous mode */ 13610 struct cmd_vf_promisc_result { 13611 cmdline_fixed_string_t set; 13612 cmdline_fixed_string_t vf; 13613 cmdline_fixed_string_t promisc; 13614 portid_t port_id; 13615 uint32_t vf_id; 13616 cmdline_fixed_string_t on_off; 13617 }; 13618 13619 /* Common CLI fields for VF unicast promiscuous mode enable disable */ 13620 cmdline_parse_token_string_t cmd_vf_promisc_set = 13621 TOKEN_STRING_INITIALIZER 13622 (struct cmd_vf_promisc_result, 13623 set, "set"); 13624 cmdline_parse_token_string_t cmd_vf_promisc_vf = 13625 TOKEN_STRING_INITIALIZER 13626 (struct cmd_vf_promisc_result, 13627 vf, "vf"); 13628 cmdline_parse_token_string_t cmd_vf_promisc_promisc = 13629 TOKEN_STRING_INITIALIZER 13630 (struct cmd_vf_promisc_result, 13631 promisc, "promisc"); 13632 cmdline_parse_token_num_t cmd_vf_promisc_port_id = 13633 TOKEN_NUM_INITIALIZER 13634 (struct cmd_vf_promisc_result, 13635 port_id, UINT16); 13636 cmdline_parse_token_num_t cmd_vf_promisc_vf_id = 13637 TOKEN_NUM_INITIALIZER 13638 (struct cmd_vf_promisc_result, 13639 vf_id, UINT32); 13640 cmdline_parse_token_string_t cmd_vf_promisc_on_off = 13641 TOKEN_STRING_INITIALIZER 13642 (struct cmd_vf_promisc_result, 13643 on_off, "on#off"); 13644 13645 static void 13646 cmd_set_vf_promisc_parsed( 13647 void *parsed_result, 13648 __attribute__((unused)) struct cmdline *cl, 13649 __attribute__((unused)) void *data) 13650 { 13651 struct cmd_vf_promisc_result *res = parsed_result; 13652 int ret = -ENOTSUP; 13653 13654 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13655 13656 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13657 return; 13658 13659 #ifdef RTE_LIBRTE_I40E_PMD 13660 ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id, 13661 res->vf_id, is_on); 13662 #endif 13663 13664 switch (ret) { 13665 case 0: 13666 break; 13667 case -EINVAL: 13668 printf("invalid vf_id %d\n", res->vf_id); 13669 break; 13670 case -ENODEV: 13671 printf("invalid port_id %d\n", res->port_id); 13672 break; 13673 case -ENOTSUP: 13674 printf("function not implemented\n"); 13675 break; 13676 default: 13677 printf("programming error: (%s)\n", strerror(-ret)); 13678 } 13679 } 13680 13681 cmdline_parse_inst_t cmd_set_vf_promisc = { 13682 .f = cmd_set_vf_promisc_parsed, 13683 .data = NULL, 13684 .help_str = "set vf promisc <port_id> <vf_id> on|off: " 13685 "Set unicast promiscuous mode for a VF from the PF", 13686 .tokens = { 13687 (void *)&cmd_vf_promisc_set, 13688 (void *)&cmd_vf_promisc_vf, 13689 (void *)&cmd_vf_promisc_promisc, 13690 (void *)&cmd_vf_promisc_port_id, 13691 (void *)&cmd_vf_promisc_vf_id, 13692 (void *)&cmd_vf_promisc_on_off, 13693 NULL, 13694 }, 13695 }; 13696 13697 /* VF multicast promiscuous mode configuration */ 13698 13699 /* Common result structure for VF multicast promiscuous mode */ 13700 struct cmd_vf_allmulti_result { 13701 cmdline_fixed_string_t set; 13702 cmdline_fixed_string_t vf; 13703 cmdline_fixed_string_t allmulti; 13704 portid_t port_id; 13705 uint32_t vf_id; 13706 cmdline_fixed_string_t on_off; 13707 }; 13708 13709 /* Common CLI fields for VF multicast promiscuous mode enable disable */ 13710 cmdline_parse_token_string_t cmd_vf_allmulti_set = 13711 TOKEN_STRING_INITIALIZER 13712 (struct cmd_vf_allmulti_result, 13713 set, "set"); 13714 cmdline_parse_token_string_t cmd_vf_allmulti_vf = 13715 TOKEN_STRING_INITIALIZER 13716 (struct cmd_vf_allmulti_result, 13717 vf, "vf"); 13718 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = 13719 TOKEN_STRING_INITIALIZER 13720 (struct cmd_vf_allmulti_result, 13721 allmulti, "allmulti"); 13722 cmdline_parse_token_num_t cmd_vf_allmulti_port_id = 13723 TOKEN_NUM_INITIALIZER 13724 (struct cmd_vf_allmulti_result, 13725 port_id, UINT16); 13726 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = 13727 TOKEN_NUM_INITIALIZER 13728 (struct cmd_vf_allmulti_result, 13729 vf_id, UINT32); 13730 cmdline_parse_token_string_t cmd_vf_allmulti_on_off = 13731 TOKEN_STRING_INITIALIZER 13732 (struct cmd_vf_allmulti_result, 13733 on_off, "on#off"); 13734 13735 static void 13736 cmd_set_vf_allmulti_parsed( 13737 void *parsed_result, 13738 __attribute__((unused)) struct cmdline *cl, 13739 __attribute__((unused)) void *data) 13740 { 13741 struct cmd_vf_allmulti_result *res = parsed_result; 13742 int ret = -ENOTSUP; 13743 13744 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13745 13746 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13747 return; 13748 13749 #ifdef RTE_LIBRTE_I40E_PMD 13750 ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id, 13751 res->vf_id, is_on); 13752 #endif 13753 13754 switch (ret) { 13755 case 0: 13756 break; 13757 case -EINVAL: 13758 printf("invalid vf_id %d\n", res->vf_id); 13759 break; 13760 case -ENODEV: 13761 printf("invalid port_id %d\n", res->port_id); 13762 break; 13763 case -ENOTSUP: 13764 printf("function not implemented\n"); 13765 break; 13766 default: 13767 printf("programming error: (%s)\n", strerror(-ret)); 13768 } 13769 } 13770 13771 cmdline_parse_inst_t cmd_set_vf_allmulti = { 13772 .f = cmd_set_vf_allmulti_parsed, 13773 .data = NULL, 13774 .help_str = "set vf allmulti <port_id> <vf_id> on|off: " 13775 "Set multicast promiscuous mode for a VF from the PF", 13776 .tokens = { 13777 (void *)&cmd_vf_allmulti_set, 13778 (void *)&cmd_vf_allmulti_vf, 13779 (void *)&cmd_vf_allmulti_allmulti, 13780 (void *)&cmd_vf_allmulti_port_id, 13781 (void *)&cmd_vf_allmulti_vf_id, 13782 (void *)&cmd_vf_allmulti_on_off, 13783 NULL, 13784 }, 13785 }; 13786 13787 /* vf broadcast mode configuration */ 13788 13789 /* Common result structure for vf broadcast */ 13790 struct cmd_set_vf_broadcast_result { 13791 cmdline_fixed_string_t set; 13792 cmdline_fixed_string_t vf; 13793 cmdline_fixed_string_t broadcast; 13794 portid_t port_id; 13795 uint16_t vf_id; 13796 cmdline_fixed_string_t on_off; 13797 }; 13798 13799 /* Common CLI fields for vf broadcast enable disable */ 13800 cmdline_parse_token_string_t cmd_set_vf_broadcast_set = 13801 TOKEN_STRING_INITIALIZER 13802 (struct cmd_set_vf_broadcast_result, 13803 set, "set"); 13804 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf = 13805 TOKEN_STRING_INITIALIZER 13806 (struct cmd_set_vf_broadcast_result, 13807 vf, "vf"); 13808 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = 13809 TOKEN_STRING_INITIALIZER 13810 (struct cmd_set_vf_broadcast_result, 13811 broadcast, "broadcast"); 13812 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = 13813 TOKEN_NUM_INITIALIZER 13814 (struct cmd_set_vf_broadcast_result, 13815 port_id, UINT16); 13816 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = 13817 TOKEN_NUM_INITIALIZER 13818 (struct cmd_set_vf_broadcast_result, 13819 vf_id, UINT16); 13820 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off = 13821 TOKEN_STRING_INITIALIZER 13822 (struct cmd_set_vf_broadcast_result, 13823 on_off, "on#off"); 13824 13825 static void 13826 cmd_set_vf_broadcast_parsed( 13827 void *parsed_result, 13828 __attribute__((unused)) struct cmdline *cl, 13829 __attribute__((unused)) void *data) 13830 { 13831 struct cmd_set_vf_broadcast_result *res = parsed_result; 13832 int ret = -ENOTSUP; 13833 13834 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13835 13836 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13837 return; 13838 13839 #ifdef RTE_LIBRTE_I40E_PMD 13840 ret = rte_pmd_i40e_set_vf_broadcast(res->port_id, 13841 res->vf_id, is_on); 13842 #endif 13843 13844 switch (ret) { 13845 case 0: 13846 break; 13847 case -EINVAL: 13848 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 13849 break; 13850 case -ENODEV: 13851 printf("invalid port_id %d\n", res->port_id); 13852 break; 13853 case -ENOTSUP: 13854 printf("function not implemented\n"); 13855 break; 13856 default: 13857 printf("programming error: (%s)\n", strerror(-ret)); 13858 } 13859 } 13860 13861 cmdline_parse_inst_t cmd_set_vf_broadcast = { 13862 .f = cmd_set_vf_broadcast_parsed, 13863 .data = NULL, 13864 .help_str = "set vf broadcast <port_id> <vf_id> on|off", 13865 .tokens = { 13866 (void *)&cmd_set_vf_broadcast_set, 13867 (void *)&cmd_set_vf_broadcast_vf, 13868 (void *)&cmd_set_vf_broadcast_broadcast, 13869 (void *)&cmd_set_vf_broadcast_port_id, 13870 (void *)&cmd_set_vf_broadcast_vf_id, 13871 (void *)&cmd_set_vf_broadcast_on_off, 13872 NULL, 13873 }, 13874 }; 13875 13876 /* vf vlan tag configuration */ 13877 13878 /* Common result structure for vf vlan tag */ 13879 struct cmd_set_vf_vlan_tag_result { 13880 cmdline_fixed_string_t set; 13881 cmdline_fixed_string_t vf; 13882 cmdline_fixed_string_t vlan; 13883 cmdline_fixed_string_t tag; 13884 portid_t port_id; 13885 uint16_t vf_id; 13886 cmdline_fixed_string_t on_off; 13887 }; 13888 13889 /* Common CLI fields for vf vlan tag enable disable */ 13890 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set = 13891 TOKEN_STRING_INITIALIZER 13892 (struct cmd_set_vf_vlan_tag_result, 13893 set, "set"); 13894 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf = 13895 TOKEN_STRING_INITIALIZER 13896 (struct cmd_set_vf_vlan_tag_result, 13897 vf, "vf"); 13898 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan = 13899 TOKEN_STRING_INITIALIZER 13900 (struct cmd_set_vf_vlan_tag_result, 13901 vlan, "vlan"); 13902 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = 13903 TOKEN_STRING_INITIALIZER 13904 (struct cmd_set_vf_vlan_tag_result, 13905 tag, "tag"); 13906 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = 13907 TOKEN_NUM_INITIALIZER 13908 (struct cmd_set_vf_vlan_tag_result, 13909 port_id, UINT16); 13910 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = 13911 TOKEN_NUM_INITIALIZER 13912 (struct cmd_set_vf_vlan_tag_result, 13913 vf_id, UINT16); 13914 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off = 13915 TOKEN_STRING_INITIALIZER 13916 (struct cmd_set_vf_vlan_tag_result, 13917 on_off, "on#off"); 13918 13919 static void 13920 cmd_set_vf_vlan_tag_parsed( 13921 void *parsed_result, 13922 __attribute__((unused)) struct cmdline *cl, 13923 __attribute__((unused)) void *data) 13924 { 13925 struct cmd_set_vf_vlan_tag_result *res = parsed_result; 13926 int ret = -ENOTSUP; 13927 13928 __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; 13929 13930 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 13931 return; 13932 13933 #ifdef RTE_LIBRTE_I40E_PMD 13934 ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id, 13935 res->vf_id, is_on); 13936 #endif 13937 13938 switch (ret) { 13939 case 0: 13940 break; 13941 case -EINVAL: 13942 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on); 13943 break; 13944 case -ENODEV: 13945 printf("invalid port_id %d\n", res->port_id); 13946 break; 13947 case -ENOTSUP: 13948 printf("function not implemented\n"); 13949 break; 13950 default: 13951 printf("programming error: (%s)\n", strerror(-ret)); 13952 } 13953 } 13954 13955 cmdline_parse_inst_t cmd_set_vf_vlan_tag = { 13956 .f = cmd_set_vf_vlan_tag_parsed, 13957 .data = NULL, 13958 .help_str = "set vf vlan tag <port_id> <vf_id> on|off", 13959 .tokens = { 13960 (void *)&cmd_set_vf_vlan_tag_set, 13961 (void *)&cmd_set_vf_vlan_tag_vf, 13962 (void *)&cmd_set_vf_vlan_tag_vlan, 13963 (void *)&cmd_set_vf_vlan_tag_tag, 13964 (void *)&cmd_set_vf_vlan_tag_port_id, 13965 (void *)&cmd_set_vf_vlan_tag_vf_id, 13966 (void *)&cmd_set_vf_vlan_tag_on_off, 13967 NULL, 13968 }, 13969 }; 13970 13971 /* Common definition of VF and TC TX bandwidth configuration */ 13972 struct cmd_vf_tc_bw_result { 13973 cmdline_fixed_string_t set; 13974 cmdline_fixed_string_t vf; 13975 cmdline_fixed_string_t tc; 13976 cmdline_fixed_string_t tx; 13977 cmdline_fixed_string_t min_bw; 13978 cmdline_fixed_string_t max_bw; 13979 cmdline_fixed_string_t strict_link_prio; 13980 portid_t port_id; 13981 uint16_t vf_id; 13982 uint8_t tc_no; 13983 uint32_t bw; 13984 cmdline_fixed_string_t bw_list; 13985 uint8_t tc_map; 13986 }; 13987 13988 cmdline_parse_token_string_t cmd_vf_tc_bw_set = 13989 TOKEN_STRING_INITIALIZER 13990 (struct cmd_vf_tc_bw_result, 13991 set, "set"); 13992 cmdline_parse_token_string_t cmd_vf_tc_bw_vf = 13993 TOKEN_STRING_INITIALIZER 13994 (struct cmd_vf_tc_bw_result, 13995 vf, "vf"); 13996 cmdline_parse_token_string_t cmd_vf_tc_bw_tc = 13997 TOKEN_STRING_INITIALIZER 13998 (struct cmd_vf_tc_bw_result, 13999 tc, "tc"); 14000 cmdline_parse_token_string_t cmd_vf_tc_bw_tx = 14001 TOKEN_STRING_INITIALIZER 14002 (struct cmd_vf_tc_bw_result, 14003 tx, "tx"); 14004 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio = 14005 TOKEN_STRING_INITIALIZER 14006 (struct cmd_vf_tc_bw_result, 14007 strict_link_prio, "strict-link-priority"); 14008 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = 14009 TOKEN_STRING_INITIALIZER 14010 (struct cmd_vf_tc_bw_result, 14011 min_bw, "min-bandwidth"); 14012 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw = 14013 TOKEN_STRING_INITIALIZER 14014 (struct cmd_vf_tc_bw_result, 14015 max_bw, "max-bandwidth"); 14016 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = 14017 TOKEN_NUM_INITIALIZER 14018 (struct cmd_vf_tc_bw_result, 14019 port_id, UINT16); 14020 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id = 14021 TOKEN_NUM_INITIALIZER 14022 (struct cmd_vf_tc_bw_result, 14023 vf_id, UINT16); 14024 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no = 14025 TOKEN_NUM_INITIALIZER 14026 (struct cmd_vf_tc_bw_result, 14027 tc_no, UINT8); 14028 cmdline_parse_token_num_t cmd_vf_tc_bw_bw = 14029 TOKEN_NUM_INITIALIZER 14030 (struct cmd_vf_tc_bw_result, 14031 bw, UINT32); 14032 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = 14033 TOKEN_STRING_INITIALIZER 14034 (struct cmd_vf_tc_bw_result, 14035 bw_list, NULL); 14036 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map = 14037 TOKEN_NUM_INITIALIZER 14038 (struct cmd_vf_tc_bw_result, 14039 tc_map, UINT8); 14040 14041 /* VF max bandwidth setting */ 14042 static void 14043 cmd_vf_max_bw_parsed( 14044 void *parsed_result, 14045 __attribute__((unused)) struct cmdline *cl, 14046 __attribute__((unused)) void *data) 14047 { 14048 struct cmd_vf_tc_bw_result *res = parsed_result; 14049 int ret = -ENOTSUP; 14050 14051 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14052 return; 14053 14054 #ifdef RTE_LIBRTE_I40E_PMD 14055 ret = rte_pmd_i40e_set_vf_max_bw(res->port_id, 14056 res->vf_id, res->bw); 14057 #endif 14058 14059 switch (ret) { 14060 case 0: 14061 break; 14062 case -EINVAL: 14063 printf("invalid vf_id %d or bandwidth %d\n", 14064 res->vf_id, res->bw); 14065 break; 14066 case -ENODEV: 14067 printf("invalid port_id %d\n", res->port_id); 14068 break; 14069 case -ENOTSUP: 14070 printf("function not implemented\n"); 14071 break; 14072 default: 14073 printf("programming error: (%s)\n", strerror(-ret)); 14074 } 14075 } 14076 14077 cmdline_parse_inst_t cmd_vf_max_bw = { 14078 .f = cmd_vf_max_bw_parsed, 14079 .data = NULL, 14080 .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>", 14081 .tokens = { 14082 (void *)&cmd_vf_tc_bw_set, 14083 (void *)&cmd_vf_tc_bw_vf, 14084 (void *)&cmd_vf_tc_bw_tx, 14085 (void *)&cmd_vf_tc_bw_max_bw, 14086 (void *)&cmd_vf_tc_bw_port_id, 14087 (void *)&cmd_vf_tc_bw_vf_id, 14088 (void *)&cmd_vf_tc_bw_bw, 14089 NULL, 14090 }, 14091 }; 14092 14093 static int 14094 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, 14095 uint8_t *tc_num, 14096 char *str) 14097 { 14098 uint32_t size; 14099 const char *p, *p0 = str; 14100 char s[256]; 14101 char *end; 14102 char *str_fld[16]; 14103 uint16_t i; 14104 int ret; 14105 14106 p = strchr(p0, '('); 14107 if (p == NULL) { 14108 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 14109 return -1; 14110 } 14111 p++; 14112 p0 = strchr(p, ')'); 14113 if (p0 == NULL) { 14114 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n"); 14115 return -1; 14116 } 14117 size = p0 - p; 14118 if (size >= sizeof(s)) { 14119 printf("The string size exceeds the internal buffer size\n"); 14120 return -1; 14121 } 14122 snprintf(s, sizeof(s), "%.*s", size, p); 14123 ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); 14124 if (ret <= 0) { 14125 printf("Failed to get the bandwidth list. "); 14126 return -1; 14127 } 14128 *tc_num = ret; 14129 for (i = 0; i < ret; i++) 14130 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); 14131 14132 return 0; 14133 } 14134 14135 /* TC min bandwidth setting */ 14136 static void 14137 cmd_vf_tc_min_bw_parsed( 14138 void *parsed_result, 14139 __attribute__((unused)) struct cmdline *cl, 14140 __attribute__((unused)) void *data) 14141 { 14142 struct cmd_vf_tc_bw_result *res = parsed_result; 14143 uint8_t tc_num; 14144 uint8_t bw[16]; 14145 int ret = -ENOTSUP; 14146 14147 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14148 return; 14149 14150 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 14151 if (ret) 14152 return; 14153 14154 #ifdef RTE_LIBRTE_I40E_PMD 14155 ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id, 14156 tc_num, bw); 14157 #endif 14158 14159 switch (ret) { 14160 case 0: 14161 break; 14162 case -EINVAL: 14163 printf("invalid vf_id %d or bandwidth\n", res->vf_id); 14164 break; 14165 case -ENODEV: 14166 printf("invalid port_id %d\n", res->port_id); 14167 break; 14168 case -ENOTSUP: 14169 printf("function not implemented\n"); 14170 break; 14171 default: 14172 printf("programming error: (%s)\n", strerror(-ret)); 14173 } 14174 } 14175 14176 cmdline_parse_inst_t cmd_vf_tc_min_bw = { 14177 .f = cmd_vf_tc_min_bw_parsed, 14178 .data = NULL, 14179 .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>" 14180 " <bw1, bw2, ...>", 14181 .tokens = { 14182 (void *)&cmd_vf_tc_bw_set, 14183 (void *)&cmd_vf_tc_bw_vf, 14184 (void *)&cmd_vf_tc_bw_tc, 14185 (void *)&cmd_vf_tc_bw_tx, 14186 (void *)&cmd_vf_tc_bw_min_bw, 14187 (void *)&cmd_vf_tc_bw_port_id, 14188 (void *)&cmd_vf_tc_bw_vf_id, 14189 (void *)&cmd_vf_tc_bw_bw_list, 14190 NULL, 14191 }, 14192 }; 14193 14194 static void 14195 cmd_tc_min_bw_parsed( 14196 void *parsed_result, 14197 __attribute__((unused)) struct cmdline *cl, 14198 __attribute__((unused)) void *data) 14199 { 14200 struct cmd_vf_tc_bw_result *res = parsed_result; 14201 struct rte_port *port; 14202 uint8_t tc_num; 14203 uint8_t bw[16]; 14204 int ret = -ENOTSUP; 14205 14206 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14207 return; 14208 14209 port = &ports[res->port_id]; 14210 /** Check if the port is not started **/ 14211 if (port->port_status != RTE_PORT_STOPPED) { 14212 printf("Please stop port %d first\n", res->port_id); 14213 return; 14214 } 14215 14216 ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); 14217 if (ret) 14218 return; 14219 14220 #ifdef RTE_LIBRTE_IXGBE_PMD 14221 ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); 14222 #endif 14223 14224 switch (ret) { 14225 case 0: 14226 break; 14227 case -EINVAL: 14228 printf("invalid bandwidth\n"); 14229 break; 14230 case -ENODEV: 14231 printf("invalid port_id %d\n", res->port_id); 14232 break; 14233 case -ENOTSUP: 14234 printf("function not implemented\n"); 14235 break; 14236 default: 14237 printf("programming error: (%s)\n", strerror(-ret)); 14238 } 14239 } 14240 14241 cmdline_parse_inst_t cmd_tc_min_bw = { 14242 .f = cmd_tc_min_bw_parsed, 14243 .data = NULL, 14244 .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>", 14245 .tokens = { 14246 (void *)&cmd_vf_tc_bw_set, 14247 (void *)&cmd_vf_tc_bw_tc, 14248 (void *)&cmd_vf_tc_bw_tx, 14249 (void *)&cmd_vf_tc_bw_min_bw, 14250 (void *)&cmd_vf_tc_bw_port_id, 14251 (void *)&cmd_vf_tc_bw_bw_list, 14252 NULL, 14253 }, 14254 }; 14255 14256 /* TC max bandwidth setting */ 14257 static void 14258 cmd_vf_tc_max_bw_parsed( 14259 void *parsed_result, 14260 __attribute__((unused)) struct cmdline *cl, 14261 __attribute__((unused)) void *data) 14262 { 14263 struct cmd_vf_tc_bw_result *res = parsed_result; 14264 int ret = -ENOTSUP; 14265 14266 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14267 return; 14268 14269 #ifdef RTE_LIBRTE_I40E_PMD 14270 ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id, 14271 res->tc_no, res->bw); 14272 #endif 14273 14274 switch (ret) { 14275 case 0: 14276 break; 14277 case -EINVAL: 14278 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n", 14279 res->vf_id, res->tc_no, res->bw); 14280 break; 14281 case -ENODEV: 14282 printf("invalid port_id %d\n", res->port_id); 14283 break; 14284 case -ENOTSUP: 14285 printf("function not implemented\n"); 14286 break; 14287 default: 14288 printf("programming error: (%s)\n", strerror(-ret)); 14289 } 14290 } 14291 14292 cmdline_parse_inst_t cmd_vf_tc_max_bw = { 14293 .f = cmd_vf_tc_max_bw_parsed, 14294 .data = NULL, 14295 .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>" 14296 " <bandwidth>", 14297 .tokens = { 14298 (void *)&cmd_vf_tc_bw_set, 14299 (void *)&cmd_vf_tc_bw_vf, 14300 (void *)&cmd_vf_tc_bw_tc, 14301 (void *)&cmd_vf_tc_bw_tx, 14302 (void *)&cmd_vf_tc_bw_max_bw, 14303 (void *)&cmd_vf_tc_bw_port_id, 14304 (void *)&cmd_vf_tc_bw_vf_id, 14305 (void *)&cmd_vf_tc_bw_tc_no, 14306 (void *)&cmd_vf_tc_bw_bw, 14307 NULL, 14308 }, 14309 }; 14310 14311 14312 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 14313 14314 /* *** Set Port default Traffic Management Hierarchy *** */ 14315 struct cmd_set_port_tm_hierarchy_default_result { 14316 cmdline_fixed_string_t set; 14317 cmdline_fixed_string_t port; 14318 cmdline_fixed_string_t tm; 14319 cmdline_fixed_string_t hierarchy; 14320 cmdline_fixed_string_t def; 14321 portid_t port_id; 14322 }; 14323 14324 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set = 14325 TOKEN_STRING_INITIALIZER( 14326 struct cmd_set_port_tm_hierarchy_default_result, set, "set"); 14327 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port = 14328 TOKEN_STRING_INITIALIZER( 14329 struct cmd_set_port_tm_hierarchy_default_result, port, "port"); 14330 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm = 14331 TOKEN_STRING_INITIALIZER( 14332 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm"); 14333 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy = 14334 TOKEN_STRING_INITIALIZER( 14335 struct cmd_set_port_tm_hierarchy_default_result, 14336 hierarchy, "hierarchy"); 14337 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default = 14338 TOKEN_STRING_INITIALIZER( 14339 struct cmd_set_port_tm_hierarchy_default_result, 14340 def, "default"); 14341 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id = 14342 TOKEN_NUM_INITIALIZER( 14343 struct cmd_set_port_tm_hierarchy_default_result, 14344 port_id, UINT16); 14345 14346 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result, 14347 __attribute__((unused)) struct cmdline *cl, 14348 __attribute__((unused)) void *data) 14349 { 14350 struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result; 14351 struct rte_port *p; 14352 portid_t port_id = res->port_id; 14353 14354 if (port_id_is_invalid(port_id, ENABLED_WARN)) 14355 return; 14356 14357 p = &ports[port_id]; 14358 14359 /* Port tm flag */ 14360 if (p->softport.tm_flag == 0) { 14361 printf(" tm not enabled on port %u (error)\n", port_id); 14362 return; 14363 } 14364 14365 /* Forward mode: tm */ 14366 if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) { 14367 printf(" tm mode not enabled(error)\n"); 14368 return; 14369 } 14370 14371 /* Set the default tm hierarchy */ 14372 p->softport.tm.default_hierarchy_enable = 1; 14373 } 14374 14375 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = { 14376 .f = cmd_set_port_tm_hierarchy_default_parsed, 14377 .data = NULL, 14378 .help_str = "set port tm hierarchy default <port_id>", 14379 .tokens = { 14380 (void *)&cmd_set_port_tm_hierarchy_default_set, 14381 (void *)&cmd_set_port_tm_hierarchy_default_port, 14382 (void *)&cmd_set_port_tm_hierarchy_default_tm, 14383 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy, 14384 (void *)&cmd_set_port_tm_hierarchy_default_default, 14385 (void *)&cmd_set_port_tm_hierarchy_default_port_id, 14386 NULL, 14387 }, 14388 }; 14389 #endif 14390 14391 /* Strict link priority scheduling mode setting */ 14392 static void 14393 cmd_strict_link_prio_parsed( 14394 void *parsed_result, 14395 __attribute__((unused)) struct cmdline *cl, 14396 __attribute__((unused)) void *data) 14397 { 14398 struct cmd_vf_tc_bw_result *res = parsed_result; 14399 int ret = -ENOTSUP; 14400 14401 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 14402 return; 14403 14404 #ifdef RTE_LIBRTE_I40E_PMD 14405 ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map); 14406 #endif 14407 14408 switch (ret) { 14409 case 0: 14410 break; 14411 case -EINVAL: 14412 printf("invalid tc_bitmap 0x%x\n", res->tc_map); 14413 break; 14414 case -ENODEV: 14415 printf("invalid port_id %d\n", res->port_id); 14416 break; 14417 case -ENOTSUP: 14418 printf("function not implemented\n"); 14419 break; 14420 default: 14421 printf("programming error: (%s)\n", strerror(-ret)); 14422 } 14423 } 14424 14425 cmdline_parse_inst_t cmd_strict_link_prio = { 14426 .f = cmd_strict_link_prio_parsed, 14427 .data = NULL, 14428 .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>", 14429 .tokens = { 14430 (void *)&cmd_vf_tc_bw_set, 14431 (void *)&cmd_vf_tc_bw_tx, 14432 (void *)&cmd_vf_tc_bw_strict_link_prio, 14433 (void *)&cmd_vf_tc_bw_port_id, 14434 (void *)&cmd_vf_tc_bw_tc_map, 14435 NULL, 14436 }, 14437 }; 14438 14439 /* Load dynamic device personalization*/ 14440 struct cmd_ddp_add_result { 14441 cmdline_fixed_string_t ddp; 14442 cmdline_fixed_string_t add; 14443 portid_t port_id; 14444 char filepath[]; 14445 }; 14446 14447 cmdline_parse_token_string_t cmd_ddp_add_ddp = 14448 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp"); 14449 cmdline_parse_token_string_t cmd_ddp_add_add = 14450 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add"); 14451 cmdline_parse_token_num_t cmd_ddp_add_port_id = 14452 TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16); 14453 cmdline_parse_token_string_t cmd_ddp_add_filepath = 14454 TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL); 14455 14456 static void 14457 cmd_ddp_add_parsed( 14458 void *parsed_result, 14459 __attribute__((unused)) struct cmdline *cl, 14460 __attribute__((unused)) void *data) 14461 { 14462 struct cmd_ddp_add_result *res = parsed_result; 14463 uint8_t *buff; 14464 uint32_t size; 14465 char *filepath; 14466 char *file_fld[2]; 14467 int file_num; 14468 int ret = -ENOTSUP; 14469 14470 if (res->port_id > nb_ports) { 14471 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14472 return; 14473 } 14474 14475 if (!all_ports_stopped()) { 14476 printf("Please stop all ports first\n"); 14477 return; 14478 } 14479 14480 filepath = strdup(res->filepath); 14481 if (filepath == NULL) { 14482 printf("Failed to allocate memory\n"); 14483 return; 14484 } 14485 file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ','); 14486 14487 buff = open_file(file_fld[0], &size); 14488 if (!buff) { 14489 free((void *)filepath); 14490 return; 14491 } 14492 14493 #ifdef RTE_LIBRTE_I40E_PMD 14494 if (ret == -ENOTSUP) 14495 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 14496 buff, size, 14497 RTE_PMD_I40E_PKG_OP_WR_ADD); 14498 #endif 14499 14500 if (ret == -EEXIST) 14501 printf("Profile has already existed.\n"); 14502 else if (ret < 0) 14503 printf("Failed to load profile.\n"); 14504 else if (file_num == 2) 14505 save_file(file_fld[1], buff, size); 14506 14507 close_file(buff); 14508 free((void *)filepath); 14509 } 14510 14511 cmdline_parse_inst_t cmd_ddp_add = { 14512 .f = cmd_ddp_add_parsed, 14513 .data = NULL, 14514 .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>", 14515 .tokens = { 14516 (void *)&cmd_ddp_add_ddp, 14517 (void *)&cmd_ddp_add_add, 14518 (void *)&cmd_ddp_add_port_id, 14519 (void *)&cmd_ddp_add_filepath, 14520 NULL, 14521 }, 14522 }; 14523 14524 /* Delete dynamic device personalization*/ 14525 struct cmd_ddp_del_result { 14526 cmdline_fixed_string_t ddp; 14527 cmdline_fixed_string_t del; 14528 portid_t port_id; 14529 char filepath[]; 14530 }; 14531 14532 cmdline_parse_token_string_t cmd_ddp_del_ddp = 14533 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp"); 14534 cmdline_parse_token_string_t cmd_ddp_del_del = 14535 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del"); 14536 cmdline_parse_token_num_t cmd_ddp_del_port_id = 14537 TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16); 14538 cmdline_parse_token_string_t cmd_ddp_del_filepath = 14539 TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL); 14540 14541 static void 14542 cmd_ddp_del_parsed( 14543 void *parsed_result, 14544 __attribute__((unused)) struct cmdline *cl, 14545 __attribute__((unused)) void *data) 14546 { 14547 struct cmd_ddp_del_result *res = parsed_result; 14548 uint8_t *buff; 14549 uint32_t size; 14550 int ret = -ENOTSUP; 14551 14552 if (res->port_id > nb_ports) { 14553 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14554 return; 14555 } 14556 14557 if (!all_ports_stopped()) { 14558 printf("Please stop all ports first\n"); 14559 return; 14560 } 14561 14562 buff = open_file(res->filepath, &size); 14563 if (!buff) 14564 return; 14565 14566 #ifdef RTE_LIBRTE_I40E_PMD 14567 if (ret == -ENOTSUP) 14568 ret = rte_pmd_i40e_process_ddp_package(res->port_id, 14569 buff, size, 14570 RTE_PMD_I40E_PKG_OP_WR_DEL); 14571 #endif 14572 14573 if (ret == -EACCES) 14574 printf("Profile does not exist.\n"); 14575 else if (ret < 0) 14576 printf("Failed to delete profile.\n"); 14577 14578 close_file(buff); 14579 } 14580 14581 cmdline_parse_inst_t cmd_ddp_del = { 14582 .f = cmd_ddp_del_parsed, 14583 .data = NULL, 14584 .help_str = "ddp del <port_id> <backup_profile_path>", 14585 .tokens = { 14586 (void *)&cmd_ddp_del_ddp, 14587 (void *)&cmd_ddp_del_del, 14588 (void *)&cmd_ddp_del_port_id, 14589 (void *)&cmd_ddp_del_filepath, 14590 NULL, 14591 }, 14592 }; 14593 14594 /* Get dynamic device personalization profile info */ 14595 struct cmd_ddp_info_result { 14596 cmdline_fixed_string_t ddp; 14597 cmdline_fixed_string_t get; 14598 cmdline_fixed_string_t info; 14599 char filepath[]; 14600 }; 14601 14602 cmdline_parse_token_string_t cmd_ddp_info_ddp = 14603 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp"); 14604 cmdline_parse_token_string_t cmd_ddp_info_get = 14605 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get"); 14606 cmdline_parse_token_string_t cmd_ddp_info_info = 14607 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info"); 14608 cmdline_parse_token_string_t cmd_ddp_info_filepath = 14609 TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL); 14610 14611 static void 14612 cmd_ddp_info_parsed( 14613 void *parsed_result, 14614 __attribute__((unused)) struct cmdline *cl, 14615 __attribute__((unused)) void *data) 14616 { 14617 struct cmd_ddp_info_result *res = parsed_result; 14618 uint8_t *pkg; 14619 uint32_t pkg_size; 14620 int ret = -ENOTSUP; 14621 #ifdef RTE_LIBRTE_I40E_PMD 14622 uint32_t i, j, n; 14623 uint8_t *buff; 14624 uint32_t buff_size = 0; 14625 struct rte_pmd_i40e_profile_info info; 14626 uint32_t dev_num = 0; 14627 struct rte_pmd_i40e_ddp_device_id *devs; 14628 uint32_t proto_num = 0; 14629 struct rte_pmd_i40e_proto_info *proto = NULL; 14630 uint32_t pctype_num = 0; 14631 struct rte_pmd_i40e_ptype_info *pctype; 14632 uint32_t ptype_num = 0; 14633 struct rte_pmd_i40e_ptype_info *ptype; 14634 uint8_t proto_id; 14635 14636 #endif 14637 14638 pkg = open_file(res->filepath, &pkg_size); 14639 if (!pkg) 14640 return; 14641 14642 #ifdef RTE_LIBRTE_I40E_PMD 14643 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14644 (uint8_t *)&info, sizeof(info), 14645 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER); 14646 if (!ret) { 14647 printf("Global Track id: 0x%x\n", info.track_id); 14648 printf("Global Version: %d.%d.%d.%d\n", 14649 info.version.major, 14650 info.version.minor, 14651 info.version.update, 14652 info.version.draft); 14653 printf("Global Package name: %s\n\n", info.name); 14654 } 14655 14656 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14657 (uint8_t *)&info, sizeof(info), 14658 RTE_PMD_I40E_PKG_INFO_HEADER); 14659 if (!ret) { 14660 printf("i40e Profile Track id: 0x%x\n", info.track_id); 14661 printf("i40e Profile Version: %d.%d.%d.%d\n", 14662 info.version.major, 14663 info.version.minor, 14664 info.version.update, 14665 info.version.draft); 14666 printf("i40e Profile name: %s\n\n", info.name); 14667 } 14668 14669 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14670 (uint8_t *)&buff_size, sizeof(buff_size), 14671 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE); 14672 if (!ret && buff_size) { 14673 buff = (uint8_t *)malloc(buff_size); 14674 if (buff) { 14675 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14676 buff, buff_size, 14677 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES); 14678 if (!ret) 14679 printf("Package Notes:\n%s\n\n", buff); 14680 free(buff); 14681 } 14682 } 14683 14684 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14685 (uint8_t *)&dev_num, sizeof(dev_num), 14686 RTE_PMD_I40E_PKG_INFO_DEVID_NUM); 14687 if (!ret && dev_num) { 14688 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id); 14689 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size); 14690 if (devs) { 14691 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14692 (uint8_t *)devs, buff_size, 14693 RTE_PMD_I40E_PKG_INFO_DEVID_LIST); 14694 if (!ret) { 14695 printf("List of supported devices:\n"); 14696 for (i = 0; i < dev_num; i++) { 14697 printf(" %04X:%04X %04X:%04X\n", 14698 devs[i].vendor_dev_id >> 16, 14699 devs[i].vendor_dev_id & 0xFFFF, 14700 devs[i].sub_vendor_dev_id >> 16, 14701 devs[i].sub_vendor_dev_id & 0xFFFF); 14702 } 14703 printf("\n"); 14704 } 14705 free(devs); 14706 } 14707 } 14708 14709 /* get information about protocols and packet types */ 14710 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14711 (uint8_t *)&proto_num, sizeof(proto_num), 14712 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM); 14713 if (ret || !proto_num) 14714 goto no_print_return; 14715 14716 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info); 14717 proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size); 14718 if (!proto) 14719 goto no_print_return; 14720 14721 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto, 14722 buff_size, 14723 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST); 14724 if (!ret) { 14725 printf("List of used protocols:\n"); 14726 for (i = 0; i < proto_num; i++) 14727 printf(" %2u: %s\n", proto[i].proto_id, 14728 proto[i].name); 14729 printf("\n"); 14730 } 14731 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, 14732 (uint8_t *)&pctype_num, sizeof(pctype_num), 14733 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM); 14734 if (ret || !pctype_num) 14735 goto no_print_pctypes; 14736 14737 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info); 14738 pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); 14739 if (!pctype) 14740 goto no_print_pctypes; 14741 14742 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype, 14743 buff_size, 14744 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST); 14745 if (ret) { 14746 free(pctype); 14747 goto no_print_pctypes; 14748 } 14749 14750 printf("List of defined packet classification types:\n"); 14751 for (i = 0; i < pctype_num; i++) { 14752 printf(" %2u:", pctype[i].ptype_id); 14753 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { 14754 proto_id = pctype[i].protocols[j]; 14755 if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { 14756 for (n = 0; n < proto_num; n++) { 14757 if (proto[n].proto_id == proto_id) { 14758 printf(" %s", proto[n].name); 14759 break; 14760 } 14761 } 14762 } 14763 } 14764 printf("\n"); 14765 } 14766 printf("\n"); 14767 free(pctype); 14768 14769 no_print_pctypes: 14770 14771 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num, 14772 sizeof(ptype_num), 14773 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM); 14774 if (ret || !ptype_num) 14775 goto no_print_return; 14776 14777 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info); 14778 ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); 14779 if (!ptype) 14780 goto no_print_return; 14781 14782 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype, 14783 buff_size, 14784 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST); 14785 if (ret) { 14786 free(ptype); 14787 goto no_print_return; 14788 } 14789 printf("List of defined packet types:\n"); 14790 for (i = 0; i < ptype_num; i++) { 14791 printf(" %2u:", ptype[i].ptype_id); 14792 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { 14793 proto_id = ptype[i].protocols[j]; 14794 if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { 14795 for (n = 0; n < proto_num; n++) { 14796 if (proto[n].proto_id == proto_id) { 14797 printf(" %s", proto[n].name); 14798 break; 14799 } 14800 } 14801 } 14802 } 14803 printf("\n"); 14804 } 14805 free(ptype); 14806 printf("\n"); 14807 14808 ret = 0; 14809 no_print_return: 14810 if (proto) 14811 free(proto); 14812 #endif 14813 if (ret == -ENOTSUP) 14814 printf("Function not supported in PMD driver\n"); 14815 close_file(pkg); 14816 } 14817 14818 cmdline_parse_inst_t cmd_ddp_get_info = { 14819 .f = cmd_ddp_info_parsed, 14820 .data = NULL, 14821 .help_str = "ddp get info <profile_path>", 14822 .tokens = { 14823 (void *)&cmd_ddp_info_ddp, 14824 (void *)&cmd_ddp_info_get, 14825 (void *)&cmd_ddp_info_info, 14826 (void *)&cmd_ddp_info_filepath, 14827 NULL, 14828 }, 14829 }; 14830 14831 /* Get dynamic device personalization profile info list*/ 14832 #define PROFILE_INFO_SIZE 48 14833 #define MAX_PROFILE_NUM 16 14834 14835 struct cmd_ddp_get_list_result { 14836 cmdline_fixed_string_t ddp; 14837 cmdline_fixed_string_t get; 14838 cmdline_fixed_string_t list; 14839 portid_t port_id; 14840 }; 14841 14842 cmdline_parse_token_string_t cmd_ddp_get_list_ddp = 14843 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp"); 14844 cmdline_parse_token_string_t cmd_ddp_get_list_get = 14845 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get"); 14846 cmdline_parse_token_string_t cmd_ddp_get_list_list = 14847 TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list"); 14848 cmdline_parse_token_num_t cmd_ddp_get_list_port_id = 14849 TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16); 14850 14851 static void 14852 cmd_ddp_get_list_parsed( 14853 void *parsed_result, 14854 __attribute__((unused)) struct cmdline *cl, 14855 __attribute__((unused)) void *data) 14856 { 14857 struct cmd_ddp_get_list_result *res = parsed_result; 14858 #ifdef RTE_LIBRTE_I40E_PMD 14859 struct rte_pmd_i40e_profile_list *p_list; 14860 struct rte_pmd_i40e_profile_info *p_info; 14861 uint32_t p_num; 14862 uint32_t size; 14863 uint32_t i; 14864 #endif 14865 int ret = -ENOTSUP; 14866 14867 if (res->port_id > nb_ports) { 14868 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14869 return; 14870 } 14871 14872 #ifdef RTE_LIBRTE_I40E_PMD 14873 size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4; 14874 p_list = (struct rte_pmd_i40e_profile_list *)malloc(size); 14875 if (!p_list) 14876 printf("%s: Failed to malloc buffer\n", __func__); 14877 14878 if (ret == -ENOTSUP) 14879 ret = rte_pmd_i40e_get_ddp_list(res->port_id, 14880 (uint8_t *)p_list, size); 14881 14882 if (!ret) { 14883 p_num = p_list->p_count; 14884 printf("Profile number is: %d\n\n", p_num); 14885 14886 for (i = 0; i < p_num; i++) { 14887 p_info = &p_list->p_info[i]; 14888 printf("Profile %d:\n", i); 14889 printf("Track id: 0x%x\n", p_info->track_id); 14890 printf("Version: %d.%d.%d.%d\n", 14891 p_info->version.major, 14892 p_info->version.minor, 14893 p_info->version.update, 14894 p_info->version.draft); 14895 printf("Profile name: %s\n\n", p_info->name); 14896 } 14897 } 14898 14899 free(p_list); 14900 #endif 14901 14902 if (ret < 0) 14903 printf("Failed to get ddp list\n"); 14904 } 14905 14906 cmdline_parse_inst_t cmd_ddp_get_list = { 14907 .f = cmd_ddp_get_list_parsed, 14908 .data = NULL, 14909 .help_str = "ddp get list <port_id>", 14910 .tokens = { 14911 (void *)&cmd_ddp_get_list_ddp, 14912 (void *)&cmd_ddp_get_list_get, 14913 (void *)&cmd_ddp_get_list_list, 14914 (void *)&cmd_ddp_get_list_port_id, 14915 NULL, 14916 }, 14917 }; 14918 14919 /* Configure input set */ 14920 struct cmd_cfg_input_set_result { 14921 cmdline_fixed_string_t port; 14922 cmdline_fixed_string_t cfg; 14923 portid_t port_id; 14924 cmdline_fixed_string_t pctype; 14925 uint8_t pctype_id; 14926 cmdline_fixed_string_t inset_type; 14927 cmdline_fixed_string_t opt; 14928 cmdline_fixed_string_t field; 14929 uint8_t field_idx; 14930 }; 14931 14932 static void 14933 cmd_cfg_input_set_parsed( 14934 void *parsed_result, 14935 __attribute__((unused)) struct cmdline *cl, 14936 __attribute__((unused)) void *data) 14937 { 14938 struct cmd_cfg_input_set_result *res = parsed_result; 14939 #ifdef RTE_LIBRTE_I40E_PMD 14940 enum rte_pmd_i40e_inset_type inset_type = INSET_NONE; 14941 struct rte_pmd_i40e_inset inset; 14942 #endif 14943 int ret = -ENOTSUP; 14944 14945 if (res->port_id > nb_ports) { 14946 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 14947 return; 14948 } 14949 14950 if (!all_ports_stopped()) { 14951 printf("Please stop all ports first\n"); 14952 return; 14953 } 14954 14955 #ifdef RTE_LIBRTE_I40E_PMD 14956 if (!strcmp(res->inset_type, "hash_inset")) 14957 inset_type = INSET_HASH; 14958 else if (!strcmp(res->inset_type, "fdir_inset")) 14959 inset_type = INSET_FDIR; 14960 else if (!strcmp(res->inset_type, "fdir_flx_inset")) 14961 inset_type = INSET_FDIR_FLX; 14962 ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id, 14963 &inset, inset_type); 14964 if (ret) { 14965 printf("Failed to get input set.\n"); 14966 return; 14967 } 14968 14969 if (!strcmp(res->opt, "get")) { 14970 ret = rte_pmd_i40e_inset_field_get(inset.inset, 14971 res->field_idx); 14972 if (ret) 14973 printf("Field index %d is enabled.\n", res->field_idx); 14974 else 14975 printf("Field index %d is disabled.\n", res->field_idx); 14976 return; 14977 } else if (!strcmp(res->opt, "set")) 14978 ret = rte_pmd_i40e_inset_field_set(&inset.inset, 14979 res->field_idx); 14980 else if (!strcmp(res->opt, "clear")) 14981 ret = rte_pmd_i40e_inset_field_clear(&inset.inset, 14982 res->field_idx); 14983 if (ret) { 14984 printf("Failed to configure input set field.\n"); 14985 return; 14986 } 14987 14988 ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id, 14989 &inset, inset_type); 14990 if (ret) { 14991 printf("Failed to set input set.\n"); 14992 return; 14993 } 14994 #endif 14995 14996 if (ret == -ENOTSUP) 14997 printf("Function not supported\n"); 14998 } 14999 15000 cmdline_parse_token_string_t cmd_cfg_input_set_port = 15001 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15002 port, "port"); 15003 cmdline_parse_token_string_t cmd_cfg_input_set_cfg = 15004 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15005 cfg, "config"); 15006 cmdline_parse_token_num_t cmd_cfg_input_set_port_id = 15007 TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result, 15008 port_id, UINT16); 15009 cmdline_parse_token_string_t cmd_cfg_input_set_pctype = 15010 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15011 pctype, "pctype"); 15012 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id = 15013 TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result, 15014 pctype_id, UINT8); 15015 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type = 15016 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15017 inset_type, 15018 "hash_inset#fdir_inset#fdir_flx_inset"); 15019 cmdline_parse_token_string_t cmd_cfg_input_set_opt = 15020 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15021 opt, "get#set#clear"); 15022 cmdline_parse_token_string_t cmd_cfg_input_set_field = 15023 TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result, 15024 field, "field"); 15025 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx = 15026 TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result, 15027 field_idx, UINT8); 15028 15029 cmdline_parse_inst_t cmd_cfg_input_set = { 15030 .f = cmd_cfg_input_set_parsed, 15031 .data = NULL, 15032 .help_str = "port config <port_id> pctype <pctype_id> hash_inset|" 15033 "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>", 15034 .tokens = { 15035 (void *)&cmd_cfg_input_set_port, 15036 (void *)&cmd_cfg_input_set_cfg, 15037 (void *)&cmd_cfg_input_set_port_id, 15038 (void *)&cmd_cfg_input_set_pctype, 15039 (void *)&cmd_cfg_input_set_pctype_id, 15040 (void *)&cmd_cfg_input_set_inset_type, 15041 (void *)&cmd_cfg_input_set_opt, 15042 (void *)&cmd_cfg_input_set_field, 15043 (void *)&cmd_cfg_input_set_field_idx, 15044 NULL, 15045 }, 15046 }; 15047 15048 /* Clear input set */ 15049 struct cmd_clear_input_set_result { 15050 cmdline_fixed_string_t port; 15051 cmdline_fixed_string_t cfg; 15052 portid_t port_id; 15053 cmdline_fixed_string_t pctype; 15054 uint8_t pctype_id; 15055 cmdline_fixed_string_t inset_type; 15056 cmdline_fixed_string_t clear; 15057 cmdline_fixed_string_t all; 15058 }; 15059 15060 static void 15061 cmd_clear_input_set_parsed( 15062 void *parsed_result, 15063 __attribute__((unused)) struct cmdline *cl, 15064 __attribute__((unused)) void *data) 15065 { 15066 struct cmd_clear_input_set_result *res = parsed_result; 15067 #ifdef RTE_LIBRTE_I40E_PMD 15068 enum rte_pmd_i40e_inset_type inset_type = INSET_NONE; 15069 struct rte_pmd_i40e_inset inset; 15070 #endif 15071 int ret = -ENOTSUP; 15072 15073 if (res->port_id > nb_ports) { 15074 printf("Invalid port, range is [0, %d]\n", nb_ports - 1); 15075 return; 15076 } 15077 15078 if (!all_ports_stopped()) { 15079 printf("Please stop all ports first\n"); 15080 return; 15081 } 15082 15083 #ifdef RTE_LIBRTE_I40E_PMD 15084 if (!strcmp(res->inset_type, "hash_inset")) 15085 inset_type = INSET_HASH; 15086 else if (!strcmp(res->inset_type, "fdir_inset")) 15087 inset_type = INSET_FDIR; 15088 else if (!strcmp(res->inset_type, "fdir_flx_inset")) 15089 inset_type = INSET_FDIR_FLX; 15090 15091 memset(&inset, 0, sizeof(inset)); 15092 15093 ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id, 15094 &inset, inset_type); 15095 if (ret) { 15096 printf("Failed to clear input set.\n"); 15097 return; 15098 } 15099 15100 #endif 15101 15102 if (ret == -ENOTSUP) 15103 printf("Function not supported\n"); 15104 } 15105 15106 cmdline_parse_token_string_t cmd_clear_input_set_port = 15107 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15108 port, "port"); 15109 cmdline_parse_token_string_t cmd_clear_input_set_cfg = 15110 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15111 cfg, "config"); 15112 cmdline_parse_token_num_t cmd_clear_input_set_port_id = 15113 TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result, 15114 port_id, UINT16); 15115 cmdline_parse_token_string_t cmd_clear_input_set_pctype = 15116 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15117 pctype, "pctype"); 15118 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id = 15119 TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result, 15120 pctype_id, UINT8); 15121 cmdline_parse_token_string_t cmd_clear_input_set_inset_type = 15122 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15123 inset_type, 15124 "hash_inset#fdir_inset#fdir_flx_inset"); 15125 cmdline_parse_token_string_t cmd_clear_input_set_clear = 15126 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15127 clear, "clear"); 15128 cmdline_parse_token_string_t cmd_clear_input_set_all = 15129 TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result, 15130 all, "all"); 15131 15132 cmdline_parse_inst_t cmd_clear_input_set = { 15133 .f = cmd_clear_input_set_parsed, 15134 .data = NULL, 15135 .help_str = "port config <port_id> pctype <pctype_id> hash_inset|" 15136 "fdir_inset|fdir_flx_inset clear all", 15137 .tokens = { 15138 (void *)&cmd_clear_input_set_port, 15139 (void *)&cmd_clear_input_set_cfg, 15140 (void *)&cmd_clear_input_set_port_id, 15141 (void *)&cmd_clear_input_set_pctype, 15142 (void *)&cmd_clear_input_set_pctype_id, 15143 (void *)&cmd_clear_input_set_inset_type, 15144 (void *)&cmd_clear_input_set_clear, 15145 (void *)&cmd_clear_input_set_all, 15146 NULL, 15147 }, 15148 }; 15149 15150 /* show vf stats */ 15151 15152 /* Common result structure for show vf stats */ 15153 struct cmd_show_vf_stats_result { 15154 cmdline_fixed_string_t show; 15155 cmdline_fixed_string_t vf; 15156 cmdline_fixed_string_t stats; 15157 portid_t port_id; 15158 uint16_t vf_id; 15159 }; 15160 15161 /* Common CLI fields show vf stats*/ 15162 cmdline_parse_token_string_t cmd_show_vf_stats_show = 15163 TOKEN_STRING_INITIALIZER 15164 (struct cmd_show_vf_stats_result, 15165 show, "show"); 15166 cmdline_parse_token_string_t cmd_show_vf_stats_vf = 15167 TOKEN_STRING_INITIALIZER 15168 (struct cmd_show_vf_stats_result, 15169 vf, "vf"); 15170 cmdline_parse_token_string_t cmd_show_vf_stats_stats = 15171 TOKEN_STRING_INITIALIZER 15172 (struct cmd_show_vf_stats_result, 15173 stats, "stats"); 15174 cmdline_parse_token_num_t cmd_show_vf_stats_port_id = 15175 TOKEN_NUM_INITIALIZER 15176 (struct cmd_show_vf_stats_result, 15177 port_id, UINT16); 15178 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id = 15179 TOKEN_NUM_INITIALIZER 15180 (struct cmd_show_vf_stats_result, 15181 vf_id, UINT16); 15182 15183 static void 15184 cmd_show_vf_stats_parsed( 15185 void *parsed_result, 15186 __attribute__((unused)) struct cmdline *cl, 15187 __attribute__((unused)) void *data) 15188 { 15189 struct cmd_show_vf_stats_result *res = parsed_result; 15190 struct rte_eth_stats stats; 15191 int ret = -ENOTSUP; 15192 static const char *nic_stats_border = "########################"; 15193 15194 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15195 return; 15196 15197 memset(&stats, 0, sizeof(stats)); 15198 15199 #ifdef RTE_LIBRTE_I40E_PMD 15200 if (ret == -ENOTSUP) 15201 ret = rte_pmd_i40e_get_vf_stats(res->port_id, 15202 res->vf_id, 15203 &stats); 15204 #endif 15205 #ifdef RTE_LIBRTE_BNXT_PMD 15206 if (ret == -ENOTSUP) 15207 ret = rte_pmd_bnxt_get_vf_stats(res->port_id, 15208 res->vf_id, 15209 &stats); 15210 #endif 15211 15212 switch (ret) { 15213 case 0: 15214 break; 15215 case -EINVAL: 15216 printf("invalid vf_id %d\n", res->vf_id); 15217 break; 15218 case -ENODEV: 15219 printf("invalid port_id %d\n", res->port_id); 15220 break; 15221 case -ENOTSUP: 15222 printf("function not implemented\n"); 15223 break; 15224 default: 15225 printf("programming error: (%s)\n", strerror(-ret)); 15226 } 15227 15228 printf("\n %s NIC statistics for port %-2d vf %-2d %s\n", 15229 nic_stats_border, res->port_id, res->vf_id, nic_stats_border); 15230 15231 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 15232 "%-"PRIu64"\n", 15233 stats.ipackets, stats.imissed, stats.ibytes); 15234 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 15235 printf(" RX-nombuf: %-10"PRIu64"\n", 15236 stats.rx_nombuf); 15237 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 15238 "%-"PRIu64"\n", 15239 stats.opackets, stats.oerrors, stats.obytes); 15240 15241 printf(" %s############################%s\n", 15242 nic_stats_border, nic_stats_border); 15243 } 15244 15245 cmdline_parse_inst_t cmd_show_vf_stats = { 15246 .f = cmd_show_vf_stats_parsed, 15247 .data = NULL, 15248 .help_str = "show vf stats <port_id> <vf_id>", 15249 .tokens = { 15250 (void *)&cmd_show_vf_stats_show, 15251 (void *)&cmd_show_vf_stats_vf, 15252 (void *)&cmd_show_vf_stats_stats, 15253 (void *)&cmd_show_vf_stats_port_id, 15254 (void *)&cmd_show_vf_stats_vf_id, 15255 NULL, 15256 }, 15257 }; 15258 15259 /* clear vf stats */ 15260 15261 /* Common result structure for clear vf stats */ 15262 struct cmd_clear_vf_stats_result { 15263 cmdline_fixed_string_t clear; 15264 cmdline_fixed_string_t vf; 15265 cmdline_fixed_string_t stats; 15266 portid_t port_id; 15267 uint16_t vf_id; 15268 }; 15269 15270 /* Common CLI fields clear vf stats*/ 15271 cmdline_parse_token_string_t cmd_clear_vf_stats_clear = 15272 TOKEN_STRING_INITIALIZER 15273 (struct cmd_clear_vf_stats_result, 15274 clear, "clear"); 15275 cmdline_parse_token_string_t cmd_clear_vf_stats_vf = 15276 TOKEN_STRING_INITIALIZER 15277 (struct cmd_clear_vf_stats_result, 15278 vf, "vf"); 15279 cmdline_parse_token_string_t cmd_clear_vf_stats_stats = 15280 TOKEN_STRING_INITIALIZER 15281 (struct cmd_clear_vf_stats_result, 15282 stats, "stats"); 15283 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id = 15284 TOKEN_NUM_INITIALIZER 15285 (struct cmd_clear_vf_stats_result, 15286 port_id, UINT16); 15287 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id = 15288 TOKEN_NUM_INITIALIZER 15289 (struct cmd_clear_vf_stats_result, 15290 vf_id, UINT16); 15291 15292 static void 15293 cmd_clear_vf_stats_parsed( 15294 void *parsed_result, 15295 __attribute__((unused)) struct cmdline *cl, 15296 __attribute__((unused)) void *data) 15297 { 15298 struct cmd_clear_vf_stats_result *res = parsed_result; 15299 int ret = -ENOTSUP; 15300 15301 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15302 return; 15303 15304 #ifdef RTE_LIBRTE_I40E_PMD 15305 if (ret == -ENOTSUP) 15306 ret = rte_pmd_i40e_reset_vf_stats(res->port_id, 15307 res->vf_id); 15308 #endif 15309 #ifdef RTE_LIBRTE_BNXT_PMD 15310 if (ret == -ENOTSUP) 15311 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id, 15312 res->vf_id); 15313 #endif 15314 15315 switch (ret) { 15316 case 0: 15317 break; 15318 case -EINVAL: 15319 printf("invalid vf_id %d\n", res->vf_id); 15320 break; 15321 case -ENODEV: 15322 printf("invalid port_id %d\n", res->port_id); 15323 break; 15324 case -ENOTSUP: 15325 printf("function not implemented\n"); 15326 break; 15327 default: 15328 printf("programming error: (%s)\n", strerror(-ret)); 15329 } 15330 } 15331 15332 cmdline_parse_inst_t cmd_clear_vf_stats = { 15333 .f = cmd_clear_vf_stats_parsed, 15334 .data = NULL, 15335 .help_str = "clear vf stats <port_id> <vf_id>", 15336 .tokens = { 15337 (void *)&cmd_clear_vf_stats_clear, 15338 (void *)&cmd_clear_vf_stats_vf, 15339 (void *)&cmd_clear_vf_stats_stats, 15340 (void *)&cmd_clear_vf_stats_port_id, 15341 (void *)&cmd_clear_vf_stats_vf_id, 15342 NULL, 15343 }, 15344 }; 15345 15346 /* port config pctype mapping reset */ 15347 15348 /* Common result structure for port config pctype mapping reset */ 15349 struct cmd_pctype_mapping_reset_result { 15350 cmdline_fixed_string_t port; 15351 cmdline_fixed_string_t config; 15352 portid_t port_id; 15353 cmdline_fixed_string_t pctype; 15354 cmdline_fixed_string_t mapping; 15355 cmdline_fixed_string_t reset; 15356 }; 15357 15358 /* Common CLI fields for port config pctype mapping reset*/ 15359 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port = 15360 TOKEN_STRING_INITIALIZER 15361 (struct cmd_pctype_mapping_reset_result, 15362 port, "port"); 15363 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config = 15364 TOKEN_STRING_INITIALIZER 15365 (struct cmd_pctype_mapping_reset_result, 15366 config, "config"); 15367 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id = 15368 TOKEN_NUM_INITIALIZER 15369 (struct cmd_pctype_mapping_reset_result, 15370 port_id, UINT16); 15371 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype = 15372 TOKEN_STRING_INITIALIZER 15373 (struct cmd_pctype_mapping_reset_result, 15374 pctype, "pctype"); 15375 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping = 15376 TOKEN_STRING_INITIALIZER 15377 (struct cmd_pctype_mapping_reset_result, 15378 mapping, "mapping"); 15379 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset = 15380 TOKEN_STRING_INITIALIZER 15381 (struct cmd_pctype_mapping_reset_result, 15382 reset, "reset"); 15383 15384 static void 15385 cmd_pctype_mapping_reset_parsed( 15386 void *parsed_result, 15387 __attribute__((unused)) struct cmdline *cl, 15388 __attribute__((unused)) void *data) 15389 { 15390 struct cmd_pctype_mapping_reset_result *res = parsed_result; 15391 int ret = -ENOTSUP; 15392 15393 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15394 return; 15395 15396 #ifdef RTE_LIBRTE_I40E_PMD 15397 ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id); 15398 #endif 15399 15400 switch (ret) { 15401 case 0: 15402 break; 15403 case -ENODEV: 15404 printf("invalid port_id %d\n", res->port_id); 15405 break; 15406 case -ENOTSUP: 15407 printf("function not implemented\n"); 15408 break; 15409 default: 15410 printf("programming error: (%s)\n", strerror(-ret)); 15411 } 15412 } 15413 15414 cmdline_parse_inst_t cmd_pctype_mapping_reset = { 15415 .f = cmd_pctype_mapping_reset_parsed, 15416 .data = NULL, 15417 .help_str = "port config <port_id> pctype mapping reset", 15418 .tokens = { 15419 (void *)&cmd_pctype_mapping_reset_port, 15420 (void *)&cmd_pctype_mapping_reset_config, 15421 (void *)&cmd_pctype_mapping_reset_port_id, 15422 (void *)&cmd_pctype_mapping_reset_pctype, 15423 (void *)&cmd_pctype_mapping_reset_mapping, 15424 (void *)&cmd_pctype_mapping_reset_reset, 15425 NULL, 15426 }, 15427 }; 15428 15429 /* show port pctype mapping */ 15430 15431 /* Common result structure for show port pctype mapping */ 15432 struct cmd_pctype_mapping_get_result { 15433 cmdline_fixed_string_t show; 15434 cmdline_fixed_string_t port; 15435 portid_t port_id; 15436 cmdline_fixed_string_t pctype; 15437 cmdline_fixed_string_t mapping; 15438 }; 15439 15440 /* Common CLI fields for pctype mapping get */ 15441 cmdline_parse_token_string_t cmd_pctype_mapping_get_show = 15442 TOKEN_STRING_INITIALIZER 15443 (struct cmd_pctype_mapping_get_result, 15444 show, "show"); 15445 cmdline_parse_token_string_t cmd_pctype_mapping_get_port = 15446 TOKEN_STRING_INITIALIZER 15447 (struct cmd_pctype_mapping_get_result, 15448 port, "port"); 15449 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id = 15450 TOKEN_NUM_INITIALIZER 15451 (struct cmd_pctype_mapping_get_result, 15452 port_id, UINT16); 15453 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype = 15454 TOKEN_STRING_INITIALIZER 15455 (struct cmd_pctype_mapping_get_result, 15456 pctype, "pctype"); 15457 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping = 15458 TOKEN_STRING_INITIALIZER 15459 (struct cmd_pctype_mapping_get_result, 15460 mapping, "mapping"); 15461 15462 static void 15463 cmd_pctype_mapping_get_parsed( 15464 void *parsed_result, 15465 __attribute__((unused)) struct cmdline *cl, 15466 __attribute__((unused)) void *data) 15467 { 15468 struct cmd_pctype_mapping_get_result *res = parsed_result; 15469 int ret = -ENOTSUP; 15470 #ifdef RTE_LIBRTE_I40E_PMD 15471 struct rte_pmd_i40e_flow_type_mapping 15472 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; 15473 int i, j, first_pctype; 15474 #endif 15475 15476 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15477 return; 15478 15479 #ifdef RTE_LIBRTE_I40E_PMD 15480 ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping); 15481 #endif 15482 15483 switch (ret) { 15484 case 0: 15485 break; 15486 case -ENODEV: 15487 printf("invalid port_id %d\n", res->port_id); 15488 return; 15489 case -ENOTSUP: 15490 printf("function not implemented\n"); 15491 return; 15492 default: 15493 printf("programming error: (%s)\n", strerror(-ret)); 15494 return; 15495 } 15496 15497 #ifdef RTE_LIBRTE_I40E_PMD 15498 for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) { 15499 if (mapping[i].pctype != 0ULL) { 15500 first_pctype = 1; 15501 15502 printf("pctype: "); 15503 for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) { 15504 if (mapping[i].pctype & (1ULL << j)) { 15505 printf(first_pctype ? 15506 "%02d" : ",%02d", j); 15507 first_pctype = 0; 15508 } 15509 } 15510 printf(" -> flowtype: %02d\n", mapping[i].flow_type); 15511 } 15512 } 15513 #endif 15514 } 15515 15516 cmdline_parse_inst_t cmd_pctype_mapping_get = { 15517 .f = cmd_pctype_mapping_get_parsed, 15518 .data = NULL, 15519 .help_str = "show port <port_id> pctype mapping", 15520 .tokens = { 15521 (void *)&cmd_pctype_mapping_get_show, 15522 (void *)&cmd_pctype_mapping_get_port, 15523 (void *)&cmd_pctype_mapping_get_port_id, 15524 (void *)&cmd_pctype_mapping_get_pctype, 15525 (void *)&cmd_pctype_mapping_get_mapping, 15526 NULL, 15527 }, 15528 }; 15529 15530 /* port config pctype mapping update */ 15531 15532 /* Common result structure for port config pctype mapping update */ 15533 struct cmd_pctype_mapping_update_result { 15534 cmdline_fixed_string_t port; 15535 cmdline_fixed_string_t config; 15536 portid_t port_id; 15537 cmdline_fixed_string_t pctype; 15538 cmdline_fixed_string_t mapping; 15539 cmdline_fixed_string_t update; 15540 cmdline_fixed_string_t pctype_list; 15541 uint16_t flow_type; 15542 }; 15543 15544 /* Common CLI fields for pctype mapping update*/ 15545 cmdline_parse_token_string_t cmd_pctype_mapping_update_port = 15546 TOKEN_STRING_INITIALIZER 15547 (struct cmd_pctype_mapping_update_result, 15548 port, "port"); 15549 cmdline_parse_token_string_t cmd_pctype_mapping_update_config = 15550 TOKEN_STRING_INITIALIZER 15551 (struct cmd_pctype_mapping_update_result, 15552 config, "config"); 15553 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id = 15554 TOKEN_NUM_INITIALIZER 15555 (struct cmd_pctype_mapping_update_result, 15556 port_id, UINT16); 15557 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype = 15558 TOKEN_STRING_INITIALIZER 15559 (struct cmd_pctype_mapping_update_result, 15560 pctype, "pctype"); 15561 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping = 15562 TOKEN_STRING_INITIALIZER 15563 (struct cmd_pctype_mapping_update_result, 15564 mapping, "mapping"); 15565 cmdline_parse_token_string_t cmd_pctype_mapping_update_update = 15566 TOKEN_STRING_INITIALIZER 15567 (struct cmd_pctype_mapping_update_result, 15568 update, "update"); 15569 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type = 15570 TOKEN_STRING_INITIALIZER 15571 (struct cmd_pctype_mapping_update_result, 15572 pctype_list, NULL); 15573 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type = 15574 TOKEN_NUM_INITIALIZER 15575 (struct cmd_pctype_mapping_update_result, 15576 flow_type, UINT16); 15577 15578 static void 15579 cmd_pctype_mapping_update_parsed( 15580 void *parsed_result, 15581 __attribute__((unused)) struct cmdline *cl, 15582 __attribute__((unused)) void *data) 15583 { 15584 struct cmd_pctype_mapping_update_result *res = parsed_result; 15585 int ret = -ENOTSUP; 15586 #ifdef RTE_LIBRTE_I40E_PMD 15587 struct rte_pmd_i40e_flow_type_mapping mapping; 15588 unsigned int i; 15589 unsigned int nb_item; 15590 unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX]; 15591 #endif 15592 15593 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15594 return; 15595 15596 #ifdef RTE_LIBRTE_I40E_PMD 15597 nb_item = parse_item_list(res->pctype_list, "pctypes", 15598 RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1); 15599 mapping.flow_type = res->flow_type; 15600 for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++) 15601 mapping.pctype |= (1ULL << pctype_list[i]); 15602 ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id, 15603 &mapping, 15604 1, 15605 0); 15606 #endif 15607 15608 switch (ret) { 15609 case 0: 15610 break; 15611 case -EINVAL: 15612 printf("invalid pctype or flow type\n"); 15613 break; 15614 case -ENODEV: 15615 printf("invalid port_id %d\n", res->port_id); 15616 break; 15617 case -ENOTSUP: 15618 printf("function not implemented\n"); 15619 break; 15620 default: 15621 printf("programming error: (%s)\n", strerror(-ret)); 15622 } 15623 } 15624 15625 cmdline_parse_inst_t cmd_pctype_mapping_update = { 15626 .f = cmd_pctype_mapping_update_parsed, 15627 .data = NULL, 15628 .help_str = "port config <port_id> pctype mapping update" 15629 " <pctype_id_0,[pctype_id_1]*> <flowtype_id>", 15630 .tokens = { 15631 (void *)&cmd_pctype_mapping_update_port, 15632 (void *)&cmd_pctype_mapping_update_config, 15633 (void *)&cmd_pctype_mapping_update_port_id, 15634 (void *)&cmd_pctype_mapping_update_pctype, 15635 (void *)&cmd_pctype_mapping_update_mapping, 15636 (void *)&cmd_pctype_mapping_update_update, 15637 (void *)&cmd_pctype_mapping_update_pc_type, 15638 (void *)&cmd_pctype_mapping_update_flow_type, 15639 NULL, 15640 }, 15641 }; 15642 15643 /* ptype mapping get */ 15644 15645 /* Common result structure for ptype mapping get */ 15646 struct cmd_ptype_mapping_get_result { 15647 cmdline_fixed_string_t ptype; 15648 cmdline_fixed_string_t mapping; 15649 cmdline_fixed_string_t get; 15650 portid_t port_id; 15651 uint8_t valid_only; 15652 }; 15653 15654 /* Common CLI fields for ptype mapping get */ 15655 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype = 15656 TOKEN_STRING_INITIALIZER 15657 (struct cmd_ptype_mapping_get_result, 15658 ptype, "ptype"); 15659 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping = 15660 TOKEN_STRING_INITIALIZER 15661 (struct cmd_ptype_mapping_get_result, 15662 mapping, "mapping"); 15663 cmdline_parse_token_string_t cmd_ptype_mapping_get_get = 15664 TOKEN_STRING_INITIALIZER 15665 (struct cmd_ptype_mapping_get_result, 15666 get, "get"); 15667 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id = 15668 TOKEN_NUM_INITIALIZER 15669 (struct cmd_ptype_mapping_get_result, 15670 port_id, UINT16); 15671 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only = 15672 TOKEN_NUM_INITIALIZER 15673 (struct cmd_ptype_mapping_get_result, 15674 valid_only, UINT8); 15675 15676 static void 15677 cmd_ptype_mapping_get_parsed( 15678 void *parsed_result, 15679 __attribute__((unused)) struct cmdline *cl, 15680 __attribute__((unused)) void *data) 15681 { 15682 struct cmd_ptype_mapping_get_result *res = parsed_result; 15683 int ret = -ENOTSUP; 15684 #ifdef RTE_LIBRTE_I40E_PMD 15685 int max_ptype_num = 256; 15686 struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num]; 15687 uint16_t count; 15688 int i; 15689 #endif 15690 15691 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15692 return; 15693 15694 #ifdef RTE_LIBRTE_I40E_PMD 15695 ret = rte_pmd_i40e_ptype_mapping_get(res->port_id, 15696 mapping, 15697 max_ptype_num, 15698 &count, 15699 res->valid_only); 15700 #endif 15701 15702 switch (ret) { 15703 case 0: 15704 break; 15705 case -ENODEV: 15706 printf("invalid port_id %d\n", res->port_id); 15707 break; 15708 case -ENOTSUP: 15709 printf("function not implemented\n"); 15710 break; 15711 default: 15712 printf("programming error: (%s)\n", strerror(-ret)); 15713 } 15714 15715 #ifdef RTE_LIBRTE_I40E_PMD 15716 if (!ret) { 15717 for (i = 0; i < count; i++) 15718 printf("%3d\t0x%08x\n", 15719 mapping[i].hw_ptype, mapping[i].sw_ptype); 15720 } 15721 #endif 15722 } 15723 15724 cmdline_parse_inst_t cmd_ptype_mapping_get = { 15725 .f = cmd_ptype_mapping_get_parsed, 15726 .data = NULL, 15727 .help_str = "ptype mapping get <port_id> <valid_only>", 15728 .tokens = { 15729 (void *)&cmd_ptype_mapping_get_ptype, 15730 (void *)&cmd_ptype_mapping_get_mapping, 15731 (void *)&cmd_ptype_mapping_get_get, 15732 (void *)&cmd_ptype_mapping_get_port_id, 15733 (void *)&cmd_ptype_mapping_get_valid_only, 15734 NULL, 15735 }, 15736 }; 15737 15738 /* ptype mapping replace */ 15739 15740 /* Common result structure for ptype mapping replace */ 15741 struct cmd_ptype_mapping_replace_result { 15742 cmdline_fixed_string_t ptype; 15743 cmdline_fixed_string_t mapping; 15744 cmdline_fixed_string_t replace; 15745 portid_t port_id; 15746 uint32_t target; 15747 uint8_t mask; 15748 uint32_t pkt_type; 15749 }; 15750 15751 /* Common CLI fields for ptype mapping replace */ 15752 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype = 15753 TOKEN_STRING_INITIALIZER 15754 (struct cmd_ptype_mapping_replace_result, 15755 ptype, "ptype"); 15756 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping = 15757 TOKEN_STRING_INITIALIZER 15758 (struct cmd_ptype_mapping_replace_result, 15759 mapping, "mapping"); 15760 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace = 15761 TOKEN_STRING_INITIALIZER 15762 (struct cmd_ptype_mapping_replace_result, 15763 replace, "replace"); 15764 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id = 15765 TOKEN_NUM_INITIALIZER 15766 (struct cmd_ptype_mapping_replace_result, 15767 port_id, UINT16); 15768 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target = 15769 TOKEN_NUM_INITIALIZER 15770 (struct cmd_ptype_mapping_replace_result, 15771 target, UINT32); 15772 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask = 15773 TOKEN_NUM_INITIALIZER 15774 (struct cmd_ptype_mapping_replace_result, 15775 mask, UINT8); 15776 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type = 15777 TOKEN_NUM_INITIALIZER 15778 (struct cmd_ptype_mapping_replace_result, 15779 pkt_type, UINT32); 15780 15781 static void 15782 cmd_ptype_mapping_replace_parsed( 15783 void *parsed_result, 15784 __attribute__((unused)) struct cmdline *cl, 15785 __attribute__((unused)) void *data) 15786 { 15787 struct cmd_ptype_mapping_replace_result *res = parsed_result; 15788 int ret = -ENOTSUP; 15789 15790 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15791 return; 15792 15793 #ifdef RTE_LIBRTE_I40E_PMD 15794 ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id, 15795 res->target, 15796 res->mask, 15797 res->pkt_type); 15798 #endif 15799 15800 switch (ret) { 15801 case 0: 15802 break; 15803 case -EINVAL: 15804 printf("invalid ptype 0x%8x or 0x%8x\n", 15805 res->target, res->pkt_type); 15806 break; 15807 case -ENODEV: 15808 printf("invalid port_id %d\n", res->port_id); 15809 break; 15810 case -ENOTSUP: 15811 printf("function not implemented\n"); 15812 break; 15813 default: 15814 printf("programming error: (%s)\n", strerror(-ret)); 15815 } 15816 } 15817 15818 cmdline_parse_inst_t cmd_ptype_mapping_replace = { 15819 .f = cmd_ptype_mapping_replace_parsed, 15820 .data = NULL, 15821 .help_str = 15822 "ptype mapping replace <port_id> <target> <mask> <pkt_type>", 15823 .tokens = { 15824 (void *)&cmd_ptype_mapping_replace_ptype, 15825 (void *)&cmd_ptype_mapping_replace_mapping, 15826 (void *)&cmd_ptype_mapping_replace_replace, 15827 (void *)&cmd_ptype_mapping_replace_port_id, 15828 (void *)&cmd_ptype_mapping_replace_target, 15829 (void *)&cmd_ptype_mapping_replace_mask, 15830 (void *)&cmd_ptype_mapping_replace_pkt_type, 15831 NULL, 15832 }, 15833 }; 15834 15835 /* ptype mapping reset */ 15836 15837 /* Common result structure for ptype mapping reset */ 15838 struct cmd_ptype_mapping_reset_result { 15839 cmdline_fixed_string_t ptype; 15840 cmdline_fixed_string_t mapping; 15841 cmdline_fixed_string_t reset; 15842 portid_t port_id; 15843 }; 15844 15845 /* Common CLI fields for ptype mapping reset*/ 15846 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype = 15847 TOKEN_STRING_INITIALIZER 15848 (struct cmd_ptype_mapping_reset_result, 15849 ptype, "ptype"); 15850 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping = 15851 TOKEN_STRING_INITIALIZER 15852 (struct cmd_ptype_mapping_reset_result, 15853 mapping, "mapping"); 15854 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset = 15855 TOKEN_STRING_INITIALIZER 15856 (struct cmd_ptype_mapping_reset_result, 15857 reset, "reset"); 15858 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id = 15859 TOKEN_NUM_INITIALIZER 15860 (struct cmd_ptype_mapping_reset_result, 15861 port_id, UINT16); 15862 15863 static void 15864 cmd_ptype_mapping_reset_parsed( 15865 void *parsed_result, 15866 __attribute__((unused)) struct cmdline *cl, 15867 __attribute__((unused)) void *data) 15868 { 15869 struct cmd_ptype_mapping_reset_result *res = parsed_result; 15870 int ret = -ENOTSUP; 15871 15872 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15873 return; 15874 15875 #ifdef RTE_LIBRTE_I40E_PMD 15876 ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id); 15877 #endif 15878 15879 switch (ret) { 15880 case 0: 15881 break; 15882 case -ENODEV: 15883 printf("invalid port_id %d\n", res->port_id); 15884 break; 15885 case -ENOTSUP: 15886 printf("function not implemented\n"); 15887 break; 15888 default: 15889 printf("programming error: (%s)\n", strerror(-ret)); 15890 } 15891 } 15892 15893 cmdline_parse_inst_t cmd_ptype_mapping_reset = { 15894 .f = cmd_ptype_mapping_reset_parsed, 15895 .data = NULL, 15896 .help_str = "ptype mapping reset <port_id>", 15897 .tokens = { 15898 (void *)&cmd_ptype_mapping_reset_ptype, 15899 (void *)&cmd_ptype_mapping_reset_mapping, 15900 (void *)&cmd_ptype_mapping_reset_reset, 15901 (void *)&cmd_ptype_mapping_reset_port_id, 15902 NULL, 15903 }, 15904 }; 15905 15906 /* ptype mapping update */ 15907 15908 /* Common result structure for ptype mapping update */ 15909 struct cmd_ptype_mapping_update_result { 15910 cmdline_fixed_string_t ptype; 15911 cmdline_fixed_string_t mapping; 15912 cmdline_fixed_string_t reset; 15913 portid_t port_id; 15914 uint8_t hw_ptype; 15915 uint32_t sw_ptype; 15916 }; 15917 15918 /* Common CLI fields for ptype mapping update*/ 15919 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype = 15920 TOKEN_STRING_INITIALIZER 15921 (struct cmd_ptype_mapping_update_result, 15922 ptype, "ptype"); 15923 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping = 15924 TOKEN_STRING_INITIALIZER 15925 (struct cmd_ptype_mapping_update_result, 15926 mapping, "mapping"); 15927 cmdline_parse_token_string_t cmd_ptype_mapping_update_update = 15928 TOKEN_STRING_INITIALIZER 15929 (struct cmd_ptype_mapping_update_result, 15930 reset, "update"); 15931 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id = 15932 TOKEN_NUM_INITIALIZER 15933 (struct cmd_ptype_mapping_update_result, 15934 port_id, UINT16); 15935 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype = 15936 TOKEN_NUM_INITIALIZER 15937 (struct cmd_ptype_mapping_update_result, 15938 hw_ptype, UINT8); 15939 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype = 15940 TOKEN_NUM_INITIALIZER 15941 (struct cmd_ptype_mapping_update_result, 15942 sw_ptype, UINT32); 15943 15944 static void 15945 cmd_ptype_mapping_update_parsed( 15946 void *parsed_result, 15947 __attribute__((unused)) struct cmdline *cl, 15948 __attribute__((unused)) void *data) 15949 { 15950 struct cmd_ptype_mapping_update_result *res = parsed_result; 15951 int ret = -ENOTSUP; 15952 #ifdef RTE_LIBRTE_I40E_PMD 15953 struct rte_pmd_i40e_ptype_mapping mapping; 15954 #endif 15955 if (port_id_is_invalid(res->port_id, ENABLED_WARN)) 15956 return; 15957 15958 #ifdef RTE_LIBRTE_I40E_PMD 15959 mapping.hw_ptype = res->hw_ptype; 15960 mapping.sw_ptype = res->sw_ptype; 15961 ret = rte_pmd_i40e_ptype_mapping_update(res->port_id, 15962 &mapping, 15963 1, 15964 0); 15965 #endif 15966 15967 switch (ret) { 15968 case 0: 15969 break; 15970 case -EINVAL: 15971 printf("invalid ptype 0x%8x\n", res->sw_ptype); 15972 break; 15973 case -ENODEV: 15974 printf("invalid port_id %d\n", res->port_id); 15975 break; 15976 case -ENOTSUP: 15977 printf("function not implemented\n"); 15978 break; 15979 default: 15980 printf("programming error: (%s)\n", strerror(-ret)); 15981 } 15982 } 15983 15984 cmdline_parse_inst_t cmd_ptype_mapping_update = { 15985 .f = cmd_ptype_mapping_update_parsed, 15986 .data = NULL, 15987 .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>", 15988 .tokens = { 15989 (void *)&cmd_ptype_mapping_update_ptype, 15990 (void *)&cmd_ptype_mapping_update_mapping, 15991 (void *)&cmd_ptype_mapping_update_update, 15992 (void *)&cmd_ptype_mapping_update_port_id, 15993 (void *)&cmd_ptype_mapping_update_hw_ptype, 15994 (void *)&cmd_ptype_mapping_update_sw_ptype, 15995 NULL, 15996 }, 15997 }; 15998 15999 /* Common result structure for file commands */ 16000 struct cmd_cmdfile_result { 16001 cmdline_fixed_string_t load; 16002 cmdline_fixed_string_t filename; 16003 }; 16004 16005 /* Common CLI fields for file commands */ 16006 cmdline_parse_token_string_t cmd_load_cmdfile = 16007 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load"); 16008 cmdline_parse_token_string_t cmd_load_cmdfile_filename = 16009 TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL); 16010 16011 static void 16012 cmd_load_from_file_parsed( 16013 void *parsed_result, 16014 __attribute__((unused)) struct cmdline *cl, 16015 __attribute__((unused)) void *data) 16016 { 16017 struct cmd_cmdfile_result *res = parsed_result; 16018 16019 cmdline_read_from_file(res->filename); 16020 } 16021 16022 cmdline_parse_inst_t cmd_load_from_file = { 16023 .f = cmd_load_from_file_parsed, 16024 .data = NULL, 16025 .help_str = "load <filename>", 16026 .tokens = { 16027 (void *)&cmd_load_cmdfile, 16028 (void *)&cmd_load_cmdfile_filename, 16029 NULL, 16030 }, 16031 }; 16032 16033 /* ******************************************************************************** */ 16034 16035 /* list of instructions */ 16036 cmdline_parse_ctx_t main_ctx[] = { 16037 (cmdline_parse_inst_t *)&cmd_help_brief, 16038 (cmdline_parse_inst_t *)&cmd_help_long, 16039 (cmdline_parse_inst_t *)&cmd_quit, 16040 (cmdline_parse_inst_t *)&cmd_load_from_file, 16041 (cmdline_parse_inst_t *)&cmd_showport, 16042 (cmdline_parse_inst_t *)&cmd_showqueue, 16043 (cmdline_parse_inst_t *)&cmd_showportall, 16044 (cmdline_parse_inst_t *)&cmd_showcfg, 16045 (cmdline_parse_inst_t *)&cmd_start, 16046 (cmdline_parse_inst_t *)&cmd_start_tx_first, 16047 (cmdline_parse_inst_t *)&cmd_start_tx_first_n, 16048 (cmdline_parse_inst_t *)&cmd_set_link_up, 16049 (cmdline_parse_inst_t *)&cmd_set_link_down, 16050 (cmdline_parse_inst_t *)&cmd_reset, 16051 (cmdline_parse_inst_t *)&cmd_set_numbers, 16052 (cmdline_parse_inst_t *)&cmd_set_log, 16053 (cmdline_parse_inst_t *)&cmd_set_txpkts, 16054 (cmdline_parse_inst_t *)&cmd_set_txsplit, 16055 (cmdline_parse_inst_t *)&cmd_set_fwd_list, 16056 (cmdline_parse_inst_t *)&cmd_set_fwd_mask, 16057 (cmdline_parse_inst_t *)&cmd_set_fwd_mode, 16058 (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode, 16059 (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry, 16060 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, 16061 (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, 16062 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one, 16063 (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, 16064 (cmdline_parse_inst_t *)&cmd_set_flush_rx, 16065 (cmdline_parse_inst_t *)&cmd_set_link_check, 16066 (cmdline_parse_inst_t *)&cmd_set_bypass_mode, 16067 (cmdline_parse_inst_t *)&cmd_set_bypass_event, 16068 (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, 16069 (cmdline_parse_inst_t *)&cmd_show_bypass_config, 16070 #ifdef RTE_LIBRTE_PMD_BOND 16071 (cmdline_parse_inst_t *) &cmd_set_bonding_mode, 16072 (cmdline_parse_inst_t *) &cmd_show_bonding_config, 16073 (cmdline_parse_inst_t *) &cmd_set_bonding_primary, 16074 (cmdline_parse_inst_t *) &cmd_add_bonding_slave, 16075 (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, 16076 (cmdline_parse_inst_t *) &cmd_create_bonded_device, 16077 (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, 16078 (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, 16079 (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, 16080 (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues, 16081 (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy, 16082 #endif 16083 (cmdline_parse_inst_t *)&cmd_vlan_offload, 16084 (cmdline_parse_inst_t *)&cmd_vlan_tpid, 16085 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, 16086 (cmdline_parse_inst_t *)&cmd_rx_vlan_filter, 16087 (cmdline_parse_inst_t *)&cmd_tx_vlan_set, 16088 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq, 16089 (cmdline_parse_inst_t *)&cmd_tx_vlan_reset, 16090 (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, 16091 (cmdline_parse_inst_t *)&cmd_csum_set, 16092 (cmdline_parse_inst_t *)&cmd_csum_show, 16093 (cmdline_parse_inst_t *)&cmd_csum_tunnel, 16094 (cmdline_parse_inst_t *)&cmd_tso_set, 16095 (cmdline_parse_inst_t *)&cmd_tso_show, 16096 (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, 16097 (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, 16098 (cmdline_parse_inst_t *)&cmd_gro_enable, 16099 (cmdline_parse_inst_t *)&cmd_gro_flush, 16100 (cmdline_parse_inst_t *)&cmd_gro_show, 16101 (cmdline_parse_inst_t *)&cmd_gso_enable, 16102 (cmdline_parse_inst_t *)&cmd_gso_size, 16103 (cmdline_parse_inst_t *)&cmd_gso_show, 16104 (cmdline_parse_inst_t *)&cmd_link_flow_control_set, 16105 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, 16106 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, 16107 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw, 16108 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw, 16109 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt, 16110 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon, 16111 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd, 16112 (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg, 16113 (cmdline_parse_inst_t *)&cmd_priority_flow_control_set, 16114 (cmdline_parse_inst_t *)&cmd_config_dcb, 16115 (cmdline_parse_inst_t *)&cmd_read_reg, 16116 (cmdline_parse_inst_t *)&cmd_read_reg_bit_field, 16117 (cmdline_parse_inst_t *)&cmd_read_reg_bit, 16118 (cmdline_parse_inst_t *)&cmd_write_reg, 16119 (cmdline_parse_inst_t *)&cmd_write_reg_bit_field, 16120 (cmdline_parse_inst_t *)&cmd_write_reg_bit, 16121 (cmdline_parse_inst_t *)&cmd_read_rxd_txd, 16122 (cmdline_parse_inst_t *)&cmd_stop, 16123 (cmdline_parse_inst_t *)&cmd_mac_addr, 16124 (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer, 16125 (cmdline_parse_inst_t *)&cmd_set_qmap, 16126 (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero, 16127 (cmdline_parse_inst_t *)&cmd_operate_port, 16128 (cmdline_parse_inst_t *)&cmd_operate_specific_port, 16129 (cmdline_parse_inst_t *)&cmd_operate_attach_port, 16130 (cmdline_parse_inst_t *)&cmd_operate_detach_port, 16131 (cmdline_parse_inst_t *)&cmd_config_speed_all, 16132 (cmdline_parse_inst_t *)&cmd_config_speed_specific, 16133 (cmdline_parse_inst_t *)&cmd_config_rx_tx, 16134 (cmdline_parse_inst_t *)&cmd_config_mtu, 16135 (cmdline_parse_inst_t *)&cmd_config_max_pkt_len, 16136 (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag, 16137 (cmdline_parse_inst_t *)&cmd_config_rss, 16138 (cmdline_parse_inst_t *)&cmd_config_rxtx_queue, 16139 (cmdline_parse_inst_t *)&cmd_config_rss_reta, 16140 (cmdline_parse_inst_t *)&cmd_showport_reta, 16141 (cmdline_parse_inst_t *)&cmd_config_burst, 16142 (cmdline_parse_inst_t *)&cmd_config_thresh, 16143 (cmdline_parse_inst_t *)&cmd_config_threshold, 16144 (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter, 16145 (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter, 16146 (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter, 16147 (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter, 16148 (cmdline_parse_inst_t *)&cmd_queue_rate_limit, 16149 (cmdline_parse_inst_t *)&cmd_tunnel_filter, 16150 (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, 16151 (cmdline_parse_inst_t *)&cmd_global_config, 16152 (cmdline_parse_inst_t *)&cmd_set_mirror_mask, 16153 (cmdline_parse_inst_t *)&cmd_set_mirror_link, 16154 (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, 16155 (cmdline_parse_inst_t *)&cmd_showport_rss_hash, 16156 (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, 16157 (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, 16158 (cmdline_parse_inst_t *)&cmd_dump, 16159 (cmdline_parse_inst_t *)&cmd_dump_one, 16160 (cmdline_parse_inst_t *)&cmd_ethertype_filter, 16161 (cmdline_parse_inst_t *)&cmd_syn_filter, 16162 (cmdline_parse_inst_t *)&cmd_2tuple_filter, 16163 (cmdline_parse_inst_t *)&cmd_5tuple_filter, 16164 (cmdline_parse_inst_t *)&cmd_flex_filter, 16165 (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director, 16166 (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, 16167 (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, 16168 (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director, 16169 (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director, 16170 (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director, 16171 (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director, 16172 (cmdline_parse_inst_t *)&cmd_flush_flow_director, 16173 (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, 16174 (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, 16175 (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, 16176 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, 16177 (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload, 16178 (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port, 16179 (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port, 16180 (cmdline_parse_inst_t *)&cmd_get_hash_global_config, 16181 (cmdline_parse_inst_t *)&cmd_set_hash_global_config, 16182 (cmdline_parse_inst_t *)&cmd_set_hash_input_set, 16183 (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, 16184 (cmdline_parse_inst_t *)&cmd_flow, 16185 (cmdline_parse_inst_t *)&cmd_show_port_meter_cap, 16186 (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm, 16187 (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm, 16188 (cmdline_parse_inst_t *)&cmd_del_port_meter_profile, 16189 (cmdline_parse_inst_t *)&cmd_create_port_meter, 16190 (cmdline_parse_inst_t *)&cmd_enable_port_meter, 16191 (cmdline_parse_inst_t *)&cmd_disable_port_meter, 16192 (cmdline_parse_inst_t *)&cmd_del_port_meter, 16193 (cmdline_parse_inst_t *)&cmd_set_port_meter_profile, 16194 (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table, 16195 (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action, 16196 (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask, 16197 (cmdline_parse_inst_t *)&cmd_show_port_meter_stats, 16198 (cmdline_parse_inst_t *)&cmd_mcast_addr, 16199 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, 16200 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, 16201 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all, 16202 (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific, 16203 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en, 16204 (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis, 16205 (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis, 16206 (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis, 16207 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add, 16208 (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del, 16209 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof, 16210 (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof, 16211 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq, 16212 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, 16213 (cmdline_parse_inst_t *)&cmd_set_tx_loopback, 16214 (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, 16215 (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, 16216 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, 16217 (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, 16218 (cmdline_parse_inst_t *)&cmd_set_macsec_sc, 16219 (cmdline_parse_inst_t *)&cmd_set_macsec_sa, 16220 (cmdline_parse_inst_t *)&cmd_set_vf_traffic, 16221 (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, 16222 (cmdline_parse_inst_t *)&cmd_vf_rate_limit, 16223 (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, 16224 (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, 16225 (cmdline_parse_inst_t *)&cmd_set_vf_promisc, 16226 (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, 16227 (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, 16228 (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, 16229 (cmdline_parse_inst_t *)&cmd_vf_max_bw, 16230 (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw, 16231 (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, 16232 (cmdline_parse_inst_t *)&cmd_strict_link_prio, 16233 (cmdline_parse_inst_t *)&cmd_tc_min_bw, 16234 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED 16235 (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default, 16236 #endif 16237 (cmdline_parse_inst_t *)&cmd_ddp_add, 16238 (cmdline_parse_inst_t *)&cmd_ddp_del, 16239 (cmdline_parse_inst_t *)&cmd_ddp_get_list, 16240 (cmdline_parse_inst_t *)&cmd_ddp_get_info, 16241 (cmdline_parse_inst_t *)&cmd_cfg_input_set, 16242 (cmdline_parse_inst_t *)&cmd_clear_input_set, 16243 (cmdline_parse_inst_t *)&cmd_show_vf_stats, 16244 (cmdline_parse_inst_t *)&cmd_clear_vf_stats, 16245 (cmdline_parse_inst_t *)&cmd_ptype_mapping_get, 16246 (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace, 16247 (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset, 16248 (cmdline_parse_inst_t *)&cmd_ptype_mapping_update, 16249 16250 (cmdline_parse_inst_t *)&cmd_pctype_mapping_get, 16251 (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset, 16252 (cmdline_parse_inst_t *)&cmd_pctype_mapping_update, 16253 (cmdline_parse_inst_t *)&cmd_queue_region, 16254 (cmdline_parse_inst_t *)&cmd_region_flowtype, 16255 (cmdline_parse_inst_t *)&cmd_user_priority_region, 16256 (cmdline_parse_inst_t *)&cmd_flush_queue_region, 16257 (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all, 16258 (cmdline_parse_inst_t *)&cmd_show_port_tm_cap, 16259 (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap, 16260 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap, 16261 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type, 16262 (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats, 16263 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile, 16264 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile, 16265 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper, 16266 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper, 16267 (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile, 16268 (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile, 16269 (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile, 16270 (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node, 16271 (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node, 16272 (cmdline_parse_inst_t *)&cmd_del_port_tm_node, 16273 (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent, 16274 (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit, 16275 NULL, 16276 }; 16277 16278 /* read cmdline commands from file */ 16279 void 16280 cmdline_read_from_file(const char *filename) 16281 { 16282 struct cmdline *cl; 16283 16284 cl = cmdline_file_new(main_ctx, "testpmd> ", filename); 16285 if (cl == NULL) { 16286 printf("Failed to create file based cmdline context: %s\n", 16287 filename); 16288 return; 16289 } 16290 16291 cmdline_interact(cl); 16292 cmdline_quit(cl); 16293 16294 cmdline_free(cl); 16295 16296 printf("Read CLI commands from %s\n", filename); 16297 } 16298 16299 /* prompt function, called from main on MASTER lcore */ 16300 void 16301 prompt(void) 16302 { 16303 /* initialize non-constant commands */ 16304 cmd_set_fwd_mode_init(); 16305 cmd_set_fwd_retry_mode_init(); 16306 16307 testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); 16308 if (testpmd_cl == NULL) 16309 return; 16310 cmdline_interact(testpmd_cl); 16311 cmdline_stdin_exit(testpmd_cl); 16312 } 16313 16314 void 16315 prompt_exit(void) 16316 { 16317 if (testpmd_cl != NULL) 16318 cmdline_quit(testpmd_cl); 16319 } 16320 16321 static void 16322 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) 16323 { 16324 if (id == (portid_t)RTE_PORT_ALL) { 16325 portid_t pid; 16326 16327 RTE_ETH_FOREACH_DEV(pid) { 16328 /* check if need_reconfig has been set to 1 */ 16329 if (ports[pid].need_reconfig == 0) 16330 ports[pid].need_reconfig = dev; 16331 /* check if need_reconfig_queues has been set to 1 */ 16332 if (ports[pid].need_reconfig_queues == 0) 16333 ports[pid].need_reconfig_queues = queue; 16334 } 16335 } else if (!port_id_is_invalid(id, DISABLED_WARN)) { 16336 /* check if need_reconfig has been set to 1 */ 16337 if (ports[id].need_reconfig == 0) 16338 ports[id].need_reconfig = dev; 16339 /* check if need_reconfig_queues has been set to 1 */ 16340 if (ports[id].need_reconfig_queues == 0) 16341 ports[id].need_reconfig_queues = queue; 16342 } 16343 } 16344